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