Skip to content

Commit 09f75cd

Browse files
Jeff GarzikDavid S. Miller
authored andcommitted
[NET] drivers/net: statistics cleanup raspberrypi#1 -- save memory and shrink code
We now have struct net_device_stats embedded in struct net_device, and the default ->get_stats() hook does the obvious thing for us. Run through drivers/net/* and remove the driver-local storage of statistics, and driver-local ->get_stats() hook where applicable. This was just the low-hanging fruit in drivers/net; plenty more drivers remain to be updated. [ Resolved conflicts with napi_struct changes and fix sunqe build regression... -DaveM ] Signed-off-by: Jeff Garzik <jeff@garzik.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ff8ac60 commit 09f75cd

83 files changed

Lines changed: 948 additions & 1763 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎drivers/net/3c501.c‎

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr)
315315
dev->tx_timeout = &el_timeout;
316316
dev->watchdog_timeo = HZ;
317317
dev->stop = &el1_close;
318-
dev->get_stats = &el1_get_stats;
319318
dev->set_multicast_list = &set_multicast_list;
320319
dev->ethtool_ops = &netdev_ethtool_ops;
321320
return 0;
@@ -374,7 +373,7 @@ static void el_timeout(struct net_device *dev)
374373
if (el_debug)
375374
printk (KERN_DEBUG "%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n",
376375
dev->name, inb(TX_STATUS), inb(AX_STATUS), inb(RX_STATUS));
377-
lp->stats.tx_errors++;
376+
dev->stats.tx_errors++;
378377
outb(TX_NORM, TX_CMD);
379378
outb(RX_NORM, RX_CMD);
380379
outb(AX_OFF, AX_CMD); /* Just trigger a false interrupt. */
@@ -441,7 +440,7 @@ static int el_start_xmit(struct sk_buff *skb, struct net_device *dev)
441440
lp->tx_pkt_start = gp_start;
442441
lp->collisions = 0;
443442

444-
lp->stats.tx_bytes += skb->len;
443+
dev->stats.tx_bytes += skb->len;
445444

446445
/*
447446
* Command mode with status cleared should [in theory]
@@ -588,7 +587,7 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
588587
printk (KERN_DEBUG "%s: Transmit failed 16 times, Ethernet jammed?\n",dev->name);
589588
outb(AX_SYS, AX_CMD);
590589
lp->txing = 0;
591-
lp->stats.tx_aborted_errors++;
590+
dev->stats.tx_aborted_errors++;
592591
netif_wake_queue(dev);
593592
}
594593
else if (txsr & TX_COLLISION)
@@ -606,7 +605,7 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
606605
outb(AX_SYS, AX_CMD);
607606
outw(lp->tx_pkt_start, GP_LOW);
608607
outb(AX_XMIT, AX_CMD);
609-
lp->stats.collisions++;
608+
dev->stats.collisions++;
610609
spin_unlock(&lp->lock);
611610
goto out;
612611
}
@@ -615,7 +614,7 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
615614
/*
616615
* It worked.. we will now fall through and receive
617616
*/
618-
lp->stats.tx_packets++;
617+
dev->stats.tx_packets++;
619618
if (el_debug > 6)
620619
printk(KERN_DEBUG " Tx succeeded %s\n",
621620
(txsr & TX_RDY) ? "." : "but tx is busy!");
@@ -640,10 +639,10 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
640639
* Just reading rx_status fixes most errors.
641640
*/
642641
if (rxsr & RX_MISSED)
643-
lp->stats.rx_missed_errors++;
642+
dev->stats.rx_missed_errors++;
644643
else if (rxsr & RX_RUNT)
645644
{ /* Handled to avoid board lock-up. */
646-
lp->stats.rx_length_errors++;
645+
dev->stats.rx_length_errors++;
647646
if (el_debug > 5)
648647
printk(KERN_DEBUG " runt.\n");
649648
}
@@ -694,7 +693,6 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
694693

695694
static void el_receive(struct net_device *dev)
696695
{
697-
struct net_local *lp = netdev_priv(dev);
698696
int ioaddr = dev->base_addr;
699697
int pkt_len;
700698
struct sk_buff *skb;
@@ -708,7 +706,7 @@ static void el_receive(struct net_device *dev)
708706
{
709707
if (el_debug)
710708
printk(KERN_DEBUG "%s: bogus packet, length=%d\n", dev->name, pkt_len);
711-
lp->stats.rx_over_errors++;
709+
dev->stats.rx_over_errors++;
712710
return;
713711
}
714712

@@ -727,7 +725,7 @@ static void el_receive(struct net_device *dev)
727725
if (skb == NULL)
728726
{
729727
printk(KERN_INFO "%s: Memory squeeze, dropping packet.\n", dev->name);
730-
lp->stats.rx_dropped++;
728+
dev->stats.rx_dropped++;
731729
return;
732730
}
733731
else
@@ -742,8 +740,8 @@ static void el_receive(struct net_device *dev)
742740
skb->protocol=eth_type_trans(skb,dev);
743741
netif_rx(skb);
744742
dev->last_rx = jiffies;
745-
lp->stats.rx_packets++;
746-
lp->stats.rx_bytes+=pkt_len;
743+
dev->stats.rx_packets++;
744+
dev->stats.rx_bytes+=pkt_len;
747745
}
748746
return;
749747
}
@@ -810,23 +808,6 @@ static int el1_close(struct net_device *dev)
810808
return 0;
811809
}
812810

