Skip to content

Commit a549123

Browse files
Julien Ducourthialbwhacks
authored andcommitted
r8169: fix unsigned int wraparound with TSO
[ Upstream commit 477206a ] The r8169 may get stuck or show bad behaviour after activating TSO : the net_device is not stopped when it has no more TX descriptors. This problem comes from TX_BUFS_AVAIL which may reach -1 when all transmit descriptors are in use. The patch simply tries to keep positive values. Tested with 8111d(onboard) on a D510MO, and with 8111e(onboard) on a Zotac 890GXITX. Signed-off-by: Julien Ducourthial <jducourt@free.fr> Acked-by: Francois Romieu <romieu@fr.zoreil.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent ba3d9c0 commit a549123

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

  • drivers/net/ethernet/realtek

‎drivers/net/ethernet/realtek/r8169.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@
6262
#define R8169_MSG_DEFAULT \
6363
(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
6464

65-
#define TX_BUFFS_AVAIL(tp) \
66-
(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
65+
#define TX_SLOTS_AVAIL(tp) \
66+
(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
67+
68+
/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
69+
#define TX_FRAGS_READY_FOR(tp,nr_frags) \
70+
(TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
6771

6872
/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
6973
The RTL chips use a 64 element hash table based on the Ethernet CRC. */
@@ -5512,7 +5516,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
55125516
u32 opts[2];
55135517
int frags;
55145518

5515-
if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
5519+
if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
55165520
netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
55175521
goto err_stop_0;
55185522
}
@@ -5560,7 +5564,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
55605564

55615565
RTL_W8(TxPoll, NPQ);
55625566

5563-
if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
5567+
if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
55645568
/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
55655569
* not miss a ring update when it notices a stopped queue.
55665570
*/
@@ -5574,7 +5578,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
55745578
* can't.
55755579
*/
55765580
smp_mb();
5577-
if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
5581+
if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
55785582
netif_wake_queue(dev);
55795583
}
55805584

@@ -5683,7 +5687,7 @@ static void rtl8169_tx_interrupt(struct net_device *dev,
56835687
*/
56845688
smp_mb();
56855689
if (netif_queue_stopped(dev) &&
5686-
(TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
5690+
TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
56875691
netif_wake_queue(dev);
56885692
}
56895693
/*

0 commit comments

Comments
 (0)