Skip to contentSkip to conversation

RDMA: Cleanups and improvements

PATCH Superseded Kamal Heib 5 participants 10 messages Jul 31, 2019 – Aug 1, 2019

Subsystems (10)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kamal Heib

author
#0 lore raw

v2 cover RDMA: Cleanups and improvements

This series includes few cleanups and improvements, the first patch introduce a new enum for describing the physical state values and use it instead of using the magic numbers, patch 2-4 add support for a common query port for iWARP drivers and remove the common code from the iWARP drivers.

Changes from v1 :
- Patch #3:
-- Delete __ prefix.
-- Add missing dev_put(netdev);
-- Initilize gid to {}.
-- Return error code directly.

Kamal Heib (4):
RDMA: Introduce ib_port_phys_state enum
RDMA/cxgb3: Use ib_device_set_netdev()
RDMA/core: Add common iWARP query port
RDMA/{cxgb3, cxgb4, i40iw}: Remove common code

 drivers/infiniband/core/device.c             | 87 ++++++++++++++++----
 drivers/infiniband/core/sysfs.c              | 24 ++++--
 drivers/infiniband/hw/bnxt_re/ib_verbs.c     |  4 +-
 drivers/infiniband/hw/cxgb3/iwch_provider.c  | 45 +++++-----
 drivers/infiniband/hw/cxgb4/provider.c       | 24 ------
 drivers/infiniband/hw/efa/efa_verbs.c        |  2 +-
 drivers/infiniband/hw/i40iw/i40iw_verbs.c    | 11 ---
 drivers/infiniband/hw/mlx5/main.c            |  4 +-
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c  |  4 +-
 drivers/infiniband/hw/qedr/verbs.c           |  4 +-
 drivers/infiniband/hw/usnic/usnic_ib_verbs.c |  7 +-
 drivers/infiniband/sw/rxe/rxe.h              |  4 -
 drivers/infiniband/sw/rxe/rxe_param.h        |  2 +-
 drivers/infiniband/sw/rxe/rxe_verbs.c        |  6 +-
 drivers/infiniband/sw/siw/siw_verbs.c        |  3 +-
 include/rdma/ib_verbs.h                      | 10 +++
 16 files changed, 136 insertions(+), 105 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v2 1/4 RDMA: Introduce ib_port_phys_state enum

In order to improve readability, add ib_port_phys_state enum to replace the use of magic numbers.

---
 drivers/infiniband/core/sysfs.c              | 24 +++++++++++++-------
 drivers/infiniband/hw/bnxt_re/ib_verbs.c     |  4 ++--
 drivers/infiniband/hw/efa/efa_verbs.c        |  2 +-
 drivers/infiniband/hw/mlx5/main.c            |  4 ++--
 drivers/infiniband/hw/ocrdma/ocrdma_verbs.c  |  4 ++--
 drivers/infiniband/hw/qedr/verbs.c           |  4 ++--
 drivers/infiniband/hw/usnic/usnic_ib_verbs.c |  7 +++---
 drivers/infiniband/sw/rxe/rxe.h              |  4 ----
 drivers/infiniband/sw/rxe/rxe_param.h        |  2 +-
 drivers/infiniband/sw/rxe/rxe_verbs.c        |  6 ++---
 drivers/infiniband/sw/siw/siw_verbs.c        |  3 ++-
 include/rdma/ib_verbs.h                      | 10 ++++++++
 12 files changed, 45 insertions(+), 29 deletions(-)
drivers/infiniband/core/sysfs.c +16 -8
index b477295a96c2..46722e04f6e1 100644
@@ -301,14 +301,22 @@ static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
 		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);
+	case IB_PORT_PHYS_STATE_SLEEP:
+		return sprintf(buf, "1: Sleep\n");
+	case IB_PORT_PHYS_STATE_POLLING:
+		return sprintf(buf, "2: Polling\n");
+	case IB_PORT_PHYS_STATE_DISABLED:
+		return sprintf(buf, "3: Disabled\n");
+	case IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING:
+		return sprintf(buf, "4: PortConfigurationTraining\n");
+	case IB_PORT_PHYS_STATE_LINK_UP:
+		return sprintf(buf, "5: LinkUp\n");
+	case IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY:
+		return sprintf(buf, "6: LinkErrorRecovery\n");
+	case IB_PORT_PHYS_STATE_PHY_TEST:
+		return sprintf(buf, "7: Phy Test\n");
+	default:
+		return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
 	}
 }
 
