rtw88: extract alloc rsvd_page and h2c skb routines

Extract skb allocation routines for rsvd_page and h2c.
These routines should also be used by USB and SDIO.

This should not change the logic at all.
memset() for pkt_info is unnecessary, just declare as {0}.
Also skb_put()/memcpy() can be replaced by skb_put_data().

Signed-off-by: Yan-Hsuan Chuang <yhchuang@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200312080852.16684-3-yhchuang@realtek.com
This commit is contained in:
Yan-Hsuan Chuang 2020-03-12 16:08:49 +08:00 committed by Kalle Valo
parent 57fb39e247
commit da14a0409e
3 changed files with 66 additions and 23 deletions

View File

@ -760,43 +760,24 @@ static int rtw_pci_write_data_rsvd_page(struct rtw_dev *rtwdev, u8 *buf,
u32 size)
{
struct sk_buff *skb;
struct rtw_tx_pkt_info pkt_info;
u32 tx_pkt_desc_sz;
u32 length;
struct rtw_tx_pkt_info pkt_info = {0};
tx_pkt_desc_sz = rtwdev->chip->tx_pkt_desc_sz;
length = size + tx_pkt_desc_sz;
skb = dev_alloc_skb(length);
skb = rtw_tx_write_data_rsvd_page_get(rtwdev, &pkt_info, buf, size);
if (!skb)
return -ENOMEM;
skb_reserve(skb, tx_pkt_desc_sz);
memcpy((u8 *)skb_put(skb, size), buf, size);
memset(&pkt_info, 0, sizeof(pkt_info));
pkt_info.tx_pkt_size = size;
pkt_info.offset = tx_pkt_desc_sz;
return rtw_pci_xmit(rtwdev, &pkt_info, skb, RTW_TX_QUEUE_BCN);
}
static int rtw_pci_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)
{
struct sk_buff *skb;
struct rtw_tx_pkt_info pkt_info;
u32 tx_pkt_desc_sz;
u32 length;
struct rtw_tx_pkt_info pkt_info = {0};
tx_pkt_desc_sz = rtwdev->chip->tx_pkt_desc_sz;
length = size + tx_pkt_desc_sz;
skb = dev_alloc_skb(length);
skb = rtw_tx_write_data_h2c_get(rtwdev, &pkt_info, buf, size);
if (!skb)
return -ENOMEM;
skb_reserve(skb, tx_pkt_desc_sz);
memcpy((u8 *)skb_put(skb, size), buf, size);
memset(&pkt_info, 0, sizeof(pkt_info));
pkt_info.tx_pkt_size = size;
return rtw_pci_xmit(rtwdev, &pkt_info, skb, RTW_TX_QUEUE_H2C);
}

View File

@ -6,6 +6,7 @@
#include "tx.h"
#include "fw.h"
#include "ps.h"
#include "debug.h"
static
void rtw_tx_stats(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
@ -368,6 +369,59 @@ void rtw_rsvd_page_pkt_info_update(struct rtw_dev *rtwdev,
pkt_info->ls = true;
}
struct sk_buff *
rtw_tx_write_data_rsvd_page_get(struct rtw_dev *rtwdev,
struct rtw_tx_pkt_info *pkt_info,
u8 *buf, u32 size)
{
struct rtw_chip_info *chip = rtwdev->chip;
struct sk_buff *skb;
u32 tx_pkt_desc_sz;
u32 length;
tx_pkt_desc_sz = chip->tx_pkt_desc_sz;
length = size + tx_pkt_desc_sz;
skb = dev_alloc_skb(length);
if (!skb) {
rtw_err(rtwdev, "failed to alloc write data rsvd page skb\n");
return NULL;
}
skb_reserve(skb, tx_pkt_desc_sz);
skb_put_data(skb, buf, size);
pkt_info->tx_pkt_size = size;
pkt_info->offset = tx_pkt_desc_sz;
return skb;
}
EXPORT_SYMBOL(rtw_tx_write_data_rsvd_page_get);
struct sk_buff *
rtw_tx_write_data_h2c_get(struct rtw_dev *rtwdev,
struct rtw_tx_pkt_info *pkt_info,
u8 *buf, u32 size)
{
struct rtw_chip_info *chip = rtwdev->chip;
struct sk_buff *skb;
u32 tx_pkt_desc_sz;
u32 length;
tx_pkt_desc_sz = chip->tx_pkt_desc_sz;
length = size + tx_pkt_desc_sz;
skb = dev_alloc_skb(length);
if (!skb) {
rtw_err(rtwdev, "failed to alloc write data h2c skb\n");
return NULL;
}
skb_reserve(skb, tx_pkt_desc_sz);
skb_put_data(skb, buf, size);
pkt_info->tx_pkt_size = size;
return skb;
}
EXPORT_SYMBOL(rtw_tx_write_data_h2c_get);
void rtw_tx(struct rtw_dev *rtwdev,
struct ieee80211_tx_control *control,
struct sk_buff *skb)

View File

@ -93,5 +93,13 @@ void rtw_tx_report_handle(struct rtw_dev *rtwdev, struct sk_buff *skb);
void rtw_rsvd_page_pkt_info_update(struct rtw_dev *rtwdev,
struct rtw_tx_pkt_info *pkt_info,
struct sk_buff *skb);
struct sk_buff *
rtw_tx_write_data_rsvd_page_get(struct rtw_dev *rtwdev,
struct rtw_tx_pkt_info *pkt_info,
u8 *buf, u32 size);
struct sk_buff *
rtw_tx_write_data_h2c_get(struct rtw_dev *rtwdev,
struct rtw_tx_pkt_info *pkt_info,
u8 *buf, u32 size);
#endif