Yunsilicon Roadmap for 24.11

2024-09-06 Thread WanRenyong
Hello, 
Please find below Yunsilicon roadmap for 24.11. 

 * Introduce XSC PMD for Yunsilicon metaScale SmartNIC

Support 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

Support NICs
--
- metaScale-200S   Single QSFP56 Port 200GE SmartNIC
- metaScale-200     Quad QSFP28 Ports 100GE SmartNIC
- metaScale-50       Dual QSFP28 Port 25GE SmartNIC
- metaScale-100Q   Quad QSFP28 Port 25GE SmartNIC

About Yunsilicon
-
Yunsilicon Technology Co., Ltd is a high tech startup focused on cloud 
datacenter ASIC product development and technology innovation.  MetaScale 
SmartNIC is designed for modern data centers, cloud environments, and 
high-performance networks and storage in AI computing centers.  
For more about Yunsilicon products, please see: 
https://www.yunsilicon.com/#/productInformation

Thanks,
WanRenyong


[PATCH 00/19] XSC PMD for Yunsilicon NICs

2024-09-06 Thread WanRenyong
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 

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


-

WanRenyong (19):
  net/xsc: add doc and minimum build framework
  net/xsc: add log macro
  net/xsc: add PCI device probe and remove
  net/xsc: add xsc device init and uninit
  net/xsc: add ioctl command interface
  net/xsc: initialize hardware information
  net/xsc: add representor ports probe
  net/xsc: create eth devices for representor ports
  net/xsc: initial representor eth device
  net/xsc: add ethdev configure and rxtx queue setup ops
  net/xsc: add mailbox and structure
  net/xsc: add ethdev RSS hash ops
  net/xsc: add ethdev start and stop ops
  net/xsc: add ethdev Rx burst
  net/xsc: add ethdev Tx burst
  net/xsc: configure xsc device hardware table
  net/xsc: add dev link and MTU ops
  net/xsc: add dev infos get
  net/xsc: add dev basic stats ops

 .mailmap |4 +
 MAINTAINERS  |9 +
 doc/guides/nics/features/xsc.ini |   18 +
 doc/guides/nics/index.rst|1 +
 doc/guides/nics/xsc.rst  |   31 +
 drivers/net/meson.build  |1 +
 drivers/net/xsc/meson.build  |   36 +
 drivers/net/xsc/xsc_ctrl.c   |   64 ++
 drivers/net/xsc/xsc_ctrl.h   |  314 +++
 drivers/net/xsc/xsc_defs.h   |   61 ++
 drivers/net/xsc/xsc_dev.c|  326 +++
 drivers/net/xsc/xsc_dev.h|   99 +++
 drivers/net/xsc/xsc_ethdev.c | 1434 ++
 drivers/net/xsc/xsc_ethdev.h |   81 ++
 drivers/net/xsc/xsc_flow.c   |  167 
 drivers/net/xsc/xsc_flow.h   |   67 ++
 drivers/net/xsc/xsc_log.h|   44 +
 drivers/net/xsc/xsc_rxtx.c   |  445 +
 drivers/net/xsc/xsc_rxtx.h   |  214 +
 drivers/net/xsc/xsc_utils.c  |  346 +++
 drivers/net/xsc/xsc_utils.h  |   27 +
 21 files changed, 3789 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_ctrl.c
 create mode 100644 drivers/net/xsc/xsc_ctrl.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_flow.c
 create mode 100644 drivers/net/xsc/xsc_flow.h
 create mode 100644 drivers/net/xsc/xsc_log.h
 create mode 100644 drivers/net/xsc/xsc_rxtx.c
 create mode 100644 drivers/net/xsc/xsc_rxtx.h
 create mode 100644 drivers/net/xsc/xsc_utils.c
 create mode 100644 drivers/net/xsc/xsc_utils.h

-- 
2.25.1


[PATCH 02/19] net/xsc: add log macro

2024-09-06 Thread WanRenyong
Add log macro to print runtime messages and trace functions.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 11 +
 drivers/net/xsc/xsc_log.h| 44 
 2 files changed, 55 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_log.h

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 0e48cb76fa..58ceaa3940 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -1,3 +1,14 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2024 Yunsilicon Technology Co., Ltd.
  */
+
+#include "xsc_log.h"
+
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
+#ifdef RTE_ETHDEV_DEBUG_RX
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_rx, rx, DEBUG);
+#endif
+#ifdef RTE_ETHDEV_DEBUG_TX
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_tx, tx, DEBUG);
+#endif
diff --git a/drivers/net/xsc/xsc_log.h b/drivers/net/xsc/xsc_log.h
new file mode 100644
index 00..163145ff09
--- /dev/null
+++ b/drivers/net/xsc/xsc_log.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_LOG_H_
+#define _XSC_LOG_H_
+
+#include 
+
+extern int xsc_logtype_init;
+extern int xsc_logtype_driver;
+
+#define PMD_INIT_LOG(level, fmt, ...) \
+   rte_log(RTE_LOG_ ## level, xsc_logtype_init, "%s(): " fmt "\n", \
+   __func__, ##__VA_ARGS__)
+
+#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
+
+#ifdef RTE_ETHDEV_DEBUG_RX
+extern int xsc_logtype_rx;
+#define PMD_RX_LOG(level, fmt, ...)\
+   rte_log(RTE_LOG_ ## level, xsc_logtype_rx,  \
+   "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define PMD_RX_LOG(level, fmt, ...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+extern int xsc_logtype_tx;
+#define PMD_TX_LOG(level, fmt, ...)\
+   rte_log(RTE_LOG_ ## level, xsc_logtype_tx,  \
+   "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define PMD_TX_LOG(level, fmt, ...) do { } while (0)
+#endif
+
+#define PMD_DRV_LOG_RAW(level, fmt, ...) \
+   rte_log(RTE_LOG_ ## level, xsc_logtype_driver, "%s(): " fmt, \
+   __func__, ##__VA_ARGS__)
+
+#define PMD_DRV_LOG(level, fmt, ...) \
+   PMD_DRV_LOG_RAW(level, fmt "\n", ##__VA_ARGS__)
+
+#endif /* _XSC_LOG_H_ */
-- 
2.25.1


[PATCH 01/19] net/xsc: add doc and minimum build framework

2024-09-06 Thread WanRenyong
Add minimum PMD code, doc and build infrastructure for xsc.

Signed-off-by: WanRenyong 
---
 .mailmap |  4 
 MAINTAINERS  |  9 +
 doc/guides/nics/features/xsc.ini |  9 +
 doc/guides/nics/index.rst|  1 +
 doc/guides/nics/xsc.rst  | 31 +++
 drivers/net/meson.build  |  1 +
 drivers/net/xsc/meson.build  | 13 +
 drivers/net/xsc/xsc_ethdev.c |  3 +++
 8 files changed, 71 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_ethdev.c

diff --git a/.mailmap b/.mailmap
index 09fa253e12..d09ed30e16 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1034,6 +1034,7 @@ Nagadheeraj Rottela 
 Naga Harish K S V 
 Naga Suresh Somarowthu 
 Nalla Pradeep 
+Na Na 
 Na Na 
 Nan Chen 
 Nannan Lu 
@@ -1268,6 +1269,7 @@ Ronak Doshi  
 Ron Beider 
 Ronghua Zhang 
 RongQiang Xie 
+Rong Qian 
 RongQing Li 
 Rongwei Liu 
 Rory Sexton 
@@ -1586,6 +1588,7 @@ Waldemar Dworakowski 
 Walter Heymans 
 Wang Sheng-Hui 
 Wangyu (Eric) 
+WanRenyong 
 Waterman Cao 
 Wathsala Vithanage 
 Weichun Chen 
@@ -1638,6 +1641,7 @@ Xiaonan Zhang 
 Xiao Wang 
 Xiaoxiao Zeng 
 Xiaoxin Peng 
+Xiaoxiong Zhang 
 Xiaoyu Min  
 Xiaoyun Li 
 Xiaoyun Wang 
diff --git a/MAINTAINERS b/MAINTAINERS
index c5a703b5c0..f87d802b24 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -994,6 +994,15 @@ F: drivers/net/txgbe/
 F: doc/guides/nics/txgbe.rst
 F: doc/guides/nics/features/txgbe.ini
 
+Yunsilicon xsc
+M: WanRenyong 
+M: Na Na 
+M: Rong Qian 
+M: Xiaoxiong Zhang 
+F: drivers/net/xsc/
+F: doc/guides/nics/xsc.rst
+F: doc/guides/nics/features/xsc.ini
+
 VMware vmxnet3
 M: Jochen Behrens 
 F: drivers/net/vmxnet3/
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 c14bc7988a..9781097a21 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -69,3 +69,4 @@ Network Interface Controller Drivers
 vhost
 virtio
 vmxnet3
+xsc
diff --git a/doc/guides/nics/xsc.rst b/doc/guides/nics/xsc.rst
new file mode 100644
index 00..d34447a259
--- /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 have not been tested and may not be supported.
+Windows and BSD are not supported yet.
diff --git a/drivers/net/meson.build b/drivers/net/meson.build
index fb6d34b782..67fbe81861 100644
--- a/drivers/net/meson.build
+++ b/drivers/net/meson.build
@@ -62,6 +62,7 @@ drivers = [
 'vhost',
 'virtio',
 'vmxnet3',
+'xsc',
 ]
 std_deps = ['ethdev', 'kvargs'] # 'ethdev' also pulls in mbuf, net, eal etc
 std_deps += ['bus_pci'] # very many PMDs depend on PCI, so make std
diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
new file mode 100644
index 00..11cdcf912b
--- /dev/null
+++ b/drivers/net/xsc/meson.build
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2024 Yunsilicon Technology Co., Ltd.
+
+if not is_linux
+build = false
+reason = 'only supported on Linux'
+endif
+
+sources = files(
+'xsc_ethdev.c',
+)
+
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
new file mode 100644
index 00..0e48cb76fa
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
-- 
2.25.1


[PATCH 04/19] net/xsc: add xsc device init and uninit

2024-09-06 Thread WanRenyong
XSC device is a concept of low level device used to manage
hardware resource and to interact with firmware.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/meson.build  |  20 +
 drivers/net/xsc/xsc_defs.h   |  23 +
 drivers/net/xsc/xsc_dev.c| 162 +++
 drivers/net/xsc/xsc_dev.h|  34 
 drivers/net/xsc/xsc_ethdev.c |  22 -
 drivers/net/xsc/xsc_ethdev.h |   1 +
 drivers/net/xsc/xsc_utils.c  |  96 +
 drivers/net/xsc/xsc_utils.h  |  14 +++
 8 files changed, 371 insertions(+), 1 deletion(-)
 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_utils.c
 create mode 100644 drivers/net/xsc/xsc_utils.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 11cdcf912b..96b4e59ac4 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -8,6 +8,26 @@ endif
 
 sources = files(
 'xsc_ethdev.c',
+'xsc_dev.c',
+'xsc_utils.c',
 )
 
+libnames = ['ibverbs']
+foreach libname:libnames
+lib = dependency('lib' + libname, method : 'pkg-config')
+if lib.found()
+ext_deps += lib
+else
+build = false
+reason = 'missing dependency, "' + lib + '"'
+subdir_done()
+endif
+endforeach
 
+lib = dependency('libxscale', required: false, method : 'pkg-config')
+if lib.found()
+ext_deps += lib
+cflags += '-DHAVE_XSC_DV_PROVIDER=1'
+else
+cflags += '-DHAVE_XSC_DV_PROVIDER=0'
+endif
diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index b4ede6eca6..97cd61b2d1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -8,5 +8,28 @@
 #define XSC_PCI_VENDOR_ID  0x1f67
 #define XSC_PCI_DEV_ID_MS  0x
 
+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,
+};
+
+enum xsc_flow_mode {
+   XSC_FLOW_OFF_HW_ONLY,
+   XSC_FLOW_ON_HW_ONLY,
+   XSC_FLOW_ON_HW_FIRST,
+   XSC_FLOW_HOTSPOT,
+   XSC_FLOW_MODE_NULL = 7,
+   XSC_FLOW_MODE_MAX,
+};
+
 #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..9673049628
--- /dev/null
+++ b/drivers/net/xsc/xsc_dev.c
@@ -0,0 +1,162 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_dev.h"
+#include "xsc_utils.h"
+
+#define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
+#define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
+
+static
+void xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs)
+{
+   struct rte_kvargs *kvlist;
+   struct xsc_devargs *xdevargs = &dev->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
+   xdevargs->flow_mode = XSC_DEV_DEF_FLOW_MODE;
+
+   rte_kvargs_free(kvlist);
+}
+
+static int
+xsc_dev_open(struct xsc_dev *dev, struct rte_pci_device *pci_dev)
+{
+   struct ibv_device *ib_dev;
+   char ctrl_file[PATH_MAX];
+   struct rte_pci_addr *pci_addr = &pci_dev->addr;
+   int ret;
+
+   ib_dev = xsc_get_ibv_device(&pci_dev->addr);
+   if (ib_dev == NULL) {
+   PMD_DRV_LOG(ERR, "Could not get ibv device");
+   return -ENODEV;
+   }
+
+   dev->ibv_ctx = ibv_open_device(ib_dev);
+   if (dev->ibv_ctx == NULL) {
+   PMD_DRV_LOG(ERR, "Could not open ibv device: %s", ib_dev->name);
+   return -ENODEV;
+   }
+
+   dev->ibv_pd = ibv_alloc_pd(dev->ibv_ctx);
+   if (dev->ibv_pd == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to create pd:%s", ib_dev->name);
+   

[PATCH 05/19] net/xsc: add ioctl command interface

2024-09-06 Thread WanRenyong
IOCTL command interface is one of methods used to interact with
firmware by PMD. By using ioctl interface, PMD sends command to
the kernel module, then the kernel module translates the command
and sends it to firmware, at last, the kernel module send back
PDM the result from firmware.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/meson.build |  1 +
 drivers/net/xsc/xsc_ctrl.c  | 56 
 drivers/net/xsc/xsc_ctrl.h  | 86 +
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_ctrl.c
 create mode 100644 drivers/net/xsc/xsc_ctrl.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 96b4e59ac4..5c989dba13 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -10,6 +10,7 @@ sources = files(
 'xsc_ethdev.c',
 'xsc_dev.c',
 'xsc_utils.c',
+'xsc_ctrl.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c
new file mode 100644
index 00..3e37bd914e
--- /dev/null
+++ b/drivers/net/xsc/xsc_ctrl.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_dev.h"
+#include "xsc_ctrl.h"
+
+int
+xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
+ void *data_in, int in_len, void *data_out, int out_len)
+{
+   struct xsc_ioctl_hdr *hdr;
+   int data_len = RTE_MAX(in_len, out_len);
+   int alloc_len = sizeof(struct xsc_ioctl_hdr) + data_len;
+   int ret = 0;
+
+   hdr = rte_zmalloc(NULL, alloc_len, RTE_CACHE_LINE_SIZE);
+   if (hdr == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to allocate xsc ioctl cmd memory");
+   return -ENOMEM;
+   }
+
+   hdr->check_field = XSC_IOCTL_CHECK_FIELD;
+   hdr->attr.opcode = opcode;
+   hdr->attr.length = data_len;
+   hdr->attr.error = 0;
+
+   if (data_in != NULL && in_len > 0)
+   rte_memcpy(hdr + 1, data_in, in_len);
+
+   ret = ioctl(dev->ctrl_fd, cmd, hdr);
+   if (ret == 0) {
+   if (hdr->attr.error != 0)
+   ret = hdr->attr.error;
+   else if (data_out != NULL && out_len > 0)
+   rte_memcpy(data_out, hdr + 1, out_len);
+   }
+
+   rte_free(hdr);
+   return ret;
+}
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
new file mode 100644
index 00..d343e1b1a7
--- /dev/null
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_CTRL_H_
+#define _XSC_CTRL_H_
+
+#include 
+
+#define XSC_IOCTL_CHECK_FIELD  0x01234567
+
+#define XSC_IOCTL_MAGIC0x1b
+#define XSC_IOCTL_CMDQ \
+   _IOWR(XSC_IOCTL_MAGIC, 1, struct xsc_ioctl_hdr)
+#define XSC_IOCTL_DRV_GET \
+   _IOR(XSC_IOCTL_MAGIC, 2, struct xsc_ioctl_hdr)
+#define XSC_IOCTL_CMDQ_RAW \
+   _IOWR(XSC_IOCTL_MAGIC, 5, struct xsc_ioctl_hdr)
+
+enum xsc_ioctl_opcode {
+   XSC_IOCTL_GET_HW_INFO   = 0x100,
+};
+
+enum xsc_ioctl_opmod {
+   XSC_IOCTL_OP_GET_LOCAL,
+};
+
+struct xsc_ioctl_attr {
+   uint16_t opcode; /* ioctl cmd */
+   uint16_t length; /* data length */
+   uint32_t error;  /* ioctl error info */
+   uint8_t data[0]; /* specific table info */
+};
+
+struct xsc_ioctl_hdr {
+   uint32_t check_field;
+   uint32_t domain;
+   uint32_t bus;
+   uint32_t devfn;
+   struct xsc_ioctl_attr attr;
+};
+
+struct xsc_ioctl_data_tl {
+   uint16_t table;
+   uint16_t opmod;
+   uint16_t length;
+   uint16_t rsvd;
+};
+
+struct xsc_ioctl_get_hwinfo {
+   uint32_t domain;
+   uint32_t bus;
+   uint32_t devfn;
+   uint32_t pcie_no;
+   uint32_t func_id;
+   uint32_t pcie_host;
+   uint32_t mac_phy_port;
+   uint32_t funcid_to_logic_port_off;
+   uint16_t lag_id;
+   uint16_t raw_qp_id_base;
+   uint16_t raw_rss_qp_id_base;
+   uint16_t pf0_vf_funcid_base;
+   uint16_t pf0_vf_funcid_top;
+   uint16_t pf1_vf_funcid_base;
+   uint16_t pf1_vf_funcid_top;
+   uint16_t pcie0_pf_funcid_base;
+   uint16_t pcie0_pf_funcid_top;
+   uint16_t pcie1_pf_funcid_base;
+   uint16_t pcie1_pf_funcid_top;
+   uint16_t lag_port_start;
+   uint16_t raw_tpe_qp_num;
+   int send_seg_num;
+   int recv_seg_num;
+   uint8_t on_chip_tbl_vld;
+   uint8_t dma_rw_tbl_vld;
+   uint8_t pct_compress_vld;
+   uint32_t chip_version;
+   uint32_t hca_core_clock;
+   uint8_t mac_bit;
+   uint8_t esw_mode

[PATCH 06/19] net/xsc: initialize hardware information

2024-09-06 Thread WanRenyong
Getting hardware information is done by ioctl command, which
contains the information of xsc device, as well as the common
information of the NIC board.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_dev.c | 63 +++
 drivers/net/xsc/xsc_dev.h | 32 
 2 files changed, 95 insertions(+)

diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 9673049628..1eb68ac95d 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -18,10 +18,64 @@
 #include "xsc_defs.h"
 #include "xsc_dev.h"
 #include "xsc_utils.h"
+#include "xsc_ctrl.h"
 
 #define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
 #define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
 
+static int xsc_hwinfo_init(struct xsc_dev *dev)
+{
+   struct {
+   struct xsc_ioctl_data_tl tl;
+   struct xsc_ioctl_get_hwinfo hwinfo;
+   } data;
+   struct xsc_ioctl_get_hwinfo *info = &data.hwinfo;
+   int data_len;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   data_len = sizeof(data);
+   data.tl.opmod = XSC_IOCTL_OP_GET_LOCAL;
+   ret = xsc_ioctl(dev, XSC_IOCTL_DRV_GET, XSC_IOCTL_GET_HW_INFO, &data, 
data_len,
+   &data, data_len);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to get hardware info");
+   return ret;
+   }
+
+   dev->hwinfo.valid = 1;
+   dev->hwinfo.pcie_no = info->pcie_no;
+   dev->hwinfo.func_id = info->func_id;
+   dev->hwinfo.pcie_host = info->pcie_host;
+   dev->hwinfo.mac_phy_port = info->mac_phy_port;
+   dev->hwinfo.funcid_to_logic_port_off = info->funcid_to_logic_port_off;
+   dev->hwinfo.lag_id = info->lag_id;
+   dev->hwinfo.raw_qp_id_base = info->raw_qp_id_base;
+   dev->hwinfo.raw_rss_qp_id_base = info->raw_rss_qp_id_base;
+   dev->hwinfo.pf0_vf_funcid_base = info->pf0_vf_funcid_base;
+   dev->hwinfo.pf0_vf_funcid_top = info->pf0_vf_funcid_top;
+   dev->hwinfo.pf1_vf_funcid_base = info->pf1_vf_funcid_base;
+   dev->hwinfo.pf1_vf_funcid_top = info->pf1_vf_funcid_top;
+   dev->hwinfo.pcie0_pf_funcid_base = info->pcie0_pf_funcid_base;
+   dev->hwinfo.pcie0_pf_funcid_top = info->pcie0_pf_funcid_top;
+   dev->hwinfo.pcie1_pf_funcid_base = info->pcie1_pf_funcid_base;
+   dev->hwinfo.pcie1_pf_funcid_top = info->pcie1_pf_funcid_top;
+   dev->hwinfo.lag_port_start = info->lag_port_start;
+   dev->hwinfo.raw_tpe_qp_num = info->raw_tpe_qp_num;
+   dev->hwinfo.send_seg_num = info->send_seg_num;
+   dev->hwinfo.recv_seg_num = info->recv_seg_num;
+   dev->hwinfo.on_chip_tbl_vld = info->on_chip_tbl_vld;
+   dev->hwinfo.dma_rw_tbl_vld = info->dma_rw_tbl_vld;
+   dev->hwinfo.pct_compress_vld = info->pct_compress_vld;
+   dev->hwinfo.chip_version = info->chip_version;
+   dev->hwinfo.hca_core_clock = info->hca_core_clock;
+   dev->hwinfo.mac_bit = info->mac_bit;
+   dev->hwinfo.esw_mode = info->esw_mode;
+
+   return 0;
+}
+
 static
 void xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs)
 {
@@ -142,11 +196,20 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct 
xsc_dev **dev)
goto dev_open_fail;
}
 
+   ret = xsc_hwinfo_init(d);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Failed to initialize hardware info");
+   goto hwinfo_init_fail;
+   return ret;
+   }
+
d->pci_dev = pci_dev;
*dev = d;
 
return 0;
 
+hwinfo_init_fail:
+   xsc_dev_close(d);
 dev_open_fail:
rte_free(d);
return ret;
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index ce9dd65400..5f0e911b42 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -11,6 +11,37 @@
 #define XSC_NIC_MODE_ARG "nic_mode"
 #define XSC_FLOW_MODE_ARG "flow_mode"
 
+struct xsc_hwinfo {
+   uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
+   uint32_t pcie_no; /* pcie number , 0 or 1 */
+   uint32_t func_id; /* pf glb func id */
+   uint32_t pcie_host; /* host pcie number */
+   uint32_t mac_phy_port; /* mac port */
+   uint32_t funcid_to_logic_port_off; /* port func id offset  */
+   uint16_t lag_id;
+   uint16_t raw_qp_id_base;
+   uint16_t raw_rss_qp_id_base;
+   uint16_t pf0_vf_funcid_base;
+   uint16_t pf0_vf_funcid_top;
+   uint16_t pf1_vf_funcid_base;
+   uint16_t pf1_vf_funcid_top;
+   uint16_t pcie0_pf_funcid_base;
+   uint16_t pcie0_pf_funcid_top;
+   uint16_t pcie1_pf_funcid_base;
+   uint16_t pcie1_pf_funcid_top;
+   uint16_t lag_port_start;
+

[PATCH 03/19] net/xsc: add PCI device probe and remove

2024-09-06 Thread WanRenyong
Support the following Yunsilicon NICs to be probed:

- metaScale-200
- metaScale-200S
- metaScale-50
- metaScale-100Q

Signed-off-by: WanRenyong 
Signed-off-by: Na Na 
---
 drivers/net/xsc/xsc_defs.h   | 12 ++
 drivers/net/xsc/xsc_ethdev.c | 74 
 drivers/net/xsc/xsc_ethdev.h | 16 
 3 files changed, 102 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_defs.h
 create mode 100644 drivers/net/xsc/xsc_ethdev.h

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
new file mode 100644
index 00..b4ede6eca6
--- /dev/null
+++ b/drivers/net/xsc/xsc_defs.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef XSC_DEFS_H_
+#define XSC_DEFS_H_
+
+#define XSC_PCI_VENDOR_ID  0x1f67
+#define XSC_PCI_DEV_ID_MS  0x
+
+#endif /* XSC_DEFS_H_ */
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 58ceaa3940..8f4d539848 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -2,7 +2,81 @@
  * Copyright 2024 Yunsilicon Technology Co., Ltd.
  */
 
+#include 
+
 #include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_ethdev.h"
+
+static int
+xsc_ethdev_init(struct rte_eth_dev *eth_dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+   PMD_INIT_FUNC_TRACE();
+
+   priv->eth_dev = eth_dev;
+   priv->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+   return 0;
+}
+
+static int
+xsc_ethdev_uninit(struct rte_eth_dev *eth_dev)
+{
+   RTE_SET_USED(eth_dev);
+   PMD_INIT_FUNC_TRACE();
+
+   return 0;
+}
+
+static int
+xsc_ethdev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+struct rte_pci_device *pci_dev)
+{
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = rte_eth_dev_pci_generic_probe(pci_dev,
+   sizeof(struct xsc_ethdev_priv),
+   xsc_ethdev_init);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Failed to probe ethdev: %s", pci_dev->name);
+   return ret;
+   }
+
+   return 0;
+}
+
+static int
+xsc_ethdev_pci_remove(struct rte_pci_device *pci_dev)
+{
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = rte_eth_dev_pci_generic_remove(pci_dev, xsc_ethdev_uninit);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Could not remove ethdev: %s", pci_dev->name);
+   return ret;
+   }
+
+   return 0;
+}
+
+static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
+   { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
+};
+
+static struct rte_pci_driver xsc_ethdev_pci_driver = {
+   .id_table  = xsc_ethdev_pci_id_map,
+   .probe = xsc_ethdev_pci_probe,
+   .remove = xsc_ethdev_pci_remove,
+};
+
+RTE_PMD_REGISTER_PCI(net_xsc, xsc_ethdev_pci_driver);
+RTE_PMD_REGISTER_PCI_TABLE(net_xsc, xsc_ethdev_pci_id_map);
 
 RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
 RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
new file mode 100644
index 00..75aa34dc63
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_ETHDEV_H_
+#define _XSC_ETHDEV_H_
+
+struct xsc_ethdev_priv {
+   struct rte_eth_dev *eth_dev;
+   struct rte_pci_device *pci_dev;
+};
+
+#define TO_XSC_ETHDEV_PRIV(dev) \
+   ((struct xsc_ethdev_priv *)(dev)->data->dev_private)
+
+#endif /* _XSC_ETHDEV_H_ */
-- 
2.25.1


[PATCH 09/19] net/xsc: initial representor eth device

2024-09-06 Thread WanRenyong
Initialize xsc eth device private data.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_defs.h   |   2 +-
 drivers/net/xsc/xsc_dev.h|   3 +
 drivers/net/xsc/xsc_ethdev.c |  64 +
 drivers/net/xsc/xsc_ethdev.h |  30 ++
 drivers/net/xsc/xsc_utils.c  | 105 +++
 drivers/net/xsc/xsc_utils.h  |   8 ++-
 6 files changed, 210 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 8cb67ed2e1..7dc57e5717 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -10,7 +10,7 @@
 
 #define XSC_VFREP_BASE_LOGICAL_PORT 1081
 
-
+#define XSC_MAX_MAC_ADDRESSES 3
 
 enum xsc_nic_mode {
XSC_NIC_MODE_LEGACY,
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index 93ab1e24fe..f77551f1c5 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -15,6 +15,9 @@
 
 #define XSC_DEV_REPR_PORT  0
 
+#define FUNCID_TYPE_MASK 0x1c000
+#define FUNCID_MASK 0x3fff
+
 struct xsc_hwinfo {
uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
uint32_t pcie_no; /* pcie number , 0 or 1 */
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index d6efc3c9a0..aacce8b90d 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -8,15 +8,79 @@
 #include "xsc_defs.h"
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
+#include "xsc_utils.h"
+
+#include "xsc_ctrl.h"
+
+const struct eth_dev_ops xsc_dev_ops = {
+};
 
 static int
 xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
 {
struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+   struct xsc_dev_config *config = &priv->config;
+   struct rte_ether_addr mac;
 
priv->repr_port = repr_port;
repr_port->drv_data = eth_dev;
+   priv->xdev = repr_port->xdev;
+   priv->mtu = RTE_ETHER_MTU;
+   priv->funcid_type = (repr_port->info.funcid & FUNCID_TYPE_MASK) >> 14;
+   priv->funcid = repr_port->info.funcid & FUNCID_MASK;
+   if (repr_port->info.port_type == XSC_PORT_TYPE_UPLINK ||
+   repr_port->info.port_type == XSC_PORT_TYPE_UPLINK_BOND)
+   priv->eth_type = RTE_ETH_REPRESENTOR_PF;
+   else
+   priv->eth_type = RTE_ETH_REPRESENTOR_VF;
+   priv->representor_id = repr_port->info.repr_id;
+   priv->dev_data = eth_dev->data;
+   priv->ifindex = repr_port->info.ifindex;
+
+   eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+   eth_dev->data->mac_addrs = priv->mac;
+   if (rte_is_zero_ether_addr(eth_dev->data->mac_addrs)) {
+   if (priv->ifindex > 0) {
+   int ret  = xsc_get_mac(mac.addr_bytes, priv->ifindex);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "port %u cannot get MAC 
address",
+   eth_dev->data->port_id);
+   return -ENODEV;
+   }
+   } else {
+   rte_eth_random_addr(mac.addr_bytes);
+   }
+   }
+
+   xsc_mac_addr_add(eth_dev, &mac, 0);
+
+   if (priv->ifindex > 0)
+   xsc_get_mtu(&priv->mtu, priv->ifindex);
+
+   config->hw_csum = 1;
+
+   config->pph_flag =  priv->xdev->devargs.pph_mode;
+   if ((config->pph_flag & XSC_TX_PPH) != 0) {
+   config->tso = 0;
+   } else {
+   config->tso = 1;
+   if (config->tso)
+   config->tso_max_payload_sz = 1500;
+   }
+
+   priv->representor = !!priv->eth_type;
+   if (priv->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;
+   }
+   eth_dev->dev_ops = &xsc_dev_ops;
+
+   eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
+   eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
+
+   rte_eth_dev_probing_finish(eth_dev);
 
return 0;
 }
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index a05a63193c..7c7e71d618 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -5,11 +5,41 @@
 #ifndef _XSC_ETHDEV_H_
 #define _XSC_ETHDEV_H_
 
