realtek: Add Link Aggregation (aka trunking) support
[openwrt/staging/chunkeey.git] / target / linux / realtek / files-5.10 / drivers / net / dsa / rtl83xx / rtl930x.c
index 04be44fc90cbd14a974b48ee7b0cee82020d034a..c7fb319229ab0cc80b38d981a3fece7cdd159ec3 100644 (file)
@@ -2344,6 +2344,46 @@ static void rtl930x_set_egr_filter(int port,  enum egr_filter state)
                    RTL930X_VLAN_PORT_EGR_FLTR + (((port / 29) << 2)));
 }
 
+void rtl930x_set_distribution_algorithm(int group, int algoidx, u32 algomsk)
+{
+       u32 l3shift = 0;
+       u32 newmask = 0;
+
+       /* TODO: for now we set algoidx to 0 */
+       algoidx = 0;
+       if (algomsk & TRUNK_DISTRIBUTION_ALGO_SIP_BIT) {
+               l3shift = 4;
+               newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SIP_BIT;
+       }
+       if (algomsk & TRUNK_DISTRIBUTION_ALGO_DIP_BIT) {
+               l3shift = 4;
+               newmask |= TRUNK_DISTRIBUTION_ALGO_L3_DIP_BIT;
+       }
+       if (algomsk & TRUNK_DISTRIBUTION_ALGO_SRC_L4PORT_BIT) {
+               l3shift = 4;
+               newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SRC_L4PORT_BIT;
+       }
+       if (algomsk & TRUNK_DISTRIBUTION_ALGO_SRC_L4PORT_BIT) {
+               l3shift = 4;
+               newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SRC_L4PORT_BIT;
+       }
+
+       if (l3shift == 4) {
+               if (algomsk & TRUNK_DISTRIBUTION_ALGO_SMAC_BIT)
+                       newmask |= TRUNK_DISTRIBUTION_ALGO_L3_SMAC_BIT;
+
+               if (algomsk & TRUNK_DISTRIBUTION_ALGO_DMAC_BIT)
+                       newmask |= TRUNK_DISTRIBUTION_ALGO_L3_DMAC_BIT;
+       } else  {
+               if (algomsk & TRUNK_DISTRIBUTION_ALGO_SMAC_BIT)
+                       newmask |= TRUNK_DISTRIBUTION_ALGO_L2_SMAC_BIT;
+               if (algomsk & TRUNK_DISTRIBUTION_ALGO_DMAC_BIT)
+                       newmask |= TRUNK_DISTRIBUTION_ALGO_L2_DMAC_BIT;
+       }
+
+       sw_w32(newmask << l3shift, RTL930X_TRK_HASH_CTRL + (algoidx << 2));
+}
+
 const struct rtl838x_reg rtl930x_reg = {
        .mask_port_reg_be = rtl838x_mask_port_reg,
        .set_port_reg_be = rtl838x_set_port_reg,
@@ -2428,4 +2468,5 @@ const struct rtl838x_reg rtl930x_reg = {
        .get_l3_router_mac = rtl930x_get_l3_router_mac,
        .set_l3_router_mac = rtl930x_set_l3_router_mac,
        .set_l3_egress_intf = rtl930x_set_l3_egress_intf,
+       .set_distribution_algorithm = rtl930x_set_distribution_algorithm,
 };