net: lan966x: Add function lan966x_mac_ip_learn()
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Tue, 4 Jan 2022 15:33:36 +0000 (16:33 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 5 Jan 2022 11:25:13 +0000 (11:25 +0000)
Extend mac functionality with the function lan966x_mac_ip_learn. This
function adds an entry in the MAC table for IP multicast addresses.
These entries can copy a frame to the CPU but also can forward on the
front ports.
This functionality is needed for mdb support. In case the CPU and some
of the front ports subscribe to an IP multicast address.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/microchip/lan966x/lan966x_mac.c
drivers/net/ethernet/microchip/lan966x/lan966x_main.h
drivers/net/ethernet/microchip/lan966x/lan966x_regs.h

index efadb8d..ca5f117 100644 (file)
@@ -68,17 +68,19 @@ static void lan966x_mac_select(struct lan966x *lan966x,
        lan_wr(mach, lan966x, ANA_MACHDATA);
 }
 
-int lan966x_mac_learn(struct lan966x *lan966x, int port,
-                     const unsigned char mac[ETH_ALEN],
-                     unsigned int vid,
-                     enum macaccess_entry_type type)
+static int __lan966x_mac_learn(struct lan966x *lan966x, int pgid,
+                              bool cpu_copy,
+                              const unsigned char mac[ETH_ALEN],
+                              unsigned int vid,
+                              enum macaccess_entry_type type)
 {
        lan966x_mac_select(lan966x, mac, vid);
 
        /* Issue a write command */
        lan_wr(ANA_MACACCESS_VALID_SET(1) |
               ANA_MACACCESS_CHANGE2SW_SET(0) |
-              ANA_MACACCESS_DEST_IDX_SET(port) |
+              ANA_MACACCESS_MAC_CPU_COPY_SET(cpu_copy) |
+              ANA_MACACCESS_DEST_IDX_SET(pgid) |
               ANA_MACACCESS_ENTRYTYPE_SET(type) |
               ANA_MACACCESS_MAC_TABLE_CMD_SET(MACACCESS_CMD_LEARN),
               lan966x, ANA_MACACCESS);
@@ -86,6 +88,30 @@ int lan966x_mac_learn(struct lan966x *lan966x, int port,
        return lan966x_mac_wait_for_completion(lan966x);
 }
 
+/* The mask of the front ports is encoded inside the mac parameter via a call
+ * to lan966x_mdb_encode_mac().
+ */
+int lan966x_mac_ip_learn(struct lan966x *lan966x,
+                        bool cpu_copy,
+                        const unsigned char mac[ETH_ALEN],
+                        unsigned int vid,
+                        enum macaccess_entry_type type)
+{
+       WARN_ON(type != ENTRYTYPE_MACV4 && type != ENTRYTYPE_MACV6);
+
+       return __lan966x_mac_learn(lan966x, 0, cpu_copy, mac, vid, type);
+}
+
+int lan966x_mac_learn(struct lan966x *lan966x, int port,
+                     const unsigned char mac[ETH_ALEN],
+                     unsigned int vid,
+                     enum macaccess_entry_type type)
+{
+       WARN_ON(type != ENTRYTYPE_NORMAL && type != ENTRYTYPE_LOCKED);
+
+       return __lan966x_mac_learn(lan966x, port, false, mac, vid, type);
+}
+
 int lan966x_mac_forget(struct lan966x *lan966x,
                       const unsigned char mac[ETH_ALEN],
                       unsigned int vid,
index c399b12..f70e545 100644 (file)
@@ -157,6 +157,11 @@ int lan966x_port_pcs_set(struct lan966x_port *port,
                         struct lan966x_port_config *config);
 void lan966x_port_init(struct lan966x_port *port);
 
+int lan966x_mac_ip_learn(struct lan966x *lan966x,
+                        bool cpu_copy,
+                        const unsigned char mac[ETH_ALEN],
+                        unsigned int vid,
+                        enum macaccess_entry_type type);
 int lan966x_mac_learn(struct lan966x *lan966x, int port,
                      const unsigned char mac[ETH_ALEN],
                      unsigned int vid,
index a13c469..7975601 100644 (file)
@@ -169,6 +169,12 @@ enum lan966x_target {
 #define ANA_MACACCESS_CHANGE2SW_GET(x)\
        FIELD_GET(ANA_MACACCESS_CHANGE2SW, x)
 
+#define ANA_MACACCESS_MAC_CPU_COPY               BIT(16)
+#define ANA_MACACCESS_MAC_CPU_COPY_SET(x)\
+       FIELD_PREP(ANA_MACACCESS_MAC_CPU_COPY, x)
+#define ANA_MACACCESS_MAC_CPU_COPY_GET(x)\
+       FIELD_GET(ANA_MACACCESS_MAC_CPU_COPY, x)
+
 #define ANA_MACACCESS_VALID                      BIT(12)
 #define ANA_MACACCESS_VALID_SET(x)\
        FIELD_PREP(ANA_MACACCESS_VALID, x)