+struct xsc_dev_config {
+   uint8_t pph_flag;
+   unsigned int hw_csum:1;
+   unsigned int tso:1;
+   unsigned int tso_max_payload_sz;
+};
+
 struct xsc_ethdev_priv {
struct rte_eth_dev 

[PATCH 10/19] net/xsc: add ethdev configure and rxtx queue setup ops

2024-09-06 Thread WanRenyong
Implement xsc ethdev configure, Rx and Tx queue setup functions.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 171 +++
 drivers/net/xsc/xsc_ethdev.h |   6 ++
 drivers/net/xsc/xsc_rxtx.h   | 115 +++
 3 files changed, 292 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_rxtx.h

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index aacce8b90d..5ad9567eb3 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -11,8 +11,179 @@
 #include "xsc_utils.h"
 
 #include "xsc_ctrl.h"
+#include "xsc_rxtx.h"
+
+static int
+xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, uint8_t *rss_key,
+  uint8_t rss_key_len)
+{
+   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;
+
+   if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN ||
+   rss_conf->rss_key == NULL) {
+   PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
+   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+   return -EINVAL;
+   }
+
+   ret = xsc_rss_modify_cmd(priv, rss_conf->rss_key, 
rss_conf->rss_key_len);
+   if (ret == 0) {
+   rte_memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
+   priv->rss_conf.rss_key_len);
+   priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
+   priv->rss_conf.rss_hf = rss_conf->rss_hf;
+   }
+
+   return ret;
+}
+
+static int
+xsc_ethdev_configure(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+   int ret;
+   struct rte_eth_rss_conf *rss_conf;
+
+   priv->num_sq = dev->data->nb_tx_queues;
+   priv->num_rq = dev->data->nb_rx_queues;
+
+   if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
+   dev->data->dev_conf.rxmode.offloads |= 
RTE_ETH_RX_OFFLOAD_RSS_HASH;
+
+   if (priv->rss_conf.rss_key == NULL) {
+   priv->rss_conf.rss_key = rte_zmalloc(NULL, XSC_RSS_HASH_KEY_LEN,
+   RTE_CACHE_LINE_SIZE);
+   if (priv->rss_conf.rss_key == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to alloc rss_key");
+   rte_errno = ENOMEM;
+   ret = -rte_errno;
+   goto error;
+   }
+   priv->rss_conf.rss_key_len = XSC_RSS_HASH_KEY_LEN;
+   }
+
+   if (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key != NULL) {
+   rss_conf = &dev->data->dev_conf.rx_adv_conf.rss_conf;
+   ret = xsc_ethdev_rss_hash_update(dev, rss_conf);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Xsc pmd set rss key error!");
+   rte_errno = -ENOEXEC;
+   goto error;
+   }
+   }
+
+   if (rxmode->offloads && RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
+   PMD_DRV_LOG(ERR, "xsc pmd do not support vlan filter now!");
+   rte_errno = EINVAL;
+   goto error;
+   }
+
+   if (rxmode->offloads && RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
+   PMD_DRV_LOG(ERR, "xsc pmd do not support vlan strip now!");
+   rte_errno = EINVAL;
+   goto error;
+   }
+
+   priv->txqs = (void *)dev->data->tx_queues;
+   priv->rxqs = (void *)dev->data->rx_queues;
+   return 0;
+
+error:
+   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",
+  

[PATCH 08/19] net/xsc: create eth devices for representor ports

2024-09-06 Thread WanRenyong
Each representor port is a rte ethernet device.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 87 
 drivers/net/xsc/xsc_ethdev.h |  1 +
 2 files changed, 88 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 6a33cbb2cd..d6efc3c9a0 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -9,6 +9,83 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 
+static int
+xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
+{
+   struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+   priv->repr_port = repr_port;
+   repr_port->drv_data = eth_dev;
+
+   return 0;
+}
+
+static int
+xsc_ethdev_init_representors(struct rte_eth_dev *eth_dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+   struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
+   struct rte_device *dev;
+   struct xsc_dev *xdev;
+   struct xsc_repr_port *repr_port;
+   char name[RTE_ETH_NAME_MAX_LEN];
+   int i;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   dev = &priv->pci_dev->device;
+   if (dev->devargs != NULL) {
+   ret = rte_eth_devargs_parse(dev->devargs->args, ð_da, 1);
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "Failed to parse device arguments: %s",
+   dev->devargs->args);
+   return -EINVAL;
+   }
+   }
+
+   xdev = priv->xdev;
+   ret = xsc_repr_ports_probe(xdev, eth_da.nb_representor_ports, 
RTE_MAX_ETHPORTS);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to probe %d xsc device representors",
+   eth_da.nb_representor_ports);
+   return ret;
+   }
+
+   repr_port = &xdev->repr_ports[XSC_DEV_REPR_PORT];
+   ret = xsc_ethdev_init_one_representor(eth_dev, repr_port);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to init backing representor");
+   return ret;
+   }
+
+   for (i = 1; i < xdev->num_repr_ports; i++) {
+   repr_port = &xdev->repr_ports[i];
+   snprintf(name, sizeof(name), "%s_rep_%d",
+xdev->ibv_name, repr_port->info.repr_id);
+   ret = rte_eth_dev_create(&xdev->pci_dev->device,
+name,
+sizeof(struct xsc_ethdev_priv),
+NULL, NULL,
+xsc_ethdev_init_one_representor,
+repr_port);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to create representor: %d", i);
+   goto destroy_reprs;
+   }
+   }
+
+   return 0;
+
+destroy_reprs:
+   while ((i--) > 1) {
+   repr_port = &xdev->repr_ports[i];
+   rte_eth_dev_destroy((struct rte_eth_dev *)repr_port->drv_data, 
NULL);
+   }
+   return ret;
+}
+
 static int
 xsc_ethdev_init(struct rte_eth_dev *eth_dev)
 {
@@ -26,7 +103,17 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev)
return ret;
}
 
+   ret = xsc_ethdev_init_representors(eth_dev);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to initialize representors");
+   goto uninit_xsc_dev;
+   }
+
return 0;
+
+uninit_xsc_dev:
+   xsc_dev_uninit(priv->xdev);
+   return ret;
 }
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 22fc462e25..a05a63193c 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,7 @@ struct xsc_ethdev_priv {
struct rte_eth_dev *eth_dev;
struct rte_pci_device *pci_dev;
struct xsc_dev *xdev;
+   struct xsc_repr_port *repr_port;
 };
 
 #define TO_XSC_ETHDEV_PRIV(dev) \
-- 
2.25.1


[PATCH 07/19] net/xsc: add representor ports probe

2024-09-06 Thread WanRenyong
XSC representor port is designed to store representor resources.
In addition to common representor ports, xsc device is a special
representor port.

Signed-off-by: WanRenyong 
Signed-off-by: Na Na 
---
 drivers/net/xsc/xsc_defs.h  |  24 +++
 drivers/net/xsc/xsc_dev.c   | 103 +-
 drivers/net/xsc/xsc_dev.h   |  27 
 drivers/net/xsc/xsc_utils.c | 122 
 drivers/net/xsc/xsc_utils.h |   3 +
 5 files changed, 278 insertions(+), 1 deletion(-)

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 97cd61b2d1..8cb67ed2e1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -8,6 +8,10 @@
 #define XSC_PCI_VENDOR_ID  0x1f67
 #define XSC_PCI_DEV_ID_MS  0x
 
+#define XSC_VFREP_BASE_LOGICAL_PORT 1081
+
+
+
 enum xsc_nic_mode {
XSC_NIC_MODE_LEGACY,
XSC_NIC_MODE_SWITCHDEV,
@@ -31,5 +35,25 @@ enum xsc_flow_mode {
XSC_FLOW_MODE_MAX,
 };
 
+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_phy_port_type {
+   XSC_PORT_TYPE_NONE = 0,
+   XSC_PORT_TYPE_UPLINK, /* mac0rep */
+   XSC_PORT_TYPE_UPLINK_BOND, /* bondrep */
+   XSC_PORT_TYPE_PFVF, /*hasreps: vfrep*/
+   XSC_PORT_TYPE_PFHPF, /*hasreps: host pf rep*/
+   XSC_PORT_TYPE_UNKNOWN,
+};
+
+#define XSC_PHY_PORT_NUM 1
+
 #endif /* XSC_DEFS_H_ */
 
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 1eb68ac95d..3ba9a16116 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -23,6 +23,31 @@
 #define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
 #define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
 
+static int
+xsc_dev_alloc_vfos_info(struct xsc_dev *dev)
+{
+   struct xsc_hwinfo *hwinfo;
+   int vfrep_offset = 0;
+   int base_lp = 0;
+
+   hwinfo = &dev->hwinfo;
+   if (hwinfo->pcie_no == 1) {
+   vfrep_offset = hwinfo->func_id -
+  hwinfo->pcie1_pf_funcid_base +
+  hwinfo->pcie0_pf_funcid_top -
+  hwinfo->pcie0_pf_funcid_base  + 1;
+   } else {
+   vfrep_offset = hwinfo->func_id - hwinfo->pcie0_pf_funcid_base;
+   }
+
+   base_lp = XSC_VFREP_BASE_LOGICAL_PORT;
+   if (dev->devargs.nic_mode == XSC_NIC_MODE_LEGACY)
+   base_lp = base_lp + vfrep_offset;
+
+   dev->vfos_logical_in_port = base_lp;
+   return 0;
+}
+
 static int xsc_hwinfo_init(struct xsc_dev *dev)
 {
struct {
@@ -174,6 +199,73 @@ xsc_dev_close(struct xsc_dev *dev)
ibv_close_device(dev->ibv_ctx);
 }
 
+static void
+xsc_repr_info_init(struct xsc_repr_info *info, enum xsc_phy_port_type 
port_type,
+  enum xsc_funcid_type funcid_type, int32_t repr_id)
+{
+   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 = XSC_PHYPORT_MAC_FUNCID << 14;
+   } else if (port_type == XSC_PORT_TYPE_PFVF) {
+   info->funcid = funcid_type << 14;
+   }
+}
+
+int
+xsc_repr_ports_probe(struct xsc_dev *dev, int nb_ports, int max_nb_ports)
+{
+   int funcid_type;
+   struct xsc_repr_port *repr_port;
+   int i;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = xsc_get_ifindex_by_pci_addr(&dev->pci_dev->addr, &dev->ifindex);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Could not get xsc dev ifindex");
+   return ret;
+   }
+
+   dev->num_repr_ports = nb_ports + 1;
+
+   dev->repr_ports = rte_zmalloc(NULL,
+ sizeof(struct xsc_repr_port) * 
dev->num_repr_ports,
+ RTE_CACHE_LINE_SIZE);
+   if (dev->repr_ports == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to allocate memory for repr_ports");
+   return -ENOMEM;
+   }
+
+   funcid_type = (dev->devargs.nic_mode == XSC_NIC_MODE_SWITCHDEV) ?
+   XSC_VF_IOCTL_FUNCID : XSC_PHYPORT_MAC_FUNCID;
+
+   repr_port = &dev->repr_ports[XSC_DEV_REPR_PORT];
+   xsc_repr_info_init(&repr_port->info,
+  XSC_PORT_TYPE_UPLINK, XSC_FUNCID_TYPE_UNKNOWN, -1);
+   repr_port->info.ifindex = dev->ifindex;
+   repr_port->xdev = dev;
+
+   if ((dev->devargs.pph_mode & XSC_TX_PPH) == 0)
+   repr_port->info.rep

[PATCH 11/19] net/xsc: add mailbox and structure

2024-09-06 Thread WanRenyong
Mailbox is a communication channel between driver and firmware.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ctrl.c |  8 
 drivers/net/xsc/xsc_ctrl.h | 31 +++
 2 files changed, 39 insertions(+)

diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c
index 3e37bd914e..4d5e4b4d07 100644
--- a/drivers/net/xsc/xsc_ctrl.c
+++ b/drivers/net/xsc/xsc_ctrl.c
@@ -54,3 +54,11 @@ xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
rte_free(hdr);
return ret;
 }
+
+int
+xsc_mailbox_exec(struct xsc_dev *dev, void *data_in,
+int in_len, void *data_out, int out_len)
+{
+   /* ignore opcode in hdr->attr when cmd = XSC_IOCTL_CMDQ_RAW */
+   return xsc_ioctl(dev, XSC_IOCTL_CMDQ_RAW, 0, data_in, in_len, data_out, 
out_len);
+}
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index d343e1b1a7..a7259c5fcb 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -40,6 +40,35 @@ struct xsc_ioctl_hdr {
struct xsc_ioctl_attr attr;
 };
 
+/* ioctl */
+struct xsc_inbox_hdr {
+   __be16 opcode;
+   uint8_trsvd[4];
+   __be16 opmod;
+};
+
+struct xsc_outbox_hdr {
+   uint8_t status;
+   uint8_t rsvd[3];
+   __be32  syndrome;
+};
+
+/* ioctl mbox */
+struct xsc_ioctl_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be16  len;
+   __be16  rsvd;
+   uint8_t data[];
+};
+
+struct xsc_ioctl_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   __be32  error;
+   __be16  len;
+   __be16  rsvd;
+   uint8_t data[];
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
@@ -82,5 +111,7 @@ struct xsc_ioctl_get_hwinfo {
 
 int xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
  void *data_in, int in_len, void *data_out, int out_len);
+int xsc_mailbox_exec(struct xsc_dev *dev, void *data_in,
+int in_len, void *data_out, int out_len);
 
 #endif /* _XSC_CTRL_H_ */
-- 
2.25.1


[PATCH 14/19] net/xsc: add ethdev Rx burst

2024-09-06 Thread WanRenyong
Implement xsc PMD receive function.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 
---
 drivers/net/xsc/xsc_rxtx.c | 189 -
 drivers/net/xsc/xsc_rxtx.h |   9 ++
 2 files changed, 197 insertions(+), 1 deletion(-)

diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 66b1511c6a..28360e62ff 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -7,11 +7,198 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 #include "xsc_rxtx.h"
+#include "xsc_utils.h"
+#include "xsc_ctrl.h"
+
+#define XSC_CQE_OWNER_MASK 0x1
+#define XSC_CQE_OWNER_HW   0x2
+#define XSC_CQE_OWNER_SW   0x4
+#define XSC_CQE_OWNER_ERR  0x8
+
+#define XSC_MAX_RX_BURST_MBUFS 64
+
+static __rte_always_inline int
+check_cqe_own(volatile struct xsc_cqe *cqe, const uint16_t cqe_n,
+ const uint16_t ci)
+
+{
+   if (unlikely(((cqe->owner & XSC_CQE_OWNER_MASK) !=
+   ((ci >> cqe_n) & XSC_CQE_OWNER_MASK
+   return XSC_CQE_OWNER_HW;
+
+   rte_io_rmb();
+   if (cqe->msg_len <= 0 && cqe->is_error)
+   return XSC_CQE_OWNER_ERR;
+
+   return XSC_CQE_OWNER_SW;
+}
+
+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 = check_cqe_own(cqe, rxq->cqe_n, rxq->cq_ci);
+   if (unlikely(ret != XSC_CQE_OWNER_SW)) {
+   if (unlikely(ret == XSC_CQE_OWNER_ERR)) {
+   /* TODO */
+   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)
 {
-   return 0;
+   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;
+   uint32_t rq_ci = rxq->rq_ci;
+   int len = 0;
+   uint32_t cq_ci_two = 0;
+   int read_cqe_num = 0;
+   int read_cqe_num_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))
+   break;
+
+   if (!pkt) {
+   if (read_cqe_num) {
+   cqe = cqe + 1;
+   len = read_cqe_num_len;
+   read_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) {
+   read_cqe_num_len = xsc_rx_poll_len(rxq, 
cqe + 1);
+

[PATCH 13/19] net/xsc: add ethdev start and stop ops

2024-09-06 Thread WanRenyong
Implement xsc ethdev start and stop function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 drivers/net/xsc/meson.build  |   1 +
 drivers/net/xsc/xsc_ctrl.h   | 152 ++-
 drivers/net/xsc/xsc_defs.h   |   2 +
 drivers/net/xsc/xsc_dev.h|   3 +
 drivers/net/xsc/xsc_ethdev.c | 740 ++-
 drivers/net/xsc/xsc_ethdev.h |  10 +
 drivers/net/xsc/xsc_rxtx.c   |  22 ++
 drivers/net/xsc/xsc_rxtx.h   |  68 +++-
 8 files changed, 994 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/xsc/xsc_rxtx.c

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 5c989dba13..2fc4e5ace7 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -11,6 +11,7 @@ sources = files(
 'xsc_dev.c',
 'xsc_utils.c',
 'xsc_ctrl.c',
+'xsc_rxtx.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index c33e625097..e51847d68f 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -5,7 +5,17 @@
 #ifndef _XSC_CTRL_H_
 #define _XSC_CTRL_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE  4096
+#endif
 
 #define XSC_IOCTL_CHECK_FIELD  0x01234567
 
@@ -25,6 +35,17 @@ enum xsc_ioctl_opmod {
XSC_IOCTL_OP_GET_LOCAL,
 };
 
+#define XSC_DIV_ROUND_UP(n, d) ({ \
+   typeof(d) _d = (d); \
+   typeof(n) _n = (n); \
+   ((_n) + (_d) - 1) / (_d); \
+})
+
+enum {
+   XSC_IOCTL_SET_QP_STATUS = 0x200,
+   XSC_IOCTL_SET_MAX
+};
+
 struct xsc_ioctl_attr {
uint16_t opcode; /* ioctl cmd */
uint16_t length; /* data length */
@@ -40,7 +61,18 @@ struct xsc_ioctl_hdr {
struct xsc_ioctl_attr attr;
 };
 
-/* ioctl */
+enum {
+   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_inbox_hdr {
__be16 opcode;
uint8_trsvd[4];
@@ -53,7 +85,6 @@ struct xsc_outbox_hdr {
__be32  syndrome;
 };
 
-/* ioctl mbox */
 struct xsc_ioctl_mbox_in {
struct xsc_inbox_hdrhdr;
__be16  len;
@@ -96,6 +127,54 @@ struct xsc_cmd_modify_nic_hca_mbox_out {
uint8_t rsvd0[4];
 };
 
+struct xsc_create_qp_request {
+   __be16  input_qpn;
+   __be16  pa_num;
+   uint8_t qp_type;
+   uint8_t log_sq_sz;
+   uint8_t log_rq_sz;
+   uint8_t dma_direct;
+   __be32  pdn;
+   __be16  cqn_send;
+   __be16  cqn_recv;
+   __be16  glb_funcid;
+   uint8_t page_shift;
+   uint8_t rsvd;
+   __be64  pas[];
+};
+
+struct xsc_create_multiqp_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be16  qp_num;
+   uint8_t qp_type;
+   uint8_t rsvd;
+   __be32  req_len;
+   uint8_t data[];
+};
+
+struct xsc_create_multiqp_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   __be32  qpn_base;
+};
+
+
+struct xsc_destroy_qp_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be32  qpn;
+   uint8_t rsvd[4];
+};
+
+struct xsc_destroy_qp_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   uint8_t rsvd[8];
+};
+
+struct xsc_ioctl_qp_range {
+   uint16_topcode;
+   int num;
+   uint32_tqpn;
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
@@ -136,6 +215,75 @@ struct xsc_ioctl_get_hwinfo {
uint8_t esw_mode;
 };
 
+/* for xscdv providers */
+#if !HAVE_XSC_DV_PROVIDER
+enum xscdv_obj_type {
+   XSCDV_OBJ_QP= 1 << 0,
+   XSCDV_OBJ_CQ= 1 << 1,
+   XSCDV_OBJ_SRQ   = 1 << 2,
+   XSCDV_OBJ_RWQ   = 1 << 3,
+   XSCDV_OBJ_DM= 1 << 4,
+   XSCDV_OBJ_AH= 1 << 5,
+   XSCDV_OBJ_PD= 1 << 6,
+};
+
+enum xsc_qp_create_flags {
+   XSC_QP_CREATE_RAWPACKE_TSO  = 1 << 0,
+   XSC_QP_CREATE_RAWPACKET_TSO = 1 << 0,
+   XSC_QP_CREATE_RAWPACKET_TX  = 1 << 1,
+};
+
+struct xscdv_cq_init_attr {
+   uint64_t comp_mask; /* Use enum xscdv_cq_init_attr_mask */
+   uint8_t cqe_comp_res_format; /* Use enum xscdv_cqe_comp_res_format */
+   uint32_t flags;
+   uint16_t cqe_size; /* when XSCDV_CQ_INIT_AT

[PATCH 15/19] net/xsc: add ethdev Tx burst

2024-09-06 Thread WanRenyong
Implement xsc PMD transmit function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 doc/guides/nics/features/xsc.ini |   4 +
 drivers/net/xsc/xsc_rxtx.c   | 231 ++-
 drivers/net/xsc/xsc_rxtx.h   |   9 ++
 3 files changed, 242 insertions(+), 2 deletions(-)

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_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 28360e62ff..7a31cd428c 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -14,6 +14,8 @@
 #define XSC_CQE_OWNER_HW   0x2
 #define XSC_CQE_OWNER_SW   0x4
 #define XSC_CQE_OWNER_ERR  0x8
+#define XSC_OPCODE_RAW 0x7
+#define XSC_TX_COMP_CQE_HANDLE_MAX 2
 
 #define XSC_MAX_RX_BURST_MBUFS 64
 
@@ -201,9 +203,234 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, 
uint16_t pkts_n)
return nb_pkts;
 }
 
+static __rte_always_inline void
+xsc_tx_elts_free(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 = 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;
+   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_compiler_barrier();
+   *txq->cq_db = rte_cpu_to_le_32(cq_db.cq_data);
+
+   /* 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_free(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;
+
+   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(mbu

[PATCH 12/19] net/xsc: add ethdev RSS hash ops

2024-09-06 Thread WanRenyong
Implement xsc ethdev RSS hash config get and update functions.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  3 +++
 drivers/net/xsc/xsc_ctrl.h   | 27 
 drivers/net/xsc/xsc_ethdev.c | 43 +++-
 drivers/net/xsc/xsc_ethdev.h | 17 +
 drivers/net/xsc/xsc_utils.h  |  5 +++-
 5 files changed, 93 insertions(+), 2 deletions(-)

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_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index a7259c5fcb..c33e625097 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -69,6 +69,33 @@ struct xsc_ioctl_mbox_out {
uint8_t data[];
 };
 
+struct xsc_nic_attr {
+   __be16   caps;
+   __be16   caps_mask;
+   uint8_t  mac_addr[6];
+};
+
+struct xsc_rss_modify_attr {
+   uint8_t  caps_mask;
+   uint8_t  rss_en;
+   __be16   rqn_base;
+   __be16   rqn_num;
+   uint8_t  hfunc;
+   __be32   hash_tmpl;
+   uint8_t  hash_key[52];
+};
+
+struct xsc_cmd_modify_nic_hca_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   struct xsc_nic_attr nic;
+   struct xsc_rss_modify_attr  rss;
+};
+
+struct xsc_cmd_modify_nic_hca_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   uint8_t rsvd0[4];
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 5ad9567eb3..1f09ab9735 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -17,6 +17,45 @@ static int
 xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, 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 |= BIT(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(BIT(XSC_TBM_CAP_RSS));
+   in.nic.caps = in.nic.caps_mask;
+
+   ret = xsc_mailbox_exec(priv->xdev, &in, sizeof(in), &out, sizeof(out));
+   if (ret != 0 || out.hdr.status != 0)
+   return -1;
+   return 0;
+}
+
+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) {
+   rte_errno = EINVAL;
+   return -rte_errno;
+   }
+   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;
 }
 
@@ -30,7 +69,7 @@ xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev,
if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN ||
rss_conf->rss_key == NULL) {
PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
-   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
return -EINVAL;
}
 
@@ -184,6 +223,8 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_configure = xsc_ethdev_configure,
.rx_queue_setup = xsc_ethdev_rx_queue_setup,
.tx_queue_setup = xsc_ethdev_tx_queue_setup,
+   .rss_hash_update = xsc_ethdev_rss_hash_update,
+   .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 10c3d8cc87..fb92d47dd0 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,8 @@
 #define XSC_MAX_DESC_NUMBER 1024
 #define XSC_RX_FREE_THRESH 32
 
+#define XSC_CMD_OP_MODIFY_NIC_HCA 0x812
+
 struct xsc_dev_config {
uint8_t pph_flag;
unsigned int hw_csum:1;
@@ -51,4 +53,19 @@ struct xsc_ethdev_priv {
 #define TO_XSC_ETHDEV_PRI

[PATCH 17/19] net/xsc: add dev link and MTU ops

2024-09-06 Thread WanRenyong
XSC PMD does not support update link right now, in order to
start device successfully link_update function always return 0.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 50 
 drivers/net/xsc/xsc_utils.c  | 23 +++
 drivers/net/xsc/xsc_utils.h  |  1 +
 4 files changed, 75 insertions(+)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 772c6418c4..84c5ff4b6b 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_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index d3e044e740..54b7e79145 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -187,6 +187,20 @@ xsc_ethdev_configure(struct rte_eth_dev *dev)
return -rte_errno;
 }
 
+static int
+xsc_ethdev_set_link_down(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   return xsc_link_process(dev, priv->ifindex, IFF_UP);
+}
+
+static int
+xsc_ethdev_set_link_up(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   return xsc_link_process(dev, priv->ifindex, ~IFF_UP);
+}
+
 static int
 xsc_init_obj(struct xscdv_obj *obj, uint64_t obj_type)
 {
@@ -983,6 +997,39 @@ 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);
+   uint16_t get_mtu = 0;
+   int ret = 0;
+
+   if (priv->eth_type != RTE_ETH_REPRESENTOR_PF) {
+   priv->mtu = mtu;
+   return 0;
+   }
+
+   ret = xsc_get_mtu(&priv->mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   ret = xsc_set_mtu(mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   ret = xsc_get_mtu(&get_mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   if (get_mtu != mtu) {
+   PMD_DRV_LOG(ERR, "mtu set to %u failure", mtu);
+   return -EAGAIN;
+   }
+
+   priv->mtu = mtu;
+   return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
   __rte_unused int wait_to_complete)
@@ -994,12 +1041,15 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_configure = xsc_ethdev_configure,
.dev_start = xsc_ethdev_start,
.dev_stop = xsc_ethdev_stop,
+   .dev_set_link_down = xsc_ethdev_set_link_down,
+   .dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
.rx_queue_setup = xsc_ethdev_rx_queue_setup,
.tx_queue_setup = xsc_ethdev_tx_queue_setup,
.rx_queue_release = xsc_ethdev_rxq_release,
.tx_queue_release = xsc_ethdev_txq_release,
+   .mtu_set = xsc_ethdev_set_mtu,
.rss_hash_update = xsc_ethdev_rss_hash_update,
.rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c
index e40b0904b7..788cdfa54a 100644
--- a/drivers/net/xsc/xsc_utils.c
+++ b/drivers/net/xsc/xsc_utils.c
@@ -321,3 +321,26 @@ xsc_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uint32_t i
dev->data->mac_addrs[index] = *mac;
return 0;
 }
+
+int
+xsc_link_process(struct rte_eth_dev *dev __rte_unused,
+uint32_t ifindex, unsigned int flags)
+{
+   struct ifreq request;
+   struct ifreq *ifr = &request;
+   char ifname[sizeof(ifr->ifr_name)];
+   int ret;
+   unsigned int keep = ~IFF_UP;
+
+   if (if_indextoname(ifindex, ifname) == NULL)
+   return -rte_errno;
+
+   ret = xsc_ifreq_by_ifname(ifname, SIOCGIFFLAGS, &request);
+   if (ret)
+   return ret;
+
+   request.ifr_flags &= keep;
+   request.ifr_flags |= flags & ~keep;
+
+   return xsc_ifreq_by_ifname(ifname, SIOCSIFFLAGS, &request);
+}
diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h
index 672ba3871e..d9327020cd 100644
--- a/drivers/net/xsc/xsc_utils.h
+++ b/drivers/net/xsc/xsc_utils.h
@@ -22,5 +22,6 @@ int xsc_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uint32
 int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex);
 int xsc_set_mtu(uint16_t mtu, uint32_t ifindex);
 int xsc_get_mac(uint8_t *mac, uint32_t ifindex);
+int xsc_link_process(struct rte_eth_dev *dev, uint32_t ifindex, unsigned int 
flags);
 
 #endif
-- 
2.25.1


[PATCH 18/19] net/xsc: add dev infos get

2024-09-06 Thread WanRenyong
Implement xsc ethdev information get function.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 60 
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 54b7e79145..0c8a620d03 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -918,6 +918,65 @@ 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->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,
@@ -1045,6 +1104,7 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
+   .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 19/19] net/xsc: add dev basic stats ops

2024-09-06 Thread WanRenyong
Implement xsc ethdev basic stats get and reset functions.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 76 
 drivers/net/xsc/xsc_rxtx.c   | 11 -
 drivers/net/xsc/xsc_rxtx.h   | 15 +++
 4 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 84c5ff4b6b..d73cf9d136 100644
--- a/doc/guides/nics/features/xsc.ini
+++ b/doc/guides/nics/features/xsc.ini
@@ -12,6 +12,7 @@ L3 checksum offload  = Y
 L4 checksum offload  = Y
 Inner L3 checksum= Y
 Inner L4 checksum= Y
+Basic stats  = 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 0c8a620d03..b3ae7ba75e 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -1089,6 +1089,80 @@ xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
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;
+
+   memset(stats, 0, sizeof(struct rte_eth_stats));
+   for (i = 0; i < rxqs_n; ++i) {
+   rxq = xsc_rxq_get(dev, 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(dev, 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(dev, 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(dev, i);
+   if (unlikely(txq == NULL))
+   continue;
+   memset(&txq->stats, 0, sizeof(struct xsc_txq_stats));
+   }
+
+   return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
   __rte_unused int wait_to_complete)
@@ -1104,6 +1178,8 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
+   .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,
diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 7a31cd428c..8aed8f4b12 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -62,6 +62,7 @@ xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct 
xsc_cqe *cqe)
ret = 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;
/* TODO */
  

[PATCH 16/19] net/xsc: configure xsc device hardware table

2024-09-06 Thread WanRenyong
Configure hardware table to enable transmission and reception of
the queues.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 
---
 drivers/net/xsc/meson.build  |   1 +
 drivers/net/xsc/xsc_ctrl.h   |  22 +
 drivers/net/xsc/xsc_ethdev.c |  39 
 drivers/net/xsc/xsc_flow.c   | 167 +++
 drivers/net/xsc/xsc_flow.h   |  67 ++
 5 files changed, 296 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_flow.c
 create mode 100644 drivers/net/xsc/xsc_flow.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 2fc4e5ace7..348e8ed145 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -12,6 +12,7 @@ sources = files(
 'xsc_utils.c',
 'xsc_ctrl.c',
 'xsc_rxtx.c',
+'xsc_flow.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index e51847d68f..51bda47ca8 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -41,6 +41,12 @@ enum xsc_ioctl_opmod {
((_n) + (_d) - 1) / (_d); \
 })
 
+enum {
+   XSC_CMD_OP_MODIFY_RAW_QP = 0x81f,
+   XSC_CMD_OP_IOCTL_FLOW= 0x900,
+   XSC_CMD_OP_MAX
+};
+
 enum {
XSC_IOCTL_SET_QP_STATUS = 0x200,
XSC_IOCTL_SET_MAX
@@ -72,6 +78,22 @@ enum {
XSC_QUEUE_TYPE_RAW_TX = 7,
XSC_QUEUE_TYPE_INVALID= 0xFF,
 };
+enum  xsc_flow_tbl_id {
+   XSC_FLOW_TBL_IPAT = 0,
+   XSC_FLOW_TBL_PCT_V4 = 4,
+   XSC_FLOW_TBL_EPAT = 19,
+   XSC_FLOW_TBL_MAX
+};
+
+enum xsc_ioctl_op {
+   XSC_IOCTL_OP_ADD,
+   XSC_IOCTL_OP_DEL,
+   XSC_IOCTL_OP_GET,
+   XSC_IOCTL_OP_CLR,
+   XSC_IOCTL_OP_MOD,
+   XSC_IOCTL_OP_MAX
+};
+
 
 struct xsc_inbox_hdr {
__be16 opcode;
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 991978dd1c..d3e044e740 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -11,6 +11,7 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 #include "xsc_utils.h"
+#include "xsc_flow.h"
 #include "xsc_ctrl.h"
 #include "xsc_rxtx.h"
 
@@ -787,6 +788,43 @@ xsc_rxq_start(struct rte_eth_dev *dev)
return -rte_errno;
 }
 
+static int
+xsc_dev_start_config_hw(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 = 0;
+   int rep_id;
+   struct xsc_rxq_data *rxq = xsc_rxq_get(dev, 0);
+   uint16_t rx_qpn = (uint16_t)rxq->qpn;
+   static int xsc_global_pct_priority_idx = 128;
+
+   if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID)
+   return -1;
+
+   hwinfo = &priv->xdev->hwinfo;
+   rep_id = priv->representor_id;
+   peer_dstinfo = hwinfo->mac_phy_port;
+   peer_logicalport = hwinfo->mac_phy_port;
+
+   qp_set_id = rep_id % 511 + 1;
+   logical_port = priv->xdev->vfos_logical_in_port + qp_set_id - 1;
+   local_dstinfo = logical_port;
+   pcie_logic_port = hwinfo->pcie_no + 8;
+
+   xsc_create_ipat(dev, logical_port, peer_dstinfo);
+   xsc_create_epat(dev, local_dstinfo, pcie_logic_port,
+   rx_qpn - hwinfo->raw_rss_qp_id_base, priv->num_rq);
+   xsc_create_pct(dev, logical_port, peer_dstinfo, 
xsc_global_pct_priority_idx++);
+   xsc_create_pct(dev, peer_logicalport, local_dstinfo, 
xsc_global_pct_priority_idx++);
+   return 0;
+}
+
 static int
 xsc_ethdev_start(struct rte_eth_dev *dev)
 {
@@ -812,6 +850,7 @@ xsc_ethdev_start(struct rte_eth_dev *dev)
dev->rx_pkt_burst = xsc_rx_burst;
dev->tx_pkt_burst = xsc_tx_burst;
 
+   ret = xsc_dev_start_config_hw(dev);
return 0;
 
 error:
diff --git a/drivers/net/xsc/xsc_flow.c b/drivers/net/xsc/xsc_flow.c
new file mode 100644
index 00..f1101b29d0
--- /dev/null
+++ b/drivers/net/xsc/xsc_flow.c
@@ -0,0 +1,167 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_dev.h"
+#include "xsc_ethdev.h"
+#include "xsc_utils.h"
+#include "xsc_flow.h"
+#include "xsc_ctrl.h"
+
+
+static int
+xsc_flow_exec(struct xsc_dev *dev, void *cmd, int len, int table, int opmod)
+{
+   struct xsc_ioctl_data_tl *tl;
+   struct xsc_ioctl_mbox_in *in;
+   struct xsc_ioctl_mbox_out *out;
+   int in_len;
+   int out_len;
+   int data_len;
+   int cmd_len;
+   int ret;
+
+   data_len = sizeof(struct xsc_ioctl_data_tl) + len;
+   in_len = sizeof(stru

[PATCH v2 00/19] XSC PMD for Yunsilicon NICs

2024-09-10 Thread WanRenyong
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 

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


---
WanRenyong (19):
  net/xsc: add doc and minimum build framework
  net/xsc: add log macro
  net/xsc: add PCI device probe and remove
  net/xsc: add xsc device init and uninit
  net/xsc: add ioctl command interface
  net/xsc: initialize hardware information
  net/xsc: add representor ports probe
  net/xsc: create eth devices for representor ports
  net/xsc: initial representor eth device
  net/xsc: add ethdev configure and rxtx queue setup ops
  net/xsc: add mailbox and structure
  net/xsc: add ethdev RSS hash ops
  net/xsc: add ethdev start and stop ops
  net/xsc: add ethdev Rx burst
  net/xsc: add ethdev Tx burst
  net/xsc: configure xsc device hardware table
  net/xsc: add dev link and MTU ops
  net/xsc: add dev infos get
  net/xsc: add dev basic stats ops

 .mailmap |4 +
 MAINTAINERS  |9 +
 doc/guides/nics/features/xsc.ini |   18 +
 doc/guides/nics/index.rst|1 +
 doc/guides/nics/xsc.rst  |   31 +
 drivers/net/meson.build  |1 +
 drivers/net/xsc/meson.build  |   36 +
 drivers/net/xsc/xsc_ctrl.c   |   64 ++
 drivers/net/xsc/xsc_ctrl.h   |  314 +++
 drivers/net/xsc/xsc_defs.h   |   61 ++
 drivers/net/xsc/xsc_dev.c|  326 +++
 drivers/net/xsc/xsc_dev.h|   99 +++
 drivers/net/xsc/xsc_ethdev.c | 1434 ++
 drivers/net/xsc/xsc_ethdev.h |   81 ++
 drivers/net/xsc/xsc_flow.c   |  167 
 drivers/net/xsc/xsc_flow.h   |   67 ++
 drivers/net/xsc/xsc_log.h|   44 +
 drivers/net/xsc/xsc_rxtx.c   |  445 +
 drivers/net/xsc/xsc_rxtx.h   |  214 +
 drivers/net/xsc/xsc_utils.c  |  346 +++
 drivers/net/xsc/xsc_utils.h  |   27 +
 21 files changed, 3789 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_ctrl.c
 create mode 100644 drivers/net/xsc/xsc_ctrl.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_flow.c
 create mode 100644 drivers/net/xsc/xsc_flow.h
 create mode 100644 drivers/net/xsc/xsc_log.h
 create mode 100644 drivers/net/xsc/xsc_rxtx.c
 create mode 100644 drivers/net/xsc/xsc_rxtx.h
 create mode 100644 drivers/net/xsc/xsc_utils.c
 create mode 100644 drivers/net/xsc/xsc_utils.h

-- 
2.25.1


[PATCH v2 02/19] net/xsc: add log macro

2024-09-10 Thread WanRenyong
Add log macro to print runtime messages and trace functions.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 11 +
 drivers/net/xsc/xsc_log.h| 44 
 2 files changed, 55 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_log.h

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 0e48cb76fa..58ceaa3940 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -1,3 +1,14 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2024 Yunsilicon Technology Co., Ltd.
  */
+
+#include "xsc_log.h"
+
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
+#ifdef RTE_ETHDEV_DEBUG_RX
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_rx, rx, DEBUG);
+#endif
+#ifdef RTE_ETHDEV_DEBUG_TX
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_tx, tx, DEBUG);
+#endif
diff --git a/drivers/net/xsc/xsc_log.h b/drivers/net/xsc/xsc_log.h
new file mode 100644
index 00..163145ff09
--- /dev/null
+++ b/drivers/net/xsc/xsc_log.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_LOG_H_
+#define _XSC_LOG_H_
+
+#include 
+
+extern int xsc_logtype_init;
+extern int xsc_logtype_driver;
+
+#define PMD_INIT_LOG(level, fmt, ...) \
+   rte_log(RTE_LOG_ ## level, xsc_logtype_init, "%s(): " fmt "\n", \
+   __func__, ##__VA_ARGS__)
+
+#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
+
+#ifdef RTE_ETHDEV_DEBUG_RX
+extern int xsc_logtype_rx;
+#define PMD_RX_LOG(level, fmt, ...)\
+   rte_log(RTE_LOG_ ## level, xsc_logtype_rx,  \
+   "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define PMD_RX_LOG(level, fmt, ...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+extern int xsc_logtype_tx;
+#define PMD_TX_LOG(level, fmt, ...)\
+   rte_log(RTE_LOG_ ## level, xsc_logtype_tx,  \
+   "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define PMD_TX_LOG(level, fmt, ...) do { } while (0)
+#endif
+
+#define PMD_DRV_LOG_RAW(level, fmt, ...) \
+   rte_log(RTE_LOG_ ## level, xsc_logtype_driver, "%s(): " fmt, \
+   __func__, ##__VA_ARGS__)
+
+#define PMD_DRV_LOG(level, fmt, ...) \
+   PMD_DRV_LOG_RAW(level, fmt "\n", ##__VA_ARGS__)
+
+#endif /* _XSC_LOG_H_ */
-- 
2.25.1


[PATCH v2 01/19] net/xsc: add doc and minimum build framework

2024-09-10 Thread WanRenyong
Add minimum PMD code, doc and build infrastructure for xsc.

Signed-off-by: WanRenyong 

---

v2:
* fix compilation error
---
 .mailmap |  4 
 MAINTAINERS  |  9 +
 doc/guides/nics/features/xsc.ini |  9 +
 doc/guides/nics/index.rst|  1 +
 doc/guides/nics/xsc.rst  | 31 +++
 drivers/net/meson.build  |  1 +
 drivers/net/xsc/meson.build  | 13 +
 drivers/net/xsc/xsc_ethdev.c |  3 +++
 8 files changed, 71 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_ethdev.c

diff --git a/.mailmap b/.mailmap
index 09fa253e12..d09ed30e16 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1034,6 +1034,7 @@ Nagadheeraj Rottela 
 Naga Harish K S V 
 Naga Suresh Somarowthu 
 Nalla Pradeep 
+Na Na 
 Na Na 
 Nan Chen 
 Nannan Lu 
@@ -1268,6 +1269,7 @@ Ronak Doshi  
 Ron Beider 
 Ronghua Zhang 
 RongQiang Xie 
+Rong Qian 
 RongQing Li 
 Rongwei Liu 
 Rory Sexton 
@@ -1586,6 +1588,7 @@ Waldemar Dworakowski 
 Walter Heymans 
 Wang Sheng-Hui 
 Wangyu (Eric) 
+WanRenyong 
 Waterman Cao 
 Wathsala Vithanage 
 Weichun Chen 
@@ -1638,6 +1641,7 @@ Xiaonan Zhang 
 Xiao Wang 
 Xiaoxiao Zeng 
 Xiaoxin Peng 
+Xiaoxiong Zhang 
 Xiaoyu Min  
 Xiaoyun Li 
 Xiaoyun Wang 
diff --git a/MAINTAINERS b/MAINTAINERS
index c5a703b5c0..f87d802b24 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -994,6 +994,15 @@ F: drivers/net/txgbe/
 F: doc/guides/nics/txgbe.rst
 F: doc/guides/nics/features/txgbe.ini
 
+Yunsilicon xsc
+M: WanRenyong 
+M: Na Na 
+M: Rong Qian 
+M: Xiaoxiong Zhang 
+F: drivers/net/xsc/
+F: doc/guides/nics/xsc.rst
+F: doc/guides/nics/features/xsc.ini
+
 VMware vmxnet3
 M: Jochen Behrens 
 F: drivers/net/vmxnet3/
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 c14bc7988a..9781097a21 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -69,3 +69,4 @@ Network Interface Controller Drivers
 vhost
 virtio
 vmxnet3
+xsc
diff --git a/doc/guides/nics/xsc.rst b/doc/guides/nics/xsc.rst
new file mode 100644
index 00..b7643b3ce2
--- /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 :doc:`../linux_gsg/index` to setup the basic DPDK 
environment.
+
+- Learning about Yunsilicon metaScale Series NICs using
+  `<https://www.yunsilicon.com/#/productInformation>`_.
+
+Limitations or Known issues
+---
+32bit ARCHs have not been tested and may not be supported.
+Windows and BSD are not supported yet.
diff --git a/drivers/net/meson.build b/drivers/net/meson.build
index fb6d34b782..67fbe81861 100644
--- a/drivers/net/meson.build
+++ b/drivers/net/meson.build
@@ -62,6 +62,7 @@ drivers = [
 'vhost',
 'virtio',
 'vmxnet3',
+'xsc',
 ]
 std_deps = ['ethdev', 'kvargs'] # 'ethdev' also pulls in mbuf, net, eal etc
 std_deps += ['bus_pci'] # very many PMDs depend on PCI, so make std
diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
new file mode 100644
index 00..11cdcf912b
--- /dev/null
+++ b/drivers/net/xsc/meson.build
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2024 Yunsilicon Technology Co., Ltd.
+
+if not is_linux
+build = false
+reason = 'only supported on Linux'
+endif
+
+sources = files(
+'xsc_ethdev.c',
+)
+
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
new file mode 100644
index 00..0e48cb76fa
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
-- 
2.25.1


[PATCH v2 05/19] net/xsc: add ioctl command interface

2024-09-10 Thread WanRenyong
IOCTL command interface is one of methods used to interact with
firmware by PMD. By using ioctl interface, PMD sends command to
the kernel module, then the kernel module translates the command
and sends it to firmware, at last, the kernel module send back
PDM the result from firmware.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/meson.build |  1 +
 drivers/net/xsc/xsc_ctrl.c  | 56 
 drivers/net/xsc/xsc_ctrl.h  | 86 +
 3 files changed, 143 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_ctrl.c
 create mode 100644 drivers/net/xsc/xsc_ctrl.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 8bf6ee7b47..f38ebdfe0f 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -10,6 +10,7 @@ sources = files(
 'xsc_ethdev.c',
 'xsc_dev.c',
 'xsc_utils.c',
+'xsc_ctrl.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c
new file mode 100644
index 00..3e37bd914e
--- /dev/null
+++ b/drivers/net/xsc/xsc_ctrl.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_dev.h"
+#include "xsc_ctrl.h"
+
+int
+xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
+ void *data_in, int in_len, void *data_out, int out_len)
+{
+   struct xsc_ioctl_hdr *hdr;
+   int data_len = RTE_MAX(in_len, out_len);
+   int alloc_len = sizeof(struct xsc_ioctl_hdr) + data_len;
+   int ret = 0;
+
+   hdr = rte_zmalloc(NULL, alloc_len, RTE_CACHE_LINE_SIZE);
+   if (hdr == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to allocate xsc ioctl cmd memory");
+   return -ENOMEM;
+   }
+
+   hdr->check_field = XSC_IOCTL_CHECK_FIELD;
+   hdr->attr.opcode = opcode;
+   hdr->attr.length = data_len;
+   hdr->attr.error = 0;
+
+   if (data_in != NULL && in_len > 0)
+   rte_memcpy(hdr + 1, data_in, in_len);
+
+   ret = ioctl(dev->ctrl_fd, cmd, hdr);
+   if (ret == 0) {
+   if (hdr->attr.error != 0)
+   ret = hdr->attr.error;
+   else if (data_out != NULL && out_len > 0)
+   rte_memcpy(data_out, hdr + 1, out_len);
+   }
+
+   rte_free(hdr);
+   return ret;
+}
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
new file mode 100644
index 00..d343e1b1a7
--- /dev/null
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_CTRL_H_
+#define _XSC_CTRL_H_
+
+#include 
+
+#define XSC_IOCTL_CHECK_FIELD  0x01234567
+
+#define XSC_IOCTL_MAGIC0x1b
+#define XSC_IOCTL_CMDQ \
+   _IOWR(XSC_IOCTL_MAGIC, 1, struct xsc_ioctl_hdr)
+#define XSC_IOCTL_DRV_GET \
+   _IOR(XSC_IOCTL_MAGIC, 2, struct xsc_ioctl_hdr)
+#define XSC_IOCTL_CMDQ_RAW \
+   _IOWR(XSC_IOCTL_MAGIC, 5, struct xsc_ioctl_hdr)
+
+enum xsc_ioctl_opcode {
+   XSC_IOCTL_GET_HW_INFO   = 0x100,
+};
+
+enum xsc_ioctl_opmod {
+   XSC_IOCTL_OP_GET_LOCAL,
+};
+
+struct xsc_ioctl_attr {
+   uint16_t opcode; /* ioctl cmd */
+   uint16_t length; /* data length */
+   uint32_t error;  /* ioctl error info */
+   uint8_t data[0]; /* specific table info */
+};
+
+struct xsc_ioctl_hdr {
+   uint32_t check_field;
+   uint32_t domain;
+   uint32_t bus;
+   uint32_t devfn;
+   struct xsc_ioctl_attr attr;
+};
+
+struct xsc_ioctl_data_tl {
+   uint16_t table;
+   uint16_t opmod;
+   uint16_t length;
+   uint16_t rsvd;
+};
+
+struct xsc_ioctl_get_hwinfo {
+   uint32_t domain;
+   uint32_t bus;
+   uint32_t devfn;
+   uint32_t pcie_no;
+   uint32_t func_id;
+   uint32_t pcie_host;
+   uint32_t mac_phy_port;
+   uint32_t funcid_to_logic_port_off;
+   uint16_t lag_id;
+   uint16_t raw_qp_id_base;
+   uint16_t raw_rss_qp_id_base;
+   uint16_t pf0_vf_funcid_base;
+   uint16_t pf0_vf_funcid_top;
+   uint16_t pf1_vf_funcid_base;
+   uint16_t pf1_vf_funcid_top;
+   uint16_t pcie0_pf_funcid_base;
+   uint16_t pcie0_pf_funcid_top;
+   uint16_t pcie1_pf_funcid_base;
+   uint16_t pcie1_pf_funcid_top;
+   uint16_t lag_port_start;
+   uint16_t raw_tpe_qp_num;
+   int send_seg_num;
+   int recv_seg_num;
+   uint8_t on_chip_tbl_vld;
+   uint8_t dma_rw_tbl_vld;
+   uint8_t pct_compress_vld;
+   uint32_t chip_version;
+   uint32_t hca_core_clock;
+   uint8_t mac_bit;
+   uint8_t esw_mode

[PATCH v2 04/19] net/xsc: add xsc device init and uninit

2024-09-10 Thread WanRenyong
XSC device is a concept of low level device used to manage
hardware resource and to interact with firmware.

Signed-off-by: WanRenyong 

---

v2:
* fix compilation error caused by missing dependency
---
 drivers/net/xsc/meson.build  |  20 +
 drivers/net/xsc/xsc_defs.h   |  23 +
 drivers/net/xsc/xsc_dev.c| 162 +++
 drivers/net/xsc/xsc_dev.h|  34 
 drivers/net/xsc/xsc_ethdev.c |  22 -
 drivers/net/xsc/xsc_ethdev.h |   1 +
 drivers/net/xsc/xsc_utils.c  |  96 +
 drivers/net/xsc/xsc_utils.h  |  14 +++
 8 files changed, 371 insertions(+), 1 deletion(-)
 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_utils.c
 create mode 100644 drivers/net/xsc/xsc_utils.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 11cdcf912b..8bf6ee7b47 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -8,6 +8,26 @@ endif
 
 sources = files(
 'xsc_ethdev.c',
+'xsc_dev.c',
+'xsc_utils.c',
 )
 
+libnames = ['ibverbs']
+foreach libname:libnames
+lib = dependency('lib' + libname, required: false, method : 'pkg-config')
+if lib.found()
+ext_deps += lib
+else
+build = false
+reason = 'missing dependency, "' + libname + '"'
+subdir_done()
+endif
+endforeach
 
+lib = dependency('libxscale', required: false, method : 'pkg-config')
+if lib.found()
+ext_deps += lib
+cflags += '-DHAVE_XSC_DV_PROVIDER=1'
+else
+cflags += '-DHAVE_XSC_DV_PROVIDER=0'
+endif
diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index b4ede6eca6..97cd61b2d1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -8,5 +8,28 @@
 #define XSC_PCI_VENDOR_ID  0x1f67
 #define XSC_PCI_DEV_ID_MS  0x
 
+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,
+};
+
+enum xsc_flow_mode {
+   XSC_FLOW_OFF_HW_ONLY,
+   XSC_FLOW_ON_HW_ONLY,
+   XSC_FLOW_ON_HW_FIRST,
+   XSC_FLOW_HOTSPOT,
+   XSC_FLOW_MODE_NULL = 7,
+   XSC_FLOW_MODE_MAX,
+};
+
 #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..9673049628
--- /dev/null
+++ b/drivers/net/xsc/xsc_dev.c
@@ -0,0 +1,162 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_dev.h"
+#include "xsc_utils.h"
+
+#define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
+#define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
+
+static
+void xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs)
+{
+   struct rte_kvargs *kvlist;
+   struct xsc_devargs *xdevargs = &dev->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
+   xdevargs->flow_mode = XSC_DEV_DEF_FLOW_MODE;
+
+   rte_kvargs_free(kvlist);
+}
+
+static int
+xsc_dev_open(struct xsc_dev *dev, struct rte_pci_device *pci_dev)
+{
+   struct ibv_device *ib_dev;
+   char ctrl_file[PATH_MAX];
+   struct rte_pci_addr *pci_addr = &pci_dev->addr;
+   int ret;
+
+   ib_dev = xsc_get_ibv_device(&pci_dev->addr);
+   if (ib_dev == NULL) {
+   PMD_DRV_LOG(ERR, "Could not get ibv device");
+   return -ENODEV;
+   }
+
+   dev->ibv_ctx = ibv_open_device(ib_dev);
+   if (dev->ibv_ctx == NULL) {
+   PMD_DRV_LOG(ERR, "Could not open ibv device: %s", ib_dev->name);
+   return -ENODEV;
+   }
+
+   dev->ibv_pd = ibv_alloc_pd(dev->ibv_ctx);
+   if (dev->ibv_pd == NULL) {

[PATCH v2 03/19] net/xsc: add PCI device probe and remove

2024-09-10 Thread WanRenyong
Support the following Yunsilicon NICs to be probed:

- metaScale-200
- metaScale-200S
- metaScale-50
- metaScale-100Q

Signed-off-by: WanRenyong 
Signed-off-by: Na Na 
---
 drivers/net/xsc/xsc_defs.h   | 12 ++
 drivers/net/xsc/xsc_ethdev.c | 74 
 drivers/net/xsc/xsc_ethdev.h | 16 
 3 files changed, 102 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_defs.h
 create mode 100644 drivers/net/xsc/xsc_ethdev.h

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
new file mode 100644
index 00..b4ede6eca6
--- /dev/null
+++ b/drivers/net/xsc/xsc_defs.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef XSC_DEFS_H_
+#define XSC_DEFS_H_
+
+#define XSC_PCI_VENDOR_ID  0x1f67
+#define XSC_PCI_DEV_ID_MS  0x
+
+#endif /* XSC_DEFS_H_ */
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 58ceaa3940..8f4d539848 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -2,7 +2,81 @@
  * Copyright 2024 Yunsilicon Technology Co., Ltd.
  */
 
+#include 
+
 #include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_ethdev.h"
+
+static int
+xsc_ethdev_init(struct rte_eth_dev *eth_dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+   PMD_INIT_FUNC_TRACE();
+
+   priv->eth_dev = eth_dev;
+   priv->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+   return 0;
+}
+
+static int
+xsc_ethdev_uninit(struct rte_eth_dev *eth_dev)
+{
+   RTE_SET_USED(eth_dev);
+   PMD_INIT_FUNC_TRACE();
+
+   return 0;
+}
+
+static int
+xsc_ethdev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+struct rte_pci_device *pci_dev)
+{
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = rte_eth_dev_pci_generic_probe(pci_dev,
+   sizeof(struct xsc_ethdev_priv),
+   xsc_ethdev_init);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Failed to probe ethdev: %s", pci_dev->name);
+   return ret;
+   }
+
+   return 0;
+}
+
+static int
+xsc_ethdev_pci_remove(struct rte_pci_device *pci_dev)
+{
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = rte_eth_dev_pci_generic_remove(pci_dev, xsc_ethdev_uninit);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Could not remove ethdev: %s", pci_dev->name);
+   return ret;
+   }
+
+   return 0;
+}
+
+static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
+   { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
+};
+
+static struct rte_pci_driver xsc_ethdev_pci_driver = {
+   .id_table  = xsc_ethdev_pci_id_map,
+   .probe = xsc_ethdev_pci_probe,
+   .remove = xsc_ethdev_pci_remove,
+};
+
+RTE_PMD_REGISTER_PCI(net_xsc, xsc_ethdev_pci_driver);
+RTE_PMD_REGISTER_PCI_TABLE(net_xsc, xsc_ethdev_pci_id_map);
 
 RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
 RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
new file mode 100644
index 00..75aa34dc63
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_ETHDEV_H_
+#define _XSC_ETHDEV_H_
+
+struct xsc_ethdev_priv {
+   struct rte_eth_dev *eth_dev;
+   struct rte_pci_device *pci_dev;
+};
+
+#define TO_XSC_ETHDEV_PRIV(dev) \
+   ((struct xsc_ethdev_priv *)(dev)->data->dev_private)
+
+#endif /* _XSC_ETHDEV_H_ */
-- 
2.25.1


[PATCH v2 06/19] net/xsc: initialize hardware information

2024-09-10 Thread WanRenyong
Getting hardware information is done by ioctl command, which
contains the information of xsc device, as well as the common
information of the NIC board.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_dev.c | 63 +++
 drivers/net/xsc/xsc_dev.h | 32 
 2 files changed, 95 insertions(+)

diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 9673049628..1eb68ac95d 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -18,10 +18,64 @@
 #include "xsc_defs.h"
 #include "xsc_dev.h"
 #include "xsc_utils.h"
+#include "xsc_ctrl.h"
 
 #define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
 #define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
 
+static int xsc_hwinfo_init(struct xsc_dev *dev)
+{
+   struct {
+   struct xsc_ioctl_data_tl tl;
+   struct xsc_ioctl_get_hwinfo hwinfo;
+   } data;
+   struct xsc_ioctl_get_hwinfo *info = &data.hwinfo;
+   int data_len;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   data_len = sizeof(data);
+   data.tl.opmod = XSC_IOCTL_OP_GET_LOCAL;
+   ret = xsc_ioctl(dev, XSC_IOCTL_DRV_GET, XSC_IOCTL_GET_HW_INFO, &data, 
data_len,
+   &data, data_len);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to get hardware info");
+   return ret;
+   }
+
+   dev->hwinfo.valid = 1;
+   dev->hwinfo.pcie_no = info->pcie_no;
+   dev->hwinfo.func_id = info->func_id;
+   dev->hwinfo.pcie_host = info->pcie_host;
+   dev->hwinfo.mac_phy_port = info->mac_phy_port;
+   dev->hwinfo.funcid_to_logic_port_off = info->funcid_to_logic_port_off;
+   dev->hwinfo.lag_id = info->lag_id;
+   dev->hwinfo.raw_qp_id_base = info->raw_qp_id_base;
+   dev->hwinfo.raw_rss_qp_id_base = info->raw_rss_qp_id_base;
+   dev->hwinfo.pf0_vf_funcid_base = info->pf0_vf_funcid_base;
+   dev->hwinfo.pf0_vf_funcid_top = info->pf0_vf_funcid_top;
+   dev->hwinfo.pf1_vf_funcid_base = info->pf1_vf_funcid_base;
+   dev->hwinfo.pf1_vf_funcid_top = info->pf1_vf_funcid_top;
+   dev->hwinfo.pcie0_pf_funcid_base = info->pcie0_pf_funcid_base;
+   dev->hwinfo.pcie0_pf_funcid_top = info->pcie0_pf_funcid_top;
+   dev->hwinfo.pcie1_pf_funcid_base = info->pcie1_pf_funcid_base;
+   dev->hwinfo.pcie1_pf_funcid_top = info->pcie1_pf_funcid_top;
+   dev->hwinfo.lag_port_start = info->lag_port_start;
+   dev->hwinfo.raw_tpe_qp_num = info->raw_tpe_qp_num;
+   dev->hwinfo.send_seg_num = info->send_seg_num;
+   dev->hwinfo.recv_seg_num = info->recv_seg_num;
+   dev->hwinfo.on_chip_tbl_vld = info->on_chip_tbl_vld;
+   dev->hwinfo.dma_rw_tbl_vld = info->dma_rw_tbl_vld;
+   dev->hwinfo.pct_compress_vld = info->pct_compress_vld;
+   dev->hwinfo.chip_version = info->chip_version;
+   dev->hwinfo.hca_core_clock = info->hca_core_clock;
+   dev->hwinfo.mac_bit = info->mac_bit;
+   dev->hwinfo.esw_mode = info->esw_mode;
+
+   return 0;
+}
+
 static
 void xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs)
 {
@@ -142,11 +196,20 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct 
xsc_dev **dev)
goto dev_open_fail;
}
 
+   ret = xsc_hwinfo_init(d);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Failed to initialize hardware info");
+   goto hwinfo_init_fail;
+   return ret;
+   }
+
d->pci_dev = pci_dev;
*dev = d;
 
return 0;
 
+hwinfo_init_fail:
+   xsc_dev_close(d);
 dev_open_fail:
rte_free(d);
return ret;
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index ce9dd65400..5f0e911b42 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -11,6 +11,37 @@
 #define XSC_NIC_MODE_ARG "nic_mode"
 #define XSC_FLOW_MODE_ARG "flow_mode"
 
+struct xsc_hwinfo {
+   uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
+   uint32_t pcie_no; /* pcie number , 0 or 1 */
+   uint32_t func_id; /* pf glb func id */
+   uint32_t pcie_host; /* host pcie number */
+   uint32_t mac_phy_port; /* mac port */
+   uint32_t funcid_to_logic_port_off; /* port func id offset  */
+   uint16_t lag_id;
+   uint16_t raw_qp_id_base;
+   uint16_t raw_rss_qp_id_base;
+   uint16_t pf0_vf_funcid_base;
+   uint16_t pf0_vf_funcid_top;
+   uint16_t pf1_vf_funcid_base;
+   uint16_t pf1_vf_funcid_top;
+   uint16_t pcie0_pf_funcid_base;
+   uint16_t pcie0_pf_funcid_top;
+   uint16_t pcie1_pf_funcid_base;
+   uint16_t pcie1_pf_funcid_top;
+   uint16_t lag_port_start;
+

[PATCH v2 10/19] net/xsc: add ethdev configure and rxtx queue setup ops

2024-09-10 Thread WanRenyong
Implement xsc ethdev configure, Rx and Tx queue setup functions.

Signed-off-by: WanRenyong 

---

v2:
* fix compilation warning
---
 drivers/net/xsc/xsc_ethdev.c | 171 +++
 drivers/net/xsc/xsc_ethdev.h |   6 ++
 drivers/net/xsc/xsc_rxtx.h   | 115 +++
 3 files changed, 292 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_rxtx.h

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index aacce8b90d..f21b105e83 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -11,8 +11,179 @@
 #include "xsc_utils.h"
 
 #include "xsc_ctrl.h"
+#include "xsc_rxtx.h"
+
+static int
+xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, uint8_t *rss_key,
+  uint8_t rss_key_len)
+{
+   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;
+
+   if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN ||
+   rss_conf->rss_key == NULL) {
+   PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
+   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+   return -EINVAL;
+   }
+
+   ret = xsc_rss_modify_cmd(priv, rss_conf->rss_key, 
rss_conf->rss_key_len);
+   if (ret == 0) {
+   rte_memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
+   priv->rss_conf.rss_key_len);
+   priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
+   priv->rss_conf.rss_hf = rss_conf->rss_hf;
+   }
+
+   return ret;
+}
+
+static int
+xsc_ethdev_configure(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+   int ret;
+   struct rte_eth_rss_conf *rss_conf;
+
+   priv->num_sq = dev->data->nb_tx_queues;
+   priv->num_rq = dev->data->nb_rx_queues;
+
+   if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
+   dev->data->dev_conf.rxmode.offloads |= 
RTE_ETH_RX_OFFLOAD_RSS_HASH;
+
+   if (priv->rss_conf.rss_key == NULL) {
+   priv->rss_conf.rss_key = rte_zmalloc(NULL, XSC_RSS_HASH_KEY_LEN,
+   RTE_CACHE_LINE_SIZE);
+   if (priv->rss_conf.rss_key == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to alloc rss_key");
+   rte_errno = ENOMEM;
+   ret = -rte_errno;
+   goto error;
+   }
+   priv->rss_conf.rss_key_len = XSC_RSS_HASH_KEY_LEN;
+   }
+
+   if (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key != NULL) {
+   rss_conf = &dev->data->dev_conf.rx_adv_conf.rss_conf;
+   ret = xsc_ethdev_rss_hash_update(dev, rss_conf);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Xsc pmd set rss key error!");
+   rte_errno = -ENOEXEC;
+   goto error;
+   }
+   }
+
+   if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
+   PMD_DRV_LOG(ERR, "xsc pmd do not support vlan filter now!");
+   rte_errno = EINVAL;
+   goto error;
+   }
+
+   if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
+   PMD_DRV_LOG(ERR, "xsc pmd do not support vlan strip now!");
+   rte_errno = EINVAL;
+   goto error;
+   }
+
+   priv->txqs = (void *)dev->data->tx_queues;
+   priv->rxqs = (void *)dev->data->rx_queues;
+   return 0;
+
+error:
+   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

[PATCH v2 07/19] net/xsc: add representor ports probe

2024-09-10 Thread WanRenyong
XSC representor port is designed to store representor resources.
In addition to common representor ports, xsc device is a special
representor port.

Signed-off-by: WanRenyong 
Signed-off-by: Na Na 
---
 drivers/net/xsc/xsc_defs.h  |  24 +++
 drivers/net/xsc/xsc_dev.c   | 103 +-
 drivers/net/xsc/xsc_dev.h   |  27 
 drivers/net/xsc/xsc_utils.c | 122 
 drivers/net/xsc/xsc_utils.h |   3 +
 5 files changed, 278 insertions(+), 1 deletion(-)

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 97cd61b2d1..8cb67ed2e1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -8,6 +8,10 @@
 #define XSC_PCI_VENDOR_ID  0x1f67
 #define XSC_PCI_DEV_ID_MS  0x
 
+#define XSC_VFREP_BASE_LOGICAL_PORT 1081
+
+
+
 enum xsc_nic_mode {
XSC_NIC_MODE_LEGACY,
XSC_NIC_MODE_SWITCHDEV,
@@ -31,5 +35,25 @@ enum xsc_flow_mode {
XSC_FLOW_MODE_MAX,
 };
 
+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_phy_port_type {
+   XSC_PORT_TYPE_NONE = 0,
+   XSC_PORT_TYPE_UPLINK, /* mac0rep */
+   XSC_PORT_TYPE_UPLINK_BOND, /* bondrep */
+   XSC_PORT_TYPE_PFVF, /*hasreps: vfrep*/
+   XSC_PORT_TYPE_PFHPF, /*hasreps: host pf rep*/
+   XSC_PORT_TYPE_UNKNOWN,
+};
+
+#define XSC_PHY_PORT_NUM 1
+
 #endif /* XSC_DEFS_H_ */
 
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 1eb68ac95d..3ba9a16116 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -23,6 +23,31 @@
 #define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
 #define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
 
+static int
+xsc_dev_alloc_vfos_info(struct xsc_dev *dev)
+{
+   struct xsc_hwinfo *hwinfo;
+   int vfrep_offset = 0;
+   int base_lp = 0;
+
+   hwinfo = &dev->hwinfo;
+   if (hwinfo->pcie_no == 1) {
+   vfrep_offset = hwinfo->func_id -
+  hwinfo->pcie1_pf_funcid_base +
+  hwinfo->pcie0_pf_funcid_top -
+  hwinfo->pcie0_pf_funcid_base  + 1;
+   } else {
+   vfrep_offset = hwinfo->func_id - hwinfo->pcie0_pf_funcid_base;
+   }
+
+   base_lp = XSC_VFREP_BASE_LOGICAL_PORT;
+   if (dev->devargs.nic_mode == XSC_NIC_MODE_LEGACY)
+   base_lp = base_lp + vfrep_offset;
+
+   dev->vfos_logical_in_port = base_lp;
+   return 0;
+}
+
 static int xsc_hwinfo_init(struct xsc_dev *dev)
 {
struct {
@@ -174,6 +199,73 @@ xsc_dev_close(struct xsc_dev *dev)
ibv_close_device(dev->ibv_ctx);
 }
 
+static void
+xsc_repr_info_init(struct xsc_repr_info *info, enum xsc_phy_port_type 
port_type,
+  enum xsc_funcid_type funcid_type, int32_t repr_id)
+{
+   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 = XSC_PHYPORT_MAC_FUNCID << 14;
+   } else if (port_type == XSC_PORT_TYPE_PFVF) {
+   info->funcid = funcid_type << 14;
+   }
+}
+
+int
+xsc_repr_ports_probe(struct xsc_dev *dev, int nb_ports, int max_nb_ports)
+{
+   int funcid_type;
+   struct xsc_repr_port *repr_port;
+   int i;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = xsc_get_ifindex_by_pci_addr(&dev->pci_dev->addr, &dev->ifindex);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Could not get xsc dev ifindex");
+   return ret;
+   }
+
+   dev->num_repr_ports = nb_ports + 1;
+
+   dev->repr_ports = rte_zmalloc(NULL,
+ sizeof(struct xsc_repr_port) * 
dev->num_repr_ports,
+ RTE_CACHE_LINE_SIZE);
+   if (dev->repr_ports == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to allocate memory for repr_ports");
+   return -ENOMEM;
+   }
+
+   funcid_type = (dev->devargs.nic_mode == XSC_NIC_MODE_SWITCHDEV) ?
+   XSC_VF_IOCTL_FUNCID : XSC_PHYPORT_MAC_FUNCID;
+
+   repr_port = &dev->repr_ports[XSC_DEV_REPR_PORT];
+   xsc_repr_info_init(&repr_port->info,
+  XSC_PORT_TYPE_UPLINK, XSC_FUNCID_TYPE_UNKNOWN, -1);
+   repr_port->info.ifindex = dev->ifindex;
+   repr_port->xdev = dev;
+
+   if ((dev->devargs.pph_mode & XSC_TX_PPH) == 0)
+   repr_port->info.rep

[PATCH v2 08/19] net/xsc: create eth devices for representor ports

2024-09-10 Thread WanRenyong
Each representor port is a rte ethernet device.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 87 
 drivers/net/xsc/xsc_ethdev.h |  1 +
 2 files changed, 88 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 6a33cbb2cd..d6efc3c9a0 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -9,6 +9,83 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 
+static int
+xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
+{
+   struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+   priv->repr_port = repr_port;
+   repr_port->drv_data = eth_dev;
+
+   return 0;
+}
+
+static int
+xsc_ethdev_init_representors(struct rte_eth_dev *eth_dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+   struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
+   struct rte_device *dev;
+   struct xsc_dev *xdev;
+   struct xsc_repr_port *repr_port;
+   char name[RTE_ETH_NAME_MAX_LEN];
+   int i;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   dev = &priv->pci_dev->device;
+   if (dev->devargs != NULL) {
+   ret = rte_eth_devargs_parse(dev->devargs->args, ð_da, 1);
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "Failed to parse device arguments: %s",
+   dev->devargs->args);
+   return -EINVAL;
+   }
+   }
+
+   xdev = priv->xdev;
+   ret = xsc_repr_ports_probe(xdev, eth_da.nb_representor_ports, 
RTE_MAX_ETHPORTS);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to probe %d xsc device representors",
+   eth_da.nb_representor_ports);
+   return ret;
+   }
+
+   repr_port = &xdev->repr_ports[XSC_DEV_REPR_PORT];
+   ret = xsc_ethdev_init_one_representor(eth_dev, repr_port);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to init backing representor");
+   return ret;
+   }
+
+   for (i = 1; i < xdev->num_repr_ports; i++) {
+   repr_port = &xdev->repr_ports[i];
+   snprintf(name, sizeof(name), "%s_rep_%d",
+xdev->ibv_name, repr_port->info.repr_id);
+   ret = rte_eth_dev_create(&xdev->pci_dev->device,
+name,
+sizeof(struct xsc_ethdev_priv),
+NULL, NULL,
+xsc_ethdev_init_one_representor,
+repr_port);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to create representor: %d", i);
+   goto destroy_reprs;
+   }
+   }
+
+   return 0;
+
+destroy_reprs:
+   while ((i--) > 1) {
+   repr_port = &xdev->repr_ports[i];
+   rte_eth_dev_destroy((struct rte_eth_dev *)repr_port->drv_data, 
NULL);
+   }
+   return ret;
+}
+
 static int
 xsc_ethdev_init(struct rte_eth_dev *eth_dev)
 {
@@ -26,7 +103,17 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev)
return ret;
}
 
