Deleted Added
full compact
if_dc.c (121939) if_dc.c (122625)
1/*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 76 unchanged lines hidden (view full) ---

85 * All of the workalike chips use some form of MII transceiver support
86 * with the exception of the Macronix chips, which also have a SYM port.
87 * The ASIX AX88140A is also documented to have a SYM port, but all
88 * the cards I've seen use an MII transceiver, probably because the
89 * AX88140A doesn't support internal NWAY.
90 */
91
92#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 76 unchanged lines hidden (view full) ---

85 * All of the workalike chips use some form of MII transceiver support
86 * with the exception of the Macronix chips, which also have a SYM port.
87 * The ASIX AX88140A is also documented to have a SYM port, but all
88 * the cards I've seen use an MII transceiver, probably because the
89 * AX88140A doesn't support internal NWAY.
90 */
91
92#include <sys/cdefs.h>
93__FBSDID("$FreeBSD: head/sys/dev/dc/if_dc.c 121939 2003-11-03 09:22:18Z dfr $");
93__FBSDID("$FreeBSD: head/sys/dev/dc/if_dc.c 122625 2003-11-13 20:55:53Z obrien $");
94
95#include <sys/param.h>
96#include <sys/endian.h>
97#include <sys/systm.h>
98#include <sys/sockio.h>
99#include <sys/mbuf.h>
100#include <sys/malloc.h>
101#include <sys/kernel.h>

--- 157 unchanged lines hidden (view full) ---

259static int dc_mii_readreg (struct dc_softc *, struct dc_mii_frame *);
260static int dc_mii_writereg (struct dc_softc *, struct dc_mii_frame *);
261static int dc_miibus_readreg (device_t, int, int);
262static int dc_miibus_writereg (device_t, int, int, int);
263static void dc_miibus_statchg (device_t);
264static void dc_miibus_mediainit (device_t);
265
266static void dc_setcfg (struct dc_softc *, int);
94
95#include <sys/param.h>
96#include <sys/endian.h>
97#include <sys/systm.h>
98#include <sys/sockio.h>
99#include <sys/mbuf.h>
100#include <sys/malloc.h>
101#include <sys/kernel.h>

--- 157 unchanged lines hidden (view full) ---

259static int dc_mii_readreg (struct dc_softc *, struct dc_mii_frame *);
260static int dc_mii_writereg (struct dc_softc *, struct dc_mii_frame *);
261static int dc_miibus_readreg (device_t, int, int);
262static int dc_miibus_writereg (device_t, int, int, int);
263static void dc_miibus_statchg (device_t);
264static void dc_miibus_mediainit (device_t);
265
266static void dc_setcfg (struct dc_softc *, int);
267static u_int32_t dc_crc_le (struct dc_softc *, const uint8_t *);
268static u_int32_t dc_crc_be (const uint8_t *);
267static u_int32_t dc_mchash_le (struct dc_softc *, caddr_t);
268static u_int32_t dc_mchash_be (caddr_t);
269static void dc_setfilt_21143 (struct dc_softc *);
270static void dc_setfilt_asix (struct dc_softc *);
271static void dc_setfilt_admtek (struct dc_softc *);
272static void dc_setfilt_xircom (struct dc_softc *);
273
274static void dc_setfilt (struct dc_softc *);
275
276static void dc_reset (struct dc_softc *);

--- 739 unchanged lines hidden (view full) ---

1016}
1017
1018#define DC_POLY 0xEDB88320
1019#define DC_BITS_512 9
1020#define DC_BITS_128 7
1021#define DC_BITS_64 6
1022
1023static u_int32_t
269static void dc_setfilt_21143 (struct dc_softc *);
270static void dc_setfilt_asix (struct dc_softc *);
271static void dc_setfilt_admtek (struct dc_softc *);
272static void dc_setfilt_xircom (struct dc_softc *);
273
274static void dc_setfilt (struct dc_softc *);
275
276static void dc_reset (struct dc_softc *);

--- 739 unchanged lines hidden (view full) ---

1016}
1017
1018#define DC_POLY 0xEDB88320
1019#define DC_BITS_512 9
1020#define DC_BITS_128 7
1021#define DC_BITS_64 6
1022
1023static u_int32_t
1024dc_crc_le(struct dc_softc *sc, const uint8_t *addr)
1024dc_mchash_le(struct dc_softc *sc, caddr_t addr)
1025{
1025{
1026 uint32_t idx, bit, data, crc;
1026 u_int32_t crc;
1027 int idx, bit;
1028 u_int8_t data;
1027
1028 /* Compute CRC for the address value. */
1029 crc = 0xFFFFFFFF; /* initial value */
1030
1031 for (idx = 0; idx < 6; idx++) {
1032 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
1033 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? DC_POLY : 0);
1034 }

--- 21 unchanged lines hidden (view full) ---

1056
1057 return (crc & ((1 << DC_BITS_512) - 1));
1058}
1059
1060/*
1061 * Calculate CRC of a multicast group address, return the lower 6 bits.
1062 */
1063static u_int32_t
1029
1030 /* Compute CRC for the address value. */
1031 crc = 0xFFFFFFFF; /* initial value */
1032
1033 for (idx = 0; idx < 6; idx++) {
1034 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
1035 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? DC_POLY : 0);
1036 }

--- 21 unchanged lines hidden (view full) ---

1058
1059 return (crc & ((1 << DC_BITS_512) - 1));
1060}
1061
1062/*
1063 * Calculate CRC of a multicast group address, return the lower 6 bits.
1064 */
1065static u_int32_t
1064dc_crc_be(const uint8_t *addr)
1066dc_mchash_be(caddr_t addr)
1065{
1067{
1066 uint32_t crc, carry;
1067 int i, j;
1068 uint8_t c;
1068 u_int32_t crc, carry;
1069 int idx, bit;
1070 u_int8_t data;
1069
1070 /* Compute CRC for the address value. */
1071 crc = 0xFFFFFFFF; /* initial value */
1072
1071
1072 /* Compute CRC for the address value. */
1073 crc = 0xFFFFFFFF; /* initial value */
1074
1073 for (i = 0; i < 6; i++) {
1074 c = *(addr + i);
1075 for (j = 0; j < 8; j++) {
1076 carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
1075 for (idx = 0; idx < 6; idx++) {
1076 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) {
1077 carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01);
1078 data >>= 1;
1077 crc <<= 1;
1079 crc <<= 1;
1078 c >>= 1;
1079 if (carry)
1080 crc = (crc ^ 0x04c11db6) | carry;
1081 }
1082 }
1083
1084 /* Return the filter bit position. */
1085 return ((crc >> 26) & 0x0000003F);
1086}

--- 41 unchanged lines hidden (view full) ---

1128 if (ifp->if_flags & IFF_ALLMULTI)
1129 DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1130 else
1131 DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1132
1133 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1134 if (ifma->ifma_addr->sa_family != AF_LINK)
1135 continue;
1080 if (carry)
1081 crc = (crc ^ 0x04c11db6) | carry;
1082 }
1083 }
1084
1085 /* Return the filter bit position. */
1086 return ((crc >> 26) & 0x0000003F);
1087}

--- 41 unchanged lines hidden (view full) ---

1129 if (ifp->if_flags & IFF_ALLMULTI)
1130 DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1131 else
1132 DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1133
1134 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1135 if (ifma->ifma_addr->sa_family != AF_LINK)
1136 continue;
1136 h = dc_crc_le(sc,
1137 h = dc_mchash_le(sc,
1137 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1138 sp[h >> 4] |= htole32(1 << (h & 0xF));
1139 }
1140
1141 if (ifp->if_flags & IFF_BROADCAST) {
1138 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1139 sp[h >> 4] |= htole32(1 << (h & 0xF));
1140 }
1141
1142 if (ifp->if_flags & IFF_BROADCAST) {
1142 h = dc_crc_le(sc, ifp->if_broadcastaddr);
1143 h = dc_mchash_le(sc, ifp->if_broadcastaddr);
1143 sp[h >> 4] |= htole32(1 << (h & 0xF));
1144 }
1145
1146 /* Set our MAC address */
1147 sp[39] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
1148 sp[40] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
1149 sp[41] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
1150

--- 47 unchanged lines hidden (view full) ---

1198 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))
1199 return;
1200
1201 /* Now program new ones. */
1202 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1203 if (ifma->ifma_addr->sa_family != AF_LINK)
1204 continue;
1205 if (DC_IS_CENTAUR(sc))
1144 sp[h >> 4] |= htole32(1 << (h & 0xF));
1145 }
1146
1147 /* Set our MAC address */
1148 sp[39] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
1149 sp[40] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
1150 sp[41] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
1151

