include/nuttx/net/netdev.h and several Ethernet drivers in arch/: Most network drivers to not support statistics. Those that do only support them when DEBUG is enabled. Each driver collects an architecture specific set of statistics and there is no mechanism in place to view those statistics. Thus, the driver feature was mostly useless. This change standardizes the driver statistics and puts the definition in the common network device structure defined in netdev.h where they can be accessed by network applications. All Ethernet drivers that collect statistics have been adapted to use these common statistics.

This commit is contained in:
Gregory Nutt
2015-11-26 12:08:09 -06:00
parent 470784d8ca
commit 2a93c66948
22 changed files with 278 additions and 548 deletions
+1 -30
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/net/cs89x0.h
*
* Copyright (C) 2009, 2012, 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2012, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -49,29 +49,6 @@
* Public Types
****************************************************************************/
/* This structure returns driver statistics (if enabled) */
#ifdef CONFIG_C89x0_STATISTICS
struct cs89x0_statistics_s
{
uint32_t tx_packets;
uint32_t tx_errors;
uint32_t tx_carriererrors;
uint32_t tx_heartbeaterrors;
uint32_t tx_windowerrors;
uint32_t tx_abortederrors;
uint32_t rx_missederrors;
uint32_t rx_packets;
uint32_t rx_errors;
uint32_t rx_lengtherrors;
uint32_t rx_crcerrors;
uint32_t rx_frameerrors;
uint32_t rx_dropped;
uint32_t rx_missederrors;
uint32_t collisions;
};
#endif
/* This structure encapsulates all state information for a single hardware
* interface. It includes values that must be provided by the user to in
* to describe details of the CS89x00 implementation on a particular board.
@@ -112,12 +89,6 @@ struct cs89x0_driver_s
/* This holds the information visible to uIP/NuttX */
struct net_driver_s cs_dev; /* Interface understood by uIP */
/* Driver statistics */
#ifdef CONFIG_C89x0_STATISTICS
struct cs89x0_statistics_s cs_stats;
#endif
};
/****************************************************************************
+1 -43
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/net/enc28j60.h
*
* Copyright (C) 2010, 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2010, 2012, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,6 @@
* CONFIG_ENC28J60_FREQUENCY - Define to use a different bus frequency
* CONFIG_ENC28J60_NINTERFACES - Specifies the number of physical ENC28J60
* devices that will be supported.
* CONFIG_ENC28J60_STATS - Collect network statistics
* CONFIG_ENC28J60_HALFDUPPLEX - Default is full duplex
*/
@@ -64,24 +63,6 @@
* Public Types
****************************************************************************/
/* This structure returns driver statistics (if enabled) */
#ifdef CONFIG_ENC28J60_STATS
struct enc_stats_s
{
uint8_t maxpktcnt; /* Max. number of buffered RX packets */
uint32_t txrequests; /* Number of TX packets queued */
uint32_t txifs; /* TXIF completion events */
uint32_t txabrts; /* TXIF completions with ESTAT.TXABRT */
uint32_t txerifs; /* TXERIF error events */
uint32_t txtimeouts; /* S/W detected TX timeouts */
uint32_t pktifs; /* PKTIF RX completion events */
uint32_t rxnotok; /* PKTIF without RXSTAT_OK */
uint32_t rxpktlen; /* PKTIF with bad pktlen */
uint32_t rxerifs; /* RXERIF error evernts */
};
#endif
/* The ENC28J60 normal provides interrupts to the MCU via a GPIO pin. The
* following structure provides an MCU-independent mechanixm for controlling
* the ENC28J60 GPIO interrupt.
@@ -151,29 +132,6 @@ struct spi_dev_s; /* see nuttx/spi/spi.h */
int enc_initialize(FAR struct spi_dev_s *spi,
FAR const struct enc_lower_s *lower, unsigned int devno);
/****************************************************************************
* Function: enc_stats
*
* Description:
* Return accumulated ENC28J60 statistics. Statistics are cleared after
* being returned.
*
* Parameters:
* devno - If more than one ENC28J60 is supported, then this is the
* zero based number that identifies the ENC28J60;
* stats - The user-provided location to return the statistics.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/
#ifdef CONFIG_ENC28J60_STATS
int enc_stats(unsigned int devno, struct enc_stats_s *stats);
#endif
#undef EXTERN
#ifdef __cplusplus
}
+1 -44
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/net/encx24j600.h
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,6 @@
* CONFIG_ENCX24J600_FREQUENCY - Define to use a different bus frequency
* CONFIG_ENCX24J600_NINTERFACES - Specifies the number of physical ENCX24J600
* devices that will be supported.
* CONFIG_ENCX24J600_STATS - Collect network statistics
* CONFIG_ENCX24J600_HALFDUPPLEX - Default is full duplex
*/
@@ -64,24 +63,6 @@
* Public Types
****************************************************************************/
/* This structure returns driver statistics (if enabled) */
#ifdef CONFIG_ENCX24J600_STATS
struct enc_stats_s
{
uint8_t maxpktcnt; /* Max. number of buffered RX packets */
uint32_t txrequests; /* Number of TX packets queued */
uint32_t txifs; /* TXIF completion events */
uint32_t txabrts; /* TXIF completions with ESTAT.TXABRT */
uint32_t txerifs; /* TXERIF error events */
uint32_t txtimeouts; /* S/W detected TX timeouts */
uint32_t pktifs; /* PKTIF RX completion events */
uint32_t rxnotok; /* PKTIF without RXSTAT_OK */
uint32_t rxpktlen; /* PKTIF with bad pktlen */
uint32_t rxerifs; /* RXERIF error evernts */
};
#endif
/* The ENCX24J600 normal provides interrupts to the MCU via a GPIO pin. The
* following structure provides an MCU-independent mechanixm for controlling
* the ENCX24J600 GPIO interrupt.
@@ -150,30 +131,6 @@ extern "C"
struct spi_dev_s; /* see nuttx/spi/spi.h */
int enc_initialize(FAR struct spi_dev_s *spi,
FAR const struct enc_lower_s *lower, unsigned int devno);
/****************************************************************************
* Function: enc_stats
*
* Description:
* Return accumulated ENCX24J600 statistics. Statistics are cleared after
* being returned.
*
* Parameters:
* devno - If more than one ENCX24J600 is supported, then this is the
* zero based number that identifies the ENCX24J600;
* stats - The user-provided location to return the statistics.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/
#ifdef CONFIG_ENCX24J600_STATS
int enc_stats(unsigned int devno, struct enc_stats_s *stats);
#endif
#undef EXTERN
#ifdef __cplusplus
}
+106 -1
View File
@@ -66,17 +66,113 @@
* Pre-processor Definitions
****************************************************************************/
/* Helper macros for network device statistics */
#ifdef CONFIG_NETDEV_STATISTICS
# define NETDEV_RESET_STATISTICS(dev) \
memset(&(dev)->d_statistics, 0, sizeof(struct netdev_statistics_s))
# define _NETDEV_STATISTIC(dev,name) ((dev)->d_statistics.name)
# define _NETDEV_ERROR(dev,name) \
do \
{ \
(dev)->d_statistics.name++; \
(dev)->d_statistics.errors++; \
} \
while (0)
# define NETDEV_RXPACKETS(dev) _NETDEV_STATISTIC(dev,rx_packets)
# define NETDEV_RXFRAGMENTS(dev) _NETDEV_STATISTIC(dev,rx_fragments)
# define NETDEV_RXERRORS(dev) _NETDEV_ERROR(dev,rx_errors)
# ifdef CONFIG_NET_IPv4
# define NETDEV_RXIPV4(dev) _NETDEV_STATISTIC(dev,rx_ipv4)
# else
# define NETDEV_RXIPV4(dev)
# endif
# ifdef CONFIG_NET_IPv6
# define NETDEV_RXIPV6(dev) _NETDEV_STATISTIC(dev,rx_ipv6)
# else
# define NETDEV_RXIPV6(dev)
# endif
# ifdef CONFIG_NET_ARP
# define NETDEV_RXARP(dev) _NETDEV_STATISTIC(dev,rx_arp)
# else
# define NETDEV_RXARP(dev)
# endif
# define NETDEV_RXDROPPED(dev) _NETDEV_STATISTIC(dev,rx_dropped)
# define NETDEV_TXPACKETS(dev) _NETDEV_STATISTIC(dev,tx_packets)
# define NETDEV_TXDONE(dev) _NETDEV_STATISTIC(dev,tx_done)
# define NETDEV_TXERRORS(dev) _NETDEV_ERROR(dev,tx_errors)
# define NETDEV_TXTIMEOUTS(dev) _NETDEV_ERROR(dev,tx_timeouts)
# define NETDEV_ERRORS(dev) _NETDEV_STATISTIC(dev,errors)
#else
# define NETDEV_RXPACKETS(dev)
# define NETDEV_RXFRAGMENTS(dev)
# define NETDEV_RXERRORS(dev)
# define NETDEV_RXIPV4(dev)
# define NETDEV_RXIPV6(dev)
# define NETDEV_RXARP(dev)
# define NETDEV_RXDROPPED(dev)
# define NETDEV_TXPACKETS(dev)
# define NETDEV_TXDONE(dev)
# define NETDEV_TXERRORS(dev)
# define NETDEV_TXTIMEOUTS(dev)
# define NETDEV_ERRORS(dev)
#endif
/****************************************************************************
* Public Types
****************************************************************************/
struct devif_callback_s; /* Forward reference */
#ifdef CONFIG_NETDEV_STATISTICS
/* If CONFIG_NETDEV_STATISTICS is enabled and if the driver supports
* statistics, then this structure holds the counts of network driver
* events.
*/
struct netdev_statistics_s
{
/* Rx Status */
uint32_t rx_packets; /* Number of packets received */
uint32_t rx_fragments; /* Number of fragments received */
uint32_t rx_errors; /* Number of receive errors */
#ifdef CONFIG_NET_IPv4
uint32_t rx_ipv4; /* Number of Rx IPv4 packets received */
#endif
#ifdef CONFIG_NET_IPv6
uint32_t rx_ipv6; /* Number of Rx IPv6 packets received */
#endif
#ifdef CONFIG_NET_ARP
uint32_t rx_arp; /* Number of Rx ARP packets received */
#endif
uint32_t rx_dropped; /* Unsupported Rx packets received */
/* Tx Status */
uint32_t tx_packets; /* Number of Tx packets queued */
unit32_t tx_done; /* Number of packets completed */
uint32_t tx_errors; /* Number of receive errors (incl timeouts) */
uint32_t tx_timeouts; /* Number of Tx timeout errors */
/* Other status */
uint32_t errors; /* Total umber of errors */
};
#endif
/* This structure collects information that is specific to a specific network
* interface driver. If the hardware platform supports only a single instance
* of this structure.
*/
struct devif_callback_s; /* Forward reference */
struct net_driver_s
{
/* This link is used to maintain a single-linked list of ethernet drivers.
@@ -192,6 +288,15 @@ struct net_driver_s
sq_queue_t grplist;
#endif
#ifdef CONFIG_NETDEV_STATISTICS
/* If CONFIG_NETDEV_STATISTICS is enabled and if the driver supports
* statistics, then this structure holds the counts of network driver
* events.
*/
struct netdev_statistics_s d_statistics;
#endif
/* Application callbacks:
*
* Network device event handlers are retained in a 'list' and are called