uha_eisa.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/eisa/eisavar.h>
15 1.1 mycroft #include <dev/eisa/eisadevs.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_EISA_SLOT_OFFSET 0xc80
21 1.1 mycroft #define UHA_EISA_IOSIZE 0x020
22 1.1 mycroft
23 1.1 mycroft int uha_eisa_match __P((struct device *, void *, void *));
24 1.1 mycroft void uha_eisa_attach __P((struct device *, struct device *, void *));
25 1.1 mycroft
26 1.1 mycroft struct cfattach uha_eisa_ca = {
27 1.1 mycroft sizeof(struct uha_softc), uha_eisa_match, uha_eisa_attach
28 1.1 mycroft };
29 1.1 mycroft
30 1.1 mycroft #define KVTOPHYS(x) vtophys(x)
31 1.1 mycroft
32 1.1 mycroft int u24_find __P((bus_chipset_tag_t, bus_io_handle_t, struct uha_softc *));
33 1.1 mycroft void u24_start_mbox __P((struct uha_softc *, struct uha_mscp *));
34 1.1 mycroft int u24_poll __P((struct uha_softc *, struct scsi_xfer *, int));
35 1.1 mycroft int u24_intr __P((void *));
36 1.1 mycroft void u24_init __P((struct uha_softc *));
37 1.1 mycroft
38 1.1 mycroft /*
39 1.1 mycroft * Check the slots looking for a board we recognise
40 1.1 mycroft * If we find one, note it's address (slot) and call
41 1.1 mycroft * the actual probe routine to check it out.
42 1.1 mycroft */
43 1.1 mycroft int
44 1.1 mycroft uha_eisa_match(parent, match, aux)
45 1.1 mycroft struct device *parent;
46 1.1 mycroft void *match, *aux;
47 1.1 mycroft {
48 1.1 mycroft struct eisa_attach_args *ea = aux;
49 1.1 mycroft bus_chipset_tag_t bc = ea->ea_bc;
50 1.1 mycroft bus_io_handle_t ioh;
51 1.1 mycroft int rv;
52 1.1 mycroft
53 1.1 mycroft /* must match one of our known ID strings */
54 1.1 mycroft if (strncmp(ea->ea_idstring, "USC024", 6))
55 1.1 mycroft return (0);
56 1.1 mycroft
57 1.1 mycroft if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + UHA_EISA_SLOT_OFFSET,
58 1.1 mycroft UHA_EISA_IOSIZE, &ioh))
59 1.1 mycroft return (0);
60 1.1 mycroft
61 1.1 mycroft rv = u24_find(bc, ioh, NULL);
62 1.1 mycroft
63 1.1 mycroft bus_io_unmap(bc, ioh, UHA_EISA_IOSIZE);
64 1.1 mycroft
65 1.1 mycroft return (rv);
66 1.1 mycroft }
67 1.1 mycroft
68 1.1 mycroft /*
69 1.1 mycroft * Attach all the sub-devices we can find
70 1.1 mycroft */
71 1.1 mycroft void
72 1.1 mycroft uha_eisa_attach(parent, self, aux)
73 1.1 mycroft struct device *parent, *self;
74 1.1 mycroft void *aux;
75 1.1 mycroft {
76 1.1 mycroft struct eisa_attach_args *ea = aux;
77 1.1 mycroft struct uha_softc *sc = (void *)self;
78 1.1 mycroft bus_chipset_tag_t bc = ea->ea_bc;
79 1.1 mycroft bus_io_handle_t ioh;
80 1.1 mycroft eisa_chipset_tag_t ec = ea->ea_ec;
81 1.1 mycroft eisa_intr_handle_t ih;
82 1.1 mycroft const char *model, *intrstr;
83 1.1 mycroft
84 1.1 mycroft if (!strncmp(ea->ea_idstring, "USC024", 6))
85 1.1 mycroft model = EISA_PRODUCT_USC0240;
86 1.1 mycroft else
87 1.1 mycroft model = "unknown model!";
88 1.1 mycroft printf(": %s\n", model);
89 1.1 mycroft
90 1.1 mycroft if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + UHA_EISA_SLOT_OFFSET,
91 1.1 mycroft UHA_EISA_IOSIZE, &ioh))
92 1.1 mycroft panic("uha_attach: could not map I/O addresses");
93 1.1 mycroft
94 1.1 mycroft sc->sc_bc = bc;
95 1.1 mycroft sc->sc_ioh = ioh;
96 1.1 mycroft if (!u24_find(bc, ioh, sc))
97 1.1 mycroft panic("uha_attach: u24_find failed!");
98 1.1 mycroft
99 1.1 mycroft if (eisa_intr_map(ec, sc->sc_irq, &ih)) {
100 1.1 mycroft printf("%s: couldn't map interrupt (%d)\n",
101 1.1 mycroft sc->sc_dev.dv_xname, sc->sc_irq);
102 1.1 mycroft return;
103 1.1 mycroft }
104 1.1 mycroft intrstr = eisa_intr_string(ec, ih);
105 1.1 mycroft sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
106 1.1 mycroft u24_intr, sc);
107 1.1 mycroft if (sc->sc_ih == NULL) {
108 1.1 mycroft printf("%s: couldn't establish interrupt",
109 1.1 mycroft sc->sc_dev.dv_xname);
110 1.1 mycroft if (intrstr != NULL)
111 1.1 mycroft printf(" at %s", intrstr);
112 1.1 mycroft printf("\n");
113 1.1 mycroft return;
114 1.1 mycroft }
115 1.1 mycroft printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
116 1.1 mycroft
117 1.1 mycroft /* Save function pointers for later use. */
118 1.1 mycroft sc->start_mbox = u24_start_mbox;
119 1.1 mycroft sc->poll = u24_poll;
120 1.1 mycroft sc->init = u24_init;
121 1.1 mycroft
122 1.1 mycroft uha_attach(sc);
123 1.1 mycroft }
124 1.1 mycroft
125 1.1 mycroft int
126 1.1 mycroft u24_find(bc, ioh, sc)
127 1.1 mycroft bus_chipset_tag_t bc;
128 1.1 mycroft bus_io_handle_t ioh;
129 1.1 mycroft struct uha_softc *sc;
130 1.1 mycroft {
131 1.1 mycroft u_int8_t config0, config1, config2;
132 1.1 mycroft int irq, drq;
133 1.1 mycroft int resetcount = 4000; /* 4 secs? */
134 1.1 mycroft
135 1.1 mycroft config0 = bus_io_read_1(bc, ioh, U24_CONFIG + 0);
136 1.1 mycroft config1 = bus_io_read_1(bc, ioh, U24_CONFIG + 1);
137 1.1 mycroft config2 = bus_io_read_1(bc, ioh, U24_CONFIG + 2);
138 1.1 mycroft if ((config0 & U24_MAGIC1) == 0 ||
139 1.1 mycroft (config1 & U24_MAGIC2) == 0)
140 1.1 mycroft return (0);
141 1.1 mycroft
142 1.1 mycroft drq = -1;
143 1.1 mycroft
144 1.1 mycroft switch (config0 & U24_IRQ_MASK) {
145 1.1 mycroft case U24_IRQ10:
146 1.1 mycroft irq = 10;
147 1.1 mycroft break;
148 1.1 mycroft case U24_IRQ11:
149 1.1 mycroft irq = 11;
150 1.1 mycroft break;
151 1.1 mycroft case U24_IRQ14:
152 1.1 mycroft irq = 14;
153 1.1 mycroft break;
154 1.1 mycroft case U24_IRQ15:
155 1.1 mycroft irq = 15;
156 1.1 mycroft break;
157 1.1 mycroft default:
158 1.1 mycroft printf("u24_find: illegal irq setting %x\n",
159 1.1 mycroft config0 & U24_IRQ_MASK);
160 1.1 mycroft return (0);
161 1.1 mycroft }
162 1.1 mycroft
163 1.1 mycroft bus_io_write_1(bc, ioh, U24_LINT, UHA_ASRST);
164 1.1 mycroft
165 1.1 mycroft while (--resetcount) {
166 1.1 mycroft if (bus_io_read_1(bc, ioh, U24_LINT))
167 1.1 mycroft break;
168 1.1 mycroft delay(1000); /* 1 mSec per loop */
169 1.1 mycroft }
170 1.1 mycroft if (!resetcount) {
171 1.1 mycroft printf("u24_find: board timed out during reset\n");
172 1.1 mycroft return (0);
173 1.1 mycroft }
174 1.1 mycroft
175 1.1 mycroft /* if we want to fill in softc, do so now */
176 1.1 mycroft if (sc != NULL) {
177 1.1 mycroft sc->sc_irq = irq;
178 1.1 mycroft sc->sc_drq = drq;
179 1.1 mycroft sc->sc_scsi_dev = config2 & U24_HOSTID_MASK;
180 1.1 mycroft }
181 1.1 mycroft
182 1.1 mycroft return (1);
183 1.1 mycroft }
184 1.1 mycroft
185 1.1 mycroft void
186 1.1 mycroft u24_start_mbox(sc, mscp)
187 1.1 mycroft struct uha_softc *sc;
188 1.1 mycroft struct uha_mscp *mscp;
189 1.1 mycroft {
190 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
191 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
192 1.1 mycroft int spincount = 100000; /* 1s should be enough */
193 1.1 mycroft
194 1.1 mycroft while (--spincount) {
195 1.1 mycroft if ((bus_io_read_1(bc, ioh, U24_LINT) & U24_LDIP) == 0)
196 1.1 mycroft break;
197 1.1 mycroft delay(100);
198 1.1 mycroft }
199 1.1 mycroft if (!spincount) {
200 1.1 mycroft printf("%s: uha_start_mbox, board not responding\n",
201 1.1 mycroft sc->sc_dev.dv_xname);
202 1.1 mycroft Debugger();
203 1.1 mycroft }
204 1.1 mycroft
205 1.1 mycroft bus_io_write_4(bc, ioh, U24_OGMPTR, KVTOPHYS(mscp));
206 1.1 mycroft if (mscp->flags & MSCP_ABORT)
207 1.1 mycroft bus_io_write_1(bc, ioh, U24_OGMCMD, 0x80);
208 1.1 mycroft else
209 1.1 mycroft bus_io_write_1(bc, ioh, U24_OGMCMD, 0x01);
210 1.1 mycroft bus_io_write_1(bc, ioh, U24_LINT, U24_OGMFULL);
211 1.1 mycroft
212 1.1 mycroft if ((mscp->xs->flags & SCSI_POLL) == 0)
213 1.1 mycroft timeout(uha_timeout, mscp, (mscp->timeout * hz) / 1000);
214 1.1 mycroft }
215 1.1 mycroft
216 1.1 mycroft int
217 1.1 mycroft u24_poll(sc, xs, count)
218 1.1 mycroft struct uha_softc *sc;
219 1.1 mycroft struct scsi_xfer *xs;
220 1.1 mycroft int count;
221 1.1 mycroft {
222 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
223 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
224 1.1 mycroft
225 1.1 mycroft while (count) {
226 1.1 mycroft /*
227 1.1 mycroft * If we had interrupts enabled, would we
228 1.1 mycroft * have got an interrupt?
229 1.1 mycroft */
230 1.1 mycroft if (bus_io_read_1(bc, ioh, U24_SINT) & U24_SDIP)
231 1.1 mycroft u24_intr(sc);
232 1.1 mycroft if (xs->flags & ITSDONE)
233 1.1 mycroft return (0);
234 1.1 mycroft delay(1000);
235 1.1 mycroft count--;
236 1.1 mycroft }
237 1.1 mycroft return (1);
238 1.1 mycroft }
239 1.1 mycroft
240 1.1 mycroft int
241 1.1 mycroft u24_intr(arg)
242 1.1 mycroft void *arg;
243 1.1 mycroft {
244 1.1 mycroft struct uha_softc *sc = arg;
245 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
246 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
247 1.1 mycroft struct uha_mscp *mscp;
248 1.1 mycroft u_char uhastat;
249 1.1 mycroft u_long mboxval;
250 1.1 mycroft
251 1.1 mycroft #ifdef UHADEBUG
252 1.1 mycroft printf("%s: uhaintr ", sc->sc_dev.dv_xname);
253 1.1 mycroft #endif /*UHADEBUG */
254 1.1 mycroft
255 1.1 mycroft if ((bus_io_read_1(bc, ioh, U24_SINT) & U24_SDIP) == 0)
256 1.1 mycroft return (0);
257 1.1 mycroft
258 1.1 mycroft for (;;) {
259 1.1 mycroft /*
260 1.1 mycroft * First get all the information and then
261 1.1 mycroft * acknowledge the interrupt
262 1.1 mycroft */
263 1.1 mycroft uhastat = bus_io_read_1(bc, ioh, U24_SINT);
264 1.1 mycroft mboxval = bus_io_read_4(bc, ioh, U24_ICMPTR);
265 1.1 mycroft bus_io_write_1(bc, ioh, U24_SINT, U24_ICM_ACK);
266 1.1 mycroft bus_io_write_1(bc, ioh, U24_ICMCMD, 0);
267 1.1 mycroft
268 1.1 mycroft #ifdef UHADEBUG
269 1.1 mycroft printf("status = 0x%x ", uhastat);
270 1.1 mycroft #endif /*UHADEBUG*/
271 1.1 mycroft
272 1.1 mycroft /*
273 1.1 mycroft * Process the completed operation
274 1.1 mycroft */
275 1.1 mycroft mscp = uha_mscp_phys_kv(sc, mboxval);
276 1.1 mycroft if (!mscp) {
277 1.1 mycroft printf("%s: BAD MSCP RETURNED!\n",
278 1.1 mycroft sc->sc_dev.dv_xname);
279 1.1 mycroft continue; /* whatever it was, it'll timeout */
280 1.1 mycroft }
281 1.1 mycroft untimeout(uha_timeout, mscp);
282 1.1 mycroft uha_done(sc, mscp);
283 1.1 mycroft
284 1.1 mycroft if ((bus_io_read_1(bc, ioh, U24_SINT) & U24_SDIP) == 0)
285 1.1 mycroft return (1);
286 1.1 mycroft }
287 1.1 mycroft }
288 1.1 mycroft
289 1.1 mycroft void
290 1.1 mycroft u24_init(sc)
291 1.1 mycroft struct uha_softc *sc;
292 1.1 mycroft {
293 1.1 mycroft bus_chipset_tag_t bc = sc->sc_bc;
294 1.1 mycroft bus_io_handle_t ioh = sc->sc_ioh;
295 1.1 mycroft
296 1.1 mycroft /* free OGM and ICM */
297 1.1 mycroft bus_io_write_1(bc, ioh, U24_OGMCMD, 0);
298 1.1 mycroft bus_io_write_1(bc, ioh, U24_ICMCMD, 0);
299 1.1 mycroft /* make sure interrupts are enabled */
300 1.1 mycroft #ifdef UHADEBUG
301 1.1 mycroft printf("u24_init: lmask=%02x, smask=%02x\n",
302 1.1 mycroft bus_io_read_1(bc, ioh, U24_LMASK),
303 1.1 mycroft bus_io_read_1(bc, ioh, U24_SMASK));
304 1.1 mycroft #endif
305 1.1 mycroft bus_io_write_1(bc, ioh, U24_LMASK, 0xd2); /* XXX */
306 1.1 mycroft bus_io_write_1(bc, ioh, U24_SMASK, 0x92); /* XXX */
307 1.1 mycroft }
308