rtw89: pci: support variant of fill_txaddr_info
authorPing-Ke Shih <pkshih@realtek.com>
Fri, 18 Mar 2022 02:32:11 +0000 (10:32 +0800)
committerKalle Valo <kvalo@kernel.org>
Wed, 6 Apr 2022 07:48:16 +0000 (10:48 +0300)
The txaddr_info is used to fill the DMA address of skb->data. The v1
version can support up to 10 entries, but the maximum size of each entry
is 2047, so it fill more than one entry for large packet, like 3000 bytes.

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220318023214.32411-9-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/core.h
drivers/net/wireless/realtek/rtw89/pci.c
drivers/net/wireless/realtek/rtw89/pci.h
drivers/net/wireless/realtek/rtw89/rtw8852ae.c
drivers/net/wireless/realtek/rtw89/rtw8852ce.c

index c17756ff5476234b85c2eb8fe2e8584a5ea7087a..501381bb74adfe2a93f44a459981fc58b3e52d18 100644 (file)
@@ -721,6 +721,7 @@ struct rtw89_tx_desc_info {
        u8 ampdu_density;
        u8 ampdu_num;
        bool sec_en;
+       u8 addr_info_nr;
        u8 sec_type;
        u8 sec_cam_idx;
        u16 data_rate;
index 9335fba28fc1e7892e2a719de662da7630ffcd27..48a5feaf2722251260148225cec1687f79e03bdb 100644 (file)
@@ -977,6 +977,58 @@ static void rtw89_pci_ops_flush_queues(struct rtw89_dev *rtwdev, u32 queues,
        __rtw89_pci_ops_flush_txchs(rtwdev, BIT(RTW89_TXCH_NUM) - 1, drop);
 }
 
+u32 rtw89_pci_fill_txaddr_info(struct rtw89_dev *rtwdev,
+                              void *txaddr_info_addr, u32 total_len,
+                              dma_addr_t dma, u8 *add_info_nr)
+{
+       struct rtw89_pci_tx_addr_info_32 *txaddr_info = txaddr_info_addr;
+
+       txaddr_info->length = cpu_to_le16(total_len);
+       txaddr_info->option = cpu_to_le16(RTW89_PCI_ADDR_MSDU_LS |
+                                         RTW89_PCI_ADDR_NUM(1));
+       txaddr_info->dma = cpu_to_le32(dma);
+
+       *add_info_nr = 1;
+
+       return sizeof(*txaddr_info);
+}
+EXPORT_SYMBOL(rtw89_pci_fill_txaddr_info);
+
+u32 rtw89_pci_fill_txaddr_info_v1(struct rtw89_dev *rtwdev,
+                                 void *txaddr_info_addr, u32 total_len,
+                                 dma_addr_t dma, u8 *add_info_nr)
+{
+       struct rtw89_pci_tx_addr_info_32_v1 *txaddr_info = txaddr_info_addr;
+       u32 remain = total_len;
+       u32 len;
+       u16 length_option;
+       int n;
+
+       for (n = 0; n < RTW89_TXADDR_INFO_NR_V1 && remain; n++) {
+               len = remain >= TXADDR_INFO_LENTHG_V1_MAX ?
+                     TXADDR_INFO_LENTHG_V1_MAX : remain;
+               remain -= len;
+
+               length_option = FIELD_PREP(B_PCIADDR_LEN_V1_MASK, len) |
+                               FIELD_PREP(B_PCIADDR_HIGH_SEL_V1_MASK, 0) |
+                               FIELD_PREP(B_PCIADDR_LS_V1_MASK, remain == 0);
+               txaddr_info->length_opt = cpu_to_le16(length_option);
+               txaddr_info->dma_low_lsb = cpu_to_le16(FIELD_GET(GENMASK(15, 0), dma));
+               txaddr_info->dma_low_msb = cpu_to_le16(FIELD_GET(GENMASK(31, 16), dma));
+
+               dma += len;
+               txaddr_info++;
+       }
+
+       WARN_ONCE(remain, "length overflow remain=%u total_len=%u",
+                 remain, total_len);
+
+       *add_info_nr = n;
+
+       return n * sizeof(*txaddr_info);
+}
+EXPORT_SYMBOL(rtw89_pci_fill_txaddr_info_v1);
+
 static int rtw89_pci_txwd_submit(struct rtw89_dev *rtwdev,
                                 struct rtw89_pci_tx_ring *tx_ring,
                                 struct rtw89_pci_tx_wd *txwd,
@@ -987,7 +1039,7 @@ static int rtw89_pci_txwd_submit(struct rtw89_dev *rtwdev,
        struct rtw89_txwd_body *txwd_body;
        struct rtw89_txwd_info *txwd_info;
        struct rtw89_pci_tx_wp_info *txwp_info;
-       struct rtw89_pci_tx_addr_info_32 *txaddr_info;
+       void *txaddr_info_addr;
        struct pci_dev *pdev = rtwpci->pdev;
        struct sk_buff *skb = tx_req->skb;
        struct rtw89_pci_tx_data *tx_data = RTW89_PCI_TX_SKB_CB(skb);
@@ -1009,7 +1061,6 @@ static int rtw89_pci_txwd_submit(struct rtw89_dev *rtwdev,
 
        tx_data->dma = dma;
 
-       txaddr_info_len = sizeof(*txaddr_info);
        txwp_len = sizeof(*txwp_info);
        txwd_len = sizeof(*txwd_body);
        txwd_len += en_wd_info ? sizeof(*txwd_info) : 0;
@@ -1021,11 +1072,10 @@ static int rtw89_pci_txwd_submit(struct rtw89_dev *rtwdev,
        txwp_info->seq3 = 0;
 
        tx_ring->tx_cnt++;
-       txaddr_info = txwd->vaddr + txwd_len + txwp_len;
-       txaddr_info->length = cpu_to_le16(skb->len);
-       txaddr_info->option = cpu_to_le16(RTW89_PCI_ADDR_MSDU_LS |
-                                         RTW89_PCI_ADDR_NUM(1));
-       txaddr_info->dma = cpu_to_le32(dma);
+       txaddr_info_addr = txwd->vaddr + txwd_len + txwp_len;
+       txaddr_info_len =
+               rtw89_chip_fill_txaddr_info(rtwdev, txaddr_info_addr, skb->len,
+                                           dma, &desc_info->addr_info_nr);
 
        txwd->len = txwd_len + txwp_len + txaddr_info_len;
 
index 2c8030af3e72f1edaa92f3b849dbd41364acd756..a67595b2118533ec087b72a43426540fe9f0d4f6 100644 (file)
@@ -448,6 +448,10 @@ struct rtw89_pci_ch_dma_addr_set {
 
 struct rtw89_pci_info {
        const struct rtw89_pci_ch_dma_addr_set *dma_addr_set;
+
+       u32 (*fill_txaddr_info)(struct rtw89_dev *rtwdev,
+                               void *txaddr_info_addr, u32 total_len,
+                               dma_addr_t dma, u8 *add_info_nr);
 };
 
 struct rtw89_pci_bd_ram {
@@ -493,6 +497,18 @@ struct rtw89_pci_tx_addr_info_32 {
        __le32 dma;
 } __packed;
 
+#define RTW89_TXADDR_INFO_NR_V1                10
+
+struct rtw89_pci_tx_addr_info_32_v1 {
+       __le16 length_opt;
+#define B_PCIADDR_LEN_V1_MASK          GENMASK(10, 0)
+#define B_PCIADDR_HIGH_SEL_V1_MASK     GENMASK(14, 11)
+#define B_PCIADDR_LS_V1_MASK           BIT(15)
+#define TXADDR_INFO_LENTHG_V1_MAX      ALIGN_DOWN(BIT(11) - 1, 4)
+       __le16 dma_low_lsb;
+       __le16 dma_low_msb;
+} __packed;
+
 #define RTW89_PCI_RPP_POLLUTED         BIT(31)
 #define RTW89_PCI_RPP_SEQ              GENMASK(30, 16)
 #define RTW89_PCI_RPP_TX_STATUS                GENMASK(15, 13)
@@ -698,5 +714,22 @@ struct pci_device_id;
 
 int rtw89_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id);
 void rtw89_pci_remove(struct pci_dev *pdev);
+u32 rtw89_pci_fill_txaddr_info(struct rtw89_dev *rtwdev,
+                              void *txaddr_info_addr, u32 total_len,
+                              dma_addr_t dma, u8 *add_info_nr);
+u32 rtw89_pci_fill_txaddr_info_v1(struct rtw89_dev *rtwdev,
+                                 void *txaddr_info_addr, u32 total_len,
+                                 dma_addr_t dma, u8 *add_info_nr);
+
+static inline
+u32 rtw89_chip_fill_txaddr_info(struct rtw89_dev *rtwdev,
+                               void *txaddr_info_addr, u32 total_len,
+                               dma_addr_t dma, u8 *add_info_nr)
+{
+       const struct rtw89_pci_info *info = rtwdev->pci_info;
+
+       return info->fill_txaddr_info(rtwdev, txaddr_info_addr, total_len,
+                                     dma, add_info_nr);
+}
 
 #endif
index 48459aba441df140b3f9b91365bce7337493fd6c..8ffc0dd90d41c8147b0260203adf2ca42562edc6 100644 (file)
@@ -10,6 +10,8 @@
 
 static const struct rtw89_pci_info rtw8852a_pci_info = {
        .dma_addr_set           = &rtw89_pci_ch_dma_addr_set,
+
+       .fill_txaddr_info       = rtw89_pci_fill_txaddr_info,
 };
 
 static const struct rtw89_driver_info rtw89_8852ae_info = {
index e71370585b4da56133635d5f6ea90a6f7e3ab95d..09794836d5c0f334a7f287b84264f6379a4a0a46 100644 (file)
@@ -11,6 +11,8 @@
 
 static const struct rtw89_pci_info rtw8852c_pci_info = {
        .dma_addr_set           = &rtw89_pci_ch_dma_addr_set_v1,
+
+       .fill_txaddr_info       = rtw89_pci_fill_txaddr_info_v1,
 };
 
 static const struct rtw89_driver_info rtw89_8852ce_info = {