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

MD Danish Anwar danishanwar at ti.com
Mon Jan 22 02:48:43 PST 2024



On 19/01/24 7:25 pm, Andrew Lunn wrote:
>> +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()

Sure.

> 
>> +
>> +	/* 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?
> 

Some codes are duplicated in icssg_fdb_add_del() and icssg_fdb_lookup().
I'll try to add helpers in next version to minimize this.

>       Andrew

-- 
Thanks and Regards,
Danish



More information about the linux-arm-kernel mailing list