RDMA: Introduce ib_port_phys_state enum
authorKamal Heib <kamalheib1@gmail.com>
Wed, 7 Aug 2019 10:31:35 +0000 (13:31 +0300)
committerDoug Ledford <dledford@redhat.com>
Mon, 12 Aug 2019 14:18:52 +0000 (10:18 -0400)
In order to improve readability, add ib_port_phys_state enum to replace
the use of magic numbers.

Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
Reviewed-by: Andrew Boyer <aboyer@tobark.org>
Acked-by: Michal Kalderon <michal.kalderon@marvell.com>
Acked-by: Bernard Metzler <bmt@zurich.ibm.com>
Link: https://lore.kernel.org/r/20190807103138.17219-2-kamalheib1@gmail.com
Signed-off-by: Doug Ledford <dledford@redhat.com>
15 files changed:
drivers/infiniband/core/sysfs.c
drivers/infiniband/hw/bnxt_re/ib_verbs.c
drivers/infiniband/hw/efa/efa_verbs.c
drivers/infiniband/hw/hns/hns_roce_device.h
drivers/infiniband/hw/hns/hns_roce_main.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
drivers/infiniband/hw/qedr/verbs.c
drivers/infiniband/hw/usnic/usnic_ib_verbs.c
drivers/infiniband/sw/rxe/rxe.h
drivers/infiniband/sw/rxe/rxe_param.h
drivers/infiniband/sw/rxe/rxe_verbs.c
drivers/infiniband/sw/siw/siw_verbs.c
include/rdma/ib_verbs.h

index b477295..7a50ced 100644 (file)
@@ -289,6 +289,24 @@ static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
                       ib_width_enum_to_int(attr.active_width), speed);
 }
 
+static const char *phys_state_to_str(enum ib_port_phys_state phys_state)
+{
+       static const char * phys_state_str[] = {
+               "<unknown>",
+               "Sleep",
+               "Polling",
+               "Disabled",
+               "PortConfigurationTraining",
+               "LinkUp",
+               "LinkErrorRecovery",
+               "Phy Test",
+       };
+
+       if (phys_state < ARRAY_SIZE(phys_state_str))
+               return phys_state_str[phys_state];
+       return "<unknown>";
+}
+
 static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
                               char *buf)
 {
@@ -300,16 +318,8 @@ static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
        if (ret)
                return ret;
 
-       switch (attr.phys_state) {
-       case 1:  return sprintf(buf, "1: Sleep\n");
-       case 2:  return sprintf(buf, "2: Polling\n");
-       case 3:  return sprintf(buf, "3: Disabled\n");
-       case 4:  return sprintf(buf, "4: PortConfigurationTraining\n");
-       case 5:  return sprintf(buf, "5: LinkUp\n");
-       case 6:  return sprintf(buf, "6: LinkErrorRecovery\n");
-       case 7:  return sprintf(buf, "7: Phy Test\n");
-       default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
-       }
+       return sprintf(buf, "%d: %s\n", attr.phys_state,
+                      phys_state_to_str(attr.phys_state));
 }
 
 static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
index 098ab88..f9e97d0 100644 (file)
@@ -220,10 +220,10 @@ int bnxt_re_query_port(struct ib_device *ibdev, u8 port_num,
 
        if (netif_running(rdev->netdev) && netif_carrier_ok(rdev->netdev)) {
                port_attr->state = IB_PORT_ACTIVE;
-               port_attr->phys_state = 5;
+               port_attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        } else {
                port_attr->state = IB_PORT_DOWN;
-               port_attr->phys_state = 3;
+               port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
        }
        port_attr->max_mtu = IB_MTU_4096;
        port_attr->active_mtu = iboe_get_mtu(rdev->netdev->mtu);
index 32d3b3d..70851bd 100644 (file)
@@ -333,7 +333,7 @@ int efa_query_port(struct ib_device *ibdev, u8 port,
        props->lmc = 1;
 
        props->state = IB_PORT_ACTIVE;
-       props->phys_state = 5;
+       props->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        props->gid_tbl_len = 1;
        props->pkey_tbl_len = 1;
        props->active_speed = IB_SPEED_EDR;
index b39497a..12a2b85 100644 (file)
@@ -989,16 +989,6 @@ struct hns_roce_hw {
        const struct ib_device_ops *hns_roce_dev_srq_ops;
 };
 
-enum hns_phy_state {
-       HNS_ROCE_PHY_SLEEP              = 1,
-       HNS_ROCE_PHY_POLLING            = 2,
-       HNS_ROCE_PHY_DISABLED           = 3,
-       HNS_ROCE_PHY_TRAINING           = 4,
-       HNS_ROCE_PHY_LINKUP             = 5,
-       HNS_ROCE_PHY_LINKERR            = 6,
-       HNS_ROCE_PHY_TEST               = 7
-};
-
 struct hns_roce_dev {
        struct ib_device        ib_dev;
        struct platform_device  *pdev;
index 1e4ba48..1b757cc 100644 (file)
@@ -262,7 +262,8 @@ static int hns_roce_query_port(struct ib_device *ib_dev, u8 port_num,
        props->state = (netif_running(net_dev) && netif_carrier_ok(net_dev)) ?
                        IB_PORT_ACTIVE : IB_PORT_DOWN;
        props->phys_state = (props->state == IB_PORT_ACTIVE) ?
-                            HNS_ROCE_PHY_LINKUP : HNS_ROCE_PHY_DISABLED;
+                            IB_PORT_PHYS_STATE_LINK_UP :
+                            IB_PORT_PHYS_STATE_DISABLED;
 
        spin_unlock_irqrestore(&hr_dev->iboe.lock, flags);
 
index 8790101..8d2f1e3 100644 (file)
@@ -734,7 +734,8 @@ out:
 
 static u8 state_to_phys_state(enum ib_port_state state)
 {
-       return state == IB_PORT_ACTIVE ? 5 : 3;
+       return state == IB_PORT_ACTIVE ?
+               IB_PORT_PHYS_STATE_LINK_UP : IB_PORT_PHYS_STATE_DISABLED;
 }
 
 static int eth_link_query_port(struct ib_device *ibdev, u8 port,
index 4a3d700..af1986b 100644 (file)
@@ -535,7 +535,7 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
        props->max_msg_sz       = 1 << MLX5_CAP_GEN(dev->mdev, log_max_msg);
        props->pkey_tbl_len     = 1;
        props->state            = IB_PORT_DOWN;
-       props->phys_state       = 3;
+       props->phys_state       = IB_PORT_PHYS_STATE_DISABLED;
 
        mlx5_query_nic_vport_qkey_viol_cntr(mdev, &qkey_viol_cntr);
        props->qkey_viol_cntr = qkey_viol_cntr;
@@ -561,7 +561,7 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
 
        if (netif_running(ndev) && netif_carrier_ok(ndev)) {
                props->state      = IB_PORT_ACTIVE;
-               props->phys_state = 5;
+               props->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        }
 
        ndev_ib_mtu = iboe_get_mtu(ndev->mtu);
index bccc113..e8267e5 100644 (file)
@@ -163,10 +163,10 @@ int ocrdma_query_port(struct ib_device *ibdev,
        netdev = dev->nic_info.netdev;
        if (netif_running(netdev) && netif_oper_up(netdev)) {
                port_state = IB_PORT_ACTIVE;
-               props->phys_state = 5;
+               props->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        } else {
                port_state = IB_PORT_DOWN;
-               props->phys_state = 3;
+               props->phys_state = IB_PORT_PHYS_STATE_DISABLED;
        }
        props->max_mtu = IB_MTU_4096;
        props->active_mtu = iboe_get_mtu(netdev->mtu);
index 0c6a4bc..6f3ce86 100644 (file)
@@ -221,10 +221,10 @@ int qedr_query_port(struct ib_device *ibdev, u8 port, struct ib_port_attr *attr)
        /* *attr being zeroed by the caller, avoid zeroing it here */
        if (rdma_port->port_state == QED_RDMA_PORT_UP) {
                attr->state = IB_PORT_ACTIVE;
-               attr->phys_state = 5;
+               attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        } else {
                attr->state = IB_PORT_DOWN;
-               attr->phys_state = 3;
+               attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
        }
        attr->max_mtu = IB_MTU_4096;
        attr->active_mtu = iboe_get_mtu(dev->ndev->mtu);
index a354c7c..556b8e4 100644 (file)
@@ -356,13 +356,14 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
 
        if (!us_ibdev->ufdev->link_up) {
                props->state = IB_PORT_DOWN;
-               props->phys_state = 3;
+               props->phys_state = IB_PORT_PHYS_STATE_DISABLED;
        } else if (!us_ibdev->ufdev->inaddr) {
                props->state = IB_PORT_INIT;
-               props->phys_state = 4;
+               props->phys_state =
+                       IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING;
        } else {
                props->state = IB_PORT_ACTIVE;
-               props->phys_state = 5;
+               props->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        }
 
        props->port_cap_flags = 0;
index ecf6e65..fb07eed 100644 (file)
  */
 #define RXE_UVERBS_ABI_VERSION         2
 
-#define RDMA_LINK_PHYS_STATE_LINK_UP   (5)
-#define RDMA_LINK_PHYS_STATE_DISABLED  (3)
-#define RDMA_LINK_PHYS_STATE_POLLING   (2)
-
 #define RXE_ROCE_V2_SPORT              (0xc000)
 
 static inline u32 rxe_crc32(struct rxe_dev *rxe,
index 1abed47..fe52073 100644 (file)
@@ -154,7 +154,7 @@ enum rxe_port_param {
        RXE_PORT_ACTIVE_WIDTH           = IB_WIDTH_1X,
        RXE_PORT_ACTIVE_SPEED           = 1,
        RXE_PORT_PKEY_TBL_LEN           = 64,
-       RXE_PORT_PHYS_STATE             = 2,
+       RXE_PORT_PHYS_STATE             = IB_PORT_PHYS_STATE_POLLING,
        RXE_PORT_SUBNET_PREFIX          = 0xfe80000000000000ULL,
 };
 
index 4ebdfcf..623129f 100644 (file)
@@ -69,11 +69,11 @@ static int rxe_query_port(struct ib_device *dev,
                              &attr->active_width);
 
        if (attr->state == IB_PORT_ACTIVE)
-               attr->phys_state = RDMA_LINK_PHYS_STATE_LINK_UP;
+               attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
        else if (dev_get_flags(rxe->ndev) & IFF_UP)
-               attr->phys_state = RDMA_LINK_PHYS_STATE_POLLING;
+               attr->phys_state = IB_PORT_PHYS_STATE_POLLING;
        else
-               attr->phys_state = RDMA_LINK_PHYS_STATE_DISABLED;
+               attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
 
        mutex_unlock(&rxe->usdev_lock);
 
index 32dc79d..404e7ca 100644 (file)
@@ -206,7 +206,8 @@ int siw_query_port(struct ib_device *base_dev, u8 port,
        attr->gid_tbl_len = 1;
        attr->max_msg_sz = -1;
        attr->max_mtu = ib_mtu_int_to_enum(sdev->netdev->mtu);
-       attr->phys_state = sdev->state == IB_PORT_ACTIVE ? 5 : 3;
+       attr->phys_state = sdev->state == IB_PORT_ACTIVE ?
+               IB_PORT_PHYS_STATE_LINK_UP : IB_PORT_PHYS_STATE_DISABLED;
        attr->pkey_tbl_len = 1;
        attr->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_DEVICE_MGMT_SUP;
        attr->state = sdev->state;
index 0ecda7d..3914990 100644 (file)
@@ -493,6 +493,16 @@ enum ib_port_state {
        IB_PORT_ACTIVE_DEFER    = 5
 };
 
+enum ib_port_phys_state {
+       IB_PORT_PHYS_STATE_SLEEP = 1,
+       IB_PORT_PHYS_STATE_POLLING = 2,
+       IB_PORT_PHYS_STATE_DISABLED = 3,
+       IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
+       IB_PORT_PHYS_STATE_LINK_UP = 5,
+       IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
+       IB_PORT_PHYS_STATE_PHY_TEST = 7,
+};
+
 enum ib_port_width {
        IB_WIDTH_1X     = 1,
        IB_WIDTH_2X     = 16,