From patchwork Wed May 25 22:43:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 97435 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 35BE2B6F98 for ; Thu, 26 May 2011 08:43:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755761Ab1EYWnv (ORCPT ); Wed, 25 May 2011 18:43:51 -0400 Received: from smtp-out.google.com ([74.125.121.67]:53113 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755630Ab1EYWnu (ORCPT ); Wed, 25 May 2011 18:43:50 -0400 Received: from wpaz1.hot.corp.google.com (wpaz1.hot.corp.google.com [172.24.198.65]) by smtp-out.google.com with ESMTP id p4PMhksh004374; Wed, 25 May 2011 15:43:46 -0700 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1306363427; bh=AgjuKiwyzbntzUgao+m2hVdEZpc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=XV16zqeFyx5EXca05plELXivGc+8xWmVJLQNDpL94rEqhFUpIJ5PDKYmPy3vEilvP LGG+Zd9x5P6Qxgu8Iqexg== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=aqXIzWjTAhMFWTA7Hn7sTAJ6kk9mRtqtcHNHN6zfTfXIn4QW/SwrOhOhgntztSW6+ NV6EyLAba+oIAygaqmNcQ== Received: from linuxrus.mtv.corp.google.com (linuxrus.mtv.corp.google.com [172.18.96.111]) by wpaz1.hot.corp.google.com with ESMTP id p4PMhip4025919; Wed, 25 May 2011 15:43:44 -0700 Received: by linuxrus.mtv.corp.google.com (Postfix, from userid 109155) id 6BCA8C3C25; Wed, 25 May 2011 15:43:44 -0700 (PDT) From: Mahesh Bandewar To: David Miller Cc: netdev , Mahesh Bandewar , Tom Herbert , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Stephen Hemminger Subject: [PATCHv3] net: Abstract features usage. Date: Wed, 25 May 2011 15:43:42 -0700 Message-Id: <1306363422-13692-1-git-send-email-maheshb@google.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1306288544-1700-1-git-send-email-maheshb@google.com> References: <1306288544-1700-1-git-send-email-maheshb@google.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- Changes since v2: Added the include which accidently went into the other patch. Changes since v1: Split the patch into two pieces. include/linux/netdev_features.h | 64 +++++++++++++++++++++++++++++++++++++++ include/linux/netdevice.h | 9 +++++ 2 files changed, 73 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 9bb5872..ca31706 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -51,6 +51,7 @@ #ifdef CONFIG_DCB #include #endif +#include struct vlan_group; struct netpoll_info; @@ -1078,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(NETIF_F_SG_BIT)