[PATCH v2 2/3] net/macb: add NEON vectorized Rx/Tx

2024-11-05 Thread liwencheng
To optimize Rx/Tx burst process, add NEON vector instructions
on ARM architecture.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   6 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 673 ++
 drivers/net/macb/meson.build  |   4 +
 3 files changed, 683 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index 8a0ff26..70c1b42 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1355,6 +1355,11 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+/* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
+ * RTE_ARCH_LOONGARCH is set.
+ */
+#if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
+   defined(RTE_ARCH_LOONGARCH) || defined(RTE_ARCH_X86)
 uint16_t
 eth_macb_recv_pkts_vec(void __rte_unused *rx_queue,
   struct rte_mbuf __rte_unused **rx_pkts,
@@ -1378,4 +1383,5 @@ eth_macb_xmit_pkts_vec(void __rte_unused *tx_queue,
 {
return 0;
 }
+#endif
 
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..62978de
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,673 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer;
+   uint8x8_t rearm_data_vec;
+
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set(&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+
+   uint32x2_t zero = vdup_n_u32(0);
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   if (rxq->rxrearm_nb + (unsigned int)MACB_RXQ_REARM_THRESH >=
+   rxq->nb_rx_desc) {
+   MACB_LOG(ERR, "allocate mbuf fail!\n");
+   for (i = 0; i < MACB_DESCS_PER_LOOP; i++) {
+   rxe[i].mbuf = &rxq->fake_mbuf;
+   vst1_u32((uint32_t 
*)&desc[MACB_DESC_ADDR_INTERVAL * i], zero);
+   }
+   }
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_de

[PATCH v2 3/3] usertools/dpdk-devbind: add platform device bind/unbind

2024-11-05 Thread liwencheng
This patch adds functions for binding and unbinding platform devices,
such as bind_platform_one and unbind_platform_one.

Signed-off-by: liwencheng 
---
 usertools/dpdk-devbind.py | 101 +-
 1 file changed, 99 insertions(+), 2 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 80c35f9..4b65b55 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -147,10 +147,32 @@ def module_is_loaded(module):
 return module in loaded_modules
 
 
+def get_platform_devices():
+global platform_devices
+
+platform_device_path = "/sys/bus/platform/devices/"
+platform_devices = os.listdir(platform_device_path)
+
+
+def devices_are_platform(devs):
+all_devices_are_platform = True
+
+get_platform_devices()
+for d in devs:
+if d not in platform_devices:
+all_devices_are_platform = False
+break
+
+return all_devices_are_platform
+
+
 def check_modules():
 '''Checks that igb_uio is loaded'''
 global dpdk_drivers
 
+if devices_are_platform(args):
+return
+
 # list of supported modules
 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
 
@@ -321,11 +343,38 @@ def dev_id_from_dev_name(dev_name):
 for d in devices.keys():
 if dev_name in devices[d]["Interface"].split(","):
 return devices[d]["Slot"]
+
+# Check if it is a platform device
+if dev_name in platform_devices:
+return dev_name
+
 # if nothing else matches - error
 raise ValueError("Unknown device: %s. "
  "Please specify device in \"bus:slot.func\" format" % 
dev_name)
 
 
+def unbind_platform_one(dev_name):
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+
+if exists(filename):
+try:
+f = open(os.path.join(filename, "unbind"), "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, os.path.join(filename, "unbind"), err))
+f.write(dev_name)
+f.close()
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, filename, err))
+f.write("")
+f.close()
+print("Successfully unbind platform device %s" % dev_name)
+
+
 def unbind_one(dev_id, force):
 '''Unbind the device identified by "dev_id" from its current driver'''
 dev = devices[dev_id]
@@ -351,6 +400,48 @@ def unbind_one(dev_id, force):
 f.close()
 
 
+def bind_platform_one(dev_name, driver):
+filename = "/sys/bus/platform/drivers/%s" % driver
+
+if not exists(filename):
+print("The driver %s is not loaded" % driver)
+return
+# unbind any existing drivers we don't want
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+if exists(filename):
+unbind_platform_one(dev_name)
+# driver_override can be used to specify the driver
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+if exists(filename):
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_name, filename, err))
+try:
+f.write(driver)
+f.close()
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
+ % (dev_name, filename, err))
+# do the bind by writing to /sys
+filename = "/sys/bus/platform/drivers/%s/bind" % driver
+try:
+f = open(filename, "w")
+except OSError as err:
+print("Error: bind failed for %s - Cannot open %s: %s"
+  % (dev_name, filename, err), file=sys.stderr)
+return
+try:
+f.write(dev_name)
+f.close()
+except OSError as err:
+print("Error: bind failed for %s - Cannot bind to driver %s: %s"
+  % (dev_name, driver, err), file=sys.stderr)
+return
+print("Successfully bind platform device %s to driver %s" % (dev_name, 
driver))
+
+
 def bind_one(dev_id, driver, force):
 '''Bind the device given by "dev_id" to the driver "driver". If the device
 is already bound to a different driver, it will be unbound first'''
@@ -475,7 +566,10 

[PATCH v2 2/3] net/macb: add NEON vectorized Rx/Tx

2024-11-05 Thread liwencheng
To optimize Rx/Tx burst process,
add NEON vector instructions on arm architecture.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   6 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 673 ++
 drivers/net/macb/meson.build  |   4 +
 3 files changed, 683 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index 81d9529..5d1aea9 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1355,6 +1355,11 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+/* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
+ * RTE_ARCH_LOONGARCH is set.
+ */
+#if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
+   defined(RTE_ARCH_LOONGARCH) || defined(RTE_ARCH_X86)
 uint16_t
 eth_macb_recv_pkts_vec(void __rte_unused *rx_queue,
   struct rte_mbuf __rte_unused **rx_pkts,
@@ -1378,3 +1383,4 @@ eth_macb_xmit_pkts_vec(void __rte_unused *tx_queue,
 {
return 0;
 }
+#endif
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..62978de
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,673 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer;
+   uint8x8_t rearm_data_vec;
+
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set(&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+
+   uint32x2_t zero = vdup_n_u32(0);
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   if (rxq->rxrearm_nb + (unsigned int)MACB_RXQ_REARM_THRESH >=
+   rxq->nb_rx_desc) {
+   MACB_LOG(ERR, "allocate mbuf fail!\n");
+   for (i = 0; i < MACB_DESCS_PER_LOOP; i++) {
+   rxe[i].mbuf = &rxq->fake_mbuf;
+   vst1_u32((uint32_t 
*)&desc[MACB_DESC_ADDR_INTERVAL * i], zero);
+   }
+   }
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_de

[PATCH v2 3/3] usertools/dpdk-devbind: add bind/unbind for platform device

2024-11-05 Thread liwencheng
This patch mainly adds functions for bind and unbind platform devices,
such as bind_platform_one and unbind_platform_one.

Signed-off-by: liwencheng 
---
 usertools/dpdk-devbind.py | 101 +-
 1 file changed, 99 insertions(+), 2 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 80c35f9..4b65b55 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -147,10 +147,32 @@ def module_is_loaded(module):
 return module in loaded_modules
 
 
+def get_platform_devices():
+global platform_devices
+
+platform_device_path = "/sys/bus/platform/devices/"
+platform_devices = os.listdir(platform_device_path)
+
+
+def devices_are_platform(devs):
+all_devices_are_platform = True
+
+get_platform_devices()
+for d in devs:
+if d not in platform_devices:
+all_devices_are_platform = False
+break
+
+return all_devices_are_platform
+
+
 def check_modules():
 '''Checks that igb_uio is loaded'''
 global dpdk_drivers
 
+if devices_are_platform(args):
+return
+
 # list of supported modules
 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
 
@@ -321,11 +343,38 @@ def dev_id_from_dev_name(dev_name):
 for d in devices.keys():
 if dev_name in devices[d]["Interface"].split(","):
 return devices[d]["Slot"]
+
+# Check if it is a platform device
+if dev_name in platform_devices:
+return dev_name
+
 # if nothing else matches - error
 raise ValueError("Unknown device: %s. "
  "Please specify device in \"bus:slot.func\" format" % 
dev_name)
 
 
+def unbind_platform_one(dev_name):
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+
+if exists(filename):
+try:
+f = open(os.path.join(filename, "unbind"), "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, os.path.join(filename, "unbind"), err))
+f.write(dev_name)
+f.close()
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, filename, err))
+f.write("")
+f.close()
+print("Successfully unbind platform device %s" % dev_name)
+
+
 def unbind_one(dev_id, force):
 '''Unbind the device identified by "dev_id" from its current driver'''
 dev = devices[dev_id]
@@ -351,6 +400,48 @@ def unbind_one(dev_id, force):
 f.close()
 
 
+def bind_platform_one(dev_name, driver):
+filename = "/sys/bus/platform/drivers/%s" % driver
+
+if not exists(filename):
+print("The driver %s is not loaded" % driver)
+return
+# unbind any existing drivers we don't want
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+if exists(filename):
+unbind_platform_one(dev_name)
+# driver_override can be used to specify the driver
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+if exists(filename):
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_name, filename, err))
+try:
+f.write(driver)
+f.close()
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
+ % (dev_name, filename, err))
+# do the bind by writing to /sys
+filename = "/sys/bus/platform/drivers/%s/bind" % driver
+try:
+f = open(filename, "w")
+except OSError as err:
+print("Error: bind failed for %s - Cannot open %s: %s"
+  % (dev_name, filename, err), file=sys.stderr)
+return
+try:
+f.write(dev_name)
+f.close()
+except OSError as err:
+print("Error: bind failed for %s - Cannot bind to driver %s: %s"
+  % (dev_name, driver, err), file=sys.stderr)
+return
+print("Successfully bind platform device %s to driver %s" % (dev_name, 
driver))
+
+
 def bind_one(dev_id, driver, force):
 '''Bind the device given by "dev_id" to the driver "driver". If the device
 is already bound to a different driver, it will be unbound first'''
@@ -475,7 +566,10 

[PATCH v2 2/3] net/macb: add NEON vectorized Rx/Tx

2024-11-10 Thread liwencheng
To optimize Rx/Tx burst process,
add NEON vector instructions on arm architecture.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   2 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 672 ++
 drivers/net/macb/meson.build  |   4 +
 3 files changed, 678 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index 7104ec5..fa36a1e 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1354,6 +1354,7 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+#if !defined(RTE_ARCH_ARM64)
 uint16_t
 eth_macb_recv_pkts_vec(void __rte_unused *rx_queue,
   struct rte_mbuf __rte_unused **rx_pkts,
@@ -1377,3 +1378,4 @@ eth_macb_xmit_pkts_vec(void __rte_unused *tx_queue,
 {
return 0;
 }
+#endif
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..7d064b7
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,672 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer = vdup_n_u64(0);
+   uint8x8_t rearm_data_vec;
+
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set(&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+
+   uint32x2_t zero = vdup_n_u32(0);
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   if (rxq->rxrearm_nb + (unsigned int)MACB_RXQ_REARM_THRESH >=
+   rxq->nb_rx_desc) {
+   MACB_LOG(ERR, "allocate mbuf fail!\n");
+   for (i = 0; i < MACB_DESCS_PER_LOOP; i++) {
+   rxe[i].mbuf = &rxq->fake_mbuf;
+   vst1_u32((uint32_t 
*)&desc[MACB_DESC_ADDR_INTERVAL * i], zero);
+   }
+   }
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
+   if (unlikely(entry == rxq->nb_rx_desc - 1))
+   dma_addr |= MACB_BIT(RX_WRAP);
+   desc->ctrl = 0;
+   

[PATCH v2 3/3] usertools/dpdk-devbind: add bind/unbind for platform device

2024-11-10 Thread liwencheng
This patch mainly adds functions for bind and unbind platform devices,
such as bind_platform_one and unbind_platform_one.

Signed-off-by: liwencheng 
Acked-by: Stephen Hemminger 
---
 usertools/dpdk-devbind.py | 101 +-
 1 file changed, 99 insertions(+), 2 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 80c35f9..4b65b55 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -147,10 +147,32 @@ def module_is_loaded(module):
 return module in loaded_modules
 
 
+def get_platform_devices():
+global platform_devices
+
+platform_device_path = "/sys/bus/platform/devices/"
+platform_devices = os.listdir(platform_device_path)
+
+
+def devices_are_platform(devs):
+all_devices_are_platform = True
+
+get_platform_devices()
+for d in devs:
+if d not in platform_devices:
+all_devices_are_platform = False
+break
+
+return all_devices_are_platform
+
+
 def check_modules():
 '''Checks that igb_uio is loaded'''
 global dpdk_drivers
 
+if devices_are_platform(args):
+return
+
 # list of supported modules
 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
 
@@ -321,11 +343,38 @@ def dev_id_from_dev_name(dev_name):
 for d in devices.keys():
 if dev_name in devices[d]["Interface"].split(","):
 return devices[d]["Slot"]
+
+# Check if it is a platform device
+if dev_name in platform_devices:
+return dev_name
+
 # if nothing else matches - error
 raise ValueError("Unknown device: %s. "
  "Please specify device in \"bus:slot.func\" format" % 
dev_name)
 
 
+def unbind_platform_one(dev_name):
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+
+if exists(filename):
+try:
+f = open(os.path.join(filename, "unbind"), "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, os.path.join(filename, "unbind"), err))
+f.write(dev_name)
+f.close()
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, filename, err))
+f.write("")
+f.close()
+print("Successfully unbind platform device %s" % dev_name)
+
+
 def unbind_one(dev_id, force):
 '''Unbind the device identified by "dev_id" from its current driver'''
 dev = devices[dev_id]
@@ -351,6 +400,48 @@ def unbind_one(dev_id, force):
 f.close()
 
 
+def bind_platform_one(dev_name, driver):
+filename = "/sys/bus/platform/drivers/%s" % driver
+
+if not exists(filename):
+print("The driver %s is not loaded" % driver)
+return
+# unbind any existing drivers we don't want
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+if exists(filename):
+unbind_platform_one(dev_name)
+# driver_override can be used to specify the driver
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+if exists(filename):
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_name, filename, err))
+try:
+f.write(driver)
+f.close()
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
+ % (dev_name, filename, err))
+# do the bind by writing to /sys
+filename = "/sys/bus/platform/drivers/%s/bind" % driver
+try:
+f = open(filename, "w")
+except OSError as err:
+print("Error: bind failed for %s - Cannot open %s: %s"
+  % (dev_name, filename, err), file=sys.stderr)
+return
+try:
+f.write(dev_name)
+f.close()
+except OSError as err:
+print("Error: bind failed for %s - Cannot bind to driver %s: %s"
+  % (dev_name, driver, err), file=sys.stderr)
+return
+print("Successfully bind platform device %s to driver %s" % (dev_name, 
driver))
+
+
 def bind_one(dev_id, driver, force):
 '''Bind the device given by "dev_id" to the driver "driver". If the device
 is already bound to a different driver, it will be unbound first'''

[PATCH v1 2/2] /usertools/dpdk-devbind:add the binding and unbinding of platform device

2024-11-01 Thread liwencheng
This patch mainly adds functions for binding and unbinding platform devices, 
such as bind_platform_one and unbind_platform_one.

Signed-off-by: liwencheng 
---
 usertools/dpdk-devbind.py | 101 +-
 1 file changed, 99 insertions(+), 2 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 80c35f9..4b65b55 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -147,10 +147,32 @@ def module_is_loaded(module):
 return module in loaded_modules
 
 
+def get_platform_devices():
+global platform_devices
+
+platform_device_path = "/sys/bus/platform/devices/"
+platform_devices = os.listdir(platform_device_path)
+
+
+def devices_are_platform(devs):
+all_devices_are_platform = True
+
+get_platform_devices()
+for d in devs:
+if d not in platform_devices:
+all_devices_are_platform = False
+break
+
+return all_devices_are_platform
+
+
 def check_modules():
 '''Checks that igb_uio is loaded'''
 global dpdk_drivers
 
+if devices_are_platform(args):
+return
+
 # list of supported modules
 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
 
@@ -321,11 +343,38 @@ def dev_id_from_dev_name(dev_name):
 for d in devices.keys():
 if dev_name in devices[d]["Interface"].split(","):
 return devices[d]["Slot"]
+
+# Check if it is a platform device
+if dev_name in platform_devices:
+return dev_name
+
 # if nothing else matches - error
 raise ValueError("Unknown device: %s. "
  "Please specify device in \"bus:slot.func\" format" % 
dev_name)
 
 
+def unbind_platform_one(dev_name):
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+
+if exists(filename):
+try:
+f = open(os.path.join(filename, "unbind"), "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, os.path.join(filename, "unbind"), err))
+f.write(dev_name)
+f.close()
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, filename, err))
+f.write("")
+f.close()
+print("Successfully unbind platform device %s" % dev_name)
+
+
 def unbind_one(dev_id, force):
 '''Unbind the device identified by "dev_id" from its current driver'''
 dev = devices[dev_id]
@@ -351,6 +400,48 @@ def unbind_one(dev_id, force):
 f.close()
 
 
+def bind_platform_one(dev_name, driver):
+filename = "/sys/bus/platform/drivers/%s" % driver
+
+if not exists(filename):
+print("The driver %s is not loaded" % driver)
+return
+# unbind any existing drivers we don't want
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+if exists(filename):
+unbind_platform_one(dev_name)
+# driver_override can be used to specify the driver
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+if exists(filename):
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_name, filename, err))
+try:
+f.write(driver)
+f.close()
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
+ % (dev_name, filename, err))
+# do the bind by writing to /sys
+filename = "/sys/bus/platform/drivers/%s/bind" % driver
+try:
+f = open(filename, "w")
+except OSError as err:
+print("Error: bind failed for %s - Cannot open %s: %s"
+  % (dev_name, filename, err), file=sys.stderr)
+return
+try:
+f.write(dev_name)
+f.close()
+except OSError as err:
+print("Error: bind failed for %s - Cannot bind to driver %s: %s"
+  % (dev_name, driver, err), file=sys.stderr)
+return
+print("Successfully bind platform device %s to driver %s" % (dev_name, 
driver))
+
+
 def bind_one(dev_id, driver, force):
 '''Bind the device given by "dev_id" to the driver "driver". If the device
 is already bound to a different driver, it will be unbound first'''
@@ -475,7 +566,10 

[PATCH v4 3/4] net/macb: add NEON vectorized Rx/Tx

2025-04-05 Thread liwencheng
To optimize Rx/Tx burst process,
add NEON vector instructions on arm architecture.

v4:
* Support hardware Rx checksum offload.
* Fixed some code style issues.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   3 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 674 ++
 drivers/net/macb/meson.build  |   4 +
 3 files changed, 681 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index ac8247d..c08e877 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1366,6 +1366,8 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+/* Stubs needed for linkage when RTE_ARCH_ARM64 is not set. */
+#if !defined(RTE_ARCH_ARM64)
 uint16_t
 eth_macb_recv_pkts_vec(void __rte_unused *rx_queue,
   struct rte_mbuf __rte_unused **rx_pkts,
@@ -1389,3 +1391,4 @@ eth_macb_xmit_pkts_vec(void __rte_unused *tx_queue,
 {
return 0;
 }
+#endif
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..c7e3405
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,674 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   volatile struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer;
+   uint8x8_t rearm_data_vec;
+
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set((struct rte_mbuf *)&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   MACB_LOG(ERR, "allocate mbuf fail!");
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
+   if (unlikely(entry == rxq->nb_rx_desc - 1))
+   dma_addr |= MACB_BIT(RX_WRAP);
+   desc->ctrl = 0;
+   /* Setting addr clears RX_USED and allows reception,
+* make sure ctrl is cleared first to avoid a race.
+*/
+   rte_wmb();
+   macb_set_addr(bp, desc, dma_addr);
+   }
+   if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc))
+   rxq->rxrearm_st

[PATCH v5 1/4] usertools/dpdk-devbind: add platform devices support

2025-04-06 Thread liwencheng
Modify dpdk-devbind to support bind and unbind platform devices,
such as bind_platform_one and unbind_platform_one.

v5:
* Add name and email to .mailmap.

Signed-off-by: liwencheng 
---
 .mailmap  |   1 +
 usertools/dpdk-devbind.py | 131 --
 2 files changed, 115 insertions(+), 17 deletions(-)

diff --git a/.mailmap b/.mailmap
index d8439b7..001d7b2 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1675,6 +1675,7 @@ Wen Chiu 
 Wen-Chi Yang 
 Wenfeng Liu 
 Wenjie Li 
+Wencheng Li 
 Wenjie Sun 
 Wenjing Qiao 
 Wenjun Wu 
diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 06ae25a..600c4ba 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -65,7 +65,7 @@
 intel_idxd_spr = {'Class': '08', 'Vendor': '8086', 'Device': '0b25',
   'SVendor': None, 'SDevice': None}
 intel_idxd_gnrd = {'Class': '08', 'Vendor': '8086', 'Device': '11fb',
-  'SVendor': None, 'SDevice': None}
+   'SVendor': None, 'SDevice': None}
 intel_idxd_dmr = {'Class': '08', 'Vendor': '8086', 'Device': '1212',
   'SVendor': None, 'SDevice': None}
 intel_ntb_skx = {'Class': '06', 'Vendor': '8086', 'Device': '201c',
@@ -156,10 +156,32 @@ def module_is_loaded(module):
 return module in loaded_modules
 
 
+def get_platform_devices():
+global platform_devices
+
+platform_device_path = "/sys/bus/platform/devices/"
+platform_devices = os.listdir(platform_device_path)
+
+
+def devices_are_platform(devs):
+all_devices_are_platform = True
+
+get_platform_devices()
+for d in devs:
+if d not in platform_devices:
+all_devices_are_platform = False
+break
+
+return all_devices_are_platform
+
+
 def check_modules():
 '''Checks that igb_uio is loaded'''
 global dpdk_drivers
 
+if devices_are_platform(args):
+return
+
 # list of supported modules
 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
 
@@ -330,11 +352,38 @@ def dev_id_from_dev_name(dev_name):
 for d in devices.keys():
 if dev_name in devices[d]["Interface"].split(","):
 return devices[d]["Slot"]
+
+# Check if it is a platform device
+if dev_name in platform_devices:
+return dev_name
+
 # if nothing else matches - error
 raise ValueError("Unknown device: %s. "
  "Please specify device in \"bus:slot.func\" format" % 
dev_name)
 
 
+def unbind_platform_one(dev_name):
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+
+if exists(filename):
+try:
+f = open(os.path.join(filename, "unbind"), "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, os.path.join(filename, "unbind"), err))
+f.write(dev_name)
+f.close()
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, filename, err))
+f.write("")
+f.close()
+print("Successfully unbind platform device %s" % dev_name)
+
+
 def unbind_one(dev_id, force):
 '''Unbind the device identified by "dev_id" from its current driver'''
 dev = devices[dev_id]
