Skip to content

Commit fac0cef

Browse files
committed
Merge branch 'nfp-SR-IOV-ndos-support'
Jakub Kicinski says: ==================== nfp: SR-IOV ndos support This set adds basic SR-IOV including setting/getting VF MAC addresses, VLANs, link state and spoofcheck settings. It is wired up for both vNICs and representors (note: ip link will not report VF settings on VF/PF representors because they are not linked to the PF PCI device). Pablo and team add the basic implementation, Simon and Dirk follow up with the representor plumbing. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents bd9dfc5 + 6abd224 commit fac0cef

9 files changed

Lines changed: 378 additions & 1 deletion

File tree

‎drivers/net/ethernet/netronome/nfp/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ nfp-objs := \
2323
nfp_net_ethtool.o \
2424
nfp_net_main.o \
2525
nfp_net_repr.o \
26+
nfp_net_sriov.o \
2627
nfp_netvf_main.o \
2728
nfp_port.o \
2829
bpf/main.o \

‎drivers/net/ethernet/netronome/nfp/nfp_main.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct nfp_rtsym_table;
7373
* @mac_stats_mem: Pointer to mapped MAC stats area
7474
* @vf_cfg_bar: Pointer to the CPP area for the VF configuration BAR
7575
* @vf_cfg_mem: Pointer to mapped VF configuration area
76+
* @vfcfg_tbl2_area: Pointer to the CPP area for the VF config table
77+
* @vfcfg_tbl2: Pointer to mapped VF config table
7678
* @irq_entries: Array of MSI-X entries for all vNICs
7779
* @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit)
7880
* @num_vfs: Number of SR-IOV VFs enabled
@@ -107,6 +109,8 @@ struct nfp_pf {
107109
u8 __iomem *mac_stats_mem;
108110
struct nfp_cpp_area *vf_cfg_bar;
109111
u8 __iomem *vf_cfg_mem;
112+
struct nfp_cpp_area *vfcfg_tbl2_area;
113+
u8 __iomem *vfcfg_tbl2;
110114

111115
struct msix_entry *irq_entries;
112116

‎drivers/net/ethernet/netronome/nfp/nfp_net_common.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "nfp_app.h"
7272
#include "nfp_net_ctrl.h"
7373
#include "nfp_net.h"
74+
#include "nfp_net_sriov.h"
7475
#include "nfp_port.h"
7576

7677
/**
@@ -3421,6 +3422,11 @@ const struct net_device_ops nfp_net_netdev_ops = {
34213422
.ndo_get_stats64 = nfp_net_stat64,
34223423
.ndo_vlan_rx_add_vid = nfp_net_vlan_rx_add_vid,
34233424
.ndo_vlan_rx_kill_vid = nfp_net_vlan_rx_kill_vid,
3425+
.ndo_set_vf_mac = nfp_app_set_vf_mac,
3426+
.ndo_set_vf_vlan = nfp_app_set_vf_vlan,
3427+
.ndo_set_vf_spoofchk = nfp_app_set_vf_spoofchk,
3428+
.ndo_get_vf_config = nfp_app_get_vf_config,
3429+
.ndo_set_vf_link_state = nfp_app_set_vf_link_state,
34243430
.ndo_setup_tc = nfp_port_setup_tc,
34253431
.ndo_tx_timeout = nfp_net_tx_timeout,
34263432
.ndo_set_rx_mode = nfp_net_set_rx_mode,

‎drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
#define NFP_NET_CFG_UPDATE_BPF (0x1 << 10) /* BPF program load */
165165
#define NFP_NET_CFG_UPDATE_MACADDR (0x1 << 11) /* MAC address change */
166166
#define NFP_NET_CFG_UPDATE_MBOX (0x1 << 12) /* Mailbox update */
167+
#define NFP_NET_CFG_UPDATE_VF (0x1 << 13) /* VF settings change */
167168
#define NFP_NET_CFG_UPDATE_ERR (0x1 << 31) /* A error occurred */
168169
#define NFP_NET_CFG_TXRS_ENABLE 0x0008
169170
#define NFP_NET_CFG_RXRS_ENABLE 0x0010

‎drivers/net/ethernet/netronome/nfp/nfp_net_main.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "nfpcore/nfp6000_pcie.h"
5858
#include "nfp_app.h"
5959
#include "nfp_net_ctrl.h"
60+
#include "nfp_net_sriov.h"
6061
#include "nfp_net.h"
6162
#include "nfp_main.h"
6263
#include "nfp_port.h"
@@ -489,6 +490,8 @@ static void nfp_net_pf_app_stop(struct nfp_pf *pf)
489490

490491
static void nfp_net_pci_unmap_mem(struct nfp_pf *pf)
491492
{
493+
if (pf->vfcfg_tbl2_area)
494+
nfp_cpp_area_release_free(pf->vfcfg_tbl2_area);
492495
if (pf->vf_cfg_bar)
493496
nfp_cpp_area_release_free(pf->vf_cfg_bar);
494497
if (pf->mac_stats_bar)
@@ -535,17 +538,32 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf)
535538
pf->vf_cfg_mem = NULL;
536539
}
537540

