1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/wifi.h"
9 #include "../include/mlme_osdep.h"
10 #include "../include/xmit_osdep.h"
11 #include "../include/osdep_intf.h"
12 #include "../include/usb_osintf.h"
14 uint rtw_remainder_len(struct pkt_file *pfile)
16 return pfile->buf_len - ((size_t)(pfile->cur_addr) -
17 (size_t)(pfile->buf_start));
20 void _rtw_open_pktfile(struct sk_buff *pktptr, struct pkt_file *pfile)
24 pr_err("8188eu: pktptr is NULL\n");
28 pr_err("8188eu: pfile is NULL\n");
32 pfile->cur_addr = pktptr->data;
33 pfile->buf_start = pktptr->data;
34 pfile->pkt_len = pktptr->len;
35 pfile->buf_len = pktptr->len;
37 pfile->cur_buffer = pfile->buf_start;
41 uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
45 len = rtw_remainder_len(pfile);
46 len = (rlen > len) ? len : rlen;
49 skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, len);
51 pfile->cur_addr += len;
52 pfile->pkt_len -= len;
57 bool rtw_endofpktfile(struct pkt_file *pfile)
60 if (pfile->pkt_len == 0) {
68 int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz)
70 pxmitbuf->pallocated_buf = kzalloc(alloc_sz, GFP_KERNEL);
71 if (!pxmitbuf->pallocated_buf)
74 pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ);
75 pxmitbuf->dma_transfer_addr = 0;
77 pxmitbuf->pxmit_urb = usb_alloc_urb(0, GFP_KERNEL);
78 if (!pxmitbuf->pxmit_urb)
84 void rtw_os_xmit_resource_free(struct adapter *padapter,
85 struct xmit_buf *pxmitbuf, u32 free_sz)
87 usb_free_urb(pxmitbuf->pxmit_urb);
89 kfree(pxmitbuf->pallocated_buf);
92 #define WMM_XMIT_THRESHOLD (NR_XMITFRAME * 2 / 5)
94 void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt)
97 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
99 queue = skb_get_queue_mapping(pkt);
100 if (padapter->registrypriv.wifi_spec) {
101 if (__netif_subqueue_stopped(padapter->pnetdev, queue) &&
102 (pxmitpriv->hwxmits[queue].accnt < WMM_XMIT_THRESHOLD))
103 netif_wake_subqueue(padapter->pnetdev, queue);
105 if (__netif_subqueue_stopped(padapter->pnetdev, queue))
106 netif_wake_subqueue(padapter->pnetdev, queue);
109 dev_kfree_skb_any(pkt);
112 void rtw_os_xmit_complete(struct adapter *padapter, struct xmit_frame *pxframe)
115 rtw_os_pkt_complete(padapter, pxframe->pkt);
119 void rtw_os_xmit_schedule(struct adapter *padapter)
121 struct xmit_priv *pxmitpriv;
126 pxmitpriv = &padapter->xmitpriv;
128 spin_lock_bh(&pxmitpriv->lock);
130 if (rtw_txframes_pending(padapter))
131 tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
133 spin_unlock_bh(&pxmitpriv->lock);
136 static void rtw_check_xmit_resource(struct adapter *padapter, struct sk_buff *pkt)
138 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
141 queue = skb_get_queue_mapping(pkt);
142 if (padapter->registrypriv.wifi_spec) {
143 /* No free space for Tx, tx_worker is too slow */
144 if (pxmitpriv->hwxmits[queue].accnt > WMM_XMIT_THRESHOLD)
145 netif_stop_subqueue(padapter->pnetdev, queue);
147 if (pxmitpriv->free_xmitframe_cnt <= 4) {
148 if (!netif_tx_queue_stopped(netdev_get_tx_queue(padapter->pnetdev, queue)))
149 netif_stop_subqueue(padapter->pnetdev, queue);
154 static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb)
156 struct sta_priv *pstapriv = &padapter->stapriv;
157 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
158 struct list_head *phead, *plist;
159 struct sk_buff *newskb;
160 struct sta_info *psta = NULL;
163 spin_lock_bh(&pstapriv->asoc_list_lock);
164 phead = &pstapriv->asoc_list;
167 /* free sta asoc_queue */
168 while (phead != plist) {
169 psta = container_of(plist, struct sta_info, asoc_list);
173 /* avoid come from STA1 and send back STA1 */
174 if (!memcmp(psta->hwaddr, &skb->data[6], 6))
177 newskb = skb_copy(skb, GFP_ATOMIC);
180 memcpy(newskb->data, psta->hwaddr, 6);
181 res = rtw_xmit(padapter, &newskb);
183 pxmitpriv->tx_drop++;
184 dev_kfree_skb_any(newskb);
186 pxmitpriv->tx_pkts++;
189 pxmitpriv->tx_drop++;
191 spin_unlock_bh(&pstapriv->asoc_list_lock);
192 return false; /* Caller shall tx this multicast frame via normal way. */
196 spin_unlock_bh(&pstapriv->asoc_list_lock);
197 dev_kfree_skb_any(skb);
201 int rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev)
203 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
204 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
205 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
208 if (!rtw_if_up(padapter))
211 rtw_check_xmit_resource(padapter, pkt);
213 if (!rtw_mc2u_disable && check_fwstate(pmlmepriv, WIFI_AP_STATE) &&
214 (IP_MCAST_MAC(pkt->data) || ICMPV6_MCAST_MAC(pkt->data)) &&
215 (padapter->registrypriv.wifi_spec == 0)) {
216 if (pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME / 4)) {
217 res = rtw_mlcst2unicst(padapter, pkt);
223 res = rtw_xmit(padapter, &pkt);
227 pxmitpriv->tx_pkts++;
231 pxmitpriv->tx_drop++;
232 dev_kfree_skb_any(pkt);