Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

IB/core: Refactor rate_show to use ib_port_attr_to_rate()

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>

authored by

Or Har-Toov and committed by
Leon Romanovsky
d4adeff2 2941abac

+8 -48
+8 -48
drivers/infiniband/core/sysfs.c
··· 292 292 static ssize_t rate_show(struct ib_device *ibdev, u32 port_num, 293 293 struct ib_port_attribute *unused, char *buf) 294 294 { 295 + struct ib_port_speed_info speed_info; 295 296 struct ib_port_attr attr; 296 - char *speed = ""; 297 - int rate; /* in deci-Gb/sec */ 298 297 ssize_t ret; 299 298 300 299 ret = ib_query_port(ibdev, port_num, &attr); 301 300 if (ret) 302 301 return ret; 303 302 304 - switch (attr.active_speed) { 305 - case IB_SPEED_DDR: 306 - speed = " DDR"; 307 - rate = 50; 308 - break; 309 - case IB_SPEED_QDR: 310 - speed = " QDR"; 311 - rate = 100; 312 - break; 313 - case IB_SPEED_FDR10: 314 - speed = " FDR10"; 315 - rate = 100; 316 - break; 317 - case IB_SPEED_FDR: 318 - speed = " FDR"; 319 - rate = 140; 320 - break; 321 - case IB_SPEED_EDR: 322 - speed = " EDR"; 323 - rate = 250; 324 - break; 325 - case IB_SPEED_HDR: 326 - speed = " HDR"; 327 - rate = 500; 328 - break; 329 - case IB_SPEED_NDR: 330 - speed = " NDR"; 331 - rate = 1000; 332 - break; 333 - case IB_SPEED_XDR: 334 - speed = " XDR"; 335 - rate = 2000; 336 - break; 337 - case IB_SPEED_SDR: 338 - default: /* default to SDR for invalid rates */ 339 - speed = " SDR"; 340 - rate = 25; 341 - break; 342 - } 303 + ret = ib_port_attr_to_speed_info(&attr, &speed_info); 304 + if (ret) 305 + return ret; 343 306 344 - rate *= ib_width_enum_to_int(attr.active_width); 345 - if (rate < 0) 346 - return -EINVAL; 347 - 348 - return sysfs_emit(buf, "%d%s Gb/sec (%dX%s)\n", rate / 10, 349 - rate % 10 ? ".5" : "", 350 - ib_width_enum_to_int(attr.active_width), speed); 307 + return sysfs_emit(buf, "%d%s Gb/sec (%dX%s)\n", speed_info.rate / 10, 308 + speed_info.rate % 10 ? ".5" : "", 309 + ib_width_enum_to_int(attr.active_width), 310 + speed_info.str); 351 311 } 352 312 353 313 static const char *phys_state_to_str(enum ib_port_phys_state phys_state)