3 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch.
5 * SPDX-License-Identifier: GPL-2.0+
7 * linux/drivers/scsi/sym53c8xx.c
12 * SCSI support based on the chip sym53C810.
14 * 09-19-2001 Andreas Heppel, Sysgo RTS GmbH <aheppel@sysgo.de>
15 * The local version of this driver for the BAB750 board does not
16 * use interrupts but polls the chip instead (see the call of
17 * 'handle_scsi_int()' in 'scsi_issue()'.
24 #include <asm/processor.h>
25 #include <sym53c8xx.h>
28 #undef SYM53C8XX_DEBUG
30 #ifdef SYM53C8XX_DEBUG
31 #define PRINTF(fmt,args...) printf (fmt ,##args)
33 #define PRINTF(fmt,args...)
36 #if defined(CONFIG_CMD_SCSI) && defined(CONFIG_SCSI_SYM53C8XX)
38 #undef SCSI_SINGLE_STEP
40 * Single Step is only used for debug purposes
42 #ifdef SCSI_SINGLE_STEP
43 static unsigned long start_script_select
;
44 static unsigned long start_script_msgout
;
45 static unsigned long start_script_msgin
;
46 static unsigned long start_script_msg_ext
;
47 static unsigned long start_script_cmd
;
48 static unsigned long start_script_data_in
;
49 static unsigned long start_script_data_out
;
50 static unsigned long start_script_status
;
51 static unsigned long start_script_complete
;
52 static unsigned long start_script_error
;
53 static unsigned long start_script_reselection
;
54 static unsigned int len_script_select
;
55 static unsigned int len_script_msgout
;
56 static unsigned int len_script_msgin
;
57 static unsigned int len_script_msg_ext
;
58 static unsigned int len_script_cmd
;
59 static unsigned int len_script_data_in
;
60 static unsigned int len_script_data_out
;
61 static unsigned int len_script_status
;
62 static unsigned int len_script_complete
;
63 static unsigned int len_script_error
;
64 static unsigned int len_script_reselection
;
68 static unsigned short scsi_int_mask
; /* shadow register for SCSI related interrupts */
69 static unsigned char script_int_mask
; /* shadow register for SCRIPT related interrupts */
70 static unsigned long script_select
[8]; /* script for selection */
71 static unsigned long script_msgout
[8]; /* script for message out phase (NOT USED) */
72 static unsigned long script_msgin
[14]; /* script for message in phase */
73 static unsigned long script_msg_ext
[32]; /* script for message in phase when more than 1 byte message */
74 static unsigned long script_cmd
[18]; /* script for command phase */
75 static unsigned long script_data_in
[8]; /* script for data in phase */
76 static unsigned long script_data_out
[8]; /* script for data out phase */
77 static unsigned long script_status
[6]; /* script for status phase */
78 static unsigned long script_complete
[10]; /* script for complete */
79 static unsigned long script_reselection
[4]; /* script for reselection (NOT USED) */
80 static unsigned long script_error
[2]; /* script for error handling */
82 static unsigned long int_stat
[3]; /* interrupt status */
83 static unsigned long scsi_mem_addr
; /* base memory address =SCSI_MEM_ADDRESS; */
85 #define bus_to_phys(a) pci_mem_to_phys(busdevfunc, (unsigned long) (a))
86 #define phys_to_bus(a) pci_phys_to_mem(busdevfunc, (unsigned long) (a))
88 #define SCSI_MAX_RETRY 3 /* number of retries in scsi_issue() */
90 #define SCSI_MAX_RETRY_NOT_READY 10 /* number of retries when device is not ready */
91 #define SCSI_NOT_READY_TIME_OUT 500 /* timeout per retry when not ready */
93 /*********************************************************************************
94 * forward declerations
97 void scsi_chip_init(void);
98 void handle_scsi_int(void);
101 /********************************************************************************
102 * reports SCSI errors to the user
104 void scsi_print_error (ccb
* pccb
)
108 printf ("SCSI Error: Target %d LUN %d Command %02X\n", pccb
->target
,
109 pccb
->lun
, pccb
->cmd
[0]);
111 for (i
= 0; i
< pccb
->cmdlen
; i
++)
112 printf ("%02X ", pccb
->cmd
[i
]);
113 printf ("(len=%d)\n", pccb
->cmdlen
);
115 switch (pccb
->contr_stat
) {
117 printf ("Complete (no Error)\n");
119 case SIR_SEL_ATN_NO_MSG_OUT
:
120 printf ("Selected with ATN no MSG out phase\n");
122 case SIR_CMD_OUT_ILL_PH
:
123 printf ("Command out illegal phase\n");
125 case SIR_MSG_RECEIVED
:
126 printf ("MSG received Error\n");
128 case SIR_DATA_IN_ERR
:
129 printf ("Data in Error\n");
131 case SIR_DATA_OUT_ERR
:
132 printf ("Data out Error\n");
134 case SIR_SCRIPT_ERROR
:
135 printf ("Script Error\n");
137 case SIR_MSG_OUT_NO_CMD
:
138 printf ("MSG out no Command phase\n");
141 printf ("MSG in over 7 bytes\n");
144 printf ("Interrupt on fly\n");
146 case SCSI_SEL_TIME_OUT
:
147 printf ("SCSI Selection Timeout\n");
149 case SCSI_HNS_TIME_OUT
:
150 printf ("SCSI Handshake Timeout\n");
152 case SCSI_MA_TIME_OUT
:
153 printf ("SCSI Phase Error\n");
156 printf ("SCSI unexpected disconnect\n");
159 printf ("unknown status %lx\n", pccb
->contr_stat
);
162 printf (" Sense: SK %x (", pccb
->sense_buf
[2] & 0x0f);
163 switch (pccb
->sense_buf
[2] & 0xf) {
165 printf ("No Sense)");
167 case SENSE_RECOVERED_ERROR
:
168 printf ("Recovered Error)");
170 case SENSE_NOT_READY
:
171 printf ("Not Ready)");
173 case SENSE_MEDIUM_ERROR
:
174 printf ("Medium Error)");
176 case SENSE_HARDWARE_ERROR
:
177 printf ("Hardware Error)");
179 case SENSE_ILLEGAL_REQUEST
:
180 printf ("Illegal request)");
182 case SENSE_UNIT_ATTENTION
:
183 printf ("Unit Attention)");
185 case SENSE_DATA_PROTECT
:
186 printf ("Data Protect)");
188 case SENSE_BLANK_CHECK
:
189 printf ("Blank check)");
191 case SENSE_VENDOR_SPECIFIC
:
192 printf ("Vendor specific)");
194 case SENSE_COPY_ABORTED
:
195 printf ("Copy aborted)");
197 case SENSE_ABORTED_COMMAND
:
198 printf ("Aborted Command)");
200 case SENSE_VOLUME_OVERFLOW
:
201 printf ("Volume overflow)");
203 case SENSE_MISCOMPARE
:
204 printf ("Misscompare\n");
207 printf ("Illegal Sensecode\n");
210 printf (" ASC %x ASCQ %x\n", pccb
->sense_buf
[12],
211 pccb
->sense_buf
[13]);
212 printf (" Status: ");
213 switch (pccb
->status
) {
218 printf ("Check condition\n");
221 printf ("Condition Met\n");
227 printf ("Intermediate\n");
230 printf ("Intermediate condition met\n");
233 printf ("Reservation conflict\n");
236 printf ("Command terminated\n");
239 printf ("Task set full\n");
242 printf ("unknown: %02X\n", pccb
->status
);
249 /******************************************************************************
250 * sets-up the SCSI controller
251 * the base memory address is retrieved via the pci_read_config_dword
253 void scsi_low_level_init(int busdevfunc
)
259 pci_read_config_byte(busdevfunc
, PCI_INTERRUPT_LINE
, &vec
);
260 pci_read_config_dword(busdevfunc
, PCI_BASE_ADDRESS_1
, &addr
);
262 addr
= bus_to_phys(addr
& ~0xf);
265 * Enable bus mastering in case this has not been done, yet.
267 pci_read_config_dword(busdevfunc
, PCI_COMMAND
, &cmd
);
268 cmd
|= PCI_COMMAND_MASTER
;
269 pci_write_config_dword(busdevfunc
, PCI_COMMAND
, cmd
);
271 scsi_mem_addr
= addr
;
278 /************************************************************************************
279 * Low level Part of SCSI Driver
283 * big-endian -> little endian conversion for the script
285 unsigned long swap_script(unsigned long val
)
288 tmp
= ((val
>>24)&0xff) | ((val
>>8)&0xff00) | ((val
<<8)&0xff0000) | ((val
<<24)&0xff000000);
293 void scsi_write_byte(ulong offset
,unsigned char val
)
295 out8(scsi_mem_addr
+offset
,val
);
299 unsigned char scsi_read_byte(ulong offset
)
301 return(in8(scsi_mem_addr
+offset
));
305 /********************************************************************************
308 void handle_scsi_int(void)
310 unsigned char stat
,stat1
,stat2
;
311 unsigned short sstat
;
313 #ifdef SCSI_SINGLE_STEP
316 stat
=scsi_read_byte(ISTAT
);
317 if((stat
& DIP
)==DIP
) { /* DMA Interrupt pending */
318 stat1
=scsi_read_byte(DSTAT
);
319 #ifdef SCSI_SINGLE_STEP
320 if((stat1
& SSI
)==SSI
) {
321 tt
=in32r(scsi_mem_addr
+DSP
);
322 if(((tt
)>=start_script_select
) && ((tt
)<start_script_select
+len_script_select
)) {
323 printf("select %d\n",(tt
-start_script_select
)>>2);
326 if(((tt
)>=start_script_msgout
) && ((tt
)<start_script_msgout
+len_script_msgout
)) {
327 printf("msgout %d\n",(tt
-start_script_msgout
)>>2);
330 if(((tt
)>=start_script_msgin
) && ((tt
)<start_script_msgin
+len_script_msgin
)) {
331 printf("msgin %d\n",(tt
-start_script_msgin
)>>2);
334 if(((tt
)>=start_script_msg_ext
) && ((tt
)<start_script_msg_ext
+len_script_msg_ext
)) {
335 printf("msgin_ext %d\n",(tt
-start_script_msg_ext
)>>2);
338 if(((tt
)>=start_script_cmd
) && ((tt
)<start_script_cmd
+len_script_cmd
)) {
339 printf("cmd %d\n",(tt
-start_script_cmd
)>>2);
342 if(((tt
)>=start_script_data_in
) && ((tt
)<start_script_data_in
+len_script_data_in
)) {
343 printf("data_in %d\n",(tt
-start_script_data_in
)>>2);
346 if(((tt
)>=start_script_data_out
) && ((tt
)<start_script_data_out
+len_script_data_out
)) {
347 printf("data_out %d\n",(tt
-start_script_data_out
)>>2);
350 if(((tt
)>=start_script_status
) && ((tt
)<start_script_status
+len_script_status
)) {
351 printf("status %d\n",(tt
-start_script_status
)>>2);
354 if(((tt
)>=start_script_complete
) && ((tt
)<start_script_complete
+len_script_complete
)) {
355 printf("complete %d\n",(tt
-start_script_complete
)>>2);
358 if(((tt
)>=start_script_error
) && ((tt
)<start_script_error
+len_script_error
)) {
359 printf("error %d\n",(tt
-start_script_error
)>>2);
362 if(((tt
)>=start_script_reselection
) && ((tt
)<start_script_reselection
+len_script_reselection
)) {
363 printf("reselection %d\n",(tt
-start_script_reselection
)>>2);
366 printf("sc: %lx\n",tt
);
368 stat2
=scsi_read_byte(DCNTL
);
370 scsi_write_byte(DCNTL
,stat2
);
373 if((stat1
& SIR
)==SIR
) /* script interrupt */
375 int_stat
[0]=in32(scsi_mem_addr
+DSPS
);
377 if((stat1
& DFE
)==0) { /* fifo not epmty */
378 scsi_write_byte(CTEST3
,CLF
); /* Clear DMA FIFO */
379 stat2
=scsi_read_byte(STEST3
);
380 scsi_write_byte(STEST3
,(stat2
| CSF
)); /* Clear SCSI FIFO */
383 if((stat
& SIP
)==SIP
) { /* scsi interrupt */
384 sstat
= (unsigned short)scsi_read_byte(SIST
+1);
386 sstat
|= (unsigned short)scsi_read_byte(SIST
);
389 break; /* found an empty int status */
391 int_stat
[i
]=SCSI_INT_STATE
| sstat
;
392 stat1
=scsi_read_byte(DSTAT
);
393 if((stat1
& DFE
)==0) { /* fifo not epmty */
394 scsi_write_byte(CTEST3
,CLF
); /* Clear DMA FIFO */
395 stat2
=scsi_read_byte(STEST3
);
396 scsi_write_byte(STEST3
,(stat2
| CSF
)); /* Clear SCSI FIFO */
399 if((stat
& INTF
)==INTF
) { /* interrupt on Fly */
400 scsi_write_byte(ISTAT
,stat
); /* clear it */
403 break; /* found an empty int status */
405 int_stat
[i
]=INT_ON_FY
;
409 void scsi_bus_reset(void)
413 int end
= CONFIG_SYS_SCSI_SPIN_UP_TIME
*1000;
415 t
=scsi_read_byte(SCNTL1
);
416 scsi_write_byte(SCNTL1
,(t
| CRST
));
418 scsi_write_byte(SCNTL1
,t
);
420 puts("waiting for devices to spin up");
422 udelay(1000); /* give the devices time to spin up */
427 scsi_chip_init(); /* reinit the chip ...*/
431 void scsi_int_enable(void)
433 scsi_write_byte(SIEN
,(unsigned char)scsi_int_mask
);
434 scsi_write_byte(SIEN
+1,(unsigned char)(scsi_int_mask
>>8));
435 scsi_write_byte(DIEN
,script_int_mask
);
438 void scsi_write_dsp(unsigned long start
)
440 #ifdef SCSI_SINGLE_STEP
443 out32r(scsi_mem_addr
+ DSP
,start
);
444 #ifdef SCSI_SINGLE_STEP
445 t
=scsi_read_byte(DCNTL
);
447 scsi_write_byte(DCNTL
,t
);
451 /* only used for debug purposes */
452 void scsi_print_script(void)
454 printf("script_select @ 0x%08lX\n",(unsigned long)&script_select
[0]);
455 printf("script_msgout @ 0x%08lX\n",(unsigned long)&script_msgout
[0]);
456 printf("script_msgin @ 0x%08lX\n",(unsigned long)&script_msgin
[0]);
457 printf("script_msgext @ 0x%08lX\n",(unsigned long)&script_msg_ext
[0]);
458 printf("script_cmd @ 0x%08lX\n",(unsigned long)&script_cmd
[0]);
459 printf("script_data_in @ 0x%08lX\n",(unsigned long)&script_data_in
[0]);
460 printf("script_data_out @ 0x%08lX\n",(unsigned long)&script_data_out
[0]);
461 printf("script_status @ 0x%08lX\n",(unsigned long)&script_status
[0]);
462 printf("script_complete @ 0x%08lX\n",(unsigned long)&script_complete
[0]);
463 printf("script_error @ 0x%08lX\n",(unsigned long)&script_error
[0]);
467 void scsi_set_script(ccb
*pccb
)
469 int busdevfunc
= pccb
->priv
;
472 script_select
[i
++]=swap_script(SCR_REG_REG(GPREG
, SCR_AND
, 0xfe));
473 script_select
[i
++]=0; /* LED ON */
474 script_select
[i
++]=swap_script(SCR_CLR(SCR_TRG
)); /* select initiator mode */
475 script_select
[i
++]=0;
476 /* script_select[i++]=swap_script(SCR_SEL_ABS_ATN | pccb->target << 16); */
477 script_select
[i
++]=swap_script(SCR_SEL_ABS
| pccb
->target
<< 16);
478 script_select
[i
++]=swap_script(phys_to_bus(&script_cmd
[4])); /* error handling */
479 script_select
[i
++]=swap_script(SCR_JUMP
); /* next section */
480 /* script_select[i++]=swap_script((unsigned long)&script_msgout[0]); */ /* message out */
481 script_select
[i
++]=swap_script(phys_to_bus(&script_cmd
[0])); /* command out */
483 #ifdef SCSI_SINGLE_STEP
484 start_script_select
=(unsigned long)&script_select
[0];
485 len_script_select
=i
*4;
489 script_msgout
[i
++]=swap_script(SCR_INT
^ IFFALSE (WHEN (SCR_MSG_OUT
)));
490 script_msgout
[i
++]=SIR_SEL_ATN_NO_MSG_OUT
;
491 script_msgout
[i
++]=swap_script( SCR_MOVE_ABS(1) ^ SCR_MSG_OUT
);
492 script_msgout
[i
++]=swap_script(phys_to_bus(&pccb
->msgout
[0]));
493 script_msgout
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (WHEN (SCR_COMMAND
))); /* if Command phase */
494 script_msgout
[i
++]=swap_script(phys_to_bus(&script_cmd
[0])); /* switch to command */
495 script_msgout
[i
++]=swap_script(SCR_INT
); /* interrupt if not */
496 script_msgout
[i
++]=SIR_MSG_OUT_NO_CMD
;
498 #ifdef SCSI_SINGLE_STEP
499 start_script_msgout
=(unsigned long)&script_msgout
[0];
500 len_script_msgout
=i
*4;
503 script_cmd
[i
++]=swap_script(SCR_MOVE_ABS(pccb
->cmdlen
) ^ SCR_COMMAND
);
504 script_cmd
[i
++]=swap_script(phys_to_bus(&pccb
->cmd
[0]));
505 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
))); /* message in ? */
506 script_cmd
[i
++]=swap_script(phys_to_bus(&script_msgin
[0]));
507 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (IF (SCR_DATA_OUT
))); /* data out ? */
508 script_cmd
[i
++]=swap_script(phys_to_bus(&script_data_out
[0]));
509 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (IF (SCR_DATA_IN
))); /* data in ? */
510 script_cmd
[i
++]=swap_script(phys_to_bus(&script_data_in
[0]));
511 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (IF (SCR_STATUS
))); /* status ? */
512 script_cmd
[i
++]=swap_script(phys_to_bus(&script_status
[0]));
513 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (IF (SCR_COMMAND
))); /* command ? */
514 script_cmd
[i
++]=swap_script(phys_to_bus(&script_cmd
[0]));
515 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (IF (SCR_MSG_OUT
))); /* message out ? */
516 script_cmd
[i
++]=swap_script(phys_to_bus(&script_msgout
[0]));
517 script_cmd
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (IF (SCR_MSG_IN
))); /* just for error handling message in ? */
518 script_cmd
[i
++]=swap_script(phys_to_bus(&script_msgin
[0]));
519 script_cmd
[i
++]=swap_script(SCR_INT
); /* interrupt if not */
520 script_cmd
[i
++]=SIR_CMD_OUT_ILL_PH
;
521 #ifdef SCSI_SINGLE_STEP
522 start_script_cmd
=(unsigned long)&script_cmd
[0];
526 script_data_out
[i
++]=swap_script(SCR_MOVE_ABS(pccb
->datalen
)^ SCR_DATA_OUT
); /* move */
527 script_data_out
[i
++]=swap_script(phys_to_bus(pccb
->pdata
)); /* pointer to buffer */
528 script_data_out
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (WHEN (SCR_STATUS
)));
529 script_data_out
[i
++]=swap_script(phys_to_bus(&script_status
[0]));
530 script_data_out
[i
++]=swap_script(SCR_INT
);
531 script_data_out
[i
++]=SIR_DATA_OUT_ERR
;
533 #ifdef SCSI_SINGLE_STEP
534 start_script_data_out
=(unsigned long)&script_data_out
[0];
535 len_script_data_out
=i
*4;
538 script_data_in
[i
++]=swap_script(SCR_MOVE_ABS(pccb
->datalen
)^ SCR_DATA_IN
); /* move */
539 script_data_in
[i
++]=swap_script(phys_to_bus(pccb
->pdata
)); /* pointer to buffer */
540 script_data_in
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (WHEN (SCR_STATUS
)));
541 script_data_in
[i
++]=swap_script(phys_to_bus(&script_status
[0]));
542 script_data_in
[i
++]=swap_script(SCR_INT
);
543 script_data_in
[i
++]=SIR_DATA_IN_ERR
;
544 #ifdef SCSI_SINGLE_STEP
545 start_script_data_in
=(unsigned long)&script_data_in
[0];
546 len_script_data_in
=i
*4;
549 script_msgin
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
);
550 script_msgin
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[0]));
551 script_msgin
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (DATA (M_COMPLETE
)));
552 script_msgin
[i
++]=swap_script(phys_to_bus(&script_complete
[0]));
553 script_msgin
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (DATA (M_DISCONNECT
)));
554 script_msgin
[i
++]=swap_script(phys_to_bus(&script_complete
[0]));
555 script_msgin
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (DATA (M_SAVE_DP
)));
556 script_msgin
[i
++]=swap_script(phys_to_bus(&script_complete
[0]));
557 script_msgin
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (DATA (M_RESTORE_DP
)));
558 script_msgin
[i
++]=swap_script(phys_to_bus(&script_complete
[0]));
559 script_msgin
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (DATA (M_EXTENDED
)));
560 script_msgin
[i
++]=swap_script(phys_to_bus(&script_msg_ext
[0]));
561 script_msgin
[i
++]=swap_script(SCR_INT
);
562 script_msgin
[i
++]=SIR_MSG_RECEIVED
;
563 #ifdef SCSI_SINGLE_STEP
564 start_script_msgin
=(unsigned long)&script_msgin
[0];
565 len_script_msgin
=i
*4;
568 script_msg_ext
[i
++]=swap_script(SCR_CLR (SCR_ACK
)); /* clear ACK */
569 script_msg_ext
[i
++]=0;
570 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* assuming this is the msg length */
571 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[1]));
572 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
573 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
574 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* next */
575 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[2]));
576 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
577 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
578 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* next */
579 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[3]));
580 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
581 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
582 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* next */
583 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[4]));
584 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
585 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
586 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* next */
587 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[5]));
588 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
589 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
590 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* next */
591 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[6]));
592 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
593 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
594 script_msg_ext
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN
); /* next */
595 script_msg_ext
[i
++]=swap_script(phys_to_bus(&pccb
->msgin
[7]));
596 script_msg_ext
[i
++]=swap_script(SCR_JUMP
^ IFFALSE (IF (SCR_MSG_IN
)));
597 script_msg_ext
[i
++]=swap_script(phys_to_bus(&script_complete
[0])); /* no more bytes */
598 script_msg_ext
[i
++]=swap_script(SCR_INT
);
599 script_msg_ext
[i
++]=SIR_MSG_OVER7
;
600 #ifdef SCSI_SINGLE_STEP
601 start_script_msg_ext
=(unsigned long)&script_msg_ext
[0];
602 len_script_msg_ext
=i
*4;
605 script_status
[i
++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_STATUS
);
606 script_status
[i
++]=swap_script(phys_to_bus(&pccb
->status
));
607 script_status
[i
++]=swap_script(SCR_JUMP
^ IFTRUE (WHEN (SCR_MSG_IN
)));
608 script_status
[i
++]=swap_script(phys_to_bus(&script_msgin
[0]));
609 script_status
[i
++]=swap_script(SCR_INT
);
610 script_status
[i
++]=SIR_STATUS_ILL_PH
;
611 #ifdef SCSI_SINGLE_STEP
612 start_script_status
=(unsigned long)&script_status
[0];
613 len_script_status
=i
*4;
616 script_complete
[i
++]=swap_script(SCR_REG_REG (SCNTL2
, SCR_AND
, 0x7f));
617 script_complete
[i
++]=0;
618 script_complete
[i
++]=swap_script(SCR_CLR (SCR_ACK
|SCR_ATN
));
619 script_complete
[i
++]=0;
620 script_complete
[i
++]=swap_script(SCR_WAIT_DISC
);
621 script_complete
[i
++]=0;
622 script_complete
[i
++]=swap_script(SCR_REG_REG(GPREG
, SCR_OR
, 0x01));
623 script_complete
[i
++]=0; /* LED OFF */
624 script_complete
[i
++]=swap_script(SCR_INT
);
625 script_complete
[i
++]=SIR_COMPLETE
;
626 #ifdef SCSI_SINGLE_STEP
627 start_script_complete
=(unsigned long)&script_complete
[0];
628 len_script_complete
=i
*4;
631 script_error
[i
++]=swap_script(SCR_INT
); /* interrupt if error */
632 script_error
[i
++]=SIR_SCRIPT_ERROR
;
633 #ifdef SCSI_SINGLE_STEP
634 start_script_error
=(unsigned long)&script_error
[0];
635 len_script_error
=i
*4;
638 script_reselection
[i
++]=swap_script(SCR_CLR (SCR_TRG
)); /* target status */
639 script_reselection
[i
++]=0;
640 script_reselection
[i
++]=swap_script(SCR_WAIT_RESEL
);
641 script_reselection
[i
++]=swap_script(phys_to_bus(&script_select
[0])); /* len = 4 */
642 #ifdef SCSI_SINGLE_STEP
643 start_script_reselection
=(unsigned long)&script_reselection
[0];
644 len_script_reselection
=i
*4;
649 void scsi_issue(ccb
*pccb
)
651 int busdevfunc
= pccb
->priv
;
653 unsigned short sstat
;
654 int retrycnt
; /* retry counter */
656 int_stat
[i
]=0; /* delete all int status */
657 /* struct pccb must be set-up correctly */
659 PRINTF("ID %d issue cmd %02X\n",pccb
->target
,pccb
->cmd
[0]);
660 pccb
->trans_bytes
=0; /* no bytes transfered yet */
661 scsi_set_script(pccb
); /* fill in SCRIPT */
662 scsi_int_mask
=STO
| UDC
| MA
; /* | CMP; / * Interrupts which are enabled */
663 script_int_mask
=0xff; /* enable all Ints */
665 scsi_write_dsp(phys_to_bus(&script_select
[0])); /* start script */
666 /* now we have to wait for IRQs */
669 * This version of the driver is _not_ interrupt driven,
670 * but polls the chip's interrupt registers (ISTAT, DSTAT).
672 while(int_stat
[0]==0)
675 if(int_stat
[0]==SIR_COMPLETE
) {
676 if(pccb
->msgin
[0]==M_DISCONNECT
) {
677 PRINTF("Wait for reselection\n");
679 int_stat
[i
]=0; /* delete all int status */
680 scsi_write_dsp(phys_to_bus(&script_reselection
[0])); /* start reselection script */
683 pccb
->contr_stat
=SIR_COMPLETE
;
686 if((int_stat
[0] & SCSI_INT_STATE
)==SCSI_INT_STATE
) { /* scsi interrupt */
687 sstat
=(unsigned short)int_stat
[0];
688 if((sstat
& STO
)==STO
) { /* selection timeout */
689 pccb
->contr_stat
=SCSI_SEL_TIME_OUT
;
690 scsi_write_byte(GPREG
,0x01);
691 PRINTF("ID: %X Selection Timeout\n",pccb
->target
);
694 if((sstat
& UDC
)==UDC
) { /* unexpected disconnect */
695 pccb
->contr_stat
=SCSI_UNEXP_DIS
;
696 scsi_write_byte(GPREG
,0x01);
697 PRINTF("ID: %X Unexpected Disconnect\n",pccb
->target
);
700 if((sstat
& RSL
)==RSL
) { /* reselection */
701 pccb
->contr_stat
=SCSI_UNEXP_DIS
;
702 scsi_write_byte(GPREG
,0x01);
703 PRINTF("ID: %X Unexpected Disconnect\n",pccb
->target
);
706 if(((sstat
& MA
)==MA
)||((sstat
& HTH
)==HTH
)) { /* phase missmatch */
707 if(retrycnt
<SCSI_MAX_RETRY
) {
708 pccb
->trans_bytes
=pccb
->datalen
-
709 ((unsigned long)scsi_read_byte(DBC
) |
710 ((unsigned long)scsi_read_byte(DBC
+1)<<8) |
711 ((unsigned long)scsi_read_byte(DBC
+2)<<16));
713 int_stat
[i
]=0; /* delete all int status */
715 PRINTF("ID: %X Phase Missmatch Retry %d Phase %02X transfered %lx\n",
716 pccb
->target
,retrycnt
,scsi_read_byte(SBCL
),pccb
->trans_bytes
);
717 scsi_write_dsp(phys_to_bus(&script_cmd
[4])); /* start retry script */
721 pccb
->contr_stat
=SCSI_MA_TIME_OUT
;
723 pccb
->contr_stat
=SCSI_HNS_TIME_OUT
;
724 PRINTF("Phase Missmatch stat %lx\n",pccb
->contr_stat
);
727 /* if((sstat & CMP)==CMP) {
728 pccb->contr_stat=SIR_COMPLETE;
732 PRINTF("SCSI INT %lX\n",int_stat
[0]);
733 pccb
->contr_stat
=int_stat
[0];
736 PRINTF("SCRIPT INT %lX phase %02X\n",int_stat
[0],scsi_read_byte(SBCL
));
737 pccb
->contr_stat
=int_stat
[0];
741 int scsi_exec(ccb
*pccb
)
743 unsigned char tmpcmd
[16],tmpstat
;
745 unsigned long transbytes
,datalen
;
746 unsigned char *tmpptr
;
750 if(pccb
->contr_stat
!=SIR_COMPLETE
)
752 if(pccb
->status
==S_GOOD
)
754 if(pccb
->status
==S_CHECK_COND
) { /* check condition */
756 tmpcmd
[i
]=pccb
->cmd
[i
];
757 pccb
->cmd
[0]=SCSI_REQ_SENSE
;
758 pccb
->cmd
[1]=pccb
->lun
<<5;
764 pccb
->msgout
[0]=SCSI_IDENTIFY
;
765 transbytes
=pccb
->trans_bytes
;
767 pccb
->pdata
= &pccb
->sense_buf
[0];
768 datalen
=pccb
->datalen
;
770 tmpstat
=pccb
->status
;
773 pccb
->cmd
[i
]=tmpcmd
[i
];
774 pccb
->trans_bytes
=transbytes
;
776 pccb
->datalen
=datalen
;
777 pccb
->status
=tmpstat
;
778 PRINTF("Request_sense sense key %x ASC %x ASCQ %x\n",pccb
->sense_buf
[2]&0x0f,
779 pccb
->sense_buf
[12],pccb
->sense_buf
[13]);
780 switch(pccb
->sense_buf
[2]&0xf) {
782 case SENSE_RECOVERED_ERROR
:
786 case SENSE_NOT_READY
:
787 if((pccb
->sense_buf
[12]!=0x04)||(pccb
->sense_buf
[13]!=0x01)) {
788 /* if device is not in process of becoming ready */
791 } /* else fall through */
792 case SENSE_UNIT_ATTENTION
:
793 if(retrycnt
<SCSI_MAX_RETRY_NOT_READY
) {
794 PRINTF("Target %d not ready, retry %d\n",pccb
->target
,retrycnt
);
795 for(t
=0;t
<SCSI_NOT_READY_TIME_OUT
;t
++)
796 udelay(1000); /* 1sec wait */
800 PRINTF("Target %d not ready, %d retried\n",pccb
->target
,retrycnt
);
806 PRINTF("Status = %X\n",pccb
->status
);
811 void scsi_chip_init(void)
813 /* first we issue a soft reset */
814 scsi_write_byte(ISTAT
,SRST
);
816 scsi_write_byte(ISTAT
,0);
818 scsi_write_byte(SCNTL0
,0xC0); /* full arbitration no start, no message, parity disabled, master */
819 scsi_write_byte(SCNTL1
,0x00);
820 scsi_write_byte(SCNTL2
,0x00);
821 #ifndef CONFIG_SYS_SCSI_SYM53C8XX_CCF /* config value for none 40 MHz clocks */
822 scsi_write_byte(SCNTL3
,0x13); /* synchronous clock 40/4=10MHz, asynchronous 40MHz */
824 scsi_write_byte(SCNTL3
,CONFIG_SYS_SCSI_SYM53C8XX_CCF
); /* config value for none 40 MHz clocks */
826 scsi_write_byte(SCID
,0x47); /* ID=7, enable reselection */
827 scsi_write_byte(SXFER
,0x00); /* synchronous transfer period 10MHz, asynchronous */
828 scsi_write_byte(SDID
,0x00); /* targed SCSI ID = 0 */
829 scsi_int_mask
=0x0000; /* no Interrupt is enabled */
830 script_int_mask
=0x00;
832 scsi_write_byte(GPREG
,0x01); /* GPIO0 is LED (off) */
833 scsi_write_byte(GPCNTL
,0x0E); /* GPIO0 is Output */
834 scsi_write_byte(STIME0
,0x08); /* handshake timer disabled, selection timeout 512msec */
835 scsi_write_byte(RESPID
,0x80); /* repond only to the own ID (reselection) */
836 scsi_write_byte(STEST1
,0x00); /* not isolated, SCLK is used */
837 scsi_write_byte(STEST2
,0x00); /* no Lowlevel Mode? */
838 scsi_write_byte(STEST3
,0x80); /* enable tolerANT */
839 scsi_write_byte(CTEST3
,0x04); /* clear FIFO */
840 scsi_write_byte(CTEST4
,0x00);
841 scsi_write_byte(CTEST5
,0x00);
842 #ifdef SCSI_SINGLE_STEP
843 /* scsi_write_byte(DCNTL,IRQM | SSM); */
844 scsi_write_byte(DCNTL
,IRQD
| SSM
);
845 scsi_write_byte(DMODE
,MAN
);
847 /* scsi_write_byte(DCNTL,IRQM); */
848 scsi_write_byte(DCNTL
,IRQD
);
849 scsi_write_byte(DMODE
,0x00);