Skip to contentSkip to conversation

IB/{core, usnic}: Add generic function to extract IB speed from netdev

PATCH In review Yuval Shaia 2 participants 4 messages Jun 14, 2017 – Jul 28, 2017 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 IB/{core, usnic}: Add generic function to extract IB speed from netdev

Please review this change which adds generic function to extract speed from netdev and return IB speed to caller.

[PATCH v4 1/2] IB/usnic: Implement get_netdev hook
Preliminary and needed anyway patch which adds get_netdev implementation to usnic driver.

[PATCH v4 2/2] IB/core: Add generic function to extract IB speed from The actual patch that adds the $subject functionality.

Yuval
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

PATCH v4 1/2 IB/usnic: Implement get_netdev hook

In reply to a message not in the archive

usnic's get_netdev hook for struct ib_device is missing - add it.

---
v3 -> v4:
* Not functional change, just add r-b

---
 drivers/infiniband/hw/usnic/usnic_ib_main.c  |  1 +
 drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 10 ++++++++++
 drivers/infiniband/hw/usnic/usnic_ib_verbs.h |  1 +
 3 files changed, 12 insertions(+)
drivers/infiniband/hw/usnic/usnic_ib_main.c +1 -0
index c0c1e8b..80577b9 100644
@@ -409,6 +409,7 @@ static void *usnic_ib_device_add(struct pci_dev *dev)
 	us_ibdev->ib_dev.query_port = usnic_ib_query_port;
 	us_ibdev->ib_dev.query_pkey = usnic_ib_query_pkey;
 	us_ibdev->ib_dev.query_gid = usnic_ib_query_gid;
+	us_ibdev->ib_dev.get_netdev = usnic_get_netdev;
 	us_ibdev->ib_dev.get_link_layer = usnic_ib_port_link_layer;
 	us_ibdev->ib_dev.alloc_pd = usnic_ib_alloc_pd;
 	us_ibdev->ib_dev.dealloc_pd = usnic_ib_dealloc_pd;
drivers/infiniband/hw/usnic/usnic_ib_verbs.c +10 -0
index 4996984..f9dc1e80 100644
@@ -424,6 +424,16 @@ int usnic_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
 	return 0;
 }
 
+struct net_device *usnic_get_netdev(struct ib_device *device, u8 port_num)
+{
+	struct usnic_ib_dev *us_ibdev = to_usdev(device);
+
+	if (us_ibdev->netdev)
+		dev_hold(us_ibdev->netdev);
+
+	return us_ibdev->netdev;
+}
+
 int usnic_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
 				u16 *pkey)
 {
drivers/infiniband/hw/usnic/usnic_ib_verbs.h +1 -0
index 172e43b..1fda944 100644
@@ -48,6 +48,7 @@ int usnic_ib_query_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
 				struct ib_qp_init_attr *qp_init_attr);
 int usnic_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
 				union ib_gid *gid);
+struct net_device *usnic_get_netdev(struct ib_device *device, u8 port_num);
 int usnic_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
 				u16 *pkey);
 struct ib_pd *usnic_ib_alloc_pd(struct ib_device *ibdev,
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH v4 2/2 IB/core: Add generic function to extract IB speed from netdev

In reply to a message not in the archive

Logic of retrieving netdev speed from net_device and translating it to IB speed is implemented in rxe, in usnic and in bnxt drivers.

Define new function which merges all.

---
v0 -> v1:
* Invite usnic to the party.

v1 -> v2:
* Utilize __ethtool_get_link_ksettings
* Rename to ib_get_eth_speed
* Add some validation checks
* Implement get_netdev in usnic

v2 -> v3:
* Split to two separate patches

v3 -> v4:
* Change func's return values
* While there add some r-b

---
 drivers/infiniband/core/verbs.c              | 55 ++++++++++++++++++++++++++++
 drivers/infiniband/hw/bnxt_re/ib_verbs.c     | 49 ++-----------------------
 drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 31 +++-------------
 drivers/infiniband/sw/rxe/rxe_verbs.c        | 53 +++------------------------
 include/rdma/ib_verbs.h                      |  1 +
 5 files changed, 71 insertions(+), 118 deletions(-)
drivers/infiniband/core/verbs.c +55 -0
index 4792f52..769f736 100644
@@ -1253,6 +1253,61 @@ int ib_resolve_eth_dmac(struct ib_device *device,
 }
 EXPORT_SYMBOL(ib_resolve_eth_dmac);
 
+int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width)
+{
+	int rc;
+	u32 netdev_speed;
+	struct net_device *netdev;
+	struct ethtool_link_ksettings lksettings;
+
+	if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
+		return -EINVAL;
+
+	if (!dev->get_netdev)
+		return -EOPNOTSUPP;
+
+	netdev = dev->get_netdev(dev, port_num);
+	if (!netdev)
+		return -ENODEV;
+
+	rtnl_lock();
+	rc = __ethtool_get_link_ksettings(netdev, &lksettings);
+	rtnl_unlock();
+
+	dev_put(netdev);
+
+	if (!rc) {
+		netdev_speed = lksettings.base.speed;
+	} else {
+		netdev_speed = SPEED_1000;
+		pr_warn("%s speed is unknown, defaulting to %d\n", netdev->name,
+			netdev_speed);
+	}
+
+	if (netdev_speed <= SPEED_1000) {
+		*width = IB_WIDTH_1X;
+		*speed = IB_SPEED_SDR;
+	} else if (netdev_speed <= SPEED_10000) {
+		*width = IB_WIDTH_1X;
+		*speed = IB_SPEED_FDR10;
+	} else if (netdev_speed <= SPEED_20000) {
+		*width = IB_WIDTH_4X;
+		*speed = IB_SPEED_DDR;
+	} else if (netdev_speed <= SPEED_25000) {
+		*width = IB_WIDTH_1X;
+		*speed = IB_SPEED_EDR;
+	} else if (netdev_speed <= SPEED_40000) {
+		*width = IB_WIDTH_4X;
+		*speed = IB_SPEED_FDR10;
+	} else {
+		*width = IB_WIDTH_4X;
+		*speed = IB_SPEED_EDR;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(ib_get_eth_speed);
+
 int ib_modify_qp(struct ib_qp *qp,
 		 struct ib_qp_attr *qp_attr,
 		 int qp_attr_mask)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3 -46

61 lines not on this page · raw message

drivers/infiniband/hw/usnic/usnic_ib_verbs.c +6 -25
index f9dc1e80..e5f57dd 100644
@@ -226,27 +226,6 @@ static void qp_grp_destroy(struct usnic_ib_qp_grp *qp_grp)
 	spin_unlock(&vf->lock);
 }
 
-static void eth_speed_to_ib_speed(int speed, u8 *active_speed,
-					u8 *active_width)
-{
-	if (speed <= 10000) {
-		*active_width = IB_WIDTH_1X;
-		*active_speed = IB_SPEED_FDR10;
-	} else if (speed <= 20000) {
-		*active_width = IB_WIDTH_4X;
-		*active_speed = IB_SPEED_DDR;
-	} else if (speed <= 30000) {
-		*active_width = IB_WIDTH_4X;
-		*active_speed = IB_SPEED_QDR;
-	} else if (speed <= 40000) {
-		*active_width = IB_WIDTH_4X;
-		*active_speed = IB_SPEED_FDR10;
-	} else {
-		*active_width = IB_WIDTH_4X;
-		*active_speed = IB_SPEED_EDR;
-	}
-}
-
 static int create_qp_validate_user_data(struct usnic_ib_create_qp_cmd cmd)
 {
 	if (cmd.spec.trans_type <= USNIC_TRANSPORT_UNKNOWN ||
@@ -326,12 +305,16 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
 				struct ib_port_attr *props)
 {
 	struct usnic_ib_dev *us_ibdev = to_usdev(ibdev);
-	struct ethtool_link_ksettings cmd;
 
 	usnic_dbg("\n");
 
 	mutex_lock(&us_ibdev->usdev_lock);
-	__ethtool_get_link_ksettings(us_ibdev->netdev, &cmd);
+	if (!ib_get_eth_speed(ibdev, port, &props->active_speed,
+			      &props->active_width)) {
+		mutex_unlock(&us_ibdev->usdev_lock);
+		return -EINVAL;
+	}
+
 	/* props being zeroed by the caller, avoid zeroing it here */
 
 	props->lid = 0;
@@ -355,8 +338,6 @@ int usnic_ib_query_port(struct ib_device *ibdev, u8 port,
 	props->pkey_tbl_len = 1;
 	props->bad_pkey_cntr = 0;
 	props->qkey_viol_cntr = 0;
-	eth_speed_to_ib_speed(cmd.base.speed, &props->active_speed,
-			      &props->active_width);
 	props->max_mtu = IB_MTU_4096;
 	props->active_mtu = iboe_get_mtu(us_ibdev->ufdev->mtu);
 	/* Userspace will adjust for hdrs */
drivers/infiniband/sw/rxe/rxe_verbs.c +6 -47

75 lines not on this page · raw message

include/rdma/ib_verbs.h +1 -0
index ba8314e..860cb30 100644
@@ -3488,6 +3488,7 @@ void ib_drain_qp(struct ib_qp *qp);
 
 int ib_resolve_eth_dmac(struct ib_device *device,
 			struct rdma_ah_attr *ah_attr);
+int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width);
 
 static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr)
 {
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
In reply to a message not in the archive
Quoted 9 lines · Yuval Shaia

Please review this change which adds generic function to extract speed from
netdev and return IB speed to caller.

[PATCH v4 1/2] IB/usnic: Implement get_netdev hook Preliminary and needed anyway patch which adds get_netdev implementation to
usnic driver.

Quoted 4 lines

[PATCH v4 2/2] IB/core: Add generic function to extract IB speed from The actual patch that adds the $subject functionality.

Yuval

Thanks, v4 series applied.

Also, please update your address for Sagi in your personal addressbook in your mail client. The one you used on this submission is wrong (I checked the MAINTAINERS file to make sure it was right there and it is).

Signature · 8 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html