+   ret = xsc_ethdev_init_representors(eth_dev);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to initialize representors");
+   goto uninit_xsc_dev;
+   }
+
return 0;
+
+uninit_xsc_dev:
+   xsc_dev_uninit(priv->xdev);
+   return ret;
 }
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 22fc462e25..a05a63193c 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,7 @@ struct xsc_ethdev_priv {
struct rte_eth_dev *eth_dev;
struct rte_pci_device *pci_dev;
struct xsc_dev *xdev;
+   struct xsc_repr_port *repr_port;
 };
 
 #define TO_XSC_ETHDEV_PRIV(dev) \
-- 
2.25.1


[PATCH v2 09/19] net/xsc: initial representor eth device

2024-09-10 Thread WanRenyong
Initialize xsc eth device private data.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_defs.h   |   2 +-
 drivers/net/xsc/xsc_dev.h|   3 +
 drivers/net/xsc/xsc_ethdev.c |  64 +
 drivers/net/xsc/xsc_ethdev.h |  30 ++
 drivers/net/xsc/xsc_utils.c  | 105 +++
 drivers/net/xsc/xsc_utils.h  |   8 ++-
 6 files changed, 210 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 8cb67ed2e1..7dc57e5717 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -10,7 +10,7 @@
 
 #define XSC_VFREP_BASE_LOGICAL_PORT 1081
 
-
+#define XSC_MAX_MAC_ADDRESSES 3
 
 enum xsc_nic_mode {
XSC_NIC_MODE_LEGACY,
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index 93ab1e24fe..f77551f1c5 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -15,6 +15,9 @@
 
 #define XSC_DEV_REPR_PORT  0
 
+#define FUNCID_TYPE_MASK 0x1c000
+#define FUNCID_MASK 0x3fff
+
 struct xsc_hwinfo {
uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
uint32_t pcie_no; /* pcie number , 0 or 1 */
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index d6efc3c9a0..aacce8b90d 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -8,15 +8,79 @@
 #include "xsc_defs.h"
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
+#include "xsc_utils.h"
+
+#include "xsc_ctrl.h"
+
+const struct eth_dev_ops xsc_dev_ops = {
+};
 
 static int
 xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
 {
struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+   struct xsc_dev_config *config = &priv->config;
+   struct rte_ether_addr mac;
 
priv->repr_port = repr_port;
repr_port->drv_data = eth_dev;
+   priv->xdev = repr_port->xdev;
+   priv->mtu = RTE_ETHER_MTU;
+   priv->funcid_type = (repr_port->info.funcid & FUNCID_TYPE_MASK) >> 14;
+   priv->funcid = repr_port->info.funcid & FUNCID_MASK;
+   if (repr_port->info.port_type == XSC_PORT_TYPE_UPLINK ||
+   repr_port->info.port_type == XSC_PORT_TYPE_UPLINK_BOND)
+   priv->eth_type = RTE_ETH_REPRESENTOR_PF;
+   else
+   priv->eth_type = RTE_ETH_REPRESENTOR_VF;
+   priv->representor_id = repr_port->info.repr_id;
+   priv->dev_data = eth_dev->data;
+   priv->ifindex = repr_port->info.ifindex;
+
+   eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+   eth_dev->data->mac_addrs = priv->mac;
+   if (rte_is_zero_ether_addr(eth_dev->data->mac_addrs)) {
+   if (priv->ifindex > 0) {
+   int ret  = xsc_get_mac(mac.addr_bytes, priv->ifindex);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "port %u cannot get MAC 
address",
+   eth_dev->data->port_id);
+   return -ENODEV;
+   }
+   } else {
+   rte_eth_random_addr(mac.addr_bytes);
+   }
+   }
+
+   xsc_mac_addr_add(eth_dev, &mac, 0);
+
+   if (priv->ifindex > 0)
+   xsc_get_mtu(&priv->mtu, priv->ifindex);
+
+   config->hw_csum = 1;
+
+   config->pph_flag =  priv->xdev->devargs.pph_mode;
+   if ((config->pph_flag & XSC_TX_PPH) != 0) {
+   config->tso = 0;
+   } else {
+   config->tso = 1;
+   if (config->tso)
+   config->tso_max_payload_sz = 1500;
+   }
+
+   priv->representor = !!priv->eth_type;
+   if (priv->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;
+   }
+   eth_dev->dev_ops = &xsc_dev_ops;
+
+   eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
+   eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
+
+   rte_eth_dev_probing_finish(eth_dev);
 
return 0;
 }
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index a05a63193c..7c7e71d618 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -5,11 +5,41 @@
 #ifndef _XSC_ETHDEV_H_
 #define _XSC_ETHDEV_H_
 
+struct xsc_dev_config {
+   uint8_t pph_flag;
+   unsigned int hw_csum:1;
+   unsigned int tso:1;
+   unsigned int tso_max_payload_sz;
+};
+
 struct xsc_ethdev_priv {
struct rte_eth_dev 

[PATCH v2 13/19] net/xsc: add ethdev start and stop ops

2024-09-10 Thread WanRenyong
Implement xsc ethdev start and stop function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 drivers/net/xsc/meson.build  |   1 +
 drivers/net/xsc/xsc_ctrl.h   | 152 ++-
 drivers/net/xsc/xsc_defs.h   |   2 +
 drivers/net/xsc/xsc_dev.h|   3 +
 drivers/net/xsc/xsc_ethdev.c | 740 ++-
 drivers/net/xsc/xsc_ethdev.h |  10 +
 drivers/net/xsc/xsc_rxtx.c   |  22 ++
 drivers/net/xsc/xsc_rxtx.h   |  68 +++-
 8 files changed, 994 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/xsc/xsc_rxtx.c

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index f38ebdfe0f..5f15c8def5 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -11,6 +11,7 @@ sources = files(
 'xsc_dev.c',
 'xsc_utils.c',
 'xsc_ctrl.c',
+'xsc_rxtx.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index c33e625097..e51847d68f 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -5,7 +5,17 @@
 #ifndef _XSC_CTRL_H_
 #define _XSC_CTRL_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE  4096
+#endif
 
 #define XSC_IOCTL_CHECK_FIELD  0x01234567
 
@@ -25,6 +35,17 @@ enum xsc_ioctl_opmod {
XSC_IOCTL_OP_GET_LOCAL,
 };
 
+#define XSC_DIV_ROUND_UP(n, d) ({ \
+   typeof(d) _d = (d); \
+   typeof(n) _n = (n); \
+   ((_n) + (_d) - 1) / (_d); \
+})
+
+enum {
+   XSC_IOCTL_SET_QP_STATUS = 0x200,
+   XSC_IOCTL_SET_MAX
+};
+
 struct xsc_ioctl_attr {
uint16_t opcode; /* ioctl cmd */
uint16_t length; /* data length */
@@ -40,7 +61,18 @@ struct xsc_ioctl_hdr {
struct xsc_ioctl_attr attr;
 };
 
-/* ioctl */
+enum {
+   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_inbox_hdr {
__be16 opcode;
uint8_trsvd[4];
@@ -53,7 +85,6 @@ struct xsc_outbox_hdr {
__be32  syndrome;
 };
 
-/* ioctl mbox */
 struct xsc_ioctl_mbox_in {
struct xsc_inbox_hdrhdr;
__be16  len;
@@ -96,6 +127,54 @@ struct xsc_cmd_modify_nic_hca_mbox_out {
uint8_t rsvd0[4];
 };
 
+struct xsc_create_qp_request {
+   __be16  input_qpn;
+   __be16  pa_num;
+   uint8_t qp_type;
+   uint8_t log_sq_sz;
+   uint8_t log_rq_sz;
+   uint8_t dma_direct;
+   __be32  pdn;
+   __be16  cqn_send;
+   __be16  cqn_recv;
+   __be16  glb_funcid;
+   uint8_t page_shift;
+   uint8_t rsvd;
+   __be64  pas[];
+};
+
+struct xsc_create_multiqp_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be16  qp_num;
+   uint8_t qp_type;
+   uint8_t rsvd;
+   __be32  req_len;
+   uint8_t data[];
+};
+
+struct xsc_create_multiqp_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   __be32  qpn_base;
+};
+
+
+struct xsc_destroy_qp_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be32  qpn;
+   uint8_t rsvd[4];
+};
+
+struct xsc_destroy_qp_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   uint8_t rsvd[8];
+};
+
+struct xsc_ioctl_qp_range {
+   uint16_topcode;
+   int num;
+   uint32_tqpn;
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
@@ -136,6 +215,75 @@ struct xsc_ioctl_get_hwinfo {
uint8_t esw_mode;
 };
 
+/* for xscdv providers */
+#if !HAVE_XSC_DV_PROVIDER
+enum xscdv_obj_type {
+   XSCDV_OBJ_QP= 1 << 0,
+   XSCDV_OBJ_CQ= 1 << 1,
+   XSCDV_OBJ_SRQ   = 1 << 2,
+   XSCDV_OBJ_RWQ   = 1 << 3,
+   XSCDV_OBJ_DM= 1 << 4,
+   XSCDV_OBJ_AH= 1 << 5,
+   XSCDV_OBJ_PD= 1 << 6,
+};
+
+enum xsc_qp_create_flags {
+   XSC_QP_CREATE_RAWPACKE_TSO  = 1 << 0,
+   XSC_QP_CREATE_RAWPACKET_TSO = 1 << 0,
+   XSC_QP_CREATE_RAWPACKET_TX  = 1 << 1,
+};
+
+struct xscdv_cq_init_attr {
+   uint64_t comp_mask; /* Use enum xscdv_cq_init_attr_mask */
+   uint8_t cqe_comp_res_format; /* Use enum xscdv_cqe_comp_res_format */
+   uint32_t flags;
+   uint16_t cqe_size; /* when XSCDV_CQ_INIT_AT

[PATCH v2 11/19] net/xsc: add mailbox and structure

2024-09-10 Thread WanRenyong
Mailbox is a communication channel between driver and firmware.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ctrl.c |  8 
 drivers/net/xsc/xsc_ctrl.h | 31 +++
 2 files changed, 39 insertions(+)

diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c
index 3e37bd914e..4d5e4b4d07 100644
--- a/drivers/net/xsc/xsc_ctrl.c
+++ b/drivers/net/xsc/xsc_ctrl.c
@@ -54,3 +54,11 @@ xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
rte_free(hdr);
return ret;
 }
+
+int
+xsc_mailbox_exec(struct xsc_dev *dev, void *data_in,
+int in_len, void *data_out, int out_len)
+{
+   /* ignore opcode in hdr->attr when cmd = XSC_IOCTL_CMDQ_RAW */
+   return xsc_ioctl(dev, XSC_IOCTL_CMDQ_RAW, 0, data_in, in_len, data_out, 
out_len);
+}
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index d343e1b1a7..a7259c5fcb 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -40,6 +40,35 @@ struct xsc_ioctl_hdr {
struct xsc_ioctl_attr attr;
 };
 
+/* ioctl */
+struct xsc_inbox_hdr {
+   __be16 opcode;
+   uint8_trsvd[4];
+   __be16 opmod;
+};
+
+struct xsc_outbox_hdr {
+   uint8_t status;
+   uint8_t rsvd[3];
+   __be32  syndrome;
+};
+
+/* ioctl mbox */
+struct xsc_ioctl_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be16  len;
+   __be16  rsvd;
+   uint8_t data[];
+};
+
+struct xsc_ioctl_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   __be32  error;
+   __be16  len;
+   __be16  rsvd;
+   uint8_t data[];
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
@@ -82,5 +111,7 @@ struct xsc_ioctl_get_hwinfo {
 
 int xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
  void *data_in, int in_len, void *data_out, int out_len);
+int xsc_mailbox_exec(struct xsc_dev *dev, void *data_in,
+int in_len, void *data_out, int out_len);
 
 #endif /* _XSC_CTRL_H_ */
-- 
2.25.1


[PATCH v2 14/19] net/xsc: add ethdev Rx burst

2024-09-10 Thread WanRenyong
Implement xsc PMD receive function.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 
---
 drivers/net/xsc/xsc_rxtx.c | 189 -
 drivers/net/xsc/xsc_rxtx.h |   9 ++
 2 files changed, 197 insertions(+), 1 deletion(-)

diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 66b1511c6a..28360e62ff 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -7,11 +7,198 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 #include "xsc_rxtx.h"
+#include "xsc_utils.h"
+#include "xsc_ctrl.h"
+
+#define XSC_CQE_OWNER_MASK 0x1
+#define XSC_CQE_OWNER_HW   0x2
+#define XSC_CQE_OWNER_SW   0x4
+#define XSC_CQE_OWNER_ERR  0x8
+
+#define XSC_MAX_RX_BURST_MBUFS 64
+
+static __rte_always_inline int
+check_cqe_own(volatile struct xsc_cqe *cqe, const uint16_t cqe_n,
+ const uint16_t ci)
+
+{
+   if (unlikely(((cqe->owner & XSC_CQE_OWNER_MASK) !=
+   ((ci >> cqe_n) & XSC_CQE_OWNER_MASK
+   return XSC_CQE_OWNER_HW;
+
+   rte_io_rmb();
+   if (cqe->msg_len <= 0 && cqe->is_error)
+   return XSC_CQE_OWNER_ERR;
+
+   return XSC_CQE_OWNER_SW;
+}
+
+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 = check_cqe_own(cqe, rxq->cqe_n, rxq->cq_ci);
+   if (unlikely(ret != XSC_CQE_OWNER_SW)) {
+   if (unlikely(ret == XSC_CQE_OWNER_ERR)) {
+   /* TODO */
+   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)
 {
-   return 0;
+   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;
+   uint32_t rq_ci = rxq->rq_ci;
+   int len = 0;
+   uint32_t cq_ci_two = 0;
+   int read_cqe_num = 0;
+   int read_cqe_num_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))
+   break;
+
+   if (!pkt) {
+   if (read_cqe_num) {
+   cqe = cqe + 1;
+   len = read_cqe_num_len;
+   read_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) {
+   read_cqe_num_len = xsc_rx_poll_len(rxq, 
cqe + 1);
+

[PATCH v2 12/19] net/xsc: add ethdev RSS hash ops

2024-09-10 Thread WanRenyong
Implement xsc ethdev RSS hash config get and update functions.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  3 +++
 drivers/net/xsc/xsc_ctrl.h   | 27 
 drivers/net/xsc/xsc_ethdev.c | 43 +++-
 drivers/net/xsc/xsc_ethdev.h | 17 +
 drivers/net/xsc/xsc_utils.h  |  5 +++-
 5 files changed, 93 insertions(+), 2 deletions(-)

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_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index a7259c5fcb..c33e625097 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -69,6 +69,33 @@ struct xsc_ioctl_mbox_out {
uint8_t data[];
 };
 
+struct xsc_nic_attr {
+   __be16   caps;
+   __be16   caps_mask;
+   uint8_t  mac_addr[6];
+};
+
+struct xsc_rss_modify_attr {
+   uint8_t  caps_mask;
+   uint8_t  rss_en;
+   __be16   rqn_base;
+   __be16   rqn_num;
+   uint8_t  hfunc;
+   __be32   hash_tmpl;
+   uint8_t  hash_key[52];
+};
+
+struct xsc_cmd_modify_nic_hca_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   struct xsc_nic_attr nic;
+   struct xsc_rss_modify_attr  rss;
+};
+
+struct xsc_cmd_modify_nic_hca_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   uint8_t rsvd0[4];
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index f21b105e83..25b2a4c44d 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -17,6 +17,45 @@ static int
 xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, 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 |= BIT(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(BIT(XSC_TBM_CAP_RSS));
+   in.nic.caps = in.nic.caps_mask;
+
+   ret = xsc_mailbox_exec(priv->xdev, &in, sizeof(in), &out, sizeof(out));
+   if (ret != 0 || out.hdr.status != 0)
+   return -1;
+   return 0;
+}
+
+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) {
+   rte_errno = EINVAL;
+   return -rte_errno;
+   }
+   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;
 }
 
@@ -30,7 +69,7 @@ xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev,
if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN ||
rss_conf->rss_key == NULL) {
PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
-   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
return -EINVAL;
}
 
@@ -184,6 +223,8 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_configure = xsc_ethdev_configure,
.rx_queue_setup = xsc_ethdev_rx_queue_setup,
.tx_queue_setup = xsc_ethdev_tx_queue_setup,
+   .rss_hash_update = xsc_ethdev_rss_hash_update,
+   .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 10c3d8cc87..fb92d47dd0 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,8 @@
 #define XSC_MAX_DESC_NUMBER 1024
 #define XSC_RX_FREE_THRESH 32
 
+#define XSC_CMD_OP_MODIFY_NIC_HCA 0x812
+
 struct xsc_dev_config {
uint8_t pph_flag;
unsigned int hw_csum:1;
@@ -51,4 +53,19 @@ struct xsc_ethdev_priv {
 #define TO_XSC_ETHDEV_PRI

[PATCH v2 18/19] net/xsc: add dev infos get

2024-09-10 Thread WanRenyong
Implement xsc ethdev information get function.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 60 
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index bc5e827d70..ba3c215112 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -918,6 +918,65 @@ 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->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,
@@ -1045,6 +1104,7 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
+   .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 v2 15/19] net/xsc: add ethdev Tx burst

2024-09-10 Thread WanRenyong
Implement xsc PMD transmit function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 doc/guides/nics/features/xsc.ini |   4 +
 drivers/net/xsc/xsc_rxtx.c   | 231 ++-
 drivers/net/xsc/xsc_rxtx.h   |   9 ++
 3 files changed, 242 insertions(+), 2 deletions(-)

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_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 28360e62ff..7a31cd428c 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -14,6 +14,8 @@
 #define XSC_CQE_OWNER_HW   0x2
 #define XSC_CQE_OWNER_SW   0x4
 #define XSC_CQE_OWNER_ERR  0x8
+#define XSC_OPCODE_RAW 0x7
+#define XSC_TX_COMP_CQE_HANDLE_MAX 2
 
 #define XSC_MAX_RX_BURST_MBUFS 64
 
@@ -201,9 +203,234 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, 
uint16_t pkts_n)
return nb_pkts;
 }
 
+static __rte_always_inline void
+xsc_tx_elts_free(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 = 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;
+   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_compiler_barrier();
+   *txq->cq_db = rte_cpu_to_le_32(cq_db.cq_data);
+
+   /* 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_free(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;
+
+   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(mbu

[PATCH v2 19/19] net/xsc: add dev basic stats ops

2024-09-10 Thread WanRenyong
Implement xsc ethdev basic stats get and reset functions.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 76 
 drivers/net/xsc/xsc_rxtx.c   | 11 -
 drivers/net/xsc/xsc_rxtx.h   | 15 +++
 4 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 84c5ff4b6b..d73cf9d136 100644
--- a/doc/guides/nics/features/xsc.ini
+++ b/doc/guides/nics/features/xsc.ini
@@ -12,6 +12,7 @@ L3 checksum offload  = Y
 L4 checksum offload  = Y
 Inner L3 checksum= Y
 Inner L4 checksum= Y
+Basic stats  = 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 ba3c215112..9fa7173a7a 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -1089,6 +1089,80 @@ xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
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;
+
+   memset(stats, 0, sizeof(struct rte_eth_stats));
+   for (i = 0; i < rxqs_n; ++i) {
+   rxq = xsc_rxq_get(dev, 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(dev, 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(dev, 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(dev, i);
+   if (unlikely(txq == NULL))
+   continue;
+   memset(&txq->stats, 0, sizeof(struct xsc_txq_stats));
+   }
+
+   return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
   __rte_unused int wait_to_complete)
@@ -1104,6 +1178,8 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
+   .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,
diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 7a31cd428c..8aed8f4b12 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -62,6 +62,7 @@ xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct 
xsc_cqe *cqe)
ret = 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;
/* TODO */
  

[PATCH v2 17/19] net/xsc: add dev link and MTU ops

2024-09-10 Thread WanRenyong
XSC PMD does not support update link right now, in order to
start device successfully link_update function always return 0.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 50 
 drivers/net/xsc/xsc_utils.c  | 23 +++
 drivers/net/xsc/xsc_utils.h  |  1 +
 4 files changed, 75 insertions(+)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 772c6418c4..84c5ff4b6b 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_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 0dc1a63cc5..bc5e827d70 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -187,6 +187,20 @@ xsc_ethdev_configure(struct rte_eth_dev *dev)
return -rte_errno;
 }
 
+static int
+xsc_ethdev_set_link_down(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   return xsc_link_process(dev, priv->ifindex, IFF_UP);
+}
+
+static int
+xsc_ethdev_set_link_up(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   return xsc_link_process(dev, priv->ifindex, ~IFF_UP);
+}
+
 static int
 xsc_init_obj(struct xscdv_obj *obj, uint64_t obj_type)
 {
@@ -983,6 +997,39 @@ 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);
+   uint16_t get_mtu = 0;
+   int ret = 0;
+
+   if (priv->eth_type != RTE_ETH_REPRESENTOR_PF) {
+   priv->mtu = mtu;
+   return 0;
+   }
+
+   ret = xsc_get_mtu(&priv->mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   ret = xsc_set_mtu(mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   ret = xsc_get_mtu(&get_mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   if (get_mtu != mtu) {
+   PMD_DRV_LOG(ERR, "mtu set to %u failure", mtu);
+   return -EAGAIN;
+   }
+
+   priv->mtu = mtu;
+   return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
   __rte_unused int wait_to_complete)
@@ -994,12 +1041,15 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_configure = xsc_ethdev_configure,
.dev_start = xsc_ethdev_start,
.dev_stop = xsc_ethdev_stop,
+   .dev_set_link_down = xsc_ethdev_set_link_down,
+   .dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
.rx_queue_setup = xsc_ethdev_rx_queue_setup,
.tx_queue_setup = xsc_ethdev_tx_queue_setup,
.rx_queue_release = xsc_ethdev_rxq_release,
.tx_queue_release = xsc_ethdev_txq_release,
+   .mtu_set = xsc_ethdev_set_mtu,
.rss_hash_update = xsc_ethdev_rss_hash_update,
.rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c
index e40b0904b7..788cdfa54a 100644
--- a/drivers/net/xsc/xsc_utils.c
+++ b/drivers/net/xsc/xsc_utils.c
@@ -321,3 +321,26 @@ xsc_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uint32_t i
dev->data->mac_addrs[index] = *mac;
return 0;
 }
+
+int
+xsc_link_process(struct rte_eth_dev *dev __rte_unused,
+uint32_t ifindex, unsigned int flags)
+{
+   struct ifreq request;
+   struct ifreq *ifr = &request;
+   char ifname[sizeof(ifr->ifr_name)];
+   int ret;
+   unsigned int keep = ~IFF_UP;
+
+   if (if_indextoname(ifindex, ifname) == NULL)
+   return -rte_errno;
+
+   ret = xsc_ifreq_by_ifname(ifname, SIOCGIFFLAGS, &request);
+   if (ret)
+   return ret;
+
+   request.ifr_flags &= keep;
+   request.ifr_flags |= flags & ~keep;
+
+   return xsc_ifreq_by_ifname(ifname, SIOCSIFFLAGS, &request);
+}
diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h
index 672ba3871e..d9327020cd 100644
--- a/drivers/net/xsc/xsc_utils.h
+++ b/drivers/net/xsc/xsc_utils.h
@@ -22,5 +22,6 @@ int xsc_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uint32
 int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex);
 int xsc_set_mtu(uint16_t mtu, uint32_t ifindex);
 int xsc_get_mac(uint8_t *mac, uint32_t ifindex);
+int xsc_link_process(struct rte_eth_dev *dev, uint32_t ifindex, unsigned int 
flags);
 
 #endif
-- 
2.25.1


[PATCH v2 16/19] net/xsc: configure xsc device hardware table

2024-09-10 Thread WanRenyong
Configure hardware table to enable transmission and reception of
the queues.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 
---
 drivers/net/xsc/meson.build  |   1 +
 drivers/net/xsc/xsc_ctrl.h   |  22 +
 drivers/net/xsc/xsc_ethdev.c |  39 
 drivers/net/xsc/xsc_flow.c   | 167 +++
 drivers/net/xsc/xsc_flow.h   |  67 ++
 5 files changed, 296 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_flow.c
 create mode 100644 drivers/net/xsc/xsc_flow.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 5f15c8def5..e922e3b320 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -12,6 +12,7 @@ sources = files(
 'xsc_utils.c',
 'xsc_ctrl.c',
 'xsc_rxtx.c',
+'xsc_flow.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index e51847d68f..51bda47ca8 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -41,6 +41,12 @@ enum xsc_ioctl_opmod {
((_n) + (_d) - 1) / (_d); \
 })
 
