]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - devlink/devlink.c
devlink: Show controller number of a devlink port
[mirror_iproute2.git] / devlink / devlink.c
index f67fe6dd875903422b6e8f1f85a40a16a4918ff7..0374175eda3dd160268683fb0202c3e08d05ae2c 100644 (file)
 #include <limits.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <signal.h>
+#include <time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #include <sys/sysinfo.h>
 #define _LINUX_SYSINFO_H /* avoid collision with musl header */
 #include <linux/genetlink.h>
 #include <linux/devlink.h>
+#include <linux/netlink.h>
 #include <libmnl/libmnl.h>
 #include <netinet/ether.h>
+#include <sys/select.h>
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <rt_names.h>
 
-#include "SNAPSHOT.h"
+#include "version.h"
 #include "list.h"
 #include "mnlg.h"
-#include "json_writer.h"
+#include "json_print.h"
 #include "utils.h"
 #include "namespace.h"
 
@@ -292,6 +300,8 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #define DL_OPT_TRAP_POLICER_ID         BIT(34)
 #define DL_OPT_TRAP_POLICER_RATE       BIT(35)
 #define DL_OPT_TRAP_POLICER_BURST      BIT(36)
+#define DL_OPT_HEALTH_REPORTER_AUTO_DUMP     BIT(37)
+#define DL_OPT_PORT_FUNCTION_HW_ADDR BIT(38)
 
 struct dl_opts {
        uint64_t present; /* flags of present items */
@@ -328,6 +338,7 @@ struct dl_opts {
        const char *reporter_name;
        uint64_t reporter_graceful_period;
        bool reporter_auto_recover;
+       bool reporter_auto_dump;
        const char *trap_name;
        const char *trap_group_name;
        enum devlink_trap_action trap_action;
@@ -336,6 +347,8 @@ struct dl_opts {
        uint32_t trap_policer_id;
        uint64_t trap_policer_rate;
        uint64_t trap_policer_burst;
+       char port_function_hw_addr[MAX_ADDR_LEN];
+       uint32_t port_function_hw_addr_len;
 };
 
 struct dl {
@@ -427,6 +440,127 @@ static void __pr_out_indent_newline(struct dl *dl)
                pr_out(" ");
 }
 
+static bool is_binary_eol(int i)
+{
+       return !(i%16);
+}
+
+static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
+{
+       int i = 0;
+
+       while (i < len) {
+               if (dl->json_output)
+                       print_int(PRINT_JSON, NULL, NULL, data[i]);
+               else
+                       pr_out("%02x ", data[i]);
+               i++;
+               if (!dl->json_output && is_binary_eol(i))
+                       __pr_out_newline();
+       }
+       if (!dl->json_output && !is_binary_eol(i))
+               __pr_out_newline();
+}
+
+static void pr_out_name(struct dl *dl, const char *name)
+{
+       __pr_out_indent_newline(dl);
+       if (dl->json_output)
+               print_string(PRINT_JSON, name, NULL, NULL);
+       else
+               pr_out("%s:", name);
+}
+
+static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
+{
+       __pr_out_indent_newline(dl);
+       if (val == (uint64_t) -1)
+               return print_string_name_value(name, "unlimited");
+
+       if (dl->json_output)
+               print_u64(PRINT_JSON, name, NULL, val);
+       else
+               pr_out("%s %"PRIu64, name, val);
+}
+
+static void pr_out_section_start(struct dl *dl, const char *name)
+{
+       if (dl->json_output) {
+               open_json_object(NULL);
+               open_json_object(name);
+       }
+}
+
+static void pr_out_section_end(struct dl *dl)
+{
+       if (dl->json_output) {
+               if (dl->arr_last.present)
+                       close_json_array(PRINT_JSON, NULL);
+               close_json_object();
+               close_json_object();
+       }
+}
+
+static void pr_out_array_start(struct dl *dl, const char *name)
+{
+       if (dl->json_output) {
+               open_json_array(PRINT_JSON, name);
+       } else {
+               __pr_out_indent_inc();
+               __pr_out_newline();
+               pr_out("%s:", name);
+               __pr_out_indent_inc();
+               __pr_out_newline();
+       }
+}
+
+static void pr_out_array_end(struct dl *dl)
+{
+       if (dl->json_output) {
+               close_json_array(PRINT_JSON, NULL);
+       } else {
+               __pr_out_indent_dec();
+               __pr_out_indent_dec();
+       }
+}
+
+static void pr_out_object_start(struct dl *dl, const char *name)
+{
+       if (dl->json_output) {
+               open_json_object(name);
+       } else {
+               __pr_out_indent_inc();
+               __pr_out_newline();
+               pr_out("%s:", name);
+               __pr_out_indent_inc();
+               __pr_out_newline();
+       }
+}
+
+static void pr_out_object_end(struct dl *dl)
+{
+       if (dl->json_output) {
+               close_json_object();
+       } else {
+               __pr_out_indent_dec();
+               __pr_out_indent_dec();
+       }
+}
+
+static void pr_out_entry_start(struct dl *dl)
+{
+       if (dl->json_output)
+               open_json_object(NULL);
+}
+
+static void pr_out_entry_end(struct dl *dl)
+{
+       if (dl->json_output)
+               close_json_object();
+       else
+               __pr_out_newline();
+}
+
 static void check_indent_newline(struct dl *dl)
 {
        __pr_out_indent_newline(dl);
@@ -447,6 +581,8 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_PORT_NETDEV_IFINDEX] = MNL_TYPE_U32,
        [DEVLINK_ATTR_PORT_NETDEV_NAME] = MNL_TYPE_NUL_STRING,
        [DEVLINK_ATTR_PORT_IBDEV_NAME] = MNL_TYPE_NUL_STRING,
+       [DEVLINK_ATTR_PORT_LANES] = MNL_TYPE_U32,
+       [DEVLINK_ATTR_PORT_SPLITTABLE] = MNL_TYPE_U8,
        [DEVLINK_ATTR_SB_INDEX] = MNL_TYPE_U32,
        [DEVLINK_ATTR_SB_SIZE] = MNL_TYPE_U32,
        [DEVLINK_ATTR_SB_INGRESS_POOL_COUNT] = MNL_TYPE_U16,
@@ -514,6 +650,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_REGION_CHUNK_LEN] = MNL_TYPE_U64,
        [DEVLINK_ATTR_INFO_DRIVER_NAME] = MNL_TYPE_STRING,
        [DEVLINK_ATTR_INFO_SERIAL_NUMBER] = MNL_TYPE_STRING,
+       [DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER] = MNL_TYPE_STRING,
        [DEVLINK_ATTR_INFO_VERSION_FIXED] = MNL_TYPE_NESTED,
        [DEVLINK_ATTR_INFO_VERSION_RUNNING] = MNL_TYPE_NESTED,
        [DEVLINK_ATTR_INFO_VERSION_STORED] = MNL_TYPE_NESTED,
@@ -585,6 +722,30 @@ static int attr_stats_cb(const struct nlattr *attr, void *data)
        return MNL_CB_OK;
 }
 
+static const enum mnl_attr_data_type
+devlink_function_policy[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = {
+       [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR ] = MNL_TYPE_BINARY,
+};
+
+static int function_attr_cb(const struct nlattr *attr, void *data)
+{
+       const struct nlattr **tb = data;
+       int type;
+
+       /* Allow the tool to work on top of newer kernels that might contain
+        * more attributes.
+        */
+       if (mnl_attr_type_valid(attr, DEVLINK_PORT_FUNCTION_ATTR_MAX) < 0)
+               return MNL_CB_OK;
+
+       type = mnl_attr_get_type(attr);
+       if (mnl_attr_validate(attr, devlink_function_policy[type]) < 0)
+               return MNL_CB_ERROR;
+
+       tb[type] = attr;
+       return MNL_CB_OK;
+}
+
 static int ifname_map_cb(const struct nlmsghdr *nlh, void *data)
 {
        struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
@@ -1147,6 +1308,8 @@ static int trap_action_get(const char *actionstr,
                *p_action = DEVLINK_TRAP_ACTION_DROP;
        } else if (strcmp(actionstr, "trap") == 0) {
                *p_action = DEVLINK_TRAP_ACTION_TRAP;
+       } else if (strcmp(actionstr, "mirror") == 0) {
+               *p_action = DEVLINK_TRAP_ACTION_MIRROR;
        } else {
                pr_err("Unknown trap action \"%s\"\n", actionstr);
                return -EINVAL;
@@ -1154,6 +1317,17 @@ static int trap_action_get(const char *actionstr,
        return 0;
 }
 
+static int hw_addr_parse(const char *addrstr, char *hw_addr, uint32_t *len)
+{
+       int alen;
+
+       alen = ll_addr_a2n(hw_addr, MAX_ADDR_LEN, addrstr);
+       if (alen < 0)
+               return -EINVAL;
+       *len = alen;
+       return 0;
+}
+
 struct dl_args_metadata {
        uint64_t o_flag;
        char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN];
@@ -1184,6 +1358,7 @@ static const struct dl_args_metadata dl_args_required[] = {
        {DL_OPT_HEALTH_REPORTER_NAME, "Reporter's name is expected."},
        {DL_OPT_TRAP_NAME,            "Trap's name is expected."},
        {DL_OPT_TRAP_GROUP_NAME,      "Trap group's name is expected."},
+       {DL_OPT_PORT_FUNCTION_HW_ADDR, "Port function's hardware address is expected."},
 };
 
 static int dl_args_finding_required_validate(uint64_t o_required,
@@ -1474,6 +1649,13 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        o_found |= DL_OPT_HEALTH_REPORTER_AUTO_RECOVER;
+               } else if (dl_argv_match(dl, "auto_dump") &&
+                       (o_all & DL_OPT_HEALTH_REPORTER_AUTO_DUMP)) {
+                       dl_arg_inc(dl);
+                       err = dl_argv_bool(dl, &opts->reporter_auto_dump);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_HEALTH_REPORTER_AUTO_DUMP;
                } else if (dl_argv_match(dl, "trap") &&
                           (o_all & DL_OPT_TRAP_NAME)) {
                        dl_arg_inc(dl);
@@ -1543,6 +1725,20 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        o_found |= DL_OPT_TRAP_POLICER_BURST;
+               } else if (dl_argv_match(dl, "hw_addr") &&
+                          (o_all & DL_OPT_PORT_FUNCTION_HW_ADDR)) {
+                       const char *addrstr;
+
+                       dl_arg_inc(dl);
+                       err = dl_argv_str(dl, &addrstr);
+                       if (err)
+                               return err;
+                       err = hw_addr_parse(addrstr, opts->port_function_hw_addr,
+                                           &opts->port_function_hw_addr_len);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_PORT_FUNCTION_HW_ADDR;
+
                } else {
                        pr_err("Unknown option \"%s\"\n", dl_argv(dl));
                        return -EINVAL;
@@ -1559,6 +1755,18 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
        return dl_args_finding_required_validate(o_required, o_found);
 }
 
+static void
+dl_function_attr_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+       struct nlattr *nest;
+
+       nest = mnl_attr_nest_start(nlh, DEVLINK_ATTR_PORT_FUNCTION);
+       mnl_attr_put(nlh, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR,
+                    opts->port_function_hw_addr_len,
+                    opts->port_function_hw_addr);
+       mnl_attr_nest_end(nlh, nest);
+}
+
 static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
 {
        struct dl_opts *opts = &dl->opts;
@@ -1656,6 +1864,9 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
        if (opts->present & DL_OPT_HEALTH_REPORTER_AUTO_RECOVER)
                mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,
                                opts->reporter_auto_recover);
+       if (opts->present & DL_OPT_HEALTH_REPORTER_AUTO_DUMP)
+               mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP,
+                               opts->reporter_auto_dump);
        if (opts->present & DL_OPT_TRAP_NAME)
                mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME,
                                  opts->trap_name);
