Skip to content

Commit 8aa0cb0

Browse files
Jakub Kicinskidavem330
authored andcommitted
nfp: move port init to apps
Start fleshing out the apps by turning the vNIC init code to a per-app callback. The two initial apps we have are NIC and eBPF. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 69394af commit 8aa0cb0

File tree

8 files changed

+309
-35
lines changed

8 files changed

+309
-35
lines changed

drivers/net/ethernet/netronome/nfp/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ nfp-objs := \
1515
nfpcore/nfp_rtsym.o \
1616
nfpcore/nfp_target.o \
1717
nfp_app.o \
18+
nfp_app_nic.o \
1819
nfp_devlink.o \
1920
nfp_hwmon.o \
2021
nfp_main.o \
@@ -23,7 +24,9 @@ nfp-objs := \
2324
nfp_net_offload.o \
2425
nfp_net_main.o \
2526
nfp_netvf_main.o \
26-
nfp_port.o
27+
nfp_port.o \
28+
bpf/main.o \
29+
nic/main.o
2730

2831
ifeq ($(CONFIG_BPF_SYSCALL),y)
2932
nfp-objs += \
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 "../nfpcore/nfp_cpp.h"
35+
#include "../nfp_app.h"
36+
#include "../nfp_main.h"
37+
#include "../nfp_net.h"
38+
#include "../nfp_port.h"
39+
40+
static int
41+
nfp_bpf_vnic_init(struct nfp_app *app, struct nfp_net *nn, unsigned int id)
42+
{
43+
/* Limit to single port, otherwise it's just a NIC */
44+
if (id > 0) {
45+
nfp_warn(app->cpp,
46+
"BPF NIC doesn't support more than one port right now\n");
47+
nn->port = nfp_port_alloc(app, NFP_PORT_INVALID, nn->dp.netdev);
48+
return PTR_ERR_OR_ZERO(nn->port);
49+
}
50+
51+
return nfp_app_nic_vnic_init(app, nn, id);
52+
}
53+
54+
const struct nfp_app_type app_bpf = {
55+
.id = NFP_APP_BPF_NIC,
56+
57+
.vnic_init = nfp_bpf_vnic_init,
58+
};

drivers/net/ethernet/netronome/nfp/nfp_app.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,30 @@
3333

3434
#include <linux/slab.h>
3535

36+
#include "nfpcore/nfp_cpp.h"
3637
#include "nfp_app.h"
3738
#include "nfp_main.h"
3839

39-
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
40+
static const struct nfp_app_type *apps[] = {
41+
&app_nic,
42+
&app_bpf,
43+
};
44+
45+
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
4046
{
4147
struct nfp_app *app;
48+
unsigned int i;
49+
50+
for (i = 0; i < ARRAY_SIZE(apps); i++)
51+
if (apps[i]->id == id)
52+
break;
53+
if (i == ARRAY_SIZE(apps)) {
54+
nfp_err(pf->cpp, "failed to find app with ID 0x%02hhx\n", id);
55+
return ERR_PTR(-EINVAL);
56+
}
57+
58+
if (WARN_ON(!apps[i]->vnic_init))
59+
return ERR_PTR(-EINVAL);
4260

4361
app = kzalloc(sizeof(*app), GFP_KERNEL);
4462
if (!app)
@@ -47,6 +65,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
4765
app->pf = pf;
4866
app->cpp = pf->cpp;
4967
app->pdev = pf->pdev;
68+
app->type = apps[i];
5069

5170
return app;
5271
}

drivers/net/ethernet/netronome/nfp/nfp_app.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,70 @@
3535
#define _NFP_APP_H 1
3636

3737
struct pci_dev;
38+
struct nfp_app;
3839
struct nfp_cpp;
3940
struct nfp_pf;
41+
struct nfp_net;
42+
43+
enum nfp_app_id {
44+
NFP_APP_CORE_NIC = 0x1,
45+
NFP_APP_BPF_NIC = 0x2,
46+
};
47+
48+
extern const struct nfp_app_type app_nic;
49+
extern const struct nfp_app_type app_bpf;
50+
51+
/**
52+
* struct nfp_app_type - application definition
53+
* @id: application ID
54+
*
55+
* Callbacks
56+
* @init: perform basic app checks
57+
* @vnic_init: init vNICs (assign port types, etc.)
58+
*/
59+
struct nfp_app_type {
60+
enum nfp_app_id id;
61+
62+
int (*init)(struct nfp_app *app);
63+
64+
int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn,
65+
unsigned int id);
66+
};
4067

4168
/**
4269
* struct nfp_app - NFP application container
4370
* @pdev: backpointer to PCI device
4471
* @pf: backpointer to NFP PF structure
4572
* @cpp: pointer to the CPP handle
73+
* @type: pointer to const application ops and info
4674
*/
4775
struct nfp_app {
4876
struct pci_dev *pdev;
4977
struct nfp_pf *pf;
5078
struct nfp_cpp *cpp;
79+
80+
const struct nfp_app_type *type;
5181
};
5282

53-
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf);
83+
static inline int nfp_app_init(struct nfp_app *app)
84+
{
85+
if (!app->type->init)
86+
return 0;
87+
return app->type->init(app);
88+
}
89+
90+
static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn,
91+
unsigned int id)
92+
{
93+
return app->type->vnic_init(app, nn, id);
94+
}
95+
96+
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
5497
void nfp_app_free(struct nfp_app *app);
5598

99+
/* Callbacks shared between apps */
100+
101+
int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
102+
unsigned int id);
103+
56104
#endif
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 "nfpcore/nfp_cpp.h"
35+
#include "nfpcore/nfp_nsp.h"
36+
#include "nfp_app.h"
37+
#include "nfp_main.h"
38+
#include "nfp_net.h"
39+
#include "nfp_port.h"
40+
41+
static int
42+
nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
43+
struct nfp_net *nn, unsigned int id)
44+
{
45+
if (!pf->eth_tbl)
46+
return 0;
47+
48+
nn->port = nfp_port_alloc(app, NFP_PORT_PHYS_PORT, nn->dp.netdev);
49+
if (IS_ERR(nn->port))
50+
return PTR_ERR(nn->port);
51+
52+
nn->port->eth_id = id;
53+
nn->port->eth_port = nfp_net_find_port(pf->eth_tbl, id);
54+
55+
/* Check if vNIC has external port associated and cfg is OK */
56+
if (!nn->port->eth_port) {
57+
nfp_err(app->cpp,
58+
"NSP port entries don't match vNICs (no entry for port #%d)\n",
59+
id);
60+
nfp_port_free(nn->port);
61+
return -EINVAL;
62+
}
63+
if (nn->port->eth_port->override_changed) {
64+
nfp_warn(app->cpp,
65+
"Config changed for port #%d, reboot required before port will be operational\n",
66+
id);
67+
nn->port->type = NFP_PORT_INVALID;
68+
return 1;
69+
}
70+
71+
return 0;
72+
}
73+
74+
int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
75+
unsigned int id)
76+
{
77+
int err;
78+
79+
err = nfp_app_nic_vnic_init_phy_port(app->pf, app, nn, id);
80+
if (err)
81+
return err < 0 ? err : 0;
82+
83+
nfp_net_get_mac_addr(nn, app->cpp, id);
84+
85+
return 0;
86+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct pci_dev;
5454
struct nfp_cpp;
5555
struct nfp_cpp_area;
5656
struct nfp_eth_table;
57+
struct nfp_net;
5758
struct nfp_nsp_identify;
5859

5960
/**
@@ -123,4 +124,9 @@ void nfp_net_pci_remove(struct nfp_pf *pf);
123124
int nfp_hwmon_register(struct nfp_pf *pf);
124125
void nfp_hwmon_unregister(struct nfp_pf *pf);
125126

127+
struct nfp_eth_table_port *
128+
nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id);
129+
void
130+
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id);
131+
126132
#endif /* NFP_MAIN_H */

0 commit comments

Comments
 (0)