Deleted Added
full compact
aic7xxx.seq (19906) aic7xxx.seq (19921)
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,

--- 25 unchanged lines hidden (view full) ---

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
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,

--- 25 unchanged lines hidden (view full) ---

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.49 1996/11/16 01:07:34 gibbs Exp $"
42VERSION AIC7XXX_SEQ_VER "$Id: aic7xxx.seq,v 1.50 1996/11/21 06:18:33 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

--- 26 unchanged lines hidden (view full) ---

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 */
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

--- 26 unchanged lines hidden (view full) ---

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 */
85
86p_busfree:
87 mvi LASTPHASE, P_BUSFREE
88
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 */

--- 45 unchanged lines hidden (view full) ---

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
89start:
90 and FLAGS,0x07 /* clear target specific flags */
91 mvi SCSISEQ,ENRSELI /* Always allow reselection */
92 clr SCSIRATE /*
93 * We don't know the target we will
94 * connect to, so default to narrow
95 * transfers to avoid parity problems.
96 */

--- 45 unchanged lines hidden (view full) ---

142 mvi DMAPARAMS, 0xd /* HDMAEN|DIRECTION|FIFORESET */
143 mov CUR_SCBID call dma_scb
144
145/*
146 * See if there is not already an active SCB for this target. This code
147 * locks out on a per target basis instead of target/lun. Although this
148 * is not ideal for devices that have multiple luns active at the same
149 * 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 * commands. We also don't have enough spare SCB space for us 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 /*

--- 154 unchanged lines hidden (view full) ---

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 */
151 * SCBID of the currently busy transaction for each target/lun making it
152 * impossible to link up the SCBs.
153 */
154test_busy:
155 test SCB_CONTROL, TAG_ENB jnz start_scb
156 mov SAVED_SCBPTR, SCBPTR
157 mov SCB_TCL call index_untagged_scb
158 mov ARG_1, SINDIR /*

--- 154 unchanged lines hidden (view full) ---

313 mov SXFRCTL0,DINDEX
314
315 mvi SCSISEQ,ENAUTOATNP /*
316 * ATN on parity errors
317 * for "in" phases
318 */
319 mvi CLRSINT1,CLRBUSFREE
320 mvi CLRSINT0,0x60 /* CLRSELDI|CLRSELDO */
321 or SIMODE1, ENBUSFREE /*
322 * We aren't expecting a
323 * bus free, so interrupt
324 * the kernel driver if it
325 * happens.
326 */
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:

--- 67 unchanged lines hidden (view full) ---

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
327/*
328 * Main loop for information transfer phases. If BSY is false, then
329 * we have a bus free condition, expected or not. Otherwise, wait
330 * for the target to assert REQ before checking MSG, C/D and I/O
331 * for the bus phase.
332 *
333 */
334ITloop:

--- 67 unchanged lines hidden (view full) ---

402 test SG_COUNT, 0xff jnz data_phase_inbounds
403/*
404 * Turn on 'Bit Bucket' mode, set the transfer count to
405 * 16meg and let the target run until it changes phase.
406 * When the transfer completes, notify the host that we
407 * had an overrun.
408 */
409 or SXFRCTL1,BITBUCKET
410 and DMAPARAMS, 0xf7 /* Turn off HDMAEN */
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 */

--- 120 unchanged lines hidden (view full) ---

531/*
532 * When target asks for a byte, drop ATN if it's the last one in
533 * the message. Otherwise, keep going until the message is exhausted.
534 *
535 * Keep an eye out for a phase change, in case the target issues
536 * a MESSAGE REJECT.
537 */
538p_mesgout_loop:
411 mvi STCNT0,0xff
412 mvi STCNT1,0xff
413 mvi STCNT2,0xff
414
415data_phase_inbounds:
416/* If we are the last SG block, ensure wideodd is off. */
417 cmp SG_COUNT,0x01 jne data_phase_wideodd
418 and DMAPARAMS, 0xbf /* Turn off WIDEODD */

--- 120 unchanged lines hidden (view full) ---

539/*
540 * When target asks for a byte, drop ATN if it's the last one in
541 * the message. Otherwise, keep going until the message is exhausted.
542 *
543 * Keep an eye out for a phase change, in case the target issues
544 * a MESSAGE REJECT.
545 */
546p_mesgout_loop:
539 test SSTAT1,BUSFREE jnz p_mesgout_done
540 test SSTAT0,SPIORDY jz p_mesgout_loop
541 test SSTAT1,PHASEMIS jnz p_mesgout_done
542/*
543 * If the next bus phase after ATN drops is a message out, it means
544 * that the target is requesting that the last message(s) be resent.
545 */
547 test SSTAT0,SPIORDY jz p_mesgout_loop
548 test SSTAT1,PHASEMIS jnz p_mesgout_done
549/*
550 * If the next bus phase after ATN drops is a message out, it means
551 * that the target is requesting that the last message(s) be resent.
552 */
553p_mesgout_dropatn:
554 cmp DINDEX,1 jne p_mesgout_testretry /* last byte? */
555 mvi CLRSINT1,CLRATNO /* drop ATN */
556p_mesgout_testretry:
546 test DINDEX,0xff jnz p_mesgout_outb
547 or SCSISIGO,ATNO /* turn on ATN for the retry */
548 jmp p_mesgout_start
549p_mesgout_outb:
557 test DINDEX,0xff jnz p_mesgout_outb
558 or SCSISIGO,ATNO /* turn on ATN for the retry */
559 jmp p_mesgout_start
560p_mesgout_outb:
550 cmp DINDEX,1 jne p_mesgout_outb2 /* last byte? */
551 mvi CLRSINT1,CLRATNO /* drop ATN */
552p_mesgout_outb2:
553 dec DINDEX
554 mvi CLRSINT0, CLRSPIORDY
555 mov SCSIDATL,SINDIR
556 jmp p_mesgout_loop
557
558p_mesgout_done:
559 mvi CLRSINT1,CLRATNO /* Be sure to turn ATNO off */
560 clr MSG_LEN /* no active msg */

--- 44 unchanged lines hidden (view full) ---

605 * If the kernel driver does not wish to request sense, it need only clear
606 * RETURN_1, and the command is allowed to complete normally. We don't bother
607 * to post to the QOUTFIFO in the error cases since it would require extra
608 * work in the kernel driver to ensure that the entry was removed before the
609 * command complete code tried processing it.
610 */
611
612/*
561 dec DINDEX
562 mvi CLRSINT0, CLRSPIORDY
563 mov SCSIDATL,SINDIR
564 jmp p_mesgout_loop
565
566p_mesgout_done:
567 mvi CLRSINT1,CLRATNO /* Be sure to turn ATNO off */
568 clr MSG_LEN /* no active msg */

