1 /* $NetBSD: if_fea.c,v 1.41 2009/05/12 14:21:32 cegger Exp $ */
4 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * Id: if_fea.c,v 1.8 1997/03/21 13:45:45 thomas Exp
30 * DEC PDQ FDDI Controller
32 * This module support the DEFEA EISA FDDI Controller.
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: if_fea.c,v 1.41 2009/05/12 14:21:32 cegger Exp $");
40 #include <sys/param.h>
41 #include <sys/kernel.h>
43 #include <sys/protosw.h>
44 #include <sys/socket.h>
45 #include <sys/ioctl.h>
46 #include <sys/errno.h>
47 #include <sys/malloc.h>
48 #if defined(__FreeBSD__)
49 #include <sys/devconf.h>
50 #elif defined(__bsdi__) || defined(__NetBSD__)
51 #include <sys/device.h>
55 #include <net/if_types.h>
56 #include <net/if_dl.h>
61 #include <net/bpfdesc.h>
65 #include <netinet/in.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/in_var.h>
68 #include <netinet/ip.h>
71 #if defined(__FreeBSD__)
72 #include <netinet/if_fddi.h>
74 #include <net/if_fddi.h>
77 #if defined(__FreeBSD__)
78 #include <netinet/if_ether.h>
79 #include <i386/eisa/eisaconf.h>
80 #include <i386/isa/icu.h>
81 #include <dev/pdq/pdqvar.h>
82 #include <dev/pdq/pdqreg.h>
83 #elif defined(__bsdi__)
84 #include <netinet/if_ether.h>
85 #include <i386/isa/isa.h>
86 #include <i386/isa/icu.h>
87 #include <i386/isa/dma.h>
88 #include <i386/isa/isavar.h>
89 #include <i386/eisa/eisa.h>
90 #include <dev/pdq/pdqvar.h>
91 #include <dev/pdq/pdqreg.h>
92 #elif defined(__NetBSD__)
96 #include <dev/ic/pdqvar.h>
97 #include <dev/ic/pdqreg.h>
99 #include <dev/eisa/eisareg.h>
100 #include <dev/eisa/eisavar.h>
101 #include <dev/eisa/eisadevs.h>
108 #define DEFEA_IRQS 0x0000FBA9U
110 #if defined(__FreeBSD__)
111 static pdq_softc_t
*pdqs_eisa
[16];
112 #define PDQ_EISA_UNIT_TO_SOFTC(unit) (pdqs_eisa[unit])
113 #define DEFEA_INTRENABLE 0x8 /* level interrupt */
114 #define pdq_eisa_ifwatchdog NULL
115 #define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
117 #elif defined(__bsdi__)
118 extern struct cfdriver feacd
;
119 #define PDQ_EISA_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)device_lookup_private(&feacd, unit))
120 #define DEFEA_INTRENABLE 0x28 /* edge interrupt */
121 static const int pdq_eisa_irqs
[4] = { IRQ9
, IRQ10
, IRQ11
, IRQ15
};
122 #define DEFEA_DECODE_IRQ(n) (pdq_eisa_irqs[(n)])
124 #elif defined(__NetBSD__)
125 #define DEFEA_INTRENABLE 0x8 /* level interrupt */
126 #define pdq_eisa_ifwatchdog NULL
127 #define DEFEA_DECODE_IRQ(n) ((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
130 #error unknown system
133 #ifndef pdq_eisa_ifwatchdog
138 pdq_ifwatchdog(&PDQ_EISA_UNIT_TO_SOFTC(unit
)->sc_if
);
145 pdq_bus_ioport_t iobase
,
151 *irq
= DEFEA_DECODE_IRQ(PDQ_OS_IORD_8(bc
, iobase
, PDQ_EISA_IO_CONFIG_STAT_0
) & 3);
152 *maddr
= (PDQ_OS_IORD_8(bc
, iobase
, PDQ_EISA_MEM_ADD_CMP_0
) << 8)
153 | (PDQ_OS_IORD_8(bc
, iobase
, PDQ_EISA_MEM_ADD_CMP_1
) << 16);
154 *msiz
= (PDQ_OS_IORD_8(bc
, iobase
, PDQ_EISA_MEM_ADD_MASK_0
) + 4) << 8;
164 * Do the standard initialization for the DEFEA registers.
166 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_FUNCTION_CTRL
, 0x23);
167 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_IO_CMP_1_1
, (sc
->sc_iobase
>> 8) & 0xF0);
168 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_IO_CMP_0_1
, (sc
->sc_iobase
>> 8) & 0xF0);
169 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_SLOT_CTRL
, 0x01);
170 data
= PDQ_OS_IORD_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_BURST_HOLDOFF
);
171 #if defined(__NetBSD__)
172 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_BURST_HOLDOFF
,
173 sc
->sc_iotag
== sc
->sc_csrtag
? data
& ~1 : data
| 1);
174 #elif defined(PDQ_IOMAPPED)
175 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_BURST_HOLDOFF
, data
& ~1);
177 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_BURST_HOLDOFF
, data
| 1);
179 data
= PDQ_OS_IORD_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_IO_CONFIG_STAT_0
);
180 PDQ_OS_IOWR_8(sc
->sc_iotag
, sc
->sc_iobase
, PDQ_EISA_IO_CONFIG_STAT_0
, data
| DEFEA_INTRENABLE
);
183 #if defined(__FreeBSD__)
184 static int pdq_eisa_shutdown(struct kern_devconf
*kdc
, int force
);
185 static int pdq_eisa_probe(void);
186 static int pdq_eisa_attach(struct eisa_device
*ed
);
188 static unsigned long pdq_eisa_unit
;
190 static struct eisa_driver pdq_eisa_driver
= {
191 "fea", pdq_eisa_probe
, pdq_eisa_attach
, NULL
, &pdq_eisa_unit
194 DATA_SET(eisadriver_set
, pdq_eisa_driver
);
196 static struct kern_devconf kdc_pdq_eisa
= {
197 0, 0, 0, /* filled in by dev_attach */
198 "fea", 0, { MDDT_EISA
, 0, "net" },
199 eisa_generic_externalize
, 0, pdq_eisa_shutdown
, EISA_EXTERNALLEN
,
200 &kdc_eisa0
, /* parent */
202 DC_BUSY
, /* host adapters are always ``in use'' */
203 "DEC DEFEA EISA FDDI Controller",
211 if ((type
>> 8) == 0x10a330)
212 return kdc_pdq_eisa
.kdc_description
;
220 struct eisa_device
*ed
= NULL
;
223 for (count
= 0; (ed
= eisa_match_dev(ed
, pdq_eisa_match
)) != NULL
; count
++) {
224 pdq_bus_ioport_t iobase
= ed
->ioconf
.slot
* EISA_SLOT_SIZE
;
225 pdq_uint32_t irq
, maddr
, msiz
;
227 eisa_add_iospace(ed
, iobase
, 0x200, RESVADDR_NONE
);
228 pdq_eisa_subprobe(PDQ_BUS_EISA
, iobase
, &maddr
, &msiz
, &irq
);
229 eisa_add_mspace(ed
, maddr
, msiz
, RESVADDR_NONE
);
230 eisa_add_intr(ed
, irq
);
231 eisa_registerdev(ed
, &pdq_eisa_driver
, &kdc_pdq_eisa
);
240 pdq_softc_t
* const sc
= (pdq_softc_t
*) arg
;
241 (void) pdq_interrupt(sc
->sc_pdq
);
246 struct eisa_device
*ed
)
251 int irq
= ffs(ed
->ioconf
.irq
) - 1;
253 sc
= (pdq_softc_t
*) malloc(sizeof(*sc
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
255 printf("fea%d: malloc failed!\n", sc
->sc_if
.if_unit
);
258 pdqs_eisa
[ed
->unit
] = sc
;
260 sc
->sc_if
.if_name
= "fea";
261 sc
->sc_if
.if_unit
= ed
->unit
;
263 if ((iospace
= ed
->ioconf
.ioaddrs
.lh_first
) == NULL
) {
264 printf("fea%d: no iospace??\n", sc
->sc_if
.if_unit
);
267 if ((mspace
= ed
->ioconf
.maddrs
.lh_first
) == NULL
) {
268 printf("fea%d: no memory space??\n", sc
->sc_if
.if_unit
);
272 sc
->sc_iobase
= (pdq_bus_ioport_t
) iospace
->addr
;
273 sc
->sc_membase
= (pdq_bus_memaddr_t
) pmap_mapdev(mspace
->addr
, mspace
->size
);
274 if (sc
->sc_membase
== NULL
) {
275 printf("fea%d: failed to map memory 0x%x-0x%x!\n",
276 sc
->sc_if
.if_unit
, mspace
->addr
, mspace
->addr
+ mspace
->size
- 1);
281 if (eisa_reg_iospace(ed
, iospace
)) {
282 printf("fea%d: failed to register iospace 0x%x-0x%x!\n",
283 sc
->sc_if
.if_unit
, iospace
->addr
, iospace
->addr
+ iospace
->size
- 1);
286 if (eisa_reg_mspace(ed
, mspace
)) {
287 printf("fea%d: failed to register memory 0x%x-0x%x!\n",
288 sc
->sc_if
.if_unit
, mspace
->addr
, mspace
->addr
+ mspace
->size
- 1);
292 if (eisa_reg_intr(ed
, irq
, pdq_eisa_interrupt
, sc
, &net_imask
, 1)) {
293 printf("fea%d: interrupt registration failed\n", sc
->sc_if
.if_unit
);
299 pdq_eisa_devinit(sc
);
300 sc
->sc_pdq
= pdq_initialize(PDQ_BUS_EISA
, sc
->sc_membase
,
301 sc
->sc_if
.if_name
, sc
->sc_if
.if_unit
,
302 (void *) sc
, PDQ_DEFEA
);
303 if (sc
->sc_pdq
== NULL
) {
304 printf("fea%d: initialization failed\n", sc
->sc_if
.if_unit
);
308 if (eisa_enable_intr(ed
, irq
)) {
309 printf("fea%d: failed to enable interrupt\n", sc
->sc_if
.if_unit
);
313 memcpy(sc
->sc_ac
.ac_enaddr
, (void *) sc
->sc_pdq
->pdq_hwaddr
.lanaddr_bytes
, 6);
314 pdq_ifattach(sc
, pdq_eisa_ifwatchdog
);
316 ed
->kdc
->kdc_state
= DC_BUSY
; /* host adapters always busy */
323 struct kern_devconf
*kdc
,
326 pdq_hwreset(PDQ_EISA_UNIT_TO_SOFTC(kdc
->kdc_unit
)->sc_pdq
);
327 (void) dev_detach(kdc
);
330 #endif /* __FreeBSD__ */
332 #if defined(__bsdi__)
339 struct isa_attach_args
*ia
= (struct isa_attach_args
*) aux
;
341 pdq_uint32_t irq
, maddr
, msiz
;
343 if (isa_bustype
!= BUS_EISA
)
346 if ((slot
= eisa_match(cf
, ia
)) == 0)
348 ia
->ia_iobase
= slot
<< 12;
349 ia
->ia_iosize
= EISA_NPORT
;
350 eisa_slotalloc(slot
);
352 pdq_eisa_subprobe(PDQ_BUS_EISA
, ia
->ia_iobase
, &maddr
, &msiz
, &irq
);
353 if (ia
->ia_irq
!= IRQUNK
&& irq
!= ia
->ia_irq
) {
354 printf("fea%d: error: desired IRQ of %d does not match device's actual IRQ (%d),\n",
356 ffs(ia
->ia_irq
) - 1, ffs(irq
) - 1);
359 if (ia
->ia_irq
== IRQUNK
) {
360 if ((ia
->ia_irq
= isa_irqalloc(irq
)) == 0) {
361 if ((ia
->ia_irq
= isa_irqalloc(IRQ9
|IRQ10
|IRQ11
|IRQ15
)) == 0) {
362 printf("fea%d: error: IRQ %d is already in use\n", cf
->cf_unit
,
366 irq
= PDQ_OS_IORD_8(PDQ_BUS_EISA
, ia
->ia_iobase
, PDQ_EISA_IO_CONFIG_STAT_0
) & ~3;
367 switch (ia
->ia_irq
) {
369 case IRQ10
: irq
|= 1;
370 case IRQ11
: irq
|= 2;
371 case IRQ15
: irq
|= 3;
373 PDQ_OS_IOWR_8(PDQ_BUS_EISA
, ia
->ia_iobase
, PDQ_EISA_IO_CONFIG_STAT_0
, irq
);
377 printf("fea%d: error: memory not enabled! ECU reconfiguration required\n",
382 /* EISA bus masters don't use host DMA channels */
383 ia
->ia_drq
= DRQNONE
;
385 ia
->ia_maddr
= (void *) maddr
;
396 pdq_softc_t
*sc
= (pdq_softc_t
*) self
;
397 struct isa_attach_args
*ia
= (struct isa_attach_args
*) aux
;
398 struct ifnet
*ifp
= &sc
->sc_if
;
400 sc
->sc_if
.if_unit
= sc
->sc_dev
.dv_unit
;
401 sc
->sc_if
.if_name
= "fea";
402 sc
->sc_if
.if_flags
= 0;
404 sc
->sc_iobase
= ia
->ia_iobase
;
406 pdq_eisa_devinit(sc
);
407 sc
->sc_pdq
= pdq_initialize(PDQ_BUS_EISA
,
408 (pdq_bus_memaddr_t
) ISA_HOLE_VADDR(ia
->ia_maddr
),
409 sc
->sc_if
.if_name
, sc
->sc_if
.if_unit
,
410 (void *) sc
, PDQ_DEFEA
);
411 if (sc
->sc_pdq
== NULL
) {
412 printf("fea%d: initialization failed\n", sc
->sc_if
.if_unit
);
416 memcpy(sc
->sc_ac
.ac_enaddr
, (void *) sc
->sc_pdq
->pdq_hwaddr
.lanaddr_bytes
, 6);
418 pdq_ifattach(sc
, pdq_eisa_ifwatchdog
);
420 isa_establish(&sc
->sc_id
, &sc
->sc_dev
);
422 sc
->sc_ih
.ih_fun
= pdq_interrupt
;
423 sc
->sc_ih
.ih_arg
= (void *) sc
->sc_pdq
;
424 intr_establish(ia
->ia_irq
, &sc
->sc_ih
, DV_NET
);
426 sc
->sc_ats
.func
= (void (*)(void *)) pdq_hwreset
;
427 sc
->sc_ats
.arg
= (void *) sc
->sc_pdq
;
428 atshutdown(&sc
->sc_ats
, ATSH_ADD
);
431 static char *pdq_eisa_ids
[] = {
432 "DEC3001", /* 0x0130A310 */
433 "DEC3002", /* 0x0230A310 */
434 "DEC3003", /* 0x0330A310 */
435 "DEC3004", /* 0x0430A310 */
438 struct cfdriver feacd
= {
439 0, "fea", pdq_eisa_probe
, pdq_eisa_attach
, DV_IFNET
, sizeof(pdq_softc_t
),
442 #endif /* __bsdi__ */
444 #if defined(__NetBSD__)
451 const struct eisa_attach_args
* const ea
= (struct eisa_attach_args
*) aux
;
453 if (strncmp(ea
->ea_idstring
, "DEC300", 6) == 0)
465 pdq_softc_t
* const sc
= device_private(self
);
466 struct eisa_attach_args
* const ea
= (struct eisa_attach_args
*) aux
;
467 pdq_uint32_t irq
, maddr
, msiz
;
468 eisa_intr_handle_t ih
;
471 sc
->sc_iotag
= ea
->ea_iot
;
472 sc
->sc_dmatag
= ea
->ea_dmat
;
473 memcpy(sc
->sc_if
.if_xname
, device_xname(&sc
->sc_dev
), IFNAMSIZ
);
474 sc
->sc_if
.if_flags
= 0;
475 sc
->sc_if
.if_softc
= sc
;
477 if (bus_space_map(sc
->sc_iotag
, EISA_SLOT_ADDR(ea
->ea_slot
), EISA_SLOT_SIZE
, 0, &sc
->sc_iobase
)) {
479 aprint_error_dev(&sc
->sc_dev
, "failed to map I/O!\n");
483 pdq_eisa_subprobe(sc
->sc_iotag
, sc
->sc_iobase
, &maddr
, &msiz
, &irq
);
485 if (maddr
!= 0 && msiz
!= 0) {
486 sc
->sc_csrtag
= ea
->ea_memt
;
487 if (bus_space_map(sc
->sc_csrtag
, maddr
, msiz
, 0, &sc
->sc_membase
)) {
488 bus_space_unmap(sc
->sc_iotag
, sc
->sc_iobase
, EISA_SLOT_SIZE
);
490 aprint_error_dev(&sc
->sc_dev
, "failed to map memory (0x%x-0x%x)!\n",
491 maddr
, maddr
+ msiz
- 1);
495 sc
->sc_csrtag
= sc
->sc_iotag
;
496 sc
->sc_membase
= sc
->sc_iobase
;
499 pdq_eisa_devinit(sc
);
500 sc
->sc_pdq
= pdq_initialize(sc
->sc_csrtag
, sc
->sc_membase
,
501 sc
->sc_if
.if_xname
, 0,
502 (void *) sc
, PDQ_DEFEA
);
503 if (sc
->sc_pdq
== NULL
) {
504 aprint_error_dev(&sc
->sc_dev
, "initialization failed\n");
508 pdq_ifattach(sc
, pdq_eisa_ifwatchdog
);
510 if (eisa_intr_map(ea
->ea_ec
, irq
, &ih
)) {
511 aprint_error_dev(&sc
->sc_dev
, "couldn't map interrupt (%d)\n", irq
);
514 intrstr
= eisa_intr_string(ea
->ea_ec
, ih
);
515 sc
->sc_ih
= eisa_intr_establish(ea
->ea_ec
, ih
, IST_LEVEL
, IPL_NET
,
516 (int (*)(void *)) pdq_interrupt
, sc
->sc_pdq
);
517 if (sc
->sc_ih
== NULL
) {
518 aprint_error_dev(&sc
->sc_dev
, "couldn't establish interrupt");
520 aprint_error(" at %s", intrstr
);
524 sc
->sc_ats
= shutdownhook_establish((void (*)(void *)) pdq_hwreset
, sc
->sc_pdq
);
525 if (sc
->sc_ats
== NULL
)
526 aprint_error_dev(self
, "warning: couldn't establish shutdown hook\n");
527 if (sc
->sc_csrtag
!= sc
->sc_iotag
)
528 printf("%s: using iomem 0x%x-0x%x\n", device_xname(&sc
->sc_dev
), maddr
, maddr
+ msiz
- 1);
530 printf("%s: interrupting at %s\n", device_xname(&sc
->sc_dev
), intrstr
);
533 CFATTACH_DECL(fea
, sizeof(pdq_softc_t
),
534 pdq_eisa_match
, pdq_eisa_attach
, NULL
, NULL
);