Commit 5a712c13 authored by Sathya Perla's avatar Sathya Perla Committed by David S. Miller

be2net: fix MAC address modification for VF

Currently, the VFs by default don't have the privilege to modify MAC address.
This will change in a subsequent fix wherein VFs will have the ability to
modify MAC/VLAN filters.

Fix be_mac_addr_set() logic to support MAC address modification on a
privileged VF too.
Signed-off-by: default avatarSathya Perla <sathya.perla@emulex.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e18dbf7e
...@@ -2606,9 +2606,12 @@ int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege, ...@@ -2606,9 +2606,12 @@ int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
return status; return status;
} }
/* Uses synchronous MCCQ */ /* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
* pmac_id_valid: false => pmac_id or MAC address is requested.
* If pmac_id is returned, pmac_id_valid is returned as true
*/
int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
bool *pmac_id_active, u32 *pmac_id, u8 domain) bool *pmac_id_valid, u32 *pmac_id, u8 domain)
{ {
struct be_mcc_wrb *wrb; struct be_mcc_wrb *wrb;
struct be_cmd_req_get_mac_list *req; struct be_cmd_req_get_mac_list *req;
...@@ -2644,12 +2647,25 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, ...@@ -2644,12 +2647,25 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
get_mac_list_cmd.size, wrb, &get_mac_list_cmd); get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
req->hdr.domain = domain; req->hdr.domain = domain;
req->mac_type = MAC_ADDRESS_TYPE_NETWORK; req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
req->perm_override = 1; if (*pmac_id_valid) {
req->mac_id = cpu_to_le32(*pmac_id);
req->iface_id = cpu_to_le16(adapter->if_handle);
req->perm_override = 0;
} else {
req->perm_override = 1;
}
status = be_mcc_notify_wait(adapter); status = be_mcc_notify_wait(adapter);
if (!status) { if (!status) {
struct be_cmd_resp_get_mac_list *resp = struct be_cmd_resp_get_mac_list *resp =
get_mac_list_cmd.va; get_mac_list_cmd.va;
if (*pmac_id_valid) {
memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
ETH_ALEN);
goto out;
}
mac_count = resp->true_mac_count + resp->pseudo_mac_count; mac_count = resp->true_mac_count + resp->pseudo_mac_count;
/* Mac list returned could contain one or more active mac_ids /* Mac list returned could contain one or more active mac_ids
* or one or more true or pseudo permanant mac addresses. * or one or more true or pseudo permanant mac addresses.
...@@ -2667,14 +2683,14 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, ...@@ -2667,14 +2683,14 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
* is 6 bytes * is 6 bytes
*/ */
if (mac_addr_size == sizeof(u32)) { if (mac_addr_size == sizeof(u32)) {
*pmac_id_active = true; *pmac_id_valid = true;
mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id; mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
*pmac_id = le32_to_cpu(mac_id); *pmac_id = le32_to_cpu(mac_id);
goto out; goto out;
} }
} }
/* If no active mac_id found, return first mac addr */ /* If no active mac_id found, return first mac addr */
*pmac_id_active = false; *pmac_id_valid = false;
memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr, memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
ETH_ALEN); ETH_ALEN);
} }
...@@ -2686,6 +2702,23 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, ...@@ -2686,6 +2702,23 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
return status; return status;
} }
int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id, u8 *mac)
{
int status;
bool active = true;
/* When SH FW is ready, SH should use Lancer path too */
if (lancer_chip(adapter)) {
/* Fetch the MAC address using pmac_id */
status = be_cmd_get_mac_from_list(adapter, mac, &active,
&curr_pmac_id, 0);
return status;
} else {
return be_cmd_mac_addr_query(adapter, mac, false,
adapter->if_handle, curr_pmac_id);
}
}
/* Uses synchronous MCCQ */ /* Uses synchronous MCCQ */
int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array, int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
u8 mac_count, u32 domain) u8 mac_count, u32 domain)
......
...@@ -1924,6 +1924,8 @@ extern int be_cmd_get_fn_privileges(struct be_adapter *adapter, ...@@ -1924,6 +1924,8 @@ extern int be_cmd_get_fn_privileges(struct be_adapter *adapter,
extern int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, extern int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
bool *pmac_id_active, u32 *pmac_id, bool *pmac_id_active, u32 *pmac_id,
u8 domain); u8 domain);
extern int be_cmd_get_active_mac(struct be_adapter *adapter, u32 pmac_id,
u8 *mac);
extern int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array, extern int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
u8 mac_count, u32 domain); u8 mac_count, u32 domain);
extern int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid, extern int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
......
...@@ -247,54 +247,54 @@ void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped) ...@@ -247,54 +247,54 @@ void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped)
static int be_mac_addr_set(struct net_device *netdev, void *p) static int be_mac_addr_set(struct net_device *netdev, void *p)
{ {
struct be_adapter *adapter = netdev_priv(netdev); struct be_adapter *adapter = netdev_priv(netdev);
struct device *dev = &adapter->pdev->dev;
struct sockaddr *addr = p; struct sockaddr *addr = p;
int status = 0; int status;
u8 current_mac[ETH_ALEN]; u8 mac[ETH_ALEN];
u32 pmac_id = adapter->pmac_id[0]; u32 old_pmac_id = adapter->pmac_id[0], curr_pmac_id = 0;
bool active_mac = true;
if (!is_valid_ether_addr(addr->sa_data)) if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
/* For BE VF, MAC address is already activated by PF. /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT
* Hence only operation left is updating netdev->devaddr. * privilege or if PF did not provision the new MAC address.
* Update it if user is passing the same MAC which was used * On BE3, this cmd will always fail if the VF doesn't have the
* during configuring VF MAC from PF(Hypervisor). * FILTMGMT privilege. This failure is OK, only if the PF programmed
* the MAC for the VF.
*/ */
if (!lancer_chip(adapter) && !be_physfn(adapter)) { status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
status = be_cmd_mac_addr_query(adapter, current_mac, adapter->if_handle, &adapter->pmac_id[0], 0);
false, adapter->if_handle, 0); if (!status) {
if (!status && !memcmp(current_mac, addr->sa_data, ETH_ALEN)) curr_pmac_id = adapter->pmac_id[0];
goto done;
else
goto err;
}
if (!memcmp(addr->sa_data, netdev->dev_addr, ETH_ALEN)) /* Delete the old programmed MAC. This call may fail if the
goto done; * old MAC was already deleted by the PF driver.
*/
if (adapter->pmac_id[0] != old_pmac_id)
be_cmd_pmac_del(adapter, adapter->if_handle,
old_pmac_id, 0);
}
/* For Lancer check if any MAC is active. /* Decide if the new MAC is successfully activated only after
* If active, get its mac id. * querying the FW
*/ */
if (lancer_chip(adapter) && !be_physfn(adapter)) status = be_cmd_get_active_mac(adapter, curr_pmac_id, mac);
be_cmd_get_mac_from_list(adapter, current_mac, &active_mac,
&pmac_id, 0);
status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
adapter->if_handle,
&adapter->pmac_id[0], 0);
if (status) if (status)
goto err; goto err;
if (active_mac) /* The MAC change did not happen, either due to lack of privilege
be_cmd_pmac_del(adapter, adapter->if_handle, * or PF didn't pre-provision.
pmac_id, 0); */
done: if (memcmp(addr->sa_data, mac, ETH_ALEN)) {
status = -EPERM;
goto err;
}
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
dev_info(dev, "MAC address changed to %pM\n", mac);
return 0; return 0;
err: err:
dev_err(&adapter->pdev->dev, "MAC %pM set Failed\n", addr->sa_data); dev_warn(dev, "MAC address change to %pM failed\n", addr->sa_data);
return status; return status;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment