From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, vivien.didelot@savoirfairelinux.com,
andrew@lunn.ch, jiri@resnulli.us, marcelo.leitner@gmail.com,
Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next v2 1/4] net: switchdev: Prepare for deferred functions modifying objects
Date: Mon, 9 Jan 2017 12:45:20 -0800 [thread overview]
Message-ID: <20170109204523.5843-2-f.fainelli@gmail.com> (raw)
In-Reply-To: <20170109204523.5843-1-f.fainelli@gmail.com>
In preparation for adding support for deferred dump operations, allow
specifying a deferred function whose signature allows read/write
objects.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/switchdev/switchdev.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 017801f9dbaa..3d70ad02c617 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -100,11 +100,14 @@ static DEFINE_SPINLOCK(deferred_lock);
typedef void switchdev_deferred_func_t(struct net_device *dev,
const void *data);
+typedef void switchdev_deferred_func_rw_t(struct net_device *dev,
+ void *data);
struct switchdev_deferred_item {
struct list_head list;
struct net_device *dev;
switchdev_deferred_func_t *func;
+ switchdev_deferred_func_rw_t *func_rw;
unsigned long data[0];
};
@@ -138,7 +141,10 @@ void switchdev_deferred_process(void)
ASSERT_RTNL();
while ((dfitem = switchdev_deferred_dequeue())) {
- dfitem->func(dfitem->dev, dfitem->data);
+ if (dfitem->func)
+ dfitem->func(dfitem->dev, dfitem->data);
+ else if (dfitem->func_rw)
+ dfitem->func_rw(dfitem->dev, dfitem->data);
dev_put(dfitem->dev);
kfree(dfitem);
}
@@ -156,7 +162,8 @@ static DECLARE_WORK(deferred_process_work, switchdev_deferred_process_work);
static int switchdev_deferred_enqueue(struct net_device *dev,
const void *data, size_t data_len,
- switchdev_deferred_func_t *func)
+ switchdev_deferred_func_t *func,
+ switchdev_deferred_func_rw_t *func_rw)
{
struct switchdev_deferred_item *dfitem;
@@ -165,6 +172,7 @@ static int switchdev_deferred_enqueue(struct net_device *dev,
return -ENOMEM;
dfitem->dev = dev;
dfitem->func = func;
+ dfitem->func_rw = func_rw;
memcpy(dfitem->data, data, data_len);
dev_hold(dev);
spin_lock_bh(&deferred_lock);
@@ -312,7 +320,8 @@ static int switchdev_port_attr_set_defer(struct net_device *dev,
const struct switchdev_attr *attr)
{
return switchdev_deferred_enqueue(dev, attr, sizeof(*attr),
- switchdev_port_attr_set_deferred);
+ switchdev_port_attr_set_deferred,
+ NULL);
}
/**
@@ -441,7 +450,8 @@ static int switchdev_port_obj_add_defer(struct net_device *dev,
const struct switchdev_obj *obj)
{
return switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj),
- switchdev_port_obj_add_deferred);
+ switchdev_port_obj_add_deferred,
+ NULL);
}
/**
@@ -511,7 +521,8 @@ static int switchdev_port_obj_del_defer(struct net_device *dev,
const struct switchdev_obj *obj)
{
return switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj),
- switchdev_port_obj_del_deferred);
+ switchdev_port_obj_del_deferred,
+ NULL);
}
/**
--
2.9.3
next prev parent reply other threads:[~2017-01-09 20:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-09 20:45 [PATCH net-next v2 0/4] net: switchdev: Avoid sleep in atomic with DSA Florian Fainelli
2017-01-09 20:45 ` Florian Fainelli [this message]
2017-01-10 10:09 ` [PATCH net-next v2 1/4] net: switchdev: Prepare for deferred functions modifying objects Jiri Pirko
2017-01-10 17:57 ` Florian Fainelli
2017-01-09 20:45 ` [PATCH net-next v2 2/4] net: switchdev: Add object dump deferred operation Florian Fainelli
2017-01-09 20:45 ` [PATCH net-next v2 3/4] net: switchdev: Add switchdev_port_bridge_getlink_deferred Florian Fainelli
2017-01-09 20:45 ` [PATCH net-next v2 4/4] net: dsa: Utilize switchdev_port_bridge_getlink_deferred() Florian Fainelli
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=20170109204523.5843-2-f.fainelli@gmail.com \
--to=f.fainelli@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=jiri@resnulli.us \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@savoirfairelinux.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).