be2net: refactor MAC-addr setup code
authorSathya Perla <sathya.perla@emulex.com>
Tue, 23 Jul 2013 09:55:02 +0000 (15:25 +0530)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Jul 2013 22:41:52 +0000 (15:41 -0700)
The code to configure the permanent MAC in be_setup() has become quite
complicated, with different FW cmds being used for BEx, SH-R and Lancer.
Simplify the logic by moving some of this complexity to be_cmds.c. This
makes the code in be_setup() a little more readable.

Signed-off-by: Sathya Perla <sathya.perla@emulex.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/emulex/benet/be_cmds.c
drivers/net/ethernet/emulex/benet/be_cmds.h
drivers/net/ethernet/emulex/benet/be_main.c

index b384ae7c9da557a2628c37850bc5d120463ab30d..f4ee94eb0c1951abda13b5402354530da44a43d5 100644 (file)
@@ -2755,6 +2755,24 @@ int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id, u8 *mac)
        }
 }
 
+int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
+{
+       int status;
+       bool pmac_valid = false;
+
+       memset(mac, 0, ETH_ALEN);
+
+       if (lancer_chip(adapter))
+               status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
+                                                 NULL, 0);
+       else if (be_physfn(adapter))
+               status = be_cmd_mac_addr_query(adapter, mac, true, 0, 0);
+       else
+               status = be_cmd_mac_addr_query(adapter, mac, false,
+                                              adapter->if_handle, 0);
+       return status;
+}
+
 /* Uses synchronous MCCQ */
 int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
                        u8 mac_count, u32 domain)
index 671a89d84f98ebc046a714ddcc1f5ed51b6cc205..5e9e2b0e920a9573d534b57dbe570dda4d84adfc 100644 (file)
@@ -1934,6 +1934,7 @@ extern int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
                                    u8 domain);
 extern int be_cmd_get_active_mac(struct be_adapter *adapter, u32 pmac_id,
                                 u8 *mac);
+extern int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac);
 extern int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
                                                u8 mac_count, u32 domain);
 extern int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
index 858bb473bd42c45cce55c3df9f29d379e329c1f7..73b0009c99fb7326dd55e66a20e592a377df10d3 100644 (file)
@@ -2759,7 +2759,7 @@ static int be_vfs_mac_query(struct be_adapter *adapter)
        int status, vf;
        u8 mac[ETH_ALEN];
        struct be_vf_cfg *vf_cfg;
-       bool active;
+       bool active = false;
 
        for_all_vfs(adapter, vf_cfg, vf) {
                be_cmd_get_mac_from_list(adapter, mac, &active,
@@ -2984,41 +2984,6 @@ static void be_setup_init(struct be_adapter *adapter)
                adapter->cmd_privileges = MIN_PRIVILEGES;
 }
 
-static int be_get_mac_addr(struct be_adapter *adapter, u8 *mac, u32 if_handle,
-                          bool *active_mac, u32 *pmac_id)
-{
-       int status = 0;
-
-       if (!is_zero_ether_addr(adapter->netdev->perm_addr)) {
-               memcpy(mac, adapter->netdev->dev_addr, ETH_ALEN);
-               if (!lancer_chip(adapter) && !be_physfn(adapter))
-                       *active_mac = true;
-               else
-                       *active_mac = false;
-
-               return status;
-       }
-
-       if (lancer_chip(adapter)) {
-               status = be_cmd_get_mac_from_list(adapter, mac,
-                                                 active_mac, pmac_id, 0);
-               if (*active_mac) {
-                       status = be_cmd_mac_addr_query(adapter, mac, false,
-                                                      if_handle, *pmac_id);
-               }
-       } else if (be_physfn(adapter)) {
-               /* For BE3, for PF get permanent MAC */
-               status = be_cmd_mac_addr_query(adapter, mac, true, 0, 0);
-               *active_mac = false;
-       } else {
-               /* For BE3, for VF get soft MAC assigned by PF*/
-               status = be_cmd_mac_addr_query(adapter, mac, false,
-                                              if_handle, 0);
-               *active_mac = true;
-       }
-       return status;
-}
-
 static void be_get_resources(struct be_adapter *adapter)
 {
        u16 dev_num_vfs;
@@ -3124,14 +3089,38 @@ err:
        return status;
 }
 
+static int be_mac_setup(struct be_adapter *adapter)
+{
+       u8 mac[ETH_ALEN];
+       int status;
+
+       if (is_zero_ether_addr(adapter->netdev->dev_addr)) {
+               status = be_cmd_get_perm_mac(adapter, mac);
+               if (status)
+                       return status;
+
+               memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
+               memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
+       } else {
+               /* Maybe the HW was reset; dev_addr must be re-programmed */
+               memcpy(mac, adapter->netdev->dev_addr, ETH_ALEN);
+       }
+
+       /* On BE3 VFs this cmd may fail due to lack of privilege.
+        * Ignore the failure as in this case pmac_id is fetched
+        * in the IFACE_CREATE cmd.
+        */
+       be_cmd_pmac_add(adapter, mac, adapter->if_handle,
+                       &adapter->pmac_id[0], 0);
+       return 0;
+}
+
 static int be_setup(struct be_adapter *adapter)
 {
        struct device *dev = &adapter->pdev->dev;
        u32 en_flags;
        u32 tx_fc, rx_fc;
        int status;
-       u8 mac[ETH_ALEN];
-       bool active_mac;
 
        be_setup_init(adapter);
 
@@ -3171,36 +3160,18 @@ static int be_setup(struct be_adapter *adapter)
 
        en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
                        BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS;
-
        if (adapter->function_caps & BE_FUNCTION_CAPS_RSS)
                en_flags |= BE_IF_FLAGS_RSS;
-
        en_flags = en_flags & adapter->if_cap_flags;
-
        status = be_cmd_if_create(adapter, adapter->if_cap_flags, en_flags,
                                  &adapter->if_handle, 0);
        if (status != 0)
                goto err;
 
-       memset(mac, 0, ETH_ALEN);
-       active_mac = false;
-       status = be_get_mac_addr(adapter, mac, adapter->if_handle,
-                                &active_mac, &adapter->pmac_id[0]);
-       if (status != 0)
+       status = be_mac_setup(adapter);
+       if (status)
                goto err;
 
-       if (!active_mac) {
-               status = be_cmd_pmac_add(adapter, mac, adapter->if_handle,
-                                        &adapter->pmac_id[0], 0);
-               if (status != 0)
-                       goto err;
-       }
-
-       if (is_zero_ether_addr(adapter->netdev->dev_addr)) {
-               memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
-               memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
-       }
-
        status = be_tx_qs_create(adapter);
        if (status)
                goto err;