[LEDE-DEV] [RFC] AR8327 driver: implementing get_port_stats function

Daniel Gonzalez Cabanelas dgcbueu at gmail.com
Mon Feb 27 13:11:29 PST 2017


> Fetching the entire port stats only to look up two fields seems rather
> excessive. Please make a function instead that will look up the register
> number and fetch only the relevant registers.
> The lookup can be further simplified by adding an enum for the mib_stats
> array index.
> 
> - Felix

Hi Felix. Could this function be valid?. I'm afraid I cannot make anything more
sophisticated

ar8xxx_sw_get_port_stats(struct switch_dev *dev, int port,
		       struct switch_port_stats *stats)
{
  	struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
	unsigned int base;
	unsigned int rx_offset, tx_offset;

	if (port >= dev->ports)
		return -EINVAL;

	base = priv->chip->reg_port_stats_start +
	       priv->chip->reg_port_stats_length * port;

	if (priv->chip->num_mibs == ARRAY_SIZE(ar8236_mibs)){
		rx_offset = AR8236_STATS_RXGOODBYTE;
		tx_offset = AR8236_STATS_TXBYTE;
	}

	else if (priv->chip->num_mibs == ARRAY_SIZE(ar8216_mibs)){
		rx_offset = AR8216_STATS_RXGOODBYTE;
		tx_offset = AR8216_STATS_TXBYTE;
	}

	stats->rx_bytes = ar8xxx_read(priv, base + rx_offset);
	stats->tx_bytes = ar8xxx_read(priv, base + tx_offset);

	return 0;
}

Also tested and working ok.

Regards
Daniel






More information about the Lede-dev mailing list