xref: /linux/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c (revision 9410645520e9b820069761f3450ef6661418e279)
1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver.
2c0c050c5SMichael Chan  *
311f15ed3SMichael Chan  * Copyright (c) 2014-2016 Broadcom Corporation
4746df139SVasundhara Volam  * Copyright (c) 2016-2018 Broadcom Limited
5c0c050c5SMichael Chan  *
6c0c050c5SMichael Chan  * This program is free software; you can redistribute it and/or modify
7c0c050c5SMichael Chan  * it under the terms of the GNU General Public License as published by
8c0c050c5SMichael Chan  * the Free Software Foundation.
9c0c050c5SMichael Chan  */
10c0c050c5SMichael Chan 
11cc69837fSJakub Kicinski #include <linux/ethtool.h>
12c0c050c5SMichael Chan #include <linux/module.h>
13c0c050c5SMichael Chan #include <linux/pci.h>
14c0c050c5SMichael Chan #include <linux/netdevice.h>
15c0c050c5SMichael Chan #include <linux/if_vlan.h>
16c0c050c5SMichael Chan #include <linux/interrupt.h>
17c0c050c5SMichael Chan #include <linux/etherdevice.h>
18*26e3846eSSreekanth Reddy #include <net/dcbnl.h>
19c0c050c5SMichael Chan #include "bnxt_hsi.h"
20c0c050c5SMichael Chan #include "bnxt.h"
213c8c20dbSEdwin Peer #include "bnxt_hwrm.h"
222f593846SMichael Chan #include "bnxt_ulp.h"
23c0c050c5SMichael Chan #include "bnxt_sriov.h"
244ab0c6a8SSathya Perla #include "bnxt_vfr.h"
25c0c050c5SMichael Chan #include "bnxt_ethtool.h"
26c0c050c5SMichael Chan 
27c0c050c5SMichael Chan #ifdef CONFIG_BNXT_SRIOV
bnxt_hwrm_fwd_async_event_cmpl(struct bnxt * bp,struct bnxt_vf_info * vf,u16 event_id)28350a7149SEddie Wai static int bnxt_hwrm_fwd_async_event_cmpl(struct bnxt *bp,
29350a7149SEddie Wai 					  struct bnxt_vf_info *vf, u16 event_id)
30350a7149SEddie Wai {
31bbf33d1dSEdwin Peer 	struct hwrm_fwd_async_event_cmpl_input *req;
32350a7149SEddie Wai 	struct hwrm_async_event_cmpl *async_cmpl;
33350a7149SEddie Wai 	int rc = 0;
34350a7149SEddie Wai 
35bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FWD_ASYNC_EVENT_CMPL);
36bbf33d1dSEdwin Peer 	if (rc)
37bbf33d1dSEdwin Peer 		goto exit;
38bbf33d1dSEdwin Peer 
39350a7149SEddie Wai 	if (vf)
40bbf33d1dSEdwin Peer 		req->encap_async_event_target_id = cpu_to_le16(vf->fw_fid);
41350a7149SEddie Wai 	else
42350a7149SEddie Wai 		/* broadcast this async event to all VFs */
43bbf33d1dSEdwin Peer 		req->encap_async_event_target_id = cpu_to_le16(0xffff);
44bbf33d1dSEdwin Peer 	async_cmpl =
45bbf33d1dSEdwin Peer 		(struct hwrm_async_event_cmpl *)req->encap_async_event_cmpl;
4687c374deSMichael Chan 	async_cmpl->type = cpu_to_le16(ASYNC_EVENT_CMPL_TYPE_HWRM_ASYNC_EVENT);
47350a7149SEddie Wai 	async_cmpl->event_id = cpu_to_le16(event_id);
48350a7149SEddie Wai 
49bbf33d1dSEdwin Peer 	rc = hwrm_req_send(bp, req);
50bbf33d1dSEdwin Peer exit:
51a798302dSMichael Chan 	if (rc)
52350a7149SEddie Wai 		netdev_err(bp->dev, "hwrm_fwd_async_event_cmpl failed. rc:%d\n",
53350a7149SEddie Wai 			   rc);
54350a7149SEddie Wai 	return rc;
55350a7149SEddie Wai }
56350a7149SEddie Wai 
bnxt_vf_ndo_prep(struct bnxt * bp,int vf_id)57c0c050c5SMichael Chan static int bnxt_vf_ndo_prep(struct bnxt *bp, int vf_id)
58c0c050c5SMichael Chan {
59c0c050c5SMichael Chan 	if (!bp->pf.active_vfs) {
60c0c050c5SMichael Chan 		netdev_err(bp->dev, "vf ndo called though sriov is disabled\n");
61c0c050c5SMichael Chan 		return -EINVAL;
62c0c050c5SMichael Chan 	}
6378f30004SVenkat Duvvuru 	if (vf_id >= bp->pf.active_vfs) {
64c0c050c5SMichael Chan 		netdev_err(bp->dev, "Invalid VF id %d\n", vf_id);
65c0c050c5SMichael Chan 		return -EINVAL;
66c0c050c5SMichael Chan 	}
67c0c050c5SMichael Chan 	return 0;
68c0c050c5SMichael Chan }
69c0c050c5SMichael Chan 
bnxt_set_vf_spoofchk(struct net_device * dev,int vf_id,bool setting)70c0c050c5SMichael Chan int bnxt_set_vf_spoofchk(struct net_device *dev, int vf_id, bool setting)
71c0c050c5SMichael Chan {
72c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
73bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
74c0c050c5SMichael Chan 	bool old_setting = false;
75bbf33d1dSEdwin Peer 	struct bnxt_vf_info *vf;
76c0c050c5SMichael Chan 	u32 func_flags;
77c0c050c5SMichael Chan 	int rc;
78c0c050c5SMichael Chan 
798eb992e8SMichael Chan 	if (bp->hwrm_spec_code < 0x10701)
808eb992e8SMichael Chan 		return -ENOTSUPP;
818eb992e8SMichael Chan 
82c0c050c5SMichael Chan 	rc = bnxt_vf_ndo_prep(bp, vf_id);
83c0c050c5SMichael Chan 	if (rc)
84c0c050c5SMichael Chan 		return rc;
85c0c050c5SMichael Chan 
86c0c050c5SMichael Chan 	vf = &bp->pf.vf[vf_id];
87c0c050c5SMichael Chan 	if (vf->flags & BNXT_VF_SPOOFCHK)
88c0c050c5SMichael Chan 		old_setting = true;
89c0c050c5SMichael Chan 	if (old_setting == setting)
90c0c050c5SMichael Chan 		return 0;
91c0c050c5SMichael Chan 
92c0c050c5SMichael Chan 	if (setting)
93c71c4e49SMichael Chan 		func_flags = FUNC_CFG_REQ_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE;
94c0c050c5SMichael Chan 	else
95c71c4e49SMichael Chan 		func_flags = FUNC_CFG_REQ_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE;
96c0c050c5SMichael Chan 	/*TODO: if the driver supports VLAN filter on guest VLAN,
97c0c050c5SMichael Chan 	 * the spoof check should also include vlan anti-spoofing
98c0c050c5SMichael Chan 	 */
9973b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
100bbf33d1dSEdwin Peer 	if (!rc) {
101bbf33d1dSEdwin Peer 		req->fid = cpu_to_le16(vf->fw_fid);
102bbf33d1dSEdwin Peer 		req->flags = cpu_to_le32(func_flags);
103bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
104c0c050c5SMichael Chan 		if (!rc) {
105c0c050c5SMichael Chan 			if (setting)
106c0c050c5SMichael Chan 				vf->flags |= BNXT_VF_SPOOFCHK;
107c0c050c5SMichael Chan 			else
108c0c050c5SMichael Chan 				vf->flags &= ~BNXT_VF_SPOOFCHK;
109c0c050c5SMichael Chan 		}
110bbf33d1dSEdwin Peer 	}
111c0c050c5SMichael Chan 	return rc;
112c0c050c5SMichael Chan }
113c0c050c5SMichael Chan 
bnxt_hwrm_func_qcfg_flags(struct bnxt * bp,struct bnxt_vf_info * vf)1142a516444SMichael Chan static int bnxt_hwrm_func_qcfg_flags(struct bnxt *bp, struct bnxt_vf_info *vf)
1152a516444SMichael Chan {
116bbf33d1dSEdwin Peer 	struct hwrm_func_qcfg_output *resp;
117bbf33d1dSEdwin Peer 	struct hwrm_func_qcfg_input *req;
1182a516444SMichael Chan 	int rc;
1192a516444SMichael Chan 
120bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FUNC_QCFG);
121bbf33d1dSEdwin Peer 	if (rc)
122d4f1420dSMichael Chan 		return rc;
123bbf33d1dSEdwin Peer 
124bbf33d1dSEdwin Peer 	req->fid = cpu_to_le16(BNXT_PF(bp) ? vf->fw_fid : 0xffff);
125bbf33d1dSEdwin Peer 	resp = hwrm_req_hold(bp, req);
126bbf33d1dSEdwin Peer 	rc = hwrm_req_send(bp, req);
127bbf33d1dSEdwin Peer 	if (!rc)
1282a516444SMichael Chan 		vf->func_qcfg_flags = le16_to_cpu(resp->flags);
129bbf33d1dSEdwin Peer 	hwrm_req_drop(bp, req);
130bbf33d1dSEdwin Peer 	return rc;
1312a516444SMichael Chan }
1322a516444SMichael Chan 
bnxt_is_trusted_vf(struct bnxt * bp,struct bnxt_vf_info * vf)133dd85fc0aSEdwin Peer bool bnxt_is_trusted_vf(struct bnxt *bp, struct bnxt_vf_info *vf)
1342a516444SMichael Chan {
135dd85fc0aSEdwin Peer 	if (BNXT_PF(bp) && !(bp->fw_cap & BNXT_FW_CAP_TRUSTED_VF))
1362a516444SMichael Chan 		return !!(vf->flags & BNXT_VF_TRUST);
1372a516444SMichael Chan 
1382a516444SMichael Chan 	bnxt_hwrm_func_qcfg_flags(bp, vf);
1392a516444SMichael Chan 	return !!(vf->func_qcfg_flags & FUNC_QCFG_RESP_FLAGS_TRUSTED_VF);
1402a516444SMichael Chan }
1412a516444SMichael Chan 
bnxt_hwrm_set_trusted_vf(struct bnxt * bp,struct bnxt_vf_info * vf)1422a516444SMichael Chan static int bnxt_hwrm_set_trusted_vf(struct bnxt *bp, struct bnxt_vf_info *vf)
1432a516444SMichael Chan {
144bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
145bbf33d1dSEdwin Peer 	int rc;
1462a516444SMichael Chan 
1472a516444SMichael Chan 	if (!(bp->fw_cap & BNXT_FW_CAP_TRUSTED_VF))
1482a516444SMichael Chan 		return 0;
1492a516444SMichael Chan 
15073b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
151bbf33d1dSEdwin Peer 	if (rc)
152bbf33d1dSEdwin Peer 		return rc;
153bbf33d1dSEdwin Peer 
154bbf33d1dSEdwin Peer 	req->fid = cpu_to_le16(vf->fw_fid);
1552a516444SMichael Chan 	if (vf->flags & BNXT_VF_TRUST)
156bbf33d1dSEdwin Peer 		req->flags = cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_ENABLE);
1572a516444SMichael Chan 	else
158bbf33d1dSEdwin Peer 		req->flags = cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_DISABLE);
159bbf33d1dSEdwin Peer 	return hwrm_req_send(bp, req);
1602a516444SMichael Chan }
1612a516444SMichael Chan 
bnxt_set_vf_trust(struct net_device * dev,int vf_id,bool trusted)162746df139SVasundhara Volam int bnxt_set_vf_trust(struct net_device *dev, int vf_id, bool trusted)
163746df139SVasundhara Volam {
164746df139SVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
165746df139SVasundhara Volam 	struct bnxt_vf_info *vf;
166746df139SVasundhara Volam 
167746df139SVasundhara Volam 	if (bnxt_vf_ndo_prep(bp, vf_id))
168746df139SVasundhara Volam 		return -EINVAL;
169746df139SVasundhara Volam 
170746df139SVasundhara Volam 	vf = &bp->pf.vf[vf_id];
171746df139SVasundhara Volam 	if (trusted)
172746df139SVasundhara Volam 		vf->flags |= BNXT_VF_TRUST;
173746df139SVasundhara Volam 	else
174746df139SVasundhara Volam 		vf->flags &= ~BNXT_VF_TRUST;
175746df139SVasundhara Volam 
1762a516444SMichael Chan 	bnxt_hwrm_set_trusted_vf(bp, vf);
177746df139SVasundhara Volam 	return 0;
178746df139SVasundhara Volam }
179746df139SVasundhara Volam 
bnxt_get_vf_config(struct net_device * dev,int vf_id,struct ifla_vf_info * ivi)180c0c050c5SMichael Chan int bnxt_get_vf_config(struct net_device *dev, int vf_id,
181c0c050c5SMichael Chan 		       struct ifla_vf_info *ivi)
182c0c050c5SMichael Chan {
183c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
184c0c050c5SMichael Chan 	struct bnxt_vf_info *vf;
185c0c050c5SMichael Chan 	int rc;
186c0c050c5SMichael Chan 
187c0c050c5SMichael Chan 	rc = bnxt_vf_ndo_prep(bp, vf_id);
188c0c050c5SMichael Chan 	if (rc)
189c0c050c5SMichael Chan 		return rc;
190c0c050c5SMichael Chan 
191c0c050c5SMichael Chan 	ivi->vf = vf_id;
192c0c050c5SMichael Chan 	vf = &bp->pf.vf[vf_id];
193c0c050c5SMichael Chan 
19491cdda40SVasundhara Volam 	if (is_valid_ether_addr(vf->mac_addr))
195c0c050c5SMichael Chan 		memcpy(&ivi->mac, vf->mac_addr, ETH_ALEN);
19691cdda40SVasundhara Volam 	else
19791cdda40SVasundhara Volam 		memcpy(&ivi->mac, vf->vf_mac_addr, ETH_ALEN);
198c0c050c5SMichael Chan 	ivi->max_tx_rate = vf->max_tx_rate;
199c0c050c5SMichael Chan 	ivi->min_tx_rate = vf->min_tx_rate;
200*26e3846eSSreekanth Reddy 	ivi->vlan = vf->vlan & VLAN_VID_MASK;
201f0249056SMichael Chan 	ivi->qos = vf->vlan >> VLAN_PRIO_SHIFT;
202f0249056SMichael Chan 	ivi->spoofchk = !!(vf->flags & BNXT_VF_SPOOFCHK);
2032a516444SMichael Chan 	ivi->trusted = bnxt_is_trusted_vf(bp, vf);
204c0c050c5SMichael Chan 	if (!(vf->flags & BNXT_VF_LINK_FORCED))
205c0c050c5SMichael Chan 		ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
206c0c050c5SMichael Chan 	else if (vf->flags & BNXT_VF_LINK_UP)
207c0c050c5SMichael Chan 		ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
208c0c050c5SMichael Chan 	else
209c0c050c5SMichael Chan 		ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
210c0c050c5SMichael Chan 
211c0c050c5SMichael Chan 	return 0;
212c0c050c5SMichael Chan }
213c0c050c5SMichael Chan 
bnxt_set_vf_mac(struct net_device * dev,int vf_id,u8 * mac)214c0c050c5SMichael Chan int bnxt_set_vf_mac(struct net_device *dev, int vf_id, u8 *mac)
215c0c050c5SMichael Chan {
216c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
217bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
218c0c050c5SMichael Chan 	struct bnxt_vf_info *vf;
219c0c050c5SMichael Chan 	int rc;
220c0c050c5SMichael Chan 
221c0c050c5SMichael Chan 	rc = bnxt_vf_ndo_prep(bp, vf_id);
222c0c050c5SMichael Chan 	if (rc)
223c0c050c5SMichael Chan 		return rc;
224c0c050c5SMichael Chan 	/* reject bc or mc mac addr, zero mac addr means allow
225c0c050c5SMichael Chan 	 * VF to use its own mac addr
226c0c050c5SMichael Chan 	 */
227c0c050c5SMichael Chan 	if (is_multicast_ether_addr(mac)) {
228c0c050c5SMichael Chan 		netdev_err(dev, "Invalid VF ethernet address\n");
229c0c050c5SMichael Chan 		return -EINVAL;
230c0c050c5SMichael Chan 	}
231c0c050c5SMichael Chan 	vf = &bp->pf.vf[vf_id];
232c0c050c5SMichael Chan 
23373b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
234bbf33d1dSEdwin Peer 	if (rc)
235bbf33d1dSEdwin Peer 		return rc;
236bbf33d1dSEdwin Peer 
237c0c050c5SMichael Chan 	memcpy(vf->mac_addr, mac, ETH_ALEN);
238bbf33d1dSEdwin Peer 
239bbf33d1dSEdwin Peer 	req->fid = cpu_to_le16(vf->fw_fid);
240bbf33d1dSEdwin Peer 	req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_MAC_ADDR);
241bbf33d1dSEdwin Peer 	memcpy(req->dflt_mac_addr, mac, ETH_ALEN);
242bbf33d1dSEdwin Peer 	return hwrm_req_send(bp, req);
243c0c050c5SMichael Chan }
244c0c050c5SMichael Chan 
bnxt_set_vf_vlan(struct net_device * dev,int vf_id,u16 vlan_id,u8 qos,__be16 vlan_proto)24579aab093SMoshe Shemesh int bnxt_set_vf_vlan(struct net_device *dev, int vf_id, u16 vlan_id, u8 qos,
24679aab093SMoshe Shemesh 		     __be16 vlan_proto)
247c0c050c5SMichael Chan {
248c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
249bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
250c0c050c5SMichael Chan 	struct bnxt_vf_info *vf;
251c0c050c5SMichael Chan 	u16 vlan_tag;
252c0c050c5SMichael Chan 	int rc;
253c0c050c5SMichael Chan 
254cf6645f8SMichael Chan 	if (bp->hwrm_spec_code < 0x10201)
255cf6645f8SMichael Chan 		return -ENOTSUPP;
256cf6645f8SMichael Chan 
257*26e3846eSSreekanth Reddy 	if (vlan_proto != htons(ETH_P_8021Q) &&
258*26e3846eSSreekanth Reddy 	    (vlan_proto != htons(ETH_P_8021AD) ||
259*26e3846eSSreekanth Reddy 	     !(bp->fw_cap & BNXT_FW_CAP_DFLT_VLAN_TPID_PCP)))
26079aab093SMoshe Shemesh 		return -EPROTONOSUPPORT;
26179aab093SMoshe Shemesh 
262c0c050c5SMichael Chan 	rc = bnxt_vf_ndo_prep(bp, vf_id);
263c0c050c5SMichael Chan 	if (rc)
264c0c050c5SMichael Chan 		return rc;
265c0c050c5SMichael Chan 
266*26e3846eSSreekanth Reddy 	if (vlan_id >= VLAN_N_VID || qos >= IEEE_8021Q_MAX_PRIORITIES ||
267*26e3846eSSreekanth Reddy 	    (!vlan_id && qos))
268c0c050c5SMichael Chan 		return -EINVAL;
269c0c050c5SMichael Chan 
270c0c050c5SMichael Chan 	vf = &bp->pf.vf[vf_id];
271*26e3846eSSreekanth Reddy 	vlan_tag = vlan_id | (u16)qos << VLAN_PRIO_SHIFT;
272c0c050c5SMichael Chan 	if (vlan_tag == vf->vlan)
273c0c050c5SMichael Chan 		return 0;
274c0c050c5SMichael Chan 
27573b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
276bbf33d1dSEdwin Peer 	if (!rc) {
277bbf33d1dSEdwin Peer 		req->fid = cpu_to_le16(vf->fw_fid);
278bbf33d1dSEdwin Peer 		req->dflt_vlan = cpu_to_le16(vlan_tag);
279bbf33d1dSEdwin Peer 		req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_VLAN);
280*26e3846eSSreekanth Reddy 		if (bp->fw_cap & BNXT_FW_CAP_DFLT_VLAN_TPID_PCP) {
281*26e3846eSSreekanth Reddy 			req->enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_TPID);
282*26e3846eSSreekanth Reddy 			req->tpid = vlan_proto;
283*26e3846eSSreekanth Reddy 		}
284bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
285c0c050c5SMichael Chan 		if (!rc)
286c0c050c5SMichael Chan 			vf->vlan = vlan_tag;
287bbf33d1dSEdwin Peer 	}
288c0c050c5SMichael Chan 	return rc;
289c0c050c5SMichael Chan }
290c0c050c5SMichael Chan 
bnxt_set_vf_bw(struct net_device * dev,int vf_id,int min_tx_rate,int max_tx_rate)291c0c050c5SMichael Chan int bnxt_set_vf_bw(struct net_device *dev, int vf_id, int min_tx_rate,
292c0c050c5SMichael Chan 		   int max_tx_rate)
293c0c050c5SMichael Chan {
294c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
295bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
296c0c050c5SMichael Chan 	struct bnxt_vf_info *vf;
297c0c050c5SMichael Chan 	u32 pf_link_speed;
298c0c050c5SMichael Chan 	int rc;
299c0c050c5SMichael Chan 
300c0c050c5SMichael Chan 	rc = bnxt_vf_ndo_prep(bp, vf_id);
301c0c050c5SMichael Chan 	if (rc)
302c0c050c5SMichael Chan 		return rc;
303c0c050c5SMichael Chan 
304c0c050c5SMichael Chan 	vf = &bp->pf.vf[vf_id];
305c0c050c5SMichael Chan 	pf_link_speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
306c0c050c5SMichael Chan 	if (max_tx_rate > pf_link_speed) {
307c0c050c5SMichael Chan 		netdev_info(bp->dev, "max tx rate %d exceed PF link speed for VF %d\n",
308c0c050c5SMichael Chan 			    max_tx_rate, vf_id);
309c0c050c5SMichael Chan 		return -EINVAL;
310c0c050c5SMichael Chan 	}
311c0c050c5SMichael Chan 
31210e11aa2SBin Chen 	if (min_tx_rate > pf_link_speed) {
313c0c050c5SMichael Chan 		netdev_info(bp->dev, "min tx rate %d is invalid for VF %d\n",
314c0c050c5SMichael Chan 			    min_tx_rate, vf_id);
315c0c050c5SMichael Chan 		return -EINVAL;
316c0c050c5SMichael Chan 	}
317c0c050c5SMichael Chan 	if (min_tx_rate == vf->min_tx_rate && max_tx_rate == vf->max_tx_rate)
318c0c050c5SMichael Chan 		return 0;
31973b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
320bbf33d1dSEdwin Peer 	if (!rc) {
321bbf33d1dSEdwin Peer 		req->fid = cpu_to_le16(vf->fw_fid);
322bbf33d1dSEdwin Peer 		req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_MAX_BW |
323bbf33d1dSEdwin Peer 					   FUNC_CFG_REQ_ENABLES_MIN_BW);
324bbf33d1dSEdwin Peer 		req->max_bw = cpu_to_le32(max_tx_rate);
325bbf33d1dSEdwin Peer 		req->min_bw = cpu_to_le32(min_tx_rate);
326bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
327c0c050c5SMichael Chan 		if (!rc) {
328c0c050c5SMichael Chan 			vf->min_tx_rate = min_tx_rate;
329c0c050c5SMichael Chan 			vf->max_tx_rate = max_tx_rate;
330c0c050c5SMichael Chan 		}
331bbf33d1dSEdwin Peer 	}
332c0c050c5SMichael Chan 	return rc;
333c0c050c5SMichael Chan }
334c0c050c5SMichael Chan 
bnxt_set_vf_link_state(struct net_device * dev,int vf_id,int link)335c0c050c5SMichael Chan int bnxt_set_vf_link_state(struct net_device *dev, int vf_id, int link)
336c0c050c5SMichael Chan {
337c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
338c0c050c5SMichael Chan 	struct bnxt_vf_info *vf;
339c0c050c5SMichael Chan 	int rc;
340c0c050c5SMichael Chan 
341c0c050c5SMichael Chan 	rc = bnxt_vf_ndo_prep(bp, vf_id);
342c0c050c5SMichael Chan 	if (rc)
343c0c050c5SMichael Chan 		return rc;
344c0c050c5SMichael Chan 
345c0c050c5SMichael Chan 	vf = &bp->pf.vf[vf_id];
346c0c050c5SMichael Chan 
347c0c050c5SMichael Chan 	vf->flags &= ~(BNXT_VF_LINK_UP | BNXT_VF_LINK_FORCED);
348c0c050c5SMichael Chan 	switch (link) {
349c0c050c5SMichael Chan 	case IFLA_VF_LINK_STATE_AUTO:
350c0c050c5SMichael Chan 		vf->flags |= BNXT_VF_LINK_UP;
351c0c050c5SMichael Chan 		break;
352c0c050c5SMichael Chan 	case IFLA_VF_LINK_STATE_DISABLE:
353c0c050c5SMichael Chan 		vf->flags |= BNXT_VF_LINK_FORCED;
354c0c050c5SMichael Chan 		break;
355c0c050c5SMichael Chan 	case IFLA_VF_LINK_STATE_ENABLE:
356c0c050c5SMichael Chan 		vf->flags |= BNXT_VF_LINK_UP | BNXT_VF_LINK_FORCED;
357c0c050c5SMichael Chan 		break;
358c0c050c5SMichael Chan 	default:
359c0c050c5SMichael Chan 		netdev_err(bp->dev, "Invalid link option\n");
360c0c050c5SMichael Chan 		rc = -EINVAL;
361c0c050c5SMichael Chan 		break;
362c0c050c5SMichael Chan 	}
363350a7149SEddie Wai 	if (vf->flags & (BNXT_VF_LINK_UP | BNXT_VF_LINK_FORCED))
364350a7149SEddie Wai 		rc = bnxt_hwrm_fwd_async_event_cmpl(bp, vf,
36587c374deSMichael Chan 			ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE);
366c0c050c5SMichael Chan 	return rc;
367c0c050c5SMichael Chan }
368c0c050c5SMichael Chan 
bnxt_set_vf_attr(struct bnxt * bp,int num_vfs)369c0c050c5SMichael Chan static int bnxt_set_vf_attr(struct bnxt *bp, int num_vfs)
370c0c050c5SMichael Chan {
371c0c050c5SMichael Chan 	int i;
372c0c050c5SMichael Chan 	struct bnxt_vf_info *vf;
373c0c050c5SMichael Chan 
374c0c050c5SMichael Chan 	for (i = 0; i < num_vfs; i++) {
375c0c050c5SMichael Chan 		vf = &bp->pf.vf[i];
376c0c050c5SMichael Chan 		memset(vf, 0, sizeof(*vf));
377c0c050c5SMichael Chan 	}
378c0c050c5SMichael Chan 	return 0;
379c0c050c5SMichael Chan }
380c0c050c5SMichael Chan 
bnxt_hwrm_func_vf_resource_free(struct bnxt * bp,int num_vfs)3814bb6cdceSJeffrey Huang static int bnxt_hwrm_func_vf_resource_free(struct bnxt *bp, int num_vfs)
382c0c050c5SMichael Chan {
383bbf33d1dSEdwin Peer 	struct hwrm_func_vf_resc_free_input *req;
384c0c050c5SMichael Chan 	struct bnxt_pf_info *pf = &bp->pf;
385bbf33d1dSEdwin Peer 	int i, rc;
386c0c050c5SMichael Chan 
387bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FUNC_VF_RESC_FREE);
388bbf33d1dSEdwin Peer 	if (rc)
389bbf33d1dSEdwin Peer 		return rc;
390c0c050c5SMichael Chan 
391bbf33d1dSEdwin Peer 	hwrm_req_hold(bp, req);
3924bb6cdceSJeffrey Huang 	for (i = pf->first_vf_id; i < pf->first_vf_id + num_vfs; i++) {
393bbf33d1dSEdwin Peer 		req->vf_id = cpu_to_le16(i);
394bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
395c0c050c5SMichael Chan 		if (rc)
396c0c050c5SMichael Chan 			break;
397c0c050c5SMichael Chan 	}
398bbf33d1dSEdwin Peer 	hwrm_req_drop(bp, req);
399c0c050c5SMichael Chan 	return rc;
400c0c050c5SMichael Chan }
401c0c050c5SMichael Chan 
bnxt_free_vf_resources(struct bnxt * bp)402c0c050c5SMichael Chan static void bnxt_free_vf_resources(struct bnxt *bp)
403c0c050c5SMichael Chan {
404c0c050c5SMichael Chan 	struct pci_dev *pdev = bp->pdev;
405c0c050c5SMichael Chan 	int i;
406c0c050c5SMichael Chan 
407c0c050c5SMichael Chan 	kfree(bp->pf.vf_event_bmap);
408c0c050c5SMichael Chan 	bp->pf.vf_event_bmap = NULL;
409c0c050c5SMichael Chan 
410c0c050c5SMichael Chan 	for (i = 0; i < 4; i++) {
411c0c050c5SMichael Chan 		if (bp->pf.hwrm_cmd_req_addr[i]) {
412c0c050c5SMichael Chan 			dma_free_coherent(&pdev->dev, BNXT_PAGE_SIZE,
413c0c050c5SMichael Chan 					  bp->pf.hwrm_cmd_req_addr[i],
414c0c050c5SMichael Chan 					  bp->pf.hwrm_cmd_req_dma_addr[i]);
415c0c050c5SMichael Chan 			bp->pf.hwrm_cmd_req_addr[i] = NULL;
416c0c050c5SMichael Chan 		}
417c0c050c5SMichael Chan 	}
418c0c050c5SMichael Chan 
419c8b1d743SDavide Caratti 	bp->pf.active_vfs = 0;
420c0c050c5SMichael Chan 	kfree(bp->pf.vf);
421c0c050c5SMichael Chan 	bp->pf.vf = NULL;
422c0c050c5SMichael Chan }
423c0c050c5SMichael Chan 
bnxt_alloc_vf_resources(struct bnxt * bp,int num_vfs)424c0c050c5SMichael Chan static int bnxt_alloc_vf_resources(struct bnxt *bp, int num_vfs)
425c0c050c5SMichael Chan {
426c0c050c5SMichael Chan 	struct pci_dev *pdev = bp->pdev;
427c0c050c5SMichael Chan 	u32 nr_pages, size, i, j, k = 0;
428c0c050c5SMichael Chan 
429c0c050c5SMichael Chan 	bp->pf.vf = kcalloc(num_vfs, sizeof(struct bnxt_vf_info), GFP_KERNEL);
430c0c050c5SMichael Chan 	if (!bp->pf.vf)
431c0c050c5SMichael Chan 		return -ENOMEM;
432c0c050c5SMichael Chan 
433c0c050c5SMichael Chan 	bnxt_set_vf_attr(bp, num_vfs);
434c0c050c5SMichael Chan 
435c0c050c5SMichael Chan 	size = num_vfs * BNXT_HWRM_REQ_MAX_SIZE;
436c0c050c5SMichael Chan 	nr_pages = size / BNXT_PAGE_SIZE;
437c0c050c5SMichael Chan 	if (size & (BNXT_PAGE_SIZE - 1))
438c0c050c5SMichael Chan 		nr_pages++;
439c0c050c5SMichael Chan 
440c0c050c5SMichael Chan 	for (i = 0; i < nr_pages; i++) {
441c0c050c5SMichael Chan 		bp->pf.hwrm_cmd_req_addr[i] =
442c0c050c5SMichael Chan 			dma_alloc_coherent(&pdev->dev, BNXT_PAGE_SIZE,
443c0c050c5SMichael Chan 					   &bp->pf.hwrm_cmd_req_dma_addr[i],
444c0c050c5SMichael Chan 					   GFP_KERNEL);
445c0c050c5SMichael Chan 
446c0c050c5SMichael Chan 		if (!bp->pf.hwrm_cmd_req_addr[i])
447c0c050c5SMichael Chan 			return -ENOMEM;
448c0c050c5SMichael Chan 
449c0c050c5SMichael Chan 		for (j = 0; j < BNXT_HWRM_REQS_PER_PAGE && k < num_vfs; j++) {
450c0c050c5SMichael Chan 			struct bnxt_vf_info *vf = &bp->pf.vf[k];
451c0c050c5SMichael Chan 
452c0c050c5SMichael Chan 			vf->hwrm_cmd_req_addr = bp->pf.hwrm_cmd_req_addr[i] +
453c0c050c5SMichael Chan 						j * BNXT_HWRM_REQ_MAX_SIZE;
454c0c050c5SMichael Chan 			vf->hwrm_cmd_req_dma_addr =
455c0c050c5SMichael Chan 				bp->pf.hwrm_cmd_req_dma_addr[i] + j *
456c0c050c5SMichael Chan 				BNXT_HWRM_REQ_MAX_SIZE;
457c0c050c5SMichael Chan 			k++;
458c0c050c5SMichael Chan 		}
459c0c050c5SMichael Chan 	}
460c0c050c5SMichael Chan 
461c0c050c5SMichael Chan 	/* Max 128 VF's */
462c0c050c5SMichael Chan 	bp->pf.vf_event_bmap = kzalloc(16, GFP_KERNEL);
463c0c050c5SMichael Chan 	if (!bp->pf.vf_event_bmap)
464c0c050c5SMichael Chan 		return -ENOMEM;
465c0c050c5SMichael Chan 
466c0c050c5SMichael Chan 	bp->pf.hwrm_cmd_req_pages = nr_pages;
467c0c050c5SMichael Chan 	return 0;
468c0c050c5SMichael Chan }
469c0c050c5SMichael Chan 
bnxt_hwrm_func_buf_rgtr(struct bnxt * bp)470c0c050c5SMichael Chan static int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
471c0c050c5SMichael Chan {
472bbf33d1dSEdwin Peer 	struct hwrm_func_buf_rgtr_input *req;
473bbf33d1dSEdwin Peer 	int rc;
474c0c050c5SMichael Chan 
475bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FUNC_BUF_RGTR);
476bbf33d1dSEdwin Peer 	if (rc)
477bbf33d1dSEdwin Peer 		return rc;
478c0c050c5SMichael Chan 
479bbf33d1dSEdwin Peer 	req->req_buf_num_pages = cpu_to_le16(bp->pf.hwrm_cmd_req_pages);
480bbf33d1dSEdwin Peer 	req->req_buf_page_size = cpu_to_le16(BNXT_PAGE_SHIFT);
481bbf33d1dSEdwin Peer 	req->req_buf_len = cpu_to_le16(BNXT_HWRM_REQ_MAX_SIZE);
482bbf33d1dSEdwin Peer 	req->req_buf_page_addr0 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[0]);
483bbf33d1dSEdwin Peer 	req->req_buf_page_addr1 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[1]);
484bbf33d1dSEdwin Peer 	req->req_buf_page_addr2 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[2]);
485bbf33d1dSEdwin Peer 	req->req_buf_page_addr3 = cpu_to_le64(bp->pf.hwrm_cmd_req_dma_addr[3]);
486c0c050c5SMichael Chan 
487bbf33d1dSEdwin Peer 	return hwrm_req_send(bp, req);
488c0c050c5SMichael Chan }
489c0c050c5SMichael Chan 
__bnxt_set_vf_params(struct bnxt * bp,int vf_id)490bbf33d1dSEdwin Peer static int __bnxt_set_vf_params(struct bnxt *bp, int vf_id)
4912cd86968SVasundhara Volam {
492bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
4932cd86968SVasundhara Volam 	struct bnxt_vf_info *vf;
494bbf33d1dSEdwin Peer 	int rc;
495bbf33d1dSEdwin Peer 
49673b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
497bbf33d1dSEdwin Peer 	if (rc)
498bbf33d1dSEdwin Peer 		return rc;
4992cd86968SVasundhara Volam 
5002cd86968SVasundhara Volam 	vf = &bp->pf.vf[vf_id];
501bbf33d1dSEdwin Peer 	req->fid = cpu_to_le16(vf->fw_fid);
5022cd86968SVasundhara Volam 
5032cd86968SVasundhara Volam 	if (is_valid_ether_addr(vf->mac_addr)) {
504bbf33d1dSEdwin Peer 		req->enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_MAC_ADDR);
505bbf33d1dSEdwin Peer 		memcpy(req->dflt_mac_addr, vf->mac_addr, ETH_ALEN);
5062cd86968SVasundhara Volam 	}
5072cd86968SVasundhara Volam 	if (vf->vlan) {
508bbf33d1dSEdwin Peer 		req->enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_VLAN);
509bbf33d1dSEdwin Peer 		req->dflt_vlan = cpu_to_le16(vf->vlan);
5102cd86968SVasundhara Volam 	}
5112cd86968SVasundhara Volam 	if (vf->max_tx_rate) {
512bbf33d1dSEdwin Peer 		req->enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_MAX_BW |
513bbf33d1dSEdwin Peer 					    FUNC_CFG_REQ_ENABLES_MIN_BW);
514bbf33d1dSEdwin Peer 		req->max_bw = cpu_to_le32(vf->max_tx_rate);
515bbf33d1dSEdwin Peer 		req->min_bw = cpu_to_le32(vf->min_tx_rate);
5162cd86968SVasundhara Volam 	}
5172cd86968SVasundhara Volam 	if (vf->flags & BNXT_VF_TRUST)
518bbf33d1dSEdwin Peer 		req->flags |= cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_ENABLE);
5192cd86968SVasundhara Volam 
520bbf33d1dSEdwin Peer 	return hwrm_req_send(bp, req);
5212cd86968SVasundhara Volam }
5222cd86968SVasundhara Volam 
5234673d664SMichael Chan /* Only called by PF to reserve resources for VFs, returns actual number of
5244673d664SMichael Chan  * VFs configured, or < 0 on error.
5254673d664SMichael Chan  */
bnxt_hwrm_func_vf_resc_cfg(struct bnxt * bp,int num_vfs,bool reset)5262cd86968SVasundhara Volam static int bnxt_hwrm_func_vf_resc_cfg(struct bnxt *bp, int num_vfs, bool reset)
5274673d664SMichael Chan {
528bbf33d1dSEdwin Peer 	struct hwrm_func_vf_resource_cfg_input *req;
5294673d664SMichael Chan 	struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
5304673d664SMichael Chan 	u16 vf_tx_rings, vf_rx_rings, vf_cp_rings;
5314673d664SMichael Chan 	u16 vf_stat_ctx, vf_vnics, vf_ring_grps;
5324673d664SMichael Chan 	struct bnxt_pf_info *pf = &bp->pf;
533bf82736dSMichael Chan 	int i, rc = 0, min = 1;
534b16b6891SMichael Chan 	u16 vf_msix = 0;
5351acefc9aSMichael Chan 	u16 vf_rss;
5364673d664SMichael Chan 
537bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FUNC_VF_RESOURCE_CFG);
538bbf33d1dSEdwin Peer 	if (rc)
539bbf33d1dSEdwin Peer 		return rc;
5404673d664SMichael Chan 
5411c7fd6eeSRandy Schacher 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {
542b16b6891SMichael Chan 		vf_msix = hw_resc->max_nqs - bnxt_nq_rings_in_use(bp);
543b16b6891SMichael Chan 		vf_ring_grps = 0;
544b16b6891SMichael Chan 	} else {
545b16b6891SMichael Chan 		vf_ring_grps = hw_resc->max_hw_ring_grps - bp->rx_nr_rings;
546b16b6891SMichael Chan 	}
547e916b081SMichael Chan 	vf_cp_rings = bnxt_get_avail_cp_rings_for_en(bp);
548c027c6b4SVasundhara Volam 	vf_stat_ctx = bnxt_get_avail_stat_ctxs_for_en(bp);
5494673d664SMichael Chan 	if (bp->flags & BNXT_FLAG_AGG_RINGS)
5504673d664SMichael Chan 		vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings * 2;
5514673d664SMichael Chan 	else
5524673d664SMichael Chan 		vf_rx_rings = hw_resc->max_rx_rings - bp->rx_nr_rings;
5534673d664SMichael Chan 	vf_tx_rings = hw_resc->max_tx_rings - bp->tx_nr_rings;
5544673d664SMichael Chan 	vf_vnics = hw_resc->max_vnics - bp->nr_vnics;
5551acefc9aSMichael Chan 	vf_rss = hw_resc->max_rsscos_ctxs - bp->rsscos_nr_ctxs;
5564673d664SMichael Chan 
557bbf33d1dSEdwin Peer 	req->min_rsscos_ctx = cpu_to_le16(BNXT_VF_MIN_RSS_CTX);
558bf82736dSMichael Chan 	if (pf->vf_resv_strategy == BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
559bf82736dSMichael Chan 		min = 0;
560bbf33d1dSEdwin Peer 		req->min_rsscos_ctx = cpu_to_le16(min);
561bf82736dSMichael Chan 	}
562bf82736dSMichael Chan 	if (pf->vf_resv_strategy == BNXT_VF_RESV_STRATEGY_MINIMAL ||
563bf82736dSMichael Chan 	    pf->vf_resv_strategy == BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
564bbf33d1dSEdwin Peer 		req->min_cmpl_rings = cpu_to_le16(min);
565bbf33d1dSEdwin Peer 		req->min_tx_rings = cpu_to_le16(min);
566bbf33d1dSEdwin Peer 		req->min_rx_rings = cpu_to_le16(min);
567bbf33d1dSEdwin Peer 		req->min_l2_ctxs = cpu_to_le16(min);
568bbf33d1dSEdwin Peer 		req->min_vnics = cpu_to_le16(min);
569bbf33d1dSEdwin Peer 		req->min_stat_ctx = cpu_to_le16(min);
5701c7fd6eeSRandy Schacher 		if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
571bbf33d1dSEdwin Peer 			req->min_hw_ring_grps = cpu_to_le16(min);
5724673d664SMichael Chan 	} else {
5734673d664SMichael Chan 		vf_cp_rings /= num_vfs;
5744673d664SMichael Chan 		vf_tx_rings /= num_vfs;
5754673d664SMichael Chan 		vf_rx_rings /= num_vfs;
576cbdbf0aaSVikas Gupta 		if ((bp->fw_cap & BNXT_FW_CAP_PRE_RESV_VNICS) &&
577cbdbf0aaSVikas Gupta 		    vf_vnics >= pf->max_vfs) {
578cbdbf0aaSVikas Gupta 			/* Take into account that FW has pre-reserved 1 VNIC for
579cbdbf0aaSVikas Gupta 			 * each pf->max_vfs.
580cbdbf0aaSVikas Gupta 			 */
581cbdbf0aaSVikas Gupta 			vf_vnics = (vf_vnics - pf->max_vfs + num_vfs) / num_vfs;
582cbdbf0aaSVikas Gupta 		} else {
5834673d664SMichael Chan 			vf_vnics /= num_vfs;
584cbdbf0aaSVikas Gupta 		}
5854673d664SMichael Chan 		vf_stat_ctx /= num_vfs;
5864673d664SMichael Chan 		vf_ring_grps /= num_vfs;
5871acefc9aSMichael Chan 		vf_rss /= num_vfs;
5884673d664SMichael Chan 
589cbdbf0aaSVikas Gupta 		vf_vnics = min_t(u16, vf_vnics, vf_rx_rings);
590bbf33d1dSEdwin Peer 		req->min_cmpl_rings = cpu_to_le16(vf_cp_rings);
591bbf33d1dSEdwin Peer 		req->min_tx_rings = cpu_to_le16(vf_tx_rings);
592bbf33d1dSEdwin Peer 		req->min_rx_rings = cpu_to_le16(vf_rx_rings);
593bbf33d1dSEdwin Peer 		req->min_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX);
594bbf33d1dSEdwin Peer 		req->min_vnics = cpu_to_le16(vf_vnics);
595bbf33d1dSEdwin Peer 		req->min_stat_ctx = cpu_to_le16(vf_stat_ctx);
596bbf33d1dSEdwin Peer 		req->min_hw_ring_grps = cpu_to_le16(vf_ring_grps);
597bbf33d1dSEdwin Peer 		req->min_rsscos_ctx = cpu_to_le16(vf_rss);
5984673d664SMichael Chan 	}
599bbf33d1dSEdwin Peer 	req->max_cmpl_rings = cpu_to_le16(vf_cp_rings);
600bbf33d1dSEdwin Peer 	req->max_tx_rings = cpu_to_le16(vf_tx_rings);
601bbf33d1dSEdwin Peer 	req->max_rx_rings = cpu_to_le16(vf_rx_rings);
602bbf33d1dSEdwin Peer 	req->max_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX);
603bbf33d1dSEdwin Peer 	req->max_vnics = cpu_to_le16(vf_vnics);
604bbf33d1dSEdwin Peer 	req->max_stat_ctx = cpu_to_le16(vf_stat_ctx);
605bbf33d1dSEdwin Peer 	req->max_hw_ring_grps = cpu_to_le16(vf_ring_grps);
606bbf33d1dSEdwin Peer 	req->max_rsscos_ctx = cpu_to_le16(vf_rss);
6071c7fd6eeSRandy Schacher 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
608bbf33d1dSEdwin Peer 		req->max_msix = cpu_to_le16(vf_msix / num_vfs);
6094673d664SMichael Chan 
610bbf33d1dSEdwin Peer 	hwrm_req_hold(bp, req);
6114673d664SMichael Chan 	for (i = 0; i < num_vfs; i++) {
6122cd86968SVasundhara Volam 		if (reset)
6132cd86968SVasundhara Volam 			__bnxt_set_vf_params(bp, i);
6142cd86968SVasundhara Volam 
615bbf33d1dSEdwin Peer 		req->vf_id = cpu_to_le16(pf->first_vf_id + i);
616bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
617d4f1420dSMichael Chan 		if (rc)
6184673d664SMichael Chan 			break;
6194673d664SMichael Chan 		pf->active_vfs = i + 1;
6204673d664SMichael Chan 		pf->vf[i].fw_fid = pf->first_vf_id + i;
6214673d664SMichael Chan 	}
622bbf33d1dSEdwin Peer 
6234673d664SMichael Chan 	if (pf->active_vfs) {
624596f9d55SMichael Chan 		u16 n = pf->active_vfs;
6254673d664SMichael Chan 
626bbf33d1dSEdwin Peer 		hw_resc->max_tx_rings -= le16_to_cpu(req->min_tx_rings) * n;
627bbf33d1dSEdwin Peer 		hw_resc->max_rx_rings -= le16_to_cpu(req->min_rx_rings) * n;
628bbf33d1dSEdwin Peer 		hw_resc->max_hw_ring_grps -=
629bbf33d1dSEdwin Peer 			le16_to_cpu(req->min_hw_ring_grps) * n;
630bbf33d1dSEdwin Peer 		hw_resc->max_cp_rings -= le16_to_cpu(req->min_cmpl_rings) * n;
631bbf33d1dSEdwin Peer 		hw_resc->max_rsscos_ctxs -=
632bbf33d1dSEdwin Peer 			le16_to_cpu(req->min_rsscos_ctx) * n;
633bbf33d1dSEdwin Peer 		hw_resc->max_stat_ctxs -= le16_to_cpu(req->min_stat_ctx) * n;
634bbf33d1dSEdwin Peer 		hw_resc->max_vnics -= le16_to_cpu(req->min_vnics) * n;
6351c7fd6eeSRandy Schacher 		if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
63609a89cc5SVikas Gupta 			hw_resc->max_nqs -= vf_msix;
6374673d664SMichael Chan 
6384673d664SMichael Chan 		rc = pf->active_vfs;
6394673d664SMichael Chan 	}
640bbf33d1dSEdwin Peer 	hwrm_req_drop(bp, req);
6414673d664SMichael Chan 	return rc;
6424673d664SMichael Chan }
6434673d664SMichael Chan 
6444673d664SMichael Chan /* Only called by PF to reserve resources for VFs, returns actual number of
6454673d664SMichael Chan  * VFs configured, or < 0 on error.
6464673d664SMichael Chan  */
bnxt_hwrm_func_cfg(struct bnxt * bp,int num_vfs)64792268c32SMichael Chan static int bnxt_hwrm_func_cfg(struct bnxt *bp, int num_vfs)
648c0c050c5SMichael Chan {
649c0c050c5SMichael Chan 	u16 vf_tx_rings, vf_rx_rings, vf_cp_rings, vf_stat_ctx, vf_vnics;
6506a4f2947SMichael Chan 	struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
651c0c050c5SMichael Chan 	struct bnxt_pf_info *pf = &bp->pf;
652bbf33d1dSEdwin Peer 	struct hwrm_func_cfg_input *req;
653391be5c2SMichael Chan 	int total_vf_tx_rings = 0;
654c027c6b4SVasundhara Volam 	u16 vf_ring_grps;
655bbf33d1dSEdwin Peer 	u32 mtu, i;
656bbf33d1dSEdwin Peer 	int rc;
657c0c050c5SMichael Chan 
65873b24e7cSJakub Kicinski 	rc = bnxt_hwrm_func_cfg_short_req_init(bp, &req);
659bbf33d1dSEdwin Peer 	if (rc)
660bbf33d1dSEdwin Peer 		return rc;
661c0c050c5SMichael Chan 
662c0c050c5SMichael Chan 	/* Remaining rings are distributed equally amongs VF's for now */
663e916b081SMichael Chan 	vf_cp_rings = bnxt_get_avail_cp_rings_for_en(bp) / num_vfs;
664c027c6b4SVasundhara Volam 	vf_stat_ctx = bnxt_get_avail_stat_ctxs_for_en(bp) / num_vfs;
665c0c050c5SMichael Chan 	if (bp->flags & BNXT_FLAG_AGG_RINGS)
6666a4f2947SMichael Chan 		vf_rx_rings = (hw_resc->max_rx_rings - bp->rx_nr_rings * 2) /
66792268c32SMichael Chan 			      num_vfs;
668c0c050c5SMichael Chan 	else
6696a4f2947SMichael Chan 		vf_rx_rings = (hw_resc->max_rx_rings - bp->rx_nr_rings) /
6706a4f2947SMichael Chan 			      num_vfs;
6716a4f2947SMichael Chan 	vf_ring_grps = (hw_resc->max_hw_ring_grps - bp->rx_nr_rings) / num_vfs;
6726a4f2947SMichael Chan 	vf_tx_rings = (hw_resc->max_tx_rings - bp->tx_nr_rings) / num_vfs;
6736a4f2947SMichael Chan 	vf_vnics = (hw_resc->max_vnics - bp->nr_vnics) / num_vfs;
6748427af81SMichael Chan 	vf_vnics = min_t(u16, vf_vnics, vf_rx_rings);
675c0c050c5SMichael Chan 
676bbf33d1dSEdwin Peer 	req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ADMIN_MTU |
677c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_MRU |
678c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS |
679c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS |
680c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS |
681c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS |
682c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS |
683c0c050c5SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_L2_CTXS |
684b72d4a68SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_VNICS |
685b72d4a68SMichael Chan 				   FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS);
686c0c050c5SMichael Chan 
687d0b82c54SVasundhara Volam 	mtu = bp->dev->mtu + ETH_HLEN + VLAN_HLEN;
688bbf33d1dSEdwin Peer 	req->mru = cpu_to_le16(mtu);
689bbf33d1dSEdwin Peer 	req->admin_mtu = cpu_to_le16(mtu);
690c0c050c5SMichael Chan 
691bbf33d1dSEdwin Peer 	req->num_rsscos_ctxs = cpu_to_le16(1);
692bbf33d1dSEdwin Peer 	req->num_cmpl_rings = cpu_to_le16(vf_cp_rings);
693bbf33d1dSEdwin Peer 	req->num_tx_rings = cpu_to_le16(vf_tx_rings);
694bbf33d1dSEdwin Peer 	req->num_rx_rings = cpu_to_le16(vf_rx_rings);
695bbf33d1dSEdwin Peer 	req->num_hw_ring_grps = cpu_to_le16(vf_ring_grps);
696bbf33d1dSEdwin Peer 	req->num_l2_ctxs = cpu_to_le16(4);
697c0c050c5SMichael Chan 
698bbf33d1dSEdwin Peer 	req->num_vnics = cpu_to_le16(vf_vnics);
699c0c050c5SMichael Chan 	/* FIXME spec currently uses 1 bit for stats ctx */
700bbf33d1dSEdwin Peer 	req->num_stat_ctxs = cpu_to_le16(vf_stat_ctx);
701c0c050c5SMichael Chan 
702bbf33d1dSEdwin Peer 	hwrm_req_hold(bp, req);
70392268c32SMichael Chan 	for (i = 0; i < num_vfs; i++) {
704391be5c2SMichael Chan 		int vf_tx_rsvd = vf_tx_rings;
705391be5c2SMichael Chan 
706bbf33d1dSEdwin Peer 		req->fid = cpu_to_le16(pf->first_vf_id + i);
707bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
708c0c050c5SMichael Chan 		if (rc)
709c0c050c5SMichael Chan 			break;
71092268c32SMichael Chan 		pf->active_vfs = i + 1;
711bbf33d1dSEdwin Peer 		pf->vf[i].fw_fid = le16_to_cpu(req->fid);
712391be5c2SMichael Chan 		rc = __bnxt_hwrm_get_tx_rings(bp, pf->vf[i].fw_fid,
713391be5c2SMichael Chan 					      &vf_tx_rsvd);
714391be5c2SMichael Chan 		if (rc)
715391be5c2SMichael Chan 			break;
716391be5c2SMichael Chan 		total_vf_tx_rings += vf_tx_rsvd;
717c0c050c5SMichael Chan 	}
718bbf33d1dSEdwin Peer 	hwrm_req_drop(bp, req);
7194673d664SMichael Chan 	if (pf->active_vfs) {
7206a4f2947SMichael Chan 		hw_resc->max_tx_rings -= total_vf_tx_rings;
7216a4f2947SMichael Chan 		hw_resc->max_rx_rings -= vf_rx_rings * num_vfs;
7226a4f2947SMichael Chan 		hw_resc->max_hw_ring_grps -= vf_ring_grps * num_vfs;
7236a4f2947SMichael Chan 		hw_resc->max_cp_rings -= vf_cp_rings * num_vfs;
7246a4f2947SMichael Chan 		hw_resc->max_rsscos_ctxs -= num_vfs;
7256a4f2947SMichael Chan 		hw_resc->max_stat_ctxs -= vf_stat_ctx * num_vfs;
7266a4f2947SMichael Chan 		hw_resc->max_vnics -= vf_vnics * num_vfs;
7274673d664SMichael Chan 		rc = pf->active_vfs;
728c0c050c5SMichael Chan 	}
729c0c050c5SMichael Chan 	return rc;
730c0c050c5SMichael Chan }
731c0c050c5SMichael Chan 
bnxt_func_cfg(struct bnxt * bp,int num_vfs,bool reset)7322cd86968SVasundhara Volam static int bnxt_func_cfg(struct bnxt *bp, int num_vfs, bool reset)
7334673d664SMichael Chan {
734f1ca94deSMichael Chan 	if (BNXT_NEW_RM(bp))
7352cd86968SVasundhara Volam 		return bnxt_hwrm_func_vf_resc_cfg(bp, num_vfs, reset);
7364673d664SMichael Chan 	else
7374673d664SMichael Chan 		return bnxt_hwrm_func_cfg(bp, num_vfs);
7384673d664SMichael Chan }
7394673d664SMichael Chan 
bnxt_cfg_hw_sriov(struct bnxt * bp,int * num_vfs,bool reset)7402cd86968SVasundhara Volam int bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset)
741702d5011SMichael Chan {
742702d5011SMichael Chan 	int rc;
743702d5011SMichael Chan 
74491b9be48SVasundhara Volam 	/* Register buffers for VFs */
74591b9be48SVasundhara Volam 	rc = bnxt_hwrm_func_buf_rgtr(bp);
74691b9be48SVasundhara Volam 	if (rc)
74791b9be48SVasundhara Volam 		return rc;
74891b9be48SVasundhara Volam 
749702d5011SMichael Chan 	/* Reserve resources for VFs */
7502cd86968SVasundhara Volam 	rc = bnxt_func_cfg(bp, *num_vfs, reset);
751702d5011SMichael Chan 	if (rc != *num_vfs) {
752702d5011SMichael Chan 		if (rc <= 0) {
753702d5011SMichael Chan 			netdev_warn(bp->dev, "Unable to reserve resources for SRIOV.\n");
754702d5011SMichael Chan 			*num_vfs = 0;
755702d5011SMichael Chan 			return rc;
756702d5011SMichael Chan 		}
757702d5011SMichael Chan 		netdev_warn(bp->dev, "Only able to reserve resources for %d VFs.\n",
758702d5011SMichael Chan 			    rc);
759702d5011SMichael Chan 		*num_vfs = rc;
760702d5011SMichael Chan 	}
761702d5011SMichael Chan 
762702d5011SMichael Chan 	return 0;
763702d5011SMichael Chan }
764702d5011SMichael Chan 
bnxt_sriov_enable(struct bnxt * bp,int * num_vfs)765c0c050c5SMichael Chan static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs)
766c0c050c5SMichael Chan {
767c0c050c5SMichael Chan 	int rc = 0, vfs_supported;
768c0c050c5SMichael Chan 	int min_rx_rings, min_tx_rings, min_rss_ctxs;
7696a4f2947SMichael Chan 	struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
770c0c050c5SMichael Chan 	int tx_ok = 0, rx_ok = 0, rss_ok = 0;
77102157079SMichael Chan 	int avail_cp, avail_stat;
772c0c050c5SMichael Chan 
773c0c050c5SMichael Chan 	/* Check if we can enable requested num of vf's. At a mininum
774c0c050c5SMichael Chan 	 * we require 1 RX 1 TX rings for each VF. In this minimum conf
775c0c050c5SMichael Chan 	 * features like TPA will not be available.
776c0c050c5SMichael Chan 	 */
777c0c050c5SMichael Chan 	vfs_supported = *num_vfs;
778c0c050c5SMichael Chan 
779e916b081SMichael Chan 	avail_cp = bnxt_get_avail_cp_rings_for_en(bp);
780c027c6b4SVasundhara Volam 	avail_stat = bnxt_get_avail_stat_ctxs_for_en(bp);
78102157079SMichael Chan 	avail_cp = min_t(int, avail_cp, avail_stat);
78202157079SMichael Chan 
783c0c050c5SMichael Chan 	while (vfs_supported) {
784c0c050c5SMichael Chan 		min_rx_rings = vfs_supported;
785c0c050c5SMichael Chan 		min_tx_rings = vfs_supported;
786c0c050c5SMichael Chan 		min_rss_ctxs = vfs_supported;
787c0c050c5SMichael Chan 
788c0c050c5SMichael Chan 		if (bp->flags & BNXT_FLAG_AGG_RINGS) {
7896a4f2947SMichael Chan 			if (hw_resc->max_rx_rings - bp->rx_nr_rings * 2 >=
790c0c050c5SMichael Chan 			    min_rx_rings)
791c0c050c5SMichael Chan 				rx_ok = 1;
792c0c050c5SMichael Chan 		} else {
7936a4f2947SMichael Chan 			if (hw_resc->max_rx_rings - bp->rx_nr_rings >=
794c0c050c5SMichael Chan 			    min_rx_rings)
795c0c050c5SMichael Chan 				rx_ok = 1;
796c0c050c5SMichael Chan 		}
7976a4f2947SMichael Chan 		if (hw_resc->max_vnics - bp->nr_vnics < min_rx_rings ||
79802157079SMichael Chan 		    avail_cp < min_rx_rings)
7998427af81SMichael Chan 			rx_ok = 0;
800c0c050c5SMichael Chan 
8016a4f2947SMichael Chan 		if (hw_resc->max_tx_rings - bp->tx_nr_rings >= min_tx_rings &&
80202157079SMichael Chan 		    avail_cp >= min_tx_rings)
803c0c050c5SMichael Chan 			tx_ok = 1;
804c0c050c5SMichael Chan 
8056a4f2947SMichael Chan 		if (hw_resc->max_rsscos_ctxs - bp->rsscos_nr_ctxs >=
8066a4f2947SMichael Chan 		    min_rss_ctxs)
807c0c050c5SMichael Chan 			rss_ok = 1;
808c0c050c5SMichael Chan 
809c0c050c5SMichael Chan 		if (tx_ok && rx_ok && rss_ok)
810c0c050c5SMichael Chan 			break;
811c0c050c5SMichael Chan 
812c0c050c5SMichael Chan 		vfs_supported--;
813c0c050c5SMichael Chan 	}
814c0c050c5SMichael Chan 
815c0c050c5SMichael Chan 	if (!vfs_supported) {
816c0c050c5SMichael Chan 		netdev_err(bp->dev, "Cannot enable VF's as all resources are used by PF\n");
817c0c050c5SMichael Chan 		return -EINVAL;
818c0c050c5SMichael Chan 	}
819c0c050c5SMichael Chan 
820c0c050c5SMichael Chan 	if (vfs_supported != *num_vfs) {
821c0c050c5SMichael Chan 		netdev_info(bp->dev, "Requested VFs %d, can enable %d\n",
822c0c050c5SMichael Chan 			    *num_vfs, vfs_supported);
823c0c050c5SMichael Chan 		*num_vfs = vfs_supported;
824c0c050c5SMichael Chan 	}
825c0c050c5SMichael Chan 
826c0c050c5SMichael Chan 	rc = bnxt_alloc_vf_resources(bp, *num_vfs);
827c0c050c5SMichael Chan 	if (rc)
828c0c050c5SMichael Chan 		goto err_out1;
829c0c050c5SMichael Chan 
8302cd86968SVasundhara Volam 	rc = bnxt_cfg_hw_sriov(bp, num_vfs, false);
831c0c050c5SMichael Chan 	if (rc)
832c0c050c5SMichael Chan 		goto err_out2;
833c0c050c5SMichael Chan 
834c0c050c5SMichael Chan 	rc = pci_enable_sriov(bp->pdev, *num_vfs);
835a43c26faSAjit Khaparde 	if (rc)
836c0c050c5SMichael Chan 		goto err_out2;
837c0c050c5SMichael Chan 
838f032d8a9SIvan Vecera 	if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
839c0c050c5SMichael Chan 		return 0;
840c0c050c5SMichael Chan 
841f032d8a9SIvan Vecera 	/* Create representors for VFs in switchdev mode */
842f032d8a9SIvan Vecera 	devl_lock(bp->dl);
843f032d8a9SIvan Vecera 	rc = bnxt_vf_reps_create(bp);
844f032d8a9SIvan Vecera 	devl_unlock(bp->dl);
845f032d8a9SIvan Vecera 	if (rc) {
846f032d8a9SIvan Vecera 		netdev_info(bp->dev, "Cannot enable VFS as representors cannot be created\n");
847f032d8a9SIvan Vecera 		goto err_out3;
848f032d8a9SIvan Vecera 	}
849f032d8a9SIvan Vecera 
850f032d8a9SIvan Vecera 	return 0;
851f032d8a9SIvan Vecera 
852f032d8a9SIvan Vecera err_out3:
853f032d8a9SIvan Vecera 	/* Disable SR-IOV */
854f032d8a9SIvan Vecera 	pci_disable_sriov(bp->pdev);
855f032d8a9SIvan Vecera 
856c0c050c5SMichael Chan err_out2:
857c0c050c5SMichael Chan 	/* Free the resources reserved for various VF's */
8584bb6cdceSJeffrey Huang 	bnxt_hwrm_func_vf_resource_free(bp, *num_vfs);
859c0c050c5SMichael Chan 
860c5b744d3SKashyap Desai 	/* Restore the max resources */
861c5b744d3SKashyap Desai 	bnxt_hwrm_func_qcaps(bp);
862c5b744d3SKashyap Desai 
863c0c050c5SMichael Chan err_out1:
864c0c050c5SMichael Chan 	bnxt_free_vf_resources(bp);
865c0c050c5SMichael Chan 
866c0c050c5SMichael Chan 	return rc;
867c0c050c5SMichael Chan }
868c0c050c5SMichael Chan 
bnxt_sriov_disable(struct bnxt * bp)869c0c050c5SMichael Chan void bnxt_sriov_disable(struct bnxt *bp)
870c0c050c5SMichael Chan {
8714bb6cdceSJeffrey Huang 	u16 num_vfs = pci_num_vf(bp->pdev);
8724bb6cdceSJeffrey Huang 
8734bb6cdceSJeffrey Huang 	if (!num_vfs)
874c0c050c5SMichael Chan 		return;
875c0c050c5SMichael Chan 
8764ab0c6a8SSathya Perla 	/* synchronize VF and VF-rep create and destroy */
8777a1b0b1aSJakub Kicinski 	devl_lock(bp->dl);
8784ab0c6a8SSathya Perla 	bnxt_vf_reps_destroy(bp);
8794ab0c6a8SSathya Perla 
8804bb6cdceSJeffrey Huang 	if (pci_vfs_assigned(bp->pdev)) {
88119241368SJeffrey Huang 		bnxt_hwrm_fwd_async_event_cmpl(
88287c374deSMichael Chan 			bp, NULL, ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD);
8834bb6cdceSJeffrey Huang 		netdev_warn(bp->dev, "Unable to free %d VFs because some are assigned to VMs.\n",
8844bb6cdceSJeffrey Huang 			    num_vfs);
8854bb6cdceSJeffrey Huang 	} else {
886c0c050c5SMichael Chan 		pci_disable_sriov(bp->pdev);
8874bb6cdceSJeffrey Huang 		/* Free the HW resources reserved for various VF's */
8884bb6cdceSJeffrey Huang 		bnxt_hwrm_func_vf_resource_free(bp, num_vfs);
8894bb6cdceSJeffrey Huang 	}
8907a1b0b1aSJakub Kicinski 	devl_unlock(bp->dl);
891c0c050c5SMichael Chan 
892c0c050c5SMichael Chan 	bnxt_free_vf_resources(bp);
893c0c050c5SMichael Chan 
8944a21b49bSMichael Chan 	/* Reclaim all resources for the PF. */
8957b08f661SMichael Chan 	rtnl_lock();
8967b08f661SMichael Chan 	bnxt_restore_pf_fw_resources(bp);
8977b08f661SMichael Chan 	rtnl_unlock();
898c0c050c5SMichael Chan }
899c0c050c5SMichael Chan 
bnxt_sriov_configure(struct pci_dev * pdev,int num_vfs)900c0c050c5SMichael Chan int bnxt_sriov_configure(struct pci_dev *pdev, int num_vfs)
901c0c050c5SMichael Chan {
902c0c050c5SMichael Chan 	struct net_device *dev = pci_get_drvdata(pdev);
903c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
904c0c050c5SMichael Chan 
905c0c050c5SMichael Chan 	rtnl_lock();
906c0c050c5SMichael Chan 	if (!netif_running(dev)) {
907c0c050c5SMichael Chan 		netdev_warn(dev, "Reject SRIOV config request since if is down!\n");
908c0c050c5SMichael Chan 		rtnl_unlock();
909c0c050c5SMichael Chan 		return 0;
910c0c050c5SMichael Chan 	}
9113bc7d4a3SMichael Chan 	if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
9123bc7d4a3SMichael Chan 		netdev_warn(dev, "Reject SRIOV config request when FW reset is in progress\n");
9133bc7d4a3SMichael Chan 		rtnl_unlock();
9143bc7d4a3SMichael Chan 		return 0;
9153bc7d4a3SMichael Chan 	}
916c0c050c5SMichael Chan 	bp->sriov_cfg = true;
917c0c050c5SMichael Chan 	rtnl_unlock();
9184bb6cdceSJeffrey Huang 
9194bb6cdceSJeffrey Huang 	if (pci_vfs_assigned(bp->pdev)) {
9204bb6cdceSJeffrey Huang 		netdev_warn(dev, "Unable to configure SRIOV since some VFs are assigned to VMs.\n");
9214bb6cdceSJeffrey Huang 		num_vfs = 0;
9224bb6cdceSJeffrey Huang 		goto sriov_cfg_exit;
923c0c050c5SMichael Chan 	}
924c0c050c5SMichael Chan 
925c0c050c5SMichael Chan 	/* Check if enabled VFs is same as requested */
9264bb6cdceSJeffrey Huang 	if (num_vfs && num_vfs == bp->pf.active_vfs)
9274bb6cdceSJeffrey Huang 		goto sriov_cfg_exit;
9284bb6cdceSJeffrey Huang 
9294bb6cdceSJeffrey Huang 	/* if there are previous existing VFs, clean them up */
9304bb6cdceSJeffrey Huang 	bnxt_sriov_disable(bp);
9314bb6cdceSJeffrey Huang 	if (!num_vfs)
9324bb6cdceSJeffrey Huang 		goto sriov_cfg_exit;
933c0c050c5SMichael Chan 
934c0c050c5SMichael Chan 	bnxt_sriov_enable(bp, &num_vfs);
935c0c050c5SMichael Chan 
9364bb6cdceSJeffrey Huang sriov_cfg_exit:
937c0c050c5SMichael Chan 	bp->sriov_cfg = false;
938c0c050c5SMichael Chan 	wake_up(&bp->sriov_cfg_wait);
939c0c050c5SMichael Chan 
940c0c050c5SMichael Chan 	return num_vfs;
941c0c050c5SMichael Chan }
942c0c050c5SMichael Chan 
bnxt_hwrm_fwd_resp(struct bnxt * bp,struct bnxt_vf_info * vf,void * encap_resp,__le64 encap_resp_addr,__le16 encap_resp_cpr,u32 msg_size)943c0c050c5SMichael Chan static int bnxt_hwrm_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf,
944c0c050c5SMichael Chan 			      void *encap_resp, __le64 encap_resp_addr,
945c0c050c5SMichael Chan 			      __le16 encap_resp_cpr, u32 msg_size)
946c0c050c5SMichael Chan {
947bbf33d1dSEdwin Peer 	struct hwrm_fwd_resp_input *req;
948bbf33d1dSEdwin Peer 	int rc;
949c0c050c5SMichael Chan 
9507d9df38cSMichael Chan 	if (BNXT_FWD_RESP_SIZE_ERR(msg_size)) {
9517d9df38cSMichael Chan 		netdev_warn_once(bp->dev, "HWRM fwd response too big (%d bytes)\n",
9527d9df38cSMichael Chan 				 msg_size);
95359895f59SMichael Chan 		return -EINVAL;
9547d9df38cSMichael Chan 	}
95559895f59SMichael Chan 
956bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FWD_RESP);
957bbf33d1dSEdwin Peer 	if (!rc) {
958c0c050c5SMichael Chan 		/* Set the new target id */
959bbf33d1dSEdwin Peer 		req->target_id = cpu_to_le16(vf->fw_fid);
960bbf33d1dSEdwin Peer 		req->encap_resp_target_id = cpu_to_le16(vf->fw_fid);
961bbf33d1dSEdwin Peer 		req->encap_resp_len = cpu_to_le16(msg_size);
962bbf33d1dSEdwin Peer 		req->encap_resp_addr = encap_resp_addr;
963bbf33d1dSEdwin Peer 		req->encap_resp_cmpl_ring = encap_resp_cpr;
964bbf33d1dSEdwin Peer 		memcpy(req->encap_resp, encap_resp, msg_size);
965c0c050c5SMichael Chan 
966bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
967bbf33d1dSEdwin Peer 	}
968a798302dSMichael Chan 	if (rc)
969c0c050c5SMichael Chan 		netdev_err(bp->dev, "hwrm_fwd_resp failed. rc:%d\n", rc);
970c0c050c5SMichael Chan 	return rc;
971c0c050c5SMichael Chan }
972c0c050c5SMichael Chan 
bnxt_hwrm_fwd_err_resp(struct bnxt * bp,struct bnxt_vf_info * vf,u32 msg_size)973c0c050c5SMichael Chan static int bnxt_hwrm_fwd_err_resp(struct bnxt *bp, struct bnxt_vf_info *vf,
974c0c050c5SMichael Chan 				  u32 msg_size)
975c0c050c5SMichael Chan {
976bbf33d1dSEdwin Peer 	struct hwrm_reject_fwd_resp_input *req;
977bbf33d1dSEdwin Peer 	int rc;
978c0c050c5SMichael Chan 
97959895f59SMichael Chan 	if (BNXT_REJ_FWD_RESP_SIZE_ERR(msg_size))
98059895f59SMichael Chan 		return -EINVAL;
98159895f59SMichael Chan 
982bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_REJECT_FWD_RESP);
983bbf33d1dSEdwin Peer 	if (!rc) {
984c0c050c5SMichael Chan 		/* Set the new target id */
985bbf33d1dSEdwin Peer 		req->target_id = cpu_to_le16(vf->fw_fid);
986bbf33d1dSEdwin Peer 		req->encap_resp_target_id = cpu_to_le16(vf->fw_fid);
987bbf33d1dSEdwin Peer 		memcpy(req->encap_request, vf->hwrm_cmd_req_addr, msg_size);
988c0c050c5SMichael Chan 
989bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
990bbf33d1dSEdwin Peer 	}
991a798302dSMichael Chan 	if (rc)
992c0c050c5SMichael Chan 		netdev_err(bp->dev, "hwrm_fwd_err_resp failed. rc:%d\n", rc);
993c0c050c5SMichael Chan 	return rc;
994c0c050c5SMichael Chan }
995c0c050c5SMichael Chan 
bnxt_hwrm_exec_fwd_resp(struct bnxt * bp,struct bnxt_vf_info * vf,u32 msg_size)996c0c050c5SMichael Chan static int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf,
997c0c050c5SMichael Chan 				   u32 msg_size)
998c0c050c5SMichael Chan {
999bbf33d1dSEdwin Peer 	struct hwrm_exec_fwd_resp_input *req;
1000bbf33d1dSEdwin Peer 	int rc;
1001c0c050c5SMichael Chan 
100259895f59SMichael Chan 	if (BNXT_EXEC_FWD_RESP_SIZE_ERR(msg_size))
100359895f59SMichael Chan 		return -EINVAL;
100459895f59SMichael Chan 
1005bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_EXEC_FWD_RESP);
1006bbf33d1dSEdwin Peer 	if (!rc) {
1007c0c050c5SMichael Chan 		/* Set the new target id */
1008bbf33d1dSEdwin Peer 		req->target_id = cpu_to_le16(vf->fw_fid);
1009bbf33d1dSEdwin Peer 		req->encap_resp_target_id = cpu_to_le16(vf->fw_fid);
1010bbf33d1dSEdwin Peer 		memcpy(req->encap_request, vf->hwrm_cmd_req_addr, msg_size);
1011c0c050c5SMichael Chan 
1012bbf33d1dSEdwin Peer 		rc = hwrm_req_send(bp, req);
1013bbf33d1dSEdwin Peer 	}
1014a798302dSMichael Chan 	if (rc)
1015c0c050c5SMichael Chan 		netdev_err(bp->dev, "hwrm_exec_fw_resp failed. rc:%d\n", rc);
1016c0c050c5SMichael Chan 	return rc;
1017c0c050c5SMichael Chan }
1018c0c050c5SMichael Chan 
bnxt_vf_configure_mac(struct bnxt * bp,struct bnxt_vf_info * vf)1019746df139SVasundhara Volam static int bnxt_vf_configure_mac(struct bnxt *bp, struct bnxt_vf_info *vf)
102091cdda40SVasundhara Volam {
102191cdda40SVasundhara Volam 	u32 msg_size = sizeof(struct hwrm_func_vf_cfg_input);
102291cdda40SVasundhara Volam 	struct hwrm_func_vf_cfg_input *req =
102391cdda40SVasundhara Volam 		(struct hwrm_func_vf_cfg_input *)vf->hwrm_cmd_req_addr;
102491cdda40SVasundhara Volam 
1025746df139SVasundhara Volam 	/* Allow VF to set a valid MAC address, if trust is set to on or
1026746df139SVasundhara Volam 	 * if the PF assigned MAC address is zero
102791cdda40SVasundhara Volam 	 */
102891cdda40SVasundhara Volam 	if (req->enables & cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_DFLT_MAC_ADDR)) {
10292a516444SMichael Chan 		bool trust = bnxt_is_trusted_vf(bp, vf);
10302a516444SMichael Chan 
103191cdda40SVasundhara Volam 		if (is_valid_ether_addr(req->dflt_mac_addr) &&
10322a516444SMichael Chan 		    (trust || !is_valid_ether_addr(vf->mac_addr) ||
1033707e7e96SMichael Chan 		     ether_addr_equal(req->dflt_mac_addr, vf->mac_addr))) {
103491cdda40SVasundhara Volam 			ether_addr_copy(vf->vf_mac_addr, req->dflt_mac_addr);
103591cdda40SVasundhara Volam 			return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size);
103691cdda40SVasundhara Volam 		}
103791cdda40SVasundhara Volam 		return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size);
103891cdda40SVasundhara Volam 	}
103991cdda40SVasundhara Volam 	return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size);
104091cdda40SVasundhara Volam }
104191cdda40SVasundhara Volam 
bnxt_vf_validate_set_mac(struct bnxt * bp,struct bnxt_vf_info * vf)1042c0c050c5SMichael Chan static int bnxt_vf_validate_set_mac(struct bnxt *bp, struct bnxt_vf_info *vf)
1043c0c050c5SMichael Chan {
1044c0c050c5SMichael Chan 	u32 msg_size = sizeof(struct hwrm_cfa_l2_filter_alloc_input);
1045c0c050c5SMichael Chan 	struct hwrm_cfa_l2_filter_alloc_input *req =
1046c0c050c5SMichael Chan 		(struct hwrm_cfa_l2_filter_alloc_input *)vf->hwrm_cmd_req_addr;
104791cdda40SVasundhara Volam 	bool mac_ok = false;
1048c0c050c5SMichael Chan 
1049746df139SVasundhara Volam 	if (!is_valid_ether_addr((const u8 *)req->l2_addr))
1050746df139SVasundhara Volam 		return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size);
1051746df139SVasundhara Volam 
1052746df139SVasundhara Volam 	/* Allow VF to set a valid MAC address, if trust is set to on.
1053746df139SVasundhara Volam 	 * Or VF MAC address must first match MAC address in PF's context.
105491cdda40SVasundhara Volam 	 * Otherwise, it must match the VF MAC address if firmware spec >=
105591cdda40SVasundhara Volam 	 * 1.2.2
105691cdda40SVasundhara Volam 	 */
10572a516444SMichael Chan 	if (bnxt_is_trusted_vf(bp, vf)) {
1058746df139SVasundhara Volam 		mac_ok = true;
1059746df139SVasundhara Volam 	} else if (is_valid_ether_addr(vf->mac_addr)) {
106091cdda40SVasundhara Volam 		if (ether_addr_equal((const u8 *)req->l2_addr, vf->mac_addr))
106191cdda40SVasundhara Volam 			mac_ok = true;
106291cdda40SVasundhara Volam 	} else if (is_valid_ether_addr(vf->vf_mac_addr)) {
106391cdda40SVasundhara Volam 		if (ether_addr_equal((const u8 *)req->l2_addr, vf->vf_mac_addr))
106491cdda40SVasundhara Volam 			mac_ok = true;
106591cdda40SVasundhara Volam 	} else {
10666fd544c8SYueHaibing 		/* There are two cases:
10676fd544c8SYueHaibing 		 * 1.If firmware spec < 0x10202,VF MAC address is not forwarded
10686fd544c8SYueHaibing 		 *   to the PF and so it doesn't have to match
10696fd544c8SYueHaibing 		 * 2.Allow VF to modify it's own MAC when PF has not assigned a
10706fd544c8SYueHaibing 		 *   valid MAC address and firmware spec >= 0x10202
10716fd544c8SYueHaibing 		 */
107291cdda40SVasundhara Volam 		mac_ok = true;
107391cdda40SVasundhara Volam 	}
107491cdda40SVasundhara Volam 	if (mac_ok)
1075c0c050c5SMichael Chan 		return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size);
1076c0c050c5SMichael Chan 	return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size);
1077c0c050c5SMichael Chan }
1078c0c050c5SMichael Chan 
bnxt_vf_set_link(struct bnxt * bp,struct bnxt_vf_info * vf)1079c0c050c5SMichael Chan static int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf)
1080c0c050c5SMichael Chan {
1081c0c050c5SMichael Chan 	int rc = 0;
1082c0c050c5SMichael Chan 
1083c0c050c5SMichael Chan 	if (!(vf->flags & BNXT_VF_LINK_FORCED)) {
1084c0c050c5SMichael Chan 		/* real link */
1085c0c050c5SMichael Chan 		rc = bnxt_hwrm_exec_fwd_resp(
1086c0c050c5SMichael Chan 			bp, vf, sizeof(struct hwrm_port_phy_qcfg_input));
1087c0c050c5SMichael Chan 	} else {
10887d9df38cSMichael Chan 		struct hwrm_port_phy_qcfg_output_compat phy_qcfg_resp = {};
1089c0c050c5SMichael Chan 		struct hwrm_port_phy_qcfg_input *phy_qcfg_req;
1090c0c050c5SMichael Chan 
1091c0c050c5SMichael Chan 		phy_qcfg_req =
1092c0c050c5SMichael Chan 		(struct hwrm_port_phy_qcfg_input *)vf->hwrm_cmd_req_addr;
10933c10ed49SEdwin Peer 		mutex_lock(&bp->link_lock);
1094c0c050c5SMichael Chan 		memcpy(&phy_qcfg_resp, &bp->link_info.phy_qcfg_resp,
1095c0c050c5SMichael Chan 		       sizeof(phy_qcfg_resp));
10963c10ed49SEdwin Peer 		mutex_unlock(&bp->link_lock);
1097845adfe4SMichael Chan 		phy_qcfg_resp.resp_len = cpu_to_le16(sizeof(phy_qcfg_resp));
1098c0c050c5SMichael Chan 		phy_qcfg_resp.seq_id = phy_qcfg_req->seq_id;
10997d9df38cSMichael Chan 		/* New SPEEDS2 fields are beyond the legacy structure, so
11007d9df38cSMichael Chan 		 * clear the SPEEDS2_SUPPORTED flag.
11017d9df38cSMichael Chan 		 */
11027d9df38cSMichael Chan 		phy_qcfg_resp.option_flags &=
11037d9df38cSMichael Chan 			~PORT_PHY_QCAPS_RESP_FLAGS2_SPEEDS2_SUPPORTED;
1104845adfe4SMichael Chan 		phy_qcfg_resp.valid = 1;
1105c0c050c5SMichael Chan 
1106c0c050c5SMichael Chan 		if (vf->flags & BNXT_VF_LINK_UP) {
1107c0c050c5SMichael Chan 			/* if physical link is down, force link up on VF */
110873b9bad6SMichael Chan 			if (phy_qcfg_resp.link !=
110973b9bad6SMichael Chan 			    PORT_PHY_QCFG_RESP_LINK_LINK) {
1110c0c050c5SMichael Chan 				phy_qcfg_resp.link =
1111c0c050c5SMichael Chan 					PORT_PHY_QCFG_RESP_LINK_LINK;
111211f15ed3SMichael Chan 				phy_qcfg_resp.link_speed = cpu_to_le16(
111311f15ed3SMichael Chan 					PORT_PHY_QCFG_RESP_LINK_SPEED_10GB);
1114acb20054SMichael Chan 				phy_qcfg_resp.duplex_cfg =
1115acb20054SMichael Chan 					PORT_PHY_QCFG_RESP_DUPLEX_CFG_FULL;
1116acb20054SMichael Chan 				phy_qcfg_resp.duplex_state =
1117acb20054SMichael Chan 					PORT_PHY_QCFG_RESP_DUPLEX_STATE_FULL;
1118c0c050c5SMichael Chan 				phy_qcfg_resp.pause =
1119c0c050c5SMichael Chan 					(PORT_PHY_QCFG_RESP_PAUSE_TX |
1120c0c050c5SMichael Chan 					 PORT_PHY_QCFG_RESP_PAUSE_RX);
1121c0c050c5SMichael Chan 			}
1122c0c050c5SMichael Chan 		} else {
1123c0c050c5SMichael Chan 			/* force link down */
1124c0c050c5SMichael Chan 			phy_qcfg_resp.link = PORT_PHY_QCFG_RESP_LINK_NO_LINK;
1125c0c050c5SMichael Chan 			phy_qcfg_resp.link_speed = 0;
1126acb20054SMichael Chan 			phy_qcfg_resp.duplex_state =
1127acb20054SMichael Chan 				PORT_PHY_QCFG_RESP_DUPLEX_STATE_HALF;
1128c0c050c5SMichael Chan 			phy_qcfg_resp.pause = 0;
1129c0c050c5SMichael Chan 		}
1130c0c050c5SMichael Chan 		rc = bnxt_hwrm_fwd_resp(bp, vf, &phy_qcfg_resp,
1131c0c050c5SMichael Chan 					phy_qcfg_req->resp_addr,
1132c0c050c5SMichael Chan 					phy_qcfg_req->cmpl_ring,
1133c0c050c5SMichael Chan 					sizeof(phy_qcfg_resp));
1134c0c050c5SMichael Chan 	}
1135c0c050c5SMichael Chan 	return rc;
1136c0c050c5SMichael Chan }
1137c0c050c5SMichael Chan 
bnxt_vf_req_validate_snd(struct bnxt * bp,struct bnxt_vf_info * vf)1138c0c050c5SMichael Chan static int bnxt_vf_req_validate_snd(struct bnxt *bp, struct bnxt_vf_info *vf)
1139c0c050c5SMichael Chan {
1140c0c050c5SMichael Chan 	int rc = 0;
1141a8643e16SMichael Chan 	struct input *encap_req = vf->hwrm_cmd_req_addr;
1142a8643e16SMichael Chan 	u32 req_type = le16_to_cpu(encap_req->req_type);
1143c0c050c5SMichael Chan 
1144c0c050c5SMichael Chan 	switch (req_type) {
114591cdda40SVasundhara Volam 	case HWRM_FUNC_VF_CFG:
1146746df139SVasundhara Volam 		rc = bnxt_vf_configure_mac(bp, vf);
114791cdda40SVasundhara Volam 		break;
1148c0c050c5SMichael Chan 	case HWRM_CFA_L2_FILTER_ALLOC:
1149c0c050c5SMichael Chan 		rc = bnxt_vf_validate_set_mac(bp, vf);
1150c0c050c5SMichael Chan 		break;
1151c0c050c5SMichael Chan 	case HWRM_FUNC_CFG:
1152c0c050c5SMichael Chan 		/* TODO Validate if VF is allowed to change mac address,
1153c0c050c5SMichael Chan 		 * mtu, num of rings etc
1154c0c050c5SMichael Chan 		 */
1155c0c050c5SMichael Chan 		rc = bnxt_hwrm_exec_fwd_resp(
1156c0c050c5SMichael Chan 			bp, vf, sizeof(struct hwrm_func_cfg_input));
1157c0c050c5SMichael Chan 		break;
1158c0c050c5SMichael Chan 	case HWRM_PORT_PHY_QCFG:
1159c0c050c5SMichael Chan 		rc = bnxt_vf_set_link(bp, vf);
1160c0c050c5SMichael Chan 		break;
1161c0c050c5SMichael Chan 	default:
1162c0c050c5SMichael Chan 		break;
1163c0c050c5SMichael Chan 	}
1164c0c050c5SMichael Chan 	return rc;
1165c0c050c5SMichael Chan }
1166c0c050c5SMichael Chan 
bnxt_hwrm_exec_fwd_req(struct bnxt * bp)1167c0c050c5SMichael Chan void bnxt_hwrm_exec_fwd_req(struct bnxt *bp)
1168c0c050c5SMichael Chan {
1169c0c050c5SMichael Chan 	u32 i = 0, active_vfs = bp->pf.active_vfs, vf_id;
1170c0c050c5SMichael Chan 
1171c0c050c5SMichael Chan 	/* Scan through VF's and process commands */
1172c0c050c5SMichael Chan 	while (1) {
1173c0c050c5SMichael Chan 		vf_id = find_next_bit(bp->pf.vf_event_bmap, active_vfs, i);
1174c0c050c5SMichael Chan 		if (vf_id >= active_vfs)
1175c0c050c5SMichael Chan 			break;
1176c0c050c5SMichael Chan 
1177c0c050c5SMichael Chan 		clear_bit(vf_id, bp->pf.vf_event_bmap);
1178c0c050c5SMichael Chan 		bnxt_vf_req_validate_snd(bp, &bp->pf.vf[vf_id]);
1179c0c050c5SMichael Chan 		i = vf_id + 1;
1180c0c050c5SMichael Chan 	}
1181c0c050c5SMichael Chan }
1182379a80a1SMichael Chan 
bnxt_approve_mac(struct bnxt * bp,const u8 * mac,bool strict)118376660757SJakub Kicinski int bnxt_approve_mac(struct bnxt *bp, const u8 *mac, bool strict)
11847b3c8e27SMichael Chan {
1185bbf33d1dSEdwin Peer 	struct hwrm_func_vf_cfg_input *req;
11867b3c8e27SMichael Chan 	int rc = 0;
11877b3c8e27SMichael Chan 
11887b3c8e27SMichael Chan 	if (!BNXT_VF(bp))
11897b3c8e27SMichael Chan 		return 0;
11907b3c8e27SMichael Chan 
11917b3c8e27SMichael Chan 	if (bp->hwrm_spec_code < 0x10202) {
11927b3c8e27SMichael Chan 		if (is_valid_ether_addr(bp->vf.mac_addr))
11937b3c8e27SMichael Chan 			rc = -EADDRNOTAVAIL;
11947b3c8e27SMichael Chan 		goto mac_done;
11957b3c8e27SMichael Chan 	}
1196bbf33d1dSEdwin Peer 
1197bbf33d1dSEdwin Peer 	rc = hwrm_req_init(bp, req, HWRM_FUNC_VF_CFG);
1198bbf33d1dSEdwin Peer 	if (rc)
1199bbf33d1dSEdwin Peer 		goto mac_done;
1200bbf33d1dSEdwin Peer 
1201bbf33d1dSEdwin Peer 	req->enables = cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_DFLT_MAC_ADDR);
1202bbf33d1dSEdwin Peer 	memcpy(req->dflt_mac_addr, mac, ETH_ALEN);
1203bbf33d1dSEdwin Peer 	if (!strict)
1204bbf33d1dSEdwin Peer 		hwrm_req_flags(bp, req, BNXT_HWRM_CTX_SILENT);
1205bbf33d1dSEdwin Peer 	rc = hwrm_req_send(bp, req);
12067b3c8e27SMichael Chan mac_done:
12077b3c8e27SMichael Chan 	if (rc && strict) {
12087b3c8e27SMichael Chan 		rc = -EADDRNOTAVAIL;
12097b3c8e27SMichael Chan 		netdev_warn(bp->dev, "VF MAC address %pM not approved by the PF\n",
12107b3c8e27SMichael Chan 			    mac);
12117b3c8e27SMichael Chan 		return rc;
12127b3c8e27SMichael Chan 	}
12137b3c8e27SMichael Chan 	return 0;
12147b3c8e27SMichael Chan }
12157b3c8e27SMichael Chan 
bnxt_update_vf_mac(struct bnxt * bp)1216379a80a1SMichael Chan void bnxt_update_vf_mac(struct bnxt *bp)
1217379a80a1SMichael Chan {
1218bbf33d1dSEdwin Peer 	struct hwrm_func_qcaps_output *resp;
1219bbf33d1dSEdwin Peer 	struct hwrm_func_qcaps_input *req;
122092923cc7SMichael Chan 	bool inform_pf = false;
1221379a80a1SMichael Chan 
1222bbf33d1dSEdwin Peer 	if (hwrm_req_init(bp, req, HWRM_FUNC_QCAPS))
1223bbf33d1dSEdwin Peer 		return;
1224379a80a1SMichael Chan 
1225bbf33d1dSEdwin Peer 	req->fid = cpu_to_le16(0xffff);
1226bbf33d1dSEdwin Peer 
1227bbf33d1dSEdwin Peer 	resp = hwrm_req_hold(bp, req);
1228bbf33d1dSEdwin Peer 	if (hwrm_req_send(bp, req))
1229379a80a1SMichael Chan 		goto update_vf_mac_exit;
1230379a80a1SMichael Chan 
12313874d6a8SJeffrey Huang 	/* Store MAC address from the firmware.  There are 2 cases:
12323874d6a8SJeffrey Huang 	 * 1. MAC address is valid.  It is assigned from the PF and we
12333874d6a8SJeffrey Huang 	 *    need to override the current VF MAC address with it.
12343874d6a8SJeffrey Huang 	 * 2. MAC address is zero.  The VF will use a random MAC address by
12353874d6a8SJeffrey Huang 	 *    default but the stored zero MAC will allow the VF user to change
12363874d6a8SJeffrey Huang 	 *    the random MAC address using ndo_set_mac_address() if he wants.
12373874d6a8SJeffrey Huang 	 */
123892923cc7SMichael Chan 	if (!ether_addr_equal(resp->mac_address, bp->vf.mac_addr)) {
123911f15ed3SMichael Chan 		memcpy(bp->vf.mac_addr, resp->mac_address, ETH_ALEN);
124092923cc7SMichael Chan 		/* This means we are now using our own MAC address, let
124192923cc7SMichael Chan 		 * the PF know about this MAC address.
124292923cc7SMichael Chan 		 */
124392923cc7SMichael Chan 		if (!is_valid_ether_addr(bp->vf.mac_addr))
124492923cc7SMichael Chan 			inform_pf = true;
124592923cc7SMichael Chan 	}
12463874d6a8SJeffrey Huang 
12473874d6a8SJeffrey Huang 	/* overwrite netdev dev_addr with admin VF MAC */
12483874d6a8SJeffrey Huang 	if (is_valid_ether_addr(bp->vf.mac_addr))
1249a96d317fSJakub Kicinski 		eth_hw_addr_set(bp->dev, bp->vf.mac_addr);
1250379a80a1SMichael Chan update_vf_mac_exit:
1251bbf33d1dSEdwin Peer 	hwrm_req_drop(bp, req);
125292923cc7SMichael Chan 	if (inform_pf)
125392923cc7SMichael Chan 		bnxt_approve_mac(bp, bp->dev->dev_addr, false);
1254379a80a1SMichael Chan }
1255379a80a1SMichael Chan 
1256c0c050c5SMichael Chan #else
1257c0c050c5SMichael Chan 
bnxt_cfg_hw_sriov(struct bnxt * bp,int * num_vfs,bool reset)12582cd86968SVasundhara Volam int bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset)
1259702d5011SMichael Chan {
1260702d5011SMichael Chan 	if (*num_vfs)
1261702d5011SMichael Chan 		return -EOPNOTSUPP;
1262702d5011SMichael Chan 	return 0;
1263702d5011SMichael Chan }
1264702d5011SMichael Chan 
bnxt_sriov_disable(struct bnxt * bp)1265c0c050c5SMichael Chan void bnxt_sriov_disable(struct bnxt *bp)
1266c0c050c5SMichael Chan {
1267c0c050c5SMichael Chan }
1268c0c050c5SMichael Chan 
bnxt_hwrm_exec_fwd_req(struct bnxt * bp)1269c0c050c5SMichael Chan void bnxt_hwrm_exec_fwd_req(struct bnxt *bp)
1270c0c050c5SMichael Chan {
1271379a80a1SMichael Chan 	netdev_err(bp->dev, "Invalid VF message received when SRIOV is not enable\n");
1272379a80a1SMichael Chan }
1273379a80a1SMichael Chan 
bnxt_update_vf_mac(struct bnxt * bp)1274379a80a1SMichael Chan void bnxt_update_vf_mac(struct bnxt *bp)
1275379a80a1SMichael Chan {
1276c0c050c5SMichael Chan }
127784c33dd3SMichael Chan 
bnxt_approve_mac(struct bnxt * bp,const u8 * mac,bool strict)127876660757SJakub Kicinski int bnxt_approve_mac(struct bnxt *bp, const u8 *mac, bool strict)
127984c33dd3SMichael Chan {
128084c33dd3SMichael Chan 	return 0;
128184c33dd3SMichael Chan }
1282c0c050c5SMichael Chan #endif
1283