@@ -1679,6 +1890,8 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
        if (opts->present & DL_OPT_TRAP_POLICER_BURST)
                mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_BURST,
                                 opts->trap_policer_burst);
+       if (opts->present & DL_OPT_PORT_FUNCTION_HW_ADDR)
+               dl_function_attr_put(nlh, opts);
 }
 
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
@@ -1902,7 +2115,19 @@ static void __pr_out_port_handle_start(struct dl *dl, const char *bus_name,
                        open_json_object(buf);
                }
        } else {
-               pr_out("%s:", buf);
+               if (array) {
+                       if (should_arr_last_port_handle_end(dl, bus_name, dev_name, port_index))
+                               __pr_out_indent_dec();
+                       if (should_arr_last_port_handle_start(dl, bus_name,
+                                                             dev_name, port_index)) {
+                               pr_out("%s:", buf);
+                               __pr_out_newline();
+                               __pr_out_indent_inc();
+                               arr_last_port_handle_set(dl, bus_name, dev_name, port_index);
+                       }
+               } else {
+                       pr_out("%s:", buf);
+               }
        }
 }
 
@@ -1938,49 +2163,6 @@ static void pr_out_port_handle_end(struct dl *dl)
                pr_out("\n");
 }
 
-static void pr_out_u64(struct dl *dl, const char *name, uint64_t val)
-{
-       __pr_out_indent_newline(dl);
-       if (val == (uint64_t) -1)
-               return print_string_name_value(name, "unlimited");
-
-       if (dl->json_output)
-               print_u64(PRINT_JSON, name, NULL, val);
-       else
-               pr_out("%s %"PRIu64, name, val);
-}
-
-static bool is_binary_eol(int i)
-{
-       return !(i%16);
-}
-
-static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
-{
-       int i = 0;
-
-       while (i < len) {
-               if (dl->json_output)
-                       print_int(PRINT_JSON, NULL, NULL, data[i]);
-               else
-                       pr_out("%02x ", data[i]);
-               i++;
-               if (!dl->json_output && is_binary_eol(i))
-                       __pr_out_newline();
-       }
-       if (!dl->json_output && !is_binary_eol(i))
-               __pr_out_newline();
-}
-
-static void pr_out_name(struct dl *dl, const char *name)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               print_string(PRINT_JSON, name, NULL, NULL);
-       else
-               pr_out("%s:", name);
-}
-
 static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr)
 {
        if (dl->json_output) {
@@ -2022,84 +2204,6 @@ static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
        pr_out_region_chunk_end(dl);
 }
 
-static void pr_out_section_start(struct dl *dl, const char *name)
-{
-       if (dl->json_output) {
-               open_json_object(NULL);
-               open_json_object(name);
-       }
-}
-
-static void pr_out_section_end(struct dl *dl)
-{
-       if (dl->json_output) {
-               if (dl->arr_last.present)
-                       close_json_array(PRINT_JSON, NULL);
-               close_json_object();
-               close_json_object();
-       }
-}
-
-static void pr_out_array_start(struct dl *dl, const char *name)
-{
-       if (dl->json_output) {
-               open_json_array(PRINT_JSON, name);
-       } else {
-               __pr_out_indent_inc();
-               __pr_out_newline();
-               pr_out("%s:", name);
-               __pr_out_indent_inc();
-               __pr_out_newline();
-       }
-}
-
-static void pr_out_array_end(struct dl *dl)
-{
-       if (dl->json_output) {
-               close_json_array(PRINT_JSON, NULL);
-       } else {
-               __pr_out_indent_dec();
-               __pr_out_indent_dec();
-       }
-}
-
-static void pr_out_object_start(struct dl *dl, const char *name)
-{
-       if (dl->json_output) {
-               open_json_object(name);
-       } else {
-               __pr_out_indent_inc();
-               __pr_out_newline();
-               pr_out("%s:", name);
-               __pr_out_indent_inc();
-               __pr_out_newline();
-       }
-}
-
-static void pr_out_object_end(struct dl *dl)
-{
-       if (dl->json_output) {
-               close_json_object();
-       } else {
-               __pr_out_indent_dec();
-               __pr_out_indent_dec();
-       }
-}
-
-static void pr_out_entry_start(struct dl *dl)
-{
-       if (dl->json_output)
-               open_json_object(NULL);
-}
-
-static void pr_out_entry_end(struct dl *dl)
-{
-       if (dl->json_output)
-               close_json_object();
-       else
-               __pr_out_newline();
-}
-
 static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats)
 {
        struct nlattr *tb[DEVLINK_ATTR_STATS_MAX + 1] = {};
@@ -2337,6 +2441,11 @@ static const struct param_val_conv param_val_conv[] = {
                .vstr = "flash",
                .vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_FLASH,
        },
+       {
+               .name = "fw_load_policy",
+               .vstr = "disk",
+               .vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_DISK,
+       },
        {
                .name = "reset_dev_on_drv_probe",
                .vstr = "unknown",
@@ -2873,6 +2982,16 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
                print_string(PRINT_ANY, "serial_number", "serial_number %s",
                             mnl_attr_get_str(nla_sn));
        }
+
+       if (tb[DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER]) {
+               struct nlattr *nla_bsn = tb[DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER];
+
+               if (!dl->json_output)
+                       __pr_out_newline();
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "board.serial_number", "board.serial_number %s",
+                            mnl_attr_get_str(nla_bsn));
+       }
        __pr_out_indent_dec();
 
        if (has_versions) {
@@ -2908,6 +3027,7 @@ static int cmd_versions_show_cb(const struct nlmsghdr *nlh, void *data)
                tb[DEVLINK_ATTR_INFO_VERSION_STORED];
        has_info = tb[DEVLINK_ATTR_INFO_DRIVER_NAME] ||
                tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER] ||
+               tb[DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER] ||
                has_versions;
 
        if (has_info)
@@ -3184,6 +3304,8 @@ static void cmd_port_help(void)
        pr_err("       devlink port set DEV/PORT_INDEX [ type { eth | ib | auto} ]\n");
        pr_err("       devlink port split DEV/PORT_INDEX count COUNT\n");
        pr_err("       devlink port unsplit DEV/PORT_INDEX\n");
+       pr_err("       devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ]\n");
+       pr_err("       devlink port health show [ DEV/PORT_INDEX reporter REPORTER_NAME ]\n");
 }
 
 static const char *port_type_name(uint32_t type)
@@ -3221,6 +3343,9 @@ static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb)
 {
        uint16_t fn_num;
 
+       if (tb[DEVLINK_ATTR_PORT_CONTROLLER_NUMBER])
+               print_uint(PRINT_ANY, "controller", " controller %u",
+                          mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_CONTROLLER_NUMBER]));
        if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
                fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
                print_uint(PRINT_ANY, "pfnum", " pfnum %u", fn_num);
@@ -3229,6 +3354,43 @@ static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb)
                fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
                print_uint(PRINT_ANY, "vfnum", " vfnum %u", fn_num);
        }
+       if (tb[DEVLINK_ATTR_PORT_EXTERNAL]) {
+               uint8_t external;
+
+               external = mnl_attr_get_u8(tb[DEVLINK_ATTR_PORT_EXTERNAL]);
+               print_bool(PRINT_ANY, "external", " external %s", external);
+       }
+}
+
+static void pr_out_port_function(struct dl *dl, struct nlattr **tb_port)
+{
+       struct nlattr *tb[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = {};
+       unsigned char *data;
+       SPRINT_BUF(hw_addr);
+       uint32_t len;
+       int err;
+
+       if (!tb_port[DEVLINK_ATTR_PORT_FUNCTION])
+               return;
+
+       err = mnl_attr_parse_nested(tb_port[DEVLINK_ATTR_PORT_FUNCTION],
+                                   function_attr_cb, tb);
+       if (err != MNL_CB_OK)
+               return;
+
+       if (!tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR])
+               return;
+
+       len = mnl_attr_get_payload_len(tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]);
+       data = mnl_attr_get_payload(tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]);
+
+       pr_out_object_start(dl, "function");
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "hw_addr", "hw_addr %s",
+                    ll_addr_n2a(data, len, 0, hw_addr, sizeof(hw_addr)));
+       if (!dl->json_output)
+               __pr_out_indent_dec();
+       pr_out_object_end(dl);
 }
 
 static void pr_out_port(struct dl *dl, struct nlattr **tb)
@@ -3284,6 +3446,14 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
        if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
                print_uint(PRINT_ANY, "split_group", " split_group %u",
                           mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_SPLIT_GROUP]));
+       if (tb[DEVLINK_ATTR_PORT_SPLITTABLE])
+               print_bool(PRINT_ANY, "splittable", " splittable %s",
+                          mnl_attr_get_u8(tb[DEVLINK_ATTR_PORT_SPLITTABLE]));
+       if (tb[DEVLINK_ATTR_PORT_LANES])
+               print_uint(PRINT_ANY, "lanes", " lanes %u",
+                          mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_LANES]));
+
+       pr_out_port_function(dl, tb);
        pr_out_port_handle_end(dl);
 }
 
@@ -3369,6 +3539,41 @@ static int cmd_port_unsplit(struct dl *dl)
        return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
 }
 
+static void cmd_port_function_help(void)
+{
+       pr_err("Usage: devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ]\n");
+}
+
+static int cmd_port_function_set(struct dl *dl)
+{
+       struct nlmsghdr *nlh;
+       int err;
+
+       nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET, NLM_F_REQUEST | NLM_F_ACK);
+
+       err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_FUNCTION_HW_ADDR, 0);
+       if (err)
+               return err;
+
+       return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+}
+
+static int cmd_port_function(struct dl *dl)
+{
+       if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
+               cmd_port_function_help();
+               return 0;
+       } else if (dl_argv_match(dl, "set")) {
+               dl_arg_inc(dl);
+               return cmd_port_function_set(dl);
+       }
+       pr_err("Command \"%s\" not found\n", dl_argv(dl));
+       return -ENOENT;
+}
+
+static int cmd_health(struct dl *dl);
+static int __cmd_health_show(struct dl *dl, bool show_device, bool show_port);
+
 static int cmd_port(struct dl *dl)
 {
        if (dl_argv_match(dl, "help")) {
@@ -3387,6 +3592,18 @@ static int cmd_port(struct dl *dl)
        } else if (dl_argv_match(dl, "unsplit")) {
                dl_arg_inc(dl);
                return cmd_port_unsplit(dl);
+       } else if (dl_argv_match(dl, "function")) {
+               dl_arg_inc(dl);
+               return cmd_port_function(dl);
+       } else if (dl_argv_match(dl, "health")) {
+               dl_arg_inc(dl);
+               if (dl_argv_match(dl, "list") || dl_no_arg(dl)
+                   || (dl_argv_match(dl, "show") && dl_argc(dl) == 1)) {
+                       dl_arg_inc(dl);
+                       return __cmd_health_show(dl, false, true);
+               } else {
+                       return cmd_health(dl);
+               }
        }
        pr_err("Command \"%s\" not found\n", dl_argv(dl));
        return -ENOENT;
@@ -4319,7 +4536,8 @@ static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
 }
 
 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_health(struct dl *dl, struct nlattr **tb_health,
+                         bool show_device, bool show_port);
 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);
