target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl930x.c
static void rtl930x_host_route_read(int idx, struct rtl83xx_route *rt)
{
	u32 v;
	// Read L3_HOST_ROUTE_IPUC table (1) via register RTL9300_TBL_1
	struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 1);

	idx = ((idx / 6) * 8) + (idx % 6);

	pr_debug("In %s, physical index %d\n", __func__, idx);
	rtl_table_read(r, idx);
	// The table has a size of 5 (for UC, 11 for MC) registers
	v = sw_r32(rtl_table_data(r, 0));
	rt->attr.valid = !!(v & BIT(31));
	if (!rt->attr.valid)
		goto out;
	rt->attr.type = (v >> 29) & 0x3;
	switch (rt->attr.type) {
	case 0: // IPv4 Unicast route
		rt->dst_ip = sw_r32(rtl_table_data(r, 4));
		break;
	case 2: // IPv6 Unicast route
		ipv6_addr_set(&rt->dst_ip6,
			      sw_r32(rtl_table_data(r, 3)), sw_r32(rtl_table_data(r, 2)),
			      sw_r32(rtl_table_data(r, 1)), sw_r32(rtl_table_data(r, 0)));
		break;
	case 1: // IPv4 Multicast route
	case 3: // IPv6 Multicast route
		pr_warn("%s: route type not supported\n", __func__);
		goto out;
	}

	rt->attr.hit = !!(v & BIT(20));
	rt->attr.dst_null = !!(v & BIT(19));
	rt->attr.action = (v >> 17) & 3;
	rt->nh.id = (v >> 6) & 0x7ff;
	rt->attr.ttl_dec = !!(v & BIT(5));
	rt->attr.ttl_check = !!(v & BIT(4));
	rt->attr.qos_as = !!(v & BIT(3));
	rt->attr.qos_prio =  v & 0x7;
	pr_debug("%s: index %d is valid: %d\n", __func__, idx, rt->attr.valid);
	pr_debug("%s: next_hop: %d, hit: %d, action :%d, ttl_dec %d, ttl_check %d, dst_null %d\n",
		__func__, rt->nh.id, rt->attr.hit, rt->attr.action, rt->attr.ttl_dec, rt->attr.ttl_check,
		rt->attr.dst_null);
	pr_debug("%s: Destination: %pI4\n", __func__, &rt->dst_ip);

out:
	rtl_table_release(r);
}
/*
 * Read a host route entry from the table using its index
 * We currently only support IPv4 and IPv6 unicast route
 */
Read a host route entry from the table using its index
We currently only support IPv4 and IPv6 unicast route
Read a host route entry from the table using its index We currently only support IPv4 and IPv6 unicast route
static void rtl930x_host_route_read(int idx, struct rtl83xx_route *rt)
{
	u32 v;
	struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 1);
	idx = ((idx / 6) * 8) + (idx % 6);
	pr_debug("In %s, physical index %d\n", __func__, idx);
	rtl_table_read(r, idx);
	v = sw_r32(rtl_table_data(r, 0));
	rt->attr.valid = !!(v & BIT(31));
	if (!rt->attr.valid)
		goto out;
	rt->attr.type = (v >> 29) & 0x3;
	switch (rt->attr.type) {
	case 0: 
		rt->dst_ip = sw_r32(rtl_table_data(r, 4));
		break;
	case 2: 
		ipv6_addr_set(&rt->dst_ip6,
			      sw_r32(rtl_table_data(r, 3)), sw_r32(rtl_table_data(r, 2)),
			      sw_r32(rtl_table_data(r, 1)), sw_r32(rtl_table_data(r, 0)));
		break;
	case 1: 
	case 3: 
		pr_warn("%s: route type not supported\n", __func__);
		goto out;
	}
	rt->attr.hit = !!(v & BIT(20));
	rt->attr.dst_null = !!(v & BIT(19));
	rt->attr.action = (v >> 17) & 3;
	rt->nh.id = (v >> 6) & 0x7ff;
	rt->attr.ttl_dec = !!(v & BIT(5));
	rt->attr.ttl_check = !!(v & BIT(4));
	rt->attr.qos_as = !!(v & BIT(3));
	rt->attr.qos_prio =  v & 0x7;
	pr_debug("%s: index %d is valid: %d\n", __func__, idx, rt->attr.valid);
	pr_debug("%s: next_hop: %d, hit: %d, action :%d, ttl_dec %d, ttl_check %d, dst_null %d\n",
		__func__, rt->nh.id, rt->attr.hit, rt->attr.action, rt->attr.ttl_dec, rt->attr.ttl_check,
		rt->attr.dst_null);
	pr_debug("%s: Destination: %pI4\n", __func__, &rt->dst_ip);
out:
	rtl_table_release(r);
}
static void rtl930x_host_route_read ( int idx , struct rtl83xx_route * rt ) { u32 v ; struct table_reg * r = rtl_table_get ( RTL9300_TBL_1 , 1 ) ; idx = ( ( idx / 6 ) * 8 ) + ( idx % 6 ) ; pr_debug ( " \n " , __func__ , idx ) ; rtl_table_read ( r , idx ) ; v = sw_r32 ( rtl_table_data ( r , 0 ) ) ; rt -> attr . valid = ! ! ( v & BIT ( 31 ) ) ; if ( ! rt -> attr . valid ) goto out ; rt -> attr . type = ( v >> 29 ) & 0x3 ; switch ( rt -> attr . type ) { case 0 : rt -> dst_ip = sw_r32 ( rtl_table_data ( r , 4 ) ) ; break ; case 2 : ipv6_addr_set ( & rt -> dst_ip6 , sw_r32 ( rtl_table_data ( r , 3 ) ) , sw_r32 ( rtl_table_data ( r , 2 ) ) , sw_r32 ( rtl_table_data ( r , 1 ) ) , sw_r32 ( rtl_table_data ( r , 0 ) ) ) ; break ; case 1 : case 3 : pr_warn ( " \n " , __func__ ) ; goto out ; } rt -> attr . hit = ! ! ( v & BIT ( 20 ) ) ; rt -> attr . dst_null = ! ! ( v & BIT ( 19 ) ) ; rt -> attr . action = ( v >> 17 ) & 3 ; rt -> nh . id = ( v >> 6 ) & 0x7ff ; rt -> attr . ttl_dec = ! ! ( v & BIT ( 5 ) ) ; rt -> attr . ttl_check = ! ! ( v & BIT ( 4 ) ) ; rt -> attr . qos_as = ! ! ( v & BIT ( 3 ) ) ; rt -> attr . qos_prio = v & 0x7 ; pr_debug ( " \n " , __func__ , idx , rt -> attr . valid ) ; pr_debug ( " \n " , __func__ , rt -> nh . id , rt -> attr . hit , rt -> attr . action , rt -> attr . ttl_dec , rt -> attr . ttl_check , rt -> attr . dst_null ) ; pr_debug ( " \n " , __func__ , & rt -> dst_ip ) ; out : rtl_table_release ( r ) ; }
Read a host route entry from the table using its index
 We currently only support IPv4 and IPv6 unicast route
Read a host route entry from the table using its index We currently only support IPv4 and IPv6 unicast route
// Read L3_HOST_ROUTE_IPUC table (1) via register RTL9300_TBL_1 // The table has a size of 5 (for UC, 11 for MC) registers // IPv4 Unicast route // IPv6 Unicast route // IPv4 Multicast route // IPv6 Multicast route