Deleted Added
full compact
if_stge.c (169157) if_stge.c (169158)
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 169157 2007-05-01 03:15:04Z yongari $");
45__FBSDID("$FreeBSD: head/sys/dev/stge/if_stge.c 169158 2007-05-01 03:35:48Z 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>

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

474 * stge_miibus_statchg: [mii interface function]
475 *
476 * Callback from MII layer when media changes.
477 */
478static void
479stge_miibus_statchg(device_t dev)
480{
481 struct stge_softc *sc;
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>

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

474 * stge_miibus_statchg: [mii interface function]
475 *
476 * Callback from MII layer when media changes.
477 */
478static void
479stge_miibus_statchg(device_t dev)
480{
481 struct stge_softc *sc;
482 struct mii_data *mii;
483
484 sc = device_get_softc(dev);
482
483 sc = device_get_softc(dev);
485 mii = device_get_softc(sc->sc_miibus);
486
487 STGE_MII_LOCK(sc);
488 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE) {
489 STGE_MII_UNLOCK(sc);
490 return;
491 }
492
493 sc->sc_MACCtrl = 0;
494 if (((mii->mii_media_active & IFM_GMASK) & IFM_FDX) != 0)
495 sc->sc_MACCtrl |= MC_DuplexSelect;
496 if (((mii->mii_media_active & IFM_GMASK) & IFM_FLAG0) != 0)
497 sc->sc_MACCtrl |= MC_RxFlowControlEnable;
498 if (((mii->mii_media_active & IFM_GMASK) & IFM_FLAG1) != 0)
499 sc->sc_MACCtrl |= MC_TxFlowControlEnable;
500 /*
501 * We can't access STGE_MACCtrl register in this context due to
502 * the races between MII layer and driver which accesses this
503 * register to program MAC. In order to solve the race, we defer
504 * STGE_MACCtrl programming until we know we are out of MII.
505 */
506 taskqueue_enqueue(taskqueue_swi, &sc->sc_link_task);
484 taskqueue_enqueue(taskqueue_swi, &sc->sc_link_task);
507 STGE_MII_UNLOCK(sc);
508}
509
510/*
511 * stge_mediastatus: [ifmedia interface function]
512 *
513 * Get the current interface media status.
514 */
515static void

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

1312 struct mbuf *m_head;
1313 int enq;
1314
1315 sc = ifp->if_softc;
1316
1317 STGE_LOCK_ASSERT(sc);
1318
1319 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
485}
486
487/*
488 * stge_mediastatus: [ifmedia interface function]
489 *
490 * Get the current interface media status.
491 */
492static void

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

1289 struct mbuf *m_head;
1290 int enq;
1291
1292 sc = ifp->if_softc;
1293
1294 STGE_LOCK_ASSERT(sc);
1295
1296 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
1320 IFF_DRV_RUNNING)
1297 IFF_DRV_RUNNING || sc->sc_link == 0)
1321 return;
1322
1323 for (enq = 0; !IFQ_DRV_IS_EMPTY(&ifp->if_snd); ) {
1324 if (sc->sc_cdata.stge_tx_cnt >= STGE_TX_HIWAT) {
1325 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1326 break;
1327 }
1328

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

1486
1487 return (error);
1488}
1489
1490static void
1491stge_link_task(void *arg, int pending)
1492{
1493 struct stge_softc *sc;
1298 return;
1299
1300 for (enq = 0; !IFQ_DRV_IS_EMPTY(&ifp->if_snd); ) {
1301 if (sc->sc_cdata.stge_tx_cnt >= STGE_TX_HIWAT) {
1302 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1303 break;
1304 }
1305

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

1463
1464 return (error);
1465}
1466
1467static void
1468stge_link_task(void *arg, int pending)
1469{
1470 struct stge_softc *sc;
1471 struct mii_data *mii;
1494 uint32_t v, ac;
1495 int i;
1496
1497 sc = (struct stge_softc *)arg;
1498 STGE_LOCK(sc);
1472 uint32_t v, ac;
1473 int i;
1474
1475 sc = (struct stge_softc *)arg;
1476 STGE_LOCK(sc);
1477
1478 mii = device_get_softc(sc->sc_miibus);
1479 if (mii->mii_media_status & IFM_ACTIVE) {
1480 if (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)
1481 sc->sc_link = 1;
1482 } else
1483 sc->sc_link = 0;
1484
1485 sc->sc_MACCtrl = 0;
1486 if (((mii->mii_media_active & IFM_GMASK) & IFM_FDX) != 0)
1487 sc->sc_MACCtrl |= MC_DuplexSelect;
1488 if (((mii->mii_media_active & IFM_GMASK) & IFM_FLAG0) != 0)
1489 sc->sc_MACCtrl |= MC_RxFlowControlEnable;
1490 if (((mii->mii_media_active & IFM_GMASK) & IFM_FLAG1) != 0)
1491 sc->sc_MACCtrl |= MC_TxFlowControlEnable;
1499 /*
1500 * Update STGE_MACCtrl register depending on link status.
1501 * (duplex, flow control etc)
1502 */
1503 v = ac = CSR_READ_4(sc, STGE_MACCtrl) & MC_MASK;
1504 v &= ~(MC_DuplexSelect|MC_RxFlowControlEnable|MC_TxFlowControlEnable);
1505 v |= sc->sc_MACCtrl;
1506 CSR_WRITE_4(sc, STGE_MACCtrl, v);

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

2242 CSR_WRITE_4(sc, STGE_MACCtrl, v);
2243 /*
2244 * It seems that transmitting frames without checking the state of
2245 * Rx/Tx MAC wedge the hardware.
2246 */
2247 stge_start_tx(sc);
2248 stge_start_rx(sc);
2249
1492 /*
1493 * Update STGE_MACCtrl register depending on link status.
1494 * (duplex, flow control etc)
1495 */
1496 v = ac = CSR_READ_4(sc, STGE_MACCtrl) & MC_MASK;
1497 v &= ~(MC_DuplexSelect|MC_RxFlowControlEnable|MC_TxFlowControlEnable);
1498 v |= sc->sc_MACCtrl;
1499 CSR_WRITE_4(sc, STGE_MACCtrl, v);

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

2235 CSR_WRITE_4(sc, STGE_MACCtrl, v);
2236 /*
2237 * It seems that transmitting frames without checking the state of
2238 * Rx/Tx MAC wedge the hardware.
2239 */
2240 stge_start_tx(sc);
2241 stge_start_rx(sc);
2242
2243 sc->sc_link = 0;
2250 /*
2251 * Set the current media.
2252 */
2253 mii_mediachg(mii);
2254
2255 /*
2256 * Start the one second MII clock.
2257 */

--- 106 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);
2244 /*
2245 * Set the current media.
2246 */
2247 mii_mediachg(mii);
2248
2249 /*
2250 * Start the one second MII clock.
2251 */

--- 106 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);
2366 sc->sc_link = 0;
2372}
2373
2374static void
2375stge_start_tx(struct stge_softc *sc)
2376{
2377 uint32_t v;
2378 int i;
2379

--- 324 unchanged lines hidden ---
2367}
2368
2369static void
2370stge_start_tx(struct stge_softc *sc)
2371{
2372 uint32_t v;
2373 int i;
2374

--- 324 unchanged lines hidden ---