1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #define _XMIT_OSDEP_C_
17 #include <osdep_service.h>
18 #include <drv_types.h>
20 #include <linux/if_ether.h>
23 #include <mlme_osdep.h>
24 #include <xmit_osdep.h>
25 #include <osdep_intf.h>
27 int rtw_os_xmit_resource_alloc23a(struct rtw_adapter *padapter,
28 struct xmit_buf *pxmitbuf, u32 alloc_sz)
32 pxmitbuf->pallocated_buf = kzalloc(alloc_sz, GFP_KERNEL);
33 if (pxmitbuf->pallocated_buf == NULL)
36 pxmitbuf->pbuf = PTR_ALIGN(pxmitbuf->pallocated_buf, XMITBUF_ALIGN_SZ);
38 for (i = 0; i < 8; i++) {
39 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
40 if (pxmitbuf->pxmit_urb[i] == NULL) {
41 DBG_8723A("pxmitbuf->pxmit_urb[i]==NULL");
48 void rtw_os_xmit_resource_free23a(struct rtw_adapter *padapter,
49 struct xmit_buf *pxmitbuf)
53 for (i = 0; i < 8; i++)
54 usb_free_urb(pxmitbuf->pxmit_urb[i]);
55 kfree(pxmitbuf->pallocated_buf);
58 #define WMM_XMIT_THRESHOLD (NR_XMITFRAME*2/5)
60 void rtw_os_pkt_complete23a(struct rtw_adapter *padapter, struct sk_buff *pkt)
62 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
65 queue = skb_get_queue_mapping(pkt);
66 if (padapter->registrypriv.wifi_spec) {
67 if (__netif_subqueue_stopped(padapter->pnetdev, queue) &&
68 (pxmitpriv->hwxmits[queue].accnt < WMM_XMIT_THRESHOLD))
69 netif_wake_subqueue(padapter->pnetdev, queue);
71 if (__netif_subqueue_stopped(padapter->pnetdev, queue))
72 netif_wake_subqueue(padapter->pnetdev, queue);
74 dev_kfree_skb_any(pkt);
77 void rtw_os_xmit_complete23a(struct rtw_adapter *padapter,
78 struct xmit_frame *pxframe)
81 rtw_os_pkt_complete23a(padapter, pxframe->pkt);
86 void rtw_os_xmit_schedule23a(struct rtw_adapter *padapter)
88 struct xmit_priv *pxmitpriv;
92 pxmitpriv = &padapter->xmitpriv;
94 spin_lock_bh(&pxmitpriv->lock);
96 if (rtw_txframes_pending23a(padapter))
97 tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
98 spin_unlock_bh(&pxmitpriv->lock);
101 static void rtw_check_xmit_resource(struct rtw_adapter *padapter,
104 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
107 queue = skb_get_queue_mapping(pkt);
108 if (padapter->registrypriv.wifi_spec) {
109 /* No free space for Tx, tx_worker is too slow */
110 if (pxmitpriv->hwxmits[queue].accnt > WMM_XMIT_THRESHOLD)
111 netif_stop_subqueue(padapter->pnetdev, queue);
113 if (pxmitpriv->free_xmitframe_cnt <= 4) {
114 if (!netif_tx_queue_stopped(netdev_get_tx_queue(padapter->pnetdev, queue)))
115 netif_stop_subqueue(padapter->pnetdev, queue);
120 int rtw_xmit23a_entry23a(struct sk_buff *skb, struct net_device *pnetdev)
122 struct rtw_adapter *padapter = netdev_priv(pnetdev);
123 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
126 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, "+xmit_enry\n");
128 if (!rtw_if_up23a(padapter)) {
129 RT_TRACE(_module_xmit_osdep_c_, _drv_err_,
130 "rtw_xmit23a_entry23a: rtw_if_up23a fail\n");
134 rtw_check_xmit_resource(padapter, skb);
136 res = rtw_xmit23a(padapter, skb);
140 pxmitpriv->tx_pkts++;
141 RT_TRACE(_module_xmit_osdep_c_, _drv_info_,
142 "rtw_xmit23a_entry23a: tx_pkts=%d\n",
143 (u32)pxmitpriv->tx_pkts);
147 pxmitpriv->tx_drop++;
148 dev_kfree_skb_any(skb);
149 RT_TRACE(_module_xmit_osdep_c_, _drv_notice_,
150 "rtw_xmit23a_entry23a: drop, tx_drop=%d\n",
151 (u32)pxmitpriv->tx_drop);