813-
/**
814-
* el1_get_stats:
815-
* @dev: The card to get the statistics for
816-
*
817-
* In smarter devices this function is needed to pull statistics off the
818-
* board itself. The 3c501 has no hardware statistics. We maintain them all
819-
* so they are by definition always up to date.
820-
*
821-
* Returns the statistics for the card from the card private data
822-
*/
823-
824-
static struct net_device_stats *el1_get_stats(struct net_device *dev)
825-
{
826-
struct net_local *lp = netdev_priv(dev);
827-
return &lp->stats;
828-
}
829-
830811
/**
831812
* set_multicast_list:
832813
* @dev: The device to adjust

‎drivers/net/3c501.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ static irqreturn_t el_interrupt(int irq, void *dev_id);
1111
static void el_receive(struct net_device *dev);
1212
static void el_reset(struct net_device *dev);
1313
static int el1_close(struct net_device *dev);
14-
static struct net_device_stats *el1_get_stats(struct net_device *dev);
1514
static void set_multicast_list(struct net_device *dev);
1615
static const struct ethtool_ops netdev_ethtool_ops;
1716

@@ -29,7 +28,6 @@ static int el_debug = EL_DEBUG;
2928

3029
struct net_local
3130
{
32-
struct net_device_stats stats;
3331
int tx_pkt_start; /* The length of the current Tx packet. */
3432
int collisions; /* Tx collisions this packet */
3533
int loading; /* Spot buffer load collisions */

‎drivers/net/3c507.c‎

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ enum commands {
118118

119119
/* Information that need to be kept for each board. */
120120
struct net_local {
121-
struct net_device_stats stats;
122121
int last_restart;
123122
ushort rx_head;
124123
ushort rx_tail;
@@ -289,7 +288,6 @@ static int el16_send_packet(struct sk_buff *skb, struct net_device *dev);
289288
static irqreturn_t el16_interrupt(int irq, void *dev_id);
290289
static void el16_rx(struct net_device *dev);
291290
static int el16_close(struct net_device *dev);
292-
static struct net_device_stats *el16_get_stats(struct net_device *dev);
293291
static void el16_tx_timeout (struct net_device *dev);
294292

295293
static void hardware_send_packet(struct net_device *dev, void *buf, short length, short pad);
@@ -455,7 +453,6 @@ static int __init el16_probe1(struct net_device *dev, int ioaddr)
455453
dev->open = el16_open;
456454
dev->stop = el16_close;
457455
dev->hard_start_xmit = el16_send_packet;
458-
dev->get_stats = el16_get_stats;
459456
dev->tx_timeout = el16_tx_timeout;
460457
dev->watchdog_timeo = TX_TIMEOUT;
461458
dev->ethtool_ops = &netdev_ethtool_ops;
@@ -489,7 +486,7 @@ static void el16_tx_timeout (struct net_device *dev)
489486
readw(shmem + iSCB_STATUS) & 0x8000 ? "IRQ conflict" :
490487
"network cable problem");
491488
/* Try to restart the adaptor. */
492-
if (lp->last_restart == lp->stats.tx_packets) {
489+
if (lp->last_restart == dev->stats.tx_packets) {
493490
if (net_debug > 1)
494491
printk ("Resetting board.\n");
495492
/* Completely reset the adaptor. */
@@ -501,7 +498,7 @@ static void el16_tx_timeout (struct net_device *dev)
501498
printk ("Kicking board.\n");
502499
writew(0xf000 | CUC_START | RX_START, shmem + iSCB_CMD);
503500
outb (0, ioaddr + SIGNAL_CA); /* Issue channel-attn. */
504-
lp->last_restart = lp->stats.tx_packets;
501+
lp->last_restart = dev->stats.tx_packets;
505502
}
506503
dev->trans_start = jiffies;
507504
netif_wake_queue (dev);
@@ -520,7 +517,7 @@ static int el16_send_packet (struct sk_buff *skb, struct net_device *dev)
520517

521518
spin_lock_irqsave (&lp->lock, flags);
522519

523-
lp->stats.tx_bytes += length;
520+
dev->stats.tx_bytes += length;
524521
/* Disable the 82586's input to the interrupt line. */
525522
outb (0x80, ioaddr + MISC_CTRL);
526523

@@ -579,14 +576,14 @@ static irqreturn_t el16_interrupt(int irq, void *dev_id)
579576
}
580577
/* Tx unsuccessful or some interesting status bit set. */
581578
if (!(tx_status & 0x2000) || (tx_status & 0x0f3f)) {
582-
lp->stats.tx_errors++;
583-
if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
584-
if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
585-
if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
586-
if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
587-
lp->stats.collisions += tx_status & 0xf;
579+
dev->stats.tx_errors++;
580+
if (tx_status & 0x0600) dev->stats.tx_carrier_errors++;
581+
if (tx_status & 0x0100) dev->stats.tx_fifo_errors++;
582+
if (!(tx_status & 0x0040)) dev->stats.tx_heartbeat_errors++;
583+
if (tx_status & 0x0020) dev->stats.tx_aborted_errors++;
584+
dev->stats.collisions += tx_status & 0xf;
588585
}
589-
lp->stats.tx_packets++;
586+
dev->stats.tx_packets++;
590587
if (net_debug > 5)
591588
printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
592589
lp->tx_reap += TX_BUF_SIZE;
@@ -665,17 +662,6 @@ static int el16_close(struct net_device *dev)
665662
return 0;
666663
}
667664

