From patchwork Wed Sep 29 12:00:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 1534353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=rs/XvNYx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKFMP5dFdz9ssD for ; Wed, 29 Sep 2021 22:01:05 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 1549660BAF; Wed, 29 Sep 2021 12:01:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SeQi-49Kwxwd; Wed, 29 Sep 2021 12:01:02 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 1036D60BBB; Wed, 29 Sep 2021 12:01:02 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 40FD91BF2F6 for ; Wed, 29 Sep 2021 12:00:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 2F913827B1 for ; Wed, 29 Sep 2021 12:00:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MWxkBU1YfoYm for ; Wed, 29 Sep 2021 12:00:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp1.osuosl.org (Postfix) with ESMTPS id 928D982FE4 for ; Wed, 29 Sep 2021 12:00:58 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F75561414; Wed, 29 Sep 2021 12:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632916858; bh=sWOMc53F6fyjiBJQ3ELzEBwFAXedaQQqVi7cxDeJKLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rs/XvNYxmfzCfL9jh91wFmivkm84vokPpMn/jA+yIEPJXh+T0IRl7w5dJyY6tHPX8 Spof3xyYVDwokJtnoqfRfDVC35T8dDtJlCZ0CcXK3XoIcFVUDR1CYuUzaUJAjkecru 15O0f1m9pRiLpiZuMaU7nSSoSd5Yh8UzS4Ioy4/kIpTuxaa/aZEl92wcdYJWHlDwsS 8h2TCijNo0rJfapU0b+HI+hfEji8mA7wK+HwJqQLgiG9q71uRANLbC4nY+RqjENwFL OR1ZxPGIB4JYvN2pGlck1ysSDYcDwQh4wMkYJnGejtJlttb3ipc/7uPP+ppTXYrHJE 1axdAYORcnFLw== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Date: Wed, 29 Sep 2021 15:00:44 +0300 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Intel-wired-lan] [PATCH net-next v1 3/5] devlink: Allow set specific ops callbacks dynamically X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , Alexandre Belloni , Simon Horman , oss-drivers@corigine.com, netdev@vger.kernel.org, Jerin Jacob , GR-everest-linux-l2@marvell.com, Subbaraya Sundeep , Ioana Ciornei , Leon Romanovsky , Michael Chan , Linu Cherian , Tariq Toukan , Florian Fainelli , Eric Dumazet , linux-rdma@vger.kernel.org, Moshe Shemesh , linux-staging@lists.linux.dev, Shannon Nelson , intel-wired-lan@lists.osuosl.org, Vadym Kochan , Yisen Zhuang , Vivien Didelot , Sunil Goutham , Ariel Elior , Ido Schimmel , Richard Cochran , Satanand Burla , Felix Manlunas , Claudiu Manoil , Jiri Pirko , drivers@pensando.io, linux-omap@vger.kernel.org, Bin Luo , Salil Mehta , GR-Linux-NIC-Dev@marvell.com, Manish Chopra , Greg Kroah-Hartman , Vladimir Oltean , linux-kernel@vger.kernel.org, Coiby Xu , UNGLinuxDriver@microchip.com, Taras Chornyi , hariprasad , Shay Drory , Jonathan Lemon , Derek Chickles , Saeed Mahameed , Geetha sowjanya Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" From: Leon Romanovsky Introduce new devlink call to set specific ops callback during device initialization phase after devlink_alloc() is already called. This allows us to set reload_* specific ops based on device property which sometimes is known almost at the end of driver initialization. For the sake of simplicity, this API lacks any type of locking and needs to be called before devlink_register() to make sure that no parallel access to the ops is possible at this stage. Signed-off-by: Leon Romanovsky --- include/net/devlink.h | 1 + net/core/devlink.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 317b09917c41..305be548ac21 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1565,6 +1565,7 @@ static inline struct devlink *devlink_alloc(struct devlink_ops *ops, { return devlink_alloc_ns(ops, priv_size, &init_net, dev); } +void devlink_set_ops(struct devlink *devlink, struct devlink_ops *ops); void devlink_register(struct devlink *devlink); void devlink_unregister(struct devlink *devlink); void devlink_reload_enable(struct devlink *devlink); diff --git a/net/core/devlink.c b/net/core/devlink.c index 9ae38128d6e1..67a846d424b7 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -8906,6 +8906,43 @@ static bool devlink_reload_actions_valid(struct devlink_ops *ops) return true; } +/** + * devlink_set_ops - Set devlink ops dynamically + * + * @devlink: devlink + * @ops: devlink ops to set + * + * This interface allows us to set ops based on device property + * which is known after devlink_alloc() was already called. For now, + * it is applicable for reload_* assignments only and all other + * callbacks are ignored. + * + * It should be called before devlink_register(), so doesn't have any + * protection from concurent access. + */ +void devlink_set_ops(struct devlink *devlink, struct devlink_ops *ops) +{ + struct devlink_ops *dev_ops = devlink->ops; + + WARN_ON(!devlink_reload_actions_valid(ops)); + +#define SET_DEVICE_OP(ptr, op, name) \ + do { \ + if ((op)->name) \ + if (!((ptr)->name)) \ + (ptr)->name = (op)->name; \ + } while (0) + + /* Keep sorted */ + SET_DEVICE_OP(dev_ops, ops, reload_actions); + SET_DEVICE_OP(dev_ops, ops, reload_down); + SET_DEVICE_OP(dev_ops, ops, reload_limits); + SET_DEVICE_OP(dev_ops, ops, reload_up); + +#undef SET_DEVICE_OP +} +EXPORT_SYMBOL_GPL(devlink_set_ops); + /** * devlink_alloc_ns - Allocate new devlink instance resources * in specific namespace @@ -8926,8 +8963,6 @@ struct devlink *devlink_alloc_ns(struct devlink_ops *ops, size_t priv_size, int ret; WARN_ON(!ops || !dev); - if (!devlink_reload_actions_valid(ops)) - return NULL; devlink = kzalloc(sizeof(*devlink) + priv_size, GFP_KERNEL); if (!devlink) @@ -8942,6 +8977,8 @@ struct devlink *devlink_alloc_ns(struct devlink_ops *ops, size_t priv_size, devlink->dev = dev; devlink->ops = ops; + /* To check validity of reload actions */ + devlink_set_ops(devlink, ops); xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC); write_pnet(&devlink->_net, net); INIT_LIST_HEAD(&devlink->port_list);