1 The original code does not work well when the number of mulitcast
2 address to handle is greater than MCAST_MAX. It only enable promiscous
3 mode instead of multicast hash table mode, so the hash table function
4 will not be activated and all multicast frames will be recieved in this
7 This patch fixes the following issues with the r6040 NIC operating in
10 1) When the IFF_ALLMULTI flag is set, we should write 0xffff to the NIC
11 hash table registers to make it process multicast traffic.
13 2) When the number of multicast address to handle is smaller than
14 MCAST_MAX, we should use the NIC multicast registers MID1_{L,M,H}.
16 3) The hashing of the address was not correct, due to an invalid
17 substraction (15 - (crc & 0x0f)) instead of (crc & 0x0f) and an
18 incorrect crc algorithm (ether_crc_le) instead of (ether_crc).
20 4) If necessary, we should set HASH_EN flag in MCR0 to enable multicast
24 The version is for net-next-2.6:
26 Reported-by: Marc Leclerc <marc-leclerc@signaturealpha.com>
27 Tested-by: Marc Leclerc <marc-leclerc@signaturealpha.com>
28 Signed-off-by: Shawn Lin <shawn@dmp.com.tw>
29 Signed-off-by: Albert Chen <albert.chen@rdc.com.tw>
31 --- a/drivers/net/r6040.c
32 +++ b/drivers/net/r6040.c
36 #define MCR0 0x00 /* Control register 0 */
37 +#define PROMISC 0x0020 /* Promiscuous mode */
38 +#define HASH_EN 0x0100 /* Enable multicast hash table function */
39 #define MCR1 0x04 /* Control register 1 */
40 #define MAC_RST 0x0001 /* Reset the MAC */
41 #define MBCR 0x08 /* Bus control */
42 @@ -837,76 +839,88 @@ static void r6040_multicast_list(struct
44 struct r6040_private *lp = netdev_priv(dev);
45 void __iomem *ioaddr = lp->base;
49 struct dev_mc_list *dmi = dev->mc_list;
51 + u16 hash_table[4] = { 0 };
54 - adrp = (u16 *)dev->dev_addr;
55 - iowrite16(adrp[0], ioaddr + MID_0L);
56 - iowrite16(adrp[1], ioaddr + MID_0M);
57 - iowrite16(adrp[2], ioaddr + MID_0H);
59 - /* Promiscous Mode */
60 spin_lock_irqsave(&lp->lock, flags);
62 /* Clear AMCP & PROM bits */
63 - reg = ioread16(ioaddr) & ~0x0120;
64 + lp->mcr0 = ioread16(ioaddr + MCR0) & ~(PROMISC | HASH_EN);
66 + /* Promiscuous mode */
67 if (dev->flags & IFF_PROMISC) {
70 + lp->mcr0 |= PROMISC;
72 - /* Too many multicast addresses
73 - * accept all traffic */
74 - else if ((dev->mc_count > MCAST_MAX)
75 - || (dev->flags & IFF_ALLMULTI))
78 - iowrite16(reg, ioaddr);
79 - spin_unlock_irqrestore(&lp->lock, flags);
81 - /* Build the hash table */
82 - if (dev->mc_count > MCAST_MAX) {
85 + /* Enable multicast hash table function to
86 + * receive all multicast packets. */
87 + else if (dev->flags & IFF_ALLMULTI) {
88 + lp->mcr0 |= HASH_EN;
90 + for (i = 0; i < MCAST_MAX ; i++) {
91 + iowrite16(0, ioaddr + MID_1L + 8 * i);
92 + iowrite16(0, ioaddr + MID_1M + 8 * i);
93 + iowrite16(0, ioaddr + MID_1H + 8 * i);
96 for (i = 0; i < 4; i++)
98 + hash_table[i] = 0xffff;
101 - for (i = 0; i < dev->mc_count; i++) {
102 - char *addrs = dmi->dmi_addr;
103 + /* Use internal multicast address registers if the number of
104 + * multicast addresses is not greater than MCAST_MAX. */
105 + else if (dev->mc_count <= MCAST_MAX) {
107 + while (i < dev->mc_count) {
108 + u16 *adrp = (u16 *)dmi->dmi_addr;
111 + iowrite16(adrp[0], ioaddr + MID_1L + 8 * i);
112 + iowrite16(adrp[1], ioaddr + MID_1M + 8 * i);
113 + iowrite16(adrp[2], ioaddr + MID_1H + 8 * i);
116 + while (i < MCAST_MAX) {
117 + iowrite16(0, ioaddr + MID_1L + 8 * i);
118 + iowrite16(0, ioaddr + MID_1M + 8 * i);
119 + iowrite16(0, ioaddr + MID_1H + 8 * i);
123 + /* Otherwise, Enable multicast hash table function. */
129 + lp->mcr0 |= HASH_EN;
131 - crc = ether_crc_le(6, addrs);
133 - hash_table[crc >> 4] |= 1 << (15 - (crc & 0xf));
134 + for (i = 0; i < MCAST_MAX ; i++) {
135 + iowrite16(0, ioaddr + MID_1L + 8 * i);
136 + iowrite16(0, ioaddr + MID_1M + 8 * i);
137 + iowrite16(0, ioaddr + MID_1H + 8 * i);
139 - /* Fill the MAC hash tables with their values */
141 + /* Build multicast hash table */
142 + for (i = 0; i < dev->mc_count; i++) {
143 + u8 *addrs = dmi->dmi_addr;
146 + crc = ether_crc(ETH_ALEN, addrs);
147 + hash_table[crc >> 4] |= 1 << (crc & 0xf);
150 + iowrite16(lp->mcr0, ioaddr + MCR0);
152 + /* Fill the MAC hash tables with their values */
153 + if (lp->mcr0 && HASH_EN) {
154 iowrite16(hash_table[0], ioaddr + MAR0);
155 iowrite16(hash_table[1], ioaddr + MAR1);
156 iowrite16(hash_table[2], ioaddr + MAR2);
157 iowrite16(hash_table[3], ioaddr + MAR3);
159 - /* Multicast Address 1~4 case */
160 - dmi = dev->mc_list;
161 - for (i = 0, dmi; (i < dev->mc_count) && (i < MCAST_MAX); i++) {
162 - adrp = (u16 *)dmi->dmi_addr;
163 - iowrite16(adrp[0], ioaddr + MID_1L + 8*i);
164 - iowrite16(adrp[1], ioaddr + MID_1M + 8*i);
165 - iowrite16(adrp[2], ioaddr + MID_1H + 8*i);
168 - for (i = dev->mc_count; i < MCAST_MAX; i++) {
169 - iowrite16(0xffff, ioaddr + MID_1L + 8*i);
170 - iowrite16(0xffff, ioaddr + MID_1M + 8*i);
171 - iowrite16(0xffff, ioaddr + MID_1H + 8*i);
174 + spin_unlock_irqrestore(&lp->lock, flags);
177 static void netdev_get_drvinfo(struct net_device *dev,