Re: [PATCH v4 net-next 2/2] net: dsa: qca: ar9331: export stats64
Hi George, On Fri, Dec 04, 2020 at 04:04:07PM -0600, George McCollister wrote: > On Fri, Dec 4, 2020 at 8:59 AM Oleksij Rempel wrote: > > > > Add stats support for the ar9331 switch. > > > > Signed-off-by: Oleksij Rempel > > --- > > drivers/net/dsa/qca/ar9331.c | 247 ++- > > 1 file changed, 246 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c > > index 605d7b675216..4c1a4c448d80 100644 > > --- a/drivers/net/dsa/qca/ar9331.c > > +++ b/drivers/net/dsa/qca/ar9331.c > > @@ -101,6 +101,57 @@ > > AR9331_SW_PORT_STATUS_RX_FLOW_EN | > > AR9331_SW_PORT_STATUS_TX_FLOW_EN | \ > > AR9331_SW_PORT_STATUS_SPEED_M) > > > > +/* MIB registers */ > > +#define AR9331_MIB_COUNTER(x) (0x2 + ((x) * 0x100)) > > + > > +#define AR9331_PORT_MIB_rxbroad(_port) (AR9331_MIB_COUNTER(_port) > > + 0x00) > > +#define AR9331_PORT_MIB_rxpause(_port) (AR9331_MIB_COUNTER(_port) > > + 0x04) > > +#define AR9331_PORT_MIB_rxmulti(_port) (AR9331_MIB_COUNTER(_port) > > + 0x08) > > +#define AR9331_PORT_MIB_rxfcserr(_port) > > (AR9331_MIB_COUNTER(_port) + 0x0c) > > +#define AR9331_PORT_MIB_rxalignerr(_port) (AR9331_MIB_COUNTER(_port) > > + 0x10) > > +#define AR9331_PORT_MIB_rxrunt(_port) (AR9331_MIB_COUNTER(_port) > > + 0x14) > > +#define AR9331_PORT_MIB_rxfragment(_port) (AR9331_MIB_COUNTER(_port) > > + 0x18) > > +#define AR9331_PORT_MIB_rx64byte(_port) > > (AR9331_MIB_COUNTER(_port) + 0x1c) > > +#define AR9331_PORT_MIB_rx128byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x20) > > +#define AR9331_PORT_MIB_rx256byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x24) > > +#define AR9331_PORT_MIB_rx512byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x28) > > +#define AR9331_PORT_MIB_rx1024byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x2c) > > +#define AR9331_PORT_MIB_rx1518byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x30) > > +#define AR9331_PORT_MIB_rxmaxbyte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x34) > > +#define AR9331_PORT_MIB_rxtoolong(_port) (AR9331_MIB_COUNTER(_port) > > + 0x38) > > + > > +/* 64 bit counter */ > > +#define AR9331_PORT_MIB_rxgoodbyte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x3c) > > + > > +/* 64 bit counter */ > > +#define AR9331_PORT_MIB_rxbadbyte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x44) > > + > > +#define AR9331_PORT_MIB_rxoverflow(_port) (AR9331_MIB_COUNTER(_port) > > + 0x4c) > > +#define AR9331_PORT_MIB_filtered(_port) > > (AR9331_MIB_COUNTER(_port) + 0x50) > > +#define AR9331_PORT_MIB_txbroad(_port) (AR9331_MIB_COUNTER(_port) > > + 0x54) > > +#define AR9331_PORT_MIB_txpause(_port) (AR9331_MIB_COUNTER(_port) > > + 0x58) > > +#define AR9331_PORT_MIB_txmulti(_port) (AR9331_MIB_COUNTER(_port) > > + 0x5c) > > +#define AR9331_PORT_MIB_txunderrun(_port) (AR9331_MIB_COUNTER(_port) > > + 0x60) > > +#define AR9331_PORT_MIB_tx64byte(_port) > > (AR9331_MIB_COUNTER(_port) + 0x64) > > +#define AR9331_PORT_MIB_tx128byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x68) > > +#define AR9331_PORT_MIB_tx256byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x6c) > > +#define AR9331_PORT_MIB_tx512byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x70) > > +#define AR9331_PORT_MIB_tx1024byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x74) > > +#define AR9331_PORT_MIB_tx1518byte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x78) > > +#define AR9331_PORT_MIB_txmaxbyte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x7c) > > +#define AR9331_PORT_MIB_txoversize(_port) (AR9331_MIB_COUNTER(_port) > > + 0x80) > > + > > +/* 64 bit counter */ > > +#define AR9331_PORT_MIB_txbyte(_port) (AR9331_MIB_COUNTER(_port) > > + 0x84) > > + > > +#define AR9331_PORT_MIB_txcollision(_port) (AR9331_MIB_COUNTER(_port) > > + 0x8c) > > +#define AR9331_PORT_MIB_txabortcol(_port) (AR9331_MIB_COUNTER(_port) > > + 0x90) > > +#define AR9331_PORT_MIB_txmulticol(_port) (AR9331_MIB_COUNTER(_port) > > + 0x94) > > +#define AR9331_PORT_MIB_txsinglecol(_port) (AR9331_MIB_COUNTER(_port) > > + 0x98) > > +#define AR9331_PORT_MIB_txexcdefer(_port) (AR9331_MIB_COUNTER(_port) > > + 0x9c) > > +#define AR9331_PORT_MIB_txdefer(_port) (AR9331_MIB_COUNTER(_port) > > + 0xa0) > > +#define AR9331_PORT_MIB_txlatecol(_port) (AR9331_MIB_COUNTER(_port) > > + 0xa4) > > + > > /* Phy bypass mode > > * > > * Bit: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 | > > @@ -154,6 +205,59 @@ > > #define AR9331_SW_MDIO_POLL_SLEEP_US 1 > > #define AR9331_SW_MDIO_POLL_TIMEOUT_US 20 > > > > +#define STATS_INTERVAL_JIFFIES (3 * HZ) > > + > > +struct ar9331_sw_stats { > > +
Re: [PATCH v4 net-next 2/2] net: dsa: qca: ar9331: export stats64
> +static void ar9331_stats_update(struct ar9331_sw_port *port, > + struct rtnl_link_stats64 *stats) > +{ > + struct ar9331_sw_stats *s = &port->stats; > + > + stats->rx_packets = s->rxbroad + s->rxmulti + s->rx64byte + > + s->rx128byte + s->rx256byte + s->rx512byte + s->rx1024byte + > + s->rx1518byte + s->rxmaxbyte; > + stats->tx_packets = s->txbroad + s->txmulti + s->tx64byte + > + s->tx128byte + s->tx256byte + s->tx512byte + s->tx1024byte + > + s->tx1518byte + s->txmaxbyte; > + stats->rx_bytes = s->rxgoodbyte; > + stats->tx_bytes = s->txbyte; > + stats->rx_errors = s->rxfcserr + s->rxalignerr + s->rxrunt + > + s->rxfragment + s->rxoverflow; > + stats->tx_errors = s->txoversize; > + stats->multicast = s->rxmulti; > + stats->collisions = s->txcollision; > + stats->rx_length_errors = s->rxrunt + s->rxfragment + s->rxtoolong; > + stats->rx_crc_errors = s->rxfcserr + s->rxalignerr + s->rxfragment; > + stats->rx_frame_errors = s->rxalignerr; > + stats->rx_missed_errors = s->rxoverflow; > + stats->tx_aborted_errors = s->txabortcol; > + stats->tx_fifo_errors = s->txunderrun; > + stats->tx_window_errors = s->txlatecol; > + stats->rx_nohandler = s->filtered; > +} > + Since these are u64 and you cannot take the mutex, you need to using include/linux/u64_stats_sync.h Andrew
Re: [PATCH v4 net-next 2/2] net: dsa: qca: ar9331: export stats64
> > +struct ar9331_sw_stats { > > + u64 rxbroad; > > + u64 rxpause; > > + u64 rxmulti; > > +}; 7> > +struct ar9331_sw_port { > > + int idx; > > + struct ar9331_sw_priv *priv; > > + struct delayed_work mib_read; > > + struct ar9331_sw_stats stats; > > +static void ar9331_stats_update(struct ar9331_sw_port *port, > > + struct rtnl_link_stats64 *stats) > > +{ > > + struct ar9331_sw_stats *s = &port->stats; > > + > > + stats->rx_packets = s->rxbroad + s->rxmulti + s->rx64byte + > > + s->rx128byte + s->rx256byte + s->rx512byte + s->rx1024byte + > > + s->rx1518byte + s->rxmaxbyte; > > Are all of these port->stats accesses always atomic? I'll need to do > something similar in my xrs700x driver and want to make sure there > doesn't need to be a lock between here and where they're updated in > the delayed work. Since these are u64, they are not atomic on 32 bit systems. Take a look at include/linux/u64_stats_sync.h Andrewu
Re: [PATCH v4 net-next 2/2] net: dsa: qca: ar9331: export stats64
On Fri, Dec 4, 2020 at 8:59 AM Oleksij Rempel wrote: > > Add stats support for the ar9331 switch. > > Signed-off-by: Oleksij Rempel > --- > drivers/net/dsa/qca/ar9331.c | 247 ++- > 1 file changed, 246 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c > index 605d7b675216..4c1a4c448d80 100644 > --- a/drivers/net/dsa/qca/ar9331.c > +++ b/drivers/net/dsa/qca/ar9331.c > @@ -101,6 +101,57 @@ > AR9331_SW_PORT_STATUS_RX_FLOW_EN | AR9331_SW_PORT_STATUS_TX_FLOW_EN > | \ > AR9331_SW_PORT_STATUS_SPEED_M) > > +/* MIB registers */ > +#define AR9331_MIB_COUNTER(x) (0x2 + ((x) * 0x100)) > + > +#define AR9331_PORT_MIB_rxbroad(_port) (AR9331_MIB_COUNTER(_port) + > 0x00) > +#define AR9331_PORT_MIB_rxpause(_port) (AR9331_MIB_COUNTER(_port) + > 0x04) > +#define AR9331_PORT_MIB_rxmulti(_port) (AR9331_MIB_COUNTER(_port) + > 0x08) > +#define AR9331_PORT_MIB_rxfcserr(_port) > (AR9331_MIB_COUNTER(_port) + 0x0c) > +#define AR9331_PORT_MIB_rxalignerr(_port) (AR9331_MIB_COUNTER(_port) + > 0x10) > +#define AR9331_PORT_MIB_rxrunt(_port) (AR9331_MIB_COUNTER(_port) + > 0x14) > +#define AR9331_PORT_MIB_rxfragment(_port) (AR9331_MIB_COUNTER(_port) + > 0x18) > +#define AR9331_PORT_MIB_rx64byte(_port) > (AR9331_MIB_COUNTER(_port) + 0x1c) > +#define AR9331_PORT_MIB_rx128byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x20) > +#define AR9331_PORT_MIB_rx256byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x24) > +#define AR9331_PORT_MIB_rx512byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x28) > +#define AR9331_PORT_MIB_rx1024byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x2c) > +#define AR9331_PORT_MIB_rx1518byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x30) > +#define AR9331_PORT_MIB_rxmaxbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x34) > +#define AR9331_PORT_MIB_rxtoolong(_port) (AR9331_MIB_COUNTER(_port) + > 0x38) > + > +/* 64 bit counter */ > +#define AR9331_PORT_MIB_rxgoodbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x3c) > + > +/* 64 bit counter */ > +#define AR9331_PORT_MIB_rxbadbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x44) > + > +#define AR9331_PORT_MIB_rxoverflow(_port) (AR9331_MIB_COUNTER(_port) + > 0x4c) > +#define AR9331_PORT_MIB_filtered(_port) > (AR9331_MIB_COUNTER(_port) + 0x50) > +#define AR9331_PORT_MIB_txbroad(_port) (AR9331_MIB_COUNTER(_port) + > 0x54) > +#define AR9331_PORT_MIB_txpause(_port) (AR9331_MIB_COUNTER(_port) + > 0x58) > +#define AR9331_PORT_MIB_txmulti(_port) (AR9331_MIB_COUNTER(_port) + > 0x5c) > +#define AR9331_PORT_MIB_txunderrun(_port) (AR9331_MIB_COUNTER(_port) + > 0x60) > +#define AR9331_PORT_MIB_tx64byte(_port) > (AR9331_MIB_COUNTER(_port) + 0x64) > +#define AR9331_PORT_MIB_tx128byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x68) > +#define AR9331_PORT_MIB_tx256byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x6c) > +#define AR9331_PORT_MIB_tx512byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x70) > +#define AR9331_PORT_MIB_tx1024byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x74) > +#define AR9331_PORT_MIB_tx1518byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x78) > +#define AR9331_PORT_MIB_txmaxbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x7c) > +#define AR9331_PORT_MIB_txoversize(_port) (AR9331_MIB_COUNTER(_port) + > 0x80) > + > +/* 64 bit counter */ > +#define AR9331_PORT_MIB_txbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x84) > + > +#define AR9331_PORT_MIB_txcollision(_port) (AR9331_MIB_COUNTER(_port) + > 0x8c) > +#define AR9331_PORT_MIB_txabortcol(_port) (AR9331_MIB_COUNTER(_port) + > 0x90) > +#define AR9331_PORT_MIB_txmulticol(_port) (AR9331_MIB_COUNTER(_port) + > 0x94) > +#define AR9331_PORT_MIB_txsinglecol(_port) (AR9331_MIB_COUNTER(_port) + > 0x98) > +#define AR9331_PORT_MIB_txexcdefer(_port) (AR9331_MIB_COUNTER(_port) + > 0x9c) > +#define AR9331_PORT_MIB_txdefer(_port) (AR9331_MIB_COUNTER(_port) + > 0xa0) > +#define AR9331_PORT_MIB_txlatecol(_port) (AR9331_MIB_COUNTER(_port) + > 0xa4) > + > /* Phy bypass mode > * > * Bit: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 | > @@ -154,6 +205,59 @@ > #define AR9331_SW_MDIO_POLL_SLEEP_US 1 > #define AR9331_SW_MDIO_POLL_TIMEOUT_US 20 > > +#define STATS_INTERVAL_JIFFIES (3 * HZ) > + > +struct ar9331_sw_stats { > + u64 rxbroad; > + u64 rxpause; > + u64 rxmulti; > + u64 rxfcserr; > + u64 rxalignerr; > + u64 rxrunt; > + u64 rxfragment; > + u64 rx64byte; > + u64 rx128byte; > + u64 rx256byte; > + u64 rx512byte; > + u64 rx1024byte; > + u64 rx1518byte; > +
Re: [PATCH v4 net-next 2/2] net: dsa: qca: ar9331: export stats64
On Fri, Dec 4, 2020 at 8:59 AM Oleksij Rempel wrote: > > Add stats support for the ar9331 switch. > > Signed-off-by: Oleksij Rempel > --- > drivers/net/dsa/qca/ar9331.c | 247 ++- > 1 file changed, 246 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c > index 605d7b675216..4c1a4c448d80 100644 > --- a/drivers/net/dsa/qca/ar9331.c > +++ b/drivers/net/dsa/qca/ar9331.c > @@ -101,6 +101,57 @@ > AR9331_SW_PORT_STATUS_RX_FLOW_EN | AR9331_SW_PORT_STATUS_TX_FLOW_EN > | \ > AR9331_SW_PORT_STATUS_SPEED_M) > > +/* MIB registers */ > +#define AR9331_MIB_COUNTER(x) (0x2 + ((x) * 0x100)) > + > +#define AR9331_PORT_MIB_rxbroad(_port) (AR9331_MIB_COUNTER(_port) + > 0x00) > +#define AR9331_PORT_MIB_rxpause(_port) (AR9331_MIB_COUNTER(_port) + > 0x04) > +#define AR9331_PORT_MIB_rxmulti(_port) (AR9331_MIB_COUNTER(_port) + > 0x08) > +#define AR9331_PORT_MIB_rxfcserr(_port) > (AR9331_MIB_COUNTER(_port) + 0x0c) > +#define AR9331_PORT_MIB_rxalignerr(_port) (AR9331_MIB_COUNTER(_port) + > 0x10) > +#define AR9331_PORT_MIB_rxrunt(_port) (AR9331_MIB_COUNTER(_port) + > 0x14) > +#define AR9331_PORT_MIB_rxfragment(_port) (AR9331_MIB_COUNTER(_port) + > 0x18) > +#define AR9331_PORT_MIB_rx64byte(_port) > (AR9331_MIB_COUNTER(_port) + 0x1c) > +#define AR9331_PORT_MIB_rx128byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x20) > +#define AR9331_PORT_MIB_rx256byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x24) > +#define AR9331_PORT_MIB_rx512byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x28) > +#define AR9331_PORT_MIB_rx1024byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x2c) > +#define AR9331_PORT_MIB_rx1518byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x30) > +#define AR9331_PORT_MIB_rxmaxbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x34) > +#define AR9331_PORT_MIB_rxtoolong(_port) (AR9331_MIB_COUNTER(_port) + > 0x38) > + > +/* 64 bit counter */ > +#define AR9331_PORT_MIB_rxgoodbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x3c) > + > +/* 64 bit counter */ > +#define AR9331_PORT_MIB_rxbadbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x44) > + > +#define AR9331_PORT_MIB_rxoverflow(_port) (AR9331_MIB_COUNTER(_port) + > 0x4c) > +#define AR9331_PORT_MIB_filtered(_port) > (AR9331_MIB_COUNTER(_port) + 0x50) > +#define AR9331_PORT_MIB_txbroad(_port) (AR9331_MIB_COUNTER(_port) + > 0x54) > +#define AR9331_PORT_MIB_txpause(_port) (AR9331_MIB_COUNTER(_port) + > 0x58) > +#define AR9331_PORT_MIB_txmulti(_port) (AR9331_MIB_COUNTER(_port) + > 0x5c) > +#define AR9331_PORT_MIB_txunderrun(_port) (AR9331_MIB_COUNTER(_port) + > 0x60) > +#define AR9331_PORT_MIB_tx64byte(_port) > (AR9331_MIB_COUNTER(_port) + 0x64) > +#define AR9331_PORT_MIB_tx128byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x68) > +#define AR9331_PORT_MIB_tx256byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x6c) > +#define AR9331_PORT_MIB_tx512byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x70) > +#define AR9331_PORT_MIB_tx1024byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x74) > +#define AR9331_PORT_MIB_tx1518byte(_port) (AR9331_MIB_COUNTER(_port) + > 0x78) > +#define AR9331_PORT_MIB_txmaxbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x7c) > +#define AR9331_PORT_MIB_txoversize(_port) (AR9331_MIB_COUNTER(_port) + > 0x80) > + > +/* 64 bit counter */ > +#define AR9331_PORT_MIB_txbyte(_port) (AR9331_MIB_COUNTER(_port) + > 0x84) > + > +#define AR9331_PORT_MIB_txcollision(_port) (AR9331_MIB_COUNTER(_port) + > 0x8c) > +#define AR9331_PORT_MIB_txabortcol(_port) (AR9331_MIB_COUNTER(_port) + > 0x90) > +#define AR9331_PORT_MIB_txmulticol(_port) (AR9331_MIB_COUNTER(_port) + > 0x94) > +#define AR9331_PORT_MIB_txsinglecol(_port) (AR9331_MIB_COUNTER(_port) + > 0x98) > +#define AR9331_PORT_MIB_txexcdefer(_port) (AR9331_MIB_COUNTER(_port) + > 0x9c) > +#define AR9331_PORT_MIB_txdefer(_port) (AR9331_MIB_COUNTER(_port) + > 0xa0) > +#define AR9331_PORT_MIB_txlatecol(_port) (AR9331_MIB_COUNTER(_port) + > 0xa4) > + > /* Phy bypass mode > * > * Bit: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 | > @@ -154,6 +205,59 @@ > #define AR9331_SW_MDIO_POLL_SLEEP_US 1 > #define AR9331_SW_MDIO_POLL_TIMEOUT_US 20 > > +#define STATS_INTERVAL_JIFFIES (3 * HZ) > + > +struct ar9331_sw_stats { > + u64 rxbroad; > + u64 rxpause; > + u64 rxmulti; > + u64 rxfcserr; > + u64 rxalignerr; > + u64 rxrunt; > + u64 rxfragment; > + u64 rx64byte; > + u64 rx128byte; > + u64 rx256byte; > + u64 rx512byte; > + u64 rx1024byte; > + u64 rx1518byte; > +
[PATCH v4 net-next 2/2] net: dsa: qca: ar9331: export stats64
Add stats support for the ar9331 switch. Signed-off-by: Oleksij Rempel --- drivers/net/dsa/qca/ar9331.c | 247 ++- 1 file changed, 246 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c index 605d7b675216..4c1a4c448d80 100644 --- a/drivers/net/dsa/qca/ar9331.c +++ b/drivers/net/dsa/qca/ar9331.c @@ -101,6 +101,57 @@ AR9331_SW_PORT_STATUS_RX_FLOW_EN | AR9331_SW_PORT_STATUS_TX_FLOW_EN | \ AR9331_SW_PORT_STATUS_SPEED_M) +/* MIB registers */ +#define AR9331_MIB_COUNTER(x) (0x2 + ((x) * 0x100)) + +#define AR9331_PORT_MIB_rxbroad(_port) (AR9331_MIB_COUNTER(_port) + 0x00) +#define AR9331_PORT_MIB_rxpause(_port) (AR9331_MIB_COUNTER(_port) + 0x04) +#define AR9331_PORT_MIB_rxmulti(_port) (AR9331_MIB_COUNTER(_port) + 0x08) +#define AR9331_PORT_MIB_rxfcserr(_port) (AR9331_MIB_COUNTER(_port) + 0x0c) +#define AR9331_PORT_MIB_rxalignerr(_port) (AR9331_MIB_COUNTER(_port) + 0x10) +#define AR9331_PORT_MIB_rxrunt(_port) (AR9331_MIB_COUNTER(_port) + 0x14) +#define AR9331_PORT_MIB_rxfragment(_port) (AR9331_MIB_COUNTER(_port) + 0x18) +#define AR9331_PORT_MIB_rx64byte(_port) (AR9331_MIB_COUNTER(_port) + 0x1c) +#define AR9331_PORT_MIB_rx128byte(_port) (AR9331_MIB_COUNTER(_port) + 0x20) +#define AR9331_PORT_MIB_rx256byte(_port) (AR9331_MIB_COUNTER(_port) + 0x24) +#define AR9331_PORT_MIB_rx512byte(_port) (AR9331_MIB_COUNTER(_port) + 0x28) +#define AR9331_PORT_MIB_rx1024byte(_port) (AR9331_MIB_COUNTER(_port) + 0x2c) +#define AR9331_PORT_MIB_rx1518byte(_port) (AR9331_MIB_COUNTER(_port) + 0x30) +#define AR9331_PORT_MIB_rxmaxbyte(_port) (AR9331_MIB_COUNTER(_port) + 0x34) +#define AR9331_PORT_MIB_rxtoolong(_port) (AR9331_MIB_COUNTER(_port) + 0x38) + +/* 64 bit counter */ +#define AR9331_PORT_MIB_rxgoodbyte(_port) (AR9331_MIB_COUNTER(_port) + 0x3c) + +/* 64 bit counter */ +#define AR9331_PORT_MIB_rxbadbyte(_port) (AR9331_MIB_COUNTER(_port) + 0x44) + +#define AR9331_PORT_MIB_rxoverflow(_port) (AR9331_MIB_COUNTER(_port) + 0x4c) +#define AR9331_PORT_MIB_filtered(_port) (AR9331_MIB_COUNTER(_port) + 0x50) +#define AR9331_PORT_MIB_txbroad(_port) (AR9331_MIB_COUNTER(_port) + 0x54) +#define AR9331_PORT_MIB_txpause(_port) (AR9331_MIB_COUNTER(_port) + 0x58) +#define AR9331_PORT_MIB_txmulti(_port) (AR9331_MIB_COUNTER(_port) + 0x5c) +#define AR9331_PORT_MIB_txunderrun(_port) (AR9331_MIB_COUNTER(_port) + 0x60) +#define AR9331_PORT_MIB_tx64byte(_port) (AR9331_MIB_COUNTER(_port) + 0x64) +#define AR9331_PORT_MIB_tx128byte(_port) (AR9331_MIB_COUNTER(_port) + 0x68) +#define AR9331_PORT_MIB_tx256byte(_port) (AR9331_MIB_COUNTER(_port) + 0x6c) +#define AR9331_PORT_MIB_tx512byte(_port) (AR9331_MIB_COUNTER(_port) + 0x70) +#define AR9331_PORT_MIB_tx1024byte(_port) (AR9331_MIB_COUNTER(_port) + 0x74) +#define AR9331_PORT_MIB_tx1518byte(_port) (AR9331_MIB_COUNTER(_port) + 0x78) +#define AR9331_PORT_MIB_txmaxbyte(_port) (AR9331_MIB_COUNTER(_port) + 0x7c) +#define AR9331_PORT_MIB_txoversize(_port) (AR9331_MIB_COUNTER(_port) + 0x80) + +/* 64 bit counter */ +#define AR9331_PORT_MIB_txbyte(_port) (AR9331_MIB_COUNTER(_port) + 0x84) + +#define AR9331_PORT_MIB_txcollision(_port) (AR9331_MIB_COUNTER(_port) + 0x8c) +#define AR9331_PORT_MIB_txabortcol(_port) (AR9331_MIB_COUNTER(_port) + 0x90) +#define AR9331_PORT_MIB_txmulticol(_port) (AR9331_MIB_COUNTER(_port) + 0x94) +#define AR9331_PORT_MIB_txsinglecol(_port) (AR9331_MIB_COUNTER(_port) + 0x98) +#define AR9331_PORT_MIB_txexcdefer(_port) (AR9331_MIB_COUNTER(_port) + 0x9c) +#define AR9331_PORT_MIB_txdefer(_port) (AR9331_MIB_COUNTER(_port) + 0xa0) +#define AR9331_PORT_MIB_txlatecol(_port) (AR9331_MIB_COUNTER(_port) + 0xa4) + /* Phy bypass mode * * Bit: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 | @@ -154,6 +205,59 @@ #define AR9331_SW_MDIO_POLL_SLEEP_US 1 #define AR9331_SW_MDIO_POLL_TIMEOUT_US 20 +#define STATS_INTERVAL_JIFFIES (3 * HZ) + +struct ar9331_sw_stats { + u64 rxbroad; + u64 rxpause; + u64 rxmulti; + u64 rxfcserr; + u64 rxalignerr; + u64 rxrunt; + u64 rxfragment; + u64 rx64byte; + u64 rx128byte; + u64 rx256byte; + u64 rx512byte; + u64 rx1024byte; + u64 rx1518byte; + u64 rxmaxbyte; + u64 rxtoolong; + u64 rxgoodbyte; + u64 rxbadbyte; + u64 rxoverflow; + u64 filtered; + u64 txbroad; + u64 txpause; + u64 txmulti; + u64 txunderrun; + u64 tx64byte; + u64 tx128byte; + u64 tx256byte; + u64 tx512byt