Skip to content

Commit

Permalink
[NET] drivers/net: statistics cleanup #1 -- save memory and shrink code
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jeff Garzik authored and David S. Miller committed Oct 10, 2007
1 parent ff8ac60 commit 09f75cd
Show file tree
Hide file tree
Showing 83 changed files with 948 additions and 1,763 deletions.
41 changes: 11 additions & 30 deletions drivers/net/3c501.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ static int __init el1_probe1(struct net_device *dev, int ioaddr)
dev->tx_timeout = &el_timeout;
dev->watchdog_timeo = HZ;
dev->stop = &el1_close;
dev->get_stats = &el1_get_stats;
dev->set_multicast_list = &set_multicast_list;
dev->ethtool_ops = &netdev_ethtool_ops;
return 0;
Expand Down Expand Up @@ -374,7 +373,7 @@ static void el_timeout(struct net_device *dev)
if (el_debug)
printk (KERN_DEBUG "%s: transmit timed out, txsr %#2x axsr=%02x rxsr=%02x.\n",
dev->name, inb(TX_STATUS), inb(AX_STATUS), inb(RX_STATUS));
lp->stats.tx_errors++;
dev->stats.tx_errors++;
outb(TX_NORM, TX_CMD);
outb(RX_NORM, RX_CMD);
outb(AX_OFF, AX_CMD); /* Just trigger a false interrupt. */
Expand Down Expand Up @@ -441,7 +440,7 @@ static int el_start_xmit(struct sk_buff *skb, struct net_device *dev)
lp->tx_pkt_start = gp_start;
lp->collisions = 0;

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

/*
* Command mode with status cleared should [in theory]
Expand Down Expand Up @@ -588,7 +587,7 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
printk (KERN_DEBUG "%s: Transmit failed 16 times, Ethernet jammed?\n",dev->name);
outb(AX_SYS, AX_CMD);
lp->txing = 0;
lp->stats.tx_aborted_errors++;
dev->stats.tx_aborted_errors++;
netif_wake_queue(dev);
}
else if (txsr & TX_COLLISION)
Expand All @@ -606,7 +605,7 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
outb(AX_SYS, AX_CMD);
outw(lp->tx_pkt_start, GP_LOW);
outb(AX_XMIT, AX_CMD);
lp->stats.collisions++;
dev->stats.collisions++;
spin_unlock(&lp->lock);
goto out;
}
Expand All @@ -615,7 +614,7 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
/*
* It worked.. we will now fall through and receive
*/
lp->stats.tx_packets++;
dev->stats.tx_packets++;
if (el_debug > 6)
printk(KERN_DEBUG " Tx succeeded %s\n",
(txsr & TX_RDY) ? "." : "but tx is busy!");
Expand All @@ -640,10 +639,10 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)
* Just reading rx_status fixes most errors.
*/
if (rxsr & RX_MISSED)
lp->stats.rx_missed_errors++;
dev->stats.rx_missed_errors++;
else if (rxsr & RX_RUNT)
{ /* Handled to avoid board lock-up. */
lp->stats.rx_length_errors++;
dev->stats.rx_length_errors++;
if (el_debug > 5)
printk(KERN_DEBUG " runt.\n");
}
Expand Down Expand Up @@ -694,7 +693,6 @@ static irqreturn_t el_interrupt(int irq, void *dev_id)

static void el_receive(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
int ioaddr = dev->base_addr;
int pkt_len;
struct sk_buff *skb;
Expand All @@ -708,7 +706,7 @@ static void el_receive(struct net_device *dev)
{
if (el_debug)
printk(KERN_DEBUG "%s: bogus packet, length=%d\n", dev->name, pkt_len);
lp->stats.rx_over_errors++;
dev->stats.rx_over_errors++;
return;
}

Expand All @@ -727,7 +725,7 @@ static void el_receive(struct net_device *dev)
if (skb == NULL)
{
printk(KERN_INFO "%s: Memory squeeze, dropping packet.\n", dev->name);
lp->stats.rx_dropped++;
dev->stats.rx_dropped++;
return;
}
else
Expand All @@ -742,8 +740,8 @@ static void el_receive(struct net_device *dev)
skb->protocol=eth_type_trans(skb,dev);
netif_rx(skb);
dev->last_rx = jiffies;
lp->stats.rx_packets++;
lp->stats.rx_bytes+=pkt_len;
dev->stats.rx_packets++;
dev->stats.rx_bytes+=pkt_len;
}
return;
}
Expand Down Expand Up @@ -810,23 +808,6 @@ static int el1_close(struct net_device *dev)
return 0;
}

/**
* el1_get_stats:
* @dev: The card to get the statistics for
*
* In smarter devices this function is needed to pull statistics off the
* board itself. The 3c501 has no hardware statistics. We maintain them all
* so they are by definition always up to date.
*
* Returns the statistics for the card from the card private data
*/

