Skip to content

Commit

Permalink
ethtool: add compat for flash update
Browse files Browse the repository at this point in the history
If driver does not support ethtool flash update operation
call into devlink.

Signed-off-by: Jakub Kicinski <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jakub Kicinski authored and davem330 committed Feb 17, 2019
1 parent 76726cc commit 4eceba1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/net/devlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -1195,11 +1195,18 @@ devlink_health_report(struct devlink_health_reporter *reporter,
#if IS_REACHABLE(CONFIG_NET_DEVLINK)
void devlink_compat_running_version(struct net_device *dev,
char *buf, size_t len);
int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
#else
static inline void
devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
{
}

static inline int
devlink_compat_flash_update(struct net_device *dev, const char *file_name)
{
return -EOPNOTSUPP;
}
#endif

#endif /* _NET_DEVLINK_H_ */
30 changes: 30 additions & 0 deletions net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -6450,6 +6450,36 @@ void devlink_compat_running_version(struct net_device *dev,
mutex_unlock(&devlink_mutex);
}

int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
{
struct devlink_port *devlink_port;
struct devlink *devlink;

mutex_lock(&devlink_mutex);
list_for_each_entry(devlink, &devlink_list, list) {
mutex_lock(&devlink->lock);
list_for_each_entry(devlink_port, &devlink->port_list, list) {
int ret = -EOPNOTSUPP;

if (devlink_port->type != DEVLINK_PORT_TYPE_ETH ||
devlink_port->type_dev != dev)
continue;

mutex_unlock(&devlink_mutex);
if (devlink->ops->flash_update)
ret = devlink->ops->flash_update(devlink,
file_name,
NULL, NULL);
mutex_unlock(&devlink->lock);
return ret;
}
mutex_unlock(&devlink->lock);
}
mutex_unlock(&devlink_mutex);

return -EOPNOTSUPP;
}

static int __init devlink_module_init(void)
{
return genl_register_family(&devlink_nl_family);
Expand Down
12 changes: 9 additions & 3 deletions net/core/ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2038,11 +2038,17 @@ static noinline_for_stack int ethtool_flash_device(struct net_device *dev,

if (copy_from_user(&efl, useraddr, sizeof(efl)))
return -EFAULT;
efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;

if (!dev->ethtool_ops->flash_device)
return -EOPNOTSUPP;
if (!dev->ethtool_ops->flash_device) {
int ret;

efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
rtnl_unlock();
ret = devlink_compat_flash_update(dev, efl.data);
rtnl_lock();

return ret;
}

return dev->ethtool_ops->flash_device(dev, &efl);
}
Expand Down

0 comments on commit 4eceba1

Please sign in to comment.