18c2ecf20Sopenharmony_ci/* Broadcom NetXtreme-C/E network driver. 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016 Broadcom Corporation 48c2ecf20Sopenharmony_ci * Copyright (c) 2016-2018 Broadcom Limited 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 78c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 88c2ecf20Sopenharmony_ci * the Free Software Foundation. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <linux/pci.h> 138c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 148c2ecf20Sopenharmony_ci#include <linux/if_vlan.h> 158c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 168c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 178c2ecf20Sopenharmony_ci#include "bnxt_hsi.h" 188c2ecf20Sopenharmony_ci#include "bnxt.h" 198c2ecf20Sopenharmony_ci#include "bnxt_ulp.h" 208c2ecf20Sopenharmony_ci#include "bnxt_sriov.h" 218c2ecf20Sopenharmony_ci#include "bnxt_vfr.h" 228c2ecf20Sopenharmony_ci#include "bnxt_ethtool.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#ifdef CONFIG_BNXT_SRIOV 258c2ecf20Sopenharmony_cistatic int bnxt_hwrm_fwd_async_event_cmpl(struct bnxt *bp, 268c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf, u16 event_id) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci struct hwrm_fwd_async_event_cmpl_input req = {0}; 298c2ecf20Sopenharmony_ci struct hwrm_async_event_cmpl *async_cmpl; 308c2ecf20Sopenharmony_ci int rc = 0; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FWD_ASYNC_EVENT_CMPL, -1, -1); 338c2ecf20Sopenharmony_ci if (vf) 348c2ecf20Sopenharmony_ci req.encap_async_event_target_id = cpu_to_le16(vf->fw_fid); 358c2ecf20Sopenharmony_ci else 368c2ecf20Sopenharmony_ci /* broadcast this async event to all VFs */ 378c2ecf20Sopenharmony_ci req.encap_async_event_target_id = cpu_to_le16(0xffff); 388c2ecf20Sopenharmony_ci async_cmpl = (struct hwrm_async_event_cmpl *)req.encap_async_event_cmpl; 398c2ecf20Sopenharmony_ci async_cmpl->type = cpu_to_le16(ASYNC_EVENT_CMPL_TYPE_HWRM_ASYNC_EVENT); 408c2ecf20Sopenharmony_ci async_cmpl->event_id = cpu_to_le16(event_id); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 438c2ecf20Sopenharmony_ci if (rc) 448c2ecf20Sopenharmony_ci netdev_err(bp->dev, "hwrm_fwd_async_event_cmpl failed. rc:%d\n", 458c2ecf20Sopenharmony_ci rc); 468c2ecf20Sopenharmony_ci return rc; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic int bnxt_vf_ndo_prep(struct bnxt *bp, int vf_id) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { 528c2ecf20Sopenharmony_ci netdev_err(bp->dev, "vf ndo called though PF is down\n"); 538c2ecf20Sopenharmony_ci return -EINVAL; 548c2ecf20Sopenharmony_ci } 558c2ecf20Sopenharmony_ci if (!bp->pf.active_vfs) { 568c2ecf20Sopenharmony_ci netdev_err(bp->dev, "vf ndo called though sriov is disabled\n"); 578c2ecf20Sopenharmony_ci return -EINVAL; 588c2ecf20Sopenharmony_ci } 598c2ecf20Sopenharmony_ci if (vf_id >= bp->pf.active_vfs) { 608c2ecf20Sopenharmony_ci netdev_err(bp->dev, "Invalid VF id %d\n", vf_id); 618c2ecf20Sopenharmony_ci return -EINVAL; 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci return 0; 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciint bnxt_set_vf_spoofchk(struct net_device *dev, int vf_id, bool setting) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 698c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 708c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 718c2ecf20Sopenharmony_ci bool old_setting = false; 728c2ecf20Sopenharmony_ci u32 func_flags; 738c2ecf20Sopenharmony_ci int rc; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci if (bp->hwrm_spec_code < 0x10701) 768c2ecf20Sopenharmony_ci return -ENOTSUPP; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci rc = bnxt_vf_ndo_prep(bp, vf_id); 798c2ecf20Sopenharmony_ci if (rc) 808c2ecf20Sopenharmony_ci return rc; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 838c2ecf20Sopenharmony_ci if (vf->flags & BNXT_VF_SPOOFCHK) 848c2ecf20Sopenharmony_ci old_setting = true; 858c2ecf20Sopenharmony_ci if (old_setting == setting) 868c2ecf20Sopenharmony_ci return 0; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci if (setting) 898c2ecf20Sopenharmony_ci func_flags = FUNC_CFG_REQ_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE; 908c2ecf20Sopenharmony_ci else 918c2ecf20Sopenharmony_ci func_flags = FUNC_CFG_REQ_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE; 928c2ecf20Sopenharmony_ci /*TODO: if the driver supports VLAN filter on guest VLAN, 938c2ecf20Sopenharmony_ci * the spoof check should also include vlan anti-spoofing 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 968c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 978c2ecf20Sopenharmony_ci req.flags = cpu_to_le32(func_flags); 988c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 998c2ecf20Sopenharmony_ci if (!rc) { 1008c2ecf20Sopenharmony_ci if (setting) 1018c2ecf20Sopenharmony_ci vf->flags |= BNXT_VF_SPOOFCHK; 1028c2ecf20Sopenharmony_ci else 1038c2ecf20Sopenharmony_ci vf->flags &= ~BNXT_VF_SPOOFCHK; 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci return rc; 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic int bnxt_hwrm_func_qcfg_flags(struct bnxt *bp, struct bnxt_vf_info *vf) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; 1118c2ecf20Sopenharmony_ci struct hwrm_func_qcfg_input req = {0}; 1128c2ecf20Sopenharmony_ci int rc; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); 1158c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 1168c2ecf20Sopenharmony_ci mutex_lock(&bp->hwrm_cmd_lock); 1178c2ecf20Sopenharmony_ci rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1188c2ecf20Sopenharmony_ci if (rc) { 1198c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 1208c2ecf20Sopenharmony_ci return rc; 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci vf->func_qcfg_flags = le16_to_cpu(resp->flags); 1238c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 1248c2ecf20Sopenharmony_ci return 0; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic bool bnxt_is_trusted_vf(struct bnxt *bp, struct bnxt_vf_info *vf) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci if (!(bp->fw_cap & BNXT_FW_CAP_TRUSTED_VF)) 1308c2ecf20Sopenharmony_ci return !!(vf->flags & BNXT_VF_TRUST); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci bnxt_hwrm_func_qcfg_flags(bp, vf); 1338c2ecf20Sopenharmony_ci return !!(vf->func_qcfg_flags & FUNC_QCFG_RESP_FLAGS_TRUSTED_VF); 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic int bnxt_hwrm_set_trusted_vf(struct bnxt *bp, struct bnxt_vf_info *vf) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci if (!(bp->fw_cap & BNXT_FW_CAP_TRUSTED_VF)) 1418c2ecf20Sopenharmony_ci return 0; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 1448c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 1458c2ecf20Sopenharmony_ci if (vf->flags & BNXT_VF_TRUST) 1468c2ecf20Sopenharmony_ci req.flags = cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_ENABLE); 1478c2ecf20Sopenharmony_ci else 1488c2ecf20Sopenharmony_ci req.flags = cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_DISABLE); 1498c2ecf20Sopenharmony_ci return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1508c2ecf20Sopenharmony_ci} 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ciint bnxt_set_vf_trust(struct net_device *dev, int vf_id, bool trusted) 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 1558c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci if (bnxt_vf_ndo_prep(bp, vf_id)) 1588c2ecf20Sopenharmony_ci return -EINVAL; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 1618c2ecf20Sopenharmony_ci if (trusted) 1628c2ecf20Sopenharmony_ci vf->flags |= BNXT_VF_TRUST; 1638c2ecf20Sopenharmony_ci else 1648c2ecf20Sopenharmony_ci vf->flags &= ~BNXT_VF_TRUST; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci bnxt_hwrm_set_trusted_vf(bp, vf); 1678c2ecf20Sopenharmony_ci return 0; 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ciint bnxt_get_vf_config(struct net_device *dev, int vf_id, 1718c2ecf20Sopenharmony_ci struct ifla_vf_info *ivi) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 1748c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 1758c2ecf20Sopenharmony_ci int rc; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci rc = bnxt_vf_ndo_prep(bp, vf_id); 1788c2ecf20Sopenharmony_ci if (rc) 1798c2ecf20Sopenharmony_ci return rc; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci ivi->vf = vf_id; 1828c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci if (is_valid_ether_addr(vf->mac_addr)) 1858c2ecf20Sopenharmony_ci memcpy(&ivi->mac, vf->mac_addr, ETH_ALEN); 1868c2ecf20Sopenharmony_ci else 1878c2ecf20Sopenharmony_ci memcpy(&ivi->mac, vf->vf_mac_addr, ETH_ALEN); 1888c2ecf20Sopenharmony_ci ivi->max_tx_rate = vf->max_tx_rate; 1898c2ecf20Sopenharmony_ci ivi->min_tx_rate = vf->min_tx_rate; 1908c2ecf20Sopenharmony_ci ivi->vlan = vf->vlan; 1918c2ecf20Sopenharmony_ci if (vf->flags & BNXT_VF_QOS) 1928c2ecf20Sopenharmony_ci ivi->qos = vf->vlan >> VLAN_PRIO_SHIFT; 1938c2ecf20Sopenharmony_ci else 1948c2ecf20Sopenharmony_ci ivi->qos = 0; 1958c2ecf20Sopenharmony_ci ivi->spoofchk = !!(vf->flags & BNXT_VF_SPOOFCHK); 1968c2ecf20Sopenharmony_ci ivi->trusted = bnxt_is_trusted_vf(bp, vf); 1978c2ecf20Sopenharmony_ci if (!(vf->flags & BNXT_VF_LINK_FORCED)) 1988c2ecf20Sopenharmony_ci ivi->linkstate = IFLA_VF_LINK_STATE_AUTO; 1998c2ecf20Sopenharmony_ci else if (vf->flags & BNXT_VF_LINK_UP) 2008c2ecf20Sopenharmony_ci ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE; 2018c2ecf20Sopenharmony_ci else 2028c2ecf20Sopenharmony_ci ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci return 0; 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ciint bnxt_set_vf_mac(struct net_device *dev, int vf_id, u8 *mac) 2088c2ecf20Sopenharmony_ci{ 2098c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 2108c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 2118c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 2128c2ecf20Sopenharmony_ci int rc; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci rc = bnxt_vf_ndo_prep(bp, vf_id); 2158c2ecf20Sopenharmony_ci if (rc) 2168c2ecf20Sopenharmony_ci return rc; 2178c2ecf20Sopenharmony_ci /* reject bc or mc mac addr, zero mac addr means allow 2188c2ecf20Sopenharmony_ci * VF to use its own mac addr 2198c2ecf20Sopenharmony_ci */ 2208c2ecf20Sopenharmony_ci if (is_multicast_ether_addr(mac)) { 2218c2ecf20Sopenharmony_ci netdev_err(dev, "Invalid VF ethernet address\n"); 2228c2ecf20Sopenharmony_ci return -EINVAL; 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci memcpy(vf->mac_addr, mac, ETH_ALEN); 2278c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 2288c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 2298c2ecf20Sopenharmony_ci req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_MAC_ADDR); 2308c2ecf20Sopenharmony_ci memcpy(req.dflt_mac_addr, mac, ETH_ALEN); 2318c2ecf20Sopenharmony_ci return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ciint bnxt_set_vf_vlan(struct net_device *dev, int vf_id, u16 vlan_id, u8 qos, 2358c2ecf20Sopenharmony_ci __be16 vlan_proto) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 2388c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 2398c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 2408c2ecf20Sopenharmony_ci u16 vlan_tag; 2418c2ecf20Sopenharmony_ci int rc; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci if (bp->hwrm_spec_code < 0x10201) 2448c2ecf20Sopenharmony_ci return -ENOTSUPP; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci if (vlan_proto != htons(ETH_P_8021Q)) 2478c2ecf20Sopenharmony_ci return -EPROTONOSUPPORT; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci rc = bnxt_vf_ndo_prep(bp, vf_id); 2508c2ecf20Sopenharmony_ci if (rc) 2518c2ecf20Sopenharmony_ci return rc; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci /* TODO: needed to implement proper handling of user priority, 2548c2ecf20Sopenharmony_ci * currently fail the command if there is valid priority 2558c2ecf20Sopenharmony_ci */ 2568c2ecf20Sopenharmony_ci if (vlan_id > 4095 || qos) 2578c2ecf20Sopenharmony_ci return -EINVAL; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 2608c2ecf20Sopenharmony_ci vlan_tag = vlan_id; 2618c2ecf20Sopenharmony_ci if (vlan_tag == vf->vlan) 2628c2ecf20Sopenharmony_ci return 0; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 2658c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 2668c2ecf20Sopenharmony_ci req.dflt_vlan = cpu_to_le16(vlan_tag); 2678c2ecf20Sopenharmony_ci req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_VLAN); 2688c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2698c2ecf20Sopenharmony_ci if (!rc) 2708c2ecf20Sopenharmony_ci vf->vlan = vlan_tag; 2718c2ecf20Sopenharmony_ci return rc; 2728c2ecf20Sopenharmony_ci} 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ciint bnxt_set_vf_bw(struct net_device *dev, int vf_id, int min_tx_rate, 2758c2ecf20Sopenharmony_ci int max_tx_rate) 2768c2ecf20Sopenharmony_ci{ 2778c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 2788c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 2798c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 2808c2ecf20Sopenharmony_ci u32 pf_link_speed; 2818c2ecf20Sopenharmony_ci int rc; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci rc = bnxt_vf_ndo_prep(bp, vf_id); 2848c2ecf20Sopenharmony_ci if (rc) 2858c2ecf20Sopenharmony_ci return rc; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 2888c2ecf20Sopenharmony_ci pf_link_speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed); 2898c2ecf20Sopenharmony_ci if (max_tx_rate > pf_link_speed) { 2908c2ecf20Sopenharmony_ci netdev_info(bp->dev, "max tx rate %d exceed PF link speed for VF %d\n", 2918c2ecf20Sopenharmony_ci max_tx_rate, vf_id); 2928c2ecf20Sopenharmony_ci return -EINVAL; 2938c2ecf20Sopenharmony_ci } 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci if (min_tx_rate > pf_link_speed || min_tx_rate > max_tx_rate) { 2968c2ecf20Sopenharmony_ci netdev_info(bp->dev, "min tx rate %d is invalid for VF %d\n", 2978c2ecf20Sopenharmony_ci min_tx_rate, vf_id); 2988c2ecf20Sopenharmony_ci return -EINVAL; 2998c2ecf20Sopenharmony_ci } 3008c2ecf20Sopenharmony_ci if (min_tx_rate == vf->min_tx_rate && max_tx_rate == vf->max_tx_rate) 3018c2ecf20Sopenharmony_ci return 0; 3028c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 3038c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 3048c2ecf20Sopenharmony_ci req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_MAX_BW); 3058c2ecf20Sopenharmony_ci req.max_bw = cpu_to_le32(max_tx_rate); 3068c2ecf20Sopenharmony_ci req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_MIN_BW); 3078c2ecf20Sopenharmony_ci req.min_bw = cpu_to_le32(min_tx_rate); 3088c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 3098c2ecf20Sopenharmony_ci if (!rc) { 3108c2ecf20Sopenharmony_ci vf->min_tx_rate = min_tx_rate; 3118c2ecf20Sopenharmony_ci vf->max_tx_rate = max_tx_rate; 3128c2ecf20Sopenharmony_ci } 3138c2ecf20Sopenharmony_ci return rc; 3148c2ecf20Sopenharmony_ci} 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ciint bnxt_set_vf_link_state(struct net_device *dev, int vf_id, int link) 3178c2ecf20Sopenharmony_ci{ 3188c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 3198c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 3208c2ecf20Sopenharmony_ci int rc; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci rc = bnxt_vf_ndo_prep(bp, vf_id); 3238c2ecf20Sopenharmony_ci if (rc) 3248c2ecf20Sopenharmony_ci return rc; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci vf->flags &= ~(BNXT_VF_LINK_UP | BNXT_VF_LINK_FORCED); 3298c2ecf20Sopenharmony_ci switch (link) { 3308c2ecf20Sopenharmony_ci case IFLA_VF_LINK_STATE_AUTO: 3318c2ecf20Sopenharmony_ci vf->flags |= BNXT_VF_LINK_UP; 3328c2ecf20Sopenharmony_ci break; 3338c2ecf20Sopenharmony_ci case IFLA_VF_LINK_STATE_DISABLE: 3348c2ecf20Sopenharmony_ci vf->flags |= BNXT_VF_LINK_FORCED; 3358c2ecf20Sopenharmony_ci break; 3368c2ecf20Sopenharmony_ci case IFLA_VF_LINK_STATE_ENABLE: 3378c2ecf20Sopenharmony_ci vf->flags |= BNXT_VF_LINK_UP | BNXT_VF_LINK_FORCED; 3388c2ecf20Sopenharmony_ci break; 3398c2ecf20Sopenharmony_ci default: 3408c2ecf20Sopenharmony_ci netdev_err(bp->dev, "Invalid link option\n"); 3418c2ecf20Sopenharmony_ci rc = -EINVAL; 3428c2ecf20Sopenharmony_ci break; 3438c2ecf20Sopenharmony_ci } 3448c2ecf20Sopenharmony_ci if (vf->flags & (BNXT_VF_LINK_UP | BNXT_VF_LINK_FORCED)) 3458c2ecf20Sopenharmony_ci rc = bnxt_hwrm_fwd_async_event_cmpl(bp, vf, 3468c2ecf20Sopenharmony_ci ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE); 3478c2ecf20Sopenharmony_ci return rc; 3488c2ecf20Sopenharmony_ci} 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_cistatic int bnxt_set_vf_attr(struct bnxt *bp, int num_vfs) 3518c2ecf20Sopenharmony_ci{ 3528c2ecf20Sopenharmony_ci int i; 3538c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci for (i = 0; i < num_vfs; i++) { 3568c2ecf20Sopenharmony_ci vf = &bp->pf.vf[i]; 3578c2ecf20Sopenharmony_ci memset(vf, 0, sizeof(*vf)); 3588c2ecf20Sopenharmony_ci } 3598c2ecf20Sopenharmony_ci return 0; 3608c2ecf20Sopenharmony_ci} 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistatic int bnxt_hwrm_func_vf_resource_free(struct bnxt *bp, int num_vfs) 3638c2ecf20Sopenharmony_ci{ 3648c2ecf20Sopenharmony_ci int i, rc = 0; 3658c2ecf20Sopenharmony_ci struct bnxt_pf_info *pf = &bp->pf; 3668c2ecf20Sopenharmony_ci struct hwrm_func_vf_resc_free_input req = {0}; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_RESC_FREE, -1, -1); 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci mutex_lock(&bp->hwrm_cmd_lock); 3718c2ecf20Sopenharmony_ci for (i = pf->first_vf_id; i < pf->first_vf_id + num_vfs; i++) { 3728c2ecf20Sopenharmony_ci req.vf_id = cpu_to_le16(i); 3738c2ecf20Sopenharmony_ci rc = _hwrm_send_message(bp, &req, sizeof(req), 3748c2ecf20Sopenharmony_ci HWRM_CMD_TIMEOUT); 3758c2ecf20Sopenharmony_ci if (rc) 3768c2ecf20Sopenharmony_ci break; 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 3798c2ecf20Sopenharmony_ci return rc; 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_cistatic void bnxt_free_vf_resources(struct bnxt *bp) 3838c2ecf20Sopenharmony_ci{ 3848c2ecf20Sopenharmony_ci struct pci_dev *pdev = bp->pdev; 3858c2ecf20Sopenharmony_ci int i; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci kfree(bp->pf.vf_event_bmap); 3888c2ecf20Sopenharmony_ci bp->pf.vf_event_bmap = NULL; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 3918c2ecf20Sopenharmony_ci if (bp->pf.hwrm_cmd_req_addr[i]) { 3928c2ecf20Sopenharmony_ci dma_free_coherent(&pdev->dev, BNXT_PAGE_SIZE, 3938c2ecf20Sopenharmony_ci bp->pf.hwrm_cmd_req_addr[i], 3948c2ecf20Sopenharmony_ci bp->pf.hwrm_cmd_req_dma_addr[i]); 3958c2ecf20Sopenharmony_ci bp->pf.hwrm_cmd_req_addr[i] = NULL; 3968c2ecf20Sopenharmony_ci } 3978c2ecf20Sopenharmony_ci } 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci bp->pf.active_vfs = 0; 4008c2ecf20Sopenharmony_ci kfree(bp->pf.vf); 4018c2ecf20Sopenharmony_ci bp->pf.vf = NULL; 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_cistatic int bnxt_alloc_vf_resources(struct bnxt *bp, int num_vfs) 4058c2ecf20Sopenharmony_ci{ 4068c2ecf20Sopenharmony_ci struct pci_dev *pdev = bp->pdev; 4078c2ecf20Sopenharmony_ci u32 nr_pages, size, i, j, k = 0; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci bp->pf.vf = kcalloc(num_vfs, sizeof(struct bnxt_vf_info), GFP_KERNEL); 4108c2ecf20Sopenharmony_ci if (!bp->pf.vf) 4118c2ecf20Sopenharmony_ci return -ENOMEM; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci bnxt_set_vf_attr(bp, num_vfs); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci size = num_vfs * BNXT_HWRM_REQ_MAX_SIZE; 4168c2ecf20Sopenharmony_ci nr_pages = size / BNXT_PAGE_SIZE; 4178c2ecf20Sopenharmony_ci if (size & (BNXT_PAGE_SIZE - 1)) 4188c2ecf20Sopenharmony_ci nr_pages++; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci for (i = 0; i < nr_pages; i++) { 4218c2ecf20Sopenharmony_ci bp->pf.hwrm_cmd_req_addr[i] = 4228c2ecf20Sopenharmony_ci dma_alloc_coherent(&pdev->dev, BNXT_PAGE_SIZE, 4238c2ecf20Sopenharmony_ci &bp->pf.hwrm_cmd_req_dma_addr[i], 4248c2ecf20Sopenharmony_ci GFP_KERNEL); 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci if (!bp->pf.hwrm_cmd_req_addr[i]) 4278c2ecf20Sopenharmony_ci return -ENOMEM; 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci for (j = 0; j < BNXT_HWRM_REQS_PER_PAGE && k < num_vfs; j++) { 4308c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf = &bp->pf.vf[k]; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci vf->hwrm_cmd_req_addr = bp->pf.hwrm_cmd_req_addr[i] + 4338c2ecf20Sopenharmony_ci j * BNXT_HWRM_REQ_MAX_SIZE; 4348c2ecf20Sopenharmony_ci vf->hwrm_cmd_req_dma_addr = 4358c2ecf20Sopenharmony_ci bp->pf.hwrm_cmd_req_dma_addr[i] + j * 4368c2ecf20Sopenharmony_ci BNXT_HWRM_REQ_MAX_SIZE; 4378c2ecf20Sopenharmony_ci k++; 4388c2ecf20Sopenharmony_ci } 4398c2ecf20Sopenharmony_ci } 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci /* Max 128 VF's */ 4428c2ecf20Sopenharmony_ci bp->pf.vf_event_bmap = kzalloc(16, GFP_KERNEL); 4438c2ecf20Sopenharmony_ci if (!bp->pf.vf_event_bmap) 4448c2ecf20Sopenharmony_ci return -ENOMEM; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci bp->pf.hwrm_cmd_req_pages = nr_pages; 4478c2ecf20Sopenharmony_ci return 0; 4488c2ecf20Sopenharmony_ci} 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_cistatic int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp) 4518c2ecf20Sopenharmony_ci{ 4528c2ecf20Sopenharmony_ci struct hwrm_func_buf_rgtr_input req = {0}; 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_BUF_RGTR, -1, -1); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci req.req_buf_num_pages = cpu_to_le16(bp->pf.hwrm_cmd_req_pages); 4578c2ecf20Sopenharmony_ci req.req_buf_page_size = cpu_to_le16(BNXT_PAGE_SHIFT); 4588c2ecf20Sopenharmony_ci req.req_buf_len = cpu_to_le16(BNXT_HWRM_REQ_MAX_SIZE); 4598c2ecf20Sopenharmony_ci req.req_buf_page_addr0 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[0]); 4608c2ecf20Sopenharmony_ci req.req_buf_page_addr1 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[1]); 4618c2ecf20Sopenharmony_ci req.req_buf_page_addr2 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[2]); 4628c2ecf20Sopenharmony_ci req.req_buf_page_addr3 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[3]); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci/* Caller holds bp->hwrm_cmd_lock mutex lock */ 4688c2ecf20Sopenharmony_cistatic void __bnxt_set_vf_params(struct bnxt *bp, int vf_id) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 4718c2ecf20Sopenharmony_ci struct bnxt_vf_info *vf; 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci vf = &bp->pf.vf[vf_id]; 4748c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 4758c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(vf->fw_fid); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci if (is_valid_ether_addr(vf->mac_addr)) { 4788c2ecf20Sopenharmony_ci req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_MAC_ADDR); 4798c2ecf20Sopenharmony_ci memcpy(req.dflt_mac_addr, vf->mac_addr, ETH_ALEN); 4808c2ecf20Sopenharmony_ci } 4818c2ecf20Sopenharmony_ci if (vf->vlan) { 4828c2ecf20Sopenharmony_ci req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_VLAN); 4838c2ecf20Sopenharmony_ci req.dflt_vlan = cpu_to_le16(vf->vlan); 4848c2ecf20Sopenharmony_ci } 4858c2ecf20Sopenharmony_ci if (vf->max_tx_rate) { 4868c2ecf20Sopenharmony_ci req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_MAX_BW); 4878c2ecf20Sopenharmony_ci req.max_bw = cpu_to_le32(vf->max_tx_rate); 4888c2ecf20Sopenharmony_ci#ifdef HAVE_IFLA_TX_RATE 4898c2ecf20Sopenharmony_ci req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_MIN_BW); 4908c2ecf20Sopenharmony_ci req.min_bw = cpu_to_le32(vf->min_tx_rate); 4918c2ecf20Sopenharmony_ci#endif 4928c2ecf20Sopenharmony_ci } 4938c2ecf20Sopenharmony_ci if (vf->flags & BNXT_VF_TRUST) 4948c2ecf20Sopenharmony_ci req.flags |= cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_ENABLE); 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4978c2ecf20Sopenharmony_ci} 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci/* Only called by PF to reserve resources for VFs, returns actual number of 5008c2ecf20Sopenharmony_ci * VFs configured, or < 0 on error. 5018c2ecf20Sopenharmony_ci */ 5028c2ecf20Sopenharmony_cistatic int bnxt_hwrm_func_vf_resc_cfg(struct bnxt *bp, int num_vfs, bool reset) 5038c2ecf20Sopenharmony_ci{ 5048c2ecf20Sopenharmony_ci struct hwrm_func_vf_resource_cfg_input req = {0}; 5058c2ecf20Sopenharmony_ci struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 5068c2ecf20Sopenharmony_ci u16 vf_tx_rings, vf_rx_rings, vf_cp_rings; 5078c2ecf20Sopenharmony_ci u16 vf_stat_ctx, vf_vnics, vf_ring_grps; 5088c2ecf20Sopenharmony_ci struct bnxt_pf_info *pf = &bp->pf; 5098c2ecf20Sopenharmony_ci int i, rc = 0, min = 1; 5108c2ecf20Sopenharmony_ci u16 vf_msix = 0; 5118c2ecf20Sopenharmony_ci u16 vf_rss; 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_RESOURCE_CFG, -1, -1); 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci if (bp->flags & BNXT_FLAG_CHIP_P5) { 5168c2ecf20Sopenharmony_ci vf_msix = hw_resc->max_nqs - bnxt_nq_rings_in_use(bp); 5178c2ecf20Sopenharmony_ci vf_ring_grps = 0; 5188c2ecf20Sopenharmony_ci } else { 5198c2ecf20Sopenharmony_ci vf_ring_grps = hw_resc->max_hw_ring_grps - bp->rx_nr_rings; 5208c2ecf20Sopenharmony_ci } 5218c2ecf20Sopenharmony_ci vf_cp_rings = bnxt_get_avail_cp_rings_for_en(bp); 5228c2ecf20Sopenharmony_ci vf_stat_ctx = bnxt_get_avail_stat_ctxs_for_en(bp); 5238c2ecf20Sopenharmony_ci if (bp->flags & BNXT_FLAG_AGG_RINGS) 5248c2ecf20Sopenharmony_ci vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings * 2; 5258c2ecf20Sopenharmony_ci else 5268c2ecf20Sopenharmony_ci vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings; 5278c2ecf20Sopenharmony_ci vf_tx_rings = hw_resc->max_tx_rings - bp->tx_nr_rings; 5288c2ecf20Sopenharmony_ci vf_vnics = hw_resc->max_vnics - bp->nr_vnics; 5298c2ecf20Sopenharmony_ci vf_vnics = min_t(u16, vf_vnics, vf_rx_rings); 5308c2ecf20Sopenharmony_ci vf_rss = hw_resc->max_rsscos_ctxs - bp->rsscos_nr_ctxs; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci req.min_rsscos_ctx = cpu_to_le16(BNXT_VF_MIN_RSS_CTX); 5338c2ecf20Sopenharmony_ci if (pf->vf_resv_strategy == BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC) { 5348c2ecf20Sopenharmony_ci min = 0; 5358c2ecf20Sopenharmony_ci req.min_rsscos_ctx = cpu_to_le16(min); 5368c2ecf20Sopenharmony_ci } 5378c2ecf20Sopenharmony_ci if (pf->vf_resv_strategy == BNXT_VF_RESV_STRATEGY_MINIMAL || 5388c2ecf20Sopenharmony_ci pf->vf_resv_strategy == BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC) { 5398c2ecf20Sopenharmony_ci req.min_cmpl_rings = cpu_to_le16(min); 5408c2ecf20Sopenharmony_ci req.min_tx_rings = cpu_to_le16(min); 5418c2ecf20Sopenharmony_ci req.min_rx_rings = cpu_to_le16(min); 5428c2ecf20Sopenharmony_ci req.min_l2_ctxs = cpu_to_le16(min); 5438c2ecf20Sopenharmony_ci req.min_vnics = cpu_to_le16(min); 5448c2ecf20Sopenharmony_ci req.min_stat_ctx = cpu_to_le16(min); 5458c2ecf20Sopenharmony_ci if (!(bp->flags & BNXT_FLAG_CHIP_P5)) 5468c2ecf20Sopenharmony_ci req.min_hw_ring_grps = cpu_to_le16(min); 5478c2ecf20Sopenharmony_ci } else { 5488c2ecf20Sopenharmony_ci vf_cp_rings /= num_vfs; 5498c2ecf20Sopenharmony_ci vf_tx_rings /= num_vfs; 5508c2ecf20Sopenharmony_ci vf_rx_rings /= num_vfs; 5518c2ecf20Sopenharmony_ci vf_vnics /= num_vfs; 5528c2ecf20Sopenharmony_ci vf_stat_ctx /= num_vfs; 5538c2ecf20Sopenharmony_ci vf_ring_grps /= num_vfs; 5548c2ecf20Sopenharmony_ci vf_rss /= num_vfs; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci req.min_cmpl_rings = cpu_to_le16(vf_cp_rings); 5578c2ecf20Sopenharmony_ci req.min_tx_rings = cpu_to_le16(vf_tx_rings); 5588c2ecf20Sopenharmony_ci req.min_rx_rings = cpu_to_le16(vf_rx_rings); 5598c2ecf20Sopenharmony_ci req.min_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX); 5608c2ecf20Sopenharmony_ci req.min_vnics = cpu_to_le16(vf_vnics); 5618c2ecf20Sopenharmony_ci req.min_stat_ctx = cpu_to_le16(vf_stat_ctx); 5628c2ecf20Sopenharmony_ci req.min_hw_ring_grps = cpu_to_le16(vf_ring_grps); 5638c2ecf20Sopenharmony_ci req.min_rsscos_ctx = cpu_to_le16(vf_rss); 5648c2ecf20Sopenharmony_ci } 5658c2ecf20Sopenharmony_ci req.max_cmpl_rings = cpu_to_le16(vf_cp_rings); 5668c2ecf20Sopenharmony_ci req.max_tx_rings = cpu_to_le16(vf_tx_rings); 5678c2ecf20Sopenharmony_ci req.max_rx_rings = cpu_to_le16(vf_rx_rings); 5688c2ecf20Sopenharmony_ci req.max_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX); 5698c2ecf20Sopenharmony_ci req.max_vnics = cpu_to_le16(vf_vnics); 5708c2ecf20Sopenharmony_ci req.max_stat_ctx = cpu_to_le16(vf_stat_ctx); 5718c2ecf20Sopenharmony_ci req.max_hw_ring_grps = cpu_to_le16(vf_ring_grps); 5728c2ecf20Sopenharmony_ci req.max_rsscos_ctx = cpu_to_le16(vf_rss); 5738c2ecf20Sopenharmony_ci if (bp->flags & BNXT_FLAG_CHIP_P5) 5748c2ecf20Sopenharmony_ci req.max_msix = cpu_to_le16(vf_msix / num_vfs); 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci mutex_lock(&bp->hwrm_cmd_lock); 5778c2ecf20Sopenharmony_ci for (i = 0; i < num_vfs; i++) { 5788c2ecf20Sopenharmony_ci if (reset) 5798c2ecf20Sopenharmony_ci __bnxt_set_vf_params(bp, i); 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci req.vf_id = cpu_to_le16(pf->first_vf_id + i); 5828c2ecf20Sopenharmony_ci rc = _hwrm_send_message(bp, &req, sizeof(req), 5838c2ecf20Sopenharmony_ci HWRM_CMD_TIMEOUT); 5848c2ecf20Sopenharmony_ci if (rc) 5858c2ecf20Sopenharmony_ci break; 5868c2ecf20Sopenharmony_ci pf->active_vfs = i + 1; 5878c2ecf20Sopenharmony_ci pf->vf[i].fw_fid = pf->first_vf_id + i; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 5908c2ecf20Sopenharmony_ci if (pf->active_vfs) { 5918c2ecf20Sopenharmony_ci u16 n = pf->active_vfs; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci hw_resc->max_tx_rings -= le16_to_cpu(req.min_tx_rings) * n; 5948c2ecf20Sopenharmony_ci hw_resc->max_rx_rings -= le16_to_cpu(req.min_rx_rings) * n; 5958c2ecf20Sopenharmony_ci hw_resc->max_hw_ring_grps -= le16_to_cpu(req.min_hw_ring_grps) * 5968c2ecf20Sopenharmony_ci n; 5978c2ecf20Sopenharmony_ci hw_resc->max_cp_rings -= le16_to_cpu(req.min_cmpl_rings) * n; 5988c2ecf20Sopenharmony_ci hw_resc->max_rsscos_ctxs -= le16_to_cpu(req.min_rsscos_ctx) * n; 5998c2ecf20Sopenharmony_ci hw_resc->max_stat_ctxs -= le16_to_cpu(req.min_stat_ctx) * n; 6008c2ecf20Sopenharmony_ci hw_resc->max_vnics -= le16_to_cpu(req.min_vnics) * n; 6018c2ecf20Sopenharmony_ci if (bp->flags & BNXT_FLAG_CHIP_P5) 6028c2ecf20Sopenharmony_ci hw_resc->max_nqs -= vf_msix; 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci rc = pf->active_vfs; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci return rc; 6078c2ecf20Sopenharmony_ci} 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci/* Only called by PF to reserve resources for VFs, returns actual number of 6108c2ecf20Sopenharmony_ci * VFs configured, or < 0 on error. 6118c2ecf20Sopenharmony_ci */ 6128c2ecf20Sopenharmony_cistatic int bnxt_hwrm_func_cfg(struct bnxt *bp, int num_vfs) 6138c2ecf20Sopenharmony_ci{ 6148c2ecf20Sopenharmony_ci u32 rc = 0, mtu, i; 6158c2ecf20Sopenharmony_ci u16 vf_tx_rings, vf_rx_rings, vf_cp_rings, vf_stat_ctx, vf_vnics; 6168c2ecf20Sopenharmony_ci struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 6178c2ecf20Sopenharmony_ci struct hwrm_func_cfg_input req = {0}; 6188c2ecf20Sopenharmony_ci struct bnxt_pf_info *pf = &bp->pf; 6198c2ecf20Sopenharmony_ci int total_vf_tx_rings = 0; 6208c2ecf20Sopenharmony_ci u16 vf_ring_grps; 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci /* Remaining rings are distributed equally amongs VF's for now */ 6258c2ecf20Sopenharmony_ci vf_cp_rings = bnxt_get_avail_cp_rings_for_en(bp) / num_vfs; 6268c2ecf20Sopenharmony_ci vf_stat_ctx = bnxt_get_avail_stat_ctxs_for_en(bp) / num_vfs; 6278c2ecf20Sopenharmony_ci if (bp->flags & BNXT_FLAG_AGG_RINGS) 6288c2ecf20Sopenharmony_ci vf_rx_rings = (hw_resc->max_rx_rings - bp->rx_nr_rings * 2) / 6298c2ecf20Sopenharmony_ci num_vfs; 6308c2ecf20Sopenharmony_ci else 6318c2ecf20Sopenharmony_ci vf_rx_rings = (hw_resc->max_rx_rings - bp->rx_nr_rings) / 6328c2ecf20Sopenharmony_ci num_vfs; 6338c2ecf20Sopenharmony_ci vf_ring_grps = (hw_resc->max_hw_ring_grps - bp->rx_nr_rings) / num_vfs; 6348c2ecf20Sopenharmony_ci vf_tx_rings = (hw_resc->max_tx_rings - bp->tx_nr_rings) / num_vfs; 6358c2ecf20Sopenharmony_ci vf_vnics = (hw_resc->max_vnics - bp->nr_vnics) / num_vfs; 6368c2ecf20Sopenharmony_ci vf_vnics = min_t(u16, vf_vnics, vf_rx_rings); 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_MTU | 6398c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_MRU | 6408c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS | 6418c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS | 6428c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS | 6438c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS | 6448c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS | 6458c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_L2_CTXS | 6468c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_VNICS | 6478c2ecf20Sopenharmony_ci FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS); 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci mtu = bp->dev->mtu + ETH_HLEN + VLAN_HLEN; 6508c2ecf20Sopenharmony_ci req.mru = cpu_to_le16(mtu); 6518c2ecf20Sopenharmony_ci req.mtu = cpu_to_le16(mtu); 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci req.num_rsscos_ctxs = cpu_to_le16(1); 6548c2ecf20Sopenharmony_ci req.num_cmpl_rings = cpu_to_le16(vf_cp_rings); 6558c2ecf20Sopenharmony_ci req.num_tx_rings = cpu_to_le16(vf_tx_rings); 6568c2ecf20Sopenharmony_ci req.num_rx_rings = cpu_to_le16(vf_rx_rings); 6578c2ecf20Sopenharmony_ci req.num_hw_ring_grps = cpu_to_le16(vf_ring_grps); 6588c2ecf20Sopenharmony_ci req.num_l2_ctxs = cpu_to_le16(4); 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci req.num_vnics = cpu_to_le16(vf_vnics); 6618c2ecf20Sopenharmony_ci /* FIXME spec currently uses 1 bit for stats ctx */ 6628c2ecf20Sopenharmony_ci req.num_stat_ctxs = cpu_to_le16(vf_stat_ctx); 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci mutex_lock(&bp->hwrm_cmd_lock); 6658c2ecf20Sopenharmony_ci for (i = 0; i < num_vfs; i++) { 6668c2ecf20Sopenharmony_ci int vf_tx_rsvd = vf_tx_rings; 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(pf->first_vf_id + i); 6698c2ecf20Sopenharmony_ci rc = _hwrm_send_message(bp, &req, sizeof(req), 6708c2ecf20Sopenharmony_ci HWRM_CMD_TIMEOUT); 6718c2ecf20Sopenharmony_ci if (rc) 6728c2ecf20Sopenharmony_ci break; 6738c2ecf20Sopenharmony_ci pf->active_vfs = i + 1; 6748c2ecf20Sopenharmony_ci pf->vf[i].fw_fid = le16_to_cpu(req.fid); 6758c2ecf20Sopenharmony_ci rc = __bnxt_hwrm_get_tx_rings(bp, pf->vf[i].fw_fid, 6768c2ecf20Sopenharmony_ci &vf_tx_rsvd); 6778c2ecf20Sopenharmony_ci if (rc) 6788c2ecf20Sopenharmony_ci break; 6798c2ecf20Sopenharmony_ci total_vf_tx_rings += vf_tx_rsvd; 6808c2ecf20Sopenharmony_ci } 6818c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 6828c2ecf20Sopenharmony_ci if (pf->active_vfs) { 6838c2ecf20Sopenharmony_ci hw_resc->max_tx_rings -= total_vf_tx_rings; 6848c2ecf20Sopenharmony_ci hw_resc->max_rx_rings -= vf_rx_rings * num_vfs; 6858c2ecf20Sopenharmony_ci hw_resc->max_hw_ring_grps -= vf_ring_grps * num_vfs; 6868c2ecf20Sopenharmony_ci hw_resc->max_cp_rings -= vf_cp_rings * num_vfs; 6878c2ecf20Sopenharmony_ci hw_resc->max_rsscos_ctxs -= num_vfs; 6888c2ecf20Sopenharmony_ci hw_resc->max_stat_ctxs -= vf_stat_ctx * num_vfs; 6898c2ecf20Sopenharmony_ci hw_resc->max_vnics -= vf_vnics * num_vfs; 6908c2ecf20Sopenharmony_ci rc = pf->active_vfs; 6918c2ecf20Sopenharmony_ci } 6928c2ecf20Sopenharmony_ci return rc; 6938c2ecf20Sopenharmony_ci} 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_cistatic int bnxt_func_cfg(struct bnxt *bp, int num_vfs, bool reset) 6968c2ecf20Sopenharmony_ci{ 6978c2ecf20Sopenharmony_ci if (BNXT_NEW_RM(bp)) 6988c2ecf20Sopenharmony_ci return bnxt_hwrm_func_vf_resc_cfg(bp, num_vfs, reset); 6998c2ecf20Sopenharmony_ci else 7008c2ecf20Sopenharmony_ci return bnxt_hwrm_func_cfg(bp, num_vfs); 7018c2ecf20Sopenharmony_ci} 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ciint bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset) 7048c2ecf20Sopenharmony_ci{ 7058c2ecf20Sopenharmony_ci int rc; 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci /* Register buffers for VFs */ 7088c2ecf20Sopenharmony_ci rc = bnxt_hwrm_func_buf_rgtr(bp); 7098c2ecf20Sopenharmony_ci if (rc) 7108c2ecf20Sopenharmony_ci return rc; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci /* Reserve resources for VFs */ 7138c2ecf20Sopenharmony_ci rc = bnxt_func_cfg(bp, *num_vfs, reset); 7148c2ecf20Sopenharmony_ci if (rc != *num_vfs) { 7158c2ecf20Sopenharmony_ci if (rc <= 0) { 7168c2ecf20Sopenharmony_ci netdev_warn(bp->dev, "Unable to reserve resources for SRIOV.\n"); 7178c2ecf20Sopenharmony_ci *num_vfs = 0; 7188c2ecf20Sopenharmony_ci return rc; 7198c2ecf20Sopenharmony_ci } 7208c2ecf20Sopenharmony_ci netdev_warn(bp->dev, "Only able to reserve resources for %d VFs.\n", 7218c2ecf20Sopenharmony_ci rc); 7228c2ecf20Sopenharmony_ci *num_vfs = rc; 7238c2ecf20Sopenharmony_ci } 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci bnxt_ulp_sriov_cfg(bp, *num_vfs); 7268c2ecf20Sopenharmony_ci return 0; 7278c2ecf20Sopenharmony_ci} 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_cistatic int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs) 7308c2ecf20Sopenharmony_ci{ 7318c2ecf20Sopenharmony_ci int rc = 0, vfs_supported; 7328c2ecf20Sopenharmony_ci int min_rx_rings, min_tx_rings, min_rss_ctxs; 7338c2ecf20Sopenharmony_ci struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 7348c2ecf20Sopenharmony_ci int tx_ok = 0, rx_ok = 0, rss_ok = 0; 7358c2ecf20Sopenharmony_ci int avail_cp, avail_stat; 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci /* Check if we can enable requested num of vf's. At a mininum 7388c2ecf20Sopenharmony_ci * we require 1 RX 1 TX rings for each VF. In this minimum conf 7398c2ecf20Sopenharmony_ci * features like TPA will not be available. 7408c2ecf20Sopenharmony_ci */ 7418c2ecf20Sopenharmony_ci vfs_supported = *num_vfs; 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci avail_cp = bnxt_get_avail_cp_rings_for_en(bp); 7448c2ecf20Sopenharmony_ci avail_stat = bnxt_get_avail_stat_ctxs_for_en(bp); 7458c2ecf20Sopenharmony_ci avail_cp = min_t(int, avail_cp, avail_stat); 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci while (vfs_supported) { 7488c2ecf20Sopenharmony_ci min_rx_rings = vfs_supported; 7498c2ecf20Sopenharmony_ci min_tx_rings = vfs_supported; 7508c2ecf20Sopenharmony_ci min_rss_ctxs = vfs_supported; 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci if (bp->flags & BNXT_FLAG_AGG_RINGS) { 7538c2ecf20Sopenharmony_ci if (hw_resc->max_rx_rings - bp->rx_nr_rings * 2 >= 7548c2ecf20Sopenharmony_ci min_rx_rings) 7558c2ecf20Sopenharmony_ci rx_ok = 1; 7568c2ecf20Sopenharmony_ci } else { 7578c2ecf20Sopenharmony_ci if (hw_resc->max_rx_rings - bp->rx_nr_rings >= 7588c2ecf20Sopenharmony_ci min_rx_rings) 7598c2ecf20Sopenharmony_ci rx_ok = 1; 7608c2ecf20Sopenharmony_ci } 7618c2ecf20Sopenharmony_ci if (hw_resc->max_vnics - bp->nr_vnics < min_rx_rings || 7628c2ecf20Sopenharmony_ci avail_cp < min_rx_rings) 7638c2ecf20Sopenharmony_ci rx_ok = 0; 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci if (hw_resc->max_tx_rings - bp->tx_nr_rings >= min_tx_rings && 7668c2ecf20Sopenharmony_ci avail_cp >= min_tx_rings) 7678c2ecf20Sopenharmony_ci tx_ok = 1; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci if (hw_resc->max_rsscos_ctxs - bp->rsscos_nr_ctxs >= 7708c2ecf20Sopenharmony_ci min_rss_ctxs) 7718c2ecf20Sopenharmony_ci rss_ok = 1; 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci if (tx_ok && rx_ok && rss_ok) 7748c2ecf20Sopenharmony_ci break; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci vfs_supported--; 7778c2ecf20Sopenharmony_ci } 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci if (!vfs_supported) { 7808c2ecf20Sopenharmony_ci netdev_err(bp->dev, "Cannot enable VF's as all resources are used by PF\n"); 7818c2ecf20Sopenharmony_ci return -EINVAL; 7828c2ecf20Sopenharmony_ci } 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci if (vfs_supported != *num_vfs) { 7858c2ecf20Sopenharmony_ci netdev_info(bp->dev, "Requested VFs %d, can enable %d\n", 7868c2ecf20Sopenharmony_ci *num_vfs, vfs_supported); 7878c2ecf20Sopenharmony_ci *num_vfs = vfs_supported; 7888c2ecf20Sopenharmony_ci } 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci rc = bnxt_alloc_vf_resources(bp, *num_vfs); 7918c2ecf20Sopenharmony_ci if (rc) 7928c2ecf20Sopenharmony_ci goto err_out1; 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci rc = bnxt_cfg_hw_sriov(bp, num_vfs, false); 7958c2ecf20Sopenharmony_ci if (rc) 7968c2ecf20Sopenharmony_ci goto err_out2; 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci rc = pci_enable_sriov(bp->pdev, *num_vfs); 7998c2ecf20Sopenharmony_ci if (rc) 8008c2ecf20Sopenharmony_ci goto err_out2; 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci return 0; 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_cierr_out2: 8058c2ecf20Sopenharmony_ci /* Free the resources reserved for various VF's */ 8068c2ecf20Sopenharmony_ci bnxt_hwrm_func_vf_resource_free(bp, *num_vfs); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_cierr_out1: 8098c2ecf20Sopenharmony_ci bnxt_free_vf_resources(bp); 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci return rc; 8128c2ecf20Sopenharmony_ci} 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_civoid bnxt_sriov_disable(struct bnxt *bp) 8158c2ecf20Sopenharmony_ci{ 8168c2ecf20Sopenharmony_ci u16 num_vfs = pci_num_vf(bp->pdev); 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci if (!num_vfs) 8198c2ecf20Sopenharmony_ci return; 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci /* synchronize VF and VF-rep create and destroy */ 8228c2ecf20Sopenharmony_ci mutex_lock(&bp->sriov_lock); 8238c2ecf20Sopenharmony_ci bnxt_vf_reps_destroy(bp); 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci if (pci_vfs_assigned(bp->pdev)) { 8268c2ecf20Sopenharmony_ci bnxt_hwrm_fwd_async_event_cmpl( 8278c2ecf20Sopenharmony_ci bp, NULL, ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD); 8288c2ecf20Sopenharmony_ci netdev_warn(bp->dev, "Unable to free %d VFs because some are assigned to VMs.\n", 8298c2ecf20Sopenharmony_ci num_vfs); 8308c2ecf20Sopenharmony_ci } else { 8318c2ecf20Sopenharmony_ci pci_disable_sriov(bp->pdev); 8328c2ecf20Sopenharmony_ci /* Free the HW resources reserved for various VF's */ 8338c2ecf20Sopenharmony_ci bnxt_hwrm_func_vf_resource_free(bp, num_vfs); 8348c2ecf20Sopenharmony_ci } 8358c2ecf20Sopenharmony_ci mutex_unlock(&bp->sriov_lock); 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci bnxt_free_vf_resources(bp); 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci /* Reclaim all resources for the PF. */ 8408c2ecf20Sopenharmony_ci rtnl_lock(); 8418c2ecf20Sopenharmony_ci bnxt_restore_pf_fw_resources(bp); 8428c2ecf20Sopenharmony_ci rtnl_unlock(); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci bnxt_ulp_sriov_cfg(bp, 0); 8458c2ecf20Sopenharmony_ci} 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ciint bnxt_sriov_configure(struct pci_dev *pdev, int num_vfs) 8488c2ecf20Sopenharmony_ci{ 8498c2ecf20Sopenharmony_ci struct net_device *dev = pci_get_drvdata(pdev); 8508c2ecf20Sopenharmony_ci struct bnxt *bp = netdev_priv(dev); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci if (!(bp->flags & BNXT_FLAG_USING_MSIX)) { 8538c2ecf20Sopenharmony_ci netdev_warn(dev, "Not allow SRIOV if the irq mode is not MSIX\n"); 8548c2ecf20Sopenharmony_ci return 0; 8558c2ecf20Sopenharmony_ci } 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci rtnl_lock(); 8588c2ecf20Sopenharmony_ci if (!netif_running(dev)) { 8598c2ecf20Sopenharmony_ci netdev_warn(dev, "Reject SRIOV config request since if is down!\n"); 8608c2ecf20Sopenharmony_ci rtnl_unlock(); 8618c2ecf20Sopenharmony_ci return 0; 8628c2ecf20Sopenharmony_ci } 8638c2ecf20Sopenharmony_ci if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) { 8648c2ecf20Sopenharmony_ci netdev_warn(dev, "Reject SRIOV config request when FW reset is in progress\n"); 8658c2ecf20Sopenharmony_ci rtnl_unlock(); 8668c2ecf20Sopenharmony_ci return 0; 8678c2ecf20Sopenharmony_ci } 8688c2ecf20Sopenharmony_ci bp->sriov_cfg = true; 8698c2ecf20Sopenharmony_ci rtnl_unlock(); 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci if (pci_vfs_assigned(bp->pdev)) { 8728c2ecf20Sopenharmony_ci netdev_warn(dev, "Unable to configure SRIOV since some VFs are assigned to VMs.\n"); 8738c2ecf20Sopenharmony_ci num_vfs = 0; 8748c2ecf20Sopenharmony_ci goto sriov_cfg_exit; 8758c2ecf20Sopenharmony_ci } 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci /* Check if enabled VFs is same as requested */ 8788c2ecf20Sopenharmony_ci if (num_vfs && num_vfs == bp->pf.active_vfs) 8798c2ecf20Sopenharmony_ci goto sriov_cfg_exit; 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ci /* if there are previous existing VFs, clean them up */ 8828c2ecf20Sopenharmony_ci bnxt_sriov_disable(bp); 8838c2ecf20Sopenharmony_ci if (!num_vfs) 8848c2ecf20Sopenharmony_ci goto sriov_cfg_exit; 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_ci bnxt_sriov_enable(bp, &num_vfs); 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_cisriov_cfg_exit: 8898c2ecf20Sopenharmony_ci bp->sriov_cfg = false; 8908c2ecf20Sopenharmony_ci wake_up(&bp->sriov_cfg_wait); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci return num_vfs; 8938c2ecf20Sopenharmony_ci} 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_cistatic int bnxt_hwrm_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf, 8968c2ecf20Sopenharmony_ci void *encap_resp, __le64 encap_resp_addr, 8978c2ecf20Sopenharmony_ci __le16 encap_resp_cpr, u32 msg_size) 8988c2ecf20Sopenharmony_ci{ 8998c2ecf20Sopenharmony_ci int rc = 0; 9008c2ecf20Sopenharmony_ci struct hwrm_fwd_resp_input req = {0}; 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_ci if (BNXT_FWD_RESP_SIZE_ERR(msg_size)) 9038c2ecf20Sopenharmony_ci return -EINVAL; 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FWD_RESP, -1, -1); 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci /* Set the new target id */ 9088c2ecf20Sopenharmony_ci req.target_id = cpu_to_le16(vf->fw_fid); 9098c2ecf20Sopenharmony_ci req.encap_resp_target_id = cpu_to_le16(vf->fw_fid); 9108c2ecf20Sopenharmony_ci req.encap_resp_len = cpu_to_le16(msg_size); 9118c2ecf20Sopenharmony_ci req.encap_resp_addr = encap_resp_addr; 9128c2ecf20Sopenharmony_ci req.encap_resp_cmpl_ring = encap_resp_cpr; 9138c2ecf20Sopenharmony_ci memcpy(req.encap_resp, encap_resp, msg_size); 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 9168c2ecf20Sopenharmony_ci if (rc) 9178c2ecf20Sopenharmony_ci netdev_err(bp->dev, "hwrm_fwd_resp failed. rc:%d\n", rc); 9188c2ecf20Sopenharmony_ci return rc; 9198c2ecf20Sopenharmony_ci} 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_cistatic int bnxt_hwrm_fwd_err_resp(struct bnxt *bp, struct bnxt_vf_info *vf, 9228c2ecf20Sopenharmony_ci u32 msg_size) 9238c2ecf20Sopenharmony_ci{ 9248c2ecf20Sopenharmony_ci int rc = 0; 9258c2ecf20Sopenharmony_ci struct hwrm_reject_fwd_resp_input req = {0}; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci if (BNXT_REJ_FWD_RESP_SIZE_ERR(msg_size)) 9288c2ecf20Sopenharmony_ci return -EINVAL; 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_REJECT_FWD_RESP, -1, -1); 9318c2ecf20Sopenharmony_ci /* Set the new target id */ 9328c2ecf20Sopenharmony_ci req.target_id = cpu_to_le16(vf->fw_fid); 9338c2ecf20Sopenharmony_ci req.encap_resp_target_id = cpu_to_le16(vf->fw_fid); 9348c2ecf20Sopenharmony_ci memcpy(req.encap_request, vf->hwrm_cmd_req_addr, msg_size); 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 9378c2ecf20Sopenharmony_ci if (rc) 9388c2ecf20Sopenharmony_ci netdev_err(bp->dev, "hwrm_fwd_err_resp failed. rc:%d\n", rc); 9398c2ecf20Sopenharmony_ci return rc; 9408c2ecf20Sopenharmony_ci} 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_cistatic int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf, 9438c2ecf20Sopenharmony_ci u32 msg_size) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci int rc = 0; 9468c2ecf20Sopenharmony_ci struct hwrm_exec_fwd_resp_input req = {0}; 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci if (BNXT_EXEC_FWD_RESP_SIZE_ERR(msg_size)) 9498c2ecf20Sopenharmony_ci return -EINVAL; 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_EXEC_FWD_RESP, -1, -1); 9528c2ecf20Sopenharmony_ci /* Set the new target id */ 9538c2ecf20Sopenharmony_ci req.target_id = cpu_to_le16(vf->fw_fid); 9548c2ecf20Sopenharmony_ci req.encap_resp_target_id = cpu_to_le16(vf->fw_fid); 9558c2ecf20Sopenharmony_ci memcpy(req.encap_request, vf->hwrm_cmd_req_addr, msg_size); 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 9588c2ecf20Sopenharmony_ci if (rc) 9598c2ecf20Sopenharmony_ci netdev_err(bp->dev, "hwrm_exec_fw_resp failed. rc:%d\n", rc); 9608c2ecf20Sopenharmony_ci return rc; 9618c2ecf20Sopenharmony_ci} 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_cistatic int bnxt_vf_configure_mac(struct bnxt *bp, struct bnxt_vf_info *vf) 9648c2ecf20Sopenharmony_ci{ 9658c2ecf20Sopenharmony_ci u32 msg_size = sizeof(struct hwrm_func_vf_cfg_input); 9668c2ecf20Sopenharmony_ci struct hwrm_func_vf_cfg_input *req = 9678c2ecf20Sopenharmony_ci (struct hwrm_func_vf_cfg_input *)vf->hwrm_cmd_req_addr; 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci /* Allow VF to set a valid MAC address, if trust is set to on or 9708c2ecf20Sopenharmony_ci * if the PF assigned MAC address is zero 9718c2ecf20Sopenharmony_ci */ 9728c2ecf20Sopenharmony_ci if (req->enables & cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_DFLT_MAC_ADDR)) { 9738c2ecf20Sopenharmony_ci bool trust = bnxt_is_trusted_vf(bp, vf); 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci if (is_valid_ether_addr(req->dflt_mac_addr) && 9768c2ecf20Sopenharmony_ci (trust || !is_valid_ether_addr(vf->mac_addr) || 9778c2ecf20Sopenharmony_ci ether_addr_equal(req->dflt_mac_addr, vf->mac_addr))) { 9788c2ecf20Sopenharmony_ci ether_addr_copy(vf->vf_mac_addr, req->dflt_mac_addr); 9798c2ecf20Sopenharmony_ci return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size); 9808c2ecf20Sopenharmony_ci } 9818c2ecf20Sopenharmony_ci return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size); 9828c2ecf20Sopenharmony_ci } 9838c2ecf20Sopenharmony_ci return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size); 9848c2ecf20Sopenharmony_ci} 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_cistatic int bnxt_vf_validate_set_mac(struct bnxt *bp, struct bnxt_vf_info *vf) 9878c2ecf20Sopenharmony_ci{ 9888c2ecf20Sopenharmony_ci u32 msg_size = sizeof(struct hwrm_cfa_l2_filter_alloc_input); 9898c2ecf20Sopenharmony_ci struct hwrm_cfa_l2_filter_alloc_input *req = 9908c2ecf20Sopenharmony_ci (struct hwrm_cfa_l2_filter_alloc_input *)vf->hwrm_cmd_req_addr; 9918c2ecf20Sopenharmony_ci bool mac_ok = false; 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_ci if (!is_valid_ether_addr((const u8 *)req->l2_addr)) 9948c2ecf20Sopenharmony_ci return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size); 9958c2ecf20Sopenharmony_ci 9968c2ecf20Sopenharmony_ci /* Allow VF to set a valid MAC address, if trust is set to on. 9978c2ecf20Sopenharmony_ci * Or VF MAC address must first match MAC address in PF's context. 9988c2ecf20Sopenharmony_ci * Otherwise, it must match the VF MAC address if firmware spec >= 9998c2ecf20Sopenharmony_ci * 1.2.2 10008c2ecf20Sopenharmony_ci */ 10018c2ecf20Sopenharmony_ci if (bnxt_is_trusted_vf(bp, vf)) { 10028c2ecf20Sopenharmony_ci mac_ok = true; 10038c2ecf20Sopenharmony_ci } else if (is_valid_ether_addr(vf->mac_addr)) { 10048c2ecf20Sopenharmony_ci if (ether_addr_equal((const u8 *)req->l2_addr, vf->mac_addr)) 10058c2ecf20Sopenharmony_ci mac_ok = true; 10068c2ecf20Sopenharmony_ci } else if (is_valid_ether_addr(vf->vf_mac_addr)) { 10078c2ecf20Sopenharmony_ci if (ether_addr_equal((const u8 *)req->l2_addr, vf->vf_mac_addr)) 10088c2ecf20Sopenharmony_ci mac_ok = true; 10098c2ecf20Sopenharmony_ci } else { 10108c2ecf20Sopenharmony_ci /* There are two cases: 10118c2ecf20Sopenharmony_ci * 1.If firmware spec < 0x10202,VF MAC address is not forwarded 10128c2ecf20Sopenharmony_ci * to the PF and so it doesn't have to match 10138c2ecf20Sopenharmony_ci * 2.Allow VF to modify it's own MAC when PF has not assigned a 10148c2ecf20Sopenharmony_ci * valid MAC address and firmware spec >= 0x10202 10158c2ecf20Sopenharmony_ci */ 10168c2ecf20Sopenharmony_ci mac_ok = true; 10178c2ecf20Sopenharmony_ci } 10188c2ecf20Sopenharmony_ci if (mac_ok) 10198c2ecf20Sopenharmony_ci return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size); 10208c2ecf20Sopenharmony_ci return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size); 10218c2ecf20Sopenharmony_ci} 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_cistatic int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf) 10248c2ecf20Sopenharmony_ci{ 10258c2ecf20Sopenharmony_ci int rc = 0; 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci if (!(vf->flags & BNXT_VF_LINK_FORCED)) { 10288c2ecf20Sopenharmony_ci /* real link */ 10298c2ecf20Sopenharmony_ci rc = bnxt_hwrm_exec_fwd_resp( 10308c2ecf20Sopenharmony_ci bp, vf, sizeof(struct hwrm_port_phy_qcfg_input)); 10318c2ecf20Sopenharmony_ci } else { 10328c2ecf20Sopenharmony_ci struct hwrm_port_phy_qcfg_output phy_qcfg_resp = {0}; 10338c2ecf20Sopenharmony_ci struct hwrm_port_phy_qcfg_input *phy_qcfg_req; 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci phy_qcfg_req = 10368c2ecf20Sopenharmony_ci (struct hwrm_port_phy_qcfg_input *)vf->hwrm_cmd_req_addr; 10378c2ecf20Sopenharmony_ci mutex_lock(&bp->hwrm_cmd_lock); 10388c2ecf20Sopenharmony_ci memcpy(&phy_qcfg_resp, &bp->link_info.phy_qcfg_resp, 10398c2ecf20Sopenharmony_ci sizeof(phy_qcfg_resp)); 10408c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 10418c2ecf20Sopenharmony_ci phy_qcfg_resp.resp_len = cpu_to_le16(sizeof(phy_qcfg_resp)); 10428c2ecf20Sopenharmony_ci phy_qcfg_resp.seq_id = phy_qcfg_req->seq_id; 10438c2ecf20Sopenharmony_ci phy_qcfg_resp.valid = 1; 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci if (vf->flags & BNXT_VF_LINK_UP) { 10468c2ecf20Sopenharmony_ci /* if physical link is down, force link up on VF */ 10478c2ecf20Sopenharmony_ci if (phy_qcfg_resp.link != 10488c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_LINK_LINK) { 10498c2ecf20Sopenharmony_ci phy_qcfg_resp.link = 10508c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_LINK_LINK; 10518c2ecf20Sopenharmony_ci phy_qcfg_resp.link_speed = cpu_to_le16( 10528c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_LINK_SPEED_10GB); 10538c2ecf20Sopenharmony_ci phy_qcfg_resp.duplex_cfg = 10548c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_DUPLEX_CFG_FULL; 10558c2ecf20Sopenharmony_ci phy_qcfg_resp.duplex_state = 10568c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_DUPLEX_STATE_FULL; 10578c2ecf20Sopenharmony_ci phy_qcfg_resp.pause = 10588c2ecf20Sopenharmony_ci (PORT_PHY_QCFG_RESP_PAUSE_TX | 10598c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_PAUSE_RX); 10608c2ecf20Sopenharmony_ci } 10618c2ecf20Sopenharmony_ci } else { 10628c2ecf20Sopenharmony_ci /* force link down */ 10638c2ecf20Sopenharmony_ci phy_qcfg_resp.link = PORT_PHY_QCFG_RESP_LINK_NO_LINK; 10648c2ecf20Sopenharmony_ci phy_qcfg_resp.link_speed = 0; 10658c2ecf20Sopenharmony_ci phy_qcfg_resp.duplex_state = 10668c2ecf20Sopenharmony_ci PORT_PHY_QCFG_RESP_DUPLEX_STATE_HALF; 10678c2ecf20Sopenharmony_ci phy_qcfg_resp.pause = 0; 10688c2ecf20Sopenharmony_ci } 10698c2ecf20Sopenharmony_ci rc = bnxt_hwrm_fwd_resp(bp, vf, &phy_qcfg_resp, 10708c2ecf20Sopenharmony_ci phy_qcfg_req->resp_addr, 10718c2ecf20Sopenharmony_ci phy_qcfg_req->cmpl_ring, 10728c2ecf20Sopenharmony_ci sizeof(phy_qcfg_resp)); 10738c2ecf20Sopenharmony_ci } 10748c2ecf20Sopenharmony_ci return rc; 10758c2ecf20Sopenharmony_ci} 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_cistatic int bnxt_vf_req_validate_snd(struct bnxt *bp, struct bnxt_vf_info *vf) 10788c2ecf20Sopenharmony_ci{ 10798c2ecf20Sopenharmony_ci int rc = 0; 10808c2ecf20Sopenharmony_ci struct input *encap_req = vf->hwrm_cmd_req_addr; 10818c2ecf20Sopenharmony_ci u32 req_type = le16_to_cpu(encap_req->req_type); 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci switch (req_type) { 10848c2ecf20Sopenharmony_ci case HWRM_FUNC_VF_CFG: 10858c2ecf20Sopenharmony_ci rc = bnxt_vf_configure_mac(bp, vf); 10868c2ecf20Sopenharmony_ci break; 10878c2ecf20Sopenharmony_ci case HWRM_CFA_L2_FILTER_ALLOC: 10888c2ecf20Sopenharmony_ci rc = bnxt_vf_validate_set_mac(bp, vf); 10898c2ecf20Sopenharmony_ci break; 10908c2ecf20Sopenharmony_ci case HWRM_FUNC_CFG: 10918c2ecf20Sopenharmony_ci /* TODO Validate if VF is allowed to change mac address, 10928c2ecf20Sopenharmony_ci * mtu, num of rings etc 10938c2ecf20Sopenharmony_ci */ 10948c2ecf20Sopenharmony_ci rc = bnxt_hwrm_exec_fwd_resp( 10958c2ecf20Sopenharmony_ci bp, vf, sizeof(struct hwrm_func_cfg_input)); 10968c2ecf20Sopenharmony_ci break; 10978c2ecf20Sopenharmony_ci case HWRM_PORT_PHY_QCFG: 10988c2ecf20Sopenharmony_ci rc = bnxt_vf_set_link(bp, vf); 10998c2ecf20Sopenharmony_ci break; 11008c2ecf20Sopenharmony_ci default: 11018c2ecf20Sopenharmony_ci break; 11028c2ecf20Sopenharmony_ci } 11038c2ecf20Sopenharmony_ci return rc; 11048c2ecf20Sopenharmony_ci} 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_civoid bnxt_hwrm_exec_fwd_req(struct bnxt *bp) 11078c2ecf20Sopenharmony_ci{ 11088c2ecf20Sopenharmony_ci u32 i = 0, active_vfs = bp->pf.active_vfs, vf_id; 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci /* Scan through VF's and process commands */ 11118c2ecf20Sopenharmony_ci while (1) { 11128c2ecf20Sopenharmony_ci vf_id = find_next_bit(bp->pf.vf_event_bmap, active_vfs, i); 11138c2ecf20Sopenharmony_ci if (vf_id >= active_vfs) 11148c2ecf20Sopenharmony_ci break; 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_ci clear_bit(vf_id, bp->pf.vf_event_bmap); 11178c2ecf20Sopenharmony_ci bnxt_vf_req_validate_snd(bp, &bp->pf.vf[vf_id]); 11188c2ecf20Sopenharmony_ci i = vf_id + 1; 11198c2ecf20Sopenharmony_ci } 11208c2ecf20Sopenharmony_ci} 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_civoid bnxt_update_vf_mac(struct bnxt *bp) 11238c2ecf20Sopenharmony_ci{ 11248c2ecf20Sopenharmony_ci struct hwrm_func_qcaps_input req = {0}; 11258c2ecf20Sopenharmony_ci struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1); 11288c2ecf20Sopenharmony_ci req.fid = cpu_to_le16(0xffff); 11298c2ecf20Sopenharmony_ci 11308c2ecf20Sopenharmony_ci mutex_lock(&bp->hwrm_cmd_lock); 11318c2ecf20Sopenharmony_ci if (_hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT)) 11328c2ecf20Sopenharmony_ci goto update_vf_mac_exit; 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci /* Store MAC address from the firmware. There are 2 cases: 11358c2ecf20Sopenharmony_ci * 1. MAC address is valid. It is assigned from the PF and we 11368c2ecf20Sopenharmony_ci * need to override the current VF MAC address with it. 11378c2ecf20Sopenharmony_ci * 2. MAC address is zero. The VF will use a random MAC address by 11388c2ecf20Sopenharmony_ci * default but the stored zero MAC will allow the VF user to change 11398c2ecf20Sopenharmony_ci * the random MAC address using ndo_set_mac_address() if he wants. 11408c2ecf20Sopenharmony_ci */ 11418c2ecf20Sopenharmony_ci if (!ether_addr_equal(resp->mac_address, bp->vf.mac_addr)) 11428c2ecf20Sopenharmony_ci memcpy(bp->vf.mac_addr, resp->mac_address, ETH_ALEN); 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci /* overwrite netdev dev_addr with admin VF MAC */ 11458c2ecf20Sopenharmony_ci if (is_valid_ether_addr(bp->vf.mac_addr)) 11468c2ecf20Sopenharmony_ci memcpy(bp->dev->dev_addr, bp->vf.mac_addr, ETH_ALEN); 11478c2ecf20Sopenharmony_ciupdate_vf_mac_exit: 11488c2ecf20Sopenharmony_ci mutex_unlock(&bp->hwrm_cmd_lock); 11498c2ecf20Sopenharmony_ci} 11508c2ecf20Sopenharmony_ci 11518c2ecf20Sopenharmony_ciint bnxt_approve_mac(struct bnxt *bp, u8 *mac, bool strict) 11528c2ecf20Sopenharmony_ci{ 11538c2ecf20Sopenharmony_ci struct hwrm_func_vf_cfg_input req = {0}; 11548c2ecf20Sopenharmony_ci int rc = 0; 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci if (!BNXT_VF(bp)) 11578c2ecf20Sopenharmony_ci return 0; 11588c2ecf20Sopenharmony_ci 11598c2ecf20Sopenharmony_ci if (bp->hwrm_spec_code < 0x10202) { 11608c2ecf20Sopenharmony_ci if (is_valid_ether_addr(bp->vf.mac_addr)) 11618c2ecf20Sopenharmony_ci rc = -EADDRNOTAVAIL; 11628c2ecf20Sopenharmony_ci goto mac_done; 11638c2ecf20Sopenharmony_ci } 11648c2ecf20Sopenharmony_ci bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); 11658c2ecf20Sopenharmony_ci req.enables = cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_DFLT_MAC_ADDR); 11668c2ecf20Sopenharmony_ci memcpy(req.dflt_mac_addr, mac, ETH_ALEN); 11678c2ecf20Sopenharmony_ci rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 11688c2ecf20Sopenharmony_cimac_done: 11698c2ecf20Sopenharmony_ci if (rc && strict) { 11708c2ecf20Sopenharmony_ci rc = -EADDRNOTAVAIL; 11718c2ecf20Sopenharmony_ci netdev_warn(bp->dev, "VF MAC address %pM not approved by the PF\n", 11728c2ecf20Sopenharmony_ci mac); 11738c2ecf20Sopenharmony_ci return rc; 11748c2ecf20Sopenharmony_ci } 11758c2ecf20Sopenharmony_ci return 0; 11768c2ecf20Sopenharmony_ci} 11778c2ecf20Sopenharmony_ci#else 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_ciint bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset) 11808c2ecf20Sopenharmony_ci{ 11818c2ecf20Sopenharmony_ci if (*num_vfs) 11828c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 11838c2ecf20Sopenharmony_ci return 0; 11848c2ecf20Sopenharmony_ci} 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_civoid bnxt_sriov_disable(struct bnxt *bp) 11878c2ecf20Sopenharmony_ci{ 11888c2ecf20Sopenharmony_ci} 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_civoid bnxt_hwrm_exec_fwd_req(struct bnxt *bp) 11918c2ecf20Sopenharmony_ci{ 11928c2ecf20Sopenharmony_ci netdev_err(bp->dev, "Invalid VF message received when SRIOV is not enable\n"); 11938c2ecf20Sopenharmony_ci} 11948c2ecf20Sopenharmony_ci 11958c2ecf20Sopenharmony_civoid bnxt_update_vf_mac(struct bnxt *bp) 11968c2ecf20Sopenharmony_ci{ 11978c2ecf20Sopenharmony_ci} 11988c2ecf20Sopenharmony_ci 11998c2ecf20Sopenharmony_ciint bnxt_approve_mac(struct bnxt *bp, u8 *mac, bool strict) 12008c2ecf20Sopenharmony_ci{ 12018c2ecf20Sopenharmony_ci return 0; 12028c2ecf20Sopenharmony_ci} 12038c2ecf20Sopenharmony_ci#endif 1204