* [PATCH 00/27] refact the nfpcore module @ 2023-08-24 11:09 Chaoyong He 2023-08-24 11:09 ` [PATCH 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He ` (27 more replies) 0 siblings, 28 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He This patch series aims to: - Make the coding style satisfy with DPDK. - Sync the logic with kernel driver. - Make the sub-module more modular. - Extend the nfp configure BAR from 8 to 24. Chaoyong He (27): net/nfp: explicitly compare to null and 0 net/nfp: unify the indent coding style net/nfp: unify the type of integer variable net/nfp: remove the unneeded logic net/nfp: standard the local variable coding style net/nfp: adjust the log statement net/nfp: standard the comment style net/nfp: using the DPDK memory management API net/nfp: standard the blank character net/nfp: unify the guide line of header file net/nfp: rename some parameter and variable net/nfp: refact the hwinfo module net/nfp: refact the nffw module net/nfp: refact the mip module net/nfp: refact the rtsym module net/nfp: refact the resource module net/nfp: refact the target module net/nfp: add a new header file net/nfp: refact the nsp module net/nfp: refact the mutex module net/nfp: rename data field to sync with kernel driver net/nfp: add the dev module net/nfp: add header file for PCIe module net/nfp: refact the cppcore module net/nfp: refact the PCIe module net/nfp: refact the cppcore and PCIe module net/nfp: extend the usage of nfp BAR from 8 to 24 drivers/net/nfp/flower/nfp_flower.c | 14 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 3 +- drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 +- drivers/net/nfp/nfp_common.h | 52 +- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 108 +- drivers/net/nfp/nfp_ethdev_vf.c | 17 +- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 - drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 - drivers/net/nfp/nfpcore/nfp6000_pcie.c | 1031 ++++++++++++++++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 20 + drivers/net/nfp/nfpcore/nfp_cpp.h | 776 +++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 824 ------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 1088 +++++++++++------ drivers/net/nfp/nfpcore/nfp_dev.c | 81 ++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 199 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 74 +- drivers/net/nfp/nfpcore/nfp_mip.c | 103 +- drivers/net/nfp/nfpcore/nfp_mip.h | 7 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 383 +++--- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 + drivers/net/nfp/nfpcore/nfp_nffw.c | 207 ++-- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 580 ++++++--- drivers/net/nfp/nfpcore/nfp_nsp.h | 336 ++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 27 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 534 ++++---- drivers/net/nfp/nfpcore/nfp_platform.h | 42 + drivers/net/nfp/nfpcore/nfp_resource.c | 216 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 36 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 452 +++++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 67 +- drivers/net/nfp/nfpcore/nfp_target.c | 9 +- drivers/net/nfp/nfpcore/nfp_target.h | 597 +-------- 39 files changed, 4080 insertions(+), 4043 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.c create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h delete mode 100644 drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 01/27] net/nfp: explicitly compare to null and 0 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 02/27] net/nfp: unify the indent coding style Chaoyong He ` (26 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He To compliance with the coding standard, make the pointer variable explicitly comparing to 'NULL' and the integer variable explicitly comparing to '0'. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 ++++++------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++++++------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 20 ++++++++++---------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_resource.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 4 ++-- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 658c618ee6..2ee60eefc3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -224,10 +224,10 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, newcfg |= offset >> bitsize; - if (bar_base) + if (bar_base != NULL) *bar_base = offset; - if (bar_config) + if (bar_config != NULL) *bar_config = newcfg; return 0; @@ -266,7 +266,7 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); - if (err) + if (err != 0) return err; bar->base = newbase; @@ -515,7 +515,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) { + if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } @@ -583,7 +583,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) + if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; is_64 = width == TARGET_WIDTH_64; @@ -764,7 +764,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) if (rte_eal_process_type() == RTE_PROC_PRIMARY && cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); - if (ret) + if (ret != 0) goto error; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6daee313ce..2c6ec3e126 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -235,7 +235,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, if (area == NULL) return NULL; - if (nfp_cpp_area_acquire(area)) { + if (nfp_cpp_area_acquire(area) != 0) { nfp_cpp_area_free(area); return NULL; } @@ -252,7 +252,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, void nfp_cpp_area_free(struct nfp_cpp_area *area) { - if (area->cpp->op->area_cleanup) + if (area->cpp->op->area_cleanup != NULL) area->cpp->op->area_cleanup(area); free(area); } @@ -280,7 +280,7 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) int nfp_cpp_area_acquire(struct nfp_cpp_area *area) { - if (area->cpp->op->area_acquire) { + if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); if (err < 0) @@ -299,7 +299,7 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) void nfp_cpp_area_release(struct nfp_cpp_area *area) { - if (area->cpp->op->area_release) + if (area->cpp->op->area_release != NULL) area->cpp->op->area_release(area); } @@ -319,7 +319,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) { void *iomem = NULL; - if (area->cpp->op->area_iomem) + if (area->cpp->op->area_iomem != NULL) iomem = area->cpp->op->area_iomem(area); return iomem; @@ -621,10 +621,10 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) void nfp_cpp_free(struct nfp_cpp *cpp) { - if (cpp->op && cpp->op->free) + if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len) + if (cpp->serial_len != 0) free(cpp->serial); free(cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 9054bb0315..a9d166c4dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -37,7 +37,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { const char *key, *val, *end = hwinfo->data + size; - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { @@ -141,7 +141,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); - if (db) + if (db != NULL) return db; nanosleep(&wait, NULL); @@ -164,7 +164,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return NULL; err = nfp_hwinfo_db_validate(db, hwdb_size); - if (err) { + if (err != 0) { free(db); return NULL; } @@ -188,7 +188,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 6b392ad5eb..f9723dd136 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -75,7 +75,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) return -ENODEV; err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr); - if (err) + if (err != 0) goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); @@ -105,7 +105,7 @@ nfp_mip_open(struct nfp_cpp *cpp) return NULL; err = nfp_mip_read_resource(cpp, mip); - if (err) { + if (err != 0) { free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index f967a29351..0410a00856 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -38,7 +38,7 @@ static int _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) { /* Address must be 64-bit aligned */ - if (address & 7) + if ((address & 7) != 0) return -EINVAL; if (NFP_CPP_MODEL_IS_6000(model)) { diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 07d63900dc..433780a5e7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -190,7 +190,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; for (i = 0; i < cnt; i++) - if (nffw_fwinfo_loaded_get(&fwinfo[i])) + if (nffw_fwinfo_loaded_get(&fwinfo[i]) != 0) return &fwinfo[i]; return NULL; @@ -217,7 +217,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); *off = nffw_fwinfo_mip_offset_get(fwinfo); - if (nffw_fwinfo_mip_mu_da_get(fwinfo)) { + if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 1f6b7bd85c..6474abf0c2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -95,7 +95,7 @@ nfp_nsp_check(struct nfp_nsp *state) return -EINVAL; } - if (reg & NSP_STATUS_BUSY) { + if ((reg & NSP_STATUS_BUSY) != 0) { PMD_DRV_LOG(ERR, "Service processor busy!"); return -EBUSY; } @@ -128,7 +128,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) state->res = res; err = nfp_nsp_check(state); - if (err) { + if (err != 0) { nfp_nsp_close(state); return NULL; } @@ -219,7 +219,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err) + if (err != 0) return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || @@ -245,7 +245,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -254,7 +254,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_STATUS_BUSY to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -266,7 +266,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); @@ -319,13 +319,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); - if (in_buf && in_size) { + if (in_buf != NULL && in_size > 0) { err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf && out_size && out_size > in_size) { + if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, out_size - in_size); @@ -337,7 +337,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (ret < 0) return ret; - if (out_buf && out_size) { + if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); if (err < 0) return err; @@ -369,7 +369,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } - if (err) + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 01b4652280..825a84a8cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -212,7 +212,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, dst->fec_modes_supported |= fec << NFP_FEC_BASER_BIT; fec = FIELD_GET(NSP_ETH_PORT_FEC_SUPP_RS, port); dst->fec_modes_supported |= fec << NFP_FEC_REED_SOLOMON_BIT; - if (dst->fec_modes_supported) + if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); @@ -285,7 +285,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) cnt++; } @@ -294,7 +294,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * those that give a port count, verify it against the value calculated * above. */ - if (ret && ret != cnt) { + if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; @@ -309,7 +309,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); @@ -621,7 +621,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) return -EIO; err = __nfp_eth_set_fec(nsp, mode); - if (err) { + if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 351bc623ed..838cd6e0ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -115,15 +115,15 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, { int err; - if (nfp_cpp_mutex_lock(dev_mutex)) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) return -EINVAL; err = nfp_cpp_resource_find(cpp, res); - if (err) + if (err != 0) goto err_unlock_dev; err = nfp_cpp_mutex_trylock(res->mutex); - if (err) + if (err != 0) goto err_res_mutex_free; nfp_cpp_mutex_unlock(dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 343b0d0bcf..4c45aec5c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -362,10 +362,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) if (err) err = -EIO; exit: - if (error) + if (error != NULL) *error = err; - if (err) + if (err != 0) return ~0ULL; return val; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 02/27] net/nfp: unify the indent coding style 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He 2023-08-24 11:09 ` [PATCH 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 03/27] net/nfp: unify the type of integer variable Chaoyong He ` (25 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Each parameter of function should occupy one line, and indent two TAB character. All the statement which span multi line should indent two TAB character. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 80 +++++----- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 152 ++++++++++-------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 173 +++++++++++++-------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 23 +-- drivers/net/nfp/nfpcore/nfp_mip.c | 21 ++- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 108 +++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 19 +-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 69 ++++---- drivers/net/nfp/nfpcore/nfp_resource.c | 29 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 38 +++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 15 +- 16 files changed, 447 insertions(+), 322 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 8f87c09327..54bef3cb6b 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -56,7 +56,8 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp, + struct rte_pci_device *dev); /* * Free the bus. @@ -69,9 +70,9 @@ struct nfp_cpp_operations { * NOTE: This is _not_ serialized */ int (*area_init)(struct nfp_cpp_area *area, - uint32_t dest, - unsigned long long address, - unsigned long size); + uint32_t dest, + unsigned long long address, + unsigned long size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -101,17 +102,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_read)(struct nfp_cpp_area *area, - void *kernel_vaddr, - unsigned long offset, - unsigned int length); + void *kernel_vaddr, + unsigned long offset, + unsigned int length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, - const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + const void *kernel_vaddr, + unsigned long offset, + unsigned int length); }; /* @@ -239,7 +240,7 @@ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); * @param len Length of the serial byte array */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len); + size_t serial_len); /* * Set the private data of the nfp_cpp instance @@ -279,7 +280,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + int driver_lock_needed); /* * Free a NFP CPP handle @@ -397,8 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, - unsigned long size); + unsigned long long address, unsigned long size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,10 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, - const char *name, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, unsigned long long address, + unsigned long size); /* * Free an allocated NFP CPP area handle @@ -448,9 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, unsigned long long address, unsigned long size); /* * Release the resources, then free the NFP CPP area handle @@ -459,8 +455,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, - struct nfp_cpp_area **area); + uint64_t addr, unsigned long size, struct nfp_cpp_area **area); /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -484,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * */ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *buffer, size_t length); + void *buffer, size_t length); /* * Write to a NFP CPP area handle from a buffer. The area must be acquired with @@ -498,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *buffer, size_t length); + const void *buffer, size_t length); /* * nfp_cpp_area_iomem() - get IOMEM region for CPP area @@ -522,7 +517,7 @@ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); * @return 0 on success, negative value on failure. */ int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); + unsigned long long offset, unsigned long size); /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle @@ -552,7 +547,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + unsigned long long address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -566,8 +561,8 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); + unsigned long long address, const void *kernel_vaddr, + size_t length); @@ -582,7 +577,7 @@ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); + uint32_t value, size_t length); /* * Read a single 32-bit value from a NFP CPP area handle @@ -599,7 +594,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value); + uint32_t *value); /* * Write a single 32-bit value to a NFP CPP area handle @@ -616,7 +611,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value); + uint32_t value); /* * Read a single 64-bit value from a NFP CPP area handle @@ -633,7 +628,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value); + uint64_t *value); /* * Write a single 64-bit value to a NFP CPP area handle @@ -650,7 +645,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value); + uint64_t value); /* * Write a single 32-bit value on the XPB bus @@ -685,7 +680,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); * @return 0 on success, or -1 on failure. */ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); + uint32_t value); /* * Modify bits of a 32-bit value from the XPB bus @@ -699,7 +694,7 @@ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, negative value on failure. */ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); + uint32_t value, int timeout_us); /* * Read a 32-bit word from a NFP CPP ID @@ -712,7 +707,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + unsigned long long address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -726,7 +721,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + unsigned long long address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -739,7 +734,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + unsigned long long address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -752,7 +747,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + unsigned long long address, uint64_t value); /* * Initialize a mutex location @@ -773,7 +768,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -793,8 +788,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, - uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 2ee60eefc3..884cc84eaa 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -130,9 +130,15 @@ nfp_bar_maptype(struct nfp_bar *bar) #define TARGET_WIDTH_64 8 static int -nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, - uint64_t *bar_base, int tgt, int act, int tok, - uint64_t offset, size_t size, int width) +nfp_compute_bar(const struct nfp_bar *bar, + uint32_t *bar_config, + uint64_t *bar_base, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint32_t bitsize; uint32_t newcfg; @@ -143,19 +149,16 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, switch (width) { case 8: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); break; case 4: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); break; case 0: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); break; default: return -EINVAL; @@ -165,60 +168,58 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), act, + (unsigned long long)mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + bar->index, tgt, act, tok, (unsigned long long)offset, + (unsigned long long)(offset + mask)); bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); /* Bulk mapping */ - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), + tgt, tok, (unsigned long long)mask, + (unsigned long long)(offset & mask), + (unsigned long long)(offset + size - 1) & mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); + bar->index, tgt, tok, (unsigned long long)offset, + (unsigned long long)(offset + ~mask)); bitsize = 40 - 21; } if (bar->bitsize < bitsize) { PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + tgt, tok, act); return -EINVAL; } @@ -234,8 +235,9 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, } static int -nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - uint32_t newcfg) +nfp_bar_write(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + uint32_t newcfg) { int base, slot; @@ -246,7 +248,7 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, return (-ENOMEM); bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); *(uint32_t *)(bar->csr) = newcfg; @@ -257,15 +259,21 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, } static int -nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, - int act, int tok, uint64_t offset, size_t size, int width) +nfp_reconfigure_bar(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint64_t newbase; uint32_t newcfg; int err; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + size, width); if (err != 0) return err; @@ -390,8 +398,10 @@ struct nfp6000_area_priv { }; static int -nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, unsigned long size) +nfp6000_area_init(struct nfp_cpp_area *area, + uint32_t dest, + unsigned long long address, + unsigned long size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -400,8 +410,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, uint32_t token = NFP_CPP_ID_TOKEN_of(dest); int pp, ret = 0; - pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), - address); + pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) return pp; @@ -409,7 +418,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->width.write = PULL_WIDTH(pp); if (priv->width.read > 0 && - priv->width.write > 0 && priv->width.read != priv->width.write) + priv->width.write > 0 && + priv->width.read != priv->width.write) return -EINVAL; if (priv->width.read > 0) @@ -428,8 +438,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->size = size; ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); + priv->token, priv->offset, priv->size, + priv->width.bar); return ret; } @@ -441,14 +451,13 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { + NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { priv->bar_offset = priv->offset & - (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, - priv->target); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, priv->token); + (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, + priv->target); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, + priv->token); } else { priv->bar_offset = priv->offset & priv->bar->mask; } @@ -490,8 +499,10 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) } static int -nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_read(struct nfp_cpp_area *area, + void *kernel_vaddr, + unsigned long offset, + unsigned int length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -524,17 +535,17 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { + priv->action == NFP_CPP_ACTION_RW) { is_64 = false; } if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -558,8 +569,10 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, } static int -nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_write(struct nfp_cpp_area *area, + const void *kernel_vaddr, + unsigned long offset, + unsigned int length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -590,16 +603,16 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) + priv->action == NFP_CPP_ACTION_RW) is_64 = false; if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -655,7 +668,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) } static int -nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_model(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint32_t model; @@ -671,7 +685,8 @@ nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_interface(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t interface; @@ -686,7 +701,8 @@ nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_serial(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t tmp; uint8_t serial[6]; @@ -733,7 +749,8 @@ nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) +nfp6000_set_barsz(struct rte_pci_device *dev, + struct nfp_pcie_user *desc) { unsigned long tmp; int i = 0; @@ -748,7 +765,8 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) } static int -nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp, + struct rte_pci_device *dev) { int ret = 0; struct nfp_pcie_user *desc; @@ -762,7 +780,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 2c6ec3e126..25f7700b08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -27,7 +27,8 @@ NFP_PL_DEVICE_ID_MASK) void -nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) +nfp_cpp_priv_set(struct nfp_cpp *cpp, + void *priv) { cpp->priv = priv; } @@ -39,7 +40,8 @@ nfp_cpp_priv(struct nfp_cpp *cpp) } void -nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) +nfp_cpp_model_set(struct nfp_cpp *cpp, + uint32_t model) { cpp->model = model; } @@ -62,21 +64,24 @@ nfp_cpp_model(struct nfp_cpp *cpp) } void -nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) +nfp_cpp_interface_set(struct nfp_cpp *cpp, + uint32_t interface) { cpp->interface = interface; } int -nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) +nfp_cpp_serial(struct nfp_cpp *cpp, + const uint8_t **serial) { *serial = cpp->serial; return cpp->serial_len; } int -nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len) +nfp_cpp_serial_set(struct nfp_cpp *cpp, + const uint8_t *serial, + size_t serial_len) { if (cpp->serial_len) free(cpp->serial); @@ -161,9 +166,11 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) * NOTE: @address and @size must be 32-bit aligned values. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, - const char *name, unsigned long long address, - unsigned long size) +nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, + uint32_t dest, + const char *name, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -183,7 +190,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, name = ""; area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + strlen(name) + 1); if (area == NULL) return NULL; @@ -204,8 +211,10 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, } struct nfp_cpp_area * -nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc(struct nfp_cpp *cpp, + uint32_t dest, + unsigned long long address, + unsigned long size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -226,8 +235,10 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, * NOTE: The area must also be 'released' when the structure is freed. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; @@ -340,8 +351,10 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *kernel_vaddr, size_t length) +nfp_cpp_area_read(struct nfp_cpp_area *area, + unsigned long offset, + void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -364,8 +377,10 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *kernel_vaddr, size_t length) +nfp_cpp_area_write(struct nfp_cpp_area *area, + unsigned long offset, + const void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -392,8 +407,9 @@ nfp_cpp_area_mapped(struct nfp_cpp_area *area) * or negative value on error. */ int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, - unsigned long length) +nfp_cpp_area_check_range(struct nfp_cpp_area *area, + unsigned long long offset, + unsigned long length) { if (((offset + length) > area->size)) return -EFAULT; @@ -406,7 +422,8 @@ nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, * based upon NFP model. */ static uint32_t -nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) +nfp_xpb_to_cpp(struct nfp_cpp *cpp, + uint32_t *xpb_addr) { uint32_t xpb; int island; @@ -433,7 +450,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) else /* And only non-ARM interfaces use island id = 1 */ if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) + NFP_CPP_INTERFACE_TYPE_ARM) *xpb_addr |= (1 << 24); } else { (*xpb_addr) |= (1 << 30); @@ -443,8 +460,9 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) } int -nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value) +nfp_cpp_area_readl(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t *value) { int sz; uint32_t tmp = 0; @@ -456,8 +474,9 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value) +nfp_cpp_area_writel(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value) { int sz; @@ -467,8 +486,9 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value) +nfp_cpp_area_readq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t *value) { int sz; uint64_t tmp = 0; @@ -480,8 +500,9 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value) +nfp_cpp_area_writeq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t value) { int sz; @@ -492,8 +513,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t *value) +nfp_cpp_readl(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t *value) { int sz; uint32_t tmp; @@ -505,8 +528,10 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t value) +nfp_cpp_writel(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t value) { int sz; @@ -517,8 +542,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t *value) +nfp_cpp_readq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t *value) { int sz; uint64_t tmp; @@ -530,8 +557,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t value) +nfp_cpp_writeq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t value) { int sz; @@ -542,7 +571,9 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) +nfp_xpb_writel(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t value) { uint32_t cpp_dest; @@ -552,7 +583,9 @@ nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) } int -nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) +nfp_xpb_readl(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t *value) { uint32_t cpp_dest; @@ -562,7 +595,8 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *dev, + int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -596,7 +630,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + (tgt * 4); err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { free(cpp); return NULL; @@ -631,7 +665,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) } struct nfp_cpp * -nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_from_device_name(struct rte_pci_device *dev, + int driver_lock_needed) { return nfp_cpp_alloc(dev, driver_lock_needed); } @@ -647,7 +682,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) * @return 0 on success, or -1 on failure. */ int -nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, +nfp_xpb_writelm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, uint32_t value) { int err; @@ -674,8 +711,11 @@ nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, or negative value on failure. */ int -nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us) +nfp_xpb_waitlm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, + uint32_t value, + int timeout_us) { uint32_t tmp; int err; @@ -716,8 +756,11 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @length: number of bytes to read */ int -nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, void *kernel_vaddr, size_t length) +nfp_cpp_read(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -743,9 +786,11 @@ nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, * @length: number of bytes to write */ int -nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, const void *kernel_vaddr, - size_t length) +nfp_cpp_write(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + const void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -768,8 +813,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, * @length: length of area to fill */ int -nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length) +nfp_cpp_area_fill(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value, + size_t length) { int err; size_t i; @@ -795,9 +842,8 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = - nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); + err = nfp_cpp_area_write(area, offset + i, &value64, + sizeof(value64)); if (err < 0) return err; if (err != sizeof(value64)) @@ -805,8 +851,7 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } if ((i + sizeof(value)) <= length) { - err = - nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); + err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); if (err < 0) return err; if (err != sizeof(value)) @@ -822,13 +867,14 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) +__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, + uint32_t *model) { uint32_t reg; int err; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, - ®); + ®); if (err < 0) return err; @@ -853,8 +899,11 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) * Return: Pointer to memory mapped area or NULL */ uint8_t * -nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, struct nfp_cpp_area **area) +nfp_cpp_map_area(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + unsigned long size, + struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index a9d166c4dc..ea4c7d6a9e 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -33,12 +33,13 @@ nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) } static int -nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) +nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, + uint32_t size) { const char *key, *val, *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { PMD_DRV_LOG(ERR, "Bad HWINFO - overflowing value"); @@ -54,7 +55,8 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) } static int -nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) +nfp_hwinfo_db_validate(struct nfp_hwinfo *db, + uint32_t len) { uint32_t size, new_crc, *crc; @@ -69,7 +71,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", - new_crc, *crc); + new_crc, *crc); return -EINVAL; } @@ -77,7 +79,8 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) } static struct nfp_hwinfo * -nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) +nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, + size_t *cpp_size) { struct nfp_hwinfo *header; void *res; @@ -115,7 +118,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) if (header->version != NFP_HWINFO_VERSION_2) { PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", - header->version); + header->version); goto exit_free; } @@ -129,7 +132,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) } static struct nfp_hwinfo * -nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) +nfp_hwinfo_fetch(struct nfp_cpp *cpp, + size_t *hwdb_size) { struct timespec wait; struct nfp_hwinfo *db; @@ -179,7 +183,8 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) * Return: Value of the HWInfo name, or NULL */ const char * -nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) +nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, + const char *lookup) { const char *key, *val, *end; @@ -189,7 +194,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (strcmp(key, lookup) == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f9723dd136..0071d3fc37 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -37,8 +37,10 @@ struct nfp_mip { /* Read memory and check if it could be a valid MIP */ static int -nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - struct nfp_mip *mip) +nfp_mip_try_read(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + struct nfp_mip *mip) { int ret; @@ -49,12 +51,12 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, } if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", - rte_le_to_cpu_32(mip->signature)); + rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", - rte_le_to_cpu_32(mip->mip_version)); + rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -63,7 +65,8 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, /* Try to locate MIP using the resource table */ static int -nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) +nfp_mip_read_resource(struct nfp_cpp *cpp, + struct nfp_mip *mip) { struct nfp_nffw_info *nffw_info; uint32_t cpp_id; @@ -134,7 +137,9 @@ nfp_mip_name(const struct nfp_mip *mip) * @size: Location for size of MIP symbol table */ void -nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_symtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->symtab_addr); *size = rte_le_to_cpu_32(mip->symtab_size); @@ -147,7 +152,9 @@ nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) * @size: Location for size of MIP symbol name table */ void -nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_strtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->strtab_addr); *size = rte_le_to_cpu_32(mip->strtab_size); diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index d0919b58fe..980abc2517 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,5 +17,5 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *off); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 0410a00856..047e755416 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,9 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) +_nfp_cpp_mutex_validate(uint32_t model, + int *target, + unsigned long long address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -72,8 +74,10 @@ _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) * @return 0 on success, or negative value on failure. */ int -nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, - uint32_t key) +nfp_cpp_mutex_init(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ @@ -87,9 +91,8 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, if (err < 0) return err; - err = - nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address + 0, + MUTEX_LOCKED(nfp_cpp_interface(cpp))); if (err < 0) return err; @@ -114,8 +117,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * -nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key) +nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); struct nfp_cpp_mutex *mutex; @@ -265,8 +270,8 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return err; if (time(NULL) >= warn_at) { PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->usage, mutex->depth, mutex->target, + mutex->address, mutex->key); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 433780a5e7..8bdc69766e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -138,8 +138,8 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) goto err_release; err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), - nfp_resource_address(state->res), - fwinf, sizeof(*fwinf)); + nfp_resource_address(state->res), + fwinf, sizeof(*fwinf)); if (err < (int)sizeof(*fwinf)) goto err_release; @@ -205,8 +205,9 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) * Return: 0, or -ERRNO */ int -nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) +nfp_nffw_info_mip_first(struct nfp_nffw_info *state, + uint32_t *cpp_id, + uint64_t *off) { struct nffw_fwinfo *fwinfo; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 6474abf0c2..4f476f6f2b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -22,7 +22,8 @@ nfp_nsp_config_modified(struct nfp_nsp *state) } void -nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified) +nfp_nsp_config_set_modified(struct nfp_nsp *state, + int modified) { state->modified = modified; } @@ -40,7 +41,9 @@ nfp_nsp_config_idx(struct nfp_nsp *state) } void -nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx) +nfp_nsp_config_set_state(struct nfp_nsp *state, + void *entries, + unsigned int idx) { state->entries = entries; state->idx = idx; @@ -91,7 +94,7 @@ nfp_nsp_check(struct nfp_nsp *state) if (state->ver.major != NSP_MAJOR || state->ver.minor < NSP_MINOR) { PMD_DRV_LOG(ERR, "Unsupported ABI %hu.%hu", state->ver.major, - state->ver.minor); + state->ver.minor); return -EINVAL; } @@ -160,8 +163,12 @@ nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state) } static int -nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, - uint64_t addr, uint64_t mask, uint64_t val) +nfp_nsp_wait_reg(struct nfp_cpp *cpp, + uint64_t *reg, + uint32_t nsp_cpp, + uint64_t addr, + uint64_t mask, + uint64_t val) { struct timespec wait; int count; @@ -204,8 +211,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, * -ETIMEDOUT if the NSP took longer than 30 seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, - uint32_t buff_cpp, uint64_t buff_addr) +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code, + uint32_t option, + uint32_t buff_cpp, + uint64_t buff_addr) { uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; struct nfp_cpp *cpp = state->cpp; @@ -223,40 +233,40 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { + !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); + buff_cpp, buff_addr); return -EINVAL; } err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | - FIELD_PREP(NSP_COMMAND_START, 1)); + FIELD_PREP(NSP_COMMAND_OPTION, option) | + FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, - NSP_COMMAND_START, 0); + NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } /* Wait for NSP_STATUS_BUSY to go to 0 */ - err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, - 0); + err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, + NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } @@ -268,7 +278,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); + -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); return -err; } @@ -279,9 +289,12 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, #define SZ_1M 0x00100000 static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, - const void *in_buf, unsigned int in_size, void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf(struct nfp_nsp *nsp, + uint16_t code, uint32_t option, + const void *in_buf, + unsigned int in_size, + void *out_buf, + unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; unsigned int max_size; @@ -291,28 +304,26 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); + code, nsp->ver.major, nsp->ver.minor); return -EOPNOTSUPP; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER_CONFIG, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); if (err < 0) return err; max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); + code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, + ®); if (err < 0) return err; @@ -328,7 +339,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + out_size - in_size); if (err < 0) return err; } @@ -388,38 +399,47 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) } int -nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_load_fw(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_eth_table(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) +nfp_nsp_write_eth_table(struct nfp_nsp *state, + const void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_identify(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, void *buf, - unsigned int size) +nfp_nsp_read_sensors(struct nfp_nsp *state, + unsigned int sensor_mask, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + 0, buf, size); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 9905b2d3d3..1e2deaabb4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -114,9 +114,10 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); + void *buf, unsigned int size); -static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) +static inline int +nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } @@ -229,22 +230,22 @@ struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); + int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + unsigned int size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + unsigned int idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) +static inline int +nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return !!eth_port->fec_modes_supported; } @@ -297,6 +298,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + long *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 21b338461e..28dba27124 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -73,7 +73,9 @@ struct nfp_sensors { }; int -nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val) +nfp_hwmon_read_sensor(struct nfp_cpp *cpp, + enum nfp_nsp_sensor_id id, + long *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 825a84a8cd..3eeefc74af 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -168,8 +168,10 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) } static void -nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, struct nfp_eth_table_port *dst) +nfp_eth_port_translate(struct nfp_nsp *nsp, + const union eth_table_entry *src, + unsigned int index, + struct nfp_eth_table_port *dst) { unsigned int rate; unsigned int fec; @@ -225,21 +227,21 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, - table->ports[i].index); + table->ports[i].index); for (j = 0; j < table->count; j++) { if (table->ports[i].label_port != - table->ports[j].label_port) + table->ports[j].label_port) continue; table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; if (table->ports[i].label_subport == - table->ports[j].label_subport) + table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", - table->ports[i].label_port, - table->ports[i].label_subport); + table->ports[i].label_port, + table->ports[i].label_subport); table->ports[i].is_split = 1; } @@ -296,7 +298,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", - ret, cnt); + ret, cnt); goto err; } @@ -354,7 +356,8 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) } struct nfp_nsp * -nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx) +nfp_eth_config_start(struct nfp_cpp *cpp, + unsigned int idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -447,7 +450,9 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) * -ERRNO - configuration failed. */ int -nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) +nfp_eth_set_mod_enable(struct nfp_cpp *cpp, + unsigned int idx, + int enable) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -487,7 +492,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) * -ERRNO - configuration failed. */ int -nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) +nfp_eth_set_configured(struct nfp_cpp *cpp, + unsigned int idx, + int configed) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -523,9 +530,12 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) } static int -nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, - const uint64_t mask, const unsigned int shift, - unsigned int val, const uint64_t ctrl_bit) +nfp_eth_set_bit_config(struct nfp_nsp *nsp, + unsigned int raw_idx, + const uint64_t mask, + const unsigned int shift, + unsigned int val, + const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); unsigned int idx = nfp_nsp_config_idx(nsp); @@ -560,7 +570,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, (__extension__ ({ \ typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /* @@ -574,11 +584,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, * Return: 0 or -ERRNO. */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) +__nfp_eth_set_aneg(struct nfp_nsp *nsp, + enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_ANEG, mode, - NSP_ETH_CTRL_SET_ANEG); + NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } /* @@ -592,11 +602,11 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) * Return: 0 or -ERRNO. */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) +__nfp_eth_set_fec(struct nfp_nsp *nsp, + enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_FEC, mode, - NSP_ETH_CTRL_SET_FEC); + NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } /* @@ -611,7 +621,9 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) * -ERRNO - configuration failed. */ int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) +nfp_eth_set_fec(struct nfp_cpp *cpp, + unsigned int idx, + enum nfp_eth_fec mode) { struct nfp_nsp *nsp; int err; @@ -642,7 +654,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) +__nfp_eth_set_speed(struct nfp_nsp *nsp, + unsigned int speed) { enum nfp_eth_rate rate; @@ -653,8 +666,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) } return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_RATE, rate, - NSP_ETH_CTRL_SET_RATE); + NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } /* @@ -668,8 +680,9 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes) +__nfp_eth_set_split(struct nfp_nsp *nsp, + unsigned int lanes) { - return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, - lanes, NSP_ETH_CTRL_SET_LANES); + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, + NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 838cd6e0ef..57089c770f 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -64,7 +64,8 @@ struct nfp_resource { }; static int -nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) +nfp_cpp_resource_find(struct nfp_cpp *cpp, + struct nfp_resource *res) { char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; struct nfp_resource_entry entry; @@ -85,7 +86,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { uint64_t addr = NFP_RESOURCE_TBL_BASE + - sizeof(struct nfp_resource_entry) * i; + sizeof(struct nfp_resource_entry) * i; ret = nfp_cpp_read(cpp, cpp_id, addr, &entry, sizeof(entry)); if (ret != sizeof(entry)) @@ -95,12 +96,11 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) continue; /* Found key! */ - res->mutex = - nfp_cpp_mutex_alloc(cpp, - NFP_RESOURCE_TBL_TARGET, addr, key); + res->mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, + addr, key); res->cpp_id = NFP_CPP_ID(entry.region.cpp_target, - entry.region.cpp_action, - entry.region.cpp_token); + entry.region.cpp_action, + entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; return 0; @@ -110,8 +110,9 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) } static int -nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, - struct nfp_cpp_mutex *dev_mutex) +nfp_resource_try_acquire(struct nfp_cpp *cpp, + struct nfp_resource *res, + struct nfp_cpp_mutex *dev_mutex) { int err; @@ -148,7 +149,8 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, * Return: NFP Resource handle, or NULL */ struct nfp_resource * -nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) +nfp_resource_acquire(struct nfp_cpp *cpp, + const char *name) { struct nfp_cpp_mutex *dev_mutex; struct nfp_resource *res; @@ -165,8 +167,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, - NFP_RESOURCE_TBL_BASE, - NFP_RESOURCE_TBL_KEY); + NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { free(res); return NULL; @@ -234,8 +235,8 @@ nfp_resource_cpp_id(const struct nfp_resource *res) * * Return: const char pointer to the name of the resource */ -const char -*nfp_resource_name(const struct nfp_resource *res) +const char * +nfp_resource_name(const struct nfp_resource *res) { return res->name; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 06cc6f74f4..009b7359a4 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -18,7 +18,7 @@ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, - const char *name); + const char *name); /** * Release a NFP Resource, and free the handle diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 4c45aec5c1..aa3b7a483e 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -40,22 +40,25 @@ struct nfp_rtsym_table { }; static int -nfp_meid(uint8_t island_id, uint8_t menum) +nfp_meid(uint8_t island_id, + uint8_t menum) { return (island_id & 0x3F) == island_id && menum < 12 ? (island_id << 4) | (menum + 4) : -1; } static void -nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, uint32_t strtab_size, - struct nfp_rtsym *sw, struct nfp_rtsym_entry *fw) +nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, + uint32_t strtab_size, + struct nfp_rtsym *sw, + struct nfp_rtsym_entry *fw) { sw->type = fw->type; sw->name = cache->strtab + rte_le_to_cpu_16(fw->name) % strtab_size; sw->addr = ((uint64_t)fw->addr_hi << 32) | - rte_le_to_cpu_32(fw->addr_lo); + rte_le_to_cpu_32(fw->addr_lo); sw->size = ((uint64_t)fw->size_hi << 32) | - rte_le_to_cpu_32(fw->size_lo); + rte_le_to_cpu_32(fw->size_lo); PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", sw->name, sw->addr, sw->size, sw->target); @@ -93,7 +96,8 @@ nfp_rtsym_table_read(struct nfp_cpp *cpp) } struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) +__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip) { uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; struct nfp_rtsym_entry *rtsymtab; @@ -142,7 +146,7 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) for (n = 0; n < cache->num; n++) nfp_rtsym_sw_entry_init(cache, strtab_size, - &cache->symtab[n], &rtsymtab[n]); + &cache->symtab[n], &rtsymtab[n]); free(rtsymtab); @@ -178,7 +182,8 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) +nfp_rtsym_get(struct nfp_rtsym_table *rtbl, + int idx) { if (rtbl == NULL) return NULL; @@ -197,7 +202,8 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name) +nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name) { int n; @@ -331,7 +337,9 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, * Return: value read, on error sets the error and returns ~0ULL. */ uint64_t -nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) +nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, + const char *name, + int *error) { const struct nfp_rtsym *sym; uint32_t val32; @@ -354,7 +362,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, - name, sym->size); + name, sym->size); err = -EINVAL; break; } @@ -372,8 +380,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) } uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area) +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, + const char *name, + unsigned int min_size, + struct nfp_cpp_area **area) { int ret; uint8_t *mem; @@ -397,7 +407,7 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, if (sym->size < min_size) { PMD_DRV_LOG(ERR, "Symbol %s too small (%" PRIu64 " < %u)", name, - sym->size, min_size); + sym->size, min_size); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 8b494211bc..30768f1ccf 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -43,19 +43,18 @@ struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip); +struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip); 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); +const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name); uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, - int *error); -uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + int *error); +uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, + unsigned int min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 03/27] net/nfp: unify the type of integer variable 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He 2023-08-24 11:09 ` [PATCH 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-08-24 11:09 ` [PATCH 02/27] net/nfp: unify the indent coding style Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 04/27] net/nfp: remove the unneeded logic Chaoyong He ` (24 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Unify the type of integer variable to the DPDK prefer style. Also change the return type of 'nfp_eth_speed2rate()' to the corresponding enum, which make it more readable. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 53 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 20 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 40 +++++++-------- drivers/net/nfp/nfpcore/nfp_mutex.c | 12 ++--- drivers/net/nfp/nfpcore/nfp_nffw.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nsp.c | 28 +++++----- drivers/net/nfp/nfpcore/nfp_nsp.h | 59 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 52 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- 12 files changed, 139 insertions(+), 139 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 54bef3cb6b..782272a3f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -71,8 +71,8 @@ struct nfp_cpp_operations { */ int (*area_init)(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size); + uint64_t address, + size_t size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -103,16 +103,16 @@ struct nfp_cpp_operations { */ int (*area_read)(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); }; /* @@ -398,7 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, unsigned long size); + uint64_t address, size_t size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,8 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, const char *name, unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, uint64_t address, + uint32_t size); /* * Free an allocated NFP CPP area handle @@ -446,7 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, unsigned long long address, unsigned long size); + uint32_t cpp_id, uint64_t address, size_t size); /* * Release the resources, then free the NFP CPP area handle @@ -455,7 +455,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, struct nfp_cpp_area **area); + uint64_t addr, uint32_t size, struct nfp_cpp_area **area); + /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -478,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * @return bytes read on success, negative value on failure. * */ -int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); /* @@ -492,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * * @return bytes written on success, negative value on failure. */ -int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); /* @@ -547,7 +548,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + uint64_t address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -561,9 +562,7 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); - + uint64_t address, const void *kernel_vaddr, size_t length); /* @@ -593,7 +592,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); /* @@ -610,7 +609,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); /* @@ -627,7 +626,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); /* @@ -644,7 +643,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); /* @@ -707,7 +706,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + uint64_t address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -721,7 +720,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + uint64_t address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -734,7 +733,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + uint64_t address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -747,7 +746,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + uint64_t address, uint64_t value); /* * Initialize a mutex location @@ -768,7 +767,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -788,7 +787,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 884cc84eaa..881f21bfd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -101,7 +101,7 @@ struct nfp_bar { uint64_t base; /* CPP address base */ uint64_t mask; /* Bit mask of the bar */ uint32_t bitsize; /* Bit size of the bar */ - int index; + uint32_t index; int lock; char *csr; @@ -400,8 +400,8 @@ struct nfp6000_area_priv { static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -501,8 +501,8 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -510,7 +510,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -571,8 +571,8 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -580,7 +580,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, struct nfp6000_area_priv *priv; uint32_t *wrptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -752,7 +752,7 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - unsigned long tmp; + uint64_t tmp; int i = 0; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 25f7700b08..7b32721d60 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -169,8 +169,8 @@ struct nfp_cpp_area * nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, const char *name, - unsigned long long address, - unsigned long size) + uint64_t address, + uint32_t size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -184,7 +184,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, if (err < 0) return NULL; - address = (unsigned long long)tmp64; + address = tmp64; if (name == NULL) name = ""; @@ -213,8 +213,8 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -237,8 +237,8 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_cpp_area *area; @@ -352,7 +352,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) */ int nfp_cpp_area_read(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, void *kernel_vaddr, size_t length) { @@ -378,7 +378,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, */ int nfp_cpp_area_write(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, const void *kernel_vaddr, size_t length) { @@ -461,7 +461,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, int nfp_cpp_area_readl(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t *value) { int sz; @@ -475,7 +475,7 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, int nfp_cpp_area_writel(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t value) { int sz; @@ -487,7 +487,7 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, int nfp_cpp_area_readq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t *value) { int sz; @@ -501,7 +501,7 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, int nfp_cpp_area_writeq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t value) { int sz; @@ -515,7 +515,7 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t *value) { int sz; @@ -530,7 +530,7 @@ nfp_cpp_readl(struct nfp_cpp *cpp, int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t value) { int sz; @@ -544,7 +544,7 @@ nfp_cpp_writel(struct nfp_cpp *cpp, int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t *value) { int sz; @@ -559,7 +559,7 @@ nfp_cpp_readq(struct nfp_cpp *cpp, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t value) { int sz; @@ -758,7 +758,7 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, void *kernel_vaddr, size_t length) { @@ -788,7 +788,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, const void *kernel_vaddr, size_t length) { @@ -902,7 +902,7 @@ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, + uint32_t size, struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 047e755416..697361da4d 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -28,16 +28,16 @@ struct nfp_cpp_mutex { struct nfp_cpp *cpp; uint8_t target; uint16_t depth; - unsigned long long address; + uint64_t address; uint32_t key; - unsigned int usage; + uint32_t usage; struct nfp_cpp_mutex *prev, *next; }; static int _nfp_cpp_mutex_validate(uint32_t model, int *target, - unsigned long long address) + uint64_t address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -76,7 +76,7 @@ _nfp_cpp_mutex_validate(uint32_t model, int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -119,7 +119,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -269,7 +269,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", + PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", mutex->usage, mutex->depth, mutex->target, mutex->address, mutex->key); warn_at = time(NULL) + 60; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 8bdc69766e..7ff468373b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,7 +68,7 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - unsigned int mode, addr40; + uint32_t mode, addr40; uint32_t xpbaddr, imbcppat; int err; @@ -84,7 +84,7 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) return nfp_cppat_mu_locality_lsb(mode, addr40); } -static unsigned int +static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { /* @@ -183,7 +183,7 @@ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { struct nffw_fwinfo *fwinfo; - unsigned int cnt, i; + uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4f476f6f2b..87eed3d951 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -34,7 +34,7 @@ nfp_nsp_config_entries(struct nfp_nsp *state) return state->entries; } -unsigned int +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state) { return state->idx; @@ -43,7 +43,7 @@ nfp_nsp_config_idx(struct nfp_nsp *state) void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx) + uint32_t idx) { state->entries = entries; state->idx = idx; @@ -59,12 +59,12 @@ nfp_nsp_config_clear_state(struct nfp_nsp *state) static void nfp_nsp_print_extended_error(uint32_t ret_val) { - int i; + uint32_t i; if (ret_val == 0) return; - for (i = 0; i < (int)RTE_DIM(nsp_errors); i++) + for (i = 0; i < RTE_DIM(nsp_errors); i++) if (ret_val == (uint32_t)nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -171,7 +171,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t val) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -297,7 +297,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; - unsigned int max_size; + size_t max_size; uint64_t reg, cpp_buf; int ret, err; uint32_t cpp_id; @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } @@ -361,7 +361,7 @@ int nfp_nsp_wait(struct nfp_nsp *state) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -401,7 +401,7 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, NULL, 0); @@ -410,7 +410,7 @@ nfp_nsp_load_fw(struct nfp_nsp *state, int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, buf, size); @@ -419,7 +419,7 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, NULL, 0); @@ -428,7 +428,7 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, buf, size); @@ -436,9 +436,9 @@ nfp_nsp_read_identify(struct nfp_nsp *state, int nfp_nsp_read_sensors(struct nfp_nsp *state, - unsigned int sensor_mask, + uint32_t sensor_mask, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, 0, buf, size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 1e2deaabb4..edb56e26ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -110,11 +110,11 @@ uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); int nfp_nsp_wait(struct nfp_nsp *state); int nfp_nsp_device_soft_reset(struct nfp_nsp *state); -int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); -int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); -int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); +int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); +int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, + void *buf, size_t size); static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) @@ -188,17 +188,17 @@ enum nfp_eth_fec { * @fec_modes_supported: bitmap of FEC modes supported */ struct nfp_eth_table { - unsigned int count; - unsigned int max_index; + uint32_t count; + uint32_t max_index; struct nfp_eth_table_port { - unsigned int eth_index; - unsigned int index; - unsigned int nbi; - unsigned int base; - unsigned int lanes; - unsigned int speed; - - unsigned int interface; + uint32_t eth_index; + uint32_t index; + uint32_t nbi; + uint32_t base; + uint32_t lanes; + uint32_t speed; + + uint32_t interface; enum nfp_eth_media media; enum nfp_eth_fec fec; @@ -218,51 +218,50 @@ struct nfp_eth_table { /* Computed fields */ uint8_t port_type; - unsigned int port_lanes; + uint32_t port_lanes; int is_split; - unsigned int fec_modes_supported; + uint32_t fec_modes_supported; } ports[]; }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); -int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + size_t size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); -unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { - return !!eth_port->fec_modes_supported; + return eth_port->fec_modes_supported != 0; } -static inline unsigned int +static inline uint32_t nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported; } -struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx); +struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes); +int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /** * struct nfp_nsp_identify - NSP static information @@ -298,6 +297,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + uint32_t *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 28dba27124..31677b66e6 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -75,7 +75,7 @@ struct nfp_sensors { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val) + uint32_t *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 3eeefc74af..9213023690 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -124,7 +124,7 @@ union eth_table_entry { static const struct { enum nfp_eth_rate rate; - unsigned int speed; + uint32_t speed; } nsp_eth_rate_tbl[] = { { RATE_INVALID, 0, }, { RATE_10M, SPEED_10, }, @@ -134,24 +134,24 @@ static const struct { { RATE_25G, SPEED_25000, }, }; -static unsigned int +static uint32_t nfp_eth_rate2speed(enum nfp_eth_rate rate) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].rate == rate) return nsp_eth_rate_tbl[i].speed; return 0; } -static unsigned int -nfp_eth_speed2rate(unsigned int speed) +static enum nfp_eth_rate +nfp_eth_speed2rate(uint32_t speed) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].speed == speed) return nsp_eth_rate_tbl[i].rate; @@ -161,7 +161,7 @@ nfp_eth_speed2rate(unsigned int speed) static void nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) { - int i; + uint32_t i; for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) dst[RTE_ETHER_ADDR_LEN - i - 1] = src[i]; @@ -170,11 +170,11 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) static void nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, + uint32_t index, struct nfp_eth_table_port *dst) { - unsigned int rate; - unsigned int fec; + uint32_t rate; + uint32_t fec; uint64_t port, state; port = rte_le_to_cpu_64(src->port); @@ -223,7 +223,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - unsigned int i, j; + uint32_t i, j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -268,7 +268,9 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; struct nfp_eth_table *table; uint32_t table_sz; - int i, j, ret, cnt = 0; + uint32_t i; + uint32_t j; + int ret, cnt = 0; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -318,7 +320,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } nfp_eth_calc_port_geometry(table); - for (i = 0; i < (int)table->count; i++) + for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); free(entries); @@ -357,7 +359,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, - unsigned int idx) + uint32_t idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -451,7 +453,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int enable) { union eth_table_entry *entries; @@ -493,7 +495,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, */ int nfp_eth_set_configured(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int configed) { union eth_table_entry *entries; @@ -531,14 +533,14 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, static int nfp_eth_set_bit_config(struct nfp_nsp *nsp, - unsigned int raw_idx, + uint32_t raw_idx, const uint64_t mask, - const unsigned int shift, - unsigned int val, + const uint32_t shift, + uint32_t val, const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - unsigned int idx = nfp_nsp_config_idx(nsp); + uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; /* @@ -622,7 +624,7 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, */ int nfp_eth_set_fec(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, enum nfp_eth_fec mode) { struct nfp_nsp *nsp; @@ -655,7 +657,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, - unsigned int speed) + uint32_t speed) { enum nfp_eth_rate rate; @@ -681,7 +683,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, */ int __nfp_eth_set_split(struct nfp_nsp *nsp, - unsigned int lanes) + uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 57089c770f..9dd4832779 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -156,7 +156,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; int err; struct timespec wait; - int count; + uint16_t count; res = malloc(sizeof(*res)); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index aa3b7a483e..243d3c9ce5 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -382,7 +382,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, + uint32_t min_size, struct nfp_cpp_area **area) { int ret; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 30768f1ccf..e7295258b3 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -56,5 +56,5 @@ const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + uint32_t min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 04/27] net/nfp: remove the unneeded logic 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (2 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 03/27] net/nfp: unify the type of integer variable Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 05/27] net/nfp: standard the local variable coding style Chaoyong He ` (23 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Remove the unneeded logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 107 ---- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 - drivers/net/nfp/nfpcore/nfp_cppcore.c | 162 ------ drivers/net/nfp/nfpcore/nfp_mutex.c | 48 -- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 24 - drivers/net/nfp/nfpcore/nfp_target.h | 567 --------------------- 6 files changed, 920 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 782272a3f4..139752f85a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -96,7 +96,6 @@ struct nfp_cpp_operations { void *(*area_iomem)(struct nfp_cpp_area *area); - void *(*area_mapped)(struct nfp_cpp_area *area); /* * Perform a read from a NFP CPP area * Serialized @@ -457,16 +456,6 @@ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Return an IO pointer to the beginning of the NFP CPP area handle. The area - * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * - * @return Pointer to IO memory, or NULL on failure. - */ -void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); - /* * Read from a NFP CPP area handle into a buffer. The area must be acquired with * 'nfp_cpp_area_acquire()' before calling this operation. @@ -508,18 +497,6 @@ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Verify that IO can be performed on an offset in an area - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] size Size of region to validate - * - * @return 0 on success, negative value on failure. - */ -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); - /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle * @@ -564,20 +541,6 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); - -/* - * Fill a NFP CPP area handle and offset with a value - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the NFP CPP ID address space - * @param[in] value 32-bit value to fill area with - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, negative value on failure. - */ -int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); - /* * Read a single 32-bit value from a NFP CPP area handle * @@ -668,33 +631,6 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, negative value on failure. - */ -int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); - /* * Read a 32-bit word from a NFP CPP ID * @@ -789,49 +725,6 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Get the NFP CPP handle the mutex was created with - * - * @param mutex NFP mutex handle - * @return NFP CPP handle - */ -struct nfp_cpp *nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex key - * - * @param mutex NFP mutex handle - * @return Mutex key - */ -uint32_t nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex owner - * - * @param mutex NFP mutex handle - * @return Interface ID of the mutex owner - * - * NOTE: This is for debug purposes ONLY - the owner may change at any time, - * unless it has been locked by this NFP CPP handle. - */ -uint16_t nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex target - * - * @param mutex NFP mutex handle - * @return Mutex CPP target (ie NFP_CPP_TARGET_MU) - */ -int nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex address - * - * @param mutex NFP mutex handle - * @return Mutex CPP address - */ -uint64_t nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex); - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 881f21bfd0..ec14ec45dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -471,17 +471,6 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) return 0; } -static void * -nfp6000_area_mapped(struct nfp_cpp_area *area) -{ - struct nfp6000_area_priv *area_priv = nfp_cpp_area_priv(area); - - if (area_priv->iomem == NULL) - return NULL; - - return area_priv->iomem; -} - static void nfp6000_area_release(struct nfp_cpp_area *area) { @@ -829,7 +818,6 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, - .area_mapped = nfp6000_area_mapped, .area_read = nfp6000_area_read, .area_write = nfp6000_area_write, .area_iomem = nfp6000_area_iomem, diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7b32721d60..f885e7d8ff 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -388,35 +388,6 @@ nfp_cpp_area_write(struct nfp_cpp_area *area, return area->cpp->op->area_write(area, kernel_vaddr, offset, length); } -void * -nfp_cpp_area_mapped(struct nfp_cpp_area *area) -{ - if (area->cpp->op->area_mapped) - return area->cpp->op->area_mapped(area); - return NULL; -} - -/* - * nfp_cpp_area_check_range - check if address range fits in CPP area - * - * @area: CPP area handle - * @offset: offset into CPP area - * @length: size of address range in bytes - * - * Check if address range fits within CPP area. Return 0 if area fits - * or negative value on error. - */ -int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, - unsigned long length) -{ - if (((offset + length) > area->size)) - return -EFAULT; - - return 0; -} - /* * Return the correct CPP address, and fixup xpb_addr as needed, * based upon NFP model. @@ -671,82 +642,6 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int -nfp_xpb_writelm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value) -{ - int err; - uint32_t tmp; - - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - return err; - - tmp &= ~mask; - tmp |= (mask & value); - return nfp_xpb_writel(cpp, xpb_tgt, tmp); -} - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, or negative value on failure. - */ -int -nfp_xpb_waitlm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value, - int timeout_us) -{ - uint32_t tmp; - int err; - - do { - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - goto exit; - - if ((tmp & mask) == (value & mask)) { - if (timeout_us < 0) - timeout_us = 0; - break; - } - - if (timeout_us < 0) - continue; - - timeout_us -= 100; - usleep(100); - } while (timeout_us >= 0); - - if (timeout_us < 0) - err = -ETIMEDOUT; - else - err = timeout_us; - -exit: - return err; -} - /* * nfp_cpp_read - read from CPP target * @cpp: CPP handle @@ -805,63 +700,6 @@ nfp_cpp_write(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_area_fill - fill a CPP area with a value - * @area: CPP area - * @offset: offset into CPP area - * @value: value to fill with - * @length: length of area to fill - */ -int -nfp_cpp_area_fill(struct nfp_cpp_area *area, - unsigned long offset, - uint32_t value, - size_t length) -{ - int err; - size_t i; - uint64_t value64; - - value = rte_cpu_to_le_32(value); - value64 = ((uint64_t)value << 32) | value; - - if ((offset + length) > area->size) - return -EINVAL; - - if ((area->offset + offset) & 3) - return -EINVAL; - - if (((area->offset + offset) & 7) == 4 && length >= 4) { - err = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - offset += sizeof(value); - length -= sizeof(value); - } - - for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); - if (err < 0) - return err; - if (err != sizeof(value64)) - return -ENOSPC; - } - - if ((i + sizeof(value)) <= length) { - err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - i += sizeof(value); - } - - return (int)i; -} - /* * NOTE: This code should not use nfp_xpb_* functions, * as those are model-specific diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 697361da4d..4d26e6f052 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -178,54 +178,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -struct nfp_cpp * -nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex) -{ - return mutex->cpp; -} - -uint32_t -nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex) -{ - return mutex->key; -} - -uint16_t -nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex) -{ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t value, key; - int err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - return err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); - if (err < 0) - return err; - - if (key != mutex->key) - return -EPERM; - - if (MUTEX_IS_LOCKED(value) == 0) - return 0; - - return MUTEX_INTERFACE(value); -} - -int -nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex) -{ - return mutex->target; -} - -uint64_t -nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex) -{ - return mutex->address; -} - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9213023690..899fcd7441 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,30 +11,6 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) #define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 03908a894f..195e599d31 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,571 +6,4 @@ #ifndef NFP_TARGET_H #define NFP_TARGET_H -#include "nfp_cpp.h" - -#define P32 1 -#define P64 2 - -#define PUSHPULL(_pull, _push) (((_pull) << 4) | ((_push) << 0)) - -#ifndef NFP_ERRNO -#include <errno.h> -#define NFP_ERRNO(x) (errno = (x), -1) -#endif - -static inline int -pushpull_width(int pp) -{ - pp &= 0xf; - - if (pp == 0) - return NFP_ERRNO(EINVAL); - return (2 << pp); -} - -#define PUSH_WIDTH(_pushpull) pushpull_width((_pushpull) >> 0) -#define PULL_WIDTH(_pushpull) pushpull_width((_pushpull) >> 4) - -static inline int -target_rw(uint32_t cpp_id, int pp, int start, int len) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < start || island > (start + len))) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): - return PUSHPULL(0, pp); - case NFP_CPP_ID(0, 1, 0): - return PUSHPULL(pp, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(pp, pp); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_dma(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiDma */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiDma */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_stats(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiStats */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiStats */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_tm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiTM */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiTM */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_ppc(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiPreclassifier */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiPreclassifier */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi(uint32_t cpp_id, uint64_t address) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - uint64_t rel_addr = address & 0x3fFFFF; - - if (island && (island < 8 || island > 9)) - return NFP_ERRNO(EINVAL); - - if (rel_addr < (1 << 20)) - return nfp6000_nbi_dma(cpp_id); - if (rel_addr < (2 << 20)) - return nfp6000_nbi_stats(cpp_id); - if (rel_addr < (3 << 20)) - return nfp6000_nbi_tm(cpp_id); - return nfp6000_nbi_ppc(cpp_id); -} - -/* - * This structure ONLY includes items that can be done with a read or write of - * 32-bit or 64-bit words. All others are not listed. - */ -static inline int -nfp6000_mu_common(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): /* read_be/write_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): /* read_le/write_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 2): /* {read/write}_swap_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 3): /* {read/write}_swap_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, 0, 0): /* read_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 1): /* read_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 2): /* read_swap_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 3): /* read_swap_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* write_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 1): /* write_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 2): /* write_swap_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 3): /* write_swap_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 3, 0): /* atomic_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 2): /* mask_compare_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* atomic_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 2): /* atomic_write_imm */ - return PUSHPULL(0, 0); - case NFP_CPP_ID(0, 4, 3): /* swap_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 5, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 5, 3): /* test_set_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 6, 0): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 3): /* test_clr_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 7, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 7, 3): /* test_add_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 8, 0): /* addsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 3): /* test_sub_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 0): /* microq128_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 1): /* microq128_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 2): /* microq128_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 0): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 3): /* test_xor_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 0): /* read32_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 1): /* read32_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 2): /* read32_swap_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 3): /* read32_swap_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 31, 0): /* write32_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 1): /* write32_le */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 2): /* write32_swap_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 3): /* write32_swap_le */ - return PUSHPULL(P32, 0); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_mu_ctm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 16, 1): /* packet_read_packet_status */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_emu(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 18, 0): /* read_queue */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 1): /* read_queue_ring */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 2): /* write_queue */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 18, 3): /* write_queue_ring */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 20, 2): /* journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 21, 0): /* get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 1): /* get_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 2): /* get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 0): /* pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 1): /* pop_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 2): /* pop_freely */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_imu(uint32_t cpp_id) -{ - return nfp6000_mu_common(cpp_id); -} - -static inline int -nfp6000_mu(uint32_t cpp_id, uint64_t address) -{ - int pp; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island == 0) { - if (address < 0x2000000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x8000000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0x9800000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x9C00000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0xA000000000ULL) - pp = nfp6000_mu_imu(cpp_id); - else - pp = nfp6000_mu_ctm(cpp_id); - } else if (island >= 24 && island <= 27) { - pp = nfp6000_mu_emu(cpp_id); - } else if (island >= 28 && island <= 31) { - pp = nfp6000_mu_imu(cpp_id); - } else if (island == 1 || - (island >= 4 && island <= 7) || - (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { - pp = nfp6000_mu_ctm(cpp_id); - } else { - pp = NFP_ERRNO(EINVAL); - } - - return pp; -} - -static inline int -nfp6000_ila(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 48 || island > 51)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* read_check_error */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 0): /* read_int */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* write_int */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 48, 4); - } -} - -static inline int -nfp6000_pci(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 4 || island > 7)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 4, 4); - } -} - -static inline int -nfp6000_crypto(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 12 || island > 15)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(P64, 0); - default: - return target_rw(cpp_id, P64, 12, 4); - } -} - -static inline int -nfp6000_cap_xpb(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* RingGet */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 0, 2): /* Interthread Signal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 1): /* RingPut */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 2): /* CTNNWr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* ReflectRd, signal none */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 1): /* ReflectRd, signal self */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 2): /* ReflectRd, signal remote */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 3): /* ReflectRd, signal both */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* ReflectWr, signal none */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 1): /* ReflectWr, signal self */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 2): /* ReflectWr, signal remote */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 3): /* ReflectWr, signal both */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): - return PUSHPULL(P32, P32); - default: - return target_rw(cpp_id, P32, 1, 63); - } -} - -static inline int -nfp6000_cls(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 3): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 1): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 1): /* add64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 1): /* sub64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 2): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 2): /* hash_mask */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* hash_clear */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 0): /* ring_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 1): /* ring_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 2): /* ring_get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 3): /* ring_pop_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* ring_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 2): /* ring_journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 14, 0): /* reflect_write_sig_local */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 1): /* reflect_read_sig_local */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 17, 2): /* statistic */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 24, 0): /* ring_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 24, 1): /* ring_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 25, 0): /* ring_workq_add_thread */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 25, 1): /* ring_workq_add_work */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 0, 64); - } -} - -static inline int -nfp6000_target_pushpull(uint32_t cpp_id, uint64_t address) -{ - switch (NFP_CPP_ID_TARGET_of(cpp_id)) { - case NFP6000_CPPTGT_NBI: - return nfp6000_nbi(cpp_id, address); - case NFP6000_CPPTGT_VQDR: - return target_rw(cpp_id, P32, 24, 4); - case NFP6000_CPPTGT_ILA: - return nfp6000_ila(cpp_id); - case NFP6000_CPPTGT_MU: - return nfp6000_mu(cpp_id, address); - case NFP6000_CPPTGT_PCIE: - return nfp6000_pci(cpp_id); - case NFP6000_CPPTGT_ARM: - if (address < 0x10000) - return target_rw(cpp_id, P64, 1, 1); - else - return target_rw(cpp_id, P32, 1, 1); - case NFP6000_CPPTGT_CRYPTO: - return nfp6000_crypto(cpp_id); - case NFP6000_CPPTGT_CTXPB: - return nfp6000_cap_xpb(cpp_id); - case NFP6000_CPPTGT_CLS: - return nfp6000_cls(cpp_id); - case 0: - return target_rw(cpp_id, P32, 4, 4); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_pushpull_width(int pp, int write_not_read) -{ - if (pp < 0) - return pp; - - if (write_not_read) - return PULL_WIDTH(pp); - else - return PUSH_WIDTH(pp); -} - -static inline int -nfp6000_target_action_width(uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - int pp; - - pp = nfp6000_target_pushpull(cpp_id, address); - - return nfp_target_pushpull_width(pp, write_not_read); -} - -static inline int -nfp_target_action_width(uint32_t model, uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - if (NFP_CPP_MODEL_IS_6000(model)) { - return nfp6000_target_action_width(cpp_id, address, - write_not_read); - } else { - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table) -{ - int err; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_island_id); - uint8_t target = NFP_CPP_ID_TARGET_of(cpp_island_id); - uint32_t imb; - - if (target >= 16) - return NFP_ERRNO(EINVAL); - - if (island == 0) { - /* Already translated */ - *cpp_target_id = cpp_island_id; - *cpp_target_address = cpp_island_address; - return 0; - } - - if (imb_table == NULL) { - /* CPP + Island only allowed on systems with IMB tables */ - return NFP_ERRNO(EINVAL); - } - - imb = imb_table[target]; - - *cpp_target_address = cpp_island_address; - err = _nfp6000_cppat_addr_encode(cpp_target_address, island, target, - ((imb >> 13) & 7), - ((imb >> 12) & 1), - ((imb >> 6) & 0x3f), - ((imb >> 0) & 0x3f)); - if (err == 0) { - *cpp_target_id = - NFP_CPP_ID(target, NFP_CPP_ID_ACTION_of(cpp_island_id), - NFP_CPP_ID_TOKEN_of(cpp_island_id)); - } - - return err; -} - #endif /* NFP_TARGET_H */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 05/27] net/nfp: standard the local variable coding style 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (3 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 04/27] net/nfp: remove the unneeded logic Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 06/27] net/nfp: adjust the log statement Chaoyong He ` (22 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He There should only declare one local variable in each line, and the local variable should be arranged from short to long in the function. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 58 ++++++++++++---------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 27 ++++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 8 +-- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 ++++++---- drivers/net/nfp/nfpcore/nfp_nffw.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nsp.c | 40 ++++++++------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +-- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 39 ++++++++------- drivers/net/nfp/nfpcore/nfp_resource.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 19 ++++--- 11 files changed, 151 insertions(+), 117 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index ec14ec45dc..78beee07ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -140,9 +140,9 @@ nfp_compute_bar(const struct nfp_bar *bar, size_t size, int width) { - uint32_t bitsize; - uint32_t newcfg; uint64_t mask; + uint32_t newcfg; + uint32_t bitsize; if (tgt >= 16) return -EINVAL; @@ -239,7 +239,8 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base, slot; + int base; + int slot; base = bar->index >> 3; slot = bar->index & 7; @@ -268,9 +269,9 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, size_t size, int width) { - uint64_t newbase; - uint32_t newcfg; int err; + uint32_t newcfg; + uint64_t newbase; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); @@ -303,8 +304,10 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, static int nfp_enable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -333,8 +336,10 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) static struct nfp_bar * nfp_alloc_bar(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -356,8 +361,10 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) static void nfp_disable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -403,12 +410,13 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint64_t address, size_t size) { - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); - struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + int pp; + int ret = 0; + uint32_t token = NFP_CPP_ID_TOKEN_of(dest); uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); - uint32_t token = NFP_CPP_ID_TOKEN_of(dest); - int pp, ret = 0; + struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -493,14 +501,14 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + size_t n; + int width; + bool is_64; + uint32_t *wrptr32 = kernel_vaddr; uint64_t *wrptr64 = kernel_vaddr; - const volatile uint64_t *rdptr64; struct nfp6000_area_priv *priv; - uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; - int width; - size_t n; - bool is_64; + const volatile uint64_t *rdptr64; priv = nfp_cpp_area_priv(area); rdptr64 = (uint64_t *)(priv->iomem + offset); @@ -563,14 +571,14 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { - const uint64_t *rdptr64 = kernel_vaddr; - uint64_t *wrptr64; - const uint32_t *rdptr32 = kernel_vaddr; - struct nfp6000_area_priv *priv; - uint32_t *wrptr32; - int width; size_t n; + int width; bool is_64; + uint32_t *wrptr32; + uint64_t *wrptr64; + struct nfp6000_area_priv *priv; + const uint32_t *rdptr32 = kernel_vaddr; + const uint64_t *rdptr64 = kernel_vaddr; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); @@ -693,10 +701,10 @@ static int nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) { + off_t pos; uint16_t tmp; uint8_t serial[6]; int serial_len = 6; - off_t pos; pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); if (pos <= 0) { @@ -741,8 +749,8 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - uint64_t tmp; int i = 0; + uint64_t tmp; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f885e7d8ff..776842bdf6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -172,9 +172,9 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint64_t address, uint32_t size) { + int err; struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; - int err; if (cpp == NULL) return NULL; @@ -396,8 +396,8 @@ static uint32_t nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) { - uint32_t xpb; int island; + uint32_t xpb; xpb = NFP_CPP_ID(14, NFP_CPP_ACTION_RW, 0); @@ -569,9 +569,9 @@ static struct nfp_cpp * nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) { - const struct nfp_cpp_operations *ops; - struct nfp_cpp *cpp; int err; + struct nfp_cpp *cpp; + const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); @@ -657,8 +657,8 @@ nfp_cpp_read(struct nfp_cpp *cpp, void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { @@ -687,8 +687,8 @@ nfp_cpp_write(struct nfp_cpp *cpp, const void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) @@ -708,8 +708,8 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { - uint32_t reg; int err; + uint32_t reg; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, ®); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index ea4c7d6a9e..819761eda0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -36,7 +36,9 @@ static int nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { - const char *key, *val, *end = hwinfo->data + size; + const char *key; + const char *val; + const char *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { @@ -58,7 +60,9 @@ static int nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) { - uint32_t size, new_crc, *crc; + uint32_t *crc; + uint32_t size; + uint32_t new_crc; size = db->size; if (size > len) { @@ -82,12 +86,12 @@ static struct nfp_hwinfo * nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) { - struct nfp_hwinfo *header; - void *res; - uint64_t cpp_addr; - uint32_t cpp_id; int err; + void *res; uint8_t *db; + uint32_t cpp_id; + uint64_t cpp_addr; + struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); if (res) { @@ -135,13 +139,12 @@ static struct nfp_hwinfo * nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) { + int count = 0; struct timespec wait; struct nfp_hwinfo *db; - int count; wait.tv_sec = 0; wait.tv_nsec = 10000000; - count = 0; for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -159,9 +162,9 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo * nfp_hwinfo_read(struct nfp_cpp *cpp) { - struct nfp_hwinfo *db; - size_t hwdb_size = 0; int err; + size_t hwdb_size = 0; + struct nfp_hwinfo *db; db = nfp_hwinfo_fetch(cpp, &hwdb_size); if (db == NULL) @@ -186,7 +189,9 @@ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) { - const char *key, *val, *end; + const char *key; + const char *val; + const char *end; if (hwinfo == NULL || lookup == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0071d3fc37..1e601313b4 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -68,10 +68,10 @@ static int nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) { - struct nfp_nffw_info *nffw_info; - uint32_t cpp_id; - uint64_t addr; int err; + uint64_t addr; + uint32_t cpp_id; + struct nfp_nffw_info *nffw_info; nffw_info = nfp_nffw_info_open(cpp); if (nffw_info == NULL) @@ -100,8 +100,8 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) { - struct nfp_mip *mip; int err; + struct nfp_mip *mip; mip = malloc(sizeof(*mip)); if (mip == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 4d26e6f052..05e0ff46e5 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -79,9 +79,9 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { + int err; uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - int err; err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -122,11 +122,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { - uint32_t model = nfp_cpp_model(cpp); - struct nfp_cpp_mutex *mutex; - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ int err; uint32_t tmp; + struct nfp_cpp_mutex *mutex; + uint32_t model = nfp_cpp_model(cpp); + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -241,12 +241,13 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) { - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + int err; + uint32_t key; + uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t key, value; uint16_t interface = nfp_cpp_interface(cpp); - int err; + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -295,12 +296,14 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) { + int err; + uint32_t key; + uint32_t tmp; + uint32_t value; + struct nfp_cpp *cpp = mutex->cpp; uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ - uint32_t key, value, tmp; - struct nfp_cpp *cpp = mutex->cpp; - int err; if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 7ff468373b..32e0fc94bb 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,9 +68,11 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - uint32_t mode, addr40; - uint32_t xpbaddr, imbcppat; int err; + uint32_t mode; + uint32_t addr40; + uint32_t xpbaddr; + uint32_t imbcppat; /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; @@ -117,10 +119,10 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) { - struct nfp_nffw_info_data *fwinf; - struct nfp_nffw_info *state; - uint32_t info_ver; int err; + uint32_t info_ver; + struct nfp_nffw_info *state; + struct nfp_nffw_info_data *fwinf; state = malloc(sizeof(*state)); if (state == NULL) @@ -182,8 +184,9 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { + uint32_t i; + uint32_t cnt; struct nffw_fwinfo *fwinfo; - uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 87eed3d951..a00bd5870d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -72,10 +72,11 @@ nfp_nsp_print_extended_error(uint32_t ret_val) static int nfp_nsp_check(struct nfp_nsp *state) { - struct nfp_cpp *cpp = state->cpp; - uint64_t nsp_status, reg; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t nsp_status; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_status = nfp_resource_address(state->res) + NSP_STATUS; @@ -113,9 +114,9 @@ nfp_nsp_check(struct nfp_nsp *state) struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) { - struct nfp_resource *res; - struct nfp_nsp *state; int err; + struct nfp_nsp *state; + struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); if (res == NULL) @@ -170,13 +171,12 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t mask, uint64_t val) { - struct timespec wait; - uint32_t count; int err; + uint32_t count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -217,10 +217,15 @@ nfp_nsp_command(struct nfp_nsp *state, uint32_t buff_cpp, uint64_t buff_addr) { - uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; - struct nfp_cpp *cpp = state->cpp; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t ret_val; + uint64_t nsp_base; + uint64_t nsp_buffer; + uint64_t nsp_status; + uint64_t nsp_command; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_base = nfp_resource_address(state->res); @@ -296,11 +301,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, void *out_buf, unsigned int out_size) { - struct nfp_cpp *cpp = nsp->cpp; + int err; + int ret; + uint64_t reg; size_t max_size; - uint64_t reg, cpp_buf; - int ret, err; uint32_t cpp_id; + uint64_t cpp_buf; + struct nfp_cpp *cpp = nsp->cpp; if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", @@ -360,13 +367,12 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, int nfp_nsp_wait(struct nfp_nsp *state) { - struct timespec wait; - uint32_t count; int err; + int count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 31677b66e6..3081e22dad 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -26,9 +26,9 @@ struct nsp_identify { struct nfp_nsp_identify * __nfp_nsp_identify(struct nfp_nsp *nsp) { - struct nfp_nsp_identify *nspi = NULL; - struct nsp_identify *ni; int ret; + struct nsp_identify *ni; + struct nfp_nsp_identify *nspi = NULL; if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; @@ -77,9 +77,9 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val) { - struct nfp_sensors s; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + struct nfp_sensors s; nsp = nfp_nsp_open(cpp); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 899fcd7441..9e8a247e5c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -149,9 +149,10 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, uint32_t index, struct nfp_eth_table_port *dst) { - uint32_t rate; uint32_t fec; - uint64_t port, state; + uint64_t port; + uint32_t rate; + uint64_t state; port = rte_le_to_cpu_64(src->port); state = rte_le_to_cpu_64(src->state); @@ -199,7 +200,8 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - uint32_t i, j; + uint32_t i; + uint32_t j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -241,12 +243,13 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) static struct nfp_eth_table * __nfp_eth_read_ports(struct nfp_nsp *nsp) { - union eth_table_entry *entries; - struct nfp_eth_table *table; - uint32_t table_sz; + int ret; uint32_t i; uint32_t j; - int ret, cnt = 0; + int cnt = 0; + uint32_t table_sz; + struct nfp_eth_table *table; + union eth_table_entry *entries; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -320,8 +323,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) { - struct nfp_eth_table *ret; struct nfp_nsp *nsp; + struct nfp_eth_table *ret; nsp = nfp_nsp_open(cpp); if (nsp == NULL) @@ -337,9 +340,9 @@ struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + union eth_table_entry *entries; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -400,8 +403,8 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) int nfp_eth_config_commit_end(struct nfp_nsp *nsp) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); int ret = 1; + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); if (nfp_nsp_config_modified(nsp)) { ret = nfp_nsp_write_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); @@ -432,9 +435,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -474,9 +477,9 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -515,9 +518,9 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, uint32_t val, const uint64_t ctrl_bit) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; + uint32_t idx = nfp_nsp_config_idx(nsp); + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); /* * Note: set features were added in ABI 0.14 but the error @@ -603,8 +606,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode) { - struct nfp_nsp *nsp; int err; + struct nfp_nsp *nsp; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 9dd4832779..fa92f2762e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -67,10 +67,12 @@ static int nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) { - char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; + int ret; + uint32_t i; + uint32_t key; + uint32_t cpp_id; struct nfp_resource_entry entry; - uint32_t cpp_id, key; - int ret, i; + char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; cpp_id = NFP_CPP_ID(NFP_RESOURCE_TBL_TARGET, 3, 0); /* Atomic read */ @@ -152,11 +154,11 @@ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) { - struct nfp_cpp_mutex *dev_mutex; - struct nfp_resource *res; int err; + uint16_t count = 0; struct timespec wait; - uint16_t count; + struct nfp_resource *res; + struct nfp_cpp_mutex *dev_mutex; res = malloc(sizeof(*res)); if (res == NULL) @@ -175,7 +177,6 @@ nfp_resource_acquire(struct nfp_cpp *cpp, wait.tv_sec = 0; wait.tv_nsec = 1000000; - count = 0; for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 243d3c9ce5..a34278beca 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -85,8 +85,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, struct nfp_rtsym_table * nfp_rtsym_table_read(struct nfp_cpp *cpp) { - struct nfp_rtsym_table *rtbl; struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; mip = nfp_mip_open(cpp); rtbl = __nfp_rtsym_table_read(cpp, mip); @@ -99,13 +99,18 @@ struct nfp_rtsym_table * __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) { - uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; - struct nfp_rtsym_entry *rtsymtab; + int n; + int err; + uint32_t size; + uint32_t strtab_addr; + uint32_t symtab_addr; + uint32_t strtab_size; + uint32_t symtab_size; struct nfp_rtsym_table *cache; + struct nfp_rtsym_entry *rtsymtab; const uint32_t dram = NFP_CPP_ID(NFP_CPP_TARGET_MU, NFP_CPP_ACTION_RW, 0) | NFP_ISL_EMEM0; - int err, n, size; if (mip == NULL) return NULL; @@ -341,10 +346,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) { - const struct nfp_rtsym *sym; - uint32_t val32; - uint64_t val; int err; + uint64_t val; + uint32_t val32; + const struct nfp_rtsym *sym; sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 06/27] net/nfp: adjust the log statement 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (4 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 05/27] net/nfp: standard the local variable coding style Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 07/27] net/nfp: standard the comment style Chaoyong He ` (21 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add log statement to the important control logic, which means more strict check of the return value of function call. Also remove some verbose info log statement. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 37 ++++++---------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 20 +++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 28 ++++++++-------- drivers/net/nfp/nfpcore/nfp_mip.c | 7 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 4 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 ++++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 25 +++++++++++---- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++--- drivers/net/nfp/nfpcore/nfp_resource.c | 17 +++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 14 +++----- 10 files changed, 92 insertions(+), 79 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 78beee07ef..bdf4a658f5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -174,18 +174,10 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } - offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + offset &= mask; bitsize = 40 - 16; } else { @@ -198,30 +190,16 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); - bitsize = 40 - 21; } - if (bar->bitsize < bitsize) { - PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + if (bar->bitsize < bitsize) return -EINVAL; - } newcfg |= offset >> bitsize; @@ -254,7 +232,6 @@ nfp_bar_write(struct nfp_pcie_user *nfp, *(uint32_t *)(bar->csr) = newcfg; bar->barcfg = newcfg; - PMD_DRV_LOG(DEBUG, "BAR%d: updated to 0x%08x", bar->index, newcfg); return 0; } @@ -795,7 +772,11 @@ nfp6000_init(struct nfp_cpp *cpp, desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; - nfp_enable_bars(desc); + ret = nfp_enable_bars(desc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Enable bars failed"); + return -1; + } nfp_cpp_priv_set(cpp, desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 776842bdf6..66f4ddaab7 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -200,6 +200,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, err = cpp->op->area_init(area, dest, address, size); if (err < 0) { + PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } @@ -243,10 +244,13 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc(cpp, destination, address, size); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate CPP area"); return NULL; + } if (nfp_cpp_area_acquire(area) != 0) { + PMD_DRV_LOG(ERR, "Failed to acquire CPP area"); nfp_cpp_area_free(area); return NULL; } @@ -294,8 +298,10 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; + } } return 0; @@ -662,7 +668,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { - PMD_DRV_LOG(ERR, "Area allocation/acquire failed"); + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } @@ -691,8 +697,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; + } err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); @@ -746,8 +754,10 @@ nfp_cpp_map_area(struct nfp_cpp *cpp, uint8_t *res; *area = nfp_cpp_area_alloc_acquire(cpp, cpp_id, addr, size); - if (*area == NULL) + if (*area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for map"); goto err_eio; + } res = nfp_cpp_area_iomem(*area); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 819761eda0..b658b5e900 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -74,7 +74,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, new_crc = nfp_crc32_posix((char *)db, size); crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { - PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", + PMD_DRV_LOG(ERR, "CRC mismatch, calculated %#x, expected %#x", new_crc, *crc); return -EINVAL; } @@ -94,34 +94,36 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); - if (res) { - cpp_id = nfp_resource_cpp_id(res); - cpp_addr = nfp_resource_address(res); - *cpp_size = nfp_resource_size(res); + if (res == NULL) { + PMD_DRV_LOG(ERR, "HWInfo - acquire resource failed"); + return NULL; + } - nfp_resource_release(res); + cpp_id = nfp_resource_cpp_id(res); + cpp_addr = nfp_resource_address(res); + *cpp_size = nfp_resource_size(res); - if (*cpp_size < HWINFO_SIZE_MIN) - return NULL; - } else { + nfp_resource_release(res); + + if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - } db = malloc(*cpp_size + 1); if (db == NULL) return NULL; err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size); - if (err != (int)*cpp_size) + if (err != (int)*cpp_size) { + PMD_DRV_LOG(ERR, "HWInfo - CPP read error %d", err); goto exit_free; + } header = (void *)db; - PMD_DRV_LOG(DEBUG, "NFP HWINFO header: %#08x", *(uint32_t *)header); if (nfp_hwinfo_is_updating(header)) goto exit_free; if (header->version != NFP_HWINFO_VERSION_2) { - PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", + PMD_DRV_LOG(ERR, "Unknown HWInfo version: %#08x", header->version); goto exit_free; } diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 1e601313b4..086e82db70 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -46,16 +46,16 @@ nfp_mip_try_read(struct nfp_cpp *cpp, ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip)); if (ret != sizeof(*mip)) { - PMD_DRV_LOG(ERR, "Failed to read MIP data (%d, %zu)", ret, sizeof(*mip)); + PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } if (mip->signature != NFP_MIP_SIGNATURE) { - PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", + PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { - PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", + PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -109,6 +109,7 @@ nfp_mip_open(struct nfp_cpp *cpp) err = nfp_mip_read_resource(cpp, mip); if (err != 0) { + PMD_DRV_LOG(ERR, "Failed to read MIP resource"); free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 05e0ff46e5..82919d8270 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -221,9 +221,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 32e0fc94bb..6ba40cd085 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,6 +3,7 @@ * All rights reserved. */ +#include "../nfp_logs.h" #include "nfp_cpp.h" #include "nfp_nffw.h" #include "nfp_mip.h" @@ -131,8 +132,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) memset(state, 0, sizeof(*state)); state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); - if (state->res == NULL) + if (state->res == NULL) { + PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); goto err_free; + } fwinf = &state->fwinf; @@ -142,8 +145,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), nfp_resource_address(state->res), fwinf, sizeof(*fwinf)); - if (err < (int)sizeof(*fwinf)) + if (err < (int)sizeof(*fwinf)) { + PMD_DRV_LOG(ERR, "NFFW - CPP read error %d", err); goto err_release; + } if (nffw_res_flg_init_get(fwinf) == 0) goto err_release; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index a00bd5870d..76d418d478 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -82,8 +82,10 @@ nfp_nsp_check(struct nfp_nsp *state) nsp_status = nfp_resource_address(state->res) + NSP_STATUS; err = nfp_cpp_readq(cpp, nsp_cpp, nsp_status, ®); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed %d", err); return err; + } if (FIELD_GET(NSP_STATUS_MAGIC, reg) != NSP_MAGIC) { PMD_DRV_LOG(ERR, "Cannot detect NFP Service Processor"); @@ -119,8 +121,10 @@ nfp_nsp_open(struct nfp_cpp *cpp) struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); - if (res == NULL) + if (res == NULL) { + PMD_DRV_LOG(ERR, "NSP - resource acquire failed"); return NULL; + } state = malloc(sizeof(*state)); if (state == NULL) { @@ -133,6 +137,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) err = nfp_nsp_check(state); if (err != 0) { + PMD_DRV_LOG(ERR, "NSP - check failed"); nfp_nsp_close(state); return NULL; } @@ -180,8 +185,10 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed"); return err; + } if ((*reg & mask) == val) return 0; @@ -234,8 +241,10 @@ nfp_nsp_command(struct nfp_nsp *state, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "Check NSP command failed"); return err; + } if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { @@ -261,7 +270,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", err, code); return err; } @@ -270,7 +279,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", err, code); return err; } @@ -352,8 +361,10 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, } ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); - if (ret < 0) + if (ret < 0) { + PMD_DRV_LOG(ERR, "NSP command failed"); return ret; + } if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9e8a247e5c..51dcf24f5f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -259,7 +259,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } @@ -278,7 +278,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * above. */ if (ret != 0 && ret != cnt) { - PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", + PMD_DRV_LOG(ERR, "Table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; } @@ -357,12 +357,12 @@ nfp_eth_config_start(struct nfp_cpp *cpp, ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } if ((entries[idx].port & NSP_ETH_PORT_LANES_MASK) == 0) { - PMD_DRV_LOG(ERR, "trying to set port state on disabled port %d", idx); + PMD_DRV_LOG(ERR, "Trying to set port state on disabled port %d", idx); goto err; } @@ -642,7 +642,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, rate = nfp_eth_speed2rate(speed); if (rate == RATE_INVALID) { - PMD_DRV_LOG(ERR, "could not find matching lane rate for speed %u", speed); + PMD_DRV_LOG(ERR, "Could not find matching lane rate for speed %u", speed); return -EINVAL; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index fa92f2762e..363f7d6198 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -118,16 +118,22 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, { int err; - if (nfp_cpp_mutex_lock(dev_mutex) != 0) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex lock failed"); return -EINVAL; + } err = nfp_cpp_resource_find(cpp, res); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP resource find failed"); goto err_unlock_dev; + } err = nfp_cpp_mutex_trylock(res->mutex); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex trylock failed"); goto err_res_mutex_free; + } nfp_cpp_mutex_unlock(dev_mutex); @@ -171,6 +177,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); free(res); return NULL; } @@ -182,8 +189,10 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err = nfp_resource_try_acquire(cpp, res, dev_mutex); if (err == 0) break; - if (err != -EBUSY) + if (err != -EBUSY) { + PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); goto err_free; + } if (count++ > 1000) { PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index a34278beca..d15a920752 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -60,8 +60,6 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->size = ((uint64_t)fw->size_hi << 32) | rte_le_to_cpu_32(fw->size_lo); - PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", - sw->name, sw->addr, sw->size, sw->target); switch (fw->target) { case SYM_TGT_LMEM: sw->target = NFP_RTSYM_TARGET_LMEM; @@ -227,7 +225,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) { switch (sym->type) { case NFP_RTSYM_TYPE_NONE: - PMD_DRV_LOG(ERR, "rtsym '%s': type NONE", sym->name); + PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ case NFP_RTSYM_TYPE_FUNCTION: @@ -235,7 +233,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_ABS: return sizeof(uint64_t); default: - PMD_DRV_LOG(ERR, "rtsym '%s': unknown type: %d", sym->name, sym->type); + PMD_DRV_LOG(ERR, "Unknown RTSYM type %u", sym->type); return 0; } } @@ -366,7 +364,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); break; default: - PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", name, sym->size); err = -EINVAL; break; @@ -396,10 +394,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, uint32_t cpp_id; const struct nfp_rtsym *sym; - PMD_DRV_LOG(DEBUG, "mapping symbol %s", name); sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { - PMD_INIT_LOG(ERR, "symbol lookup fails for %s", name); + PMD_DRV_LOG(ERR, "Symbol lookup fails for %s", name); return NULL; } @@ -418,10 +415,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, mem = nfp_cpp_map_area(rtbl->cpp, cpp_id, addr, sym->size, area); if (mem == NULL) { - PMD_INIT_LOG(ERR, "Failed to map symbol %s", name); + PMD_DRV_LOG(ERR, "Failed to map symbol %s", name); return NULL; } - PMD_DRV_LOG(DEBUG, "symbol %s with address %p", name, mem); return mem; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 07/27] net/nfp: standard the comment style 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (5 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 06/27] net/nfp: adjust the log statement Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 08/27] net/nfp: using the DPDK memory management API Chaoyong He ` (20 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Follow the DPDK coding style, use the kdoc comment style. Also add some comment to help understand logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 504 ++++----------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 39 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 484 ++++++++++++++++---- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 21 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 + drivers/net/nfp/nfpcore/nfp_mip.c | 43 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 69 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 49 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 6 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 53 ++- drivers/net/nfp/nfpcore/nfp_nsp.h | 108 ++--- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 170 ++++--- drivers/net/nfp/nfpcore/nfp_resource.c | 103 +++-- drivers/net/nfp/nfpcore/nfp_resource.h | 28 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 59 ++- drivers/net/nfp/nfpcore/nfp_rtsym.h | 12 +- drivers/net/nfp/nfpcore/nfp_target.c | 2 +- 17 files changed, 888 insertions(+), 864 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 139752f85a..82189e9910 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -10,9 +10,7 @@ struct nfp_cpp_mutex; -/* - * NFP CPP handle - */ +/* NFP CPP handle */ struct nfp_cpp { uint32_t model; uint32_t interface; @@ -37,9 +35,7 @@ struct nfp_cpp { int driver_lock_needed; }; -/* - * NFP CPP device area handle - */ +/* NFP CPP device area handle */ struct nfp_cpp_area { struct nfp_cpp *cpp; char *name; @@ -127,35 +123,45 @@ struct nfp_cpp_operations { #define NFP_CPP_TARGET_ID_MASK 0x1f -/* +/** * Pack target, token, and action into a CPP ID. * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id * - * @return NFP CPP ID + * @return + * NFP CPP ID */ #define NFP_CPP_ID(target, action, token) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ (((action) & 0xff) << 8)) -/* +/** * Pack target, token, action, and island into a CPP ID. - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id - * @island NFP CPP island id * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @return NFP CPP ID + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id + * @param island + * NFP CPP island id + * + * @return + * NFP CPP ID */ #define NFP_CPP_ISLAND_ID(target, action, token, island) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ @@ -163,9 +169,12 @@ struct nfp_cpp_operations { /** * Return the NFP CPP target of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP target + * @param id + * NFP CPP ID + * + * @return + * NFP CPP target */ static inline uint8_t NFP_CPP_ID_TARGET_of(uint32_t id) @@ -173,11 +182,14 @@ NFP_CPP_ID_TARGET_of(uint32_t id) return (id >> 24) & NFP_CPP_TARGET_ID_MASK; } -/* +/** * Return the NFP CPP token of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP token + * @param id + * NFP CPP ID + * + * @return + * NFP CPP token */ static inline uint8_t NFP_CPP_ID_TOKEN_of(uint32_t id) @@ -185,11 +197,14 @@ NFP_CPP_ID_TOKEN_of(uint32_t id) return (id >> 16) & 0xff; } -/* +/** * Return the NFP CPP action of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP action + * @param id + * NFP CPP ID + * + * @return + * NFP CPP action */ static inline uint8_t NFP_CPP_ID_ACTION_of(uint32_t id) @@ -197,11 +212,14 @@ NFP_CPP_ID_ACTION_of(uint32_t id) return (id >> 8) & 0xff; } -/* +/** * Return the NFP CPP island of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP island + * @param id + * NFP CPP ID + * + * @return + * NFP CPP island */ static inline uint8_t NFP_CPP_ID_ISLAND_of(uint32_t id) @@ -215,109 +233,57 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) */ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); -/* - * Set the model id - * - * @param cpp NFP CPP operations structure - * @param model Model ID - */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param interface Interface ID - */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param serial NFP serial byte array - * @param len Length of the serial byte array - */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); -/* - * Set the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); -/* - * Return the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void *nfp_cpp_priv(struct nfp_cpp *cpp); -/* - * Get the privately allocated portion of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the private area, or NULL on failure - */ void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); -/* - * NFP CPP core interface for CPP clients. - */ - -/* - * Open a NFP CPP handle to a CPP device - * - * @param[in] id 0-based ID for the CPP interface to use - * - * @return NFP CPP handle, or NULL on failure. - */ +/* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed); -/* - * Free a NFP CPP handle - * - * @param[in] cpp NFP CPP handle - */ void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/* - * NFP_CPP_MODEL_CHIP_of - retrieve the chip ID from the model ID +/** + * Retrieve the chip ID from the model ID * * The chip ID is a 16-bit BCD+A-F encoding for the chip type. * - * @param[in] model NFP CPP model id - * @return NFP CPP chip id + * @param model + * NFP CPP model id + * + * @return + * NFP CPP chip id */ #define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) -/* - * NFP_CPP_MODEL_IS_6000 - Check for the NFP6000 family of devices +/** + * Check for the NFP6000 family of devices * * NOTE: The NFP4000 series is considered as a NFP6000 series variant. * - * @param[in] model NFP CPP model id - * @return true if model is in the NFP6000 family, false otherwise. + * @param model + * NFP CPP model id + * + * @return + * true if model is in the NFP6000 family, false otherwise. */ #define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) -/* - * nfp_cpp_model - Retrieve the Model ID of the NFP - * - * @param[in] cpp NFP CPP handle - * @return NFP CPP Model ID - */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,7 +296,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); #define NFP_CPP_INTERFACE_TYPE_RPC 0x3 #define NFP_CPP_INTERFACE_TYPE_ILA 0x4 -/* +/** * Construct a 16-bit NFP Interface ID * * Interface IDs consists of 4 bits of interface type, 4 bits of unit @@ -340,422 +306,138 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * which use the MU Atomic CompareAndWrite operation - hence the limit to 16 * bits to be able to use the NFP Interface ID as a lock owner. * - * @param[in] type NFP Interface Type - * @param[in] unit Unit identifier for the interface type - * @param[in] channel Channel identifier for the interface unit - * @return Interface ID + * @param type + * NFP Interface Type + * @param unit + * Unit identifier for the interface type + * @param channel + * Channel identifier for the interface unit + * + * @return + * Interface ID */ #define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) -/* +/** * Get the interface type of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's type + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's type */ #define NFP_CPP_INTERFACE_TYPE_of(interface) (((interface) >> 12) & 0xf) -/* +/** * Get the interface unit of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's unit + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's unit */ #define NFP_CPP_INTERFACE_UNIT_of(interface) (((interface) >> 8) & 0xf) -/* +/** * Get the interface channel of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's channel + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's channel */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) -/* - * Retrieve the Interface ID of the NFP - * @param[in] cpp NFP CPP handle - * @return NFP CPP Interface ID - */ + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -/* - * Retrieve the NFP Serial Number (unique per NFP) - * @param[in] cpp NFP CPP handle - * @param[out] serial Pointer to reference the serial number array - * - * @return size of the NFP6000 serial number, in bytes - */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] name Name of owner of the area - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t cpp_id, const char *name, uint64_t address, uint32_t size); -/* - * Free an allocated NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_free(struct nfp_cpp_area *area); -/* - * Acquire the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - * - * @return 0 on success, -1 on failure. - */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area); -/* - * Release the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release(struct nfp_cpp_area *area); -/* - * Allocate, then acquire the resources needed to access the NFP CPP area handle - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Release the resources, then free the NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Read from a NFP CPP area handle into a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer to receive the data - * @param[in] length Length of the data to read - * - * @return bytes read on success, negative value on failure. - * - */ int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); -/* - * Write to a NFP CPP area handle from a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer that holds the data - * @param[in] length Length of the data to read - * - * @return bytes written on success, negative value on failure. - */ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area - * @area: CPP area handle - * - * Returns an iomem pointer for use with readl()/writel() style operations. - * - * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL - */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Get the NFP CPP handle that is the parent of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return NFP CPP handle - */ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); -/* - * Get the name passed during allocation of the NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the area's name - */ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); -/* - * Read a block of data from a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy read data to - * @param[in] length Size of the area to reserve - * - * @return bytes read on success, -1 on failure. - */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, void *kernel_vaddr, size_t length); -/* - * Write a block of data to a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy write data from - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, -1 on failure. - */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); -/* - * Read a single 32-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); -/* - * Write a single 32-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); -/* - * Read a single 64-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); -/* - * Write a single 64-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); -/* - * Write a single 32-bit value on the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); -/* - * Read a single 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Read a 32-bit word from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t *value); -/* - * Write a 32-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - * - */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t value); -/* - * Read a 64-bit work from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t *value); -/* - * Write a 64-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -/* - * Initialize a mutex location - - * The CPP target:address must point to a 64-bit aligned location, and will - * initialize 64 bits of data at the location. - * - * This creates the initial mutex state, as locked by this nfp_cpp_interface(). - * - * This function should only be called when setting up the initial lock state - * upon boot-up of the system. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id Unique 32-bit value for this mutex - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Create a mutex handle from an address controlled by a MU Atomic engine - * - * The CPP target:address must point to a 64-bit aligned location, and reserve - * 64 bits of data at the location for use by the handle. - * - * Only target/address pairs that point to entities that support the MU Atomic - * Engine's CmpAndSwap32 command are supported. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id 32-bit unique key (must match the key at this location) - * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on - * failure. - */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Free a mutex handle - does not alter the lock state - * - * @param mutex NFP CPP Mutex handle - */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); -/* - * Lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); -/* - * Unlock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); -/* - * Attempt to lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. - */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index bdf4a658f5..7e94bfb611 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -72,40 +72,25 @@ #define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ (((bar) * 8 + (slot)) * 4) -/* - * Define to enable a bit more verbose debug output. - * Set to 1 to enable a bit more verbose debug output. - */ struct nfp_pcie_user; struct nfp6000_area_priv; -/* - * struct nfp_bar - describes BAR configuration and usage - * @nfp: backlink to owner - * @barcfg: cached contents of BAR config CSR - * @base: the BAR's base CPP offset - * @mask: mask for the BAR aperture (read only) - * @bitsize: bitsize of BAR aperture (read only) - * @index: index of the BAR - * @lock: lock to specify if bar is in use - * @refcnt: number of current users - * @iomem: mapped IO memory - */ +/* Describes BAR configuration and usage */ #define NFP_BAR_MIN 1 #define NFP_BAR_MID 5 #define NFP_BAR_MAX 7 struct nfp_bar { - struct nfp_pcie_user *nfp; - uint32_t barcfg; - uint64_t base; /* CPP address base */ - uint64_t mask; /* Bit mask of the bar */ - uint32_t bitsize; /* Bit size of the bar */ - uint32_t index; - int lock; + struct nfp_pcie_user *nfp; /**< Backlink to owner */ + uint32_t barcfg; /**< BAR config CSR */ + uint64_t base; /**< Base CPP offset */ + uint64_t mask; /**< Mask of the BAR aperture (read only) */ + uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ + uint32_t index; /**< Index of the BAR */ + int lock; /**< If the BAR has been locked */ char *csr; - char *iomem; + char *iomem; /**< mapped IO memory */ }; #define BUSDEV_SZ 13 @@ -360,9 +345,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* - * Generic CPP bus access interface. - */ +/* Generic CPP bus access interface. */ struct nfp6000_area_priv { struct nfp_bar *bar; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 66f4ddaab7..f601907673 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -26,6 +26,15 @@ #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/** + * Set the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) @@ -33,12 +42,29 @@ nfp_cpp_priv_set(struct nfp_cpp *cpp, cpp->priv = priv; } +/** + * Return the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void * nfp_cpp_priv(struct nfp_cpp *cpp) { return cpp->priv; } +/** + * Set the model id + * + * @param cpp + * NFP CPP operations structure + * @param model + * Model ID + */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) @@ -46,6 +72,15 @@ nfp_cpp_model_set(struct nfp_cpp *cpp, cpp->model = model; } +/** + * Retrieve the Model ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Model ID + */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp) { @@ -63,6 +98,14 @@ nfp_cpp_model(struct nfp_cpp *cpp) return model; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param interface + * Interface ID + */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) @@ -70,6 +113,17 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, cpp->interface = interface; } +/** + * Retrieve the Serial ID of the NFP + * + * @param cpp + * NFP CPP handle + * @param serial + * Pointer to NFP serial number + * + * @return + * Length of NFP serial number + */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) @@ -78,6 +132,16 @@ nfp_cpp_serial(struct nfp_cpp *cpp, return cpp->serial_len; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param serial + * NFP serial byte array + * @param serial_len + * Length of the serial byte array + */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, @@ -96,6 +160,15 @@ nfp_cpp_serial_set(struct nfp_cpp *cpp, return 0; } +/** + * Retrieve the Interface ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Interface ID + */ uint16_t nfp_cpp_interface(struct nfp_cpp *cpp) { @@ -105,18 +178,45 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Get the privately allocated portion of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the private area, or NULL on failure + */ void * nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area) { return &cpp_area[1]; } +/** + * Get the NFP CPP handle that is the pci_dev of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * NFP CPP handle + */ struct nfp_cpp * nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area) { return cpp_area->cpp; } +/** + * Get the name passed during allocation of the NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the area's name + */ const char * nfp_cpp_area_name(struct nfp_cpp_area *cpp_area) { @@ -153,15 +253,24 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) return cpp->mu_locality_lsb; } -/* - * nfp_cpp_area_alloc - allocate a new CPP area - * @cpp: CPP handle - * @dest: CPP id - * @address: start address on CPP target - * @size: size of area in bytes +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. * - * Allocate and initialize a CPP area structure. The area must later - * be locked down with an 'acquire' before it can be safely accessed. + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param name + * Name of region + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL * * NOTE: @address and @size must be 32-bit aligned values. */ @@ -211,6 +320,25 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, return area; } +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. + * + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * + * NOTE: @address and @size must be 32-bit aligned values. + */ struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, @@ -220,17 +348,22 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, 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 - * @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. * + * @param cpp + * CPP device handle + * @param destination + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * * NOTE: @address and @size must be 32-bit aligned values. * * NOTE: The area must also be 'released' when the structure is freed. @@ -258,11 +391,11 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, return area; } -/* - * nfp_cpp_area_free - free up the CPP area - * area: CPP area handle - * +/** * Frees up memory resources held by the CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_free(struct nfp_cpp_area *area) @@ -272,11 +405,11 @@ nfp_cpp_area_free(struct nfp_cpp_area *area) free(area); } -/* - * nfp_cpp_area_release_free - release CPP area and free it - * area: CPP area handle +/** + * Releases CPP area and frees up memory resources held by it. * - * Releases CPP area and frees up memory resources held by the it. + * @param area + * CPP area handle */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area) @@ -285,12 +418,15 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) nfp_cpp_area_free(area); } -/* - * nfp_cpp_area_acquire - lock down a CPP area for access - * @area: CPP area handle +/** + * Locks down the CPP area for a potential long term activity. + * Area must always be locked down before being accessed. * - * Locks down the CPP area for a potential long term activity. Area - * must always be locked down before being accessed. + * @param area + * CPP area handle + * + * @return + * 0 on success, -1 on failure. */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area) @@ -307,11 +443,11 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) return 0; } -/* - * nfp_cpp_area_release - release a locked down CPP area - * @area: CPP area handle - * +/** * Releases a previously locked down CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_release(struct nfp_cpp_area *area) @@ -320,16 +456,16 @@ nfp_cpp_area_release(struct nfp_cpp_area *area) area->cpp->op->area_release(area); } -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area +/** + * Returns an iomem pointer for use with readl()/writel() style operations. * - * @area: CPP area handle + * @param area + * CPP area handle * - * Returns an iomem pointer for use with readl()/writel() style operations. + * @return + * Pointer to the area, or NULL * * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL */ void * nfp_cpp_area_iomem(struct nfp_cpp_area *area) @@ -342,18 +478,22 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) return iomem; } -/* - * nfp_cpp_area_read - read data from CPP area +/** + * Read data from indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to put data into - * @length: number of bytes to read + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Read data from indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -368,18 +508,22 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, return area->cpp->op->area_read(area, kernel_vaddr, offset, length); } -/* - * nfp_cpp_area_write - write data to CPP area +/** + * Write data to indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to read data from - * @length: number of bytes to write + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Write data to indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -436,6 +580,19 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, return xpb; } +/** + * Read a uint32_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, @@ -450,6 +607,19 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, @@ -462,6 +632,19 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, @@ -476,6 +659,19 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, @@ -489,6 +685,21 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint32_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -504,6 +715,21 @@ nfp_cpp_readl(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -518,6 +744,21 @@ nfp_cpp_writel(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -533,6 +774,21 @@ nfp_cpp_readq(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -547,6 +803,19 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Write a uint32_t word to a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -559,6 +828,19 @@ nfp_xpb_writel(struct nfp_cpp *cpp, return nfp_cpp_writel(cpp, cpp_dest, xpb_addr, value); } +/** + * Read a uint32_t value from a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -625,9 +907,11 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return cpp; } -/* - * nfp_cpp_free - free the CPP handle - * @cpp: CPP handle +/** + * Free the CPP handle + * + * @param cpp + * CPP handle */ void nfp_cpp_free(struct nfp_cpp *cpp) @@ -641,6 +925,19 @@ nfp_cpp_free(struct nfp_cpp *cpp) free(cpp); } +/** + * Create a NFP CPP handle from device + * + * @param dev + * PCI device + * @param driver_lock_needed + * Driver lock flag + * + * @return + * NFP CPP handle on success, NULL on failure + * + * NOTE: On failure, cpp_ops->free will be called! + */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) @@ -648,13 +945,22 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * nfp_cpp_read - read from CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer for result - * @length: number of bytes to read +/** + * Read from CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer for result + * @param length + * Number of bytes to read + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_read(struct nfp_cpp *cpp, @@ -678,13 +984,22 @@ nfp_cpp_read(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_write - write to CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer to read from - * @length: number of bytes to write +/** + * Write to CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer to read from + * @param length + * Number of bytes to write + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_write(struct nfp_cpp *cpp, @@ -731,18 +1046,23 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return 0; } -/* - * nfp_cpp_map_area() - Helper function to map an area - * @cpp: NFP CPP handler - * @cpp_id: CPP ID - * @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). * - * Map an area of IOMEM access. To undo the effect of this function call - * @nfp_cpp_area_release_free(*area). + * @param cpp + * NFP CPP handler + * @param cpp_id + * CPP id + * @param addr + * CPP address + * @param size + * Size of the area + * @param area + * Area handle (output) * - * Return: Pointer to memory mapped area or NULL + * @return + * Pointer to memory mapped area or NULL */ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index b658b5e900..f5579ab60f 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -3,7 +3,8 @@ * All rights reserved. */ -/* Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM +/* + * Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM * after chip reset. * * Examples of the fields: @@ -146,7 +147,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *db; wait.tv_sec = 0; - wait.tv_nsec = 10000000; + wait.tv_nsec = 10000000; /* 10ms */ for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -154,7 +155,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, return db; nanosleep(&wait, NULL); - if (count++ > 200) { + if (count++ > 200) { /* 10ms * 200 = 2s */ PMD_DRV_LOG(ERR, "NFP access error"); return NULL; } @@ -180,12 +181,16 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return db; } -/* - * nfp_hwinfo_lookup() - Find a value in the HWInfo table by name - * @hwinfo: NFP HWinfo table - * @lookup: HWInfo name to search for +/** + * Find a value in the HWInfo table by name + * + * @param hwinfo + * NFP HWInfo table + * @param lookup + * HWInfo name to search for * - * Return: Value of the HWInfo name, or NULL + * @return + * Value of the HWInfo name, or NULL */ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index a3da7512db..424db8035d 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -59,6 +59,8 @@ * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' * * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. */ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 086e82db70..0892c99e96 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -87,15 +87,16 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, return err; } -/* - * nfp_mip_open() - Get device MIP structure - * @cpp: NFP CPP Handle - * - * Copy MIP structure from NFP device and return it. The returned +/** + * Copy MIP structure from NFP device and return it. The returned * structure is handled internally by the library and should be - * freed by calling nfp_mip_close(). + * freed by calling @nfp_mip_close(). + * + * @param cpp + * NFP CPP Handle * - * Return: pointer to mip, NULL on failure. + * @return + * Pointer to MIP, NULL on failure. */ struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) @@ -131,11 +132,15 @@ nfp_mip_name(const struct nfp_mip *mip) return mip->name; } -/* - * nfp_mip_symtab() - Get the address and size of the MIP symbol table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol table - * @size: Location for size of MIP symbol table +/** + * Get the address and size of the MIP symbol table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol table + * @param size + * Location for size of MIP symbol table */ void nfp_mip_symtab(const struct nfp_mip *mip, @@ -146,11 +151,15 @@ nfp_mip_symtab(const struct nfp_mip *mip, *size = rte_le_to_cpu_32(mip->symtab_size); } -/* - * nfp_mip_strtab() - Get the address and size of the MIP symbol name table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol name table - * @size: Location for size of MIP symbol name table +/** + * Get the address and size of the MIP symbol name table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol name table + * @param size + * Location for size of MIP symbol name table */ void nfp_mip_strtab(const struct nfp_mip *mip, diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82919d8270..404d4fa938 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -53,7 +53,7 @@ _nfp_cpp_mutex_validate(uint32_t model, return 0; } -/* +/** * Initialize a mutex location * * The CPP target:address must point to a 64-bit aligned location, and @@ -65,13 +65,17 @@ _nfp_cpp_mutex_validate(uint32_t model, * This function should only be called when setting up * the initial lock state upon boot-up of the system. * - * @param mutex NFP CPP Mutex handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key Unique 32-bit value for this mutex + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * Unique 32-bit value for this mutex * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, @@ -99,7 +103,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, return 0; } -/* +/** * Create a mutex handle from an address controlled by a MU Atomic engine * * The CPP target:address must point to a 64-bit aligned location, and @@ -108,13 +112,17 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, * Only target/address pairs that point to entities that support the * MU Atomic Engine are supported. * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key 32-bit unique key (must match the key at this location) + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * 32-bit unique key (must match the key at this location) * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. + * @return + * A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, @@ -178,10 +186,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -/* +/** * Free a mutex handle - does not alter the lock state * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) @@ -203,12 +212,14 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) free(mutex); } -/* +/** * Lock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure. */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) @@ -229,12 +240,14 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return 0; } -/* +/** * Unlock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) @@ -280,16 +293,18 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return err; } -/* +/** * Attempt to lock a mutex handle, using the NFP MU Atomic Engine * * Valid lock states: - * * 0x....0000 - Unlocked * 0x....000f - Locked * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. + * @param mutex + * NFP CPP Mutex handle + * + * @return + * 0 if the lock succeeded, negative value on failure. */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) @@ -352,7 +367,7 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) * If there was another contending for this lock, then * the lock state would be 0x....000f * - * Write our owner ID into the lock + * Write our owner ID into the lock. * While not strictly necessary, this helps with * debug and bookkeeping. */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 6ba40cd085..af55671a88 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -52,7 +52,7 @@ nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 8) | mip_offset_lo */ +/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { @@ -111,11 +111,14 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) } } -/* - * nfp_nffw_info_open() - Acquire the lock on the NFFW table - * @cpp: NFP CPP handle +/** + * Acquire the lock on the NFFW table + * + * @param cpp + * NFP CPP handle * - * Return: nffw info pointer, or NULL on failure + * @return + * NFFW info pointer, or NULL on failure */ struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) @@ -167,11 +170,11 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) return NULL; } -/* - * nfp_nffw_info_close() - Release the lock on the NFFW table - * @state: NFP FW info state +/** + * Release the lock on the NFFW table * - * Return: void + * @param state + * NFFW info pointer */ void nfp_nffw_info_close(struct nfp_nffw_info *state) @@ -180,11 +183,14 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) free(state); } -/* - * nfp_nffw_info_fwid_first() - Return the first firmware ID in the NFFW - * @state: NFP FW info state +/** + * Return the first firmware ID in the NFFW * - * Return: First NFFW firmware info, NULL on failure + * @param state + * NFFW info pointer + * + * @return: + * First NFFW firmware info, NULL on failure */ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) @@ -204,13 +210,18 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; } -/* - * nfp_nffw_info_mip_first() - Retrieve the location of the first FW's MIP - * @state: NFP FW info state - * @cpp_id: Pointer to the CPP ID of the MIP - * @off: Pointer to the CPP Address of the MIP +/** + * Retrieve the location of the first FW's MIP + * + * @param state + * NFFW info pointer + * @param cpp_id + * Pointer to the CPP ID of the MIP + * @param off + * Pointer to the CPP Address of the MIP * - * Return: 0, or -ERRNO + * @return + * 0, or -ERRNO */ int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 46ac8a8d07..e032b6cce7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,7 +8,8 @@ #include "nfp_cpp.h" -/* Init-CSR owner IDs for firmware map to firmware IDs which start at 4. +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. * Lower IDs are reserved for target and loader IDs. */ #define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ @@ -16,7 +17,7 @@ #define NFFW_FWID_ALL 255 -/** +/* * NFFW_INFO_VERSION history: * 0: This was never actually used (before versioning), but it refers to * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later @@ -35,6 +36,7 @@ #define NFFW_MEINFO_CNT_V2 200 #define NFFW_FWINFO_CNT_V2 200 +/* nfp.nffw meinfo */ struct nffw_meinfo { uint32_t ctxmask__fwid__meid; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 76d418d478..039e4729bd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -109,9 +109,11 @@ nfp_nsp_check(struct nfp_nsp *state) return 0; } -/* - * nfp_nsp_open() - Prepare for communication and lock the NSP resource. - * @cpp: NFP CPP Handle +/** + * Prepare for communication and lock the NSP resource. + * + * @param cpp + * NFP CPP Handle */ struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) @@ -145,9 +147,11 @@ nfp_nsp_open(struct nfp_cpp *cpp) return state; } -/* - * nfp_nsp_close() - Clean up and unlock the NSP resource. - * @state: NFP SP state +/** + * Clean up and unlock the NSP resource. + * + * @param state + * NFP SP state */ void nfp_nsp_close(struct nfp_nsp *state) @@ -181,7 +185,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -194,28 +198,27 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, return 0; nanosleep(&wait, 0); - if (count++ > 1000) + if (count++ > 1000) /* 25ms * 1000 = 25s */ return -ETIMEDOUT; } } -/* - * nfp_nsp_command() - Execute a command on the NFP Service Processor - * @state: NFP SP state - * @code: NFP SP Command Code - * @option: NFP SP Command Argument - * @buff_cpp: NFP SP Buffer CPP Address info - * @buff_addr: NFP SP Buffer Host address - * - * Return: 0 for success with no result +/** + * Execute a command on the NFP Service Processor * - * positive value for NSP completion with a result code + * @param state + * NFP SP state + * @param arg + * NFP command argument structure * - * -EAGAIN if the NSP is not yet present - * -ENODEV if the NSP is not a supported model - * -EBUSY if the NSP is stuck - * -EINTR if interrupted while waiting for completion - * -ETIMEDOUT if the NSP took longer than 30 seconds to complete + * @return + * - 0 for success with no result + * - Positive value for NSP completion with a result code + * - -EAGAIN if the NSP is not yet present + * - -ENODEV if the NSP is not a supported model + * - -EBUSY if the NSP is stuck + * - -EINTR if interrupted while waiting for completion + * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int nfp_nsp_command(struct nfp_nsp *state, @@ -383,7 +386,7 @@ nfp_nsp_wait(struct nfp_nsp *state) struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); @@ -392,7 +395,7 @@ nfp_nsp_wait(struct nfp_nsp *state) nanosleep(&wait, 0); - if (count++ > 1000) { + if (count++ > 1000) { /* 25ms * 1000 = 25s */ err = -ETIMEDOUT; break; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index edb56e26ca..0fcb21e99c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -158,72 +158,45 @@ enum nfp_eth_fec { #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) -/** - * struct nfp_eth_table - ETH table information - * @count: number of table entries - * @max_index: max of @index fields of all @ports - * @ports: table of ports - * - * @eth_index: port index according to legacy ethX numbering - * @index: chip-wide first channel index - * @nbi: NBI index - * @base: first channel index (within NBI) - * @lanes: number of channels - * @speed: interface speed (in Mbps) - * @interface: interface (module) plugged in - * @media: media type of the @interface - * @fec: forward error correction mode - * @aneg: auto negotiation mode - * @mac_addr: interface MAC address - * @label_port: port id - * @label_subport: id of interface within port (for split ports) - * @enabled: is enabled? - * @tx_enabled: is TX enabled? - * @rx_enabled: is RX enabled? - * @override_changed: is media reconfig pending? - * - * @port_type: one of %PORT_* defines for ethtool - * @port_lanes: total number of lanes on the port (sum of lanes of all subports) - * @is_split: is interface part of a split port - * @fec_modes_supported: bitmap of FEC modes supported - */ +/* ETH table information */ struct nfp_eth_table { - uint32_t count; - uint32_t max_index; + uint32_t count; /**< Number of table entries */ + uint32_t max_index; /**< Max of @index fields of all @ports */ struct nfp_eth_table_port { + /** Port index according to legacy ethX numbering */ uint32_t eth_index; - uint32_t index; - uint32_t nbi; - uint32_t base; - uint32_t lanes; - uint32_t speed; + uint32_t index; /**< Chip-wide first channel index */ + uint32_t nbi; /**< NBI index */ + uint32_t base; /**< First channel index (within NBI) */ + uint32_t lanes; /**< Number of channels */ + uint32_t speed; /**< Interface speed (in Mbps) */ - uint32_t interface; - enum nfp_eth_media media; + uint32_t interface; /**< Interface (module) plugged in */ + enum nfp_eth_media media; /**< Media type of the @interface */ - enum nfp_eth_fec fec; - enum nfp_eth_aneg aneg; + enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ - struct rte_ether_addr mac_addr; + struct rte_ether_addr mac_addr; /**< Interface MAC address */ - uint8_t label_port; + uint8_t label_port; /**< Port id */ + /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; - int tx_enabled; - int rx_enabled; - - int override_changed; + int enabled; /**< Enable port */ + int tx_enabled; /**< Enable TX */ + int rx_enabled; /**< Enable RX */ - /* Computed fields */ - uint8_t port_type; + int override_changed; /**< Media reconfig pending */ + uint8_t port_type; /**< One of %PORT_* */ + /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; + int is_split; /**< Split port */ - uint32_t fec_modes_supported; - } ports[]; + uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ + } ports[]; /**< Table of ports */ }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); @@ -263,28 +236,17 @@ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); -/** - * struct nfp_nsp_identify - NSP static information - * @version: opaque version string - * @flags: version flags - * @br_primary: branch id of primary bootloader - * @br_secondary: branch id of secondary bootloader - * @br_nsp: branch id of NSP - * @primary: version of primary bootloader - * @secondary: version id of secondary bootloader - * @nsp: version id of NSP - * @sensor_mask: mask of present sensors available on NIC - */ +/* NSP static information */ struct nfp_nsp_identify { - char version[40]; - uint8_t flags; - uint8_t br_primary; - uint8_t br_secondary; - uint8_t br_nsp; - uint16_t primary; - uint16_t secondary; - uint16_t nsp; - uint64_t sensor_mask; + char version[40]; /**< Opaque version string */ + uint8_t flags; /**< Version flags */ + uint8_t br_primary; /**< Branch id of primary bootloader */ + uint8_t br_secondary; /**< Branch id of secondary bootloader */ + uint8_t br_nsp; /**< Branch id of NSP */ + uint16_t primary; /**< Version of primary bootloader */ + uint16_t secondary; /**< Version id of secondary bootloader */ + uint16_t nsp; /**< Version id of NSP */ + uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 51dcf24f5f..e32884e7d3 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -263,7 +263,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) goto err; } - /* The NFP3800 NIC support 8 ports, but only 2 ports are valid, + /* + * The NFP3800 NIC support 8 ports, but only 2 ports are valid, * the rest 6 ports mac are all 0, ensure we don't use these port */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { @@ -273,7 +274,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) cnt++; } - /* Some versions of flash will give us 0 instead of port count. For + /* + * Some versions of flash will give us 0 instead of port count. For * those that give a port count, verify it against the value calculated * above. */ @@ -311,14 +313,16 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) return NULL; } -/* - * nfp_eth_read_ports() - retrieve port information - * @cpp: NFP CPP handle +/** + * Read the port information from the device. + * + * Returned structure should be freed once no longer needed. * - * Read the port information from the device. Returned structure should - * be freed with kfree() once no longer needed. + * @param cpp + * NFP CPP handle * - * Return: populated ETH table or NULL on error. + * @return + * Populated ETH table or NULL on error. */ struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) @@ -386,19 +390,19 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) free(entries); } -/* - * nfp_eth_config_commit_end() - perform recorded configuration changes - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * +/** * Perform the configuration which was requested with __nfp_eth_set_*() - * helpers and recorded in @nsp state. If device was already configured - * as requested or no __nfp_eth_set_*() operations were made no NSP command + * helpers and recorded in @nsp state. If device was already configured + * as requested or no __nfp_eth_set_*() operations were made, no NSP command * will be performed. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_config_commit_end(struct nfp_nsp *nsp) @@ -416,19 +420,21 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) return ret; } -/* - * nfp_eth_set_mod_enable() - set PHY module enable control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @enable: Desired state - * +/** * Enable or disable PHY module (this usually means setting the TX lanes * disable bits). * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param enable + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, @@ -459,18 +465,20 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * nfp_eth_set_configured() - set PHY module configured control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @configed: Desired state - * +/** * Set the ifup/ifdown state on the PHY. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param configured + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_configured(struct nfp_cpp *cpp, @@ -524,7 +532,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, /* * Note: set features were added in ABI 0.14 but the error - * codes were initially not populated correctly. + * codes were initially not populated correctly. */ if (nfp_nsp_get_abi_ver_minor(nsp) < 17) { PMD_DRV_LOG(ERR, "set operations not supported, please update flash"); @@ -554,15 +562,17 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, val, ctrl_bit); \ })) -/* - * __nfp_eth_set_aneg() - set PHY autonegotiation control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired autonegotiation mode - * +/** * Allow/disallow PHY module to advertise/perform autonegotiation. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired autonegotiation mode + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, @@ -572,15 +582,17 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } -/* - * __nfp_eth_set_fec() - set PHY forward error correction control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired fec mode - * +/** * Set the PHY module forward error correction mode. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired fec mode + * + * @return + * 0 or -ERRNO */ static int __nfp_eth_set_fec(struct nfp_nsp *nsp, @@ -590,16 +602,20 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } -/* - * nfp_eth_set_fec() - set PHY forward error correction control mode - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @mode: Desired fec mode +/** + * Set PHY forward error correction control mode + * + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param mode + * Desired fec mode * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_fec(struct nfp_cpp *cpp, @@ -622,17 +638,19 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * __nfp_eth_set_speed() - set interface speed/rate - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @speed: Desired speed (per lane) - * - * Set lane speed. Provided @speed value should be subport speed divided - * by number of lanes this subport is spanning (i.e. 10000 for 40G, 25000 for - * 50G, etc.) +/** + * Set lane speed. + * Provided @speed value should be subport speed divided by number of + * lanes this subport is spanning (i.e. 10000 for 40G, 25000 for 50G, etc.) * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param speed + * Desired speed (per lane) + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, @@ -650,15 +668,17 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } -/* - * __nfp_eth_set_split() - set interface lane split - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @lanes: Desired lanes per port - * +/** * Set number of lanes in the port. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param lanes + * Desired lanes per port + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_split(struct nfp_nsp *nsp, diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 363f7d6198..bdebf5c3aa 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -22,32 +22,23 @@ #define NFP_RESOURCE_ENTRY_NAME_SZ 8 -/* - * struct nfp_resource_entry - Resource table entry - * @owner: NFP CPP Lock, interface owner - * @key: NFP CPP Lock, posix_crc32(name, 8) - * @region: Memory region descriptor - * @name: ASCII, zero padded name - * @reserved - * @cpp_action: CPP Action - * @cpp_token: CPP Token - * @cpp_target: CPP Target ID - * @page_offset: 256-byte page offset into target's CPP address - * @page_size: size, in 256-byte pages - */ +/* Resource table entry */ struct nfp_resource_entry { struct nfp_resource_entry_mutex { - uint32_t owner; - uint32_t key; + uint32_t owner; /**< NFP CPP Lock, interface owner */ + uint32_t key; /**< NFP CPP Lock, posix_crc32(name, 8) */ } mutex; + /* Memory region descriptor */ struct nfp_resource_entry_region { + /** ASCII, zero padded name */ uint8_t name[NFP_RESOURCE_ENTRY_NAME_SZ]; uint8_t reserved[5]; - uint8_t cpp_action; - uint8_t cpp_token; - uint8_t cpp_target; + uint8_t cpp_action; /**< CPP Action */ + uint8_t cpp_token; /**< CPP Token */ + uint8_t cpp_target; /**< CPP Target ID */ + /** 256-byte page offset into target's CPP address */ uint32_t page_offset; - uint32_t page_size; + uint32_t page_size; /**< Size, in 256-byte pages */ } region; }; @@ -147,14 +138,18 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, return err; } -/* - * nfp_resource_acquire() - Acquire a resource handle - * @cpp: NFP CPP handle - * @name: Name of the resource +/** + * Acquire a resource handle + * + * Note: This function locks the acquired resource. * - * NOTE: This function locks the acquired resource + * @param cpp + * NFP CPP handle + * @param name + * Name of the resource * - * Return: NFP Resource handle, or NULL + * @return + * NFP Resource handle, or NULL */ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, @@ -183,7 +178,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, } wait.tv_sec = 0; - wait.tv_nsec = 1000000; + wait.tv_nsec = 1000000; /* 1ms */ for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); @@ -194,7 +189,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, goto err_free; } - if (count++ > 1000) { + if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); err = -EBUSY; goto err_free; @@ -213,11 +208,13 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_resource_release() - Release a NFP Resource handle - * @res: NFP Resource handle +/** + * Release a NFP Resource handle * - * NOTE: This function implicitly unlocks the resource handle + * NOTE: This function implicitly unlocks the resource handle. + * + * @param res + * NFP Resource handle */ void nfp_resource_release(struct nfp_resource *res) @@ -227,11 +224,14 @@ nfp_resource_release(struct nfp_resource *res) free(res); } -/* - * nfp_resource_cpp_id() - Return the cpp_id of a resource handle - * @res: NFP Resource handle +/** + * Return the cpp_id of a resource handle + * + * @param res + * NFP Resource handle * - * Return: NFP CPP ID + * @return + * NFP CPP ID */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res) @@ -239,11 +239,14 @@ nfp_resource_cpp_id(const struct nfp_resource *res) return res->cpp_id; } -/* - * nfp_resource_name() - Return the name of a resource handle - * @res: NFP Resource handle +/** + * Return the name of a resource handle * - * Return: const char pointer to the name of the resource + * @param res + * NFP Resource handle + * + * @return + * Const char pointer to the name of the resource */ const char * nfp_resource_name(const struct nfp_resource *res) @@ -251,11 +254,14 @@ nfp_resource_name(const struct nfp_resource *res) return res->name; } -/* - * nfp_resource_address() - Return the address of a resource handle - * @res: NFP Resource handle +/** + * Return the address of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Address of the resource + * @return + * Address of the resource */ uint64_t nfp_resource_address(const struct nfp_resource *res) @@ -263,11 +269,14 @@ nfp_resource_address(const struct nfp_resource *res) return res->addr; } -/* - * nfp_resource_size() - Return the size in bytes of a resource handle - * @res: NFP Resource handle +/** + * Return the size in bytes of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Size of the resource in bytes + * @return + * Size of the resource in bytes */ uint64_t nfp_resource_size(const struct nfp_resource *res) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 009b7359a4..4236950caf 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -8,43 +8,27 @@ #include "nfp_cpp.h" +/* Netronone Flow Firmware Table */ #define NFP_RESOURCE_NFP_NFFW "nfp.nffw" + +/* NFP Hardware Info Database */ #define NFP_RESOURCE_NFP_HWINFO "nfp.info" + +/* Service Processor */ #define NFP_RESOURCE_NSP "nfp.sp" -/** - * Opaque handle to a NFP Resource - */ +/* Opaque handle to a NFP Resource */ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, const char *name); -/** - * Release a NFP Resource, and free the handle - * @param[in] res NFP Resource handle - */ void nfp_resource_release(struct nfp_resource *res); -/** - * Return the CPP ID of a NFP Resource - * @param[in] res NFP Resource handle - * @return CPP ID of the NFP Resource - */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res); -/** - * Return the name of a NFP Resource - * @param[in] res NFP Resource handle - * @return Name of the NFP Resource - */ const char *nfp_resource_name(const struct nfp_resource *res); -/** - * Return the target address of a NFP Resource - * @param[in] res NFP Resource handle - * @return Address of the NFP Resource - */ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index d15a920752..0e6c0f9fe1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -162,11 +162,14 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_rtsym_count() - Get the number of RTSYM descriptors - * @rtbl: NFP RTsym table +/** + * Get the number of RTSYM descriptors + * + * @param rtbl + * NFP RTSYM table * - * Return: Number of RTSYM descriptors + * @return + * Number of RTSYM descriptors */ int nfp_rtsym_count(struct nfp_rtsym_table *rtbl) @@ -177,12 +180,16 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) return rtbl->num; } -/* - * nfp_rtsym_get() - Get the Nth RTSYM descriptor - * @rtbl: NFP RTsym table - * @idx: Index (0-based) of the RTSYM descriptor +/** + * Get the Nth RTSYM descriptor + * + * @param rtbl + * NFP RTSYM table + * @param idx + * Index (0-based) of the RTSYM descriptor * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_get(struct nfp_rtsym_table *rtbl, @@ -197,12 +204,16 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, return &rtbl->symtab[idx]; } -/* - * nfp_rtsym_lookup() - Return the RTSYM descriptor for a symbol name - * @rtbl: NFP RTsym table - * @name: Symbol name +/** + * Return the RTSYM descriptor for a symbol name + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, @@ -227,7 +238,8 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_NONE: PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; - case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ + case NFP_RTSYM_TYPE_OBJECT: + /* FALLTHROUGH */ case NFP_RTSYM_TYPE_FUNCTION: return sym->size; case NFP_RTSYM_TYPE_ABS: @@ -327,17 +339,22 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } -/* - * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol - * @rtbl: NFP RTsym table - * @name: Symbol name - * @error: Pointer to error code (optional) +/** + * Read a simple unsigned scalar value from symbol * * Lookup a symbol, map, read it and return it's value. Value of the symbol * will be interpreted as a simple little-endian unsigned value. Symbol can * be 4 or 8 bytes in size. * - * Return: value read, on error sets the error and returns ~0ULL. + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param error + * Pointer to error code (optional) + * + * @return + * Value read, on error sets the error and returns ~0ULL. */ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index e7295258b3..ff1facbd17 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -31,12 +31,12 @@ * of "sram" symbols for backward compatibility, which are viewed as global. */ struct nfp_rtsym { - const char *name; - uint64_t addr; - uint64_t size; - int type; - int target; - int domain; + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + int type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ }; struct nfp_rtsym_table; diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 611848e233..540b242a43 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -767,7 +767,7 @@ nfp_encode_basic(uint64_t *addr, /* * Make sure we compare against isldN values by clearing the * LSB. This is what the silicon does. - **/ + */ isld[0] &= ~1; isld[1] &= ~1; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 08/27] net/nfp: using the DPDK memory management API 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (6 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 07/27] net/nfp: standard the comment style Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 09/27] net/nfp: standard the blank character Chaoyong He ` (19 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Revise the logic, using the DPDK memory management API to replace the malloc()/free(). Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_mip.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_mutex.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +++----- drivers/net/nfp/nfpcore/nfp_nsp.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +++----- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 19 ++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 10 ++++------ 11 files changed, 39 insertions(+), 48 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 77dab864f3..37895e8355 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -225,7 +225,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); + rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); rte_free(app_fw_flower); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e3ff3d8087..2e43055fd5 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -47,7 +47,7 @@ nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic, int port) rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->mac_addr); - free(nfp_eth_table); + rte_free(nfp_eth_table); return 0; } @@ -312,7 +312,7 @@ nfp_net_close(struct rte_eth_dev *dev) PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); + rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); rte_free(app_fw_nic); @@ -1047,9 +1047,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) sym_tbl_cleanup: free(sym_tbl); eth_table_cleanup: - free(nfp_eth_table); + rte_free(nfp_eth_table); hwinfo_cleanup: - free(hwinfo); + rte_free(hwinfo); cpp_cleanup: nfp_cpp_free(cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f601907673..1e0608a8e4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -866,7 +866,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, if (ops == NULL || ops->init == NULL) return NULL; - cpp = calloc(1, sizeof(*cpp)); + cpp = rte_zmalloc(NULL, sizeof(*cpp), 0); if (cpp == NULL) return NULL; @@ -876,7 +876,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, if (cpp->op->init) { err = cpp->op->init(cpp, dev); if (err < 0) { - free(cpp); + rte_free(cpp); return NULL; } } @@ -891,7 +891,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, err = nfp_xpb_readl(cpp, xpbaddr, (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { - free(cpp); + rte_free(cpp); return NULL; } } @@ -900,7 +900,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); - free(cpp); + rte_free(cpp); return NULL; } @@ -922,7 +922,7 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->serial_len != 0) free(cpp->serial); - free(cpp); + rte_free(cpp); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index f5579ab60f..7abf9c7700 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -109,7 +109,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - db = malloc(*cpp_size + 1); + db = rte_zmalloc(NULL, *cpp_size + 1, 0); if (db == NULL) return NULL; @@ -134,7 +134,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, return (void *)db; exit_free: - free(db); + rte_free(db); return NULL; } @@ -175,7 +175,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) err = nfp_hwinfo_db_validate(db, hwdb_size); if (err != 0) { - free(db); + rte_free(db); return NULL; } return db; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0892c99e96..3c59582846 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -104,14 +104,14 @@ nfp_mip_open(struct nfp_cpp *cpp) int err; struct nfp_mip *mip; - mip = malloc(sizeof(*mip)); + mip = rte_zmalloc(NULL, sizeof(*mip), 0); if (mip == NULL) return NULL; err = nfp_mip_read_resource(cpp, mip); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to read MIP resource"); - free(mip); + rte_free(mip); return NULL; } @@ -123,7 +123,7 @@ nfp_mip_open(struct nfp_cpp *cpp) void nfp_mip_close(struct nfp_mip *mip) { - free(mip); + rte_free(mip); } const char * diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 404d4fa938..5392924cf0 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -163,7 +163,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, if (tmp != key) return NULL; - mutex = calloc(sizeof(*mutex), 1); + mutex = rte_zmalloc(NULL, sizeof(*mutex), 0); if (mutex == NULL) return NULL; @@ -209,7 +209,7 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) if (mutex->cpp && mutex == mutex->cpp->mutex_cache) mutex->cpp->mutex_cache = mutex->next; - free(mutex); + rte_free(mutex); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index af55671a88..a635239b30 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -128,12 +128,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) struct nfp_nffw_info *state; struct nfp_nffw_info_data *fwinf; - state = malloc(sizeof(*state)); + state = rte_zmalloc(NULL, sizeof(*state), 0); if (state == NULL) return NULL; - memset(state, 0, sizeof(*state)); - state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); if (state->res == NULL) { PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); @@ -166,7 +164,7 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err_release: nfp_resource_release(state->res); err_free: - free(state); + rte_free(state); return NULL; } @@ -180,7 +178,7 @@ void nfp_nffw_info_close(struct nfp_nffw_info *state) { nfp_resource_release(state->res); - free(state); + rte_free(state); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 039e4729bd..dd2d19936d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -128,12 +128,12 @@ nfp_nsp_open(struct nfp_cpp *cpp) return NULL; } - state = malloc(sizeof(*state)); + state = rte_zmalloc(NULL, sizeof(*state), 0); if (state == NULL) { nfp_resource_release(res); return NULL; } - memset(state, 0, sizeof(*state)); + state->cpp = cpp; state->res = res; @@ -157,7 +157,7 @@ void nfp_nsp_close(struct nfp_nsp *state) { nfp_resource_release(state->res); - free(state); + rte_free(state); } uint16_t diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 3081e22dad..54e1e2215d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -33,22 +33,20 @@ __nfp_nsp_identify(struct nfp_nsp *nsp) if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; - ni = malloc(sizeof(*ni)); + ni = rte_zmalloc(NULL, sizeof(*ni), 0); if (ni == NULL) return NULL; - memset(ni, 0, sizeof(*ni)); ret = nfp_nsp_read_identify(nsp, ni, sizeof(*ni)); if (ret < 0) { PMD_DRV_LOG(ERR, "reading bsp version failed %d", ret); goto exit_free; } - nspi = malloc(sizeof(*nspi)); + nspi = rte_zmalloc(NULL, sizeof(*nspi), 0); if (nspi == NULL) goto exit_free; - memset(nspi, 0, sizeof(*nspi)); memcpy(nspi->version, ni->version, sizeof(nspi->version)); nspi->version[sizeof(nspi->version) - 1] = '\0'; nspi->flags = ni->flags; @@ -61,7 +59,7 @@ __nfp_nsp_identify(struct nfp_nsp *nsp) nspi->sensor_mask = rte_le_to_cpu_64(ni->sensor_mask); exit_free: - free(ni); + rte_free(ni); return nspi; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index e32884e7d3..1906fcd385 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -252,11 +252,10 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; const struct rte_ether_addr *mac; - entries = malloc(NSP_ETH_TABLE_SIZE); + entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) return NULL; - memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); @@ -286,11 +285,10 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } table_sz = sizeof(*table) + sizeof(struct nfp_eth_table_port) * cnt; - table = malloc(table_sz); + table = rte_zmalloc(NULL, table_sz, 0); if (table == NULL) goto err; - memset(table, 0, table_sz); table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; @@ -304,12 +302,12 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); - free(entries); + rte_free(entries); return table; err: - free(entries); + rte_free(entries); return NULL; } @@ -348,14 +346,13 @@ nfp_eth_config_start(struct nfp_cpp *cpp, struct nfp_nsp *nsp; union eth_table_entry *entries; - entries = malloc(NSP_ETH_TABLE_SIZE); + entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) return NULL; - memset(entries, 0, NSP_ETH_TABLE_SIZE); nsp = nfp_nsp_open(cpp); if (nsp == NULL) { - free(entries); + rte_free(entries); return nsp; } @@ -375,7 +372,7 @@ nfp_eth_config_start(struct nfp_cpp *cpp, err: nfp_nsp_close(nsp); - free(entries); + rte_free(entries); return NULL; } @@ -387,7 +384,7 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) nfp_nsp_config_set_modified(nsp, 0); nfp_nsp_config_clear_state(nsp); nfp_nsp_close(nsp); - free(entries); + rte_free(entries); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index bdebf5c3aa..8ba3784f8a 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -161,19 +161,17 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; struct nfp_cpp_mutex *dev_mutex; - res = malloc(sizeof(*res)); + res = rte_zmalloc(NULL, sizeof(*res), 0); if (res == NULL) return NULL; - memset(res, 0, sizeof(*res)); - strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - free(res); + rte_free(res); return NULL; } @@ -204,7 +202,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err_free: nfp_cpp_mutex_free(dev_mutex); - free(res); + rte_free(res); return NULL; } @@ -221,7 +219,7 @@ nfp_resource_release(struct nfp_resource *res) { nfp_cpp_mutex_unlock(res->mutex); nfp_cpp_mutex_free(res->mutex); - free(res); + rte_free(res); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 09/27] net/nfp: standard the blank character 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (7 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 08/27] net/nfp: using the DPDK memory management API Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 10/27] net/nfp: unify the guide line of header file Chaoyong He ` (18 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Use space character to align instead of TAB character. There should one blank line to split the block of logic, no more no less. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 18 +-- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 17 ++- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 - drivers/net/nfp/nfpcore/nfp_hwinfo.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.h | 45 ++++--- drivers/net/nfp/nfpcore/nfp_mip.c | 9 +- drivers/net/nfp/nfpcore/nfp_mip.h | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 17 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 3 + drivers/net/nfp/nfpcore/nfp_nsp.h | 105 ++++++++-------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 132 ++++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 18 +-- drivers/net/nfp/nfpcore/nfp_rtsym.c | 16 +-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 1 + 17 files changed, 204 insertions(+), 195 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index 7750a0218e..efaa87c0e5 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -15,8 +15,8 @@ #define NFP_CPP_TARGET_PCIE 9 #define NFP_CPP_TARGET_ARM 10 #define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ #define NFP_CPP_TARGET_CT_XPB 14 #define NFP_CPP_TARGET_LOCAL_SCRATCH 15 #define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 82189e9910..92cae2557a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -80,16 +80,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_acquire)(struct nfp_cpp_area *area); + /* * Release resources for a NFP CPP area * Serialized */ void (*area_release)(struct nfp_cpp_area *area); + /* * Return a void IO pointer to a NFP CPP area * NOTE: This is _not_ serialized */ - void *(*area_iomem)(struct nfp_cpp_area *area); /* @@ -280,7 +281,7 @@ void nfp_cpp_free(struct nfp_cpp *cpp); * @return * true if model is in the NFP6000 family, false otherwise. */ -#define NFP_CPP_MODEL_IS_6000(model) \ +#define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) @@ -290,11 +291,11 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * NFP Interface types - logical interface for this CPP connection 4 bits are * reserved for interface type. */ -#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 -#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 -#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 -#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 -#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 +#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 +#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 +#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 +#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 +#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 /** * Construct a 16-bit NFP Interface ID @@ -316,7 +317,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * @return * Interface ID */ -#define NFP_CPP_INTERFACE(type, unit, channel) \ +#define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) @@ -354,7 +355,6 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) - uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 7e94bfb611..28a6278497 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -37,7 +37,7 @@ #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" -#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) +#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -93,7 +93,7 @@ struct nfp_bar { char *iomem; /**< mapped IO memory */ }; -#define BUSDEV_SZ 13 +#define BUSDEV_SZ 13 struct nfp_pcie_user { struct nfp_bar bar[NFP_BAR_MAX]; @@ -163,7 +163,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); @@ -171,7 +170,6 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); @@ -179,7 +177,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 21; } @@ -278,6 +275,7 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; bar->barcfg = 0; @@ -310,6 +308,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; if (bar->lock == 0) { @@ -317,6 +316,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) return bar; } } + return NULL; } @@ -346,7 +346,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } /* Generic CPP bus access interface. */ - struct nfp6000_area_priv { struct nfp_bar *bar; uint32_t bar_offset; @@ -443,6 +442,7 @@ static void nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + priv->bar->lock = 0; priv->bar = NULL; priv->iomem = NULL; @@ -478,7 +478,6 @@ nfp6000_area_read(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.read; - if (width <= 0) return -EINVAL; @@ -548,7 +547,6 @@ nfp6000_area_write(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.write; - if (width <= 0) return -EINVAL; @@ -718,6 +716,7 @@ nfp6000_set_barsz(struct rte_pci_device *dev, i++; desc->barsz = i; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 1e0608a8e4..fa199e80d3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -433,7 +433,6 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) { if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) { PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; @@ -862,7 +861,6 @@ nfp_cpp_alloc(struct rte_pci_device *dev, const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); - if (ops == NULL || ops->init == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 7abf9c7700..cee37210b0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -54,6 +54,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, return -EINVAL; } } + return 0; } @@ -178,6 +179,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) rte_free(db); return NULL; } + return db; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 424db8035d..37427bb6c8 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -8,33 +8,31 @@ #include <inttypes.h> -#define HWINFO_SIZE_MIN 0x100 +#define HWINFO_SIZE_MIN 0x100 /* * The Hardware Info Table defines the properties of the system. * * HWInfo v1 Table (fixed size) * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value - * table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * HWInfo v2 Table (variable size) * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding - * CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * If the HWInfo table is in the process of being updated, the low bit of * version will be set. @@ -47,17 +45,16 @@ * * All keys are guaranteed to be unique. * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value * ... * * HWInfo v2 Key/Value Table * ------------------------- * * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * * Unsorted. * * Note: Only the HwInfo v2 Table be supported now. @@ -65,7 +62,7 @@ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) #define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) struct nfp_hwinfo { uint8_t start[0]; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 3c59582846..f6f07ac739 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -11,9 +11,9 @@ #include "nfp_mip.h" #include "nfp_nffw.h" -#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -#define NFP_MIP_VERSION rte_cpu_to_le_32(1) -#define NFP_MIP_MAX_OFFSET (256 * 1024) +#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ +#define NFP_MIP_VERSION rte_cpu_to_le_32(1) +#define NFP_MIP_MAX_OFFSET (256 * 1024) struct nfp_mip { uint32_t signature; @@ -49,11 +49,13 @@ nfp_mip_try_read(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } + if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } + if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); @@ -82,6 +84,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); + exit_close_nffw: nfp_nffw_info_close(nffw_info); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 980abc2517..16824a6769 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -18,4 +18,5 @@ void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); + #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 5392924cf0..61c491e07e 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -85,7 +85,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, { int err; uint32_t model = nfp_cpp_model(cpp); - uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -134,7 +134,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint32_t tmp; struct nfp_cpp_mutex *mutex; uint32_t model = nfp_cpp_model(cpp); - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -231,12 +231,15 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) /* If err != -EBUSY, then the lock was damaged */ if (err < 0 && err != -EBUSY) return err; + if (time(NULL) >= warn_at) { PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } + sched_yield(); } + return 0; } @@ -257,8 +260,8 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) uint32_t value; struct nfp_cpp *cpp = mutex->cpp; uint16_t interface = nfp_cpp_interface(cpp); - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -314,9 +317,9 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) uint32_t tmp; uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index a635239b30..b14a9bd852 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -61,10 +61,10 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index dd2d19936d..9bb344aa5f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -290,6 +290,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_cpp_readq(cpp, nsp_cpp, nsp_command, &ret_val); if (err < 0) return err; + ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); @@ -354,6 +355,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, if (err < 0) return err; } + /* Zero out remaining part of the buffer */ if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); @@ -400,6 +402,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 0fcb21e99c..ee58bf33b8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -10,73 +10,72 @@ #include "nfp_nsp.h" #define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) + (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) #define __bf_shf(x) (__builtin_ffsll(x) - 1) -#define FIELD_GET(_mask, _reg) \ +#define FIELD_GET(_mask, _reg) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ })) -#define FIELD_FIT(_mask, _val) \ +#define FIELD_FIT(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ })) -#define FIELD_PREP(_mask, _val) \ +#define FIELD_PREP(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ })) /* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_START RTE_BIT64(0) /* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) -#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER 0x18 -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) +#define NSP_CODE_MAJOR GENMASK(15, 12) +#define NSP_CODE_MINOR GENMASK(11, 0) enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ }; static const struct { @@ -123,13 +122,13 @@ nfp_nsp_has_mac_reinit(struct nfp_nsp *state) } enum nfp_eth_interface { - NFP_INTERFACE_NONE = 0, - NFP_INTERFACE_SFP = 1, - NFP_INTERFACE_SFPP = 10, - NFP_INTERFACE_SFP28 = 28, - NFP_INTERFACE_QSFP = 40, - NFP_INTERFACE_CXP = 100, - NFP_INTERFACE_QSFP28 = 112, + NFP_INTERFACE_NONE = 0, + NFP_INTERFACE_SFP = 1, + NFP_INTERFACE_SFPP = 10, + NFP_INTERFACE_SFP28 = 28, + NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_CXP = 100, + NFP_INTERFACE_QSFP28 = 112, }; enum nfp_eth_media { @@ -153,10 +152,10 @@ enum nfp_eth_fec { NFP_FEC_DISABLED_BIT, }; -#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) -#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) -#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) -#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) +#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) +#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) +#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) +#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) /* ETH table information */ struct nfp_eth_table { diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 54e1e2215d..08f12f862c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -105,5 +105,6 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, default: return -EINVAL; } + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 1906fcd385..837c9c6bbd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,70 +11,68 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define NSP_ETH_NBI_PORT_COUNT 24 -#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) -#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ - sizeof(union eth_table_entry)) - -#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) -#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) -#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) -#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) -#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) -#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) - -#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) - -#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) -#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) -#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) -#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) -#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) -#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) -#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) - -#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) -#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) -#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) -#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) -#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) +#define NSP_ETH_NBI_PORT_COUNT 24 +#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) +#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * sizeof(union eth_table_entry)) + +#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) +#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) +#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) +#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) +#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) +#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) + +#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) + +#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) +#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) +#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) +#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) +#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) +#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) +#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) + +#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) +#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) +#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) +#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) +#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) /* Which connector port. */ -#define PORT_TP 0x00 -#define PORT_AUI 0x01 -#define PORT_MII 0x02 -#define PORT_FIBRE 0x03 -#define PORT_BNC 0x04 -#define PORT_DA 0x05 -#define PORT_NONE 0xef -#define PORT_OTHER 0xff - -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 +#define PORT_TP 0x00 +#define PORT_AUI 0x01 +#define PORT_MII 0x02 +#define PORT_FIBRE 0x03 +#define PORT_BNC 0x04 +#define PORT_DA 0x05 +#define PORT_NONE 0xef +#define PORT_OTHER 0xff + +#define SPEED_10 10 +#define SPEED_100 100 +#define SPEED_1000 1000 +#define SPEED_2500 2500 +#define SPEED_5000 5000 +#define SPEED_10000 10000 +#define SPEED_14000 14000 +#define SPEED_20000 20000 +#define SPEED_25000 25000 +#define SPEED_40000 40000 +#define SPEED_50000 50000 +#define SPEED_56000 56000 +#define SPEED_100000 100000 enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW }; @@ -102,12 +100,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, 0, }, + { RATE_10M, SPEED_10, }, + { RATE_100M, SPEED_100, }, + { RATE_1G, SPEED_1000, }, + { RATE_10G, SPEED_10000, }, + { RATE_25G, SPEED_25000, }, }; static uint32_t @@ -211,10 +209,12 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) if (table->ports[i].label_port != table->ports[j].label_port) continue; + table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; + if (table->ports[i].label_subport == table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", @@ -552,11 +552,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, return 0; } -#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ - (__extension__ ({ \ - typeof(mask) _x = (mask); \ +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ + (__extension__ ({ \ + typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 8ba3784f8a..e7e232eb4e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -13,14 +13,14 @@ #include "nfp_resource.h" #include "nfp_crc.h" -#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL +#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU +#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL /* NFP Resource Table self-identifier */ -#define NFP_RESOURCE_TBL_NAME "nfp.res" -#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ +#define NFP_RESOURCE_TBL_NAME "nfp.res" +#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ -#define NFP_RESOURCE_ENTRY_NAME_SZ 8 +#define NFP_RESOURCE_ENTRY_NAME_SZ 8 /* Resource table entry */ struct nfp_resource_entry { @@ -42,9 +42,9 @@ struct nfp_resource_entry { } region; }; -#define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ - sizeof(struct nfp_resource_entry)) +#define NFP_RESOURCE_TBL_SIZE 4096 +#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ + sizeof(struct nfp_resource_entry)) struct nfp_resource { char name[NFP_RESOURCE_ENTRY_NAME_SZ + 1]; @@ -75,6 +75,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Grabbing device lock not supported"); return -EOPNOTSUPP; } + key = nfp_crc32_posix(name_pad, NFP_RESOURCE_ENTRY_NAME_SZ); for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { @@ -96,6 +97,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 0e6c0f9fe1..37811ceaeb 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -17,18 +17,18 @@ #include "nfp6000/nfp6000.h" /* These need to match the linker */ -#define SYM_TGT_LMEM 0 -#define SYM_TGT_EMU_CACHE 0x17 +#define SYM_TGT_LMEM 0 +#define SYM_TGT_EMU_CACHE 0x17 struct nfp_rtsym_entry { - uint8_t type; - uint8_t target; - uint8_t island; - uint8_t addr_hi; + uint8_t type; + uint8_t target; + uint8_t island; + uint8_t addr_hi; uint32_t addr_lo; uint16_t name; - uint8_t menum; - uint8_t size_hi; + uint8_t menum; + uint8_t size_hi; uint32_t size_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index ff1facbd17..de1966f04b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -57,4 +57,5 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); + #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 10/27] net/nfp: unify the guide line of header file 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (8 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 09/27] net/nfp: standard the blank character Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 11/27] net/nfp: rename some parameter and variable Chaoyong He ` (17 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Unify the guide line of header file, we choose '__FOO_BAR_H__' style. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 2 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 +- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_resource.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- drivers/net/nfp/nfpcore/nfp_target.h | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 92cae2557a..ceb4d56a08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -442,4 +442,4 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); -#endif /* !__NFP_CPP_H__ */ +#endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 37427bb6c8..543562779a 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -81,4 +81,4 @@ struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup); -#endif +#endif /* __NFP_HWINFO_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 16824a6769..371c635b97 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -19,4 +19,4 @@ void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); -#endif +#endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index e032b6cce7..f84be463c4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -75,4 +75,4 @@ struct nfp_nffw_info { struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); -#endif +#endif /* __NFP_NFFW_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index ee58bf33b8..7bf584dcd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NSP_NSP_H -#define NSP_NSP_H 1 +#ifndef __NSP_NSP_H__ +#define __NSP_NSP_H__ #include "nfp_cpp.h" #include "nfp_nsp.h" @@ -260,4 +260,4 @@ enum nfp_nsp_sensor_id { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val); -#endif +#endif /* __NSP_NSP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 4236950caf..18196d273c 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NFP_RESOURCE_H -#define NFP_RESOURCE_H +#ifndef __NFP_RESOURCE_H__ +#define __NFP_RESOURCE_H__ #include "nfp_cpp.h" @@ -33,4 +33,4 @@ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); -#endif /* NFP_RESOURCE_H */ +#endif /* __NFP_RESOURCE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index de1966f04b..fdde1eb75b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -58,4 +58,4 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -#endif +#endif /* __NFP_RTSYM_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 195e599d31..2a2f083914 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -3,7 +3,7 @@ * All rights reserved. */ -#ifndef NFP_TARGET_H -#define NFP_TARGET_H +#ifndef __NFP_TARGET_H__ +#define __NFP_TARGET_H__ -#endif /* NFP_TARGET_H */ +#endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 11/27] net/nfp: rename some parameter and variable 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (9 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 10/27] net/nfp: unify the guide line of header file Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 12/27] net/nfp: refact the hwinfo module Chaoyong He ` (16 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Rename some parameter and variable to make the logic easier to understand. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 10 ++--- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 42 ++++++++--------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 52 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 20 ++++----- drivers/net/nfp/nfpcore/nfp_nffw.h | 4 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 8 ++-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 20 ++++----- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index ceb4d56a08..be7ae1d919 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -247,7 +247,7 @@ void *nfp_cpp_priv(struct nfp_cpp *cpp); void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); -uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); +uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, @@ -381,10 +381,10 @@ uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *buffer, size_t length); + void *address, size_t length); int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *buffer, size_t length); + const void *address, size_t length); void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); @@ -393,10 +393,10 @@ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, void *kernel_vaddr, size_t length); + uint64_t address, void *buf, size_t length); int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, const void *kernel_vaddr, size_t length); + uint64_t address, const void *buf, size_t length); int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 28a6278497..db15411eb2 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -118,9 +118,9 @@ static int nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, uint64_t *bar_base, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -129,7 +129,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (tgt >= 16) + if (target >= 16) return -EINVAL; switch (width) { @@ -149,15 +149,15 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; } - if (act != NFP_CPP_ACTION_RW && act != 0) { + if (action != NFP_CPP_ACTION_RW && action != 0) { /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(action); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -170,8 +170,8 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -221,9 +221,9 @@ nfp_bar_write(struct nfp_pcie_user *nfp, static int nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -232,8 +232,8 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, uint32_t newcfg; uint64_t newbase; - err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + err = nfp_compute_bar(bar, &newcfg, &newbase, target, action, + token, offset, size, width); if (err != 0) return err; @@ -457,15 +457,15 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, - void *kernel_vaddr, + void *address, uint32_t offset, size_t length) { size_t n; int width; bool is_64; - uint32_t *wrptr32 = kernel_vaddr; - uint64_t *wrptr64 = kernel_vaddr; + uint32_t *wrptr32 = address; + uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; const volatile uint32_t *rdptr32; const volatile uint64_t *rdptr64; @@ -526,7 +526,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, - const void *kernel_vaddr, + const void *address, uint32_t offset, size_t length) { @@ -536,8 +536,8 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; - const uint32_t *rdptr32 = kernel_vaddr; - const uint64_t *rdptr64 = kernel_vaddr; + const uint32_t *rdptr32 = address; + const uint64_t *rdptr64 = address; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index fa199e80d3..d8e57b9075 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -90,7 +90,7 @@ nfp_cpp_model(struct nfp_cpp *cpp) if (cpp == NULL) return NFP_CPP_MODEL_INVALID; - err = __nfp_cpp_model_autodetect(cpp, &model); + err = nfp_cpp_model_autodetect(cpp, &model); if (err < 0) return err; @@ -484,7 +484,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -498,13 +498,13 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *kernel_vaddr, + void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_read(area, kernel_vaddr, offset, length); + return area->cpp->op->area_read(area, address, offset, length); } /** @@ -514,7 +514,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -528,13 +528,13 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *kernel_vaddr, + const void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_write(area, kernel_vaddr, offset, length); + return area->cpp->op->area_write(area, address, offset, length); } /* @@ -880,14 +880,14 @@ nfp_cpp_alloc(struct rte_pci_device *dev, } if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpbaddr; - size_t tgt; + uint32_t xpb_addr; + size_t target; - for (tgt = 0; tgt < RTE_DIM(cpp->imb_cat_table); tgt++) { + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + (tgt * 4); - err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, + (uint32_t *)&cpp->imb_cat_table[target]); if (err < 0) { rte_free(cpp); return NULL; @@ -950,9 +950,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer for result * @param length * Number of bytes to read @@ -963,20 +963,20 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - void *kernel_vaddr, + uint64_t offset, + void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } - err = nfp_cpp_area_read(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_read(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -989,9 +989,9 @@ nfp_cpp_read(struct nfp_cpp *cpp, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer to read from * @param length * Number of bytes to write @@ -1002,20 +1002,20 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - const void *kernel_vaddr, + uint64_t offset, + const void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; } - err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_write(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -1026,7 +1026,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, +nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { int err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 371c635b97..7fa09ee575 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,6 +17,6 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 61c491e07e..85c33502ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,7 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint32_t model, int *target, uint64_t address) { @@ -87,7 +87,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return err; @@ -152,7 +152,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return NULL; } - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b14a9bd852..b27a9fbaa7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -31,11 +31,11 @@ nffw_res_flg_init_get(const struct nfp_nffw_info_data *res) return (res->flags[0] >> 0) & 1; } -/* loaded = loaded__mu_da__mip_off_hi<31:31> */ +/* loaded = loaded_mu_da_mip_off_hi<31:31> */ static uint32_t nffw_fwinfo_loaded_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 31) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 31) & 1; } /* mip_cppid = mip_cppid */ @@ -45,18 +45,18 @@ nffw_fwinfo_mip_cppid_get(const struct nffw_fwinfo *fi) return fi->mip_cppid; } -/* loaded = loaded__mu_da__mip_off_hi<8:8> */ +/* loaded = loaded_mu_da_mip_off_hi<8:8> */ static uint32_t nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ +/* mip_offset = (loaded_mu_da_mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { - uint64_t mip_off_hi = fi->loaded__mu_da__mip_off_hi; + uint64_t mip_off_hi = fi->loaded_mu_da_mip_off_hi; return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } @@ -224,7 +224,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) + uint64_t *offset) { struct nffw_fwinfo *fwinfo; @@ -233,7 +233,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, return -EINVAL; *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); - *off = nffw_fwinfo_mip_offset_get(fwinfo); + *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; @@ -245,8 +245,8 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, if (locality_off < 0) return locality_off; - *off &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); - *off |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; + *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); + *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; } return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index f84be463c4..52e25c090a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -38,11 +38,11 @@ /* nfp.nffw meinfo */ struct nffw_meinfo { - uint32_t ctxmask__fwid__meid; + uint32_t ctxmask_fwid_meid; }; struct nffw_fwinfo { - uint32_t loaded__mu_da__mip_off_hi; + uint32_t loaded_mu_da_mip_off_hi; uint32_t mip_cppid; /* 0 means no MIP */ uint32_t mip_offset_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 7bf584dcd0..705574b900 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -231,9 +231,9 @@ struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); -int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); +int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); +int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /* NSP static information */ struct nfp_nsp_identify { @@ -248,7 +248,7 @@ struct nfp_nsp_identify { uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; -struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); +struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp); enum nfp_nsp_sensor_id { NFP_SENSOR_CHIP_TEMPERATURE, diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 08f12f862c..429f639fa2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -24,7 +24,7 @@ struct nsp_identify { }; struct nfp_nsp_identify * -__nfp_nsp_identify(struct nfp_nsp *nsp) +nfp_nsp_identify(struct nfp_nsp *nsp) { int ret; struct nsp_identify *ni; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 837c9c6bbd..eea5cde426 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -241,7 +241,7 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) } static struct nfp_eth_table * -__nfp_eth_read_ports(struct nfp_nsp *nsp) +nfp_eth_read_ports_real(struct nfp_nsp *nsp) { int ret; uint32_t i; @@ -332,7 +332,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) if (nsp == NULL) return NULL; - ret = __nfp_eth_read_ports(nsp); + ret = nfp_eth_read_ports_real(nsp); nfp_nsp_close(nsp); return ret; @@ -480,7 +480,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configed) + int configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -503,10 +503,10 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, /* Check if we are already in requested state */ reg = rte_le_to_cpu_64(entries[idx].state); - if (configed != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { + if (configured != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { reg = rte_le_to_cpu_64(entries[idx].control); reg &= ~NSP_ETH_CTRL_CONFIGURED; - reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configed); + reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); nfp_nsp_config_set_modified(nsp, 1); @@ -572,7 +572,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, +nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -592,7 +592,7 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, * 0 or -ERRNO */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, +nfp_eth_set_fec_real(struct nfp_nsp *nsp, enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -626,7 +626,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, if (nsp == NULL) return -EIO; - err = __nfp_eth_set_fec(nsp, mode); + err = nfp_eth_set_fec_real(nsp, mode); if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; @@ -650,7 +650,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, * 0 or -ERRNO */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, +nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed) { enum nfp_eth_rate rate; @@ -678,7 +678,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, +nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 12/27] net/nfp: refact the hwinfo module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (10 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 11/27] net/nfp: rename some parameter and variable Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 13/27] net/nfp: refact the nffw module Chaoyong He ` (15 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the definition of data structure and macro into the implement file. Also remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 84 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 71 +---------------------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index cee37210b0..25c2262dfc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -17,17 +17,82 @@ * (ie, in this example, ME 39 has been reserved by boardconfig.) */ -#include <stdio.h> -#include <time.h> +#include "nfp_hwinfo.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" -#include "nfp_hwinfo.h" -#include "nfp_crc.h" -static int +#define HWINFO_SIZE_MIN 0x100 + +/* + * The Hardware Info Table defines the properties of the system. + * + * HWInfo v1 Table (fixed size) + * + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * HWInfo v2 Table (variable size) + * + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * If the HWInfo table is in the process of being updated, the low bit of + * version will be set. + * + * HWInfo v1 Key/Value Table + * ------------------------- + * + * The key/value table is a set of offsets to ASCIIZ strings which have + * been strcmp(3) sorted (yes, please use bsearch(3) on the table). + * + * All keys are guaranteed to be unique. + * + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value + * ... + * + * HWInfo v2 Key/Value Table + * ------------------------- + * + * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' + * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. + */ + +#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) + +struct nfp_hwinfo { + uint8_t start[0]; + + uint32_t version; + uint32_t size; + + /* V2 specific fields */ + uint32_t limit; + uint32_t resv; + + char data[]; +}; + +static bool nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) { return hwinfo->version & NFP_HWINFO_VERSION_UPDATING; @@ -120,7 +185,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, goto exit_free; } - header = (void *)db; + header = (struct nfp_hwinfo *)db; if (nfp_hwinfo_is_updating(header)) goto exit_free; @@ -133,7 +198,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, /* NULL-terminate for safety */ db[*cpp_size] = '\0'; - return (void *)db; + return (struct nfp_hwinfo *)db; + exit_free: rte_free(db); return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 543562779a..c812f10076 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -6,76 +6,9 @@ #ifndef __NFP_HWINFO_H__ #define __NFP_HWINFO_H__ -#include <inttypes.h> +#include "nfp_cpp.h" -#define HWINFO_SIZE_MIN 0x100 - -/* - * The Hardware Info Table defines the properties of the system. - * - * HWInfo v1 Table (fixed size) - * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * HWInfo v2 Table (variable size) - * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * If the HWInfo table is in the process of being updated, the low bit of - * version will be set. - * - * HWInfo v1 Key/Value Table - * ------------------------- - * - * The key/value table is a set of offsets to ASCIIZ strings which have - * been strcmp(3) sorted (yes, please use bsearch(3) on the table). - * - * All keys are guaranteed to be unique. - * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value - * ... - * - * HWInfo v2 Key/Value Table - * ------------------------- - * - * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * Unsorted. - * - * Note: Only the HwInfo v2 Table be supported now. - */ - -#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) - -struct nfp_hwinfo { - uint8_t start[0]; - - uint32_t version; - uint32_t size; - - /* v2 specific fields */ - uint32_t limit; - uint32_t resv; - - char data[]; -}; +struct nfp_hwinfo; struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 13/27] net/nfp: refact the nffw module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (11 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 12/27] net/nfp: refact the hwinfo module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 14/27] net/nfp: refact the mip module Chaoyong He ` (14 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the definition of data structure and macro into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.h | 4 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 105 +++++++++++++++++++---------- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +----------------- 3 files changed, 72 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 7fa09ee575..dbd9af31ed 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -6,7 +6,7 @@ #ifndef __NFP_MIP_H__ #define __NFP_MIP_H__ -#include "nfp_nffw.h" +#include "nfp_cpp.h" struct nfp_mip; @@ -16,7 +16,5 @@ void nfp_mip_close(struct nfp_mip *mip); const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); -int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b27a9fbaa7..895c71afdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,12 +3,76 @@ * All rights reserved. */ -#include "../nfp_logs.h" -#include "nfp_cpp.h" #include "nfp_nffw.h" + +#include "../nfp_logs.h" #include "nfp_mip.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" +#include "nfp6000/nfp6000.h" + +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. + * Lower IDs are reserved for target and loader IDs. + */ +#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ +#define NFFW_FWID_BASE 4 + +#define NFFW_FWID_ALL 255 + +/* + * NFFW_INFO_VERSION history: + * 0: This was never actually used (before versioning), but it refers to + * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later + * changed to 200. + * 1: First versioned struct, with + * FWINFO_CNT = 120 + * MEINFO_CNT = 120 + * 2: FWINFO_CNT = 200 + * MEINFO_CNT = 200 + */ +#define NFFW_INFO_VERSION_CURRENT 2 + +/* Enough for all current chip families */ +#define NFFW_MEINFO_CNT_V1 120 +#define NFFW_FWINFO_CNT_V1 120 +#define NFFW_MEINFO_CNT_V2 200 +#define NFFW_FWINFO_CNT_V2 200 + +/* nfp.nffw meinfo */ +struct nffw_meinfo { + uint32_t ctxmask_fwid_meid; +}; + +struct nffw_fwinfo { + uint32_t loaded_mu_da_mip_off_hi; + uint32_t mip_cppid; /**< 0 means no MIP */ + uint32_t mip_offset_lo; +}; + +struct nfp_nffw_info_v1 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; +}; + +struct nfp_nffw_info_v2 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; +}; + +struct nfp_nffw_info_data { + uint32_t flags[2]; + union { + struct nfp_nffw_info_v1 v1; + struct nfp_nffw_info_v2 v2; + } info; +}; + +struct nfp_nffw_info { + struct nfp_cpp *cpp; + struct nfp_resource *res; + + struct nfp_nffw_info_data fwinf; +}; /* * flg_info_version = flags[0]<27:16> @@ -61,32 +125,6 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) - -static int -nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) -{ - int err; - uint32_t mode; - uint32_t addr40; - uint32_t xpbaddr; - uint32_t imbcppat; - - /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; - err = nfp_xpb_readl(cpp, xpbaddr, &imbcppat); - if (err < 0) - return err; - - mode = NFP_IMB_TGTADDRESSMODECFG_MODE_of(imbcppat); - addr40 = !!(imbcppat & NFP_IMB_TGTADDRESSMODECFG_ADDRMODE); - - return nfp_cppat_mu_locality_lsb(mode, addr40); -} - static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { @@ -236,14 +274,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { - int locality_off; - - if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) - return 0; - - locality_off = nfp_mip_mu_locality_lsb(state->cpp); - if (locality_off < 0) - return locality_off; + int locality_off = nfp_cpp_mu_locality_lsb(state->cpp); *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 52e25c090a..fd46009d37 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,71 +8,11 @@ #include "nfp_cpp.h" -/* - * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. - * Lower IDs are reserved for target and loader IDs. - */ -#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ -#define NFFW_FWID_BASE 4 - -#define NFFW_FWID_ALL 255 - -/* - * NFFW_INFO_VERSION history: - * 0: This was never actually used (before versioning), but it refers to - * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later - * changed to 200. - * 1: First versioned struct, with - * FWINFO_CNT = 120 - * MEINFO_CNT = 120 - * 2: FWINFO_CNT = 200 - * MEINFO_CNT = 200 - */ -#define NFFW_INFO_VERSION_CURRENT 2 - -/* Enough for all current chip families */ -#define NFFW_MEINFO_CNT_V1 120 -#define NFFW_FWINFO_CNT_V1 120 -#define NFFW_MEINFO_CNT_V2 200 -#define NFFW_FWINFO_CNT_V2 200 - -/* nfp.nffw meinfo */ -struct nffw_meinfo { - uint32_t ctxmask_fwid_meid; -}; - -struct nffw_fwinfo { - uint32_t loaded_mu_da_mip_off_hi; - uint32_t mip_cppid; /* 0 means no MIP */ - uint32_t mip_offset_lo; -}; - -struct nfp_nffw_info_v1 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; -}; - -struct nfp_nffw_info_v2 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; -}; - -struct nfp_nffw_info_data { - uint32_t flags[2]; - union { - struct nfp_nffw_info_v1 v1; - struct nfp_nffw_info_v2 v2; - } info; -}; - -struct nfp_nffw_info { - struct nfp_cpp *cpp; - struct nfp_resource *res; - - struct nfp_nffw_info_data fwinf; -}; +struct nfp_nffw_info; struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); +int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, + uint64_t *offset); #endif /* __NFP_NFFW_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 14/27] net/nfp: refact the mip module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (12 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 13/27] net/nfp: refact the nffw module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 15/27] net/nfp: refact the rtsym module Chaoyong He ` (13 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f6f07ac739..ec064b08dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -3,12 +3,11 @@ * All rights reserved. */ -#include <stdio.h> +#include "nfp_mip.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_mip.h" #include "nfp_nffw.h" #define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 15/27] net/nfp: refact the rtsym module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (13 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 14/27] net/nfp: refact the mip module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 16/27] net/nfp: refact the resource module Chaoyong He ` (12 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include <stdio.h> +#include "nfp_rtsym.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ 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); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 16/27] net/nfp: refact the resource module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (14 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 15/27] net/nfp: refact the rtsym module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 17/27] net/nfp: refact the target module Chaoyong He ` (11 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_resource.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e7e232eb4e..e4a3a42eea 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -3,15 +3,11 @@ * All rights reserved. */ -#include <stdio.h> -#include <time.h> -#include <endian.h> +#include "nfp_resource.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" #include "nfp6000/nfp6000.h" -#include "nfp_resource.h" -#include "nfp_crc.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL @@ -43,7 +39,7 @@ struct nfp_resource_entry { }; #define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ +#define NFP_RESOURCE_TBL_ENTRIES (NFP_RESOURCE_TBL_SIZE / \ sizeof(struct nfp_resource_entry)) struct nfp_resource { @@ -173,8 +169,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - rte_free(res); - return NULL; + goto err_free; } wait.tv_sec = 0; @@ -186,13 +181,12 @@ nfp_resource_acquire(struct nfp_cpp *cpp, break; if (err != -EBUSY) { PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); - goto err_free; + goto mutex_free; } if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); - err = -EBUSY; - goto err_free; + goto mutex_free; } nanosleep(&wait, NULL); @@ -202,8 +196,9 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return res; -err_free: +mutex_free: nfp_cpp_mutex_free(dev_mutex); +err_free: rte_free(res); return NULL; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 17/27] net/nfp: refact the target module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (15 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 16/27] net/nfp: refact the resource module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 18/27] net/nfp: add a new header file Chaoyong He ` (10 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the function declaration into the header file, and sync some logic from kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 -------------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 1 + drivers/net/nfp/nfpcore/nfp_cppcore.c | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 - drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 1 + drivers/net/nfp/nfpcore/nfp_target.c | 7 ++++--- drivers/net/nfp/nfpcore/nfp_target.h | 22 ++++++++++++++++++++++ 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index efaa87c0e5..4c9ac017cc 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -6,21 +6,6 @@ #ifndef __NFP_NFP6000_H__ #define __NFP_NFP6000_H__ -/* CPP Target IDs */ -#define NFP_CPP_TARGET_INVALID 0 -#define NFP_CPP_TARGET_NBI 1 -#define NFP_CPP_TARGET_QDR 2 -#define NFP_CPP_TARGET_ILA 6 -#define NFP_CPP_TARGET_MU 7 -#define NFP_CPP_TARGET_PCIE 9 -#define NFP_CPP_TARGET_ARM 10 -#define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ -#define NFP_CPP_TARGET_CT_XPB 14 -#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 -#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH - #define NFP_ISL_EMEM0 24 #define NFP_MU_ADDR_ACCESS_TYPE_MASK 3ULL @@ -52,9 +37,4 @@ nfp_cppat_mu_locality_lsb(int mode, int addr40) } } -int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); -int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table); - #endif /* NFP_NFP6000_H */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index db15411eb2..310cc691cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -34,6 +34,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index d8e57b9075..f33985bec6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -16,6 +16,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 85c33502ca..87a9351ff9 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -9,7 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) #define MUTEX_UNLOCK(interface) (0 | 0x0000) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index eea5cde426..dbabffea9c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,7 +9,6 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp6000/nfp6000.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e4a3a42eea..ee987c4438 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,7 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 2d4100dda2..022753f98a 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -14,6 +14,7 @@ #include "nfp_logs.h" #include "nfp_mip.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" enum nfp_rtsym_type { diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 540b242a43..ecb45f7928 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -3,6 +3,8 @@ * All rights reserved. */ +#include "nfp_target.h" + #include "nfp_cpp.h" #include "nfp6000/nfp6000.h" @@ -315,8 +317,7 @@ nfp6000_mu(uint32_t cpp_id, } else if (island == 1 || (island >= 4 && island <= 7) || (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { + (island >= 32 && island <= 51)) { pp = nfp6000_mu_ctm(cpp_id); } else { pp = -EINVAL; @@ -510,7 +511,7 @@ nfp_target_pushpull(uint32_t cpp_id, return nfp6000_cap_xpb(cpp_id); case NFP_CPP_TARGET_CLS: return nfp6000_cls(cpp_id); - case 0: + case NFP_CPP_TARGET_INVALID: return target_rw(cpp_id, P32, 4, 4); default: return -EINVAL; diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 2a2f083914..47527b4040 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,4 +6,26 @@ #ifndef __NFP_TARGET_H__ #define __NFP_TARGET_H__ +#include <stdint.h> + +/* CPP Target IDs */ +#define NFP_CPP_TARGET_INVALID 0 +#define NFP_CPP_TARGET_NBI 1 +#define NFP_CPP_TARGET_QDR 2 +#define NFP_CPP_TARGET_ILA 6 +#define NFP_CPP_TARGET_MU 7 +#define NFP_CPP_TARGET_PCIE 9 +#define NFP_CPP_TARGET_ARM 10 +#define NFP_CPP_TARGET_CRYPTO 12 +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_CT_XPB 14 +#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 +#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH + +int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); +int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, + uint32_t *cpp_target_id, uint64_t *cpp_target_address, + const uint32_t *imb_table); + #endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 18/27] net/nfp: add a new header file 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (16 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 17/27] net/nfp: refact the target module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 19/27] net/nfp: refact the nsp module Chaoyong He ` (9 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Split out the macro which are not easily find a DPDK substitute into a new header file. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_nsp.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp.h | 23 -------------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 + drivers/net/nfp/nfpcore/nfp_platform.h | 42 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 9bb344aa5f..8e65064b10 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -13,6 +13,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #include "nfp_resource.h" int diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 705574b900..14986a9130 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -9,29 +9,6 @@ #include "nfp_cpp.h" #include "nfp_nsp.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - /* Offsets relative to the CSR base */ #define NSP_STATUS 0x00 #define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index dbabffea9c..355d907f4d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,6 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_platform.h b/drivers/net/nfp/nfpcore/nfp_platform.h new file mode 100644 index 0000000000..fcac6b05ff --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_platform.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_PLATFORM_H__ +#define __NFP_PLATFORM_H__ + +#include <stdint.h> + +#define DMA_BIT_MASK(n) ((1ULL << (n)) - 1) + +#define BITS_PER_LONG (__SIZEOF_LONG__ * 8) +#define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8) + +#define GENMASK(h, l) \ + ((~0UL << (l)) & (~0UL >> (BITS_PER_LONG - (h) - 1))) + +#define GENMASK_ULL(h, l) \ + ((~0ULL << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - (h) - 1))) + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define FIELD_GET(_mask, _reg) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + })) + +#define FIELD_FIT(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ + })) + +#define FIELD_PREP(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + })) + +#endif /* __NFP_PLATFORM_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 19/27] net/nfp: refact the nsp module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (17 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 18/27] net/nfp: add a new header file Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 20/27] net/nfp: refact the mutex module Chaoyong He ` (8 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the definition of data structure into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 390 +++++++++++++++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 140 ++++----- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 - drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 79 ++--- 5 files changed, 398 insertions(+), 217 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 2e43055fd5..9243191de3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -661,7 +661,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev) static int nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) { - struct nfp_cpp *cpp = nsp->cpp; + struct nfp_cpp *cpp = nfp_nsp_cpp(nsp); void *fw_buf; char fw_name[125]; char serial[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 8e65064b10..75d13cb84f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -3,20 +3,127 @@ * All rights reserved. */ -#define NFP_SUBSYS "nfp_nsp" - -#include <stdio.h> -#include <time.h> +#include "nfp_nsp.h" #include <rte_common.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_nsp.h" #include "nfp_platform.h" #include "nfp_resource.h" -int +/* Offsets relative to the CSR base */ +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_DMA_BUF RTE_BIT64(1) +#define NSP_COMMAND_START RTE_BIT64(0) + +/* CPP address to retrieve the data from */ +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) + +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 + +#define NSP_CODE_MAJOR GENMASK_ULL(15, 12) +#define NSP_CODE_MINOR GENMASK_ULL(11, 0) + +#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8) +#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16) + +enum nfp_nsp_cmd { + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */ + SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */ + SPCODE_HWINFO_SET = 18, /* Set HWinfo entry */ + SPCODE_FW_LOADED = 19, /* Is application firmware loaded */ + SPCODE_VERSIONS = 21, /* Report FW versions */ + SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */ + SPCODE_READ_MEDIA = 23, /* Get the supported/advertised media for a port */ +}; + +static const struct { + uint32_t code; + const char *msg; +} nsp_errors[] = { + { 6010, "could not map to phy for port" }, + { 6011, "not an allowed rate/lanes for port" }, + { 6012, "not an allowed rate/lanes for port" }, + { 6013, "high/low error, change other port first" }, + { 6014, "config not found in flash" }, +}; + +struct nfp_nsp { + struct nfp_cpp *cpp; + struct nfp_resource *res; + struct { + uint16_t major; + uint16_t minor; + } ver; + + /** Eth table config state */ + bool modified; + uint32_t idx; + void *entries; +}; + +/* NFP command argument structure */ +struct nfp_nsp_command_arg { + uint16_t code; /**< NFP SP Command Code */ + bool dma; /**< @buf points to a host buffer, not NSP buffer */ + bool error_quiet; /**< Don't print command error/warning */ + uint32_t timeout_sec; /**< Timeout value to wait for completion in seconds */ + uint32_t option; /**< NSP Command Argument */ + uint64_t buf; /**< NSP Buffer Address */ + /** Callback for interpreting option if error occurred */ + void (*error_cb)(struct nfp_nsp *state, uint32_t ret_val); +}; + +/* NFP command with buffer argument structure */ +struct nfp_nsp_command_buf_arg { + struct nfp_nsp_command_arg arg; /**< NFP command argument structure */ + const void *in_buf; /**< Buffer with data for input */ + void *out_buf; /**< Buffer for output data */ + uint32_t in_size; /**< Size of @in_buf */ + uint32_t out_size; /**< Size of @out_buf */ +}; + +struct nfp_cpp * +nfp_nsp_cpp(struct nfp_nsp *state) +{ + return state->cpp; +} + +bool nfp_nsp_config_modified(struct nfp_nsp *state) { return state->modified; @@ -24,7 +131,7 @@ nfp_nsp_config_modified(struct nfp_nsp *state) void nfp_nsp_config_set_modified(struct nfp_nsp *state, - int modified) + bool modified) { state->modified = modified; } @@ -66,7 +173,7 @@ nfp_nsp_print_extended_error(uint32_t ret_val) return; for (i = 0; i < RTE_DIM(nsp_errors); i++) - if (ret_val == (uint32_t)nsp_errors[i].code) + if (ret_val == nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -222,11 +329,8 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, - uint16_t code, - uint32_t option, - uint32_t buff_cpp, - uint64_t buff_addr) +nfp_nsp_command_real(struct nfp_nsp *state, + const struct nfp_nsp_command_arg *arg) { int err; uint64_t reg; @@ -250,22 +354,14 @@ nfp_nsp_command(struct nfp_nsp *state, return err; } - if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { - PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); - return -EINVAL; - } - - err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, arg->buf); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_OPTION, arg->option) | + FIELD_PREP(NSP_COMMAND_CODE, arg->code) | + FIELD_PREP(NSP_COMMAND_DMA_BUF, arg->dma) | FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; @@ -275,7 +371,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", - err, code); + err, arg->code); return err; } @@ -284,7 +380,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", - err, code); + err, arg->code); return err; } @@ -296,84 +392,85 @@ nfp_nsp_command(struct nfp_nsp *state, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { - PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); - nfp_nsp_print_extended_error(ret_val); + if (!arg->error_quiet) + PMD_DRV_LOG(WARNING, "Result (error) code set: %d (%d) command: %d", + -err, (int)ret_val, arg->code); + + if (arg->error_cb != 0) + arg->error_cb(state, ret_val); + else + nfp_nsp_print_extended_error(ret_val); + return -err; } return ret_val; } -#define SZ_1M 0x00100000 +static int +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code) +{ + const struct nfp_nsp_command_arg arg = { + .code = code, + }; + + return nfp_nsp_command_real(state, &arg); +} static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, - uint16_t code, uint32_t option, - const void *in_buf, - unsigned int in_size, - void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf_def(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) { int err; int ret; uint64_t reg; - size_t max_size; uint32_t cpp_id; uint64_t cpp_buf; struct nfp_cpp *cpp = nsp->cpp; - if (nsp->ver.minor < 13) { - PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); - return -EOPNOTSUPP; - } - - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, - ®); - if (err < 0) - return err; - - max_size = RTE_MAX(in_size, out_size); - if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); - return -EINVAL; - } - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, ®); if (err < 0) return err; - cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; - cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); + cpp_id = FIELD_GET(NSP_DFLT_BUFFER_CPP, reg) << 8; + cpp_buf = FIELD_GET(NSP_DFLT_BUFFER_ADDRESS, reg); - if (in_buf != NULL && in_size > 0) { - err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); + if (arg->in_buf != NULL && arg->in_size > 0) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf, + arg->in_buf, arg->in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf != NULL && out_size > 0 && out_size > in_size) { - memset(out_buf, 0, out_size - in_size); - err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + if (arg->out_buf != NULL && arg->out_size > arg->in_size) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf + arg->in_size, + arg->out_buf, arg->out_size - arg->in_size); if (err < 0) return err; } - ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); + if (!FIELD_FIT(NSP_BUFFER_CPP, cpp_id >> 8) || + !FIELD_FIT(NSP_BUFFER_ADDRESS, cpp_buf)) { + PMD_DRV_LOG(ERR, "Buffer out of reach %#08x %#016lx", + cpp_id, cpp_buf); + return -EINVAL; + } + + arg->arg.buf = FIELD_PREP(NSP_BUFFER_CPP, cpp_id >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf); + ret = nfp_nsp_command_real(nsp, &arg->arg); if (ret < 0) { PMD_DRV_LOG(ERR, "NSP command failed"); return ret; } - if (out_buf != NULL && out_size > 0) { - err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); + if (arg->out_buf != NULL && arg->out_size > 0) { + err = nfp_cpp_read(cpp, cpp_id, cpp_buf, + arg->out_buf, arg->out_size); if (err < 0) return err; } @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, return ret; } +#define SZ_1M 0x00100000 +#define SZ_4K 0x00001000 + +static int +nfp_nsp_command_buf(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) +{ + int err; + uint64_t reg; + uint32_t size; + uint32_t max_size; + struct nfp_cpp *cpp = nsp->cpp; + + if (nsp->ver.minor < 13) { + PMD_DRV_LOG(ERR, "NSP: Code %#04x with buffer not supported ABI %hu.%hu)", + arg->arg.code, nsp->ver.major, nsp->ver.minor); + return -EOPNOTSUPP; + } + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); + if (err < 0) + return err; + + max_size = RTE_MAX(arg->in_size, arg->out_size); + size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; + if (size < max_size) { + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%u < %u)", + arg->arg.code, size, max_size); + return -EINVAL; + } + + return nfp_nsp_command_buf_def(nsp, arg); +} + int nfp_nsp_wait(struct nfp_nsp *state) { @@ -392,7 +526,7 @@ nfp_nsp_wait(struct nfp_nsp *state) wait.tv_nsec = 25000000; /* 25ms */ for (;;) { - err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); + err = nfp_nsp_command(state, SPCODE_NOOP); if (err != -EAGAIN) break; @@ -413,13 +547,57 @@ nfp_nsp_wait(struct nfp_nsp *state) int nfp_nsp_device_soft_reset(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_SOFT_RESET, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_SOFT_RESET); } int nfp_nsp_mac_reinit(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_MAC_INIT, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_MAC_INIT); +} + +static void +nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, + uint32_t ret_val) +{ + uint32_t minor; + uint32_t major; + static const char * const major_msg[] = { + /* 0 */ "Firmware from driver loaded", + /* 1 */ "Firmware from flash loaded", + /* 2 */ "Firmware loading failure", + }; + static const char * const minor_msg[] = { + /* 0 */ "", + /* 1 */ "no named partition on flash", + /* 2 */ "error reading from flash", + /* 3 */ "can not deflate", + /* 4 */ "not a trusted file", + /* 5 */ "can not parse FW file", + /* 6 */ "MIP not found in FW file", + /* 7 */ "null firmware name in MIP", + /* 8 */ "FW version none", + /* 9 */ "FW build number none", + /* 10 */ "no FW selection policy HWInfo key found", + /* 11 */ "static FW selection policy", + /* 12 */ "FW version has precedence", + /* 13 */ "different FW application load requested", + /* 14 */ "development build", + }; + + major = FIELD_GET(NFP_FW_LOAD_RET_MAJOR, ret_val); + minor = FIELD_GET(NFP_FW_LOAD_RET_MINOR, ret_val); + + if (!nfp_nsp_has_stored_fw_load(state)) + return; + + if (major >= RTE_DIM(major_msg)) + PMD_DRV_LOG(INFO, "FW loading status: %x", ret_val); + else if (minor >= RTE_DIM(minor_msg)) + PMD_DRV_LOG(INFO, "%s, reason code: %d", major_msg[major], minor); + else + PMD_DRV_LOG(INFO, "%s%c %s", major_msg[major], + minor != 0 ? ',' : '.', minor_msg[minor]); } int @@ -427,8 +605,24 @@ nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + int ret; + struct nfp_nsp_command_buf_arg load_fw = { + { + .code = SPCODE_FW_LOAD, + .option = size, + .error_cb = nfp_nsp_load_fw_extended_msg, + }, + .in_buf = buf, + .in_size = size, + }; + + ret = nfp_nsp_command_buf(state, &load_fw); + if (ret < 0) + return ret; + + nfp_nsp_load_fw_extended_msg(state, ret); + + return 0; } int @@ -436,8 +630,16 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg eth_rescan = { + { + .code = SPCODE_ETH_RESCAN, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, ð_rescan); } int @@ -445,8 +647,16 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + struct nfp_nsp_command_buf_arg eth_ctrl = { + { + .code = SPCODE_ETH_CONTROL, + .option = size, + }, + .in_buf = buf, + .in_size = size, + }; + + return nfp_nsp_command_buf(state, ð_ctrl); } int @@ -454,8 +664,16 @@ nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg identify = { + { + .code = SPCODE_NSP_IDENTIFY, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &identify); } int @@ -464,6 +682,14 @@ nfp_nsp_read_sensors(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + struct nfp_nsp_command_buf_arg sensors = { + { + .code = SPCODE_NSP_SENSORS, + .option = sensor_mask, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &sensors); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 14986a9130..fe52dffeb7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -7,78 +7,8 @@ #define __NSP_NSP_H__ #include "nfp_cpp.h" -#include "nfp_nsp.h" - -/* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) - -/* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) - -#define NSP_DFLT_BUFFER 0x18 - -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) - -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 - -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) - -enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ -}; - -static const struct { - int code; - const char *msg; -} nsp_errors[] = { - { 6010, "could not map to phy for port" }, - { 6011, "not an allowed rate/lanes for port" }, - { 6012, "not an allowed rate/lanes for port" }, - { 6013, "high/low error, change other port first" }, - { 6014, "config not found in flash" }, -}; -struct nfp_nsp { - struct nfp_cpp *cpp; - struct nfp_resource *res; - struct { - uint16_t major; - uint16_t minor; - } ver; - - /* Eth table config state */ - int modified; - unsigned int idx; - void *entries; -}; +struct nfp_nsp; struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); void nfp_nsp_close(struct nfp_nsp *state); @@ -92,18 +22,61 @@ int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, void *buf, size_t size); -static inline int +static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } +static inline bool +nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 23; +} + +static inline bool +nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 24; +} + +static inline bool +nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_fw_loaded(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_versions(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 27; +} + +static inline bool +nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 28; +} + +static inline bool +nfp_nsp_has_read_media(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 33; +} + enum nfp_eth_interface { NFP_INTERFACE_NONE = 0, NFP_INTERFACE_SFP = 1, NFP_INTERFACE_SFPP = 10, NFP_INTERFACE_SFP28 = 28, NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_RJ45 = 45, NFP_INTERFACE_CXP = 100, NFP_INTERFACE_QSFP28 = 112, }; @@ -151,6 +124,7 @@ struct nfp_eth_table { enum nfp_eth_media media; /**< Media type of the @interface */ enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ struct rte_ether_addr mac_addr; /**< Interface MAC address */ @@ -159,17 +133,18 @@ struct nfp_eth_table { /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; /**< Enable port */ - int tx_enabled; /**< Enable TX */ - int rx_enabled; /**< Enable RX */ + bool enabled; /**< Enable port */ + bool tx_enabled; /**< Enable TX */ + bool rx_enabled; /**< Enable RX */ + bool supp_aneg; /**< Support auto negotiation */ - int override_changed; /**< Media reconfig pending */ + bool override_changed; /**< Media reconfig pending */ uint8_t port_type; /**< One of %PORT_* */ /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; /**< Split port */ + bool is_split; /**< Split port */ uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ } ports[]; /**< Table of ports */ @@ -177,8 +152,8 @@ struct nfp_eth_table { struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); @@ -187,12 +162,13 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); -void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); +void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); -int nfp_nsp_config_modified(struct nfp_nsp *state); +struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); +bool nfp_nsp_config_modified(struct nfp_nsp *state); uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int +static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported != 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 429f639fa2..86956f4330 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -3,12 +3,8 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp_nffw.h" struct nsp_identify { uint8_t version[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 355d907f4d..996fd4b44a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -3,10 +3,6 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_common.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" #include "nfp_platform.h" @@ -21,6 +17,7 @@ #define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) #define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) #define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) +#define NSP_ETH_PORT_SUPP_ANEG RTE_BIT64(63) #define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) @@ -34,6 +31,7 @@ #define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) #define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) #define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) +#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28) #define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) #define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) @@ -54,26 +52,12 @@ #define PORT_NONE 0xef #define PORT_OTHER 0xff -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 - enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW + NSP_ETH_NUM_RAW, }; enum nfp_eth_rate { @@ -100,12 +84,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, RTE_ETH_SPEED_NUM_NONE, }, + { RATE_10M, RTE_ETH_SPEED_NUM_10M, }, + { RATE_100M, RTE_ETH_SPEED_NUM_100M, }, + { RATE_1G, RTE_ETH_SPEED_NUM_1G, }, + { RATE_10G, RTE_ETH_SPEED_NUM_10G, }, + { RATE_25G, RTE_ETH_SPEED_NUM_25G, }, }; static uint32_t @@ -192,7 +176,14 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; - dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->fec = FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->act_fec = dst->fec; + + if (nfp_nsp_get_abi_ver_minor(nsp) < 33) + return; + + dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state); + dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port); } static void @@ -221,7 +212,7 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) table->ports[i].label_port, table->ports[i].label_subport); - table->ports[i].is_split = 1; + table->ports[i].is_split = true; } } } @@ -232,6 +223,9 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) if (entry->interface == NFP_INTERFACE_NONE) { entry->port_type = PORT_NONE; return; + } else if (entry->interface == NFP_INTERFACE_RJ45) { + entry->port_type = PORT_TP; + return; } if (entry->media == NFP_MEDIA_FIBRE) @@ -250,7 +244,6 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) uint32_t table_sz; struct nfp_eth_table *table; union eth_table_entry *entries; - const struct rte_ether_addr *mac; entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) @@ -262,16 +255,9 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) goto err; } - /* - * The NFP3800 NIC support 8 ports, but only 2 ports are valid, - * the rest 6 ports mac are all 0, ensure we don't use these port - */ - for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) + for (i = 0; i < NSP_ETH_MAX_COUNT; i++) + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) cnt++; - } /* * Some versions of flash will give us 0 instead of port count. For @@ -291,11 +277,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) - nfp_eth_port_translate(nsp, &entries[i], i, - &table->ports[j++]); + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) + nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); } nfp_eth_calc_port_geometry(table); @@ -436,7 +419,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, - int enable) + bool enable) { uint64_t reg; struct nfp_nsp *nsp; @@ -444,7 +427,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) - return -1; + return -EIO; entries = nfp_nsp_config_entries(nsp); @@ -456,7 +439,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_ENABLED, enable); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -480,7 +463,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configured) + bool configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -509,7 +492,7 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -547,7 +530,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, entries[idx].control |= rte_cpu_to_le_64(ctrl_bit); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 20/27] net/nfp: refact the mutex module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (18 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 19/27] net/nfp: refact the nsp module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He ` (7 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add a header file to holds the API declarations of this module. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 16 -- drivers/net/nfp/nfpcore/nfp_mutex.c | 205 ++++++++++++++----------- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 +++ drivers/net/nfp/nfpcore/nfp_resource.c | 1 + 4 files changed, 138 insertions(+), 109 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index be7ae1d919..42c4df5fdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -8,8 +8,6 @@ #include <ethdev_pci.h> -struct nfp_cpp_mutex; - /* NFP CPP handle */ struct nfp_cpp { uint32_t model; @@ -426,20 +424,6 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); - uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); #endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 87a9351ff9..9363543422 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -3,21 +3,13 @@ * All rights reserved. */ -#include <malloc.h> -#include <time.h> +#include "nfp_mutex.h" + #include <sched.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" -#define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) -#define MUTEX_UNLOCK(interface) (0 | 0x0000) - -#define MUTEX_IS_LOCKED(value) (((value) & 0xffff) == 0x000f) -#define MUTEX_IS_UNLOCKED(value) (((value) & 0xffff) == 0x0000) -#define MUTEX_INTERFACE(value) (((value) >> 16) & 0xffff) - /* * If you need more than 65536 recursive locks, please * rethink your code. @@ -34,21 +26,51 @@ struct nfp_cpp_mutex { struct nfp_cpp_mutex *prev, *next; }; +static inline uint32_t +nfp_mutex_locked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x000f; +} + +static inline uint32_t +nfp_mutex_unlocked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x0000; +} + +static inline uint16_t +nfp_mutex_owner(uint32_t val) +{ + return (val >> 16) & 0xffff; +} + +static inline bool +nfp_mutex_is_locked(uint32_t val) +{ + return (val & 0xffff) == 0x000f; +} + +static inline bool +nfp_mutex_is_unlocked(uint32_t val) +{ + return (val & 0xffff) == 0; +} + static int -nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint16_t interface, int *target, uint64_t address) { + /* Not permitted on invalid interfaces */ + if (NFP_CPP_INTERFACE_TYPE_of(interface) == NFP_CPP_INTERFACE_TYPE_INVALID) + return -EINVAL; + /* Address must be 64-bit aligned */ if ((address & 7) != 0) return -EINVAL; - if (NFP_CPP_MODEL_IS_6000(model)) { - if (*target != NFP_CPP_TARGET_MU) - return -EINVAL; - } else { + if (*target != NFP_CPP_TARGET_MU) return -EINVAL; - } return 0; } @@ -84,10 +106,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t key) { int err; - uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint16_t interface = nfp_cpp_interface(cpp); - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return err; @@ -95,8 +117,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, if (err < 0) return err; - err = nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface)); if (err < 0) return err; @@ -133,26 +154,10 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int err; uint32_t tmp; struct nfp_cpp_mutex *mutex; - uint32_t model = nfp_cpp_model(cpp); uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint16_t interface = nfp_cpp_interface(cpp); - /* Look for cached mutex */ - for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { - if (mutex->target == target && mutex->address == address) - break; - } - - if (mutex) { - if (mutex->key == key) { - mutex->usage++; - return mutex; - } - - /* If the key doesn't match... */ - return NULL; - } - - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return NULL; @@ -172,16 +177,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, mutex->address = address; mutex->key = key; mutex->depth = 0; - mutex->usage = 1; - - /* Add mutex to the cache */ - if (cpp->mutex_cache) { - cpp->mutex_cache->prev = mutex; - mutex->next = cpp->mutex_cache; - cpp->mutex_cache = mutex; - } else { - cpp->mutex_cache = mutex; - } return mutex; } @@ -195,20 +190,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) { - mutex->usage--; - if (mutex->usage > 0) - return; - - /* Remove mutex from the cache */ - if (mutex->next) - mutex->next->prev = mutex->prev; - if (mutex->prev) - mutex->prev->next = mutex->next; - - /* If mutex->cpp == NULL, something broke */ - if (mutex->cpp && mutex == mutex->cpp->mutex_cache) - mutex->cpp->mutex_cache = mutex->next; - rte_free(mutex); } @@ -268,32 +249,28 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return 0; } - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - goto exit; - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; - if (value != MUTEX_LOCKED(interface)) { - err = -EACCES; - goto exit; - } + err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); + if (err < 0) + return err; + + if (value != nfp_mutex_locked(interface)) + return -EACCES; - err = nfp_cpp_writel(cpp, muw, mutex->address, MUTEX_UNLOCK(interface)); + err = nfp_cpp_writel(cpp, muw, mutex->address, + nfp_mutex_unlocked(interface)); if (err < 0) - goto exit; + return err; mutex->depth = 0; -exit: - return err; + return 0; } /** @@ -332,19 +309,17 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) /* Verify that the lock marker is not damaged */ err = nfp_cpp_readl(cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; /* * Compare against the unlocked state, and if true, * write the interface id into the top 16 bits, and * mark as locked. */ - value = MUTEX_LOCKED(nfp_cpp_interface(cpp)); + value = nfp_mutex_locked(nfp_cpp_interface(cpp)); /* * We use test_set_imm here, as it implies a read @@ -361,10 +336,10 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_readl(cpp, mus, mutex->address, &tmp); if (err < 0) - goto exit; + return err; /* Was it unlocked? */ - if (MUTEX_IS_UNLOCKED(tmp)) { + if (nfp_mutex_is_unlocked(tmp)) { /* * The read value can only be 0x....0000 in the unlocked state. * If there was another contending for this lock, then @@ -376,20 +351,64 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_writel(cpp, muw, mutex->address, value); if (err < 0) - goto exit; + return err; mutex->depth = 1; - goto exit; + return 0; } /* Already locked by us? Success! */ if (tmp == value) { mutex->depth = 1; - goto exit; + return 0; } - err = MUTEX_IS_LOCKED(tmp) ? -EBUSY : -EINVAL; + return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL; +} + +/** + * Release lock if held by local system. + * Extreme care is advised, call only when no local lock users can exist. + * + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * + * @return + * - (0) if the lock was OK + * - (1) if locked by us + * - (-errno) on invalid mutex + */ +int +nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, + int target, + uint64_t address) +{ + int err; + uint32_t tmp; + uint16_t interface = nfp_cpp_interface(cpp); + const uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + const uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + + err = nfp_cpp_mutex_validate(interface, &target, address); + if (err != 0) + return err; + + /* Check lock */ + err = nfp_cpp_readl(cpp, mur, address, &tmp); + if (err < 0) + return err; + + if (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface) + return 0; + + /* Bust the lock */ + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface)); + if (err < 0) + return err; -exit: - return err; + return 1; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.h b/drivers/net/nfp/nfpcore/nfp_mutex.h new file mode 100644 index 0000000000..a79490b4d6 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_mutex.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_MUTEX_H__ +#define __NFP_MUTEX_H__ + +#include "nfp_cpp.h" + +struct nfp_cpp_mutex; + +int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target, uint64_t address); + +#endif /* __NFP_MUTEX_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index ee987c4438..c4cc7f42f6 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,6 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" +#include "nfp_mutex.h" #include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 21/27] net/nfp: rename data field to sync with kernel driver 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (19 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 20/27] net/nfp: refact the mutex module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 22/27] net/nfp: add the dev module Chaoyong He ` (6 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Rename the data fields to sync with the logic in kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +++--- drivers/net/nfp/nfp_common.h | 4 ++-- drivers/net/nfp/nfp_ethdev.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 37895e8355..24a6878149 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -224,7 +224,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -360,8 +360,8 @@ nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type) start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ; - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; /* Set the current MTU to the maximum supported */ hw->mtu = hw->max_mtu; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 1ce51d44d4..86c4e10040 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -123,9 +123,9 @@ struct nfp_pf_dev { struct nfp_cpp *cpp; struct nfp_cpp_area *ctrl_area; - struct nfp_cpp_area *hwqueues_area; + struct nfp_cpp_area *qc_area; - uint8_t *hw_queues; + uint8_t *qc_bar; struct nfp_hwinfo *hwinfo; struct nfp_rtsym_table *sym_tbl; diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 9243191de3..3f5375deb9 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -311,7 +311,7 @@ nfp_net_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -593,8 +593,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -995,16 +995,16 @@ nfp_pf_init(struct rte_pci_device *pci_dev) } cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); - pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, cpp_id, + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, addr, NFP_QCP_QUEUE_AREA_SZ, - &pf_dev->hwqueues_area); - if (pf_dev->hw_queues == NULL) { + &pf_dev->qc_area); + if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; goto pf_cleanup; } - PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues); + PMD_INIT_LOG(DEBUG, "qc_bar address: 0x%p", pf_dev->qc_bar); /* * PF initialization has been done at this point. Call app specific @@ -1041,7 +1041,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) return 0; hwqueues_cleanup: - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); pf_cleanup: rte_free(pf_dev); sym_tbl_cleanup: -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 22/27] net/nfp: add the dev module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (20 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 23/27] net/nfp: add header file for PCIe module Chaoyong He ` (5 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add the nfp_dev module to simplify the logic. The data structure we import can gather and replace several macro which scatter everywhere. Which also make the logic of choose value for different devices unnecessary and so eliminate such logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 1 + drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 ++---------- drivers/net/nfp/nfp_common.h | 48 +++-------- drivers/net/nfp/nfp_ethdev.c | 63 ++++++--------- drivers/net/nfp/nfp_ethdev_vf.c | 17 +--- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 --- drivers/net/nfp/nfpcore/nfp_dev.c | 81 +++++++++++++++++++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 ++++++++++ 13 files changed, 185 insertions(+), 158 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 24a6878149..43263531c5 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -503,7 +503,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_rx_ring", i, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -558,7 +559,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_tx_ring", i, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 5f94d20f1b..dc6a2c7a9a 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -67,7 +67,8 @@ nfp_pf_repr_rx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -140,7 +141,8 @@ nfp_pf_repr_tx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 93c708959c..580a478cd6 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -21,6 +21,7 @@ sources = files( 'nfpcore/nfp_rtsym.c', 'nfpcore/nfp_nsp_cmds.c', 'nfpcore/nfp_crc.c', + 'nfpcore/nfp_dev.c', 'nfpcore/nfp_mutex.c', 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', diff --git a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c index ee39686329..79e1e1041c 100644 --- a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c +++ b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c @@ -262,7 +262,6 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -276,9 +275,7 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfd3_tx_desc); diff --git a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c index f66802211f..48a74d109a 100644 --- a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c +++ b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c @@ -357,7 +357,6 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -371,9 +370,7 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfdk_tx_desc); diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c index 5092e5869d..d6ff4f17ae 100644 --- a/drivers/net/nfp/nfp_common.c +++ b/drivers/net/nfp/nfp_common.c @@ -1146,30 +1146,16 @@ nfp_net_xstats_reset(struct rte_eth_dev *dev) return nfp_net_stats_reset(dev); } -int +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc) { - *max_rx_desc = NFP_NET_MAX_RX_DESC; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_rx_desc = NFP3800_NET_MIN_RX_DESC; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_rx_desc = NFP_NET_MIN_RX_DESC; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_rx_desc = hw->pf_dev->dev_info->max_qc_size; + *min_rx_desc = hw->pf_dev->dev_info->min_qc_size; } -int +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc) @@ -1181,28 +1167,13 @@ nfp_net_tx_desc_limits(struct nfp_net_hw *hw, else tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT; - *max_tx_desc = NFP_NET_MAX_TX_DESC / tx_dpp; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_tx_desc = NFP3800_NET_MIN_TX_DESC / tx_dpp; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_tx_desc = NFP_NET_MIN_TX_DESC / tx_dpp; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_tx_desc = hw->pf_dev->dev_info->max_qc_size / tx_dpp; + *min_tx_desc = hw->pf_dev->dev_info->min_qc_size / tx_dpp; } int nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; uint16_t min_tx_desc; @@ -1211,13 +1182,8 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; - - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues; dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 86c4e10040..5fc9f0ccda 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -7,16 +7,9 @@ #define _NFP_COMMON_H_ #include "nfp_ctrl.h" +#include "nfpcore/nfp_dev.h" #define NFP_NET_PMD_VERSION "0.1" -#define PCI_VENDOR_ID_NETRONOME 0x19ee -#define PCI_VENDOR_ID_CORIGINE 0x1da8 - -#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 -#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 -#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 -#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 -#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ /* Forward declaration */ struct nfp_net_adapter; @@ -28,7 +21,6 @@ struct nfp_net_adapter; #define NFP_NET_CRTL_BAR 0 #define NFP_NET_TX_BAR 2 #define NFP_NET_RX_BAR 2 -#define NFP_QCP_QUEUE_AREA_SZ 0x80000 /* Macros for accessing the Queue Controller Peripheral 'CSRs' */ #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800) @@ -39,17 +31,6 @@ struct nfp_net_adapter; #define NFP_QCP_QUEUE_STS_HI 0x000c #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask (0x3ffff) -#define NFP_PCIE_QCP_NFP3800_OFFSET 0x400000 -#define NFP_PCIE_QCP_NFP6000_OFFSET 0x80000 -#define NFP_PCIE_QUEUE_NFP3800_MASK 0x1ff -#define NFP_PCIE_QUEUE_NFP6000_MASK 0xff -#define NFP_PCIE_QCP_PF_OFFSET 0x0 -#define NFP_PCIE_QCP_VF_OFFSET 0x0 - -/* The offset of the queue controller queues in the PCIe Target */ -#define NFP_PCIE_QUEUE(_offset, _q, _mask) \ - ((_offset) + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & (_mask)))) - /* Interrupt definitions */ #define NFP_NET_IRQ_LSC_IDX 0 @@ -111,6 +92,9 @@ struct nfp_pf_dev { /* Backpointer to associated pci device */ struct rte_pci_device *pci_dev; + /** NFP ASIC params */ + const struct nfp_dev_info *dev_info; + enum nfp_app_fw_id app_fw_id; /* Pointer to the app running on the PF */ @@ -352,23 +336,11 @@ nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr) } static inline uint32_t -nfp_pci_queue(struct rte_pci_device *pdev, uint16_t queue) +nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, + uint16_t queue) { - switch (pdev->id.device_id) { - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - case PCI_DEVICE_ID_NFP3800_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - case PCI_DEVICE_ID_NFP6000_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - default: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - } + return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ * + (queue & dev_info->qc_idx_mask); } /* Prototypes for common NFP functions */ @@ -434,10 +406,10 @@ void nfp_net_close_rx_queue(struct rte_eth_dev *dev); void nfp_net_stop_tx_queue(struct rte_eth_dev *dev); void nfp_net_close_tx_queue(struct rte_eth_dev *dev); int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port); -int nfp_net_rx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc); -int nfp_net_tx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc); int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 3f5375deb9..c37d8a1449 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -496,9 +496,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) struct nfp_app_fw_nic *app_fw_nic; struct nfp_net_hw *hw; struct rte_ether_addr *tmp_ether_addr; - uint64_t rx_bar_off = 0; - uint64_t tx_bar_off = 0; - uint32_t start_q; + uint64_t rx_base; + uint64_t tx_base; int port = 0; int err; @@ -576,25 +575,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev) /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - return -ENODEV; - } + tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + rx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); - PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); + PMD_INIT_LOG(DEBUG, "tx_base: 0x%" PRIx64 "", tx_base); + PMD_INIT_LOG(DEBUG, "rx_base: 0x%" PRIx64 "", rx_base); - hw->tx_bar = pf_dev->qc_bar + tx_bar_off; - hw->rx_bar = pf_dev->qc_bar + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ; + hw->rx_bar = pf_dev->qc_bar + rx_base * NFP_QCP_QUEUE_ADDR_SZ; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -902,10 +890,17 @@ nfp_pf_init(struct rte_pci_device *pci_dev) char name[RTE_ETH_NAME_MAX_LEN]; struct nfp_rtsym_table *sym_tbl; struct nfp_eth_table *nfp_eth_table; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This @@ -976,27 +971,14 @@ nfp_pf_init(struct rte_pci_device *pci_dev) pf_dev->sym_tbl = sym_tbl; pf_dev->pci_dev = pci_dev; pf_dev->nfp_eth_table = nfp_eth_table; + pf_dev->dev_info = dev_info; /* configure access to tx/rx vNIC BARs */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP3800_OFFSET, - 0, NFP_PCIE_QUEUE_NFP3800_MASK); - break; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP6000_OFFSET, - 0, NFP_PCIE_QUEUE_NFP6000_MASK); - break; - default: - PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); - ret = -ENODEV; - goto pf_cleanup; - } - + addr = nfp_qcp_queue_offset(pf_dev->dev_info, 0); cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, - addr, NFP_QCP_QUEUE_AREA_SZ, + addr, pf_dev->dev_info->qc_area_sz, &pf_dev->qc_area); if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); @@ -1111,10 +1093,17 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) struct nfp_cpp *cpp; enum nfp_app_fw_id app_fw_id; struct nfp_rtsym_table *sym_tbl; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c index eaf815d06d..cf60e56c28 100644 --- a/drivers/net/nfp/nfp_ethdev_vf.c +++ b/drivers/net/nfp/nfp_ethdev_vf.c @@ -305,19 +305,10 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev) } /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_VF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - err = -ENODEV; - goto dev_err_ctrl_map; - } + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + tx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); + rx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c index f0c371ea2b..1b8bb3471d 100644 --- a/drivers/net/nfp/nfp_rxtx.c +++ b/drivers/net/nfp/nfp_rxtx.c @@ -677,7 +677,6 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; const struct rte_memzone *tz; @@ -689,9 +688,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); /* Validating number of descriptors */ rx_desc_sz = nb_desc * sizeof(struct nfp_net_rx_desc); diff --git a/drivers/net/nfp/nfp_rxtx.h b/drivers/net/nfp/nfp_rxtx.h index 48e548b02d..6d1c8e4605 100644 --- a/drivers/net/nfp/nfp_rxtx.h +++ b/drivers/net/nfp/nfp_rxtx.h @@ -74,18 +74,6 @@ struct nfp_meta_parsed { } vlan[NFP_META_MAX_VLANS]; }; -/* - * The maximum number of descriptors is limited by design as - * DPDK uses uint16_t variables for these values - */ -#define NFP_NET_MAX_TX_DESC (32 * 1024) -#define NFP_NET_MIN_TX_DESC 256 -#define NFP3800_NET_MIN_TX_DESC 512 - -#define NFP_NET_MAX_RX_DESC (32 * 1024) -#define NFP_NET_MIN_RX_DESC 256 -#define NFP3800_NET_MIN_RX_DESC 512 - /* Descriptor alignment */ #define NFP_ALIGN_RING_DESC 128 diff --git a/drivers/net/nfp/nfpcore/nfp_dev.c b/drivers/net/nfp/nfpcore/nfp_dev.c new file mode 100644 index 0000000000..7799fa699a --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_dev.h" + +#include <rte_bitops.h> + +#include "nfp_platform.h" + +/* + * Note: The value of 'max_qc_size' is different from kernel driver, + * because DPDK use 'uint16_t' as the data type. + */ +const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { + [NFP_DEV_NFP3800] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0x400000, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP3800", + .pcie_cfg_expbar_offset = 0x0a00, + .qc_area_sz = 0x100000, + .pf_num_per_unit = 4, + }, + [NFP_DEV_NFP3800_VF] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, + [NFP_DEV_NFP6000] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0x80000, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP4000/NFP6000", + .pcie_cfg_expbar_offset = 0x0400, + .qc_area_sz = 0x80000, + .pf_num_per_unit = 1, + }, + [NFP_DEV_NFP6000_VF] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, +}; + +const struct nfp_dev_info * +nfp_dev_info_get(uint16_t device_id) +{ + enum nfp_dev_id id; + + switch (device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + id = NFP_DEV_NFP3800; + break; + case PCI_DEVICE_ID_NFP3800_VF_NIC: + id = NFP_DEV_NFP3800_VF; + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + id = NFP_DEV_NFP6000; + break; + case PCI_DEVICE_ID_NFP6000_VF_NIC: + id = NFP_DEV_NFP6000_VF; + break; + default: + id = NFP_DEV_CNT; + break; + } + + if (id >= NFP_DEV_CNT) + return NULL; + + return &nfp_dev_info[id]; +} diff --git a/drivers/net/nfp/nfpcore/nfp_dev.h b/drivers/net/nfp/nfpcore/nfp_dev.h new file mode 100644 index 0000000000..b0fffff619 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_DEV_H__ +#define __NFP_DEV_H__ + +#include <stdint.h> + +#define PCI_VENDOR_ID_NETRONOME 0x19ee +#define PCI_VENDOR_ID_CORIGINE 0x1da8 + +#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 +#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 +#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 +#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 +#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ + +enum nfp_dev_id { + NFP_DEV_NFP3800, + NFP_DEV_NFP3800_VF, + NFP_DEV_NFP6000, + NFP_DEV_NFP6000_VF, + NFP_DEV_CNT, +}; + +struct nfp_dev_info { + /* Required fields */ + uint32_t qc_idx_mask; + uint32_t qc_addr_offset; + uint32_t min_qc_size; + uint32_t max_qc_size; + + /* PF-only fields */ + const char *chip_names; + uint32_t pcie_cfg_expbar_offset; + uint32_t qc_area_sz; + uint8_t pf_num_per_unit; +}; + +const struct nfp_dev_info *nfp_dev_info_get(uint16_t device_id); + +#endif /* __NFP_DEV_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 23/27] net/nfp: add header file for PCIe module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (21 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 22/27] net/nfp: add the dev module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 24/27] net/nfp: refact the cppcore module Chaoyong He ` (4 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add a new header file for the PCIe module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/meson.build | 2 +- .../nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} | 2 ++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 13 +++++++++++++ drivers/net/nfp/nfpcore/nfp_cpp.h | 6 ------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) rename drivers/net/nfp/nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} (99%) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 580a478cd6..d422269c4b 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -12,7 +12,6 @@ sources = files( 'flower/nfp_flower_representor.c', 'nfd3/nfp_nfd3_dp.c', 'nfdk/nfp_nfdk_dp.c', - 'nfpcore/nfp_cpp_pcie_ops.c', 'nfpcore/nfp_nsp.c', 'nfpcore/nfp_cppcore.c', 'nfpcore/nfp_resource.c', @@ -26,6 +25,7 @@ sources = files( 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', 'nfpcore/nfp_target.c', + 'nfpcore/nfp6000_pcie.c', 'nfp_common.c', 'nfp_rxtx.c', 'nfp_cpp_bridge.c', diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c similarity index 99% rename from drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c rename to drivers/net/nfp/nfpcore/nfp6000_pcie.c index 310cc691cd..abee584f85 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -14,6 +14,8 @@ * The generic CPP bus abstraction builds upon this BAR interface. */ +#include "nfp6000_pcie.h" + #include <assert.h> #include <stdio.h> #include <stdlib.h> diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h new file mode 100644 index 0000000000..e126457d45 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Netronome Systems, Inc. + * All rights reserved. + */ + +#ifndef __NFP6000_PCIE_H__ +#define __NFP6000_PCIE_H__ + +#include "nfp_cpp.h" + +const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); + +#endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 42c4df5fdd..0df97552cb 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,12 +226,6 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) return id & 0xff; } -/* - * This should be the only external function the transport - * module supplies - */ -const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); - void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f33985bec6..74b35f4a62 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -14,12 +14,12 @@ #include <rte_byteorder.h> #include <ethdev_pci.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" +#include "nfp6000_pcie.h" #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 24/27] net/nfp: refact the cppcore module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (22 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 23/27] net/nfp: add header file for PCIe module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 25/27] net/nfp: refact the PCIe module Chaoyong He ` (3 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Modify the comment and standard the coding style. Move the definition of data structure into the implement file to make the API small. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 14 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 40 ++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 186 ++++++++++++++++--------- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c index 88cd1aa572..a9998f3c08 100644 --- a/drivers/net/nfp/nfp_cpp_bridge.c +++ b/drivers/net/nfp/nfp_cpp_bridge.c @@ -344,7 +344,7 @@ nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp) return -EIO; } - tmp = cpp->interface; + tmp = nfp_cpp_interface(cpp); PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index c37d8a1449..5d129d0ad3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -654,15 +654,23 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) char fw_name[125]; char serial[40]; size_t fsize; + uint16_t interface; + uint32_t cpp_serial_len; + const uint8_t *cpp_serial; + + cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial); + if (cpp_serial_len != NFP_SERIAL_LEN) + return -ERANGE; + + interface = nfp_cpp_interface(cpp); /* Looking for firmware file in order of priority */ /* First try to find a firmware image specific for this device */ snprintf(serial, sizeof(serial), "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3], - cpp->serial[4], cpp->serial[5], cpp->interface >> 8, - cpp->interface & 0xff); + cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3], + cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff); snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH, serial); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index abee584f85..45645e04f8 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -739,7 +739,7 @@ nfp6000_init(struct nfp_cpp *cpp, strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; @@ -778,7 +778,7 @@ nfp6000_free(struct nfp_cpp *cpp) struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); nfp_disable_bars(desc); - if (cpp->driver_lock_needed) + if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); free(desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0df97552cb..34ed50ceca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -9,38 +9,12 @@ #include <ethdev_pci.h> /* NFP CPP handle */ -struct nfp_cpp { - uint32_t model; - uint32_t interface; - uint8_t *serial; - int serial_len; - void *priv; - - /* Mutex cache */ - struct nfp_cpp_mutex *mutex_cache; - const struct nfp_cpp_operations *op; - - /* - * NFP-6xxx originating island IMB CPP Address Translation. CPP Target - * ID is index into array. Values are obtained at runtime from local - * island XPB CSRs. - */ - uint32_t imb_cat_table[16]; - - /* MU access type bit offset */ - uint32_t mu_locality_lsb; - - int driver_lock_needed; -}; +struct nfp_cpp; /* NFP CPP device area handle */ -struct nfp_cpp_area { - struct nfp_cpp *cpp; - char *name; - unsigned long long offset; - unsigned long size; - /* Here follows the 'priv' part of nfp_cpp_area. */ -}; +struct nfp_cpp_area; + +#define NFP_SERIAL_LEN 6 /* * NFP CPP operations structure @@ -230,7 +204,7 @@ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); @@ -349,7 +323,9 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); + +bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp); struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 74b35f4a62..209d0b5160 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -3,30 +3,56 @@ * All rights reserved. */ -#include <assert.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> - -#include <rte_byteorder.h> -#include <ethdev_pci.h> +#include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_platform.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" -#include "nfp_nffw.h" #include "nfp6000_pcie.h" +#define NFP_PL_DEVICE_PART_NFP6000 0x6200 #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff #define NFP_PL_DEVICE_PART_MASK 0xffff0000 #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/* NFP CPP handle */ +struct nfp_cpp { + void *priv; /**< Private data of the low-level implementation */ + + uint32_t model; /**< Chip model */ + uint16_t interface; /**< Chip interface id */ + uint8_t serial[NFP_SERIAL_LEN]; /**< Chip serial number */ + + /** Low-level implementation ops */ + const struct nfp_cpp_operations *op; + + /* + * NFP-6xxx originating island IMB CPP Address Translation. CPP Target + * ID is index into array. Values are obtained at runtime from local + * island XPB CSRs. + */ + uint32_t imb_cat_table[16]; + + /**< MU access type bit offset */ + uint32_t mu_locality_lsb; + + bool driver_lock_needed; +}; + +/* NFP CPP device area handle */ +struct nfp_cpp_area { + struct nfp_cpp *cpp; + char *name; + uint64_t offset; + uint32_t size; + /* Here follows the 'priv' part of nfp_cpp_area. */ + /* Here follows the ASCII name, pointed by @name */ +}; + /** * Set the private data of the nfp_cpp instance * @@ -125,12 +151,13 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, * @return * Length of NFP serial number */ -int +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) { - *serial = cpp->serial; - return cpp->serial_len; + *serial = &cpp->serial[0]; + + return sizeof(cpp->serial); } /** @@ -143,22 +170,12 @@ nfp_cpp_serial(struct nfp_cpp *cpp, * @param serial_len * Length of the serial byte array */ -int +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len) { - if (cpp->serial_len) - free(cpp->serial); - - cpp->serial = malloc(serial_len); - if (cpp->serial == NULL) - return -1; - memcpy(cpp->serial, serial, serial_len); - cpp->serial_len = serial_len; - - return 0; } /** @@ -179,6 +196,21 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Retrieve the driver need lock flag + * + * @param cpp + * NFP CPP handle + * + * @return + * The driver need lock flag + */ +bool +nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp) +{ + return cpp->driver_lock_needed; +} + /** * Get the privately allocated portion of a NFP CPP area handle * @@ -283,39 +315,40 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t size) { int err; + size_t name_len; + uint32_t target_id; + uint64_t target_addr; struct nfp_cpp_area *area; - uint64_t tmp64 = (uint64_t)address; if (cpp == NULL) return NULL; /* Remap from cpp_island to cpp_target */ - err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table); + err = nfp_target_cpp(dest, address, &target_id, &target_addr, + cpp->imb_cat_table); if (err < 0) return NULL; - address = tmp64; - if (name == NULL) - name = ""; + name = "(reserved)"; - area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + name_len = strlen(name) + 1; + area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + name_len); if (area == NULL) return NULL; area->cpp = cpp; area->name = ((char *)area) + sizeof(*area) + cpp->op->area_priv_size; - memcpy(area->name, name, strlen(name) + 1); + memcpy(area->name, name, name_len); - err = cpp->op->area_init(area, dest, address, size); + err = cpp->op->area_init(area, target_id, target_addr, size); if (err < 0) { PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } - area->offset = address; + area->offset = target_addr; area->size = size; return area; @@ -555,26 +588,28 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, * Ensure that non-local XPB accesses go out through the * global XPBM bus. */ - island = ((*xpb_addr) >> 24) & 0x3f; + island = (*xpb_addr >> 24) & 0x3f; if (island == 0) return xpb; - if (island == 1) { - /* - * Accesses to the ARM Island overlay uses Island 0 - * Global Bit - */ - (*xpb_addr) &= ~0x7f000000; - if (*xpb_addr < 0x60000) - *xpb_addr |= (1 << 30); - else - /* And only non-ARM interfaces use island id = 1 */ - if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) - *xpb_addr |= (1 << 24); + if (island != 1) { + *xpb_addr |= (1 << 30); + return xpb; + } + + /* + * Accesses to the ARM Island overlay uses Island 0 + * Global Bit + */ + *xpb_addr &= ~0x7f000000; + if (*xpb_addr < 0x60000) { + *xpb_addr |= (1 << 30); } else { - (*xpb_addr) |= (1 << 30); + /* And only non-ARM interfaces use island id = 1 */ + if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != + NFP_CPP_INTERFACE_TYPE_ARM) + *xpb_addr |= (1 << 24); } return xpb; @@ -602,9 +637,12 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -629,7 +667,10 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, value = rte_cpu_to_le_32(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - return (sz == sizeof(value)) ? 0 : -1; + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; + + return 0; } /** @@ -654,9 +695,12 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, uint64_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_64(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -681,8 +725,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, value = rte_cpu_to_le_64(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -710,9 +756,12 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t tmp; sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -740,8 +789,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, value = rte_cpu_to_le_32(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -770,8 +821,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); *value = rte_le_to_cpu_64(tmp); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -799,8 +852,10 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, value = rte_cpu_to_le_64(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -918,9 +973,6 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len != 0) - free(cpp->serial); - rte_free(cpp); } @@ -974,7 +1026,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); - return -1; + return -EACCES; } err = nfp_cpp_area_read(area, 0, address, length); @@ -1013,7 +1065,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); - return -1; + return -EACCES; } err = nfp_cpp_area_write(area, 0, address, length); @@ -1039,8 +1091,12 @@ nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if (*model & NFP_PL_DEVICE_ID_MASK) - *model -= 0x10; + /* Disambiguate the NFP4000/NFP5000/NFP6000 chips */ + if (FIELD_GET(NFP_PL_DEVICE_PART_MASK, reg) == + NFP_PL_DEVICE_PART_NFP6000) { + if (*model & NFP_PL_DEVICE_ID_MASK) + *model -= 0x10; + } return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 25/27] net/nfp: refact the PCIe module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (23 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 24/27] net/nfp: refact the cppcore module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 26/27] net/nfp: refact the cppcore and " Chaoyong He ` (2 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 211 +++++++++++++++++-------- drivers/net/nfp/nfpcore/nfp_cpp.h | 9 ++ 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 45645e04f8..eb03571f99 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -16,23 +16,8 @@ #include "nfp6000_pcie.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> #include <unistd.h> -#include <stdint.h> -#include <stdbool.h> #include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <dirent.h> -#include <libgen.h> - -#include <sys/mman.h> -#include <sys/file.h> -#include <sys/stat.h> - -#include <ethdev_pci.h> #include "nfp_cpp.h" #include "nfp_logs.h" @@ -43,8 +28,11 @@ #define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) +#define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(_x) (((_x) >> 16) & 0x1f) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) +#define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS_OF(_x) (((_x) >> 0) & 0xffff) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT(_x) (((_x) & 0x3) << 27) +#define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(_x) (((_x) >> 27) & 0x3) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT 0 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT 1 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE 3 @@ -55,7 +43,9 @@ #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET 2 #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL 3 #define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(_x) (((_x) & 0xf) << 23) +#define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(_x) (((_x) >> 23) & 0xf) #define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(_x) (((_x) & 0x3) << 21) +#define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(_x) (((_x) >> 21) & 0x3) /* * Minimal size of the PCIe cfg memory we depend on being mapped, @@ -132,7 +122,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (target >= 16) + if (target >= NFP_CPP_NUM_TARGETS) return -EINVAL; switch (width) { @@ -182,10 +172,6 @@ nfp_compute_bar(const struct nfp_bar *bar, offset &= mask; bitsize = 40 - 21; } - - if (bar->bitsize < bitsize) - return -EINVAL; - newcfg |= offset >> bitsize; if (bar_base != NULL) @@ -434,7 +420,7 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Must have been too big. Sub-allocate. */ if (priv->bar->iomem == NULL) - return (-ENOMEM); + return -ENOMEM; priv->iomem = priv->bar->iomem + priv->bar_offset; @@ -464,9 +450,9 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32 = address; uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; @@ -484,47 +470,54 @@ nfp6000_area_read(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } - is_64 = width == TARGET_WIDTH_64; - - /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { - is_64 = false; - } + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; + ret = n; + break; + default: + return -EINVAL; + } + + return ret; } static int @@ -533,9 +526,9 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; @@ -553,47 +546,53 @@ nfp6000_area_write(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; - is_64 = width == TARGET_WIDTH_64; - - /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) - is_64 = false; + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; -} + ret = n; + break; + default: + return -EINVAL; + } -#define PCI_DEVICES "/sys/bus/pci/devices" + return ret; +} static int nfp_acquire_process_lock(struct nfp_pcie_user *desc) @@ -706,6 +705,74 @@ nfp6000_set_serial(struct rte_pci_device *dev, return 0; } +static int +nfp6000_get_dsn(struct rte_pci_device *pci_dev, + uint64_t *dsn) +{ + off_t pos; + size_t len; + uint64_t tmp; + + pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN); + if (pos <= 0) { + PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found"); + return -ENODEV; + } + + pos += 4; + len = sizeof(tmp); + + if (rte_pci_read_config(pci_dev, &tmp, len, pos) < 0) { + PMD_DRV_LOG(ERR, "nfp get device serial number failed"); + return -ENOENT; + } + + *dsn = tmp; + + return 0; +} + +static int +nfp6000_get_interface(struct rte_pci_device *dev, + uint16_t *interface) +{ + int ret; + uint64_t dsn; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + *interface = dsn & 0xffff; + + return 0; +} + +static int +nfp6000_get_serial(struct rte_pci_device *dev, + uint8_t *serial, + size_t length) +{ + int ret; + uint64_t dsn; + + if (length < NFP_SERIAL_LEN) + return -ENOMEM; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + serial[0] = (dsn >> 56) & 0xff; + serial[1] = (dsn >> 48) & 0xff; + serial[2] = (dsn >> 40) & 0xff; + serial[3] = (dsn >> 32) & 0xff; + serial[4] = (dsn >> 24) & 0xff; + serial[5] = (dsn >> 16) & 0xff; + + return 0; +} + static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) @@ -789,6 +856,10 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .free = nfp6000_free, .area_priv_size = sizeof(struct nfp6000_area_priv), + + .get_interface = nfp6000_get_interface, + .get_serial = nfp6000_get_serial, + .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 34ed50ceca..0f36ba0b50 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -16,6 +16,8 @@ struct nfp_cpp_area; #define NFP_SERIAL_LEN 6 +#define NFP_CPP_NUM_TARGETS 16 + /* * NFP CPP operations structure */ @@ -33,6 +35,13 @@ struct nfp_cpp_operations { */ void (*free)(struct nfp_cpp *cpp); + int (*get_interface)(struct rte_pci_device *dev, + uint16_t *interface); + + int (*get_serial)(struct rte_pci_device *dev, + uint8_t *serial, + size_t length); + /* * Initialize a new NFP CPP area * NOTE: This is _not_ serialized -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 26/27] net/nfp: refact the cppcore and PCIe module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (24 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 25/27] net/nfp: refact the PCIe module Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-24 11:09 ` [PATCH 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver, use the new entry function from the PCIe module instead of the cppcore module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 9 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 197 ++++++++++--------------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 6 + drivers/net/nfp/nfpcore/nfp_cpp.h | 36 +---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 68 ++++++--- 5 files changed, 141 insertions(+), 175 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 5d129d0ad3..6eefec3836 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -23,6 +23,7 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.h" #include "nfpcore/nfp_nsp.h" +#include "nfpcore/nfp6000_pcie.h" #include "nfp_common.h" #include "nfp_ctrl.h" @@ -917,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1120,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index eb03571f99..a3bc7a14c4 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -98,6 +98,24 @@ struct nfp_pcie_user { char *cfg; }; +/* Generic CPP bus access interface. */ +struct nfp6000_area_priv { + struct nfp_bar *bar; + uint32_t bar_offset; + + int target; + int action; + int token; + uint64_t offset; + struct { + int read; + int write; + int bar; + } width; + size_t size; + char *iomem; +}; + static uint32_t nfp_bar_maptype(struct nfp_bar *bar) { @@ -334,24 +352,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* Generic CPP bus access interface. */ -struct nfp6000_area_priv { - struct nfp_bar *bar; - uint32_t bar_offset; - - uint32_t target; - uint32_t action; - uint32_t token; - uint64_t offset; - struct { - int read; - int write; - int bar; - } width; - size_t size; - char *iomem; -}; - static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, @@ -624,87 +624,6 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) return 0; } -static int -nfp6000_set_model(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint32_t model; - - if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { - PMD_DRV_LOG(ERR, "nfp set model failed"); - return -1; - } - - model = model << 16; - nfp_cpp_model_set(cpp, model); - - return 0; -} - -static int -nfp6000_set_interface(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint16_t interface; - - if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { - PMD_DRV_LOG(ERR, "nfp set interface failed"); - return -1; - } - - nfp_cpp_interface_set(cpp, interface); - - return 0; -} - -static int -nfp6000_set_serial(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - off_t pos; - uint16_t tmp; - uint8_t serial[6]; - int serial_len = 6; - - pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); - if (pos <= 0) { - PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found. nfp set serial failed"); - return -1; - } else { - pos += 6; - } - - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[4] = (uint8_t)((tmp >> 8) & 0xff); - serial[5] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[2] = (uint8_t)((tmp >> 8) & 0xff); - serial[3] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[0] = (uint8_t)((tmp >> 8) & 0xff); - serial[1] = (uint8_t)(tmp & 0xff); - - nfp_cpp_serial_set(cpp, serial, serial_len); - - return 0; -} - static int nfp6000_get_dsn(struct rte_pci_device *pci_dev, uint64_t *dsn) @@ -795,12 +714,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { int ret = 0; - struct nfp_pcie_user *desc; - - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return -1; - + struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); @@ -809,17 +723,11 @@ nfp6000_init(struct nfp_cpp *cpp, nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) - goto error; + return -1; } - if (nfp6000_set_model(dev, cpp) < 0) - goto error; - if (nfp6000_set_interface(dev, cpp) < 0) - goto error; - if (nfp6000_set_serial(dev, cpp) < 0) - goto error; if (nfp6000_set_barsz(dev, desc) < 0) - goto error; + return -1; desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; @@ -830,13 +738,7 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - nfp_cpp_priv_set(cpp, desc); - return 0; - -error: - free(desc); - return -1; } static void @@ -848,7 +750,7 @@ nfp6000_free(struct nfp_cpp *cpp) if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); - free(desc); + rte_free(desc); } static const struct nfp_cpp_operations nfp6000_pcie_ops = { @@ -873,3 +775,58 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) { return &nfp6000_pcie_ops; } + +/** + * Build a NFP CPP bus from a NFP6000 PCI device + * + * @param pdev + * NFP6000 PCI device + * @param driver_lock_needed + * driver lock flag + * + * @return + * NFP CPP handle or NULL + */ +struct nfp_cpp * +nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed) +{ + int ret; + uint16_t interface; + struct nfp_cpp *cpp; + struct nfp_pcie_user *nfp; + + nfp = rte_zmalloc(NULL, sizeof(*nfp), 0); + if (nfp == NULL) + return NULL; + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + rte_free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_TYPE_of(interface) != NFP_CPP_INTERFACE_TYPE_PCI) { + PMD_DRV_LOG(ERR, "Interface type is not right."); + rte_free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_CHANNEL_of(interface) != + NFP_CPP_INTERFACE_CHANNEL_PEROPENER) { + PMD_DRV_LOG(ERR, "Interface channel is not right"); + rte_free(nfp); + return NULL; + } + + /* Probe for all the common NFP devices */ + cpp = nfp_cpp_from_device_name(pci_dev, nfp, driver_lock_needed); + if (cpp == NULL) { + PMD_DRV_LOG(ERR, "Get cpp from operation failed"); + rte_free(nfp); + return NULL; + } + + return cpp; +} diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index e126457d45..8847f6f946 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -6,8 +6,14 @@ #ifndef __NFP6000_PCIE_H__ #define __NFP6000_PCIE_H__ +#include <ethdev_pci.h> + #include "nfp_cpp.h" +#include "nfp_dev.h" const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); +struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed); + #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0f36ba0b50..e879c7c920 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,40 +226,12 @@ uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + void *priv, bool driver_lock_needed); void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/** - * Retrieve the chip ID from the model ID - * - * The chip ID is a 16-bit BCD+A-F encoding for the chip type. - * - * @param model - * NFP CPP model id - * - * @return - * NFP CPP chip id - */ -#define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) - -/** - * Check for the NFP6000 family of devices - * - * NOTE: The NFP4000 series is considered as a NFP6000 series variant. - * - * @param model - * NFP CPP model id - * - * @return - * true if model is in the NFP6000 family, false otherwise. - */ -#define NFP_CPP_MODEL_IS_6000(model) \ - ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ - (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) - uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,6 +302,12 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) +/* + * Use this channel ID for multiple virtual channel interfaces + * (ie ARM and PCIe) when setting up the interface field. + */ +#define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255 + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 209d0b5160..6f46dbf5b7 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -909,10 +909,13 @@ nfp_xpb_readl(struct nfp_cpp *cpp, } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, - int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *pci_dev, + void *priv, + bool driver_lock_needed) { int err; + size_t target; + uint32_t xpb_addr; struct nfp_cpp *cpp; const struct nfp_cpp_operations *ops; @@ -925,32 +928,50 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return NULL; cpp->op = ops; + cpp->priv = priv; cpp->driver_lock_needed = driver_lock_needed; - if (cpp->op->init) { - err = cpp->op->init(cpp, dev); + err = ops->get_interface(pci_dev, &cpp->interface); + if (err != 0) { + rte_free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + rte_free(cpp); + return NULL; + } + + /* + * NOTE: cpp_lock is NOT locked for op->init, + * since it may call NFP CPP API operations + */ + err = cpp->op->init(cpp, pci_dev); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP interface initialization failed"); + rte_free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + rte_free(cpp); + return NULL; + } + + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { + /* Hardcoded XPB IMB Base, island 0 */ + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, &cpp->imb_cat_table[target]); if (err < 0) { + PMD_DRV_LOG(ERR, "Can't read CPP mapping from device"); rte_free(cpp); return NULL; } } - if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpb_addr; - size_t target; - - for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { - /* Hardcoded XPB IMB Base, island 0 */ - xpb_addr = 0x000a0000 + (target * 4); - err = nfp_xpb_readl(cpp, xpb_addr, - (uint32_t *)&cpp->imb_cat_table[target]); - if (err < 0) { - rte_free(cpp); - return NULL; - } - } - } - err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); @@ -981,6 +1002,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) * * @param dev * PCI device + * @param priv + * Private data of low-level implementation * @param driver_lock_needed * Driver lock flag * @@ -991,9 +1014,10 @@ nfp_cpp_free(struct nfp_cpp *cpp) */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed) + void *priv, + bool driver_lock_needed) { - return nfp_cpp_alloc(dev, driver_lock_needed); + return nfp_cpp_alloc(dev, priv, driver_lock_needed); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (25 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 26/27] net/nfp: refact the cppcore and " Chaoyong He @ 2023-08-24 11:09 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-24 11:09 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver, adjust the definition of structure, and extend the usage of nfp BAR from 8 to 24. This will greatly enhance the scalability of nfp PMD. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 8 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 475 ++++++++++++++++++------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 1 + drivers/net/nfp/nfpcore/nfp_cpp.h | 5 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 346 insertions(+), 145 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 6eefec3836..d6454d8964 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -918,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1121,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index a3bc7a14c4..525c372aa7 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -19,6 +19,8 @@ #include <unistd.h> #include <fcntl.h> +#include <rte_io.h> + #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" @@ -59,20 +61,12 @@ #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4)) #define NFP_PCIE_P2C_GENERAL_SIZE(bar) (1 << ((bar)->bitsize - 4)) -#define NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(id, bar, slot) \ - (NFP_PCIE_BAR(id) + ((bar) * 8 + (slot)) * 4) - -#define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ - (((bar) * 8 + (slot)) * 4) +#define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index) ((bar_index) * 4) struct nfp_pcie_user; struct nfp6000_area_priv; /* Describes BAR configuration and usage */ -#define NFP_BAR_MIN 1 -#define NFP_BAR_MID 5 -#define NFP_BAR_MAX 7 - struct nfp_bar { struct nfp_pcie_user *nfp; /**< Backlink to owner */ uint32_t barcfg; /**< BAR config CSR */ @@ -80,22 +74,26 @@ struct nfp_bar { uint64_t mask; /**< Mask of the BAR aperture (read only) */ uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ uint32_t index; /**< Index of the BAR */ - int lock; /**< If the BAR has been locked */ + bool lock; /**< If the BAR has been locked */ - char *csr; char *iomem; /**< mapped IO memory */ + struct rte_mem_resource *resource; /**< IOMEM resource window */ }; -#define BUSDEV_SZ 13 +#define NFP_PCI_BAR_MAX (PCI_64BIT_BAR_COUNT * 8) + struct nfp_pcie_user { - struct nfp_bar bar[NFP_BAR_MAX]; + struct rte_pci_device *pci_dev; + const struct nfp_dev_info *dev_info; - int device; int lock; - char busdev[BUSDEV_SZ]; - int barsz; - int dev_id; - char *cfg; + + /* PCI BAR management */ + uint32_t bars; + struct nfp_bar bar[NFP_PCI_BAR_MAX]; + + /* Reserved BAR access */ + char *csr; }; /* Generic CPP bus access interface. */ @@ -206,19 +204,19 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base; - int slot; - - base = bar->index >> 3; - slot = bar->index & 7; + uint32_t xbar; - if (nfp->cfg == NULL) - return (-ENOMEM); + xbar = NFP_PCIE_P2C_EXPBAR_OFFSET(bar->index); - bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); - - *(uint32_t *)(bar->csr) = newcfg; + if (nfp->csr != NULL) { + rte_write32(newcfg, nfp->csr + xbar); + /* Readback to ensure BAR is flushed */ + rte_read32(nfp->csr + xbar); + } else { + xbar += nfp->dev_info->pcie_cfg_expbar_offset; + rte_pci_write_config(nfp->pci_dev, &newcfg, sizeof(uint32_t), + xbar); + } bar->barcfg = newcfg; @@ -249,105 +247,320 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, return nfp_bar_write(nfp, bar, newcfg); } -/* - * Map all PCI bars. We assume that the BAR with the PCIe config block is - * already mapped. +static uint32_t +nfp_bitsize_calc(uint64_t mask) +{ + uint64_t tmp = mask; + uint32_t bit_size = 0; + + if (tmp == 0) + return 0; + + for (; tmp != 0; tmp >>= 1) + bit_size++; + + return bit_size; +} + +static int +nfp_cmp_bars(const void *ptr_a, + const void *ptr_b) +{ + const struct nfp_bar *a = ptr_a; + const struct nfp_bar *b = ptr_b; + + if (a->bitsize == b->bitsize) + return a->index - b->index; + else + return a->bitsize - b->bitsize; +} + +static bool +nfp_bars_for_secondary(uint32_t index) +{ + uint8_t tmp = index & 0x07; + + if (tmp == 0x06 || tmp == 0x07) + return true; + else + return false; +} + +/** + * Map all PCI bars and fetch the actual BAR configurations from the board. + * We assume that the BAR with the PCIe config block is already mapped. * * BAR0.0: Reserved for General Mapping (for MSI-X access to PCIe SRAM) + * BAR0.1: -- + * BAR0.2: -- + * BAR0.3: -- + * BAR0.4: -- + * BAR0.5: -- + * BAR0.6: -- + * BAR0.7: -- * - * Halving PCItoCPPBars for primary and secondary processes. - * For CoreNIC firmware: - * NFP PMD just requires two fixed slots, one for configuration BAR, - * and another for accessing the hw queues. Another slot is needed - * for setting the link up or down. Secondary processes do not need - * to map the first two slots again, but it requires one slot for - * accessing the link, even if it is not likely the secondary process - * starting the port. - * For Flower firmware: - * NFP PMD need another fixed slots, used as the configureation BAR - * for ctrl vNIC. + * BAR1.0-BAR1.7: -- + * BAR2.0-BAR2.7: -- */ static int nfp_enable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + int pf; + uint32_t i; + uint8_t min_bars; struct nfp_bar *bar; + enum rte_proc_type_t type; + struct rte_mem_resource *res; + const uint32_t barcfg_msix_general = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) | + NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT; + + type = rte_eal_process_type(); + if (type == RTE_PROC_PRIMARY) + min_bars = 12; + else + min_bars = 4; + + for (i = 0; i < RTE_DIM(nfp->bar); i++) { + if (i != 0) { + if (type == RTE_PROC_PRIMARY) { + if (nfp_bars_for_secondary(i)) + continue; + } else { + if (!nfp_bars_for_secondary(i)) + continue; + } + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* 24 NFP bars mapping into BAR0, BAR2 and BAR4 */ + res = &nfp->pci_dev->mem_resource[(i >> 3) * 2]; + + /* Skip over BARs that are not mapped */ + if (res->addr != NULL) { + bar = &nfp->bar[i]; + bar->resource = res; + bar->barcfg = 0; + + bar->nfp = nfp; + bar->index = i; + /* The resource shared by 8 bars */ + bar->mask = (res->len >> 3) - 1; + bar->bitsize = nfp_bitsize_calc(bar->mask); + bar->base = 0; + bar->lock = false; + bar->iomem = (char *)res->addr + + ((bar->index & 7) << bar->bitsize); + + nfp->bars++; + } + } + + if (nfp->bars < min_bars) { + PMD_DRV_LOG(ERR, "Not enough usable BARs found."); + return -EINVAL; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - bar->barcfg = 0; - bar->nfp = nfp; - bar->index = x; - bar->mask = (1 << (nfp->barsz - 3)) - 1; - bar->bitsize = nfp->barsz - 3; - bar->base = 0; - bar->iomem = NULL; - bar->lock = 0; - bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, - bar->index >> 3, bar->index & 7); - bar->iomem = nfp->cfg + (bar->index << bar->bitsize); + switch (nfp->pci_dev->id.device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + pf = nfp->pci_dev->addr.function & 0x07; + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(pf); + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(0); + break; + default: + PMD_DRV_LOG(ERR, "Unsupported device ID: %04hx!", + nfp->pci_dev->id.device_id); + return -EINVAL; } + + /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */ + bar = &nfp->bar[0]; + bar->lock = true; + + nfp_bar_write(nfp, bar, barcfg_msix_general); + + /* Sort bars by bit size - use the smallest possible first. */ + qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars); + return 0; } -static struct nfp_bar * -nfp_alloc_bar(struct nfp_pcie_user *nfp) +/* Check if BAR can be used with the given parameters. */ +static bool +matching_bar_exist(struct nfp_bar *bar, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) { - int x; - int end; - int start; - struct nfp_bar *bar; + int bar_width; + int bar_token; + int bar_target; + int bar_action; + uint32_t map_type; + + bar_width = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(bar->barcfg); + switch (bar_width) { + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT: + bar_width = 4; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT: + bar_width = 8; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE: + bar_width = 0; + break; + default: + bar_width = -1; + break; + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* Make sure to match up the width */ + if (bar_width != width) + return false; + + bar_token = NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(bar->barcfg); + bar_action = NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(bar->barcfg); + map_type = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_OF(bar->barcfg); + switch (map_type) { + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET: + bar_token = -1; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK: + bar_action = NFP_CPP_ACTION_RW; + if (action == 0) + action = NFP_CPP_ACTION_RW; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED: + break; + default: + /* We don't match explicit bars through the area interface */ + return false; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->lock == 0) { - bar->lock = 1; - return bar; - } + bar_target = NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(bar->barcfg); + if ((bar_target < 0 || bar_target == target) && + (bar_token < 0 || bar_token == token) && + bar_action == action && + bar->base <= offset && + (bar->base + (1 << bar->bitsize)) >= (offset + size)) + return true; + + /* No match */ + return false; +} + +static int +find_matching_bar(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + uint32_t n; + + for (n = 0; n < nfp->bars; n++) { + struct nfp_bar *bar = &nfp->bar[n]; + + if (matching_bar_exist(bar, target, action, token, + offset, size, width)) + return n; + } + + return -1; +} + +/* Return EAGAIN if no resource is available */ +static int +find_unused_bar_noblock(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + int ret; + uint32_t n; + const struct nfp_bar *bar; + + for (n = 0; n < nfp->bars; n++) { + bar = &nfp->bar[n]; + + if (bar->bitsize == 0) + continue; + + /* Just check to see if we can make it fit... */ + ret = nfp_compute_bar(bar, NULL, NULL, target, action, + token, offset, size, width); + if (ret != 0) + continue; + + if (!bar->lock) + return n; + } + + return -EAGAIN; +} + +static int +nfp_alloc_bar(struct nfp_pcie_user *nfp, + struct nfp6000_area_priv *priv) +{ + int ret; + int bar_num; + size_t size = priv->size; + int token = priv->token; + int target = priv->target; + int action = priv->action; + int width = priv->width.bar; + uint64_t offset = priv->offset; + + /* Bar size should small than 16MB */ + if (size > (1 << 24)) + return -EINVAL; + + bar_num = find_matching_bar(nfp, target, action, token, + offset, size, width); + if (bar_num >= 0) { + /* Found a perfect match. */ + nfp->bar[bar_num].lock = true; + return bar_num; } - return NULL; + bar_num = find_unused_bar_noblock(nfp, target, action, token, + offset, size, width); + if (bar_num < 0) + return bar_num; + + nfp->bar[bar_num].lock = true; + ret = nfp_reconfigure_bar(nfp, &nfp->bar[bar_num], + target, action, token, offset, size, width); + if (ret < 0) { + nfp->bar[bar_num].lock = false; + return ret; + } + + return bar_num; } static void nfp_disable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + uint32_t i; struct nfp_bar *bar; - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; - } - - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->iomem) { + for (i = 0; i < nfp->bars; i++) { + bar = &nfp->bar[i]; + if (bar->iomem != NULL) { bar->iomem = NULL; - bar->lock = 0; + bar->lock = false; } } } @@ -364,7 +577,6 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -383,9 +595,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, else priv->width.bar = priv->width.write; - priv->bar = nfp_alloc_bar(nfp); - if (priv->bar == NULL) - return -ENOMEM; + priv->bar = NULL; priv->target = target; priv->action = action; @@ -393,17 +603,29 @@ nfp6000_area_init(struct nfp_cpp_area *area, priv->offset = address; priv->size = size; - ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); - return ret; } static int nfp6000_area_acquire(struct nfp_cpp_area *area) { + int bar_num; struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); + + /* Already allocated. */ + if (priv->bar != NULL) + return 0; + + bar_num = nfp_alloc_bar(nfp, priv); + if (bar_num < 0) { + PMD_DRV_LOG(ERR, "Failed to allocate bar %d:%d:%d:%#lx: %d", + priv->target, priv->action, priv->token, + priv->offset, bar_num); + return bar_num; + } + + priv->bar = &nfp->bar[bar_num]; /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == @@ -432,7 +654,7 @@ nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - priv->bar->lock = 0; + priv->bar->lock = false; priv->bar = NULL; priv->iomem = NULL; } @@ -603,7 +825,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) memset(&lock, 0, sizeof(lock)); - snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", desc->busdev); + snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", + desc->pci_dev->device.name); desc->lock = open(lockname, O_RDWR | O_CREAT, 0666); if (desc->lock < 0) return desc->lock; @@ -693,32 +916,11 @@ nfp6000_get_serial(struct rte_pci_device *dev, } static int -nfp6000_set_barsz(struct rte_pci_device *dev, - struct nfp_pcie_user *desc) -{ - int i = 0; - uint64_t tmp; - - tmp = dev->mem_resource[0].len; - - while (tmp >>= 1) - i++; - - desc->barsz = i; - - return 0; -} - -static int -nfp6000_init(struct nfp_cpp *cpp, - struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp) { int ret = 0; struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - memset(desc->busdev, 0, BUSDEV_SZ); - strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); - if (rte_eal_process_type() == RTE_PROC_PRIMARY && nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); @@ -726,12 +928,6 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - if (nfp6000_set_barsz(dev, desc) < 0) - return -1; - - desc->cfg = dev->mem_resource[0].addr; - desc->dev_id = dev->addr.function & 0x7; - ret = nfp_enable_bars(desc); if (ret != 0) { PMD_DRV_LOG(ERR, "Enable bars failed"); @@ -749,7 +945,6 @@ nfp6000_free(struct nfp_cpp *cpp) nfp_disable_bars(desc); if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); - close(desc->device); rte_free(desc); } @@ -789,6 +984,7 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) */ struct nfp_cpp * nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed) { int ret; @@ -800,6 +996,9 @@ nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, if (nfp == NULL) return NULL; + nfp->pci_dev = pci_dev; + nfp->dev_info = dev_info; + ret = nfp6000_get_interface(pci_dev, &interface); if (ret != 0) { PMD_DRV_LOG(ERR, "Get interface failed."); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index 8847f6f946..8e2cfb69e6 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -14,6 +14,7 @@ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed); #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index e879c7c920..2defc4fa16 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -18,6 +18,8 @@ struct nfp_cpp_area; #define NFP_CPP_NUM_TARGETS 16 +#define PCI_64BIT_BAR_COUNT 3 + /* * NFP CPP operations structure */ @@ -26,8 +28,7 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, - struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp); /* * Free the bus. diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6f46dbf5b7..8a55670f84 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -947,7 +947,7 @@ nfp_cpp_alloc(struct rte_pci_device *pci_dev, * NOTE: cpp_lock is NOT locked for op->init, * since it may call NFP CPP API operations */ - err = cpp->op->init(cpp, pci_dev); + err = cpp->op->init(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "NFP interface initialization failed"); rte_free(cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 00/27] refact the nfpcore module 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He ` (26 preceding siblings ...) 2023-08-24 11:09 ` [PATCH 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He ` (27 more replies) 27 siblings, 28 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He This patch series aims to: - Make the coding style satisfy with DPDK. - Sync the logic with kernel driver. - Make the sub-module more modular. - Extend the nfp configure BAR from 8 to 24. --- v2: * Fix the compile error in Fodora 37 environment. --- Chaoyong He (27): net/nfp: explicitly compare to null and 0 net/nfp: unify the indent coding style net/nfp: unify the type of integer variable net/nfp: remove the unneeded logic net/nfp: standard the local variable coding style net/nfp: adjust the log statement net/nfp: standard the comment style net/nfp: using the DPDK memory management API net/nfp: standard the blank character net/nfp: unify the guide line of header file net/nfp: rename some parameter and variable net/nfp: refact the hwinfo module net/nfp: refact the nffw module net/nfp: refact the mip module net/nfp: refact the rtsym module net/nfp: refact the resource module net/nfp: refact the target module net/nfp: add a new header file net/nfp: refact the nsp module net/nfp: refact the mutex module net/nfp: rename data field to sync with kernel driver net/nfp: add the dev module net/nfp: add header file for PCIe module net/nfp: refact the cppcore module net/nfp: refact the PCIe module net/nfp: refact the cppcore and PCIe module net/nfp: extend the usage of nfp BAR from 8 to 24 drivers/net/nfp/flower/nfp_flower.c | 14 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 3 +- drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 +- drivers/net/nfp/nfp_common.h | 52 +- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 108 +- drivers/net/nfp/nfp_ethdev_vf.c | 17 +- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 - drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 - drivers/net/nfp/nfpcore/nfp6000_pcie.c | 1031 ++++++++++++++++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 20 + drivers/net/nfp/nfpcore/nfp_cpp.h | 776 +++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 824 ------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 1088 +++++++++++------ drivers/net/nfp/nfpcore/nfp_dev.c | 81 ++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 199 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 74 +- drivers/net/nfp/nfpcore/nfp_mip.c | 103 +- drivers/net/nfp/nfpcore/nfp_mip.h | 7 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 383 +++--- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 + drivers/net/nfp/nfpcore/nfp_nffw.c | 207 ++-- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 580 ++++++--- drivers/net/nfp/nfpcore/nfp_nsp.h | 336 ++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 27 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 534 ++++---- drivers/net/nfp/nfpcore/nfp_platform.h | 42 + drivers/net/nfp/nfpcore/nfp_resource.c | 216 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 36 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 452 +++++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 67 +- drivers/net/nfp/nfpcore/nfp_target.c | 9 +- drivers/net/nfp/nfpcore/nfp_target.h | 597 +-------- 39 files changed, 4080 insertions(+), 4043 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.c create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h delete mode 100644 drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 01/27] net/nfp: explicitly compare to null and 0 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 02/27] net/nfp: unify the indent coding style Chaoyong He ` (26 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He To compliance with the coding standard, make the pointer variable explicitly comparing to 'NULL' and the integer variable explicitly comparing to '0'. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 ++++++------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++++++------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 20 ++++++++++---------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_resource.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 4 ++-- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 658c618ee6..2ee60eefc3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -224,10 +224,10 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, newcfg |= offset >> bitsize; - if (bar_base) + if (bar_base != NULL) *bar_base = offset; - if (bar_config) + if (bar_config != NULL) *bar_config = newcfg; return 0; @@ -266,7 +266,7 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); - if (err) + if (err != 0) return err; bar->base = newbase; @@ -515,7 +515,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) { + if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } @@ -583,7 +583,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) + if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; is_64 = width == TARGET_WIDTH_64; @@ -764,7 +764,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) if (rte_eal_process_type() == RTE_PROC_PRIMARY && cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); - if (ret) + if (ret != 0) goto error; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6daee313ce..2c6ec3e126 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -235,7 +235,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, if (area == NULL) return NULL; - if (nfp_cpp_area_acquire(area)) { + if (nfp_cpp_area_acquire(area) != 0) { nfp_cpp_area_free(area); return NULL; } @@ -252,7 +252,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, void nfp_cpp_area_free(struct nfp_cpp_area *area) { - if (area->cpp->op->area_cleanup) + if (area->cpp->op->area_cleanup != NULL) area->cpp->op->area_cleanup(area); free(area); } @@ -280,7 +280,7 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) int nfp_cpp_area_acquire(struct nfp_cpp_area *area) { - if (area->cpp->op->area_acquire) { + if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); if (err < 0) @@ -299,7 +299,7 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) void nfp_cpp_area_release(struct nfp_cpp_area *area) { - if (area->cpp->op->area_release) + if (area->cpp->op->area_release != NULL) area->cpp->op->area_release(area); } @@ -319,7 +319,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) { void *iomem = NULL; - if (area->cpp->op->area_iomem) + if (area->cpp->op->area_iomem != NULL) iomem = area->cpp->op->area_iomem(area); return iomem; @@ -621,10 +621,10 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) void nfp_cpp_free(struct nfp_cpp *cpp) { - if (cpp->op && cpp->op->free) + if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len) + if (cpp->serial_len != 0) free(cpp->serial); free(cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 9054bb0315..a9d166c4dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -37,7 +37,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { const char *key, *val, *end = hwinfo->data + size; - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { @@ -141,7 +141,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); - if (db) + if (db != NULL) return db; nanosleep(&wait, NULL); @@ -164,7 +164,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return NULL; err = nfp_hwinfo_db_validate(db, hwdb_size); - if (err) { + if (err != 0) { free(db); return NULL; } @@ -188,7 +188,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 6b392ad5eb..f9723dd136 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -75,7 +75,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) return -ENODEV; err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr); - if (err) + if (err != 0) goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); @@ -105,7 +105,7 @@ nfp_mip_open(struct nfp_cpp *cpp) return NULL; err = nfp_mip_read_resource(cpp, mip); - if (err) { + if (err != 0) { free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index f967a29351..0410a00856 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -38,7 +38,7 @@ static int _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) { /* Address must be 64-bit aligned */ - if (address & 7) + if ((address & 7) != 0) return -EINVAL; if (NFP_CPP_MODEL_IS_6000(model)) { diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 07d63900dc..433780a5e7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -190,7 +190,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; for (i = 0; i < cnt; i++) - if (nffw_fwinfo_loaded_get(&fwinfo[i])) + if (nffw_fwinfo_loaded_get(&fwinfo[i]) != 0) return &fwinfo[i]; return NULL; @@ -217,7 +217,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); *off = nffw_fwinfo_mip_offset_get(fwinfo); - if (nffw_fwinfo_mip_mu_da_get(fwinfo)) { + if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 1f6b7bd85c..6474abf0c2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -95,7 +95,7 @@ nfp_nsp_check(struct nfp_nsp *state) return -EINVAL; } - if (reg & NSP_STATUS_BUSY) { + if ((reg & NSP_STATUS_BUSY) != 0) { PMD_DRV_LOG(ERR, "Service processor busy!"); return -EBUSY; } @@ -128,7 +128,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) state->res = res; err = nfp_nsp_check(state); - if (err) { + if (err != 0) { nfp_nsp_close(state); return NULL; } @@ -219,7 +219,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err) + if (err != 0) return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || @@ -245,7 +245,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -254,7 +254,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_STATUS_BUSY to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -266,7 +266,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); @@ -319,13 +319,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); - if (in_buf && in_size) { + if (in_buf != NULL && in_size > 0) { err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf && out_size && out_size > in_size) { + if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, out_size - in_size); @@ -337,7 +337,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (ret < 0) return ret; - if (out_buf && out_size) { + if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); if (err < 0) return err; @@ -369,7 +369,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } - if (err) + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 01b4652280..825a84a8cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -212,7 +212,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, dst->fec_modes_supported |= fec << NFP_FEC_BASER_BIT; fec = FIELD_GET(NSP_ETH_PORT_FEC_SUPP_RS, port); dst->fec_modes_supported |= fec << NFP_FEC_REED_SOLOMON_BIT; - if (dst->fec_modes_supported) + if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); @@ -285,7 +285,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) cnt++; } @@ -294,7 +294,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * those that give a port count, verify it against the value calculated * above. */ - if (ret && ret != cnt) { + if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; @@ -309,7 +309,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); @@ -621,7 +621,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) return -EIO; err = __nfp_eth_set_fec(nsp, mode); - if (err) { + if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 351bc623ed..838cd6e0ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -115,15 +115,15 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, { int err; - if (nfp_cpp_mutex_lock(dev_mutex)) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) return -EINVAL; err = nfp_cpp_resource_find(cpp, res); - if (err) + if (err != 0) goto err_unlock_dev; err = nfp_cpp_mutex_trylock(res->mutex); - if (err) + if (err != 0) goto err_res_mutex_free; nfp_cpp_mutex_unlock(dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 343b0d0bcf..4c45aec5c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -362,10 +362,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) if (err) err = -EIO; exit: - if (error) + if (error != NULL) *error = err; - if (err) + if (err != 0) return ~0ULL; return val; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 02/27] net/nfp: unify the indent coding style 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 03/27] net/nfp: unify the type of integer variable Chaoyong He ` (25 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Each parameter of function should occupy one line, and indent two TAB character. All the statement which span multi line should indent two TAB character. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 80 +++++----- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 152 ++++++++++-------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 173 +++++++++++++-------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 23 +-- drivers/net/nfp/nfpcore/nfp_mip.c | 21 ++- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 108 +++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 19 +-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 69 ++++---- drivers/net/nfp/nfpcore/nfp_resource.c | 29 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 38 +++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 15 +- 16 files changed, 447 insertions(+), 322 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 8f87c09327..54bef3cb6b 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -56,7 +56,8 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp, + struct rte_pci_device *dev); /* * Free the bus. @@ -69,9 +70,9 @@ struct nfp_cpp_operations { * NOTE: This is _not_ serialized */ int (*area_init)(struct nfp_cpp_area *area, - uint32_t dest, - unsigned long long address, - unsigned long size); + uint32_t dest, + unsigned long long address, + unsigned long size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -101,17 +102,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_read)(struct nfp_cpp_area *area, - void *kernel_vaddr, - unsigned long offset, - unsigned int length); + void *kernel_vaddr, + unsigned long offset, + unsigned int length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, - const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + const void *kernel_vaddr, + unsigned long offset, + unsigned int length); }; /* @@ -239,7 +240,7 @@ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); * @param len Length of the serial byte array */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len); + size_t serial_len); /* * Set the private data of the nfp_cpp instance @@ -279,7 +280,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + int driver_lock_needed); /* * Free a NFP CPP handle @@ -397,8 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, - unsigned long size); + unsigned long long address, unsigned long size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,10 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, - const char *name, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, unsigned long long address, + unsigned long size); /* * Free an allocated NFP CPP area handle @@ -448,9 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, unsigned long long address, unsigned long size); /* * Release the resources, then free the NFP CPP area handle @@ -459,8 +455,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, - struct nfp_cpp_area **area); + uint64_t addr, unsigned long size, struct nfp_cpp_area **area); /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -484,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * */ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *buffer, size_t length); + void *buffer, size_t length); /* * Write to a NFP CPP area handle from a buffer. The area must be acquired with @@ -498,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *buffer, size_t length); + const void *buffer, size_t length); /* * nfp_cpp_area_iomem() - get IOMEM region for CPP area @@ -522,7 +517,7 @@ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); * @return 0 on success, negative value on failure. */ int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); + unsigned long long offset, unsigned long size); /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle @@ -552,7 +547,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + unsigned long long address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -566,8 +561,8 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); + unsigned long long address, const void *kernel_vaddr, + size_t length); @@ -582,7 +577,7 @@ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); + uint32_t value, size_t length); /* * Read a single 32-bit value from a NFP CPP area handle @@ -599,7 +594,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value); + uint32_t *value); /* * Write a single 32-bit value to a NFP CPP area handle @@ -616,7 +611,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value); + uint32_t value); /* * Read a single 64-bit value from a NFP CPP area handle @@ -633,7 +628,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value); + uint64_t *value); /* * Write a single 64-bit value to a NFP CPP area handle @@ -650,7 +645,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value); + uint64_t value); /* * Write a single 32-bit value on the XPB bus @@ -685,7 +680,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); * @return 0 on success, or -1 on failure. */ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); + uint32_t value); /* * Modify bits of a 32-bit value from the XPB bus @@ -699,7 +694,7 @@ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, negative value on failure. */ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); + uint32_t value, int timeout_us); /* * Read a 32-bit word from a NFP CPP ID @@ -712,7 +707,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + unsigned long long address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -726,7 +721,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + unsigned long long address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -739,7 +734,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + unsigned long long address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -752,7 +747,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + unsigned long long address, uint64_t value); /* * Initialize a mutex location @@ -773,7 +768,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -793,8 +788,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, - uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 2ee60eefc3..884cc84eaa 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -130,9 +130,15 @@ nfp_bar_maptype(struct nfp_bar *bar) #define TARGET_WIDTH_64 8 static int -nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, - uint64_t *bar_base, int tgt, int act, int tok, - uint64_t offset, size_t size, int width) +nfp_compute_bar(const struct nfp_bar *bar, + uint32_t *bar_config, + uint64_t *bar_base, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint32_t bitsize; uint32_t newcfg; @@ -143,19 +149,16 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, switch (width) { case 8: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); break; case 4: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); break; case 0: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); break; default: return -EINVAL; @@ -165,60 +168,58 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), act, + (unsigned long long)mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + bar->index, tgt, act, tok, (unsigned long long)offset, + (unsigned long long)(offset + mask)); bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); /* Bulk mapping */ - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), + tgt, tok, (unsigned long long)mask, + (unsigned long long)(offset & mask), + (unsigned long long)(offset + size - 1) & mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); + bar->index, tgt, tok, (unsigned long long)offset, + (unsigned long long)(offset + ~mask)); bitsize = 40 - 21; } if (bar->bitsize < bitsize) { PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + tgt, tok, act); return -EINVAL; } @@ -234,8 +235,9 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, } static int -nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - uint32_t newcfg) +nfp_bar_write(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + uint32_t newcfg) { int base, slot; @@ -246,7 +248,7 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, return (-ENOMEM); bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); *(uint32_t *)(bar->csr) = newcfg; @@ -257,15 +259,21 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, } static int -nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, - int act, int tok, uint64_t offset, size_t size, int width) +nfp_reconfigure_bar(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint64_t newbase; uint32_t newcfg; int err; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + size, width); if (err != 0) return err; @@ -390,8 +398,10 @@ struct nfp6000_area_priv { }; static int -nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, unsigned long size) +nfp6000_area_init(struct nfp_cpp_area *area, + uint32_t dest, + unsigned long long address, + unsigned long size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -400,8 +410,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, uint32_t token = NFP_CPP_ID_TOKEN_of(dest); int pp, ret = 0; - pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), - address); + pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) return pp; @@ -409,7 +418,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->width.write = PULL_WIDTH(pp); if (priv->width.read > 0 && - priv->width.write > 0 && priv->width.read != priv->width.write) + priv->width.write > 0 && + priv->width.read != priv->width.write) return -EINVAL; if (priv->width.read > 0) @@ -428,8 +438,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->size = size; ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); + priv->token, priv->offset, priv->size, + priv->width.bar); return ret; } @@ -441,14 +451,13 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { + NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { priv->bar_offset = priv->offset & - (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, - priv->target); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, priv->token); + (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, + priv->target); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, + priv->token); } else { priv->bar_offset = priv->offset & priv->bar->mask; } @@ -490,8 +499,10 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) } static int -nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_read(struct nfp_cpp_area *area, + void *kernel_vaddr, + unsigned long offset, + unsigned int length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -524,17 +535,17 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { + priv->action == NFP_CPP_ACTION_RW) { is_64 = false; } if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -558,8 +569,10 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, } static int -nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_write(struct nfp_cpp_area *area, + const void *kernel_vaddr, + unsigned long offset, + unsigned int length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -590,16 +603,16 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) + priv->action == NFP_CPP_ACTION_RW) is_64 = false; if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -655,7 +668,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) } static int -nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_model(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint32_t model; @@ -671,7 +685,8 @@ nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_interface(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t interface; @@ -686,7 +701,8 @@ nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_serial(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t tmp; uint8_t serial[6]; @@ -733,7 +749,8 @@ nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) +nfp6000_set_barsz(struct rte_pci_device *dev, + struct nfp_pcie_user *desc) { unsigned long tmp; int i = 0; @@ -748,7 +765,8 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) } static int -nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp, + struct rte_pci_device *dev) { int ret = 0; struct nfp_pcie_user *desc; @@ -762,7 +780,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 2c6ec3e126..25f7700b08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -27,7 +27,8 @@ NFP_PL_DEVICE_ID_MASK) void -nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) +nfp_cpp_priv_set(struct nfp_cpp *cpp, + void *priv) { cpp->priv = priv; } @@ -39,7 +40,8 @@ nfp_cpp_priv(struct nfp_cpp *cpp) } void -nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) +nfp_cpp_model_set(struct nfp_cpp *cpp, + uint32_t model) { cpp->model = model; } @@ -62,21 +64,24 @@ nfp_cpp_model(struct nfp_cpp *cpp) } void -nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) +nfp_cpp_interface_set(struct nfp_cpp *cpp, + uint32_t interface) { cpp->interface = interface; } int -nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) +nfp_cpp_serial(struct nfp_cpp *cpp, + const uint8_t **serial) { *serial = cpp->serial; return cpp->serial_len; } int -nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len) +nfp_cpp_serial_set(struct nfp_cpp *cpp, + const uint8_t *serial, + size_t serial_len) { if (cpp->serial_len) free(cpp->serial); @@ -161,9 +166,11 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) * NOTE: @address and @size must be 32-bit aligned values. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, - const char *name, unsigned long long address, - unsigned long size) +nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, + uint32_t dest, + const char *name, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -183,7 +190,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, name = ""; area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + strlen(name) + 1); if (area == NULL) return NULL; @@ -204,8 +211,10 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, } struct nfp_cpp_area * -nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc(struct nfp_cpp *cpp, + uint32_t dest, + unsigned long long address, + unsigned long size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -226,8 +235,10 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, * NOTE: The area must also be 'released' when the structure is freed. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; @@ -340,8 +351,10 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *kernel_vaddr, size_t length) +nfp_cpp_area_read(struct nfp_cpp_area *area, + unsigned long offset, + void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -364,8 +377,10 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *kernel_vaddr, size_t length) +nfp_cpp_area_write(struct nfp_cpp_area *area, + unsigned long offset, + const void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -392,8 +407,9 @@ nfp_cpp_area_mapped(struct nfp_cpp_area *area) * or negative value on error. */ int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, - unsigned long length) +nfp_cpp_area_check_range(struct nfp_cpp_area *area, + unsigned long long offset, + unsigned long length) { if (((offset + length) > area->size)) return -EFAULT; @@ -406,7 +422,8 @@ nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, * based upon NFP model. */ static uint32_t -nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) +nfp_xpb_to_cpp(struct nfp_cpp *cpp, + uint32_t *xpb_addr) { uint32_t xpb; int island; @@ -433,7 +450,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) else /* And only non-ARM interfaces use island id = 1 */ if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) + NFP_CPP_INTERFACE_TYPE_ARM) *xpb_addr |= (1 << 24); } else { (*xpb_addr) |= (1 << 30); @@ -443,8 +460,9 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) } int -nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value) +nfp_cpp_area_readl(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t *value) { int sz; uint32_t tmp = 0; @@ -456,8 +474,9 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value) +nfp_cpp_area_writel(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value) { int sz; @@ -467,8 +486,9 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value) +nfp_cpp_area_readq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t *value) { int sz; uint64_t tmp = 0; @@ -480,8 +500,9 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value) +nfp_cpp_area_writeq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t value) { int sz; @@ -492,8 +513,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t *value) +nfp_cpp_readl(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t *value) { int sz; uint32_t tmp; @@ -505,8 +528,10 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t value) +nfp_cpp_writel(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t value) { int sz; @@ -517,8 +542,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t *value) +nfp_cpp_readq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t *value) { int sz; uint64_t tmp; @@ -530,8 +557,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t value) +nfp_cpp_writeq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t value) { int sz; @@ -542,7 +571,9 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) +nfp_xpb_writel(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t value) { uint32_t cpp_dest; @@ -552,7 +583,9 @@ nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) } int -nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) +nfp_xpb_readl(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t *value) { uint32_t cpp_dest; @@ -562,7 +595,8 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *dev, + int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -596,7 +630,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + (tgt * 4); err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { free(cpp); return NULL; @@ -631,7 +665,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) } struct nfp_cpp * -nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_from_device_name(struct rte_pci_device *dev, + int driver_lock_needed) { return nfp_cpp_alloc(dev, driver_lock_needed); } @@ -647,7 +682,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) * @return 0 on success, or -1 on failure. */ int -nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, +nfp_xpb_writelm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, uint32_t value) { int err; @@ -674,8 +711,11 @@ nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, or negative value on failure. */ int -nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us) +nfp_xpb_waitlm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, + uint32_t value, + int timeout_us) { uint32_t tmp; int err; @@ -716,8 +756,11 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @length: number of bytes to read */ int -nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, void *kernel_vaddr, size_t length) +nfp_cpp_read(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -743,9 +786,11 @@ nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, * @length: number of bytes to write */ int -nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, const void *kernel_vaddr, - size_t length) +nfp_cpp_write(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + const void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -768,8 +813,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, * @length: length of area to fill */ int -nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length) +nfp_cpp_area_fill(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value, + size_t length) { int err; size_t i; @@ -795,9 +842,8 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = - nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); + err = nfp_cpp_area_write(area, offset + i, &value64, + sizeof(value64)); if (err < 0) return err; if (err != sizeof(value64)) @@ -805,8 +851,7 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } if ((i + sizeof(value)) <= length) { - err = - nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); + err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); if (err < 0) return err; if (err != sizeof(value)) @@ -822,13 +867,14 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) +__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, + uint32_t *model) { uint32_t reg; int err; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, - ®); + ®); if (err < 0) return err; @@ -853,8 +899,11 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) * Return: Pointer to memory mapped area or NULL */ uint8_t * -nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, struct nfp_cpp_area **area) +nfp_cpp_map_area(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + unsigned long size, + struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index a9d166c4dc..ea4c7d6a9e 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -33,12 +33,13 @@ nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) } static int -nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) +nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, + uint32_t size) { const char *key, *val, *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { PMD_DRV_LOG(ERR, "Bad HWINFO - overflowing value"); @@ -54,7 +55,8 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) } static int -nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) +nfp_hwinfo_db_validate(struct nfp_hwinfo *db, + uint32_t len) { uint32_t size, new_crc, *crc; @@ -69,7 +71,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", - new_crc, *crc); + new_crc, *crc); return -EINVAL; } @@ -77,7 +79,8 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) } static struct nfp_hwinfo * -nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) +nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, + size_t *cpp_size) { struct nfp_hwinfo *header; void *res; @@ -115,7 +118,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) if (header->version != NFP_HWINFO_VERSION_2) { PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", - header->version); + header->version); goto exit_free; } @@ -129,7 +132,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) } static struct nfp_hwinfo * -nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) +nfp_hwinfo_fetch(struct nfp_cpp *cpp, + size_t *hwdb_size) { struct timespec wait; struct nfp_hwinfo *db; @@ -179,7 +183,8 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) * Return: Value of the HWInfo name, or NULL */ const char * -nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) +nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, + const char *lookup) { const char *key, *val, *end; @@ -189,7 +194,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (strcmp(key, lookup) == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f9723dd136..0071d3fc37 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -37,8 +37,10 @@ struct nfp_mip { /* Read memory and check if it could be a valid MIP */ static int -nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - struct nfp_mip *mip) +nfp_mip_try_read(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + struct nfp_mip *mip) { int ret; @@ -49,12 +51,12 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, } if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", - rte_le_to_cpu_32(mip->signature)); + rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", - rte_le_to_cpu_32(mip->mip_version)); + rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -63,7 +65,8 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, /* Try to locate MIP using the resource table */ static int -nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) +nfp_mip_read_resource(struct nfp_cpp *cpp, + struct nfp_mip *mip) { struct nfp_nffw_info *nffw_info; uint32_t cpp_id; @@ -134,7 +137,9 @@ nfp_mip_name(const struct nfp_mip *mip) * @size: Location for size of MIP symbol table */ void -nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_symtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->symtab_addr); *size = rte_le_to_cpu_32(mip->symtab_size); @@ -147,7 +152,9 @@ nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) * @size: Location for size of MIP symbol name table */ void -nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_strtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->strtab_addr); *size = rte_le_to_cpu_32(mip->strtab_size); diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index d0919b58fe..980abc2517 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,5 +17,5 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *off); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 0410a00856..047e755416 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,9 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) +_nfp_cpp_mutex_validate(uint32_t model, + int *target, + unsigned long long address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -72,8 +74,10 @@ _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) * @return 0 on success, or negative value on failure. */ int -nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, - uint32_t key) +nfp_cpp_mutex_init(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ @@ -87,9 +91,8 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, if (err < 0) return err; - err = - nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address + 0, + MUTEX_LOCKED(nfp_cpp_interface(cpp))); if (err < 0) return err; @@ -114,8 +117,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * -nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key) +nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); struct nfp_cpp_mutex *mutex; @@ -265,8 +270,8 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return err; if (time(NULL) >= warn_at) { PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->usage, mutex->depth, mutex->target, + mutex->address, mutex->key); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 433780a5e7..8bdc69766e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -138,8 +138,8 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) goto err_release; err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), - nfp_resource_address(state->res), - fwinf, sizeof(*fwinf)); + nfp_resource_address(state->res), + fwinf, sizeof(*fwinf)); if (err < (int)sizeof(*fwinf)) goto err_release; @@ -205,8 +205,9 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) * Return: 0, or -ERRNO */ int -nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) +nfp_nffw_info_mip_first(struct nfp_nffw_info *state, + uint32_t *cpp_id, + uint64_t *off) { struct nffw_fwinfo *fwinfo; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 6474abf0c2..4f476f6f2b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -22,7 +22,8 @@ nfp_nsp_config_modified(struct nfp_nsp *state) } void -nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified) +nfp_nsp_config_set_modified(struct nfp_nsp *state, + int modified) { state->modified = modified; } @@ -40,7 +41,9 @@ nfp_nsp_config_idx(struct nfp_nsp *state) } void -nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx) +nfp_nsp_config_set_state(struct nfp_nsp *state, + void *entries, + unsigned int idx) { state->entries = entries; state->idx = idx; @@ -91,7 +94,7 @@ nfp_nsp_check(struct nfp_nsp *state) if (state->ver.major != NSP_MAJOR || state->ver.minor < NSP_MINOR) { PMD_DRV_LOG(ERR, "Unsupported ABI %hu.%hu", state->ver.major, - state->ver.minor); + state->ver.minor); return -EINVAL; } @@ -160,8 +163,12 @@ nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state) } static int -nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, - uint64_t addr, uint64_t mask, uint64_t val) +nfp_nsp_wait_reg(struct nfp_cpp *cpp, + uint64_t *reg, + uint32_t nsp_cpp, + uint64_t addr, + uint64_t mask, + uint64_t val) { struct timespec wait; int count; @@ -204,8 +211,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, * -ETIMEDOUT if the NSP took longer than 30 seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, - uint32_t buff_cpp, uint64_t buff_addr) +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code, + uint32_t option, + uint32_t buff_cpp, + uint64_t buff_addr) { uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; struct nfp_cpp *cpp = state->cpp; @@ -223,40 +233,40 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { + !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); + buff_cpp, buff_addr); return -EINVAL; } err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | - FIELD_PREP(NSP_COMMAND_START, 1)); + FIELD_PREP(NSP_COMMAND_OPTION, option) | + FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, - NSP_COMMAND_START, 0); + NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } /* Wait for NSP_STATUS_BUSY to go to 0 */ - err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, - 0); + err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, + NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } @@ -268,7 +278,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); + -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); return -err; } @@ -279,9 +289,12 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, #define SZ_1M 0x00100000 static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, - const void *in_buf, unsigned int in_size, void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf(struct nfp_nsp *nsp, + uint16_t code, uint32_t option, + const void *in_buf, + unsigned int in_size, + void *out_buf, + unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; unsigned int max_size; @@ -291,28 +304,26 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); + code, nsp->ver.major, nsp->ver.minor); return -EOPNOTSUPP; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER_CONFIG, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); if (err < 0) return err; max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); + code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, + ®); if (err < 0) return err; @@ -328,7 +339,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + out_size - in_size); if (err < 0) return err; } @@ -388,38 +399,47 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) } int -nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_load_fw(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_eth_table(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) +nfp_nsp_write_eth_table(struct nfp_nsp *state, + const void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_identify(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, void *buf, - unsigned int size) +nfp_nsp_read_sensors(struct nfp_nsp *state, + unsigned int sensor_mask, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + 0, buf, size); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 9905b2d3d3..1e2deaabb4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -114,9 +114,10 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); + void *buf, unsigned int size); -static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) +static inline int +nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } @@ -229,22 +230,22 @@ struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); + int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + unsigned int size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + unsigned int idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) +static inline int +nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return !!eth_port->fec_modes_supported; } @@ -297,6 +298,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + long *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 21b338461e..28dba27124 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -73,7 +73,9 @@ struct nfp_sensors { }; int -nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val) +nfp_hwmon_read_sensor(struct nfp_cpp *cpp, + enum nfp_nsp_sensor_id id, + long *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 825a84a8cd..3eeefc74af 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -168,8 +168,10 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) } static void -nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, struct nfp_eth_table_port *dst) +nfp_eth_port_translate(struct nfp_nsp *nsp, + const union eth_table_entry *src, + unsigned int index, + struct nfp_eth_table_port *dst) { unsigned int rate; unsigned int fec; @@ -225,21 +227,21 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, - table->ports[i].index); + table->ports[i].index); for (j = 0; j < table->count; j++) { if (table->ports[i].label_port != - table->ports[j].label_port) + table->ports[j].label_port) continue; table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; if (table->ports[i].label_subport == - table->ports[j].label_subport) + table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", - table->ports[i].label_port, - table->ports[i].label_subport); + table->ports[i].label_port, + table->ports[i].label_subport); table->ports[i].is_split = 1; } @@ -296,7 +298,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", - ret, cnt); + ret, cnt); goto err; } @@ -354,7 +356,8 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) } struct nfp_nsp * -nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx) +nfp_eth_config_start(struct nfp_cpp *cpp, + unsigned int idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -447,7 +450,9 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) * -ERRNO - configuration failed. */ int -nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) +nfp_eth_set_mod_enable(struct nfp_cpp *cpp, + unsigned int idx, + int enable) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -487,7 +492,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) * -ERRNO - configuration failed. */ int -nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) +nfp_eth_set_configured(struct nfp_cpp *cpp, + unsigned int idx, + int configed) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -523,9 +530,12 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) } static int -nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, - const uint64_t mask, const unsigned int shift, - unsigned int val, const uint64_t ctrl_bit) +nfp_eth_set_bit_config(struct nfp_nsp *nsp, + unsigned int raw_idx, + const uint64_t mask, + const unsigned int shift, + unsigned int val, + const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); unsigned int idx = nfp_nsp_config_idx(nsp); @@ -560,7 +570,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, (__extension__ ({ \ typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /* @@ -574,11 +584,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, * Return: 0 or -ERRNO. */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) +__nfp_eth_set_aneg(struct nfp_nsp *nsp, + enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_ANEG, mode, - NSP_ETH_CTRL_SET_ANEG); + NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } /* @@ -592,11 +602,11 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) * Return: 0 or -ERRNO. */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) +__nfp_eth_set_fec(struct nfp_nsp *nsp, + enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_FEC, mode, - NSP_ETH_CTRL_SET_FEC); + NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } /* @@ -611,7 +621,9 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) * -ERRNO - configuration failed. */ int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) +nfp_eth_set_fec(struct nfp_cpp *cpp, + unsigned int idx, + enum nfp_eth_fec mode) { struct nfp_nsp *nsp; int err; @@ -642,7 +654,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) +__nfp_eth_set_speed(struct nfp_nsp *nsp, + unsigned int speed) { enum nfp_eth_rate rate; @@ -653,8 +666,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) } return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_RATE, rate, - NSP_ETH_CTRL_SET_RATE); + NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } /* @@ -668,8 +680,9 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes) +__nfp_eth_set_split(struct nfp_nsp *nsp, + unsigned int lanes) { - return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, - lanes, NSP_ETH_CTRL_SET_LANES); + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, + NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 838cd6e0ef..57089c770f 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -64,7 +64,8 @@ struct nfp_resource { }; static int -nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) +nfp_cpp_resource_find(struct nfp_cpp *cpp, + struct nfp_resource *res) { char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; struct nfp_resource_entry entry; @@ -85,7 +86,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { uint64_t addr = NFP_RESOURCE_TBL_BASE + - sizeof(struct nfp_resource_entry) * i; + sizeof(struct nfp_resource_entry) * i; ret = nfp_cpp_read(cpp, cpp_id, addr, &entry, sizeof(entry)); if (ret != sizeof(entry)) @@ -95,12 +96,11 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) continue; /* Found key! */ - res->mutex = - nfp_cpp_mutex_alloc(cpp, - NFP_RESOURCE_TBL_TARGET, addr, key); + res->mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, + addr, key); res->cpp_id = NFP_CPP_ID(entry.region.cpp_target, - entry.region.cpp_action, - entry.region.cpp_token); + entry.region.cpp_action, + entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; return 0; @@ -110,8 +110,9 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) } static int -nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, - struct nfp_cpp_mutex *dev_mutex) +nfp_resource_try_acquire(struct nfp_cpp *cpp, + struct nfp_resource *res, + struct nfp_cpp_mutex *dev_mutex) { int err; @@ -148,7 +149,8 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, * Return: NFP Resource handle, or NULL */ struct nfp_resource * -nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) +nfp_resource_acquire(struct nfp_cpp *cpp, + const char *name) { struct nfp_cpp_mutex *dev_mutex; struct nfp_resource *res; @@ -165,8 +167,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, - NFP_RESOURCE_TBL_BASE, - NFP_RESOURCE_TBL_KEY); + NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { free(res); return NULL; @@ -234,8 +235,8 @@ nfp_resource_cpp_id(const struct nfp_resource *res) * * Return: const char pointer to the name of the resource */ -const char -*nfp_resource_name(const struct nfp_resource *res) +const char * +nfp_resource_name(const struct nfp_resource *res) { return res->name; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 06cc6f74f4..009b7359a4 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -18,7 +18,7 @@ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, - const char *name); + const char *name); /** * Release a NFP Resource, and free the handle diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 4c45aec5c1..aa3b7a483e 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -40,22 +40,25 @@ struct nfp_rtsym_table { }; static int -nfp_meid(uint8_t island_id, uint8_t menum) +nfp_meid(uint8_t island_id, + uint8_t menum) { return (island_id & 0x3F) == island_id && menum < 12 ? (island_id << 4) | (menum + 4) : -1; } static void -nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, uint32_t strtab_size, - struct nfp_rtsym *sw, struct nfp_rtsym_entry *fw) +nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, + uint32_t strtab_size, + struct nfp_rtsym *sw, + struct nfp_rtsym_entry *fw) { sw->type = fw->type; sw->name = cache->strtab + rte_le_to_cpu_16(fw->name) % strtab_size; sw->addr = ((uint64_t)fw->addr_hi << 32) | - rte_le_to_cpu_32(fw->addr_lo); + rte_le_to_cpu_32(fw->addr_lo); sw->size = ((uint64_t)fw->size_hi << 32) | - rte_le_to_cpu_32(fw->size_lo); + rte_le_to_cpu_32(fw->size_lo); PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", sw->name, sw->addr, sw->size, sw->target); @@ -93,7 +96,8 @@ nfp_rtsym_table_read(struct nfp_cpp *cpp) } struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) +__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip) { uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; struct nfp_rtsym_entry *rtsymtab; @@ -142,7 +146,7 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) for (n = 0; n < cache->num; n++) nfp_rtsym_sw_entry_init(cache, strtab_size, - &cache->symtab[n], &rtsymtab[n]); + &cache->symtab[n], &rtsymtab[n]); free(rtsymtab); @@ -178,7 +182,8 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) +nfp_rtsym_get(struct nfp_rtsym_table *rtbl, + int idx) { if (rtbl == NULL) return NULL; @@ -197,7 +202,8 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name) +nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name) { int n; @@ -331,7 +337,9 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, * Return: value read, on error sets the error and returns ~0ULL. */ uint64_t -nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) +nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, + const char *name, + int *error) { const struct nfp_rtsym *sym; uint32_t val32; @@ -354,7 +362,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, - name, sym->size); + name, sym->size); err = -EINVAL; break; } @@ -372,8 +380,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) } uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area) +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, + const char *name, + unsigned int min_size, + struct nfp_cpp_area **area) { int ret; uint8_t *mem; @@ -397,7 +407,7 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, if (sym->size < min_size) { PMD_DRV_LOG(ERR, "Symbol %s too small (%" PRIu64 " < %u)", name, - sym->size, min_size); + sym->size, min_size); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 8b494211bc..30768f1ccf 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -43,19 +43,18 @@ struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip); +struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip); 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); +const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name); uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, - int *error); -uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + int *error); +uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, + unsigned int min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 03/27] net/nfp: unify the type of integer variable 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-08-30 2:14 ` [PATCH v2 02/27] net/nfp: unify the indent coding style Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 04/27] net/nfp: remove the unneeded logic Chaoyong He ` (24 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Unify the type of integer variable to the DPDK prefer style. Also change the return type of 'nfp_eth_speed2rate()' to the corresponding enum, which make it more readable. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 53 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 20 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 40 +++++++-------- drivers/net/nfp/nfpcore/nfp_mutex.c | 12 ++--- drivers/net/nfp/nfpcore/nfp_nffw.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nsp.c | 28 +++++----- drivers/net/nfp/nfpcore/nfp_nsp.h | 59 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 52 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- 12 files changed, 139 insertions(+), 139 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 54bef3cb6b..782272a3f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -71,8 +71,8 @@ struct nfp_cpp_operations { */ int (*area_init)(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size); + uint64_t address, + size_t size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -103,16 +103,16 @@ struct nfp_cpp_operations { */ int (*area_read)(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); }; /* @@ -398,7 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, unsigned long size); + uint64_t address, size_t size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,8 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, const char *name, unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, uint64_t address, + uint32_t size); /* * Free an allocated NFP CPP area handle @@ -446,7 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, unsigned long long address, unsigned long size); + uint32_t cpp_id, uint64_t address, size_t size); /* * Release the resources, then free the NFP CPP area handle @@ -455,7 +455,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, struct nfp_cpp_area **area); + uint64_t addr, uint32_t size, struct nfp_cpp_area **area); + /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -478,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * @return bytes read on success, negative value on failure. * */ -int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); /* @@ -492,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * * @return bytes written on success, negative value on failure. */ -int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); /* @@ -547,7 +548,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + uint64_t address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -561,9 +562,7 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); - + uint64_t address, const void *kernel_vaddr, size_t length); /* @@ -593,7 +592,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); /* @@ -610,7 +609,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); /* @@ -627,7 +626,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); /* @@ -644,7 +643,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); /* @@ -707,7 +706,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + uint64_t address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -721,7 +720,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + uint64_t address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -734,7 +733,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + uint64_t address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -747,7 +746,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + uint64_t address, uint64_t value); /* * Initialize a mutex location @@ -768,7 +767,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -788,7 +787,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 884cc84eaa..881f21bfd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -101,7 +101,7 @@ struct nfp_bar { uint64_t base; /* CPP address base */ uint64_t mask; /* Bit mask of the bar */ uint32_t bitsize; /* Bit size of the bar */ - int index; + uint32_t index; int lock; char *csr; @@ -400,8 +400,8 @@ struct nfp6000_area_priv { static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -501,8 +501,8 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -510,7 +510,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -571,8 +571,8 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -580,7 +580,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, struct nfp6000_area_priv *priv; uint32_t *wrptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -752,7 +752,7 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - unsigned long tmp; + uint64_t tmp; int i = 0; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 25f7700b08..7b32721d60 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -169,8 +169,8 @@ struct nfp_cpp_area * nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, const char *name, - unsigned long long address, - unsigned long size) + uint64_t address, + uint32_t size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -184,7 +184,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, if (err < 0) return NULL; - address = (unsigned long long)tmp64; + address = tmp64; if (name == NULL) name = ""; @@ -213,8 +213,8 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -237,8 +237,8 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_cpp_area *area; @@ -352,7 +352,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) */ int nfp_cpp_area_read(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, void *kernel_vaddr, size_t length) { @@ -378,7 +378,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, */ int nfp_cpp_area_write(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, const void *kernel_vaddr, size_t length) { @@ -461,7 +461,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, int nfp_cpp_area_readl(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t *value) { int sz; @@ -475,7 +475,7 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, int nfp_cpp_area_writel(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t value) { int sz; @@ -487,7 +487,7 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, int nfp_cpp_area_readq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t *value) { int sz; @@ -501,7 +501,7 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, int nfp_cpp_area_writeq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t value) { int sz; @@ -515,7 +515,7 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t *value) { int sz; @@ -530,7 +530,7 @@ nfp_cpp_readl(struct nfp_cpp *cpp, int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t value) { int sz; @@ -544,7 +544,7 @@ nfp_cpp_writel(struct nfp_cpp *cpp, int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t *value) { int sz; @@ -559,7 +559,7 @@ nfp_cpp_readq(struct nfp_cpp *cpp, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t value) { int sz; @@ -758,7 +758,7 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, void *kernel_vaddr, size_t length) { @@ -788,7 +788,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, const void *kernel_vaddr, size_t length) { @@ -902,7 +902,7 @@ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, + uint32_t size, struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 047e755416..697361da4d 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -28,16 +28,16 @@ struct nfp_cpp_mutex { struct nfp_cpp *cpp; uint8_t target; uint16_t depth; - unsigned long long address; + uint64_t address; uint32_t key; - unsigned int usage; + uint32_t usage; struct nfp_cpp_mutex *prev, *next; }; static int _nfp_cpp_mutex_validate(uint32_t model, int *target, - unsigned long long address) + uint64_t address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -76,7 +76,7 @@ _nfp_cpp_mutex_validate(uint32_t model, int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -119,7 +119,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -269,7 +269,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", + PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", mutex->usage, mutex->depth, mutex->target, mutex->address, mutex->key); warn_at = time(NULL) + 60; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 8bdc69766e..7ff468373b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,7 +68,7 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - unsigned int mode, addr40; + uint32_t mode, addr40; uint32_t xpbaddr, imbcppat; int err; @@ -84,7 +84,7 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) return nfp_cppat_mu_locality_lsb(mode, addr40); } -static unsigned int +static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { /* @@ -183,7 +183,7 @@ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { struct nffw_fwinfo *fwinfo; - unsigned int cnt, i; + uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4f476f6f2b..87eed3d951 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -34,7 +34,7 @@ nfp_nsp_config_entries(struct nfp_nsp *state) return state->entries; } -unsigned int +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state) { return state->idx; @@ -43,7 +43,7 @@ nfp_nsp_config_idx(struct nfp_nsp *state) void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx) + uint32_t idx) { state->entries = entries; state->idx = idx; @@ -59,12 +59,12 @@ nfp_nsp_config_clear_state(struct nfp_nsp *state) static void nfp_nsp_print_extended_error(uint32_t ret_val) { - int i; + uint32_t i; if (ret_val == 0) return; - for (i = 0; i < (int)RTE_DIM(nsp_errors); i++) + for (i = 0; i < RTE_DIM(nsp_errors); i++) if (ret_val == (uint32_t)nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -171,7 +171,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t val) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -297,7 +297,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; - unsigned int max_size; + size_t max_size; uint64_t reg, cpp_buf; int ret, err; uint32_t cpp_id; @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } @@ -361,7 +361,7 @@ int nfp_nsp_wait(struct nfp_nsp *state) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -401,7 +401,7 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, NULL, 0); @@ -410,7 +410,7 @@ nfp_nsp_load_fw(struct nfp_nsp *state, int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, buf, size); @@ -419,7 +419,7 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, NULL, 0); @@ -428,7 +428,7 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, buf, size); @@ -436,9 +436,9 @@ nfp_nsp_read_identify(struct nfp_nsp *state, int nfp_nsp_read_sensors(struct nfp_nsp *state, - unsigned int sensor_mask, + uint32_t sensor_mask, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, 0, buf, size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 1e2deaabb4..edb56e26ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -110,11 +110,11 @@ uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); int nfp_nsp_wait(struct nfp_nsp *state); int nfp_nsp_device_soft_reset(struct nfp_nsp *state); -int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); -int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); -int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); +int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); +int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, + void *buf, size_t size); static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) @@ -188,17 +188,17 @@ enum nfp_eth_fec { * @fec_modes_supported: bitmap of FEC modes supported */ struct nfp_eth_table { - unsigned int count; - unsigned int max_index; + uint32_t count; + uint32_t max_index; struct nfp_eth_table_port { - unsigned int eth_index; - unsigned int index; - unsigned int nbi; - unsigned int base; - unsigned int lanes; - unsigned int speed; - - unsigned int interface; + uint32_t eth_index; + uint32_t index; + uint32_t nbi; + uint32_t base; + uint32_t lanes; + uint32_t speed; + + uint32_t interface; enum nfp_eth_media media; enum nfp_eth_fec fec; @@ -218,51 +218,50 @@ struct nfp_eth_table { /* Computed fields */ uint8_t port_type; - unsigned int port_lanes; + uint32_t port_lanes; int is_split; - unsigned int fec_modes_supported; + uint32_t fec_modes_supported; } ports[]; }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); -int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + size_t size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); -unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { - return !!eth_port->fec_modes_supported; + return eth_port->fec_modes_supported != 0; } -static inline unsigned int +static inline uint32_t nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported; } -struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx); +struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes); +int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /** * struct nfp_nsp_identify - NSP static information @@ -298,6 +297,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + uint32_t *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 28dba27124..31677b66e6 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -75,7 +75,7 @@ struct nfp_sensors { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val) + uint32_t *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 3eeefc74af..9213023690 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -124,7 +124,7 @@ union eth_table_entry { static const struct { enum nfp_eth_rate rate; - unsigned int speed; + uint32_t speed; } nsp_eth_rate_tbl[] = { { RATE_INVALID, 0, }, { RATE_10M, SPEED_10, }, @@ -134,24 +134,24 @@ static const struct { { RATE_25G, SPEED_25000, }, }; -static unsigned int +static uint32_t nfp_eth_rate2speed(enum nfp_eth_rate rate) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].rate == rate) return nsp_eth_rate_tbl[i].speed; return 0; } -static unsigned int -nfp_eth_speed2rate(unsigned int speed) +static enum nfp_eth_rate +nfp_eth_speed2rate(uint32_t speed) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].speed == speed) return nsp_eth_rate_tbl[i].rate; @@ -161,7 +161,7 @@ nfp_eth_speed2rate(unsigned int speed) static void nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) { - int i; + uint32_t i; for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) dst[RTE_ETHER_ADDR_LEN - i - 1] = src[i]; @@ -170,11 +170,11 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) static void nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, + uint32_t index, struct nfp_eth_table_port *dst) { - unsigned int rate; - unsigned int fec; + uint32_t rate; + uint32_t fec; uint64_t port, state; port = rte_le_to_cpu_64(src->port); @@ -223,7 +223,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - unsigned int i, j; + uint32_t i, j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -268,7 +268,9 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; struct nfp_eth_table *table; uint32_t table_sz; - int i, j, ret, cnt = 0; + uint32_t i; + uint32_t j; + int ret, cnt = 0; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -318,7 +320,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } nfp_eth_calc_port_geometry(table); - for (i = 0; i < (int)table->count; i++) + for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); free(entries); @@ -357,7 +359,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, - unsigned int idx) + uint32_t idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -451,7 +453,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int enable) { union eth_table_entry *entries; @@ -493,7 +495,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, */ int nfp_eth_set_configured(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int configed) { union eth_table_entry *entries; @@ -531,14 +533,14 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, static int nfp_eth_set_bit_config(struct nfp_nsp *nsp, - unsigned int raw_idx, + uint32_t raw_idx, const uint64_t mask, - const unsigned int shift, - unsigned int val, + const uint32_t shift, + uint32_t val, const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - unsigned int idx = nfp_nsp_config_idx(nsp); + uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; /* @@ -622,7 +624,7 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, */ int nfp_eth_set_fec(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, enum nfp_eth_fec mode) { struct nfp_nsp *nsp; @@ -655,7 +657,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, - unsigned int speed) + uint32_t speed) { enum nfp_eth_rate rate; @@ -681,7 +683,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, */ int __nfp_eth_set_split(struct nfp_nsp *nsp, - unsigned int lanes) + uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 57089c770f..9dd4832779 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -156,7 +156,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; int err; struct timespec wait; - int count; + uint16_t count; res = malloc(sizeof(*res)); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index aa3b7a483e..243d3c9ce5 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -382,7 +382,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, + uint32_t min_size, struct nfp_cpp_area **area) { int ret; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 30768f1ccf..e7295258b3 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -56,5 +56,5 @@ const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + uint32_t min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 04/27] net/nfp: remove the unneeded logic 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (2 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 03/27] net/nfp: unify the type of integer variable Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 05/27] net/nfp: standard the local variable coding style Chaoyong He ` (23 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Remove the unneeded logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 107 ---- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 - drivers/net/nfp/nfpcore/nfp_cppcore.c | 162 ------ drivers/net/nfp/nfpcore/nfp_mutex.c | 48 -- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 24 - drivers/net/nfp/nfpcore/nfp_target.h | 567 --------------------- 6 files changed, 920 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 782272a3f4..139752f85a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -96,7 +96,6 @@ struct nfp_cpp_operations { void *(*area_iomem)(struct nfp_cpp_area *area); - void *(*area_mapped)(struct nfp_cpp_area *area); /* * Perform a read from a NFP CPP area * Serialized @@ -457,16 +456,6 @@ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Return an IO pointer to the beginning of the NFP CPP area handle. The area - * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * - * @return Pointer to IO memory, or NULL on failure. - */ -void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); - /* * Read from a NFP CPP area handle into a buffer. The area must be acquired with * 'nfp_cpp_area_acquire()' before calling this operation. @@ -508,18 +497,6 @@ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Verify that IO can be performed on an offset in an area - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] size Size of region to validate - * - * @return 0 on success, negative value on failure. - */ -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); - /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle * @@ -564,20 +541,6 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); - -/* - * Fill a NFP CPP area handle and offset with a value - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the NFP CPP ID address space - * @param[in] value 32-bit value to fill area with - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, negative value on failure. - */ -int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); - /* * Read a single 32-bit value from a NFP CPP area handle * @@ -668,33 +631,6 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, negative value on failure. - */ -int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); - /* * Read a 32-bit word from a NFP CPP ID * @@ -789,49 +725,6 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Get the NFP CPP handle the mutex was created with - * - * @param mutex NFP mutex handle - * @return NFP CPP handle - */ -struct nfp_cpp *nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex key - * - * @param mutex NFP mutex handle - * @return Mutex key - */ -uint32_t nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex owner - * - * @param mutex NFP mutex handle - * @return Interface ID of the mutex owner - * - * NOTE: This is for debug purposes ONLY - the owner may change at any time, - * unless it has been locked by this NFP CPP handle. - */ -uint16_t nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex target - * - * @param mutex NFP mutex handle - * @return Mutex CPP target (ie NFP_CPP_TARGET_MU) - */ -int nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex address - * - * @param mutex NFP mutex handle - * @return Mutex CPP address - */ -uint64_t nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex); - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 881f21bfd0..ec14ec45dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -471,17 +471,6 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) return 0; } -static void * -nfp6000_area_mapped(struct nfp_cpp_area *area) -{ - struct nfp6000_area_priv *area_priv = nfp_cpp_area_priv(area); - - if (area_priv->iomem == NULL) - return NULL; - - return area_priv->iomem; -} - static void nfp6000_area_release(struct nfp_cpp_area *area) { @@ -829,7 +818,6 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, - .area_mapped = nfp6000_area_mapped, .area_read = nfp6000_area_read, .area_write = nfp6000_area_write, .area_iomem = nfp6000_area_iomem, diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7b32721d60..f885e7d8ff 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -388,35 +388,6 @@ nfp_cpp_area_write(struct nfp_cpp_area *area, return area->cpp->op->area_write(area, kernel_vaddr, offset, length); } -void * -nfp_cpp_area_mapped(struct nfp_cpp_area *area) -{ - if (area->cpp->op->area_mapped) - return area->cpp->op->area_mapped(area); - return NULL; -} - -/* - * nfp_cpp_area_check_range - check if address range fits in CPP area - * - * @area: CPP area handle - * @offset: offset into CPP area - * @length: size of address range in bytes - * - * Check if address range fits within CPP area. Return 0 if area fits - * or negative value on error. - */ -int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, - unsigned long length) -{ - if (((offset + length) > area->size)) - return -EFAULT; - - return 0; -} - /* * Return the correct CPP address, and fixup xpb_addr as needed, * based upon NFP model. @@ -671,82 +642,6 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int -nfp_xpb_writelm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value) -{ - int err; - uint32_t tmp; - - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - return err; - - tmp &= ~mask; - tmp |= (mask & value); - return nfp_xpb_writel(cpp, xpb_tgt, tmp); -} - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, or negative value on failure. - */ -int -nfp_xpb_waitlm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value, - int timeout_us) -{ - uint32_t tmp; - int err; - - do { - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - goto exit; - - if ((tmp & mask) == (value & mask)) { - if (timeout_us < 0) - timeout_us = 0; - break; - } - - if (timeout_us < 0) - continue; - - timeout_us -= 100; - usleep(100); - } while (timeout_us >= 0); - - if (timeout_us < 0) - err = -ETIMEDOUT; - else - err = timeout_us; - -exit: - return err; -} - /* * nfp_cpp_read - read from CPP target * @cpp: CPP handle @@ -805,63 +700,6 @@ nfp_cpp_write(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_area_fill - fill a CPP area with a value - * @area: CPP area - * @offset: offset into CPP area - * @value: value to fill with - * @length: length of area to fill - */ -int -nfp_cpp_area_fill(struct nfp_cpp_area *area, - unsigned long offset, - uint32_t value, - size_t length) -{ - int err; - size_t i; - uint64_t value64; - - value = rte_cpu_to_le_32(value); - value64 = ((uint64_t)value << 32) | value; - - if ((offset + length) > area->size) - return -EINVAL; - - if ((area->offset + offset) & 3) - return -EINVAL; - - if (((area->offset + offset) & 7) == 4 && length >= 4) { - err = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - offset += sizeof(value); - length -= sizeof(value); - } - - for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); - if (err < 0) - return err; - if (err != sizeof(value64)) - return -ENOSPC; - } - - if ((i + sizeof(value)) <= length) { - err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - i += sizeof(value); - } - - return (int)i; -} - /* * NOTE: This code should not use nfp_xpb_* functions, * as those are model-specific diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 697361da4d..4d26e6f052 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -178,54 +178,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -struct nfp_cpp * -nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex) -{ - return mutex->cpp; -} - -uint32_t -nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex) -{ - return mutex->key; -} - -uint16_t -nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex) -{ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t value, key; - int err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - return err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); - if (err < 0) - return err; - - if (key != mutex->key) - return -EPERM; - - if (MUTEX_IS_LOCKED(value) == 0) - return 0; - - return MUTEX_INTERFACE(value); -} - -int -nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex) -{ - return mutex->target; -} - -uint64_t -nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex) -{ - return mutex->address; -} - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9213023690..899fcd7441 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,30 +11,6 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) #define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 03908a894f..195e599d31 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,571 +6,4 @@ #ifndef NFP_TARGET_H #define NFP_TARGET_H -#include "nfp_cpp.h" - -#define P32 1 -#define P64 2 - -#define PUSHPULL(_pull, _push) (((_pull) << 4) | ((_push) << 0)) - -#ifndef NFP_ERRNO -#include <errno.h> -#define NFP_ERRNO(x) (errno = (x), -1) -#endif - -static inline int -pushpull_width(int pp) -{ - pp &= 0xf; - - if (pp == 0) - return NFP_ERRNO(EINVAL); - return (2 << pp); -} - -#define PUSH_WIDTH(_pushpull) pushpull_width((_pushpull) >> 0) -#define PULL_WIDTH(_pushpull) pushpull_width((_pushpull) >> 4) - -static inline int -target_rw(uint32_t cpp_id, int pp, int start, int len) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < start || island > (start + len))) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): - return PUSHPULL(0, pp); - case NFP_CPP_ID(0, 1, 0): - return PUSHPULL(pp, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(pp, pp); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_dma(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiDma */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiDma */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_stats(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiStats */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiStats */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_tm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiTM */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiTM */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_ppc(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiPreclassifier */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiPreclassifier */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi(uint32_t cpp_id, uint64_t address) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - uint64_t rel_addr = address & 0x3fFFFF; - - if (island && (island < 8 || island > 9)) - return NFP_ERRNO(EINVAL); - - if (rel_addr < (1 << 20)) - return nfp6000_nbi_dma(cpp_id); - if (rel_addr < (2 << 20)) - return nfp6000_nbi_stats(cpp_id); - if (rel_addr < (3 << 20)) - return nfp6000_nbi_tm(cpp_id); - return nfp6000_nbi_ppc(cpp_id); -} - -/* - * This structure ONLY includes items that can be done with a read or write of - * 32-bit or 64-bit words. All others are not listed. - */ -static inline int -nfp6000_mu_common(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): /* read_be/write_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): /* read_le/write_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 2): /* {read/write}_swap_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 3): /* {read/write}_swap_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, 0, 0): /* read_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 1): /* read_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 2): /* read_swap_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 3): /* read_swap_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* write_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 1): /* write_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 2): /* write_swap_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 3): /* write_swap_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 3, 0): /* atomic_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 2): /* mask_compare_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* atomic_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 2): /* atomic_write_imm */ - return PUSHPULL(0, 0); - case NFP_CPP_ID(0, 4, 3): /* swap_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 5, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 5, 3): /* test_set_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 6, 0): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 3): /* test_clr_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 7, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 7, 3): /* test_add_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 8, 0): /* addsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 3): /* test_sub_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 0): /* microq128_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 1): /* microq128_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 2): /* microq128_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 0): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 3): /* test_xor_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 0): /* read32_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 1): /* read32_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 2): /* read32_swap_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 3): /* read32_swap_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 31, 0): /* write32_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 1): /* write32_le */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 2): /* write32_swap_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 3): /* write32_swap_le */ - return PUSHPULL(P32, 0); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_mu_ctm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 16, 1): /* packet_read_packet_status */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_emu(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 18, 0): /* read_queue */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 1): /* read_queue_ring */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 2): /* write_queue */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 18, 3): /* write_queue_ring */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 20, 2): /* journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 21, 0): /* get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 1): /* get_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 2): /* get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 0): /* pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 1): /* pop_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 2): /* pop_freely */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_imu(uint32_t cpp_id) -{ - return nfp6000_mu_common(cpp_id); -} - -static inline int -nfp6000_mu(uint32_t cpp_id, uint64_t address) -{ - int pp; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island == 0) { - if (address < 0x2000000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x8000000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0x9800000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x9C00000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0xA000000000ULL) - pp = nfp6000_mu_imu(cpp_id); - else - pp = nfp6000_mu_ctm(cpp_id); - } else if (island >= 24 && island <= 27) { - pp = nfp6000_mu_emu(cpp_id); - } else if (island >= 28 && island <= 31) { - pp = nfp6000_mu_imu(cpp_id); - } else if (island == 1 || - (island >= 4 && island <= 7) || - (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { - pp = nfp6000_mu_ctm(cpp_id); - } else { - pp = NFP_ERRNO(EINVAL); - } - - return pp; -} - -static inline int -nfp6000_ila(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 48 || island > 51)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* read_check_error */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 0): /* read_int */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* write_int */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 48, 4); - } -} - -static inline int -nfp6000_pci(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 4 || island > 7)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 4, 4); - } -} - -static inline int -nfp6000_crypto(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 12 || island > 15)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(P64, 0); - default: - return target_rw(cpp_id, P64, 12, 4); - } -} - -static inline int -nfp6000_cap_xpb(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* RingGet */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 0, 2): /* Interthread Signal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 1): /* RingPut */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 2): /* CTNNWr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* ReflectRd, signal none */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 1): /* ReflectRd, signal self */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 2): /* ReflectRd, signal remote */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 3): /* ReflectRd, signal both */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* ReflectWr, signal none */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 1): /* ReflectWr, signal self */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 2): /* ReflectWr, signal remote */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 3): /* ReflectWr, signal both */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): - return PUSHPULL(P32, P32); - default: - return target_rw(cpp_id, P32, 1, 63); - } -} - -static inline int -nfp6000_cls(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 3): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 1): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 1): /* add64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 1): /* sub64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 2): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 2): /* hash_mask */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* hash_clear */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 0): /* ring_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 1): /* ring_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 2): /* ring_get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 3): /* ring_pop_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* ring_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 2): /* ring_journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 14, 0): /* reflect_write_sig_local */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 1): /* reflect_read_sig_local */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 17, 2): /* statistic */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 24, 0): /* ring_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 24, 1): /* ring_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 25, 0): /* ring_workq_add_thread */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 25, 1): /* ring_workq_add_work */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 0, 64); - } -} - -static inline int -nfp6000_target_pushpull(uint32_t cpp_id, uint64_t address) -{ - switch (NFP_CPP_ID_TARGET_of(cpp_id)) { - case NFP6000_CPPTGT_NBI: - return nfp6000_nbi(cpp_id, address); - case NFP6000_CPPTGT_VQDR: - return target_rw(cpp_id, P32, 24, 4); - case NFP6000_CPPTGT_ILA: - return nfp6000_ila(cpp_id); - case NFP6000_CPPTGT_MU: - return nfp6000_mu(cpp_id, address); - case NFP6000_CPPTGT_PCIE: - return nfp6000_pci(cpp_id); - case NFP6000_CPPTGT_ARM: - if (address < 0x10000) - return target_rw(cpp_id, P64, 1, 1); - else - return target_rw(cpp_id, P32, 1, 1); - case NFP6000_CPPTGT_CRYPTO: - return nfp6000_crypto(cpp_id); - case NFP6000_CPPTGT_CTXPB: - return nfp6000_cap_xpb(cpp_id); - case NFP6000_CPPTGT_CLS: - return nfp6000_cls(cpp_id); - case 0: - return target_rw(cpp_id, P32, 4, 4); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_pushpull_width(int pp, int write_not_read) -{ - if (pp < 0) - return pp; - - if (write_not_read) - return PULL_WIDTH(pp); - else - return PUSH_WIDTH(pp); -} - -static inline int -nfp6000_target_action_width(uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - int pp; - - pp = nfp6000_target_pushpull(cpp_id, address); - - return nfp_target_pushpull_width(pp, write_not_read); -} - -static inline int -nfp_target_action_width(uint32_t model, uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - if (NFP_CPP_MODEL_IS_6000(model)) { - return nfp6000_target_action_width(cpp_id, address, - write_not_read); - } else { - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table) -{ - int err; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_island_id); - uint8_t target = NFP_CPP_ID_TARGET_of(cpp_island_id); - uint32_t imb; - - if (target >= 16) - return NFP_ERRNO(EINVAL); - - if (island == 0) { - /* Already translated */ - *cpp_target_id = cpp_island_id; - *cpp_target_address = cpp_island_address; - return 0; - } - - if (imb_table == NULL) { - /* CPP + Island only allowed on systems with IMB tables */ - return NFP_ERRNO(EINVAL); - } - - imb = imb_table[target]; - - *cpp_target_address = cpp_island_address; - err = _nfp6000_cppat_addr_encode(cpp_target_address, island, target, - ((imb >> 13) & 7), - ((imb >> 12) & 1), - ((imb >> 6) & 0x3f), - ((imb >> 0) & 0x3f)); - if (err == 0) { - *cpp_target_id = - NFP_CPP_ID(target, NFP_CPP_ID_ACTION_of(cpp_island_id), - NFP_CPP_ID_TOKEN_of(cpp_island_id)); - } - - return err; -} - #endif /* NFP_TARGET_H */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 05/27] net/nfp: standard the local variable coding style 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (3 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 04/27] net/nfp: remove the unneeded logic Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 06/27] net/nfp: adjust the log statement Chaoyong He ` (22 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He There should only declare one local variable in each line, and the local variable should be arranged from short to long in the function. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 58 ++++++++++++---------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 27 ++++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 8 +-- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 ++++++---- drivers/net/nfp/nfpcore/nfp_nffw.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nsp.c | 40 ++++++++------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +-- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 39 ++++++++------- drivers/net/nfp/nfpcore/nfp_resource.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 19 ++++--- 11 files changed, 151 insertions(+), 117 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index ec14ec45dc..78beee07ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -140,9 +140,9 @@ nfp_compute_bar(const struct nfp_bar *bar, size_t size, int width) { - uint32_t bitsize; - uint32_t newcfg; uint64_t mask; + uint32_t newcfg; + uint32_t bitsize; if (tgt >= 16) return -EINVAL; @@ -239,7 +239,8 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base, slot; + int base; + int slot; base = bar->index >> 3; slot = bar->index & 7; @@ -268,9 +269,9 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, size_t size, int width) { - uint64_t newbase; - uint32_t newcfg; int err; + uint32_t newcfg; + uint64_t newbase; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); @@ -303,8 +304,10 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, static int nfp_enable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -333,8 +336,10 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) static struct nfp_bar * nfp_alloc_bar(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -356,8 +361,10 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) static void nfp_disable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -403,12 +410,13 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint64_t address, size_t size) { - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); - struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + int pp; + int ret = 0; + uint32_t token = NFP_CPP_ID_TOKEN_of(dest); uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); - uint32_t token = NFP_CPP_ID_TOKEN_of(dest); - int pp, ret = 0; + struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -493,14 +501,14 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + size_t n; + int width; + bool is_64; + uint32_t *wrptr32 = kernel_vaddr; uint64_t *wrptr64 = kernel_vaddr; - const volatile uint64_t *rdptr64; struct nfp6000_area_priv *priv; - uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; - int width; - size_t n; - bool is_64; + const volatile uint64_t *rdptr64; priv = nfp_cpp_area_priv(area); rdptr64 = (uint64_t *)(priv->iomem + offset); @@ -563,14 +571,14 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { - const uint64_t *rdptr64 = kernel_vaddr; - uint64_t *wrptr64; - const uint32_t *rdptr32 = kernel_vaddr; - struct nfp6000_area_priv *priv; - uint32_t *wrptr32; - int width; size_t n; + int width; bool is_64; + uint32_t *wrptr32; + uint64_t *wrptr64; + struct nfp6000_area_priv *priv; + const uint32_t *rdptr32 = kernel_vaddr; + const uint64_t *rdptr64 = kernel_vaddr; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); @@ -693,10 +701,10 @@ static int nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) { + off_t pos; uint16_t tmp; uint8_t serial[6]; int serial_len = 6; - off_t pos; pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); if (pos <= 0) { @@ -741,8 +749,8 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - uint64_t tmp; int i = 0; + uint64_t tmp; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f885e7d8ff..776842bdf6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -172,9 +172,9 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint64_t address, uint32_t size) { + int err; struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; - int err; if (cpp == NULL) return NULL; @@ -396,8 +396,8 @@ static uint32_t nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) { - uint32_t xpb; int island; + uint32_t xpb; xpb = NFP_CPP_ID(14, NFP_CPP_ACTION_RW, 0); @@ -569,9 +569,9 @@ static struct nfp_cpp * nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) { - const struct nfp_cpp_operations *ops; - struct nfp_cpp *cpp; int err; + struct nfp_cpp *cpp; + const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); @@ -657,8 +657,8 @@ nfp_cpp_read(struct nfp_cpp *cpp, void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { @@ -687,8 +687,8 @@ nfp_cpp_write(struct nfp_cpp *cpp, const void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) @@ -708,8 +708,8 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { - uint32_t reg; int err; + uint32_t reg; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, ®); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index ea4c7d6a9e..819761eda0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -36,7 +36,9 @@ static int nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { - const char *key, *val, *end = hwinfo->data + size; + const char *key; + const char *val; + const char *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { @@ -58,7 +60,9 @@ static int nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) { - uint32_t size, new_crc, *crc; + uint32_t *crc; + uint32_t size; + uint32_t new_crc; size = db->size; if (size > len) { @@ -82,12 +86,12 @@ static struct nfp_hwinfo * nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) { - struct nfp_hwinfo *header; - void *res; - uint64_t cpp_addr; - uint32_t cpp_id; int err; + void *res; uint8_t *db; + uint32_t cpp_id; + uint64_t cpp_addr; + struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); if (res) { @@ -135,13 +139,12 @@ static struct nfp_hwinfo * nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) { + int count = 0; struct timespec wait; struct nfp_hwinfo *db; - int count; wait.tv_sec = 0; wait.tv_nsec = 10000000; - count = 0; for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -159,9 +162,9 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo * nfp_hwinfo_read(struct nfp_cpp *cpp) { - struct nfp_hwinfo *db; - size_t hwdb_size = 0; int err; + size_t hwdb_size = 0; + struct nfp_hwinfo *db; db = nfp_hwinfo_fetch(cpp, &hwdb_size); if (db == NULL) @@ -186,7 +189,9 @@ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) { - const char *key, *val, *end; + const char *key; + const char *val; + const char *end; if (hwinfo == NULL || lookup == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0071d3fc37..1e601313b4 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -68,10 +68,10 @@ static int nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) { - struct nfp_nffw_info *nffw_info; - uint32_t cpp_id; - uint64_t addr; int err; + uint64_t addr; + uint32_t cpp_id; + struct nfp_nffw_info *nffw_info; nffw_info = nfp_nffw_info_open(cpp); if (nffw_info == NULL) @@ -100,8 +100,8 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) { - struct nfp_mip *mip; int err; + struct nfp_mip *mip; mip = malloc(sizeof(*mip)); if (mip == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 4d26e6f052..05e0ff46e5 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -79,9 +79,9 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { + int err; uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - int err; err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -122,11 +122,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { - uint32_t model = nfp_cpp_model(cpp); - struct nfp_cpp_mutex *mutex; - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ int err; uint32_t tmp; + struct nfp_cpp_mutex *mutex; + uint32_t model = nfp_cpp_model(cpp); + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -241,12 +241,13 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) { - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + int err; + uint32_t key; + uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t key, value; uint16_t interface = nfp_cpp_interface(cpp); - int err; + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -295,12 +296,14 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) { + int err; + uint32_t key; + uint32_t tmp; + uint32_t value; + struct nfp_cpp *cpp = mutex->cpp; uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ - uint32_t key, value, tmp; - struct nfp_cpp *cpp = mutex->cpp; - int err; if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 7ff468373b..32e0fc94bb 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,9 +68,11 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - uint32_t mode, addr40; - uint32_t xpbaddr, imbcppat; int err; + uint32_t mode; + uint32_t addr40; + uint32_t xpbaddr; + uint32_t imbcppat; /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; @@ -117,10 +119,10 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) { - struct nfp_nffw_info_data *fwinf; - struct nfp_nffw_info *state; - uint32_t info_ver; int err; + uint32_t info_ver; + struct nfp_nffw_info *state; + struct nfp_nffw_info_data *fwinf; state = malloc(sizeof(*state)); if (state == NULL) @@ -182,8 +184,9 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { + uint32_t i; + uint32_t cnt; struct nffw_fwinfo *fwinfo; - uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 87eed3d951..a00bd5870d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -72,10 +72,11 @@ nfp_nsp_print_extended_error(uint32_t ret_val) static int nfp_nsp_check(struct nfp_nsp *state) { - struct nfp_cpp *cpp = state->cpp; - uint64_t nsp_status, reg; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t nsp_status; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_status = nfp_resource_address(state->res) + NSP_STATUS; @@ -113,9 +114,9 @@ nfp_nsp_check(struct nfp_nsp *state) struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) { - struct nfp_resource *res; - struct nfp_nsp *state; int err; + struct nfp_nsp *state; + struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); if (res == NULL) @@ -170,13 +171,12 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t mask, uint64_t val) { - struct timespec wait; - uint32_t count; int err; + uint32_t count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -217,10 +217,15 @@ nfp_nsp_command(struct nfp_nsp *state, uint32_t buff_cpp, uint64_t buff_addr) { - uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; - struct nfp_cpp *cpp = state->cpp; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t ret_val; + uint64_t nsp_base; + uint64_t nsp_buffer; + uint64_t nsp_status; + uint64_t nsp_command; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_base = nfp_resource_address(state->res); @@ -296,11 +301,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, void *out_buf, unsigned int out_size) { - struct nfp_cpp *cpp = nsp->cpp; + int err; + int ret; + uint64_t reg; size_t max_size; - uint64_t reg, cpp_buf; - int ret, err; uint32_t cpp_id; + uint64_t cpp_buf; + struct nfp_cpp *cpp = nsp->cpp; if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", @@ -360,13 +367,12 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, int nfp_nsp_wait(struct nfp_nsp *state) { - struct timespec wait; - uint32_t count; int err; + int count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 31677b66e6..3081e22dad 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -26,9 +26,9 @@ struct nsp_identify { struct nfp_nsp_identify * __nfp_nsp_identify(struct nfp_nsp *nsp) { - struct nfp_nsp_identify *nspi = NULL; - struct nsp_identify *ni; int ret; + struct nsp_identify *ni; + struct nfp_nsp_identify *nspi = NULL; if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; @@ -77,9 +77,9 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val) { - struct nfp_sensors s; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + struct nfp_sensors s; nsp = nfp_nsp_open(cpp); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 899fcd7441..9e8a247e5c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -149,9 +149,10 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, uint32_t index, struct nfp_eth_table_port *dst) { - uint32_t rate; uint32_t fec; - uint64_t port, state; + uint64_t port; + uint32_t rate; + uint64_t state; port = rte_le_to_cpu_64(src->port); state = rte_le_to_cpu_64(src->state); @@ -199,7 +200,8 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - uint32_t i, j; + uint32_t i; + uint32_t j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -241,12 +243,13 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) static struct nfp_eth_table * __nfp_eth_read_ports(struct nfp_nsp *nsp) { - union eth_table_entry *entries; - struct nfp_eth_table *table; - uint32_t table_sz; + int ret; uint32_t i; uint32_t j; - int ret, cnt = 0; + int cnt = 0; + uint32_t table_sz; + struct nfp_eth_table *table; + union eth_table_entry *entries; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -320,8 +323,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) { - struct nfp_eth_table *ret; struct nfp_nsp *nsp; + struct nfp_eth_table *ret; nsp = nfp_nsp_open(cpp); if (nsp == NULL) @@ -337,9 +340,9 @@ struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + union eth_table_entry *entries; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -400,8 +403,8 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) int nfp_eth_config_commit_end(struct nfp_nsp *nsp) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); int ret = 1; + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); if (nfp_nsp_config_modified(nsp)) { ret = nfp_nsp_write_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); @@ -432,9 +435,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -474,9 +477,9 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -515,9 +518,9 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, uint32_t val, const uint64_t ctrl_bit) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; + uint32_t idx = nfp_nsp_config_idx(nsp); + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); /* * Note: set features were added in ABI 0.14 but the error @@ -603,8 +606,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode) { - struct nfp_nsp *nsp; int err; + struct nfp_nsp *nsp; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 9dd4832779..fa92f2762e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -67,10 +67,12 @@ static int nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) { - char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; + int ret; + uint32_t i; + uint32_t key; + uint32_t cpp_id; struct nfp_resource_entry entry; - uint32_t cpp_id, key; - int ret, i; + char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; cpp_id = NFP_CPP_ID(NFP_RESOURCE_TBL_TARGET, 3, 0); /* Atomic read */ @@ -152,11 +154,11 @@ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) { - struct nfp_cpp_mutex *dev_mutex; - struct nfp_resource *res; int err; + uint16_t count = 0; struct timespec wait; - uint16_t count; + struct nfp_resource *res; + struct nfp_cpp_mutex *dev_mutex; res = malloc(sizeof(*res)); if (res == NULL) @@ -175,7 +177,6 @@ nfp_resource_acquire(struct nfp_cpp *cpp, wait.tv_sec = 0; wait.tv_nsec = 1000000; - count = 0; for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 243d3c9ce5..a34278beca 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -85,8 +85,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, struct nfp_rtsym_table * nfp_rtsym_table_read(struct nfp_cpp *cpp) { - struct nfp_rtsym_table *rtbl; struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; mip = nfp_mip_open(cpp); rtbl = __nfp_rtsym_table_read(cpp, mip); @@ -99,13 +99,18 @@ struct nfp_rtsym_table * __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) { - uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; - struct nfp_rtsym_entry *rtsymtab; + int n; + int err; + uint32_t size; + uint32_t strtab_addr; + uint32_t symtab_addr; + uint32_t strtab_size; + uint32_t symtab_size; struct nfp_rtsym_table *cache; + struct nfp_rtsym_entry *rtsymtab; const uint32_t dram = NFP_CPP_ID(NFP_CPP_TARGET_MU, NFP_CPP_ACTION_RW, 0) | NFP_ISL_EMEM0; - int err, n, size; if (mip == NULL) return NULL; @@ -341,10 +346,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) { - const struct nfp_rtsym *sym; - uint32_t val32; - uint64_t val; int err; + uint64_t val; + uint32_t val32; + const struct nfp_rtsym *sym; sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 06/27] net/nfp: adjust the log statement 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (4 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 05/27] net/nfp: standard the local variable coding style Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 07/27] net/nfp: standard the comment style Chaoyong He ` (21 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add log statement to the important control logic, which means more strict check of the return value of function call. Also remove some verbose info log statement. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 37 ++++++---------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 20 +++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 28 ++++++++-------- drivers/net/nfp/nfpcore/nfp_mip.c | 7 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 4 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 ++++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 25 +++++++++++---- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++--- drivers/net/nfp/nfpcore/nfp_resource.c | 17 +++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 14 +++----- 10 files changed, 92 insertions(+), 79 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 78beee07ef..bdf4a658f5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -174,18 +174,10 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } - offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + offset &= mask; bitsize = 40 - 16; } else { @@ -198,30 +190,16 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); - bitsize = 40 - 21; } - if (bar->bitsize < bitsize) { - PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + if (bar->bitsize < bitsize) return -EINVAL; - } newcfg |= offset >> bitsize; @@ -254,7 +232,6 @@ nfp_bar_write(struct nfp_pcie_user *nfp, *(uint32_t *)(bar->csr) = newcfg; bar->barcfg = newcfg; - PMD_DRV_LOG(DEBUG, "BAR%d: updated to 0x%08x", bar->index, newcfg); return 0; } @@ -795,7 +772,11 @@ nfp6000_init(struct nfp_cpp *cpp, desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; - nfp_enable_bars(desc); + ret = nfp_enable_bars(desc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Enable bars failed"); + return -1; + } nfp_cpp_priv_set(cpp, desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 776842bdf6..66f4ddaab7 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -200,6 +200,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, err = cpp->op->area_init(area, dest, address, size); if (err < 0) { + PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } @@ -243,10 +244,13 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc(cpp, destination, address, size); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate CPP area"); return NULL; + } if (nfp_cpp_area_acquire(area) != 0) { + PMD_DRV_LOG(ERR, "Failed to acquire CPP area"); nfp_cpp_area_free(area); return NULL; } @@ -294,8 +298,10 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; + } } return 0; @@ -662,7 +668,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { - PMD_DRV_LOG(ERR, "Area allocation/acquire failed"); + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } @@ -691,8 +697,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; + } err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); @@ -746,8 +754,10 @@ nfp_cpp_map_area(struct nfp_cpp *cpp, uint8_t *res; *area = nfp_cpp_area_alloc_acquire(cpp, cpp_id, addr, size); - if (*area == NULL) + if (*area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for map"); goto err_eio; + } res = nfp_cpp_area_iomem(*area); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 819761eda0..b658b5e900 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -74,7 +74,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, new_crc = nfp_crc32_posix((char *)db, size); crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { - PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", + PMD_DRV_LOG(ERR, "CRC mismatch, calculated %#x, expected %#x", new_crc, *crc); return -EINVAL; } @@ -94,34 +94,36 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); - if (res) { - cpp_id = nfp_resource_cpp_id(res); - cpp_addr = nfp_resource_address(res); - *cpp_size = nfp_resource_size(res); + if (res == NULL) { + PMD_DRV_LOG(ERR, "HWInfo - acquire resource failed"); + return NULL; + } - nfp_resource_release(res); + cpp_id = nfp_resource_cpp_id(res); + cpp_addr = nfp_resource_address(res); + *cpp_size = nfp_resource_size(res); - if (*cpp_size < HWINFO_SIZE_MIN) - return NULL; - } else { + nfp_resource_release(res); + + if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - } db = malloc(*cpp_size + 1); if (db == NULL) return NULL; err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size); - if (err != (int)*cpp_size) + if (err != (int)*cpp_size) { + PMD_DRV_LOG(ERR, "HWInfo - CPP read error %d", err); goto exit_free; + } header = (void *)db; - PMD_DRV_LOG(DEBUG, "NFP HWINFO header: %#08x", *(uint32_t *)header); if (nfp_hwinfo_is_updating(header)) goto exit_free; if (header->version != NFP_HWINFO_VERSION_2) { - PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", + PMD_DRV_LOG(ERR, "Unknown HWInfo version: %#08x", header->version); goto exit_free; } diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 1e601313b4..086e82db70 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -46,16 +46,16 @@ nfp_mip_try_read(struct nfp_cpp *cpp, ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip)); if (ret != sizeof(*mip)) { - PMD_DRV_LOG(ERR, "Failed to read MIP data (%d, %zu)", ret, sizeof(*mip)); + PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } if (mip->signature != NFP_MIP_SIGNATURE) { - PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", + PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { - PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", + PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -109,6 +109,7 @@ nfp_mip_open(struct nfp_cpp *cpp) err = nfp_mip_read_resource(cpp, mip); if (err != 0) { + PMD_DRV_LOG(ERR, "Failed to read MIP resource"); free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 05e0ff46e5..82919d8270 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -221,9 +221,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 32e0fc94bb..6ba40cd085 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,6 +3,7 @@ * All rights reserved. */ +#include "../nfp_logs.h" #include "nfp_cpp.h" #include "nfp_nffw.h" #include "nfp_mip.h" @@ -131,8 +132,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) memset(state, 0, sizeof(*state)); state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); - if (state->res == NULL) + if (state->res == NULL) { + PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); goto err_free; + } fwinf = &state->fwinf; @@ -142,8 +145,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), nfp_resource_address(state->res), fwinf, sizeof(*fwinf)); - if (err < (int)sizeof(*fwinf)) + if (err < (int)sizeof(*fwinf)) { + PMD_DRV_LOG(ERR, "NFFW - CPP read error %d", err); goto err_release; + } if (nffw_res_flg_init_get(fwinf) == 0) goto err_release; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index a00bd5870d..76d418d478 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -82,8 +82,10 @@ nfp_nsp_check(struct nfp_nsp *state) nsp_status = nfp_resource_address(state->res) + NSP_STATUS; err = nfp_cpp_readq(cpp, nsp_cpp, nsp_status, ®); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed %d", err); return err; + } if (FIELD_GET(NSP_STATUS_MAGIC, reg) != NSP_MAGIC) { PMD_DRV_LOG(ERR, "Cannot detect NFP Service Processor"); @@ -119,8 +121,10 @@ nfp_nsp_open(struct nfp_cpp *cpp) struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); - if (res == NULL) + if (res == NULL) { + PMD_DRV_LOG(ERR, "NSP - resource acquire failed"); return NULL; + } state = malloc(sizeof(*state)); if (state == NULL) { @@ -133,6 +137,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) err = nfp_nsp_check(state); if (err != 0) { + PMD_DRV_LOG(ERR, "NSP - check failed"); nfp_nsp_close(state); return NULL; } @@ -180,8 +185,10 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed"); return err; + } if ((*reg & mask) == val) return 0; @@ -234,8 +241,10 @@ nfp_nsp_command(struct nfp_nsp *state, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "Check NSP command failed"); return err; + } if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { @@ -261,7 +270,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", err, code); return err; } @@ -270,7 +279,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", err, code); return err; } @@ -352,8 +361,10 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, } ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); - if (ret < 0) + if (ret < 0) { + PMD_DRV_LOG(ERR, "NSP command failed"); return ret; + } if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9e8a247e5c..51dcf24f5f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -259,7 +259,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } @@ -278,7 +278,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * above. */ if (ret != 0 && ret != cnt) { - PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", + PMD_DRV_LOG(ERR, "Table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; } @@ -357,12 +357,12 @@ nfp_eth_config_start(struct nfp_cpp *cpp, ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } if ((entries[idx].port & NSP_ETH_PORT_LANES_MASK) == 0) { - PMD_DRV_LOG(ERR, "trying to set port state on disabled port %d", idx); + PMD_DRV_LOG(ERR, "Trying to set port state on disabled port %d", idx); goto err; } @@ -642,7 +642,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, rate = nfp_eth_speed2rate(speed); if (rate == RATE_INVALID) { - PMD_DRV_LOG(ERR, "could not find matching lane rate for speed %u", speed); + PMD_DRV_LOG(ERR, "Could not find matching lane rate for speed %u", speed); return -EINVAL; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index fa92f2762e..363f7d6198 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -118,16 +118,22 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, { int err; - if (nfp_cpp_mutex_lock(dev_mutex) != 0) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex lock failed"); return -EINVAL; + } err = nfp_cpp_resource_find(cpp, res); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP resource find failed"); goto err_unlock_dev; + } err = nfp_cpp_mutex_trylock(res->mutex); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex trylock failed"); goto err_res_mutex_free; + } nfp_cpp_mutex_unlock(dev_mutex); @@ -171,6 +177,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); free(res); return NULL; } @@ -182,8 +189,10 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err = nfp_resource_try_acquire(cpp, res, dev_mutex); if (err == 0) break; - if (err != -EBUSY) + if (err != -EBUSY) { + PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); goto err_free; + } if (count++ > 1000) { PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index a34278beca..d15a920752 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -60,8 +60,6 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->size = ((uint64_t)fw->size_hi << 32) | rte_le_to_cpu_32(fw->size_lo); - PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", - sw->name, sw->addr, sw->size, sw->target); switch (fw->target) { case SYM_TGT_LMEM: sw->target = NFP_RTSYM_TARGET_LMEM; @@ -227,7 +225,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) { switch (sym->type) { case NFP_RTSYM_TYPE_NONE: - PMD_DRV_LOG(ERR, "rtsym '%s': type NONE", sym->name); + PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ case NFP_RTSYM_TYPE_FUNCTION: @@ -235,7 +233,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_ABS: return sizeof(uint64_t); default: - PMD_DRV_LOG(ERR, "rtsym '%s': unknown type: %d", sym->name, sym->type); + PMD_DRV_LOG(ERR, "Unknown RTSYM type %u", sym->type); return 0; } } @@ -366,7 +364,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); break; default: - PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", name, sym->size); err = -EINVAL; break; @@ -396,10 +394,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, uint32_t cpp_id; const struct nfp_rtsym *sym; - PMD_DRV_LOG(DEBUG, "mapping symbol %s", name); sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { - PMD_INIT_LOG(ERR, "symbol lookup fails for %s", name); + PMD_DRV_LOG(ERR, "Symbol lookup fails for %s", name); return NULL; } @@ -418,10 +415,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, mem = nfp_cpp_map_area(rtbl->cpp, cpp_id, addr, sym->size, area); if (mem == NULL) { - PMD_INIT_LOG(ERR, "Failed to map symbol %s", name); + PMD_DRV_LOG(ERR, "Failed to map symbol %s", name); return NULL; } - PMD_DRV_LOG(DEBUG, "symbol %s with address %p", name, mem); return mem; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 07/27] net/nfp: standard the comment style 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (5 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 06/27] net/nfp: adjust the log statement Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 08/27] net/nfp: using the DPDK memory management API Chaoyong He ` (20 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Follow the DPDK coding style, use the kdoc comment style. Also add some comment to help understand logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 504 ++++----------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 39 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 484 ++++++++++++++++---- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 21 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 + drivers/net/nfp/nfpcore/nfp_mip.c | 43 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 69 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 49 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 6 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 53 ++- drivers/net/nfp/nfpcore/nfp_nsp.h | 108 ++--- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 170 ++++--- drivers/net/nfp/nfpcore/nfp_resource.c | 103 +++-- drivers/net/nfp/nfpcore/nfp_resource.h | 28 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 59 ++- drivers/net/nfp/nfpcore/nfp_rtsym.h | 12 +- drivers/net/nfp/nfpcore/nfp_target.c | 2 +- 17 files changed, 888 insertions(+), 864 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 139752f85a..82189e9910 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -10,9 +10,7 @@ struct nfp_cpp_mutex; -/* - * NFP CPP handle - */ +/* NFP CPP handle */ struct nfp_cpp { uint32_t model; uint32_t interface; @@ -37,9 +35,7 @@ struct nfp_cpp { int driver_lock_needed; }; -/* - * NFP CPP device area handle - */ +/* NFP CPP device area handle */ struct nfp_cpp_area { struct nfp_cpp *cpp; char *name; @@ -127,35 +123,45 @@ struct nfp_cpp_operations { #define NFP_CPP_TARGET_ID_MASK 0x1f -/* +/** * Pack target, token, and action into a CPP ID. * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id * - * @return NFP CPP ID + * @return + * NFP CPP ID */ #define NFP_CPP_ID(target, action, token) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ (((action) & 0xff) << 8)) -/* +/** * Pack target, token, action, and island into a CPP ID. - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id - * @island NFP CPP island id * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @return NFP CPP ID + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id + * @param island + * NFP CPP island id + * + * @return + * NFP CPP ID */ #define NFP_CPP_ISLAND_ID(target, action, token, island) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ @@ -163,9 +169,12 @@ struct nfp_cpp_operations { /** * Return the NFP CPP target of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP target + * @param id + * NFP CPP ID + * + * @return + * NFP CPP target */ static inline uint8_t NFP_CPP_ID_TARGET_of(uint32_t id) @@ -173,11 +182,14 @@ NFP_CPP_ID_TARGET_of(uint32_t id) return (id >> 24) & NFP_CPP_TARGET_ID_MASK; } -/* +/** * Return the NFP CPP token of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP token + * @param id + * NFP CPP ID + * + * @return + * NFP CPP token */ static inline uint8_t NFP_CPP_ID_TOKEN_of(uint32_t id) @@ -185,11 +197,14 @@ NFP_CPP_ID_TOKEN_of(uint32_t id) return (id >> 16) & 0xff; } -/* +/** * Return the NFP CPP action of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP action + * @param id + * NFP CPP ID + * + * @return + * NFP CPP action */ static inline uint8_t NFP_CPP_ID_ACTION_of(uint32_t id) @@ -197,11 +212,14 @@ NFP_CPP_ID_ACTION_of(uint32_t id) return (id >> 8) & 0xff; } -/* +/** * Return the NFP CPP island of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP island + * @param id + * NFP CPP ID + * + * @return + * NFP CPP island */ static inline uint8_t NFP_CPP_ID_ISLAND_of(uint32_t id) @@ -215,109 +233,57 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) */ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); -/* - * Set the model id - * - * @param cpp NFP CPP operations structure - * @param model Model ID - */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param interface Interface ID - */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param serial NFP serial byte array - * @param len Length of the serial byte array - */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); -/* - * Set the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); -/* - * Return the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void *nfp_cpp_priv(struct nfp_cpp *cpp); -/* - * Get the privately allocated portion of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the private area, or NULL on failure - */ void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); -/* - * NFP CPP core interface for CPP clients. - */ - -/* - * Open a NFP CPP handle to a CPP device - * - * @param[in] id 0-based ID for the CPP interface to use - * - * @return NFP CPP handle, or NULL on failure. - */ +/* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed); -/* - * Free a NFP CPP handle - * - * @param[in] cpp NFP CPP handle - */ void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/* - * NFP_CPP_MODEL_CHIP_of - retrieve the chip ID from the model ID +/** + * Retrieve the chip ID from the model ID * * The chip ID is a 16-bit BCD+A-F encoding for the chip type. * - * @param[in] model NFP CPP model id - * @return NFP CPP chip id + * @param model + * NFP CPP model id + * + * @return + * NFP CPP chip id */ #define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) -/* - * NFP_CPP_MODEL_IS_6000 - Check for the NFP6000 family of devices +/** + * Check for the NFP6000 family of devices * * NOTE: The NFP4000 series is considered as a NFP6000 series variant. * - * @param[in] model NFP CPP model id - * @return true if model is in the NFP6000 family, false otherwise. + * @param model + * NFP CPP model id + * + * @return + * true if model is in the NFP6000 family, false otherwise. */ #define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) -/* - * nfp_cpp_model - Retrieve the Model ID of the NFP - * - * @param[in] cpp NFP CPP handle - * @return NFP CPP Model ID - */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,7 +296,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); #define NFP_CPP_INTERFACE_TYPE_RPC 0x3 #define NFP_CPP_INTERFACE_TYPE_ILA 0x4 -/* +/** * Construct a 16-bit NFP Interface ID * * Interface IDs consists of 4 bits of interface type, 4 bits of unit @@ -340,422 +306,138 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * which use the MU Atomic CompareAndWrite operation - hence the limit to 16 * bits to be able to use the NFP Interface ID as a lock owner. * - * @param[in] type NFP Interface Type - * @param[in] unit Unit identifier for the interface type - * @param[in] channel Channel identifier for the interface unit - * @return Interface ID + * @param type + * NFP Interface Type + * @param unit + * Unit identifier for the interface type + * @param channel + * Channel identifier for the interface unit + * + * @return + * Interface ID */ #define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) -/* +/** * Get the interface type of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's type + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's type */ #define NFP_CPP_INTERFACE_TYPE_of(interface) (((interface) >> 12) & 0xf) -/* +/** * Get the interface unit of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's unit + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's unit */ #define NFP_CPP_INTERFACE_UNIT_of(interface) (((interface) >> 8) & 0xf) -/* +/** * Get the interface channel of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's channel + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's channel */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) -/* - * Retrieve the Interface ID of the NFP - * @param[in] cpp NFP CPP handle - * @return NFP CPP Interface ID - */ + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -/* - * Retrieve the NFP Serial Number (unique per NFP) - * @param[in] cpp NFP CPP handle - * @param[out] serial Pointer to reference the serial number array - * - * @return size of the NFP6000 serial number, in bytes - */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] name Name of owner of the area - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t cpp_id, const char *name, uint64_t address, uint32_t size); -/* - * Free an allocated NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_free(struct nfp_cpp_area *area); -/* - * Acquire the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - * - * @return 0 on success, -1 on failure. - */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area); -/* - * Release the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release(struct nfp_cpp_area *area); -/* - * Allocate, then acquire the resources needed to access the NFP CPP area handle - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Release the resources, then free the NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Read from a NFP CPP area handle into a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer to receive the data - * @param[in] length Length of the data to read - * - * @return bytes read on success, negative value on failure. - * - */ int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); -/* - * Write to a NFP CPP area handle from a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer that holds the data - * @param[in] length Length of the data to read - * - * @return bytes written on success, negative value on failure. - */ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area - * @area: CPP area handle - * - * Returns an iomem pointer for use with readl()/writel() style operations. - * - * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL - */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Get the NFP CPP handle that is the parent of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return NFP CPP handle - */ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); -/* - * Get the name passed during allocation of the NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the area's name - */ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); -/* - * Read a block of data from a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy read data to - * @param[in] length Size of the area to reserve - * - * @return bytes read on success, -1 on failure. - */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, void *kernel_vaddr, size_t length); -/* - * Write a block of data to a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy write data from - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, -1 on failure. - */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); -/* - * Read a single 32-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); -/* - * Write a single 32-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); -/* - * Read a single 64-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); -/* - * Write a single 64-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); -/* - * Write a single 32-bit value on the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); -/* - * Read a single 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Read a 32-bit word from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t *value); -/* - * Write a 32-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - * - */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t value); -/* - * Read a 64-bit work from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t *value); -/* - * Write a 64-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -/* - * Initialize a mutex location - - * The CPP target:address must point to a 64-bit aligned location, and will - * initialize 64 bits of data at the location. - * - * This creates the initial mutex state, as locked by this nfp_cpp_interface(). - * - * This function should only be called when setting up the initial lock state - * upon boot-up of the system. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id Unique 32-bit value for this mutex - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Create a mutex handle from an address controlled by a MU Atomic engine - * - * The CPP target:address must point to a 64-bit aligned location, and reserve - * 64 bits of data at the location for use by the handle. - * - * Only target/address pairs that point to entities that support the MU Atomic - * Engine's CmpAndSwap32 command are supported. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id 32-bit unique key (must match the key at this location) - * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on - * failure. - */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Free a mutex handle - does not alter the lock state - * - * @param mutex NFP CPP Mutex handle - */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); -/* - * Lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); -/* - * Unlock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); -/* - * Attempt to lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. - */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index bdf4a658f5..7e94bfb611 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -72,40 +72,25 @@ #define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ (((bar) * 8 + (slot)) * 4) -/* - * Define to enable a bit more verbose debug output. - * Set to 1 to enable a bit more verbose debug output. - */ struct nfp_pcie_user; struct nfp6000_area_priv; -/* - * struct nfp_bar - describes BAR configuration and usage - * @nfp: backlink to owner - * @barcfg: cached contents of BAR config CSR - * @base: the BAR's base CPP offset - * @mask: mask for the BAR aperture (read only) - * @bitsize: bitsize of BAR aperture (read only) - * @index: index of the BAR - * @lock: lock to specify if bar is in use - * @refcnt: number of current users - * @iomem: mapped IO memory - */ +/* Describes BAR configuration and usage */ #define NFP_BAR_MIN 1 #define NFP_BAR_MID 5 #define NFP_BAR_MAX 7 struct nfp_bar { - struct nfp_pcie_user *nfp; - uint32_t barcfg; - uint64_t base; /* CPP address base */ - uint64_t mask; /* Bit mask of the bar */ - uint32_t bitsize; /* Bit size of the bar */ - uint32_t index; - int lock; + struct nfp_pcie_user *nfp; /**< Backlink to owner */ + uint32_t barcfg; /**< BAR config CSR */ + uint64_t base; /**< Base CPP offset */ + uint64_t mask; /**< Mask of the BAR aperture (read only) */ + uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ + uint32_t index; /**< Index of the BAR */ + int lock; /**< If the BAR has been locked */ char *csr; - char *iomem; + char *iomem; /**< mapped IO memory */ }; #define BUSDEV_SZ 13 @@ -360,9 +345,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* - * Generic CPP bus access interface. - */ +/* Generic CPP bus access interface. */ struct nfp6000_area_priv { struct nfp_bar *bar; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 66f4ddaab7..f601907673 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -26,6 +26,15 @@ #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/** + * Set the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) @@ -33,12 +42,29 @@ nfp_cpp_priv_set(struct nfp_cpp *cpp, cpp->priv = priv; } +/** + * Return the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void * nfp_cpp_priv(struct nfp_cpp *cpp) { return cpp->priv; } +/** + * Set the model id + * + * @param cpp + * NFP CPP operations structure + * @param model + * Model ID + */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) @@ -46,6 +72,15 @@ nfp_cpp_model_set(struct nfp_cpp *cpp, cpp->model = model; } +/** + * Retrieve the Model ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Model ID + */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp) { @@ -63,6 +98,14 @@ nfp_cpp_model(struct nfp_cpp *cpp) return model; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param interface + * Interface ID + */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) @@ -70,6 +113,17 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, cpp->interface = interface; } +/** + * Retrieve the Serial ID of the NFP + * + * @param cpp + * NFP CPP handle + * @param serial + * Pointer to NFP serial number + * + * @return + * Length of NFP serial number + */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) @@ -78,6 +132,16 @@ nfp_cpp_serial(struct nfp_cpp *cpp, return cpp->serial_len; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param serial + * NFP serial byte array + * @param serial_len + * Length of the serial byte array + */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, @@ -96,6 +160,15 @@ nfp_cpp_serial_set(struct nfp_cpp *cpp, return 0; } +/** + * Retrieve the Interface ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Interface ID + */ uint16_t nfp_cpp_interface(struct nfp_cpp *cpp) { @@ -105,18 +178,45 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Get the privately allocated portion of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the private area, or NULL on failure + */ void * nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area) { return &cpp_area[1]; } +/** + * Get the NFP CPP handle that is the pci_dev of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * NFP CPP handle + */ struct nfp_cpp * nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area) { return cpp_area->cpp; } +/** + * Get the name passed during allocation of the NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the area's name + */ const char * nfp_cpp_area_name(struct nfp_cpp_area *cpp_area) { @@ -153,15 +253,24 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) return cpp->mu_locality_lsb; } -/* - * nfp_cpp_area_alloc - allocate a new CPP area - * @cpp: CPP handle - * @dest: CPP id - * @address: start address on CPP target - * @size: size of area in bytes +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. * - * Allocate and initialize a CPP area structure. The area must later - * be locked down with an 'acquire' before it can be safely accessed. + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param name + * Name of region + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL * * NOTE: @address and @size must be 32-bit aligned values. */ @@ -211,6 +320,25 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, return area; } +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. + * + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * + * NOTE: @address and @size must be 32-bit aligned values. + */ struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, @@ -220,17 +348,22 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, 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 - * @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. * + * @param cpp + * CPP device handle + * @param destination + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * * NOTE: @address and @size must be 32-bit aligned values. * * NOTE: The area must also be 'released' when the structure is freed. @@ -258,11 +391,11 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, return area; } -/* - * nfp_cpp_area_free - free up the CPP area - * area: CPP area handle - * +/** * Frees up memory resources held by the CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_free(struct nfp_cpp_area *area) @@ -272,11 +405,11 @@ nfp_cpp_area_free(struct nfp_cpp_area *area) free(area); } -/* - * nfp_cpp_area_release_free - release CPP area and free it - * area: CPP area handle +/** + * Releases CPP area and frees up memory resources held by it. * - * Releases CPP area and frees up memory resources held by the it. + * @param area + * CPP area handle */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area) @@ -285,12 +418,15 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) nfp_cpp_area_free(area); } -/* - * nfp_cpp_area_acquire - lock down a CPP area for access - * @area: CPP area handle +/** + * Locks down the CPP area for a potential long term activity. + * Area must always be locked down before being accessed. * - * Locks down the CPP area for a potential long term activity. Area - * must always be locked down before being accessed. + * @param area + * CPP area handle + * + * @return + * 0 on success, -1 on failure. */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area) @@ -307,11 +443,11 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) return 0; } -/* - * nfp_cpp_area_release - release a locked down CPP area - * @area: CPP area handle - * +/** * Releases a previously locked down CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_release(struct nfp_cpp_area *area) @@ -320,16 +456,16 @@ nfp_cpp_area_release(struct nfp_cpp_area *area) area->cpp->op->area_release(area); } -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area +/** + * Returns an iomem pointer for use with readl()/writel() style operations. * - * @area: CPP area handle + * @param area + * CPP area handle * - * Returns an iomem pointer for use with readl()/writel() style operations. + * @return + * Pointer to the area, or NULL * * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL */ void * nfp_cpp_area_iomem(struct nfp_cpp_area *area) @@ -342,18 +478,22 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) return iomem; } -/* - * nfp_cpp_area_read - read data from CPP area +/** + * Read data from indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to put data into - * @length: number of bytes to read + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Read data from indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -368,18 +508,22 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, return area->cpp->op->area_read(area, kernel_vaddr, offset, length); } -/* - * nfp_cpp_area_write - write data to CPP area +/** + * Write data to indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to read data from - * @length: number of bytes to write + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Write data to indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -436,6 +580,19 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, return xpb; } +/** + * Read a uint32_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, @@ -450,6 +607,19 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, @@ -462,6 +632,19 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, @@ -476,6 +659,19 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, @@ -489,6 +685,21 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint32_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -504,6 +715,21 @@ nfp_cpp_readl(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -518,6 +744,21 @@ nfp_cpp_writel(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -533,6 +774,21 @@ nfp_cpp_readq(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -547,6 +803,19 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Write a uint32_t word to a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -559,6 +828,19 @@ nfp_xpb_writel(struct nfp_cpp *cpp, return nfp_cpp_writel(cpp, cpp_dest, xpb_addr, value); } +/** + * Read a uint32_t value from a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -625,9 +907,11 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return cpp; } -/* - * nfp_cpp_free - free the CPP handle - * @cpp: CPP handle +/** + * Free the CPP handle + * + * @param cpp + * CPP handle */ void nfp_cpp_free(struct nfp_cpp *cpp) @@ -641,6 +925,19 @@ nfp_cpp_free(struct nfp_cpp *cpp) free(cpp); } +/** + * Create a NFP CPP handle from device + * + * @param dev + * PCI device + * @param driver_lock_needed + * Driver lock flag + * + * @return + * NFP CPP handle on success, NULL on failure + * + * NOTE: On failure, cpp_ops->free will be called! + */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) @@ -648,13 +945,22 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * nfp_cpp_read - read from CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer for result - * @length: number of bytes to read +/** + * Read from CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer for result + * @param length + * Number of bytes to read + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_read(struct nfp_cpp *cpp, @@ -678,13 +984,22 @@ nfp_cpp_read(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_write - write to CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer to read from - * @length: number of bytes to write +/** + * Write to CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer to read from + * @param length + * Number of bytes to write + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_write(struct nfp_cpp *cpp, @@ -731,18 +1046,23 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return 0; } -/* - * nfp_cpp_map_area() - Helper function to map an area - * @cpp: NFP CPP handler - * @cpp_id: CPP ID - * @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). * - * Map an area of IOMEM access. To undo the effect of this function call - * @nfp_cpp_area_release_free(*area). + * @param cpp + * NFP CPP handler + * @param cpp_id + * CPP id + * @param addr + * CPP address + * @param size + * Size of the area + * @param area + * Area handle (output) * - * Return: Pointer to memory mapped area or NULL + * @return + * Pointer to memory mapped area or NULL */ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index b658b5e900..f5579ab60f 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -3,7 +3,8 @@ * All rights reserved. */ -/* Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM +/* + * Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM * after chip reset. * * Examples of the fields: @@ -146,7 +147,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *db; wait.tv_sec = 0; - wait.tv_nsec = 10000000; + wait.tv_nsec = 10000000; /* 10ms */ for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -154,7 +155,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, return db; nanosleep(&wait, NULL); - if (count++ > 200) { + if (count++ > 200) { /* 10ms * 200 = 2s */ PMD_DRV_LOG(ERR, "NFP access error"); return NULL; } @@ -180,12 +181,16 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return db; } -/* - * nfp_hwinfo_lookup() - Find a value in the HWInfo table by name - * @hwinfo: NFP HWinfo table - * @lookup: HWInfo name to search for +/** + * Find a value in the HWInfo table by name + * + * @param hwinfo + * NFP HWInfo table + * @param lookup + * HWInfo name to search for * - * Return: Value of the HWInfo name, or NULL + * @return + * Value of the HWInfo name, or NULL */ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index a3da7512db..424db8035d 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -59,6 +59,8 @@ * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' * * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. */ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 086e82db70..0892c99e96 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -87,15 +87,16 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, return err; } -/* - * nfp_mip_open() - Get device MIP structure - * @cpp: NFP CPP Handle - * - * Copy MIP structure from NFP device and return it. The returned +/** + * Copy MIP structure from NFP device and return it. The returned * structure is handled internally by the library and should be - * freed by calling nfp_mip_close(). + * freed by calling @nfp_mip_close(). + * + * @param cpp + * NFP CPP Handle * - * Return: pointer to mip, NULL on failure. + * @return + * Pointer to MIP, NULL on failure. */ struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) @@ -131,11 +132,15 @@ nfp_mip_name(const struct nfp_mip *mip) return mip->name; } -/* - * nfp_mip_symtab() - Get the address and size of the MIP symbol table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol table - * @size: Location for size of MIP symbol table +/** + * Get the address and size of the MIP symbol table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol table + * @param size + * Location for size of MIP symbol table */ void nfp_mip_symtab(const struct nfp_mip *mip, @@ -146,11 +151,15 @@ nfp_mip_symtab(const struct nfp_mip *mip, *size = rte_le_to_cpu_32(mip->symtab_size); } -/* - * nfp_mip_strtab() - Get the address and size of the MIP symbol name table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol name table - * @size: Location for size of MIP symbol name table +/** + * Get the address and size of the MIP symbol name table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol name table + * @param size + * Location for size of MIP symbol name table */ void nfp_mip_strtab(const struct nfp_mip *mip, diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82919d8270..404d4fa938 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -53,7 +53,7 @@ _nfp_cpp_mutex_validate(uint32_t model, return 0; } -/* +/** * Initialize a mutex location * * The CPP target:address must point to a 64-bit aligned location, and @@ -65,13 +65,17 @@ _nfp_cpp_mutex_validate(uint32_t model, * This function should only be called when setting up * the initial lock state upon boot-up of the system. * - * @param mutex NFP CPP Mutex handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key Unique 32-bit value for this mutex + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * Unique 32-bit value for this mutex * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, @@ -99,7 +103,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, return 0; } -/* +/** * Create a mutex handle from an address controlled by a MU Atomic engine * * The CPP target:address must point to a 64-bit aligned location, and @@ -108,13 +112,17 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, * Only target/address pairs that point to entities that support the * MU Atomic Engine are supported. * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key 32-bit unique key (must match the key at this location) + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * 32-bit unique key (must match the key at this location) * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. + * @return + * A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, @@ -178,10 +186,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -/* +/** * Free a mutex handle - does not alter the lock state * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) @@ -203,12 +212,14 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) free(mutex); } -/* +/** * Lock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure. */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) @@ -229,12 +240,14 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return 0; } -/* +/** * Unlock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) @@ -280,16 +293,18 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return err; } -/* +/** * Attempt to lock a mutex handle, using the NFP MU Atomic Engine * * Valid lock states: - * * 0x....0000 - Unlocked * 0x....000f - Locked * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. + * @param mutex + * NFP CPP Mutex handle + * + * @return + * 0 if the lock succeeded, negative value on failure. */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) @@ -352,7 +367,7 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) * If there was another contending for this lock, then * the lock state would be 0x....000f * - * Write our owner ID into the lock + * Write our owner ID into the lock. * While not strictly necessary, this helps with * debug and bookkeeping. */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 6ba40cd085..af55671a88 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -52,7 +52,7 @@ nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 8) | mip_offset_lo */ +/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { @@ -111,11 +111,14 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) } } -/* - * nfp_nffw_info_open() - Acquire the lock on the NFFW table - * @cpp: NFP CPP handle +/** + * Acquire the lock on the NFFW table + * + * @param cpp + * NFP CPP handle * - * Return: nffw info pointer, or NULL on failure + * @return + * NFFW info pointer, or NULL on failure */ struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) @@ -167,11 +170,11 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) return NULL; } -/* - * nfp_nffw_info_close() - Release the lock on the NFFW table - * @state: NFP FW info state +/** + * Release the lock on the NFFW table * - * Return: void + * @param state + * NFFW info pointer */ void nfp_nffw_info_close(struct nfp_nffw_info *state) @@ -180,11 +183,14 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) free(state); } -/* - * nfp_nffw_info_fwid_first() - Return the first firmware ID in the NFFW - * @state: NFP FW info state +/** + * Return the first firmware ID in the NFFW * - * Return: First NFFW firmware info, NULL on failure + * @param state + * NFFW info pointer + * + * @return: + * First NFFW firmware info, NULL on failure */ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) @@ -204,13 +210,18 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; } -/* - * nfp_nffw_info_mip_first() - Retrieve the location of the first FW's MIP - * @state: NFP FW info state - * @cpp_id: Pointer to the CPP ID of the MIP - * @off: Pointer to the CPP Address of the MIP +/** + * Retrieve the location of the first FW's MIP + * + * @param state + * NFFW info pointer + * @param cpp_id + * Pointer to the CPP ID of the MIP + * @param off + * Pointer to the CPP Address of the MIP * - * Return: 0, or -ERRNO + * @return + * 0, or -ERRNO */ int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 46ac8a8d07..e032b6cce7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,7 +8,8 @@ #include "nfp_cpp.h" -/* Init-CSR owner IDs for firmware map to firmware IDs which start at 4. +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. * Lower IDs are reserved for target and loader IDs. */ #define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ @@ -16,7 +17,7 @@ #define NFFW_FWID_ALL 255 -/** +/* * NFFW_INFO_VERSION history: * 0: This was never actually used (before versioning), but it refers to * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later @@ -35,6 +36,7 @@ #define NFFW_MEINFO_CNT_V2 200 #define NFFW_FWINFO_CNT_V2 200 +/* nfp.nffw meinfo */ struct nffw_meinfo { uint32_t ctxmask__fwid__meid; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 76d418d478..039e4729bd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -109,9 +109,11 @@ nfp_nsp_check(struct nfp_nsp *state) return 0; } -/* - * nfp_nsp_open() - Prepare for communication and lock the NSP resource. - * @cpp: NFP CPP Handle +/** + * Prepare for communication and lock the NSP resource. + * + * @param cpp + * NFP CPP Handle */ struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) @@ -145,9 +147,11 @@ nfp_nsp_open(struct nfp_cpp *cpp) return state; } -/* - * nfp_nsp_close() - Clean up and unlock the NSP resource. - * @state: NFP SP state +/** + * Clean up and unlock the NSP resource. + * + * @param state + * NFP SP state */ void nfp_nsp_close(struct nfp_nsp *state) @@ -181,7 +185,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -194,28 +198,27 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, return 0; nanosleep(&wait, 0); - if (count++ > 1000) + if (count++ > 1000) /* 25ms * 1000 = 25s */ return -ETIMEDOUT; } } -/* - * nfp_nsp_command() - Execute a command on the NFP Service Processor - * @state: NFP SP state - * @code: NFP SP Command Code - * @option: NFP SP Command Argument - * @buff_cpp: NFP SP Buffer CPP Address info - * @buff_addr: NFP SP Buffer Host address - * - * Return: 0 for success with no result +/** + * Execute a command on the NFP Service Processor * - * positive value for NSP completion with a result code + * @param state + * NFP SP state + * @param arg + * NFP command argument structure * - * -EAGAIN if the NSP is not yet present - * -ENODEV if the NSP is not a supported model - * -EBUSY if the NSP is stuck - * -EINTR if interrupted while waiting for completion - * -ETIMEDOUT if the NSP took longer than 30 seconds to complete + * @return + * - 0 for success with no result + * - Positive value for NSP completion with a result code + * - -EAGAIN if the NSP is not yet present + * - -ENODEV if the NSP is not a supported model + * - -EBUSY if the NSP is stuck + * - -EINTR if interrupted while waiting for completion + * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int nfp_nsp_command(struct nfp_nsp *state, @@ -383,7 +386,7 @@ nfp_nsp_wait(struct nfp_nsp *state) struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); @@ -392,7 +395,7 @@ nfp_nsp_wait(struct nfp_nsp *state) nanosleep(&wait, 0); - if (count++ > 1000) { + if (count++ > 1000) { /* 25ms * 1000 = 25s */ err = -ETIMEDOUT; break; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index edb56e26ca..0fcb21e99c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -158,72 +158,45 @@ enum nfp_eth_fec { #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) -/** - * struct nfp_eth_table - ETH table information - * @count: number of table entries - * @max_index: max of @index fields of all @ports - * @ports: table of ports - * - * @eth_index: port index according to legacy ethX numbering - * @index: chip-wide first channel index - * @nbi: NBI index - * @base: first channel index (within NBI) - * @lanes: number of channels - * @speed: interface speed (in Mbps) - * @interface: interface (module) plugged in - * @media: media type of the @interface - * @fec: forward error correction mode - * @aneg: auto negotiation mode - * @mac_addr: interface MAC address - * @label_port: port id - * @label_subport: id of interface within port (for split ports) - * @enabled: is enabled? - * @tx_enabled: is TX enabled? - * @rx_enabled: is RX enabled? - * @override_changed: is media reconfig pending? - * - * @port_type: one of %PORT_* defines for ethtool - * @port_lanes: total number of lanes on the port (sum of lanes of all subports) - * @is_split: is interface part of a split port - * @fec_modes_supported: bitmap of FEC modes supported - */ +/* ETH table information */ struct nfp_eth_table { - uint32_t count; - uint32_t max_index; + uint32_t count; /**< Number of table entries */ + uint32_t max_index; /**< Max of @index fields of all @ports */ struct nfp_eth_table_port { + /** Port index according to legacy ethX numbering */ uint32_t eth_index; - uint32_t index; - uint32_t nbi; - uint32_t base; - uint32_t lanes; - uint32_t speed; + uint32_t index; /**< Chip-wide first channel index */ + uint32_t nbi; /**< NBI index */ + uint32_t base; /**< First channel index (within NBI) */ + uint32_t lanes; /**< Number of channels */ + uint32_t speed; /**< Interface speed (in Mbps) */ - uint32_t interface; - enum nfp_eth_media media; + uint32_t interface; /**< Interface (module) plugged in */ + enum nfp_eth_media media; /**< Media type of the @interface */ - enum nfp_eth_fec fec; - enum nfp_eth_aneg aneg; + enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ - struct rte_ether_addr mac_addr; + struct rte_ether_addr mac_addr; /**< Interface MAC address */ - uint8_t label_port; + uint8_t label_port; /**< Port id */ + /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; - int tx_enabled; - int rx_enabled; - - int override_changed; + int enabled; /**< Enable port */ + int tx_enabled; /**< Enable TX */ + int rx_enabled; /**< Enable RX */ - /* Computed fields */ - uint8_t port_type; + int override_changed; /**< Media reconfig pending */ + uint8_t port_type; /**< One of %PORT_* */ + /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; + int is_split; /**< Split port */ - uint32_t fec_modes_supported; - } ports[]; + uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ + } ports[]; /**< Table of ports */ }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); @@ -263,28 +236,17 @@ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); -/** - * struct nfp_nsp_identify - NSP static information - * @version: opaque version string - * @flags: version flags - * @br_primary: branch id of primary bootloader - * @br_secondary: branch id of secondary bootloader - * @br_nsp: branch id of NSP - * @primary: version of primary bootloader - * @secondary: version id of secondary bootloader - * @nsp: version id of NSP - * @sensor_mask: mask of present sensors available on NIC - */ +/* NSP static information */ struct nfp_nsp_identify { - char version[40]; - uint8_t flags; - uint8_t br_primary; - uint8_t br_secondary; - uint8_t br_nsp; - uint16_t primary; - uint16_t secondary; - uint16_t nsp; - uint64_t sensor_mask; + char version[40]; /**< Opaque version string */ + uint8_t flags; /**< Version flags */ + uint8_t br_primary; /**< Branch id of primary bootloader */ + uint8_t br_secondary; /**< Branch id of secondary bootloader */ + uint8_t br_nsp; /**< Branch id of NSP */ + uint16_t primary; /**< Version of primary bootloader */ + uint16_t secondary; /**< Version id of secondary bootloader */ + uint16_t nsp; /**< Version id of NSP */ + uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 51dcf24f5f..e32884e7d3 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -263,7 +263,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) goto err; } - /* The NFP3800 NIC support 8 ports, but only 2 ports are valid, + /* + * The NFP3800 NIC support 8 ports, but only 2 ports are valid, * the rest 6 ports mac are all 0, ensure we don't use these port */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { @@ -273,7 +274,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) cnt++; } - /* Some versions of flash will give us 0 instead of port count. For + /* + * Some versions of flash will give us 0 instead of port count. For * those that give a port count, verify it against the value calculated * above. */ @@ -311,14 +313,16 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) return NULL; } -/* - * nfp_eth_read_ports() - retrieve port information - * @cpp: NFP CPP handle +/** + * Read the port information from the device. + * + * Returned structure should be freed once no longer needed. * - * Read the port information from the device. Returned structure should - * be freed with kfree() once no longer needed. + * @param cpp + * NFP CPP handle * - * Return: populated ETH table or NULL on error. + * @return + * Populated ETH table or NULL on error. */ struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) @@ -386,19 +390,19 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) free(entries); } -/* - * nfp_eth_config_commit_end() - perform recorded configuration changes - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * +/** * Perform the configuration which was requested with __nfp_eth_set_*() - * helpers and recorded in @nsp state. If device was already configured - * as requested or no __nfp_eth_set_*() operations were made no NSP command + * helpers and recorded in @nsp state. If device was already configured + * as requested or no __nfp_eth_set_*() operations were made, no NSP command * will be performed. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_config_commit_end(struct nfp_nsp *nsp) @@ -416,19 +420,21 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) return ret; } -/* - * nfp_eth_set_mod_enable() - set PHY module enable control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @enable: Desired state - * +/** * Enable or disable PHY module (this usually means setting the TX lanes * disable bits). * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param enable + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, @@ -459,18 +465,20 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * nfp_eth_set_configured() - set PHY module configured control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @configed: Desired state - * +/** * Set the ifup/ifdown state on the PHY. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param configured + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_configured(struct nfp_cpp *cpp, @@ -524,7 +532,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, /* * Note: set features were added in ABI 0.14 but the error - * codes were initially not populated correctly. + * codes were initially not populated correctly. */ if (nfp_nsp_get_abi_ver_minor(nsp) < 17) { PMD_DRV_LOG(ERR, "set operations not supported, please update flash"); @@ -554,15 +562,17 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, val, ctrl_bit); \ })) -/* - * __nfp_eth_set_aneg() - set PHY autonegotiation control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired autonegotiation mode - * +/** * Allow/disallow PHY module to advertise/perform autonegotiation. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired autonegotiation mode + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, @@ -572,15 +582,17 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } -/* - * __nfp_eth_set_fec() - set PHY forward error correction control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired fec mode - * +/** * Set the PHY module forward error correction mode. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired fec mode + * + * @return + * 0 or -ERRNO */ static int __nfp_eth_set_fec(struct nfp_nsp *nsp, @@ -590,16 +602,20 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } -/* - * nfp_eth_set_fec() - set PHY forward error correction control mode - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @mode: Desired fec mode +/** + * Set PHY forward error correction control mode + * + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param mode + * Desired fec mode * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_fec(struct nfp_cpp *cpp, @@ -622,17 +638,19 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * __nfp_eth_set_speed() - set interface speed/rate - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @speed: Desired speed (per lane) - * - * Set lane speed. Provided @speed value should be subport speed divided - * by number of lanes this subport is spanning (i.e. 10000 for 40G, 25000 for - * 50G, etc.) +/** + * Set lane speed. + * Provided @speed value should be subport speed divided by number of + * lanes this subport is spanning (i.e. 10000 for 40G, 25000 for 50G, etc.) * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param speed + * Desired speed (per lane) + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, @@ -650,15 +668,17 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } -/* - * __nfp_eth_set_split() - set interface lane split - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @lanes: Desired lanes per port - * +/** * Set number of lanes in the port. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param lanes + * Desired lanes per port + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_split(struct nfp_nsp *nsp, diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 363f7d6198..bdebf5c3aa 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -22,32 +22,23 @@ #define NFP_RESOURCE_ENTRY_NAME_SZ 8 -/* - * struct nfp_resource_entry - Resource table entry - * @owner: NFP CPP Lock, interface owner - * @key: NFP CPP Lock, posix_crc32(name, 8) - * @region: Memory region descriptor - * @name: ASCII, zero padded name - * @reserved - * @cpp_action: CPP Action - * @cpp_token: CPP Token - * @cpp_target: CPP Target ID - * @page_offset: 256-byte page offset into target's CPP address - * @page_size: size, in 256-byte pages - */ +/* Resource table entry */ struct nfp_resource_entry { struct nfp_resource_entry_mutex { - uint32_t owner; - uint32_t key; + uint32_t owner; /**< NFP CPP Lock, interface owner */ + uint32_t key; /**< NFP CPP Lock, posix_crc32(name, 8) */ } mutex; + /* Memory region descriptor */ struct nfp_resource_entry_region { + /** ASCII, zero padded name */ uint8_t name[NFP_RESOURCE_ENTRY_NAME_SZ]; uint8_t reserved[5]; - uint8_t cpp_action; - uint8_t cpp_token; - uint8_t cpp_target; + uint8_t cpp_action; /**< CPP Action */ + uint8_t cpp_token; /**< CPP Token */ + uint8_t cpp_target; /**< CPP Target ID */ + /** 256-byte page offset into target's CPP address */ uint32_t page_offset; - uint32_t page_size; + uint32_t page_size; /**< Size, in 256-byte pages */ } region; }; @@ -147,14 +138,18 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, return err; } -/* - * nfp_resource_acquire() - Acquire a resource handle - * @cpp: NFP CPP handle - * @name: Name of the resource +/** + * Acquire a resource handle + * + * Note: This function locks the acquired resource. * - * NOTE: This function locks the acquired resource + * @param cpp + * NFP CPP handle + * @param name + * Name of the resource * - * Return: NFP Resource handle, or NULL + * @return + * NFP Resource handle, or NULL */ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, @@ -183,7 +178,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, } wait.tv_sec = 0; - wait.tv_nsec = 1000000; + wait.tv_nsec = 1000000; /* 1ms */ for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); @@ -194,7 +189,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, goto err_free; } - if (count++ > 1000) { + if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); err = -EBUSY; goto err_free; @@ -213,11 +208,13 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_resource_release() - Release a NFP Resource handle - * @res: NFP Resource handle +/** + * Release a NFP Resource handle * - * NOTE: This function implicitly unlocks the resource handle + * NOTE: This function implicitly unlocks the resource handle. + * + * @param res + * NFP Resource handle */ void nfp_resource_release(struct nfp_resource *res) @@ -227,11 +224,14 @@ nfp_resource_release(struct nfp_resource *res) free(res); } -/* - * nfp_resource_cpp_id() - Return the cpp_id of a resource handle - * @res: NFP Resource handle +/** + * Return the cpp_id of a resource handle + * + * @param res + * NFP Resource handle * - * Return: NFP CPP ID + * @return + * NFP CPP ID */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res) @@ -239,11 +239,14 @@ nfp_resource_cpp_id(const struct nfp_resource *res) return res->cpp_id; } -/* - * nfp_resource_name() - Return the name of a resource handle - * @res: NFP Resource handle +/** + * Return the name of a resource handle * - * Return: const char pointer to the name of the resource + * @param res + * NFP Resource handle + * + * @return + * Const char pointer to the name of the resource */ const char * nfp_resource_name(const struct nfp_resource *res) @@ -251,11 +254,14 @@ nfp_resource_name(const struct nfp_resource *res) return res->name; } -/* - * nfp_resource_address() - Return the address of a resource handle - * @res: NFP Resource handle +/** + * Return the address of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Address of the resource + * @return + * Address of the resource */ uint64_t nfp_resource_address(const struct nfp_resource *res) @@ -263,11 +269,14 @@ nfp_resource_address(const struct nfp_resource *res) return res->addr; } -/* - * nfp_resource_size() - Return the size in bytes of a resource handle - * @res: NFP Resource handle +/** + * Return the size in bytes of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Size of the resource in bytes + * @return + * Size of the resource in bytes */ uint64_t nfp_resource_size(const struct nfp_resource *res) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 009b7359a4..4236950caf 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -8,43 +8,27 @@ #include "nfp_cpp.h" +/* Netronone Flow Firmware Table */ #define NFP_RESOURCE_NFP_NFFW "nfp.nffw" + +/* NFP Hardware Info Database */ #define NFP_RESOURCE_NFP_HWINFO "nfp.info" + +/* Service Processor */ #define NFP_RESOURCE_NSP "nfp.sp" -/** - * Opaque handle to a NFP Resource - */ +/* Opaque handle to a NFP Resource */ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, const char *name); -/** - * Release a NFP Resource, and free the handle - * @param[in] res NFP Resource handle - */ void nfp_resource_release(struct nfp_resource *res); -/** - * Return the CPP ID of a NFP Resource - * @param[in] res NFP Resource handle - * @return CPP ID of the NFP Resource - */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res); -/** - * Return the name of a NFP Resource - * @param[in] res NFP Resource handle - * @return Name of the NFP Resource - */ const char *nfp_resource_name(const struct nfp_resource *res); -/** - * Return the target address of a NFP Resource - * @param[in] res NFP Resource handle - * @return Address of the NFP Resource - */ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index d15a920752..0e6c0f9fe1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -162,11 +162,14 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_rtsym_count() - Get the number of RTSYM descriptors - * @rtbl: NFP RTsym table +/** + * Get the number of RTSYM descriptors + * + * @param rtbl + * NFP RTSYM table * - * Return: Number of RTSYM descriptors + * @return + * Number of RTSYM descriptors */ int nfp_rtsym_count(struct nfp_rtsym_table *rtbl) @@ -177,12 +180,16 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) return rtbl->num; } -/* - * nfp_rtsym_get() - Get the Nth RTSYM descriptor - * @rtbl: NFP RTsym table - * @idx: Index (0-based) of the RTSYM descriptor +/** + * Get the Nth RTSYM descriptor + * + * @param rtbl + * NFP RTSYM table + * @param idx + * Index (0-based) of the RTSYM descriptor * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_get(struct nfp_rtsym_table *rtbl, @@ -197,12 +204,16 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, return &rtbl->symtab[idx]; } -/* - * nfp_rtsym_lookup() - Return the RTSYM descriptor for a symbol name - * @rtbl: NFP RTsym table - * @name: Symbol name +/** + * Return the RTSYM descriptor for a symbol name + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, @@ -227,7 +238,8 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_NONE: PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; - case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ + case NFP_RTSYM_TYPE_OBJECT: + /* FALLTHROUGH */ case NFP_RTSYM_TYPE_FUNCTION: return sym->size; case NFP_RTSYM_TYPE_ABS: @@ -327,17 +339,22 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } -/* - * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol - * @rtbl: NFP RTsym table - * @name: Symbol name - * @error: Pointer to error code (optional) +/** + * Read a simple unsigned scalar value from symbol * * Lookup a symbol, map, read it and return it's value. Value of the symbol * will be interpreted as a simple little-endian unsigned value. Symbol can * be 4 or 8 bytes in size. * - * Return: value read, on error sets the error and returns ~0ULL. + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param error + * Pointer to error code (optional) + * + * @return + * Value read, on error sets the error and returns ~0ULL. */ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index e7295258b3..ff1facbd17 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -31,12 +31,12 @@ * of "sram" symbols for backward compatibility, which are viewed as global. */ struct nfp_rtsym { - const char *name; - uint64_t addr; - uint64_t size; - int type; - int target; - int domain; + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + int type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ }; struct nfp_rtsym_table; diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 611848e233..540b242a43 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -767,7 +767,7 @@ nfp_encode_basic(uint64_t *addr, /* * Make sure we compare against isldN values by clearing the * LSB. This is what the silicon does. - **/ + */ isld[0] &= ~1; isld[1] &= ~1; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 08/27] net/nfp: using the DPDK memory management API 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (6 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 07/27] net/nfp: standard the comment style Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 09/27] net/nfp: standard the blank character Chaoyong He ` (19 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Revise the logic, using the DPDK memory management API to replace the malloc()/free(). Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_mip.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_mutex.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +++----- drivers/net/nfp/nfpcore/nfp_nsp.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +++----- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 19 ++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 10 ++++------ 11 files changed, 39 insertions(+), 48 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 77dab864f3..37895e8355 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -225,7 +225,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); + rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); rte_free(app_fw_flower); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e3ff3d8087..2e43055fd5 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -47,7 +47,7 @@ nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic, int port) rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->mac_addr); - free(nfp_eth_table); + rte_free(nfp_eth_table); return 0; } @@ -312,7 +312,7 @@ nfp_net_close(struct rte_eth_dev *dev) PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); + rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); rte_free(app_fw_nic); @@ -1047,9 +1047,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) sym_tbl_cleanup: free(sym_tbl); eth_table_cleanup: - free(nfp_eth_table); + rte_free(nfp_eth_table); hwinfo_cleanup: - free(hwinfo); + rte_free(hwinfo); cpp_cleanup: nfp_cpp_free(cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f601907673..1e0608a8e4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -866,7 +866,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, if (ops == NULL || ops->init == NULL) return NULL; - cpp = calloc(1, sizeof(*cpp)); + cpp = rte_zmalloc(NULL, sizeof(*cpp), 0); if (cpp == NULL) return NULL; @@ -876,7 +876,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, if (cpp->op->init) { err = cpp->op->init(cpp, dev); if (err < 0) { - free(cpp); + rte_free(cpp); return NULL; } } @@ -891,7 +891,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, err = nfp_xpb_readl(cpp, xpbaddr, (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { - free(cpp); + rte_free(cpp); return NULL; } } @@ -900,7 +900,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); - free(cpp); + rte_free(cpp); return NULL; } @@ -922,7 +922,7 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->serial_len != 0) free(cpp->serial); - free(cpp); + rte_free(cpp); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index f5579ab60f..7abf9c7700 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -109,7 +109,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - db = malloc(*cpp_size + 1); + db = rte_zmalloc(NULL, *cpp_size + 1, 0); if (db == NULL) return NULL; @@ -134,7 +134,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, return (void *)db; exit_free: - free(db); + rte_free(db); return NULL; } @@ -175,7 +175,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) err = nfp_hwinfo_db_validate(db, hwdb_size); if (err != 0) { - free(db); + rte_free(db); return NULL; } return db; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0892c99e96..3c59582846 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -104,14 +104,14 @@ nfp_mip_open(struct nfp_cpp *cpp) int err; struct nfp_mip *mip; - mip = malloc(sizeof(*mip)); + mip = rte_zmalloc(NULL, sizeof(*mip), 0); if (mip == NULL) return NULL; err = nfp_mip_read_resource(cpp, mip); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to read MIP resource"); - free(mip); + rte_free(mip); return NULL; } @@ -123,7 +123,7 @@ nfp_mip_open(struct nfp_cpp *cpp) void nfp_mip_close(struct nfp_mip *mip) { - free(mip); + rte_free(mip); } const char * diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 404d4fa938..5392924cf0 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -163,7 +163,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, if (tmp != key) return NULL; - mutex = calloc(sizeof(*mutex), 1); + mutex = rte_zmalloc(NULL, sizeof(*mutex), 0); if (mutex == NULL) return NULL; @@ -209,7 +209,7 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) if (mutex->cpp && mutex == mutex->cpp->mutex_cache) mutex->cpp->mutex_cache = mutex->next; - free(mutex); + rte_free(mutex); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index af55671a88..a635239b30 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -128,12 +128,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) struct nfp_nffw_info *state; struct nfp_nffw_info_data *fwinf; - state = malloc(sizeof(*state)); + state = rte_zmalloc(NULL, sizeof(*state), 0); if (state == NULL) return NULL; - memset(state, 0, sizeof(*state)); - state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); if (state->res == NULL) { PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); @@ -166,7 +164,7 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err_release: nfp_resource_release(state->res); err_free: - free(state); + rte_free(state); return NULL; } @@ -180,7 +178,7 @@ void nfp_nffw_info_close(struct nfp_nffw_info *state) { nfp_resource_release(state->res); - free(state); + rte_free(state); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 039e4729bd..dd2d19936d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -128,12 +128,12 @@ nfp_nsp_open(struct nfp_cpp *cpp) return NULL; } - state = malloc(sizeof(*state)); + state = rte_zmalloc(NULL, sizeof(*state), 0); if (state == NULL) { nfp_resource_release(res); return NULL; } - memset(state, 0, sizeof(*state)); + state->cpp = cpp; state->res = res; @@ -157,7 +157,7 @@ void nfp_nsp_close(struct nfp_nsp *state) { nfp_resource_release(state->res); - free(state); + rte_free(state); } uint16_t diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 3081e22dad..54e1e2215d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -33,22 +33,20 @@ __nfp_nsp_identify(struct nfp_nsp *nsp) if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; - ni = malloc(sizeof(*ni)); + ni = rte_zmalloc(NULL, sizeof(*ni), 0); if (ni == NULL) return NULL; - memset(ni, 0, sizeof(*ni)); ret = nfp_nsp_read_identify(nsp, ni, sizeof(*ni)); if (ret < 0) { PMD_DRV_LOG(ERR, "reading bsp version failed %d", ret); goto exit_free; } - nspi = malloc(sizeof(*nspi)); + nspi = rte_zmalloc(NULL, sizeof(*nspi), 0); if (nspi == NULL) goto exit_free; - memset(nspi, 0, sizeof(*nspi)); memcpy(nspi->version, ni->version, sizeof(nspi->version)); nspi->version[sizeof(nspi->version) - 1] = '\0'; nspi->flags = ni->flags; @@ -61,7 +59,7 @@ __nfp_nsp_identify(struct nfp_nsp *nsp) nspi->sensor_mask = rte_le_to_cpu_64(ni->sensor_mask); exit_free: - free(ni); + rte_free(ni); return nspi; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index e32884e7d3..1906fcd385 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -252,11 +252,10 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; const struct rte_ether_addr *mac; - entries = malloc(NSP_ETH_TABLE_SIZE); + entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) return NULL; - memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); @@ -286,11 +285,10 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } table_sz = sizeof(*table) + sizeof(struct nfp_eth_table_port) * cnt; - table = malloc(table_sz); + table = rte_zmalloc(NULL, table_sz, 0); if (table == NULL) goto err; - memset(table, 0, table_sz); table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; @@ -304,12 +302,12 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); - free(entries); + rte_free(entries); return table; err: - free(entries); + rte_free(entries); return NULL; } @@ -348,14 +346,13 @@ nfp_eth_config_start(struct nfp_cpp *cpp, struct nfp_nsp *nsp; union eth_table_entry *entries; - entries = malloc(NSP_ETH_TABLE_SIZE); + entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) return NULL; - memset(entries, 0, NSP_ETH_TABLE_SIZE); nsp = nfp_nsp_open(cpp); if (nsp == NULL) { - free(entries); + rte_free(entries); return nsp; } @@ -375,7 +372,7 @@ nfp_eth_config_start(struct nfp_cpp *cpp, err: nfp_nsp_close(nsp); - free(entries); + rte_free(entries); return NULL; } @@ -387,7 +384,7 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) nfp_nsp_config_set_modified(nsp, 0); nfp_nsp_config_clear_state(nsp); nfp_nsp_close(nsp); - free(entries); + rte_free(entries); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index bdebf5c3aa..8ba3784f8a 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -161,19 +161,17 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; struct nfp_cpp_mutex *dev_mutex; - res = malloc(sizeof(*res)); + res = rte_zmalloc(NULL, sizeof(*res), 0); if (res == NULL) return NULL; - memset(res, 0, sizeof(*res)); - strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - free(res); + rte_free(res); return NULL; } @@ -204,7 +202,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err_free: nfp_cpp_mutex_free(dev_mutex); - free(res); + rte_free(res); return NULL; } @@ -221,7 +219,7 @@ nfp_resource_release(struct nfp_resource *res) { nfp_cpp_mutex_unlock(res->mutex); nfp_cpp_mutex_free(res->mutex); - free(res); + rte_free(res); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 09/27] net/nfp: standard the blank character 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (7 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 08/27] net/nfp: using the DPDK memory management API Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 10/27] net/nfp: unify the guide line of header file Chaoyong He ` (18 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Use space character to align instead of TAB character. There should one blank line to split the block of logic, no more no less. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 18 +-- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 17 ++- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 - drivers/net/nfp/nfpcore/nfp_hwinfo.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.h | 45 ++++--- drivers/net/nfp/nfpcore/nfp_mip.c | 9 +- drivers/net/nfp/nfpcore/nfp_mip.h | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 17 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 3 + drivers/net/nfp/nfpcore/nfp_nsp.h | 105 ++++++++-------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 132 ++++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 18 +-- drivers/net/nfp/nfpcore/nfp_rtsym.c | 16 +-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 1 + 17 files changed, 204 insertions(+), 195 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index 7750a0218e..efaa87c0e5 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -15,8 +15,8 @@ #define NFP_CPP_TARGET_PCIE 9 #define NFP_CPP_TARGET_ARM 10 #define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ #define NFP_CPP_TARGET_CT_XPB 14 #define NFP_CPP_TARGET_LOCAL_SCRATCH 15 #define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 82189e9910..92cae2557a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -80,16 +80,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_acquire)(struct nfp_cpp_area *area); + /* * Release resources for a NFP CPP area * Serialized */ void (*area_release)(struct nfp_cpp_area *area); + /* * Return a void IO pointer to a NFP CPP area * NOTE: This is _not_ serialized */ - void *(*area_iomem)(struct nfp_cpp_area *area); /* @@ -280,7 +281,7 @@ void nfp_cpp_free(struct nfp_cpp *cpp); * @return * true if model is in the NFP6000 family, false otherwise. */ -#define NFP_CPP_MODEL_IS_6000(model) \ +#define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) @@ -290,11 +291,11 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * NFP Interface types - logical interface for this CPP connection 4 bits are * reserved for interface type. */ -#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 -#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 -#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 -#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 -#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 +#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 +#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 +#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 +#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 +#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 /** * Construct a 16-bit NFP Interface ID @@ -316,7 +317,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * @return * Interface ID */ -#define NFP_CPP_INTERFACE(type, unit, channel) \ +#define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) @@ -354,7 +355,6 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) - uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 7e94bfb611..28a6278497 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -37,7 +37,7 @@ #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" -#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) +#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -93,7 +93,7 @@ struct nfp_bar { char *iomem; /**< mapped IO memory */ }; -#define BUSDEV_SZ 13 +#define BUSDEV_SZ 13 struct nfp_pcie_user { struct nfp_bar bar[NFP_BAR_MAX]; @@ -163,7 +163,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); @@ -171,7 +170,6 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); @@ -179,7 +177,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 21; } @@ -278,6 +275,7 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; bar->barcfg = 0; @@ -310,6 +308,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; if (bar->lock == 0) { @@ -317,6 +316,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) return bar; } } + return NULL; } @@ -346,7 +346,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } /* Generic CPP bus access interface. */ - struct nfp6000_area_priv { struct nfp_bar *bar; uint32_t bar_offset; @@ -443,6 +442,7 @@ static void nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + priv->bar->lock = 0; priv->bar = NULL; priv->iomem = NULL; @@ -478,7 +478,6 @@ nfp6000_area_read(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.read; - if (width <= 0) return -EINVAL; @@ -548,7 +547,6 @@ nfp6000_area_write(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.write; - if (width <= 0) return -EINVAL; @@ -718,6 +716,7 @@ nfp6000_set_barsz(struct rte_pci_device *dev, i++; desc->barsz = i; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 1e0608a8e4..fa199e80d3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -433,7 +433,6 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) { if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) { PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; @@ -862,7 +861,6 @@ nfp_cpp_alloc(struct rte_pci_device *dev, const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); - if (ops == NULL || ops->init == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 7abf9c7700..cee37210b0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -54,6 +54,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, return -EINVAL; } } + return 0; } @@ -178,6 +179,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) rte_free(db); return NULL; } + return db; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 424db8035d..37427bb6c8 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -8,33 +8,31 @@ #include <inttypes.h> -#define HWINFO_SIZE_MIN 0x100 +#define HWINFO_SIZE_MIN 0x100 /* * The Hardware Info Table defines the properties of the system. * * HWInfo v1 Table (fixed size) * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value - * table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * HWInfo v2 Table (variable size) * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding - * CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * If the HWInfo table is in the process of being updated, the low bit of * version will be set. @@ -47,17 +45,16 @@ * * All keys are guaranteed to be unique. * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value * ... * * HWInfo v2 Key/Value Table * ------------------------- * * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * * Unsorted. * * Note: Only the HwInfo v2 Table be supported now. @@ -65,7 +62,7 @@ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) #define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) struct nfp_hwinfo { uint8_t start[0]; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 3c59582846..f6f07ac739 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -11,9 +11,9 @@ #include "nfp_mip.h" #include "nfp_nffw.h" -#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -#define NFP_MIP_VERSION rte_cpu_to_le_32(1) -#define NFP_MIP_MAX_OFFSET (256 * 1024) +#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ +#define NFP_MIP_VERSION rte_cpu_to_le_32(1) +#define NFP_MIP_MAX_OFFSET (256 * 1024) struct nfp_mip { uint32_t signature; @@ -49,11 +49,13 @@ nfp_mip_try_read(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } + if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } + if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); @@ -82,6 +84,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); + exit_close_nffw: nfp_nffw_info_close(nffw_info); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 980abc2517..16824a6769 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -18,4 +18,5 @@ void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); + #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 5392924cf0..61c491e07e 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -85,7 +85,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, { int err; uint32_t model = nfp_cpp_model(cpp); - uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -134,7 +134,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint32_t tmp; struct nfp_cpp_mutex *mutex; uint32_t model = nfp_cpp_model(cpp); - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -231,12 +231,15 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) /* If err != -EBUSY, then the lock was damaged */ if (err < 0 && err != -EBUSY) return err; + if (time(NULL) >= warn_at) { PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } + sched_yield(); } + return 0; } @@ -257,8 +260,8 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) uint32_t value; struct nfp_cpp *cpp = mutex->cpp; uint16_t interface = nfp_cpp_interface(cpp); - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -314,9 +317,9 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) uint32_t tmp; uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index a635239b30..b14a9bd852 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -61,10 +61,10 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index dd2d19936d..9bb344aa5f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -290,6 +290,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_cpp_readq(cpp, nsp_cpp, nsp_command, &ret_val); if (err < 0) return err; + ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); @@ -354,6 +355,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, if (err < 0) return err; } + /* Zero out remaining part of the buffer */ if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); @@ -400,6 +402,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 0fcb21e99c..ee58bf33b8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -10,73 +10,72 @@ #include "nfp_nsp.h" #define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) + (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) #define __bf_shf(x) (__builtin_ffsll(x) - 1) -#define FIELD_GET(_mask, _reg) \ +#define FIELD_GET(_mask, _reg) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ })) -#define FIELD_FIT(_mask, _val) \ +#define FIELD_FIT(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ })) -#define FIELD_PREP(_mask, _val) \ +#define FIELD_PREP(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ })) /* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_START RTE_BIT64(0) /* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) -#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER 0x18 -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) +#define NSP_CODE_MAJOR GENMASK(15, 12) +#define NSP_CODE_MINOR GENMASK(11, 0) enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ }; static const struct { @@ -123,13 +122,13 @@ nfp_nsp_has_mac_reinit(struct nfp_nsp *state) } enum nfp_eth_interface { - NFP_INTERFACE_NONE = 0, - NFP_INTERFACE_SFP = 1, - NFP_INTERFACE_SFPP = 10, - NFP_INTERFACE_SFP28 = 28, - NFP_INTERFACE_QSFP = 40, - NFP_INTERFACE_CXP = 100, - NFP_INTERFACE_QSFP28 = 112, + NFP_INTERFACE_NONE = 0, + NFP_INTERFACE_SFP = 1, + NFP_INTERFACE_SFPP = 10, + NFP_INTERFACE_SFP28 = 28, + NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_CXP = 100, + NFP_INTERFACE_QSFP28 = 112, }; enum nfp_eth_media { @@ -153,10 +152,10 @@ enum nfp_eth_fec { NFP_FEC_DISABLED_BIT, }; -#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) -#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) -#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) -#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) +#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) +#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) +#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) +#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) /* ETH table information */ struct nfp_eth_table { diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 54e1e2215d..08f12f862c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -105,5 +105,6 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, default: return -EINVAL; } + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 1906fcd385..837c9c6bbd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,70 +11,68 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define NSP_ETH_NBI_PORT_COUNT 24 -#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) -#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ - sizeof(union eth_table_entry)) - -#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) -#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) -#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) -#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) -#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) -#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) - -#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) - -#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) -#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) -#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) -#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) -#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) -#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) -#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) - -#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) -#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) -#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) -#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) -#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) +#define NSP_ETH_NBI_PORT_COUNT 24 +#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) +#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * sizeof(union eth_table_entry)) + +#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) +#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) +#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) +#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) +#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) +#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) + +#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) + +#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) +#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) +#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) +#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) +#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) +#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) +#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) + +#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) +#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) +#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) +#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) +#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) /* Which connector port. */ -#define PORT_TP 0x00 -#define PORT_AUI 0x01 -#define PORT_MII 0x02 -#define PORT_FIBRE 0x03 -#define PORT_BNC 0x04 -#define PORT_DA 0x05 -#define PORT_NONE 0xef -#define PORT_OTHER 0xff - -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 +#define PORT_TP 0x00 +#define PORT_AUI 0x01 +#define PORT_MII 0x02 +#define PORT_FIBRE 0x03 +#define PORT_BNC 0x04 +#define PORT_DA 0x05 +#define PORT_NONE 0xef +#define PORT_OTHER 0xff + +#define SPEED_10 10 +#define SPEED_100 100 +#define SPEED_1000 1000 +#define SPEED_2500 2500 +#define SPEED_5000 5000 +#define SPEED_10000 10000 +#define SPEED_14000 14000 +#define SPEED_20000 20000 +#define SPEED_25000 25000 +#define SPEED_40000 40000 +#define SPEED_50000 50000 +#define SPEED_56000 56000 +#define SPEED_100000 100000 enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW }; @@ -102,12 +100,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, 0, }, + { RATE_10M, SPEED_10, }, + { RATE_100M, SPEED_100, }, + { RATE_1G, SPEED_1000, }, + { RATE_10G, SPEED_10000, }, + { RATE_25G, SPEED_25000, }, }; static uint32_t @@ -211,10 +209,12 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) if (table->ports[i].label_port != table->ports[j].label_port) continue; + table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; + if (table->ports[i].label_subport == table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", @@ -552,11 +552,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, return 0; } -#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ - (__extension__ ({ \ - typeof(mask) _x = (mask); \ +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ + (__extension__ ({ \ + typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 8ba3784f8a..e7e232eb4e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -13,14 +13,14 @@ #include "nfp_resource.h" #include "nfp_crc.h" -#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL +#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU +#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL /* NFP Resource Table self-identifier */ -#define NFP_RESOURCE_TBL_NAME "nfp.res" -#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ +#define NFP_RESOURCE_TBL_NAME "nfp.res" +#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ -#define NFP_RESOURCE_ENTRY_NAME_SZ 8 +#define NFP_RESOURCE_ENTRY_NAME_SZ 8 /* Resource table entry */ struct nfp_resource_entry { @@ -42,9 +42,9 @@ struct nfp_resource_entry { } region; }; -#define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ - sizeof(struct nfp_resource_entry)) +#define NFP_RESOURCE_TBL_SIZE 4096 +#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ + sizeof(struct nfp_resource_entry)) struct nfp_resource { char name[NFP_RESOURCE_ENTRY_NAME_SZ + 1]; @@ -75,6 +75,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Grabbing device lock not supported"); return -EOPNOTSUPP; } + key = nfp_crc32_posix(name_pad, NFP_RESOURCE_ENTRY_NAME_SZ); for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { @@ -96,6 +97,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 0e6c0f9fe1..37811ceaeb 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -17,18 +17,18 @@ #include "nfp6000/nfp6000.h" /* These need to match the linker */ -#define SYM_TGT_LMEM 0 -#define SYM_TGT_EMU_CACHE 0x17 +#define SYM_TGT_LMEM 0 +#define SYM_TGT_EMU_CACHE 0x17 struct nfp_rtsym_entry { - uint8_t type; - uint8_t target; - uint8_t island; - uint8_t addr_hi; + uint8_t type; + uint8_t target; + uint8_t island; + uint8_t addr_hi; uint32_t addr_lo; uint16_t name; - uint8_t menum; - uint8_t size_hi; + uint8_t menum; + uint8_t size_hi; uint32_t size_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index ff1facbd17..de1966f04b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -57,4 +57,5 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); + #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 10/27] net/nfp: unify the guide line of header file 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (8 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 09/27] net/nfp: standard the blank character Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 11/27] net/nfp: rename some parameter and variable Chaoyong He ` (17 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Unify the guide line of header file, we choose '__FOO_BAR_H__' style. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 2 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 +- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_resource.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- drivers/net/nfp/nfpcore/nfp_target.h | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 92cae2557a..ceb4d56a08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -442,4 +442,4 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); -#endif /* !__NFP_CPP_H__ */ +#endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 37427bb6c8..543562779a 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -81,4 +81,4 @@ struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup); -#endif +#endif /* __NFP_HWINFO_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 16824a6769..371c635b97 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -19,4 +19,4 @@ void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); -#endif +#endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index e032b6cce7..f84be463c4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -75,4 +75,4 @@ struct nfp_nffw_info { struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); -#endif +#endif /* __NFP_NFFW_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index ee58bf33b8..7bf584dcd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NSP_NSP_H -#define NSP_NSP_H 1 +#ifndef __NSP_NSP_H__ +#define __NSP_NSP_H__ #include "nfp_cpp.h" #include "nfp_nsp.h" @@ -260,4 +260,4 @@ enum nfp_nsp_sensor_id { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val); -#endif +#endif /* __NSP_NSP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 4236950caf..18196d273c 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NFP_RESOURCE_H -#define NFP_RESOURCE_H +#ifndef __NFP_RESOURCE_H__ +#define __NFP_RESOURCE_H__ #include "nfp_cpp.h" @@ -33,4 +33,4 @@ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); -#endif /* NFP_RESOURCE_H */ +#endif /* __NFP_RESOURCE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index de1966f04b..fdde1eb75b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -58,4 +58,4 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -#endif +#endif /* __NFP_RTSYM_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 195e599d31..2a2f083914 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -3,7 +3,7 @@ * All rights reserved. */ -#ifndef NFP_TARGET_H -#define NFP_TARGET_H +#ifndef __NFP_TARGET_H__ +#define __NFP_TARGET_H__ -#endif /* NFP_TARGET_H */ +#endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 11/27] net/nfp: rename some parameter and variable 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (9 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 10/27] net/nfp: unify the guide line of header file Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 12/27] net/nfp: refact the hwinfo module Chaoyong He ` (16 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Rename some parameter and variable to make the logic easier to understand. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 10 ++--- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 42 ++++++++--------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 52 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 20 ++++----- drivers/net/nfp/nfpcore/nfp_nffw.h | 4 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 8 ++-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 20 ++++----- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index ceb4d56a08..be7ae1d919 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -247,7 +247,7 @@ void *nfp_cpp_priv(struct nfp_cpp *cpp); void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); -uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); +uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, @@ -381,10 +381,10 @@ uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *buffer, size_t length); + void *address, size_t length); int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *buffer, size_t length); + const void *address, size_t length); void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); @@ -393,10 +393,10 @@ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, void *kernel_vaddr, size_t length); + uint64_t address, void *buf, size_t length); int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, const void *kernel_vaddr, size_t length); + uint64_t address, const void *buf, size_t length); int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 28a6278497..db15411eb2 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -118,9 +118,9 @@ static int nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, uint64_t *bar_base, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -129,7 +129,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (tgt >= 16) + if (target >= 16) return -EINVAL; switch (width) { @@ -149,15 +149,15 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; } - if (act != NFP_CPP_ACTION_RW && act != 0) { + if (action != NFP_CPP_ACTION_RW && action != 0) { /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(action); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -170,8 +170,8 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -221,9 +221,9 @@ nfp_bar_write(struct nfp_pcie_user *nfp, static int nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -232,8 +232,8 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, uint32_t newcfg; uint64_t newbase; - err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + err = nfp_compute_bar(bar, &newcfg, &newbase, target, action, + token, offset, size, width); if (err != 0) return err; @@ -457,15 +457,15 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, - void *kernel_vaddr, + void *address, uint32_t offset, size_t length) { size_t n; int width; bool is_64; - uint32_t *wrptr32 = kernel_vaddr; - uint64_t *wrptr64 = kernel_vaddr; + uint32_t *wrptr32 = address; + uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; const volatile uint32_t *rdptr32; const volatile uint64_t *rdptr64; @@ -526,7 +526,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, - const void *kernel_vaddr, + const void *address, uint32_t offset, size_t length) { @@ -536,8 +536,8 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; - const uint32_t *rdptr32 = kernel_vaddr; - const uint64_t *rdptr64 = kernel_vaddr; + const uint32_t *rdptr32 = address; + const uint64_t *rdptr64 = address; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index fa199e80d3..d8e57b9075 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -90,7 +90,7 @@ nfp_cpp_model(struct nfp_cpp *cpp) if (cpp == NULL) return NFP_CPP_MODEL_INVALID; - err = __nfp_cpp_model_autodetect(cpp, &model); + err = nfp_cpp_model_autodetect(cpp, &model); if (err < 0) return err; @@ -484,7 +484,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -498,13 +498,13 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *kernel_vaddr, + void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_read(area, kernel_vaddr, offset, length); + return area->cpp->op->area_read(area, address, offset, length); } /** @@ -514,7 +514,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -528,13 +528,13 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *kernel_vaddr, + const void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_write(area, kernel_vaddr, offset, length); + return area->cpp->op->area_write(area, address, offset, length); } /* @@ -880,14 +880,14 @@ nfp_cpp_alloc(struct rte_pci_device *dev, } if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpbaddr; - size_t tgt; + uint32_t xpb_addr; + size_t target; - for (tgt = 0; tgt < RTE_DIM(cpp->imb_cat_table); tgt++) { + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + (tgt * 4); - err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, + (uint32_t *)&cpp->imb_cat_table[target]); if (err < 0) { rte_free(cpp); return NULL; @@ -950,9 +950,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer for result * @param length * Number of bytes to read @@ -963,20 +963,20 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - void *kernel_vaddr, + uint64_t offset, + void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } - err = nfp_cpp_area_read(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_read(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -989,9 +989,9 @@ nfp_cpp_read(struct nfp_cpp *cpp, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer to read from * @param length * Number of bytes to write @@ -1002,20 +1002,20 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - const void *kernel_vaddr, + uint64_t offset, + const void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; } - err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_write(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -1026,7 +1026,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, +nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { int err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 371c635b97..7fa09ee575 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,6 +17,6 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 61c491e07e..85c33502ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,7 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint32_t model, int *target, uint64_t address) { @@ -87,7 +87,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return err; @@ -152,7 +152,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return NULL; } - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b14a9bd852..b27a9fbaa7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -31,11 +31,11 @@ nffw_res_flg_init_get(const struct nfp_nffw_info_data *res) return (res->flags[0] >> 0) & 1; } -/* loaded = loaded__mu_da__mip_off_hi<31:31> */ +/* loaded = loaded_mu_da_mip_off_hi<31:31> */ static uint32_t nffw_fwinfo_loaded_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 31) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 31) & 1; } /* mip_cppid = mip_cppid */ @@ -45,18 +45,18 @@ nffw_fwinfo_mip_cppid_get(const struct nffw_fwinfo *fi) return fi->mip_cppid; } -/* loaded = loaded__mu_da__mip_off_hi<8:8> */ +/* loaded = loaded_mu_da_mip_off_hi<8:8> */ static uint32_t nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ +/* mip_offset = (loaded_mu_da_mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { - uint64_t mip_off_hi = fi->loaded__mu_da__mip_off_hi; + uint64_t mip_off_hi = fi->loaded_mu_da_mip_off_hi; return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } @@ -224,7 +224,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) + uint64_t *offset) { struct nffw_fwinfo *fwinfo; @@ -233,7 +233,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, return -EINVAL; *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); - *off = nffw_fwinfo_mip_offset_get(fwinfo); + *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; @@ -245,8 +245,8 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, if (locality_off < 0) return locality_off; - *off &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); - *off |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; + *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); + *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; } return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index f84be463c4..52e25c090a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -38,11 +38,11 @@ /* nfp.nffw meinfo */ struct nffw_meinfo { - uint32_t ctxmask__fwid__meid; + uint32_t ctxmask_fwid_meid; }; struct nffw_fwinfo { - uint32_t loaded__mu_da__mip_off_hi; + uint32_t loaded_mu_da_mip_off_hi; uint32_t mip_cppid; /* 0 means no MIP */ uint32_t mip_offset_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 7bf584dcd0..705574b900 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -231,9 +231,9 @@ struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); -int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); +int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); +int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /* NSP static information */ struct nfp_nsp_identify { @@ -248,7 +248,7 @@ struct nfp_nsp_identify { uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; -struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); +struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp); enum nfp_nsp_sensor_id { NFP_SENSOR_CHIP_TEMPERATURE, diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 08f12f862c..429f639fa2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -24,7 +24,7 @@ struct nsp_identify { }; struct nfp_nsp_identify * -__nfp_nsp_identify(struct nfp_nsp *nsp) +nfp_nsp_identify(struct nfp_nsp *nsp) { int ret; struct nsp_identify *ni; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 837c9c6bbd..eea5cde426 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -241,7 +241,7 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) } static struct nfp_eth_table * -__nfp_eth_read_ports(struct nfp_nsp *nsp) +nfp_eth_read_ports_real(struct nfp_nsp *nsp) { int ret; uint32_t i; @@ -332,7 +332,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) if (nsp == NULL) return NULL; - ret = __nfp_eth_read_ports(nsp); + ret = nfp_eth_read_ports_real(nsp); nfp_nsp_close(nsp); return ret; @@ -480,7 +480,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configed) + int configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -503,10 +503,10 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, /* Check if we are already in requested state */ reg = rte_le_to_cpu_64(entries[idx].state); - if (configed != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { + if (configured != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { reg = rte_le_to_cpu_64(entries[idx].control); reg &= ~NSP_ETH_CTRL_CONFIGURED; - reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configed); + reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); nfp_nsp_config_set_modified(nsp, 1); @@ -572,7 +572,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, +nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -592,7 +592,7 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, * 0 or -ERRNO */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, +nfp_eth_set_fec_real(struct nfp_nsp *nsp, enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -626,7 +626,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, if (nsp == NULL) return -EIO; - err = __nfp_eth_set_fec(nsp, mode); + err = nfp_eth_set_fec_real(nsp, mode); if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; @@ -650,7 +650,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, * 0 or -ERRNO */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, +nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed) { enum nfp_eth_rate rate; @@ -678,7 +678,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, +nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 12/27] net/nfp: refact the hwinfo module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (10 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 11/27] net/nfp: rename some parameter and variable Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 13/27] net/nfp: refact the nffw module Chaoyong He ` (15 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the definition of data structure and macro into the implement file. Also remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 84 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 71 +---------------------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index cee37210b0..25c2262dfc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -17,17 +17,82 @@ * (ie, in this example, ME 39 has been reserved by boardconfig.) */ -#include <stdio.h> -#include <time.h> +#include "nfp_hwinfo.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" -#include "nfp_hwinfo.h" -#include "nfp_crc.h" -static int +#define HWINFO_SIZE_MIN 0x100 + +/* + * The Hardware Info Table defines the properties of the system. + * + * HWInfo v1 Table (fixed size) + * + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * HWInfo v2 Table (variable size) + * + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * If the HWInfo table is in the process of being updated, the low bit of + * version will be set. + * + * HWInfo v1 Key/Value Table + * ------------------------- + * + * The key/value table is a set of offsets to ASCIIZ strings which have + * been strcmp(3) sorted (yes, please use bsearch(3) on the table). + * + * All keys are guaranteed to be unique. + * + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value + * ... + * + * HWInfo v2 Key/Value Table + * ------------------------- + * + * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' + * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. + */ + +#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) + +struct nfp_hwinfo { + uint8_t start[0]; + + uint32_t version; + uint32_t size; + + /* V2 specific fields */ + uint32_t limit; + uint32_t resv; + + char data[]; +}; + +static bool nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) { return hwinfo->version & NFP_HWINFO_VERSION_UPDATING; @@ -120,7 +185,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, goto exit_free; } - header = (void *)db; + header = (struct nfp_hwinfo *)db; if (nfp_hwinfo_is_updating(header)) goto exit_free; @@ -133,7 +198,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, /* NULL-terminate for safety */ db[*cpp_size] = '\0'; - return (void *)db; + return (struct nfp_hwinfo *)db; + exit_free: rte_free(db); return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 543562779a..c812f10076 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -6,76 +6,9 @@ #ifndef __NFP_HWINFO_H__ #define __NFP_HWINFO_H__ -#include <inttypes.h> +#include "nfp_cpp.h" -#define HWINFO_SIZE_MIN 0x100 - -/* - * The Hardware Info Table defines the properties of the system. - * - * HWInfo v1 Table (fixed size) - * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * HWInfo v2 Table (variable size) - * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * If the HWInfo table is in the process of being updated, the low bit of - * version will be set. - * - * HWInfo v1 Key/Value Table - * ------------------------- - * - * The key/value table is a set of offsets to ASCIIZ strings which have - * been strcmp(3) sorted (yes, please use bsearch(3) on the table). - * - * All keys are guaranteed to be unique. - * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value - * ... - * - * HWInfo v2 Key/Value Table - * ------------------------- - * - * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * Unsorted. - * - * Note: Only the HwInfo v2 Table be supported now. - */ - -#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) - -struct nfp_hwinfo { - uint8_t start[0]; - - uint32_t version; - uint32_t size; - - /* v2 specific fields */ - uint32_t limit; - uint32_t resv; - - char data[]; -}; +struct nfp_hwinfo; struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 13/27] net/nfp: refact the nffw module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (11 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 12/27] net/nfp: refact the hwinfo module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 14/27] net/nfp: refact the mip module Chaoyong He ` (14 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the definition of data structure and macro into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.h | 4 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 105 +++++++++++++++++++---------- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +----------------- 3 files changed, 72 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 7fa09ee575..dbd9af31ed 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -6,7 +6,7 @@ #ifndef __NFP_MIP_H__ #define __NFP_MIP_H__ -#include "nfp_nffw.h" +#include "nfp_cpp.h" struct nfp_mip; @@ -16,7 +16,5 @@ void nfp_mip_close(struct nfp_mip *mip); const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); -int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b27a9fbaa7..895c71afdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,12 +3,76 @@ * All rights reserved. */ -#include "../nfp_logs.h" -#include "nfp_cpp.h" #include "nfp_nffw.h" + +#include "../nfp_logs.h" #include "nfp_mip.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" +#include "nfp6000/nfp6000.h" + +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. + * Lower IDs are reserved for target and loader IDs. + */ +#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ +#define NFFW_FWID_BASE 4 + +#define NFFW_FWID_ALL 255 + +/* + * NFFW_INFO_VERSION history: + * 0: This was never actually used (before versioning), but it refers to + * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later + * changed to 200. + * 1: First versioned struct, with + * FWINFO_CNT = 120 + * MEINFO_CNT = 120 + * 2: FWINFO_CNT = 200 + * MEINFO_CNT = 200 + */ +#define NFFW_INFO_VERSION_CURRENT 2 + +/* Enough for all current chip families */ +#define NFFW_MEINFO_CNT_V1 120 +#define NFFW_FWINFO_CNT_V1 120 +#define NFFW_MEINFO_CNT_V2 200 +#define NFFW_FWINFO_CNT_V2 200 + +/* nfp.nffw meinfo */ +struct nffw_meinfo { + uint32_t ctxmask_fwid_meid; +}; + +struct nffw_fwinfo { + uint32_t loaded_mu_da_mip_off_hi; + uint32_t mip_cppid; /**< 0 means no MIP */ + uint32_t mip_offset_lo; +}; + +struct nfp_nffw_info_v1 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; +}; + +struct nfp_nffw_info_v2 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; +}; + +struct nfp_nffw_info_data { + uint32_t flags[2]; + union { + struct nfp_nffw_info_v1 v1; + struct nfp_nffw_info_v2 v2; + } info; +}; + +struct nfp_nffw_info { + struct nfp_cpp *cpp; + struct nfp_resource *res; + + struct nfp_nffw_info_data fwinf; +}; /* * flg_info_version = flags[0]<27:16> @@ -61,32 +125,6 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) - -static int -nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) -{ - int err; - uint32_t mode; - uint32_t addr40; - uint32_t xpbaddr; - uint32_t imbcppat; - - /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; - err = nfp_xpb_readl(cpp, xpbaddr, &imbcppat); - if (err < 0) - return err; - - mode = NFP_IMB_TGTADDRESSMODECFG_MODE_of(imbcppat); - addr40 = !!(imbcppat & NFP_IMB_TGTADDRESSMODECFG_ADDRMODE); - - return nfp_cppat_mu_locality_lsb(mode, addr40); -} - static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { @@ -236,14 +274,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { - int locality_off; - - if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) - return 0; - - locality_off = nfp_mip_mu_locality_lsb(state->cpp); - if (locality_off < 0) - return locality_off; + int locality_off = nfp_cpp_mu_locality_lsb(state->cpp); *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 52e25c090a..fd46009d37 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,71 +8,11 @@ #include "nfp_cpp.h" -/* - * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. - * Lower IDs are reserved for target and loader IDs. - */ -#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ -#define NFFW_FWID_BASE 4 - -#define NFFW_FWID_ALL 255 - -/* - * NFFW_INFO_VERSION history: - * 0: This was never actually used (before versioning), but it refers to - * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later - * changed to 200. - * 1: First versioned struct, with - * FWINFO_CNT = 120 - * MEINFO_CNT = 120 - * 2: FWINFO_CNT = 200 - * MEINFO_CNT = 200 - */ -#define NFFW_INFO_VERSION_CURRENT 2 - -/* Enough for all current chip families */ -#define NFFW_MEINFO_CNT_V1 120 -#define NFFW_FWINFO_CNT_V1 120 -#define NFFW_MEINFO_CNT_V2 200 -#define NFFW_FWINFO_CNT_V2 200 - -/* nfp.nffw meinfo */ -struct nffw_meinfo { - uint32_t ctxmask_fwid_meid; -}; - -struct nffw_fwinfo { - uint32_t loaded_mu_da_mip_off_hi; - uint32_t mip_cppid; /* 0 means no MIP */ - uint32_t mip_offset_lo; -}; - -struct nfp_nffw_info_v1 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; -}; - -struct nfp_nffw_info_v2 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; -}; - -struct nfp_nffw_info_data { - uint32_t flags[2]; - union { - struct nfp_nffw_info_v1 v1; - struct nfp_nffw_info_v2 v2; - } info; -}; - -struct nfp_nffw_info { - struct nfp_cpp *cpp; - struct nfp_resource *res; - - struct nfp_nffw_info_data fwinf; -}; +struct nfp_nffw_info; struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); +int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, + uint64_t *offset); #endif /* __NFP_NFFW_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 14/27] net/nfp: refact the mip module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (12 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 13/27] net/nfp: refact the nffw module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 15/27] net/nfp: refact the rtsym module Chaoyong He ` (13 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f6f07ac739..ec064b08dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -3,12 +3,11 @@ * All rights reserved. */ -#include <stdio.h> +#include "nfp_mip.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_mip.h" #include "nfp_nffw.h" #define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 15/27] net/nfp: refact the rtsym module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (13 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 14/27] net/nfp: refact the mip module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 16/27] net/nfp: refact the resource module Chaoyong He ` (12 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include <stdio.h> +#include "nfp_rtsym.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ 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); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 16/27] net/nfp: refact the resource module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (14 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 15/27] net/nfp: refact the rtsym module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 17/27] net/nfp: refact the target module Chaoyong He ` (11 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_resource.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e7e232eb4e..e4a3a42eea 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -3,15 +3,11 @@ * All rights reserved. */ -#include <stdio.h> -#include <time.h> -#include <endian.h> +#include "nfp_resource.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" #include "nfp6000/nfp6000.h" -#include "nfp_resource.h" -#include "nfp_crc.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL @@ -43,7 +39,7 @@ struct nfp_resource_entry { }; #define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ +#define NFP_RESOURCE_TBL_ENTRIES (NFP_RESOURCE_TBL_SIZE / \ sizeof(struct nfp_resource_entry)) struct nfp_resource { @@ -173,8 +169,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - rte_free(res); - return NULL; + goto err_free; } wait.tv_sec = 0; @@ -186,13 +181,12 @@ nfp_resource_acquire(struct nfp_cpp *cpp, break; if (err != -EBUSY) { PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); - goto err_free; + goto mutex_free; } if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); - err = -EBUSY; - goto err_free; + goto mutex_free; } nanosleep(&wait, NULL); @@ -202,8 +196,9 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return res; -err_free: +mutex_free: nfp_cpp_mutex_free(dev_mutex); +err_free: rte_free(res); return NULL; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 17/27] net/nfp: refact the target module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (15 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 16/27] net/nfp: refact the resource module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 18/27] net/nfp: add a new header file Chaoyong He ` (10 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the function declaration into the header file, and sync some logic from kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 -------------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 1 + drivers/net/nfp/nfpcore/nfp_cppcore.c | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 - drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 1 + drivers/net/nfp/nfpcore/nfp_target.c | 7 ++++--- drivers/net/nfp/nfpcore/nfp_target.h | 22 ++++++++++++++++++++++ 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index efaa87c0e5..4c9ac017cc 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -6,21 +6,6 @@ #ifndef __NFP_NFP6000_H__ #define __NFP_NFP6000_H__ -/* CPP Target IDs */ -#define NFP_CPP_TARGET_INVALID 0 -#define NFP_CPP_TARGET_NBI 1 -#define NFP_CPP_TARGET_QDR 2 -#define NFP_CPP_TARGET_ILA 6 -#define NFP_CPP_TARGET_MU 7 -#define NFP_CPP_TARGET_PCIE 9 -#define NFP_CPP_TARGET_ARM 10 -#define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ -#define NFP_CPP_TARGET_CT_XPB 14 -#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 -#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH - #define NFP_ISL_EMEM0 24 #define NFP_MU_ADDR_ACCESS_TYPE_MASK 3ULL @@ -52,9 +37,4 @@ nfp_cppat_mu_locality_lsb(int mode, int addr40) } } -int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); -int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table); - #endif /* NFP_NFP6000_H */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index db15411eb2..310cc691cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -34,6 +34,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index d8e57b9075..f33985bec6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -16,6 +16,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 85c33502ca..87a9351ff9 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -9,7 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) #define MUTEX_UNLOCK(interface) (0 | 0x0000) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index eea5cde426..dbabffea9c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,7 +9,6 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp6000/nfp6000.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e4a3a42eea..ee987c4438 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,7 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 2d4100dda2..022753f98a 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -14,6 +14,7 @@ #include "nfp_logs.h" #include "nfp_mip.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" enum nfp_rtsym_type { diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 540b242a43..ecb45f7928 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -3,6 +3,8 @@ * All rights reserved. */ +#include "nfp_target.h" + #include "nfp_cpp.h" #include "nfp6000/nfp6000.h" @@ -315,8 +317,7 @@ nfp6000_mu(uint32_t cpp_id, } else if (island == 1 || (island >= 4 && island <= 7) || (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { + (island >= 32 && island <= 51)) { pp = nfp6000_mu_ctm(cpp_id); } else { pp = -EINVAL; @@ -510,7 +511,7 @@ nfp_target_pushpull(uint32_t cpp_id, return nfp6000_cap_xpb(cpp_id); case NFP_CPP_TARGET_CLS: return nfp6000_cls(cpp_id); - case 0: + case NFP_CPP_TARGET_INVALID: return target_rw(cpp_id, P32, 4, 4); default: return -EINVAL; diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 2a2f083914..47527b4040 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,4 +6,26 @@ #ifndef __NFP_TARGET_H__ #define __NFP_TARGET_H__ +#include <stdint.h> + +/* CPP Target IDs */ +#define NFP_CPP_TARGET_INVALID 0 +#define NFP_CPP_TARGET_NBI 1 +#define NFP_CPP_TARGET_QDR 2 +#define NFP_CPP_TARGET_ILA 6 +#define NFP_CPP_TARGET_MU 7 +#define NFP_CPP_TARGET_PCIE 9 +#define NFP_CPP_TARGET_ARM 10 +#define NFP_CPP_TARGET_CRYPTO 12 +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_CT_XPB 14 +#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 +#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH + +int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); +int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, + uint32_t *cpp_target_id, uint64_t *cpp_target_address, + const uint32_t *imb_table); + #endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 18/27] net/nfp: add a new header file 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (16 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 17/27] net/nfp: refact the target module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 19/27] net/nfp: refact the nsp module Chaoyong He ` (9 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Split out the macro which are not easily find a DPDK substitute into a new header file. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_nsp.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp.h | 23 -------------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 + drivers/net/nfp/nfpcore/nfp_platform.h | 42 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 9bb344aa5f..8e65064b10 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -13,6 +13,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #include "nfp_resource.h" int diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 705574b900..14986a9130 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -9,29 +9,6 @@ #include "nfp_cpp.h" #include "nfp_nsp.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - /* Offsets relative to the CSR base */ #define NSP_STATUS 0x00 #define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index dbabffea9c..355d907f4d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,6 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_platform.h b/drivers/net/nfp/nfpcore/nfp_platform.h new file mode 100644 index 0000000000..fcac6b05ff --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_platform.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_PLATFORM_H__ +#define __NFP_PLATFORM_H__ + +#include <stdint.h> + +#define DMA_BIT_MASK(n) ((1ULL << (n)) - 1) + +#define BITS_PER_LONG (__SIZEOF_LONG__ * 8) +#define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8) + +#define GENMASK(h, l) \ + ((~0UL << (l)) & (~0UL >> (BITS_PER_LONG - (h) - 1))) + +#define GENMASK_ULL(h, l) \ + ((~0ULL << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - (h) - 1))) + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define FIELD_GET(_mask, _reg) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + })) + +#define FIELD_FIT(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ + })) + +#define FIELD_PREP(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + })) + +#endif /* __NFP_PLATFORM_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 19/27] net/nfp: refact the nsp module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (17 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 18/27] net/nfp: add a new header file Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 20/27] net/nfp: refact the mutex module Chaoyong He ` (8 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Move the definition of data structure into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 390 +++++++++++++++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 140 ++++----- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 - drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 79 ++--- 5 files changed, 398 insertions(+), 217 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 2e43055fd5..9243191de3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -661,7 +661,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev) static int nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) { - struct nfp_cpp *cpp = nsp->cpp; + struct nfp_cpp *cpp = nfp_nsp_cpp(nsp); void *fw_buf; char fw_name[125]; char serial[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 8e65064b10..75d13cb84f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -3,20 +3,127 @@ * All rights reserved. */ -#define NFP_SUBSYS "nfp_nsp" - -#include <stdio.h> -#include <time.h> +#include "nfp_nsp.h" #include <rte_common.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_nsp.h" #include "nfp_platform.h" #include "nfp_resource.h" -int +/* Offsets relative to the CSR base */ +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_DMA_BUF RTE_BIT64(1) +#define NSP_COMMAND_START RTE_BIT64(0) + +/* CPP address to retrieve the data from */ +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) + +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 + +#define NSP_CODE_MAJOR GENMASK_ULL(15, 12) +#define NSP_CODE_MINOR GENMASK_ULL(11, 0) + +#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8) +#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16) + +enum nfp_nsp_cmd { + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */ + SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */ + SPCODE_HWINFO_SET = 18, /* Set HWinfo entry */ + SPCODE_FW_LOADED = 19, /* Is application firmware loaded */ + SPCODE_VERSIONS = 21, /* Report FW versions */ + SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */ + SPCODE_READ_MEDIA = 23, /* Get the supported/advertised media for a port */ +}; + +static const struct { + uint32_t code; + const char *msg; +} nsp_errors[] = { + { 6010, "could not map to phy for port" }, + { 6011, "not an allowed rate/lanes for port" }, + { 6012, "not an allowed rate/lanes for port" }, + { 6013, "high/low error, change other port first" }, + { 6014, "config not found in flash" }, +}; + +struct nfp_nsp { + struct nfp_cpp *cpp; + struct nfp_resource *res; + struct { + uint16_t major; + uint16_t minor; + } ver; + + /** Eth table config state */ + bool modified; + uint32_t idx; + void *entries; +}; + +/* NFP command argument structure */ +struct nfp_nsp_command_arg { + uint16_t code; /**< NFP SP Command Code */ + bool dma; /**< @buf points to a host buffer, not NSP buffer */ + bool error_quiet; /**< Don't print command error/warning */ + uint32_t timeout_sec; /**< Timeout value to wait for completion in seconds */ + uint32_t option; /**< NSP Command Argument */ + uint64_t buf; /**< NSP Buffer Address */ + /** Callback for interpreting option if error occurred */ + void (*error_cb)(struct nfp_nsp *state, uint32_t ret_val); +}; + +/* NFP command with buffer argument structure */ +struct nfp_nsp_command_buf_arg { + struct nfp_nsp_command_arg arg; /**< NFP command argument structure */ + const void *in_buf; /**< Buffer with data for input */ + void *out_buf; /**< Buffer for output data */ + uint32_t in_size; /**< Size of @in_buf */ + uint32_t out_size; /**< Size of @out_buf */ +}; + +struct nfp_cpp * +nfp_nsp_cpp(struct nfp_nsp *state) +{ + return state->cpp; +} + +bool nfp_nsp_config_modified(struct nfp_nsp *state) { return state->modified; @@ -24,7 +131,7 @@ nfp_nsp_config_modified(struct nfp_nsp *state) void nfp_nsp_config_set_modified(struct nfp_nsp *state, - int modified) + bool modified) { state->modified = modified; } @@ -66,7 +173,7 @@ nfp_nsp_print_extended_error(uint32_t ret_val) return; for (i = 0; i < RTE_DIM(nsp_errors); i++) - if (ret_val == (uint32_t)nsp_errors[i].code) + if (ret_val == nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -222,11 +329,8 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, - uint16_t code, - uint32_t option, - uint32_t buff_cpp, - uint64_t buff_addr) +nfp_nsp_command_real(struct nfp_nsp *state, + const struct nfp_nsp_command_arg *arg) { int err; uint64_t reg; @@ -250,22 +354,14 @@ nfp_nsp_command(struct nfp_nsp *state, return err; } - if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { - PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); - return -EINVAL; - } - - err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, arg->buf); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_OPTION, arg->option) | + FIELD_PREP(NSP_COMMAND_CODE, arg->code) | + FIELD_PREP(NSP_COMMAND_DMA_BUF, arg->dma) | FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; @@ -275,7 +371,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", - err, code); + err, arg->code); return err; } @@ -284,7 +380,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", - err, code); + err, arg->code); return err; } @@ -296,84 +392,85 @@ nfp_nsp_command(struct nfp_nsp *state, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { - PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); - nfp_nsp_print_extended_error(ret_val); + if (!arg->error_quiet) + PMD_DRV_LOG(WARNING, "Result (error) code set: %d (%d) command: %d", + -err, (int)ret_val, arg->code); + + if (arg->error_cb != 0) + arg->error_cb(state, ret_val); + else + nfp_nsp_print_extended_error(ret_val); + return -err; } return ret_val; } -#define SZ_1M 0x00100000 +static int +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code) +{ + const struct nfp_nsp_command_arg arg = { + .code = code, + }; + + return nfp_nsp_command_real(state, &arg); +} static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, - uint16_t code, uint32_t option, - const void *in_buf, - unsigned int in_size, - void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf_def(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) { int err; int ret; uint64_t reg; - size_t max_size; uint32_t cpp_id; uint64_t cpp_buf; struct nfp_cpp *cpp = nsp->cpp; - if (nsp->ver.minor < 13) { - PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); - return -EOPNOTSUPP; - } - - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, - ®); - if (err < 0) - return err; - - max_size = RTE_MAX(in_size, out_size); - if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); - return -EINVAL; - } - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, ®); if (err < 0) return err; - cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; - cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); + cpp_id = FIELD_GET(NSP_DFLT_BUFFER_CPP, reg) << 8; + cpp_buf = FIELD_GET(NSP_DFLT_BUFFER_ADDRESS, reg); - if (in_buf != NULL && in_size > 0) { - err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); + if (arg->in_buf != NULL && arg->in_size > 0) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf, + arg->in_buf, arg->in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf != NULL && out_size > 0 && out_size > in_size) { - memset(out_buf, 0, out_size - in_size); - err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + if (arg->out_buf != NULL && arg->out_size > arg->in_size) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf + arg->in_size, + arg->out_buf, arg->out_size - arg->in_size); if (err < 0) return err; } - ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); + if (!FIELD_FIT(NSP_BUFFER_CPP, cpp_id >> 8) || + !FIELD_FIT(NSP_BUFFER_ADDRESS, cpp_buf)) { + PMD_DRV_LOG(ERR, "Buffer out of reach %#08x %#016lx", + cpp_id, cpp_buf); + return -EINVAL; + } + + arg->arg.buf = FIELD_PREP(NSP_BUFFER_CPP, cpp_id >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf); + ret = nfp_nsp_command_real(nsp, &arg->arg); if (ret < 0) { PMD_DRV_LOG(ERR, "NSP command failed"); return ret; } - if (out_buf != NULL && out_size > 0) { - err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); + if (arg->out_buf != NULL && arg->out_size > 0) { + err = nfp_cpp_read(cpp, cpp_id, cpp_buf, + arg->out_buf, arg->out_size); if (err < 0) return err; } @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, return ret; } +#define SZ_1M 0x00100000 +#define SZ_4K 0x00001000 + +static int +nfp_nsp_command_buf(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) +{ + int err; + uint64_t reg; + uint32_t size; + uint32_t max_size; + struct nfp_cpp *cpp = nsp->cpp; + + if (nsp->ver.minor < 13) { + PMD_DRV_LOG(ERR, "NSP: Code %#04x with buffer not supported ABI %hu.%hu)", + arg->arg.code, nsp->ver.major, nsp->ver.minor); + return -EOPNOTSUPP; + } + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); + if (err < 0) + return err; + + max_size = RTE_MAX(arg->in_size, arg->out_size); + size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; + if (size < max_size) { + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%u < %u)", + arg->arg.code, size, max_size); + return -EINVAL; + } + + return nfp_nsp_command_buf_def(nsp, arg); +} + int nfp_nsp_wait(struct nfp_nsp *state) { @@ -392,7 +526,7 @@ nfp_nsp_wait(struct nfp_nsp *state) wait.tv_nsec = 25000000; /* 25ms */ for (;;) { - err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); + err = nfp_nsp_command(state, SPCODE_NOOP); if (err != -EAGAIN) break; @@ -413,13 +547,57 @@ nfp_nsp_wait(struct nfp_nsp *state) int nfp_nsp_device_soft_reset(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_SOFT_RESET, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_SOFT_RESET); } int nfp_nsp_mac_reinit(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_MAC_INIT, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_MAC_INIT); +} + +static void +nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, + uint32_t ret_val) +{ + uint32_t minor; + uint32_t major; + static const char * const major_msg[] = { + /* 0 */ "Firmware from driver loaded", + /* 1 */ "Firmware from flash loaded", + /* 2 */ "Firmware loading failure", + }; + static const char * const minor_msg[] = { + /* 0 */ "", + /* 1 */ "no named partition on flash", + /* 2 */ "error reading from flash", + /* 3 */ "can not deflate", + /* 4 */ "not a trusted file", + /* 5 */ "can not parse FW file", + /* 6 */ "MIP not found in FW file", + /* 7 */ "null firmware name in MIP", + /* 8 */ "FW version none", + /* 9 */ "FW build number none", + /* 10 */ "no FW selection policy HWInfo key found", + /* 11 */ "static FW selection policy", + /* 12 */ "FW version has precedence", + /* 13 */ "different FW application load requested", + /* 14 */ "development build", + }; + + major = FIELD_GET(NFP_FW_LOAD_RET_MAJOR, ret_val); + minor = FIELD_GET(NFP_FW_LOAD_RET_MINOR, ret_val); + + if (!nfp_nsp_has_stored_fw_load(state)) + return; + + if (major >= RTE_DIM(major_msg)) + PMD_DRV_LOG(INFO, "FW loading status: %x", ret_val); + else if (minor >= RTE_DIM(minor_msg)) + PMD_DRV_LOG(INFO, "%s, reason code: %d", major_msg[major], minor); + else + PMD_DRV_LOG(INFO, "%s%c %s", major_msg[major], + minor != 0 ? ',' : '.', minor_msg[minor]); } int @@ -427,8 +605,24 @@ nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + int ret; + struct nfp_nsp_command_buf_arg load_fw = { + { + .code = SPCODE_FW_LOAD, + .option = size, + .error_cb = nfp_nsp_load_fw_extended_msg, + }, + .in_buf = buf, + .in_size = size, + }; + + ret = nfp_nsp_command_buf(state, &load_fw); + if (ret < 0) + return ret; + + nfp_nsp_load_fw_extended_msg(state, ret); + + return 0; } int @@ -436,8 +630,16 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg eth_rescan = { + { + .code = SPCODE_ETH_RESCAN, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, ð_rescan); } int @@ -445,8 +647,16 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + struct nfp_nsp_command_buf_arg eth_ctrl = { + { + .code = SPCODE_ETH_CONTROL, + .option = size, + }, + .in_buf = buf, + .in_size = size, + }; + + return nfp_nsp_command_buf(state, ð_ctrl); } int @@ -454,8 +664,16 @@ nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg identify = { + { + .code = SPCODE_NSP_IDENTIFY, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &identify); } int @@ -464,6 +682,14 @@ nfp_nsp_read_sensors(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + struct nfp_nsp_command_buf_arg sensors = { + { + .code = SPCODE_NSP_SENSORS, + .option = sensor_mask, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &sensors); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 14986a9130..fe52dffeb7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -7,78 +7,8 @@ #define __NSP_NSP_H__ #include "nfp_cpp.h" -#include "nfp_nsp.h" - -/* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) - -/* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) - -#define NSP_DFLT_BUFFER 0x18 - -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) - -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 - -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) - -enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ -}; - -static const struct { - int code; - const char *msg; -} nsp_errors[] = { - { 6010, "could not map to phy for port" }, - { 6011, "not an allowed rate/lanes for port" }, - { 6012, "not an allowed rate/lanes for port" }, - { 6013, "high/low error, change other port first" }, - { 6014, "config not found in flash" }, -}; -struct nfp_nsp { - struct nfp_cpp *cpp; - struct nfp_resource *res; - struct { - uint16_t major; - uint16_t minor; - } ver; - - /* Eth table config state */ - int modified; - unsigned int idx; - void *entries; -}; +struct nfp_nsp; struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); void nfp_nsp_close(struct nfp_nsp *state); @@ -92,18 +22,61 @@ int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, void *buf, size_t size); -static inline int +static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } +static inline bool +nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 23; +} + +static inline bool +nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 24; +} + +static inline bool +nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_fw_loaded(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_versions(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 27; +} + +static inline bool +nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 28; +} + +static inline bool +nfp_nsp_has_read_media(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 33; +} + enum nfp_eth_interface { NFP_INTERFACE_NONE = 0, NFP_INTERFACE_SFP = 1, NFP_INTERFACE_SFPP = 10, NFP_INTERFACE_SFP28 = 28, NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_RJ45 = 45, NFP_INTERFACE_CXP = 100, NFP_INTERFACE_QSFP28 = 112, }; @@ -151,6 +124,7 @@ struct nfp_eth_table { enum nfp_eth_media media; /**< Media type of the @interface */ enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ struct rte_ether_addr mac_addr; /**< Interface MAC address */ @@ -159,17 +133,18 @@ struct nfp_eth_table { /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; /**< Enable port */ - int tx_enabled; /**< Enable TX */ - int rx_enabled; /**< Enable RX */ + bool enabled; /**< Enable port */ + bool tx_enabled; /**< Enable TX */ + bool rx_enabled; /**< Enable RX */ + bool supp_aneg; /**< Support auto negotiation */ - int override_changed; /**< Media reconfig pending */ + bool override_changed; /**< Media reconfig pending */ uint8_t port_type; /**< One of %PORT_* */ /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; /**< Split port */ + bool is_split; /**< Split port */ uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ } ports[]; /**< Table of ports */ @@ -177,8 +152,8 @@ struct nfp_eth_table { struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); @@ -187,12 +162,13 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); -void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); +void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); -int nfp_nsp_config_modified(struct nfp_nsp *state); +struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); +bool nfp_nsp_config_modified(struct nfp_nsp *state); uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int +static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported != 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 429f639fa2..86956f4330 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -3,12 +3,8 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp_nffw.h" struct nsp_identify { uint8_t version[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 355d907f4d..996fd4b44a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -3,10 +3,6 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_common.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" #include "nfp_platform.h" @@ -21,6 +17,7 @@ #define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) #define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) #define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) +#define NSP_ETH_PORT_SUPP_ANEG RTE_BIT64(63) #define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) @@ -34,6 +31,7 @@ #define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) #define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) #define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) +#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28) #define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) #define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) @@ -54,26 +52,12 @@ #define PORT_NONE 0xef #define PORT_OTHER 0xff -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 - enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW + NSP_ETH_NUM_RAW, }; enum nfp_eth_rate { @@ -100,12 +84,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, RTE_ETH_SPEED_NUM_NONE, }, + { RATE_10M, RTE_ETH_SPEED_NUM_10M, }, + { RATE_100M, RTE_ETH_SPEED_NUM_100M, }, + { RATE_1G, RTE_ETH_SPEED_NUM_1G, }, + { RATE_10G, RTE_ETH_SPEED_NUM_10G, }, + { RATE_25G, RTE_ETH_SPEED_NUM_25G, }, }; static uint32_t @@ -192,7 +176,14 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; - dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->fec = FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->act_fec = dst->fec; + + if (nfp_nsp_get_abi_ver_minor(nsp) < 33) + return; + + dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state); + dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port); } static void @@ -221,7 +212,7 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) table->ports[i].label_port, table->ports[i].label_subport); - table->ports[i].is_split = 1; + table->ports[i].is_split = true; } } } @@ -232,6 +223,9 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) if (entry->interface == NFP_INTERFACE_NONE) { entry->port_type = PORT_NONE; return; + } else if (entry->interface == NFP_INTERFACE_RJ45) { + entry->port_type = PORT_TP; + return; } if (entry->media == NFP_MEDIA_FIBRE) @@ -250,7 +244,6 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) uint32_t table_sz; struct nfp_eth_table *table; union eth_table_entry *entries; - const struct rte_ether_addr *mac; entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) @@ -262,16 +255,9 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) goto err; } - /* - * The NFP3800 NIC support 8 ports, but only 2 ports are valid, - * the rest 6 ports mac are all 0, ensure we don't use these port - */ - for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) + for (i = 0; i < NSP_ETH_MAX_COUNT; i++) + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) cnt++; - } /* * Some versions of flash will give us 0 instead of port count. For @@ -291,11 +277,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) - nfp_eth_port_translate(nsp, &entries[i], i, - &table->ports[j++]); + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) + nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); } nfp_eth_calc_port_geometry(table); @@ -436,7 +419,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, - int enable) + bool enable) { uint64_t reg; struct nfp_nsp *nsp; @@ -444,7 +427,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) - return -1; + return -EIO; entries = nfp_nsp_config_entries(nsp); @@ -456,7 +439,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_ENABLED, enable); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -480,7 +463,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configured) + bool configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -509,7 +492,7 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -547,7 +530,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, entries[idx].control |= rte_cpu_to_le_64(ctrl_bit); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 20/27] net/nfp: refact the mutex module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (18 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 19/27] net/nfp: refact the nsp module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He ` (7 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add a header file to holds the API declarations of this module. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 16 -- drivers/net/nfp/nfpcore/nfp_mutex.c | 205 ++++++++++++++----------- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 +++ drivers/net/nfp/nfpcore/nfp_resource.c | 1 + 4 files changed, 138 insertions(+), 109 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index be7ae1d919..42c4df5fdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -8,8 +8,6 @@ #include <ethdev_pci.h> -struct nfp_cpp_mutex; - /* NFP CPP handle */ struct nfp_cpp { uint32_t model; @@ -426,20 +424,6 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); - uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); #endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 87a9351ff9..9363543422 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -3,21 +3,13 @@ * All rights reserved. */ -#include <malloc.h> -#include <time.h> +#include "nfp_mutex.h" + #include <sched.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" -#define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) -#define MUTEX_UNLOCK(interface) (0 | 0x0000) - -#define MUTEX_IS_LOCKED(value) (((value) & 0xffff) == 0x000f) -#define MUTEX_IS_UNLOCKED(value) (((value) & 0xffff) == 0x0000) -#define MUTEX_INTERFACE(value) (((value) >> 16) & 0xffff) - /* * If you need more than 65536 recursive locks, please * rethink your code. @@ -34,21 +26,51 @@ struct nfp_cpp_mutex { struct nfp_cpp_mutex *prev, *next; }; +static inline uint32_t +nfp_mutex_locked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x000f; +} + +static inline uint32_t +nfp_mutex_unlocked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x0000; +} + +static inline uint16_t +nfp_mutex_owner(uint32_t val) +{ + return (val >> 16) & 0xffff; +} + +static inline bool +nfp_mutex_is_locked(uint32_t val) +{ + return (val & 0xffff) == 0x000f; +} + +static inline bool +nfp_mutex_is_unlocked(uint32_t val) +{ + return (val & 0xffff) == 0; +} + static int -nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint16_t interface, int *target, uint64_t address) { + /* Not permitted on invalid interfaces */ + if (NFP_CPP_INTERFACE_TYPE_of(interface) == NFP_CPP_INTERFACE_TYPE_INVALID) + return -EINVAL; + /* Address must be 64-bit aligned */ if ((address & 7) != 0) return -EINVAL; - if (NFP_CPP_MODEL_IS_6000(model)) { - if (*target != NFP_CPP_TARGET_MU) - return -EINVAL; - } else { + if (*target != NFP_CPP_TARGET_MU) return -EINVAL; - } return 0; } @@ -84,10 +106,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t key) { int err; - uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint16_t interface = nfp_cpp_interface(cpp); - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return err; @@ -95,8 +117,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, if (err < 0) return err; - err = nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface)); if (err < 0) return err; @@ -133,26 +154,10 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int err; uint32_t tmp; struct nfp_cpp_mutex *mutex; - uint32_t model = nfp_cpp_model(cpp); uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint16_t interface = nfp_cpp_interface(cpp); - /* Look for cached mutex */ - for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { - if (mutex->target == target && mutex->address == address) - break; - } - - if (mutex) { - if (mutex->key == key) { - mutex->usage++; - return mutex; - } - - /* If the key doesn't match... */ - return NULL; - } - - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return NULL; @@ -172,16 +177,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, mutex->address = address; mutex->key = key; mutex->depth = 0; - mutex->usage = 1; - - /* Add mutex to the cache */ - if (cpp->mutex_cache) { - cpp->mutex_cache->prev = mutex; - mutex->next = cpp->mutex_cache; - cpp->mutex_cache = mutex; - } else { - cpp->mutex_cache = mutex; - } return mutex; } @@ -195,20 +190,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) { - mutex->usage--; - if (mutex->usage > 0) - return; - - /* Remove mutex from the cache */ - if (mutex->next) - mutex->next->prev = mutex->prev; - if (mutex->prev) - mutex->prev->next = mutex->next; - - /* If mutex->cpp == NULL, something broke */ - if (mutex->cpp && mutex == mutex->cpp->mutex_cache) - mutex->cpp->mutex_cache = mutex->next; - rte_free(mutex); } @@ -268,32 +249,28 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return 0; } - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - goto exit; - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; - if (value != MUTEX_LOCKED(interface)) { - err = -EACCES; - goto exit; - } + err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); + if (err < 0) + return err; + + if (value != nfp_mutex_locked(interface)) + return -EACCES; - err = nfp_cpp_writel(cpp, muw, mutex->address, MUTEX_UNLOCK(interface)); + err = nfp_cpp_writel(cpp, muw, mutex->address, + nfp_mutex_unlocked(interface)); if (err < 0) - goto exit; + return err; mutex->depth = 0; -exit: - return err; + return 0; } /** @@ -332,19 +309,17 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) /* Verify that the lock marker is not damaged */ err = nfp_cpp_readl(cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; /* * Compare against the unlocked state, and if true, * write the interface id into the top 16 bits, and * mark as locked. */ - value = MUTEX_LOCKED(nfp_cpp_interface(cpp)); + value = nfp_mutex_locked(nfp_cpp_interface(cpp)); /* * We use test_set_imm here, as it implies a read @@ -361,10 +336,10 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_readl(cpp, mus, mutex->address, &tmp); if (err < 0) - goto exit; + return err; /* Was it unlocked? */ - if (MUTEX_IS_UNLOCKED(tmp)) { + if (nfp_mutex_is_unlocked(tmp)) { /* * The read value can only be 0x....0000 in the unlocked state. * If there was another contending for this lock, then @@ -376,20 +351,64 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_writel(cpp, muw, mutex->address, value); if (err < 0) - goto exit; + return err; mutex->depth = 1; - goto exit; + return 0; } /* Already locked by us? Success! */ if (tmp == value) { mutex->depth = 1; - goto exit; + return 0; } - err = MUTEX_IS_LOCKED(tmp) ? -EBUSY : -EINVAL; + return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL; +} + +/** + * Release lock if held by local system. + * Extreme care is advised, call only when no local lock users can exist. + * + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * + * @return + * - (0) if the lock was OK + * - (1) if locked by us + * - (-errno) on invalid mutex + */ +int +nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, + int target, + uint64_t address) +{ + int err; + uint32_t tmp; + uint16_t interface = nfp_cpp_interface(cpp); + const uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + const uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + + err = nfp_cpp_mutex_validate(interface, &target, address); + if (err != 0) + return err; + + /* Check lock */ + err = nfp_cpp_readl(cpp, mur, address, &tmp); + if (err < 0) + return err; + + if (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface) + return 0; + + /* Bust the lock */ + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface)); + if (err < 0) + return err; -exit: - return err; + return 1; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.h b/drivers/net/nfp/nfpcore/nfp_mutex.h new file mode 100644 index 0000000000..a79490b4d6 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_mutex.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_MUTEX_H__ +#define __NFP_MUTEX_H__ + +#include "nfp_cpp.h" + +struct nfp_cpp_mutex; + +int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target, uint64_t address); + +#endif /* __NFP_MUTEX_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index ee987c4438..c4cc7f42f6 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,6 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" +#include "nfp_mutex.h" #include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 21/27] net/nfp: rename data field to sync with kernel driver 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (19 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 20/27] net/nfp: refact the mutex module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 22/27] net/nfp: add the dev module Chaoyong He ` (6 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Rename the data fields to sync with the logic in kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +++--- drivers/net/nfp/nfp_common.h | 4 ++-- drivers/net/nfp/nfp_ethdev.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 37895e8355..24a6878149 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -224,7 +224,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -360,8 +360,8 @@ nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type) start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ; - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; /* Set the current MTU to the maximum supported */ hw->mtu = hw->max_mtu; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 1ce51d44d4..86c4e10040 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -123,9 +123,9 @@ struct nfp_pf_dev { struct nfp_cpp *cpp; struct nfp_cpp_area *ctrl_area; - struct nfp_cpp_area *hwqueues_area; + struct nfp_cpp_area *qc_area; - uint8_t *hw_queues; + uint8_t *qc_bar; struct nfp_hwinfo *hwinfo; struct nfp_rtsym_table *sym_tbl; diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 9243191de3..3f5375deb9 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -311,7 +311,7 @@ nfp_net_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -593,8 +593,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -995,16 +995,16 @@ nfp_pf_init(struct rte_pci_device *pci_dev) } cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); - pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, cpp_id, + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, addr, NFP_QCP_QUEUE_AREA_SZ, - &pf_dev->hwqueues_area); - if (pf_dev->hw_queues == NULL) { + &pf_dev->qc_area); + if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; goto pf_cleanup; } - PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues); + PMD_INIT_LOG(DEBUG, "qc_bar address: 0x%p", pf_dev->qc_bar); /* * PF initialization has been done at this point. Call app specific @@ -1041,7 +1041,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) return 0; hwqueues_cleanup: - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); pf_cleanup: rte_free(pf_dev); sym_tbl_cleanup: -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 22/27] net/nfp: add the dev module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (20 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 23/27] net/nfp: add header file for PCIe module Chaoyong He ` (5 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add the nfp_dev module to simplify the logic. The data structure we import can gather and replace several macro which scatter everywhere. Which also make the logic of choose value for different devices unnecessary and so eliminate such logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 1 + drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 ++---------- drivers/net/nfp/nfp_common.h | 48 +++-------- drivers/net/nfp/nfp_ethdev.c | 63 ++++++--------- drivers/net/nfp/nfp_ethdev_vf.c | 17 +--- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 --- drivers/net/nfp/nfpcore/nfp_dev.c | 81 +++++++++++++++++++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 ++++++++++ 13 files changed, 185 insertions(+), 158 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 24a6878149..43263531c5 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -503,7 +503,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_rx_ring", i, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -558,7 +559,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_tx_ring", i, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 5f94d20f1b..dc6a2c7a9a 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -67,7 +67,8 @@ nfp_pf_repr_rx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -140,7 +141,8 @@ nfp_pf_repr_tx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 93c708959c..580a478cd6 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -21,6 +21,7 @@ sources = files( 'nfpcore/nfp_rtsym.c', 'nfpcore/nfp_nsp_cmds.c', 'nfpcore/nfp_crc.c', + 'nfpcore/nfp_dev.c', 'nfpcore/nfp_mutex.c', 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', diff --git a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c index ee39686329..79e1e1041c 100644 --- a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c +++ b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c @@ -262,7 +262,6 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -276,9 +275,7 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfd3_tx_desc); diff --git a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c index f66802211f..48a74d109a 100644 --- a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c +++ b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c @@ -357,7 +357,6 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -371,9 +370,7 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfdk_tx_desc); diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c index 5092e5869d..d6ff4f17ae 100644 --- a/drivers/net/nfp/nfp_common.c +++ b/drivers/net/nfp/nfp_common.c @@ -1146,30 +1146,16 @@ nfp_net_xstats_reset(struct rte_eth_dev *dev) return nfp_net_stats_reset(dev); } -int +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc) { - *max_rx_desc = NFP_NET_MAX_RX_DESC; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_rx_desc = NFP3800_NET_MIN_RX_DESC; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_rx_desc = NFP_NET_MIN_RX_DESC; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_rx_desc = hw->pf_dev->dev_info->max_qc_size; + *min_rx_desc = hw->pf_dev->dev_info->min_qc_size; } -int +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc) @@ -1181,28 +1167,13 @@ nfp_net_tx_desc_limits(struct nfp_net_hw *hw, else tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT; - *max_tx_desc = NFP_NET_MAX_TX_DESC / tx_dpp; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_tx_desc = NFP3800_NET_MIN_TX_DESC / tx_dpp; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_tx_desc = NFP_NET_MIN_TX_DESC / tx_dpp; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_tx_desc = hw->pf_dev->dev_info->max_qc_size / tx_dpp; + *min_tx_desc = hw->pf_dev->dev_info->min_qc_size / tx_dpp; } int nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; uint16_t min_tx_desc; @@ -1211,13 +1182,8 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; - - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues; dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 86c4e10040..5fc9f0ccda 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -7,16 +7,9 @@ #define _NFP_COMMON_H_ #include "nfp_ctrl.h" +#include "nfpcore/nfp_dev.h" #define NFP_NET_PMD_VERSION "0.1" -#define PCI_VENDOR_ID_NETRONOME 0x19ee -#define PCI_VENDOR_ID_CORIGINE 0x1da8 - -#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 -#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 -#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 -#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 -#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ /* Forward declaration */ struct nfp_net_adapter; @@ -28,7 +21,6 @@ struct nfp_net_adapter; #define NFP_NET_CRTL_BAR 0 #define NFP_NET_TX_BAR 2 #define NFP_NET_RX_BAR 2 -#define NFP_QCP_QUEUE_AREA_SZ 0x80000 /* Macros for accessing the Queue Controller Peripheral 'CSRs' */ #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800) @@ -39,17 +31,6 @@ struct nfp_net_adapter; #define NFP_QCP_QUEUE_STS_HI 0x000c #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask (0x3ffff) -#define NFP_PCIE_QCP_NFP3800_OFFSET 0x400000 -#define NFP_PCIE_QCP_NFP6000_OFFSET 0x80000 -#define NFP_PCIE_QUEUE_NFP3800_MASK 0x1ff -#define NFP_PCIE_QUEUE_NFP6000_MASK 0xff -#define NFP_PCIE_QCP_PF_OFFSET 0x0 -#define NFP_PCIE_QCP_VF_OFFSET 0x0 - -/* The offset of the queue controller queues in the PCIe Target */ -#define NFP_PCIE_QUEUE(_offset, _q, _mask) \ - ((_offset) + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & (_mask)))) - /* Interrupt definitions */ #define NFP_NET_IRQ_LSC_IDX 0 @@ -111,6 +92,9 @@ struct nfp_pf_dev { /* Backpointer to associated pci device */ struct rte_pci_device *pci_dev; + /** NFP ASIC params */ + const struct nfp_dev_info *dev_info; + enum nfp_app_fw_id app_fw_id; /* Pointer to the app running on the PF */ @@ -352,23 +336,11 @@ nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr) } static inline uint32_t -nfp_pci_queue(struct rte_pci_device *pdev, uint16_t queue) +nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, + uint16_t queue) { - switch (pdev->id.device_id) { - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - case PCI_DEVICE_ID_NFP3800_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - case PCI_DEVICE_ID_NFP6000_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - default: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - } + return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ * + (queue & dev_info->qc_idx_mask); } /* Prototypes for common NFP functions */ @@ -434,10 +406,10 @@ void nfp_net_close_rx_queue(struct rte_eth_dev *dev); void nfp_net_stop_tx_queue(struct rte_eth_dev *dev); void nfp_net_close_tx_queue(struct rte_eth_dev *dev); int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port); -int nfp_net_rx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc); -int nfp_net_tx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc); int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 3f5375deb9..c37d8a1449 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -496,9 +496,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) struct nfp_app_fw_nic *app_fw_nic; struct nfp_net_hw *hw; struct rte_ether_addr *tmp_ether_addr; - uint64_t rx_bar_off = 0; - uint64_t tx_bar_off = 0; - uint32_t start_q; + uint64_t rx_base; + uint64_t tx_base; int port = 0; int err; @@ -576,25 +575,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev) /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - return -ENODEV; - } + tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + rx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); - PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); + PMD_INIT_LOG(DEBUG, "tx_base: 0x%" PRIx64 "", tx_base); + PMD_INIT_LOG(DEBUG, "rx_base: 0x%" PRIx64 "", rx_base); - hw->tx_bar = pf_dev->qc_bar + tx_bar_off; - hw->rx_bar = pf_dev->qc_bar + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ; + hw->rx_bar = pf_dev->qc_bar + rx_base * NFP_QCP_QUEUE_ADDR_SZ; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -902,10 +890,17 @@ nfp_pf_init(struct rte_pci_device *pci_dev) char name[RTE_ETH_NAME_MAX_LEN]; struct nfp_rtsym_table *sym_tbl; struct nfp_eth_table *nfp_eth_table; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This @@ -976,27 +971,14 @@ nfp_pf_init(struct rte_pci_device *pci_dev) pf_dev->sym_tbl = sym_tbl; pf_dev->pci_dev = pci_dev; pf_dev->nfp_eth_table = nfp_eth_table; + pf_dev->dev_info = dev_info; /* configure access to tx/rx vNIC BARs */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP3800_OFFSET, - 0, NFP_PCIE_QUEUE_NFP3800_MASK); - break; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP6000_OFFSET, - 0, NFP_PCIE_QUEUE_NFP6000_MASK); - break; - default: - PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); - ret = -ENODEV; - goto pf_cleanup; - } - + addr = nfp_qcp_queue_offset(pf_dev->dev_info, 0); cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, - addr, NFP_QCP_QUEUE_AREA_SZ, + addr, pf_dev->dev_info->qc_area_sz, &pf_dev->qc_area); if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); @@ -1111,10 +1093,17 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) struct nfp_cpp *cpp; enum nfp_app_fw_id app_fw_id; struct nfp_rtsym_table *sym_tbl; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c index eaf815d06d..cf60e56c28 100644 --- a/drivers/net/nfp/nfp_ethdev_vf.c +++ b/drivers/net/nfp/nfp_ethdev_vf.c @@ -305,19 +305,10 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev) } /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_VF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - err = -ENODEV; - goto dev_err_ctrl_map; - } + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + tx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); + rx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c index f0c371ea2b..1b8bb3471d 100644 --- a/drivers/net/nfp/nfp_rxtx.c +++ b/drivers/net/nfp/nfp_rxtx.c @@ -677,7 +677,6 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; const struct rte_memzone *tz; @@ -689,9 +688,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); /* Validating number of descriptors */ rx_desc_sz = nb_desc * sizeof(struct nfp_net_rx_desc); diff --git a/drivers/net/nfp/nfp_rxtx.h b/drivers/net/nfp/nfp_rxtx.h index 48e548b02d..6d1c8e4605 100644 --- a/drivers/net/nfp/nfp_rxtx.h +++ b/drivers/net/nfp/nfp_rxtx.h @@ -74,18 +74,6 @@ struct nfp_meta_parsed { } vlan[NFP_META_MAX_VLANS]; }; -/* - * The maximum number of descriptors is limited by design as - * DPDK uses uint16_t variables for these values - */ -#define NFP_NET_MAX_TX_DESC (32 * 1024) -#define NFP_NET_MIN_TX_DESC 256 -#define NFP3800_NET_MIN_TX_DESC 512 - -#define NFP_NET_MAX_RX_DESC (32 * 1024) -#define NFP_NET_MIN_RX_DESC 256 -#define NFP3800_NET_MIN_RX_DESC 512 - /* Descriptor alignment */ #define NFP_ALIGN_RING_DESC 128 diff --git a/drivers/net/nfp/nfpcore/nfp_dev.c b/drivers/net/nfp/nfpcore/nfp_dev.c new file mode 100644 index 0000000000..7799fa699a --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_dev.h" + +#include <rte_bitops.h> + +#include "nfp_platform.h" + +/* + * Note: The value of 'max_qc_size' is different from kernel driver, + * because DPDK use 'uint16_t' as the data type. + */ +const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { + [NFP_DEV_NFP3800] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0x400000, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP3800", + .pcie_cfg_expbar_offset = 0x0a00, + .qc_area_sz = 0x100000, + .pf_num_per_unit = 4, + }, + [NFP_DEV_NFP3800_VF] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, + [NFP_DEV_NFP6000] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0x80000, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP4000/NFP6000", + .pcie_cfg_expbar_offset = 0x0400, + .qc_area_sz = 0x80000, + .pf_num_per_unit = 1, + }, + [NFP_DEV_NFP6000_VF] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, +}; + +const struct nfp_dev_info * +nfp_dev_info_get(uint16_t device_id) +{ + enum nfp_dev_id id; + + switch (device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + id = NFP_DEV_NFP3800; + break; + case PCI_DEVICE_ID_NFP3800_VF_NIC: + id = NFP_DEV_NFP3800_VF; + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + id = NFP_DEV_NFP6000; + break; + case PCI_DEVICE_ID_NFP6000_VF_NIC: + id = NFP_DEV_NFP6000_VF; + break; + default: + id = NFP_DEV_CNT; + break; + } + + if (id >= NFP_DEV_CNT) + return NULL; + + return &nfp_dev_info[id]; +} diff --git a/drivers/net/nfp/nfpcore/nfp_dev.h b/drivers/net/nfp/nfpcore/nfp_dev.h new file mode 100644 index 0000000000..b0fffff619 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_DEV_H__ +#define __NFP_DEV_H__ + +#include <stdint.h> + +#define PCI_VENDOR_ID_NETRONOME 0x19ee +#define PCI_VENDOR_ID_CORIGINE 0x1da8 + +#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 +#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 +#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 +#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 +#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ + +enum nfp_dev_id { + NFP_DEV_NFP3800, + NFP_DEV_NFP3800_VF, + NFP_DEV_NFP6000, + NFP_DEV_NFP6000_VF, + NFP_DEV_CNT, +}; + +struct nfp_dev_info { + /* Required fields */ + uint32_t qc_idx_mask; + uint32_t qc_addr_offset; + uint32_t min_qc_size; + uint32_t max_qc_size; + + /* PF-only fields */ + const char *chip_names; + uint32_t pcie_cfg_expbar_offset; + uint32_t qc_area_sz; + uint8_t pf_num_per_unit; +}; + +const struct nfp_dev_info *nfp_dev_info_get(uint16_t device_id); + +#endif /* __NFP_DEV_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 23/27] net/nfp: add header file for PCIe module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (21 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 22/27] net/nfp: add the dev module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 24/27] net/nfp: refact the cppcore module Chaoyong He ` (4 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Add a new header file for the PCIe module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/meson.build | 2 +- .../nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} | 2 ++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 13 +++++++++++++ drivers/net/nfp/nfpcore/nfp_cpp.h | 6 ------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) rename drivers/net/nfp/nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} (99%) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 580a478cd6..d422269c4b 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -12,7 +12,6 @@ sources = files( 'flower/nfp_flower_representor.c', 'nfd3/nfp_nfd3_dp.c', 'nfdk/nfp_nfdk_dp.c', - 'nfpcore/nfp_cpp_pcie_ops.c', 'nfpcore/nfp_nsp.c', 'nfpcore/nfp_cppcore.c', 'nfpcore/nfp_resource.c', @@ -26,6 +25,7 @@ sources = files( 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', 'nfpcore/nfp_target.c', + 'nfpcore/nfp6000_pcie.c', 'nfp_common.c', 'nfp_rxtx.c', 'nfp_cpp_bridge.c', diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c similarity index 99% rename from drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c rename to drivers/net/nfp/nfpcore/nfp6000_pcie.c index 310cc691cd..abee584f85 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -14,6 +14,8 @@ * The generic CPP bus abstraction builds upon this BAR interface. */ +#include "nfp6000_pcie.h" + #include <assert.h> #include <stdio.h> #include <stdlib.h> diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h new file mode 100644 index 0000000000..e126457d45 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Netronome Systems, Inc. + * All rights reserved. + */ + +#ifndef __NFP6000_PCIE_H__ +#define __NFP6000_PCIE_H__ + +#include "nfp_cpp.h" + +const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); + +#endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 42c4df5fdd..0df97552cb 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,12 +226,6 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) return id & 0xff; } -/* - * This should be the only external function the transport - * module supplies - */ -const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); - void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f33985bec6..74b35f4a62 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -14,12 +14,12 @@ #include <rte_byteorder.h> #include <ethdev_pci.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" +#include "nfp6000_pcie.h" #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 24/27] net/nfp: refact the cppcore module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (22 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 23/27] net/nfp: add header file for PCIe module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 25/27] net/nfp: refact the PCIe module Chaoyong He ` (3 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Modify the comment and standard the coding style. Move the definition of data structure into the implement file to make the API small. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 14 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 40 ++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 186 ++++++++++++++++--------- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c index 88cd1aa572..a9998f3c08 100644 --- a/drivers/net/nfp/nfp_cpp_bridge.c +++ b/drivers/net/nfp/nfp_cpp_bridge.c @@ -344,7 +344,7 @@ nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp) return -EIO; } - tmp = cpp->interface; + tmp = nfp_cpp_interface(cpp); PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index c37d8a1449..5d129d0ad3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -654,15 +654,23 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) char fw_name[125]; char serial[40]; size_t fsize; + uint16_t interface; + uint32_t cpp_serial_len; + const uint8_t *cpp_serial; + + cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial); + if (cpp_serial_len != NFP_SERIAL_LEN) + return -ERANGE; + + interface = nfp_cpp_interface(cpp); /* Looking for firmware file in order of priority */ /* First try to find a firmware image specific for this device */ snprintf(serial, sizeof(serial), "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3], - cpp->serial[4], cpp->serial[5], cpp->interface >> 8, - cpp->interface & 0xff); + cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3], + cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff); snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH, serial); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index abee584f85..45645e04f8 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -739,7 +739,7 @@ nfp6000_init(struct nfp_cpp *cpp, strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; @@ -778,7 +778,7 @@ nfp6000_free(struct nfp_cpp *cpp) struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); nfp_disable_bars(desc); - if (cpp->driver_lock_needed) + if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); free(desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0df97552cb..34ed50ceca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -9,38 +9,12 @@ #include <ethdev_pci.h> /* NFP CPP handle */ -struct nfp_cpp { - uint32_t model; - uint32_t interface; - uint8_t *serial; - int serial_len; - void *priv; - - /* Mutex cache */ - struct nfp_cpp_mutex *mutex_cache; - const struct nfp_cpp_operations *op; - - /* - * NFP-6xxx originating island IMB CPP Address Translation. CPP Target - * ID is index into array. Values are obtained at runtime from local - * island XPB CSRs. - */ - uint32_t imb_cat_table[16]; - - /* MU access type bit offset */ - uint32_t mu_locality_lsb; - - int driver_lock_needed; -}; +struct nfp_cpp; /* NFP CPP device area handle */ -struct nfp_cpp_area { - struct nfp_cpp *cpp; - char *name; - unsigned long long offset; - unsigned long size; - /* Here follows the 'priv' part of nfp_cpp_area. */ -}; +struct nfp_cpp_area; + +#define NFP_SERIAL_LEN 6 /* * NFP CPP operations structure @@ -230,7 +204,7 @@ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); @@ -349,7 +323,9 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); + +bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp); struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 74b35f4a62..209d0b5160 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -3,30 +3,56 @@ * All rights reserved. */ -#include <assert.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> - -#include <rte_byteorder.h> -#include <ethdev_pci.h> +#include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_platform.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" -#include "nfp_nffw.h" #include "nfp6000_pcie.h" +#define NFP_PL_DEVICE_PART_NFP6000 0x6200 #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff #define NFP_PL_DEVICE_PART_MASK 0xffff0000 #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/* NFP CPP handle */ +struct nfp_cpp { + void *priv; /**< Private data of the low-level implementation */ + + uint32_t model; /**< Chip model */ + uint16_t interface; /**< Chip interface id */ + uint8_t serial[NFP_SERIAL_LEN]; /**< Chip serial number */ + + /** Low-level implementation ops */ + const struct nfp_cpp_operations *op; + + /* + * NFP-6xxx originating island IMB CPP Address Translation. CPP Target + * ID is index into array. Values are obtained at runtime from local + * island XPB CSRs. + */ + uint32_t imb_cat_table[16]; + + /**< MU access type bit offset */ + uint32_t mu_locality_lsb; + + bool driver_lock_needed; +}; + +/* NFP CPP device area handle */ +struct nfp_cpp_area { + struct nfp_cpp *cpp; + char *name; + uint64_t offset; + uint32_t size; + /* Here follows the 'priv' part of nfp_cpp_area. */ + /* Here follows the ASCII name, pointed by @name */ +}; + /** * Set the private data of the nfp_cpp instance * @@ -125,12 +151,13 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, * @return * Length of NFP serial number */ -int +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) { - *serial = cpp->serial; - return cpp->serial_len; + *serial = &cpp->serial[0]; + + return sizeof(cpp->serial); } /** @@ -143,22 +170,12 @@ nfp_cpp_serial(struct nfp_cpp *cpp, * @param serial_len * Length of the serial byte array */ -int +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len) { - if (cpp->serial_len) - free(cpp->serial); - - cpp->serial = malloc(serial_len); - if (cpp->serial == NULL) - return -1; - memcpy(cpp->serial, serial, serial_len); - cpp->serial_len = serial_len; - - return 0; } /** @@ -179,6 +196,21 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Retrieve the driver need lock flag + * + * @param cpp + * NFP CPP handle + * + * @return + * The driver need lock flag + */ +bool +nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp) +{ + return cpp->driver_lock_needed; +} + /** * Get the privately allocated portion of a NFP CPP area handle * @@ -283,39 +315,40 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t size) { int err; + size_t name_len; + uint32_t target_id; + uint64_t target_addr; struct nfp_cpp_area *area; - uint64_t tmp64 = (uint64_t)address; if (cpp == NULL) return NULL; /* Remap from cpp_island to cpp_target */ - err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table); + err = nfp_target_cpp(dest, address, &target_id, &target_addr, + cpp->imb_cat_table); if (err < 0) return NULL; - address = tmp64; - if (name == NULL) - name = ""; + name = "(reserved)"; - area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + name_len = strlen(name) + 1; + area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + name_len); if (area == NULL) return NULL; area->cpp = cpp; area->name = ((char *)area) + sizeof(*area) + cpp->op->area_priv_size; - memcpy(area->name, name, strlen(name) + 1); + memcpy(area->name, name, name_len); - err = cpp->op->area_init(area, dest, address, size); + err = cpp->op->area_init(area, target_id, target_addr, size); if (err < 0) { PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } - area->offset = address; + area->offset = target_addr; area->size = size; return area; @@ -555,26 +588,28 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, * Ensure that non-local XPB accesses go out through the * global XPBM bus. */ - island = ((*xpb_addr) >> 24) & 0x3f; + island = (*xpb_addr >> 24) & 0x3f; if (island == 0) return xpb; - if (island == 1) { - /* - * Accesses to the ARM Island overlay uses Island 0 - * Global Bit - */ - (*xpb_addr) &= ~0x7f000000; - if (*xpb_addr < 0x60000) - *xpb_addr |= (1 << 30); - else - /* And only non-ARM interfaces use island id = 1 */ - if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) - *xpb_addr |= (1 << 24); + if (island != 1) { + *xpb_addr |= (1 << 30); + return xpb; + } + + /* + * Accesses to the ARM Island overlay uses Island 0 + * Global Bit + */ + *xpb_addr &= ~0x7f000000; + if (*xpb_addr < 0x60000) { + *xpb_addr |= (1 << 30); } else { - (*xpb_addr) |= (1 << 30); + /* And only non-ARM interfaces use island id = 1 */ + if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != + NFP_CPP_INTERFACE_TYPE_ARM) + *xpb_addr |= (1 << 24); } return xpb; @@ -602,9 +637,12 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -629,7 +667,10 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, value = rte_cpu_to_le_32(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - return (sz == sizeof(value)) ? 0 : -1; + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; + + return 0; } /** @@ -654,9 +695,12 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, uint64_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_64(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -681,8 +725,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, value = rte_cpu_to_le_64(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -710,9 +756,12 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t tmp; sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -740,8 +789,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, value = rte_cpu_to_le_32(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -770,8 +821,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); *value = rte_le_to_cpu_64(tmp); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -799,8 +852,10 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, value = rte_cpu_to_le_64(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -918,9 +973,6 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len != 0) - free(cpp->serial); - rte_free(cpp); } @@ -974,7 +1026,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); - return -1; + return -EACCES; } err = nfp_cpp_area_read(area, 0, address, length); @@ -1013,7 +1065,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); - return -1; + return -EACCES; } err = nfp_cpp_area_write(area, 0, address, length); @@ -1039,8 +1091,12 @@ nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if (*model & NFP_PL_DEVICE_ID_MASK) - *model -= 0x10; + /* Disambiguate the NFP4000/NFP5000/NFP6000 chips */ + if (FIELD_GET(NFP_PL_DEVICE_PART_MASK, reg) == + NFP_PL_DEVICE_PART_NFP6000) { + if (*model & NFP_PL_DEVICE_ID_MASK) + *model -= 0x10; + } return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 25/27] net/nfp: refact the PCIe module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (23 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 24/27] net/nfp: refact the cppcore module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 26/27] net/nfp: refact the cppcore and " Chaoyong He ` (2 subsequent siblings) 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 211 +++++++++++++++++-------- drivers/net/nfp/nfpcore/nfp_cpp.h | 9 ++ 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 45645e04f8..4f453f19a9 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -16,23 +16,8 @@ #include "nfp6000_pcie.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> #include <unistd.h> -#include <stdint.h> -#include <stdbool.h> #include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <dirent.h> -#include <libgen.h> - -#include <sys/mman.h> -#include <sys/file.h> -#include <sys/stat.h> - -#include <ethdev_pci.h> #include "nfp_cpp.h" #include "nfp_logs.h" @@ -43,8 +28,11 @@ #define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) +#define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(_x) (((_x) >> 16) & 0x1f) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) +#define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS_OF(_x) (((_x) >> 0) & 0xffff) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT(_x) (((_x) & 0x3) << 27) +#define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(_x) (((_x) >> 27) & 0x3) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT 0 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT 1 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE 3 @@ -55,7 +43,9 @@ #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET 2 #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL 3 #define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(_x) (((_x) & 0xf) << 23) +#define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(_x) (((_x) >> 23) & 0xf) #define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(_x) (((_x) & 0x3) << 21) +#define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(_x) (((_x) >> 21) & 0x3) /* * Minimal size of the PCIe cfg memory we depend on being mapped, @@ -132,7 +122,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (target >= 16) + if (target >= NFP_CPP_NUM_TARGETS) return -EINVAL; switch (width) { @@ -182,10 +172,6 @@ nfp_compute_bar(const struct nfp_bar *bar, offset &= mask; bitsize = 40 - 21; } - - if (bar->bitsize < bitsize) - return -EINVAL; - newcfg |= offset >> bitsize; if (bar_base != NULL) @@ -434,7 +420,7 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Must have been too big. Sub-allocate. */ if (priv->bar->iomem == NULL) - return (-ENOMEM); + return -ENOMEM; priv->iomem = priv->bar->iomem + priv->bar_offset; @@ -464,9 +450,9 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32 = address; uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; @@ -484,47 +470,54 @@ nfp6000_area_read(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } - is_64 = width == TARGET_WIDTH_64; - - /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { - is_64 = false; - } + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; + ret = n; + break; + default: + return -EINVAL; + } + + return ret; } static int @@ -533,9 +526,9 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; @@ -553,47 +546,53 @@ nfp6000_area_write(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; - is_64 = width == TARGET_WIDTH_64; - - /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) - is_64 = false; + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; -} + ret = n; + break; + default: + return -EINVAL; + } -#define PCI_DEVICES "/sys/bus/pci/devices" + return ret; +} static int nfp_acquire_process_lock(struct nfp_pcie_user *desc) @@ -706,6 +705,74 @@ nfp6000_set_serial(struct rte_pci_device *dev, return 0; } +static int +nfp6000_get_dsn(struct rte_pci_device *pci_dev, + uint64_t *dsn) +{ + off_t pos; + size_t len; + uint64_t tmp = 0; + + pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN); + if (pos <= 0) { + PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found"); + return -ENODEV; + } + + pos += 4; + len = sizeof(tmp); + + if (rte_pci_read_config(pci_dev, &tmp, len, pos) < 0) { + PMD_DRV_LOG(ERR, "nfp get device serial number failed"); + return -ENOENT; + } + + *dsn = tmp; + + return 0; +} + +static int +nfp6000_get_interface(struct rte_pci_device *dev, + uint16_t *interface) +{ + int ret; + uint64_t dsn = 0; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + *interface = dsn & 0xffff; + + return 0; +} + +static int +nfp6000_get_serial(struct rte_pci_device *dev, + uint8_t *serial, + size_t length) +{ + int ret; + uint64_t dsn = 0; + + if (length < NFP_SERIAL_LEN) + return -ENOMEM; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + serial[0] = (dsn >> 56) & 0xff; + serial[1] = (dsn >> 48) & 0xff; + serial[2] = (dsn >> 40) & 0xff; + serial[3] = (dsn >> 32) & 0xff; + serial[4] = (dsn >> 24) & 0xff; + serial[5] = (dsn >> 16) & 0xff; + + return 0; +} + static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) @@ -789,6 +856,10 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .free = nfp6000_free, .area_priv_size = sizeof(struct nfp6000_area_priv), + + .get_interface = nfp6000_get_interface, + .get_serial = nfp6000_get_serial, + .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 34ed50ceca..0f36ba0b50 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -16,6 +16,8 @@ struct nfp_cpp_area; #define NFP_SERIAL_LEN 6 +#define NFP_CPP_NUM_TARGETS 16 + /* * NFP CPP operations structure */ @@ -33,6 +35,13 @@ struct nfp_cpp_operations { */ void (*free)(struct nfp_cpp *cpp); + int (*get_interface)(struct rte_pci_device *dev, + uint16_t *interface); + + int (*get_serial)(struct rte_pci_device *dev, + uint8_t *serial, + size_t length); + /* * Initialize a new NFP CPP area * NOTE: This is _not_ serialized -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 26/27] net/nfp: refact the cppcore and PCIe module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (24 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 25/27] net/nfp: refact the PCIe module Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-08-30 2:14 ` [PATCH v2 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver, use the new entry function from the PCIe module instead of the cppcore module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 9 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 197 ++++++++++--------------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 6 + drivers/net/nfp/nfpcore/nfp_cpp.h | 36 +---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 68 ++++++--- 5 files changed, 141 insertions(+), 175 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 5d129d0ad3..6eefec3836 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -23,6 +23,7 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.h" #include "nfpcore/nfp_nsp.h" +#include "nfpcore/nfp6000_pcie.h" #include "nfp_common.h" #include "nfp_ctrl.h" @@ -917,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1120,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 4f453f19a9..e32ac1107c 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -98,6 +98,24 @@ struct nfp_pcie_user { char *cfg; }; +/* Generic CPP bus access interface. */ +struct nfp6000_area_priv { + struct nfp_bar *bar; + uint32_t bar_offset; + + int target; + int action; + int token; + uint64_t offset; + struct { + int read; + int write; + int bar; + } width; + size_t size; + char *iomem; +}; + static uint32_t nfp_bar_maptype(struct nfp_bar *bar) { @@ -334,24 +352,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* Generic CPP bus access interface. */ -struct nfp6000_area_priv { - struct nfp_bar *bar; - uint32_t bar_offset; - - uint32_t target; - uint32_t action; - uint32_t token; - uint64_t offset; - struct { - int read; - int write; - int bar; - } width; - size_t size; - char *iomem; -}; - static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, @@ -624,87 +624,6 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) return 0; } -static int -nfp6000_set_model(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint32_t model; - - if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { - PMD_DRV_LOG(ERR, "nfp set model failed"); - return -1; - } - - model = model << 16; - nfp_cpp_model_set(cpp, model); - - return 0; -} - -static int -nfp6000_set_interface(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint16_t interface; - - if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { - PMD_DRV_LOG(ERR, "nfp set interface failed"); - return -1; - } - - nfp_cpp_interface_set(cpp, interface); - - return 0; -} - -static int -nfp6000_set_serial(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - off_t pos; - uint16_t tmp; - uint8_t serial[6]; - int serial_len = 6; - - pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); - if (pos <= 0) { - PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found. nfp set serial failed"); - return -1; - } else { - pos += 6; - } - - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[4] = (uint8_t)((tmp >> 8) & 0xff); - serial[5] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[2] = (uint8_t)((tmp >> 8) & 0xff); - serial[3] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[0] = (uint8_t)((tmp >> 8) & 0xff); - serial[1] = (uint8_t)(tmp & 0xff); - - nfp_cpp_serial_set(cpp, serial, serial_len); - - return 0; -} - static int nfp6000_get_dsn(struct rte_pci_device *pci_dev, uint64_t *dsn) @@ -795,12 +714,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { int ret = 0; - struct nfp_pcie_user *desc; - - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return -1; - + struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); @@ -809,17 +723,11 @@ nfp6000_init(struct nfp_cpp *cpp, nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) - goto error; + return -1; } - if (nfp6000_set_model(dev, cpp) < 0) - goto error; - if (nfp6000_set_interface(dev, cpp) < 0) - goto error; - if (nfp6000_set_serial(dev, cpp) < 0) - goto error; if (nfp6000_set_barsz(dev, desc) < 0) - goto error; + return -1; desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; @@ -830,13 +738,7 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - nfp_cpp_priv_set(cpp, desc); - return 0; - -error: - free(desc); - return -1; } static void @@ -848,7 +750,7 @@ nfp6000_free(struct nfp_cpp *cpp) if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); - free(desc); + rte_free(desc); } static const struct nfp_cpp_operations nfp6000_pcie_ops = { @@ -873,3 +775,58 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) { return &nfp6000_pcie_ops; } + +/** + * Build a NFP CPP bus from a NFP6000 PCI device + * + * @param pdev + * NFP6000 PCI device + * @param driver_lock_needed + * driver lock flag + * + * @return + * NFP CPP handle or NULL + */ +struct nfp_cpp * +nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed) +{ + int ret; + struct nfp_cpp *cpp; + uint16_t interface = 0; + struct nfp_pcie_user *nfp; + + nfp = rte_zmalloc(NULL, sizeof(*nfp), 0); + if (nfp == NULL) + return NULL; + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + rte_free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_TYPE_of(interface) != NFP_CPP_INTERFACE_TYPE_PCI) { + PMD_DRV_LOG(ERR, "Interface type is not right."); + rte_free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_CHANNEL_of(interface) != + NFP_CPP_INTERFACE_CHANNEL_PEROPENER) { + PMD_DRV_LOG(ERR, "Interface channel is not right"); + rte_free(nfp); + return NULL; + } + + /* Probe for all the common NFP devices */ + cpp = nfp_cpp_from_device_name(pci_dev, nfp, driver_lock_needed); + if (cpp == NULL) { + PMD_DRV_LOG(ERR, "Get cpp from operation failed"); + rte_free(nfp); + return NULL; + } + + return cpp; +} diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index e126457d45..8847f6f946 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -6,8 +6,14 @@ #ifndef __NFP6000_PCIE_H__ #define __NFP6000_PCIE_H__ +#include <ethdev_pci.h> + #include "nfp_cpp.h" +#include "nfp_dev.h" const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); +struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed); + #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0f36ba0b50..e879c7c920 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,40 +226,12 @@ uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + void *priv, bool driver_lock_needed); void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/** - * Retrieve the chip ID from the model ID - * - * The chip ID is a 16-bit BCD+A-F encoding for the chip type. - * - * @param model - * NFP CPP model id - * - * @return - * NFP CPP chip id - */ -#define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) - -/** - * Check for the NFP6000 family of devices - * - * NOTE: The NFP4000 series is considered as a NFP6000 series variant. - * - * @param model - * NFP CPP model id - * - * @return - * true if model is in the NFP6000 family, false otherwise. - */ -#define NFP_CPP_MODEL_IS_6000(model) \ - ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ - (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) - uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,6 +302,12 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) +/* + * Use this channel ID for multiple virtual channel interfaces + * (ie ARM and PCIe) when setting up the interface field. + */ +#define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255 + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 209d0b5160..6f46dbf5b7 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -909,10 +909,13 @@ nfp_xpb_readl(struct nfp_cpp *cpp, } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, - int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *pci_dev, + void *priv, + bool driver_lock_needed) { int err; + size_t target; + uint32_t xpb_addr; struct nfp_cpp *cpp; const struct nfp_cpp_operations *ops; @@ -925,32 +928,50 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return NULL; cpp->op = ops; + cpp->priv = priv; cpp->driver_lock_needed = driver_lock_needed; - if (cpp->op->init) { - err = cpp->op->init(cpp, dev); + err = ops->get_interface(pci_dev, &cpp->interface); + if (err != 0) { + rte_free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + rte_free(cpp); + return NULL; + } + + /* + * NOTE: cpp_lock is NOT locked for op->init, + * since it may call NFP CPP API operations + */ + err = cpp->op->init(cpp, pci_dev); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP interface initialization failed"); + rte_free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + rte_free(cpp); + return NULL; + } + + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { + /* Hardcoded XPB IMB Base, island 0 */ + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, &cpp->imb_cat_table[target]); if (err < 0) { + PMD_DRV_LOG(ERR, "Can't read CPP mapping from device"); rte_free(cpp); return NULL; } } - if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpb_addr; - size_t target; - - for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { - /* Hardcoded XPB IMB Base, island 0 */ - xpb_addr = 0x000a0000 + (target * 4); - err = nfp_xpb_readl(cpp, xpb_addr, - (uint32_t *)&cpp->imb_cat_table[target]); - if (err < 0) { - rte_free(cpp); - return NULL; - } - } - } - err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); @@ -981,6 +1002,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) * * @param dev * PCI device + * @param priv + * Private data of low-level implementation * @param driver_lock_needed * Driver lock flag * @@ -991,9 +1014,10 @@ nfp_cpp_free(struct nfp_cpp *cpp) */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed) + void *priv, + bool driver_lock_needed) { - return nfp_cpp_alloc(dev, driver_lock_needed); + return nfp_cpp_alloc(dev, priv, driver_lock_needed); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v2 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (25 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 26/27] net/nfp: refact the cppcore and " Chaoyong He @ 2023-08-30 2:14 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He 27 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-08-30 2:14 UTC (permalink / raw) To: dev; +Cc: oss-drivers, niklas.soderlund, Chaoyong He Sync the logic from kernel driver, adjust the definition of structure, and extend the usage of nfp BAR from 8 to 24. This will greatly enhance the scalability of nfp PMD. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 8 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 475 ++++++++++++++++++------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 1 + drivers/net/nfp/nfpcore/nfp_cpp.h | 5 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 346 insertions(+), 145 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 6eefec3836..d6454d8964 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -918,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1121,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index e32ac1107c..c16d9474e2 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -19,6 +19,8 @@ #include <unistd.h> #include <fcntl.h> +#include <rte_io.h> + #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" @@ -59,20 +61,12 @@ #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4)) #define NFP_PCIE_P2C_GENERAL_SIZE(bar) (1 << ((bar)->bitsize - 4)) -#define NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(id, bar, slot) \ - (NFP_PCIE_BAR(id) + ((bar) * 8 + (slot)) * 4) - -#define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ - (((bar) * 8 + (slot)) * 4) +#define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index) ((bar_index) * 4) struct nfp_pcie_user; struct nfp6000_area_priv; /* Describes BAR configuration and usage */ -#define NFP_BAR_MIN 1 -#define NFP_BAR_MID 5 -#define NFP_BAR_MAX 7 - struct nfp_bar { struct nfp_pcie_user *nfp; /**< Backlink to owner */ uint32_t barcfg; /**< BAR config CSR */ @@ -80,22 +74,26 @@ struct nfp_bar { uint64_t mask; /**< Mask of the BAR aperture (read only) */ uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ uint32_t index; /**< Index of the BAR */ - int lock; /**< If the BAR has been locked */ + bool lock; /**< If the BAR has been locked */ - char *csr; char *iomem; /**< mapped IO memory */ + struct rte_mem_resource *resource; /**< IOMEM resource window */ }; -#define BUSDEV_SZ 13 +#define NFP_PCI_BAR_MAX (PCI_64BIT_BAR_COUNT * 8) + struct nfp_pcie_user { - struct nfp_bar bar[NFP_BAR_MAX]; + struct rte_pci_device *pci_dev; + const struct nfp_dev_info *dev_info; - int device; int lock; - char busdev[BUSDEV_SZ]; - int barsz; - int dev_id; - char *cfg; + + /* PCI BAR management */ + uint32_t bars; + struct nfp_bar bar[NFP_PCI_BAR_MAX]; + + /* Reserved BAR access */ + char *csr; }; /* Generic CPP bus access interface. */ @@ -206,19 +204,19 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base; - int slot; - - base = bar->index >> 3; - slot = bar->index & 7; + uint32_t xbar; - if (nfp->cfg == NULL) - return (-ENOMEM); + xbar = NFP_PCIE_P2C_EXPBAR_OFFSET(bar->index); - bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); - - *(uint32_t *)(bar->csr) = newcfg; + if (nfp->csr != NULL) { + rte_write32(newcfg, nfp->csr + xbar); + /* Readback to ensure BAR is flushed */ + rte_read32(nfp->csr + xbar); + } else { + xbar += nfp->dev_info->pcie_cfg_expbar_offset; + rte_pci_write_config(nfp->pci_dev, &newcfg, sizeof(uint32_t), + xbar); + } bar->barcfg = newcfg; @@ -249,105 +247,320 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, return nfp_bar_write(nfp, bar, newcfg); } -/* - * Map all PCI bars. We assume that the BAR with the PCIe config block is - * already mapped. +static uint32_t +nfp_bitsize_calc(uint64_t mask) +{ + uint64_t tmp = mask; + uint32_t bit_size = 0; + + if (tmp == 0) + return 0; + + for (; tmp != 0; tmp >>= 1) + bit_size++; + + return bit_size; +} + +static int +nfp_cmp_bars(const void *ptr_a, + const void *ptr_b) +{ + const struct nfp_bar *a = ptr_a; + const struct nfp_bar *b = ptr_b; + + if (a->bitsize == b->bitsize) + return a->index - b->index; + else + return a->bitsize - b->bitsize; +} + +static bool +nfp_bars_for_secondary(uint32_t index) +{ + uint8_t tmp = index & 0x07; + + if (tmp == 0x06 || tmp == 0x07) + return true; + else + return false; +} + +/** + * Map all PCI bars and fetch the actual BAR configurations from the board. + * We assume that the BAR with the PCIe config block is already mapped. * * BAR0.0: Reserved for General Mapping (for MSI-X access to PCIe SRAM) + * BAR0.1: -- + * BAR0.2: -- + * BAR0.3: -- + * BAR0.4: -- + * BAR0.5: -- + * BAR0.6: -- + * BAR0.7: -- * - * Halving PCItoCPPBars for primary and secondary processes. - * For CoreNIC firmware: - * NFP PMD just requires two fixed slots, one for configuration BAR, - * and another for accessing the hw queues. Another slot is needed - * for setting the link up or down. Secondary processes do not need - * to map the first two slots again, but it requires one slot for - * accessing the link, even if it is not likely the secondary process - * starting the port. - * For Flower firmware: - * NFP PMD need another fixed slots, used as the configureation BAR - * for ctrl vNIC. + * BAR1.0-BAR1.7: -- + * BAR2.0-BAR2.7: -- */ static int nfp_enable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + int pf; + uint32_t i; + uint8_t min_bars; struct nfp_bar *bar; + enum rte_proc_type_t type; + struct rte_mem_resource *res; + const uint32_t barcfg_msix_general = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) | + NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT; + + type = rte_eal_process_type(); + if (type == RTE_PROC_PRIMARY) + min_bars = 12; + else + min_bars = 4; + + for (i = 0; i < RTE_DIM(nfp->bar); i++) { + if (i != 0) { + if (type == RTE_PROC_PRIMARY) { + if (nfp_bars_for_secondary(i)) + continue; + } else { + if (!nfp_bars_for_secondary(i)) + continue; + } + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* 24 NFP bars mapping into BAR0, BAR2 and BAR4 */ + res = &nfp->pci_dev->mem_resource[(i >> 3) * 2]; + + /* Skip over BARs that are not mapped */ + if (res->addr != NULL) { + bar = &nfp->bar[i]; + bar->resource = res; + bar->barcfg = 0; + + bar->nfp = nfp; + bar->index = i; + /* The resource shared by 8 bars */ + bar->mask = (res->len >> 3) - 1; + bar->bitsize = nfp_bitsize_calc(bar->mask); + bar->base = 0; + bar->lock = false; + bar->iomem = (char *)res->addr + + ((bar->index & 7) << bar->bitsize); + + nfp->bars++; + } } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - bar->barcfg = 0; - bar->nfp = nfp; - bar->index = x; - bar->mask = (1 << (nfp->barsz - 3)) - 1; - bar->bitsize = nfp->barsz - 3; - bar->base = 0; - bar->iomem = NULL; - bar->lock = 0; - bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, - bar->index >> 3, bar->index & 7); - bar->iomem = nfp->cfg + (bar->index << bar->bitsize); + if (nfp->bars < min_bars) { + PMD_DRV_LOG(ERR, "Not enough usable BARs found."); + return -EINVAL; } + + switch (nfp->pci_dev->id.device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + pf = nfp->pci_dev->addr.function & 0x07; + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(pf); + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(0); + break; + default: + PMD_DRV_LOG(ERR, "Unsupported device ID: %04hx!", + nfp->pci_dev->id.device_id); + return -EINVAL; + } + + /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */ + bar = &nfp->bar[0]; + bar->lock = true; + + nfp_bar_write(nfp, bar, barcfg_msix_general); + + /* Sort bars by bit size - use the smallest possible first. */ + qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars); + return 0; } -static struct nfp_bar * -nfp_alloc_bar(struct nfp_pcie_user *nfp) +/* Check if BAR can be used with the given parameters. */ +static bool +matching_bar_exist(struct nfp_bar *bar, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) { - int x; - int end; - int start; - struct nfp_bar *bar; + int bar_width; + int bar_token; + int bar_target; + int bar_action; + uint32_t map_type; + + bar_width = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(bar->barcfg); + switch (bar_width) { + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT: + bar_width = 4; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT: + bar_width = 8; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE: + bar_width = 0; + break; + default: + bar_width = -1; + break; + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* Make sure to match up the width */ + if (bar_width != width) + return false; + + bar_token = NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(bar->barcfg); + bar_action = NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(bar->barcfg); + map_type = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_OF(bar->barcfg); + switch (map_type) { + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET: + bar_token = -1; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK: + bar_action = NFP_CPP_ACTION_RW; + if (action == 0) + action = NFP_CPP_ACTION_RW; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED: + break; + default: + /* We don't match explicit bars through the area interface */ + return false; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->lock == 0) { - bar->lock = 1; - return bar; - } + bar_target = NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(bar->barcfg); + if ((bar_target < 0 || bar_target == target) && + (bar_token < 0 || bar_token == token) && + bar_action == action && + bar->base <= offset && + (bar->base + (1 << bar->bitsize)) >= (offset + size)) + return true; + + /* No match */ + return false; +} + +static int +find_matching_bar(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + uint32_t n; + + for (n = 0; n < nfp->bars; n++) { + struct nfp_bar *bar = &nfp->bar[n]; + + if (matching_bar_exist(bar, target, action, token, + offset, size, width)) + return n; + } + + return -1; +} + +/* Return EAGAIN if no resource is available */ +static int +find_unused_bar_noblock(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + int ret; + uint32_t n; + const struct nfp_bar *bar; + + for (n = 0; n < nfp->bars; n++) { + bar = &nfp->bar[n]; + + if (bar->bitsize == 0) + continue; + + /* Just check to see if we can make it fit... */ + ret = nfp_compute_bar(bar, NULL, NULL, target, action, + token, offset, size, width); + if (ret != 0) + continue; + + if (!bar->lock) + return n; + } + + return -EAGAIN; +} + +static int +nfp_alloc_bar(struct nfp_pcie_user *nfp, + struct nfp6000_area_priv *priv) +{ + int ret; + int bar_num; + size_t size = priv->size; + int token = priv->token; + int target = priv->target; + int action = priv->action; + int width = priv->width.bar; + uint64_t offset = priv->offset; + + /* Bar size should small than 16MB */ + if (size > (1 << 24)) + return -EINVAL; + + bar_num = find_matching_bar(nfp, target, action, token, + offset, size, width); + if (bar_num >= 0) { + /* Found a perfect match. */ + nfp->bar[bar_num].lock = true; + return bar_num; } - return NULL; + bar_num = find_unused_bar_noblock(nfp, target, action, token, + offset, size, width); + if (bar_num < 0) + return bar_num; + + nfp->bar[bar_num].lock = true; + ret = nfp_reconfigure_bar(nfp, &nfp->bar[bar_num], + target, action, token, offset, size, width); + if (ret < 0) { + nfp->bar[bar_num].lock = false; + return ret; + } + + return bar_num; } static void nfp_disable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + uint32_t i; struct nfp_bar *bar; - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; - } - - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->iomem) { + for (i = 0; i < nfp->bars; i++) { + bar = &nfp->bar[i]; + if (bar->iomem != NULL) { bar->iomem = NULL; - bar->lock = 0; + bar->lock = false; } } } @@ -364,7 +577,6 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -383,9 +595,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, else priv->width.bar = priv->width.write; - priv->bar = nfp_alloc_bar(nfp); - if (priv->bar == NULL) - return -ENOMEM; + priv->bar = NULL; priv->target = target; priv->action = action; @@ -393,17 +603,29 @@ nfp6000_area_init(struct nfp_cpp_area *area, priv->offset = address; priv->size = size; - ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); - return ret; } static int nfp6000_area_acquire(struct nfp_cpp_area *area) { + int bar_num; struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); + + /* Already allocated. */ + if (priv->bar != NULL) + return 0; + + bar_num = nfp_alloc_bar(nfp, priv); + if (bar_num < 0) { + PMD_DRV_LOG(ERR, "Failed to allocate bar %d:%d:%d:%#lx: %d", + priv->target, priv->action, priv->token, + priv->offset, bar_num); + return bar_num; + } + + priv->bar = &nfp->bar[bar_num]; /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == @@ -432,7 +654,7 @@ nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - priv->bar->lock = 0; + priv->bar->lock = false; priv->bar = NULL; priv->iomem = NULL; } @@ -603,7 +825,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) memset(&lock, 0, sizeof(lock)); - snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", desc->busdev); + snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", + desc->pci_dev->device.name); desc->lock = open(lockname, O_RDWR | O_CREAT, 0666); if (desc->lock < 0) return desc->lock; @@ -693,32 +916,11 @@ nfp6000_get_serial(struct rte_pci_device *dev, } static int -nfp6000_set_barsz(struct rte_pci_device *dev, - struct nfp_pcie_user *desc) -{ - int i = 0; - uint64_t tmp; - - tmp = dev->mem_resource[0].len; - - while (tmp >>= 1) - i++; - - desc->barsz = i; - - return 0; -} - -static int -nfp6000_init(struct nfp_cpp *cpp, - struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp) { int ret = 0; struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - memset(desc->busdev, 0, BUSDEV_SZ); - strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); - if (rte_eal_process_type() == RTE_PROC_PRIMARY && nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); @@ -726,12 +928,6 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - if (nfp6000_set_barsz(dev, desc) < 0) - return -1; - - desc->cfg = dev->mem_resource[0].addr; - desc->dev_id = dev->addr.function & 0x7; - ret = nfp_enable_bars(desc); if (ret != 0) { PMD_DRV_LOG(ERR, "Enable bars failed"); @@ -749,7 +945,6 @@ nfp6000_free(struct nfp_cpp *cpp) nfp_disable_bars(desc); if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); - close(desc->device); rte_free(desc); } @@ -789,6 +984,7 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) */ struct nfp_cpp * nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed) { int ret; @@ -800,6 +996,9 @@ nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, if (nfp == NULL) return NULL; + nfp->pci_dev = pci_dev; + nfp->dev_info = dev_info; + ret = nfp6000_get_interface(pci_dev, &interface); if (ret != 0) { PMD_DRV_LOG(ERR, "Get interface failed."); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index 8847f6f946..8e2cfb69e6 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -14,6 +14,7 @@ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed); #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index e879c7c920..2defc4fa16 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -18,6 +18,8 @@ struct nfp_cpp_area; #define NFP_CPP_NUM_TARGETS 16 +#define PCI_64BIT_BAR_COUNT 3 + /* * NFP CPP operations structure */ @@ -26,8 +28,7 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, - struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp); /* * Free the bus. diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6f46dbf5b7..8a55670f84 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -947,7 +947,7 @@ nfp_cpp_alloc(struct rte_pci_device *pci_dev, * NOTE: cpp_lock is NOT locked for op->init, * since it may call NFP CPP API operations */ - err = cpp->op->init(cpp, pci_dev); + err = cpp->op->init(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "NFP interface initialization failed"); rte_free(cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 00/27] refact the nfpcore module 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He ` (26 preceding siblings ...) 2023-08-30 2:14 ` [PATCH v2 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He ` (28 more replies) 27 siblings, 29 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He This patch series aims to: - Make the coding style satisfy with DPDK. - Sync the logic with kernel driver. - Make the sub-module more modular. - Extend the nfp configure BAR from 8 to 24. --- v3: * Fix one bug in the BAR find logic. * Modify more coding style. v2: * Fix the compile error in Fodora 37 environment. --- Chaoyong He (27): net/nfp: explicitly compare to null and 0 net/nfp: unify the indent coding style net/nfp: unify the type of integer variable net/nfp: remove the unneeded logic net/nfp: standard the local variable coding style net/nfp: adjust the log statement net/nfp: standard the comment style net/nfp: using the DPDK memory management API net/nfp: standard the blank character net/nfp: unify the guide line of header file net/nfp: rename some parameter and variable net/nfp: refact the hwinfo module net/nfp: refact the nffw module net/nfp: refact the mip module net/nfp: refact the rtsym module net/nfp: refact the resource module net/nfp: refact the target module net/nfp: add a new header file net/nfp: refact the nsp module net/nfp: refact the mutex module net/nfp: rename data field to sync with kernel driver net/nfp: add the dev module net/nfp: add header file for PCIe module net/nfp: refact the cppcore module net/nfp: refact the PCIe module net/nfp: refact the cppcore and PCIe module net/nfp: extend the usage of nfp BAR from 8 to 24 drivers/net/nfp/flower/nfp_flower.c | 14 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 3 +- drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 +- drivers/net/nfp/nfp_common.h | 52 +- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 108 +- drivers/net/nfp/nfp_ethdev_vf.c | 17 +- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 - drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 - drivers/net/nfp/nfpcore/nfp6000_pcie.c | 1034 ++++++++++++++++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 20 + drivers/net/nfp/nfpcore/nfp_cpp.h | 776 +++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 824 ------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 1088 +++++++++++------ drivers/net/nfp/nfpcore/nfp_crc.c | 23 +- drivers/net/nfp/nfpcore/nfp_dev.c | 81 ++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 199 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 74 +- drivers/net/nfp/nfpcore/nfp_mip.c | 103 +- drivers/net/nfp/nfpcore/nfp_mip.h | 7 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 383 +++--- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 + drivers/net/nfp/nfpcore/nfp_nffw.c | 210 ++-- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 580 ++++++--- drivers/net/nfp/nfpcore/nfp_nsp.h | 336 ++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 27 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 537 ++++---- drivers/net/nfp/nfpcore/nfp_platform.h | 42 + drivers/net/nfp/nfpcore/nfp_resource.c | 216 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 36 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 452 +++++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 67 +- drivers/net/nfp/nfpcore/nfp_target.c | 9 +- drivers/net/nfp/nfpcore/nfp_target.h | 597 +-------- 40 files changed, 4102 insertions(+), 4053 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.c create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h delete mode 100644 drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 01/27] net/nfp: explicitly compare to null and 0 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 02/27] net/nfp: unify the indent coding style Chaoyong He ` (27 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund To compliance with the coding standard, make the pointer variable explicitly comparing to 'NULL' and the integer variable explicitly comparing to '0'. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 ++++++------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 16 ++++++++-------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 20 ++++++++++---------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_resource.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 4 ++-- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 658c618ee6..2ee60eefc3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -224,10 +224,10 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, newcfg |= offset >> bitsize; - if (bar_base) + if (bar_base != NULL) *bar_base = offset; - if (bar_config) + if (bar_config != NULL) *bar_config = newcfg; return 0; @@ -266,7 +266,7 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); - if (err) + if (err != 0) return err; bar->base = newbase; @@ -515,7 +515,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) { + if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } @@ -583,7 +583,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) + if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; is_64 = width == TARGET_WIDTH_64; @@ -764,7 +764,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) if (rte_eal_process_type() == RTE_PROC_PRIMARY && cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); - if (ret) + if (ret != 0) goto error; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6daee313ce..31338e0047 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -235,7 +235,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, if (area == NULL) return NULL; - if (nfp_cpp_area_acquire(area)) { + if (nfp_cpp_area_acquire(area) != 0) { nfp_cpp_area_free(area); return NULL; } @@ -252,7 +252,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, void nfp_cpp_area_free(struct nfp_cpp_area *area) { - if (area->cpp->op->area_cleanup) + if (area->cpp->op->area_cleanup != NULL) area->cpp->op->area_cleanup(area); free(area); } @@ -280,7 +280,7 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) int nfp_cpp_area_acquire(struct nfp_cpp_area *area) { - if (area->cpp->op->area_acquire) { + if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); if (err < 0) @@ -299,7 +299,7 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) void nfp_cpp_area_release(struct nfp_cpp_area *area) { - if (area->cpp->op->area_release) + if (area->cpp->op->area_release != NULL) area->cpp->op->area_release(area); } @@ -319,7 +319,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) { void *iomem = NULL; - if (area->cpp->op->area_iomem) + if (area->cpp->op->area_iomem != NULL) iomem = area->cpp->op->area_iomem(area); return iomem; @@ -621,10 +621,10 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) void nfp_cpp_free(struct nfp_cpp *cpp) { - if (cpp->op && cpp->op->free) + if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len) + if (cpp->serial_len != 0) free(cpp->serial); free(cpp); @@ -833,7 +833,7 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if (*model & NFP_PL_DEVICE_ID_MASK) + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) *model -= 0x10; return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 9054bb0315..a9d166c4dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -37,7 +37,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { const char *key, *val, *end = hwinfo->data + size; - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { @@ -141,7 +141,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); - if (db) + if (db != NULL) return db; nanosleep(&wait, NULL); @@ -164,7 +164,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return NULL; err = nfp_hwinfo_db_validate(db, hwdb_size); - if (err) { + if (err != 0) { free(db); return NULL; } @@ -188,7 +188,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 6b392ad5eb..f9723dd136 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -75,7 +75,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) return -ENODEV; err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr); - if (err) + if (err != 0) goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); @@ -105,7 +105,7 @@ nfp_mip_open(struct nfp_cpp *cpp) return NULL; err = nfp_mip_read_resource(cpp, mip); - if (err) { + if (err != 0) { free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index f967a29351..0410a00856 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -38,7 +38,7 @@ static int _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) { /* Address must be 64-bit aligned */ - if (address & 7) + if ((address & 7) != 0) return -EINVAL; if (NFP_CPP_MODEL_IS_6000(model)) { diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 07d63900dc..433780a5e7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -190,7 +190,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; for (i = 0; i < cnt; i++) - if (nffw_fwinfo_loaded_get(&fwinfo[i])) + if (nffw_fwinfo_loaded_get(&fwinfo[i]) != 0) return &fwinfo[i]; return NULL; @@ -217,7 +217,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); *off = nffw_fwinfo_mip_offset_get(fwinfo); - if (nffw_fwinfo_mip_mu_da_get(fwinfo)) { + if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 1f6b7bd85c..6474abf0c2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -95,7 +95,7 @@ nfp_nsp_check(struct nfp_nsp *state) return -EINVAL; } - if (reg & NSP_STATUS_BUSY) { + if ((reg & NSP_STATUS_BUSY) != 0) { PMD_DRV_LOG(ERR, "Service processor busy!"); return -EBUSY; } @@ -128,7 +128,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) state->res = res; err = nfp_nsp_check(state); - if (err) { + if (err != 0) { nfp_nsp_close(state); return NULL; } @@ -219,7 +219,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err) + if (err != 0) return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || @@ -245,7 +245,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -254,7 +254,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_STATUS_BUSY to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -266,7 +266,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); @@ -319,13 +319,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); - if (in_buf && in_size) { + if (in_buf != NULL && in_size > 0) { err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf && out_size && out_size > in_size) { + if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, out_size - in_size); @@ -337,7 +337,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (ret < 0) return ret; - if (out_buf && out_size) { + if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); if (err < 0) return err; @@ -369,7 +369,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } - if (err) + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 01b4652280..825a84a8cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -212,7 +212,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, dst->fec_modes_supported |= fec << NFP_FEC_BASER_BIT; fec = FIELD_GET(NSP_ETH_PORT_FEC_SUPP_RS, port); dst->fec_modes_supported |= fec << NFP_FEC_REED_SOLOMON_BIT; - if (dst->fec_modes_supported) + if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); @@ -285,7 +285,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) cnt++; } @@ -294,7 +294,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * those that give a port count, verify it against the value calculated * above. */ - if (ret && ret != cnt) { + if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; @@ -309,7 +309,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); @@ -621,7 +621,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) return -EIO; err = __nfp_eth_set_fec(nsp, mode); - if (err) { + if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 351bc623ed..838cd6e0ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -115,15 +115,15 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, { int err; - if (nfp_cpp_mutex_lock(dev_mutex)) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) return -EINVAL; err = nfp_cpp_resource_find(cpp, res); - if (err) + if (err != 0) goto err_unlock_dev; err = nfp_cpp_mutex_trylock(res->mutex); - if (err) + if (err != 0) goto err_res_mutex_free; nfp_cpp_mutex_unlock(dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 343b0d0bcf..4c45aec5c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -362,10 +362,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) if (err) err = -EIO; exit: - if (error) + if (error != NULL) *error = err; - if (err) + if (err != 0) return ~0ULL; return val; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 02/27] net/nfp: unify the indent coding style 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 13:40 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 03/27] net/nfp: unify the type of integer variable Chaoyong He ` (26 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Each parameter of function should occupy one line, and indent two TAB character. All the statement which span multi line should indent two TAB character. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 80 +++++----- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 152 ++++++++++-------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 173 +++++++++++++-------- drivers/net/nfp/nfpcore/nfp_crc.c | 19 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 23 +-- drivers/net/nfp/nfpcore/nfp_mip.c | 21 ++- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 12 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 108 +++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 19 +-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 72 +++++---- drivers/net/nfp/nfpcore/nfp_resource.c | 29 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 38 +++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 15 +- 17 files changed, 463 insertions(+), 331 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 8f87c09327..54bef3cb6b 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -56,7 +56,8 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp, + struct rte_pci_device *dev); /* * Free the bus. @@ -69,9 +70,9 @@ struct nfp_cpp_operations { * NOTE: This is _not_ serialized */ int (*area_init)(struct nfp_cpp_area *area, - uint32_t dest, - unsigned long long address, - unsigned long size); + uint32_t dest, + unsigned long long address, + unsigned long size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -101,17 +102,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_read)(struct nfp_cpp_area *area, - void *kernel_vaddr, - unsigned long offset, - unsigned int length); + void *kernel_vaddr, + unsigned long offset, + unsigned int length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, - const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + const void *kernel_vaddr, + unsigned long offset, + unsigned int length); }; /* @@ -239,7 +240,7 @@ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); * @param len Length of the serial byte array */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len); + size_t serial_len); /* * Set the private data of the nfp_cpp instance @@ -279,7 +280,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + int driver_lock_needed); /* * Free a NFP CPP handle @@ -397,8 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, - unsigned long size); + unsigned long long address, unsigned long size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,10 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, - const char *name, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, unsigned long long address, + unsigned long size); /* * Free an allocated NFP CPP area handle @@ -448,9 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, unsigned long long address, unsigned long size); /* * Release the resources, then free the NFP CPP area handle @@ -459,8 +455,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, - struct nfp_cpp_area **area); + uint64_t addr, unsigned long size, struct nfp_cpp_area **area); /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -484,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * */ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *buffer, size_t length); + void *buffer, size_t length); /* * Write to a NFP CPP area handle from a buffer. The area must be acquired with @@ -498,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *buffer, size_t length); + const void *buffer, size_t length); /* * nfp_cpp_area_iomem() - get IOMEM region for CPP area @@ -522,7 +517,7 @@ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); * @return 0 on success, negative value on failure. */ int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); + unsigned long long offset, unsigned long size); /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle @@ -552,7 +547,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + unsigned long long address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -566,8 +561,8 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); + unsigned long long address, const void *kernel_vaddr, + size_t length); @@ -582,7 +577,7 @@ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); + uint32_t value, size_t length); /* * Read a single 32-bit value from a NFP CPP area handle @@ -599,7 +594,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value); + uint32_t *value); /* * Write a single 32-bit value to a NFP CPP area handle @@ -616,7 +611,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value); + uint32_t value); /* * Read a single 64-bit value from a NFP CPP area handle @@ -633,7 +628,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value); + uint64_t *value); /* * Write a single 64-bit value to a NFP CPP area handle @@ -650,7 +645,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value); + uint64_t value); /* * Write a single 32-bit value on the XPB bus @@ -685,7 +680,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); * @return 0 on success, or -1 on failure. */ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); + uint32_t value); /* * Modify bits of a 32-bit value from the XPB bus @@ -699,7 +694,7 @@ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, negative value on failure. */ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); + uint32_t value, int timeout_us); /* * Read a 32-bit word from a NFP CPP ID @@ -712,7 +707,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + unsigned long long address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -726,7 +721,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + unsigned long long address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -739,7 +734,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + unsigned long long address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -752,7 +747,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + unsigned long long address, uint64_t value); /* * Initialize a mutex location @@ -773,7 +768,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -793,8 +788,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, - uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 2ee60eefc3..884cc84eaa 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -130,9 +130,15 @@ nfp_bar_maptype(struct nfp_bar *bar) #define TARGET_WIDTH_64 8 static int -nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, - uint64_t *bar_base, int tgt, int act, int tok, - uint64_t offset, size_t size, int width) +nfp_compute_bar(const struct nfp_bar *bar, + uint32_t *bar_config, + uint64_t *bar_base, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint32_t bitsize; uint32_t newcfg; @@ -143,19 +149,16 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, switch (width) { case 8: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); break; case 4: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); break; case 0: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); break; default: return -EINVAL; @@ -165,60 +168,58 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), act, + (unsigned long long)mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + bar->index, tgt, act, tok, (unsigned long long)offset, + (unsigned long long)(offset + mask)); bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); /* Bulk mapping */ - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), + tgt, tok, (unsigned long long)mask, + (unsigned long long)(offset & mask), + (unsigned long long)(offset + size - 1) & mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); + bar->index, tgt, tok, (unsigned long long)offset, + (unsigned long long)(offset + ~mask)); bitsize = 40 - 21; } if (bar->bitsize < bitsize) { PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + tgt, tok, act); return -EINVAL; } @@ -234,8 +235,9 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, } static int -nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - uint32_t newcfg) +nfp_bar_write(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + uint32_t newcfg) { int base, slot; @@ -246,7 +248,7 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, return (-ENOMEM); bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); *(uint32_t *)(bar->csr) = newcfg; @@ -257,15 +259,21 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, } static int -nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, - int act, int tok, uint64_t offset, size_t size, int width) +nfp_reconfigure_bar(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint64_t newbase; uint32_t newcfg; int err; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + size, width); if (err != 0) return err; @@ -390,8 +398,10 @@ struct nfp6000_area_priv { }; static int -nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, unsigned long size) +nfp6000_area_init(struct nfp_cpp_area *area, + uint32_t dest, + unsigned long long address, + unsigned long size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -400,8 +410,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, uint32_t token = NFP_CPP_ID_TOKEN_of(dest); int pp, ret = 0; - pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), - address); + pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) return pp; @@ -409,7 +418,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->width.write = PULL_WIDTH(pp); if (priv->width.read > 0 && - priv->width.write > 0 && priv->width.read != priv->width.write) + priv->width.write > 0 && + priv->width.read != priv->width.write) return -EINVAL; if (priv->width.read > 0) @@ -428,8 +438,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->size = size; ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); + priv->token, priv->offset, priv->size, + priv->width.bar); return ret; } @@ -441,14 +451,13 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { + NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { priv->bar_offset = priv->offset & - (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, - priv->target); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, priv->token); + (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, + priv->target); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, + priv->token); } else { priv->bar_offset = priv->offset & priv->bar->mask; } @@ -490,8 +499,10 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) } static int -nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_read(struct nfp_cpp_area *area, + void *kernel_vaddr, + unsigned long offset, + unsigned int length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -524,17 +535,17 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { + priv->action == NFP_CPP_ACTION_RW) { is_64 = false; } if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -558,8 +569,10 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, } static int -nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_write(struct nfp_cpp_area *area, + const void *kernel_vaddr, + unsigned long offset, + unsigned int length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -590,16 +603,16 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) + priv->action == NFP_CPP_ACTION_RW) is_64 = false; if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -655,7 +668,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) } static int -nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_model(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint32_t model; @@ -671,7 +685,8 @@ nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_interface(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t interface; @@ -686,7 +701,8 @@ nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_serial(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t tmp; uint8_t serial[6]; @@ -733,7 +749,8 @@ nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) +nfp6000_set_barsz(struct rte_pci_device *dev, + struct nfp_pcie_user *desc) { unsigned long tmp; int i = 0; @@ -748,7 +765,8 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) } static int -nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp, + struct rte_pci_device *dev) { int ret = 0; struct nfp_pcie_user *desc; @@ -762,7 +780,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 31338e0047..f764208a9a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -27,7 +27,8 @@ NFP_PL_DEVICE_ID_MASK) void -nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) +nfp_cpp_priv_set(struct nfp_cpp *cpp, + void *priv) { cpp->priv = priv; } @@ -39,7 +40,8 @@ nfp_cpp_priv(struct nfp_cpp *cpp) } void -nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) +nfp_cpp_model_set(struct nfp_cpp *cpp, + uint32_t model) { cpp->model = model; } @@ -62,21 +64,24 @@ nfp_cpp_model(struct nfp_cpp *cpp) } void -nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) +nfp_cpp_interface_set(struct nfp_cpp *cpp, + uint32_t interface) { cpp->interface = interface; } int -nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) +nfp_cpp_serial(struct nfp_cpp *cpp, + const uint8_t **serial) { *serial = cpp->serial; return cpp->serial_len; } int -nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len) +nfp_cpp_serial_set(struct nfp_cpp *cpp, + const uint8_t *serial, + size_t serial_len) { if (cpp->serial_len) free(cpp->serial); @@ -161,9 +166,11 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) * NOTE: @address and @size must be 32-bit aligned values. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, - const char *name, unsigned long long address, - unsigned long size) +nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, + uint32_t dest, + const char *name, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -183,7 +190,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, name = ""; area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + strlen(name) + 1); if (area == NULL) return NULL; @@ -204,8 +211,10 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, } struct nfp_cpp_area * -nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc(struct nfp_cpp *cpp, + uint32_t dest, + unsigned long long address, + unsigned long size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -226,8 +235,10 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, * NOTE: The area must also be 'released' when the structure is freed. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; @@ -340,8 +351,10 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *kernel_vaddr, size_t length) +nfp_cpp_area_read(struct nfp_cpp_area *area, + unsigned long offset, + void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -364,8 +377,10 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *kernel_vaddr, size_t length) +nfp_cpp_area_write(struct nfp_cpp_area *area, + unsigned long offset, + const void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -392,8 +407,9 @@ nfp_cpp_area_mapped(struct nfp_cpp_area *area) * or negative value on error. */ int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, - unsigned long length) +nfp_cpp_area_check_range(struct nfp_cpp_area *area, + unsigned long long offset, + unsigned long length) { if (((offset + length) > area->size)) return -EFAULT; @@ -406,7 +422,8 @@ nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, * based upon NFP model. */ static uint32_t -nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) +nfp_xpb_to_cpp(struct nfp_cpp *cpp, + uint32_t *xpb_addr) { uint32_t xpb; int island; @@ -433,7 +450,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) else /* And only non-ARM interfaces use island id = 1 */ if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) + NFP_CPP_INTERFACE_TYPE_ARM) *xpb_addr |= (1 << 24); } else { (*xpb_addr) |= (1 << 30); @@ -443,8 +460,9 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) } int -nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value) +nfp_cpp_area_readl(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t *value) { int sz; uint32_t tmp = 0; @@ -456,8 +474,9 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value) +nfp_cpp_area_writel(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value) { int sz; @@ -467,8 +486,9 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value) +nfp_cpp_area_readq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t *value) { int sz; uint64_t tmp = 0; @@ -480,8 +500,9 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value) +nfp_cpp_area_writeq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t value) { int sz; @@ -492,8 +513,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t *value) +nfp_cpp_readl(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t *value) { int sz; uint32_t tmp; @@ -505,8 +528,10 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t value) +nfp_cpp_writel(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t value) { int sz; @@ -517,8 +542,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t *value) +nfp_cpp_readq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t *value) { int sz; uint64_t tmp; @@ -530,8 +557,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t value) +nfp_cpp_writeq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t value) { int sz; @@ -542,7 +571,9 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) +nfp_xpb_writel(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t value) { uint32_t cpp_dest; @@ -552,7 +583,9 @@ nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) } int -nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) +nfp_xpb_readl(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t *value) { uint32_t cpp_dest; @@ -562,7 +595,8 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *dev, + int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -596,7 +630,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + (tgt * 4); err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { free(cpp); return NULL; @@ -631,7 +665,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) } struct nfp_cpp * -nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_from_device_name(struct rte_pci_device *dev, + int driver_lock_needed) { return nfp_cpp_alloc(dev, driver_lock_needed); } @@ -647,7 +682,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) * @return 0 on success, or -1 on failure. */ int -nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, +nfp_xpb_writelm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, uint32_t value) { int err; @@ -674,8 +711,11 @@ nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, or negative value on failure. */ int -nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us) +nfp_xpb_waitlm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, + uint32_t value, + int timeout_us) { uint32_t tmp; int err; @@ -716,8 +756,11 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @length: number of bytes to read */ int -nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, void *kernel_vaddr, size_t length) +nfp_cpp_read(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -743,9 +786,11 @@ nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, * @length: number of bytes to write */ int -nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, const void *kernel_vaddr, - size_t length) +nfp_cpp_write(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + const void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -768,8 +813,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, * @length: length of area to fill */ int -nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length) +nfp_cpp_area_fill(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value, + size_t length) { int err; size_t i; @@ -795,9 +842,8 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = - nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); + err = nfp_cpp_area_write(area, offset + i, &value64, + sizeof(value64)); if (err < 0) return err; if (err != sizeof(value64)) @@ -805,8 +851,7 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } if ((i + sizeof(value)) <= length) { - err = - nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); + err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); if (err < 0) return err; if (err != sizeof(value)) @@ -822,13 +867,14 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) +__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, + uint32_t *model) { uint32_t reg; int err; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, - ®); + ®); if (err < 0) return err; @@ -853,8 +899,11 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) * Return: Pointer to memory mapped area or NULL */ uint8_t * -nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, struct nfp_cpp_area **area) +nfp_cpp_map_area(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + unsigned long size, + struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 20431bf845..2cd8866253 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -9,27 +9,31 @@ #include "nfp_crc.h" static inline uint32_t -nfp_crc32_be_generic(uint32_t crc, unsigned char const *p, size_t len, - uint32_t polynomial) +nfp_crc32_be_generic(uint32_t crc, + unsigned char const *p, + size_t len, + uint32_t polynomial) { int i; while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) - crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : - 0); + crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); } return crc; } static inline uint32_t -nfp_crc32_be(uint32_t crc, unsigned char const *p, size_t len) +nfp_crc32_be(uint32_t crc, + unsigned char const *p, + size_t len) { return nfp_crc32_be_generic(crc, p, len, CRCPOLY_BE); } static uint32_t -nfp_crc32_posix_end(uint32_t crc, size_t total_len) +nfp_crc32_posix_end(uint32_t crc, + size_t total_len) { /* Extend with the length of the string. */ while (total_len != 0) { @@ -43,7 +47,8 @@ nfp_crc32_posix_end(uint32_t crc, size_t total_len) } uint32_t -nfp_crc32_posix(const void *buff, size_t len) +nfp_crc32_posix(const void *buff, + size_t len) { return nfp_crc32_posix_end(nfp_crc32_be(0, buff, len), len); } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index a9d166c4dc..ea4c7d6a9e 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -33,12 +33,13 @@ nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) } static int -nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) +nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, + uint32_t size) { const char *key, *val, *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { PMD_DRV_LOG(ERR, "Bad HWINFO - overflowing value"); @@ -54,7 +55,8 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) } static int -nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) +nfp_hwinfo_db_validate(struct nfp_hwinfo *db, + uint32_t len) { uint32_t size, new_crc, *crc; @@ -69,7 +71,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", - new_crc, *crc); + new_crc, *crc); return -EINVAL; } @@ -77,7 +79,8 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) } static struct nfp_hwinfo * -nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) +nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, + size_t *cpp_size) { struct nfp_hwinfo *header; void *res; @@ -115,7 +118,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) if (header->version != NFP_HWINFO_VERSION_2) { PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", - header->version); + header->version); goto exit_free; } @@ -129,7 +132,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) } static struct nfp_hwinfo * -nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) +nfp_hwinfo_fetch(struct nfp_cpp *cpp, + size_t *hwdb_size) { struct timespec wait; struct nfp_hwinfo *db; @@ -179,7 +183,8 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) * Return: Value of the HWInfo name, or NULL */ const char * -nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) +nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, + const char *lookup) { const char *key, *val, *end; @@ -189,7 +194,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (strcmp(key, lookup) == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f9723dd136..0071d3fc37 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -37,8 +37,10 @@ struct nfp_mip { /* Read memory and check if it could be a valid MIP */ static int -nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - struct nfp_mip *mip) +nfp_mip_try_read(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + struct nfp_mip *mip) { int ret; @@ -49,12 +51,12 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, } if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", - rte_le_to_cpu_32(mip->signature)); + rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", - rte_le_to_cpu_32(mip->mip_version)); + rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -63,7 +65,8 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, /* Try to locate MIP using the resource table */ static int -nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) +nfp_mip_read_resource(struct nfp_cpp *cpp, + struct nfp_mip *mip) { struct nfp_nffw_info *nffw_info; uint32_t cpp_id; @@ -134,7 +137,9 @@ nfp_mip_name(const struct nfp_mip *mip) * @size: Location for size of MIP symbol table */ void -nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_symtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->symtab_addr); *size = rte_le_to_cpu_32(mip->symtab_size); @@ -147,7 +152,9 @@ nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) * @size: Location for size of MIP symbol name table */ void -nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_strtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->strtab_addr); *size = rte_le_to_cpu_32(mip->strtab_size); diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index d0919b58fe..980abc2517 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,5 +17,5 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *off); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 0410a00856..047e755416 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,9 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) +_nfp_cpp_mutex_validate(uint32_t model, + int *target, + unsigned long long address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -72,8 +74,10 @@ _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) * @return 0 on success, or negative value on failure. */ int -nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, - uint32_t key) +nfp_cpp_mutex_init(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ @@ -87,9 +91,8 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, if (err < 0) return err; - err = - nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address + 0, + MUTEX_LOCKED(nfp_cpp_interface(cpp))); if (err < 0) return err; @@ -114,8 +117,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * -nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key) +nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); struct nfp_cpp_mutex *mutex; @@ -265,8 +270,8 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return err; if (time(NULL) >= warn_at) { PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->usage, mutex->depth, mutex->target, + mutex->address, mutex->key); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 433780a5e7..fa65956baa 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -85,7 +85,8 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) } static unsigned int -nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) +nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, + struct nffw_fwinfo **arr) { /* * For the this code, version 0 is most likely to be version 1 in this @@ -138,8 +139,8 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) goto err_release; err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), - nfp_resource_address(state->res), - fwinf, sizeof(*fwinf)); + nfp_resource_address(state->res), + fwinf, sizeof(*fwinf)); if (err < (int)sizeof(*fwinf)) goto err_release; @@ -205,8 +206,9 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) * Return: 0, or -ERRNO */ int -nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) +nfp_nffw_info_mip_first(struct nfp_nffw_info *state, + uint32_t *cpp_id, + uint64_t *off) { struct nffw_fwinfo *fwinfo; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 6474abf0c2..4f476f6f2b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -22,7 +22,8 @@ nfp_nsp_config_modified(struct nfp_nsp *state) } void -nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified) +nfp_nsp_config_set_modified(struct nfp_nsp *state, + int modified) { state->modified = modified; } @@ -40,7 +41,9 @@ nfp_nsp_config_idx(struct nfp_nsp *state) } void -nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx) +nfp_nsp_config_set_state(struct nfp_nsp *state, + void *entries, + unsigned int idx) { state->entries = entries; state->idx = idx; @@ -91,7 +94,7 @@ nfp_nsp_check(struct nfp_nsp *state) if (state->ver.major != NSP_MAJOR || state->ver.minor < NSP_MINOR) { PMD_DRV_LOG(ERR, "Unsupported ABI %hu.%hu", state->ver.major, - state->ver.minor); + state->ver.minor); return -EINVAL; } @@ -160,8 +163,12 @@ nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state) } static int -nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, - uint64_t addr, uint64_t mask, uint64_t val) +nfp_nsp_wait_reg(struct nfp_cpp *cpp, + uint64_t *reg, + uint32_t nsp_cpp, + uint64_t addr, + uint64_t mask, + uint64_t val) { struct timespec wait; int count; @@ -204,8 +211,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, * -ETIMEDOUT if the NSP took longer than 30 seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, - uint32_t buff_cpp, uint64_t buff_addr) +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code, + uint32_t option, + uint32_t buff_cpp, + uint64_t buff_addr) { uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; struct nfp_cpp *cpp = state->cpp; @@ -223,40 +233,40 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { + !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); + buff_cpp, buff_addr); return -EINVAL; } err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | - FIELD_PREP(NSP_COMMAND_START, 1)); + FIELD_PREP(NSP_COMMAND_OPTION, option) | + FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, - NSP_COMMAND_START, 0); + NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } /* Wait for NSP_STATUS_BUSY to go to 0 */ - err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, - 0); + err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, + NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } @@ -268,7 +278,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); + -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); return -err; } @@ -279,9 +289,12 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, #define SZ_1M 0x00100000 static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, - const void *in_buf, unsigned int in_size, void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf(struct nfp_nsp *nsp, + uint16_t code, uint32_t option, + const void *in_buf, + unsigned int in_size, + void *out_buf, + unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; unsigned int max_size; @@ -291,28 +304,26 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); + code, nsp->ver.major, nsp->ver.minor); return -EOPNOTSUPP; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER_CONFIG, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); if (err < 0) return err; max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); + code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, + ®); if (err < 0) return err; @@ -328,7 +339,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + out_size - in_size); if (err < 0) return err; } @@ -388,38 +399,47 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) } int -nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_load_fw(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_eth_table(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) +nfp_nsp_write_eth_table(struct nfp_nsp *state, + const void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_identify(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, void *buf, - unsigned int size) +nfp_nsp_read_sensors(struct nfp_nsp *state, + unsigned int sensor_mask, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + 0, buf, size); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 9905b2d3d3..1e2deaabb4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -114,9 +114,10 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); + void *buf, unsigned int size); -static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) +static inline int +nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } @@ -229,22 +230,22 @@ struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); + int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + unsigned int size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + unsigned int idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) +static inline int +nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return !!eth_port->fec_modes_supported; } @@ -297,6 +298,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + long *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 21b338461e..28dba27124 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -73,7 +73,9 @@ struct nfp_sensors { }; int -nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val) +nfp_hwmon_read_sensor(struct nfp_cpp *cpp, + enum nfp_nsp_sensor_id id, + long *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 825a84a8cd..51bd57033e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -159,7 +159,8 @@ nfp_eth_speed2rate(unsigned int speed) } static void -nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) +nfp_eth_copy_mac_reverse(uint8_t *dst, + const uint8_t *src) { int i; @@ -168,8 +169,10 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) } static void -nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, struct nfp_eth_table_port *dst) +nfp_eth_port_translate(struct nfp_nsp *nsp, + const union eth_table_entry *src, + unsigned int index, + struct nfp_eth_table_port *dst) { unsigned int rate; unsigned int fec; @@ -225,21 +228,21 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, - table->ports[i].index); + table->ports[i].index); for (j = 0; j < table->count; j++) { if (table->ports[i].label_port != - table->ports[j].label_port) + table->ports[j].label_port) continue; table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; if (table->ports[i].label_subport == - table->ports[j].label_subport) + table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", - table->ports[i].label_port, - table->ports[i].label_subport); + table->ports[i].label_port, + table->ports[i].label_subport); table->ports[i].is_split = 1; } @@ -296,7 +299,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", - ret, cnt); + ret, cnt); goto err; } @@ -354,7 +357,8 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) } struct nfp_nsp * -nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx) +nfp_eth_config_start(struct nfp_cpp *cpp, + unsigned int idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -447,7 +451,9 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) * -ERRNO - configuration failed. */ int -nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) +nfp_eth_set_mod_enable(struct nfp_cpp *cpp, + unsigned int idx, + int enable) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -487,7 +493,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) * -ERRNO - configuration failed. */ int -nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) +nfp_eth_set_configured(struct nfp_cpp *cpp, + unsigned int idx, + int configed) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -523,9 +531,12 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) } static int -nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, - const uint64_t mask, const unsigned int shift, - unsigned int val, const uint64_t ctrl_bit) +nfp_eth_set_bit_config(struct nfp_nsp *nsp, + unsigned int raw_idx, + const uint64_t mask, + const unsigned int shift, + unsigned int val, + const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); unsigned int idx = nfp_nsp_config_idx(nsp); @@ -560,7 +571,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, (__extension__ ({ \ typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /* @@ -574,11 +585,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, * Return: 0 or -ERRNO. */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) +__nfp_eth_set_aneg(struct nfp_nsp *nsp, + enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_ANEG, mode, - NSP_ETH_CTRL_SET_ANEG); + NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } /* @@ -592,11 +603,11 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) * Return: 0 or -ERRNO. */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) +__nfp_eth_set_fec(struct nfp_nsp *nsp, + enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_FEC, mode, - NSP_ETH_CTRL_SET_FEC); + NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } /* @@ -611,7 +622,9 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) * -ERRNO - configuration failed. */ int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) +nfp_eth_set_fec(struct nfp_cpp *cpp, + unsigned int idx, + enum nfp_eth_fec mode) { struct nfp_nsp *nsp; int err; @@ -642,7 +655,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) +__nfp_eth_set_speed(struct nfp_nsp *nsp, + unsigned int speed) { enum nfp_eth_rate rate; @@ -653,8 +667,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) } return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_RATE, rate, - NSP_ETH_CTRL_SET_RATE); + NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } /* @@ -668,8 +681,9 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes) +__nfp_eth_set_split(struct nfp_nsp *nsp, + unsigned int lanes) { - return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, - lanes, NSP_ETH_CTRL_SET_LANES); + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, + NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 838cd6e0ef..57089c770f 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -64,7 +64,8 @@ struct nfp_resource { }; static int -nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) +nfp_cpp_resource_find(struct nfp_cpp *cpp, + struct nfp_resource *res) { char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; struct nfp_resource_entry entry; @@ -85,7 +86,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { uint64_t addr = NFP_RESOURCE_TBL_BASE + - sizeof(struct nfp_resource_entry) * i; + sizeof(struct nfp_resource_entry) * i; ret = nfp_cpp_read(cpp, cpp_id, addr, &entry, sizeof(entry)); if (ret != sizeof(entry)) @@ -95,12 +96,11 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) continue; /* Found key! */ - res->mutex = - nfp_cpp_mutex_alloc(cpp, - NFP_RESOURCE_TBL_TARGET, addr, key); + res->mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, + addr, key); res->cpp_id = NFP_CPP_ID(entry.region.cpp_target, - entry.region.cpp_action, - entry.region.cpp_token); + entry.region.cpp_action, + entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; return 0; @@ -110,8 +110,9 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) } static int -nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, - struct nfp_cpp_mutex *dev_mutex) +nfp_resource_try_acquire(struct nfp_cpp *cpp, + struct nfp_resource *res, + struct nfp_cpp_mutex *dev_mutex) { int err; @@ -148,7 +149,8 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, * Return: NFP Resource handle, or NULL */ struct nfp_resource * -nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) +nfp_resource_acquire(struct nfp_cpp *cpp, + const char *name) { struct nfp_cpp_mutex *dev_mutex; struct nfp_resource *res; @@ -165,8 +167,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, - NFP_RESOURCE_TBL_BASE, - NFP_RESOURCE_TBL_KEY); + NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { free(res); return NULL; @@ -234,8 +235,8 @@ nfp_resource_cpp_id(const struct nfp_resource *res) * * Return: const char pointer to the name of the resource */ -const char -*nfp_resource_name(const struct nfp_resource *res) +const char * +nfp_resource_name(const struct nfp_resource *res) { return res->name; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 06cc6f74f4..009b7359a4 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -18,7 +18,7 @@ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, - const char *name); + const char *name); /** * Release a NFP Resource, and free the handle diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 4c45aec5c1..aa3b7a483e 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -40,22 +40,25 @@ struct nfp_rtsym_table { }; static int -nfp_meid(uint8_t island_id, uint8_t menum) +nfp_meid(uint8_t island_id, + uint8_t menum) { return (island_id & 0x3F) == island_id && menum < 12 ? (island_id << 4) | (menum + 4) : -1; } static void -nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, uint32_t strtab_size, - struct nfp_rtsym *sw, struct nfp_rtsym_entry *fw) +nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, + uint32_t strtab_size, + struct nfp_rtsym *sw, + struct nfp_rtsym_entry *fw) { sw->type = fw->type; sw->name = cache->strtab + rte_le_to_cpu_16(fw->name) % strtab_size; sw->addr = ((uint64_t)fw->addr_hi << 32) | - rte_le_to_cpu_32(fw->addr_lo); + rte_le_to_cpu_32(fw->addr_lo); sw->size = ((uint64_t)fw->size_hi << 32) | - rte_le_to_cpu_32(fw->size_lo); + rte_le_to_cpu_32(fw->size_lo); PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", sw->name, sw->addr, sw->size, sw->target); @@ -93,7 +96,8 @@ nfp_rtsym_table_read(struct nfp_cpp *cpp) } struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) +__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip) { uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; struct nfp_rtsym_entry *rtsymtab; @@ -142,7 +146,7 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) for (n = 0; n < cache->num; n++) nfp_rtsym_sw_entry_init(cache, strtab_size, - &cache->symtab[n], &rtsymtab[n]); + &cache->symtab[n], &rtsymtab[n]); free(rtsymtab); @@ -178,7 +182,8 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) +nfp_rtsym_get(struct nfp_rtsym_table *rtbl, + int idx) { if (rtbl == NULL) return NULL; @@ -197,7 +202,8 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name) +nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name) { int n; @@ -331,7 +337,9 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, * Return: value read, on error sets the error and returns ~0ULL. */ uint64_t -nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) +nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, + const char *name, + int *error) { const struct nfp_rtsym *sym; uint32_t val32; @@ -354,7 +362,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, - name, sym->size); + name, sym->size); err = -EINVAL; break; } @@ -372,8 +380,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) } uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area) +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, + const char *name, + unsigned int min_size, + struct nfp_cpp_area **area) { int ret; uint8_t *mem; @@ -397,7 +407,7 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, if (sym->size < min_size) { PMD_DRV_LOG(ERR, "Symbol %s too small (%" PRIu64 " < %u)", name, - sym->size, min_size); + sym->size, min_size); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 8b494211bc..30768f1ccf 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -43,19 +43,18 @@ struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip); +struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip); 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); +const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name); uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, - int *error); -uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + int *error); +uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, + unsigned int min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 02/27] net/nfp: unify the indent coding style 2023-09-15 9:15 ` [PATCH v3 02/27] net/nfp: unify the indent coding style Chaoyong He @ 2023-09-15 13:40 ` Ferruh Yigit 2023-09-18 1:25 ` Chaoyong He 0 siblings, 1 reply; 159+ messages in thread From: Ferruh Yigit @ 2023-09-15 13:40 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund On 9/15/2023 10:15 AM, Chaoyong He wrote: > Each parameter of function should occupy one line, and indent two TAB > character. > No objection to it, but "Each parameter of function should occupy one line" is NOT coming from DPDK coding convention, right? If this is for driver code consistancey, that is OK. ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v3 02/27] net/nfp: unify the indent coding style 2023-09-15 13:40 ` Ferruh Yigit @ 2023-09-18 1:25 ` Chaoyong He 2023-09-18 2:22 ` Stephen Hemminger 0 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-18 1:25 UTC (permalink / raw) To: Ferruh Yigit, dev > From: Ferruh Yigit <ferruh.yigit@amd.com> > Sent: Friday, September 15, 2023 9:41 PM > To: Chaoyong He <chaoyong.he@corigine.com>; dev@dpdk.org > Cc: oss-drivers <oss-drivers@corigine.com>; Niklas Soderlund > <niklas.soderlund@corigine.com> > Subject: Re: [PATCH v3 02/27] net/nfp: unify the indent coding style > > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > Each parameter of function should occupy one line, and indent two TAB > > character. > > > > No objection to it, but "Each parameter of function should occupy one line" is > NOT coming from DPDK coding convention, right? > If this is for driver code consistancey, that is OK. Yes, it's our own coding style, a little stricter than the DPDK coding convention. ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 02/27] net/nfp: unify the indent coding style 2023-09-18 1:25 ` Chaoyong He @ 2023-09-18 2:22 ` Stephen Hemminger 0 siblings, 0 replies; 159+ messages in thread From: Stephen Hemminger @ 2023-09-18 2:22 UTC (permalink / raw) To: Chaoyong He; +Cc: Ferruh Yigit, dev On Mon, 18 Sep 2023 01:25:28 +0000 Chaoyong He <chaoyong.he@corigine.com> wrote: > > From: Ferruh Yigit <ferruh.yigit@amd.com> > > Sent: Friday, September 15, 2023 9:41 PM > > To: Chaoyong He <chaoyong.he@corigine.com>; dev@dpdk.org > > Cc: oss-drivers <oss-drivers@corigine.com>; Niklas Soderlund > > <niklas.soderlund@corigine.com> > > Subject: Re: [PATCH v3 02/27] net/nfp: unify the indent coding style > > > > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > > Each parameter of function should occupy one line, and indent two TAB > > > character. > > > > > > > No objection to it, but "Each parameter of function should occupy one line" is > > NOT coming from DPDK coding convention, right? > > If this is for driver code consistancey, that is OK. > > Yes, it's our own coding style, a little stricter than the DPDK coding convention. I wish DPDK had a uniform style and use one of the styles describable by the clang-format settings. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 03/27] net/nfp: unify the type of integer variable 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-09-15 9:15 ` [PATCH v3 02/27] net/nfp: unify the indent coding style Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 13:42 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 04/27] net/nfp: remove the unneeded logic Chaoyong He ` (25 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Unify the type of integer variable to the DPDK prefer style. Also change the return type of 'nfp_eth_speed2rate()' to the corresponding enum, which make it more readable. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 53 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 20 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 40 +++++++-------- drivers/net/nfp/nfpcore/nfp_crc.c | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 12 ++--- drivers/net/nfp/nfpcore/nfp_nffw.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nsp.c | 28 +++++----- drivers/net/nfp/nfpcore/nfp_nsp.h | 59 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 52 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- 13 files changed, 140 insertions(+), 140 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 54bef3cb6b..782272a3f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -71,8 +71,8 @@ struct nfp_cpp_operations { */ int (*area_init)(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size); + uint64_t address, + size_t size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -103,16 +103,16 @@ struct nfp_cpp_operations { */ int (*area_read)(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); }; /* @@ -398,7 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, unsigned long size); + uint64_t address, size_t size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,8 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, const char *name, unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, uint64_t address, + uint32_t size); /* * Free an allocated NFP CPP area handle @@ -446,7 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, unsigned long long address, unsigned long size); + uint32_t cpp_id, uint64_t address, size_t size); /* * Release the resources, then free the NFP CPP area handle @@ -455,7 +455,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, struct nfp_cpp_area **area); + uint64_t addr, uint32_t size, struct nfp_cpp_area **area); + /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -478,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * @return bytes read on success, negative value on failure. * */ -int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); /* @@ -492,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * * @return bytes written on success, negative value on failure. */ -int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); /* @@ -547,7 +548,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + uint64_t address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -561,9 +562,7 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); - + uint64_t address, const void *kernel_vaddr, size_t length); /* @@ -593,7 +592,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); /* @@ -610,7 +609,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); /* @@ -627,7 +626,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); /* @@ -644,7 +643,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); /* @@ -707,7 +706,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + uint64_t address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -721,7 +720,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + uint64_t address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -734,7 +733,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + uint64_t address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -747,7 +746,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + uint64_t address, uint64_t value); /* * Initialize a mutex location @@ -768,7 +767,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -788,7 +787,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 884cc84eaa..881f21bfd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -101,7 +101,7 @@ struct nfp_bar { uint64_t base; /* CPP address base */ uint64_t mask; /* Bit mask of the bar */ uint32_t bitsize; /* Bit size of the bar */ - int index; + uint32_t index; int lock; char *csr; @@ -400,8 +400,8 @@ struct nfp6000_area_priv { static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -501,8 +501,8 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -510,7 +510,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -571,8 +571,8 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -580,7 +580,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, struct nfp6000_area_priv *priv; uint32_t *wrptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -752,7 +752,7 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - unsigned long tmp; + uint64_t tmp; int i = 0; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f764208a9a..627d4eaa5d 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -169,8 +169,8 @@ struct nfp_cpp_area * nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, const char *name, - unsigned long long address, - unsigned long size) + uint64_t address, + uint32_t size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -184,7 +184,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, if (err < 0) return NULL; - address = (unsigned long long)tmp64; + address = tmp64; if (name == NULL) name = ""; @@ -213,8 +213,8 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -237,8 +237,8 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_cpp_area *area; @@ -352,7 +352,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) */ int nfp_cpp_area_read(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, void *kernel_vaddr, size_t length) { @@ -378,7 +378,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, */ int nfp_cpp_area_write(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, const void *kernel_vaddr, size_t length) { @@ -461,7 +461,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, int nfp_cpp_area_readl(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t *value) { int sz; @@ -475,7 +475,7 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, int nfp_cpp_area_writel(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t value) { int sz; @@ -487,7 +487,7 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, int nfp_cpp_area_readq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t *value) { int sz; @@ -501,7 +501,7 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, int nfp_cpp_area_writeq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t value) { int sz; @@ -515,7 +515,7 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t *value) { int sz; @@ -530,7 +530,7 @@ nfp_cpp_readl(struct nfp_cpp *cpp, int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t value) { int sz; @@ -544,7 +544,7 @@ nfp_cpp_writel(struct nfp_cpp *cpp, int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t *value) { int sz; @@ -559,7 +559,7 @@ nfp_cpp_readq(struct nfp_cpp *cpp, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t value) { int sz; @@ -758,7 +758,7 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, void *kernel_vaddr, size_t length) { @@ -788,7 +788,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, const void *kernel_vaddr, size_t length) { @@ -902,7 +902,7 @@ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, + uint32_t size, struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 2cd8866253..68f27f8c68 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -14,7 +14,7 @@ nfp_crc32_be_generic(uint32_t crc, size_t len, uint32_t polynomial) { - int i; + uint32_t i; while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 047e755416..697361da4d 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -28,16 +28,16 @@ struct nfp_cpp_mutex { struct nfp_cpp *cpp; uint8_t target; uint16_t depth; - unsigned long long address; + uint64_t address; uint32_t key; - unsigned int usage; + uint32_t usage; struct nfp_cpp_mutex *prev, *next; }; static int _nfp_cpp_mutex_validate(uint32_t model, int *target, - unsigned long long address) + uint64_t address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -76,7 +76,7 @@ _nfp_cpp_mutex_validate(uint32_t model, int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -119,7 +119,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -269,7 +269,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", + PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", mutex->usage, mutex->depth, mutex->target, mutex->address, mutex->key); warn_at = time(NULL) + 60; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index fa65956baa..2412dc0e00 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,7 +68,7 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - unsigned int mode, addr40; + uint32_t mode, addr40; uint32_t xpbaddr, imbcppat; int err; @@ -84,7 +84,7 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) return nfp_cppat_mu_locality_lsb(mode, addr40); } -static unsigned int +static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { @@ -184,7 +184,7 @@ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { struct nffw_fwinfo *fwinfo; - unsigned int cnt, i; + uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4f476f6f2b..87eed3d951 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -34,7 +34,7 @@ nfp_nsp_config_entries(struct nfp_nsp *state) return state->entries; } -unsigned int +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state) { return state->idx; @@ -43,7 +43,7 @@ nfp_nsp_config_idx(struct nfp_nsp *state) void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx) + uint32_t idx) { state->entries = entries; state->idx = idx; @@ -59,12 +59,12 @@ nfp_nsp_config_clear_state(struct nfp_nsp *state) static void nfp_nsp_print_extended_error(uint32_t ret_val) { - int i; + uint32_t i; if (ret_val == 0) return; - for (i = 0; i < (int)RTE_DIM(nsp_errors); i++) + for (i = 0; i < RTE_DIM(nsp_errors); i++) if (ret_val == (uint32_t)nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -171,7 +171,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t val) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -297,7 +297,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; - unsigned int max_size; + size_t max_size; uint64_t reg, cpp_buf; int ret, err; uint32_t cpp_id; @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } @@ -361,7 +361,7 @@ int nfp_nsp_wait(struct nfp_nsp *state) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -401,7 +401,7 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, NULL, 0); @@ -410,7 +410,7 @@ nfp_nsp_load_fw(struct nfp_nsp *state, int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, buf, size); @@ -419,7 +419,7 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, NULL, 0); @@ -428,7 +428,7 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, buf, size); @@ -436,9 +436,9 @@ nfp_nsp_read_identify(struct nfp_nsp *state, int nfp_nsp_read_sensors(struct nfp_nsp *state, - unsigned int sensor_mask, + uint32_t sensor_mask, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, 0, buf, size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 1e2deaabb4..edb56e26ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -110,11 +110,11 @@ uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); int nfp_nsp_wait(struct nfp_nsp *state); int nfp_nsp_device_soft_reset(struct nfp_nsp *state); -int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); -int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); -int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); +int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); +int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, + void *buf, size_t size); static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) @@ -188,17 +188,17 @@ enum nfp_eth_fec { * @fec_modes_supported: bitmap of FEC modes supported */ struct nfp_eth_table { - unsigned int count; - unsigned int max_index; + uint32_t count; + uint32_t max_index; struct nfp_eth_table_port { - unsigned int eth_index; - unsigned int index; - unsigned int nbi; - unsigned int base; - unsigned int lanes; - unsigned int speed; - - unsigned int interface; + uint32_t eth_index; + uint32_t index; + uint32_t nbi; + uint32_t base; + uint32_t lanes; + uint32_t speed; + + uint32_t interface; enum nfp_eth_media media; enum nfp_eth_fec fec; @@ -218,51 +218,50 @@ struct nfp_eth_table { /* Computed fields */ uint8_t port_type; - unsigned int port_lanes; + uint32_t port_lanes; int is_split; - unsigned int fec_modes_supported; + uint32_t fec_modes_supported; } ports[]; }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); -int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + size_t size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); -unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { - return !!eth_port->fec_modes_supported; + return eth_port->fec_modes_supported != 0; } -static inline unsigned int +static inline uint32_t nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported; } -struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx); +struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes); +int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /** * struct nfp_nsp_identify - NSP static information @@ -298,6 +297,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + uint32_t *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 28dba27124..31677b66e6 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -75,7 +75,7 @@ struct nfp_sensors { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val) + uint32_t *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 51bd57033e..5492840aa1 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -124,7 +124,7 @@ union eth_table_entry { static const struct { enum nfp_eth_rate rate; - unsigned int speed; + uint32_t speed; } nsp_eth_rate_tbl[] = { { RATE_INVALID, 0, }, { RATE_10M, SPEED_10, }, @@ -134,24 +134,24 @@ static const struct { { RATE_25G, SPEED_25000, }, }; -static unsigned int +static uint32_t nfp_eth_rate2speed(enum nfp_eth_rate rate) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].rate == rate) return nsp_eth_rate_tbl[i].speed; return 0; } -static unsigned int -nfp_eth_speed2rate(unsigned int speed) +static enum nfp_eth_rate +nfp_eth_speed2rate(uint32_t speed) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].speed == speed) return nsp_eth_rate_tbl[i].rate; @@ -162,7 +162,7 @@ static void nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) { - int i; + uint32_t i; for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) dst[RTE_ETHER_ADDR_LEN - i - 1] = src[i]; @@ -171,11 +171,11 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, static void nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, + uint32_t index, struct nfp_eth_table_port *dst) { - unsigned int rate; - unsigned int fec; + uint32_t rate; + uint32_t fec; uint64_t port, state; port = rte_le_to_cpu_64(src->port); @@ -224,7 +224,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - unsigned int i, j; + uint32_t i, j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -269,7 +269,9 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; struct nfp_eth_table *table; uint32_t table_sz; - int i, j, ret, cnt = 0; + uint32_t i; + uint32_t j; + int ret, cnt = 0; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -319,7 +321,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } nfp_eth_calc_port_geometry(table); - for (i = 0; i < (int)table->count; i++) + for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); free(entries); @@ -358,7 +360,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, - unsigned int idx) + uint32_t idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -452,7 +454,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int enable) { union eth_table_entry *entries; @@ -494,7 +496,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, */ int nfp_eth_set_configured(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int configed) { union eth_table_entry *entries; @@ -532,14 +534,14 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, static int nfp_eth_set_bit_config(struct nfp_nsp *nsp, - unsigned int raw_idx, + uint32_t raw_idx, const uint64_t mask, - const unsigned int shift, - unsigned int val, + const uint32_t shift, + uint32_t val, const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - unsigned int idx = nfp_nsp_config_idx(nsp); + uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; /* @@ -623,7 +625,7 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, */ int nfp_eth_set_fec(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, enum nfp_eth_fec mode) { struct nfp_nsp *nsp; @@ -656,7 +658,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, - unsigned int speed) + uint32_t speed) { enum nfp_eth_rate rate; @@ -682,7 +684,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, */ int __nfp_eth_set_split(struct nfp_nsp *nsp, - unsigned int lanes) + uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 57089c770f..9dd4832779 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -156,7 +156,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; int err; struct timespec wait; - int count; + uint16_t count; res = malloc(sizeof(*res)); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index aa3b7a483e..243d3c9ce5 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -382,7 +382,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, + uint32_t min_size, struct nfp_cpp_area **area) { int ret; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 30768f1ccf..e7295258b3 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -56,5 +56,5 @@ const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + uint32_t min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 03/27] net/nfp: unify the type of integer variable 2023-09-15 9:15 ` [PATCH v3 03/27] net/nfp: unify the type of integer variable Chaoyong He @ 2023-09-15 13:42 ` Ferruh Yigit 2023-09-18 1:26 ` Chaoyong He 0 siblings, 1 reply; 159+ messages in thread From: Ferruh Yigit @ 2023-09-15 13:42 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund On 9/15/2023 10:15 AM, Chaoyong He wrote: > Unify the type of integer variable to the DPDK prefer style. > Also change the return type of 'nfp_eth_speed2rate()' to the > corresponding enum, which make it more readable. > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> <...> > @@ -269,7 +269,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) > if (err < 0 && err != -EBUSY) > return err; > if (time(NULL) >= warn_at) { > - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", > + PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", > '%lx' is not portable between 32bits and 64bits architectures, when using fixed size variables, like 'uint64_t', better to use 'PRIx64' macro, although I know driver is only compiled for 64bits. <...> > @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, > > max_size = RTE_MAX(in_size, out_size); > if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { > - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", > + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", > '%zu' is for size_t ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v3 03/27] net/nfp: unify the type of integer variable 2023-09-15 13:42 ` Ferruh Yigit @ 2023-09-18 1:26 ` Chaoyong He 0 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 1:26 UTC (permalink / raw) To: Ferruh Yigit, dev > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > Unify the type of integer variable to the DPDK prefer style. > > Also change the return type of 'nfp_eth_speed2rate()' to the > > corresponding enum, which make it more readable. > > > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> > > <...> > > > @@ -269,7 +269,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex > *mutex) > > if (err < 0 && err != -EBUSY) > > return err; > > if (time(NULL) >= warn_at) { > > - PMD_DRV_LOG(ERR, "Warning: waiting for NFP > mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", > > + PMD_DRV_LOG(ERR, "Warning: waiting for NFP > mutex usage:%u > > +depth:%hd] target:%d addr:%lx key:%08x]", > > > > '%lx' is not portable between 32bits and 64bits architectures, when using fixed > size variables, like 'uint64_t', better to use 'PRIx64' > macro, > although I know driver is only compiled for 64bits. > Okay, I got it, thanks. > <...> > > > @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, > > > > max_size = RTE_MAX(in_size, out_size); > > if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) > { > > - PMD_DRV_LOG(ERR, "NSP: default buffer too small for > command 0x%04x (%llu < %u)", > > + PMD_DRV_LOG(ERR, "NSP: default buffer too small for > command 0x%04x > > +(%llu < %lu)", > > > > '%zu' is for size_t I will revise in the next version, thanks. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 04/27] net/nfp: remove the unneeded logic 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (2 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 03/27] net/nfp: unify the type of integer variable Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 05/27] net/nfp: standard the local variable coding style Chaoyong He ` (24 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Remove the unneeded logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 107 ---- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 - drivers/net/nfp/nfpcore/nfp_cppcore.c | 162 ------ drivers/net/nfp/nfpcore/nfp_mutex.c | 48 -- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 24 - drivers/net/nfp/nfpcore/nfp_target.h | 567 --------------------- 6 files changed, 920 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 782272a3f4..139752f85a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -96,7 +96,6 @@ struct nfp_cpp_operations { void *(*area_iomem)(struct nfp_cpp_area *area); - void *(*area_mapped)(struct nfp_cpp_area *area); /* * Perform a read from a NFP CPP area * Serialized @@ -457,16 +456,6 @@ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Return an IO pointer to the beginning of the NFP CPP area handle. The area - * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * - * @return Pointer to IO memory, or NULL on failure. - */ -void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); - /* * Read from a NFP CPP area handle into a buffer. The area must be acquired with * 'nfp_cpp_area_acquire()' before calling this operation. @@ -508,18 +497,6 @@ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Verify that IO can be performed on an offset in an area - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] size Size of region to validate - * - * @return 0 on success, negative value on failure. - */ -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); - /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle * @@ -564,20 +541,6 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); - -/* - * Fill a NFP CPP area handle and offset with a value - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the NFP CPP ID address space - * @param[in] value 32-bit value to fill area with - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, negative value on failure. - */ -int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); - /* * Read a single 32-bit value from a NFP CPP area handle * @@ -668,33 +631,6 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, negative value on failure. - */ -int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); - /* * Read a 32-bit word from a NFP CPP ID * @@ -789,49 +725,6 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Get the NFP CPP handle the mutex was created with - * - * @param mutex NFP mutex handle - * @return NFP CPP handle - */ -struct nfp_cpp *nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex key - * - * @param mutex NFP mutex handle - * @return Mutex key - */ -uint32_t nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex owner - * - * @param mutex NFP mutex handle - * @return Interface ID of the mutex owner - * - * NOTE: This is for debug purposes ONLY - the owner may change at any time, - * unless it has been locked by this NFP CPP handle. - */ -uint16_t nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex target - * - * @param mutex NFP mutex handle - * @return Mutex CPP target (ie NFP_CPP_TARGET_MU) - */ -int nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex address - * - * @param mutex NFP mutex handle - * @return Mutex CPP address - */ -uint64_t nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex); - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 881f21bfd0..ec14ec45dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -471,17 +471,6 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) return 0; } -static void * -nfp6000_area_mapped(struct nfp_cpp_area *area) -{ - struct nfp6000_area_priv *area_priv = nfp_cpp_area_priv(area); - - if (area_priv->iomem == NULL) - return NULL; - - return area_priv->iomem; -} - static void nfp6000_area_release(struct nfp_cpp_area *area) { @@ -829,7 +818,6 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, - .area_mapped = nfp6000_area_mapped, .area_read = nfp6000_area_read, .area_write = nfp6000_area_write, .area_iomem = nfp6000_area_iomem, diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 627d4eaa5d..7e7c36eda3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -388,35 +388,6 @@ nfp_cpp_area_write(struct nfp_cpp_area *area, return area->cpp->op->area_write(area, kernel_vaddr, offset, length); } -void * -nfp_cpp_area_mapped(struct nfp_cpp_area *area) -{ - if (area->cpp->op->area_mapped) - return area->cpp->op->area_mapped(area); - return NULL; -} - -/* - * nfp_cpp_area_check_range - check if address range fits in CPP area - * - * @area: CPP area handle - * @offset: offset into CPP area - * @length: size of address range in bytes - * - * Check if address range fits within CPP area. Return 0 if area fits - * or negative value on error. - */ -int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, - unsigned long length) -{ - if (((offset + length) > area->size)) - return -EFAULT; - - return 0; -} - /* * Return the correct CPP address, and fixup xpb_addr as needed, * based upon NFP model. @@ -671,82 +642,6 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int -nfp_xpb_writelm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value) -{ - int err; - uint32_t tmp; - - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - return err; - - tmp &= ~mask; - tmp |= (mask & value); - return nfp_xpb_writel(cpp, xpb_tgt, tmp); -} - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, or negative value on failure. - */ -int -nfp_xpb_waitlm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value, - int timeout_us) -{ - uint32_t tmp; - int err; - - do { - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - goto exit; - - if ((tmp & mask) == (value & mask)) { - if (timeout_us < 0) - timeout_us = 0; - break; - } - - if (timeout_us < 0) - continue; - - timeout_us -= 100; - usleep(100); - } while (timeout_us >= 0); - - if (timeout_us < 0) - err = -ETIMEDOUT; - else - err = timeout_us; - -exit: - return err; -} - /* * nfp_cpp_read - read from CPP target * @cpp: CPP handle @@ -805,63 +700,6 @@ nfp_cpp_write(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_area_fill - fill a CPP area with a value - * @area: CPP area - * @offset: offset into CPP area - * @value: value to fill with - * @length: length of area to fill - */ -int -nfp_cpp_area_fill(struct nfp_cpp_area *area, - unsigned long offset, - uint32_t value, - size_t length) -{ - int err; - size_t i; - uint64_t value64; - - value = rte_cpu_to_le_32(value); - value64 = ((uint64_t)value << 32) | value; - - if ((offset + length) > area->size) - return -EINVAL; - - if ((area->offset + offset) & 3) - return -EINVAL; - - if (((area->offset + offset) & 7) == 4 && length >= 4) { - err = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - offset += sizeof(value); - length -= sizeof(value); - } - - for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); - if (err < 0) - return err; - if (err != sizeof(value64)) - return -ENOSPC; - } - - if ((i + sizeof(value)) <= length) { - err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - i += sizeof(value); - } - - return (int)i; -} - /* * NOTE: This code should not use nfp_xpb_* functions, * as those are model-specific diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 697361da4d..4d26e6f052 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -178,54 +178,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -struct nfp_cpp * -nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex) -{ - return mutex->cpp; -} - -uint32_t -nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex) -{ - return mutex->key; -} - -uint16_t -nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex) -{ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t value, key; - int err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - return err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); - if (err < 0) - return err; - - if (key != mutex->key) - return -EPERM; - - if (MUTEX_IS_LOCKED(value) == 0) - return 0; - - return MUTEX_INTERFACE(value); -} - -int -nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex) -{ - return mutex->target; -} - -uint64_t -nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex) -{ - return mutex->address; -} - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 5492840aa1..bc155b44d8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,30 +11,6 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) #define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 03908a894f..195e599d31 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,571 +6,4 @@ #ifndef NFP_TARGET_H #define NFP_TARGET_H -#include "nfp_cpp.h" - -#define P32 1 -#define P64 2 - -#define PUSHPULL(_pull, _push) (((_pull) << 4) | ((_push) << 0)) - -#ifndef NFP_ERRNO -#include <errno.h> -#define NFP_ERRNO(x) (errno = (x), -1) -#endif - -static inline int -pushpull_width(int pp) -{ - pp &= 0xf; - - if (pp == 0) - return NFP_ERRNO(EINVAL); - return (2 << pp); -} - -#define PUSH_WIDTH(_pushpull) pushpull_width((_pushpull) >> 0) -#define PULL_WIDTH(_pushpull) pushpull_width((_pushpull) >> 4) - -static inline int -target_rw(uint32_t cpp_id, int pp, int start, int len) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < start || island > (start + len))) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): - return PUSHPULL(0, pp); - case NFP_CPP_ID(0, 1, 0): - return PUSHPULL(pp, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(pp, pp); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_dma(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiDma */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiDma */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_stats(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiStats */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiStats */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_tm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiTM */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiTM */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_ppc(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiPreclassifier */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiPreclassifier */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi(uint32_t cpp_id, uint64_t address) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - uint64_t rel_addr = address & 0x3fFFFF; - - if (island && (island < 8 || island > 9)) - return NFP_ERRNO(EINVAL); - - if (rel_addr < (1 << 20)) - return nfp6000_nbi_dma(cpp_id); - if (rel_addr < (2 << 20)) - return nfp6000_nbi_stats(cpp_id); - if (rel_addr < (3 << 20)) - return nfp6000_nbi_tm(cpp_id); - return nfp6000_nbi_ppc(cpp_id); -} - -/* - * This structure ONLY includes items that can be done with a read or write of - * 32-bit or 64-bit words. All others are not listed. - */ -static inline int -nfp6000_mu_common(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): /* read_be/write_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): /* read_le/write_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 2): /* {read/write}_swap_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 3): /* {read/write}_swap_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, 0, 0): /* read_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 1): /* read_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 2): /* read_swap_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 3): /* read_swap_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* write_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 1): /* write_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 2): /* write_swap_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 3): /* write_swap_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 3, 0): /* atomic_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 2): /* mask_compare_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* atomic_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 2): /* atomic_write_imm */ - return PUSHPULL(0, 0); - case NFP_CPP_ID(0, 4, 3): /* swap_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 5, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 5, 3): /* test_set_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 6, 0): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 3): /* test_clr_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 7, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 7, 3): /* test_add_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 8, 0): /* addsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 3): /* test_sub_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 0): /* microq128_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 1): /* microq128_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 2): /* microq128_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 0): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 3): /* test_xor_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 0): /* read32_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 1): /* read32_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 2): /* read32_swap_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 3): /* read32_swap_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 31, 0): /* write32_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 1): /* write32_le */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 2): /* write32_swap_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 3): /* write32_swap_le */ - return PUSHPULL(P32, 0); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_mu_ctm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 16, 1): /* packet_read_packet_status */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_emu(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 18, 0): /* read_queue */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 1): /* read_queue_ring */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 2): /* write_queue */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 18, 3): /* write_queue_ring */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 20, 2): /* journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 21, 0): /* get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 1): /* get_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 2): /* get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 0): /* pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 1): /* pop_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 2): /* pop_freely */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_imu(uint32_t cpp_id) -{ - return nfp6000_mu_common(cpp_id); -} - -static inline int -nfp6000_mu(uint32_t cpp_id, uint64_t address) -{ - int pp; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island == 0) { - if (address < 0x2000000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x8000000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0x9800000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x9C00000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0xA000000000ULL) - pp = nfp6000_mu_imu(cpp_id); - else - pp = nfp6000_mu_ctm(cpp_id); - } else if (island >= 24 && island <= 27) { - pp = nfp6000_mu_emu(cpp_id); - } else if (island >= 28 && island <= 31) { - pp = nfp6000_mu_imu(cpp_id); - } else if (island == 1 || - (island >= 4 && island <= 7) || - (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { - pp = nfp6000_mu_ctm(cpp_id); - } else { - pp = NFP_ERRNO(EINVAL); - } - - return pp; -} - -static inline int -nfp6000_ila(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 48 || island > 51)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* read_check_error */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 0): /* read_int */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* write_int */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 48, 4); - } -} - -static inline int -nfp6000_pci(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 4 || island > 7)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 4, 4); - } -} - -static inline int -nfp6000_crypto(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 12 || island > 15)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(P64, 0); - default: - return target_rw(cpp_id, P64, 12, 4); - } -} - -static inline int -nfp6000_cap_xpb(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* RingGet */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 0, 2): /* Interthread Signal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 1): /* RingPut */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 2): /* CTNNWr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* ReflectRd, signal none */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 1): /* ReflectRd, signal self */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 2): /* ReflectRd, signal remote */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 3): /* ReflectRd, signal both */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* ReflectWr, signal none */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 1): /* ReflectWr, signal self */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 2): /* ReflectWr, signal remote */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 3): /* ReflectWr, signal both */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): - return PUSHPULL(P32, P32); - default: - return target_rw(cpp_id, P32, 1, 63); - } -} - -static inline int -nfp6000_cls(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 3): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 1): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 1): /* add64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 1): /* sub64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 2): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 2): /* hash_mask */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* hash_clear */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 0): /* ring_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 1): /* ring_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 2): /* ring_get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 3): /* ring_pop_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* ring_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 2): /* ring_journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 14, 0): /* reflect_write_sig_local */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 1): /* reflect_read_sig_local */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 17, 2): /* statistic */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 24, 0): /* ring_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 24, 1): /* ring_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 25, 0): /* ring_workq_add_thread */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 25, 1): /* ring_workq_add_work */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 0, 64); - } -} - -static inline int -nfp6000_target_pushpull(uint32_t cpp_id, uint64_t address) -{ - switch (NFP_CPP_ID_TARGET_of(cpp_id)) { - case NFP6000_CPPTGT_NBI: - return nfp6000_nbi(cpp_id, address); - case NFP6000_CPPTGT_VQDR: - return target_rw(cpp_id, P32, 24, 4); - case NFP6000_CPPTGT_ILA: - return nfp6000_ila(cpp_id); - case NFP6000_CPPTGT_MU: - return nfp6000_mu(cpp_id, address); - case NFP6000_CPPTGT_PCIE: - return nfp6000_pci(cpp_id); - case NFP6000_CPPTGT_ARM: - if (address < 0x10000) - return target_rw(cpp_id, P64, 1, 1); - else - return target_rw(cpp_id, P32, 1, 1); - case NFP6000_CPPTGT_CRYPTO: - return nfp6000_crypto(cpp_id); - case NFP6000_CPPTGT_CTXPB: - return nfp6000_cap_xpb(cpp_id); - case NFP6000_CPPTGT_CLS: - return nfp6000_cls(cpp_id); - case 0: - return target_rw(cpp_id, P32, 4, 4); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_pushpull_width(int pp, int write_not_read) -{ - if (pp < 0) - return pp; - - if (write_not_read) - return PULL_WIDTH(pp); - else - return PUSH_WIDTH(pp); -} - -static inline int -nfp6000_target_action_width(uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - int pp; - - pp = nfp6000_target_pushpull(cpp_id, address); - - return nfp_target_pushpull_width(pp, write_not_read); -} - -static inline int -nfp_target_action_width(uint32_t model, uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - if (NFP_CPP_MODEL_IS_6000(model)) { - return nfp6000_target_action_width(cpp_id, address, - write_not_read); - } else { - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table) -{ - int err; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_island_id); - uint8_t target = NFP_CPP_ID_TARGET_of(cpp_island_id); - uint32_t imb; - - if (target >= 16) - return NFP_ERRNO(EINVAL); - - if (island == 0) { - /* Already translated */ - *cpp_target_id = cpp_island_id; - *cpp_target_address = cpp_island_address; - return 0; - } - - if (imb_table == NULL) { - /* CPP + Island only allowed on systems with IMB tables */ - return NFP_ERRNO(EINVAL); - } - - imb = imb_table[target]; - - *cpp_target_address = cpp_island_address; - err = _nfp6000_cppat_addr_encode(cpp_target_address, island, target, - ((imb >> 13) & 7), - ((imb >> 12) & 1), - ((imb >> 6) & 0x3f), - ((imb >> 0) & 0x3f)); - if (err == 0) { - *cpp_target_id = - NFP_CPP_ID(target, NFP_CPP_ID_ACTION_of(cpp_island_id), - NFP_CPP_ID_TOKEN_of(cpp_island_id)); - } - - return err; -} - #endif /* NFP_TARGET_H */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 05/27] net/nfp: standard the local variable coding style 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (3 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 04/27] net/nfp: remove the unneeded logic Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 06/27] net/nfp: adjust the log statement Chaoyong He ` (23 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund There should only declare one local variable in each line, and the local variable should be arranged from short to long in the function. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 58 ++++++++++++---------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 27 ++++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 8 +-- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 ++++++---- drivers/net/nfp/nfpcore/nfp_nffw.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nsp.c | 40 ++++++++------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +-- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 39 ++++++++------- drivers/net/nfp/nfpcore/nfp_resource.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 19 ++++--- 11 files changed, 151 insertions(+), 117 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index ec14ec45dc..78beee07ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -140,9 +140,9 @@ nfp_compute_bar(const struct nfp_bar *bar, size_t size, int width) { - uint32_t bitsize; - uint32_t newcfg; uint64_t mask; + uint32_t newcfg; + uint32_t bitsize; if (tgt >= 16) return -EINVAL; @@ -239,7 +239,8 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base, slot; + int base; + int slot; base = bar->index >> 3; slot = bar->index & 7; @@ -268,9 +269,9 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, size_t size, int width) { - uint64_t newbase; - uint32_t newcfg; int err; + uint32_t newcfg; + uint64_t newbase; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); @@ -303,8 +304,10 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, static int nfp_enable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -333,8 +336,10 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) static struct nfp_bar * nfp_alloc_bar(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -356,8 +361,10 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) static void nfp_disable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -403,12 +410,13 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint64_t address, size_t size) { - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); - struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + int pp; + int ret = 0; + uint32_t token = NFP_CPP_ID_TOKEN_of(dest); uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); - uint32_t token = NFP_CPP_ID_TOKEN_of(dest); - int pp, ret = 0; + struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -493,14 +501,14 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + size_t n; + int width; + bool is_64; + uint32_t *wrptr32 = kernel_vaddr; uint64_t *wrptr64 = kernel_vaddr; - const volatile uint64_t *rdptr64; struct nfp6000_area_priv *priv; - uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; - int width; - size_t n; - bool is_64; + const volatile uint64_t *rdptr64; priv = nfp_cpp_area_priv(area); rdptr64 = (uint64_t *)(priv->iomem + offset); @@ -563,14 +571,14 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { - const uint64_t *rdptr64 = kernel_vaddr; - uint64_t *wrptr64; - const uint32_t *rdptr32 = kernel_vaddr; - struct nfp6000_area_priv *priv; - uint32_t *wrptr32; - int width; size_t n; + int width; bool is_64; + uint32_t *wrptr32; + uint64_t *wrptr64; + struct nfp6000_area_priv *priv; + const uint32_t *rdptr32 = kernel_vaddr; + const uint64_t *rdptr64 = kernel_vaddr; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); @@ -693,10 +701,10 @@ static int nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) { + off_t pos; uint16_t tmp; uint8_t serial[6]; int serial_len = 6; - off_t pos; pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); if (pos <= 0) { @@ -741,8 +749,8 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - uint64_t tmp; int i = 0; + uint64_t tmp; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7e7c36eda3..2e5a4e7349 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -172,9 +172,9 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint64_t address, uint32_t size) { + int err; struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; - int err; if (cpp == NULL) return NULL; @@ -396,8 +396,8 @@ static uint32_t nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) { - uint32_t xpb; int island; + uint32_t xpb; xpb = NFP_CPP_ID(14, NFP_CPP_ACTION_RW, 0); @@ -569,9 +569,9 @@ static struct nfp_cpp * nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) { - const struct nfp_cpp_operations *ops; - struct nfp_cpp *cpp; int err; + struct nfp_cpp *cpp; + const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); @@ -657,8 +657,8 @@ nfp_cpp_read(struct nfp_cpp *cpp, void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { @@ -687,8 +687,8 @@ nfp_cpp_write(struct nfp_cpp *cpp, const void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) @@ -708,8 +708,8 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { - uint32_t reg; int err; + uint32_t reg; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, ®); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index ea4c7d6a9e..819761eda0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -36,7 +36,9 @@ static int nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { - const char *key, *val, *end = hwinfo->data + size; + const char *key; + const char *val; + const char *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { @@ -58,7 +60,9 @@ static int nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) { - uint32_t size, new_crc, *crc; + uint32_t *crc; + uint32_t size; + uint32_t new_crc; size = db->size; if (size > len) { @@ -82,12 +86,12 @@ static struct nfp_hwinfo * nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) { - struct nfp_hwinfo *header; - void *res; - uint64_t cpp_addr; - uint32_t cpp_id; int err; + void *res; uint8_t *db; + uint32_t cpp_id; + uint64_t cpp_addr; + struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); if (res) { @@ -135,13 +139,12 @@ static struct nfp_hwinfo * nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) { + int count = 0; struct timespec wait; struct nfp_hwinfo *db; - int count; wait.tv_sec = 0; wait.tv_nsec = 10000000; - count = 0; for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -159,9 +162,9 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo * nfp_hwinfo_read(struct nfp_cpp *cpp) { - struct nfp_hwinfo *db; - size_t hwdb_size = 0; int err; + size_t hwdb_size = 0; + struct nfp_hwinfo *db; db = nfp_hwinfo_fetch(cpp, &hwdb_size); if (db == NULL) @@ -186,7 +189,9 @@ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) { - const char *key, *val, *end; + const char *key; + const char *val; + const char *end; if (hwinfo == NULL || lookup == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0071d3fc37..1e601313b4 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -68,10 +68,10 @@ static int nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) { - struct nfp_nffw_info *nffw_info; - uint32_t cpp_id; - uint64_t addr; int err; + uint64_t addr; + uint32_t cpp_id; + struct nfp_nffw_info *nffw_info; nffw_info = nfp_nffw_info_open(cpp); if (nffw_info == NULL) @@ -100,8 +100,8 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) { - struct nfp_mip *mip; int err; + struct nfp_mip *mip; mip = malloc(sizeof(*mip)); if (mip == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 4d26e6f052..05e0ff46e5 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -79,9 +79,9 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { + int err; uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - int err; err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -122,11 +122,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { - uint32_t model = nfp_cpp_model(cpp); - struct nfp_cpp_mutex *mutex; - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ int err; uint32_t tmp; + struct nfp_cpp_mutex *mutex; + uint32_t model = nfp_cpp_model(cpp); + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -241,12 +241,13 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) { - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + int err; + uint32_t key; + uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t key, value; uint16_t interface = nfp_cpp_interface(cpp); - int err; + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -295,12 +296,14 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) { + int err; + uint32_t key; + uint32_t tmp; + uint32_t value; + struct nfp_cpp *cpp = mutex->cpp; uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ - uint32_t key, value, tmp; - struct nfp_cpp *cpp = mutex->cpp; - int err; if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 2412dc0e00..9123fc742a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,9 +68,11 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - uint32_t mode, addr40; - uint32_t xpbaddr, imbcppat; int err; + uint32_t mode; + uint32_t addr40; + uint32_t xpbaddr; + uint32_t imbcppat; /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; @@ -118,10 +120,10 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) { - struct nfp_nffw_info_data *fwinf; - struct nfp_nffw_info *state; - uint32_t info_ver; int err; + uint32_t info_ver; + struct nfp_nffw_info *state; + struct nfp_nffw_info_data *fwinf; state = malloc(sizeof(*state)); if (state == NULL) @@ -183,8 +185,9 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { + uint32_t i; + uint32_t cnt; struct nffw_fwinfo *fwinfo; - uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 87eed3d951..a00bd5870d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -72,10 +72,11 @@ nfp_nsp_print_extended_error(uint32_t ret_val) static int nfp_nsp_check(struct nfp_nsp *state) { - struct nfp_cpp *cpp = state->cpp; - uint64_t nsp_status, reg; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t nsp_status; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_status = nfp_resource_address(state->res) + NSP_STATUS; @@ -113,9 +114,9 @@ nfp_nsp_check(struct nfp_nsp *state) struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) { - struct nfp_resource *res; - struct nfp_nsp *state; int err; + struct nfp_nsp *state; + struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); if (res == NULL) @@ -170,13 +171,12 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t mask, uint64_t val) { - struct timespec wait; - uint32_t count; int err; + uint32_t count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -217,10 +217,15 @@ nfp_nsp_command(struct nfp_nsp *state, uint32_t buff_cpp, uint64_t buff_addr) { - uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; - struct nfp_cpp *cpp = state->cpp; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t ret_val; + uint64_t nsp_base; + uint64_t nsp_buffer; + uint64_t nsp_status; + uint64_t nsp_command; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_base = nfp_resource_address(state->res); @@ -296,11 +301,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, void *out_buf, unsigned int out_size) { - struct nfp_cpp *cpp = nsp->cpp; + int err; + int ret; + uint64_t reg; size_t max_size; - uint64_t reg, cpp_buf; - int ret, err; uint32_t cpp_id; + uint64_t cpp_buf; + struct nfp_cpp *cpp = nsp->cpp; if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", @@ -360,13 +367,12 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, int nfp_nsp_wait(struct nfp_nsp *state) { - struct timespec wait; - uint32_t count; int err; + int count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 31677b66e6..3081e22dad 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -26,9 +26,9 @@ struct nsp_identify { struct nfp_nsp_identify * __nfp_nsp_identify(struct nfp_nsp *nsp) { - struct nfp_nsp_identify *nspi = NULL; - struct nsp_identify *ni; int ret; + struct nsp_identify *ni; + struct nfp_nsp_identify *nspi = NULL; if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; @@ -77,9 +77,9 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val) { - struct nfp_sensors s; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + struct nfp_sensors s; nsp = nfp_nsp_open(cpp); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index bc155b44d8..9b7c8aa7f8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -150,9 +150,10 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, uint32_t index, struct nfp_eth_table_port *dst) { - uint32_t rate; uint32_t fec; - uint64_t port, state; + uint64_t port; + uint32_t rate; + uint64_t state; port = rte_le_to_cpu_64(src->port); state = rte_le_to_cpu_64(src->state); @@ -200,7 +201,8 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - uint32_t i, j; + uint32_t i; + uint32_t j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -242,12 +244,13 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) static struct nfp_eth_table * __nfp_eth_read_ports(struct nfp_nsp *nsp) { - union eth_table_entry *entries; - struct nfp_eth_table *table; - uint32_t table_sz; + int ret; uint32_t i; uint32_t j; - int ret, cnt = 0; + int cnt = 0; + uint32_t table_sz; + struct nfp_eth_table *table; + union eth_table_entry *entries; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -321,8 +324,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) { - struct nfp_eth_table *ret; struct nfp_nsp *nsp; + struct nfp_eth_table *ret; nsp = nfp_nsp_open(cpp); if (nsp == NULL) @@ -338,9 +341,9 @@ struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + union eth_table_entry *entries; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -401,8 +404,8 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) int nfp_eth_config_commit_end(struct nfp_nsp *nsp) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); int ret = 1; + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); if (nfp_nsp_config_modified(nsp)) { ret = nfp_nsp_write_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); @@ -433,9 +436,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -475,9 +478,9 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -516,9 +519,9 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, uint32_t val, const uint64_t ctrl_bit) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; + uint32_t idx = nfp_nsp_config_idx(nsp); + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); /* * Note: set features were added in ABI 0.14 but the error @@ -604,8 +607,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode) { - struct nfp_nsp *nsp; int err; + struct nfp_nsp *nsp; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 9dd4832779..fa92f2762e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -67,10 +67,12 @@ static int nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) { - char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; + int ret; + uint32_t i; + uint32_t key; + uint32_t cpp_id; struct nfp_resource_entry entry; - uint32_t cpp_id, key; - int ret, i; + char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; cpp_id = NFP_CPP_ID(NFP_RESOURCE_TBL_TARGET, 3, 0); /* Atomic read */ @@ -152,11 +154,11 @@ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) { - struct nfp_cpp_mutex *dev_mutex; - struct nfp_resource *res; int err; + uint16_t count = 0; struct timespec wait; - uint16_t count; + struct nfp_resource *res; + struct nfp_cpp_mutex *dev_mutex; res = malloc(sizeof(*res)); if (res == NULL) @@ -175,7 +177,6 @@ nfp_resource_acquire(struct nfp_cpp *cpp, wait.tv_sec = 0; wait.tv_nsec = 1000000; - count = 0; for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 243d3c9ce5..a34278beca 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -85,8 +85,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, struct nfp_rtsym_table * nfp_rtsym_table_read(struct nfp_cpp *cpp) { - struct nfp_rtsym_table *rtbl; struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; mip = nfp_mip_open(cpp); rtbl = __nfp_rtsym_table_read(cpp, mip); @@ -99,13 +99,18 @@ struct nfp_rtsym_table * __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) { - uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; - struct nfp_rtsym_entry *rtsymtab; + int n; + int err; + uint32_t size; + uint32_t strtab_addr; + uint32_t symtab_addr; + uint32_t strtab_size; + uint32_t symtab_size; struct nfp_rtsym_table *cache; + struct nfp_rtsym_entry *rtsymtab; const uint32_t dram = NFP_CPP_ID(NFP_CPP_TARGET_MU, NFP_CPP_ACTION_RW, 0) | NFP_ISL_EMEM0; - int err, n, size; if (mip == NULL) return NULL; @@ -341,10 +346,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) { - const struct nfp_rtsym *sym; - uint32_t val32; - uint64_t val; int err; + uint64_t val; + uint32_t val32; + const struct nfp_rtsym *sym; sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 06/27] net/nfp: adjust the log statement 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (4 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 05/27] net/nfp: standard the local variable coding style Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 07/27] net/nfp: standard the comment style Chaoyong He ` (22 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Add log statement to the important control logic, which means more strict check of the return value of function call. Also remove some verbose info log statement. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 37 ++++++---------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 20 +++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 28 ++++++++-------- drivers/net/nfp/nfpcore/nfp_mip.c | 7 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 4 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 ++++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 25 +++++++++++---- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++--- drivers/net/nfp/nfpcore/nfp_resource.c | 17 +++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 14 +++----- 10 files changed, 92 insertions(+), 79 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 78beee07ef..bdf4a658f5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -174,18 +174,10 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } - offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + offset &= mask; bitsize = 40 - 16; } else { @@ -198,30 +190,16 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); - bitsize = 40 - 21; } - if (bar->bitsize < bitsize) { - PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + if (bar->bitsize < bitsize) return -EINVAL; - } newcfg |= offset >> bitsize; @@ -254,7 +232,6 @@ nfp_bar_write(struct nfp_pcie_user *nfp, *(uint32_t *)(bar->csr) = newcfg; bar->barcfg = newcfg; - PMD_DRV_LOG(DEBUG, "BAR%d: updated to 0x%08x", bar->index, newcfg); return 0; } @@ -795,7 +772,11 @@ nfp6000_init(struct nfp_cpp *cpp, desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; - nfp_enable_bars(desc); + ret = nfp_enable_bars(desc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Enable bars failed"); + return -1; + } nfp_cpp_priv_set(cpp, desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 2e5a4e7349..e2af888a28 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -200,6 +200,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, err = cpp->op->area_init(area, dest, address, size); if (err < 0) { + PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } @@ -243,10 +244,13 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc(cpp, destination, address, size); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate CPP area"); return NULL; + } if (nfp_cpp_area_acquire(area) != 0) { + PMD_DRV_LOG(ERR, "Failed to acquire CPP area"); nfp_cpp_area_free(area); return NULL; } @@ -294,8 +298,10 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; + } } return 0; @@ -662,7 +668,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { - PMD_DRV_LOG(ERR, "Area allocation/acquire failed"); + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } @@ -691,8 +697,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; + } err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); @@ -746,8 +754,10 @@ nfp_cpp_map_area(struct nfp_cpp *cpp, uint8_t *res; *area = nfp_cpp_area_alloc_acquire(cpp, cpp_id, addr, size); - if (*area == NULL) + if (*area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for map"); goto err_eio; + } res = nfp_cpp_area_iomem(*area); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 819761eda0..b658b5e900 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -74,7 +74,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, new_crc = nfp_crc32_posix((char *)db, size); crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { - PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", + PMD_DRV_LOG(ERR, "CRC mismatch, calculated %#x, expected %#x", new_crc, *crc); return -EINVAL; } @@ -94,34 +94,36 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); - if (res) { - cpp_id = nfp_resource_cpp_id(res); - cpp_addr = nfp_resource_address(res); - *cpp_size = nfp_resource_size(res); + if (res == NULL) { + PMD_DRV_LOG(ERR, "HWInfo - acquire resource failed"); + return NULL; + } - nfp_resource_release(res); + cpp_id = nfp_resource_cpp_id(res); + cpp_addr = nfp_resource_address(res); + *cpp_size = nfp_resource_size(res); - if (*cpp_size < HWINFO_SIZE_MIN) - return NULL; - } else { + nfp_resource_release(res); + + if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - } db = malloc(*cpp_size + 1); if (db == NULL) return NULL; err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size); - if (err != (int)*cpp_size) + if (err != (int)*cpp_size) { + PMD_DRV_LOG(ERR, "HWInfo - CPP read error %d", err); goto exit_free; + } header = (void *)db; - PMD_DRV_LOG(DEBUG, "NFP HWINFO header: %#08x", *(uint32_t *)header); if (nfp_hwinfo_is_updating(header)) goto exit_free; if (header->version != NFP_HWINFO_VERSION_2) { - PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", + PMD_DRV_LOG(ERR, "Unknown HWInfo version: %#08x", header->version); goto exit_free; } diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 1e601313b4..086e82db70 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -46,16 +46,16 @@ nfp_mip_try_read(struct nfp_cpp *cpp, ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip)); if (ret != sizeof(*mip)) { - PMD_DRV_LOG(ERR, "Failed to read MIP data (%d, %zu)", ret, sizeof(*mip)); + PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } if (mip->signature != NFP_MIP_SIGNATURE) { - PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", + PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { - PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", + PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -109,6 +109,7 @@ nfp_mip_open(struct nfp_cpp *cpp) err = nfp_mip_read_resource(cpp, mip); if (err != 0) { + PMD_DRV_LOG(ERR, "Failed to read MIP resource"); free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 05e0ff46e5..82919d8270 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -221,9 +221,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%lx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 9123fc742a..b5a354137d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,6 +3,7 @@ * All rights reserved. */ +#include "../nfp_logs.h" #include "nfp_cpp.h" #include "nfp_nffw.h" #include "nfp_mip.h" @@ -132,8 +133,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) memset(state, 0, sizeof(*state)); state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); - if (state->res == NULL) + if (state->res == NULL) { + PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); goto err_free; + } fwinf = &state->fwinf; @@ -143,8 +146,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), nfp_resource_address(state->res), fwinf, sizeof(*fwinf)); - if (err < (int)sizeof(*fwinf)) + if (err < (int)sizeof(*fwinf)) { + PMD_DRV_LOG(ERR, "NFFW - CPP read error %d", err); goto err_release; + } if (nffw_res_flg_init_get(fwinf) == 0) goto err_release; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index a00bd5870d..76d418d478 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -82,8 +82,10 @@ nfp_nsp_check(struct nfp_nsp *state) nsp_status = nfp_resource_address(state->res) + NSP_STATUS; err = nfp_cpp_readq(cpp, nsp_cpp, nsp_status, ®); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed %d", err); return err; + } if (FIELD_GET(NSP_STATUS_MAGIC, reg) != NSP_MAGIC) { PMD_DRV_LOG(ERR, "Cannot detect NFP Service Processor"); @@ -119,8 +121,10 @@ nfp_nsp_open(struct nfp_cpp *cpp) struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); - if (res == NULL) + if (res == NULL) { + PMD_DRV_LOG(ERR, "NSP - resource acquire failed"); return NULL; + } state = malloc(sizeof(*state)); if (state == NULL) { @@ -133,6 +137,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) err = nfp_nsp_check(state); if (err != 0) { + PMD_DRV_LOG(ERR, "NSP - check failed"); nfp_nsp_close(state); return NULL; } @@ -180,8 +185,10 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed"); return err; + } if ((*reg & mask) == val) return 0; @@ -234,8 +241,10 @@ nfp_nsp_command(struct nfp_nsp *state, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "Check NSP command failed"); return err; + } if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { @@ -261,7 +270,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", err, code); return err; } @@ -270,7 +279,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", err, code); return err; } @@ -352,8 +361,10 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, } ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); - if (ret < 0) + if (ret < 0) { + PMD_DRV_LOG(ERR, "NSP command failed"); return ret; + } if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9b7c8aa7f8..74daa92aed 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -260,7 +260,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } @@ -279,7 +279,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * above. */ if (ret != 0 && ret != cnt) { - PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", + PMD_DRV_LOG(ERR, "Table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; } @@ -358,12 +358,12 @@ nfp_eth_config_start(struct nfp_cpp *cpp, ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } if ((entries[idx].port & NSP_ETH_PORT_LANES_MASK) == 0) { - PMD_DRV_LOG(ERR, "trying to set port state on disabled port %d", idx); + PMD_DRV_LOG(ERR, "Trying to set port state on disabled port %d", idx); goto err; } @@ -643,7 +643,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, rate = nfp_eth_speed2rate(speed); if (rate == RATE_INVALID) { - PMD_DRV_LOG(ERR, "could not find matching lane rate for speed %u", speed); + PMD_DRV_LOG(ERR, "Could not find matching lane rate for speed %u", speed); return -EINVAL; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index fa92f2762e..363f7d6198 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -118,16 +118,22 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, { int err; - if (nfp_cpp_mutex_lock(dev_mutex) != 0) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex lock failed"); return -EINVAL; + } err = nfp_cpp_resource_find(cpp, res); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP resource find failed"); goto err_unlock_dev; + } err = nfp_cpp_mutex_trylock(res->mutex); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex trylock failed"); goto err_res_mutex_free; + } nfp_cpp_mutex_unlock(dev_mutex); @@ -171,6 +177,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); free(res); return NULL; } @@ -182,8 +189,10 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err = nfp_resource_try_acquire(cpp, res, dev_mutex); if (err == 0) break; - if (err != -EBUSY) + if (err != -EBUSY) { + PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); goto err_free; + } if (count++ > 1000) { PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index a34278beca..d15a920752 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -60,8 +60,6 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->size = ((uint64_t)fw->size_hi << 32) | rte_le_to_cpu_32(fw->size_lo); - PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", - sw->name, sw->addr, sw->size, sw->target); switch (fw->target) { case SYM_TGT_LMEM: sw->target = NFP_RTSYM_TARGET_LMEM; @@ -227,7 +225,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) { switch (sym->type) { case NFP_RTSYM_TYPE_NONE: - PMD_DRV_LOG(ERR, "rtsym '%s': type NONE", sym->name); + PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ case NFP_RTSYM_TYPE_FUNCTION: @@ -235,7 +233,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_ABS: return sizeof(uint64_t); default: - PMD_DRV_LOG(ERR, "rtsym '%s': unknown type: %d", sym->name, sym->type); + PMD_DRV_LOG(ERR, "Unknown RTSYM type %u", sym->type); return 0; } } @@ -366,7 +364,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); break; default: - PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", name, sym->size); err = -EINVAL; break; @@ -396,10 +394,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, uint32_t cpp_id; const struct nfp_rtsym *sym; - PMD_DRV_LOG(DEBUG, "mapping symbol %s", name); sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { - PMD_INIT_LOG(ERR, "symbol lookup fails for %s", name); + PMD_DRV_LOG(ERR, "Symbol lookup fails for %s", name); return NULL; } @@ -418,10 +415,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, mem = nfp_cpp_map_area(rtbl->cpp, cpp_id, addr, sym->size, area); if (mem == NULL) { - PMD_INIT_LOG(ERR, "Failed to map symbol %s", name); + PMD_DRV_LOG(ERR, "Failed to map symbol %s", name); return NULL; } - PMD_DRV_LOG(DEBUG, "symbol %s with address %p", name, mem); return mem; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 07/27] net/nfp: standard the comment style 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (5 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 06/27] net/nfp: adjust the log statement Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 13:44 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 08/27] net/nfp: using the DPDK memory management API Chaoyong He ` (21 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Follow the DPDK coding style, use the kdoc comment style. Also add some comment to help understand logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 504 ++++----------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 39 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 484 ++++++++++++++++---- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 21 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 + drivers/net/nfp/nfpcore/nfp_mip.c | 43 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 69 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 49 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 6 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 53 ++- drivers/net/nfp/nfpcore/nfp_nsp.h | 108 ++--- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 170 ++++--- drivers/net/nfp/nfpcore/nfp_resource.c | 103 +++-- drivers/net/nfp/nfpcore/nfp_resource.h | 28 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 59 ++- drivers/net/nfp/nfpcore/nfp_rtsym.h | 12 +- drivers/net/nfp/nfpcore/nfp_target.c | 2 +- 17 files changed, 888 insertions(+), 864 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 139752f85a..82189e9910 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -10,9 +10,7 @@ struct nfp_cpp_mutex; -/* - * NFP CPP handle - */ +/* NFP CPP handle */ struct nfp_cpp { uint32_t model; uint32_t interface; @@ -37,9 +35,7 @@ struct nfp_cpp { int driver_lock_needed; }; -/* - * NFP CPP device area handle - */ +/* NFP CPP device area handle */ struct nfp_cpp_area { struct nfp_cpp *cpp; char *name; @@ -127,35 +123,45 @@ struct nfp_cpp_operations { #define NFP_CPP_TARGET_ID_MASK 0x1f -/* +/** * Pack target, token, and action into a CPP ID. * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id * - * @return NFP CPP ID + * @return + * NFP CPP ID */ #define NFP_CPP_ID(target, action, token) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ (((action) & 0xff) << 8)) -/* +/** * Pack target, token, action, and island into a CPP ID. - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id - * @island NFP CPP island id * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @return NFP CPP ID + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id + * @param island + * NFP CPP island id + * + * @return + * NFP CPP ID */ #define NFP_CPP_ISLAND_ID(target, action, token, island) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ @@ -163,9 +169,12 @@ struct nfp_cpp_operations { /** * Return the NFP CPP target of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP target + * @param id + * NFP CPP ID + * + * @return + * NFP CPP target */ static inline uint8_t NFP_CPP_ID_TARGET_of(uint32_t id) @@ -173,11 +182,14 @@ NFP_CPP_ID_TARGET_of(uint32_t id) return (id >> 24) & NFP_CPP_TARGET_ID_MASK; } -/* +/** * Return the NFP CPP token of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP token + * @param id + * NFP CPP ID + * + * @return + * NFP CPP token */ static inline uint8_t NFP_CPP_ID_TOKEN_of(uint32_t id) @@ -185,11 +197,14 @@ NFP_CPP_ID_TOKEN_of(uint32_t id) return (id >> 16) & 0xff; } -/* +/** * Return the NFP CPP action of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP action + * @param id + * NFP CPP ID + * + * @return + * NFP CPP action */ static inline uint8_t NFP_CPP_ID_ACTION_of(uint32_t id) @@ -197,11 +212,14 @@ NFP_CPP_ID_ACTION_of(uint32_t id) return (id >> 8) & 0xff; } -/* +/** * Return the NFP CPP island of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP island + * @param id + * NFP CPP ID + * + * @return + * NFP CPP island */ static inline uint8_t NFP_CPP_ID_ISLAND_of(uint32_t id) @@ -215,109 +233,57 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) */ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); -/* - * Set the model id - * - * @param cpp NFP CPP operations structure - * @param model Model ID - */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param interface Interface ID - */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param serial NFP serial byte array - * @param len Length of the serial byte array - */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); -/* - * Set the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); -/* - * Return the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void *nfp_cpp_priv(struct nfp_cpp *cpp); -/* - * Get the privately allocated portion of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the private area, or NULL on failure - */ void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); -/* - * NFP CPP core interface for CPP clients. - */ - -/* - * Open a NFP CPP handle to a CPP device - * - * @param[in] id 0-based ID for the CPP interface to use - * - * @return NFP CPP handle, or NULL on failure. - */ +/* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed); -/* - * Free a NFP CPP handle - * - * @param[in] cpp NFP CPP handle - */ void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/* - * NFP_CPP_MODEL_CHIP_of - retrieve the chip ID from the model ID +/** + * Retrieve the chip ID from the model ID * * The chip ID is a 16-bit BCD+A-F encoding for the chip type. * - * @param[in] model NFP CPP model id - * @return NFP CPP chip id + * @param model + * NFP CPP model id + * + * @return + * NFP CPP chip id */ #define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) -/* - * NFP_CPP_MODEL_IS_6000 - Check for the NFP6000 family of devices +/** + * Check for the NFP6000 family of devices * * NOTE: The NFP4000 series is considered as a NFP6000 series variant. * - * @param[in] model NFP CPP model id - * @return true if model is in the NFP6000 family, false otherwise. + * @param model + * NFP CPP model id + * + * @return + * true if model is in the NFP6000 family, false otherwise. */ #define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) -/* - * nfp_cpp_model - Retrieve the Model ID of the NFP - * - * @param[in] cpp NFP CPP handle - * @return NFP CPP Model ID - */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,7 +296,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); #define NFP_CPP_INTERFACE_TYPE_RPC 0x3 #define NFP_CPP_INTERFACE_TYPE_ILA 0x4 -/* +/** * Construct a 16-bit NFP Interface ID * * Interface IDs consists of 4 bits of interface type, 4 bits of unit @@ -340,422 +306,138 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * which use the MU Atomic CompareAndWrite operation - hence the limit to 16 * bits to be able to use the NFP Interface ID as a lock owner. * - * @param[in] type NFP Interface Type - * @param[in] unit Unit identifier for the interface type - * @param[in] channel Channel identifier for the interface unit - * @return Interface ID + * @param type + * NFP Interface Type + * @param unit + * Unit identifier for the interface type + * @param channel + * Channel identifier for the interface unit + * + * @return + * Interface ID */ #define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) -/* +/** * Get the interface type of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's type + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's type */ #define NFP_CPP_INTERFACE_TYPE_of(interface) (((interface) >> 12) & 0xf) -/* +/** * Get the interface unit of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's unit + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's unit */ #define NFP_CPP_INTERFACE_UNIT_of(interface) (((interface) >> 8) & 0xf) -/* +/** * Get the interface channel of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's channel + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's channel */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) -/* - * Retrieve the Interface ID of the NFP - * @param[in] cpp NFP CPP handle - * @return NFP CPP Interface ID - */ + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -/* - * Retrieve the NFP Serial Number (unique per NFP) - * @param[in] cpp NFP CPP handle - * @param[out] serial Pointer to reference the serial number array - * - * @return size of the NFP6000 serial number, in bytes - */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] name Name of owner of the area - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t cpp_id, const char *name, uint64_t address, uint32_t size); -/* - * Free an allocated NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_free(struct nfp_cpp_area *area); -/* - * Acquire the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - * - * @return 0 on success, -1 on failure. - */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area); -/* - * Release the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release(struct nfp_cpp_area *area); -/* - * Allocate, then acquire the resources needed to access the NFP CPP area handle - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Release the resources, then free the NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Read from a NFP CPP area handle into a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer to receive the data - * @param[in] length Length of the data to read - * - * @return bytes read on success, negative value on failure. - * - */ int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); -/* - * Write to a NFP CPP area handle from a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer that holds the data - * @param[in] length Length of the data to read - * - * @return bytes written on success, negative value on failure. - */ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area - * @area: CPP area handle - * - * Returns an iomem pointer for use with readl()/writel() style operations. - * - * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL - */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Get the NFP CPP handle that is the parent of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return NFP CPP handle - */ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); -/* - * Get the name passed during allocation of the NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the area's name - */ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); -/* - * Read a block of data from a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy read data to - * @param[in] length Size of the area to reserve - * - * @return bytes read on success, -1 on failure. - */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, void *kernel_vaddr, size_t length); -/* - * Write a block of data to a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy write data from - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, -1 on failure. - */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); -/* - * Read a single 32-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); -/* - * Write a single 32-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); -/* - * Read a single 64-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); -/* - * Write a single 64-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); -/* - * Write a single 32-bit value on the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); -/* - * Read a single 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Read a 32-bit word from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t *value); -/* - * Write a 32-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - * - */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t value); -/* - * Read a 64-bit work from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t *value); -/* - * Write a 64-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -/* - * Initialize a mutex location - - * The CPP target:address must point to a 64-bit aligned location, and will - * initialize 64 bits of data at the location. - * - * This creates the initial mutex state, as locked by this nfp_cpp_interface(). - * - * This function should only be called when setting up the initial lock state - * upon boot-up of the system. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id Unique 32-bit value for this mutex - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Create a mutex handle from an address controlled by a MU Atomic engine - * - * The CPP target:address must point to a 64-bit aligned location, and reserve - * 64 bits of data at the location for use by the handle. - * - * Only target/address pairs that point to entities that support the MU Atomic - * Engine's CmpAndSwap32 command are supported. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id 32-bit unique key (must match the key at this location) - * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on - * failure. - */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Free a mutex handle - does not alter the lock state - * - * @param mutex NFP CPP Mutex handle - */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); -/* - * Lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); -/* - * Unlock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); -/* - * Attempt to lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. - */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index bdf4a658f5..7e94bfb611 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -72,40 +72,25 @@ #define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ (((bar) * 8 + (slot)) * 4) -/* - * Define to enable a bit more verbose debug output. - * Set to 1 to enable a bit more verbose debug output. - */ struct nfp_pcie_user; struct nfp6000_area_priv; -/* - * struct nfp_bar - describes BAR configuration and usage - * @nfp: backlink to owner - * @barcfg: cached contents of BAR config CSR - * @base: the BAR's base CPP offset - * @mask: mask for the BAR aperture (read only) - * @bitsize: bitsize of BAR aperture (read only) - * @index: index of the BAR - * @lock: lock to specify if bar is in use - * @refcnt: number of current users - * @iomem: mapped IO memory - */ +/* Describes BAR configuration and usage */ #define NFP_BAR_MIN 1 #define NFP_BAR_MID 5 #define NFP_BAR_MAX 7 struct nfp_bar { - struct nfp_pcie_user *nfp; - uint32_t barcfg; - uint64_t base; /* CPP address base */ - uint64_t mask; /* Bit mask of the bar */ - uint32_t bitsize; /* Bit size of the bar */ - uint32_t index; - int lock; + struct nfp_pcie_user *nfp; /**< Backlink to owner */ + uint32_t barcfg; /**< BAR config CSR */ + uint64_t base; /**< Base CPP offset */ + uint64_t mask; /**< Mask of the BAR aperture (read only) */ + uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ + uint32_t index; /**< Index of the BAR */ + int lock; /**< If the BAR has been locked */ char *csr; - char *iomem; + char *iomem; /**< mapped IO memory */ }; #define BUSDEV_SZ 13 @@ -360,9 +345,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* - * Generic CPP bus access interface. - */ +/* Generic CPP bus access interface. */ struct nfp6000_area_priv { struct nfp_bar *bar; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index e2af888a28..0e8372576e 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -26,6 +26,15 @@ #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/** + * Set the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) @@ -33,12 +42,29 @@ nfp_cpp_priv_set(struct nfp_cpp *cpp, cpp->priv = priv; } +/** + * Return the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void * nfp_cpp_priv(struct nfp_cpp *cpp) { return cpp->priv; } +/** + * Set the model id + * + * @param cpp + * NFP CPP operations structure + * @param model + * Model ID + */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) @@ -46,6 +72,15 @@ nfp_cpp_model_set(struct nfp_cpp *cpp, cpp->model = model; } +/** + * Retrieve the Model ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Model ID + */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp) { @@ -63,6 +98,14 @@ nfp_cpp_model(struct nfp_cpp *cpp) return model; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param interface + * Interface ID + */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) @@ -70,6 +113,17 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, cpp->interface = interface; } +/** + * Retrieve the Serial ID of the NFP + * + * @param cpp + * NFP CPP handle + * @param serial + * Pointer to NFP serial number + * + * @return + * Length of NFP serial number + */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) @@ -78,6 +132,16 @@ nfp_cpp_serial(struct nfp_cpp *cpp, return cpp->serial_len; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param serial + * NFP serial byte array + * @param serial_len + * Length of the serial byte array + */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, @@ -96,6 +160,15 @@ nfp_cpp_serial_set(struct nfp_cpp *cpp, return 0; } +/** + * Retrieve the Interface ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Interface ID + */ uint16_t nfp_cpp_interface(struct nfp_cpp *cpp) { @@ -105,18 +178,45 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Get the privately allocated portion of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the private area, or NULL on failure + */ void * nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area) { return &cpp_area[1]; } +/** + * Get the NFP CPP handle that is the pci_dev of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * NFP CPP handle + */ struct nfp_cpp * nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area) { return cpp_area->cpp; } +/** + * Get the name passed during allocation of the NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the area's name + */ const char * nfp_cpp_area_name(struct nfp_cpp_area *cpp_area) { @@ -153,15 +253,24 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) return cpp->mu_locality_lsb; } -/* - * nfp_cpp_area_alloc - allocate a new CPP area - * @cpp: CPP handle - * @dest: CPP id - * @address: start address on CPP target - * @size: size of area in bytes +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. * - * Allocate and initialize a CPP area structure. The area must later - * be locked down with an 'acquire' before it can be safely accessed. + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param name + * Name of region + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL * * NOTE: @address and @size must be 32-bit aligned values. */ @@ -211,6 +320,25 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, return area; } +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. + * + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * + * NOTE: @address and @size must be 32-bit aligned values. + */ struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, @@ -220,17 +348,22 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, 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 - * @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. * + * @param cpp + * CPP device handle + * @param destination + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * * NOTE: @address and @size must be 32-bit aligned values. * * NOTE: The area must also be 'released' when the structure is freed. @@ -258,11 +391,11 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, return area; } -/* - * nfp_cpp_area_free - free up the CPP area - * area: CPP area handle - * +/** * Frees up memory resources held by the CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_free(struct nfp_cpp_area *area) @@ -272,11 +405,11 @@ nfp_cpp_area_free(struct nfp_cpp_area *area) free(area); } -/* - * nfp_cpp_area_release_free - release CPP area and free it - * area: CPP area handle +/** + * Releases CPP area and frees up memory resources held by it. * - * Releases CPP area and frees up memory resources held by the it. + * @param area + * CPP area handle */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area) @@ -285,12 +418,15 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) nfp_cpp_area_free(area); } -/* - * nfp_cpp_area_acquire - lock down a CPP area for access - * @area: CPP area handle +/** + * Locks down the CPP area for a potential long term activity. + * Area must always be locked down before being accessed. * - * Locks down the CPP area for a potential long term activity. Area - * must always be locked down before being accessed. + * @param area + * CPP area handle + * + * @return + * 0 on success, -1 on failure. */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area) @@ -307,11 +443,11 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) return 0; } -/* - * nfp_cpp_area_release - release a locked down CPP area - * @area: CPP area handle - * +/** * Releases a previously locked down CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_release(struct nfp_cpp_area *area) @@ -320,16 +456,16 @@ nfp_cpp_area_release(struct nfp_cpp_area *area) area->cpp->op->area_release(area); } -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area +/** + * Returns an iomem pointer for use with readl()/writel() style operations. * - * @area: CPP area handle + * @param area + * CPP area handle * - * Returns an iomem pointer for use with readl()/writel() style operations. + * @return + * Pointer to the area, or NULL * * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL */ void * nfp_cpp_area_iomem(struct nfp_cpp_area *area) @@ -342,18 +478,22 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) return iomem; } -/* - * nfp_cpp_area_read - read data from CPP area +/** + * Read data from indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to put data into - * @length: number of bytes to read + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Read data from indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -368,18 +508,22 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, return area->cpp->op->area_read(area, kernel_vaddr, offset, length); } -/* - * nfp_cpp_area_write - write data to CPP area +/** + * Write data to indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to read data from - * @length: number of bytes to write + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Write data to indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -436,6 +580,19 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, return xpb; } +/** + * Read a uint32_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, @@ -450,6 +607,19 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, @@ -462,6 +632,19 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, @@ -476,6 +659,19 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, @@ -489,6 +685,21 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint32_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -504,6 +715,21 @@ nfp_cpp_readl(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -518,6 +744,21 @@ nfp_cpp_writel(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -533,6 +774,21 @@ nfp_cpp_readq(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -547,6 +803,19 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Write a uint32_t word to a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -559,6 +828,19 @@ nfp_xpb_writel(struct nfp_cpp *cpp, return nfp_cpp_writel(cpp, cpp_dest, xpb_addr, value); } +/** + * Read a uint32_t value from a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -625,9 +907,11 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return cpp; } -/* - * nfp_cpp_free - free the CPP handle - * @cpp: CPP handle +/** + * Free the CPP handle + * + * @param cpp + * CPP handle */ void nfp_cpp_free(struct nfp_cpp *cpp) @@ -641,6 +925,19 @@ nfp_cpp_free(struct nfp_cpp *cpp) free(cpp); } +/** + * Create a NFP CPP handle from device + * + * @param dev + * PCI device + * @param driver_lock_needed + * Driver lock flag + * + * @return + * NFP CPP handle on success, NULL on failure + * + * NOTE: On failure, cpp_ops->free will be called! + */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) @@ -648,13 +945,22 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * nfp_cpp_read - read from CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer for result - * @length: number of bytes to read +/** + * Read from CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer for result + * @param length + * Number of bytes to read + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_read(struct nfp_cpp *cpp, @@ -678,13 +984,22 @@ nfp_cpp_read(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_write - write to CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer to read from - * @length: number of bytes to write +/** + * Write to CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer to read from + * @param length + * Number of bytes to write + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_write(struct nfp_cpp *cpp, @@ -731,18 +1046,23 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return 0; } -/* - * nfp_cpp_map_area() - Helper function to map an area - * @cpp: NFP CPP handler - * @cpp_id: CPP ID - * @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). * - * Map an area of IOMEM access. To undo the effect of this function call - * @nfp_cpp_area_release_free(*area). + * @param cpp + * NFP CPP handler + * @param cpp_id + * CPP id + * @param addr + * CPP address + * @param size + * Size of the area + * @param area + * Area handle (output) * - * Return: Pointer to memory mapped area or NULL + * @return + * Pointer to memory mapped area or NULL */ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index b658b5e900..f5579ab60f 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -3,7 +3,8 @@ * All rights reserved. */ -/* Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM +/* + * Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM * after chip reset. * * Examples of the fields: @@ -146,7 +147,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *db; wait.tv_sec = 0; - wait.tv_nsec = 10000000; + wait.tv_nsec = 10000000; /* 10ms */ for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -154,7 +155,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, return db; nanosleep(&wait, NULL); - if (count++ > 200) { + if (count++ > 200) { /* 10ms * 200 = 2s */ PMD_DRV_LOG(ERR, "NFP access error"); return NULL; } @@ -180,12 +181,16 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return db; } -/* - * nfp_hwinfo_lookup() - Find a value in the HWInfo table by name - * @hwinfo: NFP HWinfo table - * @lookup: HWInfo name to search for +/** + * Find a value in the HWInfo table by name + * + * @param hwinfo + * NFP HWInfo table + * @param lookup + * HWInfo name to search for * - * Return: Value of the HWInfo name, or NULL + * @return + * Value of the HWInfo name, or NULL */ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index a3da7512db..424db8035d 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -59,6 +59,8 @@ * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' * * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. */ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 086e82db70..0892c99e96 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -87,15 +87,16 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, return err; } -/* - * nfp_mip_open() - Get device MIP structure - * @cpp: NFP CPP Handle - * - * Copy MIP structure from NFP device and return it. The returned +/** + * Copy MIP structure from NFP device and return it. The returned * structure is handled internally by the library and should be - * freed by calling nfp_mip_close(). + * freed by calling @nfp_mip_close(). + * + * @param cpp + * NFP CPP Handle * - * Return: pointer to mip, NULL on failure. + * @return + * Pointer to MIP, NULL on failure. */ struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) @@ -131,11 +132,15 @@ nfp_mip_name(const struct nfp_mip *mip) return mip->name; } -/* - * nfp_mip_symtab() - Get the address and size of the MIP symbol table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol table - * @size: Location for size of MIP symbol table +/** + * Get the address and size of the MIP symbol table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol table + * @param size + * Location for size of MIP symbol table */ void nfp_mip_symtab(const struct nfp_mip *mip, @@ -146,11 +151,15 @@ nfp_mip_symtab(const struct nfp_mip *mip, *size = rte_le_to_cpu_32(mip->symtab_size); } -/* - * nfp_mip_strtab() - Get the address and size of the MIP symbol name table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol name table - * @size: Location for size of MIP symbol name table +/** + * Get the address and size of the MIP symbol name table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol name table + * @param size + * Location for size of MIP symbol name table */ void nfp_mip_strtab(const struct nfp_mip *mip, diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82919d8270..404d4fa938 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -53,7 +53,7 @@ _nfp_cpp_mutex_validate(uint32_t model, return 0; } -/* +/** * Initialize a mutex location * * The CPP target:address must point to a 64-bit aligned location, and @@ -65,13 +65,17 @@ _nfp_cpp_mutex_validate(uint32_t model, * This function should only be called when setting up * the initial lock state upon boot-up of the system. * - * @param mutex NFP CPP Mutex handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key Unique 32-bit value for this mutex + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * Unique 32-bit value for this mutex * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, @@ -99,7 +103,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, return 0; } -/* +/** * Create a mutex handle from an address controlled by a MU Atomic engine * * The CPP target:address must point to a 64-bit aligned location, and @@ -108,13 +112,17 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, * Only target/address pairs that point to entities that support the * MU Atomic Engine are supported. * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key 32-bit unique key (must match the key at this location) + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * 32-bit unique key (must match the key at this location) * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. + * @return + * A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, @@ -178,10 +186,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -/* +/** * Free a mutex handle - does not alter the lock state * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) @@ -203,12 +212,14 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) free(mutex); } -/* +/** * Lock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure. */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) @@ -229,12 +240,14 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return 0; } -/* +/** * Unlock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) @@ -280,16 +293,18 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return err; } -/* +/** * Attempt to lock a mutex handle, using the NFP MU Atomic Engine * * Valid lock states: - * * 0x....0000 - Unlocked * 0x....000f - Locked * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. + * @param mutex + * NFP CPP Mutex handle + * + * @return + * 0 if the lock succeeded, negative value on failure. */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) @@ -352,7 +367,7 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) * If there was another contending for this lock, then * the lock state would be 0x....000f * - * Write our owner ID into the lock + * Write our owner ID into the lock. * While not strictly necessary, this helps with * debug and bookkeeping. */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b5a354137d..5f004e3b21 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -52,7 +52,7 @@ nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 8) | mip_offset_lo */ +/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { @@ -112,11 +112,14 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, } } -/* - * nfp_nffw_info_open() - Acquire the lock on the NFFW table - * @cpp: NFP CPP handle +/** + * Acquire the lock on the NFFW table + * + * @param cpp + * NFP CPP handle * - * Return: nffw info pointer, or NULL on failure + * @return + * NFFW info pointer, or NULL on failure */ struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) @@ -168,11 +171,11 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) return NULL; } -/* - * nfp_nffw_info_close() - Release the lock on the NFFW table - * @state: NFP FW info state +/** + * Release the lock on the NFFW table * - * Return: void + * @param state + * NFFW info pointer */ void nfp_nffw_info_close(struct nfp_nffw_info *state) @@ -181,11 +184,14 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) free(state); } -/* - * nfp_nffw_info_fwid_first() - Return the first firmware ID in the NFFW - * @state: NFP FW info state +/** + * Return the first firmware ID in the NFFW * - * Return: First NFFW firmware info, NULL on failure + * @param state + * NFFW info pointer + * + * @return: + * First NFFW firmware info, NULL on failure */ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) @@ -205,13 +211,18 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; } -/* - * nfp_nffw_info_mip_first() - Retrieve the location of the first FW's MIP - * @state: NFP FW info state - * @cpp_id: Pointer to the CPP ID of the MIP - * @off: Pointer to the CPP Address of the MIP +/** + * Retrieve the location of the first FW's MIP + * + * @param state + * NFFW info pointer + * @param cpp_id + * Pointer to the CPP ID of the MIP + * @param off + * Pointer to the CPP Address of the MIP * - * Return: 0, or -ERRNO + * @return + * 0, or -ERRNO */ int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 46ac8a8d07..e032b6cce7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,7 +8,8 @@ #include "nfp_cpp.h" -/* Init-CSR owner IDs for firmware map to firmware IDs which start at 4. +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. * Lower IDs are reserved for target and loader IDs. */ #define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ @@ -16,7 +17,7 @@ #define NFFW_FWID_ALL 255 -/** +/* * NFFW_INFO_VERSION history: * 0: This was never actually used (before versioning), but it refers to * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later @@ -35,6 +36,7 @@ #define NFFW_MEINFO_CNT_V2 200 #define NFFW_FWINFO_CNT_V2 200 +/* nfp.nffw meinfo */ struct nffw_meinfo { uint32_t ctxmask__fwid__meid; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 76d418d478..039e4729bd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -109,9 +109,11 @@ nfp_nsp_check(struct nfp_nsp *state) return 0; } -/* - * nfp_nsp_open() - Prepare for communication and lock the NSP resource. - * @cpp: NFP CPP Handle +/** + * Prepare for communication and lock the NSP resource. + * + * @param cpp + * NFP CPP Handle */ struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) @@ -145,9 +147,11 @@ nfp_nsp_open(struct nfp_cpp *cpp) return state; } -/* - * nfp_nsp_close() - Clean up and unlock the NSP resource. - * @state: NFP SP state +/** + * Clean up and unlock the NSP resource. + * + * @param state + * NFP SP state */ void nfp_nsp_close(struct nfp_nsp *state) @@ -181,7 +185,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -194,28 +198,27 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, return 0; nanosleep(&wait, 0); - if (count++ > 1000) + if (count++ > 1000) /* 25ms * 1000 = 25s */ return -ETIMEDOUT; } } -/* - * nfp_nsp_command() - Execute a command on the NFP Service Processor - * @state: NFP SP state - * @code: NFP SP Command Code - * @option: NFP SP Command Argument - * @buff_cpp: NFP SP Buffer CPP Address info - * @buff_addr: NFP SP Buffer Host address - * - * Return: 0 for success with no result +/** + * Execute a command on the NFP Service Processor * - * positive value for NSP completion with a result code + * @param state + * NFP SP state + * @param arg + * NFP command argument structure * - * -EAGAIN if the NSP is not yet present - * -ENODEV if the NSP is not a supported model - * -EBUSY if the NSP is stuck - * -EINTR if interrupted while waiting for completion - * -ETIMEDOUT if the NSP took longer than 30 seconds to complete + * @return + * - 0 for success with no result + * - Positive value for NSP completion with a result code + * - -EAGAIN if the NSP is not yet present + * - -ENODEV if the NSP is not a supported model + * - -EBUSY if the NSP is stuck + * - -EINTR if interrupted while waiting for completion + * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int nfp_nsp_command(struct nfp_nsp *state, @@ -383,7 +386,7 @@ nfp_nsp_wait(struct nfp_nsp *state) struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); @@ -392,7 +395,7 @@ nfp_nsp_wait(struct nfp_nsp *state) nanosleep(&wait, 0); - if (count++ > 1000) { + if (count++ > 1000) { /* 25ms * 1000 = 25s */ err = -ETIMEDOUT; break; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index edb56e26ca..0fcb21e99c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -158,72 +158,45 @@ enum nfp_eth_fec { #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) -/** - * struct nfp_eth_table - ETH table information - * @count: number of table entries - * @max_index: max of @index fields of all @ports - * @ports: table of ports - * - * @eth_index: port index according to legacy ethX numbering - * @index: chip-wide first channel index - * @nbi: NBI index - * @base: first channel index (within NBI) - * @lanes: number of channels - * @speed: interface speed (in Mbps) - * @interface: interface (module) plugged in - * @media: media type of the @interface - * @fec: forward error correction mode - * @aneg: auto negotiation mode - * @mac_addr: interface MAC address - * @label_port: port id - * @label_subport: id of interface within port (for split ports) - * @enabled: is enabled? - * @tx_enabled: is TX enabled? - * @rx_enabled: is RX enabled? - * @override_changed: is media reconfig pending? - * - * @port_type: one of %PORT_* defines for ethtool - * @port_lanes: total number of lanes on the port (sum of lanes of all subports) - * @is_split: is interface part of a split port - * @fec_modes_supported: bitmap of FEC modes supported - */ +/* ETH table information */ struct nfp_eth_table { - uint32_t count; - uint32_t max_index; + uint32_t count; /**< Number of table entries */ + uint32_t max_index; /**< Max of @index fields of all @ports */ struct nfp_eth_table_port { + /** Port index according to legacy ethX numbering */ uint32_t eth_index; - uint32_t index; - uint32_t nbi; - uint32_t base; - uint32_t lanes; - uint32_t speed; + uint32_t index; /**< Chip-wide first channel index */ + uint32_t nbi; /**< NBI index */ + uint32_t base; /**< First channel index (within NBI) */ + uint32_t lanes; /**< Number of channels */ + uint32_t speed; /**< Interface speed (in Mbps) */ - uint32_t interface; - enum nfp_eth_media media; + uint32_t interface; /**< Interface (module) plugged in */ + enum nfp_eth_media media; /**< Media type of the @interface */ - enum nfp_eth_fec fec; - enum nfp_eth_aneg aneg; + enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ - struct rte_ether_addr mac_addr; + struct rte_ether_addr mac_addr; /**< Interface MAC address */ - uint8_t label_port; + uint8_t label_port; /**< Port id */ + /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; - int tx_enabled; - int rx_enabled; - - int override_changed; + int enabled; /**< Enable port */ + int tx_enabled; /**< Enable TX */ + int rx_enabled; /**< Enable RX */ - /* Computed fields */ - uint8_t port_type; + int override_changed; /**< Media reconfig pending */ + uint8_t port_type; /**< One of %PORT_* */ + /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; + int is_split; /**< Split port */ - uint32_t fec_modes_supported; - } ports[]; + uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ + } ports[]; /**< Table of ports */ }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); @@ -263,28 +236,17 @@ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); -/** - * struct nfp_nsp_identify - NSP static information - * @version: opaque version string - * @flags: version flags - * @br_primary: branch id of primary bootloader - * @br_secondary: branch id of secondary bootloader - * @br_nsp: branch id of NSP - * @primary: version of primary bootloader - * @secondary: version id of secondary bootloader - * @nsp: version id of NSP - * @sensor_mask: mask of present sensors available on NIC - */ +/* NSP static information */ struct nfp_nsp_identify { - char version[40]; - uint8_t flags; - uint8_t br_primary; - uint8_t br_secondary; - uint8_t br_nsp; - uint16_t primary; - uint16_t secondary; - uint16_t nsp; - uint64_t sensor_mask; + char version[40]; /**< Opaque version string */ + uint8_t flags; /**< Version flags */ + uint8_t br_primary; /**< Branch id of primary bootloader */ + uint8_t br_secondary; /**< Branch id of secondary bootloader */ + uint8_t br_nsp; /**< Branch id of NSP */ + uint16_t primary; /**< Version of primary bootloader */ + uint16_t secondary; /**< Version id of secondary bootloader */ + uint16_t nsp; /**< Version id of NSP */ + uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 74daa92aed..cb090d2a47 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -264,7 +264,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) goto err; } - /* The NFP3800 NIC support 8 ports, but only 2 ports are valid, + /* + * The NFP3800 NIC support 8 ports, but only 2 ports are valid, * the rest 6 ports mac are all 0, ensure we don't use these port */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { @@ -274,7 +275,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) cnt++; } - /* Some versions of flash will give us 0 instead of port count. For + /* + * Some versions of flash will give us 0 instead of port count. For * those that give a port count, verify it against the value calculated * above. */ @@ -312,14 +314,16 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) return NULL; } -/* - * nfp_eth_read_ports() - retrieve port information - * @cpp: NFP CPP handle +/** + * Read the port information from the device. + * + * Returned structure should be freed once no longer needed. * - * Read the port information from the device. Returned structure should - * be freed with kfree() once no longer needed. + * @param cpp + * NFP CPP handle * - * Return: populated ETH table or NULL on error. + * @return + * Populated ETH table or NULL on error. */ struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) @@ -387,19 +391,19 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) free(entries); } -/* - * nfp_eth_config_commit_end() - perform recorded configuration changes - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * +/** * Perform the configuration which was requested with __nfp_eth_set_*() - * helpers and recorded in @nsp state. If device was already configured - * as requested or no __nfp_eth_set_*() operations were made no NSP command + * helpers and recorded in @nsp state. If device was already configured + * as requested or no __nfp_eth_set_*() operations were made, no NSP command * will be performed. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_config_commit_end(struct nfp_nsp *nsp) @@ -417,19 +421,21 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) return ret; } -/* - * nfp_eth_set_mod_enable() - set PHY module enable control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @enable: Desired state - * +/** * Enable or disable PHY module (this usually means setting the TX lanes * disable bits). * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param enable + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, @@ -460,18 +466,20 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * nfp_eth_set_configured() - set PHY module configured control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @configed: Desired state - * +/** * Set the ifup/ifdown state on the PHY. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param configured + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_configured(struct nfp_cpp *cpp, @@ -525,7 +533,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, /* * Note: set features were added in ABI 0.14 but the error - * codes were initially not populated correctly. + * codes were initially not populated correctly. */ if (nfp_nsp_get_abi_ver_minor(nsp) < 17) { PMD_DRV_LOG(ERR, "set operations not supported, please update flash"); @@ -555,15 +563,17 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, val, ctrl_bit); \ })) -/* - * __nfp_eth_set_aneg() - set PHY autonegotiation control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired autonegotiation mode - * +/** * Allow/disallow PHY module to advertise/perform autonegotiation. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired autonegotiation mode + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, @@ -573,15 +583,17 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } -/* - * __nfp_eth_set_fec() - set PHY forward error correction control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired fec mode - * +/** * Set the PHY module forward error correction mode. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired fec mode + * + * @return + * 0 or -ERRNO */ static int __nfp_eth_set_fec(struct nfp_nsp *nsp, @@ -591,16 +603,20 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } -/* - * nfp_eth_set_fec() - set PHY forward error correction control mode - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @mode: Desired fec mode +/** + * Set PHY forward error correction control mode + * + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param mode + * Desired fec mode * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_fec(struct nfp_cpp *cpp, @@ -623,17 +639,19 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * __nfp_eth_set_speed() - set interface speed/rate - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @speed: Desired speed (per lane) - * - * Set lane speed. Provided @speed value should be subport speed divided - * by number of lanes this subport is spanning (i.e. 10000 for 40G, 25000 for - * 50G, etc.) +/** + * Set lane speed. + * Provided @speed value should be subport speed divided by number of + * lanes this subport is spanning (i.e. 10000 for 40G, 25000 for 50G, etc.) * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param speed + * Desired speed (per lane) + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, @@ -651,15 +669,17 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } -/* - * __nfp_eth_set_split() - set interface lane split - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @lanes: Desired lanes per port - * +/** * Set number of lanes in the port. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param lanes + * Desired lanes per port + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_split(struct nfp_nsp *nsp, diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 363f7d6198..bdebf5c3aa 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -22,32 +22,23 @@ #define NFP_RESOURCE_ENTRY_NAME_SZ 8 -/* - * struct nfp_resource_entry - Resource table entry - * @owner: NFP CPP Lock, interface owner - * @key: NFP CPP Lock, posix_crc32(name, 8) - * @region: Memory region descriptor - * @name: ASCII, zero padded name - * @reserved - * @cpp_action: CPP Action - * @cpp_token: CPP Token - * @cpp_target: CPP Target ID - * @page_offset: 256-byte page offset into target's CPP address - * @page_size: size, in 256-byte pages - */ +/* Resource table entry */ struct nfp_resource_entry { struct nfp_resource_entry_mutex { - uint32_t owner; - uint32_t key; + uint32_t owner; /**< NFP CPP Lock, interface owner */ + uint32_t key; /**< NFP CPP Lock, posix_crc32(name, 8) */ } mutex; + /* Memory region descriptor */ struct nfp_resource_entry_region { + /** ASCII, zero padded name */ uint8_t name[NFP_RESOURCE_ENTRY_NAME_SZ]; uint8_t reserved[5]; - uint8_t cpp_action; - uint8_t cpp_token; - uint8_t cpp_target; + uint8_t cpp_action; /**< CPP Action */ + uint8_t cpp_token; /**< CPP Token */ + uint8_t cpp_target; /**< CPP Target ID */ + /** 256-byte page offset into target's CPP address */ uint32_t page_offset; - uint32_t page_size; + uint32_t page_size; /**< Size, in 256-byte pages */ } region; }; @@ -147,14 +138,18 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, return err; } -/* - * nfp_resource_acquire() - Acquire a resource handle - * @cpp: NFP CPP handle - * @name: Name of the resource +/** + * Acquire a resource handle + * + * Note: This function locks the acquired resource. * - * NOTE: This function locks the acquired resource + * @param cpp + * NFP CPP handle + * @param name + * Name of the resource * - * Return: NFP Resource handle, or NULL + * @return + * NFP Resource handle, or NULL */ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, @@ -183,7 +178,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, } wait.tv_sec = 0; - wait.tv_nsec = 1000000; + wait.tv_nsec = 1000000; /* 1ms */ for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); @@ -194,7 +189,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, goto err_free; } - if (count++ > 1000) { + if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); err = -EBUSY; goto err_free; @@ -213,11 +208,13 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_resource_release() - Release a NFP Resource handle - * @res: NFP Resource handle +/** + * Release a NFP Resource handle * - * NOTE: This function implicitly unlocks the resource handle + * NOTE: This function implicitly unlocks the resource handle. + * + * @param res + * NFP Resource handle */ void nfp_resource_release(struct nfp_resource *res) @@ -227,11 +224,14 @@ nfp_resource_release(struct nfp_resource *res) free(res); } -/* - * nfp_resource_cpp_id() - Return the cpp_id of a resource handle - * @res: NFP Resource handle +/** + * Return the cpp_id of a resource handle + * + * @param res + * NFP Resource handle * - * Return: NFP CPP ID + * @return + * NFP CPP ID */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res) @@ -239,11 +239,14 @@ nfp_resource_cpp_id(const struct nfp_resource *res) return res->cpp_id; } -/* - * nfp_resource_name() - Return the name of a resource handle - * @res: NFP Resource handle +/** + * Return the name of a resource handle * - * Return: const char pointer to the name of the resource + * @param res + * NFP Resource handle + * + * @return + * Const char pointer to the name of the resource */ const char * nfp_resource_name(const struct nfp_resource *res) @@ -251,11 +254,14 @@ nfp_resource_name(const struct nfp_resource *res) return res->name; } -/* - * nfp_resource_address() - Return the address of a resource handle - * @res: NFP Resource handle +/** + * Return the address of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Address of the resource + * @return + * Address of the resource */ uint64_t nfp_resource_address(const struct nfp_resource *res) @@ -263,11 +269,14 @@ nfp_resource_address(const struct nfp_resource *res) return res->addr; } -/* - * nfp_resource_size() - Return the size in bytes of a resource handle - * @res: NFP Resource handle +/** + * Return the size in bytes of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Size of the resource in bytes + * @return + * Size of the resource in bytes */ uint64_t nfp_resource_size(const struct nfp_resource *res) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 009b7359a4..4236950caf 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -8,43 +8,27 @@ #include "nfp_cpp.h" +/* Netronone Flow Firmware Table */ #define NFP_RESOURCE_NFP_NFFW "nfp.nffw" + +/* NFP Hardware Info Database */ #define NFP_RESOURCE_NFP_HWINFO "nfp.info" + +/* Service Processor */ #define NFP_RESOURCE_NSP "nfp.sp" -/** - * Opaque handle to a NFP Resource - */ +/* Opaque handle to a NFP Resource */ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, const char *name); -/** - * Release a NFP Resource, and free the handle - * @param[in] res NFP Resource handle - */ void nfp_resource_release(struct nfp_resource *res); -/** - * Return the CPP ID of a NFP Resource - * @param[in] res NFP Resource handle - * @return CPP ID of the NFP Resource - */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res); -/** - * Return the name of a NFP Resource - * @param[in] res NFP Resource handle - * @return Name of the NFP Resource - */ const char *nfp_resource_name(const struct nfp_resource *res); -/** - * Return the target address of a NFP Resource - * @param[in] res NFP Resource handle - * @return Address of the NFP Resource - */ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index d15a920752..0e6c0f9fe1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -162,11 +162,14 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_rtsym_count() - Get the number of RTSYM descriptors - * @rtbl: NFP RTsym table +/** + * Get the number of RTSYM descriptors + * + * @param rtbl + * NFP RTSYM table * - * Return: Number of RTSYM descriptors + * @return + * Number of RTSYM descriptors */ int nfp_rtsym_count(struct nfp_rtsym_table *rtbl) @@ -177,12 +180,16 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) return rtbl->num; } -/* - * nfp_rtsym_get() - Get the Nth RTSYM descriptor - * @rtbl: NFP RTsym table - * @idx: Index (0-based) of the RTSYM descriptor +/** + * Get the Nth RTSYM descriptor + * + * @param rtbl + * NFP RTSYM table + * @param idx + * Index (0-based) of the RTSYM descriptor * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_get(struct nfp_rtsym_table *rtbl, @@ -197,12 +204,16 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, return &rtbl->symtab[idx]; } -/* - * nfp_rtsym_lookup() - Return the RTSYM descriptor for a symbol name - * @rtbl: NFP RTsym table - * @name: Symbol name +/** + * Return the RTSYM descriptor for a symbol name + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, @@ -227,7 +238,8 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_NONE: PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; - case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ + case NFP_RTSYM_TYPE_OBJECT: + /* FALLTHROUGH */ case NFP_RTSYM_TYPE_FUNCTION: return sym->size; case NFP_RTSYM_TYPE_ABS: @@ -327,17 +339,22 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } -/* - * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol - * @rtbl: NFP RTsym table - * @name: Symbol name - * @error: Pointer to error code (optional) +/** + * Read a simple unsigned scalar value from symbol * * Lookup a symbol, map, read it and return it's value. Value of the symbol * will be interpreted as a simple little-endian unsigned value. Symbol can * be 4 or 8 bytes in size. * - * Return: value read, on error sets the error and returns ~0ULL. + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param error + * Pointer to error code (optional) + * + * @return + * Value read, on error sets the error and returns ~0ULL. */ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index e7295258b3..ff1facbd17 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -31,12 +31,12 @@ * of "sram" symbols for backward compatibility, which are viewed as global. */ struct nfp_rtsym { - const char *name; - uint64_t addr; - uint64_t size; - int type; - int target; - int domain; + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + int type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ }; struct nfp_rtsym_table; diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 611848e233..540b242a43 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -767,7 +767,7 @@ nfp_encode_basic(uint64_t *addr, /* * Make sure we compare against isldN values by clearing the * LSB. This is what the silicon does. - **/ + */ isld[0] &= ~1; isld[1] &= ~1; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 07/27] net/nfp: standard the comment style 2023-09-15 9:15 ` [PATCH v3 07/27] net/nfp: standard the comment style Chaoyong He @ 2023-09-15 13:44 ` Ferruh Yigit 2023-09-18 1:28 ` Chaoyong He 2023-09-18 2:08 ` Chaoyong He 0 siblings, 2 replies; 159+ messages in thread From: Ferruh Yigit @ 2023-09-15 13:44 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund On 9/15/2023 10:15 AM, Chaoyong He wrote: > Follow the DPDK coding style, use the kdoc comment style. > Also add some comment to help understand logic. > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> <...> > > -/* > - * Set the model id > - * > - * @param cpp NFP CPP operations structure > - * @param model Model ID > - */ > void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); > As I see some comments are removed in this patch, there is no enforced comment style for internal functions, for API doxygen comments must provided. Of course consistency matters, but if comments are removed because of the syntax, I think better option to keep them with their own syntax. ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v3 07/27] net/nfp: standard the comment style 2023-09-15 13:44 ` Ferruh Yigit @ 2023-09-18 1:28 ` Chaoyong He 2023-09-18 2:08 ` Chaoyong He 1 sibling, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 1:28 UTC (permalink / raw) To: Ferruh Yigit, dev; +Cc: oss-drivers > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > Follow the DPDK coding style, use the kdoc comment style. > > Also add some comment to help understand logic. > > > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> > > <...> > > > > > -/* > > - * Set the model id > > - * > > - * @param cpp NFP CPP operations structure > > - * @param model Model ID > > - */ > > void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); > > > > As I see some comments are removed in this patch, there is no enforced > comment style for internal functions, for API doxygen comments must > provided. > > Of course consistency matters, but if comments are removed because of the > syntax, I think better option to keep them with their own syntax. Sorry for that, we may be missing some when rebase the code, we will check and add them. Thanks. ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v3 07/27] net/nfp: standard the comment style 2023-09-15 13:44 ` Ferruh Yigit 2023-09-18 1:28 ` Chaoyong He @ 2023-09-18 2:08 ` Chaoyong He 1 sibling, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:08 UTC (permalink / raw) To: Ferruh Yigit, dev; +Cc: oss-drivers > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > Follow the DPDK coding style, use the kdoc comment style. > > Also add some comment to help understand logic. > > > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> > > <...> > > > > > -/* > > - * Set the model id > > - * > > - * @param cpp NFP CPP operations structure > > - * @param model Model ID > > - */ > > void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); > > > > As I see some comments are removed in this patch, there is no enforced > comment style for internal functions, for API doxygen comments must > provided. > > Of course consistency matters, but if comments are removed because of the > syntax, I think better option to keep them with their own syntax. Oh, I understand what you mean now. We are not removing it, we just keep the comment of functions in the place where it was defined (the implement file). I will make it clear in the commit message in the next version, thanks. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 08/27] net/nfp: using the DPDK memory management API 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (6 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 07/27] net/nfp: standard the comment style Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 13:45 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 09/27] net/nfp: standard the blank character Chaoyong He ` (20 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Revise the logic, using the DPDK memory management API to replace the malloc()/free(). Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_mip.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_mutex.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +++----- drivers/net/nfp/nfpcore/nfp_nsp.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +++----- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 19 ++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 10 ++++------ 11 files changed, 39 insertions(+), 48 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 77dab864f3..37895e8355 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -225,7 +225,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); + rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); rte_free(app_fw_flower); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e3ff3d8087..2e43055fd5 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -47,7 +47,7 @@ nfp_net_pf_read_mac(struct nfp_app_fw_nic *app_fw_nic, int port) rte_ether_addr_copy(&nfp_eth_table->ports[port].mac_addr, &hw->mac_addr); - free(nfp_eth_table); + rte_free(nfp_eth_table); return 0; } @@ -312,7 +312,7 @@ nfp_net_close(struct rte_eth_dev *dev) PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); nfp_cpp_area_free(pf_dev->hwqueues_area); - free(pf_dev->hwinfo); + rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); rte_free(app_fw_nic); @@ -1047,9 +1047,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) sym_tbl_cleanup: free(sym_tbl); eth_table_cleanup: - free(nfp_eth_table); + rte_free(nfp_eth_table); hwinfo_cleanup: - free(hwinfo); + rte_free(hwinfo); cpp_cleanup: nfp_cpp_free(cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 0e8372576e..37906c6f35 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -866,7 +866,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, if (ops == NULL || ops->init == NULL) return NULL; - cpp = calloc(1, sizeof(*cpp)); + cpp = rte_zmalloc(NULL, sizeof(*cpp), 0); if (cpp == NULL) return NULL; @@ -876,7 +876,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, if (cpp->op->init) { err = cpp->op->init(cpp, dev); if (err < 0) { - free(cpp); + rte_free(cpp); return NULL; } } @@ -891,7 +891,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, err = nfp_xpb_readl(cpp, xpbaddr, (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { - free(cpp); + rte_free(cpp); return NULL; } } @@ -900,7 +900,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); - free(cpp); + rte_free(cpp); return NULL; } @@ -922,7 +922,7 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->serial_len != 0) free(cpp->serial); - free(cpp); + rte_free(cpp); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index f5579ab60f..7abf9c7700 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -109,7 +109,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - db = malloc(*cpp_size + 1); + db = rte_zmalloc(NULL, *cpp_size + 1, 0); if (db == NULL) return NULL; @@ -134,7 +134,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, return (void *)db; exit_free: - free(db); + rte_free(db); return NULL; } @@ -175,7 +175,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) err = nfp_hwinfo_db_validate(db, hwdb_size); if (err != 0) { - free(db); + rte_free(db); return NULL; } return db; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0892c99e96..3c59582846 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -104,14 +104,14 @@ nfp_mip_open(struct nfp_cpp *cpp) int err; struct nfp_mip *mip; - mip = malloc(sizeof(*mip)); + mip = rte_zmalloc(NULL, sizeof(*mip), 0); if (mip == NULL) return NULL; err = nfp_mip_read_resource(cpp, mip); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to read MIP resource"); - free(mip); + rte_free(mip); return NULL; } @@ -123,7 +123,7 @@ nfp_mip_open(struct nfp_cpp *cpp) void nfp_mip_close(struct nfp_mip *mip) { - free(mip); + rte_free(mip); } const char * diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 404d4fa938..5392924cf0 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -163,7 +163,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, if (tmp != key) return NULL; - mutex = calloc(sizeof(*mutex), 1); + mutex = rte_zmalloc(NULL, sizeof(*mutex), 0); if (mutex == NULL) return NULL; @@ -209,7 +209,7 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) if (mutex->cpp && mutex == mutex->cpp->mutex_cache) mutex->cpp->mutex_cache = mutex->next; - free(mutex); + rte_free(mutex); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 5f004e3b21..038f19c261 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -129,12 +129,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) struct nfp_nffw_info *state; struct nfp_nffw_info_data *fwinf; - state = malloc(sizeof(*state)); + state = rte_zmalloc(NULL, sizeof(*state), 0); if (state == NULL) return NULL; - memset(state, 0, sizeof(*state)); - state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); if (state->res == NULL) { PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); @@ -167,7 +165,7 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err_release: nfp_resource_release(state->res); err_free: - free(state); + rte_free(state); return NULL; } @@ -181,7 +179,7 @@ void nfp_nffw_info_close(struct nfp_nffw_info *state) { nfp_resource_release(state->res); - free(state); + rte_free(state); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 039e4729bd..dd2d19936d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -128,12 +128,12 @@ nfp_nsp_open(struct nfp_cpp *cpp) return NULL; } - state = malloc(sizeof(*state)); + state = rte_zmalloc(NULL, sizeof(*state), 0); if (state == NULL) { nfp_resource_release(res); return NULL; } - memset(state, 0, sizeof(*state)); + state->cpp = cpp; state->res = res; @@ -157,7 +157,7 @@ void nfp_nsp_close(struct nfp_nsp *state) { nfp_resource_release(state->res); - free(state); + rte_free(state); } uint16_t diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 3081e22dad..54e1e2215d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -33,22 +33,20 @@ __nfp_nsp_identify(struct nfp_nsp *nsp) if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; - ni = malloc(sizeof(*ni)); + ni = rte_zmalloc(NULL, sizeof(*ni), 0); if (ni == NULL) return NULL; - memset(ni, 0, sizeof(*ni)); ret = nfp_nsp_read_identify(nsp, ni, sizeof(*ni)); if (ret < 0) { PMD_DRV_LOG(ERR, "reading bsp version failed %d", ret); goto exit_free; } - nspi = malloc(sizeof(*nspi)); + nspi = rte_zmalloc(NULL, sizeof(*nspi), 0); if (nspi == NULL) goto exit_free; - memset(nspi, 0, sizeof(*nspi)); memcpy(nspi->version, ni->version, sizeof(nspi->version)); nspi->version[sizeof(nspi->version) - 1] = '\0'; nspi->flags = ni->flags; @@ -61,7 +59,7 @@ __nfp_nsp_identify(struct nfp_nsp *nsp) nspi->sensor_mask = rte_le_to_cpu_64(ni->sensor_mask); exit_free: - free(ni); + rte_free(ni); return nspi; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index cb090d2a47..a56ea4e068 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -253,11 +253,10 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; const struct rte_ether_addr *mac; - entries = malloc(NSP_ETH_TABLE_SIZE); + entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) return NULL; - memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); @@ -287,11 +286,10 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } table_sz = sizeof(*table) + sizeof(struct nfp_eth_table_port) * cnt; - table = malloc(table_sz); + table = rte_zmalloc(NULL, table_sz, 0); if (table == NULL) goto err; - memset(table, 0, table_sz); table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; @@ -305,12 +303,12 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); - free(entries); + rte_free(entries); return table; err: - free(entries); + rte_free(entries); return NULL; } @@ -349,14 +347,13 @@ nfp_eth_config_start(struct nfp_cpp *cpp, struct nfp_nsp *nsp; union eth_table_entry *entries; - entries = malloc(NSP_ETH_TABLE_SIZE); + entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) return NULL; - memset(entries, 0, NSP_ETH_TABLE_SIZE); nsp = nfp_nsp_open(cpp); if (nsp == NULL) { - free(entries); + rte_free(entries); return nsp; } @@ -376,7 +373,7 @@ nfp_eth_config_start(struct nfp_cpp *cpp, err: nfp_nsp_close(nsp); - free(entries); + rte_free(entries); return NULL; } @@ -388,7 +385,7 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) nfp_nsp_config_set_modified(nsp, 0); nfp_nsp_config_clear_state(nsp); nfp_nsp_close(nsp); - free(entries); + rte_free(entries); } /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index bdebf5c3aa..8ba3784f8a 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -161,19 +161,17 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; struct nfp_cpp_mutex *dev_mutex; - res = malloc(sizeof(*res)); + res = rte_zmalloc(NULL, sizeof(*res), 0); if (res == NULL) return NULL; - memset(res, 0, sizeof(*res)); - strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - free(res); + rte_free(res); return NULL; } @@ -204,7 +202,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err_free: nfp_cpp_mutex_free(dev_mutex); - free(res); + rte_free(res); return NULL; } @@ -221,7 +219,7 @@ nfp_resource_release(struct nfp_resource *res) { nfp_cpp_mutex_unlock(res->mutex); nfp_cpp_mutex_free(res->mutex); - free(res); + rte_free(res); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 08/27] net/nfp: using the DPDK memory management API 2023-09-15 9:15 ` [PATCH v3 08/27] net/nfp: using the DPDK memory management API Chaoyong He @ 2023-09-15 13:45 ` Ferruh Yigit 2023-09-18 1:29 ` Chaoyong He 0 siblings, 1 reply; 159+ messages in thread From: Ferruh Yigit @ 2023-09-15 13:45 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund, Burakov, Anatoly On 9/15/2023 10:15 AM, Chaoyong He wrote: > Revise the logic, using the DPDK memory management API to replace the > malloc()/free(). > DPDK memory management APIs are required for datapath, where it matters from which socket it is allocated, it is accessed a lot (datapath), or it is shared between primary & seconday processes. But memory for the control path come from regular heap, and perhaps that is even better as it doesn't fragment the DPDK memory space, @Anatoly can comment better on it. Briefly, if there is no reason to the otherwise, I suggest keep using malloc()/free(). ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v3 08/27] net/nfp: using the DPDK memory management API 2023-09-15 13:45 ` Ferruh Yigit @ 2023-09-18 1:29 ` Chaoyong He 0 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 1:29 UTC (permalink / raw) To: Ferruh Yigit, dev; +Cc: oss-drivers, Burakov, Anatoly > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > Revise the logic, using the DPDK memory management API to replace the > > malloc()/free(). > > > > DPDK memory management APIs are required for datapath, where it matters > from which socket it is allocated, it is accessed a lot (datapath), or it is shared > between primary & seconday processes. > > But memory for the control path come from regular heap, and perhaps that is > even better as it doesn't fragment the DPDK memory space, @Anatoly can > comment better on it. > > > Briefly, if there is no reason to the otherwise, I suggest keep using > malloc()/free(). Thanks to make it clear, I will drop these modifications in the next version. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 09/27] net/nfp: standard the blank character 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (7 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 08/27] net/nfp: using the DPDK memory management API Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 10/27] net/nfp: unify the guide line of header file Chaoyong He ` (19 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Use space character to align instead of TAB character. There should one blank line to split the block of logic, no more no less. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 18 +-- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 17 ++- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 - drivers/net/nfp/nfpcore/nfp_crc.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.h | 45 ++++--- drivers/net/nfp/nfpcore/nfp_mip.c | 9 +- drivers/net/nfp/nfpcore/nfp_mip.h | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 17 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 3 + drivers/net/nfp/nfpcore/nfp_nsp.h | 105 ++++++++-------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 132 ++++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 18 +-- drivers/net/nfp/nfpcore/nfp_rtsym.c | 16 +-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 1 + 18 files changed, 206 insertions(+), 195 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index 7750a0218e..efaa87c0e5 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -15,8 +15,8 @@ #define NFP_CPP_TARGET_PCIE 9 #define NFP_CPP_TARGET_ARM 10 #define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ #define NFP_CPP_TARGET_CT_XPB 14 #define NFP_CPP_TARGET_LOCAL_SCRATCH 15 #define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 82189e9910..92cae2557a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -80,16 +80,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_acquire)(struct nfp_cpp_area *area); + /* * Release resources for a NFP CPP area * Serialized */ void (*area_release)(struct nfp_cpp_area *area); + /* * Return a void IO pointer to a NFP CPP area * NOTE: This is _not_ serialized */ - void *(*area_iomem)(struct nfp_cpp_area *area); /* @@ -280,7 +281,7 @@ void nfp_cpp_free(struct nfp_cpp *cpp); * @return * true if model is in the NFP6000 family, false otherwise. */ -#define NFP_CPP_MODEL_IS_6000(model) \ +#define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) @@ -290,11 +291,11 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * NFP Interface types - logical interface for this CPP connection 4 bits are * reserved for interface type. */ -#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 -#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 -#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 -#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 -#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 +#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 +#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 +#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 +#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 +#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 /** * Construct a 16-bit NFP Interface ID @@ -316,7 +317,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * @return * Interface ID */ -#define NFP_CPP_INTERFACE(type, unit, channel) \ +#define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) @@ -354,7 +355,6 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) - uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 7e94bfb611..28a6278497 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -37,7 +37,7 @@ #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" -#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) +#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -93,7 +93,7 @@ struct nfp_bar { char *iomem; /**< mapped IO memory */ }; -#define BUSDEV_SZ 13 +#define BUSDEV_SZ 13 struct nfp_pcie_user { struct nfp_bar bar[NFP_BAR_MAX]; @@ -163,7 +163,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); @@ -171,7 +170,6 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); @@ -179,7 +177,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 21; } @@ -278,6 +275,7 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; bar->barcfg = 0; @@ -310,6 +308,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; if (bar->lock == 0) { @@ -317,6 +316,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) return bar; } } + return NULL; } @@ -346,7 +346,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } /* Generic CPP bus access interface. */ - struct nfp6000_area_priv { struct nfp_bar *bar; uint32_t bar_offset; @@ -443,6 +442,7 @@ static void nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + priv->bar->lock = 0; priv->bar = NULL; priv->iomem = NULL; @@ -478,7 +478,6 @@ nfp6000_area_read(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.read; - if (width <= 0) return -EINVAL; @@ -548,7 +547,6 @@ nfp6000_area_write(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.write; - if (width <= 0) return -EINVAL; @@ -718,6 +716,7 @@ nfp6000_set_barsz(struct rte_pci_device *dev, i++; desc->barsz = i; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 37906c6f35..bb6eab36e2 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -433,7 +433,6 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) { if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) { PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; @@ -862,7 +861,6 @@ nfp_cpp_alloc(struct rte_pci_device *dev, const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); - if (ops == NULL || ops->init == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 68f27f8c68..986c52711d 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -15,11 +15,13 @@ nfp_crc32_be_generic(uint32_t crc, uint32_t polynomial) { uint32_t i; + while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); } + return crc; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 7abf9c7700..cee37210b0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -54,6 +54,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, return -EINVAL; } } + return 0; } @@ -178,6 +179,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) rte_free(db); return NULL; } + return db; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 424db8035d..37427bb6c8 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -8,33 +8,31 @@ #include <inttypes.h> -#define HWINFO_SIZE_MIN 0x100 +#define HWINFO_SIZE_MIN 0x100 /* * The Hardware Info Table defines the properties of the system. * * HWInfo v1 Table (fixed size) * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value - * table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * HWInfo v2 Table (variable size) * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding - * CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * If the HWInfo table is in the process of being updated, the low bit of * version will be set. @@ -47,17 +45,16 @@ * * All keys are guaranteed to be unique. * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value * ... * * HWInfo v2 Key/Value Table * ------------------------- * * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * * Unsorted. * * Note: Only the HwInfo v2 Table be supported now. @@ -65,7 +62,7 @@ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) #define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) struct nfp_hwinfo { uint8_t start[0]; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 3c59582846..f6f07ac739 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -11,9 +11,9 @@ #include "nfp_mip.h" #include "nfp_nffw.h" -#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -#define NFP_MIP_VERSION rte_cpu_to_le_32(1) -#define NFP_MIP_MAX_OFFSET (256 * 1024) +#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ +#define NFP_MIP_VERSION rte_cpu_to_le_32(1) +#define NFP_MIP_MAX_OFFSET (256 * 1024) struct nfp_mip { uint32_t signature; @@ -49,11 +49,13 @@ nfp_mip_try_read(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } + if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } + if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); @@ -82,6 +84,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); + exit_close_nffw: nfp_nffw_info_close(nffw_info); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 980abc2517..16824a6769 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -18,4 +18,5 @@ void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); + #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 5392924cf0..61c491e07e 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -85,7 +85,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, { int err; uint32_t model = nfp_cpp_model(cpp); - uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -134,7 +134,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint32_t tmp; struct nfp_cpp_mutex *mutex; uint32_t model = nfp_cpp_model(cpp); - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -231,12 +231,15 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) /* If err != -EBUSY, then the lock was damaged */ if (err < 0 && err != -EBUSY) return err; + if (time(NULL) >= warn_at) { PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } + sched_yield(); } + return 0; } @@ -257,8 +260,8 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) uint32_t value; struct nfp_cpp *cpp = mutex->cpp; uint16_t interface = nfp_cpp_interface(cpp); - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -314,9 +317,9 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) uint32_t tmp; uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 038f19c261..0ae7d9328c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -61,10 +61,10 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index dd2d19936d..9bb344aa5f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -290,6 +290,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_cpp_readq(cpp, nsp_cpp, nsp_command, &ret_val); if (err < 0) return err; + ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); @@ -354,6 +355,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, if (err < 0) return err; } + /* Zero out remaining part of the buffer */ if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); @@ -400,6 +402,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 0fcb21e99c..ee58bf33b8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -10,73 +10,72 @@ #include "nfp_nsp.h" #define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) + (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) #define __bf_shf(x) (__builtin_ffsll(x) - 1) -#define FIELD_GET(_mask, _reg) \ +#define FIELD_GET(_mask, _reg) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ })) -#define FIELD_FIT(_mask, _val) \ +#define FIELD_FIT(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ })) -#define FIELD_PREP(_mask, _val) \ +#define FIELD_PREP(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ })) /* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_START RTE_BIT64(0) /* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) -#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER 0x18 -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) +#define NSP_CODE_MAJOR GENMASK(15, 12) +#define NSP_CODE_MINOR GENMASK(11, 0) enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ }; static const struct { @@ -123,13 +122,13 @@ nfp_nsp_has_mac_reinit(struct nfp_nsp *state) } enum nfp_eth_interface { - NFP_INTERFACE_NONE = 0, - NFP_INTERFACE_SFP = 1, - NFP_INTERFACE_SFPP = 10, - NFP_INTERFACE_SFP28 = 28, - NFP_INTERFACE_QSFP = 40, - NFP_INTERFACE_CXP = 100, - NFP_INTERFACE_QSFP28 = 112, + NFP_INTERFACE_NONE = 0, + NFP_INTERFACE_SFP = 1, + NFP_INTERFACE_SFPP = 10, + NFP_INTERFACE_SFP28 = 28, + NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_CXP = 100, + NFP_INTERFACE_QSFP28 = 112, }; enum nfp_eth_media { @@ -153,10 +152,10 @@ enum nfp_eth_fec { NFP_FEC_DISABLED_BIT, }; -#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) -#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) -#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) -#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) +#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) +#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) +#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) +#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) /* ETH table information */ struct nfp_eth_table { diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 54e1e2215d..08f12f862c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -105,5 +105,6 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, default: return -EINVAL; } + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index a56ea4e068..c01802a516 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,70 +11,68 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define NSP_ETH_NBI_PORT_COUNT 24 -#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) -#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ - sizeof(union eth_table_entry)) - -#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) -#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) -#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) -#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) -#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) -#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) - -#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) - -#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) -#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) -#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) -#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) -#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) -#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) -#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) - -#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) -#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) -#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) -#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) -#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) +#define NSP_ETH_NBI_PORT_COUNT 24 +#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) +#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * sizeof(union eth_table_entry)) + +#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) +#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) +#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) +#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) +#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) +#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) + +#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) + +#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) +#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) +#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) +#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) +#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) +#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) +#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) + +#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) +#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) +#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) +#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) +#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) /* Which connector port. */ -#define PORT_TP 0x00 -#define PORT_AUI 0x01 -#define PORT_MII 0x02 -#define PORT_FIBRE 0x03 -#define PORT_BNC 0x04 -#define PORT_DA 0x05 -#define PORT_NONE 0xef -#define PORT_OTHER 0xff - -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 +#define PORT_TP 0x00 +#define PORT_AUI 0x01 +#define PORT_MII 0x02 +#define PORT_FIBRE 0x03 +#define PORT_BNC 0x04 +#define PORT_DA 0x05 +#define PORT_NONE 0xef +#define PORT_OTHER 0xff + +#define SPEED_10 10 +#define SPEED_100 100 +#define SPEED_1000 1000 +#define SPEED_2500 2500 +#define SPEED_5000 5000 +#define SPEED_10000 10000 +#define SPEED_14000 14000 +#define SPEED_20000 20000 +#define SPEED_25000 25000 +#define SPEED_40000 40000 +#define SPEED_50000 50000 +#define SPEED_56000 56000 +#define SPEED_100000 100000 enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW }; @@ -102,12 +100,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, 0, }, + { RATE_10M, SPEED_10, }, + { RATE_100M, SPEED_100, }, + { RATE_1G, SPEED_1000, }, + { RATE_10G, SPEED_10000, }, + { RATE_25G, SPEED_25000, }, }; static uint32_t @@ -212,10 +210,12 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) if (table->ports[i].label_port != table->ports[j].label_port) continue; + table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; + if (table->ports[i].label_subport == table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", @@ -553,11 +553,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, return 0; } -#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ - (__extension__ ({ \ - typeof(mask) _x = (mask); \ +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ + (__extension__ ({ \ + typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 8ba3784f8a..e7e232eb4e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -13,14 +13,14 @@ #include "nfp_resource.h" #include "nfp_crc.h" -#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL +#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU +#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL /* NFP Resource Table self-identifier */ -#define NFP_RESOURCE_TBL_NAME "nfp.res" -#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ +#define NFP_RESOURCE_TBL_NAME "nfp.res" +#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ -#define NFP_RESOURCE_ENTRY_NAME_SZ 8 +#define NFP_RESOURCE_ENTRY_NAME_SZ 8 /* Resource table entry */ struct nfp_resource_entry { @@ -42,9 +42,9 @@ struct nfp_resource_entry { } region; }; -#define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ - sizeof(struct nfp_resource_entry)) +#define NFP_RESOURCE_TBL_SIZE 4096 +#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ + sizeof(struct nfp_resource_entry)) struct nfp_resource { char name[NFP_RESOURCE_ENTRY_NAME_SZ + 1]; @@ -75,6 +75,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Grabbing device lock not supported"); return -EOPNOTSUPP; } + key = nfp_crc32_posix(name_pad, NFP_RESOURCE_ENTRY_NAME_SZ); for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { @@ -96,6 +97,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 0e6c0f9fe1..37811ceaeb 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -17,18 +17,18 @@ #include "nfp6000/nfp6000.h" /* These need to match the linker */ -#define SYM_TGT_LMEM 0 -#define SYM_TGT_EMU_CACHE 0x17 +#define SYM_TGT_LMEM 0 +#define SYM_TGT_EMU_CACHE 0x17 struct nfp_rtsym_entry { - uint8_t type; - uint8_t target; - uint8_t island; - uint8_t addr_hi; + uint8_t type; + uint8_t target; + uint8_t island; + uint8_t addr_hi; uint32_t addr_lo; uint16_t name; - uint8_t menum; - uint8_t size_hi; + uint8_t menum; + uint8_t size_hi; uint32_t size_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index ff1facbd17..de1966f04b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -57,4 +57,5 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); + #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 10/27] net/nfp: unify the guide line of header file 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (8 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 09/27] net/nfp: standard the blank character Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 11/27] net/nfp: rename some parameter and variable Chaoyong He ` (18 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Unify the guide line of header file, we choose '__FOO_BAR_H__' style. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 2 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 +- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_resource.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- drivers/net/nfp/nfpcore/nfp_target.h | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 92cae2557a..ceb4d56a08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -442,4 +442,4 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); -#endif /* !__NFP_CPP_H__ */ +#endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 37427bb6c8..543562779a 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -81,4 +81,4 @@ struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup); -#endif +#endif /* __NFP_HWINFO_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 16824a6769..371c635b97 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -19,4 +19,4 @@ void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); -#endif +#endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index e032b6cce7..f84be463c4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -75,4 +75,4 @@ struct nfp_nffw_info { struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); -#endif +#endif /* __NFP_NFFW_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index ee58bf33b8..7bf584dcd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NSP_NSP_H -#define NSP_NSP_H 1 +#ifndef __NSP_NSP_H__ +#define __NSP_NSP_H__ #include "nfp_cpp.h" #include "nfp_nsp.h" @@ -260,4 +260,4 @@ enum nfp_nsp_sensor_id { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val); -#endif +#endif /* __NSP_NSP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 4236950caf..18196d273c 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NFP_RESOURCE_H -#define NFP_RESOURCE_H +#ifndef __NFP_RESOURCE_H__ +#define __NFP_RESOURCE_H__ #include "nfp_cpp.h" @@ -33,4 +33,4 @@ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); -#endif /* NFP_RESOURCE_H */ +#endif /* __NFP_RESOURCE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index de1966f04b..fdde1eb75b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -58,4 +58,4 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -#endif +#endif /* __NFP_RTSYM_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 195e599d31..2a2f083914 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -3,7 +3,7 @@ * All rights reserved. */ -#ifndef NFP_TARGET_H -#define NFP_TARGET_H +#ifndef __NFP_TARGET_H__ +#define __NFP_TARGET_H__ -#endif /* NFP_TARGET_H */ +#endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 11/27] net/nfp: rename some parameter and variable 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (9 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 10/27] net/nfp: unify the guide line of header file Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 12/27] net/nfp: refact the hwinfo module Chaoyong He ` (17 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Rename some parameter and variable to make the logic easier to understand. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 10 ++--- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 42 ++++++++--------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 52 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 20 ++++----- drivers/net/nfp/nfpcore/nfp_nffw.h | 4 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 8 ++-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 20 ++++----- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index ceb4d56a08..be7ae1d919 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -247,7 +247,7 @@ void *nfp_cpp_priv(struct nfp_cpp *cpp); void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); -uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); +uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, @@ -381,10 +381,10 @@ uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *buffer, size_t length); + void *address, size_t length); int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *buffer, size_t length); + const void *address, size_t length); void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); @@ -393,10 +393,10 @@ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, void *kernel_vaddr, size_t length); + uint64_t address, void *buf, size_t length); int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, const void *kernel_vaddr, size_t length); + uint64_t address, const void *buf, size_t length); int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 28a6278497..db15411eb2 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -118,9 +118,9 @@ static int nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, uint64_t *bar_base, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -129,7 +129,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (tgt >= 16) + if (target >= 16) return -EINVAL; switch (width) { @@ -149,15 +149,15 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; } - if (act != NFP_CPP_ACTION_RW && act != 0) { + if (action != NFP_CPP_ACTION_RW && action != 0) { /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(action); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -170,8 +170,8 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -221,9 +221,9 @@ nfp_bar_write(struct nfp_pcie_user *nfp, static int nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -232,8 +232,8 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, uint32_t newcfg; uint64_t newbase; - err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + err = nfp_compute_bar(bar, &newcfg, &newbase, target, action, + token, offset, size, width); if (err != 0) return err; @@ -457,15 +457,15 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, - void *kernel_vaddr, + void *address, uint32_t offset, size_t length) { size_t n; int width; bool is_64; - uint32_t *wrptr32 = kernel_vaddr; - uint64_t *wrptr64 = kernel_vaddr; + uint32_t *wrptr32 = address; + uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; const volatile uint32_t *rdptr32; const volatile uint64_t *rdptr64; @@ -526,7 +526,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, - const void *kernel_vaddr, + const void *address, uint32_t offset, size_t length) { @@ -536,8 +536,8 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; - const uint32_t *rdptr32 = kernel_vaddr; - const uint64_t *rdptr64 = kernel_vaddr; + const uint32_t *rdptr32 = address; + const uint64_t *rdptr64 = address; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index bb6eab36e2..0f68c5d667 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -90,7 +90,7 @@ nfp_cpp_model(struct nfp_cpp *cpp) if (cpp == NULL) return NFP_CPP_MODEL_INVALID; - err = __nfp_cpp_model_autodetect(cpp, &model); + err = nfp_cpp_model_autodetect(cpp, &model); if (err < 0) return err; @@ -484,7 +484,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -498,13 +498,13 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *kernel_vaddr, + void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_read(area, kernel_vaddr, offset, length); + return area->cpp->op->area_read(area, address, offset, length); } /** @@ -514,7 +514,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -528,13 +528,13 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *kernel_vaddr, + const void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_write(area, kernel_vaddr, offset, length); + return area->cpp->op->area_write(area, address, offset, length); } /* @@ -880,14 +880,14 @@ nfp_cpp_alloc(struct rte_pci_device *dev, } if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpbaddr; - size_t tgt; + uint32_t xpb_addr; + size_t target; - for (tgt = 0; tgt < RTE_DIM(cpp->imb_cat_table); tgt++) { + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + (tgt * 4); - err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, + (uint32_t *)&cpp->imb_cat_table[target]); if (err < 0) { rte_free(cpp); return NULL; @@ -950,9 +950,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer for result * @param length * Number of bytes to read @@ -963,20 +963,20 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - void *kernel_vaddr, + uint64_t offset, + void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } - err = nfp_cpp_area_read(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_read(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -989,9 +989,9 @@ nfp_cpp_read(struct nfp_cpp *cpp, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer to read from * @param length * Number of bytes to write @@ -1002,20 +1002,20 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - const void *kernel_vaddr, + uint64_t offset, + const void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; } - err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_write(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -1026,7 +1026,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, +nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { int err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 371c635b97..7fa09ee575 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,6 +17,6 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 61c491e07e..85c33502ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,7 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint32_t model, int *target, uint64_t address) { @@ -87,7 +87,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return err; @@ -152,7 +152,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return NULL; } - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 0ae7d9328c..7811363796 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -31,11 +31,11 @@ nffw_res_flg_init_get(const struct nfp_nffw_info_data *res) return (res->flags[0] >> 0) & 1; } -/* loaded = loaded__mu_da__mip_off_hi<31:31> */ +/* loaded = loaded_mu_da_mip_off_hi<31:31> */ static uint32_t nffw_fwinfo_loaded_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 31) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 31) & 1; } /* mip_cppid = mip_cppid */ @@ -45,18 +45,18 @@ nffw_fwinfo_mip_cppid_get(const struct nffw_fwinfo *fi) return fi->mip_cppid; } -/* loaded = loaded__mu_da__mip_off_hi<8:8> */ +/* loaded = loaded_mu_da_mip_off_hi<8:8> */ static uint32_t nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ +/* mip_offset = (loaded_mu_da_mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { - uint64_t mip_off_hi = fi->loaded__mu_da__mip_off_hi; + uint64_t mip_off_hi = fi->loaded_mu_da_mip_off_hi; return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } @@ -225,7 +225,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) + uint64_t *offset) { struct nffw_fwinfo *fwinfo; @@ -234,7 +234,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, return -EINVAL; *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); - *off = nffw_fwinfo_mip_offset_get(fwinfo); + *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; @@ -246,8 +246,8 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, if (locality_off < 0) return locality_off; - *off &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); - *off |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; + *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); + *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; } return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index f84be463c4..52e25c090a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -38,11 +38,11 @@ /* nfp.nffw meinfo */ struct nffw_meinfo { - uint32_t ctxmask__fwid__meid; + uint32_t ctxmask_fwid_meid; }; struct nffw_fwinfo { - uint32_t loaded__mu_da__mip_off_hi; + uint32_t loaded_mu_da_mip_off_hi; uint32_t mip_cppid; /* 0 means no MIP */ uint32_t mip_offset_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 7bf584dcd0..705574b900 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -231,9 +231,9 @@ struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); -int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); +int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); +int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /* NSP static information */ struct nfp_nsp_identify { @@ -248,7 +248,7 @@ struct nfp_nsp_identify { uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; -struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); +struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp); enum nfp_nsp_sensor_id { NFP_SENSOR_CHIP_TEMPERATURE, diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 08f12f862c..429f639fa2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -24,7 +24,7 @@ struct nsp_identify { }; struct nfp_nsp_identify * -__nfp_nsp_identify(struct nfp_nsp *nsp) +nfp_nsp_identify(struct nfp_nsp *nsp) { int ret; struct nsp_identify *ni; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index c01802a516..fba7a1dc12 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -242,7 +242,7 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) } static struct nfp_eth_table * -__nfp_eth_read_ports(struct nfp_nsp *nsp) +nfp_eth_read_ports_real(struct nfp_nsp *nsp) { int ret; uint32_t i; @@ -333,7 +333,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) if (nsp == NULL) return NULL; - ret = __nfp_eth_read_ports(nsp); + ret = nfp_eth_read_ports_real(nsp); nfp_nsp_close(nsp); return ret; @@ -481,7 +481,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configed) + int configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -504,10 +504,10 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, /* Check if we are already in requested state */ reg = rte_le_to_cpu_64(entries[idx].state); - if (configed != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { + if (configured != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { reg = rte_le_to_cpu_64(entries[idx].control); reg &= ~NSP_ETH_CTRL_CONFIGURED; - reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configed); + reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); nfp_nsp_config_set_modified(nsp, 1); @@ -573,7 +573,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, +nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -593,7 +593,7 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, * 0 or -ERRNO */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, +nfp_eth_set_fec_real(struct nfp_nsp *nsp, enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -627,7 +627,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, if (nsp == NULL) return -EIO; - err = __nfp_eth_set_fec(nsp, mode); + err = nfp_eth_set_fec_real(nsp, mode); if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; @@ -651,7 +651,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, * 0 or -ERRNO */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, +nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed) { enum nfp_eth_rate rate; @@ -679,7 +679,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, +nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 12/27] net/nfp: refact the hwinfo module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (10 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 11/27] net/nfp: rename some parameter and variable Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 13:46 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 13/27] net/nfp: refact the nffw module Chaoyong He ` (16 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Move the definition of data structure and macro into the implement file. Also remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 84 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 71 +---------------------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index cee37210b0..25c2262dfc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -17,17 +17,82 @@ * (ie, in this example, ME 39 has been reserved by boardconfig.) */ -#include <stdio.h> -#include <time.h> +#include "nfp_hwinfo.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" -#include "nfp_hwinfo.h" -#include "nfp_crc.h" -static int +#define HWINFO_SIZE_MIN 0x100 + +/* + * The Hardware Info Table defines the properties of the system. + * + * HWInfo v1 Table (fixed size) + * + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * HWInfo v2 Table (variable size) + * + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * If the HWInfo table is in the process of being updated, the low bit of + * version will be set. + * + * HWInfo v1 Key/Value Table + * ------------------------- + * + * The key/value table is a set of offsets to ASCIIZ strings which have + * been strcmp(3) sorted (yes, please use bsearch(3) on the table). + * + * All keys are guaranteed to be unique. + * + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value + * ... + * + * HWInfo v2 Key/Value Table + * ------------------------- + * + * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' + * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. + */ + +#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) + +struct nfp_hwinfo { + uint8_t start[0]; + + uint32_t version; + uint32_t size; + + /* V2 specific fields */ + uint32_t limit; + uint32_t resv; + + char data[]; +}; + +static bool nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) { return hwinfo->version & NFP_HWINFO_VERSION_UPDATING; @@ -120,7 +185,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, goto exit_free; } - header = (void *)db; + header = (struct nfp_hwinfo *)db; if (nfp_hwinfo_is_updating(header)) goto exit_free; @@ -133,7 +198,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, /* NULL-terminate for safety */ db[*cpp_size] = '\0'; - return (void *)db; + return (struct nfp_hwinfo *)db; + exit_free: rte_free(db); return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 543562779a..c812f10076 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -6,76 +6,9 @@ #ifndef __NFP_HWINFO_H__ #define __NFP_HWINFO_H__ -#include <inttypes.h> +#include "nfp_cpp.h" -#define HWINFO_SIZE_MIN 0x100 - -/* - * The Hardware Info Table defines the properties of the system. - * - * HWInfo v1 Table (fixed size) - * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * HWInfo v2 Table (variable size) - * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * If the HWInfo table is in the process of being updated, the low bit of - * version will be set. - * - * HWInfo v1 Key/Value Table - * ------------------------- - * - * The key/value table is a set of offsets to ASCIIZ strings which have - * been strcmp(3) sorted (yes, please use bsearch(3) on the table). - * - * All keys are guaranteed to be unique. - * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value - * ... - * - * HWInfo v2 Key/Value Table - * ------------------------- - * - * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * Unsorted. - * - * Note: Only the HwInfo v2 Table be supported now. - */ - -#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) - -struct nfp_hwinfo { - uint8_t start[0]; - - uint32_t version; - uint32_t size; - - /* v2 specific fields */ - uint32_t limit; - uint32_t resv; - - char data[]; -}; +struct nfp_hwinfo; struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 12/27] net/nfp: refact the hwinfo module 2023-09-15 9:15 ` [PATCH v3 12/27] net/nfp: refact the hwinfo module Chaoyong He @ 2023-09-15 13:46 ` Ferruh Yigit 2023-09-18 1:39 ` Chaoyong He 0 siblings, 1 reply; 159+ messages in thread From: Ferruh Yigit @ 2023-09-15 13:46 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund On 9/15/2023 10:15 AM, Chaoyong He wrote: > Move the definition of data structure and macro into the implement file. > What is the motivation for this move, I can see same is done in multiple other patches? Header file is still included by .c file, what is the benefit of moving from header to .c file? ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v3 12/27] net/nfp: refact the hwinfo module 2023-09-15 13:46 ` Ferruh Yigit @ 2023-09-18 1:39 ` Chaoyong He 2023-09-18 11:01 ` Ferruh Yigit 0 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-18 1:39 UTC (permalink / raw) To: Ferruh Yigit, dev; +Cc: oss-drivers > -----Original Message----- > From: Ferruh Yigit <ferruh.yigit@amd.com> > Sent: Friday, September 15, 2023 9:46 PM > To: Chaoyong He <chaoyong.he@corigine.com>; dev@dpdk.org > Cc: oss-drivers <oss-drivers@corigine.com>; Niklas Soderlund > <niklas.soderlund@corigine.com> > Subject: Re: [PATCH v3 12/27] net/nfp: refact the hwinfo module > > On 9/15/2023 10:15 AM, Chaoyong He wrote: > > Move the definition of data structure and macro into the implement file. > > > > What is the motivation for this move, I can see same is done in multiple other > patches? > Header file is still included by .c file, what is the benefit of moving from header > to .c file? We try to make the interface between modules as small as possible. We meet some problem when we add new features, too much content in the header files make it difficult to form a identify dependencies among modules. When we try to add a new data field in a structure or add a new data type in one header file, we had to modify many unrelated files just because it includes this header file, it's not good. This is the direct motivation for this move, this will make the development easier. ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 12/27] net/nfp: refact the hwinfo module 2023-09-18 1:39 ` Chaoyong He @ 2023-09-18 11:01 ` Ferruh Yigit 0 siblings, 0 replies; 159+ messages in thread From: Ferruh Yigit @ 2023-09-18 11:01 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers On 9/18/2023 2:39 AM, Chaoyong He wrote: > > >> -----Original Message----- >> From: Ferruh Yigit <ferruh.yigit@amd.com> >> Sent: Friday, September 15, 2023 9:46 PM >> To: Chaoyong He <chaoyong.he@corigine.com>; dev@dpdk.org >> Cc: oss-drivers <oss-drivers@corigine.com>; Niklas Soderlund >> <niklas.soderlund@corigine.com> >> Subject: Re: [PATCH v3 12/27] net/nfp: refact the hwinfo module >> >> On 9/15/2023 10:15 AM, Chaoyong He wrote: >>> Move the definition of data structure and macro into the implement file. >>> >> >> What is the motivation for this move, I can see same is done in multiple other >> patches? >> Header file is still included by .c file, what is the benefit of moving from header >> to .c file? > > We try to make the interface between modules as small as possible. > > We meet some problem when we add new features, too much content in the header files make it difficult to form a identify dependencies among modules. > When we try to add a new data field in a structure or add a new data type in one header file, we had to modify many unrelated files just because it includes this header file, it's not good. > > This is the direct motivation for this move, this will make the development easier.> If you can move a struct or data type to .c file, it means it is not shared so updating it should not cause change anyway. I am not against it, but I didn't get your reasoning. When there are 'nfp_hwinfo.c' and 'nfp_hwinfo.h' files, I think that is reasonable to have "nfp_hwinfo*" macros and structs in the .h file, it looks like you want to separate data structures that are shared and ones that are only used by 'nfp_hwinfo.c' but I am not sure how it helps. Anyway if you know what you are doing, it is OK, I just want to double check if this is done on purpose. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 13/27] net/nfp: refact the nffw module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (11 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 12/27] net/nfp: refact the hwinfo module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 14/27] net/nfp: refact the mip module Chaoyong He ` (15 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Move the definition of data structure and macro into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.h | 4 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 105 +++++++++++++++++++---------- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +----------------- 3 files changed, 72 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 7fa09ee575..dbd9af31ed 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -6,7 +6,7 @@ #ifndef __NFP_MIP_H__ #define __NFP_MIP_H__ -#include "nfp_nffw.h" +#include "nfp_cpp.h" struct nfp_mip; @@ -16,7 +16,5 @@ void nfp_mip_close(struct nfp_mip *mip); const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); -int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 7811363796..585b1103aa 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,12 +3,76 @@ * All rights reserved. */ -#include "../nfp_logs.h" -#include "nfp_cpp.h" #include "nfp_nffw.h" + +#include "../nfp_logs.h" #include "nfp_mip.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" +#include "nfp6000/nfp6000.h" + +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. + * Lower IDs are reserved for target and loader IDs. + */ +#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ +#define NFFW_FWID_BASE 4 + +#define NFFW_FWID_ALL 255 + +/* + * NFFW_INFO_VERSION history: + * 0: This was never actually used (before versioning), but it refers to + * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later + * changed to 200. + * 1: First versioned struct, with + * FWINFO_CNT = 120 + * MEINFO_CNT = 120 + * 2: FWINFO_CNT = 200 + * MEINFO_CNT = 200 + */ +#define NFFW_INFO_VERSION_CURRENT 2 + +/* Enough for all current chip families */ +#define NFFW_MEINFO_CNT_V1 120 +#define NFFW_FWINFO_CNT_V1 120 +#define NFFW_MEINFO_CNT_V2 200 +#define NFFW_FWINFO_CNT_V2 200 + +/* nfp.nffw meinfo */ +struct nffw_meinfo { + uint32_t ctxmask_fwid_meid; +}; + +struct nffw_fwinfo { + uint32_t loaded_mu_da_mip_off_hi; + uint32_t mip_cppid; /**< 0 means no MIP */ + uint32_t mip_offset_lo; +}; + +struct nfp_nffw_info_v1 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; +}; + +struct nfp_nffw_info_v2 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; +}; + +struct nfp_nffw_info_data { + uint32_t flags[2]; + union { + struct nfp_nffw_info_v1 v1; + struct nfp_nffw_info_v2 v2; + } info; +}; + +struct nfp_nffw_info { + struct nfp_cpp *cpp; + struct nfp_resource *res; + + struct nfp_nffw_info_data fwinf; +}; /* * flg_info_version = flags[0]<27:16> @@ -61,32 +125,6 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) - -static int -nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) -{ - int err; - uint32_t mode; - uint32_t addr40; - uint32_t xpbaddr; - uint32_t imbcppat; - - /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; - err = nfp_xpb_readl(cpp, xpbaddr, &imbcppat); - if (err < 0) - return err; - - mode = NFP_IMB_TGTADDRESSMODECFG_MODE_of(imbcppat); - addr40 = !!(imbcppat & NFP_IMB_TGTADDRESSMODECFG_ADDRMODE); - - return nfp_cppat_mu_locality_lsb(mode, addr40); -} - static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) @@ -237,14 +275,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { - int locality_off; - - if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) - return 0; - - locality_off = nfp_mip_mu_locality_lsb(state->cpp); - if (locality_off < 0) - return locality_off; + int locality_off = nfp_cpp_mu_locality_lsb(state->cpp); *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 52e25c090a..fd46009d37 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,71 +8,11 @@ #include "nfp_cpp.h" -/* - * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. - * Lower IDs are reserved for target and loader IDs. - */ -#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ -#define NFFW_FWID_BASE 4 - -#define NFFW_FWID_ALL 255 - -/* - * NFFW_INFO_VERSION history: - * 0: This was never actually used (before versioning), but it refers to - * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later - * changed to 200. - * 1: First versioned struct, with - * FWINFO_CNT = 120 - * MEINFO_CNT = 120 - * 2: FWINFO_CNT = 200 - * MEINFO_CNT = 200 - */ -#define NFFW_INFO_VERSION_CURRENT 2 - -/* Enough for all current chip families */ -#define NFFW_MEINFO_CNT_V1 120 -#define NFFW_FWINFO_CNT_V1 120 -#define NFFW_MEINFO_CNT_V2 200 -#define NFFW_FWINFO_CNT_V2 200 - -/* nfp.nffw meinfo */ -struct nffw_meinfo { - uint32_t ctxmask_fwid_meid; -}; - -struct nffw_fwinfo { - uint32_t loaded_mu_da_mip_off_hi; - uint32_t mip_cppid; /* 0 means no MIP */ - uint32_t mip_offset_lo; -}; - -struct nfp_nffw_info_v1 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; -}; - -struct nfp_nffw_info_v2 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; -}; - -struct nfp_nffw_info_data { - uint32_t flags[2]; - union { - struct nfp_nffw_info_v1 v1; - struct nfp_nffw_info_v2 v2; - } info; -}; - -struct nfp_nffw_info { - struct nfp_cpp *cpp; - struct nfp_resource *res; - - struct nfp_nffw_info_data fwinf; -}; +struct nfp_nffw_info; struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); +int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, + uint64_t *offset); #endif /* __NFP_NFFW_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 14/27] net/nfp: refact the mip module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (12 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 13/27] net/nfp: refact the nffw module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 15/27] net/nfp: refact the rtsym module Chaoyong He ` (14 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f6f07ac739..ec064b08dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -3,12 +3,11 @@ * All rights reserved. */ -#include <stdio.h> +#include "nfp_mip.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_mip.h" #include "nfp_nffw.h" #define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 15/27] net/nfp: refact the rtsym module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (13 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 14/27] net/nfp: refact the mip module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 16/27] net/nfp: refact the resource module Chaoyong He ` (13 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include <stdio.h> +#include "nfp_rtsym.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ 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); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 16/27] net/nfp: refact the resource module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (14 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 15/27] net/nfp: refact the rtsym module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 17/27] net/nfp: refact the target module Chaoyong He ` (12 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_resource.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e7e232eb4e..e4a3a42eea 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -3,15 +3,11 @@ * All rights reserved. */ -#include <stdio.h> -#include <time.h> -#include <endian.h> +#include "nfp_resource.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" #include "nfp6000/nfp6000.h" -#include "nfp_resource.h" -#include "nfp_crc.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL @@ -43,7 +39,7 @@ struct nfp_resource_entry { }; #define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ +#define NFP_RESOURCE_TBL_ENTRIES (NFP_RESOURCE_TBL_SIZE / \ sizeof(struct nfp_resource_entry)) struct nfp_resource { @@ -173,8 +169,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - rte_free(res); - return NULL; + goto err_free; } wait.tv_sec = 0; @@ -186,13 +181,12 @@ nfp_resource_acquire(struct nfp_cpp *cpp, break; if (err != -EBUSY) { PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); - goto err_free; + goto mutex_free; } if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); - err = -EBUSY; - goto err_free; + goto mutex_free; } nanosleep(&wait, NULL); @@ -202,8 +196,9 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return res; -err_free: +mutex_free: nfp_cpp_mutex_free(dev_mutex); +err_free: rte_free(res); return NULL; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 17/27] net/nfp: refact the target module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (15 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 16/27] net/nfp: refact the resource module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 18/27] net/nfp: add a new header file Chaoyong He ` (11 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Move the function declaration into the header file, and sync some logic from kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 -------------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 1 + drivers/net/nfp/nfpcore/nfp_cppcore.c | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 - drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 1 + drivers/net/nfp/nfpcore/nfp_target.c | 7 ++++--- drivers/net/nfp/nfpcore/nfp_target.h | 22 ++++++++++++++++++++++ 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index efaa87c0e5..4c9ac017cc 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -6,21 +6,6 @@ #ifndef __NFP_NFP6000_H__ #define __NFP_NFP6000_H__ -/* CPP Target IDs */ -#define NFP_CPP_TARGET_INVALID 0 -#define NFP_CPP_TARGET_NBI 1 -#define NFP_CPP_TARGET_QDR 2 -#define NFP_CPP_TARGET_ILA 6 -#define NFP_CPP_TARGET_MU 7 -#define NFP_CPP_TARGET_PCIE 9 -#define NFP_CPP_TARGET_ARM 10 -#define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ -#define NFP_CPP_TARGET_CT_XPB 14 -#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 -#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH - #define NFP_ISL_EMEM0 24 #define NFP_MU_ADDR_ACCESS_TYPE_MASK 3ULL @@ -52,9 +37,4 @@ nfp_cppat_mu_locality_lsb(int mode, int addr40) } } -int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); -int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table); - #endif /* NFP_NFP6000_H */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index db15411eb2..310cc691cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -34,6 +34,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 0f68c5d667..b7eb53697f 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -16,6 +16,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 85c33502ca..87a9351ff9 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -9,7 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) #define MUTEX_UNLOCK(interface) (0 | 0x0000) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index fba7a1dc12..7d8d35e3dd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,7 +9,6 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp6000/nfp6000.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index e4a3a42eea..ee987c4438 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,7 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 2d4100dda2..022753f98a 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -14,6 +14,7 @@ #include "nfp_logs.h" #include "nfp_mip.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" enum nfp_rtsym_type { diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 540b242a43..ecb45f7928 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -3,6 +3,8 @@ * All rights reserved. */ +#include "nfp_target.h" + #include "nfp_cpp.h" #include "nfp6000/nfp6000.h" @@ -315,8 +317,7 @@ nfp6000_mu(uint32_t cpp_id, } else if (island == 1 || (island >= 4 && island <= 7) || (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { + (island >= 32 && island <= 51)) { pp = nfp6000_mu_ctm(cpp_id); } else { pp = -EINVAL; @@ -510,7 +511,7 @@ nfp_target_pushpull(uint32_t cpp_id, return nfp6000_cap_xpb(cpp_id); case NFP_CPP_TARGET_CLS: return nfp6000_cls(cpp_id); - case 0: + case NFP_CPP_TARGET_INVALID: return target_rw(cpp_id, P32, 4, 4); default: return -EINVAL; diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 2a2f083914..47527b4040 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,4 +6,26 @@ #ifndef __NFP_TARGET_H__ #define __NFP_TARGET_H__ +#include <stdint.h> + +/* CPP Target IDs */ +#define NFP_CPP_TARGET_INVALID 0 +#define NFP_CPP_TARGET_NBI 1 +#define NFP_CPP_TARGET_QDR 2 +#define NFP_CPP_TARGET_ILA 6 +#define NFP_CPP_TARGET_MU 7 +#define NFP_CPP_TARGET_PCIE 9 +#define NFP_CPP_TARGET_ARM 10 +#define NFP_CPP_TARGET_CRYPTO 12 +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_CT_XPB 14 +#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 +#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH + +int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); +int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, + uint32_t *cpp_target_id, uint64_t *cpp_target_address, + const uint32_t *imb_table); + #endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 18/27] net/nfp: add a new header file 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (16 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 17/27] net/nfp: refact the target module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 19/27] net/nfp: refact the nsp module Chaoyong He ` (10 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Split out the macro which are not easily find a DPDK substitute into a new header file. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_nsp.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp.h | 23 -------------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 + drivers/net/nfp/nfpcore/nfp_platform.h | 42 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 9bb344aa5f..8e65064b10 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -13,6 +13,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #include "nfp_resource.h" int diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 705574b900..14986a9130 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -9,29 +9,6 @@ #include "nfp_cpp.h" #include "nfp_nsp.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - /* Offsets relative to the CSR base */ #define NSP_STATUS 0x00 #define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 7d8d35e3dd..dd17d0f5f6 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,6 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_platform.h b/drivers/net/nfp/nfpcore/nfp_platform.h new file mode 100644 index 0000000000..fcac6b05ff --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_platform.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_PLATFORM_H__ +#define __NFP_PLATFORM_H__ + +#include <stdint.h> + +#define DMA_BIT_MASK(n) ((1ULL << (n)) - 1) + +#define BITS_PER_LONG (__SIZEOF_LONG__ * 8) +#define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8) + +#define GENMASK(h, l) \ + ((~0UL << (l)) & (~0UL >> (BITS_PER_LONG - (h) - 1))) + +#define GENMASK_ULL(h, l) \ + ((~0ULL << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - (h) - 1))) + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define FIELD_GET(_mask, _reg) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + })) + +#define FIELD_FIT(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ + })) + +#define FIELD_PREP(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + })) + +#endif /* __NFP_PLATFORM_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 19/27] net/nfp: refact the nsp module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (17 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 18/27] net/nfp: add a new header file Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-18 12:31 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 20/27] net/nfp: refact the mutex module Chaoyong He ` (9 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Move the definition of data structure into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 390 +++++++++++++++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 140 ++++----- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 - drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 79 ++--- 5 files changed, 398 insertions(+), 217 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 2e43055fd5..9243191de3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -661,7 +661,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev) static int nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) { - struct nfp_cpp *cpp = nsp->cpp; + struct nfp_cpp *cpp = nfp_nsp_cpp(nsp); void *fw_buf; char fw_name[125]; char serial[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 8e65064b10..75d13cb84f 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -3,20 +3,127 @@ * All rights reserved. */ -#define NFP_SUBSYS "nfp_nsp" - -#include <stdio.h> -#include <time.h> +#include "nfp_nsp.h" #include <rte_common.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_nsp.h" #include "nfp_platform.h" #include "nfp_resource.h" -int +/* Offsets relative to the CSR base */ +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_DMA_BUF RTE_BIT64(1) +#define NSP_COMMAND_START RTE_BIT64(0) + +/* CPP address to retrieve the data from */ +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) + +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 + +#define NSP_CODE_MAJOR GENMASK_ULL(15, 12) +#define NSP_CODE_MINOR GENMASK_ULL(11, 0) + +#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8) +#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16) + +enum nfp_nsp_cmd { + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */ + SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */ + SPCODE_HWINFO_SET = 18, /* Set HWinfo entry */ + SPCODE_FW_LOADED = 19, /* Is application firmware loaded */ + SPCODE_VERSIONS = 21, /* Report FW versions */ + SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */ + SPCODE_READ_MEDIA = 23, /* Get the supported/advertised media for a port */ +}; + +static const struct { + uint32_t code; + const char *msg; +} nsp_errors[] = { + { 6010, "could not map to phy for port" }, + { 6011, "not an allowed rate/lanes for port" }, + { 6012, "not an allowed rate/lanes for port" }, + { 6013, "high/low error, change other port first" }, + { 6014, "config not found in flash" }, +}; + +struct nfp_nsp { + struct nfp_cpp *cpp; + struct nfp_resource *res; + struct { + uint16_t major; + uint16_t minor; + } ver; + + /** Eth table config state */ + bool modified; + uint32_t idx; + void *entries; +}; + +/* NFP command argument structure */ +struct nfp_nsp_command_arg { + uint16_t code; /**< NFP SP Command Code */ + bool dma; /**< @buf points to a host buffer, not NSP buffer */ + bool error_quiet; /**< Don't print command error/warning */ + uint32_t timeout_sec; /**< Timeout value to wait for completion in seconds */ + uint32_t option; /**< NSP Command Argument */ + uint64_t buf; /**< NSP Buffer Address */ + /** Callback for interpreting option if error occurred */ + void (*error_cb)(struct nfp_nsp *state, uint32_t ret_val); +}; + +/* NFP command with buffer argument structure */ +struct nfp_nsp_command_buf_arg { + struct nfp_nsp_command_arg arg; /**< NFP command argument structure */ + const void *in_buf; /**< Buffer with data for input */ + void *out_buf; /**< Buffer for output data */ + uint32_t in_size; /**< Size of @in_buf */ + uint32_t out_size; /**< Size of @out_buf */ +}; + +struct nfp_cpp * +nfp_nsp_cpp(struct nfp_nsp *state) +{ + return state->cpp; +} + +bool nfp_nsp_config_modified(struct nfp_nsp *state) { return state->modified; @@ -24,7 +131,7 @@ nfp_nsp_config_modified(struct nfp_nsp *state) void nfp_nsp_config_set_modified(struct nfp_nsp *state, - int modified) + bool modified) { state->modified = modified; } @@ -66,7 +173,7 @@ nfp_nsp_print_extended_error(uint32_t ret_val) return; for (i = 0; i < RTE_DIM(nsp_errors); i++) - if (ret_val == (uint32_t)nsp_errors[i].code) + if (ret_val == nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -222,11 +329,8 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, - uint16_t code, - uint32_t option, - uint32_t buff_cpp, - uint64_t buff_addr) +nfp_nsp_command_real(struct nfp_nsp *state, + const struct nfp_nsp_command_arg *arg) { int err; uint64_t reg; @@ -250,22 +354,14 @@ nfp_nsp_command(struct nfp_nsp *state, return err; } - if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { - PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); - return -EINVAL; - } - - err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, arg->buf); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_OPTION, arg->option) | + FIELD_PREP(NSP_COMMAND_CODE, arg->code) | + FIELD_PREP(NSP_COMMAND_DMA_BUF, arg->dma) | FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; @@ -275,7 +371,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", - err, code); + err, arg->code); return err; } @@ -284,7 +380,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", - err, code); + err, arg->code); return err; } @@ -296,84 +392,85 @@ nfp_nsp_command(struct nfp_nsp *state, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { - PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); - nfp_nsp_print_extended_error(ret_val); + if (!arg->error_quiet) + PMD_DRV_LOG(WARNING, "Result (error) code set: %d (%d) command: %d", + -err, (int)ret_val, arg->code); + + if (arg->error_cb != 0) + arg->error_cb(state, ret_val); + else + nfp_nsp_print_extended_error(ret_val); + return -err; } return ret_val; } -#define SZ_1M 0x00100000 +static int +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code) +{ + const struct nfp_nsp_command_arg arg = { + .code = code, + }; + + return nfp_nsp_command_real(state, &arg); +} static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, - uint16_t code, uint32_t option, - const void *in_buf, - unsigned int in_size, - void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf_def(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) { int err; int ret; uint64_t reg; - size_t max_size; uint32_t cpp_id; uint64_t cpp_buf; struct nfp_cpp *cpp = nsp->cpp; - if (nsp->ver.minor < 13) { - PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); - return -EOPNOTSUPP; - } - - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, - ®); - if (err < 0) - return err; - - max_size = RTE_MAX(in_size, out_size); - if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %lu)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); - return -EINVAL; - } - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, ®); if (err < 0) return err; - cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; - cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); + cpp_id = FIELD_GET(NSP_DFLT_BUFFER_CPP, reg) << 8; + cpp_buf = FIELD_GET(NSP_DFLT_BUFFER_ADDRESS, reg); - if (in_buf != NULL && in_size > 0) { - err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); + if (arg->in_buf != NULL && arg->in_size > 0) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf, + arg->in_buf, arg->in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf != NULL && out_size > 0 && out_size > in_size) { - memset(out_buf, 0, out_size - in_size); - err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + if (arg->out_buf != NULL && arg->out_size > arg->in_size) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf + arg->in_size, + arg->out_buf, arg->out_size - arg->in_size); if (err < 0) return err; } - ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); + if (!FIELD_FIT(NSP_BUFFER_CPP, cpp_id >> 8) || + !FIELD_FIT(NSP_BUFFER_ADDRESS, cpp_buf)) { + PMD_DRV_LOG(ERR, "Buffer out of reach %#08x %#016lx", + cpp_id, cpp_buf); + return -EINVAL; + } + + arg->arg.buf = FIELD_PREP(NSP_BUFFER_CPP, cpp_id >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf); + ret = nfp_nsp_command_real(nsp, &arg->arg); if (ret < 0) { PMD_DRV_LOG(ERR, "NSP command failed"); return ret; } - if (out_buf != NULL && out_size > 0) { - err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); + if (arg->out_buf != NULL && arg->out_size > 0) { + err = nfp_cpp_read(cpp, cpp_id, cpp_buf, + arg->out_buf, arg->out_size); if (err < 0) return err; } @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, return ret; } +#define SZ_1M 0x00100000 +#define SZ_4K 0x00001000 + +static int +nfp_nsp_command_buf(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) +{ + int err; + uint64_t reg; + uint32_t size; + uint32_t max_size; + struct nfp_cpp *cpp = nsp->cpp; + + if (nsp->ver.minor < 13) { + PMD_DRV_LOG(ERR, "NSP: Code %#04x with buffer not supported ABI %hu.%hu)", + arg->arg.code, nsp->ver.major, nsp->ver.minor); + return -EOPNOTSUPP; + } + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); + if (err < 0) + return err; + + max_size = RTE_MAX(arg->in_size, arg->out_size); + size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; + if (size < max_size) { + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%u < %u)", + arg->arg.code, size, max_size); + return -EINVAL; + } + + return nfp_nsp_command_buf_def(nsp, arg); +} + int nfp_nsp_wait(struct nfp_nsp *state) { @@ -392,7 +526,7 @@ nfp_nsp_wait(struct nfp_nsp *state) wait.tv_nsec = 25000000; /* 25ms */ for (;;) { - err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); + err = nfp_nsp_command(state, SPCODE_NOOP); if (err != -EAGAIN) break; @@ -413,13 +547,57 @@ nfp_nsp_wait(struct nfp_nsp *state) int nfp_nsp_device_soft_reset(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_SOFT_RESET, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_SOFT_RESET); } int nfp_nsp_mac_reinit(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_MAC_INIT, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_MAC_INIT); +} + +static void +nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, + uint32_t ret_val) +{ + uint32_t minor; + uint32_t major; + static const char * const major_msg[] = { + /* 0 */ "Firmware from driver loaded", + /* 1 */ "Firmware from flash loaded", + /* 2 */ "Firmware loading failure", + }; + static const char * const minor_msg[] = { + /* 0 */ "", + /* 1 */ "no named partition on flash", + /* 2 */ "error reading from flash", + /* 3 */ "can not deflate", + /* 4 */ "not a trusted file", + /* 5 */ "can not parse FW file", + /* 6 */ "MIP not found in FW file", + /* 7 */ "null firmware name in MIP", + /* 8 */ "FW version none", + /* 9 */ "FW build number none", + /* 10 */ "no FW selection policy HWInfo key found", + /* 11 */ "static FW selection policy", + /* 12 */ "FW version has precedence", + /* 13 */ "different FW application load requested", + /* 14 */ "development build", + }; + + major = FIELD_GET(NFP_FW_LOAD_RET_MAJOR, ret_val); + minor = FIELD_GET(NFP_FW_LOAD_RET_MINOR, ret_val); + + if (!nfp_nsp_has_stored_fw_load(state)) + return; + + if (major >= RTE_DIM(major_msg)) + PMD_DRV_LOG(INFO, "FW loading status: %x", ret_val); + else if (minor >= RTE_DIM(minor_msg)) + PMD_DRV_LOG(INFO, "%s, reason code: %d", major_msg[major], minor); + else + PMD_DRV_LOG(INFO, "%s%c %s", major_msg[major], + minor != 0 ? ',' : '.', minor_msg[minor]); } int @@ -427,8 +605,24 @@ nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + int ret; + struct nfp_nsp_command_buf_arg load_fw = { + { + .code = SPCODE_FW_LOAD, + .option = size, + .error_cb = nfp_nsp_load_fw_extended_msg, + }, + .in_buf = buf, + .in_size = size, + }; + + ret = nfp_nsp_command_buf(state, &load_fw); + if (ret < 0) + return ret; + + nfp_nsp_load_fw_extended_msg(state, ret); + + return 0; } int @@ -436,8 +630,16 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg eth_rescan = { + { + .code = SPCODE_ETH_RESCAN, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, ð_rescan); } int @@ -445,8 +647,16 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + struct nfp_nsp_command_buf_arg eth_ctrl = { + { + .code = SPCODE_ETH_CONTROL, + .option = size, + }, + .in_buf = buf, + .in_size = size, + }; + + return nfp_nsp_command_buf(state, ð_ctrl); } int @@ -454,8 +664,16 @@ nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg identify = { + { + .code = SPCODE_NSP_IDENTIFY, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &identify); } int @@ -464,6 +682,14 @@ nfp_nsp_read_sensors(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + struct nfp_nsp_command_buf_arg sensors = { + { + .code = SPCODE_NSP_SENSORS, + .option = sensor_mask, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &sensors); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 14986a9130..fe52dffeb7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -7,78 +7,8 @@ #define __NSP_NSP_H__ #include "nfp_cpp.h" -#include "nfp_nsp.h" - -/* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) - -/* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) - -#define NSP_DFLT_BUFFER 0x18 - -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) - -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 - -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) - -enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ -}; - -static const struct { - int code; - const char *msg; -} nsp_errors[] = { - { 6010, "could not map to phy for port" }, - { 6011, "not an allowed rate/lanes for port" }, - { 6012, "not an allowed rate/lanes for port" }, - { 6013, "high/low error, change other port first" }, - { 6014, "config not found in flash" }, -}; -struct nfp_nsp { - struct nfp_cpp *cpp; - struct nfp_resource *res; - struct { - uint16_t major; - uint16_t minor; - } ver; - - /* Eth table config state */ - int modified; - unsigned int idx; - void *entries; -}; +struct nfp_nsp; struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); void nfp_nsp_close(struct nfp_nsp *state); @@ -92,18 +22,61 @@ int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, void *buf, size_t size); -static inline int +static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } +static inline bool +nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 23; +} + +static inline bool +nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 24; +} + +static inline bool +nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_fw_loaded(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_versions(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 27; +} + +static inline bool +nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 28; +} + +static inline bool +nfp_nsp_has_read_media(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 33; +} + enum nfp_eth_interface { NFP_INTERFACE_NONE = 0, NFP_INTERFACE_SFP = 1, NFP_INTERFACE_SFPP = 10, NFP_INTERFACE_SFP28 = 28, NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_RJ45 = 45, NFP_INTERFACE_CXP = 100, NFP_INTERFACE_QSFP28 = 112, }; @@ -151,6 +124,7 @@ struct nfp_eth_table { enum nfp_eth_media media; /**< Media type of the @interface */ enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ struct rte_ether_addr mac_addr; /**< Interface MAC address */ @@ -159,17 +133,18 @@ struct nfp_eth_table { /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; /**< Enable port */ - int tx_enabled; /**< Enable TX */ - int rx_enabled; /**< Enable RX */ + bool enabled; /**< Enable port */ + bool tx_enabled; /**< Enable TX */ + bool rx_enabled; /**< Enable RX */ + bool supp_aneg; /**< Support auto negotiation */ - int override_changed; /**< Media reconfig pending */ + bool override_changed; /**< Media reconfig pending */ uint8_t port_type; /**< One of %PORT_* */ /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; /**< Split port */ + bool is_split; /**< Split port */ uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ } ports[]; /**< Table of ports */ @@ -177,8 +152,8 @@ struct nfp_eth_table { struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); @@ -187,12 +162,13 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); -void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); +void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); -int nfp_nsp_config_modified(struct nfp_nsp *state); +struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); +bool nfp_nsp_config_modified(struct nfp_nsp *state); uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int +static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported != 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 429f639fa2..86956f4330 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -3,12 +3,8 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp_nffw.h" struct nsp_identify { uint8_t version[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index dd17d0f5f6..90ecdaaa52 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -3,10 +3,6 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_common.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" #include "nfp_platform.h" @@ -21,6 +17,7 @@ #define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) #define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) #define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) +#define NSP_ETH_PORT_SUPP_ANEG RTE_BIT64(63) #define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) @@ -34,6 +31,7 @@ #define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) #define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) #define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) +#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28) #define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) #define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) @@ -54,26 +52,12 @@ #define PORT_NONE 0xef #define PORT_OTHER 0xff -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 - enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW + NSP_ETH_NUM_RAW, }; enum nfp_eth_rate { @@ -100,12 +84,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, RTE_ETH_SPEED_NUM_NONE, }, + { RATE_10M, RTE_ETH_SPEED_NUM_10M, }, + { RATE_100M, RTE_ETH_SPEED_NUM_100M, }, + { RATE_1G, RTE_ETH_SPEED_NUM_1G, }, + { RATE_10G, RTE_ETH_SPEED_NUM_10G, }, + { RATE_25G, RTE_ETH_SPEED_NUM_25G, }, }; static uint32_t @@ -193,7 +177,14 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; - dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->fec = FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->act_fec = dst->fec; + + if (nfp_nsp_get_abi_ver_minor(nsp) < 33) + return; + + dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state); + dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port); } static void @@ -222,7 +213,7 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) table->ports[i].label_port, table->ports[i].label_subport); - table->ports[i].is_split = 1; + table->ports[i].is_split = true; } } } @@ -233,6 +224,9 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) if (entry->interface == NFP_INTERFACE_NONE) { entry->port_type = PORT_NONE; return; + } else if (entry->interface == NFP_INTERFACE_RJ45) { + entry->port_type = PORT_TP; + return; } if (entry->media == NFP_MEDIA_FIBRE) @@ -251,7 +245,6 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) uint32_t table_sz; struct nfp_eth_table *table; union eth_table_entry *entries; - const struct rte_ether_addr *mac; entries = rte_zmalloc(NULL, NSP_ETH_TABLE_SIZE, 0); if (entries == NULL) @@ -263,16 +256,9 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) goto err; } - /* - * The NFP3800 NIC support 8 ports, but only 2 ports are valid, - * the rest 6 ports mac are all 0, ensure we don't use these port - */ - for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) + for (i = 0; i < NSP_ETH_MAX_COUNT; i++) + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) cnt++; - } /* * Some versions of flash will give us 0 instead of port count. For @@ -292,11 +278,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) - nfp_eth_port_translate(nsp, &entries[i], i, - &table->ports[j++]); + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) + nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); } nfp_eth_calc_port_geometry(table); @@ -437,7 +420,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, - int enable) + bool enable) { uint64_t reg; struct nfp_nsp *nsp; @@ -445,7 +428,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) - return -1; + return -EIO; entries = nfp_nsp_config_entries(nsp); @@ -457,7 +440,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_ENABLED, enable); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -481,7 +464,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configured) + bool configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -510,7 +493,7 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -548,7 +531,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, entries[idx].control |= rte_cpu_to_le_64(ctrl_bit); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 19/27] net/nfp: refact the nsp module 2023-09-15 9:15 ` [PATCH v3 19/27] net/nfp: refact the nsp module Chaoyong He @ 2023-09-18 12:31 ` Ferruh Yigit 2023-09-18 12:36 ` Ferruh Yigit 0 siblings, 1 reply; 159+ messages in thread From: Ferruh Yigit @ 2023-09-18 12:31 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund On 9/15/2023 10:15 AM, Chaoyong He wrote: > Move the definition of data structure into the implement file. > Also sync the logic from kernel driver and remove the unneeded header > file include statements. > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> <...> > @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, > return ret; > } > > +#define SZ_1M 0x00100000 > +#define SZ_4K 0x00001000 > + > +static int > +nfp_nsp_command_buf(struct nfp_nsp *nsp, > + struct nfp_nsp_command_buf_arg *arg) > +{ > + int err; > + uint64_t reg; > + uint32_t size; > + uint32_t max_size; > One of the previous patches, patch 3/27, updates variable type 'unsigned int max_size;' -> 'size_t max_size;' Now it is updated again to 'uint32_t max_size;', I assume by mistake that previous patch updated by this one didn't. If it is by mistake can you please check all patches that moves code, if they are aligned with previous cleanups. Or if this is intentional, can you please update the first patch to set the variable correct at first place? ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 19/27] net/nfp: refact the nsp module 2023-09-18 12:31 ` Ferruh Yigit @ 2023-09-18 12:36 ` Ferruh Yigit 0 siblings, 0 replies; 159+ messages in thread From: Ferruh Yigit @ 2023-09-18 12:36 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers, Niklas Söderlund On 9/18/2023 1:31 PM, Ferruh Yigit wrote: > On 9/15/2023 10:15 AM, Chaoyong He wrote: >> Move the definition of data structure into the implement file. >> Also sync the logic from kernel driver and remove the unneeded header >> file include statements. >> >> Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> >> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> > > <...> > >> @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, >> return ret; >> } >> >> +#define SZ_1M 0x00100000 >> +#define SZ_4K 0x00001000 >> + >> +static int >> +nfp_nsp_command_buf(struct nfp_nsp *nsp, >> + struct nfp_nsp_command_buf_arg *arg) >> +{ >> + int err; >> + uint64_t reg; >> + uint32_t size; >> + uint32_t max_size; >> > > One of the previous patches, patch 3/27, updates variable type > 'unsigned int max_size;' -> 'size_t max_size;' > > Now it is updated again to 'uint32_t max_size;', I assume by mistake > that previous patch updated by this one didn't. > > If it is by mistake can you please check all patches that moves code, if > they are aligned with previous cleanups. > Or if this is intentional, can you please update the first patch to set > the variable correct at first place? > This comment is for v4, I replied to wrong version. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 20/27] net/nfp: refact the mutex module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (18 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 19/27] net/nfp: refact the nsp module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He ` (8 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Add a header file to holds the API declarations of this module. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 16 -- drivers/net/nfp/nfpcore/nfp_mutex.c | 205 ++++++++++++++----------- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 +++ drivers/net/nfp/nfpcore/nfp_resource.c | 1 + 4 files changed, 138 insertions(+), 109 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index be7ae1d919..42c4df5fdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -8,8 +8,6 @@ #include <ethdev_pci.h> -struct nfp_cpp_mutex; - /* NFP CPP handle */ struct nfp_cpp { uint32_t model; @@ -426,20 +424,6 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); - uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); #endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 87a9351ff9..9363543422 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -3,21 +3,13 @@ * All rights reserved. */ -#include <malloc.h> -#include <time.h> +#include "nfp_mutex.h" + #include <sched.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" -#define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) -#define MUTEX_UNLOCK(interface) (0 | 0x0000) - -#define MUTEX_IS_LOCKED(value) (((value) & 0xffff) == 0x000f) -#define MUTEX_IS_UNLOCKED(value) (((value) & 0xffff) == 0x0000) -#define MUTEX_INTERFACE(value) (((value) >> 16) & 0xffff) - /* * If you need more than 65536 recursive locks, please * rethink your code. @@ -34,21 +26,51 @@ struct nfp_cpp_mutex { struct nfp_cpp_mutex *prev, *next; }; +static inline uint32_t +nfp_mutex_locked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x000f; +} + +static inline uint32_t +nfp_mutex_unlocked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x0000; +} + +static inline uint16_t +nfp_mutex_owner(uint32_t val) +{ + return (val >> 16) & 0xffff; +} + +static inline bool +nfp_mutex_is_locked(uint32_t val) +{ + return (val & 0xffff) == 0x000f; +} + +static inline bool +nfp_mutex_is_unlocked(uint32_t val) +{ + return (val & 0xffff) == 0; +} + static int -nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint16_t interface, int *target, uint64_t address) { + /* Not permitted on invalid interfaces */ + if (NFP_CPP_INTERFACE_TYPE_of(interface) == NFP_CPP_INTERFACE_TYPE_INVALID) + return -EINVAL; + /* Address must be 64-bit aligned */ if ((address & 7) != 0) return -EINVAL; - if (NFP_CPP_MODEL_IS_6000(model)) { - if (*target != NFP_CPP_TARGET_MU) - return -EINVAL; - } else { + if (*target != NFP_CPP_TARGET_MU) return -EINVAL; - } return 0; } @@ -84,10 +106,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t key) { int err; - uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint16_t interface = nfp_cpp_interface(cpp); - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return err; @@ -95,8 +117,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, if (err < 0) return err; - err = nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface)); if (err < 0) return err; @@ -133,26 +154,10 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int err; uint32_t tmp; struct nfp_cpp_mutex *mutex; - uint32_t model = nfp_cpp_model(cpp); uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint16_t interface = nfp_cpp_interface(cpp); - /* Look for cached mutex */ - for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { - if (mutex->target == target && mutex->address == address) - break; - } - - if (mutex) { - if (mutex->key == key) { - mutex->usage++; - return mutex; - } - - /* If the key doesn't match... */ - return NULL; - } - - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return NULL; @@ -172,16 +177,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, mutex->address = address; mutex->key = key; mutex->depth = 0; - mutex->usage = 1; - - /* Add mutex to the cache */ - if (cpp->mutex_cache) { - cpp->mutex_cache->prev = mutex; - mutex->next = cpp->mutex_cache; - cpp->mutex_cache = mutex; - } else { - cpp->mutex_cache = mutex; - } return mutex; } @@ -195,20 +190,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) { - mutex->usage--; - if (mutex->usage > 0) - return; - - /* Remove mutex from the cache */ - if (mutex->next) - mutex->next->prev = mutex->prev; - if (mutex->prev) - mutex->prev->next = mutex->next; - - /* If mutex->cpp == NULL, something broke */ - if (mutex->cpp && mutex == mutex->cpp->mutex_cache) - mutex->cpp->mutex_cache = mutex->next; - rte_free(mutex); } @@ -268,32 +249,28 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return 0; } - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - goto exit; - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; - if (value != MUTEX_LOCKED(interface)) { - err = -EACCES; - goto exit; - } + err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); + if (err < 0) + return err; + + if (value != nfp_mutex_locked(interface)) + return -EACCES; - err = nfp_cpp_writel(cpp, muw, mutex->address, MUTEX_UNLOCK(interface)); + err = nfp_cpp_writel(cpp, muw, mutex->address, + nfp_mutex_unlocked(interface)); if (err < 0) - goto exit; + return err; mutex->depth = 0; -exit: - return err; + return 0; } /** @@ -332,19 +309,17 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) /* Verify that the lock marker is not damaged */ err = nfp_cpp_readl(cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; /* * Compare against the unlocked state, and if true, * write the interface id into the top 16 bits, and * mark as locked. */ - value = MUTEX_LOCKED(nfp_cpp_interface(cpp)); + value = nfp_mutex_locked(nfp_cpp_interface(cpp)); /* * We use test_set_imm here, as it implies a read @@ -361,10 +336,10 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_readl(cpp, mus, mutex->address, &tmp); if (err < 0) - goto exit; + return err; /* Was it unlocked? */ - if (MUTEX_IS_UNLOCKED(tmp)) { + if (nfp_mutex_is_unlocked(tmp)) { /* * The read value can only be 0x....0000 in the unlocked state. * If there was another contending for this lock, then @@ -376,20 +351,64 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_writel(cpp, muw, mutex->address, value); if (err < 0) - goto exit; + return err; mutex->depth = 1; - goto exit; + return 0; } /* Already locked by us? Success! */ if (tmp == value) { mutex->depth = 1; - goto exit; + return 0; } - err = MUTEX_IS_LOCKED(tmp) ? -EBUSY : -EINVAL; + return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL; +} + +/** + * Release lock if held by local system. + * Extreme care is advised, call only when no local lock users can exist. + * + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * + * @return + * - (0) if the lock was OK + * - (1) if locked by us + * - (-errno) on invalid mutex + */ +int +nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, + int target, + uint64_t address) +{ + int err; + uint32_t tmp; + uint16_t interface = nfp_cpp_interface(cpp); + const uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + const uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + + err = nfp_cpp_mutex_validate(interface, &target, address); + if (err != 0) + return err; + + /* Check lock */ + err = nfp_cpp_readl(cpp, mur, address, &tmp); + if (err < 0) + return err; + + if (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface) + return 0; + + /* Bust the lock */ + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface)); + if (err < 0) + return err; -exit: - return err; + return 1; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.h b/drivers/net/nfp/nfpcore/nfp_mutex.h new file mode 100644 index 0000000000..a79490b4d6 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_mutex.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_MUTEX_H__ +#define __NFP_MUTEX_H__ + +#include "nfp_cpp.h" + +struct nfp_cpp_mutex; + +int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target, uint64_t address); + +#endif /* __NFP_MUTEX_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index ee987c4438..c4cc7f42f6 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,6 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" +#include "nfp_mutex.h" #include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 21/27] net/nfp: rename data field to sync with kernel driver 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (19 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 20/27] net/nfp: refact the mutex module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 22/27] net/nfp: add the dev module Chaoyong He ` (7 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Rename the data fields to sync with the logic in kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +++--- drivers/net/nfp/nfp_common.h | 4 ++-- drivers/net/nfp/nfp_ethdev.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 37895e8355..24a6878149 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -224,7 +224,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -360,8 +360,8 @@ nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type) start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ; - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; /* Set the current MTU to the maximum supported */ hw->mtu = hw->max_mtu; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 1ce51d44d4..86c4e10040 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -123,9 +123,9 @@ struct nfp_pf_dev { struct nfp_cpp *cpp; struct nfp_cpp_area *ctrl_area; - struct nfp_cpp_area *hwqueues_area; + struct nfp_cpp_area *qc_area; - uint8_t *hw_queues; + uint8_t *qc_bar; struct nfp_hwinfo *hwinfo; struct nfp_rtsym_table *sym_tbl; diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 9243191de3..3f5375deb9 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -311,7 +311,7 @@ nfp_net_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); rte_free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -593,8 +593,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -995,16 +995,16 @@ nfp_pf_init(struct rte_pci_device *pci_dev) } cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); - pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, cpp_id, + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, addr, NFP_QCP_QUEUE_AREA_SZ, - &pf_dev->hwqueues_area); - if (pf_dev->hw_queues == NULL) { + &pf_dev->qc_area); + if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; goto pf_cleanup; } - PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues); + PMD_INIT_LOG(DEBUG, "qc_bar address: 0x%p", pf_dev->qc_bar); /* * PF initialization has been done at this point. Call app specific @@ -1041,7 +1041,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) return 0; hwqueues_cleanup: - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); pf_cleanup: rte_free(pf_dev); sym_tbl_cleanup: -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 22/27] net/nfp: add the dev module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (20 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 23/27] net/nfp: add header file for PCIe module Chaoyong He ` (6 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Add the nfp_dev module to simplify the logic. The data structure we import can gather and replace several macro which scatter everywhere. Which also make the logic of choose value for different devices unnecessary and so eliminate such logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 1 + drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 ++---------- drivers/net/nfp/nfp_common.h | 48 +++-------- drivers/net/nfp/nfp_ethdev.c | 63 ++++++--------- drivers/net/nfp/nfp_ethdev_vf.c | 17 +--- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 --- drivers/net/nfp/nfpcore/nfp_dev.c | 81 +++++++++++++++++++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 ++++++++++ 13 files changed, 185 insertions(+), 158 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 24a6878149..43263531c5 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -503,7 +503,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_rx_ring", i, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -558,7 +559,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_tx_ring", i, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 5f94d20f1b..dc6a2c7a9a 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -67,7 +67,8 @@ nfp_pf_repr_rx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -140,7 +141,8 @@ nfp_pf_repr_tx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 93c708959c..580a478cd6 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -21,6 +21,7 @@ sources = files( 'nfpcore/nfp_rtsym.c', 'nfpcore/nfp_nsp_cmds.c', 'nfpcore/nfp_crc.c', + 'nfpcore/nfp_dev.c', 'nfpcore/nfp_mutex.c', 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', diff --git a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c index ee39686329..79e1e1041c 100644 --- a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c +++ b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c @@ -262,7 +262,6 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -276,9 +275,7 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfd3_tx_desc); diff --git a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c index f66802211f..48a74d109a 100644 --- a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c +++ b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c @@ -357,7 +357,6 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -371,9 +370,7 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfdk_tx_desc); diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c index 5092e5869d..d6ff4f17ae 100644 --- a/drivers/net/nfp/nfp_common.c +++ b/drivers/net/nfp/nfp_common.c @@ -1146,30 +1146,16 @@ nfp_net_xstats_reset(struct rte_eth_dev *dev) return nfp_net_stats_reset(dev); } -int +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc) { - *max_rx_desc = NFP_NET_MAX_RX_DESC; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_rx_desc = NFP3800_NET_MIN_RX_DESC; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_rx_desc = NFP_NET_MIN_RX_DESC; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_rx_desc = hw->pf_dev->dev_info->max_qc_size; + *min_rx_desc = hw->pf_dev->dev_info->min_qc_size; } -int +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc) @@ -1181,28 +1167,13 @@ nfp_net_tx_desc_limits(struct nfp_net_hw *hw, else tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT; - *max_tx_desc = NFP_NET_MAX_TX_DESC / tx_dpp; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_tx_desc = NFP3800_NET_MIN_TX_DESC / tx_dpp; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_tx_desc = NFP_NET_MIN_TX_DESC / tx_dpp; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_tx_desc = hw->pf_dev->dev_info->max_qc_size / tx_dpp; + *min_tx_desc = hw->pf_dev->dev_info->min_qc_size / tx_dpp; } int nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; uint16_t min_tx_desc; @@ -1211,13 +1182,8 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; - - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues; dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 86c4e10040..5fc9f0ccda 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -7,16 +7,9 @@ #define _NFP_COMMON_H_ #include "nfp_ctrl.h" +#include "nfpcore/nfp_dev.h" #define NFP_NET_PMD_VERSION "0.1" -#define PCI_VENDOR_ID_NETRONOME 0x19ee -#define PCI_VENDOR_ID_CORIGINE 0x1da8 - -#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 -#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 -#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 -#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 -#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ /* Forward declaration */ struct nfp_net_adapter; @@ -28,7 +21,6 @@ struct nfp_net_adapter; #define NFP_NET_CRTL_BAR 0 #define NFP_NET_TX_BAR 2 #define NFP_NET_RX_BAR 2 -#define NFP_QCP_QUEUE_AREA_SZ 0x80000 /* Macros for accessing the Queue Controller Peripheral 'CSRs' */ #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800) @@ -39,17 +31,6 @@ struct nfp_net_adapter; #define NFP_QCP_QUEUE_STS_HI 0x000c #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask (0x3ffff) -#define NFP_PCIE_QCP_NFP3800_OFFSET 0x400000 -#define NFP_PCIE_QCP_NFP6000_OFFSET 0x80000 -#define NFP_PCIE_QUEUE_NFP3800_MASK 0x1ff -#define NFP_PCIE_QUEUE_NFP6000_MASK 0xff -#define NFP_PCIE_QCP_PF_OFFSET 0x0 -#define NFP_PCIE_QCP_VF_OFFSET 0x0 - -/* The offset of the queue controller queues in the PCIe Target */ -#define NFP_PCIE_QUEUE(_offset, _q, _mask) \ - ((_offset) + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & (_mask)))) - /* Interrupt definitions */ #define NFP_NET_IRQ_LSC_IDX 0 @@ -111,6 +92,9 @@ struct nfp_pf_dev { /* Backpointer to associated pci device */ struct rte_pci_device *pci_dev; + /** NFP ASIC params */ + const struct nfp_dev_info *dev_info; + enum nfp_app_fw_id app_fw_id; /* Pointer to the app running on the PF */ @@ -352,23 +336,11 @@ nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr) } static inline uint32_t -nfp_pci_queue(struct rte_pci_device *pdev, uint16_t queue) +nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, + uint16_t queue) { - switch (pdev->id.device_id) { - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - case PCI_DEVICE_ID_NFP3800_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - case PCI_DEVICE_ID_NFP6000_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - default: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - } + return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ * + (queue & dev_info->qc_idx_mask); } /* Prototypes for common NFP functions */ @@ -434,10 +406,10 @@ void nfp_net_close_rx_queue(struct rte_eth_dev *dev); void nfp_net_stop_tx_queue(struct rte_eth_dev *dev); void nfp_net_close_tx_queue(struct rte_eth_dev *dev); int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port); -int nfp_net_rx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc); -int nfp_net_tx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc); int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 3f5375deb9..c37d8a1449 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -496,9 +496,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) struct nfp_app_fw_nic *app_fw_nic; struct nfp_net_hw *hw; struct rte_ether_addr *tmp_ether_addr; - uint64_t rx_bar_off = 0; - uint64_t tx_bar_off = 0; - uint32_t start_q; + uint64_t rx_base; + uint64_t tx_base; int port = 0; int err; @@ -576,25 +575,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev) /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - return -ENODEV; - } + tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + rx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); - PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); + PMD_INIT_LOG(DEBUG, "tx_base: 0x%" PRIx64 "", tx_base); + PMD_INIT_LOG(DEBUG, "rx_base: 0x%" PRIx64 "", rx_base); - hw->tx_bar = pf_dev->qc_bar + tx_bar_off; - hw->rx_bar = pf_dev->qc_bar + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ; + hw->rx_bar = pf_dev->qc_bar + rx_base * NFP_QCP_QUEUE_ADDR_SZ; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -902,10 +890,17 @@ nfp_pf_init(struct rte_pci_device *pci_dev) char name[RTE_ETH_NAME_MAX_LEN]; struct nfp_rtsym_table *sym_tbl; struct nfp_eth_table *nfp_eth_table; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This @@ -976,27 +971,14 @@ nfp_pf_init(struct rte_pci_device *pci_dev) pf_dev->sym_tbl = sym_tbl; pf_dev->pci_dev = pci_dev; pf_dev->nfp_eth_table = nfp_eth_table; + pf_dev->dev_info = dev_info; /* configure access to tx/rx vNIC BARs */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP3800_OFFSET, - 0, NFP_PCIE_QUEUE_NFP3800_MASK); - break; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP6000_OFFSET, - 0, NFP_PCIE_QUEUE_NFP6000_MASK); - break; - default: - PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); - ret = -ENODEV; - goto pf_cleanup; - } - + addr = nfp_qcp_queue_offset(pf_dev->dev_info, 0); cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, - addr, NFP_QCP_QUEUE_AREA_SZ, + addr, pf_dev->dev_info->qc_area_sz, &pf_dev->qc_area); if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); @@ -1111,10 +1093,17 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) struct nfp_cpp *cpp; enum nfp_app_fw_id app_fw_id; struct nfp_rtsym_table *sym_tbl; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c index eaf815d06d..cf60e56c28 100644 --- a/drivers/net/nfp/nfp_ethdev_vf.c +++ b/drivers/net/nfp/nfp_ethdev_vf.c @@ -305,19 +305,10 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev) } /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_VF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - err = -ENODEV; - goto dev_err_ctrl_map; - } + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + tx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); + rx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c index f0c371ea2b..1b8bb3471d 100644 --- a/drivers/net/nfp/nfp_rxtx.c +++ b/drivers/net/nfp/nfp_rxtx.c @@ -677,7 +677,6 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; const struct rte_memzone *tz; @@ -689,9 +688,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); /* Validating number of descriptors */ rx_desc_sz = nb_desc * sizeof(struct nfp_net_rx_desc); diff --git a/drivers/net/nfp/nfp_rxtx.h b/drivers/net/nfp/nfp_rxtx.h index 48e548b02d..6d1c8e4605 100644 --- a/drivers/net/nfp/nfp_rxtx.h +++ b/drivers/net/nfp/nfp_rxtx.h @@ -74,18 +74,6 @@ struct nfp_meta_parsed { } vlan[NFP_META_MAX_VLANS]; }; -/* - * The maximum number of descriptors is limited by design as - * DPDK uses uint16_t variables for these values - */ -#define NFP_NET_MAX_TX_DESC (32 * 1024) -#define NFP_NET_MIN_TX_DESC 256 -#define NFP3800_NET_MIN_TX_DESC 512 - -#define NFP_NET_MAX_RX_DESC (32 * 1024) -#define NFP_NET_MIN_RX_DESC 256 -#define NFP3800_NET_MIN_RX_DESC 512 - /* Descriptor alignment */ #define NFP_ALIGN_RING_DESC 128 diff --git a/drivers/net/nfp/nfpcore/nfp_dev.c b/drivers/net/nfp/nfpcore/nfp_dev.c new file mode 100644 index 0000000000..7799fa699a --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_dev.h" + +#include <rte_bitops.h> + +#include "nfp_platform.h" + +/* + * Note: The value of 'max_qc_size' is different from kernel driver, + * because DPDK use 'uint16_t' as the data type. + */ +const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { + [NFP_DEV_NFP3800] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0x400000, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP3800", + .pcie_cfg_expbar_offset = 0x0a00, + .qc_area_sz = 0x100000, + .pf_num_per_unit = 4, + }, + [NFP_DEV_NFP3800_VF] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, + [NFP_DEV_NFP6000] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0x80000, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP4000/NFP6000", + .pcie_cfg_expbar_offset = 0x0400, + .qc_area_sz = 0x80000, + .pf_num_per_unit = 1, + }, + [NFP_DEV_NFP6000_VF] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, +}; + +const struct nfp_dev_info * +nfp_dev_info_get(uint16_t device_id) +{ + enum nfp_dev_id id; + + switch (device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + id = NFP_DEV_NFP3800; + break; + case PCI_DEVICE_ID_NFP3800_VF_NIC: + id = NFP_DEV_NFP3800_VF; + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + id = NFP_DEV_NFP6000; + break; + case PCI_DEVICE_ID_NFP6000_VF_NIC: + id = NFP_DEV_NFP6000_VF; + break; + default: + id = NFP_DEV_CNT; + break; + } + + if (id >= NFP_DEV_CNT) + return NULL; + + return &nfp_dev_info[id]; +} diff --git a/drivers/net/nfp/nfpcore/nfp_dev.h b/drivers/net/nfp/nfpcore/nfp_dev.h new file mode 100644 index 0000000000..b0fffff619 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_DEV_H__ +#define __NFP_DEV_H__ + +#include <stdint.h> + +#define PCI_VENDOR_ID_NETRONOME 0x19ee +#define PCI_VENDOR_ID_CORIGINE 0x1da8 + +#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 +#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 +#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 +#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 +#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ + +enum nfp_dev_id { + NFP_DEV_NFP3800, + NFP_DEV_NFP3800_VF, + NFP_DEV_NFP6000, + NFP_DEV_NFP6000_VF, + NFP_DEV_CNT, +}; + +struct nfp_dev_info { + /* Required fields */ + uint32_t qc_idx_mask; + uint32_t qc_addr_offset; + uint32_t min_qc_size; + uint32_t max_qc_size; + + /* PF-only fields */ + const char *chip_names; + uint32_t pcie_cfg_expbar_offset; + uint32_t qc_area_sz; + uint8_t pf_num_per_unit; +}; + +const struct nfp_dev_info *nfp_dev_info_get(uint16_t device_id); + +#endif /* __NFP_DEV_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 23/27] net/nfp: add header file for PCIe module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (21 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 22/27] net/nfp: add the dev module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 24/27] net/nfp: refact the cppcore module Chaoyong He ` (5 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Add a new header file for the PCIe module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/meson.build | 2 +- .../nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} | 2 ++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 13 +++++++++++++ drivers/net/nfp/nfpcore/nfp_cpp.h | 6 ------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) rename drivers/net/nfp/nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} (99%) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 580a478cd6..d422269c4b 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -12,7 +12,6 @@ sources = files( 'flower/nfp_flower_representor.c', 'nfd3/nfp_nfd3_dp.c', 'nfdk/nfp_nfdk_dp.c', - 'nfpcore/nfp_cpp_pcie_ops.c', 'nfpcore/nfp_nsp.c', 'nfpcore/nfp_cppcore.c', 'nfpcore/nfp_resource.c', @@ -26,6 +25,7 @@ sources = files( 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', 'nfpcore/nfp_target.c', + 'nfpcore/nfp6000_pcie.c', 'nfp_common.c', 'nfp_rxtx.c', 'nfp_cpp_bridge.c', diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c similarity index 99% rename from drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c rename to drivers/net/nfp/nfpcore/nfp6000_pcie.c index 310cc691cd..abee584f85 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -14,6 +14,8 @@ * The generic CPP bus abstraction builds upon this BAR interface. */ +#include "nfp6000_pcie.h" + #include <assert.h> #include <stdio.h> #include <stdlib.h> diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h new file mode 100644 index 0000000000..e126457d45 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Netronome Systems, Inc. + * All rights reserved. + */ + +#ifndef __NFP6000_PCIE_H__ +#define __NFP6000_PCIE_H__ + +#include "nfp_cpp.h" + +const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); + +#endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 42c4df5fdd..0df97552cb 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,12 +226,6 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) return id & 0xff; } -/* - * This should be the only external function the transport - * module supplies - */ -const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); - void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index b7eb53697f..965b7a3428 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -14,12 +14,12 @@ #include <rte_byteorder.h> #include <ethdev_pci.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" +#include "nfp6000_pcie.h" #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 24/27] net/nfp: refact the cppcore module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (22 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 23/27] net/nfp: add header file for PCIe module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 25/27] net/nfp: refact the PCIe module Chaoyong He ` (4 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Modify the comment and standard the coding style. Move the definition of data structure into the implement file to make the API small. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 14 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 40 ++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 186 ++++++++++++++++--------- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c index 88cd1aa572..a9998f3c08 100644 --- a/drivers/net/nfp/nfp_cpp_bridge.c +++ b/drivers/net/nfp/nfp_cpp_bridge.c @@ -344,7 +344,7 @@ nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp) return -EIO; } - tmp = cpp->interface; + tmp = nfp_cpp_interface(cpp); PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index c37d8a1449..5d129d0ad3 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -654,15 +654,23 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) char fw_name[125]; char serial[40]; size_t fsize; + uint16_t interface; + uint32_t cpp_serial_len; + const uint8_t *cpp_serial; + + cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial); + if (cpp_serial_len != NFP_SERIAL_LEN) + return -ERANGE; + + interface = nfp_cpp_interface(cpp); /* Looking for firmware file in order of priority */ /* First try to find a firmware image specific for this device */ snprintf(serial, sizeof(serial), "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3], - cpp->serial[4], cpp->serial[5], cpp->interface >> 8, - cpp->interface & 0xff); + cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3], + cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff); snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH, serial); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index abee584f85..45645e04f8 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -739,7 +739,7 @@ nfp6000_init(struct nfp_cpp *cpp, strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; @@ -778,7 +778,7 @@ nfp6000_free(struct nfp_cpp *cpp) struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); nfp_disable_bars(desc); - if (cpp->driver_lock_needed) + if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); free(desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0df97552cb..34ed50ceca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -9,38 +9,12 @@ #include <ethdev_pci.h> /* NFP CPP handle */ -struct nfp_cpp { - uint32_t model; - uint32_t interface; - uint8_t *serial; - int serial_len; - void *priv; - - /* Mutex cache */ - struct nfp_cpp_mutex *mutex_cache; - const struct nfp_cpp_operations *op; - - /* - * NFP-6xxx originating island IMB CPP Address Translation. CPP Target - * ID is index into array. Values are obtained at runtime from local - * island XPB CSRs. - */ - uint32_t imb_cat_table[16]; - - /* MU access type bit offset */ - uint32_t mu_locality_lsb; - - int driver_lock_needed; -}; +struct nfp_cpp; /* NFP CPP device area handle */ -struct nfp_cpp_area { - struct nfp_cpp *cpp; - char *name; - unsigned long long offset; - unsigned long size; - /* Here follows the 'priv' part of nfp_cpp_area. */ -}; +struct nfp_cpp_area; + +#define NFP_SERIAL_LEN 6 /* * NFP CPP operations structure @@ -230,7 +204,7 @@ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); @@ -349,7 +323,9 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); + +bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp); struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 965b7a3428..0c1a03b0ab 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -3,30 +3,56 @@ * All rights reserved. */ -#include <assert.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> - -#include <rte_byteorder.h> -#include <ethdev_pci.h> +#include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_platform.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" -#include "nfp_nffw.h" #include "nfp6000_pcie.h" +#define NFP_PL_DEVICE_PART_NFP6000 0x6200 #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff #define NFP_PL_DEVICE_PART_MASK 0xffff0000 #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/* NFP CPP handle */ +struct nfp_cpp { + void *priv; /**< Private data of the low-level implementation */ + + uint32_t model; /**< Chip model */ + uint16_t interface; /**< Chip interface id */ + uint8_t serial[NFP_SERIAL_LEN]; /**< Chip serial number */ + + /** Low-level implementation ops */ + const struct nfp_cpp_operations *op; + + /* + * NFP-6xxx originating island IMB CPP Address Translation. CPP Target + * ID is index into array. Values are obtained at runtime from local + * island XPB CSRs. + */ + uint32_t imb_cat_table[16]; + + /**< MU access type bit offset */ + uint32_t mu_locality_lsb; + + bool driver_lock_needed; +}; + +/* NFP CPP device area handle */ +struct nfp_cpp_area { + struct nfp_cpp *cpp; + char *name; + uint64_t offset; + uint32_t size; + /* Here follows the 'priv' part of nfp_cpp_area. */ + /* Here follows the ASCII name, pointed by @name */ +}; + /** * Set the private data of the nfp_cpp instance * @@ -125,12 +151,13 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, * @return * Length of NFP serial number */ -int +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) { - *serial = cpp->serial; - return cpp->serial_len; + *serial = &cpp->serial[0]; + + return sizeof(cpp->serial); } /** @@ -143,22 +170,12 @@ nfp_cpp_serial(struct nfp_cpp *cpp, * @param serial_len * Length of the serial byte array */ -int +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len) { - if (cpp->serial_len) - free(cpp->serial); - - cpp->serial = malloc(serial_len); - if (cpp->serial == NULL) - return -1; - memcpy(cpp->serial, serial, serial_len); - cpp->serial_len = serial_len; - - return 0; } /** @@ -179,6 +196,21 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Retrieve the driver need lock flag + * + * @param cpp + * NFP CPP handle + * + * @return + * The driver need lock flag + */ +bool +nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp) +{ + return cpp->driver_lock_needed; +} + /** * Get the privately allocated portion of a NFP CPP area handle * @@ -283,39 +315,40 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t size) { int err; + size_t name_len; + uint32_t target_id; + uint64_t target_addr; struct nfp_cpp_area *area; - uint64_t tmp64 = (uint64_t)address; if (cpp == NULL) return NULL; /* Remap from cpp_island to cpp_target */ - err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table); + err = nfp_target_cpp(dest, address, &target_id, &target_addr, + cpp->imb_cat_table); if (err < 0) return NULL; - address = tmp64; - if (name == NULL) - name = ""; + name = "(reserved)"; - area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + name_len = strlen(name) + 1; + area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + name_len); if (area == NULL) return NULL; area->cpp = cpp; area->name = ((char *)area) + sizeof(*area) + cpp->op->area_priv_size; - memcpy(area->name, name, strlen(name) + 1); + memcpy(area->name, name, name_len); - err = cpp->op->area_init(area, dest, address, size); + err = cpp->op->area_init(area, target_id, target_addr, size); if (err < 0) { PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } - area->offset = address; + area->offset = target_addr; area->size = size; return area; @@ -555,26 +588,28 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, * Ensure that non-local XPB accesses go out through the * global XPBM bus. */ - island = ((*xpb_addr) >> 24) & 0x3f; + island = (*xpb_addr >> 24) & 0x3f; if (island == 0) return xpb; - if (island == 1) { - /* - * Accesses to the ARM Island overlay uses Island 0 - * Global Bit - */ - (*xpb_addr) &= ~0x7f000000; - if (*xpb_addr < 0x60000) - *xpb_addr |= (1 << 30); - else - /* And only non-ARM interfaces use island id = 1 */ - if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) - *xpb_addr |= (1 << 24); + if (island != 1) { + *xpb_addr |= (1 << 30); + return xpb; + } + + /* + * Accesses to the ARM Island overlay uses Island 0 + * Global Bit + */ + *xpb_addr &= ~0x7f000000; + if (*xpb_addr < 0x60000) { + *xpb_addr |= (1 << 30); } else { - (*xpb_addr) |= (1 << 30); + /* And only non-ARM interfaces use island id = 1 */ + if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != + NFP_CPP_INTERFACE_TYPE_ARM) + *xpb_addr |= (1 << 24); } return xpb; @@ -602,9 +637,12 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -629,7 +667,10 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, value = rte_cpu_to_le_32(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - return (sz == sizeof(value)) ? 0 : -1; + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; + + return 0; } /** @@ -654,9 +695,12 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, uint64_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_64(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -681,8 +725,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, value = rte_cpu_to_le_64(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -710,9 +756,12 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t tmp; sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -740,8 +789,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, value = rte_cpu_to_le_32(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -770,8 +821,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); *value = rte_le_to_cpu_64(tmp); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -799,8 +852,10 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, value = rte_cpu_to_le_64(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -918,9 +973,6 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len != 0) - free(cpp->serial); - rte_free(cpp); } @@ -974,7 +1026,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); - return -1; + return -EACCES; } err = nfp_cpp_area_read(area, 0, address, length); @@ -1013,7 +1065,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); - return -1; + return -EACCES; } err = nfp_cpp_area_write(area, 0, address, length); @@ -1039,8 +1091,12 @@ nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) - *model -= 0x10; + /* Disambiguate the NFP4000/NFP5000/NFP6000 chips */ + if (FIELD_GET(NFP_PL_DEVICE_PART_MASK, reg) == + NFP_PL_DEVICE_PART_NFP6000) { + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) + *model -= 0x10; + } return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 25/27] net/nfp: refact the PCIe module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (23 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 24/27] net/nfp: refact the cppcore module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 26/27] net/nfp: refact the cppcore and " Chaoyong He ` (3 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 211 +++++++++++++++++-------- drivers/net/nfp/nfpcore/nfp_cpp.h | 9 ++ 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 45645e04f8..4f453f19a9 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -16,23 +16,8 @@ #include "nfp6000_pcie.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> #include <unistd.h> -#include <stdint.h> -#include <stdbool.h> #include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <dirent.h> -#include <libgen.h> - -#include <sys/mman.h> -#include <sys/file.h> -#include <sys/stat.h> - -#include <ethdev_pci.h> #include "nfp_cpp.h" #include "nfp_logs.h" @@ -43,8 +28,11 @@ #define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) +#define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(_x) (((_x) >> 16) & 0x1f) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) +#define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS_OF(_x) (((_x) >> 0) & 0xffff) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT(_x) (((_x) & 0x3) << 27) +#define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(_x) (((_x) >> 27) & 0x3) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT 0 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT 1 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE 3 @@ -55,7 +43,9 @@ #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET 2 #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL 3 #define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(_x) (((_x) & 0xf) << 23) +#define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(_x) (((_x) >> 23) & 0xf) #define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(_x) (((_x) & 0x3) << 21) +#define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(_x) (((_x) >> 21) & 0x3) /* * Minimal size of the PCIe cfg memory we depend on being mapped, @@ -132,7 +122,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (target >= 16) + if (target >= NFP_CPP_NUM_TARGETS) return -EINVAL; switch (width) { @@ -182,10 +172,6 @@ nfp_compute_bar(const struct nfp_bar *bar, offset &= mask; bitsize = 40 - 21; } - - if (bar->bitsize < bitsize) - return -EINVAL; - newcfg |= offset >> bitsize; if (bar_base != NULL) @@ -434,7 +420,7 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Must have been too big. Sub-allocate. */ if (priv->bar->iomem == NULL) - return (-ENOMEM); + return -ENOMEM; priv->iomem = priv->bar->iomem + priv->bar_offset; @@ -464,9 +450,9 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32 = address; uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; @@ -484,47 +470,54 @@ nfp6000_area_read(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } - is_64 = width == TARGET_WIDTH_64; - - /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { - is_64 = false; - } + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; + ret = n; + break; + default: + return -EINVAL; + } + + return ret; } static int @@ -533,9 +526,9 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; @@ -553,47 +546,53 @@ nfp6000_area_write(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; - is_64 = width == TARGET_WIDTH_64; - - /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) - is_64 = false; + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; -} + ret = n; + break; + default: + return -EINVAL; + } -#define PCI_DEVICES "/sys/bus/pci/devices" + return ret; +} static int nfp_acquire_process_lock(struct nfp_pcie_user *desc) @@ -706,6 +705,74 @@ nfp6000_set_serial(struct rte_pci_device *dev, return 0; } +static int +nfp6000_get_dsn(struct rte_pci_device *pci_dev, + uint64_t *dsn) +{ + off_t pos; + size_t len; + uint64_t tmp = 0; + + pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN); + if (pos <= 0) { + PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found"); + return -ENODEV; + } + + pos += 4; + len = sizeof(tmp); + + if (rte_pci_read_config(pci_dev, &tmp, len, pos) < 0) { + PMD_DRV_LOG(ERR, "nfp get device serial number failed"); + return -ENOENT; + } + + *dsn = tmp; + + return 0; +} + +static int +nfp6000_get_interface(struct rte_pci_device *dev, + uint16_t *interface) +{ + int ret; + uint64_t dsn = 0; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + *interface = dsn & 0xffff; + + return 0; +} + +static int +nfp6000_get_serial(struct rte_pci_device *dev, + uint8_t *serial, + size_t length) +{ + int ret; + uint64_t dsn = 0; + + if (length < NFP_SERIAL_LEN) + return -ENOMEM; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + serial[0] = (dsn >> 56) & 0xff; + serial[1] = (dsn >> 48) & 0xff; + serial[2] = (dsn >> 40) & 0xff; + serial[3] = (dsn >> 32) & 0xff; + serial[4] = (dsn >> 24) & 0xff; + serial[5] = (dsn >> 16) & 0xff; + + return 0; +} + static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) @@ -789,6 +856,10 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .free = nfp6000_free, .area_priv_size = sizeof(struct nfp6000_area_priv), + + .get_interface = nfp6000_get_interface, + .get_serial = nfp6000_get_serial, + .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 34ed50ceca..0f36ba0b50 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -16,6 +16,8 @@ struct nfp_cpp_area; #define NFP_SERIAL_LEN 6 +#define NFP_CPP_NUM_TARGETS 16 + /* * NFP CPP operations structure */ @@ -33,6 +35,13 @@ struct nfp_cpp_operations { */ void (*free)(struct nfp_cpp *cpp); + int (*get_interface)(struct rte_pci_device *dev, + uint16_t *interface); + + int (*get_serial)(struct rte_pci_device *dev, + uint8_t *serial, + size_t length); + /* * Initialize a new NFP CPP area * NOTE: This is _not_ serialized -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 26/27] net/nfp: refact the cppcore and PCIe module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (24 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 25/27] net/nfp: refact the PCIe module Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He ` (2 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Sync the logic from kernel driver, use the new entry function from the PCIe module instead of the cppcore module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 9 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 197 ++++++++++--------------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 6 + drivers/net/nfp/nfpcore/nfp_cpp.h | 36 +---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 68 ++++++--- 5 files changed, 141 insertions(+), 175 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 5d129d0ad3..6eefec3836 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -23,6 +23,7 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.h" #include "nfpcore/nfp_nsp.h" +#include "nfpcore/nfp6000_pcie.h" #include "nfp_common.h" #include "nfp_ctrl.h" @@ -917,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1120,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 4f453f19a9..e32ac1107c 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -98,6 +98,24 @@ struct nfp_pcie_user { char *cfg; }; +/* Generic CPP bus access interface. */ +struct nfp6000_area_priv { + struct nfp_bar *bar; + uint32_t bar_offset; + + int target; + int action; + int token; + uint64_t offset; + struct { + int read; + int write; + int bar; + } width; + size_t size; + char *iomem; +}; + static uint32_t nfp_bar_maptype(struct nfp_bar *bar) { @@ -334,24 +352,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* Generic CPP bus access interface. */ -struct nfp6000_area_priv { - struct nfp_bar *bar; - uint32_t bar_offset; - - uint32_t target; - uint32_t action; - uint32_t token; - uint64_t offset; - struct { - int read; - int write; - int bar; - } width; - size_t size; - char *iomem; -}; - static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, @@ -624,87 +624,6 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) return 0; } -static int -nfp6000_set_model(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint32_t model; - - if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { - PMD_DRV_LOG(ERR, "nfp set model failed"); - return -1; - } - - model = model << 16; - nfp_cpp_model_set(cpp, model); - - return 0; -} - -static int -nfp6000_set_interface(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint16_t interface; - - if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { - PMD_DRV_LOG(ERR, "nfp set interface failed"); - return -1; - } - - nfp_cpp_interface_set(cpp, interface); - - return 0; -} - -static int -nfp6000_set_serial(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - off_t pos; - uint16_t tmp; - uint8_t serial[6]; - int serial_len = 6; - - pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); - if (pos <= 0) { - PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found. nfp set serial failed"); - return -1; - } else { - pos += 6; - } - - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[4] = (uint8_t)((tmp >> 8) & 0xff); - serial[5] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[2] = (uint8_t)((tmp >> 8) & 0xff); - serial[3] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[0] = (uint8_t)((tmp >> 8) & 0xff); - serial[1] = (uint8_t)(tmp & 0xff); - - nfp_cpp_serial_set(cpp, serial, serial_len); - - return 0; -} - static int nfp6000_get_dsn(struct rte_pci_device *pci_dev, uint64_t *dsn) @@ -795,12 +714,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { int ret = 0; - struct nfp_pcie_user *desc; - - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return -1; - + struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); @@ -809,17 +723,11 @@ nfp6000_init(struct nfp_cpp *cpp, nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) - goto error; + return -1; } - if (nfp6000_set_model(dev, cpp) < 0) - goto error; - if (nfp6000_set_interface(dev, cpp) < 0) - goto error; - if (nfp6000_set_serial(dev, cpp) < 0) - goto error; if (nfp6000_set_barsz(dev, desc) < 0) - goto error; + return -1; desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; @@ -830,13 +738,7 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - nfp_cpp_priv_set(cpp, desc); - return 0; - -error: - free(desc); - return -1; } static void @@ -848,7 +750,7 @@ nfp6000_free(struct nfp_cpp *cpp) if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); - free(desc); + rte_free(desc); } static const struct nfp_cpp_operations nfp6000_pcie_ops = { @@ -873,3 +775,58 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) { return &nfp6000_pcie_ops; } + +/** + * Build a NFP CPP bus from a NFP6000 PCI device + * + * @param pdev + * NFP6000 PCI device + * @param driver_lock_needed + * driver lock flag + * + * @return + * NFP CPP handle or NULL + */ +struct nfp_cpp * +nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed) +{ + int ret; + struct nfp_cpp *cpp; + uint16_t interface = 0; + struct nfp_pcie_user *nfp; + + nfp = rte_zmalloc(NULL, sizeof(*nfp), 0); + if (nfp == NULL) + return NULL; + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + rte_free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_TYPE_of(interface) != NFP_CPP_INTERFACE_TYPE_PCI) { + PMD_DRV_LOG(ERR, "Interface type is not right."); + rte_free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_CHANNEL_of(interface) != + NFP_CPP_INTERFACE_CHANNEL_PEROPENER) { + PMD_DRV_LOG(ERR, "Interface channel is not right"); + rte_free(nfp); + return NULL; + } + + /* Probe for all the common NFP devices */ + cpp = nfp_cpp_from_device_name(pci_dev, nfp, driver_lock_needed); + if (cpp == NULL) { + PMD_DRV_LOG(ERR, "Get cpp from operation failed"); + rte_free(nfp); + return NULL; + } + + return cpp; +} diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index e126457d45..8847f6f946 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -6,8 +6,14 @@ #ifndef __NFP6000_PCIE_H__ #define __NFP6000_PCIE_H__ +#include <ethdev_pci.h> + #include "nfp_cpp.h" +#include "nfp_dev.h" const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); +struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed); + #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0f36ba0b50..e879c7c920 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,40 +226,12 @@ uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + void *priv, bool driver_lock_needed); void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/** - * Retrieve the chip ID from the model ID - * - * The chip ID is a 16-bit BCD+A-F encoding for the chip type. - * - * @param model - * NFP CPP model id - * - * @return - * NFP CPP chip id - */ -#define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) - -/** - * Check for the NFP6000 family of devices - * - * NOTE: The NFP4000 series is considered as a NFP6000 series variant. - * - * @param model - * NFP CPP model id - * - * @return - * true if model is in the NFP6000 family, false otherwise. - */ -#define NFP_CPP_MODEL_IS_6000(model) \ - ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ - (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) - uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,6 +302,12 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) +/* + * Use this channel ID for multiple virtual channel interfaces + * (ie ARM and PCIe) when setting up the interface field. + */ +#define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255 + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 0c1a03b0ab..d70c8cd44a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -909,10 +909,13 @@ nfp_xpb_readl(struct nfp_cpp *cpp, } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, - int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *pci_dev, + void *priv, + bool driver_lock_needed) { int err; + size_t target; + uint32_t xpb_addr; struct nfp_cpp *cpp; const struct nfp_cpp_operations *ops; @@ -925,32 +928,50 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return NULL; cpp->op = ops; + cpp->priv = priv; cpp->driver_lock_needed = driver_lock_needed; - if (cpp->op->init) { - err = cpp->op->init(cpp, dev); + err = ops->get_interface(pci_dev, &cpp->interface); + if (err != 0) { + rte_free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + rte_free(cpp); + return NULL; + } + + /* + * NOTE: cpp_lock is NOT locked for op->init, + * since it may call NFP CPP API operations + */ + err = cpp->op->init(cpp, pci_dev); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP interface initialization failed"); + rte_free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + rte_free(cpp); + return NULL; + } + + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { + /* Hardcoded XPB IMB Base, island 0 */ + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, &cpp->imb_cat_table[target]); if (err < 0) { + PMD_DRV_LOG(ERR, "Can't read CPP mapping from device"); rte_free(cpp); return NULL; } } - if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpb_addr; - size_t target; - - for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { - /* Hardcoded XPB IMB Base, island 0 */ - xpb_addr = 0x000a0000 + (target * 4); - err = nfp_xpb_readl(cpp, xpb_addr, - (uint32_t *)&cpp->imb_cat_table[target]); - if (err < 0) { - rte_free(cpp); - return NULL; - } - } - } - err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); @@ -981,6 +1002,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) * * @param dev * PCI device + * @param priv + * Private data of low-level implementation * @param driver_lock_needed * Driver lock flag * @@ -991,9 +1014,10 @@ nfp_cpp_free(struct nfp_cpp *cpp) */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed) + void *priv, + bool driver_lock_needed) { - return nfp_cpp_alloc(dev, driver_lock_needed); + return nfp_cpp_alloc(dev, priv, driver_lock_needed); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v3 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (25 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 26/27] net/nfp: refact the cppcore and " Chaoyong He @ 2023-09-15 9:15 ` Chaoyong He 2023-09-15 13:49 ` [PATCH v3 00/27] refact the nfpcore module Ferruh Yigit 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-15 9:15 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He, Niklas Söderlund Sync the logic from kernel driver, adjust the definition of structure, and extend the usage of nfp BAR from 8 to 24. This will greatly enhance the scalability of nfp PMD. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 8 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 478 ++++++++++++++++++------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 1 + drivers/net/nfp/nfpcore/nfp_cpp.h | 5 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 349 insertions(+), 145 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 6eefec3836..d6454d8964 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -918,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1121,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index e32ac1107c..709177a80e 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -19,6 +19,8 @@ #include <unistd.h> #include <fcntl.h> +#include <rte_io.h> + #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" @@ -59,20 +61,12 @@ #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4)) #define NFP_PCIE_P2C_GENERAL_SIZE(bar) (1 << ((bar)->bitsize - 4)) -#define NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(id, bar, slot) \ - (NFP_PCIE_BAR(id) + ((bar) * 8 + (slot)) * 4) - -#define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ - (((bar) * 8 + (slot)) * 4) +#define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index) ((bar_index) * 4) struct nfp_pcie_user; struct nfp6000_area_priv; /* Describes BAR configuration and usage */ -#define NFP_BAR_MIN 1 -#define NFP_BAR_MID 5 -#define NFP_BAR_MAX 7 - struct nfp_bar { struct nfp_pcie_user *nfp; /**< Backlink to owner */ uint32_t barcfg; /**< BAR config CSR */ @@ -80,22 +74,26 @@ struct nfp_bar { uint64_t mask; /**< Mask of the BAR aperture (read only) */ uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ uint32_t index; /**< Index of the BAR */ - int lock; /**< If the BAR has been locked */ + bool lock; /**< If the BAR has been locked */ - char *csr; char *iomem; /**< mapped IO memory */ + struct rte_mem_resource *resource; /**< IOMEM resource window */ }; -#define BUSDEV_SZ 13 +#define NFP_PCI_BAR_MAX (PCI_64BIT_BAR_COUNT * 8) + struct nfp_pcie_user { - struct nfp_bar bar[NFP_BAR_MAX]; + struct rte_pci_device *pci_dev; + const struct nfp_dev_info *dev_info; - int device; int lock; - char busdev[BUSDEV_SZ]; - int barsz; - int dev_id; - char *cfg; + + /* PCI BAR management */ + uint32_t bars; + struct nfp_bar bar[NFP_PCI_BAR_MAX]; + + /* Reserved BAR access */ + char *csr; }; /* Generic CPP bus access interface. */ @@ -206,19 +204,19 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base; - int slot; - - base = bar->index >> 3; - slot = bar->index & 7; + uint32_t xbar; - if (nfp->cfg == NULL) - return (-ENOMEM); + xbar = NFP_PCIE_P2C_EXPBAR_OFFSET(bar->index); - bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); - - *(uint32_t *)(bar->csr) = newcfg; + if (nfp->csr != NULL) { + rte_write32(newcfg, nfp->csr + xbar); + /* Readback to ensure BAR is flushed */ + rte_read32(nfp->csr + xbar); + } else { + xbar += nfp->dev_info->pcie_cfg_expbar_offset; + rte_pci_write_config(nfp->pci_dev, &newcfg, sizeof(uint32_t), + xbar); + } bar->barcfg = newcfg; @@ -249,105 +247,323 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, return nfp_bar_write(nfp, bar, newcfg); } -/* - * Map all PCI bars. We assume that the BAR with the PCIe config block is - * already mapped. +static uint32_t +nfp_bitsize_calc(uint64_t mask) +{ + uint64_t tmp = mask; + uint32_t bit_size = 0; + + if (tmp == 0) + return 0; + + for (; tmp != 0; tmp >>= 1) + bit_size++; + + return bit_size; +} + +static int +nfp_cmp_bars(const void *ptr_a, + const void *ptr_b) +{ + const struct nfp_bar *a = ptr_a; + const struct nfp_bar *b = ptr_b; + + if (a->bitsize == b->bitsize) + return a->index - b->index; + else + return a->bitsize - b->bitsize; +} + +static bool +nfp_bars_for_secondary(uint32_t index) +{ + uint8_t tmp = index & 0x07; + + if (tmp == 0x06 || tmp == 0x07) + return true; + else + return false; +} + +/** + * Map all PCI bars and fetch the actual BAR configurations from the board. + * We assume that the BAR with the PCIe config block is already mapped. * * BAR0.0: Reserved for General Mapping (for MSI-X access to PCIe SRAM) + * BAR0.1: -- + * BAR0.2: -- + * BAR0.3: -- + * BAR0.4: -- + * BAR0.5: -- + * BAR0.6: -- + * BAR0.7: -- * - * Halving PCItoCPPBars for primary and secondary processes. - * For CoreNIC firmware: - * NFP PMD just requires two fixed slots, one for configuration BAR, - * and another for accessing the hw queues. Another slot is needed - * for setting the link up or down. Secondary processes do not need - * to map the first two slots again, but it requires one slot for - * accessing the link, even if it is not likely the secondary process - * starting the port. - * For Flower firmware: - * NFP PMD need another fixed slots, used as the configureation BAR - * for ctrl vNIC. + * BAR1.0-BAR1.7: -- + * BAR2.0-BAR2.7: -- */ static int nfp_enable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + int pf; + uint32_t i; + uint8_t min_bars; struct nfp_bar *bar; + enum rte_proc_type_t type; + struct rte_mem_resource *res; + const uint32_t barcfg_msix_general = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) | + NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT; + + type = rte_eal_process_type(); + if (type == RTE_PROC_PRIMARY) + min_bars = 12; + else + min_bars = 4; + + for (i = 0; i < RTE_DIM(nfp->bar); i++) { + if (i != 0) { + if (type == RTE_PROC_PRIMARY) { + if (nfp_bars_for_secondary(i)) + continue; + } else { + if (!nfp_bars_for_secondary(i)) + continue; + } + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* 24 NFP bars mapping into BAR0, BAR2 and BAR4 */ + res = &nfp->pci_dev->mem_resource[(i >> 3) * 2]; + + /* Skip over BARs that are not mapped */ + if (res->addr != NULL) { + bar = &nfp->bar[i]; + bar->resource = res; + bar->barcfg = 0; + + bar->nfp = nfp; + bar->index = i; + /* The resource shared by 8 bars */ + bar->mask = (res->len >> 3) - 1; + bar->bitsize = nfp_bitsize_calc(bar->mask); + bar->base = 0; + bar->lock = false; + bar->iomem = (char *)res->addr + + ((bar->index & 7) << bar->bitsize); + + nfp->bars++; + } + } + + if (nfp->bars < min_bars) { + PMD_DRV_LOG(ERR, "Not enough usable BARs found."); + return -EINVAL; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - bar->barcfg = 0; - bar->nfp = nfp; - bar->index = x; - bar->mask = (1 << (nfp->barsz - 3)) - 1; - bar->bitsize = nfp->barsz - 3; - bar->base = 0; - bar->iomem = NULL; - bar->lock = 0; - bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, - bar->index >> 3, bar->index & 7); - bar->iomem = nfp->cfg + (bar->index << bar->bitsize); + switch (nfp->pci_dev->id.device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + pf = nfp->pci_dev->addr.function & 0x07; + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(pf); + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(0); + break; + default: + PMD_DRV_LOG(ERR, "Unsupported device ID: %04hx!", + nfp->pci_dev->id.device_id); + return -EINVAL; } + + /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */ + bar = &nfp->bar[0]; + bar->lock = true; + + nfp_bar_write(nfp, bar, barcfg_msix_general); + + /* Sort bars by bit size - use the smallest possible first. */ + qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars); + return 0; } -static struct nfp_bar * -nfp_alloc_bar(struct nfp_pcie_user *nfp) +/* Check if BAR can be used with the given parameters. */ +static bool +matching_bar_exist(struct nfp_bar *bar, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) { - int x; - int end; - int start; - struct nfp_bar *bar; + int bar_width; + int bar_token; + int bar_target; + int bar_action; + uint32_t map_type; + + bar_width = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(bar->barcfg); + switch (bar_width) { + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT: + bar_width = 4; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT: + bar_width = 8; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE: + bar_width = 0; + break; + default: + bar_width = -1; + break; + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* Make sure to match up the width */ + if (bar_width != width) + return false; + + bar_token = NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(bar->barcfg); + bar_action = NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(bar->barcfg); + map_type = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_OF(bar->barcfg); + switch (map_type) { + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET: + bar_token = -1; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK: + bar_action = NFP_CPP_ACTION_RW; + if (action == 0) + action = NFP_CPP_ACTION_RW; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED: + break; + default: + /* We don't match explicit bars through the area interface */ + return false; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->lock == 0) { - bar->lock = 1; - return bar; - } + bar_target = NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(bar->barcfg); + if ((bar_target < 0 || bar_target == target) && + (bar_token < 0 || bar_token == token) && + bar_action == action && + bar->base <= offset && + (bar->base + (1 << bar->bitsize)) >= (offset + size)) + return true; + + /* No match */ + return false; +} + +static int +find_matching_bar(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + uint32_t n; + + for (n = 0; n < nfp->bars; n++) { + struct nfp_bar *bar = &nfp->bar[n]; + + if (bar->lock) + continue; + + if (matching_bar_exist(bar, target, action, token, + offset, size, width)) + return n; + } + + return -1; +} + +/* Return EAGAIN if no resource is available */ +static int +find_unused_bar_noblock(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + int ret; + uint32_t n; + const struct nfp_bar *bar; + + for (n = 0; n < nfp->bars; n++) { + bar = &nfp->bar[n]; + + if (bar->bitsize == 0) + continue; + + /* Just check to see if we can make it fit... */ + ret = nfp_compute_bar(bar, NULL, NULL, target, action, + token, offset, size, width); + if (ret != 0) + continue; + + if (!bar->lock) + return n; + } + + return -EAGAIN; +} + +static int +nfp_alloc_bar(struct nfp_pcie_user *nfp, + struct nfp6000_area_priv *priv) +{ + int ret; + int bar_num; + size_t size = priv->size; + int token = priv->token; + int target = priv->target; + int action = priv->action; + int width = priv->width.bar; + uint64_t offset = priv->offset; + + /* Bar size should small than 16MB */ + if (size > (1 << 24)) + return -EINVAL; + + bar_num = find_matching_bar(nfp, target, action, token, + offset, size, width); + if (bar_num >= 0) { + /* Found a perfect match. */ + nfp->bar[bar_num].lock = true; + return bar_num; } - return NULL; + bar_num = find_unused_bar_noblock(nfp, target, action, token, + offset, size, width); + if (bar_num < 0) + return bar_num; + + nfp->bar[bar_num].lock = true; + ret = nfp_reconfigure_bar(nfp, &nfp->bar[bar_num], + target, action, token, offset, size, width); + if (ret < 0) { + nfp->bar[bar_num].lock = false; + return ret; + } + + return bar_num; } static void nfp_disable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + uint32_t i; struct nfp_bar *bar; - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; - } - - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->iomem) { + for (i = 0; i < nfp->bars; i++) { + bar = &nfp->bar[i]; + if (bar->iomem != NULL) { bar->iomem = NULL; - bar->lock = 0; + bar->lock = false; } } } @@ -364,7 +580,6 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -383,9 +598,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, else priv->width.bar = priv->width.write; - priv->bar = nfp_alloc_bar(nfp); - if (priv->bar == NULL) - return -ENOMEM; + priv->bar = NULL; priv->target = target; priv->action = action; @@ -393,17 +606,29 @@ nfp6000_area_init(struct nfp_cpp_area *area, priv->offset = address; priv->size = size; - ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); - return ret; } static int nfp6000_area_acquire(struct nfp_cpp_area *area) { + int bar_num; struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); + + /* Already allocated. */ + if (priv->bar != NULL) + return 0; + + bar_num = nfp_alloc_bar(nfp, priv); + if (bar_num < 0) { + PMD_DRV_LOG(ERR, "Failed to allocate bar %d:%d:%d:%#lx: %d", + priv->target, priv->action, priv->token, + priv->offset, bar_num); + return bar_num; + } + + priv->bar = &nfp->bar[bar_num]; /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == @@ -432,7 +657,7 @@ nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - priv->bar->lock = 0; + priv->bar->lock = false; priv->bar = NULL; priv->iomem = NULL; } @@ -603,7 +828,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) memset(&lock, 0, sizeof(lock)); - snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", desc->busdev); + snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", + desc->pci_dev->device.name); desc->lock = open(lockname, O_RDWR | O_CREAT, 0666); if (desc->lock < 0) return desc->lock; @@ -693,32 +919,11 @@ nfp6000_get_serial(struct rte_pci_device *dev, } static int -nfp6000_set_barsz(struct rte_pci_device *dev, - struct nfp_pcie_user *desc) -{ - int i = 0; - uint64_t tmp; - - tmp = dev->mem_resource[0].len; - - while (tmp >>= 1) - i++; - - desc->barsz = i; - - return 0; -} - -static int -nfp6000_init(struct nfp_cpp *cpp, - struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp) { int ret = 0; struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - memset(desc->busdev, 0, BUSDEV_SZ); - strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); - if (rte_eal_process_type() == RTE_PROC_PRIMARY && nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); @@ -726,12 +931,6 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - if (nfp6000_set_barsz(dev, desc) < 0) - return -1; - - desc->cfg = dev->mem_resource[0].addr; - desc->dev_id = dev->addr.function & 0x7; - ret = nfp_enable_bars(desc); if (ret != 0) { PMD_DRV_LOG(ERR, "Enable bars failed"); @@ -749,7 +948,6 @@ nfp6000_free(struct nfp_cpp *cpp) nfp_disable_bars(desc); if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); - close(desc->device); rte_free(desc); } @@ -789,6 +987,7 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) */ struct nfp_cpp * nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed) { int ret; @@ -800,6 +999,9 @@ nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, if (nfp == NULL) return NULL; + nfp->pci_dev = pci_dev; + nfp->dev_info = dev_info; + ret = nfp6000_get_interface(pci_dev, &interface); if (ret != 0) { PMD_DRV_LOG(ERR, "Get interface failed."); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index 8847f6f946..8e2cfb69e6 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -14,6 +14,7 @@ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed); #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index e879c7c920..2defc4fa16 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -18,6 +18,8 @@ struct nfp_cpp_area; #define NFP_CPP_NUM_TARGETS 16 +#define PCI_64BIT_BAR_COUNT 3 + /* * NFP CPP operations structure */ @@ -26,8 +28,7 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, - struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp); /* * Free the bus. diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index d70c8cd44a..92250c150a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -947,7 +947,7 @@ nfp_cpp_alloc(struct rte_pci_device *pci_dev, * NOTE: cpp_lock is NOT locked for op->init, * since it may call NFP CPP API operations */ - err = cpp->op->init(cpp, pci_dev); + err = cpp->op->init(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "NFP interface initialization failed"); rte_free(cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v3 00/27] refact the nfpcore module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (26 preceding siblings ...) 2023-09-15 9:15 ` [PATCH v3 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He @ 2023-09-15 13:49 ` Ferruh Yigit 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He 28 siblings, 0 replies; 159+ messages in thread From: Ferruh Yigit @ 2023-09-15 13:49 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers On 9/15/2023 10:15 AM, Chaoyong He wrote: > This patch series aims to: > - Make the coding style satisfy with DPDK. > - Sync the logic with kernel driver. > - Make the sub-module more modular. > - Extend the nfp configure BAR from 8 to 24. > > --- > v3: > * Fix one bug in the BAR find logic. > * Modify more coding style. > v2: > * Fix the compile error in Fodora 37 environment. > --- > > Chaoyong He (27): > net/nfp: explicitly compare to null and 0 > net/nfp: unify the indent coding style > net/nfp: unify the type of integer variable > net/nfp: remove the unneeded logic > net/nfp: standard the local variable coding style > net/nfp: adjust the log statement > net/nfp: standard the comment style > net/nfp: using the DPDK memory management API > net/nfp: standard the blank character > net/nfp: unify the guide line of header file > net/nfp: rename some parameter and variable > net/nfp: refact the hwinfo module > net/nfp: refact the nffw module > net/nfp: refact the mip module > net/nfp: refact the rtsym module > net/nfp: refact the resource module > net/nfp: refact the target module > net/nfp: add a new header file > net/nfp: refact the nsp module > net/nfp: refact the mutex module > net/nfp: rename data field to sync with kernel driver > net/nfp: add the dev module > net/nfp: add header file for PCIe module > net/nfp: refact the cppcore module > net/nfp: refact the PCIe module > net/nfp: refact the cppcore and PCIe module > net/nfp: extend the usage of nfp BAR from 8 to 24 > Hi Chaoyong, Niklas, I put some comments on patches, mostly minor comments, only critical one is the decision to use rte memory management widely or not, please check comments. ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 00/26] refact the nfpcore module 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He ` (27 preceding siblings ...) 2023-09-15 13:49 ` [PATCH v3 00/27] refact the nfpcore module Ferruh Yigit @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He ` (28 more replies) 28 siblings, 29 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He This patch series aims to: - Make the coding style satisfy with DPDK. - Sync the logic with kernel driver. - Make the sub-module more modular. - Extend the nfp configure BAR from 8 to 24. --- v4: * Drop the commit 'using the DPDK memory management API'. * Modify the commit message of 'standard the comment style'. * Revise some comment logic as the advice of reviewer. v3: * Fix one bug in the BAR find logic. * Modify more coding style. v2: * Fix the compile error in Fodora 37 environment. --- Chaoyong He (26): net/nfp: explicitly compare to null and 0 net/nfp: unify the indent coding style net/nfp: unify the type of integer variable net/nfp: remove the unneeded logic net/nfp: standard the local variable coding style net/nfp: adjust the log statement net/nfp: standard the comment style net/nfp: standard the blank character net/nfp: unify the guide line of header file net/nfp: rename some parameter and variable net/nfp: refact the hwinfo module net/nfp: refact the nffw module net/nfp: refact the mip module net/nfp: refact the rtsym module net/nfp: refact the resource module net/nfp: refact the target module net/nfp: add a new header file net/nfp: refact the nsp module net/nfp: refact the mutex module net/nfp: rename data field to sync with kernel driver net/nfp: add the dev module net/nfp: add header file for PCIe module net/nfp: refact the cppcore module net/nfp: refact the PCIe module net/nfp: refact the cppcore and PCIe module net/nfp: extend the usage of nfp BAR from 8 to 24 drivers/net/nfp/flower/nfp_flower.c | 12 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 3 +- drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 +- drivers/net/nfp/nfp_common.h | 52 +- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 100 +- drivers/net/nfp/nfp_ethdev_vf.c | 17 +- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 - drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 - drivers/net/nfp/nfpcore/nfp6000_pcie.c | 1035 ++++++++++++++++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 20 + drivers/net/nfp/nfpcore/nfp_cpp.h | 776 +++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 824 ------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 1080 +++++++++++------ drivers/net/nfp/nfpcore/nfp_crc.c | 23 +- drivers/net/nfp/nfpcore/nfp_dev.c | 81 ++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 193 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 74 +- drivers/net/nfp/nfpcore/nfp_mip.c | 97 +- drivers/net/nfp/nfpcore/nfp_mip.h | 7 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 379 +++--- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 + drivers/net/nfp/nfpcore/nfp_nffw.c | 202 +-- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 574 ++++++--- drivers/net/nfp/nfpcore/nfp_nsp.h | 336 ++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 19 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 518 ++++---- drivers/net/nfp/nfpcore/nfp_platform.h | 42 + drivers/net/nfp/nfpcore/nfp_resource.c | 208 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 36 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 452 +++++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 67 +- drivers/net/nfp/nfpcore/nfp_target.c | 9 +- drivers/net/nfp/nfpcore/nfp_target.h | 597 +-------- 40 files changed, 4066 insertions(+), 4007 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.c create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h delete mode 100644 drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 01/26] net/nfp: explicitly compare to null and 0 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 02/26] net/nfp: unify the indent coding style Chaoyong He ` (27 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund To compliance with the coding standard, make the pointer variable explicitly comparing to 'NULL' and the integer variable explicitly comparing to '0'. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 ++++++------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 16 ++++++++-------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 20 ++++++++++---------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_resource.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 4 ++-- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 658c618ee6..2ee60eefc3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -224,10 +224,10 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, newcfg |= offset >> bitsize; - if (bar_base) + if (bar_base != NULL) *bar_base = offset; - if (bar_config) + if (bar_config != NULL) *bar_config = newcfg; return 0; @@ -266,7 +266,7 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); - if (err) + if (err != 0) return err; bar->base = newbase; @@ -515,7 +515,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) { + if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } @@ -583,7 +583,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) + if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; is_64 = width == TARGET_WIDTH_64; @@ -764,7 +764,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) if (rte_eal_process_type() == RTE_PROC_PRIMARY && cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); - if (ret) + if (ret != 0) goto error; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6daee313ce..31338e0047 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -235,7 +235,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, if (area == NULL) return NULL; - if (nfp_cpp_area_acquire(area)) { + if (nfp_cpp_area_acquire(area) != 0) { nfp_cpp_area_free(area); return NULL; } @@ -252,7 +252,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, void nfp_cpp_area_free(struct nfp_cpp_area *area) { - if (area->cpp->op->area_cleanup) + if (area->cpp->op->area_cleanup != NULL) area->cpp->op->area_cleanup(area); free(area); } @@ -280,7 +280,7 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) int nfp_cpp_area_acquire(struct nfp_cpp_area *area) { - if (area->cpp->op->area_acquire) { + if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); if (err < 0) @@ -299,7 +299,7 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) void nfp_cpp_area_release(struct nfp_cpp_area *area) { - if (area->cpp->op->area_release) + if (area->cpp->op->area_release != NULL) area->cpp->op->area_release(area); } @@ -319,7 +319,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) { void *iomem = NULL; - if (area->cpp->op->area_iomem) + if (area->cpp->op->area_iomem != NULL) iomem = area->cpp->op->area_iomem(area); return iomem; @@ -621,10 +621,10 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) void nfp_cpp_free(struct nfp_cpp *cpp) { - if (cpp->op && cpp->op->free) + if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len) + if (cpp->serial_len != 0) free(cpp->serial); free(cpp); @@ -833,7 +833,7 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if (*model & NFP_PL_DEVICE_ID_MASK) + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) *model -= 0x10; return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 9054bb0315..a9d166c4dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -37,7 +37,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { const char *key, *val, *end = hwinfo->data + size; - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { @@ -141,7 +141,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); - if (db) + if (db != NULL) return db; nanosleep(&wait, NULL); @@ -164,7 +164,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return NULL; err = nfp_hwinfo_db_validate(db, hwdb_size); - if (err) { + if (err != 0) { free(db); return NULL; } @@ -188,7 +188,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 6b392ad5eb..f9723dd136 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -75,7 +75,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) return -ENODEV; err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr); - if (err) + if (err != 0) goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); @@ -105,7 +105,7 @@ nfp_mip_open(struct nfp_cpp *cpp) return NULL; err = nfp_mip_read_resource(cpp, mip); - if (err) { + if (err != 0) { free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index f967a29351..0410a00856 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -38,7 +38,7 @@ static int _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) { /* Address must be 64-bit aligned */ - if (address & 7) + if ((address & 7) != 0) return -EINVAL; if (NFP_CPP_MODEL_IS_6000(model)) { diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 07d63900dc..433780a5e7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -190,7 +190,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; for (i = 0; i < cnt; i++) - if (nffw_fwinfo_loaded_get(&fwinfo[i])) + if (nffw_fwinfo_loaded_get(&fwinfo[i]) != 0) return &fwinfo[i]; return NULL; @@ -217,7 +217,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); *off = nffw_fwinfo_mip_offset_get(fwinfo); - if (nffw_fwinfo_mip_mu_da_get(fwinfo)) { + if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 1f6b7bd85c..6474abf0c2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -95,7 +95,7 @@ nfp_nsp_check(struct nfp_nsp *state) return -EINVAL; } - if (reg & NSP_STATUS_BUSY) { + if ((reg & NSP_STATUS_BUSY) != 0) { PMD_DRV_LOG(ERR, "Service processor busy!"); return -EBUSY; } @@ -128,7 +128,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) state->res = res; err = nfp_nsp_check(state); - if (err) { + if (err != 0) { nfp_nsp_close(state); return NULL; } @@ -219,7 +219,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err) + if (err != 0) return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || @@ -245,7 +245,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -254,7 +254,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_STATUS_BUSY to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -266,7 +266,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); @@ -319,13 +319,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); - if (in_buf && in_size) { + if (in_buf != NULL && in_size > 0) { err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf && out_size && out_size > in_size) { + if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, out_size - in_size); @@ -337,7 +337,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (ret < 0) return ret; - if (out_buf && out_size) { + if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); if (err < 0) return err; @@ -369,7 +369,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } - if (err) + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 01b4652280..825a84a8cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -212,7 +212,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, dst->fec_modes_supported |= fec << NFP_FEC_BASER_BIT; fec = FIELD_GET(NSP_ETH_PORT_FEC_SUPP_RS, port); dst->fec_modes_supported |= fec << NFP_FEC_REED_SOLOMON_BIT; - if (dst->fec_modes_supported) + if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); @@ -285,7 +285,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) cnt++; } @@ -294,7 +294,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * those that give a port count, verify it against the value calculated * above. */ - if (ret && ret != cnt) { + if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; @@ -309,7 +309,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); @@ -621,7 +621,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) return -EIO; err = __nfp_eth_set_fec(nsp, mode); - if (err) { + if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 351bc623ed..838cd6e0ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -115,15 +115,15 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, { int err; - if (nfp_cpp_mutex_lock(dev_mutex)) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) return -EINVAL; err = nfp_cpp_resource_find(cpp, res); - if (err) + if (err != 0) goto err_unlock_dev; err = nfp_cpp_mutex_trylock(res->mutex); - if (err) + if (err != 0) goto err_res_mutex_free; nfp_cpp_mutex_unlock(dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 343b0d0bcf..4c45aec5c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -362,10 +362,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) if (err) err = -EIO; exit: - if (error) + if (error != NULL) *error = err; - if (err) + if (err != 0) return ~0ULL; return val; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 02/26] net/nfp: unify the indent coding style 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He 2023-09-18 2:45 ` [PATCH v4 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 11:53 ` Niklas Söderlund 2023-09-18 2:45 ` [PATCH v4 03/26] net/nfp: unify the type of integer variable Chaoyong He ` (26 subsequent siblings) 28 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Each parameter of function should occupy one line, and indent two TAB character. All the statement which span multi line should indent two TAB character. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 80 +++++----- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 152 ++++++++++-------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 173 +++++++++++++-------- drivers/net/nfp/nfpcore/nfp_crc.c | 19 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 23 +-- drivers/net/nfp/nfpcore/nfp_mip.c | 21 ++- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 12 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 108 +++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 19 +-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 72 +++++---- drivers/net/nfp/nfpcore/nfp_resource.c | 29 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 38 +++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 15 +- 17 files changed, 463 insertions(+), 331 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 8f87c09327..54bef3cb6b 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -56,7 +56,8 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp, + struct rte_pci_device *dev); /* * Free the bus. @@ -69,9 +70,9 @@ struct nfp_cpp_operations { * NOTE: This is _not_ serialized */ int (*area_init)(struct nfp_cpp_area *area, - uint32_t dest, - unsigned long long address, - unsigned long size); + uint32_t dest, + unsigned long long address, + unsigned long size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -101,17 +102,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_read)(struct nfp_cpp_area *area, - void *kernel_vaddr, - unsigned long offset, - unsigned int length); + void *kernel_vaddr, + unsigned long offset, + unsigned int length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, - const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + const void *kernel_vaddr, + unsigned long offset, + unsigned int length); }; /* @@ -239,7 +240,7 @@ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); * @param len Length of the serial byte array */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len); + size_t serial_len); /* * Set the private data of the nfp_cpp instance @@ -279,7 +280,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + int driver_lock_needed); /* * Free a NFP CPP handle @@ -397,8 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, - unsigned long size); + unsigned long long address, unsigned long size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,10 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, - const char *name, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, unsigned long long address, + unsigned long size); /* * Free an allocated NFP CPP area handle @@ -448,9 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, unsigned long long address, unsigned long size); /* * Release the resources, then free the NFP CPP area handle @@ -459,8 +455,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, - struct nfp_cpp_area **area); + uint64_t addr, unsigned long size, struct nfp_cpp_area **area); /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -484,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * */ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *buffer, size_t length); + void *buffer, size_t length); /* * Write to a NFP CPP area handle from a buffer. The area must be acquired with @@ -498,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *buffer, size_t length); + const void *buffer, size_t length); /* * nfp_cpp_area_iomem() - get IOMEM region for CPP area @@ -522,7 +517,7 @@ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); * @return 0 on success, negative value on failure. */ int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); + unsigned long long offset, unsigned long size); /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle @@ -552,7 +547,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + unsigned long long address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -566,8 +561,8 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); + unsigned long long address, const void *kernel_vaddr, + size_t length); @@ -582,7 +577,7 @@ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); + uint32_t value, size_t length); /* * Read a single 32-bit value from a NFP CPP area handle @@ -599,7 +594,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value); + uint32_t *value); /* * Write a single 32-bit value to a NFP CPP area handle @@ -616,7 +611,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value); + uint32_t value); /* * Read a single 64-bit value from a NFP CPP area handle @@ -633,7 +628,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value); + uint64_t *value); /* * Write a single 64-bit value to a NFP CPP area handle @@ -650,7 +645,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value); + uint64_t value); /* * Write a single 32-bit value on the XPB bus @@ -685,7 +680,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); * @return 0 on success, or -1 on failure. */ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); + uint32_t value); /* * Modify bits of a 32-bit value from the XPB bus @@ -699,7 +694,7 @@ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, negative value on failure. */ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); + uint32_t value, int timeout_us); /* * Read a 32-bit word from a NFP CPP ID @@ -712,7 +707,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + unsigned long long address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -726,7 +721,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + unsigned long long address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -739,7 +734,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + unsigned long long address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -752,7 +747,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + unsigned long long address, uint64_t value); /* * Initialize a mutex location @@ -773,7 +768,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -793,8 +788,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, - uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 2ee60eefc3..884cc84eaa 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -130,9 +130,15 @@ nfp_bar_maptype(struct nfp_bar *bar) #define TARGET_WIDTH_64 8 static int -nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, - uint64_t *bar_base, int tgt, int act, int tok, - uint64_t offset, size_t size, int width) +nfp_compute_bar(const struct nfp_bar *bar, + uint32_t *bar_config, + uint64_t *bar_base, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint32_t bitsize; uint32_t newcfg; @@ -143,19 +149,16 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, switch (width) { case 8: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); break; case 4: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); break; case 0: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); break; default: return -EINVAL; @@ -165,60 +168,58 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), act, + (unsigned long long)mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + bar->index, tgt, act, tok, (unsigned long long)offset, + (unsigned long long)(offset + mask)); bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); /* Bulk mapping */ - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), + tgt, tok, (unsigned long long)mask, + (unsigned long long)(offset & mask), + (unsigned long long)(offset + size - 1) & mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); + bar->index, tgt, tok, (unsigned long long)offset, + (unsigned long long)(offset + ~mask)); bitsize = 40 - 21; } if (bar->bitsize < bitsize) { PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + tgt, tok, act); return -EINVAL; } @@ -234,8 +235,9 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, } static int -nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - uint32_t newcfg) +nfp_bar_write(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + uint32_t newcfg) { int base, slot; @@ -246,7 +248,7 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, return (-ENOMEM); bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); *(uint32_t *)(bar->csr) = newcfg; @@ -257,15 +259,21 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, } static int -nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, - int act, int tok, uint64_t offset, size_t size, int width) +nfp_reconfigure_bar(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint64_t newbase; uint32_t newcfg; int err; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + size, width); if (err != 0) return err; @@ -390,8 +398,10 @@ struct nfp6000_area_priv { }; static int -nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, unsigned long size) +nfp6000_area_init(struct nfp_cpp_area *area, + uint32_t dest, + unsigned long long address, + unsigned long size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -400,8 +410,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, uint32_t token = NFP_CPP_ID_TOKEN_of(dest); int pp, ret = 0; - pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), - address); + pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) return pp; @@ -409,7 +418,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->width.write = PULL_WIDTH(pp); if (priv->width.read > 0 && - priv->width.write > 0 && priv->width.read != priv->width.write) + priv->width.write > 0 && + priv->width.read != priv->width.write) return -EINVAL; if (priv->width.read > 0) @@ -428,8 +438,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->size = size; ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); + priv->token, priv->offset, priv->size, + priv->width.bar); return ret; } @@ -441,14 +451,13 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { + NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { priv->bar_offset = priv->offset & - (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, - priv->target); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, priv->token); + (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, + priv->target); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, + priv->token); } else { priv->bar_offset = priv->offset & priv->bar->mask; } @@ -490,8 +499,10 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) } static int -nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_read(struct nfp_cpp_area *area, + void *kernel_vaddr, + unsigned long offset, + unsigned int length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -524,17 +535,17 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { + priv->action == NFP_CPP_ACTION_RW) { is_64 = false; } if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -558,8 +569,10 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, } static int -nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_write(struct nfp_cpp_area *area, + const void *kernel_vaddr, + unsigned long offset, + unsigned int length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -590,16 +603,16 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) + priv->action == NFP_CPP_ACTION_RW) is_64 = false; if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -655,7 +668,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) } static int -nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_model(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint32_t model; @@ -671,7 +685,8 @@ nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_interface(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t interface; @@ -686,7 +701,8 @@ nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_serial(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t tmp; uint8_t serial[6]; @@ -733,7 +749,8 @@ nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) +nfp6000_set_barsz(struct rte_pci_device *dev, + struct nfp_pcie_user *desc) { unsigned long tmp; int i = 0; @@ -748,7 +765,8 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) } static int -nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp, + struct rte_pci_device *dev) { int ret = 0; struct nfp_pcie_user *desc; @@ -762,7 +780,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 31338e0047..f764208a9a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -27,7 +27,8 @@ NFP_PL_DEVICE_ID_MASK) void -nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) +nfp_cpp_priv_set(struct nfp_cpp *cpp, + void *priv) { cpp->priv = priv; } @@ -39,7 +40,8 @@ nfp_cpp_priv(struct nfp_cpp *cpp) } void -nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) +nfp_cpp_model_set(struct nfp_cpp *cpp, + uint32_t model) { cpp->model = model; } @@ -62,21 +64,24 @@ nfp_cpp_model(struct nfp_cpp *cpp) } void -nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) +nfp_cpp_interface_set(struct nfp_cpp *cpp, + uint32_t interface) { cpp->interface = interface; } int -nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) +nfp_cpp_serial(struct nfp_cpp *cpp, + const uint8_t **serial) { *serial = cpp->serial; return cpp->serial_len; } int -nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len) +nfp_cpp_serial_set(struct nfp_cpp *cpp, + const uint8_t *serial, + size_t serial_len) { if (cpp->serial_len) free(cpp->serial); @@ -161,9 +166,11 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) * NOTE: @address and @size must be 32-bit aligned values. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, - const char *name, unsigned long long address, - unsigned long size) +nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, + uint32_t dest, + const char *name, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -183,7 +190,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, name = ""; area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + strlen(name) + 1); if (area == NULL) return NULL; @@ -204,8 +211,10 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, } struct nfp_cpp_area * -nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc(struct nfp_cpp *cpp, + uint32_t dest, + unsigned long long address, + unsigned long size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -226,8 +235,10 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, * NOTE: The area must also be 'released' when the structure is freed. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; @@ -340,8 +351,10 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *kernel_vaddr, size_t length) +nfp_cpp_area_read(struct nfp_cpp_area *area, + unsigned long offset, + void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -364,8 +377,10 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *kernel_vaddr, size_t length) +nfp_cpp_area_write(struct nfp_cpp_area *area, + unsigned long offset, + const void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -392,8 +407,9 @@ nfp_cpp_area_mapped(struct nfp_cpp_area *area) * or negative value on error. */ int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, - unsigned long length) +nfp_cpp_area_check_range(struct nfp_cpp_area *area, + unsigned long long offset, + unsigned long length) { if (((offset + length) > area->size)) return -EFAULT; @@ -406,7 +422,8 @@ nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, * based upon NFP model. */ static uint32_t -nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) +nfp_xpb_to_cpp(struct nfp_cpp *cpp, + uint32_t *xpb_addr) { uint32_t xpb; int island; @@ -433,7 +450,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) else /* And only non-ARM interfaces use island id = 1 */ if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) + NFP_CPP_INTERFACE_TYPE_ARM) *xpb_addr |= (1 << 24); } else { (*xpb_addr) |= (1 << 30); @@ -443,8 +460,9 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) } int -nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value) +nfp_cpp_area_readl(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t *value) { int sz; uint32_t tmp = 0; @@ -456,8 +474,9 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value) +nfp_cpp_area_writel(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value) { int sz; @@ -467,8 +486,9 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value) +nfp_cpp_area_readq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t *value) { int sz; uint64_t tmp = 0; @@ -480,8 +500,9 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value) +nfp_cpp_area_writeq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t value) { int sz; @@ -492,8 +513,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t *value) +nfp_cpp_readl(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t *value) { int sz; uint32_t tmp; @@ -505,8 +528,10 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t value) +nfp_cpp_writel(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t value) { int sz; @@ -517,8 +542,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t *value) +nfp_cpp_readq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t *value) { int sz; uint64_t tmp; @@ -530,8 +557,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t value) +nfp_cpp_writeq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t value) { int sz; @@ -542,7 +571,9 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) +nfp_xpb_writel(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t value) { uint32_t cpp_dest; @@ -552,7 +583,9 @@ nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) } int -nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) +nfp_xpb_readl(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t *value) { uint32_t cpp_dest; @@ -562,7 +595,8 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *dev, + int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -596,7 +630,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + (tgt * 4); err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { free(cpp); return NULL; @@ -631,7 +665,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) } struct nfp_cpp * -nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_from_device_name(struct rte_pci_device *dev, + int driver_lock_needed) { return nfp_cpp_alloc(dev, driver_lock_needed); } @@ -647,7 +682,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) * @return 0 on success, or -1 on failure. */ int -nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, +nfp_xpb_writelm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, uint32_t value) { int err; @@ -674,8 +711,11 @@ nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, or negative value on failure. */ int -nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us) +nfp_xpb_waitlm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, + uint32_t value, + int timeout_us) { uint32_t tmp; int err; @@ -716,8 +756,11 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @length: number of bytes to read */ int -nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, void *kernel_vaddr, size_t length) +nfp_cpp_read(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -743,9 +786,11 @@ nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, * @length: number of bytes to write */ int -nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, const void *kernel_vaddr, - size_t length) +nfp_cpp_write(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + const void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -768,8 +813,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, * @length: length of area to fill */ int -nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length) +nfp_cpp_area_fill(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value, + size_t length) { int err; size_t i; @@ -795,9 +842,8 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = - nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); + err = nfp_cpp_area_write(area, offset + i, &value64, + sizeof(value64)); if (err < 0) return err; if (err != sizeof(value64)) @@ -805,8 +851,7 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } if ((i + sizeof(value)) <= length) { - err = - nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); + err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); if (err < 0) return err; if (err != sizeof(value)) @@ -822,13 +867,14 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) +__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, + uint32_t *model) { uint32_t reg; int err; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, - ®); + ®); if (err < 0) return err; @@ -853,8 +899,11 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) * Return: Pointer to memory mapped area or NULL */ uint8_t * -nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, struct nfp_cpp_area **area) +nfp_cpp_map_area(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + unsigned long size, + struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 20431bf845..2cd8866253 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -9,27 +9,31 @@ #include "nfp_crc.h" static inline uint32_t -nfp_crc32_be_generic(uint32_t crc, unsigned char const *p, size_t len, - uint32_t polynomial) +nfp_crc32_be_generic(uint32_t crc, + unsigned char const *p, + size_t len, + uint32_t polynomial) { int i; while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) - crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : - 0); + crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); } return crc; } static inline uint32_t -nfp_crc32_be(uint32_t crc, unsigned char const *p, size_t len) +nfp_crc32_be(uint32_t crc, + unsigned char const *p, + size_t len) { return nfp_crc32_be_generic(crc, p, len, CRCPOLY_BE); } static uint32_t -nfp_crc32_posix_end(uint32_t crc, size_t total_len) +nfp_crc32_posix_end(uint32_t crc, + size_t total_len) { /* Extend with the length of the string. */ while (total_len != 0) { @@ -43,7 +47,8 @@ nfp_crc32_posix_end(uint32_t crc, size_t total_len) } uint32_t -nfp_crc32_posix(const void *buff, size_t len) +nfp_crc32_posix(const void *buff, + size_t len) { return nfp_crc32_posix_end(nfp_crc32_be(0, buff, len), len); } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index a9d166c4dc..ea4c7d6a9e 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -33,12 +33,13 @@ nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) } static int -nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) +nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, + uint32_t size) { const char *key, *val, *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { PMD_DRV_LOG(ERR, "Bad HWINFO - overflowing value"); @@ -54,7 +55,8 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) } static int -nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) +nfp_hwinfo_db_validate(struct nfp_hwinfo *db, + uint32_t len) { uint32_t size, new_crc, *crc; @@ -69,7 +71,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", - new_crc, *crc); + new_crc, *crc); return -EINVAL; } @@ -77,7 +79,8 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) } static struct nfp_hwinfo * -nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) +nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, + size_t *cpp_size) { struct nfp_hwinfo *header; void *res; @@ -115,7 +118,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) if (header->version != NFP_HWINFO_VERSION_2) { PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", - header->version); + header->version); goto exit_free; } @@ -129,7 +132,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) } static struct nfp_hwinfo * -nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) +nfp_hwinfo_fetch(struct nfp_cpp *cpp, + size_t *hwdb_size) { struct timespec wait; struct nfp_hwinfo *db; @@ -179,7 +183,8 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) * Return: Value of the HWInfo name, or NULL */ const char * -nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) +nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, + const char *lookup) { const char *key, *val, *end; @@ -189,7 +194,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (strcmp(key, lookup) == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f9723dd136..0071d3fc37 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -37,8 +37,10 @@ struct nfp_mip { /* Read memory and check if it could be a valid MIP */ static int -nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - struct nfp_mip *mip) +nfp_mip_try_read(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + struct nfp_mip *mip) { int ret; @@ -49,12 +51,12 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, } if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", - rte_le_to_cpu_32(mip->signature)); + rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", - rte_le_to_cpu_32(mip->mip_version)); + rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -63,7 +65,8 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, /* Try to locate MIP using the resource table */ static int -nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) +nfp_mip_read_resource(struct nfp_cpp *cpp, + struct nfp_mip *mip) { struct nfp_nffw_info *nffw_info; uint32_t cpp_id; @@ -134,7 +137,9 @@ nfp_mip_name(const struct nfp_mip *mip) * @size: Location for size of MIP symbol table */ void -nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_symtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->symtab_addr); *size = rte_le_to_cpu_32(mip->symtab_size); @@ -147,7 +152,9 @@ nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) * @size: Location for size of MIP symbol name table */ void -nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_strtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->strtab_addr); *size = rte_le_to_cpu_32(mip->strtab_size); diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index d0919b58fe..980abc2517 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,5 +17,5 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *off); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 0410a00856..047e755416 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,9 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) +_nfp_cpp_mutex_validate(uint32_t model, + int *target, + unsigned long long address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -72,8 +74,10 @@ _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) * @return 0 on success, or negative value on failure. */ int -nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, - uint32_t key) +nfp_cpp_mutex_init(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ @@ -87,9 +91,8 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, if (err < 0) return err; - err = - nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address + 0, + MUTEX_LOCKED(nfp_cpp_interface(cpp))); if (err < 0) return err; @@ -114,8 +117,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * -nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key) +nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); struct nfp_cpp_mutex *mutex; @@ -265,8 +270,8 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return err; if (time(NULL) >= warn_at) { PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->usage, mutex->depth, mutex->target, + mutex->address, mutex->key); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 433780a5e7..fa65956baa 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -85,7 +85,8 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) } static unsigned int -nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) +nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, + struct nffw_fwinfo **arr) { /* * For the this code, version 0 is most likely to be version 1 in this @@ -138,8 +139,8 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) goto err_release; err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), - nfp_resource_address(state->res), - fwinf, sizeof(*fwinf)); + nfp_resource_address(state->res), + fwinf, sizeof(*fwinf)); if (err < (int)sizeof(*fwinf)) goto err_release; @@ -205,8 +206,9 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) * Return: 0, or -ERRNO */ int -nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) +nfp_nffw_info_mip_first(struct nfp_nffw_info *state, + uint32_t *cpp_id, + uint64_t *off) { struct nffw_fwinfo *fwinfo; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 6474abf0c2..4f476f6f2b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -22,7 +22,8 @@ nfp_nsp_config_modified(struct nfp_nsp *state) } void -nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified) +nfp_nsp_config_set_modified(struct nfp_nsp *state, + int modified) { state->modified = modified; } @@ -40,7 +41,9 @@ nfp_nsp_config_idx(struct nfp_nsp *state) } void -nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx) +nfp_nsp_config_set_state(struct nfp_nsp *state, + void *entries, + unsigned int idx) { state->entries = entries; state->idx = idx; @@ -91,7 +94,7 @@ nfp_nsp_check(struct nfp_nsp *state) if (state->ver.major != NSP_MAJOR || state->ver.minor < NSP_MINOR) { PMD_DRV_LOG(ERR, "Unsupported ABI %hu.%hu", state->ver.major, - state->ver.minor); + state->ver.minor); return -EINVAL; } @@ -160,8 +163,12 @@ nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state) } static int -nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, - uint64_t addr, uint64_t mask, uint64_t val) +nfp_nsp_wait_reg(struct nfp_cpp *cpp, + uint64_t *reg, + uint32_t nsp_cpp, + uint64_t addr, + uint64_t mask, + uint64_t val) { struct timespec wait; int count; @@ -204,8 +211,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, * -ETIMEDOUT if the NSP took longer than 30 seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, - uint32_t buff_cpp, uint64_t buff_addr) +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code, + uint32_t option, + uint32_t buff_cpp, + uint64_t buff_addr) { uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; struct nfp_cpp *cpp = state->cpp; @@ -223,40 +233,40 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { + !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); + buff_cpp, buff_addr); return -EINVAL; } err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | - FIELD_PREP(NSP_COMMAND_START, 1)); + FIELD_PREP(NSP_COMMAND_OPTION, option) | + FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, - NSP_COMMAND_START, 0); + NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } /* Wait for NSP_STATUS_BUSY to go to 0 */ - err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, - 0); + err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, + NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } @@ -268,7 +278,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); + -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); return -err; } @@ -279,9 +289,12 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, #define SZ_1M 0x00100000 static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, - const void *in_buf, unsigned int in_size, void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf(struct nfp_nsp *nsp, + uint16_t code, uint32_t option, + const void *in_buf, + unsigned int in_size, + void *out_buf, + unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; unsigned int max_size; @@ -291,28 +304,26 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); + code, nsp->ver.major, nsp->ver.minor); return -EOPNOTSUPP; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER_CONFIG, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); if (err < 0) return err; max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); + code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, + ®); if (err < 0) return err; @@ -328,7 +339,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + out_size - in_size); if (err < 0) return err; } @@ -388,38 +399,47 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) } int -nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_load_fw(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_eth_table(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) +nfp_nsp_write_eth_table(struct nfp_nsp *state, + const void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_identify(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, void *buf, - unsigned int size) +nfp_nsp_read_sensors(struct nfp_nsp *state, + unsigned int sensor_mask, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + 0, buf, size); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 9905b2d3d3..1e2deaabb4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -114,9 +114,10 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); + void *buf, unsigned int size); -static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) +static inline int +nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } @@ -229,22 +230,22 @@ struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); + int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + unsigned int size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + unsigned int idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) +static inline int +nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return !!eth_port->fec_modes_supported; } @@ -297,6 +298,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + long *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 21b338461e..28dba27124 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -73,7 +73,9 @@ struct nfp_sensors { }; int -nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val) +nfp_hwmon_read_sensor(struct nfp_cpp *cpp, + enum nfp_nsp_sensor_id id, + long *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 825a84a8cd..51bd57033e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -159,7 +159,8 @@ nfp_eth_speed2rate(unsigned int speed) } static void -nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) +nfp_eth_copy_mac_reverse(uint8_t *dst, + const uint8_t *src) { int i; @@ -168,8 +169,10 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) } static void -nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, struct nfp_eth_table_port *dst) +nfp_eth_port_translate(struct nfp_nsp *nsp, + const union eth_table_entry *src, + unsigned int index, + struct nfp_eth_table_port *dst) { unsigned int rate; unsigned int fec; @@ -225,21 +228,21 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, - table->ports[i].index); + table->ports[i].index); for (j = 0; j < table->count; j++) { if (table->ports[i].label_port != - table->ports[j].label_port) + table->ports[j].label_port) continue; table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; if (table->ports[i].label_subport == - table->ports[j].label_subport) + table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", - table->ports[i].label_port, - table->ports[i].label_subport); + table->ports[i].label_port, + table->ports[i].label_subport); table->ports[i].is_split = 1; } @@ -296,7 +299,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", - ret, cnt); + ret, cnt); goto err; } @@ -354,7 +357,8 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) } struct nfp_nsp * -nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx) +nfp_eth_config_start(struct nfp_cpp *cpp, + unsigned int idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -447,7 +451,9 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) * -ERRNO - configuration failed. */ int -nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) +nfp_eth_set_mod_enable(struct nfp_cpp *cpp, + unsigned int idx, + int enable) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -487,7 +493,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) * -ERRNO - configuration failed. */ int -nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) +nfp_eth_set_configured(struct nfp_cpp *cpp, + unsigned int idx, + int configed) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -523,9 +531,12 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) } static int -nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, - const uint64_t mask, const unsigned int shift, - unsigned int val, const uint64_t ctrl_bit) +nfp_eth_set_bit_config(struct nfp_nsp *nsp, + unsigned int raw_idx, + const uint64_t mask, + const unsigned int shift, + unsigned int val, + const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); unsigned int idx = nfp_nsp_config_idx(nsp); @@ -560,7 +571,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, (__extension__ ({ \ typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /* @@ -574,11 +585,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, * Return: 0 or -ERRNO. */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) +__nfp_eth_set_aneg(struct nfp_nsp *nsp, + enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_ANEG, mode, - NSP_ETH_CTRL_SET_ANEG); + NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } /* @@ -592,11 +603,11 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) * Return: 0 or -ERRNO. */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) +__nfp_eth_set_fec(struct nfp_nsp *nsp, + enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_FEC, mode, - NSP_ETH_CTRL_SET_FEC); + NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } /* @@ -611,7 +622,9 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) * -ERRNO - configuration failed. */ int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) +nfp_eth_set_fec(struct nfp_cpp *cpp, + unsigned int idx, + enum nfp_eth_fec mode) { struct nfp_nsp *nsp; int err; @@ -642,7 +655,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) +__nfp_eth_set_speed(struct nfp_nsp *nsp, + unsigned int speed) { enum nfp_eth_rate rate; @@ -653,8 +667,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) } return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_RATE, rate, - NSP_ETH_CTRL_SET_RATE); + NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } /* @@ -668,8 +681,9 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes) +__nfp_eth_set_split(struct nfp_nsp *nsp, + unsigned int lanes) { - return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, - lanes, NSP_ETH_CTRL_SET_LANES); + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, + NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 838cd6e0ef..57089c770f 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -64,7 +64,8 @@ struct nfp_resource { }; static int -nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) +nfp_cpp_resource_find(struct nfp_cpp *cpp, + struct nfp_resource *res) { char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; struct nfp_resource_entry entry; @@ -85,7 +86,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { uint64_t addr = NFP_RESOURCE_TBL_BASE + - sizeof(struct nfp_resource_entry) * i; + sizeof(struct nfp_resource_entry) * i; ret = nfp_cpp_read(cpp, cpp_id, addr, &entry, sizeof(entry)); if (ret != sizeof(entry)) @@ -95,12 +96,11 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) continue; /* Found key! */ - res->mutex = - nfp_cpp_mutex_alloc(cpp, - NFP_RESOURCE_TBL_TARGET, addr, key); + res->mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, + addr, key); res->cpp_id = NFP_CPP_ID(entry.region.cpp_target, - entry.region.cpp_action, - entry.region.cpp_token); + entry.region.cpp_action, + entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; return 0; @@ -110,8 +110,9 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) } static int -nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, - struct nfp_cpp_mutex *dev_mutex) +nfp_resource_try_acquire(struct nfp_cpp *cpp, + struct nfp_resource *res, + struct nfp_cpp_mutex *dev_mutex) { int err; @@ -148,7 +149,8 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, * Return: NFP Resource handle, or NULL */ struct nfp_resource * -nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) +nfp_resource_acquire(struct nfp_cpp *cpp, + const char *name) { struct nfp_cpp_mutex *dev_mutex; struct nfp_resource *res; @@ -165,8 +167,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, - NFP_RESOURCE_TBL_BASE, - NFP_RESOURCE_TBL_KEY); + NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { free(res); return NULL; @@ -234,8 +235,8 @@ nfp_resource_cpp_id(const struct nfp_resource *res) * * Return: const char pointer to the name of the resource */ -const char -*nfp_resource_name(const struct nfp_resource *res) +const char * +nfp_resource_name(const struct nfp_resource *res) { return res->name; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 06cc6f74f4..009b7359a4 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -18,7 +18,7 @@ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, - const char *name); + const char *name); /** * Release a NFP Resource, and free the handle diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 4c45aec5c1..aa3b7a483e 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -40,22 +40,25 @@ struct nfp_rtsym_table { }; static int -nfp_meid(uint8_t island_id, uint8_t menum) +nfp_meid(uint8_t island_id, + uint8_t menum) { return (island_id & 0x3F) == island_id && menum < 12 ? (island_id << 4) | (menum + 4) : -1; } static void -nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, uint32_t strtab_size, - struct nfp_rtsym *sw, struct nfp_rtsym_entry *fw) +nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, + uint32_t strtab_size, + struct nfp_rtsym *sw, + struct nfp_rtsym_entry *fw) { sw->type = fw->type; sw->name = cache->strtab + rte_le_to_cpu_16(fw->name) % strtab_size; sw->addr = ((uint64_t)fw->addr_hi << 32) | - rte_le_to_cpu_32(fw->addr_lo); + rte_le_to_cpu_32(fw->addr_lo); sw->size = ((uint64_t)fw->size_hi << 32) | - rte_le_to_cpu_32(fw->size_lo); + rte_le_to_cpu_32(fw->size_lo); PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", sw->name, sw->addr, sw->size, sw->target); @@ -93,7 +96,8 @@ nfp_rtsym_table_read(struct nfp_cpp *cpp) } struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) +__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip) { uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; struct nfp_rtsym_entry *rtsymtab; @@ -142,7 +146,7 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) for (n = 0; n < cache->num; n++) nfp_rtsym_sw_entry_init(cache, strtab_size, - &cache->symtab[n], &rtsymtab[n]); + &cache->symtab[n], &rtsymtab[n]); free(rtsymtab); @@ -178,7 +182,8 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) +nfp_rtsym_get(struct nfp_rtsym_table *rtbl, + int idx) { if (rtbl == NULL) return NULL; @@ -197,7 +202,8 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name) +nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name) { int n; @@ -331,7 +337,9 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, * Return: value read, on error sets the error and returns ~0ULL. */ uint64_t -nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) +nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, + const char *name, + int *error) { const struct nfp_rtsym *sym; uint32_t val32; @@ -354,7 +362,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, - name, sym->size); + name, sym->size); err = -EINVAL; break; } @@ -372,8 +380,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) } uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area) +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, + const char *name, + unsigned int min_size, + struct nfp_cpp_area **area) { int ret; uint8_t *mem; @@ -397,7 +407,7 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, if (sym->size < min_size) { PMD_DRV_LOG(ERR, "Symbol %s too small (%" PRIu64 " < %u)", name, - sym->size, min_size); + sym->size, min_size); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 8b494211bc..30768f1ccf 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -43,19 +43,18 @@ struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip); +struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip); 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); +const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name); uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, - int *error); -uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + int *error); +uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, + unsigned int min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v4 02/26] net/nfp: unify the indent coding style 2023-09-18 2:45 ` [PATCH v4 02/26] net/nfp: unify the indent coding style Chaoyong He @ 2023-09-18 11:53 ` Niklas Söderlund 0 siblings, 0 replies; 159+ messages in thread From: Niklas Söderlund @ 2023-09-18 11:53 UTC (permalink / raw) To: Chaoyong He; +Cc: dev, Niklas Söderlund Hi Chaoyong, On 2023-09-18 10:45:48 +0800, Chaoyong He wrote: > Each parameter of function should occupy one line, and indent two TAB > character. > All the statement which span multi line should indent two TAB character. > > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> > Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> Nacked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> I have not reviewed this rebase, I'm sure it's fine, but I have not reviewed it. Please drop my R-b from any future postings. > --- > drivers/net/nfp/nfpcore/nfp_cpp.h | 80 +++++----- > drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 152 ++++++++++-------- > drivers/net/nfp/nfpcore/nfp_cppcore.c | 173 +++++++++++++-------- > drivers/net/nfp/nfpcore/nfp_crc.c | 19 ++- > drivers/net/nfp/nfpcore/nfp_hwinfo.c | 23 +-- > drivers/net/nfp/nfpcore/nfp_mip.c | 21 ++- > drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- > drivers/net/nfp/nfpcore/nfp_mutex.c | 25 +-- > drivers/net/nfp/nfpcore/nfp_nffw.c | 12 +- > drivers/net/nfp/nfpcore/nfp_nsp.c | 108 +++++++------ > drivers/net/nfp/nfpcore/nfp_nsp.h | 19 +-- > drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 +- > drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 72 +++++---- > drivers/net/nfp/nfpcore/nfp_resource.c | 29 ++-- > drivers/net/nfp/nfpcore/nfp_resource.h | 2 +- > drivers/net/nfp/nfpcore/nfp_rtsym.c | 38 +++-- > drivers/net/nfp/nfpcore/nfp_rtsym.h | 15 +- > 17 files changed, 463 insertions(+), 331 deletions(-) > > diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h > index 8f87c09327..54bef3cb6b 100644 > --- a/drivers/net/nfp/nfpcore/nfp_cpp.h > +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h > @@ -56,7 +56,8 @@ struct nfp_cpp_operations { > size_t area_priv_size; > > /* Instance an NFP CPP */ > - int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); > + int (*init)(struct nfp_cpp *cpp, > + struct rte_pci_device *dev); > > /* > * Free the bus. > @@ -69,9 +70,9 @@ struct nfp_cpp_operations { > * NOTE: This is _not_ serialized > */ > int (*area_init)(struct nfp_cpp_area *area, > - uint32_t dest, > - unsigned long long address, > - unsigned long size); > + uint32_t dest, > + unsigned long long address, > + unsigned long size); > /* > * Clean up a NFP CPP area before it is freed > * NOTE: This is _not_ serialized > @@ -101,17 +102,17 @@ struct nfp_cpp_operations { > * Serialized > */ > int (*area_read)(struct nfp_cpp_area *area, > - void *kernel_vaddr, > - unsigned long offset, > - unsigned int length); > + void *kernel_vaddr, > + unsigned long offset, > + unsigned int length); > /* > * Perform a write to a NFP CPP area > * Serialized > */ > int (*area_write)(struct nfp_cpp_area *area, > - const void *kernel_vaddr, > - unsigned long offset, > - unsigned int length); > + const void *kernel_vaddr, > + unsigned long offset, > + unsigned int length); > }; > > /* > @@ -239,7 +240,7 @@ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); > * @param len Length of the serial byte array > */ > int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, > - size_t serial_len); > + size_t serial_len); > > /* > * Set the private data of the nfp_cpp instance > @@ -279,7 +280,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); > * @return NFP CPP handle, or NULL on failure. > */ > struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, > - int driver_lock_needed); > + int driver_lock_needed); > > /* > * Free a NFP CPP handle > @@ -397,8 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); > * @return NFP CPP handle, or NULL on failure. > */ > struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, > - unsigned long size); > + unsigned long long address, unsigned long size); > > /* > * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner > @@ -411,10 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, > * @return NFP CPP handle, or NULL on failure. > */ > struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, > - uint32_t cpp_id, > - const char *name, > - unsigned long long address, > - unsigned long size); > + uint32_t cpp_id, const char *name, unsigned long long address, > + unsigned long size); > > /* > * Free an allocated NFP CPP area handle > @@ -448,9 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); > * @return NFP CPP handle, or NULL on failure. > */ > struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, > - uint32_t cpp_id, > - unsigned long long address, > - unsigned long size); > + uint32_t cpp_id, unsigned long long address, unsigned long size); > > /* > * Release the resources, then free the NFP CPP area handle > @@ -459,8 +455,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, > void nfp_cpp_area_release_free(struct nfp_cpp_area *area); > > uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, > - uint64_t addr, unsigned long size, > - struct nfp_cpp_area **area); > + uint64_t addr, unsigned long size, struct nfp_cpp_area **area); > /* > * Return an IO pointer to the beginning of the NFP CPP area handle. The area > * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. > @@ -484,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); > * > */ > int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, > - void *buffer, size_t length); > + void *buffer, size_t length); > > /* > * Write to a NFP CPP area handle from a buffer. The area must be acquired with > @@ -498,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, > * @return bytes written on success, negative value on failure. > */ > int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, > - const void *buffer, size_t length); > + const void *buffer, size_t length); > > /* > * nfp_cpp_area_iomem() - get IOMEM region for CPP area > @@ -522,7 +517,7 @@ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); > * @return 0 on success, negative value on failure. > */ > int nfp_cpp_area_check_range(struct nfp_cpp_area *area, > - unsigned long long offset, unsigned long size); > + unsigned long long offset, unsigned long size); > > /* > * Get the NFP CPP handle that is the parent of a NFP CPP area handle > @@ -552,7 +547,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); > * @return bytes read on success, -1 on failure. > */ > int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, void *kernel_vaddr, size_t length); > + unsigned long long address, void *kernel_vaddr, size_t length); > > /* > * Write a block of data to a NFP CPP ID > @@ -566,8 +561,8 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, > * @return bytes written on success, -1 on failure. > */ > int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, const void *kernel_vaddr, > - size_t length); > + unsigned long long address, const void *kernel_vaddr, > + size_t length); > > > > @@ -582,7 +577,7 @@ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, > * @return bytes written on success, negative value on failure. > */ > int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, > - uint32_t value, size_t length); > + uint32_t value, size_t length); > > /* > * Read a single 32-bit value from a NFP CPP area handle > @@ -599,7 +594,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, > * @return 0 on success, or -1 on error. > */ > int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, > - uint32_t *value); > + uint32_t *value); > > /* > * Write a single 32-bit value to a NFP CPP area handle > @@ -616,7 +611,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, > * @return 0 on success, or -1 on error. > */ > int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, > - uint32_t value); > + uint32_t value); > > /* > * Read a single 64-bit value from a NFP CPP area handle > @@ -633,7 +628,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, > * @return 0 on success, or -1 on error. > */ > int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, > - uint64_t *value); > + uint64_t *value); > > /* > * Write a single 64-bit value to a NFP CPP area handle > @@ -650,7 +645,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, > * @return 0 on success, or -1 on error. > */ > int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, > - uint64_t value); > + uint64_t value); > > /* > * Write a single 32-bit value on the XPB bus > @@ -685,7 +680,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); > * @return 0 on success, or -1 on failure. > */ > int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > - uint32_t value); > + uint32_t value); > > /* > * Modify bits of a 32-bit value from the XPB bus > @@ -699,7 +694,7 @@ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > * @return >= 0 on success, negative value on failure. > */ > int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > - uint32_t value, int timeout_us); > + uint32_t value, int timeout_us); > > /* > * Read a 32-bit word from a NFP CPP ID > @@ -712,7 +707,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > * @return 0 on success, or -1 on failure. > */ > int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, uint32_t *value); > + unsigned long long address, uint32_t *value); > > /* > * Write a 32-bit value to a NFP CPP ID > @@ -726,7 +721,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, > * > */ > int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, uint32_t value); > + unsigned long long address, uint32_t value); > > /* > * Read a 64-bit work from a NFP CPP ID > @@ -739,7 +734,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, > * @return 0 on success, or -1 on failure. > */ > int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, uint64_t *value); > + unsigned long long address, uint64_t *value); > > /* > * Write a 64-bit value to a NFP CPP ID > @@ -752,7 +747,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, > * @return 0 on success, or -1 on failure. > */ > int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, > - unsigned long long address, uint64_t value); > + unsigned long long address, uint64_t value); > > /* > * Initialize a mutex location > @@ -773,7 +768,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, > * @return 0 on success, negative value on failure. > */ > int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, > - unsigned long long address, uint32_t key_id); > + unsigned long long address, uint32_t key_id); > > /* > * Create a mutex handle from an address controlled by a MU Atomic engine > @@ -793,8 +788,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, > * failure. > */ > struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, > - unsigned long long address, > - uint32_t key_id); > + unsigned long long address, uint32_t key_id); > > /* > * Get the NFP CPP handle the mutex was created with > diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c > index 2ee60eefc3..884cc84eaa 100644 > --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c > +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c > @@ -130,9 +130,15 @@ nfp_bar_maptype(struct nfp_bar *bar) > #define TARGET_WIDTH_64 8 > > static int > -nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, > - uint64_t *bar_base, int tgt, int act, int tok, > - uint64_t offset, size_t size, int width) > +nfp_compute_bar(const struct nfp_bar *bar, > + uint32_t *bar_config, > + uint64_t *bar_base, > + int tgt, > + int act, > + int tok, > + uint64_t offset, > + size_t size, > + int width) > { > uint32_t bitsize; > uint32_t newcfg; > @@ -143,19 +149,16 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, > > switch (width) { > case 8: > - newcfg = > - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT > - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); > + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT > + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); > break; > case 4: > - newcfg = > - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT > - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); > + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT > + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); > break; > case 0: > - newcfg = > - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT > - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); > + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT > + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); > break; > default: > return -EINVAL; > @@ -165,60 +168,58 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, > /* Fixed CPP mapping with specific action */ > mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); > > - newcfg |= > - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE > - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); > + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE > + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); > newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); > newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); > newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); > > if ((offset & mask) != ((offset + size - 1) & mask)) { > PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", > - bar->index, (unsigned long long)offset, > - (unsigned long long)(offset + size), act, > - (unsigned long long)mask); > + bar->index, (unsigned long long)offset, > + (unsigned long long)(offset + size), act, > + (unsigned long long)mask); > return -EINVAL; > } > offset &= mask; > > PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", > - bar->index, tgt, act, tok, (unsigned long long)offset, > - (unsigned long long)(offset + mask)); > + bar->index, tgt, act, tok, (unsigned long long)offset, > + (unsigned long long)(offset + mask)); > > bitsize = 40 - 16; > } else { > mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); > > /* Bulk mapping */ > - newcfg |= > - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE > - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); > + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE > + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); > > newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); > newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); > > if ((offset & mask) != ((offset + size - 1) & mask)) { > PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", > - bar->index, (unsigned long long)offset, > - (unsigned long long)(offset + size), > - tgt, tok, (unsigned long long)mask, > - (unsigned long long)(offset & mask), > - (unsigned long long)(offset + size - 1) & mask); > + bar->index, (unsigned long long)offset, > + (unsigned long long)(offset + size), > + tgt, tok, (unsigned long long)mask, > + (unsigned long long)(offset & mask), > + (unsigned long long)(offset + size - 1) & mask); > return -EINVAL; > } > > offset &= mask; > > PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", > - bar->index, tgt, tok, (unsigned long long)offset, > - (unsigned long long)(offset + ~mask)); > + bar->index, tgt, tok, (unsigned long long)offset, > + (unsigned long long)(offset + ~mask)); > > bitsize = 40 - 21; > } > > if (bar->bitsize < bitsize) { > PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, > - tgt, tok, act); > + tgt, tok, act); > return -EINVAL; > } > > @@ -234,8 +235,9 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, > } > > static int > -nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, > - uint32_t newcfg) > +nfp_bar_write(struct nfp_pcie_user *nfp, > + struct nfp_bar *bar, > + uint32_t newcfg) > { > int base, slot; > > @@ -246,7 +248,7 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, > return (-ENOMEM); > > bar->csr = nfp->cfg + > - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); > + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); > > *(uint32_t *)(bar->csr) = newcfg; > > @@ -257,15 +259,21 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, > } > > static int > -nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, > - int act, int tok, uint64_t offset, size_t size, int width) > +nfp_reconfigure_bar(struct nfp_pcie_user *nfp, > + struct nfp_bar *bar, > + int tgt, > + int act, > + int tok, > + uint64_t offset, > + size_t size, > + int width) > { > uint64_t newbase; > uint32_t newcfg; > int err; > > err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, > - size, width); > + size, width); > if (err != 0) > return err; > > @@ -390,8 +398,10 @@ struct nfp6000_area_priv { > }; > > static int > -nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, > - unsigned long long address, unsigned long size) > +nfp6000_area_init(struct nfp_cpp_area *area, > + uint32_t dest, > + unsigned long long address, > + unsigned long size) > { > struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); > struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); > @@ -400,8 +410,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, > uint32_t token = NFP_CPP_ID_TOKEN_of(dest); > int pp, ret = 0; > > - pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), > - address); > + pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); > if (pp < 0) > return pp; > > @@ -409,7 +418,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, > priv->width.write = PULL_WIDTH(pp); > > if (priv->width.read > 0 && > - priv->width.write > 0 && priv->width.read != priv->width.write) > + priv->width.write > 0 && > + priv->width.read != priv->width.write) > return -EINVAL; > > if (priv->width.read > 0) > @@ -428,8 +438,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, > priv->size = size; > > ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, > - priv->token, priv->offset, priv->size, > - priv->width.bar); > + priv->token, priv->offset, priv->size, > + priv->width.bar); > > return ret; > } > @@ -441,14 +451,13 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) > > /* Calculate offset into BAR. */ > if (nfp_bar_maptype(priv->bar) == > - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { > + NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { > priv->bar_offset = priv->offset & > - (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); > - priv->bar_offset += > - NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, > - priv->target); > - priv->bar_offset += > - NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, priv->token); > + (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); > + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, > + priv->target); > + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, > + priv->token); > } else { > priv->bar_offset = priv->offset & priv->bar->mask; > } > @@ -490,8 +499,10 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) > } > > static int > -nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, > - unsigned long offset, unsigned int length) > +nfp6000_area_read(struct nfp_cpp_area *area, > + void *kernel_vaddr, > + unsigned long offset, > + unsigned int length) > { > uint64_t *wrptr64 = kernel_vaddr; > const volatile uint64_t *rdptr64; > @@ -524,17 +535,17 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, > > /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ > if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && > - priv->action == NFP_CPP_ACTION_RW) { > + priv->action == NFP_CPP_ACTION_RW) { > is_64 = false; > } > > if (is_64) { > if (offset % sizeof(uint64_t) != 0 || > - length % sizeof(uint64_t) != 0) > + length % sizeof(uint64_t) != 0) > return -EINVAL; > } else { > if (offset % sizeof(uint32_t) != 0 || > - length % sizeof(uint32_t) != 0) > + length % sizeof(uint32_t) != 0) > return -EINVAL; > } > > @@ -558,8 +569,10 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, > } > > static int > -nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, > - unsigned long offset, unsigned int length) > +nfp6000_area_write(struct nfp_cpp_area *area, > + const void *kernel_vaddr, > + unsigned long offset, > + unsigned int length) > { > const uint64_t *rdptr64 = kernel_vaddr; > uint64_t *wrptr64; > @@ -590,16 +603,16 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, > > /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ > if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && > - priv->action == NFP_CPP_ACTION_RW) > + priv->action == NFP_CPP_ACTION_RW) > is_64 = false; > > if (is_64) { > if (offset % sizeof(uint64_t) != 0 || > - length % sizeof(uint64_t) != 0) > + length % sizeof(uint64_t) != 0) > return -EINVAL; > } else { > if (offset % sizeof(uint32_t) != 0 || > - length % sizeof(uint32_t) != 0) > + length % sizeof(uint32_t) != 0) > return -EINVAL; > } > > @@ -655,7 +668,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) > } > > static int > -nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) > +nfp6000_set_model(struct rte_pci_device *dev, > + struct nfp_cpp *cpp) > { > uint32_t model; > > @@ -671,7 +685,8 @@ nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) > } > > static int > -nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) > +nfp6000_set_interface(struct rte_pci_device *dev, > + struct nfp_cpp *cpp) > { > uint16_t interface; > > @@ -686,7 +701,8 @@ nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) > } > > static int > -nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) > +nfp6000_set_serial(struct rte_pci_device *dev, > + struct nfp_cpp *cpp) > { > uint16_t tmp; > uint8_t serial[6]; > @@ -733,7 +749,8 @@ nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) > } > > static int > -nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) > +nfp6000_set_barsz(struct rte_pci_device *dev, > + struct nfp_pcie_user *desc) > { > unsigned long tmp; > int i = 0; > @@ -748,7 +765,8 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) > } > > static int > -nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) > +nfp6000_init(struct nfp_cpp *cpp, > + struct rte_pci_device *dev) > { > int ret = 0; > struct nfp_pcie_user *desc; > @@ -762,7 +780,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) > strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); > > if (rte_eal_process_type() == RTE_PROC_PRIMARY && > - cpp->driver_lock_needed) { > + cpp->driver_lock_needed) { > ret = nfp_acquire_process_lock(desc); > if (ret != 0) > goto error; > diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c > index 31338e0047..f764208a9a 100644 > --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c > +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c > @@ -27,7 +27,8 @@ > NFP_PL_DEVICE_ID_MASK) > > void > -nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) > +nfp_cpp_priv_set(struct nfp_cpp *cpp, > + void *priv) > { > cpp->priv = priv; > } > @@ -39,7 +40,8 @@ nfp_cpp_priv(struct nfp_cpp *cpp) > } > > void > -nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) > +nfp_cpp_model_set(struct nfp_cpp *cpp, > + uint32_t model) > { > cpp->model = model; > } > @@ -62,21 +64,24 @@ nfp_cpp_model(struct nfp_cpp *cpp) > } > > void > -nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) > +nfp_cpp_interface_set(struct nfp_cpp *cpp, > + uint32_t interface) > { > cpp->interface = interface; > } > > int > -nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) > +nfp_cpp_serial(struct nfp_cpp *cpp, > + const uint8_t **serial) > { > *serial = cpp->serial; > return cpp->serial_len; > } > > int > -nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, > - size_t serial_len) > +nfp_cpp_serial_set(struct nfp_cpp *cpp, > + const uint8_t *serial, > + size_t serial_len) > { > if (cpp->serial_len) > free(cpp->serial); > @@ -161,9 +166,11 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) > * NOTE: @address and @size must be 32-bit aligned values. > */ > struct nfp_cpp_area * > -nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, > - const char *name, unsigned long long address, > - unsigned long size) > +nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, > + uint32_t dest, > + const char *name, > + unsigned long long address, > + unsigned long size) > { > struct nfp_cpp_area *area; > uint64_t tmp64 = (uint64_t)address; > @@ -183,7 +190,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, > name = ""; > > area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + > - strlen(name) + 1); > + strlen(name) + 1); > if (area == NULL) > return NULL; > > @@ -204,8 +211,10 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, > } > > struct nfp_cpp_area * > -nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, > - unsigned long long address, unsigned long size) > +nfp_cpp_area_alloc(struct nfp_cpp *cpp, > + uint32_t dest, > + unsigned long long address, > + unsigned long size) > { > return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); > } > @@ -226,8 +235,10 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, > * NOTE: The area must also be 'released' when the structure is freed. > */ > struct nfp_cpp_area * > -nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, > - unsigned long long address, unsigned long size) > +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, > + uint32_t destination, > + unsigned long long address, > + unsigned long size) > { > struct nfp_cpp_area *area; > > @@ -340,8 +351,10 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) > * NOTE: Area must have been locked down with an 'acquire'. > */ > int > -nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, > - void *kernel_vaddr, size_t length) > +nfp_cpp_area_read(struct nfp_cpp_area *area, > + unsigned long offset, > + void *kernel_vaddr, > + size_t length) > { > if ((offset + length) > area->size) > return -EFAULT; > @@ -364,8 +377,10 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, > * NOTE: Area must have been locked down with an 'acquire'. > */ > int > -nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, > - const void *kernel_vaddr, size_t length) > +nfp_cpp_area_write(struct nfp_cpp_area *area, > + unsigned long offset, > + const void *kernel_vaddr, > + size_t length) > { > if ((offset + length) > area->size) > return -EFAULT; > @@ -392,8 +407,9 @@ nfp_cpp_area_mapped(struct nfp_cpp_area *area) > * or negative value on error. > */ > int > -nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, > - unsigned long length) > +nfp_cpp_area_check_range(struct nfp_cpp_area *area, > + unsigned long long offset, > + unsigned long length) > { > if (((offset + length) > area->size)) > return -EFAULT; > @@ -406,7 +422,8 @@ nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, > * based upon NFP model. > */ > static uint32_t > -nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) > +nfp_xpb_to_cpp(struct nfp_cpp *cpp, > + uint32_t *xpb_addr) > { > uint32_t xpb; > int island; > @@ -433,7 +450,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) > else > /* And only non-ARM interfaces use island id = 1 */ > if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != > - NFP_CPP_INTERFACE_TYPE_ARM) > + NFP_CPP_INTERFACE_TYPE_ARM) > *xpb_addr |= (1 << 24); > } else { > (*xpb_addr) |= (1 << 30); > @@ -443,8 +460,9 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) > } > > int > -nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, > - uint32_t *value) > +nfp_cpp_area_readl(struct nfp_cpp_area *area, > + unsigned long offset, > + uint32_t *value) > { > int sz; > uint32_t tmp = 0; > @@ -456,8 +474,9 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, > } > > int > -nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, > - uint32_t value) > +nfp_cpp_area_writel(struct nfp_cpp_area *area, > + unsigned long offset, > + uint32_t value) > { > int sz; > > @@ -467,8 +486,9 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, > } > > int > -nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, > - uint64_t *value) > +nfp_cpp_area_readq(struct nfp_cpp_area *area, > + unsigned long offset, > + uint64_t *value) > { > int sz; > uint64_t tmp = 0; > @@ -480,8 +500,9 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, > } > > int > -nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, > - uint64_t value) > +nfp_cpp_area_writeq(struct nfp_cpp_area *area, > + unsigned long offset, > + uint64_t value) > { > int sz; > > @@ -492,8 +513,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, > } > > int > -nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > - uint32_t *value) > +nfp_cpp_readl(struct nfp_cpp *cpp, > + uint32_t cpp_id, > + unsigned long long address, > + uint32_t *value) > { > int sz; > uint32_t tmp; > @@ -505,8 +528,10 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > } > > int > -nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > - uint32_t value) > +nfp_cpp_writel(struct nfp_cpp *cpp, > + uint32_t cpp_id, > + unsigned long long address, > + uint32_t value) > { > int sz; > > @@ -517,8 +542,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > } > > int > -nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > - uint64_t *value) > +nfp_cpp_readq(struct nfp_cpp *cpp, > + uint32_t cpp_id, > + unsigned long long address, > + uint64_t *value) > { > int sz; > uint64_t tmp; > @@ -530,8 +557,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > } > > int > -nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > - uint64_t value) > +nfp_cpp_writeq(struct nfp_cpp *cpp, > + uint32_t cpp_id, > + unsigned long long address, > + uint64_t value) > { > int sz; > > @@ -542,7 +571,9 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, > } > > int > -nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) > +nfp_xpb_writel(struct nfp_cpp *cpp, > + uint32_t xpb_addr, > + uint32_t value) > { > uint32_t cpp_dest; > > @@ -552,7 +583,9 @@ nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) > } > > int > -nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) > +nfp_xpb_readl(struct nfp_cpp *cpp, > + uint32_t xpb_addr, > + uint32_t *value) > { > uint32_t cpp_dest; > > @@ -562,7 +595,8 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) > } > > static struct nfp_cpp * > -nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) > +nfp_cpp_alloc(struct rte_pci_device *dev, > + int driver_lock_needed) > { > const struct nfp_cpp_operations *ops; > struct nfp_cpp *cpp; > @@ -596,7 +630,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) > /* Hardcoded XPB IMB Base, island 0 */ > xpbaddr = 0x000a0000 + (tgt * 4); > err = nfp_xpb_readl(cpp, xpbaddr, > - (uint32_t *)&cpp->imb_cat_table[tgt]); > + (uint32_t *)&cpp->imb_cat_table[tgt]); > if (err < 0) { > free(cpp); > return NULL; > @@ -631,7 +665,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) > } > > struct nfp_cpp * > -nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) > +nfp_cpp_from_device_name(struct rte_pci_device *dev, > + int driver_lock_needed) > { > return nfp_cpp_alloc(dev, driver_lock_needed); > } > @@ -647,7 +682,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) > * @return 0 on success, or -1 on failure. > */ > int > -nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > +nfp_xpb_writelm(struct nfp_cpp *cpp, > + uint32_t xpb_tgt, > + uint32_t mask, > uint32_t value) > { > int err; > @@ -674,8 +711,11 @@ nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > * @return >= 0 on success, or negative value on failure. > */ > int > -nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > - uint32_t value, int timeout_us) > +nfp_xpb_waitlm(struct nfp_cpp *cpp, > + uint32_t xpb_tgt, > + uint32_t mask, > + uint32_t value, > + int timeout_us) > { > uint32_t tmp; > int err; > @@ -716,8 +756,11 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, > * @length: number of bytes to read > */ > int > -nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, > - unsigned long long address, void *kernel_vaddr, size_t length) > +nfp_cpp_read(struct nfp_cpp *cpp, > + uint32_t destination, > + unsigned long long address, > + void *kernel_vaddr, > + size_t length) > { > struct nfp_cpp_area *area; > int err; > @@ -743,9 +786,11 @@ nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, > * @length: number of bytes to write > */ > int > -nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, > - unsigned long long address, const void *kernel_vaddr, > - size_t length) > +nfp_cpp_write(struct nfp_cpp *cpp, > + uint32_t destination, > + unsigned long long address, > + const void *kernel_vaddr, > + size_t length) > { > struct nfp_cpp_area *area; > int err; > @@ -768,8 +813,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, > * @length: length of area to fill > */ > int > -nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, > - uint32_t value, size_t length) > +nfp_cpp_area_fill(struct nfp_cpp_area *area, > + unsigned long offset, > + uint32_t value, > + size_t length) > { > int err; > size_t i; > @@ -795,9 +842,8 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, > } > > for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { > - err = > - nfp_cpp_area_write(area, offset + i, &value64, > - sizeof(value64)); > + err = nfp_cpp_area_write(area, offset + i, &value64, > + sizeof(value64)); > if (err < 0) > return err; > if (err != sizeof(value64)) > @@ -805,8 +851,7 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, > } > > if ((i + sizeof(value)) <= length) { > - err = > - nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); > + err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); > if (err < 0) > return err; > if (err != sizeof(value)) > @@ -822,13 +867,14 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, > * as those are model-specific > */ > uint32_t > -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) > +__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, > + uint32_t *model) > { > uint32_t reg; > int err; > > err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, > - ®); > + ®); > if (err < 0) > return err; > > @@ -853,8 +899,11 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) > * Return: Pointer to memory mapped area or NULL > */ > uint8_t * > -nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, > - unsigned long size, struct nfp_cpp_area **area) > +nfp_cpp_map_area(struct nfp_cpp *cpp, > + uint32_t cpp_id, > + uint64_t addr, > + unsigned long size, > + struct nfp_cpp_area **area) > { > uint8_t *res; > > diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c > index 20431bf845..2cd8866253 100644 > --- a/drivers/net/nfp/nfpcore/nfp_crc.c > +++ b/drivers/net/nfp/nfpcore/nfp_crc.c > @@ -9,27 +9,31 @@ > #include "nfp_crc.h" > > static inline uint32_t > -nfp_crc32_be_generic(uint32_t crc, unsigned char const *p, size_t len, > - uint32_t polynomial) > +nfp_crc32_be_generic(uint32_t crc, > + unsigned char const *p, > + size_t len, > + uint32_t polynomial) > { > int i; > while (len--) { > crc ^= *p++ << 24; > for (i = 0; i < 8; i++) > - crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : > - 0); > + crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); > } > return crc; > } > > static inline uint32_t > -nfp_crc32_be(uint32_t crc, unsigned char const *p, size_t len) > +nfp_crc32_be(uint32_t crc, > + unsigned char const *p, > + size_t len) > { > return nfp_crc32_be_generic(crc, p, len, CRCPOLY_BE); > } > > static uint32_t > -nfp_crc32_posix_end(uint32_t crc, size_t total_len) > +nfp_crc32_posix_end(uint32_t crc, > + size_t total_len) > { > /* Extend with the length of the string. */ > while (total_len != 0) { > @@ -43,7 +47,8 @@ nfp_crc32_posix_end(uint32_t crc, size_t total_len) > } > > uint32_t > -nfp_crc32_posix(const void *buff, size_t len) > +nfp_crc32_posix(const void *buff, > + size_t len) > { > return nfp_crc32_posix_end(nfp_crc32_be(0, buff, len), len); > } > diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c > index a9d166c4dc..ea4c7d6a9e 100644 > --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c > +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c > @@ -33,12 +33,13 @@ nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) > } > > static int > -nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) > +nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, > + uint32_t size) > { > const char *key, *val, *end = hwinfo->data + size; > > for (key = hwinfo->data; *key != 0 && key < end; > - key = val + strlen(val) + 1) { > + key = val + strlen(val) + 1) { > val = key + strlen(key) + 1; > if (val >= end) { > PMD_DRV_LOG(ERR, "Bad HWINFO - overflowing value"); > @@ -54,7 +55,8 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) > } > > static int > -nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) > +nfp_hwinfo_db_validate(struct nfp_hwinfo *db, > + uint32_t len) > { > uint32_t size, new_crc, *crc; > > @@ -69,7 +71,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) > crc = (uint32_t *)(db->start + size); > if (new_crc != *crc) { > PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", > - new_crc, *crc); > + new_crc, *crc); > return -EINVAL; > } > > @@ -77,7 +79,8 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) > } > > static struct nfp_hwinfo * > -nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) > +nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, > + size_t *cpp_size) > { > struct nfp_hwinfo *header; > void *res; > @@ -115,7 +118,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) > > if (header->version != NFP_HWINFO_VERSION_2) { > PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", > - header->version); > + header->version); > goto exit_free; > } > > @@ -129,7 +132,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) > } > > static struct nfp_hwinfo * > -nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) > +nfp_hwinfo_fetch(struct nfp_cpp *cpp, > + size_t *hwdb_size) > { > struct timespec wait; > struct nfp_hwinfo *db; > @@ -179,7 +183,8 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) > * Return: Value of the HWInfo name, or NULL > */ > const char * > -nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) > +nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, > + const char *lookup) > { > const char *key, *val, *end; > > @@ -189,7 +194,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) > end = hwinfo->data + hwinfo->size - sizeof(uint32_t); > > for (key = hwinfo->data; *key != 0 && key < end; > - key = val + strlen(val) + 1) { > + key = val + strlen(val) + 1) { > val = key + strlen(key) + 1; > > if (strcmp(key, lookup) == 0) > diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c > index f9723dd136..0071d3fc37 100644 > --- a/drivers/net/nfp/nfpcore/nfp_mip.c > +++ b/drivers/net/nfp/nfpcore/nfp_mip.c > @@ -37,8 +37,10 @@ struct nfp_mip { > > /* Read memory and check if it could be a valid MIP */ > static int > -nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, > - struct nfp_mip *mip) > +nfp_mip_try_read(struct nfp_cpp *cpp, > + uint32_t cpp_id, > + uint64_t addr, > + struct nfp_mip *mip) > { > int ret; > > @@ -49,12 +51,12 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, > } > if (mip->signature != NFP_MIP_SIGNATURE) { > PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", > - rte_le_to_cpu_32(mip->signature)); > + rte_le_to_cpu_32(mip->signature)); > return -EINVAL; > } > if (mip->mip_version != NFP_MIP_VERSION) { > PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", > - rte_le_to_cpu_32(mip->mip_version)); > + rte_le_to_cpu_32(mip->mip_version)); > return -EINVAL; > } > > @@ -63,7 +65,8 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, > > /* Try to locate MIP using the resource table */ > static int > -nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) > +nfp_mip_read_resource(struct nfp_cpp *cpp, > + struct nfp_mip *mip) > { > struct nfp_nffw_info *nffw_info; > uint32_t cpp_id; > @@ -134,7 +137,9 @@ nfp_mip_name(const struct nfp_mip *mip) > * @size: Location for size of MIP symbol table > */ > void > -nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) > +nfp_mip_symtab(const struct nfp_mip *mip, > + uint32_t *addr, > + uint32_t *size) > { > *addr = rte_le_to_cpu_32(mip->symtab_addr); > *size = rte_le_to_cpu_32(mip->symtab_size); > @@ -147,7 +152,9 @@ nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) > * @size: Location for size of MIP symbol name table > */ > void > -nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) > +nfp_mip_strtab(const struct nfp_mip *mip, > + uint32_t *addr, > + uint32_t *size) > { > *addr = rte_le_to_cpu_32(mip->strtab_addr); > *size = rte_le_to_cpu_32(mip->strtab_size); > diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h > index d0919b58fe..980abc2517 100644 > --- a/drivers/net/nfp/nfpcore/nfp_mip.h > +++ b/drivers/net/nfp/nfpcore/nfp_mip.h > @@ -17,5 +17,5 @@ const char *nfp_mip_name(const struct nfp_mip *mip); > void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); > void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); > int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, > - uint64_t *off); > + uint64_t *off); > #endif > diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c > index 0410a00856..047e755416 100644 > --- a/drivers/net/nfp/nfpcore/nfp_mutex.c > +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c > @@ -35,7 +35,9 @@ struct nfp_cpp_mutex { > }; > > static int > -_nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) > +_nfp_cpp_mutex_validate(uint32_t model, > + int *target, > + unsigned long long address) > { > /* Address must be 64-bit aligned */ > if ((address & 7) != 0) > @@ -72,8 +74,10 @@ _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) > * @return 0 on success, or negative value on failure. > */ > int > -nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, > - uint32_t key) > +nfp_cpp_mutex_init(struct nfp_cpp *cpp, > + int target, > + unsigned long long address, > + uint32_t key) > { > uint32_t model = nfp_cpp_model(cpp); > uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ > @@ -87,9 +91,8 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, > if (err < 0) > return err; > > - err = > - nfp_cpp_writel(cpp, muw, address + 0, > - MUTEX_LOCKED(nfp_cpp_interface(cpp))); > + err = nfp_cpp_writel(cpp, muw, address + 0, > + MUTEX_LOCKED(nfp_cpp_interface(cpp))); > if (err < 0) > return err; > > @@ -114,8 +117,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, > * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. > */ > struct nfp_cpp_mutex * > -nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, > - unsigned long long address, uint32_t key) > +nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, > + int target, > + unsigned long long address, > + uint32_t key) > { > uint32_t model = nfp_cpp_model(cpp); > struct nfp_cpp_mutex *mutex; > @@ -265,8 +270,8 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) > return err; > if (time(NULL) >= warn_at) { > PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", > - mutex->usage, mutex->depth, mutex->target, > - mutex->address, mutex->key); > + mutex->usage, mutex->depth, mutex->target, > + mutex->address, mutex->key); > warn_at = time(NULL) + 60; > } > sched_yield(); > diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c > index 433780a5e7..fa65956baa 100644 > --- a/drivers/net/nfp/nfpcore/nfp_nffw.c > +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c > @@ -85,7 +85,8 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) > } > > static unsigned int > -nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) > +nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, > + struct nffw_fwinfo **arr) > { > /* > * For the this code, version 0 is most likely to be version 1 in this > @@ -138,8 +139,8 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) > goto err_release; > > err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), > - nfp_resource_address(state->res), > - fwinf, sizeof(*fwinf)); > + nfp_resource_address(state->res), > + fwinf, sizeof(*fwinf)); > if (err < (int)sizeof(*fwinf)) > goto err_release; > > @@ -205,8 +206,9 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) > * Return: 0, or -ERRNO > */ > int > -nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, > - uint64_t *off) > +nfp_nffw_info_mip_first(struct nfp_nffw_info *state, > + uint32_t *cpp_id, > + uint64_t *off) > { > struct nffw_fwinfo *fwinfo; > > diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c > index 6474abf0c2..4f476f6f2b 100644 > --- a/drivers/net/nfp/nfpcore/nfp_nsp.c > +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c > @@ -22,7 +22,8 @@ nfp_nsp_config_modified(struct nfp_nsp *state) > } > > void > -nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified) > +nfp_nsp_config_set_modified(struct nfp_nsp *state, > + int modified) > { > state->modified = modified; > } > @@ -40,7 +41,9 @@ nfp_nsp_config_idx(struct nfp_nsp *state) > } > > void > -nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx) > +nfp_nsp_config_set_state(struct nfp_nsp *state, > + void *entries, > + unsigned int idx) > { > state->entries = entries; > state->idx = idx; > @@ -91,7 +94,7 @@ nfp_nsp_check(struct nfp_nsp *state) > > if (state->ver.major != NSP_MAJOR || state->ver.minor < NSP_MINOR) { > PMD_DRV_LOG(ERR, "Unsupported ABI %hu.%hu", state->ver.major, > - state->ver.minor); > + state->ver.minor); > return -EINVAL; > } > > @@ -160,8 +163,12 @@ nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state) > } > > static int > -nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, > - uint64_t addr, uint64_t mask, uint64_t val) > +nfp_nsp_wait_reg(struct nfp_cpp *cpp, > + uint64_t *reg, > + uint32_t nsp_cpp, > + uint64_t addr, > + uint64_t mask, > + uint64_t val) > { > struct timespec wait; > int count; > @@ -204,8 +211,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, > * -ETIMEDOUT if the NSP took longer than 30 seconds to complete > */ > static int > -nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, > - uint32_t buff_cpp, uint64_t buff_addr) > +nfp_nsp_command(struct nfp_nsp *state, > + uint16_t code, > + uint32_t option, > + uint32_t buff_cpp, > + uint64_t buff_addr) > { > uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; > struct nfp_cpp *cpp = state->cpp; > @@ -223,40 +233,40 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, > return err; > > if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || > - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { > + !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { > PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, > - buff_cpp, buff_addr); > + buff_cpp, buff_addr); > return -EINVAL; > } > > err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, > - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | > - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); > + FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | > + FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); > if (err < 0) > return err; > > err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, > - FIELD_PREP(NSP_COMMAND_OPTION, option) | > - FIELD_PREP(NSP_COMMAND_CODE, code) | > - FIELD_PREP(NSP_COMMAND_START, 1)); > + FIELD_PREP(NSP_COMMAND_OPTION, option) | > + FIELD_PREP(NSP_COMMAND_CODE, code) | > + FIELD_PREP(NSP_COMMAND_START, 1)); > if (err < 0) > return err; > > /* Wait for NSP_COMMAND_START to go to 0 */ > err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, > - NSP_COMMAND_START, 0); > + NSP_COMMAND_START, 0); > if (err != 0) { > PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", > - err, code); > + err, code); > return err; > } > > /* Wait for NSP_STATUS_BUSY to go to 0 */ > - err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, > - 0); > + err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, > + NSP_STATUS_BUSY, 0); > if (err != 0) { > PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", > - err, code); > + err, code); > return err; > } > > @@ -268,7 +278,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, > err = FIELD_GET(NSP_STATUS_RESULT, reg); > if (err != 0) { > PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", > - -err, (int)ret_val, code); > + -err, (int)ret_val, code); > nfp_nsp_print_extended_error(ret_val); > return -err; > } > @@ -279,9 +289,12 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, > #define SZ_1M 0x00100000 > > static int > -nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, > - const void *in_buf, unsigned int in_size, void *out_buf, > - unsigned int out_size) > +nfp_nsp_command_buf(struct nfp_nsp *nsp, > + uint16_t code, uint32_t option, > + const void *in_buf, > + unsigned int in_size, > + void *out_buf, > + unsigned int out_size) > { > struct nfp_cpp *cpp = nsp->cpp; > unsigned int max_size; > @@ -291,28 +304,26 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, > > if (nsp->ver.minor < 13) { > PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", > - code, nsp->ver.major, nsp->ver.minor); > + code, nsp->ver.major, nsp->ver.minor); > return -EOPNOTSUPP; > } > > err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), > - nfp_resource_address(nsp->res) + > - NSP_DFLT_BUFFER_CONFIG, > - ®); > + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, > + ®); > if (err < 0) > return err; > > max_size = RTE_MAX(in_size, out_size); > if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { > PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", > - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); > + code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); > return -EINVAL; > } > > err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), > - nfp_resource_address(nsp->res) + > - NSP_DFLT_BUFFER, > - ®); > + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, > + ®); > if (err < 0) > return err; > > @@ -328,7 +339,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, > if (out_buf != NULL && out_size > 0 && out_size > in_size) { > memset(out_buf, 0, out_size - in_size); > err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, > - out_size - in_size); > + out_size - in_size); > if (err < 0) > return err; > } > @@ -388,38 +399,47 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) > } > > int > -nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size) > +nfp_nsp_load_fw(struct nfp_nsp *state, > + void *buf, > + unsigned int size) > { > return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, > - NULL, 0); > + NULL, 0); > } > > int > -nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size) > +nfp_nsp_read_eth_table(struct nfp_nsp *state, > + void *buf, > + unsigned int size) > { > return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, > - buf, size); > + buf, size); > } > > int > -nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, > - unsigned int size) > +nfp_nsp_write_eth_table(struct nfp_nsp *state, > + const void *buf, > + unsigned int size) > { > return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, > - NULL, 0); > + NULL, 0); > } > > int > -nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size) > +nfp_nsp_read_identify(struct nfp_nsp *state, > + void *buf, > + unsigned int size) > { > return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, > - buf, size); > + buf, size); > } > > int > -nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, void *buf, > - unsigned int size) > +nfp_nsp_read_sensors(struct nfp_nsp *state, > + unsigned int sensor_mask, > + void *buf, > + unsigned int size) > { > return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, > - 0, buf, size); > + 0, buf, size); > } > diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h > index 9905b2d3d3..1e2deaabb4 100644 > --- a/drivers/net/nfp/nfpcore/nfp_nsp.h > +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h > @@ -114,9 +114,10 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); > int nfp_nsp_mac_reinit(struct nfp_nsp *state); > int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); > int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, > - void *buf, unsigned int size); > + void *buf, unsigned int size); > > -static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) > +static inline int > +nfp_nsp_has_mac_reinit(struct nfp_nsp *state) > { > return nfp_nsp_get_abi_ver_minor(state) > 20; > } > @@ -229,22 +230,22 @@ struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); > > int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); > int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, > - int configed); > -int > -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); > + int configed); > +int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); > > int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); > int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, > - unsigned int size); > + unsigned int size); > void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, > - unsigned int idx); > + unsigned int idx); > void nfp_nsp_config_clear_state(struct nfp_nsp *state); > void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); > void *nfp_nsp_config_entries(struct nfp_nsp *state); > int nfp_nsp_config_modified(struct nfp_nsp *state); > unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); > > -static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) > +static inline int > +nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) > { > return !!eth_port->fec_modes_supported; > } > @@ -297,6 +298,6 @@ enum nfp_nsp_sensor_id { > }; > > int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, > - long *val); > + long *val); > > #endif > diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c > index 21b338461e..28dba27124 100644 > --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c > +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c > @@ -73,7 +73,9 @@ struct nfp_sensors { > }; > > int > -nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val) > +nfp_hwmon_read_sensor(struct nfp_cpp *cpp, > + enum nfp_nsp_sensor_id id, > + long *val) > { > struct nfp_sensors s; > struct nfp_nsp *nsp; > diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c > index 825a84a8cd..51bd57033e 100644 > --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c > +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c > @@ -159,7 +159,8 @@ nfp_eth_speed2rate(unsigned int speed) > } > > static void > -nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) > +nfp_eth_copy_mac_reverse(uint8_t *dst, > + const uint8_t *src) > { > int i; > > @@ -168,8 +169,10 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) > } > > static void > -nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, > - unsigned int index, struct nfp_eth_table_port *dst) > +nfp_eth_port_translate(struct nfp_nsp *nsp, > + const union eth_table_entry *src, > + unsigned int index, > + struct nfp_eth_table_port *dst) > { > unsigned int rate; > unsigned int fec; > @@ -225,21 +228,21 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) > > for (i = 0; i < table->count; i++) { > table->max_index = RTE_MAX(table->max_index, > - table->ports[i].index); > + table->ports[i].index); > > for (j = 0; j < table->count; j++) { > if (table->ports[i].label_port != > - table->ports[j].label_port) > + table->ports[j].label_port) > continue; > table->ports[i].port_lanes += table->ports[j].lanes; > > if (i == j) > continue; > if (table->ports[i].label_subport == > - table->ports[j].label_subport) > + table->ports[j].label_subport) > PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", > - table->ports[i].label_port, > - table->ports[i].label_subport); > + table->ports[i].label_port, > + table->ports[i].label_subport); > > table->ports[i].is_split = 1; > } > @@ -296,7 +299,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) > */ > if (ret != 0 && ret != cnt) { > PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", > - ret, cnt); > + ret, cnt); > goto err; > } > > @@ -354,7 +357,8 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) > } > > struct nfp_nsp * > -nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx) > +nfp_eth_config_start(struct nfp_cpp *cpp, > + unsigned int idx) > { > union eth_table_entry *entries; > struct nfp_nsp *nsp; > @@ -447,7 +451,9 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) > * -ERRNO - configuration failed. > */ > int > -nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) > +nfp_eth_set_mod_enable(struct nfp_cpp *cpp, > + unsigned int idx, > + int enable) > { > union eth_table_entry *entries; > struct nfp_nsp *nsp; > @@ -487,7 +493,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) > * -ERRNO - configuration failed. > */ > int > -nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) > +nfp_eth_set_configured(struct nfp_cpp *cpp, > + unsigned int idx, > + int configed) > { > union eth_table_entry *entries; > struct nfp_nsp *nsp; > @@ -523,9 +531,12 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) > } > > static int > -nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, > - const uint64_t mask, const unsigned int shift, > - unsigned int val, const uint64_t ctrl_bit) > +nfp_eth_set_bit_config(struct nfp_nsp *nsp, > + unsigned int raw_idx, > + const uint64_t mask, > + const unsigned int shift, > + unsigned int val, > + const uint64_t ctrl_bit) > { > union eth_table_entry *entries = nfp_nsp_config_entries(nsp); > unsigned int idx = nfp_nsp_config_idx(nsp); > @@ -560,7 +571,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, > (__extension__ ({ \ > typeof(mask) _x = (mask); \ > nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ > - val, ctrl_bit); \ > + val, ctrl_bit); \ > })) > > /* > @@ -574,11 +585,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, > * Return: 0 or -ERRNO. > */ > int > -__nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) > +__nfp_eth_set_aneg(struct nfp_nsp *nsp, > + enum nfp_eth_aneg mode) > { > return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, > - NSP_ETH_STATE_ANEG, mode, > - NSP_ETH_CTRL_SET_ANEG); > + NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); > } > > /* > @@ -592,11 +603,11 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) > * Return: 0 or -ERRNO. > */ > static int > -__nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) > +__nfp_eth_set_fec(struct nfp_nsp *nsp, > + enum nfp_eth_fec mode) > { > return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, > - NSP_ETH_STATE_FEC, mode, > - NSP_ETH_CTRL_SET_FEC); > + NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); > } > > /* > @@ -611,7 +622,9 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) > * -ERRNO - configuration failed. > */ > int > -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) > +nfp_eth_set_fec(struct nfp_cpp *cpp, > + unsigned int idx, > + enum nfp_eth_fec mode) > { > struct nfp_nsp *nsp; > int err; > @@ -642,7 +655,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) > * Return: 0 or -ERRNO. > */ > int > -__nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) > +__nfp_eth_set_speed(struct nfp_nsp *nsp, > + unsigned int speed) > { > enum nfp_eth_rate rate; > > @@ -653,8 +667,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) > } > > return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, > - NSP_ETH_STATE_RATE, rate, > - NSP_ETH_CTRL_SET_RATE); > + NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); > } > > /* > @@ -668,8 +681,9 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) > * Return: 0 or -ERRNO. > */ > int > -__nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes) > +__nfp_eth_set_split(struct nfp_nsp *nsp, > + unsigned int lanes) > { > - return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, > - lanes, NSP_ETH_CTRL_SET_LANES); > + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, > + NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); > } > diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c > index 838cd6e0ef..57089c770f 100644 > --- a/drivers/net/nfp/nfpcore/nfp_resource.c > +++ b/drivers/net/nfp/nfpcore/nfp_resource.c > @@ -64,7 +64,8 @@ struct nfp_resource { > }; > > static int > -nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) > +nfp_cpp_resource_find(struct nfp_cpp *cpp, > + struct nfp_resource *res) > { > char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; > struct nfp_resource_entry entry; > @@ -85,7 +86,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) > > for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { > uint64_t addr = NFP_RESOURCE_TBL_BASE + > - sizeof(struct nfp_resource_entry) * i; > + sizeof(struct nfp_resource_entry) * i; > > ret = nfp_cpp_read(cpp, cpp_id, addr, &entry, sizeof(entry)); > if (ret != sizeof(entry)) > @@ -95,12 +96,11 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) > continue; > > /* Found key! */ > - res->mutex = > - nfp_cpp_mutex_alloc(cpp, > - NFP_RESOURCE_TBL_TARGET, addr, key); > + res->mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, > + addr, key); > res->cpp_id = NFP_CPP_ID(entry.region.cpp_target, > - entry.region.cpp_action, > - entry.region.cpp_token); > + entry.region.cpp_action, > + entry.region.cpp_token); > res->addr = ((uint64_t)entry.region.page_offset) << 8; > res->size = (uint64_t)entry.region.page_size << 8; > return 0; > @@ -110,8 +110,9 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) > } > > static int > -nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, > - struct nfp_cpp_mutex *dev_mutex) > +nfp_resource_try_acquire(struct nfp_cpp *cpp, > + struct nfp_resource *res, > + struct nfp_cpp_mutex *dev_mutex) > { > int err; > > @@ -148,7 +149,8 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, > * Return: NFP Resource handle, or NULL > */ > struct nfp_resource * > -nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) > +nfp_resource_acquire(struct nfp_cpp *cpp, > + const char *name) > { > struct nfp_cpp_mutex *dev_mutex; > struct nfp_resource *res; > @@ -165,8 +167,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) > strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); > > dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, > - NFP_RESOURCE_TBL_BASE, > - NFP_RESOURCE_TBL_KEY); > + NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); > if (dev_mutex == NULL) { > free(res); > return NULL; > @@ -234,8 +235,8 @@ nfp_resource_cpp_id(const struct nfp_resource *res) > * > * Return: const char pointer to the name of the resource > */ > -const char > -*nfp_resource_name(const struct nfp_resource *res) > +const char * > +nfp_resource_name(const struct nfp_resource *res) > { > return res->name; > } > diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h > index 06cc6f74f4..009b7359a4 100644 > --- a/drivers/net/nfp/nfpcore/nfp_resource.h > +++ b/drivers/net/nfp/nfpcore/nfp_resource.h > @@ -18,7 +18,7 @@ > struct nfp_resource; > > struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, > - const char *name); > + const char *name); > > /** > * Release a NFP Resource, and free the handle > diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c > index 4c45aec5c1..aa3b7a483e 100644 > --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c > +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c > @@ -40,22 +40,25 @@ struct nfp_rtsym_table { > }; > > static int > -nfp_meid(uint8_t island_id, uint8_t menum) > +nfp_meid(uint8_t island_id, > + uint8_t menum) > { > return (island_id & 0x3F) == island_id && menum < 12 ? > (island_id << 4) | (menum + 4) : -1; > } > > static void > -nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, uint32_t strtab_size, > - struct nfp_rtsym *sw, struct nfp_rtsym_entry *fw) > +nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, > + uint32_t strtab_size, > + struct nfp_rtsym *sw, > + struct nfp_rtsym_entry *fw) > { > sw->type = fw->type; > sw->name = cache->strtab + rte_le_to_cpu_16(fw->name) % strtab_size; > sw->addr = ((uint64_t)fw->addr_hi << 32) | > - rte_le_to_cpu_32(fw->addr_lo); > + rte_le_to_cpu_32(fw->addr_lo); > sw->size = ((uint64_t)fw->size_hi << 32) | > - rte_le_to_cpu_32(fw->size_lo); > + rte_le_to_cpu_32(fw->size_lo); > > PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", > sw->name, sw->addr, sw->size, sw->target); > @@ -93,7 +96,8 @@ nfp_rtsym_table_read(struct nfp_cpp *cpp) > } > > struct nfp_rtsym_table * > -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) > +__nfp_rtsym_table_read(struct nfp_cpp *cpp, > + const struct nfp_mip *mip) > { > uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; > struct nfp_rtsym_entry *rtsymtab; > @@ -142,7 +146,7 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) > > for (n = 0; n < cache->num; n++) > nfp_rtsym_sw_entry_init(cache, strtab_size, > - &cache->symtab[n], &rtsymtab[n]); > + &cache->symtab[n], &rtsymtab[n]); > > free(rtsymtab); > > @@ -178,7 +182,8 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) > * Return: const pointer to a struct nfp_rtsym descriptor, or NULL > */ > const struct nfp_rtsym * > -nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) > +nfp_rtsym_get(struct nfp_rtsym_table *rtbl, > + int idx) > { > if (rtbl == NULL) > return NULL; > @@ -197,7 +202,8 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) > * Return: const pointer to a struct nfp_rtsym descriptor, or NULL > */ > const struct nfp_rtsym * > -nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name) > +nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, > + const char *name) > { > int n; > > @@ -331,7 +337,9 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, > * Return: value read, on error sets the error and returns ~0ULL. > */ > uint64_t > -nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) > +nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, > + const char *name, > + int *error) > { > const struct nfp_rtsym *sym; > uint32_t val32; > @@ -354,7 +362,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) > break; > default: > PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, > - name, sym->size); > + name, sym->size); > err = -EINVAL; > break; > } > @@ -372,8 +380,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) > } > > uint8_t * > -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, > - unsigned int min_size, struct nfp_cpp_area **area) > +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, > + const char *name, > + unsigned int min_size, > + struct nfp_cpp_area **area) > { > int ret; > uint8_t *mem; > @@ -397,7 +407,7 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, > > if (sym->size < min_size) { > PMD_DRV_LOG(ERR, "Symbol %s too small (%" PRIu64 " < %u)", name, > - sym->size, min_size); > + sym->size, min_size); > return NULL; > } > > diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h > index 8b494211bc..30768f1ccf 100644 > --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h > +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h > @@ -43,19 +43,18 @@ struct nfp_rtsym_table; > > struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); > > -struct nfp_rtsym_table * > -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip); > +struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, > + const struct nfp_mip *mip); > > 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); > +const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, > + const char *name); > > uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, > - int *error); > -uint8_t * > -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, > - unsigned int min_size, struct nfp_cpp_area **area); > + int *error); > +uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, > + unsigned int min_size, struct nfp_cpp_area **area); > #endif -- Kind Regards, Niklas Söderlund ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 03/26] net/nfp: unify the type of integer variable 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He 2023-09-18 2:45 ` [PATCH v4 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-09-18 2:45 ` [PATCH v4 02/26] net/nfp: unify the indent coding style Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 04/26] net/nfp: remove the unneeded logic Chaoyong He ` (25 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Unify the type of integer variable to the DPDK prefer style. Also change the return type of 'nfp_eth_speed2rate()' to the corresponding enum, which make it more readable. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 53 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 20 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 40 +++++++-------- drivers/net/nfp/nfpcore/nfp_crc.c | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nffw.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nsp.c | 28 +++++----- drivers/net/nfp/nfpcore/nfp_nsp.h | 59 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 52 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- 13 files changed, 142 insertions(+), 141 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 54bef3cb6b..782272a3f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -71,8 +71,8 @@ struct nfp_cpp_operations { */ int (*area_init)(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size); + uint64_t address, + size_t size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -103,16 +103,16 @@ struct nfp_cpp_operations { */ int (*area_read)(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); }; /* @@ -398,7 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, unsigned long size); + uint64_t address, size_t size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,8 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, const char *name, unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, uint64_t address, + uint32_t size); /* * Free an allocated NFP CPP area handle @@ -446,7 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, unsigned long long address, unsigned long size); + uint32_t cpp_id, uint64_t address, size_t size); /* * Release the resources, then free the NFP CPP area handle @@ -455,7 +455,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, struct nfp_cpp_area **area); + uint64_t addr, uint32_t size, struct nfp_cpp_area **area); + /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -478,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * @return bytes read on success, negative value on failure. * */ -int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); /* @@ -492,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * * @return bytes written on success, negative value on failure. */ -int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); /* @@ -547,7 +548,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + uint64_t address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -561,9 +562,7 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); - + uint64_t address, const void *kernel_vaddr, size_t length); /* @@ -593,7 +592,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); /* @@ -610,7 +609,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); /* @@ -627,7 +626,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); /* @@ -644,7 +643,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); /* @@ -707,7 +706,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + uint64_t address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -721,7 +720,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + uint64_t address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -734,7 +733,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + uint64_t address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -747,7 +746,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + uint64_t address, uint64_t value); /* * Initialize a mutex location @@ -768,7 +767,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -788,7 +787,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 884cc84eaa..881f21bfd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -101,7 +101,7 @@ struct nfp_bar { uint64_t base; /* CPP address base */ uint64_t mask; /* Bit mask of the bar */ uint32_t bitsize; /* Bit size of the bar */ - int index; + uint32_t index; int lock; char *csr; @@ -400,8 +400,8 @@ struct nfp6000_area_priv { static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -501,8 +501,8 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -510,7 +510,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -571,8 +571,8 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -580,7 +580,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, struct nfp6000_area_priv *priv; uint32_t *wrptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -752,7 +752,7 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - unsigned long tmp; + uint64_t tmp; int i = 0; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f764208a9a..627d4eaa5d 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -169,8 +169,8 @@ struct nfp_cpp_area * nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, const char *name, - unsigned long long address, - unsigned long size) + uint64_t address, + uint32_t size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -184,7 +184,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, if (err < 0) return NULL; - address = (unsigned long long)tmp64; + address = tmp64; if (name == NULL) name = ""; @@ -213,8 +213,8 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -237,8 +237,8 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_cpp_area *area; @@ -352,7 +352,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) */ int nfp_cpp_area_read(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, void *kernel_vaddr, size_t length) { @@ -378,7 +378,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, */ int nfp_cpp_area_write(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, const void *kernel_vaddr, size_t length) { @@ -461,7 +461,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, int nfp_cpp_area_readl(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t *value) { int sz; @@ -475,7 +475,7 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, int nfp_cpp_area_writel(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t value) { int sz; @@ -487,7 +487,7 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, int nfp_cpp_area_readq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t *value) { int sz; @@ -501,7 +501,7 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, int nfp_cpp_area_writeq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t value) { int sz; @@ -515,7 +515,7 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t *value) { int sz; @@ -530,7 +530,7 @@ nfp_cpp_readl(struct nfp_cpp *cpp, int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t value) { int sz; @@ -544,7 +544,7 @@ nfp_cpp_writel(struct nfp_cpp *cpp, int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t *value) { int sz; @@ -559,7 +559,7 @@ nfp_cpp_readq(struct nfp_cpp *cpp, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t value) { int sz; @@ -758,7 +758,7 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, void *kernel_vaddr, size_t length) { @@ -788,7 +788,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, const void *kernel_vaddr, size_t length) { @@ -902,7 +902,7 @@ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, + uint32_t size, struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 2cd8866253..68f27f8c68 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -14,7 +14,7 @@ nfp_crc32_be_generic(uint32_t crc, size_t len, uint32_t polynomial) { - int i; + uint32_t i; while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 047e755416..7ac06e897a 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -28,16 +28,16 @@ struct nfp_cpp_mutex { struct nfp_cpp *cpp; uint8_t target; uint16_t depth; - unsigned long long address; + uint64_t address; uint32_t key; - unsigned int usage; + uint32_t usage; struct nfp_cpp_mutex *prev, *next; }; static int _nfp_cpp_mutex_validate(uint32_t model, int *target, - unsigned long long address) + uint64_t address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -76,7 +76,7 @@ _nfp_cpp_mutex_validate(uint32_t model, int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -119,7 +119,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -269,9 +269,10 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", + PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] " + "target:%d key:%08x] addr:%" PRIx64, mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->key, mutex->address); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index fa65956baa..2412dc0e00 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,7 +68,7 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - unsigned int mode, addr40; + uint32_t mode, addr40; uint32_t xpbaddr, imbcppat; int err; @@ -84,7 +84,7 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) return nfp_cppat_mu_locality_lsb(mode, addr40); } -static unsigned int +static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { @@ -184,7 +184,7 @@ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { struct nffw_fwinfo *fwinfo; - unsigned int cnt, i; + uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4f476f6f2b..dfe396c8ac 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -34,7 +34,7 @@ nfp_nsp_config_entries(struct nfp_nsp *state) return state->entries; } -unsigned int +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state) { return state->idx; @@ -43,7 +43,7 @@ nfp_nsp_config_idx(struct nfp_nsp *state) void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx) + uint32_t idx) { state->entries = entries; state->idx = idx; @@ -59,12 +59,12 @@ nfp_nsp_config_clear_state(struct nfp_nsp *state) static void nfp_nsp_print_extended_error(uint32_t ret_val) { - int i; + uint32_t i; if (ret_val == 0) return; - for (i = 0; i < (int)RTE_DIM(nsp_errors); i++) + for (i = 0; i < RTE_DIM(nsp_errors); i++) if (ret_val == (uint32_t)nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -171,7 +171,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t val) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -297,7 +297,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; - unsigned int max_size; + size_t max_size; uint64_t reg, cpp_buf; int ret, err; uint32_t cpp_id; @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %zu)", code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } @@ -361,7 +361,7 @@ int nfp_nsp_wait(struct nfp_nsp *state) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -401,7 +401,7 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, NULL, 0); @@ -410,7 +410,7 @@ nfp_nsp_load_fw(struct nfp_nsp *state, int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, buf, size); @@ -419,7 +419,7 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, NULL, 0); @@ -428,7 +428,7 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, buf, size); @@ -436,9 +436,9 @@ nfp_nsp_read_identify(struct nfp_nsp *state, int nfp_nsp_read_sensors(struct nfp_nsp *state, - unsigned int sensor_mask, + uint32_t sensor_mask, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, 0, buf, size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 1e2deaabb4..edb56e26ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -110,11 +110,11 @@ uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); int nfp_nsp_wait(struct nfp_nsp *state); int nfp_nsp_device_soft_reset(struct nfp_nsp *state); -int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); -int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); -int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); +int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); +int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, + void *buf, size_t size); static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) @@ -188,17 +188,17 @@ enum nfp_eth_fec { * @fec_modes_supported: bitmap of FEC modes supported */ struct nfp_eth_table { - unsigned int count; - unsigned int max_index; + uint32_t count; + uint32_t max_index; struct nfp_eth_table_port { - unsigned int eth_index; - unsigned int index; - unsigned int nbi; - unsigned int base; - unsigned int lanes; - unsigned int speed; - - unsigned int interface; + uint32_t eth_index; + uint32_t index; + uint32_t nbi; + uint32_t base; + uint32_t lanes; + uint32_t speed; + + uint32_t interface; enum nfp_eth_media media; enum nfp_eth_fec fec; @@ -218,51 +218,50 @@ struct nfp_eth_table { /* Computed fields */ uint8_t port_type; - unsigned int port_lanes; + uint32_t port_lanes; int is_split; - unsigned int fec_modes_supported; + uint32_t fec_modes_supported; } ports[]; }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); -int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + size_t size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); -unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { - return !!eth_port->fec_modes_supported; + return eth_port->fec_modes_supported != 0; } -static inline unsigned int +static inline uint32_t nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported; } -struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx); +struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes); +int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /** * struct nfp_nsp_identify - NSP static information @@ -298,6 +297,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + uint32_t *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 28dba27124..31677b66e6 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -75,7 +75,7 @@ struct nfp_sensors { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val) + uint32_t *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 51bd57033e..5492840aa1 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -124,7 +124,7 @@ union eth_table_entry { static const struct { enum nfp_eth_rate rate; - unsigned int speed; + uint32_t speed; } nsp_eth_rate_tbl[] = { { RATE_INVALID, 0, }, { RATE_10M, SPEED_10, }, @@ -134,24 +134,24 @@ static const struct { { RATE_25G, SPEED_25000, }, }; -static unsigned int +static uint32_t nfp_eth_rate2speed(enum nfp_eth_rate rate) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].rate == rate) return nsp_eth_rate_tbl[i].speed; return 0; } -static unsigned int -nfp_eth_speed2rate(unsigned int speed) +static enum nfp_eth_rate +nfp_eth_speed2rate(uint32_t speed) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].speed == speed) return nsp_eth_rate_tbl[i].rate; @@ -162,7 +162,7 @@ static void nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) { - int i; + uint32_t i; for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) dst[RTE_ETHER_ADDR_LEN - i - 1] = src[i]; @@ -171,11 +171,11 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, static void nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, + uint32_t index, struct nfp_eth_table_port *dst) { - unsigned int rate; - unsigned int fec; + uint32_t rate; + uint32_t fec; uint64_t port, state; port = rte_le_to_cpu_64(src->port); @@ -224,7 +224,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - unsigned int i, j; + uint32_t i, j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -269,7 +269,9 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; struct nfp_eth_table *table; uint32_t table_sz; - int i, j, ret, cnt = 0; + uint32_t i; + uint32_t j; + int ret, cnt = 0; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -319,7 +321,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } nfp_eth_calc_port_geometry(table); - for (i = 0; i < (int)table->count; i++) + for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); free(entries); @@ -358,7 +360,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, - unsigned int idx) + uint32_t idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -452,7 +454,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int enable) { union eth_table_entry *entries; @@ -494,7 +496,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, */ int nfp_eth_set_configured(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int configed) { union eth_table_entry *entries; @@ -532,14 +534,14 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, static int nfp_eth_set_bit_config(struct nfp_nsp *nsp, - unsigned int raw_idx, + uint32_t raw_idx, const uint64_t mask, - const unsigned int shift, - unsigned int val, + const uint32_t shift, + uint32_t val, const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - unsigned int idx = nfp_nsp_config_idx(nsp); + uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; /* @@ -623,7 +625,7 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, */ int nfp_eth_set_fec(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, enum nfp_eth_fec mode) { struct nfp_nsp *nsp; @@ -656,7 +658,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, - unsigned int speed) + uint32_t speed) { enum nfp_eth_rate rate; @@ -682,7 +684,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, */ int __nfp_eth_set_split(struct nfp_nsp *nsp, - unsigned int lanes) + uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 57089c770f..9dd4832779 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -156,7 +156,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; int err; struct timespec wait; - int count; + uint16_t count; res = malloc(sizeof(*res)); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index aa3b7a483e..243d3c9ce5 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -382,7 +382,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, + uint32_t min_size, struct nfp_cpp_area **area) { int ret; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 30768f1ccf..e7295258b3 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -56,5 +56,5 @@ const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + uint32_t min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 04/26] net/nfp: remove the unneeded logic 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (2 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 03/26] net/nfp: unify the type of integer variable Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 05/26] net/nfp: standard the local variable coding style Chaoyong He ` (24 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Remove the unneeded logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 107 ---- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 - drivers/net/nfp/nfpcore/nfp_cppcore.c | 162 ------ drivers/net/nfp/nfpcore/nfp_mutex.c | 48 -- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 24 - drivers/net/nfp/nfpcore/nfp_target.h | 567 --------------------- 6 files changed, 920 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 782272a3f4..139752f85a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -96,7 +96,6 @@ struct nfp_cpp_operations { void *(*area_iomem)(struct nfp_cpp_area *area); - void *(*area_mapped)(struct nfp_cpp_area *area); /* * Perform a read from a NFP CPP area * Serialized @@ -457,16 +456,6 @@ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Return an IO pointer to the beginning of the NFP CPP area handle. The area - * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * - * @return Pointer to IO memory, or NULL on failure. - */ -void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); - /* * Read from a NFP CPP area handle into a buffer. The area must be acquired with * 'nfp_cpp_area_acquire()' before calling this operation. @@ -508,18 +497,6 @@ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Verify that IO can be performed on an offset in an area - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] size Size of region to validate - * - * @return 0 on success, negative value on failure. - */ -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); - /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle * @@ -564,20 +541,6 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); - -/* - * Fill a NFP CPP area handle and offset with a value - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the NFP CPP ID address space - * @param[in] value 32-bit value to fill area with - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, negative value on failure. - */ -int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); - /* * Read a single 32-bit value from a NFP CPP area handle * @@ -668,33 +631,6 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, negative value on failure. - */ -int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); - /* * Read a 32-bit word from a NFP CPP ID * @@ -789,49 +725,6 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Get the NFP CPP handle the mutex was created with - * - * @param mutex NFP mutex handle - * @return NFP CPP handle - */ -struct nfp_cpp *nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex key - * - * @param mutex NFP mutex handle - * @return Mutex key - */ -uint32_t nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex owner - * - * @param mutex NFP mutex handle - * @return Interface ID of the mutex owner - * - * NOTE: This is for debug purposes ONLY - the owner may change at any time, - * unless it has been locked by this NFP CPP handle. - */ -uint16_t nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex target - * - * @param mutex NFP mutex handle - * @return Mutex CPP target (ie NFP_CPP_TARGET_MU) - */ -int nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex address - * - * @param mutex NFP mutex handle - * @return Mutex CPP address - */ -uint64_t nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex); - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 881f21bfd0..ec14ec45dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -471,17 +471,6 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) return 0; } -static void * -nfp6000_area_mapped(struct nfp_cpp_area *area) -{ - struct nfp6000_area_priv *area_priv = nfp_cpp_area_priv(area); - - if (area_priv->iomem == NULL) - return NULL; - - return area_priv->iomem; -} - static void nfp6000_area_release(struct nfp_cpp_area *area) { @@ -829,7 +818,6 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, - .area_mapped = nfp6000_area_mapped, .area_read = nfp6000_area_read, .area_write = nfp6000_area_write, .area_iomem = nfp6000_area_iomem, diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 627d4eaa5d..7e7c36eda3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -388,35 +388,6 @@ nfp_cpp_area_write(struct nfp_cpp_area *area, return area->cpp->op->area_write(area, kernel_vaddr, offset, length); } -void * -nfp_cpp_area_mapped(struct nfp_cpp_area *area) -{ - if (area->cpp->op->area_mapped) - return area->cpp->op->area_mapped(area); - return NULL; -} - -/* - * nfp_cpp_area_check_range - check if address range fits in CPP area - * - * @area: CPP area handle - * @offset: offset into CPP area - * @length: size of address range in bytes - * - * Check if address range fits within CPP area. Return 0 if area fits - * or negative value on error. - */ -int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, - unsigned long length) -{ - if (((offset + length) > area->size)) - return -EFAULT; - - return 0; -} - /* * Return the correct CPP address, and fixup xpb_addr as needed, * based upon NFP model. @@ -671,82 +642,6 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int -nfp_xpb_writelm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value) -{ - int err; - uint32_t tmp; - - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - return err; - - tmp &= ~mask; - tmp |= (mask & value); - return nfp_xpb_writel(cpp, xpb_tgt, tmp); -} - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, or negative value on failure. - */ -int -nfp_xpb_waitlm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value, - int timeout_us) -{ - uint32_t tmp; - int err; - - do { - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - goto exit; - - if ((tmp & mask) == (value & mask)) { - if (timeout_us < 0) - timeout_us = 0; - break; - } - - if (timeout_us < 0) - continue; - - timeout_us -= 100; - usleep(100); - } while (timeout_us >= 0); - - if (timeout_us < 0) - err = -ETIMEDOUT; - else - err = timeout_us; - -exit: - return err; -} - /* * nfp_cpp_read - read from CPP target * @cpp: CPP handle @@ -805,63 +700,6 @@ nfp_cpp_write(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_area_fill - fill a CPP area with a value - * @area: CPP area - * @offset: offset into CPP area - * @value: value to fill with - * @length: length of area to fill - */ -int -nfp_cpp_area_fill(struct nfp_cpp_area *area, - unsigned long offset, - uint32_t value, - size_t length) -{ - int err; - size_t i; - uint64_t value64; - - value = rte_cpu_to_le_32(value); - value64 = ((uint64_t)value << 32) | value; - - if ((offset + length) > area->size) - return -EINVAL; - - if ((area->offset + offset) & 3) - return -EINVAL; - - if (((area->offset + offset) & 7) == 4 && length >= 4) { - err = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - offset += sizeof(value); - length -= sizeof(value); - } - - for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); - if (err < 0) - return err; - if (err != sizeof(value64)) - return -ENOSPC; - } - - if ((i + sizeof(value)) <= length) { - err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - i += sizeof(value); - } - - return (int)i; -} - /* * NOTE: This code should not use nfp_xpb_* functions, * as those are model-specific diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 7ac06e897a..edc8137304 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -178,54 +178,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -struct nfp_cpp * -nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex) -{ - return mutex->cpp; -} - -uint32_t -nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex) -{ - return mutex->key; -} - -uint16_t -nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex) -{ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t value, key; - int err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - return err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); - if (err < 0) - return err; - - if (key != mutex->key) - return -EPERM; - - if (MUTEX_IS_LOCKED(value) == 0) - return 0; - - return MUTEX_INTERFACE(value); -} - -int -nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex) -{ - return mutex->target; -} - -uint64_t -nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex) -{ - return mutex->address; -} - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 5492840aa1..bc155b44d8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,30 +11,6 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) #define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 03908a894f..195e599d31 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,571 +6,4 @@ #ifndef NFP_TARGET_H #define NFP_TARGET_H -#include "nfp_cpp.h" - -#define P32 1 -#define P64 2 - -#define PUSHPULL(_pull, _push) (((_pull) << 4) | ((_push) << 0)) - -#ifndef NFP_ERRNO -#include <errno.h> -#define NFP_ERRNO(x) (errno = (x), -1) -#endif - -static inline int -pushpull_width(int pp) -{ - pp &= 0xf; - - if (pp == 0) - return NFP_ERRNO(EINVAL); - return (2 << pp); -} - -#define PUSH_WIDTH(_pushpull) pushpull_width((_pushpull) >> 0) -#define PULL_WIDTH(_pushpull) pushpull_width((_pushpull) >> 4) - -static inline int -target_rw(uint32_t cpp_id, int pp, int start, int len) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < start || island > (start + len))) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): - return PUSHPULL(0, pp); - case NFP_CPP_ID(0, 1, 0): - return PUSHPULL(pp, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(pp, pp); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_dma(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiDma */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiDma */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_stats(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiStats */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiStats */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_tm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiTM */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiTM */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_ppc(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiPreclassifier */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiPreclassifier */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi(uint32_t cpp_id, uint64_t address) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - uint64_t rel_addr = address & 0x3fFFFF; - - if (island && (island < 8 || island > 9)) - return NFP_ERRNO(EINVAL); - - if (rel_addr < (1 << 20)) - return nfp6000_nbi_dma(cpp_id); - if (rel_addr < (2 << 20)) - return nfp6000_nbi_stats(cpp_id); - if (rel_addr < (3 << 20)) - return nfp6000_nbi_tm(cpp_id); - return nfp6000_nbi_ppc(cpp_id); -} - -/* - * This structure ONLY includes items that can be done with a read or write of - * 32-bit or 64-bit words. All others are not listed. - */ -static inline int -nfp6000_mu_common(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): /* read_be/write_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): /* read_le/write_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 2): /* {read/write}_swap_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 3): /* {read/write}_swap_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, 0, 0): /* read_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 1): /* read_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 2): /* read_swap_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 3): /* read_swap_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* write_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 1): /* write_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 2): /* write_swap_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 3): /* write_swap_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 3, 0): /* atomic_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 2): /* mask_compare_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* atomic_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 2): /* atomic_write_imm */ - return PUSHPULL(0, 0); - case NFP_CPP_ID(0, 4, 3): /* swap_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 5, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 5, 3): /* test_set_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 6, 0): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 3): /* test_clr_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 7, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 7, 3): /* test_add_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 8, 0): /* addsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 3): /* test_sub_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 0): /* microq128_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 1): /* microq128_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 2): /* microq128_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 0): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 3): /* test_xor_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 0): /* read32_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 1): /* read32_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 2): /* read32_swap_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 3): /* read32_swap_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 31, 0): /* write32_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 1): /* write32_le */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 2): /* write32_swap_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 3): /* write32_swap_le */ - return PUSHPULL(P32, 0); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_mu_ctm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 16, 1): /* packet_read_packet_status */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_emu(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 18, 0): /* read_queue */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 1): /* read_queue_ring */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 2): /* write_queue */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 18, 3): /* write_queue_ring */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 20, 2): /* journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 21, 0): /* get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 1): /* get_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 2): /* get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 0): /* pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 1): /* pop_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 2): /* pop_freely */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_imu(uint32_t cpp_id) -{ - return nfp6000_mu_common(cpp_id); -} - -static inline int -nfp6000_mu(uint32_t cpp_id, uint64_t address) -{ - int pp; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island == 0) { - if (address < 0x2000000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x8000000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0x9800000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x9C00000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0xA000000000ULL) - pp = nfp6000_mu_imu(cpp_id); - else - pp = nfp6000_mu_ctm(cpp_id); - } else if (island >= 24 && island <= 27) { - pp = nfp6000_mu_emu(cpp_id); - } else if (island >= 28 && island <= 31) { - pp = nfp6000_mu_imu(cpp_id); - } else if (island == 1 || - (island >= 4 && island <= 7) || - (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { - pp = nfp6000_mu_ctm(cpp_id); - } else { - pp = NFP_ERRNO(EINVAL); - } - - return pp; -} - -static inline int -nfp6000_ila(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 48 || island > 51)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* read_check_error */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 0): /* read_int */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* write_int */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 48, 4); - } -} - -static inline int -nfp6000_pci(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 4 || island > 7)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 4, 4); - } -} - -static inline int -nfp6000_crypto(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 12 || island > 15)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(P64, 0); - default: - return target_rw(cpp_id, P64, 12, 4); - } -} - -static inline int -nfp6000_cap_xpb(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* RingGet */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 0, 2): /* Interthread Signal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 1): /* RingPut */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 2): /* CTNNWr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* ReflectRd, signal none */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 1): /* ReflectRd, signal self */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 2): /* ReflectRd, signal remote */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 3): /* ReflectRd, signal both */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* ReflectWr, signal none */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 1): /* ReflectWr, signal self */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 2): /* ReflectWr, signal remote */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 3): /* ReflectWr, signal both */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): - return PUSHPULL(P32, P32); - default: - return target_rw(cpp_id, P32, 1, 63); - } -} - -static inline int -nfp6000_cls(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 3): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 1): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 1): /* add64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 1): /* sub64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 2): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 2): /* hash_mask */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* hash_clear */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 0): /* ring_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 1): /* ring_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 2): /* ring_get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 3): /* ring_pop_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* ring_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 2): /* ring_journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 14, 0): /* reflect_write_sig_local */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 1): /* reflect_read_sig_local */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 17, 2): /* statistic */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 24, 0): /* ring_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 24, 1): /* ring_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 25, 0): /* ring_workq_add_thread */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 25, 1): /* ring_workq_add_work */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 0, 64); - } -} - -static inline int -nfp6000_target_pushpull(uint32_t cpp_id, uint64_t address) -{ - switch (NFP_CPP_ID_TARGET_of(cpp_id)) { - case NFP6000_CPPTGT_NBI: - return nfp6000_nbi(cpp_id, address); - case NFP6000_CPPTGT_VQDR: - return target_rw(cpp_id, P32, 24, 4); - case NFP6000_CPPTGT_ILA: - return nfp6000_ila(cpp_id); - case NFP6000_CPPTGT_MU: - return nfp6000_mu(cpp_id, address); - case NFP6000_CPPTGT_PCIE: - return nfp6000_pci(cpp_id); - case NFP6000_CPPTGT_ARM: - if (address < 0x10000) - return target_rw(cpp_id, P64, 1, 1); - else - return target_rw(cpp_id, P32, 1, 1); - case NFP6000_CPPTGT_CRYPTO: - return nfp6000_crypto(cpp_id); - case NFP6000_CPPTGT_CTXPB: - return nfp6000_cap_xpb(cpp_id); - case NFP6000_CPPTGT_CLS: - return nfp6000_cls(cpp_id); - case 0: - return target_rw(cpp_id, P32, 4, 4); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_pushpull_width(int pp, int write_not_read) -{ - if (pp < 0) - return pp; - - if (write_not_read) - return PULL_WIDTH(pp); - else - return PUSH_WIDTH(pp); -} - -static inline int -nfp6000_target_action_width(uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - int pp; - - pp = nfp6000_target_pushpull(cpp_id, address); - - return nfp_target_pushpull_width(pp, write_not_read); -} - -static inline int -nfp_target_action_width(uint32_t model, uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - if (NFP_CPP_MODEL_IS_6000(model)) { - return nfp6000_target_action_width(cpp_id, address, - write_not_read); - } else { - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table) -{ - int err; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_island_id); - uint8_t target = NFP_CPP_ID_TARGET_of(cpp_island_id); - uint32_t imb; - - if (target >= 16) - return NFP_ERRNO(EINVAL); - - if (island == 0) { - /* Already translated */ - *cpp_target_id = cpp_island_id; - *cpp_target_address = cpp_island_address; - return 0; - } - - if (imb_table == NULL) { - /* CPP + Island only allowed on systems with IMB tables */ - return NFP_ERRNO(EINVAL); - } - - imb = imb_table[target]; - - *cpp_target_address = cpp_island_address; - err = _nfp6000_cppat_addr_encode(cpp_target_address, island, target, - ((imb >> 13) & 7), - ((imb >> 12) & 1), - ((imb >> 6) & 0x3f), - ((imb >> 0) & 0x3f)); - if (err == 0) { - *cpp_target_id = - NFP_CPP_ID(target, NFP_CPP_ID_ACTION_of(cpp_island_id), - NFP_CPP_ID_TOKEN_of(cpp_island_id)); - } - - return err; -} - #endif /* NFP_TARGET_H */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 05/26] net/nfp: standard the local variable coding style 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (3 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 04/26] net/nfp: remove the unneeded logic Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 06/26] net/nfp: adjust the log statement Chaoyong He ` (23 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund There should only declare one local variable in each line, and the local variable should be arranged from short to long in the function. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 58 ++++++++++++---------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 27 ++++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 8 +-- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 ++++++---- drivers/net/nfp/nfpcore/nfp_nffw.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nsp.c | 40 ++++++++------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +-- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 39 ++++++++------- drivers/net/nfp/nfpcore/nfp_resource.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 19 ++++--- 11 files changed, 151 insertions(+), 117 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index ec14ec45dc..78beee07ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -140,9 +140,9 @@ nfp_compute_bar(const struct nfp_bar *bar, size_t size, int width) { - uint32_t bitsize; - uint32_t newcfg; uint64_t mask; + uint32_t newcfg; + uint32_t bitsize; if (tgt >= 16) return -EINVAL; @@ -239,7 +239,8 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base, slot; + int base; + int slot; base = bar->index >> 3; slot = bar->index & 7; @@ -268,9 +269,9 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, size_t size, int width) { - uint64_t newbase; - uint32_t newcfg; int err; + uint32_t newcfg; + uint64_t newbase; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); @@ -303,8 +304,10 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, static int nfp_enable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -333,8 +336,10 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) static struct nfp_bar * nfp_alloc_bar(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -356,8 +361,10 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) static void nfp_disable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -403,12 +410,13 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint64_t address, size_t size) { - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); - struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + int pp; + int ret = 0; + uint32_t token = NFP_CPP_ID_TOKEN_of(dest); uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); - uint32_t token = NFP_CPP_ID_TOKEN_of(dest); - int pp, ret = 0; + struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -493,14 +501,14 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + size_t n; + int width; + bool is_64; + uint32_t *wrptr32 = kernel_vaddr; uint64_t *wrptr64 = kernel_vaddr; - const volatile uint64_t *rdptr64; struct nfp6000_area_priv *priv; - uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; - int width; - size_t n; - bool is_64; + const volatile uint64_t *rdptr64; priv = nfp_cpp_area_priv(area); rdptr64 = (uint64_t *)(priv->iomem + offset); @@ -563,14 +571,14 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { - const uint64_t *rdptr64 = kernel_vaddr; - uint64_t *wrptr64; - const uint32_t *rdptr32 = kernel_vaddr; - struct nfp6000_area_priv *priv; - uint32_t *wrptr32; - int width; size_t n; + int width; bool is_64; + uint32_t *wrptr32; + uint64_t *wrptr64; + struct nfp6000_area_priv *priv; + const uint32_t *rdptr32 = kernel_vaddr; + const uint64_t *rdptr64 = kernel_vaddr; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); @@ -693,10 +701,10 @@ static int nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) { + off_t pos; uint16_t tmp; uint8_t serial[6]; int serial_len = 6; - off_t pos; pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); if (pos <= 0) { @@ -741,8 +749,8 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - uint64_t tmp; int i = 0; + uint64_t tmp; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7e7c36eda3..2e5a4e7349 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -172,9 +172,9 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint64_t address, uint32_t size) { + int err; struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; - int err; if (cpp == NULL) return NULL; @@ -396,8 +396,8 @@ static uint32_t nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) { - uint32_t xpb; int island; + uint32_t xpb; xpb = NFP_CPP_ID(14, NFP_CPP_ACTION_RW, 0); @@ -569,9 +569,9 @@ static struct nfp_cpp * nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) { - const struct nfp_cpp_operations *ops; - struct nfp_cpp *cpp; int err; + struct nfp_cpp *cpp; + const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); @@ -657,8 +657,8 @@ nfp_cpp_read(struct nfp_cpp *cpp, void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { @@ -687,8 +687,8 @@ nfp_cpp_write(struct nfp_cpp *cpp, const void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) @@ -708,8 +708,8 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { - uint32_t reg; int err; + uint32_t reg; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, ®); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index ea4c7d6a9e..819761eda0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -36,7 +36,9 @@ static int nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { - const char *key, *val, *end = hwinfo->data + size; + const char *key; + const char *val; + const char *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { @@ -58,7 +60,9 @@ static int nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) { - uint32_t size, new_crc, *crc; + uint32_t *crc; + uint32_t size; + uint32_t new_crc; size = db->size; if (size > len) { @@ -82,12 +86,12 @@ static struct nfp_hwinfo * nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) { - struct nfp_hwinfo *header; - void *res; - uint64_t cpp_addr; - uint32_t cpp_id; int err; + void *res; uint8_t *db; + uint32_t cpp_id; + uint64_t cpp_addr; + struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); if (res) { @@ -135,13 +139,12 @@ static struct nfp_hwinfo * nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) { + int count = 0; struct timespec wait; struct nfp_hwinfo *db; - int count; wait.tv_sec = 0; wait.tv_nsec = 10000000; - count = 0; for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -159,9 +162,9 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo * nfp_hwinfo_read(struct nfp_cpp *cpp) { - struct nfp_hwinfo *db; - size_t hwdb_size = 0; int err; + size_t hwdb_size = 0; + struct nfp_hwinfo *db; db = nfp_hwinfo_fetch(cpp, &hwdb_size); if (db == NULL) @@ -186,7 +189,9 @@ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) { - const char *key, *val, *end; + const char *key; + const char *val; + const char *end; if (hwinfo == NULL || lookup == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0071d3fc37..1e601313b4 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -68,10 +68,10 @@ static int nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) { - struct nfp_nffw_info *nffw_info; - uint32_t cpp_id; - uint64_t addr; int err; + uint64_t addr; + uint32_t cpp_id; + struct nfp_nffw_info *nffw_info; nffw_info = nfp_nffw_info_open(cpp); if (nffw_info == NULL) @@ -100,8 +100,8 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) { - struct nfp_mip *mip; int err; + struct nfp_mip *mip; mip = malloc(sizeof(*mip)); if (mip == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index edc8137304..5be437b354 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -79,9 +79,9 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { + int err; uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - int err; err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -122,11 +122,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { - uint32_t model = nfp_cpp_model(cpp); - struct nfp_cpp_mutex *mutex; - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ int err; uint32_t tmp; + struct nfp_cpp_mutex *mutex; + uint32_t model = nfp_cpp_model(cpp); + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -242,12 +242,13 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) { - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + int err; + uint32_t key; + uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t key, value; uint16_t interface = nfp_cpp_interface(cpp); - int err; + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -296,12 +297,14 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) { + int err; + uint32_t key; + uint32_t tmp; + uint32_t value; + struct nfp_cpp *cpp = mutex->cpp; uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ - uint32_t key, value, tmp; - struct nfp_cpp *cpp = mutex->cpp; - int err; if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 2412dc0e00..9123fc742a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,9 +68,11 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - uint32_t mode, addr40; - uint32_t xpbaddr, imbcppat; int err; + uint32_t mode; + uint32_t addr40; + uint32_t xpbaddr; + uint32_t imbcppat; /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; @@ -118,10 +120,10 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) { - struct nfp_nffw_info_data *fwinf; - struct nfp_nffw_info *state; - uint32_t info_ver; int err; + uint32_t info_ver; + struct nfp_nffw_info *state; + struct nfp_nffw_info_data *fwinf; state = malloc(sizeof(*state)); if (state == NULL) @@ -183,8 +185,9 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { + uint32_t i; + uint32_t cnt; struct nffw_fwinfo *fwinfo; - uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index dfe396c8ac..4861772a98 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -72,10 +72,11 @@ nfp_nsp_print_extended_error(uint32_t ret_val) static int nfp_nsp_check(struct nfp_nsp *state) { - struct nfp_cpp *cpp = state->cpp; - uint64_t nsp_status, reg; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t nsp_status; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_status = nfp_resource_address(state->res) + NSP_STATUS; @@ -113,9 +114,9 @@ nfp_nsp_check(struct nfp_nsp *state) struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) { - struct nfp_resource *res; - struct nfp_nsp *state; int err; + struct nfp_nsp *state; + struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); if (res == NULL) @@ -170,13 +171,12 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t mask, uint64_t val) { - struct timespec wait; - uint32_t count; int err; + uint32_t count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -217,10 +217,15 @@ nfp_nsp_command(struct nfp_nsp *state, uint32_t buff_cpp, uint64_t buff_addr) { - uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; - struct nfp_cpp *cpp = state->cpp; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t ret_val; + uint64_t nsp_base; + uint64_t nsp_buffer; + uint64_t nsp_status; + uint64_t nsp_command; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_base = nfp_resource_address(state->res); @@ -296,11 +301,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, void *out_buf, unsigned int out_size) { - struct nfp_cpp *cpp = nsp->cpp; + int err; + int ret; + uint64_t reg; size_t max_size; - uint64_t reg, cpp_buf; - int ret, err; uint32_t cpp_id; + uint64_t cpp_buf; + struct nfp_cpp *cpp = nsp->cpp; if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", @@ -360,13 +367,12 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, int nfp_nsp_wait(struct nfp_nsp *state) { - struct timespec wait; - uint32_t count; int err; + int count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 31677b66e6..3081e22dad 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -26,9 +26,9 @@ struct nsp_identify { struct nfp_nsp_identify * __nfp_nsp_identify(struct nfp_nsp *nsp) { - struct nfp_nsp_identify *nspi = NULL; - struct nsp_identify *ni; int ret; + struct nsp_identify *ni; + struct nfp_nsp_identify *nspi = NULL; if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; @@ -77,9 +77,9 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val) { - struct nfp_sensors s; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + struct nfp_sensors s; nsp = nfp_nsp_open(cpp); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index bc155b44d8..9b7c8aa7f8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -150,9 +150,10 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, uint32_t index, struct nfp_eth_table_port *dst) { - uint32_t rate; uint32_t fec; - uint64_t port, state; + uint64_t port; + uint32_t rate; + uint64_t state; port = rte_le_to_cpu_64(src->port); state = rte_le_to_cpu_64(src->state); @@ -200,7 +201,8 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - uint32_t i, j; + uint32_t i; + uint32_t j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -242,12 +244,13 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) static struct nfp_eth_table * __nfp_eth_read_ports(struct nfp_nsp *nsp) { - union eth_table_entry *entries; - struct nfp_eth_table *table; - uint32_t table_sz; + int ret; uint32_t i; uint32_t j; - int ret, cnt = 0; + int cnt = 0; + uint32_t table_sz; + struct nfp_eth_table *table; + union eth_table_entry *entries; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -321,8 +324,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) { - struct nfp_eth_table *ret; struct nfp_nsp *nsp; + struct nfp_eth_table *ret; nsp = nfp_nsp_open(cpp); if (nsp == NULL) @@ -338,9 +341,9 @@ struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + union eth_table_entry *entries; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -401,8 +404,8 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) int nfp_eth_config_commit_end(struct nfp_nsp *nsp) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); int ret = 1; + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); if (nfp_nsp_config_modified(nsp)) { ret = nfp_nsp_write_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); @@ -433,9 +436,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -475,9 +478,9 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -516,9 +519,9 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, uint32_t val, const uint64_t ctrl_bit) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; + uint32_t idx = nfp_nsp_config_idx(nsp); + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); /* * Note: set features were added in ABI 0.14 but the error @@ -604,8 +607,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode) { - struct nfp_nsp *nsp; int err; + struct nfp_nsp *nsp; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 9dd4832779..fa92f2762e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -67,10 +67,12 @@ static int nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) { - char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; + int ret; + uint32_t i; + uint32_t key; + uint32_t cpp_id; struct nfp_resource_entry entry; - uint32_t cpp_id, key; - int ret, i; + char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; cpp_id = NFP_CPP_ID(NFP_RESOURCE_TBL_TARGET, 3, 0); /* Atomic read */ @@ -152,11 +154,11 @@ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) { - struct nfp_cpp_mutex *dev_mutex; - struct nfp_resource *res; int err; + uint16_t count = 0; struct timespec wait; - uint16_t count; + struct nfp_resource *res; + struct nfp_cpp_mutex *dev_mutex; res = malloc(sizeof(*res)); if (res == NULL) @@ -175,7 +177,6 @@ nfp_resource_acquire(struct nfp_cpp *cpp, wait.tv_sec = 0; wait.tv_nsec = 1000000; - count = 0; for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 243d3c9ce5..a34278beca 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -85,8 +85,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, struct nfp_rtsym_table * nfp_rtsym_table_read(struct nfp_cpp *cpp) { - struct nfp_rtsym_table *rtbl; struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; mip = nfp_mip_open(cpp); rtbl = __nfp_rtsym_table_read(cpp, mip); @@ -99,13 +99,18 @@ struct nfp_rtsym_table * __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) { - uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; - struct nfp_rtsym_entry *rtsymtab; + int n; + int err; + uint32_t size; + uint32_t strtab_addr; + uint32_t symtab_addr; + uint32_t strtab_size; + uint32_t symtab_size; struct nfp_rtsym_table *cache; + struct nfp_rtsym_entry *rtsymtab; const uint32_t dram = NFP_CPP_ID(NFP_CPP_TARGET_MU, NFP_CPP_ACTION_RW, 0) | NFP_ISL_EMEM0; - int err, n, size; if (mip == NULL) return NULL; @@ -341,10 +346,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) { - const struct nfp_rtsym *sym; - uint32_t val32; - uint64_t val; int err; + uint64_t val; + uint32_t val32; + const struct nfp_rtsym *sym; sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 06/26] net/nfp: adjust the log statement 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (4 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 05/26] net/nfp: standard the local variable coding style Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 07/26] net/nfp: standard the comment style Chaoyong He ` (22 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Add log statement to the important control logic, which means more strict check of the return value of function call. Also remove some verbose info log statement. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 37 ++++++---------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 20 +++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 28 ++++++++-------- drivers/net/nfp/nfpcore/nfp_mip.c | 7 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 5 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 ++++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 25 +++++++++++---- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++--- drivers/net/nfp/nfpcore/nfp_resource.c | 17 +++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 14 +++----- 10 files changed, 92 insertions(+), 80 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 78beee07ef..bdf4a658f5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -174,18 +174,10 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } - offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + offset &= mask; bitsize = 40 - 16; } else { @@ -198,30 +190,16 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); - bitsize = 40 - 21; } - if (bar->bitsize < bitsize) { - PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + if (bar->bitsize < bitsize) return -EINVAL; - } newcfg |= offset >> bitsize; @@ -254,7 +232,6 @@ nfp_bar_write(struct nfp_pcie_user *nfp, *(uint32_t *)(bar->csr) = newcfg; bar->barcfg = newcfg; - PMD_DRV_LOG(DEBUG, "BAR%d: updated to 0x%08x", bar->index, newcfg); return 0; } @@ -795,7 +772,11 @@ nfp6000_init(struct nfp_cpp *cpp, desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; - nfp_enable_bars(desc); + ret = nfp_enable_bars(desc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Enable bars failed"); + return -1; + } nfp_cpp_priv_set(cpp, desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 2e5a4e7349..e2af888a28 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -200,6 +200,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, err = cpp->op->area_init(area, dest, address, size); if (err < 0) { + PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } @@ -243,10 +244,13 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc(cpp, destination, address, size); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate CPP area"); return NULL; + } if (nfp_cpp_area_acquire(area) != 0) { + PMD_DRV_LOG(ERR, "Failed to acquire CPP area"); nfp_cpp_area_free(area); return NULL; } @@ -294,8 +298,10 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; + } } return 0; @@ -662,7 +668,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { - PMD_DRV_LOG(ERR, "Area allocation/acquire failed"); + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } @@ -691,8 +697,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; + } err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); @@ -746,8 +754,10 @@ nfp_cpp_map_area(struct nfp_cpp *cpp, uint8_t *res; *area = nfp_cpp_area_alloc_acquire(cpp, cpp_id, addr, size); - if (*area == NULL) + if (*area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for map"); goto err_eio; + } res = nfp_cpp_area_iomem(*area); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 819761eda0..b658b5e900 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -74,7 +74,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, new_crc = nfp_crc32_posix((char *)db, size); crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { - PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", + PMD_DRV_LOG(ERR, "CRC mismatch, calculated %#x, expected %#x", new_crc, *crc); return -EINVAL; } @@ -94,34 +94,36 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); - if (res) { - cpp_id = nfp_resource_cpp_id(res); - cpp_addr = nfp_resource_address(res); - *cpp_size = nfp_resource_size(res); + if (res == NULL) { + PMD_DRV_LOG(ERR, "HWInfo - acquire resource failed"); + return NULL; + } - nfp_resource_release(res); + cpp_id = nfp_resource_cpp_id(res); + cpp_addr = nfp_resource_address(res); + *cpp_size = nfp_resource_size(res); - if (*cpp_size < HWINFO_SIZE_MIN) - return NULL; - } else { + nfp_resource_release(res); + + if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - } db = malloc(*cpp_size + 1); if (db == NULL) return NULL; err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size); - if (err != (int)*cpp_size) + if (err != (int)*cpp_size) { + PMD_DRV_LOG(ERR, "HWInfo - CPP read error %d", err); goto exit_free; + } header = (void *)db; - PMD_DRV_LOG(DEBUG, "NFP HWINFO header: %#08x", *(uint32_t *)header); if (nfp_hwinfo_is_updating(header)) goto exit_free; if (header->version != NFP_HWINFO_VERSION_2) { - PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", + PMD_DRV_LOG(ERR, "Unknown HWInfo version: %#08x", header->version); goto exit_free; } diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 1e601313b4..086e82db70 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -46,16 +46,16 @@ nfp_mip_try_read(struct nfp_cpp *cpp, ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip)); if (ret != sizeof(*mip)) { - PMD_DRV_LOG(ERR, "Failed to read MIP data (%d, %zu)", ret, sizeof(*mip)); + PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } if (mip->signature != NFP_MIP_SIGNATURE) { - PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", + PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { - PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", + PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -109,6 +109,7 @@ nfp_mip_open(struct nfp_cpp *cpp) err = nfp_mip_read_resource(cpp, mip); if (err != 0) { + PMD_DRV_LOG(ERR, "Failed to read MIP resource"); free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 5be437b354..82919d8270 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -221,10 +221,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] " - "target:%d key:%08x] addr:%" PRIx64, - mutex->usage, mutex->depth, mutex->target, - mutex->key, mutex->address); + PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 9123fc742a..b5a354137d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,6 +3,7 @@ * All rights reserved. */ +#include "../nfp_logs.h" #include "nfp_cpp.h" #include "nfp_nffw.h" #include "nfp_mip.h" @@ -132,8 +133,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) memset(state, 0, sizeof(*state)); state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); - if (state->res == NULL) + if (state->res == NULL) { + PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); goto err_free; + } fwinf = &state->fwinf; @@ -143,8 +146,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), nfp_resource_address(state->res), fwinf, sizeof(*fwinf)); - if (err < (int)sizeof(*fwinf)) + if (err < (int)sizeof(*fwinf)) { + PMD_DRV_LOG(ERR, "NFFW - CPP read error %d", err); goto err_release; + } if (nffw_res_flg_init_get(fwinf) == 0) goto err_release; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4861772a98..ff19446173 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -82,8 +82,10 @@ nfp_nsp_check(struct nfp_nsp *state) nsp_status = nfp_resource_address(state->res) + NSP_STATUS; err = nfp_cpp_readq(cpp, nsp_cpp, nsp_status, ®); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed %d", err); return err; + } if (FIELD_GET(NSP_STATUS_MAGIC, reg) != NSP_MAGIC) { PMD_DRV_LOG(ERR, "Cannot detect NFP Service Processor"); @@ -119,8 +121,10 @@ nfp_nsp_open(struct nfp_cpp *cpp) struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); - if (res == NULL) + if (res == NULL) { + PMD_DRV_LOG(ERR, "NSP - resource acquire failed"); return NULL; + } state = malloc(sizeof(*state)); if (state == NULL) { @@ -133,6 +137,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) err = nfp_nsp_check(state); if (err != 0) { + PMD_DRV_LOG(ERR, "NSP - check failed"); nfp_nsp_close(state); return NULL; } @@ -180,8 +185,10 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed"); return err; + } if ((*reg & mask) == val) return 0; @@ -234,8 +241,10 @@ nfp_nsp_command(struct nfp_nsp *state, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "Check NSP command failed"); return err; + } if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { @@ -261,7 +270,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", err, code); return err; } @@ -270,7 +279,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", err, code); return err; } @@ -352,8 +361,10 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, } ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); - if (ret < 0) + if (ret < 0) { + PMD_DRV_LOG(ERR, "NSP command failed"); return ret; + } if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9b7c8aa7f8..74daa92aed 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -260,7 +260,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } @@ -279,7 +279,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * above. */ if (ret != 0 && ret != cnt) { - PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", + PMD_DRV_LOG(ERR, "Table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; } @@ -358,12 +358,12 @@ nfp_eth_config_start(struct nfp_cpp *cpp, ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } if ((entries[idx].port & NSP_ETH_PORT_LANES_MASK) == 0) { - PMD_DRV_LOG(ERR, "trying to set port state on disabled port %d", idx); + PMD_DRV_LOG(ERR, "Trying to set port state on disabled port %d", idx); goto err; } @@ -643,7 +643,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, rate = nfp_eth_speed2rate(speed); if (rate == RATE_INVALID) { - PMD_DRV_LOG(ERR, "could not find matching lane rate for speed %u", speed); + PMD_DRV_LOG(ERR, "Could not find matching lane rate for speed %u", speed); return -EINVAL; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index fa92f2762e..363f7d6198 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -118,16 +118,22 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, { int err; - if (nfp_cpp_mutex_lock(dev_mutex) != 0) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex lock failed"); return -EINVAL; + } err = nfp_cpp_resource_find(cpp, res); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP resource find failed"); goto err_unlock_dev; + } err = nfp_cpp_mutex_trylock(res->mutex); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex trylock failed"); goto err_res_mutex_free; + } nfp_cpp_mutex_unlock(dev_mutex); @@ -171,6 +177,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); free(res); return NULL; } @@ -182,8 +189,10 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err = nfp_resource_try_acquire(cpp, res, dev_mutex); if (err == 0) break; - if (err != -EBUSY) + if (err != -EBUSY) { + PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); goto err_free; + } if (count++ > 1000) { PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index a34278beca..d15a920752 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -60,8 +60,6 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->size = ((uint64_t)fw->size_hi << 32) | rte_le_to_cpu_32(fw->size_lo); - PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", - sw->name, sw->addr, sw->size, sw->target); switch (fw->target) { case SYM_TGT_LMEM: sw->target = NFP_RTSYM_TARGET_LMEM; @@ -227,7 +225,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) { switch (sym->type) { case NFP_RTSYM_TYPE_NONE: - PMD_DRV_LOG(ERR, "rtsym '%s': type NONE", sym->name); + PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ case NFP_RTSYM_TYPE_FUNCTION: @@ -235,7 +233,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_ABS: return sizeof(uint64_t); default: - PMD_DRV_LOG(ERR, "rtsym '%s': unknown type: %d", sym->name, sym->type); + PMD_DRV_LOG(ERR, "Unknown RTSYM type %u", sym->type); return 0; } } @@ -366,7 +364,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); break; default: - PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", name, sym->size); err = -EINVAL; break; @@ -396,10 +394,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, uint32_t cpp_id; const struct nfp_rtsym *sym; - PMD_DRV_LOG(DEBUG, "mapping symbol %s", name); sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { - PMD_INIT_LOG(ERR, "symbol lookup fails for %s", name); + PMD_DRV_LOG(ERR, "Symbol lookup fails for %s", name); return NULL; } @@ -418,10 +415,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, mem = nfp_cpp_map_area(rtbl->cpp, cpp_id, addr, sym->size, area); if (mem == NULL) { - PMD_INIT_LOG(ERR, "Failed to map symbol %s", name); + PMD_DRV_LOG(ERR, "Failed to map symbol %s", name); return NULL; } - PMD_DRV_LOG(DEBUG, "symbol %s with address %p", name, mem); return mem; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 07/26] net/nfp: standard the comment style 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (5 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 06/26] net/nfp: adjust the log statement Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 08/26] net/nfp: standard the blank character Chaoyong He ` (21 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Follow the DPDK coding style, use the kdoc comment style. Also move the comment of the functions to the implement file and add some comment to help understand logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 504 ++++----------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 39 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 484 ++++++++++++++++---- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 21 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 + drivers/net/nfp/nfpcore/nfp_mip.c | 43 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 69 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 49 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 6 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 53 ++- drivers/net/nfp/nfpcore/nfp_nsp.h | 108 ++--- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 170 ++++--- drivers/net/nfp/nfpcore/nfp_resource.c | 103 +++-- drivers/net/nfp/nfpcore/nfp_resource.h | 28 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 59 ++- drivers/net/nfp/nfpcore/nfp_rtsym.h | 12 +- drivers/net/nfp/nfpcore/nfp_target.c | 2 +- 17 files changed, 888 insertions(+), 864 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 139752f85a..82189e9910 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -10,9 +10,7 @@ struct nfp_cpp_mutex; -/* - * NFP CPP handle - */ +/* NFP CPP handle */ struct nfp_cpp { uint32_t model; uint32_t interface; @@ -37,9 +35,7 @@ struct nfp_cpp { int driver_lock_needed; }; -/* - * NFP CPP device area handle - */ +/* NFP CPP device area handle */ struct nfp_cpp_area { struct nfp_cpp *cpp; char *name; @@ -127,35 +123,45 @@ struct nfp_cpp_operations { #define NFP_CPP_TARGET_ID_MASK 0x1f -/* +/** * Pack target, token, and action into a CPP ID. * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id * - * @return NFP CPP ID + * @return + * NFP CPP ID */ #define NFP_CPP_ID(target, action, token) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ (((action) & 0xff) << 8)) -/* +/** * Pack target, token, action, and island into a CPP ID. - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id - * @island NFP CPP island id * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @return NFP CPP ID + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id + * @param island + * NFP CPP island id + * + * @return + * NFP CPP ID */ #define NFP_CPP_ISLAND_ID(target, action, token, island) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ @@ -163,9 +169,12 @@ struct nfp_cpp_operations { /** * Return the NFP CPP target of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP target + * @param id + * NFP CPP ID + * + * @return + * NFP CPP target */ static inline uint8_t NFP_CPP_ID_TARGET_of(uint32_t id) @@ -173,11 +182,14 @@ NFP_CPP_ID_TARGET_of(uint32_t id) return (id >> 24) & NFP_CPP_TARGET_ID_MASK; } -/* +/** * Return the NFP CPP token of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP token + * @param id + * NFP CPP ID + * + * @return + * NFP CPP token */ static inline uint8_t NFP_CPP_ID_TOKEN_of(uint32_t id) @@ -185,11 +197,14 @@ NFP_CPP_ID_TOKEN_of(uint32_t id) return (id >> 16) & 0xff; } -/* +/** * Return the NFP CPP action of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP action + * @param id + * NFP CPP ID + * + * @return + * NFP CPP action */ static inline uint8_t NFP_CPP_ID_ACTION_of(uint32_t id) @@ -197,11 +212,14 @@ NFP_CPP_ID_ACTION_of(uint32_t id) return (id >> 8) & 0xff; } -/* +/** * Return the NFP CPP island of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP island + * @param id + * NFP CPP ID + * + * @return + * NFP CPP island */ static inline uint8_t NFP_CPP_ID_ISLAND_of(uint32_t id) @@ -215,109 +233,57 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) */ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); -/* - * Set the model id - * - * @param cpp NFP CPP operations structure - * @param model Model ID - */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param interface Interface ID - */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param serial NFP serial byte array - * @param len Length of the serial byte array - */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); -/* - * Set the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); -/* - * Return the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void *nfp_cpp_priv(struct nfp_cpp *cpp); -/* - * Get the privately allocated portion of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the private area, or NULL on failure - */ void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); -/* - * NFP CPP core interface for CPP clients. - */ - -/* - * Open a NFP CPP handle to a CPP device - * - * @param[in] id 0-based ID for the CPP interface to use - * - * @return NFP CPP handle, or NULL on failure. - */ +/* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed); -/* - * Free a NFP CPP handle - * - * @param[in] cpp NFP CPP handle - */ void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/* - * NFP_CPP_MODEL_CHIP_of - retrieve the chip ID from the model ID +/** + * Retrieve the chip ID from the model ID * * The chip ID is a 16-bit BCD+A-F encoding for the chip type. * - * @param[in] model NFP CPP model id - * @return NFP CPP chip id + * @param model + * NFP CPP model id + * + * @return + * NFP CPP chip id */ #define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) -/* - * NFP_CPP_MODEL_IS_6000 - Check for the NFP6000 family of devices +/** + * Check for the NFP6000 family of devices * * NOTE: The NFP4000 series is considered as a NFP6000 series variant. * - * @param[in] model NFP CPP model id - * @return true if model is in the NFP6000 family, false otherwise. + * @param model + * NFP CPP model id + * + * @return + * true if model is in the NFP6000 family, false otherwise. */ #define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) -/* - * nfp_cpp_model - Retrieve the Model ID of the NFP - * - * @param[in] cpp NFP CPP handle - * @return NFP CPP Model ID - */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,7 +296,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); #define NFP_CPP_INTERFACE_TYPE_RPC 0x3 #define NFP_CPP_INTERFACE_TYPE_ILA 0x4 -/* +/** * Construct a 16-bit NFP Interface ID * * Interface IDs consists of 4 bits of interface type, 4 bits of unit @@ -340,422 +306,138 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * which use the MU Atomic CompareAndWrite operation - hence the limit to 16 * bits to be able to use the NFP Interface ID as a lock owner. * - * @param[in] type NFP Interface Type - * @param[in] unit Unit identifier for the interface type - * @param[in] channel Channel identifier for the interface unit - * @return Interface ID + * @param type + * NFP Interface Type + * @param unit + * Unit identifier for the interface type + * @param channel + * Channel identifier for the interface unit + * + * @return + * Interface ID */ #define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) -/* +/** * Get the interface type of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's type + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's type */ #define NFP_CPP_INTERFACE_TYPE_of(interface) (((interface) >> 12) & 0xf) -/* +/** * Get the interface unit of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's unit + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's unit */ #define NFP_CPP_INTERFACE_UNIT_of(interface) (((interface) >> 8) & 0xf) -/* +/** * Get the interface channel of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's channel + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's channel */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) -/* - * Retrieve the Interface ID of the NFP - * @param[in] cpp NFP CPP handle - * @return NFP CPP Interface ID - */ + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -/* - * Retrieve the NFP Serial Number (unique per NFP) - * @param[in] cpp NFP CPP handle - * @param[out] serial Pointer to reference the serial number array - * - * @return size of the NFP6000 serial number, in bytes - */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] name Name of owner of the area - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t cpp_id, const char *name, uint64_t address, uint32_t size); -/* - * Free an allocated NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_free(struct nfp_cpp_area *area); -/* - * Acquire the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - * - * @return 0 on success, -1 on failure. - */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area); -/* - * Release the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release(struct nfp_cpp_area *area); -/* - * Allocate, then acquire the resources needed to access the NFP CPP area handle - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Release the resources, then free the NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Read from a NFP CPP area handle into a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer to receive the data - * @param[in] length Length of the data to read - * - * @return bytes read on success, negative value on failure. - * - */ int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); -/* - * Write to a NFP CPP area handle from a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer that holds the data - * @param[in] length Length of the data to read - * - * @return bytes written on success, negative value on failure. - */ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area - * @area: CPP area handle - * - * Returns an iomem pointer for use with readl()/writel() style operations. - * - * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL - */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Get the NFP CPP handle that is the parent of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return NFP CPP handle - */ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); -/* - * Get the name passed during allocation of the NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the area's name - */ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); -/* - * Read a block of data from a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy read data to - * @param[in] length Size of the area to reserve - * - * @return bytes read on success, -1 on failure. - */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, void *kernel_vaddr, size_t length); -/* - * Write a block of data to a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy write data from - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, -1 on failure. - */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); -/* - * Read a single 32-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); -/* - * Write a single 32-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); -/* - * Read a single 64-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); -/* - * Write a single 64-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); -/* - * Write a single 32-bit value on the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); -/* - * Read a single 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Read a 32-bit word from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t *value); -/* - * Write a 32-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - * - */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t value); -/* - * Read a 64-bit work from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t *value); -/* - * Write a 64-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -/* - * Initialize a mutex location - - * The CPP target:address must point to a 64-bit aligned location, and will - * initialize 64 bits of data at the location. - * - * This creates the initial mutex state, as locked by this nfp_cpp_interface(). - * - * This function should only be called when setting up the initial lock state - * upon boot-up of the system. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id Unique 32-bit value for this mutex - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Create a mutex handle from an address controlled by a MU Atomic engine - * - * The CPP target:address must point to a 64-bit aligned location, and reserve - * 64 bits of data at the location for use by the handle. - * - * Only target/address pairs that point to entities that support the MU Atomic - * Engine's CmpAndSwap32 command are supported. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id 32-bit unique key (must match the key at this location) - * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on - * failure. - */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Free a mutex handle - does not alter the lock state - * - * @param mutex NFP CPP Mutex handle - */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); -/* - * Lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); -/* - * Unlock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); -/* - * Attempt to lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. - */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index bdf4a658f5..7e94bfb611 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -72,40 +72,25 @@ #define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ (((bar) * 8 + (slot)) * 4) -/* - * Define to enable a bit more verbose debug output. - * Set to 1 to enable a bit more verbose debug output. - */ struct nfp_pcie_user; struct nfp6000_area_priv; -/* - * struct nfp_bar - describes BAR configuration and usage - * @nfp: backlink to owner - * @barcfg: cached contents of BAR config CSR - * @base: the BAR's base CPP offset - * @mask: mask for the BAR aperture (read only) - * @bitsize: bitsize of BAR aperture (read only) - * @index: index of the BAR - * @lock: lock to specify if bar is in use - * @refcnt: number of current users - * @iomem: mapped IO memory - */ +/* Describes BAR configuration and usage */ #define NFP_BAR_MIN 1 #define NFP_BAR_MID 5 #define NFP_BAR_MAX 7 struct nfp_bar { - struct nfp_pcie_user *nfp; - uint32_t barcfg; - uint64_t base; /* CPP address base */ - uint64_t mask; /* Bit mask of the bar */ - uint32_t bitsize; /* Bit size of the bar */ - uint32_t index; - int lock; + struct nfp_pcie_user *nfp; /**< Backlink to owner */ + uint32_t barcfg; /**< BAR config CSR */ + uint64_t base; /**< Base CPP offset */ + uint64_t mask; /**< Mask of the BAR aperture (read only) */ + uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ + uint32_t index; /**< Index of the BAR */ + int lock; /**< If the BAR has been locked */ char *csr; - char *iomem; + char *iomem; /**< mapped IO memory */ }; #define BUSDEV_SZ 13 @@ -360,9 +345,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* - * Generic CPP bus access interface. - */ +/* Generic CPP bus access interface. */ struct nfp6000_area_priv { struct nfp_bar *bar; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index e2af888a28..0e8372576e 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -26,6 +26,15 @@ #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/** + * Set the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) @@ -33,12 +42,29 @@ nfp_cpp_priv_set(struct nfp_cpp *cpp, cpp->priv = priv; } +/** + * Return the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void * nfp_cpp_priv(struct nfp_cpp *cpp) { return cpp->priv; } +/** + * Set the model id + * + * @param cpp + * NFP CPP operations structure + * @param model + * Model ID + */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) @@ -46,6 +72,15 @@ nfp_cpp_model_set(struct nfp_cpp *cpp, cpp->model = model; } +/** + * Retrieve the Model ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Model ID + */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp) { @@ -63,6 +98,14 @@ nfp_cpp_model(struct nfp_cpp *cpp) return model; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param interface + * Interface ID + */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) @@ -70,6 +113,17 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, cpp->interface = interface; } +/** + * Retrieve the Serial ID of the NFP + * + * @param cpp + * NFP CPP handle + * @param serial + * Pointer to NFP serial number + * + * @return + * Length of NFP serial number + */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) @@ -78,6 +132,16 @@ nfp_cpp_serial(struct nfp_cpp *cpp, return cpp->serial_len; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param serial + * NFP serial byte array + * @param serial_len + * Length of the serial byte array + */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, @@ -96,6 +160,15 @@ nfp_cpp_serial_set(struct nfp_cpp *cpp, return 0; } +/** + * Retrieve the Interface ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Interface ID + */ uint16_t nfp_cpp_interface(struct nfp_cpp *cpp) { @@ -105,18 +178,45 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Get the privately allocated portion of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the private area, or NULL on failure + */ void * nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area) { return &cpp_area[1]; } +/** + * Get the NFP CPP handle that is the pci_dev of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * NFP CPP handle + */ struct nfp_cpp * nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area) { return cpp_area->cpp; } +/** + * Get the name passed during allocation of the NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the area's name + */ const char * nfp_cpp_area_name(struct nfp_cpp_area *cpp_area) { @@ -153,15 +253,24 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) return cpp->mu_locality_lsb; } -/* - * nfp_cpp_area_alloc - allocate a new CPP area - * @cpp: CPP handle - * @dest: CPP id - * @address: start address on CPP target - * @size: size of area in bytes +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. * - * Allocate and initialize a CPP area structure. The area must later - * be locked down with an 'acquire' before it can be safely accessed. + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param name + * Name of region + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL * * NOTE: @address and @size must be 32-bit aligned values. */ @@ -211,6 +320,25 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, return area; } +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. + * + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * + * NOTE: @address and @size must be 32-bit aligned values. + */ struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, @@ -220,17 +348,22 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, 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 - * @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. * + * @param cpp + * CPP device handle + * @param destination + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * * NOTE: @address and @size must be 32-bit aligned values. * * NOTE: The area must also be 'released' when the structure is freed. @@ -258,11 +391,11 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, return area; } -/* - * nfp_cpp_area_free - free up the CPP area - * area: CPP area handle - * +/** * Frees up memory resources held by the CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_free(struct nfp_cpp_area *area) @@ -272,11 +405,11 @@ nfp_cpp_area_free(struct nfp_cpp_area *area) free(area); } -/* - * nfp_cpp_area_release_free - release CPP area and free it - * area: CPP area handle +/** + * Releases CPP area and frees up memory resources held by it. * - * Releases CPP area and frees up memory resources held by the it. + * @param area + * CPP area handle */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area) @@ -285,12 +418,15 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) nfp_cpp_area_free(area); } -/* - * nfp_cpp_area_acquire - lock down a CPP area for access - * @area: CPP area handle +/** + * Locks down the CPP area for a potential long term activity. + * Area must always be locked down before being accessed. * - * Locks down the CPP area for a potential long term activity. Area - * must always be locked down before being accessed. + * @param area + * CPP area handle + * + * @return + * 0 on success, -1 on failure. */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area) @@ -307,11 +443,11 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) return 0; } -/* - * nfp_cpp_area_release - release a locked down CPP area - * @area: CPP area handle - * +/** * Releases a previously locked down CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_release(struct nfp_cpp_area *area) @@ -320,16 +456,16 @@ nfp_cpp_area_release(struct nfp_cpp_area *area) area->cpp->op->area_release(area); } -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area +/** + * Returns an iomem pointer for use with readl()/writel() style operations. * - * @area: CPP area handle + * @param area + * CPP area handle * - * Returns an iomem pointer for use with readl()/writel() style operations. + * @return + * Pointer to the area, or NULL * * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL */ void * nfp_cpp_area_iomem(struct nfp_cpp_area *area) @@ -342,18 +478,22 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) return iomem; } -/* - * nfp_cpp_area_read - read data from CPP area +/** + * Read data from indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to put data into - * @length: number of bytes to read + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Read data from indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -368,18 +508,22 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, return area->cpp->op->area_read(area, kernel_vaddr, offset, length); } -/* - * nfp_cpp_area_write - write data to CPP area +/** + * Write data to indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to read data from - * @length: number of bytes to write + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Write data to indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -436,6 +580,19 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, return xpb; } +/** + * Read a uint32_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, @@ -450,6 +607,19 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, @@ -462,6 +632,19 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, @@ -476,6 +659,19 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, @@ -489,6 +685,21 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint32_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -504,6 +715,21 @@ nfp_cpp_readl(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -518,6 +744,21 @@ nfp_cpp_writel(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -533,6 +774,21 @@ nfp_cpp_readq(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -547,6 +803,19 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Write a uint32_t word to a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -559,6 +828,19 @@ nfp_xpb_writel(struct nfp_cpp *cpp, return nfp_cpp_writel(cpp, cpp_dest, xpb_addr, value); } +/** + * Read a uint32_t value from a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -625,9 +907,11 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return cpp; } -/* - * nfp_cpp_free - free the CPP handle - * @cpp: CPP handle +/** + * Free the CPP handle + * + * @param cpp + * CPP handle */ void nfp_cpp_free(struct nfp_cpp *cpp) @@ -641,6 +925,19 @@ nfp_cpp_free(struct nfp_cpp *cpp) free(cpp); } +/** + * Create a NFP CPP handle from device + * + * @param dev + * PCI device + * @param driver_lock_needed + * Driver lock flag + * + * @return + * NFP CPP handle on success, NULL on failure + * + * NOTE: On failure, cpp_ops->free will be called! + */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) @@ -648,13 +945,22 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * nfp_cpp_read - read from CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer for result - * @length: number of bytes to read +/** + * Read from CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer for result + * @param length + * Number of bytes to read + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_read(struct nfp_cpp *cpp, @@ -678,13 +984,22 @@ nfp_cpp_read(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_write - write to CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer to read from - * @length: number of bytes to write +/** + * Write to CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer to read from + * @param length + * Number of bytes to write + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_write(struct nfp_cpp *cpp, @@ -731,18 +1046,23 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return 0; } -/* - * nfp_cpp_map_area() - Helper function to map an area - * @cpp: NFP CPP handler - * @cpp_id: CPP ID - * @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). * - * Map an area of IOMEM access. To undo the effect of this function call - * @nfp_cpp_area_release_free(*area). + * @param cpp + * NFP CPP handler + * @param cpp_id + * CPP id + * @param addr + * CPP address + * @param size + * Size of the area + * @param area + * Area handle (output) * - * Return: Pointer to memory mapped area or NULL + * @return + * Pointer to memory mapped area or NULL */ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index b658b5e900..f5579ab60f 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -3,7 +3,8 @@ * All rights reserved. */ -/* Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM +/* + * Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM * after chip reset. * * Examples of the fields: @@ -146,7 +147,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *db; wait.tv_sec = 0; - wait.tv_nsec = 10000000; + wait.tv_nsec = 10000000; /* 10ms */ for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -154,7 +155,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, return db; nanosleep(&wait, NULL); - if (count++ > 200) { + if (count++ > 200) { /* 10ms * 200 = 2s */ PMD_DRV_LOG(ERR, "NFP access error"); return NULL; } @@ -180,12 +181,16 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return db; } -/* - * nfp_hwinfo_lookup() - Find a value in the HWInfo table by name - * @hwinfo: NFP HWinfo table - * @lookup: HWInfo name to search for +/** + * Find a value in the HWInfo table by name + * + * @param hwinfo + * NFP HWInfo table + * @param lookup + * HWInfo name to search for * - * Return: Value of the HWInfo name, or NULL + * @return + * Value of the HWInfo name, or NULL */ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index a3da7512db..424db8035d 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -59,6 +59,8 @@ * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' * * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. */ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 086e82db70..0892c99e96 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -87,15 +87,16 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, return err; } -/* - * nfp_mip_open() - Get device MIP structure - * @cpp: NFP CPP Handle - * - * Copy MIP structure from NFP device and return it. The returned +/** + * Copy MIP structure from NFP device and return it. The returned * structure is handled internally by the library and should be - * freed by calling nfp_mip_close(). + * freed by calling @nfp_mip_close(). + * + * @param cpp + * NFP CPP Handle * - * Return: pointer to mip, NULL on failure. + * @return + * Pointer to MIP, NULL on failure. */ struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) @@ -131,11 +132,15 @@ nfp_mip_name(const struct nfp_mip *mip) return mip->name; } -/* - * nfp_mip_symtab() - Get the address and size of the MIP symbol table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol table - * @size: Location for size of MIP symbol table +/** + * Get the address and size of the MIP symbol table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol table + * @param size + * Location for size of MIP symbol table */ void nfp_mip_symtab(const struct nfp_mip *mip, @@ -146,11 +151,15 @@ nfp_mip_symtab(const struct nfp_mip *mip, *size = rte_le_to_cpu_32(mip->symtab_size); } -/* - * nfp_mip_strtab() - Get the address and size of the MIP symbol name table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol name table - * @size: Location for size of MIP symbol name table +/** + * Get the address and size of the MIP symbol name table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol name table + * @param size + * Location for size of MIP symbol name table */ void nfp_mip_strtab(const struct nfp_mip *mip, diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82919d8270..404d4fa938 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -53,7 +53,7 @@ _nfp_cpp_mutex_validate(uint32_t model, return 0; } -/* +/** * Initialize a mutex location * * The CPP target:address must point to a 64-bit aligned location, and @@ -65,13 +65,17 @@ _nfp_cpp_mutex_validate(uint32_t model, * This function should only be called when setting up * the initial lock state upon boot-up of the system. * - * @param mutex NFP CPP Mutex handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key Unique 32-bit value for this mutex + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * Unique 32-bit value for this mutex * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, @@ -99,7 +103,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, return 0; } -/* +/** * Create a mutex handle from an address controlled by a MU Atomic engine * * The CPP target:address must point to a 64-bit aligned location, and @@ -108,13 +112,17 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, * Only target/address pairs that point to entities that support the * MU Atomic Engine are supported. * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key 32-bit unique key (must match the key at this location) + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * 32-bit unique key (must match the key at this location) * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. + * @return + * A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, @@ -178,10 +186,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -/* +/** * Free a mutex handle - does not alter the lock state * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) @@ -203,12 +212,14 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) free(mutex); } -/* +/** * Lock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure. */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) @@ -229,12 +240,14 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return 0; } -/* +/** * Unlock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) @@ -280,16 +293,18 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return err; } -/* +/** * Attempt to lock a mutex handle, using the NFP MU Atomic Engine * * Valid lock states: - * * 0x....0000 - Unlocked * 0x....000f - Locked * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. + * @param mutex + * NFP CPP Mutex handle + * + * @return + * 0 if the lock succeeded, negative value on failure. */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) @@ -352,7 +367,7 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) * If there was another contending for this lock, then * the lock state would be 0x....000f * - * Write our owner ID into the lock + * Write our owner ID into the lock. * While not strictly necessary, this helps with * debug and bookkeeping. */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b5a354137d..5f004e3b21 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -52,7 +52,7 @@ nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 8) | mip_offset_lo */ +/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { @@ -112,11 +112,14 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, } } -/* - * nfp_nffw_info_open() - Acquire the lock on the NFFW table - * @cpp: NFP CPP handle +/** + * Acquire the lock on the NFFW table + * + * @param cpp + * NFP CPP handle * - * Return: nffw info pointer, or NULL on failure + * @return + * NFFW info pointer, or NULL on failure */ struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) @@ -168,11 +171,11 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) return NULL; } -/* - * nfp_nffw_info_close() - Release the lock on the NFFW table - * @state: NFP FW info state +/** + * Release the lock on the NFFW table * - * Return: void + * @param state + * NFFW info pointer */ void nfp_nffw_info_close(struct nfp_nffw_info *state) @@ -181,11 +184,14 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) free(state); } -/* - * nfp_nffw_info_fwid_first() - Return the first firmware ID in the NFFW - * @state: NFP FW info state +/** + * Return the first firmware ID in the NFFW * - * Return: First NFFW firmware info, NULL on failure + * @param state + * NFFW info pointer + * + * @return: + * First NFFW firmware info, NULL on failure */ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) @@ -205,13 +211,18 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; } -/* - * nfp_nffw_info_mip_first() - Retrieve the location of the first FW's MIP - * @state: NFP FW info state - * @cpp_id: Pointer to the CPP ID of the MIP - * @off: Pointer to the CPP Address of the MIP +/** + * Retrieve the location of the first FW's MIP + * + * @param state + * NFFW info pointer + * @param cpp_id + * Pointer to the CPP ID of the MIP + * @param off + * Pointer to the CPP Address of the MIP * - * Return: 0, or -ERRNO + * @return + * 0, or -ERRNO */ int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 46ac8a8d07..e032b6cce7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,7 +8,8 @@ #include "nfp_cpp.h" -/* Init-CSR owner IDs for firmware map to firmware IDs which start at 4. +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. * Lower IDs are reserved for target and loader IDs. */ #define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ @@ -16,7 +17,7 @@ #define NFFW_FWID_ALL 255 -/** +/* * NFFW_INFO_VERSION history: * 0: This was never actually used (before versioning), but it refers to * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later @@ -35,6 +36,7 @@ #define NFFW_MEINFO_CNT_V2 200 #define NFFW_FWINFO_CNT_V2 200 +/* nfp.nffw meinfo */ struct nffw_meinfo { uint32_t ctxmask__fwid__meid; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index ff19446173..a96ccea38b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -109,9 +109,11 @@ nfp_nsp_check(struct nfp_nsp *state) return 0; } -/* - * nfp_nsp_open() - Prepare for communication and lock the NSP resource. - * @cpp: NFP CPP Handle +/** + * Prepare for communication and lock the NSP resource. + * + * @param cpp + * NFP CPP Handle */ struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) @@ -145,9 +147,11 @@ nfp_nsp_open(struct nfp_cpp *cpp) return state; } -/* - * nfp_nsp_close() - Clean up and unlock the NSP resource. - * @state: NFP SP state +/** + * Clean up and unlock the NSP resource. + * + * @param state + * NFP SP state */ void nfp_nsp_close(struct nfp_nsp *state) @@ -181,7 +185,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -194,28 +198,27 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, return 0; nanosleep(&wait, 0); - if (count++ > 1000) + if (count++ > 1000) /* 25ms * 1000 = 25s */ return -ETIMEDOUT; } } -/* - * nfp_nsp_command() - Execute a command on the NFP Service Processor - * @state: NFP SP state - * @code: NFP SP Command Code - * @option: NFP SP Command Argument - * @buff_cpp: NFP SP Buffer CPP Address info - * @buff_addr: NFP SP Buffer Host address - * - * Return: 0 for success with no result +/** + * Execute a command on the NFP Service Processor * - * positive value for NSP completion with a result code + * @param state + * NFP SP state + * @param arg + * NFP command argument structure * - * -EAGAIN if the NSP is not yet present - * -ENODEV if the NSP is not a supported model - * -EBUSY if the NSP is stuck - * -EINTR if interrupted while waiting for completion - * -ETIMEDOUT if the NSP took longer than 30 seconds to complete + * @return + * - 0 for success with no result + * - Positive value for NSP completion with a result code + * - -EAGAIN if the NSP is not yet present + * - -ENODEV if the NSP is not a supported model + * - -EBUSY if the NSP is stuck + * - -EINTR if interrupted while waiting for completion + * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int nfp_nsp_command(struct nfp_nsp *state, @@ -383,7 +386,7 @@ nfp_nsp_wait(struct nfp_nsp *state) struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); @@ -392,7 +395,7 @@ nfp_nsp_wait(struct nfp_nsp *state) nanosleep(&wait, 0); - if (count++ > 1000) { + if (count++ > 1000) { /* 25ms * 1000 = 25s */ err = -ETIMEDOUT; break; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index edb56e26ca..0fcb21e99c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -158,72 +158,45 @@ enum nfp_eth_fec { #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) -/** - * struct nfp_eth_table - ETH table information - * @count: number of table entries - * @max_index: max of @index fields of all @ports - * @ports: table of ports - * - * @eth_index: port index according to legacy ethX numbering - * @index: chip-wide first channel index - * @nbi: NBI index - * @base: first channel index (within NBI) - * @lanes: number of channels - * @speed: interface speed (in Mbps) - * @interface: interface (module) plugged in - * @media: media type of the @interface - * @fec: forward error correction mode - * @aneg: auto negotiation mode - * @mac_addr: interface MAC address - * @label_port: port id - * @label_subport: id of interface within port (for split ports) - * @enabled: is enabled? - * @tx_enabled: is TX enabled? - * @rx_enabled: is RX enabled? - * @override_changed: is media reconfig pending? - * - * @port_type: one of %PORT_* defines for ethtool - * @port_lanes: total number of lanes on the port (sum of lanes of all subports) - * @is_split: is interface part of a split port - * @fec_modes_supported: bitmap of FEC modes supported - */ +/* ETH table information */ struct nfp_eth_table { - uint32_t count; - uint32_t max_index; + uint32_t count; /**< Number of table entries */ + uint32_t max_index; /**< Max of @index fields of all @ports */ struct nfp_eth_table_port { + /** Port index according to legacy ethX numbering */ uint32_t eth_index; - uint32_t index; - uint32_t nbi; - uint32_t base; - uint32_t lanes; - uint32_t speed; + uint32_t index; /**< Chip-wide first channel index */ + uint32_t nbi; /**< NBI index */ + uint32_t base; /**< First channel index (within NBI) */ + uint32_t lanes; /**< Number of channels */ + uint32_t speed; /**< Interface speed (in Mbps) */ - uint32_t interface; - enum nfp_eth_media media; + uint32_t interface; /**< Interface (module) plugged in */ + enum nfp_eth_media media; /**< Media type of the @interface */ - enum nfp_eth_fec fec; - enum nfp_eth_aneg aneg; + enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ - struct rte_ether_addr mac_addr; + struct rte_ether_addr mac_addr; /**< Interface MAC address */ - uint8_t label_port; + uint8_t label_port; /**< Port id */ + /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; - int tx_enabled; - int rx_enabled; - - int override_changed; + int enabled; /**< Enable port */ + int tx_enabled; /**< Enable TX */ + int rx_enabled; /**< Enable RX */ - /* Computed fields */ - uint8_t port_type; + int override_changed; /**< Media reconfig pending */ + uint8_t port_type; /**< One of %PORT_* */ + /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; + int is_split; /**< Split port */ - uint32_t fec_modes_supported; - } ports[]; + uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ + } ports[]; /**< Table of ports */ }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); @@ -263,28 +236,17 @@ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); -/** - * struct nfp_nsp_identify - NSP static information - * @version: opaque version string - * @flags: version flags - * @br_primary: branch id of primary bootloader - * @br_secondary: branch id of secondary bootloader - * @br_nsp: branch id of NSP - * @primary: version of primary bootloader - * @secondary: version id of secondary bootloader - * @nsp: version id of NSP - * @sensor_mask: mask of present sensors available on NIC - */ +/* NSP static information */ struct nfp_nsp_identify { - char version[40]; - uint8_t flags; - uint8_t br_primary; - uint8_t br_secondary; - uint8_t br_nsp; - uint16_t primary; - uint16_t secondary; - uint16_t nsp; - uint64_t sensor_mask; + char version[40]; /**< Opaque version string */ + uint8_t flags; /**< Version flags */ + uint8_t br_primary; /**< Branch id of primary bootloader */ + uint8_t br_secondary; /**< Branch id of secondary bootloader */ + uint8_t br_nsp; /**< Branch id of NSP */ + uint16_t primary; /**< Version of primary bootloader */ + uint16_t secondary; /**< Version id of secondary bootloader */ + uint16_t nsp; /**< Version id of NSP */ + uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 74daa92aed..cb090d2a47 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -264,7 +264,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) goto err; } - /* The NFP3800 NIC support 8 ports, but only 2 ports are valid, + /* + * The NFP3800 NIC support 8 ports, but only 2 ports are valid, * the rest 6 ports mac are all 0, ensure we don't use these port */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { @@ -274,7 +275,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) cnt++; } - /* Some versions of flash will give us 0 instead of port count. For + /* + * Some versions of flash will give us 0 instead of port count. For * those that give a port count, verify it against the value calculated * above. */ @@ -312,14 +314,16 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) return NULL; } -/* - * nfp_eth_read_ports() - retrieve port information - * @cpp: NFP CPP handle +/** + * Read the port information from the device. + * + * Returned structure should be freed once no longer needed. * - * Read the port information from the device. Returned structure should - * be freed with kfree() once no longer needed. + * @param cpp + * NFP CPP handle * - * Return: populated ETH table or NULL on error. + * @return + * Populated ETH table or NULL on error. */ struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) @@ -387,19 +391,19 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) free(entries); } -/* - * nfp_eth_config_commit_end() - perform recorded configuration changes - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * +/** * Perform the configuration which was requested with __nfp_eth_set_*() - * helpers and recorded in @nsp state. If device was already configured - * as requested or no __nfp_eth_set_*() operations were made no NSP command + * helpers and recorded in @nsp state. If device was already configured + * as requested or no __nfp_eth_set_*() operations were made, no NSP command * will be performed. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_config_commit_end(struct nfp_nsp *nsp) @@ -417,19 +421,21 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) return ret; } -/* - * nfp_eth_set_mod_enable() - set PHY module enable control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @enable: Desired state - * +/** * Enable or disable PHY module (this usually means setting the TX lanes * disable bits). * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param enable + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, @@ -460,18 +466,20 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * nfp_eth_set_configured() - set PHY module configured control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @configed: Desired state - * +/** * Set the ifup/ifdown state on the PHY. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param configured + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_configured(struct nfp_cpp *cpp, @@ -525,7 +533,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, /* * Note: set features were added in ABI 0.14 but the error - * codes were initially not populated correctly. + * codes were initially not populated correctly. */ if (nfp_nsp_get_abi_ver_minor(nsp) < 17) { PMD_DRV_LOG(ERR, "set operations not supported, please update flash"); @@ -555,15 +563,17 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, val, ctrl_bit); \ })) -/* - * __nfp_eth_set_aneg() - set PHY autonegotiation control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired autonegotiation mode - * +/** * Allow/disallow PHY module to advertise/perform autonegotiation. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired autonegotiation mode + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, @@ -573,15 +583,17 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } -/* - * __nfp_eth_set_fec() - set PHY forward error correction control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired fec mode - * +/** * Set the PHY module forward error correction mode. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired fec mode + * + * @return + * 0 or -ERRNO */ static int __nfp_eth_set_fec(struct nfp_nsp *nsp, @@ -591,16 +603,20 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } -/* - * nfp_eth_set_fec() - set PHY forward error correction control mode - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @mode: Desired fec mode +/** + * Set PHY forward error correction control mode + * + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param mode + * Desired fec mode * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_fec(struct nfp_cpp *cpp, @@ -623,17 +639,19 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * __nfp_eth_set_speed() - set interface speed/rate - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @speed: Desired speed (per lane) - * - * Set lane speed. Provided @speed value should be subport speed divided - * by number of lanes this subport is spanning (i.e. 10000 for 40G, 25000 for - * 50G, etc.) +/** + * Set lane speed. + * Provided @speed value should be subport speed divided by number of + * lanes this subport is spanning (i.e. 10000 for 40G, 25000 for 50G, etc.) * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param speed + * Desired speed (per lane) + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, @@ -651,15 +669,17 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } -/* - * __nfp_eth_set_split() - set interface lane split - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @lanes: Desired lanes per port - * +/** * Set number of lanes in the port. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param lanes + * Desired lanes per port + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_split(struct nfp_nsp *nsp, diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 363f7d6198..bdebf5c3aa 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -22,32 +22,23 @@ #define NFP_RESOURCE_ENTRY_NAME_SZ 8 -/* - * struct nfp_resource_entry - Resource table entry - * @owner: NFP CPP Lock, interface owner - * @key: NFP CPP Lock, posix_crc32(name, 8) - * @region: Memory region descriptor - * @name: ASCII, zero padded name - * @reserved - * @cpp_action: CPP Action - * @cpp_token: CPP Token - * @cpp_target: CPP Target ID - * @page_offset: 256-byte page offset into target's CPP address - * @page_size: size, in 256-byte pages - */ +/* Resource table entry */ struct nfp_resource_entry { struct nfp_resource_entry_mutex { - uint32_t owner; - uint32_t key; + uint32_t owner; /**< NFP CPP Lock, interface owner */ + uint32_t key; /**< NFP CPP Lock, posix_crc32(name, 8) */ } mutex; + /* Memory region descriptor */ struct nfp_resource_entry_region { + /** ASCII, zero padded name */ uint8_t name[NFP_RESOURCE_ENTRY_NAME_SZ]; uint8_t reserved[5]; - uint8_t cpp_action; - uint8_t cpp_token; - uint8_t cpp_target; + uint8_t cpp_action; /**< CPP Action */ + uint8_t cpp_token; /**< CPP Token */ + uint8_t cpp_target; /**< CPP Target ID */ + /** 256-byte page offset into target's CPP address */ uint32_t page_offset; - uint32_t page_size; + uint32_t page_size; /**< Size, in 256-byte pages */ } region; }; @@ -147,14 +138,18 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, return err; } -/* - * nfp_resource_acquire() - Acquire a resource handle - * @cpp: NFP CPP handle - * @name: Name of the resource +/** + * Acquire a resource handle + * + * Note: This function locks the acquired resource. * - * NOTE: This function locks the acquired resource + * @param cpp + * NFP CPP handle + * @param name + * Name of the resource * - * Return: NFP Resource handle, or NULL + * @return + * NFP Resource handle, or NULL */ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, @@ -183,7 +178,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, } wait.tv_sec = 0; - wait.tv_nsec = 1000000; + wait.tv_nsec = 1000000; /* 1ms */ for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); @@ -194,7 +189,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, goto err_free; } - if (count++ > 1000) { + if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); err = -EBUSY; goto err_free; @@ -213,11 +208,13 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_resource_release() - Release a NFP Resource handle - * @res: NFP Resource handle +/** + * Release a NFP Resource handle * - * NOTE: This function implicitly unlocks the resource handle + * NOTE: This function implicitly unlocks the resource handle. + * + * @param res + * NFP Resource handle */ void nfp_resource_release(struct nfp_resource *res) @@ -227,11 +224,14 @@ nfp_resource_release(struct nfp_resource *res) free(res); } -/* - * nfp_resource_cpp_id() - Return the cpp_id of a resource handle - * @res: NFP Resource handle +/** + * Return the cpp_id of a resource handle + * + * @param res + * NFP Resource handle * - * Return: NFP CPP ID + * @return + * NFP CPP ID */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res) @@ -239,11 +239,14 @@ nfp_resource_cpp_id(const struct nfp_resource *res) return res->cpp_id; } -/* - * nfp_resource_name() - Return the name of a resource handle - * @res: NFP Resource handle +/** + * Return the name of a resource handle * - * Return: const char pointer to the name of the resource + * @param res + * NFP Resource handle + * + * @return + * Const char pointer to the name of the resource */ const char * nfp_resource_name(const struct nfp_resource *res) @@ -251,11 +254,14 @@ nfp_resource_name(const struct nfp_resource *res) return res->name; } -/* - * nfp_resource_address() - Return the address of a resource handle - * @res: NFP Resource handle +/** + * Return the address of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Address of the resource + * @return + * Address of the resource */ uint64_t nfp_resource_address(const struct nfp_resource *res) @@ -263,11 +269,14 @@ nfp_resource_address(const struct nfp_resource *res) return res->addr; } -/* - * nfp_resource_size() - Return the size in bytes of a resource handle - * @res: NFP Resource handle +/** + * Return the size in bytes of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Size of the resource in bytes + * @return + * Size of the resource in bytes */ uint64_t nfp_resource_size(const struct nfp_resource *res) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 009b7359a4..4236950caf 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -8,43 +8,27 @@ #include "nfp_cpp.h" +/* Netronone Flow Firmware Table */ #define NFP_RESOURCE_NFP_NFFW "nfp.nffw" + +/* NFP Hardware Info Database */ #define NFP_RESOURCE_NFP_HWINFO "nfp.info" + +/* Service Processor */ #define NFP_RESOURCE_NSP "nfp.sp" -/** - * Opaque handle to a NFP Resource - */ +/* Opaque handle to a NFP Resource */ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, const char *name); -/** - * Release a NFP Resource, and free the handle - * @param[in] res NFP Resource handle - */ void nfp_resource_release(struct nfp_resource *res); -/** - * Return the CPP ID of a NFP Resource - * @param[in] res NFP Resource handle - * @return CPP ID of the NFP Resource - */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res); -/** - * Return the name of a NFP Resource - * @param[in] res NFP Resource handle - * @return Name of the NFP Resource - */ const char *nfp_resource_name(const struct nfp_resource *res); -/** - * Return the target address of a NFP Resource - * @param[in] res NFP Resource handle - * @return Address of the NFP Resource - */ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index d15a920752..0e6c0f9fe1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -162,11 +162,14 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_rtsym_count() - Get the number of RTSYM descriptors - * @rtbl: NFP RTsym table +/** + * Get the number of RTSYM descriptors + * + * @param rtbl + * NFP RTSYM table * - * Return: Number of RTSYM descriptors + * @return + * Number of RTSYM descriptors */ int nfp_rtsym_count(struct nfp_rtsym_table *rtbl) @@ -177,12 +180,16 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) return rtbl->num; } -/* - * nfp_rtsym_get() - Get the Nth RTSYM descriptor - * @rtbl: NFP RTsym table - * @idx: Index (0-based) of the RTSYM descriptor +/** + * Get the Nth RTSYM descriptor + * + * @param rtbl + * NFP RTSYM table + * @param idx + * Index (0-based) of the RTSYM descriptor * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_get(struct nfp_rtsym_table *rtbl, @@ -197,12 +204,16 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, return &rtbl->symtab[idx]; } -/* - * nfp_rtsym_lookup() - Return the RTSYM descriptor for a symbol name - * @rtbl: NFP RTsym table - * @name: Symbol name +/** + * Return the RTSYM descriptor for a symbol name + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, @@ -227,7 +238,8 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_NONE: PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; - case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ + case NFP_RTSYM_TYPE_OBJECT: + /* FALLTHROUGH */ case NFP_RTSYM_TYPE_FUNCTION: return sym->size; case NFP_RTSYM_TYPE_ABS: @@ -327,17 +339,22 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } -/* - * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol - * @rtbl: NFP RTsym table - * @name: Symbol name - * @error: Pointer to error code (optional) +/** + * Read a simple unsigned scalar value from symbol * * Lookup a symbol, map, read it and return it's value. Value of the symbol * will be interpreted as a simple little-endian unsigned value. Symbol can * be 4 or 8 bytes in size. * - * Return: value read, on error sets the error and returns ~0ULL. + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param error + * Pointer to error code (optional) + * + * @return + * Value read, on error sets the error and returns ~0ULL. */ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index e7295258b3..ff1facbd17 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -31,12 +31,12 @@ * of "sram" symbols for backward compatibility, which are viewed as global. */ struct nfp_rtsym { - const char *name; - uint64_t addr; - uint64_t size; - int type; - int target; - int domain; + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + int type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ }; struct nfp_rtsym_table; diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 611848e233..540b242a43 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -767,7 +767,7 @@ nfp_encode_basic(uint64_t *addr, /* * Make sure we compare against isldN values by clearing the * LSB. This is what the silicon does. - **/ + */ isld[0] &= ~1; isld[1] &= ~1; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 08/26] net/nfp: standard the blank character 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (6 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 07/26] net/nfp: standard the comment style Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 09/26] net/nfp: unify the guide line of header file Chaoyong He ` (20 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Use space character to align instead of TAB character. There should one blank line to split the block of logic, no more no less. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 18 +-- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 17 ++- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 - drivers/net/nfp/nfpcore/nfp_crc.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.h | 45 ++++--- drivers/net/nfp/nfpcore/nfp_mip.c | 9 +- drivers/net/nfp/nfpcore/nfp_mip.h | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 17 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 3 + drivers/net/nfp/nfpcore/nfp_nsp.h | 105 ++++++++-------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 132 ++++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 18 +-- drivers/net/nfp/nfpcore/nfp_rtsym.c | 16 +-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 1 + 18 files changed, 206 insertions(+), 195 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index 7750a0218e..efaa87c0e5 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -15,8 +15,8 @@ #define NFP_CPP_TARGET_PCIE 9 #define NFP_CPP_TARGET_ARM 10 #define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ #define NFP_CPP_TARGET_CT_XPB 14 #define NFP_CPP_TARGET_LOCAL_SCRATCH 15 #define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 82189e9910..92cae2557a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -80,16 +80,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_acquire)(struct nfp_cpp_area *area); + /* * Release resources for a NFP CPP area * Serialized */ void (*area_release)(struct nfp_cpp_area *area); + /* * Return a void IO pointer to a NFP CPP area * NOTE: This is _not_ serialized */ - void *(*area_iomem)(struct nfp_cpp_area *area); /* @@ -280,7 +281,7 @@ void nfp_cpp_free(struct nfp_cpp *cpp); * @return * true if model is in the NFP6000 family, false otherwise. */ -#define NFP_CPP_MODEL_IS_6000(model) \ +#define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) @@ -290,11 +291,11 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * NFP Interface types - logical interface for this CPP connection 4 bits are * reserved for interface type. */ -#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 -#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 -#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 -#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 -#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 +#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 +#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 +#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 +#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 +#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 /** * Construct a 16-bit NFP Interface ID @@ -316,7 +317,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * @return * Interface ID */ -#define NFP_CPP_INTERFACE(type, unit, channel) \ +#define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) @@ -354,7 +355,6 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) - uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 7e94bfb611..28a6278497 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -37,7 +37,7 @@ #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" -#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) +#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -93,7 +93,7 @@ struct nfp_bar { char *iomem; /**< mapped IO memory */ }; -#define BUSDEV_SZ 13 +#define BUSDEV_SZ 13 struct nfp_pcie_user { struct nfp_bar bar[NFP_BAR_MAX]; @@ -163,7 +163,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); @@ -171,7 +170,6 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); @@ -179,7 +177,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 21; } @@ -278,6 +275,7 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; bar->barcfg = 0; @@ -310,6 +308,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; if (bar->lock == 0) { @@ -317,6 +316,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) return bar; } } + return NULL; } @@ -346,7 +346,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } /* Generic CPP bus access interface. */ - struct nfp6000_area_priv { struct nfp_bar *bar; uint32_t bar_offset; @@ -443,6 +442,7 @@ static void nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + priv->bar->lock = 0; priv->bar = NULL; priv->iomem = NULL; @@ -478,7 +478,6 @@ nfp6000_area_read(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.read; - if (width <= 0) return -EINVAL; @@ -548,7 +547,6 @@ nfp6000_area_write(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.write; - if (width <= 0) return -EINVAL; @@ -718,6 +716,7 @@ nfp6000_set_barsz(struct rte_pci_device *dev, i++; desc->barsz = i; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 0e8372576e..c46fd62e32 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -433,7 +433,6 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) { if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) { PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; @@ -862,7 +861,6 @@ nfp_cpp_alloc(struct rte_pci_device *dev, const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); - if (ops == NULL || ops->init == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 68f27f8c68..986c52711d 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -15,11 +15,13 @@ nfp_crc32_be_generic(uint32_t crc, uint32_t polynomial) { uint32_t i; + while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); } + return crc; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index f5579ab60f..e33e660ea9 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -54,6 +54,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, return -EINVAL; } } + return 0; } @@ -178,6 +179,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) free(db); return NULL; } + return db; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 424db8035d..37427bb6c8 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -8,33 +8,31 @@ #include <inttypes.h> -#define HWINFO_SIZE_MIN 0x100 +#define HWINFO_SIZE_MIN 0x100 /* * The Hardware Info Table defines the properties of the system. * * HWInfo v1 Table (fixed size) * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value - * table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * HWInfo v2 Table (variable size) * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding - * CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * If the HWInfo table is in the process of being updated, the low bit of * version will be set. @@ -47,17 +45,16 @@ * * All keys are guaranteed to be unique. * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value * ... * * HWInfo v2 Key/Value Table * ------------------------- * * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * * Unsorted. * * Note: Only the HwInfo v2 Table be supported now. @@ -65,7 +62,7 @@ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) #define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) struct nfp_hwinfo { uint8_t start[0]; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0892c99e96..7f06c24927 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -11,9 +11,9 @@ #include "nfp_mip.h" #include "nfp_nffw.h" -#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -#define NFP_MIP_VERSION rte_cpu_to_le_32(1) -#define NFP_MIP_MAX_OFFSET (256 * 1024) +#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ +#define NFP_MIP_VERSION rte_cpu_to_le_32(1) +#define NFP_MIP_MAX_OFFSET (256 * 1024) struct nfp_mip { uint32_t signature; @@ -49,11 +49,13 @@ nfp_mip_try_read(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } + if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } + if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); @@ -82,6 +84,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); + exit_close_nffw: nfp_nffw_info_close(nffw_info); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 980abc2517..16824a6769 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -18,4 +18,5 @@ void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); + #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 404d4fa938..e97537b795 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -85,7 +85,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, { int err; uint32_t model = nfp_cpp_model(cpp); - uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -134,7 +134,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint32_t tmp; struct nfp_cpp_mutex *mutex; uint32_t model = nfp_cpp_model(cpp); - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -231,12 +231,15 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) /* If err != -EBUSY, then the lock was damaged */ if (err < 0 && err != -EBUSY) return err; + if (time(NULL) >= warn_at) { PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } + sched_yield(); } + return 0; } @@ -257,8 +260,8 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) uint32_t value; struct nfp_cpp *cpp = mutex->cpp; uint16_t interface = nfp_cpp_interface(cpp); - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -314,9 +317,9 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) uint32_t tmp; uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 5f004e3b21..be80eeaa0e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -61,10 +61,10 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index a96ccea38b..ca3fc2fa59 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -290,6 +290,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_cpp_readq(cpp, nsp_cpp, nsp_command, &ret_val); if (err < 0) return err; + ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); @@ -354,6 +355,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, if (err < 0) return err; } + /* Zero out remaining part of the buffer */ if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); @@ -400,6 +402,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 0fcb21e99c..ee58bf33b8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -10,73 +10,72 @@ #include "nfp_nsp.h" #define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) + (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) #define __bf_shf(x) (__builtin_ffsll(x) - 1) -#define FIELD_GET(_mask, _reg) \ +#define FIELD_GET(_mask, _reg) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ })) -#define FIELD_FIT(_mask, _val) \ +#define FIELD_FIT(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ })) -#define FIELD_PREP(_mask, _val) \ +#define FIELD_PREP(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ })) /* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_START RTE_BIT64(0) /* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) -#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER 0x18 -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) +#define NSP_CODE_MAJOR GENMASK(15, 12) +#define NSP_CODE_MINOR GENMASK(11, 0) enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ }; static const struct { @@ -123,13 +122,13 @@ nfp_nsp_has_mac_reinit(struct nfp_nsp *state) } enum nfp_eth_interface { - NFP_INTERFACE_NONE = 0, - NFP_INTERFACE_SFP = 1, - NFP_INTERFACE_SFPP = 10, - NFP_INTERFACE_SFP28 = 28, - NFP_INTERFACE_QSFP = 40, - NFP_INTERFACE_CXP = 100, - NFP_INTERFACE_QSFP28 = 112, + NFP_INTERFACE_NONE = 0, + NFP_INTERFACE_SFP = 1, + NFP_INTERFACE_SFPP = 10, + NFP_INTERFACE_SFP28 = 28, + NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_CXP = 100, + NFP_INTERFACE_QSFP28 = 112, }; enum nfp_eth_media { @@ -153,10 +152,10 @@ enum nfp_eth_fec { NFP_FEC_DISABLED_BIT, }; -#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) -#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) -#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) -#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) +#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) +#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) +#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) +#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) /* ETH table information */ struct nfp_eth_table { diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 3081e22dad..769ed54957 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -107,5 +107,6 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, default: return -EINVAL; } + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index cb090d2a47..d291552d03 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,70 +11,68 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define NSP_ETH_NBI_PORT_COUNT 24 -#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) -#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ - sizeof(union eth_table_entry)) - -#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) -#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) -#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) -#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) -#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) -#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) - -#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) - -#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) -#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) -#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) -#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) -#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) -#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) -#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) - -#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) -#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) -#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) -#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) -#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) +#define NSP_ETH_NBI_PORT_COUNT 24 +#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) +#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * sizeof(union eth_table_entry)) + +#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) +#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) +#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) +#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) +#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) +#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) + +#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) + +#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) +#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) +#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) +#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) +#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) +#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) +#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) + +#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) +#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) +#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) +#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) +#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) /* Which connector port. */ -#define PORT_TP 0x00 -#define PORT_AUI 0x01 -#define PORT_MII 0x02 -#define PORT_FIBRE 0x03 -#define PORT_BNC 0x04 -#define PORT_DA 0x05 -#define PORT_NONE 0xef -#define PORT_OTHER 0xff - -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 +#define PORT_TP 0x00 +#define PORT_AUI 0x01 +#define PORT_MII 0x02 +#define PORT_FIBRE 0x03 +#define PORT_BNC 0x04 +#define PORT_DA 0x05 +#define PORT_NONE 0xef +#define PORT_OTHER 0xff + +#define SPEED_10 10 +#define SPEED_100 100 +#define SPEED_1000 1000 +#define SPEED_2500 2500 +#define SPEED_5000 5000 +#define SPEED_10000 10000 +#define SPEED_14000 14000 +#define SPEED_20000 20000 +#define SPEED_25000 25000 +#define SPEED_40000 40000 +#define SPEED_50000 50000 +#define SPEED_56000 56000 +#define SPEED_100000 100000 enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW }; @@ -102,12 +100,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, 0, }, + { RATE_10M, SPEED_10, }, + { RATE_100M, SPEED_100, }, + { RATE_1G, SPEED_1000, }, + { RATE_10G, SPEED_10000, }, + { RATE_25G, SPEED_25000, }, }; static uint32_t @@ -212,10 +210,12 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) if (table->ports[i].label_port != table->ports[j].label_port) continue; + table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; + if (table->ports[i].label_subport == table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", @@ -556,11 +556,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, return 0; } -#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ - (__extension__ ({ \ - typeof(mask) _x = (mask); \ +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ + (__extension__ ({ \ + typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index bdebf5c3aa..54bcc5f234 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -13,14 +13,14 @@ #include "nfp_resource.h" #include "nfp_crc.h" -#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL +#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU +#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL /* NFP Resource Table self-identifier */ -#define NFP_RESOURCE_TBL_NAME "nfp.res" -#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ +#define NFP_RESOURCE_TBL_NAME "nfp.res" +#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ -#define NFP_RESOURCE_ENTRY_NAME_SZ 8 +#define NFP_RESOURCE_ENTRY_NAME_SZ 8 /* Resource table entry */ struct nfp_resource_entry { @@ -42,9 +42,9 @@ struct nfp_resource_entry { } region; }; -#define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ - sizeof(struct nfp_resource_entry)) +#define NFP_RESOURCE_TBL_SIZE 4096 +#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ + sizeof(struct nfp_resource_entry)) struct nfp_resource { char name[NFP_RESOURCE_ENTRY_NAME_SZ + 1]; @@ -75,6 +75,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Grabbing device lock not supported"); return -EOPNOTSUPP; } + key = nfp_crc32_posix(name_pad, NFP_RESOURCE_ENTRY_NAME_SZ); for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { @@ -96,6 +97,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 0e6c0f9fe1..37811ceaeb 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -17,18 +17,18 @@ #include "nfp6000/nfp6000.h" /* These need to match the linker */ -#define SYM_TGT_LMEM 0 -#define SYM_TGT_EMU_CACHE 0x17 +#define SYM_TGT_LMEM 0 +#define SYM_TGT_EMU_CACHE 0x17 struct nfp_rtsym_entry { - uint8_t type; - uint8_t target; - uint8_t island; - uint8_t addr_hi; + uint8_t type; + uint8_t target; + uint8_t island; + uint8_t addr_hi; uint32_t addr_lo; uint16_t name; - uint8_t menum; - uint8_t size_hi; + uint8_t menum; + uint8_t size_hi; uint32_t size_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index ff1facbd17..de1966f04b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -57,4 +57,5 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); + #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 09/26] net/nfp: unify the guide line of header file 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (7 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 08/26] net/nfp: standard the blank character Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 10/26] net/nfp: rename some parameter and variable Chaoyong He ` (19 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Unify the guide line of header file, we choose '__FOO_BAR_H__' style. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 2 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 +- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_resource.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- drivers/net/nfp/nfpcore/nfp_target.h | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 92cae2557a..ceb4d56a08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -442,4 +442,4 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); -#endif /* !__NFP_CPP_H__ */ +#endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 37427bb6c8..543562779a 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -81,4 +81,4 @@ struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup); -#endif +#endif /* __NFP_HWINFO_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 16824a6769..371c635b97 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -19,4 +19,4 @@ void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); -#endif +#endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index e032b6cce7..f84be463c4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -75,4 +75,4 @@ struct nfp_nffw_info { struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); -#endif +#endif /* __NFP_NFFW_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index ee58bf33b8..7bf584dcd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NSP_NSP_H -#define NSP_NSP_H 1 +#ifndef __NSP_NSP_H__ +#define __NSP_NSP_H__ #include "nfp_cpp.h" #include "nfp_nsp.h" @@ -260,4 +260,4 @@ enum nfp_nsp_sensor_id { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val); -#endif +#endif /* __NSP_NSP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 4236950caf..18196d273c 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NFP_RESOURCE_H -#define NFP_RESOURCE_H +#ifndef __NFP_RESOURCE_H__ +#define __NFP_RESOURCE_H__ #include "nfp_cpp.h" @@ -33,4 +33,4 @@ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); -#endif /* NFP_RESOURCE_H */ +#endif /* __NFP_RESOURCE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index de1966f04b..fdde1eb75b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -58,4 +58,4 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -#endif +#endif /* __NFP_RTSYM_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 195e599d31..2a2f083914 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -3,7 +3,7 @@ * All rights reserved. */ -#ifndef NFP_TARGET_H -#define NFP_TARGET_H +#ifndef __NFP_TARGET_H__ +#define __NFP_TARGET_H__ -#endif /* NFP_TARGET_H */ +#endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 10/26] net/nfp: rename some parameter and variable 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (8 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 09/26] net/nfp: unify the guide line of header file Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 11/26] net/nfp: refact the hwinfo module Chaoyong He ` (18 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Rename some parameter and variable to make the logic easier to understand. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 10 ++--- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 42 ++++++++--------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 52 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 20 ++++----- drivers/net/nfp/nfpcore/nfp_nffw.h | 4 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 8 ++-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 20 ++++----- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index ceb4d56a08..be7ae1d919 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -247,7 +247,7 @@ void *nfp_cpp_priv(struct nfp_cpp *cpp); void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); -uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); +uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, @@ -381,10 +381,10 @@ uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *buffer, size_t length); + void *address, size_t length); int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *buffer, size_t length); + const void *address, size_t length); void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); @@ -393,10 +393,10 @@ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, void *kernel_vaddr, size_t length); + uint64_t address, void *buf, size_t length); int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, const void *kernel_vaddr, size_t length); + uint64_t address, const void *buf, size_t length); int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 28a6278497..db15411eb2 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -118,9 +118,9 @@ static int nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, uint64_t *bar_base, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -129,7 +129,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (tgt >= 16) + if (target >= 16) return -EINVAL; switch (width) { @@ -149,15 +149,15 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; } - if (act != NFP_CPP_ACTION_RW && act != 0) { + if (action != NFP_CPP_ACTION_RW && action != 0) { /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(action); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -170,8 +170,8 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -221,9 +221,9 @@ nfp_bar_write(struct nfp_pcie_user *nfp, static int nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -232,8 +232,8 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, uint32_t newcfg; uint64_t newbase; - err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + err = nfp_compute_bar(bar, &newcfg, &newbase, target, action, + token, offset, size, width); if (err != 0) return err; @@ -457,15 +457,15 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, - void *kernel_vaddr, + void *address, uint32_t offset, size_t length) { size_t n; int width; bool is_64; - uint32_t *wrptr32 = kernel_vaddr; - uint64_t *wrptr64 = kernel_vaddr; + uint32_t *wrptr32 = address; + uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; const volatile uint32_t *rdptr32; const volatile uint64_t *rdptr64; @@ -526,7 +526,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, - const void *kernel_vaddr, + const void *address, uint32_t offset, size_t length) { @@ -536,8 +536,8 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; - const uint32_t *rdptr32 = kernel_vaddr; - const uint64_t *rdptr64 = kernel_vaddr; + const uint32_t *rdptr32 = address; + const uint64_t *rdptr64 = address; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index c46fd62e32..7173b4d8a5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -90,7 +90,7 @@ nfp_cpp_model(struct nfp_cpp *cpp) if (cpp == NULL) return NFP_CPP_MODEL_INVALID; - err = __nfp_cpp_model_autodetect(cpp, &model); + err = nfp_cpp_model_autodetect(cpp, &model); if (err < 0) return err; @@ -484,7 +484,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -498,13 +498,13 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *kernel_vaddr, + void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_read(area, kernel_vaddr, offset, length); + return area->cpp->op->area_read(area, address, offset, length); } /** @@ -514,7 +514,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -528,13 +528,13 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *kernel_vaddr, + const void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_write(area, kernel_vaddr, offset, length); + return area->cpp->op->area_write(area, address, offset, length); } /* @@ -880,14 +880,14 @@ nfp_cpp_alloc(struct rte_pci_device *dev, } if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpbaddr; - size_t tgt; + uint32_t xpb_addr; + size_t target; - for (tgt = 0; tgt < RTE_DIM(cpp->imb_cat_table); tgt++) { + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + (tgt * 4); - err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, + (uint32_t *)&cpp->imb_cat_table[target]); if (err < 0) { free(cpp); return NULL; @@ -950,9 +950,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer for result * @param length * Number of bytes to read @@ -963,20 +963,20 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - void *kernel_vaddr, + uint64_t offset, + void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } - err = nfp_cpp_area_read(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_read(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -989,9 +989,9 @@ nfp_cpp_read(struct nfp_cpp *cpp, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer to read from * @param length * Number of bytes to write @@ -1002,20 +1002,20 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - const void *kernel_vaddr, + uint64_t offset, + const void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; } - err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_write(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -1026,7 +1026,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, +nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { int err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 371c635b97..7fa09ee575 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,6 +17,6 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index e97537b795..82598be7a1 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,7 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint32_t model, int *target, uint64_t address) { @@ -87,7 +87,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return err; @@ -152,7 +152,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return NULL; } - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index be80eeaa0e..df6292e909 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -31,11 +31,11 @@ nffw_res_flg_init_get(const struct nfp_nffw_info_data *res) return (res->flags[0] >> 0) & 1; } -/* loaded = loaded__mu_da__mip_off_hi<31:31> */ +/* loaded = loaded_mu_da_mip_off_hi<31:31> */ static uint32_t nffw_fwinfo_loaded_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 31) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 31) & 1; } /* mip_cppid = mip_cppid */ @@ -45,18 +45,18 @@ nffw_fwinfo_mip_cppid_get(const struct nffw_fwinfo *fi) return fi->mip_cppid; } -/* loaded = loaded__mu_da__mip_off_hi<8:8> */ +/* loaded = loaded_mu_da_mip_off_hi<8:8> */ static uint32_t nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ +/* mip_offset = (loaded_mu_da_mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { - uint64_t mip_off_hi = fi->loaded__mu_da__mip_off_hi; + uint64_t mip_off_hi = fi->loaded_mu_da_mip_off_hi; return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } @@ -227,7 +227,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) + uint64_t *offset) { struct nffw_fwinfo *fwinfo; @@ -236,7 +236,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, return -EINVAL; *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); - *off = nffw_fwinfo_mip_offset_get(fwinfo); + *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; @@ -248,8 +248,8 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, if (locality_off < 0) return locality_off; - *off &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); - *off |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; + *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); + *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; } return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index f84be463c4..52e25c090a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -38,11 +38,11 @@ /* nfp.nffw meinfo */ struct nffw_meinfo { - uint32_t ctxmask__fwid__meid; + uint32_t ctxmask_fwid_meid; }; struct nffw_fwinfo { - uint32_t loaded__mu_da__mip_off_hi; + uint32_t loaded_mu_da_mip_off_hi; uint32_t mip_cppid; /* 0 means no MIP */ uint32_t mip_offset_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 7bf584dcd0..705574b900 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -231,9 +231,9 @@ struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); -int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); +int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); +int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /* NSP static information */ struct nfp_nsp_identify { @@ -248,7 +248,7 @@ struct nfp_nsp_identify { uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; -struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); +struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp); enum nfp_nsp_sensor_id { NFP_SENSOR_CHIP_TEMPERATURE, diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 769ed54957..f656f200f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -24,7 +24,7 @@ struct nsp_identify { }; struct nfp_nsp_identify * -__nfp_nsp_identify(struct nfp_nsp *nsp) +nfp_nsp_identify(struct nfp_nsp *nsp) { int ret; struct nsp_identify *ni; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index d291552d03..32c1838a40 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -242,7 +242,7 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) } static struct nfp_eth_table * -__nfp_eth_read_ports(struct nfp_nsp *nsp) +nfp_eth_read_ports_real(struct nfp_nsp *nsp) { int ret; uint32_t i; @@ -335,7 +335,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) if (nsp == NULL) return NULL; - ret = __nfp_eth_read_ports(nsp); + ret = nfp_eth_read_ports_real(nsp); nfp_nsp_close(nsp); return ret; @@ -484,7 +484,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configed) + int configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -507,10 +507,10 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, /* Check if we are already in requested state */ reg = rte_le_to_cpu_64(entries[idx].state); - if (configed != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { + if (configured != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { reg = rte_le_to_cpu_64(entries[idx].control); reg &= ~NSP_ETH_CTRL_CONFIGURED; - reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configed); + reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); nfp_nsp_config_set_modified(nsp, 1); @@ -576,7 +576,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, +nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -596,7 +596,7 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, * 0 or -ERRNO */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, +nfp_eth_set_fec_real(struct nfp_nsp *nsp, enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -630,7 +630,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, if (nsp == NULL) return -EIO; - err = __nfp_eth_set_fec(nsp, mode); + err = nfp_eth_set_fec_real(nsp, mode); if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; @@ -654,7 +654,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, * 0 or -ERRNO */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, +nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed) { enum nfp_eth_rate rate; @@ -682,7 +682,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, +nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 11/26] net/nfp: refact the hwinfo module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (9 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 10/26] net/nfp: rename some parameter and variable Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 12/26] net/nfp: refact the nffw module Chaoyong He ` (17 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Move the definition of data structure and macro into the implement file. Also remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 84 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 71 +---------------------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index e33e660ea9..c334202bd7 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -17,17 +17,82 @@ * (ie, in this example, ME 39 has been reserved by boardconfig.) */ -#include <stdio.h> -#include <time.h> +#include "nfp_hwinfo.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" -#include "nfp_hwinfo.h" -#include "nfp_crc.h" -static int +#define HWINFO_SIZE_MIN 0x100 + +/* + * The Hardware Info Table defines the properties of the system. + * + * HWInfo v1 Table (fixed size) + * + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * HWInfo v2 Table (variable size) + * + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * If the HWInfo table is in the process of being updated, the low bit of + * version will be set. + * + * HWInfo v1 Key/Value Table + * ------------------------- + * + * The key/value table is a set of offsets to ASCIIZ strings which have + * been strcmp(3) sorted (yes, please use bsearch(3) on the table). + * + * All keys are guaranteed to be unique. + * + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value + * ... + * + * HWInfo v2 Key/Value Table + * ------------------------- + * + * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' + * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. + */ + +#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) + +struct nfp_hwinfo { + uint8_t start[0]; + + uint32_t version; + uint32_t size; + + /* V2 specific fields */ + uint32_t limit; + uint32_t resv; + + char data[]; +}; + +static bool nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) { return hwinfo->version & NFP_HWINFO_VERSION_UPDATING; @@ -120,7 +185,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, goto exit_free; } - header = (void *)db; + header = (struct nfp_hwinfo *)db; if (nfp_hwinfo_is_updating(header)) goto exit_free; @@ -133,7 +198,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, /* NULL-terminate for safety */ db[*cpp_size] = '\0'; - return (void *)db; + return (struct nfp_hwinfo *)db; + exit_free: free(db); return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 543562779a..c812f10076 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -6,76 +6,9 @@ #ifndef __NFP_HWINFO_H__ #define __NFP_HWINFO_H__ -#include <inttypes.h> +#include "nfp_cpp.h" -#define HWINFO_SIZE_MIN 0x100 - -/* - * The Hardware Info Table defines the properties of the system. - * - * HWInfo v1 Table (fixed size) - * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * HWInfo v2 Table (variable size) - * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * If the HWInfo table is in the process of being updated, the low bit of - * version will be set. - * - * HWInfo v1 Key/Value Table - * ------------------------- - * - * The key/value table is a set of offsets to ASCIIZ strings which have - * been strcmp(3) sorted (yes, please use bsearch(3) on the table). - * - * All keys are guaranteed to be unique. - * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value - * ... - * - * HWInfo v2 Key/Value Table - * ------------------------- - * - * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * Unsorted. - * - * Note: Only the HwInfo v2 Table be supported now. - */ - -#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) - -struct nfp_hwinfo { - uint8_t start[0]; - - uint32_t version; - uint32_t size; - - /* v2 specific fields */ - uint32_t limit; - uint32_t resv; - - char data[]; -}; +struct nfp_hwinfo; struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 12/26] net/nfp: refact the nffw module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (10 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 11/26] net/nfp: refact the hwinfo module Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:45 ` [PATCH v4 13/26] net/nfp: refact the mip module Chaoyong He ` (16 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Move the definition of data structure and macro into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.h | 4 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 105 +++++++++++++++++++---------- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +----------------- 3 files changed, 72 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 7fa09ee575..dbd9af31ed 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -6,7 +6,7 @@ #ifndef __NFP_MIP_H__ #define __NFP_MIP_H__ -#include "nfp_nffw.h" +#include "nfp_cpp.h" struct nfp_mip; @@ -16,7 +16,5 @@ void nfp_mip_close(struct nfp_mip *mip); const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); -int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index df6292e909..2f07fcd6c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,12 +3,76 @@ * All rights reserved. */ -#include "../nfp_logs.h" -#include "nfp_cpp.h" #include "nfp_nffw.h" + +#include "../nfp_logs.h" #include "nfp_mip.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" +#include "nfp6000/nfp6000.h" + +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. + * Lower IDs are reserved for target and loader IDs. + */ +#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ +#define NFFW_FWID_BASE 4 + +#define NFFW_FWID_ALL 255 + +/* + * NFFW_INFO_VERSION history: + * 0: This was never actually used (before versioning), but it refers to + * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later + * changed to 200. + * 1: First versioned struct, with + * FWINFO_CNT = 120 + * MEINFO_CNT = 120 + * 2: FWINFO_CNT = 200 + * MEINFO_CNT = 200 + */ +#define NFFW_INFO_VERSION_CURRENT 2 + +/* Enough for all current chip families */ +#define NFFW_MEINFO_CNT_V1 120 +#define NFFW_FWINFO_CNT_V1 120 +#define NFFW_MEINFO_CNT_V2 200 +#define NFFW_FWINFO_CNT_V2 200 + +/* nfp.nffw meinfo */ +struct nffw_meinfo { + uint32_t ctxmask_fwid_meid; +}; + +struct nffw_fwinfo { + uint32_t loaded_mu_da_mip_off_hi; + uint32_t mip_cppid; /**< 0 means no MIP */ + uint32_t mip_offset_lo; +}; + +struct nfp_nffw_info_v1 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; +}; + +struct nfp_nffw_info_v2 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; +}; + +struct nfp_nffw_info_data { + uint32_t flags[2]; + union { + struct nfp_nffw_info_v1 v1; + struct nfp_nffw_info_v2 v2; + } info; +}; + +struct nfp_nffw_info { + struct nfp_cpp *cpp; + struct nfp_resource *res; + + struct nfp_nffw_info_data fwinf; +}; /* * flg_info_version = flags[0]<27:16> @@ -61,32 +125,6 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) - -static int -nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) -{ - int err; - uint32_t mode; - uint32_t addr40; - uint32_t xpbaddr; - uint32_t imbcppat; - - /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; - err = nfp_xpb_readl(cpp, xpbaddr, &imbcppat); - if (err < 0) - return err; - - mode = NFP_IMB_TGTADDRESSMODECFG_MODE_of(imbcppat); - addr40 = !!(imbcppat & NFP_IMB_TGTADDRESSMODECFG_ADDRMODE); - - return nfp_cppat_mu_locality_lsb(mode, addr40); -} - static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) @@ -239,14 +277,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { - int locality_off; - - if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) - return 0; - - locality_off = nfp_mip_mu_locality_lsb(state->cpp); - if (locality_off < 0) - return locality_off; + int locality_off = nfp_cpp_mu_locality_lsb(state->cpp); *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 52e25c090a..fd46009d37 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,71 +8,11 @@ #include "nfp_cpp.h" -/* - * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. - * Lower IDs are reserved for target and loader IDs. - */ -#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ -#define NFFW_FWID_BASE 4 - -#define NFFW_FWID_ALL 255 - -/* - * NFFW_INFO_VERSION history: - * 0: This was never actually used (before versioning), but it refers to - * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later - * changed to 200. - * 1: First versioned struct, with - * FWINFO_CNT = 120 - * MEINFO_CNT = 120 - * 2: FWINFO_CNT = 200 - * MEINFO_CNT = 200 - */ -#define NFFW_INFO_VERSION_CURRENT 2 - -/* Enough for all current chip families */ -#define NFFW_MEINFO_CNT_V1 120 -#define NFFW_FWINFO_CNT_V1 120 -#define NFFW_MEINFO_CNT_V2 200 -#define NFFW_FWINFO_CNT_V2 200 - -/* nfp.nffw meinfo */ -struct nffw_meinfo { - uint32_t ctxmask_fwid_meid; -}; - -struct nffw_fwinfo { - uint32_t loaded_mu_da_mip_off_hi; - uint32_t mip_cppid; /* 0 means no MIP */ - uint32_t mip_offset_lo; -}; - -struct nfp_nffw_info_v1 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; -}; - -struct nfp_nffw_info_v2 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; -}; - -struct nfp_nffw_info_data { - uint32_t flags[2]; - union { - struct nfp_nffw_info_v1 v1; - struct nfp_nffw_info_v2 v2; - } info; -}; - -struct nfp_nffw_info { - struct nfp_cpp *cpp; - struct nfp_resource *res; - - struct nfp_nffw_info_data fwinf; -}; +struct nfp_nffw_info; struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); +int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, + uint64_t *offset); #endif /* __NFP_NFFW_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 13/26] net/nfp: refact the mip module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (11 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 12/26] net/nfp: refact the nffw module Chaoyong He @ 2023-09-18 2:45 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 14/26] net/nfp: refact the rtsym module Chaoyong He ` (15 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:45 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 7f06c24927..d5ada3687a 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -3,12 +3,11 @@ * All rights reserved. */ -#include <stdio.h> +#include "nfp_mip.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_mip.h" #include "nfp_nffw.h" #define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 14/26] net/nfp: refact the rtsym module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (12 preceding siblings ...) 2023-09-18 2:45 ` [PATCH v4 13/26] net/nfp: refact the mip module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 15/26] net/nfp: refact the resource module Chaoyong He ` (14 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include <stdio.h> +#include "nfp_rtsym.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ 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); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 15/26] net/nfp: refact the resource module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (13 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 14/26] net/nfp: refact the rtsym module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 16/26] net/nfp: refact the target module Chaoyong He ` (13 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_resource.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 54bcc5f234..c0afdbfdd2 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -3,15 +3,11 @@ * All rights reserved. */ -#include <stdio.h> -#include <time.h> -#include <endian.h> +#include "nfp_resource.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" #include "nfp6000/nfp6000.h" -#include "nfp_resource.h" -#include "nfp_crc.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL @@ -43,7 +39,7 @@ struct nfp_resource_entry { }; #define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ +#define NFP_RESOURCE_TBL_ENTRIES (NFP_RESOURCE_TBL_SIZE / \ sizeof(struct nfp_resource_entry)) struct nfp_resource { @@ -175,8 +171,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - free(res); - return NULL; + goto err_free; } wait.tv_sec = 0; @@ -188,13 +183,12 @@ nfp_resource_acquire(struct nfp_cpp *cpp, break; if (err != -EBUSY) { PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); - goto err_free; + goto mutex_free; } if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); - err = -EBUSY; - goto err_free; + goto mutex_free; } nanosleep(&wait, NULL); @@ -204,8 +198,9 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return res; -err_free: +mutex_free: nfp_cpp_mutex_free(dev_mutex); +err_free: free(res); return NULL; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 16/26] net/nfp: refact the target module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (14 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 15/26] net/nfp: refact the resource module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 17/26] net/nfp: add a new header file Chaoyong He ` (12 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Move the function declaration into the header file, and sync some logic from kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 -------------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 1 + drivers/net/nfp/nfpcore/nfp_cppcore.c | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 - drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 1 + drivers/net/nfp/nfpcore/nfp_target.c | 7 ++++--- drivers/net/nfp/nfpcore/nfp_target.h | 22 ++++++++++++++++++++++ 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index efaa87c0e5..4c9ac017cc 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -6,21 +6,6 @@ #ifndef __NFP_NFP6000_H__ #define __NFP_NFP6000_H__ -/* CPP Target IDs */ -#define NFP_CPP_TARGET_INVALID 0 -#define NFP_CPP_TARGET_NBI 1 -#define NFP_CPP_TARGET_QDR 2 -#define NFP_CPP_TARGET_ILA 6 -#define NFP_CPP_TARGET_MU 7 -#define NFP_CPP_TARGET_PCIE 9 -#define NFP_CPP_TARGET_ARM 10 -#define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ -#define NFP_CPP_TARGET_CT_XPB 14 -#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 -#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH - #define NFP_ISL_EMEM0 24 #define NFP_MU_ADDR_ACCESS_TYPE_MASK 3ULL @@ -52,9 +37,4 @@ nfp_cppat_mu_locality_lsb(int mode, int addr40) } } -int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); -int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table); - #endif /* NFP_NFP6000_H */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index db15411eb2..310cc691cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -34,6 +34,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7173b4d8a5..41485b6975 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -16,6 +16,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82598be7a1..96ba60697c 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -9,7 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) #define MUTEX_UNLOCK(interface) (0 | 0x0000) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 32c1838a40..36bd49d659 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,7 +9,6 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp6000/nfp6000.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index c0afdbfdd2..539eb69680 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,7 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 2d4100dda2..022753f98a 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -14,6 +14,7 @@ #include "nfp_logs.h" #include "nfp_mip.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" enum nfp_rtsym_type { diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 540b242a43..ecb45f7928 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -3,6 +3,8 @@ * All rights reserved. */ +#include "nfp_target.h" + #include "nfp_cpp.h" #include "nfp6000/nfp6000.h" @@ -315,8 +317,7 @@ nfp6000_mu(uint32_t cpp_id, } else if (island == 1 || (island >= 4 && island <= 7) || (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { + (island >= 32 && island <= 51)) { pp = nfp6000_mu_ctm(cpp_id); } else { pp = -EINVAL; @@ -510,7 +511,7 @@ nfp_target_pushpull(uint32_t cpp_id, return nfp6000_cap_xpb(cpp_id); case NFP_CPP_TARGET_CLS: return nfp6000_cls(cpp_id); - case 0: + case NFP_CPP_TARGET_INVALID: return target_rw(cpp_id, P32, 4, 4); default: return -EINVAL; diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 2a2f083914..47527b4040 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,4 +6,26 @@ #ifndef __NFP_TARGET_H__ #define __NFP_TARGET_H__ +#include <stdint.h> + +/* CPP Target IDs */ +#define NFP_CPP_TARGET_INVALID 0 +#define NFP_CPP_TARGET_NBI 1 +#define NFP_CPP_TARGET_QDR 2 +#define NFP_CPP_TARGET_ILA 6 +#define NFP_CPP_TARGET_MU 7 +#define NFP_CPP_TARGET_PCIE 9 +#define NFP_CPP_TARGET_ARM 10 +#define NFP_CPP_TARGET_CRYPTO 12 +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_CT_XPB 14 +#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 +#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH + +int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); +int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, + uint32_t *cpp_target_id, uint64_t *cpp_target_address, + const uint32_t *imb_table); + #endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 17/26] net/nfp: add a new header file 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (15 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 16/26] net/nfp: refact the target module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 18/26] net/nfp: refact the nsp module Chaoyong He ` (11 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Split out the macro which are not easily find a DPDK substitute into a new header file. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_nsp.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp.h | 23 -------------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 + drivers/net/nfp/nfpcore/nfp_platform.h | 42 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index ca3fc2fa59..0f67148907 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -13,6 +13,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #include "nfp_resource.h" int diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 705574b900..14986a9130 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -9,29 +9,6 @@ #include "nfp_cpp.h" #include "nfp_nsp.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - /* Offsets relative to the CSR base */ #define NSP_STATUS 0x00 #define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 36bd49d659..eb30d8e779 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,6 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_platform.h b/drivers/net/nfp/nfpcore/nfp_platform.h new file mode 100644 index 0000000000..fcac6b05ff --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_platform.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_PLATFORM_H__ +#define __NFP_PLATFORM_H__ + +#include <stdint.h> + +#define DMA_BIT_MASK(n) ((1ULL << (n)) - 1) + +#define BITS_PER_LONG (__SIZEOF_LONG__ * 8) +#define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8) + +#define GENMASK(h, l) \ + ((~0UL << (l)) & (~0UL >> (BITS_PER_LONG - (h) - 1))) + +#define GENMASK_ULL(h, l) \ + ((~0ULL << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - (h) - 1))) + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define FIELD_GET(_mask, _reg) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + })) + +#define FIELD_FIT(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ + })) + +#define FIELD_PREP(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + })) + +#endif /* __NFP_PLATFORM_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 18/26] net/nfp: refact the nsp module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (16 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 17/26] net/nfp: add a new header file Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 19/26] net/nfp: refact the mutex module Chaoyong He ` (10 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Move the definition of data structure into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 390 +++++++++++++++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 140 ++++----- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 - drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 79 ++--- 5 files changed, 398 insertions(+), 217 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e3ff3d8087..efb47c5d56 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -661,7 +661,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev) static int nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) { - struct nfp_cpp *cpp = nsp->cpp; + struct nfp_cpp *cpp = nfp_nsp_cpp(nsp); void *fw_buf; char fw_name[125]; char serial[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 0f67148907..e9b3fc3945 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -3,20 +3,127 @@ * All rights reserved. */ -#define NFP_SUBSYS "nfp_nsp" - -#include <stdio.h> -#include <time.h> +#include "nfp_nsp.h" #include <rte_common.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_nsp.h" #include "nfp_platform.h" #include "nfp_resource.h" -int +/* Offsets relative to the CSR base */ +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_DMA_BUF RTE_BIT64(1) +#define NSP_COMMAND_START RTE_BIT64(0) + +/* CPP address to retrieve the data from */ +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) + +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 + +#define NSP_CODE_MAJOR GENMASK_ULL(15, 12) +#define NSP_CODE_MINOR GENMASK_ULL(11, 0) + +#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8) +#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16) + +enum nfp_nsp_cmd { + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */ + SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */ + SPCODE_HWINFO_SET = 18, /* Set HWinfo entry */ + SPCODE_FW_LOADED = 19, /* Is application firmware loaded */ + SPCODE_VERSIONS = 21, /* Report FW versions */ + SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */ + SPCODE_READ_MEDIA = 23, /* Get the supported/advertised media for a port */ +}; + +static const struct { + uint32_t code; + const char *msg; +} nsp_errors[] = { + { 6010, "could not map to phy for port" }, + { 6011, "not an allowed rate/lanes for port" }, + { 6012, "not an allowed rate/lanes for port" }, + { 6013, "high/low error, change other port first" }, + { 6014, "config not found in flash" }, +}; + +struct nfp_nsp { + struct nfp_cpp *cpp; + struct nfp_resource *res; + struct { + uint16_t major; + uint16_t minor; + } ver; + + /** Eth table config state */ + bool modified; + uint32_t idx; + void *entries; +}; + +/* NFP command argument structure */ +struct nfp_nsp_command_arg { + uint16_t code; /**< NFP SP Command Code */ + bool dma; /**< @buf points to a host buffer, not NSP buffer */ + bool error_quiet; /**< Don't print command error/warning */ + uint32_t timeout_sec; /**< Timeout value to wait for completion in seconds */ + uint32_t option; /**< NSP Command Argument */ + uint64_t buf; /**< NSP Buffer Address */ + /** Callback for interpreting option if error occurred */ + void (*error_cb)(struct nfp_nsp *state, uint32_t ret_val); +}; + +/* NFP command with buffer argument structure */ +struct nfp_nsp_command_buf_arg { + struct nfp_nsp_command_arg arg; /**< NFP command argument structure */ + const void *in_buf; /**< Buffer with data for input */ + void *out_buf; /**< Buffer for output data */ + uint32_t in_size; /**< Size of @in_buf */ + uint32_t out_size; /**< Size of @out_buf */ +}; + +struct nfp_cpp * +nfp_nsp_cpp(struct nfp_nsp *state) +{ + return state->cpp; +} + +bool nfp_nsp_config_modified(struct nfp_nsp *state) { return state->modified; @@ -24,7 +131,7 @@ nfp_nsp_config_modified(struct nfp_nsp *state) void nfp_nsp_config_set_modified(struct nfp_nsp *state, - int modified) + bool modified) { state->modified = modified; } @@ -66,7 +173,7 @@ nfp_nsp_print_extended_error(uint32_t ret_val) return; for (i = 0; i < RTE_DIM(nsp_errors); i++) - if (ret_val == (uint32_t)nsp_errors[i].code) + if (ret_val == nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -222,11 +329,8 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, - uint16_t code, - uint32_t option, - uint32_t buff_cpp, - uint64_t buff_addr) +nfp_nsp_command_real(struct nfp_nsp *state, + const struct nfp_nsp_command_arg *arg) { int err; uint64_t reg; @@ -250,22 +354,14 @@ nfp_nsp_command(struct nfp_nsp *state, return err; } - if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { - PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); - return -EINVAL; - } - - err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, arg->buf); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_OPTION, arg->option) | + FIELD_PREP(NSP_COMMAND_CODE, arg->code) | + FIELD_PREP(NSP_COMMAND_DMA_BUF, arg->dma) | FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; @@ -275,7 +371,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", - err, code); + err, arg->code); return err; } @@ -284,7 +380,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", - err, code); + err, arg->code); return err; } @@ -296,84 +392,85 @@ nfp_nsp_command(struct nfp_nsp *state, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { - PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); - nfp_nsp_print_extended_error(ret_val); + if (!arg->error_quiet) + PMD_DRV_LOG(WARNING, "Result (error) code set: %d (%d) command: %d", + -err, (int)ret_val, arg->code); + + if (arg->error_cb != 0) + arg->error_cb(state, ret_val); + else + nfp_nsp_print_extended_error(ret_val); + return -err; } return ret_val; } -#define SZ_1M 0x00100000 +static int +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code) +{ + const struct nfp_nsp_command_arg arg = { + .code = code, + }; + + return nfp_nsp_command_real(state, &arg); +} static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, - uint16_t code, uint32_t option, - const void *in_buf, - unsigned int in_size, - void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf_def(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) { int err; int ret; uint64_t reg; - size_t max_size; uint32_t cpp_id; uint64_t cpp_buf; struct nfp_cpp *cpp = nsp->cpp; - if (nsp->ver.minor < 13) { - PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); - return -EOPNOTSUPP; - } - - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, - ®); - if (err < 0) - return err; - - max_size = RTE_MAX(in_size, out_size); - if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %zu)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); - return -EINVAL; - } - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, ®); if (err < 0) return err; - cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; - cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); + cpp_id = FIELD_GET(NSP_DFLT_BUFFER_CPP, reg) << 8; + cpp_buf = FIELD_GET(NSP_DFLT_BUFFER_ADDRESS, reg); - if (in_buf != NULL && in_size > 0) { - err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); + if (arg->in_buf != NULL && arg->in_size > 0) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf, + arg->in_buf, arg->in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf != NULL && out_size > 0 && out_size > in_size) { - memset(out_buf, 0, out_size - in_size); - err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + if (arg->out_buf != NULL && arg->out_size > arg->in_size) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf + arg->in_size, + arg->out_buf, arg->out_size - arg->in_size); if (err < 0) return err; } - ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); + if (!FIELD_FIT(NSP_BUFFER_CPP, cpp_id >> 8) || + !FIELD_FIT(NSP_BUFFER_ADDRESS, cpp_buf)) { + PMD_DRV_LOG(ERR, "Buffer out of reach %#08x %#016lx", + cpp_id, cpp_buf); + return -EINVAL; + } + + arg->arg.buf = FIELD_PREP(NSP_BUFFER_CPP, cpp_id >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf); + ret = nfp_nsp_command_real(nsp, &arg->arg); if (ret < 0) { PMD_DRV_LOG(ERR, "NSP command failed"); return ret; } - if (out_buf != NULL && out_size > 0) { - err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); + if (arg->out_buf != NULL && arg->out_size > 0) { + err = nfp_cpp_read(cpp, cpp_id, cpp_buf, + arg->out_buf, arg->out_size); if (err < 0) return err; } @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, return ret; } +#define SZ_1M 0x00100000 +#define SZ_4K 0x00001000 + +static int +nfp_nsp_command_buf(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) +{ + int err; + uint64_t reg; + uint32_t size; + uint32_t max_size; + struct nfp_cpp *cpp = nsp->cpp; + + if (nsp->ver.minor < 13) { + PMD_DRV_LOG(ERR, "NSP: Code %#04x with buffer not supported ABI %hu.%hu)", + arg->arg.code, nsp->ver.major, nsp->ver.minor); + return -EOPNOTSUPP; + } + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); + if (err < 0) + return err; + + max_size = RTE_MAX(arg->in_size, arg->out_size); + size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; + if (size < max_size) { + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%u < %u)", + arg->arg.code, size, max_size); + return -EINVAL; + } + + return nfp_nsp_command_buf_def(nsp, arg); +} + int nfp_nsp_wait(struct nfp_nsp *state) { @@ -392,7 +526,7 @@ nfp_nsp_wait(struct nfp_nsp *state) wait.tv_nsec = 25000000; /* 25ms */ for (;;) { - err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); + err = nfp_nsp_command(state, SPCODE_NOOP); if (err != -EAGAIN) break; @@ -413,13 +547,57 @@ nfp_nsp_wait(struct nfp_nsp *state) int nfp_nsp_device_soft_reset(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_SOFT_RESET, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_SOFT_RESET); } int nfp_nsp_mac_reinit(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_MAC_INIT, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_MAC_INIT); +} + +static void +nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, + uint32_t ret_val) +{ + uint32_t minor; + uint32_t major; + static const char * const major_msg[] = { + /* 0 */ "Firmware from driver loaded", + /* 1 */ "Firmware from flash loaded", + /* 2 */ "Firmware loading failure", + }; + static const char * const minor_msg[] = { + /* 0 */ "", + /* 1 */ "no named partition on flash", + /* 2 */ "error reading from flash", + /* 3 */ "can not deflate", + /* 4 */ "not a trusted file", + /* 5 */ "can not parse FW file", + /* 6 */ "MIP not found in FW file", + /* 7 */ "null firmware name in MIP", + /* 8 */ "FW version none", + /* 9 */ "FW build number none", + /* 10 */ "no FW selection policy HWInfo key found", + /* 11 */ "static FW selection policy", + /* 12 */ "FW version has precedence", + /* 13 */ "different FW application load requested", + /* 14 */ "development build", + }; + + major = FIELD_GET(NFP_FW_LOAD_RET_MAJOR, ret_val); + minor = FIELD_GET(NFP_FW_LOAD_RET_MINOR, ret_val); + + if (!nfp_nsp_has_stored_fw_load(state)) + return; + + if (major >= RTE_DIM(major_msg)) + PMD_DRV_LOG(INFO, "FW loading status: %x", ret_val); + else if (minor >= RTE_DIM(minor_msg)) + PMD_DRV_LOG(INFO, "%s, reason code: %d", major_msg[major], minor); + else + PMD_DRV_LOG(INFO, "%s%c %s", major_msg[major], + minor != 0 ? ',' : '.', minor_msg[minor]); } int @@ -427,8 +605,24 @@ nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + int ret; + struct nfp_nsp_command_buf_arg load_fw = { + { + .code = SPCODE_FW_LOAD, + .option = size, + .error_cb = nfp_nsp_load_fw_extended_msg, + }, + .in_buf = buf, + .in_size = size, + }; + + ret = nfp_nsp_command_buf(state, &load_fw); + if (ret < 0) + return ret; + + nfp_nsp_load_fw_extended_msg(state, ret); + + return 0; } int @@ -436,8 +630,16 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg eth_rescan = { + { + .code = SPCODE_ETH_RESCAN, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, ð_rescan); } int @@ -445,8 +647,16 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + struct nfp_nsp_command_buf_arg eth_ctrl = { + { + .code = SPCODE_ETH_CONTROL, + .option = size, + }, + .in_buf = buf, + .in_size = size, + }; + + return nfp_nsp_command_buf(state, ð_ctrl); } int @@ -454,8 +664,16 @@ nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg identify = { + { + .code = SPCODE_NSP_IDENTIFY, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &identify); } int @@ -464,6 +682,14 @@ nfp_nsp_read_sensors(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + struct nfp_nsp_command_buf_arg sensors = { + { + .code = SPCODE_NSP_SENSORS, + .option = sensor_mask, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &sensors); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 14986a9130..fe52dffeb7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -7,78 +7,8 @@ #define __NSP_NSP_H__ #include "nfp_cpp.h" -#include "nfp_nsp.h" - -/* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) - -/* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) - -#define NSP_DFLT_BUFFER 0x18 - -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) - -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 - -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) - -enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ -}; - -static const struct { - int code; - const char *msg; -} nsp_errors[] = { - { 6010, "could not map to phy for port" }, - { 6011, "not an allowed rate/lanes for port" }, - { 6012, "not an allowed rate/lanes for port" }, - { 6013, "high/low error, change other port first" }, - { 6014, "config not found in flash" }, -}; -struct nfp_nsp { - struct nfp_cpp *cpp; - struct nfp_resource *res; - struct { - uint16_t major; - uint16_t minor; - } ver; - - /* Eth table config state */ - int modified; - unsigned int idx; - void *entries; -}; +struct nfp_nsp; struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); void nfp_nsp_close(struct nfp_nsp *state); @@ -92,18 +22,61 @@ int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, void *buf, size_t size); -static inline int +static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } +static inline bool +nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 23; +} + +static inline bool +nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 24; +} + +static inline bool +nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_fw_loaded(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_versions(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 27; +} + +static inline bool +nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 28; +} + +static inline bool +nfp_nsp_has_read_media(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 33; +} + enum nfp_eth_interface { NFP_INTERFACE_NONE = 0, NFP_INTERFACE_SFP = 1, NFP_INTERFACE_SFPP = 10, NFP_INTERFACE_SFP28 = 28, NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_RJ45 = 45, NFP_INTERFACE_CXP = 100, NFP_INTERFACE_QSFP28 = 112, }; @@ -151,6 +124,7 @@ struct nfp_eth_table { enum nfp_eth_media media; /**< Media type of the @interface */ enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ struct rte_ether_addr mac_addr; /**< Interface MAC address */ @@ -159,17 +133,18 @@ struct nfp_eth_table { /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; /**< Enable port */ - int tx_enabled; /**< Enable TX */ - int rx_enabled; /**< Enable RX */ + bool enabled; /**< Enable port */ + bool tx_enabled; /**< Enable TX */ + bool rx_enabled; /**< Enable RX */ + bool supp_aneg; /**< Support auto negotiation */ - int override_changed; /**< Media reconfig pending */ + bool override_changed; /**< Media reconfig pending */ uint8_t port_type; /**< One of %PORT_* */ /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; /**< Split port */ + bool is_split; /**< Split port */ uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ } ports[]; /**< Table of ports */ @@ -177,8 +152,8 @@ struct nfp_eth_table { struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); @@ -187,12 +162,13 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); -void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); +void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); -int nfp_nsp_config_modified(struct nfp_nsp *state); +struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); +bool nfp_nsp_config_modified(struct nfp_nsp *state); uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int +static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported != 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index f656f200f4..46fa5467de 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -3,12 +3,8 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp_nffw.h" struct nsp_identify { uint8_t version[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index eb30d8e779..cc472907ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -3,10 +3,6 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_common.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" #include "nfp_platform.h" @@ -21,6 +17,7 @@ #define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) #define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) #define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) +#define NSP_ETH_PORT_SUPP_ANEG RTE_BIT64(63) #define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) @@ -34,6 +31,7 @@ #define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) #define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) #define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) +#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28) #define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) #define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) @@ -54,26 +52,12 @@ #define PORT_NONE 0xef #define PORT_OTHER 0xff -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 - enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW + NSP_ETH_NUM_RAW, }; enum nfp_eth_rate { @@ -100,12 +84,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, RTE_ETH_SPEED_NUM_NONE, }, + { RATE_10M, RTE_ETH_SPEED_NUM_10M, }, + { RATE_100M, RTE_ETH_SPEED_NUM_100M, }, + { RATE_1G, RTE_ETH_SPEED_NUM_1G, }, + { RATE_10G, RTE_ETH_SPEED_NUM_10G, }, + { RATE_25G, RTE_ETH_SPEED_NUM_25G, }, }; static uint32_t @@ -193,7 +177,14 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; - dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->fec = FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->act_fec = dst->fec; + + if (nfp_nsp_get_abi_ver_minor(nsp) < 33) + return; + + dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state); + dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port); } static void @@ -222,7 +213,7 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) table->ports[i].label_port, table->ports[i].label_subport); - table->ports[i].is_split = 1; + table->ports[i].is_split = true; } } } @@ -233,6 +224,9 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) if (entry->interface == NFP_INTERFACE_NONE) { entry->port_type = PORT_NONE; return; + } else if (entry->interface == NFP_INTERFACE_RJ45) { + entry->port_type = PORT_TP; + return; } if (entry->media == NFP_MEDIA_FIBRE) @@ -251,7 +245,6 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) uint32_t table_sz; struct nfp_eth_table *table; union eth_table_entry *entries; - const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -264,16 +257,9 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) goto err; } - /* - * The NFP3800 NIC support 8 ports, but only 2 ports are valid, - * the rest 6 ports mac are all 0, ensure we don't use these port - */ - for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) + for (i = 0; i < NSP_ETH_MAX_COUNT; i++) + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) cnt++; - } /* * Some versions of flash will give us 0 instead of port count. For @@ -294,11 +280,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) memset(table, 0, table_sz); table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) - nfp_eth_port_translate(nsp, &entries[i], i, - &table->ports[j++]); + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) + nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); } nfp_eth_calc_port_geometry(table); @@ -440,7 +423,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, - int enable) + bool enable) { uint64_t reg; struct nfp_nsp *nsp; @@ -448,7 +431,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) - return -1; + return -EIO; entries = nfp_nsp_config_entries(nsp); @@ -460,7 +443,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_ENABLED, enable); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -484,7 +467,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configured) + bool configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -513,7 +496,7 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -551,7 +534,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, entries[idx].control |= rte_cpu_to_le_64(ctrl_bit); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 19/26] net/nfp: refact the mutex module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (17 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 18/26] net/nfp: refact the nsp module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 20/26] net/nfp: rename data field to sync with kernel driver Chaoyong He ` (9 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Add a header file to holds the API declarations of this module. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 16 -- drivers/net/nfp/nfpcore/nfp_mutex.c | 205 ++++++++++++++----------- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 +++ drivers/net/nfp/nfpcore/nfp_resource.c | 1 + 4 files changed, 138 insertions(+), 109 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index be7ae1d919..42c4df5fdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -8,8 +8,6 @@ #include <ethdev_pci.h> -struct nfp_cpp_mutex; - /* NFP CPP handle */ struct nfp_cpp { uint32_t model; @@ -426,20 +424,6 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); - uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); #endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 96ba60697c..3c10c7a090 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -3,21 +3,13 @@ * All rights reserved. */ -#include <malloc.h> -#include <time.h> +#include "nfp_mutex.h" + #include <sched.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" -#define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) -#define MUTEX_UNLOCK(interface) (0 | 0x0000) - -#define MUTEX_IS_LOCKED(value) (((value) & 0xffff) == 0x000f) -#define MUTEX_IS_UNLOCKED(value) (((value) & 0xffff) == 0x0000) -#define MUTEX_INTERFACE(value) (((value) >> 16) & 0xffff) - /* * If you need more than 65536 recursive locks, please * rethink your code. @@ -34,21 +26,51 @@ struct nfp_cpp_mutex { struct nfp_cpp_mutex *prev, *next; }; +static inline uint32_t +nfp_mutex_locked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x000f; +} + +static inline uint32_t +nfp_mutex_unlocked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x0000; +} + +static inline uint16_t +nfp_mutex_owner(uint32_t val) +{ + return (val >> 16) & 0xffff; +} + +static inline bool +nfp_mutex_is_locked(uint32_t val) +{ + return (val & 0xffff) == 0x000f; +} + +static inline bool +nfp_mutex_is_unlocked(uint32_t val) +{ + return (val & 0xffff) == 0; +} + static int -nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint16_t interface, int *target, uint64_t address) { + /* Not permitted on invalid interfaces */ + if (NFP_CPP_INTERFACE_TYPE_of(interface) == NFP_CPP_INTERFACE_TYPE_INVALID) + return -EINVAL; + /* Address must be 64-bit aligned */ if ((address & 7) != 0) return -EINVAL; - if (NFP_CPP_MODEL_IS_6000(model)) { - if (*target != NFP_CPP_TARGET_MU) - return -EINVAL; - } else { + if (*target != NFP_CPP_TARGET_MU) return -EINVAL; - } return 0; } @@ -84,10 +106,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t key) { int err; - uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint16_t interface = nfp_cpp_interface(cpp); - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return err; @@ -95,8 +117,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, if (err < 0) return err; - err = nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface)); if (err < 0) return err; @@ -133,26 +154,10 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int err; uint32_t tmp; struct nfp_cpp_mutex *mutex; - uint32_t model = nfp_cpp_model(cpp); uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint16_t interface = nfp_cpp_interface(cpp); - /* Look for cached mutex */ - for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { - if (mutex->target == target && mutex->address == address) - break; - } - - if (mutex) { - if (mutex->key == key) { - mutex->usage++; - return mutex; - } - - /* If the key doesn't match... */ - return NULL; - } - - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return NULL; @@ -172,16 +177,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, mutex->address = address; mutex->key = key; mutex->depth = 0; - mutex->usage = 1; - - /* Add mutex to the cache */ - if (cpp->mutex_cache) { - cpp->mutex_cache->prev = mutex; - mutex->next = cpp->mutex_cache; - cpp->mutex_cache = mutex; - } else { - cpp->mutex_cache = mutex; - } return mutex; } @@ -195,20 +190,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) { - mutex->usage--; - if (mutex->usage > 0) - return; - - /* Remove mutex from the cache */ - if (mutex->next) - mutex->next->prev = mutex->prev; - if (mutex->prev) - mutex->prev->next = mutex->next; - - /* If mutex->cpp == NULL, something broke */ - if (mutex->cpp && mutex == mutex->cpp->mutex_cache) - mutex->cpp->mutex_cache = mutex->next; - free(mutex); } @@ -268,32 +249,28 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return 0; } - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - goto exit; - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; - if (value != MUTEX_LOCKED(interface)) { - err = -EACCES; - goto exit; - } + err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); + if (err < 0) + return err; + + if (value != nfp_mutex_locked(interface)) + return -EACCES; - err = nfp_cpp_writel(cpp, muw, mutex->address, MUTEX_UNLOCK(interface)); + err = nfp_cpp_writel(cpp, muw, mutex->address, + nfp_mutex_unlocked(interface)); if (err < 0) - goto exit; + return err; mutex->depth = 0; -exit: - return err; + return 0; } /** @@ -332,19 +309,17 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) /* Verify that the lock marker is not damaged */ err = nfp_cpp_readl(cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; /* * Compare against the unlocked state, and if true, * write the interface id into the top 16 bits, and * mark as locked. */ - value = MUTEX_LOCKED(nfp_cpp_interface(cpp)); + value = nfp_mutex_locked(nfp_cpp_interface(cpp)); /* * We use test_set_imm here, as it implies a read @@ -361,10 +336,10 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_readl(cpp, mus, mutex->address, &tmp); if (err < 0) - goto exit; + return err; /* Was it unlocked? */ - if (MUTEX_IS_UNLOCKED(tmp)) { + if (nfp_mutex_is_unlocked(tmp)) { /* * The read value can only be 0x....0000 in the unlocked state. * If there was another contending for this lock, then @@ -376,20 +351,64 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_writel(cpp, muw, mutex->address, value); if (err < 0) - goto exit; + return err; mutex->depth = 1; - goto exit; + return 0; } /* Already locked by us? Success! */ if (tmp == value) { mutex->depth = 1; - goto exit; + return 0; } - err = MUTEX_IS_LOCKED(tmp) ? -EBUSY : -EINVAL; + return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL; +} + +/** + * Release lock if held by local system. + * Extreme care is advised, call only when no local lock users can exist. + * + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * + * @return + * - (0) if the lock was OK + * - (1) if locked by us + * - (-errno) on invalid mutex + */ +int +nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, + int target, + uint64_t address) +{ + int err; + uint32_t tmp; + uint16_t interface = nfp_cpp_interface(cpp); + const uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + const uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + + err = nfp_cpp_mutex_validate(interface, &target, address); + if (err != 0) + return err; + + /* Check lock */ + err = nfp_cpp_readl(cpp, mur, address, &tmp); + if (err < 0) + return err; + + if (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface) + return 0; + + /* Bust the lock */ + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface)); + if (err < 0) + return err; -exit: - return err; + return 1; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.h b/drivers/net/nfp/nfpcore/nfp_mutex.h new file mode 100644 index 0000000000..a79490b4d6 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_mutex.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_MUTEX_H__ +#define __NFP_MUTEX_H__ + +#include "nfp_cpp.h" + +struct nfp_cpp_mutex; + +int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target, uint64_t address); + +#endif /* __NFP_MUTEX_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 539eb69680..d59d2d6c1e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,6 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" +#include "nfp_mutex.h" #include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 20/26] net/nfp: rename data field to sync with kernel driver 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (18 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 19/26] net/nfp: refact the mutex module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 21/26] net/nfp: add the dev module Chaoyong He ` (8 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Rename the data fields to sync with the logic in kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +++--- drivers/net/nfp/nfp_common.h | 4 ++-- drivers/net/nfp/nfp_ethdev.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 77dab864f3..fead917599 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -224,7 +224,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -360,8 +360,8 @@ nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type) start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ; - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; /* Set the current MTU to the maximum supported */ hw->mtu = hw->max_mtu; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 1ce51d44d4..86c4e10040 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -123,9 +123,9 @@ struct nfp_pf_dev { struct nfp_cpp *cpp; struct nfp_cpp_area *ctrl_area; - struct nfp_cpp_area *hwqueues_area; + struct nfp_cpp_area *qc_area; - uint8_t *hw_queues; + uint8_t *qc_bar; struct nfp_hwinfo *hwinfo; struct nfp_rtsym_table *sym_tbl; diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index efb47c5d56..899d4dd253 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -311,7 +311,7 @@ nfp_net_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -593,8 +593,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -995,16 +995,16 @@ nfp_pf_init(struct rte_pci_device *pci_dev) } cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); - pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, cpp_id, + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, addr, NFP_QCP_QUEUE_AREA_SZ, - &pf_dev->hwqueues_area); - if (pf_dev->hw_queues == NULL) { + &pf_dev->qc_area); + if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; goto pf_cleanup; } - PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues); + PMD_INIT_LOG(DEBUG, "qc_bar address: 0x%p", pf_dev->qc_bar); /* * PF initialization has been done at this point. Call app specific @@ -1041,7 +1041,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) return 0; hwqueues_cleanup: - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); pf_cleanup: rte_free(pf_dev); sym_tbl_cleanup: -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 21/26] net/nfp: add the dev module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (19 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 20/26] net/nfp: rename data field to sync with kernel driver Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 22/26] net/nfp: add header file for PCIe module Chaoyong He ` (7 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Add the nfp_dev module to simplify the logic. The data structure we import can gather and replace several macro which scatter everywhere. Which also make the logic of choose value for different devices unnecessary and so eliminate such logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 1 + drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 ++---------- drivers/net/nfp/nfp_common.h | 48 +++-------- drivers/net/nfp/nfp_ethdev.c | 63 ++++++--------- drivers/net/nfp/nfp_ethdev_vf.c | 17 +--- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 --- drivers/net/nfp/nfpcore/nfp_dev.c | 81 +++++++++++++++++++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 ++++++++++ 13 files changed, 185 insertions(+), 158 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index fead917599..cb72a6a025 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -503,7 +503,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_rx_ring", i, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -558,7 +559,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_tx_ring", i, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 5f94d20f1b..dc6a2c7a9a 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -67,7 +67,8 @@ nfp_pf_repr_rx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -140,7 +141,8 @@ nfp_pf_repr_tx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + hw->pf_dev->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 93c708959c..580a478cd6 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -21,6 +21,7 @@ sources = files( 'nfpcore/nfp_rtsym.c', 'nfpcore/nfp_nsp_cmds.c', 'nfpcore/nfp_crc.c', + 'nfpcore/nfp_dev.c', 'nfpcore/nfp_mutex.c', 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', diff --git a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c index ee39686329..79e1e1041c 100644 --- a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c +++ b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c @@ -262,7 +262,6 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -276,9 +275,7 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfd3_tx_desc); diff --git a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c index f66802211f..48a74d109a 100644 --- a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c +++ b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c @@ -357,7 +357,6 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -371,9 +370,7 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfdk_tx_desc); diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c index 5092e5869d..d6ff4f17ae 100644 --- a/drivers/net/nfp/nfp_common.c +++ b/drivers/net/nfp/nfp_common.c @@ -1146,30 +1146,16 @@ nfp_net_xstats_reset(struct rte_eth_dev *dev) return nfp_net_stats_reset(dev); } -int +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc) { - *max_rx_desc = NFP_NET_MAX_RX_DESC; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_rx_desc = NFP3800_NET_MIN_RX_DESC; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_rx_desc = NFP_NET_MIN_RX_DESC; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_rx_desc = hw->pf_dev->dev_info->max_qc_size; + *min_rx_desc = hw->pf_dev->dev_info->min_qc_size; } -int +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc) @@ -1181,28 +1167,13 @@ nfp_net_tx_desc_limits(struct nfp_net_hw *hw, else tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT; - *max_tx_desc = NFP_NET_MAX_TX_DESC / tx_dpp; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_tx_desc = NFP3800_NET_MIN_TX_DESC / tx_dpp; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_tx_desc = NFP_NET_MIN_TX_DESC / tx_dpp; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_tx_desc = hw->pf_dev->dev_info->max_qc_size / tx_dpp; + *min_tx_desc = hw->pf_dev->dev_info->min_qc_size / tx_dpp; } int nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; uint16_t min_tx_desc; @@ -1211,13 +1182,8 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; - - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues; dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 86c4e10040..5fc9f0ccda 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -7,16 +7,9 @@ #define _NFP_COMMON_H_ #include "nfp_ctrl.h" +#include "nfpcore/nfp_dev.h" #define NFP_NET_PMD_VERSION "0.1" -#define PCI_VENDOR_ID_NETRONOME 0x19ee -#define PCI_VENDOR_ID_CORIGINE 0x1da8 - -#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 -#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 -#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 -#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 -#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ /* Forward declaration */ struct nfp_net_adapter; @@ -28,7 +21,6 @@ struct nfp_net_adapter; #define NFP_NET_CRTL_BAR 0 #define NFP_NET_TX_BAR 2 #define NFP_NET_RX_BAR 2 -#define NFP_QCP_QUEUE_AREA_SZ 0x80000 /* Macros for accessing the Queue Controller Peripheral 'CSRs' */ #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800) @@ -39,17 +31,6 @@ struct nfp_net_adapter; #define NFP_QCP_QUEUE_STS_HI 0x000c #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask (0x3ffff) -#define NFP_PCIE_QCP_NFP3800_OFFSET 0x400000 -#define NFP_PCIE_QCP_NFP6000_OFFSET 0x80000 -#define NFP_PCIE_QUEUE_NFP3800_MASK 0x1ff -#define NFP_PCIE_QUEUE_NFP6000_MASK 0xff -#define NFP_PCIE_QCP_PF_OFFSET 0x0 -#define NFP_PCIE_QCP_VF_OFFSET 0x0 - -/* The offset of the queue controller queues in the PCIe Target */ -#define NFP_PCIE_QUEUE(_offset, _q, _mask) \ - ((_offset) + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & (_mask)))) - /* Interrupt definitions */ #define NFP_NET_IRQ_LSC_IDX 0 @@ -111,6 +92,9 @@ struct nfp_pf_dev { /* Backpointer to associated pci device */ struct rte_pci_device *pci_dev; + /** NFP ASIC params */ + const struct nfp_dev_info *dev_info; + enum nfp_app_fw_id app_fw_id; /* Pointer to the app running on the PF */ @@ -352,23 +336,11 @@ nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr) } static inline uint32_t -nfp_pci_queue(struct rte_pci_device *pdev, uint16_t queue) +nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, + uint16_t queue) { - switch (pdev->id.device_id) { - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - case PCI_DEVICE_ID_NFP3800_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - case PCI_DEVICE_ID_NFP6000_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - default: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - } + return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ * + (queue & dev_info->qc_idx_mask); } /* Prototypes for common NFP functions */ @@ -434,10 +406,10 @@ void nfp_net_close_rx_queue(struct rte_eth_dev *dev); void nfp_net_stop_tx_queue(struct rte_eth_dev *dev); void nfp_net_close_tx_queue(struct rte_eth_dev *dev); int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port); -int nfp_net_rx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc); -int nfp_net_tx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc); int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 899d4dd253..46bedb6696 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -496,9 +496,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) struct nfp_app_fw_nic *app_fw_nic; struct nfp_net_hw *hw; struct rte_ether_addr *tmp_ether_addr; - uint64_t rx_bar_off = 0; - uint64_t tx_bar_off = 0; - uint32_t start_q; + uint64_t rx_base; + uint64_t tx_base; int port = 0; int err; @@ -576,25 +575,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev) /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - return -ENODEV; - } + tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + rx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); - PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); + PMD_INIT_LOG(DEBUG, "tx_base: 0x%" PRIx64 "", tx_base); + PMD_INIT_LOG(DEBUG, "rx_base: 0x%" PRIx64 "", rx_base); - hw->tx_bar = pf_dev->qc_bar + tx_bar_off; - hw->rx_bar = pf_dev->qc_bar + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ; + hw->rx_bar = pf_dev->qc_bar + rx_base * NFP_QCP_QUEUE_ADDR_SZ; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -902,10 +890,17 @@ nfp_pf_init(struct rte_pci_device *pci_dev) char name[RTE_ETH_NAME_MAX_LEN]; struct nfp_rtsym_table *sym_tbl; struct nfp_eth_table *nfp_eth_table; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This @@ -976,27 +971,14 @@ nfp_pf_init(struct rte_pci_device *pci_dev) pf_dev->sym_tbl = sym_tbl; pf_dev->pci_dev = pci_dev; pf_dev->nfp_eth_table = nfp_eth_table; + pf_dev->dev_info = dev_info; /* configure access to tx/rx vNIC BARs */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP3800_OFFSET, - 0, NFP_PCIE_QUEUE_NFP3800_MASK); - break; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP6000_OFFSET, - 0, NFP_PCIE_QUEUE_NFP6000_MASK); - break; - default: - PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); - ret = -ENODEV; - goto pf_cleanup; - } - + addr = nfp_qcp_queue_offset(pf_dev->dev_info, 0); cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, - addr, NFP_QCP_QUEUE_AREA_SZ, + addr, pf_dev->dev_info->qc_area_sz, &pf_dev->qc_area); if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); @@ -1111,10 +1093,17 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) struct nfp_cpp *cpp; enum nfp_app_fw_id app_fw_id; struct nfp_rtsym_table *sym_tbl; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c index eaf815d06d..cf60e56c28 100644 --- a/drivers/net/nfp/nfp_ethdev_vf.c +++ b/drivers/net/nfp/nfp_ethdev_vf.c @@ -305,19 +305,10 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev) } /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_VF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - err = -ENODEV; - goto dev_err_ctrl_map; - } + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + tx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); + rx_bar_off = nfp_qcp_queue_offset(hw->pf_dev->dev_info, start_q); PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c index f0c371ea2b..1b8bb3471d 100644 --- a/drivers/net/nfp/nfp_rxtx.c +++ b/drivers/net/nfp/nfp_rxtx.c @@ -677,7 +677,6 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; const struct rte_memzone *tz; @@ -689,9 +688,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); /* Validating number of descriptors */ rx_desc_sz = nb_desc * sizeof(struct nfp_net_rx_desc); diff --git a/drivers/net/nfp/nfp_rxtx.h b/drivers/net/nfp/nfp_rxtx.h index 48e548b02d..6d1c8e4605 100644 --- a/drivers/net/nfp/nfp_rxtx.h +++ b/drivers/net/nfp/nfp_rxtx.h @@ -74,18 +74,6 @@ struct nfp_meta_parsed { } vlan[NFP_META_MAX_VLANS]; }; -/* - * The maximum number of descriptors is limited by design as - * DPDK uses uint16_t variables for these values - */ -#define NFP_NET_MAX_TX_DESC (32 * 1024) -#define NFP_NET_MIN_TX_DESC 256 -#define NFP3800_NET_MIN_TX_DESC 512 - -#define NFP_NET_MAX_RX_DESC (32 * 1024) -#define NFP_NET_MIN_RX_DESC 256 -#define NFP3800_NET_MIN_RX_DESC 512 - /* Descriptor alignment */ #define NFP_ALIGN_RING_DESC 128 diff --git a/drivers/net/nfp/nfpcore/nfp_dev.c b/drivers/net/nfp/nfpcore/nfp_dev.c new file mode 100644 index 0000000000..7799fa699a --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_dev.h" + +#include <rte_bitops.h> + +#include "nfp_platform.h" + +/* + * Note: The value of 'max_qc_size' is different from kernel driver, + * because DPDK use 'uint16_t' as the data type. + */ +const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { + [NFP_DEV_NFP3800] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0x400000, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP3800", + .pcie_cfg_expbar_offset = 0x0a00, + .qc_area_sz = 0x100000, + .pf_num_per_unit = 4, + }, + [NFP_DEV_NFP3800_VF] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, + [NFP_DEV_NFP6000] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0x80000, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP4000/NFP6000", + .pcie_cfg_expbar_offset = 0x0400, + .qc_area_sz = 0x80000, + .pf_num_per_unit = 1, + }, + [NFP_DEV_NFP6000_VF] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, +}; + +const struct nfp_dev_info * +nfp_dev_info_get(uint16_t device_id) +{ + enum nfp_dev_id id; + + switch (device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + id = NFP_DEV_NFP3800; + break; + case PCI_DEVICE_ID_NFP3800_VF_NIC: + id = NFP_DEV_NFP3800_VF; + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + id = NFP_DEV_NFP6000; + break; + case PCI_DEVICE_ID_NFP6000_VF_NIC: + id = NFP_DEV_NFP6000_VF; + break; + default: + id = NFP_DEV_CNT; + break; + } + + if (id >= NFP_DEV_CNT) + return NULL; + + return &nfp_dev_info[id]; +} diff --git a/drivers/net/nfp/nfpcore/nfp_dev.h b/drivers/net/nfp/nfpcore/nfp_dev.h new file mode 100644 index 0000000000..b0fffff619 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_DEV_H__ +#define __NFP_DEV_H__ + +#include <stdint.h> + +#define PCI_VENDOR_ID_NETRONOME 0x19ee +#define PCI_VENDOR_ID_CORIGINE 0x1da8 + +#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 +#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 +#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 +#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 +#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ + +enum nfp_dev_id { + NFP_DEV_NFP3800, + NFP_DEV_NFP3800_VF, + NFP_DEV_NFP6000, + NFP_DEV_NFP6000_VF, + NFP_DEV_CNT, +}; + +struct nfp_dev_info { + /* Required fields */ + uint32_t qc_idx_mask; + uint32_t qc_addr_offset; + uint32_t min_qc_size; + uint32_t max_qc_size; + + /* PF-only fields */ + const char *chip_names; + uint32_t pcie_cfg_expbar_offset; + uint32_t qc_area_sz; + uint8_t pf_num_per_unit; +}; + +const struct nfp_dev_info *nfp_dev_info_get(uint16_t device_id); + +#endif /* __NFP_DEV_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 22/26] net/nfp: add header file for PCIe module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (20 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 21/26] net/nfp: add the dev module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 23/26] net/nfp: refact the cppcore module Chaoyong He ` (6 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Add a new header file for the PCIe module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/meson.build | 2 +- .../nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} | 2 ++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 13 +++++++++++++ drivers/net/nfp/nfpcore/nfp_cpp.h | 6 ------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) rename drivers/net/nfp/nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} (99%) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 580a478cd6..d422269c4b 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -12,7 +12,6 @@ sources = files( 'flower/nfp_flower_representor.c', 'nfd3/nfp_nfd3_dp.c', 'nfdk/nfp_nfdk_dp.c', - 'nfpcore/nfp_cpp_pcie_ops.c', 'nfpcore/nfp_nsp.c', 'nfpcore/nfp_cppcore.c', 'nfpcore/nfp_resource.c', @@ -26,6 +25,7 @@ sources = files( 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', 'nfpcore/nfp_target.c', + 'nfpcore/nfp6000_pcie.c', 'nfp_common.c', 'nfp_rxtx.c', 'nfp_cpp_bridge.c', diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c similarity index 99% rename from drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c rename to drivers/net/nfp/nfpcore/nfp6000_pcie.c index 310cc691cd..abee584f85 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -14,6 +14,8 @@ * The generic CPP bus abstraction builds upon this BAR interface. */ +#include "nfp6000_pcie.h" + #include <assert.h> #include <stdio.h> #include <stdlib.h> diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h new file mode 100644 index 0000000000..e126457d45 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Netronome Systems, Inc. + * All rights reserved. + */ + +#ifndef __NFP6000_PCIE_H__ +#define __NFP6000_PCIE_H__ + +#include "nfp_cpp.h" + +const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); + +#endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 42c4df5fdd..0df97552cb 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,12 +226,6 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) return id & 0xff; } -/* - * This should be the only external function the transport - * module supplies - */ -const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); - void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 41485b6975..47dd2f2bca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -14,12 +14,12 @@ #include <rte_byteorder.h> #include <ethdev_pci.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" +#include "nfp6000_pcie.h" #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 23/26] net/nfp: refact the cppcore module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (21 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 22/26] net/nfp: add header file for PCIe module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 24/26] net/nfp: refact the PCIe module Chaoyong He ` (5 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Modify the comment and standard the coding style. Move the definition of data structure into the implement file to make the API small. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 14 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 40 ++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 186 ++++++++++++++++--------- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c index 88cd1aa572..a9998f3c08 100644 --- a/drivers/net/nfp/nfp_cpp_bridge.c +++ b/drivers/net/nfp/nfp_cpp_bridge.c @@ -344,7 +344,7 @@ nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp) return -EIO; } - tmp = cpp->interface; + tmp = nfp_cpp_interface(cpp); PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 46bedb6696..921fa167dd 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -654,15 +654,23 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) char fw_name[125]; char serial[40]; size_t fsize; + uint16_t interface; + uint32_t cpp_serial_len; + const uint8_t *cpp_serial; + + cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial); + if (cpp_serial_len != NFP_SERIAL_LEN) + return -ERANGE; + + interface = nfp_cpp_interface(cpp); /* Looking for firmware file in order of priority */ /* First try to find a firmware image specific for this device */ snprintf(serial, sizeof(serial), "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3], - cpp->serial[4], cpp->serial[5], cpp->interface >> 8, - cpp->interface & 0xff); + cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3], + cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff); snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH, serial); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index abee584f85..45645e04f8 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -739,7 +739,7 @@ nfp6000_init(struct nfp_cpp *cpp, strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; @@ -778,7 +778,7 @@ nfp6000_free(struct nfp_cpp *cpp) struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); nfp_disable_bars(desc); - if (cpp->driver_lock_needed) + if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); free(desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0df97552cb..34ed50ceca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -9,38 +9,12 @@ #include <ethdev_pci.h> /* NFP CPP handle */ -struct nfp_cpp { - uint32_t model; - uint32_t interface; - uint8_t *serial; - int serial_len; - void *priv; - - /* Mutex cache */ - struct nfp_cpp_mutex *mutex_cache; - const struct nfp_cpp_operations *op; - - /* - * NFP-6xxx originating island IMB CPP Address Translation. CPP Target - * ID is index into array. Values are obtained at runtime from local - * island XPB CSRs. - */ - uint32_t imb_cat_table[16]; - - /* MU access type bit offset */ - uint32_t mu_locality_lsb; - - int driver_lock_needed; -}; +struct nfp_cpp; /* NFP CPP device area handle */ -struct nfp_cpp_area { - struct nfp_cpp *cpp; - char *name; - unsigned long long offset; - unsigned long size; - /* Here follows the 'priv' part of nfp_cpp_area. */ -}; +struct nfp_cpp_area; + +#define NFP_SERIAL_LEN 6 /* * NFP CPP operations structure @@ -230,7 +204,7 @@ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); @@ -349,7 +323,9 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); + +bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp); struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 47dd2f2bca..bbf2eaa448 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -3,30 +3,56 @@ * All rights reserved. */ -#include <assert.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> - -#include <rte_byteorder.h> -#include <ethdev_pci.h> +#include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_platform.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" -#include "nfp_nffw.h" #include "nfp6000_pcie.h" +#define NFP_PL_DEVICE_PART_NFP6000 0x6200 #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff #define NFP_PL_DEVICE_PART_MASK 0xffff0000 #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/* NFP CPP handle */ +struct nfp_cpp { + void *priv; /**< Private data of the low-level implementation */ + + uint32_t model; /**< Chip model */ + uint16_t interface; /**< Chip interface id */ + uint8_t serial[NFP_SERIAL_LEN]; /**< Chip serial number */ + + /** Low-level implementation ops */ + const struct nfp_cpp_operations *op; + + /* + * NFP-6xxx originating island IMB CPP Address Translation. CPP Target + * ID is index into array. Values are obtained at runtime from local + * island XPB CSRs. + */ + uint32_t imb_cat_table[16]; + + /**< MU access type bit offset */ + uint32_t mu_locality_lsb; + + bool driver_lock_needed; +}; + +/* NFP CPP device area handle */ +struct nfp_cpp_area { + struct nfp_cpp *cpp; + char *name; + uint64_t offset; + uint32_t size; + /* Here follows the 'priv' part of nfp_cpp_area. */ + /* Here follows the ASCII name, pointed by @name */ +}; + /** * Set the private data of the nfp_cpp instance * @@ -125,12 +151,13 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, * @return * Length of NFP serial number */ -int +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) { - *serial = cpp->serial; - return cpp->serial_len; + *serial = &cpp->serial[0]; + + return sizeof(cpp->serial); } /** @@ -143,22 +170,12 @@ nfp_cpp_serial(struct nfp_cpp *cpp, * @param serial_len * Length of the serial byte array */ -int +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len) { - if (cpp->serial_len) - free(cpp->serial); - - cpp->serial = malloc(serial_len); - if (cpp->serial == NULL) - return -1; - memcpy(cpp->serial, serial, serial_len); - cpp->serial_len = serial_len; - - return 0; } /** @@ -179,6 +196,21 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Retrieve the driver need lock flag + * + * @param cpp + * NFP CPP handle + * + * @return + * The driver need lock flag + */ +bool +nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp) +{ + return cpp->driver_lock_needed; +} + /** * Get the privately allocated portion of a NFP CPP area handle * @@ -283,39 +315,40 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t size) { int err; + size_t name_len; + uint32_t target_id; + uint64_t target_addr; struct nfp_cpp_area *area; - uint64_t tmp64 = (uint64_t)address; if (cpp == NULL) return NULL; /* Remap from cpp_island to cpp_target */ - err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table); + err = nfp_target_cpp(dest, address, &target_id, &target_addr, + cpp->imb_cat_table); if (err < 0) return NULL; - address = tmp64; - if (name == NULL) - name = ""; + name = "(reserved)"; - area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + name_len = strlen(name) + 1; + area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + name_len); if (area == NULL) return NULL; area->cpp = cpp; area->name = ((char *)area) + sizeof(*area) + cpp->op->area_priv_size; - memcpy(area->name, name, strlen(name) + 1); + memcpy(area->name, name, name_len); - err = cpp->op->area_init(area, dest, address, size); + err = cpp->op->area_init(area, target_id, target_addr, size); if (err < 0) { PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } - area->offset = address; + area->offset = target_addr; area->size = size; return area; @@ -555,26 +588,28 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, * Ensure that non-local XPB accesses go out through the * global XPBM bus. */ - island = ((*xpb_addr) >> 24) & 0x3f; + island = (*xpb_addr >> 24) & 0x3f; if (island == 0) return xpb; - if (island == 1) { - /* - * Accesses to the ARM Island overlay uses Island 0 - * Global Bit - */ - (*xpb_addr) &= ~0x7f000000; - if (*xpb_addr < 0x60000) - *xpb_addr |= (1 << 30); - else - /* And only non-ARM interfaces use island id = 1 */ - if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) - *xpb_addr |= (1 << 24); + if (island != 1) { + *xpb_addr |= (1 << 30); + return xpb; + } + + /* + * Accesses to the ARM Island overlay uses Island 0 + * Global Bit + */ + *xpb_addr &= ~0x7f000000; + if (*xpb_addr < 0x60000) { + *xpb_addr |= (1 << 30); } else { - (*xpb_addr) |= (1 << 30); + /* And only non-ARM interfaces use island id = 1 */ + if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != + NFP_CPP_INTERFACE_TYPE_ARM) + *xpb_addr |= (1 << 24); } return xpb; @@ -602,9 +637,12 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -629,7 +667,10 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, value = rte_cpu_to_le_32(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - return (sz == sizeof(value)) ? 0 : -1; + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; + + return 0; } /** @@ -654,9 +695,12 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, uint64_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_64(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -681,8 +725,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, value = rte_cpu_to_le_64(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -710,9 +756,12 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t tmp; sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -740,8 +789,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, value = rte_cpu_to_le_32(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -770,8 +821,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); *value = rte_le_to_cpu_64(tmp); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -799,8 +852,10 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, value = rte_cpu_to_le_64(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -918,9 +973,6 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len != 0) - free(cpp->serial); - free(cpp); } @@ -974,7 +1026,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); - return -1; + return -EACCES; } err = nfp_cpp_area_read(area, 0, address, length); @@ -1013,7 +1065,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); - return -1; + return -EACCES; } err = nfp_cpp_area_write(area, 0, address, length); @@ -1039,8 +1091,12 @@ nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) - *model -= 0x10; + /* Disambiguate the NFP4000/NFP5000/NFP6000 chips */ + if (FIELD_GET(NFP_PL_DEVICE_PART_MASK, reg) == + NFP_PL_DEVICE_PART_NFP6000) { + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) + *model -= 0x10; + } return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 24/26] net/nfp: refact the PCIe module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (22 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 23/26] net/nfp: refact the cppcore module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 25/26] net/nfp: refact the cppcore and " Chaoyong He ` (4 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 211 +++++++++++++++++-------- drivers/net/nfp/nfpcore/nfp_cpp.h | 9 ++ 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 45645e04f8..4f453f19a9 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -16,23 +16,8 @@ #include "nfp6000_pcie.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> #include <unistd.h> -#include <stdint.h> -#include <stdbool.h> #include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <dirent.h> -#include <libgen.h> - -#include <sys/mman.h> -#include <sys/file.h> -#include <sys/stat.h> - -#include <ethdev_pci.h> #include "nfp_cpp.h" #include "nfp_logs.h" @@ -43,8 +28,11 @@ #define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) +#define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(_x) (((_x) >> 16) & 0x1f) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) +#define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS_OF(_x) (((_x) >> 0) & 0xffff) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT(_x) (((_x) & 0x3) << 27) +#define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(_x) (((_x) >> 27) & 0x3) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT 0 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT 1 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE 3 @@ -55,7 +43,9 @@ #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET 2 #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL 3 #define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(_x) (((_x) & 0xf) << 23) +#define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(_x) (((_x) >> 23) & 0xf) #define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(_x) (((_x) & 0x3) << 21) +#define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(_x) (((_x) >> 21) & 0x3) /* * Minimal size of the PCIe cfg memory we depend on being mapped, @@ -132,7 +122,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (target >= 16) + if (target >= NFP_CPP_NUM_TARGETS) return -EINVAL; switch (width) { @@ -182,10 +172,6 @@ nfp_compute_bar(const struct nfp_bar *bar, offset &= mask; bitsize = 40 - 21; } - - if (bar->bitsize < bitsize) - return -EINVAL; - newcfg |= offset >> bitsize; if (bar_base != NULL) @@ -434,7 +420,7 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Must have been too big. Sub-allocate. */ if (priv->bar->iomem == NULL) - return (-ENOMEM); + return -ENOMEM; priv->iomem = priv->bar->iomem + priv->bar_offset; @@ -464,9 +450,9 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32 = address; uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; @@ -484,47 +470,54 @@ nfp6000_area_read(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } - is_64 = width == TARGET_WIDTH_64; - - /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { - is_64 = false; - } + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; + ret = n; + break; + default: + return -EINVAL; + } + + return ret; } static int @@ -533,9 +526,9 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; @@ -553,47 +546,53 @@ nfp6000_area_write(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; - is_64 = width == TARGET_WIDTH_64; - - /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) - is_64 = false; + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; -} + ret = n; + break; + default: + return -EINVAL; + } -#define PCI_DEVICES "/sys/bus/pci/devices" + return ret; +} static int nfp_acquire_process_lock(struct nfp_pcie_user *desc) @@ -706,6 +705,74 @@ nfp6000_set_serial(struct rte_pci_device *dev, return 0; } +static int +nfp6000_get_dsn(struct rte_pci_device *pci_dev, + uint64_t *dsn) +{ + off_t pos; + size_t len; + uint64_t tmp = 0; + + pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN); + if (pos <= 0) { + PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found"); + return -ENODEV; + } + + pos += 4; + len = sizeof(tmp); + + if (rte_pci_read_config(pci_dev, &tmp, len, pos) < 0) { + PMD_DRV_LOG(ERR, "nfp get device serial number failed"); + return -ENOENT; + } + + *dsn = tmp; + + return 0; +} + +static int +nfp6000_get_interface(struct rte_pci_device *dev, + uint16_t *interface) +{ + int ret; + uint64_t dsn = 0; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + *interface = dsn & 0xffff; + + return 0; +} + +static int +nfp6000_get_serial(struct rte_pci_device *dev, + uint8_t *serial, + size_t length) +{ + int ret; + uint64_t dsn = 0; + + if (length < NFP_SERIAL_LEN) + return -ENOMEM; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + serial[0] = (dsn >> 56) & 0xff; + serial[1] = (dsn >> 48) & 0xff; + serial[2] = (dsn >> 40) & 0xff; + serial[3] = (dsn >> 32) & 0xff; + serial[4] = (dsn >> 24) & 0xff; + serial[5] = (dsn >> 16) & 0xff; + + return 0; +} + static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) @@ -789,6 +856,10 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .free = nfp6000_free, .area_priv_size = sizeof(struct nfp6000_area_priv), + + .get_interface = nfp6000_get_interface, + .get_serial = nfp6000_get_serial, + .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 34ed50ceca..0f36ba0b50 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -16,6 +16,8 @@ struct nfp_cpp_area; #define NFP_SERIAL_LEN 6 +#define NFP_CPP_NUM_TARGETS 16 + /* * NFP CPP operations structure */ @@ -33,6 +35,13 @@ struct nfp_cpp_operations { */ void (*free)(struct nfp_cpp *cpp); + int (*get_interface)(struct rte_pci_device *dev, + uint16_t *interface); + + int (*get_serial)(struct rte_pci_device *dev, + uint8_t *serial, + size_t length); + /* * Initialize a new NFP CPP area * NOTE: This is _not_ serialized -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 25/26] net/nfp: refact the cppcore and PCIe module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (23 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 24/26] net/nfp: refact the PCIe module Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-18 2:46 ` [PATCH v4 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He ` (3 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Sync the logic from kernel driver, use the new entry function from the PCIe module instead of the cppcore module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 9 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 197 ++++++++++--------------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 6 + drivers/net/nfp/nfpcore/nfp_cpp.h | 36 +---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 68 ++++++--- 5 files changed, 142 insertions(+), 174 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 921fa167dd..a645e23a4d 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -23,6 +23,7 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.h" #include "nfpcore/nfp_nsp.h" +#include "nfpcore/nfp6000_pcie.h" #include "nfp_common.h" #include "nfp_ctrl.h" @@ -917,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1120,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 4f453f19a9..40076cdc11 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -98,6 +98,24 @@ struct nfp_pcie_user { char *cfg; }; +/* Generic CPP bus access interface. */ +struct nfp6000_area_priv { + struct nfp_bar *bar; + uint32_t bar_offset; + + int target; + int action; + int token; + uint64_t offset; + struct { + int read; + int write; + int bar; + } width; + size_t size; + char *iomem; +}; + static uint32_t nfp_bar_maptype(struct nfp_bar *bar) { @@ -334,24 +352,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* Generic CPP bus access interface. */ -struct nfp6000_area_priv { - struct nfp_bar *bar; - uint32_t bar_offset; - - uint32_t target; - uint32_t action; - uint32_t token; - uint64_t offset; - struct { - int read; - int write; - int bar; - } width; - size_t size; - char *iomem; -}; - static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, @@ -624,87 +624,6 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) return 0; } -static int -nfp6000_set_model(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint32_t model; - - if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { - PMD_DRV_LOG(ERR, "nfp set model failed"); - return -1; - } - - model = model << 16; - nfp_cpp_model_set(cpp, model); - - return 0; -} - -static int -nfp6000_set_interface(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint16_t interface; - - if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { - PMD_DRV_LOG(ERR, "nfp set interface failed"); - return -1; - } - - nfp_cpp_interface_set(cpp, interface); - - return 0; -} - -static int -nfp6000_set_serial(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - off_t pos; - uint16_t tmp; - uint8_t serial[6]; - int serial_len = 6; - - pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); - if (pos <= 0) { - PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found. nfp set serial failed"); - return -1; - } else { - pos += 6; - } - - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[4] = (uint8_t)((tmp >> 8) & 0xff); - serial[5] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[2] = (uint8_t)((tmp >> 8) & 0xff); - serial[3] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[0] = (uint8_t)((tmp >> 8) & 0xff); - serial[1] = (uint8_t)(tmp & 0xff); - - nfp_cpp_serial_set(cpp, serial, serial_len); - - return 0; -} - static int nfp6000_get_dsn(struct rte_pci_device *pci_dev, uint64_t *dsn) @@ -795,12 +714,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { int ret = 0; - struct nfp_pcie_user *desc; - - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return -1; - + struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); @@ -809,17 +723,11 @@ nfp6000_init(struct nfp_cpp *cpp, nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) - goto error; + return -1; } - if (nfp6000_set_model(dev, cpp) < 0) - goto error; - if (nfp6000_set_interface(dev, cpp) < 0) - goto error; - if (nfp6000_set_serial(dev, cpp) < 0) - goto error; if (nfp6000_set_barsz(dev, desc) < 0) - goto error; + return -1; desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; @@ -830,13 +738,7 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - nfp_cpp_priv_set(cpp, desc); - return 0; - -error: - free(desc); - return -1; } static void @@ -873,3 +775,60 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) { return &nfp6000_pcie_ops; } + +/** + * Build a NFP CPP bus from a NFP6000 PCI device + * + * @param pdev + * NFP6000 PCI device + * @param driver_lock_needed + * driver lock flag + * + * @return + * NFP CPP handle or NULL + */ +struct nfp_cpp * +nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed) +{ + int ret; + struct nfp_cpp *cpp; + uint16_t interface = 0; + struct nfp_pcie_user *nfp; + + nfp = malloc(sizeof(*nfp)); + if (nfp == NULL) + return NULL; + + memset(nfp, 0, sizeof(*nfp)); + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_TYPE_of(interface) != NFP_CPP_INTERFACE_TYPE_PCI) { + PMD_DRV_LOG(ERR, "Interface type is not right."); + free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_CHANNEL_of(interface) != + NFP_CPP_INTERFACE_CHANNEL_PEROPENER) { + PMD_DRV_LOG(ERR, "Interface channel is not right"); + free(nfp); + return NULL; + } + + /* Probe for all the common NFP devices */ + cpp = nfp_cpp_from_device_name(pci_dev, nfp, driver_lock_needed); + if (cpp == NULL) { + PMD_DRV_LOG(ERR, "Get cpp from operation failed"); + free(nfp); + return NULL; + } + + return cpp; +} diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index e126457d45..8847f6f946 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -6,8 +6,14 @@ #ifndef __NFP6000_PCIE_H__ #define __NFP6000_PCIE_H__ +#include <ethdev_pci.h> + #include "nfp_cpp.h" +#include "nfp_dev.h" const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); +struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed); + #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0f36ba0b50..e879c7c920 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,40 +226,12 @@ uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + void *priv, bool driver_lock_needed); void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/** - * Retrieve the chip ID from the model ID - * - * The chip ID is a 16-bit BCD+A-F encoding for the chip type. - * - * @param model - * NFP CPP model id - * - * @return - * NFP CPP chip id - */ -#define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) - -/** - * Check for the NFP6000 family of devices - * - * NOTE: The NFP4000 series is considered as a NFP6000 series variant. - * - * @param model - * NFP CPP model id - * - * @return - * true if model is in the NFP6000 family, false otherwise. - */ -#define NFP_CPP_MODEL_IS_6000(model) \ - ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ - (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) - uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,6 +302,12 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) +/* + * Use this channel ID for multiple virtual channel interfaces + * (ie ARM and PCIe) when setting up the interface field. + */ +#define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255 + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index bbf2eaa448..8b2d00a6a1 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -909,10 +909,13 @@ nfp_xpb_readl(struct nfp_cpp *cpp, } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, - int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *pci_dev, + void *priv, + bool driver_lock_needed) { int err; + size_t target; + uint32_t xpb_addr; struct nfp_cpp *cpp; const struct nfp_cpp_operations *ops; @@ -925,32 +928,50 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return NULL; cpp->op = ops; + cpp->priv = priv; cpp->driver_lock_needed = driver_lock_needed; - if (cpp->op->init) { - err = cpp->op->init(cpp, dev); + err = ops->get_interface(pci_dev, &cpp->interface); + if (err != 0) { + free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + free(cpp); + return NULL; + } + + /* + * NOTE: cpp_lock is NOT locked for op->init, + * since it may call NFP CPP API operations + */ + err = cpp->op->init(cpp, pci_dev); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP interface initialization failed"); + free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + free(cpp); + return NULL; + } + + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { + /* Hardcoded XPB IMB Base, island 0 */ + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, &cpp->imb_cat_table[target]); if (err < 0) { + PMD_DRV_LOG(ERR, "Can't read CPP mapping from device"); free(cpp); return NULL; } } - if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpb_addr; - size_t target; - - for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { - /* Hardcoded XPB IMB Base, island 0 */ - xpb_addr = 0x000a0000 + (target * 4); - err = nfp_xpb_readl(cpp, xpb_addr, - (uint32_t *)&cpp->imb_cat_table[target]); - if (err < 0) { - free(cpp); - return NULL; - } - } - } - err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); @@ -981,6 +1002,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) * * @param dev * PCI device + * @param priv + * Private data of low-level implementation * @param driver_lock_needed * Driver lock flag * @@ -991,9 +1014,10 @@ nfp_cpp_free(struct nfp_cpp *cpp) */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed) + void *priv, + bool driver_lock_needed) { - return nfp_cpp_alloc(dev, driver_lock_needed); + return nfp_cpp_alloc(dev, priv, driver_lock_needed); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v4 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (24 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 25/26] net/nfp: refact the cppcore and " Chaoyong He @ 2023-09-18 2:46 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (2 subsequent siblings) 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-18 2:46 UTC (permalink / raw) To: dev; +Cc: Chaoyong He, Niklas Söderlund Sync the logic from kernel driver, adjust the definition of structure, and extend the usage of nfp BAR from 8 to 24. This will greatly enhance the scalability of nfp PMD. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 8 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 477 ++++++++++++++++++------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 1 + drivers/net/nfp/nfpcore/nfp_cpp.h | 5 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 348 insertions(+), 145 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index a645e23a4d..a4386b771c 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -918,9 +918,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1121,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 40076cdc11..13cf523506 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -19,6 +19,8 @@ #include <unistd.h> #include <fcntl.h> +#include <rte_io.h> + #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" @@ -59,20 +61,12 @@ #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4)) #define NFP_PCIE_P2C_GENERAL_SIZE(bar) (1 << ((bar)->bitsize - 4)) -#define NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(id, bar, slot) \ - (NFP_PCIE_BAR(id) + ((bar) * 8 + (slot)) * 4) - -#define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ - (((bar) * 8 + (slot)) * 4) +#define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index) ((bar_index) * 4) struct nfp_pcie_user; struct nfp6000_area_priv; /* Describes BAR configuration and usage */ -#define NFP_BAR_MIN 1 -#define NFP_BAR_MID 5 -#define NFP_BAR_MAX 7 - struct nfp_bar { struct nfp_pcie_user *nfp; /**< Backlink to owner */ uint32_t barcfg; /**< BAR config CSR */ @@ -80,22 +74,26 @@ struct nfp_bar { uint64_t mask; /**< Mask of the BAR aperture (read only) */ uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ uint32_t index; /**< Index of the BAR */ - int lock; /**< If the BAR has been locked */ + bool lock; /**< If the BAR has been locked */ - char *csr; char *iomem; /**< mapped IO memory */ + struct rte_mem_resource *resource; /**< IOMEM resource window */ }; -#define BUSDEV_SZ 13 +#define NFP_PCI_BAR_MAX (PCI_64BIT_BAR_COUNT * 8) + struct nfp_pcie_user { - struct nfp_bar bar[NFP_BAR_MAX]; + struct rte_pci_device *pci_dev; + const struct nfp_dev_info *dev_info; - int device; int lock; - char busdev[BUSDEV_SZ]; - int barsz; - int dev_id; - char *cfg; + + /* PCI BAR management */ + uint32_t bars; + struct nfp_bar bar[NFP_PCI_BAR_MAX]; + + /* Reserved BAR access */ + char *csr; }; /* Generic CPP bus access interface. */ @@ -206,19 +204,19 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base; - int slot; - - base = bar->index >> 3; - slot = bar->index & 7; + uint32_t xbar; - if (nfp->cfg == NULL) - return (-ENOMEM); + xbar = NFP_PCIE_P2C_EXPBAR_OFFSET(bar->index); - bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); - - *(uint32_t *)(bar->csr) = newcfg; + if (nfp->csr != NULL) { + rte_write32(newcfg, nfp->csr + xbar); + /* Readback to ensure BAR is flushed */ + rte_read32(nfp->csr + xbar); + } else { + xbar += nfp->dev_info->pcie_cfg_expbar_offset; + rte_pci_write_config(nfp->pci_dev, &newcfg, sizeof(uint32_t), + xbar); + } bar->barcfg = newcfg; @@ -249,105 +247,323 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, return nfp_bar_write(nfp, bar, newcfg); } -/* - * Map all PCI bars. We assume that the BAR with the PCIe config block is - * already mapped. +static uint32_t +nfp_bitsize_calc(uint64_t mask) +{ + uint64_t tmp = mask; + uint32_t bit_size = 0; + + if (tmp == 0) + return 0; + + for (; tmp != 0; tmp >>= 1) + bit_size++; + + return bit_size; +} + +static int +nfp_cmp_bars(const void *ptr_a, + const void *ptr_b) +{ + const struct nfp_bar *a = ptr_a; + const struct nfp_bar *b = ptr_b; + + if (a->bitsize == b->bitsize) + return a->index - b->index; + else + return a->bitsize - b->bitsize; +} + +static bool +nfp_bars_for_secondary(uint32_t index) +{ + uint8_t tmp = index & 0x07; + + if (tmp == 0x06 || tmp == 0x07) + return true; + else + return false; +} + +/** + * Map all PCI bars and fetch the actual BAR configurations from the board. + * We assume that the BAR with the PCIe config block is already mapped. * * BAR0.0: Reserved for General Mapping (for MSI-X access to PCIe SRAM) + * BAR0.1: -- + * BAR0.2: -- + * BAR0.3: -- + * BAR0.4: -- + * BAR0.5: -- + * BAR0.6: -- + * BAR0.7: -- * - * Halving PCItoCPPBars for primary and secondary processes. - * For CoreNIC firmware: - * NFP PMD just requires two fixed slots, one for configuration BAR, - * and another for accessing the hw queues. Another slot is needed - * for setting the link up or down. Secondary processes do not need - * to map the first two slots again, but it requires one slot for - * accessing the link, even if it is not likely the secondary process - * starting the port. - * For Flower firmware: - * NFP PMD need another fixed slots, used as the configureation BAR - * for ctrl vNIC. + * BAR1.0-BAR1.7: -- + * BAR2.0-BAR2.7: -- */ static int nfp_enable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + int pf; + uint32_t i; + uint8_t min_bars; struct nfp_bar *bar; + enum rte_proc_type_t type; + struct rte_mem_resource *res; + const uint32_t barcfg_msix_general = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) | + NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT; + + type = rte_eal_process_type(); + if (type == RTE_PROC_PRIMARY) + min_bars = 12; + else + min_bars = 4; + + for (i = 0; i < RTE_DIM(nfp->bar); i++) { + if (i != 0) { + if (type == RTE_PROC_PRIMARY) { + if (nfp_bars_for_secondary(i)) + continue; + } else { + if (!nfp_bars_for_secondary(i)) + continue; + } + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* 24 NFP bars mapping into BAR0, BAR2 and BAR4 */ + res = &nfp->pci_dev->mem_resource[(i >> 3) * 2]; + + /* Skip over BARs that are not mapped */ + if (res->addr != NULL) { + bar = &nfp->bar[i]; + bar->resource = res; + bar->barcfg = 0; + + bar->nfp = nfp; + bar->index = i; + /* The resource shared by 8 bars */ + bar->mask = (res->len >> 3) - 1; + bar->bitsize = nfp_bitsize_calc(bar->mask); + bar->base = 0; + bar->lock = false; + bar->iomem = (char *)res->addr + + ((bar->index & 7) << bar->bitsize); + + nfp->bars++; + } } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - bar->barcfg = 0; - bar->nfp = nfp; - bar->index = x; - bar->mask = (1 << (nfp->barsz - 3)) - 1; - bar->bitsize = nfp->barsz - 3; - bar->base = 0; - bar->iomem = NULL; - bar->lock = 0; - bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, - bar->index >> 3, bar->index & 7); - bar->iomem = nfp->cfg + (bar->index << bar->bitsize); + if (nfp->bars < min_bars) { + PMD_DRV_LOG(ERR, "Not enough usable BARs found."); + return -EINVAL; } + + switch (nfp->pci_dev->id.device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + pf = nfp->pci_dev->addr.function & 0x07; + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(pf); + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(0); + break; + default: + PMD_DRV_LOG(ERR, "Unsupported device ID: %04hx!", + nfp->pci_dev->id.device_id); + return -EINVAL; + } + + /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */ + bar = &nfp->bar[0]; + bar->lock = true; + + nfp_bar_write(nfp, bar, barcfg_msix_general); + + /* Sort bars by bit size - use the smallest possible first. */ + qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars); + return 0; } -static struct nfp_bar * -nfp_alloc_bar(struct nfp_pcie_user *nfp) +/* Check if BAR can be used with the given parameters. */ +static bool +matching_bar_exist(struct nfp_bar *bar, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) { - int x; - int end; - int start; - struct nfp_bar *bar; + int bar_width; + int bar_token; + int bar_target; + int bar_action; + uint32_t map_type; + + bar_width = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(bar->barcfg); + switch (bar_width) { + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT: + bar_width = 4; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT: + bar_width = 8; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE: + bar_width = 0; + break; + default: + bar_width = -1; + break; + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* Make sure to match up the width */ + if (bar_width != width) + return false; + + bar_token = NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(bar->barcfg); + bar_action = NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(bar->barcfg); + map_type = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_OF(bar->barcfg); + switch (map_type) { + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET: + bar_token = -1; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK: + bar_action = NFP_CPP_ACTION_RW; + if (action == 0) + action = NFP_CPP_ACTION_RW; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED: + break; + default: + /* We don't match explicit bars through the area interface */ + return false; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->lock == 0) { - bar->lock = 1; - return bar; - } + bar_target = NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(bar->barcfg); + if ((bar_target < 0 || bar_target == target) && + (bar_token < 0 || bar_token == token) && + bar_action == action && + bar->base <= offset && + (bar->base + (1 << bar->bitsize)) >= (offset + size)) + return true; + + /* No match */ + return false; +} + +static int +find_matching_bar(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + uint32_t n; + + for (n = 0; n < nfp->bars; n++) { + struct nfp_bar *bar = &nfp->bar[n]; + + if (bar->lock) + continue; + + if (matching_bar_exist(bar, target, action, token, + offset, size, width)) + return n; + } + + return -1; +} + +/* Return EAGAIN if no resource is available */ +static int +find_unused_bar_noblock(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + int ret; + uint32_t n; + const struct nfp_bar *bar; + + for (n = 0; n < nfp->bars; n++) { + bar = &nfp->bar[n]; + + if (bar->bitsize == 0) + continue; + + /* Just check to see if we can make it fit... */ + ret = nfp_compute_bar(bar, NULL, NULL, target, action, + token, offset, size, width); + if (ret != 0) + continue; + + if (!bar->lock) + return n; + } + + return -EAGAIN; +} + +static int +nfp_alloc_bar(struct nfp_pcie_user *nfp, + struct nfp6000_area_priv *priv) +{ + int ret; + int bar_num; + size_t size = priv->size; + int token = priv->token; + int target = priv->target; + int action = priv->action; + int width = priv->width.bar; + uint64_t offset = priv->offset; + + /* Bar size should small than 16MB */ + if (size > (1 << 24)) + return -EINVAL; + + bar_num = find_matching_bar(nfp, target, action, token, + offset, size, width); + if (bar_num >= 0) { + /* Found a perfect match. */ + nfp->bar[bar_num].lock = true; + return bar_num; } - return NULL; + bar_num = find_unused_bar_noblock(nfp, target, action, token, + offset, size, width); + if (bar_num < 0) + return bar_num; + + nfp->bar[bar_num].lock = true; + ret = nfp_reconfigure_bar(nfp, &nfp->bar[bar_num], + target, action, token, offset, size, width); + if (ret < 0) { + nfp->bar[bar_num].lock = false; + return ret; + } + + return bar_num; } static void nfp_disable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + uint32_t i; struct nfp_bar *bar; - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; - } - - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->iomem) { + for (i = 0; i < nfp->bars; i++) { + bar = &nfp->bar[i]; + if (bar->iomem != NULL) { bar->iomem = NULL; - bar->lock = 0; + bar->lock = false; } } } @@ -364,7 +580,6 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -383,9 +598,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, else priv->width.bar = priv->width.write; - priv->bar = nfp_alloc_bar(nfp); - if (priv->bar == NULL) - return -ENOMEM; + priv->bar = NULL; priv->target = target; priv->action = action; @@ -393,17 +606,29 @@ nfp6000_area_init(struct nfp_cpp_area *area, priv->offset = address; priv->size = size; - ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); - return ret; } static int nfp6000_area_acquire(struct nfp_cpp_area *area) { + int bar_num; struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); + + /* Already allocated. */ + if (priv->bar != NULL) + return 0; + + bar_num = nfp_alloc_bar(nfp, priv); + if (bar_num < 0) { + PMD_DRV_LOG(ERR, "Failed to allocate bar %d:%d:%d:%#lx: %d", + priv->target, priv->action, priv->token, + priv->offset, bar_num); + return bar_num; + } + + priv->bar = &nfp->bar[bar_num]; /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == @@ -432,7 +657,7 @@ nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - priv->bar->lock = 0; + priv->bar->lock = false; priv->bar = NULL; priv->iomem = NULL; } @@ -603,7 +828,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) memset(&lock, 0, sizeof(lock)); - snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", desc->busdev); + snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", + desc->pci_dev->device.name); desc->lock = open(lockname, O_RDWR | O_CREAT, 0666); if (desc->lock < 0) return desc->lock; @@ -693,32 +919,11 @@ nfp6000_get_serial(struct rte_pci_device *dev, } static int -nfp6000_set_barsz(struct rte_pci_device *dev, - struct nfp_pcie_user *desc) -{ - int i = 0; - uint64_t tmp; - - tmp = dev->mem_resource[0].len; - - while (tmp >>= 1) - i++; - - desc->barsz = i; - - return 0; -} - -static int -nfp6000_init(struct nfp_cpp *cpp, - struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp) { int ret = 0; struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - memset(desc->busdev, 0, BUSDEV_SZ); - strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); - if (rte_eal_process_type() == RTE_PROC_PRIMARY && nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); @@ -726,12 +931,6 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - if (nfp6000_set_barsz(dev, desc) < 0) - return -1; - - desc->cfg = dev->mem_resource[0].addr; - desc->dev_id = dev->addr.function & 0x7; - ret = nfp_enable_bars(desc); if (ret != 0) { PMD_DRV_LOG(ERR, "Enable bars failed"); @@ -749,7 +948,6 @@ nfp6000_free(struct nfp_cpp *cpp) nfp_disable_bars(desc); if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); - close(desc->device); free(desc); } @@ -789,6 +987,7 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) */ struct nfp_cpp * nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed) { int ret; @@ -801,6 +1000,8 @@ nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, return NULL; memset(nfp, 0, sizeof(*nfp)); + nfp->pci_dev = pci_dev; + nfp->dev_info = dev_info; ret = nfp6000_get_interface(pci_dev, &interface); if (ret != 0) { diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index 8847f6f946..8e2cfb69e6 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -14,6 +14,7 @@ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed); #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index e879c7c920..2defc4fa16 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -18,6 +18,8 @@ struct nfp_cpp_area; #define NFP_CPP_NUM_TARGETS 16 +#define PCI_64BIT_BAR_COUNT 3 + /* * NFP CPP operations structure */ @@ -26,8 +28,7 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, - struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp); /* * Free the bus. diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 8b2d00a6a1..f9b08a12b6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -947,7 +947,7 @@ nfp_cpp_alloc(struct rte_pci_device *pci_dev, * NOTE: cpp_lock is NOT locked for op->init, * since it may call NFP CPP API operations */ - err = cpp->op->init(cpp, pci_dev); + err = cpp->op->init(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "NFP interface initialization failed"); free(cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 00/26] refact the nfpcore module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (25 preceding siblings ...) 2023-09-18 2:46 ` [PATCH v4 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He ` (25 more replies) 2023-09-20 1:28 ` [PATCH v5 25/26] net/nfp: refact the cppcore and PCIe module Chaoyong He 2023-09-20 1:29 ` [PATCH v5 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 28 siblings, 26 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He This patch series aims to: - Make the coding style satisfy with DPDK. - Sync the logic with kernel driver. - Make the sub-module more modular. - Extend the nfp configure BAR from 8 to 24. --- v5: * Fix one bug in the logic of VF using dev module. * Remove the R-b tag as the requirement of Niklas. * Revise logic follow the advice of reviewer. v4: * Drop the commit 'using the DPDK memory management API'. * Modify the commit message of 'standard the comment style'. * Revise some comment logic as the advice of reviewer. v3: * Fix one bug in the BAR find logic. * Modify more coding style. v2: * Fix the compile error in Fodora 37 environment. --- Chaoyong He (26): net/nfp: explicitly compare to null and 0 net/nfp: unify the indent coding style net/nfp: unify the type of integer variable net/nfp: remove the unneeded logic net/nfp: standard the local variable coding style net/nfp: adjust the log statement net/nfp: standard the comment style net/nfp: standard the blank character net/nfp: unify the guide line of header file net/nfp: rename some parameter and variable net/nfp: refact the hwinfo module net/nfp: refact the nffw module net/nfp: refact the mip module net/nfp: refact the rtsym module net/nfp: refact the resource module net/nfp: refact the target module net/nfp: add a new header file net/nfp: refact the nsp module net/nfp: refact the mutex module net/nfp: rename data field to sync with kernel driver net/nfp: add the dev module net/nfp: add header file for PCIe module net/nfp: refact the cppcore module net/nfp: refact the PCIe module net/nfp: refact the cppcore and PCIe module net/nfp: extend the usage of nfp BAR from 8 to 24 drivers/net/nfp/flower/nfp_flower.c | 17 +- drivers/net/nfp/flower/nfp_flower.h | 3 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 3 +- drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 +- drivers/net/nfp/nfp_common.h | 52 +- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 106 +- drivers/net/nfp/nfp_ethdev_vf.c | 25 +- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 - drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 - drivers/net/nfp/nfpcore/nfp6000_pcie.c | 1035 ++++++++++++++++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 20 + drivers/net/nfp/nfpcore/nfp_cpp.h | 776 +++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 824 ------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 1080 +++++++++++------ drivers/net/nfp/nfpcore/nfp_crc.c | 23 +- drivers/net/nfp/nfpcore/nfp_dev.c | 81 ++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 193 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 74 +- drivers/net/nfp/nfpcore/nfp_mip.c | 97 +- drivers/net/nfp/nfpcore/nfp_mip.h | 7 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 379 +++--- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 + drivers/net/nfp/nfpcore/nfp_nffw.c | 202 +-- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 574 ++++++--- drivers/net/nfp/nfpcore/nfp_nsp.h | 336 ++--- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 19 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 518 ++++---- drivers/net/nfp/nfpcore/nfp_platform.h | 42 + drivers/net/nfp/nfpcore/nfp_resource.c | 208 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 36 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 452 +++++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 67 +- drivers/net/nfp/nfpcore/nfp_target.c | 9 +- drivers/net/nfp/nfpcore/nfp_target.h | 597 +-------- 41 files changed, 4083 insertions(+), 4012 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.c create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h delete mode 100644 drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 01/26] net/nfp: explicitly compare to null and 0 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 02/26] net/nfp: unify the indent coding style Chaoyong He ` (24 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He To compliance with the coding standard, make the pointer variable explicitly comparing to 'NULL' and the integer variable explicitly comparing to '0'. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 ++++++------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 16 ++++++++-------- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 8 ++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 4 ++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 20 ++++++++++---------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++++----- drivers/net/nfp/nfpcore/nfp_resource.c | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 4 ++-- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 658c618ee6..2ee60eefc3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -224,10 +224,10 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, newcfg |= offset >> bitsize; - if (bar_base) + if (bar_base != NULL) *bar_base = offset; - if (bar_config) + if (bar_config != NULL) *bar_config = newcfg; return 0; @@ -266,7 +266,7 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); - if (err) + if (err != 0) return err; bar->base = newbase; @@ -515,7 +515,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) { + if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } @@ -583,7 +583,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, return -EINVAL; /* Unaligned? Translate to an explicit access */ - if ((priv->offset + offset) & (width - 1)) + if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; is_64 = width == TARGET_WIDTH_64; @@ -764,7 +764,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) if (rte_eal_process_type() == RTE_PROC_PRIMARY && cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); - if (ret) + if (ret != 0) goto error; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 6daee313ce..31338e0047 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -235,7 +235,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, if (area == NULL) return NULL; - if (nfp_cpp_area_acquire(area)) { + if (nfp_cpp_area_acquire(area) != 0) { nfp_cpp_area_free(area); return NULL; } @@ -252,7 +252,7 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, void nfp_cpp_area_free(struct nfp_cpp_area *area) { - if (area->cpp->op->area_cleanup) + if (area->cpp->op->area_cleanup != NULL) area->cpp->op->area_cleanup(area); free(area); } @@ -280,7 +280,7 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) int nfp_cpp_area_acquire(struct nfp_cpp_area *area) { - if (area->cpp->op->area_acquire) { + if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); if (err < 0) @@ -299,7 +299,7 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) void nfp_cpp_area_release(struct nfp_cpp_area *area) { - if (area->cpp->op->area_release) + if (area->cpp->op->area_release != NULL) area->cpp->op->area_release(area); } @@ -319,7 +319,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) { void *iomem = NULL; - if (area->cpp->op->area_iomem) + if (area->cpp->op->area_iomem != NULL) iomem = area->cpp->op->area_iomem(area); return iomem; @@ -621,10 +621,10 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) void nfp_cpp_free(struct nfp_cpp *cpp) { - if (cpp->op && cpp->op->free) + if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len) + if (cpp->serial_len != 0) free(cpp->serial); free(cpp); @@ -833,7 +833,7 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if (*model & NFP_PL_DEVICE_ID_MASK) + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) *model -= 0x10; return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 9054bb0315..a9d166c4dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -37,7 +37,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { const char *key, *val, *end = hwinfo->data + size; - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { @@ -141,7 +141,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); - if (db) + if (db != NULL) return db; nanosleep(&wait, NULL); @@ -164,7 +164,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return NULL; err = nfp_hwinfo_db_validate(db, hwdb_size); - if (err) { + if (err != 0) { free(db); return NULL; } @@ -188,7 +188,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); - for (key = hwinfo->data; *key && key < end; + for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { val = key + strlen(key) + 1; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 6b392ad5eb..f9723dd136 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -75,7 +75,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) return -ENODEV; err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr); - if (err) + if (err != 0) goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); @@ -105,7 +105,7 @@ nfp_mip_open(struct nfp_cpp *cpp) return NULL; err = nfp_mip_read_resource(cpp, mip); - if (err) { + if (err != 0) { free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index f967a29351..0410a00856 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -38,7 +38,7 @@ static int _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) { /* Address must be 64-bit aligned */ - if (address & 7) + if ((address & 7) != 0) return -EINVAL; if (NFP_CPP_MODEL_IS_6000(model)) { diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 07d63900dc..433780a5e7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -190,7 +190,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; for (i = 0; i < cnt; i++) - if (nffw_fwinfo_loaded_get(&fwinfo[i])) + if (nffw_fwinfo_loaded_get(&fwinfo[i]) != 0) return &fwinfo[i]; return NULL; @@ -217,7 +217,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); *off = nffw_fwinfo_mip_offset_get(fwinfo); - if (nffw_fwinfo_mip_mu_da_get(fwinfo)) { + if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 1f6b7bd85c..6474abf0c2 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -95,7 +95,7 @@ nfp_nsp_check(struct nfp_nsp *state) return -EINVAL; } - if (reg & NSP_STATUS_BUSY) { + if ((reg & NSP_STATUS_BUSY) != 0) { PMD_DRV_LOG(ERR, "Service processor busy!"); return -EBUSY; } @@ -128,7 +128,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) state->res = res; err = nfp_nsp_check(state); - if (err) { + if (err != 0) { nfp_nsp_close(state); return NULL; } @@ -219,7 +219,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err) + if (err != 0) return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || @@ -245,7 +245,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -254,7 +254,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, /* Wait for NSP_STATUS_BUSY to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", err, code); return err; @@ -266,7 +266,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); - if (err) { + if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); @@ -319,13 +319,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); - if (in_buf && in_size) { + if (in_buf != NULL && in_size > 0) { err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf && out_size && out_size > in_size) { + if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, out_size - in_size); @@ -337,7 +337,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (ret < 0) return ret; - if (out_buf && out_size) { + if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); if (err < 0) return err; @@ -369,7 +369,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } - if (err) + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 01b4652280..825a84a8cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -212,7 +212,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, dst->fec_modes_supported |= fec << NFP_FEC_BASER_BIT; fec = FIELD_GET(NSP_ETH_PORT_FEC_SUPP_RS, port); dst->fec_modes_supported |= fec << NFP_FEC_REED_SOLOMON_BIT; - if (dst->fec_modes_supported) + if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); @@ -285,7 +285,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) cnt++; } @@ -294,7 +294,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * those that give a port count, verify it against the value calculated * above. */ - if (ret && ret != cnt) { + if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; @@ -309,7 +309,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) && + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && !rte_is_zero_ether_addr(mac)) nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); @@ -621,7 +621,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) return -EIO; err = __nfp_eth_set_fec(nsp, mode); - if (err) { + if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 351bc623ed..838cd6e0ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -115,15 +115,15 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, { int err; - if (nfp_cpp_mutex_lock(dev_mutex)) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) return -EINVAL; err = nfp_cpp_resource_find(cpp, res); - if (err) + if (err != 0) goto err_unlock_dev; err = nfp_cpp_mutex_trylock(res->mutex); - if (err) + if (err != 0) goto err_res_mutex_free; nfp_cpp_mutex_unlock(dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 343b0d0bcf..4c45aec5c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -362,10 +362,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) if (err) err = -EIO; exit: - if (error) + if (error != NULL) *error = err; - if (err) + if (err != 0) return ~0ULL; return val; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 02/26] net/nfp: unify the indent coding style 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 03/26] net/nfp: unify the type of integer variable Chaoyong He ` (23 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Each parameter of function should occupy one line, and indent two TAB character. All the statement which span multi line should indent two TAB character. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 80 +++++----- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 152 ++++++++++-------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 173 +++++++++++++-------- drivers/net/nfp/nfpcore/nfp_crc.c | 19 ++- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 23 +-- drivers/net/nfp/nfpcore/nfp_mip.c | 21 ++- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 12 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 108 +++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 19 +-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 72 +++++---- drivers/net/nfp/nfpcore/nfp_resource.c | 29 ++-- drivers/net/nfp/nfpcore/nfp_resource.h | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 38 +++-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 15 +- 17 files changed, 463 insertions(+), 331 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 8f87c09327..54bef3cb6b 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -56,7 +56,8 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp, + struct rte_pci_device *dev); /* * Free the bus. @@ -69,9 +70,9 @@ struct nfp_cpp_operations { * NOTE: This is _not_ serialized */ int (*area_init)(struct nfp_cpp_area *area, - uint32_t dest, - unsigned long long address, - unsigned long size); + uint32_t dest, + unsigned long long address, + unsigned long size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -101,17 +102,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_read)(struct nfp_cpp_area *area, - void *kernel_vaddr, - unsigned long offset, - unsigned int length); + void *kernel_vaddr, + unsigned long offset, + unsigned int length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, - const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + const void *kernel_vaddr, + unsigned long offset, + unsigned int length); }; /* @@ -239,7 +240,7 @@ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); * @param len Length of the serial byte array */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len); + size_t serial_len); /* * Set the private data of the nfp_cpp instance @@ -279,7 +280,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + int driver_lock_needed); /* * Free a NFP CPP handle @@ -397,8 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, - unsigned long size); + unsigned long long address, unsigned long size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,10 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, - const char *name, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, unsigned long long address, + unsigned long size); /* * Free an allocated NFP CPP area handle @@ -448,9 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, - unsigned long long address, - unsigned long size); + uint32_t cpp_id, unsigned long long address, unsigned long size); /* * Release the resources, then free the NFP CPP area handle @@ -459,8 +455,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, - struct nfp_cpp_area **area); + uint64_t addr, unsigned long size, struct nfp_cpp_area **area); /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -484,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * */ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *buffer, size_t length); + void *buffer, size_t length); /* * Write to a NFP CPP area handle from a buffer. The area must be acquired with @@ -498,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *buffer, size_t length); + const void *buffer, size_t length); /* * nfp_cpp_area_iomem() - get IOMEM region for CPP area @@ -522,7 +517,7 @@ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); * @return 0 on success, negative value on failure. */ int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); + unsigned long long offset, unsigned long size); /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle @@ -552,7 +547,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + unsigned long long address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -566,8 +561,8 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); + unsigned long long address, const void *kernel_vaddr, + size_t length); @@ -582,7 +577,7 @@ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, negative value on failure. */ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); + uint32_t value, size_t length); /* * Read a single 32-bit value from a NFP CPP area handle @@ -599,7 +594,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value); + uint32_t *value); /* * Write a single 32-bit value to a NFP CPP area handle @@ -616,7 +611,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value); + uint32_t value); /* * Read a single 64-bit value from a NFP CPP area handle @@ -633,7 +628,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value); + uint64_t *value); /* * Write a single 64-bit value to a NFP CPP area handle @@ -650,7 +645,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * @return 0 on success, or -1 on error. */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value); + uint64_t value); /* * Write a single 32-bit value on the XPB bus @@ -685,7 +680,7 @@ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); * @return 0 on success, or -1 on failure. */ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); + uint32_t value); /* * Modify bits of a 32-bit value from the XPB bus @@ -699,7 +694,7 @@ int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, negative value on failure. */ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); + uint32_t value, int timeout_us); /* * Read a 32-bit word from a NFP CPP ID @@ -712,7 +707,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + unsigned long long address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -726,7 +721,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + unsigned long long address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -739,7 +734,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + unsigned long long address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -752,7 +747,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + unsigned long long address, uint64_t value); /* * Initialize a mutex location @@ -773,7 +768,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -793,8 +788,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, - uint32_t key_id); + unsigned long long address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 2ee60eefc3..884cc84eaa 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -130,9 +130,15 @@ nfp_bar_maptype(struct nfp_bar *bar) #define TARGET_WIDTH_64 8 static int -nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, - uint64_t *bar_base, int tgt, int act, int tok, - uint64_t offset, size_t size, int width) +nfp_compute_bar(const struct nfp_bar *bar, + uint32_t *bar_config, + uint64_t *bar_base, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint32_t bitsize; uint32_t newcfg; @@ -143,19 +149,16 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, switch (width) { case 8: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT); break; case 4: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT); break; case 0: - newcfg = - NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT - (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); + newcfg = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT + (NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE); break; default: return -EINVAL; @@ -165,60 +168,58 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), act, + (unsigned long long)mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + bar->index, tgt, act, tok, (unsigned long long)offset, + (unsigned long long)(offset + mask)); bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); /* Bulk mapping */ - newcfg |= - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE - (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); if ((offset & mask) != ((offset + size - 1) & mask)) { PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + bar->index, (unsigned long long)offset, + (unsigned long long)(offset + size), + tgt, tok, (unsigned long long)mask, + (unsigned long long)(offset & mask), + (unsigned long long)(offset + size - 1) & mask); return -EINVAL; } offset &= mask; PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); + bar->index, tgt, tok, (unsigned long long)offset, + (unsigned long long)(offset + ~mask)); bitsize = 40 - 21; } if (bar->bitsize < bitsize) { PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + tgt, tok, act); return -EINVAL; } @@ -234,8 +235,9 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, } static int -nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - uint32_t newcfg) +nfp_bar_write(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + uint32_t newcfg) { int base, slot; @@ -246,7 +248,7 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, return (-ENOMEM); bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); *(uint32_t *)(bar->csr) = newcfg; @@ -257,15 +259,21 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, } static int -nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, int tgt, - int act, int tok, uint64_t offset, size_t size, int width) +nfp_reconfigure_bar(struct nfp_pcie_user *nfp, + struct nfp_bar *bar, + int tgt, + int act, + int tok, + uint64_t offset, + size_t size, + int width) { uint64_t newbase; uint32_t newcfg; int err; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + size, width); if (err != 0) return err; @@ -390,8 +398,10 @@ struct nfp6000_area_priv { }; static int -nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, unsigned long size) +nfp6000_area_init(struct nfp_cpp_area *area, + uint32_t dest, + unsigned long long address, + unsigned long size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -400,8 +410,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, uint32_t token = NFP_CPP_ID_TOKEN_of(dest); int pp, ret = 0; - pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), - address); + pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) return pp; @@ -409,7 +418,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->width.write = PULL_WIDTH(pp); if (priv->width.read > 0 && - priv->width.write > 0 && priv->width.read != priv->width.write) + priv->width.write > 0 && + priv->width.read != priv->width.write) return -EINVAL; if (priv->width.read > 0) @@ -428,8 +438,8 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, priv->size = size; ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); + priv->token, priv->offset, priv->size, + priv->width.bar); return ret; } @@ -441,14 +451,13 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == - NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { + NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) { priv->bar_offset = priv->offset & - (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, - priv->target); - priv->bar_offset += - NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, priv->token); + (NFP_PCIE_P2C_GENERAL_SIZE(priv->bar) - 1); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(priv->bar, + priv->target); + priv->bar_offset += NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(priv->bar, + priv->token); } else { priv->bar_offset = priv->offset & priv->bar->mask; } @@ -490,8 +499,10 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) } static int -nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_read(struct nfp_cpp_area *area, + void *kernel_vaddr, + unsigned long offset, + unsigned int length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -524,17 +535,17 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { + priv->action == NFP_CPP_ACTION_RW) { is_64 = false; } if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -558,8 +569,10 @@ nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, } static int -nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, unsigned int length) +nfp6000_area_write(struct nfp_cpp_area *area, + const void *kernel_vaddr, + unsigned long offset, + unsigned int length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -590,16 +603,16 @@ nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) + priv->action == NFP_CPP_ACTION_RW) is_64 = false; if (is_64) { if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) + length % sizeof(uint64_t) != 0) return -EINVAL; } else { if (offset % sizeof(uint32_t) != 0 || - length % sizeof(uint32_t) != 0) + length % sizeof(uint32_t) != 0) return -EINVAL; } @@ -655,7 +668,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) } static int -nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_model(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint32_t model; @@ -671,7 +685,8 @@ nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_interface(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t interface; @@ -686,7 +701,8 @@ nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) +nfp6000_set_serial(struct rte_pci_device *dev, + struct nfp_cpp *cpp) { uint16_t tmp; uint8_t serial[6]; @@ -733,7 +749,8 @@ nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) } static int -nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) +nfp6000_set_barsz(struct rte_pci_device *dev, + struct nfp_pcie_user *desc) { unsigned long tmp; int i = 0; @@ -748,7 +765,8 @@ nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) } static int -nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp, + struct rte_pci_device *dev) { int ret = 0; struct nfp_pcie_user *desc; @@ -762,7 +780,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 31338e0047..f764208a9a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -27,7 +27,8 @@ NFP_PL_DEVICE_ID_MASK) void -nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) +nfp_cpp_priv_set(struct nfp_cpp *cpp, + void *priv) { cpp->priv = priv; } @@ -39,7 +40,8 @@ nfp_cpp_priv(struct nfp_cpp *cpp) } void -nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) +nfp_cpp_model_set(struct nfp_cpp *cpp, + uint32_t model) { cpp->model = model; } @@ -62,21 +64,24 @@ nfp_cpp_model(struct nfp_cpp *cpp) } void -nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) +nfp_cpp_interface_set(struct nfp_cpp *cpp, + uint32_t interface) { cpp->interface = interface; } int -nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) +nfp_cpp_serial(struct nfp_cpp *cpp, + const uint8_t **serial) { *serial = cpp->serial; return cpp->serial_len; } int -nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, - size_t serial_len) +nfp_cpp_serial_set(struct nfp_cpp *cpp, + const uint8_t *serial, + size_t serial_len) { if (cpp->serial_len) free(cpp->serial); @@ -161,9 +166,11 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) * NOTE: @address and @size must be 32-bit aligned values. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, - const char *name, unsigned long long address, - unsigned long size) +nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, + uint32_t dest, + const char *name, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -183,7 +190,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, name = ""; area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + strlen(name) + 1); if (area == NULL) return NULL; @@ -204,8 +211,10 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, } struct nfp_cpp_area * -nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc(struct nfp_cpp *cpp, + uint32_t dest, + unsigned long long address, + unsigned long size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -226,8 +235,10 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, * NOTE: The area must also be 'released' when the structure is freed. */ struct nfp_cpp_area * -nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, unsigned long size) +nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + unsigned long size) { struct nfp_cpp_area *area; @@ -340,8 +351,10 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, - void *kernel_vaddr, size_t length) +nfp_cpp_area_read(struct nfp_cpp_area *area, + unsigned long offset, + void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -364,8 +377,10 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * NOTE: Area must have been locked down with an 'acquire'. */ int -nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, - const void *kernel_vaddr, size_t length) +nfp_cpp_area_write(struct nfp_cpp_area *area, + unsigned long offset, + const void *kernel_vaddr, + size_t length) { if ((offset + length) > area->size) return -EFAULT; @@ -392,8 +407,9 @@ nfp_cpp_area_mapped(struct nfp_cpp_area *area) * or negative value on error. */ int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, - unsigned long length) +nfp_cpp_area_check_range(struct nfp_cpp_area *area, + unsigned long long offset, + unsigned long length) { if (((offset + length) > area->size)) return -EFAULT; @@ -406,7 +422,8 @@ nfp_cpp_area_check_range(struct nfp_cpp_area *area, unsigned long long offset, * based upon NFP model. */ static uint32_t -nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) +nfp_xpb_to_cpp(struct nfp_cpp *cpp, + uint32_t *xpb_addr) { uint32_t xpb; int island; @@ -433,7 +450,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) else /* And only non-ARM interfaces use island id = 1 */ if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) + NFP_CPP_INTERFACE_TYPE_ARM) *xpb_addr |= (1 << 24); } else { (*xpb_addr) |= (1 << 30); @@ -443,8 +460,9 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) } int -nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, - uint32_t *value) +nfp_cpp_area_readl(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t *value) { int sz; uint32_t tmp = 0; @@ -456,8 +474,9 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value) +nfp_cpp_area_writel(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value) { int sz; @@ -467,8 +486,9 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t *value) +nfp_cpp_area_readq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t *value) { int sz; uint64_t tmp = 0; @@ -480,8 +500,9 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, - uint64_t value) +nfp_cpp_area_writeq(struct nfp_cpp_area *area, + unsigned long offset, + uint64_t value) { int sz; @@ -492,8 +513,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, } int -nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t *value) +nfp_cpp_readl(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t *value) { int sz; uint32_t tmp; @@ -505,8 +528,10 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint32_t value) +nfp_cpp_writel(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint32_t value) { int sz; @@ -517,8 +542,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t *value) +nfp_cpp_readq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t *value) { int sz; uint64_t tmp; @@ -530,8 +557,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, - uint64_t value) +nfp_cpp_writeq(struct nfp_cpp *cpp, + uint32_t cpp_id, + unsigned long long address, + uint64_t value) { int sz; @@ -542,7 +571,9 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, unsigned long long address, } int -nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) +nfp_xpb_writel(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t value) { uint32_t cpp_dest; @@ -552,7 +583,9 @@ nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t value) } int -nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) +nfp_xpb_readl(struct nfp_cpp *cpp, + uint32_t xpb_addr, + uint32_t *value) { uint32_t cpp_dest; @@ -562,7 +595,8 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *dev, + int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -596,7 +630,7 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + (tgt * 4); err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + (uint32_t *)&cpp->imb_cat_table[tgt]); if (err < 0) { free(cpp); return NULL; @@ -631,7 +665,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) } struct nfp_cpp * -nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) +nfp_cpp_from_device_name(struct rte_pci_device *dev, + int driver_lock_needed) { return nfp_cpp_alloc(dev, driver_lock_needed); } @@ -647,7 +682,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) * @return 0 on success, or -1 on failure. */ int -nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, +nfp_xpb_writelm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, uint32_t value) { int err; @@ -674,8 +711,11 @@ nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return >= 0 on success, or negative value on failure. */ int -nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us) +nfp_xpb_waitlm(struct nfp_cpp *cpp, + uint32_t xpb_tgt, + uint32_t mask, + uint32_t value, + int timeout_us) { uint32_t tmp; int err; @@ -716,8 +756,11 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @length: number of bytes to read */ int -nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, void *kernel_vaddr, size_t length) +nfp_cpp_read(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -743,9 +786,11 @@ nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, * @length: number of bytes to write */ int -nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, const void *kernel_vaddr, - size_t length) +nfp_cpp_write(struct nfp_cpp *cpp, + uint32_t destination, + unsigned long long address, + const void *kernel_vaddr, + size_t length) { struct nfp_cpp_area *area; int err; @@ -768,8 +813,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, * @length: length of area to fill */ int -nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length) +nfp_cpp_area_fill(struct nfp_cpp_area *area, + unsigned long offset, + uint32_t value, + size_t length) { int err; size_t i; @@ -795,9 +842,8 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = - nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); + err = nfp_cpp_area_write(area, offset + i, &value64, + sizeof(value64)); if (err < 0) return err; if (err != sizeof(value64)) @@ -805,8 +851,7 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, } if ((i + sizeof(value)) <= length) { - err = - nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); + err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); if (err < 0) return err; if (err != sizeof(value)) @@ -822,13 +867,14 @@ nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) +__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, + uint32_t *model) { uint32_t reg; int err; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, - ®); + ®); if (err < 0) return err; @@ -853,8 +899,11 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) * Return: Pointer to memory mapped area or NULL */ uint8_t * -nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, struct nfp_cpp_area **area) +nfp_cpp_map_area(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + unsigned long size, + struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 20431bf845..2cd8866253 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -9,27 +9,31 @@ #include "nfp_crc.h" static inline uint32_t -nfp_crc32_be_generic(uint32_t crc, unsigned char const *p, size_t len, - uint32_t polynomial) +nfp_crc32_be_generic(uint32_t crc, + unsigned char const *p, + size_t len, + uint32_t polynomial) { int i; while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) - crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : - 0); + crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); } return crc; } static inline uint32_t -nfp_crc32_be(uint32_t crc, unsigned char const *p, size_t len) +nfp_crc32_be(uint32_t crc, + unsigned char const *p, + size_t len) { return nfp_crc32_be_generic(crc, p, len, CRCPOLY_BE); } static uint32_t -nfp_crc32_posix_end(uint32_t crc, size_t total_len) +nfp_crc32_posix_end(uint32_t crc, + size_t total_len) { /* Extend with the length of the string. */ while (total_len != 0) { @@ -43,7 +47,8 @@ nfp_crc32_posix_end(uint32_t crc, size_t total_len) } uint32_t -nfp_crc32_posix(const void *buff, size_t len) +nfp_crc32_posix(const void *buff, + size_t len) { return nfp_crc32_posix_end(nfp_crc32_be(0, buff, len), len); } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index a9d166c4dc..ea4c7d6a9e 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -33,12 +33,13 @@ nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) } static int -nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) +nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, + uint32_t size) { const char *key, *val, *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (val >= end) { PMD_DRV_LOG(ERR, "Bad HWINFO - overflowing value"); @@ -54,7 +55,8 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) } static int -nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) +nfp_hwinfo_db_validate(struct nfp_hwinfo *db, + uint32_t len) { uint32_t size, new_crc, *crc; @@ -69,7 +71,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", - new_crc, *crc); + new_crc, *crc); return -EINVAL; } @@ -77,7 +79,8 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) } static struct nfp_hwinfo * -nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) +nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, + size_t *cpp_size) { struct nfp_hwinfo *header; void *res; @@ -115,7 +118,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) if (header->version != NFP_HWINFO_VERSION_2) { PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", - header->version); + header->version); goto exit_free; } @@ -129,7 +132,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) } static struct nfp_hwinfo * -nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) +nfp_hwinfo_fetch(struct nfp_cpp *cpp, + size_t *hwdb_size) { struct timespec wait; struct nfp_hwinfo *db; @@ -179,7 +183,8 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) * Return: Value of the HWInfo name, or NULL */ const char * -nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) +nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, + const char *lookup) { const char *key, *val, *end; @@ -189,7 +194,7 @@ nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) end = hwinfo->data + hwinfo->size - sizeof(uint32_t); for (key = hwinfo->data; *key != 0 && key < end; - key = val + strlen(val) + 1) { + key = val + strlen(val) + 1) { val = key + strlen(key) + 1; if (strcmp(key, lookup) == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index f9723dd136..0071d3fc37 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -37,8 +37,10 @@ struct nfp_mip { /* Read memory and check if it could be a valid MIP */ static int -nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - struct nfp_mip *mip) +nfp_mip_try_read(struct nfp_cpp *cpp, + uint32_t cpp_id, + uint64_t addr, + struct nfp_mip *mip) { int ret; @@ -49,12 +51,12 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, } if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", - rte_le_to_cpu_32(mip->signature)); + rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", - rte_le_to_cpu_32(mip->mip_version)); + rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -63,7 +65,8 @@ nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, /* Try to locate MIP using the resource table */ static int -nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) +nfp_mip_read_resource(struct nfp_cpp *cpp, + struct nfp_mip *mip) { struct nfp_nffw_info *nffw_info; uint32_t cpp_id; @@ -134,7 +137,9 @@ nfp_mip_name(const struct nfp_mip *mip) * @size: Location for size of MIP symbol table */ void -nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_symtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->symtab_addr); *size = rte_le_to_cpu_32(mip->symtab_size); @@ -147,7 +152,9 @@ nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) * @size: Location for size of MIP symbol name table */ void -nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size) +nfp_mip_strtab(const struct nfp_mip *mip, + uint32_t *addr, + uint32_t *size) { *addr = rte_le_to_cpu_32(mip->strtab_addr); *size = rte_le_to_cpu_32(mip->strtab_size); diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index d0919b58fe..980abc2517 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,5 +17,5 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *off); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 0410a00856..047e755416 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,9 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) +_nfp_cpp_mutex_validate(uint32_t model, + int *target, + unsigned long long address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -72,8 +74,10 @@ _nfp_cpp_mutex_validate(uint32_t model, int *target, unsigned long long address) * @return 0 on success, or negative value on failure. */ int -nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, - uint32_t key) +nfp_cpp_mutex_init(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ @@ -87,9 +91,8 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, if (err < 0) return err; - err = - nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address + 0, + MUTEX_LOCKED(nfp_cpp_interface(cpp))); if (err < 0) return err; @@ -114,8 +117,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, unsigned long long address, * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * -nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key) +nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, + int target, + unsigned long long address, + uint32_t key) { uint32_t model = nfp_cpp_model(cpp); struct nfp_cpp_mutex *mutex; @@ -265,8 +270,8 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return err; if (time(NULL) >= warn_at) { PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", - mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->usage, mutex->depth, mutex->target, + mutex->address, mutex->key); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 433780a5e7..fa65956baa 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -85,7 +85,8 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) } static unsigned int -nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) +nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, + struct nffw_fwinfo **arr) { /* * For the this code, version 0 is most likely to be version 1 in this @@ -138,8 +139,8 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) goto err_release; err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), - nfp_resource_address(state->res), - fwinf, sizeof(*fwinf)); + nfp_resource_address(state->res), + fwinf, sizeof(*fwinf)); if (err < (int)sizeof(*fwinf)) goto err_release; @@ -205,8 +206,9 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) * Return: 0, or -ERRNO */ int -nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) +nfp_nffw_info_mip_first(struct nfp_nffw_info *state, + uint32_t *cpp_id, + uint64_t *off) { struct nffw_fwinfo *fwinfo; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 6474abf0c2..4f476f6f2b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -22,7 +22,8 @@ nfp_nsp_config_modified(struct nfp_nsp *state) } void -nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified) +nfp_nsp_config_set_modified(struct nfp_nsp *state, + int modified) { state->modified = modified; } @@ -40,7 +41,9 @@ nfp_nsp_config_idx(struct nfp_nsp *state) } void -nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx) +nfp_nsp_config_set_state(struct nfp_nsp *state, + void *entries, + unsigned int idx) { state->entries = entries; state->idx = idx; @@ -91,7 +94,7 @@ nfp_nsp_check(struct nfp_nsp *state) if (state->ver.major != NSP_MAJOR || state->ver.minor < NSP_MINOR) { PMD_DRV_LOG(ERR, "Unsupported ABI %hu.%hu", state->ver.major, - state->ver.minor); + state->ver.minor); return -EINVAL; } @@ -160,8 +163,12 @@ nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state) } static int -nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, - uint64_t addr, uint64_t mask, uint64_t val) +nfp_nsp_wait_reg(struct nfp_cpp *cpp, + uint64_t *reg, + uint32_t nsp_cpp, + uint64_t addr, + uint64_t mask, + uint64_t val) { struct timespec wait; int count; @@ -204,8 +211,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t *reg, uint32_t nsp_cpp, * -ETIMEDOUT if the NSP took longer than 30 seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, - uint32_t buff_cpp, uint64_t buff_addr) +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code, + uint32_t option, + uint32_t buff_cpp, + uint64_t buff_addr) { uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; struct nfp_cpp *cpp = state->cpp; @@ -223,40 +233,40 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, return err; if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { + !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); + buff_cpp, buff_addr); return -EINVAL; } err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | - FIELD_PREP(NSP_COMMAND_START, 1)); + FIELD_PREP(NSP_COMMAND_OPTION, option) | + FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; /* Wait for NSP_COMMAND_START to go to 0 */ err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, - NSP_COMMAND_START, 0); + NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } /* Wait for NSP_STATUS_BUSY to go to 0 */ - err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, - 0); + err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, + NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", - err, code); + err, code); return err; } @@ -268,7 +278,7 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); + -err, (int)ret_val, code); nfp_nsp_print_extended_error(ret_val); return -err; } @@ -279,9 +289,12 @@ nfp_nsp_command(struct nfp_nsp *state, uint16_t code, uint32_t option, #define SZ_1M 0x00100000 static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, - const void *in_buf, unsigned int in_size, void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf(struct nfp_nsp *nsp, + uint16_t code, uint32_t option, + const void *in_buf, + unsigned int in_size, + void *out_buf, + unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; unsigned int max_size; @@ -291,28 +304,26 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); + code, nsp->ver.major, nsp->ver.minor); return -EOPNOTSUPP; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER_CONFIG, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); if (err < 0) return err; max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); + code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + - NSP_DFLT_BUFFER, - ®); + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, + ®); if (err < 0) return err; @@ -328,7 +339,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, uint16_t code, uint32_t option, if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + out_size - in_size); if (err < 0) return err; } @@ -388,38 +399,47 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) } int -nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_load_fw(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_eth_table(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) +nfp_nsp_write_eth_table(struct nfp_nsp *state, + const void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + NULL, 0); } int -nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size) +nfp_nsp_read_identify(struct nfp_nsp *state, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + buf, size); } int -nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, void *buf, - unsigned int size) +nfp_nsp_read_sensors(struct nfp_nsp *state, + unsigned int sensor_mask, + void *buf, + unsigned int size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + 0, buf, size); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 9905b2d3d3..1e2deaabb4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -114,9 +114,10 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); + void *buf, unsigned int size); -static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) +static inline int +nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } @@ -229,22 +230,22 @@ struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); + int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + unsigned int size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + unsigned int idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) +static inline int +nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return !!eth_port->fec_modes_supported; } @@ -297,6 +298,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + long *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 21b338461e..28dba27124 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -73,7 +73,9 @@ struct nfp_sensors { }; int -nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val) +nfp_hwmon_read_sensor(struct nfp_cpp *cpp, + enum nfp_nsp_sensor_id id, + long *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 825a84a8cd..51bd57033e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -159,7 +159,8 @@ nfp_eth_speed2rate(unsigned int speed) } static void -nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) +nfp_eth_copy_mac_reverse(uint8_t *dst, + const uint8_t *src) { int i; @@ -168,8 +169,10 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) } static void -nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, struct nfp_eth_table_port *dst) +nfp_eth_port_translate(struct nfp_nsp *nsp, + const union eth_table_entry *src, + unsigned int index, + struct nfp_eth_table_port *dst) { unsigned int rate; unsigned int fec; @@ -225,21 +228,21 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, - table->ports[i].index); + table->ports[i].index); for (j = 0; j < table->count; j++) { if (table->ports[i].label_port != - table->ports[j].label_port) + table->ports[j].label_port) continue; table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; if (table->ports[i].label_subport == - table->ports[j].label_subport) + table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", - table->ports[i].label_port, - table->ports[i].label_subport); + table->ports[i].label_port, + table->ports[i].label_subport); table->ports[i].is_split = 1; } @@ -296,7 +299,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) */ if (ret != 0 && ret != cnt) { PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", - ret, cnt); + ret, cnt); goto err; } @@ -354,7 +357,8 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) } struct nfp_nsp * -nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx) +nfp_eth_config_start(struct nfp_cpp *cpp, + unsigned int idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -447,7 +451,9 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) * -ERRNO - configuration failed. */ int -nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) +nfp_eth_set_mod_enable(struct nfp_cpp *cpp, + unsigned int idx, + int enable) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -487,7 +493,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable) * -ERRNO - configuration failed. */ int -nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) +nfp_eth_set_configured(struct nfp_cpp *cpp, + unsigned int idx, + int configed) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -523,9 +531,12 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, int configed) } static int -nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, - const uint64_t mask, const unsigned int shift, - unsigned int val, const uint64_t ctrl_bit) +nfp_eth_set_bit_config(struct nfp_nsp *nsp, + unsigned int raw_idx, + const uint64_t mask, + const unsigned int shift, + unsigned int val, + const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); unsigned int idx = nfp_nsp_config_idx(nsp); @@ -560,7 +571,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, (__extension__ ({ \ typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /* @@ -574,11 +585,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx, * Return: 0 or -ERRNO. */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) +__nfp_eth_set_aneg(struct nfp_nsp *nsp, + enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_ANEG, mode, - NSP_ETH_CTRL_SET_ANEG); + NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } /* @@ -592,11 +603,11 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) * Return: 0 or -ERRNO. */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) +__nfp_eth_set_fec(struct nfp_nsp *nsp, + enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_FEC, mode, - NSP_ETH_CTRL_SET_FEC); + NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } /* @@ -611,7 +622,9 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, enum nfp_eth_fec mode) * -ERRNO - configuration failed. */ int -nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) +nfp_eth_set_fec(struct nfp_cpp *cpp, + unsigned int idx, + enum nfp_eth_fec mode) { struct nfp_nsp *nsp; int err; @@ -642,7 +655,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) +__nfp_eth_set_speed(struct nfp_nsp *nsp, + unsigned int speed) { enum nfp_eth_rate rate; @@ -653,8 +667,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) } return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, - NSP_ETH_STATE_RATE, rate, - NSP_ETH_CTRL_SET_RATE); + NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } /* @@ -668,8 +681,9 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed) * Return: 0 or -ERRNO. */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes) +__nfp_eth_set_split(struct nfp_nsp *nsp, + unsigned int lanes) { - return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, - lanes, NSP_ETH_CTRL_SET_LANES); + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, + NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 838cd6e0ef..57089c770f 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -64,7 +64,8 @@ struct nfp_resource { }; static int -nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) +nfp_cpp_resource_find(struct nfp_cpp *cpp, + struct nfp_resource *res) { char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; struct nfp_resource_entry entry; @@ -85,7 +86,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { uint64_t addr = NFP_RESOURCE_TBL_BASE + - sizeof(struct nfp_resource_entry) * i; + sizeof(struct nfp_resource_entry) * i; ret = nfp_cpp_read(cpp, cpp_id, addr, &entry, sizeof(entry)); if (ret != sizeof(entry)) @@ -95,12 +96,11 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) continue; /* Found key! */ - res->mutex = - nfp_cpp_mutex_alloc(cpp, - NFP_RESOURCE_TBL_TARGET, addr, key); + res->mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, + addr, key); res->cpp_id = NFP_CPP_ID(entry.region.cpp_target, - entry.region.cpp_action, - entry.region.cpp_token); + entry.region.cpp_action, + entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; return 0; @@ -110,8 +110,9 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) } static int -nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, - struct nfp_cpp_mutex *dev_mutex) +nfp_resource_try_acquire(struct nfp_cpp *cpp, + struct nfp_resource *res, + struct nfp_cpp_mutex *dev_mutex) { int err; @@ -148,7 +149,8 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, struct nfp_resource *res, * Return: NFP Resource handle, or NULL */ struct nfp_resource * -nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) +nfp_resource_acquire(struct nfp_cpp *cpp, + const char *name) { struct nfp_cpp_mutex *dev_mutex; struct nfp_resource *res; @@ -165,8 +167,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) strncpy(res->name, name, NFP_RESOURCE_ENTRY_NAME_SZ); dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, - NFP_RESOURCE_TBL_BASE, - NFP_RESOURCE_TBL_KEY); + NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { free(res); return NULL; @@ -234,8 +235,8 @@ nfp_resource_cpp_id(const struct nfp_resource *res) * * Return: const char pointer to the name of the resource */ -const char -*nfp_resource_name(const struct nfp_resource *res) +const char * +nfp_resource_name(const struct nfp_resource *res) { return res->name; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 06cc6f74f4..009b7359a4 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -18,7 +18,7 @@ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, - const char *name); + const char *name); /** * Release a NFP Resource, and free the handle diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 4c45aec5c1..aa3b7a483e 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -40,22 +40,25 @@ struct nfp_rtsym_table { }; static int -nfp_meid(uint8_t island_id, uint8_t menum) +nfp_meid(uint8_t island_id, + uint8_t menum) { return (island_id & 0x3F) == island_id && menum < 12 ? (island_id << 4) | (menum + 4) : -1; } static void -nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, uint32_t strtab_size, - struct nfp_rtsym *sw, struct nfp_rtsym_entry *fw) +nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, + uint32_t strtab_size, + struct nfp_rtsym *sw, + struct nfp_rtsym_entry *fw) { sw->type = fw->type; sw->name = cache->strtab + rte_le_to_cpu_16(fw->name) % strtab_size; sw->addr = ((uint64_t)fw->addr_hi << 32) | - rte_le_to_cpu_32(fw->addr_lo); + rte_le_to_cpu_32(fw->addr_lo); sw->size = ((uint64_t)fw->size_hi << 32) | - rte_le_to_cpu_32(fw->size_lo); + rte_le_to_cpu_32(fw->size_lo); PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", sw->name, sw->addr, sw->size, sw->target); @@ -93,7 +96,8 @@ nfp_rtsym_table_read(struct nfp_cpp *cpp) } struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) +__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip) { uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; struct nfp_rtsym_entry *rtsymtab; @@ -142,7 +146,7 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) for (n = 0; n < cache->num; n++) nfp_rtsym_sw_entry_init(cache, strtab_size, - &cache->symtab[n], &rtsymtab[n]); + &cache->symtab[n], &rtsymtab[n]); free(rtsymtab); @@ -178,7 +182,8 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) +nfp_rtsym_get(struct nfp_rtsym_table *rtbl, + int idx) { if (rtbl == NULL) return NULL; @@ -197,7 +202,8 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx) * Return: const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * -nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name) +nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name) { int n; @@ -331,7 +337,9 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, * Return: value read, on error sets the error and returns ~0ULL. */ uint64_t -nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) +nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, + const char *name, + int *error) { const struct nfp_rtsym *sym; uint32_t val32; @@ -354,7 +362,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, - name, sym->size); + name, sym->size); err = -EINVAL; break; } @@ -372,8 +380,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) } uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area) +nfp_rtsym_map(struct nfp_rtsym_table *rtbl, + const char *name, + unsigned int min_size, + struct nfp_cpp_area **area) { int ret; uint8_t *mem; @@ -397,7 +407,7 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, if (sym->size < min_size) { PMD_DRV_LOG(ERR, "Symbol %s too small (%" PRIu64 " < %u)", name, - sym->size, min_size); + sym->size, min_size); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 8b494211bc..30768f1ccf 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -43,19 +43,18 @@ struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip); +struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, + const struct nfp_mip *mip); 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); +const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, + const char *name); uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, - int *error); -uint8_t * -nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + int *error); +uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, + unsigned int min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 03/26] net/nfp: unify the type of integer variable 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-09-19 9:54 ` [PATCH v5 02/26] net/nfp: unify the indent coding style Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 04/26] net/nfp: remove the unneeded logic Chaoyong He ` (22 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Unify the type of integer variable to the DPDK prefer style. Also change the return type of 'nfp_eth_speed2rate()' to the corresponding enum, which make it more readable. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 53 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 20 ++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 40 +++++++-------- drivers/net/nfp/nfpcore/nfp_crc.c | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nffw.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nsp.c | 28 +++++----- drivers/net/nfp/nfpcore/nfp_nsp.h | 59 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 52 ++++++++++--------- drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- 13 files changed, 142 insertions(+), 141 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 54bef3cb6b..782272a3f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -71,8 +71,8 @@ struct nfp_cpp_operations { */ int (*area_init)(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size); + uint64_t address, + size_t size); /* * Clean up a NFP CPP area before it is freed * NOTE: This is _not_ serialized @@ -103,16 +103,16 @@ struct nfp_cpp_operations { */ int (*area_read)(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); /* * Perform a write to a NFP CPP area * Serialized */ int (*area_write)(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length); + uint32_t offset, + size_t length); }; /* @@ -398,7 +398,7 @@ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, unsigned long size); + uint64_t address, size_t size); /* * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner @@ -411,8 +411,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, - uint32_t cpp_id, const char *name, unsigned long long address, - unsigned long size); + uint32_t cpp_id, const char *name, uint64_t address, + uint32_t size); /* * Free an allocated NFP CPP area handle @@ -446,7 +446,7 @@ void nfp_cpp_area_release(struct nfp_cpp_area *area); * @return NFP CPP handle, or NULL on failure. */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, - uint32_t cpp_id, unsigned long long address, unsigned long size); + uint32_t cpp_id, uint64_t address, size_t size); /* * Release the resources, then free the NFP CPP area handle @@ -455,7 +455,8 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t addr, unsigned long size, struct nfp_cpp_area **area); + uint64_t addr, uint32_t size, struct nfp_cpp_area **area); + /* * Return an IO pointer to the beginning of the NFP CPP area handle. The area * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. @@ -478,7 +479,7 @@ void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); * @return bytes read on success, negative value on failure. * */ -int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); /* @@ -492,7 +493,7 @@ int nfp_cpp_area_read(struct nfp_cpp_area *area, unsigned long offset, * * @return bytes written on success, negative value on failure. */ -int nfp_cpp_area_write(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); /* @@ -547,7 +548,7 @@ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); * @return bytes read on success, -1 on failure. */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, void *kernel_vaddr, size_t length); + uint64_t address, void *kernel_vaddr, size_t length); /* * Write a block of data to a NFP CPP ID @@ -561,9 +562,7 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, * @return bytes written on success, -1 on failure. */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, const void *kernel_vaddr, - size_t length); - + uint64_t address, const void *kernel_vaddr, size_t length); /* @@ -593,7 +592,7 @@ int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); /* @@ -610,7 +609,7 @@ int nfp_cpp_area_readl(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); /* @@ -627,7 +626,7 @@ int nfp_cpp_area_writel(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); /* @@ -644,7 +643,7 @@ int nfp_cpp_area_readq(struct nfp_cpp_area *area, unsigned long offset, * * @return 0 on success, or -1 on error. */ -int nfp_cpp_area_writeq(struct nfp_cpp_area *area, unsigned long offset, +int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); /* @@ -707,7 +706,7 @@ int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t *value); + uint64_t address, uint32_t *value); /* * Write a 32-bit value to a NFP CPP ID @@ -721,7 +720,7 @@ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, * */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint32_t value); + uint64_t address, uint32_t value); /* * Read a 64-bit work from a NFP CPP ID @@ -734,7 +733,7 @@ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t *value); + uint64_t address, uint64_t *value); /* * Write a 64-bit value to a NFP CPP ID @@ -747,7 +746,7 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, or -1 on failure. */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, uint64_t value); + uint64_t address, uint64_t value); /* * Initialize a mutex location @@ -768,7 +767,7 @@ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, * @return 0 on success, negative value on failure. */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Create a mutex handle from an address controlled by a MU Atomic engine @@ -788,7 +787,7 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, * failure. */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, uint32_t key_id); + uint64_t address, uint32_t key_id); /* * Get the NFP CPP handle the mutex was created with diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 884cc84eaa..881f21bfd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -101,7 +101,7 @@ struct nfp_bar { uint64_t base; /* CPP address base */ uint64_t mask; /* Bit mask of the bar */ uint32_t bitsize; /* Bit size of the bar */ - int index; + uint32_t index; int lock; char *csr; @@ -400,8 +400,8 @@ struct nfp6000_area_priv { static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); @@ -501,8 +501,8 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { uint64_t *wrptr64 = kernel_vaddr; const volatile uint64_t *rdptr64; @@ -510,7 +510,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -571,8 +571,8 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, const void *kernel_vaddr, - unsigned long offset, - unsigned int length) + uint32_t offset, + size_t length) { const uint64_t *rdptr64 = kernel_vaddr; uint64_t *wrptr64; @@ -580,7 +580,7 @@ nfp6000_area_write(struct nfp_cpp_area *area, struct nfp6000_area_priv *priv; uint32_t *wrptr32; int width; - unsigned int n; + size_t n; bool is_64; priv = nfp_cpp_area_priv(area); @@ -752,7 +752,7 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - unsigned long tmp; + uint64_t tmp; int i = 0; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f764208a9a..627d4eaa5d 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -169,8 +169,8 @@ struct nfp_cpp_area * nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest, const char *name, - unsigned long long address, - unsigned long size) + uint64_t address, + uint32_t size) { struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; @@ -184,7 +184,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, if (err < 0) return NULL; - address = (unsigned long long)tmp64; + address = tmp64; if (name == NULL) name = ""; @@ -213,8 +213,8 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { return nfp_cpp_area_alloc_with_name(cpp, dest, NULL, address, size); } @@ -237,8 +237,8 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, struct nfp_cpp_area * nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, - unsigned long size) + uint64_t address, + size_t size) { struct nfp_cpp_area *area; @@ -352,7 +352,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) */ int nfp_cpp_area_read(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, void *kernel_vaddr, size_t length) { @@ -378,7 +378,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, */ int nfp_cpp_area_write(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, const void *kernel_vaddr, size_t length) { @@ -461,7 +461,7 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, int nfp_cpp_area_readl(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t *value) { int sz; @@ -475,7 +475,7 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, int nfp_cpp_area_writel(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint32_t value) { int sz; @@ -487,7 +487,7 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, int nfp_cpp_area_readq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t *value) { int sz; @@ -501,7 +501,7 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, int nfp_cpp_area_writeq(struct nfp_cpp_area *area, - unsigned long offset, + uint32_t offset, uint64_t value) { int sz; @@ -515,7 +515,7 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t *value) { int sz; @@ -530,7 +530,7 @@ nfp_cpp_readl(struct nfp_cpp *cpp, int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint32_t value) { int sz; @@ -544,7 +544,7 @@ nfp_cpp_writel(struct nfp_cpp *cpp, int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t *value) { int sz; @@ -559,7 +559,7 @@ nfp_cpp_readq(struct nfp_cpp *cpp, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, - unsigned long long address, + uint64_t address, uint64_t value) { int sz; @@ -758,7 +758,7 @@ nfp_xpb_waitlm(struct nfp_cpp *cpp, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, void *kernel_vaddr, size_t length) { @@ -788,7 +788,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - unsigned long long address, + uint64_t address, const void *kernel_vaddr, size_t length) { @@ -902,7 +902,7 @@ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, - unsigned long size, + uint32_t size, struct nfp_cpp_area **area) { uint8_t *res; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 2cd8866253..68f27f8c68 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -14,7 +14,7 @@ nfp_crc32_be_generic(uint32_t crc, size_t len, uint32_t polynomial) { - int i; + uint32_t i; while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 047e755416..7ac06e897a 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -28,16 +28,16 @@ struct nfp_cpp_mutex { struct nfp_cpp *cpp; uint8_t target; uint16_t depth; - unsigned long long address; + uint64_t address; uint32_t key; - unsigned int usage; + uint32_t usage; struct nfp_cpp_mutex *prev, *next; }; static int _nfp_cpp_mutex_validate(uint32_t model, int *target, - unsigned long long address) + uint64_t address) { /* Address must be 64-bit aligned */ if ((address & 7) != 0) @@ -76,7 +76,7 @@ _nfp_cpp_mutex_validate(uint32_t model, int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -119,7 +119,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - unsigned long long address, + uint64_t address, uint32_t key) { uint32_t model = nfp_cpp_model(cpp); @@ -269,9 +269,10 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] target:%d addr:%llx key:%08x]", + PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] " + "target:%d key:%08x] addr:%" PRIx64, mutex->usage, mutex->depth, mutex->target, - mutex->address, mutex->key); + mutex->key, mutex->address); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index fa65956baa..2412dc0e00 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,7 +68,7 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - unsigned int mode, addr40; + uint32_t mode, addr40; uint32_t xpbaddr, imbcppat; int err; @@ -84,7 +84,7 @@ nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) return nfp_cppat_mu_locality_lsb(mode, addr40); } -static unsigned int +static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) { @@ -184,7 +184,7 @@ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { struct nffw_fwinfo *fwinfo; - unsigned int cnt, i; + uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4f476f6f2b..dfe396c8ac 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -34,7 +34,7 @@ nfp_nsp_config_entries(struct nfp_nsp *state) return state->entries; } -unsigned int +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state) { return state->idx; @@ -43,7 +43,7 @@ nfp_nsp_config_idx(struct nfp_nsp *state) void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx) + uint32_t idx) { state->entries = entries; state->idx = idx; @@ -59,12 +59,12 @@ nfp_nsp_config_clear_state(struct nfp_nsp *state) static void nfp_nsp_print_extended_error(uint32_t ret_val) { - int i; + uint32_t i; if (ret_val == 0) return; - for (i = 0; i < (int)RTE_DIM(nsp_errors); i++) + for (i = 0; i < RTE_DIM(nsp_errors); i++) if (ret_val == (uint32_t)nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -171,7 +171,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t val) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -297,7 +297,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, unsigned int out_size) { struct nfp_cpp *cpp = nsp->cpp; - unsigned int max_size; + size_t max_size; uint64_t reg, cpp_buf; int ret, err; uint32_t cpp_id; @@ -316,7 +316,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, max_size = RTE_MAX(in_size, out_size); if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %u)", + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %zu)", code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); return -EINVAL; } @@ -361,7 +361,7 @@ int nfp_nsp_wait(struct nfp_nsp *state) { struct timespec wait; - int count; + uint32_t count; int err; wait.tv_sec = 0; @@ -401,7 +401,7 @@ nfp_nsp_mac_reinit(struct nfp_nsp *state) int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, NULL, 0); @@ -410,7 +410,7 @@ nfp_nsp_load_fw(struct nfp_nsp *state, int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, buf, size); @@ -419,7 +419,7 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, NULL, 0); @@ -428,7 +428,7 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, buf, size); @@ -436,9 +436,9 @@ nfp_nsp_read_identify(struct nfp_nsp *state, int nfp_nsp_read_sensors(struct nfp_nsp *state, - unsigned int sensor_mask, + uint32_t sensor_mask, void *buf, - unsigned int size) + size_t size) { return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, 0, buf, size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 1e2deaabb4..edb56e26ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -110,11 +110,11 @@ uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state); uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state); int nfp_nsp_wait(struct nfp_nsp *state); int nfp_nsp_device_soft_reset(struct nfp_nsp *state); -int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_mac_reinit(struct nfp_nsp *state); -int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size); -int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, - void *buf, unsigned int size); +int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); +int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, + void *buf, size_t size); static inline int nfp_nsp_has_mac_reinit(struct nfp_nsp *state) @@ -188,17 +188,17 @@ enum nfp_eth_fec { * @fec_modes_supported: bitmap of FEC modes supported */ struct nfp_eth_table { - unsigned int count; - unsigned int max_index; + uint32_t count; + uint32_t max_index; struct nfp_eth_table_port { - unsigned int eth_index; - unsigned int index; - unsigned int nbi; - unsigned int base; - unsigned int lanes; - unsigned int speed; - - unsigned int interface; + uint32_t eth_index; + uint32_t index; + uint32_t nbi; + uint32_t base; + uint32_t lanes; + uint32_t speed; + + uint32_t interface; enum nfp_eth_media media; enum nfp_eth_fec fec; @@ -218,51 +218,50 @@ struct nfp_eth_table { /* Computed fields */ uint8_t port_type; - unsigned int port_lanes; + uint32_t port_lanes; int is_split; - unsigned int fec_modes_supported; + uint32_t fec_modes_supported; } ports[]; }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, - int configed); -int nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); -int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size); +int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, - unsigned int size); + size_t size); void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, - unsigned int idx); + uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); int nfp_nsp_config_modified(struct nfp_nsp *state); -unsigned int nfp_nsp_config_idx(struct nfp_nsp *state); +uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); static inline int nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { - return !!eth_port->fec_modes_supported; + return eth_port->fec_modes_supported != 0; } -static inline unsigned int +static inline uint32_t nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported; } -struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx); +struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes); +int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /** * struct nfp_nsp_identify - NSP static information @@ -298,6 +297,6 @@ enum nfp_nsp_sensor_id { }; int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val); + uint32_t *val); #endif diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 28dba27124..31677b66e6 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -75,7 +75,7 @@ struct nfp_sensors { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, - long *val) + uint32_t *val) { struct nfp_sensors s; struct nfp_nsp *nsp; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 51bd57033e..5492840aa1 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -124,7 +124,7 @@ union eth_table_entry { static const struct { enum nfp_eth_rate rate; - unsigned int speed; + uint32_t speed; } nsp_eth_rate_tbl[] = { { RATE_INVALID, 0, }, { RATE_10M, SPEED_10, }, @@ -134,24 +134,24 @@ static const struct { { RATE_25G, SPEED_25000, }, }; -static unsigned int +static uint32_t nfp_eth_rate2speed(enum nfp_eth_rate rate) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].rate == rate) return nsp_eth_rate_tbl[i].speed; return 0; } -static unsigned int -nfp_eth_speed2rate(unsigned int speed) +static enum nfp_eth_rate +nfp_eth_speed2rate(uint32_t speed) { - int i; + uint32_t i; - for (i = 0; i < (int)RTE_DIM(nsp_eth_rate_tbl); i++) + for (i = 0; i < RTE_DIM(nsp_eth_rate_tbl); i++) if (nsp_eth_rate_tbl[i].speed == speed) return nsp_eth_rate_tbl[i].rate; @@ -162,7 +162,7 @@ static void nfp_eth_copy_mac_reverse(uint8_t *dst, const uint8_t *src) { - int i; + uint32_t i; for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) dst[RTE_ETHER_ADDR_LEN - i - 1] = src[i]; @@ -171,11 +171,11 @@ nfp_eth_copy_mac_reverse(uint8_t *dst, static void nfp_eth_port_translate(struct nfp_nsp *nsp, const union eth_table_entry *src, - unsigned int index, + uint32_t index, struct nfp_eth_table_port *dst) { - unsigned int rate; - unsigned int fec; + uint32_t rate; + uint32_t fec; uint64_t port, state; port = rte_le_to_cpu_64(src->port); @@ -224,7 +224,7 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - unsigned int i, j; + uint32_t i, j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -269,7 +269,9 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) union eth_table_entry *entries; struct nfp_eth_table *table; uint32_t table_sz; - int i, j, ret, cnt = 0; + uint32_t i; + uint32_t j; + int ret, cnt = 0; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -319,7 +321,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) } nfp_eth_calc_port_geometry(table); - for (i = 0; i < (int)table->count; i++) + for (i = 0; i < table->count; i++) nfp_eth_calc_port_type(&table->ports[i]); free(entries); @@ -358,7 +360,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, - unsigned int idx) + uint32_t idx) { union eth_table_entry *entries; struct nfp_nsp *nsp; @@ -452,7 +454,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int enable) { union eth_table_entry *entries; @@ -494,7 +496,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, */ int nfp_eth_set_configured(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, int configed) { union eth_table_entry *entries; @@ -532,14 +534,14 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, static int nfp_eth_set_bit_config(struct nfp_nsp *nsp, - unsigned int raw_idx, + uint32_t raw_idx, const uint64_t mask, - const unsigned int shift, - unsigned int val, + const uint32_t shift, + uint32_t val, const uint64_t ctrl_bit) { union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - unsigned int idx = nfp_nsp_config_idx(nsp); + uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; /* @@ -623,7 +625,7 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, */ int nfp_eth_set_fec(struct nfp_cpp *cpp, - unsigned int idx, + uint32_t idx, enum nfp_eth_fec mode) { struct nfp_nsp *nsp; @@ -656,7 +658,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, - unsigned int speed) + uint32_t speed) { enum nfp_eth_rate rate; @@ -682,7 +684,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, */ int __nfp_eth_set_split(struct nfp_nsp *nsp, - unsigned int lanes) + uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES, lanes, NSP_ETH_CTRL_SET_LANES); diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 57089c770f..9dd4832779 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -156,7 +156,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, struct nfp_resource *res; int err; struct timespec wait; - int count; + uint16_t count; res = malloc(sizeof(*res)); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index aa3b7a483e..243d3c9ce5 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -382,7 +382,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, + uint32_t min_size, struct nfp_cpp_area **area) { int ret; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index 30768f1ccf..e7295258b3 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -56,5 +56,5 @@ const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, - unsigned int min_size, struct nfp_cpp_area **area); + uint32_t min_size, struct nfp_cpp_area **area); #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 04/26] net/nfp: remove the unneeded logic 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (2 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 03/26] net/nfp: unify the type of integer variable Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 05/26] net/nfp: standard the local variable coding style Chaoyong He ` (21 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Remove the unneeded logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 107 ---- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 12 - drivers/net/nfp/nfpcore/nfp_cppcore.c | 162 ------ drivers/net/nfp/nfpcore/nfp_mutex.c | 48 -- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 24 - drivers/net/nfp/nfpcore/nfp_target.h | 567 --------------------- 6 files changed, 920 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 782272a3f4..139752f85a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -96,7 +96,6 @@ struct nfp_cpp_operations { void *(*area_iomem)(struct nfp_cpp_area *area); - void *(*area_mapped)(struct nfp_cpp_area *area); /* * Perform a read from a NFP CPP area * Serialized @@ -457,16 +456,6 @@ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Return an IO pointer to the beginning of the NFP CPP area handle. The area - * must be acquired with 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * - * @return Pointer to IO memory, or NULL on failure. - */ -void *nfp_cpp_area_mapped(struct nfp_cpp_area *area); - /* * Read from a NFP CPP area handle into a buffer. The area must be acquired with * 'nfp_cpp_area_acquire()' before calling this operation. @@ -508,18 +497,6 @@ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Verify that IO can be performed on an offset in an area - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] size Size of region to validate - * - * @return 0 on success, negative value on failure. - */ -int nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, unsigned long size); - /* * Get the NFP CPP handle that is the parent of a NFP CPP area handle * @@ -564,20 +541,6 @@ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); - -/* - * Fill a NFP CPP area handle and offset with a value - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the NFP CPP ID address space - * @param[in] value 32-bit value to fill area with - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, negative value on failure. - */ -int nfp_cpp_area_fill(struct nfp_cpp_area *area, unsigned long offset, - uint32_t value, size_t length); - /* * Read a single 32-bit value from a NFP CPP area handle * @@ -668,33 +631,6 @@ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int nfp_xpb_writelm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value); - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, negative value on failure. - */ -int nfp_xpb_waitlm(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t mask, - uint32_t value, int timeout_us); - /* * Read a 32-bit word from a NFP CPP ID * @@ -789,49 +725,6 @@ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Get the NFP CPP handle the mutex was created with - * - * @param mutex NFP mutex handle - * @return NFP CPP handle - */ -struct nfp_cpp *nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex key - * - * @param mutex NFP mutex handle - * @return Mutex key - */ -uint32_t nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex owner - * - * @param mutex NFP mutex handle - * @return Interface ID of the mutex owner - * - * NOTE: This is for debug purposes ONLY - the owner may change at any time, - * unless it has been locked by this NFP CPP handle. - */ -uint16_t nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex target - * - * @param mutex NFP mutex handle - * @return Mutex CPP target (ie NFP_CPP_TARGET_MU) - */ -int nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex); - -/* - * Get the mutex address - * - * @param mutex NFP mutex handle - * @return Mutex CPP address - */ -uint64_t nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex); - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 881f21bfd0..ec14ec45dc 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -471,17 +471,6 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) return 0; } -static void * -nfp6000_area_mapped(struct nfp_cpp_area *area) -{ - struct nfp6000_area_priv *area_priv = nfp_cpp_area_priv(area); - - if (area_priv->iomem == NULL) - return NULL; - - return area_priv->iomem; -} - static void nfp6000_area_release(struct nfp_cpp_area *area) { @@ -829,7 +818,6 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, - .area_mapped = nfp6000_area_mapped, .area_read = nfp6000_area_read, .area_write = nfp6000_area_write, .area_iomem = nfp6000_area_iomem, diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 627d4eaa5d..7e7c36eda3 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -388,35 +388,6 @@ nfp_cpp_area_write(struct nfp_cpp_area *area, return area->cpp->op->area_write(area, kernel_vaddr, offset, length); } -void * -nfp_cpp_area_mapped(struct nfp_cpp_area *area) -{ - if (area->cpp->op->area_mapped) - return area->cpp->op->area_mapped(area); - return NULL; -} - -/* - * nfp_cpp_area_check_range - check if address range fits in CPP area - * - * @area: CPP area handle - * @offset: offset into CPP area - * @length: size of address range in bytes - * - * Check if address range fits within CPP area. Return 0 if area fits - * or negative value on error. - */ -int -nfp_cpp_area_check_range(struct nfp_cpp_area *area, - unsigned long long offset, - unsigned long length) -{ - if (((offset + length) > area->size)) - return -EFAULT; - - return 0; -} - /* * Return the correct CPP address, and fixup xpb_addr as needed, * based upon NFP model. @@ -671,82 +642,6 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to modify - * - * @return 0 on success, or -1 on failure. - */ -int -nfp_xpb_writelm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value) -{ - int err; - uint32_t tmp; - - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - return err; - - tmp &= ~mask; - tmp |= (mask & value); - return nfp_xpb_writel(cpp, xpb_tgt, tmp); -} - -/* - * Modify bits of a 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param mask mask of bits to alter - * @param value value to monitor for - * @param timeout_us maximum number of us to wait (-1 for forever) - * - * @return >= 0 on success, or negative value on failure. - */ -int -nfp_xpb_waitlm(struct nfp_cpp *cpp, - uint32_t xpb_tgt, - uint32_t mask, - uint32_t value, - int timeout_us) -{ - uint32_t tmp; - int err; - - do { - err = nfp_xpb_readl(cpp, xpb_tgt, &tmp); - if (err < 0) - goto exit; - - if ((tmp & mask) == (value & mask)) { - if (timeout_us < 0) - timeout_us = 0; - break; - } - - if (timeout_us < 0) - continue; - - timeout_us -= 100; - usleep(100); - } while (timeout_us >= 0); - - if (timeout_us < 0) - err = -ETIMEDOUT; - else - err = timeout_us; - -exit: - return err; -} - /* * nfp_cpp_read - read from CPP target * @cpp: CPP handle @@ -805,63 +700,6 @@ nfp_cpp_write(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_area_fill - fill a CPP area with a value - * @area: CPP area - * @offset: offset into CPP area - * @value: value to fill with - * @length: length of area to fill - */ -int -nfp_cpp_area_fill(struct nfp_cpp_area *area, - unsigned long offset, - uint32_t value, - size_t length) -{ - int err; - size_t i; - uint64_t value64; - - value = rte_cpu_to_le_32(value); - value64 = ((uint64_t)value << 32) | value; - - if ((offset + length) > area->size) - return -EINVAL; - - if ((area->offset + offset) & 3) - return -EINVAL; - - if (((area->offset + offset) & 7) == 4 && length >= 4) { - err = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - offset += sizeof(value); - length -= sizeof(value); - } - - for (i = 0; (i + sizeof(value)) < length; i += sizeof(value64)) { - err = nfp_cpp_area_write(area, offset + i, &value64, - sizeof(value64)); - if (err < 0) - return err; - if (err != sizeof(value64)) - return -ENOSPC; - } - - if ((i + sizeof(value)) <= length) { - err = nfp_cpp_area_write(area, offset + i, &value, sizeof(value)); - if (err < 0) - return err; - if (err != sizeof(value)) - return -ENOSPC; - i += sizeof(value); - } - - return (int)i; -} - /* * NOTE: This code should not use nfp_xpb_* functions, * as those are model-specific diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 7ac06e897a..edc8137304 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -178,54 +178,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -struct nfp_cpp * -nfp_cpp_mutex_cpp(struct nfp_cpp_mutex *mutex) -{ - return mutex->cpp; -} - -uint32_t -nfp_cpp_mutex_key(struct nfp_cpp_mutex *mutex) -{ - return mutex->key; -} - -uint16_t -nfp_cpp_mutex_owner(struct nfp_cpp_mutex *mutex) -{ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t value, key; - int err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - return err; - - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); - if (err < 0) - return err; - - if (key != mutex->key) - return -EPERM; - - if (MUTEX_IS_LOCKED(value) == 0) - return 0; - - return MUTEX_INTERFACE(value); -} - -int -nfp_cpp_mutex_target(struct nfp_cpp_mutex *mutex) -{ - return mutex->target; -} - -uint64_t -nfp_cpp_mutex_address(struct nfp_cpp_mutex *mutex) -{ - return mutex->address; -} - /* * Free a mutex handle - does not alter the lock state * diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 5492840aa1..bc155b44d8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,30 +11,6 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) #define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 03908a894f..195e599d31 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,571 +6,4 @@ #ifndef NFP_TARGET_H #define NFP_TARGET_H -#include "nfp_cpp.h" - -#define P32 1 -#define P64 2 - -#define PUSHPULL(_pull, _push) (((_pull) << 4) | ((_push) << 0)) - -#ifndef NFP_ERRNO -#include <errno.h> -#define NFP_ERRNO(x) (errno = (x), -1) -#endif - -static inline int -pushpull_width(int pp) -{ - pp &= 0xf; - - if (pp == 0) - return NFP_ERRNO(EINVAL); - return (2 << pp); -} - -#define PUSH_WIDTH(_pushpull) pushpull_width((_pushpull) >> 0) -#define PULL_WIDTH(_pushpull) pushpull_width((_pushpull) >> 4) - -static inline int -target_rw(uint32_t cpp_id, int pp, int start, int len) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < start || island > (start + len))) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): - return PUSHPULL(0, pp); - case NFP_CPP_ID(0, 1, 0): - return PUSHPULL(pp, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(pp, pp); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_dma(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiDma */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiDma */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_stats(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiStats */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiStats */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_tm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiTM */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiTM */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi_ppc(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 0): /* ReadNbiPreclassifier */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* WriteNbiPreclassifier */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): - return PUSHPULL(P64, P64); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_nbi(uint32_t cpp_id, uint64_t address) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - uint64_t rel_addr = address & 0x3fFFFF; - - if (island && (island < 8 || island > 9)) - return NFP_ERRNO(EINVAL); - - if (rel_addr < (1 << 20)) - return nfp6000_nbi_dma(cpp_id); - if (rel_addr < (2 << 20)) - return nfp6000_nbi_stats(cpp_id); - if (rel_addr < (3 << 20)) - return nfp6000_nbi_tm(cpp_id); - return nfp6000_nbi_ppc(cpp_id); -} - -/* - * This structure ONLY includes items that can be done with a read or write of - * 32-bit or 64-bit words. All others are not listed. - */ -static inline int -nfp6000_mu_common(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 0): /* read_be/write_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): /* read_le/write_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 2): /* {read/write}_swap_be */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 3): /* {read/write}_swap_le */ - return PUSHPULL(P64, P64); - case NFP_CPP_ID(0, 0, 0): /* read_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 1): /* read_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 2): /* read_swap_be */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 0, 3): /* read_swap_le */ - return PUSHPULL(0, P64); - case NFP_CPP_ID(0, 1, 0): /* write_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 1): /* write_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 2): /* write_swap_be */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 1, 3): /* write_swap_le */ - return PUSHPULL(P64, 0); - case NFP_CPP_ID(0, 3, 0): /* atomic_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 2): /* mask_compare_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* atomic_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 2): /* atomic_write_imm */ - return PUSHPULL(0, 0); - case NFP_CPP_ID(0, 4, 3): /* swap_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 5, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 5, 3): /* test_set_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 6, 0): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 3): /* test_clr_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 7, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 7, 3): /* test_add_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 8, 0): /* addsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 3): /* test_sub_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 3): /* test_subsat_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 0): /* microq128_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 1): /* microq128_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 13, 2): /* microq128_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 0): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 3): /* test_xor_imm */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 0): /* read32_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 1): /* read32_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 2): /* read32_swap_be */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 28, 3): /* read32_swap_le */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 31, 0): /* write32_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 1): /* write32_le */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 2): /* write32_swap_be */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 31, 3): /* write32_swap_le */ - return PUSHPULL(P32, 0); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp6000_mu_ctm(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 16, 1): /* packet_read_packet_status */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_emu(uint32_t cpp_id) -{ - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 18, 0): /* read_queue */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 1): /* read_queue_ring */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 18, 2): /* write_queue */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 18, 3): /* write_queue_ring */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 20, 2): /* journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 21, 0): /* get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 1): /* get_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 21, 2): /* get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 0): /* pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 1): /* pop_eop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 22, 2): /* pop_freely */ - return PUSHPULL(0, P32); - default: - return nfp6000_mu_common(cpp_id); - } -} - -static inline int -nfp6000_mu_imu(uint32_t cpp_id) -{ - return nfp6000_mu_common(cpp_id); -} - -static inline int -nfp6000_mu(uint32_t cpp_id, uint64_t address) -{ - int pp; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island == 0) { - if (address < 0x2000000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x8000000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0x9800000000ULL) - pp = nfp6000_mu_ctm(cpp_id); - else if (address < 0x9C00000000ULL) - pp = nfp6000_mu_emu(cpp_id); - else if (address < 0xA000000000ULL) - pp = nfp6000_mu_imu(cpp_id); - else - pp = nfp6000_mu_ctm(cpp_id); - } else if (island >= 24 && island <= 27) { - pp = nfp6000_mu_emu(cpp_id); - } else if (island >= 28 && island <= 31) { - pp = nfp6000_mu_imu(cpp_id); - } else if (island == 1 || - (island >= 4 && island <= 7) || - (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { - pp = nfp6000_mu_ctm(cpp_id); - } else { - pp = NFP_ERRNO(EINVAL); - } - - return pp; -} - -static inline int -nfp6000_ila(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 48 || island > 51)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* read_check_error */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 0): /* read_int */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* write_int */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 48, 4); - } -} - -static inline int -nfp6000_pci(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 4 || island > 7)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 4, 4); - } -} - -static inline int -nfp6000_crypto(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island && (island < 12 || island > 15)) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 2, 0): - return PUSHPULL(P64, 0); - default: - return target_rw(cpp_id, P64, 12, 4); - } -} - -static inline int -nfp6000_cap_xpb(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 1): /* RingGet */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 0, 2): /* Interthread Signal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 1): /* RingPut */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 1, 2): /* CTNNWr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* ReflectRd, signal none */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 1): /* ReflectRd, signal self */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 2): /* ReflectRd, signal remote */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 2, 3): /* ReflectRd, signal both */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 3, 0): /* ReflectWr, signal none */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 1): /* ReflectWr, signal self */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 2): /* ReflectWr, signal remote */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 3, 3): /* ReflectWr, signal both */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, NFP_CPP_ACTION_RW, 1): - return PUSHPULL(P32, P32); - default: - return target_rw(cpp_id, P32, 1, 63); - } -} - -static inline int -nfp6000_cls(uint32_t cpp_id) -{ - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_id); - - if (island > 63) - return NFP_ERRNO(EINVAL); - - switch (cpp_id & NFP_CPP_ID(0, ~0, ~0)) { - case NFP_CPP_ID(0, 0, 3): /* xor */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 0): /* set */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 2, 1): /* clr */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 0): /* add */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 4, 1): /* add64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 0): /* sub */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 1): /* sub64 */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 6, 2): /* subsat */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 2): /* hash_mask */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 8, 3): /* hash_clear */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 9, 0): /* ring_get */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 1): /* ring_pop */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 2): /* ring_get_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 9, 3): /* ring_pop_freely */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 10, 0): /* ring_put */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 10, 2): /* ring_journal */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 14, 0): /* reflect_write_sig_local */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 15, 1): /* reflect_read_sig_local */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 17, 2): /* statistic */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 24, 0): /* ring_read */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 24, 1): /* ring_write */ - return PUSHPULL(P32, 0); - case NFP_CPP_ID(0, 25, 0): /* ring_workq_add_thread */ - return PUSHPULL(0, P32); - case NFP_CPP_ID(0, 25, 1): /* ring_workq_add_work */ - return PUSHPULL(P32, 0); - default: - return target_rw(cpp_id, P32, 0, 64); - } -} - -static inline int -nfp6000_target_pushpull(uint32_t cpp_id, uint64_t address) -{ - switch (NFP_CPP_ID_TARGET_of(cpp_id)) { - case NFP6000_CPPTGT_NBI: - return nfp6000_nbi(cpp_id, address); - case NFP6000_CPPTGT_VQDR: - return target_rw(cpp_id, P32, 24, 4); - case NFP6000_CPPTGT_ILA: - return nfp6000_ila(cpp_id); - case NFP6000_CPPTGT_MU: - return nfp6000_mu(cpp_id, address); - case NFP6000_CPPTGT_PCIE: - return nfp6000_pci(cpp_id); - case NFP6000_CPPTGT_ARM: - if (address < 0x10000) - return target_rw(cpp_id, P64, 1, 1); - else - return target_rw(cpp_id, P32, 1, 1); - case NFP6000_CPPTGT_CRYPTO: - return nfp6000_crypto(cpp_id); - case NFP6000_CPPTGT_CTXPB: - return nfp6000_cap_xpb(cpp_id); - case NFP6000_CPPTGT_CLS: - return nfp6000_cls(cpp_id); - case 0: - return target_rw(cpp_id, P32, 4, 4); - default: - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_pushpull_width(int pp, int write_not_read) -{ - if (pp < 0) - return pp; - - if (write_not_read) - return PULL_WIDTH(pp); - else - return PUSH_WIDTH(pp); -} - -static inline int -nfp6000_target_action_width(uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - int pp; - - pp = nfp6000_target_pushpull(cpp_id, address); - - return nfp_target_pushpull_width(pp, write_not_read); -} - -static inline int -nfp_target_action_width(uint32_t model, uint32_t cpp_id, uint64_t address, - int write_not_read) -{ - if (NFP_CPP_MODEL_IS_6000(model)) { - return nfp6000_target_action_width(cpp_id, address, - write_not_read); - } else { - return NFP_ERRNO(EINVAL); - } -} - -static inline int -nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table) -{ - int err; - uint8_t island = NFP_CPP_ID_ISLAND_of(cpp_island_id); - uint8_t target = NFP_CPP_ID_TARGET_of(cpp_island_id); - uint32_t imb; - - if (target >= 16) - return NFP_ERRNO(EINVAL); - - if (island == 0) { - /* Already translated */ - *cpp_target_id = cpp_island_id; - *cpp_target_address = cpp_island_address; - return 0; - } - - if (imb_table == NULL) { - /* CPP + Island only allowed on systems with IMB tables */ - return NFP_ERRNO(EINVAL); - } - - imb = imb_table[target]; - - *cpp_target_address = cpp_island_address; - err = _nfp6000_cppat_addr_encode(cpp_target_address, island, target, - ((imb >> 13) & 7), - ((imb >> 12) & 1), - ((imb >> 6) & 0x3f), - ((imb >> 0) & 0x3f)); - if (err == 0) { - *cpp_target_id = - NFP_CPP_ID(target, NFP_CPP_ID_ACTION_of(cpp_island_id), - NFP_CPP_ID_TOKEN_of(cpp_island_id)); - } - - return err; -} - #endif /* NFP_TARGET_H */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 05/26] net/nfp: standard the local variable coding style 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (3 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 04/26] net/nfp: remove the unneeded logic Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 06/26] net/nfp: adjust the log statement Chaoyong He ` (20 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He There should only declare one local variable in each line, and the local variable should be arranged from short to long in the function. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 58 ++++++++++++---------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 14 +++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 27 ++++++---- drivers/net/nfp/nfpcore/nfp_mip.c | 8 +-- drivers/net/nfp/nfpcore/nfp_mutex.c | 25 ++++++---- drivers/net/nfp/nfpcore/nfp_nffw.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_nsp.c | 40 ++++++++------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 8 +-- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 39 ++++++++------- drivers/net/nfp/nfpcore/nfp_resource.c | 15 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 19 ++++--- 11 files changed, 151 insertions(+), 117 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index ec14ec45dc..78beee07ef 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -140,9 +140,9 @@ nfp_compute_bar(const struct nfp_bar *bar, size_t size, int width) { - uint32_t bitsize; - uint32_t newcfg; uint64_t mask; + uint32_t newcfg; + uint32_t bitsize; if (tgt >= 16) return -EINVAL; @@ -239,7 +239,8 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base, slot; + int base; + int slot; base = bar->index >> 3; slot = bar->index & 7; @@ -268,9 +269,9 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, size_t size, int width) { - uint64_t newbase; - uint32_t newcfg; int err; + uint32_t newcfg; + uint64_t newbase; err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, size, width); @@ -303,8 +304,10 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, static int nfp_enable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -333,8 +336,10 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) static struct nfp_bar * nfp_alloc_bar(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -356,8 +361,10 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) static void nfp_disable_bars(struct nfp_pcie_user *nfp) { + int x; + int end; + int start; struct nfp_bar *bar; - int x, start, end; if (rte_eal_process_type() == RTE_PROC_PRIMARY) { start = NFP_BAR_MID; @@ -403,12 +410,13 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint64_t address, size_t size) { - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); - struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + int pp; + int ret = 0; + uint32_t token = NFP_CPP_ID_TOKEN_of(dest); uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); - uint32_t token = NFP_CPP_ID_TOKEN_of(dest); - int pp, ret = 0; + struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -493,14 +501,14 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + size_t n; + int width; + bool is_64; + uint32_t *wrptr32 = kernel_vaddr; uint64_t *wrptr64 = kernel_vaddr; - const volatile uint64_t *rdptr64; struct nfp6000_area_priv *priv; - uint32_t *wrptr32 = kernel_vaddr; const volatile uint32_t *rdptr32; - int width; - size_t n; - bool is_64; + const volatile uint64_t *rdptr64; priv = nfp_cpp_area_priv(area); rdptr64 = (uint64_t *)(priv->iomem + offset); @@ -563,14 +571,14 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { - const uint64_t *rdptr64 = kernel_vaddr; - uint64_t *wrptr64; - const uint32_t *rdptr32 = kernel_vaddr; - struct nfp6000_area_priv *priv; - uint32_t *wrptr32; - int width; size_t n; + int width; bool is_64; + uint32_t *wrptr32; + uint64_t *wrptr64; + struct nfp6000_area_priv *priv; + const uint32_t *rdptr32 = kernel_vaddr; + const uint64_t *rdptr64 = kernel_vaddr; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); @@ -693,10 +701,10 @@ static int nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) { + off_t pos; uint16_t tmp; uint8_t serial[6]; int serial_len = 6; - off_t pos; pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); if (pos <= 0) { @@ -741,8 +749,8 @@ static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - uint64_t tmp; int i = 0; + uint64_t tmp; tmp = dev->mem_resource[0].len; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7e7c36eda3..2e5a4e7349 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -172,9 +172,9 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint64_t address, uint32_t size) { + int err; struct nfp_cpp_area *area; uint64_t tmp64 = (uint64_t)address; - int err; if (cpp == NULL) return NULL; @@ -396,8 +396,8 @@ static uint32_t nfp_xpb_to_cpp(struct nfp_cpp *cpp, uint32_t *xpb_addr) { - uint32_t xpb; int island; + uint32_t xpb; xpb = NFP_CPP_ID(14, NFP_CPP_ACTION_RW, 0); @@ -569,9 +569,9 @@ static struct nfp_cpp * nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) { - const struct nfp_cpp_operations *ops; - struct nfp_cpp *cpp; int err; + struct nfp_cpp *cpp; + const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); @@ -657,8 +657,8 @@ nfp_cpp_read(struct nfp_cpp *cpp, void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { @@ -687,8 +687,8 @@ nfp_cpp_write(struct nfp_cpp *cpp, const void *kernel_vaddr, size_t length) { - struct nfp_cpp_area *area; int err; + struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) @@ -708,8 +708,8 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { - uint32_t reg; int err; + uint32_t reg; err = nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) + NFP_PL_DEVICE_ID, ®); diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index ea4c7d6a9e..819761eda0 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -36,7 +36,9 @@ static int nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, uint32_t size) { - const char *key, *val, *end = hwinfo->data + size; + const char *key; + const char *val; + const char *end = hwinfo->data + size; for (key = hwinfo->data; *key != 0 && key < end; key = val + strlen(val) + 1) { @@ -58,7 +60,9 @@ static int nfp_hwinfo_db_validate(struct nfp_hwinfo *db, uint32_t len) { - uint32_t size, new_crc, *crc; + uint32_t *crc; + uint32_t size; + uint32_t new_crc; size = db->size; if (size > len) { @@ -82,12 +86,12 @@ static struct nfp_hwinfo * nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, size_t *cpp_size) { - struct nfp_hwinfo *header; - void *res; - uint64_t cpp_addr; - uint32_t cpp_id; int err; + void *res; uint8_t *db; + uint32_t cpp_id; + uint64_t cpp_addr; + struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); if (res) { @@ -135,13 +139,12 @@ static struct nfp_hwinfo * nfp_hwinfo_fetch(struct nfp_cpp *cpp, size_t *hwdb_size) { + int count = 0; struct timespec wait; struct nfp_hwinfo *db; - int count; wait.tv_sec = 0; wait.tv_nsec = 10000000; - count = 0; for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -159,9 +162,9 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo * nfp_hwinfo_read(struct nfp_cpp *cpp) { - struct nfp_hwinfo *db; - size_t hwdb_size = 0; int err; + size_t hwdb_size = 0; + struct nfp_hwinfo *db; db = nfp_hwinfo_fetch(cpp, &hwdb_size); if (db == NULL) @@ -186,7 +189,9 @@ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup) { - const char *key, *val, *end; + const char *key; + const char *val; + const char *end; if (hwinfo == NULL || lookup == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0071d3fc37..1e601313b4 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -68,10 +68,10 @@ static int nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip) { - struct nfp_nffw_info *nffw_info; - uint32_t cpp_id; - uint64_t addr; int err; + uint64_t addr; + uint32_t cpp_id; + struct nfp_nffw_info *nffw_info; nffw_info = nfp_nffw_info_open(cpp); if (nffw_info == NULL) @@ -100,8 +100,8 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) { - struct nfp_mip *mip; int err; + struct nfp_mip *mip; mip = malloc(sizeof(*mip)); if (mip == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index edc8137304..5be437b354 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -79,9 +79,9 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { + int err; uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - int err; err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -122,11 +122,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint64_t address, uint32_t key) { - uint32_t model = nfp_cpp_model(cpp); - struct nfp_cpp_mutex *mutex; - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ int err; uint32_t tmp; + struct nfp_cpp_mutex *mutex; + uint32_t model = nfp_cpp_model(cpp); + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -242,12 +242,13 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) { - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + int err; + uint32_t key; + uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t key, value; uint16_t interface = nfp_cpp_interface(cpp); - int err; + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -296,12 +297,14 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) { + int err; + uint32_t key; + uint32_t tmp; + uint32_t value; + struct nfp_cpp *cpp = mutex->cpp; uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ - uint32_t key, value, tmp; - struct nfp_cpp *cpp = mutex->cpp; - int err; if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 2412dc0e00..9123fc742a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -68,9 +68,11 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) { - uint32_t mode, addr40; - uint32_t xpbaddr, imbcppat; int err; + uint32_t mode; + uint32_t addr40; + uint32_t xpbaddr; + uint32_t imbcppat; /* Hardcoded XPB IMB Base, island 0 */ xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; @@ -118,10 +120,10 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) { - struct nfp_nffw_info_data *fwinf; - struct nfp_nffw_info *state; - uint32_t info_ver; int err; + uint32_t info_ver; + struct nfp_nffw_info *state; + struct nfp_nffw_info_data *fwinf; state = malloc(sizeof(*state)); if (state == NULL) @@ -183,8 +185,9 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) { + uint32_t i; + uint32_t cnt; struct nffw_fwinfo *fwinfo; - uint32_t cnt, i; cnt = nffw_res_fwinfos(&state->fwinf, &fwinfo); if (cnt == 0) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index dfe396c8ac..4861772a98 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -72,10 +72,11 @@ nfp_nsp_print_extended_error(uint32_t ret_val) static int nfp_nsp_check(struct nfp_nsp *state) { - struct nfp_cpp *cpp = state->cpp; - uint64_t nsp_status, reg; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t nsp_status; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_status = nfp_resource_address(state->res) + NSP_STATUS; @@ -113,9 +114,9 @@ nfp_nsp_check(struct nfp_nsp *state) struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) { - struct nfp_resource *res; - struct nfp_nsp *state; int err; + struct nfp_nsp *state; + struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); if (res == NULL) @@ -170,13 +171,12 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, uint64_t mask, uint64_t val) { - struct timespec wait; - uint32_t count; int err; + uint32_t count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -217,10 +217,15 @@ nfp_nsp_command(struct nfp_nsp *state, uint32_t buff_cpp, uint64_t buff_addr) { - uint64_t reg, ret_val, nsp_base, nsp_buffer, nsp_status, nsp_command; - struct nfp_cpp *cpp = state->cpp; - uint32_t nsp_cpp; int err; + uint64_t reg; + uint32_t nsp_cpp; + uint64_t ret_val; + uint64_t nsp_base; + uint64_t nsp_buffer; + uint64_t nsp_status; + uint64_t nsp_command; + struct nfp_cpp *cpp = state->cpp; nsp_cpp = nfp_resource_cpp_id(state->res); nsp_base = nfp_resource_address(state->res); @@ -296,11 +301,13 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, void *out_buf, unsigned int out_size) { - struct nfp_cpp *cpp = nsp->cpp; + int err; + int ret; + uint64_t reg; size_t max_size; - uint64_t reg, cpp_buf; - int ret, err; uint32_t cpp_id; + uint64_t cpp_buf; + struct nfp_cpp *cpp = nsp->cpp; if (nsp->ver.minor < 13) { PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", @@ -360,13 +367,12 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, int nfp_nsp_wait(struct nfp_nsp *state) { - struct timespec wait; - uint32_t count; int err; + int count = 0; + struct timespec wait; wait.tv_sec = 0; wait.tv_nsec = 25000000; - count = 0; for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 31677b66e6..3081e22dad 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -26,9 +26,9 @@ struct nsp_identify { struct nfp_nsp_identify * __nfp_nsp_identify(struct nfp_nsp *nsp) { - struct nfp_nsp_identify *nspi = NULL; - struct nsp_identify *ni; int ret; + struct nsp_identify *ni; + struct nfp_nsp_identify *nspi = NULL; if (nfp_nsp_get_abi_ver_minor(nsp) < 15) return NULL; @@ -77,9 +77,9 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val) { - struct nfp_sensors s; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + struct nfp_sensors s; nsp = nfp_nsp_open(cpp); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index bc155b44d8..9b7c8aa7f8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -150,9 +150,10 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, uint32_t index, struct nfp_eth_table_port *dst) { - uint32_t rate; uint32_t fec; - uint64_t port, state; + uint64_t port; + uint32_t rate; + uint64_t state; port = rte_le_to_cpu_64(src->port); state = rte_le_to_cpu_64(src->state); @@ -200,7 +201,8 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, static void nfp_eth_calc_port_geometry(struct nfp_eth_table *table) { - uint32_t i, j; + uint32_t i; + uint32_t j; for (i = 0; i < table->count; i++) { table->max_index = RTE_MAX(table->max_index, @@ -242,12 +244,13 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) static struct nfp_eth_table * __nfp_eth_read_ports(struct nfp_nsp *nsp) { - union eth_table_entry *entries; - struct nfp_eth_table *table; - uint32_t table_sz; + int ret; uint32_t i; uint32_t j; - int ret, cnt = 0; + int cnt = 0; + uint32_t table_sz; + struct nfp_eth_table *table; + union eth_table_entry *entries; const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); @@ -321,8 +324,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) { - struct nfp_eth_table *ret; struct nfp_nsp *nsp; + struct nfp_eth_table *ret; nsp = nfp_nsp_open(cpp); if (nsp == NULL) @@ -338,9 +341,9 @@ struct nfp_nsp * nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; int ret; + struct nfp_nsp *nsp; + union eth_table_entry *entries; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -401,8 +404,8 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) int nfp_eth_config_commit_end(struct nfp_nsp *nsp) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); int ret = 1; + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); if (nfp_nsp_config_modified(nsp)) { ret = nfp_nsp_write_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); @@ -433,9 +436,9 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -475,9 +478,9 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed) { - union eth_table_entry *entries; - struct nfp_nsp *nsp; uint64_t reg; + struct nfp_nsp *nsp; + union eth_table_entry *entries; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) @@ -516,9 +519,9 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, uint32_t val, const uint64_t ctrl_bit) { - union eth_table_entry *entries = nfp_nsp_config_entries(nsp); - uint32_t idx = nfp_nsp_config_idx(nsp); uint64_t reg; + uint32_t idx = nfp_nsp_config_idx(nsp); + union eth_table_entry *entries = nfp_nsp_config_entries(nsp); /* * Note: set features were added in ABI 0.14 but the error @@ -604,8 +607,8 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode) { - struct nfp_nsp *nsp; int err; + struct nfp_nsp *nsp; nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 9dd4832779..fa92f2762e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -67,10 +67,12 @@ static int nfp_cpp_resource_find(struct nfp_cpp *cpp, struct nfp_resource *res) { - char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; + int ret; + uint32_t i; + uint32_t key; + uint32_t cpp_id; struct nfp_resource_entry entry; - uint32_t cpp_id, key; - int ret, i; + char name_pad[NFP_RESOURCE_ENTRY_NAME_SZ + 2]; cpp_id = NFP_CPP_ID(NFP_RESOURCE_TBL_TARGET, 3, 0); /* Atomic read */ @@ -152,11 +154,11 @@ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, const char *name) { - struct nfp_cpp_mutex *dev_mutex; - struct nfp_resource *res; int err; + uint16_t count = 0; struct timespec wait; - uint16_t count; + struct nfp_resource *res; + struct nfp_cpp_mutex *dev_mutex; res = malloc(sizeof(*res)); if (res == NULL) @@ -175,7 +177,6 @@ nfp_resource_acquire(struct nfp_cpp *cpp, wait.tv_sec = 0; wait.tv_nsec = 1000000; - count = 0; for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 243d3c9ce5..a34278beca 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -85,8 +85,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, struct nfp_rtsym_table * nfp_rtsym_table_read(struct nfp_cpp *cpp) { - struct nfp_rtsym_table *rtbl; struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; mip = nfp_mip_open(cpp); rtbl = __nfp_rtsym_table_read(cpp, mip); @@ -99,13 +99,18 @@ struct nfp_rtsym_table * __nfp_rtsym_table_read(struct nfp_cpp *cpp, const struct nfp_mip *mip) { - uint32_t strtab_addr, symtab_addr, strtab_size, symtab_size; - struct nfp_rtsym_entry *rtsymtab; + int n; + int err; + uint32_t size; + uint32_t strtab_addr; + uint32_t symtab_addr; + uint32_t strtab_size; + uint32_t symtab_size; struct nfp_rtsym_table *cache; + struct nfp_rtsym_entry *rtsymtab; const uint32_t dram = NFP_CPP_ID(NFP_CPP_TARGET_MU, NFP_CPP_ACTION_RW, 0) | NFP_ISL_EMEM0; - int err, n, size; if (mip == NULL) return NULL; @@ -341,10 +346,10 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error) { - const struct nfp_rtsym *sym; - uint32_t val32; - uint64_t val; int err; + uint64_t val; + uint32_t val32; + const struct nfp_rtsym *sym; sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 06/26] net/nfp: adjust the log statement 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (4 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 05/26] net/nfp: standard the local variable coding style Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 07/26] net/nfp: standard the comment style Chaoyong He ` (19 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Add log statement to the important control logic, which means more strict check of the return value of function call. Also remove some verbose info log statement. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 37 ++++++---------------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 20 +++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 28 ++++++++-------- drivers/net/nfp/nfpcore/nfp_mip.c | 7 ++-- drivers/net/nfp/nfpcore/nfp_mutex.c | 5 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 9 ++++-- drivers/net/nfp/nfpcore/nfp_nsp.c | 25 +++++++++++---- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 10 +++--- drivers/net/nfp/nfpcore/nfp_resource.c | 17 +++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.c | 14 +++----- 10 files changed, 92 insertions(+), 80 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 78beee07ef..bdf4a658f5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -174,18 +174,10 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for Fixed mapping <%#llx,%#llx>, action=%d BAR too small (0x%llx)", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), act, - (unsigned long long)mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } - offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created Fixed mapping %d:%d:%d:0x%#llx-0x%#llx>", - bar->index, tgt, act, tok, (unsigned long long)offset, - (unsigned long long)(offset + mask)); + offset &= mask; bitsize = 40 - 16; } else { @@ -198,30 +190,16 @@ nfp_compute_bar(const struct nfp_bar *bar, newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); - if ((offset & mask) != ((offset + size - 1) & mask)) { - PMD_DRV_LOG(ERR, "BAR%d: Won't use for bulk mapping <%#llx,%#llx> target=%d, token=%d BAR too small (%#llx) - (%#llx != %#llx).", - bar->index, (unsigned long long)offset, - (unsigned long long)(offset + size), - tgt, tok, (unsigned long long)mask, - (unsigned long long)(offset & mask), - (unsigned long long)(offset + size - 1) & mask); + if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; - } offset &= mask; - PMD_DRV_LOG(DEBUG, "BAR%d: Created bulk mapping %d:x:%d:%#llx-%#llx", - bar->index, tgt, tok, (unsigned long long)offset, - (unsigned long long)(offset + ~mask)); - bitsize = 40 - 21; } - if (bar->bitsize < bitsize) { - PMD_DRV_LOG(ERR, "BAR%d: Too small for %d:%d:%d", bar->index, - tgt, tok, act); + if (bar->bitsize < bitsize) return -EINVAL; - } newcfg |= offset >> bitsize; @@ -254,7 +232,6 @@ nfp_bar_write(struct nfp_pcie_user *nfp, *(uint32_t *)(bar->csr) = newcfg; bar->barcfg = newcfg; - PMD_DRV_LOG(DEBUG, "BAR%d: updated to 0x%08x", bar->index, newcfg); return 0; } @@ -795,7 +772,11 @@ nfp6000_init(struct nfp_cpp *cpp, desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; - nfp_enable_bars(desc); + ret = nfp_enable_bars(desc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Enable bars failed"); + return -1; + } nfp_cpp_priv_set(cpp, desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 2e5a4e7349..e2af888a28 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -200,6 +200,7 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, err = cpp->op->area_init(area, dest, address, size); if (err < 0) { + PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } @@ -243,10 +244,13 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc(cpp, destination, address, size); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate CPP area"); return NULL; + } if (nfp_cpp_area_acquire(area) != 0) { + PMD_DRV_LOG(ERR, "Failed to acquire CPP area"); nfp_cpp_area_free(area); return NULL; } @@ -294,8 +298,10 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; + } } return 0; @@ -662,7 +668,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); if (area == NULL) { - PMD_DRV_LOG(ERR, "Area allocation/acquire failed"); + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } @@ -691,8 +697,10 @@ nfp_cpp_write(struct nfp_cpp *cpp, struct nfp_cpp_area *area; area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); - if (area == NULL) + if (area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; + } err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); @@ -746,8 +754,10 @@ nfp_cpp_map_area(struct nfp_cpp *cpp, uint8_t *res; *area = nfp_cpp_area_alloc_acquire(cpp, cpp_id, addr, size); - if (*area == NULL) + if (*area == NULL) { + PMD_DRV_LOG(ERR, "Area allocation/acquire failed for map"); goto err_eio; + } res = nfp_cpp_area_iomem(*area); if (res == NULL) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index 819761eda0..b658b5e900 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -74,7 +74,7 @@ nfp_hwinfo_db_validate(struct nfp_hwinfo *db, new_crc = nfp_crc32_posix((char *)db, size); crc = (uint32_t *)(db->start + size); if (new_crc != *crc) { - PMD_DRV_LOG(ERR, "Corrupt hwinfo table (CRC mismatch) calculated 0x%x, expected 0x%x", + PMD_DRV_LOG(ERR, "CRC mismatch, calculated %#x, expected %#x", new_crc, *crc); return -EINVAL; } @@ -94,34 +94,36 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *header; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_HWINFO); - if (res) { - cpp_id = nfp_resource_cpp_id(res); - cpp_addr = nfp_resource_address(res); - *cpp_size = nfp_resource_size(res); + if (res == NULL) { + PMD_DRV_LOG(ERR, "HWInfo - acquire resource failed"); + return NULL; + } - nfp_resource_release(res); + cpp_id = nfp_resource_cpp_id(res); + cpp_addr = nfp_resource_address(res); + *cpp_size = nfp_resource_size(res); - if (*cpp_size < HWINFO_SIZE_MIN) - return NULL; - } else { + nfp_resource_release(res); + + if (*cpp_size < HWINFO_SIZE_MIN) return NULL; - } db = malloc(*cpp_size + 1); if (db == NULL) return NULL; err = nfp_cpp_read(cpp, cpp_id, cpp_addr, db, *cpp_size); - if (err != (int)*cpp_size) + if (err != (int)*cpp_size) { + PMD_DRV_LOG(ERR, "HWInfo - CPP read error %d", err); goto exit_free; + } header = (void *)db; - PMD_DRV_LOG(DEBUG, "NFP HWINFO header: %#08x", *(uint32_t *)header); if (nfp_hwinfo_is_updating(header)) goto exit_free; if (header->version != NFP_HWINFO_VERSION_2) { - PMD_DRV_LOG(DEBUG, "Unknown HWInfo version: 0x%08x", + PMD_DRV_LOG(ERR, "Unknown HWInfo version: %#08x", header->version); goto exit_free; } diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 1e601313b4..086e82db70 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -46,16 +46,16 @@ nfp_mip_try_read(struct nfp_cpp *cpp, ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip)); if (ret != sizeof(*mip)) { - PMD_DRV_LOG(ERR, "Failed to read MIP data (%d, %zu)", ret, sizeof(*mip)); + PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } if (mip->signature != NFP_MIP_SIGNATURE) { - PMD_DRV_LOG(ERR, "Incorrect MIP signature (0x%08x)", + PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } if (mip->mip_version != NFP_MIP_VERSION) { - PMD_DRV_LOG(ERR, "Unsupported MIP version (%d)", + PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); return -EINVAL; } @@ -109,6 +109,7 @@ nfp_mip_open(struct nfp_cpp *cpp) err = nfp_mip_read_resource(cpp, mip); if (err != 0) { + PMD_DRV_LOG(ERR, "Failed to read MIP resource"); free(mip); return NULL; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 5be437b354..82919d8270 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -221,10 +221,7 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) if (err < 0 && err != -EBUSY) return err; if (time(NULL) >= warn_at) { - PMD_DRV_LOG(ERR, "Warning: waiting for NFP mutex usage:%u depth:%hd] " - "target:%d key:%08x] addr:%" PRIx64, - mutex->usage, mutex->depth, mutex->target, - mutex->key, mutex->address); + PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } sched_yield(); diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 9123fc742a..b5a354137d 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,6 +3,7 @@ * All rights reserved. */ +#include "../nfp_logs.h" #include "nfp_cpp.h" #include "nfp_nffw.h" #include "nfp_mip.h" @@ -132,8 +133,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) memset(state, 0, sizeof(*state)); state->res = nfp_resource_acquire(cpp, NFP_RESOURCE_NFP_NFFW); - if (state->res == NULL) + if (state->res == NULL) { + PMD_DRV_LOG(ERR, "NFFW - acquire resource failed"); goto err_free; + } fwinf = &state->fwinf; @@ -143,8 +146,10 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) err = nfp_cpp_read(cpp, nfp_resource_cpp_id(state->res), nfp_resource_address(state->res), fwinf, sizeof(*fwinf)); - if (err < (int)sizeof(*fwinf)) + if (err < (int)sizeof(*fwinf)) { + PMD_DRV_LOG(ERR, "NFFW - CPP read error %d", err); goto err_release; + } if (nffw_res_flg_init_get(fwinf) == 0) goto err_release; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 4861772a98..ff19446173 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -82,8 +82,10 @@ nfp_nsp_check(struct nfp_nsp *state) nsp_status = nfp_resource_address(state->res) + NSP_STATUS; err = nfp_cpp_readq(cpp, nsp_cpp, nsp_status, ®); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed %d", err); return err; + } if (FIELD_GET(NSP_STATUS_MAGIC, reg) != NSP_MAGIC) { PMD_DRV_LOG(ERR, "Cannot detect NFP Service Processor"); @@ -119,8 +121,10 @@ nfp_nsp_open(struct nfp_cpp *cpp) struct nfp_resource *res; res = nfp_resource_acquire(cpp, NFP_RESOURCE_NSP); - if (res == NULL) + if (res == NULL) { + PMD_DRV_LOG(ERR, "NSP - resource acquire failed"); return NULL; + } state = malloc(sizeof(*state)); if (state == NULL) { @@ -133,6 +137,7 @@ nfp_nsp_open(struct nfp_cpp *cpp) err = nfp_nsp_check(state); if (err != 0) { + PMD_DRV_LOG(ERR, "NSP - check failed"); nfp_nsp_close(state); return NULL; } @@ -180,8 +185,10 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); - if (err < 0) + if (err < 0) { + PMD_DRV_LOG(ERR, "NSP - CPP readq failed"); return err; + } if ((*reg & mask) == val) return 0; @@ -234,8 +241,10 @@ nfp_nsp_command(struct nfp_nsp *state, nsp_buffer = nsp_base + NSP_BUFFER; err = nfp_nsp_check(state); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "Check NSP command failed"); return err; + } if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { @@ -261,7 +270,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_command, NSP_COMMAND_START, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", err, code); return err; } @@ -270,7 +279,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_nsp_wait_reg(cpp, ®, nsp_cpp, nsp_status, NSP_STATUS_BUSY, 0); if (err != 0) { - PMD_DRV_LOG(ERR, "Error %d waiting for code 0x%04x to start", + PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", err, code); return err; } @@ -352,8 +361,10 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, } ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); - if (ret < 0) + if (ret < 0) { + PMD_DRV_LOG(ERR, "NSP command failed"); return ret; + } if (out_buf != NULL && out_size > 0) { err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 9b7c8aa7f8..74daa92aed 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -260,7 +260,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) memset(entries, 0, NSP_ETH_TABLE_SIZE); ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } @@ -279,7 +279,7 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) * above. */ if (ret != 0 && ret != cnt) { - PMD_DRV_LOG(ERR, "table entry count (%d) unmatch entries present (%d)", + PMD_DRV_LOG(ERR, "Table entry count (%d) unmatch entries present (%d)", ret, cnt); goto err; } @@ -358,12 +358,12 @@ nfp_eth_config_start(struct nfp_cpp *cpp, ret = nfp_nsp_read_eth_table(nsp, entries, NSP_ETH_TABLE_SIZE); if (ret < 0) { - PMD_DRV_LOG(ERR, "reading port table failed %d", ret); + PMD_DRV_LOG(ERR, "Reading port table failed %d", ret); goto err; } if ((entries[idx].port & NSP_ETH_PORT_LANES_MASK) == 0) { - PMD_DRV_LOG(ERR, "trying to set port state on disabled port %d", idx); + PMD_DRV_LOG(ERR, "Trying to set port state on disabled port %d", idx); goto err; } @@ -643,7 +643,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, rate = nfp_eth_speed2rate(speed); if (rate == RATE_INVALID) { - PMD_DRV_LOG(ERR, "could not find matching lane rate for speed %u", speed); + PMD_DRV_LOG(ERR, "Could not find matching lane rate for speed %u", speed); return -EINVAL; } diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index fa92f2762e..363f7d6198 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -118,16 +118,22 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, { int err; - if (nfp_cpp_mutex_lock(dev_mutex) != 0) + if (nfp_cpp_mutex_lock(dev_mutex) != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex lock failed"); return -EINVAL; + } err = nfp_cpp_resource_find(cpp, res); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP resource find failed"); goto err_unlock_dev; + } err = nfp_cpp_mutex_trylock(res->mutex); - if (err != 0) + if (err != 0) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex trylock failed"); goto err_res_mutex_free; + } nfp_cpp_mutex_unlock(dev_mutex); @@ -171,6 +177,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { + PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); free(res); return NULL; } @@ -182,8 +189,10 @@ nfp_resource_acquire(struct nfp_cpp *cpp, err = nfp_resource_try_acquire(cpp, res, dev_mutex); if (err == 0) break; - if (err != -EBUSY) + if (err != -EBUSY) { + PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); goto err_free; + } if (count++ > 1000) { PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index a34278beca..d15a920752 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -60,8 +60,6 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->size = ((uint64_t)fw->size_hi << 32) | rte_le_to_cpu_32(fw->size_lo); - PMD_INIT_LOG(DEBUG, "rtsym_entry_init name=%s, addr=%" PRIx64 ", size=%" PRIu64 ", target=%d", - sw->name, sw->addr, sw->size, sw->target); switch (fw->target) { case SYM_TGT_LMEM: sw->target = NFP_RTSYM_TARGET_LMEM; @@ -227,7 +225,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) { switch (sym->type) { case NFP_RTSYM_TYPE_NONE: - PMD_DRV_LOG(ERR, "rtsym '%s': type NONE", sym->name); + PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ case NFP_RTSYM_TYPE_FUNCTION: @@ -235,7 +233,7 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_ABS: return sizeof(uint64_t); default: - PMD_DRV_LOG(ERR, "rtsym '%s': unknown type: %d", sym->name, sym->type); + PMD_DRV_LOG(ERR, "Unknown RTSYM type %u", sym->type); return 0; } } @@ -366,7 +364,7 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); break; default: - PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %" PRId64, + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", name, sym->size); err = -EINVAL; break; @@ -396,10 +394,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, uint32_t cpp_id; const struct nfp_rtsym *sym; - PMD_DRV_LOG(DEBUG, "mapping symbol %s", name); sym = nfp_rtsym_lookup(rtbl, name); if (sym == NULL) { - PMD_INIT_LOG(ERR, "symbol lookup fails for %s", name); + PMD_DRV_LOG(ERR, "Symbol lookup fails for %s", name); return NULL; } @@ -418,10 +415,9 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, mem = nfp_cpp_map_area(rtbl->cpp, cpp_id, addr, sym->size, area); if (mem == NULL) { - PMD_INIT_LOG(ERR, "Failed to map symbol %s", name); + PMD_DRV_LOG(ERR, "Failed to map symbol %s", name); return NULL; } - PMD_DRV_LOG(DEBUG, "symbol %s with address %p", name, mem); return mem; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 07/26] net/nfp: standard the comment style 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (5 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 06/26] net/nfp: adjust the log statement Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 08/26] net/nfp: standard the blank character Chaoyong He ` (18 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Follow the DPDK coding style, use the kdoc comment style. Also move the comment of the functions to the implement file and add some comment to help understand logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 504 ++++----------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 39 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 484 ++++++++++++++++---- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 21 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 + drivers/net/nfp/nfpcore/nfp_mip.c | 43 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 69 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 49 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 6 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 53 ++- drivers/net/nfp/nfpcore/nfp_nsp.h | 108 ++--- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 170 ++++--- drivers/net/nfp/nfpcore/nfp_resource.c | 103 +++-- drivers/net/nfp/nfpcore/nfp_resource.h | 28 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 59 ++- drivers/net/nfp/nfpcore/nfp_rtsym.h | 12 +- drivers/net/nfp/nfpcore/nfp_target.c | 2 +- 17 files changed, 888 insertions(+), 864 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 139752f85a..82189e9910 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -10,9 +10,7 @@ struct nfp_cpp_mutex; -/* - * NFP CPP handle - */ +/* NFP CPP handle */ struct nfp_cpp { uint32_t model; uint32_t interface; @@ -37,9 +35,7 @@ struct nfp_cpp { int driver_lock_needed; }; -/* - * NFP CPP device area handle - */ +/* NFP CPP device area handle */ struct nfp_cpp_area { struct nfp_cpp *cpp; char *name; @@ -127,35 +123,45 @@ struct nfp_cpp_operations { #define NFP_CPP_TARGET_ID_MASK 0x1f -/* +/** * Pack target, token, and action into a CPP ID. * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id * - * @return NFP CPP ID + * @return + * NFP CPP ID */ #define NFP_CPP_ID(target, action, token) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ (((action) & 0xff) << 8)) -/* +/** * Pack target, token, action, and island into a CPP ID. - * @target NFP CPP target id - * @action NFP CPP action id - * @token NFP CPP token id - * @island NFP CPP island id * * Create a 32-bit CPP identifier representing the access to be made. * These identifiers are used as parameters to other NFP CPP functions. * Some CPP devices may allow wildcard identifiers to be specified. * - * @return NFP CPP ID + * @param target + * NFP CPP target id + * @param action + * NFP CPP action id + * @param token + * NFP CPP token id + * @param island + * NFP CPP island id + * + * @return + * NFP CPP ID */ #define NFP_CPP_ISLAND_ID(target, action, token, island) \ ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \ @@ -163,9 +169,12 @@ struct nfp_cpp_operations { /** * Return the NFP CPP target of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP target + * @param id + * NFP CPP ID + * + * @return + * NFP CPP target */ static inline uint8_t NFP_CPP_ID_TARGET_of(uint32_t id) @@ -173,11 +182,14 @@ NFP_CPP_ID_TARGET_of(uint32_t id) return (id >> 24) & NFP_CPP_TARGET_ID_MASK; } -/* +/** * Return the NFP CPP token of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP token + * @param id + * NFP CPP ID + * + * @return + * NFP CPP token */ static inline uint8_t NFP_CPP_ID_TOKEN_of(uint32_t id) @@ -185,11 +197,14 @@ NFP_CPP_ID_TOKEN_of(uint32_t id) return (id >> 16) & 0xff; } -/* +/** * Return the NFP CPP action of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP action + * @param id + * NFP CPP ID + * + * @return + * NFP CPP action */ static inline uint8_t NFP_CPP_ID_ACTION_of(uint32_t id) @@ -197,11 +212,14 @@ NFP_CPP_ID_ACTION_of(uint32_t id) return (id >> 8) & 0xff; } -/* +/** * Return the NFP CPP island of a NFP CPP ID - * @id NFP CPP ID * - * @return NFP CPP island + * @param id + * NFP CPP ID + * + * @return + * NFP CPP island */ static inline uint8_t NFP_CPP_ID_ISLAND_of(uint32_t id) @@ -215,109 +233,57 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) */ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); -/* - * Set the model id - * - * @param cpp NFP CPP operations structure - * @param model Model ID - */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param interface Interface ID - */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -/* - * Set the private instance owned data of a nfp_cpp struct - * - * @param cpp NFP CPP operations structure - * @param serial NFP serial byte array - * @param len Length of the serial byte array - */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); -/* - * Set the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); -/* - * Return the private data of the nfp_cpp instance - * - * @param cpp NFP CPP operations structure - * @return Opaque device pointer - */ void *nfp_cpp_priv(struct nfp_cpp *cpp); -/* - * Get the privately allocated portion of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the private area, or NULL on failure - */ void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); -/* - * NFP CPP core interface for CPP clients. - */ - -/* - * Open a NFP CPP handle to a CPP device - * - * @param[in] id 0-based ID for the CPP interface to use - * - * @return NFP CPP handle, or NULL on failure. - */ +/* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed); -/* - * Free a NFP CPP handle - * - * @param[in] cpp NFP CPP handle - */ void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/* - * NFP_CPP_MODEL_CHIP_of - retrieve the chip ID from the model ID +/** + * Retrieve the chip ID from the model ID * * The chip ID is a 16-bit BCD+A-F encoding for the chip type. * - * @param[in] model NFP CPP model id - * @return NFP CPP chip id + * @param model + * NFP CPP model id + * + * @return + * NFP CPP chip id */ #define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) -/* - * NFP_CPP_MODEL_IS_6000 - Check for the NFP6000 family of devices +/** + * Check for the NFP6000 family of devices * * NOTE: The NFP4000 series is considered as a NFP6000 series variant. * - * @param[in] model NFP CPP model id - * @return true if model is in the NFP6000 family, false otherwise. + * @param model + * NFP CPP model id + * + * @return + * true if model is in the NFP6000 family, false otherwise. */ #define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) -/* - * nfp_cpp_model - Retrieve the Model ID of the NFP - * - * @param[in] cpp NFP CPP handle - * @return NFP CPP Model ID - */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,7 +296,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); #define NFP_CPP_INTERFACE_TYPE_RPC 0x3 #define NFP_CPP_INTERFACE_TYPE_ILA 0x4 -/* +/** * Construct a 16-bit NFP Interface ID * * Interface IDs consists of 4 bits of interface type, 4 bits of unit @@ -340,422 +306,138 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * which use the MU Atomic CompareAndWrite operation - hence the limit to 16 * bits to be able to use the NFP Interface ID as a lock owner. * - * @param[in] type NFP Interface Type - * @param[in] unit Unit identifier for the interface type - * @param[in] channel Channel identifier for the interface unit - * @return Interface ID + * @param type + * NFP Interface Type + * @param unit + * Unit identifier for the interface type + * @param channel + * Channel identifier for the interface unit + * + * @return + * Interface ID */ #define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) -/* +/** * Get the interface type of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's type + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's type */ #define NFP_CPP_INTERFACE_TYPE_of(interface) (((interface) >> 12) & 0xf) -/* +/** * Get the interface unit of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's unit + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's unit */ #define NFP_CPP_INTERFACE_UNIT_of(interface) (((interface) >> 8) & 0xf) -/* +/** * Get the interface channel of a NFP Interface ID - * @param[in] interface NFP Interface ID - * @return NFP Interface ID's channel + * + * @param interface + * NFP Interface ID + * + * @return + * NFP Interface ID's channel */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) -/* - * Retrieve the Interface ID of the NFP - * @param[in] cpp NFP CPP handle - * @return NFP CPP Interface ID - */ + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -/* - * Retrieve the NFP Serial Number (unique per NFP) - * @param[in] cpp NFP CPP handle - * @param[out] serial Pointer to reference the serial number array - * - * @return size of the NFP6000 serial number, in bytes - */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Allocate a NFP CPP area handle, as an offset into a CPP ID, by a named owner - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] name Name of owner of the area - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t cpp_id, const char *name, uint64_t address, uint32_t size); -/* - * Free an allocated NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_free(struct nfp_cpp_area *area); -/* - * Acquire the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - * - * @return 0 on success, -1 on failure. - */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area); -/* - * Release the resources needed to access the NFP CPP area handle - * - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release(struct nfp_cpp_area *area); -/* - * Allocate, then acquire the resources needed to access the NFP CPP area handle - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] size Size of the area to reserve - * - * @return NFP CPP handle, or NULL on failure. - */ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); -/* - * Release the resources, then free the NFP CPP area handle - * @param[in] area NFP CPP area handle - */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area); uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); -/* - * Read from a NFP CPP area handle into a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer to receive the data - * @param[in] length Length of the data to read - * - * @return bytes read on success, negative value on failure. - * - */ int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, void *buffer, size_t length); -/* - * Write to a NFP CPP area handle from a buffer. The area must be acquired with - * 'nfp_cpp_area_acquire()' before calling this operation. - * - * @param[in] area NFP CPP area handle - * @param[in] offset Offset into the area - * @param[in] buffer Location of buffer that holds the data - * @param[in] length Length of the data to read - * - * @return bytes written on success, negative value on failure. - */ int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, const void *buffer, size_t length); -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area - * @area: CPP area handle - * - * Returns an iomem pointer for use with readl()/writel() style operations. - * - * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL - */ void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); -/* - * Get the NFP CPP handle that is the parent of a NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return NFP CPP handle - */ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); -/* - * Get the name passed during allocation of the NFP CPP area handle - * - * @param cpp_area NFP CPP area handle - * @return Pointer to the area's name - */ const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); -/* - * Read a block of data from a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy read data to - * @param[in] length Size of the area to reserve - * - * @return bytes read on success, -1 on failure. - */ int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, void *kernel_vaddr, size_t length); -/* - * Write a block of data to a NFP CPP ID - * - * @param[in] cpp NFP CPP handle - * @param[in] cpp_id NFP CPP ID - * @param[in] address Offset into the NFP CPP ID address space - * @param[in] kernel_vaddr Buffer to copy write data from - * @param[in] length Size of the area to reserve - * - * @return bytes written on success, -1 on failure. - */ int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, const void *kernel_vaddr, size_t length); -/* - * Read a single 32-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); -/* - * Write a single 32-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 32-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, uint32_t value); -/* - * Read a single 64-bit value from a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value output value - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, uint64_t *value); -/* - * Write a single 64-bit value to a NFP CPP area handle - * - * @param area NFP CPP area handle - * @param offset offset into NFP CPP area handle - * @param value value to write - * - * The area must be acquired with 'nfp_cpp_area_acquire()' before calling this - * operation. - * - * NOTE: offset must be 64-bit aligned. - * - * @return 0 on success, or -1 on error. - */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, uint64_t value); -/* - * Write a single 32-bit value on the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value); -/* - * Read a single 32-bit value from the XPB bus - * - * @param cpp NFP CPP device handle - * @param xpb_tgt XPB target and address - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value); -/* - * Read a 32-bit word from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t *value); -/* - * Write a 32-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - * - */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint32_t value); -/* - * Read a 64-bit work from a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value output value - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t *value); -/* - * Write a 64-bit value to a NFP CPP ID - * - * @param cpp NFP CPP handle - * @param cpp_id NFP CPP ID - * @param address offset into the NFP CPP ID address space - * @param value value to write - * - * @return 0 on success, or -1 on failure. - */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -/* - * Initialize a mutex location - - * The CPP target:address must point to a 64-bit aligned location, and will - * initialize 64 bits of data at the location. - * - * This creates the initial mutex state, as locked by this nfp_cpp_interface(). - * - * This function should only be called when setting up the initial lock state - * upon boot-up of the system. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id Unique 32-bit value for this mutex - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Create a mutex handle from an address controlled by a MU Atomic engine - * - * The CPP target:address must point to a 64-bit aligned location, and reserve - * 64 bits of data at the location for use by the handle. - * - * Only target/address pairs that point to entities that support the MU Atomic - * Engine's CmpAndSwap32 command are supported. - * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID - * @param address Offset into the address space of the NFP CPP target ID - * @param key_id 32-bit unique key (must match the key at this location) - * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on - * failure. - */ struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, uint64_t address, uint32_t key_id); -/* - * Free a mutex handle - does not alter the lock state - * - * @param mutex NFP CPP Mutex handle - */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); -/* - * Lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); -/* - * Unlock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * - * @return 0 on success, negative value on failure. - */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); -/* - * Attempt to lock a mutex handle, using the NFP MU Atomic Engine - * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. - */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index bdf4a658f5..7e94bfb611 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -72,40 +72,25 @@ #define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ (((bar) * 8 + (slot)) * 4) -/* - * Define to enable a bit more verbose debug output. - * Set to 1 to enable a bit more verbose debug output. - */ struct nfp_pcie_user; struct nfp6000_area_priv; -/* - * struct nfp_bar - describes BAR configuration and usage - * @nfp: backlink to owner - * @barcfg: cached contents of BAR config CSR - * @base: the BAR's base CPP offset - * @mask: mask for the BAR aperture (read only) - * @bitsize: bitsize of BAR aperture (read only) - * @index: index of the BAR - * @lock: lock to specify if bar is in use - * @refcnt: number of current users - * @iomem: mapped IO memory - */ +/* Describes BAR configuration and usage */ #define NFP_BAR_MIN 1 #define NFP_BAR_MID 5 #define NFP_BAR_MAX 7 struct nfp_bar { - struct nfp_pcie_user *nfp; - uint32_t barcfg; - uint64_t base; /* CPP address base */ - uint64_t mask; /* Bit mask of the bar */ - uint32_t bitsize; /* Bit size of the bar */ - uint32_t index; - int lock; + struct nfp_pcie_user *nfp; /**< Backlink to owner */ + uint32_t barcfg; /**< BAR config CSR */ + uint64_t base; /**< Base CPP offset */ + uint64_t mask; /**< Mask of the BAR aperture (read only) */ + uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ + uint32_t index; /**< Index of the BAR */ + int lock; /**< If the BAR has been locked */ char *csr; - char *iomem; + char *iomem; /**< mapped IO memory */ }; #define BUSDEV_SZ 13 @@ -360,9 +345,7 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* - * Generic CPP bus access interface. - */ +/* Generic CPP bus access interface. */ struct nfp6000_area_priv { struct nfp_bar *bar; diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index e2af888a28..0e8372576e 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -26,6 +26,15 @@ #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/** + * Set the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv) @@ -33,12 +42,29 @@ nfp_cpp_priv_set(struct nfp_cpp *cpp, cpp->priv = priv; } +/** + * Return the private data of the nfp_cpp instance + * + * @param cpp + * NFP CPP operations structure + * + * @return + * Opaque device pointer + */ void * nfp_cpp_priv(struct nfp_cpp *cpp) { return cpp->priv; } +/** + * Set the model id + * + * @param cpp + * NFP CPP operations structure + * @param model + * Model ID + */ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model) @@ -46,6 +72,15 @@ nfp_cpp_model_set(struct nfp_cpp *cpp, cpp->model = model; } +/** + * Retrieve the Model ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Model ID + */ uint32_t nfp_cpp_model(struct nfp_cpp *cpp) { @@ -63,6 +98,14 @@ nfp_cpp_model(struct nfp_cpp *cpp) return model; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param interface + * Interface ID + */ void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface) @@ -70,6 +113,17 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, cpp->interface = interface; } +/** + * Retrieve the Serial ID of the NFP + * + * @param cpp + * NFP CPP handle + * @param serial + * Pointer to NFP serial number + * + * @return + * Length of NFP serial number + */ int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) @@ -78,6 +132,16 @@ nfp_cpp_serial(struct nfp_cpp *cpp, return cpp->serial_len; } +/** + * Set the private instance owned data of a nfp_cpp struct + * + * @param cpp + * NFP CPP operations structure + * @param serial + * NFP serial byte array + * @param serial_len + * Length of the serial byte array + */ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, @@ -96,6 +160,15 @@ nfp_cpp_serial_set(struct nfp_cpp *cpp, return 0; } +/** + * Retrieve the Interface ID of the NFP + * + * @param cpp + * NFP CPP handle + * + * @return + * NFP CPP Interface ID + */ uint16_t nfp_cpp_interface(struct nfp_cpp *cpp) { @@ -105,18 +178,45 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Get the privately allocated portion of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the private area, or NULL on failure + */ void * nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area) { return &cpp_area[1]; } +/** + * Get the NFP CPP handle that is the pci_dev of a NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * NFP CPP handle + */ struct nfp_cpp * nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area) { return cpp_area->cpp; } +/** + * Get the name passed during allocation of the NFP CPP area handle + * + * @param cpp_area + * NFP CPP area handle + * + * @return + * Pointer to the area's name + */ const char * nfp_cpp_area_name(struct nfp_cpp_area *cpp_area) { @@ -153,15 +253,24 @@ nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp) return cpp->mu_locality_lsb; } -/* - * nfp_cpp_area_alloc - allocate a new CPP area - * @cpp: CPP handle - * @dest: CPP id - * @address: start address on CPP target - * @size: size of area in bytes +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. * - * Allocate and initialize a CPP area structure. The area must later - * be locked down with an 'acquire' before it can be safely accessed. + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param name + * Name of region + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL * * NOTE: @address and @size must be 32-bit aligned values. */ @@ -211,6 +320,25 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, return area; } +/** + * Allocate and initialize a CPP area structure. + * The area must later be locked down with an 'acquire' before + * it can be safely accessed. + * + * @param cpp + * CPP device handle + * @param dest + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * + * NOTE: @address and @size must be 32-bit aligned values. + */ struct nfp_cpp_area * nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t dest, @@ -220,17 +348,22 @@ nfp_cpp_area_alloc(struct nfp_cpp *cpp, 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 - * @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. * + * @param cpp + * CPP device handle + * @param destination + * CPP id + * @param address + * Address of region + * @param size + * Size of region + * + * @return + * NFP CPP area handle, or NULL + * * NOTE: @address and @size must be 32-bit aligned values. * * NOTE: The area must also be 'released' when the structure is freed. @@ -258,11 +391,11 @@ nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp, return area; } -/* - * nfp_cpp_area_free - free up the CPP area - * area: CPP area handle - * +/** * Frees up memory resources held by the CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_free(struct nfp_cpp_area *area) @@ -272,11 +405,11 @@ nfp_cpp_area_free(struct nfp_cpp_area *area) free(area); } -/* - * nfp_cpp_area_release_free - release CPP area and free it - * area: CPP area handle +/** + * Releases CPP area and frees up memory resources held by it. * - * Releases CPP area and frees up memory resources held by the it. + * @param area + * CPP area handle */ void nfp_cpp_area_release_free(struct nfp_cpp_area *area) @@ -285,12 +418,15 @@ nfp_cpp_area_release_free(struct nfp_cpp_area *area) nfp_cpp_area_free(area); } -/* - * nfp_cpp_area_acquire - lock down a CPP area for access - * @area: CPP area handle +/** + * Locks down the CPP area for a potential long term activity. + * Area must always be locked down before being accessed. * - * Locks down the CPP area for a potential long term activity. Area - * must always be locked down before being accessed. + * @param area + * CPP area handle + * + * @return + * 0 on success, -1 on failure. */ int nfp_cpp_area_acquire(struct nfp_cpp_area *area) @@ -307,11 +443,11 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) return 0; } -/* - * nfp_cpp_area_release - release a locked down CPP area - * @area: CPP area handle - * +/** * Releases a previously locked down CPP area. + * + * @param area + * CPP area handle */ void nfp_cpp_area_release(struct nfp_cpp_area *area) @@ -320,16 +456,16 @@ nfp_cpp_area_release(struct nfp_cpp_area *area) area->cpp->op->area_release(area); } -/* - * nfp_cpp_area_iomem() - get IOMEM region for CPP area +/** + * Returns an iomem pointer for use with readl()/writel() style operations. * - * @area: CPP area handle + * @param area + * CPP area handle * - * Returns an iomem pointer for use with readl()/writel() style operations. + * @return + * Pointer to the area, or NULL * * NOTE: Area must have been locked down with an 'acquire'. - * - * Return: pointer to the area, or NULL */ void * nfp_cpp_area_iomem(struct nfp_cpp_area *area) @@ -342,18 +478,22 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) return iomem; } -/* - * nfp_cpp_area_read - read data from CPP area +/** + * Read data from indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to put data into - * @length: number of bytes to read + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Read data from indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -368,18 +508,22 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, return area->cpp->op->area_read(area, kernel_vaddr, offset, length); } -/* - * nfp_cpp_area_write - write data to CPP area +/** + * Write data to indicated CPP region. * - * @area: CPP area handle - * @offset: offset into CPP area - * @kernel_vaddr: kernel address to read data from - * @length: number of bytes to write + * @param area + * CPP area handle + * @param offset + * Offset into CPP area + * @param kernel_vaddr + * Address to put data into + * @param length + * Number of bytes to read * - * Write data to indicated CPP region. + * @return + * Length of io, or -ERRNO * * NOTE: @offset and @length must be 32-bit aligned values. - * * NOTE: Area must have been locked down with an 'acquire'. */ int @@ -436,6 +580,19 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, return xpb; } +/** + * Read a uint32_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, @@ -450,6 +607,19 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset, @@ -462,6 +632,19 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset, @@ -476,6 +659,19 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t vale to an area + * + * @param area + * CPP Area handle + * @param offset + * Offset into area + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset, @@ -489,6 +685,21 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint32_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -504,6 +715,21 @@ nfp_cpp_readl(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint32_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -518,6 +744,21 @@ nfp_cpp_writel(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Read a uint64_t value from a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -533,6 +774,21 @@ nfp_cpp_readq(struct nfp_cpp *cpp, return (sz == sizeof(*value)) ? 0 : -1; } +/** + * Write a uint64_t value to a CPP location + * + * @param cpp + * CPP device handle + * @param cpp_id + * CPP ID for operation + * @param address + * Address for operation + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, @@ -547,6 +803,19 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, return (sz == sizeof(value)) ? 0 : -1; } +/** + * Write a uint32_t word to a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Value to write + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -559,6 +828,19 @@ nfp_xpb_writel(struct nfp_cpp *cpp, return nfp_cpp_writel(cpp, cpp_dest, xpb_addr, value); } +/** + * Read a uint32_t value from a XPB location + * + * @param cpp + * CPP device handle + * @param xpb_addr + * XPB target and address + * @param value + * Pointer to read buffer + * + * @return + * 0 on success, or -ERRNO + */ int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, @@ -625,9 +907,11 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return cpp; } -/* - * nfp_cpp_free - free the CPP handle - * @cpp: CPP handle +/** + * Free the CPP handle + * + * @param cpp + * CPP handle */ void nfp_cpp_free(struct nfp_cpp *cpp) @@ -641,6 +925,19 @@ nfp_cpp_free(struct nfp_cpp *cpp) free(cpp); } +/** + * Create a NFP CPP handle from device + * + * @param dev + * PCI device + * @param driver_lock_needed + * Driver lock flag + * + * @return + * NFP CPP handle on success, NULL on failure + * + * NOTE: On failure, cpp_ops->free will be called! + */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) @@ -648,13 +945,22 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, return nfp_cpp_alloc(dev, driver_lock_needed); } -/* - * nfp_cpp_read - read from CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer for result - * @length: number of bytes to read +/** + * Read from CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer for result + * @param length + * Number of bytes to read + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_read(struct nfp_cpp *cpp, @@ -678,13 +984,22 @@ nfp_cpp_read(struct nfp_cpp *cpp, return err; } -/* - * nfp_cpp_write - write to CPP target - * @cpp: CPP handle - * @destination: CPP id - * @address: offset into CPP target - * @kernel_vaddr: kernel buffer to read from - * @length: number of bytes to write +/** + * Write to CPP target + * + * @param cpp + * CPP handle + * @param destination + * CPP id + * @param address + * Offset into CPP target + * @param kernel_vaddr + * Buffer to read from + * @param length + * Number of bytes to write + * + * @return + * Length of io, or -ERRNO */ int nfp_cpp_write(struct nfp_cpp *cpp, @@ -731,18 +1046,23 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return 0; } -/* - * nfp_cpp_map_area() - Helper function to map an area - * @cpp: NFP CPP handler - * @cpp_id: CPP ID - * @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). * - * Map an area of IOMEM access. To undo the effect of this function call - * @nfp_cpp_area_release_free(*area). + * @param cpp + * NFP CPP handler + * @param cpp_id + * CPP id + * @param addr + * CPP address + * @param size + * Size of the area + * @param area + * Area handle (output) * - * Return: Pointer to memory mapped area or NULL + * @return + * Pointer to memory mapped area or NULL */ uint8_t * nfp_cpp_map_area(struct nfp_cpp *cpp, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index b658b5e900..f5579ab60f 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -3,7 +3,8 @@ * All rights reserved. */ -/* Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM +/* + * Parse the hwinfo table that the ARM firmware builds in the ARM scratch SRAM * after chip reset. * * Examples of the fields: @@ -146,7 +147,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, struct nfp_hwinfo *db; wait.tv_sec = 0; - wait.tv_nsec = 10000000; + wait.tv_nsec = 10000000; /* 10ms */ for (;;) { db = nfp_hwinfo_try_fetch(cpp, hwdb_size); @@ -154,7 +155,7 @@ nfp_hwinfo_fetch(struct nfp_cpp *cpp, return db; nanosleep(&wait, NULL); - if (count++ > 200) { + if (count++ > 200) { /* 10ms * 200 = 2s */ PMD_DRV_LOG(ERR, "NFP access error"); return NULL; } @@ -180,12 +181,16 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) return db; } -/* - * nfp_hwinfo_lookup() - Find a value in the HWInfo table by name - * @hwinfo: NFP HWinfo table - * @lookup: HWInfo name to search for +/** + * Find a value in the HWInfo table by name + * + * @param hwinfo + * NFP HWInfo table + * @param lookup + * HWInfo name to search for * - * Return: Value of the HWInfo name, or NULL + * @return + * Value of the HWInfo name, or NULL */ const char * nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index a3da7512db..424db8035d 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -59,6 +59,8 @@ * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' * * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. */ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 086e82db70..0892c99e96 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -87,15 +87,16 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, return err; } -/* - * nfp_mip_open() - Get device MIP structure - * @cpp: NFP CPP Handle - * - * Copy MIP structure from NFP device and return it. The returned +/** + * Copy MIP structure from NFP device and return it. The returned * structure is handled internally by the library and should be - * freed by calling nfp_mip_close(). + * freed by calling @nfp_mip_close(). + * + * @param cpp + * NFP CPP Handle * - * Return: pointer to mip, NULL on failure. + * @return + * Pointer to MIP, NULL on failure. */ struct nfp_mip * nfp_mip_open(struct nfp_cpp *cpp) @@ -131,11 +132,15 @@ nfp_mip_name(const struct nfp_mip *mip) return mip->name; } -/* - * nfp_mip_symtab() - Get the address and size of the MIP symbol table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol table - * @size: Location for size of MIP symbol table +/** + * Get the address and size of the MIP symbol table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol table + * @param size + * Location for size of MIP symbol table */ void nfp_mip_symtab(const struct nfp_mip *mip, @@ -146,11 +151,15 @@ nfp_mip_symtab(const struct nfp_mip *mip, *size = rte_le_to_cpu_32(mip->symtab_size); } -/* - * nfp_mip_strtab() - Get the address and size of the MIP symbol name table - * @mip: MIP handle - * @addr: Location for NFP DDR address of MIP symbol name table - * @size: Location for size of MIP symbol name table +/** + * Get the address and size of the MIP symbol name table. + * + * @param mip + * MIP handle + * @param addr + * Location for NFP DDR address of MIP symbol name table + * @param size + * Location for size of MIP symbol name table */ void nfp_mip_strtab(const struct nfp_mip *mip, diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82919d8270..404d4fa938 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -53,7 +53,7 @@ _nfp_cpp_mutex_validate(uint32_t model, return 0; } -/* +/** * Initialize a mutex location * * The CPP target:address must point to a 64-bit aligned location, and @@ -65,13 +65,17 @@ _nfp_cpp_mutex_validate(uint32_t model, * This function should only be called when setting up * the initial lock state upon boot-up of the system. * - * @param mutex NFP CPP Mutex handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key Unique 32-bit value for this mutex + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * Unique 32-bit value for this mutex * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_init(struct nfp_cpp *cpp, @@ -99,7 +103,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, return 0; } -/* +/** * Create a mutex handle from an address controlled by a MU Atomic engine * * The CPP target:address must point to a 64-bit aligned location, and @@ -108,13 +112,17 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, * Only target/address pairs that point to entities that support the * MU Atomic Engine are supported. * - * @param cpp NFP CPP handle - * @param target NFP CPP target ID (ie NFP_CPP_TARGET_CLS or - * NFP_CPP_TARGET_MU) - * @param address Offset into the address space of the NFP CPP target ID - * @param key 32-bit unique key (must match the key at this location) + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * @param key + * 32-bit unique key (must match the key at this location) * - * @return A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. + * @return + * A non-NULL struct nfp_cpp_mutex * on success, NULL on failure. */ struct nfp_cpp_mutex * nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, @@ -178,10 +186,11 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return mutex; } -/* +/** * Free a mutex handle - does not alter the lock state * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle */ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) @@ -203,12 +212,14 @@ nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) free(mutex); } -/* +/** * Lock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure. */ int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) @@ -229,12 +240,14 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) return 0; } -/* +/** * Unlock a mutex handle, using the NFP MU Atomic Engine * - * @param mutex NFP CPP Mutex handle + * @param mutex + * NFP CPP Mutex handle * - * @return 0 on success, or negative value on failure. + * @return + * 0 on success, or negative value on failure */ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) @@ -280,16 +293,18 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return err; } -/* +/** * Attempt to lock a mutex handle, using the NFP MU Atomic Engine * * Valid lock states: - * * 0x....0000 - Unlocked * 0x....000f - Locked * - * @param mutex NFP CPP Mutex handle - * @return 0 if the lock succeeded, negative value on failure. + * @param mutex + * NFP CPP Mutex handle + * + * @return + * 0 if the lock succeeded, negative value on failure. */ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) @@ -352,7 +367,7 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) * If there was another contending for this lock, then * the lock state would be 0x....000f * - * Write our owner ID into the lock + * Write our owner ID into the lock. * While not strictly necessary, this helps with * debug and bookkeeping. */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index b5a354137d..5f004e3b21 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -52,7 +52,7 @@ nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 8) | mip_offset_lo */ +/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { @@ -112,11 +112,14 @@ nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, } } -/* - * nfp_nffw_info_open() - Acquire the lock on the NFFW table - * @cpp: NFP CPP handle +/** + * Acquire the lock on the NFFW table + * + * @param cpp + * NFP CPP handle * - * Return: nffw info pointer, or NULL on failure + * @return + * NFFW info pointer, or NULL on failure */ struct nfp_nffw_info * nfp_nffw_info_open(struct nfp_cpp *cpp) @@ -168,11 +171,11 @@ nfp_nffw_info_open(struct nfp_cpp *cpp) return NULL; } -/* - * nfp_nffw_info_close() - Release the lock on the NFFW table - * @state: NFP FW info state +/** + * Release the lock on the NFFW table * - * Return: void + * @param state + * NFFW info pointer */ void nfp_nffw_info_close(struct nfp_nffw_info *state) @@ -181,11 +184,14 @@ nfp_nffw_info_close(struct nfp_nffw_info *state) free(state); } -/* - * nfp_nffw_info_fwid_first() - Return the first firmware ID in the NFFW - * @state: NFP FW info state +/** + * Return the first firmware ID in the NFFW * - * Return: First NFFW firmware info, NULL on failure + * @param state + * NFFW info pointer + * + * @return: + * First NFFW firmware info, NULL on failure */ static struct nffw_fwinfo * nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) @@ -205,13 +211,18 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) return NULL; } -/* - * nfp_nffw_info_mip_first() - Retrieve the location of the first FW's MIP - * @state: NFP FW info state - * @cpp_id: Pointer to the CPP ID of the MIP - * @off: Pointer to the CPP Address of the MIP +/** + * Retrieve the location of the first FW's MIP + * + * @param state + * NFFW info pointer + * @param cpp_id + * Pointer to the CPP ID of the MIP + * @param off + * Pointer to the CPP Address of the MIP * - * Return: 0, or -ERRNO + * @return + * 0, or -ERRNO */ int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 46ac8a8d07..e032b6cce7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,7 +8,8 @@ #include "nfp_cpp.h" -/* Init-CSR owner IDs for firmware map to firmware IDs which start at 4. +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. * Lower IDs are reserved for target and loader IDs. */ #define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ @@ -16,7 +17,7 @@ #define NFFW_FWID_ALL 255 -/** +/* * NFFW_INFO_VERSION history: * 0: This was never actually used (before versioning), but it refers to * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later @@ -35,6 +36,7 @@ #define NFFW_MEINFO_CNT_V2 200 #define NFFW_FWINFO_CNT_V2 200 +/* nfp.nffw meinfo */ struct nffw_meinfo { uint32_t ctxmask__fwid__meid; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index ff19446173..a96ccea38b 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -109,9 +109,11 @@ nfp_nsp_check(struct nfp_nsp *state) return 0; } -/* - * nfp_nsp_open() - Prepare for communication and lock the NSP resource. - * @cpp: NFP CPP Handle +/** + * Prepare for communication and lock the NSP resource. + * + * @param cpp + * NFP CPP Handle */ struct nfp_nsp * nfp_nsp_open(struct nfp_cpp *cpp) @@ -145,9 +147,11 @@ nfp_nsp_open(struct nfp_cpp *cpp) return state; } -/* - * nfp_nsp_close() - Clean up and unlock the NSP resource. - * @state: NFP SP state +/** + * Clean up and unlock the NSP resource. + * + * @param state + * NFP SP state */ void nfp_nsp_close(struct nfp_nsp *state) @@ -181,7 +185,7 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_cpp_readq(cpp, nsp_cpp, addr, reg); @@ -194,28 +198,27 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, return 0; nanosleep(&wait, 0); - if (count++ > 1000) + if (count++ > 1000) /* 25ms * 1000 = 25s */ return -ETIMEDOUT; } } -/* - * nfp_nsp_command() - Execute a command on the NFP Service Processor - * @state: NFP SP state - * @code: NFP SP Command Code - * @option: NFP SP Command Argument - * @buff_cpp: NFP SP Buffer CPP Address info - * @buff_addr: NFP SP Buffer Host address - * - * Return: 0 for success with no result +/** + * Execute a command on the NFP Service Processor * - * positive value for NSP completion with a result code + * @param state + * NFP SP state + * @param arg + * NFP command argument structure * - * -EAGAIN if the NSP is not yet present - * -ENODEV if the NSP is not a supported model - * -EBUSY if the NSP is stuck - * -EINTR if interrupted while waiting for completion - * -ETIMEDOUT if the NSP took longer than 30 seconds to complete + * @return + * - 0 for success with no result + * - Positive value for NSP completion with a result code + * - -EAGAIN if the NSP is not yet present + * - -ENODEV if the NSP is not a supported model + * - -EBUSY if the NSP is stuck + * - -EINTR if interrupted while waiting for completion + * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int nfp_nsp_command(struct nfp_nsp *state, @@ -383,7 +386,7 @@ nfp_nsp_wait(struct nfp_nsp *state) struct timespec wait; wait.tv_sec = 0; - wait.tv_nsec = 25000000; + wait.tv_nsec = 25000000; /* 25ms */ for (;;) { err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); @@ -392,7 +395,7 @@ nfp_nsp_wait(struct nfp_nsp *state) nanosleep(&wait, 0); - if (count++ > 1000) { + if (count++ > 1000) { /* 25ms * 1000 = 25s */ err = -ETIMEDOUT; break; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index edb56e26ca..0fcb21e99c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -158,72 +158,45 @@ enum nfp_eth_fec { #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) -/** - * struct nfp_eth_table - ETH table information - * @count: number of table entries - * @max_index: max of @index fields of all @ports - * @ports: table of ports - * - * @eth_index: port index according to legacy ethX numbering - * @index: chip-wide first channel index - * @nbi: NBI index - * @base: first channel index (within NBI) - * @lanes: number of channels - * @speed: interface speed (in Mbps) - * @interface: interface (module) plugged in - * @media: media type of the @interface - * @fec: forward error correction mode - * @aneg: auto negotiation mode - * @mac_addr: interface MAC address - * @label_port: port id - * @label_subport: id of interface within port (for split ports) - * @enabled: is enabled? - * @tx_enabled: is TX enabled? - * @rx_enabled: is RX enabled? - * @override_changed: is media reconfig pending? - * - * @port_type: one of %PORT_* defines for ethtool - * @port_lanes: total number of lanes on the port (sum of lanes of all subports) - * @is_split: is interface part of a split port - * @fec_modes_supported: bitmap of FEC modes supported - */ +/* ETH table information */ struct nfp_eth_table { - uint32_t count; - uint32_t max_index; + uint32_t count; /**< Number of table entries */ + uint32_t max_index; /**< Max of @index fields of all @ports */ struct nfp_eth_table_port { + /** Port index according to legacy ethX numbering */ uint32_t eth_index; - uint32_t index; - uint32_t nbi; - uint32_t base; - uint32_t lanes; - uint32_t speed; + uint32_t index; /**< Chip-wide first channel index */ + uint32_t nbi; /**< NBI index */ + uint32_t base; /**< First channel index (within NBI) */ + uint32_t lanes; /**< Number of channels */ + uint32_t speed; /**< Interface speed (in Mbps) */ - uint32_t interface; - enum nfp_eth_media media; + uint32_t interface; /**< Interface (module) plugged in */ + enum nfp_eth_media media; /**< Media type of the @interface */ - enum nfp_eth_fec fec; - enum nfp_eth_aneg aneg; + enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ - struct rte_ether_addr mac_addr; + struct rte_ether_addr mac_addr; /**< Interface MAC address */ - uint8_t label_port; + uint8_t label_port; /**< Port id */ + /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; - int tx_enabled; - int rx_enabled; - - int override_changed; + int enabled; /**< Enable port */ + int tx_enabled; /**< Enable TX */ + int rx_enabled; /**< Enable RX */ - /* Computed fields */ - uint8_t port_type; + int override_changed; /**< Media reconfig pending */ + uint8_t port_type; /**< One of %PORT_* */ + /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; + int is_split; /**< Split port */ - uint32_t fec_modes_supported; - } ports[]; + uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ + } ports[]; /**< Table of ports */ }; struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); @@ -263,28 +236,17 @@ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); -/** - * struct nfp_nsp_identify - NSP static information - * @version: opaque version string - * @flags: version flags - * @br_primary: branch id of primary bootloader - * @br_secondary: branch id of secondary bootloader - * @br_nsp: branch id of NSP - * @primary: version of primary bootloader - * @secondary: version id of secondary bootloader - * @nsp: version id of NSP - * @sensor_mask: mask of present sensors available on NIC - */ +/* NSP static information */ struct nfp_nsp_identify { - char version[40]; - uint8_t flags; - uint8_t br_primary; - uint8_t br_secondary; - uint8_t br_nsp; - uint16_t primary; - uint16_t secondary; - uint16_t nsp; - uint64_t sensor_mask; + char version[40]; /**< Opaque version string */ + uint8_t flags; /**< Version flags */ + uint8_t br_primary; /**< Branch id of primary bootloader */ + uint8_t br_secondary; /**< Branch id of secondary bootloader */ + uint8_t br_nsp; /**< Branch id of NSP */ + uint16_t primary; /**< Version of primary bootloader */ + uint16_t secondary; /**< Version id of secondary bootloader */ + uint16_t nsp; /**< Version id of NSP */ + uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 74daa92aed..cb090d2a47 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -264,7 +264,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) goto err; } - /* The NFP3800 NIC support 8 ports, but only 2 ports are valid, + /* + * The NFP3800 NIC support 8 ports, but only 2 ports are valid, * the rest 6 ports mac are all 0, ensure we don't use these port */ for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { @@ -274,7 +275,8 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) cnt++; } - /* Some versions of flash will give us 0 instead of port count. For + /* + * Some versions of flash will give us 0 instead of port count. For * those that give a port count, verify it against the value calculated * above. */ @@ -312,14 +314,16 @@ __nfp_eth_read_ports(struct nfp_nsp *nsp) return NULL; } -/* - * nfp_eth_read_ports() - retrieve port information - * @cpp: NFP CPP handle +/** + * Read the port information from the device. + * + * Returned structure should be freed once no longer needed. * - * Read the port information from the device. Returned structure should - * be freed with kfree() once no longer needed. + * @param cpp + * NFP CPP handle * - * Return: populated ETH table or NULL on error. + * @return + * Populated ETH table or NULL on error. */ struct nfp_eth_table * nfp_eth_read_ports(struct nfp_cpp *cpp) @@ -387,19 +391,19 @@ nfp_eth_config_cleanup_end(struct nfp_nsp *nsp) free(entries); } -/* - * nfp_eth_config_commit_end() - perform recorded configuration changes - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * +/** * Perform the configuration which was requested with __nfp_eth_set_*() - * helpers and recorded in @nsp state. If device was already configured - * as requested or no __nfp_eth_set_*() operations were made no NSP command + * helpers and recorded in @nsp state. If device was already configured + * as requested or no __nfp_eth_set_*() operations were made, no NSP command * will be performed. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_config_commit_end(struct nfp_nsp *nsp) @@ -417,19 +421,21 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) return ret; } -/* - * nfp_eth_set_mod_enable() - set PHY module enable control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @enable: Desired state - * +/** * Enable or disable PHY module (this usually means setting the TX lanes * disable bits). * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param enable + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, @@ -460,18 +466,20 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * nfp_eth_set_configured() - set PHY module configured control bit - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @configed: Desired state - * +/** * Set the ifup/ifdown state on the PHY. * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param configured + * Desired state + * + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_configured(struct nfp_cpp *cpp, @@ -525,7 +533,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, /* * Note: set features were added in ABI 0.14 but the error - * codes were initially not populated correctly. + * codes were initially not populated correctly. */ if (nfp_nsp_get_abi_ver_minor(nsp) < 17) { PMD_DRV_LOG(ERR, "set operations not supported, please update flash"); @@ -555,15 +563,17 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, val, ctrl_bit); \ })) -/* - * __nfp_eth_set_aneg() - set PHY autonegotiation control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired autonegotiation mode - * +/** * Allow/disallow PHY module to advertise/perform autonegotiation. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired autonegotiation mode + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_aneg(struct nfp_nsp *nsp, @@ -573,15 +583,17 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, NSP_ETH_STATE_ANEG, mode, NSP_ETH_CTRL_SET_ANEG); } -/* - * __nfp_eth_set_fec() - set PHY forward error correction control bit - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @mode: Desired fec mode - * +/** * Set the PHY module forward error correction mode. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param mode + * Desired fec mode + * + * @return + * 0 or -ERRNO */ static int __nfp_eth_set_fec(struct nfp_nsp *nsp, @@ -591,16 +603,20 @@ __nfp_eth_set_fec(struct nfp_nsp *nsp, NSP_ETH_STATE_FEC, mode, NSP_ETH_CTRL_SET_FEC); } -/* - * nfp_eth_set_fec() - set PHY forward error correction control mode - * @cpp: NFP CPP handle - * @idx: NFP chip-wide port index - * @mode: Desired fec mode +/** + * Set PHY forward error correction control mode + * + * @param cpp + * NFP CPP handle + * @param idx + * NFP chip-wide port index + * @param mode + * Desired fec mode * - * Return: - * 0 - configuration successful; - * 1 - no changes were needed; - * -ERRNO - configuration failed. + * @return + * - (0) Configuration successful + * - (1) No changes were needed + * - (-ERRNO) Configuration failed */ int nfp_eth_set_fec(struct nfp_cpp *cpp, @@ -623,17 +639,19 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, return nfp_eth_config_commit_end(nsp); } -/* - * __nfp_eth_set_speed() - set interface speed/rate - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @speed: Desired speed (per lane) - * - * Set lane speed. Provided @speed value should be subport speed divided - * by number of lanes this subport is spanning (i.e. 10000 for 40G, 25000 for - * 50G, etc.) +/** + * Set lane speed. + * Provided @speed value should be subport speed divided by number of + * lanes this subport is spanning (i.e. 10000 for 40G, 25000 for 50G, etc.) * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param speed + * Desired speed (per lane) + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_speed(struct nfp_nsp *nsp, @@ -651,15 +669,17 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, NSP_ETH_STATE_RATE, rate, NSP_ETH_CTRL_SET_RATE); } -/* - * __nfp_eth_set_split() - set interface lane split - * @nsp: NFP NSP handle returned from nfp_eth_config_start() - * @lanes: Desired lanes per port - * +/** * Set number of lanes in the port. * Will write to hwinfo overrides in the flash (persistent config). * - * Return: 0 or -ERRNO. + * @param nsp + * NFP NSP handle returned from nfp_eth_config_start() + * @param lanes + * Desired lanes per port + * + * @return + * 0 or -ERRNO */ int __nfp_eth_set_split(struct nfp_nsp *nsp, diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 363f7d6198..bdebf5c3aa 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -22,32 +22,23 @@ #define NFP_RESOURCE_ENTRY_NAME_SZ 8 -/* - * struct nfp_resource_entry - Resource table entry - * @owner: NFP CPP Lock, interface owner - * @key: NFP CPP Lock, posix_crc32(name, 8) - * @region: Memory region descriptor - * @name: ASCII, zero padded name - * @reserved - * @cpp_action: CPP Action - * @cpp_token: CPP Token - * @cpp_target: CPP Target ID - * @page_offset: 256-byte page offset into target's CPP address - * @page_size: size, in 256-byte pages - */ +/* Resource table entry */ struct nfp_resource_entry { struct nfp_resource_entry_mutex { - uint32_t owner; - uint32_t key; + uint32_t owner; /**< NFP CPP Lock, interface owner */ + uint32_t key; /**< NFP CPP Lock, posix_crc32(name, 8) */ } mutex; + /* Memory region descriptor */ struct nfp_resource_entry_region { + /** ASCII, zero padded name */ uint8_t name[NFP_RESOURCE_ENTRY_NAME_SZ]; uint8_t reserved[5]; - uint8_t cpp_action; - uint8_t cpp_token; - uint8_t cpp_target; + uint8_t cpp_action; /**< CPP Action */ + uint8_t cpp_token; /**< CPP Token */ + uint8_t cpp_target; /**< CPP Target ID */ + /** 256-byte page offset into target's CPP address */ uint32_t page_offset; - uint32_t page_size; + uint32_t page_size; /**< Size, in 256-byte pages */ } region; }; @@ -147,14 +138,18 @@ nfp_resource_try_acquire(struct nfp_cpp *cpp, return err; } -/* - * nfp_resource_acquire() - Acquire a resource handle - * @cpp: NFP CPP handle - * @name: Name of the resource +/** + * Acquire a resource handle + * + * Note: This function locks the acquired resource. * - * NOTE: This function locks the acquired resource + * @param cpp + * NFP CPP handle + * @param name + * Name of the resource * - * Return: NFP Resource handle, or NULL + * @return + * NFP Resource handle, or NULL */ struct nfp_resource * nfp_resource_acquire(struct nfp_cpp *cpp, @@ -183,7 +178,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, } wait.tv_sec = 0; - wait.tv_nsec = 1000000; + wait.tv_nsec = 1000000; /* 1ms */ for (;;) { err = nfp_resource_try_acquire(cpp, res, dev_mutex); @@ -194,7 +189,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, goto err_free; } - if (count++ > 1000) { + if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); err = -EBUSY; goto err_free; @@ -213,11 +208,13 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_resource_release() - Release a NFP Resource handle - * @res: NFP Resource handle +/** + * Release a NFP Resource handle * - * NOTE: This function implicitly unlocks the resource handle + * NOTE: This function implicitly unlocks the resource handle. + * + * @param res + * NFP Resource handle */ void nfp_resource_release(struct nfp_resource *res) @@ -227,11 +224,14 @@ nfp_resource_release(struct nfp_resource *res) free(res); } -/* - * nfp_resource_cpp_id() - Return the cpp_id of a resource handle - * @res: NFP Resource handle +/** + * Return the cpp_id of a resource handle + * + * @param res + * NFP Resource handle * - * Return: NFP CPP ID + * @return + * NFP CPP ID */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res) @@ -239,11 +239,14 @@ nfp_resource_cpp_id(const struct nfp_resource *res) return res->cpp_id; } -/* - * nfp_resource_name() - Return the name of a resource handle - * @res: NFP Resource handle +/** + * Return the name of a resource handle * - * Return: const char pointer to the name of the resource + * @param res + * NFP Resource handle + * + * @return + * Const char pointer to the name of the resource */ const char * nfp_resource_name(const struct nfp_resource *res) @@ -251,11 +254,14 @@ nfp_resource_name(const struct nfp_resource *res) return res->name; } -/* - * nfp_resource_address() - Return the address of a resource handle - * @res: NFP Resource handle +/** + * Return the address of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Address of the resource + * @return + * Address of the resource */ uint64_t nfp_resource_address(const struct nfp_resource *res) @@ -263,11 +269,14 @@ nfp_resource_address(const struct nfp_resource *res) return res->addr; } -/* - * nfp_resource_size() - Return the size in bytes of a resource handle - * @res: NFP Resource handle +/** + * Return the size in bytes of a resource handle + * + * @param res + * NFP Resource handle * - * Return: Size of the resource in bytes + * @return + * Size of the resource in bytes */ uint64_t nfp_resource_size(const struct nfp_resource *res) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 009b7359a4..4236950caf 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -8,43 +8,27 @@ #include "nfp_cpp.h" +/* Netronone Flow Firmware Table */ #define NFP_RESOURCE_NFP_NFFW "nfp.nffw" + +/* NFP Hardware Info Database */ #define NFP_RESOURCE_NFP_HWINFO "nfp.info" + +/* Service Processor */ #define NFP_RESOURCE_NSP "nfp.sp" -/** - * Opaque handle to a NFP Resource - */ +/* Opaque handle to a NFP Resource */ struct nfp_resource; struct nfp_resource *nfp_resource_acquire(struct nfp_cpp *cpp, const char *name); -/** - * Release a NFP Resource, and free the handle - * @param[in] res NFP Resource handle - */ void nfp_resource_release(struct nfp_resource *res); -/** - * Return the CPP ID of a NFP Resource - * @param[in] res NFP Resource handle - * @return CPP ID of the NFP Resource - */ uint32_t nfp_resource_cpp_id(const struct nfp_resource *res); -/** - * Return the name of a NFP Resource - * @param[in] res NFP Resource handle - * @return Name of the NFP Resource - */ const char *nfp_resource_name(const struct nfp_resource *res); -/** - * Return the target address of a NFP Resource - * @param[in] res NFP Resource handle - * @return Address of the NFP Resource - */ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index d15a920752..0e6c0f9fe1 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -162,11 +162,14 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } -/* - * nfp_rtsym_count() - Get the number of RTSYM descriptors - * @rtbl: NFP RTsym table +/** + * Get the number of RTSYM descriptors + * + * @param rtbl + * NFP RTSYM table * - * Return: Number of RTSYM descriptors + * @return + * Number of RTSYM descriptors */ int nfp_rtsym_count(struct nfp_rtsym_table *rtbl) @@ -177,12 +180,16 @@ nfp_rtsym_count(struct nfp_rtsym_table *rtbl) return rtbl->num; } -/* - * nfp_rtsym_get() - Get the Nth RTSYM descriptor - * @rtbl: NFP RTsym table - * @idx: Index (0-based) of the RTSYM descriptor +/** + * Get the Nth RTSYM descriptor + * + * @param rtbl + * NFP RTSYM table + * @param idx + * Index (0-based) of the RTSYM descriptor * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_get(struct nfp_rtsym_table *rtbl, @@ -197,12 +204,16 @@ nfp_rtsym_get(struct nfp_rtsym_table *rtbl, return &rtbl->symtab[idx]; } -/* - * nfp_rtsym_lookup() - Return the RTSYM descriptor for a symbol name - * @rtbl: NFP RTsym table - * @name: Symbol name +/** + * Return the RTSYM descriptor for a symbol name + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name * - * Return: const pointer to a struct nfp_rtsym descriptor, or NULL + * @return + * Const pointer to a struct nfp_rtsym descriptor, or NULL */ const struct nfp_rtsym * nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, @@ -227,7 +238,8 @@ nfp_rtsym_size(const struct nfp_rtsym *sym) case NFP_RTSYM_TYPE_NONE: PMD_DRV_LOG(ERR, "The type of rtsym '%s' is NONE", sym->name); return 0; - case NFP_RTSYM_TYPE_OBJECT: /* Fall through */ + case NFP_RTSYM_TYPE_OBJECT: + /* FALLTHROUGH */ case NFP_RTSYM_TYPE_FUNCTION: return sym->size; case NFP_RTSYM_TYPE_ABS: @@ -327,17 +339,22 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } -/* - * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol - * @rtbl: NFP RTsym table - * @name: Symbol name - * @error: Pointer to error code (optional) +/** + * Read a simple unsigned scalar value from symbol * * Lookup a symbol, map, read it and return it's value. Value of the symbol * will be interpreted as a simple little-endian unsigned value. Symbol can * be 4 or 8 bytes in size. * - * Return: value read, on error sets the error and returns ~0ULL. + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param error + * Pointer to error code (optional) + * + * @return + * Value read, on error sets the error and returns ~0ULL. */ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index e7295258b3..ff1facbd17 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -31,12 +31,12 @@ * of "sram" symbols for backward compatibility, which are viewed as global. */ struct nfp_rtsym { - const char *name; - uint64_t addr; - uint64_t size; - int type; - int target; - int domain; + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + int type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ }; struct nfp_rtsym_table; diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 611848e233..540b242a43 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -767,7 +767,7 @@ nfp_encode_basic(uint64_t *addr, /* * Make sure we compare against isldN values by clearing the * LSB. This is what the silicon does. - **/ + */ isld[0] &= ~1; isld[1] &= ~1; -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 08/26] net/nfp: standard the blank character 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (6 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 07/26] net/nfp: standard the comment style Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 09/26] net/nfp: unify the guide line of header file Chaoyong He ` (17 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Use space character to align instead of TAB character. There should one blank line to split the block of logic, no more no less. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 18 +-- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 17 ++- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 - drivers/net/nfp/nfpcore/nfp_crc.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.c | 2 + drivers/net/nfp/nfpcore/nfp_hwinfo.h | 45 ++++--- drivers/net/nfp/nfpcore/nfp_mip.c | 9 +- drivers/net/nfp/nfpcore/nfp_mip.h | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 17 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 8 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 3 + drivers/net/nfp/nfpcore/nfp_nsp.h | 105 ++++++++-------- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 132 ++++++++++----------- drivers/net/nfp/nfpcore/nfp_resource.c | 18 +-- drivers/net/nfp/nfpcore/nfp_rtsym.c | 16 +-- drivers/net/nfp/nfpcore/nfp_rtsym.h | 1 + 18 files changed, 206 insertions(+), 195 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index 7750a0218e..efaa87c0e5 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -15,8 +15,8 @@ #define NFP_CPP_TARGET_PCIE 9 #define NFP_CPP_TARGET_ARM 10 #define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ #define NFP_CPP_TARGET_CT_XPB 14 #define NFP_CPP_TARGET_LOCAL_SCRATCH 15 #define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 82189e9910..92cae2557a 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -80,16 +80,17 @@ struct nfp_cpp_operations { * Serialized */ int (*area_acquire)(struct nfp_cpp_area *area); + /* * Release resources for a NFP CPP area * Serialized */ void (*area_release)(struct nfp_cpp_area *area); + /* * Return a void IO pointer to a NFP CPP area * NOTE: This is _not_ serialized */ - void *(*area_iomem)(struct nfp_cpp_area *area); /* @@ -280,7 +281,7 @@ void nfp_cpp_free(struct nfp_cpp *cpp); * @return * true if model is in the NFP6000 family, false otherwise. */ -#define NFP_CPP_MODEL_IS_6000(model) \ +#define NFP_CPP_MODEL_IS_6000(model) \ ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) @@ -290,11 +291,11 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * NFP Interface types - logical interface for this CPP connection 4 bits are * reserved for interface type. */ -#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 -#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 -#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 -#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 -#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 +#define NFP_CPP_INTERFACE_TYPE_INVALID 0x0 +#define NFP_CPP_INTERFACE_TYPE_PCI 0x1 +#define NFP_CPP_INTERFACE_TYPE_ARM 0x2 +#define NFP_CPP_INTERFACE_TYPE_RPC 0x3 +#define NFP_CPP_INTERFACE_TYPE_ILA 0x4 /** * Construct a 16-bit NFP Interface ID @@ -316,7 +317,7 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); * @return * Interface ID */ -#define NFP_CPP_INTERFACE(type, unit, channel) \ +#define NFP_CPP_INTERFACE(type, unit, channel) \ ((((type) & 0xf) << 12) | \ (((unit) & 0xf) << 8) | \ (((channel) & 0xff) << 0)) @@ -354,7 +355,6 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) - uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 7e94bfb611..28a6278497 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -37,7 +37,7 @@ #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" -#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) +#define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) @@ -58,7 +58,7 @@ * Minimal size of the PCIe cfg memory we depend on being mapped, * queue controller and DMA controller don't have to be covered. */ -#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ +#define NFP_PCI_MIN_MAP_SIZE 0x080000 /* 512K */ #define NFP_PCIE_P2C_FIXED_SIZE(bar) (1 << (bar)->bitsize) #define NFP_PCIE_P2C_BULK_SIZE(bar) (1 << (bar)->bitsize) @@ -93,7 +93,7 @@ struct nfp_bar { char *iomem; /**< mapped IO memory */ }; -#define BUSDEV_SZ 13 +#define BUSDEV_SZ 13 struct nfp_pcie_user { struct nfp_bar bar[NFP_BAR_MAX]; @@ -163,7 +163,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 16; } else { mask = ~(NFP_PCIE_P2C_BULK_SIZE(bar) - 1); @@ -171,7 +170,6 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); @@ -179,7 +177,6 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; offset &= mask; - bitsize = 40 - 21; } @@ -278,6 +275,7 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; bar->barcfg = 0; @@ -310,6 +308,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) start = NFP_BAR_MAX; end = NFP_BAR_MID; } + for (x = start; x > end; x--) { bar = &nfp->bar[x - 1]; if (bar->lock == 0) { @@ -317,6 +316,7 @@ nfp_alloc_bar(struct nfp_pcie_user *nfp) return bar; } } + return NULL; } @@ -346,7 +346,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } /* Generic CPP bus access interface. */ - struct nfp6000_area_priv { struct nfp_bar *bar; uint32_t bar_offset; @@ -443,6 +442,7 @@ static void nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + priv->bar->lock = 0; priv->bar = NULL; priv->iomem = NULL; @@ -478,7 +478,6 @@ nfp6000_area_read(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.read; - if (width <= 0) return -EINVAL; @@ -548,7 +547,6 @@ nfp6000_area_write(struct nfp_cpp_area *area, return -EFAULT; width = priv->width.write; - if (width <= 0) return -EINVAL; @@ -718,6 +716,7 @@ nfp6000_set_barsz(struct rte_pci_device *dev, i++; desc->barsz = i; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 0e8372576e..c46fd62e32 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -433,7 +433,6 @@ nfp_cpp_area_acquire(struct nfp_cpp_area *area) { if (area->cpp->op->area_acquire != NULL) { int err = area->cpp->op->area_acquire(area); - if (err < 0) { PMD_DRV_LOG(ERR, "Area acquire op failed"); return -1; @@ -862,7 +861,6 @@ nfp_cpp_alloc(struct rte_pci_device *dev, const struct nfp_cpp_operations *ops; ops = nfp_cpp_transport_operations(); - if (ops == NULL || ops->init == NULL) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_crc.c b/drivers/net/nfp/nfpcore/nfp_crc.c index 68f27f8c68..986c52711d 100644 --- a/drivers/net/nfp/nfpcore/nfp_crc.c +++ b/drivers/net/nfp/nfpcore/nfp_crc.c @@ -15,11 +15,13 @@ nfp_crc32_be_generic(uint32_t crc, uint32_t polynomial) { uint32_t i; + while (len--) { crc ^= *p++ << 24; for (i = 0; i < 8; i++) crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0); } + return crc; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index f5579ab60f..e33e660ea9 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -54,6 +54,7 @@ nfp_hwinfo_db_walk(struct nfp_hwinfo *hwinfo, return -EINVAL; } } + return 0; } @@ -178,6 +179,7 @@ nfp_hwinfo_read(struct nfp_cpp *cpp) free(db); return NULL; } + return db; } diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 424db8035d..37427bb6c8 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -8,33 +8,31 @@ #include <inttypes.h> -#define HWINFO_SIZE_MIN 0x100 +#define HWINFO_SIZE_MIN 0x100 /* * The Hardware Info Table defines the properties of the system. * * HWInfo v1 Table (fixed size) * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value - * table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * HWInfo v2 Table (variable size) * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding - * CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE * * If the HWInfo table is in the process of being updated, the low bit of * version will be set. @@ -47,17 +45,16 @@ * * All keys are guaranteed to be unique. * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value * ... * * HWInfo v2 Key/Value Table * ------------------------- * * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * * Unsorted. * * Note: Only the HwInfo v2 Table be supported now. @@ -65,7 +62,7 @@ #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) #define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) struct nfp_hwinfo { uint8_t start[0]; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 0892c99e96..7f06c24927 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -11,9 +11,9 @@ #include "nfp_mip.h" #include "nfp_nffw.h" -#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -#define NFP_MIP_VERSION rte_cpu_to_le_32(1) -#define NFP_MIP_MAX_OFFSET (256 * 1024) +#define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ +#define NFP_MIP_VERSION rte_cpu_to_le_32(1) +#define NFP_MIP_MAX_OFFSET (256 * 1024) struct nfp_mip { uint32_t signature; @@ -49,11 +49,13 @@ nfp_mip_try_read(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Failed to read MIP data"); return -EIO; } + if (mip->signature != NFP_MIP_SIGNATURE) { PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x", rte_le_to_cpu_32(mip->signature)); return -EINVAL; } + if (mip->mip_version != NFP_MIP_VERSION) { PMD_DRV_LOG(ERR, "Unsupported MIP version %d", rte_le_to_cpu_32(mip->mip_version)); @@ -82,6 +84,7 @@ nfp_mip_read_resource(struct nfp_cpp *cpp, goto exit_close_nffw; err = nfp_mip_try_read(cpp, cpp_id, addr, mip); + exit_close_nffw: nfp_nffw_info_close(nffw_info); return err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 980abc2517..16824a6769 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -18,4 +18,5 @@ void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); + #endif diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 404d4fa938..e97537b795 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -85,7 +85,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, { int err; uint32_t model = nfp_cpp_model(cpp); - uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ err = _nfp_cpp_mutex_validate(model, &target, address); if (err < 0) @@ -134,7 +134,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, uint32_t tmp; struct nfp_cpp_mutex *mutex; uint32_t model = nfp_cpp_model(cpp); - uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ /* Look for cached mutex */ for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { @@ -231,12 +231,15 @@ nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex) /* If err != -EBUSY, then the lock was damaged */ if (err < 0 && err != -EBUSY) return err; + if (time(NULL) >= warn_at) { PMD_DRV_LOG(WARNING, "Waiting for NFP mutex..."); warn_at = time(NULL) + 60; } + sched_yield(); } + return 0; } @@ -257,8 +260,8 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) uint32_t value; struct nfp_cpp *cpp = mutex->cpp; uint16_t interface = nfp_cpp_interface(cpp); - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ if (mutex->depth > 1) { mutex->depth--; @@ -314,9 +317,9 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) uint32_t tmp; uint32_t value; struct nfp_cpp *cpp = mutex->cpp; - uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ - uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ - uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ + uint32_t mur = NFP_CPP_ID(mutex->target, 3, 0); /* atomic_read */ + uint32_t muw = NFP_CPP_ID(mutex->target, 4, 0); /* atomic_write */ + uint32_t mus = NFP_CPP_ID(mutex->target, 5, 3); /* test_set_imm */ if (mutex->depth > 0) { if (mutex->depth == MUTEX_DEPTH_MAX) diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index 5f004e3b21..be80eeaa0e 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -61,10 +61,10 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 +#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) static int nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index a96ccea38b..ca3fc2fa59 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -290,6 +290,7 @@ nfp_nsp_command(struct nfp_nsp *state, err = nfp_cpp_readq(cpp, nsp_cpp, nsp_command, &ret_val); if (err < 0) return err; + ret_val = FIELD_GET(NSP_COMMAND_OPTION, ret_val); err = FIELD_GET(NSP_STATUS_RESULT, reg); @@ -354,6 +355,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, if (err < 0) return err; } + /* Zero out remaining part of the buffer */ if (out_buf != NULL && out_size > 0 && out_size > in_size) { memset(out_buf, 0, out_size - in_size); @@ -400,6 +402,7 @@ nfp_nsp_wait(struct nfp_nsp *state) break; } } + if (err != 0) PMD_DRV_LOG(ERR, "NSP failed to respond %d", err); diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 0fcb21e99c..ee58bf33b8 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -10,73 +10,72 @@ #include "nfp_nsp.h" #define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & \ - (~0ULL >> (64 - 1 - (h)))) + (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) #define __bf_shf(x) (__builtin_ffsll(x) - 1) -#define FIELD_GET(_mask, _reg) \ +#define FIELD_GET(_mask, _reg) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ })) -#define FIELD_FIT(_mask, _val) \ +#define FIELD_FIT(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ })) -#define FIELD_PREP(_mask, _val) \ +#define FIELD_PREP(_mask, _val) \ (__extension__ ({ \ typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ })) /* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_START RTE_BIT64(0) /* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) -#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER 0x18 -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) +#define NSP_CODE_MAJOR GENMASK(15, 12) +#define NSP_CODE_MINOR GENMASK(11, 0) enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ }; static const struct { @@ -123,13 +122,13 @@ nfp_nsp_has_mac_reinit(struct nfp_nsp *state) } enum nfp_eth_interface { - NFP_INTERFACE_NONE = 0, - NFP_INTERFACE_SFP = 1, - NFP_INTERFACE_SFPP = 10, - NFP_INTERFACE_SFP28 = 28, - NFP_INTERFACE_QSFP = 40, - NFP_INTERFACE_CXP = 100, - NFP_INTERFACE_QSFP28 = 112, + NFP_INTERFACE_NONE = 0, + NFP_INTERFACE_SFP = 1, + NFP_INTERFACE_SFPP = 10, + NFP_INTERFACE_SFP28 = 28, + NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_CXP = 100, + NFP_INTERFACE_QSFP28 = 112, }; enum nfp_eth_media { @@ -153,10 +152,10 @@ enum nfp_eth_fec { NFP_FEC_DISABLED_BIT, }; -#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) -#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) -#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) -#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) +#define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT) +#define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT) +#define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT) +#define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT) /* ETH table information */ struct nfp_eth_table { diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 3081e22dad..769ed54957 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -107,5 +107,6 @@ nfp_hwmon_read_sensor(struct nfp_cpp *cpp, default: return -EINVAL; } + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index cb090d2a47..d291552d03 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -11,70 +11,68 @@ #include "nfp_nsp.h" #include "nfp6000/nfp6000.h" -#define NSP_ETH_NBI_PORT_COUNT 24 -#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) -#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * \ - sizeof(union eth_table_entry)) - -#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) -#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) -#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) -#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) -#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) -#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) - -#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) - -#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) -#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) -#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) -#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) -#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) -#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) -#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) - -#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) -#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) -#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) -#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) -#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) -#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) -#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) -#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) +#define NSP_ETH_NBI_PORT_COUNT 24 +#define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) +#define NSP_ETH_TABLE_SIZE (NSP_ETH_MAX_COUNT * sizeof(union eth_table_entry)) + +#define NSP_ETH_PORT_LANES GENMASK_ULL(3, 0) +#define NSP_ETH_PORT_INDEX GENMASK_ULL(15, 8) +#define NSP_ETH_PORT_LABEL GENMASK_ULL(53, 48) +#define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) +#define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) +#define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) + +#define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) + +#define NSP_ETH_STATE_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_STATE_ENABLED RTE_BIT64(1) +#define NSP_ETH_STATE_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_STATE_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_STATE_RATE GENMASK_ULL(11, 8) +#define NSP_ETH_STATE_INTERFACE GENMASK_ULL(19, 12) +#define NSP_ETH_STATE_MEDIA GENMASK_ULL(21, 20) +#define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) +#define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) +#define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) + +#define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) +#define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) +#define NSP_ETH_CTRL_TX_ENABLED RTE_BIT64(2) +#define NSP_ETH_CTRL_RX_ENABLED RTE_BIT64(3) +#define NSP_ETH_CTRL_SET_RATE RTE_BIT64(4) +#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5) +#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6) +#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7) /* Which connector port. */ -#define PORT_TP 0x00 -#define PORT_AUI 0x01 -#define PORT_MII 0x02 -#define PORT_FIBRE 0x03 -#define PORT_BNC 0x04 -#define PORT_DA 0x05 -#define PORT_NONE 0xef -#define PORT_OTHER 0xff - -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 +#define PORT_TP 0x00 +#define PORT_AUI 0x01 +#define PORT_MII 0x02 +#define PORT_FIBRE 0x03 +#define PORT_BNC 0x04 +#define PORT_DA 0x05 +#define PORT_NONE 0xef +#define PORT_OTHER 0xff + +#define SPEED_10 10 +#define SPEED_100 100 +#define SPEED_1000 1000 +#define SPEED_2500 2500 +#define SPEED_5000 5000 +#define SPEED_10000 10000 +#define SPEED_14000 14000 +#define SPEED_20000 20000 +#define SPEED_25000 25000 +#define SPEED_40000 40000 +#define SPEED_50000 50000 +#define SPEED_56000 56000 +#define SPEED_100000 100000 enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW }; @@ -102,12 +100,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, 0, }, + { RATE_10M, SPEED_10, }, + { RATE_100M, SPEED_100, }, + { RATE_1G, SPEED_1000, }, + { RATE_10G, SPEED_10000, }, + { RATE_25G, SPEED_25000, }, }; static uint32_t @@ -212,10 +210,12 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) if (table->ports[i].label_port != table->ports[j].label_port) continue; + table->ports[i].port_lanes += table->ports[j].lanes; if (i == j) continue; + if (table->ports[i].label_subport == table->ports[j].label_subport) PMD_DRV_LOG(DEBUG, "Port %d subport %d is a duplicate", @@ -556,11 +556,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, return 0; } -#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ - (__extension__ ({ \ - typeof(mask) _x = (mask); \ +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \ + (__extension__ ({ \ + typeof(mask) _x = (mask); \ nfp_eth_set_bit_config(nsp, raw_idx, _x, __bf_shf(_x), \ - val, ctrl_bit); \ + val, ctrl_bit); \ })) /** diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index bdebf5c3aa..54bcc5f234 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -13,14 +13,14 @@ #include "nfp_resource.h" #include "nfp_crc.h" -#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL +#define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU +#define NFP_RESOURCE_TBL_BASE 0x8100000000ULL /* NFP Resource Table self-identifier */ -#define NFP_RESOURCE_TBL_NAME "nfp.res" -#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ +#define NFP_RESOURCE_TBL_NAME "nfp.res" +#define NFP_RESOURCE_TBL_KEY 0x00000000 /* Special key for entry 0 */ -#define NFP_RESOURCE_ENTRY_NAME_SZ 8 +#define NFP_RESOURCE_ENTRY_NAME_SZ 8 /* Resource table entry */ struct nfp_resource_entry { @@ -42,9 +42,9 @@ struct nfp_resource_entry { } region; }; -#define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ - sizeof(struct nfp_resource_entry)) +#define NFP_RESOURCE_TBL_SIZE 4096 +#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ + sizeof(struct nfp_resource_entry)) struct nfp_resource { char name[NFP_RESOURCE_ENTRY_NAME_SZ + 1]; @@ -75,6 +75,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, PMD_DRV_LOG(ERR, "Grabbing device lock not supported"); return -EOPNOTSUPP; } + key = nfp_crc32_posix(name_pad, NFP_RESOURCE_ENTRY_NAME_SZ); for (i = 0; i < NFP_RESOURCE_TBL_ENTRIES; i++) { @@ -96,6 +97,7 @@ nfp_cpp_resource_find(struct nfp_cpp *cpp, entry.region.cpp_token); res->addr = ((uint64_t)entry.region.page_offset) << 8; res->size = (uint64_t)entry.region.page_size << 8; + return 0; } diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 0e6c0f9fe1..37811ceaeb 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -17,18 +17,18 @@ #include "nfp6000/nfp6000.h" /* These need to match the linker */ -#define SYM_TGT_LMEM 0 -#define SYM_TGT_EMU_CACHE 0x17 +#define SYM_TGT_LMEM 0 +#define SYM_TGT_EMU_CACHE 0x17 struct nfp_rtsym_entry { - uint8_t type; - uint8_t target; - uint8_t island; - uint8_t addr_hi; + uint8_t type; + uint8_t target; + uint8_t island; + uint8_t addr_hi; uint32_t addr_lo; uint16_t name; - uint8_t menum; - uint8_t size_hi; + uint8_t menum; + uint8_t size_hi; uint32_t size_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index ff1facbd17..de1966f04b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -57,4 +57,5 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); + #endif -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 09/26] net/nfp: unify the guide line of header file 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (7 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 08/26] net/nfp: standard the blank character Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 10/26] net/nfp: rename some parameter and variable Chaoyong He ` (16 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Unify the guide line of header file, we choose '__FOO_BAR_H__' style. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 2 +- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 2 +- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_nffw.h | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_resource.h | 6 +++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 2 +- drivers/net/nfp/nfpcore/nfp_target.h | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 92cae2557a..ceb4d56a08 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -442,4 +442,4 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); -#endif /* !__NFP_CPP_H__ */ +#endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 37427bb6c8..543562779a 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -81,4 +81,4 @@ struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup); -#endif +#endif /* __NFP_HWINFO_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 16824a6769..371c635b97 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -19,4 +19,4 @@ void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, uint64_t *off); -#endif +#endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index e032b6cce7..f84be463c4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -75,4 +75,4 @@ struct nfp_nffw_info { struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); -#endif +#endif /* __NFP_NFFW_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index ee58bf33b8..7bf584dcd0 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NSP_NSP_H -#define NSP_NSP_H 1 +#ifndef __NSP_NSP_H__ +#define __NSP_NSP_H__ #include "nfp_cpp.h" #include "nfp_nsp.h" @@ -260,4 +260,4 @@ enum nfp_nsp_sensor_id { int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, uint32_t *val); -#endif +#endif /* __NSP_NSP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.h b/drivers/net/nfp/nfpcore/nfp_resource.h index 4236950caf..18196d273c 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.h +++ b/drivers/net/nfp/nfpcore/nfp_resource.h @@ -3,8 +3,8 @@ * All rights reserved. */ -#ifndef NFP_RESOURCE_H -#define NFP_RESOURCE_H +#ifndef __NFP_RESOURCE_H__ +#define __NFP_RESOURCE_H__ #include "nfp_cpp.h" @@ -33,4 +33,4 @@ uint64_t nfp_resource_address(const struct nfp_resource *res); uint64_t nfp_resource_size(const struct nfp_resource *res); -#endif /* NFP_RESOURCE_H */ +#endif /* __NFP_RESOURCE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index de1966f04b..fdde1eb75b 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -58,4 +58,4 @@ uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -#endif +#endif /* __NFP_RTSYM_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 195e599d31..2a2f083914 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -3,7 +3,7 @@ * All rights reserved. */ -#ifndef NFP_TARGET_H -#define NFP_TARGET_H +#ifndef __NFP_TARGET_H__ +#define __NFP_TARGET_H__ -#endif /* NFP_TARGET_H */ +#endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 10/26] net/nfp: rename some parameter and variable 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (8 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 09/26] net/nfp: unify the guide line of header file Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 11/26] net/nfp: refact the hwinfo module Chaoyong He ` (15 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Rename some parameter and variable to make the logic easier to understand. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 10 ++--- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 42 ++++++++--------- drivers/net/nfp/nfpcore/nfp_cppcore.c | 52 +++++++++++----------- drivers/net/nfp/nfpcore/nfp_mip.h | 2 +- drivers/net/nfp/nfpcore/nfp_mutex.c | 6 +-- drivers/net/nfp/nfpcore/nfp_nffw.c | 20 ++++----- drivers/net/nfp/nfpcore/nfp_nffw.h | 4 +- drivers/net/nfp/nfpcore/nfp_nsp.h | 8 ++-- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 20 ++++----- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index ceb4d56a08..be7ae1d919 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -247,7 +247,7 @@ void *nfp_cpp_priv(struct nfp_cpp *cpp); void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area); -uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); +uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, @@ -381,10 +381,10 @@ uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr, uint32_t size, struct nfp_cpp_area **area); int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *buffer, size_t length); + void *address, size_t length); int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *buffer, size_t length); + const void *address, size_t length); void *nfp_cpp_area_iomem(struct nfp_cpp_area *area); @@ -393,10 +393,10 @@ struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area); const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area); int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, void *kernel_vaddr, size_t length); + uint64_t address, void *buf, size_t length); int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id, - uint64_t address, const void *kernel_vaddr, size_t length); + uint64_t address, const void *buf, size_t length); int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset, uint32_t *value); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 28a6278497..db15411eb2 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -118,9 +118,9 @@ static int nfp_compute_bar(const struct nfp_bar *bar, uint32_t *bar_config, uint64_t *bar_base, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -129,7 +129,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (tgt >= 16) + if (target >= 16) return -EINVAL; switch (width) { @@ -149,15 +149,15 @@ nfp_compute_bar(const struct nfp_bar *bar, return -EINVAL; } - if (act != NFP_CPP_ACTION_RW && act != 0) { + if (action != NFP_CPP_ACTION_RW && action != 0) { /* Fixed CPP mapping with specific action */ mask = ~(NFP_PCIE_P2C_FIXED_SIZE(bar) - 1); newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(act); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(action); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -170,8 +170,8 @@ nfp_compute_bar(const struct nfp_bar *bar, /* Bulk mapping */ newcfg |= NFP_PCIE_BAR_PCIE2CPP_MAPTYPE (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(tgt); - newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(tok); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(target); + newcfg |= NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(token); if ((offset & mask) != ((offset + size - 1) & mask)) return -EINVAL; @@ -221,9 +221,9 @@ nfp_bar_write(struct nfp_pcie_user *nfp, static int nfp_reconfigure_bar(struct nfp_pcie_user *nfp, struct nfp_bar *bar, - int tgt, - int act, - int tok, + int target, + int action, + int token, uint64_t offset, size_t size, int width) @@ -232,8 +232,8 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, uint32_t newcfg; uint64_t newbase; - err = nfp_compute_bar(bar, &newcfg, &newbase, tgt, act, tok, offset, - size, width); + err = nfp_compute_bar(bar, &newcfg, &newbase, target, action, + token, offset, size, width); if (err != 0) return err; @@ -457,15 +457,15 @@ nfp6000_area_iomem(struct nfp_cpp_area *area) static int nfp6000_area_read(struct nfp_cpp_area *area, - void *kernel_vaddr, + void *address, uint32_t offset, size_t length) { size_t n; int width; bool is_64; - uint32_t *wrptr32 = kernel_vaddr; - uint64_t *wrptr64 = kernel_vaddr; + uint32_t *wrptr32 = address; + uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; const volatile uint32_t *rdptr32; const volatile uint64_t *rdptr64; @@ -526,7 +526,7 @@ nfp6000_area_read(struct nfp_cpp_area *area, static int nfp6000_area_write(struct nfp_cpp_area *area, - const void *kernel_vaddr, + const void *address, uint32_t offset, size_t length) { @@ -536,8 +536,8 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; - const uint32_t *rdptr32 = kernel_vaddr; - const uint64_t *rdptr64 = kernel_vaddr; + const uint32_t *rdptr32 = address; + const uint64_t *rdptr64 = address; priv = nfp_cpp_area_priv(area); wrptr64 = (uint64_t *)(priv->iomem + offset); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index c46fd62e32..7173b4d8a5 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -90,7 +90,7 @@ nfp_cpp_model(struct nfp_cpp *cpp) if (cpp == NULL) return NFP_CPP_MODEL_INVALID; - err = __nfp_cpp_model_autodetect(cpp, &model); + err = nfp_cpp_model_autodetect(cpp, &model); if (err < 0) return err; @@ -484,7 +484,7 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -498,13 +498,13 @@ nfp_cpp_area_iomem(struct nfp_cpp_area *area) int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset, - void *kernel_vaddr, + void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_read(area, kernel_vaddr, offset, length); + return area->cpp->op->area_read(area, address, offset, length); } /** @@ -514,7 +514,7 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, * CPP area handle * @param offset * Offset into CPP area - * @param kernel_vaddr + * @param address * Address to put data into * @param length * Number of bytes to read @@ -528,13 +528,13 @@ nfp_cpp_area_read(struct nfp_cpp_area *area, int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset, - const void *kernel_vaddr, + const void *address, size_t length) { if ((offset + length) > area->size) return -EFAULT; - return area->cpp->op->area_write(area, kernel_vaddr, offset, length); + return area->cpp->op->area_write(area, address, offset, length); } /* @@ -880,14 +880,14 @@ nfp_cpp_alloc(struct rte_pci_device *dev, } if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpbaddr; - size_t tgt; + uint32_t xpb_addr; + size_t target; - for (tgt = 0; tgt < RTE_DIM(cpp->imb_cat_table); tgt++) { + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + (tgt * 4); - err = nfp_xpb_readl(cpp, xpbaddr, - (uint32_t *)&cpp->imb_cat_table[tgt]); + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, + (uint32_t *)&cpp->imb_cat_table[target]); if (err < 0) { free(cpp); return NULL; @@ -950,9 +950,9 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer for result * @param length * Number of bytes to read @@ -963,20 +963,20 @@ nfp_cpp_from_device_name(struct rte_pci_device *dev, int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - void *kernel_vaddr, + uint64_t offset, + void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); return -1; } - err = nfp_cpp_area_read(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_read(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -989,9 +989,9 @@ nfp_cpp_read(struct nfp_cpp *cpp, * CPP handle * @param destination * CPP id - * @param address + * @param offset * Offset into CPP target - * @param kernel_vaddr + * @param address * Buffer to read from * @param length * Number of bytes to write @@ -1002,20 +1002,20 @@ nfp_cpp_read(struct nfp_cpp *cpp, int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t destination, - uint64_t address, - const void *kernel_vaddr, + uint64_t offset, + const void *address, size_t length) { int err; struct nfp_cpp_area *area; - area = nfp_cpp_area_alloc_acquire(cpp, destination, address, length); + area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); return -1; } - err = nfp_cpp_area_write(area, 0, kernel_vaddr, length); + err = nfp_cpp_area_write(area, 0, address, length); nfp_cpp_area_release_free(area); return err; @@ -1026,7 +1026,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, * as those are model-specific */ uint32_t -__nfp_cpp_model_autodetect(struct nfp_cpp *cpp, +nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model) { int err; diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 371c635b97..7fa09ee575 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -17,6 +17,6 @@ const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off); + uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index e97537b795..82598be7a1 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -35,7 +35,7 @@ struct nfp_cpp_mutex { }; static int -_nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint32_t model, int *target, uint64_t address) { @@ -87,7 +87,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return err; @@ -152,7 +152,7 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, return NULL; } - err = _nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(model, &target, address); if (err < 0) return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index be80eeaa0e..df6292e909 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -31,11 +31,11 @@ nffw_res_flg_init_get(const struct nfp_nffw_info_data *res) return (res->flags[0] >> 0) & 1; } -/* loaded = loaded__mu_da__mip_off_hi<31:31> */ +/* loaded = loaded_mu_da_mip_off_hi<31:31> */ static uint32_t nffw_fwinfo_loaded_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 31) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 31) & 1; } /* mip_cppid = mip_cppid */ @@ -45,18 +45,18 @@ nffw_fwinfo_mip_cppid_get(const struct nffw_fwinfo *fi) return fi->mip_cppid; } -/* loaded = loaded__mu_da__mip_off_hi<8:8> */ +/* loaded = loaded_mu_da_mip_off_hi<8:8> */ static uint32_t nffw_fwinfo_mip_mu_da_get(const struct nffw_fwinfo *fi) { - return (fi->loaded__mu_da__mip_off_hi >> 8) & 1; + return (fi->loaded_mu_da_mip_off_hi >> 8) & 1; } -/* mip_offset = (loaded__mu_da__mip_off_hi<7:0> << 32) | mip_offset_lo */ +/* mip_offset = (loaded_mu_da_mip_off_hi<7:0> << 32) | mip_offset_lo */ static uint64_t nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) { - uint64_t mip_off_hi = fi->loaded__mu_da__mip_off_hi; + uint64_t mip_off_hi = fi->loaded_mu_da_mip_off_hi; return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } @@ -227,7 +227,7 @@ nfp_nffw_info_fwid_first(struct nfp_nffw_info *state) int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *off) + uint64_t *offset) { struct nffw_fwinfo *fwinfo; @@ -236,7 +236,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, return -EINVAL; *cpp_id = nffw_fwinfo_mip_cppid_get(fwinfo); - *off = nffw_fwinfo_mip_offset_get(fwinfo); + *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { int locality_off; @@ -248,8 +248,8 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, if (locality_off < 0) return locality_off; - *off &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); - *off |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; + *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); + *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; } return 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index f84be463c4..52e25c090a 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -38,11 +38,11 @@ /* nfp.nffw meinfo */ struct nffw_meinfo { - uint32_t ctxmask__fwid__meid; + uint32_t ctxmask_fwid_meid; }; struct nffw_fwinfo { - uint32_t loaded__mu_da__mip_off_hi; + uint32_t loaded_mu_da_mip_off_hi; uint32_t mip_cppid; /* 0 means no MIP */ uint32_t mip_offset_lo; }; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 7bf584dcd0..705574b900 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -231,9 +231,9 @@ struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx); int nfp_eth_config_commit_end(struct nfp_nsp *nsp); void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp); -int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); -int __nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); -int __nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); +int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode); +int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed); +int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes); /* NSP static information */ struct nfp_nsp_identify { @@ -248,7 +248,7 @@ struct nfp_nsp_identify { uint64_t sensor_mask; /**< Mask of present sensors available on NIC */ }; -struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp); +struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp); enum nfp_nsp_sensor_id { NFP_SENSOR_CHIP_TEMPERATURE, diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index 769ed54957..f656f200f4 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -24,7 +24,7 @@ struct nsp_identify { }; struct nfp_nsp_identify * -__nfp_nsp_identify(struct nfp_nsp *nsp) +nfp_nsp_identify(struct nfp_nsp *nsp) { int ret; struct nsp_identify *ni; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index d291552d03..32c1838a40 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -242,7 +242,7 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) } static struct nfp_eth_table * -__nfp_eth_read_ports(struct nfp_nsp *nsp) +nfp_eth_read_ports_real(struct nfp_nsp *nsp) { int ret; uint32_t i; @@ -335,7 +335,7 @@ nfp_eth_read_ports(struct nfp_cpp *cpp) if (nsp == NULL) return NULL; - ret = __nfp_eth_read_ports(nsp); + ret = nfp_eth_read_ports_real(nsp); nfp_nsp_close(nsp); return ret; @@ -484,7 +484,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configed) + int configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -507,10 +507,10 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, /* Check if we are already in requested state */ reg = rte_le_to_cpu_64(entries[idx].state); - if (configed != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { + if (configured != (int)FIELD_GET(NSP_ETH_STATE_CONFIGURED, reg)) { reg = rte_le_to_cpu_64(entries[idx].control); reg &= ~NSP_ETH_CTRL_CONFIGURED; - reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configed); + reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); nfp_nsp_config_set_modified(nsp, 1); @@ -576,7 +576,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_aneg(struct nfp_nsp *nsp, +nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -596,7 +596,7 @@ __nfp_eth_set_aneg(struct nfp_nsp *nsp, * 0 or -ERRNO */ static int -__nfp_eth_set_fec(struct nfp_nsp *nsp, +nfp_eth_set_fec_real(struct nfp_nsp *nsp, enum nfp_eth_fec mode) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE, @@ -630,7 +630,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, if (nsp == NULL) return -EIO; - err = __nfp_eth_set_fec(nsp, mode); + err = nfp_eth_set_fec_real(nsp, mode); if (err != 0) { nfp_eth_config_cleanup_end(nsp); return err; @@ -654,7 +654,7 @@ nfp_eth_set_fec(struct nfp_cpp *cpp, * 0 or -ERRNO */ int -__nfp_eth_set_speed(struct nfp_nsp *nsp, +nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed) { enum nfp_eth_rate rate; @@ -682,7 +682,7 @@ __nfp_eth_set_speed(struct nfp_nsp *nsp, * 0 or -ERRNO */ int -__nfp_eth_set_split(struct nfp_nsp *nsp, +nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes) { return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 11/26] net/nfp: refact the hwinfo module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (9 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 10/26] net/nfp: rename some parameter and variable Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 12/26] net/nfp: refact the nffw module Chaoyong He ` (14 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Move the definition of data structure and macro into the implement file. Also remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 84 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 71 +---------------------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index e33e660ea9..c334202bd7 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -17,17 +17,82 @@ * (ie, in this example, ME 39 has been reserved by boardconfig.) */ -#include <stdio.h> -#include <time.h> +#include "nfp_hwinfo.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" -#include "nfp_hwinfo.h" -#include "nfp_crc.h" -static int +#define HWINFO_SIZE_MIN 0x100 + +/* + * The Hardware Info Table defines the properties of the system. + * + * HWInfo v1 Table (fixed size) + * + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * HWInfo v2 Table (variable size) + * + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * If the HWInfo table is in the process of being updated, the low bit of + * version will be set. + * + * HWInfo v1 Key/Value Table + * ------------------------- + * + * The key/value table is a set of offsets to ASCIIZ strings which have + * been strcmp(3) sorted (yes, please use bsearch(3) on the table). + * + * All keys are guaranteed to be unique. + * + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value + * ... + * + * HWInfo v2 Key/Value Table + * ------------------------- + * + * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' + * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. + */ + +#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) + +struct nfp_hwinfo { + uint8_t start[0]; + + uint32_t version; + uint32_t size; + + /* V2 specific fields */ + uint32_t limit; + uint32_t resv; + + char data[]; +}; + +static bool nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) { return hwinfo->version & NFP_HWINFO_VERSION_UPDATING; @@ -120,7 +185,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, goto exit_free; } - header = (void *)db; + header = (struct nfp_hwinfo *)db; if (nfp_hwinfo_is_updating(header)) goto exit_free; @@ -133,7 +198,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, /* NULL-terminate for safety */ db[*cpp_size] = '\0'; - return (void *)db; + return (struct nfp_hwinfo *)db; + exit_free: free(db); return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 543562779a..c812f10076 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -6,76 +6,9 @@ #ifndef __NFP_HWINFO_H__ #define __NFP_HWINFO_H__ -#include <inttypes.h> +#include "nfp_cpp.h" -#define HWINFO_SIZE_MIN 0x100 - -/* - * The Hardware Info Table defines the properties of the system. - * - * HWInfo v1 Table (fixed size) - * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * HWInfo v2 Table (variable size) - * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * If the HWInfo table is in the process of being updated, the low bit of - * version will be set. - * - * HWInfo v1 Key/Value Table - * ------------------------- - * - * The key/value table is a set of offsets to ASCIIZ strings which have - * been strcmp(3) sorted (yes, please use bsearch(3) on the table). - * - * All keys are guaranteed to be unique. - * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value - * ... - * - * HWInfo v2 Key/Value Table - * ------------------------- - * - * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * Unsorted. - * - * Note: Only the HwInfo v2 Table be supported now. - */ - -#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) - -struct nfp_hwinfo { - uint8_t start[0]; - - uint32_t version; - uint32_t size; - - /* v2 specific fields */ - uint32_t limit; - uint32_t resv; - - char data[]; -}; +struct nfp_hwinfo; struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 12/26] net/nfp: refact the nffw module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (10 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 11/26] net/nfp: refact the hwinfo module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 13/26] net/nfp: refact the mip module Chaoyong He ` (13 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Move the definition of data structure and macro into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.h | 4 +- drivers/net/nfp/nfpcore/nfp_nffw.c | 105 +++++++++++++++++++---------- drivers/net/nfp/nfpcore/nfp_nffw.h | 66 +----------------- 3 files changed, 72 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.h b/drivers/net/nfp/nfpcore/nfp_mip.h index 7fa09ee575..dbd9af31ed 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.h +++ b/drivers/net/nfp/nfpcore/nfp_mip.h @@ -6,7 +6,7 @@ #ifndef __NFP_MIP_H__ #define __NFP_MIP_H__ -#include "nfp_nffw.h" +#include "nfp_cpp.h" struct nfp_mip; @@ -16,7 +16,5 @@ void nfp_mip_close(struct nfp_mip *mip); const char *nfp_mip_name(const struct nfp_mip *mip); void nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); void nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size); -int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, - uint64_t *offset); #endif /* __NFP_MIP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.c b/drivers/net/nfp/nfpcore/nfp_nffw.c index df6292e909..2f07fcd6c1 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.c +++ b/drivers/net/nfp/nfpcore/nfp_nffw.c @@ -3,12 +3,76 @@ * All rights reserved. */ -#include "../nfp_logs.h" -#include "nfp_cpp.h" #include "nfp_nffw.h" + +#include "../nfp_logs.h" #include "nfp_mip.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" +#include "nfp6000/nfp6000.h" + +/* + * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. + * Lower IDs are reserved for target and loader IDs. + */ +#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ +#define NFFW_FWID_BASE 4 + +#define NFFW_FWID_ALL 255 + +/* + * NFFW_INFO_VERSION history: + * 0: This was never actually used (before versioning), but it refers to + * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later + * changed to 200. + * 1: First versioned struct, with + * FWINFO_CNT = 120 + * MEINFO_CNT = 120 + * 2: FWINFO_CNT = 200 + * MEINFO_CNT = 200 + */ +#define NFFW_INFO_VERSION_CURRENT 2 + +/* Enough for all current chip families */ +#define NFFW_MEINFO_CNT_V1 120 +#define NFFW_FWINFO_CNT_V1 120 +#define NFFW_MEINFO_CNT_V2 200 +#define NFFW_FWINFO_CNT_V2 200 + +/* nfp.nffw meinfo */ +struct nffw_meinfo { + uint32_t ctxmask_fwid_meid; +}; + +struct nffw_fwinfo { + uint32_t loaded_mu_da_mip_off_hi; + uint32_t mip_cppid; /**< 0 means no MIP */ + uint32_t mip_offset_lo; +}; + +struct nfp_nffw_info_v1 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; +}; + +struct nfp_nffw_info_v2 { + struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; + struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; +}; + +struct nfp_nffw_info_data { + uint32_t flags[2]; + union { + struct nfp_nffw_info_v1 v1; + struct nfp_nffw_info_v2 v2; + } info; +}; + +struct nfp_nffw_info { + struct nfp_cpp *cpp; + struct nfp_resource *res; + + struct nfp_nffw_info_data fwinf; +}; /* * flg_info_version = flags[0]<27:16> @@ -61,32 +125,6 @@ nffw_fwinfo_mip_offset_get(const struct nffw_fwinfo *fi) return (mip_off_hi & 0xFF) << 32 | fi->mip_offset_lo; } -#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x) (((_x) >> 13) & 0x7) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE RTE_BIT32(12) -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_32_BIT 0 -#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE_40_BIT RTE_BIT32(12) - -static int -nfp_mip_mu_locality_lsb(struct nfp_cpp *cpp) -{ - int err; - uint32_t mode; - uint32_t addr40; - uint32_t xpbaddr; - uint32_t imbcppat; - - /* Hardcoded XPB IMB Base, island 0 */ - xpbaddr = 0x000a0000 + NFP_CPP_TARGET_MU * 4; - err = nfp_xpb_readl(cpp, xpbaddr, &imbcppat); - if (err < 0) - return err; - - mode = NFP_IMB_TGTADDRESSMODECFG_MODE_of(imbcppat); - addr40 = !!(imbcppat & NFP_IMB_TGTADDRESSMODECFG_ADDRMODE); - - return nfp_cppat_mu_locality_lsb(mode, addr40); -} - static uint32_t nffw_res_fwinfos(struct nfp_nffw_info_data *fwinf, struct nffw_fwinfo **arr) @@ -239,14 +277,7 @@ nfp_nffw_info_mip_first(struct nfp_nffw_info *state, *offset = nffw_fwinfo_mip_offset_get(fwinfo); if (nffw_fwinfo_mip_mu_da_get(fwinfo) != 0) { - int locality_off; - - if (NFP_CPP_ID_TARGET_of(*cpp_id) != NFP_CPP_TARGET_MU) - return 0; - - locality_off = nfp_mip_mu_locality_lsb(state->cpp); - if (locality_off < 0) - return locality_off; + int locality_off = nfp_cpp_mu_locality_lsb(state->cpp); *offset &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off); *offset |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off; diff --git a/drivers/net/nfp/nfpcore/nfp_nffw.h b/drivers/net/nfp/nfpcore/nfp_nffw.h index 52e25c090a..fd46009d37 100644 --- a/drivers/net/nfp/nfpcore/nfp_nffw.h +++ b/drivers/net/nfp/nfpcore/nfp_nffw.h @@ -8,71 +8,11 @@ #include "nfp_cpp.h" -/* - * Init-CSR owner IDs for firmware map to firmware IDs which start at 4. - * Lower IDs are reserved for target and loader IDs. - */ -#define NFFW_FWID_EXT 3 /* For active MEs that we didn't load. */ -#define NFFW_FWID_BASE 4 - -#define NFFW_FWID_ALL 255 - -/* - * NFFW_INFO_VERSION history: - * 0: This was never actually used (before versioning), but it refers to - * the previous struct which had FWINFO_CNT = MEINFO_CNT = 120 that later - * changed to 200. - * 1: First versioned struct, with - * FWINFO_CNT = 120 - * MEINFO_CNT = 120 - * 2: FWINFO_CNT = 200 - * MEINFO_CNT = 200 - */ -#define NFFW_INFO_VERSION_CURRENT 2 - -/* Enough for all current chip families */ -#define NFFW_MEINFO_CNT_V1 120 -#define NFFW_FWINFO_CNT_V1 120 -#define NFFW_MEINFO_CNT_V2 200 -#define NFFW_FWINFO_CNT_V2 200 - -/* nfp.nffw meinfo */ -struct nffw_meinfo { - uint32_t ctxmask_fwid_meid; -}; - -struct nffw_fwinfo { - uint32_t loaded_mu_da_mip_off_hi; - uint32_t mip_cppid; /* 0 means no MIP */ - uint32_t mip_offset_lo; -}; - -struct nfp_nffw_info_v1 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V1]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V1]; -}; - -struct nfp_nffw_info_v2 { - struct nffw_meinfo meinfo[NFFW_MEINFO_CNT_V2]; - struct nffw_fwinfo fwinfo[NFFW_FWINFO_CNT_V2]; -}; - -struct nfp_nffw_info_data { - uint32_t flags[2]; - union { - struct nfp_nffw_info_v1 v1; - struct nfp_nffw_info_v2 v2; - } info; -}; - -struct nfp_nffw_info { - struct nfp_cpp *cpp; - struct nfp_resource *res; - - struct nfp_nffw_info_data fwinf; -}; +struct nfp_nffw_info; struct nfp_nffw_info *nfp_nffw_info_open(struct nfp_cpp *cpp); void nfp_nffw_info_close(struct nfp_nffw_info *state); +int nfp_nffw_info_mip_first(struct nfp_nffw_info *state, uint32_t *cpp_id, + uint64_t *offset); #endif /* __NFP_NFFW_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 13/26] net/nfp: refact the mip module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (11 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 12/26] net/nfp: refact the nffw module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 14/26] net/nfp: refact the rtsym module Chaoyong He ` (12 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_mip.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_mip.c b/drivers/net/nfp/nfpcore/nfp_mip.c index 7f06c24927..d5ada3687a 100644 --- a/drivers/net/nfp/nfpcore/nfp_mip.c +++ b/drivers/net/nfp/nfpcore/nfp_mip.c @@ -3,12 +3,11 @@ * All rights reserved. */ -#include <stdio.h> +#include "nfp_mip.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_mip.h" #include "nfp_nffw.h" #define NFP_MIP_SIGNATURE rte_cpu_to_le_32(0x0050494d) /* "MIP\0" */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 14/26] net/nfp: refact the rtsym module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (12 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 13/26] net/nfp: refact the mip module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 15/26] net/nfp: refact the resource module Chaoyong He ` (11 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include <stdio.h> +#include "nfp_rtsym.h" + #include <rte_byteorder.h> -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ 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); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 15/26] net/nfp: refact the resource module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (13 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 14/26] net/nfp: refact the rtsym module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 16/26] net/nfp: refact the target module Chaoyong He ` (10 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_resource.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 54bcc5f234..c0afdbfdd2 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -3,15 +3,11 @@ * All rights reserved. */ -#include <stdio.h> -#include <time.h> -#include <endian.h> +#include "nfp_resource.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" #include "nfp6000/nfp6000.h" -#include "nfp_resource.h" -#include "nfp_crc.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL @@ -43,7 +39,7 @@ struct nfp_resource_entry { }; #define NFP_RESOURCE_TBL_SIZE 4096 -#define NFP_RESOURCE_TBL_ENTRIES (int)(NFP_RESOURCE_TBL_SIZE / \ +#define NFP_RESOURCE_TBL_ENTRIES (NFP_RESOURCE_TBL_SIZE / \ sizeof(struct nfp_resource_entry)) struct nfp_resource { @@ -175,8 +171,7 @@ nfp_resource_acquire(struct nfp_cpp *cpp, NFP_RESOURCE_TBL_BASE, NFP_RESOURCE_TBL_KEY); if (dev_mutex == NULL) { PMD_DRV_LOG(ERR, "RESOURCE - CPP mutex alloc failed"); - free(res); - return NULL; + goto err_free; } wait.tv_sec = 0; @@ -188,13 +183,12 @@ nfp_resource_acquire(struct nfp_cpp *cpp, break; if (err != -EBUSY) { PMD_DRV_LOG(ERR, "RESOURCE - try acquire failed"); - goto err_free; + goto mutex_free; } if (count++ > 1000) { /* 1ms * 1000 = 1s */ PMD_DRV_LOG(ERR, "Error: resource %s timed out", name); - err = -EBUSY; - goto err_free; + goto mutex_free; } nanosleep(&wait, NULL); @@ -204,8 +198,9 @@ nfp_resource_acquire(struct nfp_cpp *cpp, return res; -err_free: +mutex_free: nfp_cpp_mutex_free(dev_mutex); +err_free: free(res); return NULL; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 16/26] net/nfp: refact the target module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (14 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 15/26] net/nfp: refact the resource module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 17/26] net/nfp: add a new header file Chaoyong He ` (9 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Move the function declaration into the header file, and sync some logic from kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000/nfp6000.h | 20 -------------------- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 1 + drivers/net/nfp/nfpcore/nfp_cppcore.c | 1 + drivers/net/nfp/nfpcore/nfp_mutex.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 - drivers/net/nfp/nfpcore/nfp_resource.c | 2 +- drivers/net/nfp/nfpcore/nfp_rtsym.c | 1 + drivers/net/nfp/nfpcore/nfp_target.c | 7 ++++--- drivers/net/nfp/nfpcore/nfp_target.h | 22 ++++++++++++++++++++++ 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h index efaa87c0e5..4c9ac017cc 100644 --- a/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h +++ b/drivers/net/nfp/nfpcore/nfp6000/nfp6000.h @@ -6,21 +6,6 @@ #ifndef __NFP_NFP6000_H__ #define __NFP_NFP6000_H__ -/* CPP Target IDs */ -#define NFP_CPP_TARGET_INVALID 0 -#define NFP_CPP_TARGET_NBI 1 -#define NFP_CPP_TARGET_QDR 2 -#define NFP_CPP_TARGET_ILA 6 -#define NFP_CPP_TARGET_MU 7 -#define NFP_CPP_TARGET_PCIE 9 -#define NFP_CPP_TARGET_ARM 10 -#define NFP_CPP_TARGET_CRYPTO 12 -#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ -#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ -#define NFP_CPP_TARGET_CT_XPB 14 -#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 -#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH - #define NFP_ISL_EMEM0 24 #define NFP_MU_ADDR_ACCESS_TYPE_MASK 3ULL @@ -52,9 +37,4 @@ nfp_cppat_mu_locality_lsb(int mode, int addr40) } } -int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); -int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, - uint32_t *cpp_target_id, uint64_t *cpp_target_address, - const uint32_t *imb_table); - #endif /* NFP_NFP6000_H */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index db15411eb2..310cc691cd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -34,6 +34,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "../nfp_logs.h" diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 7173b4d8a5..41485b6975 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -16,6 +16,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 82598be7a1..96ba60697c 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -9,7 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) #define MUTEX_UNLOCK(interface) (0 | 0x0000) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 32c1838a40..36bd49d659 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,7 +9,6 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp6000/nfp6000.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index c0afdbfdd2..539eb69680 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,7 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" +#include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU #define NFP_RESOURCE_TBL_BASE 0x8100000000ULL diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 2d4100dda2..022753f98a 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -14,6 +14,7 @@ #include "nfp_logs.h" #include "nfp_mip.h" +#include "nfp_target.h" #include "nfp6000/nfp6000.h" enum nfp_rtsym_type { diff --git a/drivers/net/nfp/nfpcore/nfp_target.c b/drivers/net/nfp/nfpcore/nfp_target.c index 540b242a43..ecb45f7928 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.c +++ b/drivers/net/nfp/nfpcore/nfp_target.c @@ -3,6 +3,8 @@ * All rights reserved. */ +#include "nfp_target.h" + #include "nfp_cpp.h" #include "nfp6000/nfp6000.h" @@ -315,8 +317,7 @@ nfp6000_mu(uint32_t cpp_id, } else if (island == 1 || (island >= 4 && island <= 7) || (island >= 12 && island <= 13) || - (island >= 32 && island <= 47) || - (island >= 48 && island <= 51)) { + (island >= 32 && island <= 51)) { pp = nfp6000_mu_ctm(cpp_id); } else { pp = -EINVAL; @@ -510,7 +511,7 @@ nfp_target_pushpull(uint32_t cpp_id, return nfp6000_cap_xpb(cpp_id); case NFP_CPP_TARGET_CLS: return nfp6000_cls(cpp_id); - case 0: + case NFP_CPP_TARGET_INVALID: return target_rw(cpp_id, P32, 4, 4); default: return -EINVAL; diff --git a/drivers/net/nfp/nfpcore/nfp_target.h b/drivers/net/nfp/nfpcore/nfp_target.h index 2a2f083914..47527b4040 100644 --- a/drivers/net/nfp/nfpcore/nfp_target.h +++ b/drivers/net/nfp/nfpcore/nfp_target.h @@ -6,4 +6,26 @@ #ifndef __NFP_TARGET_H__ #define __NFP_TARGET_H__ +#include <stdint.h> + +/* CPP Target IDs */ +#define NFP_CPP_TARGET_INVALID 0 +#define NFP_CPP_TARGET_NBI 1 +#define NFP_CPP_TARGET_QDR 2 +#define NFP_CPP_TARGET_ILA 6 +#define NFP_CPP_TARGET_MU 7 +#define NFP_CPP_TARGET_PCIE 9 +#define NFP_CPP_TARGET_ARM 10 +#define NFP_CPP_TARGET_CRYPTO 12 +#define NFP_CPP_TARGET_ISLAND_XPB 14 /* Shared with CAP */ +#define NFP_CPP_TARGET_ISLAND_CAP 14 /* Shared with XPB */ +#define NFP_CPP_TARGET_CT_XPB 14 +#define NFP_CPP_TARGET_LOCAL_SCRATCH 15 +#define NFP_CPP_TARGET_CLS NFP_CPP_TARGET_LOCAL_SCRATCH + +int nfp_target_pushpull(uint32_t cpp_id, uint64_t address); +int nfp_target_cpp(uint32_t cpp_island_id, uint64_t cpp_island_address, + uint32_t *cpp_target_id, uint64_t *cpp_target_address, + const uint32_t *imb_table); + #endif /* __NFP_TARGET_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 17/26] net/nfp: add a new header file 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (15 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 16/26] net/nfp: refact the target module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 18/26] net/nfp: refact the nsp module Chaoyong He ` (8 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Split out the macro which are not easily find a DPDK substitute into a new header file. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_nsp.c | 1 + drivers/net/nfp/nfpcore/nfp_nsp.h | 23 -------------- drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 1 + drivers/net/nfp/nfpcore/nfp_platform.h | 42 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_platform.h diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index ca3fc2fa59..0f67148907 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -13,6 +13,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #include "nfp_resource.h" int diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 705574b900..14986a9130 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -9,29 +9,6 @@ #include "nfp_cpp.h" #include "nfp_nsp.h" -#define GENMASK_ULL(h, l) \ - (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (64 - 1 - (h)))) - -#define __bf_shf(x) (__builtin_ffsll(x) - 1) - -#define FIELD_GET(_mask, _reg) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ - })) - -#define FIELD_FIT(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ - })) - -#define FIELD_PREP(_mask, _val) \ - (__extension__ ({ \ - typeof(_mask) _x = (_mask); \ - ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ - })) - /* Offsets relative to the CSR base */ #define NSP_STATUS 0x00 #define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index 36bd49d659..eb30d8e779 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -9,6 +9,7 @@ #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" +#include "nfp_platform.h" #define NSP_ETH_NBI_PORT_COUNT 24 #define NSP_ETH_MAX_COUNT (2 * NSP_ETH_NBI_PORT_COUNT) diff --git a/drivers/net/nfp/nfpcore/nfp_platform.h b/drivers/net/nfp/nfpcore/nfp_platform.h new file mode 100644 index 0000000000..fcac6b05ff --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_platform.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_PLATFORM_H__ +#define __NFP_PLATFORM_H__ + +#include <stdint.h> + +#define DMA_BIT_MASK(n) ((1ULL << (n)) - 1) + +#define BITS_PER_LONG (__SIZEOF_LONG__ * 8) +#define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8) + +#define GENMASK(h, l) \ + ((~0UL << (l)) & (~0UL >> (BITS_PER_LONG - (h) - 1))) + +#define GENMASK_ULL(h, l) \ + ((~0ULL << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - (h) - 1))) + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define FIELD_GET(_mask, _reg) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + (typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \ + })) + +#define FIELD_FIT(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + !((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \ + })) + +#define FIELD_PREP(_mask, _val) \ + (__extension__ ({ \ + typeof(_mask) _x = (_mask); \ + ((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \ + })) + +#endif /* __NFP_PLATFORM_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 18/26] net/nfp: refact the nsp module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (16 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 17/26] net/nfp: add a new header file Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 19/26] net/nfp: refact the mutex module Chaoyong He ` (7 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Move the definition of data structure into the implement file. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 2 +- drivers/net/nfp/nfpcore/nfp_nsp.c | 390 +++++++++++++++++++------ drivers/net/nfp/nfpcore/nfp_nsp.h | 140 ++++----- drivers/net/nfp/nfpcore/nfp_nsp_cmds.c | 4 - drivers/net/nfp/nfpcore/nfp_nsp_eth.c | 79 ++--- 5 files changed, 398 insertions(+), 217 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index e3ff3d8087..efb47c5d56 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -661,7 +661,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev) static int nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) { - struct nfp_cpp *cpp = nsp->cpp; + struct nfp_cpp *cpp = nfp_nsp_cpp(nsp); void *fw_buf; char fw_name[125]; char serial[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 0f67148907..5b804f6174 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -3,20 +3,127 @@ * All rights reserved. */ -#define NFP_SUBSYS "nfp_nsp" - -#include <stdio.h> -#include <time.h> +#include "nfp_nsp.h" #include <rte_common.h> -#include "nfp_cpp.h" #include "nfp_logs.h" -#include "nfp_nsp.h" #include "nfp_platform.h" #include "nfp_resource.h" -int +/* Offsets relative to the CSR base */ +#define NSP_STATUS 0x00 +#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) +#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) +#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) +#define NSP_STATUS_CODE GENMASK_ULL(31, 16) +#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) +#define NSP_STATUS_BUSY RTE_BIT64(0) + +#define NSP_COMMAND 0x08 +#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) +#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) +#define NSP_COMMAND_DMA_BUF RTE_BIT64(1) +#define NSP_COMMAND_START RTE_BIT64(0) + +/* CPP address to retrieve the data from */ +#define NSP_BUFFER 0x10 +#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER 0x18 +#define NSP_DFLT_BUFFER_CPP GENMASK_ULL(63, 40) +#define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) + +#define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) +#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) + +#define NSP_MAGIC 0xab10 +#define NSP_MAJOR 0 +#define NSP_MINOR 8 + +#define NSP_CODE_MAJOR GENMASK_ULL(15, 12) +#define NSP_CODE_MINOR GENMASK_ULL(11, 0) + +#define NFP_FW_LOAD_RET_MAJOR GENMASK_ULL(15, 8) +#define NFP_FW_LOAD_RET_MINOR GENMASK_ULL(23, 16) + +enum nfp_nsp_cmd { + SPCODE_NOOP = 0, /* No operation */ + SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ + SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ + SPCODE_PHY_INIT = 3, /* Initialize the PHY */ + SPCODE_MAC_INIT = 4, /* Initialize the MAC */ + SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ + SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ + SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ + SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ + SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */ + SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ + SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ + SPCODE_FW_STORED = 16, /* If no FW loaded, load flash app FW */ + SPCODE_HWINFO_LOOKUP = 17, /* Lookup HWinfo with overwrites etc. */ + SPCODE_HWINFO_SET = 18, /* Set HWinfo entry */ + SPCODE_FW_LOADED = 19, /* Is application firmware loaded */ + SPCODE_VERSIONS = 21, /* Report FW versions */ + SPCODE_READ_SFF_EEPROM = 22, /* Read module EEPROM */ + SPCODE_READ_MEDIA = 23, /* Get the supported/advertised media for a port */ +}; + +static const struct { + uint32_t code; + const char *msg; +} nsp_errors[] = { + { 6010, "could not map to phy for port" }, + { 6011, "not an allowed rate/lanes for port" }, + { 6012, "not an allowed rate/lanes for port" }, + { 6013, "high/low error, change other port first" }, + { 6014, "config not found in flash" }, +}; + +struct nfp_nsp { + struct nfp_cpp *cpp; + struct nfp_resource *res; + struct { + uint16_t major; + uint16_t minor; + } ver; + + /** Eth table config state */ + bool modified; + uint32_t idx; + void *entries; +}; + +/* NFP command argument structure */ +struct nfp_nsp_command_arg { + uint16_t code; /**< NFP SP Command Code */ + bool dma; /**< @buf points to a host buffer, not NSP buffer */ + bool error_quiet; /**< Don't print command error/warning */ + uint32_t timeout_sec; /**< Timeout value to wait for completion in seconds */ + uint32_t option; /**< NSP Command Argument */ + uint64_t buf; /**< NSP Buffer Address */ + /** Callback for interpreting option if error occurred */ + void (*error_cb)(struct nfp_nsp *state, uint32_t ret_val); +}; + +/* NFP command with buffer argument structure */ +struct nfp_nsp_command_buf_arg { + struct nfp_nsp_command_arg arg; /**< NFP command argument structure */ + const void *in_buf; /**< Buffer with data for input */ + void *out_buf; /**< Buffer for output data */ + uint32_t in_size; /**< Size of @in_buf */ + uint32_t out_size; /**< Size of @out_buf */ +}; + +struct nfp_cpp * +nfp_nsp_cpp(struct nfp_nsp *state) +{ + return state->cpp; +} + +bool nfp_nsp_config_modified(struct nfp_nsp *state) { return state->modified; @@ -24,7 +131,7 @@ nfp_nsp_config_modified(struct nfp_nsp *state) void nfp_nsp_config_set_modified(struct nfp_nsp *state, - int modified) + bool modified) { state->modified = modified; } @@ -66,7 +173,7 @@ nfp_nsp_print_extended_error(uint32_t ret_val) return; for (i = 0; i < RTE_DIM(nsp_errors); i++) - if (ret_val == (uint32_t)nsp_errors[i].code) + if (ret_val == nsp_errors[i].code) PMD_DRV_LOG(ERR, "err msg: %s", nsp_errors[i].msg); } @@ -222,11 +329,8 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, * - -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete */ static int -nfp_nsp_command(struct nfp_nsp *state, - uint16_t code, - uint32_t option, - uint32_t buff_cpp, - uint64_t buff_addr) +nfp_nsp_command_real(struct nfp_nsp *state, + const struct nfp_nsp_command_arg *arg) { int err; uint64_t reg; @@ -250,22 +354,14 @@ nfp_nsp_command(struct nfp_nsp *state, return err; } - if (!FIELD_FIT(NSP_BUFFER_CPP, buff_cpp >> 8) || - !FIELD_FIT(NSP_BUFFER_ADDRESS, buff_addr)) { - PMD_DRV_LOG(ERR, "Host buffer out of reach %08x %" PRIx64, - buff_cpp, buff_addr); - return -EINVAL; - } - - err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, - FIELD_PREP(NSP_BUFFER_CPP, buff_cpp >> 8) | - FIELD_PREP(NSP_BUFFER_ADDRESS, buff_addr)); + err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_buffer, arg->buf); if (err < 0) return err; err = nfp_cpp_writeq(cpp, nsp_cpp, nsp_command, - FIELD_PREP(NSP_COMMAND_OPTION, option) | - FIELD_PREP(NSP_COMMAND_CODE, code) | + FIELD_PREP(NSP_COMMAND_OPTION, arg->option) | + FIELD_PREP(NSP_COMMAND_CODE, arg->code) | + FIELD_PREP(NSP_COMMAND_DMA_BUF, arg->dma) | FIELD_PREP(NSP_COMMAND_START, 1)); if (err < 0) return err; @@ -275,7 +371,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_COMMAND_START, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to start", - err, code); + err, arg->code); return err; } @@ -284,7 +380,7 @@ nfp_nsp_command(struct nfp_nsp *state, NSP_STATUS_BUSY, 0); if (err != 0) { PMD_DRV_LOG(ERR, "Error %d waiting for code %#04x to complete", - err, code); + err, arg->code); return err; } @@ -296,84 +392,85 @@ nfp_nsp_command(struct nfp_nsp *state, err = FIELD_GET(NSP_STATUS_RESULT, reg); if (err != 0) { - PMD_DRV_LOG(ERR, "Result (error) code set: %d (%d) command: %d", - -err, (int)ret_val, code); - nfp_nsp_print_extended_error(ret_val); + if (!arg->error_quiet) + PMD_DRV_LOG(WARNING, "Result (error) code set: %d (%d) command: %d", + -err, (int)ret_val, arg->code); + + if (arg->error_cb != 0) + arg->error_cb(state, ret_val); + else + nfp_nsp_print_extended_error(ret_val); + return -err; } return ret_val; } -#define SZ_1M 0x00100000 +static int +nfp_nsp_command(struct nfp_nsp *state, + uint16_t code) +{ + const struct nfp_nsp_command_arg arg = { + .code = code, + }; + + return nfp_nsp_command_real(state, &arg); +} static int -nfp_nsp_command_buf(struct nfp_nsp *nsp, - uint16_t code, uint32_t option, - const void *in_buf, - unsigned int in_size, - void *out_buf, - unsigned int out_size) +nfp_nsp_command_buf_def(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) { int err; int ret; uint64_t reg; - size_t max_size; uint32_t cpp_id; uint64_t cpp_buf; struct nfp_cpp *cpp = nsp->cpp; - if (nsp->ver.minor < 13) { - PMD_DRV_LOG(ERR, "NSP: Code 0x%04x with buffer not supported ABI %hu.%hu)", - code, nsp->ver.major, nsp->ver.minor); - return -EOPNOTSUPP; - } - - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), - nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, - ®); - if (err < 0) - return err; - - max_size = RTE_MAX(in_size, out_size); - if (FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M < max_size) { - PMD_DRV_LOG(ERR, "NSP: default buffer too small for command 0x%04x (%llu < %zu)", - code, FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M, max_size); - return -EINVAL; - } - err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER, ®); if (err < 0) return err; - cpp_id = FIELD_GET(NSP_BUFFER_CPP, reg) << 8; - cpp_buf = FIELD_GET(NSP_BUFFER_ADDRESS, reg); + cpp_id = FIELD_GET(NSP_DFLT_BUFFER_CPP, reg) << 8; + cpp_buf = FIELD_GET(NSP_DFLT_BUFFER_ADDRESS, reg); - if (in_buf != NULL && in_size > 0) { - err = nfp_cpp_write(cpp, cpp_id, cpp_buf, in_buf, in_size); + if (arg->in_buf != NULL && arg->in_size > 0) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf, + arg->in_buf, arg->in_size); if (err < 0) return err; } /* Zero out remaining part of the buffer */ - if (out_buf != NULL && out_size > 0 && out_size > in_size) { - memset(out_buf, 0, out_size - in_size); - err = nfp_cpp_write(cpp, cpp_id, cpp_buf + in_size, out_buf, - out_size - in_size); + if (arg->out_buf != NULL && arg->out_size > arg->in_size) { + err = nfp_cpp_write(cpp, cpp_id, cpp_buf + arg->in_size, + arg->out_buf, arg->out_size - arg->in_size); if (err < 0) return err; } - ret = nfp_nsp_command(nsp, code, option, cpp_id, cpp_buf); + if (!FIELD_FIT(NSP_BUFFER_CPP, cpp_id >> 8) || + !FIELD_FIT(NSP_BUFFER_ADDRESS, cpp_buf)) { + PMD_DRV_LOG(ERR, "Buffer out of reach %#08x %#016lx", + cpp_id, cpp_buf); + return -EINVAL; + } + + arg->arg.buf = FIELD_PREP(NSP_BUFFER_CPP, cpp_id >> 8) | + FIELD_PREP(NSP_BUFFER_ADDRESS, cpp_buf); + ret = nfp_nsp_command_real(nsp, &arg->arg); if (ret < 0) { PMD_DRV_LOG(ERR, "NSP command failed"); return ret; } - if (out_buf != NULL && out_size > 0) { - err = nfp_cpp_read(cpp, cpp_id, cpp_buf, out_buf, out_size); + if (arg->out_buf != NULL && arg->out_size > 0) { + err = nfp_cpp_read(cpp, cpp_id, cpp_buf, + arg->out_buf, arg->out_size); if (err < 0) return err; } @@ -381,6 +478,43 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, return ret; } +#define SZ_1M 0x00100000 +#define SZ_4K 0x00001000 + +static int +nfp_nsp_command_buf(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg) +{ + int err; + size_t size; + uint64_t reg; + size_t max_size; + struct nfp_cpp *cpp = nsp->cpp; + + if (nsp->ver.minor < 13) { + PMD_DRV_LOG(ERR, "NSP: Code %#04x with buffer not supported ABI %hu.%hu)", + arg->arg.code, nsp->ver.major, nsp->ver.minor); + return -EOPNOTSUPP; + } + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NSP_DFLT_BUFFER_CONFIG, + ®); + if (err < 0) + return err; + + max_size = RTE_MAX(arg->in_size, arg->out_size); + size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; + if (size < max_size) { + PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%zu < %zu)", + arg->arg.code, size, max_size); + return -EINVAL; + } + + return nfp_nsp_command_buf_def(nsp, arg); +} + int nfp_nsp_wait(struct nfp_nsp *state) { @@ -392,7 +526,7 @@ nfp_nsp_wait(struct nfp_nsp *state) wait.tv_nsec = 25000000; /* 25ms */ for (;;) { - err = nfp_nsp_command(state, SPCODE_NOOP, 0, 0, 0); + err = nfp_nsp_command(state, SPCODE_NOOP); if (err != -EAGAIN) break; @@ -413,13 +547,57 @@ nfp_nsp_wait(struct nfp_nsp *state) int nfp_nsp_device_soft_reset(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_SOFT_RESET, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_SOFT_RESET); } int nfp_nsp_mac_reinit(struct nfp_nsp *state) { - return nfp_nsp_command(state, SPCODE_MAC_INIT, 0, 0, 0); + return nfp_nsp_command(state, SPCODE_MAC_INIT); +} + +static void +nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, + uint32_t ret_val) +{ + uint32_t minor; + uint32_t major; + static const char * const major_msg[] = { + /* 0 */ "Firmware from driver loaded", + /* 1 */ "Firmware from flash loaded", + /* 2 */ "Firmware loading failure", + }; + static const char * const minor_msg[] = { + /* 0 */ "", + /* 1 */ "no named partition on flash", + /* 2 */ "error reading from flash", + /* 3 */ "can not deflate", + /* 4 */ "not a trusted file", + /* 5 */ "can not parse FW file", + /* 6 */ "MIP not found in FW file", + /* 7 */ "null firmware name in MIP", + /* 8 */ "FW version none", + /* 9 */ "FW build number none", + /* 10 */ "no FW selection policy HWInfo key found", + /* 11 */ "static FW selection policy", + /* 12 */ "FW version has precedence", + /* 13 */ "different FW application load requested", + /* 14 */ "development build", + }; + + major = FIELD_GET(NFP_FW_LOAD_RET_MAJOR, ret_val); + minor = FIELD_GET(NFP_FW_LOAD_RET_MINOR, ret_val); + + if (!nfp_nsp_has_stored_fw_load(state)) + return; + + if (major >= RTE_DIM(major_msg)) + PMD_DRV_LOG(INFO, "FW loading status: %x", ret_val); + else if (minor >= RTE_DIM(minor_msg)) + PMD_DRV_LOG(INFO, "%s, reason code: %d", major_msg[major], minor); + else + PMD_DRV_LOG(INFO, "%s%c %s", major_msg[major], + minor != 0 ? ',' : '.', minor_msg[minor]); } int @@ -427,8 +605,24 @@ nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_FW_LOAD, size, buf, size, - NULL, 0); + int ret; + struct nfp_nsp_command_buf_arg load_fw = { + { + .code = SPCODE_FW_LOAD, + .option = size, + .error_cb = nfp_nsp_load_fw_extended_msg, + }, + .in_buf = buf, + .in_size = size, + }; + + ret = nfp_nsp_command_buf(state, &load_fw); + if (ret < 0) + return ret; + + nfp_nsp_load_fw_extended_msg(state, ret); + + return 0; } int @@ -436,8 +630,16 @@ nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg eth_rescan = { + { + .code = SPCODE_ETH_RESCAN, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, ð_rescan); } int @@ -445,8 +647,16 @@ nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_ETH_CONTROL, size, buf, size, - NULL, 0); + struct nfp_nsp_command_buf_arg eth_ctrl = { + { + .code = SPCODE_ETH_CONTROL, + .option = size, + }, + .in_buf = buf, + .in_size = size, + }; + + return nfp_nsp_command_buf(state, ð_ctrl); } int @@ -454,8 +664,16 @@ nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_IDENTIFY, size, NULL, 0, - buf, size); + struct nfp_nsp_command_buf_arg identify = { + { + .code = SPCODE_NSP_IDENTIFY, + .option = size, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &identify); } int @@ -464,6 +682,14 @@ nfp_nsp_read_sensors(struct nfp_nsp *state, void *buf, size_t size) { - return nfp_nsp_command_buf(state, SPCODE_NSP_SENSORS, sensor_mask, NULL, - 0, buf, size); + struct nfp_nsp_command_buf_arg sensors = { + { + .code = SPCODE_NSP_SENSORS, + .option = sensor_mask, + }, + .out_buf = buf, + .out_size = size, + }; + + return nfp_nsp_command_buf(state, &sensors); } diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.h b/drivers/net/nfp/nfpcore/nfp_nsp.h index 14986a9130..fe52dffeb7 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.h +++ b/drivers/net/nfp/nfpcore/nfp_nsp.h @@ -7,78 +7,8 @@ #define __NSP_NSP_H__ #include "nfp_cpp.h" -#include "nfp_nsp.h" - -/* Offsets relative to the CSR base */ -#define NSP_STATUS 0x00 -#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48) -#define NSP_STATUS_MAJOR GENMASK_ULL(47, 44) -#define NSP_STATUS_MINOR GENMASK_ULL(43, 32) -#define NSP_STATUS_CODE GENMASK_ULL(31, 16) -#define NSP_STATUS_RESULT GENMASK_ULL(15, 8) -#define NSP_STATUS_BUSY RTE_BIT64(0) - -#define NSP_COMMAND 0x08 -#define NSP_COMMAND_OPTION GENMASK_ULL(63, 32) -#define NSP_COMMAND_CODE GENMASK_ULL(31, 16) -#define NSP_COMMAND_START RTE_BIT64(0) - -/* CPP address to retrieve the data from */ -#define NSP_BUFFER 0x10 -#define NSP_BUFFER_CPP GENMASK_ULL(63, 40) -#define NSP_BUFFER_PCIE GENMASK_ULL(39, 38) -#define NSP_BUFFER_ADDRESS GENMASK_ULL(37, 0) - -#define NSP_DFLT_BUFFER 0x18 - -#define NSP_DFLT_BUFFER_CONFIG 0x20 -#define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) - -#define NSP_MAGIC 0xab10 -#define NSP_MAJOR 0 -#define NSP_MINOR 8 - -#define NSP_CODE_MAJOR GENMASK(15, 12) -#define NSP_CODE_MINOR GENMASK(11, 0) - -enum nfp_nsp_cmd { - SPCODE_NOOP = 0, /* No operation */ - SPCODE_SOFT_RESET = 1, /* Soft reset the NFP */ - SPCODE_FW_DEFAULT = 2, /* Load default (UNDI) FW */ - SPCODE_PHY_INIT = 3, /* Initialize the PHY */ - SPCODE_MAC_INIT = 4, /* Initialize the MAC */ - SPCODE_PHY_RXADAPT = 5, /* Re-run PHY RX Adaptation */ - SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */ - SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */ - SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */ - SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */ - SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */ -}; - -static const struct { - int code; - const char *msg; -} nsp_errors[] = { - { 6010, "could not map to phy for port" }, - { 6011, "not an allowed rate/lanes for port" }, - { 6012, "not an allowed rate/lanes for port" }, - { 6013, "high/low error, change other port first" }, - { 6014, "config not found in flash" }, -}; -struct nfp_nsp { - struct nfp_cpp *cpp; - struct nfp_resource *res; - struct { - uint16_t major; - uint16_t minor; - } ver; - - /* Eth table config state */ - int modified; - unsigned int idx; - void *entries; -}; +struct nfp_nsp; struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp); void nfp_nsp_close(struct nfp_nsp *state); @@ -92,18 +22,61 @@ int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size); int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask, void *buf, size_t size); -static inline int +static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state) { return nfp_nsp_get_abi_ver_minor(state) > 20; } +static inline bool +nfp_nsp_has_stored_fw_load(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 23; +} + +static inline bool +nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 24; +} + +static inline bool +nfp_nsp_has_hwinfo_set(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_fw_loaded(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 25; +} + +static inline bool +nfp_nsp_has_versions(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 27; +} + +static inline bool +nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 28; +} + +static inline bool +nfp_nsp_has_read_media(struct nfp_nsp *state) +{ + return nfp_nsp_get_abi_ver_minor(state) > 33; +} + enum nfp_eth_interface { NFP_INTERFACE_NONE = 0, NFP_INTERFACE_SFP = 1, NFP_INTERFACE_SFPP = 10, NFP_INTERFACE_SFP28 = 28, NFP_INTERFACE_QSFP = 40, + NFP_INTERFACE_RJ45 = 45, NFP_INTERFACE_CXP = 100, NFP_INTERFACE_QSFP28 = 112, }; @@ -151,6 +124,7 @@ struct nfp_eth_table { enum nfp_eth_media media; /**< Media type of the @interface */ enum nfp_eth_fec fec; /**< Forward Error Correction mode */ + enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */ enum nfp_eth_aneg aneg; /**< Auto negotiation mode */ struct rte_ether_addr mac_addr; /**< Interface MAC address */ @@ -159,17 +133,18 @@ struct nfp_eth_table { /** Id of interface within port (for split ports) */ uint8_t label_subport; - int enabled; /**< Enable port */ - int tx_enabled; /**< Enable TX */ - int rx_enabled; /**< Enable RX */ + bool enabled; /**< Enable port */ + bool tx_enabled; /**< Enable TX */ + bool rx_enabled; /**< Enable RX */ + bool supp_aneg; /**< Support auto negotiation */ - int override_changed; /**< Media reconfig pending */ + bool override_changed; /**< Media reconfig pending */ uint8_t port_type; /**< One of %PORT_* */ /** Sum of lanes of all subports of this port */ uint32_t port_lanes; - int is_split; /**< Split port */ + bool is_split; /**< Split port */ uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */ } ports[]; /**< Table of ports */ @@ -177,8 +152,8 @@ struct nfp_eth_table { struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp); -int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, int enable); -int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, int configed); +int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable); +int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured); int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode); int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size); @@ -187,12 +162,13 @@ int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf, void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, uint32_t idx); void nfp_nsp_config_clear_state(struct nfp_nsp *state); -void nfp_nsp_config_set_modified(struct nfp_nsp *state, int modified); +void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified); void *nfp_nsp_config_entries(struct nfp_nsp *state); -int nfp_nsp_config_modified(struct nfp_nsp *state); +struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state); +bool nfp_nsp_config_modified(struct nfp_nsp *state); uint32_t nfp_nsp_config_idx(struct nfp_nsp *state); -static inline int +static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port) { return eth_port->fec_modes_supported != 0; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c index f656f200f4..46fa5467de 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c @@ -3,12 +3,8 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" -#include "nfp_nffw.h" struct nsp_identify { uint8_t version[40]; diff --git a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c index eb30d8e779..cc472907ca 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp_eth.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp_eth.c @@ -3,10 +3,6 @@ * All rights reserved. */ -#include <stdio.h> -#include <rte_common.h> -#include <rte_byteorder.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_nsp.h" #include "nfp_platform.h" @@ -21,6 +17,7 @@ #define NSP_ETH_PORT_PHYLABEL GENMASK_ULL(59, 54) #define NSP_ETH_PORT_FEC_SUPP_BASER RTE_BIT64(60) #define NSP_ETH_PORT_FEC_SUPP_RS RTE_BIT64(61) +#define NSP_ETH_PORT_SUPP_ANEG RTE_BIT64(63) #define NSP_ETH_PORT_LANES_MASK rte_cpu_to_le_64(NSP_ETH_PORT_LANES) @@ -34,6 +31,7 @@ #define NSP_ETH_STATE_OVRD_CHNG RTE_BIT64(22) #define NSP_ETH_STATE_ANEG GENMASK_ULL(25, 23) #define NSP_ETH_STATE_FEC GENMASK_ULL(27, 26) +#define NSP_ETH_STATE_ACT_FEC GENMASK_ULL(29, 28) #define NSP_ETH_CTRL_CONFIGURED RTE_BIT64(0) #define NSP_ETH_CTRL_ENABLED RTE_BIT64(1) @@ -54,26 +52,12 @@ #define PORT_NONE 0xef #define PORT_OTHER 0xff -#define SPEED_10 10 -#define SPEED_100 100 -#define SPEED_1000 1000 -#define SPEED_2500 2500 -#define SPEED_5000 5000 -#define SPEED_10000 10000 -#define SPEED_14000 14000 -#define SPEED_20000 20000 -#define SPEED_25000 25000 -#define SPEED_40000 40000 -#define SPEED_50000 50000 -#define SPEED_56000 56000 -#define SPEED_100000 100000 - enum nfp_eth_raw { NSP_ETH_RAW_PORT = 0, NSP_ETH_RAW_STATE, NSP_ETH_RAW_MAC, NSP_ETH_RAW_CONTROL, - NSP_ETH_NUM_RAW + NSP_ETH_NUM_RAW, }; enum nfp_eth_rate { @@ -100,12 +84,12 @@ static const struct { enum nfp_eth_rate rate; uint32_t speed; } nsp_eth_rate_tbl[] = { - { RATE_INVALID, 0, }, - { RATE_10M, SPEED_10, }, - { RATE_100M, SPEED_100, }, - { RATE_1G, SPEED_1000, }, - { RATE_10G, SPEED_10000, }, - { RATE_25G, SPEED_25000, }, + { RATE_INVALID, RTE_ETH_SPEED_NUM_NONE, }, + { RATE_10M, RTE_ETH_SPEED_NUM_10M, }, + { RATE_100M, RTE_ETH_SPEED_NUM_100M, }, + { RATE_1G, RTE_ETH_SPEED_NUM_1G, }, + { RATE_10G, RTE_ETH_SPEED_NUM_10G, }, + { RATE_25G, RTE_ETH_SPEED_NUM_25G, }, }; static uint32_t @@ -193,7 +177,14 @@ nfp_eth_port_translate(struct nfp_nsp *nsp, if (dst->fec_modes_supported != 0) dst->fec_modes_supported |= NFP_FEC_AUTO | NFP_FEC_DISABLED; - dst->fec = 1 << FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->fec = FIELD_GET(NSP_ETH_STATE_FEC, state); + dst->act_fec = dst->fec; + + if (nfp_nsp_get_abi_ver_minor(nsp) < 33) + return; + + dst->act_fec = FIELD_GET(NSP_ETH_STATE_ACT_FEC, state); + dst->supp_aneg = FIELD_GET(NSP_ETH_PORT_SUPP_ANEG, port); } static void @@ -222,7 +213,7 @@ nfp_eth_calc_port_geometry(struct nfp_eth_table *table) table->ports[i].label_port, table->ports[i].label_subport); - table->ports[i].is_split = 1; + table->ports[i].is_split = true; } } } @@ -233,6 +224,9 @@ nfp_eth_calc_port_type(struct nfp_eth_table_port *entry) if (entry->interface == NFP_INTERFACE_NONE) { entry->port_type = PORT_NONE; return; + } else if (entry->interface == NFP_INTERFACE_RJ45) { + entry->port_type = PORT_TP; + return; } if (entry->media == NFP_MEDIA_FIBRE) @@ -251,7 +245,6 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) uint32_t table_sz; struct nfp_eth_table *table; union eth_table_entry *entries; - const struct rte_ether_addr *mac; entries = malloc(NSP_ETH_TABLE_SIZE); if (entries == NULL) @@ -264,16 +257,9 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) goto err; } - /* - * The NFP3800 NIC support 8 ports, but only 2 ports are valid, - * the rest 6 ports mac are all 0, ensure we don't use these port - */ - for (i = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) + for (i = 0; i < NSP_ETH_MAX_COUNT; i++) + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) cnt++; - } /* * Some versions of flash will give us 0 instead of port count. For @@ -294,11 +280,8 @@ nfp_eth_read_ports_real(struct nfp_nsp *nsp) memset(table, 0, table_sz); table->count = cnt; for (i = 0, j = 0; i < NSP_ETH_MAX_COUNT; i++) { - mac = (const struct rte_ether_addr *)entries[i].mac_addr; - if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0 && - !rte_is_zero_ether_addr(mac)) - nfp_eth_port_translate(nsp, &entries[i], i, - &table->ports[j++]); + if ((entries[i].port & NSP_ETH_PORT_LANES_MASK) != 0) + nfp_eth_port_translate(nsp, &entries[i], i, &table->ports[j++]); } nfp_eth_calc_port_geometry(table); @@ -440,7 +423,7 @@ nfp_eth_config_commit_end(struct nfp_nsp *nsp) int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, - int enable) + bool enable) { uint64_t reg; struct nfp_nsp *nsp; @@ -448,7 +431,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, nsp = nfp_eth_config_start(cpp, idx); if (nsp == NULL) - return -1; + return -EIO; entries = nfp_nsp_config_entries(nsp); @@ -460,7 +443,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_ENABLED, enable); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -484,7 +467,7 @@ nfp_eth_set_mod_enable(struct nfp_cpp *cpp, int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, - int configured) + bool configured) { uint64_t reg; struct nfp_nsp *nsp; @@ -513,7 +496,7 @@ nfp_eth_set_configured(struct nfp_cpp *cpp, reg |= FIELD_PREP(NSP_ETH_CTRL_CONFIGURED, configured); entries[idx].control = rte_cpu_to_le_64(reg); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); } return nfp_eth_config_commit_end(nsp); @@ -551,7 +534,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, entries[idx].control |= rte_cpu_to_le_64(ctrl_bit); - nfp_nsp_config_set_modified(nsp, 1); + nfp_nsp_config_set_modified(nsp, true); return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 19/26] net/nfp: refact the mutex module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (17 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 18/26] net/nfp: refact the nsp module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 20/26] net/nfp: rename data field to sync with kernel driver Chaoyong He ` (6 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Add a header file to holds the API declarations of this module. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp_cpp.h | 16 -- drivers/net/nfp/nfpcore/nfp_mutex.c | 205 ++++++++++++++----------- drivers/net/nfp/nfpcore/nfp_mutex.h | 25 +++ drivers/net/nfp/nfpcore/nfp_resource.c | 1 + 4 files changed, 138 insertions(+), 109 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_mutex.h diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index be7ae1d919..42c4df5fdd 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -8,8 +8,6 @@ #include <ethdev_pci.h> -struct nfp_cpp_mutex; - /* NFP CPP handle */ struct nfp_cpp { uint32_t model; @@ -426,20 +424,6 @@ int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id, int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, uint64_t value); -int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, - uint64_t address, uint32_t key_id); - -void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); - -int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); - uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp); #endif /* __NFP_CPP_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.c b/drivers/net/nfp/nfpcore/nfp_mutex.c index 96ba60697c..3c10c7a090 100644 --- a/drivers/net/nfp/nfpcore/nfp_mutex.c +++ b/drivers/net/nfp/nfpcore/nfp_mutex.c @@ -3,21 +3,13 @@ * All rights reserved. */ -#include <malloc.h> -#include <time.h> +#include "nfp_mutex.h" + #include <sched.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" -#define MUTEX_LOCKED(interface) ((((uint32_t)(interface)) << 16) | 0x000f) -#define MUTEX_UNLOCK(interface) (0 | 0x0000) - -#define MUTEX_IS_LOCKED(value) (((value) & 0xffff) == 0x000f) -#define MUTEX_IS_UNLOCKED(value) (((value) & 0xffff) == 0x0000) -#define MUTEX_INTERFACE(value) (((value) >> 16) & 0xffff) - /* * If you need more than 65536 recursive locks, please * rethink your code. @@ -34,21 +26,51 @@ struct nfp_cpp_mutex { struct nfp_cpp_mutex *prev, *next; }; +static inline uint32_t +nfp_mutex_locked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x000f; +} + +static inline uint32_t +nfp_mutex_unlocked(uint16_t interface) +{ + return (uint32_t)interface << 16 | 0x0000; +} + +static inline uint16_t +nfp_mutex_owner(uint32_t val) +{ + return (val >> 16) & 0xffff; +} + +static inline bool +nfp_mutex_is_locked(uint32_t val) +{ + return (val & 0xffff) == 0x000f; +} + +static inline bool +nfp_mutex_is_unlocked(uint32_t val) +{ + return (val & 0xffff) == 0; +} + static int -nfp_cpp_mutex_validate(uint32_t model, +nfp_cpp_mutex_validate(uint16_t interface, int *target, uint64_t address) { + /* Not permitted on invalid interfaces */ + if (NFP_CPP_INTERFACE_TYPE_of(interface) == NFP_CPP_INTERFACE_TYPE_INVALID) + return -EINVAL; + /* Address must be 64-bit aligned */ if ((address & 7) != 0) return -EINVAL; - if (NFP_CPP_MODEL_IS_6000(model)) { - if (*target != NFP_CPP_TARGET_MU) - return -EINVAL; - } else { + if (*target != NFP_CPP_TARGET_MU) return -EINVAL; - } return 0; } @@ -84,10 +106,10 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, uint32_t key) { int err; - uint32_t model = nfp_cpp_model(cpp); uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + uint16_t interface = nfp_cpp_interface(cpp); - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return err; @@ -95,8 +117,7 @@ nfp_cpp_mutex_init(struct nfp_cpp *cpp, if (err < 0) return err; - err = nfp_cpp_writel(cpp, muw, address + 0, - MUTEX_LOCKED(nfp_cpp_interface(cpp))); + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface)); if (err < 0) return err; @@ -133,26 +154,10 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int err; uint32_t tmp; struct nfp_cpp_mutex *mutex; - uint32_t model = nfp_cpp_model(cpp); uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + uint16_t interface = nfp_cpp_interface(cpp); - /* Look for cached mutex */ - for (mutex = cpp->mutex_cache; mutex; mutex = mutex->next) { - if (mutex->target == target && mutex->address == address) - break; - } - - if (mutex) { - if (mutex->key == key) { - mutex->usage++; - return mutex; - } - - /* If the key doesn't match... */ - return NULL; - } - - err = nfp_cpp_mutex_validate(model, &target, address); + err = nfp_cpp_mutex_validate(interface, &target, address); if (err < 0) return NULL; @@ -172,16 +177,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, mutex->address = address; mutex->key = key; mutex->depth = 0; - mutex->usage = 1; - - /* Add mutex to the cache */ - if (cpp->mutex_cache) { - cpp->mutex_cache->prev = mutex; - mutex->next = cpp->mutex_cache; - cpp->mutex_cache = mutex; - } else { - cpp->mutex_cache = mutex; - } return mutex; } @@ -195,20 +190,6 @@ nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex) { - mutex->usage--; - if (mutex->usage > 0) - return; - - /* Remove mutex from the cache */ - if (mutex->next) - mutex->next->prev = mutex->prev; - if (mutex->prev) - mutex->prev->next = mutex->next; - - /* If mutex->cpp == NULL, something broke */ - if (mutex->cpp && mutex == mutex->cpp->mutex_cache) - mutex->cpp->mutex_cache = mutex->next; - free(mutex); } @@ -268,32 +249,28 @@ nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex) return 0; } - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); - if (err < 0) - goto exit; - err = nfp_cpp_readl(mutex->cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; - if (value != MUTEX_LOCKED(interface)) { - err = -EACCES; - goto exit; - } + err = nfp_cpp_readl(mutex->cpp, mur, mutex->address, &value); + if (err < 0) + return err; + + if (value != nfp_mutex_locked(interface)) + return -EACCES; - err = nfp_cpp_writel(cpp, muw, mutex->address, MUTEX_UNLOCK(interface)); + err = nfp_cpp_writel(cpp, muw, mutex->address, + nfp_mutex_unlocked(interface)); if (err < 0) - goto exit; + return err; mutex->depth = 0; -exit: - return err; + return 0; } /** @@ -332,19 +309,17 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) /* Verify that the lock marker is not damaged */ err = nfp_cpp_readl(cpp, mur, mutex->address + 4, &key); if (err < 0) - goto exit; + return err; - if (key != mutex->key) { - err = -EPERM; - goto exit; - } + if (key != mutex->key) + return -EPERM; /* * Compare against the unlocked state, and if true, * write the interface id into the top 16 bits, and * mark as locked. */ - value = MUTEX_LOCKED(nfp_cpp_interface(cpp)); + value = nfp_mutex_locked(nfp_cpp_interface(cpp)); /* * We use test_set_imm here, as it implies a read @@ -361,10 +336,10 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_readl(cpp, mus, mutex->address, &tmp); if (err < 0) - goto exit; + return err; /* Was it unlocked? */ - if (MUTEX_IS_UNLOCKED(tmp)) { + if (nfp_mutex_is_unlocked(tmp)) { /* * The read value can only be 0x....0000 in the unlocked state. * If there was another contending for this lock, then @@ -376,20 +351,64 @@ nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) */ err = nfp_cpp_writel(cpp, muw, mutex->address, value); if (err < 0) - goto exit; + return err; mutex->depth = 1; - goto exit; + return 0; } /* Already locked by us? Success! */ if (tmp == value) { mutex->depth = 1; - goto exit; + return 0; } - err = MUTEX_IS_LOCKED(tmp) ? -EBUSY : -EINVAL; + return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL; +} + +/** + * Release lock if held by local system. + * Extreme care is advised, call only when no local lock users can exist. + * + * @param cpp + * NFP CPP handle + * @param target + * NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU) + * @param address + * Offset into the address space of the NFP CPP target ID + * + * @return + * - (0) if the lock was OK + * - (1) if locked by us + * - (-errno) on invalid mutex + */ +int +nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, + int target, + uint64_t address) +{ + int err; + uint32_t tmp; + uint16_t interface = nfp_cpp_interface(cpp); + const uint32_t mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */ + const uint32_t muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */ + + err = nfp_cpp_mutex_validate(interface, &target, address); + if (err != 0) + return err; + + /* Check lock */ + err = nfp_cpp_readl(cpp, mur, address, &tmp); + if (err < 0) + return err; + + if (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface) + return 0; + + /* Bust the lock */ + err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface)); + if (err < 0) + return err; -exit: - return err; + return 1; } diff --git a/drivers/net/nfp/nfpcore/nfp_mutex.h b/drivers/net/nfp/nfpcore/nfp_mutex.h new file mode 100644 index 0000000000..a79490b4d6 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_mutex.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_MUTEX_H__ +#define __NFP_MUTEX_H__ + +#include "nfp_cpp.h" + +struct nfp_cpp_mutex; + +int nfp_cpp_mutex_init(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +struct nfp_cpp_mutex *nfp_cpp_mutex_alloc(struct nfp_cpp *cpp, int target, + uint64_t address, uint32_t key_id); + +void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); +int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target, uint64_t address); + +#endif /* __NFP_MUTEX_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_resource.c b/drivers/net/nfp/nfpcore/nfp_resource.c index 539eb69680..d59d2d6c1e 100644 --- a/drivers/net/nfp/nfpcore/nfp_resource.c +++ b/drivers/net/nfp/nfpcore/nfp_resource.c @@ -7,6 +7,7 @@ #include "nfp_crc.h" #include "nfp_logs.h" +#include "nfp_mutex.h" #include "nfp_target.h" #define NFP_RESOURCE_TBL_TARGET NFP_CPP_TARGET_MU -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 20/26] net/nfp: rename data field to sync with kernel driver 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (18 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 19/26] net/nfp: refact the mutex module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 21/26] net/nfp: add the dev module Chaoyong He ` (5 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Rename the data fields to sync with the logic in kernel driver. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 6 +++--- drivers/net/nfp/nfp_common.h | 4 ++-- drivers/net/nfp/nfp_ethdev.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index 77dab864f3..fead917599 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -224,7 +224,7 @@ nfp_flower_pf_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_DRV_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -360,8 +360,8 @@ nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type) start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ; - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; /* Set the current MTU to the maximum supported */ hw->mtu = hw->max_mtu; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 1ce51d44d4..86c4e10040 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -123,9 +123,9 @@ struct nfp_pf_dev { struct nfp_cpp *cpp; struct nfp_cpp_area *ctrl_area; - struct nfp_cpp_area *hwqueues_area; + struct nfp_cpp_area *qc_area; - uint8_t *hw_queues; + uint8_t *qc_bar; struct nfp_hwinfo *hwinfo; struct nfp_rtsym_table *sym_tbl; diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index efb47c5d56..899d4dd253 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -311,7 +311,7 @@ nfp_net_close(struct rte_eth_dev *dev) /* Now it is safe to free all PF resources */ PMD_INIT_LOG(INFO, "Freeing PF resources"); nfp_cpp_area_free(pf_dev->ctrl_area); - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); free(pf_dev->hwinfo); free(pf_dev->sym_tbl); nfp_cpp_free(pf_dev->cpp); @@ -593,8 +593,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); - hw->tx_bar = pf_dev->hw_queues + tx_bar_off; - hw->rx_bar = pf_dev->hw_queues + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_bar_off; + hw->rx_bar = pf_dev->qc_bar + rx_bar_off; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -995,16 +995,16 @@ nfp_pf_init(struct rte_pci_device *pci_dev) } cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); - pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, cpp_id, + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, addr, NFP_QCP_QUEUE_AREA_SZ, - &pf_dev->hwqueues_area); - if (pf_dev->hw_queues == NULL) { + &pf_dev->qc_area); + if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; goto pf_cleanup; } - PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues); + PMD_INIT_LOG(DEBUG, "qc_bar address: 0x%p", pf_dev->qc_bar); /* * PF initialization has been done at this point. Call app specific @@ -1041,7 +1041,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) return 0; hwqueues_cleanup: - nfp_cpp_area_free(pf_dev->hwqueues_area); + nfp_cpp_area_free(pf_dev->qc_area); pf_cleanup: rte_free(pf_dev); sym_tbl_cleanup: -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 21/26] net/nfp: add the dev module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (19 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 20/26] net/nfp: rename data field to sync with kernel driver Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 22/26] net/nfp: add header file for PCIe module Chaoyong He ` (4 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Add the nfp_dev module to simplify the logic. The data structure we import can gather and replace several macro which scatter everywhere. Which also make the logic of choose value for different devices unnecessary and so eliminate such logic. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/flower/nfp_flower.c | 11 ++- drivers/net/nfp/flower/nfp_flower.h | 3 +- .../net/nfp/flower/nfp_flower_representor.c | 6 +- drivers/net/nfp/meson.build | 1 + drivers/net/nfp/nfd3/nfp_nfd3_dp.c | 5 +- drivers/net/nfp/nfdk/nfp_nfdk_dp.c | 5 +- drivers/net/nfp/nfp_common.c | 50 ++---------- drivers/net/nfp/nfp_common.h | 48 +++-------- drivers/net/nfp/nfp_ethdev.c | 71 +++++++--------- drivers/net/nfp/nfp_ethdev_vf.c | 25 +++--- drivers/net/nfp/nfp_rxtx.c | 5 +- drivers/net/nfp/nfp_rxtx.h | 12 --- drivers/net/nfp/nfpcore/nfp_dev.c | 81 +++++++++++++++++++ drivers/net/nfp/nfpcore/nfp_dev.h | 44 ++++++++++ 14 files changed, 203 insertions(+), 164 deletions(-) create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.c create mode 100644 drivers/net/nfp/nfpcore/nfp_dev.h diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c index fead917599..bbcfa6e66a 100644 --- a/drivers/net/nfp/flower/nfp_flower.c +++ b/drivers/net/nfp/flower/nfp_flower.c @@ -503,7 +503,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_rx_ring", i, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + hw->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -558,7 +559,8 @@ nfp_flower_init_ctrl_vnic(struct nfp_net_hw *hw) * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(eth_dev, "ctrl_tx_ring", i, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + hw->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, numa_node); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); @@ -789,7 +791,8 @@ nfp_flower_nfd_func_register(struct nfp_app_fw_flower *app_fw_flower) } int -nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev) +nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev, + const struct nfp_dev_info *dev_info) { int ret; int err; @@ -858,6 +861,7 @@ nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev) pf_hw->ctrl_bar = pf_dev->ctrl_bar; pf_hw->pf_dev = pf_dev; pf_hw->cpp = pf_dev->cpp; + pf_hw->dev_info = dev_info; ret = nfp_flower_init_vnic_common(app_fw_flower->pf_hw, "pf_vnic"); if (ret != 0) { @@ -883,6 +887,7 @@ nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev) /* Now populate the ctrl vNIC */ ctrl_hw->pf_dev = pf_dev; ctrl_hw->cpp = pf_dev->cpp; + ctrl_hw->dev_info = dev_info; ret = nfp_flower_init_ctrl_vnic(app_fw_flower->ctrl_hw); if (ret != 0) { diff --git a/drivers/net/nfp/flower/nfp_flower.h b/drivers/net/nfp/flower/nfp_flower.h index 34092cd4b4..e8df8b1769 100644 --- a/drivers/net/nfp/flower/nfp_flower.h +++ b/drivers/net/nfp/flower/nfp_flower.h @@ -103,7 +103,8 @@ nfp_flower_support_decap_v2(const struct nfp_app_fw_flower *app_fw_flower) return app_fw_flower->ext_features & NFP_FL_FEATS_DECAP_V2; } -int nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev); +int nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev, + const struct nfp_dev_info *dev_info); int nfp_secondary_init_app_fw_flower(struct nfp_cpp *cpp); bool nfp_flower_pf_dispatch_pkts(struct nfp_net_hw *hw, struct rte_mbuf *mbuf, diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 5f94d20f1b..48c3b3f844 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -67,7 +67,8 @@ nfp_pf_repr_rx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, - sizeof(struct nfp_net_rx_desc) * NFP_NET_MAX_RX_DESC, + sizeof(struct nfp_net_rx_desc) * + hw->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating rx dma"); @@ -140,7 +141,8 @@ nfp_pf_repr_tx_queue_setup(struct rte_eth_dev *dev, * resizing in later calls to the queue setup function. */ tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, - sizeof(struct nfp_net_nfd3_tx_desc) * NFP_NET_MAX_TX_DESC, + sizeof(struct nfp_net_nfd3_tx_desc) * + hw->dev_info->max_qc_size, NFP_MEMZONE_ALIGN, socket_id); if (tz == NULL) { PMD_DRV_LOG(ERR, "Error allocating tx dma"); diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 93c708959c..580a478cd6 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -21,6 +21,7 @@ sources = files( 'nfpcore/nfp_rtsym.c', 'nfpcore/nfp_nsp_cmds.c', 'nfpcore/nfp_crc.c', + 'nfpcore/nfp_dev.c', 'nfpcore/nfp_mutex.c', 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', diff --git a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c index ee39686329..79e1e1041c 100644 --- a/drivers/net/nfp/nfd3/nfp_nfd3_dp.c +++ b/drivers/net/nfp/nfd3/nfp_nfd3_dp.c @@ -262,7 +262,6 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -276,9 +275,7 @@ nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfd3_tx_desc); diff --git a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c index f66802211f..48a74d109a 100644 --- a/drivers/net/nfp/nfdk/nfp_nfdk_dp.c +++ b/drivers/net/nfp/nfdk/nfp_nfdk_dp.c @@ -357,7 +357,6 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { - int ret; size_t size; uint32_t tx_desc_sz; uint16_t min_tx_desc; @@ -371,9 +370,7 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); /* Validating number of descriptors */ tx_desc_sz = nb_desc * sizeof(struct nfp_net_nfdk_tx_desc); diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c index 5092e5869d..160df27c94 100644 --- a/drivers/net/nfp/nfp_common.c +++ b/drivers/net/nfp/nfp_common.c @@ -1146,30 +1146,16 @@ nfp_net_xstats_reset(struct rte_eth_dev *dev) return nfp_net_stats_reset(dev); } -int +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc) { - *max_rx_desc = NFP_NET_MAX_RX_DESC; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_rx_desc = NFP3800_NET_MIN_RX_DESC; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_rx_desc = NFP_NET_MIN_RX_DESC; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_rx_desc = hw->dev_info->max_qc_size; + *min_rx_desc = hw->dev_info->min_qc_size; } -int +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc) @@ -1181,28 +1167,13 @@ nfp_net_tx_desc_limits(struct nfp_net_hw *hw, else tx_dpp = NFDK_TX_DESC_PER_SIMPLE_PKT; - *max_tx_desc = NFP_NET_MAX_TX_DESC / tx_dpp; - - switch (hw->device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP3800_VF_NIC: - *min_tx_desc = NFP3800_NET_MIN_TX_DESC / tx_dpp; - return 0; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - *min_tx_desc = NFP_NET_MIN_TX_DESC / tx_dpp; - return 0; - default: - PMD_DRV_LOG(ERR, "Unknown NFP device id."); - return -EINVAL; - } + *max_tx_desc = hw->dev_info->max_qc_size / tx_dpp; + *min_tx_desc = hw->dev_info->min_qc_size / tx_dpp; } int nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; uint16_t min_tx_desc; @@ -1211,13 +1182,8 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; - - ret = nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); + nfp_net_tx_desc_limits(hw, &min_tx_desc, &max_tx_desc); dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues; dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues; diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h index 86c4e10040..36ad4e1d32 100644 --- a/drivers/net/nfp/nfp_common.h +++ b/drivers/net/nfp/nfp_common.h @@ -7,16 +7,9 @@ #define _NFP_COMMON_H_ #include "nfp_ctrl.h" +#include "nfpcore/nfp_dev.h" #define NFP_NET_PMD_VERSION "0.1" -#define PCI_VENDOR_ID_NETRONOME 0x19ee -#define PCI_VENDOR_ID_CORIGINE 0x1da8 - -#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 -#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 -#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 -#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 -#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ /* Forward declaration */ struct nfp_net_adapter; @@ -28,7 +21,6 @@ struct nfp_net_adapter; #define NFP_NET_CRTL_BAR 0 #define NFP_NET_TX_BAR 2 #define NFP_NET_RX_BAR 2 -#define NFP_QCP_QUEUE_AREA_SZ 0x80000 /* Macros for accessing the Queue Controller Peripheral 'CSRs' */ #define NFP_QCP_QUEUE_OFF(_x) ((_x) * 0x800) @@ -39,17 +31,6 @@ struct nfp_net_adapter; #define NFP_QCP_QUEUE_STS_HI 0x000c #define NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask (0x3ffff) -#define NFP_PCIE_QCP_NFP3800_OFFSET 0x400000 -#define NFP_PCIE_QCP_NFP6000_OFFSET 0x80000 -#define NFP_PCIE_QUEUE_NFP3800_MASK 0x1ff -#define NFP_PCIE_QUEUE_NFP6000_MASK 0xff -#define NFP_PCIE_QCP_PF_OFFSET 0x0 -#define NFP_PCIE_QCP_VF_OFFSET 0x0 - -/* The offset of the queue controller queues in the PCIe Target */ -#define NFP_PCIE_QUEUE(_offset, _q, _mask) \ - ((_offset) + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & (_mask)))) - /* Interrupt definitions */ #define NFP_NET_IRQ_LSC_IDX 0 @@ -163,6 +144,9 @@ struct nfp_net_hw { uint32_t rx_offset; enum nfp_net_meta_format meta_format; + /** NFP ASIC params */ + const struct nfp_dev_info *dev_info; + /* Current values for control */ uint32_t ctrl; @@ -352,23 +336,11 @@ nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr) } static inline uint32_t -nfp_pci_queue(struct rte_pci_device *pdev, uint16_t queue) +nfp_qcp_queue_offset(const struct nfp_dev_info *dev_info, + uint16_t queue) { - switch (pdev->id.device_id) { - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - case PCI_DEVICE_ID_NFP3800_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - case PCI_DEVICE_ID_NFP6000_VF_NIC: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_VF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP6000_MASK); - default: - return NFP_PCIE_QUEUE(NFP_PCIE_QCP_PF_OFFSET, queue, - NFP_PCIE_QUEUE_NFP3800_MASK); - } + return dev_info->qc_addr_offset + NFP_QCP_QUEUE_ADDR_SZ * + (queue & dev_info->qc_idx_mask); } /* Prototypes for common NFP functions */ @@ -434,10 +406,10 @@ void nfp_net_close_rx_queue(struct rte_eth_dev *dev); void nfp_net_stop_tx_queue(struct rte_eth_dev *dev); void nfp_net_close_tx_queue(struct rte_eth_dev *dev); int nfp_net_set_vxlan_port(struct nfp_net_hw *hw, size_t idx, uint16_t port); -int nfp_net_rx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_rx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_rx_desc, uint16_t *max_rx_desc); -int nfp_net_tx_desc_limits(struct nfp_net_hw *hw, +void nfp_net_tx_desc_limits(struct nfp_net_hw *hw, uint16_t *min_tx_desc, uint16_t *max_tx_desc); int nfp_net_check_dma_mask(struct nfp_net_hw *hw, char *name); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 899d4dd253..8ddce1e5b2 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -496,9 +496,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev) struct nfp_app_fw_nic *app_fw_nic; struct nfp_net_hw *hw; struct rte_ether_addr *tmp_ether_addr; - uint64_t rx_bar_off = 0; - uint64_t tx_bar_off = 0; - uint32_t start_q; + uint64_t rx_base; + uint64_t tx_base; int port = 0; int err; @@ -576,25 +575,14 @@ nfp_net_init(struct rte_eth_dev *eth_dev) /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - return -ENODEV; - } + tx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + rx_base = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); - PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); + PMD_INIT_LOG(DEBUG, "tx_base: 0x%" PRIx64 "", tx_base); + PMD_INIT_LOG(DEBUG, "rx_base: 0x%" PRIx64 "", rx_base); - hw->tx_bar = pf_dev->qc_bar + tx_bar_off; - hw->rx_bar = pf_dev->qc_bar + rx_bar_off; + hw->tx_bar = pf_dev->qc_bar + tx_base * NFP_QCP_QUEUE_ADDR_SZ; + hw->rx_bar = pf_dev->qc_bar + rx_base * NFP_QCP_QUEUE_ADDR_SZ; eth_dev->data->dev_private = hw; PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p", @@ -761,7 +749,8 @@ nfp_fw_setup(struct rte_pci_device *dev, } static int -nfp_init_app_fw_nic(struct nfp_pf_dev *pf_dev) +nfp_init_app_fw_nic(struct nfp_pf_dev *pf_dev, + const struct nfp_dev_info *dev_info) { int i; int ret; @@ -849,6 +838,7 @@ nfp_init_app_fw_nic(struct nfp_pf_dev *pf_dev) /* Add this device to the PF's array of physical ports */ app_fw_nic->ports[i] = hw; + hw->dev_info = dev_info; hw->pf_dev = pf_dev; hw->cpp = pf_dev->cpp; hw->eth_dev = eth_dev; @@ -902,10 +892,17 @@ nfp_pf_init(struct rte_pci_device *pci_dev) char name[RTE_ETH_NAME_MAX_LEN]; struct nfp_rtsym_table *sym_tbl; struct nfp_eth_table *nfp_eth_table; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This @@ -978,26 +975,11 @@ nfp_pf_init(struct rte_pci_device *pci_dev) pf_dev->nfp_eth_table = nfp_eth_table; /* configure access to tx/rx vNIC BARs */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP3800_OFFSET, - 0, NFP_PCIE_QUEUE_NFP3800_MASK); - break; - case PCI_DEVICE_ID_NFP4000_PF_NIC: - case PCI_DEVICE_ID_NFP6000_PF_NIC: - addr = NFP_PCIE_QUEUE(NFP_PCIE_QCP_NFP6000_OFFSET, - 0, NFP_PCIE_QUEUE_NFP6000_MASK); - break; - default: - PMD_INIT_LOG(ERR, "nfp_net: no device ID matching"); - ret = -ENODEV; - goto pf_cleanup; - } - + addr = nfp_qcp_queue_offset(dev_info, 0); cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0); + pf_dev->qc_bar = nfp_cpp_map_area(pf_dev->cpp, cpp_id, - addr, NFP_QCP_QUEUE_AREA_SZ, - &pf_dev->qc_area); + addr, dev_info->qc_area_sz, &pf_dev->qc_area); if (pf_dev->qc_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc"); ret = -EIO; @@ -1013,7 +995,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) switch (pf_dev->app_fw_id) { case NFP_APP_FW_CORE_NIC: PMD_INIT_LOG(INFO, "Initializing coreNIC"); - ret = nfp_init_app_fw_nic(pf_dev); + ret = nfp_init_app_fw_nic(pf_dev, dev_info); if (ret != 0) { PMD_INIT_LOG(ERR, "Could not initialize coreNIC!"); goto hwqueues_cleanup; @@ -1021,7 +1003,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) break; case NFP_APP_FW_FLOWER_NIC: PMD_INIT_LOG(INFO, "Initializing Flower"); - ret = nfp_init_app_fw_flower(pf_dev); + ret = nfp_init_app_fw_flower(pf_dev, dev_info); if (ret != 0) { PMD_INIT_LOG(ERR, "Could not initialize Flower!"); goto hwqueues_cleanup; @@ -1111,10 +1093,17 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) struct nfp_cpp *cpp; enum nfp_app_fw_id app_fw_id; struct nfp_rtsym_table *sym_tbl; + const struct nfp_dev_info *dev_info; if (pci_dev == NULL) return -ENODEV; + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + /* * When device bound to UIO, the device could be used, by mistake, * by two DPDK apps, and the UIO driver does not avoid it. This diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c index eaf815d06d..1a02a857ea 100644 --- a/drivers/net/nfp/nfp_ethdev_vf.c +++ b/drivers/net/nfp/nfp_ethdev_vf.c @@ -268,12 +268,20 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev) uint32_t start_q; int port = 0; int err; + const struct nfp_dev_info *dev_info; PMD_INIT_FUNC_TRACE(); pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); + dev_info = nfp_dev_info_get(pci_dev->id.device_id); + if (dev_info == NULL) { + PMD_INIT_LOG(ERR, "Not supported device ID"); + return -ENODEV; + } + hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); + hw->dev_info = dev_info; hw->ctrl_bar = pci_dev->mem_resource[0].addr; if (hw->ctrl_bar == NULL) { @@ -305,19 +313,10 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev) } /* Work out where in the BAR the queues start. */ - switch (pci_dev->id.device_id) { - case PCI_DEVICE_ID_NFP3800_VF_NIC: - case PCI_DEVICE_ID_NFP6000_VF_NIC: - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); - tx_bar_off = nfp_pci_queue(pci_dev, start_q); - start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); - rx_bar_off = nfp_pci_queue(pci_dev, start_q); - break; - default: - PMD_DRV_LOG(ERR, "nfp_net: no device ID matching"); - err = -ENODEV; - goto dev_err_ctrl_map; - } + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ); + tx_bar_off = nfp_qcp_queue_offset(dev_info, start_q); + start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ); + rx_bar_off = nfp_qcp_queue_offset(dev_info, start_q); PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off); PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off); diff --git a/drivers/net/nfp/nfp_rxtx.c b/drivers/net/nfp/nfp_rxtx.c index f0c371ea2b..1b8bb3471d 100644 --- a/drivers/net/nfp/nfp_rxtx.c +++ b/drivers/net/nfp/nfp_rxtx.c @@ -677,7 +677,6 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp) { - int ret; uint16_t min_rx_desc; uint16_t max_rx_desc; const struct rte_memzone *tz; @@ -689,9 +688,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev, PMD_INIT_FUNC_TRACE(); - ret = nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); - if (ret != 0) - return ret; + nfp_net_rx_desc_limits(hw, &min_rx_desc, &max_rx_desc); /* Validating number of descriptors */ rx_desc_sz = nb_desc * sizeof(struct nfp_net_rx_desc); diff --git a/drivers/net/nfp/nfp_rxtx.h b/drivers/net/nfp/nfp_rxtx.h index 48e548b02d..6d1c8e4605 100644 --- a/drivers/net/nfp/nfp_rxtx.h +++ b/drivers/net/nfp/nfp_rxtx.h @@ -74,18 +74,6 @@ struct nfp_meta_parsed { } vlan[NFP_META_MAX_VLANS]; }; -/* - * The maximum number of descriptors is limited by design as - * DPDK uses uint16_t variables for these values - */ -#define NFP_NET_MAX_TX_DESC (32 * 1024) -#define NFP_NET_MIN_TX_DESC 256 -#define NFP3800_NET_MIN_TX_DESC 512 - -#define NFP_NET_MAX_RX_DESC (32 * 1024) -#define NFP_NET_MIN_RX_DESC 256 -#define NFP3800_NET_MIN_RX_DESC 512 - /* Descriptor alignment */ #define NFP_ALIGN_RING_DESC 128 diff --git a/drivers/net/nfp/nfpcore/nfp_dev.c b/drivers/net/nfp/nfpcore/nfp_dev.c new file mode 100644 index 0000000000..7799fa699a --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_dev.h" + +#include <rte_bitops.h> + +#include "nfp_platform.h" + +/* + * Note: The value of 'max_qc_size' is different from kernel driver, + * because DPDK use 'uint16_t' as the data type. + */ +const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { + [NFP_DEV_NFP3800] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0x400000, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP3800", + .pcie_cfg_expbar_offset = 0x0a00, + .qc_area_sz = 0x100000, + .pf_num_per_unit = 4, + }, + [NFP_DEV_NFP3800_VF] = { + .qc_idx_mask = GENMASK(8, 0), + .qc_addr_offset = 0, + .min_qc_size = 512, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, + [NFP_DEV_NFP6000] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0x80000, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + + .chip_names = "NFP4000/NFP6000", + .pcie_cfg_expbar_offset = 0x0400, + .qc_area_sz = 0x80000, + .pf_num_per_unit = 1, + }, + [NFP_DEV_NFP6000_VF] = { + .qc_idx_mask = GENMASK(7, 0), + .qc_addr_offset = 0, + .min_qc_size = 256, + .max_qc_size = RTE_BIT32(15), /**< 32K */ + }, +}; + +const struct nfp_dev_info * +nfp_dev_info_get(uint16_t device_id) +{ + enum nfp_dev_id id; + + switch (device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + id = NFP_DEV_NFP3800; + break; + case PCI_DEVICE_ID_NFP3800_VF_NIC: + id = NFP_DEV_NFP3800_VF; + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + id = NFP_DEV_NFP6000; + break; + case PCI_DEVICE_ID_NFP6000_VF_NIC: + id = NFP_DEV_NFP6000_VF; + break; + default: + id = NFP_DEV_CNT; + break; + } + + if (id >= NFP_DEV_CNT) + return NULL; + + return &nfp_dev_info[id]; +} diff --git a/drivers/net/nfp/nfpcore/nfp_dev.h b/drivers/net/nfp/nfpcore/nfp_dev.h new file mode 100644 index 0000000000..b0fffff619 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp_dev.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_DEV_H__ +#define __NFP_DEV_H__ + +#include <stdint.h> + +#define PCI_VENDOR_ID_NETRONOME 0x19ee +#define PCI_VENDOR_ID_CORIGINE 0x1da8 + +#define PCI_DEVICE_ID_NFP3800_PF_NIC 0x3800 +#define PCI_DEVICE_ID_NFP3800_VF_NIC 0x3803 +#define PCI_DEVICE_ID_NFP4000_PF_NIC 0x4000 +#define PCI_DEVICE_ID_NFP6000_PF_NIC 0x6000 +#define PCI_DEVICE_ID_NFP6000_VF_NIC 0x6003 /* Include NFP4000VF */ + +enum nfp_dev_id { + NFP_DEV_NFP3800, + NFP_DEV_NFP3800_VF, + NFP_DEV_NFP6000, + NFP_DEV_NFP6000_VF, + NFP_DEV_CNT, +}; + +struct nfp_dev_info { + /* Required fields */ + uint32_t qc_idx_mask; + uint32_t qc_addr_offset; + uint32_t min_qc_size; + uint32_t max_qc_size; + + /* PF-only fields */ + const char *chip_names; + uint32_t pcie_cfg_expbar_offset; + uint32_t qc_area_sz; + uint8_t pf_num_per_unit; +}; + +const struct nfp_dev_info *nfp_dev_info_get(uint16_t device_id); + +#endif /* __NFP_DEV_H__ */ -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 22/26] net/nfp: add header file for PCIe module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (20 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 21/26] net/nfp: add the dev module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 23/26] net/nfp: refact the cppcore module Chaoyong He ` (3 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Add a new header file for the PCIe module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/meson.build | 2 +- .../nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} | 2 ++ drivers/net/nfp/nfpcore/nfp6000_pcie.h | 13 +++++++++++++ drivers/net/nfp/nfpcore/nfp_cpp.h | 6 ------ drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) rename drivers/net/nfp/nfpcore/{nfp_cpp_pcie_ops.c => nfp6000_pcie.c} (99%) create mode 100644 drivers/net/nfp/nfpcore/nfp6000_pcie.h diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 580a478cd6..d422269c4b 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -12,7 +12,6 @@ sources = files( 'flower/nfp_flower_representor.c', 'nfd3/nfp_nfd3_dp.c', 'nfdk/nfp_nfdk_dp.c', - 'nfpcore/nfp_cpp_pcie_ops.c', 'nfpcore/nfp_nsp.c', 'nfpcore/nfp_cppcore.c', 'nfpcore/nfp_resource.c', @@ -26,6 +25,7 @@ sources = files( 'nfpcore/nfp_nsp_eth.c', 'nfpcore/nfp_hwinfo.c', 'nfpcore/nfp_target.c', + 'nfpcore/nfp6000_pcie.c', 'nfp_common.c', 'nfp_rxtx.c', 'nfp_cpp_bridge.c', diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c similarity index 99% rename from drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c rename to drivers/net/nfp/nfpcore/nfp6000_pcie.c index 310cc691cd..abee584f85 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -14,6 +14,8 @@ * The generic CPP bus abstraction builds upon this BAR interface. */ +#include "nfp6000_pcie.h" + #include <assert.h> #include <stdio.h> #include <stdlib.h> diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h new file mode 100644 index 0000000000..e126457d45 --- /dev/null +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Netronome Systems, Inc. + * All rights reserved. + */ + +#ifndef __NFP6000_PCIE_H__ +#define __NFP6000_PCIE_H__ + +#include "nfp_cpp.h" + +const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); + +#endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 42c4df5fdd..0df97552cb 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,12 +226,6 @@ NFP_CPP_ID_ISLAND_of(uint32_t id) return id & 0xff; } -/* - * This should be the only external function the transport - * module supplies - */ -const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); - void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 41485b6975..47dd2f2bca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -14,12 +14,12 @@ #include <rte_byteorder.h> #include <ethdev_pci.h> -#include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" #include "nfp_nffw.h" +#include "nfp6000_pcie.h" #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 23/26] net/nfp: refact the cppcore module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (21 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 22/26] net/nfp: add header file for PCIe module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 9:54 ` [PATCH v5 24/26] net/nfp: refact the PCIe module Chaoyong He ` (2 subsequent siblings) 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Modify the comment and standard the coding style. Move the definition of data structure into the implement file to make the API small. Also sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfp_cpp_bridge.c | 2 +- drivers/net/nfp/nfp_ethdev.c | 14 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 4 +- drivers/net/nfp/nfpcore/nfp_cpp.h | 40 ++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 186 ++++++++++++++++--------- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/drivers/net/nfp/nfp_cpp_bridge.c b/drivers/net/nfp/nfp_cpp_bridge.c index 88cd1aa572..a9998f3c08 100644 --- a/drivers/net/nfp/nfp_cpp_bridge.c +++ b/drivers/net/nfp/nfp_cpp_bridge.c @@ -344,7 +344,7 @@ nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp) return -EIO; } - tmp = cpp->interface; + tmp = nfp_cpp_interface(cpp); PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 8ddce1e5b2..04244c4e08 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -654,15 +654,23 @@ nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card) char fw_name[125]; char serial[40]; size_t fsize; + uint16_t interface; + uint32_t cpp_serial_len; + const uint8_t *cpp_serial; + + cpp_serial_len = nfp_cpp_serial(cpp, &cpp_serial); + if (cpp_serial_len != NFP_SERIAL_LEN) + return -ERANGE; + + interface = nfp_cpp_interface(cpp); /* Looking for firmware file in order of priority */ /* First try to find a firmware image specific for this device */ snprintf(serial, sizeof(serial), "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", - cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3], - cpp->serial[4], cpp->serial[5], cpp->interface >> 8, - cpp->interface & 0xff); + cpp_serial[0], cpp_serial[1], cpp_serial[2], cpp_serial[3], + cpp_serial[4], cpp_serial[5], interface >> 8, interface & 0xff); snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH, serial); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index abee584f85..45645e04f8 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -739,7 +739,7 @@ nfp6000_init(struct nfp_cpp *cpp, strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (rte_eal_process_type() == RTE_PROC_PRIMARY && - cpp->driver_lock_needed) { + nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) goto error; @@ -778,7 +778,7 @@ nfp6000_free(struct nfp_cpp *cpp) struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); nfp_disable_bars(desc); - if (cpp->driver_lock_needed) + if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); close(desc->device); free(desc); diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0df97552cb..34ed50ceca 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -9,38 +9,12 @@ #include <ethdev_pci.h> /* NFP CPP handle */ -struct nfp_cpp { - uint32_t model; - uint32_t interface; - uint8_t *serial; - int serial_len; - void *priv; - - /* Mutex cache */ - struct nfp_cpp_mutex *mutex_cache; - const struct nfp_cpp_operations *op; - - /* - * NFP-6xxx originating island IMB CPP Address Translation. CPP Target - * ID is index into array. Values are obtained at runtime from local - * island XPB CSRs. - */ - uint32_t imb_cat_table[16]; - - /* MU access type bit offset */ - uint32_t mu_locality_lsb; - - int driver_lock_needed; -}; +struct nfp_cpp; /* NFP CPP device area handle */ -struct nfp_cpp_area { - struct nfp_cpp *cpp; - char *name; - unsigned long long offset; - unsigned long size; - /* Here follows the 'priv' part of nfp_cpp_area. */ -}; +struct nfp_cpp_area; + +#define NFP_SERIAL_LEN 6 /* * NFP CPP operations structure @@ -230,7 +204,7 @@ void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model); void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface); -int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len); void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv); @@ -349,7 +323,9 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); -int nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); + +bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp); struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t address, size_t size); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 47dd2f2bca..bbf2eaa448 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -3,30 +3,56 @@ * All rights reserved. */ -#include <assert.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> - -#include <rte_byteorder.h> -#include <ethdev_pci.h> +#include "nfp_cpp.h" #include "nfp_logs.h" +#include "nfp_platform.h" #include "nfp_target.h" #include "nfp6000/nfp6000.h" #include "nfp6000/nfp_xpb.h" -#include "nfp_nffw.h" #include "nfp6000_pcie.h" +#define NFP_PL_DEVICE_PART_NFP6000 0x6200 #define NFP_PL_DEVICE_ID 0x00000004 #define NFP_PL_DEVICE_ID_MASK 0xff #define NFP_PL_DEVICE_PART_MASK 0xffff0000 #define NFP_PL_DEVICE_MODEL_MASK (NFP_PL_DEVICE_PART_MASK | \ NFP_PL_DEVICE_ID_MASK) +/* NFP CPP handle */ +struct nfp_cpp { + void *priv; /**< Private data of the low-level implementation */ + + uint32_t model; /**< Chip model */ + uint16_t interface; /**< Chip interface id */ + uint8_t serial[NFP_SERIAL_LEN]; /**< Chip serial number */ + + /** Low-level implementation ops */ + const struct nfp_cpp_operations *op; + + /* + * NFP-6xxx originating island IMB CPP Address Translation. CPP Target + * ID is index into array. Values are obtained at runtime from local + * island XPB CSRs. + */ + uint32_t imb_cat_table[16]; + + /**< MU access type bit offset */ + uint32_t mu_locality_lsb; + + bool driver_lock_needed; +}; + +/* NFP CPP device area handle */ +struct nfp_cpp_area { + struct nfp_cpp *cpp; + char *name; + uint64_t offset; + uint32_t size; + /* Here follows the 'priv' part of nfp_cpp_area. */ + /* Here follows the ASCII name, pointed by @name */ +}; + /** * Set the private data of the nfp_cpp instance * @@ -125,12 +151,13 @@ nfp_cpp_interface_set(struct nfp_cpp *cpp, * @return * Length of NFP serial number */ -int +uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial) { - *serial = cpp->serial; - return cpp->serial_len; + *serial = &cpp->serial[0]; + + return sizeof(cpp->serial); } /** @@ -143,22 +170,12 @@ nfp_cpp_serial(struct nfp_cpp *cpp, * @param serial_len * Length of the serial byte array */ -int +void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, size_t serial_len) { - if (cpp->serial_len) - free(cpp->serial); - - cpp->serial = malloc(serial_len); - if (cpp->serial == NULL) - return -1; - memcpy(cpp->serial, serial, serial_len); - cpp->serial_len = serial_len; - - return 0; } /** @@ -179,6 +196,21 @@ nfp_cpp_interface(struct nfp_cpp *cpp) return cpp->interface; } +/** + * Retrieve the driver need lock flag + * + * @param cpp + * NFP CPP handle + * + * @return + * The driver need lock flag + */ +bool +nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp) +{ + return cpp->driver_lock_needed; +} + /** * Get the privately allocated portion of a NFP CPP area handle * @@ -283,39 +315,40 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t size) { int err; + size_t name_len; + uint32_t target_id; + uint64_t target_addr; struct nfp_cpp_area *area; - uint64_t tmp64 = (uint64_t)address; if (cpp == NULL) return NULL; /* Remap from cpp_island to cpp_target */ - err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table); + err = nfp_target_cpp(dest, address, &target_id, &target_addr, + cpp->imb_cat_table); if (err < 0) return NULL; - address = tmp64; - if (name == NULL) - name = ""; + name = "(reserved)"; - area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + - strlen(name) + 1); + name_len = strlen(name) + 1; + area = calloc(1, sizeof(*area) + cpp->op->area_priv_size + name_len); if (area == NULL) return NULL; area->cpp = cpp; area->name = ((char *)area) + sizeof(*area) + cpp->op->area_priv_size; - memcpy(area->name, name, strlen(name) + 1); + memcpy(area->name, name, name_len); - err = cpp->op->area_init(area, dest, address, size); + err = cpp->op->area_init(area, target_id, target_addr, size); if (err < 0) { PMD_DRV_LOG(ERR, "Area init op failed"); free(area); return NULL; } - area->offset = address; + area->offset = target_addr; area->size = size; return area; @@ -555,26 +588,28 @@ nfp_xpb_to_cpp(struct nfp_cpp *cpp, * Ensure that non-local XPB accesses go out through the * global XPBM bus. */ - island = ((*xpb_addr) >> 24) & 0x3f; + island = (*xpb_addr >> 24) & 0x3f; if (island == 0) return xpb; - if (island == 1) { - /* - * Accesses to the ARM Island overlay uses Island 0 - * Global Bit - */ - (*xpb_addr) &= ~0x7f000000; - if (*xpb_addr < 0x60000) - *xpb_addr |= (1 << 30); - else - /* And only non-ARM interfaces use island id = 1 */ - if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != - NFP_CPP_INTERFACE_TYPE_ARM) - *xpb_addr |= (1 << 24); + if (island != 1) { + *xpb_addr |= (1 << 30); + return xpb; + } + + /* + * Accesses to the ARM Island overlay uses Island 0 + * Global Bit + */ + *xpb_addr &= ~0x7f000000; + if (*xpb_addr < 0x60000) { + *xpb_addr |= (1 << 30); } else { - (*xpb_addr) |= (1 << 30); + /* And only non-ARM interfaces use island id = 1 */ + if (NFP_CPP_INTERFACE_TYPE_of(nfp_cpp_interface(cpp)) != + NFP_CPP_INTERFACE_TYPE_ARM) + *xpb_addr |= (1 << 24); } return xpb; @@ -602,9 +637,12 @@ nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -629,7 +667,10 @@ nfp_cpp_area_writel(struct nfp_cpp_area *area, value = rte_cpu_to_le_32(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); - return (sz == sizeof(value)) ? 0 : -1; + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; + + return 0; } /** @@ -654,9 +695,12 @@ nfp_cpp_area_readq(struct nfp_cpp_area *area, uint64_t tmp = 0; sz = nfp_cpp_area_read(area, offset, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_64(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -681,8 +725,10 @@ nfp_cpp_area_writeq(struct nfp_cpp_area *area, value = rte_cpu_to_le_64(value); sz = nfp_cpp_area_write(area, offset, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -710,9 +756,12 @@ nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t tmp; sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; + *value = rte_le_to_cpu_32(tmp); - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -740,8 +789,10 @@ nfp_cpp_writel(struct nfp_cpp *cpp, value = rte_cpu_to_le_32(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -770,8 +821,10 @@ nfp_cpp_readq(struct nfp_cpp *cpp, sz = nfp_cpp_read(cpp, cpp_id, address, &tmp, sizeof(tmp)); *value = rte_le_to_cpu_64(tmp); + if (sz != sizeof(tmp)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(*value)) ? 0 : -1; + return 0; } /** @@ -799,8 +852,10 @@ nfp_cpp_writeq(struct nfp_cpp *cpp, value = rte_cpu_to_le_64(value); sz = nfp_cpp_write(cpp, cpp_id, address, &value, sizeof(value)); + if (sz != sizeof(value)) + return sz < 0 ? sz : -EIO; - return (sz == sizeof(value)) ? 0 : -1; + return 0; } /** @@ -918,9 +973,6 @@ nfp_cpp_free(struct nfp_cpp *cpp) if (cpp->op != NULL && cpp->op->free != NULL) cpp->op->free(cpp); - if (cpp->serial_len != 0) - free(cpp->serial); - free(cpp); } @@ -974,7 +1026,7 @@ nfp_cpp_read(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for read"); - return -1; + return -EACCES; } err = nfp_cpp_area_read(area, 0, address, length); @@ -1013,7 +1065,7 @@ nfp_cpp_write(struct nfp_cpp *cpp, area = nfp_cpp_area_alloc_acquire(cpp, destination, offset, length); if (area == NULL) { PMD_DRV_LOG(ERR, "Area allocation/acquire failed for write"); - return -1; + return -EACCES; } err = nfp_cpp_area_write(area, 0, address, length); @@ -1039,8 +1091,12 @@ nfp_cpp_model_autodetect(struct nfp_cpp *cpp, return err; *model = reg & NFP_PL_DEVICE_MODEL_MASK; - if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) - *model -= 0x10; + /* Disambiguate the NFP4000/NFP5000/NFP6000 chips */ + if (FIELD_GET(NFP_PL_DEVICE_PART_MASK, reg) == + NFP_PL_DEVICE_PART_NFP6000) { + if ((*model & NFP_PL_DEVICE_ID_MASK) != 0) + *model -= 0x10; + } return 0; } -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 24/26] net/nfp: refact the PCIe module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (22 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 23/26] net/nfp: refact the cppcore module Chaoyong He @ 2023-09-19 9:54 ` Chaoyong He 2023-09-19 21:18 ` [PATCH v5 00/26] refact the nfpcore module Ferruh Yigit 2023-09-20 9:59 ` Ferruh Yigit 25 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-19 9:54 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Sync the logic from kernel driver and remove the unneeded header file include statements. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 211 +++++++++++++++++-------- drivers/net/nfp/nfpcore/nfp_cpp.h | 9 ++ 2 files changed, 150 insertions(+), 70 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 45645e04f8..4f453f19a9 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -16,23 +16,8 @@ #include "nfp6000_pcie.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> #include <unistd.h> -#include <stdint.h> -#include <stdbool.h> #include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <dirent.h> -#include <libgen.h> - -#include <sys/mman.h> -#include <sys/file.h> -#include <sys/stat.h> - -#include <ethdev_pci.h> #include "nfp_cpp.h" #include "nfp_logs.h" @@ -43,8 +28,11 @@ #define NFP_PCIE_BAR(_pf) (0x30000 + ((_pf) & 7) * 0xc0) #define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS(_x) (((_x) & 0x1f) << 16) +#define NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(_x) (((_x) >> 16) & 0x1f) #define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS(_x) (((_x) & 0xffff) << 0) +#define NFP_PCIE_BAR_PCIE2CPP_BASEADDRESS_OF(_x) (((_x) >> 0) & 0xffff) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT(_x) (((_x) & 0x3) << 27) +#define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(_x) (((_x) >> 27) & 0x3) #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT 0 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT 1 #define NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE 3 @@ -55,7 +43,9 @@ #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET 2 #define NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL 3 #define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS(_x) (((_x) & 0xf) << 23) +#define NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(_x) (((_x) >> 23) & 0xf) #define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS(_x) (((_x) & 0x3) << 21) +#define NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(_x) (((_x) >> 21) & 0x3) /* * Minimal size of the PCIe cfg memory we depend on being mapped, @@ -132,7 +122,7 @@ nfp_compute_bar(const struct nfp_bar *bar, uint32_t newcfg; uint32_t bitsize; - if (target >= 16) + if (target >= NFP_CPP_NUM_TARGETS) return -EINVAL; switch (width) { @@ -182,10 +172,6 @@ nfp_compute_bar(const struct nfp_bar *bar, offset &= mask; bitsize = 40 - 21; } - - if (bar->bitsize < bitsize) - return -EINVAL; - newcfg |= offset >> bitsize; if (bar_base != NULL) @@ -434,7 +420,7 @@ nfp6000_area_acquire(struct nfp_cpp_area *area) /* Must have been too big. Sub-allocate. */ if (priv->bar->iomem == NULL) - return (-ENOMEM); + return -ENOMEM; priv->iomem = priv->bar->iomem + priv->bar_offset; @@ -464,9 +450,9 @@ nfp6000_area_read(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32 = address; uint64_t *wrptr64 = address; struct nfp6000_area_priv *priv; @@ -484,47 +470,54 @@ nfp6000_area_read(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) { PMD_DRV_LOG(ERR, "aread_read unaligned!!!"); return -EINVAL; } - is_64 = width == TARGET_WIDTH_64; - - /* MU reads via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) { - is_64 = false; - } + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; + ret = n; + break; + default: + return -EINVAL; + } + + return ret; } static int @@ -533,9 +526,9 @@ nfp6000_area_write(struct nfp_cpp_area *area, uint32_t offset, size_t length) { + int ret; size_t n; int width; - bool is_64; uint32_t *wrptr32; uint64_t *wrptr64; struct nfp6000_area_priv *priv; @@ -553,47 +546,53 @@ nfp6000_area_write(struct nfp_cpp_area *area, if (width <= 0) return -EINVAL; + /* MU reads via a PCIe2CPP BAR support 32bit (and other) lengths */ + if (priv->target == (NFP_CPP_TARGET_MU & NFP_CPP_TARGET_ID_MASK) && + priv->action == NFP_CPP_ACTION_RW && + (offset % sizeof(uint64_t) == 4 || + length % sizeof(uint64_t) == 4)) + width = TARGET_WIDTH_32; + /* Unaligned? Translate to an explicit access */ if (((priv->offset + offset) & (width - 1)) != 0) return -EINVAL; - is_64 = width == TARGET_WIDTH_64; - - /* MU writes via a PCIe2CPP BAR supports 32bit (and other) lengths */ - if (priv->target == (NFP_CPP_TARGET_ID_MASK & NFP_CPP_TARGET_MU) && - priv->action == NFP_CPP_ACTION_RW) - is_64 = false; + if (priv->bar == NULL) + return -EFAULT; - if (is_64) { - if (offset % sizeof(uint64_t) != 0 || - length % sizeof(uint64_t) != 0) - return -EINVAL; - } else { + switch (width) { + case TARGET_WIDTH_32: if (offset % sizeof(uint32_t) != 0 || length % sizeof(uint32_t) != 0) return -EINVAL; - } - if (priv->bar == NULL) - return -EFAULT; + for (n = 0; n < length; n += sizeof(uint32_t)) { + *wrptr32 = *rdptr32; + wrptr32++; + rdptr32++; + } + + ret = n; + break; + case TARGET_WIDTH_64: + if (offset % sizeof(uint64_t) != 0 || + length % sizeof(uint64_t) != 0) + return -EINVAL; - if (is_64) for (n = 0; n < length; n += sizeof(uint64_t)) { *wrptr64 = *rdptr64; wrptr64++; rdptr64++; } - else - for (n = 0; n < length; n += sizeof(uint32_t)) { - *wrptr32 = *rdptr32; - wrptr32++; - rdptr32++; - } - return n; -} + ret = n; + break; + default: + return -EINVAL; + } -#define PCI_DEVICES "/sys/bus/pci/devices" + return ret; +} static int nfp_acquire_process_lock(struct nfp_pcie_user *desc) @@ -706,6 +705,74 @@ nfp6000_set_serial(struct rte_pci_device *dev, return 0; } +static int +nfp6000_get_dsn(struct rte_pci_device *pci_dev, + uint64_t *dsn) +{ + off_t pos; + size_t len; + uint64_t tmp = 0; + + pos = rte_pci_find_ext_capability(pci_dev, RTE_PCI_EXT_CAP_ID_DSN); + if (pos <= 0) { + PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found"); + return -ENODEV; + } + + pos += 4; + len = sizeof(tmp); + + if (rte_pci_read_config(pci_dev, &tmp, len, pos) < 0) { + PMD_DRV_LOG(ERR, "nfp get device serial number failed"); + return -ENOENT; + } + + *dsn = tmp; + + return 0; +} + +static int +nfp6000_get_interface(struct rte_pci_device *dev, + uint16_t *interface) +{ + int ret; + uint64_t dsn = 0; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + *interface = dsn & 0xffff; + + return 0; +} + +static int +nfp6000_get_serial(struct rte_pci_device *dev, + uint8_t *serial, + size_t length) +{ + int ret; + uint64_t dsn = 0; + + if (length < NFP_SERIAL_LEN) + return -ENOMEM; + + ret = nfp6000_get_dsn(dev, &dsn); + if (ret != 0) + return ret; + + serial[0] = (dsn >> 56) & 0xff; + serial[1] = (dsn >> 48) & 0xff; + serial[2] = (dsn >> 40) & 0xff; + serial[3] = (dsn >> 32) & 0xff; + serial[4] = (dsn >> 24) & 0xff; + serial[5] = (dsn >> 16) & 0xff; + + return 0; +} + static int nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) @@ -789,6 +856,10 @@ static const struct nfp_cpp_operations nfp6000_pcie_ops = { .free = nfp6000_free, .area_priv_size = sizeof(struct nfp6000_area_priv), + + .get_interface = nfp6000_get_interface, + .get_serial = nfp6000_get_serial, + .area_init = nfp6000_area_init, .area_acquire = nfp6000_area_acquire, .area_release = nfp6000_area_release, diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 34ed50ceca..0f36ba0b50 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -16,6 +16,8 @@ struct nfp_cpp_area; #define NFP_SERIAL_LEN 6 +#define NFP_CPP_NUM_TARGETS 16 + /* * NFP CPP operations structure */ @@ -33,6 +35,13 @@ struct nfp_cpp_operations { */ void (*free)(struct nfp_cpp *cpp); + int (*get_interface)(struct rte_pci_device *dev, + uint16_t *interface); + + int (*get_serial)(struct rte_pci_device *dev, + uint8_t *serial, + size_t length); + /* * Initialize a new NFP CPP area * NOTE: This is _not_ serialized -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v5 00/26] refact the nfpcore module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (23 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 24/26] net/nfp: refact the PCIe module Chaoyong He @ 2023-09-19 21:18 ` Ferruh Yigit 2023-09-20 1:55 ` Chaoyong He 2023-09-20 9:59 ` Ferruh Yigit 25 siblings, 1 reply; 159+ messages in thread From: Ferruh Yigit @ 2023-09-19 21:18 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers On 9/19/2023 10:54 AM, Chaoyong He wrote: > This patch series aims to: > - Make the coding style satisfy with DPDK. > - Sync the logic with kernel driver. > - Make the sub-module more modular. > - Extend the nfp configure BAR from 8 to 24. > > --- > v5: > * Fix one bug in the logic of VF using dev module. > * Remove the R-b tag as the requirement of Niklas. > * Revise logic follow the advice of reviewer. > v4: > * Drop the commit 'using the DPDK memory management API'. > * Modify the commit message of 'standard the comment style'. > * Revise some comment logic as the advice of reviewer. > v3: > * Fix one bug in the BAR find logic. > * Modify more coding style. > v2: > * Fix the compile error in Fodora 37 environment. > --- > > Chaoyong He (26): > net/nfp: explicitly compare to null and 0 > net/nfp: unify the indent coding style > net/nfp: unify the type of integer variable > net/nfp: remove the unneeded logic > net/nfp: standard the local variable coding style > net/nfp: adjust the log statement > net/nfp: standard the comment style > net/nfp: standard the blank character > net/nfp: unify the guide line of header file > net/nfp: rename some parameter and variable > net/nfp: refact the hwinfo module > net/nfp: refact the nffw module > net/nfp: refact the mip module > net/nfp: refact the rtsym module > net/nfp: refact the resource module > net/nfp: refact the target module > net/nfp: add a new header file > net/nfp: refact the nsp module > net/nfp: refact the mutex module > net/nfp: rename data field to sync with kernel driver > net/nfp: add the dev module > net/nfp: add header file for PCIe module > net/nfp: refact the cppcore module > net/nfp: refact the PCIe module > net/nfp: refact the cppcore and PCIe module > net/nfp: extend the usage of nfp BAR from 8 to 24 > Hi Chaoyong, This set has 24 patches in the mail_list/patchwork, last two patches are missing, can you please double check? ^ permalink raw reply [flat|nested] 159+ messages in thread
* RE: [PATCH v5 00/26] refact the nfpcore module 2023-09-19 21:18 ` [PATCH v5 00/26] refact the nfpcore module Ferruh Yigit @ 2023-09-20 1:55 ` Chaoyong He 2023-09-20 8:54 ` Ferruh Yigit 0 siblings, 1 reply; 159+ messages in thread From: Chaoyong He @ 2023-09-20 1:55 UTC (permalink / raw) To: Ferruh Yigit, dev; +Cc: oss-drivers > On 9/19/2023 10:54 AM, Chaoyong He wrote: > > This patch series aims to: > > - Make the coding style satisfy with DPDK. > > - Sync the logic with kernel driver. > > - Make the sub-module more modular. > > - Extend the nfp configure BAR from 8 to 24. > > > > --- > > v5: > > * Fix one bug in the logic of VF using dev module. > > * Remove the R-b tag as the requirement of Niklas. > > * Revise logic follow the advice of reviewer. > > v4: > > * Drop the commit 'using the DPDK memory management API'. > > * Modify the commit message of 'standard the comment style'. > > * Revise some comment logic as the advice of reviewer. > > v3: > > * Fix one bug in the BAR find logic. > > * Modify more coding style. > > v2: > > * Fix the compile error in Fodora 37 environment. > > --- > > > > Chaoyong He (26): > > net/nfp: explicitly compare to null and 0 > > net/nfp: unify the indent coding style > > net/nfp: unify the type of integer variable > > net/nfp: remove the unneeded logic > > net/nfp: standard the local variable coding style > > net/nfp: adjust the log statement > > net/nfp: standard the comment style > > net/nfp: standard the blank character > > net/nfp: unify the guide line of header file > > net/nfp: rename some parameter and variable > > net/nfp: refact the hwinfo module > > net/nfp: refact the nffw module > > net/nfp: refact the mip module > > net/nfp: refact the rtsym module > > net/nfp: refact the resource module > > net/nfp: refact the target module > > net/nfp: add a new header file > > net/nfp: refact the nsp module > > net/nfp: refact the mutex module > > net/nfp: rename data field to sync with kernel driver > > net/nfp: add the dev module > > net/nfp: add header file for PCIe module > > net/nfp: refact the cppcore module > > net/nfp: refact the PCIe module > > net/nfp: refact the cppcore and PCIe module > > net/nfp: extend the usage of nfp BAR from 8 to 24 > > > > > Hi Chaoyong, > > This set has 24 patches in the mail_list/patchwork, last two patches are > missing, can you please double check? Sorry, the send email command failed after the 24/26 patch has send out, and I'm not found that. $ git send-email --to dev@dpdk.org --cc oss-drivers@corigine.com --in-reply-to 20230918024612.1600536-1-chaoyong.he@corigine.com ./*.patch Can't locate Email/Valid.pm in @INC (you may need to install the Email::Valid module) (@INC contains: /usr/share/perl5/vendor_perl /usr/local/lib64/perl5/5.32 /usr/local/share/perl5/5.32 /usr/lib64/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /usr/libexec/git-core/git-send-email line 1138. ...propagated at /usr/libexec/git-core/git-send-email line 1694. This is the first time I meet this problem, and it's my fault did not notice it, and I still not sure what cause it. I re-send the 25/26 and 26/26 patch with the same command (except the './*.patch' part), but seems they are not recognized as the same series in the patchwork: Untitled series #29559 Untitled series #29560 How to fix that or should I send a v6 version for the whole series? ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v5 00/26] refact the nfpcore module 2023-09-20 1:55 ` Chaoyong He @ 2023-09-20 8:54 ` Ferruh Yigit 0 siblings, 0 replies; 159+ messages in thread From: Ferruh Yigit @ 2023-09-20 8:54 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers On 9/20/2023 2:55 AM, Chaoyong He wrote: >> On 9/19/2023 10:54 AM, Chaoyong He wrote: >>> This patch series aims to: >>> - Make the coding style satisfy with DPDK. >>> - Sync the logic with kernel driver. >>> - Make the sub-module more modular. >>> - Extend the nfp configure BAR from 8 to 24. >>> >>> --- >>> v5: >>> * Fix one bug in the logic of VF using dev module. >>> * Remove the R-b tag as the requirement of Niklas. >>> * Revise logic follow the advice of reviewer. >>> v4: >>> * Drop the commit 'using the DPDK memory management API'. >>> * Modify the commit message of 'standard the comment style'. >>> * Revise some comment logic as the advice of reviewer. >>> v3: >>> * Fix one bug in the BAR find logic. >>> * Modify more coding style. >>> v2: >>> * Fix the compile error in Fodora 37 environment. >>> --- >>> >>> Chaoyong He (26): >>> net/nfp: explicitly compare to null and 0 >>> net/nfp: unify the indent coding style >>> net/nfp: unify the type of integer variable >>> net/nfp: remove the unneeded logic >>> net/nfp: standard the local variable coding style >>> net/nfp: adjust the log statement >>> net/nfp: standard the comment style >>> net/nfp: standard the blank character >>> net/nfp: unify the guide line of header file >>> net/nfp: rename some parameter and variable >>> net/nfp: refact the hwinfo module >>> net/nfp: refact the nffw module >>> net/nfp: refact the mip module >>> net/nfp: refact the rtsym module >>> net/nfp: refact the resource module >>> net/nfp: refact the target module >>> net/nfp: add a new header file >>> net/nfp: refact the nsp module >>> net/nfp: refact the mutex module >>> net/nfp: rename data field to sync with kernel driver >>> net/nfp: add the dev module >>> net/nfp: add header file for PCIe module >>> net/nfp: refact the cppcore module >>> net/nfp: refact the PCIe module >>> net/nfp: refact the cppcore and PCIe module >>> net/nfp: extend the usage of nfp BAR from 8 to 24 >>> >> >> >> Hi Chaoyong, >> >> This set has 24 patches in the mail_list/patchwork, last two patches are >> missing, can you please double check? > > Sorry, the send email command failed after the 24/26 patch has send out, and I'm not found that. > > $ git send-email --to dev@dpdk.org --cc oss-drivers@corigine.com --in-reply-to 20230918024612.1600536-1-chaoyong.he@corigine.com ./*.patch > > Can't locate Email/Valid.pm in @INC (you may need to install the Email::Valid module) (@INC contains: /usr/share/perl5/vendor_perl /usr/local/lib64/perl5/5.32 /usr/local/share/perl5/5.32 /usr/lib64/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /usr/libexec/git-core/git-send-email line 1138. > ...propagated at /usr/libexec/git-core/git-send-email line 1694. > > This is the first time I meet this problem, and it's my fault did not notice it, and I still not sure what cause it. > Same here, error is not familiar and not sure about root cause. > I re-send the 25/26 and 26/26 patch with the same command (except the './*.patch' part), but seems they are not recognized as the same series in the patchwork: > Untitled series #29559 > Untitled series #29560 > > How to fix that or should I send a v6 version for the whole series? > That is OK, I will get missing patches manually. ^ permalink raw reply [flat|nested] 159+ messages in thread
* Re: [PATCH v5 00/26] refact the nfpcore module 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He ` (24 preceding siblings ...) 2023-09-19 21:18 ` [PATCH v5 00/26] refact the nfpcore module Ferruh Yigit @ 2023-09-20 9:59 ` Ferruh Yigit 25 siblings, 0 replies; 159+ messages in thread From: Ferruh Yigit @ 2023-09-20 9:59 UTC (permalink / raw) To: Chaoyong He, dev; +Cc: oss-drivers On 9/19/2023 10:54 AM, Chaoyong He wrote: > This patch series aims to: > - Make the coding style satisfy with DPDK. > - Sync the logic with kernel driver. > - Make the sub-module more modular. > - Extend the nfp configure BAR from 8 to 24. > > --- > v5: > * Fix one bug in the logic of VF using dev module. > * Remove the R-b tag as the requirement of Niklas. > * Revise logic follow the advice of reviewer. > v4: > * Drop the commit 'using the DPDK memory management API'. > * Modify the commit message of 'standard the comment style'. > * Revise some comment logic as the advice of reviewer. > v3: > * Fix one bug in the BAR find logic. > * Modify more coding style. > v2: > * Fix the compile error in Fodora 37 environment. > --- > > Chaoyong He (26): > net/nfp: explicitly compare to null and 0 > net/nfp: unify the indent coding style > net/nfp: unify the type of integer variable > net/nfp: remove the unneeded logic > net/nfp: standard the local variable coding style > net/nfp: adjust the log statement > net/nfp: standard the comment style > net/nfp: standard the blank character > net/nfp: unify the guide line of header file > net/nfp: rename some parameter and variable > net/nfp: refact the hwinfo module > net/nfp: refact the nffw module > net/nfp: refact the mip module > net/nfp: refact the rtsym module > net/nfp: refact the resource module > net/nfp: refact the target module > net/nfp: add a new header file > net/nfp: refact the nsp module > net/nfp: refact the mutex module > net/nfp: rename data field to sync with kernel driver > net/nfp: add the dev module > net/nfp: add header file for PCIe module > net/nfp: refact the cppcore module > net/nfp: refact the PCIe module > net/nfp: refact the cppcore and PCIe module > net/nfp: extend the usage of nfp BAR from 8 to 24 > Series applied to dpdk-next-net/main, thanks. For reference following sets merged (as set split into multiple series because of send-email issues): https://patchwork.dpdk.org/project/dpdk/list/?series=29547 https://patchwork.dpdk.org/project/dpdk/list/?series=29559 https://patchwork.dpdk.org/project/dpdk/list/?series=29560 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 25/26] net/nfp: refact the cppcore and PCIe module 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (26 preceding siblings ...) 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He @ 2023-09-20 1:28 ` Chaoyong He 2023-09-20 1:29 ` [PATCH v5 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-20 1:28 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Sync the logic from kernel driver, use the new entry function from the PCIe module instead of the cppcore module. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 9 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 197 ++++++++++--------------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 6 + drivers/net/nfp/nfpcore/nfp_cpp.h | 36 +---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 68 ++++++--- 5 files changed, 142 insertions(+), 174 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 04244c4e08..673bb06d00 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -23,6 +23,7 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.h" #include "nfpcore/nfp_nsp.h" +#include "nfpcore/nfp6000_pcie.h" #include "nfp_common.h" #include "nfp_ctrl.h" @@ -919,9 +920,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1120,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_device_name(pci_dev, 0); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); else - cpp = nfp_cpp_from_device_name(pci_dev, 1); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 4f453f19a9..40076cdc11 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -98,6 +98,24 @@ struct nfp_pcie_user { char *cfg; }; +/* Generic CPP bus access interface. */ +struct nfp6000_area_priv { + struct nfp_bar *bar; + uint32_t bar_offset; + + int target; + int action; + int token; + uint64_t offset; + struct { + int read; + int write; + int bar; + } width; + size_t size; + char *iomem; +}; + static uint32_t nfp_bar_maptype(struct nfp_bar *bar) { @@ -334,24 +352,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) } } -/* Generic CPP bus access interface. */ -struct nfp6000_area_priv { - struct nfp_bar *bar; - uint32_t bar_offset; - - uint32_t target; - uint32_t action; - uint32_t token; - uint64_t offset; - struct { - int read; - int write; - int bar; - } width; - size_t size; - char *iomem; -}; - static int nfp6000_area_init(struct nfp_cpp_area *area, uint32_t dest, @@ -624,87 +624,6 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) return 0; } -static int -nfp6000_set_model(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint32_t model; - - if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { - PMD_DRV_LOG(ERR, "nfp set model failed"); - return -1; - } - - model = model << 16; - nfp_cpp_model_set(cpp, model); - - return 0; -} - -static int -nfp6000_set_interface(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - uint16_t interface; - - if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { - PMD_DRV_LOG(ERR, "nfp set interface failed"); - return -1; - } - - nfp_cpp_interface_set(cpp, interface); - - return 0; -} - -static int -nfp6000_set_serial(struct rte_pci_device *dev, - struct nfp_cpp *cpp) -{ - off_t pos; - uint16_t tmp; - uint8_t serial[6]; - int serial_len = 6; - - pos = rte_pci_find_ext_capability(dev, RTE_PCI_EXT_CAP_ID_DSN); - if (pos <= 0) { - PMD_DRV_LOG(ERR, "PCI_EXT_CAP_ID_DSN not found. nfp set serial failed"); - return -1; - } else { - pos += 6; - } - - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[4] = (uint8_t)((tmp >> 8) & 0xff); - serial[5] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[2] = (uint8_t)((tmp >> 8) & 0xff); - serial[3] = (uint8_t)(tmp & 0xff); - - pos += 2; - if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { - PMD_DRV_LOG(ERR, "nfp set serial failed"); - return -1; - } - - serial[0] = (uint8_t)((tmp >> 8) & 0xff); - serial[1] = (uint8_t)(tmp & 0xff); - - nfp_cpp_serial_set(cpp, serial, serial_len); - - return 0; -} - static int nfp6000_get_dsn(struct rte_pci_device *pci_dev, uint64_t *dsn) @@ -795,12 +714,7 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { int ret = 0; - struct nfp_pcie_user *desc; - - desc = malloc(sizeof(*desc)); - if (desc == NULL) - return -1; - + struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); @@ -809,17 +723,11 @@ nfp6000_init(struct nfp_cpp *cpp, nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); if (ret != 0) - goto error; + return -1; } - if (nfp6000_set_model(dev, cpp) < 0) - goto error; - if (nfp6000_set_interface(dev, cpp) < 0) - goto error; - if (nfp6000_set_serial(dev, cpp) < 0) - goto error; if (nfp6000_set_barsz(dev, desc) < 0) - goto error; + return -1; desc->cfg = dev->mem_resource[0].addr; desc->dev_id = dev->addr.function & 0x7; @@ -830,13 +738,7 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - nfp_cpp_priv_set(cpp, desc); - return 0; - -error: - free(desc); - return -1; } static void @@ -873,3 +775,60 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) { return &nfp6000_pcie_ops; } + +/** + * Build a NFP CPP bus from a NFP6000 PCI device + * + * @param pdev + * NFP6000 PCI device + * @param driver_lock_needed + * driver lock flag + * + * @return + * NFP CPP handle or NULL + */ +struct nfp_cpp * +nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed) +{ + int ret; + struct nfp_cpp *cpp; + uint16_t interface = 0; + struct nfp_pcie_user *nfp; + + nfp = malloc(sizeof(*nfp)); + if (nfp == NULL) + return NULL; + + memset(nfp, 0, sizeof(*nfp)); + + ret = nfp6000_get_interface(pci_dev, &interface); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Get interface failed."); + free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_TYPE_of(interface) != NFP_CPP_INTERFACE_TYPE_PCI) { + PMD_DRV_LOG(ERR, "Interface type is not right."); + free(nfp); + return NULL; + } + + if (NFP_CPP_INTERFACE_CHANNEL_of(interface) != + NFP_CPP_INTERFACE_CHANNEL_PEROPENER) { + PMD_DRV_LOG(ERR, "Interface channel is not right"); + free(nfp); + return NULL; + } + + /* Probe for all the common NFP devices */ + cpp = nfp_cpp_from_device_name(pci_dev, nfp, driver_lock_needed); + if (cpp == NULL) { + PMD_DRV_LOG(ERR, "Get cpp from operation failed"); + free(nfp); + return NULL; + } + + return cpp; +} diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index e126457d45..8847f6f946 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -6,8 +6,14 @@ #ifndef __NFP6000_PCIE_H__ #define __NFP6000_PCIE_H__ +#include <ethdev_pci.h> + #include "nfp_cpp.h" +#include "nfp_dev.h" const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); +struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + bool driver_lock_needed); + #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 0f36ba0b50..e879c7c920 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -226,40 +226,12 @@ uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model); /* NFP CPP core interface for CPP clients */ struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed); + void *priv, bool driver_lock_needed); void nfp_cpp_free(struct nfp_cpp *cpp); #define NFP_CPP_MODEL_INVALID 0xffffffff -/** - * Retrieve the chip ID from the model ID - * - * The chip ID is a 16-bit BCD+A-F encoding for the chip type. - * - * @param model - * NFP CPP model id - * - * @return - * NFP CPP chip id - */ -#define NFP_CPP_MODEL_CHIP_of(model) (((model) >> 16) & 0xffff) - -/** - * Check for the NFP6000 family of devices - * - * NOTE: The NFP4000 series is considered as a NFP6000 series variant. - * - * @param model - * NFP CPP model id - * - * @return - * true if model is in the NFP6000 family, false otherwise. - */ -#define NFP_CPP_MODEL_IS_6000(model) \ - ((NFP_CPP_MODEL_CHIP_of(model) >= 0x3800) && \ - (NFP_CPP_MODEL_CHIP_of(model) < 0x7000)) - uint32_t nfp_cpp_model(struct nfp_cpp *cpp); /* @@ -330,6 +302,12 @@ uint32_t nfp_cpp_model(struct nfp_cpp *cpp); */ #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >> 0) & 0xff) +/* + * Use this channel ID for multiple virtual channel interfaces + * (ie ARM and PCIe) when setting up the interface field. + */ +#define NFP_CPP_INTERFACE_CHANNEL_PEROPENER 255 + uint16_t nfp_cpp_interface(struct nfp_cpp *cpp); uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index bbf2eaa448..8b2d00a6a1 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -909,10 +909,13 @@ nfp_xpb_readl(struct nfp_cpp *cpp, } static struct nfp_cpp * -nfp_cpp_alloc(struct rte_pci_device *dev, - int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *pci_dev, + void *priv, + bool driver_lock_needed) { int err; + size_t target; + uint32_t xpb_addr; struct nfp_cpp *cpp; const struct nfp_cpp_operations *ops; @@ -925,32 +928,50 @@ nfp_cpp_alloc(struct rte_pci_device *dev, return NULL; cpp->op = ops; + cpp->priv = priv; cpp->driver_lock_needed = driver_lock_needed; - if (cpp->op->init) { - err = cpp->op->init(cpp, dev); + err = ops->get_interface(pci_dev, &cpp->interface); + if (err != 0) { + free(cpp); + return NULL; + } + + err = ops->get_serial(pci_dev, cpp->serial, NFP_SERIAL_LEN); + if (err != 0) { + free(cpp); + return NULL; + } + + /* + * NOTE: cpp_lock is NOT locked for op->init, + * since it may call NFP CPP API operations + */ + err = cpp->op->init(cpp, pci_dev); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP interface initialization failed"); + free(cpp); + return NULL; + } + + err = nfp_cpp_model_autodetect(cpp, &cpp->model); + if (err < 0) { + PMD_DRV_LOG(ERR, "NFP model detection failed"); + free(cpp); + return NULL; + } + + for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { + /* Hardcoded XPB IMB Base, island 0 */ + xpb_addr = 0x000a0000 + (target * 4); + err = nfp_xpb_readl(cpp, xpb_addr, &cpp->imb_cat_table[target]); if (err < 0) { + PMD_DRV_LOG(ERR, "Can't read CPP mapping from device"); free(cpp); return NULL; } } - if (NFP_CPP_MODEL_IS_6000(nfp_cpp_model(cpp))) { - uint32_t xpb_addr; - size_t target; - - for (target = 0; target < RTE_DIM(cpp->imb_cat_table); target++) { - /* Hardcoded XPB IMB Base, island 0 */ - xpb_addr = 0x000a0000 + (target * 4); - err = nfp_xpb_readl(cpp, xpb_addr, - (uint32_t *)&cpp->imb_cat_table[target]); - if (err < 0) { - free(cpp); - return NULL; - } - } - } - err = nfp_cpp_set_mu_locality_lsb(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "Can't calculate MU locality bit offset"); @@ -981,6 +1002,8 @@ nfp_cpp_free(struct nfp_cpp *cpp) * * @param dev * PCI device + * @param priv + * Private data of low-level implementation * @param driver_lock_needed * Driver lock flag * @@ -991,9 +1014,10 @@ nfp_cpp_free(struct nfp_cpp *cpp) */ struct nfp_cpp * nfp_cpp_from_device_name(struct rte_pci_device *dev, - int driver_lock_needed) + void *priv, + bool driver_lock_needed) { - return nfp_cpp_alloc(dev, driver_lock_needed); + return nfp_cpp_alloc(dev, priv, driver_lock_needed); } /** -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
* [PATCH v5 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He ` (27 preceding siblings ...) 2023-09-20 1:28 ` [PATCH v5 25/26] net/nfp: refact the cppcore and PCIe module Chaoyong He @ 2023-09-20 1:29 ` Chaoyong He 28 siblings, 0 replies; 159+ messages in thread From: Chaoyong He @ 2023-09-20 1:29 UTC (permalink / raw) To: dev; +Cc: oss-drivers, Chaoyong He Sync the logic from kernel driver, adjust the definition of structure, and extend the usage of nfp BAR from 8 to 24. This will greatly enhance the scalability of nfp PMD. Signed-off-by: Chaoyong He <chaoyong.he@corigine.com> --- drivers/net/nfp/nfp_ethdev.c | 8 +- drivers/net/nfp/nfpcore/nfp6000_pcie.c | 477 ++++++++++++++++++------- drivers/net/nfp/nfpcore/nfp6000_pcie.h | 1 + drivers/net/nfp/nfpcore/nfp_cpp.h | 5 +- drivers/net/nfp/nfpcore/nfp_cppcore.c | 2 +- 5 files changed, 348 insertions(+), 145 deletions(-) diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 673bb06d00..b2a2cd9ed8 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -920,9 +920,9 @@ nfp_pf_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); @@ -1121,9 +1121,9 @@ nfp_pf_secondary_init(struct rte_pci_device *pci_dev) * use a lock file if UIO is being used. */ if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO) - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, false); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, false); else - cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, true); + cpp = nfp_cpp_from_nfp6000_pcie(pci_dev, dev_info, true); if (cpp == NULL) { PMD_INIT_LOG(ERR, "A CPP handle can not be obtained"); diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c index 40076cdc11..13cf523506 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c @@ -19,6 +19,8 @@ #include <unistd.h> #include <fcntl.h> +#include <rte_io.h> + #include "nfp_cpp.h" #include "nfp_logs.h" #include "nfp_target.h" @@ -59,20 +61,12 @@ #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4)) #define NFP_PCIE_P2C_GENERAL_SIZE(bar) (1 << ((bar)->bitsize - 4)) -#define NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(id, bar, slot) \ - (NFP_PCIE_BAR(id) + ((bar) * 8 + (slot)) * 4) - -#define NFP_PCIE_CPP_BAR_PCIETOCPPEXPBAR(bar, slot) \ - (((bar) * 8 + (slot)) * 4) +#define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index) ((bar_index) * 4) struct nfp_pcie_user; struct nfp6000_area_priv; /* Describes BAR configuration and usage */ -#define NFP_BAR_MIN 1 -#define NFP_BAR_MID 5 -#define NFP_BAR_MAX 7 - struct nfp_bar { struct nfp_pcie_user *nfp; /**< Backlink to owner */ uint32_t barcfg; /**< BAR config CSR */ @@ -80,22 +74,26 @@ struct nfp_bar { uint64_t mask; /**< Mask of the BAR aperture (read only) */ uint32_t bitsize; /**< Bit size of the BAR aperture (read only) */ uint32_t index; /**< Index of the BAR */ - int lock; /**< If the BAR has been locked */ + bool lock; /**< If the BAR has been locked */ - char *csr; char *iomem; /**< mapped IO memory */ + struct rte_mem_resource *resource; /**< IOMEM resource window */ }; -#define BUSDEV_SZ 13 +#define NFP_PCI_BAR_MAX (PCI_64BIT_BAR_COUNT * 8) + struct nfp_pcie_user { - struct nfp_bar bar[NFP_BAR_MAX]; + struct rte_pci_device *pci_dev; + const struct nfp_dev_info *dev_info; - int device; int lock; - char busdev[BUSDEV_SZ]; - int barsz; - int dev_id; - char *cfg; + + /* PCI BAR management */ + uint32_t bars; + struct nfp_bar bar[NFP_PCI_BAR_MAX]; + + /* Reserved BAR access */ + char *csr; }; /* Generic CPP bus access interface. */ @@ -206,19 +204,19 @@ nfp_bar_write(struct nfp_pcie_user *nfp, struct nfp_bar *bar, uint32_t newcfg) { - int base; - int slot; - - base = bar->index >> 3; - slot = bar->index & 7; + uint32_t xbar; - if (nfp->cfg == NULL) - return (-ENOMEM); + xbar = NFP_PCIE_P2C_EXPBAR_OFFSET(bar->index); - bar->csr = nfp->cfg + - NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, base, slot); - - *(uint32_t *)(bar->csr) = newcfg; + if (nfp->csr != NULL) { + rte_write32(newcfg, nfp->csr + xbar); + /* Readback to ensure BAR is flushed */ + rte_read32(nfp->csr + xbar); + } else { + xbar += nfp->dev_info->pcie_cfg_expbar_offset; + rte_pci_write_config(nfp->pci_dev, &newcfg, sizeof(uint32_t), + xbar); + } bar->barcfg = newcfg; @@ -249,105 +247,323 @@ nfp_reconfigure_bar(struct nfp_pcie_user *nfp, return nfp_bar_write(nfp, bar, newcfg); } -/* - * Map all PCI bars. We assume that the BAR with the PCIe config block is - * already mapped. +static uint32_t +nfp_bitsize_calc(uint64_t mask) +{ + uint64_t tmp = mask; + uint32_t bit_size = 0; + + if (tmp == 0) + return 0; + + for (; tmp != 0; tmp >>= 1) + bit_size++; + + return bit_size; +} + +static int +nfp_cmp_bars(const void *ptr_a, + const void *ptr_b) +{ + const struct nfp_bar *a = ptr_a; + const struct nfp_bar *b = ptr_b; + + if (a->bitsize == b->bitsize) + return a->index - b->index; + else + return a->bitsize - b->bitsize; +} + +static bool +nfp_bars_for_secondary(uint32_t index) +{ + uint8_t tmp = index & 0x07; + + if (tmp == 0x06 || tmp == 0x07) + return true; + else + return false; +} + +/** + * Map all PCI bars and fetch the actual BAR configurations from the board. + * We assume that the BAR with the PCIe config block is already mapped. * * BAR0.0: Reserved for General Mapping (for MSI-X access to PCIe SRAM) + * BAR0.1: -- + * BAR0.2: -- + * BAR0.3: -- + * BAR0.4: -- + * BAR0.5: -- + * BAR0.6: -- + * BAR0.7: -- * - * Halving PCItoCPPBars for primary and secondary processes. - * For CoreNIC firmware: - * NFP PMD just requires two fixed slots, one for configuration BAR, - * and another for accessing the hw queues. Another slot is needed - * for setting the link up or down. Secondary processes do not need - * to map the first two slots again, but it requires one slot for - * accessing the link, even if it is not likely the secondary process - * starting the port. - * For Flower firmware: - * NFP PMD need another fixed slots, used as the configureation BAR - * for ctrl vNIC. + * BAR1.0-BAR1.7: -- + * BAR2.0-BAR2.7: -- */ static int nfp_enable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + int pf; + uint32_t i; + uint8_t min_bars; struct nfp_bar *bar; + enum rte_proc_type_t type; + struct rte_mem_resource *res; + const uint32_t barcfg_msix_general = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE + (NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_GENERAL) | + NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT; + + type = rte_eal_process_type(); + if (type == RTE_PROC_PRIMARY) + min_bars = 12; + else + min_bars = 4; + + for (i = 0; i < RTE_DIM(nfp->bar); i++) { + if (i != 0) { + if (type == RTE_PROC_PRIMARY) { + if (nfp_bars_for_secondary(i)) + continue; + } else { + if (!nfp_bars_for_secondary(i)) + continue; + } + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* 24 NFP bars mapping into BAR0, BAR2 and BAR4 */ + res = &nfp->pci_dev->mem_resource[(i >> 3) * 2]; + + /* Skip over BARs that are not mapped */ + if (res->addr != NULL) { + bar = &nfp->bar[i]; + bar->resource = res; + bar->barcfg = 0; + + bar->nfp = nfp; + bar->index = i; + /* The resource shared by 8 bars */ + bar->mask = (res->len >> 3) - 1; + bar->bitsize = nfp_bitsize_calc(bar->mask); + bar->base = 0; + bar->lock = false; + bar->iomem = (char *)res->addr + + ((bar->index & 7) << bar->bitsize); + + nfp->bars++; + } } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - bar->barcfg = 0; - bar->nfp = nfp; - bar->index = x; - bar->mask = (1 << (nfp->barsz - 3)) - 1; - bar->bitsize = nfp->barsz - 3; - bar->base = 0; - bar->iomem = NULL; - bar->lock = 0; - bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(nfp->dev_id, - bar->index >> 3, bar->index & 7); - bar->iomem = nfp->cfg + (bar->index << bar->bitsize); + if (nfp->bars < min_bars) { + PMD_DRV_LOG(ERR, "Not enough usable BARs found."); + return -EINVAL; } + + switch (nfp->pci_dev->id.device_id) { + case PCI_DEVICE_ID_NFP3800_PF_NIC: + pf = nfp->pci_dev->addr.function & 0x07; + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(pf); + break; + case PCI_DEVICE_ID_NFP4000_PF_NIC: + case PCI_DEVICE_ID_NFP6000_PF_NIC: + nfp->csr = nfp->bar[0].iomem + NFP_PCIE_BAR(0); + break; + default: + PMD_DRV_LOG(ERR, "Unsupported device ID: %04hx!", + nfp->pci_dev->id.device_id); + return -EINVAL; + } + + /* Configure, and lock, BAR0.0 for General Target use (MSI-X SRAM) */ + bar = &nfp->bar[0]; + bar->lock = true; + + nfp_bar_write(nfp, bar, barcfg_msix_general); + + /* Sort bars by bit size - use the smallest possible first. */ + qsort(&nfp->bar[0], nfp->bars, sizeof(nfp->bar[0]), nfp_cmp_bars); + return 0; } -static struct nfp_bar * -nfp_alloc_bar(struct nfp_pcie_user *nfp) +/* Check if BAR can be used with the given parameters. */ +static bool +matching_bar_exist(struct nfp_bar *bar, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) { - int x; - int end; - int start; - struct nfp_bar *bar; + int bar_width; + int bar_token; + int bar_target; + int bar_action; + uint32_t map_type; + + bar_width = NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_OF(bar->barcfg); + switch (bar_width) { + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_32BIT: + bar_width = 4; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_64BIT: + bar_width = 8; + break; + case NFP_PCIE_BAR_PCIE2CPP_LENGTHSELECT_0BYTE: + bar_width = 0; + break; + default: + bar_width = -1; + break; + } - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; + /* Make sure to match up the width */ + if (bar_width != width) + return false; + + bar_token = NFP_PCIE_BAR_PCIE2CPP_TOKEN_BASEADDRESS_OF(bar->barcfg); + bar_action = NFP_PCIE_BAR_PCIE2CPP_ACTION_BASEADDRESS_OF(bar->barcfg); + map_type = NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_OF(bar->barcfg); + switch (map_type) { + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_TARGET: + bar_token = -1; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_BULK: + bar_action = NFP_CPP_ACTION_RW; + if (action == 0) + action = NFP_CPP_ACTION_RW; + /* FALLTHROUGH */ + case NFP_PCIE_BAR_PCIE2CPP_MAPTYPE_FIXED: + break; + default: + /* We don't match explicit bars through the area interface */ + return false; } - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->lock == 0) { - bar->lock = 1; - return bar; - } + bar_target = NFP_PCIE_BAR_PCIE2CPP_TARGET_BASEADDRESS_OF(bar->barcfg); + if ((bar_target < 0 || bar_target == target) && + (bar_token < 0 || bar_token == token) && + bar_action == action && + bar->base <= offset && + (bar->base + (1 << bar->bitsize)) >= (offset + size)) + return true; + + /* No match */ + return false; +} + +static int +find_matching_bar(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + uint32_t n; + + for (n = 0; n < nfp->bars; n++) { + struct nfp_bar *bar = &nfp->bar[n]; + + if (bar->lock) + continue; + + if (matching_bar_exist(bar, target, action, token, + offset, size, width)) + return n; + } + + return -1; +} + +/* Return EAGAIN if no resource is available */ +static int +find_unused_bar_noblock(struct nfp_pcie_user *nfp, + int target, + int action, + int token, + uint64_t offset, + size_t size, + int width) +{ + int ret; + uint32_t n; + const struct nfp_bar *bar; + + for (n = 0; n < nfp->bars; n++) { + bar = &nfp->bar[n]; + + if (bar->bitsize == 0) + continue; + + /* Just check to see if we can make it fit... */ + ret = nfp_compute_bar(bar, NULL, NULL, target, action, + token, offset, size, width); + if (ret != 0) + continue; + + if (!bar->lock) + return n; + } + + return -EAGAIN; +} + +static int +nfp_alloc_bar(struct nfp_pcie_user *nfp, + struct nfp6000_area_priv *priv) +{ + int ret; + int bar_num; + size_t size = priv->size; + int token = priv->token; + int target = priv->target; + int action = priv->action; + int width = priv->width.bar; + uint64_t offset = priv->offset; + + /* Bar size should small than 16MB */ + if (size > (1 << 24)) + return -EINVAL; + + bar_num = find_matching_bar(nfp, target, action, token, + offset, size, width); + if (bar_num >= 0) { + /* Found a perfect match. */ + nfp->bar[bar_num].lock = true; + return bar_num; } - return NULL; + bar_num = find_unused_bar_noblock(nfp, target, action, token, + offset, size, width); + if (bar_num < 0) + return bar_num; + + nfp->bar[bar_num].lock = true; + ret = nfp_reconfigure_bar(nfp, &nfp->bar[bar_num], + target, action, token, offset, size, width); + if (ret < 0) { + nfp->bar[bar_num].lock = false; + return ret; + } + + return bar_num; } static void nfp_disable_bars(struct nfp_pcie_user *nfp) { - int x; - int end; - int start; + uint32_t i; struct nfp_bar *bar; - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - start = NFP_BAR_MID; - end = NFP_BAR_MIN; - } else { - start = NFP_BAR_MAX; - end = NFP_BAR_MID; - } - - for (x = start; x > end; x--) { - bar = &nfp->bar[x - 1]; - if (bar->iomem) { + for (i = 0; i < nfp->bars; i++) { + bar = &nfp->bar[i]; + if (bar->iomem != NULL) { bar->iomem = NULL; - bar->lock = 0; + bar->lock = false; } } } @@ -364,7 +580,6 @@ nfp6000_area_init(struct nfp_cpp_area *area, uint32_t target = NFP_CPP_ID_TARGET_of(dest); uint32_t action = NFP_CPP_ID_ACTION_of(dest); struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); pp = nfp_target_pushpull(NFP_CPP_ID(target, action, token), address); if (pp < 0) @@ -383,9 +598,7 @@ nfp6000_area_init(struct nfp_cpp_area *area, else priv->width.bar = priv->width.write; - priv->bar = nfp_alloc_bar(nfp); - if (priv->bar == NULL) - return -ENOMEM; + priv->bar = NULL; priv->target = target; priv->action = action; @@ -393,17 +606,29 @@ nfp6000_area_init(struct nfp_cpp_area *area, priv->offset = address; priv->size = size; - ret = nfp_reconfigure_bar(nfp, priv->bar, priv->target, priv->action, - priv->token, priv->offset, priv->size, - priv->width.bar); - return ret; } static int nfp6000_area_acquire(struct nfp_cpp_area *area) { + int bar_num; struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); + struct nfp_pcie_user *nfp = nfp_cpp_priv(nfp_cpp_area_cpp(area)); + + /* Already allocated. */ + if (priv->bar != NULL) + return 0; + + bar_num = nfp_alloc_bar(nfp, priv); + if (bar_num < 0) { + PMD_DRV_LOG(ERR, "Failed to allocate bar %d:%d:%d:%#lx: %d", + priv->target, priv->action, priv->token, + priv->offset, bar_num); + return bar_num; + } + + priv->bar = &nfp->bar[bar_num]; /* Calculate offset into BAR. */ if (nfp_bar_maptype(priv->bar) == @@ -432,7 +657,7 @@ nfp6000_area_release(struct nfp_cpp_area *area) { struct nfp6000_area_priv *priv = nfp_cpp_area_priv(area); - priv->bar->lock = 0; + priv->bar->lock = false; priv->bar = NULL; priv->iomem = NULL; } @@ -603,7 +828,8 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) memset(&lock, 0, sizeof(lock)); - snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", desc->busdev); + snprintf(lockname, sizeof(lockname), "/var/lock/nfp_%s", + desc->pci_dev->device.name); desc->lock = open(lockname, O_RDWR | O_CREAT, 0666); if (desc->lock < 0) return desc->lock; @@ -693,32 +919,11 @@ nfp6000_get_serial(struct rte_pci_device *dev, } static int -nfp6000_set_barsz(struct rte_pci_device *dev, - struct nfp_pcie_user *desc) -{ - int i = 0; - uint64_t tmp; - - tmp = dev->mem_resource[0].len; - - while (tmp >>= 1) - i++; - - desc->barsz = i; - - return 0; -} - -static int -nfp6000_init(struct nfp_cpp *cpp, - struct rte_pci_device *dev) +nfp6000_init(struct nfp_cpp *cpp) { int ret = 0; struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - memset(desc->busdev, 0, BUSDEV_SZ); - strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); - if (rte_eal_process_type() == RTE_PROC_PRIMARY && nfp_cpp_driver_need_lock(cpp)) { ret = nfp_acquire_process_lock(desc); @@ -726,12 +931,6 @@ nfp6000_init(struct nfp_cpp *cpp, return -1; } - if (nfp6000_set_barsz(dev, desc) < 0) - return -1; - - desc->cfg = dev->mem_resource[0].addr; - desc->dev_id = dev->addr.function & 0x7; - ret = nfp_enable_bars(desc); if (ret != 0) { PMD_DRV_LOG(ERR, "Enable bars failed"); @@ -749,7 +948,6 @@ nfp6000_free(struct nfp_cpp *cpp) nfp_disable_bars(desc); if (nfp_cpp_driver_need_lock(cpp)) close(desc->lock); - close(desc->device); free(desc); } @@ -789,6 +987,7 @@ nfp_cpp_operations *nfp_cpp_transport_operations(void) */ struct nfp_cpp * nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed) { int ret; @@ -801,6 +1000,8 @@ nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, return NULL; memset(nfp, 0, sizeof(*nfp)); + nfp->pci_dev = pci_dev; + nfp->dev_info = dev_info; ret = nfp6000_get_interface(pci_dev, &interface); if (ret != 0) { diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.h b/drivers/net/nfp/nfpcore/nfp6000_pcie.h index 8847f6f946..8e2cfb69e6 100644 --- a/drivers/net/nfp/nfpcore/nfp6000_pcie.h +++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.h @@ -14,6 +14,7 @@ const struct nfp_cpp_operations *nfp_cpp_transport_operations(void); struct nfp_cpp *nfp_cpp_from_nfp6000_pcie(struct rte_pci_device *pci_dev, + const struct nfp_dev_info *dev_info, bool driver_lock_needed); #endif /* __NFP6000_PCIE_H__ */ diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index e879c7c920..2defc4fa16 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -18,6 +18,8 @@ struct nfp_cpp_area; #define NFP_CPP_NUM_TARGETS 16 +#define PCI_64BIT_BAR_COUNT 3 + /* * NFP CPP operations structure */ @@ -26,8 +28,7 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, - struct rte_pci_device *dev); + int (*init)(struct nfp_cpp *cpp); /* * Free the bus. diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 8b2d00a6a1..f9b08a12b6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -947,7 +947,7 @@ nfp_cpp_alloc(struct rte_pci_device *pci_dev, * NOTE: cpp_lock is NOT locked for op->init, * since it may call NFP CPP API operations */ - err = cpp->op->init(cpp, pci_dev); + err = cpp->op->init(cpp); if (err < 0) { PMD_DRV_LOG(ERR, "NFP interface initialization failed"); free(cpp); -- 2.39.1 ^ permalink raw reply [flat|nested] 159+ messages in thread
end of thread, other threads:[~2023-09-20 9:59 UTC | newest] Thread overview: 159+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-08-24 11:09 [PATCH 00/27] refact the nfpcore module Chaoyong He 2023-08-24 11:09 ` [PATCH 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-08-24 11:09 ` [PATCH 02/27] net/nfp: unify the indent coding style Chaoyong He 2023-08-24 11:09 ` [PATCH 03/27] net/nfp: unify the type of integer variable Chaoyong He 2023-08-24 11:09 ` [PATCH 04/27] net/nfp: remove the unneeded logic Chaoyong He 2023-08-24 11:09 ` [PATCH 05/27] net/nfp: standard the local variable coding style Chaoyong He 2023-08-24 11:09 ` [PATCH 06/27] net/nfp: adjust the log statement Chaoyong He 2023-08-24 11:09 ` [PATCH 07/27] net/nfp: standard the comment style Chaoyong He 2023-08-24 11:09 ` [PATCH 08/27] net/nfp: using the DPDK memory management API Chaoyong He 2023-08-24 11:09 ` [PATCH 09/27] net/nfp: standard the blank character Chaoyong He 2023-08-24 11:09 ` [PATCH 10/27] net/nfp: unify the guide line of header file Chaoyong He 2023-08-24 11:09 ` [PATCH 11/27] net/nfp: rename some parameter and variable Chaoyong He 2023-08-24 11:09 ` [PATCH 12/27] net/nfp: refact the hwinfo module Chaoyong He 2023-08-24 11:09 ` [PATCH 13/27] net/nfp: refact the nffw module Chaoyong He 2023-08-24 11:09 ` [PATCH 14/27] net/nfp: refact the mip module Chaoyong He 2023-08-24 11:09 ` [PATCH 15/27] net/nfp: refact the rtsym module Chaoyong He 2023-08-24 11:09 ` [PATCH 16/27] net/nfp: refact the resource module Chaoyong He 2023-08-24 11:09 ` [PATCH 17/27] net/nfp: refact the target module Chaoyong He 2023-08-24 11:09 ` [PATCH 18/27] net/nfp: add a new header file Chaoyong He 2023-08-24 11:09 ` [PATCH 19/27] net/nfp: refact the nsp module Chaoyong He 2023-08-24 11:09 ` [PATCH 20/27] net/nfp: refact the mutex module Chaoyong He 2023-08-24 11:09 ` [PATCH 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He 2023-08-24 11:09 ` [PATCH 22/27] net/nfp: add the dev module Chaoyong He 2023-08-24 11:09 ` [PATCH 23/27] net/nfp: add header file for PCIe module Chaoyong He 2023-08-24 11:09 ` [PATCH 24/27] net/nfp: refact the cppcore module Chaoyong He 2023-08-24 11:09 ` [PATCH 25/27] net/nfp: refact the PCIe module Chaoyong He 2023-08-24 11:09 ` [PATCH 26/27] net/nfp: refact the cppcore and " Chaoyong He 2023-08-24 11:09 ` [PATCH 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 2023-08-30 2:14 ` [PATCH v2 00/27] refact the nfpcore module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-08-30 2:14 ` [PATCH v2 02/27] net/nfp: unify the indent coding style Chaoyong He 2023-08-30 2:14 ` [PATCH v2 03/27] net/nfp: unify the type of integer variable Chaoyong He 2023-08-30 2:14 ` [PATCH v2 04/27] net/nfp: remove the unneeded logic Chaoyong He 2023-08-30 2:14 ` [PATCH v2 05/27] net/nfp: standard the local variable coding style Chaoyong He 2023-08-30 2:14 ` [PATCH v2 06/27] net/nfp: adjust the log statement Chaoyong He 2023-08-30 2:14 ` [PATCH v2 07/27] net/nfp: standard the comment style Chaoyong He 2023-08-30 2:14 ` [PATCH v2 08/27] net/nfp: using the DPDK memory management API Chaoyong He 2023-08-30 2:14 ` [PATCH v2 09/27] net/nfp: standard the blank character Chaoyong He 2023-08-30 2:14 ` [PATCH v2 10/27] net/nfp: unify the guide line of header file Chaoyong He 2023-08-30 2:14 ` [PATCH v2 11/27] net/nfp: rename some parameter and variable Chaoyong He 2023-08-30 2:14 ` [PATCH v2 12/27] net/nfp: refact the hwinfo module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 13/27] net/nfp: refact the nffw module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 14/27] net/nfp: refact the mip module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 15/27] net/nfp: refact the rtsym module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 16/27] net/nfp: refact the resource module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 17/27] net/nfp: refact the target module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 18/27] net/nfp: add a new header file Chaoyong He 2023-08-30 2:14 ` [PATCH v2 19/27] net/nfp: refact the nsp module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 20/27] net/nfp: refact the mutex module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He 2023-08-30 2:14 ` [PATCH v2 22/27] net/nfp: add the dev module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 23/27] net/nfp: add header file for PCIe module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 24/27] net/nfp: refact the cppcore module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 25/27] net/nfp: refact the PCIe module Chaoyong He 2023-08-30 2:14 ` [PATCH v2 26/27] net/nfp: refact the cppcore and " Chaoyong He 2023-08-30 2:14 ` [PATCH v2 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 2023-09-15 9:15 ` [PATCH v3 00/27] refact the nfpcore module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 01/27] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-09-15 9:15 ` [PATCH v3 02/27] net/nfp: unify the indent coding style Chaoyong He 2023-09-15 13:40 ` Ferruh Yigit 2023-09-18 1:25 ` Chaoyong He 2023-09-18 2:22 ` Stephen Hemminger 2023-09-15 9:15 ` [PATCH v3 03/27] net/nfp: unify the type of integer variable Chaoyong He 2023-09-15 13:42 ` Ferruh Yigit 2023-09-18 1:26 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 04/27] net/nfp: remove the unneeded logic Chaoyong He 2023-09-15 9:15 ` [PATCH v3 05/27] net/nfp: standard the local variable coding style Chaoyong He 2023-09-15 9:15 ` [PATCH v3 06/27] net/nfp: adjust the log statement Chaoyong He 2023-09-15 9:15 ` [PATCH v3 07/27] net/nfp: standard the comment style Chaoyong He 2023-09-15 13:44 ` Ferruh Yigit 2023-09-18 1:28 ` Chaoyong He 2023-09-18 2:08 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 08/27] net/nfp: using the DPDK memory management API Chaoyong He 2023-09-15 13:45 ` Ferruh Yigit 2023-09-18 1:29 ` Chaoyong He 2023-09-15 9:15 ` [PATCH v3 09/27] net/nfp: standard the blank character Chaoyong He 2023-09-15 9:15 ` [PATCH v3 10/27] net/nfp: unify the guide line of header file Chaoyong He 2023-09-15 9:15 ` [PATCH v3 11/27] net/nfp: rename some parameter and variable Chaoyong He 2023-09-15 9:15 ` [PATCH v3 12/27] net/nfp: refact the hwinfo module Chaoyong He 2023-09-15 13:46 ` Ferruh Yigit 2023-09-18 1:39 ` Chaoyong He 2023-09-18 11:01 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 13/27] net/nfp: refact the nffw module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 14/27] net/nfp: refact the mip module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 15/27] net/nfp: refact the rtsym module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 16/27] net/nfp: refact the resource module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 17/27] net/nfp: refact the target module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 18/27] net/nfp: add a new header file Chaoyong He 2023-09-15 9:15 ` [PATCH v3 19/27] net/nfp: refact the nsp module Chaoyong He 2023-09-18 12:31 ` Ferruh Yigit 2023-09-18 12:36 ` Ferruh Yigit 2023-09-15 9:15 ` [PATCH v3 20/27] net/nfp: refact the mutex module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 21/27] net/nfp: rename data field to sync with kernel driver Chaoyong He 2023-09-15 9:15 ` [PATCH v3 22/27] net/nfp: add the dev module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 23/27] net/nfp: add header file for PCIe module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 24/27] net/nfp: refact the cppcore module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 25/27] net/nfp: refact the PCIe module Chaoyong He 2023-09-15 9:15 ` [PATCH v3 26/27] net/nfp: refact the cppcore and " Chaoyong He 2023-09-15 9:15 ` [PATCH v3 27/27] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 2023-09-15 13:49 ` [PATCH v3 00/27] refact the nfpcore module Ferruh Yigit 2023-09-18 2:45 ` [PATCH v4 00/26] " Chaoyong He 2023-09-18 2:45 ` [PATCH v4 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-09-18 2:45 ` [PATCH v4 02/26] net/nfp: unify the indent coding style Chaoyong He 2023-09-18 11:53 ` Niklas Söderlund 2023-09-18 2:45 ` [PATCH v4 03/26] net/nfp: unify the type of integer variable Chaoyong He 2023-09-18 2:45 ` [PATCH v4 04/26] net/nfp: remove the unneeded logic Chaoyong He 2023-09-18 2:45 ` [PATCH v4 05/26] net/nfp: standard the local variable coding style Chaoyong He 2023-09-18 2:45 ` [PATCH v4 06/26] net/nfp: adjust the log statement Chaoyong He 2023-09-18 2:45 ` [PATCH v4 07/26] net/nfp: standard the comment style Chaoyong He 2023-09-18 2:45 ` [PATCH v4 08/26] net/nfp: standard the blank character Chaoyong He 2023-09-18 2:45 ` [PATCH v4 09/26] net/nfp: unify the guide line of header file Chaoyong He 2023-09-18 2:45 ` [PATCH v4 10/26] net/nfp: rename some parameter and variable Chaoyong He 2023-09-18 2:45 ` [PATCH v4 11/26] net/nfp: refact the hwinfo module Chaoyong He 2023-09-18 2:45 ` [PATCH v4 12/26] net/nfp: refact the nffw module Chaoyong He 2023-09-18 2:45 ` [PATCH v4 13/26] net/nfp: refact the mip module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 14/26] net/nfp: refact the rtsym module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 15/26] net/nfp: refact the resource module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 16/26] net/nfp: refact the target module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 17/26] net/nfp: add a new header file Chaoyong He 2023-09-18 2:46 ` [PATCH v4 18/26] net/nfp: refact the nsp module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 19/26] net/nfp: refact the mutex module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 20/26] net/nfp: rename data field to sync with kernel driver Chaoyong He 2023-09-18 2:46 ` [PATCH v4 21/26] net/nfp: add the dev module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 22/26] net/nfp: add header file for PCIe module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 23/26] net/nfp: refact the cppcore module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 24/26] net/nfp: refact the PCIe module Chaoyong He 2023-09-18 2:46 ` [PATCH v4 25/26] net/nfp: refact the cppcore and " Chaoyong He 2023-09-18 2:46 ` [PATCH v4 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He 2023-09-19 9:54 ` [PATCH v5 00/26] refact the nfpcore module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 01/26] net/nfp: explicitly compare to null and 0 Chaoyong He 2023-09-19 9:54 ` [PATCH v5 02/26] net/nfp: unify the indent coding style Chaoyong He 2023-09-19 9:54 ` [PATCH v5 03/26] net/nfp: unify the type of integer variable Chaoyong He 2023-09-19 9:54 ` [PATCH v5 04/26] net/nfp: remove the unneeded logic Chaoyong He 2023-09-19 9:54 ` [PATCH v5 05/26] net/nfp: standard the local variable coding style Chaoyong He 2023-09-19 9:54 ` [PATCH v5 06/26] net/nfp: adjust the log statement Chaoyong He 2023-09-19 9:54 ` [PATCH v5 07/26] net/nfp: standard the comment style Chaoyong He 2023-09-19 9:54 ` [PATCH v5 08/26] net/nfp: standard the blank character Chaoyong He 2023-09-19 9:54 ` [PATCH v5 09/26] net/nfp: unify the guide line of header file Chaoyong He 2023-09-19 9:54 ` [PATCH v5 10/26] net/nfp: rename some parameter and variable Chaoyong He 2023-09-19 9:54 ` [PATCH v5 11/26] net/nfp: refact the hwinfo module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 12/26] net/nfp: refact the nffw module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 13/26] net/nfp: refact the mip module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 14/26] net/nfp: refact the rtsym module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 15/26] net/nfp: refact the resource module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 16/26] net/nfp: refact the target module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 17/26] net/nfp: add a new header file Chaoyong He 2023-09-19 9:54 ` [PATCH v5 18/26] net/nfp: refact the nsp module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 19/26] net/nfp: refact the mutex module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 20/26] net/nfp: rename data field to sync with kernel driver Chaoyong He 2023-09-19 9:54 ` [PATCH v5 21/26] net/nfp: add the dev module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 22/26] net/nfp: add header file for PCIe module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 23/26] net/nfp: refact the cppcore module Chaoyong He 2023-09-19 9:54 ` [PATCH v5 24/26] net/nfp: refact the PCIe module Chaoyong He 2023-09-19 21:18 ` [PATCH v5 00/26] refact the nfpcore module Ferruh Yigit 2023-09-20 1:55 ` Chaoyong He 2023-09-20 8:54 ` Ferruh Yigit 2023-09-20 9:59 ` Ferruh Yigit 2023-09-20 1:28 ` [PATCH v5 25/26] net/nfp: refact the cppcore and PCIe module Chaoyong He 2023-09-20 1:29 ` [PATCH v5 26/26] net/nfp: extend the usage of nfp BAR from 8 to 24 Chaoyong He
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).