Commit 8aa0cb00 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

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: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 69394af5
...@@ -15,6 +15,7 @@ nfp-objs := \ ...@@ -15,6 +15,7 @@ nfp-objs := \
nfpcore/nfp_rtsym.o \ nfpcore/nfp_rtsym.o \
nfpcore/nfp_target.o \ nfpcore/nfp_target.o \
nfp_app.o \ nfp_app.o \
nfp_app_nic.o \
nfp_devlink.o \ nfp_devlink.o \
nfp_hwmon.o \ nfp_hwmon.o \
nfp_main.o \ nfp_main.o \
...@@ -23,7 +24,9 @@ nfp-objs := \ ...@@ -23,7 +24,9 @@ nfp-objs := \
nfp_net_offload.o \ nfp_net_offload.o \
nfp_net_main.o \ nfp_net_main.o \
nfp_netvf_main.o \ nfp_netvf_main.o \
nfp_port.o nfp_port.o \
bpf/main.o \
nic/main.o
ifeq ($(CONFIG_BPF_SYSCALL),y) ifeq ($(CONFIG_BPF_SYSCALL),y)
nfp-objs += \ nfp-objs += \
......
/*
* Copyright (C) 2017 Netronome Systems, Inc.
*
* This software is dual licensed under the GNU General License Version 2,
* June 1991 as shown in the file COPYING in the top-level directory of this
* source tree or the BSD 2-Clause License provided below. You have the
* option to license this software under the complete terms of either license.
*
* The BSD 2-Clause License:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "../nfpcore/nfp_cpp.h"
#include "../nfp_app.h"
#include "../nfp_main.h"
#include "../nfp_net.h"
#include "../nfp_port.h"
static int
nfp_bpf_vnic_init(struct nfp_app *app, struct nfp_net *nn, unsigned int id)
{
/* Limit to single port, otherwise it's just a NIC */
if (id > 0) {
nfp_warn(app->cpp,
"BPF NIC doesn't support more than one port right now\n");
nn->port = nfp_port_alloc(app, NFP_PORT_INVALID, nn->dp.netdev);
return PTR_ERR_OR_ZERO(nn->port);
}
return nfp_app_nic_vnic_init(app, nn, id);
}
const struct nfp_app_type app_bpf = {
.id = NFP_APP_BPF_NIC,
.vnic_init = nfp_bpf_vnic_init,
};
...@@ -33,12 +33,30 @@ ...@@ -33,12 +33,30 @@
#include <linux/slab.h> #include <linux/slab.h>
#include "nfpcore/nfp_cpp.h"
#include "nfp_app.h" #include "nfp_app.h"
#include "nfp_main.h" #include "nfp_main.h"
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf) static const struct nfp_app_type *apps[] = {
&app_nic,
&app_bpf,
};
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
{ {
struct nfp_app *app; struct nfp_app *app;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(apps); i++)
if (apps[i]->id == id)
break;
if (i == ARRAY_SIZE(apps)) {
nfp_err(pf->cpp, "failed to find app with ID 0x%02hhx\n", id);
return ERR_PTR(-EINVAL);
}
if (WARN_ON(!apps[i]->vnic_init))
return ERR_PTR(-EINVAL);
app = kzalloc(sizeof(*app), GFP_KERNEL); app = kzalloc(sizeof(*app), GFP_KERNEL);
if (!app) if (!app)
...@@ -47,6 +65,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf) ...@@ -47,6 +65,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
app->pf = pf; app->pf = pf;
app->cpp = pf->cpp; app->cpp = pf->cpp;
app->pdev = pf->pdev; app->pdev = pf->pdev;
app->type = apps[i];
return app; return app;
} }
......
...@@ -35,22 +35,70 @@ ...@@ -35,22 +35,70 @@
#define _NFP_APP_H 1 #define _NFP_APP_H 1
struct pci_dev; struct pci_dev;
struct nfp_app;
struct nfp_cpp; struct nfp_cpp;
struct nfp_pf; struct nfp_pf;
struct nfp_net;
enum nfp_app_id {
NFP_APP_CORE_NIC = 0x1,
NFP_APP_BPF_NIC = 0x2,
};
extern const struct nfp_app_type app_nic;
extern const struct nfp_app_type app_bpf;
/**
* struct nfp_app_type - application definition
* @id: application ID
*
* Callbacks
* @init: perform basic app checks
* @vnic_init: init vNICs (assign port types, etc.)
*/
struct nfp_app_type {
enum nfp_app_id id;
int (*init)(struct nfp_app *app);
int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn,
unsigned int id);
};
/** /**
* struct nfp_app - NFP application container * struct nfp_app - NFP application container
* @pdev: backpointer to PCI device * @pdev: backpointer to PCI device
* @pf: backpointer to NFP PF structure * @pf: backpointer to NFP PF structure
* @cpp: pointer to the CPP handle * @cpp: pointer to the CPP handle
* @type: pointer to const application ops and info
*/ */
struct nfp_app { struct nfp_app {
struct pci_dev *pdev; struct pci_dev *pdev;
struct nfp_pf *pf; struct nfp_pf *pf;
struct nfp_cpp *cpp; struct nfp_cpp *cpp;
const struct nfp_app_type *type;
}; };
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf); static inline int nfp_app_init(struct nfp_app *app)
{
if (!app->type->init)
return 0;
return app->type->init(app);
}
static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn,
unsigned int id)
{
return app->type->vnic_init(app, nn, id);
}
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
void nfp_app_free(struct nfp_app *app); void nfp_app_free(struct nfp_app *app);
/* Callbacks shared between apps */
int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
unsigned int id);
#endif #endif
/*
* Copyright (C) 2017 Netronome Systems, Inc.
*
* This software is dual licensed under the GNU General License Version 2,
* June 1991 as shown in the file COPYING in the top-level directory of this
* source tree or the BSD 2-Clause License provided below. You have the
* option to license this software under the complete terms of either license.
*
* The BSD 2-Clause License:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "nfpcore/nfp_cpp.h"
#include "nfpcore/nfp_nsp.h"
#include "nfp_app.h"
#include "nfp_main.h"
#include "nfp_net.h"
#include "nfp_port.h"
static int
nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
struct nfp_net *nn, unsigned int id)
{
if (!pf->eth_tbl)
return 0;
nn->port = nfp_port_alloc(app, NFP_PORT_PHYS_PORT, nn->dp.netdev);
if (IS_ERR(nn->port))
return PTR_ERR(nn->port);
nn->port->eth_id = id;
nn->port->eth_port = nfp_net_find_port(pf->eth_tbl, id);
/* Check if vNIC has external port associated and cfg is OK */
if (!nn->port->eth_port) {
nfp_err(app->cpp,
"NSP port entries don't match vNICs (no entry for port #%d)\n",
id);
nfp_port_free(nn->port);
return -EINVAL;
}
if (nn->port->eth_port->override_changed) {
nfp_warn(app->cpp,
"Config changed for port #%d, reboot required before port will be operational\n",
id);
nn->port->type = NFP_PORT_INVALID;
return 1;
}
return 0;
}
int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
unsigned int id)
{
int err;
err = nfp_app_nic_vnic_init_phy_port(app->pf, app, nn, id);
if (err)
return err < 0 ? err : 0;
nfp_net_get_mac_addr(nn, app->cpp, id);
return 0;
}
...@@ -54,6 +54,7 @@ struct pci_dev; ...@@ -54,6 +54,7 @@ struct pci_dev;
struct nfp_cpp; struct nfp_cpp;
struct nfp_cpp_area; struct nfp_cpp_area;
struct nfp_eth_table; struct nfp_eth_table;
struct nfp_net;
struct nfp_nsp_identify; struct nfp_nsp_identify;
/** /**
...@@ -123,4 +124,9 @@ void nfp_net_pci_remove(struct nfp_pf *pf); ...@@ -123,4 +124,9 @@ void nfp_net_pci_remove(struct nfp_pf *pf);
int nfp_hwmon_register(struct nfp_pf *pf); int nfp_hwmon_register(struct nfp_pf *pf);
void nfp_hwmon_unregister(struct nfp_pf *pf); void nfp_hwmon_unregister(struct nfp_pf *pf);
struct nfp_eth_table_port *
nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id);
void
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id);
#endif /* NFP_MAIN_H */ #endif /* NFP_MAIN_H */
...@@ -141,7 +141,7 @@ static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp, ...@@ -141,7 +141,7 @@ static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp,
* First try to get the MAC address from NSP ETH table. If that * First try to get the MAC address from NSP ETH table. If that
* fails try HWInfo. As a last resort generate a random address. * fails try HWInfo. As a last resort generate a random address.
*/ */
static void void
nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id) nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id)
{ {
struct nfp_eth_table_port *eth_port; struct nfp_eth_table_port *eth_port;
...@@ -179,7 +179,7 @@ nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id) ...@@ -179,7 +179,7 @@ nfp_net_get_mac_addr(struct nfp_net *nn, struct nfp_cpp *cpp, unsigned int id)
ether_addr_copy(dp->netdev->perm_addr, mac_addr); ether_addr_copy(dp->netdev->perm_addr, mac_addr);
} }
static struct nfp_eth_table_port * struct nfp_eth_table_port *
nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id) nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id)
{ {
int i; int i;
...@@ -217,6 +217,12 @@ static int nfp_net_pf_get_num_ports(struct nfp_pf *pf) ...@@ -217,6 +217,12 @@ static int nfp_net_pf_get_num_ports(struct nfp_pf *pf)
return nfp_net_pf_rtsym_read_optional(pf, "nfd_cfg_pf%u_num_ports", 1); return nfp_net_pf_rtsym_read_optional(pf, "nfd_cfg_pf%u_num_ports", 1);
} }
static int nfp_net_pf_get_app_id(struct nfp_pf *pf)
{
return nfp_net_pf_rtsym_read_optional(pf, "_pf%u_net_app_id",
NFP_APP_CORE_NIC);
}
static unsigned int static unsigned int
nfp_net_pf_total_qcs(struct nfp_pf *pf, void __iomem *ctrl_bar, nfp_net_pf_total_qcs(struct nfp_pf *pf, void __iomem *ctrl_bar,
unsigned int stride, u32 start_off, u32 num_off) unsigned int stride, u32 start_off, u32 num_off)
...@@ -302,9 +308,9 @@ nfp_net_pf_alloc_vnic(struct nfp_pf *pf, void __iomem *ctrl_bar, ...@@ -302,9 +308,9 @@ nfp_net_pf_alloc_vnic(struct nfp_pf *pf, void __iomem *ctrl_bar,
int stride, struct nfp_net_fw_version *fw_ver, int stride, struct nfp_net_fw_version *fw_ver,
unsigned int eth_id) unsigned int eth_id)
{ {
struct nfp_eth_table_port *eth_port;
u32 n_tx_rings, n_rx_rings; u32 n_tx_rings, n_rx_rings;
struct nfp_net *nn; struct nfp_net *nn;
int err;
n_tx_rings = readl(ctrl_bar + NFP_NET_CFG_MAX_TXRINGS); n_tx_rings = readl(ctrl_bar + NFP_NET_CFG_MAX_TXRINGS);
n_rx_rings = readl(ctrl_bar + NFP_NET_CFG_MAX_RXRINGS); n_rx_rings = readl(ctrl_bar + NFP_NET_CFG_MAX_RXRINGS);
...@@ -323,16 +329,10 @@ nfp_net_pf_alloc_vnic(struct nfp_pf *pf, void __iomem *ctrl_bar, ...@@ -323,16 +329,10 @@ nfp_net_pf_alloc_vnic(struct nfp_pf *pf, void __iomem *ctrl_bar,
nn->stride_rx = stride; nn->stride_rx = stride;
nn->stride_tx = stride; nn->stride_tx = stride;
eth_port = nfp_net_find_port(pf->eth_tbl, eth_id); err = nfp_app_vnic_init(pf->app, nn, eth_id);
if (eth_port) { if (err) {
nn->port = nfp_port_alloc(pf->app, NFP_PORT_PHYS_PORT,
nn->dp.netdev);
if (IS_ERR(nn->port)) {
nfp_net_free(nn); nfp_net_free(nn);
return ERR_CAST(nn->port); return ERR_PTR(err);
}
nn->port->eth_id = eth_id;
nn->port->eth_port = eth_port;
} }
pf->num_vnics++; pf->num_vnics++;
...@@ -346,9 +346,6 @@ nfp_net_pf_init_vnic(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id) ...@@ -346,9 +346,6 @@ nfp_net_pf_init_vnic(struct nfp_pf *pf, struct nfp_net *nn, unsigned int id)
{ {
int err; int err;
/* Get MAC address */
nfp_net_get_mac_addr(nn, pf->cpp, id);
/* Get ME clock frequency from ctrl BAR /* Get ME clock frequency from ctrl BAR
* XXX for now frequency is hardcoded until we figure out how * XXX for now frequency is hardcoded until we figure out how
* to get the value from nfp-hwinfo into ctrl bar * to get the value from nfp-hwinfo into ctrl bar
...@@ -387,12 +384,6 @@ nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, ...@@ -387,12 +384,6 @@ nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar,
unsigned int i; unsigned int i;
int err; int err;
if (pf->eth_tbl && pf->max_data_vnics != pf->eth_tbl->count) {
nfp_err(pf->cpp, "ETH entries don't match vNICs (%d vs %d)\n",
pf->max_data_vnics, pf->eth_tbl->count);
return -EINVAL;
}
prev_tx_base = readl(ctrl_bar + NFP_NET_CFG_START_TXQ); prev_tx_base = readl(ctrl_bar + NFP_NET_CFG_START_TXQ);
prev_rx_base = readl(ctrl_bar + NFP_NET_CFG_START_RXQ); prev_rx_base = readl(ctrl_bar + NFP_NET_CFG_START_RXQ);
...@@ -413,14 +404,8 @@ nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar, ...@@ -413,14 +404,8 @@ nfp_net_pf_alloc_vnics(struct nfp_pf *pf, void __iomem *ctrl_bar,
ctrl_bar += NFP_PF_CSR_SLICE_SIZE; ctrl_bar += NFP_PF_CSR_SLICE_SIZE;
/* Check if vNIC has external port associated and cfg is OK */ /* Kill the vNIC if app init marked it as invalid */
if (pf->eth_tbl && !nn->port) { if (nn->port && nn->port->type == NFP_PORT_INVALID) {
nfp_err(pf->cpp, "NSP port entries don't match vNICs (no entry for port #%d)\n", i);
err = -EINVAL;
goto err_free_prev;
}
if (nn->port && nn->port->eth_port->override_changed) {
nfp_warn(pf->cpp, "Config changed for port #%d, reboot required before port will be operational\n", i);
nfp_net_pf_free_vnic(pf, nn); nfp_net_pf_free_vnic(pf, nn);
continue; continue;
} }
...@@ -518,9 +503,21 @@ nfp_net_pf_spawn_vnics(struct nfp_pf *pf, ...@@ -518,9 +503,21 @@ nfp_net_pf_spawn_vnics(struct nfp_pf *pf,
static int nfp_net_pf_app_init(struct nfp_pf *pf) static int nfp_net_pf_app_init(struct nfp_pf *pf)
{ {
pf->app = nfp_app_alloc(pf); int err;
pf->app = nfp_app_alloc(pf, nfp_net_pf_get_app_id(pf));
if (IS_ERR(pf->app))
return PTR_ERR(pf->app);
return PTR_ERR_OR_ZERO(pf->app); err = nfp_app_init(pf->app);
if (err)
goto err_free;
return 0;
err_free:
nfp_app_free(pf->app);
return err;
} }
static void nfp_net_pf_app_clean(struct nfp_pf *pf) static void nfp_net_pf_app_clean(struct nfp_pf *pf)
......
/*
* Copyright (C) 2017 Netronome Systems, Inc.
*
* This software is dual licensed under the GNU General License Version 2,
* June 1991 as shown in the file COPYING in the top-level directory of this
* source tree or the BSD 2-Clause License provided below. You have the
* option to license this software under the complete terms of either license.
*
* The BSD 2-Clause License:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "../nfpcore/nfp_cpp.h"
#include "../nfpcore/nfp_nsp.h"
#include "../nfp_app.h"
#include "../nfp_main.h"
static int nfp_nic_init(struct nfp_app *app)
{
struct nfp_pf *pf = app->pf;
if (pf->eth_tbl && pf->max_data_vnics != pf->eth_tbl->count) {
nfp_err(pf->cpp, "ETH entries don't match vNICs (%d vs %d)\n",
pf->max_data_vnics, pf->eth_tbl->count);
return -EINVAL;
}
return 0;
}
const struct nfp_app_type app_nic = {
.id = NFP_APP_CORE_NIC,
.init = nfp_nic_init,
.vnic_init = nfp_app_nic_vnic_init,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment