]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - devlink/devlink.c
devlink: Introduce PCI SF port flavour and attribute
[mirror_iproute2.git] / devlink / devlink.c
index e05a2336787a4a28fcf00db0bfb94bbdac5e441e..338cb03532527f1434d22279a71d1e7546e9045c 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 <sys/time.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"
 
@@ -41,6 +50,9 @@
 #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"
@@ -149,6 +161,30 @@ static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
        return 0;
 }
 
+static void dummy_signal_handler(int signum)
+{
+}
+
+static int _mnlg_socket_recv_run_intr(struct mnlg_socket *nlg,
+                                     mnl_cb_t data_cb, void *data)
+{
+       struct sigaction act, oact;
+       int err;
+
+       act.sa_handler = dummy_signal_handler;
+       sigemptyset(&act.sa_mask);
+       act.sa_flags = SA_NODEFER;
+
+       sigaction(SIGINT, &act, &oact);
+       err = mnlg_socket_recv_run(nlg, data_cb, data);
+       sigaction(SIGINT, &oact, NULL);
+       if (err < 0 && errno != EINTR) {
+               pr_err("devlink answers: %s\n", strerror(errno));
+               return -errno;
+       }
+       return 0;
+}
+
 static int _mnlg_socket_send(struct mnlg_socket *nlg,
                             const struct nlmsghdr *nlh)
 {
@@ -262,6 +298,14 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #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)
+#define DL_OPT_HEALTH_REPORTER_AUTO_DUMP     BIT(37)
+#define DL_OPT_PORT_FUNCTION_HW_ADDR BIT(38)
+#define DL_OPT_FLASH_OVERWRITE         BIT(39)
+#define DL_OPT_RELOAD_ACTION           BIT(40)
+#define DL_OPT_RELOAD_LIMIT    BIT(41)
 
 struct dl_opts {
        uint64_t present; /* flags of present items */
@@ -280,10 +324,10 @@ struct dl_opts {
        enum devlink_eswitch_mode eswitch_mode;
        enum devlink_eswitch_inline_mode eswitch_inline_mode;
        const char *dpipe_table_name;
-       bool dpipe_counters_enable;
-       bool eswitch_encap_mode;
+       bool dpipe_counters_enabled;
+       enum devlink_eswitch_encap_mode eswitch_encap_mode;
        const char *resource_path;
-       uint32_t resource_size;
+       uint64_t resource_size;
        uint32_t resource_id;
        bool resource_id_valid;
        const char *param_name;
@@ -298,11 +342,20 @@ 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;
        bool netns_is_pid;
        uint32_t netns;
+       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;
+       uint32_t overwrite_mask;
+       enum devlink_reload_action reload_action;
+       enum devlink_reload_limit reload_limit;
 };
 
 struct dl {
@@ -312,7 +365,6 @@ struct dl {
        char **argv;
        bool no_nice_names;
        struct dl_opts opts;
-       json_writer_t *jw;
        bool json_output;
        bool pretty_output;
        bool verbose;
@@ -395,6 +447,138 @@ 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);
+
+       if (g_indent_newline && !is_json_context()) {
+               printf("%s", g_indent_str);
+               g_indent_newline = false;
+       }
+       g_new_line_count = 0;
+}
+
 static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_BUS_NAME] = MNL_TYPE_NUL_STRING,
        [DEVLINK_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
@@ -404,6 +588,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,
@@ -471,6 +657,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,
@@ -495,12 +682,25 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
        [DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
        [DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
+       [DEVLINK_ATTR_DEV_STATS] = MNL_TYPE_NESTED,
+       [DEVLINK_ATTR_RELOAD_STATS] = MNL_TYPE_NESTED,
+       [DEVLINK_ATTR_RELOAD_STATS_ENTRY] = MNL_TYPE_NESTED,
+       [DEVLINK_ATTR_RELOAD_ACTION] = MNL_TYPE_U8,
+       [DEVLINK_ATTR_RELOAD_STATS_LIMIT] = MNL_TYPE_U8,
+       [DEVLINK_ATTR_RELOAD_STATS_VALUE] = MNL_TYPE_U32,
+       [DEVLINK_ATTR_REMOTE_RELOAD_STATS] = MNL_TYPE_NESTED,
+       [DEVLINK_ATTR_RELOAD_ACTION_INFO] = MNL_TYPE_NESTED,
+       [DEVLINK_ATTR_RELOAD_ACTION_STATS] = MNL_TYPE_NESTED,
+       [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)
@@ -538,6 +738,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] = {};
@@ -718,9 +942,11 @@ static int strtobool(const char *str, bool *p_val)
 {
        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;
@@ -1055,28 +1281,34 @@ static int eswitch_inline_mode_get(const char *typestr,
        return 0;
 }
 
-static int dpipe_counters_enable_get(const char *typestr,
-                                    bool *counters_enable)
+static int
+eswitch_encap_mode_get(const char *typestr,
+                      enum devlink_eswitch_encap_mode *p_encap_mode)
 {
-       if (strcmp(typestr, "enable") == 0) {
-               *counters_enable = 1;
-       } else if (strcmp(typestr, "disable") == 0) {
-               *counters_enable = 0;
+       /* 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 counter_state \"%s\"\n", typestr);
+               pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
                return -EINVAL;
        }
        return 0;
 }
 
-static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
+static int flash_overwrite_section_get(const char *sectionstr, uint32_t *mask)
 {
-       if (strcmp(typestr, "enable") == 0) {
-               *p_mode = true;
-       } else if (strcmp(typestr, "disable") == 0) {
-               *p_mode = false;
+       if (strcmp(sectionstr, "settings") == 0) {
+               *mask |= DEVLINK_FLASH_OVERWRITE_SETTINGS;
+       } else if (strcmp(sectionstr, "identifiers") == 0) {
+               *mask |= DEVLINK_FLASH_OVERWRITE_IDENTIFIERS;
        } else {
-               pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
+               pr_err("Unknown overwrite section \"%s\"\n", sectionstr);
                return -EINVAL;
        }
        return 0;
@@ -1105,6 +1337,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;
@@ -1112,6 +1346,54 @@ 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;
+}
+
+static int reload_action_get(struct dl *dl, const char *actionstr,
+                            enum devlink_reload_action *action)
+{
+       if (strcmp(actionstr, "driver_reinit") == 0) {
+               *action = DEVLINK_RELOAD_ACTION_DRIVER_REINIT;
+       } else if (strcmp(actionstr, "fw_activate") == 0) {
+               *action = DEVLINK_RELOAD_ACTION_FW_ACTIVATE;
+       } else {
+               pr_err("Unknown reload action \"%s\"\n", actionstr);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int reload_limit_get(struct dl *dl, const char *limitstr,
+                            enum devlink_reload_limit *limit)
+{
+       if (strcmp(limitstr, "no_reset") == 0) {
+               *limit = DEVLINK_RELOAD_LIMIT_NO_RESET;
+       } else {
+               pr_err("Unknown reload limit \"%s\"\n", limitstr);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static struct str_num_map port_flavour_map[] = {
+       { .str = "physical", .num = DEVLINK_PORT_FLAVOUR_PHYSICAL },
+       { .str = "cpu", .num = DEVLINK_PORT_FLAVOUR_CPU },
+       { .str = "dsa", .num = DEVLINK_PORT_FLAVOUR_DSA },
+       { .str = "pcipf", .num = DEVLINK_PORT_FLAVOUR_PCI_PF },
+       { .str = "pcivf", .num = DEVLINK_PORT_FLAVOUR_PCI_VF },
+       { .str = "pcisf", .num = DEVLINK_PORT_FLAVOUR_PCI_SF },
+       { .str = "virtual", .num = DEVLINK_PORT_FLAVOUR_VIRTUAL},
+       { .str = NULL, },
+};
+
 struct dl_args_metadata {
        uint64_t o_flag;
        char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN];
@@ -1142,6 +1424,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,
@@ -1179,6 +1462,7 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                                          &opts->port_index, &handle_bit);
                if (err)
                        return err;
+               o_required &= ~(DL_OPT_HANDLE | DL_OPT_HANDLEP) | handle_bit;
                o_found |= handle_bit;
        } else if (o_required & DL_OPT_HANDLE) {
                err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name);
@@ -1312,20 +1596,16 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        o_found |= DL_OPT_DPIPE_TABLE_NAME;
-               } else if (dl_argv_match(dl, "counters") &&
+               } else if ((dl_argv_match(dl, "counters") ||
+                           dl_argv_match(dl, "counters_enabled")) &&
                           (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_enabled);
                        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;
 
@@ -1348,7 +1628,7 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                } else if (dl_argv_match(dl, "size") &&
                           (o_all & DL_OPT_RESOURCE_SIZE)) {
                        dl_arg_inc(dl);
-                       err = dl_argv_uint32_t(dl, &opts->resource_size);
+                       err = dl_argv_uint64_t(dl, &opts->resource_size);
                        if (err)
                                return err;
                        o_found |= DL_OPT_RESOURCE_SIZE;
@@ -1413,6 +1693,21 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        o_found |= DL_OPT_FLASH_COMPONENT;
+
+               } else if (dl_argv_match(dl, "overwrite") &&
+                               (o_all & DL_OPT_FLASH_OVERWRITE)) {
+                       const char *sectionstr;
+
+                       dl_arg_inc(dl);
+                       err = dl_argv_str(dl, &sectionstr);
+                       if(err)
+                               return err;
+                       err = flash_overwrite_section_get(sectionstr,
+                                                         &opts->overwrite_mask);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_FLASH_OVERWRITE;
+
                } else if (dl_argv_match(dl, "reporter") &&
                           (o_all & DL_OPT_HEALTH_REPORTER_NAME)) {
                        dl_arg_inc(dl);
@@ -1435,6 +1730,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);
@@ -1478,6 +1780,70 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                                opts->netns_is_pid = true;
                        }
                        o_found |= DL_OPT_NETNS;
+               } else if (dl_argv_match(dl, "action") &&
+                          (o_all & DL_OPT_RELOAD_ACTION)) {
+                       const char *actionstr;
+
+                       dl_arg_inc(dl);
+                       err = dl_argv_str(dl, &actionstr);
+                       if (err)
+                               return err;
+                       err = reload_action_get(dl, actionstr, &opts->reload_action);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_RELOAD_ACTION;
+               } else if (dl_argv_match(dl, "limit") &&
+                          (o_all & DL_OPT_RELOAD_LIMIT)) {
+                       const char *limitstr;
+
+                       dl_arg_inc(dl);
+                       err = dl_argv_str(dl, &limitstr);
+                       if (err)
+                               return err;
+                       err = reload_limit_get(dl, limitstr, &opts->reload_limit);
+                       if (err)
+                               return err;
+                       o_found |= DL_OPT_RELOAD_LIMIT;
+               } 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 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;
@@ -1494,6 +1860,40 @@ 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_flash_update_overwrite_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+       struct nla_bitfield32 overwrite_mask;
+
+       overwrite_mask.selector = DEVLINK_SUPPORTED_FLASH_OVERWRITE_SECTIONS;
+       overwrite_mask.value = opts->overwrite_mask;
+
+       mnl_attr_put(nlh, DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK,
+                    sizeof(overwrite_mask), &overwrite_mask);
+}
+
+static void
+dl_reload_limits_put(struct nlmsghdr *nlh, const struct dl_opts *opts)
+{
+       struct nla_bitfield32 limits;
+
+       limits.selector = DEVLINK_RELOAD_LIMITS_VALID_MASK;
+       limits.value = BIT(opts->reload_limit);
+       mnl_attr_put(nlh, DEVLINK_ATTR_RELOAD_LIMITS, sizeof(limits), &limits);
+}
+
 static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
 {
        struct dl_opts *opts = &dl->opts;
@@ -1550,7 +1950,7 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
                                  opts->dpipe_table_name);
        if (opts->present & DL_OPT_DPIPE_TABLE_COUNTERS)
                mnl_attr_put_u8(nlh, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED,
-                               opts->dpipe_counters_enable);
+                               opts->dpipe_counters_enabled);
        if (opts->present & DL_OPT_ESWITCH_ENCAP_MODE)
                mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_ENCAP_MODE,
                                opts->eswitch_encap_mode);
@@ -1581,6 +1981,8 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
        if (opts->present & DL_OPT_FLASH_COMPONENT)
                mnl_attr_put_strz(nlh, DEVLINK_ATTR_FLASH_UPDATE_COMPONENT,
                                  opts->flash_component);
+       if (opts->present & DL_OPT_FLASH_OVERWRITE)
+               dl_flash_update_overwrite_put(nlh, opts);
        if (opts->present & DL_OPT_HEALTH_REPORTER_NAME)
                mnl_attr_put_strz(nlh, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
                                  opts->reporter_name);
@@ -1591,6 +1993,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);
@@ -1605,6 +2010,22 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
                                 opts->netns_is_pid ? DEVLINK_ATTR_NETNS_PID :
                                                      DEVLINK_ATTR_NETNS_FD,
                                 opts->netns);
+       if (opts->present & DL_OPT_RELOAD_ACTION)
+               mnl_attr_put_u8(nlh, DEVLINK_ATTR_RELOAD_ACTION,
+                               opts->reload_action);
+       if (opts->present & DL_OPT_RELOAD_LIMIT)
+               dl_reload_limits_put(nlh, opts);
+       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);
+       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,
@@ -1661,13 +2082,14 @@ static void cmd_dev_help(void)
        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");
        pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
+       pr_err("                              [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
        pr_err("       devlink dev info [ DEV ]\n");
-       pr_err("       devlink dev flash DEV file PATH [ component NAME ]\n");
+       pr_err("       devlink dev flash DEV file PATH [ component NAME ] [ overwrite SECTION ]\n");
 }
 
 static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name,
@@ -1714,19 +2136,17 @@ static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb,
        if (dl->json_output) {
                if (array) {
                        if (should_arr_last_handle_end(dl, bus_name, dev_name))
-                               jsonw_end_array(dl->jw);
+                               close_json_array(PRINT_JSON, NULL);
                        if (should_arr_last_handle_start(dl, bus_name,
                                                         dev_name)) {
-                               jsonw_name(dl->jw, buf);
-                               jsonw_start_array(dl->jw);
-                               jsonw_start_object(dl->jw);
+                               open_json_array(PRINT_JSON, buf);
+                               open_json_object(NULL);
                                arr_last_handle_set(dl, bus_name, dev_name);
                        } else {
-                               jsonw_start_object(dl->jw);
+                               open_json_object(NULL);
                        }
                } else {
-                       jsonw_name(dl->jw, buf);
-                       jsonw_start_object(dl->jw);
+                       open_json_object(buf);
                }
        } else {
                if (array) {
@@ -1753,7 +2173,7 @@ static void pr_out_handle_start_arr(struct dl *dl, struct nlattr **tb)
 static void pr_out_handle_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                __pr_out_newline();
 }
@@ -1815,24 +2235,34 @@ static void __pr_out_port_handle_start(struct dl *dl, const char *bus_name,
                        if (should_arr_last_port_handle_end(dl, bus_name,
                                                            dev_name,
                                                            port_index))
-                               jsonw_end_array(dl->jw);
+                               close_json_array(PRINT_JSON, NULL);
                        if (should_arr_last_port_handle_start(dl, bus_name,
                                                              dev_name,
                                                              port_index)) {
-                               jsonw_name(dl->jw, buf);
-                               jsonw_start_array(dl->jw);
-                               jsonw_start_object(dl->jw);
+                               open_json_array(PRINT_JSON, buf);
+                               open_json_object(NULL);
                                arr_last_port_handle_set(dl, bus_name, dev_name,
                                                         port_index);
                        } else {
-                               jsonw_start_object(dl->jw);
+                               open_json_object(NULL);
                        }
                } else {
-                       jsonw_name(dl->jw, buf);
-                       jsonw_start_object(dl->jw);
+                       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);
+               }
        }
 }
 
@@ -1863,131 +2293,23 @@ static void pr_out_port_handle_start_arr(struct dl *dl, struct nlattr **tb, bool
 static void pr_out_port_handle_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                pr_out("\n");
 }
 
-
-static void pr_out_str(struct dl *dl, const char *name, const char *val)
+static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr)
 {
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_string_field(dl->jw, name, val);
-       else
-               pr_out("%s %s", name, val);
+       if (dl->json_output) {
+               print_uint(PRINT_JSON, "address", NULL, addr);
+               open_json_array(PRINT_JSON, "data");
+       }
 }
 
-static void pr_out_bool(struct dl *dl, const char *name, bool val)
+static void pr_out_region_chunk_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_bool_field(dl->jw, name, val);
-       else
-               pr_out_str(dl, name, val ? "true" : "false");
-}
-
-static void pr_out_uint(struct dl *dl, const char *name, unsigned int val)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_uint_field(dl->jw, name, val);
-       else
-               pr_out("%s %u", name, val);
-}
-
-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 pr_out_str(dl, name, "unlimited");
-
-       if (dl->json_output)
-               jsonw_u64_field(dl->jw, name, val);
-       else
-               pr_out("%s %"PRIu64, name, val);
-}
-
-static void pr_out_bool_value(struct dl *dl, bool value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_bool(dl->jw, value);
-       else
-               pr_out("%s", value ? "true" : "false");
-}
-
-static void pr_out_uint_value(struct dl *dl, unsigned int value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_uint(dl->jw, value);
-       else
-               pr_out("%u", value);
-}
-
-static void pr_out_uint64_value(struct dl *dl, uint64_t value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_u64(dl->jw, value);
-       else
-               pr_out("%"PRIu64, value);
-}
-
-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)
-                       jsonw_printf(dl->jw, "%d", 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_str_value(struct dl *dl, const char *value)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_string(dl->jw, value);
-       else
-               pr_out("%s", value);
-}
-
-static void pr_out_name(struct dl *dl, const char *name)
-{
-       __pr_out_indent_newline(dl);
-       if (dl->json_output)
-               jsonw_name(dl->jw, name);
-       else
-               pr_out("%s:", name);
-}
-
-static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr)
-{
-       if (dl->json_output) {
-               jsonw_name(dl->jw, "address");
-               jsonw_uint(dl->jw, addr);
-               jsonw_name(dl->jw, "data");
-               jsonw_start_array(dl->jw);
-       }
-}
-
-static void pr_out_region_chunk_end(struct dl *dl)
-{
-       if (dl->json_output)
-               jsonw_end_array(dl->jw);
+               close_json_array(PRINT_JSON, NULL);
 }
 
 static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
@@ -2007,7 +2329,7 @@ static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
                align_val++;
 
                if (dl->json_output)
-                       jsonw_printf(dl->jw, "%d", data[i]);
+                       print_int(PRINT_JSON, NULL, NULL, data[i]);
                else
                        pr_out("%02x ", data[i]);
 
@@ -2017,87 +2339,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) {
-               jsonw_start_object(dl->jw);
-               jsonw_name(dl->jw, name);
-               jsonw_start_object(dl->jw);
-       }
-}
-
-static void pr_out_section_end(struct dl *dl)
-{
-       if (dl->json_output) {
-               if (dl->arr_last.present)
-                       jsonw_end_array(dl->jw);
-               jsonw_end_object(dl->jw);
-               jsonw_end_object(dl->jw);
-       }
-}
-
-static void pr_out_array_start(struct dl *dl, const char *name)
-{
-       if (dl->json_output) {
-               jsonw_name(dl->jw, name);
-               jsonw_start_array(dl->jw);
-       } 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) {
-               jsonw_end_array(dl->jw);
-       } 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) {
-               jsonw_name(dl->jw, name);
-               jsonw_start_object(dl->jw);
-       } 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) {
-               jsonw_end_object(dl->jw);
-       } else {
-               __pr_out_indent_dec();
-               __pr_out_indent_dec();
-       }
-}
-
-static void pr_out_entry_start(struct dl *dl)
-{
-       if (dl->json_output)
-               jsonw_start_object(dl->jw);
-}
-
-static void pr_out_entry_end(struct dl *dl)
-{
-       if (dl->json_output)
-               jsonw_end_object(dl->jw);
-       else
-               __pr_out_newline();
-}
-
 static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats)
 {
        struct nlattr *tb[DEVLINK_ATTR_STATS_MAX + 1] = {};
@@ -2118,6 +2359,9 @@ static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats)
        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);
 }
@@ -2135,6 +2379,30 @@ static const char *param_cmode_name(uint8_t cmode)
        }
 }
 
+static const char *reload_action_name(uint8_t reload_action)
+{
+       switch (reload_action) {
+       case DEVLINK_RELOAD_ACTION_DRIVER_REINIT:
+               return "driver_reinit";
+       case DEVLINK_RELOAD_ACTION_FW_ACTIVATE:
+               return "fw_activate";
+       default:
+               return "<unknown reload action>";
+       }
+}
+
+static const char *reload_limit_name(uint8_t reload_limit)
+{
+       switch (reload_limit) {
+       case DEVLINK_RELOAD_LIMIT_UNSPEC:
+               return "unspecified";
+       case DEVLINK_RELOAD_LIMIT_NO_RESET:
+               return "no_reset";
+       default:
+               return "<unknown reload action>";
+       }
+}
+
 static const char *eswitch_mode_name(uint32_t mode)
 {
        switch (mode) {
@@ -2160,23 +2428,39 @@ static const char *eswitch_inline_mode_name(uint32_t mode)
        }
 }
 
+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);
 
-       if (tb[DEVLINK_ATTR_ESWITCH_MODE])
-               pr_out_str(dl, "mode",
-                          eswitch_mode_name(mnl_attr_get_u16(tb[DEVLINK_ATTR_ESWITCH_MODE])));
-
-       if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])
-               pr_out_str(dl, "inline-mode",
-                          eswitch_inline_mode_name(mnl_attr_get_u8(
-                                  tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
-
+       if (tb[DEVLINK_ATTR_ESWITCH_MODE]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "mode", "mode %s",
+                            eswitch_mode_name(mnl_attr_get_u16(
+                                    tb[DEVLINK_ATTR_ESWITCH_MODE])));
+       }
+       if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "inline-mode", "inline-mode %s",
+                            eswitch_inline_mode_name(mnl_attr_get_u8(
+                                    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]);
-
-               pr_out_str(dl, "encap", encap_mode ? "enable" : "disable");
+               check_indent_newline(dl);
+               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);
@@ -2316,6 +2600,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",
@@ -2363,8 +2652,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
             !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
                return;
 
-       pr_out_str(dl, "cmode",
-                  param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "cmode", "cmode %s",
+                    param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
+
        val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
 
        conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
@@ -2380,9 +2671,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
-                       pr_out_uint(dl, "value", mnl_attr_get_u8(val_attr));
+                       print_uint(PRINT_ANY, "value", " value %u",
+                                  mnl_attr_get_u8(val_attr));
                }
                break;
        case MNL_TYPE_U16:
@@ -2394,9 +2686,10 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
-                       pr_out_uint(dl, "value", mnl_attr_get_u16(val_attr));
+                       print_uint(PRINT_ANY, "value", " value %u",
+                                  mnl_attr_get_u16(val_attr));
                }
                break;
        case MNL_TYPE_U32:
@@ -2408,16 +2701,18 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
                                                     &vstr);
                        if (err)
                                return;
-                       pr_out_str(dl, "value", vstr);
+                       print_string(PRINT_ANY, "value", " value %s", vstr);
                } else {
-                       pr_out_uint(dl, "value", mnl_attr_get_u32(val_attr));
+                       print_uint(PRINT_ANY, "value", " value %u",
+                                  mnl_attr_get_u32(val_attr));
                }
                break;
        case MNL_TYPE_STRING:
-               pr_out_str(dl, "value", mnl_attr_get_str(val_attr));
+               print_string(PRINT_ANY, "value", " value %s",
+                            mnl_attr_get_str(val_attr));
                break;
        case MNL_TYPE_FLAG:
-               pr_out_bool(dl, "value", val_attr ? true : false);
+               print_bool(PRINT_ANY, "value", " value %s", val_attr);
                break;
        }
 }
@@ -2446,12 +2741,12 @@ static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
        nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
 
        nla_name = mnl_attr_get_str(nla_param[DEVLINK_ATTR_PARAM_NAME]);
-       pr_out_str(dl, "name", nla_name);
-
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s ", nla_name);
        if (!nla_param[DEVLINK_ATTR_PARAM_GENERIC])
-               pr_out_str(dl, "type", "driver-specific");
+               print_string(PRINT_ANY, "type", "type %s", "driver-specific");
        else
-               pr_out_str(dl, "type", "generic");
+               print_string(PRINT_ANY, "type", "type %s", "generic");
 
        pr_out_array_start(dl, "values");
        mnl_attr_for_each_nested(param_value_attr,
@@ -2563,7 +2858,7 @@ static int cmd_dev_param_set(struct dl *dl)
        struct param_ctx ctx = {};
        struct nlmsghdr *nlh;
        bool conv_exists;
-       uint32_t val_u32;
+       uint32_t val_u32 = 0;
        uint16_t val_u16;
        uint8_t val_u8;
        bool val_bool;
@@ -2712,28 +3007,119 @@ static int cmd_dev_param(struct dl *dl)
        pr_err("Command \"%s\" not found\n", dl_argv(dl));
        return -ENOENT;
 }
-static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
+
+static void pr_out_action_stats(struct dl *dl, struct nlattr *action_stats)
 {
-       struct dl *dl = data;
+       struct nlattr *tb_stats_entry[DEVLINK_ATTR_MAX + 1] = {};
+       struct nlattr *nla_reload_stats_entry, *nla_limit, *nla_value;
+       enum devlink_reload_limit limit;
+       uint32_t value;
+       int err;
+
+       mnl_attr_for_each_nested(nla_reload_stats_entry, action_stats) {
+               err = mnl_attr_parse_nested(nla_reload_stats_entry, attr_cb,
+                                           tb_stats_entry);
+               if (err != MNL_CB_OK)
+                       return;
+
+               nla_limit = tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_LIMIT];
+               nla_value = tb_stats_entry[DEVLINK_ATTR_RELOAD_STATS_VALUE];
+               if (!nla_limit || !nla_value)
+                       return;
+
+               check_indent_newline(dl);
+               limit = mnl_attr_get_u8(nla_limit);
+               value = mnl_attr_get_u32(nla_value);
+               print_uint_name_value(reload_limit_name(limit), value);
+       }
+}
+
+static void pr_out_reload_stats(struct dl *dl, struct nlattr *reload_stats)
+{
+       struct nlattr *nla_action_info, *nla_action, *nla_action_stats;
        struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
-       uint8_t reload_failed = 0;
+       enum devlink_reload_action action;
+       int err;
 
-       mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-       if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-               return MNL_CB_ERROR;
+       mnl_attr_for_each_nested(nla_action_info, reload_stats) {
+               err = mnl_attr_parse_nested(nla_action_info, attr_cb, tb);
+               if (err != MNL_CB_OK)
+                       return;
+               nla_action = tb[DEVLINK_ATTR_RELOAD_ACTION];
+               nla_action_stats = tb[DEVLINK_ATTR_RELOAD_ACTION_STATS];
+               if (!nla_action || !nla_action_stats)
+                       return;
+
+               action = mnl_attr_get_u8(nla_action);
+               pr_out_object_start(dl, reload_action_name(action));
+               pr_out_action_stats(dl, nla_action_stats);
+               pr_out_object_end(dl);
+       }
+}
+
+static void pr_out_reload_data(struct dl *dl, struct nlattr **tb)
+{
+       struct nlattr *nla_reload_stats, *nla_remote_reload_stats;
+       struct nlattr *tb_stats[DEVLINK_ATTR_MAX + 1] = {};
+       uint8_t reload_failed = 0;
+       int err;
 
        if (tb[DEVLINK_ATTR_RELOAD_FAILED])
                reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
 
        if (reload_failed) {
+               check_indent_newline(dl);
+               print_bool(PRINT_ANY, "reload_failed", "reload_failed %s", true);
+       }
+       if (!tb[DEVLINK_ATTR_DEV_STATS] || !dl->stats)
+               return;
+       err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_DEV_STATS], attr_cb,
+                                   tb_stats);
+       if (err != MNL_CB_OK)
+               return;
+
+       pr_out_object_start(dl, "stats");
+
+       nla_reload_stats = tb_stats[DEVLINK_ATTR_RELOAD_STATS];
+       if (nla_reload_stats) {
+               pr_out_object_start(dl, "reload");
+               pr_out_reload_stats(dl, nla_reload_stats);
+               pr_out_object_end(dl);
+       }
+       nla_remote_reload_stats = tb_stats[DEVLINK_ATTR_REMOTE_RELOAD_STATS];
+       if (nla_remote_reload_stats) {
+               pr_out_object_start(dl, "remote_reload");
+               pr_out_reload_stats(dl, nla_remote_reload_stats);
+               pr_out_object_end(dl);
+       }
+
+       pr_out_object_end(dl);
+}
+
+
+static void pr_out_dev(struct dl *dl, struct nlattr **tb)
+{
+       if ((tb[DEVLINK_ATTR_RELOAD_FAILED] && mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED])) ||
+           (tb[DEVLINK_ATTR_DEV_STATS] && dl->stats)) {
                __pr_out_handle_start(dl, tb, true, false);
-               pr_out_bool(dl, "reload_failed", true);
+               pr_out_reload_data(dl, tb);
                pr_out_handle_end(dl);
        } else {
                pr_out_handle(dl, tb);
        }
+}
+
+static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
+{
+       struct dl *dl = data;
+       struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+
+       mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+       if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
+               return MNL_CB_ERROR;
 
+       pr_out_dev(dl, tb);
        return MNL_CB_OK;
 }
 
@@ -2760,9 +3146,55 @@ static int cmd_dev_show(struct dl *dl)
        return err;
 }
 
-static void cmd_dev_reload_help(void)
+static void pr_out_reload_actions_performed(struct dl *dl, struct nlattr **tb)
+{
+       struct nlattr *nla_actions_performed;
+       struct nla_bitfield32 *actions;
+       uint32_t actions_performed;
+       uint16_t len;
+       int action;
+
+       if (!tb[DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED])
+               return;
+
+       nla_actions_performed = tb[DEVLINK_ATTR_RELOAD_ACTIONS_PERFORMED];
+       len = mnl_attr_get_payload_len(nla_actions_performed);
+       if (len != sizeof(*actions))
+               return;
+       actions = mnl_attr_get_payload(nla_actions_performed);
+       if (!actions)
+               return;
+       g_new_line_count = 1; /* Avoid extra new line in non-json print */
+       pr_out_array_start(dl, "reload_actions_performed");
+       actions_performed = actions->value & actions->selector;
+       for (action = 0; action <= DEVLINK_RELOAD_ACTION_MAX; action++) {
+               if (BIT(action) & actions_performed) {
+                       check_indent_newline(dl);
+                       print_string(PRINT_ANY, NULL, "%s",
+                                    reload_action_name(action));
+               }
+       }
+       pr_out_array_end(dl);
+       if (!dl->json_output)
+               __pr_out_newline();
+}
+
+static int cmd_dev_reload_cb(const struct nlmsghdr *nlh, void *data)
 {
-       pr_err("Usage: devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
+       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_RELOAD_ACTIONS_PERFORMED])
+               return MNL_CB_ERROR;
+
+       pr_out_section_start(dl, "reload");
+       pr_out_reload_actions_performed(dl, tb);
+       pr_out_section_end(dl);
+
+       return MNL_CB_OK;
 }
 
 static int cmd_dev_reload(struct dl *dl)
@@ -2771,18 +3203,20 @@ static int cmd_dev_reload(struct dl *dl)
        int err;
 
        if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-               cmd_dev_reload_help();
+               cmd_dev_help();
                return 0;
        }
 
        nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
                               NLM_F_REQUEST | NLM_F_ACK);
 
-       err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_NETNS);
+       err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
+                               DL_OPT_NETNS | DL_OPT_RELOAD_ACTION |
+                               DL_OPT_RELOAD_LIMIT);
        if (err)
                return err;
 
-       return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+       return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_reload_cb, dl);
 }
 
 static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
@@ -2815,7 +3249,8 @@ static void pr_out_versions_single(struct dl *dl, const struct nlmsghdr *nlh,
                ver_name = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_NAME]);
                ver_value = mnl_attr_get_str(tb[DEVLINK_ATTR_INFO_VERSION_VALUE]);
 
-               pr_out_str(dl, ver_name, ver_value);
+               check_indent_newline(dl);
+               print_string_name_value(ver_name, ver_value);
                if (!dl->json_output)
                        __pr_out_newline();
        }
@@ -2835,7 +3270,9 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
 
                if (!dl->json_output)
                        __pr_out_newline();
-               pr_out_str(dl, "driver", mnl_attr_get_str(nla_drv));
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "driver", "driver %s",
+                            mnl_attr_get_str(nla_drv));
        }
 
        if (tb[DEVLINK_ATTR_INFO_SERIAL_NUMBER]) {
@@ -2843,7 +3280,19 @@ static void pr_out_info(struct dl *dl, const struct nlmsghdr *nlh,
 
                if (!dl->json_output)
                        __pr_out_newline();
-               pr_out_str(dl, "serial_number", mnl_attr_get_str(nla_sn));
+               check_indent_newline(dl);
+               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();
 
@@ -2880,6 +3329,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)
@@ -2888,11 +3338,6 @@ static int cmd_versions_show_cb(const struct nlmsghdr *nlh, void *data)
        return MNL_CB_OK;
 }
 
-static void cmd_dev_info_help(void)
-{
-       pr_err("Usage: devlink dev info [ DEV ]\n");
-}
-
 static int cmd_dev_info(struct dl *dl)
 {
        struct nlmsghdr *nlh;
@@ -2900,7 +3345,7 @@ static int cmd_dev_info(struct dl *dl)
        int err;
 
        if (dl_argv_match(dl, "help")) {
-               cmd_dev_info_help();
+               cmd_dev_help();
                return 0;
        }
 
@@ -2921,14 +3366,11 @@ static int cmd_dev_info(struct dl *dl)
        return err;
 }
 
-static void cmd_dev_flash_help(void)
-{
-       pr_err("Usage: devlink dev flash DEV file PATH [ component NAME ]\n");
-}
-
-
 struct cmd_dev_flash_status_ctx {
        struct dl *dl;
+       struct timespec time_of_last_status;
+       uint64_t status_msg_timeout;
+       size_t elapsed_time_msg_len;
        char *last_msg;
        char *last_component;
        uint8_t not_first:1,
@@ -2946,6 +3388,16 @@ static int nullstrcmp(const char *str1, const char *str2)
        return str1 ? 1 : -1;
 }
 
+static void cmd_dev_flash_clear_elapsed_time(struct cmd_dev_flash_status_ctx *ctx)
+{
+       int i;
+
+       for (i = 0; i < ctx->elapsed_time_msg_len; i++)
+               pr_out_tty("\b \b");
+
+       ctx->elapsed_time_msg_len = 0;
+}
+
 static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data)
 {
        struct cmd_dev_flash_status_ctx *ctx = data;
@@ -2958,6 +3410,8 @@ static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data)
        const char *bus_name;
        const char *dev_name;
 
+       cmd_dev_flash_clear_elapsed_time(ctx);
+
        if (genl->cmd != DEVLINK_CMD_FLASH_UPDATE_STATUS &&
            genl->cmd != DEVLINK_CMD_FLASH_UPDATE_END)
                return MNL_CB_STOP;
@@ -2987,12 +3441,19 @@ static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data)
                done = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE]);
        if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL])
                total = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL]);
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TIMEOUT])
+               ctx->status_msg_timeout = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TIMEOUT]);
+       else
+               ctx->status_msg_timeout = 0;
 
        if (!nullstrcmp(msg, ctx->last_msg) &&
            !nullstrcmp(component, ctx->last_component) &&
            ctx->last_pc && ctx->not_first) {
                pr_out_tty("\b\b\b\b\b"); /* clean percentage */
        } else {
+               /* only update the last status timestamp if the message changed */
+               clock_gettime(CLOCK_MONOTONIC, &ctx->time_of_last_status);
+
                if (ctx->not_first)
                        pr_out("\n");
                if (component) {
@@ -3018,11 +3479,78 @@ static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data)
        return MNL_CB_STOP;
 }
 
+static void cmd_dev_flash_time_elapsed(struct cmd_dev_flash_status_ctx *ctx)
+{
+       struct timespec now, res;
+
+       clock_gettime(CLOCK_MONOTONIC, &now);
+
+       res.tv_sec = now.tv_sec - ctx->time_of_last_status.tv_sec;
+       res.tv_nsec = now.tv_nsec - ctx->time_of_last_status.tv_nsec;
+       if (res.tv_nsec < 0) {
+               res.tv_sec--;
+               res.tv_nsec += 1000000000L;
+       }
+
+       /* Only begin displaying an elapsed time message if we've waited a few
+        * seconds with no response, or the status message included a timeout
+        * value.
+        */
+       if (res.tv_sec > 2 || ctx->status_msg_timeout) {
+               uint64_t elapsed_m, elapsed_s;
+               char msg[128];
+               size_t len;
+
+               /* clear the last elapsed time message, if we have one */
+               cmd_dev_flash_clear_elapsed_time(ctx);
+
+               elapsed_m = res.tv_sec / 60;
+               elapsed_s = res.tv_sec % 60;
+
+               /**
+                * If we've elapsed a few seconds without receiving any status
+                * notification from the device, we display a time elapsed
+                * message. This has a few possible formats:
+                *
+                * 1) just time elapsed, when no timeout was provided
+                *    " ( Xm Ys )"
+                * 2) time elapsed out of a timeout that came from the device
+                *    driver via DEVLINK_CMD_FLASH_UPDATE_STATUS_TIMEOUT
+                *    " ( Xm Ys : Am Ys)"
+                * 3) time elapsed if we still receive no status after
+                *    reaching the provided timeout.
+                *    " ( Xm Ys : timeout reached )"
+                */
+               if (!ctx->status_msg_timeout) {
+                       len = snprintf(msg, sizeof(msg),
+                                      " ( %lum %lus )", elapsed_m, elapsed_s);
+               } else if (res.tv_sec <= ctx->status_msg_timeout) {
+                       uint64_t timeout_m, timeout_s;
+
+                       timeout_m = ctx->status_msg_timeout / 60;
+                       timeout_s = ctx->status_msg_timeout % 60;
+
+                       len = snprintf(msg, sizeof(msg),
+                                      " ( %lum %lus : %lum %lus )",
+                                      elapsed_m, elapsed_s, timeout_m, timeout_s);
+               } else {
+                       len = snprintf(msg, sizeof(msg),
+                                      " ( %lum %lus : timeout reached )", elapsed_m, elapsed_s);
+               }
+
+               ctx->elapsed_time_msg_len = len;
+
+               pr_out_tty("%s", msg);
+               fflush(stdout);
+       }
+}
+
 static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
                                     struct mnlg_socket *nlg_ntf,
                                     int pipe_r)
 {
        int nlfd = mnlg_socket_get_fd(nlg_ntf);
+       struct timeval timeout;
        fd_set fds[3];
        int fdmax;
        int i;
@@ -3037,7 +3565,14 @@ static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
        if (nlfd >= fdmax)
                fdmax = nlfd + 1;
 
-       while (select(fdmax, &fds[0], &fds[1], &fds[2], NULL) < 0) {
+       /* select only for a short while (1/10th of a second) in order to
+        * allow periodically updating the screen with an elapsed time
+        * indicator.
+        */
+       timeout.tv_sec = 0;
+       timeout.tv_usec = 100000;
+
+       while (select(fdmax, &fds[0], &fds[1], &fds[2], &timeout) < 0) {
                if (errno == EINTR)
                        continue;
                pr_err("select() failed\n");
@@ -3059,6 +3594,7 @@ static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
                        return err2;
                ctx->flash_done = 1;
        }
+       cmd_dev_flash_time_elapsed(ctx);
        return 0;
 }
 
@@ -3074,7 +3610,7 @@ static int cmd_dev_flash(struct dl *dl)
        int err;
 
        if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-               cmd_dev_flash_help();
+               cmd_dev_help();
                return 0;
        }
 
@@ -3082,7 +3618,7 @@ static int cmd_dev_flash(struct dl *dl)
                               NLM_F_REQUEST | NLM_F_ACK);
 
        err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_FLASH_FILE_NAME,
-                               DL_OPT_FLASH_COMPONENT);
+                               DL_OPT_FLASH_COMPONENT | DL_OPT_FLASH_OVERWRITE);
        if (err)
                return err;
 
@@ -3092,31 +3628,40 @@ static int cmd_dev_flash(struct dl *dl)
 
        err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
        if (err)
-               return err;
+               goto err_socket;
 
        err = pipe(pipe_fds);
-       if (err == -1)
-               return -errno;
+       if (err == -1) {
+               err = -errno;
+               goto err_socket;
+       }
        pipe_r = pipe_fds[0];
        pipe_w = pipe_fds[1];
 
        pid = fork();
        if (pid == -1) {
-               close(pipe_r);
                close(pipe_w);
-               return -errno;
+               err = -errno;
+               goto out;
        } else if (!pid) {
                /* 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);
 
+       /* initialize starting time to allow comparison for when to begin
+        * displaying a time elapsed message.
+        */
+       clock_gettime(CLOCK_MONOTONIC, &ctx.time_of_last_status);
+
        do {
                err = cmd_dev_flash_fds_process(&ctx, nlg_ntf, pipe_r);
                if (err)
@@ -3126,6 +3671,7 @@ static int cmd_dev_flash(struct dl *dl)
        err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
 out:
        close(pipe_r);
+err_socket:
        mnlg_socket_close(nlg_ntf);
        return err;
 }
@@ -3165,6 +3711,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)
@@ -3180,70 +3728,110 @@ static const char *port_type_name(uint32_t type)
 
 static const char *port_flavour_name(uint16_t flavour)
 {
-       switch (flavour) {
-       case DEVLINK_PORT_FLAVOUR_PHYSICAL:
-               return "physical";
-       case DEVLINK_PORT_FLAVOUR_CPU:
-               return "cpu";
-       case DEVLINK_PORT_FLAVOUR_DSA:
-               return "dsa";
-       case DEVLINK_PORT_FLAVOUR_PCI_PF:
-               return "pcipf";
-       case DEVLINK_PORT_FLAVOUR_PCI_VF:
-               return "pcivf";
-       default:
-               return "<unknown flavour>";
-       }
+       const char *str;
+
+       str = str_map_lookup_u16(port_flavour_map, flavour);
+       return str ? str : "<unknown flavour>";
 }
 
-static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb)
+static void pr_out_port_pfvfsf_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]);
-               pr_out_uint(dl, "pfnum", fn_num);
+               print_uint(PRINT_ANY, "pfnum", " pfnum %u", fn_num);
        }
        if (tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]) {
                fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
-               pr_out_uint(dl, "vfnum", fn_num);
+               print_uint(PRINT_ANY, "vfnum", " vfnum %u", fn_num);
+       }
+       if (tb[DEVLINK_ATTR_PORT_PCI_SF_NUMBER]) {
+               fn_num = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_PCI_SF_NUMBER]);
+               print_uint(PRINT_ANY, "sfnum", " sfnum %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)
 {
        struct nlattr *pt_attr = tb[DEVLINK_ATTR_PORT_TYPE];
        struct nlattr *dpt_attr = tb[DEVLINK_ATTR_PORT_DESIRED_TYPE];
 
        pr_out_port_handle_start(dl, tb, false);
+       check_indent_newline(dl);
        if (pt_attr) {
                uint16_t port_type = mnl_attr_get_u16(pt_attr);
 
-               pr_out_str(dl, "type", port_type_name(port_type));
+               print_string(PRINT_ANY, "type", "type %s",
+                            port_type_name(port_type));
                if (dpt_attr) {
                        uint16_t des_port_type = mnl_attr_get_u16(dpt_attr);
 
                        if (port_type != des_port_type)
-                               pr_out_str(dl, "des_type",
-                                          port_type_name(des_port_type));
+                               print_string(PRINT_ANY, "des_type", " des_type %s",
+                                            port_type_name(des_port_type));
                }
        }
-       if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
-               pr_out_str(dl, "netdev",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
-       if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME])
-               pr_out_str(dl, "ibdev",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
+       if (tb[DEVLINK_ATTR_PORT_NETDEV_NAME]) {
+               print_string(PRINT_ANY, "netdev", " netdev %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]));
+       }
+       if (tb[DEVLINK_ATTR_PORT_IBDEV_NAME]) {
+               print_string(PRINT_ANY, "ibdev", " ibdev %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_IBDEV_NAME]));
+               }
        if (tb[DEVLINK_ATTR_PORT_FLAVOUR]) {
                uint16_t port_flavour =
                                mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
 
-               pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
+               print_string(PRINT_ANY, "flavour", " flavour %s",
+                            port_flavour_name(port_flavour));
 
                switch (port_flavour) {
                case DEVLINK_PORT_FLAVOUR_PCI_PF:
                case DEVLINK_PORT_FLAVOUR_PCI_VF:
-                       pr_out_port_pfvf_num(dl, tb);
+               case DEVLINK_PORT_FLAVOUR_PCI_SF:
+                       pr_out_port_pfvfsf_num(dl, tb);
                        break;
                default:
                        break;
@@ -3253,11 +3841,19 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
                uint32_t port_number;
 
                port_number = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_NUMBER]);
-               pr_out_uint(dl, "port", port_number);
+               print_uint(PRINT_ANY, "port", " port %u", port_number);
        }
        if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
-               pr_out_uint(dl, "split_group",
-                           mnl_attr_get_u32(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);
 }
 
@@ -3343,6 +3939,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")) {
@@ -3361,6 +3992,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;
@@ -3389,18 +4032,19 @@ static void cmd_sb_help(void)
 static void pr_out_sb(struct dl *dl, struct nlattr **tb)
 {
        pr_out_handle_start_arr(dl, tb);
-       pr_out_uint(dl, "sb",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "size",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_SIZE]));
-       pr_out_uint(dl, "ing_pools",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT]));
-       pr_out_uint(dl, "eg_pools",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT]));
-       pr_out_uint(dl, "ing_tcs",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_TC_COUNT]));
-       pr_out_uint(dl, "eg_tcs",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_TC_COUNT]));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "size", " size %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_SIZE]));
+       print_uint(PRINT_ANY, "ing_pools", " ing_pools %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT]));
+       print_uint(PRINT_ANY, "eg_pools", " eg_pools %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT]));
+       print_uint(PRINT_ANY, "ing_tcs", " ing_tcs %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_INGRESS_TC_COUNT]));
+       print_uint(PRINT_ANY, "eg_tcs", " eg_tcs %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_EGRESS_TC_COUNT]));
        pr_out_handle_end(dl);
 }
 
@@ -3466,19 +4110,20 @@ static const char *threshold_type_name(uint8_t type)
 static void pr_out_sb_pool(struct dl *dl, struct nlattr **tb)
 {
        pr_out_handle_start_arr(dl, tb);
-       pr_out_uint(dl, "sb",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "pool",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_str(dl, "type",
-                  pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
-       pr_out_uint(dl, "size",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_SIZE]));
-       pr_out_str(dl, "thtype",
-                  threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "pool", " pool %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
+       print_string(PRINT_ANY, "type", " type %s",
+                    pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
+       print_uint(PRINT_ANY, "size", " size %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_SIZE]));
+       print_string(PRINT_ANY, "thtype", " thtype %s",
+                    threshold_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE])));
        if (tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE])
-               pr_out_uint(dl, "cell_size",
-                           mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE]));
+               print_uint(PRINT_ANY, "cell_size", " cell size %u",
+                          mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_POOL_CELL_SIZE]));
        pr_out_handle_end(dl);
 }
 
