if_cs_isapnp.c revision 1.1.2.2 1 1.1.2.2 nathanw /* $NetBSD: if_cs_isapnp.c,v 1.1.2.2 2002/01/08 00:30:36 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*-
4 1.1.2.2 nathanw * Copyright (c)2001 YAMAMOTO Takashi,
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
9 1.1.2.2 nathanw * are met:
10 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.1.2.2 nathanw *
16 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1.2.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1.2.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1.2.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1.2.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1.2.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.2.2 nathanw * SUCH DAMAGE.
27 1.1.2.2 nathanw */
28 1.1.2.2 nathanw
29 1.1.2.2 nathanw #include <sys/cdefs.h>
30 1.1.2.2 nathanw __KERNEL_RCSID(0, "$NetBSD: if_cs_isapnp.c,v 1.1.2.2 2002/01/08 00:30:36 nathanw Exp $");
31 1.1.2.2 nathanw
32 1.1.2.2 nathanw #include <sys/param.h>
33 1.1.2.2 nathanw #include <sys/systm.h>
34 1.1.2.2 nathanw #include <sys/device.h>
35 1.1.2.2 nathanw #include <sys/socket.h>
36 1.1.2.2 nathanw
37 1.1.2.2 nathanw #include "rnd.h"
38 1.1.2.2 nathanw #if NRND > 0
39 1.1.2.2 nathanw #include <sys/rnd.h>
40 1.1.2.2 nathanw #endif
41 1.1.2.2 nathanw
42 1.1.2.2 nathanw #include <net/if.h>
43 1.1.2.2 nathanw #include <net/if_ether.h>
44 1.1.2.2 nathanw #include <net/if_media.h>
45 1.1.2.2 nathanw
46 1.1.2.2 nathanw #include <machine/bus.h>
47 1.1.2.2 nathanw #include <machine/intr.h>
48 1.1.2.2 nathanw
49 1.1.2.2 nathanw #include <dev/isa/isavar.h>
50 1.1.2.2 nathanw
51 1.1.2.2 nathanw #include <dev/ic/cs89x0reg.h>
52 1.1.2.2 nathanw #include <dev/ic/cs89x0var.h>
53 1.1.2.2 nathanw
54 1.1.2.2 nathanw #include <dev/isapnp/isapnpreg.h>
55 1.1.2.2 nathanw #include <dev/isapnp/isapnpvar.h>
56 1.1.2.2 nathanw #include <dev/isapnp/isapnpdevs.h>
57 1.1.2.2 nathanw
58 1.1.2.2 nathanw #define DEVNAME(sc) (sc)->sc_dev.dv_xname
59 1.1.2.2 nathanw
60 1.1.2.2 nathanw int cs_isapnp_match(struct device *, struct cfdata *, void *);
61 1.1.2.2 nathanw void cs_isapnp_attach(struct device *, struct device *, void *);
62 1.1.2.2 nathanw
63 1.1.2.2 nathanw struct cfattach cs_isapnp_ca = {
64 1.1.2.2 nathanw sizeof(struct cs_softc),
65 1.1.2.2 nathanw cs_isapnp_match,
66 1.1.2.2 nathanw cs_isapnp_attach
67 1.1.2.2 nathanw };
68 1.1.2.2 nathanw
69 1.1.2.2 nathanw int
70 1.1.2.2 nathanw cs_isapnp_match(parent, match, aux)
71 1.1.2.2 nathanw struct device *parent;
72 1.1.2.2 nathanw struct cfdata *match;
73 1.1.2.2 nathanw void *aux;
74 1.1.2.2 nathanw {
75 1.1.2.2 nathanw int pri, variant;
76 1.1.2.2 nathanw
77 1.1.2.2 nathanw pri = isapnp_devmatch(aux, &isapnp_cs_devinfo, &variant);
78 1.1.2.2 nathanw if (pri && variant > 0)
79 1.1.2.2 nathanw pri = 0;
80 1.1.2.2 nathanw return pri;
81 1.1.2.2 nathanw }
82 1.1.2.2 nathanw
83 1.1.2.2 nathanw void
84 1.1.2.2 nathanw cs_isapnp_attach(parent, self, aux)
85 1.1.2.2 nathanw struct device *parent, *self;
86 1.1.2.2 nathanw void *aux;
87 1.1.2.2 nathanw {
88 1.1.2.2 nathanw struct cs_softc *sc = (void *)self;
89 1.1.2.2 nathanw struct isapnp_attach_args *ipa = aux;
90 1.1.2.2 nathanw #ifdef notyet
91 1.1.2.2 nathanw struct cs_softc_isa *isc = (void *)sc;
92 1.1.2.2 nathanw int i;
93 1.1.2.2 nathanw #endif
94 1.1.2.2 nathanw
95 1.1.2.2 nathanw printf("\n");
96 1.1.2.2 nathanw
97 1.1.2.2 nathanw if (ipa->ipa_nio != 1 || ipa->ipa_nirq != 1 || ipa->ipa_ndrq) {
98 1.1.2.2 nathanw printf("%s: unexpected resource requirements\n",
99 1.1.2.2 nathanw DEVNAME(sc));
100 1.1.2.2 nathanw return;
101 1.1.2.2 nathanw }
102 1.1.2.2 nathanw
103 1.1.2.2 nathanw if (ipa->ipa_io[0].length != CS8900_IOSIZE) {
104 1.1.2.2 nathanw printf("%s: unexpected io size\n", DEVNAME(sc));
105 1.1.2.2 nathanw return;
106 1.1.2.2 nathanw }
107 1.1.2.2 nathanw
108 1.1.2.2 nathanw if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
109 1.1.2.2 nathanw printf("%s: unable to allocate resources\n", DEVNAME(sc));
110 1.1.2.2 nathanw return;
111 1.1.2.2 nathanw }
112 1.1.2.2 nathanw
113 1.1.2.2 nathanw printf("%s: %s %s\n", DEVNAME(sc), ipa->ipa_devident,
114 1.1.2.2 nathanw ipa->ipa_devclass);
115 1.1.2.2 nathanw
116 1.1.2.2 nathanw #ifdef notyet
117 1.1.2.2 nathanw #ifdef DEBUG
118 1.1.2.2 nathanw printf("%s: nio=%u, nmem=%u, nmem32=%u, ndrq=%u, nirq=%u\n", DEVNAME(sc),
119 1.1.2.2 nathanw ipa->ipa_nio, ipa->ipa_nmem, ipa->ipa_nmem32, ipa->ipa_ndrq, ipa->ipa_nirq);
120 1.1.2.2 nathanw #endif
121 1.1.2.2 nathanw isc->sc_ic = ipa->ipa_ic;
122 1.1.2.2 nathanw isc->sc_drq = ISACF_DRQ_DEFAULT;
123 1.1.2.2 nathanw #endif
124 1.1.2.2 nathanw sc->sc_iot = ipa->ipa_iot;
125 1.1.2.2 nathanw sc->sc_ioh = ipa->ipa_io[0].h;
126 1.1.2.2 nathanw sc->sc_irq = ipa->ipa_irq[0].num;
127 1.1.2.2 nathanw
128 1.1.2.2 nathanw #ifdef notyet
129 1.1.2.2 nathanw for (i = 0; i < ipa->ipa_nmem; i++) {
130 1.1.2.2 nathanw if (ipa->ipa_mem[i].length == CS8900_MEMSIZE) {
131 1.1.2.2 nathanw #if 0
132 1.1.2.2 nathanw u_int16_t id;
133 1.1.2.2 nathanw
134 1.1.2.2 nathanw id = CS_READ_PACKET_PAGE_MEM(ipa->ipa_memt,
135 1.1.2.2 nathanw ipa->ipa_mem[i].h, PKTPG_EISA_NUM);
136 1.1.2.2 nathanw if (id != EISA_NUM_CRYSTAL) {
137 1.1.2.2 nathanw printf("%s: unexpected id(%u)\n",
138 1.1.2.2 nathanw DEVNAME(sc), id);
139 1.1.2.2 nathanw continue;
140 1.1.2.2 nathanw }
141 1.1.2.2 nathanw printf("%s: correct id(%u) from mem=%u\n",
142 1.1.2.2 nathanw DEVNAME(sc), id, (u_int)ipa->ipa_mem[i].h);
143 1.1.2.2 nathanw #endif
144 1.1.2.2 nathanw
145 1.1.2.2 nathanw sc->sc_memt = ipa->ipa_memt;
146 1.1.2.2 nathanw sc->sc_memh = ipa->ipa_mem[i].h;
147 1.1.2.2 nathanw sc->sc_pktpgaddr = ipa->ipa_mem[i].base;
148 1.1.2.2 nathanw sc->sc_cfgflags |= CFGFLG_MEM_MODE;
149 1.1.2.2 nathanw printf("%s: memory mode\n", DEVNAME(sc));
150 1.1.2.2 nathanw break;
151 1.1.2.2 nathanw }
152 1.1.2.2 nathanw }
153 1.1.2.2 nathanw #endif
154 1.1.2.2 nathanw
155 1.1.2.2 nathanw sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
156 1.1.2.2 nathanw ipa->ipa_irq[0].type, IPL_NET, cs_intr, sc);
157 1.1.2.2 nathanw if (sc->sc_ih == 0) {
158 1.1.2.2 nathanw printf("%s: unable to establish interrupt\n",
159 1.1.2.2 nathanw DEVNAME(sc));
160 1.1.2.2 nathanw goto fail;
161 1.1.2.2 nathanw }
162 1.1.2.2 nathanw
163 1.1.2.2 nathanw if (cs_attach(sc, 0, 0, 0, 0)) {
164 1.1.2.2 nathanw printf("%s: unable to attach\n", DEVNAME(sc));
165 1.1.2.2 nathanw goto fail;
166 1.1.2.2 nathanw }
167 1.1.2.2 nathanw
168 1.1.2.2 nathanw return;
169 1.1.2.2 nathanw
170 1.1.2.2 nathanw fail:
171 1.1.2.2 nathanw if (sc->sc_ih)
172 1.1.2.2 nathanw isa_intr_disestablish(ipa->ipa_ic, sc->sc_ih);
173 1.1.2.2 nathanw isapnp_unconfig(ipa->ipa_iot, ipa->ipa_memt, ipa);
174 1.1.2.2 nathanw }
175