2 * Copyright (c) 2000, 2001 Richard Hodges and Matriplex, inc.
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.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Matriplex, inc.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 ******************************************************************************
33 * This driver is derived from the Nicstar driver by Mark Tinguely, and
34 * some of the original driver still exists here. Those portions are...
35 * Copyright (c) 1996, 1997, 1998, 1999 Mark Tinguely
36 * All rights reserved.
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
54 #include <sys/module.h>
55 #include <machine/bus.h>
56 #include <machine/resource.h>
60 #include <net/if_arp.h>
62 #include <netatm/port.h>
63 #include <netatm/queue.h>
64 #include <netatm/atm.h>
65 #include <netatm/atm_sys.h>
66 #include <netatm/atm_sap.h>
67 #include <netatm/atm_cm.h>
68 #include <netatm/atm_if.h>
69 #include <netatm/atm_stack.h>
70 #include <netatm/atm_pcb.h>
71 #include <netatm/atm_var.h>
73 #include <dev/pci/pcireg.h>
74 #include <dev/pci/pcivar.h>
76 #include <dev/idt/idtreg.h>
77 #include <dev/idt/idtvar.h>
79 #define IDT_VID 0x111d
80 #define IDT_NICSTAR_DID 0x0001
87 { IDT_VID, IDT_NICSTAR_DID, "IDT IDT77201/211 NICStAR ATM Adapter" },
91 uma_zone_t idt_nif_zone;
92 uma_zone_t idt_vcc_zone;
94 static int idt_probe (device_t);
95 static int idt_attach (device_t);
96 static int idt_detach (device_t);
97 static int idt_shutdown (device_t);
98 static void idt_free (device_t);
99 static int idt_modevent (module_t, int, void *);
102 idt_probe(device_t dev)
104 struct pci_type *t = pci_devs;
106 while(t->pci_name != NULL) {
107 if ((pci_get_vendor(dev) == t->pci_vid) &&
108 (pci_get_device(dev) == t->pci_did)) {
109 device_set_desc(dev, t->pci_name);
110 return(BUS_PROBE_DEFAULT);
118 /******************************************************************************
122 * Date first: 11/14/2000 last: 06/10/2001
126 idt_attach(device_t dev)
128 struct idt_softc *sc;
131 sc = device_get_softc(dev);
135 pci_enable_busmaster(dev);
137 /* count = 2 (times 32 PCI clocks) */
138 pci_write_config(dev, PCIR_LATTIMER, 0x20, 1);
140 /* Map IDT registers */
142 sc->mem_type = SYS_RES_MEMORY;
143 sc->mem = bus_alloc_resource_any(dev, sc->mem_type, &sc->mem_rid,
145 if (sc->mem == NULL) {
146 device_printf(dev, "could not map registers.\n");
150 sc->bustag = rman_get_bustag(sc->mem);
151 sc->bushandle = rman_get_bushandle(sc->mem);
155 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
156 RF_ACTIVE | RF_SHAREABLE);
157 if (sc->irq == NULL) {
158 device_printf(dev, "could not map interrupt.\n");
163 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, nicstar_intr,
166 device_printf(dev, "could not setup irq.\n");
171 sc->virt_baseaddr = (vm_offset_t)rman_get_virtual(sc->mem);
172 sc->cmd_reg = sc->virt_baseaddr + REGCMD; /* old reg */
173 sc->stat_reg = sc->virt_baseaddr + REGSTAT; /* old reg */
174 sc->reg_cmd = (u_long *)(sc->virt_baseaddr + REGCMD);
175 sc->reg_stat = (u_long *)(sc->virt_baseaddr + REGSTAT);
176 sc->reg_cfg = (u_long *)(sc->virt_baseaddr + REGCFG);
177 sc->reg_data = (u_long *)(sc->virt_baseaddr + 0);
178 sc->reg_tsqh = (u_long *)(sc->virt_baseaddr + REGTSQH);
179 sc->reg_gp = (u_long *)(sc->virt_baseaddr + REGGP);
180 sc->pci_rev = pci_get_revid(dev);
183 callout_handle_init(&sc->ch);
185 phys_init(sc); /* initialize the hardware */
186 nicstar_init(sc); /* allocate and initialize */
188 error = idt_harp_init(sc);
198 /******************************************************************************
202 * Date first: 11/14/2000 last: 11/14/2000
206 idt_detach(device_t dev)
208 struct idt_softc *sc;
211 sc = device_get_softc(dev);
215 * De-Register this interface with ATM core services
217 error = atm_physif_deregister(&sc->iu_cmn);
219 idt_device_stop(sc); /* Stop the device */
222 * Lock out all device interupts.
224 DEVICE_LOCK(&sc->iu_cmn);
227 DEVICE_UNLOCK(&sc->iu_cmn);
232 /******************************************************************************
236 * Date first: 11/14/2000 last: 11/14/2000
240 idt_shutdown(device_t dev)
243 struct idt_softc *sc;
245 sc = device_get_softc(dev);
247 idt_device_stop(sc); /* Stop the device */
253 idt_free (device_t dev)
255 struct idt_softc *sc;
257 sc = device_get_softc(dev);
260 bus_teardown_intr(dev, sc->irq, sc->irq_ih);
262 bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
264 bus_release_resource(dev, sc->mem_type, sc->mem_rid, sc->mem);
270 idt_modevent (module_t mod, int type, void *data)
278 idt_nif_zone = uma_zcreate("idt nif",
279 sizeof(struct atm_nif),
280 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
281 if (idt_nif_zone == NULL)
282 panic("hfa_modevent:uma_zcreate nif");
283 uma_zone_set_max(idt_nif_zone, 20);
285 idt_vcc_zone = uma_zcreate("idt vcc",
287 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
288 if (idt_vcc_zone == NULL)
289 panic("hfa_modevent: uma_zcreate vcc");
290 uma_zone_set_max(idt_vcc_zone, 100);
295 uma_zdestroy(idt_nif_zone);
296 uma_zdestroy(idt_vcc_zone);
306 static device_method_t idt_methods[] = {
307 DEVMETHOD(device_probe, idt_probe),
308 DEVMETHOD(device_attach, idt_attach),
309 DEVMETHOD(device_detach, idt_detach),
310 DEVMETHOD(device_shutdown, idt_shutdown),
314 static driver_t idt_driver = {
317 sizeof(struct idt_softc)
320 static devclass_t idt_devclass;
322 DRIVER_MODULE(idt, pci, idt_driver, idt_devclass, idt_modevent, 0);
323 MODULE_VERSION(idt, 1);