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 97E31A0A03; Mon, 18 Jan 2021 21:36:00 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D97D3140E44; Mon, 18 Jan 2021 21:35:42 +0100 (CET) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id 1A3F4140E31 for ; Mon, 18 Jan 2021 21:35:41 +0100 (CET) Received: by mail-pj1-f51.google.com with SMTP id my11so374853pjb.1 for ; Mon, 18 Jan 2021 12:35:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pensando.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5V0utI41IP4n5uHU/CUDc8Z62D/2K4NuChrdE9DQSYU=; b=XgTVj/o/f/G5Hs8AJkmJczEIXWUBdLntnc20aAARgD6M52dnalYQEwstjNlFwaqLJ4 DwPNg8puMFH2+EHeOIOAGmzpIQ+soXnSjGE7g4wpSRgE4FuoE261Aotw0sT322J7DD+E T94U7sWIhs8xfm0NBPFj5KGwAZPHWk5BHv1DBQI31vuNbNRHuq8sxUyLF1YBEwZyFfa4 pfStCoZnvET8n1nnmqbZUecisoKZxLtORZTUl3aQaKqWZj2P+KsLfKidjMIt22Rw7eix rFvvpYLSCRgrgUBV/K4A8k8ixIuyS+5wSy6/ad0K+8JZwFwSgeujD/4SdXBeZH4Otizw giTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5V0utI41IP4n5uHU/CUDc8Z62D/2K4NuChrdE9DQSYU=; b=f2HXJaUFTpx1p9ze47UKF6qvoFV1TsZ5/Y5xZ+31GnbXxqaXJbVC/QcvRpxCI0SksK 9aGTXvpdiyMtv5PBbbmrdaFKW6lVVo3sFB5N6KIsoW239HGG2C5u24bmCADiXT7ZTDK6 Nj2YMsmZp8ZNaRVEKMuatXN3VcJODeB0/n2xsj26273keAcBNqw9y3+zM3NnpJDMExOj 1d1OAv9iYwqzQoDCngv60Ai7XpGhq/zgeAfvfzpcpY5nSVwGMG2G4pBnrQeRw87Jz66r n55vIE618dp7LfJE1I7KCkhJFJCU+O4jzGBHL7UfUqbApBc/PVJgAZNkEgBbQKwkZHv5 4Q0w== X-Gm-Message-State: AOAM533YXc++Wo6X5Z3NBwBQ5mIojkn9SWIbjzfUvII3Btymn/iqqnCZ ifyIXsWZVrOFuBtgXUsuRhkzT7HrgxDYSw== X-Google-Smtp-Source: ABdhPJx60XZOAPToiiixnH2h3nL0xmNEKfjCp0raJMcev0L9aQvIQO2g8locIc7TOF2d6SotEoBHWw== X-Received: by 2002:a17:90a:bc49:: with SMTP id t9mr1145647pjv.95.1611002140091; Mon, 18 Jan 2021 12:35:40 -0800 (PST) Received: from driver-dev1.pensando.io ([12.226.153.42]) by smtp.gmail.com with ESMTPSA id g201sm795160pfb.81.2021.01.18.12.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 12:35:39 -0800 (PST) From: Andrew Boyer To: dev@dpdk.org Cc: Alfredo Cardigliano , Andrew Boyer Date: Mon, 18 Jan 2021 12:34:59 -0800 Message-Id: <20210118203508.1332-5-aboyer@pensando.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210118203508.1332-1-aboyer@pensando.io> References: <20210118203508.1332-1-aboyer@pensando.io> Subject: [dpdk-dev] [PATCH 04/13] net/ionic: add an array-size macro 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 Sender: "dev" Using the IONIC_ARRAY_SIZE() macro makes the code clearer. Signed-off-by: Andrew Boyer --- 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