2022-06-08 23:46:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Copyright(c) 2007 - 2012 Realtek Corporation. */
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
#define _XMIT_OSDEP_C_
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
#include "../include/osdep_service.h"
|
|
|
|
#include "../include/drv_types.h"
|
|
|
|
#include "../include/wifi.h"
|
|
|
|
#include "../include/mlme_osdep.h"
|
|
|
|
#include "../include/xmit_osdep.h"
|
|
|
|
#include "../include/osdep_intf.h"
|
|
|
|
#include "../include/usb_osintf.h"
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
uint rtw_remainder_len(struct pkt_file *pfile)
|
|
|
|
{
|
2013-08-12 03:07:26 +00:00
|
|
|
return pfile->buf_len - ((size_t)(pfile->cur_addr) -
|
|
|
|
(size_t)(pfile->buf_start));
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
void _rtw_open_pktfile(struct sk_buff *pktptr, struct pkt_file *pfile)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2014-12-01 22:31:15 +00:00
|
|
|
|
2017-01-16 21:23:52 +00:00
|
|
|
if (!pktptr) {
|
|
|
|
pr_err("8188eu: pktptr is NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!pfile) {
|
|
|
|
pr_err("8188eu: pfile is NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
pfile->pkt = pktptr;
|
2013-08-12 03:07:26 +00:00
|
|
|
pfile->cur_addr = pktptr->data;
|
|
|
|
pfile->buf_start = pktptr->data;
|
|
|
|
pfile->pkt_len = pktptr->len;
|
|
|
|
pfile->buf_len = pktptr->len;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
pfile->cur_buffer = pfile->buf_start;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
|
2013-05-19 04:28:07 +00:00
|
|
|
{
|
2013-05-08 21:45:39 +00:00
|
|
|
uint len = 0;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
len = rtw_remainder_len(pfile);
|
|
|
|
len = (rlen > len) ? len : rlen;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
if (rmem)
|
2022-06-08 23:46:35 +00:00
|
|
|
skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, len);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
pfile->cur_addr += len;
|
|
|
|
pfile->pkt_len -= len;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
return len;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
bool rtw_endofpktfile(struct pkt_file *pfile)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2014-12-01 22:31:15 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
if (pfile->pkt_len == 0) {
|
2022-06-08 23:46:35 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
return true;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
return false;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
pxmitbuf->pallocated_buf = kzalloc(alloc_sz, GFP_KERNEL);
|
|
|
|
if (!pxmitbuf->pallocated_buf)
|
2013-05-08 21:45:39 +00:00
|
|
|
return _FAIL;
|
|
|
|
|
2013-07-24 17:19:14 +00:00
|
|
|
pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ);
|
2013-05-08 21:45:39 +00:00
|
|
|
pxmitbuf->dma_transfer_addr = 0;
|
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2013-05-19 04:28:07 +00:00
|
|
|
pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
|
2022-06-08 23:46:35 +00:00
|
|
|
if (!pxmitbuf->pxmit_urb[i])
|
2013-05-19 04:28:07 +00:00
|
|
|
return _FAIL;
|
|
|
|
}
|
|
|
|
return _SUCCESS;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
void rtw_os_xmit_resource_free(struct adapter *padapter,
|
|
|
|
struct xmit_buf *pxmitbuf, u32 free_sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
usb_free_urb(pxmitbuf->pxmit_urb[i]);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-10-19 17:45:47 +00:00
|
|
|
kfree(pxmitbuf->pallocated_buf);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
#define WMM_XMIT_THRESHOLD (NR_XMITFRAME * 2 / 5)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-07-27 01:08:39 +00:00
|
|
|
void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
u16 queue;
|
|
|
|
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
|
|
|
|
|
|
|
|
queue = skb_get_queue_mapping(pkt);
|
|
|
|
if (padapter->registrypriv.wifi_spec) {
|
2013-05-09 04:04:25 +00:00
|
|
|
if (__netif_subqueue_stopped(padapter->pnetdev, queue) &&
|
2013-08-12 03:07:26 +00:00
|
|
|
(pxmitpriv->hwxmits[queue].accnt < WMM_XMIT_THRESHOLD))
|
2013-05-08 21:45:39 +00:00
|
|
|
netif_wake_subqueue(padapter->pnetdev, queue);
|
|
|
|
} else {
|
2013-05-09 04:04:25 +00:00
|
|
|
if (__netif_subqueue_stopped(padapter->pnetdev, queue))
|
2013-05-08 21:45:39 +00:00
|
|
|
netif_wake_subqueue(padapter->pnetdev, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_kfree_skb_any(pkt);
|
|
|
|
}
|
|
|
|
|
2013-07-27 01:08:39 +00:00
|
|
|
void rtw_os_xmit_complete(struct adapter *padapter, struct xmit_frame *pxframe)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-09 04:04:25 +00:00
|
|
|
if (pxframe->pkt)
|
2013-05-08 21:45:39 +00:00
|
|
|
rtw_os_pkt_complete(padapter, pxframe->pkt);
|
|
|
|
pxframe->pkt = NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-27 01:08:39 +00:00
|
|
|
void rtw_os_xmit_schedule(struct adapter *padapter)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
struct xmit_priv *pxmitpriv;
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (!padapter)
|
2013-05-08 21:45:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
pxmitpriv = &padapter->xmitpriv;
|
|
|
|
|
2014-11-29 00:42:41 +00:00
|
|
|
spin_lock_bh(&pxmitpriv->lock);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
if (rtw_txframes_pending(padapter))
|
2013-05-08 21:45:39 +00:00
|
|
|
tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
|
|
|
|
|
2014-11-29 00:42:41 +00:00
|
|
|
spin_unlock_bh(&pxmitpriv->lock);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-27 01:08:39 +00:00
|
|
|
static void rtw_check_xmit_resource(struct adapter *padapter, struct sk_buff *pkt)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
|
|
|
|
u16 queue;
|
|
|
|
|
|
|
|
queue = skb_get_queue_mapping(pkt);
|
|
|
|
if (padapter->registrypriv.wifi_spec) {
|
|
|
|
/* No free space for Tx, tx_worker is too slow */
|
2013-08-12 03:07:26 +00:00
|
|
|
if (pxmitpriv->hwxmits[queue].accnt > WMM_XMIT_THRESHOLD)
|
2013-05-08 21:45:39 +00:00
|
|
|
netif_stop_subqueue(padapter->pnetdev, queue);
|
|
|
|
} else {
|
2013-08-12 03:07:26 +00:00
|
|
|
if (pxmitpriv->free_xmitframe_cnt <= 4) {
|
2013-05-08 21:45:39 +00:00
|
|
|
if (!netif_tx_queue_stopped(netdev_get_tx_queue(padapter->pnetdev, queue)))
|
|
|
|
netif_stop_subqueue(padapter->pnetdev, queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 01:08:39 +00:00
|
|
|
static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
struct sta_priv *pstapriv = &padapter->stapriv;
|
|
|
|
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
|
2013-07-25 14:49:25 +00:00
|
|
|
struct list_head *phead, *plist;
|
2013-05-08 21:45:39 +00:00
|
|
|
struct sk_buff *newskb;
|
|
|
|
struct sta_info *psta = NULL;
|
|
|
|
s32 res;
|
|
|
|
|
2014-11-29 00:42:41 +00:00
|
|
|
spin_lock_bh(&pstapriv->asoc_list_lock);
|
2013-05-08 21:45:39 +00:00
|
|
|
phead = &pstapriv->asoc_list;
|
2014-12-13 17:50:41 +00:00
|
|
|
plist = phead->next;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
/* free sta asoc_queue */
|
2014-12-13 17:50:41 +00:00
|
|
|
while (phead != plist) {
|
2014-12-13 16:40:44 +00:00
|
|
|
psta = container_of(plist, struct sta_info, asoc_list);
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2014-12-13 17:50:41 +00:00
|
|
|
plist = plist->next;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-19 04:28:07 +00:00
|
|
|
/* avoid come from STA1 and send back STA1 */
|
|
|
|
if (!memcmp(psta->hwaddr, &skb->data[6], 6))
|
|
|
|
continue;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
newskb = skb_copy(skb, GFP_ATOMIC);
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
if (newskb) {
|
|
|
|
memcpy(newskb->data, psta->hwaddr, 6);
|
|
|
|
res = rtw_xmit(padapter, &newskb);
|
|
|
|
if (res < 0) {
|
|
|
|
pxmitpriv->tx_drop++;
|
2013-05-19 04:28:07 +00:00
|
|
|
dev_kfree_skb_any(newskb);
|
2013-08-12 03:07:26 +00:00
|
|
|
} else {
|
2013-05-08 21:45:39 +00:00
|
|
|
pxmitpriv->tx_pkts++;
|
2013-08-12 03:07:26 +00:00
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
} else {
|
|
|
|
pxmitpriv->tx_drop++;
|
|
|
|
|
2014-11-29 00:42:41 +00:00
|
|
|
spin_unlock_bh(&pstapriv->asoc_list_lock);
|
2013-08-12 03:07:26 +00:00
|
|
|
return false; /* Caller shall tx this multicast frame via normal way. */
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-29 00:42:41 +00:00
|
|
|
spin_unlock_bh(&pstapriv->asoc_list_lock);
|
2013-05-08 21:45:39 +00:00
|
|
|
dev_kfree_skb_any(skb);
|
2013-05-26 03:02:10 +00:00
|
|
|
return true;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 15:53:16 +00:00
|
|
|
int rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-07-27 01:08:39 +00:00
|
|
|
struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
|
2013-05-08 21:45:39 +00:00
|
|
|
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
|
|
|
|
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
|
|
|
s32 res = 0;
|
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
if (!rtw_if_up(padapter))
|
2013-05-08 21:45:39 +00:00
|
|
|
goto drop_packet;
|
|
|
|
|
|
|
|
rtw_check_xmit_resource(padapter, pkt);
|
|
|
|
|
2013-08-12 03:07:26 +00:00
|
|
|
if (!rtw_mc2u_disable && check_fwstate(pmlmepriv, WIFI_AP_STATE) &&
|
|
|
|
(IP_MCAST_MAC(pkt->data) || ICMPV6_MCAST_MAC(pkt->data)) &&
|
|
|
|
(padapter->registrypriv.wifi_spec == 0)) {
|
2022-06-08 23:46:35 +00:00
|
|
|
if (pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME / 4)) {
|
2013-05-08 21:45:39 +00:00
|
|
|
res = rtw_mlcst2unicst(padapter, pkt);
|
2013-08-12 03:07:26 +00:00
|
|
|
if (res)
|
2013-05-08 21:45:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2013-05-19 04:28:07 +00:00
|
|
|
}
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
res = rtw_xmit(padapter, &pkt);
|
2013-07-20 21:22:15 +00:00
|
|
|
if (res < 0)
|
2013-05-08 21:45:39 +00:00
|
|
|
goto drop_packet;
|
|
|
|
|
|
|
|
pxmitpriv->tx_pkts++;
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
drop_packet:
|
|
|
|
pxmitpriv->tx_drop++;
|
|
|
|
dev_kfree_skb_any(pkt);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|