| 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 |
| 5 | condition. |
| 6 | |
| 7 | This patch fixes the following issues with the r6040 NIC operating in |
| 8 | multicast: |
| 9 | |
| 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. |
| 12 | |
| 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}. |
| 15 | |
| 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). |
| 19 | |
| 20 | 4) If necessary, we should set HASH_EN flag in MCR0 to enable multicast |
| 21 | hash table function. |
| 22 | |
| 23 | |
| 24 | The version is for net-next-2.6: |
| 25 | |
| 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> |
| 30 | --- |
| 31 | --- a/drivers/net/r6040.c |
| 32 | +++ b/drivers/net/r6040.c |
| 33 | @@ -70,6 +70,8 @@ |
| 34 | |
| 35 | /* MAC registers */ |
| 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 |
| 43 | { |
| 44 | struct r6040_private *lp = netdev_priv(dev); |
| 45 | void __iomem *ioaddr = lp->base; |
| 46 | - u16 *adrp; |
| 47 | - u16 reg; |
| 48 | unsigned long flags; |
| 49 | struct dev_mc_list *dmi = dev->mc_list; |
| 50 | int i; |
| 51 | + u16 hash_table[4] = { 0 }; |
| 52 | |
| 53 | - /* MAC Address */ |
| 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); |
| 58 | - |
| 59 | - /* Promiscous Mode */ |
| 60 | spin_lock_irqsave(&lp->lock, flags); |
| 61 | |
| 62 | /* Clear AMCP & PROM bits */ |
| 63 | - reg = ioread16(ioaddr) & ~0x0120; |
| 64 | + lp->mcr0 = ioread16(ioaddr + MCR0) & ~(PROMISC | HASH_EN); |
| 65 | + |
| 66 | + /* Promiscuous mode */ |
| 67 | if (dev->flags & IFF_PROMISC) { |
| 68 | - reg |= 0x0020; |
| 69 | - lp->mcr0 |= 0x0020; |
| 70 | + lp->mcr0 |= PROMISC; |
| 71 | } |
| 72 | - /* Too many multicast addresses |
| 73 | - * accept all traffic */ |
| 74 | - else if ((dev->mc_count > MCAST_MAX) |
| 75 | - || (dev->flags & IFF_ALLMULTI)) |
| 76 | - reg |= 0x0020; |
| 77 | |
| 78 | - iowrite16(reg, ioaddr); |
| 79 | - spin_unlock_irqrestore(&lp->lock, flags); |
| 80 | - |
| 81 | - /* Build the hash table */ |
| 82 | - if (dev->mc_count > MCAST_MAX) { |
| 83 | - u16 hash_table[4]; |
| 84 | - u32 crc; |
| 85 | + /* Enable multicast hash table function to |
| 86 | + * receive all multicast packets. */ |
| 87 | + else if (dev->flags & IFF_ALLMULTI) { |
| 88 | + lp->mcr0 |= HASH_EN; |
| 89 | + |
| 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); |
| 94 | + } |
| 95 | |
| 96 | for (i = 0; i < 4; i++) |
| 97 | - hash_table[i] = 0; |
| 98 | + hash_table[i] = 0xffff; |
| 99 | + } |
| 100 | |
| 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) { |
| 106 | + i = 0; |
| 107 | + while (i < dev->mc_count) { |
| 108 | + u16 *adrp = (u16 *)dmi->dmi_addr; |
| 109 | |
| 110 | dmi = dmi->next; |
| 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); |
| 114 | + i++; |
| 115 | + } |
| 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); |
| 120 | + i++; |
| 121 | + } |
| 122 | + } |
| 123 | + /* Otherwise, Enable multicast hash table function. */ |
| 124 | + else { |
| 125 | + u32 crc; |
| 126 | |
| 127 | - if (!(*addrs & 1)) |
| 128 | - continue; |
| 129 | + lp->mcr0 |= HASH_EN; |
| 130 | |
| 131 | - crc = ether_crc_le(6, addrs); |
| 132 | - crc >>= 26; |
| 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); |
| 138 | } |
| 139 | - /* Fill the MAC hash tables with their values */ |
| 140 | + |
| 141 | + /* Build multicast hash table */ |
| 142 | + for (i = 0; i < dev->mc_count; i++) { |
| 143 | + u8 *addrs = dmi->dmi_addr; |
| 144 | + dmi = dmi->next; |
| 145 | + |
| 146 | + crc = ether_crc(ETH_ALEN, addrs); |
| 147 | + hash_table[crc >> 4] |= 1 << (crc & 0xf); |
| 148 | + } |
| 149 | + } |
| 150 | + iowrite16(lp->mcr0, ioaddr + MCR0); |
| 151 | + |
| 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); |
| 158 | } |
| 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); |
| 166 | - dmi = dmi->next; |
| 167 | - } |
| 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); |
| 172 | - } |
| 173 | + |
| 174 | + spin_unlock_irqrestore(&lp->lock, flags); |
| 175 | } |
| 176 | |
| 177 | static void netdev_get_drvinfo(struct net_device *dev, |
| 178 | |