DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "11" <caowenbo@mucse.com>
Cc: <dev@dpdk.org>
Subject: Re: [[PATCH v1] 4/8] net/rnp: add mbx basic api feature
Date: Tue, 1 Aug 2023 19:27:10 -0700	[thread overview]
Message-ID: <20230801192710.38b47091@hermes.local> (raw)
In-Reply-To: <2FACEF30971C9899+004b01d9c4e2$76751d60$635f5820$@mucse.com>

On Wed, 2 Aug 2023 09:41:29 +0800
"11" <caowenbo@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


  reply	other threads:[~2023-08-02  2:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01  7:22 Wenbo Cao
2023-08-01 15:25 ` Stephen Hemminger
2023-08-02  1:41   ` 11
2023-08-02  2:27     ` Stephen Hemminger [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-08-01  6:43 [[PATCH v1] 0/8] *** SUBJECT HERE *** Wenbo Cao
2023-08-01  6:43 ` [[PATCH v1] 4/8] net/rnp: add mbx basic api feature Wenbo Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230801192710.38b47091@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=caowenbo@mucse.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).