@@ -4398,7 +4616,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                    !tb[DEVLINK_ATTR_HEALTH_REPORTER])
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
-               pr_out_health(dl, tb);
+               pr_out_health(dl, tb, true, true);
                pr_out_mon_footer();
                break;
        case DEVLINK_CMD_TRAP_GET: /* fall through */
@@ -4445,6 +4663,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                pr_out_trap_policer(dl, tb, false);
                break;
        }
+       fflush(stdout);
        return MNL_CB_OK;
 }
 
@@ -6464,10 +6683,47 @@ static int cmd_region_read(struct dl *dl)
        return err;
 }
 
+static int cmd_region_snapshot_new_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_REGION_NAME] ||
+           !tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID])
+               return MNL_CB_ERROR;
+
+       pr_out_region(dl, tb);
+
+       return MNL_CB_OK;
+}
+
+static int cmd_region_snapshot_new(struct dl *dl)
+{
+       struct nlmsghdr *nlh;
+       int err;
+
+       nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_NEW,
+                              NLM_F_REQUEST | NLM_F_ACK);
+
+       err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION,
+                               DL_OPT_REGION_SNAPSHOT_ID);
+       if (err)
+               return err;
+
+       pr_out_section_start(dl, "regions");
+       err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_snapshot_new_cb, dl);
+       pr_out_section_end(dl);
+       return err;
+}
+
 static void cmd_region_help(void)
 {
        pr_err("Usage: devlink region show [ DEV/REGION ]\n");
        pr_err("       devlink region del DEV/REGION snapshot SNAPSHOT_ID\n");
+       pr_err("       devlink region new DEV/REGION snapshot SNAPSHOT_ID\n");
        pr_err("       devlink region dump DEV/REGION [ snapshot SNAPSHOT_ID ]\n");
        pr_err("       devlink region read DEV/REGION [ snapshot SNAPSHOT_ID ] address ADDRESS length LENGTH\n");
 }
@@ -6491,6 +6747,9 @@ static int cmd_region(struct dl *dl)
        } else if (dl_argv_match(dl, "read")) {
                dl_arg_inc(dl);
                return cmd_region_read(dl);
+       } else if (dl_argv_match(dl, "new")) {
+               dl_arg_inc(dl);
+               return cmd_region_snapshot_new(dl);
        }
        pr_err("Command \"%s\" not found\n", dl_argv(dl));
        return -ENOENT;
@@ -6503,9 +6762,10 @@ static int cmd_health_set_params(struct dl *dl)
 
        nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_HEALTH_REPORTER_SET,
                               NLM_F_REQUEST | NLM_F_ACK);
-       err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME,
+       err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HANDLEP | DL_OPT_HEALTH_REPORTER_NAME,
                            DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD |
-                           DL_OPT_HEALTH_REPORTER_AUTO_RECOVER);
+                           DL_OPT_HEALTH_REPORTER_AUTO_RECOVER |
+                           DL_OPT_HEALTH_REPORTER_AUTO_DUMP);
        if (err)
                return err;
 
@@ -6522,7 +6782,8 @@ static int cmd_health_dump_clear(struct dl *dl)
                               NLM_F_REQUEST | NLM_F_ACK);
 
        err = dl_argv_parse_put(nlh, dl,
-                               DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME, 0);
+                               DL_OPT_HANDLE | DL_OPT_HANDLEP |
+                               DL_OPT_HEALTH_REPORTER_NAME, 0);
        if (err)
                return err;
 
@@ -6769,7 +7030,8 @@ static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
        nlh = mnlg_msg_prepare(dl->nlg, cmd, flags | NLM_F_REQUEST | NLM_F_ACK);
 
        err = dl_argv_parse_put(nlh, dl,
-                               DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME, 0);
+                               DL_OPT_HANDLE | DL_OPT_HANDLEP |
+                               DL_OPT_HEALTH_REPORTER_NAME, 0);
        if (err)
                return err;
 
@@ -6802,7 +7064,8 @@ static int cmd_health_recover(struct dl *dl)
                               NLM_F_REQUEST | NLM_F_ACK);
 
        err = dl_argv_parse_put(nlh, dl,
-                               DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME, 0);
+                               DL_OPT_HANDLE | DL_OPT_HANDLEP |
+                               DL_OPT_HEALTH_REPORTER_NAME, 0);
        if (err)
                return err;
 
@@ -6876,7 +7139,8 @@ static void pr_out_dump_report_timestamp(struct dl *dl, const struct nlattr *att
        print_string(PRINT_ANY, "last_dump_time", " last_dump_time %s", dump_time);
 }
 
-static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
+static void pr_out_health(struct dl *dl, struct nlattr **tb_health,
+                         bool print_device, bool print_port)
 {
        struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
        enum devlink_health_reporter_state state;
@@ -6893,7 +7157,20 @@ static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
            !tb[DEVLINK_ATTR_HEALTH_REPORTER_STATE])
                return;
 
-       pr_out_handle_start_arr(dl, tb_health);
+       if (!print_device && !print_port)
+               return;
+       if (print_port) {
+               if (!print_device && !tb_health[DEVLINK_ATTR_PORT_INDEX])
+                       return;
+               else if (tb_health[DEVLINK_ATTR_PORT_INDEX])
+                       pr_out_port_handle_start_arr(dl, tb_health, false);
+       }
+       if (print_device) {
+               if (!print_port && tb_health[DEVLINK_ATTR_PORT_INDEX])
+                       return;
+               else if (!tb_health[DEVLINK_ATTR_PORT_INDEX])
+                       pr_out_handle_start_arr(dl, tb_health);
+       }
 
        check_indent_newline(dl);
        print_string(PRINT_ANY, "reporter", "reporter %s",
@@ -6919,30 +7196,41 @@ static void pr_out_health(struct dl *dl, struct nlattr **tb_health)
        if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])
                print_bool(PRINT_ANY, "auto_recover", " auto_recover %s",
                           mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]));
+       if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP])
+               print_bool(PRINT_ANY, "auto_dump", " auto_dump %s",
+                          mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]));
 
        __pr_out_indent_dec();
        pr_out_handle_end(dl);
 }
 
+struct health_ctx {
+       struct dl *dl;
+       bool show_device;
+       bool show_port;
+};
+
 static int cmd_health_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;
