]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
devlink: check flash_update parameter support in net core
authorJacob Keller <jacob.e.keller@intel.com>
Fri, 25 Sep 2020 20:46:05 +0000 (13:46 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 26 Sep 2020 00:20:57 +0000 (17:20 -0700)
When implementing .flash_update, drivers which do not support
per-component update are manually checking the component parameter to
verify that it is NULL. Without this check, the driver might accept an
update request with a component specified even though it will not honor
such a request.

Instead of having each driver check this, move the logic into
net/core/devlink.c, and use a new `supported_flash_update_params` field
in the devlink_ops. Drivers which will support per-component update must
now specify this by setting DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT in
the supported_flash_update_params in their devlink_ops.

This helps ensure that drivers do not forget to check for a NULL
component if they do not support per-component update. This also enables
a slightly better error message by enabling the core stack to set the
netlink bad attribute message to indicate precisely the unsupported
attribute in the message.

Going forward, any new additional parameter to flash update will require
a bit in the supported_flash_update_params bitfield.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Cc: Jiri Pirko <jiri@mellanox.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michael Chan <michael.chan@broadcom.com>
Cc: Bin Luo <luobin9@huawei.com>
Cc: Saeed Mahameed <saeedm@mellanox.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Ido Schimmel <idosch@mellanox.com>
Cc: Danielle Ratson <danieller@mellanox.com>
Cc: Shannon Nelson <snelson@pensando.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
drivers/net/ethernet/huawei/hinic/hinic_devlink.c
drivers/net/ethernet/intel/ice/ice_devlink.c
drivers/net/ethernet/mellanox/mlx5/core/devlink.c
drivers/net/ethernet/mellanox/mlxsw/core.c
drivers/net/ethernet/netronome/nfp/nfp_devlink.c
drivers/net/ethernet/pensando/ionic/ionic_devlink.c
drivers/net/netdevsim/dev.c
include/net/devlink.h
net/core/devlink.c

index 3a854195d5b0f6577d06c10ceccaff58649ddafb..a17764db1419252eb14822cd2107febe120e933a 100644 (file)
@@ -23,9 +23,6 @@ bnxt_dl_flash_update(struct devlink *dl, const char *filename,
        struct bnxt *bp = bnxt_get_bp_from_dl(dl);
        int rc;
 
-       if (region)
-               return -EOPNOTSUPP;
-
        if (!BNXT_PF(bp)) {
                NL_SET_ERR_MSG_MOD(extack,
                                   "flash update not supported from a VF");
@@ -33,15 +30,12 @@ bnxt_dl_flash_update(struct devlink *dl, const char *filename,
        }
 
        devlink_flash_update_begin_notify(dl);
-       devlink_flash_update_status_notify(dl, "Preparing to flash", region, 0,
-                                          0);
+       devlink_flash_update_status_notify(dl, "Preparing to flash", NULL, 0, 0);
        rc = bnxt_flash_package_from_file(bp->dev, filename, 0);
        if (!rc)
-               devlink_flash_update_status_notify(dl, "Flashing done", region,
-                                                  0, 0);
+               devlink_flash_update_status_notify(dl, "Flashing done", NULL, 0, 0);
        else
-               devlink_flash_update_status_notify(dl, "Flashing failed",
-                                                  region, 0, 0);
+               devlink_flash_update_status_notify(dl, "Flashing failed", NULL, 0, 0);
        devlink_flash_update_end_notify(dl);
        return rc;
 }
index 16bda7381ba0befb08e224232c08fca1e4aee684..662a27a514ae3a7e654558643494355f2a0a3fc9 100644 (file)
@@ -289,9 +289,6 @@ static int hinic_devlink_flash_update(struct devlink *devlink,
        const struct firmware *fw;
        int err;
 
-       if (component)
-               return -EOPNOTSUPP;
-
        err = request_firmware_direct(&fw, file_name,
                                      &priv->hwdev->hwif->pdev->dev);
        if (err)
index 67d1190cb16413eee6a23fd2e03f003ae9ce6795..4666f1d5a6955aa6818ea699bb00a2e3ae9c9383 100644 (file)
@@ -252,16 +252,12 @@ ice_devlink_flash_update(struct devlink *devlink, const char *path,
        const struct firmware *fw;
        int err;
 
-       /* individual component update is not yet supported */
-       if (component)
-               return -EOPNOTSUPP;
-
        if (!hw->dev_caps.common_cap.nvm_unified_update) {
                NL_SET_ERR_MSG_MOD(extack, "Current firmware does not support unified update");
                return -EOPNOTSUPP;
        }
 
-       err = ice_check_for_pending_update(pf, component, extack);
+       err = ice_check_for_pending_update(pf, NULL, extack);
        if (err)
                return err;
 
@@ -272,8 +268,7 @@ ice_devlink_flash_update(struct devlink *devlink, const char *path,
        }
 
        devlink_flash_update_begin_notify(devlink);
-       devlink_flash_update_status_notify(devlink, "Preparing to flash",
-                                          component, 0, 0);
+       devlink_flash_update_status_notify(devlink, "Preparing to flash", NULL, 0, 0);
        err = ice_flash_pldm_image(pf, fw, extack);
        devlink_flash_update_end_notify(devlink);
 
index c709e9a385f6bd4cb58517f728980b66a7a87771..fccae4b802b6bd322853a261e01a6214d82fcdf3 100644 (file)
@@ -16,9 +16,6 @@ static int mlx5_devlink_flash_update(struct devlink *devlink,
        const struct firmware *fw;
        int err;
 
-       if (component)
-               return -EOPNOTSUPP;
-
        err = request_firmware_direct(&fw, file_name, &dev->pdev->dev);
        if (err)
                return err;
index 1bb21fe295b9ef36b91c6bff7d7ad1df217ca8f4..3ffd03ef9c0e7eaed5c158fd21b1d725d92cc504 100644 (file)
@@ -1108,9 +1108,6 @@ static int mlxsw_core_fw_flash_update(struct mlxsw_core *mlxsw_core,
        const struct firmware *firmware;
        int err;
 
-       if (component)
-               return -EOPNOTSUPP;
-
        err = request_firmware_direct(&firmware, file_name, mlxsw_core->bus_info->dev);
        if (err)
                return err;
index be52510d446bd113a95091a26fad6b27a875d873..c93cb9a27e25def827a1edde8ee63178d38da475 100644 (file)
@@ -332,8 +332,6 @@ static int
 nfp_devlink_flash_update(struct devlink *devlink, const char *path,
                         const char *component, struct netlink_ext_ack *extack)
 {
-       if (component)
-               return -EOPNOTSUPP;
        return nfp_flash_update_common(devlink_priv(devlink), path, extack);
 }
 
index 5348f05ebc32d444126170d333b5b8083be5b64c..c125988b095483560921927148532089b3187a1f 100644 (file)
@@ -16,9 +16,6 @@ static int ionic_dl_flash_update(struct devlink *dl,
 {
        struct ionic *ionic = devlink_priv(dl);
 
-       if (component)
-               return -EOPNOTSUPP;
-
        return ionic_firmware_update(ionic->lif, fwname, extack);
 }
 
index e665efd760f80aebef0348321bca8bff53b9b437..424bdab8e8888cfde01a3e1c03bc7b30a9a9ce95 100644 (file)
@@ -879,6 +879,7 @@ nsim_dev_devlink_trap_policer_counter_get(struct devlink *devlink,
 }
 
 static const struct devlink_ops nsim_dev_devlink_ops = {
+       .supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT,
        .reload_down = nsim_dev_reload_down,
        .reload_up = nsim_dev_reload_up,
        .info_get = nsim_dev_info_get,
index 4883dbae7faf8bbb00154a01cef700ad21f96aec..cec6b4f109fa7299888028ba39b75d94b2e7f7e3 100644 (file)
@@ -550,6 +550,8 @@ enum devlink_param_generic_id {
 /* Firmware bundle identifier */
 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID      "fw.bundle_id"
 
+#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
+
 struct devlink_region;
 struct devlink_info_req;
 
@@ -1037,6 +1039,12 @@ enum devlink_trap_group_generic_id {
        }
 
 struct devlink_ops {
+       /**
+        * @supported_flash_update_params:
+        * mask of parameters supported by the driver's .flash_update
+        * implemementation.
+        */
+       u32 supported_flash_update_params;
        int (*reload_down)(struct devlink *devlink, bool netns_change,
                           struct netlink_ext_ack *extack);
        int (*reload_up)(struct devlink *devlink,
@@ -1097,6 +1105,13 @@ struct devlink_ops {
                                      struct netlink_ext_ack *extack);
        int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
                        struct netlink_ext_ack *extack);
+       /**
+        * @flash_update: Device flash update function
+        *
+        * Used to perform a flash update for the device. The set of
+        * parameters supported by the driver should be set in
+        * supported_flash_update_params.
+        */
        int (*flash_update)(struct devlink *devlink, const char *file_name,
                            const char *component,
                            struct netlink_ext_ack *extack);
index ac32b672a04bcb82edea35b4b3a9c2128e412aa7..7c69a41016a27eb21e916ca6831058be7ceb8077 100644 (file)
@@ -3148,18 +3148,29 @@ 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;
+       const char *file_name, *component = NULL;
        struct nlattr *nla_component;
+       u32 supported_params;
 
        if (!devlink->ops->flash_update)
                return -EOPNOTSUPP;
 
        if (!info->attrs[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME])
                return -EINVAL;
+
+       supported_params = devlink->ops->supported_flash_update_params;
+
        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;
+       if (nla_component) {
+               if (!(supported_params & DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT)) {
+                       NL_SET_ERR_MSG_ATTR(info->extack, nla_component,
+                                           "component update is not supported by this device");
+                       return -EOPNOTSUPP;
+               }
+               component = nla_data(nla_component);
+       }
 
        return devlink->ops->flash_update(devlink, file_name, component,
                                          info->extack);