2 * Copyright (c) 2003, 2004 by Quinton Dolan <q@onthenet.com.au>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $Id: if_nv.c,v 1.20 2005/03/12 01:11:00 q Exp $
27 * $DragonFly: src/sys/dev/netif/nv/Attic/if_nv.c,v 1.15 2005/06/15 11:35:22 joerg Exp $
31 * NVIDIA nForce MCP Networking Adapter driver
33 * This is a port of the NVIDIA MCP Linux ethernet driver distributed by NVIDIA
34 * through their web site.
36 * All mainstream nForce and nForce2 motherboards are supported. This module
37 * is as stable, sometimes more stable, than the linux version. (Recent
38 * Linux stability issues seem to be related to some issues with newer
39 * distributions using GCC 3.x, however this don't appear to effect FreeBSD
42 * In accordance with the NVIDIA distribution license it is necessary to
43 * link this module against the nvlibnet.o binary object included in the
44 * Linux driver source distribution. The binary component is not modified in
45 * any way and is simply linked against a FreeBSD equivalent of the nvnet.c
46 * linux kernel module "wrapper".
48 * The Linux driver uses a common code API that is shared between Win32 and
49 * i386 Linux. This abstracts the low level driver functions and uses
50 * callbacks and hooks to access the underlying hardware device. By using
51 * this same API in a FreeBSD kernel module it is possible to support the
52 * hardware without breaching the Linux source distributions licensing
53 * requirements, or obtaining the hardware programming specifications.
55 * Although not conventional, it works, and given the relatively small
56 * amount of hardware centric code, it's hopefully no more buggy than its
59 * NVIDIA now suppport the nForce3 AMD64 platform, however I have been
60 * unable to access such a system to verify support. However, the code is
61 * reported to work with little modification when compiled with the AMD64
62 * version of the NVIDIA Linux library. All that should be necessary to make
63 * the driver work is to link it directly into the kernel, instead of as a
64 * module, and apply the docs/amd64.diff patch in this source distribution to
65 * the NVIDIA Linux driver source.
67 * This driver should work on all versions of FreeBSD since 4.9/5.1 as well
68 * as recent versions of DragonFly.
70 * Written by Quinton Dolan <q@onthenet.com.au>
71 * Portions based on existing FreeBSD network drivers.
72 * NVIDIA API usage derived from distributed NVIDIA NVNET driver source files.
74 * $Id: if_nv.c,v 1.9 2003/12/13 15:27:40 q Exp $
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/sockio.h>
81 #include <sys/malloc.h>
82 #include <sys/kernel.h>
83 #include <sys/socket.h>
84 #include <sys/sysctl.h>
85 #include <sys/queue.h>
86 #include <sys/module.h>
87 #include <sys/thread2.h>
90 #include <net/ifq_var.h>
91 #include <net/if_arp.h>
92 #include <net/ethernet.h>
93 #include <net/if_dl.h>
94 #include <net/if_media.h>
98 #include <net/vlan/if_vlan_var.h>
100 #include <machine/bus_memio.h>
101 #include <machine/bus.h>
102 #include <machine/resource.h>
104 #include <vm/vm.h> /* for vtophys */
105 #include <vm/pmap.h> /* for vtophys */
106 #include <machine/clock.h> /* for DELAY */
108 #include <sys/rman.h>
110 #include <bus/pci/pcireg.h>
111 #include <bus/pci/pcivar.h>
113 #include <dev/netif/mii_layer/mii.h>
114 #include <dev/netif/mii_layer/miivar.h>
116 MODULE_DEPEND(nv, pci, 1, 1, 1);
117 MODULE_DEPEND(nv, miibus, 1, 1, 1);
119 #include "if_nvreg.h"
120 #include "miibus_if.h"
122 static int nv_probe(device_t);
123 static int nv_attach(device_t);
124 static int nv_detach(device_t);
125 static void nv_init(void *);
126 static void nv_stop(struct nv_softc *);
127 static void nv_shutdown(device_t);
128 static int nv_init_rings(struct nv_softc *);
129 static void nv_free_rings(struct nv_softc *);
131 static void nv_ifstart(struct ifnet *);
132 static int nv_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
133 static void nv_intr(void *);
134 static void nv_tick(void *);
135 static void nv_setmulti(struct nv_softc *);
136 static void nv_watchdog(struct ifnet *);
137 static void nv_update_stats(struct nv_softc *);
139 static int nv_ifmedia_upd(struct ifnet *);
140 static void nv_ifmedia_sts(struct ifnet *, struct ifmediareq *);
141 static int nv_miibus_readreg(device_t, int, int);
142 static void nv_miibus_writereg(device_t, int, int, int);
144 static void nv_dmamap_cb(void *, bus_dma_segment_t *, int, int);
145 static void nv_dmamap_tx_cb(void *, bus_dma_segment_t *, int, bus_size_t, int);
147 static NV_SINT32 nv_osalloc(PNV_VOID, PMEMORY_BLOCK);
148 static NV_SINT32 nv_osfree(PNV_VOID, PMEMORY_BLOCK);
149 static NV_SINT32 nv_osallocex(PNV_VOID, PMEMORY_BLOCKEX);
150 static NV_SINT32 nv_osfreeex(PNV_VOID, PMEMORY_BLOCKEX);
151 static NV_SINT32 nv_osclear(PNV_VOID, PNV_VOID, NV_SINT32);
152 static NV_SINT32 nv_osdelay(PNV_VOID, NV_UINT32);
153 static NV_SINT32 nv_osallocrxbuf(PNV_VOID, PMEMORY_BLOCK, PNV_VOID *);
154 static NV_SINT32 nv_osfreerxbuf(PNV_VOID, PMEMORY_BLOCK, PNV_VOID);
155 static NV_SINT32 nv_ospackettx(PNV_VOID, PNV_VOID, NV_UINT32);
156 static NV_SINT32 nv_ospacketrx(PNV_VOID, PNV_VOID, NV_UINT32, NV_UINT8 *, NV_UINT8);
157 static NV_SINT32 nv_oslinkchg(PNV_VOID, NV_SINT32);
158 static NV_SINT32 nv_osalloctimer(PNV_VOID, PNV_VOID *);
159 static NV_SINT32 nv_osfreetimer(PNV_VOID, PNV_VOID);
160 static NV_SINT32 nv_osinittimer(PNV_VOID, PNV_VOID, PTIMER_FUNC, PNV_VOID);
161 static NV_SINT32 nv_ossettimer(PNV_VOID, PNV_VOID, NV_UINT32);
162 static NV_SINT32 nv_oscanceltimer(PNV_VOID, PNV_VOID);
164 static NV_SINT32 nv_ospreprocpkt(PNV_VOID, PNV_VOID, PNV_VOID *, NV_UINT8 *, NV_UINT8);
165 static PNV_VOID nv_ospreprocpktnopq(PNV_VOID, PNV_VOID);
166 static NV_SINT32 nv_osindicatepkt(PNV_VOID, PNV_VOID *, NV_UINT32);
167 static NV_SINT32 nv_oslockalloc(PNV_VOID, NV_SINT32, PNV_VOID *);
168 static NV_SINT32 nv_oslockacquire(PNV_VOID, NV_SINT32, PNV_VOID);
169 static NV_SINT32 nv_oslockrelease(PNV_VOID, NV_SINT32, PNV_VOID);
170 static PNV_VOID nv_osreturnbufvirt(PNV_VOID, PNV_VOID);
172 static device_method_t nv_methods[] = {
173 /* Device interface */
174 DEVMETHOD(device_probe, nv_probe),
175 DEVMETHOD(device_attach, nv_attach),
176 DEVMETHOD(device_detach, nv_detach),
177 DEVMETHOD(device_shutdown, nv_shutdown),
180 DEVMETHOD(bus_print_child, bus_generic_print_child),
181 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
184 DEVMETHOD(miibus_readreg, nv_miibus_readreg),
185 DEVMETHOD(miibus_writereg, nv_miibus_writereg),
190 static driver_t nv_driver = {
193 sizeof(struct nv_softc)
196 static devclass_t nv_devclass;
198 static int nv_pollinterval = 0;
199 SYSCTL_INT(_hw, OID_AUTO, nv_pollinterval, CTLFLAG_RW,
200 &nv_pollinterval, 0, "delay between interface polls");
202 DRIVER_MODULE(nv, pci, nv_driver, nv_devclass, 0, 0);
203 DRIVER_MODULE(miibus, nv, miibus_driver, miibus_devclass, 0, 0);
205 static struct nv_type nv_devs[] = {
206 {NVIDIA_VENDORID, NFORCE_MCPNET1_DEVICEID,
207 "NVIDIA nForce MCP Networking Adapter"},
208 {NVIDIA_VENDORID, NFORCE_MCPNET2_DEVICEID,
209 "NVIDIA nForce MCP2 Networking Adapter"},
210 {NVIDIA_VENDORID, NFORCE_MCPNET3_DEVICEID,
211 "NVIDIA nForce MCP3 Networking Adapter"},
212 {NVIDIA_VENDORID, NFORCE_MCPNET4_DEVICEID,
213 "NVIDIA nForce MCP4 Networking Adapter"},
214 {NVIDIA_VENDORID, NFORCE_MCPNET5_DEVICEID,
215 "NVIDIA nForce MCP5 Networking Adapter"},
216 {NVIDIA_VENDORID, NFORCE_MCPNET6_DEVICEID,
217 "NVIDIA nForce MCP6 Networking Adapter"},
218 {NVIDIA_VENDORID, NFORCE_MCPNET7_DEVICEID,
219 "NVIDIA nForce MCP7 Networking Adapter"},
223 /* DMA MEM map callback function to get data segment physical address */
225 nv_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nsegs, int error)
231 ("Too many DMA segments returned when mapping DMA memory"));
232 *(bus_addr_t *)arg = segs->ds_addr;
235 /* DMA RX map callback function to get data segment physical address */
237 nv_dmamap_rx_cb(void *arg, bus_dma_segment_t * segs, int nsegs, bus_size_t mapsize, int error)
241 *(bus_addr_t *)arg = segs->ds_addr;
245 * DMA TX buffer callback function to allocate fragment data segment
249 nv_dmamap_tx_cb(void *arg, bus_dma_segment_t * segs, int nsegs, bus_size_t mapsize, int error)
251 struct nv_tx_desc *info = arg;
255 KASSERT(nsegs < NV_MAX_FRAGS,
256 ("Too many DMA segments returned when mapping mbuf"));
257 info->numfrags = nsegs;
258 bcopy(segs, info->frags, nsegs * sizeof(bus_dma_segment_t));
261 /* Probe for supported hardware ID's */
263 nv_probe(device_t dev)
265 struct nv_type *t = nv_devs;
267 /* Check for matching PCI DEVICE ID's */
268 while (t->name != NULL) {
269 if ((pci_get_vendor(dev) == t->vid_id) &&
270 (pci_get_device(dev) == t->dev_id)) {
271 device_set_desc(dev, t->name);
280 /* Attach driver and initialise hardware for use */
282 nv_attach(device_t dev)
284 u_char eaddr[ETHER_ADDR_LEN];
288 ADAPTER_OPEN_PARAMS OpenParams;
289 int error = 0, i, rid;
291 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_attach - entry\n");
293 sc = device_get_softc(dev);
296 callout_init(&sc->nv_stat_timer);
298 /* Preinitialize data structures */
299 bzero(&OpenParams, sizeof(ADAPTER_OPEN_PARAMS));
301 /* Enable bus mastering */
302 pci_enable_busmaster(dev);
304 /* Allocate memory mapped address space */
306 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
308 if (sc->res == NULL) {
309 device_printf(dev, "couldn't map memory\n");
313 sc->sc_st = rman_get_bustag(sc->res);
314 sc->sc_sh = rman_get_bushandle(sc->res);
316 /* Allocate interrupt */
318 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
319 RF_SHAREABLE | RF_ACTIVE);
321 if (sc->irq == NULL) {
322 device_printf(dev, "couldn't map interrupt\n");
326 /* Allocate DMA tags */
327 error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
328 BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES * NV_MAX_FRAGS,
329 NV_MAX_FRAGS, MCLBYTES, 0,
332 device_printf(dev, "couldn't allocate dma tag\n");
335 error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
336 BUS_SPACE_MAXADDR, NULL, NULL,
337 sizeof(struct nv_rx_desc) * RX_RING_SIZE, 1,
338 sizeof(struct nv_rx_desc) * RX_RING_SIZE, 0,
341 device_printf(dev, "couldn't allocate dma tag\n");
344 error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
345 BUS_SPACE_MAXADDR, NULL, NULL,
346 sizeof(struct nv_tx_desc) * TX_RING_SIZE, 1,
347 sizeof(struct nv_tx_desc) * TX_RING_SIZE, 0,
350 device_printf(dev, "couldn't allocate dma tag\n");
354 error = bus_dmamap_create(sc->ttag, 0, &sc->tmap);
356 device_printf(dev, "couldn't create dma map\n");
360 /* Allocate DMA safe memory and get the DMA addresses. */
361 error = bus_dmamem_alloc(sc->ttag, (void **)&sc->tx_desc,
362 BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->tmap);
364 device_printf(dev, "couldn't allocate dma memory\n");
367 error = bus_dmamap_load(sc->ttag, sc->tmap, sc->tx_desc,
368 sizeof(struct nv_tx_desc) * TX_RING_SIZE, nv_dmamap_cb,
371 device_printf(dev, "couldn't map dma memory\n");
375 error = bus_dmamap_create(sc->rtag, 0, &sc->rmap);
377 device_printf(dev, "couldn't create dma map\n");
381 error = bus_dmamem_alloc(sc->rtag, (void **)&sc->rx_desc,
382 BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->rmap);
384 device_printf(dev, "couldn't allocate dma memory\n");
387 error = bus_dmamap_load(sc->rtag, sc->rmap, sc->rx_desc,
388 sizeof(struct nv_rx_desc) * RX_RING_SIZE, nv_dmamap_cb,
391 device_printf(dev, "couldn't map dma memory\n");
394 /* Initialize rings. */
395 if (nv_init_rings(sc)) {
396 device_printf(dev, "failed to init rings\n");
400 /* Setup NVIDIA API callback routines */
403 osapi->pfnAllocMemory = nv_osalloc;
404 osapi->pfnFreeMemory = nv_osfree;
405 osapi->pfnAllocMemoryEx = nv_osallocex;
406 osapi->pfnFreeMemoryEx = nv_osfreeex;
407 osapi->pfnClearMemory = nv_osclear;
408 osapi->pfnStallExecution = nv_osdelay;
409 osapi->pfnAllocReceiveBuffer = nv_osallocrxbuf;
410 osapi->pfnFreeReceiveBuffer = nv_osfreerxbuf;
411 osapi->pfnPacketWasSent = nv_ospackettx;
412 osapi->pfnPacketWasReceived = nv_ospacketrx;
413 osapi->pfnLinkStateHasChanged = nv_oslinkchg;
414 osapi->pfnAllocTimer = nv_osalloctimer;
415 osapi->pfnFreeTimer = nv_osfreetimer;
416 osapi->pfnInitializeTimer = nv_osinittimer;
417 osapi->pfnSetTimer = nv_ossettimer;
418 osapi->pfnCancelTimer = nv_oscanceltimer;
419 osapi->pfnPreprocessPacket = nv_ospreprocpkt;
420 osapi->pfnPreprocessPacketNopq = nv_ospreprocpktnopq;
421 osapi->pfnIndicatePackets = nv_osindicatepkt;
422 osapi->pfnLockAlloc = nv_oslockalloc;
423 osapi->pfnLockAcquire = nv_oslockacquire;
424 osapi->pfnLockRelease = nv_oslockrelease;
425 osapi->pfnReturnBufferVirtual = nv_osreturnbufvirt;
428 sc->max_frame_size = ETHERMTU + ETHER_HDR_LEN + FCS_LEN;
430 /* TODO - We don't support hardware offload yet */
434 /* Set NVIDIA API startup parameters */
435 OpenParams.MaxDpcLoop = 2;
436 OpenParams.MaxRxPkt = RX_RING_SIZE;
437 OpenParams.MaxTxPkt = TX_RING_SIZE;
438 OpenParams.SentPacketStatusSuccess = 1;
439 OpenParams.SentPacketStatusFailure = 0;
440 OpenParams.MaxRxPktToAccumulate = 6;
441 OpenParams.ulPollInterval = nv_pollinterval;
442 OpenParams.SetForcedModeEveryNthRxPacket = 0;
443 OpenParams.SetForcedModeEveryNthTxPacket = 0;
444 OpenParams.RxForcedInterrupt = 0;
445 OpenParams.TxForcedInterrupt = 0;
446 OpenParams.pOSApi = osapi;
447 OpenParams.pvHardwareBaseAddress = rman_get_virtual(sc->res);
448 OpenParams.bASFEnabled = 0;
449 OpenParams.ulDescriptorVersion = sc->hwmode;
450 OpenParams.ulMaxPacketSize = sc->max_frame_size;
451 OpenParams.DeviceId = pci_get_device(dev);
453 /* Open NVIDIA Hardware API */
454 error = ADAPTER_Open(&OpenParams, (void **)&(sc->hwapi), &sc->phyaddr);
456 device_printf(dev, "failed to open NVIDIA Hardware API: 0x%x\n", error);
460 /* TODO - Add support for MODE2 hardware offload */
462 bzero(&sc->adapterdata, sizeof(sc->adapterdata));
464 sc->adapterdata.ulMediaIF = sc->media;
465 sc->adapterdata.ulModeRegTxReadCompleteEnable = 1;
466 sc->hwapi->pfnSetCommonData(sc->hwapi->pADCX, &sc->adapterdata);
468 /* MAC is loaded backwards into h/w reg */
469 sc->hwapi->pfnGetNodeAddress(sc->hwapi->pADCX, sc->original_mac_addr);
470 for (i = 0; i < 6; i++) {
471 eaddr[i] = sc->original_mac_addr[5 - i];
473 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, eaddr);
474 bcopy(eaddr, (char *)&sc->sc_macaddr, ETHER_ADDR_LEN);
476 DEBUGOUT(NV_DEBUG_INIT, "nv: do mii_phy_probe\n");
478 /* Probe device for MII interface to PHY */
479 if (mii_phy_probe(dev, &sc->miibus,
480 nv_ifmedia_upd, nv_ifmedia_sts)) {
481 device_printf(dev, "MII without any phy!\n");
485 /* Setup interface parameters */
488 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
489 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
490 ifp->if_ioctl = nv_ioctl;
491 ifp->if_start = nv_ifstart;
492 ifp->if_watchdog = nv_watchdog;
494 ifp->if_init = nv_init;
495 ifp->if_mtu = ETHERMTU;
496 ifp->if_baudrate = IF_Mbps(100);
497 ifp->if_capabilities |= IFCAP_VLAN_MTU;
498 ifq_set_maxlen(&ifp->if_snd, TX_RING_SIZE - 1);
499 ifq_set_ready(&ifp->if_snd);
501 /* Attach to OS's managers. */
502 ether_ifattach(ifp, sc->sc_macaddr);
504 /* Activate our interrupt handler. - attach last to avoid lock */
505 error = bus_setup_intr(sc->dev, sc->irq, INTR_TYPE_NET,
506 nv_intr, sc, &sc->sc_ih, NULL);
509 device_printf(sc->dev, "couldn't set up interrupt handler\n");
512 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_attach - exit\n");
521 /* Detach interface for module unload */
523 nv_detach(device_t dev)
525 struct nv_softc *sc = device_get_softc(dev);
530 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - entry\n");
532 ifp = &sc->arpcom.ac_if;
534 if (device_is_attached(dev)) {
540 device_delete_child(dev, sc->miibus);
541 bus_generic_detach(dev);
543 /* Reload unreversed address back into MAC in original state */
544 if (sc->original_mac_addr)
545 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, sc->original_mac_addr);
547 DEBUGOUT(NV_DEBUG_DEINIT, "nv: do pfnClose\n");
548 /* Detach from NVIDIA hardware API */
549 if (sc->hwapi->pfnClose)
550 sc->hwapi->pfnClose(sc->hwapi->pADCX, FALSE);
551 /* Release resources */
553 bus_teardown_intr(sc->dev, sc->irq, sc->sc_ih);
555 bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq);
557 bus_release_resource(sc->dev, SYS_RES_MEMORY, NV_RID, sc->res);
562 bus_dmamap_unload(sc->rtag, sc->rmap);
563 bus_dmamem_free(sc->rtag, sc->rx_desc, sc->rmap);
564 bus_dmamap_destroy(sc->rtag, sc->rmap);
567 bus_dma_tag_destroy(sc->mtag);
569 bus_dma_tag_destroy(sc->ttag);
571 bus_dma_tag_destroy(sc->rtag);
575 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - exit\n");
580 /* Initialise interface and start it "RUNNING" */
584 struct nv_softc *sc = xsc;
590 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init - entry (%d)\n", sc->linkup);
594 /* Do nothing if already running */
595 if (ifp->if_flags & IFF_RUNNING)
600 DEBUGOUT(NV_DEBUG_INIT, "nv: do pfnInit\n");
601 /* Setup Hardware interface and allocate memory structures */
602 error = sc->hwapi->pfnInit(sc->hwapi->pADCX,
604 0, /* force full duplex */
606 0, /* force async mode */
610 device_printf(sc->dev, "failed to start NVIDIA Hardware interface\n");
613 /* Set the MAC address */
614 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, sc->sc_macaddr);
615 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
616 sc->hwapi->pfnStart(sc->hwapi->pADCX);
618 /* Setup multicast filter */
622 /* Update interface parameters */
623 ifp->if_flags |= IFF_RUNNING;
624 ifp->if_flags &= ~IFF_OACTIVE;
626 callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc);
628 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init - exit\n");
636 /* Stop interface activity ie. not "RUNNING" */
638 nv_stop(struct nv_softc *sc)
644 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_stop - entry\n");
649 /* Cancel tick timer */
650 callout_stop(&sc->nv_stat_timer);
652 /* Stop hardware activity */
653 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
654 sc->hwapi->pfnStop(sc->hwapi->pADCX, 0);
656 DEBUGOUT(NV_DEBUG_DEINIT, "nv: do pfnDeinit\n");
657 /* Shutdown interface and deallocate memory buffers */
658 if (sc->hwapi->pfnDeinit)
659 sc->hwapi->pfnDeinit(sc->hwapi->pADCX, 0);
665 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
667 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_stop - exit\n");
674 /* Shutdown interface for unload/reboot */
676 nv_shutdown(device_t dev)
680 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_shutdown\n");
682 sc = device_get_softc(dev);
684 /* Stop hardware activity */
688 /* Allocate TX ring buffers */
690 nv_init_rings(struct nv_softc *sc)
696 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init_rings - entry\n");
698 sc->cur_rx = sc->cur_tx = sc->pending_rxs = sc->pending_txs = 0;
699 /* Initialise RX ring */
700 for (i = 0; i < RX_RING_SIZE; i++) {
701 struct nv_rx_desc *desc = sc->rx_desc + i;
702 struct nv_map_buffer *buf = &desc->buf;
704 buf->mbuf = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
705 if (buf->mbuf == NULL) {
706 device_printf(sc->dev, "couldn't allocate mbuf\n");
711 buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
712 m_adj(buf->mbuf, ETHER_ALIGN);
714 error = bus_dmamap_create(sc->mtag, 0, &buf->map);
716 device_printf(sc->dev, "couldn't create dma map\n");
720 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
721 nv_dmamap_rx_cb, &desc->paddr, 0);
723 device_printf(sc->dev, "couldn't dma map mbuf\n");
727 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
729 desc->buflength = buf->mbuf->m_len;
730 desc->vaddr = mtod(buf->mbuf, caddr_t);
732 bus_dmamap_sync(sc->rtag, sc->rmap,
733 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
735 /* Initialize TX ring */
736 for (i = 0; i < TX_RING_SIZE; i++) {
737 struct nv_tx_desc *desc = sc->tx_desc + i;
738 struct nv_map_buffer *buf = &desc->buf;
742 error = bus_dmamap_create(sc->mtag, 0, &buf->map);
744 device_printf(sc->dev, "couldn't create dma map\n");
749 bus_dmamap_sync(sc->ttag, sc->tmap,
750 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
752 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init_rings - exit\n");
760 /* Free the TX ring buffers */
762 nv_free_rings(struct nv_softc *sc)
768 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_free_rings - entry\n");
770 for (i = 0; i < RX_RING_SIZE; i++) {
771 struct nv_rx_desc *desc = sc->rx_desc + i;
772 struct nv_map_buffer *buf = &desc->buf;
775 bus_dmamap_unload(sc->mtag, buf->map);
776 bus_dmamap_destroy(sc->mtag, buf->map);
782 for (i = 0; i < TX_RING_SIZE; i++) {
783 struct nv_tx_desc *desc = sc->tx_desc + i;
784 struct nv_map_buffer *buf = &desc->buf;
787 bus_dmamap_unload(sc->mtag, buf->map);
788 bus_dmamap_destroy(sc->mtag, buf->map);
794 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_free_rings - exit\n");
799 /* Main loop for sending packets from OS to interface */
801 nv_ifstart(struct ifnet *ifp)
803 struct nv_softc *sc = ifp->if_softc;
804 struct nv_map_buffer *buf;
806 struct nv_tx_desc *desc;
807 ADAPTER_WRITE_DATA txdata;
810 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_ifstart - entry\n");
812 /* If link is down/busy or queue is empty do nothing */
813 if (ifp->if_flags & IFF_OACTIVE || ifq_is_empty(&ifp->if_snd))
816 /* Transmit queued packets until sent or TX ring is full */
817 while (sc->pending_txs < TX_RING_SIZE) {
818 desc = sc->tx_desc + sc->cur_tx;
821 /* Get next packet to send. */
822 m0 = ifq_dequeue(&ifp->if_snd);
824 /* If nothing to send, return. */
828 /* Map MBUF for DMA access */
829 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m0,
830 nv_dmamap_tx_cb, desc, BUS_DMA_NOWAIT);
832 if (error && error != EFBIG) {
838 * Packet has too many fragments - defrag into new mbuf
842 m = m_defrag(m0, MB_DONTWAIT);
851 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m,
852 nv_dmamap_tx_cb, desc, BUS_DMA_NOWAIT);
859 /* Do sync on DMA bounce buffer */
860 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREWRITE);
863 txdata.ulNumberOfElements = desc->numfrags;
864 txdata.pvID = (PVOID)desc;
866 /* Put fragments into API element list */
867 txdata.ulTotalLength = buf->mbuf->m_len;
868 for (i = 0; i < desc->numfrags; i++) {
869 txdata.sElement[i].ulLength = (ulong)desc->frags[i].ds_len;
870 txdata.sElement[i].pPhysical = (PVOID)desc->frags[i].ds_addr;
873 /* Send packet to Nvidia API for transmission */
874 error = sc->hwapi->pfnWrite(sc->hwapi->pADCX, &txdata);
877 case ADAPTERERR_NONE:
878 /* Packet was queued in API TX queue successfully */
880 sc->cur_tx = (sc->cur_tx + 1) % TX_RING_SIZE;
883 case ADAPTERERR_TRANSMIT_QUEUE_FULL:
884 /* The API TX queue is full - requeue the packet */
885 device_printf(sc->dev, "nv_ifstart: transmit queue is full\n");
886 ifp->if_flags |= IFF_OACTIVE;
887 bus_dmamap_unload(sc->mtag, buf->map);
892 /* The API failed to queue/send the packet so dump it */
893 device_printf(sc->dev, "nv_ifstart: transmit error\n");
894 bus_dmamap_unload(sc->mtag, buf->map);
900 /* Set watchdog timer. */
903 /* Copy packet to BPF tap */
906 ifp->if_flags |= IFF_OACTIVE;
908 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_ifstart - exit\n");
911 /* Handle IOCTL events */
913 nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
915 struct nv_softc *sc = ifp->if_softc;
916 struct ifreq *ifr = (struct ifreq *) data;
917 struct mii_data *mii;
922 DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - entry\n");
927 if (ifp->if_mtu == ifr->ifr_mtu)
929 if (ifr->ifr_mtu + ifp->if_hdrlen <= MAX_PACKET_SIZE_1518) {
930 ifp->if_mtu = ifr->ifr_mtu;
938 /* Setup interface flags */
939 if (ifp->if_flags & IFF_UP) {
940 if ((ifp->if_flags & IFF_RUNNING) == 0) {
945 if (ifp->if_flags & IFF_RUNNING) {
951 /* Handle IFF_PROMISC and IFF_ALLMULTI flags. */
957 /* Setup multicast filter */
958 if (ifp->if_flags & IFF_RUNNING) {
964 /* Get/Set interface media parameters */
965 mii = device_get_softc(sc->miibus);
966 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
970 /* Everything else we forward to generic ether ioctl */
971 error = ether_ioctl(ifp, command, data);
975 DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - exit\n");
982 /* Interrupt service routine */
986 struct nv_softc *sc = arg;
987 struct ifnet *ifp = &sc->sc_if;
989 DEBUGOUT(NV_DEBUG_INTERRUPT, "nv: nv_intr - entry\n");
991 if (!ifp->if_flags & IFF_UP) {
995 /* Handle interrupt event */
996 if (sc->hwapi->pfnQueryInterrupt(sc->hwapi->pADCX)) {
997 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
998 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
1000 if (!ifq_is_empty(&ifp->if_snd))
1003 /* If no pending packets we don't need a timeout */
1004 if (sc->pending_txs == 0)
1005 sc->sc_if.if_timer = 0;
1007 DEBUGOUT(NV_DEBUG_INTERRUPT, "nv: nv_intr - exit\n");
1012 /* Setup multicast filters */
1014 nv_setmulti(struct nv_softc *sc)
1017 struct ifmultiaddr *ifma;
1018 PACKET_FILTER hwfilter;
1021 u_int8_t andaddr[6];
1025 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_setmulti - entry\n");
1029 /* Initialize filter */
1030 hwfilter.ulFilterFlags = 0;
1031 for (i = 0; i < 6; i++) {
1032 hwfilter.acMulticastAddress[i] = 0;
1033 hwfilter.acMulticastMask[i] = 0;
1036 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) {
1037 /* Accept all packets */
1038 hwfilter.ulFilterFlags |= ACCEPT_ALL_PACKETS;
1039 sc->hwapi->pfnSetPacketFilter(sc->hwapi->pADCX, &hwfilter);
1043 /* Setup multicast filter */
1044 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1047 if (ifma->ifma_addr->sa_family != AF_LINK)
1050 addrp = LLADDR((struct sockaddr_dl *) ifma->ifma_addr);
1051 for (i = 0; i < 6; i++) {
1052 u_int8_t mcaddr = addrp[i];
1053 andaddr[i] &= mcaddr;
1054 oraddr[i] |= mcaddr;
1057 for (i = 0; i < 6; i++) {
1058 hwfilter.acMulticastAddress[i] = andaddr[i] & oraddr[i];
1059 hwfilter.acMulticastMask[i] = andaddr[i] | (~oraddr[i]);
1062 /* Send filter to NVIDIA API */
1063 sc->hwapi->pfnSetPacketFilter(sc->hwapi->pADCX, &hwfilter);
1067 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_setmulti - exit\n");
1072 /* Change the current media/mediaopts */
1074 nv_ifmedia_upd(struct ifnet *ifp)
1076 struct nv_softc *sc = ifp->if_softc;
1077 struct mii_data *mii;
1079 DEBUGOUT(NV_DEBUG_MII, "nv: nv_ifmedia_upd\n");
1081 mii = device_get_softc(sc->miibus);
1083 if (mii->mii_instance) {
1084 struct mii_softc *miisc;
1085 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1086 miisc = LIST_NEXT(miisc, mii_list)) {
1087 mii_phy_reset(miisc);
1095 /* Update current miibus PHY status of media */
1097 nv_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1099 struct nv_softc *sc;
1100 struct mii_data *mii;
1102 DEBUGOUT(NV_DEBUG_MII, "nv: nv_ifmedia_sts\n");
1105 mii = device_get_softc(sc->miibus);
1108 ifmr->ifm_active = mii->mii_media_active;
1109 ifmr->ifm_status = mii->mii_media_status;
1114 /* miibus tick timer - maintain link status */
1118 struct nv_softc *sc = xsc;
1119 struct mii_data *mii;
1125 nv_update_stats(sc);
1127 mii = device_get_softc(sc->miibus);
1130 if (mii->mii_media_status & IFM_ACTIVE &&
1131 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1132 if (!ifq_is_empty(&ifp->if_snd))
1135 callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc);
1142 /* Update ifnet data structure with collected interface stats from API */
1144 nv_update_stats(struct nv_softc *sc)
1146 struct ifnet *ifp = &sc->sc_if;
1147 ADAPTER_STATS stats;
1152 sc->hwapi->pfnGetStatistics(sc->hwapi->pADCX, &stats);
1154 ifp->if_ipackets = stats.ulSuccessfulReceptions;
1155 ifp->if_ierrors = stats.ulMissedFrames +
1156 stats.ulFailedReceptions +
1158 stats.ulFramingErrors +
1159 stats.ulOverFlowErrors;
1161 ifp->if_opackets = stats.ulSuccessfulTransmissions;
1162 ifp->if_oerrors = sc->tx_errors +
1163 stats.ulFailedTransmissions +
1164 stats.ulRetryErrors +
1165 stats.ulUnderflowErrors +
1166 stats.ulLossOfCarrierErrors +
1167 stats.ulLateCollisionErrors;
1169 ifp->if_collisions = stats.ulLateCollisionErrors;
1176 /* miibus Read PHY register wrapper - calls Nvidia API entry point */
1178 nv_miibus_readreg(device_t dev, int phy, int reg)
1180 struct nv_softc *sc = device_get_softc(dev);
1183 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_readreg - entry\n");
1185 ADAPTER_ReadPhy(sc->hwapi->pADCX, phy, reg, &data);
1187 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_readreg - exit\n");
1192 /* miibus Write PHY register wrapper - calls Nvidia API entry point */
1194 nv_miibus_writereg(device_t dev, int phy, int reg, int data)
1196 struct nv_softc *sc = device_get_softc(dev);
1198 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_writereg - entry\n");
1200 ADAPTER_WritePhy(sc->hwapi->pADCX, phy, reg, (ulong)data);
1202 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_writereg - exit\n");
1207 /* Watchdog timer to prevent PHY lockups */
1209 nv_watchdog(struct ifnet *ifp)
1211 struct nv_softc *sc = ifp->if_softc;
1213 device_printf(sc->dev, "device timeout (%d)\n", sc->pending_txs);
1218 ifp->if_flags &= ~IFF_RUNNING;
1221 if (!ifq_is_empty(&ifp->if_snd))
1227 /* --- Start of NVOSAPI interface --- */
1229 /* Allocate DMA enabled general use memory for API */
1231 nv_osalloc(PNV_VOID ctx, PMEMORY_BLOCK mem)
1233 struct nv_softc *sc;
1234 bus_addr_t mem_physical;
1236 DEBUGOUT(NV_DEBUG_API, "nv: nv_osalloc - %d\n", mem->uiLength);
1238 sc = (struct nv_softc *)ctx;
1240 mem->pLogical = (PVOID)contigmalloc(mem->uiLength, M_DEVBUF,
1241 M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE, 0);
1243 if (!mem->pLogical) {
1244 device_printf(sc->dev, "memory allocation failed\n");
1247 memset(mem->pLogical, 0, (ulong)mem->uiLength);
1248 mem_physical = vtophys(mem->pLogical);
1249 mem->pPhysical = (PVOID)mem_physical;
1251 DEBUGOUT(NV_DEBUG_API, "nv: nv_osalloc %p/%p - %d\n",
1252 mem->pLogical, mem->pPhysical, mem->uiLength);
1257 /* Free allocated memory */
1259 nv_osfree(PNV_VOID ctx, PMEMORY_BLOCK mem)
1261 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfree - %p - %d\n",
1262 mem->pLogical, mem->uiLength);
1264 contigfree(mem->pLogical, PAGE_SIZE, M_DEVBUF);
1268 /* Copied directly from nvnet.c */
1270 nv_osallocex(PNV_VOID ctx, PMEMORY_BLOCKEX mem_block_ex)
1272 MEMORY_BLOCK mem_block;
1274 DEBUGOUT(NV_DEBUG_API, "nv: nv_osallocex\n");
1276 mem_block_ex->pLogical = NULL;
1277 mem_block_ex->uiLengthOrig = mem_block_ex->uiLength;
1279 if ((mem_block_ex->AllocFlags & ALLOC_MEMORY_ALIGNED) &&
1280 (mem_block_ex->AlignmentSize > 1)) {
1281 DEBUGOUT(NV_DEBUG_API, " aligning on %d\n",
1282 mem_block_ex->AlignmentSize);
1283 mem_block_ex->uiLengthOrig += mem_block_ex->AlignmentSize;
1285 mem_block.uiLength = mem_block_ex->uiLengthOrig;
1287 if (nv_osalloc(ctx, &mem_block) == 0) {
1290 mem_block_ex->pLogicalOrig = mem_block.pLogical;
1291 mem_block_ex->pPhysicalOrigLow = (uintptr_t)mem_block.pPhysical;
1292 mem_block_ex->pPhysicalOrigHigh = 0;
1294 mem_block_ex->pPhysical = mem_block.pPhysical;
1295 mem_block_ex->pLogical = mem_block.pLogical;
1297 if (mem_block_ex->uiLength != mem_block_ex->uiLengthOrig) {
1298 unsigned int offset;
1299 offset = mem_block_ex->pPhysicalOrigLow & (mem_block_ex->AlignmentSize - 1);
1302 mem_block_ex->pPhysical = (PVOID)((uintptr_t)mem_block_ex->pPhysical +
1303 mem_block_ex->AlignmentSize - offset);
1304 mem_block_ex->pLogical = (PVOID)((uintptr_t)mem_block_ex->pLogical +
1305 mem_block_ex->AlignmentSize - offset);
1307 } /* if (mem_block_ex->uiLength !=
1308 * mem_block_ex->uiLengthOrig) */
1312 /* Copied directly from nvnet.c */
1314 nv_osfreeex(PNV_VOID ctx, PMEMORY_BLOCKEX mem_block_ex)
1316 MEMORY_BLOCK mem_block;
1318 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfreeex\n");
1320 mem_block.pLogical = mem_block_ex->pLogicalOrig;
1321 mem_block.pPhysical = (PVOID)((uintptr_t)mem_block_ex->pPhysicalOrigLow);
1322 mem_block.uiLength = mem_block_ex->uiLengthOrig;
1324 return (nv_osfree(ctx, &mem_block));
1327 /* Clear memory region */
1329 nv_osclear(PNV_VOID ctx, PNV_VOID mem, NV_SINT32 length)
1331 DEBUGOUT(NV_DEBUG_API, "nv: nv_osclear\n");
1332 memset(mem, 0, length);
1336 /* Sleep for a tick */
1338 nv_osdelay(PNV_VOID ctx, NV_UINT32 usec)
1344 /* Allocate memory for rx buffer */
1346 nv_osallocrxbuf(PNV_VOID ctx, PMEMORY_BLOCK mem, PNV_VOID *id)
1348 struct nv_softc *sc = ctx;
1349 struct nv_rx_desc *desc;
1350 struct nv_map_buffer *buf;
1355 DEBUGOUT(NV_DEBUG_API, "nv: nv_osallocrxbuf\n");
1357 if (sc->pending_rxs == RX_RING_SIZE) {
1358 device_printf(sc->dev, "rx ring buffer is full\n");
1361 desc = sc->rx_desc + sc->cur_rx;
1364 if (buf->mbuf == NULL) {
1365 buf->mbuf = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
1366 if (buf->mbuf == NULL) {
1367 device_printf(sc->dev, "failed to allocate memory\n");
1370 buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
1371 m_adj(buf->mbuf, ETHER_ALIGN);
1373 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
1374 nv_dmamap_rx_cb, &desc->paddr, 0);
1376 device_printf(sc->dev, "failed to dmamap mbuf\n");
1381 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
1382 desc->buflength = buf->mbuf->m_len;
1383 desc->vaddr = mtod(buf->mbuf, PVOID);
1386 sc->cur_rx = (sc->cur_rx + 1) % RX_RING_SIZE;
1388 mem->pLogical = (void *)desc->vaddr;
1389 mem->pPhysical = (void *)desc->paddr;
1390 mem->uiLength = desc->buflength;
1402 /* Free the rx buffer */
1404 nv_osfreerxbuf(PNV_VOID ctx, PMEMORY_BLOCK mem, PNV_VOID id)
1406 struct nv_softc *sc = ctx;
1407 struct nv_rx_desc *desc;
1408 struct nv_map_buffer *buf;
1412 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfreerxbuf\n");
1414 desc = (struct nv_rx_desc *) id;
1418 bus_dmamap_unload(sc->mtag, buf->map);
1419 bus_dmamap_destroy(sc->mtag, buf->map);
1430 /* This gets called by the Nvidia API after our TX packet has been sent */
1432 nv_ospackettx(PNV_VOID ctx, PNV_VOID id, NV_UINT32 success)
1434 struct nv_softc *sc = ctx;
1435 struct nv_map_buffer *buf;
1436 struct nv_tx_desc *desc = (struct nv_tx_desc *) id;
1441 DEBUGOUT(NV_DEBUG_API, "nv: nv_ospackettx\n");
1447 /* Unload and free mbuf cluster */
1448 if (buf->mbuf == NULL)
1451 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTWRITE);
1452 bus_dmamap_unload(sc->mtag, buf->map);
1456 if (!ifq_is_empty(&ifp->if_snd) && sc->pending_txs < TX_RING_SIZE)
1465 /* This gets called by the Nvidia API when a new packet has been received */
1466 /* XXX What is newbuf used for? XXX */
1468 nv_ospacketrx(PNV_VOID ctx, PNV_VOID data, NV_UINT32 success,
1469 NV_UINT8 *newbuf, NV_UINT8 priority)
1471 struct nv_softc *sc = ctx;
1473 struct nv_rx_desc *desc;
1474 struct nv_map_buffer *buf;
1475 ADAPTER_READ_DATA *readdata;
1478 DEBUGOUT(NV_DEBUG_API, "nv: nv_ospacketrx\n");
1482 readdata = (ADAPTER_READ_DATA *) data;
1483 desc = readdata->pvID;
1485 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1488 /* Sync DMA bounce buffer. */
1489 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1491 /* First mbuf in packet holds the ethernet and packet headers */
1492 buf->mbuf->m_pkthdr.rcvif = ifp;
1493 buf->mbuf->m_pkthdr.len = buf->mbuf->m_len = readdata->ulTotalLength;
1495 bus_dmamap_unload(sc->mtag, buf->map);
1497 /* Give mbuf to OS. */
1498 (*ifp->if_input) (ifp, buf->mbuf);
1499 if (readdata->ulFilterMatch & ADREADFL_MULTICAST_MATCH)
1502 /* Blat the mbuf pointer, kernel will free the mbuf cluster */
1505 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1506 bus_dmamap_unload(sc->mtag, buf->map);
1511 sc->cur_rx = desc - sc->rx_desc;
1519 /* This gets called by NVIDIA API when the PHY link state changes */
1521 nv_oslinkchg(PNV_VOID ctx, NV_SINT32 enabled)
1523 struct nv_softc *sc = (struct nv_softc *)ctx;
1526 DEBUGOUT(NV_DEBUG_API, "nv: nv_oslinkchg\n");
1531 ifp->if_flags |= IFF_UP;
1533 ifp->if_flags &= ~IFF_UP;
1540 /* Setup a watchdog timer */
1542 nv_osalloctimer(PNV_VOID ctx, PNV_VOID *timer)
1544 struct nv_softc *sc = (struct nv_softc *)ctx;
1546 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osalloctimer\n");
1548 callout_init(&sc->ostimer);
1549 *timer = &sc->ostimer;
1554 /* Free the timer */
1556 nv_osfreetimer(PNV_VOID ctx, PNV_VOID timer)
1558 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osfreetimer\n");
1563 /* Setup timer parameters */
1565 nv_osinittimer(PNV_VOID ctx, PNV_VOID timer, PTIMER_FUNC func, PNV_VOID parameters)
1567 struct nv_softc *sc = (struct nv_softc *)ctx;
1569 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osinittimer\n");
1571 sc->ostimer_func = func;
1572 sc->ostimer_params = parameters;
1577 /* Set the timer to go off */
1579 nv_ossettimer(PNV_VOID ctx, PNV_VOID timer, NV_UINT32 delay)
1581 struct nv_softc *sc = ctx;
1583 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ossettimer\n");
1585 callout_reset(&sc->ostimer, delay, sc->ostimer_func,
1586 sc->ostimer_params);
1591 /* Cancel the timer */
1593 nv_oscanceltimer(PNV_VOID ctx, PNV_VOID timer)
1595 struct nv_softc *sc = ctx;
1597 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_oscanceltimer\n");
1599 callout_stop(&sc->ostimer);
1605 nv_ospreprocpkt(PNV_VOID ctx, PNV_VOID readdata, PNV_VOID *id, NV_UINT8 *newbuffer,
1608 /* Not implemented */
1609 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ospreprocpkt\n");
1615 nv_ospreprocpktnopq(PNV_VOID ctx, PNV_VOID readdata)
1617 /* Not implemented */
1618 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ospreprocpkt\n");
1624 nv_osindicatepkt(PNV_VOID ctx, PNV_VOID *id, NV_UINT32 pktno)
1626 /* Not implemented */
1627 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osindicatepkt\n");
1632 /* Allocate mutex context (already done in nv_attach) */
1634 nv_oslockalloc(PNV_VOID ctx, NV_SINT32 type, PNV_VOID *pLock)
1636 struct nv_softc *sc = (struct nv_softc *)ctx;
1638 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockalloc\n");
1640 *pLock = (void **)sc;
1645 /* Obtain a spin lock */
1647 nv_oslockacquire(PNV_VOID ctx, NV_SINT32 type, PNV_VOID lock)
1649 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockacquire\n");
1651 NV_OSLOCK((struct nv_softc *)lock);
1658 nv_oslockrelease(PNV_VOID ctx, NV_SINT32 type, PNV_VOID lock)
1660 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockrelease\n");
1662 NV_OSUNLOCK((struct nv_softc *)lock);
1667 /* I have no idea what this is for */
1669 nv_osreturnbufvirt(PNV_VOID ctx, PNV_VOID readdata)
1671 /* Not implemented */
1672 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_osreturnbufvirt\n");
1673 panic("nv: nv_osreturnbufvirtual not implemented\n");
1679 /* --- End on NVOSAPI interface --- */