[PATCH 06/12] fec: refactor set_multicast_list() to make it more readable

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Sascha Hauer
Date: Wednesday, April 15, 2009 - 4:32 am

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fec.c |   99 +++++++++++++++++++++++++++-------------------------
 1 files changed, 51 insertions(+), 48 deletions(-)

diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index ab8e66b..b72df48 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -1518,57 +1518,60 @@ static void set_multicast_list(struct net_device *dev)
 		tmp = readl(fep->hwp + FEC_R_CNTRL);
 		tmp |= 0x8;
 		writel(tmp, fep->hwp + FEC_R_CNTRL);
-	} else {
-		tmp = readl(fep->hwp + FEC_R_CNTRL);
-		tmp &= ~0x8;
-		writel(tmp, fep->hwp + FEC_R_CNTRL);
+		return;
+	}
 
-		if (dev->flags & IFF_ALLMULTI) {
-			/* Catch all multicast addresses, so set the
-			 * filter to all 1's
-			 */
-			writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-			writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-		} else {
-			/* Clear filter and add the addresses in hash register
-			 */
-			writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-			writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-
-			dmi = dev->mc_list;
-
-			for (j = 0; j < dev->mc_count; j++, dmi = dmi->next) {
-				/* Only support group multicast for now */
-				if (!(dmi->dmi_addr[0] & 1))
-					continue;
-
-				/* calculate crc32 value of mac address */
-				crc = 0xffffffff;
-
-				for (i = 0; i < dmi->dmi_addrlen; i++) {
-					data = dmi->dmi_addr[i];
-					for (bit = 0; bit < 8; bit++, data >>= 1) {
-						crc = (crc >> 1) ^
-						(((crc ^ data) & 1) ? CRC32_POLY : 0);
-					}
-				}
-
-				/* only upper 6 bits (HASH_BITS) are used
-				 * which point to specific bit in he hash registers
-				 */
-				hash = (crc >> (32 - HASH_BITS)) & 0x3f;
-
-				if (hash > 31) {
-					tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-					tmp |= 1 << (hash - 32);
-					writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-				} else {
-					tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-					tmp |= 1 << hash;
-					writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-				}
+	tmp = readl(fep->hwp + FEC_R_CNTRL);
+	tmp &= ~0x8;
+	writel(tmp, fep->hwp + FEC_R_CNTRL);
+
+	if (dev->flags & IFF_ALLMULTI) {
+		/* Catch all multicast addresses, so set the
+		 * filter to all 1's
+		 */
+		writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
+		writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
+
+		return;
+	}
+
+	/* Clear filter and add the addresses in hash register
+	 */
+	writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
+	writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
+
+	dmi = dev->mc_list;
+
+	for (j = 0; j < dev->mc_count; j++, dmi = dmi->next) {
+		/* Only support group multicast for now */
+		if (!(dmi->dmi_addr[0] & 1))
+			continue;
+
+		/* calculate crc32 value of mac address */
+		crc = 0xffffffff;
+
+		for (i = 0; i < dmi->dmi_addrlen; i++) {
+			data = dmi->dmi_addr[i];
+			for (bit = 0; bit < 8; bit++, data >>= 1) {
+				crc = (crc >> 1) ^
+				(((crc ^ data) & 1) ? CRC32_POLY : 0);
 			}
 		}
+
+		/* only upper 6 bits (HASH_BITS) are used
+		 * which point to specific bit in he hash registers
+		 */
+		hash = (crc >> (32 - HASH_BITS)) & 0x3f;
+
+		if (hash > 31) {
+			tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
+			tmp |= 1 << (hash - 32);
+			writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
+		} else {
+			tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
+			tmp |= 1 << hash;
+			writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
+		}
 	}
 }
 
-- 
1.6.2.1

--
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
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] FEC driver: patches for -next, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 01/12] fec: remove unused ifdef, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 02/12] fec: switch to writel/readl, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 03/12] fec: do not typedef struct types, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 04/12] fec: remove unnecessary cast, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 05/12] fec: Codingstyle cleanups, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 06/12] fec: refactor set_multicast_list() to make i ..., Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 07/12] fec: refactor init function, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 08/12] fec: align receive packets, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 09/12] fec: remove debugging printks, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 10/12] fec: switch to net_device_ops, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 11/12] FEC Buffer rework, Sascha Hauer, (Wed Apr 15, 4:32 am)
[PATCH 12/12] fec: call fec_restart() in fec_open(), Sascha Hauer, (Wed Apr 15, 4:32 am)
Re: [PATCH] FEC driver: patches for -next, Greg Ungerer, (Wed Apr 15, 5:12 am)
Re: [PATCH] FEC driver: patches for -next, Sascha Hauer, (Wed Apr 15, 5:55 am)
Re: [PATCH 02/12] fec: switch to writel/readl, Sascha Hauer, (Wed Apr 15, 6:11 am)
Re: [PATCH 02/12] fec: switch to writel/readl, David Miller, (Thu Apr 16, 2:36 am)
Re: [PATCH 03/12] fec: do not typedef struct types, David Miller, (Thu Apr 16, 2:36 am)
Re: [PATCH 04/12] fec: remove unnecessary cast, David Miller, (Thu Apr 16, 2:36 am)
Re: [PATCH 05/12] fec: Codingstyle cleanups, David Miller, (Thu Apr 16, 2:36 am)
Re: [PATCH 07/12] fec: refactor init function, David Miller, (Thu Apr 16, 2:37 am)
Re: [PATCH 08/12] fec: align receive packets, David Miller, (Thu Apr 16, 2:37 am)
Re: [PATCH 09/12] fec: remove debugging printks, David Miller, (Thu Apr 16, 2:37 am)
Re: [PATCH 10/12] fec: switch to net_device_ops, David Miller, (Thu Apr 16, 2:37 am)
Re: [PATCH 11/12] FEC Buffer rework, David Miller, (Thu Apr 16, 2:38 am)
Re: [PATCH 12/12] fec: call fec_restart() in fec_open(), David Miller, (Thu Apr 16, 2:38 am)
Re: [PATCH 11/12] FEC Buffer rework, Greg Ungerer, (Fri Apr 17, 3:07 am)
Re: [PATCH 11/12] FEC Buffer rework, Sascha Hauer, (Fri Apr 17, 3:12 am)