• Home
  • History
  • Annotate
  • only in this directory
if_fea.c revision 29381
1279377Simp/*-
2279377Simp * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
3279377Simp * All rights reserved.
4279377Simp *
5279377Simp * Redistribution and use in source and binary forms, with or without
6279377Simp * modification, are permitted provided that the following conditions
7279377Simp * are met:
8279377Simp * 1. Redistributions of source code must retain the above copyright
9279377Simp *    notice, this list of conditions and the following disclaimer.
10279377Simp * 2. The name of the author may not be used to endorse or promote products
11279377Simp *    derived from this software withough specific prior written permission
12279377Simp *
13279377Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14279377Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15279377Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16279377Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17279377Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18279377Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19279377Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20279377Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21279377Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22279377Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23279377Simp *
24279377Simp * $Id: if_fea.c,v 1.5 1997/09/13 15:28:30 peter Exp $
25279377Simp */
26279377Simp
27279377Simp/*
28279377Simp * DEC PDQ FDDI Controller
29279377Simp *
30279377Simp *	This module support the DEFEA EISA FDDI Controller.
31279377Simp */
32279377Simp
33279377Simp
34279377Simp#include <sys/param.h>
35279377Simp#include <sys/kernel.h>
36279377Simp#include <sys/socket.h>
37279377Simp#if defined(__bsdi__) || defined(__NetBSD__)
38279377Simp#include <sys/device.h>
39279377Simp#endif
40279377Simp
41279377Simp#include <net/if.h>
42279377Simp
43279377Simp#ifdef INET
44279377Simp#include <netinet/in.h>
45279377Simp#include <netinet/if_ether.h>
46#endif
47
48#if defined(__FreeBSD__)
49#include <i386/eisa/eisaconf.h>
50#include <dev/pdq/pdqvar.h>
51#include <dev/pdq/pdqreg.h>
52#elif defined(__bsdi__)
53#include <i386/isa/isa.h>
54#include <i386/isa/icu.h>
55#include <i386/isa/dma.h>
56#include <i386/isa/isavar.h>
57#include <i386/eisa/eisa.h>
58#include <dev/pdq/pdqvar.h>
59#include <dev/pdq/pdqreg.h>
60#elif defined(__NetBSD__)
61#include <machine/cpu.h>
62#include <machine/bus.h>
63
64#include <dev/ic/pdqvar.h>
65#include <dev/ic/pdqreg.h>
66
67#include <dev/eisa/eisareg.h>
68#include <dev/eisa/eisavar.h>
69#include <dev/eisa/eisadevs.h>
70#endif
71
72/*
73 *
74 */
75
76#define	DEFEA_IRQS		0x0000FBA9U
77
78#if defined(__FreeBSD__)
79static pdq_softc_t *pdqs_eisa[16];
80#define	PDQ_EISA_UNIT_TO_SOFTC(unit)	(pdqs_eisa[unit])
81#define	DEFEA_INTRENABLE		0x8	/* level interrupt */
82#define	pdq_eisa_ifwatchdog		NULL
83#define	DEFEA_DECODE_IRQ(n)		((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
84
85#elif defined(__bsdi__)
86extern struct cfdriver feacd;
87#define	PDQ_EISA_UNIT_TO_SOFTC(unit)	((pdq_softc_t *)feacd.cd_devs[unit])
88#define	DEFEA_INTRENABLE		0x28	/* edge interrupt */
89static const int pdq_eisa_irqs[4] = { IRQ9, IRQ10, IRQ11, IRQ15 };
90#define	DEFEA_DECODE_IRQ(n)		(pdq_eisa_irqs[(n)])
91
92#elif defined(__NetBSD__)
93#define	DEFEA_INTRENABLE		0x8	/* level interrupt */
94#define	pdq_eisa_ifwatchdog		NULL
95#define	DEFEA_DECODE_IRQ(n)		((DEFEA_IRQS >> ((n) << 2)) & 0x0f)
96
97#else
98#error unknown system
99#endif
100
101#ifndef pdq_eisa_ifwatchdog
102static ifnet_ret_t
103pdq_eisa_ifwatchdog(
104    int unit)
105{
106    pdq_ifwatchdog(&PDQ_EISA_UNIT_TO_SOFTC(unit)->sc_if);
107}
108#endif
109
110static void
111pdq_eisa_subprobe(
112    pdq_bus_t bc,
113    pdq_bus_ioport_t iobase,
114    pdq_uint32_t *maddr,
115    pdq_uint32_t *msize,
116    pdq_uint32_t *irq)
117{
118    if (irq != NULL)
119	*irq = DEFEA_DECODE_IRQ(PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_IO_CONFIG_STAT_0) & 3);
120    *maddr = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_0) << 8)
121	| (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_CMP_1) << 16);
122    *msize = (PDQ_OS_IORD_8(bc, iobase, PDQ_EISA_MEM_ADD_MASK_0) + 4) << 8;
123}
124
125static void
126pdq_eisa_devinit(
127    pdq_softc_t *sc)
128{
129    pdq_uint8_t data;
130
131    /*
132     * Do the standard initialization for the DEFEA registers.
133     */
134    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_FUNCTION_CTRL, 0x23);
135    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_1_1, (sc->sc_iobase >> 8) & 0xF0);
136    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CMP_0_1, (sc->sc_iobase >> 8) & 0xF0);
137    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_SLOT_CTRL, 0x01);
138    data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF);
139#if defined(PDQ_IOMAPPED)
140    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data & ~1);
141#else
142    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_BURST_HOLDOFF, data | 1);
143#endif
144    data = PDQ_OS_IORD_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0);
145    PDQ_OS_IOWR_8(sc->sc_bc, sc->sc_iobase, PDQ_EISA_IO_CONFIG_STAT_0, data | DEFEA_INTRENABLE);
146}
147
148#if defined(__FreeBSD__)
149static void pdq_eisa_shutdown(int howto, void *sc);
150static int pdq_eisa_probe(void);
151static int pdq_eisa_attach(struct eisa_device *ed);
152
153static unsigned long pdq_eisa_unit;
154
155static struct eisa_driver pdq_eisa_driver = {
156    "fea", pdq_eisa_probe, pdq_eisa_attach, NULL, &pdq_eisa_unit
157};
158
159DATA_SET(eisadriver_set, pdq_eisa_driver);
160
161
162static const char *
163pdq_eisa_match(
164    eisa_id_t type)
165{
166    if ((type >> 8) == 0x10a330)
167	return ("DEC DEFEA EISA FDDI Controller");
168    return NULL;
169}
170
171static int
172pdq_eisa_probe(
173    void)
174{
175    struct eisa_device *ed = NULL;
176    int count;
177
178    for (count = 0; (ed = eisa_match_dev(ed, pdq_eisa_match)) != NULL; count++) {
179	pdq_bus_ioport_t iobase = ed->ioconf.slot * EISA_SLOT_SIZE;
180	pdq_uint32_t irq, maddr, msize;
181
182	eisa_add_iospace(ed, iobase, 0x200, RESVADDR_NONE);
183	pdq_eisa_subprobe(PDQ_BUS_EISA, iobase, &maddr, &msize, &irq);
184	eisa_add_mspace(ed, maddr, msize, RESVADDR_NONE);
185	eisa_add_intr(ed, irq);
186	eisa_registerdev(ed, &pdq_eisa_driver);
187    }
188    return count;
189}
190
191static void
192pdq_eisa_interrupt(
193    void *arg)
194{
195    pdq_softc_t * const sc = (pdq_softc_t *) arg;
196    (void) pdq_interrupt(sc->sc_pdq);
197}
198
199static int
200pdq_eisa_attach(
201    struct eisa_device *ed)
202{
203    pdq_softc_t *sc;
204    resvaddr_t *iospace;
205    resvaddr_t *mspace;
206    int irq = ffs(ed->ioconf.irq) - 1;
207
208    sc = (pdq_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_WAITOK);
209    if (sc == NULL) {
210	printf("fea%d: malloc failed!\n", sc->sc_if.if_unit);
211	return -1;
212    }
213    pdqs_eisa[ed->unit] = sc;
214
215    bzero(sc, sizeof(pdq_softc_t));	/* Zero out the softc*/
216    sc->sc_if.if_name = "fea";
217    sc->sc_if.if_unit = ed->unit;
218
219    if ((iospace = ed->ioconf.ioaddrs.lh_first) == NULL) {
220	printf("fea%d: no iospace??\n", sc->sc_if.if_unit);
221	return -1;
222    }
223    if ((mspace = ed->ioconf.maddrs.lh_first) == NULL) {
224	printf("fea%d: no memory space??\n", sc->sc_if.if_unit);
225	return -1;
226    }
227
228    sc->sc_iobase = (pdq_bus_ioport_t) iospace->addr;
229    sc->sc_membase = (pdq_bus_memaddr_t) pmap_mapdev(mspace->addr, mspace->size);
230    if (sc->sc_membase == NULL) {
231	printf("fea%d: failed to map memory 0x%x-0x%x!\n",
232	       sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1);
233	return -1;
234    }
235
236    eisa_reg_start(ed);
237    if (eisa_reg_iospace(ed, iospace)) {
238	printf("fea%d: failed to register iospace 0x%x-0x%x!\n",
239	       sc->sc_if.if_unit, iospace->addr, iospace->addr + iospace->size - 1);
240	return -1;
241    }
242    if (eisa_reg_mspace(ed, mspace)) {
243	printf("fea%d: failed to register memory 0x%x-0x%x!\n",
244	       sc->sc_if.if_unit, mspace->addr, mspace->addr + mspace->size - 1);
245	return -1;
246    }
247
248    if (eisa_reg_intr(ed, irq, pdq_eisa_interrupt, sc, &net_imask, 1)) {
249	printf("fea%d: interrupt registration failed\n", sc->sc_if.if_unit);
250	return -1;
251    }
252
253    eisa_reg_end(ed);
254
255    pdq_eisa_devinit(sc);
256    sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA, sc->sc_membase,
257				sc->sc_if.if_name, sc->sc_if.if_unit,
258				(void *) sc, PDQ_DEFEA);
259    if (sc->sc_pdq == NULL) {
260	printf("fea%d: initialization failed\n", sc->sc_if.if_unit);
261	return -1;
262    }
263
264    if (eisa_enable_intr(ed, irq)) {
265	printf("fea%d: failed to enable interrupt\n", sc->sc_if.if_unit);
266	return -1;
267    }
268
269    bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
270    pdq_ifattach(sc, pdq_eisa_ifwatchdog);
271    at_shutdown(pdq_eisa_shutdown, (void *) sc, SHUTDOWN_POST_SYNC);
272
273    return 0;
274}
275
276static void
277pdq_eisa_shutdown(
278    int howto,
279    void *sc)
280{
281    pdq_hwreset(((pdq_softc_t *)sc)->sc_pdq);
282}
283#endif /* __FreeBSD__ */
284
285#if defined(__bsdi__)
286static int
287pdq_eisa_probe(
288    struct device *parent,
289    struct cfdata *cf,
290    void *aux)
291{
292    struct isa_attach_args *ia = (struct isa_attach_args *) aux;
293    int slot;
294    pdq_uint32_t irq, maddr, msize;
295
296    if (isa_bustype != BUS_EISA)
297	return 0;
298
299    if ((slot = eisa_match(cf, ia)) == 0)
300	return 0;
301    ia->ia_iobase = slot << 12;
302    ia->ia_iosize = EISA_NPORT;
303    eisa_slotalloc(slot);
304
305    pdq_eisa_subprobe(PDQ_BUS_EISA, ia->ia_iobase, &maddr, &msize, &irq);
306    if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
307	printf("fea%d: error: desired IRQ of %d does not match device's actual IRQ (%d),\n",
308	       cf->cf_unit,
309	       ffs(ia->ia_irq) - 1, ffs(irq) - 1);
310	return 0;
311    }
312    if (ia->ia_irq == IRQUNK) {
313	if ((ia->ia_irq = isa_irqalloc(irq)) == 0) {
314	    if ((ia->ia_irq = isa_irqalloc(IRQ9|IRQ10|IRQ11|IRQ15)) == 0) {
315		printf("fea%d: error: IRQ %d is already in use\n", cf->cf_unit,
316		       ffs(irq) - 1);
317		return 0;
318	    }
319	    irq = PDQ_OS_IORD_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0) & ~3;
320	    switch (ia->ia_irq) {
321		case IRQ9:  irq |= 0;
322		case IRQ10: irq |= 1;
323		case IRQ11: irq |= 2;
324		case IRQ15: irq |= 3;
325	    }
326	    PDQ_OS_IOWR_8(PDQ_BUS_EISA, ia->ia_iobase, PDQ_EISA_IO_CONFIG_STAT_0, irq);
327	}
328    }
329    if (maddr == 0) {
330	printf("fea%d: error: memory not enabled! ECU reconfiguration required\n",
331	       cf->cf_unit);
332	return 0;
333    }
334
335    /* EISA bus masters don't use host DMA channels */
336    ia->ia_drq = DRQNONE;
337
338    ia->ia_maddr = (caddr_t) maddr;
339    ia->ia_msize = msize;
340    return 1;
341}
342
343static void
344pdq_eisa_attach(
345    struct device *parent,
346    struct device *self,
347    void *aux)
348{
349    pdq_softc_t *sc = (pdq_softc_t *) self;
350    register struct isa_attach_args *ia = (struct isa_attach_args *) aux;
351    register struct ifnet *ifp = &sc->sc_if;
352
353    sc->sc_if.if_unit = sc->sc_dev.dv_unit;
354    sc->sc_if.if_name = "fea";
355    sc->sc_if.if_flags = 0;
356
357    sc->sc_iobase = ia->ia_iobase;
358
359    pdq_eisa_devinit(sc);
360    sc->sc_pdq = pdq_initialize(PDQ_BUS_EISA,
361				(pdq_bus_memaddr_t) ISA_HOLE_VADDR(ia->ia_maddr),
362				sc->sc_if.if_name, sc->sc_if.if_unit,
363				(void *) sc, PDQ_DEFEA);
364    if (sc->sc_pdq == NULL) {
365	printf("fea%d: initialization failed\n", sc->sc_if.if_unit);
366	return;
367    }
368
369    bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
370
371    pdq_ifattach(sc, pdq_eisa_ifwatchdog);
372
373    isa_establish(&sc->sc_id, &sc->sc_dev);
374
375    sc->sc_ih.ih_fun = pdq_interrupt;
376    sc->sc_ih.ih_arg = (void *) sc->sc_pdq;
377    intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET);
378
379    sc->sc_ats.func = (void (*)(void *)) pdq_hwreset;
380    sc->sc_ats.arg = (void *) sc->sc_pdq;
381    atshutdown(&sc->sc_ats, ATSH_ADD);
382}
383
384static char *pdq_eisa_ids[] = {
385    "DEC3001",	/* 0x0130A310 */
386    "DEC3002",	/* 0x0230A310 */
387    "DEC3003",	/* 0x0330A310 */
388    "DEC3004",	/* 0x0430A310 */
389};
390
391struct cfdriver feacd = {
392    0, "fea", pdq_eisa_probe, pdq_eisa_attach, DV_IFNET, sizeof(pdq_softc_t),
393    pdq_eisa_ids
394};
395#endif /* __bsdi__ */
396
397#if defined(__NetBSD__)
398static int
399pdq_eisa_match(
400    struct device *parent,
401    void *match,
402    void *aux)
403{
404    const struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux;
405
406    if (strncmp(ea->ea_idstring, "DEC300", 6) == 0)
407	return 1;
408
409    return 0;
410}
411
412static void
413pdq_eisa_attach(
414    struct device *parent,
415    struct device *self,
416    void *aux)
417{
418    pdq_softc_t * const sc = (pdq_softc_t *) self;
419    struct eisa_attach_args * const ea = (struct eisa_attach_args *) aux;
420    pdq_uint32_t irq, maddr, msize;
421    eisa_intr_handle_t ih;
422    const char *intrstr;
423
424    sc->sc_bc = ea->ea_bc;
425    bcopy(sc->sc_dev.dv_xname, sc->sc_if.if_xname, IFNAMSIZ);
426    sc->sc_if.if_flags = 0;
427    sc->sc_if.if_softc = sc;
428
429    if (bus_io_map(sc->sc_bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &sc->sc_iobase)) {
430	printf("\n%s: failed to map I/O!\n", sc->sc_dev.dv_xname);
431	return;
432    }
433
434    pdq_eisa_subprobe(sc->sc_bc, sc->sc_iobase, &maddr, &msize, &irq);
435
436#if !defined(PDQ_IOMAPPED)
437    if (maddr == 0 || msize == 0) {
438	printf("\n%s: error: memory not enabled! ECU reconfiguration required\n",
439	       sc->sc_dev.dv_xname);
440	return;
441    }
442
443    if (bus_mem_map(sc->sc_bc, maddr, msize, 0, &sc->sc_membase)) {
444	bus_io_unmap(sc->sc_bc, sc->sc_iobase, EISA_SLOT_SIZE);
445	printf("\n%s: failed to map memory (0x%x-0x%x)!\n",
446	       sc->sc_dev.dv_xname, maddr, maddr + msize - 1);
447	return;
448    }
449#endif
450    pdq_eisa_devinit(sc);
451    sc->sc_pdq = pdq_initialize(sc->sc_bc, sc->sc_membase,
452				sc->sc_if.if_xname, 0,
453				(void *) sc, PDQ_DEFEA);
454    if (sc->sc_pdq == NULL) {
455	printf("%s: initialization failed\n", sc->sc_dev.dv_xname);
456	return;
457    }
458
459    bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
460
461    pdq_ifattach(sc, pdq_eisa_ifwatchdog);
462
463    if (eisa_intr_map(ea->ea_ec, irq, &ih)) {
464	printf("%s: couldn't map interrupt (%d)\n", sc->sc_dev.dv_xname, irq);
465	return;
466    }
467    intrstr = eisa_intr_string(ea->ea_ec, ih);
468    sc->sc_ih = eisa_intr_establish(ea->ea_ec, ih, IST_LEVEL, IPL_NET,
469				    (int (*)(void *)) pdq_interrupt, sc->sc_pdq);
470    if (sc->sc_ih == NULL) {
471	printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
472	if (intrstr != NULL)
473	    printf(" at %s", intrstr);
474	printf("\n");
475	return;
476    }
477    sc->sc_ats = shutdownhook_establish((void (*)(void *)) pdq_hwreset, sc->sc_pdq);
478    if (sc->sc_ats == NULL)
479	printf("%s: warning: couldn't establish shutdown hook\n", self->dv_xname);
480#if !defined(PDQ_IOMAPPED)
481    printf("%s: using iomem 0x%x-0x%x\n", sc->sc_dev.dv_xname, maddr, maddr + msize - 1);
482#endif
483    if (intrstr != NULL)
484	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
485}
486
487struct cfattach fea_ca = {
488    sizeof(pdq_softc_t), pdq_eisa_match, pdq_eisa_attach
489};
490
491struct cfdriver fea_cd = {
492    0, "fea", DV_IFNET
493};
494#endif
495