From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D6E0642FB3; Wed, 2 Aug 2023 04:27:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC890410DC; Wed, 2 Aug 2023 04:27:17 +0200 (CEST) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by mails.dpdk.org (Postfix) with ESMTP id 274F840DDB for ; Wed, 2 Aug 2023 04:27:16 +0200 (CEST) Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-54290603887so3969182a12.1 for ; Tue, 01 Aug 2023 19:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1690943235; x=1691548035; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=LgrqmPBrHZ1Dcy/BVMyjNowP0WrYX3BRlsaWISggysw=; b=LVFUoW+1AefUaCfoy0zCD14mrsQljCpehrccewiUbUaBPG+/XAb7IqXwNCpP+iDEkZ s+SmazGg0SecjqGyliCwqD5BRae9Y8iGJcCbXat5AytF5RjkZ8e3sYo9fgUO+rLpEURV 3jiup6j/rkoNFOhobP45QBEH1GP3Bqc7UKd1NSgYL2hvO70yKElpH0Is2sQu79fKMEL5 ClvUsjZPBZjpATQcb7AH+BVzw3gyMVwYxtrk3vv5w9Yjh7gYkkcveKphZwkvgS6clFYm 9M3NvziP8VxAGTCieej3xLWKh39fxyFSwWUQtCEMZaiJHHJffkC7KwcQWhv/XfNpdO9d aAlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690943235; x=1691548035; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LgrqmPBrHZ1Dcy/BVMyjNowP0WrYX3BRlsaWISggysw=; b=lx7VqbbT/qq3gBSmxmuz9XRhsWa42PKEOchina//lMswGFVritkPUZapNn1LtlbopW L2Zs9hoHyzNZPnkhN/q92mwwUU1vuh1c1HIMovBJJJBwLNNVTwaJhC4ipJtT9AfhJXfO XNnIV7MX6Jy9rIXykPZqxa5+cyjbmSRrjeUDKsQ3pqsMCXFiePGGCuO0C5ZkYHSYAhM/ sbPp1dPfFOcX2CT4TyaEBqoNES4BNT8wGEX7ox1RTJGKc6/3dP6k9Oo2oO+/7jftsNXw pXQtYtviLKuvz5o0d1JCnEk8Hr3ZRAs2XJTeuLFdoK1kAY2xttrH3vFEObla725lXyWe M6xA== X-Gm-Message-State: ABy/qLYjoQdjLH4ahqzw5esDwCtPJor2vmZRWuAdqVKLNTt72wlNXUht PYO9d6hOqImHUt3ZEfJglKD29I1YE0SOxrnAbO0roQ== X-Google-Smtp-Source: APBJJlF0kdhkQl6ETuPgGKhKfzb5UwFlIr+x+RM8aL4IIuZNPW4MjCUrmCkMxPZid9T95zKxHwiYGA== X-Received: by 2002:a17:903:11d0:b0:1b7:e49f:39 with SMTP id q16-20020a17090311d000b001b7e49f0039mr14004345plh.60.1690943235010; Tue, 01 Aug 2023 19:27:15 -0700 (PDT) Received: from hermes.local (204-195-127-207.wavecable.com. [204.195.127.207]) by smtp.gmail.com with ESMTPSA id iy15-20020a170903130f00b001bbb1eec92esm11087099plb.281.2023.08.01.19.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 19:27:14 -0700 (PDT) Date: Tue, 1 Aug 2023 19:27:10 -0700 From: Stephen Hemminger To: "11" Cc: Subject: Re: [[PATCH v1] 4/8] net/rnp: add mbx basic api feature Message-ID: <20230801192710.38b47091@hermes.local> In-Reply-To: <2FACEF30971C9899+004b01d9c4e2$76751d60$635f5820$@mucse.com> References: <20230801072207.836932-1-caowenbo@mucse.com> <20230801082555.36dd9f80@hermes.local> <2FACEF30971C9899+004b01d9c4e2$76751d60$635f5820$@mucse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, 2 Aug 2023 09:41:29 +0800 "11" 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