Commit 26031b39 authored by Stanislaw Gruszka's avatar Stanislaw Gruszka Committed by Felix Fietkau

mt76usb: remove mt76u_buf redundant fileds

Remove mt76u_buf->{len, buf} fields and operate on corresponding
urb fields directly.
Signed-off-by: default avatarStanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 112f980a
...@@ -91,8 +91,6 @@ struct mt76_tx_info { ...@@ -91,8 +91,6 @@ struct mt76_tx_info {
struct mt76u_buf { struct mt76u_buf {
struct urb *urb; struct urb *urb;
size_t len;
void *buf;
bool done; bool done;
}; };
......
...@@ -315,7 +315,7 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76u_buf *buf, int nsgs, ...@@ -315,7 +315,7 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76u_buf *buf, int nsgs,
} }
urb->num_sgs = max_t(int, i, urb->num_sgs); urb->num_sgs = max_t(int, i, urb->num_sgs);
buf->len = urb->num_sgs * sglen, urb->transfer_buffer_length = urb->num_sgs * sglen,
sg_init_marker(urb->sg, urb->num_sgs); sg_init_marker(urb->sg, urb->num_sgs);
return i ? : -ENOMEM; return i ? : -ENOMEM;
...@@ -328,8 +328,11 @@ mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q, ...@@ -328,8 +328,11 @@ mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q,
if (dev->usb.sg_en) { if (dev->usb.sg_en) {
return mt76u_fill_rx_sg(dev, buf, nsgs, gfp); return mt76u_fill_rx_sg(dev, buf, nsgs, gfp);
} else { } else {
buf->buf = page_frag_alloc(&q->rx_page, q->buf_size, gfp); buf->urb->transfer_buffer_length =
return buf->buf ? 0 : -ENOMEM; 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;
} }
} }
...@@ -338,8 +341,6 @@ mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf) ...@@ -338,8 +341,6 @@ mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf)
{ {
struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
buf->len = SKB_WITH_OVERHEAD(q->buf_size);
buf->urb = usb_alloc_urb(0, GFP_KERNEL); buf->urb = usb_alloc_urb(0, GFP_KERNEL);
if (!buf->urb) if (!buf->urb)
return -ENOMEM; return -ENOMEM;
...@@ -365,8 +366,8 @@ static void mt76u_buf_free(struct mt76u_buf *buf) ...@@ -365,8 +366,8 @@ static void mt76u_buf_free(struct mt76u_buf *buf)
for (i = 0; i < urb->num_sgs; i++) for (i = 0; i < urb->num_sgs; i++)
skb_free_frag(sg_virt(&urb->sg[i])); skb_free_frag(sg_virt(&urb->sg[i]));
if (buf->buf) if (urb->transfer_buffer)
skb_free_frag(buf->buf); skb_free_frag(urb->transfer_buffer);
usb_free_urb(buf->urb); usb_free_urb(buf->urb);
} }
...@@ -377,7 +378,6 @@ mt76u_fill_bulk_urb(struct mt76_dev *dev, int dir, int index, ...@@ -377,7 +378,6 @@ mt76u_fill_bulk_urb(struct mt76_dev *dev, int dir, int index,
void *context) void *context)
{ {
struct usb_device *udev = to_usb_device(dev->dev); struct usb_device *udev = to_usb_device(dev->dev);
u8 *data = buf->urb->num_sgs ? NULL : buf->buf;
unsigned int pipe; unsigned int pipe;
if (dir == USB_DIR_IN) if (dir == USB_DIR_IN)
...@@ -385,8 +385,10 @@ mt76u_fill_bulk_urb(struct mt76_dev *dev, int dir, int index, ...@@ -385,8 +385,10 @@ mt76u_fill_bulk_urb(struct mt76_dev *dev, int dir, int index,
else else
pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[index]); pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[index]);
usb_fill_bulk_urb(buf->urb, udev, pipe, data, buf->len, buf->urb->dev = udev;
complete_fn, context); buf->urb->pipe = pipe;
buf->urb->complete = complete_fn;
buf->urb->context = context;
} }
static inline struct mt76u_buf static inline struct mt76u_buf
...@@ -426,8 +428,9 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf) ...@@ -426,8 +428,9 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf)
{ {
struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];
struct urb *urb = buf->urb; struct urb *urb = buf->urb;
u8 *data = urb->num_sgs ? sg_virt(&urb->sg[0]) : buf->buf; u8 *data = urb->num_sgs ? sg_virt(&urb->sg[0]) : urb->transfer_buffer;
int data_len, len, nsgs = 1; int data_len = urb->num_sgs ? urb->sg[0].length : urb->actual_length;
int len, nsgs = 1;
struct sk_buff *skb; struct sk_buff *skb;
if (!test_bit(MT76_STATE_INITIALIZED, &dev->state)) if (!test_bit(MT76_STATE_INITIALIZED, &dev->state))
...@@ -437,7 +440,6 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf) ...@@ -437,7 +440,6 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf)
if (len < 0) if (len < 0)
return 0; return 0;
data_len = urb->num_sgs ? urb->sg[0].length : buf->len;
data_len = min_t(int, len, data_len - MT_DMA_HDR_LEN); data_len = min_t(int, len, data_len - MT_DMA_HDR_LEN);
if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size)) if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size))
return 0; return 0;
...@@ -701,15 +703,21 @@ static void mt76u_complete_tx(struct urb *urb) ...@@ -701,15 +703,21 @@ static void mt76u_complete_tx(struct urb *urb)
} }
static int static int
mt76u_tx_build_sg(struct mt76_dev *dev, struct sk_buff *skb, mt76u_tx_setup_buffers(struct mt76_dev *dev, struct sk_buff *skb,
struct urb *urb) struct urb *urb)
{ {
if (!dev->usb.sg_en) urb->transfer_buffer_length = skb->len;
return 0;
sg_init_table(urb->sg, MT_SG_MAX_SIZE); if (!dev->usb.sg_en) {
urb->num_sgs = skb_to_sgvec(skb, urb->sg, 0, skb->len); urb->transfer_buffer = skb->data;
return urb->num_sgs; return 0;
} else {
sg_init_table(urb->sg, MT_SG_MAX_SIZE);
urb->num_sgs = skb_to_sgvec(skb, urb->sg, 0, skb->len);
if (urb->num_sgs == 0)
return -ENOMEM;
return urb->num_sgs;
}
} }
static int static int
...@@ -731,14 +739,12 @@ mt76u_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid, ...@@ -731,14 +739,12 @@ mt76u_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
return err; return err;
buf = &q->entry[idx].ubuf; buf = &q->entry[idx].ubuf;
buf->buf = skb->data; err = mt76u_tx_setup_buffers(dev, skb, buf->urb);
buf->len = skb->len;
buf->done = false;
err = mt76u_tx_build_sg(dev, skb, buf->urb);
if (err < 0) if (err < 0)
return err; return err;
buf->done = false;
mt76u_fill_bulk_urb(dev, USB_DIR_OUT, q2ep(q->hw_idx), mt76u_fill_bulk_urb(dev, USB_DIR_OUT, q2ep(q->hw_idx),
buf, mt76u_complete_tx, buf); buf, mt76u_complete_tx, buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment