From d557ee6bdc6dc4df2ab8e00c2127120b4acbdfca Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:15 -0700 Subject: [PATCH 01/14] nfp: explicitly check if application FW is loaded We support application FW being either loaded automatically at boot from flash or (more commonly) by the driver from disk. If FW is not found on disk and nothing is preloaded users are faced with this unintuitive error: nfp 0000:04:00.0: nfp: Failed to find PF symbol _pf0_net_bar0 We can do better. Since we rely on symbol table being present - check early if it could be correctly read out of from the device and if not print a more informative message. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- drivers/net/ethernet/netronome/nfp/nfp_net_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index cfcbc3b9a9aa..3169400dd474 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -589,10 +589,7 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf) ctrl_bar_sz, &pf->data_vnic_bar); if (IS_ERR(mem)) { nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n"); - err = PTR_ERR(mem); - if (!pf->fw_loaded && err == -ENOENT) - err = -EPROBE_DEFER; - return err; + return PTR_ERR(mem); } pf->mac_stats_mem = nfp_net_pf_map_rtsym(pf, "net.macstats", @@ -786,6 +783,12 @@ int nfp_net_pci_probe(struct nfp_pf *pf) return -EINVAL; } + if (!pf->rtbl) { + nfp_err(pf->cpp, "No %s, giving up.\n", + pf->fw_loaded ? "symbol table" : "firmware found"); + return -EPROBE_DEFER; + } + mutex_lock(&pf->lock); pf->max_data_vnics = nfp_net_pf_get_num_ports(pf); if ((int)pf->max_data_vnics < 0) { From 064dc3196ebd2587ad9a4ca2d26629a20f819352 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:16 -0700 Subject: [PATCH 02/14] nfp: move area mapping helper into nfpcore nfp_net_map_area() is a helper for mapping areas of NFP memory defined in nfp_net_main.c. Move it to nfpcore to allow reuse and rename accordingly. Create an additional helper - nfp_cpp_area_alloc_acquire() the opposite of already existing nfp_cpp_area_release_free(). Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/nfp_net_main.c | 56 +------------------ .../ethernet/netronome/nfp/nfpcore/nfp_cpp.h | 7 +++ .../netronome/nfp/nfpcore/nfp_cppcore.c | 35 ++++++++++++ .../netronome/nfp/nfpcore/nfp_cpplib.c | 40 +++++++++++++ 4 files changed, 84 insertions(+), 54 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index 3169400dd474..16ee904db0cd 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -80,58 +80,6 @@ static int nfp_is_ready(struct nfp_pf *pf) return state == 15; } -/** - * nfp_net_map_area() - Help function to map an area - * @cpp: NFP CPP handler - * @name: Name for the area - * @target: CPP target - * @addr: CPP address - * @size: Size of the area - * @area: Area handle (returned). - * - * This function is primarily to simplify the code in the main probe - * function. To undo the effect of this functions call - * @nfp_cpp_area_release_free(*area); - * - * Return: Pointer to memory mapped area or ERR_PTR - */ -static u8 __iomem *nfp_net_map_area(struct nfp_cpp *cpp, - const char *name, int isl, int target, - unsigned long long addr, unsigned long size, - struct nfp_cpp_area **area) -{ - u8 __iomem *res; - u32 dest; - int err; - - dest = NFP_CPP_ISLAND_ID(target, NFP_CPP_ACTION_RW, 0, isl); - - *area = nfp_cpp_area_alloc_with_name(cpp, dest, name, addr, size); - if (!*area) { - err = -EIO; - goto err_area; - } - - err = nfp_cpp_area_acquire(*area); - if (err < 0) - goto err_acquire; - - res = nfp_cpp_area_iomem(*area); - if (!res) { - err = -EIO; - goto err_map; - } - - return res; - -err_map: - nfp_cpp_area_release(*area); -err_acquire: - nfp_cpp_area_free(*area); -err_area: - return (u8 __iomem *)ERR_PTR(err); -} - /** * nfp_net_get_mac_addr() - Get the MAC address. * @pf: NFP PF handle @@ -242,7 +190,7 @@ nfp_net_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt, return (u8 __iomem *)ERR_PTR(-EINVAL); } - mem = nfp_net_map_area(pf->cpp, name, sym->domain, sym->target, + mem = nfp_cpp_map_area(pf->cpp, name, sym->domain, sym->target, sym->addr, sym->size, area); if (IS_ERR(mem)) { nfp_err(pf->cpp, "Failed to map PF symbol %s: %ld\n", @@ -617,7 +565,7 @@ static int nfp_net_pci_map_mem(struct nfp_pf *pf) pf->vf_cfg_mem = NULL; } - mem = nfp_net_map_area(pf->cpp, "net.qc", 0, 0, + mem = nfp_cpp_map_area(pf->cpp, "net.qc", 0, 0, NFP_PCIE_QUEUE(0), NFP_QCP_QUEUE_AREA_SZ, &pf->qc_area); if (IS_ERR(mem)) { diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h index 25a967158ce9..235dd023d9b9 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h @@ -230,6 +230,9 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, u32 cpp_id, unsigned long long address, unsigned long size); +struct nfp_cpp_area * +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, const char *name, u32 cpp_id, + unsigned long long address, unsigned long size); void nfp_cpp_area_free(struct nfp_cpp_area *area); int nfp_cpp_area_acquire(struct nfp_cpp_area *area); int nfp_cpp_area_acquire_nonblocking(struct nfp_cpp_area *area); @@ -278,6 +281,10 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, u32 cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, u32 cpp_id, unsigned long long address, u64 value); +u8 __iomem * +nfp_cpp_map_area(struct nfp_cpp *cpp, const char *name, int domain, int target, + u64 addr, unsigned long size, struct nfp_cpp_area **area); + struct nfp_cpp_mutex; int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c index 9b69dcf87be9..7d5d7293efed 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c @@ -360,6 +360,41 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, u32 dest, return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } +/** + * nfp_cpp_area_alloc_acquire() - allocate a new CPP area and lock it down + * @cpp: CPP handle + * @name: Name of region + * @dest: CPP id + * @address: Start address on CPP target + * @size: Size of area + * + * Allocate and initialize a CPP area structure, and lock it down so + * that it can be accessed directly. + * + * NOTE: @address and @size must be 32-bit aligned values. + * + * NOTE: The area must also be 'released' when the structure is freed. + * + * Return: NFP CPP Area handle, or NULL + */ +struct nfp_cpp_area * +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, const char *name, u32 dest, + unsigned long long address, unsigned long size) +{ + struct nfp_cpp_area *area; + + area = nfp_cpp_area_alloc_with_name(cpp, dest, name, address, size); + if (!area) + return NULL; + + if (nfp_cpp_area_acquire(area)) { + nfp_cpp_area_free(area); + return NULL; + } + + return area; +} + /** * nfp_cpp_area_free() - free up the CPP area * @area: CPP area handle diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpplib.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpplib.c index 0ba0379b8f75..ab86bceb93f2 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpplib.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpplib.c @@ -279,3 +279,43 @@ exit_release: return err; } + +/** + * nfp_cpp_map_area() - Helper function to map an area + * @cpp: NFP CPP handler + * @name: Name for the area + * @domain: CPP domain + * @target: CPP target + * @addr: CPP address + * @size: Size of the area + * @area: Area handle (output) + * + * Map an area of IOMEM access. To undo the effect of this function call + * @nfp_cpp_area_release_free(*area). + * + * Return: Pointer to memory mapped area or ERR_PTR + */ +u8 __iomem * +nfp_cpp_map_area(struct nfp_cpp *cpp, const char *name, int domain, int target, + u64 addr, unsigned long size, struct nfp_cpp_area **area) +{ + u8 __iomem *res; + u32 dest; + + dest = NFP_CPP_ISLAND_ID(target, NFP_CPP_ACTION_RW, 0, domain); + + *area = nfp_cpp_area_alloc_acquire(cpp, name, dest, addr, size); + if (!*area) + goto err_eio; + + res = nfp_cpp_area_iomem(*area); + if (!res) + goto err_release_free; + + return res; + +err_release_free: + nfp_cpp_area_release_free(*area); +err_eio: + return (u8 __iomem *)ERR_PTR(-EIO); +} From f84730240735b15f725ce59d66a663de82650b46 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:17 -0700 Subject: [PATCH 03/14] nfp: add helper for mapping runtime symbols Move most of the helper for mapping RTsyms from nfp_net_main.c to nfpcore. Use the new helper directly for mapping MAC statistics, since they don't need to include the PCIe interface ID in the symbol name. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/nfp_net_main.c | 36 +++++-------------- .../ethernet/netronome/nfp/nfpcore/nfp_nffw.h | 4 +++ .../netronome/nfp/nfpcore/nfp_rtsym.c | 27 ++++++++++++++ 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index 16ee904db0cd..93d6ea183956 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -174,31 +174,12 @@ static u8 __iomem * nfp_net_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt, unsigned int min_size, struct nfp_cpp_area **area) { - const struct nfp_rtsym *sym; char pf_symbol[256]; - u8 __iomem *mem; snprintf(pf_symbol, sizeof(pf_symbol), sym_fmt, nfp_cppcore_pcie_unit(pf->cpp)); - sym = nfp_rtsym_lookup(pf->rtbl, pf_symbol); - if (!sym) - return (u8 __iomem *)ERR_PTR(-ENOENT); - - if (sym->size < min_size) { - nfp_err(pf->cpp, "PF symbol %s too small\n", pf_symbol); - return (u8 __iomem *)ERR_PTR(-EINVAL); - } - - mem = nfp_cpp_map_area(pf->cpp, name, sym->domain, sym->target, - sym->addr, sym->size, area); - if (IS_ERR(mem)) { - nfp_err(pf->cpp, "Failed to map PF symbol %s: %ld\n", - pf_symbol, PTR_ERR(mem)); - return mem; - } - - return mem; + return nfp_rtsym_map(pf->rtbl, pf_symbol, name, min_size, area); } static void nfp_net_pf_free_vnic(struct nfp_pf *pf, struct nfp_net *nn) @@ -528,23 +509,22 @@ static void nfp_net_pci_unmap_mem(struct nfp_pf *pf) static int nfp_net_pci_map_mem(struct nfp_pf *pf) { - u32 ctrl_bar_sz; u8 __iomem *mem; + u32 min_size; int err; - ctrl_bar_sz = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE; + min_size = pf->max_data_vnics * NFP_PF_CSR_SLICE_SIZE; mem = nfp_net_pf_map_rtsym(pf, "net.ctrl", "_pf%d_net_bar0", - ctrl_bar_sz, &pf->data_vnic_bar); + min_size, &pf->data_vnic_bar); if (IS_ERR(mem)) { nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n"); return PTR_ERR(mem); } - pf->mac_stats_mem = nfp_net_pf_map_rtsym(pf, "net.macstats", - "_mac_stats", - NFP_MAC_STATS_SIZE * - (pf->eth_tbl->max_index + 1), - &pf->mac_stats_bar); + min_size = NFP_MAC_STATS_SIZE * (pf->eth_tbl->max_index + 1); + pf->mac_stats_mem = nfp_rtsym_map(pf->rtbl, "_mac_stats", + "net.macstats", min_size, + &pf->mac_stats_bar); if (IS_ERR(pf->mac_stats_mem)) { if (PTR_ERR(pf->mac_stats_mem) != -ENOENT) { err = PTR_ERR(pf->mac_stats_mem); diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.h b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.h index d27d29782a12..c9724fb7ea4b 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nffw.h @@ -97,7 +97,11 @@ int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); const struct nfp_rtsym * nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name); + u64 nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +u8 __iomem * +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, const char *id, + unsigned int min_size, struct nfp_cpp_area **area); #endif /* NFP_NFFW_H */ diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_rtsym.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_rtsym.c index 203f9cbae0fb..ecda474ac7c3 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_rtsym.c @@ -289,3 +289,30 @@ exit: return ~0ULL; return val; } + +u8 __iomem * +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, const char *id, + unsigned int min_size, struct nfp_cpp_area **area) +{ + const struct nfp_rtsym *sym; + u8 __iomem *mem; + + sym = nfp_rtsym_lookup(rtbl, name); + if (!sym) + return (u8 __iomem *)ERR_PTR(-ENOENT); + + if (sym->size < min_size) { + nfp_err(rtbl->cpp, "Symbol %s too small\n", name); + return (u8 __iomem *)ERR_PTR(-EINVAL); + } + + mem = nfp_cpp_map_area(rtbl->cpp, id, sym->domain, sym->target, + sym->addr, sym->size, area); + if (IS_ERR(mem)) { + nfp_err(rtbl->cpp, "Failed to map symbol %s: %ld\n", + name, PTR_ERR(mem)); + return mem; + } + + return mem; +} From 8a119cef9a84c396c7de49da2fb4b8af09e96d2b Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:18 -0700 Subject: [PATCH 04/14] nfp: remove unused nfp_cpp_area_check_range() Remove unused nfp_cpp_area_check_range() function. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../ethernet/netronome/nfp/nfpcore/nfp_cpp.h | 2 -- .../netronome/nfp/nfpcore/nfp_cppcore.c | 21 ------------------- 2 files changed, 23 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h index 235dd023d9b9..5798adc57cbc 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cpp.h @@ -242,8 +242,6 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, void *buffer, size_t length); int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, const void *buffer, size_t length); -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c index 7d5d7293efed..04dd5758ecf5 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c @@ -570,27 +570,6 @@ int nfp_cpp_area_write(struct nfp_cpp_area *area, return area->cpp->op->area_write(area, kernel_vaddr, offset, length); } -/** - * nfp_cpp_area_check_range() - check if address range fits in CPP area - * @area: CPP area handle - * @offset: offset into CPP target - * @length: size of address range in bytes - * - * Check if address range fits within CPP area. Return 0 if area - * fits or -EFAULT on error. - * - * Return: 0, or -ERRNO - */ -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long length) -{ - if (offset < area->offset || - offset + length > area->offset + area->size) - return -EFAULT; - - return 0; -} - /** * nfp_cpp_area_name() - return name of a CPP area * @cpp_area: CPP area handle From 9ce6bbbb0503e58e8629ae0185e916b271237bc3 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:19 -0700 Subject: [PATCH 05/14] nfp: add nfp_app cleanup callback and make flower use it Add a cleanup callback for undoing what app init callback did. Make flower allocate its private structure on init and free it from the new callback. While at it remember to set the app pointer to NULL on the error path to avoid any races while probe path unwinds. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/flower/main.c | 24 +++++++++---------- drivers/net/ethernet/netronome/nfp/nfp_app.h | 10 +++++++- .../net/ethernet/netronome/nfp/nfp_net_main.c | 6 ++++- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.c b/drivers/net/ethernet/netronome/nfp/flower/main.c index 8e5ca6b4bb33..54d42a7f0d75 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/main.c +++ b/drivers/net/ethernet/netronome/nfp/flower/main.c @@ -296,26 +296,16 @@ static int nfp_flower_start(struct nfp_app *app) NFP_REPR_TYPE_PF, 1); } -static void nfp_flower_vnic_clean(struct nfp_app *app, struct nfp_net *nn) -{ - kfree(app->priv); - app->priv = NULL; -} - static int nfp_flower_vnic_init(struct nfp_app *app, struct nfp_net *nn, unsigned int id) { - struct nfp_flower_priv *priv; + struct nfp_flower_priv *priv = app->priv; if (id > 0) { nfp_warn(app->cpp, "FlowerNIC doesn't support more than one data vNIC\n"); goto err_invalid_port; } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - app->priv = priv; priv->nn = nn; eth_hw_addr_random(nn->dp.netdev); @@ -347,9 +337,19 @@ static int nfp_flower_init(struct nfp_app *app) return -EINVAL; } + app->priv = kzalloc(sizeof(struct nfp_flower_priv), GFP_KERNEL); + if (!app->priv) + return -ENOMEM; + return 0; } +static void nfp_flower_clean(struct nfp_app *app) +{ + kfree(app->priv); + app->priv = NULL; +} + const struct nfp_app_type app_flower = { .id = NFP_APP_FLOWER_NIC, .name = "flower", @@ -358,9 +358,9 @@ const struct nfp_app_type app_flower = { .extra_cap = nfp_flower_extra_cap, .init = nfp_flower_init, + .clean = nfp_flower_clean, .vnic_init = nfp_flower_vnic_init, - .vnic_clean = nfp_flower_vnic_clean, .start = nfp_flower_start, .stop = nfp_flower_stop, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.h b/drivers/net/ethernet/netronome/nfp/nfp_app.h index ae2d02753d1a..2fb503a817d2 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_app.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_app.h @@ -66,7 +66,8 @@ extern const struct nfp_app_type app_flower; * @ctrl_has_meta: control messages have prepend of type:5/port:CTRL * * Callbacks - * @init: perform basic app checks + * @init: perform basic app checks and init + * @clean: clean app state * @extra_cap: extra capabilities string * @vnic_init: init vNICs (assign port types, etc.) * @vnic_clean: clean up app's vNIC state @@ -88,6 +89,7 @@ struct nfp_app_type { bool ctrl_has_meta; int (*init)(struct nfp_app *app); + void (*clean)(struct nfp_app *app); const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn); @@ -144,6 +146,12 @@ static inline int nfp_app_init(struct nfp_app *app) return app->type->init(app); } +static inline void nfp_app_clean(struct nfp_app *app) +{ + if (app->type->clean) + app->type->clean(app); +} + static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn, unsigned int id) { diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index 93d6ea183956..49c4910fbcc6 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -414,7 +414,7 @@ nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) if (IS_ERR(ctrl_bar)) { nfp_err(pf->cpp, "Failed to find data vNIC memory symbol\n"); err = PTR_ERR(ctrl_bar); - goto err_free; + goto err_app_clean; } pf->ctrl_vnic = nfp_net_pf_alloc_vnic(pf, false, ctrl_bar, qc_bar, @@ -428,8 +428,11 @@ nfp_net_pf_app_init(struct nfp_pf *pf, u8 __iomem *qc_bar, unsigned int stride) err_unmap: nfp_cpp_area_release_free(pf->ctrl_vnic_bar); +err_app_clean: + nfp_app_clean(pf->app); err_free: nfp_app_free(pf->app); + pf->app = NULL; return err; } @@ -439,6 +442,7 @@ static void nfp_net_pf_app_clean(struct nfp_pf *pf) nfp_net_pf_free_vnic(pf, pf->ctrl_vnic); nfp_cpp_area_release_free(pf->ctrl_vnic_bar); } + nfp_app_clean(pf->app); nfp_app_free(pf->app); pf->app = NULL; } From 38edbf6f5da4f87741e73b74dc323706827e83e0 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:20 -0700 Subject: [PATCH 06/14] nfp: spawn nfp_ports for PF and VF ports nfp_port is an abstraction which is supposed to allow us sharing code between different netdev types (vNIC vs repr). Spawn ports for PFs and VFs to enable this sharing. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/flower/main.c | 19 ++++++++++++++++-- drivers/net/ethernet/netronome/nfp/nfp_port.h | 20 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.c b/drivers/net/ethernet/netronome/nfp/flower/main.c index 54d42a7f0d75..757bc3d78ea4 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/main.c +++ b/drivers/net/ethernet/netronome/nfp/flower/main.c @@ -162,14 +162,19 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, u8 nfp_pcie = nfp_cppcore_pcie_unit(app->pf->cpp); struct nfp_flower_priv *priv = app->priv; struct nfp_reprs *reprs, *old_reprs; + enum nfp_port_type port_type; const u8 queue = 0; int i, err; + port_type = repr_type == NFP_REPR_TYPE_PF ? NFP_PORT_PF_PORT : + NFP_PORT_VF_PORT; + reprs = nfp_reprs_alloc(cnt); if (!reprs) return -ENOMEM; for (i = 0; i < cnt; i++) { + struct nfp_port *port; u32 port_id; reprs->reprs[i] = nfp_repr_alloc(app); @@ -178,15 +183,25 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, goto err_reprs_clean; } + port = nfp_port_alloc(app, port_type, reprs->reprs[i]); + if (repr_type == NFP_REPR_TYPE_PF) { + port->pf_id = i; + } else { + port->pf_id = 0; /* For now we only support 1 PF */ + port->vf_id = i; + } + eth_hw_addr_random(reprs->reprs[i]); port_id = nfp_flower_cmsg_pcie_port(nfp_pcie, vnic_type, i, queue); err = nfp_repr_init(app, reprs->reprs[i], &nfp_flower_repr_netdev_ops, - port_id, NULL, priv->nn->dp.netdev); - if (err) + port_id, port, priv->nn->dp.netdev); + if (err) { + nfp_port_free(port); goto err_reprs_clean; + } nfp_info(app->cpp, "%s%d Representor(%s) created\n", repr_type == NFP_REPR_TYPE_PF ? "PF" : "VF", i, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.h b/drivers/net/ethernet/netronome/nfp/nfp_port.h index f472bea4ec2b..57d852a4ca59 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.h @@ -47,10 +47,14 @@ struct nfp_port; * state when port disappears because of FW fault or config * change * @NFP_PORT_PHYS_PORT: external NIC port + * @NFP_PORT_PF_PORT: logical port of PCI PF + * @NFP_PORT_VF_PORT: logical port of PCI VF */ enum nfp_port_type { NFP_PORT_INVALID, NFP_PORT_PHYS_PORT, + NFP_PORT_PF_PORT, + NFP_PORT_VF_PORT, }; /** @@ -72,6 +76,8 @@ enum nfp_port_flags { * @dl_port: devlink port structure * @eth_id: for %NFP_PORT_PHYS_PORT port ID in NFP enumeration scheme * @eth_port: for %NFP_PORT_PHYS_PORT translated ETH Table port entry + * @pf_id: for %NFP_PORT_PF_PORT, %NFP_PORT_VF_PORT ID of the PCI PF (0-3) + * @vf_id: for %NFP_PORT_VF_PORT ID of the PCI VF within @pf_id * @port_list: entry on pf's list of ports */ struct nfp_port { @@ -84,8 +90,18 @@ struct nfp_port { struct devlink_port dl_port; - unsigned int eth_id; - struct nfp_eth_table_port *eth_port; + union { + /* NFP_PORT_PHYS_PORT */ + struct { + unsigned int eth_id; + struct nfp_eth_table_port *eth_port; + }; + /* NFP_PORT_PF_PORT, NFP_PORT_VF_PORT */ + struct { + unsigned int pf_id; + unsigned int vf_id; + }; + }; struct list_head port_list; }; From 3238b250b7624a20756667032648263eb3dc1521 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:21 -0700 Subject: [PATCH 07/14] nfp: make the representor get stats app-independent Thanks to the fact that all representors will now have an nfp_port, we can depend on information there to provide a app-independent .ndo_get_stats64(). Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/flower/main.c | 16 +---------- .../net/ethernet/netronome/nfp/nfp_net_repr.c | 28 +++++++++++++------ .../net/ethernet/netronome/nfp/nfp_net_repr.h | 4 +-- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.c b/drivers/net/ethernet/netronome/nfp/flower/main.c index 757bc3d78ea4..2e66d51ec104 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/main.c +++ b/drivers/net/ethernet/netronome/nfp/flower/main.c @@ -104,20 +104,6 @@ nfp_flower_repr_get(struct nfp_app *app, u32 port_id) return reprs->reprs[port]; } -static void -nfp_flower_repr_netdev_get_stats64(struct net_device *netdev, - struct rtnl_link_stats64 *stats) -{ - struct nfp_repr *repr = netdev_priv(netdev); - enum nfp_repr_type type; - u32 port_id; - u8 port = 0; - - port_id = repr->dst->u.port_info.port_id; - type = nfp_flower_repr_get_type_and_port(repr->app, port_id, &port); - nfp_repr_get_stats64(repr->app, type, port, stats); -} - static int nfp_flower_repr_netdev_open(struct net_device *netdev) { int err; @@ -144,7 +130,7 @@ static const struct net_device_ops nfp_flower_repr_netdev_ops = { .ndo_open = nfp_flower_repr_netdev_open, .ndo_stop = nfp_flower_repr_netdev_stop, .ndo_start_xmit = nfp_repr_xmit, - .ndo_get_stats64 = nfp_flower_repr_netdev_get_stats64, + .ndo_get_stats64 = nfp_repr_get_stats64, .ndo_has_offload_stats = nfp_repr_has_offload_stats, .ndo_get_offload_stats = nfp_repr_get_offload_stats, }; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c index 44adcc5df11e..6f1548c6840c 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c @@ -37,6 +37,7 @@ #include #include "nfpcore/nfp_cpp.h" +#include "nfpcore/nfp_nsp.h" #include "nfp_app.h" #include "nfp_main.h" #include "nfp_net_ctrl.h" @@ -136,18 +137,27 @@ nfp_repr_pf_get_stats64(const struct nfp_app *app, u8 pf, } void -nfp_repr_get_stats64(const struct nfp_app *app, enum nfp_repr_type type, - u8 port, struct rtnl_link_stats64 *stats) +nfp_repr_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) { - switch (type) { - case NFP_REPR_TYPE_PHYS_PORT: - nfp_repr_phy_port_get_stats64(app, port, stats); + struct nfp_repr *repr = netdev_priv(netdev); + struct nfp_eth_table_port *eth_port; + struct nfp_app *app = repr->app; + + if (WARN_ON(!repr->port)) + return; + + switch (repr->port->type) { + case NFP_PORT_PHYS_PORT: + eth_port = __nfp_port_get_eth_port(repr->port); + if (!eth_port) + break; + nfp_repr_phy_port_get_stats64(app, eth_port->index, stats); break; - case NFP_REPR_TYPE_PF: - nfp_repr_pf_get_stats64(app, port, stats); + case NFP_PORT_PF_PORT: + nfp_repr_pf_get_stats64(app, repr->port->pf_id, stats); break; - case NFP_REPR_TYPE_VF: - nfp_repr_vf_get_stats64(app, port, stats); + case NFP_PORT_VF_PORT: + nfp_repr_vf_get_stats64(app, repr->port->vf_id, stats); default: break; } diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h index c5ed6611f708..e970661ecd42 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h @@ -99,8 +99,8 @@ enum nfp_repr_type { void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len); void -nfp_repr_get_stats64(const struct nfp_app *app, enum nfp_repr_type type, - u8 port, struct rtnl_link_stats64 *stats); +nfp_repr_get_stats64(struct net_device *netdev, + struct rtnl_link_stats64 *stats); bool nfp_repr_has_offload_stats(const struct net_device *dev, int attr_id); int nfp_repr_get_offload_stats(int attr_id, const struct net_device *dev, void *stats); From 5d7c64a70fa15aef903469b05ca664f7cd17d769 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:22 -0700 Subject: [PATCH 08/14] nfp: move representors' struct net_device_ops to shared code Apps shouldn't declare their own struct net_device_ops for representors, this makes sharing code harder. Add necessary nfp_app callbacks and move the definition of representors' struct net_device_ops to common code. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/flower/cmsg.c | 5 +-- .../net/ethernet/netronome/nfp/flower/cmsg.h | 2 +- .../net/ethernet/netronome/nfp/flower/main.c | 32 ++++++--------- drivers/net/ethernet/netronome/nfp/nfp_app.h | 20 ++++++++++ .../net/ethernet/netronome/nfp/nfp_net_repr.c | 40 +++++++++++++++---- .../net/ethernet/netronome/nfp/nfp_net_repr.h | 8 ---- 6 files changed, 68 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/flower/cmsg.c b/drivers/net/ethernet/netronome/nfp/flower/cmsg.c index 7761be436726..916a6196d2ba 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/cmsg.c +++ b/drivers/net/ethernet/netronome/nfp/flower/cmsg.c @@ -79,9 +79,8 @@ nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size, return skb; } -int nfp_flower_cmsg_portmod(struct net_device *netdev, bool carrier_ok) +int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok) { - struct nfp_repr *repr = netdev_priv(netdev); struct nfp_flower_cmsg_portmod *msg; struct sk_buff *skb; @@ -94,7 +93,7 @@ int nfp_flower_cmsg_portmod(struct net_device *netdev, bool carrier_ok) msg->portnum = cpu_to_be32(repr->dst->u.port_info.port_id); msg->reserved = 0; msg->info = carrier_ok; - msg->mtu = cpu_to_be16(netdev->mtu); + msg->mtu = cpu_to_be16(repr->netdev->mtu); nfp_ctrl_tx(repr->app->ctrl, skb); diff --git a/drivers/net/ethernet/netronome/nfp/flower/cmsg.h b/drivers/net/ethernet/netronome/nfp/flower/cmsg.h index 2eeddada7f4d..c10ae7631941 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/cmsg.h +++ b/drivers/net/ethernet/netronome/nfp/flower/cmsg.h @@ -110,7 +110,7 @@ nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type, NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT); } -int nfp_flower_cmsg_portmod(struct net_device *netdev, bool carrier_ok); +int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok); void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb); #endif diff --git a/drivers/net/ethernet/netronome/nfp/flower/main.c b/drivers/net/ethernet/netronome/nfp/flower/main.c index 2e66d51ec104..ab68a8f58862 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/main.c +++ b/drivers/net/ethernet/netronome/nfp/flower/main.c @@ -104,37 +104,30 @@ nfp_flower_repr_get(struct nfp_app *app, u32 port_id) return reprs->reprs[port]; } -static int nfp_flower_repr_netdev_open(struct net_device *netdev) +static int +nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr) { int err; - err = nfp_flower_cmsg_portmod(netdev, true); + err = nfp_flower_cmsg_portmod(repr, true); if (err) return err; - netif_carrier_on(netdev); - netif_tx_wake_all_queues(netdev); + netif_carrier_on(repr->netdev); + netif_tx_wake_all_queues(repr->netdev); return 0; } -static int nfp_flower_repr_netdev_stop(struct net_device *netdev) +static int +nfp_flower_repr_netdev_stop(struct nfp_app *app, struct nfp_repr *repr) { - netif_carrier_off(netdev); - netif_tx_disable(netdev); + netif_carrier_off(repr->netdev); + netif_tx_disable(repr->netdev); - return nfp_flower_cmsg_portmod(netdev, false); + return nfp_flower_cmsg_portmod(repr, false); } -static const struct net_device_ops nfp_flower_repr_netdev_ops = { - .ndo_open = nfp_flower_repr_netdev_open, - .ndo_stop = nfp_flower_repr_netdev_stop, - .ndo_start_xmit = nfp_repr_xmit, - .ndo_get_stats64 = nfp_repr_get_stats64, - .ndo_has_offload_stats = nfp_repr_has_offload_stats, - .ndo_get_offload_stats = nfp_repr_get_offload_stats, -}; - static void nfp_flower_sriov_disable(struct nfp_app *app) { nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_VF); @@ -182,7 +175,6 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, port_id = nfp_flower_cmsg_pcie_port(nfp_pcie, vnic_type, i, queue); err = nfp_repr_init(app, reprs->reprs[i], - &nfp_flower_repr_netdev_ops, port_id, port, priv->nn->dp.netdev); if (err) { nfp_port_free(port); @@ -261,7 +253,6 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) cmsg_port_id = nfp_flower_cmsg_phys_port(phys_port); err = nfp_repr_init(app, reprs->reprs[phys_port], - &nfp_flower_repr_netdev_ops, cmsg_port_id, port, priv->nn->dp.netdev); if (err) { nfp_port_free(port); @@ -363,6 +354,9 @@ const struct nfp_app_type app_flower = { .vnic_init = nfp_flower_vnic_init, + .repr_open = nfp_flower_repr_netdev_open, + .repr_stop = nfp_flower_repr_netdev_stop, + .start = nfp_flower_start, .stop = nfp_flower_stop, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.h b/drivers/net/ethernet/netronome/nfp/nfp_app.h index 2fb503a817d2..5d714e10d9a9 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_app.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_app.h @@ -47,6 +47,7 @@ struct sk_buff; struct nfp_app; struct nfp_cpp; struct nfp_pf; +struct nfp_repr; struct nfp_net; enum nfp_app_id { @@ -71,6 +72,8 @@ extern const struct nfp_app_type app_flower; * @extra_cap: extra capabilities string * @vnic_init: init vNICs (assign port types, etc.) * @vnic_clean: clean up app's vNIC state + * @repr_open: representor netdev open callback + * @repr_stop: representor netdev stop callback * @start: start application logic * @stop: stop application logic * @ctrl_msg_rx: control message handler @@ -97,6 +100,9 @@ struct nfp_app_type { unsigned int id); void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn); + int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr); + int (*repr_stop)(struct nfp_app *app, struct nfp_repr *repr); + int (*start)(struct nfp_app *app); void (*stop)(struct nfp_app *app); @@ -164,6 +170,20 @@ static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn) app->type->vnic_clean(app, nn); } +static inline int nfp_app_repr_open(struct nfp_app *app, struct nfp_repr *repr) +{ + if (!app->type->repr_open) + return -EINVAL; + return app->type->repr_open(app, repr); +} + +static inline int nfp_app_repr_stop(struct nfp_app *app, struct nfp_repr *repr) +{ + if (!app->type->repr_stop) + return -EINVAL; + return app->type->repr_stop(app, repr); +} + static inline int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl) { app->ctrl = ctrl; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c index 6f1548c6840c..44416f679fdb 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c @@ -136,7 +136,7 @@ nfp_repr_pf_get_stats64(const struct nfp_app *app, u8 pf, stats->rx_dropped = readq(mem + NFP_NET_CFG_STATS_TX_DISCARDS); } -void +static void nfp_repr_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) { struct nfp_repr *repr = netdev_priv(netdev); @@ -163,7 +163,7 @@ nfp_repr_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) } } -bool +static bool nfp_repr_has_offload_stats(const struct net_device *dev, int attr_id) { switch (attr_id) { @@ -206,8 +206,9 @@ nfp_repr_get_host_stats64(const struct net_device *netdev, return 0; } -int nfp_repr_get_offload_stats(int attr_id, const struct net_device *dev, - void *stats) +static int +nfp_repr_get_offload_stats(int attr_id, const struct net_device *dev, + void *stats) { switch (attr_id) { case IFLA_OFFLOAD_XSTATS_CPU_HIT: @@ -217,7 +218,7 @@ int nfp_repr_get_offload_stats(int attr_id, const struct net_device *dev, return -EINVAL; } -netdev_tx_t nfp_repr_xmit(struct sk_buff *skb, struct net_device *netdev) +static netdev_tx_t nfp_repr_xmit(struct sk_buff *skb, struct net_device *netdev) { struct nfp_repr *repr = netdev_priv(netdev); unsigned int len = skb->len; @@ -234,6 +235,29 @@ netdev_tx_t nfp_repr_xmit(struct sk_buff *skb, struct net_device *netdev) return ret; } +static int nfp_repr_stop(struct net_device *netdev) +{ + struct nfp_repr *repr = netdev_priv(netdev); + + return nfp_app_repr_stop(repr->app, repr); +} + +static int nfp_repr_open(struct net_device *netdev) +{ + struct nfp_repr *repr = netdev_priv(netdev); + + return nfp_app_repr_open(repr->app, repr); +} + +static const struct net_device_ops nfp_repr_netdev_ops = { + .ndo_open = nfp_repr_open, + .ndo_stop = nfp_repr_stop, + .ndo_start_xmit = nfp_repr_xmit, + .ndo_get_stats64 = nfp_repr_get_stats64, + .ndo_has_offload_stats = nfp_repr_has_offload_stats, + .ndo_get_offload_stats = nfp_repr_get_offload_stats, +}; + static void nfp_repr_clean(struct nfp_repr *repr) { unregister_netdev(repr->netdev); @@ -258,8 +282,8 @@ static void nfp_repr_set_lockdep_class(struct net_device *dev) } int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, - const struct net_device_ops *netdev_ops, u32 cmsg_port_id, - struct nfp_port *port, struct net_device *pf_netdev) + u32 cmsg_port_id, struct nfp_port *port, + struct net_device *pf_netdev) { struct nfp_repr *repr = netdev_priv(netdev); int err; @@ -273,7 +297,7 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, repr->dst->u.port_info.port_id = cmsg_port_id; repr->dst->u.port_info.lower_dev = pf_netdev; - netdev->netdev_ops = netdev_ops; + netdev->netdev_ops = &nfp_repr_netdev_ops; err = register_netdev(netdev); if (err) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h index e970661ecd42..8f126362d5ed 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h @@ -98,15 +98,7 @@ enum nfp_repr_type { #define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1) void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len); -void -nfp_repr_get_stats64(struct net_device *netdev, - struct rtnl_link_stats64 *stats); -bool nfp_repr_has_offload_stats(const struct net_device *dev, int attr_id); -int nfp_repr_get_offload_stats(int attr_id, const struct net_device *dev, - void *stats); -netdev_tx_t nfp_repr_xmit(struct sk_buff *skb, struct net_device *netdev); int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, - const struct net_device_ops *netdev_ops, u32 cmsg_port_id, struct nfp_port *port, struct net_device *pf_netdev); struct net_device *nfp_repr_alloc(struct nfp_app *app); From 39ae7eb69db3a3daa3aa2f6c66e37dba1975ef00 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:23 -0700 Subject: [PATCH 09/14] nfp: allow converting representor's netdev into nfp_port Based on struct net_device_ops figure out if netdev is a nfp_repr. Use this knowledge to convert netdev directly to nfp_port. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/nfp_net_repr.c | 2 +- .../net/ethernet/netronome/nfp/nfp_net_repr.h | 7 +++++++ drivers/net/ethernet/netronome/nfp/nfp_port.c | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c index 44416f679fdb..7bfdef2af1a9 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c @@ -249,7 +249,7 @@ static int nfp_repr_open(struct net_device *netdev) return nfp_app_repr_open(repr->app, repr); } -static const struct net_device_ops nfp_repr_netdev_ops = { +const struct net_device_ops nfp_repr_netdev_ops = { .ndo_open = nfp_repr_open, .ndo_stop = nfp_repr_stop, .ndo_start_xmit = nfp_repr_xmit, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h index 8f126362d5ed..6a6727816010 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.h @@ -97,6 +97,13 @@ enum nfp_repr_type { }; #define NFP_REPR_TYPE_MAX (__NFP_REPR_TYPE_MAX - 1) +extern const struct net_device_ops nfp_repr_netdev_ops; + +static inline bool nfp_netdev_is_nfp_repr(struct net_device *netdev) +{ + return netdev->netdev_ops == &nfp_repr_netdev_ops; +} + void nfp_repr_inc_rx_stats(struct net_device *netdev, unsigned int len); int nfp_repr_init(struct nfp_app *app, struct net_device *netdev, u32 cmsg_port_id, struct nfp_port *port, diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c index 19bceeb82225..0be6c7e0b1c1 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c @@ -42,13 +42,21 @@ struct nfp_port *nfp_port_from_netdev(struct net_device *netdev) { - struct nfp_net *nn; + if (nfp_netdev_is_nfp_net(netdev)) { + struct nfp_net *nn = netdev_priv(netdev); - if (WARN_ON(!nfp_netdev_is_nfp_net(netdev))) - return NULL; - nn = netdev_priv(netdev); + return nn->port; + } - return nn->port; + if (nfp_netdev_is_nfp_repr(netdev)) { + struct nfp_repr *repr = netdev_priv(netdev); + + return repr->port; + } + + WARN(1, "Unknown netdev type for nfp_port\n"); + + return NULL; } struct nfp_port * From 168c478e107e790456cd6ebb308529756c21de3f Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:24 -0700 Subject: [PATCH 10/14] nfp: wire get_phys_port_name on representors Make nfp_port_get_phys_port_name() support new port types and wire it up to representors' struct net_device_ops. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- .../net/ethernet/netronome/nfp/nfp_net_repr.c | 1 + drivers/net/ethernet/netronome/nfp/nfp_port.c | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c index 7bfdef2af1a9..046b89eb4cf2 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c @@ -256,6 +256,7 @@ const struct net_device_ops nfp_repr_netdev_ops = { .ndo_get_stats64 = nfp_repr_get_stats64, .ndo_has_offload_stats = nfp_repr_has_offload_stats, .ndo_get_offload_stats = nfp_repr_get_offload_stats, + .ndo_get_phys_port_name = nfp_port_get_phys_port_name, }; static void nfp_repr_clean(struct nfp_repr *repr) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c index 0be6c7e0b1c1..0b44952945d8 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_port.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c @@ -106,15 +106,31 @@ nfp_port_get_phys_port_name(struct net_device *netdev, char *name, size_t len) int n; port = nfp_port_from_netdev(netdev); - eth_port = __nfp_port_get_eth_port(port); - if (!eth_port) + if (!port) return -EOPNOTSUPP; - if (!eth_port->is_split) - n = snprintf(name, len, "p%d", eth_port->label_port); - else - n = snprintf(name, len, "p%ds%d", eth_port->label_port, - eth_port->label_subport); + switch (port->type) { + case NFP_PORT_PHYS_PORT: + eth_port = __nfp_port_get_eth_port(port); + if (!eth_port) + return -EOPNOTSUPP; + + if (!eth_port->is_split) + n = snprintf(name, len, "p%d", eth_port->label_port); + else + n = snprintf(name, len, "p%ds%d", eth_port->label_port, + eth_port->label_subport); + break; + case NFP_PORT_PF_PORT: + n = snprintf(name, len, "pf%d", port->pf_id); + break; + case NFP_PORT_VF_PORT: + n = snprintf(name, len, "pf%dvf%d", port->pf_id, port->vf_id); + break; + default: + return -EOPNOTSUPP; + } + if (n >= len) return -EINVAL; From 0dc78621918693face1700d1379c2b9f740282f5 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:25 -0700 Subject: [PATCH 11/14] nfp: handle SR-IOV already enabled when driver is probing We assumed that when we probe number of enabled VFs will be at 0. This doesn't have to be the case for example if previous driver left SR-IOV enabled due to some VFs being assigned. Read the number of VFs enabled. Fail probe if it's above current FWs limit. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- drivers/net/ethernet/netronome/nfp/nfp_main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.c b/drivers/net/ethernet/netronome/nfp/nfp_main.c index 748e54cc885e..d47adb4c86d6 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.c @@ -414,6 +414,14 @@ static int nfp_pci_probe(struct pci_dev *pdev, if (err) goto err_fw_unload; + pf->num_vfs = pci_num_vf(pdev); + if (pf->num_vfs > pf->limit_vfs) { + dev_err(&pdev->dev, + "Error: %d VFs already enabled, but loaded FW can only support %d\n", + pf->num_vfs, pf->limit_vfs); + goto err_fw_unload; + } + err = nfp_net_pci_probe(pf); if (err) goto err_sriov_unlimit; From e3f28473b8ed348f7c052fa1bf79edfde5efba48 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:26 -0700 Subject: [PATCH 12/14] nfp: reorder SR-IOV config and nfp_app SR-IOV callbacks We previously assumed that app callback can be guaranteed to be executed before SR-IOV is actually enabled. Given that we can't guarantee that SR-IOV will be disabled during probe or that we will be able to disable it on remove, we should reorder the callbacks. We should also call the app's sriov_enable if SR-IOV was enabled during probe. Application FW must be able to disable VFs internally and not depend on them being removed at PCIe level. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- drivers/net/ethernet/netronome/nfp/nfp_main.c | 40 ++++++++----------- .../net/ethernet/netronome/nfp/nfp_net_main.c | 10 +++++ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.c b/drivers/net/ethernet/netronome/nfp/nfp_main.c index d47adb4c86d6..a0f3df8572d6 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.c @@ -107,17 +107,18 @@ static int nfp_pcie_sriov_enable(struct pci_dev *pdev, int num_vfs) goto err_unlock; } - err = nfp_app_sriov_enable(pf->app, num_vfs); + err = pci_enable_sriov(pdev, num_vfs); if (err) { - dev_warn(&pdev->dev, "App specific PCI sriov configuration failed: %d\n", - err); + dev_warn(&pdev->dev, "Failed to enable PCI SR-IOV: %d\n", err); goto err_unlock; } - err = pci_enable_sriov(pdev, num_vfs); + err = nfp_app_sriov_enable(pf->app, num_vfs); if (err) { - dev_warn(&pdev->dev, "Failed to enable PCI sriov: %d\n", err); - goto err_app_sriov_disable; + dev_warn(&pdev->dev, + "App specific PCI SR-IOV configuration failed: %d\n", + err); + goto err_sriov_disable; } pf->num_vfs = num_vfs; @@ -127,8 +128,8 @@ static int nfp_pcie_sriov_enable(struct pci_dev *pdev, int num_vfs) mutex_unlock(&pf->lock); return num_vfs; -err_app_sriov_disable: - nfp_app_sriov_disable(pf->app); +err_sriov_disable: + pci_disable_sriov(pdev); err_unlock: mutex_unlock(&pf->lock); return err; @@ -136,17 +137,20 @@ err_unlock: return 0; } -static int __nfp_pcie_sriov_disable(struct pci_dev *pdev) +static int nfp_pcie_sriov_disable(struct pci_dev *pdev) { #ifdef CONFIG_PCI_IOV struct nfp_pf *pf = pci_get_drvdata(pdev); + mutex_lock(&pf->lock); + /* If the VFs are assigned we cannot shut down SR-IOV without * causing issues, so just leave the hardware available but * disabled */ if (pci_vfs_assigned(pdev)) { dev_warn(&pdev->dev, "Disabling while VFs assigned - VFs will not be deallocated\n"); + mutex_unlock(&pf->lock); return -EPERM; } @@ -156,22 +160,12 @@ static int __nfp_pcie_sriov_disable(struct pci_dev *pdev) pci_disable_sriov(pdev); dev_dbg(&pdev->dev, "Removed VFs.\n"); + + mutex_unlock(&pf->lock); #endif return 0; } -static int nfp_pcie_sriov_disable(struct pci_dev *pdev) -{ - struct nfp_pf *pf = pci_get_drvdata(pdev); - int err; - - mutex_lock(&pf->lock); - err = __nfp_pcie_sriov_disable(pdev); - mutex_unlock(&pf->lock); - - return err; -} - static int nfp_pcie_sriov_configure(struct pci_dev *pdev, int num_vfs) { if (num_vfs == 0) @@ -471,11 +465,11 @@ static void nfp_pci_remove(struct pci_dev *pdev) devlink = priv_to_devlink(pf); + nfp_net_pci_remove(pf); + nfp_pcie_sriov_disable(pdev); pci_sriov_set_totalvfs(pf->pdev, 0); - nfp_net_pci_remove(pf); - devlink_unregister(devlink); kfree(pf->rtbl); diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index 49c4910fbcc6..4d22e1cc013e 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -488,8 +488,16 @@ static int nfp_net_pf_app_start(struct nfp_pf *pf) if (err) goto err_ctrl_stop; + if (pf->num_vfs) { + err = nfp_app_sriov_enable(pf->app, pf->num_vfs); + if (err) + goto err_app_stop; + } + return 0; +err_app_stop: + nfp_app_stop(pf->app); err_ctrl_stop: nfp_net_pf_app_stop_ctrl(pf); return err; @@ -497,6 +505,8 @@ err_ctrl_stop: static void nfp_net_pf_app_stop(struct nfp_pf *pf) { + if (pf->num_vfs) + nfp_app_sriov_disable(pf->app); nfp_app_stop(pf->app); nfp_net_pf_app_stop_ctrl(pf); } From 6d48ceb27af1420882f092495fc796cfcbf92a14 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:27 -0700 Subject: [PATCH 13/14] nfp: allocate a private workqueue for driver work Since we grab pf->lock around pci_enable_sriov() we can no longer safely queue work which may also grab that lock onto system workqueue. pci_enable_sriov() will flush system workqueue as part to wait for VF probing. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- drivers/net/ethernet/netronome/nfp/nfp_main.c | 9 +++++++++ drivers/net/ethernet/netronome/nfp/nfp_main.h | 4 ++++ drivers/net/ethernet/netronome/nfp/nfp_net_main.c | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.c b/drivers/net/ethernet/netronome/nfp/nfp_main.c index a0f3df8572d6..d67969d3e484 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.c @@ -376,6 +376,12 @@ static int nfp_pci_probe(struct pci_dev *pdev, pci_set_drvdata(pdev, pf); pf->pdev = pdev; + pf->wq = alloc_workqueue("nfp-%s", 0, 2, pci_name(pdev)); + if (!pf->wq) { + err = -ENOMEM; + goto err_pci_priv_unset; + } + pf->cpp = nfp_cpp_from_nfp6000_pcie(pdev); if (IS_ERR_OR_NULL(pf->cpp)) { err = PTR_ERR(pf->cpp); @@ -445,6 +451,8 @@ err_hwinfo_free: kfree(pf->hwinfo); nfp_cpp_free(pf->cpp); err_disable_msix: + destroy_workqueue(pf->wq); +err_pci_priv_unset: pci_set_drvdata(pdev, NULL); mutex_destroy(&pf->lock); devlink_free(devlink); @@ -477,6 +485,7 @@ static void nfp_pci_remove(struct pci_dev *pdev) if (pf->fw_loaded) nfp_fw_unload(pf); + destroy_workqueue(pf->wq); pci_set_drvdata(pdev, NULL); kfree(pf->hwinfo); nfp_cpp_free(pf->cpp); diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.h b/drivers/net/ethernet/netronome/nfp/nfp_main.h index edc14dc78674..a08cfba7e68e 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.h @@ -89,6 +89,7 @@ struct nfp_rtsym_table; * @num_vnics: Number of vNICs spawned * @vnics: Linked list of vNIC structures (struct nfp_net) * @ports: Linked list of port structures (struct nfp_port) + * @wq: Workqueue for running works which need to grab @lock * @port_refresh_work: Work entry for taking netdevs out * @lock: Protects all fields which may change after probe */ @@ -131,7 +132,10 @@ struct nfp_pf { struct list_head vnics; struct list_head ports; + + struct workqueue_struct *wq; struct work_struct port_refresh_work; + struct mutex lock; }; diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c index 4d22e1cc013e..c85a2f18c4df 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_main.c @@ -682,7 +682,7 @@ void nfp_net_refresh_port_table(struct nfp_port *port) set_bit(NFP_PORT_CHANGED, &port->flags); - schedule_work(&pf->port_refresh_work); + queue_work(pf->wq, &pf->port_refresh_work); } int nfp_net_refresh_eth_port(struct nfp_port *port) From 57ae676ee63ec810c64aea67fc451ae0900a05f9 Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Tue, 27 Jun 2017 00:50:28 -0700 Subject: [PATCH 14/14] nfp: flower: add Kconfig for flower app Give users an option not to build the flower-offload related code. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman Signed-off-by: David S. Miller --- drivers/net/ethernet/netronome/Kconfig | 10 ++++++++++ drivers/net/ethernet/netronome/nfp/Makefile | 8 ++++++-- drivers/net/ethernet/netronome/nfp/nfp_app.c | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/netronome/Kconfig b/drivers/net/ethernet/netronome/Kconfig index 0d5a7b9203a4..0e331e2f685a 100644 --- a/drivers/net/ethernet/netronome/Kconfig +++ b/drivers/net/ethernet/netronome/Kconfig @@ -25,6 +25,16 @@ config NFP cards working as a advanced Ethernet NIC. It works with both SR-IOV physical and virtual functions. +config NFP_APP_FLOWER + bool "NFP4000/NFP6000 TC Flower offload support" + depends on NFP + depends on NET_SWITCHDEV + ---help--- + Enable driver support for TC Flower offload on NFP4000 and NFP6000. + Say Y, if you are planning to make use of TC Flower offload + either directly, with Open vSwitch, or any other way. Note that + TC Flower offload requires specific FW to work. + config NFP_DEBUG bool "Debug support for Netronome(R) NFP4000/NFP6000 NIC drivers" depends on NFP diff --git a/drivers/net/ethernet/netronome/nfp/Makefile b/drivers/net/ethernet/netronome/nfp/Makefile index 10b556b2c59d..43bdbc228969 100644 --- a/drivers/net/ethernet/netronome/nfp/Makefile +++ b/drivers/net/ethernet/netronome/nfp/Makefile @@ -27,10 +27,14 @@ nfp-objs := \ nfp_port.o \ bpf/main.o \ bpf/offload.o \ - flower/cmsg.o \ - flower/main.o \ nic/main.o +ifeq ($(CONFIG_NFP_APP_FLOWER),y) +nfp-objs += \ + flower/cmsg.o \ + flower/main.o +endif + ifeq ($(CONFIG_BPF_SYSCALL),y) nfp-objs += \ bpf/verifier.o \ diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.c b/drivers/net/ethernet/netronome/nfp/nfp_app.c index 5620de05c996..c704c022574f 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_app.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_app.c @@ -43,7 +43,9 @@ static const struct nfp_app_type *apps[] = { &app_nic, &app_bpf, +#ifdef CONFIG_NFP_APP_FLOWER &app_flower, +#endif }; const char *nfp_app_mip_name(struct nfp_app *app)