Skip to content

Commit

Permalink
Merge branch 'nfp-introduce-nfp_port-and-nfp_app'
Browse files Browse the repository at this point in the history
Jakub Kicinski says:

====================
nfp: introduce nfp_port and nfp_app

This series builds foundation for upcoming development.  So far the nfp
driver was focused on delivering basic NIC-like functionality.  We want
to switch gears a bit going forward and support more advanced applications.

First few patches are naming clean ups and reshuffling.  The two main
structures this series adds are nfp_port and nfp_app.

nfp_port represents a device port, where port can mean external port,
VF or PF.  For now only external port/MAC/PHY port is added.  nfp_port
is supposed to make it easy to share ethtool and devlink code regardless
of netdev type (full vNIC vs representors).

nfp_app is an abstraction which should allow easier development of new
applications.  So far we have relied fully on port capabilities to detect
which offloads and features are available.  The usual development model
for NFP is that people start with one of our "core NIC" FW apps (C one,
or a macro assembler one) and build advanced functionality on top of that.
Therefore basic netdev code is shared, but the higher-level logic is
usually more project specific.  The higher-level logic is also per-adapter
rather than per-port, so creating per-adapter control entity makes sense.
Hopefully the separation of lower-level netdev code and application logic
will help us limit interdependencies and accelerate parallel projects
(e.g. TC flower offloads vs eBPF offload).

v2:
 - don't hide definition of nfp_app to avoid silly function calls (Dave);
 - reorder kdoc of nfp_main (Simon);
 - make nfp_netdev_is_nfp_net() static inline as well.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed May 22, 2017
2 parents bd08048 + 1876749 commit 0172397
Show file tree
Hide file tree
Showing 14 changed files with 658 additions and 265 deletions.
4 changes: 3 additions & 1 deletion drivers/net/ethernet/netronome/nfp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ nfp-objs := \
nfpcore/nfp_resource.o \
nfpcore/nfp_rtsym.o \
nfpcore/nfp_target.o \
nfp_app.o \
nfp_main.o \
nfp_net_common.o \
nfp_net_ethtool.o \
nfp_net_offload.o \
nfp_net_main.o \
nfp_netvf_main.o
nfp_netvf_main.o \
nfp_port.o

ifeq ($(CONFIG_BPF_SYSCALL),y)
nfp-objs += \
Expand Down
57 changes: 57 additions & 0 deletions drivers/net/ethernet/netronome/nfp/nfp_app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 <linux/slab.h>

#include "nfp_app.h"
#include "nfp_main.h"

struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
{
struct nfp_app *app;

app = kzalloc(sizeof(*app), GFP_KERNEL);
if (!app)
return ERR_PTR(-ENOMEM);

app->pf = pf;
app->cpp = pf->cpp;
app->pdev = pf->pdev;

return app;
}

void nfp_app_free(struct nfp_app *app)
{
kfree(app);
}
56 changes: 56 additions & 0 deletions drivers/net/ethernet/netronome/nfp/nfp_app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.
*/

#ifndef _NFP_APP_H
#define _NFP_APP_H 1

struct pci_dev;
struct nfp_cpp;
struct nfp_pf;

/**
* struct nfp_app - NFP application container
* @pdev: backpointer to PCI device
* @pf: backpointer to NFP PF structure
* @cpp: pointer to the CPP handle
*/
struct nfp_app {
struct pci_dev *pdev;
struct nfp_pf *pf;
struct nfp_cpp *cpp;
};

struct nfp_app *nfp_app_alloc(struct nfp_pf *pf);
void nfp_app_free(struct nfp_app *app);

#endif
1 change: 1 addition & 0 deletions drivers/net/ethernet/netronome/nfp/nfp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ static int nfp_pci_probe(struct pci_dev *pdev,
err = -ENOMEM;
goto err_rel_regions;
}
INIT_LIST_HEAD(&pf->vnics);
INIT_LIST_HEAD(&pf->ports);
pci_set_drvdata(pdev, pf);
pf->pdev = pdev;
Expand Down
25 changes: 15 additions & 10 deletions drivers/net/ethernet/netronome/nfp/nfp_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,31 @@ struct nfp_eth_table;
* struct nfp_pf - NFP PF-specific device structure
* @pdev: Backpointer to PCI device
* @cpp: Pointer to the CPP handle
* @ctrl_area: Pointer to the CPP area for the control BAR
* @app: Pointer to the APP handle
* @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs
* @tx_area: Pointer to the CPP area for the TX queues
* @rx_area: Pointer to the CPP area for the FL/RX queues
* @irq_entries: Array of MSI-X entries for all ports
* @irq_entries: Array of MSI-X entries for all vNICs
* @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit)
* @num_vfs: Number of SR-IOV VFs enabled
* @fw_loaded: Is the firmware loaded?
* @eth_tbl: NSP ETH table
* @ddir: Per-device debugfs directory
* @num_ports: Number of adapter ports app firmware supports
* @num_netdevs: Number of netdevs spawned
* @ports: Linked list of port structures (struct nfp_net)
* @port_lock: Protects @ports, @num_ports, @num_netdevs
* @max_data_vnics: Number of data vNICs app firmware supports
* @num_vnics: Number of vNICs spawned
* @vnics: Linked list of vNIC structures (struct nfp_net)
* @ports: Linked list of port structures (struct nfp_port)
* @port_refresh_work: Work entry for taking netdevs out
* @lock: Protects all fields which may change after probe
*/
struct nfp_pf {
struct pci_dev *pdev;

struct nfp_cpp *cpp;

struct nfp_cpp_area *ctrl_area;
struct nfp_app *app;

struct nfp_cpp_area *data_vnic_bar;
struct nfp_cpp_area *tx_area;
struct nfp_cpp_area *rx_area;

Expand All @@ -92,12 +96,13 @@ struct nfp_pf {

struct dentry *ddir;

unsigned int num_ports;
unsigned int num_netdevs;
unsigned int max_data_vnics;
unsigned int num_vnics;

struct list_head vnics;
struct list_head ports;
struct work_struct port_refresh_work;
struct mutex port_lock;
struct mutex lock;
};

extern struct pci_driver nfp_netvf_pci_driver;
Expand Down
44 changes: 24 additions & 20 deletions drivers/net/ethernet/netronome/nfp/nfp_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#define NFP_NET_NON_Q_VECTORS 2
#define NFP_NET_IRQ_LSC_IDX 0
#define NFP_NET_IRQ_EXN_IDX 1
#define NFP_NET_MIN_PORT_IRQS (NFP_NET_NON_Q_VECTORS + 1)
#define NFP_NET_MIN_VNIC_IRQS (NFP_NET_NON_Q_VECTORS + 1)

/* Queue/Ring definitions */
#define NFP_NET_MAX_TX_RINGS 64 /* Max. # of Tx rings per device */
Expand Down Expand Up @@ -116,6 +116,7 @@ struct nfp_cpp;
struct nfp_eth_table_port;
struct nfp_net;
struct nfp_net_r_vector;
struct nfp_port;

/* Convenience macro for wrapping descriptor index on ring size */
#define D_IDX(ring, idx) ((idx) & ((ring)->cnt - 1))
Expand Down Expand Up @@ -542,7 +543,6 @@ struct nfp_net_dp {
* @reconfig_sync_present: Some thread is performing synchronous reconfig
* @reconfig_timer: Timer for async reading of reconfig results
* @link_up: Is the link up?
* @link_changed: Has link state changes since last port refresh?
* @link_status_lock: Protects @link_* and ensures atomicity with BAR reading
* @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter
* @rx_coalesce_max_frames: RX interrupt moderation frame count parameter
Expand All @@ -555,10 +555,10 @@ struct nfp_net_dp {
* @rx_bar: Pointer to mapped FL/RX queues
* @debugfs_dir: Device directory in debugfs
* @ethtool_dump_flag: Ethtool dump flag
* @port_list: Entry on device port list
* @vnic_list: Entry on device vNIC list
* @pdev: Backpointer to PCI device
* @cpp: CPP device handle if available
* @eth_port: Translated ETH Table port entry
* @app: APP handle if available
* @port: Pointer to nfp_port structure if vNIC is a port
*/
struct nfp_net {
struct nfp_net_dp dp;
Expand Down Expand Up @@ -600,7 +600,6 @@ struct nfp_net {
u32 me_freq_mhz;

bool link_up;
bool link_changed;
spinlock_t link_status_lock;

spinlock_t reconfig_lock;
Expand All @@ -625,12 +624,12 @@ struct nfp_net {
struct dentry *debugfs_dir;
u32 ethtool_dump_flag;

struct list_head port_list;
struct list_head vnic_list;

struct pci_dev *pdev;
struct nfp_cpp *cpp;
struct nfp_app *app;

struct nfp_eth_table_port *eth_port;
struct nfp_port *port;
};

/* Functions to read/write from/to a BAR
Expand Down Expand Up @@ -802,16 +801,25 @@ static inline u32 nfp_qcp_wr_ptr_read(u8 __iomem *q)
/* Globals */
extern const char nfp_driver_version[];

extern const struct net_device_ops nfp_net_netdev_ops;

static inline bool nfp_netdev_is_nfp_net(struct net_device *netdev)
{
return netdev->netdev_ops == &nfp_net_netdev_ops;
}

/* Prototypes */
void nfp_net_get_fw_version(struct nfp_net_fw_version *fw_ver,
void __iomem *ctrl_bar);

struct nfp_net *
nfp_net_netdev_alloc(struct pci_dev *pdev,
unsigned int max_tx_rings, unsigned int max_rx_rings);
void nfp_net_netdev_free(struct nfp_net *nn);
int nfp_net_netdev_init(struct net_device *netdev);
void nfp_net_netdev_clean(struct net_device *netdev);
nfp_net_alloc(struct pci_dev *pdev,
unsigned int max_tx_rings, unsigned int max_rx_rings);
void nfp_net_free(struct nfp_net *nn);

int nfp_net_init(struct nfp_net *nn);
void nfp_net_clean(struct nfp_net *nn);

void nfp_net_set_ethtool_ops(struct net_device *netdev);
void nfp_net_info(struct nfp_net *nn);
int nfp_net_reconfig(struct nfp_net *nn, u32 update);
Expand All @@ -832,15 +840,11 @@ struct nfp_net_dp *nfp_net_clone_dp(struct nfp_net *nn);
int nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *new,
struct netlink_ext_ack *extack);

bool nfp_net_link_changed_read_clear(struct nfp_net *nn);
int nfp_net_refresh_eth_port(struct nfp_net *nn);
void nfp_net_refresh_port_table(struct nfp_net *nn);

#ifdef CONFIG_NFP_DEBUG
void nfp_net_debugfs_create(void);
void nfp_net_debugfs_destroy(void);
struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev);
void nfp_net_debugfs_port_add(struct nfp_net *nn, struct dentry *ddir, int id);
void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir, int id);
void nfp_net_debugfs_dir_clean(struct dentry **dir);
#else
static inline void nfp_net_debugfs_create(void)
Expand All @@ -857,7 +861,7 @@ static inline struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev)
}

static inline void
nfp_net_debugfs_port_add(struct nfp_net *nn, struct dentry *ddir, int id)
nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir, int id)
{
}

Expand Down
Loading

0 comments on commit 0172397

Please sign in to comment.