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_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)
287 return ((val >> 24) & 0xff) | ((val >> 8) & 0xff00) |
288 ((val << 8) & 0xff0000) | ((val << 24) & 0xff000000);
292 void scsi_write_byte(ulong offset,unsigned char val)
294 out8(scsi_mem_addr+offset,val);
298 unsigned char scsi_read_byte(ulong offset)
300 return(in8(scsi_mem_addr+offset));
304 /********************************************************************************
307 void handle_scsi_int(void)
309 unsigned char stat,stat1,stat2;
310 unsigned short sstat;
312 #ifdef SCSI_SINGLE_STEP
315 stat=scsi_read_byte(ISTAT);
316 if((stat & DIP)==DIP) { /* DMA Interrupt pending */
317 stat1=scsi_read_byte(DSTAT);
318 #ifdef SCSI_SINGLE_STEP
319 if((stat1 & SSI)==SSI) {
320 tt=in32r(scsi_mem_addr+DSP);
321 if(((tt)>=start_script_select) && ((tt)<start_script_select+len_script_select)) {
322 printf("select %d\n",(tt-start_script_select)>>2);
325 if(((tt)>=start_script_msgout) && ((tt)<start_script_msgout+len_script_msgout)) {
326 printf("msgout %d\n",(tt-start_script_msgout)>>2);
329 if(((tt)>=start_script_msgin) && ((tt)<start_script_msgin+len_script_msgin)) {
330 printf("msgin %d\n",(tt-start_script_msgin)>>2);
333 if(((tt)>=start_script_msg_ext) && ((tt)<start_script_msg_ext+len_script_msg_ext)) {
334 printf("msgin_ext %d\n",(tt-start_script_msg_ext)>>2);
337 if(((tt)>=start_script_cmd) && ((tt)<start_script_cmd+len_script_cmd)) {
338 printf("cmd %d\n",(tt-start_script_cmd)>>2);
341 if(((tt)>=start_script_data_in) && ((tt)<start_script_data_in+len_script_data_in)) {
342 printf("data_in %d\n",(tt-start_script_data_in)>>2);
345 if(((tt)>=start_script_data_out) && ((tt)<start_script_data_out+len_script_data_out)) {
346 printf("data_out %d\n",(tt-start_script_data_out)>>2);
349 if(((tt)>=start_script_status) && ((tt)<start_script_status+len_script_status)) {
350 printf("status %d\n",(tt-start_script_status)>>2);
353 if(((tt)>=start_script_complete) && ((tt)<start_script_complete+len_script_complete)) {
354 printf("complete %d\n",(tt-start_script_complete)>>2);
357 if(((tt)>=start_script_error) && ((tt)<start_script_error+len_script_error)) {
358 printf("error %d\n",(tt-start_script_error)>>2);
361 if(((tt)>=start_script_reselection) && ((tt)<start_script_reselection+len_script_reselection)) {
362 printf("reselection %d\n",(tt-start_script_reselection)>>2);
365 printf("sc: %lx\n",tt);
367 stat2=scsi_read_byte(DCNTL);
369 scsi_write_byte(DCNTL,stat2);
372 if((stat1 & SIR)==SIR) /* script interrupt */
374 int_stat[0]=in32(scsi_mem_addr+DSPS);
376 if((stat1 & DFE)==0) { /* fifo not epmty */
377 scsi_write_byte(CTEST3,CLF); /* Clear DMA FIFO */
378 stat2=scsi_read_byte(STEST3);
379 scsi_write_byte(STEST3,(stat2 | CSF)); /* Clear SCSI FIFO */
382 if((stat & SIP)==SIP) { /* scsi interrupt */
383 sstat = (unsigned short)scsi_read_byte(SIST+1);
385 sstat |= (unsigned short)scsi_read_byte(SIST);
388 break; /* found an empty int status */
390 int_stat[i]=SCSI_INT_STATE | sstat;
391 stat1=scsi_read_byte(DSTAT);
392 if((stat1 & DFE)==0) { /* fifo not epmty */
393 scsi_write_byte(CTEST3,CLF); /* Clear DMA FIFO */
394 stat2=scsi_read_byte(STEST3);
395 scsi_write_byte(STEST3,(stat2 | CSF)); /* Clear SCSI FIFO */
398 if((stat & INTF)==INTF) { /* interrupt on Fly */
399 scsi_write_byte(ISTAT,stat); /* clear it */
402 break; /* found an empty int status */
404 int_stat[i]=INT_ON_FY;
408 void scsi_bus_reset(void)
412 int end = CONFIG_SYS_SCSI_SPIN_UP_TIME*1000;
414 t=scsi_read_byte(SCNTL1);
415 scsi_write_byte(SCNTL1,(t | CRST));
417 scsi_write_byte(SCNTL1,t);
419 puts("waiting for devices to spin up");
421 udelay(1000); /* give the devices time to spin up */
426 scsi_chip_init(); /* reinit the chip ...*/
430 void scsi_int_enable(void)
432 scsi_write_byte(SIEN,(unsigned char)scsi_int_mask);
433 scsi_write_byte(SIEN+1,(unsigned char)(scsi_int_mask>>8));
434 scsi_write_byte(DIEN,script_int_mask);
437 void scsi_write_dsp(unsigned long start)
439 #ifdef SCSI_SINGLE_STEP
442 out32r(scsi_mem_addr + DSP,start);
443 #ifdef SCSI_SINGLE_STEP
444 t=scsi_read_byte(DCNTL);
446 scsi_write_byte(DCNTL,t);
450 /* only used for debug purposes */
451 void scsi_print_script(void)
453 printf("script_select @ 0x%08lX\n",(unsigned long)&script_select[0]);
454 printf("script_msgout @ 0x%08lX\n",(unsigned long)&script_msgout[0]);
455 printf("script_msgin @ 0x%08lX\n",(unsigned long)&script_msgin[0]);
456 printf("script_msgext @ 0x%08lX\n",(unsigned long)&script_msg_ext[0]);
457 printf("script_cmd @ 0x%08lX\n",(unsigned long)&script_cmd[0]);
458 printf("script_data_in @ 0x%08lX\n",(unsigned long)&script_data_in[0]);
459 printf("script_data_out @ 0x%08lX\n",(unsigned long)&script_data_out[0]);
460 printf("script_status @ 0x%08lX\n",(unsigned long)&script_status[0]);
461 printf("script_complete @ 0x%08lX\n",(unsigned long)&script_complete[0]);
462 printf("script_error @ 0x%08lX\n",(unsigned long)&script_error[0]);
466 void scsi_set_script(ccb *pccb)
468 int busdevfunc = pccb->priv;
471 script_select[i++]=swap_script(SCR_REG_REG(GPREG, SCR_AND, 0xfe));
472 script_select[i++]=0; /* LED ON */
473 script_select[i++]=swap_script(SCR_CLR(SCR_TRG)); /* select initiator mode */
474 script_select[i++]=0;
475 /* script_select[i++]=swap_script(SCR_SEL_ABS_ATN | pccb->target << 16); */
476 script_select[i++]=swap_script(SCR_SEL_ABS | pccb->target << 16);
477 script_select[i++]=swap_script(phys_to_bus(&script_cmd[4])); /* error handling */
478 script_select[i++]=swap_script(SCR_JUMP); /* next section */
479 /* script_select[i++]=swap_script((unsigned long)&script_msgout[0]); */ /* message out */
480 script_select[i++]=swap_script(phys_to_bus(&script_cmd[0])); /* command out */
482 #ifdef SCSI_SINGLE_STEP
483 start_script_select=(unsigned long)&script_select[0];
484 len_script_select=i*4;
488 script_msgout[i++]=swap_script(SCR_INT ^ IFFALSE (WHEN (SCR_MSG_OUT)));
489 script_msgout[i++]=SIR_SEL_ATN_NO_MSG_OUT;
490 script_msgout[i++]=swap_script( SCR_MOVE_ABS(1) ^ SCR_MSG_OUT);
491 script_msgout[i++]=swap_script(phys_to_bus(&pccb->msgout[0]));
492 script_msgout[i++]=swap_script(SCR_JUMP ^ IFTRUE (WHEN (SCR_COMMAND))); /* if Command phase */
493 script_msgout[i++]=swap_script(phys_to_bus(&script_cmd[0])); /* switch to command */
494 script_msgout[i++]=swap_script(SCR_INT); /* interrupt if not */
495 script_msgout[i++]=SIR_MSG_OUT_NO_CMD;
497 #ifdef SCSI_SINGLE_STEP
498 start_script_msgout=(unsigned long)&script_msgout[0];
499 len_script_msgout=i*4;
502 script_cmd[i++]=swap_script(SCR_MOVE_ABS(pccb->cmdlen) ^ SCR_COMMAND);
503 script_cmd[i++]=swap_script(phys_to_bus(&pccb->cmd[0]));
504 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN))); /* message in ? */
505 script_cmd[i++]=swap_script(phys_to_bus(&script_msgin[0]));
506 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (IF (SCR_DATA_OUT))); /* data out ? */
507 script_cmd[i++]=swap_script(phys_to_bus(&script_data_out[0]));
508 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (IF (SCR_DATA_IN))); /* data in ? */
509 script_cmd[i++]=swap_script(phys_to_bus(&script_data_in[0]));
510 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (IF (SCR_STATUS))); /* status ? */
511 script_cmd[i++]=swap_script(phys_to_bus(&script_status[0]));
512 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (IF (SCR_COMMAND))); /* command ? */
513 script_cmd[i++]=swap_script(phys_to_bus(&script_cmd[0]));
514 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (IF (SCR_MSG_OUT))); /* message out ? */
515 script_cmd[i++]=swap_script(phys_to_bus(&script_msgout[0]));
516 script_cmd[i++]=swap_script(SCR_JUMP ^ IFTRUE (IF (SCR_MSG_IN))); /* just for error handling message in ? */
517 script_cmd[i++]=swap_script(phys_to_bus(&script_msgin[0]));
518 script_cmd[i++]=swap_script(SCR_INT); /* interrupt if not */
519 script_cmd[i++]=SIR_CMD_OUT_ILL_PH;
520 #ifdef SCSI_SINGLE_STEP
521 start_script_cmd=(unsigned long)&script_cmd[0];
525 script_data_out[i++]=swap_script(SCR_MOVE_ABS(pccb->datalen)^ SCR_DATA_OUT); /* move */
526 script_data_out[i++]=swap_script(phys_to_bus(pccb->pdata)); /* pointer to buffer */
527 script_data_out[i++]=swap_script(SCR_JUMP ^ IFTRUE (WHEN (SCR_STATUS)));
528 script_data_out[i++]=swap_script(phys_to_bus(&script_status[0]));
529 script_data_out[i++]=swap_script(SCR_INT);
530 script_data_out[i++]=SIR_DATA_OUT_ERR;
532 #ifdef SCSI_SINGLE_STEP
533 start_script_data_out=(unsigned long)&script_data_out[0];
534 len_script_data_out=i*4;
537 script_data_in[i++]=swap_script(SCR_MOVE_ABS(pccb->datalen)^ SCR_DATA_IN); /* move */
538 script_data_in[i++]=swap_script(phys_to_bus(pccb->pdata)); /* pointer to buffer */
539 script_data_in[i++]=swap_script(SCR_JUMP ^ IFTRUE (WHEN (SCR_STATUS)));
540 script_data_in[i++]=swap_script(phys_to_bus(&script_status[0]));
541 script_data_in[i++]=swap_script(SCR_INT);
542 script_data_in[i++]=SIR_DATA_IN_ERR;
543 #ifdef SCSI_SINGLE_STEP
544 start_script_data_in=(unsigned long)&script_data_in[0];
545 len_script_data_in=i*4;
548 script_msgin[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN);
549 script_msgin[i++]=swap_script(phys_to_bus(&pccb->msgin[0]));
550 script_msgin[i++]=swap_script(SCR_JUMP ^ IFTRUE (DATA (M_COMPLETE)));
551 script_msgin[i++]=swap_script(phys_to_bus(&script_complete[0]));
552 script_msgin[i++]=swap_script(SCR_JUMP ^ IFTRUE (DATA (M_DISCONNECT)));
553 script_msgin[i++]=swap_script(phys_to_bus(&script_complete[0]));
554 script_msgin[i++]=swap_script(SCR_JUMP ^ IFTRUE (DATA (M_SAVE_DP)));
555 script_msgin[i++]=swap_script(phys_to_bus(&script_complete[0]));
556 script_msgin[i++]=swap_script(SCR_JUMP ^ IFTRUE (DATA (M_RESTORE_DP)));
557 script_msgin[i++]=swap_script(phys_to_bus(&script_complete[0]));
558 script_msgin[i++]=swap_script(SCR_JUMP ^ IFTRUE (DATA (M_EXTENDED)));
559 script_msgin[i++]=swap_script(phys_to_bus(&script_msg_ext[0]));
560 script_msgin[i++]=swap_script(SCR_INT);
561 script_msgin[i++]=SIR_MSG_RECEIVED;
562 #ifdef SCSI_SINGLE_STEP
563 start_script_msgin=(unsigned long)&script_msgin[0];
564 len_script_msgin=i*4;
567 script_msg_ext[i++]=swap_script(SCR_CLR (SCR_ACK)); /* clear ACK */
568 script_msg_ext[i++]=0;
569 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* assuming this is the msg length */
570 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[1]));
571 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
572 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
573 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* next */
574 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[2]));
575 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
576 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
577 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* next */
578 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[3]));
579 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
580 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
581 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* next */
582 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[4]));
583 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
584 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
585 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* next */
586 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[5]));
587 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
588 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
589 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* next */
590 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[6]));
591 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
592 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
593 script_msg_ext[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_MSG_IN); /* next */
594 script_msg_ext[i++]=swap_script(phys_to_bus(&pccb->msgin[7]));
595 script_msg_ext[i++]=swap_script(SCR_JUMP ^ IFFALSE (IF (SCR_MSG_IN)));
596 script_msg_ext[i++]=swap_script(phys_to_bus(&script_complete[0])); /* no more bytes */
597 script_msg_ext[i++]=swap_script(SCR_INT);
598 script_msg_ext[i++]=SIR_MSG_OVER7;
599 #ifdef SCSI_SINGLE_STEP
600 start_script_msg_ext=(unsigned long)&script_msg_ext[0];
601 len_script_msg_ext=i*4;
604 script_status[i++]=swap_script(SCR_MOVE_ABS (1) ^ SCR_STATUS);
605 script_status[i++]=swap_script(phys_to_bus(&pccb->status));
606 script_status[i++]=swap_script(SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)));
607 script_status[i++]=swap_script(phys_to_bus(&script_msgin[0]));
608 script_status[i++]=swap_script(SCR_INT);
609 script_status[i++]=SIR_STATUS_ILL_PH;
610 #ifdef SCSI_SINGLE_STEP
611 start_script_status=(unsigned long)&script_status[0];
612 len_script_status=i*4;
615 script_complete[i++]=swap_script(SCR_REG_REG (SCNTL2, SCR_AND, 0x7f));
616 script_complete[i++]=0;
617 script_complete[i++]=swap_script(SCR_CLR (SCR_ACK|SCR_ATN));
618 script_complete[i++]=0;
619 script_complete[i++]=swap_script(SCR_WAIT_DISC);
620 script_complete[i++]=0;
621 script_complete[i++]=swap_script(SCR_REG_REG(GPREG, SCR_OR, 0x01));
622 script_complete[i++]=0; /* LED OFF */
623 script_complete[i++]=swap_script(SCR_INT);
624 script_complete[i++]=SIR_COMPLETE;
625 #ifdef SCSI_SINGLE_STEP
626 start_script_complete=(unsigned long)&script_complete[0];
627 len_script_complete=i*4;
630 script_error[i++]=swap_script(SCR_INT); /* interrupt if error */
631 script_error[i++]=SIR_SCRIPT_ERROR;
632 #ifdef SCSI_SINGLE_STEP
633 start_script_error=(unsigned long)&script_error[0];
634 len_script_error=i*4;
637 script_reselection[i++]=swap_script(SCR_CLR (SCR_TRG)); /* target status */
638 script_reselection[i++]=0;
639 script_reselection[i++]=swap_script(SCR_WAIT_RESEL);
640 script_reselection[i++]=swap_script(phys_to_bus(&script_select[0])); /* len = 4 */
641 #ifdef SCSI_SINGLE_STEP
642 start_script_reselection=(unsigned long)&script_reselection[0];
643 len_script_reselection=i*4;
648 void scsi_issue(ccb *pccb)
650 int busdevfunc = pccb->priv;
652 unsigned short sstat;
653 int retrycnt; /* retry counter */
655 int_stat[i]=0; /* delete all int status */
656 /* struct pccb must be set-up correctly */
658 PRINTF("ID %d issue cmd %02X\n",pccb->target,pccb->cmd[0]);
659 pccb->trans_bytes=0; /* no bytes transferred yet */
660 scsi_set_script(pccb); /* fill in SCRIPT */
661 scsi_int_mask=STO | UDC | MA; /* | CMP; / * Interrupts which are enabled */
662 script_int_mask=0xff; /* enable all Ints */
664 scsi_write_dsp(phys_to_bus(&script_select[0])); /* start script */
665 /* now we have to wait for IRQs */
668 * This version of the driver is _not_ interrupt driven,
669 * but polls the chip's interrupt registers (ISTAT, DSTAT).
671 while(int_stat[0]==0)
674 if(int_stat[0]==SIR_COMPLETE) {
675 if(pccb->msgin[0]==M_DISCONNECT) {
676 PRINTF("Wait for reselection\n");
678 int_stat[i]=0; /* delete all int status */
679 scsi_write_dsp(phys_to_bus(&script_reselection[0])); /* start reselection script */
682 pccb->contr_stat=SIR_COMPLETE;
685 if((int_stat[0] & SCSI_INT_STATE)==SCSI_INT_STATE) { /* scsi interrupt */
686 sstat=(unsigned short)int_stat[0];
687 if((sstat & STO)==STO) { /* selection timeout */
688 pccb->contr_stat=SCSI_SEL_TIME_OUT;
689 scsi_write_byte(GPREG,0x01);
690 PRINTF("ID: %X Selection Timeout\n",pccb->target);
693 if((sstat & UDC)==UDC) { /* unexpected disconnect */
694 pccb->contr_stat=SCSI_UNEXP_DIS;
695 scsi_write_byte(GPREG,0x01);
696 PRINTF("ID: %X Unexpected Disconnect\n",pccb->target);
699 if((sstat & RSL)==RSL) { /* reselection */
700 pccb->contr_stat=SCSI_UNEXP_DIS;
701 scsi_write_byte(GPREG,0x01);
702 PRINTF("ID: %X Unexpected Disconnect\n",pccb->target);
705 if(((sstat & MA)==MA)||((sstat & HTH)==HTH)) { /* phase missmatch */
706 if(retrycnt<SCSI_MAX_RETRY) {
707 pccb->trans_bytes=pccb->datalen -
708 ((unsigned long)scsi_read_byte(DBC) |
709 ((unsigned long)scsi_read_byte(DBC+1)<<8) |
710 ((unsigned long)scsi_read_byte(DBC+2)<<16));
712 int_stat[i]=0; /* delete all int status */
714 PRINTF("ID: %X Phase Missmatch Retry %d Phase %02X transferred %lx\n",
715 pccb->target,retrycnt,scsi_read_byte(SBCL),pccb->trans_bytes);
716 scsi_write_dsp(phys_to_bus(&script_cmd[4])); /* start retry script */
720 pccb->contr_stat=SCSI_MA_TIME_OUT;
722 pccb->contr_stat=SCSI_HNS_TIME_OUT;
723 PRINTF("Phase Missmatch stat %lx\n",pccb->contr_stat);
726 /* if((sstat & CMP)==CMP) {
727 pccb->contr_stat=SIR_COMPLETE;
731 PRINTF("SCSI INT %lX\n",int_stat[0]);
732 pccb->contr_stat=int_stat[0];
735 PRINTF("SCRIPT INT %lX phase %02X\n",int_stat[0],scsi_read_byte(SBCL));
736 pccb->contr_stat=int_stat[0];
740 int scsi_exec(ccb *pccb)
742 unsigned char tmpcmd[16],tmpstat;
744 unsigned long transbytes,datalen;
745 unsigned char *tmpptr;
749 if(pccb->contr_stat!=SIR_COMPLETE)
751 if(pccb->status==S_GOOD)
753 if(pccb->status==S_CHECK_COND) { /* check condition */
755 tmpcmd[i]=pccb->cmd[i];
756 pccb->cmd[0]=SCSI_REQ_SENSE;
757 pccb->cmd[1]=pccb->lun<<5;
763 pccb->msgout[0]=SCSI_IDENTIFY;
764 transbytes=pccb->trans_bytes;
766 pccb->pdata = &pccb->sense_buf[0];
767 datalen=pccb->datalen;
769 tmpstat=pccb->status;
772 pccb->cmd[i]=tmpcmd[i];
773 pccb->trans_bytes=transbytes;
775 pccb->datalen=datalen;
776 pccb->status=tmpstat;
777 PRINTF("Request_sense sense key %x ASC %x ASCQ %x\n",pccb->sense_buf[2]&0x0f,
778 pccb->sense_buf[12],pccb->sense_buf[13]);
779 switch(pccb->sense_buf[2]&0xf) {
781 case SENSE_RECOVERED_ERROR:
785 case SENSE_NOT_READY:
786 if((pccb->sense_buf[12]!=0x04)||(pccb->sense_buf[13]!=0x01)) {
787 /* if device is not in process of becoming ready */
790 } /* else fall through */
791 case SENSE_UNIT_ATTENTION:
792 if(retrycnt<SCSI_MAX_RETRY_NOT_READY) {
793 PRINTF("Target %d not ready, retry %d\n",pccb->target,retrycnt);
794 for(t=0;t<SCSI_NOT_READY_TIME_OUT;t++)
795 udelay(1000); /* 1sec wait */
799 PRINTF("Target %d not ready, %d retried\n",pccb->target,retrycnt);
805 PRINTF("Status = %X\n",pccb->status);
810 void scsi_chip_init(void)
812 /* first we issue a soft reset */
813 scsi_write_byte(ISTAT,SRST);
815 scsi_write_byte(ISTAT,0);
817 scsi_write_byte(SCNTL0,0xC0); /* full arbitration no start, no message, parity disabled, master */
818 scsi_write_byte(SCNTL1,0x00);
819 scsi_write_byte(SCNTL2,0x00);
820 #ifndef CONFIG_SYS_SCSI_SYM53C8XX_CCF /* config value for none 40 MHz clocks */
821 scsi_write_byte(SCNTL3,0x13); /* synchronous clock 40/4=10MHz, asynchronous 40MHz */
823 scsi_write_byte(SCNTL3,CONFIG_SYS_SCSI_SYM53C8XX_CCF); /* config value for none 40 MHz clocks */
825 scsi_write_byte(SCID,0x47); /* ID=7, enable reselection */
826 scsi_write_byte(SXFER,0x00); /* synchronous transfer period 10MHz, asynchronous */
827 scsi_write_byte(SDID,0x00); /* targed SCSI ID = 0 */
828 scsi_int_mask=0x0000; /* no Interrupt is enabled */
829 script_int_mask=0x00;
831 scsi_write_byte(GPREG,0x01); /* GPIO0 is LED (off) */
832 scsi_write_byte(GPCNTL,0x0E); /* GPIO0 is Output */
833 scsi_write_byte(STIME0,0x08); /* handshake timer disabled, selection timeout 512msec */
834 scsi_write_byte(RESPID,0x80); /* repond only to the own ID (reselection) */
835 scsi_write_byte(STEST1,0x00); /* not isolated, SCLK is used */
836 scsi_write_byte(STEST2,0x00); /* no Lowlevel Mode? */
837 scsi_write_byte(STEST3,0x80); /* enable tolerANT */
838 scsi_write_byte(CTEST3,0x04); /* clear FIFO */
839 scsi_write_byte(CTEST4,0x00);
840 scsi_write_byte(CTEST5,0x00);
841 #ifdef SCSI_SINGLE_STEP
842 /* scsi_write_byte(DCNTL,IRQM | SSM); */
843 scsi_write_byte(DCNTL,IRQD | SSM);
844 scsi_write_byte(DMODE,MAN);
846 /* scsi_write_byte(DCNTL,IRQM); */
847 scsi_write_byte(DCNTL,IRQD);
848 scsi_write_byte(DMODE,0x00);