aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/mv643xx_eth.c
diff options
context:
space:
mode:
authorLennert Buytenhek <buytenh@wantstofly.org>2008-06-01 05:43:32 -0400
committerLennert Buytenhek <buytenh@wantstofly.org>2008-06-12 02:40:33 -0400
commit69876569bbf3dfac567f47c619888c827cb87b30 (patch)
tree7605c046ba3c5be284c782d8b41496a89673f548 /drivers/net/mv643xx_eth.c
parent16820054773027a9be2e2b5e33eb2015d32deeaf (diff)
mv643xx_eth: massively simplify multicast address crc8 computation
Replace the 70-line crc8 computation (used for multicast address filtering tables) by a 5-line version. Signed-off-by: Lennert Buytenhek <buytenh@marvell.com> Acked-by: Dale Farnsworth <dale@farnsworth.org>
Diffstat (limited to 'drivers/net/mv643xx_eth.c')
-rw-r--r--drivers/net/mv643xx_eth.c95
1 files changed, 21 insertions, 74 deletions
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index cc93af002013..84e6c41becde 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -1141,16 +1141,29 @@ static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr)
1141 return 0; 1141 return 0;
1142} 1142}
1143 1143
1144static int addr_crc(unsigned char *addr)
1145{
1146 int crc = 0;
1147 int i;
1148
1149 for (i = 0; i < 6; i++) {
1150 int j;
1151
1152 crc = (crc ^ addr[i]) << 8;
1153 for (j = 7; j >= 0; j--) {
1154 if (crc & (0x100 << j))
1155 crc ^= 0x107 << j;
1156 }
1157 }
1158
1159 return crc;
1160}
1161
1144static void mc_addr(struct mv643xx_eth_private *mp, unsigned char *addr) 1162static void mc_addr(struct mv643xx_eth_private *mp, unsigned char *addr)
1145{ 1163{
1146 unsigned int port_num = mp->port_num; 1164 unsigned int port_num = mp->port_num;
1147 unsigned int mac_h;
1148 unsigned int mac_l;
1149 unsigned char crc_result = 0;
1150 int table; 1165 int table;
1151 int mac_array[48]; 1166 int crc;
1152 int crc[8];
1153 int i;
1154 1167
1155 if ((addr[0] == 0x01) && (addr[1] == 0x00) && 1168 if ((addr[0] == 0x01) && (addr[1] == 0x00) &&
1156 (addr[2] == 0x5E) && (addr[3] == 0x00) && (addr[4] == 0x00)) { 1169 (addr[2] == 0x5E) && (addr[3] == 0x00) && (addr[4] == 0x00)) {
@@ -1159,76 +1172,10 @@ static void mc_addr(struct mv643xx_eth_private *mp, unsigned char *addr)
1159 return; 1172 return;
1160 } 1173 }
1161 1174
1162 /* Calculate CRC-8 out of the given address */ 1175 crc = addr_crc(addr);
1163 mac_h = (addr[0] << 8) | (addr[1]);
1164 mac_l = (addr[2] << 24) | (addr[3] << 16) |
1165 (addr[4] << 8) | (addr[5] << 0);
1166
1167 for (i = 0; i < 32; i++)
1168 mac_array[i] = (mac_l >> i) & 0x1;
1169 for (i = 32; i < 48; i++)
1170 mac_array[i] = (mac_h >> (i - 32)) & 0x1;
1171
1172 crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^
1173 mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^
1174 mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
1175 mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^
1176 mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0];
1177
1178 crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
1179 mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^
1180 mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
1181 mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^
1182 mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^
1183 mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
1184 mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0];
1185
1186 crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^
1187 mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^
1188 mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
1189 mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^
1190 mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^
1191 mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0];
1192
1193 crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
1194 mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^
1195 mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
1196 mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
1197 mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^
1198 mac_array[3] ^ mac_array[2] ^ mac_array[1];
1199
1200 crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^
1201 mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^
1202 mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
1203 mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^
1204 mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^
1205 mac_array[3] ^ mac_array[2];
1206
1207 crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^
1208 mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^
1209 mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
1210 mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^
1211 mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^
1212 mac_array[4] ^ mac_array[3];
1213
1214 crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^
1215 mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^
1216 mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
1217 mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^
1218 mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^
1219 mac_array[4];
1220
1221 crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^
1222 mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^
1223 mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
1224 mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^
1225 mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5];
1226
1227 for (i = 0; i < 8; i++)
1228 crc_result = crc_result | (crc[i] << i);
1229 1176
1230 table = OTHER_MCAST_TABLE(port_num); 1177 table = OTHER_MCAST_TABLE(port_num);
1231 set_filter_table_entry(mp, table, crc_result); 1178 set_filter_table_entry(mp, table, crc);
1232} 1179}
1233 1180
1234static void set_multicast_list(struct net_device *dev) 1181static void set_multicast_list(struct net_device *dev)