[RFC PATCH v2 1/3] net: ti: icssg-prueth: Add helper functions to configure FDB

Andrew Lunn andrew at lunn.ch
Fri Jan 19 05:55:08 PST 2024


> +int icssg_fdb_add_del(struct prueth_emac *emac, const unsigned char *addr,
> +		      u8 vid, u8 fid_c2, bool add)
> +{
> +
> +	for (i = 0; i < ETH_ALEN; i++)
> +		mac_fid[i] = addr[i];

ether_addr_copy()

> +
> +	/* 1-1 VID-FID mapping is already setup */
> +	mac_fid[ETH_ALEN] = fid;
> +	mac_fid[ETH_ALEN + 1] = 0;
> +
> +	fdb_slot = bitrev32(crc32_le(0, mac_fid, 8)) & PRUETH_SWITCH_FDB_MASK;
> +

> +	fid_c2 |= ICSSG_FDB_ENTRY_VALID;
> +	memcpy(&fdb_cmd.cmd_args[0], addr, 4);
> +	memcpy(&fdb_cmd.cmd_args[1], &addr[4], 2);
> +	fdb_cmd.cmd_args[1] |= ((fid << 16) | (fid_c2 << 24));
> +	fdb_cmd.cmd_args[2] = fdb_slot;

> +int icssg_fdb_lookup(struct prueth_emac *emac, const unsigned char *addr,
> +		     u8 vid)
> +{

> +	for (i = 0; i < ETH_ALEN; i++)
> +		mac_fid[i] = addr[i];
> +
> +	/* 1-1 VID-FID mapping is already setup */
> +	mac_fid[ETH_ALEN] = fid;
> +	mac_fid[ETH_ALEN + 1] = 0;

> +	memcpy(&fdb_cmd.cmd_args[0], addr, 4);
> +	memcpy(&fdb_cmd.cmd_args[1], &addr[4], 2);
> +	fdb_cmd.cmd_args[1] |= fid << 16;
> +	fdb_cmd.cmd_args[2] = fdb_slot;

Maybe add some helpers to reduce the amount of duplicated code?

      Andrew



More information about the linux-arm-kernel mailing list