On Wed, 9 Sep 2020 15:26:51 -0700 Jacob Keller wrote: > diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h > index 40d35145c879..19a573566359 100644 > --- a/include/uapi/linux/devlink.h > +++ b/include/uapi/linux/devlink.h > @@ -228,6 +228,28 @@ enum { > DEVLINK_ATTR_STATS_MAX = __DEVLINK_ATTR_STATS_MAX - 1 > }; > > +/* Specify what sections of a flash component can be overwritten when > + * performing an update. Overwriting of firmware binary sections is always > + * implicitly assumed to be allowed. > + * > + * Each section must be documented in > + * Documentation/networking/devlink/devlink-flash.rst > + * > + */ > +enum { > + DEVLINK_FLASH_OVERWRITE_SETTINGS_BIT, > + DEVLINK_FLASH_OVERWRITE_IDENTIFIERS_BIT, > + > + __DEVLINK_FLASH_OVERWRITE_MAX_BIT, > + DEVLINK_FLASH_OVERWRITE_MAX_BIT = __DEVLINK_FLASH_OVERWRITE_MAX_BIT - 1 > +}; > + > +#define DEVLINK_FLASH_OVERWRITE_SETTINGS > BIT(DEVLINK_FLASH_OVERWRITE_SETTINGS_BIT) > +#define DEVLINK_FLASH_OVERWRITE_IDENTIFIERS > BIT(DEVLINK_FLASH_OVERWRITE_IDENTIFIERS_BIT) > + > +#define DEVLINK_SUPPORTED_FLASH_OVERWRITE_SECTIONS \ > + (BIT(__DEVLINK_FLASH_OVERWRITE_MAX_BIT) - 1)
I don't think you can use BIT() in uAPI headers :( > /** > * enum devlink_trap_action - Packet trap action. > * @DEVLINK_TRAP_ACTION_DROP: Packet is dropped by the device and a copy is > not > @@ -460,6 +482,9 @@ enum devlink_attr { > > DEVLINK_ATTR_PORT_EXTERNAL, /* u8 */ > DEVLINK_ATTR_PORT_CONTROLLER_NUMBER, /* u32 */ > + > + DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK, /* bitfield32 */ > + > /* add new attributes above here, update the policy in devlink.c */ > > __DEVLINK_ATTR_MAX, > diff --git a/net/core/devlink.c b/net/core/devlink.c > index c61f9c8205f6..d0d38ca17ea8 100644 > --- a/net/core/devlink.c > +++ b/net/core/devlink.c > @@ -3125,8 +3125,8 @@ static int devlink_nl_cmd_flash_update(struct sk_buff > *skb, > struct genl_info *info) > { > struct devlink_flash_update_params params = {}; > + struct nlattr *nla_component, *nla_overwrite; > struct devlink *devlink = info->user_ptr[0]; > - struct nlattr *nla_component; > u32 supported_params; > > if (!devlink->ops->flash_update) > @@ -3149,6 +3149,19 @@ static int devlink_nl_cmd_flash_update(struct sk_buff > *skb, > params.component = nla_data(nla_component); > } > > + nla_overwrite = info->attrs[DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK]; > + if (nla_overwrite) { > + struct nla_bitfield32 sections; > + > + if (!(supported_params & > DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK)) { > + NL_SET_ERR_MSG_ATTR(info->extack, nla_overwrite, > + "overwrite is not supported"); settings ... by this device ? > + return -EOPNOTSUPP; > + } > + sections = nla_get_bitfield32(nla_overwrite); > + params.overwrite_mask = sections.value & sections.selector;