Deleted Added
full compact
if_nve.c (195049) if_nve.c (199560)
1/*-
2 * Copyright (c) 2005 by David E. O'Brien <obrien@FreeBSD.org>.
3 * Copyright (c) 2003,2004 by Quinton Dolan <q@onthenet.com.au>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

67 * as recent versions of DragonFly.
68 *
69 * Written by Quinton Dolan <q@onthenet.com.au>
70 * Portions based on existing FreeBSD network drivers.
71 * NVIDIA API usage derived from distributed NVIDIA NVNET driver source files.
72 */
73
74#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005 by David E. O'Brien <obrien@FreeBSD.org>.
3 * Copyright (c) 2003,2004 by Quinton Dolan <q@onthenet.com.au>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

67 * as recent versions of DragonFly.
68 *
69 * Written by Quinton Dolan <q@onthenet.com.au>
70 * Portions based on existing FreeBSD network drivers.
71 * NVIDIA API usage derived from distributed NVIDIA NVNET driver source files.
72 */
73
74#include <sys/cdefs.h>
75__FBSDID("$FreeBSD: head/sys/dev/nve/if_nve.c 195049 2009-06-26 11:45:06Z rwatson $");
75__FBSDID("$FreeBSD: head/sys/dev/nve/if_nve.c 199560 2009-11-19 22:14:23Z jhb $");
76
77#include <sys/param.h>
78#include <sys/systm.h>
79#include <sys/sockio.h>
80#include <sys/mbuf.h>
81#include <sys/malloc.h>
82#include <sys/kernel.h>
83#include <sys/socket.h>

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

135static void nve_free_rings(struct nve_softc *);
136
137static void nve_ifstart(struct ifnet *);
138static void nve_ifstart_locked(struct ifnet *);
139static int nve_ioctl(struct ifnet *, u_long, caddr_t);
140static void nve_intr(void *);
141static void nve_tick(void *);
142static void nve_setmulti(struct nve_softc *);
76
77#include <sys/param.h>
78#include <sys/systm.h>
79#include <sys/sockio.h>
80#include <sys/mbuf.h>
81#include <sys/malloc.h>
82#include <sys/kernel.h>
83#include <sys/socket.h>

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

135static void nve_free_rings(struct nve_softc *);
136
137static void nve_ifstart(struct ifnet *);
138static void nve_ifstart_locked(struct ifnet *);
139static int nve_ioctl(struct ifnet *, u_long, caddr_t);
140static void nve_intr(void *);
141static void nve_tick(void *);
142static void nve_setmulti(struct nve_softc *);
143static void nve_watchdog(struct ifnet *);
143static void nve_watchdog(struct nve_softc *);
144static void nve_update_stats(struct nve_softc *);
145
146static int nve_ifmedia_upd(struct ifnet *);
147static void nve_ifmedia_upd_locked(struct ifnet *);
148static void nve_ifmedia_sts(struct ifnet *, struct ifmediareq *);
149static int nve_miibus_readreg(device_t, int, int);
150static int nve_miibus_writereg(device_t, int, int, int);
151

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

535 }
536
537 /* Setup interface parameters */
538 ifp->if_softc = sc;
539 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
540 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
541 ifp->if_ioctl = nve_ioctl;
542 ifp->if_start = nve_ifstart;
144static void nve_update_stats(struct nve_softc *);
145
146static int nve_ifmedia_upd(struct ifnet *);
147static void nve_ifmedia_upd_locked(struct ifnet *);
148static void nve_ifmedia_sts(struct ifnet *, struct ifmediareq *);
149static int nve_miibus_readreg(device_t, int, int);
150static int nve_miibus_writereg(device_t, int, int, int);
151

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

535 }
536
537 /* Setup interface parameters */
538 ifp->if_softc = sc;
539 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
540 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
541 ifp->if_ioctl = nve_ioctl;
542 ifp->if_start = nve_ifstart;
543 ifp->if_watchdog = nve_watchdog;
544 ifp->if_timer = 0;
545 ifp->if_init = nve_init;
546 ifp->if_mtu = ETHERMTU;
547 ifp->if_baudrate = IF_Mbps(100);
548 IFQ_SET_MAXLEN(&ifp->if_snd, TX_RING_SIZE - 1);
549 ifp->if_snd.ifq_drv_maxlen = TX_RING_SIZE - 1;
550 IFQ_SET_READY(&ifp->if_snd);
551 ifp->if_capabilities |= IFCAP_VLAN_MTU;
552 ifp->if_capenable |= IFCAP_VLAN_MTU;

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

