netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Woojung.Huh@microchip.com
Cc: f.fainelli@gmail.com, vivien.didelot@savoirfairelinux.com,
	sergei.shtylyov@cogentembedded.com, netdev@vger.kernel.org,
	davem@davemloft.net, UNGLinuxDriver@microchip.com
Subject: Re: [PATCH v3 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477
Date: Mon, 22 May 2017 23:27:57 +0200	[thread overview]
Message-ID: <20170522212757.GS29447@lunn.ch> (raw)
In-Reply-To: <9235D6609DB808459E95D78E17F2E43D40A81210@CHN-SV-EXMX02.mchp-main.com>

On Mon, May 22, 2017 at 09:21:28PM +0000, Woojung.Huh@microchip.com wrote:
> Hi Andres,
> 
> > > +static struct {
> > > +	int index;
> > > +	char string[ETH_GSTRING_LEN];
> > 
> > Hi Woojung
> > 
> > Since you need to respin for the skb_put_padto(), please make this
> > const.
> OK.
> 
> > > +static int get_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
> > > +{
> > > +	struct ksz_device *dev = ds->priv;
> > > +	u8 data;
> > > +	int timeout = 1000;
> > > +
> > > +	ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> > VLAN_INDEX_M);
> > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_READ | VLAN_START);
> > > +
> > > +	/* wait to be cleared */
> > > +	data = 0;
> > > +	do {
> > > +		ksz_read8(dev, REG_SW_VLAN_CTRL, &data);
> > > +		if (!(data & VLAN_START))
> > > +			break;
> > > +		usleep_range(1, 10);
> > > +	} while (timeout-- > 0);
> > > +
> > > +	if (!timeout)
> > > +		return -ETIMEDOUT;
> > > +
> > > +	ksz_read32(dev, REG_SW_VLAN_ENTRY__4, &vlan_table[0]);
> > > +	ksz_read32(dev, REG_SW_VLAN_ENTRY_UNTAG__4,
> > &vlan_table[1]);
> > > +	ksz_read32(dev, REG_SW_VLAN_ENTRY_PORTS__4, &vlan_table[2]);
> > > +
> > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int set_vlan_table(struct dsa_switch *ds, u16 vid, u32 *vlan_table)
> > > +{
> > > +	struct ksz_device *dev = ds->priv;
> > > +	u8 data;
> > > +	int timeout = 1000;
> > > +
> > > +	ksz_write32(dev, REG_SW_VLAN_ENTRY__4, vlan_table[0]);
> > > +	ksz_write32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, vlan_table[1]);
> > > +	ksz_write32(dev, REG_SW_VLAN_ENTRY_PORTS__4, vlan_table[2]);
> > > +
> > > +	ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> > VLAN_INDEX_M);
> > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_START | VLAN_WRITE);
> > > +
> > > +	do {
> > > +		ksz_read8(dev, REG_SW_VLAN_CTRL, &data);
> > > +		if (!(data & VLAN_START))
> > > +			break;
> > > +		usleep_range(1, 10);
> > > +	} while (timeout-- > 0);
> > > +
> > > +	if (!timeout)
> > > +		return -ETIMEDOUT;
> > > +
> > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > > +
> > > +	mutex_lock(&dev->vlancache_mutex);
> > 
> > Humm. I think this is wrong. Shouldn't you hold the mutex while you
> > change the hardware as well as the cache. Otherwise there is a risk
> > your cache could be different to the hardware when you get a race
> > between two threads?
> Thanks for pointing this out.
> Rather than two separate mutex (H/W and vlancache), will put one HW access mutex
> around get_vlan_table and set_vlan_table to cover vlancache access too. Even though
> little bit overhead. How do you think?

I would move the mutex_lock(&dev->vlancache_mutex) to be beginning of
the function. It then protects both the hardware and the vlan cache,
and keeps them synchronised.

    Andrew

  reply	other threads:[~2017-05-22 21:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-19 22:57 [PATCH v3 net-next 3/5] dsa: add DSA switch driver for Microchip KSZ9477 Woojung.Huh
2017-05-20  0:10 ` Florian Fainelli
2017-05-22 14:31 ` Andrew Lunn
2017-05-22 21:21   ` Woojung.Huh
2017-05-22 21:27     ` Andrew Lunn [this message]
2017-05-22 22:26       ` Woojung.Huh

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=20170522212757.GS29447@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=sergei.shtylyov@cogentembedded.com \
    --cc=vivien.didelot@savoirfairelinux.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).