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