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.11 2005/05/24 09:52:14 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>
89 #include <net/ifq_var.h>
90 #include <net/if_arp.h>
91 #include <net/ethernet.h>
92 #include <net/if_dl.h>
93 #include <net/if_media.h>
97 #include <net/vlan/if_vlan_var.h>
99 #include <machine/bus_memio.h>
100 #include <machine/bus.h>
101 #include <machine/resource.h>
103 #include <vm/vm.h> /* for vtophys */
104 #include <vm/pmap.h> /* for vtophys */
105 #include <machine/clock.h> /* for DELAY */
107 #include <sys/rman.h>
109 #include <bus/pci/pcireg.h>
110 #include <bus/pci/pcivar.h>
112 #include <dev/netif/mii_layer/mii.h>
113 #include <dev/netif/mii_layer/miivar.h>
115 MODULE_DEPEND(nv, pci, 1, 1, 1);
116 MODULE_DEPEND(nv, miibus, 1, 1, 1);
118 #include "if_nvreg.h"
119 #include "miibus_if.h"
121 static int nv_probe(device_t);
122 static int nv_attach(device_t);
123 static int nv_detach(device_t);
124 static void nv_init(void *);
125 static void nv_stop(struct nv_softc *);
126 static void nv_shutdown(device_t);
127 static int nv_init_rings(struct nv_softc *);
128 static void nv_free_rings(struct nv_softc *);
130 static void nv_ifstart(struct ifnet *);
131 static int nv_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
132 static void nv_intr(void *);
133 static void nv_tick(void *);
134 static void nv_setmulti(struct nv_softc *);
135 static void nv_watchdog(struct ifnet *);
136 static void nv_update_stats(struct nv_softc *);
138 static int nv_ifmedia_upd(struct ifnet *);
139 static void nv_ifmedia_sts(struct ifnet *, struct ifmediareq *);
140 static int nv_miibus_readreg(device_t, int, int);
141 static void nv_miibus_writereg(device_t, int, int, int);
143 static void nv_dmamap_cb(void *, bus_dma_segment_t *, int, int);
144 static void nv_dmamap_tx_cb(void *, bus_dma_segment_t *, int, bus_size_t, int);
146 static NV_SINT32 nv_osalloc(PNV_VOID, PMEMORY_BLOCK);
147 static NV_SINT32 nv_osfree(PNV_VOID, PMEMORY_BLOCK);
148 static NV_SINT32 nv_osallocex(PNV_VOID, PMEMORY_BLOCKEX);
149 static NV_SINT32 nv_osfreeex(PNV_VOID, PMEMORY_BLOCKEX);
150 static NV_SINT32 nv_osclear(PNV_VOID, PNV_VOID, NV_SINT32);
151 static NV_SINT32 nv_osdelay(PNV_VOID, NV_UINT32);
152 static NV_SINT32 nv_osallocrxbuf(PNV_VOID, PMEMORY_BLOCK, PNV_VOID *);
153 static NV_SINT32 nv_osfreerxbuf(PNV_VOID, PMEMORY_BLOCK, PNV_VOID);
154 static NV_SINT32 nv_ospackettx(PNV_VOID, PNV_VOID, NV_UINT32);
155 static NV_SINT32 nv_ospacketrx(PNV_VOID, PNV_VOID, NV_UINT32, NV_UINT8 *, NV_UINT8);
156 static NV_SINT32 nv_oslinkchg(PNV_VOID, NV_SINT32);
157 static NV_SINT32 nv_osalloctimer(PNV_VOID, PNV_VOID *);
158 static NV_SINT32 nv_osfreetimer(PNV_VOID, PNV_VOID);
159 static NV_SINT32 nv_osinittimer(PNV_VOID, PNV_VOID, PTIMER_FUNC, PNV_VOID);
160 static NV_SINT32 nv_ossettimer(PNV_VOID, PNV_VOID, NV_UINT32);
161 static NV_SINT32 nv_oscanceltimer(PNV_VOID, PNV_VOID);
163 static NV_SINT32 nv_ospreprocpkt(PNV_VOID, PNV_VOID, PNV_VOID *, NV_UINT8 *, NV_UINT8);
164 static PNV_VOID nv_ospreprocpktnopq(PNV_VOID, PNV_VOID);
165 static NV_SINT32 nv_osindicatepkt(PNV_VOID, PNV_VOID *, NV_UINT32);
166 static NV_SINT32 nv_oslockalloc(PNV_VOID, NV_SINT32, PNV_VOID *);
167 static NV_SINT32 nv_oslockacquire(PNV_VOID, NV_SINT32, PNV_VOID);
168 static NV_SINT32 nv_oslockrelease(PNV_VOID, NV_SINT32, PNV_VOID);
169 static PNV_VOID nv_osreturnbufvirt(PNV_VOID, PNV_VOID);
171 static device_method_t nv_methods[] = {
172 /* Device interface */
173 DEVMETHOD(device_probe, nv_probe),
174 DEVMETHOD(device_attach, nv_attach),
175 DEVMETHOD(device_detach, nv_detach),
176 DEVMETHOD(device_shutdown, nv_shutdown),
179 DEVMETHOD(bus_print_child, bus_generic_print_child),
180 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
183 DEVMETHOD(miibus_readreg, nv_miibus_readreg),
184 DEVMETHOD(miibus_writereg, nv_miibus_writereg),
189 static driver_t nv_driver = {
192 sizeof(struct nv_softc)
195 static devclass_t nv_devclass;
197 static int nv_pollinterval = 0;
198 SYSCTL_INT(_hw, OID_AUTO, nv_pollinterval, CTLFLAG_RW,
199 &nv_pollinterval, 0, "delay between interface polls");
201 DRIVER_MODULE(nv, pci, nv_driver, nv_devclass, 0, 0);
202 DRIVER_MODULE(miibus, nv, miibus_driver, miibus_devclass, 0, 0);
204 static struct nv_type nv_devs[] = {
205 {NVIDIA_VENDORID, NFORCE_MCPNET1_DEVICEID,
206 "NVIDIA nForce MCP Networking Adapter"},
207 {NVIDIA_VENDORID, NFORCE_MCPNET2_DEVICEID,
208 "NVIDIA nForce MCP2 Networking Adapter"},
209 {NVIDIA_VENDORID, NFORCE_MCPNET3_DEVICEID,
210 "NVIDIA nForce MCP3 Networking Adapter"},
211 {NVIDIA_VENDORID, NFORCE_MCPNET4_DEVICEID,
212 "NVIDIA nForce MCP4 Networking Adapter"},
213 {NVIDIA_VENDORID, NFORCE_MCPNET5_DEVICEID,
214 "NVIDIA nForce MCP5 Networking Adapter"},
215 {NVIDIA_VENDORID, NFORCE_MCPNET6_DEVICEID,
216 "NVIDIA nForce MCP6 Networking Adapter"},
217 {NVIDIA_VENDORID, NFORCE_MCPNET7_DEVICEID,
218 "NVIDIA nForce MCP7 Networking Adapter"},
222 /* DMA MEM map callback function to get data segment physical address */
224 nv_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nsegs, int error)
230 ("Too many DMA segments returned when mapping DMA memory"));
231 *(bus_addr_t *)arg = segs->ds_addr;
234 /* DMA RX map callback function to get data segment physical address */
236 nv_dmamap_rx_cb(void *arg, bus_dma_segment_t * segs, int nsegs, bus_size_t mapsize, int error)
240 *(bus_addr_t *)arg = segs->ds_addr;
244 * DMA TX buffer callback function to allocate fragment data segment
248 nv_dmamap_tx_cb(void *arg, bus_dma_segment_t * segs, int nsegs, bus_size_t mapsize, int error)
250 struct nv_tx_desc *info = arg;
254 KASSERT(nsegs < NV_MAX_FRAGS,
255 ("Too many DMA segments returned when mapping mbuf"));
256 info->numfrags = nsegs;
257 bcopy(segs, info->frags, nsegs * sizeof(bus_dma_segment_t));
260 /* Probe for supported hardware ID's */
262 nv_probe(device_t dev)
264 struct nv_type *t = nv_devs;
266 /* Check for matching PCI DEVICE ID's */
267 while (t->name != NULL) {
268 if ((pci_get_vendor(dev) == t->vid_id) &&
269 (pci_get_device(dev) == t->dev_id)) {
270 device_set_desc(dev, t->name);
279 /* Attach driver and initialise hardware for use */
281 nv_attach(device_t dev)
283 u_char eaddr[ETHER_ADDR_LEN];
287 ADAPTER_OPEN_PARAMS OpenParams;
288 int error = 0, i, rid;
290 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_attach - entry\n");
292 sc = device_get_softc(dev);
295 callout_init(&sc->nv_stat_timer);
297 /* Preinitialize data structures */
298 bzero(&OpenParams, sizeof(ADAPTER_OPEN_PARAMS));
300 /* Enable bus mastering */
301 pci_enable_busmaster(dev);
303 /* Allocate memory mapped address space */
305 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
307 if (sc->res == NULL) {
308 device_printf(dev, "couldn't map memory\n");
312 sc->sc_st = rman_get_bustag(sc->res);
313 sc->sc_sh = rman_get_bushandle(sc->res);
315 /* Allocate interrupt */
317 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
318 RF_SHAREABLE | RF_ACTIVE);
320 if (sc->irq == NULL) {
321 device_printf(dev, "couldn't map interrupt\n");
325 /* Allocate DMA tags */
326 error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
327 BUS_SPACE_MAXADDR, NULL, NULL, MCLBYTES * NV_MAX_FRAGS,
328 NV_MAX_FRAGS, MCLBYTES, 0,
331 device_printf(dev, "couldn't allocate dma tag\n");
334 error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
335 BUS_SPACE_MAXADDR, NULL, NULL,
336 sizeof(struct nv_rx_desc) * RX_RING_SIZE, 1,
337 sizeof(struct nv_rx_desc) * RX_RING_SIZE, 0,
340 device_printf(dev, "couldn't allocate dma tag\n");
343 error = bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT,
344 BUS_SPACE_MAXADDR, NULL, NULL,
345 sizeof(struct nv_tx_desc) * TX_RING_SIZE, 1,
346 sizeof(struct nv_tx_desc) * TX_RING_SIZE, 0,
349 device_printf(dev, "couldn't allocate dma tag\n");
353 error = bus_dmamap_create(sc->ttag, 0, &sc->tmap);
355 device_printf(dev, "couldn't create dma map\n");
359 /* Allocate DMA safe memory and get the DMA addresses. */
360 error = bus_dmamem_alloc(sc->ttag, (void **)&sc->tx_desc,
361 BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->tmap);
363 device_printf(dev, "couldn't allocate dma memory\n");
366 error = bus_dmamap_load(sc->ttag, sc->tmap, sc->tx_desc,
367 sizeof(struct nv_tx_desc) * TX_RING_SIZE, nv_dmamap_cb,
370 device_printf(dev, "couldn't map dma memory\n");
374 error = bus_dmamap_create(sc->rtag, 0, &sc->rmap);
376 device_printf(dev, "couldn't create dma map\n");
380 error = bus_dmamem_alloc(sc->rtag, (void **)&sc->rx_desc,
381 BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->rmap);
383 device_printf(dev, "couldn't allocate dma memory\n");
386 error = bus_dmamap_load(sc->rtag, sc->rmap, sc->rx_desc,
387 sizeof(struct nv_rx_desc) * RX_RING_SIZE, nv_dmamap_cb,
390 device_printf(dev, "couldn't map dma memory\n");
393 /* Initialize rings. */
394 if (nv_init_rings(sc)) {
395 device_printf(dev, "failed to init rings\n");
399 /* Setup NVIDIA API callback routines */
402 osapi->pfnAllocMemory = nv_osalloc;
403 osapi->pfnFreeMemory = nv_osfree;
404 osapi->pfnAllocMemoryEx = nv_osallocex;
405 osapi->pfnFreeMemoryEx = nv_osfreeex;
406 osapi->pfnClearMemory = nv_osclear;
407 osapi->pfnStallExecution = nv_osdelay;
408 osapi->pfnAllocReceiveBuffer = nv_osallocrxbuf;
409 osapi->pfnFreeReceiveBuffer = nv_osfreerxbuf;
410 osapi->pfnPacketWasSent = nv_ospackettx;
411 osapi->pfnPacketWasReceived = nv_ospacketrx;
412 osapi->pfnLinkStateHasChanged = nv_oslinkchg;
413 osapi->pfnAllocTimer = nv_osalloctimer;
414 osapi->pfnFreeTimer = nv_osfreetimer;
415 osapi->pfnInitializeTimer = nv_osinittimer;
416 osapi->pfnSetTimer = nv_ossettimer;
417 osapi->pfnCancelTimer = nv_oscanceltimer;
418 osapi->pfnPreprocessPacket = nv_ospreprocpkt;
419 osapi->pfnPreprocessPacketNopq = nv_ospreprocpktnopq;
420 osapi->pfnIndicatePackets = nv_osindicatepkt;
421 osapi->pfnLockAlloc = nv_oslockalloc;
422 osapi->pfnLockAcquire = nv_oslockacquire;
423 osapi->pfnLockRelease = nv_oslockrelease;
424 osapi->pfnReturnBufferVirtual = nv_osreturnbufvirt;
427 sc->max_frame_size = ETHERMTU + ETHER_HDR_LEN + FCS_LEN;
429 /* TODO - We don't support hardware offload yet */
433 /* Set NVIDIA API startup parameters */
434 OpenParams.MaxDpcLoop = 2;
435 OpenParams.MaxRxPkt = RX_RING_SIZE;
436 OpenParams.MaxTxPkt = TX_RING_SIZE;
437 OpenParams.SentPacketStatusSuccess = 1;
438 OpenParams.SentPacketStatusFailure = 0;
439 OpenParams.MaxRxPktToAccumulate = 6;
440 OpenParams.ulPollInterval = nv_pollinterval;
441 OpenParams.SetForcedModeEveryNthRxPacket = 0;
442 OpenParams.SetForcedModeEveryNthTxPacket = 0;
443 OpenParams.RxForcedInterrupt = 0;
444 OpenParams.TxForcedInterrupt = 0;
445 OpenParams.pOSApi = osapi;
446 OpenParams.pvHardwareBaseAddress = rman_get_virtual(sc->res);
447 OpenParams.bASFEnabled = 0;
448 OpenParams.ulDescriptorVersion = sc->hwmode;
449 OpenParams.ulMaxPacketSize = sc->max_frame_size;
450 OpenParams.DeviceId = pci_get_device(dev);
452 /* Open NVIDIA Hardware API */
453 error = ADAPTER_Open(&OpenParams, (void **)&(sc->hwapi), &sc->phyaddr);
455 device_printf(dev, "failed to open NVIDIA Hardware API: 0x%x\n", error);
459 /* TODO - Add support for MODE2 hardware offload */
461 bzero(&sc->adapterdata, sizeof(sc->adapterdata));
463 sc->adapterdata.ulMediaIF = sc->media;
464 sc->adapterdata.ulModeRegTxReadCompleteEnable = 1;
465 sc->hwapi->pfnSetCommonData(sc->hwapi->pADCX, &sc->adapterdata);
467 /* MAC is loaded backwards into h/w reg */
468 sc->hwapi->pfnGetNodeAddress(sc->hwapi->pADCX, sc->original_mac_addr);
469 for (i = 0; i < 6; i++) {
470 eaddr[i] = sc->original_mac_addr[5 - i];
472 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, eaddr);
473 bcopy(eaddr, (char *)&sc->sc_macaddr, ETHER_ADDR_LEN);
475 DEBUGOUT(NV_DEBUG_INIT, "nv: do mii_phy_probe\n");
477 /* Probe device for MII interface to PHY */
478 if (mii_phy_probe(dev, &sc->miibus,
479 nv_ifmedia_upd, nv_ifmedia_sts)) {
480 device_printf(dev, "MII without any phy!\n");
484 /* Setup interface parameters */
487 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
488 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
489 ifp->if_ioctl = nv_ioctl;
490 ifp->if_start = nv_ifstart;
491 ifp->if_watchdog = nv_watchdog;
493 ifp->if_init = nv_init;
494 ifp->if_mtu = ETHERMTU;
495 ifp->if_baudrate = IF_Mbps(100);
496 ifp->if_capabilities |= IFCAP_VLAN_MTU;
497 ifq_set_maxlen(&ifp->if_snd, TX_RING_SIZE - 1);
498 ifq_set_ready(&ifp->if_snd);
500 /* Attach to OS's managers. */
501 ether_ifattach(ifp, sc->sc_macaddr);
503 /* Activate our interrupt handler. - attach last to avoid lock */
504 error = bus_setup_intr(sc->dev, sc->irq, INTR_TYPE_NET,
505 nv_intr, sc, &sc->sc_ih);
507 device_printf(sc->dev, "couldn't set up interrupt handler\n");
510 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_attach - exit\n");
519 /* Detach interface for module unload */
521 nv_detach(device_t dev)
523 struct nv_softc *sc = device_get_softc(dev);
528 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - entry\n");
530 ifp = &sc->arpcom.ac_if;
532 if (device_is_attached(dev)) {
538 device_delete_child(dev, sc->miibus);
539 bus_generic_detach(dev);
541 /* Reload unreversed address back into MAC in original state */
542 if (sc->original_mac_addr)
543 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, sc->original_mac_addr);
545 DEBUGOUT(NV_DEBUG_DEINIT, "nv: do pfnClose\n");
546 /* Detach from NVIDIA hardware API */
547 if (sc->hwapi->pfnClose)
548 sc->hwapi->pfnClose(sc->hwapi->pADCX, FALSE);
549 /* Release resources */
551 bus_teardown_intr(sc->dev, sc->irq, sc->sc_ih);
553 bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq);
555 bus_release_resource(sc->dev, SYS_RES_MEMORY, NV_RID, sc->res);
560 bus_dmamap_unload(sc->rtag, sc->rmap);
561 bus_dmamem_free(sc->rtag, sc->rx_desc, sc->rmap);
562 bus_dmamap_destroy(sc->rtag, sc->rmap);
565 bus_dma_tag_destroy(sc->mtag);
567 bus_dma_tag_destroy(sc->ttag);
569 bus_dma_tag_destroy(sc->rtag);
573 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - exit\n");
578 /* Initialise interface and start it "RUNNING" */
582 struct nv_softc *sc = xsc;
588 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init - entry (%d)\n", sc->linkup);
592 /* Do nothing if already running */
593 if (ifp->if_flags & IFF_RUNNING)
598 DEBUGOUT(NV_DEBUG_INIT, "nv: do pfnInit\n");
599 /* Setup Hardware interface and allocate memory structures */
600 error = sc->hwapi->pfnInit(sc->hwapi->pADCX,
602 0, /* force full duplex */
604 0, /* force async mode */
608 device_printf(sc->dev, "failed to start NVIDIA Hardware interface\n");
611 /* Set the MAC address */
612 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, sc->sc_macaddr);
613 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
614 sc->hwapi->pfnStart(sc->hwapi->pADCX);
616 /* Setup multicast filter */
620 /* Update interface parameters */
621 ifp->if_flags |= IFF_RUNNING;
622 ifp->if_flags &= ~IFF_OACTIVE;
624 callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc);
626 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init - exit\n");
634 /* Stop interface activity ie. not "RUNNING" */
636 nv_stop(struct nv_softc *sc)
642 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_stop - entry\n");
647 /* Cancel tick timer */
648 callout_stop(&sc->nv_stat_timer);
650 /* Stop hardware activity */
651 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
652 sc->hwapi->pfnStop(sc->hwapi->pADCX, 0);
654 DEBUGOUT(NV_DEBUG_DEINIT, "nv: do pfnDeinit\n");
655 /* Shutdown interface and deallocate memory buffers */
656 if (sc->hwapi->pfnDeinit)
657 sc->hwapi->pfnDeinit(sc->hwapi->pADCX, 0);
663 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
665 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_stop - exit\n");
672 /* Shutdown interface for unload/reboot */
674 nv_shutdown(device_t dev)
678 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_shutdown\n");
680 sc = device_get_softc(dev);
682 /* Stop hardware activity */
686 /* Allocate TX ring buffers */
688 nv_init_rings(struct nv_softc *sc)
694 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init_rings - entry\n");
696 sc->cur_rx = sc->cur_tx = sc->pending_rxs = sc->pending_txs = 0;
697 /* Initialise RX ring */
698 for (i = 0; i < RX_RING_SIZE; i++) {
699 struct nv_rx_desc *desc = sc->rx_desc + i;
700 struct nv_map_buffer *buf = &desc->buf;
702 buf->mbuf = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
703 if (buf->mbuf == NULL) {
704 device_printf(sc->dev, "couldn't allocate mbuf\n");
709 buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
710 m_adj(buf->mbuf, ETHER_ALIGN);
712 error = bus_dmamap_create(sc->mtag, 0, &buf->map);
714 device_printf(sc->dev, "couldn't create dma map\n");
718 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
719 nv_dmamap_rx_cb, &desc->paddr, 0);
721 device_printf(sc->dev, "couldn't dma map mbuf\n");
725 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
727 desc->buflength = buf->mbuf->m_len;
728 desc->vaddr = mtod(buf->mbuf, caddr_t);
730 bus_dmamap_sync(sc->rtag, sc->rmap,
731 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
733 /* Initialize TX ring */
734 for (i = 0; i < TX_RING_SIZE; i++) {
735 struct nv_tx_desc *desc = sc->tx_desc + i;
736 struct nv_map_buffer *buf = &desc->buf;
740 error = bus_dmamap_create(sc->mtag, 0, &buf->map);
742 device_printf(sc->dev, "couldn't create dma map\n");
747 bus_dmamap_sync(sc->ttag, sc->tmap,
748 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
750 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init_rings - exit\n");
758 /* Free the TX ring buffers */
760 nv_free_rings(struct nv_softc *sc)
766 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_free_rings - entry\n");
768 for (i = 0; i < RX_RING_SIZE; i++) {
769 struct nv_rx_desc *desc = sc->rx_desc + i;
770 struct nv_map_buffer *buf = &desc->buf;
773 bus_dmamap_unload(sc->mtag, buf->map);
774 bus_dmamap_destroy(sc->mtag, buf->map);
780 for (i = 0; i < TX_RING_SIZE; i++) {
781 struct nv_tx_desc *desc = sc->tx_desc + i;
782 struct nv_map_buffer *buf = &desc->buf;
785 bus_dmamap_unload(sc->mtag, buf->map);
786 bus_dmamap_destroy(sc->mtag, buf->map);
792 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_free_rings - exit\n");
797 /* Main loop for sending packets from OS to interface */
799 nv_ifstart(struct ifnet *ifp)
801 struct nv_softc *sc = ifp->if_softc;
802 struct nv_map_buffer *buf;
804 struct nv_tx_desc *desc;
805 ADAPTER_WRITE_DATA txdata;
808 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_ifstart - entry\n");
810 /* If link is down/busy or queue is empty do nothing */
811 if (ifp->if_flags & IFF_OACTIVE || ifq_is_empty(&ifp->if_snd))
814 /* Transmit queued packets until sent or TX ring is full */
815 while (sc->pending_txs < TX_RING_SIZE) {
816 desc = sc->tx_desc + sc->cur_tx;
819 /* Get next packet to send. */
820 m0 = ifq_dequeue(&ifp->if_snd);
822 /* If nothing to send, return. */
826 /* Map MBUF for DMA access */
827 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m0,
828 nv_dmamap_tx_cb, desc, BUS_DMA_NOWAIT);
830 if (error && error != EFBIG) {
836 * Packet has too many fragments - defrag into new mbuf
840 m = m_defrag(m0, MB_DONTWAIT);
849 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m,
850 nv_dmamap_tx_cb, desc, BUS_DMA_NOWAIT);
857 /* Do sync on DMA bounce buffer */
858 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREWRITE);
861 txdata.ulNumberOfElements = desc->numfrags;
862 txdata.pvID = (PVOID)desc;
864 /* Put fragments into API element list */
865 txdata.ulTotalLength = buf->mbuf->m_len;
866 for (i = 0; i < desc->numfrags; i++) {
867 txdata.sElement[i].ulLength = (ulong)desc->frags[i].ds_len;
868 txdata.sElement[i].pPhysical = (PVOID)desc->frags[i].ds_addr;
871 /* Send packet to Nvidia API for transmission */
872 error = sc->hwapi->pfnWrite(sc->hwapi->pADCX, &txdata);
875 case ADAPTERERR_NONE:
876 /* Packet was queued in API TX queue successfully */
878 sc->cur_tx = (sc->cur_tx + 1) % TX_RING_SIZE;
881 case ADAPTERERR_TRANSMIT_QUEUE_FULL:
882 /* The API TX queue is full - requeue the packet */
883 device_printf(sc->dev, "nv_ifstart: transmit queue is full\n");
884 ifp->if_flags |= IFF_OACTIVE;
885 bus_dmamap_unload(sc->mtag, buf->map);
890 /* The API failed to queue/send the packet so dump it */
891 device_printf(sc->dev, "nv_ifstart: transmit error\n");
892 bus_dmamap_unload(sc->mtag, buf->map);
898 /* Set watchdog timer. */
901 /* Copy packet to BPF tap */
904 ifp->if_flags |= IFF_OACTIVE;
906 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_ifstart - exit\n");
909 /* Handle IOCTL events */
911 nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
913 struct nv_softc *sc = ifp->if_softc;
914 struct ifreq *ifr = (struct ifreq *) data;
915 struct mii_data *mii;
920 DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - entry\n");
925 if (ifp->if_mtu == ifr->ifr_mtu)
927 if (ifr->ifr_mtu + ifp->if_hdrlen <= MAX_PACKET_SIZE_1518) {
928 ifp->if_mtu = ifr->ifr_mtu;
936 /* Setup interface flags */
937 if (ifp->if_flags & IFF_UP) {
938 if ((ifp->if_flags & IFF_RUNNING) == 0) {
943 if (ifp->if_flags & IFF_RUNNING) {
949 /* Handle IFF_PROMISC and IFF_ALLMULTI flags. */
955 /* Setup multicast filter */
956 if (ifp->if_flags & IFF_RUNNING) {
962 /* Get/Set interface media parameters */
963 mii = device_get_softc(sc->miibus);
964 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
968 /* Everything else we forward to generic ether ioctl */
969 error = ether_ioctl(ifp, (int)command, data);
973 DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - exit\n");
980 /* Interrupt service routine */
984 struct nv_softc *sc = arg;
985 struct ifnet *ifp = &sc->sc_if;
987 DEBUGOUT(NV_DEBUG_INTERRUPT, "nv: nv_intr - entry\n");
989 if (!ifp->if_flags & IFF_UP) {
993 /* Handle interrupt event */
994 if (sc->hwapi->pfnQueryInterrupt(sc->hwapi->pADCX)) {
995 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
996 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
998 if (!ifq_is_empty(&ifp->if_snd))
1001 /* If no pending packets we don't need a timeout */
1002 if (sc->pending_txs == 0)
1003 sc->sc_if.if_timer = 0;
1005 DEBUGOUT(NV_DEBUG_INTERRUPT, "nv: nv_intr - exit\n");
1010 /* Setup multicast filters */
1012 nv_setmulti(struct nv_softc *sc)
1015 struct ifmultiaddr *ifma;
1016 PACKET_FILTER hwfilter;
1019 u_int8_t andaddr[6];
1023 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_setmulti - entry\n");
1027 /* Initialize filter */
1028 hwfilter.ulFilterFlags = 0;
1029 for (i = 0; i < 6; i++) {
1030 hwfilter.acMulticastAddress[i] = 0;
1031 hwfilter.acMulticastMask[i] = 0;
1034 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) {
1035 /* Accept all packets */
1036 hwfilter.ulFilterFlags |= ACCEPT_ALL_PACKETS;
1037 sc->hwapi->pfnSetPacketFilter(sc->hwapi->pADCX, &hwfilter);
1041 /* Setup multicast filter */
1042 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1045 if (ifma->ifma_addr->sa_family != AF_LINK)
1048 addrp = LLADDR((struct sockaddr_dl *) ifma->ifma_addr);
1049 for (i = 0; i < 6; i++) {
1050 u_int8_t mcaddr = addrp[i];
1051 andaddr[i] &= mcaddr;
1052 oraddr[i] |= mcaddr;
1055 for (i = 0; i < 6; i++) {
1056 hwfilter.acMulticastAddress[i] = andaddr[i] & oraddr[i];
1057 hwfilter.acMulticastMask[i] = andaddr[i] | (~oraddr[i]);
1060 /* Send filter to NVIDIA API */
1061 sc->hwapi->pfnSetPacketFilter(sc->hwapi->pADCX, &hwfilter);
1065 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_setmulti - exit\n");
1070 /* Change the current media/mediaopts */
1072 nv_ifmedia_upd(struct ifnet *ifp)
1074 struct nv_softc *sc = ifp->if_softc;
1075 struct mii_data *mii;
1077 DEBUGOUT(NV_DEBUG_MII, "nv: nv_ifmedia_upd\n");
1079 mii = device_get_softc(sc->miibus);
1081 if (mii->mii_instance) {
1082 struct mii_softc *miisc;
1083 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1084 miisc = LIST_NEXT(miisc, mii_list)) {
1085 mii_phy_reset(miisc);
1093 /* Update current miibus PHY status of media */
1095 nv_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1097 struct nv_softc *sc;
1098 struct mii_data *mii;
1100 DEBUGOUT(NV_DEBUG_MII, "nv: nv_ifmedia_sts\n");
1103 mii = device_get_softc(sc->miibus);
1106 ifmr->ifm_active = mii->mii_media_active;
1107 ifmr->ifm_status = mii->mii_media_status;
1112 /* miibus tick timer - maintain link status */
1116 struct nv_softc *sc = xsc;
1117 struct mii_data *mii;
1123 nv_update_stats(sc);
1125 mii = device_get_softc(sc->miibus);
1128 if (mii->mii_media_status & IFM_ACTIVE &&
1129 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1130 if (!ifq_is_empty(&ifp->if_snd))
1133 callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc);
1140 /* Update ifnet data structure with collected interface stats from API */
1142 nv_update_stats(struct nv_softc *sc)
1144 struct ifnet *ifp = &sc->sc_if;
1145 ADAPTER_STATS stats;
1150 sc->hwapi->pfnGetStatistics(sc->hwapi->pADCX, &stats);
1152 ifp->if_ipackets = stats.ulSuccessfulReceptions;
1153 ifp->if_ierrors = stats.ulMissedFrames +
1154 stats.ulFailedReceptions +
1156 stats.ulFramingErrors +
1157 stats.ulOverFlowErrors;
1159 ifp->if_opackets = stats.ulSuccessfulTransmissions;
1160 ifp->if_oerrors = sc->tx_errors +
1161 stats.ulFailedTransmissions +
1162 stats.ulRetryErrors +
1163 stats.ulUnderflowErrors +
1164 stats.ulLossOfCarrierErrors +
1165 stats.ulLateCollisionErrors;
1167 ifp->if_collisions = stats.ulLateCollisionErrors;
1174 /* miibus Read PHY register wrapper - calls Nvidia API entry point */
1176 nv_miibus_readreg(device_t dev, int phy, int reg)
1178 struct nv_softc *sc = device_get_softc(dev);
1181 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_readreg - entry\n");
1183 ADAPTER_ReadPhy(sc->hwapi->pADCX, phy, reg, &data);
1185 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_readreg - exit\n");
1190 /* miibus Write PHY register wrapper - calls Nvidia API entry point */
1192 nv_miibus_writereg(device_t dev, int phy, int reg, int data)
1194 struct nv_softc *sc = device_get_softc(dev);
1196 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_writereg - entry\n");
1198 ADAPTER_WritePhy(sc->hwapi->pADCX, phy, reg, (ulong)data);
1200 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_writereg - exit\n");
1205 /* Watchdog timer to prevent PHY lockups */
1207 nv_watchdog(struct ifnet *ifp)
1209 struct nv_softc *sc = ifp->if_softc;
1211 device_printf(sc->dev, "device timeout (%d)\n", sc->pending_txs);
1216 ifp->if_flags &= ~IFF_RUNNING;
1219 if (!ifq_is_empty(&ifp->if_snd))
1225 /* --- Start of NVOSAPI interface --- */
1227 /* Allocate DMA enabled general use memory for API */
1229 nv_osalloc(PNV_VOID ctx, PMEMORY_BLOCK mem)
1231 struct nv_softc *sc;
1232 bus_addr_t mem_physical;
1234 DEBUGOUT(NV_DEBUG_API, "nv: nv_osalloc - %d\n", mem->uiLength);
1236 sc = (struct nv_softc *)ctx;
1238 mem->pLogical = (PVOID)contigmalloc(mem->uiLength, M_DEVBUF,
1239 M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE, 0);
1241 if (!mem->pLogical) {
1242 device_printf(sc->dev, "memory allocation failed\n");
1245 memset(mem->pLogical, 0, (ulong)mem->uiLength);
1246 mem_physical = vtophys(mem->pLogical);
1247 mem->pPhysical = (PVOID)mem_physical;
1249 DEBUGOUT(NV_DEBUG_API, "nv: nv_osalloc %p/%p - %d\n",
1250 mem->pLogical, mem->pPhysical, mem->uiLength);
1255 /* Free allocated memory */
1257 nv_osfree(PNV_VOID ctx, PMEMORY_BLOCK mem)
1259 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfree - %p - %d\n",
1260 mem->pLogical, mem->uiLength);
1262 contigfree(mem->pLogical, PAGE_SIZE, M_DEVBUF);
1266 /* Copied directly from nvnet.c */
1268 nv_osallocex(PNV_VOID ctx, PMEMORY_BLOCKEX mem_block_ex)
1270 MEMORY_BLOCK mem_block;
1272 DEBUGOUT(NV_DEBUG_API, "nv: nv_osallocex\n");
1274 mem_block_ex->pLogical = NULL;
1275 mem_block_ex->uiLengthOrig = mem_block_ex->uiLength;
1277 if ((mem_block_ex->AllocFlags & ALLOC_MEMORY_ALIGNED) &&
1278 (mem_block_ex->AlignmentSize > 1)) {
1279 DEBUGOUT(NV_DEBUG_API, " aligning on %d\n",
1280 mem_block_ex->AlignmentSize);
1281 mem_block_ex->uiLengthOrig += mem_block_ex->AlignmentSize;
1283 mem_block.uiLength = mem_block_ex->uiLengthOrig;
1285 if (nv_osalloc(ctx, &mem_block) == 0) {
1288 mem_block_ex->pLogicalOrig = mem_block.pLogical;
1289 mem_block_ex->pPhysicalOrigLow = (uintptr_t)mem_block.pPhysical;
1290 mem_block_ex->pPhysicalOrigHigh = 0;
1292 mem_block_ex->pPhysical = mem_block.pPhysical;
1293 mem_block_ex->pLogical = mem_block.pLogical;
1295 if (mem_block_ex->uiLength != mem_block_ex->uiLengthOrig) {
1296 unsigned int offset;
1297 offset = mem_block_ex->pPhysicalOrigLow & (mem_block_ex->AlignmentSize - 1);
1300 mem_block_ex->pPhysical = (PVOID)((uintptr_t)mem_block_ex->pPhysical +
1301 mem_block_ex->AlignmentSize - offset);
1302 mem_block_ex->pLogical = (PVOID)((uintptr_t)mem_block_ex->pLogical +
1303 mem_block_ex->AlignmentSize - offset);
1305 } /* if (mem_block_ex->uiLength !=
1306 * mem_block_ex->uiLengthOrig) */
1310 /* Copied directly from nvnet.c */
1312 nv_osfreeex(PNV_VOID ctx, PMEMORY_BLOCKEX mem_block_ex)
1314 MEMORY_BLOCK mem_block;
1316 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfreeex\n");
1318 mem_block.pLogical = mem_block_ex->pLogicalOrig;
1319 mem_block.pPhysical = (PVOID)((uintptr_t)mem_block_ex->pPhysicalOrigLow);
1320 mem_block.uiLength = mem_block_ex->uiLengthOrig;
1322 return (nv_osfree(ctx, &mem_block));
1325 /* Clear memory region */
1327 nv_osclear(PNV_VOID ctx, PNV_VOID mem, NV_SINT32 length)
1329 DEBUGOUT(NV_DEBUG_API, "nv: nv_osclear\n");
1330 memset(mem, 0, length);
1334 /* Sleep for a tick */
1336 nv_osdelay(PNV_VOID ctx, NV_UINT32 usec)
1342 /* Allocate memory for rx buffer */
1344 nv_osallocrxbuf(PNV_VOID ctx, PMEMORY_BLOCK mem, PNV_VOID *id)
1346 struct nv_softc *sc = ctx;
1347 struct nv_rx_desc *desc;
1348 struct nv_map_buffer *buf;
1353 DEBUGOUT(NV_DEBUG_API, "nv: nv_osallocrxbuf\n");
1355 if (sc->pending_rxs == RX_RING_SIZE) {
1356 device_printf(sc->dev, "rx ring buffer is full\n");
1359 desc = sc->rx_desc + sc->cur_rx;
1362 if (buf->mbuf == NULL) {
1363 buf->mbuf = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
1364 if (buf->mbuf == NULL) {
1365 device_printf(sc->dev, "failed to allocate memory\n");
1368 buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
1369 m_adj(buf->mbuf, ETHER_ALIGN);
1371 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
1372 nv_dmamap_rx_cb, &desc->paddr, 0);
1374 device_printf(sc->dev, "failed to dmamap mbuf\n");
1379 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
1380 desc->buflength = buf->mbuf->m_len;
1381 desc->vaddr = mtod(buf->mbuf, PVOID);
1384 sc->cur_rx = (sc->cur_rx + 1) % RX_RING_SIZE;
1386 mem->pLogical = (void *)desc->vaddr;
1387 mem->pPhysical = (void *)desc->paddr;
1388 mem->uiLength = desc->buflength;
1400 /* Free the rx buffer */
1402 nv_osfreerxbuf(PNV_VOID ctx, PMEMORY_BLOCK mem, PNV_VOID id)
1404 struct nv_softc *sc = ctx;
1405 struct nv_rx_desc *desc;
1406 struct nv_map_buffer *buf;
1410 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfreerxbuf\n");
1412 desc = (struct nv_rx_desc *) id;
1416 bus_dmamap_unload(sc->mtag, buf->map);
1417 bus_dmamap_destroy(sc->mtag, buf->map);
1428 /* This gets called by the Nvidia API after our TX packet has been sent */
1430 nv_ospackettx(PNV_VOID ctx, PNV_VOID id, NV_UINT32 success)
1432 struct nv_softc *sc = ctx;
1433 struct nv_map_buffer *buf;
1434 struct nv_tx_desc *desc = (struct nv_tx_desc *) id;
1439 DEBUGOUT(NV_DEBUG_API, "nv: nv_ospackettx\n");
1445 /* Unload and free mbuf cluster */
1446 if (buf->mbuf == NULL)
1449 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTWRITE);
1450 bus_dmamap_unload(sc->mtag, buf->map);
1454 if (!ifq_is_empty(&ifp->if_snd) && sc->pending_txs < TX_RING_SIZE)
1463 /* This gets called by the Nvidia API when a new packet has been received */
1464 /* XXX What is newbuf used for? XXX */
1466 nv_ospacketrx(PNV_VOID ctx, PNV_VOID data, NV_UINT32 success,
1467 NV_UINT8 *newbuf, NV_UINT8 priority)
1469 struct nv_softc *sc = ctx;
1471 struct nv_rx_desc *desc;
1472 struct nv_map_buffer *buf;
1473 ADAPTER_READ_DATA *readdata;
1476 DEBUGOUT(NV_DEBUG_API, "nv: nv_ospacketrx\n");
1480 readdata = (ADAPTER_READ_DATA *) data;
1481 desc = readdata->pvID;
1483 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1486 /* Sync DMA bounce buffer. */
1487 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1489 /* First mbuf in packet holds the ethernet and packet headers */
1490 buf->mbuf->m_pkthdr.rcvif = ifp;
1491 buf->mbuf->m_pkthdr.len = buf->mbuf->m_len = readdata->ulTotalLength;
1493 bus_dmamap_unload(sc->mtag, buf->map);
1495 /* Give mbuf to OS. */
1496 (*ifp->if_input) (ifp, buf->mbuf);
1497 if (readdata->ulFilterMatch & ADREADFL_MULTICAST_MATCH)
1500 /* Blat the mbuf pointer, kernel will free the mbuf cluster */
1503 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1504 bus_dmamap_unload(sc->mtag, buf->map);
1509 sc->cur_rx = desc - sc->rx_desc;
1517 /* This gets called by NVIDIA API when the PHY link state changes */
1519 nv_oslinkchg(PNV_VOID ctx, NV_SINT32 enabled)
1521 struct nv_softc *sc = (struct nv_softc *)ctx;
1524 DEBUGOUT(NV_DEBUG_API, "nv: nv_oslinkchg\n");
1529 ifp->if_flags |= IFF_UP;
1531 ifp->if_flags &= ~IFF_UP;
1538 /* Setup a watchdog timer */
1540 nv_osalloctimer(PNV_VOID ctx, PNV_VOID *timer)
1542 struct nv_softc *sc = (struct nv_softc *)ctx;
1544 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osalloctimer\n");
1546 callout_init(&sc->ostimer);
1547 *timer = &sc->ostimer;
1552 /* Free the timer */
1554 nv_osfreetimer(PNV_VOID ctx, PNV_VOID timer)
1556 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osfreetimer\n");
1561 /* Setup timer parameters */
1563 nv_osinittimer(PNV_VOID ctx, PNV_VOID timer, PTIMER_FUNC func, PNV_VOID parameters)
1565 struct nv_softc *sc = (struct nv_softc *)ctx;
1567 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osinittimer\n");
1569 sc->ostimer_func = func;
1570 sc->ostimer_params = parameters;
1575 /* Set the timer to go off */
1577 nv_ossettimer(PNV_VOID ctx, PNV_VOID timer, NV_UINT32 delay)
1579 struct nv_softc *sc = ctx;
1581 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ossettimer\n");
1583 callout_reset(&sc->ostimer, delay, sc->ostimer_func,
1584 sc->ostimer_params);
1589 /* Cancel the timer */
1591 nv_oscanceltimer(PNV_VOID ctx, PNV_VOID timer)
1593 struct nv_softc *sc = ctx;
1595 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_oscanceltimer\n");
1597 callout_stop(&sc->ostimer);
1603 nv_ospreprocpkt(PNV_VOID ctx, PNV_VOID readdata, PNV_VOID *id, NV_UINT8 *newbuffer,
1606 /* Not implemented */
1607 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ospreprocpkt\n");
1613 nv_ospreprocpktnopq(PNV_VOID ctx, PNV_VOID readdata)
1615 /* Not implemented */
1616 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ospreprocpkt\n");
1622 nv_osindicatepkt(PNV_VOID ctx, PNV_VOID *id, NV_UINT32 pktno)
1624 /* Not implemented */
1625 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osindicatepkt\n");
1630 /* Allocate mutex context (already done in nv_attach) */
1632 nv_oslockalloc(PNV_VOID ctx, NV_SINT32 type, PNV_VOID *pLock)
1634 struct nv_softc *sc = (struct nv_softc *)ctx;
1636 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockalloc\n");
1638 *pLock = (void **)sc;
1643 /* Obtain a spin lock */
1645 nv_oslockacquire(PNV_VOID ctx, NV_SINT32 type, PNV_VOID lock)
1647 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockacquire\n");
1649 NV_OSLOCK((struct nv_softc *)lock);
1656 nv_oslockrelease(PNV_VOID ctx, NV_SINT32 type, PNV_VOID lock)
1658 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockrelease\n");
1660 NV_OSUNLOCK((struct nv_softc *)lock);
1665 /* I have no idea what this is for */
1667 nv_osreturnbufvirt(PNV_VOID ctx, PNV_VOID readdata)
1669 /* Not implemented */
1670 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_osreturnbufvirt\n");
1671 panic("nv: nv_osreturnbufvirtual not implemented\n");
1677 /* --- End on NVOSAPI interface --- */