541+
min_size = NFP_NET_VF_CFG_SZ * pf->limit_vfs + NFP_NET_VF_CFG_MB_SZ;
542+
pf->vfcfg_tbl2 = nfp_net_pf_map_rtsym(pf, "net.vfcfg_tbl2",
543+
"_pf%d_net_vf_cfg2",
544+
min_size, &pf->vfcfg_tbl2_area);
545+
if (IS_ERR(pf->vfcfg_tbl2)) {
546+
if (PTR_ERR(pf->vfcfg_tbl2) != -ENOENT) {
547+
err = PTR_ERR(pf->vfcfg_tbl2);
548+
goto err_unmap_vf_cfg;
549+
}
550+
pf->vfcfg_tbl2 = NULL;
551+
}
552+
538553
mem = nfp_cpp_map_area(pf->cpp, "net.qc", 0, 0,
539554
NFP_PCIE_QUEUE(0), NFP_QCP_QUEUE_AREA_SZ,
540555
&pf->qc_area);
541556
if (IS_ERR(mem)) {
542557
nfp_err(pf->cpp, "Failed to map Queue Controller area.\n");
543558
err = PTR_ERR(mem);
544-
goto err_unmap_vf_cfg;
559+
goto err_unmap_vfcfg_tbl2;
545560
}
546561

547562
return 0;
548563

564+
err_unmap_vfcfg_tbl2:
565+
if (pf->vfcfg_tbl2_area)
566+
nfp_cpp_area_release_free(pf->vfcfg_tbl2_area);
549567
err_unmap_vf_cfg:
550568
if (pf->vf_cfg_bar)
551569
nfp_cpp_area_release_free(pf->vf_cfg_bar);

‎drivers/net/ethernet/netronome/nfp/nfp_net_repr.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "nfp_main.h"
4444
#include "nfp_net_ctrl.h"
4545
#include "nfp_net_repr.h"
46+
#include "nfp_net_sriov.h"
4647
#include "nfp_port.h"
4748

4849
static void
@@ -247,6 +248,11 @@ const struct net_device_ops nfp_repr_netdev_ops = {
247248
.ndo_get_offload_stats = nfp_repr_get_offload_stats,
248249
.ndo_get_phys_port_name = nfp_port_get_phys_port_name,
249250
.ndo_setup_tc = nfp_port_setup_tc,
251+
.ndo_set_vf_mac = nfp_app_set_vf_mac,
252+
.ndo_set_vf_vlan = nfp_app_set_vf_vlan,
253+
.ndo_set_vf_spoofchk = nfp_app_set_vf_spoofchk,
254+
.ndo_get_vf_config = nfp_app_get_vf_config,
255+
.ndo_set_vf_link_state = nfp_app_set_vf_link_state,
250256
};
251257

