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: Add helper to convert port attributes to data rate

Introduce ib_port_attr_to_rate() to compute the data rate in 100 Mbps
units (deci-Gb/sec) from a port's active_speed and active_width
attributes. This generic helper removes duplicated speed-to-rate
calculations, which are used by sysfs and the upcoming new verb.

Signed-off-by: Or Har-Toov <ohartoov@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
2941abac 263d1d99

+65
+51
drivers/infiniband/core/verbs.c
··· 217 217 } 218 218 EXPORT_SYMBOL(ib_rate_to_mbps); 219 219 220 + struct ib_speed_attr { 221 + const char *str; 222 + int speed; 223 + }; 224 + 225 + #define IB_SPEED_ATTR(speed_type, _str, _speed) \ 226 + [speed_type] = {.str = _str, .speed = _speed} 227 + 228 + static const struct ib_speed_attr ib_speed_attrs[] = { 229 + IB_SPEED_ATTR(IB_SPEED_SDR, " SDR", 25), 230 + IB_SPEED_ATTR(IB_SPEED_DDR, " DDR", 50), 231 + IB_SPEED_ATTR(IB_SPEED_QDR, " QDR", 100), 232 + IB_SPEED_ATTR(IB_SPEED_FDR10, " FDR10", 100), 233 + IB_SPEED_ATTR(IB_SPEED_FDR, " FDR", 140), 234 + IB_SPEED_ATTR(IB_SPEED_EDR, " EDR", 250), 235 + IB_SPEED_ATTR(IB_SPEED_HDR, " HDR", 500), 236 + IB_SPEED_ATTR(IB_SPEED_NDR, " NDR", 1000), 237 + IB_SPEED_ATTR(IB_SPEED_XDR, " XDR", 2000), 238 + }; 239 + 240 + int ib_port_attr_to_speed_info(struct ib_port_attr *attr, 241 + struct ib_port_speed_info *speed_info) 242 + { 243 + int speed_idx = attr->active_speed; 244 + 245 + switch (attr->active_speed) { 246 + case IB_SPEED_DDR: 247 + case IB_SPEED_QDR: 248 + case IB_SPEED_FDR10: 249 + case IB_SPEED_FDR: 250 + case IB_SPEED_EDR: 251 + case IB_SPEED_HDR: 252 + case IB_SPEED_NDR: 253 + case IB_SPEED_XDR: 254 + case IB_SPEED_SDR: 255 + break; 256 + default: 257 + speed_idx = IB_SPEED_SDR; /* Default to SDR for invalid rates */ 258 + break; 259 + } 260 + 261 + speed_info->str = ib_speed_attrs[speed_idx].str; 262 + speed_info->rate = ib_speed_attrs[speed_idx].speed; 263 + speed_info->rate *= ib_width_enum_to_int(attr->active_width); 264 + if (speed_info->rate < 0) 265 + return -EINVAL; 266 + 267 + return 0; 268 + } 269 + EXPORT_SYMBOL(ib_port_attr_to_speed_info); 270 + 220 271 __attribute_const__ enum rdma_transport_type 221 272 rdma_node_get_transport(unsigned int node_type) 222 273 {
+14
include/rdma/ib_verbs.h
··· 878 878 */ 879 879 __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate); 880 880 881 + struct ib_port_speed_info { 882 + const char *str; 883 + int rate; /* in deci-Gb/sec (100 MBps units) */ 884 + }; 885 + 886 + /** 887 + * ib_port_attr_to_speed_info - Convert port attributes to speed information 888 + * @attr: Port attributes containing active_speed and active_width 889 + * @speed_info: Speed information to return 890 + * 891 + * Returns 0 on success, -EINVAL on error. 892 + */ 893 + int ib_port_attr_to_speed_info(struct ib_port_attr *attr, 894 + struct ib_port_speed_info *speed_info); 881 895 882 896 /** 883 897 * enum ib_mr_type - memory region type