drivers/infiniband/hw/bnxt_re/ib_verbs.c +2 -2
index a91653aabf38..ca6306c24881 100644
@@ -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);
drivers/infiniband/hw/efa/efa_verbs.c +1 -1
index df77bc312a25..f36071a92f97 100644
@@ -306,7 +306,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;
drivers/infiniband/hw/mlx5/main.c +2 -2
index c2a5780cb394..bc4d7dca170f 100644
@@ -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);
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -2
index bccc11378109..e8267e590772 100644
@@ -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);
drivers/infiniband/hw/qedr/verbs.c +2 -2
index 27d90a84ea01..1373312aec58 100644
@@ -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);
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +4 -3
index eeb07b245ef9..4f8f1d3eb559 100644
@@ -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;
drivers/infiniband/sw/rxe/rxe.h +0 -4
index ecf6e659c0da..fb07eed9e402 100644
@@ -65,10 +65,6 @@
  */
 #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,
drivers/infiniband/sw/rxe/rxe_param.h +1 -1
index 1abed47ca221..fe5207386700 100644
@@ -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,
 };
 
drivers/infiniband/sw/rxe/rxe_verbs.c +3 -3
index 4ebdfcf4d33e..623129f27f5a 100644
@@ -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);
 
drivers/infiniband/sw/siw/siw_verbs.c +2 -1
index 32dc79d0e898..404e7ca4b30c 100644
@@ -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;
include/rdma/ib_verbs.h +10 -0
index c5f8a9f17063..27fe844cff42 100644
@@ -451,6 +451,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,
Signature · 1 line
2.20.1
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH for-next V2 1/4] RDMA: Introduce ib_port_phys_state enum

Thanks! I meant to do this two years ago.

Quoted 249 lines · Kamal Heib

In order to improve readability, add ib_port_phys_state enum to replace the use of magic numbers.

---

drivers/infiniband/core/sysfs.c              | 24 +++++++++++++-------
drivers/infiniband/hw/bnxt_re/ib_verbs.c     |  4 ++--
drivers/infiniband/hw/efa/efa_verbs.c        |  2 +-
drivers/infiniband/hw/mlx5/main.c            |  4 ++--
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c  |  4 ++--
drivers/infiniband/hw/qedr/verbs.c           |  4 ++--
drivers/infiniband/hw/usnic/usnic_ib_verbs.c |  7 +++---
drivers/infiniband/sw/rxe/rxe.h              |  4 ----
drivers/infiniband/sw/rxe/rxe_param.h        |  2 +-
drivers/infiniband/sw/rxe/rxe_verbs.c        |  6 ++---
drivers/infiniband/sw/siw/siw_verbs.c        |  3 ++-
include/rdma/ib_verbs.h                      | 10 ++++++++
12 files changed, 45 insertions(+), 29 deletions(-)
drivers/infiniband/core/sysfs.c +16 -8
index b477295a96c2..46722e04f6e1 100644
@@ -301,14 +301,22 @@ static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
 		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);
+	case IB_PORT_PHYS_STATE_SLEEP:
+		return sprintf(buf, "1: Sleep\n");
+	case IB_PORT_PHYS_STATE_POLLING:
+		return sprintf(buf, "2: Polling\n");
+	case IB_PORT_PHYS_STATE_DISABLED:
+		return sprintf(buf, "3: Disabled\n");
+	case IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING:
+		return sprintf(buf, "4: PortConfigurationTraining\n");
+	case IB_PORT_PHYS_STATE_LINK_UP:
+		return sprintf(buf, "5: LinkUp\n");
+	case IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY:
+		return sprintf(buf, "6: LinkErrorRecovery\n");
+	case IB_PORT_PHYS_STATE_PHY_TEST:
+		return sprintf(buf, "7: Phy Test\n");
+	default:
+		return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
 	}
 }
 
drivers/infiniband/hw/bnxt_re/ib_verbs.c +2 -2
index a91653aabf38..ca6306c24881 100644
@@ -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);
drivers/infiniband/hw/efa/efa_verbs.c +1 -1
index df77bc312a25..f36071a92f97 100644
@@ -306,7 +306,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;
drivers/infiniband/hw/mlx5/main.c +2 -2
index c2a5780cb394..bc4d7dca170f 100644
@@ -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);
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -2
index bccc11378109..e8267e590772 100644
@@ -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);
drivers/infiniband/hw/qedr/verbs.c +2 -2
index 27d90a84ea01..1373312aec58 100644
@@ -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);
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +4 -3
index eeb07b245ef9..4f8f1d3eb559 100644
@@ -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;
drivers/infiniband/sw/rxe/rxe.h +0 -4
index ecf6e659c0da..fb07eed9e402 100644
@@ -65,10 +65,6 @@
 */
 #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,
drivers/infiniband/sw/rxe/rxe_param.h +1 -1
index 1abed47ca221..fe5207386700 100644
@@ -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,
 };
 
drivers/infiniband/sw/rxe/rxe_verbs.c +3 -3
index 4ebdfcf4d33e..623129f27f5a 100644
@@ -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);
 
drivers/infiniband/sw/siw/siw_verbs.c +2 -1
index 32dc79d0e898..404e7ca4b30c 100644
@@ -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;
include/rdma/ib_verbs.h +10 -0
index c5f8a9f17063..27fe844cff42 100644
@@ -451,6 +451,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,
Signature · 1 line
2.20.1
Acked-by
#3 lore raw

