]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
IB/core: Refactor rate_show to use ib_port_attr_to_rate()
authorOr Har-Toov <ohartoov@nvidia.com>
Thu, 18 Dec 2025 15:58:40 +0000 (17:58 +0200)
committerLeon Romanovsky <leon@kernel.org>
Mon, 5 Jan 2026 07:42:59 +0000 (02:42 -0500)
Update sysfs rate_show() to rely on ib_port_attr_to_speed_info() for
converting IB port speed and width attributes to data rate and speed
string.

Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Maher Sanalla <msanalla@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/sysfs.c

index 0ed862b38b4435c5854391cf73aa773130672226..bfaca07933d836a8135eadfe8cf66f0551b951b6 100644 (file)
@@ -292,62 +292,22 @@ static ssize_t cap_mask_show(struct ib_device *ibdev, u32 port_num,
 static ssize_t rate_show(struct ib_device *ibdev, u32 port_num,
                         struct ib_port_attribute *unused, char *buf)
 {
+       struct ib_port_speed_info speed_info;
        struct ib_port_attr attr;
-       char *speed = "";
-       int rate;               /* in deci-Gb/sec */
        ssize_t ret;
 
        ret = ib_query_port(ibdev, port_num, &attr);
        if (ret)
                return ret;
 
-       switch (attr.active_speed) {
-       case IB_SPEED_DDR:
-               speed = " DDR";
-               rate = 50;
-               break;
-       case IB_SPEED_QDR:
-               speed = " QDR";
-               rate = 100;
-               break;
-       case IB_SPEED_FDR10:
-               speed = " FDR10";
-               rate = 100;
-               break;
-       case IB_SPEED_FDR:
-               speed = " FDR";
-               rate = 140;
-               break;
-       case IB_SPEED_EDR:
-               speed = " EDR";
-               rate = 250;
-               break;
-       case IB_SPEED_HDR:
-               speed = " HDR";
-               rate = 500;
-               break;
-       case IB_SPEED_NDR:
-               speed = " NDR";
-               rate = 1000;
-               break;
-       case IB_SPEED_XDR:
-               speed = " XDR";
-               rate = 2000;
-               break;
-       case IB_SPEED_SDR:
-       default:                /* default to SDR for invalid rates */
-               speed = " SDR";
-               rate = 25;
-               break;
-       }
-
-       rate *= ib_width_enum_to_int(attr.active_width);
-       if (rate < 0)
-               return -EINVAL;
+       ret = ib_port_attr_to_speed_info(&attr, &speed_info);
+       if (ret)
+               return ret;
 
-       return sysfs_emit(buf, "%d%s Gb/sec (%dX%s)\n", rate / 10,
-                         rate % 10 ? ".5" : "",
-                         ib_width_enum_to_int(attr.active_width), speed);
+       return sysfs_emit(buf, "%d%s Gb/sec (%dX%s)\n", speed_info.rate / 10,
+                         speed_info.rate % 10 ? ".5" : "",
+                         ib_width_enum_to_int(attr.active_width),
+                         speed_info.str);
 }
 
 static const char *phys_state_to_str(enum ib_port_phys_state phys_state)