@@ -360,6 +409,48 @@ def unbind_one(dev_id, force):
 f.close()
 
 
+def bind_platform_one(dev_name, driver):
+filename = "/sys/bus/platform/drivers/%s" % driver
+
+if not exists(filename):
+print("The driver %s is not loaded" % driver)
+return
+# unbind any existing drivers we don't want
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+if exists(filename):
+unbind_platform_one(dev_name)
+# driver_override can be used to specify the driver
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+if exists(filename):
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_name, filename, err))
+try:
+f.write(driver)
+ 

[PATCH v5 3/4] net/macb: add NEON vectorized Rx/Tx

2025-04-06 Thread liwencheng
To optimize Rx/Tx burst process,
add NEON vector instructions on arm architecture.

v5:
* Initialize the mbuf_initializer.
* Fixed some code style issues.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   3 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 675 ++
 drivers/net/macb/meson.build  |   1 +
 3 files changed, 679 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index 1473b0d..ab9477d 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1366,6 +1366,8 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+/* Stubs needed for linkage when RTE_ARCH_ARM64 is not set. */
+#if !defined(RTE_ARCH_ARM64)
 uint16_t
 eth_macb_recv_pkts_vec(void *rx_queue __rte_unused,
   struct rte_mbuf **rx_pkts __rte_unused,
@@ -1389,3 +1391,4 @@ eth_macb_xmit_pkts_vec(void *tx_queue __rte_unused,
 {
return 0;
 }
+#endif
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..24e318c
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,675 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   volatile struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer;
+   uint8x8_t rearm_data_vec;
+
+   mbuf_initializer = vdup_n_u64(0);
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set((struct rte_mbuf *)&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   MACB_LOG(ERR, "allocate mbuf fail!");
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
+   if (unlikely(entry == rxq->nb_rx_desc - 1))
+   dma_addr |= MACB_BIT(RX_WRAP);
+   desc->ctrl = 0;
+   /* Setting addr clears RX_USED and allows reception,
+* make sure ctrl is cleared first to avoid a race.
+*/
+   rte_wmb();
+   macb_set_addr(bp, desc, dma_addr);
+   }
+   if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc

[PATCH v5 4/4] net/macb: add necessary docs and update related files

2025-04-06 Thread liwencheng
Added missing documentation in doc/guides/nics,
mailmap entry, and updated MAINTAINERS file.

v5:
* Add driver based on 25.07.

Signed-off-by: liwencheng 
---
 MAINTAINERS|  6 ++
 doc/guides/nics/features/macb.ini  | 27 +++
 doc/guides/nics/index.rst  |  1 +
 doc/guides/nics/macb.rst   | 26 ++
 doc/guides/rel_notes/release_25_07.rst |  4 
 5 files changed, 64 insertions(+)
 create mode 100644 doc/guides/nics/features/macb.ini
 create mode 100644 doc/guides/nics/macb.rst

diff --git a/MAINTAINERS b/MAINTAINERS
index 4b01103..379645d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -920,6 +920,12 @@ F: doc/guides/platform/bluefield.rst
 F: doc/guides/nics/mlx5.rst
 F: doc/guides/nics/features/mlx5.ini
 
+Phytium macb
+M: Wencheng Li 
+F: drivers/net/macb
+F: doc/guides/nics/macb.rst
+F: doc/guides/nics/features/macb.ini
+
 Microsoft mana
 M: Long Li 
 M: Wei Hu 
diff --git a/doc/guides/nics/features/macb.ini 
b/doc/guides/nics/features/macb.ini
new file mode 100644
index 000..cefc282
--- /dev/null
+++ b/doc/guides/nics/features/macb.ini
@@ -0,0 +1,27 @@
+;
+; Supported features of the 'macb' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+
+[Features]
+Speed capabilities   = Y
+Link status  = Y
+Queue start/stop = Y
+MTU update   = Y
+Allmulticast mode= Y
+CRC offload  = Y
+L3 checksum offload  = Y
+L4 checksum offload  = Y
+Scattered Rx = Y
+Rx descriptor status = Y
+Basic stats  = Y
+Linux= Y
+
+[rte_flow items]
+eth  = Y
+ipv4 = Y
+ipv6 = Y
+raw  = Y
+tcp  = Y
+udp  = Y
diff --git a/doc/guides/nics/index.rst b/doc/guides/nics/index.rst
index 10a2eca..8ae1950 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -43,6 +43,7 @@ Network Interface Controller Drivers
 ionic
 ipn3ke
 ixgbe
+macb
 mana
 memif
 mlx4
diff --git a/doc/guides/nics/macb.rst b/doc/guides/nics/macb.rst
new file mode 100644
index 000..5614a63
--- /dev/null
+++ b/doc/guides/nics/macb.rst
@@ -0,0 +1,26 @@
+..  SPDX-License-Identifier: BSD-3-Clause
+Copyright(c) 2022~2023 Phytium Technology Co., Ltd.
+
+MACB Poll Mode Driver
+=
+
+The MACB PMD provides poll mode driver support
+for the Ethernet interface MAC 1/2.5/10 Gbps adapter.
+
+Supported Chipsets and NICs
+---
+
+Phytium Ethernet interface cdns,phytium-gem-1.0
+Phytium Ethernet interface cdns,phytium-gem-2.0
+
+Features
+
+
+Features of the MACB PMD are:
+
+* Speed capabilities
+* Link status
+* Tx Queue start/stop
+* Multiple queues for TX and RX
+* CRC offload
+* Jumbo frames supported
diff --git a/doc/guides/rel_notes/release_25_07.rst 
b/doc/guides/rel_notes/release_25_07.rst
index cd1025a..9298dc1 100644
--- a/doc/guides/rel_notes/release_25_07.rst
+++ b/doc/guides/rel_notes/release_25_07.rst
@@ -55,6 +55,10 @@ New Features
  Also, make sure to start the actual text at the margin.
  ===
 
+* **Added Phytium macb net driver.**
+
+  Added a new network PMD which supports Phytium 1 and 10 Gigabit
+  Ethernet NICs.
 
 Removed Items
 -
-- 
2.7.4



[PATCH v6 0/3] net/macb: updated net macb driver.

2025-04-07 Thread liwencheng
v6:
- Fixed build failures across different OS.

v5:
- Putting __rte_unused after the declaration.
- Correct RX-bytes and TX-bytes statistics.
- Initialize the mbuf_initializer.
- Add driver based on 25.07.
- Fixed some code style issues.

v4:
- Fix tab errors in meson.build file.
- Use RTE_LOG_LINE instead of rte_log.
- Replace %l with %PRI*64.
- Replace rte_smp_[r/w]mb with rte_[r/w]mb.
- Do not use variadic arguments in macros.
- Do not use variable-length array pkts[nb_bufs].
- Use __rte_cache_aligned only for struct or union types alignment.
- Support hardware Rx/Tx checksum offload.
- Fixed some code style issues.
v3:
- Changed functions that always return 0 and whose return value
is unused to void type, improving code simplicity and readability.
- Fixed the implicit conversion issues in the
macb_usxgmii_pcs_check_for_link and
macb_usxgmii_pcs_check_for_link functions.
- Added the missing SPDX license tags.
- Added the missing mailmap entry.
- Updated the MAINTAINERS file to include the missing information.

v2:
- Split the driver into three logically independent patches,
rather than one large patch.
- Added conditional compilation to address the issue of
macb_rxtx_vec_neon.c failing to compile in certain modes.
- Fixed some code style issues.

v1:
- updated net macb driver.

*** BLURB HERE ***

Wencheng Li (3):
  net/macb: add new poll mode driver
  net/macb: add NEON vectorized Rx/Tx
  net/macb: add necessary docs and update related files

 .mailmap   |1 +
 MAINTAINERS|6 +
 doc/guides/nics/features/macb.ini  |   27 +
 doc/guides/nics/index.rst  |1 +
 doc/guides/nics/macb.rst   |   26 +
 doc/guides/rel_notes/release_25_07.rst |4 +
 drivers/net/macb/base/generic_phy.c|  271 +
 drivers/net/macb/base/generic_phy.h|  202 
 drivers/net/macb/base/macb_common.c|  670 
 drivers/net/macb/base/macb_common.h|  253 +
 drivers/net/macb/base/macb_errno.h |   58 +
 drivers/net/macb/base/macb_hw.h| 1138 +++
 drivers/net/macb/base/macb_type.h  |   23 +
 drivers/net/macb/base/macb_uio.c   |  351 ++
 drivers/net/macb/base/macb_uio.h   |   50 +
 drivers/net/macb/base/meson.build  |   25 +
 drivers/net/macb/macb_ethdev.c | 1861 
 drivers/net/macb/macb_ethdev.h |   91 ++
 drivers/net/macb/macb_log.h|   19 +
 drivers/net/macb/macb_rxtx.c   | 1394 
 drivers/net/macb/macb_rxtx.h   |  325 ++
 drivers/net/macb/macb_rxtx_vec_neon.c  |  675 
 drivers/net/macb/meson.build   |   22 +
 drivers/net/meson.build|1 +
 24 files changed, 7494 insertions(+)
 create mode 100644 doc/guides/nics/features/macb.ini
 create mode 100644 doc/guides/nics/macb.rst
 create mode 100644 drivers/net/macb/base/generic_phy.c
 create mode 100644 drivers/net/macb/base/generic_phy.h
 create mode 100644 drivers/net/macb/base/macb_common.c
 create mode 100644 drivers/net/macb/base/macb_common.h
 create mode 100644 drivers/net/macb/base/macb_errno.h
 create mode 100644 drivers/net/macb/base/macb_hw.h
 create mode 100644 drivers/net/macb/base/macb_type.h
 create mode 100644 drivers/net/macb/base/macb_uio.c
 create mode 100644 drivers/net/macb/base/macb_uio.h
 create mode 100644 drivers/net/macb/base/meson.build
 create mode 100644 drivers/net/macb/macb_ethdev.c
 create mode 100644 drivers/net/macb/macb_ethdev.h
 create mode 100644 drivers/net/macb/macb_log.h
 create mode 100644 drivers/net/macb/macb_rxtx.c
 create mode 100644 drivers/net/macb/macb_rxtx.h
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c
 create mode 100644 drivers/net/macb/meson.build

-- 
2.7.4



[PATCH v6 2/3] net/macb: add NEON vectorized Rx/Tx

2025-04-07 Thread liwencheng
To optimize Rx/Tx burst process,
add NEON vector instructions on arm architecture.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   3 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 675 ++
 drivers/net/macb/meson.build  |   4 +
 3 files changed, 682 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index 1473b0d..ab9477d 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1366,6 +1366,8 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+/* Stubs needed for linkage when RTE_ARCH_ARM64 is not set. */
+#if !defined(RTE_ARCH_ARM64)
 uint16_t
 eth_macb_recv_pkts_vec(void *rx_queue __rte_unused,
   struct rte_mbuf **rx_pkts __rte_unused,
@@ -1389,3 +1391,4 @@ eth_macb_xmit_pkts_vec(void *tx_queue __rte_unused,
 {
return 0;
 }
+#endif
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..24e318c
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,675 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   volatile struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer;
+   uint8x8_t rearm_data_vec;
+
+   mbuf_initializer = vdup_n_u64(0);
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set((struct rte_mbuf *)&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   MACB_LOG(ERR, "allocate mbuf fail!");
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
+   if (unlikely(entry == rxq->nb_rx_desc - 1))
+   dma_addr |= MACB_BIT(RX_WRAP);
+   desc->ctrl = 0;
+   /* Setting addr clears RX_USED and allows reception,
+* make sure ctrl is cleared first to avoid a race.
+*/
+   rte_wmb();
+   macb_set_addr(bp, desc, dma_addr);
+   }
+   if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc))
+   rxq->rxrearm_start = 0;
+   rxq->rxrearm_

[PATCH v4 3/4] net/macb: add NEON vectorized Rx/Tx

2025-04-02 Thread liwencheng
To optimize Rx/Tx burst process,
add NEON vector instructions on arm architecture.

v4:
* Support hardware Rx checksum offload.
* Fixed some code style issues.

Signed-off-by: liwencheng 
---
 drivers/net/macb/macb_rxtx.c  |   3 +
 drivers/net/macb/macb_rxtx_vec_neon.c | 674 ++
 drivers/net/macb/meson.build  |   4 +
 3 files changed, 681 insertions(+)
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c

diff --git a/drivers/net/macb/macb_rxtx.c b/drivers/net/macb/macb_rxtx.c
index ac8247d..c08e877 100644
--- a/drivers/net/macb/macb_rxtx.c
+++ b/drivers/net/macb/macb_rxtx.c
@@ -1366,6 +1366,8 @@ int __rte_cold eth_macb_rx_init(struct rte_eth_dev *dev)
return 0;
 }
 
+/* Stubs needed for linkage when RTE_ARCH_ARM64 is not set. */
+#if !defined(RTE_ARCH_ARM64)
 uint16_t
 eth_macb_recv_pkts_vec(void __rte_unused *rx_queue,
   struct rte_mbuf __rte_unused **rx_pkts,
@@ -1389,3 +1391,4 @@ eth_macb_xmit_pkts_vec(void __rte_unused *tx_queue,
 {
return 0;
 }
+#endif
diff --git a/drivers/net/macb/macb_rxtx_vec_neon.c 
b/drivers/net/macb/macb_rxtx_vec_neon.c
new file mode 100644
index 000..c7e3405
--- /dev/null
+++ b/drivers/net/macb/macb_rxtx_vec_neon.c
@@ -0,0 +1,674 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Phytium Technology Co., Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "macb_rxtx.h"
+
+#pragma GCC diagnostic ignored "-Wcast-qual"
+
+#define MACB_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
+
+#define MACB_DESC_EOF_MASK 0x80808080
+
+static inline uint32_t macb_get_packet_type(struct rte_mbuf *rxm)
+{
+   struct rte_ether_hdr *eth_hdr;
+   uint16_t ether_type;
+
+   eth_hdr = rte_pktmbuf_mtod(rxm, struct rte_ether_hdr *);
+   ether_type = eth_hdr->ether_type;
+
+   if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
+   else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
+   return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
+   else
+   return RTE_PTYPE_UNKNOWN;
+}
+
+static inline uint8x8_t macb_mbuf_initializer(struct macb_rx_queue *rxq)
+{
+   volatile struct rte_mbuf mbuf = {.buf_addr = 0}; /* zeroed mbuf */
+   uint64x1_t mbuf_initializer;
+   uint8x8_t rearm_data_vec;
+
+   mbuf.data_off = RTE_PKTMBUF_HEADROOM + MACB_RX_DATA_OFFSET;
+   mbuf.nb_segs = 1;
+   mbuf.port = rxq->port_id;
+   rte_mbuf_refcnt_set((struct rte_mbuf *)&mbuf, 1);
+
+   /* prevent compiler reordering: rearm_data covers previous fields */
+   rte_compiler_barrier();
+   mbuf_initializer =
+   vset_lane_u64(*(uint64_t *)(&mbuf.rearm_data), 
mbuf_initializer, 0);
+   rearm_data_vec = vld1_u8((uint8_t *)&mbuf_initializer);
+   return rearm_data_vec;
+}
+
+static inline void macb_rxq_rearm(struct macb_rx_queue *rxq)
+{
+   uint64_t dma_addr;
+   struct macb_dma_desc *desc;
+   unsigned int entry;
+   struct rte_mbuf *nmb;
+   struct macb *bp;
+   register int i = 0;
+   struct macb_rx_entry *rxe;
+   uint8x8_t rearm_data_vec;
+
+   bp = rxq->bp;
+   rxe = &rxq->rx_sw_ring[rxq->rxrearm_start];
+
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+
+   rearm_data_vec = macb_mbuf_initializer(rxq);
+
+   /* Pull 'n' more MBUFs into the software ring */
+   if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxe,
+   MACB_RXQ_REARM_THRESH) < 0)) {
+   MACB_LOG(ERR, "allocate mbuf fail!");
+   rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
+   MACB_RXQ_REARM_THRESH;
+   return;
+   }
+
+   for (i = 0; i < MACB_RXQ_REARM_THRESH; ++i) {
+   nmb = rxe[i].mbuf;
+   entry = macb_rx_ring_wrap(bp, rxq->rxrearm_start);
+   desc = macb_rx_desc(rxq, entry);
+   rxq->rxrearm_start++;
+   vst1_u8((uint8_t *)&nmb->rearm_data, rearm_data_vec);
+   dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
+   if (unlikely(entry == rxq->nb_rx_desc - 1))
+   dma_addr |= MACB_BIT(RX_WRAP);
+   desc->ctrl = 0;
+   /* Setting addr clears RX_USED and allows reception,
+* make sure ctrl is cleared first to avoid a race.
+*/
+   rte_wmb();
+   macb_set_addr(bp, desc, dma_addr);
+   }
+   if (unlikely(rxq->rxrearm_start >= rxq->nb_rx_desc))
+   rxq->rxrearm_st

[PATCH v5 0/4]

2025-04-07 Thread liwencheng
v5:
- Putting __rte_unused after the declaration.
- Correct RX-bytes and TX-bytes statistics.
- Initialize the mbuf_initializer.
- Add driver based on 25.07.
- Fixed some code style issues.

v4:
- Fix tab errors in meson.build file.
- Use RTE_LOG_LINE instead of rte_log.
- Replace %l with %PRI*64.
- Replace rte_smp_[r/w]mb with rte_[r/w]mb.
- Do not use variadic arguments in macros.
- Do not use variable-length array pkts[nb_bufs].
- Use __rte_cache_aligned only for struct or union types alignment.
- Support hardware Rx/Tx checksum offload.
- Fixed some code style issues.
v3:
- Changed functions that always return 0 and whose return value
is unused to void type, improving code simplicity and readability.
- Fixed the implicit conversion issues in the
macb_usxgmii_pcs_check_for_link and
macb_usxgmii_pcs_check_for_link functions.
- Added the missing SPDX license tags.
- Added the missing mailmap entry.
- Updated the MAINTAINERS file to include the missing information.

v2:
- Split the driver into three logically independent patches,
rather than one large patch.
- Added conditional compilation to address the issue of
macb_rxtx_vec_neon.c failing to compile in certain modes.
- Fixed some code style issues.

v1:
- updated net macb driver.

*** BLURB HERE ***

Wencheng Li (4):
  usertools/dpdk-devbind: add platform devices support
  net/macb: add new poll mode driver
  net/macb: add NEON vectorized Rx/Tx
  net/macb: add necessary docs and update related files

 .mailmap   |1 +
 MAINTAINERS|6 +
 doc/guides/nics/features/macb.ini  |   27 +
 doc/guides/nics/index.rst  |1 +
 doc/guides/nics/macb.rst   |   26 +
 doc/guides/rel_notes/release_25_07.rst |4 +
 drivers/net/macb/base/generic_phy.c|  271 +
 drivers/net/macb/base/generic_phy.h|  202 
 drivers/net/macb/base/macb_common.c|  670 
 drivers/net/macb/base/macb_common.h|  253 +
 drivers/net/macb/base/macb_errno.h |   58 +
 drivers/net/macb/base/macb_hw.h| 1138 +++
 drivers/net/macb/base/macb_type.h  |   23 +
 drivers/net/macb/base/macb_uio.c   |  351 ++
 drivers/net/macb/base/macb_uio.h   |   50 +
 drivers/net/macb/base/meson.build  |   29 +
 drivers/net/macb/macb_ethdev.c | 1861 
 drivers/net/macb/macb_ethdev.h |   91 ++
 drivers/net/macb/macb_log.h|   19 +
 drivers/net/macb/macb_rxtx.c   | 1394 
 drivers/net/macb/macb_rxtx.h   |  325 ++
 drivers/net/macb/macb_rxtx_vec_neon.c  |  675 
 drivers/net/macb/meson.build   |   23 +
 drivers/net/meson.build|1 +
 usertools/dpdk-devbind.py  |  131 ++-
 25 files changed, 7613 insertions(+), 17 deletions(-)
 create mode 100644 doc/guides/nics/features/macb.ini
 create mode 100644 doc/guides/nics/macb.rst
 create mode 100644 drivers/net/macb/base/generic_phy.c
 create mode 100644 drivers/net/macb/base/generic_phy.h
 create mode 100644 drivers/net/macb/base/macb_common.c
 create mode 100644 drivers/net/macb/base/macb_common.h
 create mode 100644 drivers/net/macb/base/macb_errno.h
 create mode 100644 drivers/net/macb/base/macb_hw.h
 create mode 100644 drivers/net/macb/base/macb_type.h
 create mode 100644 drivers/net/macb/base/macb_uio.c
 create mode 100644 drivers/net/macb/base/macb_uio.h
 create mode 100644 drivers/net/macb/base/meson.build
 create mode 100644 drivers/net/macb/macb_ethdev.c
 create mode 100644 drivers/net/macb/macb_ethdev.h
 create mode 100644 drivers/net/macb/macb_log.h
 create mode 100644 drivers/net/macb/macb_rxtx.c
 create mode 100644 drivers/net/macb/macb_rxtx.h
 create mode 100644 drivers/net/macb/macb_rxtx_vec_neon.c
 create mode 100644 drivers/net/macb/meson.build

-- 
2.7.4



[PATCH v6 3/3] net/macb: add necessary docs and update related files

2025-04-10 Thread liwencheng
Added missing documentation in doc/guides/nics,
mailmap entry, and updated MAINTAINERS file.

Signed-off-by: liwencheng 
---
 MAINTAINERS|  6 ++
 doc/guides/nics/features/macb.ini  | 27 +++
 doc/guides/nics/index.rst  |  1 +
 doc/guides/nics/macb.rst   | 26 ++
 doc/guides/rel_notes/release_25_07.rst |  4 
 5 files changed, 64 insertions(+)
 create mode 100644 doc/guides/nics/features/macb.ini
 create mode 100644 doc/guides/nics/macb.rst

diff --git a/MAINTAINERS b/MAINTAINERS
index 167cc74..8b725ce 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -916,6 +916,12 @@ F: doc/guides/platform/bluefield.rst
 F: doc/guides/nics/mlx5.rst
 F: doc/guides/nics/features/mlx5.ini
 
+Phytium macb
+M: Wencheng Li 
+F: drivers/net/macb
+F: doc/guides/nics/macb.rst
+F: doc/guides/nics/features/macb.ini
+
 Microsoft mana
 M: Long Li 
 M: Wei Hu 
diff --git a/doc/guides/nics/features/macb.ini 
b/doc/guides/nics/features/macb.ini
new file mode 100644
index 000..cefc282
--- /dev/null
+++ b/doc/guides/nics/features/macb.ini
@@ -0,0 +1,27 @@
+;
+; Supported features of the 'macb' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+
+[Features]
+Speed capabilities   = Y
+Link status  = Y
+Queue start/stop = Y
+MTU update   = Y
+Allmulticast mode= Y
+CRC offload  = Y
+L3 checksum offload  = Y
+L4 checksum offload  = Y
+Scattered Rx = Y
+Rx descriptor status = Y
+Basic stats  = Y
+Linux= Y
+
+[rte_flow items]
+eth  = Y
+ipv4 = Y
+ipv6 = Y
+raw  = Y
+tcp  = Y
+udp  = Y
diff --git a/doc/guides/nics/index.rst b/doc/guides/nics/index.rst
index 10a2eca..8ae1950 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -43,6 +43,7 @@ Network Interface Controller Drivers
 ionic
 ipn3ke
 ixgbe
+macb
 mana
 memif
 mlx4
diff --git a/doc/guides/nics/macb.rst b/doc/guides/nics/macb.rst
new file mode 100644
index 000..5614a63
--- /dev/null
+++ b/doc/guides/nics/macb.rst
@@ -0,0 +1,26 @@
+..  SPDX-License-Identifier: BSD-3-Clause
+Copyright(c) 2022~2023 Phytium Technology Co., Ltd.
+
+MACB Poll Mode Driver
+=
+
+The MACB PMD provides poll mode driver support
+for the Ethernet interface MAC 1/2.5/10 Gbps adapter.
+
+Supported Chipsets and NICs
+---
+
+Phytium Ethernet interface cdns,phytium-gem-1.0
+Phytium Ethernet interface cdns,phytium-gem-2.0
+
+Features
+
+
+Features of the MACB PMD are:
+
+* Speed capabilities
+* Link status
+* Tx Queue start/stop
+* Multiple queues for TX and RX
+* CRC offload
+* Jumbo frames supported
diff --git a/doc/guides/rel_notes/release_25_07.rst 
b/doc/guides/rel_notes/release_25_07.rst
index 093b85d..5530bfc 100644
--- a/doc/guides/rel_notes/release_25_07.rst
+++ b/doc/guides/rel_notes/release_25_07.rst
@@ -55,6 +55,10 @@ New Features
  Also, make sure to start the actual text at the margin.
  ===
 
+* **Added Phytium macb net driver.**
+
+  Added a new network PMD which supports Phytium 1 and 10 Gigabit
+  Ethernet NICs.
 
 Removed Items
 -
-- 
2.7.4



[PATCH v4 4/4] net/macb: add necessary docs and update related files

2025-04-02 Thread liwencheng
Added missing documentation in doc/guides/nics,
mailmap entry, and updated MAINTAINERS file.

Signed-off-by: liwencheng 
---
 .mailmap   |  1 +
 MAINTAINERS|  6 ++
 doc/guides/nics/features/macb.ini  | 27 +++
 doc/guides/nics/index.rst  |  1 +
 doc/guides/nics/macb.rst   | 26 ++
 doc/guides/rel_notes/release_25_03.rst |  5 +
 6 files changed, 66 insertions(+)
 create mode 100644 doc/guides/nics/features/macb.ini
 create mode 100644 doc/guides/nics/macb.rst

diff --git a/.mailmap b/.mailmap
index d8439b7..001d7b2 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1675,6 +1675,7 @@ Wen Chiu 
 Wen-Chi Yang 
 Wenfeng Liu 
 Wenjie Li 
+Wencheng Li 
 Wenjie Sun 
 Wenjing Qiao 
 Wenjun Wu 
diff --git a/MAINTAINERS b/MAINTAINERS
index 4b01103..379645d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -920,6 +920,12 @@ F: doc/guides/platform/bluefield.rst
 F: doc/guides/nics/mlx5.rst
 F: doc/guides/nics/features/mlx5.ini
 
+Phytium macb
+M: Wencheng Li 
+F: drivers/net/macb
+F: doc/guides/nics/macb.rst
+F: doc/guides/nics/features/macb.ini
+
 Microsoft mana
 M: Long Li 
 M: Wei Hu 
diff --git a/doc/guides/nics/features/macb.ini 
b/doc/guides/nics/features/macb.ini
new file mode 100644
index 000..cefc282
--- /dev/null
+++ b/doc/guides/nics/features/macb.ini
@@ -0,0 +1,27 @@
+;
+; Supported features of the 'macb' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+
+[Features]
+Speed capabilities   = Y
+Link status  = Y
+Queue start/stop = Y
+MTU update   = Y
+Allmulticast mode= Y
+CRC offload  = Y
+L3 checksum offload  = Y
+L4 checksum offload  = Y
+Scattered Rx = Y
+Rx descriptor status = Y
+Basic stats  = Y
+Linux= Y
+
+[rte_flow items]
+eth  = Y
+ipv4 = Y
+ipv6 = Y
+raw  = Y
+tcp  = Y
+udp  = Y
diff --git a/doc/guides/nics/index.rst b/doc/guides/nics/index.rst
index 10a2eca..8ae1950 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -43,6 +43,7 @@ Network Interface Controller Drivers
 ionic
 ipn3ke
 ixgbe
+macb
 mana
 memif
 mlx4
diff --git a/doc/guides/nics/macb.rst b/doc/guides/nics/macb.rst
new file mode 100644
index 000..5614a63
--- /dev/null
+++ b/doc/guides/nics/macb.rst
@@ -0,0 +1,26 @@
+..  SPDX-License-Identifier: BSD-3-Clause
+Copyright(c) 2022~2023 Phytium Technology Co., Ltd.
+
+MACB Poll Mode Driver
+=
+
+The MACB PMD provides poll mode driver support
+for the Ethernet interface MAC 1/2.5/10 Gbps adapter.
+
+Supported Chipsets and NICs
+---
+
+Phytium Ethernet interface cdns,phytium-gem-1.0
+Phytium Ethernet interface cdns,phytium-gem-2.0
+
+Features
+
+
+Features of the MACB PMD are:
+
+* Speed capabilities
+* Link status
+* Tx Queue start/stop
+* Multiple queues for TX and RX
+* CRC offload
+* Jumbo frames supported
diff --git a/doc/guides/rel_notes/release_25_03.rst 
b/doc/guides/rel_notes/release_25_03.rst
index 652562a..f53ccc9 100644
--- a/doc/guides/rel_notes/release_25_03.rst
+++ b/doc/guides/rel_notes/release_25_03.rst
@@ -127,6 +127,11 @@ New Features
 
   See the :doc:`../compressdevs/zsda` guide for more details on the new driver.
 
+* **Added Phytium macb net driver.**
+
+  Added a new network PMD which supports Phytium 1 and 10 Gigabit
+  Ethernet NICs.
+
 * **Added atomic tests to the eventdev test application.**
 
   Added two atomic tests: ``atomic_queue`` and ``atomic_atq``.
-- 
2.7.4



[PATCH v4 1/4] usertools/dpdk-devbind: add bind/unbind for platform device

2025-04-02 Thread liwencheng
This patch mainly adds functions for bind and unbind platform devices,
such as bind_platform_one and unbind_platform_one.

Signed-off-by: liwencheng 
---
 usertools/dpdk-devbind.py | 131 --
 1 file changed, 114 insertions(+), 17 deletions(-)

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 06ae25a..600c4ba 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -65,7 +65,7 @@
 intel_idxd_spr = {'Class': '08', 'Vendor': '8086', 'Device': '0b25',
   'SVendor': None, 'SDevice': None}
 intel_idxd_gnrd = {'Class': '08', 'Vendor': '8086', 'Device': '11fb',
-  'SVendor': None, 'SDevice': None}
+   'SVendor': None, 'SDevice': None}
 intel_idxd_dmr = {'Class': '08', 'Vendor': '8086', 'Device': '1212',
   'SVendor': None, 'SDevice': None}
 intel_ntb_skx = {'Class': '06', 'Vendor': '8086', 'Device': '201c',
@@ -156,10 +156,32 @@ def module_is_loaded(module):
 return module in loaded_modules
 
 
+def get_platform_devices():
+global platform_devices
+
+platform_device_path = "/sys/bus/platform/devices/"
+platform_devices = os.listdir(platform_device_path)
+
+
+def devices_are_platform(devs):
+all_devices_are_platform = True
+
+get_platform_devices()
+for d in devs:
+if d not in platform_devices:
+all_devices_are_platform = False
+break
+
+return all_devices_are_platform
+
+
 def check_modules():
 '''Checks that igb_uio is loaded'''
 global dpdk_drivers
 
+if devices_are_platform(args):
+return
+
 # list of supported modules
 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers]
 
