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 24F64A0508; Thu, 14 Apr 2022 15:01:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 170D940F35; Thu, 14 Apr 2022 15:01:57 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 4B03840E64 for ; Thu, 14 Apr 2022 15:01:55 +0200 (CEST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KfKHf0rqrzBrxn for ; Thu, 14 Apr 2022 20:57:34 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 14 Apr 2022 21:01:53 +0800 From: "Min Hu (Connor)" To: CC: "Min Hu (Connor)" , Yisen Zhuang , Lijun Ou Subject: [PATCH 1/5] net/hns3: refactor adapter state dump Date: Thu, 14 Apr 2022 21:00:52 +0800 Message-ID: <20220414130056.37428-2-humin29@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220414130056.37428-1-humin29@huawei.com> References: <20220414130056.37428-1-humin29@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected 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 This patch refactor adapter state dump. Fixes: 1a03c659cb9d ("net/hns3: dump device basic info") Signed-off-by: Min Hu (Connor) --- drivers/net/hns3/hns3_ethdev_dump.c | 41 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev_dump.c b/drivers/net/hns3/hns3_ethdev_dump.c index beffdd9e32..8b7a90a67e 100644 --- a/drivers/net/hns3/hns3_ethdev_dump.c +++ b/drivers/net/hns3/hns3_ethdev_dump.c @@ -13,26 +13,31 @@ #include "hns3_rxtx.h" static const char * -get_adapter_state_name(uint32_t state) -{ - static const char * const state_name[] = { - "UNINITIALIZED", - "INITIALIZED", - "CONFIGURING", - "CONFIGURED", - "STARTING", - "STARTED", - "STOPPING", - "CLOSING", - "CLOSED", - "REMOVED", - "NSTATES" +get_adapter_state_name(enum hns3_adapter_state state) +{ + const struct { + enum hns3_adapter_state state; + const char *name; + } adapter_state_name[] = { + {HNS3_NIC_UNINITIALIZED, "UNINITIALIZED"}, + {HNS3_NIC_INITIALIZED, "INITIALIZED"}, + {HNS3_NIC_CONFIGURING, "CONFIGURING"}, + {HNS3_NIC_CONFIGURED, "CONFIGURED"}, + {HNS3_NIC_STARTING, "STARTING"}, + {HNS3_NIC_STARTED, "STARTED"}, + {HNS3_NIC_STOPPING, "STOPPING"}, + {HNS3_NIC_CLOSING, "CLOSING"}, + {HNS3_NIC_CLOSED, "CLOSED"}, + {HNS3_NIC_REMOVED, "REMOVED"}, + {HNS3_NIC_NSTATES, "NSTATES"}, }; + uint32_t i; - if (state < RTE_DIM(state_name)) - return state_name[state]; - else - return "unknown"; + for (i = 0; i < RTE_DIM(adapter_state_name); i++) + if (state == adapter_state_name[i].state) + return adapter_state_name[i].name; + + return "Unknown"; } static const char * -- 2.33.0