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_recv_priv(struct adapter * padapter)15 int rtl8188eu_init_recv_priv(struct adapter *padapter)
16 {
17 struct recv_priv *precvpriv = &padapter->recvpriv;
18 int i, res = _SUCCESS;
19 struct recv_buf *precvbuf;
20
21 tasklet_init(&precvpriv->recv_tasklet,
22 rtl8188eu_recv_tasklet,
23 (unsigned long)padapter);
24
25 /* init recv_buf */
26 rtw_init_queue(&precvpriv->free_recv_buf_queue);
27
28 precvpriv->pallocated_recv_buf = kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4,
29 GFP_KERNEL);
30 if (!precvpriv->pallocated_recv_buf) {
31 res = _FAIL;
32 goto exit;
33 }
34
35 precvpriv->precv_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(precvpriv->pallocated_recv_buf), 4);
36
37 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
38
39 for (i = 0; i < NR_RECVBUFF; i++) {
40 res = rtw_os_recvbuf_resource_alloc(padapter, precvbuf);
41 if (res == _FAIL)
42 break;
43 precvbuf->adapter = padapter;
44 precvbuf++;
45 }
46 precvpriv->free_recv_buf_queue_cnt = NR_RECVBUFF;
47 skb_queue_head_init(&precvpriv->rx_skb_queue);
48 {
49 int i;
50 size_t tmpaddr = 0;
51 size_t alignment = 0;
52 struct sk_buff *pskb = NULL;
53
54 skb_queue_head_init(&precvpriv->free_recv_skb_queue);
55
56 for (i = 0; i < NR_PREALLOC_RECV_SKB; i++) {
57 pskb = __netdev_alloc_skb(padapter->pnetdev, MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ, GFP_KERNEL);
58 if (pskb) {
59 pskb->dev = padapter->pnetdev;
60 tmpaddr = (size_t)pskb->data;
61 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
62 skb_reserve(pskb, (RECVBUFF_ALIGN_SZ - alignment));
63
64 skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
65 }
66 pskb = NULL;
67 }
68 }
69 exit:
70 return res;
71 }
72
rtl8188eu_free_recv_priv(struct adapter * padapter)73 void rtl8188eu_free_recv_priv(struct adapter *padapter)
74 {
75 int i;
76 struct recv_buf *precvbuf;
77 struct recv_priv *precvpriv = &padapter->recvpriv;
78
79 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
80
81 for (i = 0; i < NR_RECVBUFF; i++) {
82 rtw_os_recvbuf_resource_free(padapter, precvbuf);
83 precvbuf++;
84 }
85
86 kfree(precvpriv->pallocated_recv_buf);
87
88 skb_queue_purge(&precvpriv->rx_skb_queue);
89
90 skb_queue_purge(&precvpriv->free_recv_skb_queue);
91 }
92