* [PATCH for-next] RDMA/core: Get IB width and speed from netdev
@ 2023-05-22 1:25 Junxian Huang
2023-06-01 15:57 ` Jason Gunthorpe
0 siblings, 1 reply; 3+ messages in thread
From: Junxian Huang @ 2023-05-22 1:25 UTC (permalink / raw)
To: jgg, leon; +Cc: linux-rdma, linuxarm, linux-kernel, huangjunxian6
From: Haoyue Xu <xuhaoyue1@hisilicon.com>
Logic of retrieving netdev lanes and speed from net_device and
translating it to IB width and speed. Also, add a generic function
to translating netdev speed to IB speed.
Signed-off-by: Haoyue Xu <xuhaoyue1@hisilicon.com>
Signed-off-by: Luoyouming <luoyouming@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
drivers/infiniband/core/verbs.c | 19 +++++++++++++++++--
include/rdma/ib_verbs.h | 26 ++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index b99b3cc283b6..35f1b670600a 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -1880,11 +1880,19 @@ int ib_modify_qp_with_udata(struct ib_qp *ib_qp, struct ib_qp_attr *attr,
}
EXPORT_SYMBOL(ib_modify_qp_with_udata);
+static void ib_get_width_and_speed(u32 netdev_speed, u32 lanes,
+ u16 *speed, u8 *width)
+{
+ *width = ib_int_to_ib_width(lanes);
+ *speed = ib_eth_to_ib_speed(netdev_speed / lanes);
+}
+
int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)
{
int rc;
u32 netdev_speed;
struct net_device *netdev;
+ bool cap_link_lanes_supported;
struct ethtool_link_ksettings lksettings;
if (rdma_port_get_link_layer(dev, port_num) != IB_LINK_LAYER_ETHERNET)
@@ -1896,16 +1904,23 @@ int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed, u8 *width)
rtnl_lock();
rc = __ethtool_get_link_ksettings(netdev, &lksettings);
+ cap_link_lanes_supported = netdev->ethtool_ops->cap_link_lanes_supported;
rtnl_unlock();
dev_put(netdev);
if (!rc && lksettings.base.speed != (u32)SPEED_UNKNOWN) {
netdev_speed = lksettings.base.speed;
+ if (cap_link_lanes_supported && lksettings.lanes) {
+ ib_get_width_and_speed(netdev_speed, lksettings.lanes,
+ speed, width);
+ return 0;
+ }
} else {
netdev_speed = SPEED_1000;
- pr_warn("%s speed is unknown, defaulting to %u\n", netdev->name,
- netdev_speed);
+ if (rc)
+ pr_warn("%s speed is unknown, defaulting to %u\n",
+ netdev->name, netdev_speed);
}
if (netdev_speed <= SPEED_1000) {
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 1e7774ac808f..7dc926ec7fee 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -552,6 +552,18 @@ static inline int ib_width_enum_to_int(enum ib_port_width width)
}
}
+static inline int ib_int_to_ib_width(u32 lanes)
+{
+ switch (lanes) {
+ case 1: return IB_WIDTH_1X;
+ case 2: return IB_WIDTH_2X;
+ case 4: return IB_WIDTH_4X;
+ case 8: return IB_WIDTH_8X;
+ case 12: return IB_WIDTH_12X;
+ default: return IB_WIDTH_1X;
+ }
+}
+
enum ib_port_speed {
IB_SPEED_SDR = 1,
IB_SPEED_DDR = 2,
@@ -563,6 +575,20 @@ enum ib_port_speed {
IB_SPEED_NDR = 128,
};
+static inline int ib_eth_to_ib_speed(u32 speed)
+{
+ switch (speed) {
+ case SPEED_2500: return IB_SPEED_SDR;
+ case SPEED_5000: return IB_SPEED_DDR;
+ case SPEED_10000: return IB_SPEED_FDR10;
+ case SPEED_14000: return IB_SPEED_FDR;
+ case SPEED_25000: return IB_SPEED_EDR;
+ case SPEED_50000: return IB_SPEED_HDR;
+ case SPEED_100000: return IB_SPEED_NDR;
+ default: return IB_SPEED_SDR;
+ }
+}
+
enum ib_stat_flag {
IB_STAT_FLAG_OPTIONAL = 1 << 0,
};
--
2.30.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH for-next] RDMA/core: Get IB width and speed from netdev
2023-05-22 1:25 [PATCH for-next] RDMA/core: Get IB width and speed from netdev Junxian Huang
@ 2023-06-01 15:57 ` Jason Gunthorpe
2023-06-02 3:25 ` Junxian Huang
0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 15:57 UTC (permalink / raw)
To: Junxian Huang; +Cc: leon, linux-rdma, linuxarm, linux-kernel
On Mon, May 22, 2023 at 09:25:02AM +0800, Junxian Huang wrote:
> From: Haoyue Xu <xuhaoyue1@hisilicon.com>
>
> Logic of retrieving netdev lanes and speed from net_device and
> translating it to IB width and speed. Also, add a generic function
> to translating netdev speed to IB speed.
>
> Signed-off-by: Haoyue Xu <xuhaoyue1@hisilicon.com>
> Signed-off-by: Luoyouming <luoyouming@huawei.com>
> Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
> ---
> drivers/infiniband/core/verbs.c | 19 +++++++++++++++++--
> include/rdma/ib_verbs.h | 26 ++++++++++++++++++++++++++
> 2 files changed, 43 insertions(+), 2 deletions(-)
Can you explain in the commit message why we'd want to do this?
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH for-next] RDMA/core: Get IB width and speed from netdev
2023-06-01 15:57 ` Jason Gunthorpe
@ 2023-06-02 3:25 ` Junxian Huang
0 siblings, 0 replies; 3+ messages in thread
From: Junxian Huang @ 2023-06-02 3:25 UTC (permalink / raw)
To: Jason Gunthorpe; +Cc: leon, linux-rdma, linuxarm, linux-kernel
On 2023/6/1 23:57, Jason Gunthorpe wrote:
> On Mon, May 22, 2023 at 09:25:02AM +0800, Junxian Huang wrote:
>> From: Haoyue Xu <xuhaoyue1@hisilicon.com>
>>
>> Logic of retrieving netdev lanes and speed from net_device and
>> translating it to IB width and speed. Also, add a generic function
>> to translating netdev speed to IB speed.
>>
>> Signed-off-by: Haoyue Xu <xuhaoyue1@hisilicon.com>
>> Signed-off-by: Luoyouming <luoyouming@huawei.com>
>> Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
>> ---
>> drivers/infiniband/core/verbs.c | 19 +++++++++++++++++--
>> include/rdma/ib_verbs.h | 26 ++++++++++++++++++++++++++
>> 2 files changed, 43 insertions(+), 2 deletions(-)
>
> Can you explain in the commit message why we'd want to do this?
>
> Jason
Sure. I'll add the explanation in v2.
Junxian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-02 3:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-22 1:25 [PATCH for-next] RDMA/core: Get IB width and speed from netdev Junxian Huang
2023-06-01 15:57 ` Jason Gunthorpe
2023-06-02 3:25 ` Junxian Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox