uha_isa.c revision 1.1 1 1.1 mycroft #include <sys/types.h>
2 1.1 mycroft #include <sys/param.h>
3 1.1 mycroft #include <sys/device.h>
4 1.1 mycroft #include <sys/kernel.h>
5 1.1 mycroft #include <sys/proc.h>
6 1.1 mycroft #include <sys/user.h>
7 1.1 mycroft
8 1.1 mycroft #include <machine/bus.h>
9 1.1 mycroft #include <machine/intr.h>
10 1.1 mycroft
11 1.1 mycroft #include <scsi/scsi_all.h>
12 1.1 mycroft #include <scsi/scsiconf.h>
13 1.1 mycroft
14 1.1 mycroft #include <dev/isa/isavar.h>
15 1.1 mycroft #include <dev/isa/isadmavar.h>
16 1.1 mycroft
17 1.1 mycroft #include <dev/ic/uhareg.h>
18 1.1 mycroft #include <dev/ic/uhavar.h>
19 1.1 mycroft
20 1.1 mycroft #define UHA_ISA_IOSIZE 16
21 1.1 mycroft
22 1.1 mycroft int uha_isa_probe __P((struct device *, void *, void *));
23 1.1 mycroft void uha_isa_attach __P((struct device *, struct device *, void *));
24 1.1 mycroft
25 1.1 mycroft struct cfattach uha_isa_ca = {
26 1.1 mycroft sizeof(struct uha_softc), uha_isa_probe, uha_isa_attach
27 1.1 mycroft };
28 1.1 mycroft
29 1.1 mycroft #define KVTOPHYS(x) vtophys(x)
30 1.1 mycroft
31 1.1 mycroft int u14_find __P((bus_chipset_tag_t, bus_io_handle_t, struct uha_softc *));
32 1.1 mycroft void u14_start_mbox __P((struct uha_softc *, struct uha_mscp *));
33 1.1 mycroft int u14_poll __P((struct uha_softc *, struct scsi_xfer *, int));
34 1.1 mycroft int u14_intr __P((void *));
35 1.1 mycroft void u14_init __P((struct uha_softc *));
36 1.1 mycroft
37 1.1 mycroft /*
38 1.1 mycroft * Check the slots looking for a board we recognise
39 1.1 mycroft * If we find one, note it's address (slot) and call
40 1.1 mycroft * the actual probe routine to check it out.
41 1.1 mycroft */
42 1.1 mycroft int
43 1.1 mycroft uha_isa_probe(parent, match, aux)
44 1.1 mycroft struct device *parent;
45 1.1 mycroft void *match, *aux;
46 1.1 mycroft {
47 1.1 mycroft struct isa_attach_args *ia = aux;
48 1.1 mycroft struct uha_softc sc;
49 1.1 mycroft bus_chipset_tag_t bc = ia->ia_bc;
50 1.1 mycroft bus_io_handle_t ioh;
51 1.1 mycroft isa_chipset_tag_t ic = ia->ia_ic;
52 1.1 mycroft int rv;
53 1.1 mycroft
54 1.1 mycroft if (bus_io_map(bc, ia->ia_iobase, UHA_ISA_IOSIZE, &ioh))
55 1.1 mycroft return (0);
56 1.1 mycroft
57 1.1 mycroft rv = u14_find(bc, ioh, &sc);
58 1.1 mycroft
59 1.1 mycroft bus_io_unmap(bc, ioh, UHA_ISA_IOSIZE);
60 1.1 mycroft
61 1.1 mycroft if (rv) {
62 1.1 mycroft if (ia->ia_irq != -1 && ia->ia_irq != sc.sc_irq)
63 1.1 mycroft return (0);
64 1.1 mycroft if (ia->ia_drq != -1 && ia->ia_drq != sc.sc_drq)
65 1.1 mycroft return (0);
66 1.1 mycroft ia->ia_irq = sc.sc_irq;
67 1.1 mycroft ia->ia_drq = sc.sc_drq;
68 1.1 mycroft ia->ia_msize = 0;
69 1.1 mycroft ia->ia_iosize = UHA_ISA_IOSIZE;
70 1.1 mycroft }
71 1.1 mycroft return (rv);
72 1.1 mycroft }
73 1.1 mycroft
74 1.1 mycroft /*
75 1.1 mycroft * Attach all the sub-devices we can find
76 1.1 mycroft */
77 1.1 mycroft void
78 1.1 mycroft uha_isa_attach(parent, self, aux)
79 1.1 mycroft struct device *parent, *self;
80 1.1 mycroft void *aux;
81 1.1 mycroft {
82 1.1 mycroft struct isa_attach_args *ia = aux;
83 1.1 mycroft struct uha_softc *sc = (void *)self;
84 1.1 mycroft bus_chipset_tag_t bc = ia->ia_bc;
85 1.1 mycroft bus_io_handle_t ioh;
86 1.1 mycroft isa_chipset_tag_t ic = ia->ia_ic;
87 1.1 mycroft
88 1.1 mycroft printf("\n");
89 1.1 mycroft
90 1.1 mycroft if (bus_io_map(bc, ia->ia_iobase, UHA_ISA_IOSIZE, &ioh))
91 1.1 mycroft panic("uha_attach: bus_io_map failed!");
92 1.1 mycroft
93 1.1 mycroft sc->sc_bc = bc;
94 1.1 mycroft sc->sc_ioh = ioh;
95 1.1 mycroft if (!u14_find(bc, ioh, sc))
96 1.1 mycroft panic("uha_attach: u14_find failed!");
97 1.1 mycroft
98 1.1 mycroft if (sc->sc_drq != -1)
99 1.1 mycroft isa_dmacascade(sc->sc_drq);
100 1.1 mycroft
101 1.1 mycroft sc->sc_ih = isa_intr_establish(ic, sc->sc_irq, IST_EDGE, IPL_BIO,
102 1.1 mycroft u14_intr, sc);
103 1.1 mycroft if (sc->sc_ih == NULL) {
104 1.1 mycroft printf("%s: couldn't establish interrupt\n",
105 1.1 mycroft sc->sc_dev.dv_xname);
106 1.1 mycroft return;
107 1.1 mycroft }
108 1.1 mycroft
109 1.1 mycroft /* Save function pointers for later use. */
110 1.1 mycroft sc->start_mbox = u14_start_mbox;
111 1.1 mycroft sc->poll = u14_poll;
112 1.1 mycroft sc->init = u14_init;
113 1.1 mycroft
114 1.1 mycroft uha_attach(sc);
115 1.1 mycroft }
116 1.1 mycroft
117 1.1 mycroft /*
118 1.1 mycroft * Start the board, ready for normal operation
119 1.1 mycroft */
120 1.1 mycroft int
121 1.1 mycroft u14_find(bc, ioh, sc)
122 1.1 mycroft bus_chipset_tag_t bc;
123 1.1 mycroft bus_io_handle_t ioh;
124 1.1 mycroft struct uha_softc *sc;
125 1.1 mycroft {
126 1.1 mycroft u_int16_t model, config;
127 1.1 mycroft int irq, drq;
128 1.1 mycroft int resetcount = 4000; /* 4 secs? */
129 1.1 mycroft
130 1.1 mycroft model = (bus_io_read_1(bc, ioh, U14_ID + 0) << 8) |
131 1.1 mycroft (bus_io_read_1(bc, ioh, U14_ID + 1) << 0);
132 1.1 mycroft if ((model & 0xfff0) != 0x5640)
133 1.1 mycroft return (0);
134 1.1 mycroft
135 1.1 mycroft config = (bus_io_read_1(bc, ioh, U14_CONFIG + 0) << 8) |
136 1.1 mycroft (bus_io_read_1(bc, ioh, U14_CONFIG + 1) << 0);
137 1.1 mycroft
138 1.1 mycroft switch (model & 0x000f) {
139 1.1 mycroft case 0x0000:
140 1.1 mycroft switch (config & U14_DMA_MASK) {
141 1.1 mycroft case U14_DMA_CH5:
142 1.1 mycroft drq = 5;
143 1.1 mycroft break;
144 1.1 mycroft case U14_DMA_CH6:
145 1.1 mycroft drq = 6;
146 1.1 mycroft break;
147 1.1 mycroft case U14_DMA_CH7:
148 1.1 mycroft drq = 7;
149 1.1 mycroft break;
150 1.1 mycroft default:
151 1.1 mycroft printf("u14_find: illegal drq setting %x\n",
152 1.1 mycroft config & U14_DMA_MASK);
153 1.1 mycroft return (0);
154 1.1 mycroft }
155 1.1 mycroft break;
156 1.1 mycroft case 0x0001:
157 1.1 mycroft /* This is a 34f, and doesn't need an ISA DMA channel. */
158 1.1 mycroft drq = -1;
159 1.1 mycroft break;
160 1.1 mycroft }
161 1.1 mycroft
162 1.1 mycroft switch (config & U14_IRQ_MASK) {
163 1.1 mycroft case U14_IRQ10:
164 1.1 mycroft irq = 10;
165 1.1 mycroft break;
166 1.1 mycroft case U14_IRQ11:
167 1.1 mycroft irq = 11;
168 1.1 mycroft break;
169 1.1 mycroft case U14_IRQ14:
170 1.1 mycroft irq = 14;
171 1.1 mycroft break;
172 1.1 mycroft case U14_IRQ15:
173 1.1 mycroft irq = 15;
174 1.1 mycroft break;
175 1.1 mycroft default:
176 1.1 mycroft printf("u14_find: illegal irq setting %x\n",
177 1.1 mycroft config & U14_IRQ_MASK);
178 1.1 mycroft return (0);
179 1.1 mycroft }
180 1.1 mycroft
181 1.1 mycroft bus_io_write_1(bc, ioh, U14_LINT, UHA_ASRST);
182 1.1 mycroft
183 1.1 mycroft while (--resetcount) {
184 1.1 mycroft if (bus_io_read_1(bc, ioh, U14_LINT))
185 1.1 mycroft break;
186 1.1 mycroft delay(1000); /* 1 mSec per loop */
187 1.1 mycroft }
188 1.1 mycroft if (!resetcount) {
189 1.1 mycroft printf("u14_find: board timed out during reset\n");
190 1.1 mycroft return (0);
191 1.1 mycroft }
192 1.1 mycroft
193 1.1 mycroft /* if we want to fill in softc, do so now */
194 1.1 mycroft if (sc != NULL) {
195 1.1 mycroft sc->sc_irq = irq;
196 1.1 mycroft sc->sc_drq = drq;
197 1.1 mycroft sc->sc_scsi_dev = config & U14_HOSTID_MASK;
198 1.1 mycroft }
199 1.1 mycroft
200 1.1 mycroft return (1);
201 1.1 mycroft }
202 1.1 mycroft
203 1.1 mycroft /*
204 1.1 mycroft * Function to send a command out through a mailbox
205 1.1 mycroft */
206 1.1 mycroft void
207 1.1 mycroft u14_start_mbox(sc, mscp)
208 1.1 mycroft struct uha_softc *sc;
209 1.1 mycroft struct uha_mscp *mscp;
210 1.1 mycroft {
211 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
212 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
213 1.1 mycroft int spincount = 100000; /* 1s should be enough */
214 1.1 mycroft
215 1.1 mycroft while (--spincount) {
216 1.1 mycroft if ((bus_io_read_1(bc, ioh, U14_LINT) & U14_LDIP) == 0)
217 1.1 mycroft break;
218 1.1 mycroft delay(100);
219 1.1 mycroft }
220 1.1 mycroft if (!spincount) {
221 1.1 mycroft printf("%s: uha_start_mbox, board not responding\n",
222 1.1 mycroft sc->sc_dev.dv_xname);
223 1.1 mycroft Debugger();
224 1.1 mycroft }
225 1.1 mycroft
226 1.1 mycroft bus_io_write_4(bc, ioh, U14_OGMPTR, KVTOPHYS(mscp));
227 1.1 mycroft if (mscp->flags & MSCP_ABORT)
228 1.1 mycroft bus_io_write_1(bc, ioh, U14_LINT, U14_ABORT);
229 1.1 mycroft else
230 1.1 mycroft bus_io_write_1(bc, ioh, U14_LINT, U14_OGMFULL);
231 1.1 mycroft
232 1.1 mycroft if ((mscp->xs->flags & SCSI_POLL) == 0)
233 1.1 mycroft timeout(uha_timeout, mscp, (mscp->timeout * hz) / 1000);
234 1.1 mycroft }
235 1.1 mycroft
236 1.1 mycroft /*
237 1.1 mycroft * Function to poll for command completion when in poll mode.
238 1.1 mycroft *
239 1.1 mycroft * wait = timeout in msec
240 1.1 mycroft */
241 1.1 mycroft int
242 1.1 mycroft u14_poll(sc, xs, count)
243 1.1 mycroft struct uha_softc *sc;
244 1.1 mycroft struct scsi_xfer *xs;
245 1.1 mycroft int count;
246 1.1 mycroft {
247 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
248 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
249 1.1 mycroft
250 1.1 mycroft while (count) {
251 1.1 mycroft /*
252 1.1 mycroft * If we had interrupts enabled, would we
253 1.1 mycroft * have got an interrupt?
254 1.1 mycroft */
255 1.1 mycroft if (bus_io_read_1(bc, ioh, U14_SINT) & U14_SDIP)
256 1.1 mycroft u14_intr(sc);
257 1.1 mycroft if (xs->flags & ITSDONE)
258 1.1 mycroft return (0);
259 1.1 mycroft delay(1000);
260 1.1 mycroft count--;
261 1.1 mycroft }
262 1.1 mycroft return (1);
263 1.1 mycroft }
264 1.1 mycroft
265 1.1 mycroft /*
266 1.1 mycroft * Catch an interrupt from the adaptor
267 1.1 mycroft */
268 1.1 mycroft int
269 1.1 mycroft u14_intr(arg)
270 1.1 mycroft void *arg;
271 1.1 mycroft {
272 1.1 mycroft struct uha_softc *sc = arg;
273 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
274 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
275 1.1 mycroft struct uha_mscp *mscp;
276 1.1 mycroft u_char uhastat;
277 1.1 mycroft u_long mboxval;
278 1.1 mycroft
279 1.1 mycroft #ifdef UHADEBUG
280 1.1 mycroft printf("%s: uhaintr ", sc->sc_dev.dv_xname);
281 1.1 mycroft #endif /*UHADEBUG */
282 1.1 mycroft
283 1.1 mycroft if ((bus_io_read_1(bc, ioh, U14_SINT) & U14_SDIP) == 0)
284 1.1 mycroft return (0);
285 1.1 mycroft
286 1.1 mycroft for (;;) {
287 1.1 mycroft /*
288 1.1 mycroft * First get all the information and then
289 1.1 mycroft * acknowledge the interrupt
290 1.1 mycroft */
291 1.1 mycroft uhastat = bus_io_read_1(bc, ioh, U14_SINT);
292 1.1 mycroft mboxval = bus_io_read_4(bc, ioh, U14_ICMPTR);
293 1.1 mycroft /* XXX Send an ABORT_ACK instead? */
294 1.1 mycroft bus_io_write_1(bc, ioh, U14_SINT, U14_ICM_ACK);
295 1.1 mycroft
296 1.1 mycroft #ifdef UHADEBUG
297 1.1 mycroft printf("status = 0x%x ", uhastat);
298 1.1 mycroft #endif /*UHADEBUG*/
299 1.1 mycroft
300 1.1 mycroft /*
301 1.1 mycroft * Process the completed operation
302 1.1 mycroft */
303 1.1 mycroft mscp = uha_mscp_phys_kv(sc, mboxval);
304 1.1 mycroft if (!mscp) {
305 1.1 mycroft printf("%s: BAD MSCP RETURNED!\n",
306 1.1 mycroft sc->sc_dev.dv_xname);
307 1.1 mycroft continue; /* whatever it was, it'll timeout */
308 1.1 mycroft }
309 1.1 mycroft
310 1.1 mycroft untimeout(uha_timeout, mscp);
311 1.1 mycroft uha_done(sc, mscp);
312 1.1 mycroft
313 1.1 mycroft if ((bus_io_read_1(bc, ioh, U14_SINT) & U14_SDIP) == 0)
314 1.1 mycroft return (1);
315 1.1 mycroft }
316 1.1 mycroft }
317 1.1 mycroft
318 1.1 mycroft void
319 1.1 mycroft u14_init(sc)
320 1.1 mycroft struct uha_softc *sc;
321 1.1 mycroft {
322 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
323 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
324 1.1 mycroft
325 1.1 mycroft /* make sure interrupts are enabled */
326 1.1 mycroft #ifdef UHADEBUG
327 1.1 mycroft printf("u14_init: lmask=%02x, smask=%02x\n",
328 1.1 mycroft bus_io_read_1(bc, ioh, U14_LMASK),
329 1.1 mycroft bus_io_read_1(bc, ioh, U14_SMASK));
330 1.1 mycroft #endif
331 1.1 mycroft bus_io_write_1(bc, ioh, U14_LMASK, 0xd1); /* XXX */
332 1.1 mycroft bus_io_write_1(bc, ioh, U14_SMASK, 0x91); /* XXX */
333 1.1 mycroft }
334