@@ -330,11 +352,38 @@ def dev_id_from_dev_name(dev_name):
 for d in devices.keys():
 if dev_name in devices[d]["Interface"].split(","):
 return devices[d]["Slot"]
+
+# Check if it is a platform device
+if dev_name in platform_devices:
+return dev_name
+
 # if nothing else matches - error
 raise ValueError("Unknown device: %s. "
  "Please specify device in \"bus:slot.func\" format" % 
dev_name)
 
 
+def unbind_platform_one(dev_name):
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+
+if exists(filename):
+try:
+f = open(os.path.join(filename, "unbind"), "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, os.path.join(filename, "unbind"), err))
+f.write(dev_name)
+f.close()
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s" %
+ (dev_name, filename, err))
+f.write("")
+f.close()
+print("Successfully unbind platform device %s" % dev_name)
+
+
 def unbind_one(dev_id, force):
 '''Unbind the device identified by "dev_id" from its current driver'''
 dev = devices[dev_id]
@@ -360,6 +409,48 @@ def unbind_one(dev_id, force):
 f.close()
 
 
+def bind_platform_one(dev_name, driver):
+filename = "/sys/bus/platform/drivers/%s" % driver
+
+if not exists(filename):
+print("The driver %s is not loaded" % driver)
+return
+# unbind any existing drivers we don't want
+filename = "/sys/bus/platform/devices/%s/driver" % dev_name
+if exists(filename):
+unbind_platform_one(dev_name)
+# driver_override can be used to specify the driver
+filename = "/sys/bus/platform/devices/%s/driver_override" % dev_name
+if exists(filename):
+try:
+f = open(filename, "w")
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot open %s: %s"
+ % (dev_name, filename, err))
+try:
+f.write(driver)
+f.close()
+except OSError as err:
+sys.exit("Error: unbind failed for %s - Cannot write %s: %s"
+ % (dev_name, filename, err))
+# do the bind by writing to /sys
+filename = "/sys/bus/platform/drivers/%s/bind" % driver
+try:
+   