--- 47 unchanged lines hidden (view full) ---

1199 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))
1200 return;
1201
1202 /* Now program new ones. */
1203 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1204 if (ifma->ifma_addr->sa_family != AF_LINK)
1205 continue;
1206 if (DC_IS_CENTAUR(sc))
1206 h = dc_crc_le(sc, LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1207 h = dc_mchash_le(sc,
1208 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1207 else
1209 else
1208 h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1210 h = dc_mchash_be(
1211 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1209 if (h < 32)
1210 hashes[0] |= (1 << h);
1211 else
1212 hashes[1] |= (1 << (h - 32));
1213 }
1214
1215 CSR_WRITE_4(sc, DC_AL_MAR0, hashes[0]);
1216 CSR_WRITE_4(sc, DC_AL_MAR1, hashes[1]);

--- 49 unchanged lines hidden (view full) ---

1266 */
1267 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))
1268 return;
1269
1270 /* now program new ones */
1271 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1272 if (ifma->ifma_addr->sa_family != AF_LINK)
1273 continue;
1212 if (h < 32)
1213 hashes[0] |= (1 << h);
1214 else
1215 hashes[1] |= (1 << (h - 32));
1216 }
1217
1218 CSR_WRITE_4(sc, DC_AL_MAR0, hashes[0]);
1219 CSR_WRITE_4(sc, DC_AL_MAR1, hashes[1]);

--- 49 unchanged lines hidden (view full) ---

1269 */
1270 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))
1271 return;
1272
1273 /* now program new ones */
1274 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1275 if (ifma->ifma_addr->sa_family != AF_LINK)
1276 continue;
1274 h = dc_crc_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1277 h = dc_mchash_be(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1275 if (h < 32)
1276 hashes[0] |= (1 << h);
1277 else
1278 hashes[1] |= (1 << (h - 32));
1279 }
1280
1281 CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR0);
1282 CSR_WRITE_4(sc, DC_AX_FILTDATA, hashes[0]);

--- 35 unchanged lines hidden (view full) ---

1318 if (ifp->if_flags & IFF_ALLMULTI)
1319 DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1320 else
1321 DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1322
1323 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1324 if (ifma->ifma_addr->sa_family != AF_LINK)
1325 continue;
1278 if (h < 32)
1279 hashes[0] |= (1 << h);
1280 else
1281 hashes[1] |= (1 << (h - 32));
1282 }
1283
1284 CSR_WRITE_4(sc, DC_AX_FILTIDX, DC_AX_FILTIDX_MAR0);
1285 CSR_WRITE_4(sc, DC_AX_FILTDATA, hashes[0]);

--- 35 unchanged lines hidden (view full) ---

1321 if (ifp->if_flags & IFF_ALLMULTI)
1322 DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1323 else
1324 DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_RX_ALLMULTI);
1325
1326 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1327 if (ifma->ifma_addr->sa_family != AF_LINK)
1328 continue;
1326 h = dc_crc_le(sc,
1329 h = dc_mchash_le(sc,
1327 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1328 sp[h >> 4] |= htole32(1 << (h & 0xF));
1329 }
1330
1331 if (ifp->if_flags & IFF_BROADCAST) {
1330 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
1331 sp[h >> 4] |= htole32(1 << (h & 0xF));
1332 }
1333
1334 if (ifp->if_flags & IFF_BROADCAST) {
1332 h = dc_crc_le(sc, ifp->if_broadcastaddr);
1335 h = dc_mchash_le(sc, ifp->if_broadcastaddr);
1333 sp[h >> 4] |= htole32(1 << (h & 0xF));
1334 }
1335
1336 /* Set our MAC address */
1337 sp[0] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
1338 sp[1] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
1339 sp[2] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
1340

--- 2515 unchanged lines hidden ---
1336 sp[h >> 4] |= htole32(1 << (h & 0xF));
1337 }
1338
1339 /* Set our MAC address */
1340 sp[0] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
1341 sp[1] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
1342 sp[2] = DC_SP_MAC(((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
1343

--- 2515 unchanged lines hidden ---