devlink: add flash update command
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 14 Feb 2019 21:40:44 +0000 (13:40 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 17 Feb 2019 23:27:38 +0000 (15:27 -0800)
Add devlink flash update command. Advanced NICs have firmware
stored in flash and often cryptographically secured. Updating
that flash is handled by management firmware. Ethtool has a
flash update command which served us well, however, it has two
shortcomings:
 - it takes rtnl_lock unnecessarily - really flash update has
   nothing to do with networking, so using a networking device
   as a handle is suboptimal, which leads us to the second one:
 - it requires a functioning netdev - in case device enters an
   error state and can't spawn a netdev (e.g. communication
   with the device fails) there is no netdev to use as a handle
   for flashing.

Devlink already has the ability to report the firmware versions,
now with the ability to update the firmware/flash we will be
able to recover devices in bad state.

To enable updates of sub-components of the FW allow passing
component name.  This name should correspond to one of the
versions reported in devlink info.

v1: - replace target id with component name (Jiri).

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/devlink.h
include/uapi/linux/devlink.h
net/core/devlink.c

index c6d88759b7d5cc29f041688a9ee894a70755d66d..18d7a051f41218e2e06a1102cf283bb5a5448771 100644 (file)
@@ -521,6 +521,9 @@ struct devlink_ops {
                                      struct netlink_ext_ack *extack);
        int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
                        struct netlink_ext_ack *extack);
+       int (*flash_update)(struct devlink *devlink, const char *file_name,
+                           const char *component,
+                           struct netlink_ext_ack *extack);
 };
 
 static inline void *devlink_priv(struct devlink *devlink)
index 72d9f7c8919046ed010abe13d0e1a45a61ebeed1..53de8802a000b508537cc0a51966e9459374aafc 100644 (file)
@@ -103,6 +103,8 @@ enum devlink_command {
        DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
        DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
 
+       DEVLINK_CMD_FLASH_UPDATE,
+
        /* add new commands above here */
        __DEVLINK_CMD_MAX,
        DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
@@ -326,6 +328,10 @@ enum devlink_attr {
        DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS,           /* u64 */
        DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD,   /* u64 */
        DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,      /* u8 */
+
+       DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME,    /* string */
+       DEVLINK_ATTR_FLASH_UPDATE_COMPONENT,    /* string */
+
        /* add new attributes above here, update the policy in devlink.c */
 
        __DEVLINK_ATTR_MAX,
index 1d7502a5a651d98fdfd2c4ee7cc36a09b7e313b7..4a1ad0b13e52676ab83c3ffb51870ab7388283de 100644 (file)
@@ -2662,6 +2662,27 @@ static int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info)
        return devlink->ops->reload(devlink, info->extack);
 }
 
+static int devlink_nl_cmd_flash_update(struct sk_buff *skb,
+                                      struct genl_info *info)
+{
+       struct devlink *devlink = info->user_ptr[0];
+       const char *file_name, *component;
+       struct nlattr *nla_component;
+
+       if (!devlink->ops->flash_update)
+               return -EOPNOTSUPP;
+
+       if (!info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME])
+               return -EINVAL;
+       file_name = nla_data(info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME]);
+
+       nla_component = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT];
+       component = nla_component ? nla_data(nla_component) : NULL;
+
+       return devlink->ops->flash_update(devlink, file_name, component,
+                                         info->extack);
+}
+
 static const struct devlink_param devlink_param_generic[] = {
        {
                .id = DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
@@ -4883,6 +4904,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_HEALTH_REPORTER_NAME] = { .type = NLA_NUL_STRING },
        [DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = { .type = NLA_U64 },
        [DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER] = { .type = NLA_U8 },
+       [DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME] = { .type = NLA_NUL_STRING },
+       [DEVLINK_ATTR_FLASH_UPDATE_COMPONENT] = { .type = NLA_NUL_STRING },
 };
 
 static const struct genl_ops devlink_nl_ops[] = {
@@ -5171,6 +5194,13 @@ static const struct genl_ops devlink_nl_ops[] = {
                .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
                                  DEVLINK_NL_FLAG_NO_LOCK,
        },
+       {
+               .cmd = DEVLINK_CMD_FLASH_UPDATE,
+               .doit = devlink_nl_cmd_flash_update,
+               .policy = devlink_nl_policy,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
+       },
 };
 
 static struct genl_family devlink_nl_family __ro_after_init = {