Statistical Information

The last method a driver needs is get_stats. This method returns a pointer to the statistics for the device. Its implementation is pretty easy:

struct enet_statistics *snull_stats(struct device *dev)
{
    struct snull_priv *priv = (struct snull_priv *)dev->priv;
    return &priv->stats;
}

The real work needed to return meaningful statistics is distributed throughout the driver, where the various fields are updated. The following list shows the most interesting fields in struct enet_statistics.

int rx_packets; , int tx_packets;

These fields hold the total number of incoming and outgoing packets successfully transferred by the interface.

int rx_errors; , int tx_errors;

The number of erroneous receptions and transmissions. Receive errors can be the result of bad checksums, wrong packet sizes, or other problems. Transmit errors are less common and are due mainly to cable problems.

int rx_dropped; , int tx_dropped;

The number of packets dropped during reception and transmission. Packets are dropped when there’s no memory available for packet data. tx_dropped is rarely used.

The structure has several more fields, which can be used to detail the kind of errors that happened during transmission or reception. The interested reader is urged to look at the structure’s definition in <linux/if_ether.h>.

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.