aic7xxx.seq revision 1.7 1 1.7 leo /* $NetBSD: aic7xxx.seq,v 1.7 1998/03/11 20:57:03 leo Exp $ */
2 1.3 thorpej
3 1.2 mycroft /*+M***********************************************************************
4 1.2 mycroft *Adaptec 274x/284x/294x device driver for Linux and FreeBSD.
5 1.2 mycroft *
6 1.2 mycroft *Copyright (c) 1994 John Aycock
7 1.2 mycroft * The University of Calgary Department of Computer Science.
8 1.2 mycroft * All rights reserved.
9 1.2 mycroft *
10 1.2 mycroft *FreeBSD, Twin, Wide, 2 command per target support, tagged queuing,
11 1.2 mycroft *SCB paging and other optimizations:
12 1.2 mycroft *Copyright (c) 1994, 1995, 1996 Justin Gibbs. All rights reserved.
13 1.2 mycroft *
14 1.2 mycroft *Redistribution and use in source and binary forms, with or without
15 1.2 mycroft *modification, are permitted provided that the following conditions
16 1.2 mycroft *are met:
17 1.2 mycroft *1. Redistributions of source code must retain the above copyright
18 1.2 mycroft * notice, this list of conditions, and the following disclaimer.
19 1.2 mycroft *2. Redistributions in binary form must reproduce the above copyright
20 1.2 mycroft * notice, this list of conditions and the following disclaimer in the
21 1.2 mycroft * documentation and/or other materials provided with the distribution.
22 1.2 mycroft *3. All advertising materials mentioning features or use of this software
23 1.2 mycroft * must display the following acknowledgement:
24 1.2 mycroft * This product includes software developed by the University of Calgary
25 1.2 mycroft * Department of Computer Science and its contributors.
26 1.2 mycroft *4. Neither the name of the University nor the names of its contributors
27 1.2 mycroft * may be used to endorse or promote products derived from this software
28 1.2 mycroft * without specific prior written permission.
29 1.2 mycroft *
30 1.2 mycroft *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31 1.2 mycroft *ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 1.2 mycroft *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 1.2 mycroft *ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34 1.2 mycroft *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 1.2 mycroft *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 1.2 mycroft *OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 1.2 mycroft *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 1.2 mycroft *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 1.2 mycroft *OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 1.2 mycroft *SUCH DAMAGE.
41 1.2 mycroft *
42 1.4 explorer * from Id: aic7xxx.seq,v 1.42 1996/06/09 17:29:11 gibbs Exp
43 1.4 explorer *
44 1.2 mycroft *-M************************************************************************/
45 1.2 mycroft
46 1.7 leo VERSION AIC7XXX_SEQ_VER "$NetBSD: aic7xxx.seq,v 1.7 1998/03/11 20:57:03 leo Exp $"
47 1.2 mycroft
48 1.2 mycroft #if defined(__NetBSD__)
49 1.5 mycroft #include "../../ic/aic7xxxreg.h"
50 1.7 leo #include "../../scsipi/scsi_message.h"
51 1.2 mycroft #elif defined(__FreeBSD__)
52 1.2 mycroft #include "../../dev/aic7xxx/aic7xxx_reg.h"
53 1.6 gibbs #include "../../scsi/scsi_message.h"
54 1.2 mycroft #endif
55 1.2 mycroft
56 1.2 mycroft /*
57 1.2 mycroft * We can't just use ACCUM in the sequencer code because it
58 1.2 mycroft * must be treated specially by the assembler, and it currently
59 1.2 mycroft * looks for the symbol 'A'. This is the only register defined in
60 1.2 mycroft * the assembler's symbol space.
61 1.2 mycroft */
62 1.2 mycroft A = ACCUM
63 1.2 mycroft
64 1.2 mycroft /* After starting the selection hardware, we check for reconnecting targets
65 1.2 mycroft * as well as for our selection to complete just in case the reselection wins
66 1.2 mycroft * bus arbitration. The problem with this is that we must keep track of the
67 1.2 mycroft * SCB that we've already pulled from the QINFIFO and started the selection
68 1.2 mycroft * on just in case the reselection wins so that we can retry the selection at
69 1.2 mycroft * a later time. This problem cannot be resolved by holding a single entry
70 1.2 mycroft * in scratch ram since a reconnecting target can request sense and this will
71 1.2 mycroft * create yet another SCB waiting for selection. The solution used here is to
72 1.2 mycroft * use byte 27 of the SCB as a psuedo-next pointer and to thread a list
73 1.2 mycroft * of SCBs that are awaiting selection. Since 0-0xfe are valid SCB offsets,
74 1.2 mycroft * SCB_LIST_NULL is 0xff which is out of range. The kernel driver must
75 1.2 mycroft * add an entry to this list everytime a request sense occurs. The sequencer
76 1.2 mycroft * will automatically consume the entries.
77 1.2 mycroft */
78 1.2 mycroft
79 1.2 mycroft /*
80 1.2 mycroft * We assume that the kernel driver may reset us at any time, even in the
81 1.2 mycroft * middle of a DMA, so clear DFCNTRL too.
82 1.2 mycroft */
83 1.2 mycroft reset:
84 1.2 mycroft clr DFCNTRL
85 1.2 mycroft clr SCSISIGO /* De-assert BSY */
86 1.2 mycroft /*
87 1.2 mycroft * We jump to start after every bus free.
88 1.2 mycroft */
89 1.1 mycroft start:
90 1.2 mycroft and FLAGS,0x0f /* clear target specific flags */
91 1.2 mycroft mvi SCSISEQ,ENRSELI /* Always allow reselection */
92 1.4 explorer clr SCSIRATE /*
93 1.4 explorer * We don't know the target we will
94 1.4 explorer * connect to, so default to narrow
95 1.4 explorer * transfers to avoid parity problems.
96 1.4 explorer */
97 1.1 mycroft poll_for_work:
98 1.2 mycroft /*
99 1.2 mycroft * Are we a twin channel device?
100 1.2 mycroft * For fairness, we check the other bus first,
101 1.2 mycroft * since we just finished a transaction on the
102 1.2 mycroft * current channel.
103 1.2 mycroft */
104 1.2 mycroft test FLAGS,TWIN_BUS jz start2
105 1.2 mycroft xor SBLKCTL,SELBUSB /* Toggle to the other bus */
106 1.1 mycroft test SSTAT0,SELDI jnz reselect
107 1.2 mycroft xor SBLKCTL,SELBUSB /* Toggle to the original bus */
108 1.1 mycroft start2:
109 1.1 mycroft test SSTAT0,SELDI jnz reselect
110 1.2 mycroft cmp WAITING_SCBH,SCB_LIST_NULL jne start_waiting
111 1.2 mycroft mov A, QCNTMASK
112 1.2 mycroft test QINCNT,A jz poll_for_work
113 1.2 mycroft
114 1.2 mycroft /*
115 1.2 mycroft * We have at least one queued SCB now and we don't have any
116 1.2 mycroft * SCBs in the list of SCBs awaiting selection. Set the SCB
117 1.2 mycroft * pointer from the FIFO so we see the right bank of SCB
118 1.2 mycroft * registers.
119 1.2 mycroft */
120 1.1 mycroft mov SCBPTR,QINFIFO
121 1.1 mycroft
122 1.2 mycroft /*
123 1.2 mycroft * See if there is not already an active SCB for this target. This code
124 1.2 mycroft * locks out on a per target basis instead of target/lun. Although this
125 1.2 mycroft * is not ideal for devices that have multiple luns active at the same
126 1.2 mycroft * time, it is faster than looping through all SCB's looking for active
127 1.2 mycroft * commands. It may be benificial to make findscb a more general procedure
128 1.2 mycroft * to see if the added cost of the search is negligible. This code also
129 1.2 mycroft * assumes that the kernel driver will clear the active flags on board
130 1.2 mycroft * initialization, board reset, and a target SELTO. Tagged commands
131 1.2 mycroft * don't set the active bits since you can queue more than one command
132 1.2 mycroft * at a time. We do, however, look to see if there are any non-tagged
133 1.2 mycroft * I/Os in progress, and requeue the command if there are. Tagged and
134 1.2 mycroft * non-tagged commands cannot be mixed to a single target.
135 1.2 mycroft */
136 1.1 mycroft
137 1.1 mycroft test_busy:
138 1.2 mycroft mov FUNCTION1,SCB_TCL
139 1.1 mycroft mov A,FUNCTION1
140 1.2 mycroft test SCB_TCL,0x88 jz test_a /* Id < 8 && A channel */
141 1.1 mycroft
142 1.1 mycroft test ACTIVE_B,A jnz requeue
143 1.2 mycroft test SCB_CONTROL,TAG_ENB jnz start_scb
144 1.2 mycroft /* Mark the current target as busy */
145 1.2 mycroft or ACTIVE_B,A
146 1.1 mycroft jmp start_scb
147 1.1 mycroft
148 1.2 mycroft /* Place the currently active SCB back on the queue for later processing */
149 1.1 mycroft requeue:
150 1.1 mycroft mov QINFIFO, SCBPTR
151 1.1 mycroft jmp poll_for_work
152 1.1 mycroft
153 1.2 mycroft /*
154 1.2 mycroft * Pull the first entry off of the waiting for selection list
155 1.2 mycroft * We don't have to "test_busy" because only transactions that
156 1.2 mycroft * have passed that test can be in the waiting_scb list.
157 1.2 mycroft */
158 1.1 mycroft start_waiting:
159 1.1 mycroft mov SCBPTR,WAITING_SCBH
160 1.2 mycroft jmp start_scb2
161 1.1 mycroft
162 1.1 mycroft test_a:
163 1.2 mycroft test ACTIVE_A,A jnz requeue
164 1.2 mycroft test SCB_CONTROL,TAG_ENB jnz start_scb
165 1.2 mycroft /* Mark the current target as busy */
166 1.2 mycroft or ACTIVE_A,A
167 1.1 mycroft
168 1.1 mycroft start_scb:
169 1.2 mycroft mov SCB_NEXT,WAITING_SCBH
170 1.1 mycroft mov WAITING_SCBH, SCBPTR
171 1.2 mycroft start_scb2:
172 1.2 mycroft and SINDEX,0xf7,SBLKCTL /* Clear the channel select bit */
173 1.2 mycroft and A,0x08,SCB_TCL /* Get new channel bit */
174 1.2 mycroft or SINDEX,A
175 1.2 mycroft mov SBLKCTL,SINDEX /* select channel */
176 1.2 mycroft mov SCB_TCL call initialize_scsiid
177 1.1 mycroft
178 1.2 mycroft /*
179 1.2 mycroft * Enable selection phase as an initiator, and do automatic ATN
180 1.2 mycroft * after the selection. We do this now so that we can overlap the
181 1.2 mycroft * rest of our work to set up this target with the arbitration and
182 1.2 mycroft * selection bus phases.
183 1.2 mycroft */
184 1.2 mycroft start_selection:
185 1.2 mycroft mvi SCSISEQ,0x58 /* ENSELO|ENAUTOATNO|ENRSELI */
186 1.1 mycroft
187 1.2 mycroft /*
188 1.2 mycroft * As soon as we get a successful selection, the target should go
189 1.2 mycroft * into the message out phase since we have ATN asserted. Prepare
190 1.2 mycroft * the message to send.
191 1.2 mycroft *
192 1.2 mycroft * Messages are stored in scratch RAM starting with a length byte
193 1.2 mycroft * followed by the message itself.
194 1.2 mycroft */
195 1.2 mycroft
196 1.2 mycroft mk_identify:
197 1.2 mycroft and A,DISCENB,SCB_CONTROL /* mask off disconnect privledge */
198 1.2 mycroft
199 1.2 mycroft and MSG0,0x7,SCB_TCL /* lun */
200 1.2 mycroft or MSG0,A /* or in disconnect privledge */
201 1.6 gibbs or MSG0,MSG_IDENTIFYFLAG
202 1.2 mycroft mvi MSG_LEN, 1
203 1.2 mycroft
204 1.2 mycroft /*
205 1.2 mycroft * Send a tag message if TAG_ENB is set in the SCB control block.
206 1.2 mycroft * Use SCB_TAG (the position in the kernel's SCB array) as the tag value.
207 1.2 mycroft */
208 1.1 mycroft mk_tag:
209 1.6 gibbs test SCB_CONTROL,TAG_ENB jz mk_message
210 1.2 mycroft mvi DINDEX, MSG1
211 1.2 mycroft and DINDIR,0x23,SCB_CONTROL
212 1.2 mycroft mov DINDIR,SCB_TAG
213 1.1 mycroft
214 1.2 mycroft add MSG_LEN,COMP_MSG0,DINDEX /* update message length */
215 1.1 mycroft
216 1.6 gibbs /*
217 1.6 gibbs * Interrupt the driver, and allow it to tweak the message buffer
218 1.6 gibbs * if it asks.
219 1.6 gibbs */
220 1.6 gibbs mk_message:
221 1.6 gibbs test SCB_CONTROL,MK_MESSAGE jz wait_for_selection
222 1.1 mycroft
223 1.6 gibbs mvi INTSTAT,AWAITING_MSG
224 1.1 mycroft
225 1.2 mycroft wait_for_selection:
226 1.2 mycroft test SSTAT0,SELDO jnz select
227 1.2 mycroft test SSTAT0,SELDI jz wait_for_selection
228 1.2 mycroft
229 1.2 mycroft /*
230 1.2 mycroft * Reselection has been initiated by a target. Make a note that we've been
231 1.2 mycroft * reselected, but haven't seen an IDENTIFY message from the target
232 1.2 mycroft * yet.
233 1.2 mycroft */
234 1.1 mycroft reselect:
235 1.2 mycroft clr MSG_LEN /* Don't have anything in the mesg buffer */
236 1.1 mycroft mov SELID call initialize_scsiid
237 1.2 mycroft or FLAGS,RESELECTED
238 1.2 mycroft jmp select2
239 1.1 mycroft
240 1.2 mycroft /*
241 1.2 mycroft * After the selection, remove this SCB from the "waiting for selection"
242 1.2 mycroft * list. This is achieved by simply moving our "next" pointer into
243 1.2 mycroft * WAITING_SCBH. Our next pointer will be set to null the next time this
244 1.2 mycroft * SCB is used, so don't bother with it now.
245 1.2 mycroft */
246 1.1 mycroft select:
247 1.2 mycroft mov WAITING_SCBH,SCB_NEXT
248 1.2 mycroft or FLAGS,SELECTED
249 1.1 mycroft select2:
250 1.2 mycroft /*
251 1.2 mycroft * Set CLRCHN here before the target has entered a data transfer mode -
252 1.2 mycroft * with synchronous SCSI, if you do it later, you blow away some
253 1.2 mycroft * data in the SCSI FIFO that the target has already sent to you.
254 1.2 mycroft */
255 1.2 mycroft or SXFRCTL0,CLRCHN
256 1.2 mycroft /*
257 1.2 mycroft * Initialize SCSIRATE with the appropriate value for this target.
258 1.2 mycroft */
259 1.2 mycroft call ndx_dtr
260 1.2 mycroft mov SCSIRATE,SINDIR
261 1.2 mycroft
262 1.4 explorer /*
263 1.4 explorer * Initialize Ultra mode setting.
264 1.4 explorer */
265 1.4 explorer mov FUNCTION1,SCSIID
266 1.4 explorer mov A,FUNCTION1
267 1.4 explorer and SINDEX,0xdf,SXFRCTL0 /* default to Ultra disabled */
268 1.4 explorer test SCSIID, 0x80 jnz ultra_b /* Target ID > 7 */
269 1.4 explorer test SBLKCTL, SELBUSB jnz ultra_b /* Second channel device */
270 1.4 explorer test ULTRA_ENB,A jz set_sxfrctl0
271 1.4 explorer or SINDEX, ULTRAEN jmp set_sxfrctl0
272 1.4 explorer ultra_b:
273 1.4 explorer test ULTRA_ENB_B,A jz set_sxfrctl0
274 1.4 explorer or SINDEX, ULTRAEN
275 1.4 explorer
276 1.4 explorer set_sxfrctl0:
277 1.4 explorer mov SXFRCTL0,SINDEX
278 1.4 explorer
279 1.2 mycroft mvi SCSISEQ,ENAUTOATNP /*
280 1.2 mycroft * ATN on parity errors
281 1.2 mycroft * for "in" phases
282 1.2 mycroft */
283 1.2 mycroft mvi CLRSINT1,CLRBUSFREE
284 1.2 mycroft mvi CLRSINT0,0x60 /* CLRSELDI|CLRSELDO */
285 1.2 mycroft /*
286 1.2 mycroft * Main loop for information transfer phases. If BSY is false, then
287 1.2 mycroft * we have a bus free condition, expected or not. Otherwise, wait
288 1.2 mycroft * for the target to assert REQ before checking MSG, C/D and I/O
289 1.2 mycroft * for the bus phase.
290 1.2 mycroft *
291 1.2 mycroft */
292 1.1 mycroft ITloop:
293 1.2 mycroft test SSTAT1,BUSFREE jnz p_busfree
294 1.2 mycroft test SSTAT1,REQINIT jz ITloop
295 1.1 mycroft
296 1.2 mycroft and A,PHASE_MASK,SCSISIGI
297 1.2 mycroft mov LASTPHASE,A
298 1.2 mycroft mov SCSISIGO,A
299 1.1 mycroft
300 1.1 mycroft cmp ALLZEROS,A je p_dataout
301 1.2 mycroft cmp A,P_DATAIN je p_datain
302 1.2 mycroft cmp A,P_COMMAND je p_command
303 1.2 mycroft cmp A,P_MESGOUT je p_mesgout
304 1.2 mycroft cmp A,P_STATUS je p_status
305 1.2 mycroft cmp A,P_MESGIN je p_mesgin
306 1.1 mycroft
307 1.2 mycroft mvi INTSTAT,BAD_PHASE /* unknown phase - signal driver */
308 1.4 explorer jmp ITloop /* Try reading the bus again. */
309 1.1 mycroft
310 1.1 mycroft p_dataout:
311 1.2 mycroft mvi DMAPARAMS,0x7d /*
312 1.2 mycroft * WIDEODD|SCSIEN|SDMAEN|HDMAEN|
313 1.2 mycroft * DIRECTION|FIFORESET
314 1.2 mycroft */
315 1.2 mycroft jmp data_phase_init
316 1.2 mycroft
317 1.2 mycroft /*
318 1.2 mycroft * If we re-enter the data phase after going through another phase, the
319 1.2 mycroft * STCNT may have been cleared, so restore it from the residual field.
320 1.2 mycroft */
321 1.2 mycroft data_phase_reinit:
322 1.2 mycroft mov STCNT0,SCB_RESID_DCNT0
323 1.2 mycroft mov STCNT1,SCB_RESID_DCNT1
324 1.2 mycroft mov STCNT2,SCB_RESID_DCNT2
325 1.2 mycroft jmp data_phase_loop
326 1.1 mycroft
327 1.1 mycroft p_datain:
328 1.2 mycroft mvi DMAPARAMS,0x79 /*
329 1.2 mycroft * WIDEODD|SCSIEN|SDMAEN|HDMAEN|
330 1.2 mycroft * !DIRECTION|FIFORESET
331 1.2 mycroft */
332 1.2 mycroft data_phase_init:
333 1.1 mycroft call assert
334 1.1 mycroft
335 1.2 mycroft test FLAGS, DPHASE jnz data_phase_reinit
336 1.2 mycroft call sg_scb2ram
337 1.2 mycroft or FLAGS, DPHASE /* We have seen a data phase */
338 1.1 mycroft
339 1.2 mycroft data_phase_loop:
340 1.4 explorer /* Guard against overruns */
341 1.4 explorer test SG_COUNT, 0xff jnz data_phase_inbounds
342 1.4 explorer /*
343 1.4 explorer * Turn on 'Bit Bucket' mode, set the transfer count to
344 1.4 explorer * 16meg and let the target run until it changes phase.
345 1.4 explorer * When the transfer completes, notify the host that we
346 1.4 explorer * had an overrun.
347 1.4 explorer */
348 1.4 explorer or SXFRCTL1,BITBUCKET
349 1.4 explorer mvi STCNT0,0xff
350 1.4 explorer mvi STCNT1,0xff
351 1.4 explorer mvi STCNT2,0xff
352 1.4 explorer
353 1.4 explorer data_phase_inbounds:
354 1.2 mycroft /* If we are the last SG block, don't set wideodd. */
355 1.2 mycroft cmp SG_COUNT,0x01 jne data_phase_wideodd
356 1.2 mycroft and DMAPARAMS, 0xbf /* Turn off WIDEODD */
357 1.2 mycroft data_phase_wideodd:
358 1.2 mycroft mov DMAPARAMS call dma
359 1.2 mycroft
360 1.4 explorer /* Go tell the host about any overruns */
361 1.4 explorer test SXFRCTL1,BITBUCKET jnz data_phase_overrun
362 1.4 explorer
363 1.2 mycroft /* Exit if we had an underrun */
364 1.2 mycroft test SSTAT0,SDONE jz data_phase_finish /* underrun STCNT != 0 */
365 1.2 mycroft
366 1.2 mycroft /*
367 1.2 mycroft * Advance the scatter-gather pointers if needed
368 1.2 mycroft */
369 1.2 mycroft sg_advance:
370 1.2 mycroft dec SG_COUNT /* one less segment to go */
371 1.1 mycroft
372 1.2 mycroft test SG_COUNT, 0xff jz data_phase_finish /* Are we done? */
373 1.1 mycroft
374 1.2 mycroft clr A /* add sizeof(struct scatter) */
375 1.2 mycroft add SG_NEXT0,SG_SIZEOF,SG_NEXT0
376 1.2 mycroft adc SG_NEXT1,A,SG_NEXT1
377 1.2 mycroft
378 1.2 mycroft /*
379 1.2 mycroft * Load a struct scatter and set up the data address and length.
380 1.2 mycroft * If the working value of the SG count is nonzero, then
381 1.2 mycroft * we need to load a new set of values.
382 1.2 mycroft *
383 1.2 mycroft * This, like all DMA's, assumes little-endian host data storage.
384 1.2 mycroft */
385 1.2 mycroft sg_load:
386 1.2 mycroft clr HCNT2
387 1.2 mycroft clr HCNT1
388 1.2 mycroft mvi HCNT0,SG_SIZEOF
389 1.2 mycroft
390 1.2 mycroft mov HADDR0,SG_NEXT0
391 1.2 mycroft mov HADDR1,SG_NEXT1
392 1.2 mycroft mov HADDR2,SG_NEXT2
393 1.2 mycroft mov HADDR3,SG_NEXT3
394 1.2 mycroft
395 1.2 mycroft or DFCNTRL,0xd /* HDMAEN|DIRECTION|FIFORESET */
396 1.2 mycroft
397 1.2 mycroft /*
398 1.2 mycroft * Wait for DMA from host memory to data FIFO to complete, then disable
399 1.2 mycroft * DMA and wait for it to acknowledge that it's off.
400 1.2 mycroft */
401 1.2 mycroft dma_finish:
402 1.2 mycroft test DFSTATUS,HDONE jz dma_finish
403 1.2 mycroft /* Turn off DMA preserving WIDEODD */
404 1.2 mycroft and DFCNTRL,WIDEODD
405 1.2 mycroft dma_finish2:
406 1.2 mycroft test DFCNTRL,HDMAENACK jnz dma_finish2
407 1.1 mycroft
408 1.2 mycroft /*
409 1.2 mycroft * Copy data from FIFO into SCB data pointer and data count. This assumes
410 1.2 mycroft * that the struct scatterlist has this structure (this and sizeof(struct
411 1.2 mycroft * scatterlist) == 12 are asserted in aic7xxx.c for the Linux driver):
412 1.2 mycroft *
413 1.2 mycroft * struct scatterlist {
414 1.2 mycroft * char *address; four bytes, little-endian order
415 1.2 mycroft * ... four bytes, ignored
416 1.2 mycroft * unsigned short length; two bytes, little-endian order
417 1.2 mycroft * }
418 1.2 mycroft *
419 1.2 mycroft *
420 1.2 mycroft * In FreeBSD, the scatter list entry is only 8 bytes.
421 1.2 mycroft *
422 1.2 mycroft * struct ahc_dma_seg {
423 1.2 mycroft * physaddr addr; four bytes, little-endian order
424 1.2 mycroft * long len; four bytes, little endian order
425 1.2 mycroft * };
426 1.2 mycroft */
427 1.2 mycroft
428 1.7 leo #if BIG_ENDIAN_CPU
429 1.7 leo mov HADDR3,DFDAT
430 1.7 leo mov HADDR2,DFDAT
431 1.7 leo mov HADDR1,DFDAT
432 1.7 leo mov HADDR0,DFDAT
433 1.7 leo #else
434 1.2 mycroft mov HADDR0,DFDAT
435 1.2 mycroft mov HADDR1,DFDAT
436 1.2 mycroft mov HADDR2,DFDAT
437 1.2 mycroft mov HADDR3,DFDAT
438 1.7 leo #endif
439 1.2 mycroft /*
440 1.2 mycroft * For Linux, we must throw away four bytes since there is a 32bit gap
441 1.2 mycroft * in the middle of a struct scatterlist.
442 1.2 mycroft */
443 1.2 mycroft #ifdef __linux__
444 1.2 mycroft mov NONE,DFDAT
445 1.2 mycroft mov NONE,DFDAT
446 1.2 mycroft mov NONE,DFDAT
447 1.2 mycroft mov NONE,DFDAT
448 1.2 mycroft #endif
449 1.7 leo #if BIG_ENDIAN_CPU
450 1.7 leo mov HCNT2,DFDAT /* LEO: MSB unused */
451 1.7 leo mov HCNT2,DFDAT
452 1.7 leo mov HCNT1,DFDAT
453 1.7 leo mov HCNT0,DFDAT
454 1.7 leo #else
455 1.2 mycroft mov HCNT0,DFDAT
456 1.2 mycroft mov HCNT1,DFDAT
457 1.2 mycroft mov HCNT2,DFDAT
458 1.7 leo #endif
459 1.2 mycroft
460 1.2 mycroft /* Load STCNT as well. It is a mirror of HCNT */
461 1.2 mycroft mov STCNT0,HCNT0
462 1.2 mycroft mov STCNT1,HCNT1
463 1.2 mycroft mov STCNT2,HCNT2
464 1.2 mycroft test SSTAT1,PHASEMIS jz data_phase_loop
465 1.2 mycroft
466 1.2 mycroft data_phase_finish:
467 1.2 mycroft /*
468 1.2 mycroft * After a DMA finishes, save the SG and STCNT residuals back into the SCB
469 1.2 mycroft * We use STCNT instead of HCNT, since it's a reflection of how many bytes
470 1.2 mycroft * were transferred on the SCSI (as opposed to the host) bus.
471 1.2 mycroft */
472 1.2 mycroft mov SCB_RESID_DCNT0,STCNT0
473 1.2 mycroft mov SCB_RESID_DCNT1,STCNT1
474 1.2 mycroft mov SCB_RESID_DCNT2,STCNT2
475 1.2 mycroft mov SCB_RESID_SGCNT, SG_COUNT
476 1.1 mycroft jmp ITloop
477 1.1 mycroft
478 1.4 explorer data_phase_overrun:
479 1.4 explorer /*
480 1.4 explorer * Turn off BITBUCKET mode and notify the host
481 1.4 explorer */
482 1.4 explorer and SXFRCTL1,0x7f /* ~BITBUCKET */
483 1.4 explorer mvi INTSTAT,DATA_OVERRUN
484 1.4 explorer jmp ITloop
485 1.4 explorer
486 1.2 mycroft /*
487 1.2 mycroft * Command phase. Set up the DMA registers and let 'er rip.
488 1.2 mycroft */
489 1.1 mycroft p_command:
490 1.1 mycroft call assert
491 1.1 mycroft
492 1.2 mycroft /*
493 1.2 mycroft * Load HADDR and HCNT.
494 1.2 mycroft */
495 1.7 leo #if BIG_ENDIAN_CPU
496 1.7 leo mov HADDR3, SCB_CMDPTR0
497 1.7 leo mov HADDR2, SCB_CMDPTR1
498 1.7 leo mov HADDR1, SCB_CMDPTR2
499 1.7 leo mov HADDR0, SCB_CMDPTR3
500 1.7 leo #else
501 1.2 mycroft mov HADDR0, SCB_CMDPTR0
502 1.2 mycroft mov HADDR1, SCB_CMDPTR1
503 1.2 mycroft mov HADDR2, SCB_CMDPTR2
504 1.2 mycroft mov HADDR3, SCB_CMDPTR3
505 1.7 leo #endif
506 1.2 mycroft mov HCNT0, SCB_CMDLEN
507 1.2 mycroft clr HCNT1
508 1.2 mycroft clr HCNT2
509 1.2 mycroft
510 1.2 mycroft mov STCNT0, HCNT0
511 1.2 mycroft mov STCNT1, HCNT1
512 1.2 mycroft mov STCNT2, HCNT2
513 1.1 mycroft
514 1.1 mycroft mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN|
515 1.1 mycroft # DIRECTION|FIFORESET
516 1.1 mycroft jmp ITloop
517 1.1 mycroft
518 1.2 mycroft /*
519 1.2 mycroft * Status phase. Wait for the data byte to appear, then read it
520 1.2 mycroft * and store it into the SCB.
521 1.2 mycroft */
522 1.1 mycroft p_status:
523 1.2 mycroft mvi SCB_TARGET_STATUS call inb_first
524 1.2 mycroft jmp mesgin_done
525 1.1 mycroft
526 1.2 mycroft /*
527 1.2 mycroft * Message out phase. If there is not an active message, but the target
528 1.2 mycroft * took us into this phase anyway, build a no-op message and send it.
529 1.2 mycroft */
530 1.1 mycroft p_mesgout:
531 1.2 mycroft test MSG_LEN, 0xff jnz p_mesgout_start
532 1.6 gibbs mvi MSG_NOOP call mk_mesg /* build NOP message */
533 1.1 mycroft
534 1.2 mycroft p_mesgout_start:
535 1.2 mycroft /*
536 1.2 mycroft * Set up automatic PIO transfer from MSG0. Bit 3 in
537 1.2 mycroft * SXFRCTL0 (SPIOEN) is already on.
538 1.2 mycroft */
539 1.2 mycroft mvi SINDEX,MSG0
540 1.1 mycroft mov DINDEX,MSG_LEN
541 1.1 mycroft
542 1.2 mycroft /*
543 1.2 mycroft * When target asks for a byte, drop ATN if it's the last one in
544 1.2 mycroft * the message. Otherwise, keep going until the message is exhausted.
545 1.2 mycroft *
546 1.2 mycroft * Keep an eye out for a phase change, in case the target issues
547 1.2 mycroft * a MESSAGE REJECT.
548 1.2 mycroft */
549 1.2 mycroft p_mesgout_loop:
550 1.2 mycroft test SSTAT1,PHASEMIS jnz p_mesgout_phasemis
551 1.2 mycroft test SSTAT0,SPIORDY jz p_mesgout_loop
552 1.4 explorer test SSTAT1,PHASEMIS jnz p_mesgout_phasemis
553 1.2 mycroft cmp DINDEX,1 jne p_mesgout_outb /* last byte? */
554 1.2 mycroft mvi CLRSINT1,CLRATNO /* drop ATN */
555 1.2 mycroft p_mesgout_outb:
556 1.2 mycroft dec DINDEX
557 1.2 mycroft or CLRSINT0, CLRSPIORDY
558 1.1 mycroft mov SCSIDATL,SINDIR
559 1.2 mycroft
560 1.2 mycroft p_mesgout4:
561 1.2 mycroft test DINDEX,0xff jnz p_mesgout_loop
562 1.2 mycroft
563 1.2 mycroft /*
564 1.2 mycroft * If the next bus phase after ATN drops is a message out, it means
565 1.2 mycroft * that the target is requesting that the last message(s) be resent.
566 1.2 mycroft */
567 1.2 mycroft p_mesgout_snoop:
568 1.2 mycroft test SSTAT1,BUSFREE jnz p_mesgout_done
569 1.2 mycroft test SSTAT1,REQINIT jz p_mesgout_snoop
570 1.1 mycroft
571 1.2 mycroft test SSTAT1,PHASEMIS jnz p_mesgout_done
572 1.1 mycroft
573 1.2 mycroft or SCSISIGO,ATNO /* turn on ATNO */
574 1.1 mycroft
575 1.1 mycroft jmp ITloop
576 1.1 mycroft
577 1.2 mycroft p_mesgout_phasemis:
578 1.2 mycroft mvi CLRSINT1,CLRATNO /* Be sure to turn ATNO off */
579 1.2 mycroft p_mesgout_done:
580 1.2 mycroft clr MSG_LEN /* no active msg */
581 1.1 mycroft jmp ITloop
582 1.1 mycroft
583 1.2 mycroft /*
584 1.2 mycroft * Message in phase. Bytes are read using Automatic PIO mode.
585 1.2 mycroft */
586 1.1 mycroft p_mesgin:
587 1.2 mycroft mvi A call inb_first /* read the 1st message byte */
588 1.2 mycroft mov REJBYTE,A /* save it for the driver */
589 1.2 mycroft
590 1.6 gibbs test A,MSG_IDENTIFYFLAG jnz mesgin_identify
591 1.2 mycroft cmp A,MSG_DISCONNECT je mesgin_disconnect
592 1.6 gibbs cmp A,MSG_SAVEDATAPOINTER je mesgin_sdptrs
593 1.2 mycroft cmp ALLZEROS,A je mesgin_complete
594 1.6 gibbs cmp A,MSG_RESTOREPOINTERS je mesgin_rdptrs
595 1.2 mycroft cmp A,MSG_EXTENDED je mesgin_extended
596 1.6 gibbs cmp A,MSG_MESSAGE_REJECT je mesgin_reject
597 1.2 mycroft
598 1.2 mycroft rej_mesgin:
599 1.2 mycroft /*
600 1.2 mycroft * We have no idea what this message in is, and there's no way
601 1.2 mycroft * to pass it up to the kernel, so we issue a message reject and
602 1.2 mycroft * hope for the best. Since we're now using manual PIO mode to
603 1.2 mycroft * read in the message, there should no longer be a race condition
604 1.2 mycroft * present when we assert ATN. In any case, rejection should be a
605 1.2 mycroft * rare occurrence - signal the driver when it happens.
606 1.2 mycroft */
607 1.2 mycroft or SCSISIGO,ATNO /* turn on ATNO */
608 1.2 mycroft mvi INTSTAT,SEND_REJECT /* let driver know */
609 1.2 mycroft
610 1.6 gibbs mvi MSG_MESSAGE_REJECT call mk_mesg
611 1.2 mycroft
612 1.2 mycroft mesgin_done:
613 1.2 mycroft call inb_last /*ack & turn auto PIO back on*/
614 1.2 mycroft jmp ITloop
615 1.2 mycroft
616 1.2 mycroft
617 1.2 mycroft mesgin_complete:
618 1.2 mycroft /*
619 1.2 mycroft * We got a "command complete" message, so put the SCB_TAG into QUEUEOUT,
620 1.2 mycroft * and trigger a completion interrupt. Check status for non zero return
621 1.2 mycroft * and interrupt driver if needed. This allows the driver to interpret
622 1.2 mycroft * errors only when they occur instead of always uploading the scb. If
623 1.2 mycroft * the status is SCSI_CHECK, the driver will download a new scb requesting
624 1.2 mycroft * sense to replace the old one, modify the "waiting for selection" SCB list
625 1.2 mycroft * and set RETURN_1 to SEND_SENSE. If RETURN_1 is set to SEND_SENSE the
626 1.2 mycroft * sequencer imediately jumps to main loop where it will run down the waiting
627 1.2 mycroft * SCB list and process the sense request. If the kernel driver does not
628 1.2 mycroft * wish to request sense, it need only clear RETURN_1, and the command is
629 1.2 mycroft * allowed to complete. We don't bother to post to the QOUTFIFO in the
630 1.2 mycroft * error case since it would require extra work in the kernel driver to
631 1.2 mycroft * ensure that the entry was removed before the command complete code tried
632 1.2 mycroft * processing it.
633 1.2 mycroft *
634 1.2 mycroft * First check for residuals
635 1.2 mycroft */
636 1.2 mycroft test SCB_RESID_SGCNT,0xff jz check_status
637 1.2 mycroft /*
638 1.2 mycroft * If we have a residual count, interrupt and tell the host. Other
639 1.2 mycroft * alternatives are to pause the sequencer on all command completes (yuck),
640 1.2 mycroft * dma the resid directly to the host (slick, we may have space to do it now)
641 1.2 mycroft * or have the sequencer pause itself when it encounters a non-zero resid
642 1.2 mycroft * (unecessary pause just to flag the command -yuck-, but takes one instruction
643 1.2 mycroft * and since it shouldn't happen that often is good enough for our purposes).
644 1.2 mycroft */
645 1.2 mycroft resid:
646 1.2 mycroft mvi INTSTAT,RESIDUAL
647 1.1 mycroft
648 1.1 mycroft check_status:
649 1.2 mycroft test SCB_TARGET_STATUS,0xff jz status_ok /* Good Status? */
650 1.2 mycroft mvi INTSTAT,BAD_STATUS /* let driver know */
651 1.2 mycroft cmp RETURN_1, SEND_SENSE jne status_ok
652 1.2 mycroft jmp mesgin_done
653 1.1 mycroft
654 1.1 mycroft status_ok:
655 1.2 mycroft /* First, mark this target as free. */
656 1.2 mycroft test SCB_CONTROL,TAG_ENB jnz test_immediate /*
657 1.2 mycroft * Tagged commands
658 1.2 mycroft * don't busy the
659 1.2 mycroft * target.
660 1.2 mycroft */
661 1.2 mycroft mov FUNCTION1,SCB_TCL
662 1.1 mycroft mov A,FUNCTION1
663 1.2 mycroft test SCB_TCL,0x88 jz clear_a
664 1.1 mycroft xor ACTIVE_B,A
665 1.2 mycroft jmp test_immediate
666 1.1 mycroft
667 1.1 mycroft clear_a:
668 1.1 mycroft xor ACTIVE_A,A
669 1.1 mycroft
670 1.2 mycroft test_immediate:
671 1.2 mycroft test SCB_CMDLEN,0xff jnz complete /* Immediate message complete */
672 1.2 mycroft /*
673 1.2 mycroft * Pause the sequencer until the driver gets around to handling the command
674 1.2 mycroft * complete. This is so that any action that might require carefull timing
675 1.2 mycroft * with the completion of this command can occur.
676 1.2 mycroft */
677 1.2 mycroft mvi INTSTAT,IMMEDDONE
678 1.2 mycroft jmp start
679 1.1 mycroft complete:
680 1.2 mycroft mov QOUTFIFO,SCB_TAG
681 1.1 mycroft mvi INTSTAT,CMDCMPLT
682 1.2 mycroft jmp mesgin_done
683 1.1 mycroft
684 1.1 mycroft
685 1.2 mycroft /*
686 1.6 gibbs * Is it an extended message? Copy the message to our message buffer and
687 1.6 gibbs * notify the host. The host will tell us whether to reject this message,
688 1.6 gibbs * respond to it with the message that the host placed in our message buffer,
689 1.6 gibbs * or simply to do nothing.
690 1.2 mycroft */
691 1.2 mycroft mesgin_extended:
692 1.6 gibbs mvi MSGIN_EXT_LEN call inb_next
693 1.6 gibbs mvi MSGIN_EXT_OPCODE call inb_next
694 1.6 gibbs mov A, MSGIN_EXT_LEN
695 1.6 gibbs dec A /* Length counts the op code */
696 1.6 gibbs mvi SINDEX, MSGIN_EXT_BYTE0
697 1.6 gibbs mesgin_extended_loop:
698 1.6 gibbs test A, 0xFF jz mesgin_extended_intr
699 1.6 gibbs cmp SINDEX, MSGIN_EXT_LASTBYTE je mesgin_extended_dump
700 1.6 gibbs call inb_next
701 1.6 gibbs dec A
702 1.6 gibbs /*
703 1.6 gibbs * We pass the arg to inb in SINDEX, but DINDEX is the one incremented
704 1.6 gibbs * so update SINDEX with DINDEX's value before looping again.
705 1.6 gibbs */
706 1.6 gibbs mov DINDEX jmp mesgin_extended_loop
707 1.6 gibbs mesgin_extended_dump:
708 1.6 gibbs /* We have no more storage space, so dump the rest */
709 1.6 gibbs test A, 0xFF jz mesgin_extended_intr
710 1.6 gibbs mvi NONE call inb_next
711 1.6 gibbs dec A
712 1.6 gibbs jmp mesgin_extended_dump
713 1.6 gibbs mesgin_extended_intr:
714 1.6 gibbs mvi INTSTAT,EXTENDED_MSG /* let driver know */
715 1.6 gibbs cmp RETURN_1,SEND_REJ je rej_mesgin
716 1.6 gibbs cmp RETURN_1,SEND_MSG jne mesgin_done
717 1.6 gibbs /* The kernel has setup a message to be sent */
718 1.2 mycroft or SCSISIGO,ATNO /* turn on ATNO */
719 1.2 mycroft jmp mesgin_done
720 1.2 mycroft
721 1.2 mycroft /*
722 1.2 mycroft * Is it a disconnect message? Set a flag in the SCB to remind us
723 1.2 mycroft * and await the bus going free.
724 1.2 mycroft */
725 1.2 mycroft mesgin_disconnect:
726 1.2 mycroft or SCB_CONTROL,DISCONNECTED
727 1.2 mycroft test FLAGS, PAGESCBS jz mesgin_done
728 1.2 mycroft /*
729 1.2 mycroft * Link this SCB into the DISCONNECTED list. This list holds the
730 1.2 mycroft * candidates for paging out an SCB if one is needed for a new command.
731 1.2 mycroft * Modifying the disconnected list is a critical(pause dissabled) section.
732 1.2 mycroft */
733 1.2 mycroft mvi SCB_PREV, SCB_LIST_NULL
734 1.2 mycroft mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
735 1.2 mycroft mov SCB_NEXT, DISCONNECTED_SCBH
736 1.2 mycroft mov DISCONNECTED_SCBH, SCBPTR
737 1.2 mycroft cmp SCB_NEXT,SCB_LIST_NULL je linkdone
738 1.2 mycroft mov SCBPTR,SCB_NEXT
739 1.2 mycroft mov SCB_PREV,DISCONNECTED_SCBH
740 1.2 mycroft mov SCBPTR,DISCONNECTED_SCBH
741 1.2 mycroft linkdone:
742 1.2 mycroft mvi SEQCTL,0x10 /* !PAUSEDIS|FASTMODE */
743 1.2 mycroft jmp mesgin_done
744 1.2 mycroft
745 1.2 mycroft /*
746 1.2 mycroft * Save data pointers message? Copy working values into the SCB,
747 1.2 mycroft * usually in preparation for a disconnect.
748 1.2 mycroft */
749 1.2 mycroft mesgin_sdptrs:
750 1.1 mycroft call sg_ram2scb
751 1.2 mycroft jmp mesgin_done
752 1.1 mycroft
753 1.2 mycroft /*
754 1.2 mycroft * Restore pointers message? Data pointers are recopied from the
755 1.2 mycroft * SCB anytime we enter a data phase for the first time, so all
756 1.2 mycroft * we need to do is clear the DPHASE flag and let the data phase
757 1.2 mycroft * code do the rest.
758 1.2 mycroft */
759 1.2 mycroft mesgin_rdptrs:
760 1.2 mycroft and FLAGS,0xef /*
761 1.2 mycroft * !DPHASE we'll reload them
762 1.2 mycroft * the next time through
763 1.2 mycroft */
764 1.2 mycroft jmp mesgin_done
765 1.2 mycroft
766 1.2 mycroft /*
767 1.2 mycroft * Identify message? For a reconnecting target, this tells us the lun
768 1.2 mycroft * that the reconnection is for - find the correct SCB and switch to it,
769 1.2 mycroft * clearing the "disconnected" bit so we don't "find" it by accident later.
770 1.2 mycroft */
771 1.2 mycroft mesgin_identify:
772 1.2 mycroft test A,0x78 jnz rej_mesgin /*!DiscPriv|!LUNTAR|!Reserved*/
773 1.1 mycroft
774 1.2 mycroft and A,0x07 /* lun in lower three bits */
775 1.1 mycroft or SAVED_TCL,A,SELID
776 1.1 mycroft and SAVED_TCL,0xf7
777 1.2 mycroft and A,SELBUSB,SBLKCTL /* B Channel?? */
778 1.1 mycroft or SAVED_TCL,A
779 1.2 mycroft call inb_last /* ACK */
780 1.2 mycroft
781 1.2 mycroft /*
782 1.2 mycroft * Here we "snoop" the bus looking for a SIMPLE QUEUE TAG message.
783 1.2 mycroft * If we get one, we use the tag returned to switch to find the proper
784 1.2 mycroft * SCB. With SCB paging, this requires using findSCB for both tagged
785 1.2 mycroft * and non-tagged transactions since the SCB may exist in any slot.
786 1.2 mycroft * If we're not using SCB paging, we can use the tag as the direct
787 1.2 mycroft * index to the SCB.
788 1.2 mycroft */
789 1.2 mycroft mvi ARG_1,SCB_LIST_NULL /* Default to no-tag */
790 1.2 mycroft snoop_tag_loop:
791 1.6 gibbs test SSTAT1,BUSFREE jnz use_findSCB
792 1.6 gibbs test SSTAT1,REQINIT jz snoop_tag_loop
793 1.6 gibbs test SSTAT1,PHASEMIS jnz use_findSCB
794 1.6 gibbs mvi A call inb_first
795 1.6 gibbs cmp A,MSG_SIMPLE_Q_TAG jne use_findSCB
796 1.2 mycroft get_tag:
797 1.2 mycroft mvi ARG_1 call inb_next /* tag value */
798 1.2 mycroft /*
799 1.2 mycroft * See if the tag is in range. The tag is < SCBCOUNT if we add
800 1.2 mycroft * the complement of SCBCOUNT to the incomming tag and there is
801 1.2 mycroft * no carry.
802 1.2 mycroft */
803 1.2 mycroft mov A,COMP_SCBCOUNT
804 1.2 mycroft add SINDEX,A,ARG_1
805 1.2 mycroft jc abort_tag
806 1.2 mycroft
807 1.2 mycroft /*
808 1.2 mycroft * Ensure that the SCB the tag points to is for an SCB transaction
809 1.2 mycroft * to the reconnecting target.
810 1.2 mycroft */
811 1.2 mycroft test FLAGS, PAGESCBS jz index_by_tag
812 1.2 mycroft call inb_last /* Ack Tag */
813 1.2 mycroft use_findSCB:
814 1.2 mycroft mov ALLZEROS call findSCB /* Have to search */
815 1.1 mycroft setup_SCB:
816 1.2 mycroft and SCB_CONTROL,0xfb /* clear disconnect bit in SCB */
817 1.2 mycroft or FLAGS,IDENTIFY_SEEN /* make note of IDENTIFY */
818 1.1 mycroft jmp ITloop
819 1.2 mycroft index_by_tag:
820 1.2 mycroft mov SCBPTR,ARG_1
821 1.1 mycroft mov A,SAVED_TCL
822 1.2 mycroft cmp SCB_TCL,A jne abort_tag
823 1.2 mycroft test SCB_CONTROL,TAG_ENB jz abort_tag
824 1.2 mycroft call inb_last /* Ack Successful tag */
825 1.2 mycroft jmp setup_SCB
826 1.2 mycroft
827 1.1 mycroft abort_tag:
828 1.2 mycroft or SCSISIGO,ATNO /* turn on ATNO */
829 1.2 mycroft mvi INTSTAT,ABORT_TAG /* let driver know */
830 1.2 mycroft mvi MSG_ABORT_TAG call mk_mesg /* ABORT TAG message */
831 1.2 mycroft jmp mesgin_done
832 1.2 mycroft
833 1.2 mycroft /*
834 1.2 mycroft * Message reject? Let the kernel driver handle this. If we have an
835 1.2 mycroft * outstanding WDTR or SDTR negotiation, assume that it's a response from
836 1.2 mycroft * the target selecting 8bit or asynchronous transfer, otherwise just ignore
837 1.2 mycroft * it since we have no clue what it pertains to.
838 1.2 mycroft */
839 1.2 mycroft mesgin_reject:
840 1.2 mycroft mvi INTSTAT, REJECT_MSG
841 1.2 mycroft jmp mesgin_done
842 1.2 mycroft
843 1.2 mycroft /*
844 1.2 mycroft * [ ADD MORE MESSAGE HANDLING HERE ]
845 1.2 mycroft */
846 1.2 mycroft
847 1.2 mycroft /*
848 1.2 mycroft * Bus free phase. It might be useful to interrupt the device
849 1.2 mycroft * driver if we aren't expecting this. For now, make sure that
850 1.2 mycroft * ATN isn't being asserted and look for a new command.
851 1.2 mycroft */
852 1.2 mycroft p_busfree:
853 1.2 mycroft mvi CLRSINT1,CLRATNO
854 1.2 mycroft clr LASTPHASE
855 1.1 mycroft
856 1.2 mycroft /*
857 1.2 mycroft * if this is an immediate command, perform a psuedo command complete to
858 1.2 mycroft * notify the driver.
859 1.2 mycroft */
860 1.2 mycroft test SCB_CMDLEN,0xff jz status_ok
861 1.1 mycroft jmp start
862 1.1 mycroft
863 1.2 mycroft /*
864 1.2 mycroft * Locking the driver out, build a one-byte message passed in SINDEX
865 1.2 mycroft * if there is no active message already. SINDEX is returned intact.
866 1.2 mycroft */
867 1.2 mycroft mk_mesg:
868 1.2 mycroft mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
869 1.2 mycroft test MSG_LEN,0xff jz mk_mesg1 /* Should always succeed */
870 1.1 mycroft
871 1.2 mycroft /*
872 1.2 mycroft * Hmmm. For some reason the mesg buffer is in use.
873 1.2 mycroft * Tell the driver. It should look at SINDEX to find
874 1.2 mycroft * out what we wanted to use the buffer for and resolve
875 1.2 mycroft * the conflict.
876 1.2 mycroft */
877 1.2 mycroft mvi SEQCTL,0x10 /* !PAUSEDIS|FASTMODE */
878 1.2 mycroft mvi INTSTAT,MSG_BUFFER_BUSY
879 1.1 mycroft
880 1.1 mycroft mk_mesg1:
881 1.2 mycroft mvi MSG_LEN,1 /* length = 1 */
882 1.2 mycroft mov MSG0,SINDEX /* 1-byte message */
883 1.2 mycroft mvi SEQCTL,0x10 ret /* !PAUSEDIS|FASTMODE */
884 1.2 mycroft
885 1.2 mycroft /*
886 1.2 mycroft * Functions to read data in Automatic PIO mode.
887 1.2 mycroft *
888 1.2 mycroft * According to Adaptec's documentation, an ACK is not sent on input from
889 1.2 mycroft * the target until SCSIDATL is read from. So we wait until SCSIDATL is
890 1.2 mycroft * latched (the usual way), then read the data byte directly off the bus
891 1.2 mycroft * using SCSIBUSL. When we have pulled the ATN line, or we just want to
892 1.2 mycroft * acknowledge the byte, then we do a dummy read from SCISDATL. The SCSI
893 1.2 mycroft * spec guarantees that the target will hold the data byte on the bus until
894 1.2 mycroft * we send our ACK.
895 1.2 mycroft *
896 1.2 mycroft * The assumption here is that these are called in a particular sequence,
897 1.2 mycroft * and that REQ is already set when inb_first is called. inb_{first,next}
898 1.2 mycroft * use the same calling convention as inb.
899 1.2 mycroft */
900 1.1 mycroft
901 1.2 mycroft inb_next:
902 1.2 mycroft or CLRSINT0, CLRSPIORDY
903 1.2 mycroft mov NONE,SCSIDATL /*dummy read from latch to ACK*/
904 1.2 mycroft inb_next_wait:
905 1.2 mycroft test SSTAT1,PHASEMIS jnz mesgin_phasemis
906 1.2 mycroft test SSTAT0,SPIORDY jz inb_next_wait /* wait for next byte */
907 1.1 mycroft inb_first:
908 1.1 mycroft mov DINDEX,SINDEX
909 1.4 explorer test SSTAT1,PHASEMIS jnz mesgin_phasemis
910 1.2 mycroft mov DINDIR,SCSIBUSL ret /*read byte directly from bus*/
911 1.2 mycroft inb_last:
912 1.2 mycroft mov NONE,SCSIDATL ret /*dummy read from latch to ACK*/
913 1.1 mycroft
914 1.2 mycroft mesgin_phasemis:
915 1.2 mycroft /*
916 1.2 mycroft * We expected to receive another byte, but the target changed phase
917 1.2 mycroft */
918 1.2 mycroft mvi INTSTAT, MSGIN_PHASEMIS
919 1.2 mycroft jmp ITloop
920 1.1 mycroft
921 1.2 mycroft /*
922 1.2 mycroft * DMA data transfer. HADDR and HCNT must be loaded first, and
923 1.2 mycroft * SINDEX should contain the value to load DFCNTRL with - 0x3d for
924 1.2 mycroft * host->scsi, or 0x39 for scsi->host. The SCSI channel is cleared
925 1.2 mycroft * during initialization.
926 1.2 mycroft */
927 1.1 mycroft dma:
928 1.1 mycroft mov DFCNTRL,SINDEX
929 1.1 mycroft dma1:
930 1.2 mycroft test SSTAT0,DMADONE jnz dma3
931 1.2 mycroft test SSTAT1,PHASEMIS jz dma1 /* ie. underrun */
932 1.2 mycroft
933 1.2 mycroft /*
934 1.2 mycroft * We will be "done" DMAing when the transfer count goes to zero, or
935 1.2 mycroft * the target changes the phase (in light of this, it makes sense that
936 1.2 mycroft * the DMA circuitry doesn't ACK when PHASEMIS is active). If we are
937 1.2 mycroft * doing a SCSI->Host transfer, the data FIFO should be flushed auto-
938 1.2 mycroft * magically on STCNT=0 or a phase change, so just wait for FIFO empty
939 1.2 mycroft * status.
940 1.2 mycroft */
941 1.1 mycroft dma3:
942 1.2 mycroft test SINDEX,DIRECTION jnz dma5
943 1.1 mycroft dma4:
944 1.2 mycroft test DFSTATUS,FIFOEMP jz dma4
945 1.1 mycroft
946 1.2 mycroft /*
947 1.2 mycroft * Now shut the DMA enables off and make sure that the DMA enables are
948 1.2 mycroft * actually off first lest we get an ILLSADDR.
949 1.2 mycroft */
950 1.1 mycroft dma5:
951 1.2 mycroft /* disable DMA, but maintain WIDEODD */
952 1.2 mycroft and DFCNTRL,WIDEODD
953 1.1 mycroft dma6:
954 1.2 mycroft test DFCNTRL,0x38 jnz dma6 /* SCSIENACK|SDMAENACK|HDMAENACK */
955 1.6 gibbs return:
956 1.1 mycroft ret
957 1.1 mycroft
958 1.2 mycroft /*
959 1.2 mycroft * Common SCSI initialization for selection and reselection. Expects
960 1.2 mycroft * the target SCSI ID to be in the upper four bits of SINDEX, and A's
961 1.2 mycroft * contents are stomped on return.
962 1.2 mycroft */
963 1.1 mycroft initialize_scsiid:
964 1.2 mycroft and SINDEX,0xf0 /* Get target ID */
965 1.1 mycroft and A,0x0f,SCSIID
966 1.1 mycroft or SINDEX,A
967 1.1 mycroft mov SCSIID,SINDEX ret
968 1.1 mycroft
969 1.2 mycroft /*
970 1.2 mycroft * Assert that if we've been reselected, then we've seen an IDENTIFY
971 1.2 mycroft * message.
972 1.2 mycroft */
973 1.1 mycroft assert:
974 1.2 mycroft test FLAGS,RESELECTED jz return /* reselected? */
975 1.2 mycroft test FLAGS,IDENTIFY_SEEN jnz return /* seen IDENTIFY? */
976 1.1 mycroft
977 1.2 mycroft mvi INTSTAT,NO_IDENT ret /* no - cause a kernel panic */
978 1.1 mycroft
979 1.2 mycroft /*
980 1.2 mycroft * Locate the SCB matching the target ID/channel/lun in SAVED_TCL, and the tag
981 1.2 mycroft * value in ARG_1. If ARG_1 == SCB_LIST_NULL, we're looking for a non-tagged
982 1.2 mycroft * SCB. Have the kernel print a warning message if it can't be found, and
983 1.2 mycroft * generate an ABORT/ABORT_TAG message to the target. SINDEX should be
984 1.2 mycroft * cleared on call.
985 1.2 mycroft */
986 1.1 mycroft findSCB:
987 1.1 mycroft mov A,SAVED_TCL
988 1.2 mycroft mov SCBPTR,SINDEX /* switch to next SCB */
989 1.2 mycroft mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
990 1.2 mycroft cmp SCB_TCL,A jne findSCB1 /* target ID/channel/lun match? */
991 1.2 mycroft test SCB_CONTROL,DISCONNECTED jz findSCB1 /*should be disconnected*/
992 1.2 mycroft test SCB_CONTROL,TAG_ENB jnz findTaggedSCB
993 1.2 mycroft cmp ARG_1,SCB_LIST_NULL je foundSCB
994 1.2 mycroft jmp findSCB1
995 1.2 mycroft findTaggedSCB:
996 1.2 mycroft mov A, ARG_1 /* Tag passed in ARG_1 */
997 1.2 mycroft cmp SCB_TAG,A jne findSCB1 /* Found it? */
998 1.2 mycroft foundSCB:
999 1.2 mycroft test FLAGS,PAGESCBS jz foundSCB_ret
1000 1.2 mycroft /* Remove this SCB from the disconnection list */
1001 1.2 mycroft cmp SCB_NEXT,SCB_LIST_NULL je unlink_prev
1002 1.2 mycroft mov SAVED_LINKPTR, SCB_PREV
1003 1.2 mycroft mov SCBPTR, SCB_NEXT
1004 1.2 mycroft mov SCB_PREV, SAVED_LINKPTR
1005 1.2 mycroft mov SCBPTR, SINDEX
1006 1.2 mycroft unlink_prev:
1007 1.2 mycroft cmp SCB_PREV,SCB_LIST_NULL je rHead/* At the head of the list */
1008 1.2 mycroft mov SAVED_LINKPTR, SCB_NEXT
1009 1.2 mycroft mov SCBPTR, SCB_PREV
1010 1.2 mycroft mov SCB_NEXT, SAVED_LINKPTR
1011 1.2 mycroft mov SCBPTR, SINDEX
1012 1.2 mycroft mvi SEQCTL,0x10 ret /* !PAUSEDIS|FASTMODE */
1013 1.2 mycroft rHead:
1014 1.2 mycroft mov DISCONNECTED_SCBH,SCB_NEXT
1015 1.2 mycroft foundSCB_ret:
1016 1.2 mycroft mvi SEQCTL,0x10 ret /* !PAUSEDIS|FASTMODE */
1017 1.1 mycroft
1018 1.1 mycroft findSCB1:
1019 1.2 mycroft mvi SEQCTL,0x10 /* !PAUSEDIS|FASTMODE */
1020 1.1 mycroft inc SINDEX
1021 1.1 mycroft mov A,SCBCOUNT
1022 1.1 mycroft cmp SINDEX,A jne findSCB
1023 1.1 mycroft
1024 1.2 mycroft mvi INTSTAT,NO_MATCH /* not found - signal kernel */
1025 1.2 mycroft cmp RETURN_1,SCB_PAGEDIN je return
1026 1.2 mycroft or SCSISIGO,ATNO /* assert ATNO */
1027 1.2 mycroft cmp ARG_1,SCB_LIST_NULL jne find_abort_tag
1028 1.2 mycroft mvi MSG_ABORT call mk_mesg
1029 1.2 mycroft jmp ITloop
1030 1.2 mycroft find_abort_tag:
1031 1.2 mycroft mvi MSG_ABORT_TAG call mk_mesg
1032 1.2 mycroft jmp ITloop
1033 1.1 mycroft
1034 1.2 mycroft /*
1035 1.2 mycroft * Make a working copy of the scatter-gather parameters from the SCB.
1036 1.2 mycroft */
1037 1.1 mycroft sg_scb2ram:
1038 1.7 leo #if BIG_ENDIAN_CPU
1039 1.7 leo mov HADDR3, SCB_DATAPTR0
1040 1.7 leo mov HADDR2, SCB_DATAPTR1
1041 1.7 leo mov HADDR1, SCB_DATAPTR2
1042 1.7 leo mov HADDR0, SCB_DATAPTR3
1043 1.7 leo mov HCNT0, SCB_DATACNT3
1044 1.7 leo mov HCNT1, SCB_DATACNT2
1045 1.7 leo mov HCNT2, SCB_DATACNT1
1046 1.7 leo #else
1047 1.2 mycroft mov HADDR0, SCB_DATAPTR0
1048 1.2 mycroft mov HADDR1, SCB_DATAPTR1
1049 1.2 mycroft mov HADDR2, SCB_DATAPTR2
1050 1.2 mycroft mov HADDR3, SCB_DATAPTR3
1051 1.2 mycroft mov HCNT0, SCB_DATACNT0
1052 1.2 mycroft mov HCNT1, SCB_DATACNT1
1053 1.2 mycroft mov HCNT2, SCB_DATACNT2
1054 1.7 leo #endif
1055 1.2 mycroft
1056 1.2 mycroft mov STCNT0, HCNT0
1057 1.2 mycroft mov STCNT1, HCNT1
1058 1.2 mycroft mov STCNT2, HCNT2
1059 1.2 mycroft
1060 1.2 mycroft mov SG_COUNT,SCB_SGCOUNT
1061 1.2 mycroft
1062 1.7 leo #if BIG_ENDIAN_CPU
1063 1.7 leo mov SG_NEXT3, SCB_SGPTR0
1064 1.7 leo mov SG_NEXT2, SCB_SGPTR1
1065 1.7 leo mov SG_NEXT1, SCB_SGPTR2
1066 1.7 leo mov SG_NEXT0, SCB_SGPTR3 ret
1067 1.7 leo #else
1068 1.2 mycroft mov SG_NEXT0, SCB_SGPTR0
1069 1.2 mycroft mov SG_NEXT1, SCB_SGPTR1
1070 1.2 mycroft mov SG_NEXT2, SCB_SGPTR2
1071 1.2 mycroft mov SG_NEXT3, SCB_SGPTR3 ret
1072 1.7 leo #endif
1073 1.2 mycroft
1074 1.2 mycroft /*
1075 1.2 mycroft * Copying RAM values back to SCB, for Save Data Pointers message, but
1076 1.2 mycroft * only if we've actually been into a data phase to change them. This
1077 1.2 mycroft * protects against bogus data in scratch ram and the residual counts
1078 1.2 mycroft * since they are only initialized when we go into data_in or data_out.
1079 1.2 mycroft */
1080 1.1 mycroft sg_ram2scb:
1081 1.2 mycroft test FLAGS, DPHASE jz return
1082 1.2 mycroft mov SCB_SGCOUNT,SG_COUNT
1083 1.1 mycroft
1084 1.7 leo #if BIG_ENDIAN_CPU
1085 1.7 leo mov SCB_SGPTR3,SG_NEXT0
1086 1.7 leo mov SCB_SGPTR2,SG_NEXT1
1087 1.7 leo mov SCB_SGPTR1,SG_NEXT2
1088 1.7 leo mov SCB_SGPTR0,SG_NEXT3
1089 1.7 leo mov SCB_DATAPTR3,SHADDR0
1090 1.7 leo mov SCB_DATAPTR2,SHADDR1
1091 1.7 leo mov SCB_DATAPTR1,SHADDR2
1092 1.7 leo mov SCB_DATAPTR0,SHADDR3
1093 1.7 leo #else
1094 1.2 mycroft mov SCB_SGPTR0,SG_NEXT0
1095 1.2 mycroft mov SCB_SGPTR1,SG_NEXT1
1096 1.2 mycroft mov SCB_SGPTR2,SG_NEXT2
1097 1.2 mycroft mov SCB_SGPTR3,SG_NEXT3
1098 1.2 mycroft mov SCB_DATAPTR0,SHADDR0
1099 1.2 mycroft mov SCB_DATAPTR1,SHADDR1
1100 1.2 mycroft mov SCB_DATAPTR2,SHADDR2
1101 1.2 mycroft mov SCB_DATAPTR3,SHADDR3
1102 1.7 leo #endif
1103 1.7 leo
1104 1.2 mycroft
1105 1.2 mycroft /*
1106 1.2 mycroft * Use the residual number since STCNT is corrupted by any message transfer
1107 1.2 mycroft */
1108 1.7 leo #if BIG_ENDIAN_CPU
1109 1.7 leo mov SCB_DATACNT3,SCB_RESID_DCNT0
1110 1.7 leo mov SCB_DATACNT2,SCB_RESID_DCNT1
1111 1.7 leo mov SCB_DATACNT1,SCB_RESID_DCNT2 ret
1112 1.7 leo #else
1113 1.2 mycroft mov SCB_DATACNT0,SCB_RESID_DCNT0
1114 1.2 mycroft mov SCB_DATACNT1,SCB_RESID_DCNT1
1115 1.2 mycroft mov SCB_DATACNT2,SCB_RESID_DCNT2 ret
1116 1.7 leo #endif
1117 1.2 mycroft
1118 1.2 mycroft /*
1119 1.2 mycroft * Add the array base TARG_SCRATCH to the target offset (the target address
1120 1.2 mycroft * is in SCSIID), and return the result in SINDEX. The accumulator
1121 1.2 mycroft * contains the 3->8 decoding of the target ID on return.
1122 1.2 mycroft */
1123 1.1 mycroft ndx_dtr:
1124 1.1 mycroft shr A,SCSIID,4
1125 1.2 mycroft test SBLKCTL,SELBUSB jz ndx_dtr_2
1126 1.2 mycroft or A,0x08 /* Channel B entries add 8 */
1127 1.1 mycroft ndx_dtr_2:
1128 1.2 mycroft add SINDEX,TARG_SCRATCH,A ret
1129