@@ -3558,12 +4203,13 @@ static int cmd_sb_pool(struct dl *dl)
 static void pr_out_sb_port_pool(struct dl *dl, struct nlattr **tb)
 {
        pr_out_port_handle_start_arr(dl, tb, true);
-       pr_out_uint(dl, "sb",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "pool",
-                   mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_uint(dl, "threshold",
-                   mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "pool", " pool %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
+       print_uint(PRINT_ANY, "threshold", " threshold %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
        pr_out_port_handle_end(dl);
 }
 
@@ -3656,16 +4302,17 @@ static int cmd_sb_port(struct dl *dl)
 static void pr_out_sb_tc_bind(struct dl *dl, struct nlattr **tb)
 {
        pr_out_port_handle_start_arr(dl, tb, true);
-       pr_out_uint(dl, "sb",
-              mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
-       pr_out_uint(dl, "tc",
-              mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]));
-       pr_out_str(dl, "type",
-              pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
-       pr_out_uint(dl, "pool",
-              mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
-       pr_out_uint(dl, "threshold",
-              mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
+       check_indent_newline(dl);
+       print_uint(PRINT_ANY, "sb", "sb %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_INDEX]));
+       print_uint(PRINT_ANY, "tc", " tc %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_TC_INDEX]));
+       print_string(PRINT_ANY, "type", " type %s",
+                    pool_type_name(mnl_attr_get_u8(tb[DEVLINK_ATTR_SB_POOL_TYPE])));
+       print_uint(PRINT_ANY, "pool", " pool %u",
+                  mnl_attr_get_u16(tb[DEVLINK_ATTR_SB_POOL_INDEX]));
+       print_uint(PRINT_ANY, "threshold", " threshold %u",
+                  mnl_attr_get_u32(tb[DEVLINK_ATTR_SB_THRESHOLD]));
        pr_out_port_handle_end(dl);
 }
 
@@ -3886,20 +4533,18 @@ static void pr_out_json_occ_show_item_list(struct dl *dl, const char *label,
        struct occ_item *occ_item;
        char buf[32];
 
-       jsonw_name(dl->jw, label);
-       jsonw_start_object(dl->jw);
+       open_json_object(label);
        list_for_each_entry(occ_item, list, list) {
                sprintf(buf, "%u", occ_item->index);
-               jsonw_name(dl->jw, buf);
-               jsonw_start_object(dl->jw);
+               open_json_object(buf);
                if (bound_pool)
-                       jsonw_uint_field(dl->jw, "bound_pool",
-                                        occ_item->bound_pool_index);
-               jsonw_uint_field(dl->jw, "current", occ_item->cur);
-               jsonw_uint_field(dl->jw, "max", occ_item->max);
-               jsonw_end_object(dl->jw);
+                       print_uint(PRINT_JSON, "bound_pool", NULL,
+                                  occ_item->bound_pool_index);
+               print_uint(PRINT_JSON, "current", NULL, occ_item->cur);
+               print_uint(PRINT_JSON, "max", NULL, occ_item->max);
+               close_json_object();
        }
-       jsonw_end_object(dl->jw);
+       close_json_object();
 }
 
 static void pr_out_occ_show_port(struct dl *dl, struct occ_port *occ_port)
@@ -4164,6 +4809,7 @@ static const char *cmd_name(uint8_t cmd)
        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";
@@ -4172,6 +4818,10 @@ static const char *cmd_name(uint8_t cmd)
        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>";
        }
 }
@@ -4204,6 +4854,8 @@ static const char *cmd_obj(uint8_t 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:
@@ -4214,13 +4866,32 @@ static const char *cmd_obj(uint8_t cmd)
        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_mon_header(uint8_t cmd)
 {
-       pr_out("[%s,%s] ", cmd_obj(cmd), cmd_name(cmd));
+       if (!is_json_context()) {
+               pr_out("[%s,%s] ", cmd_obj(cmd), cmd_name(cmd));
+       } else {
+               open_json_object(NULL);
+               print_string(PRINT_JSON, "command", NULL, cmd_name(cmd));
+               open_json_object(cmd_obj(cmd));
+       }
+}
+
+static void pr_out_mon_footer(void)
+{
+       if (is_json_context()) {
+               close_json_object();
+               close_json_object();
+       }
 }
 
 static bool cmd_filter_check(struct dl *dl, uint8_t cmd)
@@ -4242,13 +4913,16 @@ static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
 {
        __pr_out_handle_start(dl, tb, true, false);
 
-       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
-               pr_out_str(dl, "msg",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
-
-       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
-               pr_out_str(dl, "component",
-                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "msg", "msg %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
+       }
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "component", "component %s",
+                            mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+       }
 
        if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
                pr_out_u64(dl, "done",
@@ -4262,8 +4936,11 @@ 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,
+                         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);
 
 static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
 {
@@ -4284,7 +4961,9 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
-               pr_out_handle(dl, tb);
+               dl->stats = true;
+               pr_out_dev(dl, tb);
+               pr_out_mon_footer();
                break;
        case DEVLINK_CMD_PORT_GET: /* fall through */
        case DEVLINK_CMD_PORT_SET: /* fall through */
@@ -4296,6 +4975,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
                pr_out_port(dl, tb);
+               pr_out_mon_footer();
                break;
        case DEVLINK_CMD_PARAM_GET: /* fall through */
        case DEVLINK_CMD_PARAM_SET: /* fall through */
@@ -4307,6 +4987,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
                pr_out_param(dl, tb, false);
+               pr_out_mon_footer();
                break;
        case DEVLINK_CMD_REGION_GET: /* fall through */
        case DEVLINK_CMD_REGION_SET: /* fall through */
@@ -4318,6 +4999,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
                pr_out_region(dl, tb);
+               pr_out_mon_footer();
                break;
        case DEVLINK_CMD_FLASH_UPDATE: /* fall through */
        case DEVLINK_CMD_FLASH_UPDATE_END: /* fall through */
@@ -4327,6 +5009,16 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
                pr_out_flash_update(dl, tb);
+               pr_out_mon_footer();
+               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, true, true);
+               pr_out_mon_footer();
                break;
        case DEVLINK_CMD_TRAP_GET: /* fall through */
        case DEVLINK_CMD_TRAP_SET: /* fall through */
@@ -4343,6 +5035,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
                pr_out_trap(dl, tb, false);
+               pr_out_mon_footer();
                break;
        case DEVLINK_CMD_TRAP_GROUP_GET: /* fall through */
        case DEVLINK_CMD_TRAP_GROUP_SET: /* fall through */
@@ -4355,8 +5048,23 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
                pr_out_trap_group(dl, tb, false);
+               pr_out_mon_footer();
+               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;
        }
+       fflush(stdout);
        return MNL_CB_OK;
 }
 
@@ -4370,8 +5078,10 @@ static int cmd_mon_show(struct dl *dl)
                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;
                }
@@ -4379,7 +5089,11 @@ static int cmd_mon_show(struct dl *dl)
        err = _mnlg_socket_group_add(dl->nlg, DEVLINK_GENL_MCGRP_CONFIG_NAME);
        if (err)
                return err;
-       err = _mnlg_socket_recv_run(dl->nlg, cmd_mon_show_cb, dl);
+       open_json_object(NULL);
+       open_json_array(PRINT_JSON, "mon");
+       err = _mnlg_socket_recv_run_intr(dl->nlg, cmd_mon_show_cb, dl);
+       close_json_array(PRINT_JSON, NULL);
+       close_json_object();
        if (err)
                return err;
        return 0;
@@ -4388,7 +5102,7 @@ static int cmd_mon_show(struct dl *dl)
 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)
@@ -4715,13 +5429,15 @@ static void pr_out_dpipe_fields(struct dpipe_ctx *ctx,
        for (i = 0; i < field_count; i++) {
                field = &fields[i];
                pr_out_entry_start(ctx->dl);
-               pr_out_str(ctx->dl, "name", field->name);
+               check_indent_newline(ctx->dl);
+               print_string(PRINT_ANY, "name", "name %s", field->name);
                if (ctx->dl->verbose)
-                       pr_out_uint(ctx->dl, "id", field->id);
-               pr_out_uint(ctx->dl, "bitwidth", field->bitwidth);
-               if (field->mapping_type)
-                       pr_out_str(ctx->dl, "mapping_type",
-                                  dpipe_field_mapping_e2s(field->mapping_type));
+                       print_uint(PRINT_ANY, "id", " id %u", field->id);
+               print_uint(PRINT_ANY, "bitwidth", " bitwidth %u", field->bitwidth);
+               if (field->mapping_type) {
+                       print_string(PRINT_ANY, "mapping_type", " mapping_type %s",
+                                    dpipe_field_mapping_e2s(field->mapping_type));
+               }
                pr_out_entry_end(ctx->dl);
        }
 }
@@ -4731,11 +5447,11 @@ pr_out_dpipe_header(struct dpipe_ctx *ctx, struct nlattr **tb,
                    struct dpipe_header *header, bool global)
 {
        pr_out_handle_start_arr(ctx->dl, tb);
-       pr_out_str(ctx->dl, "name", header->name);
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "name", "name %s", header->name);
        if (ctx->dl->verbose) {
-               pr_out_uint(ctx->dl, "id", header->id);
-               pr_out_str(ctx->dl, "global",
-                          global ? "true" : "false");
+               print_uint(PRINT_ANY, "id", " id %u", header->id);
+               print_bool(PRINT_ANY, "global", " global %s", global);
        }
        pr_out_array_start(ctx->dl, "field");
        pr_out_dpipe_fields(ctx, header->fields,
@@ -4913,15 +5629,19 @@ static int cmd_dpipe_headers_show(struct dl *dl)
        return err;
 }
 
-static void cmd_dpipe_header_help(void)
+static void cmd_dpipe_help(void)
 {
-       pr_err("Usage: devlink dpipe headers show DEV\n");
+       pr_err("Usage: devlink dpipe table show DEV [ name TABLE_NAME ]\n");
+       pr_err("       devlink dpipe table set DEV name TABLE_NAME\n");
+       pr_err("                               [ counters_enabled { true | false } ]\n");
+       pr_err("       devlink dpipe table dump DEV name TABLE_NAME\n");
+       pr_err("       devlink dpipe header show DEV\n");
 }
 
 static int cmd_dpipe_header(struct dl *dl)
 {
        if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-               cmd_dpipe_header_help();
+               cmd_dpipe_help();
                return 0;
        } else if (dl_argv_match(dl, "show")) {
                dl_arg_inc(dl);
@@ -4959,20 +5679,21 @@ static void pr_out_dpipe_action(struct dpipe_action *action,
        struct dpipe_op_info *op_info = &action->info;
        const char *mapping;
 
-       pr_out_str(ctx->dl, "type",
-                  dpipe_action_type_e2s(action->type));
-       pr_out_str(ctx->dl, "header",
-                  dpipe_header_id2s(ctx, op_info->header_id,
-                                    op_info->header_global));
-       pr_out_str(ctx->dl, "field",
-                  dpipe_field_id2s(ctx, op_info->header_id,
-                                   op_info->field_id,
-                                   op_info->header_global));
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "type", "type %s",
+                    dpipe_action_type_e2s(action->type));
+       print_string(PRINT_ANY, "header", " header %s",
+                    dpipe_header_id2s(ctx, op_info->header_id,
+                                      op_info->header_global));
+       print_string(PRINT_ANY, "field", " field %s",
+                    dpipe_field_id2s(ctx, op_info->header_id,
+                                     op_info->field_id,
+                                     op_info->header_global));
        mapping = dpipe_mapping_get(ctx, op_info->header_id,
                                    op_info->field_id,
                                    op_info->header_global);
        if (mapping)
-               pr_out_str(ctx->dl, "mapping", mapping);
+               print_string(PRINT_ANY, "mapping", " mapping %s", mapping);
 }
 
 static int dpipe_action_parse(struct dpipe_action *action, struct nlattr *nl)
@@ -5041,20 +5762,21 @@ static void pr_out_dpipe_match(struct dpipe_match *match,
        struct dpipe_op_info *op_info = &match->info;
        const char *mapping;
 
-       pr_out_str(ctx->dl, "type",
-                  dpipe_match_type_e2s(match->type));
-       pr_out_str(ctx->dl, "header",
-                  dpipe_header_id2s(ctx, op_info->header_id,
-                                    op_info->header_global));
-       pr_out_str(ctx->dl, "field",
-                  dpipe_field_id2s(ctx, op_info->header_id,
-                                   op_info->field_id,
-                                   op_info->header_global));
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "type", "type %s",
+                    dpipe_match_type_e2s(match->type));
+       print_string(PRINT_ANY, "header", " header %s",
+                    dpipe_header_id2s(ctx, op_info->header_id,
+                                      op_info->header_global));
+       print_string(PRINT_ANY, "field", " field %s",
+                    dpipe_field_id2s(ctx, op_info->header_id,
+                                     op_info->field_id,
+                                     op_info->header_global));
        mapping = dpipe_mapping_get(ctx, op_info->header_id,
                                    op_info->field_id,
                                    op_info->header_global);
        if (mapping)
-               pr_out_str(ctx->dl, "mapping", mapping);
+               print_string(PRINT_ANY, "mapping", " mapping %s", mapping);
 }
 
 static int dpipe_match_parse(struct dpipe_match *match,
@@ -5159,7 +5881,8 @@ resource_path_print(struct dl *dl, struct resources *resources,
                path -= strlen(del);
                memcpy(path, del, strlen(del));
        }
-       pr_out_str(dl, "resource_path", path);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "resource_path", "resource_path %s", path);
        free(path);
 }
 
@@ -5204,16 +5927,17 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
        if (!ctx->print_tables)
                return 0;
 
-       pr_out_str(ctx->dl, "name", table->name);
-       pr_out_uint(ctx->dl, "size", size);
-       pr_out_str(ctx->dl, "counters_enabled",
-                  counters_enabled ? "true" : "false");
+       check_indent_newline(ctx->dl);
+       print_string(PRINT_ANY, "name", "name %s", table->name);
+       print_uint(PRINT_ANY, "size", " size %u", size);
+       print_bool(PRINT_ANY, "counters_enabled", " counters_enabled %s", counters_enabled);
 
        if (resource_valid) {
                resource_units = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS]);
                resource_path_print(ctx->dl, ctx->resources,
                                    table->resource_id);
-               pr_out_uint(ctx->dl, "resource_units", resource_units);
+               print_uint(PRINT_ANY, "resource_units", " resource_units %u",
+                          resource_units);
        }
 
        pr_out_array_start(ctx->dl, "match");
@@ -5384,7 +6108,8 @@ static void dpipe_field_printer_ipv4_addr(struct dpipe_ctx *ctx,
        struct in_addr ip_addr;
 
        ip_addr.s_addr = htonl(*(uint32_t *)value);
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type), inet_ntoa(ip_addr));
 }
 
 static void
@@ -5392,8 +6117,9 @@ dpipe_field_printer_ethernet_addr(struct dpipe_ctx *ctx,
                                  enum dpipe_value_type type,
                                  void *value)
 {
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type),
-                  ether_ntoa((struct ether_addr *)value));
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type),
+                               ether_ntoa((struct ether_addr *)value));
 }
 
 static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
@@ -5403,7 +6129,8 @@ static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx,
        char str[INET6_ADDRSTRLEN];
 
        inet_ntop(AF_INET6, value, str, INET6_ADDRSTRLEN);
-       pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str);
+       check_indent_newline(ctx->dl);
+       print_string_name_value(dpipe_value_type_e2s(type), str);
 }
 
 static struct dpipe_field_printer dpipe_field_printers_ipv4[] = {
@@ -5493,7 +6220,8 @@ static void __pr_out_entry_value(struct dpipe_ctx *ctx,
        if (value_len == sizeof(uint32_t)) {
                uint32_t *value_32 = value;
 
-               pr_out_uint(ctx->dl, dpipe_value_type_e2s(type), *value_32);
+               check_indent_newline(ctx->dl);
+               print_uint_name_value(dpipe_value_type_e2s(type), *value_32);
        }
 }
 
@@ -5514,7 +6242,8 @@ static void pr_out_dpipe_entry_value(struct dpipe_ctx *ctx,
 
        if (mapping) {
                value_mapping = mnl_attr_get_u32(nla_match_value[DEVLINK_ATTR_DPIPE_VALUE_MAPPING]);
-               pr_out_uint(ctx->dl, "mapping_value", value_mapping);
+               check_indent_newline(ctx->dl);
+               print_uint(PRINT_ANY, "mapping_value", "mapping_value %u", value_mapping);
        }
 
        if (mask) {
@@ -5631,12 +6360,13 @@ static int dpipe_entry_show(struct dpipe_ctx *ctx, struct nlattr *nl)
                return -EINVAL;
        }
 
+       check_indent_newline(ctx->dl);
        entry_index = mnl_attr_get_u32(nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_INDEX]);
-       pr_out_uint(ctx->dl, "index", entry_index);
+       print_uint(PRINT_ANY, "index", "index %u", entry_index);
 
        if (nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER]) {
                counter = mnl_attr_get_u64(nla_entry[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER]);
-               pr_out_uint(ctx->dl, "counter", counter);
+               print_uint(PRINT_ANY, "counter", " counter %u", counter);
        }
 
        pr_out_array_start(ctx->dl, "match_value");
