From patchwork Mon Dec 9 12:38:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen-chien Jesse Sung X-Patchwork-Id: 299019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id D2EDB2C00AB for ; Mon, 9 Dec 2013 23:42:43 +1100 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1Vq0AU-0003qo-ND; Mon, 09 Dec 2013 12:42:34 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1Vq0AP-0003mT-ET for kernel-team@lists.ubuntu.com; Mon, 09 Dec 2013 12:42:29 +0000 Received: from [112.105.106.20] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Vq0AO-0006v5-Dc; Mon, 09 Dec 2013 12:42:29 +0000 From: Wen-chien Jesse Sung To: kernel-team@lists.ubuntu.com Subject: [Saucy][PATCH 1/6] be2net: fix MAC address modification for VF Date: Mon, 9 Dec 2013 20:38:51 +0800 Message-Id: <1386592736-5623-1-git-send-email-jesse.sung@canonical.com> X-Mailer: git-send-email 1.8.3.2 Cc: Sathya Perla , YK , Sureshkumar Reddy Reddygari X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Sathya Perla BugLink: https://launchpad.net/bugs/1257227 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: Sathya Perla Signed-off-by: David S. Miller (cherry picked from commit 5a712c13d3641a3bed243753f115434a7125e440) Signed-off-by: Wen-chien Jesse Sung --- drivers/net/ethernet/emulex/benet/be_cmds.c | 43 ++++++++++++++++--- drivers/net/ethernet/emulex/benet/be_cmds.h | 2 + drivers/net/ethernet/emulex/benet/be_main.c | 66 ++++++++++++++--------------- 3 files changed, 73 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c index 13ac104..c2592cc 100644 --- a/drivers/net/ethernet/emulex/benet/be_cmds.c +++ b/drivers/net/ethernet/emulex/benet/be_cmds.c @@ -2607,9 +2607,12 @@ err: 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, - 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_cmd_req_get_mac_list *req; @@ -2645,12 +2648,25 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, get_mac_list_cmd.size, wrb, &get_mac_list_cmd); req->hdr.domain = domain; 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); if (!status) { struct be_cmd_resp_get_mac_list *resp = 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 list returned could contain one or more active mac_ids * or one or more true or pseudo permanant mac addresses. @@ -2668,14 +2684,14 @@ int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, * is 6 bytes */ 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; *pmac_id = le32_to_cpu(mac_id); goto out; } } /* 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, ETH_ALEN); } @@ -2687,6 +2703,23 @@ out: 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 */ int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array, u8 mac_count, u32 domain) diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.h b/drivers/net/ethernet/emulex/benet/be_cmds.h index 1b3b9e8..7ef4d8f 100644 --- a/drivers/net/ethernet/emulex/benet/be_cmds.h +++ b/drivers/net/ethernet/emulex/benet/be_cmds.h @@ -1930,6 +1930,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, bool *pmac_id_active, u32 *pmac_id, 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, u8 mac_count, u32 domain); extern int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid, diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c index 3d91a5e..be4f1fe 100644 --- a/drivers/net/ethernet/emulex/benet/be_main.c +++ b/drivers/net/ethernet/emulex/benet/be_main.c @@ -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) { struct be_adapter *adapter = netdev_priv(netdev); + struct device *dev = &adapter->pdev->dev; struct sockaddr *addr = p; - int status = 0; - u8 current_mac[ETH_ALEN]; - u32 pmac_id = adapter->pmac_id[0]; - bool active_mac = true; + int status; + u8 mac[ETH_ALEN]; + u32 old_pmac_id = adapter->pmac_id[0], curr_pmac_id = 0; if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL; - /* For BE VF, MAC address is already activated by PF. - * Hence only operation left is updating netdev->devaddr. - * Update it if user is passing the same MAC which was used - * during configuring VF MAC from PF(Hypervisor). + /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT + * privilege or if PF did not provision the new MAC address. + * On BE3, this cmd will always fail if the VF doesn't have the + * 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_mac_addr_query(adapter, current_mac, - false, adapter->if_handle, 0); - if (!status && !memcmp(current_mac, addr->sa_data, ETH_ALEN)) - goto done; - else - goto err; - } + status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data, + adapter->if_handle, &adapter->pmac_id[0], 0); + if (!status) { + curr_pmac_id = adapter->pmac_id[0]; - if (!memcmp(addr->sa_data, netdev->dev_addr, ETH_ALEN)) - goto done; + /* Delete the old programmed MAC. This call may fail if the + * 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. - * If active, get its mac id. + /* Decide if the new MAC is successfully activated only after + * querying the FW */ - if (lancer_chip(adapter) && !be_physfn(adapter)) - 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); - + status = be_cmd_get_active_mac(adapter, curr_pmac_id, mac); if (status) goto err; - if (active_mac) - be_cmd_pmac_del(adapter, adapter->if_handle, - pmac_id, 0); -done: + /* The MAC change did not happen, either due to lack of privilege + * or PF didn't pre-provision. + */ + if (memcmp(addr->sa_data, mac, ETH_ALEN)) { + status = -EPERM; + goto err; + } + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); + dev_info(dev, "MAC address changed to %pM\n", mac); return 0; 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; }