]> git.droids-corp.org - dpdk.git/commitdiff
net/hns3: refactor adapter state dump
authorMin Hu (Connor) <humin29@huawei.com>
Thu, 14 Apr 2022 13:00:52 +0000 (21:00 +0800)
committerFerruh Yigit <ferruh.yigit@xilinx.com>
Thu, 5 May 2022 12:57:10 +0000 (14:57 +0200)
This patch refactors adapter state dump.

Fixes: 1a03c659cb9d ("net/hns3: dump device basic info")
Cc: stable@dpdk.org
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
drivers/net/hns3/hns3_ethdev_dump.c

index beffdd9e32af33674c26c7a388f47b582f80e5be..8b7a90a67e08681b453ddc3b93723f0fbf4e3e17 100644 (file)
 #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 *