Skip to contentSkip to conversation

r8152: adjust rx functions

PATCH Superseded Hayes Wang 3 participants 27 messages Nov 7, 2014 – Nov 21, 2014

Subsystems (3)
lore
Share & tools
lore

Hayes Wang

author
#0 lore raw

cover r8152: adjust rx functions

Adjust some flows and codes which are relative to r8152_submit_rx() and rtl_start_rx().

Hayes Wang (2):
r8152: adjust r8152_submit_rx
r8152: adjust rtl_start_rx

 drivers/net/usb/r8152.c | 51 +++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 23 deletions(-)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH 1/2 r8152: adjust r8152_submit_rx

The behavior of handling the returned status from r8152_submit_rx() is almost same, so let r8152_submit_rx() deal with the error directly. This could avoid the duplicate code.

---
 drivers/net/usb/r8152.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/net/usb/r8152.c +19 -20
index 66b139a..ad62994 100644
@@ -1032,7 +1032,6 @@ static void read_bulk_callback(struct urb *urb)
 	int status = urb->status;
 	struct rx_agg *agg;
 	struct r8152 *tp;
-	int result;
 
 	agg = urb->context;
 	if (!agg)
@@ -1083,16 +1082,7 @@ static void read_bulk_callback(struct urb *urb)
 		break;
 	}
 
-	result = r8152_submit_rx(tp, agg, GFP_ATOMIC);
-	if (result == -ENODEV) {
-		set_bit(RTL8152_UNPLUG, &tp->flags);
-		netif_device_detach(tp->netdev);
-	} else if (result) {
-		spin_lock(&tp->rx_lock);
-		list_add_tail(&agg->list, &tp->rx_done);
-		spin_unlock(&tp->rx_lock);
-		tasklet_schedule(&tp->tl);
-	}
+	r8152_submit_rx(tp, agg, GFP_ATOMIC);
 }
 
 static void write_bulk_callback(struct urb *urb)
@@ -1681,7 +1671,6 @@ static void rx_bottom(struct r8152 *tp)
 		int len_used = 0;
 		struct urb *urb;
 		u8 *rx_data;
-		int ret;
 
 		list_del_init(cursor);
 
@@ -1734,13 +1723,7 @@ find_next_rx:
 		}
 
 submit:
-		ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
-		if (ret && ret != -ENODEV) {
-			spin_lock_irqsave(&tp->rx_lock, flags);
-			list_add_tail(&agg->list, &tp->rx_done);
-			spin_unlock_irqrestore(&tp->rx_lock, flags);
-			tasklet_schedule(&tp->tl);
-		}
+		r8152_submit_rx(tp, agg, GFP_ATOMIC);
 	}
 }
 
@@ -1805,11 +1788,27 @@ static void bottom_half(unsigned long data)
 static
 int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
 {
+	int ret = 0;
+
 	usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
 			  agg->head, agg_buf_sz,
 			  (usb_complete_t)read_bulk_callback, agg);
 
-	return usb_submit_urb(agg->urb, mem_flags);
+	ret = usb_submit_urb(agg->urb, mem_flags);
+
+	if (ret == -ENODEV) {
+		set_bit(RTL8152_UNPLUG, &tp->flags);
+		netif_device_detach(tp->netdev);
+	} else if (ret) {
+		unsigned long flags;
+
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_add_tail(&agg->list, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
+		tasklet_schedule(&tp->tl);
+	}
+
+	return ret;
 }
 
 static void rtl_drop_queued_tx(struct r8152 *tp)
Signature · 1 line
1.9.3
author
#2 lore raw

PATCH 2/2 r8152: adjust rtl_start_rx

In reply to Hayes Wang

Submit all the rx buffers, even though a error occurs. Otherwise the buffers which are not submitted would be lost until next rtl_start_rx() is called. Besides, the fail buffer could be re-submitted later.

---
 drivers/net/usb/r8152.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/usb/r8152.c +9 -3
index ad62994..5e0386f 100644
@@ -1993,10 +1993,16 @@ static int rtl_start_rx(struct r8152 *tp)
 
 	INIT_LIST_HEAD(&tp->rx_done);
 	for (i = 0; i < RTL8152_MAX_RX; i++) {
+		int rr;
+
 		INIT_LIST_HEAD(&tp->rx_info[i].list);
-		ret = r8152_submit_rx(tp, &tp->rx_info[i], GFP_KERNEL);
-		if (ret)
-			break;
+
+		rr = r8152_submit_rx(tp, &tp->rx_info[i], GFP_KERNEL);
+		if (rr)
+			netif_err(tp, rx_err, tp->netdev,
+				  "Couldn't submit rx[%d], ret = %d\n", i, rr);
+		if (!ret)
+			ret = rr;
 	}
 
 	return ret;
Signature · 1 line
1.9.3
maintainer
#3 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Fri, 7 Nov 2014 17:55:11 +0800

Quoted 6 lines

Submit all the rx buffers, even though a error occurs. Otherwise the buffers which are not submitted would be lost until next rtl_start_rx() is called. Besides, the fail buffer could be re-submitted later.

Does this even work?

If you leave a hole in the ring, the device is going to stop there anyways.

So better to replenish the next time you call into this function rather than leaving gaps in your receive ring.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Saturday, November 08, 2014 12:35 AM

[...]

Quoted 4 lines

Does this even work?

If you leave a hole in the ring, the device is going to stop there anyways.

Excuse me. I don't sure I understand your meaning clearly.

The behavior is different for PCI(e) and USB ethernet device. The PCI nic could know the ring buffer by certain way, so the device could fill the data into the buffer one by one automatically. However, for usb nic, the driver has to indicate (i.e. submit) each buffer for each data. The device doesn't know what is the next buffer by itself. That is, the driver determines the order by which the data would be filled.

Therefore, when I try to submit 10 rx buffers and some of them fail, I could get the data depending on the order of the successful ones. Besides, the driver has to submit the buffer for next data continually, so the previous unsuccessful ones could be tried again for the same time.

Best Regards,
Hayes

maintainer
#5 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Mon, 10 Nov 2014 03:29:27 +0000

Quoted 9 lines

The behavior is different for PCI(e) and USB ethernet device. The PCI nic could know the ring buffer by certain way, so the device could fill the data into the buffer one by one automatically. However, for usb nic, the driver has to indicate (i.e. submit) each buffer for each data. The device doesn't know what is the next buffer by itself. That is, the driver determines the order by which the data would be filled.

Quoted 5 lines

Therefore, when I try to submit 10 rx buffers and some of them fail, I could get the data depending on the order of the successful ones. Besides, the driver has to submit the buffer for next data continually, so the previous unsuccessful ones could be tried again for the same time.

Ok, but if we are looping here in rtl_start_rx() and r8152_submit_rx() fails due to a memory allocation failure, there is nothing which is going to make such a memory allocation succeed in the next iteration of the loop.

Unless you can prove that often it can succeed after an initial failure, this is just wasted work and in fact making it take longer for the system to reclaim memory when under pressure because these extra iterations are completely wasted cpu work.

author
#6 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, November 12, 2014 10:51 AM

[...]

Quoted 9 lines

Ok, but if we are looping here in rtl_start_rx() and r8152_submit_rx() fails due to a memory allocation failure, there is nothing which is going to make such a memory allocation succeed in the next iteration of the loop.

Unless you can prove that often it can succeed after an initial failure, this is just wasted work and in fact making it take longer for the system to reclaim memory when under pressure because these extra iterations are completely wasted cpu work.

How about that when a error occurs, add the remaining rx to the list without submission? Then, the remianing rx could be re-submitted later, and the rtl_start_rx() could be completed as soon as possible.

drivers/net/usb/r8152.c +22 -1
index 0a30fd3..3273e3d 100644
@@ -1991,14 +1991,35 @@ static void rxdy_gated_en(struct r8152 *tp, bool enable)
 
 static int rtl_start_rx(struct r8152 *tp)
 {
+	struct list_head rx_queue;
 	int i, ret = 0;
 
 	INIT_LIST_HEAD(&tp->rx_done);
 	for (i = 0; i < RTL8152_MAX_RX; i++) {
 		INIT_LIST_HEAD(&tp->rx_info[i].list);
 		ret = r8152_submit_rx(tp, &tp->rx_info[i], GFP_KERNEL);
-		if (ret)
+		if (ret) {
+			i++;
 			break;
+		}
+	}
+
+	INIT_LIST_HEAD(&rx_queue);
+	for (; i < RTL8152_MAX_RX; i++) {
+		struct rx_agg *agg = &tp->rx_info[i];
+		struct urb *urb = agg->urb;
+
+		INIT_LIST_HEAD(&agg->list);
+		urb->actual_length = 0;
+		list_add_tail(&agg->list, &rx_queue);
+	}
+
+	if (!list_empty(&rx_queue)) {
+		unsigned long flags;
+
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_splice_tail(&rx_queue, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
 	}
 
 	return ret;

Best Regards,
Hayes

maintainer
#7 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Wed, 12 Nov 2014 05:07:40 +0000

Quoted 4 lines

How about that when a error occurs, add the remaining rx to the list without submission? Then, the remianing rx could be re-submitted later, and the rtl_start_rx() could be completed as soon as possible.

I really want to know why you are spending so much effort on this.

Is there a real situation that happened very often, which you diagnosed in detail, and therefore you want to address?

author
#8 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, November 12, 2014 1:13 PM

[...]

Quoted 4 lines

I really want to know why you are spending so much effort on this.

Is there a real situation that happened very often, which you diagnosed in detail, and therefore you want to address?

No. I just consider the possible situation and want to make the driver better. If you think this is unnecessary, I would remove it.

Best Regards,
Hayes

maintainer
#9 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Wed, 12 Nov 2014 05:23:03 +0000

Quoted 11 lines

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, November 12, 2014 1:13 PM

[...]

Quoted 4 lines

I really want to know why you are spending so much effort on this.

Is there a real situation that happened very often, which you diagnosed in detail, and therefore you want to address?

No. I just consider the possible situation and want to make the driver better. If you think this is unnecessary, I would remove it.

What do other USB network drivers do in similar situations?

author
#10 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, November 12, 2014 1:44 PM

[...]

Quoted 1 line

What do other USB network drivers do in similar situations?

According to the usbnet.c, it would make sure to submit the number of min(10, RX_QLEN(dev)) rx buffers. If there are not enough rx buffers, it schedule a tasklet for next try.

The brief flow is as following.
1. Call open().
- schedule a tasklet.
2. Tasklet is called.
if (dev->rxq.qlen < RX_QLEN(dev)) {
- submit rx buffers util the number of
min(10, RX_QLEN(dev)). If the error
occurs, break the loop.
- If the dev->rxq.qlen < RX_QLEN(dev),
schedule the tasklet.
}

Best Regards,
Hayes

maintainer
#11 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Wed, 12 Nov 2014 06:29:46 +0000

Quoted 9 lines

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, November 12, 2014 1:44 PM

[...]

Quoted 1 line

What do other USB network drivers do in similar situations?

According to the usbnet.c, it would make sure to submit the number of min(10, RX_QLEN(dev)) rx buffers. If there are not enough rx buffers, it schedule a tasklet for next try.

Quoted 11 lines

The brief flow is as following.
1. Call open().
- schedule a tasklet.
2. Tasklet is called.
if (dev->rxq.qlen < RX_QLEN(dev)) {
- submit rx buffers util the number of
min(10, RX_QLEN(dev)). If the error
occurs, break the loop.
- If the dev->rxq.qlen < RX_QLEN(dev),
schedule the tasklet.
}

That sounds like a better recovery model, why don't you mimick it?

author
#12 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Thursday, November 13, 2014 3:50 AM

[...]

Quoted 16 lines
Quoted 4 lines

According to the usbnet.c, it would make sure to submit the number of min(10, RX_QLEN(dev)) rx buffers. If there are not enough rx buffers, it schedule a tasklet for next try.

Quoted 11 lines

The brief flow is as following.
1. Call open().
- schedule a tasklet.
2. Tasklet is called.
if (dev->rxq.qlen < RX_QLEN(dev)) {
- submit rx buffers util the number of
min(10, RX_QLEN(dev)). If the error
occurs, break the loop.
- If the dev->rxq.qlen < RX_QLEN(dev),
schedule the tasklet.
}

Quoted 1 line

That sounds like a better recovery model, why don't you mimick it?

My last method which I mentioned yesterday is similar to this one. The difference is that I would re-use the rx buffers, so I have to add them to the list for re-submitting, not alwayes allocate new one.

Although one rx buffer could contain many packets, I don't think the whole size of the rx buffer is alwayes used. Therefore, I re-use the rx buffers to avoid allocating the 16K bytes rx buffer alwayes. This also makes sure that I always have the buffers to submit without allocating new one.

If you could accept this, I would modify this patch by this way.

Best Regards,
Hayes

maintainer
#13 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Thu, 13 Nov 2014 02:31:14 +0000

Quoted 12 lines

My last method which I mentioned yesterday is similar to this one. The difference is that I would re-use the rx buffers, so I have to add them to the list for re-submitting, not alwayes allocate new one.

Although one rx buffer could contain many packets, I don't think the whole size of the rx buffer is alwayes used. Therefore, I re-use the rx buffers to avoid allocating the 16K bytes rx buffer alwayes. This also makes sure that I always have the buffers to submit without allocating new one.

Quoted 2 lines

If you could accept this, I would modify this patch by this way.

I'll reread your original patch and think some more about this.

Thanks.

maintainer
#14 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: David Miller <[email protected]>
Date: Wed, 12 Nov 2014 22:31:46 -0500 (EST)

Quoted 15 lines

From: Hayes Wang <[email protected]>
Date: Thu, 13 Nov 2014 02:31:14 +0000

Quoted 12 lines

My last method which I mentioned yesterday is similar to this one. The difference is that I would re-use the rx buffers, so I have to add them to the list for re-submitting, not alwayes allocate new one.

Although one rx buffer could contain many packets, I don't think the whole size of the rx buffer is alwayes used. Therefore, I re-use the rx buffers to avoid allocating the 16K bytes rx buffer alwayes. This also makes sure that I always have the buffers to submit without allocating new one.

Quoted 4 lines
Quoted 2 lines

If you could accept this, I would modify this patch by this way.

I'll reread your original patch and think some more about this.

What if even the first r8152_submit_rx() fails? What ever will cause any of these retries to trigger at all?

Second, why does your patch increment 'i' with 'i++;' in the error break path? You should mark the first failed entry as unallocated with actual_length == 0 and place it on the rx_done queue.

author
#15 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Friday, November 14, 2014 5:23 AM

[...]

Quoted 2 lines

What if even the first r8152_submit_rx() fails? What ever will cause any of these retries to trigger at all?

According to the patch #1 "adjust r8152_submit_rx", the r8152_submit_rx() would add the rx to the list and schedule the tasklet, when the error occurs. Each time the tasklet is called, the rx_bottom() would deal with all the rx in the list. If the actual_length isn't vaild, the rx buffer would be submitted directly. By this way, the retries would be done. That is, the retries would be triggered when the tasklet is called. Therefore, any tx, rx, and tasklet scheduling would result in the retries.

Quoted 3 lines

Second, why does your patch increment 'i' with 'i++;' in the error break path? You should mark the first failed entry as unallocated with actual_length == 0 and place it on the rx_done queue.

Because the r8152_submit_rx() would add the failed rx to the list, I only have to deal with the remaining ones. That is why I increase the "i", otherwise the failed one would be added twice.

I remember the usb_submit_urb() would set actual_length to 0, so I skip the step. I would check it again.

Best Regards,
Hayes

author
#16 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

In reply to David Miller

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Saturday, November 08, 2014 12:35 AM

[...]

Quoted 7 lines

Does this even work?

If you leave a hole in the ring, the device is going to stop there anyways.

So better to replenish the next time you call into this function rather than leaving gaps in your receive ring.

Excuse me. Is this still unacceptable?
Should I remove this patch for keeping the original flow?

Best Regards,
Hayes

maintainer
#17 lore raw

Re: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

From: Hayes Wang <[email protected]>
Date: Wed, 12 Nov 2014 01:45:08 +0000

Quoted 5 lines

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Saturday, November 08, 2014 12:35 AM

[...]

Quoted 2 lines

Does this even work?

Quoted 8 lines
Quoted 5 lines

If you leave a hole in the ring, the device is going to stop there anyways.

So better to replenish the next time you call into this function rather than leaving gaps in your receive ring.

Excuse me. Is this still unacceptable?
Should I remove this patch for keeping the original flow?

I haven't had time to process your original reply, please be patient.

author
#18 lore raw

RE: [PATCH net-next 2/2] r8152: adjust rtl_start_rx

David Miller [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, November 12, 2014 10:20 AM

[...]

Quoted 1 line

I haven't had time to process your original reply, please be patient.

I am sorry for bothering you, and thanks for your reply.

Best Regards,
Hayes

author
#19 lore raw

v2 cover r8152: adjust rx functions

In reply to Hayes Wang

v2:
For patch #1, set actual_length to 0 before adding the rx to the list, when a error occurs.

For patch #2, change the flow. Stop submitting the rx if a error occurs, and add the remaining rx to the list for submitting later.

v1:
Adjust some flows and codes which are relative to r8152_submit_rx() and rtl_start_rx().

Hayes Wang (2):
r8152: adjust r8152_submit_rx
r8152: adjust rtl_start_rx

 drivers/net/usb/r8152.c | 60 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 20 deletions(-)
Signature · 1 line
1.9.3
author
#20 lore raw

PATCH v2 1/2 r8152: adjust r8152_submit_rx

The behavior of handling the returned status from r8152_submit_rx() is almost same, so let r8152_submit_rx() deal with the error directly. This could avoid the duplicate code.

---
 drivers/net/usb/r8152.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
drivers/net/usb/r8152.c +21 -20
index 0a30fd3..df0868b 100644
@@ -1032,7 +1032,6 @@ static void read_bulk_callback(struct urb *urb)
 	int status = urb->status;
 	struct rx_agg *agg;
 	struct r8152 *tp;
-	int result;
 
 	agg = urb->context;
 	if (!agg)
@@ -1083,16 +1082,7 @@ static void read_bulk_callback(struct urb *urb)
 		break;
 	}
 
-	result = r8152_submit_rx(tp, agg, GFP_ATOMIC);
-	if (result == -ENODEV) {
-		set_bit(RTL8152_UNPLUG, &tp->flags);
-		netif_device_detach(tp->netdev);
-	} else if (result) {
-		spin_lock(&tp->rx_lock);
-		list_add_tail(&agg->list, &tp->rx_done);
-		spin_unlock(&tp->rx_lock);
-		tasklet_schedule(&tp->tl);
-	}
+	r8152_submit_rx(tp, agg, GFP_ATOMIC);
 }
 
 static void write_bulk_callback(struct urb *urb)
@@ -1680,7 +1670,6 @@ static void rx_bottom(struct r8152 *tp)
 		int len_used = 0;
 		struct urb *urb;
 		u8 *rx_data;
-		int ret;
 
 		list_del_init(cursor);
 
@@ -1733,13 +1722,7 @@ find_next_rx:
 		}
 
 submit:
-		ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
-		if (ret && ret != -ENODEV) {
-			spin_lock_irqsave(&tp->rx_lock, flags);
-			list_add_tail(&agg->list, &tp->rx_done);
-			spin_unlock_irqrestore(&tp->rx_lock, flags);
-			tasklet_schedule(&tp->tl);
-		}
+		r8152_submit_rx(tp, agg, GFP_ATOMIC);
 	}
 }
 
@@ -1806,11 +1789,29 @@ static void bottom_half(unsigned long data)
 static
 int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
 {
+	int ret = 0;
+
 	usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
 			  agg->head, agg_buf_sz,
 			  (usb_complete_t)read_bulk_callback, agg);
 
-	return usb_submit_urb(agg->urb, mem_flags);
+	ret = usb_submit_urb(agg->urb, mem_flags);
+
+	if (ret == -ENODEV) {
+		set_bit(RTL8152_UNPLUG, &tp->flags);
+		netif_device_detach(tp->netdev);
+	} else if (ret) {
+		struct urb *urb = agg->urb;
+		unsigned long flags;
+
+		urb->actual_length = 0;
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_add_tail(&agg->list, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
+		tasklet_schedule(&tp->tl);
+	}
+
+	return ret;
 }
 
 static void rtl_drop_queued_tx(struct r8152 *tp)
Signature · 1 line
1.9.3
#21 lore raw

Re: [PATCH net-next v2 1/2] r8152: adjust r8152_submit_rx

Hello.

Quoted 13 lines · Hayes Wang

The behavior of handling the returned status from r8152_submit_rx() is almost same, so let r8152_submit_rx() deal with the error directly. This could avoid the duplicate code.

---
  drivers/net/usb/r8152.c | 41 +++++++++++++++++++++--------------------
  1 file changed, 21 insertions(+), 20 deletions(-)
drivers/net/usb/r8152.c +0 -0
index 0a30fd3..df0868b 100644

[...]

drivers/net/usb/r8152.c static void bottom_half(unsigned long data) · line 1792

Quoted 5 lines
drivers/net/usb/r8152.c +1 -0
@@ -1806,11 +1789,29 @@ static void bottom_half(unsigned long data)
  static
  int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
  {
+	int ret = 0;

Initialization not needed.

drivers/net/usb/r8152.c static void bottom_half(unsigned long data) · line 1799

Quoted 8 lines
drivers/net/usb/r8152.c +3 -1
+
  	usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
  			  agg->head, agg_buf_sz,
  			  (usb_complete_t)read_bulk_callback, agg);
 
-	return usb_submit_urb(agg->urb, mem_flags);
+	ret = usb_submit_urb(agg->urb, mem_flags);
+

Empty line not needed here either.

Quoted 6 lines
drivers/net/usb/r8152.c +6 -0
+	if (ret == -ENODEV) {
+		set_bit(RTL8152_UNPLUG, &tp->flags);
+		netif_device_detach(tp->netdev);
+	} else if (ret) {
+		struct urb *urb = agg->urb;
+		unsigned long flags;

drivers/net/usb/r8152.c static void bottom_half(unsigned long data) · line 1815

Quoted 10 lines
drivers/net/usb/r8152.c +9 -0
+
+		urb->actual_length = 0;
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_add_tail(&agg->list, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
+		tasklet_schedule(&tp->tl);
+	}
+
+	return ret;
  }

[...]

WBR, Sergei

author
#22 lore raw

PATCH v2 2/2 r8152: adjust rtl_start_rx

In reply to Hayes Wang

If there is a error for r8152_submit_rx(), add the remaining rx buffers to the list. Then the remaining rx buffers could be submitted later.

---
 drivers/net/usb/r8152.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/net/usb/r8152.c +19 -0
index df0868b..c7acadd 100644
@@ -2002,6 +2002,25 @@ static int rtl_start_rx(struct r8152 *tp)
 			break;
 	}
 
+	if (ret && ++i < RTL8152_MAX_RX) {
+		struct list_head rx_queue;
+		unsigned long flags;
+
+		INIT_LIST_HEAD(&rx_queue);
+
+		do {
+			struct rx_agg *agg = &tp->rx_info[i++];
+			struct urb *urb = agg->urb;
+
+			urb->actual_length = 0;
+			list_add_tail(&agg->list, &rx_queue);
+		} while (i < RTL8152_MAX_RX);
+
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_splice_tail(&rx_queue, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
+	}
+
 	return ret;
 }
 
Signature · 1 line
1.9.3
author
#23 lore raw

v3 cover r8152: adjust rx functions

In reply to Hayes Wang

v3:
For patch #1, remove unnecessary initialization for ret and unnecessary blank line in r8152_submit_rx().

v2:
For patch #1, set actual_length to 0 before adding the rx to the list, when a error occurs.

For patch #2, change the flow. Stop submitting the rx if a error occurs, and add the remaining rx to the list for submitting later.

v1:
Adjust some flows and codes which are relative to r8152_submit_rx() and rtl_start_rx().

Hayes Wang (2):
r8152: adjust r8152_submit_rx
r8152: adjust rtl_start_rx

 drivers/net/usb/r8152.c | 60 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 20 deletions(-)

--
1.9.3

author
#24 lore raw

PATCH v3 1/2 r8152: adjust r8152_submit_rx

The behavior of handling the returned status from r8152_submit_rx() is almost same, so let r8152_submit_rx() deal with the error directly. This could avoid the duplicate code.

---
 drivers/net/usb/r8152.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/net/usb/r8152.c +20 -20
index 0a30fd3..3b89229 100644
@@ -1032,7 +1032,6 @@ static void read_bulk_callback(struct urb *urb)
 	int status = urb->status;
 	struct rx_agg *agg;
 	struct r8152 *tp;
-	int result;
 
 	agg = urb->context;
 	if (!agg)
@@ -1083,16 +1082,7 @@ static void read_bulk_callback(struct urb *urb)
 		break;
 	}
 
-	result = r8152_submit_rx(tp, agg, GFP_ATOMIC);
-	if (result == -ENODEV) {
-		set_bit(RTL8152_UNPLUG, &tp->flags);
-		netif_device_detach(tp->netdev);
-	} else if (result) {
-		spin_lock(&tp->rx_lock);
-		list_add_tail(&agg->list, &tp->rx_done);
-		spin_unlock(&tp->rx_lock);
-		tasklet_schedule(&tp->tl);
-	}
+	r8152_submit_rx(tp, agg, GFP_ATOMIC);
 }
 
 static void write_bulk_callback(struct urb *urb)
@@ -1680,7 +1670,6 @@ static void rx_bottom(struct r8152 *tp)
 		int len_used = 0;
 		struct urb *urb;
 		u8 *rx_data;
-		int ret;
 
 		list_del_init(cursor);
 
@@ -1733,13 +1722,7 @@ find_next_rx:
 		}
 
 submit:
-		ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
-		if (ret && ret != -ENODEV) {
-			spin_lock_irqsave(&tp->rx_lock, flags);
-			list_add_tail(&agg->list, &tp->rx_done);
-			spin_unlock_irqrestore(&tp->rx_lock, flags);
-			tasklet_schedule(&tp->tl);
-		}
+		r8152_submit_rx(tp, agg, GFP_ATOMIC);
 	}
 }
 
@@ -1806,11 +1789,28 @@ static void bottom_half(unsigned long data)
 static
 int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
 {
+	int ret;
+
 	usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
 			  agg->head, agg_buf_sz,
 			  (usb_complete_t)read_bulk_callback, agg);
 
-	return usb_submit_urb(agg->urb, mem_flags);
+	ret = usb_submit_urb(agg->urb, mem_flags);
+	if (ret == -ENODEV) {
+		set_bit(RTL8152_UNPLUG, &tp->flags);
+		netif_device_detach(tp->netdev);
+	} else if (ret) {
+		struct urb *urb = agg->urb;
+		unsigned long flags;
+
+		urb->actual_length = 0;
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_add_tail(&agg->list, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
+		tasklet_schedule(&tp->tl);
+	}
+
+	return ret;
 }
 
 static void rtl_drop_queued_tx(struct r8152 *tp)
Signature · 1 line
1.9.3
author
#25 lore raw

PATCH v3 2/2 r8152: adjust rtl_start_rx

In reply to Hayes Wang

If there is a error for r8152_submit_rx(), add the remaining rx buffers to the list. Then the remaining rx buffers could be submitted later.

---
 drivers/net/usb/r8152.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/net/usb/r8152.c +19 -0
index 3b89229..4a9ece0 100644
@@ -2001,6 +2001,25 @@ static int rtl_start_rx(struct r8152 *tp)
 			break;
 	}
 
+	if (ret && ++i < RTL8152_MAX_RX) {
+		struct list_head rx_queue;
+		unsigned long flags;
+
+		INIT_LIST_HEAD(&rx_queue);
+
+		do {
+			struct rx_agg *agg = &tp->rx_info[i++];
+			struct urb *urb = agg->urb;
+
+			urb->actual_length = 0;
+			list_add_tail(&agg->list, &rx_queue);
+		} while (i < RTL8152_MAX_RX);
+
+		spin_lock_irqsave(&tp->rx_lock, flags);
+		list_splice_tail(&rx_queue, &tp->rx_done);
+		spin_unlock_irqrestore(&tp->rx_lock, flags);
+	}
+
 	return ret;
 }
 
Signature · 1 line
1.9.3
maintainer
#26 lore raw
In reply to Hayes Wang

From: Hayes Wang <[email protected]>
Date: Thu, 20 Nov 2014 10:29:04 +0800

Quoted 8 lines

v3:
For patch #1, remove unnecessary initialization for ret and unnecessary blank line in r8152_submit_rx().

v2:
For patch #1, set actual_length to 0 before adding the rx to the list, when a error occurs.

Quoted 6 lines

For patch #2, change the flow. Stop submitting the rx if a error occurs, and add the remaining rx to the list for submitting later.

v1:
Adjust some flows and codes which are relative to r8152_submit_rx() and rtl_start_rx().

Series applied, thanks.