net/hns3: updates for Rx Tx
Subsystems (2)
cover net/hns3: updates for Rx Tx
This series are updates for Rx/Tx process.
Chengchang Tang (1):
net/hns3: fix segfault when Tx multiple buffer packets
Wei Hu (Xavier) (7):
net/hns3: report Rx free threshold net/hns3: reduce address calculation in Rx net/hns3: add simple Rx process function net/hns3: add simple Tx process function net/hns3: add vector Tx burst with NEON instructions net/hns3: add vector Rx burst with NEON instructions net/hns3: add restriction on setting VF MTU
config/common_base | 1 + config/common_linux | 1 + drivers/net/hns3/Makefile | 5 + drivers/net/hns3/hns3_ethdev.c | 18 +- drivers/net/hns3/hns3_ethdev.h | 54 +- drivers/net/hns3/hns3_ethdev_vf.c | 41 +- drivers/net/hns3/hns3_rxtx.c | 1006 +++++++++++++++++++++++---------- drivers/net/hns3/hns3_rxtx.h | 227 +++++++- drivers/net/hns3/hns3_rxtx_vec.c | 214 +++++++ drivers/net/hns3/hns3_rxtx_vec.h | 77 +++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 284 ++++++++++ drivers/net/hns3/meson.build | 4 + 12 files changed, 1631 insertions(+), 301 deletions(-) create mode 100644 drivers/net/hns3/hns3_rxtx_vec.c create mode 100644 drivers/net/hns3/hns3_rxtx_vec.h create mode 100644 drivers/net/hns3/hns3_rxtx_vec_neon.h
Signature · 1 line
2.9.5
PATCH 1/8 net/hns3: report Rx free threshold
From: "Wei Hu (Xavier)" <[email protected]>
This patch reports .rx_free_thresh value in the .dev_infos_get ops implementation function named hns3_dev_infos_get and hns3vf_dev_infos_get. In addition, the name of the member variable of struct hns3_rx_queue is modified and comments are added to improve code readability.
--- drivers/net/hns3/hns3_ethdev.c | 2 ++ drivers/net/hns3/hns3_ethdev_vf.c | 2 ++ drivers/net/hns3/hns3_rxtx.c | 30 ++++++++++++------------------ drivers/net/hns3/hns3_rxtx.h | 9 ++++++--- 4 files changed, 22 insertions(+), 21 deletions(-)
drivers/net/hns3/hns3_ethdev.c +2 -0
@@ -2501,12 +2501,14 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) }; info->default_rxconf = (struct rte_eth_rxconf ) { + .rx_free_thresh =HNS3_DEFAULT_RX_FREE_THRESH ,/* * If there are no available Rx buffer descriptors, incoming * packets are always dropped by hardware based on hns3 network * engine. */ .rx_drop_en =1 , + .offloads =0 , }; info->vmdq_queue_num =0 ;
drivers/net/hns3/hns3_ethdev_vf.c +2 -0
@@ -944,12 +944,14 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) }; info->default_rxconf = (struct rte_eth_rxconf ) { + .rx_free_thresh =HNS3_DEFAULT_RX_FREE_THRESH ,/* * If there are no available Rx buffer descriptors, incoming * packets are always dropped by hardware based on hns3 network * engine. */ .rx_drop_en =1 , + .offloads =0 , }; info->vmdq_queue_num =0 ;
drivers/net/hns3/hns3_rxtx.c +12 -18
@@ -652,8 +652,7 @@ hns3_dev_rx_queue_start(struct hns3_adapter *hns, uint16_t idx) } rxq->next_to_use =0 ; - rxq->next_to_clean =0 ; - rxq->nb_rx_hold =0 ; + rxq->rx_free_hold =0 ;hns3_init_rx_queue_hw (rxq);return 0 ;
@@ -667,8 +666,7 @@ hns3_fake_rx_queue_start(struct hns3_adapter *hns, uint16_t idx) rxq = (struct hns3_rx_queue *)hw->fkq_data.rx_queues[idx]; rxq->next_to_use =0 ; - rxq->next_to_clean =0 ; - rxq->nb_rx_hold =0 ; + rxq->rx_free_hold =0 ;hns3_init_rx_queue_hw (rxq); }
@@ -1303,10 +1301,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, rxq->hns = hns; rxq->mb_pool = mp; -if (conf->rx_free_thresh <=0 ) - rxq->rx_free_thresh =DEFAULT_RX_FREE_THRESH ; -else - rxq->rx_free_thresh = conf->rx_free_thresh; + rxq->rx_free_thresh = (conf->rx_free_thresh >0 ) ? + conf->rx_free_thresh :HNS3_DEFAULT_RX_FREE_THRESH ; rxq->rx_deferred_start = conf->rx_deferred_start; rx_entry_len =sizeof (struct hns3_entry ) * rxq->nb_rx_desc;
@@ -1319,8 +1315,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, } rxq->next_to_use =0 ; - rxq->next_to_clean =0 ; - rxq->nb_rx_hold =0 ; + rxq->rx_free_hold =0 ; rxq->pkt_first_seg =NULL ; rxq->pkt_last_seg =NULL ; rxq->port_id = dev->data->port_id;
@@ -1656,11 +1651,11 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) nb_rx_bd =0 ; rxq = rx_queue; - rx_id = rxq->next_to_clean; + rx_id = rxq->next_to_use; rx_ring = rxq->rx_ring; + sw_ring = rxq->sw_ring; first_seg = rxq->pkt_first_seg; last_seg = rxq->pkt_last_seg; - sw_ring = rxq->sw_ring;while (nb_rx < nb_pkts) { rxdp = &rx_ring[rx_id];
@@ -1843,16 +1838,15 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) first_seg =NULL ; } - rxq->next_to_clean = rx_id; + rxq->next_to_use = rx_id; rxq->pkt_first_seg = first_seg; rxq->pkt_last_seg = last_seg; - nb_rx_bd = nb_rx_bd + rxq->nb_rx_hold; -if (nb_rx_bd > rxq->rx_free_thresh) { -hns3_clean_rx_buffers (rxq, nb_rx_bd); - nb_rx_bd =0 ; + rxq->rx_free_hold += nb_rx_bd; +if (rxq->rx_free_hold > rxq->rx_free_thresh) { +hns3_clean_rx_buffers (rxq, rxq->rx_free_hold); + rxq->rx_free_hold =0 ; } - rxq->nb_rx_hold = nb_rx_bd;return nb_rx; }
drivers/net/hns3/hns3_rxtx.h +6 -3
@@ -10,6 +10,7 @@#define HNS3_DEFAULT_RING_DESC 1024#define HNS3_ALIGN_RING_DESC 32#define HNS3_RING_BASE_ALIGN 128 +#define HNS3_DEFAULT_RX_FREE_THRESH 32#define HNS3_512_BD_BUF_SIZE 512#define HNS3_1K_BD_BUF_SIZE 1024
@@ -243,12 +244,14 @@ struct hns3_rx_queue {uint16_t queue_id;uint16_t port_id;uint16_t nb_rx_desc; -uint16_t nb_rx_hold; -uint16_t rx_tail; -uint16_t next_to_clean;uint16_t next_to_use;uint16_t rx_buf_len; +/* +* threshold for the number of BDs waited to passed to hardware. If the +* number exceeds the threshold, driver will pass these BDs to hardware. +*/ uint16_t rx_free_thresh; +uint16_t rx_free_hold;/* num of BDs waited to passed to hardware */ /* * port based vlan configuration state.
Signature · 1 line
2.9.5
PATCH 2/8 net/hns3: reduce address calculation in Rx
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds the internal function named hns3_write_reg_opt to avoid performance loss from address calculation during register access in the '.rx_pkt_burst' ops implementation function named hns3_recv_pkts.
In addition, because hardware always access register in little-endian mode based on hns3 network engine, so driver should also call rte_cpu_to_le_32 to convert data in little-endian mode before writing register and call rte_le_to_cpu_32 to convert data after reading from register. Here the driver encapsulates the data conversion operation in the register read/write operation function as below:
hns3_write_reg
hns3_write_reg_opt
hns3_read_reg
Therefore, when calling these functions, conversion is not required again.
--- drivers/net/hns3/hns3_ethdev.h | 29 +++++++++++++++++++++++++++-- drivers/net/hns3/hns3_rxtx.c | 14 +++----------- drivers/net/hns3/hns3_rxtx.h | 1 + 3 files changed, 31 insertions(+), 13 deletions(-)
drivers/net/hns3/hns3_ethdev.h +27 -2
@@ -708,14 +708,39 @@ struct hns3_adapter {#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +/* +* Because hardware always access register in little-endian mode based on hns3 +* network engine, so driver should also call rte_cpu_to_le_32 to convert data +* in little-endian mode before writing register and call rte_le_to_cpu_32 to +* convert data after reading from register. +* +* Here the driver encapsulates the data conversion operation in the register +* read/write operation function as below: +* hns3_write_reg +* hns3_write_reg_opt +* hns3_read_reg +* Therefore, when calling these functions, conversion is not required again. +*/ static inline void hns3_write_reg (void *base,uint32_t reg,uint32_t value) { -rte_write32 (value, (volatile void *)((char *)base + reg)); +rte_write32 (rte_cpu_to_le_32 (value), + (volatile void *)((char *)base + reg)); +} + +/* +* The optimized function for writing registers used in the '.rx_pkt_burst' and +* '.tx_pkt_burst' ops implementation function. +*/ +static inline void hns3_write_reg_opt (volatile void *addr,uint32_t value) +{ +rte_io_wmb (); +rte_write32_relaxed (rte_cpu_to_le_32 (value), addr); }static inline uint32_t hns3_read_reg (void *base,uint32_t reg) { -return rte_read32 ((volatile void *)((char *)base + reg)); +uint32_t read_val =rte_read32 ((volatile void *)((char *)base + reg)); +return rte_le_to_cpu_32 (read_val); }#define hns3_write_dev (a, reg, value) \
drivers/net/hns3/hns3_rxtx.c +3 -11
@@ -1323,6 +1323,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, rxq->configured = true; rxq->io_base = (void *)((char *)hw->io_base +HNS3_TQP_REG_OFFSET + idx *HNS3_TQP_REG_SIZE ); + rxq->io_head_reg = (volatile void *)((char *)rxq->io_base + +HNS3_RING_RX_HEAD_REG ); rxq->rx_buf_len = rx_buf_size; rxq->l2_errors =0 ; rxq->pkt_len_errors =0 ;
@@ -1472,16 +1474,6 @@ hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev)return NULL ; } -static void -hns3_clean_rx_buffers (struct hns3_rx_queue *rxq,int count) -{ - rxq->next_to_use += count; -if (rxq->next_to_use >= rxq->nb_rx_desc) - rxq->next_to_use -= rxq->nb_rx_desc; - -hns3_write_dev (rxq,HNS3_RING_RX_HEAD_REG , count); -} - static int hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm, uint32_t bd_base_info, uint32_t l234_info,
@@ -1844,7 +1836,7 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) rxq->rx_free_hold += nb_rx_bd;if (rxq->rx_free_hold > rxq->rx_free_thresh) { -hns3_clean_rx_buffers (rxq, rxq->rx_free_hold); +hns3_write_reg_opt (rxq->io_head_reg, rxq->rx_free_hold); rxq->rx_free_hold =0 ; }
drivers/net/hns3/hns3_rxtx.h +1 -0
@@ -231,6 +231,7 @@ struct hns3_entry {struct hns3_rx_queue {void *io_base; +volatile void *io_head_reg;struct hns3_adapter *hns;struct rte_mempool *mb_pool;struct hns3_desc *rx_ring;
Signature · 1 line
2.9.5
PATCH 3/8 net/hns3: add simple Rx process function
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds simple Rx process function and support chose Rx function by real Rx offloads capability.
--- drivers/net/hns3/hns3_ethdev.c | 7 +- drivers/net/hns3/hns3_ethdev.h | 21 ++ drivers/net/hns3/hns3_ethdev_vf.c | 11 +- drivers/net/hns3/hns3_rxtx.c | 538 +++++++++++++++++++++++--------------- drivers/net/hns3/hns3_rxtx.h | 130 ++++++++- 5 files changed, 489 insertions(+), 218 deletions(-)
drivers/net/hns3/hns3_ethdev.c +6 -1
@@ -2351,6 +2351,8 @@ hns3_dev_configure(struct rte_eth_dev *dev)if (ret) goto cfg_err; + hns->rx_simple_allowed = true; +hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;return 0 ;
@@ -4746,6 +4748,7 @@ hns3_dev_start(struct rte_eth_dev *dev) hw->adapter_state =HNS3_NIC_STARTED ;rte_spinlock_unlock (&hw->lock); +hns3_rx_scattered_calc (dev);hns3_set_rxtx_function (dev);hns3_mp_req_start_rxtx (dev);rte_eal_alarm_set (HNS3_SERVICE_INTERVAL , hns3_service_handler, dev);
@@ -4844,6 +4847,7 @@ hns3_dev_stop(struct rte_eth_dev *dev)hns3_dev_release_mbufs (hns); hw->adapter_state =HNS3_NIC_CONFIGURED ; } +hns3_rx_scattered_reset (dev);rte_eal_alarm_cancel (hns3_service_handler, dev);rte_spinlock_unlock (&hw->lock); }
@@ -5514,6 +5518,7 @@ hns3_reset_service(void *param) }static const struct eth_dev_ops hns3_eth_dev_ops = { + .dev_configure = hns3_dev_configure, .dev_start = hns3_dev_start, .dev_stop = hns3_dev_stop, .dev_close = hns3_dev_close,
@@ -5539,7 +5544,7 @@ static const struct eth_dev_ops hns3_eth_dev_ops = { .rx_queue_intr_disable = hns3_dev_rx_queue_intr_disable, .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, - .dev_configure = hns3_dev_configure, + .rx_burst_mode_get = hns3_rx_burst_mode_get, .flow_ctrl_get = hns3_flow_ctrl_get, .flow_ctrl_set = hns3_flow_ctrl_set, .priority_flow_ctrl_set = hns3_priority_flow_ctrl_set,
drivers/net/hns3/hns3_ethdev.h +21 -0
@@ -433,6 +433,7 @@ struct hns3_hw {uint16_t tqps_num;/* num task queue pairs of this function */ uint16_t intr_tqps_num;/* num queue pairs mapping interrupt */ uint16_t rss_size_max;/* HW defined max RSS task queue */ +uint16_t rx_buf_len;/* hold min hardware rx buf len */ uint16_t num_tx_desc;/* desc num of per tx queue */ uint16_t num_rx_desc;/* desc num of per rx queue */ uint32_t mng_entry_num;/* number of manager table entry */
@@ -575,6 +576,23 @@ struct hns3_mp_param {/* Key string for IPC. */ #define HNS3_MP_NAME "net_hns3_mp" +#define HNS3_L2TBL_NUM 4 +#define HNS3_L3TBL_NUM 16 +#define HNS3_L4TBL_NUM 16 +#define HNS3_OL3TBL_NUM 16 +#define HNS3_OL4TBL_NUM 16 + +struct hns3_ptype_table { +uint32_t l2table[HNS3_L2TBL_NUM ]; +uint32_t l3table[HNS3_L3TBL_NUM ]; +uint32_t l4table[HNS3_L4TBL_NUM ]; +uint32_t inner_l2table[HNS3_L2TBL_NUM ]; +uint32_t inner_l3table[HNS3_L3TBL_NUM ]; +uint32_t inner_l4table[HNS3_L4TBL_NUM ]; +uint32_t ol3table[HNS3_OL3TBL_NUM ]; +uint32_t ol4table[HNS3_OL4TBL_NUM ]; +}; +struct hns3_pf {struct hns3_adapter *adapter;bool is_main_pf;
@@ -623,6 +641,9 @@ struct hns3_adapter {struct hns3_pf pf;struct hns3_vf vf; }; + +bool rx_simple_allowed; + struct hns3_ptype_table ptype_tbl __rte_cache_min_aligned; };#define HNS3_DEV_SUPPORT_DCB_B 0x0
drivers/net/hns3/hns3_ethdev_vf.c +9 -2
@@ -745,7 +745,8 @@ hns3vf_init_ring_with_vector(struct hns3_hw *hw)static int hns3vf_dev_configure (struct rte_eth_dev *dev) { -struct hns3_hw *hw =HNS3_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct hns3_adapter *hns = dev->data->dev_private; +struct hns3_hw *hw = &hns->hw;struct hns3_rss_conf *rss_cfg = &hw->rss_info;struct rte_eth_conf *conf = &dev->data->dev_conf;enum rte_eth_rx_mq_mode mq_mode = conf->rxmode.mq_mode;
@@ -820,6 +821,9 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)if (ret) goto cfg_err; + hns->rx_simple_allowed = true; +hns3_init_rx_ptype_tble (dev); + hw->adapter_state =HNS3_NIC_CONFIGURED ;return 0 ;
@@ -1875,6 +1879,7 @@ hns3vf_dev_stop(struct rte_eth_dev *dev)hns3_dev_release_mbufs (hns); hw->adapter_state =HNS3_NIC_CONFIGURED ; } +hns3_rx_scattered_reset (dev);rte_eal_alarm_cancel (hns3vf_service_handler, dev);rte_spinlock_unlock (&hw->lock); }
@@ -2111,6 +2116,7 @@ hns3vf_dev_start(struct rte_eth_dev *dev) hw->adapter_state =HNS3_NIC_STARTED ;rte_spinlock_unlock (&hw->lock); +hns3_rx_scattered_calc (dev);hns3_set_rxtx_function (dev);hns3_mp_req_start_rxtx (dev);rte_eal_alarm_set (HNS3VF_SERVICE_INTERVAL , hns3vf_service_handler, dev);
@@ -2508,6 +2514,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns) }static const struct eth_dev_ops hns3vf_eth_dev_ops = { + .dev_configure = hns3vf_dev_configure, .dev_start = hns3vf_dev_start, .dev_stop = hns3vf_dev_stop, .dev_close = hns3vf_dev_close,
@@ -2533,7 +2540,7 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = { .rx_queue_intr_disable = hns3_dev_rx_queue_intr_disable, .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, - .dev_configure = hns3vf_dev_configure, + .rx_burst_mode_get = hns3_rx_burst_mode_get, .mac_addr_add = hns3vf_add_mac_addr, .mac_addr_remove = hns3vf_remove_mac_addr, .mac_addr_set = hns3vf_set_default_mac_addr,
drivers/net/hns3/hns3_rxtx.c +324 -214
715 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx.h +129 -1
183 lines not on this page · raw message
Signature · 1 line
2.9.5
PATCH 4/8 net/hns3: add simple Tx process function
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds simple Tx process function. When multiple segment packets are not needed, Which means that DEV_TX_OFFLOAD_MBUF_FAST_FREE offload is not set, we can simple Tx process.
--- drivers/net/hns3/hns3_ethdev.c | 6 + drivers/net/hns3/hns3_ethdev.h | 1 + drivers/net/hns3/hns3_ethdev_vf.c | 6 + drivers/net/hns3/hns3_rxtx.c | 260 +++++++++++++++++++++++++++++++++++--- drivers/net/hns3/hns3_rxtx.h | 34 +++++ 5 files changed, 292 insertions(+), 15 deletions(-)
drivers/net/hns3/hns3_ethdev.c +6 -0
@@ -2352,6 +2352,7 @@ hns3_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->tx_simple_allowed = true;hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
@@ -2512,6 +2513,10 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) .rx_drop_en = 1, .offloads = 0, }; + info->default_txconf = (struct rte_eth_txconf ) { + .tx_rs_thresh =HNS3_DEFAULT_TX_RS_THRESH , + .offloads =0 , + }; info->vmdq_queue_num =0 ;
@@ -5545,6 +5550,7 @@ static const struct eth_dev_ops hns3_eth_dev_ops = { .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, .rx_burst_mode_get = hns3_rx_burst_mode_get, + .tx_burst_mode_get = hns3_tx_burst_mode_get, .flow_ctrl_get = hns3_flow_ctrl_get, .flow_ctrl_set = hns3_flow_ctrl_set, .priority_flow_ctrl_set = hns3_priority_flow_ctrl_set,
drivers/net/hns3/hns3_ethdev.h +1 -0
@@ -643,6 +643,7 @@ struct hns3_adapter { };bool rx_simple_allowed; +bool tx_simple_allowed; struct hns3_ptype_table ptype_tbl __rte_cache_min_aligned; };
drivers/net/hns3/hns3_ethdev_vf.c +6 -0
@@ -822,6 +822,7 @@ hns3vf_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->tx_simple_allowed = true;hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
@@ -957,6 +958,10 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) .rx_drop_en = 1, .offloads = 0, }; + info->default_txconf = (struct rte_eth_txconf ) { + .tx_rs_thresh =HNS3_DEFAULT_TX_RS_THRESH , + .offloads =0 , + }; info->vmdq_queue_num =0 ;
@@ -2541,6 +2546,7 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = { .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, .rx_burst_mode_get = hns3_rx_burst_mode_get, + .tx_burst_mode_get = hns3_tx_burst_mode_get, .mac_addr_add = hns3vf_add_mac_addr, .mac_addr_remove = hns3vf_remove_mac_addr, .mac_addr_set = hns3vf_set_default_mac_addr,
drivers/net/hns3/hns3_rxtx.c +245 -15
329 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx.h +34 -0
@@ -13,6 +13,9 @@#define HNS3_BULK_ALLOC_MBUF_NUM 32#define HNS3_DEFAULT_RX_FREE_THRESH 32 +#define HNS3_DEFAULT_TX_FREE_THRESH 32 +#define HNS3_DEFAULT_TX_RS_THRESH 32 +#define HNS3_TX_FAST_FREE_AHEAD 64#define HNS3_512_BD_BUF_SIZE 512#define HNS3_1K_BD_BUF_SIZE 1024
@@ -282,6 +285,7 @@ struct hns3_rx_queue {struct hns3_tx_queue {void *io_base; +volatile void *io_tail_reg;struct hns3_adapter *hns;struct hns3_desc *tx_ring;uint64_t tx_ring_phys_addr;/* TX ring DMA address */
@@ -291,10 +295,32 @@ struct hns3_tx_queue {uint16_t queue_id;uint16_t port_id;uint16_t nb_tx_desc; +/* +* index of next BD whose corresponding rte_mbuf can be released by +* driver. +*/ uint16_t next_to_clean; +/* index of next BD to be filled by driver to send packet */ uint16_t next_to_use; +/* num of remaining BDs ready to be filled by driver to send packet */ uint16_t tx_bd_ready; +/* threshold for free tx buffer if available BDs less than this value */ +uint16_t tx_free_thresh; + +/* +* For better performance in tx datapath, releasing mbuf in batches is +* required. +* Only checking the VLD bit of the last descriptor in a batch of the +* thresh descriptors does not mean that these descriptors are all sent +* by hardware successfully. So we need to check that the VLD bits of +* all descriptors are cleared. and then free all mbufs in the batch. +* - tx_rs_thresh +* Number of mbufs released at a time. + +*/ +uint16_t tx_rs_thresh; +/* * port based vlan configuration state. * value range: HNS3_PORT_BASE_VLAN_DISABLE / HNS3_PORT_BASE_VLAN_ENABLE
@@ -360,6 +386,9 @@ struct hns3_tx_queue {uint64_t pkt_padding_fail_cnt; }; +#define HNS3_GET_TX_QUEUE_PEND_BD_NUM (txq) \ + ((txq)->nb_tx_desc - 1 - (txq)->tx_bd_ready) +struct hns3_queue_info {const char *type;/* point to queue memory name */ const char *ring_name;/* point to hardware ring name */
@@ -525,8 +554,13 @@ int hns3_rx_burst_mode_get(struct rte_eth_dev *dev, struct rte_eth_burst_mode *mode); uint16_t hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t hns3_xmit_pkts_simple (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);uint16_t hns3_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +int hns3_tx_burst_mode_get (struct rte_eth_dev *dev, + __rte_unused uint16_t queue_id, +struct rte_eth_burst_mode *mode);const uint32_t *hns3_dev_supported_ptypes_get (struct rte_eth_dev *dev);void hns3_init_rx_ptype_tble (struct rte_eth_dev *dev);void hns3_set_rxtx_function (struct rte_eth_dev *eth_dev);
Signature · 1 line
2.9.5
PATCH 5/8 net/hns3: add vector Tx burst with NEON instructions
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds NEON vector instructions to optimize Tx burst process.
--- config/common_base | 1 + config/common_linux | 1 + drivers/net/hns3/Makefile | 5 +++ drivers/net/hns3/hns3_ethdev.c | 2 + drivers/net/hns3/hns3_ethdev.h | 2 + drivers/net/hns3/hns3_ethdev_vf.c | 2 + drivers/net/hns3/hns3_rxtx.c | 33 ++++++++++++++ drivers/net/hns3/hns3_rxtx.h | 20 ++++++++- drivers/net/hns3/hns3_rxtx_vec.c | 47 ++++++++++++++++++++ drivers/net/hns3/hns3_rxtx_vec.h | 57 ++++++++++++++++++++++++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 81 +++++++++++++++++++++++++++++++++++ drivers/net/hns3/meson.build | 4 ++ 12 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 drivers/net/hns3/hns3_rxtx_vec.c create mode 100644 drivers/net/hns3/hns3_rxtx_vec.h create mode 100644 drivers/net/hns3/hns3_rxtx_vec_neon.h
config/common_base +1 -0
@@ -292,6 +292,7 @@ CONFIG_RTE_LIBRTE_HINIC_PMD=n # Compile burst-oriented HNS3 PMD driver # CONFIG_RTE_LIBRTE_HNS3_PMD=n +CONFIG_RTE_LIBRTE_HNS3_INC_VECTOR=n # # Compile Pensando IONIC PMD driver
config/common_linux +1 -0
@@ -66,3 +66,4 @@ CONFIG_RTE_LIBRTE_HINIC_PMD=y # Hisilicon HNS3 PMD driver # CONFIG_RTE_LIBRTE_HNS3_PMD=y +CONFIG_RTE_LIBRTE_HNS3_INC_VECTOR=y
drivers/net/hns3/Makefile +5 -0
@@ -30,6 +30,11 @@ SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_ethdev_vf.c SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_cmd.c SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_mbx.c SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_rxtx.c + +ifeq ($(CONFIG_RTE_ARCH_ARM64),y) +SRCS-$(CONFIG_RTE_LIBRTE_HNS3_INC_VECTOR) += hns3_rxtx_vec.c +endif + SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_rss.c SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_flow.c SRCS-$(CONFIG_RTE_LIBRTE_HNS3_PMD) += hns3_fdir.c
drivers/net/hns3/hns3_ethdev.c +2 -0
@@ -2353,6 +2353,8 @@ hns3_dev_configure(struct rte_eth_dev *dev) hns->rx_simple_allowed = true; hns->tx_simple_allowed = true; + hns->tx_vec_allowed = true; +hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
drivers/net/hns3/hns3_ethdev.h +2 -0
@@ -644,6 +644,8 @@ struct hns3_adapter {bool rx_simple_allowed;bool tx_simple_allowed; +bool tx_vec_allowed; + struct hns3_ptype_table ptype_tbl __rte_cache_min_aligned; };
drivers/net/hns3/hns3_ethdev_vf.c +2 -0
@@ -823,6 +823,8 @@ hns3vf_dev_configure(struct rte_eth_dev *dev) hns->rx_simple_allowed = true; hns->tx_simple_allowed = true; + hns->tx_vec_allowed = true; +hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
drivers/net/hns3/hns3_rxtx.c +33 -0
@@ -95,6 +95,8 @@ hns3_tx_queue_release(void *queue)rte_memzone_free (txq->mz);if (txq->sw_ring)rte_free (txq->sw_ring); +if (txq->free) +rte_free (txq->free);rte_free (txq); } }
@@ -1020,6 +1022,7 @@ hns3_fake_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,/* Don't need alloc sw_ring, because upper applications don't use it */ txq->sw_ring =NULL ; + txq->free =NULL ; txq->hns = hns; txq->tx_deferred_start = false;
@@ -2052,6 +2055,15 @@ hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, txq->tx_bd_ready = txq->nb_tx_desc -1 ; txq->tx_free_thresh = tx_free_thresh; txq->tx_rs_thresh = tx_rs_thresh; + txq->free =rte_zmalloc_socket ("hns3 TX mbuf free array" , +sizeof (struct rte_mbuf *) * txq->tx_rs_thresh, +RTE_CACHE_LINE_SIZE , socket_id); +if (!txq->free) { +hns3_err (hw,"failed to allocate tx mbuf free array!" ); +hns3_tx_queue_release (txq); +return -ENOMEM ; + } + txq->port_id = dev->data->port_id; txq->pvid_state = hw->port_base_vlan_cfg.state; txq->configured = true;
@@ -3105,6 +3117,20 @@ hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)return nb_tx; } +int __rte_weak +hns3_tx_check_vec_support(__rte_unused struct rte_eth_dev *dev) +{ +return -ENOTSUP ; +} + +uint16_t __rte_weak +hns3_xmit_pkts_vec(__rte_unused void *tx_queue, + __rte_unused struct rte_mbuf **tx_pkts, + __rte_unused uint16_t nb_pkts) +{ +return 0 ; +} +int hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,struct rte_eth_burst_mode *mode)
@@ -3116,6 +3142,8 @@ hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id, info ="Scalar Simple" ; else if (pkt_burst == hns3_xmit_pkts) info ="Scalar" ; + else if (pkt_burst == hns3_xmit_pkts_vec) + info ="Vector Neon" ;if (info ==NULL )return -EINVAL ;
@@ -3131,6 +3159,11 @@ hns3_get_tx_function(struct rte_eth_dev *dev, eth_tx_prep_t *prep)uint64_t offloads = dev->data->dev_conf.txmode.offloads;struct hns3_adapter *hns = dev->data->dev_private; +if (hns->tx_vec_allowed &&hns3_tx_check_vec_support (dev) ==0 ) { + *prep =NULL ; +return hns3_xmit_pkts_vec; + } +if (hns->tx_simple_allowed && offloads == (offloads &DEV_TX_OFFLOAD_MBUF_FAST_FREE )) { *prep =NULL ;
drivers/net/hns3/hns3_rxtx.h +19 -1
@@ -17,6 +17,10 @@#define HNS3_DEFAULT_TX_RS_THRESH 32#define HNS3_TX_FAST_FREE_AHEAD 64 +#define HNS3_UINT8_BIT 8 +#define HNS3_UINT16_BIT 16 +#define HNS3_UINT32_BIT 32 +#define HNS3_512_BD_BUF_SIZE 512#define HNS3_1K_BD_BUF_SIZE 1024#define HNS3_2K_BD_BUF_SIZE 2048
@@ -132,6 +136,13 @@#define HNS3_L3_LEN_UNIT 2UL#define HNS3_L4_LEN_UNIT 2UL +#define HNS3_TXD_DEFAULT_BDTYPE 0 +#define HNS3_TXD_VLD_CMD (0x1 << HNS3_TXD_VLD_B) +#define HNS3_TXD_FE_CMD (0x1 << HNS3_TXD_FE_B) +#define HNS3_TXD_DEFAULT_VLD_FE_BDTYPE \ + (HNS3_TXD_VLD_CMD | HNS3_TXD_FE_CMD | HNS3_TXD_DEFAULT_BDTYPE) +#define HNS3_TXD_SEND_SIZE_SHIFT 16 +enum hns3_pkt_l2t_type {HNS3_L2_TYPE_UNICAST ,HNS3_L2_TYPE_MULTICAST ,
@@ -317,9 +328,13 @@ struct hns3_tx_queue {* all descriptors are cleared. and then free all mbufs in the batch. * - tx_rs_thresh * Number of mbufs released at a time. - +* +* - free +* Tx mbuf free array used for preserving temporarily address of mbuf +* released back to mempool, when releasing mbuf in batches. */ uint16_t tx_rs_thresh; +struct rte_mbuf **free;/* * port based vlan configuration state.
@@ -558,6 +573,8 @@ uint16_t hns3_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);uint16_t hns3_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t hns3_xmit_pkts_vec (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);int hns3_tx_burst_mode_get (struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,struct rte_eth_burst_mode *mode);
@@ -577,6 +594,7 @@ int hns3_restore_gro_conf(struct hns3_hw *hw);void hns3_update_all_queues_pvid_state (struct hns3_hw *hw);void hns3_rx_scattered_reset (struct rte_eth_dev *dev);void hns3_rx_scattered_calc (struct rte_eth_dev *dev); +int hns3_tx_check_vec_support (struct rte_eth_dev *dev);void hns3_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_rxq_info *qinfo); void hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/hns3/hns3_rxtx_vec.c new file +47 -0
47 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx_vec.h new file +57 -0
57 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx_vec_neon.h new file +81 -0
81 lines not on this page · raw message
drivers/net/hns3/meson.build +4 -0
@@ -27,4 +27,8 @@ sources = files('hns3_cmd.c', 'hns3_stats.c', 'hns3_mp.c') +if (dpdk_conf.has('RTE_ARCH_ARM64')) + sources += files('hns3_rxtx_vec.c') +endif + deps += ['hash']
Signature · 1 line
2.9.5
PATCH 6/8 net/hns3: add vector Rx burst with NEON instructions
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds NEON vector instructions to optimize Rx burst process.
--- drivers/net/hns3/hns3_ethdev.c | 1 + drivers/net/hns3/hns3_ethdev.h | 1 + drivers/net/hns3/hns3_ethdev_vf.c | 1 + drivers/net/hns3/hns3_rxtx.c | 94 +++++++++++++++- drivers/net/hns3/hns3_rxtx.h | 35 +++++- drivers/net/hns3/hns3_rxtx_vec.c | 167 ++++++++++++++++++++++++++++ drivers/net/hns3/hns3_rxtx_vec.h | 20 ++++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 203 ++++++++++++++++++++++++++++++++++ 8 files changed, 514 insertions(+), 8 deletions(-)
drivers/net/hns3/hns3_ethdev.c +1 -0
@@ -2352,6 +2352,7 @@ hns3_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->rx_vec_allowed = true; hns->tx_simple_allowed = true; hns->tx_vec_allowed = true;
drivers/net/hns3/hns3_ethdev.h +1 -0
@@ -643,6 +643,7 @@ struct hns3_adapter { };bool rx_simple_allowed; +bool rx_vec_allowed;bool tx_simple_allowed;bool tx_vec_allowed;
drivers/net/hns3/hns3_ethdev_vf.c +1 -0
@@ -822,6 +822,7 @@ hns3vf_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->rx_vec_allowed = true; hns->tx_simple_allowed = true; hns->tx_vec_allowed = true;
drivers/net/hns3/hns3_rxtx.c +88 -6
164 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx.h +33 -2
@@ -17,6 +17,18 @@#define HNS3_DEFAULT_TX_RS_THRESH 32#define HNS3_TX_FAST_FREE_AHEAD 64 +#define HNS3_DEFAULT_RX_BURST 32 +#if (HNS3_DEFAULT_RX_BURST >64 ) +#error "PMD HNS3: HNS3_DEFAULT_RX_BURST must <= 64\n" +#endif +#define HNS3_DEFAULT_DESCS_PER_LOOP 4 +#define HNS3_SVE_DEFAULT_DESCS_PER_LOOP 8 +#if (HNS3_DEFAULT_DESCS_PER_LOOP >HNS3_SVE_DEFAULT_DESCS_PER_LOOP ) +#define HNS3_VECTOR_RX_OFFSET_TABLE_LEN HNS3_DEFAULT_DESCS_PER_LOOP +#else +#define HNS3_VECTOR_RX_OFFSET_TABLE_LEN HNS3_SVE_DEFAULT_DESCS_PER_LOOP +#endif +#define HNS3_DEFAULT_RXQ_REARM_THRESH 64#define HNS3_UINT8_BIT 8#define HNS3_UINT16_BIT 16#define HNS3_UINT32_BIT 32
@@ -236,7 +248,13 @@ struct hns3_desc {uint16_t ot_vlan_tag; }; }; -uint32_t bd_base_info; +union { +uint32_t bd_base_info; +struct { +uint16_t bdtype_vld_udp0; +uint16_t fe_lum_crcp_l3l4p; + }; + }; } rx; }; } __rte_packed;
@@ -270,7 +288,8 @@ struct hns3_rx_queue {uint16_t rx_free_thresh;uint16_t next_to_use;/* index of next BD to be polled */ uint16_t rx_free_hold;/* num of BDs waited to passed to hardware */ - +uint16_t rx_rearm_start;/* index of BD that driver re-arming from */ +uint16_t rx_rearm_nb;/* number of remaining BDs to be re-armed */ /* * port based vlan configuration state. * value range: HNS3_PORT_BASE_VLAN_DISABLE / HNS3_PORT_BASE_VLAN_ENABLE
@@ -292,6 +311,11 @@ struct hns3_rx_queue {struct rte_mbuf *bulk_mbuf[HNS3_BULK_ALLOC_MBUF_NUM ];uint16_t bulk_mbuf_num; + +/* offset_table: used for vector, to solve execute re-order problem */ +uint8_t offset_table[HNS3_VECTOR_RX_OFFSET_TABLE_LEN +1 ]; +uint64_t mbuf_initializer;/* value to init mbufs used with vector rx */ +struct rte_mbuf fake_mbuf;/* fake mbuf used with vector rx */ };struct hns3_tx_queue {
@@ -554,6 +578,8 @@ int hns3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);void hns3_enable_all_queues (struct hns3_hw *hw,bool en);int hns3_start_queues (struct hns3_adapter *hns,bool reset_queue);int hns3_stop_queues (struct hns3_adapter *hns,bool reset_queue); +int hns3_rxq_iterate (struct rte_eth_dev *dev, +int (*callback)(struct hns3_rx_queue *,void *),void *arg);void hns3_dev_release_mbufs (struct hns3_adapter *hns); int hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, unsigned int socket, const struct rte_eth_rxconf *conf,
@@ -564,9 +590,12 @@ uint16_t hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);uint16_t hns3_recv_scattered_pkts (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t hns3_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts, +uint16_t nb_pkts);int hns3_rx_burst_mode_get (struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,struct rte_eth_burst_mode *mode); +int hns3_rx_check_vec_support (struct rte_eth_dev *dev); uint16_t hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t nb_pkts); uint16_t hns3_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
@@ -594,7 +623,9 @@ int hns3_restore_gro_conf(struct hns3_hw *hw);void hns3_update_all_queues_pvid_state (struct hns3_hw *hw);void hns3_rx_scattered_reset (struct rte_eth_dev *dev);void hns3_rx_scattered_calc (struct rte_eth_dev *dev); +int hns3_rx_check_vec_support (struct rte_eth_dev *dev);int hns3_tx_check_vec_support (struct rte_eth_dev *dev); +void hns3_rxq_vec_setup (struct hns3_rx_queue *rxq);void hns3_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_rxq_info *qinfo); void hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/hns3/hns3_rxtx_vec.c +167 -0
170 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx_vec.h +20 -0
@@ -54,4 +54,24 @@ hns3_tx_free_buffers(struct hns3_tx_queue *txq)if (txq->next_to_clean >= txq->nb_tx_desc) txq->next_to_clean = 0; } + +static inline uint16_t +hns3_rx_reassemble_pkts (struct rte_mbuf **rx_pkts, +uint16_t nb_pkts, +uint64_t pkt_err_mask) +{ +uint16_t count, i; +uint64_t mask; + + count =0 ; +for (i =0 ; i < nb_pkts; i++) { + mask = ((uint64_t )1u ) << i; +if (pkt_err_mask & mask) +rte_pktmbuf_free_seg (rx_pkts[i]); +else + rx_pkts[count++] = rx_pkts[i]; + } + +return count; +}#endif /* _HNS3_RXTX_VEC_H_ */
drivers/net/hns3/hns3_rxtx_vec_neon.h +203 -0
207 lines not on this page · raw message
Signature · 1 line
2.9.5
PATCH 7/8 net/hns3: add restriction on setting VF MTU
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
when Rx of scattered packets is off, we have some possibility of using vector Rx process function or simple Rx functions in hns3 PMD driver. If the input MTU is increased and the maximum length of received packets is greater than the length of a buffer for Rx packets, the hardware network engine needs to use multiple BDs and buffers to store these packets. This will cause problems when still using vector Rx process function or simple Rx function to receiving packets. So, when Rx of scattered packets is off and device is started, it is not permitted to increase MTU so that the maximum length of Rx packets is greater than Rx buffer length.
--- drivers/net/hns3/hns3_ethdev_vf.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/net/hns3/hns3_ethdev_vf.c +19 -0
@@ -871,6 +871,25 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)return -EIO ; } +/* +* when Rx of scattered packets is off, we have some possibility of +* using vector Rx process function or simple Rx functions in hns3 PMD +* driver. If the input MTU is increased and the maximum length of +* received packets is greater than the length of a buffer for Rx +* packet, the hardware network engine needs to use multiple BDs and +* buffers to store these packets. This will cause problems when still +* using vector Rx process function or simple Rx function to receiving +* packets. So, when Rx of scattered packets is off and device is +* started, it is not permitted to increase MTU so that the maximum +* length of Rx packets is greater than Rx buffer length. +*/ +if (dev->data->dev_started && !dev->data->scattered_rx && + frame_size > hw->rx_buf_len) { +hns3_err (hw,"failed to set mtu because current is " +"not scattered rx mode" ); +return -EOPNOTSUPP ; + } +rte_spinlock_lock (&hw->lock); ret =hns3vf_config_mtu (hw, mtu);if (ret) {
Signature · 1 line
2.9.5
PATCH 8/8 net/hns3: fix segfault when Tx multiple buffer packets
In reply to Wei Hu (Xavier)From: Chengchang Tang <[email protected]>
Currently, there is a possibility that segment faults occur when sending packets whose payloads are stored in multiple buffers based on hns3 network engine. The related core dump information as follows:
Program terminated with signal 11, Segmentation fault. 0 hns3_reassemble_tx_pkts
2512 temp = temp->next;
Missing separate debuginfos, use:
(gdb) bt
0 hns3_reassemble_tx_pkts 1 0x0000000000969c60 in hns3_check_non_tso_pkt 2 0x000000000096adbc in hns3_xmit_pkts 3 0x000000000050d4d0 in rte_eth_tx_burst 4 0x000000000050fca4 in pkt_burst_transmit 5 0x00000000004ca6b8 in run_pkt_fwd_on_lcore 6 0x00000000004ca7fc in start_pkt_forward_on_core 7 0x00000000006975a4 in eal_thread_loop 8 0x0000ffffa6f7fc48 in start_thread 9 0x0000ffffa6ed1600 in thread_start
The root cause is that hns3 PMD driver invokes the rte_pktmbuf_free_seg API function to release the same rte_mbuf multiple times. The rte_mbuf pointer is not set to NULL in the internal function hns3_rx_queue_release_mbufs which is invoked during queue setup, stop and close. As a result the rte_mbuf in Rx queues will be repeatedly released when the user application setup queues or stop/start the dev for multiple times. Probably for performance reasons, DPDK mempool lib does not check for the repeated rte_mbuf releases. The Address of released rte_mbuf are directly stored into the per lcore cache of the mempool. This makes the rte_mbufs obtained from mempool by calling rte_mempool_get_bulk API function repetitively. ultimately, it causes to access to a NULL pointer in PMD driver.
This patch fixes this problem by setting released mbuf pointer to NULL in the internal function named hns3_rx_queue_release_mbuf. And the other internal function named hns3_reassemble_tx_pkts is optimized to avoid a similar problem.
--- drivers/net/hns3/hns3_rxtx.c | 61 +++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 38 deletions(-)
drivers/net/hns3/hns3_rxtx.c +23 -38
@@ -43,15 +43,19 @@ hns3_rx_queue_release_mbufs(struct hns3_rx_queue *rxq)if (rxq->rx_rearm_nb ==0 ) {for (i =0 ; i < rxq->nb_rx_desc; i++) { -if (rxq->sw_ring[i].mbuf !=NULL ) +if (rxq->sw_ring[i].mbuf !=NULL ) {rte_pktmbuf_free_seg (rxq->sw_ring[i].mbuf); + rxq->sw_ring[i].mbuf =NULL ; + } } }else {for (i = rxq->next_to_use; i != rxq->rx_rearm_start; i = (i +1 ) % rxq->nb_rx_desc) { -if (rxq->sw_ring[i].mbuf !=NULL ) +if (rxq->sw_ring[i].mbuf !=NULL ) {rte_pktmbuf_free_seg (rxq->sw_ring[i].mbuf); + rxq->sw_ring[i].mbuf =NULL ; + } } }
@@ -2368,37 +2372,24 @@ hns3_fill_first_desc(struct hns3_tx_queue *txq, struct hns3_desc *desc, } } -static int -hns3_tx_alloc_mbufs (struct hns3_tx_queue *txq,struct rte_mempool *mb_pool, -uint16_t nb_new_buf,struct rte_mbuf **alloc_mbuf) +static inline int +hns3_tx_alloc_mbufs (struct rte_mempool *mb_pool,uint16_t nb_new_buf, +struct rte_mbuf **alloc_mbuf) { -struct rte_mbuf *new_mbuf =NULL ; -struct rte_eth_dev *dev; -struct rte_mbuf *temp; -struct hns3_hw *hw; +#define MAX_NON_TSO_BD_PER_PKT 18 +struct rte_mbuf *pkt_segs[MAX_NON_TSO_BD_PER_PKT ];uint16_t i;/* Allocate enough mbufs */ -for (i =0 ; i < nb_new_buf; i++) { - temp =rte_pktmbuf_alloc (mb_pool); -if (unlikely (temp ==NULL )) { - dev = &rte_eth_devices[txq->port_id]; - hw =HNS3_DEV_PRIVATE_TO_HW (dev->data->dev_private); -hns3_err (hw,"Failed to alloc TX mbuf port_id=%d," -"queue_id=%d in reassemble tx pkts." , - txq->port_id, txq->queue_id); -rte_pktmbuf_free (new_mbuf); -return -ENOMEM ; - } - temp->next = new_mbuf; - new_mbuf = temp; - } - -if (new_mbuf ==NULL ) +if (rte_mempool_get_bulk (mb_pool, (void **)pkt_segs, nb_new_buf))return -ENOMEM ; - new_mbuf->nb_segs = nb_new_buf; - *alloc_mbuf = new_mbuf; +for (i =0 ; i < nb_new_buf -1 ; i++) + pkt_segs[i]->next = pkt_segs[i +1 ]; + + pkt_segs[nb_new_buf -1 ]->next =NULL ; + pkt_segs[0 ]->nb_segs = nb_new_buf; + *alloc_mbuf = pkt_segs[0 ];return 0 ; }
@@ -2418,10 +2409,8 @@ hns3_pktmbuf_copy_hdr(struct rte_mbuf *new_pkt, struct rte_mbuf *old_pkt) }static int -hns3_reassemble_tx_pkts (void *tx_queue,struct rte_mbuf *tx_pkt, -struct rte_mbuf **new_pkt) +hns3_reassemble_tx_pkts (struct rte_mbuf *tx_pkt,struct rte_mbuf **new_pkt) { -struct hns3_tx_queue *txq = tx_queue;struct rte_mempool *mb_pool;struct rte_mbuf *new_mbuf;struct rte_mbuf *temp_new;
@@ -2433,7 +2422,6 @@ hns3_reassemble_tx_pkts(void *tx_queue, struct rte_mbuf *tx_pkt,uint16_t len_s;uint16_t len_d;uint16_t len; -uint16_t i;int ret;char *s;char *d;
@@ -2449,7 +2437,7 @@ hns3_reassemble_tx_pkts(void *tx_queue, struct rte_mbuf *tx_pkt, last_buf_len = buf_size;/* Allocate enough mbufs */ - ret =hns3_tx_alloc_mbufs (txq, mb_pool, nb_new_buf, &new_mbuf); + ret =hns3_tx_alloc_mbufs (mb_pool, nb_new_buf, &new_mbuf);if (ret)return ret;
@@ -2458,12 +2446,9 @@ hns3_reassemble_tx_pkts(void *tx_queue, struct rte_mbuf *tx_pkt, s = rte_pktmbuf_mtod(temp, char *); len_s =rte_pktmbuf_data_len (temp); temp_new = new_mbuf; -for (i =0 ; i < nb_new_buf; i++) { +while (temp !=NULL && temp_new !=NULL ) { d = rte_pktmbuf_mtod(temp_new, char *); -if (i < nb_new_buf -1 ) - buf_len = buf_size; -else - buf_len = last_buf_len; + buf_len = temp_new->next ==NULL ? last_buf_len : buf_size; len_d = buf_len;while (len_d) {
@@ -2924,7 +2909,7 @@ hns3_check_non_tso_pkt(uint16_t nb_buf, struct rte_mbuf **m_seg,if (unlikely (nb_buf >HNS3_MAX_NON_TSO_BD_PER_PKT )) { txq->exceed_limit_bd_pkt_cnt++; - ret =hns3_reassemble_tx_pkts (txq, tx_pkt, &new_pkt); + ret =hns3_reassemble_tx_pkts (tx_pkt, &new_pkt);if (ret) { txq->exceed_limit_bd_reassem_fail++;return ret;
Signature · 1 line
2.9.5
v2 cover net/hns3: updates for Rx Tx
In reply to Wei Hu (Xavier)This series are updates for Rx/Tx process.
Chengchang Tang (1):
net/hns3: fix segfault when Tx multiple buffer packets
Wei Hu (Xavier) (7):
net/hns3: report Rx free threshold net/hns3: reduce address calculation in Rx net/hns3: add simple Rx process function net/hns3: add simple Tx process function net/hns3: add vector Tx burst with NEON instructions net/hns3: add vector Rx burst with NEON instructions net/hns3: add restriction on setting VF MTU
drivers/net/hns3/hns3_ethdev.c | 18 +- drivers/net/hns3/hns3_ethdev.h | 54 +- drivers/net/hns3/hns3_ethdev_vf.c | 41 +- drivers/net/hns3/hns3_rxtx.c | 1014 +++++++++++++++++++++++---------- drivers/net/hns3/hns3_rxtx.h | 237 +++++++- drivers/net/hns3/hns3_rxtx_vec.c | 214 +++++++ drivers/net/hns3/hns3_rxtx_vec.h | 77 +++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 288 ++++++++++ drivers/net/hns3/hns3_stats.c | 16 +- drivers/net/hns3/meson.build | 4 + 10 files changed, 1645 insertions(+), 318 deletions(-) create mode 100644 drivers/net/hns3/hns3_rxtx_vec.c create mode 100644 drivers/net/hns3/hns3_rxtx_vec.h create mode 100644 drivers/net/hns3/hns3_rxtx_vec_neon.h
Signature · 1 line
2.9.5
PATCH v2 1/8 net/hns3: report Rx free threshold
From: "Wei Hu (Xavier)" <[email protected]>
This patch reports .rx_free_thresh value in the .dev_infos_get ops implementation function named hns3_dev_infos_get and hns3vf_dev_infos_get. In addition, the name of the member variable of struct hns3_rx_queue is modified and comments are added to improve code readability.
--- drivers/net/hns3/hns3_ethdev.c | 2 ++ drivers/net/hns3/hns3_ethdev_vf.c | 2 ++ drivers/net/hns3/hns3_rxtx.c | 30 ++++++++++++------------------ drivers/net/hns3/hns3_rxtx.h | 9 ++++++--- 4 files changed, 22 insertions(+), 21 deletions(-)
drivers/net/hns3/hns3_ethdev.c +2 -0
@@ -2501,12 +2501,14 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) }; info->default_rxconf = (struct rte_eth_rxconf ) { + .rx_free_thresh =HNS3_DEFAULT_RX_FREE_THRESH ,/* * If there are no available Rx buffer descriptors, incoming * packets are always dropped by hardware based on hns3 network * engine. */ .rx_drop_en =1 , + .offloads =0 , }; info->vmdq_queue_num =0 ;
drivers/net/hns3/hns3_ethdev_vf.c +2 -0
@@ -944,12 +944,14 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) }; info->default_rxconf = (struct rte_eth_rxconf ) { + .rx_free_thresh =HNS3_DEFAULT_RX_FREE_THRESH ,/* * If there are no available Rx buffer descriptors, incoming * packets are always dropped by hardware based on hns3 network * engine. */ .rx_drop_en =1 , + .offloads =0 , }; info->vmdq_queue_num =0 ;
drivers/net/hns3/hns3_rxtx.c +12 -18
@@ -652,8 +652,7 @@ hns3_dev_rx_queue_start(struct hns3_adapter *hns, uint16_t idx) } rxq->next_to_use =0 ; - rxq->next_to_clean =0 ; - rxq->nb_rx_hold =0 ; + rxq->rx_free_hold =0 ;hns3_init_rx_queue_hw (rxq);return 0 ;
@@ -667,8 +666,7 @@ hns3_fake_rx_queue_start(struct hns3_adapter *hns, uint16_t idx) rxq = (struct hns3_rx_queue *)hw->fkq_data.rx_queues[idx]; rxq->next_to_use =0 ; - rxq->next_to_clean =0 ; - rxq->nb_rx_hold =0 ; + rxq->rx_free_hold =0 ;hns3_init_rx_queue_hw (rxq); }
@@ -1303,10 +1301,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, rxq->hns = hns; rxq->mb_pool = mp; -if (conf->rx_free_thresh <=0 ) - rxq->rx_free_thresh =DEFAULT_RX_FREE_THRESH ; -else - rxq->rx_free_thresh = conf->rx_free_thresh; + rxq->rx_free_thresh = (conf->rx_free_thresh >0 ) ? + conf->rx_free_thresh :HNS3_DEFAULT_RX_FREE_THRESH ; rxq->rx_deferred_start = conf->rx_deferred_start; rx_entry_len =sizeof (struct hns3_entry ) * rxq->nb_rx_desc;
@@ -1319,8 +1315,7 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, } rxq->next_to_use =0 ; - rxq->next_to_clean =0 ; - rxq->nb_rx_hold =0 ; + rxq->rx_free_hold =0 ; rxq->pkt_first_seg =NULL ; rxq->pkt_last_seg =NULL ; rxq->port_id = dev->data->port_id;
@@ -1656,11 +1651,11 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) nb_rx_bd =0 ; rxq = rx_queue; - rx_id = rxq->next_to_clean; + rx_id = rxq->next_to_use; rx_ring = rxq->rx_ring; + sw_ring = rxq->sw_ring; first_seg = rxq->pkt_first_seg; last_seg = rxq->pkt_last_seg; - sw_ring = rxq->sw_ring;while (nb_rx < nb_pkts) { rxdp = &rx_ring[rx_id];
@@ -1843,16 +1838,15 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) first_seg =NULL ; } - rxq->next_to_clean = rx_id; + rxq->next_to_use = rx_id; rxq->pkt_first_seg = first_seg; rxq->pkt_last_seg = last_seg; - nb_rx_bd = nb_rx_bd + rxq->nb_rx_hold; -if (nb_rx_bd > rxq->rx_free_thresh) { -hns3_clean_rx_buffers (rxq, nb_rx_bd); - nb_rx_bd =0 ; + rxq->rx_free_hold += nb_rx_bd; +if (rxq->rx_free_hold > rxq->rx_free_thresh) { +hns3_clean_rx_buffers (rxq, rxq->rx_free_hold); + rxq->rx_free_hold =0 ; } - rxq->nb_rx_hold = nb_rx_bd;return nb_rx; }
drivers/net/hns3/hns3_rxtx.h +6 -3
@@ -10,6 +10,7 @@#define HNS3_DEFAULT_RING_DESC 1024#define HNS3_ALIGN_RING_DESC 32#define HNS3_RING_BASE_ALIGN 128 +#define HNS3_DEFAULT_RX_FREE_THRESH 32#define HNS3_512_BD_BUF_SIZE 512#define HNS3_1K_BD_BUF_SIZE 1024
@@ -243,12 +244,14 @@ struct hns3_rx_queue {uint16_t queue_id;uint16_t port_id;uint16_t nb_rx_desc; -uint16_t nb_rx_hold; -uint16_t rx_tail; -uint16_t next_to_clean;uint16_t next_to_use;uint16_t rx_buf_len; +/* +* threshold for the number of BDs waited to passed to hardware. If the +* number exceeds the threshold, driver will pass these BDs to hardware. +*/ uint16_t rx_free_thresh; +uint16_t rx_free_hold;/* num of BDs waited to passed to hardware */ /* * port based vlan configuration state.
Signature · 1 line
2.9.5
PATCH v2 2/8 net/hns3: reduce address calculation in Rx
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds the internal function named hns3_write_reg_opt to avoid performance loss from address calculation during register access in the '.rx_pkt_burst' ops implementation function named hns3_recv_pkts.
In addition, because hardware always access register in little-endian mode based on hns3 network engine, so driver should also call rte_cpu_to_le_32 to convert data in little-endian mode before writing register and call rte_le_to_cpu_32 to convert data after reading from register. Here the driver encapsulates the data conversion operation in the register read/write operation function as below:
hns3_write_reg
hns3_write_reg_opt
hns3_read_reg
Therefore, when calling these functions, conversion is not required again.
--- drivers/net/hns3/hns3_ethdev.h | 29 +++++++++++++++++++++++++++-- drivers/net/hns3/hns3_rxtx.c | 14 +++----------- drivers/net/hns3/hns3_rxtx.h | 1 + 3 files changed, 31 insertions(+), 13 deletions(-)
drivers/net/hns3/hns3_ethdev.h +27 -2
@@ -708,14 +708,39 @@ struct hns3_adapter {#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +/* +* Because hardware always access register in little-endian mode based on hns3 +* network engine, so driver should also call rte_cpu_to_le_32 to convert data +* in little-endian mode before writing register and call rte_le_to_cpu_32 to +* convert data after reading from register. +* +* Here the driver encapsulates the data conversion operation in the register +* read/write operation function as below: +* hns3_write_reg +* hns3_write_reg_opt +* hns3_read_reg +* Therefore, when calling these functions, conversion is not required again. +*/ static inline void hns3_write_reg (void *base,uint32_t reg,uint32_t value) { -rte_write32 (value, (volatile void *)((char *)base + reg)); +rte_write32 (rte_cpu_to_le_32 (value), + (volatile void *)((char *)base + reg)); +} + +/* +* The optimized function for writing registers used in the '.rx_pkt_burst' and +* '.tx_pkt_burst' ops implementation function. +*/ +static inline void hns3_write_reg_opt (volatile void *addr,uint32_t value) +{ +rte_io_wmb (); +rte_write32_relaxed (rte_cpu_to_le_32 (value), addr); }static inline uint32_t hns3_read_reg (void *base,uint32_t reg) { -return rte_read32 ((volatile void *)((char *)base + reg)); +uint32_t read_val =rte_read32 ((volatile void *)((char *)base + reg)); +return rte_le_to_cpu_32 (read_val); }#define hns3_write_dev (a, reg, value) \
drivers/net/hns3/hns3_rxtx.c +3 -11
@@ -1323,6 +1323,8 @@ hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, rxq->configured = true; rxq->io_base = (void *)((char *)hw->io_base +HNS3_TQP_REG_OFFSET + idx *HNS3_TQP_REG_SIZE ); + rxq->io_head_reg = (volatile void *)((char *)rxq->io_base + +HNS3_RING_RX_HEAD_REG ); rxq->rx_buf_len = rx_buf_size; rxq->l2_errors =0 ; rxq->pkt_len_errors =0 ;
@@ -1472,16 +1474,6 @@ hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev)return NULL ; } -static void -hns3_clean_rx_buffers (struct hns3_rx_queue *rxq,int count) -{ - rxq->next_to_use += count; -if (rxq->next_to_use >= rxq->nb_rx_desc) - rxq->next_to_use -= rxq->nb_rx_desc; - -hns3_write_dev (rxq,HNS3_RING_RX_HEAD_REG , count); -} - static int hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm, uint32_t bd_base_info, uint32_t l234_info,
@@ -1844,7 +1836,7 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) rxq->rx_free_hold += nb_rx_bd;if (rxq->rx_free_hold > rxq->rx_free_thresh) { -hns3_clean_rx_buffers (rxq, rxq->rx_free_hold); +hns3_write_reg_opt (rxq->io_head_reg, rxq->rx_free_hold); rxq->rx_free_hold =0 ; }
drivers/net/hns3/hns3_rxtx.h +1 -0
@@ -231,6 +231,7 @@ struct hns3_entry {struct hns3_rx_queue {void *io_base; +volatile void *io_head_reg;struct hns3_adapter *hns;struct rte_mempool *mb_pool;struct hns3_desc *rx_ring;
Signature · 1 line
2.9.5
PATCH v2 3/8 net/hns3: add simple Rx process function
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds simple Rx process function and support chose Rx function by real Rx offloads capability.
--- drivers/net/hns3/hns3_ethdev.c | 7 +- drivers/net/hns3/hns3_ethdev.h | 21 ++ drivers/net/hns3/hns3_ethdev_vf.c | 11 +- drivers/net/hns3/hns3_rxtx.c | 546 +++++++++++++++++++++++--------------- drivers/net/hns3/hns3_rxtx.h | 140 +++++++++- drivers/net/hns3/hns3_stats.c | 16 +- 6 files changed, 506 insertions(+), 235 deletions(-)
drivers/net/hns3/hns3_ethdev.c +6 -1
@@ -2351,6 +2351,8 @@ hns3_dev_configure(struct rte_eth_dev *dev)if (ret) goto cfg_err; + hns->rx_simple_allowed = true; +hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;return 0 ;
@@ -4746,6 +4748,7 @@ hns3_dev_start(struct rte_eth_dev *dev) hw->adapter_state =HNS3_NIC_STARTED ;rte_spinlock_unlock (&hw->lock); +hns3_rx_scattered_calc (dev);hns3_set_rxtx_function (dev);hns3_mp_req_start_rxtx (dev);rte_eal_alarm_set (HNS3_SERVICE_INTERVAL , hns3_service_handler, dev);
@@ -4844,6 +4847,7 @@ hns3_dev_stop(struct rte_eth_dev *dev)hns3_dev_release_mbufs (hns); hw->adapter_state =HNS3_NIC_CONFIGURED ; } +hns3_rx_scattered_reset (dev);rte_eal_alarm_cancel (hns3_service_handler, dev);rte_spinlock_unlock (&hw->lock); }
@@ -5514,6 +5518,7 @@ hns3_reset_service(void *param) }static const struct eth_dev_ops hns3_eth_dev_ops = { + .dev_configure = hns3_dev_configure, .dev_start = hns3_dev_start, .dev_stop = hns3_dev_stop, .dev_close = hns3_dev_close,
@@ -5539,7 +5544,7 @@ static const struct eth_dev_ops hns3_eth_dev_ops = { .rx_queue_intr_disable = hns3_dev_rx_queue_intr_disable, .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, - .dev_configure = hns3_dev_configure, + .rx_burst_mode_get = hns3_rx_burst_mode_get, .flow_ctrl_get = hns3_flow_ctrl_get, .flow_ctrl_set = hns3_flow_ctrl_set, .priority_flow_ctrl_set = hns3_priority_flow_ctrl_set,
drivers/net/hns3/hns3_ethdev.h +21 -0
@@ -433,6 +433,7 @@ struct hns3_hw {uint16_t tqps_num;/* num task queue pairs of this function */ uint16_t intr_tqps_num;/* num queue pairs mapping interrupt */ uint16_t rss_size_max;/* HW defined max RSS task queue */ +uint16_t rx_buf_len;/* hold min hardware rx buf len */ uint16_t num_tx_desc;/* desc num of per tx queue */ uint16_t num_rx_desc;/* desc num of per rx queue */ uint32_t mng_entry_num;/* number of manager table entry */
@@ -575,6 +576,23 @@ struct hns3_mp_param {/* Key string for IPC. */ #define HNS3_MP_NAME "net_hns3_mp" +#define HNS3_L2TBL_NUM 4 +#define HNS3_L3TBL_NUM 16 +#define HNS3_L4TBL_NUM 16 +#define HNS3_OL3TBL_NUM 16 +#define HNS3_OL4TBL_NUM 16 + +struct hns3_ptype_table { +uint32_t l2table[HNS3_L2TBL_NUM ]; +uint32_t l3table[HNS3_L3TBL_NUM ]; +uint32_t l4table[HNS3_L4TBL_NUM ]; +uint32_t inner_l2table[HNS3_L2TBL_NUM ]; +uint32_t inner_l3table[HNS3_L3TBL_NUM ]; +uint32_t inner_l4table[HNS3_L4TBL_NUM ]; +uint32_t ol3table[HNS3_OL3TBL_NUM ]; +uint32_t ol4table[HNS3_OL4TBL_NUM ]; +}; +struct hns3_pf {struct hns3_adapter *adapter;bool is_main_pf;
@@ -623,6 +641,9 @@ struct hns3_adapter {struct hns3_pf pf;struct hns3_vf vf; }; + +bool rx_simple_allowed; + struct hns3_ptype_table ptype_tbl __rte_cache_min_aligned; };#define HNS3_DEV_SUPPORT_DCB_B 0x0
drivers/net/hns3/hns3_ethdev_vf.c +9 -2
@@ -745,7 +745,8 @@ hns3vf_init_ring_with_vector(struct hns3_hw *hw)static int hns3vf_dev_configure (struct rte_eth_dev *dev) { -struct hns3_hw *hw =HNS3_DEV_PRIVATE_TO_HW (dev->data->dev_private); +struct hns3_adapter *hns = dev->data->dev_private; +struct hns3_hw *hw = &hns->hw;struct hns3_rss_conf *rss_cfg = &hw->rss_info;struct rte_eth_conf *conf = &dev->data->dev_conf;enum rte_eth_rx_mq_mode mq_mode = conf->rxmode.mq_mode;
@@ -820,6 +821,9 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)if (ret) goto cfg_err; + hns->rx_simple_allowed = true; +hns3_init_rx_ptype_tble (dev); + hw->adapter_state =HNS3_NIC_CONFIGURED ;return 0 ;
@@ -1875,6 +1879,7 @@ hns3vf_dev_stop(struct rte_eth_dev *dev)hns3_dev_release_mbufs (hns); hw->adapter_state =HNS3_NIC_CONFIGURED ; } +hns3_rx_scattered_reset (dev);rte_eal_alarm_cancel (hns3vf_service_handler, dev);rte_spinlock_unlock (&hw->lock); }
@@ -2111,6 +2116,7 @@ hns3vf_dev_start(struct rte_eth_dev *dev) hw->adapter_state =HNS3_NIC_STARTED ;rte_spinlock_unlock (&hw->lock); +hns3_rx_scattered_calc (dev);hns3_set_rxtx_function (dev);hns3_mp_req_start_rxtx (dev);rte_eal_alarm_set (HNS3VF_SERVICE_INTERVAL , hns3vf_service_handler, dev);
@@ -2508,6 +2514,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns) }static const struct eth_dev_ops hns3vf_eth_dev_ops = { + .dev_configure = hns3vf_dev_configure, .dev_start = hns3vf_dev_start, .dev_stop = hns3vf_dev_stop, .dev_close = hns3vf_dev_close,
@@ -2533,7 +2540,7 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = { .rx_queue_intr_disable = hns3_dev_rx_queue_intr_disable, .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, - .dev_configure = hns3vf_dev_configure, + .rx_burst_mode_get = hns3_rx_burst_mode_get, .mac_addr_add = hns3vf_add_mac_addr, .mac_addr_remove = hns3vf_remove_mac_addr, .mac_addr_set = hns3vf_set_default_mac_addr,
drivers/net/hns3/hns3_rxtx.c +328 -218
729 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx.h +134 -6
199 lines not on this page · raw message
drivers/net/hns3/hns3_stats.c +8 -8
@@ -271,13 +271,13 @@ static const struct hns3_xstats_name_offset hns3_rx_bd_error_strings[] = { {"L2_RX_ERRORS" , HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l2_errors)}, {"RX_L3_CHECKSUM_ERRORS", - HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l3_csum_erros)}, + HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l3_csum_errors)}, {"RX_L4_CHECKSUM_ERRORS", - HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l4_csum_erros)}, + HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l4_csum_errors)}, {"RX_OL3_CHECKSUM_ERRORS", - HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(ol3_csum_erros)}, + HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(ol3_csum_errors)}, {"RX_OL4_CHECKSUM_ERRORS", - HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(ol4_csum_erros)} + HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(ol4_csum_errors)} };/* The statistic of the Tx errors */
@@ -594,10 +594,10 @@ hns3_stats_reset(struct rte_eth_dev *eth_dev)if (rxq) { rxq->pkt_len_errors =0 ; rxq->l2_errors =0 ; - rxq->l3_csum_erros =0 ; - rxq->l4_csum_erros =0 ; - rxq->ol3_csum_erros =0 ; - rxq->ol4_csum_erros =0 ; + rxq->l3_csum_errors =0 ; + rxq->l4_csum_errors =0 ; + rxq->ol3_csum_errors =0 ; + rxq->ol4_csum_errors =0 ; } }
Signature · 1 line
2.9.5
PATCH v2 4/8 net/hns3: add simple Tx process function
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds simple Tx process function. When multiple segment packets are not needed, Which means that DEV_TX_OFFLOAD_MBUF_FAST_FREE offload is not set, we can simple Tx process.
--- drivers/net/hns3/hns3_ethdev.c | 6 + drivers/net/hns3/hns3_ethdev.h | 1 + drivers/net/hns3/hns3_ethdev_vf.c | 6 + drivers/net/hns3/hns3_rxtx.c | 260 +++++++++++++++++++++++++++++++++++--- drivers/net/hns3/hns3_rxtx.h | 34 +++++ 5 files changed, 292 insertions(+), 15 deletions(-)
drivers/net/hns3/hns3_ethdev.c +6 -0
@@ -2352,6 +2352,7 @@ hns3_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->tx_simple_allowed = true;hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
@@ -2512,6 +2513,10 @@ hns3_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) .rx_drop_en = 1, .offloads = 0, }; + info->default_txconf = (struct rte_eth_txconf ) { + .tx_rs_thresh =HNS3_DEFAULT_TX_RS_THRESH , + .offloads =0 , + }; info->vmdq_queue_num =0 ;
@@ -5545,6 +5550,7 @@ static const struct eth_dev_ops hns3_eth_dev_ops = { .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, .rx_burst_mode_get = hns3_rx_burst_mode_get, + .tx_burst_mode_get = hns3_tx_burst_mode_get, .flow_ctrl_get = hns3_flow_ctrl_get, .flow_ctrl_set = hns3_flow_ctrl_set, .priority_flow_ctrl_set = hns3_priority_flow_ctrl_set,
drivers/net/hns3/hns3_ethdev.h +1 -0
@@ -643,6 +643,7 @@ struct hns3_adapter { };bool rx_simple_allowed; +bool tx_simple_allowed; struct hns3_ptype_table ptype_tbl __rte_cache_min_aligned; };
drivers/net/hns3/hns3_ethdev_vf.c +6 -0
@@ -822,6 +822,7 @@ hns3vf_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->tx_simple_allowed = true;hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
@@ -957,6 +958,10 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info) .rx_drop_en = 1, .offloads = 0, }; + info->default_txconf = (struct rte_eth_txconf ) { + .tx_rs_thresh =HNS3_DEFAULT_TX_RS_THRESH , + .offloads =0 , + }; info->vmdq_queue_num =0 ;
@@ -2541,6 +2546,7 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = { .rxq_info_get = hns3_rxq_info_get, .txq_info_get = hns3_txq_info_get, .rx_burst_mode_get = hns3_rx_burst_mode_get, + .tx_burst_mode_get = hns3_tx_burst_mode_get, .mac_addr_add = hns3vf_add_mac_addr, .mac_addr_remove = hns3vf_remove_mac_addr, .mac_addr_set = hns3vf_set_default_mac_addr,
drivers/net/hns3/hns3_rxtx.c +245 -15
329 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx.h +34 -0
@@ -13,6 +13,9 @@#define HNS3_BULK_ALLOC_MBUF_NUM 32#define HNS3_DEFAULT_RX_FREE_THRESH 32 +#define HNS3_DEFAULT_TX_FREE_THRESH 32 +#define HNS3_DEFAULT_TX_RS_THRESH 32 +#define HNS3_TX_FAST_FREE_AHEAD 64#define HNS3_512_BD_BUF_SIZE 512#define HNS3_1K_BD_BUF_SIZE 1024
@@ -282,6 +285,7 @@ struct hns3_rx_queue {struct hns3_tx_queue {void *io_base; +volatile void *io_tail_reg;struct hns3_adapter *hns;struct hns3_desc *tx_ring;uint64_t tx_ring_phys_addr;/* TX ring DMA address */
@@ -291,10 +295,32 @@ struct hns3_tx_queue {uint16_t queue_id;uint16_t port_id;uint16_t nb_tx_desc; +/* +* index of next BD whose corresponding rte_mbuf can be released by +* driver. +*/ uint16_t next_to_clean; +/* index of next BD to be filled by driver to send packet */ uint16_t next_to_use; +/* num of remaining BDs ready to be filled by driver to send packet */ uint16_t tx_bd_ready; +/* threshold for free tx buffer if available BDs less than this value */ +uint16_t tx_free_thresh; + +/* +* For better performance in tx datapath, releasing mbuf in batches is +* required. +* Only checking the VLD bit of the last descriptor in a batch of the +* thresh descriptors does not mean that these descriptors are all sent +* by hardware successfully. So we need to check that the VLD bits of +* all descriptors are cleared. and then free all mbufs in the batch. +* - tx_rs_thresh +* Number of mbufs released at a time. + +*/ +uint16_t tx_rs_thresh; +/* * port based vlan configuration state. * value range: HNS3_PORT_BASE_VLAN_DISABLE / HNS3_PORT_BASE_VLAN_ENABLE
@@ -360,6 +386,9 @@ struct hns3_tx_queue {uint64_t pkt_padding_fail_cnt; }; +#define HNS3_GET_TX_QUEUE_PEND_BD_NUM (txq) \ + ((txq)->nb_tx_desc - 1 - (txq)->tx_bd_ready) +struct hns3_queue_info {const char *type;/* point to queue memory name */ const char *ring_name;/* point to hardware ring name */
@@ -525,8 +554,13 @@ int hns3_rx_burst_mode_get(struct rte_eth_dev *dev, struct rte_eth_burst_mode *mode); uint16_t hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t hns3_xmit_pkts_simple (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);uint16_t hns3_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +int hns3_tx_burst_mode_get (struct rte_eth_dev *dev, + __rte_unused uint16_t queue_id, +struct rte_eth_burst_mode *mode);const uint32_t *hns3_dev_supported_ptypes_get (struct rte_eth_dev *dev);void hns3_init_rx_ptype_tble (struct rte_eth_dev *dev);void hns3_set_rxtx_function (struct rte_eth_dev *eth_dev);
Signature · 1 line
2.9.5
PATCH v2 5/8 net/hns3: add vector Tx burst with NEON instructions
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds NEON vector instructions to optimize Tx burst process.
---
v1 -> v2: modification about meson.build for hns3_rxtx_vec.c file.
--- drivers/net/hns3/hns3_ethdev.c | 2 + drivers/net/hns3/hns3_ethdev.h | 2 + drivers/net/hns3/hns3_ethdev_vf.c | 2 + drivers/net/hns3/hns3_rxtx.c | 33 ++++++++++++++ drivers/net/hns3/hns3_rxtx.h | 20 ++++++++- drivers/net/hns3/hns3_rxtx_vec.c | 47 +++++++++++++++++++ drivers/net/hns3/hns3_rxtx_vec.h | 57 +++++++++++++++++++++++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 85 +++++++++++++++++++++++++++++++++++ drivers/net/hns3/meson.build | 4 ++ 9 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 drivers/net/hns3/hns3_rxtx_vec.c create mode 100644 drivers/net/hns3/hns3_rxtx_vec.h create mode 100644 drivers/net/hns3/hns3_rxtx_vec_neon.h
drivers/net/hns3/hns3_ethdev.c +2 -0
@@ -2353,6 +2353,8 @@ hns3_dev_configure(struct rte_eth_dev *dev) hns->rx_simple_allowed = true; hns->tx_simple_allowed = true; + hns->tx_vec_allowed = true; +hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
drivers/net/hns3/hns3_ethdev.h +2 -0
@@ -644,6 +644,8 @@ struct hns3_adapter {bool rx_simple_allowed;bool tx_simple_allowed; +bool tx_vec_allowed; + struct hns3_ptype_table ptype_tbl __rte_cache_min_aligned; };
drivers/net/hns3/hns3_ethdev_vf.c +2 -0
@@ -823,6 +823,8 @@ hns3vf_dev_configure(struct rte_eth_dev *dev) hns->rx_simple_allowed = true; hns->tx_simple_allowed = true; + hns->tx_vec_allowed = true; +hns3_init_rx_ptype_tble (dev); hw->adapter_state =HNS3_NIC_CONFIGURED ;
drivers/net/hns3/hns3_rxtx.c +33 -0
@@ -95,6 +95,8 @@ hns3_tx_queue_release(void *queue)rte_memzone_free (txq->mz);if (txq->sw_ring)rte_free (txq->sw_ring); +if (txq->free) +rte_free (txq->free);rte_free (txq); } }
@@ -1020,6 +1022,7 @@ hns3_fake_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,/* Don't need alloc sw_ring, because upper applications don't use it */ txq->sw_ring =NULL ; + txq->free =NULL ; txq->hns = hns; txq->tx_deferred_start = false;
@@ -2052,6 +2055,15 @@ hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, txq->tx_bd_ready = txq->nb_tx_desc -1 ; txq->tx_free_thresh = tx_free_thresh; txq->tx_rs_thresh = tx_rs_thresh; + txq->free =rte_zmalloc_socket ("hns3 TX mbuf free array" , +sizeof (struct rte_mbuf *) * txq->tx_rs_thresh, +RTE_CACHE_LINE_SIZE , socket_id); +if (!txq->free) { +hns3_err (hw,"failed to allocate tx mbuf free array!" ); +hns3_tx_queue_release (txq); +return -ENOMEM ; + } + txq->port_id = dev->data->port_id; txq->pvid_state = hw->port_base_vlan_cfg.state; txq->configured = true;
@@ -3105,6 +3117,20 @@ hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)return nb_tx; } +int __rte_weak +hns3_tx_check_vec_support(__rte_unused struct rte_eth_dev *dev) +{ +return -ENOTSUP ; +} + +uint16_t __rte_weak +hns3_xmit_pkts_vec(__rte_unused void *tx_queue, + __rte_unused struct rte_mbuf **tx_pkts, + __rte_unused uint16_t nb_pkts) +{ +return 0 ; +} +int hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,struct rte_eth_burst_mode *mode)
@@ -3116,6 +3142,8 @@ hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id, info ="Scalar Simple" ; else if (pkt_burst == hns3_xmit_pkts) info ="Scalar" ; + else if (pkt_burst == hns3_xmit_pkts_vec) + info ="Vector Neon" ;if (info ==NULL )return -EINVAL ;
@@ -3131,6 +3159,11 @@ hns3_get_tx_function(struct rte_eth_dev *dev, eth_tx_prep_t *prep)uint64_t offloads = dev->data->dev_conf.txmode.offloads;struct hns3_adapter *hns = dev->data->dev_private; +if (hns->tx_vec_allowed &&hns3_tx_check_vec_support (dev) ==0 ) { + *prep =NULL ; +return hns3_xmit_pkts_vec; + } +if (hns->tx_simple_allowed && offloads == (offloads &DEV_TX_OFFLOAD_MBUF_FAST_FREE )) { *prep =NULL ;
drivers/net/hns3/hns3_rxtx.h +19 -1
@@ -17,6 +17,10 @@#define HNS3_DEFAULT_TX_RS_THRESH 32#define HNS3_TX_FAST_FREE_AHEAD 64 +#define HNS3_UINT8_BIT 8 +#define HNS3_UINT16_BIT 16 +#define HNS3_UINT32_BIT 32 +#define HNS3_512_BD_BUF_SIZE 512#define HNS3_1K_BD_BUF_SIZE 1024#define HNS3_2K_BD_BUF_SIZE 2048
@@ -132,6 +136,13 @@#define HNS3_L3_LEN_UNIT 2UL#define HNS3_L4_LEN_UNIT 2UL +#define HNS3_TXD_DEFAULT_BDTYPE 0 +#define HNS3_TXD_VLD_CMD (0x1 << HNS3_TXD_VLD_B) +#define HNS3_TXD_FE_CMD (0x1 << HNS3_TXD_FE_B) +#define HNS3_TXD_DEFAULT_VLD_FE_BDTYPE \ + (HNS3_TXD_VLD_CMD | HNS3_TXD_FE_CMD | HNS3_TXD_DEFAULT_BDTYPE) +#define HNS3_TXD_SEND_SIZE_SHIFT 16 +enum hns3_pkt_l2t_type {HNS3_L2_TYPE_UNICAST ,HNS3_L2_TYPE_MULTICAST ,
@@ -317,9 +328,13 @@ struct hns3_tx_queue {* all descriptors are cleared. and then free all mbufs in the batch. * - tx_rs_thresh * Number of mbufs released at a time. - +* +* - free +* Tx mbuf free array used for preserving temporarily address of mbuf +* released back to mempool, when releasing mbuf in batches. */ uint16_t tx_rs_thresh; +struct rte_mbuf **free;/* * port based vlan configuration state.
@@ -558,6 +573,8 @@ uint16_t hns3_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);uint16_t hns3_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); +uint16_t hns3_xmit_pkts_vec (void *tx_queue,struct rte_mbuf **tx_pkts, +uint16_t nb_pkts);int hns3_tx_burst_mode_get (struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,struct rte_eth_burst_mode *mode);
@@ -577,6 +594,7 @@ int hns3_restore_gro_conf(struct hns3_hw *hw);void hns3_update_all_queues_pvid_state (struct hns3_hw *hw);void hns3_rx_scattered_reset (struct rte_eth_dev *dev);void hns3_rx_scattered_calc (struct rte_eth_dev *dev); +int hns3_tx_check_vec_support (struct rte_eth_dev *dev);void hns3_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_rxq_info *qinfo); void hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/hns3/hns3_rxtx_vec.c new file +47 -0
47 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx_vec.h new file +57 -0
57 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx_vec_neon.h new file +85 -0
85 lines not on this page · raw message
drivers/net/hns3/meson.build +4 -0
@@ -28,3 +28,7 @@ sources = files('hns3_cmd.c', 'hns3_mp.c') deps += ['hash'] + +if arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64') + sources += files('hns3_rxtx_vec.c') +endif
Signature · 1 line
2.9.5
PATCH v2 6/8 net/hns3: add vector Rx burst with NEON instructions
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
This patch adds NEON vector instructions to optimize Rx burst process.
--- drivers/net/hns3/hns3_ethdev.c | 1 + drivers/net/hns3/hns3_ethdev.h | 1 + drivers/net/hns3/hns3_ethdev_vf.c | 1 + drivers/net/hns3/hns3_rxtx.c | 94 +++++++++++++++- drivers/net/hns3/hns3_rxtx.h | 35 +++++- drivers/net/hns3/hns3_rxtx_vec.c | 167 ++++++++++++++++++++++++++++ drivers/net/hns3/hns3_rxtx_vec.h | 20 ++++ drivers/net/hns3/hns3_rxtx_vec_neon.h | 203 ++++++++++++++++++++++++++++++++++ 8 files changed, 514 insertions(+), 8 deletions(-)
drivers/net/hns3/hns3_ethdev.c +1 -0
@@ -2352,6 +2352,7 @@ hns3_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->rx_vec_allowed = true; hns->tx_simple_allowed = true; hns->tx_vec_allowed = true;
drivers/net/hns3/hns3_ethdev.h +1 -0
@@ -643,6 +643,7 @@ struct hns3_adapter { };bool rx_simple_allowed; +bool rx_vec_allowed;bool tx_simple_allowed;bool tx_vec_allowed;
drivers/net/hns3/hns3_ethdev_vf.c +1 -0
@@ -822,6 +822,7 @@ hns3vf_dev_configure(struct rte_eth_dev *dev) goto cfg_err; hns->rx_simple_allowed = true; + hns->rx_vec_allowed = true; hns->tx_simple_allowed = true; hns->tx_vec_allowed = true;
drivers/net/hns3/hns3_rxtx.c +88 -6
164 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx.h +33 -2
@@ -17,6 +17,18 @@#define HNS3_DEFAULT_TX_RS_THRESH 32#define HNS3_TX_FAST_FREE_AHEAD 64 +#define HNS3_DEFAULT_RX_BURST 32 +#if (HNS3_DEFAULT_RX_BURST >64 ) +#error "PMD HNS3: HNS3_DEFAULT_RX_BURST must <= 64\n" +#endif +#define HNS3_DEFAULT_DESCS_PER_LOOP 4 +#define HNS3_SVE_DEFAULT_DESCS_PER_LOOP 8 +#if (HNS3_DEFAULT_DESCS_PER_LOOP >HNS3_SVE_DEFAULT_DESCS_PER_LOOP ) +#define HNS3_VECTOR_RX_OFFSET_TABLE_LEN HNS3_DEFAULT_DESCS_PER_LOOP +#else +#define HNS3_VECTOR_RX_OFFSET_TABLE_LEN HNS3_SVE_DEFAULT_DESCS_PER_LOOP +#endif +#define HNS3_DEFAULT_RXQ_REARM_THRESH 64#define HNS3_UINT8_BIT 8#define HNS3_UINT16_BIT 16#define HNS3_UINT32_BIT 32
@@ -236,7 +248,13 @@ struct hns3_desc {uint16_t ot_vlan_tag; }; }; -uint32_t bd_base_info; +union { +uint32_t bd_base_info; +struct { +uint16_t bdtype_vld_udp0; +uint16_t fe_lum_crcp_l3l4p; + }; + }; } rx; }; } __rte_packed;
@@ -270,7 +288,8 @@ struct hns3_rx_queue {uint16_t rx_free_thresh;uint16_t next_to_use;/* index of next BD to be polled */ uint16_t rx_free_hold;/* num of BDs waited to passed to hardware */ - +uint16_t rx_rearm_start;/* index of BD that driver re-arming from */ +uint16_t rx_rearm_nb;/* number of remaining BDs to be re-armed */ /* * port based vlan configuration state. * value range: HNS3_PORT_BASE_VLAN_DISABLE / HNS3_PORT_BASE_VLAN_ENABLE
@@ -292,6 +311,11 @@ struct hns3_rx_queue {struct rte_mbuf *bulk_mbuf[HNS3_BULK_ALLOC_MBUF_NUM ];uint16_t bulk_mbuf_num; + +/* offset_table: used for vector, to solve execute re-order problem */ +uint8_t offset_table[HNS3_VECTOR_RX_OFFSET_TABLE_LEN +1 ]; +uint64_t mbuf_initializer;/* value to init mbufs used with vector rx */ +struct rte_mbuf fake_mbuf;/* fake mbuf used with vector rx */ };struct hns3_tx_queue {
@@ -554,6 +578,8 @@ int hns3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);void hns3_enable_all_queues (struct hns3_hw *hw,bool en);int hns3_start_queues (struct hns3_adapter *hns,bool reset_queue);int hns3_stop_queues (struct hns3_adapter *hns,bool reset_queue); +int hns3_rxq_iterate (struct rte_eth_dev *dev, +int (*callback)(struct hns3_rx_queue *,void *),void *arg);void hns3_dev_release_mbufs (struct hns3_adapter *hns); int hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc, unsigned int socket, const struct rte_eth_rxconf *conf,
@@ -564,9 +590,12 @@ uint16_t hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts);uint16_t hns3_recv_scattered_pkts (void *rx_queue,struct rte_mbuf **rx_pkts,uint16_t nb_pkts); +uint16_t hns3_recv_pkts_vec (void *rx_queue,struct rte_mbuf **rx_pkts, +uint16_t nb_pkts);int hns3_rx_burst_mode_get (struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,struct rte_eth_burst_mode *mode); +int hns3_rx_check_vec_support (struct rte_eth_dev *dev); uint16_t hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,uint16_t nb_pkts); uint16_t hns3_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
@@ -594,7 +623,9 @@ int hns3_restore_gro_conf(struct hns3_hw *hw);void hns3_update_all_queues_pvid_state (struct hns3_hw *hw);void hns3_rx_scattered_reset (struct rte_eth_dev *dev);void hns3_rx_scattered_calc (struct rte_eth_dev *dev); +int hns3_rx_check_vec_support (struct rte_eth_dev *dev);int hns3_tx_check_vec_support (struct rte_eth_dev *dev); +void hns3_rxq_vec_setup (struct hns3_rx_queue *rxq);void hns3_rxq_info_get (struct rte_eth_dev *dev,uint16_t queue_id,struct rte_eth_rxq_info *qinfo); void hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
drivers/net/hns3/hns3_rxtx_vec.c +167 -0
170 lines not on this page · raw message
drivers/net/hns3/hns3_rxtx_vec.h +20 -0
@@ -54,4 +54,24 @@ hns3_tx_free_buffers(struct hns3_tx_queue *txq)if (txq->next_to_clean >= txq->nb_tx_desc) txq->next_to_clean = 0; } + +static inline uint16_t +hns3_rx_reassemble_pkts (struct rte_mbuf **rx_pkts, +uint16_t nb_pkts, +uint64_t pkt_err_mask) +{ +uint16_t count, i; +uint64_t mask; + + count =0 ; +for (i =0 ; i < nb_pkts; i++) { + mask = ((uint64_t )1u ) << i; +if (pkt_err_mask & mask) +rte_pktmbuf_free_seg (rx_pkts[i]); +else + rx_pkts[count++] = rx_pkts[i]; + } + +return count; +}#endif /* _HNS3_RXTX_VEC_H_ */
drivers/net/hns3/hns3_rxtx_vec_neon.h +203 -0
207 lines not on this page · raw message
Signature · 1 line
2.9.5
PATCH v2 7/8 net/hns3: add restriction on setting VF MTU
In reply to Wei Hu (Xavier)From: "Wei Hu (Xavier)" <[email protected]>
when Rx of scattered packets is off, we have some possibility of using vector Rx process function or simple Rx functions in hns3 PMD driver. If the input MTU is increased and the maximum length of received packets is greater than the length of a buffer for Rx packets, the hardware network engine needs to use multiple BDs and buffers to store these packets. This will cause problems when still using vector Rx process function or simple Rx function to receiving packets. So, when Rx of scattered packets is off and device is started, it is not permitted to increase MTU so that the maximum length of Rx packets is greater than Rx buffer length.
--- drivers/net/hns3/hns3_ethdev_vf.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/net/hns3/hns3_ethdev_vf.c +19 -0
@@ -871,6 +871,25 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)return -EIO ; } +/* +* when Rx of scattered packets is off, we have some possibility of +* using vector Rx process function or simple Rx functions in hns3 PMD +* driver. If the input MTU is increased and the maximum length of +* received packets is greater than the length of a buffer for Rx +* packet, the hardware network engine needs to use multiple BDs and +* buffers to store these packets. This will cause problems when still +* using vector Rx process function or simple Rx function to receiving +* packets. So, when Rx of scattered packets is off and device is +* started, it is not permitted to increase MTU so that the maximum +* length of Rx packets is greater than Rx buffer length. +*/ +if (dev->data->dev_started && !dev->data->scattered_rx && + frame_size > hw->rx_buf_len) { +hns3_err (hw,"failed to set mtu because current is " +"not scattered rx mode" ); +return -EOPNOTSUPP ; + } +rte_spinlock_lock (&hw->lock); ret =hns3vf_config_mtu (hw, mtu);if (ret) {
Signature · 1 line
2.9.5
PATCH v2 8/8 net/hns3: fix segfault when Tx multiple buffer packets
In reply to Wei Hu (Xavier)From: Chengchang Tang <[email protected]>
Currently, there is a possibility that segment faults occur when sending packets whose payloads are stored in multiple buffers based on hns3 network engine. The related core dump information as follows:
Program terminated with signal 11, Segmentation fault. 0 hns3_reassemble_tx_pkts
2512 temp = temp->next;
Missing separate debuginfos, use:
(gdb) bt
0 hns3_reassemble_tx_pkts 1 0x0000000000969c60 in hns3_check_non_tso_pkt 2 0x000000000096adbc in hns3_xmit_pkts 3 0x000000000050d4d0 in rte_eth_tx_burst 4 0x000000000050fca4 in pkt_burst_transmit 5 0x00000000004ca6b8 in run_pkt_fwd_on_lcore 6 0x00000000004ca7fc in start_pkt_forward_on_core 7 0x00000000006975a4 in eal_thread_loop 8 0x0000ffffa6f7fc48 in start_thread 9 0x0000ffffa6ed1600 in thread_start
The root cause is that hns3 PMD driver invokes the rte_pktmbuf_free_seg API function to release the same rte_mbuf multiple times. The rte_mbuf pointer is not set to NULL in the internal function hns3_rx_queue_release_mbufs which is invoked during queue setup, stop and close. As a result the rte_mbuf in Rx queues will be repeatedly released when the user application setup queues or stop/start the dev for multiple times. Probably for performance reasons, DPDK mempool lib does not check for the repeated rte_mbuf releases. The Address of released rte_mbuf are directly stored into the per lcore cache of the mempool. This makes the rte_mbufs obtained from mempool by calling rte_mempool_get_bulk API function repetitively. ultimately, it causes to access to a NULL pointer in PMD driver.
This patch fixes this problem by setting released mbuf pointer to NULL in the internal function named hns3_rx_queue_release_mbuf. And the other internal function named hns3_reassemble_tx_pkts is optimized to avoid a similar problem.
--- drivers/net/hns3/hns3_rxtx.c | 61 +++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 38 deletions(-)
drivers/net/hns3/hns3_rxtx.c +23 -38
@@ -43,15 +43,19 @@ hns3_rx_queue_release_mbufs(struct hns3_rx_queue *rxq)if (rxq->rx_rearm_nb ==0 ) {for (i =0 ; i < rxq->nb_rx_desc; i++) { -if (rxq->sw_ring[i].mbuf !=NULL ) +if (rxq->sw_ring[i].mbuf !=NULL ) {rte_pktmbuf_free_seg (rxq->sw_ring[i].mbuf); + rxq->sw_ring[i].mbuf =NULL ; + } } }else {for (i = rxq->next_to_use; i != rxq->rx_rearm_start; i = (i +1 ) % rxq->nb_rx_desc) { -if (rxq->sw_ring[i].mbuf !=NULL ) +if (rxq->sw_ring[i].mbuf !=NULL ) {rte_pktmbuf_free_seg (rxq->sw_ring[i].mbuf); + rxq->sw_ring[i].mbuf =NULL ; + } } }
@@ -2368,37 +2372,24 @@ hns3_fill_first_desc(struct hns3_tx_queue *txq, struct hns3_desc *desc, } } -static int -hns3_tx_alloc_mbufs (struct hns3_tx_queue *txq,struct rte_mempool *mb_pool, -uint16_t nb_new_buf,struct rte_mbuf **alloc_mbuf) +static inline int +hns3_tx_alloc_mbufs (struct rte_mempool *mb_pool,uint16_t nb_new_buf, +struct rte_mbuf **alloc_mbuf) { -struct rte_mbuf *new_mbuf =NULL ; -struct rte_eth_dev *dev; -struct rte_mbuf *temp; -struct hns3_hw *hw; +#define MAX_NON_TSO_BD_PER_PKT 18 +struct rte_mbuf *pkt_segs[MAX_NON_TSO_BD_PER_PKT ];uint16_t i;/* Allocate enough mbufs */ -for (i =0 ; i < nb_new_buf; i++) { - temp =rte_pktmbuf_alloc (mb_pool); -if (unlikely (temp ==NULL )) { - dev = &rte_eth_devices[txq->port_id]; - hw =HNS3_DEV_PRIVATE_TO_HW (dev->data->dev_private); -hns3_err (hw,"Failed to alloc TX mbuf port_id=%d," -"queue_id=%d in reassemble tx pkts." , - txq->port_id, txq->queue_id); -rte_pktmbuf_free (new_mbuf); -return -ENOMEM ; - } - temp->next = new_mbuf; - new_mbuf = temp; - } - -if (new_mbuf ==NULL ) +if (rte_mempool_get_bulk (mb_pool, (void **)pkt_segs, nb_new_buf))return -ENOMEM ; - new_mbuf->nb_segs = nb_new_buf; - *alloc_mbuf = new_mbuf; +for (i =0 ; i < nb_new_buf -1 ; i++) + pkt_segs[i]->next = pkt_segs[i +1 ]; + + pkt_segs[nb_new_buf -1 ]->next =NULL ; + pkt_segs[0 ]->nb_segs = nb_new_buf; + *alloc_mbuf = pkt_segs[0 ];return 0 ; }
@@ -2418,10 +2409,8 @@ hns3_pktmbuf_copy_hdr(struct rte_mbuf *new_pkt, struct rte_mbuf *old_pkt) }static int -hns3_reassemble_tx_pkts (void *tx_queue,struct rte_mbuf *tx_pkt, -struct rte_mbuf **new_pkt) +hns3_reassemble_tx_pkts (struct rte_mbuf *tx_pkt,struct rte_mbuf **new_pkt) { -struct hns3_tx_queue *txq = tx_queue;struct rte_mempool *mb_pool;struct rte_mbuf *new_mbuf;struct rte_mbuf *temp_new;
@@ -2433,7 +2422,6 @@ hns3_reassemble_tx_pkts(void *tx_queue, struct rte_mbuf *tx_pkt,uint16_t len_s;uint16_t len_d;uint16_t len; -uint16_t i;int ret;char *s;char *d;
@@ -2449,7 +2437,7 @@ hns3_reassemble_tx_pkts(void *tx_queue, struct rte_mbuf *tx_pkt, last_buf_len = buf_size;/* Allocate enough mbufs */ - ret =hns3_tx_alloc_mbufs (txq, mb_pool, nb_new_buf, &new_mbuf); + ret =hns3_tx_alloc_mbufs (mb_pool, nb_new_buf, &new_mbuf);if (ret)return ret;
@@ -2458,12 +2446,9 @@ hns3_reassemble_tx_pkts(void *tx_queue, struct rte_mbuf *tx_pkt, s = rte_pktmbuf_mtod(temp, char *); len_s =rte_pktmbuf_data_len (temp); temp_new = new_mbuf; -for (i =0 ; i < nb_new_buf; i++) { +while (temp !=NULL && temp_new !=NULL ) { d = rte_pktmbuf_mtod(temp_new, char *); -if (i < nb_new_buf -1 ) - buf_len = buf_size; -else - buf_len = last_buf_len; + buf_len = temp_new->next ==NULL ? last_buf_len : buf_size; len_d = buf_len;while (len_d) {
@@ -2924,7 +2909,7 @@ hns3_check_non_tso_pkt(uint16_t nb_buf, struct rte_mbuf **m_seg,if (unlikely (nb_buf >HNS3_MAX_NON_TSO_BD_PER_PKT )) { txq->exceed_limit_bd_pkt_cnt++; - ret =hns3_reassemble_tx_pkts (txq, tx_pkt, &new_pkt); + ret =hns3_reassemble_tx_pkts (tx_pkt, &new_pkt);if (ret) { txq->exceed_limit_bd_reassem_fail++;return ret;
Signature · 1 line
2.9.5
Quoted 5 lines · Wei Hu (Xavier)
This series are updates for Rx/Tx process.
Chengchang Tang (1):
net/hns3: fix segfault when Tx multiple buffer packets
Quoted 9 lines
Wei Hu (Xavier) (7):
net/hns3: report Rx free threshold net/hns3: reduce address calculation in Rx net/hns3: add simple Rx process function net/hns3: add simple Tx process function net/hns3: add vector Tx burst with NEON instructions net/hns3: add vector Rx burst with NEON instructions net/hns3: add restriction on setting VF MTU
Series applied to dpdk-next-net/main, thanks.