+enum {
+   XSC_CMD_OP_MODIFY_RAW_QP = 0x81f,
+   XSC_CMD_OP_IOCTL_FLOW= 0x900,
+   XSC_CMD_OP_MAX
+};
+
 enum {
XSC_IOCTL_SET_QP_STATUS = 0x200,
XSC_IOCTL_SET_MAX
@@ -72,6 +78,22 @@ enum {
XSC_QUEUE_TYPE_RAW_TX = 7,
XSC_QUEUE_TYPE_INVALID= 0xFF,
 };
+enum  xsc_flow_tbl_id {
+   XSC_FLOW_TBL_IPAT = 0,
+   XSC_FLOW_TBL_PCT_V4 = 4,
+   XSC_FLOW_TBL_EPAT = 19,
+   XSC_FLOW_TBL_MAX
+};
+
+enum xsc_ioctl_op {
+   XSC_IOCTL_OP_ADD,
+   XSC_IOCTL_OP_DEL,
+   XSC_IOCTL_OP_GET,
+   XSC_IOCTL_OP_CLR,
+   XSC_IOCTL_OP_MOD,
+   XSC_IOCTL_OP_MAX
+};
+
 
 struct xsc_inbox_hdr {
__be16 opcode;
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 35daa16528..0dc1a63cc5 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -11,6 +11,7 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 #include "xsc_utils.h"
+#include "xsc_flow.h"
 #include "xsc_ctrl.h"
 #include "xsc_rxtx.h"
 
@@ -787,6 +788,43 @@ xsc_rxq_start(struct rte_eth_dev *dev)
return -rte_errno;
 }
 
+static int
+xsc_dev_start_config_hw(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 = 0;
+   int rep_id;
+   struct xsc_rxq_data *rxq = xsc_rxq_get(dev, 0);
+   uint16_t rx_qpn = (uint16_t)rxq->qpn;
+   static int xsc_global_pct_priority_idx = 128;
+
+   if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID)
+   return -1;
+
+   hwinfo = &priv->xdev->hwinfo;
+   rep_id = priv->representor_id;
+   peer_dstinfo = hwinfo->mac_phy_port;
+   peer_logicalport = hwinfo->mac_phy_port;
+
+   qp_set_id = rep_id % 511 + 1;
+   logical_port = priv->xdev->vfos_logical_in_port + qp_set_id - 1;
+   local_dstinfo = logical_port;
+   pcie_logic_port = hwinfo->pcie_no + 8;
+
+   xsc_create_ipat(dev, logical_port, peer_dstinfo);
+   xsc_create_epat(dev, local_dstinfo, pcie_logic_port,
+   rx_qpn - hwinfo->raw_rss_qp_id_base, priv->num_rq);
+   xsc_create_pct(dev, logical_port, peer_dstinfo, 
xsc_global_pct_priority_idx++);
+   xsc_create_pct(dev, peer_logicalport, local_dstinfo, 
xsc_global_pct_priority_idx++);
+   return 0;
+}
+
 static int
 xsc_ethdev_start(struct rte_eth_dev *dev)
 {
@@ -812,6 +850,7 @@ xsc_ethdev_start(struct rte_eth_dev *dev)
dev->rx_pkt_burst = xsc_rx_burst;
dev->tx_pkt_burst = xsc_tx_burst;
 
+   ret = xsc_dev_start_config_hw(dev);
return 0;
 
 error:
diff --git a/drivers/net/xsc/xsc_flow.c b/drivers/net/xsc/xsc_flow.c
new file mode 100644
index 00..f1101b29d0
--- /dev/null
+++ b/drivers/net/xsc/xsc_flow.c
@@ -0,0 +1,167 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_dev.h"
+#include "xsc_ethdev.h"
+#include "xsc_utils.h"
+#include "xsc_flow.h"
+#include "xsc_ctrl.h"
+
+
+static int
+xsc_flow_exec(struct xsc_dev *dev, void *cmd, int len, int table, int opmod)
+{
+   struct xsc_ioctl_data_tl *tl;
+   struct xsc_ioctl_mbox_in *in;
+   struct xsc_ioctl_mbox_out *out;
+   int in_len;
+   int out_len;
+   int data_len;
+   int cmd_len;
+   int ret;
+
+   data_len = sizeof(struct xsc_ioctl_data_tl) + len;
+   in_len = sizeof(stru

Re: [PATCH v2 00/19] XSC PMD for Yunsilicon NICs

2024-09-11 Thread WanRenyong
On 2024/9/11 16:51, Ferruh Yigit wrote:
> Hi WanRenyong,
>
> Thanks for upstreaming the driver,
> I did not had a chance to check in detail yet, but when sending next
> version can you please send patch series as threaded, with following
> git-send-email arguments:
> `--thread --no-chain-reply-to`
>
> Or this can be added to .gitconfig as documented in [1].
>
>
> Also there is new PMD upstreaming guide work in progress [2], current
> version still can be useful, can you please check it.
>
> Thanks,
> ferruh
>
>
> [1]
> https://old.dpdk.org/dev
>
> [2]
> https://patches.dpdk.org/project/dpdk/patch/20240910145801.46186-1-nandinipersad...@gmail.com/

Hi, ferruh,

Thanks for you reply, I got it.

--
Thanks,
WanRenyong


Re: [PATCH v2 02/19] net/xsc: add log macro

2024-09-11 Thread WanRenyong
On 2024/9/11 15:40, David Marchand wrote:
> On Wed, Sep 11, 2024 at 4:08 AM WanRenyong  wrote:
>> Add log macro to print runtime messages and trace functions.
>>
>> Signed-off-by: WanRenyong 
>> ---
>>   drivers/net/xsc/xsc_ethdev.c | 11 +
>>   drivers/net/xsc/xsc_log.h| 44 
>>   2 files changed, 55 insertions(+)
>>   create mode 100644 drivers/net/xsc/xsc_log.h
>>
>> diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
>> index 0e48cb76fa..58ceaa3940 100644
>> --- a/drivers/net/xsc/xsc_ethdev.c
>> +++ b/drivers/net/xsc/xsc_ethdev.c
>> @@ -1,3 +1,14 @@
>>   /* SPDX-License-Identifier: BSD-3-Clause
>>* Copyright 2024 Yunsilicon Technology Co., Ltd.
>>*/
>> +
>> +#include "xsc_log.h"
>> +
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
>> +#ifdef RTE_ETHDEV_DEBUG_RX
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_rx, rx, DEBUG);
>> +#endif
>> +#ifdef RTE_ETHDEV_DEBUG_TX
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_tx, tx, DEBUG);
>> +#endif
>> diff --git a/drivers/net/xsc/xsc_log.h b/drivers/net/xsc/xsc_log.h
>> new file mode 100644
>> index 00..163145ff09
>> --- /dev/null
>> +++ b/drivers/net/xsc/xsc_log.h
>> @@ -0,0 +1,44 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright 2024 Yunsilicon Technology Co., Ltd.
>> + */
>> +
>> +#ifndef _XSC_LOG_H_
>> +#define _XSC_LOG_H_
>> +
>> +#include 
>> +
>> +extern int xsc_logtype_init;
>> +extern int xsc_logtype_driver;
>> +
>> +#define PMD_INIT_LOG(level, fmt, ...) \
>> +   rte_log(RTE_LOG_ ## level, xsc_logtype_init, "%s(): " fmt "\n", \
>> +   __func__, ##__VA_ARGS__)
>> +
>> +#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
>> +
>> +#ifdef RTE_ETHDEV_DEBUG_RX
>> +extern int xsc_logtype_rx;
>> +#define PMD_RX_LOG(level, fmt, ...)\
>> +   rte_log(RTE_LOG_ ## level, xsc_logtype_rx,  \
>> +   "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
>> +#else
>> +#define PMD_RX_LOG(level, fmt, ...) do { } while (0)
>> +#endif
>> +
>> +#ifdef RTE_ETHDEV_DEBUG_TX
>> +extern int xsc_logtype_tx;
>> +#define PMD_TX_LOG(level, fmt, ...)\
>> +   rte_log(RTE_LOG_ ## level, xsc_logtype_tx,  \
>> +   "%s(): " fmt "\n", __func__, ##__VA_ARGS__)
>> +#else
>> +#define PMD_TX_LOG(level, fmt, ...) do { } while (0)
>> +#endif
>> +
>> +#define PMD_DRV_LOG_RAW(level, fmt, ...) \
>> +   rte_log(RTE_LOG_ ## level, xsc_logtype_driver, "%s(): " fmt, \
>> +   __func__, ##__VA_ARGS__)
>> +
>> +#define PMD_DRV_LOG(level, fmt, ...) \
>> +   PMD_DRV_LOG_RAW(level, fmt "\n", ##__VA_ARGS__)
>> +
>> +#endif /* _XSC_LOG_H_ */
> Please use RTE_LOG_LINE_PREFIX in those macros.
>
>
OK, will fix it in next version.

-- 
Thanks,
WanRenyong


Re: [PATCH v2 04/19] net/xsc: add xsc device init and uninit

2024-09-11 Thread WanRenyong
On 2024/9/11 11:47, Stephen Hemminger wrote:
> On Wed, 11 Sep 2024 10:07:25 +0800
> "WanRenyong"  wrote:
>
>> +
>> +sprintf(path, "%s/device/uevent", dev_path);
> better to use snprintf for safety
OK,  will fix it in next version.
>> +while (fgets(line, sizeof(line), file) == line) {
>> +size_t len = strlen(line);
>> +
>> +/* Truncate long lines. */
>> +if (len == (sizeof(line) - 1)) {
>> +while (line[(len - 1)] != '\n') {
>> +int n = fgetc(file);
>> +
>> +if (n == EOF)
>> +goto out;
>> +line[(len - 1)] = n;
>> +}
>> +/* No match for long lines. */
>> +continue;
>> +}
> If you have to deal with long lines better to use something
> like getline() that handles arbitrary length.
I will think about it.

Hello Stephen,

Thanks for your review,  my reply please see above.

-- 
Thanks,
WanRenyong


Re: [PATCH v2 05/19] net/xsc: add ioctl command interface

2024-09-11 Thread WanRenyong
On 2024/9/11 11:48, Stephen Hemminger wrote:
> On Wed, 11 Sep 2024 10:07:26 +0800
> "WanRenyong"  wrote:
>
>> +hdr = rte_zmalloc(NULL, alloc_len, RTE_CACHE_LINE_SIZE);
>> +if (hdr == NULL) {
>> +PMD_DRV_LOG(ERR, "Failed to allocate xsc ioctl cmd memory");
>> +return -ENOMEM;
>> +}
>> +
> This is local to function, use malloc() not rte_zmalloc().
> It doesn't need to come from hugepages.

Hello, Stephen,

Thanks for you review,  will fix it in next version.

-- 
Thanks,
WanRenyong


Re: [PATCH v2 05/19] net/xsc: add ioctl command interface

2024-09-11 Thread WanRenyong
On 2024/9/11 11:49, Stephen Hemminger wrote:
> On Wed, 11 Sep 2024 10:07:26 +0800
> "WanRenyong"  wrote:
>
>> +if (data_in != NULL && in_len > 0)
>> +rte_memcpy(hdr + 1, data_in, in_len);
>> +
>> +ret = ioctl(dev->ctrl_fd, cmd, hdr);
>> +if (ret == 0) {
>> +if (hdr->attr.error != 0)
>> +ret = hdr->attr.error;
>> +else if (data_out != NULL && out_len > 0)
>> +rte_memcpy(data_out, hdr + 1, out_len);
> Don't need to use rte_memcpy() here. Better to use regular memcpy() which
> has more checking

Hello, Stephen,

Thanks for your review,  will fix it in next version.

-- 
Thanks,
WanRenyong


Re: [PATCH v2 05/19] net/xsc: add ioctl command interface

2024-09-11 Thread WanRenyong
On 2024/9/11 11:50, Stephen Hemminger wrote:
> On Wed, 11 Sep 2024 10:07:26 +0800
> "WanRenyong"  wrote:
>
>> +#define XSC_IOCTL_CHECK_FIELD   0x01234567
>> +
>> +#define XSC_IOCTL_MAGIC 0x1b
>> +#define XSC_IOCTL_CMDQ \
>> +_IOWR(XSC_IOCTL_MAGIC, 1, struct xsc_ioctl_hdr)
>> +#define XSC_IOCTL_DRV_GET \
>> +_IOR(XSC_IOCTL_MAGIC, 2, struct xsc_ioctl_hdr)
>> +#define XSC_IOCTL_CMDQ_RAW \
>> +_IOWR(XSC_IOCTL_MAGIC, 5, struct xsc_ioctl_hdr)
>> +
>> +enum xsc_ioctl_opcode {
>> +XSC_IOCTL_GET_HW_INFO   = 0x100,
>> +};
>> +
>> +enum xsc_ioctl_opmod {
>> +XSC_IOCTL_OP_GET_LOCAL,
>> +};
>> +
>> +struct xsc_ioctl_attr {
>> +uint16_t opcode; /* ioctl cmd */
>> +uint16_t length; /* data length */
>> +uint32_t error;  /* ioctl error info */
>> +uint8_t data[0]; /* specific table info */
> Do not use zero length array (ZLA). Instead use variable length array (VLA)

will fix it in next version.

>
>> +};
>> +
> Does this device driver depend on some upstr
Yes, it depends on linux kernel driver of the device.

Hello, Stephen,

Thanks for your review,  please see above.

-- 
Thanks,
WanRenyong


Re: [PATCH v2 05/19] net/xsc: add ioctl command interface

2024-09-12 Thread WanRenyong
On 2024/9/12 13:50, Stephen Hemminger wrote:
> On Thu, 12 Sep 2024 12:14:08 +0800
> "WanRenyong"  wrote:
>
>>>   
>>>> +};
>>>> +
>>> Does this device driver depend on some upstr
>> Yes, it depends on linux kernel driver of the device.
>>
>> Hello, Stephen,
>>
>> Thanks for your review,  please see above.
> What is the driver? I don't see in the current kernel.org tree.
>
>
> My concern is that if the driver is not upstream, it is probably not
> going to pass the review of kernel developers. This means security and
> API changes would be required.
>
> Ioctl's are considered the worst API to the kernel and unlikely
> to be accepted.

Hello, Stephen,

Thank you for reply.Our kernel driver is being prepared to open source.

Our PMD is going to coexist with kernel driver to support flow 
bifurcation feature.

Ioctl API is used for interaction between PMD and kernel driver. As you 
said, ioctl is

the worst API, should I consider using read and write instead?

If not, could you please give me some advice?


-- 
Thanks,
WanRenyong


Re: [PATCH v2 05/19] net/xsc: add ioctl command interface

2024-09-12 Thread WanRenyong
On 2024/9/12 17:18, fengchengwen wrote:
> On 2024/9/12 16:19, WanRenyong wrote:
>> On 2024/9/12 13:50, Stephen Hemminger wrote:
>>> On Thu, 12 Sep 2024 12:14:08 +0800
>>> "WanRenyong"  wrote:
>>>
>>>>>
>>>>>> +};
>>>>>> +
>>>>> Does this device driver depend on some upstr
>>>> Yes, it depends on linux kernel driver of the device.
>>>>
>>>> Hello, Stephen,
>>>>
>>>> Thanks for your review,  please see above.
>>> What is the driver? I don't see in the current kernel.org tree.
>>>
>>>
>>> My concern is that if the driver is not upstream, it is probably not
>>> going to pass the review of kernel developers. This means security and
>>> API changes would be required.
>>>
>>> Ioctl's are considered the worst API to the kernel and unlikely
>>> to be accepted.
>> Hello, Stephen,
>>
>> Thank you for reply.Our kernel driver is being prepared to open source.
>>
>> Our PMD is going to coexist with kernel driver to support flow
>> bifurcation feature.
> It seemed uacce bus could handle this, so that you could use several queues 
> on DPDK, and
> steer flows to these queues by bifurcation feature.
>
>> Ioctl API is used for interaction between PMD and kernel driver. As you
>> said, ioctl is
>>
>> the worst API, should I consider using read and write instead?
> It seemed the ioctl couldn't handle VF located in VM, and interact 
> with PF driver which run in host kernel.
>> If not, could you please give me some advice?
> If your NIC support firmware, could consider use firmware as mid-man between 
> DPDK and kernel.
>
>>
Hello, fengchenwen,

Thanks for your reply.
Sorry for not describing it clearly. We know how to implement the 
bifurcation functionality. The main issue is that ioctl is used 
forcommunication with the kernel driver by PMD, but ioctl is not 
considered a good API, we need to find a better approach. Implemented 
via firmware might be a good idea, but it's complex, we can think about 
it in the further.Recently shoud I consider using read and write 
instead?  Is there any advise?

-- 
Thanks,
WanRenyong


Re: [PATCH v3] doc: add new driver guidelines

2024-09-12 Thread WanRenyong
On 2024/9/13 4:26, Stephen Hemminger wrote
> +
> +Finalizing
> +--
> +
> +Once the driver has been upstreamed, the author has
> +a responsibility to the community to maintain it.
> +
> +This includes the public test report. Authors must send a public
> +test report after the first upstreaming of the PMD. The same
> +public test procedure may be reproduced regularly per release.
Is there any guildelines about how to write a test report? Is there any 
template?
> +
> +Dependencies
> +
> +
> +At times, drivers may have dependencies to external software.
> +For driver dependencies, same DPDK rules for dependencies applies.
> +Dependencies should be publicly and freely available,
> +drivers which depend on non-available components will not be accepted.
> +If the required dependency is not yet publicly available, then wait to submit
> +the driver until the dependent library is available.
> +
Could you please interpret dependencies publicly and freely?There are 4 
scenarios as below:
1. A dependency is niche software, but it's open-sourced on github, is 
it publicly or freely?
2. A dependency which belongs to our company and open-sourced on github, 
is it publicly or freely?
3. A dependency which is not available in the upstream distribution, but 
available in the downstream distribution. For instance, a kernel driver 
dependent upon by PMD, which is not available in kernel.org,but it's 
available in openeuler kernel, the openeuler kernel is publicly and 
freely.  Is it publicly or freely?4. If a distribution does not include 
the dependency, I redistribute it with the dependency and open source, 
this is somewhat similar to mlnx_ofed, is it publicly or freely?

Hello, Stephen,

These guildelines are very useful for begineers like me :). I have some 
questions above, could you please explain them? Thank you.

-- 
Thanks,
WanRenyong


Re: [PATCH v3 19/19] net/xsc: add dev basic stats ops

2024-09-21 Thread WanRenyong
On 2024/9/20 3:04, Stephen Hemminger wrote:
> On Wed, 18 Sep 2024 14:09:36 +0800
> "WanRenyong"  wrote:
>
>>   
>> +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;
>> +
>> +memset(stats, 0, sizeof(struct rte_eth_stats));
> Memset here is unnecessary already done in ethdev.
Thanks for review, will fix it in the next version.

-- 
Thanks,
WanRenyong


Re: [PATCH v3 19/19] net/xsc: add dev basic stats ops

2024-09-21 Thread WanRenyong
On 2024/9/20 3:05, Stephen Hemminger wrote:
> On Wed, 18 Sep 2024 14:09:36 +0800
> "WanRenyong"  wrote:
>
>> @@ -166,6 +169,7 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, 
>> uint16_t pkts_n)
>>  /* Fill wqe */
>>  wqe->va = rte_cpu_to_le_64(rte_pktmbuf_iova(rep));
>>  rte_pktmbuf_data_len(seg) = len;
>> +rxq->stats.rx_bytes += rte_pktmbuf_pkt_len(pkt);
>>   
>>  *(pkts++) = pkt;
>>  pkt = NULL;
>> @@ -200,6 +204,7 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, 
>> uint16_t pkts_n)
>>  rxq->nb_rx_hold = 0;
>>  }
>>   
>> +rxq->stats.rx_pkts += nb_pkts;
>>  return nb_pkts;
>>   }
> You can a small performance boost by keeping a total_bytes counter in 
> rx_burst function
> and only add it to rx_bytes after the loop.
Hello, Stephen,

Thanks for review. This a good suggestion, I'll take it.

-- 
Thanks,
WanRenyong


[PATCH v3 10/19] net/xsc: add ethdev configure and rxtx queue setup ops

2024-09-17 Thread WanRenyong
Implement xsc ethdev configure, Rx and Tx queue setup functions.

Signed-off-by: WanRenyong 

---

v3:
* use variable length array (VLA) instead of zero length array (ZLA)

v2:
* fix compilation warning
---
 drivers/net/xsc/xsc_ethdev.c | 171 +++
 drivers/net/xsc/xsc_ethdev.h |   6 ++
 drivers/net/xsc/xsc_rxtx.h   | 115 +++
 3 files changed, 292 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_rxtx.h

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 6596e12df7..3c38a9e93e 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -11,8 +11,179 @@
 #include "xsc_utils.h"
 
 #include "xsc_ctrl.h"
+#include "xsc_rxtx.h"
+
+static int
+xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, uint8_t *rss_key,
+  uint8_t rss_key_len)
+{
+   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;
+
+   if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN ||
+   rss_conf->rss_key == NULL) {
+   PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
+   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+   return -EINVAL;
+   }
+
+   ret = xsc_rss_modify_cmd(priv, rss_conf->rss_key, 
rss_conf->rss_key_len);
+   if (ret == 0) {
+   rte_memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
+   priv->rss_conf.rss_key_len);
+   priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
+   priv->rss_conf.rss_hf = rss_conf->rss_hf;
+   }
+
+   return ret;
+}
+
+static int
+xsc_ethdev_configure(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+   int ret;
+   struct rte_eth_rss_conf *rss_conf;
+
+   priv->num_sq = dev->data->nb_tx_queues;
+   priv->num_rq = dev->data->nb_rx_queues;
+
+   if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
+   dev->data->dev_conf.rxmode.offloads |= 
RTE_ETH_RX_OFFLOAD_RSS_HASH;
+
+   if (priv->rss_conf.rss_key == NULL) {
+   priv->rss_conf.rss_key = rte_zmalloc(NULL, XSC_RSS_HASH_KEY_LEN,
+   RTE_CACHE_LINE_SIZE);
+   if (priv->rss_conf.rss_key == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to alloc rss_key");
+   rte_errno = ENOMEM;
+   ret = -rte_errno;
+   goto error;
+   }
+   priv->rss_conf.rss_key_len = XSC_RSS_HASH_KEY_LEN;
+   }
+
+   if (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key != NULL) {
+   rss_conf = &dev->data->dev_conf.rx_adv_conf.rss_conf;
+   ret = xsc_ethdev_rss_hash_update(dev, rss_conf);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Xsc pmd set rss key error!");
+   rte_errno = -ENOEXEC;
+   goto error;
+   }
+   }
+
+   if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
+   PMD_DRV_LOG(ERR, "xsc pmd do not support vlan filter now!");
+   rte_errno = EINVAL;
+   goto error;
+   }
+
+   if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
+   PMD_DRV_LOG(ERR, "xsc pmd do not support vlan strip now!");
+   rte_errno = EINVAL;
+   goto error;
+   }
+
+   priv->txqs = (void *)dev->data->tx_queues;
+   priv->rxqs = (void *)dev->data->rx_queues;
+   return 0;
+
+error:
+   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 

[PATCH v3 02/19] net/xsc: add log macro

2024-09-17 Thread WanRenyong
Add log macro to print runtime messages and trace functions.

Signed-off-by: WanRenyong 

---

v3:
* use RTE_LOG_LINE_PREFIX instead of rte_log
---
 drivers/net/xsc/xsc_ethdev.c | 11 +
 drivers/net/xsc/xsc_log.h| 46 
 2 files changed, 57 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_log.h

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 0e48cb76fa..58ceaa3940 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -1,3 +1,14 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2024 Yunsilicon Technology Co., Ltd.
  */
+
+#include "xsc_log.h"
+
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
+#ifdef RTE_ETHDEV_DEBUG_RX
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_rx, rx, DEBUG);
+#endif
+#ifdef RTE_ETHDEV_DEBUG_TX
+RTE_LOG_REGISTER_SUFFIX(xsc_logtype_tx, tx, DEBUG);
+#endif
diff --git a/drivers/net/xsc/xsc_log.h b/drivers/net/xsc/xsc_log.h
new file mode 100644
index 00..99a88fcd1b
--- /dev/null
+++ b/drivers/net/xsc/xsc_log.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_LOG_H_
+#define _XSC_LOG_H_
+
+#include 
+
+extern int xsc_logtype_init;
+extern int xsc_logtype_driver;
+#define RTE_LOGTYPE_XSC_INIT xsc_logtype_init
+#define RTE_LOGTYPE_XSC_DRV xsc_logtype_driver
+
+
+#define PMD_INIT_LOG(level, ...) \
+   RTE_LOG_LINE_PREFIX(level, XSC_INIT, "%s(): ", __func__, __VA_ARGS__)
+
+
+#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
+
+#ifdef RTE_ETHDEV_DEBUG_RX
+extern int xsc_logtype_rx;
+#define RTE_LOGTYPE_XSC_RX xsc_logtype_rx
+#define PMD_RX_LOG(level, ...) \
+   RTE_LOG_LINE_PREFIX(level, XSC_RX, "%s(): ", __func__, __VA_ARGS__)
+#else
+#define PMD_RX_LOG(level, ...) do { } while (0)
+#endif
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+extern int xsc_logtype_tx;
+#define RTE_LOGTYPE_XSC_TX xsc_logtype_tx
+#define PMD_TX_LOG(level, ...) \
+   RTE_LOG_LINE_PREFIX(level, XSC_TX, "%s(): ", __func__, __VA_ARGS__)
+#else
+#define PMD_TX_LOG(level, ...) do { } while (0)
+#endif
+
+#define PMD_DRV_LOG_RAW(level, ...) \
+   RTE_LOG_LINE_PREFIX(level, XSC_DRV, "%s(): ", __func__, __VA_ARGS__)
+
+#define PMD_DRV_LOG(level, ...) \
+   PMD_DRV_LOG_RAW(level, __VA_ARGS__)
+
+#endif /* _XSC_LOG_H_ */
-- 
2.25.1


Re: [PATCH v3 02/19] net/xsc: add log macro