Re: [PATCH for-next V2 1/4] RDMA: Introduce ib_port_phys_state enum

Quoted 238 lines · Andrew Boyer

Thanks! I meant to do this two years ago.

Quoted 233 lines · Kamal Heib

In order to improve readability, add ib_port_phys_state enum to replace the use of magic numbers.

---

drivers/infiniband/core/sysfs.c              | 24 +++++++++++++-------
drivers/infiniband/hw/bnxt_re/ib_verbs.c     |  4 ++--
drivers/infiniband/hw/efa/efa_verbs.c        |  2 +-
drivers/infiniband/hw/mlx5/main.c            |  4 ++--
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c  |  4 ++--
drivers/infiniband/hw/qedr/verbs.c           |  4 ++--
drivers/infiniband/hw/usnic/usnic_ib_verbs.c |  7 +++---
drivers/infiniband/sw/rxe/rxe.h              |  4 ----
drivers/infiniband/sw/rxe/rxe_param.h        |  2 +-
drivers/infiniband/sw/rxe/rxe_verbs.c        |  6 ++---
drivers/infiniband/sw/siw/siw_verbs.c        |  3 ++-
include/rdma/ib_verbs.h                      | 10 ++++++++
12 files changed, 45 insertions(+), 29 deletions(-)
drivers/infiniband/core/sysfs.c +16 -8
index b477295a96c2..46722e04f6e1 100644
@@ -301,14 +301,22 @@ static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
              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);
+     case IB_PORT_PHYS_STATE_SLEEP:
+             return sprintf(buf, "1: Sleep\n");
+     case IB_PORT_PHYS_STATE_POLLING:
+             return sprintf(buf, "2: Polling\n");
+     case IB_PORT_PHYS_STATE_DISABLED:
+             return sprintf(buf, "3: Disabled\n");
+     case IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING:
+             return sprintf(buf, "4: PortConfigurationTraining\n");
+     case IB_PORT_PHYS_STATE_LINK_UP:
+             return sprintf(buf, "5: LinkUp\n");
+     case IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY:
+             return sprintf(buf, "6: LinkErrorRecovery\n");
+     case IB_PORT_PHYS_STATE_PHY_TEST:
+             return sprintf(buf, "7: Phy Test\n");
+     default:
+             return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
      }
 }
 
drivers/infiniband/hw/bnxt_re/ib_verbs.c +2 -2
index a91653aabf38..ca6306c24881 100644
@@ -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);
drivers/infiniband/hw/efa/efa_verbs.c +1 -1
index df77bc312a25..f36071a92f97 100644
@@ -306,7 +306,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;
drivers/infiniband/hw/mlx5/main.c +2 -2
index c2a5780cb394..bc4d7dca170f 100644
@@ -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);
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +2 -2
index bccc11378109..e8267e590772 100644
@@ -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);
drivers/infiniband/hw/qedr/verbs.c +2 -2
index 27d90a84ea01..1373312aec58 100644
@@ -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);
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +4 -3
index eeb07b245ef9..4f8f1d3eb559 100644
@@ -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;
drivers/infiniband/sw/rxe/rxe.h +0 -4
index ecf6e659c0da..fb07eed9e402 100644
@@ -65,10 +65,6 @@
 */
 #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,
drivers/infiniband/sw/rxe/rxe_param.h +1 -1
index 1abed47ca221..fe5207386700 100644
@@ -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,
 };
 
drivers/infiniband/sw/rxe/rxe_verbs.c +3 -3
index 4ebdfcf4d33e..623129f27f5a 100644
@@ -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);
 
drivers/infiniband/sw/siw/siw_verbs.c +2 -1
index 32dc79d0e898..404e7ca4b30c 100644
@@ -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;
include/rdma/ib_verbs.h +0 -0
index c5f8a9f17063..27fe844cff42 100644
@@ -451,6 +451,16 @@ enum ib_port_state {
      IB_PORT_ACTIVE_DEFER    = 5
 };
 
Quoted 17 lines
Quoted 14 lines
include/rdma/ib_verbs.h +10 -1
+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,
--
Quoted 2 lines

2.20.1

Ack'ing for bnxt_re

author
#4 lore raw

PATCH v2 2/4 RDMA/cxgb3: Use ib_device_set_netdev()

In reply to Kamal Heib

This change is required to associate the cxgb3 ib_dev with the underlying net_device, so in the upcoming patch we can call ib_device_get_netdev().

---
 drivers/infiniband/hw/cxgb3/iwch_provider.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/infiniband/hw/cxgb3/iwch_provider.c +20 -0
index e775c1a1a450..5848e4727b2e 100644
@@ -1273,8 +1273,24 @@ static const struct ib_device_ops iwch_dev_ops = {
 	INIT_RDMA_OBJ_SIZE(ib_ucontext, iwch_ucontext, ibucontext),
 };
 