[PATCH v4 4/4] net/macb: add necessary docs and update related files

2025-04-04 Thread liwencheng
Added missing documentation in doc/guides/nics,
mailmap entry, and updated MAINTAINERS file.

Signed-off-by: liwencheng 
---
 .mailmap   |  1 +
 MAINTAINERS|  6 ++
 doc/guides/nics/features/macb.ini  | 27 +++
 doc/guides/nics/index.rst  |  1 +
 doc/guides/nics/macb.rst   | 26 ++
 doc/guides/rel_notes/release_25_03.rst |  5 +
 6 files changed, 66 insertions(+)
 create mode 100644 doc/guides/nics/features/macb.ini
 create mode 100644 doc/guides/nics/macb.rst

diff --git a/.mailmap b/.mailmap
index d8439b7..001d7b2 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1675,6 +1675,7 @@ Wen Chiu 
 Wen-Chi Yang 
 Wenfeng Liu 
 Wenjie Li 
+Wencheng Li 
 Wenjie Sun 
 Wenjing Qiao 
 Wenjun Wu 
diff --git a/MAINTAINERS b/MAINTAINERS
index 4b01103..379645d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -920,6 +920,12 @@ F: doc/guides/platform/bluefield.rst
 F: doc/guides/nics/mlx5.rst
 F: doc/guides/nics/features/mlx5.ini
 
