netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <Tristram.Ha@microchip.com>
To: <m.grzeschik@pengutronix.de>
Cc: <andrew@lunn.ch>, <f.fainelli@gmail.com>, <davem@davemloft.net>,
	<kernel@pengutronix.de>, <netdev@vger.kernel.org>,
	<matthias.schiffer@ew.tq-group.com>, <Woojung.Huh@microchip.com>,
	<UNGLinuxDriver@microchip.com>
Subject: RE: [PATCH v5 4/6] net: dsa: microchip: ksz8795: add support for ksz88xx chips
Date: Wed, 16 Dec 2020 06:33:06 +0000	[thread overview]
Message-ID: <BYAPR11MB35585C642A2073D0CBC85E44ECC50@BYAPR11MB3558.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20201207125627.30843-5-m.grzeschik@pengutronix.de>

>  static void ksz8_r_vlan_table(struct ksz_device *dev, u16 vid, u32 *vlan)
>  {
> -       int index;
> -       u16 *data;
> -       u16 addr;
> +       u16 addr = vid / dev->phy_port_cnt;
>         u64 buf;
> 
> -       data = (u16 *)&buf;
> -       addr = vid / dev->phy_port_cnt;
> -       index = vid & 3;
>         ksz8_r_table(dev, TABLE_VLAN, addr, &buf);
> -       *vlan = data[index];
> +       if (dev->features & IS_88X3) {
> +               *vlan = (u32)buf;
> +       } else {
> +               u16 *data = (u16 *)&buf;
> +
> +               *vlan = data[vid & 3];
> +       }
>  }
> 
>  static void ksz8_w_vlan_table(struct ksz_device *dev, u16 vid, u32 vlan)
>  {
> -       int index;
> -       u16 *data;
> -       u16 addr;
> +       u16 addr = vid / dev->phy_port_cnt;
>         u64 buf;
> 
> -       data = (u16 *)&buf;
> -       addr = vid / dev->phy_port_cnt;
> -       index = vid & 3;
>         ksz8_r_table(dev, TABLE_VLAN, addr, &buf);
> -       data[index] = vlan;
> +
> +       if (dev->features & IS_88X3) {
> +               buf = vlan;
> +       } else {
> +               u16 *data = (u16 *)&buf;
> +
> +               data[vid & 3] = vlan;
> +       }
> +
>         dev->vlan_cache[vid].table[0] = vlan;
>         ksz8_w_table(dev, TABLE_VLAN, addr, buf);
>  }

I am confused about how the addr is derived.

In KSZ8795 vid is in range of 0-4095.  The addr is just (vid / 4) as there
are 4 entries in one access.  The data are lined up in 16-bit boundary
so that the VLAN information can be accessed using the array.

For KSZ8895 the VLAN data are not lined up so the 64-bit variable
needs to be shifted accordingly and masked.

For KSZ8863 the addr is a hard value from 0 to 15.  The data buffer is just
32-bit.  The vid value is contained in the entry.  You need to match that vid
with the input vid to return the right information.

You need a different VLAN read function to check if the VLAN is already
programmed in the VLAN table by searching all 16 entries.

For the VLAN write function you need to check if there is available space
to add a new entry.  The VID range is still 0-4095, but the FID range is 0-15.


  reply	other threads:[~2020-12-16  6:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07 12:56 [PATCH v5 0/6] microchip: add support for ksz88x3 driver family Michael Grzeschik
2020-12-07 12:56 ` [PATCH v5 1/6] net: dsa: microchip: ksz8795: change drivers prefix to be generic Michael Grzeschik
2020-12-07 12:56 ` [PATCH v5 2/6] net: dsa: microchip: ksz8795: move cpu_select_interface to extra function Michael Grzeschik
2020-12-07 12:56 ` [PATCH v5 3/6] net: dsa: microchip: ksz8795: move register offsets and shifts to separate struct Michael Grzeschik
2020-12-07 14:11   ` kernel test robot
2020-12-07 15:01   ` David Miller
2020-12-07 20:02   ` Tristram.Ha
2020-12-07 21:44     ` Michael Grzeschik
2020-12-15 16:31       ` Michael Grzeschik
2020-12-11  4:21   ` kernel test robot
2020-12-07 12:56 ` [PATCH v5 4/6] net: dsa: microchip: ksz8795: add support for ksz88xx chips Michael Grzeschik
2020-12-16  6:33   ` Tristram.Ha [this message]
2021-02-01 18:37     ` Michael Grzeschik
2020-12-07 12:56 ` [PATCH v5 5/6] net: dsa: microchip: Add Microchip KSZ8863 SPI based driver support Michael Grzeschik
2020-12-07 12:56 ` [PATCH v5 6/6] dt-bindings: net: dsa: document additional Microchip KSZ8863/8873 switch Michael Grzeschik

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=BYAPR11MB35585C642A2073D0CBC85E44ECC50@BYAPR11MB3558.namprd11.prod.outlook.com \
    --to=tristram.ha@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=m.grzeschik@pengutronix.de \
    --cc=matthias.schiffer@ew.tq-group.com \
    --cc=netdev@vger.kernel.org \
    /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).