linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads
@ 2019-02-20 10:12 Stanislaw Gruszka
  2019-02-20 10:12 ` [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses Stanislaw Gruszka
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-02-20 10:12 UTC (permalink / raw)
  To: Felix Fietkau; +Cc: linux-wireless, Lorenzo Bianconi

Extend mt76u_bulk_msg() such it can be used for synchronous bulk reads.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 drivers/net/wireless/mediatek/mt76/mt76.h            | 13 ++++++++++---
 drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c |  4 ++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index f55dc621e060..45e44bcaa523 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -729,7 +729,8 @@ static inline u8 q2ep(u8 qid)
 }
 
 static inline int
-mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout)
+mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len,
+	       int timeout)
 {
 	struct usb_interface *intf = to_usb_interface(dev->dev);
 	struct usb_device *udev = interface_to_usbdev(intf);
@@ -737,8 +738,14 @@ mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout)
 	unsigned int pipe;
 	int sent;
 
-	pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
-	return usb_bulk_msg(udev, pipe, data, len, &sent, timeout);
+	if (actual_len) {
+		pipe = usb_rcvbulkpipe(udev, usb->in_ep[MT_EP_IN_CMD_RESP]);
+	} else {
+		actual_len = &sent;
+		pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
+	}
+
+	return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout);
 }
 
 int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
index e469e383cb88..f497c8e4332a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
@@ -126,7 +126,7 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
 	if (ret)
 		return ret;
 
-	ret = mt76u_bulk_msg(dev, skb->data, skb->len, 500);
+	ret = mt76u_bulk_msg(dev, skb->data, skb->len, NULL, 500);
 	if (ret)
 		return ret;
 
@@ -271,7 +271,7 @@ __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, u8 *data,
 
 	data_len = MT_CMD_HDR_LEN + len + sizeof(info);
 
-	err = mt76u_bulk_msg(&dev->mt76, data, data_len, 1000);
+	err = mt76u_bulk_msg(&dev->mt76, data, data_len, NULL, 1000);
 	if (err) {
 		dev_err(dev->mt76.dev, "firmware upload failed: %d\n", err);
 		return err;
-- 
2.7.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses
  2019-02-20 10:12 [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Stanislaw Gruszka
@ 2019-02-20 10:12 ` Stanislaw Gruszka
  2019-02-20 10:38   ` Lorenzo Bianconi
  2019-02-20 10:12 ` [PATCH 3/3] mt76usb: remove usb_mcu.c Stanislaw Gruszka
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-02-20 10:12 UTC (permalink / raw)
  To: Felix Fietkau; +Cc: linux-wireless, Lorenzo Bianconi

Use usb_bulk_msg for reading MCU command responses. This simplify code
a lot.

Together with 97a3005759c ("mt76usb: allow mt76u_bulk_msg be used
for reads") it also fix possible problems with rx data buffers
not being aligned and contained within single page. After doing
page_frag_alloc(1024) consecutive page_frag_alloc(PAGE_SIZE) will
alloc PAGE_SIZE buffer at PAGE_SIZE - 1024 offset.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 drivers/net/wireless/mediatek/mt76/mt76.h          |  3 +-
 drivers/net/wireless/mediatek/mt76/mt76x0/usb.c    | 11 --------
 .../net/wireless/mediatek/mt76/mt76x02_usb_mcu.c   | 32 +++++++---------------
 drivers/net/wireless/mediatek/mt76/mt76x2/usb.c    | 11 --------
 drivers/net/wireless/mediatek/mt76/usb.c           |  1 -
 drivers/net/wireless/mediatek/mt76/usb_mcu.c       | 31 +++------------------
 6 files changed, 15 insertions(+), 74 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 45e44bcaa523..ce53069461ec 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -384,8 +384,7 @@ struct mt76_usb {
 
 	struct mt76u_mcu {
 		struct mutex mutex;
-		struct completion cmpl;
-		struct mt76u_buf res;
+		u8 *data;
 		u32 msg_seq;
 
 		/* multiple reads */
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
index da9d05f6074d..f0c33890f1a5 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
@@ -311,13 +311,11 @@ static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf,
 					 pm_message_t state)
 {
 	struct mt76x02_dev *dev = usb_get_intfdata(usb_intf);
-	struct mt76_usb *usb = &dev->mt76.usb;
 
 	mt76u_stop_queues(&dev->mt76);
 	mt76x0u_mac_stop(dev);
 	clear_bit(MT76_STATE_MCU_RUNNING, &dev->mt76.state);
 	mt76x0_chip_onoff(dev, false, false);
-	usb_kill_urb(usb->mcu.res.urb);
 
 	return 0;
 }
@@ -328,15 +326,6 @@ static int __maybe_unused mt76x0_resume(struct usb_interface *usb_intf)
 	struct mt76_usb *usb = &dev->mt76.usb;
 	int ret;
 
-	reinit_completion(&usb->mcu.cmpl);
-	ret = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
-			       MT_EP_IN_CMD_RESP,
-			       &usb->mcu.res, GFP_KERNEL,
-			       mt76u_mcu_complete_urb,
-			       &usb->mcu.cmpl);
-	if (ret < 0)
-		goto err;
-
 	ret = mt76u_submit_rx_buffers(&dev->mt76);
 	if (ret < 0)
 		goto err;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
index f497c8e4332a..0cb8751321a1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
@@ -61,33 +61,21 @@ mt76x02u_multiple_mcu_reads(struct mt76_dev *dev, u8 *data, int len)
 static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
 {
 	struct mt76_usb *usb = &dev->usb;
-	struct mt76u_buf *buf = &usb->mcu.res;
-	struct urb *urb = buf->urb;
-	u8 *data = buf->buf;
-	int i, ret;
+	u8 *data = usb->mcu.data;
+	int i, len, ret;
 	u32 rxfce;
 
 	for (i = 0; i < 5; i++) {
-		if (!wait_for_completion_timeout(&usb->mcu.cmpl,
-						 msecs_to_jiffies(300)))
+		ret = mt76u_bulk_msg(dev, data, MCU_RESP_URB_SIZE, &len, 300);
+		if (ret == -ETIMEDOUT)
 			continue;
-
-		if (urb->status)
-			return -EIO;
+		if (ret)
+			goto out;
 
 		if (usb->mcu.rp)
-			mt76x02u_multiple_mcu_reads(dev, data + 4,
-						    urb->actual_length - 8);
+			mt76x02u_multiple_mcu_reads(dev, data + 4, len - 8);
 
 		rxfce = get_unaligned_le32(data);
-		ret = mt76u_submit_buf(dev, USB_DIR_IN,
-				       MT_EP_IN_CMD_RESP,
-				       buf, GFP_KERNEL,
-				       mt76u_mcu_complete_urb,
-				       &usb->mcu.cmpl);
-		if (ret)
-			return ret;
-
 		if (seq == FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce) &&
 		    FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce) == EVT_CMD_DONE)
 			return 0;
@@ -96,9 +84,9 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
 			FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce),
 			seq, FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce));
 	}
