#define ESWITCH_INLINE_MODE_NETWORK "network"
#define ESWITCH_INLINE_MODE_TRANSPORT "transport"
+#define ESWITCH_ENCAP_MODE_NONE "none"
+#define ESWITCH_ENCAP_MODE_BASIC "basic"
+
#define PARAM_CMODE_RUNTIME_STR "runtime"
#define PARAM_CMODE_DRIVERINIT_STR "driverinit"
#define PARAM_CMODE_PERMANENT_STR "permanent"
#define DL_OPT_TRAP_ACTION BIT(31)
#define DL_OPT_TRAP_GROUP_NAME BIT(32)
#define DL_OPT_NETNS BIT(33)
+#define DL_OPT_TRAP_POLICER_ID BIT(34)
+#define DL_OPT_TRAP_POLICER_RATE BIT(35)
+#define DL_OPT_TRAP_POLICER_BURST BIT(36)
struct dl_opts {
uint64_t present; /* flags of present items */
enum devlink_eswitch_inline_mode eswitch_inline_mode;
const char *dpipe_table_name;
bool dpipe_counters_enable;
- bool eswitch_encap_mode;
+ enum devlink_eswitch_encap_mode eswitch_encap_mode;
const char *resource_path;
uint64_t resource_size;
uint32_t resource_id;
enum devlink_trap_action trap_action;
bool netns_is_pid;
uint32_t netns;
+ uint32_t trap_policer_id;
+ uint64_t trap_policer_rate;
+ uint64_t trap_policer_burst;
};
struct dl {
[DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
+ [DEVLINK_ATTR_TRAP_POLICER_ID] = MNL_TYPE_U32,
+ [DEVLINK_ATTR_TRAP_POLICER_RATE] = MNL_TYPE_U64,
+ [DEVLINK_ATTR_TRAP_POLICER_BURST] = MNL_TYPE_U64,
};
static const enum mnl_attr_data_type
devlink_stats_policy[DEVLINK_ATTR_STATS_MAX + 1] = {
[DEVLINK_ATTR_STATS_RX_PACKETS] = MNL_TYPE_U64,
[DEVLINK_ATTR_STATS_RX_BYTES] = MNL_TYPE_U64,
+ [DEVLINK_ATTR_STATS_RX_DROPPED] = MNL_TYPE_U64,
};
static int attr_cb(const struct nlattr *attr, void *data)
{
bool val;
- if (!strcmp(str, "true") || !strcmp(str, "1"))
+ if (!strcmp(str, "true") || !strcmp(str, "1") ||
+ !strcmp(str, "enable"))
val = true;
- else if (!strcmp(str, "false") || !strcmp(str, "0"))
+ else if (!strcmp(str, "false") || !strcmp(str, "0") ||
+ !strcmp(str, "disable"))
val = false;
else
return -EINVAL;
return 0;
}
-static int dpipe_counters_enable_get(const char *typestr,
- bool *counters_enable)
-{
- if (strcmp(typestr, "enable") == 0) {
- *counters_enable = 1;
- } else if (strcmp(typestr, "disable") == 0) {
- *counters_enable = 0;
- } else {
- pr_err("Unknown counter_state \"%s\"\n", typestr);
- return -EINVAL;
- }
- return 0;
-}
-
-static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
+static int
+eswitch_encap_mode_get(const char *typestr,
+ enum devlink_eswitch_encap_mode *p_encap_mode)
{
- if (strcmp(typestr, "enable") == 0) {
- *p_mode = true;
- } else if (strcmp(typestr, "disable") == 0) {
- *p_mode = false;
+ /* The initial implementation incorrectly accepted "enable"/"disable".
+ * Carry it to maintain backward compatibility.
+ */
+ if (strcmp(typestr, "disable") == 0 ||
+ strcmp(typestr, ESWITCH_ENCAP_MODE_NONE) == 0) {
+ *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_NONE;
+ } else if (strcmp(typestr, "enable") == 0 ||
+ strcmp(typestr, ESWITCH_ENCAP_MODE_BASIC) == 0) {
+ *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_BASIC;
} else {
pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
return -EINVAL;
o_found |= DL_OPT_DPIPE_TABLE_NAME;
} else if (dl_argv_match(dl, "counters") &&
(o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) {
- const char *typestr;
-
dl_arg_inc(dl);
- err = dl_argv_str(dl, &typestr);
- if (err)
- return err;
- err = dpipe_counters_enable_get(typestr,
- &opts->dpipe_counters_enable);
+ err = dl_argv_bool(dl, &opts->dpipe_counters_enable);
if (err)
return err;
o_found |= DL_OPT_DPIPE_TABLE_COUNTERS;
- } else if (dl_argv_match(dl, "encap") &&
+ } else if ((dl_argv_match(dl, "encap") || /* Original incorrect implementation */
+ dl_argv_match(dl, "encap-mode")) &&
(o_all & DL_OPT_ESWITCH_ENCAP_MODE)) {
const char *typestr;
opts->netns_is_pid = true;
}
o_found |= DL_OPT_NETNS;
+ } else if (dl_argv_match(dl, "policer") &&
+ (o_all & DL_OPT_TRAP_POLICER_ID)) {
+ dl_arg_inc(dl);
+ err = dl_argv_uint32_t(dl, &opts->trap_policer_id);
+ if (err)
+ return err;
+ o_found |= DL_OPT_TRAP_POLICER_ID;
+ } else if (dl_argv_match(dl, "nopolicer") &&
+ (o_all & DL_OPT_TRAP_POLICER_ID)) {
+ dl_arg_inc(dl);
+ opts->trap_policer_id = 0;
+ o_found |= DL_OPT_TRAP_POLICER_ID;
+ } else if (dl_argv_match(dl, "rate") &&
+ (o_all & DL_OPT_TRAP_POLICER_RATE)) {
+ dl_arg_inc(dl);
+ err = dl_argv_uint64_t(dl, &opts->trap_policer_rate);
+ if (err)
+ return err;
+ o_found |= DL_OPT_TRAP_POLICER_RATE;
+ } else if (dl_argv_match(dl, "burst") &&
+ (o_all & DL_OPT_TRAP_POLICER_BURST)) {
+ dl_arg_inc(dl);
+ err = dl_argv_uint64_t(dl, &opts->trap_policer_burst);
+ if (err)
+ return err;
+ o_found |= DL_OPT_TRAP_POLICER_BURST;
} else {
pr_err("Unknown option \"%s\"\n", dl_argv(dl));
return -EINVAL;
opts->netns_is_pid ? DEVLINK_ATTR_NETNS_PID :
DEVLINK_ATTR_NETNS_FD,
opts->netns);
+ if (opts->present & DL_OPT_TRAP_POLICER_ID)
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_TRAP_POLICER_ID,
+ opts->trap_policer_id);
+ if (opts->present & DL_OPT_TRAP_POLICER_RATE)
+ mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_RATE,
+ opts->trap_policer_rate);
+ if (opts->present & DL_OPT_TRAP_POLICER_BURST)
+ mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_BURST,
+ opts->trap_policer_burst);
}
static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
pr_err("Usage: devlink dev show [ DEV ]\n");
pr_err(" devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n");
pr_err(" [ inline-mode { none | link | network | transport } ]\n");
- pr_err(" [ encap { disable | enable } ]\n");
+ pr_err(" [ encap-mode { none | basic } ]\n");
pr_err(" devlink dev eswitch show DEV\n");
pr_err(" devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
pr_err(" devlink dev param show [DEV name PARAMETER]\n");
if (tb[DEVLINK_ATTR_STATS_RX_PACKETS])
pr_out_u64(dl, "packets",
mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_PACKETS]));
+ if (tb[DEVLINK_ATTR_STATS_RX_DROPPED])
+ pr_out_u64(dl, "dropped",
+ mnl_attr_get_u64(tb[DEVLINK_ATTR_STATS_RX_DROPPED]));
pr_out_object_end(dl);
pr_out_object_end(dl);
}
}
}
+static const char *eswitch_encap_mode_name(uint32_t mode)
+{
+ switch (mode) {
+ case DEVLINK_ESWITCH_ENCAP_MODE_NONE:
+ return ESWITCH_ENCAP_MODE_NONE;
+ case DEVLINK_ESWITCH_ENCAP_MODE_BASIC:
+ return ESWITCH_ENCAP_MODE_BASIC;
+ default:
+ return "<unknown mode>";
+ }
+}
+
static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
{
__pr_out_handle_start(dl, tb, true, false);
tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
}
if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) {
- bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]);
-
check_indent_newline(dl);
- print_string(PRINT_ANY, "encap", "encap %s",
- encap_mode ? "enable" : "disable");
+ print_string(PRINT_ANY, "encap-mode", "encap-mode %s",
+ eswitch_encap_mode_name(mnl_attr_get_u8(
+ tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE])));
}
pr_out_handle_end(dl);
/* In child, just execute the flash and pass returned
* value through pipe once it is done.
*/
+ int cc;
+
close(pipe_r);
err = _mnlg_socket_send(dl->nlg, nlh);
- write(pipe_w, &err, sizeof(err));
+ cc = write(pipe_w, &err, sizeof(err));
close(pipe_w);
- exit(0);
+ exit(cc != sizeof(err));
}
close(pipe_w);
return "pcipf";
case DEVLINK_PORT_FLAVOUR_PCI_VF:
return "pcivf";
+ case DEVLINK_PORT_FLAVOUR_VIRTUAL:
+ return "virtual";
default:
return "<unknown flavour>";
}
case DEVLINK_CMD_FLASH_UPDATE: return "begin";
case DEVLINK_CMD_FLASH_UPDATE_END: return "end";
case DEVLINK_CMD_FLASH_UPDATE_STATUS: return "status";
+ case DEVLINK_CMD_HEALTH_REPORTER_RECOVER: return "status";
case DEVLINK_CMD_TRAP_GET: return "get";
case DEVLINK_CMD_TRAP_SET: return "set";
case DEVLINK_CMD_TRAP_NEW: return "new";
case DEVLINK_CMD_TRAP_GROUP_SET: return "set";
case DEVLINK_CMD_TRAP_GROUP_NEW: return "new";
case DEVLINK_CMD_TRAP_GROUP_DEL: return "del";
+ case DEVLINK_CMD_TRAP_POLICER_GET: return "get";
+ case DEVLINK_CMD_TRAP_POLICER_SET: return "set";
+ case DEVLINK_CMD_TRAP_POLICER_NEW: return "new";
+ case DEVLINK_CMD_TRAP_POLICER_DEL: return "del";
default: return "<unknown cmd>";
}
}
case DEVLINK_CMD_FLASH_UPDATE_END:
case DEVLINK_CMD_FLASH_UPDATE_STATUS:
return "flash";
+ case DEVLINK_CMD_HEALTH_REPORTER_RECOVER:
+ return "health";
case DEVLINK_CMD_TRAP_GET:
case DEVLINK_CMD_TRAP_SET:
case DEVLINK_CMD_TRAP_NEW:
case DEVLINK_CMD_TRAP_GROUP_NEW:
case DEVLINK_CMD_TRAP_GROUP_DEL:
return "trap-group";
+ case DEVLINK_CMD_TRAP_POLICER_GET:
+ case DEVLINK_CMD_TRAP_POLICER_SET:
+ case DEVLINK_CMD_TRAP_POLICER_NEW:
+ case DEVLINK_CMD_TRAP_POLICER_DEL:
+ return "trap-policer";
default: return "<unknown obj>";
}
}
}
static void pr_out_region(struct dl *dl, struct nlattr **tb);
+static void pr_out_health(struct dl *dl, struct nlattr **tb_health);
static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array);
static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array);
+static void pr_out_trap_policer(struct dl *dl, struct nlattr **tb, bool array);
static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
{
pr_out_mon_header(genl->cmd);
pr_out_flash_update(dl, tb);
break;
+ case DEVLINK_CMD_HEALTH_REPORTER_RECOVER:
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+ !tb[DEVLINK_ATTR_HEALTH_REPORTER])
+ return MNL_CB_ERROR;
+ pr_out_mon_header(genl->cmd);
+ pr_out_health(dl, tb);
+ break;
case DEVLINK_CMD_TRAP_GET: /* fall through */
case DEVLINK_CMD_TRAP_SET: /* fall through */
case DEVLINK_CMD_TRAP_NEW: /* fall through */
pr_out_mon_header(genl->cmd);
pr_out_trap_group(dl, tb, false);
break;
+ case DEVLINK_CMD_TRAP_POLICER_GET: /* fall through */
+ case DEVLINK_CMD_TRAP_POLICER_SET: /* fall through */
+ case DEVLINK_CMD_TRAP_POLICER_NEW: /* fall through */
+ case DEVLINK_CMD_TRAP_POLICER_DEL: /* fall through */
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+ !tb[DEVLINK_ATTR_TRAP_POLICER_ID] ||
+ !tb[DEVLINK_ATTR_TRAP_POLICER_RATE] ||
+ !tb[DEVLINK_ATTR_TRAP_POLICER_BURST])
+ return MNL_CB_ERROR;
+ pr_out_mon_header(genl->cmd);
+ pr_out_trap_policer(dl, tb, false);
+ break;
}
return MNL_CB_OK;
}
if (strcmp(cur_obj, "all") != 0 &&
strcmp(cur_obj, "dev") != 0 &&
strcmp(cur_obj, "port") != 0 &&
+ strcmp(cur_obj, "health") != 0 &&
strcmp(cur_obj, "trap") != 0 &&
- strcmp(cur_obj, "trap-group") != 0) {
+ strcmp(cur_obj, "trap-group") != 0 &&
+ strcmp(cur_obj, "trap-policer") != 0) {
pr_err("Unknown object \"%s\"\n", cur_obj);
return -EINVAL;
}
static void cmd_mon_help(void)
{
pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n"
- "where OBJECT-LIST := { dev | port | trap | trap-group }\n");
+ "where OBJECT-LIST := { dev | port | health | trap | trap-group | trap-policer }\n");
}
static int cmd_mon(struct dl *dl)
pr_err(" devlink health diagnose DEV reporter REPORTER_NAME\n");
pr_err(" devlink health dump show DEV reporter REPORTER_NAME\n");
pr_err(" devlink health dump clear DEV reporter REPORTER_NAME\n");
- pr_err(" devlink health set DEV reporter REPORTER_NAME { grace_period | auto_recover } { msec | boolean }\n");
+ pr_err(" devlink health set DEV reporter REPORTER_NAME\n");
+ pr_err(" [ grace_period MSEC ]\n");
+ pr_err(" [ auto_recover { true | false } ]\n");
}
static int cmd_health(struct dl *dl)
switch (attr->nla_type) {
case DEVLINK_ATTR_TRAP_METADATA_TYPE_IN_PORT:
return "input_port";
+ case DEVLINK_ATTR_TRAP_METADATA_TYPE_FA_COOKIE:
+ return "flow_action_cookie";
default:
return "<unknown metadata type>";
}
pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop } ]\n");
pr_err(" devlink trap show [ DEV trap TRAP ]\n");
pr_err(" devlink trap group set DEV group GROUP [ action { trap | drop } ]\n");
+ pr_err(" [ policer POLICER ] [ nopolicer ]\n");
pr_err(" devlink trap group show [ DEV group GROUP ]\n");
+ pr_err(" devlink trap policer set DEV policer POLICER [ rate RATE ] [ burst BURST ]\n");
+ pr_err(" devlink trap policer show DEV policer POLICER\n");
}
static int cmd_trap_show(struct dl *dl)
print_string(PRINT_ANY, "name", "name %s",
mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
print_bool(PRINT_ANY, "generic", " generic %s", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
+ if (tb[DEVLINK_ATTR_TRAP_POLICER_ID])
+ print_uint(PRINT_ANY, "policer", " policer %u",
+ mnl_attr_get_u32(tb[DEVLINK_ATTR_TRAP_POLICER_ID]));
pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
pr_out_handle_end(dl);
}
err = dl_argv_parse_put(nlh, dl,
DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME,
- DL_OPT_TRAP_ACTION);
+ DL_OPT_TRAP_ACTION | DL_OPT_TRAP_POLICER_ID);
if (err)
return err;
return -ENOENT;
}
+static void pr_out_trap_policer(struct dl *dl, struct nlattr **tb, bool array)
+{
+ if (array)
+ pr_out_handle_start_arr(dl, tb);
+ else
+ __pr_out_handle_start(dl, tb, true, false);
+
+ check_indent_newline(dl);
+ print_uint(PRINT_ANY, "policer", "policer %u",
+ mnl_attr_get_u32(tb[DEVLINK_ATTR_TRAP_POLICER_ID]));
+ print_u64(PRINT_ANY, "rate", " rate %llu",
+ mnl_attr_get_u64(tb[DEVLINK_ATTR_TRAP_POLICER_RATE]));
+ print_u64(PRINT_ANY, "burst", " burst %llu",
+ mnl_attr_get_u64(tb[DEVLINK_ATTR_TRAP_POLICER_BURST]));
+ if (tb[DEVLINK_ATTR_STATS])
+ pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
+ pr_out_handle_end(dl);
+}
+
+static int cmd_trap_policer_show_cb(const struct nlmsghdr *nlh, void *data)
+{
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ struct dl *dl = data;
+
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+ !tb[DEVLINK_ATTR_TRAP_POLICER_ID] ||
+ !tb[DEVLINK_ATTR_TRAP_POLICER_RATE] ||
+ !tb[DEVLINK_ATTR_TRAP_POLICER_BURST])
+ return MNL_CB_ERROR;
+
+ pr_out_trap_policer(dl, tb, true);
+
+ return MNL_CB_OK;
+}
+
+static int cmd_trap_policer_show(struct dl *dl)
+{
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
+ struct nlmsghdr *nlh;
+ int err;
+
+ if (dl_argc(dl) == 0)
+ flags |= NLM_F_DUMP;
+
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_POLICER_GET, flags);
+
+ if (dl_argc(dl) > 0) {
+ err = dl_argv_parse_put(nlh, dl,
+ DL_OPT_HANDLE | DL_OPT_TRAP_POLICER_ID,
+ 0);
+ if (err)
+ return err;
+ }
+
+ pr_out_section_start(dl, "trap_policer");
+ err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_trap_policer_show_cb, dl);
+ pr_out_section_end(dl);
+
+ return err;
+}
+
+static int cmd_trap_policer_set(struct dl *dl)
+{
+ struct nlmsghdr *nlh;
+ int err;
+
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_TRAP_POLICER_SET,
+ NLM_F_REQUEST | NLM_F_ACK);
+
+ err = dl_argv_parse_put(nlh, dl,
+ DL_OPT_HANDLE | DL_OPT_TRAP_POLICER_ID,
+ DL_OPT_TRAP_POLICER_RATE |
+ DL_OPT_TRAP_POLICER_BURST);
+ if (err)
+ return err;
+
+ return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+}
+
+static int cmd_trap_policer(struct dl *dl)
+{
+ if (dl_argv_match(dl, "help")) {
+ cmd_trap_help();
+ return 0;
+ } else if (dl_argv_match(dl, "show") ||
+ dl_argv_match(dl, "list") || dl_no_arg(dl)) {
+ dl_arg_inc(dl);
+ return cmd_trap_policer_show(dl);
+ } else if (dl_argv_match(dl, "set")) {
+ dl_arg_inc(dl);
+ return cmd_trap_policer_set(dl);
+ }
+ pr_err("Command \"%s\" not found\n", dl_argv(dl));
+ return -ENOENT;
+}
+
static int cmd_trap(struct dl *dl)
{
if (dl_argv_match(dl, "help")) {
} else if (dl_argv_match(dl, "group")) {
dl_arg_inc(dl);
return cmd_trap_group(dl);
+ } else if (dl_argv_match(dl, "policer")) {
+ dl_arg_inc(dl);
+ return cmd_trap_policer(dl);
}
pr_err("Command \"%s\" not found\n", dl_argv(dl));
return -ENOENT;