--- 44 unchanged lines hidden (view full) ---

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 * We expect to go to bus free after this message.
622 */
623 and SIMODE1, 0xf7 /* ~ENBUSFREE */
624/*
613 * First check for residuals
614 */
615 test SCB_RESID_SGCNT,0xff jnz upload_scb
616 test SCB_TARGET_STATUS,0xff jz status_ok /* Good Status? */
617upload_scb:
618 mvi DMAPARAMS, 0x9 /* HDMAEN | FIFORESET*/
619 mov SCB_TAG call dma_scb
620check_status:
621 test SCB_TARGET_STATUS,0xff jz status_ok /* Just a residual? */
622 mvi INTSTAT,BAD_STATUS /* let driver know */
623 cmp RETURN_1, SEND_SENSE jne status_ok
624 /* This SCB becomes the next to execute as it will retrieve sense */
625 mov SCB_LINKED_NEXT, SCB_TAG
626 jmp dma_next_scb
627
628status_ok:
629/* First, mark this target as free. */
625 * First check for residuals
626 */
627 test SCB_RESID_SGCNT,0xff jnz upload_scb
628 test SCB_TARGET_STATUS,0xff jz status_ok /* Good Status? */
629upload_scb:
630 mvi DMAPARAMS, 0x9 /* HDMAEN | FIFORESET*/
631 mov SCB_TAG call dma_scb
632check_status:
633 test SCB_TARGET_STATUS,0xff jz status_ok /* Just a residual? */
634 mvi INTSTAT,BAD_STATUS /* let driver know */
635 cmp RETURN_1, SEND_SENSE jne status_ok
636 /* This SCB becomes the next to execute as it will retrieve sense */
637 mov SCB_LINKED_NEXT, SCB_TAG
638 jmp dma_next_scb
639
640status_ok:
641/* First, mark this target as free. */
630 test SCB_CONTROL,TAG_ENB jnz test_immediate /*
642 test SCB_CONTROL,TAG_ENB jnz complete /*
631 * Tagged commands
632 * don't busy the
633 * target.
634 */
635 mov SAVED_SCBPTR, SCBPTR
636 mov SAVED_LINKPTR, SCB_LINKED_NEXT
637 mov SCB_TCL call index_untagged_scb
638 mov DINDIR, SAVED_LINKPTR
639 mov SCBPTR, SAVED_SCBPTR
640
643 * Tagged commands
644 * don't busy the
645 * target.
646 */
647 mov SAVED_SCBPTR, SCBPTR
648 mov SAVED_LINKPTR, SCB_LINKED_NEXT
649 mov SCB_TCL call index_untagged_scb
650 mov DINDIR, SAVED_LINKPTR
651 mov SCBPTR, SAVED_SCBPTR
652
641test_immediate:
642 test SCB_CMDLEN,0xff jnz complete /* Immediate message complete */
643/*
644 * Pause the sequencer until the driver gets around to handling the command
645 * complete. This is so that any action that might require carefull timing
646 * with the completion of this command can occur.
647 */
648 mvi INTSTAT,IMMEDDONE
649 jmp dma_next_scb
650complete:
651 test FLAGS, PAGESCBS jz complete_post
652 mov A, QFULLCNT
653complete_poll:
654 cmp QOUTQCNT, A je complete_poll
655 mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
656 inc QOUTQCNT
657complete_post:
658 /* Post the SCB and issue an interrupt */
659 mov QOUTFIFO,SCB_TAG
660 mvi SEQCTL,0x10 /* FASTMODE */
661 mvi INTSTAT,CMDCMPLT
662
663dma_next_scb:
653complete:
654 test FLAGS, PAGESCBS jz complete_post
655 mov A, QFULLCNT
656complete_poll:
657 cmp QOUTQCNT, A je complete_poll
658 mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
659 inc QOUTQCNT
660complete_post:
661 /* Post the SCB and issue an interrupt */
662 mov QOUTFIFO,SCB_TAG
663 mvi SEQCTL,0x10 /* FASTMODE */
664 mvi INTSTAT,CMDCMPLT
665
666dma_next_scb:
664 cmp SCB_LINKED_NEXT, SCB_LIST_NULL je mesgin_done
667 cmp SCB_LINKED_NEXT, SCB_LIST_NULL je add_to_free_list
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
668 test FLAGS, PAGESCBS jnz dma_next_scb2
669 /* Only DMA on top of ourselves if we are the SCB to download */
670 mov A, SCB_LINKED_NEXT
671 cmp SCB_TAG, A je dma_next_scb2
672 mov SCBPTR, A
673 jmp add_to_waiting_list
674dma_next_scb2:
675 mvi DMAPARAMS, 0xd /* HDMAEN|DIRECTION|FIFORESET */
676 mov SCB_LINKED_NEXT call dma_scb
677add_to_waiting_list:
678 mov SCB_NEXT,WAITING_SCBH
679 mov WAITING_SCBH, SCBPTR
677 or FLAGS, SCB_LISTED
678 jmp mesgin_done
680 jmp mesgin_done
681add_to_free_list:
682 call add_scb_to_free_list
683 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:

--- 14 unchanged lines hidden (view full) ---

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:
684
685/*
686 * Is it an extended message? Copy the message to our message buffer and
687 * notify the host. The host will tell us whether to reject this message,
688 * respond to it with the message that the host placed in our message buffer,
689 * or simply to do nothing.
690 */
691mesgin_extended:

