Commit e5c5180a authored by David S. Miller's avatar David S. Miller

Merge branch 'nfp-ctrl-vNIC'

Jakub Kicinski says:

====================
nfp: ctrl vNIC

This series adds the ability to use one vNIC as a control channel
for passing messages to and from the application firmware.  The
implementation restructures the existing netdev vNIC code to be able
to deal with nfp_nets with netdev pointer set to NULL.  Control vNICs
are not visible to userspace (other than for dumping ring state), and
since they don't have netdevs we use a tasklet for RX and simple skb
list for TX queuing.

Due to special status of the control vNIC we have to reshuffle the
init code a bit to make sure control vNIC will be fully brought up
(and therefore communication with app FW can happen) before any netdev
or port is visible to user space.

FW will designate which vNIC is supposed to be used as control one
by setting _pf%u_net_ctrl_bar symbol.  Some FWs depend on metadata
being prepended to control message, some prefer to look at queue ID
to decide that something is a control message.  Our implementation
can cater to both.

First two users of this code will be eBPF maps and flower offloads.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2b30842b f9380629
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <linux/skbuff.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "nfpcore/nfp_cpp.h" #include "nfpcore/nfp_cpp.h"
...@@ -42,6 +43,23 @@ static const struct nfp_app_type *apps[] = { ...@@ -42,6 +43,23 @@ static const struct nfp_app_type *apps[] = {
&app_bpf, &app_bpf,
}; };
struct sk_buff *nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size)
{
struct sk_buff *skb;
if (nfp_app_ctrl_has_meta(app))
size += 8;
skb = alloc_skb(size, GFP_ATOMIC);
if (!skb)
return NULL;
if (nfp_app_ctrl_has_meta(app))
skb_reserve(skb, 8);
return skb;
}
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id) struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
{ {
struct nfp_app *app; struct nfp_app *app;
......
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
struct bpf_prog; struct bpf_prog;
struct net_device; struct net_device;
struct pci_dev; struct pci_dev;
struct sk_buff;
struct tc_to_netdev; struct tc_to_netdev;
struct sk_buff;
struct nfp_app; struct nfp_app;
struct nfp_cpp; struct nfp_cpp;
struct nfp_pf; struct nfp_pf;
...@@ -55,12 +57,16 @@ extern const struct nfp_app_type app_bpf; ...@@ -55,12 +57,16 @@ extern const struct nfp_app_type app_bpf;
* struct nfp_app_type - application definition * struct nfp_app_type - application definition
* @id: application ID * @id: application ID
* @name: application name * @name: application name
* @ctrl_has_meta: control messages have prepend of type:5/port:CTRL
* *
* Callbacks * Callbacks
* @init: perform basic app checks * @init: perform basic app checks
* @extra_cap: extra capabilities string * @extra_cap: extra capabilities string
* @vnic_init: init vNICs (assign port types, etc.) * @vnic_init: init vNICs (assign port types, etc.)
* @vnic_clean: clean up app's vNIC state * @vnic_clean: clean up app's vNIC state
* @start: start application logic
* @stop: stop application logic
* @ctrl_msg_rx: control message handler
* @setup_tc: setup TC ndo * @setup_tc: setup TC ndo
* @tc_busy: TC HW offload busy (rules loaded) * @tc_busy: TC HW offload busy (rules loaded)
* @xdp_offload: offload an XDP program * @xdp_offload: offload an XDP program
...@@ -69,6 +75,8 @@ struct nfp_app_type { ...@@ -69,6 +75,8 @@ struct nfp_app_type {
enum nfp_app_id id; enum nfp_app_id id;
const char *name; const char *name;
bool ctrl_has_meta;
int (*init)(struct nfp_app *app); int (*init)(struct nfp_app *app);
const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn); const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
...@@ -77,6 +85,11 @@ struct nfp_app_type { ...@@ -77,6 +85,11 @@ struct nfp_app_type {
unsigned int id); unsigned int id);
void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn); void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
int (*start)(struct nfp_app *app);
void (*stop)(struct nfp_app *app);
void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
int (*setup_tc)(struct nfp_app *app, struct net_device *netdev, int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
u32 handle, __be16 proto, struct tc_to_netdev *tc); u32 handle, __be16 proto, struct tc_to_netdev *tc);
bool (*tc_busy)(struct nfp_app *app, struct nfp_net *nn); bool (*tc_busy)(struct nfp_app *app, struct nfp_net *nn);
...@@ -89,6 +102,7 @@ struct nfp_app_type { ...@@ -89,6 +102,7 @@ struct nfp_app_type {
* @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
* @ctrl: pointer to ctrl vNIC struct
* @type: pointer to const application ops and info * @type: pointer to const application ops and info
*/ */
struct nfp_app { struct nfp_app {
...@@ -96,9 +110,13 @@ struct nfp_app { ...@@ -96,9 +110,13 @@ struct nfp_app {
struct nfp_pf *pf; struct nfp_pf *pf;
struct nfp_cpp *cpp; struct nfp_cpp *cpp;
struct nfp_net *ctrl;
const struct nfp_app_type *type; const struct nfp_app_type *type;
}; };
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
static inline int nfp_app_init(struct nfp_app *app) static inline int nfp_app_init(struct nfp_app *app)
{ {
if (!app->type->init) if (!app->type->init)
...@@ -118,6 +136,21 @@ static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn) ...@@ -118,6 +136,21 @@ static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
app->type->vnic_clean(app, nn); app->type->vnic_clean(app, nn);
} }
static inline int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl)
{
app->ctrl = ctrl;
if (!app->type->start)
return 0;
return app->type->start(app);
}
static inline void nfp_app_stop(struct nfp_app *app)
{
if (!app->type->stop)
return;
app->type->stop(app);
}
static inline const char *nfp_app_name(struct nfp_app *app) static inline const char *nfp_app_name(struct nfp_app *app)
{ {
if (!app) if (!app)
...@@ -125,6 +158,16 @@ static inline const char *nfp_app_name(struct nfp_app *app) ...@@ -125,6 +158,16 @@ static inline const char *nfp_app_name(struct nfp_app *app)
return app->type->name; return app->type->name;
} }
static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
{
return app && app->type->ctrl_msg_rx;
}
static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
{
return app->type->ctrl_has_meta;
}
static inline const char *nfp_app_extra_cap(struct nfp_app *app, static inline const char *nfp_app_extra_cap(struct nfp_app *app,
struct nfp_net *nn) struct nfp_net *nn)
{ {
...@@ -163,6 +206,18 @@ static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn, ...@@ -163,6 +206,18 @@ static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
return app->type->xdp_offload(app, nn, prog); return app->type->xdp_offload(app, nn, prog);
} }
static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
{
return nfp_ctrl_tx(app->ctrl, skb);
}
static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
{
app->type->ctrl_msg_rx(app, skb);
}
struct sk_buff *nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size);
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id 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);
......
...@@ -63,12 +63,13 @@ struct nfp_nsp_identify; ...@@ -63,12 +63,13 @@ struct nfp_nsp_identify;
* @cpp: Pointer to the CPP handle * @cpp: Pointer to the CPP handle
* @app: Pointer to the APP handle * @app: Pointer to the APP handle
* @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs * @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs
* @tx_area: Pointer to the CPP area for the TX queues * @ctrl_vnic_bar: Pointer to the CPP area for the ctrl vNIC's BAR
* @rx_area: Pointer to the CPP area for the FL/RX queues * @qc_area: Pointer to the CPP area for the queues
* @irq_entries: Array of MSI-X entries for all vNICs * @irq_entries: Array of MSI-X entries for all vNICs
* @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit) * @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit)
* @num_vfs: Number of SR-IOV VFs enabled * @num_vfs: Number of SR-IOV VFs enabled
* @fw_loaded: Is the firmware loaded? * @fw_loaded: Is the firmware loaded?
* @ctrl_vnic: Pointer to the control vNIC if available
* @eth_tbl: NSP ETH table * @eth_tbl: NSP ETH table
* @nspi: NSP identification info * @nspi: NSP identification info
* @hwmon_dev: pointer to hwmon device * @hwmon_dev: pointer to hwmon device
...@@ -88,8 +89,8 @@ struct nfp_pf { ...@@ -88,8 +89,8 @@ struct nfp_pf {
struct nfp_app *app; struct nfp_app *app;
struct nfp_cpp_area *data_vnic_bar; struct nfp_cpp_area *data_vnic_bar;
struct nfp_cpp_area *tx_area; struct nfp_cpp_area *ctrl_vnic_bar;
struct nfp_cpp_area *rx_area; struct nfp_cpp_area *qc_area;
struct msix_entry *irq_entries; struct msix_entry *irq_entries;
...@@ -98,6 +99,8 @@ struct nfp_pf { ...@@ -98,6 +99,8 @@ struct nfp_pf {
bool fw_loaded; bool fw_loaded;
struct nfp_net *ctrl_vnic;
struct nfp_eth_table *eth_tbl; struct nfp_eth_table *eth_tbl;
struct nfp_nsp_identify *nspi; struct nfp_nsp_identify *nspi;
...@@ -129,4 +132,6 @@ nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id); ...@@ -129,4 +132,6 @@ nfp_net_find_port(struct nfp_eth_table *eth_tbl, unsigned int id);
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);
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
#endif /* NFP_MAIN_H */ #endif /* NFP_MAIN_H */
...@@ -50,15 +50,32 @@ ...@@ -50,15 +50,32 @@
#include "nfp_net_ctrl.h" #include "nfp_net_ctrl.h"
#define nn_err(nn, fmt, args...) netdev_err((nn)->dp.netdev, fmt, ## args) #define nn_pr(nn, lvl, fmt, args...) \
#define nn_warn(nn, fmt, args...) netdev_warn((nn)->dp.netdev, fmt, ## args) ({ \
#define nn_info(nn, fmt, args...) netdev_info((nn)->dp.netdev, fmt, ## args) struct nfp_net *__nn = (nn); \
#define nn_dbg(nn, fmt, args...) netdev_dbg((nn)->dp.netdev, fmt, ## args) \
if (__nn->dp.netdev) \
netdev_printk(lvl, __nn->dp.netdev, fmt, ## args); \
else \
dev_printk(lvl, __nn->dp.dev, "ctrl: " fmt, ## args); \
})
#define nn_err(nn, fmt, args...) nn_pr(nn, KERN_ERR, fmt, ## args)
#define nn_warn(nn, fmt, args...) nn_pr(nn, KERN_WARNING, fmt, ## args)
#define nn_info(nn, fmt, args...) nn_pr(nn, KERN_INFO, fmt, ## args)
#define nn_dbg(nn, fmt, args...) nn_pr(nn, KERN_DEBUG, fmt, ## args)
#define nn_dp_warn(dp, fmt, args...) \ #define nn_dp_warn(dp, fmt, args...) \
do { \ ({ \
if (unlikely(net_ratelimit())) \ struct nfp_net_dp *__dp = (dp); \
netdev_warn((dp)->netdev, fmt, ## args); \ \
} while (0) if (unlikely(net_ratelimit())) { \
if (__dp->netdev) \
netdev_warn(__dp->netdev, fmt, ## args); \
else \
dev_warn(__dp->dev, fmt, ## args); \
} \
})
/* Max time to wait for NFP to respond on updates (in seconds) */ /* Max time to wait for NFP to respond on updates (in seconds) */
#define NFP_NET_POLL_TIMEOUT 5 #define NFP_NET_POLL_TIMEOUT 5
...@@ -388,7 +405,14 @@ struct nfp_net_rx_ring { ...@@ -388,7 +405,14 @@ struct nfp_net_rx_ring {
*/ */
struct nfp_net_r_vector { struct nfp_net_r_vector {
struct nfp_net *nfp_net; struct nfp_net *nfp_net;
struct napi_struct napi; union {
struct napi_struct napi;
struct {
struct tasklet_struct tasklet;
struct sk_buff_head queue;
struct spinlock lock;
};
};
struct nfp_net_tx_ring *tx_ring; struct nfp_net_tx_ring *tx_ring;
struct nfp_net_rx_ring *rx_ring; struct nfp_net_rx_ring *rx_ring;
...@@ -681,6 +705,7 @@ static inline void nn_pci_flush(struct nfp_net *nn) ...@@ -681,6 +705,7 @@ static inline void nn_pci_flush(struct nfp_net *nn)
* either add to a pointer or to read the pointer value. * either add to a pointer or to read the pointer value.
*/ */
#define NFP_QCP_QUEUE_ADDR_SZ 0x800 #define NFP_QCP_QUEUE_ADDR_SZ 0x800
#define NFP_QCP_QUEUE_AREA_SZ 0x80000
#define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ) #define NFP_QCP_QUEUE_OFF(_x) ((_x) * NFP_QCP_QUEUE_ADDR_SZ)
#define NFP_QCP_QUEUE_ADD_RPTR 0x0000 #define NFP_QCP_QUEUE_ADD_RPTR 0x0000
#define NFP_QCP_QUEUE_ADD_WPTR 0x0004 #define NFP_QCP_QUEUE_ADD_WPTR 0x0004
...@@ -788,6 +813,22 @@ static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q) ...@@ -788,6 +813,22 @@ static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q)
return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR); return _nfp_qcp_read(q, NFP_QCP_WRITE_PTR);
} }
static inline bool nfp_net_is_data_vnic(struct nfp_net *nn)
{
WARN_ON_ONCE(!nn->dp.netdev && nn->port);
return !!nn->dp.netdev;
}
static inline bool nfp_net_running(struct nfp_net *nn)
{
return nn->dp.ctrl & NFP_NET_CFG_CTRL_ENABLE;
}
static inline const char *nfp_net_name(struct nfp_net *nn)
{
return nn->dp.netdev ? nn->dp.netdev->name : "ctrl";
}
/* Globals */ /* Globals */
extern const char nfp_driver_version[]; extern const char nfp_driver_version[];
...@@ -803,13 +844,16 @@ void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver, ...@@ -803,13 +844,16 @@ void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver,
void __iomem *ctrl_bar); void __iomem *ctrl_bar);
struct nfp_net * struct nfp_net *
nfp_net_alloc(struct pci_dev *pdev, nfp_net_alloc(struct pci_dev *pdev, bool needs_netdev,
unsigned int max_tx_rings, unsigned int max_rx_rings); unsigned int max_tx_rings, unsigned int max_rx_rings);
void nfp_net_free(struct nfp_net *nn); void nfp_net_free(struct nfp_net *nn);
int nfp_net_init(struct nfp_net *nn); int nfp_net_init(struct nfp_net *nn);
void nfp_net_clean(struct nfp_net *nn); void nfp_net_clean(struct nfp_net *nn);
int nfp_ctrl_open(struct nfp_net *nn);
void nfp_ctrl_close(struct nfp_net *nn);
void nfp_net_set_ethtool_ops(struct net_device *netdev); void nfp_net_set_ethtool_ops(struct net_device *netdev);
void nfp_net_info(struct nfp_net *nn); void nfp_net_info(struct nfp_net *nn);
int nfp_net_reconfig(struct nfp_net *nn, u32 update); int nfp_net_reconfig(struct nfp_net *nn, u32 update);
......
...@@ -71,8 +71,11 @@ ...@@ -71,8 +71,11 @@
#define NFP_NET_META_FIELD_SIZE 4 #define NFP_NET_META_FIELD_SIZE 4
#define NFP_NET_META_HASH 1 /* next field carries hash type */ #define NFP_NET_META_HASH 1 /* next field carries hash type */
#define NFP_NET_META_MARK 2 #define NFP_NET_META_MARK 2
#define NFP_NET_META_PORTID 5
#define NFP_NET_META_CSUM 6 /* checksum complete type */ #define NFP_NET_META_CSUM 6 /* checksum complete type */
#define NFP_META_PORT_ID_CTRL ~0U
/** /**
* Hash type pre-pended when a RSS hash was computed * Hash type pre-pended when a RSS hash was computed
*/ */
......
...@@ -54,7 +54,7 @@ static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data) ...@@ -54,7 +54,7 @@ static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data)
goto out; goto out;
nn = r_vec->nfp_net; nn = r_vec->nfp_net;
rx_ring = r_vec->rx_ring; rx_ring = r_vec->rx_ring;
if (!netif_running(nn->dp.netdev)) if (!nfp_net_running(nn))
goto out; goto out;
rxd_cnt = rx_ring->cnt; rxd_cnt = rx_ring->cnt;
...@@ -138,7 +138,7 @@ static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data) ...@@ -138,7 +138,7 @@ static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data)
if (!r_vec->nfp_net || !tx_ring) if (!r_vec->nfp_net || !tx_ring)
goto out; goto out;
nn = r_vec->nfp_net; nn = r_vec->nfp_net;
if (!netif_running(nn->dp.netdev)) if (!nfp_net_running(nn))
goto out; goto out;
txd_cnt = tx_ring->cnt; txd_cnt = tx_ring->cnt;
...@@ -209,7 +209,10 @@ void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir, int id) ...@@ -209,7 +209,10 @@ void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir, int id)
if (IS_ERR_OR_NULL(nfp_dir)) if (IS_ERR_OR_NULL(nfp_dir))
return; return;
sprintf(name, "vnic%d", id); if (nfp_net_is_data_vnic(nn))
sprintf(name, "vnic%d", id);
else
strcpy(name, "ctrl-vnic");
nn->debugfs_dir = debugfs_create_dir(name, ddir); nn->debugfs_dir = debugfs_create_dir(name, ddir);
if (IS_ERR_OR_NULL(nn->debugfs_dir)) if (IS_ERR_OR_NULL(nn->debugfs_dir))
return; return;
......
...@@ -161,7 +161,7 @@ static int nfp_netvf_pci_probe(struct pci_dev *pdev, ...@@ -161,7 +161,7 @@ static int nfp_netvf_pci_probe(struct pci_dev *pdev,
dev_warn(&pdev->dev, "OBSOLETE Firmware detected - VF isolation not available\n"); dev_warn(&pdev->dev, "OBSOLETE Firmware detected - VF isolation not available\n");
} else { } else {
switch (fw_ver.major) { switch (fw_ver.major) {
case 1 ... 4: case 1 ... 5:
stride = 4; stride = 4;
tx_bar_no = NFP_NET_Q0_BAR; tx_bar_no = NFP_NET_Q0_BAR;
rx_bar_no = tx_bar_no; rx_bar_no = tx_bar_no;
...@@ -202,7 +202,7 @@ static int nfp_netvf_pci_probe(struct pci_dev *pdev, ...@@ -202,7 +202,7 @@ static int nfp_netvf_pci_probe(struct pci_dev *pdev,
rx_bar_off = NFP_PCIE_QUEUE(startq); rx_bar_off = NFP_PCIE_QUEUE(startq);
/* Allocate and initialise the netdev */ /* Allocate and initialise the netdev */
nn = nfp_net_alloc(pdev, max_tx_rings, max_rx_rings); nn = nfp_net_alloc(pdev, true, max_tx_rings, max_rx_rings);
if (IS_ERR(nn)) { if (IS_ERR(nn)) {
err = PTR_ERR(nn); err = PTR_ERR(nn);
goto err_ctrl_unmap; goto err_ctrl_unmap;
......
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