On Wed, 2 Aug 2023 09:41:29 +0800 "11" <caowe...@mucse.com> 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. diff --git a/drivers/net/rnp/rnp.h b/drivers/net/rnp/rnp.h index a8999ddc471c..437a2cc2093d 100644 --- a/drivers/net/rnp/rnp.h +++ b/drivers/net/rnp/rnp.h @@ -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) diff --git a/drivers/net/rnp/rnp_ethdev.c b/drivers/net/rnp/rnp_ethdev.c index 4747a41423dd..4518eaa3efa9 100644 --- a/drivers/net/rnp/rnp_ethdev.c +++ b/drivers/net/rnp/rnp_ethdev.c @@ -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 diff --git a/drivers/net/rnp/rnp_mbx.c b/drivers/net/rnp/rnp_mbx.c index 0f1c0a5b7471..b39e05bb715c 100644 --- a/drivers/net/rnp/rnp_mbx.c +++ b/drivers/net/rnp/rnp_mbx.c @@ -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, diff --git a/drivers/net/rnp/rnp_mbx.h b/drivers/net/rnp/rnp_mbx.h index ee020b5fbce7..0fae78167336 100644 --- a/drivers/net/rnp/rnp_mbx.h +++ b/drivers/net/rnp/rnp_mbx.h @@ -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