Skip to content

Commit

Permalink
nfp: move port init to apps
Browse files Browse the repository at this point in the history
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 <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed May 31, 2017
1 parent 69394af commit 8aa0cb0
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 35 deletions.
5 changes: 4 additions & 1 deletion drivers/net/ethernet/netronome/nfp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nfp-objs := \
nfpcore/nfp_rtsym.o \
nfpcore/nfp_target.o \
nfp_app.o \
nfp_app_nic.o \
nfp_devlink.o \
nfp_hwmon.o \
nfp_main.o \
Expand All @@ -23,7 +24,9 @@ nfp-objs := \
nfp_net_offload.o \
nfp_net_main.o \
nfp_netvf_main.o \
nfp_port.o
nfp_port.o \
bpf/main.o \
nic/main.o

ifeq ($(CONFIG_BPF_SYSCALL),y)
nfp-objs += \
Expand Down
58 changes: 58 additions & 0 deletions drivers/net/ethernet/netronome/nfp/bpf/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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,
};
21 changes: 20 additions & 1 deletion drivers/net/ethernet/netronome/nfp/nfp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,30 @@

#include <linux/slab.h>

#include "nfpcore/nfp_cpp.h"
#include "nfp_app.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;
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);
if (!app)
Expand All @@ -47,6 +65,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
app->pf = pf;
app->cpp = pf->cpp;
app->pdev = pf->pdev;
app->type = apps[i];

return app;
}
Expand Down
50 changes: 49 additions & 1 deletion drivers/net/ethernet/netronome/nfp/nfp_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,70 @@
#define _NFP_APP_H 1

struct pci_dev;
struct nfp_app;
struct nfp_cpp;
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
* @pdev: backpointer to PCI device
* @pf: backpointer to NFP PF structure
* @cpp: pointer to the CPP handle
* @type: pointer to const application ops and info
*/
struct nfp_app {
struct pci_dev *pdev;
struct nfp_pf *pf;
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);

/* Callbacks shared between apps */

int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,
unsigned int id);

#endif
86 changes: 86 additions & 0 deletions drivers/net/ethernet/netronome/nfp/nfp_app_nic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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;
}
6 changes: 6 additions & 0 deletions drivers/net/ethernet/netronome/nfp/nfp_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct pci_dev;
struct nfp_cpp;
struct nfp_cpp_area;
struct nfp_eth_table;
struct nfp_net;
struct nfp_nsp_identify;

/**
Expand Down Expand Up @@ -123,4 +124,9 @@ void nfp_net_pci_remove(struct nfp_pf *pf);
int nfp_hwmon_register(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 */
Loading

0 comments on commit 8aa0cb0

Please sign in to comment.