From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: linux-wireless@vger.kernel.org, Felix Fietkau <nbd@nbd.name>
Subject: Re: [RFC 07/12] mt76usb: remove mt76u_buf and use urb directly
Date: Tue, 12 Mar 2019 17:27:43 +0100 [thread overview]
Message-ID: <20190312162742.GE2611@localhost.localdomain> (raw)
In-Reply-To: <1552403166-3821-8-git-send-email-sgruszka@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 11997 bytes --]
> Put urb pointer in mt76_queue_entry directly instead of mt76u_buf
> structure.
>
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> drivers/net/wireless/mediatek/mt76/mt76.h | 6 +-
> drivers/net/wireless/mediatek/mt76/usb.c | 132 +++++++++++++++---------------
> 2 files changed, 65 insertions(+), 73 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index 998505064dee..859d0325583b 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -83,10 +83,6 @@ struct mt76_queue_buf {
> int len;
> };
>
> -struct mt76u_buf {
> - struct urb *urb;
> -};
> -
> struct mt76_queue_entry {
> union {
> void *buf;
> @@ -94,7 +90,7 @@ struct mt76_queue_entry {
> };
> union {
> struct mt76_txwi_cache *txwi;
> - struct mt76u_buf ubuf;
> + struct urb *urb;
> };
> enum mt76_txq_id qid;
> bool schedule;
> diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
> index a4ef9bb1603d..2c21f4773a19 100644
> --- a/drivers/net/wireless/mediatek/mt76/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/usb.c
> @@ -283,12 +283,11 @@ static bool mt76u_check_sg(struct mt76_dev *dev)
> }
>
> static int
> -mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76u_buf *buf, int nsgs,
> +mt76u_fill_rx_sg(struct mt76_dev *dev, struct urb *urb, int nsgs,
> gfp_t gfp)
> {
> struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
> int sglen = SKB_WITH_OVERHEAD(q->buf_size);
> - struct urb *urb = buf->urb;
>
> int i;
>
> @@ -323,44 +322,43 @@ static bool mt76u_check_sg(struct mt76_dev *dev)
>
> static int
> mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q,
> - struct mt76u_buf *buf, int nsgs, gfp_t gfp)
> + struct urb *urb, int nsgs, gfp_t gfp)
> {
> if (dev->usb.sg_en) {
> - return mt76u_fill_rx_sg(dev, buf, nsgs, gfp);
> + return mt76u_fill_rx_sg(dev, urb, nsgs, gfp);
> } else {
> - buf->urb->transfer_buffer_length =
> - SKB_WITH_OVERHEAD(q->buf_size);
> - buf->urb->transfer_buffer =
> - page_frag_alloc(&q->rx_page, q->buf_size, gfp);
> - return buf->urb->transfer_buffer ? 0 : -ENOMEM;
> + urb->transfer_buffer_length = SKB_WITH_OVERHEAD(q->buf_size);
> + urb->transfer_buffer = page_frag_alloc(&q->rx_page,
> + q->buf_size, gfp);
> + return urb->transfer_buffer ? 0 : -ENOMEM;
> }
> }
>
> static int
> -mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf)
> +mt76u_urb_alloc(struct mt76_dev *dev, struct mt76_queue_entry *e)
> {
> struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
> + struct urb *urb;
>
> - buf->urb = usb_alloc_urb(0, GFP_KERNEL);
> - if (!buf->urb)
> + urb = usb_alloc_urb(0, GFP_KERNEL);
I guess here you can do:
e->urb = usb_alloc_urb(0, GFP_KERNEL);
if (!e->urb)
return -ENOMEM;
Regards,
Lorenzo
> + if (!urb)
> return -ENOMEM;
> + e->urb = urb;
>
> if (dev->usb.sg_en) {
> - buf->urb->sg = devm_kcalloc(dev->dev, MT_SG_MAX_SIZE,
> - sizeof(*buf->urb->sg),
> - GFP_KERNEL);
> - if (!buf->urb->sg)
> + urb->sg = devm_kcalloc(dev->dev, MT_SG_MAX_SIZE,
> + sizeof(urb->sg), GFP_KERNEL);
> + if (!urb->sg)
> return -ENOMEM;
>
> - sg_init_table(buf->urb->sg, MT_SG_MAX_SIZE);
> + sg_init_table(urb->sg, MT_SG_MAX_SIZE);
> }
>
> - return mt76u_refill_rx(dev, q, buf, MT_SG_MAX_SIZE, GFP_KERNEL);
> + return mt76u_refill_rx(dev, q, urb, MT_SG_MAX_SIZE, GFP_KERNEL);
> }
>
> -static void mt76u_buf_free(struct mt76u_buf *buf)
> +static void mt76u_urb_free(struct urb *urb)
> {
> - struct urb *urb = buf->urb;
> int i;
>
> for (i = 0; i < urb->num_sgs; i++)
> @@ -369,12 +367,12 @@ static void mt76u_buf_free(struct mt76u_buf *buf)
> if (urb->transfer_buffer)
> skb_free_frag(urb->transfer_buffer);
>
> - usb_free_urb(buf->urb);
> + usb_free_urb(urb);
> }
>
> static void
> mt76u_fill_bulk_urb(struct mt76_dev *dev, int dir, int index,
> - struct mt76u_buf *buf, usb_complete_t complete_fn,
> + struct urb *urb, usb_complete_t complete_fn,
> void *context)
> {
> struct usb_device *udev = to_usb_device(dev->dev);
> @@ -385,27 +383,27 @@ static void mt76u_buf_free(struct mt76u_buf *buf)
> else
> pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[index]);
>
> - buf->urb->dev = udev;
> - buf->urb->pipe = pipe;
> - buf->urb->complete = complete_fn;
> - buf->urb->context = context;
> + urb->dev = udev;
> + urb->pipe = pipe;
> + urb->complete = complete_fn;
> + urb->context = context;
> }
>
> -static inline struct mt76u_buf
> -*mt76u_get_next_rx_entry(struct mt76_queue *q)
> +static inline struct urb *
> +mt76u_get_next_rx_entry(struct mt76_queue *q)
> {
> - struct mt76u_buf *buf = NULL;
> + struct urb *urb = NULL;
> unsigned long flags;
>
> spin_lock_irqsave(&q->lock, flags);
> if (q->queued > 0) {
> - buf = &q->entry[q->head].ubuf;
> + urb = q->entry[q->head].urb;
> q->head = (q->head + 1) % q->ndesc;
> q->queued--;
> }
> spin_unlock_irqrestore(&q->lock, flags);
>
> - return buf;
> + return urb;
> }
>
> static int mt76u_get_rx_entry_len(u8 *data, u32 data_len)
> @@ -424,10 +422,9 @@ static int mt76u_get_rx_entry_len(u8 *data, u32 data_len)
> }
>
> static int
> -mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf)
> +mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb)
> {
> struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
> - struct urb *urb = buf->urb;
> u8 *data = urb->num_sgs ? sg_virt(&urb->sg[0]) : urb->transfer_buffer;
> int data_len, len, nsgs = 1;
> struct sk_buff *skb;
> @@ -488,7 +485,7 @@ static void mt76u_complete_rx(struct urb *urb)
> }
>
> spin_lock_irqsave(&q->lock, flags);
> - if (WARN_ONCE(q->entry[q->tail].ubuf.urb != urb, "rx urb mismatch"))
> + if (WARN_ONCE(q->entry[q->tail].urb != urb, "rx urb mismatch"))
> goto out;
>
> q->tail = (q->tail + 1) % q->ndesc;
> @@ -499,37 +496,37 @@ static void mt76u_complete_rx(struct urb *urb)
> }
>
> static int
> -mt76u_submit_rx_buf(struct mt76_dev *dev, struct mt76u_buf *buf)
> +mt76u_submit_rx_buf(struct mt76_dev *dev, struct urb *urb)
> {
> - mt76u_fill_bulk_urb(dev, USB_DIR_IN, MT_EP_IN_PKT_RX, buf,
> + mt76u_fill_bulk_urb(dev, USB_DIR_IN, MT_EP_IN_PKT_RX, urb,
> mt76u_complete_rx, dev);
> - trace_submit_urb(dev, buf->urb);
> + trace_submit_urb(dev, urb);
>
> - return usb_submit_urb(buf->urb, GFP_ATOMIC);
> + return usb_submit_urb(urb, GFP_ATOMIC);
> }
>
> static void mt76u_rx_tasklet(unsigned long data)
> {
> struct mt76_dev *dev = (struct mt76_dev *)data;
> struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
> - struct mt76u_buf *buf;
> + struct urb *urb;
> int err, count;
>
> rcu_read_lock();
>
> while (true) {
> - buf = mt76u_get_next_rx_entry(q);
> - if (!buf)
> + urb = mt76u_get_next_rx_entry(q);
> + if (!urb)
> break;
>
> - count = mt76u_process_rx_entry(dev, buf);
> + count = mt76u_process_rx_entry(dev, urb);
> if (count > 0) {
> - err = mt76u_refill_rx(dev, q, buf, count,
> + err = mt76u_refill_rx(dev, q, urb, count,
> GFP_ATOMIC);
> if (err < 0)
> break;
> }
> - mt76u_submit_rx_buf(dev, buf);
> + mt76u_submit_rx_buf(dev, urb);
> }
> mt76_rx_poll_complete(dev, MT_RXQ_MAIN, NULL);
>
> @@ -544,7 +541,7 @@ int mt76u_submit_rx_buffers(struct mt76_dev *dev)
>
> spin_lock_irqsave(&q->lock, flags);
> for (i = 0; i < q->ndesc; i++) {
> - err = mt76u_submit_rx_buf(dev, &q->entry[i].ubuf);
> + err = mt76u_submit_rx_buf(dev, q->entry[i].urb);
> if (err < 0)
> break;
> }
> @@ -576,7 +573,7 @@ static int mt76u_alloc_rx(struct mt76_dev *dev)
> q->buf_size = dev->usb.sg_en ? MT_RX_BUF_SIZE : PAGE_SIZE;
> q->ndesc = MT_NUM_RX_ENTRIES;
> for (i = 0; i < q->ndesc; i++) {
> - err = mt76u_buf_alloc(dev, &q->entry[i].ubuf);
> + err = mt76u_urb_alloc(dev, &q->entry[i]);
> if (err < 0)
> return err;
> }
> @@ -591,7 +588,7 @@ static void mt76u_free_rx(struct mt76_dev *dev)
> int i;
>
> for (i = 0; i < q->ndesc; i++)
> - mt76u_buf_free(&q->entry[i].ubuf);
> + mt76u_urb_free(q->entry[i].urb);
>
> if (!q->rx_page.va)
> return;
> @@ -607,7 +604,7 @@ static void mt76u_stop_rx(struct mt76_dev *dev)
> int i;
>
> for (i = 0; i < q->ndesc; i++)
> - usb_kill_urb(q->entry[i].ubuf.urb);
> + usb_kill_urb(q->entry[i].urb);
> }
>
> static void mt76u_tx_tasklet(unsigned long data)
> @@ -718,7 +715,7 @@ static void mt76u_complete_tx(struct urb *urb)
> struct ieee80211_sta *sta)
> {
> struct mt76_queue *q = dev->q_tx[qid].q;
> - struct mt76u_buf *buf;
> + struct urb *urb;
> u16 idx = q->tail;
> int err;
>
> @@ -731,18 +728,18 @@ static void mt76u_complete_tx(struct urb *urb)
> return err;
>
> q->entry[idx].done = false;
> - buf = &q->entry[idx].ubuf;
> + urb = q->entry[idx].urb;
> if (!dev->usb.sg_en) {
> - buf->urb->transfer_buffer = skb->data;
> + urb->transfer_buffer = skb->data;
> } else {
> - err = mt76u_tx_build_sg(dev, skb, buf->urb);
> + err = mt76u_tx_build_sg(dev, skb, urb);
> if (err < 0)
> return err;
> }
> - buf->urb->transfer_buffer_length = skb->len;
> + urb->transfer_buffer_length = skb->len;
>
> mt76u_fill_bulk_urb(dev, USB_DIR_OUT, q2ep(q->hw_idx),
> - buf, mt76u_complete_tx, &q->entry[idx]);
> + urb, mt76u_complete_tx, &q->entry[idx]);
>
> q->tail = (q->tail + 1) % q->ndesc;
> q->entry[idx].skb = skb;
> @@ -753,14 +750,14 @@ static void mt76u_complete_tx(struct urb *urb)
>
> static void mt76u_tx_kick(struct mt76_dev *dev, struct mt76_queue *q)
> {
> - struct mt76u_buf *buf;
> + struct urb *urb;
> int err;
>
> while (q->first != q->tail) {
> - buf = &q->entry[q->first].ubuf;
> + urb = q->entry[q->first].urb;
>
> - trace_submit_urb(dev, buf->urb);
> - err = usb_submit_urb(buf->urb, GFP_ATOMIC);
> + trace_submit_urb(dev, urb);
> + err = usb_submit_urb(urb, GFP_ATOMIC);
> if (err < 0) {
> if (err == -ENODEV)
> set_bit(MT76_REMOVED, &dev->state);
> @@ -775,7 +772,7 @@ static void mt76u_tx_kick(struct mt76_dev *dev, struct mt76_queue *q)
>
> static int mt76u_alloc_tx(struct mt76_dev *dev)
> {
> - struct mt76u_buf *buf;
> + struct urb *urb;
> struct mt76_queue *q;
> int i, j;
>
> @@ -803,19 +800,18 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
>
> q->ndesc = MT_NUM_TX_ENTRIES;
> for (j = 0; j < q->ndesc; j++) {
> - buf = &q->entry[j].ubuf;
> -
> - buf->urb = usb_alloc_urb(0, GFP_KERNEL);
> - if (!buf->urb)
> + urb = usb_alloc_urb(0, GFP_KERNEL);
> + if (!urb)
> return -ENOMEM;
> + q->entry[j].urb = urb;
>
> if (dev->usb.sg_en) {
> size_t size = MT_SG_MAX_SIZE *
> sizeof(struct scatterlist);
>
> - buf->urb->sg = devm_kzalloc(dev->dev, size,
> - GFP_KERNEL);
> - if (!buf->urb->sg)
> + urb->sg = devm_kzalloc(dev->dev, size,
> + GFP_KERNEL);
> + if (!urb->sg)
> return -ENOMEM;
> }
> }
> @@ -831,7 +827,7 @@ static void mt76u_free_tx(struct mt76_dev *dev)
> for (i = 0; i < IEEE80211_NUM_ACS; i++) {
> q = dev->q_tx[i].q;
> for (j = 0; j < q->ndesc; j++)
> - usb_free_urb(q->entry[j].ubuf.urb);
> + usb_free_urb(q->entry[j].urb);
> }
> }
>
> @@ -843,7 +839,7 @@ static void mt76u_stop_tx(struct mt76_dev *dev)
> for (i = 0; i < IEEE80211_NUM_ACS; i++) {
> q = dev->q_tx[i].q;
> for (j = 0; j < q->ndesc; j++)
> - usb_kill_urb(q->entry[j].ubuf.urb);
> + usb_kill_urb(q->entry[j].urb);
> }
> }
>
> --
> 1.9.3
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2019-03-12 16:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-12 15:05 [RFC 00/12] mt76usb: some cleanups and optimizations Stanislaw Gruszka
2019-03-12 15:05 ` [RFC 01/12] mt76usb: change mt76u_submit_buf Stanislaw Gruszka
2019-03-12 15:05 ` [RFC 02/12] mt76: remove rx_page_lock Stanislaw Gruszka
2019-03-12 15:05 ` [RFC 03/12] mt76usb: change mt76u_fill_rx_sg arguments Stanislaw Gruszka
2019-03-12 15:05 ` [RFC 04/12] mt76usb: use usb_dev private data Stanislaw Gruszka
2019-03-12 15:05 ` [RFC 05/12] mt76usb: remove mt76u_buf redundant fileds Stanislaw Gruszka
2019-03-12 16:25 ` Lorenzo Bianconi
2019-03-13 12:53 ` Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 06/12] mt76usb: move mt76u_buf->done to queue entry Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 07/12] mt76usb: remove mt76u_buf and use urb directly Stanislaw Gruszka
2019-03-12 16:27 ` Lorenzo Bianconi [this message]
2019-03-13 12:53 ` Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 08/12] mt76usb: remove MT_RXQ_MAIN queue from mt76u_urb_alloc Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 09/12] mt76usb: resue mt76u_urb_alloc for tx Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 10/12] mt76usb: remove unneded sg_init_table Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 11/12] mt76usb: allocate urb and sg as linear data Stanislaw Gruszka
2019-03-12 16:34 ` Lorenzo Bianconi
2019-03-13 12:59 ` Stanislaw Gruszka
2019-03-12 15:06 ` [RFC 12/12] mt76usb: remove queue variable from rx_tasklet Stanislaw Gruszka
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=20190312162742.GE2611@localhost.localdomain \
--to=lorenzo.bianconi@redhat.com \
--cc=linux-wireless@vger.kernel.org \
--cc=nbd@nbd.name \
--cc=sgruszka@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).