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.10 2005/04/04 18:45:07 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(dev, SYS_RES_MEMORY, &rid,
306 0, ~0, 1, 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(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
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);
508 device_printf(sc->dev, "couldn't set up interrupt handler\n");
511 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_attach - exit\n");
520 /* Detach interface for module unload */
522 nv_detach(device_t dev)
524 struct nv_softc *sc = device_get_softc(dev);
529 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - entry\n");
531 ifp = &sc->arpcom.ac_if;
533 if (device_is_attached(dev)) {
539 device_delete_child(dev, sc->miibus);
540 bus_generic_detach(dev);
542 /* Reload unreversed address back into MAC in original state */
543 if (sc->original_mac_addr)
544 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, sc->original_mac_addr);
546 DEBUGOUT(NV_DEBUG_DEINIT, "nv: do pfnClose\n");
547 /* Detach from NVIDIA hardware API */
548 if (sc->hwapi->pfnClose)
549 sc->hwapi->pfnClose(sc->hwapi->pADCX, FALSE);
550 /* Release resources */
552 bus_teardown_intr(sc->dev, sc->irq, sc->sc_ih);
554 bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq);
556 bus_release_resource(sc->dev, SYS_RES_MEMORY, NV_RID, sc->res);
561 bus_dmamap_unload(sc->rtag, sc->rmap);
562 bus_dmamem_free(sc->rtag, sc->rx_desc, sc->rmap);
563 bus_dmamap_destroy(sc->rtag, sc->rmap);
566 bus_dma_tag_destroy(sc->mtag);
568 bus_dma_tag_destroy(sc->ttag);
570 bus_dma_tag_destroy(sc->rtag);
574 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_detach - exit\n");
579 /* Initialise interface and start it "RUNNING" */
583 struct nv_softc *sc = xsc;
589 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init - entry (%d)\n", sc->linkup);
593 /* Do nothing if already running */
594 if (ifp->if_flags & IFF_RUNNING)
599 DEBUGOUT(NV_DEBUG_INIT, "nv: do pfnInit\n");
600 /* Setup Hardware interface and allocate memory structures */
601 error = sc->hwapi->pfnInit(sc->hwapi->pADCX,
603 0, /* force full duplex */
605 0, /* force async mode */
609 device_printf(sc->dev, "failed to start NVIDIA Hardware interface\n");
612 /* Set the MAC address */
613 sc->hwapi->pfnSetNodeAddress(sc->hwapi->pADCX, sc->sc_macaddr);
614 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
615 sc->hwapi->pfnStart(sc->hwapi->pADCX);
617 /* Setup multicast filter */
621 /* Update interface parameters */
622 ifp->if_flags |= IFF_RUNNING;
623 ifp->if_flags &= ~IFF_OACTIVE;
625 callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc);
627 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init - exit\n");
635 /* Stop interface activity ie. not "RUNNING" */
637 nv_stop(struct nv_softc *sc)
643 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_stop - entry\n");
648 /* Cancel tick timer */
649 callout_stop(&sc->nv_stat_timer);
651 /* Stop hardware activity */
652 sc->hwapi->pfnDisableInterrupts(sc->hwapi->pADCX);
653 sc->hwapi->pfnStop(sc->hwapi->pADCX, 0);
655 DEBUGOUT(NV_DEBUG_DEINIT, "nv: do pfnDeinit\n");
656 /* Shutdown interface and deallocate memory buffers */
657 if (sc->hwapi->pfnDeinit)
658 sc->hwapi->pfnDeinit(sc->hwapi->pADCX, 0);
664 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
666 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_stop - exit\n");
673 /* Shutdown interface for unload/reboot */
675 nv_shutdown(device_t dev)
679 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_shutdown\n");
681 sc = device_get_softc(dev);
683 /* Stop hardware activity */
687 /* Allocate TX ring buffers */
689 nv_init_rings(struct nv_softc *sc)
695 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init_rings - entry\n");
697 sc->cur_rx = sc->cur_tx = sc->pending_rxs = sc->pending_txs = 0;
698 /* Initialise RX ring */
699 for (i = 0; i < RX_RING_SIZE; i++) {
700 struct nv_rx_desc *desc = sc->rx_desc + i;
701 struct nv_map_buffer *buf = &desc->buf;
703 buf->mbuf = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
704 if (buf->mbuf == NULL) {
705 device_printf(sc->dev, "couldn't allocate mbuf\n");
710 buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
711 m_adj(buf->mbuf, ETHER_ALIGN);
713 error = bus_dmamap_create(sc->mtag, 0, &buf->map);
715 device_printf(sc->dev, "couldn't create dma map\n");
719 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
720 nv_dmamap_rx_cb, &desc->paddr, 0);
722 device_printf(sc->dev, "couldn't dma map mbuf\n");
726 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
728 desc->buflength = buf->mbuf->m_len;
729 desc->vaddr = mtod(buf->mbuf, caddr_t);
731 bus_dmamap_sync(sc->rtag, sc->rmap,
732 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
734 /* Initialize TX ring */
735 for (i = 0; i < TX_RING_SIZE; i++) {
736 struct nv_tx_desc *desc = sc->tx_desc + i;
737 struct nv_map_buffer *buf = &desc->buf;
741 error = bus_dmamap_create(sc->mtag, 0, &buf->map);
743 device_printf(sc->dev, "couldn't create dma map\n");
748 bus_dmamap_sync(sc->ttag, sc->tmap,
749 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
751 DEBUGOUT(NV_DEBUG_INIT, "nv: nv_init_rings - exit\n");
759 /* Free the TX ring buffers */
761 nv_free_rings(struct nv_softc *sc)
767 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_free_rings - entry\n");
769 for (i = 0; i < RX_RING_SIZE; i++) {
770 struct nv_rx_desc *desc = sc->rx_desc + i;
771 struct nv_map_buffer *buf = &desc->buf;
774 bus_dmamap_unload(sc->mtag, buf->map);
775 bus_dmamap_destroy(sc->mtag, buf->map);
781 for (i = 0; i < TX_RING_SIZE; i++) {
782 struct nv_tx_desc *desc = sc->tx_desc + i;
783 struct nv_map_buffer *buf = &desc->buf;
786 bus_dmamap_unload(sc->mtag, buf->map);
787 bus_dmamap_destroy(sc->mtag, buf->map);
793 DEBUGOUT(NV_DEBUG_DEINIT, "nv: nv_free_rings - exit\n");
798 /* Main loop for sending packets from OS to interface */
800 nv_ifstart(struct ifnet *ifp)
802 struct nv_softc *sc = ifp->if_softc;
803 struct nv_map_buffer *buf;
805 struct nv_tx_desc *desc;
806 ADAPTER_WRITE_DATA txdata;
809 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_ifstart - entry\n");
811 /* If link is down/busy or queue is empty do nothing */
812 if (ifp->if_flags & IFF_OACTIVE || ifq_is_empty(&ifp->if_snd))
815 /* Transmit queued packets until sent or TX ring is full */
816 while (sc->pending_txs < TX_RING_SIZE) {
817 desc = sc->tx_desc + sc->cur_tx;
820 /* Get next packet to send. */
821 m0 = ifq_dequeue(&ifp->if_snd);
823 /* If nothing to send, return. */
827 /* Map MBUF for DMA access */
828 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m0,
829 nv_dmamap_tx_cb, desc, BUS_DMA_NOWAIT);
831 if (error && error != EFBIG) {
837 * Packet has too many fragments - defrag into new mbuf
841 m = m_defrag(m0, MB_DONTWAIT);
850 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m,
851 nv_dmamap_tx_cb, desc, BUS_DMA_NOWAIT);
858 /* Do sync on DMA bounce buffer */
859 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREWRITE);
862 txdata.ulNumberOfElements = desc->numfrags;
863 txdata.pvID = (PVOID)desc;
865 /* Put fragments into API element list */
866 txdata.ulTotalLength = buf->mbuf->m_len;
867 for (i = 0; i < desc->numfrags; i++) {
868 txdata.sElement[i].ulLength = (ulong)desc->frags[i].ds_len;
869 txdata.sElement[i].pPhysical = (PVOID)desc->frags[i].ds_addr;
872 /* Send packet to Nvidia API for transmission */
873 error = sc->hwapi->pfnWrite(sc->hwapi->pADCX, &txdata);
876 case ADAPTERERR_NONE:
877 /* Packet was queued in API TX queue successfully */
879 sc->cur_tx = (sc->cur_tx + 1) % TX_RING_SIZE;
882 case ADAPTERERR_TRANSMIT_QUEUE_FULL:
883 /* The API TX queue is full - requeue the packet */
884 device_printf(sc->dev, "nv_ifstart: transmit queue is full\n");
885 ifp->if_flags |= IFF_OACTIVE;
886 bus_dmamap_unload(sc->mtag, buf->map);
891 /* The API failed to queue/send the packet so dump it */
892 device_printf(sc->dev, "nv_ifstart: transmit error\n");
893 bus_dmamap_unload(sc->mtag, buf->map);
899 /* Set watchdog timer. */
902 /* Copy packet to BPF tap */
905 ifp->if_flags |= IFF_OACTIVE;
907 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_ifstart - exit\n");
910 /* Handle IOCTL events */
912 nv_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
914 struct nv_softc *sc = ifp->if_softc;
915 struct ifreq *ifr = (struct ifreq *) data;
916 struct mii_data *mii;
921 DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - entry\n");
926 if (ifp->if_mtu == ifr->ifr_mtu)
928 if (ifr->ifr_mtu + ifp->if_hdrlen <= MAX_PACKET_SIZE_1518) {
929 ifp->if_mtu = ifr->ifr_mtu;
937 /* Setup interface flags */
938 if (ifp->if_flags & IFF_UP) {
939 if ((ifp->if_flags & IFF_RUNNING) == 0) {
944 if (ifp->if_flags & IFF_RUNNING) {
950 /* Handle IFF_PROMISC and IFF_ALLMULTI flags. */
956 /* Setup multicast filter */
957 if (ifp->if_flags & IFF_RUNNING) {
963 /* Get/Set interface media parameters */
964 mii = device_get_softc(sc->miibus);
965 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
969 /* Everything else we forward to generic ether ioctl */
970 error = ether_ioctl(ifp, (int)command, data);
974 DEBUGOUT(NV_DEBUG_IOCTL, "nv: nv_ioctl - exit\n");
981 /* Interrupt service routine */
985 struct nv_softc *sc = arg;
986 struct ifnet *ifp = &sc->sc_if;
988 DEBUGOUT(NV_DEBUG_INTERRUPT, "nv: nv_intr - entry\n");
990 if (!ifp->if_flags & IFF_UP) {
994 /* Handle interrupt event */
995 if (sc->hwapi->pfnQueryInterrupt(sc->hwapi->pADCX)) {
996 sc->hwapi->pfnHandleInterrupt(sc->hwapi->pADCX);
997 sc->hwapi->pfnEnableInterrupts(sc->hwapi->pADCX);
999 if (!ifq_is_empty(&ifp->if_snd))
1002 /* If no pending packets we don't need a timeout */
1003 if (sc->pending_txs == 0)
1004 sc->sc_if.if_timer = 0;
1006 DEBUGOUT(NV_DEBUG_INTERRUPT, "nv: nv_intr - exit\n");
1011 /* Setup multicast filters */
1013 nv_setmulti(struct nv_softc *sc)
1016 struct ifmultiaddr *ifma;
1017 PACKET_FILTER hwfilter;
1020 u_int8_t andaddr[6];
1024 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_setmulti - entry\n");
1028 /* Initialize filter */
1029 hwfilter.ulFilterFlags = 0;
1030 for (i = 0; i < 6; i++) {
1031 hwfilter.acMulticastAddress[i] = 0;
1032 hwfilter.acMulticastMask[i] = 0;
1035 if (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) {
1036 /* Accept all packets */
1037 hwfilter.ulFilterFlags |= ACCEPT_ALL_PACKETS;
1038 sc->hwapi->pfnSetPacketFilter(sc->hwapi->pADCX, &hwfilter);
1042 /* Setup multicast filter */
1043 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1046 if (ifma->ifma_addr->sa_family != AF_LINK)
1049 addrp = LLADDR((struct sockaddr_dl *) ifma->ifma_addr);
1050 for (i = 0; i < 6; i++) {
1051 u_int8_t mcaddr = addrp[i];
1052 andaddr[i] &= mcaddr;
1053 oraddr[i] |= mcaddr;
1056 for (i = 0; i < 6; i++) {
1057 hwfilter.acMulticastAddress[i] = andaddr[i] & oraddr[i];
1058 hwfilter.acMulticastMask[i] = andaddr[i] | (~oraddr[i]);
1061 /* Send filter to NVIDIA API */
1062 sc->hwapi->pfnSetPacketFilter(sc->hwapi->pADCX, &hwfilter);
1066 DEBUGOUT(NV_DEBUG_RUNNING, "nv: nv_setmulti - exit\n");
1071 /* Change the current media/mediaopts */
1073 nv_ifmedia_upd(struct ifnet *ifp)
1075 struct nv_softc *sc = ifp->if_softc;
1076 struct mii_data *mii;
1078 DEBUGOUT(NV_DEBUG_MII, "nv: nv_ifmedia_upd\n");
1080 mii = device_get_softc(sc->miibus);
1082 if (mii->mii_instance) {
1083 struct mii_softc *miisc;
1084 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1085 miisc = LIST_NEXT(miisc, mii_list)) {
1086 mii_phy_reset(miisc);
1094 /* Update current miibus PHY status of media */
1096 nv_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1098 struct nv_softc *sc;
1099 struct mii_data *mii;
1101 DEBUGOUT(NV_DEBUG_MII, "nv: nv_ifmedia_sts\n");
1104 mii = device_get_softc(sc->miibus);
1107 ifmr->ifm_active = mii->mii_media_active;
1108 ifmr->ifm_status = mii->mii_media_status;
1113 /* miibus tick timer - maintain link status */
1117 struct nv_softc *sc = xsc;
1118 struct mii_data *mii;
1124 nv_update_stats(sc);
1126 mii = device_get_softc(sc->miibus);
1129 if (mii->mii_media_status & IFM_ACTIVE &&
1130 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1131 if (!ifq_is_empty(&ifp->if_snd))
1134 callout_reset(&sc->nv_stat_timer, hz, nv_tick, sc);
1141 /* Update ifnet data structure with collected interface stats from API */
1143 nv_update_stats(struct nv_softc *sc)
1145 struct ifnet *ifp = &sc->sc_if;
1146 ADAPTER_STATS stats;
1151 sc->hwapi->pfnGetStatistics(sc->hwapi->pADCX, &stats);
1153 ifp->if_ipackets = stats.ulSuccessfulReceptions;
1154 ifp->if_ierrors = stats.ulMissedFrames +
1155 stats.ulFailedReceptions +
1157 stats.ulFramingErrors +
1158 stats.ulOverFlowErrors;
1160 ifp->if_opackets = stats.ulSuccessfulTransmissions;
1161 ifp->if_oerrors = sc->tx_errors +
1162 stats.ulFailedTransmissions +
1163 stats.ulRetryErrors +
1164 stats.ulUnderflowErrors +
1165 stats.ulLossOfCarrierErrors +
1166 stats.ulLateCollisionErrors;
1168 ifp->if_collisions = stats.ulLateCollisionErrors;
1175 /* miibus Read PHY register wrapper - calls Nvidia API entry point */
1177 nv_miibus_readreg(device_t dev, int phy, int reg)
1179 struct nv_softc *sc = device_get_softc(dev);
1182 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_readreg - entry\n");
1184 ADAPTER_ReadPhy(sc->hwapi->pADCX, phy, reg, &data);
1186 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_readreg - exit\n");
1191 /* miibus Write PHY register wrapper - calls Nvidia API entry point */
1193 nv_miibus_writereg(device_t dev, int phy, int reg, int data)
1195 struct nv_softc *sc = device_get_softc(dev);
1197 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_writereg - entry\n");
1199 ADAPTER_WritePhy(sc->hwapi->pADCX, phy, reg, (ulong)data);
1201 DEBUGOUT(NV_DEBUG_MII, "nv: nv_miibus_writereg - exit\n");
1206 /* Watchdog timer to prevent PHY lockups */
1208 nv_watchdog(struct ifnet *ifp)
1210 struct nv_softc *sc = ifp->if_softc;
1212 device_printf(sc->dev, "device timeout (%d)\n", sc->pending_txs);
1217 ifp->if_flags &= ~IFF_RUNNING;
1220 if (!ifq_is_empty(&ifp->if_snd))
1226 /* --- Start of NVOSAPI interface --- */
1228 /* Allocate DMA enabled general use memory for API */
1230 nv_osalloc(PNV_VOID ctx, PMEMORY_BLOCK mem)
1232 struct nv_softc *sc;
1233 bus_addr_t mem_physical;
1235 DEBUGOUT(NV_DEBUG_API, "nv: nv_osalloc - %d\n", mem->uiLength);
1237 sc = (struct nv_softc *)ctx;
1239 mem->pLogical = (PVOID)contigmalloc(mem->uiLength, M_DEVBUF,
1240 M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE, 0);
1242 if (!mem->pLogical) {
1243 device_printf(sc->dev, "memory allocation failed\n");
1246 memset(mem->pLogical, 0, (ulong)mem->uiLength);
1247 mem_physical = vtophys(mem->pLogical);
1248 mem->pPhysical = (PVOID)mem_physical;
1250 DEBUGOUT(NV_DEBUG_API, "nv: nv_osalloc %p/%p - %d\n",
1251 mem->pLogical, mem->pPhysical, mem->uiLength);
1256 /* Free allocated memory */
1258 nv_osfree(PNV_VOID ctx, PMEMORY_BLOCK mem)
1260 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfree - %p - %d\n",
1261 mem->pLogical, mem->uiLength);
1263 contigfree(mem->pLogical, PAGE_SIZE, M_DEVBUF);
1267 /* Copied directly from nvnet.c */
1269 nv_osallocex(PNV_VOID ctx, PMEMORY_BLOCKEX mem_block_ex)
1271 MEMORY_BLOCK mem_block;
1273 DEBUGOUT(NV_DEBUG_API, "nv: nv_osallocex\n");
1275 mem_block_ex->pLogical = NULL;
1276 mem_block_ex->uiLengthOrig = mem_block_ex->uiLength;
1278 if ((mem_block_ex->AllocFlags & ALLOC_MEMORY_ALIGNED) &&
1279 (mem_block_ex->AlignmentSize > 1)) {
1280 DEBUGOUT(NV_DEBUG_API, " aligning on %d\n",
1281 mem_block_ex->AlignmentSize);
1282 mem_block_ex->uiLengthOrig += mem_block_ex->AlignmentSize;
1284 mem_block.uiLength = mem_block_ex->uiLengthOrig;
1286 if (nv_osalloc(ctx, &mem_block) == 0) {
1289 mem_block_ex->pLogicalOrig = mem_block.pLogical;
1290 mem_block_ex->pPhysicalOrigLow = (uintptr_t)mem_block.pPhysical;
1291 mem_block_ex->pPhysicalOrigHigh = 0;
1293 mem_block_ex->pPhysical = mem_block.pPhysical;
1294 mem_block_ex->pLogical = mem_block.pLogical;
1296 if (mem_block_ex->uiLength != mem_block_ex->uiLengthOrig) {
1297 unsigned int offset;
1298 offset = mem_block_ex->pPhysicalOrigLow & (mem_block_ex->AlignmentSize - 1);
1301 mem_block_ex->pPhysical = (PVOID)((uintptr_t)mem_block_ex->pPhysical +
1302 mem_block_ex->AlignmentSize - offset);
1303 mem_block_ex->pLogical = (PVOID)((uintptr_t)mem_block_ex->pLogical +
1304 mem_block_ex->AlignmentSize - offset);
1306 } /* if (mem_block_ex->uiLength !=
1307 * mem_block_ex->uiLengthOrig) */
1311 /* Copied directly from nvnet.c */
1313 nv_osfreeex(PNV_VOID ctx, PMEMORY_BLOCKEX mem_block_ex)
1315 MEMORY_BLOCK mem_block;
1317 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfreeex\n");
1319 mem_block.pLogical = mem_block_ex->pLogicalOrig;
1320 mem_block.pPhysical = (PVOID)((uintptr_t)mem_block_ex->pPhysicalOrigLow);
1321 mem_block.uiLength = mem_block_ex->uiLengthOrig;
1323 return (nv_osfree(ctx, &mem_block));
1326 /* Clear memory region */
1328 nv_osclear(PNV_VOID ctx, PNV_VOID mem, NV_SINT32 length)
1330 DEBUGOUT(NV_DEBUG_API, "nv: nv_osclear\n");
1331 memset(mem, 0, length);
1335 /* Sleep for a tick */
1337 nv_osdelay(PNV_VOID ctx, NV_UINT32 usec)
1343 /* Allocate memory for rx buffer */
1345 nv_osallocrxbuf(PNV_VOID ctx, PMEMORY_BLOCK mem, PNV_VOID *id)
1347 struct nv_softc *sc = ctx;
1348 struct nv_rx_desc *desc;
1349 struct nv_map_buffer *buf;
1354 DEBUGOUT(NV_DEBUG_API, "nv: nv_osallocrxbuf\n");
1356 if (sc->pending_rxs == RX_RING_SIZE) {
1357 device_printf(sc->dev, "rx ring buffer is full\n");
1360 desc = sc->rx_desc + sc->cur_rx;
1363 if (buf->mbuf == NULL) {
1364 buf->mbuf = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
1365 if (buf->mbuf == NULL) {
1366 device_printf(sc->dev, "failed to allocate memory\n");
1369 buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
1370 m_adj(buf->mbuf, ETHER_ALIGN);
1372 error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
1373 nv_dmamap_rx_cb, &desc->paddr, 0);
1375 device_printf(sc->dev, "failed to dmamap mbuf\n");
1380 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
1381 desc->buflength = buf->mbuf->m_len;
1382 desc->vaddr = mtod(buf->mbuf, PVOID);
1385 sc->cur_rx = (sc->cur_rx + 1) % RX_RING_SIZE;
1387 mem->pLogical = (void *)desc->vaddr;
1388 mem->pPhysical = (void *)desc->paddr;
1389 mem->uiLength = desc->buflength;
1401 /* Free the rx buffer */
1403 nv_osfreerxbuf(PNV_VOID ctx, PMEMORY_BLOCK mem, PNV_VOID id)
1405 struct nv_softc *sc = ctx;
1406 struct nv_rx_desc *desc;
1407 struct nv_map_buffer *buf;
1411 DEBUGOUT(NV_DEBUG_API, "nv: nv_osfreerxbuf\n");
1413 desc = (struct nv_rx_desc *) id;
1417 bus_dmamap_unload(sc->mtag, buf->map);
1418 bus_dmamap_destroy(sc->mtag, buf->map);
1429 /* This gets called by the Nvidia API after our TX packet has been sent */
1431 nv_ospackettx(PNV_VOID ctx, PNV_VOID id, NV_UINT32 success)
1433 struct nv_softc *sc = ctx;
1434 struct nv_map_buffer *buf;
1435 struct nv_tx_desc *desc = (struct nv_tx_desc *) id;
1440 DEBUGOUT(NV_DEBUG_API, "nv: nv_ospackettx\n");
1446 /* Unload and free mbuf cluster */
1447 if (buf->mbuf == NULL)
1450 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTWRITE);
1451 bus_dmamap_unload(sc->mtag, buf->map);
1455 if (!ifq_is_empty(&ifp->if_snd) && sc->pending_txs < TX_RING_SIZE)
1464 /* This gets called by the Nvidia API when a new packet has been received */
1465 /* XXX What is newbuf used for? XXX */
1467 nv_ospacketrx(PNV_VOID ctx, PNV_VOID data, NV_UINT32 success,
1468 NV_UINT8 *newbuf, NV_UINT8 priority)
1470 struct nv_softc *sc = ctx;
1472 struct nv_rx_desc *desc;
1473 struct nv_map_buffer *buf;
1474 ADAPTER_READ_DATA *readdata;
1477 DEBUGOUT(NV_DEBUG_API, "nv: nv_ospacketrx\n");
1481 readdata = (ADAPTER_READ_DATA *) data;
1482 desc = readdata->pvID;
1484 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1487 /* Sync DMA bounce buffer. */
1488 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1490 /* First mbuf in packet holds the ethernet and packet headers */
1491 buf->mbuf->m_pkthdr.rcvif = ifp;
1492 buf->mbuf->m_pkthdr.len = buf->mbuf->m_len = readdata->ulTotalLength;
1494 bus_dmamap_unload(sc->mtag, buf->map);
1496 /* Give mbuf to OS. */
1497 (*ifp->if_input) (ifp, buf->mbuf);
1498 if (readdata->ulFilterMatch & ADREADFL_MULTICAST_MATCH)
1501 /* Blat the mbuf pointer, kernel will free the mbuf cluster */
1504 bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
1505 bus_dmamap_unload(sc->mtag, buf->map);
1510 sc->cur_rx = desc - sc->rx_desc;
1518 /* This gets called by NVIDIA API when the PHY link state changes */
1520 nv_oslinkchg(PNV_VOID ctx, NV_SINT32 enabled)
1522 struct nv_softc *sc = (struct nv_softc *)ctx;
1525 DEBUGOUT(NV_DEBUG_API, "nv: nv_oslinkchg\n");
1530 ifp->if_flags |= IFF_UP;
1532 ifp->if_flags &= ~IFF_UP;
1539 /* Setup a watchdog timer */
1541 nv_osalloctimer(PNV_VOID ctx, PNV_VOID *timer)
1543 struct nv_softc *sc = (struct nv_softc *)ctx;
1545 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osalloctimer\n");
1547 callout_init(&sc->ostimer);
1548 *timer = &sc->ostimer;
1553 /* Free the timer */
1555 nv_osfreetimer(PNV_VOID ctx, PNV_VOID timer)
1557 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osfreetimer\n");
1562 /* Setup timer parameters */
1564 nv_osinittimer(PNV_VOID ctx, PNV_VOID timer, PTIMER_FUNC func, PNV_VOID parameters)
1566 struct nv_softc *sc = (struct nv_softc *)ctx;
1568 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osinittimer\n");
1570 sc->ostimer_func = func;
1571 sc->ostimer_params = parameters;
1576 /* Set the timer to go off */
1578 nv_ossettimer(PNV_VOID ctx, PNV_VOID timer, NV_UINT32 delay)
1580 struct nv_softc *sc = ctx;
1582 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ossettimer\n");
1584 callout_reset(&sc->ostimer, delay, sc->ostimer_func,
1585 sc->ostimer_params);
1590 /* Cancel the timer */
1592 nv_oscanceltimer(PNV_VOID ctx, PNV_VOID timer)
1594 struct nv_softc *sc = ctx;
1596 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_oscanceltimer\n");
1598 callout_stop(&sc->ostimer);
1604 nv_ospreprocpkt(PNV_VOID ctx, PNV_VOID readdata, PNV_VOID *id, NV_UINT8 *newbuffer,
1607 /* Not implemented */
1608 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ospreprocpkt\n");
1614 nv_ospreprocpktnopq(PNV_VOID ctx, PNV_VOID readdata)
1616 /* Not implemented */
1617 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_ospreprocpkt\n");
1623 nv_osindicatepkt(PNV_VOID ctx, PNV_VOID *id, NV_UINT32 pktno)
1625 /* Not implemented */
1626 DEBUGOUT(NV_DEBUG_BROKEN, "nv: nv_osindicatepkt\n");
1631 /* Allocate mutex context (already done in nv_attach) */
1633 nv_oslockalloc(PNV_VOID ctx, NV_SINT32 type, PNV_VOID *pLock)
1635 struct nv_softc *sc = (struct nv_softc *)ctx;
1637 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockalloc\n");
1639 *pLock = (void **)sc;
1644 /* Obtain a spin lock */
1646 nv_oslockacquire(PNV_VOID ctx, NV_SINT32 type, PNV_VOID lock)
1648 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockacquire\n");
1650 NV_OSLOCK((struct nv_softc *)lock);
1657 nv_oslockrelease(PNV_VOID ctx, NV_SINT32 type, PNV_VOID lock)
1659 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_oslockrelease\n");
1661 NV_OSUNLOCK((struct nv_softc *)lock);
1666 /* I have no idea what this is for */
1668 nv_osreturnbufvirt(PNV_VOID ctx, PNV_VOID readdata)
1670 /* Not implemented */
1671 DEBUGOUT(NV_DEBUG_LOCK, "nv: nv_osreturnbufvirt\n");
1672 panic("nv: nv_osreturnbufvirtual not implemented\n");
1678 /* --- End on NVOSAPI interface --- */