1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #define _RTL8188EU_RECV_C_
5 #include "../include/osdep_service.h"
6 #include "../include/drv_types.h"
7 #include "../include/recv_osdep.h"
8 #include "../include/mlme_osdep.h"
9
10 #include "../include/usb_ops.h"
11 #include "../include/wifi.h"
12
13 #include "../include/rtl8188e_hal.h"
14
rtl8188eu_init_recvbuf(struct adapter * padapter,struct recv_buf * precvbuf)15 void rtl8188eu_init_recvbuf(struct adapter *padapter, struct recv_buf *precvbuf)
16 {
17 precvbuf->transfer_len = 0;
18
19 precvbuf->len = 0;
20
21 precvbuf->ref_cnt = 0;
22
23 if (precvbuf->pbuf) {
24 precvbuf->pdata = precvbuf->pbuf;
25 precvbuf->phead = precvbuf->pbuf;
26 precvbuf->ptail = precvbuf->pbuf;
27 precvbuf->pend = precvbuf->pdata + MAX_RECVBUF_SZ;
28 }
29 }
30
rtl8188eu_init_recv_priv(struct adapter * padapter)31 int rtl8188eu_init_recv_priv(struct adapter *padapter)
32 {
33 struct recv_priv *precvpriv = &padapter->recvpriv;
34 int i, res = _SUCCESS;
35 struct recv_buf *precvbuf;
36
37 tasklet_init(&precvpriv->recv_tasklet,
38 rtl8188eu_recv_tasklet,
39 (unsigned long)padapter);
40
41 /* init recv_buf */
42 _rtw_init_queue(&precvpriv->free_recv_buf_queue);
43
44 precvpriv->pallocated_recv_buf = kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4,
45 GFP_KERNEL);
46 if (!precvpriv->pallocated_recv_buf) {
47 res = _FAIL;
48 goto exit;
49 }
50 memset(precvpriv->pallocated_recv_buf, 0, NR_RECVBUFF * sizeof(struct recv_buf) + 4);
51
52 precvpriv->precv_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_recv_buf), 4);
53
54 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
55
56 for (i = 0; i < NR_RECVBUFF; i++) {
57 INIT_LIST_HEAD(&precvbuf->list);
58 spin_lock_init(&precvbuf->recvbuf_lock);
59 precvbuf->alloc_sz = MAX_RECVBUF_SZ;
60 res = rtw_os_recvbuf_resource_alloc(padapter, precvbuf);
61 if (res == _FAIL)
62 break;
63 precvbuf->ref_cnt = 0;
64 precvbuf->adapter = padapter;
65 precvbuf++;
66 }
67 precvpriv->free_recv_buf_queue_cnt = NR_RECVBUFF;
68 skb_queue_head_init(&precvpriv->rx_skb_queue);
69 {
70 int i;
71 size_t tmpaddr = 0;
72 size_t alignment = 0;
73 struct sk_buff *pskb = NULL;
74
75 skb_queue_head_init(&precvpriv->free_recv_skb_queue);
76
77 for (i = 0; i < NR_PREALLOC_RECV_SKB; i++) {
78 pskb = __netdev_alloc_skb(padapter->pnetdev, MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ, GFP_KERNEL);
79 if (pskb) {
80 pskb->dev = padapter->pnetdev;
81 tmpaddr = (size_t)pskb->data;
82 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
83 skb_reserve(pskb, (RECVBUFF_ALIGN_SZ - alignment));
84
85 skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
86 }
87 pskb = NULL;
88 }
89 }
90 exit:
91 return res;
92 }
93
rtl8188eu_free_recv_priv(struct adapter * padapter)94 void rtl8188eu_free_recv_priv(struct adapter *padapter)
95 {
96 int i;
97 struct recv_buf *precvbuf;
98 struct recv_priv *precvpriv = &padapter->recvpriv;
99
100 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
101
102 for (i = 0; i < NR_RECVBUFF; i++) {
103 rtw_os_recvbuf_resource_free(padapter, precvbuf);
104 precvbuf++;
105 }
106
107 kfree(precvpriv->pallocated_recv_buf);
108
109 if (skb_queue_len(&precvpriv->rx_skb_queue))
110 DBG_88E(KERN_WARNING "rx_skb_queue not empty\n");
111 skb_queue_purge(&precvpriv->rx_skb_queue);
112
113 if (skb_queue_len(&precvpriv->free_recv_skb_queue))
114 DBG_88E(KERN_WARNING "free_recv_skb_queue not empty, %d\n", skb_queue_len(&precvpriv->free_recv_skb_queue));
115
116 skb_queue_purge(&precvpriv->free_recv_skb_queue);
117 }
118