@@ -5727,16 +6457,10 @@ out:
        return err;
 }
 
-static void cmd_dpipe_table_help(void)
-{
-       pr_err("Usage: devlink dpipe table [ OBJECT-LIST ]\n"
-              "where  OBJECT-LIST := { show | set | dump }\n");
-}
-
 static int cmd_dpipe_table(struct dl *dl)
 {
        if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
-               cmd_dpipe_table_help();
+               cmd_dpipe_help();
                return 0;
        } else if (dl_argv_match(dl, "show")) {
                dl_arg_inc(dl);
@@ -5752,12 +6476,6 @@ static int cmd_dpipe_table(struct dl *dl)
        return -ENOENT;
 }
 
-static void cmd_dpipe_help(void)
-{
-       pr_err("Usage: devlink dpipe [ OBJECT-LIST ]\n"
-              "where  OBJECT-LIST := { header | table }\n");
-}
-
 static int cmd_dpipe(struct dl *dl)
 {
        if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
@@ -5882,20 +6600,24 @@ static void resource_show(struct resource *resource,
        struct dl *dl = ctx->dl;
        bool array = false;
 
-       pr_out_str(dl, "name", resource->name);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s", resource->name);
        if (dl->verbose)
                resource_path_print(dl, ctx->resources, resource->id);
        pr_out_u64(dl, "size", resource->size);
        if (resource->size != resource->size_new)
                pr_out_u64(dl, "size_new", resource->size_new);
        if (resource->occ_valid)
-               pr_out_uint(dl, "occ", resource->size_occ);
-       pr_out_str(dl, "unit", resource_unit_str_get(resource->unit));
+               print_uint(PRINT_ANY, "occ", " occ %u",  resource->size_occ);
+       print_string(PRINT_ANY, "unit", " unit %s",
+                    resource_unit_str_get(resource->unit));
 
        if (resource->size_min != resource->size_max) {
-               pr_out_uint(dl, "size_min", resource->size_min);
+               print_uint(PRINT_ANY, "size_min", " size_min %u",
+                          resource->size_min);
                pr_out_u64(dl, "size_max", resource->size_max);
-               pr_out_uint(dl, "size_gran", resource->size_gran);
+               print_uint(PRINT_ANY, "size_gran", " size_gran %u",
+                          resource->size_gran);
        }
 
        list_for_each_entry(table, &ctx->tables->table_list, list)
@@ -5906,14 +6628,17 @@ static void resource_show(struct resource *resource,
        if (array)
                pr_out_array_start(dl, "dpipe_tables");
        else
-               pr_out_str(dl, "dpipe_tables", "none");
+               print_string(PRINT_ANY, "dpipe_tables", " dpipe_tables none",
+                            "none");
 
        list_for_each_entry(table, &ctx->tables->table_list, list) {
                if (table->resource_id != resource->id ||
                    !table->resource_valid)
                        continue;
                pr_out_entry_start(dl);
-               pr_out_str(dl, "table_name", table->name);
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "table_name", "table_name %s",
+                            table->name);
                pr_out_entry_end(dl);
        }
        if (array)
@@ -5922,9 +6647,11 @@ static void resource_show(struct resource *resource,
        if (list_empty(&resource->resource_list))
                return;
 
-       if (ctx->pending_change)
-               pr_out_str(dl, "size_valid", resource->size_valid ?
-                          "true" : "false");
+       if (ctx->pending_change) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, "size_valid", "size_valid %s",
+                            resource->size_valid ? "true" : "false");
+       }
        pr_out_array_start(dl, "resources");
        list_for_each_entry(child_resource, &resource->resource_list, list) {
                pr_out_entry_start(dl);
@@ -6139,18 +6866,16 @@ static void pr_out_region_handle_start(struct dl *dl, struct nlattr **tb)
        char buf[256];
 
        sprintf(buf, "%s/%s/%s", bus_name, dev_name, region_name);
-       if (dl->json_output) {
-               jsonw_name(dl->jw, buf);
-               jsonw_start_object(dl->jw);
-       } else {
+       if (dl->json_output)
+               open_json_object(buf);
+       else
                pr_out("%s:", buf);
-       }
 }
 
 static void pr_out_region_handle_end(struct dl *dl)
 {
        if (dl->json_output)
-               jsonw_end_object(dl->jw);
+               close_json_object();
        else
                pr_out("\n");
 }
@@ -6158,18 +6883,16 @@ static void pr_out_region_handle_end(struct dl *dl)
 static void pr_out_region_snapshots_start(struct dl *dl, bool array)
 {
        __pr_out_indent_newline(dl);
-       if (dl->json_output) {
-               jsonw_name(dl->jw, "snapshot");
-               jsonw_start_array(dl->jw);
-       } else {
+       if (dl->json_output)
+               open_json_array(PRINT_JSON, "snapshot");
+       else
                pr_out("snapshot %s", array ? "[" : "");
-       }
 }
 
 static void pr_out_region_snapshots_end(struct dl *dl, bool array)
 {
        if (dl->json_output)
-               jsonw_end_array(dl->jw);
+               close_json_array(PRINT_JSON, NULL);
        else if (array)
                pr_out("]");
 }
@@ -6184,7 +6907,7 @@ static void pr_out_region_snapshots_id(struct dl *dl, struct nlattr **tb, int in
        snapshot_id = mnl_attr_get_u32(tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
 
        if (dl->json_output)
-               jsonw_uint(dl->jw, snapshot_id);
+               print_uint(PRINT_JSON, NULL, NULL, snapshot_id);
        else
                pr_out("%s%u", index ? " " : "", snapshot_id);
 }
@@ -6361,10 +7084,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");
 }
@@ -6388,6 +7148,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;
@@ -6400,9 +7163,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;
 
@@ -6419,7 +7183,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;
 
@@ -6432,24 +7197,25 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
        uint8_t *data;
        uint32_t len;
 
+       check_indent_newline(dl);
        switch (type) {
        case MNL_TYPE_FLAG:
-               pr_out_bool_value(dl, mnl_attr_get_u8(nl_data));
+               print_bool(PRINT_ANY, NULL, "%s", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U8:
-               pr_out_uint_value(dl, mnl_attr_get_u8(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u8(nl_data));
                break;
        case MNL_TYPE_U16:
-               pr_out_uint_value(dl, mnl_attr_get_u16(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u16(nl_data));
                break;
        case MNL_TYPE_U32:
-               pr_out_uint_value(dl, mnl_attr_get_u32(nl_data));
+               print_uint(PRINT_ANY, NULL, "%u", mnl_attr_get_u32(nl_data));
                break;
        case MNL_TYPE_U64:
-               pr_out_uint64_value(dl, mnl_attr_get_u64(nl_data));
+               print_u64(PRINT_ANY, NULL, "%"PRIu64, mnl_attr_get_u64(nl_data));
                break;
        case MNL_TYPE_NUL_STRING:
-               pr_out_str_value(dl, mnl_attr_get_str(nl_data));
+               print_string(PRINT_ANY, NULL, "%s", mnl_attr_get_str(nl_data));
                break;
        case MNL_TYPE_BINARY:
                len = mnl_attr_get_payload_len(nl_data);
@@ -6462,12 +7228,23 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
        return MNL_CB_OK;
 }
 
+static void pr_out_fmsg_name(struct dl *dl, char **name)
+{
+       if (!*name)
+               return;
+
+       pr_out_name(dl, *name);
+       free(*name);
+       *name = NULL;
+}
+
 struct nest_entry {
        int attr_type;
        struct list_head list;
 };
 
 struct fmsg_cb_data {
+       char *name;
        struct dl *dl;
        uint8_t value_type;
        struct list_head entry_list;
@@ -6497,6 +7274,56 @@ static int cmd_fmsg_nest_queue(struct fmsg_cb_data *fmsg_data,
        return MNL_CB_OK;
 }
 
+static void pr_out_fmsg_group_start(struct dl *dl, char **name)
+{
+       __pr_out_newline();
+       pr_out_fmsg_name(dl, name);
+       __pr_out_newline();
+       __pr_out_indent_inc();
+}
+
+static void pr_out_fmsg_group_end(struct dl *dl)
+{
+       __pr_out_newline();
+       __pr_out_indent_dec();
+}
+
+static void pr_out_fmsg_start_object(struct dl *dl, char **name)
+{
+       if (dl->json_output) {
+               pr_out_fmsg_name(dl, name);
+               open_json_object(NULL);
+       } else {
+               pr_out_fmsg_group_start(dl, name);
+       }
+}
+
+static void pr_out_fmsg_end_object(struct dl *dl)
+{
+       if (dl->json_output)
+               close_json_object();
+       else
+               pr_out_fmsg_group_end(dl);
+}
+
+static void pr_out_fmsg_start_array(struct dl *dl, char **name)
+{
+       if (dl->json_output) {
+               pr_out_fmsg_name(dl, name);
+               open_json_array(PRINT_JSON, NULL);
+       } else {
+               pr_out_fmsg_group_start(dl, name);
+       }
+}
+
+static void pr_out_fmsg_end_array(struct dl *dl)
+{
+       if (dl->json_output)
+               close_json_array(PRINT_JSON, NULL);
+       else
+               pr_out_fmsg_group_end(dl);
+}
+
 static int cmd_fmsg_nest(struct fmsg_cb_data *fmsg_data, uint8_t nest_value,
                         bool start)
 {
@@ -6511,26 +7338,17 @@ static int cmd_fmsg_nest(struct fmsg_cb_data *fmsg_data, uint8_t nest_value,
        switch (value) {
        case DEVLINK_ATTR_FMSG_OBJ_NEST_START:
                if (start)
-                       pr_out_entry_start(dl);
+                       pr_out_fmsg_start_object(dl, &fmsg_data->name);
                else
-                       pr_out_entry_end(dl);
+                       pr_out_fmsg_end_object(dl);
                break;
        case DEVLINK_ATTR_FMSG_PAIR_NEST_START:
                break;
        case DEVLINK_ATTR_FMSG_ARR_NEST_START:
-               if (dl->json_output) {
-                       if (start)
-                               jsonw_start_array(dl->jw);
-                       else
-                               jsonw_end_array(dl->jw);
-               } else {
-                       if (start) {
-                               __pr_out_newline();
-                               __pr_out_indent_inc();
-                       } else {
-                               __pr_out_indent_dec();
-                       }
-               }
+               if (start)
+                       pr_out_fmsg_start_array(dl, &fmsg_data->name);
+               else
+                       pr_out_fmsg_end_array(dl);
                break;
        default:
                return -EINVAL;
@@ -6568,12 +7386,16 @@ static int cmd_fmsg_object_cb(const struct nlmsghdr *nlh, void *data)
                                return err;
                        break;
                case DEVLINK_ATTR_FMSG_OBJ_NAME:
-                       pr_out_name(dl, mnl_attr_get_str(nla_object));
+                       free(fmsg_data->name);
+                       fmsg_data->name = strdup(mnl_attr_get_str(nla_object));
+                       if (!fmsg_data->name)
+                               return -ENOMEM;
                        break;
                case DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE:
                        fmsg_data->value_type = mnl_attr_get_u8(nla_object);
                        break;
                case DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA:
+                       pr_out_fmsg_name(dl, &fmsg_data->name);
                        err = fmsg_value_show(dl, fmsg_data->value_type,
                                              nla_object);
                        if (err != MNL_CB_OK)
@@ -6586,6 +7408,20 @@ static int cmd_fmsg_object_cb(const struct nlmsghdr *nlh, void *data)
        return MNL_CB_OK;
 }
 
+static void cmd_fmsg_init(struct dl *dl, struct fmsg_cb_data *data)
+{
+       /* FMSG is dynamic: opening of an object or array causes a
+        * newline. JSON starts with an { or [, but plain text should
+        * not start with a new line. Ensure this by setting
+        * g_new_line_count to 1: avoiding newline before the first
+        * print.
+        */
+       g_new_line_count = 1;
+       data->name = NULL;
+       data->dl = dl;
+       INIT_LIST_HEAD(&data->entry_list);
+}
+
 static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
 {
        struct fmsg_cb_data data;
@@ -6595,13 +7431,14 @@ 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;
 
-       data.dl = dl;
-       INIT_LIST_HEAD(&data.entry_list);
+       cmd_fmsg_init(dl, &data);
        err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_fmsg_object_cb, &data);
+       free(data.name);
        return err;
 }
 
@@ -6619,6 +7456,13 @@ static int cmd_health_diagnose(struct dl *dl)
                                        0);
 }
 
+static int cmd_health_test(struct dl *dl)
+{
+       return cmd_health_object_common(dl,
+                                       DEVLINK_CMD_HEALTH_REPORTER_TEST,
+                                       0);
+}
+
 static int cmd_health_recover(struct dl *dl)
 {
        struct nlmsghdr *nlh;
@@ -6628,7 +7472,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;
 
@@ -6653,8 +7498,11 @@ static const char *health_state_name(uint8_t state)
        }
 }
 
-static void format_logtime(uint64_t time_ms, char *ts_date, char *ts_time)
+static void pr_out_dump_reporter_format_logtime(struct dl *dl, const struct nlattr *attr)
 {
+       char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       uint64_t time_ms = mnl_attr_get_u64(attr);
        struct sysinfo s_info;
        struct tm *info;
        time_t now, sec;
@@ -6672,16 +7520,38 @@ static void format_logtime(uint64_t time_ms, char *ts_date, char *ts_time)
        sec = now - s_info.uptime + time_ms / 1000;
        info = localtime(&sec);
 out:
-       strftime(ts_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", info);
-       strftime(ts_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", info);
+       strftime(dump_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", info);
+       strftime(dump_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", info);
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "last_dump_date", "last_dump_date %s", dump_date);
+       print_string(PRINT_ANY, "last_dump_time", " last_dump_time %s", dump_time);
+}
+
+static void pr_out_dump_report_timestamp(struct dl *dl, const struct nlattr *attr)
+{
+       char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
+       time_t tv_sec;
+       struct tm *tm;
+       uint64_t ts;
+
+       ts = mnl_attr_get_u64(attr);
+       tv_sec = ts / 1000000000;
+       tm = localtime(&tv_sec);
+
+       strftime(dump_date, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%Y-%m-%d", tm);
+       strftime(dump_time, HEALTH_REPORTER_TIMESTAMP_FMT_LEN, "%H:%M:%S", tm);
+
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "last_dump_date", "last_dump_date %s", dump_date);
+       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;
-       const struct nlattr *attr;
-       uint64_t time_ms;
        int err;
 
        err = mnl_attr_parse_nested(tb_health[DEVLINK_ATTR_HEALTH_REPORTER],
@@ -6695,61 +7565,80 @@ 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);
+       }
 
-       pr_out_str(dl, "reporter",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "reporter", "reporter %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_HEALTH_REPORTER_NAME]));
        if (!dl->json_output) {
                __pr_out_newline();
                __pr_out_indent_inc();
        }
        state = mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_STATE]);
-       pr_out_str(dl, "state", health_state_name(state));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "state", "state %s", health_state_name(state));
        pr_out_u64(dl, "error",
                   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT]));
        pr_out_u64(dl, "recover",
                   mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT]));