668-
/* Get the current statistics. This may be called with the card open or
669-
closed. */
670-
static struct net_device_stats *el16_get_stats(struct net_device *dev)
671-
{
672-
struct net_local *lp = netdev_priv(dev);
673-
674-
/* ToDo: decide if there are any useful statistics from the SCB. */
675-
676-
return &lp->stats;
677-
}
678-
679665
/* Initialize the Rx-block list. */
680666
static void init_rx_bufs(struct net_device *dev)
681667
{
@@ -852,12 +838,12 @@ static void el16_rx(struct net_device *dev)
852838
pkt_len);
853839
} else if ((frame_status & 0x2000) == 0) {
854840
/* Frame Rxed, but with error. */
855-
lp->stats.rx_errors++;
856-
if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
857-
if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
858-
if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
859-
if (frame_status & 0x0100) lp->stats.rx_over_errors++;
860-
if (frame_status & 0x0080) lp->stats.rx_length_errors++;
841+
dev->stats.rx_errors++;
842+
if (frame_status & 0x0800) dev->stats.rx_crc_errors++;
843+
if (frame_status & 0x0400) dev->stats.rx_frame_errors++;
844+
if (frame_status & 0x0200) dev->stats.rx_fifo_errors++;
845+
if (frame_status & 0x0100) dev->stats.rx_over_errors++;
846+
if (frame_status & 0x0080) dev->stats.rx_length_errors++;
861847
} else {
862848
/* Malloc up new buffer. */
863849
struct sk_buff *skb;
@@ -866,7 +852,7 @@ static void el16_rx(struct net_device *dev)
866852
skb = dev_alloc_skb(pkt_len+2);
867853
if (skb == NULL) {
868854
printk("%s: Memory squeeze, dropping packet.\n", dev->name);
869-
lp->stats.rx_dropped++;
855+
dev->stats.rx_dropped++;
870856
break;
871857
}
872858

@@ -878,8 +864,8 @@ static void el16_rx(struct net_device *dev)
878864
skb->protocol=eth_type_trans(skb,dev);
879865
netif_rx(skb);
880866
dev->last_rx = jiffies;
881-
lp->stats.rx_packets++;
882-
lp->stats.rx_bytes += pkt_len;
867+
dev->stats.rx_packets++;
868+
dev->stats.rx_bytes += pkt_len;
883869
}
884870

885871
/* Clear the status word and set End-of-List on the rx frame. */

‎drivers/net/7990.c‎

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -305,26 +305,26 @@ static int lance_rx (struct net_device *dev)
305305

306306
/* We got an incomplete frame? */
307307
if ((bits & LE_R1_POK) != LE_R1_POK) {
308-
lp->stats.rx_over_errors++;
309-
lp->stats.rx_errors++;
308+
dev->stats.rx_over_errors++;
309+
dev->stats.rx_errors++;
310310
continue;
311311
} else if (bits & LE_R1_ERR) {
312312
/* Count only the end frame as a rx error,
313313
* not the beginning
314314
*/
315-
if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
316-
if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
317-
if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
318-
if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
319-
if (bits & LE_R1_EOP) lp->stats.rx_errors++;
315+
if (bits & LE_R1_BUF) dev->stats.rx_fifo_errors++;
316+
if (bits & LE_R1_CRC) dev->stats.rx_crc_errors++;
317+
if (bits & LE_R1_OFL) dev->stats.rx_over_errors++;
318+
if (bits & LE_R1_FRA) dev->stats.rx_frame_errors++;
319+
if (bits & LE_R1_EOP) dev->stats.rx_errors++;
320320
} else {
321321
len = (rd->mblength & 0xfff) - 4;
322322
skb = dev_alloc_skb (len+2);
323323

324324
if (skb == 0) {
325325
printk ("%s: Memory squeeze, deferring packet.\n",
326326
dev->name);
327-
lp->stats.rx_dropped++;
327+
dev->stats.rx_dropped++;
328328
rd->mblength = 0;
329329
rd->rmd1_bits = LE_R1_OWN;
330330
lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
@@ -339,8 +339,8 @@ static int lance_rx (struct net_device *dev)
339339
skb->protocol = eth_type_trans (skb, dev);
340340
netif_rx (skb);
341341
dev->last_rx = jiffies;
342-
lp->stats.rx_packets++;
343-
lp->stats.rx_bytes += len;
342+
dev->stats.rx_packets++;
343+
dev->stats.rx_bytes += len;
344344
}
345345

346346
/* Return the packet to the pool */
@@ -377,12 +377,12 @@ static int lance_tx (struct net_device *dev)
377377
if (td->tmd1_bits & LE_T1_ERR) {
378378
status = td->misc;
379379

380-
lp->stats.tx_errors++;
381-
if (status & LE_T3_RTY) lp->stats.tx_aborted_errors++;
382-
if (status & LE_T3_LCOL) lp->stats.tx_window_errors++;
380+
dev->stats.tx_errors++;
381+
if (status & LE_T3_RTY) dev->stats.tx_aborted_errors++;
382+
if (status & LE_T3_LCOL) dev->stats.tx_window_errors++;
383383

384384
if (status & LE_T3_CLOS) {
385-
lp->stats.tx_carrier_errors++;
385+
dev->stats.tx_carrier_errors++;
386386
if (lp->auto_select) {
387387
lp->tpe = 1 - lp->tpe;
388388
printk("%s: Carrier Lost, trying %s\n",
@@ -400,7 +400,7 @@ static int lance_tx (struct net_device *dev)
400400
/* buffer errors and underflows turn off the transmitter */
401401
/* Restart the adapter */
402402
if (status & (LE_T3_BUF|LE_T3_UFL)) {
403-
lp->stats.tx_fifo_errors++;
403+
dev->stats.tx_fifo_errors++;
404404

405405
printk ("%s: Tx: ERR_BUF|ERR_UFL, restarting\n",
406406
dev->name);
@@ -420,13 +420,13 @@ static int lance_tx (struct net_device *dev)
420420

421421
/* One collision before packet was sent. */
422422
if (td->tmd1_bits & LE_T1_EONE)
423-
lp->stats.collisions++;
423+
dev->stats.collisions++;
424424

425425
/* More than one collision, be optimistic. */
426426
if (td->tmd1_bits & LE_T1_EMORE)
427-
lp->stats.collisions += 2;
427+
dev->stats.collisions += 2;
428428

429-
lp->stats.tx_packets++;
429+
dev->stats.tx_packets++;
430430
}
431431

432432
j = (j + 1) & lp->tx_ring_mod_mask;
@@ -471,9 +471,9 @@ lance_interrupt (int irq, void *dev_id)
471471

472472
/* Log misc errors. */
473473
if (csr0 & LE_C0_BABL)
474-
lp->stats.tx_errors++; /* Tx babble. */
474+
dev->stats.tx_errors++; /* Tx babble. */
475475
if (csr0 & LE_C0_MISS)
476-
lp->stats.rx_errors++; /* Missed a Rx frame. */
476+
dev->stats.rx_errors++; /* Missed a Rx frame. */
477477
if (csr0 & LE_C0_MERR) {
478478
printk("%s: Bus master arbitration failure, status %4.4x.\n",
479479
dev->name, csr0);
@@ -589,13 +589,6 @@ int lance_start_xmit (struct sk_buff *skb, struct net_device *dev)
589589
return 0;
590590
}
591591

592-
struct net_device_stats *lance_get_stats (struct net_device *dev)
593-
{
594-
struct lance_private *lp = netdev_priv(dev);
595-
596-
return &lp->stats;
597-
}
598-
599592
/* taken from the depca driver via a2065.c */
600593
static void lance_load_multicast (struct net_device *dev)
601594
{

0 commit comments

Comments
 (0)