target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl930x.c
static void rtl930x_host_route_write(int idx, struct rtl83xx_route *rt)
{
	u32 v;
	// Access L3_HOST_ROUTE_IPUC table (1) via register RTL9300_TBL_1
	struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 1);
	// The table has a size of 5 (for UC, 11 for MC) registers

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

	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: GW: %pI4, prefix_len: %d\n", __func__, &rt->dst_ip, rt->prefix_len);

	v = BIT(31); // Entry is valid
	v |= (rt->attr.type & 0x3) << 29;
	v |= rt->attr.hit ? BIT(20) : 0;
	v |= rt->attr.dst_null ? BIT(19) : 0;
	v |= (rt->attr.action & 0x3) << 17;
	v |= (rt->nh.id & 0x7ff) << 6;
	v |= rt->attr.ttl_dec ? BIT(5) : 0;
	v |= rt->attr.ttl_check ? BIT(4) : 0;
	v |= rt->attr.qos_as ? BIT(3) : 0;
	v |= rt->attr.qos_prio & 0x7;

	sw_w32(v, rtl_table_data(r, 0));
	switch (rt->attr.type) {
	case 0: // IPv4 Unicast route
		sw_w32(0, rtl_table_data(r, 1));
		sw_w32(0, rtl_table_data(r, 2));
		sw_w32(0, rtl_table_data(r, 3));
		sw_w32(rt->dst_ip, rtl_table_data(r, 4));
		break;
	case 2: // IPv6 Unicast route
		sw_w32(rt->dst_ip6.s6_addr32[0], rtl_table_data(r, 1));
		sw_w32(rt->dst_ip6.s6_addr32[1], rtl_table_data(r, 2));
		sw_w32(rt->dst_ip6.s6_addr32[2], rtl_table_data(r, 3));
		sw_w32(rt->dst_ip6.s6_addr32[3], rtl_table_data(r, 4));
		break;
	case 1: // IPv4 Multicast route
	case 3: // IPv6 Multicast route
		pr_warn("%s: route type not supported\n", __func__);
		goto out;
	}

	rtl_table_write(r, idx);

out:
	rtl_table_release(r);
}
/*
 * Write a host route entry from the table using its index
 * We currently only support IPv4 and IPv6 unicast route
 */
Write a host route entry from the table using its index
We currently only support IPv4 and IPv6 unicast route
Write a host route entry from the table using its index We currently only support IPv4 and IPv6 unicast route
static void rtl930x_host_route_write(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("%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: GW: %pI4, prefix_len: %d\n", __func__, &rt->dst_ip, rt->prefix_len);
	v = BIT(31); 
	v |= (rt->attr.type & 0x3) << 29;
	v |= rt->attr.hit ? BIT(20) : 0;
	v |= rt->attr.dst_null ? BIT(19) : 0;
	v |= (rt->attr.action & 0x3) << 17;
	v |= (rt->nh.id & 0x7ff) << 6;
	v |= rt->attr.ttl_dec ? BIT(5) : 0;
	v |= rt->attr.ttl_check ? BIT(4) : 0;
	v |= rt->attr.qos_as ? BIT(3) : 0;
	v |= rt->attr.qos_prio & 0x7;
	sw_w32(v, rtl_table_data(r, 0));
	switch (rt->attr.type) {
	case 0: 
		sw_w32(0, rtl_table_data(r, 1));
		sw_w32(0, rtl_table_data(r, 2));
		sw_w32(0, rtl_table_data(r, 3));
		sw_w32(rt->dst_ip, rtl_table_data(r, 4));
		break;
	case 2: 
		sw_w32(rt->dst_ip6.s6_addr32[0], rtl_table_data(r, 1));
		sw_w32(rt->dst_ip6.s6_addr32[1], rtl_table_data(r, 2));
		sw_w32(rt->dst_ip6.s6_addr32[2], rtl_table_data(r, 3));
		sw_w32(rt->dst_ip6.s6_addr32[3], rtl_table_data(r, 4));
		break;
	case 1: 
	case 3: 
		pr_warn("%s: route type not supported\n", __func__);
		goto out;
	}
	rtl_table_write(r, idx);
out:
	rtl_table_release(r);
}
static void rtl930x_host_route_write ( 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 , 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 , rt -> prefix_len ) ; v = BIT ( 31 ) ; v |= ( rt -> attr . type & 0x3 ) << 29 ; v |= rt -> attr . hit ? BIT ( 20 ) : 0 ; v |= rt -> attr . dst_null ? BIT ( 19 ) : 0 ; v |= ( rt -> attr . action & 0x3 ) << 17 ; v |= ( rt -> nh . id & 0x7ff ) << 6 ; v |= rt -> attr . ttl_dec ? BIT ( 5 ) : 0 ; v |= rt -> attr . ttl_check ? BIT ( 4 ) : 0 ; v |= rt -> attr . qos_as ? BIT ( 3 ) : 0 ; v |= rt -> attr . qos_prio & 0x7 ; sw_w32 ( v , rtl_table_data ( r , 0 ) ) ; switch ( rt -> attr . type ) { case 0 : sw_w32 ( 0 , rtl_table_data ( r , 1 ) ) ; sw_w32 ( 0 , rtl_table_data ( r , 2 ) ) ; sw_w32 ( 0 , rtl_table_data ( r , 3 ) ) ; sw_w32 ( rt -> dst_ip , rtl_table_data ( r , 4 ) ) ; break ; case 2 : sw_w32 ( rt -> dst_ip6 . s6_addr32 [ 0 ] , rtl_table_data ( r , 1 ) ) ; sw_w32 ( rt -> dst_ip6 . s6_addr32 [ 1 ] , rtl_table_data ( r , 2 ) ) ; sw_w32 ( rt -> dst_ip6 . s6_addr32 [ 2 ] , rtl_table_data ( r , 3 ) ) ; sw_w32 ( rt -> dst_ip6 . s6_addr32 [ 3 ] , rtl_table_data ( r , 4 ) ) ; break ; case 1 : case 3 : pr_warn ( " \n " , __func__ ) ; goto out ; } rtl_table_write ( r , idx ) ; out : rtl_table_release ( r ) ; }
Write a host route entry from the table using its index
 We currently only support IPv4 and IPv6 unicast route
Write a host route entry from the table using its index We currently only support IPv4 and IPv6 unicast route
// Access L3_HOST_ROUTE_IPUC table (1) via register RTL9300_TBL_1 // The table has a size of 5 (for UC, 11 for MC) registers // Entry is valid // IPv4 Unicast route // IPv6 Unicast route // IPv4 Multicast route // IPv6 Multicast route