static struct net_device_stats *el1_get_stats(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);
return &lp->stats;
}

/**
* set_multicast_list:
* @dev: The device to adjust
Expand Down
2 changes: 0 additions & 2 deletions drivers/net/3c501.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ static irqreturn_t el_interrupt(int irq, void *dev_id);
static void el_receive(struct net_device *dev);
static void el_reset(struct net_device *dev);
static int el1_close(struct net_device *dev);
static struct net_device_stats *el1_get_stats(struct net_device *dev);
static void set_multicast_list(struct net_device *dev);
static const struct ethtool_ops netdev_ethtool_ops;

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

struct net_local
{
struct net_device_stats stats;
int tx_pkt_start; /* The length of the current Tx packet. */
int collisions; /* Tx collisions this packet */
int loading; /* Spot buffer load collisions */
Expand Down
52 changes: 19 additions & 33 deletions drivers/net/3c507.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ enum commands {

/* Information that need to be kept for each board. */
struct net_local {
struct net_device_stats stats;
int last_restart;
ushort rx_head;
ushort rx_tail;
Expand Down Expand Up @@ -289,7 +288,6 @@ static int el16_send_packet(struct sk_buff *skb, struct net_device *dev);
static irqreturn_t el16_interrupt(int irq, void *dev_id);
static void el16_rx(struct net_device *dev);
static int el16_close(struct net_device *dev);
static struct net_device_stats *el16_get_stats(struct net_device *dev);
static void el16_tx_timeout (struct net_device *dev);

static void hardware_send_packet(struct net_device *dev, void *buf, short length, short pad);
Expand Down Expand Up @@ -455,7 +453,6 @@ static int __init el16_probe1(struct net_device *dev, int ioaddr)
dev->open = el16_open;
dev->stop = el16_close;
dev->hard_start_xmit = el16_send_packet;
dev->get_stats = el16_get_stats;
dev->tx_timeout = el16_tx_timeout;
dev->watchdog_timeo = TX_TIMEOUT;
dev->ethtool_ops = &netdev_ethtool_ops;
Expand Down Expand Up @@ -489,7 +486,7 @@ static void el16_tx_timeout (struct net_device *dev)
readw(shmem + iSCB_STATUS) & 0x8000 ? "IRQ conflict" :
"network cable problem");
/* Try to restart the adaptor. */
if (lp->last_restart == lp->stats.tx_packets) {
if (lp->last_restart == dev->stats.tx_packets) {
if (net_debug > 1)
printk ("Resetting board.\n");
/* Completely reset the adaptor. */
Expand All @@ -501,7 +498,7 @@ static void el16_tx_timeout (struct net_device *dev)
printk ("Kicking board.\n");
writew(0xf000 | CUC_START | RX_START, shmem + iSCB_CMD);
outb (0, ioaddr + SIGNAL_CA); /* Issue channel-attn. */
lp->last_restart = lp->stats.tx_packets;
lp->last_restart = dev->stats.tx_packets;
}
dev->trans_start = jiffies;
netif_wake_queue (dev);
Expand All @@ -520,7 +517,7 @@ static int el16_send_packet (struct sk_buff *skb, struct net_device *dev)

spin_lock_irqsave (&lp->lock, flags);

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

Expand Down Expand Up @@ -579,14 +576,14 @@ static irqreturn_t el16_interrupt(int irq, void *dev_id)
}
/* Tx unsuccessful or some interesting status bit set. */
if (!(tx_status & 0x2000) || (tx_status & 0x0f3f)) {
lp->stats.tx_errors++;
if (tx_status & 0x0600) lp->stats.tx_carrier_errors++;
if (tx_status & 0x0100) lp->stats.tx_fifo_errors++;
if (!(tx_status & 0x0040)) lp->stats.tx_heartbeat_errors++;
if (tx_status & 0x0020) lp->stats.tx_aborted_errors++;
lp->stats.collisions += tx_status & 0xf;
dev->stats.tx_errors++;
if (tx_status & 0x0600) dev->stats.tx_carrier_errors++;
if (tx_status & 0x0100) dev->stats.tx_fifo_errors++;
if (!(tx_status & 0x0040)) dev->stats.tx_heartbeat_errors++;
if (tx_status & 0x0020) dev->stats.tx_aborted_errors++;
dev->stats.collisions += tx_status & 0xf;
}
lp->stats.tx_packets++;
dev->stats.tx_packets++;
if (net_debug > 5)
printk("Reaped %x, Tx status %04x.\n" , lp->tx_reap, tx_status);
lp->tx_reap += TX_BUF_SIZE;
Expand Down Expand Up @@ -665,17 +662,6 @@ static int el16_close(struct net_device *dev)
return 0;
}

/* Get the current statistics. This may be called with the card open or
closed. */
static struct net_device_stats *el16_get_stats(struct net_device *dev)
{
struct net_local *lp = netdev_priv(dev);

/* ToDo: decide if there are any useful statistics from the SCB. */

return &lp->stats;
}

/* Initialize the Rx-block list. */
static void init_rx_bufs(struct net_device *dev)
{
Expand Down Expand Up @@ -852,12 +838,12 @@ static void el16_rx(struct net_device *dev)
pkt_len);
} else if ((frame_status & 0x2000) == 0) {
/* Frame Rxed, but with error. */
lp->stats.rx_errors++;
if (frame_status & 0x0800) lp->stats.rx_crc_errors++;
if (frame_status & 0x0400) lp->stats.rx_frame_errors++;
if (frame_status & 0x0200) lp->stats.rx_fifo_errors++;
if (frame_status & 0x0100) lp->stats.rx_over_errors++;
if (frame_status & 0x0080) lp->stats.rx_length_errors++;
dev->stats.rx_errors++;
if (frame_status & 0x0800) dev->stats.rx_crc_errors++;
if (frame_status & 0x0400) dev->stats.rx_frame_errors++;
if (frame_status & 0x0200) dev->stats.rx_fifo_errors++;
if (frame_status & 0x0100) dev->stats.rx_over_errors++;
if (frame_status & 0x0080) dev->stats.rx_length_errors++;
} else {
/* Malloc up new buffer. */
struct sk_buff *skb;
Expand All @@ -866,7 +852,7 @@ static void el16_rx(struct net_device *dev)
skb = dev_alloc_skb(pkt_len+2);
if (skb == NULL) {
printk("%s: Memory squeeze, dropping packet.\n", dev->name);
lp->stats.rx_dropped++;
dev->stats.rx_dropped++;
break;
}

Expand All @@ -878,8 +864,8 @@ static void el16_rx(struct net_device *dev)
skb->protocol=eth_type_trans(skb,dev);
netif_rx(skb);
dev->last_rx = jiffies;
lp->stats.rx_packets++;
lp->stats.rx_bytes += pkt_len;
dev->stats.rx_packets++;
dev->stats.rx_bytes += pkt_len;
}

/* Clear the status word and set End-of-List on the rx frame. */
Expand Down
47 changes: 20 additions & 27 deletions drivers/net/7990.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,26 @@ static int lance_rx (struct net_device *dev)

/* We got an incomplete frame? */
if ((bits & LE_R1_POK) != LE_R1_POK) {
lp->stats.rx_over_errors++;
lp->stats.rx_errors++;
dev->stats.rx_over_errors++;
dev->stats.rx_errors++;
continue;
} else if (bits & LE_R1_ERR) {
/* Count only the end frame as a rx error,
* not the beginning
*/
if (bits & LE_R1_BUF) lp->stats.rx_fifo_errors++;
if (bits & LE_R1_CRC) lp->stats.rx_crc_errors++;
if (bits & LE_R1_OFL) lp->stats.rx_over_errors++;
if (bits & LE_R1_FRA) lp->stats.rx_frame_errors++;
if (bits & LE_R1_EOP) lp->stats.rx_errors++;
if (bits & LE_R1_BUF) dev->stats.rx_fifo_errors++;
if (bits & LE_R1_CRC) dev->stats.rx_crc_errors++;
if (bits & LE_R1_OFL) dev->stats.rx_over_errors++;
if (bits & LE_R1_FRA) dev->stats.rx_frame_errors++;
if (bits & LE_R1_EOP) dev->stats.rx_errors++;
} else {
len = (rd->mblength & 0xfff) - 4;
skb = dev_alloc_skb (len+2);

if (skb == 0) {
printk ("%s: Memory squeeze, deferring packet.\n",
dev->name);
lp->stats.rx_dropped++;
dev->stats.rx_dropped++;
rd->mblength = 0;
rd->rmd1_bits = LE_R1_OWN;
lp->rx_new = (lp->rx_new + 1) & lp->rx_ring_mod_mask;
Expand All @@ -339,8 +339,8 @@ static int lance_rx (struct net_device *dev)
skb->protocol = eth_type_trans (skb, dev);
netif_rx (skb);
dev->last_rx = jiffies;
lp->stats.rx_packets++;
lp->stats.rx_bytes += len;
dev->stats.rx_packets++;
dev->stats.rx_bytes += len;
}

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

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

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

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

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

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

lp->stats.tx_packets++;
dev->stats.tx_packets++;
}

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

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

struct net_device_stats *lance_get_stats (struct net_device *dev)
{
struct lance_private *lp = netdev_priv(dev);

return &lp->stats;
}

/* taken from the depca driver via a2065.c */
static void lance_load_multicast (struct net_device *dev)
{
Expand Down
Loading

0 comments on commit 09f75cd

Please sign in to comment.