netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Florian Fainelli" <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: amwang@redhat.com, jiri@resnulli.us, stephen@networkplumber.org,
	kaber@trash.net, davem@davemloft.net, vyasevic@redhat.com,
	johannes@sipsolutions.net, eric.dumazet@gmail.com,
	"Florian Fainelli" <f.fainelli@gmail.com>
Subject: [PATCH 1/3] net: add a new NETDEV_CHANGEROOM event type
Date: Tue, 20 Aug 2013 13:45:50 +0100	[thread overview]
Message-ID: <1377002752-4622-2-git-send-email-f.fainelli@gmail.com> (raw)
In-Reply-To: <1377002752-4622-1-git-send-email-f.fainelli@gmail.com>

The event NETDEV_CHANGEROOM event can be used by devices/subsystems
which need to adjust their needed_headroom and/or needed_tailroom
requirements dynamically. Two helper functions are introduced:

- dev_set_headroom(dev, new_headroom)
- dev_set_taioroom(dev, new_tailroom)

which will notify listeners of such a change.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 include/linux/netdevice.h |  3 +++
 net/core/dev.c            | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 077363d..2b3e56c 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1652,6 +1652,7 @@ struct packet_offload {
 #define NETDEV_JOIN		0x0014
 #define NETDEV_CHANGEUPPER	0x0015
 #define NETDEV_RESEND_IGMP	0x0016
+#define NETDEV_CHANGEROOM	0x0017 /* needed_headroom/tailroom change */
 
 extern int register_netdevice_notifier(struct notifier_block *nb);
 extern int unregister_netdevice_notifier(struct notifier_block *nb);
@@ -2329,6 +2330,8 @@ extern int		dev_change_net_namespace(struct net_device *,
 						 struct net *, const char *);
 extern int		dev_set_mtu(struct net_device *, int);
 extern void		dev_set_group(struct net_device *, int);
+extern int		dev_set_headroom(struct net_device *, unsigned short);
+extern int		dev_set_tailroom(struct net_device *, unsigned short);
 extern int		dev_set_mac_address(struct net_device *,
 					    struct sockaddr *);
 extern int		dev_change_carrier(struct net_device *,
diff --git a/net/core/dev.c b/net/core/dev.c
index 1ed2b66..be712be 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4931,6 +4931,52 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
 EXPORT_SYMBOL(dev_set_mtu);
 
 /**
+ *	dev_set_headroom - Change device needed headroom
+ *	@dev: device
+ *	@new_headroom: new headroom size
+ *
+ * 	Change the network device headroom space.
+ */
+int dev_set_headroom(struct net_device *dev, unsigned short new_headroom)
+{
+	if (dev->needed_headroom == new_headroom)
+		return 0;
+
+	if (!netif_device_present(dev))
+		return -ENODEV;
+
+	dev->needed_headroom = new_headroom;
+
+	call_netdevice_notifiers(NETDEV_CHANGEROOM, dev);
+
+	return 0;
+}
+EXPORT_SYMBOL(dev_set_headroom);
+
+/**
+ *	dev_set_tailroom - Change device needed tailroom
+ *	@dev: device
+ *	@new_tailroom: new tailroom size
+ *
+ * 	Change the network device tailroom space.
+ */
+int dev_set_tailroom(struct net_device *dev, unsigned short new_tailroom)
+{
+	if (dev->needed_tailroom == new_tailroom)
+		return 0;
+
+	if (!netif_device_present(dev))
+		return -ENODEV;
+
+	dev->needed_tailroom = new_tailroom;
+
+	call_netdevice_notifiers(NETDEV_CHANGEROOM, dev);
+
+	return 0;
+}
+EXPORT_SYMBOL(dev_set_tailroom);
+
+/**
  *	dev_set_group - Change group this device belongs to
  *	@dev: device
  *	@new_group: group this device should belong to
-- 
1.8.1.2

  reply	other threads:[~2013-08-20 12:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-20 12:45 [PATCH 0/3] net: propagate dynamic needed_headroom/tailroom changes Florian Fainelli
2013-08-20 12:45 ` Florian Fainelli [this message]
2013-08-20 15:16   ` [PATCH 1/3] net: add a new NETDEV_CHANGEROOM event type Johannes Berg
2013-08-20 15:30     ` Florian Fainelli
2013-08-20 16:10       ` Jiri Pirko
2013-08-20 16:35       ` Johannes Berg
2013-08-20 17:30         ` Florian Fainelli
2013-08-20 12:45 ` [PATCH 2/3] net: vlan: handle NETDEV_CHANGEROOM events Florian Fainelli
2013-08-20 12:45 ` [PATCH 3/3] net: bridge: handle NETDEV_CHANGEROOM event Florian Fainelli
2013-08-20 13:29 ` [PATCH 0/3] net: propagate dynamic needed_headroom/tailroom changes Jiri Pirko
2013-08-20 14:24   ` Florian Fainelli
2013-08-20 14:27     ` Jiri Pirko

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=1377002752-4622-2-git-send-email-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=amwang@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jiri@resnulli.us \
    --cc=johannes@sipsolutions.net \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=vyasevic@redhat.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).