-       if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS]) {
-               char dump_date[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
-               char dump_time[HEALTH_REPORTER_TIMESTAMP_FMT_LEN];
-
-               attr = tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS];
-               time_ms = mnl_attr_get_u64(attr);
-               format_logtime(time_ms, dump_date, dump_time);
-
-               pr_out_str(dl, "last_dump_date", dump_date);
-               pr_out_str(dl, "last_dump_time", dump_time);
-       }
+       if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS])
+               pr_out_dump_report_timestamp(dl, tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS]);
+       else if (tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS])
+               pr_out_dump_reporter_format_logtime(dl, tb[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS]);
        if (tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD])
                pr_out_u64(dl, "grace_period",
                           mnl_attr_get_u64(tb[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]));
        if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])
-               pr_out_bool(dl, "auto_recover",
-                           mnl_attr_get_u8(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;
 
@@ -6759,27 +7648,32 @@ 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 { grace_period | auto_recover } { msec | boolean }\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 test { 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)
@@ -6790,13 +7684,16 @@ 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);
        } else if (dl_argv_match(dl, "diagnose")) {
                dl_arg_inc(dl);
                return cmd_health_diagnose(dl);
+       } else if (dl_argv_match(dl, "test")) {
+               dl_arg_inc(dl);
+               return cmd_health_test(dl);
        } else if (dl_argv_match(dl, "dump")) {
                dl_arg_inc(dl);
                if (dl_argv_match(dl, "show")) {
@@ -6821,6 +7718,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>";
        }
@@ -6833,6 +7732,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>";
        }
@@ -6843,6 +7744,8 @@ static const char *trap_metadata_name(const struct nlattr *attr)
        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>";
        }
@@ -6852,8 +7755,11 @@ static void pr_out_trap_metadata(struct dl *dl, struct nlattr *attr)
        struct nlattr *attr_metadata;
 
        pr_out_array_start(dl, "metadata");
-       mnl_attr_for_each_nested(attr_metadata, attr)
-               pr_out_str_value(dl, trap_metadata_name(attr_metadata));
+       mnl_attr_for_each_nested(attr_metadata, attr) {
+               check_indent_newline(dl);
+               print_string(PRINT_ANY, NULL, "%s",
+                            trap_metadata_name(attr_metadata));
+       }
        pr_out_array_end(dl);
 }
 
@@ -6867,12 +7773,14 @@ static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array)
        else
                __pr_out_handle_start(dl, tb, true, false);
 
-       pr_out_str(dl, "name", mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
-       pr_out_str(dl, "type", trap_type_name(type));
-       pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
-       pr_out_str(dl, "action", trap_action_name(action));
-       pr_out_str(dl, "group",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
+       check_indent_newline(dl);
+       print_string(PRINT_ANY, "name", "name %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_NAME]));
+       print_string(PRINT_ANY, "type", " type %s", trap_type_name(type));
+       print_bool(PRINT_ANY, "generic", " generic %s", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
+       print_string(PRINT_ANY, "action", " action %s", trap_action_name(action));
+       print_string(PRINT_ANY, "group", " group %s",
+                    mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
        if (dl->verbose)
                pr_out_trap_metadata(dl, tb[DEVLINK_ATTR_TRAP_METADATA]);
        pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
@@ -6900,10 +7808,13 @@ 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");
+       pr_err("       devlink trap policer show DEV policer POLICER\n");
 }
 
 static int cmd_trap_show(struct dl *dl)
@@ -6954,9 +7865,13 @@ static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array)
        else
                __pr_out_handle_start(dl, tb, true, false);
 
-       pr_out_str(dl, "name",
-                  mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
-       pr_out_bool(dl, "generic", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
+       check_indent_newline(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);
 }
@@ -7013,7 +7928,7 @@ static int cmd_trap_group_set(struct dl *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;
 
@@ -7037,6 +7952,104 @@ static int cmd_trap_group(struct dl *dl)
        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")) {
@@ -7052,6 +8065,9 @@ static int cmd_trap(struct dl *dl)
        } 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;
@@ -7120,18 +8136,9 @@ static int dl_init(struct dl *dl)
                pr_err("Failed to create index map\n");
                goto err_ifname_map_create;
        }
-       if (dl->json_output) {
-               dl->jw = jsonw_new(stdout);
-               if (!dl->jw) {
-                       pr_err("Failed to create JSON writer\n");
-                       goto err_json_new;
-               }
-               jsonw_pretty(dl->jw, dl->pretty_output);
-       }
+       new_json_obj_plain(dl->json_output);
        return 0;
 
-err_json_new:
-       ifname_map_fini(dl);
 err_ifname_map_create:
        mnlg_socket_close(dl->nlg);
        return err;
@@ -7139,8 +8146,7 @@ err_ifname_map_create:
 
 static void dl_fini(struct dl *dl)
 {
-       if (dl->json_output)
-               jsonw_destroy(&dl->jw);
+       delete_json_obj_plain();
        ifname_map_fini(dl);
        mnlg_socket_close(dl->nlg);
 }
@@ -7160,43 +8166,16 @@ static void dl_free(struct dl *dl)
        free(dl);
 }
 
-static int dl_batch(struct dl *dl, const char *name, bool force)
+static int dl_batch_cmd(int argc, char *argv[], void *data)
 {
-       char *line = NULL;
-       size_t len = 0;
-       int ret = EXIT_SUCCESS;
-
-       if (name && strcmp(name, "-") != 0) {
-               if (freopen(name, "r", stdin) == NULL) {
-                       fprintf(stderr,
-                               "Cannot open file \"%s\" for reading: %s\n",
-                               name, strerror(errno));
-                       return EXIT_FAILURE;
-               }
-       }
-
-       cmdlineno = 0;
-       while (getcmdline(&line, &len, stdin) != -1) {
-               char *largv[100];
-               int largc;
-
-               largc = makeargs(line, largv, 100);
-               if (!largc)
-                       continue;       /* blank line */
-
-               if (dl_cmd(dl, largc, largv)) {
-                       fprintf(stderr, "Command failed %s:%d\n",
-                               name, cmdlineno);
-                       ret = EXIT_FAILURE;
-                       if (!force)
-                               break;
-               }
-       }
+       struct dl *dl = data;
 
-       if (line)
-               free(line);
+       return dl_cmd(dl, argc, argv);
+}
 
-       return ret;
+static int dl_batch(struct dl *dl, const char *name, bool force)
+{
+       return do_batch(name, force, dl_batch_cmd, dl);
 }
 
 int main(int argc, char **argv)
@@ -7231,7 +8210,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':
@@ -7247,7 +8226,7 @@ int main(int argc, char **argv)
                        dl->json_output = true;
                        break;
                case 'p':
-                       dl->pretty_output = true;
+                       pretty = true;
                        break;
                case 'v':
                        dl->verbose = true;