[04/13] net/ionic: add an array-size macro
Checks
Commit Message
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(-)
Comments
On 1/18/2021 8:34 PM, Andrew Boyer wrote:
> Using the IONIC_ARRAY_SIZE() macro makes the code clearer.
>
> Signed-off-by: Andrew Boyer <aboyer@pensando.io>
There is already 'RTE_DIM' macro for it (in
'lib/librte_eal/include/rte_common.h'), what do you think using it instead of
creating a new one?
> On Jan 27, 2021, at 12:22 PM, Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> On 1/18/2021 8:34 PM, Andrew Boyer wrote:
>> Using the IONIC_ARRAY_SIZE() macro makes the code clearer.
>> Signed-off-by: Andrew Boyer <aboyer@pensando.io>
>
> There is already 'RTE_DIM' macro for it (in 'lib/librte_eal/include/rte_common.h'), what do you think using it instead of creating a new one?
>
Ah, I got fooled by NICVF_ARRAY_SIZE(), EFX_ARRAY_SIZE(), and friends. Will happily switch to RTE_DIM().
-Andrew
@@ -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);
@@ -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,
@@ -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);
@@ -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)
@@ -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))