252258
static void nfp_repr_clean(struct nfp_repr *repr)
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
/*
2+
* Copyright (C) 2017 Netronome Systems, Inc.
3+
*
4+
* This software is dual licensed under the GNU General License Version 2,
5+
* June 1991 as shown in the file COPYING in the top-level directory of this
6+
* source tree or the BSD 2-Clause License provided below. You have the
7+
* option to license this software under the complete terms of either license.
8+
*
9+
* The BSD 2-Clause License:
10+
*
11+
* Redistribution and use in source and binary forms, with or
12+
* without modification, are permitted provided that the following
13+
* conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above
16+
* copyright notice, this list of conditions and the following
17+
* disclaimer.
18+
*
19+
* 2. Redistributions in binary form must reproduce the above
20+
* copyright notice, this list of conditions and the following
21+
* disclaimer in the documentation and/or other materials
22+
* provided with the distribution.
23+
*
24+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
* SOFTWARE.
32+
*/
33+
34+
#include <linux/bitfield.h>
35+
#include <linux/errno.h>
36+
#include <linux/etherdevice.h>
37+
#include <linux/if_link.h>
38+
#include <linux/if_ether.h>
39+
40+
#include "nfpcore/nfp_cpp.h"
41+
#include "nfp_app.h"
42+
#include "nfp_main.h"
43+
#include "nfp_net_ctrl.h"
44+
#include "nfp_net.h"
45+
#include "nfp_net_sriov.h"
46+
47+
static int
48+
nfp_net_sriov_check(struct nfp_app *app, int vf, u16 cap, const char *msg)
49+
{
50+
u16 cap_vf;
51+
52+
if (!app || !app->pf->vfcfg_tbl2)
53+
return -EOPNOTSUPP;
54+
55+
cap_vf = readw(app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_CAP);
56+
if ((cap_vf & cap) != cap) {
57+
nfp_warn(app->pf->cpp, "ndo_set_vf_%s not supported\n", msg);
58+
return -EOPNOTSUPP;
59+
}
60+
61+
if (vf < 0 || vf >= app->pf->num_vfs) {
62+
nfp_warn(app->pf->cpp, "invalid VF id %d\n", vf);
63+
return -EINVAL;
64+
}
65+
66+
return 0;
67+
}
68+
69+
static int
70+
nfp_net_sriov_update(struct nfp_app *app, int vf, u16 update, const char *msg)
71+
{
72+
struct nfp_net *nn;
73+
int ret;
74+
75+
/* Write update info to mailbox in VF config symbol */
76+
writeb(vf, app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_VF_NUM);
77+
writew(update, app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_UPD);
78+
79+
nn = list_first_entry(&app->pf->vnics, struct nfp_net, vnic_list);
80+
/* Signal VF reconfiguration */
81+
ret = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_VF);
82+
if (ret)
83+
return ret;
84+
85+
ret = readw(app->pf->vfcfg_tbl2 + NFP_NET_VF_CFG_MB_RET);
86+
if (ret)
87+
nfp_warn(app->pf->cpp,
88+
"FW refused VF %s update with errno: %d\n", msg, ret);
89+
return -ret;
90+
}
91+
92+
int nfp_app_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
93+
{
94+
struct nfp_app *app = nfp_app_from_netdev(netdev);
95+
unsigned int vf_offset;
96+
int err;
97+
98+
err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_MAC, "mac");
99+
if (err)
100+
return err;
101+
102+
if (is_multicast_ether_addr(mac)) {
103+
nfp_warn(app->pf->cpp,
104+
"invalid Ethernet address %pM for VF id %d\n",
105+
mac, vf);
106+
return -EINVAL;
107+
}
108+
109+
/* Write MAC to VF entry in VF config symbol */
110+
vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ;
111+
writel(get_unaligned_be32(mac), app->pf->vfcfg_tbl2 + vf_offset);
112+
writew(get_unaligned_be16(mac + 4),
113+
app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_MAC_LO);
114+
115+
return nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_MAC, "MAC");
116+
}
117+
118+
int nfp_app_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos,
119+
__be16 vlan_proto)
120+
{
121+
struct nfp_app *app = nfp_app_from_netdev(netdev);
122+
unsigned int vf_offset;
123+
u16 vlan_tci;
124+
int err;
125+
126+
err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_VLAN, "vlan");
127+
if (err)
128+
return err;
129+
130+
if (vlan_proto != htons(ETH_P_8021Q))
131+
return -EOPNOTSUPP;
132+
133+
if (vlan > 4095 || qos > 7) {
134+
nfp_warn(app->pf->cpp,
135+
"invalid vlan id or qos for VF id %d\n", vf);
136+
return -EINVAL;
137+
}
138+
139+
/* Write VLAN tag to VF entry in VF config symbol */
140+
vlan_tci = FIELD_PREP(NFP_NET_VF_CFG_VLAN_VID, vlan) |
141+
FIELD_PREP(NFP_NET_VF_CFG_VLAN_QOS, qos);
142+
vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ;
143+
writew(vlan_tci, app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_VLAN);
144+
145+
return nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_VLAN,
146+
"vlan");
147+
}
148+
149+
int nfp_app_set_vf_spoofchk(struct net_device *netdev, int vf, bool enable)
150+
{
151+
struct nfp_app *app = nfp_app_from_netdev(netdev);
152+
unsigned int vf_offset;
153+
u8 vf_ctrl;
154+
int err;
155+
156+
err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_SPOOF,
157+
"spoofchk");
158+
if (err)
159+
return err;
160+
161+
/* Write spoof check control bit to VF entry in VF config symbol */
162+
vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ +
163+
NFP_NET_VF_CFG_CTRL;
164+
vf_ctrl = readb(app->pf->vfcfg_tbl2 + vf_offset);
165+
vf_ctrl &= ~NFP_NET_VF_CFG_CTRL_SPOOF;
166+
vf_ctrl |= FIELD_PREP(NFP_NET_VF_CFG_CTRL_SPOOF, enable);
167+
writeb(vf_ctrl, app->pf->vfcfg_tbl2 + vf_offset);
168+
169+
return nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_SPOOF,
170+
"spoofchk");
171+
}
172+
173+
int nfp_app_set_vf_link_state(struct net_device *netdev, int vf,
174+
int link_state)
175+
{
176+
struct nfp_app *app = nfp_app_from_netdev(netdev);
177+
unsigned int vf_offset;
178+
u8 vf_ctrl;
179+
int err;
180+
181+
err = nfp_net_sriov_check(app, vf, NFP_NET_VF_CFG_MB_CAP_LINK_STATE,
182+
"link_state");
183+
if (err)
184+
return err;
185+
186+
switch (link_state) {
187+
case IFLA_VF_LINK_STATE_AUTO:
188+
case IFLA_VF_LINK_STATE_ENABLE:
189+
case IFLA_VF_LINK_STATE_DISABLE:
190+
break;
191+
default:
192+
return -EINVAL;
193+
}
194+
195+
/* Write link state to VF entry in VF config symbol */
196+
vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ +
197+
NFP_NET_VF_CFG_CTRL;
198+
vf_ctrl = readb(app->pf->vfcfg_tbl2 + vf_offset);
199+
vf_ctrl &= ~NFP_NET_VF_CFG_CTRL_LINK_STATE;
200+
vf_ctrl |= FIELD_PREP(NFP_NET_VF_CFG_CTRL_LINK_STATE, link_state);
201+
writeb(vf_ctrl, app->pf->vfcfg_tbl2 + vf_offset);
202+
203+
return nfp_net_sriov_update(app, vf, NFP_NET_VF_CFG_MB_UPD_LINK_STATE,
204+
"link state");
205+
}
206+
207+
int nfp_app_get_vf_config(struct net_device *netdev, int vf,
208+
struct ifla_vf_info *ivi)
209+
{
210+
struct nfp_app *app = nfp_app_from_netdev(netdev);
211+
unsigned int vf_offset;
212+
u16 vlan_tci;
213+
u32 mac_hi;
214+
u16 mac_lo;
215+
u8 flags;
216+
int err;
217+
218+
err = nfp_net_sriov_check(app, vf, 0, "");
219+
if (err)
220+
return err;
221+
222+
vf_offset = NFP_NET_VF_CFG_MB_SZ + vf * NFP_NET_VF_CFG_SZ;
223+
224+
mac_hi = readl(app->pf->vfcfg_tbl2 + vf_offset);
225+
mac_lo = readw(app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_MAC_LO);
226+
227+
flags = readb(app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_CTRL);
228+
vlan_tci = readw(app->pf->vfcfg_tbl2 + vf_offset + NFP_NET_VF_CFG_VLAN);
229+
230+
memset(ivi, 0, sizeof(*ivi));
231+
ivi->vf = vf;
232+
233+
put_unaligned_be32(mac_hi, &ivi->mac[0]);
234+
put_unaligned_be16(mac_lo, &ivi->mac[4]);
235+
236+
ivi->vlan = FIELD_GET(NFP_NET_VF_CFG_VLAN_VID, vlan_tci);
237+
ivi->qos = FIELD_GET(NFP_NET_VF_CFG_VLAN_QOS, vlan_tci);
238+
239+
ivi->spoofchk = FIELD_GET(NFP_NET_VF_CFG_CTRL_SPOOF, flags);
240+
ivi->linkstate = FIELD_GET(NFP_NET_VF_CFG_CTRL_LINK_STATE, flags);
241+
242+
return 0;
243+
}

0 commit comments

Comments
 (0)