igb: Add support for MAC address filters specifying source addresses
authorVinicius Costa Gomes <vinicius.gomes@intel.com>
Tue, 10 Apr 2018 17:49:53 +0000 (10:49 -0700)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Wed, 25 Apr 2018 17:35:13 +0000 (10:35 -0700)
Makes it possible to direct packets to queues based on their source
address. Documents the expected usage of the 'flags' parameter.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/igb/e1000_defines.h
drivers/net/ethernet/intel/igb/igb.h
drivers/net/ethernet/intel/igb/igb_main.c

index 98534f765e0eae25e2975cbc027fec0831d44583..5417edbe31252e03cd9742831a276617f620c6ae 100644 (file)
  * manageability enabled, allowing us room for 15 multicast addresses.
  */
 #define E1000_RAH_AV  0x80000000        /* Receive descriptor valid */
+#define E1000_RAH_ASEL_SRC_ADDR 0x00010000
 #define E1000_RAL_MAC_ADDR_LEN 4
 #define E1000_RAH_MAC_ADDR_LEN 2
 #define E1000_RAH_POOL_MASK 0x03FC0000
index 8dbc399b345e54903cb0bf0704367a0ca57f8c64..1ff58f7a5c7d61e36433690c55a83bb4387e575f 100644 (file)
@@ -474,6 +474,7 @@ struct igb_mac_addr {
 
 #define IGB_MAC_STATE_DEFAULT  0x1
 #define IGB_MAC_STATE_IN_USE   0x2
+#define IGB_MAC_STATE_SRC_ADDR 0x4
 
 /* board specific private data structure */
 struct igb_adapter {
index 0facaa73f6261f1616f375ecb6dbcf80a22b9c20..902db2096bfdb76dcfba1ca3e237737ee988f349 100644 (file)
@@ -6859,8 +6859,14 @@ static void igb_set_default_mac_filter(struct igb_adapter *adapter)
        igb_rar_set_index(adapter, 0);
 }
 
-static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
-                             const u8 queue)
+/* Add a MAC filter for 'addr' directing matching traffic to 'queue',
+ * 'flags' is used to indicate what kind of match is made, match is by
+ * default for the destination address, if matching by source address
+ * is desired the flag IGB_MAC_STATE_SRC_ADDR can be used.
+ */
+static int igb_add_mac_filter_flags(struct igb_adapter *adapter,
+                                   const u8 *addr, const u8 queue,
+                                   const u8 flags)
 {
        struct e1000_hw *hw = &adapter->hw;
        int rar_entries = hw->mac.rar_entry_count -
@@ -6880,7 +6886,7 @@ static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
 
                ether_addr_copy(adapter->mac_table[i].addr, addr);
                adapter->mac_table[i].queue = queue;
-               adapter->mac_table[i].state |= IGB_MAC_STATE_IN_USE;
+               adapter->mac_table[i].state |= IGB_MAC_STATE_IN_USE | flags;
 
                igb_rar_set_index(adapter, i);
                return i;
@@ -6889,8 +6895,21 @@ static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
        return -ENOSPC;
 }
 
-static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
+static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
                              const u8 queue)
+{
+       return igb_add_mac_filter_flags(adapter, addr, queue, 0);
+}
+
+/* Remove a MAC filter for 'addr' directing matching traffic to
+ * 'queue', 'flags' is used to indicate what kind of match need to be
+ * removed, match is by default for the destination address, if
+ * matching by source address is to be removed the flag
+ * IGB_MAC_STATE_SRC_ADDR can be used.
+ */
+static int igb_del_mac_filter_flags(struct igb_adapter *adapter,
+                                   const u8 *addr, const u8 queue,
+                                   const u8 flags)
 {
        struct e1000_hw *hw = &adapter->hw;
        int rar_entries = hw->mac.rar_entry_count -
@@ -6907,12 +6926,14 @@ static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
        for (i = 0; i < rar_entries; i++) {
                if (!(adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE))
                        continue;
+               if ((adapter->mac_table[i].state & flags) != flags)
+                       continue;
                if (adapter->mac_table[i].queue != queue)
                        continue;
                if (!ether_addr_equal(adapter->mac_table[i].addr, addr))
                        continue;
 
-               adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
+               adapter->mac_table[i].state = 0;
                memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
                adapter->mac_table[i].queue = 0;
 
@@ -6923,6 +6944,12 @@ static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
        return -ENOENT;
 }
 
+static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
+                             const u8 queue)
+{
+       return igb_del_mac_filter_flags(adapter, addr, queue, 0);
+}
+
 static int igb_uc_sync(struct net_device *netdev, const unsigned char *addr)
 {
        struct igb_adapter *adapter = netdev_priv(netdev);
@@ -8766,6 +8793,9 @@ static void igb_rar_set_index(struct igb_adapter *adapter, u32 index)
                if (is_valid_ether_addr(addr))
                        rar_high |= E1000_RAH_AV;
 
+               if (adapter->mac_table[index].state & IGB_MAC_STATE_SRC_ADDR)
+                       rar_high |= E1000_RAH_ASEL_SRC_ADDR;
+
                switch (hw->mac.type) {
                case e1000_82575:
                case e1000_i210: