siop.c revision 1.1 1 1.1 mw /*
2 1.1 mw * Copyright (c) 1990 The Regents of the University of California.
3 1.1 mw * All rights reserved.
4 1.1 mw *
5 1.1 mw * This code is derived from software contributed to Berkeley by
6 1.1 mw * Van Jacobson of Lawrence Berkeley Laboratory.
7 1.1 mw *
8 1.1 mw * Redistribution and use in source and binary forms, with or without
9 1.1 mw * modification, are permitted provided that the following conditions
10 1.1 mw * are met:
11 1.1 mw * 1. Redistributions of source code must retain the above copyright
12 1.1 mw * notice, this list of conditions and the following disclaimer.
13 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 mw * notice, this list of conditions and the following disclaimer in the
15 1.1 mw * documentation and/or other materials provided with the distribution.
16 1.1 mw * 3. All advertising materials mentioning features or use of this software
17 1.1 mw * must display the following acknowledgement:
18 1.1 mw * This product includes software developed by the University of
19 1.1 mw * California, Berkeley and its contributors.
20 1.1 mw * 4. Neither the name of the University nor the names of its contributors
21 1.1 mw * may be used to endorse or promote products derived from this software
22 1.1 mw * without specific prior written permission.
23 1.1 mw *
24 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 mw * SUCH DAMAGE.
35 1.1 mw *
36 1.1 mw * @(#)siop.c 7.5 (Berkeley) 5/4/91
37 1.1 mw *
38 1.1 mw * MULTICONTROLLER support only working for multiple controllers of the
39 1.1 mw * same kind at the moment !!
40 1.1 mw *
41 1.1 mw */
42 1.1 mw
43 1.1 mw /*
44 1.1 mw * AMIGA 53C710 scsi adaptor driver
45 1.1 mw */
46 1.1 mw #include "zeusscsi.h"
47 1.1 mw #include "magnumscsi.h"
48 1.1 mw #define NSIOP (NZEUSSCSI + NMAGNUMSCSI)
49 1.1 mw #if NSIOP > 0
50 1.1 mw
51 1.1 mw /* these are used to determine if we compile for sddriver or rzdriver */
52 1.1 mw #include "a3000scsi.h"
53 1.1 mw #include "a2091scsi.h"
54 1.1 mw #include "gvp11scsi.h"
55 1.1 mw
56 1.1 mw #ifndef lint
57 1.1 mw static char rcsid[] = "$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/amiga/dev/siop.c,v 1.1 1994/01/26 21:06:20 mw Exp $";
58 1.1 mw #endif
59 1.1 mw
60 1.1 mw #include "sys/param.h"
61 1.1 mw #include "sys/systm.h"
62 1.1 mw #include "sys/buf.h"
63 1.1 mw #include "device.h"
64 1.1 mw
65 1.1 mw #if (NA3000SCSI + NA2091SCSI + NAGVP11SCSI) == 0
66 1.1 mw /* Kludge for sd.c */
67 1.1 mw #define siopstart scsistart
68 1.1 mw #define siopgo scsigo
69 1.1 mw #define siopdone scsidone
70 1.1 mw #define siopreset scsireset
71 1.1 mw #define siop_delay scsi_delay
72 1.1 mw #define siop_test_unit_rdy scsi_test_unit_rdy
73 1.1 mw #define siop_start_stop_unit scsi_start_stop_unit
74 1.1 mw #define siop_request_sense scsi_request_sense
75 1.1 mw #define siop_immed_command scsi_immed_command
76 1.1 mw #define siop_tt_read scsi_tt_read
77 1.1 mw #define siop_tt_write scsi_tt_write
78 1.1 mw #define siop_tt_oddio scsi_tt_oddio
79 1.1 mw #define siopreq scsireq
80 1.1 mw #define siopustart scsiustart
81 1.1 mw #define siopfree scsifree
82 1.1 mw #endif
83 1.1 mw
84 1.1 mw #include "siopvar.h"
85 1.1 mw #include "siopreg.h"
86 1.1 mw
87 1.1 mw #include "../amiga/custom.h"
88 1.1 mw
89 1.1 mw #include "machine/cpu.h"
90 1.1 mw
91 1.1 mw extern u_int kvtop();
92 1.1 mw
93 1.1 mw /*
94 1.1 mw * SCSI delays
95 1.1 mw * In u-seconds, primarily for state changes on the SPC.
96 1.1 mw */
97 1.1 mw #define SCSI_CMD_WAIT 50000 /* wait per step of 'immediate' cmds */
98 1.1 mw #define SCSI_DATA_WAIT 50000 /* wait per data in/out step */
99 1.1 mw #define SCSI_INIT_WAIT 50000 /* wait per step (both) during init */
100 1.1 mw
101 1.1 mw #if NZEUSSCSI > 0
102 1.1 mw int zeusscsiinit();
103 1.1 mw
104 1.1 mw struct driver zeusscsidriver = {
105 1.1 mw zeusscsiinit, "Zeusscsi", (int (*)())siopstart, (int (*)())siopgo,
106 1.1 mw (int (*)())siopintr2, (int (*)())siopdone,
107 1.1 mw };
108 1.1 mw #endif
109 1.1 mw
110 1.1 mw #if NMAGNUMSCSI > 0
111 1.1 mw int magnumscsiinit();
112 1.1 mw
113 1.1 mw struct driver magnumscsidriver = {
114 1.1 mw magnumscsiinit, "Magnumscsi", (int (*)())siopstart, (int (*)())siopgo,
115 1.1 mw (int (*)())siopintr2, (int (*)())siopdone,
116 1.1 mw };
117 1.1 mw #endif
118 1.1 mw
119 1.1 mw /* 53C710 script */
120 1.1 mw unsigned long scripts[] = {
121 1.1 mw 0x47000000, 0x00000298, /* 000 - 0 */
122 1.1 mw 0x838b0000, 0x000000d0, /* 008 - 8 */
123 1.1 mw 0x7a1b1000, 0x00000000, /* 010 - 16 */
124 1.1 mw 0x828a0000, 0x00000088, /* 018 - 24 */
125 1.1 mw 0x9e020000, 0x0000ff01, /* 020 - 32 */
126 1.1 mw 0x72350000, 0x00000000, /* 028 - 40 */
127 1.1 mw 0x808c0000, 0x00000048, /* 030 - 48 */
128 1.1 mw 0x58000008, 0x00000000, /* 038 - 56 */
129 1.1 mw 0x1e000024, 0x00000024, /* 040 - 64 */
130 1.1 mw 0x838b0000, 0x00000090, /* 048 - 72 */
131 1.1 mw 0x1f00002c, 0x0000002c, /* 050 - 80 */
132 1.1 mw 0x838b0000, 0x00000080, /* 058 - 88 */
133 1.1 mw 0x868a0000, 0xffffffd0, /* 060 - 96 */
134 1.1 mw 0x838a0000, 0x00000070, /* 068 - 104 */
135 1.1 mw 0x878a0000, 0x00000120, /* 070 - 112 */
136 1.1 mw 0x80880000, 0x00000028, /* 078 - 120 */
137 1.1 mw 0x1e000004, 0x00000004, /* 080 - 128 */
138 1.1 mw 0x838b0000, 0x00000050, /* 088 - 136 */
139 1.1 mw 0x868a0000, 0xffffffe8, /* 090 - 144 */
140 1.1 mw 0x838a0000, 0x00000040, /* 098 - 152 */
141 1.1 mw 0x878a0000, 0x000000f0, /* 0a0 - 160 */
142 1.1 mw 0x9a020000, 0x0000ff02, /* 0a8 - 168 */
143 1.1 mw 0x1a00000c, 0x0000000c, /* 0b0 - 176 */
144 1.1 mw 0x878b0000, 0x00000130, /* 0b8 - 184 */
145 1.1 mw 0x838a0000, 0x00000018, /* 0c0 - 192 */
146 1.1 mw 0x818a0000, 0x000000b0, /* 0c8 - 200 */
147 1.1 mw 0x808a0000, 0x00000080, /* 0d0 - 208 */
148 1.1 mw 0x98080000, 0x0000ff03, /* 0d8 - 216 */
149 1.1 mw 0x1b000014, 0x00000014, /* 0e0 - 224 */
150 1.1 mw 0x72090000, 0x00000000, /* 0e8 - 232 */
151 1.1 mw 0x6a340000, 0x00000000, /* 0f0 - 240 */
152 1.1 mw 0x9f030000, 0x0000ff04, /* 0f8 - 248 */
153 1.1 mw 0x1f00001c, 0x0000001c, /* 100 - 256 */
154 1.1 mw 0x98040000, 0x0000ff26, /* 108 - 264 */
155 1.1 mw 0x60000040, 0x00000000, /* 110 - 272 */
156 1.1 mw 0x48000000, 0x00000000, /* 118 - 280 */
157 1.1 mw 0x7c1bef00, 0x00000000, /* 120 - 288 */
158 1.1 mw 0x72340000, 0x00000000, /* 128 - 296 */
159 1.1 mw 0x980c0002, 0x0000fffc, /* 130 - 304 */
160 1.1 mw 0x980c0008, 0x0000fffb, /* 138 - 312 */
161 1.1 mw 0x980c0018, 0x0000fffd, /* 140 - 320 */
162 1.1 mw 0x98040000, 0x0000fffe, /* 148 - 328 */
163 1.1 mw 0x98080000, 0x0000ff00, /* 150 - 336 */
164 1.1 mw 0x18000034, 0x00000034, /* 158 - 344 */
165 1.1 mw 0x808b0000, 0x000001c0, /* 160 - 352 */
166 1.1 mw 0x838b0000, 0xffffff70, /* 168 - 360 */
167 1.1 mw 0x878a0000, 0x000000d0, /* 170 - 368 */
168 1.1 mw 0x98080000, 0x0000ff05, /* 178 - 376 */
169 1.1 mw 0x19000034, 0x00000034, /* 180 - 384 */
170 1.1 mw 0x818b0000, 0x00000160, /* 188 - 392 */
171 1.1 mw 0x80880000, 0xffffffd0, /* 190 - 400 */
172 1.1 mw 0x1f00001c, 0x0000001c, /* 198 - 408 */
173 1.1 mw 0x808c0001, 0x00000018, /* 1a0 - 416 */
174 1.1 mw 0x980c0002, 0x0000ff08, /* 1a8 - 424 */
175 1.1 mw 0x808c0004, 0x00000020, /* 1b0 - 432 */
176 1.1 mw 0x98080000, 0x0000ff06, /* 1b8 - 440 */
177 1.1 mw 0x60000040, 0x00000000, /* 1c0 - 448 */
178 1.1 mw 0x1f00002c, 0x0000002c, /* 1c8 - 456 */
179 1.1 mw 0x98080000, 0x0000ff07, /* 1d0 - 464 */
180 1.1 mw 0x60000040, 0x00000000, /* 1d8 - 472 */
181 1.1 mw 0x48000000, 0x00000000, /* 1e0 - 480 */
182 1.1 mw 0x98080000, 0x0000ff09, /* 1e8 - 488 */
183 1.1 mw 0x1f00001c, 0x0000001c, /* 1f0 - 496 */
184 1.1 mw 0x808c0001, 0x00000018, /* 1f8 - 504 */
185 1.1 mw 0x980c0002, 0x0000ff10, /* 200 - 512 */
186 1.1 mw 0x808c0004, 0x00000020, /* 208 - 520 */
187 1.1 mw 0x98080000, 0x0000ff11, /* 210 - 528 */
188 1.1 mw 0x60000040, 0x00000000, /* 218 - 536 */
189 1.1 mw 0x1f00002c, 0x0000002c, /* 220 - 544 */
190 1.1 mw 0x98080000, 0x0000ff12, /* 228 - 552 */
191 1.1 mw 0x60000040, 0x00000000, /* 230 - 560 */
192 1.1 mw 0x48000000, 0x00000000, /* 238 - 568 */
193 1.1 mw 0x98080000, 0x0000ff13, /* 240 - 576 */
194 1.1 mw 0x1f00001c, 0x0000001c, /* 248 - 584 */
195 1.1 mw 0x808c0001, 0x00000018, /* 250 - 592 */
196 1.1 mw 0x980c0002, 0x0000ff14, /* 258 - 600 */
197 1.1 mw 0x808c0004, 0x00000020, /* 260 - 608 */
198 1.1 mw 0x98080000, 0x0000ff15, /* 268 - 616 */
199 1.1 mw 0x60000040, 0x00000000, /* 270 - 624 */
200 1.1 mw 0x1f00002c, 0x0000002c, /* 278 - 632 */
201 1.1 mw 0x98080000, 0x0000ff16, /* 280 - 640 */
202 1.1 mw 0x60000040, 0x00000000, /* 288 - 648 */
203 1.1 mw 0x48000000, 0x00000000, /* 290 - 656 */
204 1.1 mw 0x98080000, 0x0000ff17, /* 298 - 664 */
205 1.1 mw 0x54000000, 0x00000040, /* 2a0 - 672 */
206 1.1 mw 0x9f030000, 0x0000ff18, /* 2a8 - 680 */
207 1.1 mw 0x1f00001c, 0x0000001c, /* 2b0 - 688 */
208 1.1 mw 0x990b0000, 0x0000ff19, /* 2b8 - 696 */
209 1.1 mw 0x980a0000, 0x0000ff20, /* 2c0 - 704 */
210 1.1 mw 0x9f0a0000, 0x0000ff21, /* 2c8 - 712 */
211 1.1 mw 0x9b0a0000, 0x0000ff22, /* 2d0 - 720 */
212 1.1 mw 0x9e0a0000, 0x0000ff23, /* 2d8 - 728 */
213 1.1 mw 0x98080000, 0x0000ff24, /* 2e0 - 736 */
214 1.1 mw 0x98080000, 0x0000ff25, /* 2e8 - 744 */
215 1.1 mw 0x76100800, 0x00000000, /* 2f0 - 752 */
216 1.1 mw 0x80840700, 0x00000008, /* 2f8 - 760 */
217 1.1 mw 0x7e110100, 0x00000000, /* 300 - 768 */
218 1.1 mw 0x6a100000, 0x00000000, /* 308 - 776 */
219 1.1 mw 0x19000034, 0x00000034, /* 310 - 784 */
220 1.1 mw 0x818b0000, 0xffffffd0, /* 318 - 792 */
221 1.1 mw 0x98080000, 0x0000ff27, /* 320 - 800 */
222 1.1 mw 0x76100800, 0x00000000, /* 328 - 808 */
223 1.1 mw 0x80840700, 0x00000008, /* 330 - 816 */
224 1.1 mw 0x7e110100, 0x00000000, /* 338 - 824 */
225 1.1 mw 0x6a100000, 0x00000000, /* 340 - 832 */
226 1.1 mw 0x18000034, 0x00000034, /* 348 - 840 */
227 1.1 mw 0x808b0000, 0xffffffd0, /* 350 - 848 */
228 1.1 mw 0x98080000, 0x0000ff27 /* 358 - 856 */
229 1.1 mw };
230 1.1 mw
231 1.1 mw #define Ent_msgout 0x00000018
232 1.1 mw #define Ent_cmd 0x000000a8
233 1.1 mw #define Ent_status 0x000000e0
234 1.1 mw #define Ent_msgin 0x000000f8
235 1.1 mw #define Ent_dataout 0x00000158
236 1.1 mw #define Ent_datain 0x00000180
237 1.1 mw
238 1.1 mw struct siop_softc siop_softc[NSIOP];
239 1.1 mw
240 1.1 mw int siop_cmd_wait = SCSI_CMD_WAIT;
241 1.1 mw int siop_data_wait = SCSI_DATA_WAIT;
242 1.1 mw int siop_init_wait = SCSI_INIT_WAIT;
243 1.1 mw
244 1.1 mw static struct {
245 1.1 mw unsigned char x; /* period from sync request message */
246 1.1 mw unsigned char y; /* siop_period << 4 | sbcl */
247 1.1 mw } xxx[] = {
248 1.1 mw {0x0f, 0x01},
249 1.1 mw {0x13, 0x11},
250 1.1 mw {0x17, 0x21},
251 1.1 mw /* {0x17, 0x02}, */
252 1.1 mw {0x1b, 0x31},
253 1.1 mw {0x1d, 0x12},
254 1.1 mw {0x1e, 0x41},
255 1.1 mw /* {0x1e, 0x03}, */
256 1.1 mw {0x22, 0x51},
257 1.1 mw {0x23, 0x22},
258 1.1 mw {0x26, 0x61},
259 1.1 mw /* {0x26, 0x13}, */
260 1.1 mw {0x29, 0x32},
261 1.1 mw {0x2a, 0x71},
262 1.1 mw {0x2d, 0x23},
263 1.1 mw {0x2e, 0x42},
264 1.1 mw {0x34, 0x52},
265 1.1 mw {0x35, 0x33},
266 1.1 mw {0x3a, 0x62},
267 1.1 mw {0x3c, 0x43},
268 1.1 mw {0x40, 0x72},
269 1.1 mw {0x44, 0x53},
270 1.1 mw {0x4b, 0x63},
271 1.1 mw {0x53, 0x73}
272 1.1 mw };
273 1.1 mw
274 1.1 mw scsi_period_to_siop (dev, target)
275 1.1 mw struct siop_softc *dev;
276 1.1 mw {
277 1.1 mw int period, offset, i, sxfer;
278 1.1 mw
279 1.1 mw period = dev->sc_msg[4];
280 1.1 mw offset = dev->sc_msg[5];
281 1.1 mw sxfer = 0;
282 1.1 mw if (offset <= SIOP_MAX_OFFSET)
283 1.1 mw sxfer = offset;
284 1.1 mw for (i = 0; i < sizeof (xxx) / 2; ++i) {
285 1.1 mw if (period <= xxx[i].x) {
286 1.1 mw sxfer |= xxx[i].y & 0x70;
287 1.1 mw offset = xxx[i].y & 0x03;
288 1.1 mw break;
289 1.1 mw }
290 1.1 mw }
291 1.1 mw dev->sc_sync[target].period = sxfer;
292 1.1 mw dev->sc_sync[target].offset = offset;
293 1.1 mw #ifdef DEBUG
294 1.1 mw printf ("sync: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, offset);
295 1.1 mw #endif
296 1.1 mw }
297 1.1 mw
298 1.1 mw /* default to not inhibit sync negotiation on any drive */
299 1.1 mw u_char siop_inhibit_sync[NSIOP][8] = { 0, 0, 1, 0, 0, 0, 0 }; /* initialize, so patchable */
300 1.1 mw int siop_no_dma = 0;
301 1.1 mw
302 1.1 mw /*
303 1.1 mw * XXX Set/reset long delays.
304 1.1 mw *
305 1.1 mw * if delay == 0, reset default delays
306 1.1 mw * if delay < 0, set both delays to default long initialization values
307 1.1 mw * if delay > 0, set both delays to this value
308 1.1 mw *
309 1.1 mw * Used when a devices is expected to respond slowly (e.g. during
310 1.1 mw * initialization).
311 1.1 mw */
312 1.1 mw void
313 1.1 mw siop_delay(delay)
314 1.1 mw int delay;
315 1.1 mw {
316 1.1 mw static int saved_cmd_wait, saved_data_wait;
317 1.1 mw
318 1.1 mw if (delay) {
319 1.1 mw saved_cmd_wait = siop_cmd_wait;
320 1.1 mw saved_data_wait = siop_data_wait;
321 1.1 mw if (delay > 0)
322 1.1 mw siop_cmd_wait = siop_data_wait = delay;
323 1.1 mw else
324 1.1 mw siop_cmd_wait = siop_data_wait = siop_init_wait;
325 1.1 mw } else {
326 1.1 mw siop_cmd_wait = saved_cmd_wait;
327 1.1 mw siop_data_wait = saved_data_wait;
328 1.1 mw }
329 1.1 mw }
330 1.1 mw
331 1.1 mw static int initialized[NSIOP];
332 1.1 mw
333 1.1 mw #ifdef DEBUG
334 1.1 mw /* 0x01 - full debug */
335 1.1 mw /* 0x02 - DMA chaining */
336 1.1 mw /* 0x04 - siopintr */
337 1.1 mw /* 0x08 - phase mismatch */
338 1.1 mw int siop_debug = 0;
339 1.1 mw int siopsync_debug = 0;
340 1.1 mw int siopdma_hits = 0;
341 1.1 mw int siopdma_misses = 0;
342 1.1 mw #endif
343 1.1 mw
344 1.1 mw static void
345 1.1 mw siopabort(dev, regs, where)
346 1.1 mw register struct siop_softc *dev;
347 1.1 mw volatile register siop_regmap_t *regs;
348 1.1 mw char *where;
349 1.1 mw {
350 1.1 mw
351 1.1 mw printf ("siop%d: abort %s: dstat %02x, sstat0 %02x sbcl %02x\n",
352 1.1 mw dev->sc_ac->amiga_unit,
353 1.1 mw where, regs->siop_dstat, regs->siop_sstat0, regs->siop_sbcl);
354 1.1 mw
355 1.1 mw if (dev->sc_flags & SIOP_SELECTED) {
356 1.1 mw #ifdef TODO
357 1.1 mw SET_SBIC_cmd (regs, SBIC_CMD_ABORT);
358 1.1 mw WAIT_CIP (regs);
359 1.1 mw
360 1.1 mw GET_SBIC_asr (regs, asr);
361 1.1 mw if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
362 1.1 mw {
363 1.1 mw /* ok, get more drastic.. */
364 1.1 mw
365 1.1 mw SET_SBIC_cmd (regs, SBIC_CMD_RESET);
366 1.1 mw DELAY(25);
367 1.1 mw SBIC_WAIT(regs, SBIC_ASR_INT, 0);
368 1.1 mw GET_SBIC_csr (regs, csr); /* clears interrupt also */
369 1.1 mw
370 1.1 mw dev->sc_flags &= ~SIOP_SELECTED;
371 1.1 mw return;
372 1.1 mw }
373 1.1 mw
374 1.1 mw do
375 1.1 mw {
376 1.1 mw SBIC_WAIT (regs, SBIC_ASR_INT, 0);
377 1.1 mw GET_SBIC_csr (regs, csr);
378 1.1 mw }
379 1.1 mw while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
380 1.1 mw && (csr != SBIC_CSR_CMD_INVALID));
381 1.1 mw #endif
382 1.1 mw
383 1.1 mw /* lets just hope it worked.. */
384 1.1 mw dev->sc_flags &= ~SIOP_SELECTED;
385 1.1 mw }
386 1.1 mw }
387 1.1 mw
388 1.1 mw #if NZEUSSCSI > 0
389 1.1 mw int
390 1.1 mw zeusscsiinit(ac)
391 1.1 mw register struct amiga_ctlr *ac;
392 1.1 mw {
393 1.1 mw register struct siop_softc *dev = &siop_softc[ac->amiga_unit];
394 1.1 mw
395 1.1 mw #ifdef DEBUG
396 1.1 mw if (siop_debug)
397 1.1 mw printf ("zeusscsiinit: addr %x unit %d scripts %x ds %x\n",
398 1.1 mw ac->amiga_addr, ac->amiga_unit, scripts, &dev->sc_ds);
399 1.1 mw #endif
400 1.1 mw if ((int) scripts & 3)
401 1.1 mw panic ("zeusscsiinit: scripts not on a longword boundary");
402 1.1 mw if ((long)&dev->sc_ds & 3)
403 1.1 mw panic("zeusscsiinit: data storage alignment error\n");
404 1.1 mw if (! ac->amiga_addr)
405 1.1 mw return 0;
406 1.1 mw
407 1.1 mw if (initialized[ac->amiga_unit])
408 1.1 mw return 0;
409 1.1 mw
410 1.1 mw initialized[ac->amiga_unit] = 1;
411 1.1 mw
412 1.1 mw /* advance ac->amiga_addr to point to the real siop-registers */
413 1.1 mw ac->amiga_addr = (caddr_t) ((int)ac->amiga_addr + 0x4000);
414 1.1 mw dev->sc_clock_freq = 0xc0;
415 1.1 mw
416 1.1 mw /* hardwired IPL */
417 1.1 mw ac->amiga_ipl = 6;
418 1.1 mw dev->sc_ac = ac;
419 1.1 mw dev->sc_dq.dq_driver = &zeusscsidriver;
420 1.1 mw dev->sc_sq.dq_forw = dev->sc_sq.dq_back = &dev->sc_sq;
421 1.1 mw siopreset (ac->amiga_unit);
422 1.1 mw
423 1.1 mw /* For the ZEUS SCSI, both IPL6 and IPL2 interrupts have to be
424 1.1 mw enabled. The ZEUS SCSI generates IPL6 interrupts, which are
425 1.1 mw not blocked by splbio(). The ZEUS interrupt handler saves the
426 1.1 mw siop interrupt status information in siop_softc and sets the
427 1.1 mw PORTS interrupt to process the interrupt at IPL2.
428 1.1 mw
429 1.1 mw make sure IPL2 interrupts are delivered to the cpu when siopintr6
430 1.1 mw generates some. Note that this does not yet enable siop-interrupts,
431 1.1 mw this is handled in siopgo, which selectively enables interrupts only
432 1.1 mw while DMA requests are pending.
433 1.1 mw
434 1.1 mw Note that enabling PORTS interrupts also enables keyboard interrupts
435 1.1 mw as soon as the corresponding int-enable bit in CIA-A is set. */
436 1.1 mw
437 1.1 mw #if 0 /* EXTER interrupts are enabled in the clock initialization */
438 1.1 mw custom.intreq = INTF_EXTER;
439 1.1 mw custom.intena = INTF_SETCLR | INTF_EXTER;
440 1.1 mw #endif
441 1.1 mw custom.intreq = INTF_PORTS;
442 1.1 mw custom.intena = INTF_SETCLR | INTF_PORTS;
443 1.1 mw return(1);
444 1.1 mw }
445 1.1 mw #endif
446 1.1 mw
447 1.1 mw #if NMAGNUMSCSI > 0
448 1.1 mw int
449 1.1 mw magnumscsiinit(ac)
450 1.1 mw register struct amiga_ctlr *ac;
451 1.1 mw {
452 1.1 mw register struct siop_softc *dev = &siop_softc[ac->amiga_unit];
453 1.1 mw
454 1.1 mw #ifdef DEBUG
455 1.1 mw if (siop_debug)
456 1.1 mw printf ("magnumscsiinit: addr %x unit %d scripts %x ds %x\n",
457 1.1 mw ac->amiga_addr, ac->amiga_unit, scripts, &dev->sc_ds);
458 1.1 mw #endif
459 1.1 mw if ((int) scripts & 3)
460 1.1 mw panic ("magnumscsiinit: scripts not on a longword boundary");
461 1.1 mw if ((long)&dev->sc_ds & 3)
462 1.1 mw panic("magnumscsiinit: data storage alignment error\n");
463 1.1 mw if (! ac->amiga_addr)
464 1.1 mw return 0;
465 1.1 mw
466 1.1 mw if (initialized[ac->amiga_unit])
467 1.1 mw return 0;
468 1.1 mw
469 1.1 mw initialized[ac->amiga_unit] = 1;
470 1.1 mw
471 1.1 mw /* advance ac->amiga_addr to point to the real siop-registers */
472 1.1 mw ac->amiga_addr = (caddr_t) ((int)ac->amiga_addr + 0x8000);
473 1.1 mw dev->sc_clock_freq = 0x40; /* DCNTL = 25.01->37.5MHZ / SCLK/1.5 */
474 1.1 mw
475 1.1 mw /* hardwired IPL */
476 1.1 mw ac->amiga_ipl = 2;
477 1.1 mw dev->sc_ac = ac;
478 1.1 mw dev->sc_dq.dq_driver = &magnumscsidriver;
479 1.1 mw dev->sc_sq.dq_forw = dev->sc_sq.dq_back = &dev->sc_sq;
480 1.1 mw siopreset (ac->amiga_unit);
481 1.1 mw
482 1.1 mw /* make sure IPL2 interrupts are delivered to the cpu when the siop
483 1.1 mw generates some. Note that this does not yet enable siop-interrupts,
484 1.1 mw this is handled in siopgo, which selectively enables interrupts only
485 1.1 mw while DMA requests are pending.
486 1.1 mw
487 1.1 mw Note that enabling PORTS interrupts also enables keyboard interrupts
488 1.1 mw as soon as the corresponding int-enable bit in CIA-A is set. */
489 1.1 mw
490 1.1 mw custom.intreq = INTF_PORTS;
491 1.1 mw custom.intena = INTF_SETCLR | INTF_PORTS;
492 1.1 mw return(1);
493 1.1 mw }
494 1.1 mw #endif
495 1.1 mw
496 1.1 mw
497 1.1 mw void
498 1.1 mw siopreset(unit)
499 1.1 mw register int unit;
500 1.1 mw {
501 1.1 mw register struct siop_softc *dev = &siop_softc[unit];
502 1.1 mw volatile register siop_regmap_t *regs =
503 1.1 mw (siop_regmap_t *)dev->sc_ac->amiga_addr;
504 1.1 mw u_int i, s;
505 1.1 mw u_char my_id, csr;
506 1.1 mw
507 1.1 mw if (dev->sc_flags & SIOP_ALIVE)
508 1.1 mw siopabort(dev, regs, "reset");
509 1.1 mw
510 1.1 mw printf("siop%d: ", unit);
511 1.1 mw
512 1.1 mw s = splbio();
513 1.1 mw my_id = 7;
514 1.1 mw
515 1.1 mw /*
516 1.1 mw * Reset the chip
517 1.1 mw * XXX - is this really needed?
518 1.1 mw */
519 1.1 mw regs->siop_sien &= ~SIOP_SIEN_RST;
520 1.1 mw regs->siop_scntl1 |= SIOP_SCNTL1_RST;
521 1.1 mw for (i = 0; i < 1000; ++i)
522 1.1 mw ;
523 1.1 mw regs->siop_scntl1 &= ~SIOP_SCNTL1_RST;
524 1.1 mw regs->siop_sien |= SIOP_SIEN_RST;
525 1.1 mw
526 1.1 mw /*
527 1.1 mw * Set up various chip parameters
528 1.1 mw */
529 1.1 mw regs->siop_istat = 0x40;
530 1.1 mw for (i = 0; i < 1000; ++i)
531 1.1 mw ;
532 1.1 mw regs->siop_istat = 0x00;
533 1.1 mw regs->siop_scntl0 = SIOP_ARB_FULL | SIOP_SCNTL0_EPC | SIOP_SCNTL0_EPG;
534 1.1 mw regs->siop_dcntl = dev->sc_clock_freq;
535 1.1 mw regs->siop_dmode = 0x80;
536 1.1 mw regs->siop_sien = 0x00; /* don't enable interrupts yet */
537 1.1 mw regs->siop_dien = 0x00; /* don't enable interrupts yet */
538 1.1 mw regs->siop_scid = 1 << my_id;
539 1.1 mw regs->siop_dwt = 0x00;
540 1.1 mw regs->siop_ctest0 |= 0x20; /* Enable Active Negation ?? */
541 1.1 mw regs->siop_ctest7 |= 0x02; /* TT1 */
542 1.1 mw
543 1.1 mw /* will need to re-negotiate sync xfers */
544 1.1 mw bzero(&dev->sc_sync, sizeof (dev->sc_sync));
545 1.1 mw
546 1.1 mw splx (s);
547 1.1 mw
548 1.1 mw printf("siop id %d\n", my_id);
549 1.1 mw dev->sc_flags |= SIOP_ALIVE;
550 1.1 mw dev->sc_flags &= ~(SIOP_SELECTED | SIOP_DMA);
551 1.1 mw }
552 1.1 mw
553 1.1 mw /*
554 1.1 mw * Setup Data Storage for 53C710 and start SCRIPTS processing
555 1.1 mw */
556 1.1 mw
557 1.1 mw static void
558 1.1 mw siop_setup (dev, target, cbuf, clen, buf, len)
559 1.1 mw struct siop_softc *dev;
560 1.1 mw int target;
561 1.1 mw u_char *cbuf;
562 1.1 mw int clen;
563 1.1 mw u_char *buf;
564 1.1 mw int len;
565 1.1 mw {
566 1.1 mw volatile register siop_regmap_t *regs =
567 1.1 mw (siop_regmap_t *)dev->sc_ac->amiga_addr;
568 1.1 mw int i;
569 1.1 mw int nchain;
570 1.1 mw int count, tcount;
571 1.1 mw char *addr, *dmaend;
572 1.1 mw
573 1.1 mw dev->sc_istat = 0;
574 1.1 mw dev->sc_lun = 0x80; /* XXX */
575 1.1 mw dev->sc_stat[0] = -1;
576 1.1 mw dev->sc_msg[0] = -1;
577 1.1 mw dev->sc_ds.scsi_addr = (0x10000 << target) | (dev->sc_sync[target].period << 8);
578 1.1 mw dev->sc_ds.idlen = 1;
579 1.1 mw dev->sc_ds.idbuf = (char *) kvtop(&dev->sc_lun);
580 1.1 mw dev->sc_ds.cmdlen = clen;
581 1.1 mw dev->sc_ds.cmdbuf = (char *) kvtop(cbuf);
582 1.1 mw dev->sc_ds.stslen = 1;
583 1.1 mw dev->sc_ds.stsbuf = (char *) kvtop(&dev->sc_stat[0]);
584 1.1 mw dev->sc_ds.msglen = 1;
585 1.1 mw dev->sc_ds.msgbuf = (char *) kvtop(&dev->sc_msg[0]);
586 1.1 mw dev->sc_ds.sdtrolen = 0;
587 1.1 mw dev->sc_ds.sdtrilen = 0;
588 1.1 mw dev->sc_ds.chain[0].datalen = len;
589 1.1 mw dev->sc_ds.chain[0].databuf = (char *) kvtop(buf);
590 1.1 mw
591 1.1 mw if (dev->sc_sync[target].state == SYNC_START) {
592 1.1 mw if (siop_inhibit_sync[dev->sc_ac->amiga_unit][target]) {
593 1.1 mw dev->sc_sync[target].state = SYNC_DONE;
594 1.1 mw dev->sc_sync[target].offset = 0;
595 1.1 mw dev->sc_sync[target].period = 0;
596 1.1 mw #ifdef DEBUG
597 1.1 mw if (siopsync_debug)
598 1.1 mw printf ("Forcing target %d asynchronous\n", target);
599 1.1 mw #endif
600 1.1 mw }
601 1.1 mw else {
602 1.1 mw dev->sc_msg[1] = MSG_IDENTIFY;
603 1.1 mw dev->sc_msg[2] = MSG_EXT_MESSAGE;
604 1.1 mw dev->sc_msg[3] = 3;
605 1.1 mw dev->sc_msg[4] = MSG_SYNC_REQ;
606 1.1 mw dev->sc_msg[5] = 100/4; /* min period = 100 nsec */
607 1.1 mw dev->sc_msg[6] = SIOP_MAX_OFFSET;
608 1.1 mw dev->sc_ds.sdtrolen = 6;
609 1.1 mw dev->sc_ds.sdtrilen = sizeof (dev->sc_msg) - 1;
610 1.1 mw dev->sc_ds.sdtrobuf = dev->sc_ds.sdtribuf = (char *) kvtop(dev->sc_msg + 1);
611 1.1 mw dev->sc_sync[target].state = SYNC_SENT;
612 1.1 mw #ifdef DEBUG
613 1.1 mw if (siopsync_debug)
614 1.1 mw printf ("Sending sync request to target %d\n", target);
615 1.1 mw #endif
616 1.1 mw }
617 1.1 mw }
618 1.1 mw
619 1.1 mw /*
620 1.1 mw * If length is > 1 page, check for consecutive physical pages
621 1.1 mw * Need to set up chaining if not
622 1.1 mw */
623 1.1 mw nchain = 0;
624 1.1 mw count = len;
625 1.1 mw addr = buf;
626 1.1 mw dmaend = NULL;
627 1.1 mw while (count > 0) {
628 1.1 mw dev->sc_ds.chain[nchain].databuf = (char *) kvtop (addr);
629 1.1 mw if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
630 1.1 mw tcount = count;
631 1.1 mw dev->sc_ds.chain[nchain].datalen = tcount;
632 1.1 mw addr += tcount;
633 1.1 mw count -= tcount;
634 1.1 mw if (dev->sc_ds.chain[nchain].databuf == dmaend) {
635 1.1 mw dmaend += dev->sc_ds.chain[nchain].datalen;
636 1.1 mw dev->sc_ds.chain[--nchain].datalen += tcount;
637 1.1 mw #ifdef DEBUG
638 1.1 mw ++siopdma_hits;
639 1.1 mw #endif
640 1.1 mw }
641 1.1 mw else {
642 1.1 mw dmaend = dev->sc_ds.chain[nchain].databuf +
643 1.1 mw dev->sc_ds.chain[nchain].datalen;
644 1.1 mw dev->sc_ds.chain[nchain].datalen = tcount;
645 1.1 mw #ifdef DEBUG
646 1.1 mw ++siopdma_misses;
647 1.1 mw #endif
648 1.1 mw }
649 1.1 mw ++nchain;
650 1.1 mw }
651 1.1 mw #ifdef DEBUG
652 1.1 mw if (nchain != 1 && len != 0 && siop_debug & 3) {
653 1.1 mw printf ("DMA chaining set: %d\n", nchain);
654 1.1 mw for (i = 0; i < nchain; ++i) {
655 1.1 mw printf (" [%d] %8x %4x\n", i, dev->sc_ds.chain[i].databuf,
656 1.1 mw dev->sc_ds.chain[i].datalen);
657 1.1 mw }
658 1.1 mw }
659 1.1 mw #endif
660 1.1 mw
661 1.1 mw regs->siop_sbcl = dev->sc_sync[target].offset;
662 1.1 mw if (dev->sc_ds.sdtrolen)
663 1.1 mw regs->siop_scratch = regs->siop_scratch | 0x100;
664 1.1 mw else
665 1.1 mw regs->siop_scratch = regs->siop_scratch & ~0xff00;
666 1.1 mw regs->siop_dsa = (long) kvtop(&dev->sc_ds);
667 1.1 mw DCIS(); /* push data cache */
668 1.1 mw regs->siop_dsp = (long) kvtop(scripts);
669 1.1 mw }
670 1.1 mw
671 1.1 mw /*
672 1.1 mw * Process a DMA or SCSI interrupt from the 53C710 SIOP
673 1.1 mw */
674 1.1 mw
675 1.1 mw static int
676 1.1 mw siop_checkintr(dev, istat, dstat, sstat0, status)
677 1.1 mw struct siop_softc *dev;
678 1.1 mw u_char istat;
679 1.1 mw u_char dstat;
680 1.1 mw u_char sstat0;
681 1.1 mw int *status;
682 1.1 mw {
683 1.1 mw volatile register siop_regmap_t *regs =
684 1.1 mw (siop_regmap_t *)dev->sc_ac->amiga_addr;
685 1.1 mw int target;
686 1.1 mw
687 1.1 mw regs->siop_ctest8 |= 0x04;
688 1.1 mw while ((regs->siop_ctest1 & SIOP_CTEST1_FMT) == 0)
689 1.1 mw ;
690 1.1 mw regs->siop_ctest8 &= ~0x04;
691 1.1 mw #ifdef DEBUG
692 1.1 mw if (siop_debug & 1) {
693 1.1 mw DCIAS(kvtop(&dev->sc_stat)); /* XXX */
694 1.1 mw printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
695 1.1 mw istat, dstat, sstat0, regs->siop_dsps, regs->siop_sbcl, dev->sc_stat[0], dev->sc_msg[0]);
696 1.1 mw }
697 1.1 mw #endif
698 1.1 mw if (dstat & SIOP_DSTAT_SIR && (regs->siop_dsps == 0xff00 ||
699 1.1 mw regs->siop_dsps == 0xfffc)) {
700 1.1 mw /* Normal completion status, or check condition */
701 1.1 mw if (regs->siop_dsa != (long) kvtop(&dev->sc_ds)) {
702 1.1 mw printf ("siop: invalid dsa: %x %x\n", regs->siop_dsa,
703 1.1 mw kvtop(&dev->sc_ds));
704 1.1 mw panic("*** siop DSA invalid ***");
705 1.1 mw }
706 1.1 mw target = dev->sc_slave;
707 1.1 mw if (dev->sc_sync[target].state == SYNC_SENT) {
708 1.1 mw #ifdef DEBUG
709 1.1 mw if (siopsync_debug)
710 1.1 mw printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
711 1.1 mw dev->sc_msg[1], dev->sc_msg[2], dev->sc_msg[3],
712 1.1 mw dev->sc_msg[4], dev->sc_msg[5], dev->sc_msg[6]);
713 1.1 mw #endif
714 1.1 mw dev->sc_sync[target].state = SYNC_DONE;
715 1.1 mw dev->sc_sync[target].period = 0;
716 1.1 mw dev->sc_sync[target].offset = 0;
717 1.1 mw if (dev->sc_msg[1] == MSG_EXT_MESSAGE &&
718 1.1 mw dev->sc_msg[2] == 3 &&
719 1.1 mw dev->sc_msg[3] == MSG_SYNC_REQ) {
720 1.1 mw printf ("siop%d: target %d now synchronous, period=%dns, offset=%d\n",
721 1.1 mw dev->sc_ac->amiga_unit, target,
722 1.1 mw dev->sc_msg[4] * 4, dev->sc_msg[5]);
723 1.1 mw scsi_period_to_siop (dev, target);
724 1.1 mw }
725 1.1 mw }
726 1.1 mw DCIAS(kvtop(&dev->sc_stat)); /* XXX */
727 1.1 mw *status = dev->sc_stat[0];
728 1.1 mw return 1;
729 1.1 mw }
730 1.1 mw if (sstat0 & SIOP_SSTAT0_M_A) { /* Phase mismatch */
731 1.1 mw #ifdef DEBUG
732 1.1 mw if (siop_debug & 9)
733 1.1 mw printf ("Phase mismatch: %x dsp +%x\n", regs->siop_sbcl,
734 1.1 mw regs->siop_dsp - kvtop(scripts));
735 1.1 mw #endif
736 1.1 mw if ((regs->siop_sbcl & SIOP_REQ) == 0)
737 1.1 mw printf ("Phase mismatch: REQ not asserted! %02x\n",
738 1.1 mw regs->siop_sbcl);
739 1.1 mw switch (regs->siop_sbcl & 7) {
740 1.1 mw /*
741 1.1 mw * For data out and data in phase, check for DMA chaining
742 1.1 mw */
743 1.1 mw
744 1.1 mw /*
745 1.1 mw * for message in, check for possible reject for sync request
746 1.1 mw */
747 1.1 mw case 0:
748 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_dataout;
749 1.1 mw break;
750 1.1 mw case 1:
751 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_datain;
752 1.1 mw break;
753 1.1 mw case 2:
754 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_cmd;
755 1.1 mw break;
756 1.1 mw case 3:
757 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_status;
758 1.1 mw break;
759 1.1 mw case 6:
760 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_msgout;
761 1.1 mw break;
762 1.1 mw case 7:
763 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_msgin;
764 1.1 mw break;
765 1.1 mw default:
766 1.1 mw goto bad_phase;
767 1.1 mw }
768 1.1 mw return 0;
769 1.1 mw }
770 1.1 mw if (sstat0 & SIOP_SSTAT0_STO) { /* Select timed out */
771 1.1 mw *status = -1;
772 1.1 mw return 1;
773 1.1 mw }
774 1.1 mw if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff05 &&
775 1.1 mw (regs->siop_sbcl & (SIOP_MSG | SIOP_CD)) == 0) {
776 1.1 mw printf ("DMA chaining failed\n");
777 1.1 mw siopreset (dev->sc_ac->amiga_unit);
778 1.1 mw *status = -1;
779 1.1 mw return 1;
780 1.1 mw }
781 1.1 mw if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff27) {
782 1.1 mw #ifdef DEBUG
783 1.1 mw if (siop_debug & 3)
784 1.1 mw printf ("DMA chaining completed: dsa %x dnad %x addr %x\n",
785 1.1 mw regs->siop_dsa, regs->siop_dnad, regs->siop_addr);
786 1.1 mw #endif
787 1.1 mw regs->siop_dsa = kvtop (&dev->sc_ds);
788 1.1 mw regs->siop_dsp = kvtop (scripts) + Ent_status;
789 1.1 mw return 0;
790 1.1 mw }
791 1.1 mw target = dev->sc_slave;
792 1.1 mw if (dstat & SIOP_DSTAT_SIR && regs->siop_dsps == 0xff26 &&
793 1.1 mw dev->sc_msg[0] == MSG_REJECT && dev->sc_sync[target].state == SYNC_SENT) {
794 1.1 mw dev->sc_sync[target].state = SYNC_DONE;
795 1.1 mw dev->sc_sync[target].period = 0;
796 1.1 mw dev->sc_sync[target].offset = 0;
797 1.1 mw dev->sc_ds.sdtrolen = 0;
798 1.1 mw dev->sc_ds.sdtrilen = 0;
799 1.1 mw #ifdef DEBUG
800 1.1 mw if (siopsync_debug || 1)
801 1.1 mw printf ("target %d rejected sync, going asynchronous\n", target);
802 1.1 mw #endif
803 1.1 mw siop_inhibit_sync[dev->sc_ac->amiga_unit][target] = -1;
804 1.1 mw if ((regs->siop_sbcl & 7) == 6) {
805 1.1 mw regs->siop_dsp = kvtop(scripts) + Ent_msgout;
806 1.1 mw return (0);
807 1.1 mw }
808 1.1 mw }
809 1.1 mw if (sstat0 == 0 && dstat & SIOP_DSTAT_SIR) {
810 1.1 mw DCIAS(kvtop(&dev->sc_stat));
811 1.1 mw printf ("SIOP interrupt: %x sts %x msg %x sbcl %x\n",
812 1.1 mw regs->siop_dsps, dev->sc_stat[0], dev->sc_msg[0],
813 1.1 mw regs->siop_sbcl);
814 1.1 mw siopreset (dev->sc_ac->amiga_unit);
815 1.1 mw *status = -1;
816 1.1 mw return 1;
817 1.1 mw }
818 1.1 mw bad_phase:
819 1.1 mw /*
820 1.1 mw * temporary panic for unhandled conditions
821 1.1 mw * displays various things about the 53C710 status and registers
822 1.1 mw * then panics
823 1.1 mw */
824 1.1 mw printf ("siopchkintr: target %x ds %x\n", target, &dev->sc_ds);
825 1.1 mw printf ("scripts %x ds %x regs %x dsp %x dcmd %x\n", kvtop(scripts),
826 1.1 mw kvtop(&dev->sc_ds), kvtop(regs), regs->siop_dsp, *((long *)®s->siop_dcmd));
827 1.1 mw printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x dsa %x sbcl %x sts %x msg %x\n",
828 1.1 mw istat, dstat, sstat0, regs->siop_dsps, regs->siop_dsa, regs->siop_sbcl,
829 1.1 mw dev->sc_stat[0], dev->sc_msg[0]);
830 1.1 mw panic("siopchkintr: **** temp ****");
831 1.1 mw }
832 1.1 mw
833 1.1 mw /*
834 1.1 mw * SCSI 'immediate' command: issue a command to some SCSI device
835 1.1 mw * and get back an 'immediate' response (i.e., do programmed xfer
836 1.1 mw * to get the response data). 'cbuf' is a buffer containing a scsi
837 1.1 mw * command of length clen bytes. 'buf' is a buffer of length 'len'
838 1.1 mw * bytes for data. The transfer direction is determined by the device
839 1.1 mw * (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
840 1.1 mw * command must supply no data. 'xferphase' is the bus phase the
841 1.1 mw * caller expects to happen after the command is issued. It should
842 1.1 mw * be one of DATA_IN_PHASE, DATA_OUT_PHASE or STATUS_PHASE.
843 1.1 mw *
844 1.1 mw * XXX - 53C710 will use DMA, but no interrupts (it's a heck of a
845 1.1 mw * lot easier to do than to use programmed I/O).
846 1.1 mw *
847 1.1 mw */
848 1.1 mw static int
849 1.1 mw siopicmd(dev, target, cbuf, clen, buf, len)
850 1.1 mw struct siop_softc *dev;
851 1.1 mw int target;
852 1.1 mw u_char *cbuf;
853 1.1 mw int clen;
854 1.1 mw u_char *buf;
855 1.1 mw int len;
856 1.1 mw {
857 1.1 mw volatile register siop_regmap_t *regs =
858 1.1 mw (siop_regmap_t *)dev->sc_ac->amiga_addr;
859 1.1 mw int i;
860 1.1 mw int status;
861 1.1 mw u_char istat;
862 1.1 mw u_char dstat;
863 1.1 mw u_char sstat0;
864 1.1 mw
865 1.1 mw if (dev->sc_flags & SIOP_SELECTED) {
866 1.1 mw printf ("siopicmd%d: bus busy\n", target);
867 1.1 mw return -1;
868 1.1 mw }
869 1.1 mw regs->siop_sien = 0x00; /* disable SCSI and DMA interrupts */
870 1.1 mw regs->siop_dien = 0x00;
871 1.1 mw dev->sc_flags |= SIOP_SELECTED;
872 1.1 mw dev->sc_slave = target;
873 1.1 mw #ifdef DEBUG
874 1.1 mw if (siop_debug & 1)
875 1.1 mw printf ("siopicmd: target %x cmd %02x ds %x\n", target,
876 1.1 mw cbuf[0], &dev->sc_ds);
877 1.1 mw #endif
878 1.1 mw siop_setup (dev, target, cbuf, clen, buf, len);
879 1.1 mw
880 1.1 mw for (;;) {
881 1.1 mw /* use cmd_wait values? */
882 1.1 mw i = siop_cmd_wait << 1;
883 1.1 mw while (((istat = regs->siop_istat) &
884 1.1 mw (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
885 1.1 mw if (--i <= 0) {
886 1.1 mw printf ("waiting: tgt %d cmd %02x sbcl %02x dsp %x (+%x) dcmd %x ds %x\n",
887 1.1 mw target, cbuf[0],
888 1.1 mw regs->siop_sbcl, regs->siop_dsp,
889 1.1 mw regs->siop_dsp - kvtop(scripts),
890 1.1 mw *((long *)®s->siop_dcmd), &dev->sc_ds);
891 1.1 mw i = siop_cmd_wait << 2;
892 1.1 mw }
893 1.1 mw DELAY(1);
894 1.1 mw }
895 1.1 mw dstat = regs->siop_dstat;
896 1.1 mw sstat0 = regs->siop_sstat0;
897 1.1 mw #ifdef DEBUG
898 1.1 mw if (siop_debug & 1) {
899 1.1 mw DCIAS(kvtop(&dev->sc_stat)); /* XXX should just invalidate dev->sc_stat */
900 1.1 mw printf ("siopicmd: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
901 1.1 mw istat, dstat, sstat0, regs->siop_dsps, regs->siop_sbcl,
902 1.1 mw dev->sc_stat[0], dev->sc_msg[0]);
903 1.1 mw }
904 1.1 mw #endif
905 1.1 mw if (siop_checkintr(dev, istat, dstat, sstat0, &status)) {
906 1.1 mw dev->sc_flags &= ~SIOP_SELECTED;
907 1.1 mw return (status);
908 1.1 mw }
909 1.1 mw }
910 1.1 mw }
911 1.1 mw
912 1.1 mw int
913 1.1 mw siop_test_unit_rdy(ctlr, slave, unit)
914 1.1 mw int ctlr, slave, unit;
915 1.1 mw {
916 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
917 1.1 mw static struct scsi_cdb6 cdb = { CMD_TEST_UNIT_READY };
918 1.1 mw
919 1.1 mw cdb.lun = unit;
920 1.1 mw return (siopicmd(dev, slave, (u_char *)&cdb, sizeof(cdb), (u_char *)0, 0));
921 1.1 mw }
922 1.1 mw
923 1.1 mw int
924 1.1 mw siop_start_stop_unit (ctlr, slave, unit, start)
925 1.1 mw int ctlr, slave, unit;
926 1.1 mw {
927 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
928 1.1 mw static struct scsi_cdb6 cdb = { CMD_LOADUNLOAD };
929 1.1 mw
930 1.1 mw cdb.lun = unit;
931 1.1 mw /* we don't set the immediate bit, so we wait for the
932 1.1 mw command to succeed.
933 1.1 mw We also don't touch the LoEj bit, which is primarily meant
934 1.1 mw for floppies. */
935 1.1 mw cdb.len = start & 0x01;
936 1.1 mw return (siopicmd(dev, slave, (u_char *)&cdb, sizeof(cdb), (u_char *)0, 0));
937 1.1 mw }
938 1.1 mw
939 1.1 mw
940 1.1 mw int
941 1.1 mw siop_request_sense(ctlr, slave, unit, buf, len)
942 1.1 mw int ctlr, slave, unit;
943 1.1 mw u_char *buf;
944 1.1 mw unsigned len;
945 1.1 mw {
946 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
947 1.1 mw static struct scsi_cdb6 cdb = { CMD_REQUEST_SENSE };
948 1.1 mw
949 1.1 mw cdb.lun = unit;
950 1.1 mw cdb.len = len;
951 1.1 mw return (siopicmd(dev, slave, (u_char *)&cdb, sizeof(cdb), buf, len));
952 1.1 mw }
953 1.1 mw
954 1.1 mw int
955 1.1 mw siop_immed_command(ctlr, slave, unit, cdb, buf, len, rd)
956 1.1 mw int ctlr, slave, unit;
957 1.1 mw struct scsi_fmt_cdb *cdb;
958 1.1 mw u_char *buf;
959 1.1 mw unsigned len;
960 1.1 mw {
961 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
962 1.1 mw
963 1.1 mw cdb->cdb[1] |= (unit << 5);
964 1.1 mw return (siopicmd(dev, slave, (u_char *) cdb->cdb, cdb->len, buf, len));
965 1.1 mw }
966 1.1 mw
967 1.1 mw /*
968 1.1 mw * The following routines are test-and-transfer i/o versions of read/write
969 1.1 mw * for things like reading disk labels and writing core dumps. The
970 1.1 mw * routine scsigo should be used for normal data transfers, NOT these
971 1.1 mw * routines.
972 1.1 mw */
973 1.1 mw int
974 1.1 mw siop_tt_read(ctlr, slave, unit, buf, len, blk, bshift)
975 1.1 mw int ctlr, slave, unit;
976 1.1 mw u_char *buf;
977 1.1 mw u_int len;
978 1.1 mw daddr_t blk;
979 1.1 mw int bshift;
980 1.1 mw {
981 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
982 1.1 mw struct scsi_cdb10 cdb;
983 1.1 mw int stat;
984 1.1 mw int old_wait = siop_data_wait;
985 1.1 mw
986 1.1 mw #ifdef DEBUG
987 1.1 mw if (siop_debug & 1)
988 1.1 mw printf ("siop%d: tt_read blk %x\n", slave, blk);
989 1.1 mw #endif
990 1.1 mw siop_data_wait = 300000;
991 1.1 mw bzero(&cdb, sizeof(cdb));
992 1.1 mw cdb.cmd = CMD_READ_EXT;
993 1.1 mw cdb.lun = unit;
994 1.1 mw blk >>= bshift;
995 1.1 mw cdb.lbah = blk >> 24;
996 1.1 mw cdb.lbahm = blk >> 16;
997 1.1 mw cdb.lbalm = blk >> 8;
998 1.1 mw cdb.lbal = blk;
999 1.1 mw cdb.lenh = len >> (8 + DEV_BSHIFT + bshift);
1000 1.1 mw cdb.lenl = len >> (DEV_BSHIFT + bshift);
1001 1.1 mw stat = siopicmd(dev, slave, (u_char *) &cdb, sizeof(cdb), buf, len);
1002 1.1 mw siop_data_wait = old_wait;
1003 1.1 mw return (stat);
1004 1.1 mw }
1005 1.1 mw
1006 1.1 mw int
1007 1.1 mw siop_tt_write(ctlr, slave, unit, buf, len, blk, bshift)
1008 1.1 mw int ctlr, slave, unit;
1009 1.1 mw u_char *buf;
1010 1.1 mw u_int len;
1011 1.1 mw daddr_t blk;
1012 1.1 mw int bshift;
1013 1.1 mw {
1014 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
1015 1.1 mw struct scsi_cdb10 cdb;
1016 1.1 mw int stat;
1017 1.1 mw int old_wait = siop_data_wait;
1018 1.1 mw
1019 1.1 mw #ifdef DEBUG
1020 1.1 mw if (siop_debug | 1) /* XXX */
1021 1.1 mw printf ("siop%d: tt_write\n", slave);
1022 1.1 mw if (blk < 604)
1023 1.1 mw panic("siop_tt_write: writing block < 604");
1024 1.1 mw #endif
1025 1.1 mw siop_data_wait = 300000;
1026 1.1 mw
1027 1.1 mw bzero(&cdb, sizeof(cdb));
1028 1.1 mw cdb.cmd = CMD_WRITE_EXT;
1029 1.1 mw cdb.lun = unit;
1030 1.1 mw blk >>= bshift;
1031 1.1 mw cdb.lbah = blk >> 24;
1032 1.1 mw cdb.lbahm = blk >> 16;
1033 1.1 mw cdb.lbalm = blk >> 8;
1034 1.1 mw cdb.lbal = blk;
1035 1.1 mw cdb.lenh = len >> (8 + DEV_BSHIFT + bshift);
1036 1.1 mw cdb.lenl = len >> (DEV_BSHIFT + bshift);
1037 1.1 mw stat = siopicmd(dev, slave, (u_char *) &cdb, sizeof(cdb), buf, len);
1038 1.1 mw siop_data_wait = old_wait;
1039 1.1 mw return (stat);
1040 1.1 mw }
1041 1.1 mw
1042 1.1 mw int
1043 1.1 mw siopreq(dq)
1044 1.1 mw register struct devqueue *dq;
1045 1.1 mw {
1046 1.1 mw register struct devqueue *hq;
1047 1.1 mw
1048 1.1 mw hq = &siop_softc[dq->dq_ctlr].sc_sq;
1049 1.1 mw insque(dq, hq->dq_back);
1050 1.1 mw #ifdef DEBUG
1051 1.1 mw if (siop_debug & 1)
1052 1.1 mw printf ("siopreq %d ", dq->dq_back == hq ? 1 : 0);
1053 1.1 mw #endif
1054 1.1 mw if (dq->dq_back == hq)
1055 1.1 mw return(1);
1056 1.1 mw return(0);
1057 1.1 mw }
1058 1.1 mw
1059 1.1 mw int
1060 1.1 mw siopustart (int unit)
1061 1.1 mw {
1062 1.1 mw register struct siop_softc *dev = &siop_softc[unit];
1063 1.1 mw
1064 1.1 mw #ifdef DEBUG
1065 1.1 mw if (siop_debug & 1)
1066 1.1 mw printf ("siop%d: ustart ", unit);
1067 1.1 mw #endif
1068 1.1 mw return(1);
1069 1.1 mw }
1070 1.1 mw
1071 1.1 mw void
1072 1.1 mw siopstart (int unit)
1073 1.1 mw {
1074 1.1 mw register struct devqueue *dq;
1075 1.1 mw
1076 1.1 mw #ifdef DEBUG
1077 1.1 mw if (siop_debug & 1)
1078 1.1 mw printf ("siop%d: start ", unit);
1079 1.1 mw #endif
1080 1.1 mw dq = siop_softc[unit].sc_sq.dq_forw;
1081 1.1 mw (dq->dq_driver->d_go)(dq->dq_unit);
1082 1.1 mw }
1083 1.1 mw
1084 1.1 mw int
1085 1.1 mw siopgo(ctlr, slave, unit, bp, cdb, pad)
1086 1.1 mw int ctlr, slave, unit;
1087 1.1 mw struct buf *bp;
1088 1.1 mw struct scsi_fmt_cdb *cdb;
1089 1.1 mw int pad;
1090 1.1 mw {
1091 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
1092 1.1 mw volatile register siop_regmap_t *regs =
1093 1.1 mw (siop_regmap_t *)dev->sc_ac->amiga_addr;
1094 1.1 mw int i;
1095 1.1 mw int nchain;
1096 1.1 mw int count, tcount;
1097 1.1 mw char *addr, *dmaend;
1098 1.1 mw
1099 1.1 mw #ifdef DEBUG
1100 1.1 mw if (siop_debug & 1)
1101 1.1 mw printf ("siop%d: go ", slave);
1102 1.1 mw if ((cdb->cdb[1] & 1) == 0 &&
1103 1.1 mw ((cdb->cdb[0] == CMD_WRITE && cdb->cdb[2] == 0 && cdb->cdb[3] == 0) ||
1104 1.1 mw (cdb->cdb[0] == CMD_WRITE_EXT && cdb->cdb[2] == 0 && cdb->cdb[3] == 0
1105 1.1 mw && cdb->cdb[4] == 0)))
1106 1.1 mw panic ("siopgo: attempted write to block < 0x100");
1107 1.1 mw #endif
1108 1.1 mw cdb->cdb[1] |= unit << 5;
1109 1.1 mw
1110 1.1 mw if (dev->sc_flags & SIOP_SELECTED) {
1111 1.1 mw printf ("siopgo%d: bus busy\n", slave);
1112 1.1 mw return 1;
1113 1.1 mw }
1114 1.1 mw
1115 1.1 mw if (siop_no_dma) {
1116 1.1 mw register struct devqueue *dq;
1117 1.1 mw
1118 1.1 mw /* in this case do the transfer with programmed I/O :-( This is
1119 1.1 mw probably still faster than doing the transfer with DMA into a
1120 1.1 mw buffer and copying it later to its final destination, comments? */
1121 1.1 mw /* XXX - 53C710 uses DMA, but non-interrupt */
1122 1.1 mw siopicmd (dev, slave, (u_char *) cdb->cdb, cdb->len,
1123 1.1 mw bp->b_un.b_addr, bp->b_bcount);
1124 1.1 mw
1125 1.1 mw dq = dev->sc_sq.dq_forw;
1126 1.1 mw (dq->dq_driver->d_intr)(dq->dq_unit, dev->sc_stat[0]);
1127 1.1 mw return dev->sc_stat[0];
1128 1.1 mw }
1129 1.1 mw
1130 1.1 mw dev->sc_flags |= SIOP_SELECTED | SIOP_DMA;
1131 1.1 mw dev->sc_slave = slave;
1132 1.1 mw /* enable SCSI and DMA interrupts */
1133 1.1 mw regs->siop_sien = SIOP_SIEN_M_A | SIOP_SIEN_STO | SIOP_SIEN_SEL | SIOP_SIEN_SGE |
1134 1.1 mw SIOP_SIEN_UDC | SIOP_SIEN_RST | SIOP_SIEN_PAR;
1135 1.1 mw regs->siop_dien = 0x20 | SIOP_DIEN_ABRT | SIOP_DIEN_SIR | SIOP_DIEN_WTD |
1136 1.1 mw SIOP_DIEN_OPC;
1137 1.1 mw #ifdef DEBUG
1138 1.1 mw if (siop_debug & 1)
1139 1.1 mw printf ("siopgo: target %x cmd %02x ds %x\n", slave, cdb->cdb[0], &dev->sc_ds);
1140 1.1 mw #endif
1141 1.1 mw
1142 1.1 mw siop_setup(dev, slave, cdb->cdb, cdb->len, bp->b_un.b_addr, bp->b_bcount);
1143 1.1 mw
1144 1.1 mw return (0);
1145 1.1 mw }
1146 1.1 mw
1147 1.1 mw void
1148 1.1 mw siopdone (int unit)
1149 1.1 mw {
1150 1.1 mw volatile register siop_regmap_t *regs =
1151 1.1 mw (siop_regmap_t *)siop_softc[unit].sc_ac->amiga_addr;
1152 1.1 mw
1153 1.1 mw #ifdef DEBUG
1154 1.1 mw if (siop_debug & 1)
1155 1.1 mw printf("siop%d: done called!\n", unit);
1156 1.1 mw #endif
1157 1.1 mw }
1158 1.1 mw
1159 1.1 mw /*
1160 1.1 mw * Level 6 interrupt processing for the Progressive Peripherals Inc
1161 1.1 mw * Zeus SCSI. Because the level 6 interrupt is above splbio, the
1162 1.1 mw * interrupt status is saved and the INTF_PORTS interrupt is set.
1163 1.1 mw * This way, the actual processing of the interrupt can be deferred
1164 1.1 mw * until splbio is unblocked
1165 1.1 mw */
1166 1.1 mw
1167 1.1 mw #if NZEUSSCSI > 0
1168 1.1 mw int
1169 1.1 mw siopintr6 ()
1170 1.1 mw {
1171 1.1 mw register struct siop_softc *dev;
1172 1.1 mw volatile register siop_regmap_t *regs;
1173 1.1 mw register u_char istat;
1174 1.1 mw int unit;
1175 1.1 mw int found = 0;
1176 1.1 mw
1177 1.1 mw for (unit = 0, dev = siop_softc; unit < NSIOP; unit++, dev++) {
1178 1.1 mw if (!initialized[dev->sc_ac->amiga_unit])
1179 1.1 mw continue;
1180 1.1 mw if (dev->sc_ac->amiga_ipl != 6)
1181 1.1 mw continue;
1182 1.1 mw regs = (siop_regmap_t *)dev->sc_ac->amiga_addr;
1183 1.1 mw istat = regs->siop_istat;
1184 1.1 mw if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
1185 1.1 mw continue;
1186 1.1 mw if ((dev->sc_flags & (SIOP_DMA | SIOP_SELECTED)) == SIOP_SELECTED)
1187 1.1 mw continue; /* doing non-interrupt I/O */
1188 1.1 mw found++;
1189 1.1 mw dev->sc_istat = istat;
1190 1.1 mw dev->sc_dstat = regs->siop_dstat;
1191 1.1 mw dev->sc_sstat0 = regs->siop_sstat0;
1192 1.1 mw custom.intreq = INTF_EXTER;
1193 1.1 mw custom.intreq = INTF_SETCLR | INTF_PORTS;
1194 1.1 mw }
1195 1.1 mw return (found);
1196 1.1 mw }
1197 1.1 mw #endif
1198 1.1 mw
1199 1.1 mw /*
1200 1.1 mw * Check for 53C710 interrupts
1201 1.1 mw */
1202 1.1 mw
1203 1.1 mw int
1204 1.1 mw siopintr2 ()
1205 1.1 mw {
1206 1.1 mw register struct siop_softc *dev;
1207 1.1 mw volatile register siop_regmap_t *regs;
1208 1.1 mw register u_char istat, dstat, sstat0;
1209 1.1 mw register struct devqueue *dq;
1210 1.1 mw int unit;
1211 1.1 mw int status;
1212 1.1 mw int found = 0;
1213 1.1 mw
1214 1.1 mw for (unit = 0, dev = siop_softc; unit < NSIOP; unit++, dev++) {
1215 1.1 mw if (!initialized[dev->sc_ac->amiga_unit])
1216 1.1 mw continue;
1217 1.1 mw regs = (siop_regmap_t *)dev->sc_ac->amiga_addr;
1218 1.1 mw if (dev->sc_ac->amiga_ipl == 6)
1219 1.1 mw istat = dev->sc_istat;
1220 1.1 mw else
1221 1.1 mw istat = regs->siop_istat;
1222 1.1 mw if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
1223 1.1 mw continue;
1224 1.1 mw if ((dev->sc_flags & (SIOP_DMA | SIOP_SELECTED)) == SIOP_SELECTED)
1225 1.1 mw continue; /* doing non-interrupt I/O */
1226 1.1 mw /* Got a valid interrupt on this device */
1227 1.1 mw found++;
1228 1.1 mw if (dev->sc_ac->amiga_ipl == 6) {
1229 1.1 mw dstat = dev->sc_dstat;
1230 1.1 mw sstat0 = dev->sc_sstat0;
1231 1.1 mw dev->sc_istat = 0;
1232 1.1 mw }
1233 1.1 mw else {
1234 1.1 mw dstat = regs->siop_dstat;
1235 1.1 mw sstat0 = regs->siop_sstat0;
1236 1.1 mw }
1237 1.1 mw #ifdef DEBUG
1238 1.1 mw if (siop_debug & 1)
1239 1.1 mw printf ("siop%d: intr istat %x dstat %x sstat0 %x\n",
1240 1.1 mw unit, istat, dstat, sstat0);
1241 1.1 mw if ((dev->sc_flags & SIOP_DMA) == 0) {
1242 1.1 mw printf ("siop%d: spurious interrupt? istat %x dstat %x sstat0 %x\n",
1243 1.1 mw unit, istat, dstat, sstat0);
1244 1.1 mw }
1245 1.1 mw #endif
1246 1.1 mw
1247 1.1 mw #ifdef DEBUG
1248 1.1 mw if (siop_debug & 5) {
1249 1.1 mw DCIAS(kvtop(&dev->sc_stat));
1250 1.1 mw printf ("siopintr%d: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
1251 1.1 mw unit, istat, dstat, sstat0, regs->siop_dsps,
1252 1.1 mw regs->siop_sbcl, dev->sc_stat[0], dev->sc_msg[0]);
1253 1.1 mw }
1254 1.1 mw #endif
1255 1.1 mw if (siop_checkintr (dev, istat, dstat, sstat0, &status)) {
1256 1.1 mw #if 1
1257 1.1 mw regs->siop_sien = 0;
1258 1.1 mw regs->siop_dien = 0;
1259 1.1 mw if (status == 0xff)
1260 1.1 mw printf ("siopintr: status == 0xff\n");
1261 1.1 mw #endif
1262 1.1 mw dev->sc_flags &= ~(SIOP_DMA | SIOP_SELECTED);
1263 1.1 mw dq = dev->sc_sq.dq_forw;
1264 1.1 mw (dq->dq_driver->d_intr)(dq->dq_unit, status);
1265 1.1 mw }
1266 1.1 mw }
1267 1.1 mw return (found);
1268 1.1 mw }
1269 1.1 mw
1270 1.1 mw void
1271 1.1 mw siopfree(dq)
1272 1.1 mw register struct devqueue *dq;
1273 1.1 mw {
1274 1.1 mw register struct devqueue *hq;
1275 1.1 mw
1276 1.1 mw #ifdef DEBUG
1277 1.1 mw if (siop_debug & 1)
1278 1.1 mw printf ("siopfree\n");
1279 1.1 mw #endif
1280 1.1 mw hq = &siop_softc[dq->dq_ctlr].sc_sq;
1281 1.1 mw remque(dq);
1282 1.1 mw if ((dq = hq->dq_forw) != hq)
1283 1.1 mw (dq->dq_driver->d_start)(dq->dq_unit);
1284 1.1 mw }
1285 1.1 mw
1286 1.1 mw /*
1287 1.1 mw * (XXX) The following routine is needed for the SCSI tape driver
1288 1.1 mw * to read odd-size records.
1289 1.1 mw */
1290 1.1 mw
1291 1.1 mw /* XXX - probably not needed for the 53C710 */
1292 1.1 mw
1293 1.1 mw #include "st.h"
1294 1.1 mw #if NST > 0
1295 1.1 mw int
1296 1.1 mw siop_tt_oddio(ctlr, slave, unit, buf, len, b_flags, freedma)
1297 1.1 mw int ctlr, slave, unit, b_flags;
1298 1.1 mw u_char *buf;
1299 1.1 mw u_int len;
1300 1.1 mw {
1301 1.1 mw register struct siop_softc *dev = &siop_softc[ctlr];
1302 1.1 mw struct scsi_cdb6 cdb;
1303 1.1 mw u_char iphase;
1304 1.1 mw int stat;
1305 1.1 mw
1306 1.1 mw printf ("siop%d: tt_oddio\n", slave);
1307 1.1 mw #if 0
1308 1.1 mw /*
1309 1.1 mw * First free any DMA channel that was allocated.
1310 1.1 mw * We can't use DMA to do this transfer.
1311 1.1 mw */
1312 1.1 mw if (freedma)
1313 1.1 mw dev->dmafree(&dev->sc_dq);
1314 1.1 mw /*
1315 1.1 mw * Initialize command block
1316 1.1 mw */
1317 1.1 mw bzero(&cdb, sizeof(cdb));
1318 1.1 mw cdb.lun = unit;
1319 1.1 mw cdb.lbam = (len >> 16) & 0xff;
1320 1.1 mw cdb.lbal = (len >> 8) & 0xff;
1321 1.1 mw cdb.len = len & 0xff;
1322 1.1 mw if (buf == 0) {
1323 1.1 mw cdb.cmd = CMD_SPACE;
1324 1.1 mw cdb.lun |= 0x00;
1325 1.1 mw len = 0;
1326 1.1 mw iphase = MESG_IN_PHASE;
1327 1.1 mw } else if (b_flags & B_READ) {
1328 1.1 mw cdb.cmd = CMD_READ;
1329 1.1 mw iphase = DATA_IN_PHASE;
1330 1.1 mw } else {
1331 1.1 mw cdb.cmd = CMD_WRITE;
1332 1.1 mw iphase = DATA_OUT_PHASE;
1333 1.1 mw }
1334 1.1 mw /*
1335 1.1 mw * Perform command (with very long delays)
1336 1.1 mw */
1337 1.1 mw scsi_delay(30000000);
1338 1.1 mw stat = siopicmd(dev, slave, (u_char *) &cdb, sizeof(cdb), buf, len, iphase);
1339 1.1 mw scsi_delay(0);
1340 1.1 mw return (stat);
1341 1.1 mw #endif
1342 1.1 mw return -1;
1343 1.1 mw }
1344 1.1 mw #endif
1345 1.1 mw #endif
1346