+       struct health_ctx *ctx = data;
+       struct dl *dl = ctx->dl;
 
        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_health(dl, tb);
+       pr_out_health(dl, tb, ctx->show_device, ctx->show_port);
 
        return MNL_CB_OK;
 }
 
-static int cmd_health_show(struct dl *dl)
+static int __cmd_health_show(struct dl *dl, bool show_device, bool show_port)
 {
        struct nlmsghdr *nlh;
+       struct health_ctx ctx = { dl, show_device, show_port };
        uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
        int err;
 
@@ -6952,29 +7240,31 @@ static int cmd_health_show(struct dl *dl)
                               flags);
 
        if (dl_argc(dl) > 0) {
+               ctx.show_port = true;
                err = dl_argv_parse_put(nlh, dl,
-                                       DL_OPT_HANDLE |
+                                       DL_OPT_HANDLE | DL_OPT_HANDLEP |
                                        DL_OPT_HEALTH_REPORTER_NAME, 0);
                if (err)
                        return err;
        }
        pr_out_section_start(dl, "health");
 
-       err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_health_show_cb, dl);
+       err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_health_show_cb, &ctx);
        pr_out_section_end(dl);
        return err;
 }
 
 static void cmd_health_help(void)
 {
-       pr_err("Usage: devlink health show [ dev DEV reporter REPORTER_NAME ]\n");
-       pr_err("       devlink health recover DEV reporter REPORTER_NAME\n");
-       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\n");
+       pr_err("Usage: devlink health show [ { DEV | DEV/PORT_INDEX } reporter REPORTER_NAME ]\n");
+       pr_err("       devlink health recover { DEV | DEV/PORT_INDEX } reporter REPORTER_NAME\n");
+       pr_err("       devlink health diagnose { DEV | DEV/PORT_INDEX } reporter REPORTER_NAME\n");
+       pr_err("       devlink health dump show { DEV | DEV/PORT_INDEX } reporter REPORTER_NAME\n");
+       pr_err("       devlink health dump clear { DEV | DEV/PORT_INDEX } reporter REPORTER_NAME\n");
+       pr_err("       devlink health set { DEV | DEV/PORT_INDEX } reporter REPORTER_NAME\n");
        pr_err("                          [ grace_period MSEC ]\n");
        pr_err("                          [ auto_recover { true | false } ]\n");
+       pr_err("                          [ auto_dump    { true | false } ]\n");
 }
 
 static int cmd_health(struct dl *dl)
@@ -6985,7 +7275,7 @@ static int cmd_health(struct dl *dl)
        } else if (dl_argv_match(dl, "show") ||
                   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
                dl_arg_inc(dl);
-               return cmd_health_show(dl);
+               return __cmd_health_show(dl, true, true);
        } else if (dl_argv_match(dl, "recover")) {
                dl_arg_inc(dl);
                return cmd_health_recover(dl);
@@ -7016,6 +7306,8 @@ static const char *trap_type_name(uint8_t type)
                return "drop";
        case DEVLINK_TRAP_TYPE_EXCEPTION:
                return "exception";
+       case DEVLINK_TRAP_TYPE_CONTROL:
+               return "control";
        default:
                return "<unknown type>";
        }
@@ -7028,6 +7320,8 @@ static const char *trap_action_name(uint8_t action)
                return "drop";
        case DEVLINK_TRAP_ACTION_TRAP:
                return "trap";
+       case DEVLINK_TRAP_ACTION_MIRROR:
+               return "mirror";
        default:
                return "<unknown action>";
        }
@@ -7102,9 +7396,9 @@ static int cmd_trap_show_cb(const struct nlmsghdr *nlh, void *data)
 
 static void cmd_trap_help(void)
 {
-       pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop } ]\n");
+       pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop | mirror } ]\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("       devlink trap group set DEV group GROUP [ action { trap | drop | mirror } ]\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");
@@ -7531,7 +7825,7 @@ int main(int argc, char **argv)
 
                switch (opt) {
                case 'V':
-                       printf("devlink utility, iproute2-ss%s\n", SNAPSHOT);
+                       printf("devlink utility, iproute2-%s\n", version);
                        ret = EXIT_SUCCESS;
                        goto dl_free;
                case 'f':