public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH 04/10] mt76: move mcu timeout handling to .mcu_parse_response
Date: Wed, 30 Sep 2020 14:24:35 +0200	[thread overview]
Message-ID: <20200930122441.64523-4-nbd@nbd.name> (raw)
In-Reply-To: <20200930122441.64523-1-nbd@nbd.name>

Preparation for further cleanup

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../net/wireless/mediatek/mt76/mt7603/mcu.c   | 21 ++++++++++---------
 .../net/wireless/mediatek/mt76/mt7615/mcu.c   | 15 ++++++-------
 .../net/wireless/mediatek/mt76/mt76x02_mcu.c  | 21 ++++++++++---------
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 15 ++++++-------
 4 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7603/mcu.c
index 6cd947df6429..f787c9d3088e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7603/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7603/mcu.c
@@ -17,8 +17,18 @@ static int
 mt7603_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			  struct sk_buff *skb, int seq)
 {
-	struct mt7603_mcu_rxd *rxd = (struct mt7603_mcu_rxd *)skb->data;
+	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
+	struct mt7603_mcu_rxd *rxd;
+
+	if (!skb) {
+		dev_err(mdev->dev,
+			"MCU message %d (seq %d) timed out\n",
+			cmd, seq);
+		dev->mcu_hang = MT7603_WATCHDOG_TIMEOUT;
+		return -ETIMEDOUT;
+	}
 
+	rxd = (struct mt7603_mcu_rxd *)skb->data;
 	if (seq != rxd->seq)
 		return -EAGAIN;
 
@@ -85,15 +95,6 @@ mt7603_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
 
 	while (wait_resp) {
 		skb = mt76_mcu_get_response(&dev->mt76, expires);
-		if (!skb) {
-			dev_err(mdev->dev,
-				"MCU message %d (seq %d) timed out\n",
-				cmd, seq);
-			dev->mcu_hang = MT7603_WATCHDOG_TIMEOUT;
-			ret = -ETIMEDOUT;
-			break;
-		}
-
 		ret = mt7603_mcu_parse_response(mdev, cmd, skb, seq);
 		dev_kfree_skb(skb);
 		if (ret != -EAGAIN)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
index f042299b110e..fb0dce401b9a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
@@ -182,9 +182,16 @@ static int __mt7615_mcu_msg_send(struct mt7615_dev *dev, struct sk_buff *skb,
 int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			      struct sk_buff *skb, int seq)
 {
-	struct mt7615_mcu_rxd *rxd = (struct mt7615_mcu_rxd *)skb->data;
+	struct mt7615_mcu_rxd *rxd;
 	int ret = 0;
 
+	if (!skb) {
+		dev_err(mdev->dev, "Message %ld (seq %d) timeout\n",
+			cmd & MCU_CMD_MASK, seq);
+		return -ETIMEDOUT;
+	}
+
+	rxd = (struct mt7615_mcu_rxd *)skb->data;
 	if (seq != rxd->seq)
 		return -EAGAIN;
 
@@ -238,12 +245,6 @@ int mt7615_mcu_wait_response(struct mt7615_dev *dev, int cmd, int seq)
 
 	while (true) {
 		skb = mt76_mcu_get_response(&dev->mt76, expires);
-		if (!skb) {
-			dev_err(dev->mt76.dev, "Message %ld (seq %d) timeout\n",
-				cmd & MCU_CMD_MASK, seq);
-			return -ETIMEDOUT;
-		}
-
 		ret = mt7615_mcu_parse_response(&dev->mt76, cmd, skb, seq);
 		dev_kfree_skb(skb);
 		if (ret != -EAGAIN)
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
index e35b3a253f82..3b2184254ae9 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.c
@@ -13,8 +13,18 @@
 int mt76x02_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			       struct sk_buff *skb, int seq)
 {
-	u32 *rxfce = (u32 *)skb->cb;
+	struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
+	u32 *rxfce;
+
+	if (!skb) {
+		dev_err(mdev->dev,
+			"MCU message %d (seq %d) timed out\n", cmd,
+			seq);
+		dev->mcu_timeout = 1;
+		return -ETIMEDOUT;
+	}
 
+	rxfce = (u32 *)skb->cb;
 	if (seq != FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, *rxfce))
 		return -EAGAIN;
 
@@ -57,15 +67,6 @@ int mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
 
 	while (wait_resp) {
 		skb = mt76_mcu_get_response(&dev->mt76, expires);
-		if (!skb) {
-			dev_err(mdev->dev,
-				"MCU message %d (seq %d) timed out\n", cmd,
-				seq);
-			ret = -ETIMEDOUT;
-			dev->mcu_timeout = 1;
-			break;
-		}
-
 		ret = mt76x02_mcu_parse_response(mdev, cmd, skb, seq);
 		dev_kfree_skb(skb);
 		if (ret != -EAGAIN)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index 946fe139b9f7..e89fb44f8d75 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -313,9 +313,16 @@ mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd,
 			  struct sk_buff *skb, int seq)
 {
 	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
-	struct mt7915_mcu_rxd *rxd = (struct mt7915_mcu_rxd *)skb->data;
+	struct mt7915_mcu_rxd *rxd;
 	int ret = 0;
 
+	if (!skb) {
+		dev_err(mdev->dev, "Message %d (seq %d) timeout\n",
+			cmd, seq);
+		return -ETIMEDOUT;
+	}
+
+	rxd = (struct mt7915_mcu_rxd *)skb->data;
 	if (seq != rxd->seq)
 		return -EAGAIN;
 
@@ -347,12 +354,6 @@ mt7915_mcu_wait_response(struct mt7915_dev *dev, int cmd, int seq)
 
 	while (true) {
 		skb = mt76_mcu_get_response(&dev->mt76, expires);
-		if (!skb) {
-			dev_err(dev->mt76.dev, "Message %d (seq %d) timeout\n",
-				cmd, seq);
-			return -ETIMEDOUT;
-		}
-
 		ret = mt7915_mcu_parse_response(&dev->mt76, cmd, skb, seq);
 		dev_kfree_skb(skb);
 		if (ret != -EAGAIN)
-- 
2.28.0


  parent reply	other threads:[~2020-09-30 12:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 12:24 [PATCH 01/10] mt76: rename __mt76_mcu_send_msg to mt76_mcu_send_msg Felix Fietkau
2020-09-30 12:24 ` [PATCH 02/10] mt76: rename __mt76_mcu_skb_send_msg to mt76_mcu_skb_send_msg Felix Fietkau
2020-09-30 12:24 ` [PATCH 03/10] mt76: implement .mcu_parse_response in struct mt76_mcu_ops Felix Fietkau
2020-09-30 12:24 ` Felix Fietkau [this message]
2020-09-30 12:24 ` [PATCH 05/10] mt76: move waiting and locking out of mcu_ops->mcu_skb_send_msg Felix Fietkau
2020-09-30 12:24 ` [PATCH 06/10] mt76: make mcu_ops->mcu_send_msg optional Felix Fietkau
2020-09-30 12:24 ` [PATCH 07/10] mt76: mt7603: switch to .mcu_skb_send_msg Felix Fietkau
2020-09-30 12:24 ` [PATCH 08/10] mt76: implement functions to get the response skb for MCU calls Felix Fietkau
2020-09-30 12:24 ` [PATCH 09/10] mt76: mt7915: move eeprom parsing out of mt7915_mcu_parse_response Felix Fietkau
2020-09-30 12:24 ` [PATCH 10/10] mt76: mt7915: query station rx rate from firmware Felix Fietkau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200930122441.64523-4-nbd@nbd.name \
    --to=nbd@nbd.name \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox