kernel: Fix a bunch of drm warnings.
[dragonfly.git] / sys / dev / netif / ex / if_ex_isa.c
1 /*-
2  * Copyright (c) 2000 Matthew N. Dodd
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *      $FreeBSD: src/sys/dev/ex/if_ex_isa.c,v 1.3.2.1 2001/03/05 05:33:20 imp Exp $
27  */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/interrupt.h>
33 #include <sys/socket.h>
34 #include <sys/module.h>
35 #include <sys/bus.h>
36 #include <sys/rman.h>
37 #include <sys/serialize.h>
38 #include <sys/machintr.h>
39
40 #include <machine/clock.h>
41
42 #include <net/if.h>
43 #include <net/if_arp.h>
44 #include <net/if_media.h> 
45 #include <net/ifq_var.h>
46
47 #include <bus/isa/isavar.h>
48 #include <bus/isa/pnpvar.h>
49
50 #include "if_exreg.h"
51 #include "if_exvar.h"
52
53 /* Bus Front End Functions */
54 static int      ex_isa_identify (driver_t *, device_t);
55 static int      ex_isa_probe    (device_t);
56 static int      ex_isa_attach   (device_t);
57
58 /*
59  * We need an identify function to 'probe' the ISA bus.
60  */
61 static device_method_t ex_methods[] = {
62         /* Device interface */
63         DEVMETHOD(device_identify,      ex_isa_identify),
64         DEVMETHOD(device_probe,         ex_isa_probe),
65         DEVMETHOD(device_attach,        ex_isa_attach),
66
67         DEVMETHOD_END
68 };
69
70 static driver_t ex_driver = {
71         "ex",
72         ex_methods,
73         sizeof(struct ex_softc),
74 };
75
76 devclass_t ex_devclass;
77
78 DRIVER_MODULE(if_ex, isa, ex_driver, ex_devclass, NULL, NULL);
79
80 static struct isa_pnp_id ex_ids[] = {
81         { 0x3110d425,   NULL }, /* INT1031 */
82         { 0x3010d425,   NULL }, /* INT1030 */
83         { 0,            NULL },
84 };
85
86 /*
87  * Non-destructive identify.
88  */
89 static int
90 ex_isa_identify (driver_t *driver, device_t parent)
91 {
92         device_t        child;
93         u_int32_t       ioport;
94         u_char          enaddr[6];
95         u_int           irq;
96         int             tmp;
97         int             count;
98         const char *    desc;
99
100         /*
101          * Rescanning ISA I/O ports is not supported.
102          */
103         if (device_get_state(parent) == DS_ATTACHED)
104                 return (0);
105
106         if (bootverbose)
107                 kprintf("ex_isa_identify()\n");
108
109         count = 0;
110         for (ioport = 0x200; ioport < 0x3a0; ioport += 0x10) {
111
112                 /* No board found at address */
113                 if (!look_for_card(ioport)) {
114                         continue;
115                 }
116
117                 if (bootverbose)
118                         kprintf("ex: Found card at 0x%03x!\n", ioport);
119
120                 /* Board in PnP mode */
121                 if (eeprom_read(ioport, EE_W0) & EE_W0_PNP) {
122                         /* Reset the card. */
123                         outb(ioport + CMD_REG, Reset_CMD);
124                         DELAY(500);
125                         if (bootverbose)
126                                 kprintf("ex: card at 0x%03x in PnP mode!\n", ioport);
127                         continue;
128                 }
129
130                 bzero(enaddr, sizeof(enaddr));
131
132                 /* Reset the card. */
133                 outb(ioport + CMD_REG, Reset_CMD);
134                 DELAY(400);
135
136                 ex_get_address(ioport, enaddr);
137                 tmp = eeprom_read(ioport, EE_W1) & EE_W1_INT_SEL;
138
139                 /* work out which set of irq <-> internal tables to use */
140                 if (ex_card_type(enaddr) == CARD_TYPE_EX_10_PLUS) {
141                         irq  = plus_ee2irqmap[tmp];
142                         desc = "Intel Pro/10+";
143                 } else {
144                         irq = ee2irqmap[tmp];
145                         desc = "Intel Pro/10";
146                 }
147
148                 child = BUS_ADD_CHILD(parent, parent,
149                                       ISA_ORDER_SPECULATIVE, "ex", -1);
150                 device_set_desc_copy(child, desc);
151                 device_set_driver(child, driver);
152                 bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1,
153                     machintr_legacy_intr_cpuid(irq));
154                 bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, EX_IOSIZE, -1);
155                 ++count;
156
157                 if (bootverbose)
158                         kprintf("ex: Adding board at 0x%03x, irq %d\n", ioport, irq);
159         }
160         return (count ? 0 : ENXIO);
161 }
162
163 static int
164 ex_isa_probe(device_t dev)
165 {
166         u_int           iobase;
167         u_int           irq;
168         u_char *        ee2irq;
169         u_char          enaddr[6];
170         int             tmp;
171         int             error;
172
173         /* Check isapnp ids */
174         error = ISA_PNP_PROBE(device_get_parent(dev), dev, ex_ids);
175
176         /* If the card had a PnP ID that didn't match any we know about */
177         if (error == ENXIO) {
178                 return(error);
179         }
180
181         /* If we had some other problem. */
182         if (!(error == 0 || error == ENOENT)) {
183                 return(error);
184         }
185
186         iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0);
187         if (!iobase) {
188                 kprintf("ex: no iobase?\n");
189                 return(ENXIO);
190         }
191
192         if (!look_for_card(iobase)) {
193                 kprintf("ex: no card found at 0x%03x\n", iobase);
194                 return(ENXIO);
195         }
196
197         if (bootverbose)
198                 kprintf("ex: ex_isa_probe() found card at 0x%03x\n", iobase);
199
200         /*
201          * Reset the card.
202          */
203         outb(iobase + CMD_REG, Reset_CMD);
204         DELAY(800);
205
206         ex_get_address(iobase, enaddr);
207
208         /* work out which set of irq <-> internal tables to use */
209         if (ex_card_type(enaddr) == CARD_TYPE_EX_10_PLUS)
210                 ee2irq = plus_ee2irqmap;
211         else
212                 ee2irq = ee2irqmap;
213
214         tmp = eeprom_read(iobase, EE_W1) & EE_W1_INT_SEL;
215         irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0);
216
217         if (irq > 0) {
218                 /* This will happen if board is in PnP mode. */
219                 if (ee2irq[tmp] != irq) {
220                         kprintf("ex: WARNING: board's EEPROM is configured"
221                                 " for IRQ %d, using %d\n",
222                                 ee2irq[tmp], irq);
223                 }
224         } else {
225                 irq = ee2irq[tmp];
226                 bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1,
227                     machintr_legacy_intr_cpuid(irq));
228         }
229
230         if (irq == 0) {
231                 kprintf("ex: invalid IRQ.\n");
232                 return(ENXIO);
233         }
234
235         return(0);
236 }
237
238 static int
239 ex_isa_attach(device_t dev)
240 {
241         struct ex_softc *       sc = device_get_softc(dev);
242         struct ifnet *          ifp = &sc->arpcom.ac_if;
243         int                     error = 0;
244         u_int16_t               temp;
245
246         sc->dev = dev;
247         sc->ioport_rid = 0;
248         sc->irq_rid = 0;
249
250         if ((error = ex_alloc_resources(dev)) != 0) {
251                 device_printf(dev, "ex_alloc_resources() failed!\n");
252                 goto bad;
253         }
254
255         /*
256          * Fill in several fields of the softc structure:
257          *      - I/O base address.
258          *      - Hardware Ethernet address.
259          *      - IRQ number (if not supplied in config file, read it from EEPROM).
260          *      - Connector type.
261          */
262         sc->iobase = rman_get_start(sc->ioport);
263         sc->irq_no = rman_get_start(sc->irq);
264
265         ex_get_address(sc->iobase, sc->arpcom.ac_enaddr);
266
267         temp = eeprom_read(sc->iobase, EE_W0);
268         device_printf(sc->dev, "%s config, %s bus, ",
269                 (temp & EE_W0_PNP) ? "PnP" : "Manual",
270                 (temp & EE_W0_BUS16) ? "16-bit" : "8-bit");
271
272         temp = eeprom_read(sc->iobase, EE_W6);
273         kprintf("board id 0x%03x, stepping 0x%01x\n",
274                 (temp & EE_W6_BOARD_MASK) >> EE_W6_BOARD_SHIFT,
275                 temp & EE_W6_STEP_MASK);
276
277         if ((error = ex_attach(dev)) != 0) {
278                 device_printf(dev, "ex_attach() failed!\n");
279                 goto bad;
280         }
281
282         ifq_set_cpuid(&ifp->if_snd, rman_get_cpuid(sc->irq));
283
284         error = bus_setup_intr(dev, sc->irq, INTR_MPSAFE,
285                                 ex_intr, (void *)sc, &sc->ih, 
286                                 ifp->if_serializer);
287         if (error) {
288                 device_printf(dev, "bus_setup_intr() failed!\n");
289                 goto bad;
290         }
291
292         return(0);
293 bad:
294         ex_release_resources(dev);
295         return (error);
296 }