if_stge.c (167190) | if_stge.c (169157) |
---|---|
1/* $NetBSD: if_stge.c,v 1.32 2005/12/11 12:22:49 christos Exp $ */ 2 3/*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. --- 28 unchanged lines hidden (view full) --- 37 */ 38 39/* 40 * Device driver for the Sundance Tech. TC9021 10/100/1000 41 * Ethernet controller. 42 */ 43 44#include <sys/cdefs.h> | 1/* $NetBSD: if_stge.c,v 1.32 2005/12/11 12:22:49 christos Exp $ */ 2 3/*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. --- 28 unchanged lines hidden (view full) --- 37 */ 38 39/* 40 * Device driver for the Sundance Tech. TC9021 10/100/1000 41 * Ethernet controller. 42 */ 43 44#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: head/sys/dev/stge/if_stge.c 167190 2007-03-04 03:38:08Z csjp $"); | 45__FBSDID("$FreeBSD: head/sys/dev/stge/if_stge.c 169157 2007-05-01 03:15:04Z yongari $"); |
46 47#ifdef HAVE_KERNEL_OPTION_HEADERS 48#include "opt_device_polling.h" 49#endif 50 51#include <sys/param.h> 52#include <sys/systm.h> 53#include <sys/endian.h> --- 78 unchanged lines hidden (view full) --- 132static int stge_detach(device_t); 133static void stge_shutdown(device_t); 134static int stge_suspend(device_t); 135static int stge_resume(device_t); 136 137static int stge_encap(struct stge_softc *, struct mbuf **); 138static void stge_start(struct ifnet *); 139static void stge_start_locked(struct ifnet *); | 46 47#ifdef HAVE_KERNEL_OPTION_HEADERS 48#include "opt_device_polling.h" 49#endif 50 51#include <sys/param.h> 52#include <sys/systm.h> 53#include <sys/endian.h> --- 78 unchanged lines hidden (view full) --- 132static int stge_detach(device_t); 133static void stge_shutdown(device_t); 134static int stge_suspend(device_t); 135static int stge_resume(device_t); 136 137static int stge_encap(struct stge_softc *, struct mbuf **); 138static void stge_start(struct ifnet *); 139static void stge_start_locked(struct ifnet *); |
140static void stge_watchdog(struct ifnet *); | 140static void stge_watchdog(struct stge_softc *); |
141static int stge_ioctl(struct ifnet *, u_long, caddr_t); 142static void stge_init(void *); 143static void stge_init_locked(struct stge_softc *); 144static void stge_vlan_setup(struct stge_softc *); 145static void stge_stop(struct stge_softc *); 146static void stge_start_tx(struct stge_softc *); 147static void stge_start_rx(struct stge_softc *); 148static void stge_stop_tx(struct stge_softc *); --- 590 unchanged lines hidden (view full) --- 739 goto fail; 740 } 741 742 ifp->if_softc = sc; 743 if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 744 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 745 ifp->if_ioctl = stge_ioctl; 746 ifp->if_start = stge_start; | 141static int stge_ioctl(struct ifnet *, u_long, caddr_t); 142static void stge_init(void *); 143static void stge_init_locked(struct stge_softc *); 144static void stge_vlan_setup(struct stge_softc *); 145static void stge_stop(struct stge_softc *); 146static void stge_start_tx(struct stge_softc *); 147static void stge_start_rx(struct stge_softc *); 148static void stge_stop_tx(struct stge_softc *); --- 590 unchanged lines hidden (view full) --- 739 goto fail; 740 } 741 742 ifp->if_softc = sc; 743 if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 744 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 745 ifp->if_ioctl = stge_ioctl; 746 ifp->if_start = stge_start; |
747 ifp->if_watchdog = stge_watchdog; | 747 ifp->if_timer = 0; 748 ifp->if_watchdog = NULL; |
748 ifp->if_init = stge_init; 749 ifp->if_mtu = ETHERMTU; 750 ifp->if_snd.ifq_drv_maxlen = STGE_TX_RING_CNT - 1; 751 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen); 752 IFQ_SET_READY(&ifp->if_snd); 753 /* Revision B3 and earlier chips have checksum bug. */ 754 if (sc->sc_rev >= 0x0c) { 755 ifp->if_hwassist = STGE_CSUM_FEATURES; --- 593 unchanged lines hidden (view full) --- 1349 ETHER_BPF_MTAP(ifp, m_head); 1350 } 1351 1352 if (enq > 0) { 1353 /* Transmit */ 1354 CSR_WRITE_4(sc, STGE_DMACtrl, DMAC_TxDMAPollNow); 1355 1356 /* Set a timeout in case the chip goes out to lunch. */ | 749 ifp->if_init = stge_init; 750 ifp->if_mtu = ETHERMTU; 751 ifp->if_snd.ifq_drv_maxlen = STGE_TX_RING_CNT - 1; 752 IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen); 753 IFQ_SET_READY(&ifp->if_snd); 754 /* Revision B3 and earlier chips have checksum bug. */ 755 if (sc->sc_rev >= 0x0c) { 756 ifp->if_hwassist = STGE_CSUM_FEATURES; --- 593 unchanged lines hidden (view full) --- 1350 ETHER_BPF_MTAP(ifp, m_head); 1351 } 1352 1353 if (enq > 0) { 1354 /* Transmit */ 1355 CSR_WRITE_4(sc, STGE_DMACtrl, DMAC_TxDMAPollNow); 1356 1357 /* Set a timeout in case the chip goes out to lunch. */ |
1357 ifp->if_timer = 5; | 1358 sc->sc_watchdog_timer = 5; |
1358 } 1359} 1360 1361/* | 1359 } 1360} 1361 1362/* |
1362 * stge_watchdog: [ifnet interface function] | 1363 * stge_watchdog: |
1363 * 1364 * Watchdog timer handler. 1365 */ 1366static void | 1364 * 1365 * Watchdog timer handler. 1366 */ 1367static void |
1367stge_watchdog(struct ifnet *ifp) | 1368stge_watchdog(struct stge_softc *sc) |
1368{ | 1369{ |
1369 struct stge_softc *sc; | 1370 struct ifnet *ifp; |
1370 | 1371 |
1371 sc = ifp->if_softc; | 1372 STGE_LOCK_ASSERT(sc); |
1372 | 1373 |
1373 STGE_LOCK(sc); | 1374 if (sc->sc_watchdog_timer == 0 || --sc->sc_watchdog_timer) 1375 return; 1376 1377 ifp = sc->sc_ifp; |
1374 if_printf(sc->sc_ifp, "device timeout\n"); 1375 ifp->if_oerrors++; 1376 stge_init_locked(sc); | 1378 if_printf(sc->sc_ifp, "device timeout\n"); 1379 ifp->if_oerrors++; 1380 stge_init_locked(sc); |
1377 STGE_UNLOCK(sc); | |
1378} 1379 1380/* 1381 * stge_ioctl: [ifnet interface function] 1382 * 1383 * Handle control requests from the operator. 1384 */ 1385static int --- 286 unchanged lines hidden (view full) --- 1672 m_freem(txd->tx_m); 1673 txd->tx_m = NULL; 1674 STAILQ_REMOVE_HEAD(&sc->sc_cdata.stge_txbusyq, tx_q); 1675 STAILQ_INSERT_TAIL(&sc->sc_cdata.stge_txfreeq, txd, tx_q); 1676 txd = STAILQ_FIRST(&sc->sc_cdata.stge_txbusyq); 1677 } 1678 sc->sc_cdata.stge_tx_cons = cons; 1679 if (sc->sc_cdata.stge_tx_cnt == 0) | 1381} 1382 1383/* 1384 * stge_ioctl: [ifnet interface function] 1385 * 1386 * Handle control requests from the operator. 1387 */ 1388static int --- 286 unchanged lines hidden (view full) --- 1675 m_freem(txd->tx_m); 1676 txd->tx_m = NULL; 1677 STAILQ_REMOVE_HEAD(&sc->sc_cdata.stge_txbusyq, tx_q); 1678 STAILQ_INSERT_TAIL(&sc->sc_cdata.stge_txfreeq, txd, tx_q); 1679 txd = STAILQ_FIRST(&sc->sc_cdata.stge_txbusyq); 1680 } 1681 sc->sc_cdata.stge_tx_cons = cons; 1682 if (sc->sc_cdata.stge_tx_cnt == 0) |
1680 ifp->if_timer = 0; | 1683 sc->sc_watchdog_timer = 0; |
1681 1682 bus_dmamap_sync(sc->sc_cdata.stge_tx_ring_tag, 1683 sc->sc_cdata.stge_tx_ring_map, 1684 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 1685} 1686 1687static __inline void 1688stge_discard_rxbuf(struct stge_softc *sc, int idx) --- 258 unchanged lines hidden (view full) --- 1947 * Relcaim any pending Tx descriptors to release mbufs in a 1948 * timely manner as we don't generate Tx completion interrupts 1949 * for every frame. This limits the delay to a maximum of one 1950 * second. 1951 */ 1952 if (sc->sc_cdata.stge_tx_cnt != 0) 1953 stge_txeof(sc); 1954 | 1684 1685 bus_dmamap_sync(sc->sc_cdata.stge_tx_ring_tag, 1686 sc->sc_cdata.stge_tx_ring_map, 1687 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 1688} 1689 1690static __inline void 1691stge_discard_rxbuf(struct stge_softc *sc, int idx) --- 258 unchanged lines hidden (view full) --- 1950 * Relcaim any pending Tx descriptors to release mbufs in a 1951 * timely manner as we don't generate Tx completion interrupts 1952 * for every frame. This limits the delay to a maximum of one 1953 * second. 1954 */ 1955 if (sc->sc_cdata.stge_tx_cnt != 0) 1956 stge_txeof(sc); 1957 |
1958 stge_watchdog(sc); 1959 |
|
1955 callout_reset(&sc->sc_tick_ch, hz, stge_tick, sc); 1956} 1957 1958/* 1959 * stge_stats_update: 1960 * 1961 * Read the TC9021 statistics counters. 1962 */ --- 335 unchanged lines hidden (view full) --- 2298 uint32_t v; 2299 int i; 2300 2301 STGE_LOCK_ASSERT(sc); 2302 /* 2303 * Stop the one second clock. 2304 */ 2305 callout_stop(&sc->sc_tick_ch); | 1960 callout_reset(&sc->sc_tick_ch, hz, stge_tick, sc); 1961} 1962 1963/* 1964 * stge_stats_update: 1965 * 1966 * Read the TC9021 statistics counters. 1967 */ --- 335 unchanged lines hidden (view full) --- 2303 uint32_t v; 2304 int i; 2305 2306 STGE_LOCK_ASSERT(sc); 2307 /* 2308 * Stop the one second clock. 2309 */ 2310 callout_stop(&sc->sc_tick_ch); |
2311 sc->sc_watchdog_timer = 0; |
|
2306 2307 /* 2308 * Reset the chip to a known state. 2309 */ 2310 stge_reset(sc, STGE_RESET_FULL); 2311 2312 /* 2313 * Disable interrupts. --- 44 unchanged lines hidden (view full) --- 2358 } 2359 } 2360 2361 /* 2362 * Mark the interface down and cancel the watchdog timer. 2363 */ 2364 ifp = sc->sc_ifp; 2365 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | 2312 2313 /* 2314 * Reset the chip to a known state. 2315 */ 2316 stge_reset(sc, STGE_RESET_FULL); 2317 2318 /* 2319 * Disable interrupts. --- 44 unchanged lines hidden (view full) --- 2364 } 2365 } 2366 2367 /* 2368 * Mark the interface down and cancel the watchdog timer. 2369 */ 2370 ifp = sc->sc_ifp; 2371 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); |
2366 ifp->if_timer = 0; | |
2367} 2368 2369static void 2370stge_start_tx(struct stge_softc *sc) 2371{ 2372 uint32_t v; 2373 int i; 2374 --- 324 unchanged lines hidden --- | 2372} 2373 2374static void 2375stge_start_tx(struct stge_softc *sc) 2376{ 2377 uint32_t v; 2378 int i; 2379 --- 324 unchanged lines hidden --- |