mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-20 21:33:58 +00:00
usbnet: Fix tx_bytes statistic running backward in cdc_ncm
cdc_ncm disagrees with usbnet about how much framing overhead should
be counted in the tx_bytes statistics, and tries 'fix' this by
decrementing tx_bytes on the transmit path. But statistics must never
be decremented except due to roll-over; this will thoroughly confuse
user-space. Also, tx_bytes is only incremented by usbnet in the
completion path.
Fix this by requiring drivers that set FLAG_MULTI_FRAME to set a
tx_bytes delta along with the tx_packets count.
Fixes: beeecd42c3
("net: cdc_ncm/cdc_mbim: adding NCM protocol statistics")
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
This commit is contained in:
parent
1e9e39f4a2
commit
7a1e890e21
5 changed files with 22 additions and 11 deletions
|
@ -189,7 +189,7 @@ struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
|
||||||
skb_put(skb, sizeof(padbytes));
|
skb_put(skb, sizeof(padbytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
usbnet_set_skb_tx_stats(skb, 1);
|
usbnet_set_skb_tx_stats(skb, 1, 0);
|
||||||
return skb;
|
return skb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1177,13 +1177,12 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
|
||||||
ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload;
|
ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload;
|
||||||
ctx->tx_ntbs++;
|
ctx->tx_ntbs++;
|
||||||
|
|
||||||
/* usbnet has already counted all the framing overhead.
|
/* usbnet will count all the framing overhead by default.
|
||||||
* Adjust the stats so that the tx_bytes counter show real
|
* Adjust the stats so that the tx_bytes counter show real
|
||||||
* payload data instead.
|
* payload data instead.
|
||||||
*/
|
*/
|
||||||
dev->net->stats.tx_bytes -= skb_out->len - ctx->tx_curr_frame_payload;
|
usbnet_set_skb_tx_stats(skb_out, n,
|
||||||
|
ctx->tx_curr_frame_payload - skb_out->len);
|
||||||
usbnet_set_skb_tx_stats(skb_out, n);
|
|
||||||
|
|
||||||
return skb_out;
|
return skb_out;
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ static struct sk_buff *sr_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
|
||||||
skb_put(skb, sizeof(padbytes));
|
skb_put(skb, sizeof(padbytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
usbnet_set_skb_tx_stats(skb, 1);
|
usbnet_set_skb_tx_stats(skb, 1, 0);
|
||||||
return skb;
|
return skb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1346,9 +1346,19 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
|
||||||
} else
|
} else
|
||||||
urb->transfer_flags |= URB_ZERO_PACKET;
|
urb->transfer_flags |= URB_ZERO_PACKET;
|
||||||
}
|
}
|
||||||
entry->length = urb->transfer_buffer_length = length;
|
urb->transfer_buffer_length = length;
|
||||||
if (!(info->flags & FLAG_MULTI_PACKET))
|
|
||||||
usbnet_set_skb_tx_stats(skb, 1);
|
if (info->flags & FLAG_MULTI_PACKET) {
|
||||||
|
/* Driver has set number of packets and a length delta.
|
||||||
|
* Calculate the complete length and ensure that it's
|
||||||
|
* positive.
|
||||||
|
*/
|
||||||
|
entry->length += length;
|
||||||
|
if (WARN_ON_ONCE(entry->length <= 0))
|
||||||
|
entry->length = length;
|
||||||
|
} else {
|
||||||
|
usbnet_set_skb_tx_stats(skb, 1, length);
|
||||||
|
}
|
||||||
|
|
||||||
spin_lock_irqsave(&dev->txq.lock, flags);
|
spin_lock_irqsave(&dev->txq.lock, flags);
|
||||||
retval = usb_autopm_get_interface_async(dev->intf);
|
retval = usb_autopm_get_interface_async(dev->intf);
|
||||||
|
|
|
@ -227,7 +227,7 @@ struct skb_data { /* skb->cb is one of these */
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
struct usbnet *dev;
|
struct usbnet *dev;
|
||||||
enum skb_state state;
|
enum skb_state state;
|
||||||
size_t length;
|
long length;
|
||||||
unsigned long packets;
|
unsigned long packets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -235,11 +235,13 @@ struct skb_data { /* skb->cb is one of these */
|
||||||
* tx_fixup method before returning an skb.
|
* tx_fixup method before returning an skb.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
usbnet_set_skb_tx_stats(struct sk_buff *skb, unsigned long packets)
|
usbnet_set_skb_tx_stats(struct sk_buff *skb,
|
||||||
|
unsigned long packets, long bytes_delta)
|
||||||
{
|
{
|
||||||
struct skb_data *entry = (struct skb_data *) skb->cb;
|
struct skb_data *entry = (struct skb_data *) skb->cb;
|
||||||
|
|
||||||
entry->packets = packets;
|
entry->packets = packets;
|
||||||
|
entry->length = bytes_delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int usbnet_open(struct net_device *net);
|
extern int usbnet_open(struct net_device *net);
|
||||||
|
|
Loading…
Add table
Reference in a new issue