All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Tristram.Ha@microchip.com
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Pavel Machek <pavel@ucw.cz>,
	UNGLinuxDriver@microchip.com, netdev@vger.kernel.org
Subject: Re: [PATCH RFC 2/6] net: dsa: microchip: Add MIB counter reading support
Date: Wed, 5 Dec 2018 18:53:47 +0100	[thread overview]
Message-ID: <20181205175347.GF12484@lunn.ch> (raw)
In-Reply-To: <1543880097-7106-3-git-send-email-Tristram.Ha@microchip.com>

Hi Tristan

> +static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr,
> +			      u64 *cnt)
> +{
> +	u32 data;
> +	int timeout;
> +	struct ksz_port *p = &dev->ports[port];
> +
> +	/* retain the flush/freeze bit */
> +	data = p->freeze ? MIB_COUNTER_FLUSH_FREEZE : 0;
> +	data |= MIB_COUNTER_READ;
> +	data |= (addr << MIB_COUNTER_INDEX_S);
> +	ksz_pwrite32(dev, port, REG_PORT_MIB_CTRL_STAT__4, data);
> +
> +	timeout = 1000;
> +	do {
> +		ksz_pread32(dev, port, REG_PORT_MIB_CTRL_STAT__4,
> +			    &data);
> +		usleep_range(1, 10);
> +		if (!(data & MIB_COUNTER_READ))
> +			break;
> +	} while (timeout-- > 0);

Could you use readx_poll_timeout() here?

> +void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	struct ksz_port_mib *mib;
> +
> +	mib = &dev->ports[port].mib;
> +
> +	/* freeze MIB counters if supported */
> +	if (dev->dev_ops->freeze_mib)
> +		dev->dev_ops->freeze_mib(dev, port, true);
> +	mutex_lock(&mib->cnt_mutex);
> +	port_r_cnt(dev, port);
> +	mutex_unlock(&mib->cnt_mutex);
> +	if (dev->dev_ops->freeze_mib)
> +		dev->dev_ops->freeze_mib(dev, port, false);

Should the freeze be protected by the mutex as well?

> +	memcpy(buf, mib->counters, dev->mib_cnt * sizeof(u64));

I wonder if this memcpy should also be protected by the mutex. As soon
as the mutex is dropped, the scheduled work could start updating
mib->counters in non-atomic ways?

> +}
> +
>  int ksz_port_bridge_join(struct dsa_switch *ds, int port,
>  			 struct net_device *br)
>  {
> @@ -255,6 +349,7 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
>  	/* setup slave port */
>  	dev->dev_ops->port_setup(dev, port, false);
>  	dev->dev_ops->phy_setup(dev, port, phy);
> +	dev->dev_ops->port_init_cnt(dev, port);

This is probably not the correct place to do this. MIB counters should
not be cleared by an ifdown/ifup cycle. They should only be cleared
when the driver is probed.

  reply	other threads:[~2018-12-05 17:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03 23:34 [PATCH RFC 0/6] net: dsa: microchip: Modify KSZ9477 DSA driver to support different tail tag formats Tristram.Ha
2018-12-03 23:34 ` [PATCH RFC 1/6] net: dsa: microchip: Prepare PHY for proper advertisement Tristram.Ha
2018-12-05 17:40   ` Andrew Lunn
2018-12-06 20:31     ` Tristram.Ha
2018-12-03 23:34 ` [PATCH RFC 2/6] net: dsa: microchip: Add MIB counter reading support Tristram.Ha
2018-12-05 17:53   ` Andrew Lunn [this message]
2018-12-06 20:16     ` Tristram.Ha
2018-12-06 20:42       ` Andrew Lunn
2018-12-03 23:34 ` [PATCH RFC 3/6] net: dsa: microchip: Break ksz_priv.h into two files Tristram.Ha
2018-12-03 23:34 ` [PATCH RFC 4/6] net: dsa: microchip: Each switch driver has its own tail tagging operations Tristram.Ha
2018-12-03 23:34 ` [PATCH RFC 5/6] net: dsa: microchip: Update tag_ksz.c to access switch driver Tristram.Ha
2018-12-05 18:00   ` Andrew Lunn
2018-12-05 18:18     ` Andrew Lunn
2018-12-05 18:52       ` Florian Fainelli
2018-12-06 20:00         ` Tristram.Ha
2018-12-06 20:41           ` Andrew Lunn
2018-12-07  3:16           ` Richard Cochran
2018-12-09  9:17           ` Pavel Machek
2018-12-11 23:59             ` Tristram.Ha
2018-12-12  8:18               ` Andrew Lunn
2018-12-03 23:34 ` [PATCH RFC 6/6] net: dsa: microchip: Add switch offload forwarding support Tristram.Ha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181205175347.GF12484@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Tristram.Ha@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.