704{
705 struct ifnet *ifp;
706
707 NVE_LOCK_ASSERT(sc);
708
709 DEBUGOUT(NVE_DEBUG_RUNNING, "nve: nve_stop - entry\n");
710
711 ifp = sc->ifp;
543 ifp->if_init = nve_init;
544 ifp->if_mtu = ETHERMTU;
545 ifp->if_baudrate = IF_Mbps(100);
546 IFQ_SET_MAXLEN(&ifp->if_snd, TX_RING_SIZE - 1);
547 ifp->if_snd.ifq_drv_maxlen = TX_RING_SIZE - 1;
548 IFQ_SET_READY(&ifp->if_snd);
549 ifp->if_capabilities |= IFCAP_VLAN_MTU;
550 ifp->if_capenable |= IFCAP_VLAN_MTU;

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

702{
703 struct ifnet *ifp;
704
705 NVE_LOCK_ASSERT(sc);
706
707 DEBUGOUT(NVE_DEBUG_RUNNING, "nve: nve_stop - entry\n");
708
709 ifp = sc->ifp;
712 ifp->if_timer = 0;
710 sc->tx_timer = 0;
713
714 /* Cancel tick timer */
715 callout_stop(&sc->stat_callout);
716
717 /* Stop hardware activity */
718 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
719 sc->hwapi->pfnStop(sc->hwapi->pADCX, 0);
720

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

978 device_printf(sc->dev, "nve_ifstart: transmit error\n");
979 bus_dmamap_unload(sc->mtag, buf->map);
980 m_freem(buf->mbuf);
981 buf->mbuf = NULL;
982 sc->tx_errors++;
983 return;
984 }
985 /* Set watchdog timer. */
711
712 /* Cancel tick timer */
713 callout_stop(&sc->stat_callout);
714
715 /* Stop hardware activity */
716 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
717 sc->hwapi->pfnStop(sc->hwapi->pADCX, 0);
718

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

976 device_printf(sc->dev, "nve_ifstart: transmit error\n");
977 bus_dmamap_unload(sc->mtag, buf->map);
978 m_freem(buf->mbuf);
979 buf->mbuf = NULL;
980 sc->tx_errors++;
981 return;
982 }
983 /* Set watchdog timer. */
986 ifp->if_timer = 8;
984 sc->tx_timer = 8;
987
988 /* Copy packet to BPF tap */
989 BPF_MTAP(ifp, m0);
990 }
991 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
992
993 DEBUGOUT(NVE_DEBUG_RUNNING, "nve: nve_ifstart - exit\n");
994}

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

1090 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
1091 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
1092 }
1093 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1094 nve_ifstart_locked(ifp);
1095
1096 /* If no pending packets we don't need a timeout */
1097 if (sc->pending_txs == 0)
985
986 /* Copy packet to BPF tap */
987 BPF_MTAP(ifp, m0);
988 }
989 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
990
991 DEBUGOUT(NVE_DEBUG_RUNNING, "nve: nve_ifstart - exit\n");
992}

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

1088 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
1089 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
1090 }
1091 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1092 nve_ifstart_locked(ifp);
1093
1094 /* If no pending packets we don't need a timeout */
1095 if (sc->pending_txs == 0)
1098 sc->ifp->if_timer = 0;
1096 sc->tx_timer = 0;
1099 NVE_UNLOCK(sc);
1100
1101 DEBUGOUT(NVE_DEBUG_INTERRUPT, "nve: nve_intr - exit\n");
1102
1103 return;
1104}
1105
1106/* Setup multicast filters */

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

1231 mii = device_get_softc(sc->miibus);
1232 mii_tick(mii);
1233
1234 if (mii->mii_media_status & IFM_ACTIVE &&
1235 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1236 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1237 nve_ifstart_locked(ifp);
1238 }
1097 NVE_UNLOCK(sc);
1098
1099 DEBUGOUT(NVE_DEBUG_INTERRUPT, "nve: nve_intr - exit\n");
1100
1101 return;
1102}
1103
1104/* Setup multicast filters */

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

