Skip to content

Commit 6588af6

Browse files
bwh-ctdavem330
authored andcommitted
usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers
Currently the usbnet core does not update the tx_packets statistic for drivers with FLAG_MULTI_PACKET and there is no hook in the TX completion path where they could do this. cdc_ncm and dependent drivers are bumping tx_packets stat on the transmit path while asix and sr9800 aren't updating it at all. Add a packet count in struct skb_data so these drivers can fill it in, initialise it to 1 for other drivers, and add the packet count to the tx_packets statistic on completion. Signed-off-by: Ben Hutchings <[email protected]> Tested-by: Bjørn Mork <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 721a57a commit 6588af6

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

drivers/net/usb/asix_common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
188188
memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
189189
skb_put(skb, sizeof(padbytes));
190190
}
191+
192+
usbnet_set_skb_tx_stats(skb, 1);
191193
return skb;
192194
}
193195

drivers/net/usb/cdc_ncm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,6 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
11721172

11731173
/* return skb */
11741174
ctx->tx_curr_skb = NULL;
1175-
dev->net->stats.tx_packets += ctx->tx_curr_frame_num;
11761175

11771176
/* keep private stats: framing overhead and number of NTBs */
11781177
ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload;
@@ -1184,6 +1183,8 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
11841183
*/
11851184
dev->net->stats.tx_bytes -= skb_out->len - ctx->tx_curr_frame_payload;
11861185

1186+
usbnet_set_skb_tx_stats(skb_out, n);
1187+
11871188
return skb_out;
11881189

11891190
exit_no_skb:

drivers/net/usb/sr9800.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static struct sk_buff *sr_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
144144
skb_put(skb, sizeof(padbytes));
145145
}
146146

147+
usbnet_set_skb_tx_stats(skb, 1);
147148
return skb;
148149
}
149150

drivers/net/usb/usbnet.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,7 @@ static void tx_complete (struct urb *urb)
11881188
struct usbnet *dev = entry->dev;
11891189

11901190
if (urb->status == 0) {
1191-
if (!(dev->driver_info->flags & FLAG_MULTI_PACKET))
1192-
dev->net->stats.tx_packets++;
1191+
dev->net->stats.tx_packets += entry->packets;
11931192
dev->net->stats.tx_bytes += entry->length;
11941193
} else {
11951194
dev->net->stats.tx_errors++;
@@ -1348,6 +1347,8 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
13481347
urb->transfer_flags |= URB_ZERO_PACKET;
13491348
}
13501349
entry->length = urb->transfer_buffer_length = length;
1350+
if (!(info->flags & FLAG_MULTI_PACKET))
1351+
usbnet_set_skb_tx_stats(skb, 1);
13511352

13521353
spin_lock_irqsave(&dev->txq.lock, flags);
13531354
retval = usb_autopm_get_interface_async(dev->intf);

include/linux/usb/usbnet.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,20 @@ struct skb_data { /* skb->cb is one of these */
228228
struct usbnet *dev;
229229
enum skb_state state;
230230
size_t length;
231+
unsigned long packets;
231232
};
232233

234+
/* Drivers that set FLAG_MULTI_PACKET must call this in their
235+
* tx_fixup method before returning an skb.
236+
*/
237+
static inline void
238+
usbnet_set_skb_tx_stats(struct sk_buff *skb, unsigned long packets)
239+
{
240+
struct skb_data *entry = (struct skb_data *) skb->cb;
241+
242+
entry->packets = packets;
243+
}
244+
233245
extern int usbnet_open(struct net_device *net);
234246
extern int usbnet_stop(struct net_device *net);
235247
extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,

0 commit comments

Comments
 (0)