DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Boyer <aboyer@pensando.io>
To: dev@dpdk.org
Cc: Alfredo Cardigliano <cardigliano@ntop.org>,
	Andrew Boyer <aboyer@pensando.io>
Subject: [dpdk-dev] [PATCH 04/13] net/ionic: add an array-size macro
Date: Mon, 18 Jan 2021 12:34:59 -0800	[thread overview]
Message-ID: <20210118203508.1332-5-aboyer@pensando.io> (raw)
In-Reply-To: <20210118203508.1332-1-aboyer@pensando.io>

Using the IONIC_ARRAY_SIZE() macro makes the code clearer.

Signed-off-by: Andrew Boyer <aboyer@pensando.io>
---
 drivers/net/ionic/ionic_dev.c    | 10 ++++------
 drivers/net/ionic/ionic_ethdev.c |  3 +--
 drivers/net/ionic/ionic_lif.c    |  9 +++------
 drivers/net/ionic/ionic_main.c   | 32 +++++++++++---------------------
 drivers/net/ionic/ionic_osdep.h  |  2 ++
 5 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/drivers/net/ionic/ionic_dev.c b/drivers/net/ionic/ionic_dev.c
index c3016b2d50..c4e871187d 100644
--- a/drivers/net/ionic/ionic_dev.c
+++ b/drivers/net/ionic/ionic_dev.c
@@ -87,9 +87,8 @@ void
 ionic_dev_cmd_comp(struct ionic_dev *idev, void *mem)
 {
 	union ionic_dev_cmd_comp *comp = mem;
-	unsigned int i;
-	uint32_t comp_size = sizeof(comp->words) /
-		sizeof(comp->words[0]);
+	uint32_t comp_size = IONIC_ARRAY_SIZE(comp->words);
+	uint32_t i;
 
 	for (i = 0; i < comp_size; i++)
 		comp->words[i] = ioread32(&idev->dev_cmd->comp.words[i]);
@@ -98,9 +97,8 @@ ionic_dev_cmd_comp(struct ionic_dev *idev, void *mem)
 void
 ionic_dev_cmd_go(struct ionic_dev *idev, union ionic_dev_cmd *cmd)
 {
-	unsigned int i;
-	uint32_t cmd_size = sizeof(cmd->words) /
-		sizeof(cmd->words[0]);
+	uint32_t cmd_size = IONIC_ARRAY_SIZE(cmd->words);
+	uint32_t i;
 
 	IONIC_PRINT(DEBUG, "Sending %s (%d) via dev_cmd",
 		    ionic_opcode_to_str(cmd->cmd.opcode), cmd->cmd.opcode);
diff --git a/drivers/net/ionic/ionic_ethdev.c b/drivers/net/ionic/ionic_ethdev.c
index a5b2301e46..9238bf7d36 100644
--- a/drivers/net/ionic/ionic_ethdev.c
+++ b/drivers/net/ionic/ionic_ethdev.c
@@ -207,8 +207,7 @@ static const struct rte_ionic_xstats_name_off rte_ionic_xstats_strings[] = {
 			tx_desc_data_error)},
 };
 
-#define IONIC_NB_HW_STATS (sizeof(rte_ionic_xstats_strings) / \
-		sizeof(rte_ionic_xstats_strings[0]))
+#define IONIC_NB_HW_STATS IONIC_ARRAY_SIZE(rte_ionic_xstats_strings)
 
 static int
 ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
diff --git a/drivers/net/ionic/ionic_lif.c b/drivers/net/ionic/ionic_lif.c
index 15e291b604..df8832f908 100644
--- a/drivers/net/ionic/ionic_lif.c
+++ b/drivers/net/ionic/ionic_lif.c
@@ -1729,13 +1729,10 @@ ionic_lif_identify(struct ionic_adapter *adapter)
 	struct ionic_dev *idev = &adapter->idev;
 	struct ionic_identity *ident = &adapter->ident;
 	union ionic_lif_config *cfg = &ident->lif.eth.config;
+	uint32_t lif_words = IONIC_ARRAY_SIZE(ident->lif.words);
+	uint32_t cmd_words = IONIC_ARRAY_SIZE(idev->dev_cmd->data);
+	uint32_t i, nwords;
 	int err;
-	unsigned int i;
-	unsigned int lif_words = sizeof(ident->lif.words) /
-		sizeof(ident->lif.words[0]);
-	unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
-		sizeof(idev->dev_cmd->data[0]);
-	unsigned int nwords;
 
 	ionic_dev_cmd_lif_identify(idev, IONIC_LIF_TYPE_CLASSIC,
 		IONIC_IDENTITY_VERSION_1);
diff --git a/drivers/net/ionic/ionic_main.c b/drivers/net/ionic/ionic_main.c
index 3f15a6f2f2..12b8d682cd 100644
--- a/drivers/net/ionic/ionic_main.c
+++ b/drivers/net/ionic/ionic_main.c
@@ -263,15 +263,11 @@ ionic_identify(struct ionic_adapter *adapter)
 {
 	struct ionic_dev *idev = &adapter->idev;
 	struct ionic_identity *ident = &adapter->ident;
-	int err = 0;
-	uint32_t i;
-	unsigned int nwords;
-	uint32_t drv_size = sizeof(ident->drv.words) /
-		sizeof(ident->drv.words[0]);
-	uint32_t cmd_size = sizeof(idev->dev_cmd->data) /
-		sizeof(idev->dev_cmd->data[0]);
-	uint32_t dev_size = sizeof(ident->dev.words) /
-		sizeof(ident->dev.words[0]);
+	uint32_t drv_size = IONIC_ARRAY_SIZE(ident->drv.words);
+	uint32_t cmd_size = IONIC_ARRAY_SIZE(idev->dev_cmd->data);
+	uint32_t dev_size = IONIC_ARRAY_SIZE(ident->dev.words);
+	uint32_t i, nwords;
+	int err;
 
 	memset(ident, 0, sizeof(*ident));
 
@@ -323,12 +319,9 @@ ionic_port_identify(struct ionic_adapter *adapter)
 {
 	struct ionic_dev *idev = &adapter->idev;
 	struct ionic_identity *ident = &adapter->ident;
-	unsigned int port_words = sizeof(ident->port.words) /
-		sizeof(ident->port.words[0]);
-	unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
-		sizeof(idev->dev_cmd->data[0]);
-	unsigned int i;
-	unsigned int nwords;
+	uint32_t port_words = IONIC_ARRAY_SIZE(ident->port.words);
+	uint32_t cmd_words = IONIC_ARRAY_SIZE(idev->dev_cmd->data);
+	uint32_t i, nwords;
 	int err;
 
 	ionic_dev_cmd_port_identify(idev);
@@ -374,12 +367,9 @@ ionic_port_init(struct ionic_adapter *adapter)
 	struct ionic_dev *idev = &adapter->idev;
 	struct ionic_identity *ident = &adapter->ident;
 	char z_name[RTE_MEMZONE_NAMESIZE];
-	unsigned int config_words = sizeof(ident->port.config.words) /
-		sizeof(ident->port.config.words[0]);
-	unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
-		sizeof(idev->dev_cmd->data[0]);
-	unsigned int nwords;
-	unsigned int i;
+	uint32_t config_words = IONIC_ARRAY_SIZE(ident->port.config.words);
+	uint32_t cmd_words = IONIC_ARRAY_SIZE(idev->dev_cmd->data);
+	uint32_t i, nwords;
 	int err;
 
 	if (idev->port_info)
diff --git a/drivers/net/ionic/ionic_osdep.h b/drivers/net/ionic/ionic_osdep.h
index a55d599184..157b0ca516 100644
--- a/drivers/net/ionic/ionic_osdep.h
+++ b/drivers/net/ionic/ionic_osdep.h
@@ -20,6 +20,8 @@
 
 #include "ionic_logs.h"
 
+#define IONIC_ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof((_arr)[0]))
+
 #define BIT(nr)            (1UL << (nr))
 #define BIT_ULL(nr)        (1ULL << (nr))
 
-- 
2.17.1


  parent reply	other threads:[~2021-01-18 20:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 20:34 [dpdk-dev] [PATCH 00/13] net/ionic: fixes and optimizations Andrew Boyer
2021-01-18 20:34 ` [dpdk-dev] [PATCH 01/13] net/ionic: strip out unneeded interrupt code Andrew Boyer
2021-01-18 20:34 ` [dpdk-dev] [PATCH 02/13] net/ionic: observe endianness in firmware commands Andrew Boyer
2021-01-18 20:34 ` [dpdk-dev] [PATCH 03/13] net/ionic: observe endianness in Rx filter code Andrew Boyer
2021-01-18 20:34 ` Andrew Boyer [this message]
2021-01-27 17:22   ` [dpdk-dev] [PATCH 04/13] net/ionic: add an array-size macro Ferruh Yigit
2021-01-27 17:40     ` Andrew Boyer
2021-01-29 22:44   ` [dpdk-dev] [PATCH v2 4/13] net/ionic: use the existing " Andrew Boyer
2021-02-02 12:45     ` Ferruh Yigit
2021-01-18 20:35 ` [dpdk-dev] [PATCH 05/13] net/ionic: query firmware for supported queue versions Andrew Boyer
2021-01-18 20:35 ` [dpdk-dev] [PATCH 06/13] net/ionic: clean up Tx queue version support Andrew Boyer
2021-01-27 17:30   ` Ferruh Yigit
2021-01-27 17:46     ` Andrew Boyer
2021-01-29 22:44   ` [dpdk-dev] [PATCH v2 6/13] " Andrew Boyer
2021-02-02 12:46     ` Ferruh Yigit
2021-02-05 20:20     ` Thomas Monjalon
2021-02-05 20:26       ` Andrew Boyer
2021-02-05 20:34         ` Thomas Monjalon
2021-01-18 20:35 ` [dpdk-dev] [PATCH 07/13] net/ionic: inline queue flush function Andrew Boyer
2021-01-27 17:36   ` Ferruh Yigit
2021-01-27 17:43     ` Andrew Boyer
2021-01-27 17:50       ` Ferruh Yigit
2021-01-18 20:35 ` [dpdk-dev] [PATCH 08/13] net/ionic: inline queue space function Andrew Boyer
2021-01-18 20:35 ` [dpdk-dev] [PATCH 09/13] net/ionic: observe endiannness in ioread/iowrite Andrew Boyer
2021-01-18 20:35 ` [dpdk-dev] [PATCH 10/13] net/ionic: fix to allow separate L3 and L4 csum offload Andrew Boyer
2021-01-18 20:35 ` [dpdk-dev] [PATCH 11/13] net/ionic: convert per-queue offloads into queue flags Andrew Boyer
2021-01-18 20:35 ` [dpdk-dev] [PATCH 12/13] net/ionic: fix up function attribute tags Andrew Boyer
2021-01-18 20:35 ` [dpdk-dev] [PATCH 13/13] net/ionic: fix address handling in transmit code Andrew Boyer
2021-01-27 18:02 ` [dpdk-dev] [PATCH 00/13] net/ionic: fixes and optimizations Ferruh Yigit
2021-01-27 18:10   ` Andrew Boyer
2021-01-27 22:23     ` Ferruh Yigit
2021-01-27 22:25       ` Ferruh Yigit
2021-01-29 22:44 [dpdk-dev] [PATCH] net: redefine array size macros Andrew Boyer
2021-02-01 22:28 ` Thomas Monjalon
2021-02-01 22:32   ` Andrew Boyer
2021-02-02 12:30     ` Ferruh Yigit
2021-02-22 17:09       ` 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=20210118203508.1332-5-aboyer@pensando.io \
    --to=aboyer@pensando.io \
    --cc=cardigliano@ntop.org \
    --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).