diff mbox series

[2/7] mt76: mt7915: rely on mt76_connac_mcu_alloc_wtbl_req

Message ID de5be711eae18d4d471ec142616a35a5247ab83b.1639763123.git.lorenzo@kernel.org
State New
Headers show
Series introduce mt76-connac dependency in mt7915 driver | expand

Commit Message

Lorenzo Bianconi Dec. 17, 2021, 5:48 p.m. UTC
Rely on mt76_connac_mcu_alloc_wtbl_req routine and remove
duplicated code.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../wireless/mediatek/mt76/mt76_connac_mcu.c  |  8 +++-
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 43 ++++---------------
 2 files changed, 15 insertions(+), 36 deletions(-)

Comments

Felix Fietkau Dec. 18, 2021, 8:45 p.m. UTC | #1
On 2021-12-17 18:48, Lorenzo Bianconi wrote:
> Rely on mt76_connac_mcu_alloc_wtbl_req routine and remove
> duplicated code.
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>   .../wireless/mediatek/mt76/mt76_connac_mcu.c  |  8 +++-
>   .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 43 ++++---------------
>   2 files changed, 15 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
> index fc5c870da420..ee512651d9f1 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
> @@ -309,8 +309,12 @@ mt76_connac_mcu_alloc_wtbl_req(struct mt76_dev *dev, struct mt76_wcid *wcid,
>   		*skb = nskb;
>   	}
>   
> -	if (sta_hdr)
> -		sta_hdr->len = cpu_to_le16(sizeof(hdr));
> +	if (sta_hdr) {
> +		if (is_mt7915(dev))
> +			le16_add_cpu(&sta_hdr->len, sizeof(hdr));
> +		else
> +			sta_hdr->len = cpu_to_le16(sizeof(hdr));
> +	}
>   
>   	return skb_put_data(nskb, &hdr, sizeof(hdr));
>   }
The change from the len assignment to addition was done as a bugfix in 
mt7915. I think it's likely that the assignment is buggy in the connac 
code as well and should be changed to match mt7915.

- Felix
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index fc5c870da420..ee512651d9f1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -309,8 +309,12 @@  mt76_connac_mcu_alloc_wtbl_req(struct mt76_dev *dev, struct mt76_wcid *wcid,
 		*skb = nskb;
 	}
 
-	if (sta_hdr)
-		sta_hdr->len = cpu_to_le16(sizeof(hdr));
+	if (sta_hdr) {
+		if (is_mt7915(dev))
+			le16_add_cpu(&sta_hdr->len, sizeof(hdr));
+		else
+			sta_hdr->len = cpu_to_le16(sizeof(hdr));
+	}
 
 	return skb_put_data(nskb, &hdr, sizeof(hdr));
 }
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 6ad6eaef3c87..840df0498676 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -574,33 +574,6 @@  void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb)
 		mt76_mcu_rx_event(&dev->mt76, skb);
 }
 
-static struct wtbl_req_hdr *
-mt7915_mcu_alloc_wtbl_req(struct mt7915_dev *dev, struct mt7915_sta *msta,
-			  int cmd, void *sta_wtbl, struct sk_buff **skb)
-{
-	struct tlv *sta_hdr = sta_wtbl;
-	struct wtbl_req_hdr hdr = {
-		.wlan_idx_lo = to_wcid_lo(msta->wcid.idx),
-		.wlan_idx_hi = to_wcid_hi(msta->wcid.idx),
-		.operation = cmd,
-	};
-	struct sk_buff *nskb = *skb;
-
-	if (!nskb) {
-		nskb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
-					  MT76_CONNAC_WTBL_UPDATE_MAX_SIZE);
-		if (!nskb)
-			return ERR_PTR(-ENOMEM);
-
-		*skb = nskb;
-	}
-
-	if (sta_hdr)
-		le16_add_cpu(&sta_hdr->len, sizeof(hdr));
-
-	return skb_put_data(nskb, &hdr, sizeof(hdr));
-}
-
 static struct tlv *
 mt7915_mcu_add_nested_tlv(struct sk_buff *skb, int tag, int len,
 			  void *sta_ntlv, void *sta_wtbl)
@@ -1187,8 +1160,8 @@  mt7915_mcu_sta_ba(struct mt7915_dev *dev,
 
 	sta_wtbl = mt7915_mcu_add_tlv(skb, STA_REC_WTBL, sizeof(struct tlv));
 
-	wtbl_hdr = mt7915_mcu_alloc_wtbl_req(dev, msta, WTBL_SET, sta_wtbl,
-					     &skb);
+	wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(&dev->mt76, &msta->wcid,
+						  WTBL_SET, sta_wtbl, &skb);
 	if (IS_ERR(wtbl_hdr))
 		return PTR_ERR(wtbl_hdr);
 
@@ -1693,8 +1666,9 @@  mt7915_mcu_sta_wtbl_tlv(struct mt7915_dev *dev, struct sk_buff *skb,
 	msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta;
 
 	tlv = mt7915_mcu_add_tlv(skb, STA_REC_WTBL, sizeof(struct tlv));
-	wtbl_hdr = mt7915_mcu_alloc_wtbl_req(dev, msta, WTBL_RESET_AND_SET,
-					     tlv, &skb);
+	wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(&dev->mt76, &msta->wcid,
+						  WTBL_RESET_AND_SET, tlv,
+						  &skb);
 	if (IS_ERR(wtbl_hdr))
 		return PTR_ERR(wtbl_hdr);
 
@@ -1720,7 +1694,8 @@  int mt7915_mcu_sta_update_hdr_trans(struct mt7915_dev *dev,
 	if (!skb)
 		return -ENOMEM;
 
-	wtbl_hdr = mt7915_mcu_alloc_wtbl_req(dev, msta, WTBL_SET, NULL, &skb);
+	wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(&dev->mt76, &msta->wcid,
+						  WTBL_SET, NULL, &skb);
 	if (IS_ERR(wtbl_hdr))
 		return PTR_ERR(wtbl_hdr);
 
@@ -2074,8 +2049,8 @@  int mt7915_mcu_add_smps(struct mt7915_dev *dev, struct ieee80211_vif *vif,
 
 	sta_wtbl = mt7915_mcu_add_tlv(skb, STA_REC_WTBL, sizeof(struct tlv));
 
-	wtbl_hdr = mt7915_mcu_alloc_wtbl_req(dev, msta, WTBL_SET, sta_wtbl,
-					     &skb);
+	wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(&dev->mt76, &msta->wcid,
+						  WTBL_SET, sta_wtbl, &skb);
 	if (IS_ERR(wtbl_hdr))
 		return PTR_ERR(wtbl_hdr);