DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Shepard Siegel <shepard.siegel@atomicrules.com>,
	Ed Czeck <ed.czeck@atomicrules.com>,
	John Miller <john.miller@atomicrules.com>,
	Ajit Khaparde <ajit.khaparde@broadcom.com>,
	Somnath Kotur <somnath.kotur@broadcom.com>,
	Jingjing Wu <jingjing.wu@intel.com>,
	Rosen Xu <rosen.xu@intel.com>,
	Jiawen Wu <jiawenwu@trustnetic.com>,
	Harman Kalra <hkalra@marvell.com>,
	Jian Wang <jianwang@trustnetic.com>
Subject: [PATCH 5/5] drivers/net: use RTE_DIM
Date: Tue, 16 Apr 2024 08:19:31 -0700	[thread overview]
Message-ID: <20240416152124.69590-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20240416152124.69590-1-stephen@networkplumber.org>

Use RTE_DIM instead of computing directly with sizeof.
Patch automatically generated via cocci/rte_dim.cocci.
Code in base/ subdirectory manually excluded.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/ark/ark_pktchkr.c         |  2 +-
 drivers/net/ark/ark_pktgen.c          |  2 +-
 drivers/net/bnxt/bnxt_hwrm.c          | 12 ++++++------
 drivers/net/e1000/em_rxtx.c           |  3 +--
 drivers/net/iavf/iavf_ipsec_crypto.c  |  3 +--
 drivers/net/igc/igc_ethdev.c          |  3 +--
 drivers/net/ipn3ke/ipn3ke_tm.c        |  3 +--
 drivers/net/ngbe/ngbe_ethdev.c        |  6 ++----
 drivers/net/octeontx/octeontx_stats.h |  3 +--
 drivers/net/txgbe/txgbe_ethdev.c      |  9 +++------
 drivers/net/txgbe/txgbe_ethdev_vf.c   |  3 +--
 11 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ark/ark_pktchkr.c b/drivers/net/ark/ark_pktchkr.c
index e1f336c73c..63c298fca8 100644
--- a/drivers/net/ark/ark_pktchkr.c
+++ b/drivers/net/ark/ark_pktchkr.c
@@ -320,7 +320,7 @@ options(const char *id)
 {
 	unsigned int i;
 
-	for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
+	for (i = 0; i < RTE_DIM(toptions); i++) {
 		if (strcmp(id, toptions[i].opt) == 0)
 			return &toptions[i];
 	}
diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c
index 69ff7072b2..98e692c3ad 100644
--- a/drivers/net/ark/ark_pktgen.c
+++ b/drivers/net/ark/ark_pktgen.c
@@ -297,7 +297,7 @@ options(const char *id)
 {
 	unsigned int i;
 
-	for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
+	for (i = 0; i < RTE_DIM(toptions); i++) {
 		if (strcmp(id, toptions[i].opt) == 0)
 			return &toptions[i];
 	}
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 6ea7089a3f..68d7382806 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -72,13 +72,13 @@ const char *media_type[] = { "Unknown", "Twisted Pair",
 	"Direct Attached Copper", "Fiber"
 };
 
-#define MAX_MEDIA_TYPE (sizeof(media_type) / sizeof(const char *))
+#define MAX_MEDIA_TYPE RTE_DIM(media_type)
 
 const char *link_status_str[] = { "Down. No link or cable detected.",
 	"Down. No link, but a cable has been detected.", "Up.",
 };
 
-#define MAX_LINK_STR (sizeof(link_status_str) / sizeof(const char *))
+#define MAX_LINK_STR RTE_DIM(link_status_str)
 
 const char *fec_mode[] = {
 	"No active FEC",
@@ -90,13 +90,13 @@ const char *fec_mode[] = {
 	"FEC RS(272,257)"
 };
 
-#define MAX_FEC_MODE (sizeof(fec_mode) / sizeof(const char *))
+#define MAX_FEC_MODE RTE_DIM(fec_mode)
 
 const char *signal_mode[] = {
 	"NRZ", "PAM4", "PAM4_112"
 };
 
-#define MAX_SIG_MODE (sizeof(signal_mode) / sizeof(const char *))
+#define MAX_SIG_MODE RTE_DIM(signal_mode)
 
 /* multi-purpose multi-key table container.
  * Add a unique entry for a new PHY attribs as per HW CAS.
@@ -226,7 +226,7 @@ struct link_speeds2_tbl {
 	},
 };
 
-#define BNXT_SPEEDS2_TBL_SZ (sizeof(link_speeds2_tbl) / sizeof(*link_speeds2_tbl))
+#define BNXT_SPEEDS2_TBL_SZ RTE_DIM(link_speeds2_tbl)
 
 /* In hwrm_phy_qcfg reports trained up speeds in link_speed(offset:0x8[31:16]) */
 struct link_speeds_tbl {
@@ -269,7 +269,7 @@ struct link_speeds_tbl {
 	},
 };
 
-#define BNXT_SPEEDS_TBL_SZ (sizeof(link_speeds_tbl) / sizeof(*link_speeds_tbl))
+#define BNXT_SPEEDS_TBL_SZ RTE_DIM(link_speeds_tbl)
 
 static const char *bnxt_get_xcvr_type(uint32_t xcvr_identifier_type_tx_lpi_timer)
 {
diff --git a/drivers/net/e1000/em_rxtx.c b/drivers/net/e1000/em_rxtx.c
index df5fbb7823..59d7793787 100644
--- a/drivers/net/e1000/em_rxtx.c
+++ b/drivers/net/e1000/em_rxtx.c
@@ -1666,8 +1666,7 @@ em_rctl_bsize(__rte_unused enum e1000_mac_type hwtyp, uint32_t *bufsz)
 	 * ***************************************************************
 	 */
 
-	for (i = 0; i != sizeof(bufsz_to_rctl) / sizeof(bufsz_to_rctl[0]);
-			i++) {
+	for (i = 0; i != RTE_DIM(bufsz_to_rctl); i++) {
 		if (rctl_bsize >= bufsz_to_rctl[i].bufsz) {
 			*bufsz = bufsz_to_rctl[i].bufsz;
 			return bufsz_to_rctl[i].rctl;
diff --git a/drivers/net/iavf/iavf_ipsec_crypto.c b/drivers/net/iavf/iavf_ipsec_crypto.c
index 6fd45ff45f..d3ce666ef0 100644
--- a/drivers/net/iavf/iavf_ipsec_crypto.c
+++ b/drivers/net/iavf/iavf_ipsec_crypto.c
@@ -1483,8 +1483,7 @@ iavf_ipsec_crypto_capabilities_get(void *device)
 	 * crypto capabilities, except for last element of the array which is
 	 * the null termination
 	 */
-	for (i = 0; i < ((sizeof(iavf_security_capabilities) /
-			sizeof(iavf_security_capabilities[0])) - 1); i++) {
+	for (i = 0; i < (RTE_DIM(iavf_security_capabilities) - 1); i++) {
 		iavf_security_capabilities[i].crypto_capabilities =
 			iavf_sctx->crypto_capabilities;
 	}
diff --git a/drivers/net/igc/igc_ethdev.c b/drivers/net/igc/igc_ethdev.c
index 87d7f7caa0..28682c42ae 100644
--- a/drivers/net/igc/igc_ethdev.c
+++ b/drivers/net/igc/igc_ethdev.c
@@ -188,8 +188,7 @@ static const struct rte_igc_xstats_name_off rte_igc_stats_strings[] = {
 		offsetof(struct igc_hw_stats, icrxdmtc)},
 };
 
-#define IGC_NB_XSTATS (sizeof(rte_igc_stats_strings) / \
-		sizeof(rte_igc_stats_strings[0]))
+#define IGC_NB_XSTATS RTE_DIM(rte_igc_stats_strings)
 
 static int eth_igc_configure(struct rte_eth_dev *dev);
 static int eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete);
diff --git a/drivers/net/ipn3ke/ipn3ke_tm.c b/drivers/net/ipn3ke/ipn3ke_tm.c
index 0260227900..54687ce637 100644
--- a/drivers/net/ipn3ke/ipn3ke_tm.c
+++ b/drivers/net/ipn3ke/ipn3ke_tm.c
@@ -67,8 +67,7 @@ struct ipn3ke_tm_shaper_params_range_type ipn3ke_tm_shaper_params_rang[] = {
 	{512,    1023,    15,    32768,    67108864,    134086656},
 };
 
-#define IPN3KE_TM_SHAPER_RANGE_NUM (sizeof(ipn3ke_tm_shaper_params_rang) / \
-	sizeof(struct ipn3ke_tm_shaper_params_range_type))
+#define IPN3KE_TM_SHAPER_RANGE_NUM RTE_DIM(ipn3ke_tm_shaper_params_rang)
 
 #define IPN3KE_TM_SHAPER_COMMITTED_RATE_MAX \
 	(ipn3ke_tm_shaper_params_rang[IPN3KE_TM_SHAPER_RANGE_NUM - 1].high)
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 4cd07a0030..f10b9647fa 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -238,8 +238,7 @@ static const struct rte_ngbe_xstats_name_off rte_ngbe_stats_strings[] = {
 	HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
 };
 
-#define NGBE_NB_HW_STATS (sizeof(rte_ngbe_stats_strings) / \
-			   sizeof(rte_ngbe_stats_strings[0]))
+#define NGBE_NB_HW_STATS RTE_DIM(rte_ngbe_stats_strings)
 
 /* Per-queue statistics */
 #define QP_XSTAT(m) {#m, offsetof(struct ngbe_hw_stats, qp[0].m)}
@@ -251,8 +250,7 @@ static const struct rte_ngbe_xstats_name_off rte_ngbe_qp_strings[] = {
 	QP_XSTAT(rx_qp_mc_packets),
 };
 
-#define NGBE_NB_QP_STATS (sizeof(rte_ngbe_qp_strings) / \
-			   sizeof(rte_ngbe_qp_strings[0]))
+#define NGBE_NB_QP_STATS RTE_DIM(rte_ngbe_qp_strings)
 
 static inline int32_t
 ngbe_pf_reset_hw(struct ngbe_hw *hw)
diff --git a/drivers/net/octeontx/octeontx_stats.h b/drivers/net/octeontx/octeontx_stats.h
index 73ef5e93bb..746205bb85 100644
--- a/drivers/net/octeontx/octeontx_stats.h
+++ b/drivers/net/octeontx/octeontx_stats.h
@@ -36,6 +36,5 @@ struct octeontx_xstats octeontx_bgx_xstats[] = {
 	BGX_XSTAT(tx_pause_packets),
 };
 
-#define NUM_BGX_XSTAT \
-	(sizeof(octeontx_bgx_xstats) / sizeof(struct octeontx_xstats))
+#define NUM_BGX_XSTAT RTE_DIM(octeontx_bgx_xstats)
 #endif /* __OCTEONTX_STATS_H__ */
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index b75e8898e2..fbf261bd0b 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -269,8 +269,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_stats_strings[] = {
 	HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
 };
 
-#define TXGBE_NB_HW_STATS (sizeof(rte_txgbe_stats_strings) / \
-			   sizeof(rte_txgbe_stats_strings[0]))
+#define TXGBE_NB_HW_STATS RTE_DIM(rte_txgbe_stats_strings)
 
 /* Per-priority statistics */
 #define UP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, up[0].m)}
@@ -290,8 +289,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_up_strings[] = {
 	UP_XSTAT(tx_up_xon2off_packets),
 };
 
-#define TXGBE_NB_UP_STATS (sizeof(rte_txgbe_up_strings) / \
-			   sizeof(rte_txgbe_up_strings[0]))
+#define TXGBE_NB_UP_STATS RTE_DIM(rte_txgbe_up_strings)
 
 /* Per-queue statistics */
 #define QP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, qp[0].m)}
@@ -303,8 +301,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_qp_strings[] = {
 	QP_XSTAT(rx_qp_mc_packets),
 };
 
-#define TXGBE_NB_QP_STATS (sizeof(rte_txgbe_qp_strings) / \
-			   sizeof(rte_txgbe_qp_strings[0]))
+#define TXGBE_NB_QP_STATS RTE_DIM(rte_txgbe_qp_strings)
 
 static inline int
 txgbe_is_sfp(struct txgbe_hw *hw)
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index f1341fbf7e..be96519b97 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -112,8 +112,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
 			offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
 };
 
-#define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) /	\
-		sizeof(rte_txgbevf_stats_strings[0]))
+#define TXGBEVF_NB_XSTATS RTE_DIM(rte_txgbevf_stats_strings)
 
 /*
  * Negotiate mailbox API version with the PF.
-- 
2.43.0


  parent reply	other threads:[~2024-04-16 15:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16 15:19 [PATCH 0/5] use RTE_DIM where possible Stephen Hemminger
2024-04-16 15:19 ` [PATCH 1/5] cocci: add script to use RTE_DIM Stephen Hemminger
2024-04-16 15:19 ` [PATCH 2/5] app: " Stephen Hemminger
2024-04-16 15:30   ` Tyler Retzlaff
2024-04-17  6:13   ` [EXTERNAL] " Akhil Goyal
2024-04-16 15:19 ` [PATCH 3/5] lib: " Stephen Hemminger
2024-04-16 15:32   ` Tyler Retzlaff
2024-04-16 15:19 ` [PATCH 4/5] examples _use RTE_DIM Stephen Hemminger
2024-04-16 15:32   ` Tyler Retzlaff
2024-04-16 15:19 ` Stephen Hemminger [this message]
2024-04-16 16:29   ` [PATCH 5/5] drivers/net: use RTE_DIM Ferruh Yigit
2024-04-16 17:32     ` Stephen Hemminger
2024-04-17  8:00       ` Ferruh Yigit

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=20240416152124.69590-6-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=ed.czeck@atomicrules.com \
    --cc=hkalra@marvell.com \
    --cc=jianwang@trustnetic.com \
    --cc=jiawenwu@trustnetic.com \
    --cc=jingjing.wu@intel.com \
    --cc=john.miller@atomicrules.com \
    --cc=rosen.xu@intel.com \
    --cc=shepard.siegel@atomicrules.com \
    --cc=somnath.kotur@broadcom.com \
    /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).