target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl931x.c
static u64 rtl931x_read_l2_entry_using_hash(u32 hash, u32 pos, struct rtl838x_l2_entry *e)
{
	u32 r[4];
	struct table_reg *q = rtl_table_get(RTL9310_TBL_0, 0);
	u32 idx;
	int i;
	u64 mac;
	u64 seed;

	pr_debug("%s: hash %08x, pos: %d\n", __func__, hash, pos);

	/* On the RTL93xx, 2 different hash algorithms are used making it a total of
	 * 8 buckets that need to be searched, 4 for each hash-half
	 * Use second hash space when bucket is between 4 and 8 */
	if (pos >= 4) {
		pos -= 4;
		hash >>= 16;
	} else {
		hash &= 0xffff;
	}

	idx = (0 << 14) | (hash << 2) | pos; // Search SRAM, with hash and at pos in bucket
	pr_debug("%s: NOW hash %08x, pos: %d\n", __func__, hash, pos);

	rtl_table_read(q, idx);
	for (i = 0; i < 4; i++)
		r[i] = sw_r32(rtl_table_data(q, i));

	rtl_table_release(q);

	rtl931x_fill_l2_entry(r, e);

	pr_debug("%s: valid: %d, nh: %d\n", __func__, e->valid, e->next_hop);
	if (!e->valid)
		return 0;

	mac = ((u64)e->mac[0]) << 40 | ((u64)e->mac[1]) << 32 | ((u64)e->mac[2]) << 24
		| ((u64)e->mac[3]) << 16 | ((u64)e->mac[4]) << 8 | ((u64)e->mac[5]);

	seed = rtl931x_l2_hash_seed(mac, e->rvid);
	pr_debug("%s: mac %016llx, seed %016llx\n", __func__, mac, seed);
	// return vid with concatenated mac as unique id
	return seed;
}
/*
 * Read an L2 UC or MC entry out of a hash bucket of the L2 forwarding table
 * hash is the id of the bucket and pos is the position of the entry in that bucket
 * The data read from the SoC is filled into rtl838x_l2_entry
 */
Read an L2 UC or MC entry out of a hash bucket of the L2 forwarding table
hash is the id of the bucket and pos is the position of the entry in that bucket
The data read from the SoC is filled into rtl838x_l2_entry
Read an L2 UC or MC entry out of a hash bucket of the L2 forwarding table hash is the id of the bucket and pos is the position of the entry in that bucket The data read from the SoC is filled into rtl838x_l2_entry
static u64 rtl931x_read_l2_entry_using_hash(u32 hash, u32 pos, struct rtl838x_l2_entry *e)
{
	u32 r[4];
	struct table_reg *q = rtl_table_get(RTL9310_TBL_0, 0);
	u32 idx;
	int i;
	u64 mac;
	u64 seed;
	pr_debug("%s: hash %08x, pos: %d\n", __func__, hash, pos);
	if (pos >= 4) {
		pos -= 4;
		hash >>= 16;
	} else {
		hash &= 0xffff;
	}
	idx = (0 << 14) | (hash << 2) | pos; 
	pr_debug("%s: NOW hash %08x, pos: %d\n", __func__, hash, pos);
	rtl_table_read(q, idx);
	for (i = 0; i < 4; i++)
		r[i] = sw_r32(rtl_table_data(q, i));
	rtl_table_release(q);
	rtl931x_fill_l2_entry(r, e);
	pr_debug("%s: valid: %d, nh: %d\n", __func__, e->valid, e->next_hop);
	if (!e->valid)
		return 0;
	mac = ((u64)e->mac[0]) << 40 | ((u64)e->mac[1]) << 32 | ((u64)e->mac[2]) << 24
		| ((u64)e->mac[3]) << 16 | ((u64)e->mac[4]) << 8 | ((u64)e->mac[5]);
	seed = rtl931x_l2_hash_seed(mac, e->rvid);
	pr_debug("%s: mac %016llx, seed %016llx\n", __func__, mac, seed);
	return seed;
}
static u64 rtl931x_read_l2_entry_using_hash ( u32 hash , u32 pos , struct rtl838x_l2_entry * e ) { u32 r [ 4 ] ; struct table_reg * q = rtl_table_get ( RTL9310_TBL_0 , 0 ) ; u32 idx ; int i ; u64 mac ; u64 seed ; pr_debug ( " \n " , __func__ , hash , pos ) ; if ( pos >= 4 ) { pos -= 4 ; hash >>= 16 ; } else { hash &= 0xffff ; } idx = ( 0 << 14 ) | ( hash << 2 ) | pos ; pr_debug ( " \n " , __func__ , hash , pos ) ; rtl_table_read ( q , idx ) ; for ( i = 0 ; i < 4 ; i ++ ) r [ i ] = sw_r32 ( rtl_table_data ( q , i ) ) ; rtl_table_release ( q ) ; rtl931x_fill_l2_entry ( r , e ) ; pr_debug ( " \n " , __func__ , e -> valid , e -> next_hop ) ; if ( ! e -> valid ) return 0 ; mac = ( ( u64 ) e -> mac [ 0 ] ) << 40 | ( ( u64 ) e -> mac [ 1 ] ) << 32 | ( ( u64 ) e -> mac [ 2 ] ) << 24 | ( ( u64 ) e -> mac [ 3 ] ) << 16 | ( ( u64 ) e -> mac [ 4 ] ) << 8 | ( ( u64 ) e -> mac [ 5 ] ) ; seed = rtl931x_l2_hash_seed ( mac , e -> rvid ) ; pr_debug ( " \n " , __func__ , mac , seed ) ; return seed ; }
Read an L2 UC or MC entry out of a hash bucket of the L2 forwarding table
 hash is the id of the bucket and pos is the position of the entry in that bucket
 The data read from the SoC is filled into rtl838x_l2_entry
Read an L2 UC or MC entry out of a hash bucket of the L2 forwarding table hash is the id of the bucket and pos is the position of the entry in that bucket The data read from the SoC is filled into rtl838x_l2_entry
/* On the RTL93xx, 2 different hash algorithms are used making it a total of
	 * 8 buckets that need to be searched, 4 for each hash-half
	 * Use second hash space when bucket is between 4 and 8 */ // Search SRAM, with hash and at pos in bucket // return vid with concatenated mac as unique id