From patchwork Mon Feb 11 06:59:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 1039663 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="W/pGptXM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43yc9F4qpmz9s4Z for ; Mon, 11 Feb 2019 17:59:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726228AbfBKG7n (ORCPT ); Mon, 11 Feb 2019 01:59:43 -0500 Received: from mail-qk1-f169.google.com ([209.85.222.169]:41422 "EHLO mail-qk1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfBKG7m (ORCPT ); Mon, 11 Feb 2019 01:59:42 -0500 Received: by mail-qk1-f169.google.com with SMTP id u188so5817147qkh.8 for ; Sun, 10 Feb 2019 22:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QBjy8du5L20NuHE4fD0jMHDl8jerhAg/Q35MnqPk/V0=; b=W/pGptXMbGVpCrJ5f1p8e6l7DPaMtW+cpdYQm6WGJJAodiK5YvrgWCdz4tYnI/VuSY 9YPVprmIWgxy6UzqxNGU/7t41rR8nkXNduf78RiJpovCzAQtFvKGMv+vDmp3TVw9dS/A r/8oivlPqzzXoLACV77rk5dqOPSVMdNe2XcGKQPm/I7t/5a42gIB9C7A7dag34gh5Fg3 jLybkRJ7aMcFJWi0h26TCsTvUqiXcBE0V9uqJCI6GY6DSezO9GLlddj0rtOBs4sHwypL 6oJxGkKF6bRDKEwIPnFClm/MQsdBmf9puZ51KAsvsM8WoAYRDikISy056HuKL343iLXT kxMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QBjy8du5L20NuHE4fD0jMHDl8jerhAg/Q35MnqPk/V0=; b=gfvQo2NjU08OiD3v2rMpL1V6eP9XAhzCjlVeWwm0eCfacqkZmQbaInvJSciSwvoOGT b4KaplXRMgDRjKYZrkqztYzrxLSAcv4KIfaj12Q/5RfK3x6E5IES4HBaYYtDsNPJVHz2 WmNFMCzdNCVJchj1PUgg9jz7opnWUR2lterlRZ/PB0Gm281JTWODIn/ZicD+VJtMwtG9 h+HJ6mheG9YHtwAQy6rokjoCL6nvaaUyJZMyI6wlufx6+07ZZtfCysl2A8AP7pBrqKyh ki6sNTjktKk/mB/56YMbQnwwGZ9olTGnDfLCygx83zscBsoGAzvIZ3JFMC43w+ny+152 MW1A== X-Gm-Message-State: AHQUAuadmmLJKwdjnL0scblUPeSYk+WMfAzkGGn9m54Jpp3qfdzuR71R Psg6rbPcVF3kxVPRWDplWZa89A== X-Google-Smtp-Source: AHgI3Ia/ieW4Q8pjdxSDg2nb3qZXy9D90hJUykTRaFPOwhAGTYE3oVcehxHCnV/xxOsPgnF4GDzCqA== X-Received: by 2002:a37:b381:: with SMTP id c123mr24485462qkf.346.1549868381554; Sun, 10 Feb 2019 22:59:41 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id c68sm9677990qkf.65.2019.02.10.22.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 22:59:41 -0800 (PST) From: Jakub Kicinski To: davem@davemloft.net, jiri@resnulli.us Cc: netdev@vger.kernel.org, oss-drivers@netronome.com, mkubecek@suse.cz, andrew@lunn.ch, Jakub Kicinski Subject: [RFC 2/3] ethtool: add compat for flash update Date: Sun, 10 Feb 2019 22:59:21 -0800 Message-Id: <20190211065923.22670-3-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190211065923.22670-1-jakub.kicinski@netronome.com> References: <20190211065923.22670-1-jakub.kicinski@netronome.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If driver does not support ethtool flash update operation call into devlink. Signed-off-by: Jakub Kicinski --- include/net/devlink.h | 9 +++++++++ net/core/devlink.c | 31 +++++++++++++++++++++++++++++++ net/core/ethtool.c | 12 +++++++++--- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 55b3478b1291..8fdadd0a43ce 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1202,11 +1202,20 @@ 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, + u32 target); #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, + u32 target) +{ + return -EOPNOTSUPP; +} #endif #endif /* _NET_DEVLINK_H_ */ diff --git a/net/core/devlink.c b/net/core/devlink.c index a4b5e194e33e..fb1b0982281b 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -6435,6 +6435,37 @@ 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, + u32 target) +{ + 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, + target, 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); diff --git a/net/core/ethtool.c b/net/core/ethtool.c index d2c47cdf25da..389782ccd4c5 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -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, efl.region); + rtnl_lock(); + + return ret; + } return dev->ethtool_ops->flash_device(dev, &efl); }