+static int set_netdevs(struct ib_device *ib_dev, struct cxio_rdev *rdev)
+{
+	int ret;
+	int i;
+
+	for (i = 0; i < rdev->port_info.nports; i++) {
+		ret = ib_device_set_netdev(ib_dev, rdev->port_info.lldevs[i],
+					   i + 1);
+		if (ret)
+			return ret;
+	}
+	return 0;
+}
+
 int iwch_register_device(struct iwch_dev *dev)
 {
+	int err;
+
 	pr_debug("%s iwch_dev %p\n", __func__, dev);
 	memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
 	memcpy(&dev->ibdev.node_guid, dev->rdev.t3cdev_p->lldev->dev_addr, 6);
@@ -1315,6 +1331,10 @@ int iwch_register_device(struct iwch_dev *dev)
 
 	rdma_set_device_sysfs_group(&dev->ibdev, &iwch_attr_group);
 	ib_set_device_ops(&dev->ibdev, &iwch_dev_ops);
+	err = set_netdevs(&dev->ibdev, &dev->rdev);
+	if (err)
+		return err;
+
 	return ib_register_device(&dev->ibdev, "cxgb3_%d");
 }
 
Signature · 1 line
2.20.1
author
#5 lore raw

PATCH v2 3/4 RDMA/core: Add common iWARP query port

In reply to Kamal Heib

Add support for a common iWARP query port function, the new function includes a common code that is used by the iWARP devices to update the port attributes like max_mtu, active_mtu, state, and phys_state, the function also includes a call for the driver-specific query_port callback to query the device-specific port attributes.

---
 drivers/infiniband/core/device.c | 87 ++++++++++++++++++++++++++------
 1 file changed, 71 insertions(+), 16 deletions(-)
drivers/infiniband/core/device.c +71 -16
index 9773145dee09..860c08ca49e7 100644
@@ -1940,31 +1940,64 @@ void ib_dispatch_event(struct ib_event *event)
 }
 EXPORT_SYMBOL(ib_dispatch_event);
 
