Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / netif / ar / if_ar_isa.c
1 /*
2  * Copyright (c) 1995 - 2001 John Hay.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the author nor the names of any co-contributors
13  *    may be used to endorse or promote products derived from this software
14  *    without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY John Hay ``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 John Hay 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  * $FreeBSD: src/sys/dev/ar/if_ar_isa.c,v 1.49.2.1 2002/06/17 15:10:57 jhay Exp $
29  * $DragonFly: src/sys/dev/netif/ar/if_ar_isa.c,v 1.2 2003/06/17 04:28:22 dillon Exp $
30  */
31
32 /*
33  * Programming assumptions and other issues.
34  *
35  * The descriptors of a DMA channel will fit in a 16K memory window.
36  *
37  * The buffers of a transmit DMA channel will fit in a 16K memory window.
38  *
39  * Only the ISA bus cards with X.21 and V.35 is tested.
40  *
41  * When interface is going up, handshaking is set and it is only cleared
42  * when the interface is down'ed.
43  *
44  * There should be a way to set/reset Raw HDLC/PPP, Loopback, DCE/DTE,
45  * internal/external clock, etc.....
46  *
47  */
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/module.h>
53 #include <sys/bus.h>
54 #include <machine/bus.h>
55 #include <machine/resource.h>
56 #include <machine/bus_pio.h>
57 #include <machine/bus_memio.h>
58 #include <sys/rman.h>
59
60 #include <isa/isavar.h>
61 #include "isa_if.h"
62
63 #include <dev/ic/hd64570.h>
64 #include <dev/ar/if_arregs.h>
65
66 #ifdef TRACE
67 #define TRC(x)               x
68 #else
69 #define TRC(x)
70 #endif
71
72 #define TRCL(x)              x
73
74 static int ar_isa_probe (device_t);
75 static int ar_isa_attach (device_t);
76
77 static struct isa_pnp_id ar_ids[] = {
78         {0,             NULL}
79 };
80
81 static device_method_t ar_methods[] = {
82         DEVMETHOD(device_probe,         ar_isa_probe),
83         DEVMETHOD(device_attach,        ar_isa_attach),
84         DEVMETHOD(device_detach,        ar_detach),
85         { 0, 0 }
86 };
87
88 static driver_t ar_isa_driver = {
89         "ar",
90         ar_methods,
91         sizeof (struct ar_hardc)
92 };
93
94 devclass_t ar_devclass;
95
96 DRIVER_MODULE(if_ar, isa, ar_isa_driver, ar_devclass, 0, 0);
97
98 /*
99  * Probe to see if it is there.
100  * Get its information and fill it in.
101  */
102 static int
103 ar_isa_probe(device_t device)
104 {
105         int error;
106         u_long membase, memsize, port_start, port_count;
107
108         error = ISA_PNP_PROBE(device_get_parent(device), device, ar_ids);
109         if(error == ENXIO || error == 0)
110                 return (error);
111
112         if((error = ar_allocate_ioport(device, 0, ARC_IO_SIZ))) {
113                 return (ENXIO);
114         }
115
116         /*
117          * Now see if the card is realy there.
118          *
119          * XXX For now I just check the undocumented ports
120          * for "570". We will probably have to do more checking.
121          */
122         error = bus_get_resource(device, SYS_RES_IOPORT, 0, &port_start,
123             &port_count);
124
125         if((inb(port_start + AR_ID_5) != '5') ||
126            (inb(port_start + AR_ID_7) != '7') ||
127            (inb(port_start + AR_ID_0) != '0')) {
128                 ar_deallocate_resources(device);
129                 return (ENXIO);
130         }
131         membase = bus_get_resource_start(device, SYS_RES_MEMORY, 0);
132         memsize = inb(port_start + AR_REV);
133         memsize = 1 << ((memsize & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
134         memsize *= ARC_WIN_SIZ;
135         error = bus_set_resource(device, SYS_RES_MEMORY, 0, membase, memsize);
136         ar_deallocate_resources(device);
137
138         return (error);
139 }
140
141 /*
142  * Malloc memory for the softc structures.
143  * Reset the card to put it in a known state.
144  * Register the ports on the adapter.
145  * Fill in the info for each port.
146  * Attach each port to sppp and bpf.
147  */
148 static int
149 ar_isa_attach(device_t device)
150 {
151         u_int tmp;
152         u_long irq, junk;
153         struct ar_hardc *hc;
154
155         hc = (struct ar_hardc *)device_get_softc(device);
156         if(ar_allocate_ioport(device, 0, ARC_IO_SIZ))
157                 return (ENXIO);
158         hc->bt = rman_get_bustag(hc->res_ioport);
159         hc->bh = rman_get_bushandle(hc->res_ioport);
160
161         hc->iobase = rman_get_start(hc->res_ioport);
162
163         tmp = inb(hc->iobase + AR_BMI);
164         hc->bustype = tmp & AR_BUS_MSK;
165         hc->memsize = (tmp & AR_MEM_MSK) >> AR_MEM_SHFT;
166         hc->memsize = 1 << hc->memsize;
167         hc->memsize <<= 16;
168         hc->interface[0] = (tmp & AR_IFACE_MSK);
169         hc->interface[1] = hc->interface[0];
170         hc->interface[2] = hc->interface[0];
171         hc->interface[3] = hc->interface[0];
172         tmp = inb(hc->iobase + AR_REV);
173         hc->revision = tmp & AR_REV_MSK;
174         hc->winsize = 1 << ((tmp & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
175         hc->winsize *= ARC_WIN_SIZ;
176         hc->winmsk = hc->winsize - 1;
177         hc->numports = inb(hc->iobase + AR_PNUM);
178         hc->handshake = inb(hc->iobase + AR_HNDSH);
179
180         if(ar_allocate_memory(device, 0, hc->winsize))
181                 return (ENXIO);
182
183         hc->mem_start = rman_get_virtual(hc->res_memory);
184         hc->mem_end = hc->mem_start + hc->winsize;
185         hc->cunit = device_get_unit(device);
186
187         switch(hc->interface[0]) {
188         case AR_IFACE_EIA_232:
189                 printf("ar%d: The EIA 232 interface is not supported.\n",
190                         hc->cunit);
191                 ar_deallocate_resources(device);
192                 return (ENXIO);
193         case AR_IFACE_V_35:
194                 break;
195         case AR_IFACE_EIA_530:
196                 printf("ar%d: WARNING: The EIA 530 interface is untested.\n",
197                         hc->cunit);
198                 break;
199         case AR_IFACE_X_21:
200                 break;
201         case AR_IFACE_COMBO:
202                 printf("ar%d: WARNING: The COMBO interface is untested.\n",
203                         hc->cunit);
204                 break;
205         }
206
207         /*
208          * Do a little sanity check.
209          */
210         if((hc->numports > NPORT) || (hc->memsize > (512*1024))) {
211                 ar_deallocate_resources(device);
212                 return (ENXIO);
213         }
214
215         if(ar_allocate_irq(device, 0, 1))
216                 return (ENXIO);
217
218         if(bus_get_resource(device, SYS_RES_IRQ, 0, &irq, &junk)) {
219                 ar_deallocate_resources(device);
220                 return (ENXIO);
221         }
222         hc->isa_irq = irq;
223
224         if(ar_attach(device)) {
225                 ar_deallocate_resources(device);
226                 return (ENXIO);
227         }
228
229         return (0);
230 }
231
232
233
234
235
236
237
238 /*
239  ********************************* END ************************************
240  */