Commit d704d16f authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau
Browse files

mt76: usb: do not use sg buffers for mcu messages



Do not use scatter-gather buffers for mcu commands.
Introduce mt76u_buf_alloc and mt76u_buf_alloc_sg routines.

Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 63a7de5d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ struct mt76u_buf {
	struct mt76_dev *dev;
	struct urb *urb;
	size_t len;
	void *buf;
	bool done;
};

@@ -748,7 +749,7 @@ void mt76u_single_wr(struct mt76_dev *dev, const u8 req,
int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf);
void mt76u_deinit(struct mt76_dev *dev);
int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf,
		    int nsgs, int len, int sglen, gfp_t gfp);
		    int len, int data_len, gfp_t gfp);
void mt76u_buf_free(struct mt76u_buf *buf);
int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index,
		     struct mt76u_buf *buf, gfp_t gfp,
+1 −2
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ 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;
	u32 rxfce;
	u8 *data;

	for (i = 0; i < 5; i++) {
		if (!wait_for_completion_timeout(&usb->mcu.cmpl,
@@ -75,7 +75,6 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq)
		if (urb->status)
			return -EIO;

		data = sg_virt(&urb->sg[0]);
		if (usb->mcu.rp)
			mt76x02u_multiple_mcu_reads(dev, data + 4,
						    urb->actual_length - 8);
+31 −7
Original line number Diff line number Diff line
@@ -319,7 +319,8 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76u_buf *buf,
	return i ? : -ENOMEM;
}

int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf,
static int
mt76u_buf_alloc_sg(struct mt76_dev *dev, struct mt76u_buf *buf,
		   int nsgs, int len, int sglen, gfp_t gfp)
{
	buf->urb = usb_alloc_urb(0, gfp);
@@ -337,6 +338,25 @@ int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf,
	return mt76u_fill_rx_sg(dev, buf, nsgs, len, sglen);
}

int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf,
		    int len, int data_len, gfp_t gfp)
{
	struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN];

	buf->urb = usb_alloc_urb(0, gfp);
	if (!buf->urb)
		return -ENOMEM;

	buf->buf = page_frag_alloc(&q->rx_page, len, gfp);
	if (!buf->buf)
		return -ENOMEM;

	buf->len = data_len;
	buf->dev = dev;

	return 0;
}

void mt76u_buf_free(struct mt76u_buf *buf)
{
	struct urb *urb = buf->urb;
@@ -350,6 +370,9 @@ void mt76u_buf_free(struct mt76u_buf *buf)

		skb_free_frag(sg_virt(sg));
	}
	if (buf->buf)
		skb_free_frag(buf->buf);

	usb_free_urb(buf->urb);
}
EXPORT_SYMBOL_GPL(mt76u_buf_free);
@@ -360,6 +383,7 @@ int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index,
{
	struct usb_interface *intf = to_usb_interface(dev->dev);
	struct usb_device *udev = interface_to_usbdev(intf);
	u8 *data = buf->urb->num_sgs ? NULL : buf->buf;
	unsigned int pipe;

	if (dir == USB_DIR_IN)
@@ -367,7 +391,7 @@ int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index,
	else
		pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[index]);

	usb_fill_bulk_urb(buf->urb, udev, pipe, NULL, buf->len,
	usb_fill_bulk_urb(buf->urb, udev, pipe, data, buf->len,
			  complete_fn, context);
	trace_submit_urb(dev, buf->urb);

@@ -555,7 +579,7 @@ static int mt76u_alloc_rx(struct mt76_dev *dev)

	q->ndesc = MT_NUM_RX_ENTRIES;
	for (i = 0; i < q->ndesc; i++) {
		err = mt76u_buf_alloc(dev, &q->entry[i].ubuf,
		err = mt76u_buf_alloc_sg(dev, &q->entry[i].ubuf,
					 nsgs, q->buf_size,
					 SKB_WITH_OVERHEAD(q->buf_size),
					 GFP_KERNEL);
+2 −3
Original line number Diff line number Diff line
@@ -29,9 +29,8 @@ 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, 1,
			      MCU_RESP_URB_SIZE, MCU_RESP_URB_SIZE,
			      GFP_KERNEL);
	err = mt76u_buf_alloc(dev, &usb->mcu.res, MCU_RESP_URB_SIZE,
			      MCU_RESP_URB_SIZE, GFP_KERNEL);
	if (err < 0)
		return err;