Skip to content

Commit 78cac6f

Browse files
committed
Merge branch 'r8152-modify-rx_bottom'
Hayes Wang says: ==================== r8152: modify rx_bottom v3: For patch #1, this patch is replaced. The new patch only break the loop, and keep that the driver would queue the rx packets. For patch #2, modify the code depends on patch #1. For work_down < budget, napi_get_frags() and napi_gro_frags() would be used. For the others, nothing is changed. v2: For patch #1, add comment, update commit message, and add Fixes tag. v1: These patches are used to improve rx_bottom(). ==================== Link: https://lore.kernel.org/r/20230926111714.9448-432-nic_swsd@realtek.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents f8e5b77 + 788d30d commit 78cac6f

File tree

1 file changed

+63
-22
lines changed

1 file changed

+63
-22
lines changed

drivers/net/usb/r8152.c

+63-22
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ static int rx_bottom(struct r8152 *tp, int budget)
24492449
}
24502450
}
24512451

2452-
if (list_empty(&tp->rx_done))
2452+
if (list_empty(&tp->rx_done) || work_done >= budget)
24532453
goto out1;
24542454

24552455
clear_bit(RX_EPROTO, &tp->flags);
@@ -2465,6 +2465,15 @@ static int rx_bottom(struct r8152 *tp, int budget)
24652465
struct urb *urb;
24662466
u8 *rx_data;
24672467

2468+
/* A bulk transfer of USB may contain may packets, so the
2469+
* total packets may more than the budget. Deal with all
2470+
* packets in current bulk transfer, and stop to handle the
2471+
* next bulk transfer until next schedule, if budget is
2472+
* exhausted.
2473+
*/
2474+
if (work_done >= budget)
2475+
break;
2476+
24682477
list_del_init(cursor);
24692478

24702479
agg = list_entry(cursor, struct rx_agg, list);
@@ -2481,12 +2490,11 @@ static int rx_bottom(struct r8152 *tp, int budget)
24812490
while (urb->actual_length > len_used) {
24822491
struct net_device *netdev = tp->netdev;
24832492
struct net_device_stats *stats = &netdev->stats;
2484-
unsigned int pkt_len, rx_frag_head_sz;
2493+
unsigned int pkt_len, rx_frag_head_sz, len;
24852494
struct sk_buff *skb;
2495+
bool use_frags;
24862496

2487-
/* limit the skb numbers for rx_queue */
2488-
if (unlikely(skb_queue_len(&tp->rx_queue) >= 1000))
2489-
break;
2497+
WARN_ON_ONCE(skb_queue_len(&tp->rx_queue) >= 1000);
24902498

24912499
pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
24922500
if (pkt_len < ETH_ZLEN)
@@ -2497,45 +2505,77 @@ static int rx_bottom(struct r8152 *tp, int budget)
24972505
break;
24982506

24992507
pkt_len -= ETH_FCS_LEN;
2508+
len = pkt_len;
25002509
rx_data += sizeof(struct rx_desc);
25012510

2502-
if (!agg_free || tp->rx_copybreak > pkt_len)
2503-
rx_frag_head_sz = pkt_len;
2511+
if (!agg_free || tp->rx_copybreak > len)
2512+
use_frags = false;
25042513
else
2505-
rx_frag_head_sz = tp->rx_copybreak;
2514+
use_frags = true;
2515+
2516+
if (use_frags) {
2517+
/* If the budget is exhausted, the packet
2518+
* would be queued in the driver. That is,
2519+
* napi_gro_frags() wouldn't be called, so
2520+
* we couldn't use napi_get_frags().
2521+
*/
2522+
if (work_done >= budget) {
2523+
rx_frag_head_sz = tp->rx_copybreak;
2524+
skb = napi_alloc_skb(napi,
2525+
rx_frag_head_sz);
2526+
} else {
2527+
rx_frag_head_sz = 0;
2528+
skb = napi_get_frags(napi);
2529+
}
2530+
} else {
2531+
rx_frag_head_sz = 0;
2532+
skb = napi_alloc_skb(napi, len);
2533+
}
25062534

2507-
skb = napi_alloc_skb(napi, rx_frag_head_sz);
25082535
if (!skb) {
25092536
stats->rx_dropped++;
25102537
goto find_next_rx;
25112538
}
25122539

25132540
skb->ip_summed = r8152_rx_csum(tp, rx_desc);
2514-
memcpy(skb->data, rx_data, rx_frag_head_sz);
2515-
skb_put(skb, rx_frag_head_sz);
2516-
pkt_len -= rx_frag_head_sz;
2517-
rx_data += rx_frag_head_sz;
2518-
if (pkt_len) {
2541+
rtl_rx_vlan_tag(rx_desc, skb);
2542+
2543+
if (use_frags) {
2544+
if (rx_frag_head_sz) {
2545+
memcpy(skb->data, rx_data,
2546+
rx_frag_head_sz);
2547+
skb_put(skb, rx_frag_head_sz);
2548+
len -= rx_frag_head_sz;
2549+
rx_data += rx_frag_head_sz;
2550+
skb->protocol = eth_type_trans(skb,
2551+
netdev);
2552+
}
2553+
25192554
skb_add_rx_frag(skb, 0, agg->page,
25202555
agg_offset(agg, rx_data),
2521-
pkt_len,
2522-
SKB_DATA_ALIGN(pkt_len));
2556+
len, SKB_DATA_ALIGN(len));
25232557
get_page(agg->page);
2558+
} else {
2559+
memcpy(skb->data, rx_data, len);
2560+
skb_put(skb, len);
2561+
skb->protocol = eth_type_trans(skb, netdev);
25242562
}
25252563

2526-
skb->protocol = eth_type_trans(skb, netdev);
2527-
rtl_rx_vlan_tag(rx_desc, skb);
25282564
if (work_done < budget) {
2565+
if (use_frags)
2566+
napi_gro_frags(napi);
2567+
else
2568+
napi_gro_receive(napi, skb);
2569+
25292570
work_done++;
25302571
stats->rx_packets++;
2531-
stats->rx_bytes += skb->len;
2532-
napi_gro_receive(napi, skb);
2572+
stats->rx_bytes += pkt_len;
25332573
} else {
25342574
__skb_queue_tail(&tp->rx_queue, skb);
25352575
}
25362576

25372577
find_next_rx:
2538-
rx_data = rx_agg_align(rx_data + pkt_len + ETH_FCS_LEN);
2578+
rx_data = rx_agg_align(rx_data + len + ETH_FCS_LEN);
25392579
rx_desc = (struct rx_desc *)rx_data;
25402580
len_used = agg_offset(agg, rx_data);
25412581
len_used += sizeof(struct rx_desc);
@@ -2564,9 +2604,10 @@ static int rx_bottom(struct r8152 *tp, int budget)
25642604
}
25652605
}
25662606

2607+
/* Splice the remained list back to rx_done for next schedule */
25672608
if (!list_empty(&rx_queue)) {
25682609
spin_lock_irqsave(&tp->rx_lock, flags);
2569-
list_splice_tail(&rx_queue, &tp->rx_done);
2610+
list_splice(&rx_queue, &tp->rx_done);
25702611
spin_unlock_irqrestore(&tp->rx_lock, flags);
25712612
}
25722613

0 commit comments

Comments
 (0)