2024-09-18 Thread WanRenyong
On 2024/9/18 16:56, David Marchand wrote:
> On Wed, Sep 18, 2024 at 8:10 AM WanRenyong  wrote:
>> Add log macro to print runtime messages and trace functions.
>>
>> Signed-off-by: WanRenyong 
>>
>> ---
>>
>> v3:
>> * use RTE_LOG_LINE_PREFIX instead of rte_log
>> ---
>>   drivers/net/xsc/xsc_ethdev.c | 11 +
>>   drivers/net/xsc/xsc_log.h| 46 
>>   2 files changed, 57 insertions(+)
>>   create mode 100644 drivers/net/xsc/xsc_log.h
>>
>> diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
>> index 0e48cb76fa..58ceaa3940 100644
>> --- a/drivers/net/xsc/xsc_ethdev.c
>> +++ b/drivers/net/xsc/xsc_ethdev.c
>> @@ -1,3 +1,14 @@
>>   /* SPDX-License-Identifier: BSD-3-Clause
>>* Copyright 2024 Yunsilicon Technology Co., Ltd.
>>*/
>> +
>> +#include "xsc_log.h"
>> +
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
>> +#ifdef RTE_ETHDEV_DEBUG_RX
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_rx, rx, DEBUG);
>> +#endif
>> +#ifdef RTE_ETHDEV_DEBUG_TX
>> +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_tx, tx, DEBUG);
>> +#endif
>> diff --git a/drivers/net/xsc/xsc_log.h b/drivers/net/xsc/xsc_log.h
>> new file mode 100644
>> index 00..99a88fcd1b
>> --- /dev/null
>> +++ b/drivers/net/xsc/xsc_log.h
>> @@ -0,0 +1,46 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright 2024 Yunsilicon Technology Co., Ltd.
>> + */
>> +
>> +#ifndef _XSC_LOG_H_
>> +#define _XSC_LOG_H_
>> +
>> +#include 
>> +
>> +extern int xsc_logtype_init;
>> +extern int xsc_logtype_driver;
>> +#define RTE_LOGTYPE_XSC_INIT xsc_logtype_init
>> +#define RTE_LOGTYPE_XSC_DRV xsc_logtype_driver
>> +
>> +
>> +#define PMD_INIT_LOG(level, ...) \
>> +   RTE_LOG_LINE_PREFIX(level, XSC_INIT, "%s(): ", __func__, __VA_ARGS__)
> Thank you for converting to RTE_LOG_LINE!
>
>> +
>> +
>> +#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>")
>> +
>> +#ifdef RTE_ETHDEV_DEBUG_RX
>> +extern int xsc_logtype_rx;
>> +#define RTE_LOGTYPE_XSC_RX xsc_logtype_rx
>> +#define PMD_RX_LOG(level, ...) \
>> +   RTE_LOG_LINE_PREFIX(level, XSC_RX, "%s(): ", __func__, __VA_ARGS__)
>> +#else
>> +#define PMD_RX_LOG(level, ...) do { } while (0)
>> +#endif
>> +
>> +#ifdef RTE_ETHDEV_DEBUG_TX
>> +extern int xsc_logtype_tx;
>> +#define RTE_LOGTYPE_XSC_TX xsc_logtype_tx
>> +#define PMD_TX_LOG(level, ...) \
>> +   RTE_LOG_LINE_PREFIX(level, XSC_TX, "%s(): ", __func__, __VA_ARGS__)
>> +#else
>> +#define PMD_TX_LOG(level, ...) do { } while (0)
>> +#endif
> I don't see any code calling those macros in the series, so I would
> remove them for now.
> You can introduce them in the future when needed.
>
>
>> +
>> +#define PMD_DRV_LOG_RAW(level, ...) \
>> +   RTE_LOG_LINE_PREFIX(level, XSC_DRV, "%s(): ", __func__, __VA_ARGS__)
>> +
>> +#define PMD_DRV_LOG(level, ...) \
>> +   PMD_DRV_LOG_RAW(level, __VA_ARGS__)
> The PMD_DRV_LOG_RAW macro seems unused and can be removed =>
> PMD_DRV_LOG() directly calls RTE_LOG_LINE_PREFIX().
>
>
Hello, David,

Thanks for review, all you mentioned above will be fixed in the next 
version.

-- 
Thanks,
WanRenyong


[PATCH v3 09/19] net/xsc: initial representor eth device

2024-09-17 Thread WanRenyong
Initialize xsc eth device private data.

Signed-off-by: WanRenyong 

---

v3:
* change the first letter of the log to uppercase
---
 drivers/net/xsc/xsc_defs.h   |   2 +-
 drivers/net/xsc/xsc_dev.h|   3 +
 drivers/net/xsc/xsc_ethdev.c |  64 +
 drivers/net/xsc/xsc_ethdev.h |  30 ++
 drivers/net/xsc/xsc_utils.c  | 105 +++
 drivers/net/xsc/xsc_utils.h  |   8 ++-
 6 files changed, 210 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 8cb67ed2e1..7dc57e5717 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -10,7 +10,7 @@
 
 #define XSC_VFREP_BASE_LOGICAL_PORT 1081
 
-
+#define XSC_MAX_MAC_ADDRESSES 3
 
 enum xsc_nic_mode {
XSC_NIC_MODE_LEGACY,
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index 93ab1e24fe..f77551f1c5 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -15,6 +15,9 @@
 
 #define XSC_DEV_REPR_PORT  0
 
+#define FUNCID_TYPE_MASK 0x1c000
+#define FUNCID_MASK 0x3fff
+
 struct xsc_hwinfo {
uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
uint32_t pcie_no; /* pcie number , 0 or 1 */
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index d6efc3c9a0..6596e12df7 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -8,15 +8,79 @@
 #include "xsc_defs.h"
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
+#include "xsc_utils.h"
+
+#include "xsc_ctrl.h"
+
+const struct eth_dev_ops xsc_dev_ops = {
+};
 
 static int
 xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
 {
struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+   struct xsc_dev_config *config = &priv->config;
+   struct rte_ether_addr mac;
 
priv->repr_port = repr_port;
repr_port->drv_data = eth_dev;
+   priv->xdev = repr_port->xdev;
+   priv->mtu = RTE_ETHER_MTU;
+   priv->funcid_type = (repr_port->info.funcid & FUNCID_TYPE_MASK) >> 14;
+   priv->funcid = repr_port->info.funcid & FUNCID_MASK;
+   if (repr_port->info.port_type == XSC_PORT_TYPE_UPLINK ||
+   repr_port->info.port_type == XSC_PORT_TYPE_UPLINK_BOND)
+   priv->eth_type = RTE_ETH_REPRESENTOR_PF;
+   else
+   priv->eth_type = RTE_ETH_REPRESENTOR_VF;
+   priv->representor_id = repr_port->info.repr_id;
+   priv->dev_data = eth_dev->data;
+   priv->ifindex = repr_port->info.ifindex;
+
+   eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+   eth_dev->data->mac_addrs = priv->mac;
+   if (rte_is_zero_ether_addr(eth_dev->data->mac_addrs)) {
+   if (priv->ifindex > 0) {
+   int ret  = xsc_get_mac(mac.addr_bytes, priv->ifindex);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Port %u cannot get MAC 
address",
+   eth_dev->data->port_id);
+   return -ENODEV;
+   }
+   } else {
+   rte_eth_random_addr(mac.addr_bytes);
+   }
+   }
+
+   xsc_mac_addr_add(eth_dev, &mac, 0);
+
+   if (priv->ifindex > 0)
+   xsc_get_mtu(&priv->mtu, priv->ifindex);
+
+   config->hw_csum = 1;
+
+   config->pph_flag =  priv->xdev->devargs.pph_mode;
+   if ((config->pph_flag & XSC_TX_PPH) != 0) {
+   config->tso = 0;
+   } else {
+   config->tso = 1;
+   if (config->tso)
+   config->tso_max_payload_sz = 1500;
+   }
+
+   priv->representor = !!priv->eth_type;
+   if (priv->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;
+   }
+   eth_dev->dev_ops = &xsc_dev_ops;
+
+   eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
+   eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
+
+   rte_eth_dev_probing_finish(eth_dev);
 
return 0;
 }
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index a05a63193c..7c7e71d618 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -5,11 +5,41 @@
 #ifndef _XSC_ETHDEV_H_
 #define _XSC_ETHDEV_H_
 
+struct xsc_dev_config {
+   uint8_t pph_flag;
+   unsigned int hw_csum:1;
+   unsigned int tso:1;
+   unsigned int tso_max_payload_sz;
+

[PATCH v3 11/19] net/xsc: add mailbox and structure

2024-09-17 Thread WanRenyong
Mailbox is a communication channel between driver and firmware.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ctrl.c |  8 
 drivers/net/xsc/xsc_ctrl.h | 31 +++
 2 files changed, 39 insertions(+)

diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c
index 956a8549e6..fe294a8bc7 100644
--- a/drivers/net/xsc/xsc_ctrl.c
+++ b/drivers/net/xsc/xsc_ctrl.c
@@ -55,3 +55,11 @@ xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
free(hdr);
return ret;
 }
+
+int
+xsc_mailbox_exec(struct xsc_dev *dev, void *data_in,
+int in_len, void *data_out, int out_len)
+{
+   /* ignore opcode in hdr->attr when cmd = XSC_IOCTL_CMDQ_RAW */
+   return xsc_ioctl(dev, XSC_IOCTL_CMDQ_RAW, 0, data_in, in_len, data_out, 
out_len);
+}
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index 833984745b..7b4d9db9ed 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -40,6 +40,35 @@ struct xsc_ioctl_hdr {
struct xsc_ioctl_attr attr;
 };
 
+/* ioctl */
+struct xsc_inbox_hdr {
+   __be16 opcode;
+   uint8_trsvd[4];
+   __be16 opmod;
+};
+
+struct xsc_outbox_hdr {
+   uint8_t status;
+   uint8_t rsvd[3];
+   __be32  syndrome;
+};
+
+/* ioctl mbox */
+struct xsc_ioctl_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be16  len;
+   __be16  rsvd;
+   uint8_t data[];
+};
+
+struct xsc_ioctl_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   __be32  error;
+   __be16  len;
+   __be16  rsvd;
+   uint8_t data[];
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
@@ -82,5 +111,7 @@ struct xsc_ioctl_get_hwinfo {
 
 int xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
  void *data_in, int in_len, void *data_out, int out_len);
+int xsc_mailbox_exec(struct xsc_dev *dev, void *data_in,
+int in_len, void *data_out, int out_len);
 
 #endif /* _XSC_CTRL_H_ */
-- 
2.25.1


[PATCH v3 08/19] net/xsc: create eth devices for representor ports

2024-09-17 Thread WanRenyong
Each representor port is a rte ethernet device.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 87 
 drivers/net/xsc/xsc_ethdev.h |  1 +
 2 files changed, 88 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 6a33cbb2cd..d6efc3c9a0 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -9,6 +9,83 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 
+static int
+xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
+{
+   struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+   priv->repr_port = repr_port;
+   repr_port->drv_data = eth_dev;
+
+   return 0;
+}
+
+static int
+xsc_ethdev_init_representors(struct rte_eth_dev *eth_dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+   struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
+   struct rte_device *dev;
+   struct xsc_dev *xdev;
+   struct xsc_repr_port *repr_port;
+   char name[RTE_ETH_NAME_MAX_LEN];
+   int i;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   dev = &priv->pci_dev->device;
+   if (dev->devargs != NULL) {
+   ret = rte_eth_devargs_parse(dev->devargs->args, ð_da, 1);
+   if (ret < 0) {
+   PMD_DRV_LOG(ERR, "Failed to parse device arguments: %s",
+   dev->devargs->args);
+   return -EINVAL;
+   }
+   }
+
+   xdev = priv->xdev;
+   ret = xsc_repr_ports_probe(xdev, eth_da.nb_representor_ports, 
RTE_MAX_ETHPORTS);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to probe %d xsc device representors",
+   eth_da.nb_representor_ports);
+   return ret;
+   }
+
+   repr_port = &xdev->repr_ports[XSC_DEV_REPR_PORT];
+   ret = xsc_ethdev_init_one_representor(eth_dev, repr_port);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to init backing representor");
+   return ret;
+   }
+
+   for (i = 1; i < xdev->num_repr_ports; i++) {
+   repr_port = &xdev->repr_ports[i];
+   snprintf(name, sizeof(name), "%s_rep_%d",
+xdev->ibv_name, repr_port->info.repr_id);
+   ret = rte_eth_dev_create(&xdev->pci_dev->device,
+name,
+sizeof(struct xsc_ethdev_priv),
+NULL, NULL,
+xsc_ethdev_init_one_representor,
+repr_port);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to create representor: %d", i);
+   goto destroy_reprs;
+   }
+   }
+
+   return 0;
+
+destroy_reprs:
+   while ((i--) > 1) {
+   repr_port = &xdev->repr_ports[i];
+   rte_eth_dev_destroy((struct rte_eth_dev *)repr_port->drv_data, 
NULL);
+   }
+   return ret;
+}
+
 static int
 xsc_ethdev_init(struct rte_eth_dev *eth_dev)
 {
@@ -26,7 +103,17 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev)
return ret;
}
 
+   ret = xsc_ethdev_init_representors(eth_dev);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to initialize representors");
+   goto uninit_xsc_dev;
+   }
+
return 0;
+
+uninit_xsc_dev:
+   xsc_dev_uninit(priv->xdev);
+   return ret;
 }
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 22fc462e25..a05a63193c 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,7 @@ struct xsc_ethdev_priv {
struct rte_eth_dev *eth_dev;
struct rte_pci_device *pci_dev;
struct xsc_dev *xdev;
+   struct xsc_repr_port *repr_port;
 };
 
 #define TO_XSC_ETHDEV_PRIV(dev) \
-- 
2.25.1


[PATCH v3 15/19] net/xsc: add ethdev Tx burst

2024-09-17 Thread WanRenyong
Implement xsc PMD transmit function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 doc/guides/nics/features/xsc.ini |   4 +
 drivers/net/xsc/xsc_rxtx.c   | 231 ++-
 drivers/net/xsc/xsc_rxtx.h   |   9 ++
 3 files changed, 242 insertions(+), 2 deletions(-)

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_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 28360e62ff..7a31cd428c 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -14,6 +14,8 @@
 #define XSC_CQE_OWNER_HW   0x2
 #define XSC_CQE_OWNER_SW   0x4
 #define XSC_CQE_OWNER_ERR  0x8
+#define XSC_OPCODE_RAW 0x7
+#define XSC_TX_COMP_CQE_HANDLE_MAX 2
 
 #define XSC_MAX_RX_BURST_MBUFS 64
 
@@ -201,9 +203,234 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, 
uint16_t pkts_n)
return nb_pkts;
 }
 
