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