1229 mii = device_get_softc(sc->miibus);
1230 mii_tick(mii);
1231
1232 if (mii->mii_media_status & IFM_ACTIVE &&
1233 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1234 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1235 nve_ifstart_locked(ifp);
1236 }
1237
1238 if (sc->tx_timer > 0 && --sc->tx_timer == 0)
1239 nve_watchdog(sc);
1239 callout_reset(&sc->stat_callout, hz, nve_tick, sc);
1240
1241 return;
1242}
1243
1244/* Update ifnet data structure with collected interface stats from API */
1245static void
1246nve_update_stats(struct nve_softc *sc)

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

1302
1303 DEBUGOUT(NVE_DEBUG_MII, "nve: nve_miibus_writereg - exit\n");
1304
1305 return 0;
1306}
1307
1308/* Watchdog timer to prevent PHY lockups */
1309static void
1240 callout_reset(&sc->stat_callout, hz, nve_tick, sc);
1241
1242 return;
1243}
1244
1245/* Update ifnet data structure with collected interface stats from API */
1246static void
1247nve_update_stats(struct nve_softc *sc)

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

1303
1304 DEBUGOUT(NVE_DEBUG_MII, "nve: nve_miibus_writereg - exit\n");
1305
1306 return 0;
1307}
1308
1309/* Watchdog timer to prevent PHY lockups */
1310static void
1310nve_watchdog(struct ifnet *ifp)
1311nve_watchdog(struct nve_softc *sc)
1311{
1312{
1312 struct nve_softc *sc = ifp->if_softc;
1313 struct ifnet *ifp;
1313 int pending_txs_start;
1314
1314 int pending_txs_start;
1315
1315 NVE_LOCK(sc);
1316 NVE_LOCK_ASSERT(sc);
1317 ifp = sc->ifp;
1316
1317 /*
1318 * The nvidia driver blob defers tx completion notifications.
1319 * Thus, sometimes the watchdog timer will go off when the
1320 * tx engine is fine, but the tx completions are just deferred.
1321 * Try kicking the driver blob to clear out any pending tx
1322 * completions. If that clears up any of the pending tx
1323 * operations, then just return without printing the warning
1324 * message or resetting the adapter, as we can then conclude
1325 * the chip hasn't actually crashed (it's still sending packets).
1326 */
1327 pending_txs_start = sc->pending_txs;
1328 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
1329 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
1330 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
1318
1319 /*
1320 * The nvidia driver blob defers tx completion notifications.
1321 * Thus, sometimes the watchdog timer will go off when the
1322 * tx engine is fine, but the tx completions are just deferred.
1323 * Try kicking the driver blob to clear out any pending tx
1324 * completions. If that clears up any of the pending tx
1325 * operations, then just return without printing the warning
1326 * message or resetting the adapter, as we can then conclude
1327 * the chip hasn't actually crashed (it's still sending packets).
1328 */
1329 pending_txs_start = sc->pending_txs;
1330 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
1331 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
1332 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
1331 if (sc->pending_txs < pending_txs_start) {
1332 NVE_UNLOCK(sc);
1333 if (sc->pending_txs < pending_txs_start)
1333 return;
1334 return;
1334 }
1335
1336 device_printf(sc->dev, "device timeout (%d)\n", sc->pending_txs);
1337
1338 sc->tx_errors++;
1339
1340 nve_stop(sc);
1335
1336 device_printf(sc->dev, "device timeout (%d)\n", sc->pending_txs);
1337
1338 sc->tx_errors++;
1339
1340 nve_stop(sc);
1341 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1342 nve_init_locked(sc);
1343
1344 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1345 nve_ifstart_locked(ifp);
1341 nve_init_locked(sc);
1342
1343 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1344 nve_ifstart_locked(ifp);
1346 NVE_UNLOCK(sc);
1347
1348 return;
1349}
1350
1351/* --- Start of NVOSAPI interface --- */
1352
1353/* Allocate DMA enabled general use memory for API */
1354static NV_SINT32
1355nve_osalloc(PNV_VOID ctx, PMEMORY_BLOCK mem)
1356{

--- 443 unchanged lines hidden ---
1345}
1346
1347/* --- Start of NVOSAPI interface --- */
1348
1349/* Allocate DMA enabled general use memory for API */
1350static NV_SINT32
1351nve_osalloc(PNV_VOID ctx, PMEMORY_BLOCK mem)
1352{

--- 443 unchanged lines hidden ---