2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
7 * This driver is derived from the Linux sym53c8xx driver.
8 * Copyright (C) 1998-2000 Gerard Roudier
10 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
11 * a port of the FreeBSD ncr driver to Linux-1.2.13.
13 * The original ncr driver has been written for 386bsd and FreeBSD by
14 * Wolfgang Stanglmeier <wolf@cologne.de>
15 * Stefan Esser <se@mi.Uni-Koeln.de>
16 * Copyright (C) 1994 Wolfgang Stanglmeier
18 * Other major contributions:
20 * NVRAM detection and reading.
21 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23 *-----------------------------------------------------------------------------
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 * Scripts for SYMBIOS-Processor
43 * We have to know the offsets of all labels before we reach
44 * them (for forward jumps). Therefore we declare a struct
45 * here. If you make changes inside the script,
47 * DONT FORGET TO CHANGE THE LENGTHS HERE!
51 * Script fragments which are loaded into the on-chip RAM
52 * of 825A, 875, 876, 895, 895A, 896 and 1010 chips.
53 * Must not exceed 4K bytes.
57 u32 getjob_begin [ 4];
61 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
69 #ifdef SYM_CONF_IARB_SUPPORT
80 u32 datai_done_wsr [ 20];
82 u32 datao_done_wss [ 6];
87 #ifdef SYM_CONF_IARB_SUPPORT
99 u32 complete_error [ 5];
102 u32 disconnect [ 11];
103 u32 disconnect2 [ 5];
105 #ifdef SYM_CONF_IARB_SUPPORT
110 #ifdef SYM_CONF_IARB_SUPPORT
115 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
120 u32 reselected [ 19];
123 u32 reselected1 [ 25];
128 #if SYM_CONF_MAX_TASK*4 > 512
130 #elif SYM_CONF_MAX_TASK*4 > 256
141 u32 resel_no_tag [ 4];
143 u32 data_in [SYM_CONF_MAX_SG * 2];
145 u32 data_out [SYM_CONF_MAX_SG * 2];
148 u32 pm0_data_out [ 6];
149 u32 pm0_data_end [ 7];
150 u32 pm_data_end [ 4];
153 u32 pm1_data_out [ 6];
154 u32 pm1_data_end [ 9];
158 * Script fragments which stay in main memory for all chips
159 * except for chips that support 8K on-chip RAM.
163 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
164 u32 sel_for_abort [ 18];
166 u32 sel_for_abort [ 16];
168 u32 sel_for_abort_1 [ 2];
169 u32 msg_in_etc [ 12];
170 u32 msg_received [ 5];
171 u32 msg_weird_seen [ 5];
172 u32 msg_extended [ 17];
183 u32 nego_bad_phase [ 4];
185 u32 msg_out_done [ 4];
187 u32 data_ovrun1 [ 22];
188 u32 data_ovrun2 [ 8];
189 u32 abort_resel [ 16];
190 u32 resend_ident [ 4];
191 u32 ident_break [ 4];
192 u32 ident_break_atn [ 4];
194 u32 resel_bad_lun [ 4];
196 u32 bad_i_t_l_q [ 4];
198 u32 wsr_ma_helper [ 4];
212 * Script fragments used at initialisations.
213 * Only runs out of main memory.
220 static struct SYM_FWA_SCR SYM_FWA_SCR = {
221 /*--------------------------< START >----------------------------*/ {
224 * Will be patched with a NO_OP if LED
225 * not needed or not desired.
227 SCR_REG_REG (gpreg, SCR_AND, 0xfe),
232 SCR_FROM_REG (ctest2),
235 * Stop here if the C code wants to perform
236 * some error recovery procedure manually.
237 * (Indicate this by setting SEM in ISTAT)
239 SCR_FROM_REG (istat),
242 * Report to the C code the next position in
243 * the start queue the SCRIPTS will schedule.
244 * The C code must not change SCRATCHA.
249 SCR_INT ^ IFTRUE (MASK (SEM, SEM)),
252 * Start the next job.
254 * @DSA = start point for this job.
255 * SCRATCHA = address of this job in the start queue.
257 * We will restore startpos with SCRATCHA if we fails the
258 * arbitration or if it is the idle job.
260 * The below GETJOB_BEGIN to GETJOB_END section of SCRIPTS
261 * is a critical path. If it is partially executed, it then
262 * may happen that the job address is not yet in the DSA
263 * and the next queue position points to the next JOB.
265 }/*-------------------------< GETJOB_BEGIN >---------------------*/,{
267 * Copy to a fixed location both the next STARTPOS
268 * and the current JOB address, using self modifying
275 }/*-------------------------< _SMS_A10 >-------------------------*/,{
279 * Move the start address to TEMP using self-
280 * modifying SCRIPTS and jump indirectly to
286 }/*-------------------------< GETJOB_END >-----------------------*/,{
291 }/*-------------------------< _SMS_A20 >-------------------------*/,{
296 }/*-------------------------< SELECT >---------------------------*/,{
298 * DSA contains the address of a scheduled
301 * SCRATCHA contains the address of the start queue
302 * entry which points to the next job.
304 * Set Initiator mode.
306 * (Target mode is left as an exercise for the reader)
308 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
313 * And try to select this target.
315 SCR_SEL_TBL_ATN ^ offsetof (struct sym_dsb, select),
318 * Now there are 4 possibilities:
320 * (1) The chip loses arbitration.
321 * This is ok, because it will try again,
322 * when the bus becomes idle.
323 * (But beware of the timeout function!)
325 * (2) The chip is reselected.
326 * Then the script processor takes the jump
327 * to the RESELECT label.
329 * (3) The chip wins arbitration.
330 * Then it will execute SCRIPTS instruction until
331 * the next instruction that checks SCSI phase.
332 * Then will stop and wait for selection to be
333 * complete or selection time-out to occur.
335 * After having won arbitration, the SCRIPTS
336 * processor is able to execute instructions while
337 * the SCSI core is performing SCSI selection.
341 * Copy the CCB header to a fixed location
342 * in the HCB using self-modifying SCRIPTS.
347 SCR_COPY (sizeof(struct sym_ccbh)),
348 }/*-------------------------< _SMS_A30 >-------------------------*/,{
352 * Initialize the status register
355 HADDR_1 (ccb_head.status),
357 }/*-------------------------< WF_SEL_DONE >----------------------*/,{
358 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_OUT)),
359 SIR_SEL_ATN_NO_MSG_OUT,
360 }/*-------------------------< SEND_IDENT >-----------------------*/,{
362 * Selection complete.
363 * Send the IDENTIFY and possibly the TAG message
364 * and negotiation message if present.
366 SCR_MOVE_TBL ^ SCR_MSG_OUT,
367 offsetof (struct sym_dsb, smsg),
368 }/*-------------------------< SELECT2 >--------------------------*/,{
369 #ifdef SYM_CONF_IARB_SUPPORT
371 * Set IMMEDIATE ARBITRATION if we have been given
372 * a hint to do so. (Some job to do after this one).
374 SCR_FROM_REG (HF_REG),
376 SCR_JUMPR ^ IFFALSE (MASK (HF_HINT_IARB, HF_HINT_IARB)),
378 SCR_REG_REG (scntl1, SCR_OR, IARB),
382 * Anticipate the COMMAND phase.
383 * This is the PHASE we expect at this point.
385 SCR_JUMP ^ IFFALSE (WHEN (SCR_COMMAND)),
386 PADDR_A (sel_no_cmd),
387 }/*-------------------------< COMMAND >--------------------------*/,{
389 * ... and send the command
391 SCR_MOVE_TBL ^ SCR_COMMAND,
392 offsetof (struct sym_dsb, cmd),
393 }/*-------------------------< DISPATCH >-------------------------*/,{
395 * MSG_IN is the only phase that shall be
396 * entered at least once for each (re)selection.
397 * So we test it first.
399 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
401 SCR_JUMP ^ IFTRUE (IF (SCR_DATA_OUT)),
402 PADDR_A (datao_phase),
403 SCR_JUMP ^ IFTRUE (IF (SCR_DATA_IN)),
404 PADDR_A (datai_phase),
405 SCR_JUMP ^ IFTRUE (IF (SCR_STATUS)),
407 SCR_JUMP ^ IFTRUE (IF (SCR_COMMAND)),
409 SCR_JUMP ^ IFTRUE (IF (SCR_MSG_OUT)),
412 * Discard as many illegal phases as
413 * required and tell the C code about.
415 SCR_JUMPR ^ IFFALSE (WHEN (SCR_ILG_OUT)),
417 SCR_MOVE_ABS (1) ^ SCR_ILG_OUT,
419 SCR_JUMPR ^ IFTRUE (WHEN (SCR_ILG_OUT)),
421 SCR_JUMPR ^ IFFALSE (WHEN (SCR_ILG_IN)),
423 SCR_MOVE_ABS (1) ^ SCR_ILG_IN,
425 SCR_JUMPR ^ IFTRUE (WHEN (SCR_ILG_IN)),
431 }/*-------------------------< SEL_NO_CMD >-----------------------*/,{
433 * The target does not switch to command
434 * phase after IDENTIFY has been sent.
436 * If it stays in MSG OUT phase send it
437 * the IDENTIFY again.
439 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
440 PADDR_B (resend_ident),
442 * If target does not switch to MSG IN phase
443 * and we sent a negotiation, assert the
444 * failure immediately.
446 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
448 SCR_FROM_REG (HS_REG),
450 SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
453 * Jump to dispatcher.
457 }/*-------------------------< INIT >-----------------------------*/,{
459 * Wait for the SCSI RESET signal to be
460 * inactive before restarting operations,
461 * since the chip may hang on SEL_ATN
462 * if SCSI RESET is active.
464 SCR_FROM_REG (sstat0),
466 SCR_JUMPR ^ IFTRUE (MASK (IRST, IRST)),
470 }/*-------------------------< CLRACK >---------------------------*/,{
472 * Terminate possible pending message phase.
478 }/*-------------------------< DATAI_DONE >-----------------------*/,{
480 * Save current pointer to LASTP.
484 HADDR_1 (ccb_head.lastp),
486 * If the SWIDE is not full, jump to dispatcher.
487 * We anticipate a STATUS phase.
489 SCR_FROM_REG (scntl2),
491 SCR_JUMP ^ IFTRUE (MASK (WSR, WSR)),
492 PADDR_A (datai_done_wsr),
493 SCR_JUMP ^ IFTRUE (WHEN (SCR_STATUS)),
497 }/*-------------------------< DATAI_DONE_WSR >-------------------*/,{
500 * Clear this condition.
502 SCR_REG_REG (scntl2, SCR_OR, WSR),
505 * We are expecting an IGNORE RESIDUE message
506 * from the device, otherwise we are in data
507 * overrun condition. Check against MSG_IN phase.
509 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_IN)),
511 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
514 * We are in MSG_IN phase,
515 * Read the first byte of the message.
516 * If it is not an IGNORE RESIDUE message,
517 * signal overrun and jump to message
520 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
522 SCR_INT ^ IFFALSE (DATA (M_IGN_RESIDUE)),
524 SCR_JUMP ^ IFFALSE (DATA (M_IGN_RESIDUE)),
527 * We got the message we expected.
528 * Read the 2nd byte, and jump to dispatcher.
532 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
538 }/*-------------------------< DATAO_DONE >-----------------------*/,{
540 * Save current pointer to LASTP.
544 HADDR_1 (ccb_head.lastp),
546 * If the SODL is not full jump to dispatcher.
547 * We anticipate a STATUS phase.
549 SCR_FROM_REG (scntl2),
551 SCR_JUMP ^ IFTRUE (MASK (WSS, WSS)),
552 PADDR_A (datao_done_wss),
553 SCR_JUMP ^ IFTRUE (WHEN (SCR_STATUS)),
557 }/*-------------------------< DATAO_DONE_WSS >-------------------*/,{
559 * The SODL is full, clear this condition.
561 SCR_REG_REG (scntl2, SCR_OR, WSS),
564 * And signal a DATA UNDERRUN condition
571 }/*-------------------------< DATAI_PHASE >----------------------*/,{
573 * Jump to current pointer.
576 HADDR_1 (ccb_head.lastp),
580 }/*-------------------------< DATAO_PHASE >----------------------*/,{
582 * Jump to current pointer.
585 HADDR_1 (ccb_head.lastp),
589 }/*-------------------------< MSG_IN >---------------------------*/,{
591 * Get the first byte of the message.
593 * The script processor doesn't negate the
594 * ACK signal after this transfer.
596 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
598 }/*-------------------------< MSG_IN2 >--------------------------*/,{
600 * Check first against 1 byte messages
601 * that we handle from SCRIPTS.
603 SCR_JUMP ^ IFTRUE (DATA (M_COMPLETE)),
605 SCR_JUMP ^ IFTRUE (DATA (M_DISCONNECT)),
606 PADDR_A (disconnect),
607 SCR_JUMP ^ IFTRUE (DATA (M_SAVE_DP)),
609 SCR_JUMP ^ IFTRUE (DATA (M_RESTORE_DP)),
610 PADDR_A (restore_dp),
612 * We handle all other messages from the
613 * C code, so no need to waste on-chip RAM
617 PADDR_B (msg_in_etc),
618 }/*-------------------------< STATUS >---------------------------*/,{
622 SCR_MOVE_ABS (1) ^ SCR_STATUS,
624 #ifdef SYM_CONF_IARB_SUPPORT
626 * If STATUS is not GOOD, clear IMMEDIATE ARBITRATION,
627 * since we may have to tamper the start queue from
630 SCR_JUMPR ^ IFTRUE (DATA (S_GOOD)),
632 SCR_REG_REG (scntl1, SCR_AND, ~IARB),
636 * save status to scsi_status.
641 SCR_LOAD_REG (HS_REG, HS_COMPLETE),
644 * Anticipate the MESSAGE PHASE for
645 * the TASK COMPLETE message.
647 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
651 }/*-------------------------< COMPLETE >-------------------------*/,{
655 * When we terminate the cycle by clearing ACK,
656 * the target may disconnect immediately.
658 * We don't want to be told of an "unexpected disconnect",
659 * so we disable this feature.
661 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
664 * Terminate cycle ...
666 SCR_CLR (SCR_ACK|SCR_ATN),
669 * ... and wait for the disconnect.
673 }/*-------------------------< COMPLETE2 >------------------------*/,{
679 HADDR_1 (ccb_head.status),
681 * Move back the CCB header using self-modifying
687 SCR_COPY (sizeof(struct sym_ccbh)),
689 }/*-------------------------< _SMS_A40 >-------------------------*/,{
692 * Some bridges may reorder DMA writes to memory.
693 * We donnot want the CPU to deal with completions
694 * without all the posted write having been flushed
695 * to memory. This DUMMY READ should flush posted
696 * buffers prior to the CPU having to deal with
699 SCR_COPY (4), /* DUMMY READ */
700 HADDR_1 (ccb_head.status),
703 * If command resulted in not GOOD status,
704 * call the C code if needed.
706 SCR_FROM_REG (SS_REG),
708 SCR_CALL ^ IFFALSE (DATA (S_GOOD)),
709 PADDR_B (bad_status),
711 * If we performed an auto-sense, call
712 * the C code to synchronyze task aborts
713 * with UNIT ATTENTION conditions.
715 SCR_FROM_REG (HF_REG),
717 SCR_JUMP ^ IFFALSE (MASK (0 ,(HF_SENSE|HF_EXT_ERR))),
718 PADDR_A (complete_error),
719 }/*-------------------------< DONE >-----------------------------*/,{
721 * Copy the DSA to the DONE QUEUE and
722 * signal completion to the host.
723 * If we are interrupted between DONE
724 * and DONE_END, we must reset, otherwise
725 * the completed CCB may be lost.
732 }/*-------------------------< _SMS_A50 >-------------------------*/,{
738 * The instruction below reads the DONE QUEUE next
739 * free position from memory.
740 * In addition it ensures that all PCI posted writes
741 * are flushed and so the DSA value of the done
742 * CCB is visible by the CPU before INTFLY is raised.
745 }/*-------------------------< _SMS_A60 >-------------------------*/,{
748 }/*-------------------------< DONE_END >-------------------------*/,{
753 }/*-------------------------< COMPLETE_ERROR >-------------------*/,{
759 }/*-------------------------< SAVE_DP >--------------------------*/,{
761 * Clear ACK immediately.
762 * No need to delay it.
767 * Keep track we received a SAVE DP, so
768 * we will switch to the other PM context
769 * on the next PM since the DP may point
770 * to the current PM context.
772 SCR_REG_REG (HF_REG, SCR_OR, HF_DP_SAVED),
776 * Copy LASTP to SAVEP.
779 HADDR_1 (ccb_head.lastp),
780 HADDR_1 (ccb_head.savep),
782 * Anticipate the MESSAGE PHASE for
783 * the DISCONNECT message.
785 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
789 }/*-------------------------< RESTORE_DP >-----------------------*/,{
791 * Clear ACK immediately.
792 * No need to delay it.
797 * Copy SAVEP to LASTP.
800 HADDR_1 (ccb_head.savep),
801 HADDR_1 (ccb_head.lastp),
804 }/*-------------------------< DISCONNECT >-----------------------*/,{
808 * disable the "unexpected disconnect" feature,
809 * and remove the ACK signal.
811 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
813 SCR_CLR (SCR_ACK|SCR_ATN),
816 * Wait for the disconnect.
821 * Status is: DISCONNECTED.
823 SCR_LOAD_REG (HS_REG, HS_DISCONNECT),
830 HADDR_1 (ccb_head.status),
831 }/*-------------------------< DISCONNECT2 >----------------------*/,{
833 * Move back the CCB header using self-modifying
839 SCR_COPY (sizeof(struct sym_ccbh)),
841 }/*-------------------------< _SMS_A65 >-------------------------*/,{
845 }/*-------------------------< IDLE >-----------------------------*/,{
848 * Switch the LED off and wait for reselect.
849 * Will be patched with a NO_OP if LED
850 * not needed or not desired.
852 SCR_REG_REG (gpreg, SCR_OR, 0x01),
854 #ifdef SYM_CONF_IARB_SUPPORT
858 }/*-------------------------< UNGETJOB >-------------------------*/,{
859 #ifdef SYM_CONF_IARB_SUPPORT
861 * Set IMMEDIATE ARBITRATION, for the next time.
862 * This will give us better chance to win arbitration
863 * for the job we just wanted to do.
865 SCR_REG_REG (scntl1, SCR_OR, IARB),
869 * We are not able to restart the SCRIPTS if we are
870 * interrupted and these instruction haven't been
871 * all executed. BTW, this is very unlikely to
872 * happen, but we check that from the C code.
874 SCR_LOAD_REG (dsa, 0xff),
879 }/*-------------------------< RESELECT >-------------------------*/,{
880 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
882 * Make sure we are in initiator mode.
888 * Sleep waiting for a reselection.
892 }/*-------------------------< RESELECTED >-----------------------*/,{
895 * Will be patched with a NO_OP if LED
896 * not needed or not desired.
898 SCR_REG_REG (gpreg, SCR_AND, 0xfe),
901 * load the target id into the sdid
903 SCR_REG_SFBR (ssid, SCR_AND, 0x8F),
908 * Load the target control block address
913 SCR_SFBR_REG (dsa, SCR_SHL, 0),
915 SCR_REG_REG (dsa, SCR_SHL, 0),
917 SCR_REG_REG (dsa, SCR_AND, 0x3c),
923 }/*-------------------------< _SMS_A70 >-------------------------*/,{
927 * Copy the TCB header to a fixed place in
933 SCR_COPY (sizeof(struct sym_tcbh)),
934 }/*-------------------------< _SMS_A80 >-------------------------*/,{
938 * We expect MESSAGE IN phase.
939 * If not, get help from the C code.
941 SCR_INT ^ IFFALSE (WHEN (SCR_MSG_IN)),
943 }/*-------------------------< RESELECTED1 >----------------------*/,{
945 * Load the synchronous transfer registers.
948 HADDR_1 (tcb_head.wval),
951 HADDR_1 (tcb_head.sval),
954 * Get the IDENTIFY message.
956 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
959 * If IDENTIFY LUN #0, use a faster path
960 * to find the LCB structure.
962 SCR_JUMP ^ IFTRUE (MASK (0x80, 0xbf)),
963 PADDR_A (resel_lun0),
965 * If message isn't an IDENTIFY,
966 * tell the C code about.
968 SCR_INT ^ IFFALSE (MASK (0x80, 0x80)),
969 SIR_RESEL_NO_IDENTIFY,
971 * It is an IDENTIFY message,
972 * Load the LUN control block address.
975 HADDR_1 (tcb_head.luntbl_sa),
977 SCR_SFBR_REG (dsa, SCR_SHL, 0),
979 SCR_REG_REG (dsa, SCR_SHL, 0),
981 SCR_REG_REG (dsa, SCR_AND, 0xfc),
987 }/*-------------------------< _SMS_A90 >-------------------------*/,{
992 }/*-------------------------< RESEL_LUN0 >-----------------------*/,{
994 * LUN 0 special case (but usual one :))
997 HADDR_1 (tcb_head.lun0_sa),
1000 * Jump indirectly to the reselect action for this LUN.
1001 * (lcb.head.resel_sa assumed at offset zero of lcb).
1005 PADDR_A (_sms_a100),
1007 }/*-------------------------< _SMS_A100 >------------------------*/,{
1012 /* In normal situations, we jump to RESEL_TAG or RESEL_NO_TAG */
1013 }/*-------------------------< RESEL_TAG >------------------------*/,{
1015 * ACK the IDENTIFY previously received.
1020 * It shall be a tagged command.
1022 * The C code will deal with errors.
1023 * Aggressive optimization, isn't it? :)
1025 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
1028 * Copy the LCB header to a fixed place in
1029 * the HCB using self-modifying SCRIPTS.
1033 PADDR_A (_sms_a110),
1034 SCR_COPY (sizeof(struct sym_lcbh)),
1035 }/*-------------------------< _SMS_A110 >------------------------*/,{
1039 * Load the pointer to the tagged task
1040 * table for this LUN.
1043 HADDR_1 (lcb_head.itlq_tbl_sa),
1046 * The SIDL still contains the TAG value.
1047 * Aggressive optimization, isn't it? :):)
1049 SCR_REG_SFBR (sidl, SCR_SHL, 0),
1051 #if SYM_CONF_MAX_TASK*4 > 512
1052 SCR_JUMPR ^ IFFALSE (CARRYSET),
1054 SCR_REG_REG (dsa1, SCR_OR, 2),
1056 SCR_REG_REG (sfbr, SCR_SHL, 0),
1058 SCR_JUMPR ^ IFFALSE (CARRYSET),
1060 SCR_REG_REG (dsa1, SCR_OR, 1),
1062 #elif SYM_CONF_MAX_TASK*4 > 256
1063 SCR_JUMPR ^ IFFALSE (CARRYSET),
1065 SCR_REG_REG (dsa1, SCR_OR, 1),
1069 * Retrieve the DSA of this task.
1070 * JUMP indirectly to the restart point of the CCB.
1072 SCR_SFBR_REG (dsa, SCR_AND, 0xfc),
1076 PADDR_A (_sms_a120),
1078 }/*-------------------------< _SMS_A120 >------------------------*/,{
1081 }/*-------------------------< RESEL_GO >-------------------------*/,{
1084 PADDR_A (_sms_a130),
1086 * Move 'ccb.phys.head.go' action to
1087 * scratch/scratch1. So scratch1 will
1088 * contain the 'restart' field of the
1092 }/*-------------------------< _SMS_A130 >------------------------*/,{
1096 PADDR_B (scratch1), /* phys.head.go.restart */
1100 /* In normal situations we branch to RESEL_DSA */
1101 }/*-------------------------< RESEL_DSA >------------------------*/,{
1103 * ACK the IDENTIFY or TAG previously received.
1107 }/*-------------------------< RESEL_DSA1 >-----------------------*/,{
1109 * Copy the CCB header to a fixed location
1110 * in the HCB using self-modifying SCRIPTS.
1114 PADDR_A (_sms_a140),
1115 SCR_COPY (sizeof(struct sym_ccbh)),
1116 }/*-------------------------< _SMS_A140 >------------------------*/,{
1120 * Initialize the status register
1123 HADDR_1 (ccb_head.status),
1126 * Jump to dispatcher.
1130 }/*-------------------------< RESEL_NO_TAG >---------------------*/,{
1132 * Copy the LCB header to a fixed place in
1133 * the HCB using self-modifying SCRIPTS.
1137 PADDR_A (_sms_a145),
1138 SCR_COPY (sizeof(struct sym_lcbh)),
1139 }/*-------------------------< _SMS_A145 >------------------------*/,{
1143 * Load the DSA with the unique ITL task.
1146 HADDR_1 (lcb_head.itl_task_sa),
1150 }/*-------------------------< DATA_IN >--------------------------*/,{
1152 * Because the size depends on the
1153 * #define SYM_CONF_MAX_SG parameter,
1154 * it is filled in at runtime.
1156 * ##===========< i=0; i<SYM_CONF_MAX_SG >=========
1157 * || SCR_CHMOV_TBL ^ SCR_DATA_IN,
1158 * || offsetof (struct sym_dsb, data[ i]),
1159 * ##==========================================
1162 }/*-------------------------< DATA_IN2 >-------------------------*/,{
1164 PADDR_A (datai_done),
1166 PADDR_B (data_ovrun),
1167 }/*-------------------------< DATA_OUT >-------------------------*/,{
1169 * Because the size depends on the
1170 * #define SYM_CONF_MAX_SG parameter,
1171 * it is filled in at runtime.
1173 * ##===========< i=0; i<SYM_CONF_MAX_SG >=========
1174 * || SCR_CHMOV_TBL ^ SCR_DATA_OUT,
1175 * || offsetof (struct sym_dsb, data[ i]),
1176 * ##==========================================
1179 }/*-------------------------< DATA_OUT2 >------------------------*/,{
1181 PADDR_A (datao_done),
1183 PADDR_B (data_ovrun),
1184 }/*-------------------------< PM0_DATA >-------------------------*/,{
1186 * Read our host flags to SFBR, so we will be able
1187 * to check against the data direction we expect.
1189 SCR_FROM_REG (HF_REG),
1192 * Check against actual DATA PHASE.
1194 SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
1195 PADDR_A (pm0_data_out),
1197 * Actual phase is DATA IN.
1198 * Check against expected direction.
1200 SCR_JUMP ^ IFFALSE (MASK (HF_DATA_IN, HF_DATA_IN)),
1201 PADDR_B (data_ovrun),
1203 * Keep track we are moving data from the
1204 * PM0 DATA mini-script.
1206 SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM0),
1209 * Move the data to memory.
1211 SCR_CHMOV_TBL ^ SCR_DATA_IN,
1212 offsetof (struct sym_ccb, phys.pm0.sg),
1214 PADDR_A (pm0_data_end),
1215 }/*-------------------------< PM0_DATA_OUT >---------------------*/,{
1217 * Actual phase is DATA OUT.
1218 * Check against expected direction.
1220 SCR_JUMP ^ IFTRUE (MASK (HF_DATA_IN, HF_DATA_IN)),
1221 PADDR_B (data_ovrun),
1223 * Keep track we are moving data from the
1224 * PM0 DATA mini-script.
1226 SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM0),
1229 * Move the data from memory.
1231 SCR_CHMOV_TBL ^ SCR_DATA_OUT,
1232 offsetof (struct sym_ccb, phys.pm0.sg),
1233 }/*-------------------------< PM0_DATA_END >---------------------*/,{
1235 * Clear the flag that told we were moving
1236 * data from the PM0 DATA mini-script.
1238 SCR_REG_REG (HF_REG, SCR_AND, (~HF_IN_PM0)),
1241 * Return to the previous DATA script which
1242 * is guaranteed by design (if no bug) to be
1243 * the main DATA script for this transfer.
1248 SCR_REG_REG (scratcha, SCR_ADD, offsetof (struct sym_ccb,phys.pm0.ret)),
1250 }/*-------------------------< PM_DATA_END >----------------------*/,{
1253 PADDR_A (_sms_a150),
1255 }/*-------------------------< _SMS_A150 >------------------------*/,{
1260 }/*-------------------------< PM1_DATA >-------------------------*/,{
1262 * Read our host flags to SFBR, so we will be able
1263 * to check against the data direction we expect.
1265 SCR_FROM_REG (HF_REG),
1268 * Check against actual DATA PHASE.
1270 SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
1271 PADDR_A (pm1_data_out),
1273 * Actual phase is DATA IN.
1274 * Check against expected direction.
1276 SCR_JUMP ^ IFFALSE (MASK (HF_DATA_IN, HF_DATA_IN)),
1277 PADDR_B (data_ovrun),
1279 * Keep track we are moving data from the
1280 * PM1 DATA mini-script.
1282 SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM1),
1285 * Move the data to memory.
1287 SCR_CHMOV_TBL ^ SCR_DATA_IN,
1288 offsetof (struct sym_ccb, phys.pm1.sg),
1290 PADDR_A (pm1_data_end),
1291 }/*-------------------------< PM1_DATA_OUT >---------------------*/,{
1293 * Actual phase is DATA OUT.
1294 * Check against expected direction.
1296 SCR_JUMP ^ IFTRUE (MASK (HF_DATA_IN, HF_DATA_IN)),
1297 PADDR_B (data_ovrun),
1299 * Keep track we are moving data from the
1300 * PM1 DATA mini-script.
1302 SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM1),
1305 * Move the data from memory.
1307 SCR_CHMOV_TBL ^ SCR_DATA_OUT,
1308 offsetof (struct sym_ccb, phys.pm1.sg),
1309 }/*-------------------------< PM1_DATA_END >---------------------*/,{
1311 * Clear the flag that told we were moving
1312 * data from the PM1 DATA mini-script.
1314 SCR_REG_REG (HF_REG, SCR_AND, (~HF_IN_PM1)),
1317 * Return to the previous DATA script which
1318 * is guaranteed by design (if no bug) to be
1319 * the main DATA script for this transfer.
1324 SCR_REG_REG (scratcha, SCR_ADD, offsetof (struct sym_ccb,phys.pm1.ret)),
1327 PADDR_A (pm_data_end),
1328 }/*--------------------------<>----------------------------------*/
1331 static struct SYM_FWB_SCR SYM_FWB_SCR = {
1332 /*-------------------------< NO_DATA >--------------------------*/ {
1334 PADDR_B (data_ovrun),
1335 }/*-------------------------< SEL_FOR_ABORT >--------------------*/,{
1337 * We are jumped here by the C code, if we have
1338 * some target to reset or some disconnected
1339 * job to abort. Since error recovery is a serious
1340 * busyness, we will really reset the SCSI BUS, if
1341 * case of a SCSI interrupt occurring in this path.
1344 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
1346 * Set initiator mode.
1352 * And try to select this target.
1354 SCR_SEL_TBL_ATN ^ offsetof (struct sym_hcb, abrt_sel),
1357 * Wait for the selection to complete or
1358 * the selection to time out.
1360 SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_OUT)),
1366 SIR_TARGET_SELECTED,
1368 * The C code should let us continue here.
1369 * Send the 'kiss of death' message.
1370 * We expect an immediate disconnect once
1371 * the target has eaten the message.
1373 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
1375 SCR_MOVE_TBL ^ SCR_MSG_OUT,
1376 offsetof (struct sym_hcb, abrt_tbl),
1377 SCR_CLR (SCR_ACK|SCR_ATN),
1382 * Tell the C code that we are done.
1386 }/*-------------------------< SEL_FOR_ABORT_1 >------------------*/,{
1388 * Jump at scheduler.
1392 }/*-------------------------< MSG_IN_ETC >-----------------------*/,{
1394 * If it is an EXTENDED (variable size message)
1397 SCR_JUMP ^ IFTRUE (DATA (M_EXTENDED)),
1398 PADDR_B (msg_extended),
1400 * Let the C code handle any other
1403 SCR_JUMP ^ IFTRUE (MASK (0x00, 0xf0)),
1404 PADDR_B (msg_received),
1405 SCR_JUMP ^ IFTRUE (MASK (0x10, 0xf0)),
1406 PADDR_B (msg_received),
1408 * We donnot handle 2 bytes messages from SCRIPTS.
1409 * So, let the C code deal with these ones too.
1411 SCR_JUMP ^ IFFALSE (MASK (0x20, 0xf0)),
1412 PADDR_B (msg_weird_seen),
1415 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
1417 }/*-------------------------< MSG_RECEIVED >---------------------*/,{
1418 SCR_COPY (4), /* DUMMY READ */
1423 }/*-------------------------< MSG_WEIRD_SEEN >-------------------*/,{
1424 SCR_COPY (4), /* DUMMY READ */
1429 }/*-------------------------< MSG_EXTENDED >---------------------*/,{
1431 * Clear ACK and get the next byte
1432 * assumed to be the message length.
1436 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
1439 * Try to catch some unlikely situations as 0 length
1440 * or too large the length.
1442 SCR_JUMP ^ IFTRUE (DATA (0)),
1443 PADDR_B (msg_weird_seen),
1444 SCR_TO_REG (scratcha),
1446 SCR_REG_REG (sfbr, SCR_ADD, (256-8)),
1448 SCR_JUMP ^ IFTRUE (CARRYSET),
1449 PADDR_B (msg_weird_seen),
1451 * We donnot handle extended messages from SCRIPTS.
1452 * Read the amount of data correponding to the
1453 * message length and call the C code.
1460 }/*-------------------------< _SMS_B10 >-------------------------*/,{
1461 SCR_MOVE_ABS (0) ^ SCR_MSG_IN,
1464 PADDR_B (msg_received),
1465 }/*-------------------------< MSG_BAD >--------------------------*/,{
1467 * unimplemented message - reject it.
1475 }/*-------------------------< MSG_WEIRD >------------------------*/,{
1477 * weird message received
1478 * ignore all MSG IN phases and reject it.
1484 }/*-------------------------< MSG_WEIRD1 >-----------------------*/,{
1487 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
1489 SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
1492 PADDR_B (msg_weird1),
1493 }/*-------------------------< WDTR_RESP >------------------------*/,{
1495 * let the target fetch our answer.
1501 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
1502 PADDR_B (nego_bad_phase),
1503 }/*-------------------------< SEND_WDTR >------------------------*/,{
1505 * Send the M_X_WIDE_REQ
1507 SCR_MOVE_ABS (4) ^ SCR_MSG_OUT,
1510 PADDR_B (msg_out_done),
1511 }/*-------------------------< SDTR_RESP >------------------------*/,{
1513 * let the target fetch our answer.
1519 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
1520 PADDR_B (nego_bad_phase),
1521 }/*-------------------------< SEND_SDTR >------------------------*/,{
1523 * Send the M_X_SYNC_REQ
1525 SCR_MOVE_ABS (5) ^ SCR_MSG_OUT,
1528 PADDR_B (msg_out_done),
1529 }/*-------------------------< PPR_RESP >-------------------------*/,{
1531 * let the target fetch our answer.
1537 SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
1538 PADDR_B (nego_bad_phase),
1539 }/*-------------------------< SEND_PPR >-------------------------*/,{
1541 * Send the M_X_PPR_REQ
1543 SCR_MOVE_ABS (8) ^ SCR_MSG_OUT,
1546 PADDR_B (msg_out_done),
1547 }/*-------------------------< NEGO_BAD_PHASE >-------------------*/,{
1552 }/*-------------------------< MSG_OUT >--------------------------*/,{
1554 * The target requests a message.
1555 * We donnot send messages that may
1556 * require the device to go to bus free.
1558 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
1561 * ... wait for the next phase
1562 * if it's a message out, send it again, ...
1564 SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
1566 }/*-------------------------< MSG_OUT_DONE >---------------------*/,{
1568 * Let the C code be aware of the
1569 * sent message and clear the message.
1574 * ... and process the next phase
1578 }/*-------------------------< DATA_OVRUN >-----------------------*/,{
1580 * Zero scratcha that will count the
1586 }/*-------------------------< DATA_OVRUN1 >----------------------*/,{
1588 * The target may want to transfer too much data.
1590 * If phase is DATA OUT write 1 byte and count it.
1592 SCR_JUMPR ^ IFFALSE (WHEN (SCR_DATA_OUT)),
1594 SCR_CHMOV_ABS (1) ^ SCR_DATA_OUT,
1597 PADDR_B (data_ovrun2),
1599 * If WSR is set, clear this condition, and
1602 SCR_FROM_REG (scntl2),
1604 SCR_JUMPR ^ IFFALSE (MASK (WSR, WSR)),
1606 SCR_REG_REG (scntl2, SCR_OR, WSR),
1609 PADDR_B (data_ovrun2),
1611 * Finally check against DATA IN phase.
1612 * Signal data overrun to the C code
1613 * and jump to dispatcher if not so.
1614 * Read 1 byte otherwise and count it.
1616 SCR_JUMPR ^ IFTRUE (WHEN (SCR_DATA_IN)),
1622 SCR_CHMOV_ABS (1) ^ SCR_DATA_IN,
1624 }/*-------------------------< DATA_OVRUN2 >----------------------*/,{
1627 * This will allow to return a negative
1630 SCR_REG_REG (scratcha, SCR_ADD, 0x01),
1632 SCR_REG_REG (scratcha1, SCR_ADDC, 0),
1634 SCR_REG_REG (scratcha2, SCR_ADDC, 0),
1637 * .. and repeat as required.
1640 PADDR_B (data_ovrun1),
1641 }/*-------------------------< ABORT_RESEL >----------------------*/,{
1647 * send the abort/abortag/reset message
1648 * we expect an immediate disconnect
1650 SCR_REG_REG (scntl2, SCR_AND, 0x7f),
1652 SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
1654 SCR_CLR (SCR_ACK|SCR_ATN),
1662 }/*-------------------------< RESEND_IDENT >---------------------*/,{
1664 * The target stays in MSG OUT phase after having acked
1665 * Identify [+ Tag [+ Extended message ]]. Targets shall
1666 * behave this way on parity error.
1667 * We must send it again all the messages.
1669 SCR_SET (SCR_ATN), /* Shall be asserted 2 deskew delays before the */
1670 0, /* 1rst ACK = 90 ns. Hope the chip isn't too fast */
1672 PADDR_A (send_ident),
1673 }/*-------------------------< IDENT_BREAK >----------------------*/,{
1678 }/*-------------------------< IDENT_BREAK_ATN >------------------*/,{
1683 }/*-------------------------< SDATA_IN >-------------------------*/,{
1684 SCR_CHMOV_TBL ^ SCR_DATA_IN,
1685 offsetof (struct sym_dsb, sense),
1687 PADDR_A (datai_done),
1689 PADDR_B (data_ovrun),
1690 }/*-------------------------< RESEL_BAD_LUN >--------------------*/,{
1692 * Message is an IDENTIFY, but lun is unknown.
1693 * Signal problem to C code for logging the event.
1694 * Send a M_ABORT to clear all pending tasks.
1699 PADDR_B (abort_resel),
1700 }/*-------------------------< BAD_I_T_L >------------------------*/,{
1702 * We donnot have a task for that I_T_L.
1703 * Signal problem to C code for logging the event.
1704 * Send a M_ABORT message.
1707 SIR_RESEL_BAD_I_T_L,
1709 PADDR_B (abort_resel),
1710 }/*-------------------------< BAD_I_T_L_Q >----------------------*/,{
1712 * We donnot have a task that matches the tag.
1713 * Signal problem to C code for logging the event.
1714 * Send a M_ABORTTAG message.
1717 SIR_RESEL_BAD_I_T_L_Q,
1719 PADDR_B (abort_resel),
1720 }/*-------------------------< BAD_STATUS >-----------------------*/,{
1722 * Anything different from INTERMEDIATE
1723 * CONDITION MET should be a bad SCSI status,
1724 * given that GOOD status has already been tested.
1730 SCR_INT ^ IFFALSE (DATA (S_COND_MET)),
1731 SIR_BAD_SCSI_STATUS,
1734 }/*-------------------------< WSR_MA_HELPER >--------------------*/,{
1736 * Helper for the C code when WSR bit is set.
1737 * Perform the move of the residual byte.
1739 SCR_CHMOV_TBL ^ SCR_DATA_IN,
1740 offsetof (struct sym_ccb, phys.wresid),
1744 }/*-------------------------< ZERO >-----------------------------*/,{
1746 }/*-------------------------< SCRATCH >--------------------------*/,{
1747 SCR_DATA_ZERO, /* MUST BE BEFORE SCRATCH1 */
1748 }/*-------------------------< SCRATCH1 >-------------------------*/,{
1750 }/*-------------------------< PREV_DONE >------------------------*/,{
1751 SCR_DATA_ZERO, /* MUST BE BEFORE DONE_POS ! */
1752 }/*-------------------------< DONE_POS >-------------------------*/,{
1754 }/*-------------------------< NEXTJOB >--------------------------*/,{
1755 SCR_DATA_ZERO, /* MUST BE BEFORE STARTPOS ! */
1756 }/*-------------------------< STARTPOS >-------------------------*/,{
1758 }/*-------------------------< TARGTBL >--------------------------*/,{
1760 }/*--------------------------<>----------------------------------*/
1763 static struct SYM_FWZ_SCR SYM_FWZ_SCR = {
1764 /*-------------------------< SNOOPTEST >------------------------*/{
1766 * Read the variable.
1772 * Write the variable.
1778 * Read back the variable.
1783 }/*-------------------------< SNOOPEND >-------------------------*/,{
1789 }/*--------------------------<>----------------------------------*/