--- 14 unchanged lines hidden (view full) ---

706 or SCSISIGO,ATNO /* turn on ATNO */
707 jmp mesgin_done
708
709/*
710 * Is it a disconnect message? Set a flag in the SCB to remind us
711 * and await the bus going free.
712 */
713mesgin_disconnect:
714 and SIMODE1, 0xf7 /* ~ENBUSFREE */
709 or SCB_CONTROL,DISCONNECTED
710 test FLAGS, PAGESCBS jz mesgin_done
711 call add_scb_to_disc_list
715 or SCB_CONTROL,DISCONNECTED
716 test FLAGS, PAGESCBS jz mesgin_done
717 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.

--- 46 unchanged lines hidden (view full) ---

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:
718 jmp mesgin_done
719
720/*
721 * Save data pointers message:
722 * Copying RAM values back to SCB, for Save Data Pointers message, but
723 * only if we've actually been into a data phase to change them. This
724 * protects against bogus data in scratch ram and the residual counts
725 * since they are only initialized when we go into data_in or data_out.

--- 46 unchanged lines hidden (view full) ---

772 * If we get one, we use the tag returned to switch to find the proper
773 * SCB. With SCB paging, this requires using findSCB for both tagged
774 * and non-tagged transactions since the SCB may exist in any slot.
775 * If we're not using SCB paging, we can use the tag as the direct
776 * index to the SCB.
777 */
778 mvi ARG_1,SCB_LIST_NULL /* Default to no-tag */
779snoop_tag_loop:
775 test SSTAT1,BUSFREE jnz use_findSCB
776 test SSTAT1,REQINIT jz snoop_tag_loop
780 test SSTAT0,SPIORDY 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

--- 44 unchanged lines hidden (view full) ---

829 mvi INTSTAT, REJECT_MSG
830 jmp mesgin_done
831
832/*
833 * [ ADD MORE MESSAGE HANDLING HERE ]
834 */
835
836/*
781 test SSTAT1,PHASEMIS jnz use_findSCB
782 mvi A call inb_first
783 cmp A,MSG_SIMPLE_Q_TAG jne use_findSCB
784get_tag:
785 or FLAGS, TAGGED_SCB
786 mvi ARG_1 call inb_next /* tag value */
787/*
788 * See if the tag is in range. The tag is < SCBCOUNT if we add

--- 44 unchanged lines hidden (view full) ---

833 mvi INTSTAT, REJECT_MSG
834 jmp mesgin_done
835
836/*
837 * [ ADD MORE MESSAGE HANDLING HERE ]
838 */
839
840/*
837 * Bus free phase. It might be useful to interrupt the device
838 * driver if we aren't expecting this.
839 */
840p_busfree:
841 mvi LASTPHASE, P_BUSFREE
842
843/*
844 * if this is an immediate command, perform a psuedo command complete to
845 * notify the driver.
846 */
847 test SCB_CMDLEN,0xff jz status_ok
848 test FLAGS, SCB_LISTED jnz start
849 /*
850 * This SCB didn't disconnect or have a command complete,
851 * so put it on the free queue. It was probably the
852 * result of an abort of some sort. This prevents us
853 * from "leaking" SCBs.
854 */
855 call add_scb_to_free_list
856 jmp start
857
858/*
859 * Locking the driver out, build a one-byte message passed in SINDEX
860 * if there is no active message already. SINDEX is returned intact.
861 */
862mk_mesg:
863 mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
864 test MSG_LEN,0xff jz mk_mesg1 /* Should always succeed */
865
866 /*

--- 301 unchanged lines hidden ---
841 * Locking the driver out, build a one-byte message passed in SINDEX
842 * if there is no active message already. SINDEX is returned intact.
843 */
844mk_mesg:
845 mvi SEQCTL,0x50 /* PAUSEDIS|FASTMODE */
846 test MSG_LEN,0xff jz mk_mesg1 /* Should always succeed */
847
848 /*

--- 301 unchanged lines hidden ---