From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5F2BC43381 for ; Fri, 15 Feb 2019 08:53:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC96F204EC for ; Fri, 15 Feb 2019 08:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391632AbfBOIxS (ORCPT ); Fri, 15 Feb 2019 03:53:18 -0500 Received: from mx2.suse.de ([195.135.220.15]:55084 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727777AbfBOIxR (ORCPT ); Fri, 15 Feb 2019 03:53:17 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BFB81AF3A; Fri, 15 Feb 2019 08:53:16 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 36285E0139; Fri, 15 Feb 2019 09:53:15 +0100 (CET) Date: Fri, 15 Feb 2019 09:53:15 +0100 From: Michal Kubecek To: netdev@vger.kernel.org Cc: Jakub Kicinski , davem@davemloft.net, jiri@resnulli.us, oss-drivers@netronome.com, andrew@lunn.ch Subject: Re: [PATCH net-next 2/3] ethtool: add compat for flash update Message-ID: <20190215085315.GL25518@unicorn.suse.cz> References: <20190214214046.19182-1-jakub.kicinski@netronome.com> <20190214214046.19182-3-jakub.kicinski@netronome.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190214214046.19182-3-jakub.kicinski@netronome.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Feb 14, 2019 at 01:40:45PM -0800, Jakub Kicinski wrote: > If driver does not support ethtool flash update operation > call into devlink. > > Signed-off-by: Jakub Kicinski > --- ... > diff --git a/net/core/devlink.c b/net/core/devlink.c > index bd507e13bb7b..d169b5426d3d 100644 > --- a/net/core/devlink.c > +++ b/net/core/devlink.c > @@ -6435,6 +6435,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); We already have similar lookup in devlink_compat_running_version() (the only difference seems to be that we keep holding devlink_mutex until the end there) and it's likely the net_device -> devlink lookup will be needed in more places in the future. How about having a helper for it? I also wonder how does the lookup scale. But I don't have clear idea how long the lists can become in real life and the ethtool operations are not really time critical. Michal Kubecek