From patchwork Tue Jan 26 14:57:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 43702 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 DAF07B7CCD for ; Wed, 27 Jan 2010 01:57:48 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753730Ab0AZO5n (ORCPT ); Tue, 26 Jan 2010 09:57:43 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752180Ab0AZO5n (ORCPT ); Tue, 26 Jan 2010 09:57:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18166 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441Ab0AZO5m (ORCPT ); Tue, 26 Jan 2010 09:57:42 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0QEvejI002194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Jan 2010 09:57:41 -0500 Received: from localhost (psychotron.englab.brq.redhat.com [10.34.32.135]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0QEvdFZ024020; Tue, 26 Jan 2010 09:57:40 -0500 Date: Tue, 26 Jan 2010 15:57:39 +0100 From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net Subject: [PATCH net-next-2.6] net: use helpers to access mc list Message-ID: <20100126145738.GA2537@psychotron.lab.eng.brq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch introduces the similar helpers as those already done for uc list. However multicast lists are no list_head lists but "mademanually". The three macros added by this patch will make the transition of mc_list to list_head smooth. From now on, drivers can (and should) use "netdev_for_each_mc_addr" to iterate over the addresses with iterator of type "struct netdev_hw_addr". Also macros "netdev_mc_count" and "netdev_mc_empty" to read list's length. This is the state which should be reached in all drivers. Temporary macro "netdev_for_each_mc_addr" works in the ugly way, I'm aware, but it will be replaced. It uses iterator stored in "struct net_device". In every iteration, it copies addr from the list to "struct netdev_hw_addr" instance (also stored in "struct net_device"). Driver reads address stored in this structure. All is protected by addr_list_lock held by a caller. Signed-off-by: Jiri Pirko --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 93a32a5..e470b22 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -268,6 +268,18 @@ struct netdev_hw_addr_list { #define netdev_for_each_uc_addr(ha, dev) \ list_for_each_entry(ha, &dev->uc.list, list) +#define netdev_mc_count(dev) ((dev)->mc_count) +#define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0) + +/* This is ugly, but only temporary. */ +#define netdev_for_each_mc_addr(ha, dev) \ + for ((dev)->tmp_mc_iter = (dev)->mc_list, \ + netdev_tmp_mc_addr_cpy(dev), \ + ha = &dev->tmp_mc_ha; \ + (dev)->tmp_mc_iter; \ + (dev)->tmp_mc_iter = (dev)->tmp_mc_iter->next, \ + netdev_tmp_mc_addr_cpy(dev)) + struct hh_cache { struct hh_cache *hh_next; /* Next entry */ atomic_t hh_refcnt; /* number of users */ @@ -820,6 +832,8 @@ struct net_device { mac addresses */ int uc_promisc; spinlock_t addr_list_lock; + struct netdev_hw_addr tmp_mc_ha; + struct dev_addr_list *tmp_mc_iter; struct dev_addr_list *mc_list; /* Multicast mac addresses */ int mc_count; /* Number of installed mcasts */ unsigned int promiscuity; @@ -953,6 +967,15 @@ struct net_device { #define NETDEV_ALIGN 32 +/* Used and to be used by netdev_for_each_mc_addr. This will disappear. */ +static inline void netdev_tmp_mc_addr_cpy(struct net_device *dev) +{ + if (dev->tmp_mc_iter) + memcpy(dev->tmp_mc_ha.addr, + dev->tmp_mc_iter->da_addr, + MAX_ADDR_LEN); +} + static inline struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, unsigned int index)