-/**
- * ib_query_port - Query IB port attributes
- * @device:Device to query
- * @port_num:Port number to query
- * @port_attr:Port attributes
- *
- * ib_query_port() returns the attributes of a port through the
- * @port_attr pointer.
- */
-int ib_query_port(struct ib_device *device,
-		  u8 port_num,
-		  struct ib_port_attr *port_attr)
+static int iw_query_port(struct ib_device *device,
+			   u8 port_num,
+			   struct ib_port_attr *port_attr)
 {
-	union ib_gid gid;
+	struct in_device *inetdev;
+	struct net_device *netdev;
 	int err;
 
-	if (!rdma_is_port_valid(device, port_num))
-		return -EINVAL;
+	memset(port_attr, 0, sizeof(*port_attr));
+
+	netdev = ib_device_get_netdev(device, port_num);
+	if (!netdev)
+		return -ENODEV;
+
+	dev_put(netdev);
+
+	port_attr->max_mtu = IB_MTU_4096;
+	port_attr->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
+
+	if (!netif_carrier_ok(netdev)) {
+		port_attr->state = IB_PORT_DOWN;
+		port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
+	} else {
+		inetdev = in_dev_get(netdev);
+
+		if (inetdev && inetdev->ifa_list) {
+			port_attr->state = IB_PORT_ACTIVE;
+			port_attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
+			in_dev_put(inetdev);
+		} else {
+			port_attr->state = IB_PORT_INIT;
+			port_attr->phys_state =
+				IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING;
+		}
+	}
+
+	err = device->ops.query_port(device, port_num, port_attr);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int __ib_query_port(struct ib_device *device,
+			   u8 port_num,
+			   struct ib_port_attr *port_attr)
+{
+	union ib_gid gid = {};
+	int err;
 
 	memset(port_attr, 0, sizeof(*port_attr));
+
 	err = device->ops.query_port(device, port_num, port_attr);
 	if (err || port_attr->subnet_prefix)
 		return err;
 
-	if (rdma_port_get_link_layer(device, port_num) != IB_LINK_LAYER_INFINIBAND)
+	if (rdma_port_get_link_layer(device, port_num) !=
+	    IB_LINK_LAYER_INFINIBAND)
 		return 0;
 
 	err = device->ops.query_gid(device, port_num, 0, &gid);
@@ -1974,6 +2007,28 @@ int ib_query_port(struct ib_device *device,
 	port_attr->subnet_prefix = be64_to_cpu(gid.global.subnet_prefix);
 	return 0;
 }
+
+/**
+ * ib_query_port - Query IB port attributes
+ * @device:Device to query
+ * @port_num:Port number to query
+ * @port_attr:Port attributes
+ *
+ * ib_query_port() returns the attributes of a port through the
+ * @port_attr pointer.
+ */
+int ib_query_port(struct ib_device *device,
+		  u8 port_num,
+		  struct ib_port_attr *port_attr)
+{
+	if (!rdma_is_port_valid(device, port_num))
+		return -EINVAL;
+
+	if (rdma_node_get_transport(device->node_type) == RDMA_TRANSPORT_IWARP)
+		return iw_query_port(device, port_num, port_attr);
+	else
+		return __ib_query_port(device, port_num, port_attr);
+}
 EXPORT_SYMBOL(ib_query_port);
 
 static void add_ndev_hash(struct ib_port_data *pdata)
Signature · 1 line
2.20.1
maintainer
#6 lore raw

RE: [PATCH for-next V2 3/4] RDMA/core: Add common iWARP query port

Quoted 9 lines

From: [email protected] <linux-rdma- [email protected]> On Behalf Of Kamal Heib

Add support for a common iWARP query port function, the new function includes a common code that is used by the iWARP devices to update the port attributes like max_mtu, active_mtu, state, and phys_state, the function also includes a call for the driver-specific query_port callback to query the device-specific port attributes.

Thanks, the qedr is also a iWARP device but it has most of the code common with The RoCE part, so we'll need to split the code earlier between the protocols. However, why not make the code for port-state and mtu common for Both iWARP + RoCE?

Quoted 115 lines
---
 drivers/infiniband/core/device.c | 87 ++++++++++++++++++++++++++------
 1 file changed, 71 insertions(+), 16 deletions(-)
drivers/infiniband/core/device.c +49 -16
index 9773145dee09..860c08ca49e7 100644
@@ -1940,31 +1940,64 @@ void ib_dispatch_event(struct ib_event *event)
 }  EXPORT_SYMBOL(ib_dispatch_event);
 
-/**
- * ib_query_port - Query IB port attributes
- * @device:Device to query
- * @port_num:Port number to query
- * @port_attr:Port attributes
- *
- * ib_query_port() returns the attributes of a port through the
- * @port_attr pointer.
- */
-int ib_query_port(struct ib_device *device,
-		  u8 port_num,
-		  struct ib_port_attr *port_attr)
+static int iw_query_port(struct ib_device *device,
+			   u8 port_num,
+			   struct ib_port_attr *port_attr)
 {
-	union ib_gid gid;
+	struct in_device *inetdev;
+	struct net_device *netdev;
 	int err;
 
-	if (!rdma_is_port_valid(device, port_num))
-		return -EINVAL;
+	memset(port_attr, 0, sizeof(*port_attr));
+
+	netdev = ib_device_get_netdev(device, port_num);
+	if (!netdev)
+		return -ENODEV;
+
+	dev_put(netdev);
+
+	port_attr->max_mtu = IB_MTU_4096;
+	port_attr->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
+
+	if (!netif_carrier_ok(netdev)) {
+		port_attr->state = IB_PORT_DOWN;
+		port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
+	} else {
+		inetdev = in_dev_get(netdev);
+
+		if (inetdev && inetdev->ifa_list) {
+			port_attr->state = IB_PORT_ACTIVE;
+			port_attr->phys_state =
 IB_PORT_PHYS_STATE_LINK_UP;
+			in_dev_put(inetdev);
+		} else {
+			port_attr->state = IB_PORT_INIT;
+			port_attr->phys_state =
+
 	IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING;
+		}
+	}
+
+	err = device->ops.query_port(device, port_num, port_attr);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int __ib_query_port(struct ib_device *device,
+			   u8 port_num,
+			   struct ib_port_attr *port_attr)
+{
+	union ib_gid gid = {};
+	int err;
 
 	memset(port_attr, 0, sizeof(*port_attr));
+
 	err = device->ops.query_port(device, port_num, port_attr);
 	if (err || port_attr->subnet_prefix)
 		return err;
 
-	if (rdma_port_get_link_layer(device, port_num) !=
 IB_LINK_LAYER_INFINIBAND)
+	if (rdma_port_get_link_layer(device, port_num) !=
+	    IB_LINK_LAYER_INFINIBAND)
 		return 0;
drivers/infiniband/core/device.c +19 -0
 	err = device->ops.query_gid(device, port_num, 0, &gid); @@ -1974,6
+2007,28 @@ int ib_query_port(struct ib_device *device,
 	port_attr->subnet_prefix = be64_to_cpu(gid.global.subnet_prefix);
 	return 0;
 }
+
+/**
+ * ib_query_port - Query IB port attributes
+ * @device:Device to query
+ * @port_num:Port number to query
+ * @port_attr:Port attributes
+ *
+ * ib_query_port() returns the attributes of a port through the
+ * @port_attr pointer.
+ */
+int ib_query_port(struct ib_device *device,
+		  u8 port_num,
+		  struct ib_port_attr *port_attr)
+{
+	if (!rdma_is_port_valid(device, port_num))
+		return -EINVAL;
+
+	if (rdma_node_get_transport(device->node_type) ==
Quoted 1 line

RDMA_TRANSPORT_IWARP)

Raising a question, in some places we use the macro above and in others rdma_protocol_iwarp(device, port_num), any reason to prefer one over the other ?
thanks,

Quoted 8 lines
drivers/infiniband/core/device.c +3 -1
+		return iw_query_port(device, port_num, port_attr);
+	else
+		return __ib_query_port(device, port_num, port_attr); }
 EXPORT_SYMBOL(ib_query_port);
 
 static void add_ndev_hash(struct ib_port_data *pdata)
--

2.20.1

author
#7 lore raw

Re: [PATCH for-next V2 3/4] RDMA/core: Add common iWARP query port

Quoted 11 lines · Michal Kalderon
Quoted 9 lines

From: [email protected] <linux-rdma- [email protected]> On Behalf Of Kamal Heib

Add support for a common iWARP query port function, the new function includes a common code that is used by the iWARP devices to update the port attributes like max_mtu, active_mtu, state, and phys_state, the function also includes a call for the driver-specific query_port callback to query the device-specific port attributes.

Thanks, the qedr is also a iWARP device but it has most of the code common with The RoCE part, so we'll need to split the code earlier between the protocols.

Yes, That's why I decided not to touch it.

Quoted 2 lines

However, why not make the code for port-state and mtu common for Both iWARP + RoCE?

I don't think that this is a good idea because they don't share the same code for determining the port-state and mtu (please see mlx4/mlx5 v.s. other iWARP drivers), while it is the same code for all iWARP drivers.

Quoted 110 lines
Quoted 110 lines
---
 drivers/infiniband/core/device.c | 87 ++++++++++++++++++++++++++------
 1 file changed, 71 insertions(+), 16 deletions(-)
drivers/infiniband/core/device.c +49 -16
index 9773145dee09..860c08ca49e7 100644
@@ -1940,31 +1940,64 @@ void ib_dispatch_event(struct ib_event *event)
 }  EXPORT_SYMBOL(ib_dispatch_event);
 
-/**
- * ib_query_port - Query IB port attributes
- * @device:Device to query
- * @port_num:Port number to query
- * @port_attr:Port attributes
- *
- * ib_query_port() returns the attributes of a port through the
- * @port_attr pointer.
- */
-int ib_query_port(struct ib_device *device,
-		  u8 port_num,
-		  struct ib_port_attr *port_attr)
+static int iw_query_port(struct ib_device *device,
+			   u8 port_num,
+			   struct ib_port_attr *port_attr)
 {
-	union ib_gid gid;
+	struct in_device *inetdev;
+	struct net_device *netdev;
 	int err;
 
-	if (!rdma_is_port_valid(device, port_num))
-		return -EINVAL;
+	memset(port_attr, 0, sizeof(*port_attr));
+
+	netdev = ib_device_get_netdev(device, port_num);
+	if (!netdev)
+		return -ENODEV;
+
+	dev_put(netdev);
+
+	port_attr->max_mtu = IB_MTU_4096;
+	port_attr->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
+
+	if (!netif_carrier_ok(netdev)) {
+		port_attr->state = IB_PORT_DOWN;
+		port_attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
+	} else {
+		inetdev = in_dev_get(netdev);
+
+		if (inetdev && inetdev->ifa_list) {
+			port_attr->state = IB_PORT_ACTIVE;
+			port_attr->phys_state =
 IB_PORT_PHYS_STATE_LINK_UP;
+			in_dev_put(inetdev);
+		} else {
+			port_attr->state = IB_PORT_INIT;
+			port_attr->phys_state =
+
 	IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING;
+		}
+	}
+
+	err = device->ops.query_port(device, port_num, port_attr);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int __ib_query_port(struct ib_device *device,
+			   u8 port_num,
+			   struct ib_port_attr *port_attr)
+{
+	union ib_gid gid = {};
+	int err;
 
 	memset(port_attr, 0, sizeof(*port_attr));
+
 	err = device->ops.query_port(device, port_num, port_attr);
 	if (err || port_attr->subnet_prefix)
 		return err;
 
-	if (rdma_port_get_link_layer(device, port_num) !=
 IB_LINK_LAYER_INFINIBAND)
+	if (rdma_port_get_link_layer(device, port_num) !=
+	    IB_LINK_LAYER_INFINIBAND)
 		return 0;
drivers/infiniband/core/device.c +14 -0
 	err = device->ops.query_gid(device, port_num, 0, &gid); @@ -1974,6
+2007,28 @@ int ib_query_port(struct ib_device *device,
 	port_attr->subnet_prefix = be64_to_cpu(gid.global.subnet_prefix);
 	return 0;
 }
+
+/**
+ * ib_query_port - Query IB port attributes
+ * @device:Device to query
+ * @port_num:Port number to query
+ * @port_attr:Port attributes
+ *
+ * ib_query_port() returns the attributes of a port through the
+ * @port_attr pointer.
+ */
+int ib_query_port(struct ib_device *device,
+		  u8 port_num,
+		  struct ib_port_attr *port_attr)
Quoted 8 lines
Quoted 6 lines
drivers/infiniband/core/device.c +5 -0
+{
+	if (!rdma_is_port_valid(device, port_num))
+		return -EINVAL;
+
+	if (rdma_node_get_transport(device->node_type) ==

RDMA_TRANSPORT_IWARP)

Raising a question, in some places we use the macro above and in others rdma_protocol_iwarp(device, port_num), any reason to prefer one over the other ?

I thought it's more readable to use rdma_node_get_transport() in this case than using rdma_protocol_iwarp().

Quoted 11 lines

thanks,

Quoted 8 lines
drivers/infiniband/core/device.c +3 -1
+		return iw_query_port(device, port_num, port_attr);
+	else
+		return __ib_query_port(device, port_num, port_attr); }
 EXPORT_SYMBOL(ib_query_port);
 
 static void add_ndev_hash(struct ib_port_data *pdata)
--

2.20.1

author
#8 lore raw

PATCH v2 4/4 RDMA/{cxgb3, cxgb4, i40iw}: Remove common code

In reply to Kamal Heib

Now that we have a common iWARP query port function we can remove the common code from the iWARP drivers.

---
 drivers/infiniband/hw/cxgb3/iwch_provider.c | 25 ---------------------
 drivers/infiniband/hw/cxgb4/provider.c      | 24 --------------------
 drivers/infiniband/hw/i40iw/i40iw_verbs.c   | 11 ---------
 3 files changed, 60 deletions(-)
drivers/infiniband/hw/cxgb3/iwch_provider.c +0 -25
index 5848e4727b2e..dcf02ec02810 100644
@@ -991,33 +991,8 @@ static int iwch_query_device(struct ib_device *ibdev, struct ib_device_attr *pro
 static int iwch_query_port(struct ib_device *ibdev,
 			   u8 port, struct ib_port_attr *props)
 {
-	struct iwch_dev *dev;
-	struct net_device *netdev;
-	struct in_device *inetdev;
-
 	pr_debug("%s ibdev %p\n", __func__, ibdev);
 
-	dev = to_iwch_dev(ibdev);
-	netdev = dev->rdev.port_info.lldevs[port-1];
-
-	/* props being zeroed by the caller, avoid zeroing it here */
-	props->max_mtu = IB_MTU_4096;
-	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
-
-	if (!netif_carrier_ok(netdev))
-		props->state = IB_PORT_DOWN;
-	else {
-		inetdev = in_dev_get(netdev);
-		if (inetdev) {
-			if (inetdev->ifa_list)
-				props->state = IB_PORT_ACTIVE;
-			else
-				props->state = IB_PORT_INIT;
-			in_dev_put(inetdev);
-		} else
-			props->state = IB_PORT_INIT;
-	}
-
 	props->port_cap_flags =
 	    IB_PORT_CM_SUP |
 	    IB_PORT_SNMP_TUNNEL_SUP |
drivers/infiniband/hw/cxgb4/provider.c +0 -24
index 5e59c5708729..d373ac0fe2cb 100644
@@ -305,32 +305,8 @@ static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *pro
 static int c4iw_query_port(struct ib_device *ibdev, u8 port,
 			   struct ib_port_attr *props)
 {
-	struct c4iw_dev *dev;
-	struct net_device *netdev;
-	struct in_device *inetdev;
-
 	pr_debug("ibdev %p\n", ibdev);
 
-	dev = to_c4iw_dev(ibdev);
-	netdev = dev->rdev.lldi.ports[port-1];
-	/* props being zeroed by the caller, avoid zeroing it here */
-	props->max_mtu = IB_MTU_4096;
-	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
-
-	if (!netif_carrier_ok(netdev))
-		props->state = IB_PORT_DOWN;
-	else {
-		inetdev = in_dev_get(netdev);
-		if (inetdev) {
-			if (inetdev->ifa_list)
-				props->state = IB_PORT_ACTIVE;
-			else
-				props->state = IB_PORT_INIT;
-			in_dev_put(inetdev);
-		} else
-			props->state = IB_PORT_INIT;
-	}
-
 	props->port_cap_flags =
 	    IB_PORT_CM_SUP |
 	    IB_PORT_SNMP_TUNNEL_SUP |
drivers/infiniband/hw/i40iw/i40iw_verbs.c +0 -11
index d169a8031375..8056930bbe2c 100644
@@ -97,18 +97,7 @@ static int i40iw_query_port(struct ib_device *ibdev,
 			    u8 port,
 			    struct ib_port_attr *props)
 {
-	struct i40iw_device *iwdev = to_iwdev(ibdev);
-	struct net_device *netdev = iwdev->netdev;
-
-	/* props being zeroed by the caller, avoid zeroing it here */
-	props->max_mtu = IB_MTU_4096;
-	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
-
 	props->lid = 1;
-	if (netif_carrier_ok(iwdev->netdev))
-		props->state = IB_PORT_ACTIVE;
-	else
-		props->state = IB_PORT_DOWN;
 	props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_REINIT_SUP |
 		IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
 	props->gid_tbl_len = 1;
Signature · 1 line
2.20.1
maintainer Acked-by on v2 4/4
#9 lore raw

Re: [PATCH for-next V2 4/4] RDMA/{cxgb3, cxgb4, i40iw}: Remove common code

Quoted 5 lines · Kamal Heib

Now that we have a common iWARP query port function we can remove the common code from the iWARP drivers.

---

Thanks for the changes! Ack for cxgb4.

Quoted 106 lines
 drivers/infiniband/hw/cxgb3/iwch_provider.c | 25 ---------------------
 drivers/infiniband/hw/cxgb4/provider.c      | 24 --------------------
 drivers/infiniband/hw/i40iw/i40iw_verbs.c   | 11 ---------
 3 files changed, 60 deletions(-)
drivers/infiniband/hw/cxgb3/iwch_provider.c +0 -25
index 5848e4727b2e..dcf02ec02810 100644
@@ -991,33 +991,8 @@ static int iwch_query_device(struct ib_device *ibdev, struct ib_device_attr *pro
 static int iwch_query_port(struct ib_device *ibdev,
 			   u8 port, struct ib_port_attr *props)
 {
-	struct iwch_dev *dev;
-	struct net_device *netdev;
-	struct in_device *inetdev;
-
 	pr_debug("%s ibdev %p\n", __func__, ibdev);
 
-	dev = to_iwch_dev(ibdev);
-	netdev = dev->rdev.port_info.lldevs[port-1];
-
-	/* props being zeroed by the caller, avoid zeroing it here */
-	props->max_mtu = IB_MTU_4096;
-	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
-
-	if (!netif_carrier_ok(netdev))
-		props->state = IB_PORT_DOWN;
-	else {
-		inetdev = in_dev_get(netdev);
-		if (inetdev) {
-			if (inetdev->ifa_list)
-				props->state = IB_PORT_ACTIVE;
-			else
-				props->state = IB_PORT_INIT;
-			in_dev_put(inetdev);
-		} else
-			props->state = IB_PORT_INIT;
-	}
-
 	props->port_cap_flags =
 	    IB_PORT_CM_SUP |
 	    IB_PORT_SNMP_TUNNEL_SUP |
drivers/infiniband/hw/cxgb4/provider.c +0 -24
index 5e59c5708729..d373ac0fe2cb 100644
@@ -305,32 +305,8 @@ static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *pro
 static int c4iw_query_port(struct ib_device *ibdev, u8 port,
 			   struct ib_port_attr *props)
 {
-	struct c4iw_dev *dev;
-	struct net_device *netdev;
-	struct in_device *inetdev;
-
 	pr_debug("ibdev %p\n", ibdev);
 
-	dev = to_c4iw_dev(ibdev);
-	netdev = dev->rdev.lldi.ports[port-1];
-	/* props being zeroed by the caller, avoid zeroing it here */
-	props->max_mtu = IB_MTU_4096;
-	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
-
-	if (!netif_carrier_ok(netdev))
-		props->state = IB_PORT_DOWN;
-	else {
-		inetdev = in_dev_get(netdev);
-		if (inetdev) {
-			if (inetdev->ifa_list)
-				props->state = IB_PORT_ACTIVE;
-			else
-				props->state = IB_PORT_INIT;
-			in_dev_put(inetdev);
-		} else
-			props->state = IB_PORT_INIT;
-	}
-
 	props->port_cap_flags =
 	    IB_PORT_CM_SUP |
 	    IB_PORT_SNMP_TUNNEL_SUP |
drivers/infiniband/hw/i40iw/i40iw_verbs.c +0 -11
index d169a8031375..8056930bbe2c 100644
@@ -97,18 +97,7 @@ static int i40iw_query_port(struct ib_device *ibdev,
 			    u8 port,
 			    struct ib_port_attr *props)
 {
-	struct i40iw_device *iwdev = to_iwdev(ibdev);
-	struct net_device *netdev = iwdev->netdev;
-
-	/* props being zeroed by the caller, avoid zeroing it here */
-	props->max_mtu = IB_MTU_4096;
-	props->active_mtu = ib_mtu_int_to_enum(netdev->mtu);
-
 	props->lid = 1;
-	if (netif_carrier_ok(iwdev->netdev))
-		props->state = IB_PORT_ACTIVE;
-	else
-		props->state = IB_PORT_DOWN;
 	props->port_cap_flags = IB_PORT_CM_SUP | IB_PORT_REINIT_SUP |
 		IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
 	props->gid_tbl_len = 1;
Signature · 1 line
2.20.1