X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=rdma%2Flink.c;h=89e81b84b2ccae8c0401c4ae2e972e57f7022c73;hb=8f5cfd23cd827054f2706e204602fa1e35a68320;hp=f0eaccbb8be709578bc78597eebd348f4cda5188;hpb=4e2eb9fdf911971c8a6615e4b07656047ada0093;p=mirror_iproute2.git diff --git a/rdma/link.c b/rdma/link.c index f0eaccbb..89e81b84 100644 --- a/rdma/link.c +++ b/rdma/link.c @@ -1,11 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* * link.c RDMA tool - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version - * 2 of the License, or (at your option) any later version. - * * Authors: Leon Romanovsky */ @@ -19,7 +14,8 @@ static int link_help(struct rd *rd) static const char *caps_to_str(uint32_t idx) { -#define RDMA_PORT_FLAGS(x) \ +#define RDMA_PORT_FLAGS_LOW(x) \ + x(RESERVED, 0) \ x(SM, 1) \ x(NOTICE, 2) \ x(TRAP, 3) \ @@ -32,7 +28,9 @@ static const char *caps_to_str(uint32_t idx) x(SM_DISABLED, 10) \ x(SYS_IMAGE_GUID, 11) \ x(PKEY_SW_EXT_PORT_TRAP, 12) \ + x(CABLE_INFO, 13) \ x(EXTENDED_SPEEDS, 14) \ + x(CAP_MASK2, 15) \ x(CM, 16) \ x(SNMP_TUNNEL, 17) \ x(REINIT, 18) \ @@ -43,16 +41,45 @@ static const char *caps_to_str(uint32_t idx) x(BOOT_MGMT, 23) \ x(LINK_LATENCY, 24) \ x(CLIENT_REG, 25) \ - x(IP_BASED_GIDS, 26) - - enum { RDMA_PORT_FLAGS(RDMA_BITMAP_ENUM) }; + x(OTHER_LOCAL_CHANGES, 26) \ + x(LINK_SPPED_WIDTH, 27) \ + x(VENDOR_SPECIFIC_MADS, 28) \ + x(MULT_PKER_TRAP, 29) \ + x(MULT_FDB, 30) \ + x(HIERARCHY_INFO, 31) + +#define RDMA_PORT_FLAGS_HIGH(x) \ + x(SET_NODE_DESC, 0) \ + x(EXT_INFO, 1) \ + x(VIRT, 2) \ + x(SWITCH_POR_STATE_TABLE, 3) \ + x(LINK_WIDTH_2X, 4) \ + x(LINK_SPEED_HDR, 5) + + /* + * Separation below is needed to allow compilation of rdmatool + * on 32bits systems. On such systems, C-enum is limited to be + * int and can't hold more than 32 bits. + */ + enum { RDMA_PORT_FLAGS_LOW(RDMA_BITMAP_ENUM) }; + enum { RDMA_PORT_FLAGS_HIGH(RDMA_BITMAP_ENUM) }; static const char * const - rdma_port_names[] = { RDMA_PORT_FLAGS(RDMA_BITMAP_NAMES) }; - #undef RDMA_PORT_FLAGS + rdma_port_names_low[] = { RDMA_PORT_FLAGS_LOW(RDMA_BITMAP_NAMES) }; + static const char * const + rdma_port_names_high[] = { RDMA_PORT_FLAGS_HIGH(RDMA_BITMAP_NAMES) }; + uint32_t high_idx; + #undef RDMA_PORT_FLAGS_LOW + #undef RDMA_PORT_FLAGS_HIGH + + if (idx < ARRAY_SIZE(rdma_port_names_low) && rdma_port_names_low[idx]) + return rdma_port_names_low[idx]; + + high_idx = idx - ARRAY_SIZE(rdma_port_names_low); + if (high_idx < ARRAY_SIZE(rdma_port_names_high) && + rdma_port_names_high[high_idx]) + return rdma_port_names_high[high_idx]; - if (idx < ARRAY_SIZE(rdma_port_names) && rdma_port_names[idx]) - return rdma_port_names[idx]; return "UNKNOWN"; } @@ -205,6 +232,26 @@ static void link_print_phys_state(struct rd *rd, struct nlattr **tb) pr_out("physical_state %s ", phys_state_to_str(phys_state)); } +static void link_print_netdev(struct rd *rd, struct nlattr **tb) +{ + const char *netdev_name; + uint32_t idx; + + if (!tb[RDMA_NLDEV_ATTR_NDEV_NAME] || !tb[RDMA_NLDEV_ATTR_NDEV_INDEX]) + return; + + netdev_name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_NDEV_NAME]); + idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_NDEV_INDEX]); + if (rd->json_output) { + jsonw_string_field(rd->jw, "netdev", netdev_name); + jsonw_uint_field(rd->jw, "netdev_index", idx); + } else { + pr_out("netdev %s ", netdev_name); + if (rd->show_details) + pr_out("netdev_index %u ", idx); + } +} + static int link_parse_cb(const struct nlmsghdr *nlh, void *data) { struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; @@ -241,6 +288,7 @@ static int link_parse_cb(const struct nlmsghdr *nlh, void *data) link_print_lmc(rd, tb); link_print_state(rd, tb); link_print_phys_state(rd, tb); + link_print_netdev(rd, tb); if (rd->show_details) link_print_caps(rd, tb); @@ -277,56 +325,15 @@ static int link_one_show(struct rd *rd) { 0 } }; + if (!rd->port_idx) + return 0; + return rd_exec_cmd(rd, cmds, "parameter"); } static int link_show(struct rd *rd) { - struct dev_map *dev_map; - uint32_t port; - int ret = 0; - - if (rd->json_output) - jsonw_start_array(rd->jw); - if (rd_no_arg(rd)) { - list_for_each_entry(dev_map, &rd->dev_map_list, list) { - rd->dev_idx = dev_map->idx; - for (port = 1; port < dev_map->num_ports + 1; port++) { - rd->port_idx = port; - ret = link_one_show(rd); - if (ret) - goto out; - } - } - - } else { - dev_map = dev_map_lookup(rd, true); - port = get_port_from_argv(rd); - if (!dev_map || port > dev_map->num_ports) { - pr_err("Wrong device name\n"); - ret = -ENOENT; - goto out; - } - rd_arg_inc(rd); - rd->dev_idx = dev_map->idx; - rd->port_idx = port ? : 1; - for (; rd->port_idx < dev_map->num_ports + 1; rd->port_idx++) { - ret = link_one_show(rd); - if (ret) - goto out; - if (port) - /* - * We got request to show link for devname - * with port index. - */ - break; - } - } - -out: - if (rd->json_output) - jsonw_end_array(rd->jw); - return ret; + return rd_exec_link(rd, link_one_show, true); } int cmd_link(struct rd *rd)