diff mbox series

[3/4] rtw88: Move enum rtw_tx_queue_type mapping code to tx.{c,h}

Message ID 20220114234825.110502-4-martin.blumenstingl@googlemail.com
State New
Headers show
Series rtw88: four small code-cleanups and refactorings | expand

Commit Message

Martin Blumenstingl Jan. 14, 2022, 11:48 p.m. UTC
This code is not specific to the PCIe bus type but can be re-used by USB
and SDIO bus types. Move it to tx.{c,h} to avoid code-duplication in the
future.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/wireless/realtek/rtw88/pci.c | 32 ++--------------------
 drivers/net/wireless/realtek/rtw88/tx.c  | 35 ++++++++++++++++++++++++
 drivers/net/wireless/realtek/rtw88/tx.h  |  3 ++
 3 files changed, 40 insertions(+), 30 deletions(-)

Comments

Ping-Ke Shih Jan. 19, 2022, 6:04 a.m. UTC | #1
> -----Original Message-----
> From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Sent: Saturday, January 15, 2022 7:48 AM
> To: linux-wireless@vger.kernel.org
> Cc: tony0620emma@gmail.com; kvalo@codeaurora.org; netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
> Neo Jou <neojou@gmail.com>; Jernej Skrabec <jernej.skrabec@gmail.com>; Pkshih <pkshih@realtek.com>; Martin
> Blumenstingl <martin.blumenstingl@googlemail.com>
> Subject: [PATCH 3/4] rtw88: Move enum rtw_tx_queue_type mapping code to tx.{c,h}
> 
> This code is not specific to the PCIe bus type but can be re-used by USB
> and SDIO bus types. Move it to tx.{c,h} to avoid code-duplication in the
> future.
> 
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

[...]

> diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c
> index efcc1b0371a8..ec6a3683c3f8 100644
> --- a/drivers/net/wireless/realtek/rtw88/tx.c
> +++ b/drivers/net/wireless/realtek/rtw88/tx.c
> @@ -665,3 +665,38 @@ void rtw_txq_cleanup(struct rtw_dev *rtwdev, struct ieee80211_txq *txq)
>  		list_del_init(&rtwtxq->list);
>  	spin_unlock_bh(&rtwdev->txq_lock);
>  }
> +
> +static enum rtw_tx_queue_type ac_to_hwq[] = {
> +	[IEEE80211_AC_VO] = RTW_TX_QUEUE_VO,
> +	[IEEE80211_AC_VI] = RTW_TX_QUEUE_VI,
> +	[IEEE80211_AC_BE] = RTW_TX_QUEUE_BE,
> +	[IEEE80211_AC_BK] = RTW_TX_QUEUE_BK,
> +};
> +
> +static_assert(ARRAY_SIZE(ac_to_hwq) == IEEE80211_NUM_ACS);
> +
> +enum rtw_tx_queue_type rtw_tx_ac_to_hwq(enum ieee80211_ac_numbers ac)
> +{
> +	return ac_to_hwq[ac];
> +}
> +EXPORT_SYMBOL(rtw_tx_ac_to_hwq);
> +

Could I know why we can't just export the array ac_to_hwq[]?
Is there a strict rule?

--
Ping-Ke
Kalle Valo Jan. 19, 2022, 6:19 a.m. UTC | #2
Pkshih <pkshih@realtek.com> writes:

>> -----Original Message-----
>> From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>> Sent: Saturday, January 15, 2022 7:48 AM
>> To: linux-wireless@vger.kernel.org
>> Cc: tony0620emma@gmail.com; kvalo@codeaurora.org;
>> netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
>> Neo Jou <neojou@gmail.com>; Jernej Skrabec
>> <jernej.skrabec@gmail.com>; Pkshih <pkshih@realtek.com>; Martin
>> Blumenstingl <martin.blumenstingl@googlemail.com>
>> Subject: [PATCH 3/4] rtw88: Move enum rtw_tx_queue_type mapping code to tx.{c,h}
>> 
>> This code is not specific to the PCIe bus type but can be re-used by USB
>> and SDIO bus types. Move it to tx.{c,h} to avoid code-duplication in the
>> future.
>> 
>> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>
> [...]
>
>> diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c
>> index efcc1b0371a8..ec6a3683c3f8 100644
>> --- a/drivers/net/wireless/realtek/rtw88/tx.c
>> +++ b/drivers/net/wireless/realtek/rtw88/tx.c
>> @@ -665,3 +665,38 @@ void rtw_txq_cleanup(struct rtw_dev *rtwdev, struct ieee80211_txq *txq)
>>  		list_del_init(&rtwtxq->list);
>>  	spin_unlock_bh(&rtwdev->txq_lock);
>>  }
>> +
>> +static enum rtw_tx_queue_type ac_to_hwq[] = {
>> +	[IEEE80211_AC_VO] = RTW_TX_QUEUE_VO,
>> +	[IEEE80211_AC_VI] = RTW_TX_QUEUE_VI,
>> +	[IEEE80211_AC_BE] = RTW_TX_QUEUE_BE,
>> +	[IEEE80211_AC_BK] = RTW_TX_QUEUE_BK,
>> +};
>> +
>> +static_assert(ARRAY_SIZE(ac_to_hwq) == IEEE80211_NUM_ACS);
>> +
>> +enum rtw_tx_queue_type rtw_tx_ac_to_hwq(enum ieee80211_ac_numbers ac)
>> +{
>> +	return ac_to_hwq[ac];
>> +}
>> +EXPORT_SYMBOL(rtw_tx_ac_to_hwq);
>> +
>
> Could I know why we can't just export the array ac_to_hwq[]?
> Is there a strict rule?

I was about to answer that with a helper function it's easier to catch
out of bands access, but then noticed the helper doesn't have a check
for that. Should it have one?
Martin Blumenstingl Jan. 23, 2022, 6:34 p.m. UTC | #3
Hi Kalle,

On Wed, Jan 19, 2022 at 7:20 AM Kalle Valo <kvalo@kernel.org> wrote:
[...]
> I was about to answer that with a helper function it's easier to catch
> out of bands access, but then noticed the helper doesn't have a check
> for that. Should it have one?
you mean something like:
    if (ac >= IEEE80211_NUM_ACS)
        return RTW_TX_QUEUE_BE;

Possibly also with a WARN_ON/WARN_ON_ONCE


Best regards,
Martin
Kalle Valo Jan. 27, 2022, 12:11 p.m. UTC | #4
Martin Blumenstingl <martin.blumenstingl@googlemail.com> writes:

> Hi Kalle,
>
> On Wed, Jan 19, 2022 at 7:20 AM Kalle Valo <kvalo@kernel.org> wrote:
> [...]
>> I was about to answer that with a helper function it's easier to catch
>> out of bands access, but then noticed the helper doesn't have a check
>> for that. Should it have one?
>
> you mean something like:
>     if (ac >= IEEE80211_NUM_ACS)
>         return RTW_TX_QUEUE_BE;
>
> Possibly also with a WARN_ON/WARN_ON_ONCE

Yeah, something like that would be good.
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c
index 2da057d18188..945411a5947b 100644
--- a/drivers/net/wireless/realtek/rtw88/pci.c
+++ b/drivers/net/wireless/realtek/rtw88/pci.c
@@ -670,34 +670,6 @@  static void rtw_pci_deep_ps(struct rtw_dev *rtwdev, bool enter)
 	spin_unlock_bh(&rtwpci->irq_lock);
 }
 
-static enum rtw_tx_queue_type ac_to_hwq[] = {
-	[IEEE80211_AC_VO] = RTW_TX_QUEUE_VO,
-	[IEEE80211_AC_VI] = RTW_TX_QUEUE_VI,
-	[IEEE80211_AC_BE] = RTW_TX_QUEUE_BE,
-	[IEEE80211_AC_BK] = RTW_TX_QUEUE_BK,
-};
-
-static_assert(ARRAY_SIZE(ac_to_hwq) == IEEE80211_NUM_ACS);
-
-static enum rtw_tx_queue_type rtw_hw_queue_mapping(struct sk_buff *skb)
-{
-	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
-	__le16 fc = hdr->frame_control;
-	u8 q_mapping = skb_get_queue_mapping(skb);
-	enum rtw_tx_queue_type queue;
-
-	if (unlikely(ieee80211_is_beacon(fc)))
-		queue = RTW_TX_QUEUE_BCN;
-	else if (unlikely(ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)))
-		queue = RTW_TX_QUEUE_MGMT;
-	else if (WARN_ON_ONCE(q_mapping >= ARRAY_SIZE(ac_to_hwq)))
-		queue = ac_to_hwq[IEEE80211_AC_BE];
-	else
-		queue = ac_to_hwq[q_mapping];
-
-	return queue;
-}
-
 static void rtw_pci_release_rsvd_page(struct rtw_pci *rtwpci,
 				      struct rtw_pci_tx_ring *ring)
 {
@@ -795,7 +767,7 @@  static void rtw_pci_flush_queues(struct rtw_dev *rtwdev, u32 queues, bool drop)
 	} else {
 		for (i = 0; i < rtwdev->hw->queues; i++)
 			if (queues & BIT(i))
-				pci_queues |= BIT(ac_to_hwq[i]);
+				pci_queues |= BIT(rtw_tx_ac_to_hwq(i));
 	}
 
 	__rtw_pci_flush_queues(rtwdev, pci_queues, drop);
@@ -949,7 +921,7 @@  static int rtw_pci_tx_write(struct rtw_dev *rtwdev,
 			    struct rtw_tx_pkt_info *pkt_info,
 			    struct sk_buff *skb)
 {
-	enum rtw_tx_queue_type queue = rtw_hw_queue_mapping(skb);
+	enum rtw_tx_queue_type queue = rtw_tx_queue_mapping(skb);
 	struct rtw_pci *rtwpci = (struct rtw_pci *)rtwdev->priv;
 	struct rtw_pci_tx_ring *ring;
 	int ret;
diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c
index efcc1b0371a8..ec6a3683c3f8 100644
--- a/drivers/net/wireless/realtek/rtw88/tx.c
+++ b/drivers/net/wireless/realtek/rtw88/tx.c
@@ -665,3 +665,38 @@  void rtw_txq_cleanup(struct rtw_dev *rtwdev, struct ieee80211_txq *txq)
 		list_del_init(&rtwtxq->list);
 	spin_unlock_bh(&rtwdev->txq_lock);
 }
+
+static enum rtw_tx_queue_type ac_to_hwq[] = {
+	[IEEE80211_AC_VO] = RTW_TX_QUEUE_VO,
+	[IEEE80211_AC_VI] = RTW_TX_QUEUE_VI,
+	[IEEE80211_AC_BE] = RTW_TX_QUEUE_BE,
+	[IEEE80211_AC_BK] = RTW_TX_QUEUE_BK,
+};
+
+static_assert(ARRAY_SIZE(ac_to_hwq) == IEEE80211_NUM_ACS);
+
+enum rtw_tx_queue_type rtw_tx_ac_to_hwq(enum ieee80211_ac_numbers ac)
+{
+	return ac_to_hwq[ac];
+}
+EXPORT_SYMBOL(rtw_tx_ac_to_hwq);
+
+enum rtw_tx_queue_type rtw_tx_queue_mapping(struct sk_buff *skb)
+{
+	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+	__le16 fc = hdr->frame_control;
+	u8 q_mapping = skb_get_queue_mapping(skb);
+	enum rtw_tx_queue_type queue;
+
+	if (unlikely(ieee80211_is_beacon(fc)))
+		queue = RTW_TX_QUEUE_BCN;
+	else if (unlikely(ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)))
+		queue = RTW_TX_QUEUE_MGMT;
+	else if (WARN_ON_ONCE(q_mapping >= ARRAY_SIZE(ac_to_hwq)))
+		queue = ac_to_hwq[IEEE80211_AC_BE];
+	else
+		queue = ac_to_hwq[q_mapping];
+
+	return queue;
+}
+EXPORT_SYMBOL(rtw_tx_queue_mapping);
diff --git a/drivers/net/wireless/realtek/rtw88/tx.h b/drivers/net/wireless/realtek/rtw88/tx.h
index 56371eff9f7f..940f944fd39c 100644
--- a/drivers/net/wireless/realtek/rtw88/tx.h
+++ b/drivers/net/wireless/realtek/rtw88/tx.h
@@ -119,4 +119,7 @@  rtw_tx_write_data_h2c_get(struct rtw_dev *rtwdev,
 			  struct rtw_tx_pkt_info *pkt_info,
 			  u8 *buf, u32 size);
 
+enum rtw_tx_queue_type rtw_tx_ac_to_hwq(enum ieee80211_ac_numbers ac);
+enum rtw_tx_queue_type rtw_tx_queue_mapping(struct sk_buff *skb);
+
 #endif