4/8] net/rnp: add mbx basic api feature
Subsystems (2)
PATCH 1/1 4/8] net/rnp: add mbx basic api feature
mbx base code is for communicate with the firmware
--- drivers/net/rnp/base/rnp_hw.h | 107 ++++++- drivers/net/rnp/meson.build | 1 + drivers/net/rnp/rnp.h | 35 +++ drivers/net/rnp/rnp_ethdev.c | 68 +++++ drivers/net/rnp/rnp_logs.h | 9 + drivers/net/rnp/rnp_mbx.c | 522 ++++++++++++++++++++++++++++++++++ drivers/net/rnp/rnp_mbx.h | 138 +++++++++ drivers/net/rnp/rnp_mbx_fw.h | 22 ++ 8 files changed, 901 insertions(+), 1 deletion(-) create mode 100644 drivers/net/rnp/rnp_mbx.c create mode 100644 drivers/net/rnp/rnp_mbx.h create mode 100644 drivers/net/rnp/rnp_mbx_fw.h
drivers/net/rnp/base/rnp_hw.h +106 -1
@@ -4,15 +4,120 @@#ifndef __RNP_HW_H__#define __RNP_HW_H__ +#include <rte_io.h> +#include <ethdev_driver.h> + +#include "rnp_osdep.h" + +static inline unsigned int rnp_rd_reg (volatile void *addr) +{ +unsigned int v =rte_read32 (addr); + +return v; +} + +static inline void rnp_wr_reg (volatile void *reg,int val) +{ +rte_write32_relaxed ((val), (reg)); +} + +#define mbx_rd32 (hw, reg) rnp_rd_reg((hw)->iobar4 + (reg)) +#define mbx_wr32 (hw, reg, val) rnp_wr_reg((hw)->iobar4 + (reg), (val)) + +struct rnp_hw ; +/* Mbx Operate info */ +enum MBX_ID { +MBX_PF =0 , +MBX_VF , +MBX_CM3CPU , +MBX_FW =MBX_CM3CPU , +MBX_VFCNT +}; +struct rnp_mbx_api { +void (*init_mbx)(struct rnp_hw *hw); +int32_t (*read)(struct rnp_hw *hw, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*write)(struct rnp_hw *hw, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*read_posted)(struct rte_eth_dev *dev, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*write_posted)(struct rte_eth_dev *dev, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*check_for_msg)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*check_for_ack)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*check_for_rst)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*configure)(struct rnp_hw *hw,int nr_vec,bool enable); +}; + +struct rnp_mbx_stats { +u32 msgs_tx; +u32 msgs_rx; + +u32 acks; +u32 reqs; +u32 rsts; +}; + +struct rnp_mbx_info { +struct rnp_mbx_api ops; +uint32_t usec_delay;/* retry interval delay time */ +uint32_t timeout;/* retry ops timeout limit */ +uint16_t size;/* data buffer size*/ +uint16_t vf_num;/* Virtual Function num */ +uint16_t pf_num;/* Physical Function num */ +uint16_t sriov_st;/* Sriov state */ +bool irq_enabled; +union { +struct { +unsigned short pf_req; +unsigned short pf_ack; + }; +struct { +unsigned short cpu_req; +unsigned short cpu_ack; + }; + }; +unsigned short vf_req[64 ]; +unsigned short vf_ack[64 ]; + +struct rnp_mbx_stats stats; + +rte_atomic16_t state; +} __rte_cache_aligned; + +#define RNP_MAX_HW_PORT_PERR_PF (4)struct rnp_hw {void *back;char *iobar0;uint32_t iobar0_len;char *iobar4;uint32_t iobar4_len; +char *link_sync; +char *dma_base; +char *eth_base; +char *veb_base; +char *mac_base[RNP_MAX_HW_PORT_PERR_PF ]; +char *msix_base; +/* === dma == */ +char *dma_axi_en; +char *dma_axi_st;uint16_t device_id;uint16_t vendor_id; -} __rte_cache_aligned; +uint16_t function; +uint16_t pf_vf_num; +uint16_t max_vfs; +void *cookie_pool; +char cookie_p_name[RTE_MEMZONE_NAMESIZE ]; +struct rnp_mbx_info mbx; +} __rte_cache_aligned;#endif /* __RNP_H__*/
drivers/net/rnp/meson.build +1 -0
@@ -9,5 +9,6 @@ endif sources = files( 'rnp_ethdev.c', + 'rnp_mbx.c', ) includes += include_directories('base')
drivers/net/rnp/rnp.h +35 -0
@@ -3,6 +3,7 @@*/ #ifndef __RNP_H__#define __RNP_H__ +#include <rte_log.h> #include "base/rnp_hw.h"
@@ -14,14 +15,17 @@struct rnp_eth_port {void *adapt; +struct rnp_hw *hw;struct rte_eth_dev *eth_dev; } __rte_cache_aligned;struct rnp_share_ops { +struct rnp_mbx_api mbx_api; } __rte_cache_aligned;struct rnp_eth_adapter {struct rnp_hw hw; +uint16_t max_vfs;struct rte_pci_device *pdev;struct rte_eth_dev *eth_dev;/* master eth_dev */ struct rnp_eth_port *ports[RNP_MAX_PORT_OF_PF ];
@@ -34,5 +38,36 @@ struct rnp_eth_adapter { (((struct rnp_eth_port *)((eth_dev)->data->dev_private)))#define RNP_DEV_TO_ADAPTER (eth_dev) \ ((struct rnp_eth_adapter *)(RNP_DEV_TO_PORT(eth_dev)->adapt)) +#define RNP_DEV_TO_HW (eth_dev) \ + (&((struct rnp_eth_adapter *)(RNP_DEV_TO_PORT((eth_dev))->adapt))->hw) +#define RNP_DEV_PP_PRIV_TO_MBX_OPS (dev) \ + (&((struct rnp_share_ops *)(dev)->process_private)->mbx_api) +#define RNP_DEV_TO_MBX_OPS (dev) RNP_DEV_PP_PRIV_TO_MBX_OPS(dev) +static inline void rnp_reg_offset_init (struct rnp_hw *hw) +{ +uint16_t i; + +if (hw->device_id ==RNP_DEV_ID_N10G && hw->mbx.pf_num) { + hw->iobar4 +=0x100000 ; + hw->msix_base = hw->iobar4 +0xa0000 ; + hw->msix_base +=0x200 ; + }else { + hw->msix_base = hw->iobar4 +0xa0000 ; + } +/* === dma status/config====== */ + hw->link_sync = hw->iobar4 +0x000c ; + hw->dma_axi_en = hw->iobar4 +0x0010 ; + hw->dma_axi_st = hw->iobar4 +0x0014 ; + +if (hw->mbx.pf_num) + hw->msix_base +=0x200 ; +/* === queue registers === */ + hw->dma_base = hw->iobar4 +0x08000 ; + hw->veb_base = hw->iobar4 +0x0 ; + hw->eth_base = hw->iobar4 +0x10000 ; +/* mac */ +for (i =0 ; i <RNP_MAX_HW_PORT_PERR_PF ; i++) + hw->mac_base[i] = hw->iobar4 +0x60000 +0x10000 * i; +}#endif /* __RNP_H__ */
drivers/net/rnp/rnp_ethdev.c +68 -0
88 lines not on this page · raw message
drivers/net/rnp/rnp_logs.h +9 -0
@@ -13,6 +13,15 @@ extern int rnp_drv_logtype; #define RNP_PMD_DRV_LOG(level, fmt, args...) \ rte_log(RTE_LOG_##level, rnp_drv_logtype, \ "%s() " fmt, __func__, ##args) +#define PMD_DRV_LOG_RAW(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, rnp_drv_logtype, "%s(): " fmt, \ + __func__, ## args) +#define PMD_DRV_LOG(level, fmt, args...) \ + PMD_DRV_LOG_RAW(level, fmt "\n", ## args) + +#define RNP_PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_##level, rnp_drv_logtype, \ + "rnp_net: (%d) " fmt, __LINE__, ##args)#ifdef RTE_LIBRTE_RNP_DEBUG_RX extern int rnp_rx_logtype; #define RNP_PMD_RX_LOG(level, fmt, args...) \
drivers/net/rnp/rnp_mbx.c new file +522 -0
522 lines not on this page · raw message
drivers/net/rnp/rnp_mbx.h new file +138 -0
138 lines not on this page · raw message
drivers/net/rnp/rnp_mbx_fw.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef __RNP_MBX_FW_H__ +#define __RNP_MBX_FW_H__ + +struct mbx_fw_cmd_reply ; +typedef void (*cookie_cb )(struct mbx_fw_cmd_reply *reply,void *priv); +#define RNP_MAX_SHARE_MEM (8 * 8) +struct mbx_req_cookie { +int magic; +#define COOKIE_MAGIC 0xCE +cookie_cb cb; +int timeout_ms; +int errcode; + +/* wait_queue_head_t wait; */ +volatile int done; +int priv_len; +char priv[RNP_MAX_SHARE_MEM ]; +}; +struct mbx_fw_cmd_reply { +} __rte_cache_aligned; + +#endif /* __RNP_MBX_FW_H__*/
Signature · 1 line
2.27.0
Quoted 13 lines · On Tue, 1 Aug 2023 07:22:07 +0000 Wenbo Cao <[email protected]> wrote:
drivers/net/rnp/base/rnp_hw.h +13
-0+struct rnp_mbx_api { +void (*init_mbx)(struct rnp_hw *hw); +int32_t (*read)(struct rnp_hw *hw, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*write)(struct rnp_hw *hw, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); + int32_t (*read_posted)(struct rte_eth_dev *dev, + uint32_t *msg, + uint16_t size,
drivers/net/rnp/base/rnp_hw.h line 58
Quoted 10 lines
drivers/net/rnp/base/rnp_hw.h +10
-0+ enum MBX_ID); +int32_t (*write_posted)(struct rte_eth_dev *dev, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*check_for_msg)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*check_for_ack)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*check_for_rst)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*configure)(struct rnp_hw *hw,int nr_vec,bool enable); +};
Since this data structure only has virtual function pointers; many types of bugs can be avoided if it can be made const.
If it const, then compiler can put the initialized table in r/o text section.
Hi Stephen,
Thanks for your comment, as your advice that I need to define the virtual function pointers
As the below type ?
const struct rnp_mbx_api {
..
}
If It will protect the virtual function address ,won't be remove by mistake?
Regards Wenbo
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: 2023年8月1日 23:26
To: Wenbo Cao <[email protected]>
Cc: [email protected]
Subject: Re: [[PATCH v1] 4/8] net/rnp: add mbx basic api feature
Quoted 12 lines · On Tue, 1 Aug 2023 07:22:07 +0000 Wenbo Cao <[email protected]> wrote:
drivers/net/rnp/base/rnp_hw.h +12
-0+struct rnp_mbx_api { +void (*init_mbx)(struct rnp_hw *hw); +int32_t (*read)(struct rnp_hw *hw, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*write)(struct rnp_hw *hw, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); + int32_t (*read_posted)(struct rte_eth_dev *dev, + uint32_t *msg,
drivers/net/rnp/base/rnp_hw.h
Quoted 10 lines
drivers/net/rnp/base/rnp_hw.h +10
-0+uint16_t size, + enum MBX_ID); +int32_t (*write_posted)(struct rte_eth_dev *dev, +uint32_t *msg, +uint16_t size, +enum MBX_ID ); +int32_t (*check_for_msg)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*check_for_ack)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*check_for_rst)(struct rnp_hw *hw,enum MBX_ID ); +int32_t (*configure)(struct rnp_hw *hw,int nr_vec,bool enable); };
Since this data structure only has virtual function pointers; many types of bugs can be avoided if it can be made const.
If it const, then compiler can put the initialized table in r/o text section.
Quoted 5 lines · On Wed, 2 Aug 2023 09:41:29 +0800 "11" <[email protected]> wrote:
Hi Stephen,
Thanks for your comment, as your advice that I need to define the virtual function pointers
As the below type ?
No, keep the struct the same, but make it const where used. You also do a copy of the ops struct so the one you initialize ends up in the shared ops. It would be cleaner to have one initialized object and have objects point to that.
Tried something like this, but it won't work.
drivers/net/rnp/rnp.h +2 -2
@@ -20,7 +20,7 @@ struct rnp_eth_port { } __rte_cache_aligned;struct rnp_share_ops { -struct rnp_mbx_api mbx_api; +const struct rnp_mbx_api *mbx_api; } __rte_cache_aligned;struct rnp_eth_adapter {
@@ -41,7 +41,7 @@ struct rnp_eth_adapter {#define RNP_DEV_TO_HW (eth_dev) \ (&((struct rnp_eth_adapter *)(RNP_DEV_TO_PORT((eth_dev))->adapt))->hw)#define RNP_DEV_PP_PRIV_TO_MBX_OPS (dev) \ - (&((struct rnp_share_ops *)(dev)->process_private)->mbx_api) + (((struct rnp_share_ops *)(dev)->process_private)->mbx_api)#define RNP_DEV_TO_MBX_OPS (dev) RNP_DEV_PP_PRIV_TO_MBX_OPS(dev)static inline void rnp_reg_offset_init (struct rnp_hw *hw)
drivers/net/rnp/rnp_ethdev.c +1 -2
@@ -11,7 +11,6 @@#include "rnp_mbx.h" #include "rnp_logs.h" -extern struct rnp_mbx_api rnp_mbx_pf_ops;static int rnp_mac_rx_disable (struct rte_eth_dev *dev) {
@@ -133,7 +132,7 @@ rnp_common_ops_init(struct rnp_eth_adapter *adapter)struct rnp_share_ops *share_priv; share_priv = adapter->share_priv; - share_priv->mbx_api = rnp_mbx_pf_ops; + share_priv->mbx_api = &rnp_mbx_pf_ops; } static int
drivers/net/rnp/rnp_mbx.c +1 -1
@@ -455,7 +455,7 @@ static int get_pfvfnum(struct rnp_hw *hw)return val >>RNP_PFVF_SHIFT ; } -struct rnp_mbx_api rnp_mbx_pf_ops = { +const struct rnp_mbx_api rnp_mbx_pf_ops = { .read = rnp_read_mbx_pf, .write = rnp_write_mbx_pf, .read_posted = rnp_read_posted_mbx_pf,
drivers/net/rnp/rnp_mbx.h +2 -0
@@ -135,4 +135,6 @@void rnp_init_mbx_ops_pf (struct rnp_hw *hw);void *rnp_memzone_reserve (const char *name,unsigned int size); + +extern const struct rnp_mbx_api rnp_mbx_pf_ops;#endif