linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: Leon Romanovsky <leonro@nvidia.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Andrew Lunn <andrew@lunn.ch>, Ariel Elior <aelior@marvell.com>,
	Bin Luo <luobin9@huawei.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Coiby Xu <coiby.xu@gmail.com>,
	Derek Chickles <dchickles@marvell.com>,
	drivers@pensando.io, Eric Dumazet <eric.dumazet@gmail.com>,
	Felix Manlunas <fmanlunas@marvell.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Geetha sowjanya <gakula@marvell.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	GR-everest-linux-l2@marvell.com, GR-Linux-NIC-Dev@marvell.com,
	hariprasad <hkelam@marvell.com>, Ido Schimmel <idosch@nvidia.com>,
	intel-wired-lan@lists.osuosl.org,
	Ioana Ciornei <ioana.ciornei@nxp.com>,
	Jerin Jacob <jerinj@marvell.com>,
	Jesse Brandeburg <jesse.brandeburg@intel.com>,
	Jiri Pirko <jiri@nvidia.com>,
	Jonathan Lemon <jonathan.lemon@gmail.com>,
	Linu Cherian <lcherian@marvell.com>,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-staging@lists.linux.dev,
	Manish Chopra <manishc@marvell.com>,
	Michael Chan <michael.chan@broadcom.com>,
	Moshe Shemesh <moshe@nvidia.com>,
	netdev@vger.kernel.org, oss-drivers@corigine.com,
	Richard Cochran <richardcochran@gmail.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Salil Mehta <salil.mehta@huawei.com>,
	Satanand Burla <sburla@marvell.com>,
	Shannon Nelson <snelson@pensando.io>,
	Shay Drory <shayd@nvidia.com>,
	Simon Horman <simon.horman@corigine.com>,
	Subbaraya Sundeep <sbhatta@marvell.com>,
	Sunil Goutham <sgoutham@marvell.com>,
	Taras Chornyi <tchornyi@marvell.com>,
	Tariq Toukan <tariqt@nvidia.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	UNGLinuxDriver@microchip.com, Vadym Kochan <vkochan@marvell.com>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Yisen Zhuang <yisen.zhuang@huawei.com>
Subject: [PATCH net-next v1 3/5] devlink: Allow set specific ops callbacks dynamically
Date: Wed, 29 Sep 2021 15:00:44 +0300	[thread overview]
Message-ID: <aac64d4861d6207a90a6d45245ee5ed59114659a.1632916329.git.leonro@nvidia.com> (raw)
In-Reply-To: <cover.1632916329.git.leonro@nvidia.com>

From: Leon Romanovsky <leonro@nvidia.com>

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 <leonro@nvidia.com>
---
 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);
-- 
2.31.1


  parent reply	other threads:[~2021-09-29 12:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 12:00 [PATCH net-next v1 0/5] Devlink reload and missed notifications fix Leon Romanovsky
2021-09-29 12:00 ` [PATCH net-next v1 1/5] devlink: Add missed notifications iterators Leon Romanovsky
2021-09-29 13:29   ` Vladimir Oltean
2021-09-29 12:00 ` [PATCH net-next v1 2/5] devlink: Allow modification of devlink ops Leon Romanovsky
2021-09-29 12:00 ` Leon Romanovsky [this message]
2021-09-29 12:25   ` [PATCH net-next v1 3/5] devlink: Allow set specific ops callbacks dynamically Greg Kroah-Hartman
2021-09-29 12:58     ` Leon Romanovsky
2021-09-29 12:00 ` [PATCH net-next v1 4/5] net/mlx5: Register separate reload devlink ops for multiport device Leon Romanovsky
2021-09-29 13:55   ` Jakub Kicinski
2021-09-29 14:16     ` Leon Romanovsky
2021-09-29 14:26       ` Jakub Kicinski
2021-09-29 14:31         ` Leon Romanovsky
2021-09-29 14:35           ` Jakub Kicinski
2021-09-29 15:24             ` Leon Romanovsky
2021-09-29 12:00 ` [PATCH net-next v1 5/5] devlink: Delete reload enable/disable interface Leon Romanovsky
2021-09-29 13:40 ` [PATCH net-next v1 0/5] Devlink reload and missed notifications fix Jakub Kicinski
2021-09-29 13:46   ` Vladimir Oltean
2021-09-29 13:56     ` Jakub Kicinski
2021-09-29 14:20       ` Leon Romanovsky
2021-09-29 14:13   ` Leon Romanovsky
2021-09-29 14:39     ` Jakub Kicinski
2021-09-29 15:31       ` Leon Romanovsky
2021-09-29 17:55         ` Jakub Kicinski
2021-09-29 19:11           ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aac64d4861d6207a90a6d45245ee5ed59114659a.1632916329.git.leonro@nvidia.com \
    --to=leon@kernel.org \
    --cc=GR-Linux-NIC-Dev@marvell.com \
    --cc=GR-everest-linux-l2@marvell.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=aelior@marvell.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=coiby.xu@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dchickles@marvell.com \
    --cc=drivers@pensando.io \
    --cc=eric.dumazet@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=fmanlunas@marvell.com \
    --cc=gakula@marvell.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkelam@marvell.com \
    --cc=idosch@nvidia.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=ioana.ciornei@nxp.com \
    --cc=jerinj@marvell.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=jiri@nvidia.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lcherian@marvell.com \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=luobin9@huawei.com \
    --cc=manishc@marvell.com \
    --cc=michael.chan@broadcom.com \
    --cc=moshe@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@corigine.com \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=salil.mehta@huawei.com \
    --cc=sbhatta@marvell.com \
    --cc=sburla@marvell.com \
    --cc=sgoutham@marvell.com \
    --cc=shayd@nvidia.com \
    --cc=simon.horman@corigine.com \
    --cc=snelson@pensando.io \
    --cc=tariqt@nvidia.com \
    --cc=tchornyi@marvell.com \
    --cc=vivien.didelot@gmail.com \
    --cc=vkochan@marvell.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=yisen.zhuang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).