netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mahesh Bandewar <maheshb@google.com>
To: David Miller <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>,
	"Mahesh Bandewar" <maheshb@google.com>,
	"Tom Herbert" <therbert@google.com>,
	"Michał Mirosław" <mirqus@gmail.com>,
	"Stephen Hemminger" <shemminger@vyatta.com>
Subject: [PATCHv2] net: Abstract features usage.
Date: Tue, 24 May 2011 18:55:44 -0700	[thread overview]
Message-ID: <1306288544-1700-1-git-send-email-maheshb@google.com> (raw)
In-Reply-To: <1306263162-2022-1-git-send-email-maheshb@google.com>

Define macros to set/clear/test bits for feature set usage. This will eliminate
the direct use of these fields and enable future ease in managing these fields.

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
---
Changes since v1:
 Split the patch into two pieces.

 include/linux/netdev_features.h |   64 +++++++++++++++++++++++++++++++++++++++
 include/linux/netdevice.h       |    8 +++++
 2 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/netdev_features.h

diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h
new file mode 100644
index 0000000..3043c4d
--- /dev/null
+++ b/include/linux/netdev_features.h
@@ -0,0 +1,64 @@
+#ifndef _NETDEV_FEATURES_H
+#define _NETDEV_FEATURES_H
+
+/* Forward declarations */
+struct net_device;
+
+typedef unsigned long *nd_feature_t;
+
+static inline void _nd_set_feature(u32 *old_field,
+		unsigned long *new_field, int bit)
+{
+	if (bit < 32)
+		*old_field |= (1 << bit);
+	set_bit(bit, new_field);
+}
+
+static inline void _nd_clear_feature(u32 *old_field,
+		unsigned long *new_field, int bit)
+{
+	if (bit < 32)
+		*old_field &= ~(1 << bit);
+
+	clear_bit(bit, new_field);
+}
+
+static inline bool _nd_test_feature(u32 old_field,
+		unsigned long *new_field, int bit)
+{
+	if (bit < 32)
+		return (old_field & (1 << bit)) == 1;	
+
+	return test_bit(bit, new_field) == 1;
+}
+
+#define netdev_set_active_feature(dev, bit)	\
+	_nd_set_feature(&(dev)->features, (dev)->active_feature, (bit))
+#define netdev_clear_active_feature(dev, bit)	\
+	_nd_clear_feature(&(dev)->features, (dev)->active_feature, (bit))
+#define netdev_test_active_feature(dev, bit)	\
+	_nd_test_feature((dev)->features, (dev)->active_feature, (bit))
+
+#define netdev_set_offered_feature(dev, bit)	\
+	_nd_set_feature(&(dev)->hw_features, (dev)->offered_feature, (bit))
+#define netdev_clear_offered_feature(dev, bit)	\
+	_nd_clear_feature(&(dev)->hw_features, (dev)->offered_feature, (bit))
+#define netdev_test_offered_feature(dev, bit)	\
+	_nd_test_feature((dev)->hw_features, (dev)->offered_feature, (bit))
+
+#define netdev_set_vlan_feature(dev, bit)	\
+	_nd_set_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit))
+#define netdev_clear_vlan_feature(dev, bit)	\
+	_nd_clear_feature(&(dev)->vlan_features, (dev)->vlan_feature, (bit))
+#define netdev_test_vlan_feature(dev, bit)	\
+	_nd_test_feature((dev)->vlan_features, (dev)->vlan_feature, (bit))
+
+#define netdev_set_wanted_feature(dev, bit)	\
+	_nd_set_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit))
+#define netdev_clear_wanted_feature(dev, bit)	\
+	_nd_clear_feature(&(dev)->wanted_features, (dev)->wanted_feature, (bit))
+#define netdev_test_wanted_feature(dev, bit)	\
+	_nd_test_feature((dev)->wanted_features, (dev)->wanted_feature, (bit))
+
+
+#endif	/* __NETDEV_FEATURES_H */
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index b4520b2..e565ceb 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1079,6 +1079,14 @@ struct net_device {
 	/* mask of features inheritable by VLAN devices */
 	u32			vlan_features;
 
+#define DEV_FEATURE_WORDS	BITS_TO_LONGS(ND_FEATURE_NUM_BITS)
+#define DEV_FEATURE_BITS	(DEV_FEATURE_WORDS * BITS_PER_LONG)
+
+	DECLARE_BITMAP(active_feature, DEV_FEATURE_BITS);
+	DECLARE_BITMAP(offered_feature, DEV_FEATURE_BITS);
+	DECLARE_BITMAP(wanted_feature, DEV_FEATURE_BITS);
+	DECLARE_BITMAP(vlan_feature, DEV_FEATURE_BITS);
+
 #define BIT2FLAG(bit)		(1 << (bit))
 
 #define NETIF_F_SG		BIT2FLAG(SG_BIT)
-- 
1.7.3.1


  parent reply	other threads:[~2011-05-25  1:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24 18:52 [PATCH] net: Abstract features usage Mahesh Bandewar
2011-05-24 19:37 ` Michał Mirosław
2011-05-24 20:29   ` Mahesh Bandewar
2011-05-24 21:49     ` Michał Mirosław
2011-05-24 23:11       ` Mahesh Bandewar
2011-05-24 21:29 ` Stephen Hemminger
2011-05-24 23:04   ` Mahesh Bandewar
2011-05-24 23:11     ` Stephen Hemminger
2011-05-24 23:25       ` Mahesh Bandewar
2011-05-25  1:55 ` Mahesh Bandewar [this message]
2011-05-25 22:43   ` [PATCHv3] " Mahesh Bandewar
2011-05-25  1:56 ` [PATCHv2] net: Define enum for the bits used in features Mahesh Bandewar
2011-05-25  7:58   ` Hagen Paul Pfeifer
2011-05-25  9:43   ` Michał Mirosław
2011-05-25  9:48     ` Michał Mirosław
2011-05-25 18:05     ` Mahesh Bandewar
2011-05-25 22:42   ` [PATCHv3] " Mahesh Bandewar
2011-05-26 10:40     ` Michał Mirosław
2011-05-27  9:25     ` [RFC PATCH] net: ethtool: use C99 array initialization for feature-names table Michał Mirosław
2011-06-04 20:34     ` [PATCHv3] net: Define enum for the bits used in features David Miller
2011-06-06  3:58       ` Michael S. Tsirkin
2011-06-06  5:15         ` David Miller
2011-06-06 15:32           ` Michael S. Tsirkin
2011-06-06 19:20             ` David Miller
2011-06-06 20:35               ` Michael S. Tsirkin
2011-06-09 16:46                 ` Michael S. Tsirkin
2011-06-09 20:12                   ` Michael S. Tsirkin
2011-06-08  6:55               ` Mahesh Bandewar
2011-06-06 15:48       ` Michał Mirosław

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=1306288544-1700-1-git-send-email-maheshb@google.com \
    --to=maheshb@google.com \
    --cc=davem@davemloft.net \
    --cc=mirqus@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    --cc=therbert@google.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).