From: Simon Horman <horms@kernel.org>
To: Pawel Dembicki <paweldembicki@gmail.com>
Cc: netdev@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Russell King <linux@armlinux.org.uk>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: dsa: vsc73xx: implement FDB operations
Date: Mon, 12 Aug 2024 14:51:08 +0100 [thread overview]
Message-ID: <20240812135108.GA21855@kernel.org> (raw)
In-Reply-To: <20240811195649.2360966-1-paweldembicki@gmail.com>
On Sun, Aug 11, 2024 at 09:56:49PM +0200, Pawel Dembicki wrote:
> This commit introduces implementations of three functions:
> .port_fdb_dump
> .port_fdb_add
> .port_fdb_del
>
> The FDB database organization is the same as in other old Vitesse chips:
> It has 2048 rows and 4 columns (buckets). The row index is calculated by
> the hash function 'vsc73xx_calc_hash' and the FDB entry must be placed
> exactly into row[hash]. The chip selects the row number by itself.
>
> Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
> ---
> drivers/net/dsa/vitesse-vsc73xx-core.c | 302 +++++++++++++++++++++++++
> drivers/net/dsa/vitesse-vsc73xx.h | 2 +
> 2 files changed, 304 insertions(+)
>
> diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
> index a82b550a9e40..7da1641b8bab 100644
> --- a/drivers/net/dsa/vitesse-vsc73xx-core.c
> +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
> @@ -46,6 +46,8 @@
> #define VSC73XX_BLOCK_MII_EXTERNAL 0x1 /* External MDIO subblock */
>
> #define CPU_PORT 6 /* CPU port */
> +#define VSC73XX_NUM_FDB_RECORDS 2048
> +#define VSC73XX_NUM_BUCKETS 4
>
> /* MAC Block registers */
> #define VSC73XX_MAC_CFG 0x00
> @@ -197,6 +199,21 @@
> #define VSC73XX_SRCMASKS_MIRROR BIT(26)
> #define VSC73XX_SRCMASKS_PORTS_MASK GENMASK(7, 0)
>
> +#define VSC73XX_MACHDATA_VID GENMASK(27, 16)
> +#define VSC73XX_MACHDATA_VID_SHIFT 16
> +#define VSC73XX_MACHDATA_MAC0_SHIFT 8
> +#define VSC73XX_MACHDATA_MAC1_SHIFT 0
> +#define VSC73XX_MACLDATA_MAC2_SHIFT 24
> +#define VSC73XX_MACLDATA_MAC3_SHIFT 16
> +#define VSC73XX_MACLDATA_MAC4_SHIFT 8
> +#define VSC73XX_MACLDATA_MAC5_SHIFT 0
> +#define VSC73XX_MAC_BYTE_MASK GENMASK(7, 0)
> +
> +#define VSC73XX_MACTINDX_SHADOW BIT(13)
> +#define VSC73XX_MACTINDX_BUCKET_MASK GENMASK(12, 11)
> +#define VSC73XX_MACTINDX_BUCKET_MASK_SHIFT 11
> +#define VSC73XX_MACTINDX_INDEX_MASK GENMASK(10, 0)
> +
> #define VSC73XX_MACACCESS_CPU_COPY BIT(14)
> #define VSC73XX_MACACCESS_FWD_KILL BIT(13)
> #define VSC73XX_MACACCESS_IGNORE_VLAN BIT(12)
> @@ -204,6 +221,7 @@
> #define VSC73XX_MACACCESS_VALID BIT(10)
> #define VSC73XX_MACACCESS_LOCKED BIT(9)
> #define VSC73XX_MACACCESS_DEST_IDX_MASK GENMASK(8, 3)
> +#define VSC73XX_MACACCESS_DEST_IDX_MASK_SHIFT 3
> #define VSC73XX_MACACCESS_CMD_MASK GENMASK(2, 0)
> #define VSC73XX_MACACCESS_CMD_IDLE 0
> #define VSC73XX_MACACCESS_CMD_LEARN 1
> @@ -329,6 +347,13 @@ struct vsc73xx_counter {
> const char *name;
> };
>
> +struct vsc73xx_fdb {
> + u16 vid;
> + u8 port;
> + u8 mac[6];
> + bool valid;
> +};
> +
> /* Counters are named according to the MIB standards where applicable.
> * Some counters are custom, non-standard. The standard counters are
> * named in accordance with RFC2819, RFC2021 and IEEE Std 802.3-2002 Annex
> @@ -1829,6 +1854,278 @@ static void vsc73xx_port_stp_state_set(struct dsa_switch *ds, int port,
> vsc73xx_refresh_fwd_map(ds, port, state);
> }
>
> +static u16 vsc73xx_calc_hash(const unsigned char *addr, u16 vid)
> +{
> + /* VID 5-0, MAC 47-44 */
> + u16 hash = ((vid & GENMASK(5, 0)) << 4) | (addr[0] >> 4);
> +
> + /* MAC 43-33 */
> + hash ^= ((addr[0] & GENMASK(3, 0)) << 7) | (addr[1] >> 1);
> + /* MAC 32-22 */
> + hash ^= ((addr[1] & BIT(0)) << 10) | (addr[2] << 2) | (addr[3] >> 6);
> + /* MAC 21-11 */
> + hash ^= ((addr[3] & GENMASK(5, 0)) << 5) | (addr[4] >> 3);
> + /* MAC 10-0 */
> + hash ^= ((addr[4] & GENMASK(2, 0)) << 8) | addr[5];
In this function and throughout this patchset I see a lot of mask nd shift
operations, sometimes combined, here and elsewhere in this patchset. It
seems likely that using FIELD_PREP, in conjunction with GENMASK and BIT,
would be appropriate instead. If combined with #defines for the GENMASK and
BIT constants with meaningful names this may significantly improve
readability.
> +
> + return hash;
> +}
...
next prev parent reply other threads:[~2024-08-12 13:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-11 19:56 [PATCH net-next] net: dsa: vsc73xx: implement FDB operations Pawel Dembicki
2024-08-12 13:51 ` Simon Horman [this message]
2024-08-13 11:34 ` Vladimir Oltean
2024-08-22 14:19 ` Paweł Dembicki
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=20240812135108.GA21855@kernel.org \
--to=horms@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=paweldembicki@gmail.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 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.