+static __rte_always_inline void
+xsc_tx_elts_free(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 = 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;
+   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_compiler_barrier();
+   *txq->cq_db = rte_cpu_to_le_32(cq_db.cq_data);
+
+   /* 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_free(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;
+
+   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(mbu

[PATCH v3 12/19] net/xsc: add ethdev RSS hash ops

2024-09-17 Thread WanRenyong
Implement xsc ethdev RSS hash config get and update functions.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  3 +++
 drivers/net/xsc/xsc_ctrl.h   | 27 
 drivers/net/xsc/xsc_ethdev.c | 43 +++-
 drivers/net/xsc/xsc_ethdev.h | 17 +
 drivers/net/xsc/xsc_utils.h  |  5 +++-
 5 files changed, 93 insertions(+), 2 deletions(-)

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_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index 7b4d9db9ed..5c90d01b54 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -69,6 +69,33 @@ struct xsc_ioctl_mbox_out {
uint8_t data[];
 };
 
+struct xsc_nic_attr {
+   __be16   caps;
+   __be16   caps_mask;
+   uint8_t  mac_addr[6];
+};
+
+struct xsc_rss_modify_attr {
+   uint8_t  caps_mask;
+   uint8_t  rss_en;
+   __be16   rqn_base;
+   __be16   rqn_num;
+   uint8_t  hfunc;
+   __be32   hash_tmpl;
+   uint8_t  hash_key[52];
+};
+
+struct xsc_cmd_modify_nic_hca_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   struct xsc_nic_attr nic;
+   struct xsc_rss_modify_attr  rss;
+};
+
+struct xsc_cmd_modify_nic_hca_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   uint8_t rsvd0[4];
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 3c38a9e93e..b0daca624f 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -17,6 +17,45 @@ static int
 xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, 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 |= BIT(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(BIT(XSC_TBM_CAP_RSS));
+   in.nic.caps = in.nic.caps_mask;
+
+   ret = xsc_mailbox_exec(priv->xdev, &in, sizeof(in), &out, sizeof(out));
+   if (ret != 0 || out.hdr.status != 0)
+   return -1;
+   return 0;
+}
+
+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) {
+   rte_errno = EINVAL;
+   return -rte_errno;
+   }
+   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;
 }
 
@@ -30,7 +69,7 @@ xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev,
if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN ||
rss_conf->rss_key == NULL) {
PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
-   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+   rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
return -EINVAL;
}
 
@@ -184,6 +223,8 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_configure = xsc_ethdev_configure,
.rx_queue_setup = xsc_ethdev_rx_queue_setup,
.tx_queue_setup = xsc_ethdev_tx_queue_setup,
+   .rss_hash_update = xsc_ethdev_rss_hash_update,
+   .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 10c3d8cc87..fb92d47dd0 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,8 @@
 #define XSC_MAX_DESC_NUMBER 1024
 #define XSC_RX_FREE_THRESH 32
 
+#define XSC_CMD_OP_MODIFY_NIC_HCA 0x812
+
 struct xsc_dev_config {
uint8_t pph_flag;
unsigned int hw_csum:1;
@@ -51,4 +53,19 @@ struct xsc_ethdev_priv {
 #define TO_XSC_ETHDEV_PRI

[PATCH v3 16/19] net/xsc: configure xsc device hardware table

2024-09-17 Thread WanRenyong
Configure hardware table to enable transmission and reception of
the queues.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 

---
v3:
* remove the \n symbol in the log
* change the first letter of the log to uppercase
---
 drivers/net/xsc/meson.build  |   1 +
 drivers/net/xsc/xsc_ctrl.h   |  22 +
 drivers/net/xsc/xsc_ethdev.c |  39 
 drivers/net/xsc/xsc_flow.c   | 168 +++
 drivers/net/xsc/xsc_flow.h   |  67 ++
 5 files changed, 297 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_flow.c
 create mode 100644 drivers/net/xsc/xsc_flow.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 32f40b50a6..429e80b650 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -17,6 +17,7 @@ sources = files(
 'xsc_utils.c',
 'xsc_ctrl.c',
 'xsc_rxtx.c',
+'xsc_flow.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index 38b53f0b8a..14030fcadf 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -41,6 +41,12 @@ enum xsc_ioctl_opmod {
((_n) + (_d) - 1) / (_d); \
 })
 
+enum {
+   XSC_CMD_OP_MODIFY_RAW_QP = 0x81f,
+   XSC_CMD_OP_IOCTL_FLOW= 0x900,
+   XSC_CMD_OP_MAX
+};
+
 enum {
XSC_IOCTL_SET_QP_STATUS = 0x200,
XSC_IOCTL_SET_MAX
@@ -72,6 +78,22 @@ enum {
XSC_QUEUE_TYPE_RAW_TX = 7,
XSC_QUEUE_TYPE_INVALID= 0xFF,
 };
+enum  xsc_flow_tbl_id {
+   XSC_FLOW_TBL_IPAT = 0,
+   XSC_FLOW_TBL_PCT_V4 = 4,
+   XSC_FLOW_TBL_EPAT = 19,
+   XSC_FLOW_TBL_MAX
+};
+
+enum xsc_ioctl_op {
+   XSC_IOCTL_OP_ADD,
+   XSC_IOCTL_OP_DEL,
+   XSC_IOCTL_OP_GET,
+   XSC_IOCTL_OP_CLR,
+   XSC_IOCTL_OP_MOD,
+   XSC_IOCTL_OP_MAX
+};
+
 
 struct xsc_inbox_hdr {
__be16 opcode;
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 33841384f5..d6433d9f59 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -11,6 +11,7 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 #include "xsc_utils.h"
+#include "xsc_flow.h"
 #include "xsc_ctrl.h"
 #include "xsc_rxtx.h"
 
@@ -788,6 +789,43 @@ xsc_rxq_start(struct rte_eth_dev *dev)
return -rte_errno;
 }
 
+static int
+xsc_dev_start_config_hw(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 = 0;
+   int rep_id;
+   struct xsc_rxq_data *rxq = xsc_rxq_get(dev, 0);
+   uint16_t rx_qpn = (uint16_t)rxq->qpn;
+   static int xsc_global_pct_priority_idx = 128;
+
+   if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID)
+   return -1;
+
+   hwinfo = &priv->xdev->hwinfo;
+   rep_id = priv->representor_id;
+   peer_dstinfo = hwinfo->mac_phy_port;
+   peer_logicalport = hwinfo->mac_phy_port;
+
+   qp_set_id = rep_id % 511 + 1;
+   logical_port = priv->xdev->vfos_logical_in_port + qp_set_id - 1;
+   local_dstinfo = logical_port;
+   pcie_logic_port = hwinfo->pcie_no + 8;
+
+   xsc_create_ipat(dev, logical_port, peer_dstinfo);
+   xsc_create_epat(dev, local_dstinfo, pcie_logic_port,
+   rx_qpn - hwinfo->raw_rss_qp_id_base, priv->num_rq);
+   xsc_create_pct(dev, logical_port, peer_dstinfo, 
xsc_global_pct_priority_idx++);
+   xsc_create_pct(dev, peer_logicalport, local_dstinfo, 
xsc_global_pct_priority_idx++);
+   return 0;
+}
+
 static int
 xsc_ethdev_start(struct rte_eth_dev *dev)
 {
@@ -813,6 +851,7 @@ xsc_ethdev_start(struct rte_eth_dev *dev)
dev->rx_pkt_burst = xsc_rx_burst;
dev->tx_pkt_burst = xsc_tx_burst;
 
+   ret = xsc_dev_start_config_hw(dev);
return 0;
 
 error:
diff --git a/drivers/net/xsc/xsc_flow.c b/drivers/net/xsc/xsc_flow.c
new file mode 100644
index 00..42b39fe601
--- /dev/null
+++ b/drivers/net/xsc/xsc_flow.c
@@ -0,0 +1,168 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_dev.h"
+#include "xsc_ethdev.h"
+#include "xsc_utils.h"
+#include "xsc_flow.h"
+#include "xsc_ctrl.h"
+
+
+static int
+xsc_flow_exec(struct xsc_dev *dev, void *cmd, int len, int table, int opmod)
+{
+   struct xsc_ioctl_data_tl *tl;
+   struct xsc_ioctl_mbox_in *in;
+   struct xsc_ioctl_mbox_out *out;
+   int in_len;
+   int out_len;
+   int data_len;
+   int cmd_len;
+   int ret;
+

[PATCH v3 13/19] net/xsc: add ethdev start and stop ops

2024-09-17 Thread WanRenyong
Implement xsc ethdev start and stop function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 

---
v3:
* remove the \n symbol in the log
* change the first letter of the log to uppercase
* use malloc instead of rte_zmalloc
---
 drivers/net/xsc/meson.build  |   1 +
 drivers/net/xsc/xsc_ctrl.h   | 152 ++-
 drivers/net/xsc/xsc_defs.h   |   2 +
 drivers/net/xsc/xsc_dev.h|   3 +
 drivers/net/xsc/xsc_ethdev.c | 741 ++-
 drivers/net/xsc/xsc_ethdev.h |  10 +
 drivers/net/xsc/xsc_rxtx.c   |  22 ++
 drivers/net/xsc/xsc_rxtx.h   |  68 +++-
 8 files changed, 995 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/xsc/xsc_rxtx.c

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index a4d7f4a884..32f40b50a6 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -16,6 +16,7 @@ sources = files(
 'xsc_dev.c',
 'xsc_utils.c',
 'xsc_ctrl.c',
+'xsc_rxtx.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
index 5c90d01b54..38b53f0b8a 100644
--- a/drivers/net/xsc/xsc_ctrl.h
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -5,7 +5,17 @@
 #ifndef _XSC_CTRL_H_
 #define _XSC_CTRL_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
+
+#ifndef PAGE_SIZE
+#define PAGE_SIZE  4096
+#endif
 
 #define XSC_IOCTL_CHECK_FIELD  0x01234567
 
@@ -25,6 +35,17 @@ enum xsc_ioctl_opmod {
XSC_IOCTL_OP_GET_LOCAL,
 };
 
+#define XSC_DIV_ROUND_UP(n, d) ({ \
+   typeof(d) _d = (d); \
+   typeof(n) _n = (n); \
+   ((_n) + (_d) - 1) / (_d); \
+})
+
+enum {
+   XSC_IOCTL_SET_QP_STATUS = 0x200,
+   XSC_IOCTL_SET_MAX
+};
+
 struct xsc_ioctl_attr {
uint16_t opcode; /* ioctl cmd */
uint16_t length; /* data length */
@@ -40,7 +61,18 @@ struct xsc_ioctl_hdr {
struct xsc_ioctl_attr attr;
 };
 
-/* ioctl */
+enum {
+   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_inbox_hdr {
__be16 opcode;
uint8_trsvd[4];
@@ -53,7 +85,6 @@ struct xsc_outbox_hdr {
__be32  syndrome;
 };
 
-/* ioctl mbox */
 struct xsc_ioctl_mbox_in {
struct xsc_inbox_hdrhdr;
__be16  len;
@@ -96,6 +127,54 @@ struct xsc_cmd_modify_nic_hca_mbox_out {
uint8_t rsvd0[4];
 };
 
+struct xsc_create_qp_request {
+   __be16  input_qpn;
+   __be16  pa_num;
+   uint8_t qp_type;
+   uint8_t log_sq_sz;
+   uint8_t log_rq_sz;
+   uint8_t dma_direct;
+   __be32  pdn;
+   __be16  cqn_send;
+   __be16  cqn_recv;
+   __be16  glb_funcid;
+   uint8_t page_shift;
+   uint8_t rsvd;
+   __be64  pas[];
+};
+
+struct xsc_create_multiqp_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be16  qp_num;
+   uint8_t qp_type;
+   uint8_t rsvd;
+   __be32  req_len;
+   uint8_t data[];
+};
+
+struct xsc_create_multiqp_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   __be32  qpn_base;
+};
+
+
+struct xsc_destroy_qp_mbox_in {
+   struct xsc_inbox_hdrhdr;
+   __be32  qpn;
+   uint8_t rsvd[4];
+};
+
+struct xsc_destroy_qp_mbox_out {
+   struct xsc_outbox_hdr   hdr;
+   uint8_t rsvd[8];
+};
+
+struct xsc_ioctl_qp_range {
+   uint16_topcode;
+   int num;
+   uint32_tqpn;
+};
+
 struct xsc_ioctl_data_tl {
uint16_t table;
uint16_t opmod;
@@ -136,6 +215,75 @@ struct xsc_ioctl_get_hwinfo {
uint8_t esw_mode;
 };
 
+/* for xscdv providers */
+#if !HAVE_XSC_DV_PROVIDER
+enum xscdv_obj_type {
+   XSCDV_OBJ_QP= 1 << 0,
+   XSCDV_OBJ_CQ= 1 << 1,
+   XSCDV_OBJ_SRQ   = 1 << 2,
+   XSCDV_OBJ_RWQ   = 1 << 3,
+   XSCDV_OBJ_DM= 1 << 4,
+   XSCDV_OBJ_AH= 1 << 5,
+   XSCDV_OBJ_PD= 1 << 6,
+};
+
+enum xsc_qp_create_flags {
+   XSC_QP_CREATE_RAWPACKE_TSO  = 1 << 0,
+   XSC_QP_CREATE_RAWPACKET_TSO = 1 << 0,
+   XSC_QP_CREATE_RAWPACKET_TX  = 1 << 1,
+};
+
+struct xscdv_cq_init_attr {
+   uint64_t comp_mask; /* Use enum xscdv_cq_init_attr_mask */
+   uint8_t cqe_comp_r

[PATCH v3 14/19] net/xsc: add ethdev Rx burst

2024-09-17 Thread WanRenyong
Implement xsc PMD receive function.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 
---
 drivers/net/xsc/xsc_rxtx.c | 189 -
 drivers/net/xsc/xsc_rxtx.h |   9 ++
 2 files changed, 197 insertions(+), 1 deletion(-)

diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 66b1511c6a..28360e62ff 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -7,11 +7,198 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 #include "xsc_rxtx.h"
+#include "xsc_utils.h"
+#include "xsc_ctrl.h"
+
+#define XSC_CQE_OWNER_MASK 0x1
+#define XSC_CQE_OWNER_HW   0x2
+#define XSC_CQE_OWNER_SW   0x4
+#define XSC_CQE_OWNER_ERR  0x8
+
+#define XSC_MAX_RX_BURST_MBUFS 64
+
+static __rte_always_inline int
+check_cqe_own(volatile struct xsc_cqe *cqe, const uint16_t cqe_n,
+ const uint16_t ci)
+
+{
+   if (unlikely(((cqe->owner & XSC_CQE_OWNER_MASK) !=
+   ((ci >> cqe_n) & XSC_CQE_OWNER_MASK
+   return XSC_CQE_OWNER_HW;
+
+   rte_io_rmb();
+   if (cqe->msg_len <= 0 && cqe->is_error)
+   return XSC_CQE_OWNER_ERR;
+
+   return XSC_CQE_OWNER_SW;
+}
+
+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 = check_cqe_own(cqe, rxq->cqe_n, rxq->cq_ci);
+   if (unlikely(ret != XSC_CQE_OWNER_SW)) {
+   if (unlikely(ret == XSC_CQE_OWNER_ERR)) {
+   /* TODO */
+   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)
 {
-   return 0;
+   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;
+   uint32_t rq_ci = rxq->rq_ci;
+   int len = 0;
+   uint32_t cq_ci_two = 0;
+   int read_cqe_num = 0;
+   int read_cqe_num_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))
+   break;
+
+   if (!pkt) {
+   if (read_cqe_num) {
+   cqe = cqe + 1;
+   len = read_cqe_num_len;
+   read_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) {
+   read_cqe_num_len = xsc_rx_poll_len(rxq, 
cqe + 1);
+

[PATCH v3 17/19] net/xsc: add dev link and MTU ops

2024-09-17 Thread WanRenyong
XSC PMD does not support update link right now, in order to
start device successfully link_update function always return 0.

Signed-off-by: WanRenyong 

---
v3:
* change the first letter of the log to uppercase
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 50 
 drivers/net/xsc/xsc_utils.c  | 23 +++
 drivers/net/xsc/xsc_utils.h  |  1 +
 4 files changed, 75 insertions(+)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 772c6418c4..84c5ff4b6b 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_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index d6433d9f59..369eba3d63 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -187,6 +187,20 @@ xsc_ethdev_configure(struct rte_eth_dev *dev)
return -rte_errno;
 }
 
+static int
+xsc_ethdev_set_link_down(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   return xsc_link_process(dev, priv->ifindex, IFF_UP);
+}
+
+static int
+xsc_ethdev_set_link_up(struct rte_eth_dev *dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+   return xsc_link_process(dev, priv->ifindex, ~IFF_UP);
+}
+
 static int
 xsc_init_obj(struct xscdv_obj *obj, uint64_t obj_type)
 {
@@ -984,6 +998,39 @@ 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);
+   uint16_t get_mtu = 0;
+   int ret = 0;
+
+   if (priv->eth_type != RTE_ETH_REPRESENTOR_PF) {
+   priv->mtu = mtu;
+   return 0;
+   }
+
+   ret = xsc_get_mtu(&priv->mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   ret = xsc_set_mtu(mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   ret = xsc_get_mtu(&get_mtu, priv->ifindex);
+   if (ret)
+   return ret;
+
+   if (get_mtu != mtu) {
+   PMD_DRV_LOG(ERR, "Mtu set to %u failure", mtu);
+   return -EAGAIN;
+   }
+
+   priv->mtu = mtu;
+   return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
   __rte_unused int wait_to_complete)
@@ -995,12 +1042,15 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_configure = xsc_ethdev_configure,
.dev_start = xsc_ethdev_start,
.dev_stop = xsc_ethdev_stop,
+   .dev_set_link_down = xsc_ethdev_set_link_down,
+   .dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
.rx_queue_setup = xsc_ethdev_rx_queue_setup,
.tx_queue_setup = xsc_ethdev_tx_queue_setup,
.rx_queue_release = xsc_ethdev_rxq_release,
.tx_queue_release = xsc_ethdev_txq_release,
+   .mtu_set = xsc_ethdev_set_mtu,
.rss_hash_update = xsc_ethdev_rss_hash_update,
.rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
 };
diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c
index 1059681619..d56661f081 100644
--- a/drivers/net/xsc/xsc_utils.c
+++ b/drivers/net/xsc/xsc_utils.c
@@ -313,3 +313,26 @@ xsc_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uint32_t i
dev->data->mac_addrs[index] = *mac;
return 0;
 }
+
+int
+xsc_link_process(struct rte_eth_dev *dev __rte_unused,
+uint32_t ifindex, unsigned int flags)
+{
+   struct ifreq request;
+   struct ifreq *ifr = &request;
+   char ifname[sizeof(ifr->ifr_name)];
+   int ret;
+   unsigned int keep = ~IFF_UP;
+
+   if (if_indextoname(ifindex, ifname) == NULL)
+   return -rte_errno;
+
+   ret = xsc_ifreq_by_ifname(ifname, SIOCGIFFLAGS, &request);
+   if (ret)
+   return ret;
+
+   request.ifr_flags &= keep;
+   request.ifr_flags |= flags & ~keep;
+
+   return xsc_ifreq_by_ifname(ifname, SIOCSIFFLAGS, &request);
+}
diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h
index 672ba3871e..d9327020cd 100644
--- a/drivers/net/xsc/xsc_utils.h
+++ b/drivers/net/xsc/xsc_utils.h
@@ -22,5 +22,6 @@ int xsc_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uint32
 int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex);
 int xsc_set_mtu(uint16_t mtu, uint32_t ifindex);
 int xsc_get_mac(uint8_t *mac, uint32_t ifindex);
+int xsc_link_process(struct rte_eth_dev *dev, uint32_t ifindex, unsigned int 
flags);
 
 #endif
-- 
2.25.1


[PATCH v3 19/19] net/xsc: add dev basic stats ops

2024-09-17 Thread WanRenyong
Implement xsc ethdev basic stats get and reset functions.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 76 
 drivers/net/xsc/xsc_rxtx.c   | 11 -
 drivers/net/xsc/xsc_rxtx.h   | 15 +++
 4 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 84c5ff4b6b..d73cf9d136 100644
--- a/doc/guides/nics/features/xsc.ini
+++ b/doc/guides/nics/features/xsc.ini
@@ -12,6 +12,7 @@ L3 checksum offload  = Y
 L4 checksum offload  = Y
 Inner L3 checksum= Y
 Inner L4 checksum= Y
+Basic stats  = 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 4407c1295b..344b645f76 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -1090,6 +1090,80 @@ xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
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;
+
+   memset(stats, 0, sizeof(struct rte_eth_stats));
+   for (i = 0; i < rxqs_n; ++i) {
+   rxq = xsc_rxq_get(dev, 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(dev, 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(dev, 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(dev, i);
+   if (unlikely(txq == NULL))
+   continue;
+   memset(&txq->stats, 0, sizeof(struct xsc_txq_stats));
+   }
+
+   return 0;
+}
+
 static int
 xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev,
   __rte_unused int wait_to_complete)
@@ -1105,6 +1179,8 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
+   .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,
diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c
index 7a31cd428c..8aed8f4b12 100644
--- a/drivers/net/xsc/xsc_rxtx.c
+++ b/drivers/net/xsc/xsc_rxtx.c
@@ -62,6 +62,7 @@ xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct 
xsc_cqe *cqe)
ret = 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;
/* TODO */
  

[PATCH v3 18/19] net/xsc: add dev infos get

2024-09-17 Thread WanRenyong
Implement xsc ethdev information get function.

Signed-off-by: WanRenyong 
---
 drivers/net/xsc/xsc_ethdev.c | 60 
 1 file changed, 60 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 369eba3d63..4407c1295b 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -919,6 +919,65 @@ 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->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,
@@ -1046,6 +1105,7 @@ const struct eth_dev_ops xsc_dev_ops = {
.dev_set_link_up = xsc_ethdev_set_link_up,
.dev_close = xsc_ethdev_close,
.link_update = xsc_ethdev_link_update,
+   .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 v3 01/19] net/xsc: add doc and minimum build framework

2024-09-17 Thread WanRenyong
Add minimum PMD code, doc and build infrastructure for xsc.

Signed-off-by: WanRenyong 

---

v2:
* fix compilation error
---
 .mailmap |  4 
 MAINTAINERS  |  9 +
 doc/guides/nics/features/xsc.ini |  9 +
 doc/guides/nics/index.rst|  1 +
 doc/guides/nics/xsc.rst  | 31 +++
 drivers/net/meson.build  |  1 +
 drivers/net/xsc/meson.build  | 18 ++
 drivers/net/xsc/xsc_ethdev.c |  3 +++
 8 files changed, 76 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_ethdev.c

diff --git a/.mailmap b/.mailmap
index 09fa253e12..d09ed30e16 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1034,6 +1034,7 @@ Nagadheeraj Rottela 
 Naga Harish K S V 
 Naga Suresh Somarowthu 
 Nalla Pradeep 
+Na Na 
 Na Na 
 Nan Chen 
 Nannan Lu 
@@ -1268,6 +1269,7 @@ Ronak Doshi  
 Ron Beider 
 Ronghua Zhang 
 RongQiang Xie 
+Rong Qian 
 RongQing Li 
 Rongwei Liu 
 Rory Sexton 
@@ -1586,6 +1588,7 @@ Waldemar Dworakowski 
 Walter Heymans 
 Wang Sheng-Hui 
 Wangyu (Eric) 
+WanRenyong 
 Waterman Cao 
 Wathsala Vithanage 
 Weichun Chen 
@@ -1638,6 +1641,7 @@ Xiaonan Zhang 
 Xiao Wang 
 Xiaoxiao Zeng 
 Xiaoxin Peng 
+Xiaoxiong Zhang 
 Xiaoyu Min  
 Xiaoyun Li 
 Xiaoyun Wang 
diff --git a/MAINTAINERS b/MAINTAINERS
index c5a703b5c0..f87d802b24 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -994,6 +994,15 @@ F: drivers/net/txgbe/
 F: doc/guides/nics/txgbe.rst
 F: doc/guides/nics/features/txgbe.ini
 
+Yunsilicon xsc
+M: WanRenyong 
+M: Na Na 
+M: Rong Qian 
+M: Xiaoxiong Zhang 
+F: drivers/net/xsc/
+F: doc/guides/nics/xsc.rst
+F: doc/guides/nics/features/xsc.ini
+
 VMware vmxnet3
 M: Jochen Behrens 
 F: drivers/net/vmxnet3/
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 c14bc7988a..9781097a21 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -69,3 +69,4 @@ Network Interface Controller Drivers
 vhost
 virtio
 vmxnet3
+xsc
diff --git a/doc/guides/nics/xsc.rst b/doc/guides/nics/xsc.rst
new file mode 100644
index 00..b7643b3ce2
--- /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 :doc:`../linux_gsg/index` to setup the basic DPDK 
environment.
+
+- Learning about Yunsilicon metaScale Series NICs using
+  `<https://www.yunsilicon.com/#/productInformation>`_.
+
+Limitations or Known issues
+---
+32bit ARCHs have not been tested and may not be supported.
+Windows and BSD are not supported yet.
diff --git a/drivers/net/meson.build b/drivers/net/meson.build
index fb6d34b782..67fbe81861 100644
--- a/drivers/net/meson.build
+++ b/drivers/net/meson.build
@@ -62,6 +62,7 @@ drivers = [
 'vhost',
 'virtio',
 'vmxnet3',
+'xsc',
 ]
 std_deps = ['ethdev', 'kvargs'] # 'ethdev' also pulls in mbuf, net, eal etc
 std_deps += ['bus_pci'] # very many PMDs depend on PCI, so make std
diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
new file mode 100644
index 00..7bd7a38483
--- /dev/null
+++ b/drivers/net/xsc/meson.build
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2024 Yunsilicon Technology Co., Ltd.
+
+if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
+build = false
+reason = 'only supported on 64bit Linux'
+endif
+
+if dpdk_conf.get('RTE_ARCH') == 'loongarch'
+build = false
+reason = 'not supported on loongarch'
+endif
+
+sources = files(
+'xsc_ethdev.c',
+)
+
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
new file mode 100644
index 00..0e48cb76fa
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
-- 
2.25.1


[PATCH v3 00/19] XSC PMD for Yunsilicon NICs

2024-09-17 Thread WanRenyong
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 

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

---

v3:
* fix compilation errors

v2:
* fix checkpatch warnings and errors

---
WanRenyong (19):
  net/xsc: add doc and minimum build framework
  net/xsc: add log macro
  net/xsc: add PCI device probe and remove
  net/xsc: add xsc device init and uninit
  net/xsc: add ioctl command interface
  net/xsc: initialize hardware information
  net/xsc: add representor ports probe
  net/xsc: create eth devices for representor ports
  net/xsc: initial representor eth device
  net/xsc: add ethdev configure and rxtx queue setup ops
  net/xsc: add mailbox and structure
  net/xsc: add ethdev RSS hash ops
  net/xsc: add ethdev start and stop ops
  net/xsc: add ethdev Rx burst
  net/xsc: add ethdev Tx burst
  net/xsc: configure xsc device hardware table
  net/xsc: add dev link and MTU ops
  net/xsc: add dev infos get
  net/xsc: add dev basic stats ops

 .mailmap |4 +
 MAINTAINERS  |9 +
 doc/guides/nics/features/xsc.ini |   18 +
 doc/guides/nics/index.rst|1 +
 doc/guides/nics/xsc.rst  |   31 +
 drivers/net/meson.build  |1 +
 drivers/net/xsc/meson.build  |   41 +
 drivers/net/xsc/xsc_ctrl.c   |   65 ++
 drivers/net/xsc/xsc_ctrl.h   |  314 +++
 drivers/net/xsc/xsc_defs.h   |   61 ++
 drivers/net/xsc/xsc_dev.c|  327 +++
 drivers/net/xsc/xsc_dev.h|   99 +++
 drivers/net/xsc/xsc_ethdev.c | 1435 ++
 drivers/net/xsc/xsc_ethdev.h |   81 ++
 drivers/net/xsc/xsc_flow.c   |  168 
 drivers/net/xsc/xsc_flow.h   |   67 ++
 drivers/net/xsc/xsc_log.h|   46 +
 drivers/net/xsc/xsc_rxtx.c   |  445 +
 drivers/net/xsc/xsc_rxtx.h   |  214 +
 drivers/net/xsc/xsc_utils.c  |  338 +++
 drivers/net/xsc/xsc_utils.h  |   27 +
 21 files changed, 3792 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_ctrl.c
 create mode 100644 drivers/net/xsc/xsc_ctrl.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_flow.c
 create mode 100644 drivers/net/xsc/xsc_flow.h
 create mode 100644 drivers/net/xsc/xsc_log.h
 create mode 100644 drivers/net/xsc/xsc_rxtx.c
 create mode 100644 drivers/net/xsc/xsc_rxtx.h
 create mode 100644 drivers/net/xsc/xsc_utils.c
 create mode 100644 drivers/net/xsc/xsc_utils.h

-- 
2.25.1


[PATCH v3 04/19] net/xsc: add xsc device init and uninit

2024-09-17 Thread WanRenyong
XSC device is a concept of low level device used to manage
hardware resource and to interact with firmware.

Signed-off-by: WanRenyong 

---

v3:
* use snprintf instead of sprintf for safety
* use getline instead of fgets to handle arbitrary length
* change the xsc_dev_args_parse function name to newline

v2:
* fix compilation error caused by missing dependency
---
 drivers/net/xsc/meson.build  |  20 +
 drivers/net/xsc/xsc_defs.h   |  23 +
 drivers/net/xsc/xsc_dev.c| 162 +++
 drivers/net/xsc/xsc_dev.h|  34 
 drivers/net/xsc/xsc_ethdev.c |  22 -
 drivers/net/xsc/xsc_ethdev.h |   1 +
 drivers/net/xsc/xsc_utils.c  |  88 +++
 drivers/net/xsc/xsc_utils.h  |  14 +++
 8 files changed, 363 insertions(+), 1 deletion(-)
 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_utils.c
 create mode 100644 drivers/net/xsc/xsc_utils.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 7bd7a38483..57d67291df 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -13,6 +13,26 @@ endif
 
 sources = files(
 'xsc_ethdev.c',
+'xsc_dev.c',
+'xsc_utils.c',
 )
 
+libnames = ['ibverbs']
+foreach libname:libnames
+lib = dependency('lib' + libname, required: false, method : 'pkg-config')
+if lib.found()
+ext_deps += lib
+else
+build = false
+reason = 'missing dependency, "' + libname + '"'
+subdir_done()
+endif
+endforeach
 
+lib = dependency('libxscale', required: false, method : 'pkg-config')
+if lib.found()
+ext_deps += lib
+cflags += '-DHAVE_XSC_DV_PROVIDER=1'
+else
+cflags += '-DHAVE_XSC_DV_PROVIDER=0'
+endif
diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index b4ede6eca6..97cd61b2d1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -8,5 +8,28 @@
 #define XSC_PCI_VENDOR_ID  0x1f67
 #define XSC_PCI_DEV_ID_MS  0x
 
+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,
+};
+
+enum xsc_flow_mode {
+   XSC_FLOW_OFF_HW_ONLY,
+   XSC_FLOW_ON_HW_ONLY,
+   XSC_FLOW_ON_HW_FIRST,
+   XSC_FLOW_HOTSPOT,
+   XSC_FLOW_MODE_NULL = 7,
+   XSC_FLOW_MODE_MAX,
+};
+
 #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..73da702f6a
--- /dev/null
+++ b/drivers/net/xsc/xsc_dev.c
@@ -0,0 +1,162 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_dev.h"
+#include "xsc_utils.h"
+
+#define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
+#define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
+
+static void
+xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs)
+{
+   struct rte_kvargs *kvlist;
+   struct xsc_devargs *xdevargs = &dev->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
+   xdevargs->flow_mode = XSC_DEV_DEF_FLOW_MODE;
+
+   rte_kvargs_free(kvlist);
+}
+
+static int
+xsc_dev_open(struct xsc_dev *dev, struct rte_pci_device *pci_dev)
+{
+   struct ibv_device *ib_dev;
+   char ctrl_file[PATH_MAX];
+   struct rte_pci_addr *pci_addr = &pci_dev->addr;
+   int ret;
+
+   ib_dev = xsc_get_ibv_device(&pci_dev->addr);
+   if (ib_dev == NULL) {
+   PMD_DRV_LOG(ERR, "Could not get ibv device");
+   return -ENODEV;
+   }
+
+   dev->ibv_ctx = ibv_open_device(ib_dev);
+   if (dev->ibv_ctx == NULL) {
+   PMD_DRV_LOG(ERR, "Could not open ibv device: %s",

[PATCH v3 05/19] net/xsc: add ioctl command interface

2024-09-17 Thread WanRenyong
IOCTL command interface is one of methods used to interact with
firmware by PMD. By using ioctl interface, PMD sends command to
the kernel module, then the kernel module translates the command
and sends it to firmware, at last, the kernel module send back
PDM the result from firmware.

Signed-off-by: WanRenyong 

---

v3:
* use malloc instead of rte_zmalloc
* use memcpy instead of rte_memcpy
* use variable length array (VLA) instead of zero length array (ZLA)
---
 drivers/net/xsc/meson.build |  1 +
 drivers/net/xsc/xsc_ctrl.c  | 57 
 drivers/net/xsc/xsc_ctrl.h  | 86 +
 3 files changed, 144 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_ctrl.c
 create mode 100644 drivers/net/xsc/xsc_ctrl.h

diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build
index 57d67291df..a4d7f4a884 100644
--- a/drivers/net/xsc/meson.build
+++ b/drivers/net/xsc/meson.build
@@ -15,6 +15,7 @@ sources = files(
 'xsc_ethdev.c',
 'xsc_dev.c',
 'xsc_utils.c',
+'xsc_ctrl.c',
 )
 
 libnames = ['ibverbs']
diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c
new file mode 100644
index 00..956a8549e6
--- /dev/null
+++ b/drivers/net/xsc/xsc_ctrl.c
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "xsc_log.h"
+#include "xsc_dev.h"
+#include "xsc_ctrl.h"
+
+int
+xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode,
+ void *data_in, int in_len, void *data_out, int out_len)
+{
+   struct xsc_ioctl_hdr *hdr;
+   int data_len = RTE_MAX(in_len, out_len);
+   int alloc_len = sizeof(struct xsc_ioctl_hdr) + data_len;
+   int ret = 0;
+
+   hdr = malloc(alloc_len);
+   memset(hdr, 0, alloc_len);
+   if (hdr == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to allocate xsc ioctl cmd memory");
+   return -ENOMEM;
+   }
+
+   hdr->check_field = XSC_IOCTL_CHECK_FIELD;
+   hdr->attr.opcode = opcode;
+   hdr->attr.length = data_len;
+   hdr->attr.error = 0;
+
+   if (data_in != NULL && in_len > 0)
+   memcpy(hdr + 1, data_in, in_len);
+
+   ret = ioctl(dev->ctrl_fd, cmd, hdr);
+   if (ret == 0) {
+   if (hdr->attr.error != 0)
+   ret = hdr->attr.error;
+   else if (data_out != NULL && out_len > 0)
+   memcpy(data_out, hdr + 1, out_len);
+   }
+
+   free(hdr);
+   return ret;
+}
diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h
new file mode 100644
index 00..833984745b
--- /dev/null
+++ b/drivers/net/xsc/xsc_ctrl.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_CTRL_H_
+#define _XSC_CTRL_H_
+
+#include 
+
+#define XSC_IOCTL_CHECK_FIELD  0x01234567
+
+#define XSC_IOCTL_MAGIC0x1b
+#define XSC_IOCTL_CMDQ \
+   _IOWR(XSC_IOCTL_MAGIC, 1, struct xsc_ioctl_hdr)
+#define XSC_IOCTL_DRV_GET \
+   _IOR(XSC_IOCTL_MAGIC, 2, struct xsc_ioctl_hdr)
+#define XSC_IOCTL_CMDQ_RAW \
+   _IOWR(XSC_IOCTL_MAGIC, 5, struct xsc_ioctl_hdr)
+
+enum xsc_ioctl_opcode {
+   XSC_IOCTL_GET_HW_INFO   = 0x100,
+};
+
+enum xsc_ioctl_opmod {
+   XSC_IOCTL_OP_GET_LOCAL,
+};
+
+struct xsc_ioctl_attr {
+   uint16_t opcode; /* ioctl cmd */
+   uint16_t length; /* data length */
+   uint32_t error;  /* ioctl error info */
+   uint8_t data[]; /* specific table info */
+};
+
+struct xsc_ioctl_hdr {
+   uint32_t check_field;
+   uint32_t domain;
+   uint32_t bus;
+   uint32_t devfn;
+   struct xsc_ioctl_attr attr;
+};
+
+struct xsc_ioctl_data_tl {
+   uint16_t table;
+   uint16_t opmod;
+   uint16_t length;
+   uint16_t rsvd;
+};
+
+struct xsc_ioctl_get_hwinfo {
+   uint32_t domain;
+   uint32_t bus;
+   uint32_t devfn;
+   uint32_t pcie_no;
+   uint32_t func_id;
+   uint32_t pcie_host;
+   uint32_t mac_phy_port;
+   uint32_t funcid_to_logic_port_off;
+   uint16_t lag_id;
+   uint16_t raw_qp_id_base;
+   uint16_t raw_rss_qp_id_base;
+   uint16_t pf0_vf_funcid_base;
+   uint16_t pf0_vf_funcid_top;
+   uint16_t pf1_vf_funcid_base;
+   uint16_t pf1_vf_funcid_top;
+   uint16_t pcie0_pf_funcid_base;
+   uint16_t pcie0_pf_funcid_top;
+   uint16_t pcie1_pf_funcid_base;
+   uint16_t pcie1_pf_funcid_top;
+   uint16_t lag_port_start;
+   uint16_t raw_tpe_qp_num;
+   int send_seg_num;
+   int recv_seg_num;
+   uint8_t on_chip_tbl_vld;
+   uint8_t dma_rw_tbl_vld;
+

[PATCH v3 06/19] net/xsc: initialize hardware information

2024-09-17 Thread WanRenyong
Getting hardware information is done by ioctl command, which
contains the information of xsc device, as well as the common
information of the NIC board.

Signed-off-by: WanRenyong 

---

v3:
* change the xsc_hwinfo_init function name to newline
---
 drivers/net/xsc/xsc_dev.c | 64 +++
 drivers/net/xsc/xsc_dev.h | 32 
 2 files changed, 96 insertions(+)

diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 73da702f6a..8c384dc25c 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -18,10 +18,65 @@
 #include "xsc_defs.h"
 #include "xsc_dev.h"
 #include "xsc_utils.h"
+#include "xsc_ctrl.h"
 
 #define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
 #define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
 
+static int
+xsc_hwinfo_init(struct xsc_dev *dev)
+{
+   struct {
+   struct xsc_ioctl_data_tl tl;
+   struct xsc_ioctl_get_hwinfo hwinfo;
+   } data;
+   struct xsc_ioctl_get_hwinfo *info = &data.hwinfo;
+   int data_len;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   data_len = sizeof(data);
+   data.tl.opmod = XSC_IOCTL_OP_GET_LOCAL;
+   ret = xsc_ioctl(dev, XSC_IOCTL_DRV_GET, XSC_IOCTL_GET_HW_INFO, &data, 
data_len,
+   &data, data_len);
+   if (ret != 0) {
+   PMD_DRV_LOG(ERR, "Failed to get hardware info");
+   return ret;
+   }
+
+   dev->hwinfo.valid = 1;
+   dev->hwinfo.pcie_no = info->pcie_no;
+   dev->hwinfo.func_id = info->func_id;
+   dev->hwinfo.pcie_host = info->pcie_host;
+   dev->hwinfo.mac_phy_port = info->mac_phy_port;
+   dev->hwinfo.funcid_to_logic_port_off = info->funcid_to_logic_port_off;
+   dev->hwinfo.lag_id = info->lag_id;
+   dev->hwinfo.raw_qp_id_base = info->raw_qp_id_base;
+   dev->hwinfo.raw_rss_qp_id_base = info->raw_rss_qp_id_base;
+   dev->hwinfo.pf0_vf_funcid_base = info->pf0_vf_funcid_base;
+   dev->hwinfo.pf0_vf_funcid_top = info->pf0_vf_funcid_top;
+   dev->hwinfo.pf1_vf_funcid_base = info->pf1_vf_funcid_base;
+   dev->hwinfo.pf1_vf_funcid_top = info->pf1_vf_funcid_top;
+   dev->hwinfo.pcie0_pf_funcid_base = info->pcie0_pf_funcid_base;
+   dev->hwinfo.pcie0_pf_funcid_top = info->pcie0_pf_funcid_top;
+   dev->hwinfo.pcie1_pf_funcid_base = info->pcie1_pf_funcid_base;
+   dev->hwinfo.pcie1_pf_funcid_top = info->pcie1_pf_funcid_top;
+   dev->hwinfo.lag_port_start = info->lag_port_start;
+   dev->hwinfo.raw_tpe_qp_num = info->raw_tpe_qp_num;
+   dev->hwinfo.send_seg_num = info->send_seg_num;
+   dev->hwinfo.recv_seg_num = info->recv_seg_num;
+   dev->hwinfo.on_chip_tbl_vld = info->on_chip_tbl_vld;
+   dev->hwinfo.dma_rw_tbl_vld = info->dma_rw_tbl_vld;
+   dev->hwinfo.pct_compress_vld = info->pct_compress_vld;
+   dev->hwinfo.chip_version = info->chip_version;
+   dev->hwinfo.hca_core_clock = info->hca_core_clock;
+   dev->hwinfo.mac_bit = info->mac_bit;
+   dev->hwinfo.esw_mode = info->esw_mode;
+
+   return 0;
+}
+
 static void
 xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs)
 {
@@ -142,11 +197,20 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct 
xsc_dev **dev)
goto dev_open_fail;
}
 
+   ret = xsc_hwinfo_init(d);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Failed to initialize hardware info");
+   goto hwinfo_init_fail;
+   return ret;
+   }
+
d->pci_dev = pci_dev;
*dev = d;
 
return 0;
 
+hwinfo_init_fail:
+   xsc_dev_close(d);
 dev_open_fail:
rte_free(d);
return ret;
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index ce9dd65400..5f0e911b42 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -11,6 +11,37 @@
 #define XSC_NIC_MODE_ARG "nic_mode"
 #define XSC_FLOW_MODE_ARG "flow_mode"
 
+struct xsc_hwinfo {
+   uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
+   uint32_t pcie_no; /* pcie number , 0 or 1 */
+   uint32_t func_id; /* pf glb func id */
+   uint32_t pcie_host; /* host pcie number */
+   uint32_t mac_phy_port; /* mac port */
+   uint32_t funcid_to_logic_port_off; /* port func id offset  */
+   uint16_t lag_id;
+   uint16_t raw_qp_id_base;
+   uint16_t raw_rss_qp_id_base;
+   uint16_t pf0_vf_funcid_base;
+   uint16_t pf0_vf_funcid_top;
+   uint16_t pf1_vf_funcid_base;
+   uint16_t pf1_vf_funcid_top;
+   uint16_t pcie0_pf_funcid_base;
+   uint16_t pcie0_pf_funcid_top;
+   uint16_t pcie1_pf_funcid_base;
+   uint16

[PATCH v3 03/19] net/xsc: add PCI device probe and remove

2024-09-17 Thread WanRenyong
Support the following Yunsilicon NICs to be probed:

- metaScale-200
- metaScale-200S
- metaScale-50
- metaScale-100Q

Signed-off-by: WanRenyong 
Signed-off-by: Na Na 
---
 drivers/net/xsc/xsc_defs.h   | 12 ++
 drivers/net/xsc/xsc_ethdev.c | 74 
 drivers/net/xsc/xsc_ethdev.h | 16 
 3 files changed, 102 insertions(+)
 create mode 100644 drivers/net/xsc/xsc_defs.h
 create mode 100644 drivers/net/xsc/xsc_ethdev.h

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
new file mode 100644
index 00..b4ede6eca6
--- /dev/null
+++ b/drivers/net/xsc/xsc_defs.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef XSC_DEFS_H_
+#define XSC_DEFS_H_
+
+#define XSC_PCI_VENDOR_ID  0x1f67
+#define XSC_PCI_DEV_ID_MS  0x
+
+#endif /* XSC_DEFS_H_ */
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 58ceaa3940..8f4d539848 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -2,7 +2,81 @@
  * Copyright 2024 Yunsilicon Technology Co., Ltd.
  */
 
+#include 
+
 #include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_ethdev.h"
+
+static int
+xsc_ethdev_init(struct rte_eth_dev *eth_dev)
+{
+   struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+   PMD_INIT_FUNC_TRACE();
+
+   priv->eth_dev = eth_dev;
+   priv->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+   return 0;
+}
+
+static int
+xsc_ethdev_uninit(struct rte_eth_dev *eth_dev)
+{
+   RTE_SET_USED(eth_dev);
+   PMD_INIT_FUNC_TRACE();
+
+   return 0;
+}
+
+static int
+xsc_ethdev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+struct rte_pci_device *pci_dev)
+{
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = rte_eth_dev_pci_generic_probe(pci_dev,
+   sizeof(struct xsc_ethdev_priv),
+   xsc_ethdev_init);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Failed to probe ethdev: %s", pci_dev->name);
+   return ret;
+   }
+
+   return 0;
+}
+
+static int
+xsc_ethdev_pci_remove(struct rte_pci_device *pci_dev)
+{
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = rte_eth_dev_pci_generic_remove(pci_dev, xsc_ethdev_uninit);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Could not remove ethdev: %s", pci_dev->name);
+   return ret;
+   }
+
+   return 0;
+}
+
+static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
+   { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
+};
+
+static struct rte_pci_driver xsc_ethdev_pci_driver = {
+   .id_table  = xsc_ethdev_pci_id_map,
+   .probe = xsc_ethdev_pci_probe,
+   .remove = xsc_ethdev_pci_remove,
+};
+
+RTE_PMD_REGISTER_PCI(net_xsc, xsc_ethdev_pci_driver);
+RTE_PMD_REGISTER_PCI_TABLE(net_xsc, xsc_ethdev_pci_id_map);
 
 RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
 RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
new file mode 100644
index 00..75aa34dc63
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_ETHDEV_H_
+#define _XSC_ETHDEV_H_
+
+struct xsc_ethdev_priv {
+   struct rte_eth_dev *eth_dev;
+   struct rte_pci_device *pci_dev;
+};
+
+#define TO_XSC_ETHDEV_PRIV(dev) \
+   ((struct xsc_ethdev_priv *)(dev)->data->dev_private)
+
+#endif /* _XSC_ETHDEV_H_ */
-- 
2.25.1


Re: [PATCH v3 03/19] net/xsc: add PCI device probe and remove

2024-09-18 Thread WanRenyong
On 2024/9/18 15:28, David Marchand wrote:
> On Wed, Sep 18, 2024 at 8:10 AM WanRenyong  wrote:
>> +static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
>> +   { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
> You need to null terminate this array with something like:
>  { .vendor_id = 0, /* sentinel */ },
>
> Otherwise the bus pci code may read a next symbol or data present in
> the .data section.
>
> ASan caught this issue when running the unit tests:
>
> ==70261==ERROR: AddressSanitizer: global-buffer-overflow on address
> 0x7f8e46bf45f0 at pc 0x7f8e56be523b bp 0x7ffe2ef88ca0 sp
> 0x7ffe2ef88c98
> READ of size 2 at 0x7f8e46bf45f0 thread T0
>  #0 0x7f8e56be523a in rte_pci_match
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:178:47
>  #1 0x7f8e56be523a in rte_pci_probe_one_driver
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:223:7
>  #2 0x7f8e56be523a in pci_probe_all_drivers
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:391:8
>  #3 0x7f8e56be3297 in pci_probe
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:418:9
>  #4 0x7f8e56fe9ea8 in rte_bus_probe
> /home/runner/work/dpdk/dpdk/build/../lib/eal/common/eal_common_bus.c:78:9
>  #5 0x7f8e570580d1 in rte_eal_init
> /home/runner/work/dpdk/dpdk/build/../lib/eal/linux/eal.c:1288:6
>  #6 0x5573a597d65d in main
> /home/runner/work/dpdk/dpdk/build/../app/test/test.c:145:9
>  #7 0x7f8e55829d8f in __libc_start_call_main
> csu/../sysdeps/nptl/libc_start_call_main.h:58:16
>  #8 0x7f8e55829e3f in __libc_start_main csu/../csu/libc-start.c:392:3
>  #9 0x5573a58bf114 in _start
> (/home/runner/work/dpdk/dpdk/build/app/dpdk-test+0x1e9114) (BuildId:
> 8d4741d712c15395a67005124e1f908d96acf7ff)
>
>
> 172 int
> 173 rte_pci_match(const struct rte_pci_driver *pci_drv,
> 174   const struct rte_pci_device *pci_dev)
> 175 {
> 176 const struct rte_pci_id *id_table;
> 177
> 178 for (id_table = pci_drv->id_table; id_table->vendor_id !=
> 0;
> 179  id_table++) {
>
>

Thanks for review, will fix it in the next version.

-- 
Thanks,
WanRenyong


[PATCH v3 07/19] net/xsc: add representor ports probe

2024-09-17 Thread WanRenyong
XSC representor port is designed to store representor resources.
In addition to common representor ports, xsc device is a special
representor port.

Signed-off-by: WanRenyong 
Signed-off-by: Na Na 
---
 drivers/net/xsc/xsc_defs.h  |  24 +++
 drivers/net/xsc/xsc_dev.c   | 103 +-
 drivers/net/xsc/xsc_dev.h   |  27 
 drivers/net/xsc/xsc_utils.c | 122 
 drivers/net/xsc/xsc_utils.h |   3 +
 5 files changed, 278 insertions(+), 1 deletion(-)

diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 97cd61b2d1..8cb67ed2e1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -8,6 +8,10 @@
 #define XSC_PCI_VENDOR_ID  0x1f67
 #define XSC_PCI_DEV_ID_MS  0x
 
+#define XSC_VFREP_BASE_LOGICAL_PORT 1081
+
+
+
 enum xsc_nic_mode {
XSC_NIC_MODE_LEGACY,
XSC_NIC_MODE_SWITCHDEV,
@@ -31,5 +35,25 @@ enum xsc_flow_mode {
XSC_FLOW_MODE_MAX,
 };
 
+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_phy_port_type {
+   XSC_PORT_TYPE_NONE = 0,
+   XSC_PORT_TYPE_UPLINK, /* mac0rep */
+   XSC_PORT_TYPE_UPLINK_BOND, /* bondrep */
+   XSC_PORT_TYPE_PFVF, /*hasreps: vfrep*/
+   XSC_PORT_TYPE_PFHPF, /*hasreps: host pf rep*/
+   XSC_PORT_TYPE_UNKNOWN,
+};
+
+#define XSC_PHY_PORT_NUM 1
+
 #endif /* XSC_DEFS_H_ */
 
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 8c384dc25c..57cdb64c62 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -23,6 +23,31 @@
 #define XSC_DEV_DEF_FLOW_MODE  XSC_FLOW_MODE_NULL
 #define XSC_DEV_CTRL_FILE_FMT  "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT
 
+static int
+xsc_dev_alloc_vfos_info(struct xsc_dev *dev)
+{
+   struct xsc_hwinfo *hwinfo;
+   int vfrep_offset = 0;
+   int base_lp = 0;
+
+   hwinfo = &dev->hwinfo;
+   if (hwinfo->pcie_no == 1) {
+   vfrep_offset = hwinfo->func_id -
+  hwinfo->pcie1_pf_funcid_base +
+  hwinfo->pcie0_pf_funcid_top -
+  hwinfo->pcie0_pf_funcid_base  + 1;
+   } else {
+   vfrep_offset = hwinfo->func_id - hwinfo->pcie0_pf_funcid_base;
+   }
+
+   base_lp = XSC_VFREP_BASE_LOGICAL_PORT;
+   if (dev->devargs.nic_mode == XSC_NIC_MODE_LEGACY)
+   base_lp = base_lp + vfrep_offset;
+
+   dev->vfos_logical_in_port = base_lp;
+   return 0;
+}
+
 static int
 xsc_hwinfo_init(struct xsc_dev *dev)
 {
@@ -175,6 +200,73 @@ xsc_dev_close(struct xsc_dev *dev)
ibv_close_device(dev->ibv_ctx);
 }
 
+static void
+xsc_repr_info_init(struct xsc_repr_info *info, enum xsc_phy_port_type 
port_type,
+  enum xsc_funcid_type funcid_type, int32_t repr_id)
+{
+   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 = XSC_PHYPORT_MAC_FUNCID << 14;
+   } else if (port_type == XSC_PORT_TYPE_PFVF) {
+   info->funcid = funcid_type << 14;
+   }
+}
+
+int
+xsc_repr_ports_probe(struct xsc_dev *dev, int nb_ports, int max_nb_ports)
+{
+   int funcid_type;
+   struct xsc_repr_port *repr_port;
+   int i;
+   int ret;
+
+   PMD_INIT_FUNC_TRACE();
+
+   ret = xsc_get_ifindex_by_pci_addr(&dev->pci_dev->addr, &dev->ifindex);
+   if (ret) {
+   PMD_DRV_LOG(ERR, "Could not get xsc dev ifindex");
+   return ret;
+   }
+
+   dev->num_repr_ports = nb_ports + 1;
+
+   dev->repr_ports = rte_zmalloc(NULL,
+ sizeof(struct xsc_repr_port) * 
dev->num_repr_ports,
+ RTE_CACHE_LINE_SIZE);
+   if (dev->repr_ports == NULL) {
+   PMD_DRV_LOG(ERR, "Failed to allocate memory for repr_ports");
+   return -ENOMEM;
+   }
+
+   funcid_type = (dev->devargs.nic_mode == XSC_NIC_MODE_SWITCHDEV) ?
+   XSC_VF_IOCTL_FUNCID : XSC_PHYPORT_MAC_FUNCID;
+
+   repr_port = &dev->repr_ports[XSC_DEV_REPR_PORT];
+   xsc_repr_info_init(&repr_port->info,
+  XSC_PORT_TYPE_UPLINK, XSC_FUNCID_TYPE_UNKNOWN, -1);
+   repr_port->info.ifindex = dev->ifindex;
+   repr_port->xdev = dev;
+
+   if ((dev->devargs.pph_mode & XSC_TX_PPH) == 0)
+   repr_port->info.repr_id = 510;
+ 

[PATCH v5 02/15] net/xsc: add xsc device initialization

2025-01-06 Thread WanRenyong
XSC device is a hardware abstract level device serving as a handle
to interact with hardware.

Signed-off-by: WanRenyong 

---

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
+   xdevargs->flow_mode = XSC_DEV_DEF_FLOW_MODE;
+
+   rte_kvargs_free(kvlist

[PATCH v5 03/15] net/xsc: add xsc mailbox

2025-01-06 Thread WanRenyong
XSC mailbox is a mechanism used for interaction between PMD and firmware.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 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;
+   rte_be16_t pcie0_pf_funcid_base;
+   rte_be16_t pcie0_pf_funcid_top;
+   r

[PATCH v5 01/15] net/xsc: add xsc PMD framework

2025-01-06 Thread WanRenyong
Add xsc PMD framework, doc and build infrastructure, supporting
PCI probe.

Signed-off-by: WanRenyong 
---
 .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   | 89 ++
 drivers/net/xsc/xsc_ethdev.h   | 15 +
 drivers/net/xsc/xsc_log.h  | 24 +++
 12 files changed, 215 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 818798273f..18293215c3 100644
--- a/.mailmap
+++ b/.mailmap
@@ -370,6 +370,7 @@ Dongdong Liu 
 Dongsheng Rong 
 Dongsu Han 
 Dong Wang 
+Dongwei Xu 
 Dongyang Pan <197020...@qq.com>
 Dong Zhou  
 Don Provan 
@@ -1062,6 +1063,7 @@ Nagadheeraj Rottela 
 Naga Harish K S V 
 Naga Suresh Somarowthu 
 Nalla Pradeep 
+Na Na 
 Na Na 
 Nan Chen 
 Nandini Persad 
@@ -1306,6 +1308,7 @@ Ronak Doshi  
 Ron Beider 
 Ronghua Zhang 
 RongQiang Xie 
+Rong Qian 
 RongQing Li 
 Rongwei Liu 
 Rory Sexton 
@@ -1633,6 +1636,7 @@ Waldemar Dworakowski 
 Walter Heymans 
 Wang Sheng-Hui 
 Wangyu (Eric) 
+WanRenyong 
 Waterman Cao 
 Wathsala Vithanage 
 Weichun Chen 
@@ -1686,6 +1690,7 @@ Xiaonan Zhang 
 Xiao Wang 
 Xiaoxiao Zeng 
 Xiaoxin Peng 
+Xiaoxiong Zhang 
 Xiaoyu Min  
 Xiaoyun Li 
 Xiaoyun Wang 
diff --git a/MAINTAINERS b/MAINTAINERS
index 60bdcce543..3426658486 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: WanRenyong 
+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 426dfcd982..6f766add72 100644
--- a/doc/guides/rel_notes/release_25_03.rst
+++ b/doc/guides/rel_notes/release_25_03.rst
@@ -55,6 +55,10 @@ New Features
  Also, make sure to start the actual text at the margin.
  ===
 
+* **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',
 'virtio',
 'vmxnet3',
+'xsc',
 '

[PATCH v5 04/15] net/xsc: add xsc dev ops to support VFIO driver

2025-01-06 Thread WanRenyong
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: WanRenyong 
Signed-off-by: Na Na 

---

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 e013d954b9..059d7d37ff 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..725a5f18d1
--- /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 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  lkey;
+   rte_le64_t  va;
+   };
+   struct {
+   uint8_t rsv2:1;
+   

[PATCH v5 05/15] net/xsc: add PCT interfaces

2025-01-06 Thread WanRenyong
PCT is the abbreviation of Packet classifier table, which is built
in NP to define behavior of various packets.

Signed-off-by: WanRenyong 
---
 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 059d7d37ff..54e0275411 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..d4eb833bf6
--- /dev/null
+++ b/drivers/net/xsc/xsc_np.c
@@ -0,0 +1,492 @@
+/*

[PATCH v5 06/15] net/xsc: initialize xsc representors

2025-01-06 Thread WanRenyong
For the design of the xsc PMD, each ethdev corresponds to a representor.

Signed-off-by: WanRenyong 
---
 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 v5 09/15] net/xsc: add ethdev start

2025-01-06 Thread WanRenyong
Implement xsc ethdev start function.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 

---
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 2072f9ccb8..d867084d78 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 7867b63f41..c940669fca 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -10,6 +10,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,
@@ -86,6 +88,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 v5 10/15] net/xsc: add ethdev stop and close

2025-01-06 Thread WanRenyong
Implement xsc ethdev close and stop functions.

Signed-off-by: WanRenyong 
---
 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 d867084d78..686d3b664d 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 c940669fca..f873fb2ebc 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -88,6 +88,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)
 {
@@ -150,6 +188,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)
 {
@@ -254,9 +316,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 v5 08/15] net/xsc: add Rx and Tx queue setup

2025-01-06 Thread WanRenyong
Implement xsc ethdev Rx and Tx queue setup functions.

Signed-off-by: WanRenyong 
Signed-off-by: Rong Qian 
---
 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 631d9c9819..7867b63f41 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -8,6 +8,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,
@@ -84,6 +86,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)
 {
@@ -112,6 +193,8 @@ xsc_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uin
 
 const struct eth_dev_ops xsc_eth_dev_ops = {
.dev_configure = xsc_ethdev_configure,
+  

[PATCH v5 07/15] net/xsc: add ethdev configure and RSS ops

2025-01-06 Thread WanRenyong
Implement xsc ethdev configure and RSS hash functions.

Signed-off-by: WanRenyong 

---

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 297c5d2324..2072f9ccb8 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 9fc5464754..631d9c9819 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -9,6 +9,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) {
+   rte_memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
+  priv->rss_conf.rss_k

[PATCH v5 11/15] net/xsc: add ethdev Rx burst

2025-01-06 Thread WanRenyong
Implement xsc ethdev Rx burst function.

Signed-off-by: WanRenyong 
Signed-off-by: Xiaoxiong Zhang 
---
 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 f873fb2ebc..2f3fe04d3c 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -310,6 +310,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 v5 14/15] net/xsc: add ethdev infos get

2025-01-06 Thread WanRenyong
Implement xsc ethdev information get ops.

Signed-off-by: WanRenyong 
---
 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 000e27222d..584890aa6f 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -365,6 +365,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,
@@ -550,6 +610,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 v5 12/15] net/xsc: add ethdev Tx burst

2025-01-06 Thread WanRenyong
Implement xsc ethdev Tx burst function.

Signed-off-by: WanRenyong 
Signed-off-by: Dongwei Xu 
---
 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 2f3fe04d3c..9cfb07b023 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -312,6 +312,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 v5 00/15] XSC PMD for Yunsilicon NICs

2025-01-06 Thread WanRenyong
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 

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

---

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

---
WanRenyong (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   |  18 +
 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   | 918 +
 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 v5 15/15] net/xsc: add ethdev link and MTU ops

2025-01-06 Thread WanRenyong
Implement xsc ethdev link and MTU ops.

Signed-off-by: WanRenyong 
---
 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 eb88517104..d73cf9d136 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 686d3b664d..d661523e13 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 584890aa6f..c1dbdf5be9 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -365,6 +365,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)
 {
@@ -504,6 +539,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 v5 13/15] net/xsc: add basic stats ops

2025-01-06 Thread WanRenyong
Implement xsc ethdev basic statatics ops.

Signed-off-by: WanRenyong 
---
 doc/guides/nics/features/xsc.ini |  1 +
 drivers/net/xsc/xsc_ethdev.c | 75 
 2 files changed, 76 insertions(+)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index 772c6418c4..eb88517104 100644
--- a/doc/guides/nics/features/xsc.ini
+++ b/doc/guides/nics/features/xsc.ini
@@ -11,6 +11,7 @@ L3 checksum offload  = Y
 L4 checksum offload  = Y
 Inner L3 checksum= Y
 Inner L4 checksum= Y
+Basic stats  = 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 9cfb07b023..000e27222d 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -444,6 +444,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)
 {
@@ -475,6 +548,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


Re: [PATCH v4 01/15] net/xsc: add xsc PMD framework

2025-01-05 Thread WanRenyong
On 2025/1/4 3:00, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:06 +0800
> "WanRenyong"  wrote:
>
>> +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.
> What kernel components does this driver expect? Are they all available in 
> current kernels?
Currently this driver expects only the vfio-pci kernel module which is 
recommended by DPDK .

-- 
Thanks,
WanRenyong


Re: [PATCH v4 04/15] net/xsc: add xsc dev ops to support VFIO driver

2025-01-05 Thread WanRenyong
On 2025/1/4 3:02, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:13 +0800
> "WanRenyong"  wrote:
>
>> +static int
>> +xsc_vfio_destroy_qp(void *qp)
>> +{
>> +int ret;
>> +int in_len, out_len, cmd_len;
>> +struct xsc_cmd_destroy_qp_mbox_in *in;
>> +struct xsc_cmd_destroy_qp_mbox_out *out;
>> +struct xsc_vfio_qp *data = (struct xsc_vfio_qp *)qp;
>> +
>> +in_len = sizeof(struct xsc_cmd_destroy_qp_mbox_in);
>> +out_len = sizeof(struct xsc_cmd_destroy_qp_mbox_out);
>> +cmd_len = RTE_MAX(in_len, out_len);
>> +
>> +in = malloc(cmd_len);
>> +if (in == NULL) {
>> +rte_errno = ENOMEM;
>> +PMD_DRV_LOG(ERR, "Failed to alloc qp destroy cmd memory");
>> +return -rte_errno;
>> +}
>> +memset(in, 0, cmd_len);
> If this data structure needs to be shared between primary and secondary 
> process,
> then it needs to be allocated with rte_malloc(). If it does not need to be
> shared, then it can come from heap with malloc().
no, this data structure is not shared between primary and secondary process.
it is a temporary memory to initial mailbox data structure.

-- 
Thanks,
WanRenyong


Re: [PATCH v4 04/15] net/xsc: add xsc dev ops to support VFIO driver

2025-01-05 Thread WanRenyong
On 2025/1/4 3:04, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:13 +0800
> "WanRenyong"  wrote:
>
>> +static int
>> +xsc_vfio_set_mtu(struct xsc_dev *xdev, uint16_t mtu)
>> +{
>> +struct xsc_cmd_set_mtu_mbox_in in;
>> +struct xsc_cmd_set_mtu_mbox_out out;
>> +int ret;
>> +
>> +memset(&in, 0, sizeof(in));
>> +memset(&out, 0, sizeof(out));
> Optionally, you can initalize on stack variables with:
>   struct xsc_cmd_set_mtu_mbox_in in = { };
>
> Either way is ok, it is up to you.
Got it.

-- 
Thanks,
WanRenyong


Re: [PATCH v4 04/15] net/xsc: add xsc dev ops to support VFIO driver

2025-01-05 Thread WanRenyong
On 2025/1/4 3:06, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:13 +0800
> "WanRenyong"  wrote:
>
>> +static int
>> +xsc_vfio_get_mac(struct xsc_dev *xdev, uint8_t *mac)
>> +{
>> +struct xsc_cmd_query_eth_mac_mbox_in in;
>> +struct xsc_cmd_query_eth_mac_mbox_out out;
>> +int ret;
>> +
>> +memset(&in, 0, sizeof(in));
>> +memset(&out, 0, sizeof(out));
>> +in.hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_QUERY_ETH_MAC);
>> +ret = xsc_vfio_mbox_exec(xdev, &in, sizeof(in), &out, sizeof(out));
>> +if (ret != 0 || out.hdr.status != 0) {
>> +PMD_DRV_LOG(ERR, "Failed to get mtu, port=%d, err=%d, 
>> out.status=%u",
>> +xdev->port_id, ret, out.hdr.status);
>> +rte_errno = ENOEXEC;
>> +return -rte_errno;
>> +}
>> +
>> +memcpy(mac, out.mac, 6);
> Prefer to use RTE_ETHER_ADDR_LEN rather than 6.
> Or use rte_ether_addr_copy
will fix it in the next version.

-- 
Thanks,
WanRenyong


Re: [PATCH v4 07/15] net/xsc: add ethdev configure and RSS ops

2025-01-05 Thread WanRenyong
On 2025/1/4 3:14, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:19 +0800
> "WanRenyong"  wrote:
>
>> +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) {
>> +rte_errno = EINVAL;
>> +return -rte_errno;
>> +}
> The parameter rss_conf is already checked for null in 
> rte_eth_dev_rss_hash_conf_get().
will remove rss_conf check in the next version.
>
>> +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;
>> +
>> +if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN || rss_conf->rss_key 
>> == NULL) {
>> +PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
>> +rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
>> +return -EINVAL;
>> +}
> Key length is already validated against value returned from 
> dev_info.hash_key_size before
> this is called by rte_eth_dev_rss_hash_update().
will remove the key length validation in the next version.
>> +static int
>> +xsc_ethdev_configure(struct rte_eth_dev *dev)
>> +{
>> +struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
>> +struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
>> +int ret;
>> +struct rte_eth_rss_conf *rss_conf;
>> +
>> +priv->num_sq = dev->data->nb_tx_queues;
>> +priv->num_rq = dev->data->nb_rx_queues;
>> +
>> +if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
>> +dev->data->dev_conf.rxmode.offloads |= 
>> RTE_ETH_RX_OFFLOAD_RSS_HASH;
>> +
>> +if (priv->rss_conf.rss_key == NULL) {
>> +priv->rss_conf.rss_key = rte_zmalloc(NULL, XSC_RSS_HASH_KEY_LEN,
>> + RTE_CACHE_LINE_SIZE);
>> +if (priv->rss_conf.rss_key == NULL) {
>> +PMD_DRV_LOG(ERR, "Failed to alloc rss key");
>> +rte_errno = ENOMEM;
>> +ret = -rte_errno;
>> +goto error;
>> +}
>> +priv->rss_conf.rss_key_len = XSC_RSS_HASH_KEY_LEN;
>> +}
>> +
>> +if (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key != NULL) {
>> +rss_conf = &dev->data->dev_conf.rx_adv_conf.rss_conf;
>> +ret = xsc_ethdev_rss_hash_update(dev, rss_conf);
>> +if (ret != 0) {
>> +PMD_DRV_LOG(ERR, "Xsc pmd set rss key error!");
>> +rte_errno = -ENOEXEC;
>> +goto error;
>> +}
>> +}
>> +
>> +if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
>> +PMD_DRV_LOG(ERR, "Xsc pmd do not support vlan filter now!");
>> +rte_errno = EINVAL;
>> +goto error;
>> +}
>> +
>> +if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
>> +PMD_DRV_LOG(ERR, "Xsc pmd do not support vlan strip now!");
>> +rte_errno = EINVAL;
>> +goto error;
>> +}
> These offload flags are already validated against rx_offload_capa by 
> rte_eth_dev_configure().
will remove these offload flags validation in the next version.
>
>


-- 
Thanks,
WanRenyong


Re: [PATCH v4 14/15] net/xsc: add ethdev infos get

2025-01-05 Thread WanRenyong
On 2025/1/4 3:22, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:35 +0800
> "WanRenyong"  wrote:
>
>> +
>> +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;
>> +}
>> +
> Note: that driver probably won't be at all functional without info_get
> but as long as each patch builds, it doesn't matter to me what order the
> patchset is in. Too hard to get a working driver at each step.
Agree with you.  When I made the patches, I had refered the the 
suggestion of Adding a new driver in DPDK Contributor's guidelines, the 
device info is recommanded to be placed later position.
Altering the orde of the patchs is a bit of a hassle, so if it's not 
unacceptable, I am going to leave it as is.

-- 
Thanks,
WanRenyong


Re: [PATCH v4 09/15] net/xsc: add ethdev start

2025-01-05 Thread WanRenyong
On 2025/1/4 3:17, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:23 +0800
> "WanRenyong"  wrote:
>
>> +static int
>> +xsc_ethdev_start(struct rte_eth_dev *dev)
>> +{
>> +int ret;
>> +struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
>> +
>> +ret = xsc_txq_start(priv);
>> +if (ret) {
>> +PMD_DRV_LOG(ERR, "Port %u txq start failed: %s",
>> +dev->data->port_id, strerror(rte_errno));
>> +goto error;
>> +}
>> +
>> +ret = xsc_rxq_start(priv);
>> +if (ret) {
>> +PMD_DRV_LOG(ERR, "Port %u Rx queue start failed: %s",
>> +dev->data->port_id, strerror(rte_errno));
>> +goto error;
>> +}
>> +
>> +dev->data->dev_started = 1;
>> +
>> +rte_wmb();
> In general, it is preferred that DPDK drivers use rte_atomic to get
> finer grain control over shared variables. Rather than using volatile
> and barriers.  This is not an absolute requirement, but something
> that is preferred and improves performance on weakly ordered platforms.
Understood, maybe rte_wmb is not neccessary here, will remove it in the 
next version.

-- 
Thanks,
WanRenyong


Re: [PATCH v4 02/15] net/xsc: add xsc device initialization

2025-01-05 Thread WanRenyong
On 2025/1/4 2:58, Stephen Hemminger wrote:
> On Fri, 03 Jan 2025 23:04:08 +0800
> "WanRenyong"  wrote:
>
>> +struct xsc_hwinfo {
>> +uint8_t valid; /* 1: current phy info is valid, 0 : invalid */
>> +uint32_t pcie_no; /* pcie number , 0 or 1 */
>> +uint32_t func_id; /* pf glb func id */
>> +uint32_t pcie_host; /* host pcie number */
>> +uint32_t mac_phy_port; /* mac port */
>> +uint32_t funcid_to_logic_port_off; /* port func id offset */
>> +uint16_t lag_id;
>> +uint16_t raw_qp_id_base;
>> +uint16_t raw_rss_qp_id_base;
>> +uint16_t pf0_vf_funcid_base;
>> +uint16_t pf0_vf_funcid_top;
>> +uint16_t pf1_vf_funcid_base;
>> +uint16_t pf1_vf_funcid_top;
>> +uint16_t pcie0_pf_funcid_base;
>> +uint16_t pcie0_pf_funcid_top;
>> +uint16_t pcie1_pf_funcid_base;
>> +uint16_t pcie1_pf_funcid_top;
>> +uint16_t lag_port_start;
>> +uint16_t raw_tpe_qp_num;
>> +int send_seg_num;
>> +int recv_seg_num;
>> +uint8_t on_chip_tbl_vld;
>> +uint8_t dma_rw_tbl_vld;
>> +uint8_t pct_compress_vld;
>> +uint32_t chip_version;
>> +uint32_t hca_core_clock;
>> +uint8_t mac_bit;
>> +uint8_t esw_mode;
>> +};
> Can you rearrange elements in this structure so there are less holes?
> Or is it shared with the hardware.
OK, I will try to rearrange the elemments in the next version.
It 's not shared with hardware, it is just used to store hardward infos.
>
> Unless you need negative value as a sentinel, avoid use of int where unsigned 
> could be used for
> seg_num.
Got it, will fix it in the next version.

unsigned

-- 
Thanks,
WanRenyong


Re: [PATCH 00/19] XSC PMD for Yunsilicon NICs

2025-01-05 Thread WanRenyong
On 2025/1/5 3:12, Stephen Hemminger wrote:
> On Fri,  6 Sep 2024 20:13:46 +0800
> "WanRenyong"  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
>>
>> 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
>>
>>
>> -
>>
>> WanRenyong (19):
>>net/xsc: add doc and minimum build framework
>>net/xsc: add log macro
>>net/xsc: add PCI device probe and remove
>>net/xsc: add xsc device init and uninit
>>net/xsc: add ioctl command interface
>>net/xsc: initialize hardware information
>>net/xsc: add representor ports probe
>>net/xsc: create eth devices for representor ports
>>net/xsc: initial representor eth device
>>net/xsc: add ethdev configure and rxtx queue setup ops
>>net/xsc: add mailbox and structure
>>net/xsc: add ethdev RSS hash ops
>>net/xsc: add ethdev start and stop ops
>>net/xsc: add ethdev Rx burst
>>net/xsc: add ethdev Tx burst
>>net/xsc: configure xsc device hardware table
>>net/xsc: add dev link and MTU ops
>>net/xsc: add dev infos get
>>net/xsc: add dev basic stats ops
>>
>>   .mailmap |4 +
>>   MAINTAINERS  |9 +
>>   doc/guides/nics/features/xsc.ini |   18 +
>>   doc/guides/nics/index.rst|1 +
>>   doc/guides/nics/xsc.rst  |   31 +
>>   drivers/net/meson.build  |1 +
>>   drivers/net/xsc/meson.build  |   36 +
>>   drivers/net/xsc/xsc_ctrl.c   |   64 ++
>>   drivers/net/xsc/xsc_ctrl.h   |  314 +++
>>   drivers/net/xsc/xsc_defs.h   |   61 ++
>>   drivers/net/xsc/xsc_dev.c|  326 +++
>>   drivers/net/xsc/xsc_dev.h|   99 +++
>>   drivers/net/xsc/xsc_ethdev.c | 1434 ++
>>   drivers/net/xsc/xsc_ethdev.h |   81 ++
>>   drivers/net/xsc/xsc_flow.c   |  167 
>>   drivers/net/xsc/xsc_flow.h   |   67 ++
>>   drivers/net/xsc/xsc_log.h|   44 +
>>   drivers/net/xsc/xsc_rxtx.c   |  445 +
>>   drivers/net/xsc/xsc_rxtx.h   |  214 +
>>   drivers/net/xsc/xsc_utils.c  |  346 +++
>>   drivers/net/xsc/xsc_utils.h  |   27 +
>>   21 files changed, 3789 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_ctrl.c
>>   create mode 100644 drivers/net/xsc/xsc_ctrl.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_flow.c
>>   create mode 100644 drivers/net/xsc/xsc_flow.h
>>   create mode 100644 drivers/net/xsc/xsc_log.h
>>   create mode 100644 drivers/net/xsc/xsc_rxtx.c
>>   create mode 100644 drivers/net/xsc/xsc_rxtx.h
>>   create mode 100644 drivers/net/xsc/xsc_utils.c
>>   create mode 100644 drivers/net/xsc/xsc_utils.h
>>
> Please fix the build error:
> drivers/libtmp_rte_net_xsc.a.p/net_xsc_xsc_vfio.c.o -c 
> ../drivers/net/xsc/xsc_vfio.c
> ../drivers/net/xsc/xsc_vfio.c:482:26: error: cast from 'volatile struct 
> xsc_cqe (*)[]' to 'void *' drops volatile qualifier [-Werror,-Wcast-qual]
>482 | cq_info->cqes = (void *)cqes;
>| ^
>
> Probably best not to mark that arg as volatile.
> Do not try and solve the problem by disabling the warning.
>
>
> And address the review feedback and resubmit when ready.

Thanks for review. We will fix it and resubmit next version soon.

-- 
Thanks,
WanRenyong


Re: [PATCH v7 00/15] XSC PMD for Yunsilicon NICs

2025-01-29 Thread WanRenyong
On 2025/1/29 4:01, 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 mode 1

  1   2   >