Re: [PATCH v4 01/32] net/sssnic: add build and doc infrastructure
Thanks for your reply, I'll fix them next version. On 2023/9/1 19:54, David Marchand wrote: On Fri, Sep 1, 2023 at 11:35 AM wrote: From: Renyong Wan Adding minimum PMD code, doc and build infrastructure for sssnic. Signed-off-by: Steven Song Signed-off-by: Renyong Wan --- v2: * Fixed 'Title underline too short' in doc/guides/nics/sssnic.rst. * Removed error.h from including files. --- .mailmap| 5 +- MAINTAINERS | 8 doc/guides/nics/features/sssnic.ini | 9 doc/guides/nics/index.rst | 1 + doc/guides/nics/sssnic.rst | 73 + drivers/net/meson.build | 1 + drivers/net/sssnic/meson.build | 18 +++ drivers/net/sssnic/sssnic_ethdev.c | 28 +++ 8 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 doc/guides/nics/features/sssnic.ini create mode 100644 doc/guides/nics/sssnic.rst create mode 100644 drivers/net/sssnic/meson.build create mode 100644 drivers/net/sssnic/sssnic_ethdev.c diff --git a/.mailmap b/.mailmap index 864d33ee46..6fa73d3b79 100644 --- a/.mailmap +++ b/.mailmap @@ -151,7 +151,6 @@ Bao-Long Tran Bar Neuman Barak Enat Barry Cao -Bartosz Staszewski Baruch Siach Bassam Zaid AlKilani Beilei Xing This looks like some rebase damage, or at least unwanted changes. Please fix. @@ -496,7 +495,6 @@ Helin Zhang Hemant Agrawal Heng Ding Hengjian Zhang -Heng Jiang Heng Wang Henning Schild Henry Cai @@ -630,7 +628,6 @@ Jie Liu Jie Pan Jie Wang Jie Zhou -Jieqiang Wang Jijiang Liu Jilei Chen Jim Harris @@ -1156,6 +1153,7 @@ Rebecca Troy Remi Pommarel Remy Horton Renata Saiakhova +Renyong Wan Reshma Pattan Ricardo Roldan Ricardo Salveti @@ -1329,6 +1327,7 @@ Stephen Hurd Steve Capper Steven Lariau Steven Luong +Steven Song Steven Webster Steven Zou Steve Rempe diff --git a/MAINTAINERS b/MAINTAINERS index a926155f26..1e57d29aa3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -633,6 +633,13 @@ F: drivers/net/af_xdp/ F: doc/guides/nics/af_xdp.rst F: doc/guides/nics/features/af_xdp.ini +3SNIC sssnic +M: Renyong Wan +M: Steven Song +F: driver/net/sssnic/ This path is incorrect. *drivers* +F: doc/guides/nics/sssnic.rst +F: doc/guides/nics/features/sssnic.ini + Amazon ENA M: Michal Krawczyk M: Shai Brandes @@ -1793,6 +1800,7 @@ F: doc/guides/tools/img/eventdev_* F: app/test/test_event_ring.c Procinfo tool +M: Maryam Tahhan M: Reshma Pattan F: app/proc-info/ F: doc/guides/tools/proc_info.rst
Re: [PATCH 08/32] net/sssnic/base: add work queue
Hello Stephen, Thanks for your kindly review. sssnic_workq is quite different from rte_ring, it's used to maintain information of hardware work queue, like Rx work queue, Tx work queue etc. Unlike rte_ring the elements of sssnic_workq are organized in a blcok of contiguous DMA memory accessed by hardware work queue, in addition the sssnic_workq records CI(consumer index) and PI(producer index) that synchronize with hardware work queue, driver generally accesses element of sssnic_workq by PI or CI. Therefore I don't think rte_ring is suitable for sssnic_workq. On 2023/9/6 23:09, Stephen Hemminger wrote: On Tue, 29 Aug 2023 15:58:05 +0800w wrote: From: Renyong Wan Work queue is used to maintain hardware queue information by driver, it is usually used in control queue, rx queue and tx queue. Signed-off-by: Steven Song Signed-off-by: Renyong Wan Looks like this driver is reinventing rte_ring. Please don't do this. -- Regards, Renyong Wan
Please help to review sssnic PMD patches
Hi, I sent sssnic PMD patches 2 weeks ago, the CI checks are all successful, but so far no body reviewed them. I really hope sssnic PMD will be merged into release 23.11. What should I do next? The following is URL of sssnic PMD patches: DPDK - Patchwork <https://patches.dpdk.org/project/dpdk/list/?series=29409> Thanks. -- Regards, Renyong Wan
Re: [PATCH v5 00/32] Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters
Hello Stephen, SSSNIC PMD does not support primary/secondary process right now, it can only run in primary process. We are going to support multiprocessnext release. Thanks. On 2023/9/18 10:37, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:26 +0800 wrote: From: Renyong Wan The sssnic PMD (**librte_pmd_sssnic**) provides poll mode driver support for 3SNIC 9x0 serials family of Ethernet adapters. Supported NICs are: - 3S910 Dual Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port QSFP28 100GbE Ethernet adapter Features of sssnic PMD are: - Link status - Link status event - Queue start/stop - Rx interrupt - Scattered Rx - TSO - LRO - Promiscuous mode - Allmulticast mode - Unicast MAC filter - Multicast MAC filte - RSS hash - RSS key update - RSS reta update - Inner RSS - VLAN filter - VLAN offload - L3 checksum offload - L4 checksum offload - Inner L3 checksum - Inner L4 checksum - Basic stats - Extended stats - Stats per queue - Flow control - FW version - Generic flow API Does this device support primary/secondary process? -- Regards, Renyong Wan
Re: [PATCH v5 04/32] net/sssnic: initialize hardware base
Hello Stephen, hw struct is just used in control plane, I think it has little impact on performance, howerver I am going to take your advice and fix it in next version of patches. Thanks. On 2023/9/18 10:28, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:30 +0800 wrote: static int sssnic_ethdev_init(struct rte_eth_dev *ethdev) { - RTE_SET_USED(ethdev); + int ret; + struct sssnic_hw *hw; + struct sssnic_netdev *netdev; + struct rte_pci_device *pci_dev; + PMD_INIT_FUNC_TRACE(); - return -EINVAL; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + netdev = SSSNIC_ETHDEV_PRIVATE(ethdev); + pci_dev = RTE_ETH_DEV_TO_PCI(ethdev); + hw = rte_zmalloc("sssnic_hw", sizeof(struct sssnic_hw), 0); For performance you might want to use rte_zmalloc_socket() to make sure the hw structure is on the same NUMA node as PCI device. -- Regards, Renyong Wan
Re: [PATCH v5 06/32] net/sssnic/base: add message definition and utility
Hello, Stephen, data_buf is just used by control plane process, and it will not be used very frequtely, it has a little impact on IO performance. I'm not going to fix it. Thanks. On 2023/9/18 10:31, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:32 +0800 wrote: +static int +sssnic_msg_buf_alloc(struct sssnic_msg *msg, size_t size) +{ + msg->data_buf = rte_zmalloc("sssnic_msg_data", size, 1); Putting message buffer on same NUMA node as device might help performance on NUMA architecture. -- Regards, Renyong Wan
Re: [PATCH v5 07/32] net/sssnic/base: add mailbox support
Hello Stephen, I'll fix it next version. On 2023/9/18 10:32, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:33 +0800 wrote: +struct sssnic_mbox_send_ctrl1_reg { + union { + uint32_t u32; + struct { + uint32_t resvd0 : 10; + /* Destination eventq in the mgmt cpu */ + uint32_t dst_eq : 2; + /* eventq that will be informed if tx done */ + uint32_t src_eq : 2; + uint32_t dma_attr : 6; + /* mailbox message size include header and body +* must 4byte align and unit is 4byte +*/ + uint32_t tx_size : 5; + uint32_t ordering : 2; + uint32_t resvd1 : 1; + /*write result back to DMA address of sending result */ + uint32_t wb : 1; Minor nit: the comment above has odd word spacing. -- Regards, Renyong Wan
Re: [PATCH v5 08/32] net/sssnic/base: add work queue
Hello Stephen, I'll fix it next version. On 2023/9/18 10:33, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:34 +0800 wrote: +void * +sssnic_workq_consume(struct sssnic_workq *workq, uint16_t num_entries, + uint16_t *ci) +{ + void *e; + uint16_t current_ci; + + if (workq->idle_entries + num_entries > workq->num_entries) + return NULL; + + current_ci = sssnic_workq_ci_get(workq); + e = (void *)sssnic_workq_entry_get(workq, current_ci); Minor nit: cast to void * is not normally necessary in C. Compiler will do it for you. -- Regards, Renyong Wan
Re: [PATCH v5 09/32] net/sssnic/base: add control queue
Hello Stephen, The length of response_data could up to 1920 bytes. Thanks. On 2023/9/18 10:36, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:35 +0800 wrote: rte_memcpy(cmd->response_data, rte_pktmbuf_mtod(mbuf, void *), + cmd->response_len); For small sizes, regular memcpy is going to be the same or faster than rte_memcpy -- Regards, Renyong Wan
Re: [PATCH v5 03/32] net/sssnic: support probe and remove
Hello Stephen, This patch is just a minimum probe frame, it does nothing and always return error. The error check will apear in the subsequent patch([PATCH v5 04/32]), in that patch, hardware base is initialized, so secondary process check is added logically. Thanks. On 2023/9/19 0:08, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:29 +0800 wrote: +static int +sssnic_ethdev_init(struct rte_eth_dev *ethdev) +{ + RTE_SET_USED(ethdev); + PMD_INIT_FUNC_TRACE(); + + return -EINVAL; +} Since device does not support secondary process, should check and return error here. -- Regards, Renyong Wan
Re: [PATCH v5 00/32] Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters
Hello Stephen, I'll fix it in next version of patch. Thanks. On 2023/9/19 11:19, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:26 +0800 wrote: From: Renyong Wan The sssnic PMD (**librte_pmd_sssnic**) provides poll mode driver support for 3SNIC 9x0 serials family of Ethernet adapters. Supported NICs are: - 3S910 Dual Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port QSFP28 100GbE Ethernet adapter Features of sssnic PMD are: - Link status - Link status event - Queue start/stop - Rx interrupt - Scattered Rx - TSO - LRO - Promiscuous mode - Allmulticast mode - Unicast MAC filter - Multicast MAC filte - RSS hash - RSS key update - RSS reta update - Inner RSS - VLAN filter - VLAN offload - L3 checksum offload - L4 checksum offload - Inner L3 checksum - Inner L4 checksum - Basic stats - Extended stats - Stats per queue - Flow control - FW version - Generic flow API --- v2: * Fixed 'Title underline too short' in doc/guides/nics/sssnic.rst. * Removed error.h from including files. * Fixed variable 'cmd_len' is uninitialized when used. * Fixed 'EINVAL' undeclared. * Fixed wrong format of printing uint64_t. * Fixed 'mask->hdr.src_addr' will always evaluate to 'true'. v3: * Fixed dereferencing type-punned pointer in base/sssnic_mbox.c. v4: * Fixed dereferencing type-punned pointer in base/sssnic_eventq.c. * Fixed coding style issue of COMPLEX_MACRO. * Fixed coding style issue of REPEATED_WORD. v5: * Fixed rebase mistake. * Fixed incorrect path in MAINTAINERS file. --- Renyong Wan (32): net/sssnic: add build and doc infrastructure net/sssnic: add log type and log macros net/sssnic: support probe and remove net/sssnic: initialize hardware base net/sssnic: add event queue net/sssnic/base: add message definition and utility net/sssnic/base: add mailbox support net/sssnic/base: add work queue net/sssnic/base: add control queue net/sssnic: add dev configure and infos get net/sssnic: add dev MAC ops net/sssnic: support dev link status net/sssnic: support link status event net/sssnic: support Rx queue setup and release net/sssnic: support Tx queue setup and release net/sssnic: support Rx queue start and stop net/sssnic: support Tx queue start and stop net/sssnic: add Rx interrupt support net/sssnic: support dev start and stop net/sssnic: support dev close and reset net/sssnic: add allmulticast and promiscuous ops net/sssnic: add basic and extended stats ops net/sssnic: support Rx packet burst net/sssnic: support Tx packet burst net/sssnic: add RSS support net/sssnic: support dev MTU set net/sssnic: support dev queue info get net/sssnic: support dev firmware version get net/sssnic: add dev flow control ops net/sssnic: support VLAN offload and filter net/sssnic: add generic flow ops net/sssnic: add VF dev support .mailmap |2 + MAINTAINERS|7 + doc/guides/nics/features/sssnic.ini| 47 + doc/guides/nics/index.rst |1 + doc/guides/nics/sssnic.rst | 73 + drivers/net/meson.build|1 + drivers/net/sssnic/base/meson.build| 20 + drivers/net/sssnic/base/sssnic_api.c | 1943 drivers/net/sssnic/base/sssnic_api.h | 498 + drivers/net/sssnic/base/sssnic_cmd.h | 514 ++ drivers/net/sssnic/base/sssnic_ctrlq.c | 521 ++ drivers/net/sssnic/base/sssnic_ctrlq.h | 58 + drivers/net/sssnic/base/sssnic_eventq.c| 461 + drivers/net/sssnic/base/sssnic_eventq.h| 84 + drivers/net/sssnic/base/sssnic_exception.c | 116 ++ drivers/net/sssnic/base/sssnic_exception.h | 10 + drivers/net/sssnic/base/sssnic_hw.c| 486 + drivers/net/sssnic/base/sssnic_hw.h| 117 ++ drivers/net/sssnic/base/sssnic_mbox.c | 615 +++ drivers/net/sssnic/base/sssnic_mbox.h | 45 + drivers/net/sssnic/base/sssnic_misc.h | 52 + drivers/net/sssnic/base/sssnic_msg.c | 254 +++ drivers/net/sssnic/base/sssnic_msg.h | 166 ++ drivers/net/sssnic/base/sssnic_reg.h | 267 +++ drivers/net/sssnic/base/sssnic_workq.c | 141 ++ drivers/net/sssnic/base/sssnic_workq.h | 108 ++ drivers/net/sssnic/meson.build | 28 + drivers/net/sssnic/sssnic_ethdev.c | 1139 drivers/net/sssnic/sssnic_ethdev.h | 102 + drivers/net/sssnic/sssnic_ethdev_fdir.c| 1017 ++ drivers/net/sssnic/sssnic_ethdev_fdir.h| 332 drivers/net/sssnic/sssnic_ethdev_flow.c| 981 ++ drivers/net/sssnic/sssnic_ethdev_flow.h| 11 + drivers/net/sssnic/sssnic_ethdev_link.c| 209 +++ drivers/net/sssnic/sssnic_ethdev_link.h| 14 + drivers/net/sssnic/sssnic_ethdev_rss.
Re: [PATCH v5 00/32] Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters
Hello Stephen, I'll fix it in next version of patch. Thanks. On 2023/9/19 11:21, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:26 +0800 wrote: From: Renyong Wan The sssnic PMD (**librte_pmd_sssnic**) provides poll mode driver support for 3SNIC 9x0 serials family of Ethernet adapters. Supported NICs are: - 3S910 Dual Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port QSFP28 100GbE Ethernet adapter Features of sssnic PMD are: - Link status - Link status event - Queue start/stop - Rx interrupt - Scattered Rx - TSO - LRO - Promiscuous mode - Allmulticast mode - Unicast MAC filter - Multicast MAC filte - RSS hash - RSS key update - RSS reta update - Inner RSS - VLAN filter - VLAN offload - L3 checksum offload - L4 checksum offload - Inner L3 checksum - Inner L4 checksum - Basic stats - Extended stats - Stats per queue - Flow control - FW version - Generic flow API --- v2: * Fixed 'Title underline too short' in doc/guides/nics/sssnic.rst. * Removed error.h from including files. * Fixed variable 'cmd_len' is uninitialized when used. * Fixed 'EINVAL' undeclared. * Fixed wrong format of printing uint64_t. * Fixed 'mask->hdr.src_addr' will always evaluate to 'true'. v3: * Fixed dereferencing type-punned pointer in base/sssnic_mbox.c. v4: * Fixed dereferencing type-punned pointer in base/sssnic_eventq.c. * Fixed coding style issue of COMPLEX_MACRO. * Fixed coding style issue of REPEATED_WORD. v5: * Fixed rebase mistake. * Fixed incorrect path in MAINTAINERS file. --- Renyong Wan (32): net/sssnic: add build and doc infrastructure net/sssnic: add log type and log macros net/sssnic: support probe and remove net/sssnic: initialize hardware base net/sssnic: add event queue net/sssnic/base: add message definition and utility net/sssnic/base: add mailbox support net/sssnic/base: add work queue net/sssnic/base: add control queue net/sssnic: add dev configure and infos get net/sssnic: add dev MAC ops net/sssnic: support dev link status net/sssnic: support link status event net/sssnic: support Rx queue setup and release net/sssnic: support Tx queue setup and release net/sssnic: support Rx queue start and stop net/sssnic: support Tx queue start and stop net/sssnic: add Rx interrupt support net/sssnic: support dev start and stop net/sssnic: support dev close and reset net/sssnic: add allmulticast and promiscuous ops net/sssnic: add basic and extended stats ops net/sssnic: support Rx packet burst net/sssnic: support Tx packet burst net/sssnic: add RSS support net/sssnic: support dev MTU set net/sssnic: support dev queue info get net/sssnic: support dev firmware version get net/sssnic: add dev flow control ops net/sssnic: support VLAN offload and filter net/sssnic: add generic flow ops net/sssnic: add VF dev support .mailmap |2 + MAINTAINERS|7 + doc/guides/nics/features/sssnic.ini| 47 + doc/guides/nics/index.rst |1 + doc/guides/nics/sssnic.rst | 73 + drivers/net/meson.build|1 + drivers/net/sssnic/base/meson.build| 20 + drivers/net/sssnic/base/sssnic_api.c | 1943 drivers/net/sssnic/base/sssnic_api.h | 498 + drivers/net/sssnic/base/sssnic_cmd.h | 514 ++ drivers/net/sssnic/base/sssnic_ctrlq.c | 521 ++ drivers/net/sssnic/base/sssnic_ctrlq.h | 58 + drivers/net/sssnic/base/sssnic_eventq.c| 461 + drivers/net/sssnic/base/sssnic_eventq.h| 84 + drivers/net/sssnic/base/sssnic_exception.c | 116 ++ drivers/net/sssnic/base/sssnic_exception.h | 10 + drivers/net/sssnic/base/sssnic_hw.c| 486 + drivers/net/sssnic/base/sssnic_hw.h| 117 ++ drivers/net/sssnic/base/sssnic_mbox.c | 615 +++ drivers/net/sssnic/base/sssnic_mbox.h | 45 + drivers/net/sssnic/base/sssnic_misc.h | 52 + drivers/net/sssnic/base/sssnic_msg.c | 254 +++ drivers/net/sssnic/base/sssnic_msg.h | 166 ++ drivers/net/sssnic/base/sssnic_reg.h | 267 +++ drivers/net/sssnic/base/sssnic_workq.c | 141 ++ drivers/net/sssnic/base/sssnic_workq.h | 108 ++ drivers/net/sssnic/meson.build | 28 + drivers/net/sssnic/sssnic_ethdev.c | 1139 drivers/net/sssnic/sssnic_ethdev.h | 102 + drivers/net/sssnic/sssnic_ethdev_fdir.c| 1017 ++ drivers/net/sssnic/sssnic_ethdev_fdir.h| 332 drivers/net/sssnic/sssnic_ethdev_flow.c| 981 ++ drivers/net/sssnic/sssnic_ethdev_flow.h| 11 + drivers/net/sssnic/sssnic_ethdev_link.c| 209 +++ drivers/net/sssnic/sssnic_ethdev_link.h| 14 + drivers/net/sssnic/sssnic_ethdev_rss.
Re: [PATCH v5 00/32] Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters
Hello Stephen, I'll fix it in next version of patch. Thanks. On 2023/9/19 11:23, Stephen Hemminger wrote: On Mon, 4 Sep 2023 12:56:26 +0800 wrote: From: Renyong Wan The sssnic PMD (**librte_pmd_sssnic**) provides poll mode driver support for 3SNIC 9x0 serials family of Ethernet adapters. Supported NICs are: - 3S910 Dual Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port SFP28 10/25GbE Ethernet adapter - 3S920 Quad Port QSFP28 100GbE Ethernet adapter Features of sssnic PMD are: - Link status - Link status event - Queue start/stop - Rx interrupt - Scattered Rx - TSO - LRO - Promiscuous mode - Allmulticast mode - Unicast MAC filter - Multicast MAC filte - RSS hash - RSS key update - RSS reta update - Inner RSS - VLAN filter - VLAN offload - L3 checksum offload - L4 checksum offload - Inner L3 checksum - Inner L4 checksum - Basic stats - Extended stats - Stats per queue - Flow control - FW version - Generic flow API --- v2: * Fixed 'Title underline too short' in doc/guides/nics/sssnic.rst. * Removed error.h from including files. * Fixed variable 'cmd_len' is uninitialized when used. * Fixed 'EINVAL' undeclared. * Fixed wrong format of printing uint64_t. * Fixed 'mask->hdr.src_addr' will always evaluate to 'true'. v3: * Fixed dereferencing type-punned pointer in base/sssnic_mbox.c. v4: * Fixed dereferencing type-punned pointer in base/sssnic_eventq.c. * Fixed coding style issue of COMPLEX_MACRO. * Fixed coding style issue of REPEATED_WORD. v5: * Fixed rebase mistake. * Fixed incorrect path in MAINTAINERS file. --- Renyong Wan (32): net/sssnic: add build and doc infrastructure net/sssnic: add log type and log macros net/sssnic: support probe and remove net/sssnic: initialize hardware base net/sssnic: add event queue net/sssnic/base: add message definition and utility net/sssnic/base: add mailbox support net/sssnic/base: add work queue net/sssnic/base: add control queue net/sssnic: add dev configure and infos get net/sssnic: add dev MAC ops net/sssnic: support dev link status net/sssnic: support link status event net/sssnic: support Rx queue setup and release net/sssnic: support Tx queue setup and release net/sssnic: support Rx queue start and stop net/sssnic: support Tx queue start and stop net/sssnic: add Rx interrupt support net/sssnic: support dev start and stop net/sssnic: support dev close and reset net/sssnic: add allmulticast and promiscuous ops net/sssnic: add basic and extended stats ops net/sssnic: support Rx packet burst net/sssnic: support Tx packet burst net/sssnic: add RSS support net/sssnic: support dev MTU set net/sssnic: support dev queue info get net/sssnic: support dev firmware version get net/sssnic: add dev flow control ops net/sssnic: support VLAN offload and filter net/sssnic: add generic flow ops net/sssnic: add VF dev support .mailmap |2 + MAINTAINERS|7 + doc/guides/nics/features/sssnic.ini| 47 + doc/guides/nics/index.rst |1 + doc/guides/nics/sssnic.rst | 73 + drivers/net/meson.build|1 + drivers/net/sssnic/base/meson.build| 20 + drivers/net/sssnic/base/sssnic_api.c | 1943 drivers/net/sssnic/base/sssnic_api.h | 498 + drivers/net/sssnic/base/sssnic_cmd.h | 514 ++ drivers/net/sssnic/base/sssnic_ctrlq.c | 521 ++ drivers/net/sssnic/base/sssnic_ctrlq.h | 58 + drivers/net/sssnic/base/sssnic_eventq.c| 461 + drivers/net/sssnic/base/sssnic_eventq.h| 84 + drivers/net/sssnic/base/sssnic_exception.c | 116 ++ drivers/net/sssnic/base/sssnic_exception.h | 10 + drivers/net/sssnic/base/sssnic_hw.c| 486 + drivers/net/sssnic/base/sssnic_hw.h| 117 ++ drivers/net/sssnic/base/sssnic_mbox.c | 615 +++ drivers/net/sssnic/base/sssnic_mbox.h | 45 + drivers/net/sssnic/base/sssnic_misc.h | 52 + drivers/net/sssnic/base/sssnic_msg.c | 254 +++ drivers/net/sssnic/base/sssnic_msg.h | 166 ++ drivers/net/sssnic/base/sssnic_reg.h | 267 +++ drivers/net/sssnic/base/sssnic_workq.c | 141 ++ drivers/net/sssnic/base/sssnic_workq.h | 108 ++ drivers/net/sssnic/meson.build | 28 + drivers/net/sssnic/sssnic_ethdev.c | 1139 drivers/net/sssnic/sssnic_ethdev.h | 102 + drivers/net/sssnic/sssnic_ethdev_fdir.c| 1017 ++ drivers/net/sssnic/sssnic_ethdev_fdir.h| 332 drivers/net/sssnic/sssnic_ethdev_flow.c| 981 ++ drivers/net/sssnic/sssnic_ethdev_flow.h| 11 + drivers/net/sssnic/sssnic_ethdev_link.c| 209 +++ drivers/net/sssnic/sssnic_ethdev_link.h| 14 + drivers/net/sssnic/sssnic_ethdev_rss.
Re: [PATCH v7 04/15] net/xsc: add xsc dev ops to support VFIO driver
On 2025/2/5 22:43, Thomas Monjalon wrote: > 05/02/2025 15:37, Renyong Wan: >> On 2025/2/5 19:44, Thomas Monjalon wrote: >>> 28/01/2025 15:46, Renyong Wan: >>>> XSC PMD is designed to support both VFIO and private kernel drivers. >>> What's the benefit of private kernel drivers? >>> Why are they private? >> Hello Thomas, >> >> Thanks for your review. >> >> It can support the bifurcation model without unbinding the kernel >> driver, by utilizing our private kernel driver in conjunction with >> rdma-core. Currently, our kernel driver is not open-source, so it is >> considered a private kernel driver. This patch series only supports the >> VFIO driver. Our kernel driver is currently in the process of being >> open-sourced on kernel.org, and once it is available there, we also plan >> to submit the code that supports our kernel driver to DPDK. > OK that's interesting, thank you. > > I think it would be the first DPDK driver to support both VFIO or bifurcated > model. > How will we choose which one to use? With devargs? > > That's how we designed it. We designed a low-level device operations framework named xsc_dev_ops to support both VFIO drivers and kernel drivers. Each xsc_dev_ops is registered before the main function runs. During the PCI device probe phase, the XSC PMD selects the corresponding xsc_dev_ops based on rte_pci_device->driver, therefore, there is no need for devargs. Thank you. -- Best regards, Renyong Wan
Re: [PATCH v7 04/15] net/xsc: add xsc dev ops to support VFIO driver
On 2025/2/5 23:45, Thomas Monjalon wrote: > 05/02/2025 16:37, Renyong Wan: >> On 2025/2/5 22:43, Thomas Monjalon wrote: >>> 05/02/2025 15:37, Renyong Wan: >>>> On 2025/2/5 19:44, Thomas Monjalon wrote: >>>>> 28/01/2025 15:46, Renyong Wan: >>>>>> XSC PMD is designed to support both VFIO and private kernel drivers. >>>>> What's the benefit of private kernel drivers? >>>>> Why are they private? >>>> Hello Thomas, >>>> >>>> Thanks for your review. >>>> >>>> It can support the bifurcation model without unbinding the kernel >>>> driver, by utilizing our private kernel driver in conjunction with >>>> rdma-core. Currently, our kernel driver is not open-source, so it is >>>> considered a private kernel driver. This patch series only supports the >>>> VFIO driver. Our kernel driver is currently in the process of being >>>> open-sourced on kernel.org, and once it is available there, we also plan >>>> to submit the code that supports our kernel driver to DPDK. >>> OK that's interesting, thank you. >>> >>> I think it would be the first DPDK driver to support both VFIO or >>> bifurcated model. >>> How will we choose which one to use? With devargs? >>> >>> >> That's how we designed it. >> We designed a low-level device operations framework named xsc_dev_ops to >> support both VFIO drivers and kernel drivers. Each xsc_dev_ops is >> registered before the main function runs. During the PCI device probe >> phase, the XSC PMD selects the corresponding xsc_dev_ops based on >> rte_pci_device->driver, therefore, there is no need for devargs. > I don't understand. > If both VFIO and the kernel driver are loaded, > we'll scan the device twice? > Will it be probed 2 times? > > No, it won't probe twice. I suppose that each PCI device will only be bound to either the VFIO driver or a kernel driver. The drv_flags of the xsc_pmd PCI driver will not preset with RTE_PCI_DRV_NEED_MAPPING. Therefore, in the rte_pci_probe_one_driver function, rte_pci_map_device() will not be called. After entering the probe phase of the xsc PMD PCI driver, rte_pci_map_device() will be called in xsc_dev_ops->init() based on whether it is a VFIO driver. Thank you. -- Best regards, Renyong Wan
Re: [PATCH v7 04/15] net/xsc: add xsc dev ops to support VFIO driver
On 2025/2/6 0:54, David Marchand wrote: >> No, it won't probe twice. >> I suppose that each PCI device will only be bound to either the VFIO >> driver or a kernel driver. The drv_flags of the xsc_pmd PCI driver will >> not preset with RTE_PCI_DRV_NEED_MAPPING. Therefore, in the >> rte_pci_probe_one_driver function, rte_pci_map_device() will not be >> called. After entering the probe phase of the xsc PMD PCI driver, >> rte_pci_map_device() will be called in xsc_dev_ops->init() based on >> whether it is a VFIO driver. > (side note, this means that this driver should probably call > rte_pci_unmap_device() in its release path, though I see none) Hello David, You're absolutely right, thank you very much for the notice, it does seem like an oversight that rte_pci_unmap_device() is missing in the driver's release path, I will fix it in the next submission. -- Best regards, Renyong Wan
Re: [PATCH v7 04/15] net/xsc: add xsc dev ops to support VFIO driver
On 2025/2/5 19:44, Thomas Monjalon wrote: > 28/01/2025 15:46, Renyong Wan: >> XSC PMD is designed to support both VFIO and private kernel drivers. > What's the benefit of private kernel drivers? > Why are they private? > > > Hello Thomas, Thanks for your review. It can support the bifurcation model without unbinding the kernel driver, by utilizing our private kernel driver in conjunction with rdma-core. Currently, our kernel driver is not open-source, so it is considered a private kernel driver. This patch series only supports the VFIO driver. Our kernel driver is currently in the process of being open-sourced on kernel.org, and once it is available there, we also plan to submit the code that supports our kernel driver to DPDK. -- Best regards, Renyong Wan
[PATCH v7 04/15] net/xsc: add xsc dev ops to support VFIO driver
XSC PMD is designed to support both VFIO and private kernel drivers. This commit add xsc dev ops to support VFIO driver. Signed-off-by: Na Na Signed-off-by: Renyong Wan --- v7: * Delete the packed attributes of sub structures and unions. v6: * Replace __rte_packed with __rte_packed_begin and __rte_packed_end. v5: * Using RTE_ETHER_ADDR_LEN instead of numeral 6. * Initialize some local variables while be defined. * Fix compilation warnings. --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_defs.h | 8 + drivers/net/xsc/xsc_dev.h | 32 ++ drivers/net/xsc/xsc_rxtx.h | 102 + drivers/net/xsc/xsc_vfio.c | 746 5 files changed, 889 insertions(+) create mode 100644 drivers/net/xsc/xsc_rxtx.h create mode 100644 drivers/net/xsc/xsc_vfio.c diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index df4c8ea499..4e20b30438 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -10,4 +10,5 @@ sources = files( 'xsc_ethdev.c', 'xsc_dev.c', 'xsc_vfio_mbox.c', +'xsc_vfio.c', ) diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index a4b36685a6..8fd59133bc 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -16,6 +16,14 @@ #define XSC_VFREP_BASE_LOGICAL_PORT1081 +#define XSC_PF_TX_DB_ADDR 0x4802000 +#define XSC_PF_RX_DB_ADDR 0x4804000 +#define XSC_PF_CQ_DB_ADDR 0x212 + +#define XSC_VF_RX_DB_ADDR 0x8d4 +#define XSC_VF_TX_DB_ADDR 0x8d0 +#define XSC_VF_CQ_DB_ADDR 0x8c4 + enum xsc_nic_mode { XSC_NIC_MODE_LEGACY, XSC_NIC_MODE_SWITCHDEV, diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index fb97bb2230..1274f9287e 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -14,6 +14,7 @@ #include "xsc_defs.h" #include "xsc_log.h" +#include "xsc_rxtx.h" #define XSC_PPH_MODE_ARG "pph_mode" #define XSC_NIC_MODE_ARG "nic_mode" @@ -25,6 +26,18 @@ #define XSC_DEV_PCT_IDX_INVALID0x #define XSC_DEV_REPR_ID_INVALID0x7FFF +enum xsc_queue_type { + XSC_QUEUE_TYPE_RDMA_RC = 0, + XSC_QUEUE_TYPE_RDMA_MAD = 1, + XSC_QUEUE_TYPE_RAW = 2, + XSC_QUEUE_TYPE_VIRTIO_NET = 3, + XSC_QUEUE_TYPE_VIRTIO_BLK = 4, + XSC_QUEUE_TYPE_RAW_TPE = 5, + XSC_QUEUE_TYPE_RAW_TSO = 6, + XSC_QUEUE_TYPE_RAW_TX = 7, + XSC_QUEUE_TYPE_INVALID = 0xFF, +}; + struct xsc_hwinfo { uint32_t pcie_no; /* pcie number , 0 or 1 */ uint32_t func_id; /* pf glb func id */ @@ -120,6 +133,25 @@ struct xsc_dev_ops { enum rte_pci_kernel_driver kdrv; int (*dev_init)(struct xsc_dev *xdev); int (*dev_close)(struct xsc_dev *xdev); + int (*get_mac)(struct xsc_dev *xdev, uint8_t *mac); + int (*set_link_up)(struct xsc_dev *xdev); + int (*set_link_down)(struct xsc_dev *xdev); + int (*link_update)(struct xsc_dev *xdev, uint8_t funcid_type, int wait_to_complete); + int (*set_mtu)(struct xsc_dev *xdev, uint16_t mtu); + int (*destroy_qp)(void *qp); + int (*destroy_cq)(void *cq); + int (*modify_qp_status)(struct xsc_dev *xdev, + uint32_t qpn, int num, int opcode); + int (*modify_qp_qostree)(struct xsc_dev *xdev, uint16_t qpn); + + int (*rx_cq_create)(struct xsc_dev *xdev, struct xsc_rx_cq_params *cq_params, + struct xsc_rx_cq_info *cq_info); + int (*tx_cq_create)(struct xsc_dev *xdev, struct xsc_tx_cq_params *cq_params, + struct xsc_tx_cq_info *cq_info); + int (*tx_qp_create)(struct xsc_dev *xdev, struct xsc_tx_qp_params *qp_params, + struct xsc_tx_qp_info *qp_info); + int (*mailbox_exec)(struct xsc_dev *xdev, void *data_in, + int in_len, void *data_out, int out_len); }; void xsc_dev_ops_register(struct xsc_dev_ops *new_ops); diff --git a/drivers/net/xsc/xsc_rxtx.h b/drivers/net/xsc/xsc_rxtx.h new file mode 100644 index 00..1a7d621a95 --- /dev/null +++ b/drivers/net/xsc/xsc_rxtx.h @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2025 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_RXTX_H_ +#define _XSC_RXTX_H_ + +#include + +struct __rte_packed_begin xsc_wqe_data_seg { + union { + struct { + uint8_t in_line:1; + uint8_t rsv0:7; + }; + struct { + rte_le32_t rsv1:1; + rte_le32_t seg_len:31; + rte_le32_t l
[PATCH v7 03/15] net/xsc: add xsc mailbox
XSC mailbox is a mechanism used for interaction between PMD and firmware. Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- v7: * Remove the cast of xdev->dev_priv. * Remove the cast of malloc return value. --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_cmd.h | 387 ++ drivers/net/xsc/xsc_defs.h | 2 + drivers/net/xsc/xsc_vfio_mbox.c | 691 drivers/net/xsc/xsc_vfio_mbox.h | 142 +++ 5 files changed, 1223 insertions(+) create mode 100644 drivers/net/xsc/xsc_cmd.h create mode 100644 drivers/net/xsc/xsc_vfio_mbox.c create mode 100644 drivers/net/xsc/xsc_vfio_mbox.h diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 683a1f6632..df4c8ea499 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -9,4 +9,5 @@ endif sources = files( 'xsc_ethdev.c', 'xsc_dev.c', +'xsc_vfio_mbox.c', ) diff --git a/drivers/net/xsc/xsc_cmd.h b/drivers/net/xsc/xsc_cmd.h new file mode 100644 index 00..433dcd0afa --- /dev/null +++ b/drivers/net/xsc/xsc_cmd.h @@ -0,0 +1,387 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2025 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_CMD_H_ +#define _XSC_CMD_H_ + +#include +#include +#include +#include +#include + +#define XSC_BOARD_SN_LEN 32 +#define XSC_CMD_QUERY_HCA_CAP_V1 1 + +enum xsc_cmd_opcode { + XSC_CMD_OP_QUERY_HCA_CAP= 0x100, + XSC_CMD_OP_CREATE_CQ= 0x400, + XSC_CMD_OP_DESTROY_CQ = 0x401, + XSC_CMD_OP_CREATE_QP= 0x500, + XSC_CMD_OP_DESTROY_QP = 0x501, + XSC_CMD_OP_RTR2RTS_QP = 0x504, + XSC_CMD_OP_QP_2RST = 0x50A, + XSC_CMD_OP_CREATE_MULTI_QP = 0x515, + XSC_CMD_OP_MODIFY_NIC_HCA = 0x812, + XSC_CMD_OP_MODIFY_RAW_QP= 0x81f, + XSC_CMD_OP_EXEC_NP = 0x900, + XSC_CMD_OP_SET_MTU = 0x1100, + XSC_CMD_OP_QUERY_ETH_MAC= 0X1101, + XSC_CMD_OP_MAX +}; + +enum xsc_cmd_status { + XSC_CMD_SUCC = 0, + XSC_CMD_FAIL, + XSC_CMD_TIMEOUT, +}; + +struct xsc_cmd_inbox_hdr { + rte_be16_t opcode; + uint8_t rsvd[4]; + rte_be16_t ver; +}; + +struct xsc_cmd_outbox_hdr { + uint8_t status; + uint8_t rsvd[5]; + rte_be16_t ver; +}; + +struct xsc_cmd_fw_version { + uint8_t major; + uint8_t minor; + rte_be16_t patch; + rte_be32_t tweak; + uint8_t extra_flag; + uint8_t rsv[7]; +}; + +struct xsc_cmd_hca_cap { + uint8_t rsvd1[12]; + uint8_t send_seg_num; + uint8_t send_wqe_shift; + uint8_t recv_seg_num; + uint8_t recv_wqe_shift; + uint8_t log_max_srq_sz; + uint8_t log_max_qp_sz; + uint8_t log_max_mtt; + uint8_t log_max_qp; + uint8_t log_max_strq_sz; + uint8_t log_max_srqs; + uint8_t rsvd2[2]; + uint8_t log_max_tso; + uint8_t log_max_cq_sz; + uint8_t rsvd3; + uint8_t log_max_cq; + uint8_t log_max_eq_sz; + uint8_t log_max_mkey; + uint8_t log_max_msix; + uint8_t log_max_eq; + uint8_t max_indirection; + uint8_t log_max_mrw_sz; + uint8_t log_max_bsf_list_sz; + uint8_t log_max_klm_list_sz; + uint8_t rsvd4; + uint8_t log_max_ra_req_dc; + uint8_t rsvd5; + uint8_t log_max_ra_res_dc; + uint8_t rsvd6; + uint8_t log_max_ra_req_qp; + uint8_t log_max_qp_depth; + uint8_t log_max_ra_res_qp; + rte_be16_t max_vfs; + rte_be16_t raweth_qp_id_end; + rte_be16_t raw_tpe_qp_num; + rte_be16_t max_qp_count; + rte_be16_t raweth_qp_id_base; + uint8_t rsvd7; + uint8_t local_ca_ack_delay; + uint8_t max_num_eqs; + uint8_t num_ports; + uint8_t log_max_msg; + uint8_t mac_port; + rte_be16_t raweth_rss_qp_id_base; + rte_be16_t stat_rate_support; + uint8_t rsvd8[2]; + rte_be64_t flags; + uint8_t rsvd9; + uint8_t uar_sz; + uint8_t rsvd10; + uint8_t log_pg_sz; + rte_be16_t bf_log_bf_reg_size; + rte_be16_t msix_base; + rte_be16_t msix_num; + rte_be16_t max_desc_sz_sq; + uint8_t rsvd11[2]; + rte_be16_t max_desc_sz_rq; + uint8_t rsvd12[2]; + rte_be16_t max_desc_sz_sq_dc; + uint8_t rsvd13[4]; + rte_be16_t max_qp_mcg; + uint8_t rsvd14; + uint8_t log_max_mcg; + uint8_t rsvd15; + uint8_t log_max_pd; + uint8_t rsvd16; + uint8_t log_max_xrcd; + uint8_t rsvd17[40]; + rte_be32_t uar_page_sz; + uint8_t rsvd18[8]; + rte_be32_t hw_feature_flag; + rte_be16_t pf0_vf_funcid_base; + rte_be16_t pf0_vf_funcid_top; + rte_be16_t pf1_vf_funcid_base; + rte_be16_t pf1_vf_funcid_top; +
[PATCH v7 05/15] net/xsc: add PCT interfaces
PCT is the abbreviation of Packet classifier table, which is built in NP to define behavior of various packets. Signed-off-by: Renyong Wan --- v6: * Replace __rte_packed with __rte_packed_begin and __rte_packed_end. --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_defs.h | 29 +++ drivers/net/xsc/xsc_dev.c | 19 +- drivers/net/xsc/xsc_dev.h | 3 + drivers/net/xsc/xsc_np.c| 492 drivers/net/xsc/xsc_np.h| 154 +++ 6 files changed, 697 insertions(+), 1 deletion(-) create mode 100644 drivers/net/xsc/xsc_np.c create mode 100644 drivers/net/xsc/xsc_np.h diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 4e20b30438..5ee03ea835 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -11,4 +11,5 @@ sources = files( 'xsc_dev.c', 'xsc_vfio_mbox.c', 'xsc_vfio.c', +'xsc_np.c', ) diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index 8fd59133bc..b1e37a5870 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -16,6 +16,26 @@ #define XSC_VFREP_BASE_LOGICAL_PORT1081 +#define XSC_RSS_HASH_KEY_LEN 52 +#define XSC_RSS_HASH_BIT_IPV4_SIP (1ULL << 0) +#define XSC_RSS_HASH_BIT_IPV4_DIP (1ULL << 1) +#define XSC_RSS_HASH_BIT_IPV6_SIP (1ULL << 2) +#define XSC_RSS_HASH_BIT_IPV6_DIP (1ULL << 3) +#define XSC_RSS_HASH_BIT_IPV4_SPORT(1ULL << 4) +#define XSC_RSS_HASH_BIT_IPV4_DPORT(1ULL << 5) +#define XSC_RSS_HASH_BIT_IPV6_SPORT(1ULL << 6) +#define XSC_RSS_HASH_BIT_IPV6_DPORT(1ULL << 7) +#define XSC_RSS_HASH_BIT_TNL_ID(1ULL << 8) +#define XSC_RSS_HASH_BIT_NXT_PRO (1ULL << 9) + +#define XSC_EPAT_VLD_FLAG (1ULL) +#define XSC_EPAT_RX_QP_ID_OFST_FLAG(1ULL << 2) +#define XSC_EPAT_QP_NUM_FLAG (1ULL << 3) +#define XSC_EPAT_RSS_EN_FLAG (1ULL << 4) +#define XSC_EPAT_RSS_HASH_TEMPLATE_FLAG(1ULL << 5) +#define XSC_EPAT_RSS_HASH_FUNC_FLAG(1ULL << 6) +#define XSC_EPAT_HAS_PPH_FLAG (1ULL << 9) + #define XSC_PF_TX_DB_ADDR 0x4802000 #define XSC_PF_RX_DB_ADDR 0x4804000 #define XSC_PF_CQ_DB_ADDR 0x212 @@ -38,4 +58,13 @@ enum xsc_pph_type { XSC_UPLINK_PPH = 0x8, }; +enum xsc_port_type { + XSC_PORT_TYPE_NONE = 0, + XSC_PORT_TYPE_UPLINK, + XSC_PORT_TYPE_UPLINK_BOND, + XSC_PORT_TYPE_PFVF, + XSC_PORT_TYPE_PFHPF, + XSC_PORT_TYPE_UNKNOWN, +}; + #endif /* XSC_DEFS_H_ */ diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index b030eb3410..8933f77b8f 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -54,8 +54,17 @@ xsc_dev_ops_register(struct xsc_dev_ops *new_ops) } int -xsc_dev_close(struct xsc_dev *xdev, int __rte_unused repr_id) +xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, +int in_len, void *data_out, int out_len) { + return xdev->dev_ops->mailbox_exec(xdev, data_in, in_len, + data_out, out_len); +} + +int +xsc_dev_close(struct xsc_dev *xdev, int repr_id) +{ + xsc_dev_clear_pct(xdev, repr_id); return xdev->dev_ops->dev_close(xdev); } @@ -121,6 +130,7 @@ void xsc_dev_uninit(struct xsc_dev *xdev) { PMD_INIT_FUNC_TRACE(); + xsc_dev_pct_uninit(); xsc_dev_close(xdev, XSC_DEV_REPR_ID_INVALID); rte_free(xdev); } @@ -159,6 +169,13 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **xdev) goto hwinfo_init_fail; } + ret = xsc_dev_pct_init(); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to init xsc pct"); + ret = -EINVAL; + goto hwinfo_init_fail; + } + *xdev = d; return 0; diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index 1274f9287e..51cf2d15fe 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -15,6 +15,7 @@ #include "xsc_defs.h" #include "xsc_log.h" #include "xsc_rxtx.h" +#include "xsc_np.h" #define XSC_PPH_MODE_ARG "pph_mode" #define XSC_NIC_MODE_ARG "nic_mode" @@ -154,6 +155,8 @@ struct xsc_dev_ops { int in_len, void *data_out, int out_len); }; +int xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, +int in_len, void *data_out, int out_len); void xsc_dev_ops_register(struct xsc_dev_ops *new_ops); int xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev); void xsc_dev_uninit(struct xsc_dev *xdev); diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c new file mode 100644 index 00..
[PATCH v7 06/15] net/xsc: initialize xsc representors
For the design of the xsc PMD, each ethdev corresponds to a representor. Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_defs.h | 11 +++ drivers/net/xsc/xsc_dev.c| 95 drivers/net/xsc/xsc_dev.h| 3 + drivers/net/xsc/xsc_ethdev.c | 170 +++ drivers/net/xsc/xsc_ethdev.h | 19 5 files changed, 298 insertions(+) diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index b1e37a5870..111776f37e 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -6,6 +6,7 @@ #define XSC_DEFS_H_ #define XSC_PAGE_SIZE 4096 +#define XSC_PHY_PORT_NUM 1 #define XSC_PCI_VENDOR_ID 0x1f67 #define XSC_PCI_DEV_ID_MS 0x @@ -15,6 +16,7 @@ #define XSC_PCI_DEV_ID_MVS 0x1153 #define XSC_VFREP_BASE_LOGICAL_PORT1081 +#define XSC_MAX_MAC_ADDRESSES 3 #define XSC_RSS_HASH_KEY_LEN 52 #define XSC_RSS_HASH_BIT_IPV4_SIP (1ULL << 0) @@ -58,6 +60,15 @@ enum xsc_pph_type { XSC_UPLINK_PPH = 0x8, }; +enum xsc_funcid_type { + XSC_FUNCID_TYPE_INVAL = 0x0, + XSC_EMU_FUNCID = 0x1, + XSC_PHYPORT_MAC_FUNCID = 0x2, + XSC_VF_IOCTL_FUNCID = 0x3, + XSC_PHYPORT_LAG_FUNCID = 0x4, + XSC_FUNCID_TYPE_UNKNOWN = 0x5, +}; + enum xsc_port_type { XSC_PORT_TYPE_NONE = 0, XSC_PORT_TYPE_UPLINK, diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 8933f77b8f..aaf18bf8e5 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -61,6 +61,12 @@ xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, data_out, out_len); } +int +xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac) +{ + return xdev->dev_ops->get_mac(xdev, mac); +} + int xsc_dev_close(struct xsc_dev *xdev, int repr_id) { @@ -126,6 +132,95 @@ xsc_dev_args_parse(struct xsc_dev *xdev, struct rte_devargs *devargs) rte_kvargs_free(kvlist); } +int +xsc_dev_qp_set_id_get(struct xsc_dev *xdev, int repr_id) +{ + if (xsc_dev_is_vf(xdev)) + return 0; + + return (repr_id % 511 + 1); +} + +static void +xsc_repr_info_init(struct xsc_dev *xdev, struct xsc_repr_info *info, + enum xsc_port_type port_type, + enum xsc_funcid_type funcid_type, int32_t repr_id) +{ + int qp_set_id, logical_port; + struct xsc_hwinfo *hwinfo = &xdev->hwinfo; + + info->repr_id = repr_id; + info->port_type = port_type; + if (port_type == XSC_PORT_TYPE_UPLINK_BOND) { + info->pf_bond = 1; + info->funcid = XSC_PHYPORT_LAG_FUNCID << 14; + } else if (port_type == XSC_PORT_TYPE_UPLINK) { + info->pf_bond = -1; + info->funcid = funcid_type << 14; + } else if (port_type == XSC_PORT_TYPE_PFVF) { + info->funcid = funcid_type << 14; + } + + qp_set_id = xsc_dev_qp_set_id_get(xdev, repr_id); + if (xsc_dev_is_vf(xdev)) + logical_port = xdev->hwinfo.func_id + + xdev->hwinfo.funcid_to_logic_port_off; + else + logical_port = xdev->vfos_logical_in_port + qp_set_id - 1; + + info->logical_port = logical_port; + info->local_dstinfo = logical_port; + info->peer_logical_port = hwinfo->mac_phy_port; + info->peer_dstinfo = hwinfo->mac_phy_port; +} + +int +xsc_dev_repr_ports_probe(struct xsc_dev *xdev, int nb_repr_ports, int max_eth_ports) +{ + int funcid_type; + struct xsc_repr_port *repr_port; + int i; + + PMD_INIT_FUNC_TRACE(); + + xdev->num_repr_ports = nb_repr_ports + XSC_PHY_PORT_NUM; + if (xdev->num_repr_ports > max_eth_ports) { + PMD_DRV_LOG(ERR, "Repr ports num %u, should be less than max %u", + xdev->num_repr_ports, max_eth_ports); + return -EINVAL; + } + + xdev->repr_ports = rte_zmalloc(NULL, + sizeof(struct xsc_repr_port) * xdev->num_repr_ports, + RTE_CACHE_LINE_SIZE); + if (xdev->repr_ports == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate memory for repr ports"); + return -ENOMEM; + } + + funcid_type = (xdev->devargs.nic_mode == XSC_NIC_MODE_SWITCHDEV) ? + XSC_VF_IOCTL_FUNCID : XSC_PHYPORT_MAC_FUNCID; + + /* PF representor use the last repr_ports */ + repr_port = &xdev->repr_ports[xdev->num_repr_ports - 1]; + xsc_repr_info_init(xdev, &repr_port->info, XSC_PORT_TYPE_UPLINK, + XSC_PHYPORT_MAC_FUNCID, xdev->num_repr_ports - 1); + repr_port->info.ifindex = xd
[PATCH v7 01/15] net/xsc: add xsc PMD framework
Add xsc PMD framework, doc and build infrastructure, supporting PCI probe. Signed-off-by: Renyong Wan --- v7: * Change the name of Wanrenyong to Renyong Wan. v6: * Delete the included header file net/if.h. * Rebase the main branch to merge release notes. --- .mailmap | 5 ++ MAINTAINERS| 10 +++ doc/guides/nics/features/xsc.ini | 9 +++ doc/guides/nics/index.rst | 1 + doc/guides/nics/xsc.rst| 31 + doc/guides/rel_notes/release_25_03.rst | 4 ++ drivers/net/meson.build| 1 + drivers/net/xsc/meson.build| 11 drivers/net/xsc/xsc_defs.h | 15 + drivers/net/xsc/xsc_ethdev.c | 88 ++ drivers/net/xsc/xsc_ethdev.h | 15 + drivers/net/xsc/xsc_log.h | 24 +++ 12 files changed, 214 insertions(+) create mode 100644 doc/guides/nics/features/xsc.ini create mode 100644 doc/guides/nics/xsc.rst create mode 100644 drivers/net/xsc/meson.build create mode 100644 drivers/net/xsc/xsc_defs.h create mode 100644 drivers/net/xsc/xsc_ethdev.c create mode 100644 drivers/net/xsc/xsc_ethdev.h create mode 100644 drivers/net/xsc/xsc_log.h diff --git a/.mailmap b/.mailmap index ebead7f072..a0e77d45c9 100644 --- a/.mailmap +++ b/.mailmap @@ -371,6 +371,7 @@ Dongdong Liu Dongsheng Rong Dongsu Han Dong Wang +Dongwei Xu Dongyang Pan <197020...@qq.com> Dong Zhou Don Provan @@ -1065,6 +1066,7 @@ Nagadheeraj Rottela Naga Harish K S V Naga Suresh Somarowthu Nalla Pradeep +Na Na Na Na Nan Chen Nandini Persad @@ -1273,6 +1275,7 @@ Remi Pommarel Remigiusz Konca Remy Horton Renata Saiakhova +Renyong Wan Reshma Pattan Ricardo Roldan Ricardo Salveti @@ -1309,6 +1312,7 @@ Ronak Doshi Ron Beider Ronghua Zhang RongQiang Xie +Rong Qian RongQing Li Rongwei Liu Rory Sexton @@ -1689,6 +1693,7 @@ Xiaonan Zhang Xiao Wang Xiaoxiao Zeng Xiaoxin Peng +Xiaoxiong Zhang Xiaoyu Min Xiaoyun Li Xiaoyun Wang diff --git a/MAINTAINERS b/MAINTAINERS index b86cdd266b..4ee8098f10 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1075,6 +1075,16 @@ F: drivers/net/avp/ F: doc/guides/nics/avp.rst F: doc/guides/nics/features/avp.ini +Yunsilicon xsc +M: Renyong Wan +M: Na Na +M: Rong Qian +M: Xiaoxiong Zhang +M: Dongwei Xu +F: drivers/net/xsc/ +F: doc/guides/nics/xsc.rst +F: doc/guides/nics/features/xsc.ini + ZTE zxdh - EXPERIMENTAL M: Junlong Wang M: Lijie Shan diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini new file mode 100644 index 00..b5c44ce535 --- /dev/null +++ b/doc/guides/nics/features/xsc.ini @@ -0,0 +1,9 @@ +; +; Supported features of the 'xsc' network poll mode driver. +; +; Refer to default.ini for the full list of available PMD features. +; +[Features] +Linux= Y +ARMv8= Y +x86-64 = Y diff --git a/doc/guides/nics/index.rst b/doc/guides/nics/index.rst index 50688d9f64..10a2eca3b0 100644 --- a/doc/guides/nics/index.rst +++ b/doc/guides/nics/index.rst @@ -70,4 +70,5 @@ Network Interface Controller Drivers vhost virtio vmxnet3 +xsc zxdh diff --git a/doc/guides/nics/xsc.rst b/doc/guides/nics/xsc.rst new file mode 100644 index 00..8e189db541 --- /dev/null +++ b/doc/guides/nics/xsc.rst @@ -0,0 +1,31 @@ +.. SPDX-License-Identifier: BSD-3-Clause +Copyright 2024 Yunsilicon Technology Co., Ltd + +XSC Poll Mode Driver +== + +The xsc PMD (**librte_net_xsc**) provides poll mode driver support for +10/25/50/100/200 Gbps Yunsilicon metaScale Series Network Adapters. + +Supported NICs +-- + +The following Yunsilicon device models are supported by the same xsc driver: + + - metaScale-200S + - metaScale-200 + - metaScale-100Q + - metaScale-50 + +Prerequisites +-- + +- Follow the DPDK :ref:`Getting Started Guide for Linux ` to setup the basic DPDK environment. + +- Learning about Yunsilicon metaScale Series NICs using + `<https://www.yunsilicon.com/#/productInformation>`_. + +Limitations or Known issues +--- +32bit ARCHs are not supported. +Windows and BSD are not supported yet. diff --git a/doc/guides/rel_notes/release_25_03.rst b/doc/guides/rel_notes/release_25_03.rst index 931fe98879..3710493aad 100644 --- a/doc/guides/rel_notes/release_25_03.rst +++ b/doc/guides/rel_notes/release_25_03.rst @@ -72,6 +72,10 @@ New Features * Added support for virtual function VF (ngbe_vf). +* **Added Yunsilicon xsc net driver [EXPERIMENTAL].** + + * Added the PMD for Yunsilicon metaScale serials NICs. + Removed Items - diff --git a/drivers/net/meson.build b/drivers/net/meson.build index dafd637ba4..c1ca7b0b39 100644 --- a/drivers/net/meson.build +++ b/drivers/net/meson.build @@ -63,6 +63,7 @@ drivers = [ 'vhost',
[PATCH v7 02/15] net/xsc: add xsc device initialization
XSC device is a hardware abstract level device serving as a handle to interact with hardware. Signed-off-by: Renyong Wan --- v7: * Define the size of xdev->name to PCI_PRI_STR_SIZE. v5: * Fix coding style issue with misspelling * Rearrange the elements in struct xsc_hwinfo to reduce holes --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_defs.h | 16 drivers/net/xsc/xsc_dev.c| 181 +++ drivers/net/xsc/xsc_dev.h| 131 + drivers/net/xsc/xsc_ethdev.c | 16 +++- drivers/net/xsc/xsc_ethdev.h | 3 + 6 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 drivers/net/xsc/xsc_dev.c create mode 100644 drivers/net/xsc/xsc_dev.h diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 84a09a23de..683a1f6632 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -8,4 +8,5 @@ endif sources = files( 'xsc_ethdev.c', +'xsc_dev.c', ) diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index 7c91d3443f..60244425cd 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -12,4 +12,20 @@ #define XSC_PCI_DEV_ID_MVHVF 0x1152 #define XSC_PCI_DEV_ID_MVS 0x1153 +#define XSC_VFREP_BASE_LOGICAL_PORT1081 + +enum xsc_nic_mode { + XSC_NIC_MODE_LEGACY, + XSC_NIC_MODE_SWITCHDEV, + XSC_NIC_MODE_SOC, +}; + +enum xsc_pph_type { + XSC_PPH_NONE= 0, + XSC_RX_PPH = 0x1, + XSC_TX_PPH = 0x2, + XSC_VFREP_PPH = 0x4, + XSC_UPLINK_PPH = 0x8, +}; + #endif /* XSC_DEFS_H_ */ diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c new file mode 100644 index 00..b030eb3410 --- /dev/null +++ b/drivers/net/xsc/xsc_dev.c @@ -0,0 +1,181 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2025 Yunsilicon Technology Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "xsc_log.h" +#include "xsc_defs.h" +#include "xsc_dev.h" + +#define XSC_DEV_DEF_FLOW_MODE 7 + +TAILQ_HEAD(xsc_dev_ops_list, xsc_dev_ops); +static struct xsc_dev_ops_list dev_ops_list = TAILQ_HEAD_INITIALIZER(dev_ops_list); + +static const struct xsc_dev_ops * +xsc_dev_ops_get(enum rte_pci_kernel_driver kdrv) +{ + const struct xsc_dev_ops *ops; + + TAILQ_FOREACH(ops, &dev_ops_list, entry) { + if (ops->kdrv == kdrv) + return ops; + } + + return NULL; +} + +void +xsc_dev_ops_register(struct xsc_dev_ops *new_ops) +{ + struct xsc_dev_ops *ops; + + TAILQ_FOREACH(ops, &dev_ops_list, entry) { + if (ops->kdrv == new_ops->kdrv) { + PMD_DRV_LOG(ERR, "xsc dev ops exists, kdrv=%d", new_ops->kdrv); + return; + } + } + + TAILQ_INSERT_TAIL(&dev_ops_list, new_ops, entry); +} + +int +xsc_dev_close(struct xsc_dev *xdev, int __rte_unused repr_id) +{ + return xdev->dev_ops->dev_close(xdev); +} + +static int +xsc_dev_alloc_vfos_info(struct xsc_dev *xdev) +{ + struct xsc_hwinfo *hwinfo; + int base_lp = 0; + + if (xsc_dev_is_vf(xdev)) + return 0; + + hwinfo = &xdev->hwinfo; + if (hwinfo->pcie_no == 1) { + xdev->vfrep_offset = hwinfo->func_id - + hwinfo->pcie1_pf_funcid_base + + hwinfo->pcie0_pf_funcid_top - + hwinfo->pcie0_pf_funcid_base + 1; + } else { + xdev->vfrep_offset = hwinfo->func_id - hwinfo->pcie0_pf_funcid_base; + } + + base_lp = XSC_VFREP_BASE_LOGICAL_PORT; + if (xdev->devargs.nic_mode == XSC_NIC_MODE_LEGACY) + base_lp += xdev->vfrep_offset; + xdev->vfos_logical_in_port = base_lp; + return 0; +} + +static void +xsc_dev_args_parse(struct xsc_dev *xdev, struct rte_devargs *devargs) +{ + struct rte_kvargs *kvlist; + struct xsc_devargs *xdevargs = &xdev->devargs; + const char *tmp; + + kvlist = rte_kvargs_parse(devargs->args, NULL); + if (kvlist == NULL) + return; + + tmp = rte_kvargs_get(kvlist, XSC_PPH_MODE_ARG); + if (tmp != NULL) + xdevargs->pph_mode = atoi(tmp); + else + xdevargs->pph_mode = XSC_PPH_NONE; + + tmp = rte_kvargs_get(kvlist, XSC_NIC_MODE_ARG); + if (tmp != NULL) + xdevargs->nic_mode = atoi(tmp); + else + xdevargs->nic_mode = XSC_NIC_MODE_LEGACY; + + tmp = rte_kvargs_get(kvlist, XSC_FLOW_MODE_ARG); + if (tmp != NULL) + xdevargs->flow_mode = atoi(tmp); + else +
[PATCH v7 07/15] net/xsc: add ethdev configure and RSS ops
Implement xsc ethdev configure and RSS hash functions. Signed-off-by: Renyong Wan --- v6: * Use memcpy instead of rte_memcpy. v5: * Remove some unnecessary parameter checks. --- doc/guides/nics/features/xsc.ini | 3 ++ drivers/net/xsc/xsc_defs.h | 15 ++ drivers/net/xsc/xsc_dev.c| 26 ++ drivers/net/xsc/xsc_dev.h| 1 + drivers/net/xsc/xsc_ethdev.c | 82 drivers/net/xsc/xsc_ethdev.h | 7 +++ 6 files changed, 134 insertions(+) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index b5c44ce535..bdeb7a984b 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -4,6 +4,9 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +RSS hash = Y +RSS key update = Y +RSS reta update = Y Linux= Y ARMv8= Y x86-64 = Y diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index 111776f37e..c445eadca1 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -78,4 +78,19 @@ enum xsc_port_type { XSC_PORT_TYPE_UNKNOWN, }; +enum xsc_tbm_cap { + XSC_TBM_CAP_HASH_PPH = 0, + XSC_TBM_CAP_RSS, + XSC_TBM_CAP_PP_BYPASS, + XSC_TBM_CAP_PCT_DROP_CONFIG, +}; + +enum xsc_rss_hf { + XSC_RSS_HASH_KEY_UPDATE = 0, + XSC_RSS_HASH_TEMP_UPDATE, + XSC_RSS_HASH_FUNC_UPDATE, + XSC_RSS_RXQ_UPDATE, + XSC_RSS_RXQ_DROP, +}; + #endif /* XSC_DEFS_H_ */ diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index aaf18bf8e5..74d577c7d0 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -19,6 +19,7 @@ #include "xsc_log.h" #include "xsc_defs.h" #include "xsc_dev.h" +#include "xsc_cmd.h" #define XSC_DEV_DEF_FLOW_MODE 7 @@ -74,6 +75,31 @@ xsc_dev_close(struct xsc_dev *xdev, int repr_id) return xdev->dev_ops->dev_close(xdev); } +int +xsc_dev_rss_key_modify(struct xsc_dev *xdev, uint8_t *rss_key, uint8_t rss_key_len) +{ + struct xsc_cmd_modify_nic_hca_mbox_in in = {}; + struct xsc_cmd_modify_nic_hca_mbox_out out = {}; + uint8_t rss_caps_mask = 0; + int ret, key_len = 0; + + in.hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_MODIFY_NIC_HCA); + + key_len = RTE_MIN(rss_key_len, XSC_RSS_HASH_KEY_LEN); + rte_memcpy(in.rss.hash_key, rss_key, key_len); + rss_caps_mask |= RTE_BIT32(XSC_RSS_HASH_KEY_UPDATE); + + in.rss.caps_mask = rss_caps_mask; + in.rss.rss_en = 1; + in.nic.caps_mask = rte_cpu_to_be_16(RTE_BIT32(XSC_TBM_CAP_RSS)); + in.nic.caps = in.nic.caps_mask; + + ret = xsc_dev_mailbox_exec(xdev, &in, sizeof(in), &out, sizeof(out)); + if (ret != 0 || out.hdr.status != 0) + return -1; + return 0; +} + static int xsc_dev_alloc_vfos_info(struct xsc_dev *xdev) { diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index d317ec9d3a..36b92a334b 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -162,6 +162,7 @@ int xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev); void xsc_dev_uninit(struct xsc_dev *xdev); int xsc_dev_close(struct xsc_dev *xdev, int repr_id); int xsc_dev_repr_ports_probe(struct xsc_dev *xdev, int nb_repr_ports, int max_eth_ports); +int xsc_dev_rss_key_modify(struct xsc_dev *xdev, uint8_t *rss_key, uint8_t rss_key_len); bool xsc_dev_is_vf(struct xsc_dev *xdev); int xsc_dev_qp_set_id_get(struct xsc_dev *xdev, int repr_id); int xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac); diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 223719ab90..60343f0081 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -8,6 +8,81 @@ #include "xsc_defs.h" #include "xsc_ethdev.h" +static int +xsc_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev, +struct rte_eth_rss_conf *rss_conf) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + if (rss_conf->rss_key != NULL && rss_conf->rss_key_len >= priv->rss_conf.rss_key_len) + memcpy(rss_conf->rss_key, priv->rss_conf.rss_key, priv->rss_conf.rss_key_len); + + rss_conf->rss_key_len = priv->rss_conf.rss_key_len; + rss_conf->rss_hf = priv->rss_conf.rss_hf; + return 0; +} + +static int +xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev, + struct rte_eth_rss_conf *rss_conf) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + int ret = 0; + + ret = xsc_dev_rss_key_modify(priv->xdev, rss_conf->rss_key, rss_conf->rss_key_len); + if (ret == 0) { + memcpy(priv->rss_conf.rss_key, rss_conf->rss_key, + priv->rss_co
[PATCH v7 08/15] net/xsc: add Rx and Tx queue setup
Implement xsc ethdev Rx and Tx queue setup functions. Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- v7: * Delete the packed attributes of sub structures and unions. v6: * Replace __rte_packed with __rte_packed_begin and __rte_packed_end. --- drivers/net/xsc/xsc_defs.h | 4 ++ drivers/net/xsc/xsc_ethdev.c | 83 drivers/net/xsc/xsc_rx.h | 59 + drivers/net/xsc/xsc_rxtx.h | 49 + drivers/net/xsc/xsc_tx.h | 55 5 files changed, 250 insertions(+) create mode 100644 drivers/net/xsc/xsc_rx.h create mode 100644 drivers/net/xsc/xsc_tx.h diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index c445eadca1..6497b53e1e 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -38,6 +38,10 @@ #define XSC_EPAT_RSS_HASH_FUNC_FLAG(1ULL << 6) #define XSC_EPAT_HAS_PPH_FLAG (1ULL << 9) +#define XSC_MAX_DESC_NUMBER1024 +#define XSC_SEND_WQE_DS3 +#define XSC_ESEG_EXTRA_DATA_SIZE 48u + #define XSC_PF_TX_DB_ADDR 0x4802000 #define XSC_PF_RX_DB_ADDR 0x4804000 #define XSC_PF_CQ_DB_ADDR 0x212 diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 60343f0081..2b0907bb2e 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -7,6 +7,8 @@ #include "xsc_log.h" #include "xsc_defs.h" #include "xsc_ethdev.h" +#include "xsc_rx.h" +#include "xsc_tx.h" static int xsc_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev, @@ -83,6 +85,85 @@ xsc_ethdev_configure(struct rte_eth_dev *dev) return -rte_errno; } +static int +xsc_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, + uint32_t socket, const struct rte_eth_rxconf *conf, + struct rte_mempool *mp) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_rxq_data *rxq_data = NULL; + uint16_t desc_n; + uint16_t rx_free_thresh; + uint64_t offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads; + + desc = (desc > XSC_MAX_DESC_NUMBER) ? XSC_MAX_DESC_NUMBER : desc; + desc_n = desc; + + if (!rte_is_power_of_2(desc)) + desc_n = 1 << rte_log2_u32(desc); + + rxq_data = rte_malloc_socket(NULL, sizeof(*rxq_data) + desc_n * sizeof(struct rte_mbuf *), +RTE_CACHE_LINE_SIZE, socket); + if (rxq_data == NULL) { + PMD_DRV_LOG(ERR, "Port %u create rxq idx %d failure", + dev->data->port_id, idx); + rte_errno = ENOMEM; + return -rte_errno; + } + rxq_data->idx = idx; + rxq_data->priv = priv; + (*priv->rxqs)[idx] = rxq_data; + + rx_free_thresh = (conf->rx_free_thresh) ? conf->rx_free_thresh : XSC_RX_FREE_THRESH; + rxq_data->rx_free_thresh = rx_free_thresh; + + rxq_data->elts = (struct rte_mbuf *(*)[desc_n])(rxq_data + 1); + rxq_data->mp = mp; + rxq_data->socket = socket; + + rxq_data->csum = !!(offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM); + rxq_data->hw_timestamp = !!(offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP); + rxq_data->crc_present = 0; + + rxq_data->wqe_n = rte_log2_u32(desc_n); + rxq_data->wqe_s = desc_n; + rxq_data->wqe_m = desc_n - 1; + + rxq_data->port_id = dev->data->port_id; + dev->data->rx_queues[idx] = rxq_data; + return 0; +} + +static int +xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, + uint32_t socket, const struct rte_eth_txconf *conf) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq; + uint16_t desc_n; + + desc = (desc > XSC_MAX_DESC_NUMBER) ? XSC_MAX_DESC_NUMBER : desc; + desc_n = desc; + + if (!rte_is_power_of_2(desc)) + desc_n = 1 << rte_log2_u32(desc); + + txq = rte_malloc_socket(NULL, sizeof(*txq) + desc_n * sizeof(struct rte_mbuf *), + RTE_CACHE_LINE_SIZE, socket); + txq->offloads = conf->offloads | dev->data->dev_conf.txmode.offloads; + txq->priv = priv; + txq->socket = socket; + + txq->elts_n = rte_log2_u32(desc_n); + txq->elts_s = desc_n; + txq->elts_m = desc_n - 1; + txq->port_id = dev->data->port_id; + txq->idx = idx; + + (*priv->txqs)[idx] = txq; + return 0; +} + static int xsc_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index) { @@ -111,6 +192,8 @@ xsc_ethdev_ma
[PATCH v7 09/15] net/xsc: add ethdev start
Implement xsc ethdev start function. Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- v5: * Remove unnecessary call of rte_wmb. --- drivers/net/xsc/meson.build | 2 + drivers/net/xsc/xsc_dev.c| 33 drivers/net/xsc/xsc_dev.h| 8 + drivers/net/xsc/xsc_ethdev.c | 172 + drivers/net/xsc/xsc_ethdev.h | 19 +++ drivers/net/xsc/xsc_rx.c | 291 +++ drivers/net/xsc/xsc_rx.h | 3 + drivers/net/xsc/xsc_rxtx.h | 27 drivers/net/xsc/xsc_tx.c | 93 +++ drivers/net/xsc/xsc_tx.h | 4 + 10 files changed, 652 insertions(+) create mode 100644 drivers/net/xsc/xsc_rx.c create mode 100644 drivers/net/xsc/xsc_tx.c diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 5ee03ea835..79664374e3 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -12,4 +12,6 @@ sources = files( 'xsc_vfio_mbox.c', 'xsc_vfio.c', 'xsc_np.c', +'xsc_rx.c', +'xsc_tx.c', ) diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 74d577c7d0..054a08bf84 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -68,6 +68,39 @@ xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac) return xdev->dev_ops->get_mac(xdev, mac); } +int +xsc_dev_modify_qp_status(struct xsc_dev *xdev, uint32_t qpn, int num, int opcode) +{ + return xdev->dev_ops->modify_qp_status(xdev, qpn, num, opcode); +} + +int +xsc_dev_modify_qp_qostree(struct xsc_dev *xdev, uint16_t qpn) +{ + return xdev->dev_ops->modify_qp_qostree(xdev, qpn); +} + +int +xsc_dev_rx_cq_create(struct xsc_dev *xdev, struct xsc_rx_cq_params *cq_params, +struct xsc_rx_cq_info *cq_info) +{ + return xdev->dev_ops->rx_cq_create(xdev, cq_params, cq_info); +} + +int +xsc_dev_tx_cq_create(struct xsc_dev *xdev, struct xsc_tx_cq_params *cq_params, +struct xsc_tx_cq_info *cq_info) +{ + return xdev->dev_ops->tx_cq_create(xdev, cq_params, cq_info); +} + +int +xsc_dev_tx_qp_create(struct xsc_dev *xdev, struct xsc_tx_qp_params *qp_params, +struct xsc_tx_qp_info *qp_info) +{ + return xdev->dev_ops->tx_qp_create(xdev, qp_params, qp_info); +} + int xsc_dev_close(struct xsc_dev *xdev, int repr_id) { diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index 36b92a334b..fafe53f752 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -158,6 +158,14 @@ struct xsc_dev_ops { int xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, int in_len, void *data_out, int out_len); void xsc_dev_ops_register(struct xsc_dev_ops *new_ops); +int xsc_dev_modify_qp_status(struct xsc_dev *xdev, uint32_t qpn, int num, int opcode); +int xsc_dev_modify_qp_qostree(struct xsc_dev *xdev, uint16_t qpn); +int xsc_dev_rx_cq_create(struct xsc_dev *xdev, struct xsc_rx_cq_params *cq_params, +struct xsc_rx_cq_info *cq_info); +int xsc_dev_tx_cq_create(struct xsc_dev *xdev, struct xsc_tx_cq_params *cq_params, +struct xsc_tx_cq_info *cq_info); +int xsc_dev_tx_qp_create(struct xsc_dev *xdev, struct xsc_tx_qp_params *qp_params, +struct xsc_tx_qp_info *qp_info); int xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev); void xsc_dev_uninit(struct xsc_dev *xdev); int xsc_dev_close(struct xsc_dev *xdev, int repr_id); diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 2b0907bb2e..24ee1e2cdc 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -9,6 +9,8 @@ #include "xsc_ethdev.h" #include "xsc_rx.h" #include "xsc_tx.h" +#include "xsc_dev.h" +#include "xsc_cmd.h" static int xsc_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev, @@ -85,6 +87,175 @@ xsc_ethdev_configure(struct rte_eth_dev *dev) return -rte_errno; } +static int +xsc_ethdev_enable(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_hwinfo *hwinfo; + int peer_dstinfo = 0; + int peer_logicalport = 0; + int logical_port = 0; + int local_dstinfo = 0; + int pcie_logic_port = 0; + int qp_set_id; + int repr_id; + struct xsc_rxq_data *rxq = xsc_rxq_get(priv, 0); + uint16_t rx_qpn = (uint16_t)rxq->qpn; + int i, vld; + struct xsc_txq_data *txq; + struct xsc_repr_port *repr; + struct xsc_repr_info *repr_info; + + if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID) + return -ENODEV; + + hwinfo = &priv->xdev->hwinfo; + repr_id = priv->representor_id; + repr = &priv->xdev->repr_ports[repr_id]; + repr_info = &repr-
[PATCH v7 13/15] net/xsc: add basic stats ops
Implement xsc ethdev basic statatics ops. Signed-off-by: Renyong Wan --- v6: * Remove unnecessary paren. * Add the feature of stats per queue in xsc.ini. --- doc/guides/nics/features/xsc.ini | 2 + drivers/net/xsc/xsc_ethdev.c | 75 2 files changed, 77 insertions(+) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index 772c6418c4..56e38a27d8 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -11,6 +11,8 @@ L3 checksum offload = Y L4 checksum offload = Y Inner L3 checksum= Y Inner L4 checksum= Y +Basic stats = Y +Stats per queue = Y Linux= Y ARMv8= Y x86-64 = Y diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index d344714d79..63c64ce547 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -443,6 +443,79 @@ xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, return 0; } +static int +xsc_ethdev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint32_t rxqs_n = priv->num_rq; + uint32_t txqs_n = priv->num_sq; + uint32_t i, idx; + struct xsc_rxq_data *rxq; + struct xsc_txq_data *txq; + + for (i = 0; i < rxqs_n; ++i) { + rxq = xsc_rxq_get(priv, i); + if (unlikely(rxq == NULL)) + continue; + + idx = rxq->idx; + if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_ipackets[idx] += rxq->stats.rx_pkts; + stats->q_ibytes[idx] += rxq->stats.rx_bytes; + stats->q_errors[idx] += rxq->stats.rx_errors + + rxq->stats.rx_nombuf; + } + stats->ipackets += rxq->stats.rx_pkts; + stats->ibytes += rxq->stats.rx_bytes; + stats->ierrors += rxq->stats.rx_errors; + stats->rx_nombuf += rxq->stats.rx_nombuf; + } + + for (i = 0; i < txqs_n; ++i) { + txq = xsc_txq_get(priv, i); + if (unlikely(txq == NULL)) + continue; + + idx = txq->idx; + if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_opackets[idx] += txq->stats.tx_pkts; + stats->q_obytes[idx] += txq->stats.tx_bytes; + stats->q_errors[idx] += txq->stats.tx_errors; + } + stats->opackets += txq->stats.tx_pkts; + stats->obytes += txq->stats.tx_bytes; + stats->oerrors += txq->stats.tx_errors; + } + + return 0; +} + +static int +xsc_ethdev_stats_reset(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint32_t rxqs_n = priv->num_rq; + uint32_t txqs_n = priv->num_sq; + uint32_t i; + struct xsc_rxq_data *rxq; + struct xsc_txq_data *txq; + + for (i = 0; i < rxqs_n; ++i) { + rxq = xsc_rxq_get(priv, i); + if (unlikely(rxq == NULL)) + continue; + memset(&rxq->stats, 0, sizeof(struct xsc_rxq_stats)); + } + for (i = 0; i < txqs_n; ++i) { + txq = xsc_txq_get(priv, i); + if (unlikely(txq == NULL)) + continue; + memset(&txq->stats, 0, sizeof(struct xsc_txq_stats)); + } + + return 0; +} + static int xsc_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index) { @@ -474,6 +547,8 @@ const struct eth_dev_ops xsc_eth_dev_ops = { .dev_start = xsc_ethdev_start, .dev_stop = xsc_ethdev_stop, .dev_close = xsc_ethdev_close, + .stats_get = xsc_ethdev_stats_get, + .stats_reset = xsc_ethdev_stats_reset, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, .rx_queue_release = xsc_ethdev_rxq_release, -- 2.25.1
[PATCH v7 11/15] net/xsc: add ethdev Rx burst
Implement xsc ethdev Rx burst function. Signed-off-by: Xiaoxiong Zhang Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_ethdev.c | 3 + drivers/net/xsc/xsc_rx.c | 174 +++ drivers/net/xsc/xsc_rx.h | 1 + drivers/net/xsc/xsc_rxtx.h | 13 +++ 4 files changed, 191 insertions(+) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 0f5a6c3ba2..ebc62fd33c 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -309,6 +309,9 @@ xsc_ethdev_start(struct rte_eth_dev *dev) } dev->data->dev_started = 1; + + dev->rx_pkt_burst = xsc_rx_burst; + ret = xsc_ethdev_enable(dev); return 0; diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index 2081f3b619..58a9cc2f26 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -13,6 +13,180 @@ #define XSC_MAX_RECV_LEN 9800 +static inline void +xsc_cq_to_mbuf(struct xsc_rxq_data *rxq, struct rte_mbuf *pkt, + volatile struct xsc_cqe *cqe) +{ + uint32_t rss_hash_res = 0; + + pkt->port = rxq->port_id; + if (rxq->rss_hash) { + rss_hash_res = rte_be_to_cpu_32(cqe->vni); + if (rss_hash_res) { + pkt->hash.rss = rss_hash_res; + pkt->ol_flags |= RTE_MBUF_F_RX_RSS_HASH; + } + } +} + +static inline int +xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct xsc_cqe *cqe) +{ + int len; + + do { + len = 0; + int ret; + + ret = xsc_check_cqe_own(cqe, rxq->cqe_n, rxq->cq_ci); + if (unlikely(ret != XSC_CQE_OWNER_SW)) { + if (unlikely(ret == XSC_CQE_OWNER_ERR)) { + ++rxq->stats.rx_errors; + if (ret == XSC_CQE_OWNER_HW || ret == -1) + return 0; + } else { + return 0; + } + } + + rxq->cq_ci += 1; + len = rte_le_to_cpu_32(cqe->msg_len); + return len; + } while (1); +} + +static __rte_always_inline void +xsc_pkt_info_sync(struct rte_mbuf *rep, struct rte_mbuf *seg) +{ + if (rep != NULL && seg != NULL) { + rep->data_len = seg->data_len; + rep->pkt_len = seg->pkt_len; + rep->data_off = seg->data_off; + rep->port = seg->port; + } +} + +uint16_t +xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) +{ + struct xsc_rxq_data *rxq = dpdk_rxq; + const uint32_t wqe_m = rxq->wqe_m; + const uint32_t cqe_m = rxq->cqe_m; + const uint32_t sge_n = rxq->sge_n; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *seg = NULL; + volatile struct xsc_cqe *cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_m]; + uint32_t nb_pkts = 0; + uint64_t nb_bytes = 0; + uint32_t rq_ci = rxq->rq_ci; + int len = 0; + uint32_t cq_ci_two = 0; + int valid_cqe_num = 0; + int cqe_msg_len = 0; + volatile struct xsc_cqe_u64 *cqe_u64 = NULL; + struct rte_mbuf *rep; + + while (pkts_n) { + uint32_t idx = rq_ci & wqe_m; + volatile struct xsc_wqe_data_seg *wqe = + &((volatile struct xsc_wqe_data_seg *)rxq->wqes)[idx << sge_n]; + + seg = (*rxq->elts)[idx]; + rte_prefetch0(cqe); + rte_prefetch0(wqe); + + rep = rte_mbuf_raw_alloc(seg->pool); + if (unlikely(rep == NULL)) { + ++rxq->stats.rx_nombuf; + break; + } + + if (!pkt) { + if (valid_cqe_num) { + cqe = cqe + 1; + len = cqe_msg_len; + valid_cqe_num = 0; + } else if ((rxq->cq_ci % 2 == 0) && (pkts_n > 1)) { + cq_ci_two = (rxq->cq_ci & rxq->cqe_m) / 2; + cqe_u64 = &(*rxq->cqes_u64)[cq_ci_two]; + cqe = (volatile struct xsc_cqe *)cqe_u64; + len = xsc_rx_poll_len(rxq, cqe); + if (len > 0) { + cqe_msg_len = xsc_rx_poll_len(rxq, cqe + 1); + if (cqe_msg_len > 0) + valid_cqe_num = 1; + } + } else { + cqe = &(*rxq->cqes)[rxq->cq_ci & rxq->cqe_m]; +
[PATCH v7 10/15] net/xsc: add ethdev stop and close
Implement xsc ethdev close and stop functions. Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_dev.c| 12 drivers/net/xsc/xsc_dev.h| 2 + drivers/net/xsc/xsc_ethdev.c | 108 +++ drivers/net/xsc/xsc_rx.c | 47 +++ drivers/net/xsc/xsc_rx.h | 2 + drivers/net/xsc/xsc_tx.c | 33 +++ drivers/net/xsc/xsc_tx.h | 2 + 7 files changed, 206 insertions(+) diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 054a08bf84..350a1fbc70 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -68,6 +68,18 @@ xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac) return xdev->dev_ops->get_mac(xdev, mac); } +int +xsc_dev_destroy_qp(struct xsc_dev *xdev, void *qp) +{ + return xdev->dev_ops->destroy_qp(qp); +} + +int +xsc_dev_destroy_cq(struct xsc_dev *xdev, void *cq) +{ + return xdev->dev_ops->destroy_cq(cq); +} + int xsc_dev_modify_qp_status(struct xsc_dev *xdev, uint32_t qpn, int num, int opcode) { diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index fafe53f752..c0a4d57af7 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -158,6 +158,8 @@ struct xsc_dev_ops { int xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, int in_len, void *data_out, int out_len); void xsc_dev_ops_register(struct xsc_dev_ops *new_ops); +int xsc_dev_destroy_qp(struct xsc_dev *xdev, void *qp); +int xsc_dev_destroy_cq(struct xsc_dev *xdev, void *cq); int xsc_dev_modify_qp_status(struct xsc_dev *xdev, uint32_t qpn, int num, int opcode); int xsc_dev_modify_qp_qostree(struct xsc_dev *xdev, uint16_t qpn); int xsc_dev_rx_cq_create(struct xsc_dev *xdev, struct xsc_rx_cq_params *cq_params, diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 24ee1e2cdc..0f5a6c3ba2 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -87,6 +87,44 @@ xsc_ethdev_configure(struct rte_eth_dev *dev) return -rte_errno; } +static void +xsc_ethdev_txq_release(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq_data = xsc_txq_get(priv, idx); + + if (txq_data == NULL) + return; + + xsc_dev_set_qpsetid(priv->xdev, txq_data->qpn, 0); + xsc_txq_obj_release(priv->xdev, txq_data); + rte_free(txq_data->fcqs); + txq_data->fcqs = NULL; + xsc_txq_elts_free(txq_data); + rte_free(txq_data); + (*priv->txqs)[idx] = NULL; + + dev->data->tx_queues[idx] = NULL; + dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED; +} + +static void +xsc_ethdev_rxq_release(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_rxq_data *rxq_data = xsc_rxq_get(priv, idx); + + if (rxq_data == NULL) + return; + xsc_rxq_rss_obj_release(priv->xdev, rxq_data); + xsc_rxq_elts_free(rxq_data); + rte_free(rxq_data); + (*priv->rxqs)[idx] = NULL; + + dev->data->rx_queues[idx] = NULL; + dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED; +} + static int xsc_ethdev_enable(struct rte_eth_dev *dev) { @@ -149,6 +187,30 @@ xsc_ethdev_enable(struct rte_eth_dev *dev) return 0; } +static void +xsc_rxq_stop(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t i; + + for (i = 0; i != priv->num_rq; ++i) + xsc_ethdev_rxq_release(dev, i); + priv->rxqs = NULL; + priv->flags &= ~XSC_FLAG_RX_QUEUE_INIT; +} + +static void +xsc_txq_stop(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t i; + + for (i = 0; i != priv->num_sq; ++i) + xsc_ethdev_txq_release(dev, i); + priv->txqs = NULL; + priv->flags &= ~XSC_FLAG_TX_QUEUE_INIT; +} + static int xsc_txq_start(struct xsc_ethdev_priv *priv) { @@ -253,9 +315,51 @@ xsc_ethdev_start(struct rte_eth_dev *dev) error: dev->data->dev_started = 0; + xsc_txq_stop(dev); + xsc_rxq_stop(dev); return -rte_errno; } +static int +xsc_ethdev_stop(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t i; + + PMD_DRV_LOG(DEBUG, "Port %u stopping", dev->data->port_id); + dev->data->dev_started = 0; + dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; + dev->tx_pkt_burst = rte_eth_pkt_burst_dummy; + rte_wmb(); + + rte_delay_us_sleep(1000 * priv->num_rq); + for (i = 0; i < priv->num_rq; ++i) + dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; + for (i
[PATCH v7 14/15] net/xsc: add ethdev infos get
Implement xsc ethdev information get ops. Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_ethdev.c | 61 1 file changed, 61 insertions(+) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 63c64ce547..5d548adb2d 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -364,6 +364,66 @@ xsc_ethdev_close(struct rte_eth_dev *dev) return 0; } +static uint64_t +xsc_get_rx_queue_offloads(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_dev_config *config = &priv->config; + uint64_t offloads = 0; + + if (config->hw_csum) + offloads |= (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | +RTE_ETH_RX_OFFLOAD_UDP_CKSUM | +RTE_ETH_RX_OFFLOAD_TCP_CKSUM); + + return offloads; +} + +static uint64_t +xsc_get_tx_port_offloads(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint64_t offloads = 0; + struct xsc_dev_config *config = &priv->config; + + if (config->hw_csum) + offloads |= (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | +RTE_ETH_TX_OFFLOAD_UDP_CKSUM | +RTE_ETH_TX_OFFLOAD_TCP_CKSUM); + if (config->tso) + offloads |= RTE_ETH_TX_OFFLOAD_TCP_TSO; + return offloads; +} + +static int +xsc_ethdev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + info->min_rx_bufsize = 64; + info->max_rx_pktlen = 65536; + info->max_lro_pkt_size = 0; + info->max_rx_queues = 256; + info->max_tx_queues = 1024; + info->rx_desc_lim.nb_max = 4096; + info->rx_desc_lim.nb_min = 16; + info->tx_desc_lim.nb_max = 8192; + info->tx_desc_lim.nb_min = 128; + + info->rx_queue_offload_capa = xsc_get_rx_queue_offloads(dev); + info->rx_offload_capa = info->rx_queue_offload_capa; + info->tx_offload_capa = xsc_get_tx_port_offloads(dev); + + info->if_index = priv->ifindex; + info->speed_capa = priv->xdev->link_speed_capa; + info->hash_key_size = XSC_RSS_HASH_KEY_LEN; + info->tx_desc_lim.nb_seg_max = 8; + info->tx_desc_lim.nb_mtu_seg_max = 8; + info->switch_info.name = dev->data->name; + info->switch_info.port_id = priv->representor_id; + return 0; +} + static int xsc_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, uint32_t socket, const struct rte_eth_rxconf *conf, @@ -549,6 +609,7 @@ const struct eth_dev_ops xsc_eth_dev_ops = { .dev_close = xsc_ethdev_close, .stats_get = xsc_ethdev_stats_get, .stats_reset = xsc_ethdev_stats_reset, + .dev_infos_get = xsc_ethdev_infos_get, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, .rx_queue_release = xsc_ethdev_rxq_release, -- 2.25.1
[PATCH v7 12/15] net/xsc: add ethdev Tx burst
Implement xsc ethdev Tx burst function. Signed-off-by: Dongwei Xu Signed-off-by: Renyong Wan --- doc/guides/nics/features/xsc.ini | 4 + drivers/net/xsc/xsc_ethdev.c | 1 + drivers/net/xsc/xsc_tx.c | 228 +++ drivers/net/xsc/xsc_tx.h | 1 + 4 files changed, 234 insertions(+) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index bdeb7a984b..772c6418c4 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -7,6 +7,10 @@ RSS hash = Y RSS key update = Y RSS reta update = Y +L3 checksum offload = Y +L4 checksum offload = Y +Inner L3 checksum= Y +Inner L4 checksum= Y Linux= Y ARMv8= Y x86-64 = Y diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index ebc62fd33c..d344714d79 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -311,6 +311,7 @@ xsc_ethdev_start(struct rte_eth_dev *dev) dev->data->dev_started = 1; dev->rx_pkt_burst = xsc_rx_burst; + dev->tx_pkt_burst = xsc_tx_burst; ret = xsc_ethdev_enable(dev); diff --git a/drivers/net/xsc/xsc_tx.c b/drivers/net/xsc/xsc_tx.c index 56daf6b4c6..406fa95381 100644 --- a/drivers/net/xsc/xsc_tx.c +++ b/drivers/net/xsc/xsc_tx.c @@ -124,3 +124,231 @@ xsc_txq_elts_free(struct xsc_txq_data *txq_data) } PMD_DRV_LOG(DEBUG, "Port %u txq %u free elts", txq_data->port_id, txq_data->idx); } + +static __rte_always_inline void +xsc_tx_elts_flush(struct xsc_txq_data *__rte_restrict txq, uint16_t tail) +{ + uint16_t elts_n = tail - txq->elts_tail; + uint32_t free_n; + + do { + free_n = txq->elts_s - (txq->elts_tail & txq->elts_m); + free_n = RTE_MIN(free_n, elts_n); + rte_pktmbuf_free_bulk(&txq->elts[txq->elts_tail & txq->elts_m], free_n); + txq->elts_tail += free_n; + elts_n -= free_n; + } while (elts_n > 0); +} + +static void +xsc_tx_cqes_handle(struct xsc_txq_data *__rte_restrict txq) +{ + uint32_t count = XSC_TX_COMP_CQE_HANDLE_MAX; + volatile struct xsc_cqe *last_cqe = NULL; + volatile struct xsc_cqe *cqe; + bool doorbell = false; + int ret; + uint16_t tail; + + do { + cqe = &txq->cqes[txq->cq_ci & txq->cqe_m]; + ret = xsc_check_cqe_own(cqe, txq->cqe_n, txq->cq_ci); + if (unlikely(ret != XSC_CQE_OWNER_SW)) { + if (likely(ret != XSC_CQE_OWNER_ERR)) + /* No new CQEs in completion queue. */ + break; + doorbell = true; + ++txq->cq_ci; + txq->cq_pi = txq->cq_ci; + last_cqe = NULL; + ++txq->stats.tx_errors; + continue; + } + + doorbell = true; + ++txq->cq_ci; + last_cqe = cqe; + } while (--count > 0); + + if (likely(doorbell)) { + union xsc_cq_doorbell cq_db = { + .cq_data = 0 + }; + cq_db.next_cid = txq->cq_ci; + cq_db.cq_num = txq->cqn; + + /* Ring doorbell */ + rte_write32(rte_cpu_to_le_32(cq_db.cq_data), txq->cq_db); + + /* Release completed elts */ + if (likely(last_cqe != NULL)) { + txq->wqe_pi = rte_le_to_cpu_16(last_cqe->wqe_id) >> txq->wqe_ds_n; + tail = txq->fcqs[(txq->cq_ci - 1) & txq->cqe_m]; + if (likely(tail != txq->elts_tail)) + xsc_tx_elts_flush(txq, tail); + } + } +} + +static __rte_always_inline void +xsc_tx_wqe_ctrl_seg_init(struct xsc_txq_data *__rte_restrict txq, +struct rte_mbuf *__rte_restrict mbuf, +struct xsc_wqe *__rte_restrict wqe) +{ + struct xsc_send_wqe_ctrl_seg *cs = &wqe->cseg; + int i = 0; + int ds_max = (1 << txq->wqe_ds_n) - 1; + + cs->msg_opcode = XSC_OPCODE_RAW; + cs->wqe_id = rte_cpu_to_le_16(txq->wqe_ci << txq->wqe_ds_n); + cs->has_pph = 0; + /* Clear dseg's seg len */ + if (cs->ds_data_num > 1 && cs->ds_data_num <= ds_max) { + for (i = 1; i < cs->ds_data_num; i++) + wqe->dseg[i].seg_len = 0; + } + + cs->ds_data_num = mbuf->nb_segs; + if (mbuf->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) + cs->csum_en = 0x2; + else + cs->csum_en = 0; +
[PATCH v7 15/15] net/xsc: add ethdev link and MTU ops
Implement xsc ethdev link and MTU ops. Signed-off-by: Renyong Wan --- doc/guides/nics/features/xsc.ini | 1 + drivers/net/xsc/xsc_dev.c| 33 ++ drivers/net/xsc/xsc_dev.h| 4 +++ drivers/net/xsc/xsc_ethdev.c | 60 4 files changed, 98 insertions(+) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index 56e38a27d8..8d5c292b7f 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -4,6 +4,7 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +MTU update = Y RSS hash = Y RSS key update = Y RSS reta update = Y diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 350a1fbc70..c836f2f35a 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -62,6 +62,39 @@ xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, data_out, out_len); } +int +xsc_dev_set_link_up(struct xsc_dev *xdev) +{ + if (xdev->dev_ops->set_link_up == NULL) + return -ENOTSUP; + + return xdev->dev_ops->set_link_up(xdev); +} + +int +xsc_dev_set_link_down(struct xsc_dev *xdev) +{ + if (xdev->dev_ops->set_link_down == NULL) + return -ENOTSUP; + + return xdev->dev_ops->set_link_down(xdev); +} + +int +xsc_dev_link_update(struct xsc_dev *xdev, uint8_t funcid_type, int wait_to_complete) +{ + if (xdev->dev_ops->link_update == NULL) + return -ENOTSUP; + + return xdev->dev_ops->link_update(xdev, funcid_type, wait_to_complete); +} + +int +xsc_dev_set_mtu(struct xsc_dev *xdev, uint16_t mtu) +{ + return xdev->dev_ops->set_mtu(xdev, mtu); +} + int xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac) { diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index c0a4d57af7..cc5fa8aad8 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -158,6 +158,9 @@ struct xsc_dev_ops { int xsc_dev_mailbox_exec(struct xsc_dev *xdev, void *data_in, int in_len, void *data_out, int out_len); void xsc_dev_ops_register(struct xsc_dev_ops *new_ops); +int xsc_dev_set_link_up(struct xsc_dev *xdev); +int xsc_dev_set_link_down(struct xsc_dev *xde); +int xsc_dev_link_update(struct xsc_dev *xdev, uint8_t funcid_type, int wait_to_complete); int xsc_dev_destroy_qp(struct xsc_dev *xdev, void *qp); int xsc_dev_destroy_cq(struct xsc_dev *xdev, void *cq); int xsc_dev_modify_qp_status(struct xsc_dev *xdev, uint32_t qpn, int num, int opcode); @@ -175,6 +178,7 @@ int xsc_dev_repr_ports_probe(struct xsc_dev *xdev, int nb_repr_ports, int max_et int xsc_dev_rss_key_modify(struct xsc_dev *xdev, uint8_t *rss_key, uint8_t rss_key_len); bool xsc_dev_is_vf(struct xsc_dev *xdev); int xsc_dev_qp_set_id_get(struct xsc_dev *xdev, int repr_id); +int xsc_dev_set_mtu(struct xsc_dev *xdev, uint16_t mtu); int xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac); #endif /* _XSC_DEV_H_ */ diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 5d548adb2d..b9675a5218 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -364,6 +364,41 @@ xsc_ethdev_close(struct rte_eth_dev *dev) return 0; } +static int +xsc_ethdev_set_link_up(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_dev *xdev = priv->xdev; + + return xsc_dev_set_link_up(xdev); +} + +static int +xsc_ethdev_set_link_down(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_dev *xdev = priv->xdev; + + return xsc_dev_set_link_down(xdev); +} + +static int +xsc_ethdev_link_update(struct rte_eth_dev *dev, + int wait_to_complete) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_dev *xdev = priv->xdev; + int ret = 0; + + ret = xsc_dev_link_update(xdev, priv->funcid_type, wait_to_complete); + if (ret == 0) { + dev->data->dev_link = xdev->pf_dev_link; + dev->data->dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds & + RTE_ETH_LINK_SPEED_FIXED); + } + return ret; +} + static uint64_t xsc_get_rx_queue_offloads(struct rte_eth_dev *dev) { @@ -503,6 +538,27 @@ xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, return 0; } +static int +xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + int ret = 0; + + if (priv->eth_type != RTE_ETH_REPRESENTOR_PF) { + priv->mtu = mtu; + return 0; + } + + ret = xsc_dev_set_mtu(priv->xdev
[PATCH v7 00/15] XSC PMD for Yunsilicon NICs
This xsc PMD (**librte_net_xsc**) provides poll mode driver for Yunsilicon metaScale serials NICs. Features: - - MTU update - TSO - RSS hash - RSS key update - RSS reta update - L3 checksum offload - L4 checksum offload - Inner L3 checksum - Inner L4 checksum - Basic stats - Stats per queue Support NICs: - - metaScale-200S Single QSFP56 Port 200GE SmartNIC - metaScale-200Quad QSFP28 Ports 100GE SmartNIC - metaScale-50 Dual QSFP28 Port 25GE SmartNIC - metaScale-100Q Quad QSFP28 Port 25GE SmartNIC --- v7: * Remove the packed attributes of sub structures and unions. * Remove the cast of xdev->dev_priv. * Remove the cast of malloc return value. * Define the size of xdev->name to PCI_PRI_STR_SIZE. * Change the name of Wanrenyong to Renyong Wan v6: * Remove unnecessary paren. * Add the feature of stats per queue in xsc.ini. * Use memcpy instead of rte_memcpy in non critical path. * Rebase from the main branch and merge release notes. * Replace __rte_packed with __rte_packed_begin and __rte_packed_end. v5: * fix compilation errors. * fix coding style issue with misspelling. * remove some unnecessary parameter checks. * remove unnecessary call of rte_wmb. * Rearrange elements in structure to avoid holes. v4: * Based on the review comments from previous versions, reconstruct the xsc PMD to eliminate the dependency on rdma core library and proprietary kernel driver, while adding support for the vfio kernel driver. v3: * fix compilation errors v2: * fix checkpatch warnings and errors --- Renyong Wan (15): net/xsc: add xsc PMD framework net/xsc: add xsc device initialization net/xsc: add xsc mailbox net/xsc: add xsc dev ops to support VFIO driver net/xsc: add PCT interfaces net/xsc: initialize xsc representors net/xsc: add ethdev configure and RSS ops net/xsc: add Rx and Tx queue setup net/xsc: add ethdev start net/xsc: add ethdev stop and close net/xsc: add ethdev Rx burst net/xsc: add ethdev Tx burst net/xsc: add basic stats ops net/xsc: add ethdev infos get net/xsc: add ethdev link and MTU ops .mailmap | 5 + MAINTAINERS| 10 + doc/guides/nics/features/xsc.ini | 19 + doc/guides/nics/index.rst | 1 + doc/guides/nics/xsc.rst| 31 + doc/guides/rel_notes/release_25_03.rst | 4 + drivers/net/meson.build| 1 + drivers/net/xsc/meson.build| 17 + drivers/net/xsc/xsc_cmd.h | 387 +++ drivers/net/xsc/xsc_defs.h | 100 +++ drivers/net/xsc/xsc_dev.c | 397 +++ drivers/net/xsc/xsc_dev.h | 184 + drivers/net/xsc/xsc_ethdev.c | 917 + drivers/net/xsc/xsc_ethdev.h | 63 ++ drivers/net/xsc/xsc_log.h | 24 + drivers/net/xsc/xsc_np.c | 492 + drivers/net/xsc/xsc_np.h | 154 + drivers/net/xsc/xsc_rx.c | 512 ++ drivers/net/xsc/xsc_rx.h | 65 ++ drivers/net/xsc/xsc_rxtx.h | 191 + drivers/net/xsc/xsc_tx.c | 354 ++ drivers/net/xsc/xsc_tx.h | 62 ++ drivers/net/xsc/xsc_vfio.c | 746 drivers/net/xsc/xsc_vfio_mbox.c| 691 +++ drivers/net/xsc/xsc_vfio_mbox.h| 142 25 files changed, 5569 insertions(+) create mode 100644 doc/guides/nics/features/xsc.ini create mode 100644 doc/guides/nics/xsc.rst create mode 100644 drivers/net/xsc/meson.build create mode 100644 drivers/net/xsc/xsc_cmd.h create mode 100644 drivers/net/xsc/xsc_defs.h create mode 100644 drivers/net/xsc/xsc_dev.c create mode 100644 drivers/net/xsc/xsc_dev.h create mode 100644 drivers/net/xsc/xsc_ethdev.c create mode 100644 drivers/net/xsc/xsc_ethdev.h create mode 100644 drivers/net/xsc/xsc_log.h create mode 100644 drivers/net/xsc/xsc_np.c create mode 100644 drivers/net/xsc/xsc_np.h create mode 100644 drivers/net/xsc/xsc_rx.c create mode 100644 drivers/net/xsc/xsc_rx.h create mode 100644 drivers/net/xsc/xsc_rxtx.h create mode 100644 drivers/net/xsc/xsc_tx.c create mode 100644 drivers/net/xsc/xsc_tx.h create mode 100644 drivers/net/xsc/xsc_vfio.c create mode 100644 drivers/net/xsc/xsc_vfio_mbox.c create mode 100644 drivers/net/xsc/xsc_vfio_mbox.h -- 2.25.1
[PATCH 2/2] net/xsc: optimize release path
Optimized the code of release path to prevent potential resource leaks. Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_dev.c| 5 - drivers/net/xsc/xsc_ethdev.c | 12 ++-- drivers/net/xsc/xsc_np.c | 1 + drivers/net/xsc/xsc_vfio.c | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 1e3dd493f9..fc9f1cddfc 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -150,7 +150,10 @@ int xsc_dev_close(struct xsc_dev *xdev, int repr_id) { xsc_dev_clear_pct(xdev, repr_id); - return xdev->dev_ops->dev_close(xdev); + + if (repr_id == xdev->num_repr_ports - 1) + return xdev->dev_ops->dev_close(xdev); + return 0; } int diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 28af9c5d15..3830c18c03 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -860,13 +860,21 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev) static int xsc_ethdev_uninit(struct rte_eth_dev *eth_dev) { + int ret = 0; + uint16_t port_id; struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev); PMD_INIT_FUNC_TRACE(); + RTE_ETH_FOREACH_DEV_OF(port_id, eth_dev->device) { + if (port_id != eth_dev->data->port_id) + ret |= rte_eth_dev_close(port_id); + } - xsc_dev_uninit(priv->xdev); + ret |= xsc_ethdev_close(eth_dev); + xsc_dev_pct_uninit(); + rte_free(priv->xdev); - return 0; + return ret == 0 ? 0 : -EIO; } static int diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c index f96797b7a4..543e6dba95 100644 --- a/drivers/net/xsc/xsc_np.c +++ b/drivers/net/xsc/xsc_np.c @@ -383,6 +383,7 @@ void xsc_dev_pct_uninit(void) { rte_free(xsc_pct_mgr.bmp_mem); + xsc_pct_mgr.bmp_mem = NULL; } int diff --git a/drivers/net/xsc/xsc_vfio.c b/drivers/net/xsc/xsc_vfio.c index 8330483523..422d30efb9 100644 --- a/drivers/net/xsc/xsc_vfio.c +++ b/drivers/net/xsc/xsc_vfio.c @@ -178,6 +178,7 @@ xsc_vfio_dev_close(struct xsc_dev *xdev) struct xsc_vfio_priv *vfio_priv = (struct xsc_vfio_priv *)xdev->dev_priv; xsc_vfio_mbox_destroy(vfio_priv->cmdq); + rte_pci_unmap_device(xdev->pci_dev); rte_free(vfio_priv); return 0; -- 2.25.1
[PATCH 1/2] net/xsc: fix resource leaks
Fixed the Coverity-detected issue that resource leaks. Coverity issue: 457741 Fixes: 3d57851720d4 ("net/xsc: check null pointer dereference") Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_rx.c | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index 0100ccdcfd..65d63b94de 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -309,8 +309,11 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) for (i = 0; i < priv->num_rq; i++) { rxq_data = xsc_rxq_get(priv, i); - if (rxq_data == NULL) - return -EINVAL; + if (rxq_data == NULL) { + rte_errno = EINVAL; + goto error; + } + req = (struct xsc_cmd_create_qp_request *)(&in->data[0] + entry_len * i); req->input_qpn = rte_cpu_to_be_16(0); /* useless for eth */ req->pa_num = rte_cpu_to_be_16(pa_num); @@ -350,8 +353,11 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) for (i = 0; i < priv->num_rq; i++) { rxq_data = xsc_rxq_get(priv, i); - if (rxq_data == NULL) - return -EINVAL; + if (rxq_data == NULL) { + rte_errno = EINVAL; + goto error; + } + rxq_data->wqes = rxq_data->rq_pas->addr; if (!xsc_dev_is_vf(xdev)) rxq_data->rq_db = (uint32_t *)((uint8_t *)xdev->bar_addr + -- 2.25.1
[PATCH 0/2] Optimize the code to void resource leaks
This patchset focuses on optimizing the code to avoid resource leaks. Renyong Wan (2): net/xsc: fix resource leaks net/xsc: optimize release path drivers/net/xsc/xsc_dev.c| 5 - drivers/net/xsc/xsc_ethdev.c | 12 ++-- drivers/net/xsc/xsc_np.c | 1 + drivers/net/xsc/xsc_rx.c | 14 ++ drivers/net/xsc/xsc_vfio.c | 1 + 5 files changed, 26 insertions(+), 7 deletions(-) -- 2.25.1
Re: [PATCH v7 00/15] XSC PMD for Yunsilicon NICs
On 2025/2/15 7:27, Stephen Hemminger wrote: > On Tue, 28 Jan 2025 22:47:22 +0800 > "Renyong Wan" wrote: > >> This xsc PMD (**librte_net_xsc**) provides poll mode driver for >> Yunsilicon metaScale serials NICs. >> >> Features: >> - >> - MTU update >> - TSO >> - RSS hash >> - RSS key update >> - RSS reta update >> - L3 checksum offload >> - L4 checksum offload >> - Inner L3 checksum >> - Inner L4 checksum >> - Basic stats >> - Stats per queue >> >> Support NICs: >> - >> - metaScale-200S Single QSFP56 Port 200GE SmartNIC >> - metaScale-200Quad QSFP28 Ports 100GE SmartNIC >> - metaScale-50 Dual QSFP28 Port 25GE SmartNIC >> - metaScale-100Q Quad QSFP28 Port 25GE SmartNIC >> >> --- >> >> v7: >> * Remove the packed attributes of sub structures and unions. >> * Remove the cast of xdev->dev_priv. >> * Remove the cast of malloc return value. >> * Define the size of xdev->name to PCI_PRI_STR_SIZE. >> * Change the name of Wanrenyong to Renyong Wan >> >> v6: >> * Remove unnecessary paren. >> * Add the feature of stats per queue in xsc.ini. >> * Use memcpy instead of rte_memcpy in non critical path. >> * Rebase from the main branch and merge release notes. >> * Replace __rte_packed with __rte_packed_begin and __rte_packed_end. >> >> v5: >> * fix compilation errors. >> * fix coding style issue with misspelling. >> * remove some unnecessary parameter checks. >> * remove unnecessary call of rte_wmb. >> * Rearrange elements in structure to avoid holes. >> >> v4: >> * Based on the review comments from previous versions, reconstruct the xsc >> PMD to eliminate >>the dependency on rdma core library and proprietary kernel driver, while >> adding support for >>the vfio kernel driver. >> >> v3: >> * fix compilation errors >> >> v2: >> * fix checkpatch warnings and errors >> >> --- >> Renyong Wan (15): >>net/xsc: add xsc PMD framework >>net/xsc: add xsc device initialization >>net/xsc: add xsc mailbox >>net/xsc: add xsc dev ops to support VFIO driver >>net/xsc: add PCT interfaces >>net/xsc: initialize xsc representors >>net/xsc: add ethdev configure and RSS ops >>net/xsc: add Rx and Tx queue setup >>net/xsc: add ethdev start >>net/xsc: add ethdev stop and close >>net/xsc: add ethdev Rx burst >>net/xsc: add ethdev Tx burst >>net/xsc: add basic stats ops >>net/xsc: add ethdev infos get >>net/xsc: add ethdev link and MTU ops >> >> .mailmap | 5 + >> MAINTAINERS| 10 + >> doc/guides/nics/features/xsc.ini | 19 + >> doc/guides/nics/index.rst | 1 + >> doc/guides/nics/xsc.rst| 31 + >> doc/guides/rel_notes/release_25_03.rst | 4 + >> drivers/net/meson.build| 1 + >> drivers/net/xsc/meson.build| 17 + >> drivers/net/xsc/xsc_cmd.h | 387 +++ >> drivers/net/xsc/xsc_defs.h | 100 +++ >> drivers/net/xsc/xsc_dev.c | 397 +++ >> drivers/net/xsc/xsc_dev.h | 184 + >> drivers/net/xsc/xsc_ethdev.c | 917 + >> drivers/net/xsc/xsc_ethdev.h | 63 ++ >> drivers/net/xsc/xsc_log.h | 24 + >> drivers/net/xsc/xsc_np.c | 492 + >> drivers/net/xsc/xsc_np.h | 154 + >> drivers/net/xsc/xsc_rx.c | 512 ++ >> drivers/net/xsc/xsc_rx.h | 65 ++ >> drivers/net/xsc/xsc_rxtx.h | 191 + >> drivers/net/xsc/xsc_tx.c | 354 ++ >> drivers/net/xsc/xsc_tx.h | 62 ++ >> drivers/net/xsc/xsc_vfio.c | 746 >> drivers/net/xsc/xsc_vfio_mbox.c| 691 +++ >> drivers/net/xsc/xsc_vfio_mbox.h| 142 >> 25 files changed, 5569 insertions(+) >> create mode 100644 doc/guides/nics/features/xsc.ini >> create mode 100644 doc/guides/nics/xsc.rst >> create mode 100644 drivers/net/xsc/meson.build >> create mode 100644 drivers/net/xsc/xsc_cmd.h >> create mode 100644 drivers/net/xsc/xsc_defs.h >> create mode 100644 drivers/net/xsc/xsc_dev.c >> create mode 100644 drivers/net/xsc/xsc_dev.h >> create mod
[PATCH 02/12] net/xsc: remove useless call
Address incorrect expression (USELESS_CALL) reported by Coverity Scan. Coverity issue: 456590 Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_np.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c index d4eb833bf6..f032a0dbc2 100644 --- a/drivers/net/xsc/xsc_np.c +++ b/drivers/net/xsc/xsc_np.c @@ -384,7 +384,6 @@ xsc_dev_create_vfos_baselp(struct xsc_dev *xdev) void xsc_dev_pct_uninit(void) { - rte_bitmap_free(xsc_pct_mgr.bmp_pct); rte_free(xsc_pct_mgr.bmp_mem); } -- 2.25.1
[PATCH 01/12] net/xsc: avoid integer overflow
Address the integer overflow issue reported by Coverity Scan. Coverity issue: 456589 Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/xsc/xsc_tx.c b/drivers/net/xsc/xsc_tx.c index 406fa95381..1d31e84d69 100644 --- a/drivers/net/xsc/xsc_tx.c +++ b/drivers/net/xsc/xsc_tx.c @@ -50,7 +50,7 @@ xsc_txq_obj_new(struct xsc_dev *xdev, struct xsc_txq_data *txq_data, txq_data->cq_db = cq_info.cq_db; txq_data->cqn = cq_info.cqn; txq_data->cqes = cq_info.cqes; - txq_data->cqe_m = txq_data->cqe_s - 1; + txq_data->cqe_m = (uint16_t)(1 << cq_info.cqe_n) - 1; PMD_DRV_LOG(INFO, "Create tx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%d", txq_data->cqe_s, txq_data->cqe_n, -- 2.25.1
[PATCH 05/12] net/xsc: avoid variable is assigned but not used
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v1001/ Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_ethdev.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 0729d43884..d04fe78d3f 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -314,6 +314,11 @@ xsc_ethdev_start(struct rte_eth_dev *dev) dev->tx_pkt_burst = xsc_tx_burst; ret = xsc_ethdev_enable(dev); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to enable port: %u", + dev->data->port_id); + goto error; + } return 0; -- 2.25.1
[PATCH 03/12] net/xsc: address incorrect format warnings
These warnings reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v576/ Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_dev.c | 2 +- drivers/net/xsc/xsc_rx.c| 4 ++-- drivers/net/xsc/xsc_tx.c| 4 ++-- drivers/net/xsc/xsc_vfio.c | 4 ++-- drivers/net/xsc/xsc_vfio_mbox.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index c836f2f35a..1e3dd493f9 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -289,7 +289,7 @@ xsc_dev_repr_ports_probe(struct xsc_dev *xdev, int nb_repr_ports, int max_eth_po xdev->num_repr_ports = nb_repr_ports + XSC_PHY_PORT_NUM; if (xdev->num_repr_ports > max_eth_ports) { - PMD_DRV_LOG(ERR, "Repr ports num %u, should be less than max %u", + PMD_DRV_LOG(ERR, "Repr ports num %d, should be less than max %d", xdev->num_repr_ports, max_eth_ports); return -EINVAL; } diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index 58a9cc2f26..3230710656 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -358,7 +358,7 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) xsc_rxq_initialize(xdev, rxq_data); rxq_data->cq_ci = 0; priv->dev_data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; - PMD_DRV_LOG(INFO, "Port %u create rx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%d", + PMD_DRV_LOG(INFO, "Port %d create rx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%u", port_id, rxq_data->wqe_s, rxq_data->wqe_n, rxq_data->rq_db, rxq_data->qpn); @@ -407,7 +407,7 @@ xsc_rxq_rss_obj_new(struct xsc_ethdev_priv *priv, uint16_t port_id) rxq_data->cq_db = cq_info.cq_db; rxq_data->cqn = cq_info.cqn; - PMD_DRV_LOG(INFO, "Port %u create rx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%d", + PMD_DRV_LOG(INFO, "Port %u create rx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%u", port_id, rxq_data->cqe_s, rxq_data->cqe_n, rxq_data->cq_db, rxq_data->cqn); diff --git a/drivers/net/xsc/xsc_tx.c b/drivers/net/xsc/xsc_tx.c index 1d31e84d69..0d6a9981d0 100644 --- a/drivers/net/xsc/xsc_tx.c +++ b/drivers/net/xsc/xsc_tx.c @@ -52,7 +52,7 @@ xsc_txq_obj_new(struct xsc_dev *xdev, struct xsc_txq_data *txq_data, txq_data->cqes = cq_info.cqes; txq_data->cqe_m = (uint16_t)(1 << cq_info.cqe_n) - 1; - PMD_DRV_LOG(INFO, "Create tx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%d", + PMD_DRV_LOG(INFO, "Create tx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%u", txq_data->cqe_s, txq_data->cqe_n, txq_data->cq_db, txq_data->cqn); @@ -83,7 +83,7 @@ xsc_txq_obj_new(struct xsc_dev *xdev, struct xsc_txq_data *txq_data, txq_data->wqe_pi = 0; txq_data->wqe_comp = 0; - PMD_DRV_LOG(INFO, "Create tx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%d", + PMD_DRV_LOG(INFO, "Create tx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%u", txq_data->wqe_s, txq_data->wqe_n, txq_data->qp_db, txq_data->qpn); return 0; diff --git a/drivers/net/xsc/xsc_vfio.c b/drivers/net/xsc/xsc_vfio.c index e8fefb9e94..6c679449af 100644 --- a/drivers/net/xsc/xsc_vfio.c +++ b/drivers/net/xsc/xsc_vfio.c @@ -337,7 +337,7 @@ xsc_vfio_modify_qp_status(struct xsc_dev *xdev, uint32_t qpn, int num, int opcod ret = xsc_vfio_mbox_exec(xdev, in, in_len, out, out_len); if (ret != 0 || out->hdr.status != 0) { - PMD_DRV_LOG(ERR, "Modify qp status failed, qpn=%d, err=%d, out.status=%u", + PMD_DRV_LOG(ERR, "Modify qp status failed, qpn=%u, err=%d, out.status=%u", qpn + i, ret, out->hdr.status); rte_errno = ENOEXEC; ret = -rte_errno; @@ -483,7 +483,7 @@ xsc_vfio_rx_cq_create(struct xsc_dev *xdev, struct xsc_rx_cq_params *cq_params, cq_info->cqn = rte_be_to_cpu_32(out->cqn); cq->cqn = cq_info->cqn; cq->xdev = xdev; - PMD_DRV_LOG(INFO, "Port id=%d, Rx cqe_n:%d, cqn:%d", + PMD_DRV_LOG(INFO, "Port id=%d, Rx cqe_n:%d, cqn:%u", port_id, cq_info->cqe_n, cq_info->cqn); free(in); diff --git a/drivers/net/xsc/xsc_vfio_mbox.c b/drivers/net/xsc/xsc_vfio_mbox.c index 454fe64645..c465679527 100644 --- a/d
[PATCH 09/12] net/xsc: avoid assign the same value to a variable
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v1048/ Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_np.c | 4 drivers/net/xsc/xsc_tx.c | 1 - 2 files changed, 5 deletions(-) diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c index eff7497255..7ff39f83c9 100644 --- a/drivers/net/xsc/xsc_np.c +++ b/drivers/net/xsc/xsc_np.c @@ -137,10 +137,6 @@ xsc_rss_hash_template_get(struct rte_eth_rss_conf *rss_conf) rss_hf &= ~XSC_RSS_HASH_BIT_IPV6_SPORT; } - if ((rss_conf->rss_hf & RTE_ETH_RSS_LEVEL_PMD_DEFAULT) || - (rss_conf->rss_hf & RTE_ETH_RSS_LEVEL_OUTERMOST)) - outer = 1; - if (rss_conf->rss_hf & RTE_ETH_RSS_LEVEL_INNERMOST) outer = 0; diff --git a/drivers/net/xsc/xsc_tx.c b/drivers/net/xsc/xsc_tx.c index 0d6a9981d0..d1a0f3284b 100644 --- a/drivers/net/xsc/xsc_tx.c +++ b/drivers/net/xsc/xsc_tx.c @@ -215,7 +215,6 @@ xsc_tx_wqe_ctrl_seg_init(struct xsc_txq_data *__rte_restrict txq, cs->csum_en = 0; if (txq->tso_en == 1 && (mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) { - cs->has_pph = 0; cs->so_type = 1; cs->so_hdr_len = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; cs->so_data_size = rte_cpu_to_le_16(mbuf->tso_segsz); -- 2.25.1
[PATCH 04/12] net/xsc: remove always-true if expressions
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v547/ Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_ethdev.c | 13 + 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index b9675a5218..0729d43884 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -721,16 +721,13 @@ xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params) config->tso = 0; } else { config->tso = 1; - if (config->tso) - config->tso_max_payload_sz = 1500; + config->tso_max_payload_sz = 1500; } - priv->is_representor = (priv->eth_type == RTE_ETH_REPRESENTOR_NONE) ? 0 : 1; - if (priv->is_representor) { - eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; - eth_dev->data->representor_id = priv->representor_id; - eth_dev->data->backer_port_id = eth_dev->data->port_id; - } + priv->is_representor = 1; + eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; + eth_dev->data->representor_id = priv->representor_id; + eth_dev->data->backer_port_id = eth_dev->data->port_id; eth_dev->dev_ops = &xsc_eth_dev_ops; eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; -- 2.25.1
[PATCH 10/12] net/xsc: avoid initialize by same function
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v656 Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_rx.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index c031e56a94..ca832dab23 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -445,10 +445,8 @@ xsc_rxq_elts_alloc(struct xsc_rxq_data *rxq_data) mbuf->port = rxq_data->port_id; mbuf->nb_segs = 1; - rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_data_room_size(rxq_data->mp) - - mbuf->data_off; - rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_room_size(rxq_data->mp) - - mbuf->data_off; + rte_pktmbuf_data_len(mbuf) = mbuf->buf_len - mbuf->data_off; + rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_len(mbuf); (*rxq_data->elts)[i] = mbuf; } -- 2.25.1
[PATCH 00/12] net/xsc: Resolve issues from PVS and Coverity Scan
This patch series resolves several issues reported by PVS and Coverity Scan, which were earlier forwarded to us by Stephen Hemminger. --- Renyong Wan (12): net/xsc: avoid integer overflow net/xsc: remove useless call net/xsc: address incorrect format warnings net/xsc: remove always-true if expressions net/xsc: avoid variable is assigned but not used net/xsc: check possible null pointer dereference net/xsc: avoid potential null pointer before used net/xsc: remove always-true part of if expression net/xsc: avoid assign the same value to a variable net/xsc: avoid initialize by same function net/xsc: optimize memcmp returns not 0 check net/xsc: avoid pointer cast to unrelated class drivers/net/xsc/xsc_dev.c | 2 +- drivers/net/xsc/xsc_ethdev.c| 35 drivers/net/xsc/xsc_np.c| 17 +++--- drivers/net/xsc/xsc_rx.c| 31 ++- drivers/net/xsc/xsc_tx.c| 7 +-- drivers/net/xsc/xsc_vfio.c | 97 - drivers/net/xsc/xsc_vfio_mbox.c | 2 +- 7 files changed, 111 insertions(+), 80 deletions(-) -- 2.25.1
[PATCH 08/12] net/xsc: remove always-true part of if expression
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v560/ Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_rx.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index dfb71ed087..c031e56a94 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -42,8 +42,6 @@ xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct xsc_cqe *cqe) if (unlikely(ret != XSC_CQE_OWNER_SW)) { if (unlikely(ret == XSC_CQE_OWNER_ERR)) { ++rxq->stats.rx_errors; - if (ret == XSC_CQE_OWNER_HW || ret == -1) - return 0; } else { return 0; } -- 2.25.1
[PATCH 11/12] net/xsc: optimize memcmp returns not 0 check
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v526/ Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_ethdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 44d861e484..28af9c5d15 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -663,7 +663,7 @@ xsc_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uin for (i = 0; i != XSC_MAX_MAC_ADDRESSES; ++i) { if (i == (int)index) continue; - if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac))) + if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)) != 0) continue; /* Address already configured elsewhere, return with error */ rte_errno = EADDRINUSE; -- 2.25.1
[PATCH 07/12] net/xsc: avoid potential null pointer before used
This issue reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v595/ Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_np.c | 2 +- drivers/net/xsc/xsc_rx.c | 2 +- drivers/net/xsc/xsc_vfio.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c index f032a0dbc2..eff7497255 100644 --- a/drivers/net/xsc/xsc_np.c +++ b/drivers/net/xsc/xsc_np.c @@ -172,13 +172,13 @@ xsc_dev_np_exec(struct xsc_dev *xdev, void *cmd, int len, int table, int opmod) out_len = sizeof(struct xsc_np_mbox_out) + data_len; cmd_len = RTE_MAX(in_len, out_len); in = malloc(cmd_len); - memset(in, 0, cmd_len); if (in == NULL) { rte_errno = ENOMEM; PMD_DRV_LOG(ERR, "Failed to alloc np cmd memory"); return -rte_errno; } + memset(in, 0, cmd_len); in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_EXEC_NP); in->len = rte_cpu_to_be_16(data_len); diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index 140d7728d6..dfb71ed087 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -296,13 +296,13 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) out_len = sizeof(struct xsc_cmd_create_multiqp_mbox_out) + entry_total_len; cmd_len = RTE_MAX(in_len, out_len); in = malloc(cmd_len); - memset(in, 0, cmd_len); if (in == NULL) { rte_errno = ENOMEM; PMD_DRV_LOG(ERR, "Alloc rss qp create cmd memory failed"); goto error; } + memset(in, 0, cmd_len); in->qp_num = rte_cpu_to_be_16((uint16_t)priv->num_rq); in->qp_type = XSC_QUEUE_TYPE_RAW; in->req_len = rte_cpu_to_be_32(cmd_len); diff --git a/drivers/net/xsc/xsc_vfio.c b/drivers/net/xsc/xsc_vfio.c index 6c679449af..2cd796ba26 100644 --- a/drivers/net/xsc/xsc_vfio.c +++ b/drivers/net/xsc/xsc_vfio.c @@ -431,13 +431,13 @@ xsc_vfio_rx_cq_create(struct xsc_dev *xdev, struct xsc_rx_cq_params *cq_params, } in = malloc(cmd_len); - memset(in, 0, cmd_len); if (in == NULL) { rte_errno = ENOMEM; PMD_DRV_LOG(ERR, "Failed to alloc rx cq exec cmd memory"); goto error; } + memset(in, 0, cmd_len); in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_CREATE_CQ); in->ctx.eqn = 0; in->ctx.pa_num = rte_cpu_to_be_16(pa_num); -- 2.25.1
[PATCH 12/12] net/xsc: avoid pointer cast to unrelated class
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v1027/ Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_np.c | 10 +++-- drivers/net/xsc/xsc_rx.c | 12 ++--- drivers/net/xsc/xsc_vfio.c | 91 +++--- 3 files changed, 68 insertions(+), 45 deletions(-) diff --git a/drivers/net/xsc/xsc_np.c b/drivers/net/xsc/xsc_np.c index 7ff39f83c9..f96797b7a4 100644 --- a/drivers/net/xsc/xsc_np.c +++ b/drivers/net/xsc/xsc_np.c @@ -162,18 +162,20 @@ xsc_dev_np_exec(struct xsc_dev *xdev, void *cmd, int len, int table, int opmod) int data_len; int cmd_len; int ret; + void *cmd_buf; data_len = sizeof(struct xsc_np_data_tl) + len; in_len = sizeof(struct xsc_np_mbox_in) + data_len; out_len = sizeof(struct xsc_np_mbox_out) + data_len; cmd_len = RTE_MAX(in_len, out_len); - in = malloc(cmd_len); - if (in == NULL) { + cmd_buf = malloc(cmd_len); + if (cmd_buf == NULL) { rte_errno = ENOMEM; PMD_DRV_LOG(ERR, "Failed to alloc np cmd memory"); return -rte_errno; } + in = cmd_buf; memset(in, 0, cmd_len); in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_EXEC_NP); in->len = rte_cpu_to_be_16(data_len); @@ -185,10 +187,10 @@ xsc_dev_np_exec(struct xsc_dev *xdev, void *cmd, int len, int table, int opmod) if (cmd && len) memcpy(tl + 1, cmd, len); - out = (struct xsc_np_mbox_out *)in; + out = cmd_buf; ret = xsc_dev_mailbox_exec(xdev, in, in_len, out, out_len); - free(in); + free(cmd_buf); return ret; } diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index ca832dab23..a702b9592b 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -276,6 +276,7 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) struct xsc_dev *xdev = priv->xdev; struct xsc_hwinfo *hwinfo = &xdev->hwinfo; char name[RTE_ETH_NAME_MAX_LEN] = { 0 }; + void *cmd_buf; rxq_data = xsc_rxq_get(priv, 0); if (rxq_data == NULL) @@ -293,13 +294,14 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) in_len = sizeof(struct xsc_cmd_create_multiqp_mbox_in) + entry_total_len; out_len = sizeof(struct xsc_cmd_create_multiqp_mbox_out) + entry_total_len; cmd_len = RTE_MAX(in_len, out_len); - in = malloc(cmd_len); - if (in == NULL) { + cmd_buf = malloc(cmd_len); + if (cmd_buf == NULL) { rte_errno = ENOMEM; PMD_DRV_LOG(ERR, "Alloc rss qp create cmd memory failed"); goto error; } + in = cmd_buf; memset(in, 0, cmd_len); in->qp_num = rte_cpu_to_be_16((uint16_t)priv->num_rq); in->qp_type = XSC_QUEUE_TYPE_RAW; @@ -333,7 +335,7 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) } in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_CREATE_MULTI_QP); - out = (struct xsc_cmd_create_multiqp_mbox_out *)in; + out = cmd_buf; ret = xsc_dev_mailbox_exec(xdev, in, in_len, out, out_len); if (ret != 0 || out->hdr.status != 0) { PMD_DRV_LOG(ERR, @@ -365,11 +367,11 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) rxq_data->rq_db, rxq_data->qpn); } - free(in); + free(cmd_buf); return 0; error: - free(in); + free(cmd_buf); return -rte_errno; } diff --git a/drivers/net/xsc/xsc_vfio.c b/drivers/net/xsc/xsc_vfio.c index 2cd796ba26..8330483523 100644 --- a/drivers/net/xsc/xsc_vfio.c +++ b/drivers/net/xsc/xsc_vfio.c @@ -70,22 +70,24 @@ xsc_vfio_hwinfo_init(struct xsc_dev *xdev) struct xsc_cmd_query_hca_cap_mbox_in *in; struct xsc_cmd_query_hca_cap_mbox_out *out; struct xsc_cmd_hca_cap *hca_cap; + void *cmd_buf; in_len = sizeof(struct xsc_cmd_query_hca_cap_mbox_in); out_len = sizeof(struct xsc_cmd_query_hca_cap_mbox_out); cmd_len = RTE_MAX(in_len, out_len); - in = malloc(cmd_len); - if (in == NULL) { + cmd_buf = malloc(cmd_len); + if (cmd_buf == NULL) { PMD_DRV_LOG(ERR, "Failed to alloc dev hwinfo cmd memory"); rte_errno = ENOMEM; return -rte_errno; } + in = cmd_buf; memset(in, 0, cmd_len); in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_QUERY_HCA_CAP); in->hdr.ver = rte_cpu_to_be_16(XSC_CMD_QUERY_HCA_CAP_V1); - out = (struct xsc_cmd_query_hca_cap_mbox_out *)in; + out = cmd_buf; ret = xsc_vfio_mbox_exec(xdev, in, in_len, out, out_len); if (ret != 0 || out->hdr.status != 0) { @@ -126,7 +128,7 @@ xsc_vfio_hwinfo_init(struct x
[PATCH 06/12] net/xsc: check possible null pointer dereference
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v522/ Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_ethdev.c | 15 +-- drivers/net/xsc/xsc_rx.c | 5 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index d04fe78d3f..44d861e484 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -137,8 +137,8 @@ xsc_ethdev_enable(struct rte_eth_dev *dev) int pcie_logic_port = 0; int qp_set_id; int repr_id; - struct xsc_rxq_data *rxq = xsc_rxq_get(priv, 0); - uint16_t rx_qpn = (uint16_t)rxq->qpn; + struct xsc_rxq_data *rxq; + uint16_t rx_qpn; int i, vld; struct xsc_txq_data *txq; struct xsc_repr_port *repr; @@ -147,6 +147,11 @@ xsc_ethdev_enable(struct rte_eth_dev *dev) if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID) return -ENODEV; + rxq = xsc_rxq_get(priv, 0); + if (rxq == NULL) + return -EINVAL; + + rx_qpn = (uint16_t)rxq->qpn; hwinfo = &priv->xdev->hwinfo; repr_id = priv->representor_id; repr = &priv->xdev->repr_ports[repr_id]; @@ -162,6 +167,8 @@ xsc_ethdev_enable(struct rte_eth_dev *dev) for (i = 0; i < priv->num_sq; i++) { txq = xsc_txq_get(priv, i); + if (txq == NULL) + return -EINVAL; xsc_dev_modify_qp_status(priv->xdev, txq->qpn, 1, XSC_CMD_OP_RTR2RTS_QP); xsc_dev_modify_qp_qostree(priv->xdev, txq->qpn); xsc_dev_set_qpsetid(priv->xdev, txq->qpn, qp_set_id); @@ -229,6 +236,8 @@ xsc_txq_start(struct xsc_ethdev_priv *priv) for (i = 0; i != priv->num_sq; ++i) { txq_data = xsc_txq_get(priv, i); + if (txq_data == NULL) + goto error; xsc_txq_elts_alloc(txq_data); ret = xsc_txq_obj_new(priv->xdev, txq_data, offloads, i); if (ret < 0) @@ -270,6 +279,8 @@ xsc_rxq_start(struct xsc_ethdev_priv *priv) for (i = 0; i != priv->num_rq; ++i) { rxq_data = xsc_rxq_get(priv, i); + if (rxq_data == NULL) + goto error; if (dev->data->rx_queue_state[i] != RTE_ETH_QUEUE_STATE_STARTED) { ret = xsc_rxq_elts_alloc(rxq_data); if (ret != 0) diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index 3230710656..140d7728d6 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -280,6 +280,9 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) char name[RTE_ETH_NAME_MAX_LEN] = { 0 }; rxq_data = xsc_rxq_get(priv, 0); + if (rxq_data == NULL) + return -EINVAL; + log_ele = rte_log2_u32(sizeof(struct xsc_wqe_data_seg)); wqe_n = rxq_data->wqe_s; log_rq_sz = rte_log2_u32(wqe_n * hwinfo->recv_seg_num); @@ -385,6 +388,8 @@ xsc_rxq_rss_obj_new(struct xsc_ethdev_priv *priv, uint16_t port_id) /* Create CQ */ for (i = 0; i < priv->num_rq; ++i) { rxq_data = xsc_rxq_get(priv, i); + if (rxq_data == NULL) + return -EINVAL; memset(&cq_params, 0, sizeof(cq_params)); memset(&cq_info, 0, sizeof(cq_info)); -- 2.25.1
[PATCH 0/2] net/xsc: Resolve warnings from PVS
This patch series resolves two warnings reported by PVS studio. --- Renyong Wan (2): net/xsc: check possible null pointer dereference net/xsc: suppress assign the same value warning drivers/net/xsc/xsc_rx.c| 6 +- drivers/net/xsc/xsc_vfio_mbox.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) -- 2.25.1
[PATCH 1/2] net/xsc: check possible null pointer dereference
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v522/ Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_rx.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c index a702b9592b..0100ccdcfd 100644 --- a/drivers/net/xsc/xsc_rx.c +++ b/drivers/net/xsc/xsc_rx.c @@ -308,7 +308,9 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) in->req_len = rte_cpu_to_be_32(cmd_len); for (i = 0; i < priv->num_rq; i++) { - rxq_data = (*priv->rxqs)[i]; + rxq_data = xsc_rxq_get(priv, i); + if (rxq_data == NULL) + return -EINVAL; req = (struct xsc_cmd_create_qp_request *)(&in->data[0] + entry_len * i); req->input_qpn = rte_cpu_to_be_16(0); /* useless for eth */ req->pa_num = rte_cpu_to_be_16(pa_num); @@ -348,6 +350,8 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id) for (i = 0; i < priv->num_rq; i++) { rxq_data = xsc_rxq_get(priv, i); + if (rxq_data == NULL) + return -EINVAL; rxq_data->wqes = rxq_data->rq_pas->addr; if (!xsc_dev_is_vf(xdev)) rxq_data->rq_db = (uint32_t *)((uint8_t *)xdev->bar_addr + -- 2.25.1
[PATCH 2/2] net/xsc: suppress assign the same value warning
This issue was reported by PVS studio, described as: https://pvs-studio.com/en/docs/warnings/v1048/ This warning is harmless since both structs have the same size. The tool is just being annoying, so we should suppress it. Signed-off-by: Rong Qian Signed-off-by: Renyong Wan --- drivers/net/xsc/xsc_vfio_mbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/xsc/xsc_vfio_mbox.c b/drivers/net/xsc/xsc_vfio_mbox.c index c465679527..3c8bb54601 100644 --- a/drivers/net/xsc/xsc_vfio_mbox.c +++ b/drivers/net/xsc/xsc_vfio_mbox.c @@ -572,7 +572,7 @@ xsc_vfio_mbox_init(struct xsc_dev *xdev) cmdq->req_lay = cmdq->req_mz->addr; snprintf(name, RTE_MEMZONE_NAMESIZE, "%s_cmd_cq", xdev->pci_dev->device.name); - size = (1 << XSC_CMDQ_DEPTH_LOG) * sizeof(struct xsc_cmdq_rsp_layout); + size = (1 << XSC_CMDQ_DEPTH_LOG) * sizeof(struct xsc_cmdq_rsp_layout); /* -V1048 */ cmdq->rsp_mz = rte_memzone_reserve_aligned(name, size, SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG, -- 2.25.1
Re: [PATCH 00/12] net/xsc: Resolve issues from PVS and Coverity Scan
Hello Stephen, Thank you for your review. I appreciate the detailed analysis and the suggestions for improvements. Please find my feedback bellow. On 2025/2/23 1:30, Stephen Hemminger wrote: > On Sat, 22 Feb 2025 11:57:59 +0800 > "Renyong Wan" wrote: > >> This patch series resolves several issues reported by PVS and Coverity Scan, >> which were earlier forwarded to us by Stephen Hemminger. >> >> --- >> Renyong Wan (12): >>net/xsc: avoid integer overflow >>net/xsc: remove useless call >>net/xsc: address incorrect format warnings >>net/xsc: remove always-true if expressions >>net/xsc: avoid variable is assigned but not used >>net/xsc: check possible null pointer dereference >>net/xsc: avoid potential null pointer before used >>net/xsc: remove always-true part of if expression >>net/xsc: avoid assign the same value to a variable >>net/xsc: avoid initialize by same function >>net/xsc: optimize memcmp returns not 0 check >>net/xsc: avoid pointer cast to unrelated class >> >> drivers/net/xsc/xsc_dev.c | 2 +- >> drivers/net/xsc/xsc_ethdev.c| 35 >> drivers/net/xsc/xsc_np.c| 17 +++--- >> drivers/net/xsc/xsc_rx.c| 31 ++- >> drivers/net/xsc/xsc_tx.c| 7 +-- >> drivers/net/xsc/xsc_vfio.c | 97 - >> drivers/net/xsc/xsc_vfio_mbox.c | 2 +- >> 7 files changed, 111 insertions(+), 80 deletions(-) >> > Applied to next-net Great to see the Coverity issues fixed. > Ran PVS Studio on it, and there are three potential things that could be > fixed later. > > 1. xsc_ethdev.c (838) > V1027 Pointer to an object of the 'rte_device' class is cast to unrelated > 'rte_pci_device' class. > > This is a generic issue in bus_pci_driver.h that can be suppressed there. Got it. Thank you. > > 2. xsc_rx.c (351) > V522 There might be dereferencing of a potential null pointer 'rxq_data'. > > Looking at the code, there are two loops over the rxq's the first one just > dereferences, and the second pass uses a helper function that could return > NULL. > Why not just use do direct index in second one: The first one doesn't seem like a best solution. It should have used the helper function xsc_rxq_get() and checked if returned null. I will optimize it next time. The second one seems to have been overlooked and not addressed. It should check the reutrn value of xsc_rxq_get(). > > -- a/drivers/net/xsc/xsc_rx.c > +++ b/drivers/net/xsc/xsc_rx.c > @@ -347,7 +347,7 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int > port_id) > rqn_base = rte_be_to_cpu_32(out->qpn_base) & 0xff; > > for (i = 0; i < priv->num_rq; i++) { > - rxq_data = xsc_rxq_get(priv, i); > + rxq_data = (*priv->rxqs)[i]; > rxq_data->wqes = rxq_data->rq_pas->addr; > if (!xsc_dev_is_vf(xdev)) > rxq_data->rq_db = (uint32_t *)((uint8_t > *)xdev->bar_addr + > > > 3. xsc_vfio_mbox.c (575) > V1048 The 'size' variable was assigned the same value. > > This one is harmless, since both commands have same size, the tool > is just being annoying. Can suppress via comment > > --- a/drivers/net/xsc/xsc_vfio_mbox.c > +++ b/drivers/net/xsc/xsc_vfio_mbox.c > @@ -572,7 +572,7 @@ xsc_vfio_mbox_init(struct xsc_dev *xdev) > cmdq->req_lay = cmdq->req_mz->addr; > > snprintf(name, RTE_MEMZONE_NAMESIZE, "%s_cmd_cq", > xdev->pci_dev->device.name); > - size = (1 << XSC_CMDQ_DEPTH_LOG) * sizeof(struct xsc_cmdq_rsp_layout); > + size = (1 << XSC_CMDQ_DEPTH_LOG) * sizeof(struct > xsc_cmdq_rsp_layout); // -V1048 OK, I understand. Since the "// -V1048" comment style will trigger an error in checkpatch, I will use the "/*-V1048*/" instead. > cmdq->rsp_mz = rte_memzone_reserve_aligned(name, > size, SOCKET_ID_ANY, > RTE_MEMZONE_IOVA_CONTIG, -- Best regards, Renyong Wan