Skip to content

Commit

Permalink
smc-tools: Fix RoCE v3 hardware capabilities
Browse files Browse the repository at this point in the history
RoCE v3 showed n/a hardware capabailities.
This patch shows the correct support now.
Refactored hex masks into constants for cleaner and consistent code.

Signed-off-by: Jan Karcher <[email protected]>
Reviewed-by: Wenjia Zhang <[email protected]>
  • Loading branch information
Jan Karcher authored and Wenjia Zhang committed Sep 29, 2022
1 parent 06b9cbe commit e3b228b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
27 changes: 19 additions & 8 deletions dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include "libnetlink.h"
#include "dev.h"

#define MASK_ROCE_V1_HEX 0x1004
#define MASK_ROCE_V2_HEX 0x1016
#define MASK_ROCE_V3_HEX 0x101e

#define MASK_ISM_V1_HEX 0x04ed

static int netdev_entered = 0;
static int ibdev_entered = 0;
static int type_entered = 0;
Expand Down Expand Up @@ -100,10 +106,10 @@ static const char *smc_ib_dev_type(unsigned int x)
static char buf[16];

switch (x) {
case 0x1004: return "RoCE_Express";
case 0x1016: return "RoCE_Express2";
case 0x101e: return "RoCE_Express3";
case 0x04ed: return "ISM";
case MASK_ROCE_V1_HEX: return "RoCE_Express";
case MASK_ROCE_V2_HEX: return "RoCE_Express2";
case MASK_ROCE_V3_HEX: return "RoCE_Express3";
case MASK_ISM_V1_HEX: return "ISM";
default: sprintf(buf, "%#x", x); return buf;
}
}
Expand Down Expand Up @@ -480,6 +486,7 @@ int dev_count_ism_devices(int *ism_count)
struct count_roce_args {
int *rocev1_count;
int *rocev2_count;
int *rocev3_count;
};

/* arg is an (struct count_roce_args *) */
Expand Down Expand Up @@ -512,23 +519,27 @@ static int count_roce_devices_reply(struct nl_msg *msg, void *arg)
}
if (dev_attrs[SMC_NLA_DEV_PCI_DEVICE])
i = nla_get_u16(dev_attrs[SMC_NLA_DEV_PCI_DEVICE]);
if (i == 0x1004)
if (i == MASK_ROCE_V1_HEX)
(*args->rocev1_count)++;
if (i == 0x1016)
if (i == MASK_ROCE_V2_HEX)
(*args->rocev2_count)++;
if (i == MASK_ROCE_V3_HEX)
(*args->rocev3_count)++;
}

return NL_OK;
}

int dev_count_roce_devices(int *rocev1_count, int *rocev2_count)
int dev_count_roce_devices(int *rocev1_count, int *rocev2_count, int *rocev3_count)
{
struct count_roce_args args = {
.rocev1_count = rocev1_count,
.rocev2_count = rocev2_count
.rocev2_count = rocev2_count,
.rocev3_count = rocev3_count,
};

*rocev1_count = 0;
*rocev2_count = 0;
*rocev3_count = 0;
return gen_nl_handle_dump(SMC_NETLINK_GET_DEV_SMCR, count_roce_devices_reply, &args);
}
2 changes: 1 addition & 1 deletion dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ extern struct rtnl_handle rth;

int invoke_devs(int argc, char **argv, int detail_level);
int dev_count_ism_devices(int *ism_count);
int dev_count_roce_devices(int *rocev1_count, int *rocev2_count);
int dev_count_roce_devices(int *rocev1_count, int *rocev2_count, int *rocev3_count);

#endif /* DEV_H_ */
10 changes: 5 additions & 5 deletions info.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "dev.h"

static int show_cmd = 0;
static int ism_count, rocev1_count, rocev2_count;
static int ism_count, rocev1_count, rocev2_count, rocev3_count;

static struct nla_policy
smc_gen_info_policy[SMC_NLA_SYS_MAX + 1] = {
Expand Down Expand Up @@ -135,12 +135,12 @@ static int handle_gen_info_reply(struct nl_msg *msg, void *arg)

/* RoCE hardware */
tmp[0] = '\0';
if (rocev1_count || rocev2_count) {
if (rocev1_count || rocev2_count || rocev3_count) {
/* Kernel found any RoCE device */
strcpy(tmp, "");
if (rocev1_count || rocev2_count)
if (rocev1_count || rocev2_count || rocev3_count)
strcat(tmp, "v1 ");
if (rocev2_count)
if (rocev2_count || rocev3_count)
strcat(tmp, "v2");
}
printf("RoCE: %s\n", (tmp[0] != '\0' ? tmp : "n/a"));
Expand Down Expand Up @@ -184,7 +184,7 @@ int invoke_info(int argc, char **argv, int detail_level)
fprintf(stderr, "Error: Failed to retrieve ISM device count\n");
return EXIT_FAILURE;
}
if (dev_count_roce_devices(&rocev1_count, &rocev2_count)) {
if (dev_count_roce_devices(&rocev1_count, &rocev2_count, &rocev3_count)) {
fprintf(stderr, "Error: Failed to retrieve RoCE device count\n");
return EXIT_FAILURE;
}
Expand Down

0 comments on commit e3b228b

Please sign in to comment.