-
-	dev_err(dev->dev, "error: %s timed out\n", __func__);
-	return -ETIMEDOUT;
+out:
+	dev_err(dev->dev, "error: %s failed with %d\n", __func__, ret);
+	return ret;
 }
 
 static int
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
index f81a85e96922..ddb6b2c48e01 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
@@ -100,11 +100,9 @@ static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
 					  pm_message_t state)
 {
 	struct mt76x02_dev *dev = usb_get_intfdata(intf);
-	struct mt76_usb *usb = &dev->mt76.usb;
 
 	mt76u_stop_queues(&dev->mt76);
 	mt76x2u_stop_hw(dev);
-	usb_kill_urb(usb->mcu.res.urb);
 
 	return 0;
 }
@@ -115,15 +113,6 @@ static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
 	struct mt76_usb *usb = &dev->mt76.usb;
 	int err;
 
-	reinit_completion(&usb->mcu.cmpl);
-	err = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
-			       MT_EP_IN_CMD_RESP,
-			       &usb->mcu.res, GFP_KERNEL,
-			       mt76u_mcu_complete_urb,
-			       &usb->mcu.cmpl);
-	if (err < 0)
-		goto err;
-
 	err = mt76u_submit_rx_buffers(&dev->mt76);
 	if (err < 0)
 		goto err;
diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index 78191968b4fa..5c3b7f735aae 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -933,7 +933,6 @@ int mt76u_init(struct mt76_dev *dev,
 	INIT_DELAYED_WORK(&usb->stat_work, mt76u_tx_status_data);
 	skb_queue_head_init(&dev->rx_skb[MT_RXQ_MAIN]);
 
-	init_completion(&usb->mcu.cmpl);
 	mutex_init(&usb->mcu.mutex);
 
 	mutex_init(&usb->usb_ctrl_mtx);
diff --git a/drivers/net/wireless/mediatek/mt76/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/usb_mcu.c
index 72c8607da4b4..747231edc57d 100644
--- a/drivers/net/wireless/mediatek/mt76/usb_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/usb_mcu.c
@@ -16,42 +16,19 @@
 
 #include "mt76.h"
 
-void mt76u_mcu_complete_urb(struct urb *urb)
-{
-	struct completion *cmpl = urb->context;
-
-	complete(cmpl);
-}
-EXPORT_SYMBOL_GPL(mt76u_mcu_complete_urb);
-
 int mt76u_mcu_init_rx(struct mt76_dev *dev)
 {
 	struct mt76_usb *usb = &dev->usb;
-	int err;
 
-	err = mt76u_buf_alloc(dev, &usb->mcu.res, MCU_RESP_URB_SIZE,
-			      MCU_RESP_URB_SIZE, GFP_KERNEL);
-	if (err < 0)
-		return err;
-
-	err = mt76u_submit_buf(dev, USB_DIR_IN, MT_EP_IN_CMD_RESP,
-			       &usb->mcu.res, GFP_KERNEL,
-			       mt76u_mcu_complete_urb,
-			       &usb->mcu.cmpl);
-	if (err < 0)
-		mt76u_buf_free(&usb->mcu.res);
-
-	return err;
+	usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);
+	return usb->mcu.data ? 0 : -ENOMEM;
 }
 EXPORT_SYMBOL_GPL(mt76u_mcu_init_rx);
 
 void mt76u_mcu_deinit(struct mt76_dev *dev)
 {
-	struct mt76u_buf *buf = &dev->usb.mcu.res;
+	struct mt76_usb *usb = &dev->usb;
 
-	if (buf->urb) {
-		usb_kill_urb(buf->urb);
-		mt76u_buf_free(buf);
-	}
+	kfree(usb->mcu.data);
 }
 EXPORT_SYMBOL_GPL(mt76u_mcu_deinit);
-- 
2.7.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] mt76usb: remove usb_mcu.c
  2019-02-20 10:12 [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Stanislaw Gruszka
  2019-02-20 10:12 ` [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses Stanislaw Gruszka
@ 2019-02-20 10:12 ` Stanislaw Gruszka
  2019-02-20 10:41   ` Lorenzo Bianconi
  2019-02-20 10:31 ` [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Lorenzo Bianconi
  2019-02-20 11:28 ` Lorenzo Bianconi
  3 siblings, 1 reply; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-02-20 10:12 UTC (permalink / raw)
  To: Felix Fietkau; +Cc: linux-wireless, Lorenzo Bianconi

Don't need separate file just for kmalloc/kfree.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 drivers/net/wireless/mediatek/mt76/mt76.h          |  2 --
 drivers/net/wireless/mediatek/mt76/mt76x0/usb.c    |  5 ----
 .../net/wireless/mediatek/mt76/mt76x2/usb_init.c   |  5 ----
 drivers/net/wireless/mediatek/mt76/usb.c           |  8 +++++
 drivers/net/wireless/mediatek/mt76/usb_mcu.c       | 34 ----------------------
 5 files changed, 8 insertions(+), 46 deletions(-)
 delete mode 100644 drivers/net/wireless/mediatek/mt76/usb_mcu.c

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index ce53069461ec..972f0ca7c818 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -774,7 +774,5 @@ struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev,
 				      unsigned long expires);
 
 void mt76u_mcu_complete_urb(struct urb *urb);
-int mt76u_mcu_init_rx(struct mt76_dev *dev);
-void mt76u_mcu_deinit(struct mt76_dev *dev);
 
 #endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
index f0c33890f1a5..91718647da02 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
@@ -79,7 +79,6 @@ static void mt76x0u_cleanup(struct mt76x02_dev *dev)
 	clear_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
 	mt76x0_chip_onoff(dev, false, false);
 	mt76u_queues_deinit(&dev->mt76);
-	mt76u_mcu_deinit(&dev->mt76);
 }
 
 static void mt76x0u_mac_stop(struct mt76x02_dev *dev)
@@ -193,10 +192,6 @@ static int mt76x0u_register_device(struct mt76x02_dev *dev)
 	if (err < 0)
 		goto out_err;
 
-	err = mt76u_mcu_init_rx(&dev->mt76);
-	if (err < 0)
-		goto out_err;
-
 	err = mt76x0u_init_hardware(dev);
 	if (err < 0)
 		goto out_err;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
index 090aaf71b3ef..1da90e58d942 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
@@ -214,10 +214,6 @@ int mt76x2u_register_device(struct mt76x02_dev *dev)
 	if (err < 0)
 		goto fail;
 
-	err = mt76u_mcu_init_rx(&dev->mt76);
-	if (err < 0)
-		goto fail;
-
 	err = mt76x2u_init_hardware(dev);
 	if (err < 0)
 		goto fail;
@@ -259,5 +255,4 @@ void mt76x2u_cleanup(struct mt76x02_dev *dev)
 	mt76x02_mcu_set_radio_state(dev, false);
 	mt76x2u_stop_hw(dev);
 	mt76u_queues_deinit(&dev->mt76);
-	mt76u_mcu_deinit(&dev->mt76);
 }
diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index 5c3b7f735aae..4fe025b92302 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -577,9 +577,14 @@ EXPORT_SYMBOL_GPL(mt76u_submit_rx_buffers);
 
 static int mt76u_alloc_rx(struct mt76_dev *dev)
 {
+	struct mt76_usb *usb = &dev->usb;
 	struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
 	int i, err;
 
+	usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);
+	if (usb->mcu.data)
+		return -ENOMEM;
+
 	spin_lock_init(&q->rx_page_lock);
 	spin_lock_init(&q->lock);
 	q->entry = devm_kcalloc(dev->dev,
@@ -610,6 +615,7 @@ static int mt76u_alloc_rx(struct mt76_dev *dev)
 
 static void mt76u_free_rx(struct mt76_dev *dev)
 {
+	struct mt76_usb *usb = &dev->usb;
 	struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
 	struct page *page;
 	int i;
@@ -626,6 +632,8 @@ static void mt76u_free_rx(struct mt76_dev *dev)
 	memset(&q->rx_page, 0, sizeof(q->rx_page));
 out:
 	spin_unlock_bh(&q->rx_page_lock);
+
+	kfree(usb->mcu.data);
 }
 
 static void mt76u_stop_rx(struct mt76_dev *dev)
diff --git a/drivers/net/wireless/mediatek/mt76/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/usb_mcu.c
deleted file mode 100644
index 747231edc57d..000000000000
--- a/drivers/net/wireless/mediatek/mt76/usb_mcu.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "mt76.h"
-
-int mt76u_mcu_init_rx(struct mt76_dev *dev)
-{
-	struct mt76_usb *usb = &dev->usb;
-
-	usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);
-	return usb->mcu.data ? 0 : -ENOMEM;
-}
-EXPORT_SYMBOL_GPL(mt76u_mcu_init_rx);
-
-void mt76u_mcu_deinit(struct mt76_dev *dev)
-{
-	struct mt76_usb *usb = &dev->usb;
-
-	kfree(usb->mcu.data);
-}
-EXPORT_SYMBOL_GPL(mt76u_mcu_deinit);
-- 
2.7.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads
  2019-02-20 10:12 [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Stanislaw Gruszka
  2019-02-20 10:12 ` [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses Stanislaw Gruszka
  2019-02-20 10:12 ` [PATCH 3/3] mt76usb: remove usb_mcu.c Stanislaw Gruszka
@ 2019-02-20 10:31 ` Lorenzo Bianconi
  2019-02-20 11:28 ` Lorenzo Bianconi
  3 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-02-20 10:31 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Felix Fietkau, linux-wireless

> Extend mt76u_bulk_msg() such it can be used for synchronous bulk reads.
> 
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt76.h            | 13 ++++++++++---
>  drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c |  4 ++--
>  2 files changed, 12 insertions(+), 5 deletions(-)
> 

[...]

> @@ -737,8 +738,14 @@ mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout)
>  	unsigned int pipe;
>  	int sent;
>  
> -	pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
> -	return usb_bulk_msg(udev, pipe, data, len, &sent, timeout);
> +	if (actual_len) {
> +		pipe = usb_rcvbulkpipe(udev, usb->in_ep[MT_EP_IN_CMD_RESP]);
> +	} else {
> +		actual_len = &sent;
> +		pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);

Hi Stanislaw,

I guess you can drop sent here since even if actual_len is NULL it will be managed
by usb_start_wait_urb()

Regards,
Lorenzo

> +	}
> +
> +	return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout);
>  }
>  
>  int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> index e469e383cb88..f497c8e4332a 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> @@ -126,7 +126,7 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
>  	if (ret)
>  		return ret;
>  
> -	ret = mt76u_bulk_msg(dev, skb->data, skb->len, 500);
> +	ret = mt76u_bulk_msg(dev, skb->data, skb->len, NULL, 500);
>  	if (ret)
>  		return ret;
>  
> @@ -271,7 +271,7 @@ __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, u8 *data,
>  
>  	data_len = MT_CMD_HDR_LEN + len + sizeof(info);
>  
> -	err = mt76u_bulk_msg(&dev->mt76, data, data_len, 1000);
> +	err = mt76u_bulk_msg(&dev->mt76, data, data_len, NULL, 1000);
>  	if (err) {
>  		dev_err(dev->mt76.dev, "firmware upload failed: %d\n", err);
>  		return err;
> -- 
> 2.7.5
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses
  2019-02-20 10:12 ` [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses Stanislaw Gruszka
@ 2019-02-20 10:38   ` Lorenzo Bianconi
  0 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-02-20 10:38 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Felix Fietkau, linux-wireless

> Use usb_bulk_msg for reading MCU command responses. This simplify code
> a lot.
> 
> Together with 97a3005759c ("mt76usb: allow mt76u_bulk_msg be used
> for reads") it also fix possible problems with rx data buffers
> not being aligned and contained within single page. After doing
> page_frag_alloc(1024) consecutive page_frag_alloc(PAGE_SIZE) will
> alloc PAGE_SIZE buffer at PAGE_SIZE - 1024 offset.
> 
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>

Hi Stanislaw,

very nice simplification. I need to post a series and this patch will help
me a lot, thx :)
Just few comments inline

Regards,
Lorenzo

> ---
>  drivers/net/wireless/mediatek/mt76/mt76.h          |  3 +-
>  drivers/net/wireless/mediatek/mt76/mt76x0/usb.c    | 11 --------
>  .../net/wireless/mediatek/mt76/mt76x02_usb_mcu.c   | 32 +++++++---------------
>  drivers/net/wireless/mediatek/mt76/mt76x2/usb.c    | 11 --------
>  drivers/net/wireless/mediatek/mt76/usb.c           |  1 -
>  drivers/net/wireless/mediatek/mt76/usb_mcu.c       | 31 +++------------------
>  6 files changed, 15 insertions(+), 74 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index 45e44bcaa523..ce53069461ec 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -384,8 +384,7 @@ struct mt76_usb {
>  
>  	struct mt76u_mcu {
>  		struct mutex mutex;
> -		struct completion cmpl;
> -		struct mt76u_buf res;
> +		u8 *data;
>  		u32 msg_seq;
>  
>  		/* multiple reads */
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
> index da9d05f6074d..f0c33890f1a5 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
> @@ -311,13 +311,11 @@ static int __maybe_unused mt76x0_suspend(struct usb_interface *usb_intf,
>  					 pm_message_t state)
>  {
>  	struct mt76x02_dev *dev = usb_get_intfdata(usb_intf);
> -	struct mt76_usb *usb = &dev->mt76.usb;
>  
>  	mt76u_stop_queues(&dev->mt76);
>  	mt76x0u_mac_stop(dev);
>  	clear_bit(MT76_STATE_MCU_RUNNING, &dev->mt76.state);
>  	mt76x0_chip_onoff(dev, false, false);
> -	usb_kill_urb(usb->mcu.res.urb);
>  
>  	return 0;
>  }
> @@ -328,15 +326,6 @@ static int __maybe_unused mt76x0_resume(struct usb_interface *usb_intf)
>  	struct mt76_usb *usb = &dev->mt76.usb;
>  	int ret;
>  
> -	reinit_completion(&usb->mcu.cmpl);
> -	ret = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
> -			       MT_EP_IN_CMD_RESP,
> -			       &usb->mcu.res, GFP_KERNEL,
> -			       mt76u_mcu_complete_urb,
> -			       &usb->mcu.cmpl);
> -	if (ret < 0)
> -		goto err;
> -
>  	ret = mt76u_submit_rx_buffers(&dev->mt76);
>  	if (ret < 0)
>  		goto err;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> index f497c8e4332a..0cb8751321a1 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> @@ -61,33 +61,21 @@ mt76x02u_multiple_mcu_reads(struct mt76_dev *dev, u8 *data, int len)
>  static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
>  {
>  	struct mt76_usb *usb = &dev->usb;
> -	struct mt76u_buf *buf = &usb->mcu.res;
> -	struct urb *urb = buf->urb;
> -	u8 *data = buf->buf;
> -	int i, ret;
> +	u8 *data = usb->mcu.data;
> +	int i, len, ret;
>  	u32 rxfce;
>  
>  	for (i = 0; i < 5; i++) {
> -		if (!wait_for_completion_timeout(&usb->mcu.cmpl,
> -						 msecs_to_jiffies(300)))
> +		ret = mt76u_bulk_msg(dev, data, MCU_RESP_URB_SIZE, &len, 300);
> +		if (ret == -ETIMEDOUT)
>  			continue;
> -
> -		if (urb->status)
> -			return -EIO;
> +		if (ret)
> +			goto out;
>  
>  		if (usb->mcu.rp)
> -			mt76x02u_multiple_mcu_reads(dev, data + 4,
> -						    urb->actual_length - 8);
> +			mt76x02u_multiple_mcu_reads(dev, data + 4, len - 8);
>  
>  		rxfce = get_unaligned_le32(data);
> -		ret = mt76u_submit_buf(dev, USB_DIR_IN,
> -				       MT_EP_IN_CMD_RESP,
> -				       buf, GFP_KERNEL,
> -				       mt76u_mcu_complete_urb,
> -				       &usb->mcu.cmpl);
> -		if (ret)
> -			return ret;
> -
>  		if (seq == FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce) &&
>  		    FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce) == EVT_CMD_DONE)
>  			return 0;
> @@ -96,9 +84,9 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
>  			FIELD_GET(MT_RX_FCE_INFO_EVT_TYPE, rxfce),
>  			seq, FIELD_GET(MT_RX_FCE_INFO_CMD_SEQ, rxfce));
>  	}
> -
> -	dev_err(dev->dev, "error: %s timed out\n", __func__);
> -	return -ETIMEDOUT;
> +out:
> +	dev_err(dev->dev, "error: %s failed with %d\n", __func__, ret);
> +	return ret;
>  }
>  
>  static int
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
> index f81a85e96922..ddb6b2c48e01 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb.c
> @@ -100,11 +100,9 @@ static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
>  					  pm_message_t state)
>  {
>  	struct mt76x02_dev *dev = usb_get_intfdata(intf);
> -	struct mt76_usb *usb = &dev->mt76.usb;
>  
>  	mt76u_stop_queues(&dev->mt76);
>  	mt76x2u_stop_hw(dev);
> -	usb_kill_urb(usb->mcu.res.urb);
>  
>  	return 0;
>  }
> @@ -115,15 +113,6 @@ static int __maybe_unused mt76x2u_resume(struct usb_interface *intf)
>  	struct mt76_usb *usb = &dev->mt76.usb;
>  	int err;
>  
> -	reinit_completion(&usb->mcu.cmpl);
> -	err = mt76u_submit_buf(&dev->mt76, USB_DIR_IN,
> -			       MT_EP_IN_CMD_RESP,
> -			       &usb->mcu.res, GFP_KERNEL,
> -			       mt76u_mcu_complete_urb,
> -			       &usb->mcu.cmpl);
> -	if (err < 0)
> -		goto err;
> -
>  	err = mt76u_submit_rx_buffers(&dev->mt76);
>  	if (err < 0)
>  		goto err;
> diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
> index 78191968b4fa..5c3b7f735aae 100644
> --- a/drivers/net/wireless/mediatek/mt76/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/usb.c
> @@ -933,7 +933,6 @@ int mt76u_init(struct mt76_dev *dev,
>  	INIT_DELAYED_WORK(&usb->stat_work, mt76u_tx_status_data);
>  	skb_queue_head_init(&dev->rx_skb[MT_RXQ_MAIN]);
>  
> -	init_completion(&usb->mcu.cmpl);
>  	mutex_init(&usb->mcu.mutex);
>  
>  	mutex_init(&usb->usb_ctrl_mtx);
> diff --git a/drivers/net/wireless/mediatek/mt76/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/usb_mcu.c
> index 72c8607da4b4..747231edc57d 100644
> --- a/drivers/net/wireless/mediatek/mt76/usb_mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/usb_mcu.c
> @@ -16,42 +16,19 @@
>  
>  #include "mt76.h"
>  
> -void mt76u_mcu_complete_urb(struct urb *urb)
> -{
> -	struct completion *cmpl = urb->context;
> -
> -	complete(cmpl);
> -}
> -EXPORT_SYMBOL_GPL(mt76u_mcu_complete_urb);
> -
>  int mt76u_mcu_init_rx(struct mt76_dev *dev)
>  {
>  	struct mt76_usb *usb = &dev->usb;
> -	int err;
>  
> -	err = mt76u_buf_alloc(dev, &usb->mcu.res, MCU_RESP_URB_SIZE,
> -			      MCU_RESP_URB_SIZE, GFP_KERNEL);
> -	if (err < 0)
> -		return err;
> -
> -	err = mt76u_submit_buf(dev, USB_DIR_IN, MT_EP_IN_CMD_RESP,
> -			       &usb->mcu.res, GFP_KERNEL,
> -			       mt76u_mcu_complete_urb,
> -			       &usb->mcu.cmpl);
> -	if (err < 0)
> -		mt76u_buf_free(&usb->mcu.res);
> -
> -	return err;
> +	usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);

if you use devm_kmalloc() you can drop mt76u_mcu_deinit

Regards,
Lorenzo

> +	return usb->mcu.data ? 0 : -ENOMEM;
>  }
>  EXPORT_SYMBOL_GPL(mt76u_mcu_init_rx);
>  
>  void mt76u_mcu_deinit(struct mt76_dev *dev)
>  {
> -	struct mt76u_buf *buf = &dev->usb.mcu.res;
> +	struct mt76_usb *usb = &dev->usb;
>  
> -	if (buf->urb) {
> -		usb_kill_urb(buf->urb);
> -		mt76u_buf_free(buf);
> -	}
> +	kfree(usb->mcu.data);
>  }
>  EXPORT_SYMBOL_GPL(mt76u_mcu_deinit);
> -- 
> 2.7.5
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mt76usb: remove usb_mcu.c
  2019-02-20 10:12 ` [PATCH 3/3] mt76usb: remove usb_mcu.c Stanislaw Gruszka
@ 2019-02-20 10:41   ` Lorenzo Bianconi
  0 siblings, 0 replies; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-02-20 10:41 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Felix Fietkau, linux-wireless

> Don't need separate file just for kmalloc/kfree.
> 

same comments here kmalloc() --> devm_kmalloc().
Maybe this patch can be squashed with 2/3?

Regards,
Lorenzo

> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt76.h          |  2 --
>  drivers/net/wireless/mediatek/mt76/mt76x0/usb.c    |  5 ----
>  .../net/wireless/mediatek/mt76/mt76x2/usb_init.c   |  5 ----
>  drivers/net/wireless/mediatek/mt76/usb.c           |  8 +++++
>  drivers/net/wireless/mediatek/mt76/usb_mcu.c       | 34 ----------------------
>  5 files changed, 8 insertions(+), 46 deletions(-)
>  delete mode 100644 drivers/net/wireless/mediatek/mt76/usb_mcu.c
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index ce53069461ec..972f0ca7c818 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -774,7 +774,5 @@ struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev,
>  				      unsigned long expires);
>  
>  void mt76u_mcu_complete_urb(struct urb *urb);
> -int mt76u_mcu_init_rx(struct mt76_dev *dev);
> -void mt76u_mcu_deinit(struct mt76_dev *dev);
>  
>  #endif
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
> index f0c33890f1a5..91718647da02 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
> @@ -79,7 +79,6 @@ static void mt76x0u_cleanup(struct mt76x02_dev *dev)
>  	clear_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
>  	mt76x0_chip_onoff(dev, false, false);
>  	mt76u_queues_deinit(&dev->mt76);
> -	mt76u_mcu_deinit(&dev->mt76);
>  }
>  
>  static void mt76x0u_mac_stop(struct mt76x02_dev *dev)
> @@ -193,10 +192,6 @@ static int mt76x0u_register_device(struct mt76x02_dev *dev)
>  	if (err < 0)
>  		goto out_err;
>  
> -	err = mt76u_mcu_init_rx(&dev->mt76);
> -	if (err < 0)
> -		goto out_err;
> -
>  	err = mt76x0u_init_hardware(dev);
>  	if (err < 0)
>  		goto out_err;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
> index 090aaf71b3ef..1da90e58d942 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c
> @@ -214,10 +214,6 @@ int mt76x2u_register_device(struct mt76x02_dev *dev)
>  	if (err < 0)
>  		goto fail;
>  
> -	err = mt76u_mcu_init_rx(&dev->mt76);
> -	if (err < 0)
> -		goto fail;
> -
>  	err = mt76x2u_init_hardware(dev);
>  	if (err < 0)
>  		goto fail;
> @@ -259,5 +255,4 @@ void mt76x2u_cleanup(struct mt76x02_dev *dev)
>  	mt76x02_mcu_set_radio_state(dev, false);
>  	mt76x2u_stop_hw(dev);
>  	mt76u_queues_deinit(&dev->mt76);
> -	mt76u_mcu_deinit(&dev->mt76);
>  }
> diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
> index 5c3b7f735aae..4fe025b92302 100644
> --- a/drivers/net/wireless/mediatek/mt76/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/usb.c
> @@ -577,9 +577,14 @@ EXPORT_SYMBOL_GPL(mt76u_submit_rx_buffers);
>  
>  static int mt76u_alloc_rx(struct mt76_dev *dev)
>  {
> +	struct mt76_usb *usb = &dev->usb;
>  	struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
>  	int i, err;
>  
> +	usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);
> +	if (usb->mcu.data)
> +		return -ENOMEM;
> +
>  	spin_lock_init(&q->rx_page_lock);
>  	spin_lock_init(&q->lock);
>  	q->entry = devm_kcalloc(dev->dev,
> @@ -610,6 +615,7 @@ static int mt76u_alloc_rx(struct mt76_dev *dev)
>  
>  static void mt76u_free_rx(struct mt76_dev *dev)
>  {
> +	struct mt76_usb *usb = &dev->usb;
>  	struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
>  	struct page *page;
>  	int i;
> @@ -626,6 +632,8 @@ static void mt76u_free_rx(struct mt76_dev *dev)
>  	memset(&q->rx_page, 0, sizeof(q->rx_page));
>  out:
>  	spin_unlock_bh(&q->rx_page_lock);
> +
> +	kfree(usb->mcu.data);
>  }
>  
>  static void mt76u_stop_rx(struct mt76_dev *dev)
> diff --git a/drivers/net/wireless/mediatek/mt76/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/usb_mcu.c
> deleted file mode 100644
> index 747231edc57d..000000000000
> --- a/drivers/net/wireless/mediatek/mt76/usb_mcu.c
> +++ /dev/null
> @@ -1,34 +0,0 @@
> -/*
> - * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
> - *
> - * Permission to use, copy, modify, and/or distribute this software for any
> - * purpose with or without fee is hereby granted, provided that the above
> - * copyright notice and this permission notice appear in all copies.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> - */
> -
> -#include "mt76.h"
> -
> -int mt76u_mcu_init_rx(struct mt76_dev *dev)
> -{
> -	struct mt76_usb *usb = &dev->usb;
> -
> -	usb->mcu.data = kmalloc(MCU_RESP_URB_SIZE, GFP_KERNEL);
> -	return usb->mcu.data ? 0 : -ENOMEM;
> -}
> -EXPORT_SYMBOL_GPL(mt76u_mcu_init_rx);
> -
> -void mt76u_mcu_deinit(struct mt76_dev *dev)
> -{
> -	struct mt76_usb *usb = &dev->usb;
> -
> -	kfree(usb->mcu.data);
> -}
> -EXPORT_SYMBOL_GPL(mt76u_mcu_deinit);
> -- 
> 2.7.5
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads
  2019-02-20 10:12 [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Stanislaw Gruszka
                   ` (2 preceding siblings ...)
  2019-02-20 10:31 ` [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Lorenzo Bianconi
@ 2019-02-20 11:28 ` Lorenzo Bianconi
  2019-02-20 12:01   ` Stanislaw Gruszka
  3 siblings, 1 reply; 8+ messages in thread
From: Lorenzo Bianconi @ 2019-02-20 11:28 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Felix Fietkau, linux-wireless

> Extend mt76u_bulk_msg() such it can be used for synchronous bulk reads.
> 
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---

Hi Stanislaw,

testing this series I got the following error:

[    3.448267] mt76x0u 1-1:1.0: ASIC revision: 76100002 MAC revision: 76502000
[    3.451220] INFO: trying to register non-static key.
[    3.452055] the code is fine but needs lockdep annotation.
[    3.452945] turning off the locking correctness validator.
[    3.453590] CPU: 0 PID: 18 Comm: kworker/0:1 Not tainted 5.0.0-rc4+ #2963
[    3.454390] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS
?-20180724_192412-buildhw-07.phx2.fedoraproject.org-1.fc29 04/01/2014
[    3.455973] Workqueue: usb_hub_wq hub_event
[    3.456642] Call Trace:
[    3.456989]  register_lock_class+0x4fd/0x510
[    3.457619]  ? mark_held_locks+0x4f/0x80
[    3.458172]  __lock_acquire+0x6c/0x1580
[    3.458675]  ? __mt76u_vendor_request+0xc0/0x110
[    3.459302]  ? find_held_lock+0x2d/0x90
[    3.459802]  lock_acquire+0x88/0x120
[    3.460283]  ? mt76u_queues_deinit+0x4e/0x120
[    3.460875]  _raw_spin_lock_bh+0x38/0x80
[    3.461412]  ? mt76u_queues_deinit+0x4e/0x120
[    3.461999]  mt76u_queues_deinit+0x4e/0x120
[    3.462565]  mt76x0u_probe+0x1e6/0x220
[    3.463070]  usb_probe_interface+0xa7/0x1d0
[    3.463639]  ? __driver_attach+0xd0/0xd0
[    3.464167]  really_probe+0xda/0x250
[    3.464754]  ? __driver_attach+0xd0/0xd0
[    3.465285]  bus_for_each_drv+0x66/0x90
[    3.465801]  __device_attach+0xa8/0xe0
[    3.466309]  bus_probe_device+0x9f/0xb0
[    3.466880]  device_add+0x3a2/0x5f0
[    3.467338]  usb_set_configuration+0x471/0x7d0
[    3.467942]  ? __driver_attach+0xd0/0xd0
[    3.468454]  generic_probe+0x48/0x70
[    3.468929]  really_probe+0xda/0x250
[    3.469411]  ? __driver_attach+0xd0/0xd0
[    3.469931]  bus_for_each_drv+0x66/0x90
[    3.470433]  __device_attach+0xa8/0xe0
[    3.470920]  bus_probe_device+0x9f/0xb0
[    3.471420]  device_add+0x3a2/0x5f0
[    3.471875]  usb_new_device+0x193/0x320
[    3.472382]  hub_event+0xbf7/0x1160
[    3.472840]  process_one_work+0x2a4/0x580
[    3.473367]  ? process_one_work+0x580/0x580
[    3.473912]  worker_thread+0x2d/0x3d0
[    3.474390]  ? process_one_work+0x580/0x580
[    3.474940]  kthread+0x115/0x130
[    3.475392]  ? kthread_create_on_node+0x40/0x40
[    3.475968]  ret_from_fork+0x3a/0x50
[    3.476492] mt76x0u: probe of 1-1:1.0 failed with error -12

Regards,
Lorenzo

>  drivers/net/wireless/mediatek/mt76/mt76.h            | 13 ++++++++++---
>  drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c |  4 ++--
>  2 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index f55dc621e060..45e44bcaa523 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -729,7 +729,8 @@ static inline u8 q2ep(u8 qid)
>  }
>  
>  static inline int
> -mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout)
> +mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len,
> +	       int timeout)
>  {
>  	struct usb_interface *intf = to_usb_interface(dev->dev);
>  	struct usb_device *udev = interface_to_usbdev(intf);
> @@ -737,8 +738,14 @@ mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int timeout)
>  	unsigned int pipe;
>  	int sent;
>  
> -	pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
> -	return usb_bulk_msg(udev, pipe, data, len, &sent, timeout);
> +	if (actual_len) {
> +		pipe = usb_rcvbulkpipe(udev, usb->in_ep[MT_EP_IN_CMD_RESP]);
> +	} else {
> +		actual_len = &sent;
> +		pipe = usb_sndbulkpipe(udev, usb->out_ep[MT_EP_OUT_INBAND_CMD]);
> +	}
> +
> +	return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout);
>  }
>  
>  int mt76u_vendor_request(struct mt76_dev *dev, u8 req,
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> index e469e383cb88..f497c8e4332a 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c
> @@ -126,7 +126,7 @@ __mt76x02u_mcu_send_msg(struct mt76_dev *dev, struct sk_buff *skb,
>  	if (ret)
>  		return ret;
>  
> -	ret = mt76u_bulk_msg(dev, skb->data, skb->len, 500);
> +	ret = mt76u_bulk_msg(dev, skb->data, skb->len, NULL, 500);
>  	if (ret)
>  		return ret;
>  
> @@ -271,7 +271,7 @@ __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, u8 *data,
>  
>  	data_len = MT_CMD_HDR_LEN + len + sizeof(info);
>  
> -	err = mt76u_bulk_msg(&dev->mt76, data, data_len, 1000);
> +	err = mt76u_bulk_msg(&dev->mt76, data, data_len, NULL, 1000);
>  	if (err) {
>  		dev_err(dev->mt76.dev, "firmware upload failed: %d\n", err);
>  		return err;
> -- 
> 2.7.5
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads
  2019-02-20 11:28 ` Lorenzo Bianconi
@ 2019-02-20 12:01   ` Stanislaw Gruszka
  0 siblings, 0 replies; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-02-20 12:01 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: Felix Fietkau, linux-wireless

On Wed, Feb 20, 2019 at 12:28:38PM +0100, Lorenzo Bianconi wrote:
> [    3.476492] mt76x0u: probe of 1-1:1.0 failed with error -12

During rework of patch 3 I made silly mistake in

+       if (usb->mcu.data)
+               return -ENOMEM;

and seems I did not reload modules properly and only tested previous
revision of the set.

Stanislaw

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-02-20 12:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-20 10:12 [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Stanislaw Gruszka
2019-02-20 10:12 ` [PATCH 2/3] mt76usb: use synchronous msg for mcu command responses Stanislaw Gruszka
2019-02-20 10:38   ` Lorenzo Bianconi
2019-02-20 10:12 ` [PATCH 3/3] mt76usb: remove usb_mcu.c Stanislaw Gruszka
2019-02-20 10:41   ` Lorenzo Bianconi
2019-02-20 10:31 ` [PATCH 1/3] mt76usb: allow mt76u_bulk_msg be used for reads Lorenzo Bianconi
2019-02-20 11:28 ` Lorenzo Bianconi
2019-02-20 12:01   ` Stanislaw Gruszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).