Skip to content

Commit 477206a

Browse files
Julien Ducourthialdavem330
authored andcommitted
r8169: fix unsigned int wraparound with TSO
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>
1 parent c5baa80 commit 477206a

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
@@ -61,8 +61,12 @@
6161
#define R8169_MSG_DEFAULT \
6262
(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
6363

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

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

5118-
if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
5122+
if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
51195123
netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
51205124
goto err_stop_0;
51215125
}
@@ -5169,7 +5173,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
51695173

51705174
mmiowb();
51715175

5172-
if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
5176+
if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
51735177
/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
51745178
* not miss a ring update when it notices a stopped queue.
51755179
*/
@@ -5183,7 +5187,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
51835187
* can't.
51845188
*/
51855189
smp_mb();
5186-
if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
5190+
if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
51875191
netif_wake_queue(dev);
51885192
}
51895193

@@ -5306,7 +5310,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
53065310
*/
53075311
smp_mb();
53085312
if (netif_queue_stopped(dev) &&
5309-
(TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
5313+
TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
53105314
netif_wake_queue(dev);
53115315
}
53125316
/*

0 commit comments

Comments
 (0)