+Phytium macb
+M: Wencheng Li 
+F: drivers/net/macb
+F: doc/guides/nics/macb.rst
+F: doc/guides/nics/features/macb.ini
+
 Microsoft mana
 M: Long Li 
 M: Wei Hu 
diff --git a/doc/guides/nics/features/macb.ini 
b/doc/guides/nics/features/macb.ini
new file mode 100644
index 000..cefc282
--- /dev/null
+++ b/doc/guides/nics/features/macb.ini
@@ -0,0 +1,27 @@
+;
+; Supported features of the 'macb' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+
+[Features]
+Speed capabilities   = Y
+Link status  = Y
+Queue start/stop = Y
+MTU update   = Y
+Allmulticast mode= Y
+CRC offload  = Y
+L3 checksum offload  = Y
+L4 checksum offload  = Y
+Scattered Rx = Y
+Rx descriptor status = Y
+Basic stats  = Y
+Linux= Y
+
+[rte_flow items]
+eth  = Y
+ipv4 = Y
+ipv6 = Y
+raw  = Y
+tcp  = Y
+udp  = Y
diff --git a/doc/guides/nics/index.rst b/doc/guides/nics/index.rst
index 10a2eca..8ae1950 100644
--- a/doc/guides/nics/index.rst
+++ b/doc/guides/nics/index.rst
@@ -43,6 +43,7 @@ Network Interface Controller Drivers
 ionic
 ipn3ke
 ixgbe
