Deleted Added
full compact
if_fxp.c (64547) if_fxp.c (65983)
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Modifications to support NetBSD and media selection:
6 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Modifications to support NetBSD and media selection:
6 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD: head/sys/dev/fxp/if_fxp.c 64547 2000-08-11 17:47:55Z wpaul $
30 * $FreeBSD: head/sys/dev/fxp/if_fxp.c 65983 2000-09-17 13:26:25Z cp $
31 */
32
33/*
34 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>

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

79
80#else /* __FreeBSD__ */
81
82#include <sys/sockio.h>
83#include <sys/bus.h>
84#include <machine/bus.h>
85#include <sys/rman.h>
86#include <machine/resource.h>
31 */
32
33/*
34 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>

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

79
80#else /* __FreeBSD__ */
81
82#include <sys/sockio.h>
83#include <sys/bus.h>
84#include <machine/bus.h>
85#include <sys/rman.h>
86#include <machine/resource.h>
87#include <machine/mutex.h>
87
88#include <net/ethernet.h>
89#include <net/if_arp.h>
90
91#include <vm/vm.h> /* for vtophys */
92#include <vm/pmap.h> /* for vtophys */
93#include <machine/clock.h> /* for DELAY */
94

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

516}
517
518static int
519fxp_attach(device_t dev)
520{
521 int error = 0;
522 struct fxp_softc *sc = device_get_softc(dev);
523 struct ifnet *ifp;
88
89#include <net/ethernet.h>
90#include <net/if_arp.h>
91
92#include <vm/vm.h> /* for vtophys */
93#include <vm/pmap.h> /* for vtophys */
94#include <machine/clock.h> /* for DELAY */
95

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

517}
518
519static int
520fxp_attach(device_t dev)
521{
522 int error = 0;
523 struct fxp_softc *sc = device_get_softc(dev);
524 struct ifnet *ifp;
524 int s;
525 FXP_SPLVAR(s)
525 u_long val;
526 int rid;
527
526 u_long val;
527 int rid;
528
529#if !defined(__NetBSD__)
530 mtx_init(&sc->sc_mtx, "fxp", MTX_DEF);
531#endif
528 callout_handle_init(&sc->stat_ch);
529
532 callout_handle_init(&sc->stat_ch);
533
530 s = splimp();
534 FXP_LOCK(sc, s);
531
532 /*
533 * Enable bus mastering.
534 */
535 val = pci_read_config(dev, PCIR_COMMAND, 2);
536 val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
537 pci_write_config(dev, PCIR_COMMAND, val, 2);
538

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

600 */
601 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
602 /*
603 * Let the system queue as many packets as we have available
604 * TX descriptors.
605 */
606 ifp->if_snd.ifq_maxlen = FXP_NTXCB - 1;
607
535
536 /*
537 * Enable bus mastering.
538 */
539 val = pci_read_config(dev, PCIR_COMMAND, 2);
540 val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
541 pci_write_config(dev, PCIR_COMMAND, val, 2);
542

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

604 */
605 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
606 /*
607 * Let the system queue as many packets as we have available
608 * TX descriptors.
609 */
610 ifp->if_snd.ifq_maxlen = FXP_NTXCB - 1;
611
608 splx(s);
612 FXP_UNLOCK(sc, s);
609 return 0;
610
611 fail:
613 return 0;
614
615 fail:
612 splx(s);
616 FXP_UNLOCK(sc, s);
617 mtx_destroy(&sc->sc_mtx);
613 return error;
614}
615
616/*
617 * Detach interface.
618 */
619static int
620fxp_detach(device_t dev)
621{
622 struct fxp_softc *sc = device_get_softc(dev);
618 return error;
619}
620
621/*
622 * Detach interface.
623 */
624static int
625fxp_detach(device_t dev)
626{
627 struct fxp_softc *sc = device_get_softc(dev);
623 int s;
628 FXP_SPLVAR(s)
624
629
625 s = splimp();
630 FXP_LOCK(sc, s);
626
627 /*
628 * Close down routes etc.
629 */
630 ether_ifdetach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED);
631
632 /*
633 * Stop DMA and drop transmit queue.

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

654
655 /*
656 * Free anciliary structures.
657 */
658 free(sc->cbl_base, M_DEVBUF);
659 free(sc->fxp_stats, M_DEVBUF);
660 free(sc->mcsp, M_DEVBUF);
661
631
632 /*
633 * Close down routes etc.
634 */
635 ether_ifdetach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED);
636
637 /*
638 * Stop DMA and drop transmit queue.

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

659
660 /*
661 * Free anciliary structures.
662 */
663 free(sc->cbl_base, M_DEVBUF);
664 free(sc->fxp_stats, M_DEVBUF);
665 free(sc->mcsp, M_DEVBUF);
666
662 splx(s);
667 FXP_UNLOCK(sc, s);
663
664 return 0;
665}
666
667/*
668 * Device shutdown routine. Called at system shutdown after sync. The
669 * main purpose of this routine is to shut off receiver DMA so that
670 * kernel memory doesn't get clobbered during warmboot.

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

954 */
955static void
956fxp_start(ifp)
957 struct ifnet *ifp;
958{
959 struct fxp_softc *sc = ifp->if_softc;
960 struct fxp_cb_tx *txp;
961
668
669 return 0;
670}
671
672/*
673 * Device shutdown routine. Called at system shutdown after sync. The
674 * main purpose of this routine is to shut off receiver DMA so that
675 * kernel memory doesn't get clobbered during warmboot.

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

959 */
960static void
961fxp_start(ifp)
962 struct ifnet *ifp;
963{
964 struct fxp_softc *sc = ifp->if_softc;
965 struct fxp_cb_tx *txp;
966
967#if !defined(__NetBSD__)
968 FXP_LOCK(sc, s);
969#endif
962 /*
963 * See if we need to suspend xmit until the multicast filter
964 * has been reprogrammed (which can only be done at the head
965 * of the command chain).
966 */
970 /*
971 * See if we need to suspend xmit until the multicast filter
972 * has been reprogrammed (which can only be done at the head
973 * of the command chain).
974 */
967 if (sc->need_mcsetup)
975 if (sc->need_mcsetup) {
976 FXP_UNLOCK(sc, s);
968 return;
977 return;
978 }
969
970 txp = NULL;
971
972 /*
973 * We're finished if there is nothing more to add to the list or if
974 * we're all filled up with buffers to transmit.
975 * NOTE: One TxCB is reserved to guarantee that fxp_mc_setup() can add
976 * a NOP command when needed.

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

1088 /*
1089 * We're finished. If we added to the list, issue a RESUME to get DMA
1090 * going again if suspended.
1091 */
1092 if (txp != NULL) {
1093 fxp_scb_wait(sc);
1094 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_RESUME);
1095 }
979
980 txp = NULL;
981
982 /*
983 * We're finished if there is nothing more to add to the list or if
984 * we're all filled up with buffers to transmit.
985 * NOTE: One TxCB is reserved to guarantee that fxp_mc_setup() can add
986 * a NOP command when needed.

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

1098 /*
1099 * We're finished. If we added to the list, issue a RESUME to get DMA
1100 * going again if suspended.
1101 */
1102 if (txp != NULL) {
1103 fxp_scb_wait(sc);
1104 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_RESUME);
1105 }
1106#if !defined(__NetBSD__)
1107 FXP_UNLOCK(sc, s);
1108#endif
1096}
1097
1098/*
1099 * Process interface interrupts.
1100 */
1101static FXP_INTR_TYPE
1102fxp_intr(arg)
1103 void *arg;
1104{
1105 struct fxp_softc *sc = arg;
1106 struct ifnet *ifp = &sc->sc_if;
1107 u_int8_t statack;
1108#if defined(__NetBSD__)
1109 int claimed = 0;
1109}
1110
1111/*
1112 * Process interface interrupts.
1113 */
1114static FXP_INTR_TYPE
1115fxp_intr(arg)
1116 void *arg;
1117{
1118 struct fxp_softc *sc = arg;
1119 struct ifnet *ifp = &sc->sc_if;
1120 u_int8_t statack;
1121#if defined(__NetBSD__)
1122 int claimed = 0;
1123#else
1124
1125 FXP_LOCK(sc, s);
1110#endif
1111
1112 while ((statack = CSR_READ_1(sc, FXP_CSR_SCB_STATACK)) != 0) {
1113#if defined(__NetBSD__)
1114 claimed = 1;
1115#endif
1116 /*
1117 * First ACK all the interrupts in this pass.

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

1210 RFA_ALIGNMENT_FUDGE);
1211 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND,
1212 FXP_SCB_COMMAND_RU_START);
1213 }
1214 }
1215 }
1216#if defined(__NetBSD__)
1217 return (claimed);
1126#endif
1127
1128 while ((statack = CSR_READ_1(sc, FXP_CSR_SCB_STATACK)) != 0) {
1129#if defined(__NetBSD__)
1130 claimed = 1;
1131#endif
1132 /*
1133 * First ACK all the interrupts in this pass.

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

1226 RFA_ALIGNMENT_FUDGE);
1227 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND,
1228 FXP_SCB_COMMAND_RU_START);
1229 }
1230 }
1231 }
1232#if defined(__NetBSD__)
1233 return (claimed);
1234#else
1235 FXP_UNLOCK(sc, s);
1218#endif
1219}
1220
1221/*
1222 * Update packet in/out/collision statistics. The i82557 doesn't
1223 * allow you to access these counters without doing a fairly
1224 * expensive DMA to get _all_ of the statistics it maintains, so
1225 * we do this operation here only once per second. The statistics

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

1232static void
1233fxp_stats_update(arg)
1234 void *arg;
1235{
1236 struct fxp_softc *sc = arg;
1237 struct ifnet *ifp = &sc->sc_if;
1238 struct fxp_stats *sp = sc->fxp_stats;
1239 struct fxp_cb_tx *txp;
1236#endif
1237}
1238
1239/*
1240 * Update packet in/out/collision statistics. The i82557 doesn't
1241 * allow you to access these counters without doing a fairly
1242 * expensive DMA to get _all_ of the statistics it maintains, so
1243 * we do this operation here only once per second. The statistics

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

1250static void
1251fxp_stats_update(arg)
1252 void *arg;
1253{
1254 struct fxp_softc *sc = arg;
1255 struct ifnet *ifp = &sc->sc_if;
1256 struct fxp_stats *sp = sc->fxp_stats;
1257 struct fxp_cb_tx *txp;
1240 int s;
1258 FXP_SPLVAR(s)
1241
1242 ifp->if_opackets += sp->tx_good;
1243 ifp->if_collisions += sp->tx_total_collisions;
1244 if (sp->rx_good) {
1245 ifp->if_ipackets += sp->rx_good;
1246 sc->rx_idle_secs = 0;
1247 } else {
1248 /*

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

1259 * If any transmit underruns occured, bump up the transmit
1260 * threshold by another 512 bytes (64 * 8).
1261 */
1262 if (sp->tx_underruns) {
1263 ifp->if_oerrors += sp->tx_underruns;
1264 if (tx_threshold < 192)
1265 tx_threshold += 64;
1266 }
1259
1260 ifp->if_opackets += sp->tx_good;
1261 ifp->if_collisions += sp->tx_total_collisions;
1262 if (sp->rx_good) {
1263 ifp->if_ipackets += sp->rx_good;
1264 sc->rx_idle_secs = 0;
1265 } else {
1266 /*

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

1277 * If any transmit underruns occured, bump up the transmit
1278 * threshold by another 512 bytes (64 * 8).
1279 */
1280 if (sp->tx_underruns) {
1281 ifp->if_oerrors += sp->tx_underruns;
1282 if (tx_threshold < 192)
1283 tx_threshold += 64;
1284 }
1267 s = splimp();
1285 FXP_LOCK(sc, s);
1268 /*
1269 * Release any xmit buffers that have completed DMA. This isn't
1270 * strictly necessary to do here, but it's advantagous for mbufs
1271 * with external storage to be released in a timely manner rather
1272 * than being defered for a potentially long time. This limits
1273 * the delay to a maximum of one second.
1274 */
1275 for (txp = sc->cbl_first; sc->tx_queued &&

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

1317 sp->tx_total_collisions = 0;
1318
1319 sp->rx_good = 0;
1320 sp->rx_crc_errors = 0;
1321 sp->rx_alignment_errors = 0;
1322 sp->rx_rnr_errors = 0;
1323 sp->rx_overrun_errors = 0;
1324 }
1286 /*
1287 * Release any xmit buffers that have completed DMA. This isn't
1288 * strictly necessary to do here, but it's advantagous for mbufs
1289 * with external storage to be released in a timely manner rather
1290 * than being defered for a potentially long time. This limits
1291 * the delay to a maximum of one second.
1292 */
1293 for (txp = sc->cbl_first; sc->tx_queued &&

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

1335 sp->tx_total_collisions = 0;
1336
1337 sp->rx_good = 0;
1338 sp->rx_crc_errors = 0;
1339 sp->rx_alignment_errors = 0;
1340 sp->rx_rnr_errors = 0;
1341 sp->rx_overrun_errors = 0;
1342 }
1325 splx(s);
1343 FXP_UNLOCK(sc, s);
1326 /*
1327 * Schedule another timeout one second from now.
1328 */
1329 sc->stat_ch = timeout(fxp_stats_update, sc, hz);
1330}
1331
1332/*
1333 * Stop the interface. Cancels the statistics updater and resets
1334 * the interface.
1335 */
1336static void
1337fxp_stop(sc)
1338 struct fxp_softc *sc;
1339{
1340 struct ifnet *ifp = &sc->sc_if;
1341 struct fxp_cb_tx *txp;
1342 int i;
1343
1344 /*
1345 * Schedule another timeout one second from now.
1346 */
1347 sc->stat_ch = timeout(fxp_stats_update, sc, hz);
1348}
1349
1350/*
1351 * Stop the interface. Cancels the statistics updater and resets
1352 * the interface.
1353 */
1354static void
1355fxp_stop(sc)
1356 struct fxp_softc *sc;
1357{
1358 struct ifnet *ifp = &sc->sc_if;
1359 struct fxp_cb_tx *txp;
1360 int i;
1361
1362#if !defined(__NetBSD__)
1363 FXP_LOCK(sc, s);
1364#endif
1365
1344 /*
1345 * Cancel stats updater.
1346 */
1347 untimeout(fxp_stats_update, sc, sc->stat_ch);
1348
1349 /*
1350 * Issue software reset
1351 */

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

1381 * above.
1382 */
1383 panic("fxp_stop: no buffers!");
1384 }
1385 }
1386
1387 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1388 ifp->if_timer = 0;
1366 /*
1367 * Cancel stats updater.
1368 */
1369 untimeout(fxp_stats_update, sc, sc->stat_ch);
1370
1371 /*
1372 * Issue software reset
1373 */

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

1403 * above.
1404 */
1405 panic("fxp_stop: no buffers!");
1406 }
1407 }
1408
1409 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1410 ifp->if_timer = 0;
1411#if !defined(__NetBSD__)
1412 FXP_UNLOCK(sc, s);
1413#endif
1389}
1390
1391/*
1392 * Watchdog/transmission transmit timeout handler. Called when a
1393 * transmission is started on the interface, but no interrupt is
1394 * received before the timeout. This usually indicates that the
1395 * card has wedged for some reason.
1396 */

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

1410fxp_init(xsc)
1411 void *xsc;
1412{
1413 struct fxp_softc *sc = xsc;
1414 struct ifnet *ifp = &sc->sc_if;
1415 struct fxp_cb_config *cbp;
1416 struct fxp_cb_ias *cb_ias;
1417 struct fxp_cb_tx *txp;
1414}
1415
1416/*
1417 * Watchdog/transmission transmit timeout handler. Called when a
1418 * transmission is started on the interface, but no interrupt is
1419 * received before the timeout. This usually indicates that the
1420 * card has wedged for some reason.
1421 */

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

1435fxp_init(xsc)
1436 void *xsc;
1437{
1438 struct fxp_softc *sc = xsc;
1439 struct ifnet *ifp = &sc->sc_if;
1440 struct fxp_cb_config *cbp;
1441 struct fxp_cb_ias *cb_ias;
1442 struct fxp_cb_tx *txp;
1418 int i, s, prm;
1443 int i, prm;
1444 FXP_SPLVAR(s)
1419
1445
1420 s = splimp();
1446 FXP_LOCK(sc, s);
1421 /*
1422 * Cancel any pending I/O
1423 */
1424 fxp_stop(sc);
1425
1426 prm = (ifp->if_flags & IFF_PROMISC) ? 1 : 0;
1427
1428 /*

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

1559
1560 /*
1561 * Set current media.
1562 */
1563 fxp_set_media(sc, sc->sc_media.ifm_cur->ifm_media);
1564
1565 ifp->if_flags |= IFF_RUNNING;
1566 ifp->if_flags &= ~IFF_OACTIVE;
1447 /*
1448 * Cancel any pending I/O
1449 */
1450 fxp_stop(sc);
1451
1452 prm = (ifp->if_flags & IFF_PROMISC) ? 1 : 0;
1453
1454 /*

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

1585
1586 /*
1587 * Set current media.
1588 */
1589 fxp_set_media(sc, sc->sc_media.ifm_cur->ifm_media);
1590
1591 ifp->if_flags |= IFF_RUNNING;
1592 ifp->if_flags &= ~IFF_OACTIVE;
1567 splx(s);
1593 FXP_UNLOCK(sc, s);
1568
1569 /*
1570 * Start stats updater.
1571 */
1572 sc->stat_ch = timeout(fxp_stats_update, sc, hz);
1573}
1574
1575static void

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

1852static int
1853fxp_ioctl(ifp, command, data)
1854 struct ifnet *ifp;
1855 FXP_IOCTLCMD_TYPE command;
1856 caddr_t data;
1857{
1858 struct fxp_softc *sc = ifp->if_softc;
1859 struct ifreq *ifr = (struct ifreq *)data;
1594
1595 /*
1596 * Start stats updater.
1597 */
1598 sc->stat_ch = timeout(fxp_stats_update, sc, hz);
1599}
1600
1601static void

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

1878static int
1879fxp_ioctl(ifp, command, data)
1880 struct ifnet *ifp;
1881 FXP_IOCTLCMD_TYPE command;
1882 caddr_t data;
1883{
1884 struct fxp_softc *sc = ifp->if_softc;
1885 struct ifreq *ifr = (struct ifreq *)data;
1860 int s, error = 0;
1886 FXP_SPLVAR(s)
1887 int error = 0;
1861
1888
1862 s = splimp();
1889 FXP_LOCK(sc, s);
1863
1864 switch (command) {
1865
1866 case SIOCSIFADDR:
1867#if !defined(__NetBSD__)
1868 case SIOCGIFADDR:
1869 case SIOCSIFMTU:
1870#endif

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

1931 case SIOCSIFMEDIA:
1932 case SIOCGIFMEDIA:
1933 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, command);
1934 break;
1935
1936 default:
1937 error = EINVAL;
1938 }
1890
1891 switch (command) {
1892
1893 case SIOCSIFADDR:
1894#if !defined(__NetBSD__)
1895 case SIOCGIFADDR:
1896 case SIOCSIFMTU:
1897#endif

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

1958 case SIOCSIFMEDIA:
1959 case SIOCGIFMEDIA:
1960 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, command);
1961 break;
1962
1963 default:
1964 error = EINVAL;
1965 }
1939 (void) splx(s);
1966 FXP_UNLOCK(sc, s);
1940 return (error);
1941}
1942
1943/*
1944 * Program the multicast filter.
1945 *
1946 * We have an artificial restriction that the multicast setup command
1947 * must be the first command in the chain, so we take steps to ensure

--- 112 unchanged lines hidden ---
1967 return (error);
1968}
1969
1970/*
1971 * Program the multicast filter.
1972 *
1973 * We have an artificial restriction that the multicast setup command
1974 * must be the first command in the chain, so we take steps to ensure

--- 112 unchanged lines hidden ---