+macb
 mana
 memif
 mlx4
diff --git a/doc/guides/nics/macb.rst b/doc/guides/nics/macb.rst
new file mode 100644
index 000..5614a63
--- /dev/null
+++ b/doc/guides/nics/macb.rst
@@ -0,0 +1,26 @@
+..  SPDX-License-Identifier: BSD-3-Clause
+Copyright(c) 2022~2023 Phytium Technology Co., Ltd.
+
+MACB Poll Mode Driver
+=
+
+The MACB PMD provides poll mode driver support
+for the Ethernet interface MAC 1/2.5/10 Gbps adapter.
+
+Supported Chipsets and NICs
+---
+
+Phytium Ethernet interface cdns,phytium-gem-1.0
+Phytium Ethernet interface cdns,phytium-gem-2.0
+
+Features
+
+
+Features of the MACB PMD are:
+
+* Speed capabilities
+* Link status
+* Tx Queue start/stop
+* Multiple queues for TX and RX
+* CRC offload
+* Jumbo frames supported
diff --git a/doc/guides/rel_notes/release_25_03.rst 
b/doc/guides/rel_notes/release_25_03.rst
index 652562a..f53ccc9 100644
--- a/doc/guides/rel_notes/release_25_03.rst
+++ b/doc/guides/rel_notes/release_25_03.rst
@@ -127,6 +127,11 @@ New Features
 
   See the :doc:`../compressdevs/zsda` guide for more details on the new driver.
 
+* **Added Phytium macb net driver.**
+
+  Added a new network PMD which supports Phytium 1 and 10 Gigabit
+  Ethernet NICs.
+
 * **Added atomic tests to the eventdev test application.**
 
   Added two atomic tests: ``atomic_queue`` and ``atomic_atq``.
-- 
2.7.4