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>
6 * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
8 * This driver is derived from the Linux sym53c8xx driver.
9 * Copyright (C) 1998-2000 Gerard Roudier
11 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
12 * a port of the FreeBSD ncr driver to Linux-1.2.13.
14 * The original ncr driver has been written for 386bsd and FreeBSD by
15 * Wolfgang Stanglmeier <wolf@cologne.de>
16 * Stefan Esser <se@mi.Uni-Koeln.de>
17 * Copyright (C) 1994 Wolfgang Stanglmeier
19 * Other major contributions:
21 * NVRAM detection and reading.
22 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
24 *-----------------------------------------------------------------------------
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 #include "sym_nvram.h"
44 #define SYM_DEBUG_GENERIC_SUPPORT
48 * Needed function prototypes.
50 static void sym_int_ma (struct sym_hcb
*np
);
51 static void sym_int_sir (struct sym_hcb
*np
);
52 static struct sym_ccb
*sym_alloc_ccb(struct sym_hcb
*np
);
53 static struct sym_ccb
*sym_ccb_from_dsa(struct sym_hcb
*np
, u32 dsa
);
54 static void sym_alloc_lcb_tags (struct sym_hcb
*np
, u_char tn
, u_char ln
);
55 static void sym_complete_error (struct sym_hcb
*np
, struct sym_ccb
*cp
);
56 static void sym_complete_ok (struct sym_hcb
*np
, struct sym_ccb
*cp
);
57 static int sym_compute_residual(struct sym_hcb
*np
, struct sym_ccb
*cp
);
60 * Print a buffer in hexadecimal format with a ".\n" at end.
62 static void sym_printl_hex(u_char
*p
, int n
)
70 * Print out the content of a SCSI message.
72 static int sym_show_msg (u_char
* msg
)
76 if (*msg
==M_EXTENDED
) {
78 if (i
-1>msg
[1]) break;
79 printf ("-%x",msg
[i
]);
82 } else if ((*msg
& 0xf0) == 0x20) {
83 printf ("-%x",msg
[1]);
89 static void sym_print_msg(struct sym_ccb
*cp
, char *label
, u_char
*msg
)
91 sym_print_addr(cp
->cmd
, "%s: ", label
);
97 static void sym_print_nego_msg(struct sym_hcb
*np
, int target
, char *label
, u_char
*msg
)
99 struct sym_tcb
*tp
= &np
->target
[target
];
100 dev_info(&tp
->sdev
->sdev_target
->dev
, "%s: ", label
);
107 * Print something that tells about extended errors.
109 void sym_print_xerr(struct scsi_cmnd
*cmd
, int x_status
)
111 if (x_status
& XE_PARITY_ERR
) {
112 sym_print_addr(cmd
, "unrecovered SCSI parity error.\n");
114 if (x_status
& XE_EXTRA_DATA
) {
115 sym_print_addr(cmd
, "extraneous data discarded.\n");
117 if (x_status
& XE_BAD_PHASE
) {
118 sym_print_addr(cmd
, "illegal scsi phase (4/5).\n");
120 if (x_status
& XE_SODL_UNRUN
) {
121 sym_print_addr(cmd
, "ODD transfer in DATA OUT phase.\n");
123 if (x_status
& XE_SWIDE_OVRUN
) {
124 sym_print_addr(cmd
, "ODD transfer in DATA IN phase.\n");
129 * Return a string for SCSI BUS mode.
131 static char *sym_scsi_bus_mode(int mode
)
134 case SMODE_HVD
: return "HVD";
135 case SMODE_SE
: return "SE";
136 case SMODE_LVD
: return "LVD";
142 * Soft reset the chip.
144 * Raising SRST when the chip is running may cause
145 * problems on dual function chips (see below).
146 * On the other hand, LVD devices need some delay
147 * to settle and report actual BUS mode in STEST4.
149 static void sym_chip_reset (struct sym_hcb
*np
)
151 OUTB(np
, nc_istat
, SRST
);
153 OUTB(np
, nc_istat
, 0);
154 udelay(2000); /* For BUS MODE to settle */
158 * Really soft reset the chip.:)
160 * Some 896 and 876 chip revisions may hang-up if we set
161 * the SRST (soft reset) bit at the wrong time when SCRIPTS
163 * So, we need to abort the current operation prior to
164 * soft resetting the chip.
166 static void sym_soft_reset (struct sym_hcb
*np
)
171 if (!(np
->features
& FE_ISTAT1
) || !(INB(np
, nc_istat1
) & SCRUN
))
174 OUTB(np
, nc_istat
, CABRT
);
175 for (i
= 100000 ; i
; --i
) {
176 istat
= INB(np
, nc_istat
);
180 else if (istat
& DIP
) {
181 if (INB(np
, nc_dstat
) & ABRT
)
186 OUTB(np
, nc_istat
, 0);
188 printf("%s: unable to abort current chip operation, "
189 "ISTAT=0x%02x.\n", sym_name(np
), istat
);
195 * Start reset process.
197 * The interrupt handler will reinitialize the chip.
199 static void sym_start_reset(struct sym_hcb
*np
)
201 sym_reset_scsi_bus(np
, 1);
204 int sym_reset_scsi_bus(struct sym_hcb
*np
, int enab_int
)
209 sym_soft_reset(np
); /* Soft reset the chip */
211 OUTW(np
, nc_sien
, RST
);
213 * Enable Tolerant, reset IRQD if present and
214 * properly set IRQ mode, prior to resetting the bus.
216 OUTB(np
, nc_stest3
, TE
);
217 OUTB(np
, nc_dcntl
, (np
->rv_dcntl
& IRQM
));
218 OUTB(np
, nc_scntl1
, CRST
);
221 if (!SYM_SETUP_SCSI_BUS_CHECK
)
224 * Check for no terminators or SCSI bus shorts to ground.
225 * Read SCSI data bus, data parity bits and control signals.
226 * We are expecting RESET to be TRUE and other signals to be
229 term
= INB(np
, nc_sstat0
);
230 term
= ((term
& 2) << 7) + ((term
& 1) << 17); /* rst sdp0 */
231 term
|= ((INB(np
, nc_sstat2
) & 0x01) << 26) | /* sdp1 */
232 ((INW(np
, nc_sbdl
) & 0xff) << 9) | /* d7-0 */
233 ((INW(np
, nc_sbdl
) & 0xff00) << 10) | /* d15-8 */
234 INB(np
, nc_sbcl
); /* req ack bsy sel atn msg cd io */
239 if (term
!= (2<<7)) {
240 printf("%s: suspicious SCSI data while resetting the BUS.\n",
242 printf("%s: %sdp0,d7-0,rst,req,ack,bsy,sel,atn,msg,c/d,i/o = "
243 "0x%lx, expecting 0x%lx\n",
245 (np
->features
& FE_WIDE
) ? "dp1,d15-8," : "",
246 (u_long
)term
, (u_long
)(2<<7));
247 if (SYM_SETUP_SCSI_BUS_CHECK
== 1)
251 OUTB(np
, nc_scntl1
, 0);
256 * Select SCSI clock frequency
258 static void sym_selectclock(struct sym_hcb
*np
, u_char scntl3
)
261 * If multiplier not present or not selected, leave here.
263 if (np
->multiplier
<= 1) {
264 OUTB(np
, nc_scntl3
, scntl3
);
268 if (sym_verbose
>= 2)
269 printf ("%s: enabling clock multiplier\n", sym_name(np
));
271 OUTB(np
, nc_stest1
, DBLEN
); /* Enable clock multiplier */
273 * Wait for the LCKFRQ bit to be set if supported by the chip.
274 * Otherwise wait 50 micro-seconds (at least).
276 if (np
->features
& FE_LCKFRQ
) {
278 while (!(INB(np
, nc_stest4
) & LCKFRQ
) && --i
> 0)
281 printf("%s: the chip cannot lock the frequency\n",
285 OUTB(np
, nc_stest3
, HSC
); /* Halt the scsi clock */
286 OUTB(np
, nc_scntl3
, scntl3
);
287 OUTB(np
, nc_stest1
, (DBLEN
|DBLSEL
));/* Select clock multiplier */
288 OUTB(np
, nc_stest3
, 0x00); /* Restart scsi clock */
293 * Determine the chip's clock frequency.
295 * This is essential for the negotiation of the synchronous
298 * Note: we have to return the correct value.
299 * THERE IS NO SAFE DEFAULT VALUE.
301 * Most NCR/SYMBIOS boards are delivered with a 40 Mhz clock.
302 * 53C860 and 53C875 rev. 1 support fast20 transfers but
303 * do not have a clock doubler and so are provided with a
304 * 80 MHz clock. All other fast20 boards incorporate a doubler
305 * and so should be delivered with a 40 MHz clock.
306 * The recent fast40 chips (895/896/895A/1010) use a 40 Mhz base
307 * clock and provide a clock quadrupler (160 Mhz).
311 * calculate SCSI clock frequency (in KHz)
313 static unsigned getfreq (struct sym_hcb
*np
, int gen
)
319 * Measure GEN timer delay in order
320 * to calculate SCSI clock frequency
322 * This code will never execute too
323 * many loop iterations (if DELAY is
324 * reasonably correct). It could get
325 * too low a delay (too high a freq.)
326 * if the CPU is slow executing the
327 * loop for some reason (an NMI, for
328 * example). For this reason we will
329 * if multiple measurements are to be
330 * performed trust the higher delay
331 * (lower frequency returned).
333 OUTW(np
, nc_sien
, 0); /* mask all scsi interrupts */
334 INW(np
, nc_sist
); /* clear pending scsi interrupt */
335 OUTB(np
, nc_dien
, 0); /* mask all dma interrupts */
336 INW(np
, nc_sist
); /* another one, just to be sure :) */
338 * The C1010-33 core does not report GEN in SIST,
339 * if this interrupt is masked in SIEN.
340 * I don't know yet if the C1010-66 behaves the same way.
342 if (np
->features
& FE_C10
) {
343 OUTW(np
, nc_sien
, GEN
);
344 OUTB(np
, nc_istat1
, SIRQD
);
346 OUTB(np
, nc_scntl3
, 4); /* set pre-scaler to divide by 3 */
347 OUTB(np
, nc_stime1
, 0); /* disable general purpose timer */
348 OUTB(np
, nc_stime1
, gen
); /* set to nominal delay of 1<<gen * 125us */
349 while (!(INW(np
, nc_sist
) & GEN
) && ms
++ < 100000)
350 udelay(1000/4); /* count in 1/4 of ms */
351 OUTB(np
, nc_stime1
, 0); /* disable general purpose timer */
353 * Undo C1010-33 specific settings.
355 if (np
->features
& FE_C10
) {
356 OUTW(np
, nc_sien
, 0);
357 OUTB(np
, nc_istat1
, 0);
360 * set prescaler to divide by whatever 0 means
361 * 0 ought to choose divide by 2, but appears
362 * to set divide by 3.5 mode in my 53c810 ...
364 OUTB(np
, nc_scntl3
, 0);
367 * adjust for prescaler, and convert into KHz
369 f
= ms
? ((1 << gen
) * (4340*4)) / ms
: 0;
372 * The C1010-33 result is biased by a factor
373 * of 2/3 compared to earlier chips.
375 if (np
->features
& FE_C10
)
378 if (sym_verbose
>= 2)
379 printf ("%s: Delay (GEN=%d): %u msec, %u KHz\n",
380 sym_name(np
), gen
, ms
/4, f
);
385 static unsigned sym_getfreq (struct sym_hcb
*np
)
390 getfreq (np
, gen
); /* throw away first result */
391 f1
= getfreq (np
, gen
);
392 f2
= getfreq (np
, gen
);
393 if (f1
> f2
) f1
= f2
; /* trust lower result */
398 * Get/probe chip SCSI clock frequency
400 static void sym_getclock (struct sym_hcb
*np
, int mult
)
402 unsigned char scntl3
= np
->sv_scntl3
;
403 unsigned char stest1
= np
->sv_stest1
;
409 * True with 875/895/896/895A with clock multiplier selected
411 if (mult
> 1 && (stest1
& (DBLEN
+DBLSEL
)) == DBLEN
+DBLSEL
) {
412 if (sym_verbose
>= 2)
413 printf ("%s: clock multiplier found\n", sym_name(np
));
414 np
->multiplier
= mult
;
418 * If multiplier not found or scntl3 not 7,5,3,
419 * reset chip and get frequency from general purpose timer.
420 * Otherwise trust scntl3 BIOS setting.
422 if (np
->multiplier
!= mult
|| (scntl3
& 7) < 3 || !(scntl3
& 1)) {
423 OUTB(np
, nc_stest1
, 0); /* make sure doubler is OFF */
424 f1
= sym_getfreq (np
);
427 printf ("%s: chip clock is %uKHz\n", sym_name(np
), f1
);
429 if (f1
< 45000) f1
= 40000;
430 else if (f1
< 55000) f1
= 50000;
433 if (f1
< 80000 && mult
> 1) {
434 if (sym_verbose
>= 2)
435 printf ("%s: clock multiplier assumed\n",
437 np
->multiplier
= mult
;
440 if ((scntl3
& 7) == 3) f1
= 40000;
441 else if ((scntl3
& 7) == 5) f1
= 80000;
444 f1
/= np
->multiplier
;
448 * Compute controller synchronous parameters.
450 f1
*= np
->multiplier
;
455 * Get/probe PCI clock frequency
457 static int sym_getpciclock (struct sym_hcb
*np
)
462 * For now, we only need to know about the actual
463 * PCI BUS clock frequency for C1010-66 chips.
466 if (np
->features
& FE_66MHZ
) {
470 OUTB(np
, nc_stest1
, SCLK
); /* Use the PCI clock as SCSI clock */
472 OUTB(np
, nc_stest1
, 0);
480 * SYMBIOS chip clock divisor table.
482 * Divisors are multiplied by 10,000,000 in order to make
483 * calculations more simple.
486 static u32 div_10M
[] = {2*_5M
, 3*_5M
, 4*_5M
, 6*_5M
, 8*_5M
, 12*_5M
, 16*_5M
};
489 * Get clock factor and sync divisor for a given
490 * synchronous factor period.
493 sym_getsync(struct sym_hcb
*np
, u_char dt
, u_char sfac
, u_char
*divp
, u_char
*fakp
)
495 u32 clk
= np
->clock_khz
; /* SCSI clock frequency in kHz */
496 int div
= np
->clock_divn
; /* Number of divisors supported */
497 u32 fak
; /* Sync factor in sxfer */
498 u32 per
; /* Period in tenths of ns */
499 u32 kpc
; /* (per * clk) */
503 * Compute the synchronous period in tenths of nano-seconds
505 if (dt
&& sfac
<= 9) per
= 125;
506 else if (sfac
<= 10) per
= 250;
507 else if (sfac
== 11) per
= 303;
508 else if (sfac
== 12) per
= 500;
509 else per
= 40 * sfac
;
517 * For earliest C10 revision 0, we cannot use extra
518 * clocks for the setting of the SCSI clocking.
519 * Note that this limits the lowest sync data transfer
520 * to 5 Mega-transfers per second and may result in
521 * using higher clock divisors.
524 if ((np
->features
& (FE_C10
|FE_U3EN
)) == FE_C10
) {
526 * Look for the lowest clock divisor that allows an
527 * output speed not faster than the period.
531 if (kpc
> (div_10M
[div
] << 2)) {
536 fak
= 0; /* No extra clocks */
537 if (div
== np
->clock_divn
) { /* Are we too fast ? */
547 * Look for the greatest clock divisor that allows an
548 * input speed faster than the period.
551 if (kpc
>= (div_10M
[div
] << 2)) break;
554 * Calculate the lowest clock factor that allows an output
555 * speed not faster than the period, and the max output speed.
556 * If fak >= 1 we will set both XCLKH_ST and XCLKH_DT.
557 * If fak >= 2 we will also set XCLKS_ST and XCLKS_DT.
560 fak
= (kpc
- 1) / (div_10M
[div
] << 1) + 1 - 2;
561 /* ret = ((2+fak)*div_10M[div])/np->clock_khz; */
563 fak
= (kpc
- 1) / div_10M
[div
] + 1 - 4;
564 /* ret = ((4+fak)*div_10M[div])/np->clock_khz; */
568 * Check against our hardware limits, or bugs :).
576 * Compute and return sync parameters.
585 * SYMBIOS chips allow burst lengths of 2, 4, 8, 16, 32, 64,
586 * 128 transfers. All chips support at least 16 transfers
587 * bursts. The 825A, 875 and 895 chips support bursts of up
588 * to 128 transfers and the 895A and 896 support bursts of up
589 * to 64 transfers. All other chips support up to 16
592 * For PCI 32 bit data transfers each transfer is a DWORD.
593 * It is a QUADWORD (8 bytes) for PCI 64 bit data transfers.
595 * We use log base 2 (burst length) as internal code, with
596 * value 0 meaning "burst disabled".
600 * Burst length from burst code.
602 #define burst_length(bc) (!(bc))? 0 : 1 << (bc)
605 * Burst code from io register bits.
607 #define burst_code(dmode, ctest4, ctest5) \
608 (ctest4) & 0x80? 0 : (((dmode) & 0xc0) >> 6) + ((ctest5) & 0x04) + 1
611 * Set initial io register bits from burst code.
613 static __inline
void sym_init_burst(struct sym_hcb
*np
, u_char bc
)
615 np
->rv_ctest4
&= ~0x80;
616 np
->rv_dmode
&= ~(0x3 << 6);
617 np
->rv_ctest5
&= ~0x4;
620 np
->rv_ctest4
|= 0x80;
624 np
->rv_dmode
|= ((bc
& 0x3) << 6);
625 np
->rv_ctest5
|= (bc
& 0x4);
631 * Print out the list of targets that have some flag disabled by user.
633 static void sym_print_targets_flag(struct sym_hcb
*np
, int mask
, char *msg
)
638 for (cnt
= 0, i
= 0 ; i
< SYM_CONF_MAX_TARGET
; i
++) {
641 if (np
->target
[i
].usrflags
& mask
) {
643 printf("%s: %s disabled for targets",
653 * Save initial settings of some IO registers.
654 * Assumed to have been set by BIOS.
655 * We cannot reset the chip prior to reading the
656 * IO registers, since informations will be lost.
657 * Since the SCRIPTS processor may be running, this
658 * is not safe on paper, but it seems to work quite
661 static void sym_save_initial_setting (struct sym_hcb
*np
)
663 np
->sv_scntl0
= INB(np
, nc_scntl0
) & 0x0a;
664 np
->sv_scntl3
= INB(np
, nc_scntl3
) & 0x07;
665 np
->sv_dmode
= INB(np
, nc_dmode
) & 0xce;
666 np
->sv_dcntl
= INB(np
, nc_dcntl
) & 0xa8;
667 np
->sv_ctest3
= INB(np
, nc_ctest3
) & 0x01;
668 np
->sv_ctest4
= INB(np
, nc_ctest4
) & 0x80;
669 np
->sv_gpcntl
= INB(np
, nc_gpcntl
);
670 np
->sv_stest1
= INB(np
, nc_stest1
);
671 np
->sv_stest2
= INB(np
, nc_stest2
) & 0x20;
672 np
->sv_stest4
= INB(np
, nc_stest4
);
673 if (np
->features
& FE_C10
) { /* Always large DMA fifo + ultra3 */
674 np
->sv_scntl4
= INB(np
, nc_scntl4
);
675 np
->sv_ctest5
= INB(np
, nc_ctest5
) & 0x04;
678 np
->sv_ctest5
= INB(np
, nc_ctest5
) & 0x24;
682 * Prepare io register values used by sym_start_up()
683 * according to selected and supported features.
685 static int sym_prepare_setting(struct Scsi_Host
*shost
, struct sym_hcb
*np
, struct sym_nvram
*nvram
)
694 np
->maxwide
= (np
->features
& FE_WIDE
)? 1 : 0;
697 * Guess the frequency of the chip's clock.
699 if (np
->features
& (FE_ULTRA3
| FE_ULTRA2
))
700 np
->clock_khz
= 160000;
701 else if (np
->features
& FE_ULTRA
)
702 np
->clock_khz
= 80000;
704 np
->clock_khz
= 40000;
707 * Get the clock multiplier factor.
709 if (np
->features
& FE_QUAD
)
711 else if (np
->features
& FE_DBLR
)
717 * Measure SCSI clock frequency for chips
718 * it may vary from assumed one.
720 if (np
->features
& FE_VARCLK
)
721 sym_getclock(np
, np
->multiplier
);
724 * Divisor to be used for async (timer pre-scaler).
726 i
= np
->clock_divn
- 1;
728 if (10ul * SYM_CONF_MIN_ASYNC
* np
->clock_khz
> div_10M
[i
]) {
736 * The C1010 uses hardwired divisors for async.
737 * So, we just throw away, the async. divisor.:-)
739 if (np
->features
& FE_C10
)
743 * Minimum synchronous period factor supported by the chip.
744 * Btw, 'period' is in tenths of nanoseconds.
746 period
= (4 * div_10M
[0] + np
->clock_khz
- 1) / np
->clock_khz
;
748 if (period
<= 250) np
->minsync
= 10;
749 else if (period
<= 303) np
->minsync
= 11;
750 else if (period
<= 500) np
->minsync
= 12;
751 else np
->minsync
= (period
+ 40 - 1) / 40;
754 * Check against chip SCSI standard support (SCSI-2,ULTRA,ULTRA2).
756 if (np
->minsync
< 25 &&
757 !(np
->features
& (FE_ULTRA
|FE_ULTRA2
|FE_ULTRA3
)))
759 else if (np
->minsync
< 12 &&
760 !(np
->features
& (FE_ULTRA2
|FE_ULTRA3
)))
764 * Maximum synchronous period factor supported by the chip.
766 period
= (11 * div_10M
[np
->clock_divn
- 1]) / (4 * np
->clock_khz
);
767 np
->maxsync
= period
> 2540 ? 254 : period
/ 10;
770 * If chip is a C1010, guess the sync limits in DT mode.
772 if ((np
->features
& (FE_C10
|FE_ULTRA3
)) == (FE_C10
|FE_ULTRA3
)) {
773 if (np
->clock_khz
== 160000) {
776 np
->maxoffs_dt
= nvram
->type
? 62 : 31;
781 * 64 bit addressing (895A/896/1010) ?
783 if (np
->features
& FE_DAC
) {
784 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
785 np
->rv_ccntl1
|= (DDAC
);
786 #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
788 np
->rv_ccntl1
|= (DDAC
);
790 np
->rv_ccntl1
|= (XTIMOD
| EXTIBMV
);
791 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
793 np
->rv_ccntl1
|= (DDAC
);
795 np
->rv_ccntl1
|= (0 | EXTIBMV
);
800 * Phase mismatch handled by SCRIPTS (895A/896/1010) ?
802 if (np
->features
& FE_NOPM
)
803 np
->rv_ccntl0
|= (ENPMJ
);
806 * C1010-33 Errata: Part Number:609-039638 (rev. 1) is fixed.
807 * In dual channel mode, contention occurs if internal cycles
808 * are used. Disable internal cycles.
810 if (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_33
&&
811 np
->revision_id
< 0x1)
812 np
->rv_ccntl0
|= DILS
;
815 * Select burst length (dwords)
817 burst_max
= SYM_SETUP_BURST_ORDER
;
818 if (burst_max
== 255)
819 burst_max
= burst_code(np
->sv_dmode
, np
->sv_ctest4
,
823 if (burst_max
> np
->maxburst
)
824 burst_max
= np
->maxburst
;
827 * DEL 352 - 53C810 Rev x11 - Part Number 609-0392140 - ITEM 2.
828 * This chip and the 860 Rev 1 may wrongly use PCI cache line
829 * based transactions on LOAD/STORE instructions. So we have
830 * to prevent these chips from using such PCI transactions in
831 * this driver. The generic ncr driver that does not use
832 * LOAD/STORE instructions does not need this work-around.
834 if ((np
->device_id
== PCI_DEVICE_ID_NCR_53C810
&&
835 np
->revision_id
>= 0x10 && np
->revision_id
<= 0x11) ||
836 (np
->device_id
== PCI_DEVICE_ID_NCR_53C860
&&
837 np
->revision_id
<= 0x1))
838 np
->features
&= ~(FE_WRIE
|FE_ERL
|FE_ERMP
);
841 * Select all supported special features.
842 * If we are using on-board RAM for scripts, prefetch (PFEN)
843 * does not help, but burst op fetch (BOF) does.
844 * Disabling PFEN makes sure BOF will be used.
846 if (np
->features
& FE_ERL
)
847 np
->rv_dmode
|= ERL
; /* Enable Read Line */
848 if (np
->features
& FE_BOF
)
849 np
->rv_dmode
|= BOF
; /* Burst Opcode Fetch */
850 if (np
->features
& FE_ERMP
)
851 np
->rv_dmode
|= ERMP
; /* Enable Read Multiple */
853 if ((np
->features
& FE_PFEN
) && !np
->ram_ba
)
855 if (np
->features
& FE_PFEN
)
857 np
->rv_dcntl
|= PFEN
; /* Prefetch Enable */
858 if (np
->features
& FE_CLSE
)
859 np
->rv_dcntl
|= CLSE
; /* Cache Line Size Enable */
860 if (np
->features
& FE_WRIE
)
861 np
->rv_ctest3
|= WRIE
; /* Write and Invalidate */
862 if (np
->features
& FE_DFS
)
863 np
->rv_ctest5
|= DFS
; /* Dma Fifo Size */
868 np
->rv_ctest4
|= MPEE
; /* Master parity checking */
869 np
->rv_scntl0
|= 0x0a; /* full arb., ena parity, par->ATN */
872 * Get parity checking, host ID and verbose mode from NVRAM
875 sym_nvram_setup_host(shost
, np
, nvram
);
878 * Get SCSI addr of host adapter (set by bios?).
880 if (np
->myaddr
== 255) {
881 np
->myaddr
= INB(np
, nc_scid
) & 0x07;
883 np
->myaddr
= SYM_SETUP_HOST_ID
;
887 * Prepare initial io register bits for burst length
889 sym_init_burst(np
, burst_max
);
893 * - LVD capable chips (895/895A/896/1010) report the
894 * current BUS mode through the STEST4 IO register.
895 * - For previous generation chips (825/825A/875),
896 * user has to tell us how to check against HVD,
897 * since a 100% safe algorithm is not possible.
899 np
->scsi_mode
= SMODE_SE
;
900 if (np
->features
& (FE_ULTRA2
|FE_ULTRA3
))
901 np
->scsi_mode
= (np
->sv_stest4
& SMODE
);
902 else if (np
->features
& FE_DIFF
) {
903 if (SYM_SETUP_SCSI_DIFF
== 1) {
905 if (np
->sv_stest2
& 0x20)
906 np
->scsi_mode
= SMODE_HVD
;
908 else if (nvram
->type
== SYM_SYMBIOS_NVRAM
) {
909 if (!(INB(np
, nc_gpreg
) & 0x08))
910 np
->scsi_mode
= SMODE_HVD
;
913 else if (SYM_SETUP_SCSI_DIFF
== 2)
914 np
->scsi_mode
= SMODE_HVD
;
916 if (np
->scsi_mode
== SMODE_HVD
)
917 np
->rv_stest2
|= 0x20;
920 * Set LED support from SCRIPTS.
921 * Ignore this feature for boards known to use a
922 * specific GPIO wiring and for the 895A, 896
923 * and 1010 that drive the LED directly.
925 if ((SYM_SETUP_SCSI_LED
||
926 (nvram
->type
== SYM_SYMBIOS_NVRAM
||
927 (nvram
->type
== SYM_TEKRAM_NVRAM
&&
928 np
->device_id
== PCI_DEVICE_ID_NCR_53C895
))) &&
929 !(np
->features
& FE_LEDC
) && !(np
->sv_gpcntl
& 0x01))
930 np
->features
|= FE_LED0
;
935 switch(SYM_SETUP_IRQ_MODE
& 3) {
937 np
->rv_dcntl
|= IRQM
;
940 np
->rv_dcntl
|= (np
->sv_dcntl
& IRQM
);
947 * Configure targets according to driver setup.
948 * If NVRAM present get targets setup from NVRAM.
950 for (i
= 0 ; i
< SYM_CONF_MAX_TARGET
; i
++) {
951 struct sym_tcb
*tp
= &np
->target
[i
];
953 tp
->usrflags
|= (SYM_DISC_ENABLED
| SYM_TAGS_ENABLED
);
954 tp
->usrtags
= SYM_SETUP_MAX_TAG
;
956 sym_nvram_setup_target(np
, i
, nvram
);
959 tp
->usrflags
&= ~SYM_TAGS_ENABLED
;
963 * Let user know about the settings.
965 printf("%s: %s, ID %d, Fast-%d, %s, %s\n", sym_name(np
),
966 sym_nvram_type(nvram
), np
->myaddr
,
967 (np
->features
& FE_ULTRA3
) ? 80 :
968 (np
->features
& FE_ULTRA2
) ? 40 :
969 (np
->features
& FE_ULTRA
) ? 20 : 10,
970 sym_scsi_bus_mode(np
->scsi_mode
),
971 (np
->rv_scntl0
& 0xa) ? "parity checking" : "NO parity");
973 * Tell him more on demand.
976 printf("%s: %s IRQ line driver%s\n",
978 np
->rv_dcntl
& IRQM
? "totem pole" : "open drain",
979 np
->ram_ba
? ", using on-chip SRAM" : "");
980 printf("%s: using %s firmware.\n", sym_name(np
), np
->fw_name
);
981 if (np
->features
& FE_NOPM
)
982 printf("%s: handling phase mismatch from SCRIPTS.\n",
988 if (sym_verbose
>= 2) {
989 printf ("%s: initial SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
990 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
991 sym_name(np
), np
->sv_scntl3
, np
->sv_dmode
, np
->sv_dcntl
,
992 np
->sv_ctest3
, np
->sv_ctest4
, np
->sv_ctest5
);
994 printf ("%s: final SCNTL3/DMODE/DCNTL/CTEST3/4/5 = "
995 "(hex) %02x/%02x/%02x/%02x/%02x/%02x\n",
996 sym_name(np
), np
->rv_scntl3
, np
->rv_dmode
, np
->rv_dcntl
,
997 np
->rv_ctest3
, np
->rv_ctest4
, np
->rv_ctest5
);
1000 * Let user be aware of targets that have some disable flags set.
1002 sym_print_targets_flag(np
, SYM_SCAN_BOOT_DISABLED
, "SCAN AT BOOT");
1004 sym_print_targets_flag(np
, SYM_SCAN_LUNS_DISABLED
,
1011 * Test the pci bus snoop logic :-(
1013 * Has to be called with interrupts disabled.
1015 #ifndef CONFIG_SCSI_SYM53C8XX_IOMAPPED
1016 static int sym_regtest (struct sym_hcb
*np
)
1018 register volatile u32 data
;
1020 * chip registers may NOT be cached.
1021 * write 0xffffffff to a read only register area,
1022 * and try to read it back.
1025 OUTL(np
, nc_dstat
, data
);
1026 data
= INL(np
, nc_dstat
);
1028 if (data
== 0xffffffff) {
1030 if ((data
& 0xe2f0fffd) != 0x02000080) {
1032 printf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
1040 static int sym_snooptest (struct sym_hcb
*np
)
1042 u32 sym_rd
, sym_wr
, sym_bk
, host_rd
, host_wr
, pc
, dstat
;
1044 #ifndef CONFIG_SCSI_SYM53C8XX_IOMAPPED
1045 err
|= sym_regtest (np
);
1046 if (err
) return (err
);
1050 * Enable Master Parity Checking as we intend
1051 * to enable it for normal operations.
1053 OUTB(np
, nc_ctest4
, (np
->rv_ctest4
& MPEE
));
1057 pc
= SCRIPTZ_BA(np
, snooptest
);
1061 * Set memory and register.
1063 np
->scratch
= cpu_to_scr(host_wr
);
1064 OUTL(np
, nc_temp
, sym_wr
);
1066 * Start script (exchange values)
1068 OUTL(np
, nc_dsa
, np
->hcb_ba
);
1071 * Wait 'til done (with timeout)
1073 for (i
=0; i
<SYM_SNOOP_TIMEOUT
; i
++)
1074 if (INB(np
, nc_istat
) & (INTF
|SIP
|DIP
))
1076 if (i
>=SYM_SNOOP_TIMEOUT
) {
1077 printf ("CACHE TEST FAILED: timeout.\n");
1081 * Check for fatal DMA errors.
1083 dstat
= INB(np
, nc_dstat
);
1084 #if 1 /* Band aiding for broken hardwares that fail PCI parity */
1085 if ((dstat
& MDPE
) && (np
->rv_ctest4
& MPEE
)) {
1086 printf ("%s: PCI DATA PARITY ERROR DETECTED - "
1087 "DISABLING MASTER DATA PARITY CHECKING.\n",
1089 np
->rv_ctest4
&= ~MPEE
;
1093 if (dstat
& (MDPE
|BF
|IID
)) {
1094 printf ("CACHE TEST FAILED: DMA error (dstat=0x%02x).", dstat
);
1098 * Save termination position.
1100 pc
= INL(np
, nc_dsp
);
1102 * Read memory and register.
1104 host_rd
= scr_to_cpu(np
->scratch
);
1105 sym_rd
= INL(np
, nc_scratcha
);
1106 sym_bk
= INL(np
, nc_temp
);
1108 * Check termination position.
1110 if (pc
!= SCRIPTZ_BA(np
, snoopend
)+8) {
1111 printf ("CACHE TEST FAILED: script execution failed.\n");
1112 printf ("start=%08lx, pc=%08lx, end=%08lx\n",
1113 (u_long
) SCRIPTZ_BA(np
, snooptest
), (u_long
) pc
,
1114 (u_long
) SCRIPTZ_BA(np
, snoopend
) +8);
1120 if (host_wr
!= sym_rd
) {
1121 printf ("CACHE TEST FAILED: host wrote %d, chip read %d.\n",
1122 (int) host_wr
, (int) sym_rd
);
1125 if (host_rd
!= sym_wr
) {
1126 printf ("CACHE TEST FAILED: chip wrote %d, host read %d.\n",
1127 (int) sym_wr
, (int) host_rd
);
1130 if (sym_bk
!= sym_wr
) {
1131 printf ("CACHE TEST FAILED: chip wrote %d, read back %d.\n",
1132 (int) sym_wr
, (int) sym_bk
);
1140 * log message for real hard errors
1142 * sym0 targ 0?: ERROR (ds:si) (so-si-sd) (sx/s3/s4) @ name (dsp:dbc).
1143 * reg: r0 r1 r2 r3 r4 r5 r6 ..... rf.
1145 * exception register:
1150 * so: control lines as driven by chip.
1151 * si: control lines as seen by chip.
1152 * sd: scsi data lines as seen by chip.
1155 * sx: sxfer (see the manual)
1156 * s3: scntl3 (see the manual)
1157 * s4: scntl4 (see the manual)
1159 * current script command:
1160 * dsp: script address (relative to start of script).
1161 * dbc: first word of script command.
1163 * First 24 register of the chip:
1166 static void sym_log_hard_error(struct sym_hcb
*np
, u_short sist
, u_char dstat
)
1172 u_char
*script_base
;
1175 dsp
= INL(np
, nc_dsp
);
1177 if (dsp
> np
->scripta_ba
&&
1178 dsp
<= np
->scripta_ba
+ np
->scripta_sz
) {
1179 script_ofs
= dsp
- np
->scripta_ba
;
1180 script_size
= np
->scripta_sz
;
1181 script_base
= (u_char
*) np
->scripta0
;
1182 script_name
= "scripta";
1184 else if (np
->scriptb_ba
< dsp
&&
1185 dsp
<= np
->scriptb_ba
+ np
->scriptb_sz
) {
1186 script_ofs
= dsp
- np
->scriptb_ba
;
1187 script_size
= np
->scriptb_sz
;
1188 script_base
= (u_char
*) np
->scriptb0
;
1189 script_name
= "scriptb";
1194 script_name
= "mem";
1197 printf ("%s:%d: ERROR (%x:%x) (%x-%x-%x) (%x/%x/%x) @ (%s %x:%08x).\n",
1198 sym_name(np
), (unsigned)INB(np
, nc_sdid
)&0x0f, dstat
, sist
,
1199 (unsigned)INB(np
, nc_socl
), (unsigned)INB(np
, nc_sbcl
),
1200 (unsigned)INB(np
, nc_sbdl
), (unsigned)INB(np
, nc_sxfer
),
1201 (unsigned)INB(np
, nc_scntl3
),
1202 (np
->features
& FE_C10
) ? (unsigned)INB(np
, nc_scntl4
) : 0,
1203 script_name
, script_ofs
, (unsigned)INL(np
, nc_dbc
));
1205 if (((script_ofs
& 3) == 0) &&
1206 (unsigned)script_ofs
< script_size
) {
1207 printf ("%s: script cmd = %08x\n", sym_name(np
),
1208 scr_to_cpu((int) *(u32
*)(script_base
+ script_ofs
)));
1211 printf ("%s: regdump:", sym_name(np
));
1213 printf (" %02x", (unsigned)INB_OFF(np
, i
));
1219 if (dstat
& (MDPE
|BF
))
1220 sym_log_bus_error(np
);
1223 static struct sym_chip sym_dev_table
[] = {
1224 {PCI_DEVICE_ID_NCR_53C810
, 0x0f, "810", 4, 8, 4, 64,
1227 #ifdef SYM_DEBUG_GENERIC_SUPPORT
1228 {PCI_DEVICE_ID_NCR_53C810
, 0xff, "810a", 4, 8, 4, 1,
1232 {PCI_DEVICE_ID_NCR_53C810
, 0xff, "810a", 4, 8, 4, 1,
1233 FE_CACHE_SET
|FE_LDSTR
|FE_PFEN
|FE_BOF
}
1236 {PCI_DEVICE_ID_NCR_53C815
, 0xff, "815", 4, 8, 4, 64,
1239 {PCI_DEVICE_ID_NCR_53C825
, 0x0f, "825", 6, 8, 4, 64,
1240 FE_WIDE
|FE_BOF
|FE_ERL
|FE_DIFF
}
1242 {PCI_DEVICE_ID_NCR_53C825
, 0xff, "825a", 6, 8, 4, 2,
1243 FE_WIDE
|FE_CACHE0_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|FE_RAM
|FE_DIFF
}
1245 {PCI_DEVICE_ID_NCR_53C860
, 0xff, "860", 4, 8, 5, 1,
1246 FE_ULTRA
|FE_CACHE_SET
|FE_BOF
|FE_LDSTR
|FE_PFEN
}
1248 {PCI_DEVICE_ID_NCR_53C875
, 0x01, "875", 6, 16, 5, 2,
1249 FE_WIDE
|FE_ULTRA
|FE_CACHE0_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1250 FE_RAM
|FE_DIFF
|FE_VARCLK
}
1252 {PCI_DEVICE_ID_NCR_53C875
, 0xff, "875", 6, 16, 5, 2,
1253 FE_WIDE
|FE_ULTRA
|FE_DBLR
|FE_CACHE0_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1254 FE_RAM
|FE_DIFF
|FE_VARCLK
}
1256 {PCI_DEVICE_ID_NCR_53C875J
, 0xff, "875J", 6, 16, 5, 2,
1257 FE_WIDE
|FE_ULTRA
|FE_DBLR
|FE_CACHE0_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1258 FE_RAM
|FE_DIFF
|FE_VARCLK
}
1260 {PCI_DEVICE_ID_NCR_53C885
, 0xff, "885", 6, 16, 5, 2,
1261 FE_WIDE
|FE_ULTRA
|FE_DBLR
|FE_CACHE0_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1262 FE_RAM
|FE_DIFF
|FE_VARCLK
}
1264 #ifdef SYM_DEBUG_GENERIC_SUPPORT
1265 {PCI_DEVICE_ID_NCR_53C895
, 0xff, "895", 6, 31, 7, 2,
1266 FE_WIDE
|FE_ULTRA2
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFS
|
1270 {PCI_DEVICE_ID_NCR_53C895
, 0xff, "895", 6, 31, 7, 2,
1271 FE_WIDE
|FE_ULTRA2
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1275 {PCI_DEVICE_ID_NCR_53C896
, 0xff, "896", 6, 31, 7, 4,
1276 FE_WIDE
|FE_ULTRA2
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1277 FE_RAM
|FE_RAM8K
|FE_64BIT
|FE_DAC
|FE_IO256
|FE_NOPM
|FE_LEDC
|FE_LCKFRQ
}
1279 {PCI_DEVICE_ID_LSI_53C895A
, 0xff, "895a", 6, 31, 7, 4,
1280 FE_WIDE
|FE_ULTRA2
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1281 FE_RAM
|FE_RAM8K
|FE_DAC
|FE_IO256
|FE_NOPM
|FE_LEDC
|FE_LCKFRQ
}
1283 {PCI_DEVICE_ID_LSI_53C875A
, 0xff, "875a", 6, 31, 7, 4,
1284 FE_WIDE
|FE_ULTRA
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1285 FE_RAM
|FE_DAC
|FE_IO256
|FE_NOPM
|FE_LEDC
|FE_LCKFRQ
}
1287 {PCI_DEVICE_ID_LSI_53C1010_33
, 0x00, "1010-33", 6, 31, 7, 8,
1288 FE_WIDE
|FE_ULTRA3
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFBC
|FE_LDSTR
|FE_PFEN
|
1289 FE_RAM
|FE_RAM8K
|FE_64BIT
|FE_DAC
|FE_IO256
|FE_NOPM
|FE_LEDC
|FE_CRC
|
1292 {PCI_DEVICE_ID_LSI_53C1010_33
, 0xff, "1010-33", 6, 31, 7, 8,
1293 FE_WIDE
|FE_ULTRA3
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFBC
|FE_LDSTR
|FE_PFEN
|
1294 FE_RAM
|FE_RAM8K
|FE_64BIT
|FE_DAC
|FE_IO256
|FE_NOPM
|FE_LEDC
|FE_CRC
|
1297 {PCI_DEVICE_ID_LSI_53C1010_66
, 0xff, "1010-66", 6, 31, 7, 8,
1298 FE_WIDE
|FE_ULTRA3
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFBC
|FE_LDSTR
|FE_PFEN
|
1299 FE_RAM
|FE_RAM8K
|FE_64BIT
|FE_DAC
|FE_IO256
|FE_NOPM
|FE_LEDC
|FE_66MHZ
|FE_CRC
|
1302 {PCI_DEVICE_ID_LSI_53C1510
, 0xff, "1510d", 6, 31, 7, 4,
1303 FE_WIDE
|FE_ULTRA2
|FE_QUAD
|FE_CACHE_SET
|FE_BOF
|FE_DFS
|FE_LDSTR
|FE_PFEN
|
1304 FE_RAM
|FE_IO256
|FE_LEDC
}
1307 #define sym_num_devs \
1308 (sizeof(sym_dev_table) / sizeof(sym_dev_table[0]))
1311 * Look up the chip table.
1313 * Return a pointer to the chip entry if found,
1317 sym_lookup_chip_table (u_short device_id
, u_char revision
)
1319 struct sym_chip
*chip
;
1322 for (i
= 0; i
< sym_num_devs
; i
++) {
1323 chip
= &sym_dev_table
[i
];
1324 if (device_id
!= chip
->device_id
)
1326 if (revision
> chip
->revision_id
)
1334 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1336 * Lookup the 64 bit DMA segments map.
1337 * This is only used if the direct mapping
1338 * has been unsuccessful.
1340 int sym_lookup_dmap(struct sym_hcb
*np
, u32 h
, int s
)
1347 /* Look up existing mappings */
1348 for (i
= SYM_DMAP_SIZE
-1; i
> 0; i
--) {
1349 if (h
== np
->dmap_bah
[i
])
1352 /* If direct mapping is free, get it */
1353 if (!np
->dmap_bah
[s
])
1355 /* Collision -> lookup free mappings */
1356 for (s
= SYM_DMAP_SIZE
-1; s
> 0; s
--) {
1357 if (!np
->dmap_bah
[s
])
1361 panic("sym: ran out of 64 bit DMA segment registers");
1364 np
->dmap_bah
[s
] = h
;
1370 * Update IO registers scratch C..R so they will be
1371 * in sync. with queued CCB expectations.
1373 static void sym_update_dmap_regs(struct sym_hcb
*np
)
1377 if (!np
->dmap_dirty
)
1379 o
= offsetof(struct sym_reg
, nc_scrx
[0]);
1380 for (i
= 0; i
< SYM_DMAP_SIZE
; i
++) {
1381 OUTL_OFF(np
, o
, np
->dmap_bah
[i
]);
1388 /* Enforce all the fiddly SPI rules and the chip limitations */
1389 static void sym_check_goals(struct sym_hcb
*np
, struct scsi_target
*starget
,
1390 struct sym_trans
*goal
)
1392 if (!spi_support_wide(starget
))
1395 if (!spi_support_sync(starget
)) {
1404 if (spi_support_dt(starget
)) {
1405 if (spi_support_dt_only(starget
))
1408 if (goal
->offset
== 0)
1414 /* Some targets fail to properly negotiate DT in SE mode */
1415 if ((np
->scsi_mode
!= SMODE_LVD
) || !(np
->features
& FE_U3EN
))
1419 /* all DT transfers must be wide */
1421 if (goal
->offset
> np
->maxoffs_dt
)
1422 goal
->offset
= np
->maxoffs_dt
;
1423 if (goal
->period
< np
->minsync_dt
)
1424 goal
->period
= np
->minsync_dt
;
1425 if (goal
->period
> np
->maxsync_dt
)
1426 goal
->period
= np
->maxsync_dt
;
1428 goal
->iu
= goal
->qas
= 0;
1429 if (goal
->offset
> np
->maxoffs
)
1430 goal
->offset
= np
->maxoffs
;
1431 if (goal
->period
< np
->minsync
)
1432 goal
->period
= np
->minsync
;
1433 if (goal
->period
> np
->maxsync
)
1434 goal
->period
= np
->maxsync
;
1439 * Prepare the next negotiation message if needed.
1441 * Fill in the part of message buffer that contains the
1442 * negotiation and the nego_status field of the CCB.
1443 * Returns the size of the message in bytes.
1445 static int sym_prepare_nego(struct sym_hcb
*np
, struct sym_ccb
*cp
, u_char
*msgptr
)
1447 struct sym_tcb
*tp
= &np
->target
[cp
->target
];
1448 struct scsi_target
*starget
= tp
->sdev
->sdev_target
;
1449 struct sym_trans
*goal
= &tp
->tgoal
;
1453 sym_check_goals(np
, starget
, goal
);
1456 * Many devices implement PPR in a buggy way, so only use it if we
1459 if (goal
->iu
|| goal
->dt
|| goal
->qas
|| (goal
->period
< 0xa)) {
1461 } else if (spi_width(starget
) != goal
->width
) {
1463 } else if (spi_period(starget
) != goal
->period
||
1464 spi_offset(starget
) != goal
->offset
) {
1467 goal
->check_nego
= 0;
1473 msgptr
[msglen
++] = M_EXTENDED
;
1474 msgptr
[msglen
++] = 3;
1475 msgptr
[msglen
++] = M_X_SYNC_REQ
;
1476 msgptr
[msglen
++] = goal
->period
;
1477 msgptr
[msglen
++] = goal
->offset
;
1480 msgptr
[msglen
++] = M_EXTENDED
;
1481 msgptr
[msglen
++] = 2;
1482 msgptr
[msglen
++] = M_X_WIDE_REQ
;
1483 msgptr
[msglen
++] = goal
->width
;
1486 msgptr
[msglen
++] = M_EXTENDED
;
1487 msgptr
[msglen
++] = 6;
1488 msgptr
[msglen
++] = M_X_PPR_REQ
;
1489 msgptr
[msglen
++] = goal
->period
;
1490 msgptr
[msglen
++] = 0;
1491 msgptr
[msglen
++] = goal
->offset
;
1492 msgptr
[msglen
++] = goal
->width
;
1493 msgptr
[msglen
++] = (goal
->iu
? PPR_OPT_IU
: 0) |
1494 (goal
->dt
? PPR_OPT_DT
: 0) |
1495 (goal
->qas
? PPR_OPT_QAS
: 0);
1499 cp
->nego_status
= nego
;
1502 tp
->nego_cp
= cp
; /* Keep track a nego will be performed */
1503 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
1504 sym_print_nego_msg(np
, cp
->target
,
1505 nego
== NS_SYNC
? "sync msgout" :
1506 nego
== NS_WIDE
? "wide msgout" :
1507 "ppr msgout", msgptr
);
1515 * Insert a job into the start queue.
1517 void sym_put_start_queue(struct sym_hcb
*np
, struct sym_ccb
*cp
)
1521 #ifdef SYM_CONF_IARB_SUPPORT
1523 * If the previously queued CCB is not yet done,
1524 * set the IARB hint. The SCRIPTS will go with IARB
1525 * for this job when starting the previous one.
1526 * We leave devices a chance to win arbitration by
1527 * not using more than 'iarb_max' consecutive
1528 * immediate arbitrations.
1530 if (np
->last_cp
&& np
->iarb_count
< np
->iarb_max
) {
1531 np
->last_cp
->host_flags
|= HF_HINT_IARB
;
1539 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1541 * Make SCRIPTS aware of the 64 bit DMA
1542 * segment registers not being up-to-date.
1545 cp
->host_xflags
|= HX_DMAP_DIRTY
;
1549 * Insert first the idle task and then our job.
1550 * The MBs should ensure proper ordering.
1552 qidx
= np
->squeueput
+ 2;
1553 if (qidx
>= MAX_QUEUE
*2) qidx
= 0;
1555 np
->squeue
[qidx
] = cpu_to_scr(np
->idletask_ba
);
1556 MEMORY_WRITE_BARRIER();
1557 np
->squeue
[np
->squeueput
] = cpu_to_scr(cp
->ccb_ba
);
1559 np
->squeueput
= qidx
;
1561 if (DEBUG_FLAGS
& DEBUG_QUEUE
)
1562 printf ("%s: queuepos=%d.\n", sym_name (np
), np
->squeueput
);
1565 * Script processor may be waiting for reselect.
1568 MEMORY_WRITE_BARRIER();
1569 OUTB(np
, nc_istat
, SIGP
|np
->istat_sem
);
1572 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1574 * Start next ready-to-start CCBs.
1576 void sym_start_next_ccbs(struct sym_hcb
*np
, struct sym_lcb
*lp
, int maxn
)
1582 * Paranoia, as usual. :-)
1584 assert(!lp
->started_tags
|| !lp
->started_no_tag
);
1587 * Try to start as many commands as asked by caller.
1588 * Prevent from having both tagged and untagged
1589 * commands queued to the device at the same time.
1592 qp
= sym_remque_head(&lp
->waiting_ccbq
);
1595 cp
= sym_que_entry(qp
, struct sym_ccb
, link2_ccbq
);
1596 if (cp
->tag
!= NO_TAG
) {
1597 if (lp
->started_no_tag
||
1598 lp
->started_tags
>= lp
->started_max
) {
1599 sym_insque_head(qp
, &lp
->waiting_ccbq
);
1602 lp
->itlq_tbl
[cp
->tag
] = cpu_to_scr(cp
->ccb_ba
);
1604 cpu_to_scr(SCRIPTA_BA(np
, resel_tag
));
1607 if (lp
->started_no_tag
|| lp
->started_tags
) {
1608 sym_insque_head(qp
, &lp
->waiting_ccbq
);
1611 lp
->head
.itl_task_sa
= cpu_to_scr(cp
->ccb_ba
);
1613 cpu_to_scr(SCRIPTA_BA(np
, resel_no_tag
));
1614 ++lp
->started_no_tag
;
1617 sym_insque_tail(qp
, &lp
->started_ccbq
);
1618 sym_put_start_queue(np
, cp
);
1621 #endif /* SYM_OPT_HANDLE_DEVICE_QUEUEING */
1624 * The chip may have completed jobs. Look at the DONE QUEUE.
1626 * On paper, memory read barriers may be needed here to
1627 * prevent out of order LOADs by the CPU from having
1628 * prefetched stale data prior to DMA having occurred.
1630 static int sym_wakeup_done (struct sym_hcb
*np
)
1639 /* MEMORY_READ_BARRIER(); */
1641 dsa
= scr_to_cpu(np
->dqueue
[i
]);
1645 if ((i
= i
+2) >= MAX_QUEUE
*2)
1648 cp
= sym_ccb_from_dsa(np
, dsa
);
1650 MEMORY_READ_BARRIER();
1651 sym_complete_ok (np
, cp
);
1655 printf ("%s: bad DSA (%x) in done queue.\n",
1656 sym_name(np
), (u_int
) dsa
);
1664 * Complete all CCBs queued to the COMP queue.
1666 * These CCBs are assumed:
1667 * - Not to be referenced either by devices or
1668 * SCRIPTS-related queues and datas.
1669 * - To have to be completed with an error condition
1672 * The device queue freeze count is incremented
1673 * for each CCB that does not prevent this.
1674 * This function is called when all CCBs involved
1675 * in error handling/recovery have been reaped.
1677 static void sym_flush_comp_queue(struct sym_hcb
*np
, int cam_status
)
1682 while ((qp
= sym_remque_head(&np
->comp_ccbq
)) != 0) {
1683 struct scsi_cmnd
*cmd
;
1684 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
1685 sym_insque_tail(&cp
->link_ccbq
, &np
->busy_ccbq
);
1686 /* Leave quiet CCBs waiting for resources */
1687 if (cp
->host_status
== HS_WAIT
)
1691 sym_set_cam_status(cmd
, cam_status
);
1692 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1693 if (sym_get_cam_status(cmd
) == CAM_REQUEUE_REQ
) {
1694 struct sym_tcb
*tp
= &np
->target
[cp
->target
];
1695 struct sym_lcb
*lp
= sym_lp(tp
, cp
->lun
);
1697 sym_remque(&cp
->link2_ccbq
);
1698 sym_insque_tail(&cp
->link2_ccbq
,
1701 if (cp
->tag
!= NO_TAG
)
1704 --lp
->started_no_tag
;
1711 sym_free_ccb(np
, cp
);
1712 sym_xpt_done(np
, cmd
);
1717 * Complete all active CCBs with error.
1718 * Used on CHIP/SCSI RESET.
1720 static void sym_flush_busy_queue (struct sym_hcb
*np
, int cam_status
)
1723 * Move all active CCBs to the COMP queue
1724 * and flush this queue.
1726 sym_que_splice(&np
->busy_ccbq
, &np
->comp_ccbq
);
1727 sym_que_init(&np
->busy_ccbq
);
1728 sym_flush_comp_queue(np
, cam_status
);
1735 * 0: initialisation.
1736 * 1: SCSI BUS RESET delivered or received.
1737 * 2: SCSI BUS MODE changed.
1739 void sym_start_up (struct sym_hcb
*np
, int reason
)
1745 * Reset chip if asked, otherwise just clear fifos.
1750 OUTB(np
, nc_stest3
, TE
|CSF
);
1751 OUTONB(np
, nc_ctest3
, CLF
);
1757 phys
= np
->squeue_ba
;
1758 for (i
= 0; i
< MAX_QUEUE
*2; i
+= 2) {
1759 np
->squeue
[i
] = cpu_to_scr(np
->idletask_ba
);
1760 np
->squeue
[i
+1] = cpu_to_scr(phys
+ (i
+2)*4);
1762 np
->squeue
[MAX_QUEUE
*2-1] = cpu_to_scr(phys
);
1765 * Start at first entry.
1772 phys
= np
->dqueue_ba
;
1773 for (i
= 0; i
< MAX_QUEUE
*2; i
+= 2) {
1775 np
->dqueue
[i
+1] = cpu_to_scr(phys
+ (i
+2)*4);
1777 np
->dqueue
[MAX_QUEUE
*2-1] = cpu_to_scr(phys
);
1780 * Start at first entry.
1785 * Install patches in scripts.
1786 * This also let point to first position the start
1787 * and done queue pointers used from SCRIPTS.
1792 * Wakeup all pending jobs.
1794 sym_flush_busy_queue(np
, CAM_SCSI_BUS_RESET
);
1799 OUTB(np
, nc_istat
, 0x00); /* Remove Reset, abort */
1800 udelay(2000); /* The 895 needs time for the bus mode to settle */
1802 OUTB(np
, nc_scntl0
, np
->rv_scntl0
| 0xc0);
1803 /* full arb., ena parity, par->ATN */
1804 OUTB(np
, nc_scntl1
, 0x00); /* odd parity, and remove CRST!! */
1806 sym_selectclock(np
, np
->rv_scntl3
); /* Select SCSI clock */
1808 OUTB(np
, nc_scid
, RRE
|np
->myaddr
); /* Adapter SCSI address */
1809 OUTW(np
, nc_respid
, 1ul<<np
->myaddr
); /* Id to respond to */
1810 OUTB(np
, nc_istat
, SIGP
); /* Signal Process */
1811 OUTB(np
, nc_dmode
, np
->rv_dmode
); /* Burst length, dma mode */
1812 OUTB(np
, nc_ctest5
, np
->rv_ctest5
); /* Large fifo + large burst */
1814 OUTB(np
, nc_dcntl
, NOCOM
|np
->rv_dcntl
); /* Protect SFBR */
1815 OUTB(np
, nc_ctest3
, np
->rv_ctest3
); /* Write and invalidate */
1816 OUTB(np
, nc_ctest4
, np
->rv_ctest4
); /* Master parity checking */
1818 /* Extended Sreq/Sack filtering not supported on the C10 */
1819 if (np
->features
& FE_C10
)
1820 OUTB(np
, nc_stest2
, np
->rv_stest2
);
1822 OUTB(np
, nc_stest2
, EXT
|np
->rv_stest2
);
1824 OUTB(np
, nc_stest3
, TE
); /* TolerANT enable */
1825 OUTB(np
, nc_stime0
, 0x0c); /* HTH disabled STO 0.25 sec */
1828 * For now, disable AIP generation on C1010-66.
1830 if (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_66
)
1831 OUTB(np
, nc_aipcntl1
, DISAIP
);
1834 * C10101 rev. 0 errata.
1835 * Errant SGE's when in narrow. Write bits 4 & 5 of
1836 * STEST1 register to disable SGE. We probably should do
1837 * that from SCRIPTS for each selection/reselection, but
1838 * I just don't want. :)
1840 if (np
->device_id
== PCI_DEVICE_ID_LSI_53C1010_33
&&
1841 np
->revision_id
< 1)
1842 OUTB(np
, nc_stest1
, INB(np
, nc_stest1
) | 0x30);
1845 * DEL 441 - 53C876 Rev 5 - Part Number 609-0392787/2788 - ITEM 2.
1846 * Disable overlapped arbitration for some dual function devices,
1847 * regardless revision id (kind of post-chip-design feature. ;-))
1849 if (np
->device_id
== PCI_DEVICE_ID_NCR_53C875
)
1850 OUTB(np
, nc_ctest0
, (1<<5));
1851 else if (np
->device_id
== PCI_DEVICE_ID_NCR_53C896
)
1852 np
->rv_ccntl0
|= DPR
;
1855 * Write CCNTL0/CCNTL1 for chips capable of 64 bit addressing
1856 * and/or hardware phase mismatch, since only such chips
1857 * seem to support those IO registers.
1859 if (np
->features
& (FE_DAC
|FE_NOPM
)) {
1860 OUTB(np
, nc_ccntl0
, np
->rv_ccntl0
);
1861 OUTB(np
, nc_ccntl1
, np
->rv_ccntl1
);
1864 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1866 * Set up scratch C and DRS IO registers to map the 32 bit
1867 * DMA address range our data structures are located in.
1870 np
->dmap_bah
[0] = 0; /* ??? */
1871 OUTL(np
, nc_scrx
[0], np
->dmap_bah
[0]);
1872 OUTL(np
, nc_drs
, np
->dmap_bah
[0]);
1877 * If phase mismatch handled by scripts (895A/896/1010),
1878 * set PM jump addresses.
1880 if (np
->features
& FE_NOPM
) {
1881 OUTL(np
, nc_pmjad1
, SCRIPTB_BA(np
, pm_handle
));
1882 OUTL(np
, nc_pmjad2
, SCRIPTB_BA(np
, pm_handle
));
1886 * Enable GPIO0 pin for writing if LED support from SCRIPTS.
1887 * Also set GPIO5 and clear GPIO6 if hardware LED control.
1889 if (np
->features
& FE_LED0
)
1890 OUTB(np
, nc_gpcntl
, INB(np
, nc_gpcntl
) & ~0x01);
1891 else if (np
->features
& FE_LEDC
)
1892 OUTB(np
, nc_gpcntl
, (INB(np
, nc_gpcntl
) & ~0x41) | 0x20);
1897 OUTW(np
, nc_sien
, STO
|HTH
|MA
|SGE
|UDC
|RST
|PAR
);
1898 OUTB(np
, nc_dien
, MDPE
|BF
|SSI
|SIR
|IID
);
1901 * For 895/6 enable SBMC interrupt and save current SCSI bus mode.
1902 * Try to eat the spurious SBMC interrupt that may occur when
1903 * we reset the chip but not the SCSI BUS (at initialization).
1905 if (np
->features
& (FE_ULTRA2
|FE_ULTRA3
)) {
1906 OUTONW(np
, nc_sien
, SBMC
);
1911 np
->scsi_mode
= INB(np
, nc_stest4
) & SMODE
;
1915 * Fill in target structure.
1916 * Reinitialize usrsync.
1917 * Reinitialize usrwide.
1918 * Prepare sync negotiation according to actual SCSI bus mode.
1920 for (i
=0;i
<SYM_CONF_MAX_TARGET
;i
++) {
1921 struct sym_tcb
*tp
= &np
->target
[i
];
1925 tp
->head
.wval
= np
->rv_scntl3
;
1930 * Download SCSI SCRIPTS to on-chip RAM if present,
1931 * and start script processor.
1932 * We do the download preferently from the CPU.
1933 * For platforms that may not support PCI memory mapping,
1934 * we use simple SCRIPTS that performs MEMORY MOVEs.
1936 phys
= SCRIPTA_BA(np
, init
);
1938 if (sym_verbose
>= 2)
1939 printf("%s: Downloading SCSI SCRIPTS.\n", sym_name(np
));
1940 memcpy_toio(np
->s
.ramaddr
, np
->scripta0
, np
->scripta_sz
);
1941 if (np
->ram_ws
== 8192) {
1942 memcpy_toio(np
->s
.ramaddr
+ 4096, np
->scriptb0
, np
->scriptb_sz
);
1943 phys
= scr_to_cpu(np
->scr_ram_seg
);
1944 OUTL(np
, nc_mmws
, phys
);
1945 OUTL(np
, nc_mmrs
, phys
);
1946 OUTL(np
, nc_sfs
, phys
);
1947 phys
= SCRIPTB_BA(np
, start64
);
1953 OUTL(np
, nc_dsa
, np
->hcb_ba
);
1957 * Notify the XPT about the RESET condition.
1960 sym_xpt_async_bus_reset(np
);
1964 * Switch trans mode for current job and its target.
1966 static void sym_settrans(struct sym_hcb
*np
, int target
, u_char opts
, u_char ofs
,
1967 u_char per
, u_char wide
, u_char div
, u_char fak
)
1970 u_char sval
, wval
, uval
;
1971 struct sym_tcb
*tp
= &np
->target
[target
];
1973 assert(target
== (INB(np
, nc_sdid
) & 0x0f));
1975 sval
= tp
->head
.sval
;
1976 wval
= tp
->head
.wval
;
1977 uval
= tp
->head
.uval
;
1980 printf("XXXX sval=%x wval=%x uval=%x (%x)\n",
1981 sval
, wval
, uval
, np
->rv_scntl3
);
1986 if (!(np
->features
& FE_C10
))
1987 sval
= (sval
& ~0x1f) | ofs
;
1989 sval
= (sval
& ~0x3f) | ofs
;
1992 * Set the sync divisor and extra clock factor.
1995 wval
= (wval
& ~0x70) | ((div
+1) << 4);
1996 if (!(np
->features
& FE_C10
))
1997 sval
= (sval
& ~0xe0) | (fak
<< 5);
1999 uval
= uval
& ~(XCLKH_ST
|XCLKH_DT
|XCLKS_ST
|XCLKS_DT
);
2000 if (fak
>= 1) uval
|= (XCLKH_ST
|XCLKH_DT
);
2001 if (fak
>= 2) uval
|= (XCLKS_ST
|XCLKS_DT
);
2006 * Set the bus width.
2013 * Set misc. ultra enable bits.
2015 if (np
->features
& FE_C10
) {
2016 uval
= uval
& ~(U3EN
|AIPCKEN
);
2018 assert(np
->features
& FE_U3EN
);
2022 wval
= wval
& ~ULTRA
;
2023 if (per
<= 12) wval
|= ULTRA
;
2027 * Stop there if sync parameters are unchanged.
2029 if (tp
->head
.sval
== sval
&&
2030 tp
->head
.wval
== wval
&&
2031 tp
->head
.uval
== uval
)
2033 tp
->head
.sval
= sval
;
2034 tp
->head
.wval
= wval
;
2035 tp
->head
.uval
= uval
;
2038 * Disable extended Sreq/Sack filtering if per < 50.
2039 * Not supported on the C1010.
2041 if (per
< 50 && !(np
->features
& FE_C10
))
2042 OUTOFFB(np
, nc_stest2
, EXT
);
2045 * set actual value and sync_status
2047 OUTB(np
, nc_sxfer
, tp
->head
.sval
);
2048 OUTB(np
, nc_scntl3
, tp
->head
.wval
);
2050 if (np
->features
& FE_C10
) {
2051 OUTB(np
, nc_scntl4
, tp
->head
.uval
);
2055 * patch ALL busy ccbs of this target.
2057 FOR_EACH_QUEUED_ELEMENT(&np
->busy_ccbq
, qp
) {
2059 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
2060 if (cp
->target
!= target
)
2062 cp
->phys
.select
.sel_scntl3
= tp
->head
.wval
;
2063 cp
->phys
.select
.sel_sxfer
= tp
->head
.sval
;
2064 if (np
->features
& FE_C10
) {
2065 cp
->phys
.select
.sel_scntl4
= tp
->head
.uval
;
2071 * We received a WDTR.
2072 * Let everything be aware of the changes.
2074 static void sym_setwide(struct sym_hcb
*np
, int target
, u_char wide
)
2076 struct sym_tcb
*tp
= &np
->target
[target
];
2077 struct scsi_target
*starget
= tp
->sdev
->sdev_target
;
2079 if (spi_width(starget
) == wide
)
2082 sym_settrans(np
, target
, 0, 0, 0, wide
, 0, 0);
2084 tp
->tgoal
.width
= wide
;
2085 spi_offset(starget
) = 0;
2086 spi_period(starget
) = 0;
2087 spi_width(starget
) = wide
;
2088 spi_iu(starget
) = 0;
2089 spi_dt(starget
) = 0;
2090 spi_qas(starget
) = 0;
2092 if (sym_verbose
>= 3)
2093 spi_display_xfer_agreement(starget
);
2097 * We received a SDTR.
2098 * Let everything be aware of the changes.
2101 sym_setsync(struct sym_hcb
*np
, int target
,
2102 u_char ofs
, u_char per
, u_char div
, u_char fak
)
2104 struct sym_tcb
*tp
= &np
->target
[target
];
2105 struct scsi_target
*starget
= tp
->sdev
->sdev_target
;
2106 u_char wide
= (tp
->head
.wval
& EWS
) ? BUS_16_BIT
: BUS_8_BIT
;
2108 sym_settrans(np
, target
, 0, ofs
, per
, wide
, div
, fak
);
2110 spi_period(starget
) = per
;
2111 spi_offset(starget
) = ofs
;
2112 spi_iu(starget
) = spi_dt(starget
) = spi_qas(starget
) = 0;
2114 if (!tp
->tgoal
.dt
&& !tp
->tgoal
.iu
&& !tp
->tgoal
.qas
) {
2115 tp
->tgoal
.period
= per
;
2116 tp
->tgoal
.offset
= ofs
;
2117 tp
->tgoal
.check_nego
= 0;
2120 spi_display_xfer_agreement(starget
);
2124 * We received a PPR.
2125 * Let everything be aware of the changes.
2128 sym_setpprot(struct sym_hcb
*np
, int target
, u_char opts
, u_char ofs
,
2129 u_char per
, u_char wide
, u_char div
, u_char fak
)
2131 struct sym_tcb
*tp
= &np
->target
[target
];
2132 struct scsi_target
*starget
= tp
->sdev
->sdev_target
;
2134 sym_settrans(np
, target
, opts
, ofs
, per
, wide
, div
, fak
);
2136 spi_width(starget
) = tp
->tgoal
.width
= wide
;
2137 spi_period(starget
) = tp
->tgoal
.period
= per
;
2138 spi_offset(starget
) = tp
->tgoal
.offset
= ofs
;
2139 spi_iu(starget
) = tp
->tgoal
.iu
= !!(opts
& PPR_OPT_IU
);
2140 spi_dt(starget
) = tp
->tgoal
.dt
= !!(opts
& PPR_OPT_DT
);
2141 spi_qas(starget
) = tp
->tgoal
.qas
= !!(opts
& PPR_OPT_QAS
);
2142 tp
->tgoal
.check_nego
= 0;
2144 spi_display_xfer_agreement(starget
);
2148 * generic recovery from scsi interrupt
2150 * The doc says that when the chip gets an SCSI interrupt,
2151 * it tries to stop in an orderly fashion, by completing
2152 * an instruction fetch that had started or by flushing
2153 * the DMA fifo for a write to memory that was executing.
2154 * Such a fashion is not enough to know if the instruction
2155 * that was just before the current DSP value has been
2158 * There are some small SCRIPTS sections that deal with
2159 * the start queue and the done queue that may break any
2160 * assomption from the C code if we are interrupted
2161 * inside, so we reset if this happens. Btw, since these
2162 * SCRIPTS sections are executed while the SCRIPTS hasn't
2163 * started SCSI operations, it is very unlikely to happen.
2165 * All the driver data structures are supposed to be
2166 * allocated from the same 4 GB memory window, so there
2167 * is a 1 to 1 relationship between DSA and driver data
2168 * structures. Since we are careful :) to invalidate the
2169 * DSA when we complete a command or when the SCRIPTS
2170 * pushes a DSA into a queue, we can trust it when it
2173 static void sym_recover_scsi_int (struct sym_hcb
*np
, u_char hsts
)
2175 u32 dsp
= INL(np
, nc_dsp
);
2176 u32 dsa
= INL(np
, nc_dsa
);
2177 struct sym_ccb
*cp
= sym_ccb_from_dsa(np
, dsa
);
2180 * If we haven't been interrupted inside the SCRIPTS
2181 * critical pathes, we can safely restart the SCRIPTS
2182 * and trust the DSA value if it matches a CCB.
2184 if ((!(dsp
> SCRIPTA_BA(np
, getjob_begin
) &&
2185 dsp
< SCRIPTA_BA(np
, getjob_end
) + 1)) &&
2186 (!(dsp
> SCRIPTA_BA(np
, ungetjob
) &&
2187 dsp
< SCRIPTA_BA(np
, reselect
) + 1)) &&
2188 (!(dsp
> SCRIPTB_BA(np
, sel_for_abort
) &&
2189 dsp
< SCRIPTB_BA(np
, sel_for_abort_1
) + 1)) &&
2190 (!(dsp
> SCRIPTA_BA(np
, done
) &&
2191 dsp
< SCRIPTA_BA(np
, done_end
) + 1))) {
2192 OUTB(np
, nc_ctest3
, np
->rv_ctest3
| CLF
); /* clear dma fifo */
2193 OUTB(np
, nc_stest3
, TE
|CSF
); /* clear scsi fifo */
2195 * If we have a CCB, let the SCRIPTS call us back for
2196 * the handling of the error with SCRATCHA filled with
2197 * STARTPOS. This way, we will be able to freeze the
2198 * device queue and requeue awaiting IOs.
2201 cp
->host_status
= hsts
;
2202 OUTL_DSP(np
, SCRIPTA_BA(np
, complete_error
));
2205 * Otherwise just restart the SCRIPTS.
2208 OUTL(np
, nc_dsa
, 0xffffff);
2209 OUTL_DSP(np
, SCRIPTA_BA(np
, start
));
2218 sym_start_reset(np
);
2222 * chip exception handler for selection timeout
2224 static void sym_int_sto (struct sym_hcb
*np
)
2226 u32 dsp
= INL(np
, nc_dsp
);
2228 if (DEBUG_FLAGS
& DEBUG_TINY
) printf ("T");
2230 if (dsp
== SCRIPTA_BA(np
, wf_sel_done
) + 8)
2231 sym_recover_scsi_int(np
, HS_SEL_TIMEOUT
);
2233 sym_start_reset(np
);
2237 * chip exception handler for unexpected disconnect
2239 static void sym_int_udc (struct sym_hcb
*np
)
2241 printf ("%s: unexpected disconnect\n", sym_name(np
));
2242 sym_recover_scsi_int(np
, HS_UNEXPECTED
);
2246 * chip exception handler for SCSI bus mode change
2248 * spi2-r12 11.2.3 says a transceiver mode change must
2249 * generate a reset event and a device that detects a reset
2250 * event shall initiate a hard reset. It says also that a
2251 * device that detects a mode change shall set data transfer
2252 * mode to eight bit asynchronous, etc...
2253 * So, just reinitializing all except chip should be enough.
2255 static void sym_int_sbmc (struct sym_hcb
*np
)
2257 u_char scsi_mode
= INB(np
, nc_stest4
) & SMODE
;
2262 printf("%s: SCSI BUS mode change from %s to %s.\n", sym_name(np
),
2263 sym_scsi_bus_mode(np
->scsi_mode
), sym_scsi_bus_mode(scsi_mode
));
2266 * Should suspend command processing for a few seconds and
2267 * reinitialize all except the chip.
2269 sym_start_up (np
, 2);
2273 * chip exception handler for SCSI parity error.
2275 * When the chip detects a SCSI parity error and is
2276 * currently executing a (CH)MOV instruction, it does
2277 * not interrupt immediately, but tries to finish the
2278 * transfer of the current scatter entry before
2279 * interrupting. The following situations may occur:
2281 * - The complete scatter entry has been transferred
2282 * without the device having changed phase.
2283 * The chip will then interrupt with the DSP pointing
2284 * to the instruction that follows the MOV.
2286 * - A phase mismatch occurs before the MOV finished
2287 * and phase errors are to be handled by the C code.
2288 * The chip will then interrupt with both PAR and MA
2291 * - A phase mismatch occurs before the MOV finished and
2292 * phase errors are to be handled by SCRIPTS.
2293 * The chip will load the DSP with the phase mismatch
2294 * JUMP address and interrupt the host processor.
2296 static void sym_int_par (struct sym_hcb
*np
, u_short sist
)
2298 u_char hsts
= INB(np
, HS_PRT
);
2299 u32 dsp
= INL(np
, nc_dsp
);
2300 u32 dbc
= INL(np
, nc_dbc
);
2301 u32 dsa
= INL(np
, nc_dsa
);
2302 u_char sbcl
= INB(np
, nc_sbcl
);
2303 u_char cmd
= dbc
>> 24;
2304 int phase
= cmd
& 7;
2305 struct sym_ccb
*cp
= sym_ccb_from_dsa(np
, dsa
);
2307 printf("%s: SCSI parity error detected: SCR1=%d DBC=%x SBCL=%x\n",
2308 sym_name(np
), hsts
, dbc
, sbcl
);
2311 * Check that the chip is connected to the SCSI BUS.
2313 if (!(INB(np
, nc_scntl1
) & ISCON
)) {
2314 sym_recover_scsi_int(np
, HS_UNEXPECTED
);
2319 * If the nexus is not clearly identified, reset the bus.
2320 * We will try to do better later.
2326 * Check instruction was a MOV, direction was INPUT and
2329 if ((cmd
& 0xc0) || !(phase
& 1) || !(sbcl
& 0x8))
2333 * Keep track of the parity error.
2335 OUTONB(np
, HF_PRT
, HF_EXT_ERR
);
2336 cp
->xerr_status
|= XE_PARITY_ERR
;
2339 * Prepare the message to send to the device.
2341 np
->msgout
[0] = (phase
== 7) ? M_PARITY
: M_ID_ERROR
;
2344 * If the old phase was DATA IN phase, we have to deal with
2345 * the 3 situations described above.
2346 * For other input phases (MSG IN and STATUS), the device
2347 * must resend the whole thing that failed parity checking
2348 * or signal error. So, jumping to dispatcher should be OK.
2350 if (phase
== 1 || phase
== 5) {
2351 /* Phase mismatch handled by SCRIPTS */
2352 if (dsp
== SCRIPTB_BA(np
, pm_handle
))
2354 /* Phase mismatch handled by the C code */
2357 /* No phase mismatch occurred */
2359 sym_set_script_dp (np
, cp
, dsp
);
2360 OUTL_DSP(np
, SCRIPTA_BA(np
, dispatch
));
2363 else if (phase
== 7) /* We definitely cannot handle parity errors */
2364 #if 1 /* in message-in phase due to the relection */
2365 goto reset_all
; /* path and various message anticipations. */
2367 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
2370 OUTL_DSP(np
, SCRIPTA_BA(np
, dispatch
));
2374 sym_start_reset(np
);
2379 * chip exception handler for phase errors.
2381 * We have to construct a new transfer descriptor,
2382 * to transfer the rest of the current block.
2384 static void sym_int_ma (struct sym_hcb
*np
)
2397 u_char hflags
, hflags0
;
2401 dsp
= INL(np
, nc_dsp
);
2402 dbc
= INL(np
, nc_dbc
);
2403 dsa
= INL(np
, nc_dsa
);
2406 rest
= dbc
& 0xffffff;
2410 * locate matching cp if any.
2412 cp
= sym_ccb_from_dsa(np
, dsa
);
2415 * Donnot take into account dma fifo and various buffers in
2416 * INPUT phase since the chip flushes everything before
2417 * raising the MA interrupt for interrupted INPUT phases.
2418 * For DATA IN phase, we will check for the SWIDE later.
2420 if ((cmd
& 7) != 1 && (cmd
& 7) != 5) {
2423 if (np
->features
& FE_DFBC
)
2424 delta
= INW(np
, nc_dfbc
);
2429 * Read DFIFO, CTEST[4-6] using 1 PCI bus ownership.
2431 dfifo
= INL(np
, nc_dfifo
);
2434 * Calculate remaining bytes in DMA fifo.
2435 * (CTEST5 = dfifo >> 16)
2437 if (dfifo
& (DFS
<< 16))
2438 delta
= ((((dfifo
>> 8) & 0x300) |
2439 (dfifo
& 0xff)) - rest
) & 0x3ff;
2441 delta
= ((dfifo
& 0xff) - rest
) & 0x7f;
2445 * The data in the dma fifo has not been transfered to
2446 * the target -> add the amount to the rest
2447 * and clear the data.
2448 * Check the sstat2 register in case of wide transfer.
2451 ss0
= INB(np
, nc_sstat0
);
2452 if (ss0
& OLF
) rest
++;
2453 if (!(np
->features
& FE_C10
))
2454 if (ss0
& ORF
) rest
++;
2455 if (cp
&& (cp
->phys
.select
.sel_scntl3
& EWS
)) {
2456 ss2
= INB(np
, nc_sstat2
);
2457 if (ss2
& OLF1
) rest
++;
2458 if (!(np
->features
& FE_C10
))
2459 if (ss2
& ORF1
) rest
++;
2465 OUTB(np
, nc_ctest3
, np
->rv_ctest3
| CLF
); /* dma fifo */
2466 OUTB(np
, nc_stest3
, TE
|CSF
); /* scsi fifo */
2470 * log the information
2472 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_PHASE
))
2473 printf ("P%x%x RL=%d D=%d ", cmd
&7, INB(np
, nc_sbcl
)&7,
2474 (unsigned) rest
, (unsigned) delta
);
2477 * try to find the interrupted script command,
2478 * and the address at which to continue.
2482 if (dsp
> np
->scripta_ba
&&
2483 dsp
<= np
->scripta_ba
+ np
->scripta_sz
) {
2484 vdsp
= (u32
*)((char*)np
->scripta0
+ (dsp
-np
->scripta_ba
-8));
2487 else if (dsp
> np
->scriptb_ba
&&
2488 dsp
<= np
->scriptb_ba
+ np
->scriptb_sz
) {
2489 vdsp
= (u32
*)((char*)np
->scriptb0
+ (dsp
-np
->scriptb_ba
-8));
2494 * log the information
2496 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
2497 printf ("\nCP=%p DSP=%x NXT=%x VDSP=%p CMD=%x ",
2498 cp
, (unsigned)dsp
, (unsigned)nxtdsp
, vdsp
, cmd
);
2502 printf ("%s: interrupted SCRIPT address not found.\n",
2508 printf ("%s: SCSI phase error fixup: CCB already dequeued.\n",
2514 * get old startaddress and old length.
2516 oadr
= scr_to_cpu(vdsp
[1]);
2518 if (cmd
& 0x10) { /* Table indirect */
2519 tblp
= (u32
*) ((char*) &cp
->phys
+ oadr
);
2520 olen
= scr_to_cpu(tblp
[0]);
2521 oadr
= scr_to_cpu(tblp
[1]);
2524 olen
= scr_to_cpu(vdsp
[0]) & 0xffffff;
2527 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
2528 printf ("OCMD=%x\nTBLP=%p OLEN=%x OADR=%x\n",
2529 (unsigned) (scr_to_cpu(vdsp
[0]) >> 24),
2536 * check cmd against assumed interrupted script command.
2537 * If dt data phase, the MOVE instruction hasn't bit 4 of
2540 if (((cmd
& 2) ? cmd
: (cmd
& ~4)) != (scr_to_cpu(vdsp
[0]) >> 24)) {
2541 sym_print_addr(cp
->cmd
,
2542 "internal error: cmd=%02x != %02x=(vdsp[0] >> 24)\n",
2543 cmd
, scr_to_cpu(vdsp
[0]) >> 24);
2549 * if old phase not dataphase, leave here.
2552 sym_print_addr(cp
->cmd
,
2553 "phase change %x-%x %d@%08x resid=%d.\n",
2554 cmd
&7, INB(np
, nc_sbcl
)&7, (unsigned)olen
,
2555 (unsigned)oadr
, (unsigned)rest
);
2556 goto unexpected_phase
;
2560 * Choose the correct PM save area.
2562 * Look at the PM_SAVE SCRIPT if you want to understand
2563 * this stuff. The equivalent code is implemented in
2564 * SCRIPTS for the 895A, 896 and 1010 that are able to
2565 * handle PM from the SCRIPTS processor.
2567 hflags0
= INB(np
, HF_PRT
);
2570 if (hflags
& (HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
)) {
2571 if (hflags
& HF_IN_PM0
)
2572 nxtdsp
= scr_to_cpu(cp
->phys
.pm0
.ret
);
2573 else if (hflags
& HF_IN_PM1
)
2574 nxtdsp
= scr_to_cpu(cp
->phys
.pm1
.ret
);
2576 if (hflags
& HF_DP_SAVED
)
2577 hflags
^= HF_ACT_PM
;
2580 if (!(hflags
& HF_ACT_PM
)) {
2582 newcmd
= SCRIPTA_BA(np
, pm0_data
);
2586 newcmd
= SCRIPTA_BA(np
, pm1_data
);
2589 hflags
&= ~(HF_IN_PM0
| HF_IN_PM1
| HF_DP_SAVED
);
2590 if (hflags
!= hflags0
)
2591 OUTB(np
, HF_PRT
, hflags
);
2594 * fillin the phase mismatch context
2596 pm
->sg
.addr
= cpu_to_scr(oadr
+ olen
- rest
);
2597 pm
->sg
.size
= cpu_to_scr(rest
);
2598 pm
->ret
= cpu_to_scr(nxtdsp
);
2601 * If we have a SWIDE,
2602 * - prepare the address to write the SWIDE from SCRIPTS,
2603 * - compute the SCRIPTS address to restart from,
2604 * - move current data pointer context by one byte.
2606 nxtdsp
= SCRIPTA_BA(np
, dispatch
);
2607 if ((cmd
& 7) == 1 && cp
&& (cp
->phys
.select
.sel_scntl3
& EWS
) &&
2608 (INB(np
, nc_scntl2
) & WSR
)) {
2612 * Set up the table indirect for the MOVE
2613 * of the residual byte and adjust the data
2616 tmp
= scr_to_cpu(pm
->sg
.addr
);
2617 cp
->phys
.wresid
.addr
= cpu_to_scr(tmp
);
2618 pm
->sg
.addr
= cpu_to_scr(tmp
+ 1);
2619 tmp
= scr_to_cpu(pm
->sg
.size
);
2620 cp
->phys
.wresid
.size
= cpu_to_scr((tmp
&0xff000000) | 1);
2621 pm
->sg
.size
= cpu_to_scr(tmp
- 1);
2624 * If only the residual byte is to be moved,
2625 * no PM context is needed.
2627 if ((tmp
&0xffffff) == 1)
2631 * Prepare the address of SCRIPTS that will
2632 * move the residual byte to memory.
2634 nxtdsp
= SCRIPTB_BA(np
, wsr_ma_helper
);
2637 if (DEBUG_FLAGS
& DEBUG_PHASE
) {
2638 sym_print_addr(cp
->cmd
, "PM %x %x %x / %x %x %x.\n",
2639 hflags0
, hflags
, newcmd
,
2640 (unsigned)scr_to_cpu(pm
->sg
.addr
),
2641 (unsigned)scr_to_cpu(pm
->sg
.size
),
2642 (unsigned)scr_to_cpu(pm
->ret
));
2646 * Restart the SCRIPTS processor.
2648 sym_set_script_dp (np
, cp
, newcmd
);
2649 OUTL_DSP(np
, nxtdsp
);
2653 * Unexpected phase changes that occurs when the current phase
2654 * is not a DATA IN or DATA OUT phase are due to error conditions.
2655 * Such event may only happen when the SCRIPTS is using a
2656 * multibyte SCSI MOVE.
2658 * Phase change Some possible cause
2660 * COMMAND --> MSG IN SCSI parity error detected by target.
2661 * COMMAND --> STATUS Bad command or refused by target.
2662 * MSG OUT --> MSG IN Message rejected by target.
2663 * MSG OUT --> COMMAND Bogus target that discards extended
2664 * negotiation messages.
2666 * The code below does not care of the new phase and so
2667 * trusts the target. Why to annoy it ?
2668 * If the interrupted phase is COMMAND phase, we restart at
2670 * If a target does not get all the messages after selection,
2671 * the code assumes blindly that the target discards extended
2672 * messages and clears the negotiation status.
2673 * If the target does not want all our response to negotiation,
2674 * we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids
2675 * bloat for such a should_not_happen situation).
2676 * In all other situation, we reset the BUS.
2677 * Are these assumptions reasonnable ? (Wait and see ...)
2684 case 2: /* COMMAND phase */
2685 nxtdsp
= SCRIPTA_BA(np
, dispatch
);
2688 case 3: /* STATUS phase */
2689 nxtdsp
= SCRIPTA_BA(np
, dispatch
);
2692 case 6: /* MSG OUT phase */
2694 * If the device may want to use untagged when we want
2695 * tagged, we prepare an IDENTIFY without disc. granted,
2696 * since we will not be able to handle reselect.
2697 * Otherwise, we just don't care.
2699 if (dsp
== SCRIPTA_BA(np
, send_ident
)) {
2700 if (cp
->tag
!= NO_TAG
&& olen
- rest
<= 3) {
2701 cp
->host_status
= HS_BUSY
;
2702 np
->msgout
[0] = IDENTIFY(0, cp
->lun
);
2703 nxtdsp
= SCRIPTB_BA(np
, ident_break_atn
);
2706 nxtdsp
= SCRIPTB_BA(np
, ident_break
);
2708 else if (dsp
== SCRIPTB_BA(np
, send_wdtr
) ||
2709 dsp
== SCRIPTB_BA(np
, send_sdtr
) ||
2710 dsp
== SCRIPTB_BA(np
, send_ppr
)) {
2711 nxtdsp
= SCRIPTB_BA(np
, nego_bad_phase
);
2712 if (dsp
== SCRIPTB_BA(np
, send_ppr
)) {
2713 struct scsi_device
*dev
= cp
->cmd
->device
;
2719 case 7: /* MSG IN phase */
2720 nxtdsp
= SCRIPTA_BA(np
, clrack
);
2726 OUTL_DSP(np
, nxtdsp
);
2731 sym_start_reset(np
);
2735 * chip interrupt handler
2737 * In normal situations, interrupt conditions occur one at
2738 * a time. But when something bad happens on the SCSI BUS,
2739 * the chip may raise several interrupt flags before
2740 * stopping and interrupting the CPU. The additionnal
2741 * interrupt flags are stacked in some extra registers
2742 * after the SIP and/or DIP flag has been raised in the
2743 * ISTAT. After the CPU has read the interrupt condition
2744 * flag from SIST or DSTAT, the chip unstacks the other
2745 * interrupt flags and sets the corresponding bits in
2746 * SIST or DSTAT. Since the chip starts stacking once the
2747 * SIP or DIP flag is set, there is a small window of time
2748 * where the stacking does not occur.
2750 * Typically, multiple interrupt conditions may happen in
2751 * the following situations:
2753 * - SCSI parity error + Phase mismatch (PAR|MA)
2754 * When an parity error is detected in input phase
2755 * and the device switches to msg-in phase inside a
2757 * - SCSI parity error + Unexpected disconnect (PAR|UDC)
2758 * When a stupid device does not want to handle the
2759 * recovery of an SCSI parity error.
2760 * - Some combinations of STO, PAR, UDC, ...
2761 * When using non compliant SCSI stuff, when user is
2762 * doing non compliant hot tampering on the BUS, when
2763 * something really bad happens to a device, etc ...
2765 * The heuristic suggested by SYMBIOS to handle
2766 * multiple interrupts is to try unstacking all
2767 * interrupts conditions and to handle them on some
2768 * priority based on error severity.
2769 * This will work when the unstacking has been
2770 * successful, but we cannot be 100 % sure of that,
2771 * since the CPU may have been faster to unstack than
2772 * the chip is able to stack. Hmmm ... But it seems that
2773 * such a situation is very unlikely to happen.
2775 * If this happen, for example STO caught by the CPU
2776 * then UDC happenning before the CPU have restarted
2777 * the SCRIPTS, the driver may wrongly complete the
2778 * same command on UDC, since the SCRIPTS didn't restart
2779 * and the DSA still points to the same command.
2780 * We avoid this situation by setting the DSA to an
2781 * invalid value when the CCB is completed and before
2782 * restarting the SCRIPTS.
2784 * Another issue is that we need some section of our
2785 * recovery procedures to be somehow uninterruptible but
2786 * the SCRIPTS processor does not provides such a
2787 * feature. For this reason, we handle recovery preferently
2788 * from the C code and check against some SCRIPTS critical
2789 * sections from the C code.
2791 * Hopefully, the interrupt handling of the driver is now
2792 * able to resist to weird BUS error conditions, but donnot
2793 * ask me for any guarantee that it will never fail. :-)
2794 * Use at your own decision and risk.
2797 void sym_interrupt (struct sym_hcb
*np
)
2799 u_char istat
, istatc
;
2804 * interrupt on the fly ?
2805 * (SCRIPTS may still be running)
2807 * A `dummy read' is needed to ensure that the
2808 * clear of the INTF flag reaches the device
2809 * and that posted writes are flushed to memory
2810 * before the scanning of the DONE queue.
2811 * Note that SCRIPTS also (dummy) read to memory
2812 * prior to deliver the INTF interrupt condition.
2814 istat
= INB(np
, nc_istat
);
2816 OUTB(np
, nc_istat
, (istat
& SIGP
) | INTF
| np
->istat_sem
);
2817 istat
= INB(np
, nc_istat
); /* DUMMY READ */
2818 if (DEBUG_FLAGS
& DEBUG_TINY
) printf ("F ");
2819 sym_wakeup_done(np
);
2822 if (!(istat
& (SIP
|DIP
)))
2825 #if 0 /* We should never get this one */
2827 OUTB(np
, nc_istat
, CABRT
);
2831 * PAR and MA interrupts may occur at the same time,
2832 * and we need to know of both in order to handle
2833 * this situation properly. We try to unstack SCSI
2834 * interrupts for that reason. BTW, I dislike a LOT
2835 * such a loop inside the interrupt routine.
2836 * Even if DMA interrupt stacking is very unlikely to
2837 * happen, we also try unstacking these ones, since
2838 * this has no performance impact.
2845 sist
|= INW(np
, nc_sist
);
2847 dstat
|= INB(np
, nc_dstat
);
2848 istatc
= INB(np
, nc_istat
);
2850 } while (istatc
& (SIP
|DIP
));
2852 if (DEBUG_FLAGS
& DEBUG_TINY
)
2853 printf ("<%d|%x:%x|%x:%x>",
2854 (int)INB(np
, nc_scr0
),
2856 (unsigned)INL(np
, nc_dsp
),
2857 (unsigned)INL(np
, nc_dbc
));
2859 * On paper, a memory read barrier may be needed here to
2860 * prevent out of order LOADs by the CPU from having
2861 * prefetched stale data prior to DMA having occurred.
2862 * And since we are paranoid ... :)
2864 MEMORY_READ_BARRIER();
2867 * First, interrupts we want to service cleanly.
2869 * Phase mismatch (MA) is the most frequent interrupt
2870 * for chip earlier than the 896 and so we have to service
2871 * it as quickly as possible.
2872 * A SCSI parity error (PAR) may be combined with a phase
2873 * mismatch condition (MA).
2874 * Programmed interrupts (SIR) are used to call the C code
2876 * The single step interrupt (SSI) is not used in this
2879 if (!(sist
& (STO
|GEN
|HTH
|SGE
|UDC
|SBMC
|RST
)) &&
2880 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
2881 if (sist
& PAR
) sym_int_par (np
, sist
);
2882 else if (sist
& MA
) sym_int_ma (np
);
2883 else if (dstat
& SIR
) sym_int_sir (np
);
2884 else if (dstat
& SSI
) OUTONB_STD();
2885 else goto unknown_int
;
2890 * Now, interrupts that donnot happen in normal
2891 * situations and that we may need to recover from.
2893 * On SCSI RESET (RST), we reset everything.
2894 * On SCSI BUS MODE CHANGE (SBMC), we complete all
2895 * active CCBs with RESET status, prepare all devices
2896 * for negotiating again and restart the SCRIPTS.
2897 * On STO and UDC, we complete the CCB with the corres-
2898 * ponding status and restart the SCRIPTS.
2901 printf("%s: SCSI BUS reset detected.\n", sym_name(np
));
2902 sym_start_up (np
, 1);
2906 OUTB(np
, nc_ctest3
, np
->rv_ctest3
| CLF
); /* clear dma fifo */
2907 OUTB(np
, nc_stest3
, TE
|CSF
); /* clear scsi fifo */
2909 if (!(sist
& (GEN
|HTH
|SGE
)) &&
2910 !(dstat
& (MDPE
|BF
|ABRT
|IID
))) {
2911 if (sist
& SBMC
) sym_int_sbmc (np
);
2912 else if (sist
& STO
) sym_int_sto (np
);
2913 else if (sist
& UDC
) sym_int_udc (np
);
2914 else goto unknown_int
;
2919 * Now, interrupts we are not able to recover cleanly.
2921 * Log message for hard errors.
2925 sym_log_hard_error(np
, sist
, dstat
);
2927 if ((sist
& (GEN
|HTH
|SGE
)) ||
2928 (dstat
& (MDPE
|BF
|ABRT
|IID
))) {
2929 sym_start_reset(np
);
2935 * We just miss the cause of the interrupt. :(
2936 * Print a message. The timeout will do the real work.
2938 printf( "%s: unknown interrupt(s) ignored, "
2939 "ISTAT=0x%x DSTAT=0x%x SIST=0x%x\n",
2940 sym_name(np
), istat
, dstat
, sist
);
2944 * Dequeue from the START queue all CCBs that match
2945 * a given target/lun/task condition (-1 means all),
2946 * and move them from the BUSY queue to the COMP queue
2947 * with CAM_REQUEUE_REQ status condition.
2948 * This function is used during error handling/recovery.
2949 * It is called with SCRIPTS not running.
2952 sym_dequeue_from_squeue(struct sym_hcb
*np
, int i
, int target
, int lun
, int task
)
2958 * Make sure the starting index is within range.
2960 assert((i
>= 0) && (i
< 2*MAX_QUEUE
));
2963 * Walk until end of START queue and dequeue every job
2964 * that matches the target/lun/task condition.
2967 while (i
!= np
->squeueput
) {
2968 cp
= sym_ccb_from_dsa(np
, scr_to_cpu(np
->squeue
[i
]));
2970 #ifdef SYM_CONF_IARB_SUPPORT
2971 /* Forget hints for IARB, they may be no longer relevant */
2972 cp
->host_flags
&= ~HF_HINT_IARB
;
2974 if ((target
== -1 || cp
->target
== target
) &&
2975 (lun
== -1 || cp
->lun
== lun
) &&
2976 (task
== -1 || cp
->tag
== task
)) {
2977 sym_set_cam_status(cp
->cmd
, CAM_REQUEUE_REQ
);
2978 sym_remque(&cp
->link_ccbq
);
2979 sym_insque_tail(&cp
->link_ccbq
, &np
->comp_ccbq
);
2983 np
->squeue
[j
] = np
->squeue
[i
];
2984 if ((j
+= 2) >= MAX_QUEUE
*2) j
= 0;
2986 if ((i
+= 2) >= MAX_QUEUE
*2) i
= 0;
2988 if (i
!= j
) /* Copy back the idle task if needed */
2989 np
->squeue
[j
] = np
->squeue
[i
];
2990 np
->squeueput
= j
; /* Update our current start queue pointer */
2996 * chip handler for bad SCSI status condition
2998 * In case of bad SCSI status, we unqueue all the tasks
2999 * currently queued to the controller but not yet started
3000 * and then restart the SCRIPTS processor immediately.
3002 * QUEUE FULL and BUSY conditions are handled the same way.
3003 * Basically all the not yet started tasks are requeued in
3004 * device queue and the queue is frozen until a completion.
3006 * For CHECK CONDITION and COMMAND TERMINATED status, we use
3007 * the CCB of the failed command to prepare a REQUEST SENSE
3008 * SCSI command and queue it to the controller queue.
3010 * SCRATCHA is assumed to have been loaded with STARTPOS
3011 * before the SCRIPTS called the C code.
3013 static void sym_sir_bad_scsi_status(struct sym_hcb
*np
, int num
, struct sym_ccb
*cp
)
3016 u_char s_status
= cp
->ssss_status
;
3017 u_char h_flags
= cp
->host_flags
;
3022 * Compute the index of the next job to start from SCRIPTS.
3024 i
= (INL(np
, nc_scratcha
) - np
->squeue_ba
) / 4;
3027 * The last CCB queued used for IARB hint may be
3028 * no longer relevant. Forget it.
3030 #ifdef SYM_CONF_IARB_SUPPORT
3036 * Now deal with the SCSI status.
3041 if (sym_verbose
>= 2) {
3042 sym_print_addr(cp
->cmd
, "%s\n",
3043 s_status
== S_BUSY
? "BUSY" : "QUEUE FULL\n");
3045 default: /* S_INT, S_INT_COND_MET, S_CONFLICT */
3046 sym_complete_error (np
, cp
);
3051 * If we get an SCSI error when requesting sense, give up.
3053 if (h_flags
& HF_SENSE
) {
3054 sym_complete_error (np
, cp
);
3059 * Dequeue all queued CCBs for that device not yet started,
3060 * and restart the SCRIPTS processor immediately.
3062 sym_dequeue_from_squeue(np
, i
, cp
->target
, cp
->lun
, -1);
3063 OUTL_DSP(np
, SCRIPTA_BA(np
, start
));
3066 * Save some info of the actual IO.
3067 * Compute the data residual.
3069 cp
->sv_scsi_status
= cp
->ssss_status
;
3070 cp
->sv_xerr_status
= cp
->xerr_status
;
3071 cp
->sv_resid
= sym_compute_residual(np
, cp
);
3074 * Prepare all needed data structures for
3075 * requesting sense data.
3078 cp
->scsi_smsg2
[0] = IDENTIFY(0, cp
->lun
);
3082 * If we are currently using anything different from
3083 * async. 8 bit data transfers with that target,
3084 * start a negotiation, since the device may want
3085 * to report us a UNIT ATTENTION condition due to
3086 * a cause we currently ignore, and we donnot want
3087 * to be stuck with WIDE and/or SYNC data transfer.
3089 * cp->nego_status is filled by sym_prepare_nego().
3091 cp
->nego_status
= 0;
3092 msglen
+= sym_prepare_nego(np
, cp
, &cp
->scsi_smsg2
[msglen
]);
3094 * Message table indirect structure.
3096 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_BA(cp
, scsi_smsg2
));
3097 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
3102 cp
->phys
.cmd
.addr
= cpu_to_scr(CCB_BA(cp
, sensecmd
));
3103 cp
->phys
.cmd
.size
= cpu_to_scr(6);
3106 * patch requested size into sense command
3108 cp
->sensecmd
[0] = REQUEST_SENSE
;
3109 cp
->sensecmd
[1] = 0;
3110 if (cp
->cmd
->device
->scsi_level
<= SCSI_2
&& cp
->lun
<= 7)
3111 cp
->sensecmd
[1] = cp
->lun
<< 5;
3112 cp
->sensecmd
[4] = SYM_SNS_BBUF_LEN
;
3113 cp
->data_len
= SYM_SNS_BBUF_LEN
;
3118 memset(cp
->sns_bbuf
, 0, SYM_SNS_BBUF_LEN
);
3119 cp
->phys
.sense
.addr
= cpu_to_scr(CCB_BA(cp
, sns_bbuf
));
3120 cp
->phys
.sense
.size
= cpu_to_scr(SYM_SNS_BBUF_LEN
);
3123 * requeue the command.
3125 startp
= SCRIPTB_BA(np
, sdata_in
);
3127 cp
->phys
.head
.savep
= cpu_to_scr(startp
);
3128 cp
->phys
.head
.lastp
= cpu_to_scr(startp
);
3129 cp
->startp
= cpu_to_scr(startp
);
3130 cp
->goalp
= cpu_to_scr(startp
+ 16);
3132 cp
->host_xflags
= 0;
3133 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
3134 cp
->ssss_status
= S_ILLEGAL
;
3135 cp
->host_flags
= (HF_SENSE
|HF_DATA_IN
);
3136 cp
->xerr_status
= 0;
3137 cp
->extra_bytes
= 0;
3139 cp
->phys
.head
.go
.start
= cpu_to_scr(SCRIPTA_BA(np
, select
));
3142 * Requeue the command.
3144 sym_put_start_queue(np
, cp
);
3147 * Give back to upper layer everything we have dequeued.
3149 sym_flush_comp_queue(np
, 0);
3155 * After a device has accepted some management message
3156 * as BUS DEVICE RESET, ABORT TASK, etc ..., or when
3157 * a device signals a UNIT ATTENTION condition, some
3158 * tasks are thrown away by the device. We are required
3159 * to reflect that on our tasks list since the device
3160 * will never complete these tasks.
3162 * This function move from the BUSY queue to the COMP
3163 * queue all disconnected CCBs for a given target that
3164 * match the following criteria:
3165 * - lun=-1 means any logical UNIT otherwise a given one.
3166 * - task=-1 means any task, otherwise a given one.
3168 int sym_clear_tasks(struct sym_hcb
*np
, int cam_status
, int target
, int lun
, int task
)
3170 SYM_QUEHEAD qtmp
, *qp
;
3175 * Move the entire BUSY queue to our temporary queue.
3177 sym_que_init(&qtmp
);
3178 sym_que_splice(&np
->busy_ccbq
, &qtmp
);
3179 sym_que_init(&np
->busy_ccbq
);
3182 * Put all CCBs that matches our criteria into
3183 * the COMP queue and put back other ones into
3186 while ((qp
= sym_remque_head(&qtmp
)) != 0) {
3187 struct scsi_cmnd
*cmd
;
3188 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
3190 if (cp
->host_status
!= HS_DISCONNECT
||
3191 cp
->target
!= target
||
3192 (lun
!= -1 && cp
->lun
!= lun
) ||
3194 (cp
->tag
!= NO_TAG
&& cp
->scsi_smsg
[2] != task
))) {
3195 sym_insque_tail(&cp
->link_ccbq
, &np
->busy_ccbq
);
3198 sym_insque_tail(&cp
->link_ccbq
, &np
->comp_ccbq
);
3200 /* Preserve the software timeout condition */
3201 if (sym_get_cam_status(cmd
) != CAM_CMD_TIMEOUT
)
3202 sym_set_cam_status(cmd
, cam_status
);
3205 printf("XXXX TASK @%p CLEARED\n", cp
);
3212 * chip handler for TASKS recovery
3214 * We cannot safely abort a command, while the SCRIPTS
3215 * processor is running, since we just would be in race
3218 * As long as we have tasks to abort, we keep the SEM
3219 * bit set in the ISTAT. When this bit is set, the
3220 * SCRIPTS processor interrupts (SIR_SCRIPT_STOPPED)
3221 * each time it enters the scheduler.
3223 * If we have to reset a target, clear tasks of a unit,
3224 * or to perform the abort of a disconnected job, we
3225 * restart the SCRIPTS for selecting the target. Once
3226 * selected, the SCRIPTS interrupts (SIR_TARGET_SELECTED).
3227 * If it loses arbitration, the SCRIPTS will interrupt again
3228 * the next time it will enter its scheduler, and so on ...
3230 * On SIR_TARGET_SELECTED, we scan for the more
3231 * appropriate thing to do:
3233 * - If nothing, we just sent a M_ABORT message to the
3234 * target to get rid of the useless SCSI bus ownership.
3235 * According to the specs, no tasks shall be affected.
3236 * - If the target is to be reset, we send it a M_RESET
3238 * - If a logical UNIT is to be cleared , we send the
3239 * IDENTIFY(lun) + M_ABORT.
3240 * - If an untagged task is to be aborted, we send the
3241 * IDENTIFY(lun) + M_ABORT.
3242 * - If a tagged task is to be aborted, we send the
3243 * IDENTIFY(lun) + task attributes + M_ABORT_TAG.
3245 * Once our 'kiss of death' :) message has been accepted
3246 * by the target, the SCRIPTS interrupts again
3247 * (SIR_ABORT_SENT). On this interrupt, we complete
3248 * all the CCBs that should have been aborted by the
3249 * target according to our message.
3251 static void sym_sir_task_recovery(struct sym_hcb
*np
, int num
)
3255 struct sym_tcb
*tp
= NULL
; /* gcc isn't quite smart enough yet */
3256 struct scsi_target
*starget
;
3257 int target
=-1, lun
=-1, task
;
3262 * The SCRIPTS processor stopped before starting
3263 * the next command in order to allow us to perform
3264 * some task recovery.
3266 case SIR_SCRIPT_STOPPED
:
3268 * Do we have any target to reset or unit to clear ?
3270 for (i
= 0 ; i
< SYM_CONF_MAX_TARGET
; i
++) {
3271 tp
= &np
->target
[i
];
3273 (tp
->lun0p
&& tp
->lun0p
->to_clear
)) {
3279 for (k
= 1 ; k
< SYM_CONF_MAX_LUN
; k
++) {
3280 if (tp
->lunmp
[k
] && tp
->lunmp
[k
]->to_clear
) {
3290 * If not, walk the busy queue for any
3291 * disconnected CCB to be aborted.
3294 FOR_EACH_QUEUED_ELEMENT(&np
->busy_ccbq
, qp
) {
3295 cp
= sym_que_entry(qp
,struct sym_ccb
,link_ccbq
);
3296 if (cp
->host_status
!= HS_DISCONNECT
)
3299 target
= cp
->target
;
3306 * If some target is to be selected,
3307 * prepare and start the selection.
3310 tp
= &np
->target
[target
];
3311 np
->abrt_sel
.sel_id
= target
;
3312 np
->abrt_sel
.sel_scntl3
= tp
->head
.wval
;
3313 np
->abrt_sel
.sel_sxfer
= tp
->head
.sval
;
3314 OUTL(np
, nc_dsa
, np
->hcb_ba
);
3315 OUTL_DSP(np
, SCRIPTB_BA(np
, sel_for_abort
));
3320 * Now look for a CCB to abort that haven't started yet.
3321 * Btw, the SCRIPTS processor is still stopped, so
3322 * we are not in race.
3326 FOR_EACH_QUEUED_ELEMENT(&np
->busy_ccbq
, qp
) {
3327 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
3328 if (cp
->host_status
!= HS_BUSY
&&
3329 cp
->host_status
!= HS_NEGOTIATE
)
3333 #ifdef SYM_CONF_IARB_SUPPORT
3335 * If we are using IMMEDIATE ARBITRATION, we donnot
3336 * want to cancel the last queued CCB, since the
3337 * SCRIPTS may have anticipated the selection.
3339 if (cp
== np
->last_cp
) {
3344 i
= 1; /* Means we have found some */
3349 * We are done, so we donnot need
3350 * to synchronize with the SCRIPTS anylonger.
3351 * Remove the SEM flag from the ISTAT.
3354 OUTB(np
, nc_istat
, SIGP
);
3358 * Compute index of next position in the start
3359 * queue the SCRIPTS intends to start and dequeue
3360 * all CCBs for that device that haven't been started.
3362 i
= (INL(np
, nc_scratcha
) - np
->squeue_ba
) / 4;
3363 i
= sym_dequeue_from_squeue(np
, i
, cp
->target
, cp
->lun
, -1);
3366 * Make sure at least our IO to abort has been dequeued.
3368 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
3369 assert(i
&& sym_get_cam_status(cp
->cmd
) == CAM_REQUEUE_REQ
);
3371 sym_remque(&cp
->link_ccbq
);
3372 sym_insque_tail(&cp
->link_ccbq
, &np
->comp_ccbq
);
3375 * Keep track in cam status of the reason of the abort.
3377 if (cp
->to_abort
== 2)
3378 sym_set_cam_status(cp
->cmd
, CAM_CMD_TIMEOUT
);
3380 sym_set_cam_status(cp
->cmd
, CAM_REQ_ABORTED
);
3383 * Complete with error everything that we have dequeued.
3385 sym_flush_comp_queue(np
, 0);
3388 * The SCRIPTS processor has selected a target
3389 * we may have some manual recovery to perform for.
3391 case SIR_TARGET_SELECTED
:
3392 target
= INB(np
, nc_sdid
) & 0xf;
3393 tp
= &np
->target
[target
];
3395 np
->abrt_tbl
.addr
= cpu_to_scr(vtobus(np
->abrt_msg
));
3398 * If the target is to be reset, prepare a
3399 * M_RESET message and clear the to_reset flag
3400 * since we donnot expect this operation to fail.
3403 np
->abrt_msg
[0] = M_RESET
;
3404 np
->abrt_tbl
.size
= 1;
3410 * Otherwise, look for some logical unit to be cleared.
3412 if (tp
->lun0p
&& tp
->lun0p
->to_clear
)
3414 else if (tp
->lunmp
) {
3415 for (k
= 1 ; k
< SYM_CONF_MAX_LUN
; k
++) {
3416 if (tp
->lunmp
[k
] && tp
->lunmp
[k
]->to_clear
) {
3424 * If a logical unit is to be cleared, prepare
3425 * an IDENTIFY(lun) + ABORT MESSAGE.
3428 struct sym_lcb
*lp
= sym_lp(tp
, lun
);
3429 lp
->to_clear
= 0; /* We don't expect to fail here */
3430 np
->abrt_msg
[0] = IDENTIFY(0, lun
);
3431 np
->abrt_msg
[1] = M_ABORT
;
3432 np
->abrt_tbl
.size
= 2;
3437 * Otherwise, look for some disconnected job to
3438 * abort for this target.
3442 FOR_EACH_QUEUED_ELEMENT(&np
->busy_ccbq
, qp
) {
3443 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
3444 if (cp
->host_status
!= HS_DISCONNECT
)
3446 if (cp
->target
!= target
)
3450 i
= 1; /* Means we have some */
3455 * If we have none, probably since the device has
3456 * completed the command before we won abitration,
3457 * send a M_ABORT message without IDENTIFY.
3458 * According to the specs, the device must just
3459 * disconnect the BUS and not abort any task.
3462 np
->abrt_msg
[0] = M_ABORT
;
3463 np
->abrt_tbl
.size
= 1;
3468 * We have some task to abort.
3469 * Set the IDENTIFY(lun)
3471 np
->abrt_msg
[0] = IDENTIFY(0, cp
->lun
);
3474 * If we want to abort an untagged command, we
3475 * will send a IDENTIFY + M_ABORT.
3476 * Otherwise (tagged command), we will send
3477 * a IDENTITFY + task attributes + ABORT TAG.
3479 if (cp
->tag
== NO_TAG
) {
3480 np
->abrt_msg
[1] = M_ABORT
;
3481 np
->abrt_tbl
.size
= 2;
3483 np
->abrt_msg
[1] = cp
->scsi_smsg
[1];
3484 np
->abrt_msg
[2] = cp
->scsi_smsg
[2];
3485 np
->abrt_msg
[3] = M_ABORT_TAG
;
3486 np
->abrt_tbl
.size
= 4;
3489 * Keep track of software timeout condition, since the
3490 * peripheral driver may not count retries on abort
3491 * conditions not due to timeout.
3493 if (cp
->to_abort
== 2)
3494 sym_set_cam_status(cp
->cmd
, CAM_CMD_TIMEOUT
);
3495 cp
->to_abort
= 0; /* We donnot expect to fail here */
3499 * The target has accepted our message and switched
3500 * to BUS FREE phase as we expected.
3502 case SIR_ABORT_SENT
:
3503 target
= INB(np
, nc_sdid
) & 0xf;
3504 tp
= &np
->target
[target
];
3505 starget
= tp
->sdev
->sdev_target
;
3508 ** If we didn't abort anything, leave here.
3510 if (np
->abrt_msg
[0] == M_ABORT
)
3514 * If we sent a M_RESET, then a hardware reset has
3515 * been performed by the target.
3516 * - Reset everything to async 8 bit
3517 * - Tell ourself to negotiate next time :-)
3518 * - Prepare to clear all disconnected CCBs for
3519 * this target from our task list (lun=task=-1)
3523 if (np
->abrt_msg
[0] == M_RESET
) {
3525 tp
->head
.wval
= np
->rv_scntl3
;
3527 spi_period(starget
) = 0;
3528 spi_offset(starget
) = 0;
3529 spi_width(starget
) = 0;
3530 spi_iu(starget
) = 0;
3531 spi_dt(starget
) = 0;
3532 spi_qas(starget
) = 0;
3533 tp
->tgoal
.check_nego
= 1;
3537 * Otherwise, check for the LUN and TASK(s)
3538 * concerned by the cancelation.
3539 * If it is not ABORT_TAG then it is CLEAR_QUEUE
3540 * or an ABORT message :-)
3543 lun
= np
->abrt_msg
[0] & 0x3f;
3544 if (np
->abrt_msg
[1] == M_ABORT_TAG
)
3545 task
= np
->abrt_msg
[2];
3549 * Complete all the CCBs the device should have
3550 * aborted due to our 'kiss of death' message.
3552 i
= (INL(np
, nc_scratcha
) - np
->squeue_ba
) / 4;
3553 sym_dequeue_from_squeue(np
, i
, target
, lun
, -1);
3554 sym_clear_tasks(np
, CAM_REQ_ABORTED
, target
, lun
, task
);
3555 sym_flush_comp_queue(np
, 0);
3558 * If we sent a BDR, make upper layer aware of that.
3560 if (np
->abrt_msg
[0] == M_RESET
)
3561 sym_xpt_async_sent_bdr(np
, target
);
3566 * Print to the log the message we intend to send.
3568 if (num
== SIR_TARGET_SELECTED
) {
3569 dev_info(&tp
->sdev
->sdev_target
->dev
, "control msgout:");
3570 sym_printl_hex(np
->abrt_msg
, np
->abrt_tbl
.size
);
3571 np
->abrt_tbl
.size
= cpu_to_scr(np
->abrt_tbl
.size
);
3575 * Let the SCRIPTS processor continue.
3581 * Gerard's alchemy:) that deals with with the data
3582 * pointer for both MDP and the residual calculation.
3584 * I didn't want to bloat the code by more than 200
3585 * lines for the handling of both MDP and the residual.
3586 * This has been achieved by using a data pointer
3587 * representation consisting in an index in the data
3588 * array (dp_sg) and a negative offset (dp_ofs) that
3589 * have the following meaning:
3591 * - dp_sg = SYM_CONF_MAX_SG
3592 * we are at the end of the data script.
3593 * - dp_sg < SYM_CONF_MAX_SG
3594 * dp_sg points to the next entry of the scatter array
3595 * we want to transfer.
3597 * dp_ofs represents the residual of bytes of the
3598 * previous entry scatter entry we will send first.
3600 * no residual to send first.
3602 * The function sym_evaluate_dp() accepts an arbitray
3603 * offset (basically from the MDP message) and returns
3604 * the corresponding values of dp_sg and dp_ofs.
3607 static int sym_evaluate_dp(struct sym_hcb
*np
, struct sym_ccb
*cp
, u32 scr
, int *ofs
)
3610 int dp_ofs
, dp_sg
, dp_sgmin
;
3615 * Compute the resulted data pointer in term of a script
3616 * address within some DATA script and a signed byte offset.
3620 if (dp_scr
== SCRIPTA_BA(np
, pm0_data
))
3622 else if (dp_scr
== SCRIPTA_BA(np
, pm1_data
))
3628 dp_scr
= scr_to_cpu(pm
->ret
);
3629 dp_ofs
-= scr_to_cpu(pm
->sg
.size
);
3633 * If we are auto-sensing, then we are done.
3635 if (cp
->host_flags
& HF_SENSE
) {
3641 * Deduce the index of the sg entry.
3642 * Keep track of the index of the first valid entry.
3643 * If result is dp_sg = SYM_CONF_MAX_SG, then we are at the
3646 tmp
= scr_to_cpu(sym_goalp(cp
));
3647 dp_sg
= SYM_CONF_MAX_SG
;
3649 dp_sg
-= (tmp
- 8 - (int)dp_scr
) / (2*4);
3650 dp_sgmin
= SYM_CONF_MAX_SG
- cp
->segments
;
3653 * Move to the sg entry the data pointer belongs to.
3655 * If we are inside the data area, we expect result to be:
3658 * dp_ofs = 0 and dp_sg is the index of the sg entry
3659 * the data pointer belongs to (or the end of the data)
3661 * dp_ofs < 0 and dp_sg is the index of the sg entry
3662 * the data pointer belongs to + 1.
3666 while (dp_sg
> dp_sgmin
) {
3668 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
].size
);
3669 n
= dp_ofs
+ (tmp
& 0xffffff);
3677 else if (dp_ofs
> 0) {
3678 while (dp_sg
< SYM_CONF_MAX_SG
) {
3679 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
].size
);
3680 dp_ofs
-= (tmp
& 0xffffff);
3688 * Make sure the data pointer is inside the data area.
3689 * If not, return some error.
3691 if (dp_sg
< dp_sgmin
|| (dp_sg
== dp_sgmin
&& dp_ofs
< 0))
3693 else if (dp_sg
> SYM_CONF_MAX_SG
||
3694 (dp_sg
== SYM_CONF_MAX_SG
&& dp_ofs
> 0))
3698 * Save the extreme pointer if needed.
3700 if (dp_sg
> cp
->ext_sg
||
3701 (dp_sg
== cp
->ext_sg
&& dp_ofs
> cp
->ext_ofs
)) {
3703 cp
->ext_ofs
= dp_ofs
;
3717 * chip handler for MODIFY DATA POINTER MESSAGE
3719 * We also call this function on IGNORE WIDE RESIDUE
3720 * messages that do not match a SWIDE full condition.
3721 * Btw, we assume in that situation that such a message
3722 * is equivalent to a MODIFY DATA POINTER (offset=-1).
3725 static void sym_modify_dp(struct sym_hcb
*np
, struct sym_tcb
*tp
, struct sym_ccb
*cp
, int ofs
)
3728 u32 dp_scr
= sym_get_script_dp (np
, cp
);
3736 * Not supported for auto-sense.
3738 if (cp
->host_flags
& HF_SENSE
)
3742 * Apply our alchemy:) (see comments in sym_evaluate_dp()),
3743 * to the resulted data pointer.
3745 dp_sg
= sym_evaluate_dp(np
, cp
, dp_scr
, &dp_ofs
);
3750 * And our alchemy:) allows to easily calculate the data
3751 * script address we want to return for the next data phase.
3753 dp_ret
= cpu_to_scr(sym_goalp(cp
));
3754 dp_ret
= dp_ret
- 8 - (SYM_CONF_MAX_SG
- dp_sg
) * (2*4);
3757 * If offset / scatter entry is zero we donnot need
3758 * a context for the new current data pointer.
3766 * Get a context for the new current data pointer.
3768 hflags
= INB(np
, HF_PRT
);
3770 if (hflags
& HF_DP_SAVED
)
3771 hflags
^= HF_ACT_PM
;
3773 if (!(hflags
& HF_ACT_PM
)) {
3775 dp_scr
= SCRIPTA_BA(np
, pm0_data
);
3779 dp_scr
= SCRIPTA_BA(np
, pm1_data
);
3782 hflags
&= ~(HF_DP_SAVED
);
3784 OUTB(np
, HF_PRT
, hflags
);
3787 * Set up the new current data pointer.
3788 * ofs < 0 there, and for the next data phase, we
3789 * want to transfer part of the data of the sg entry
3790 * corresponding to index dp_sg-1 prior to returning
3791 * to the main data script.
3793 pm
->ret
= cpu_to_scr(dp_ret
);
3794 tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
-1].addr
);
3795 tmp
+= scr_to_cpu(cp
->phys
.data
[dp_sg
-1].size
) + dp_ofs
;
3796 pm
->sg
.addr
= cpu_to_scr(tmp
);
3797 pm
->sg
.size
= cpu_to_scr(-dp_ofs
);
3800 sym_set_script_dp (np
, cp
, dp_scr
);
3801 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
3805 OUTL_DSP(np
, SCRIPTB_BA(np
, msg_bad
));
3810 * chip calculation of the data residual.
3812 * As I used to say, the requirement of data residual
3813 * in SCSI is broken, useless and cannot be achieved
3814 * without huge complexity.
3815 * But most OSes and even the official CAM require it.
3816 * When stupidity happens to be so widely spread inside
3817 * a community, it gets hard to convince.
3819 * Anyway, I don't care, since I am not going to use
3820 * any software that considers this data residual as
3821 * a relevant information. :)
3824 int sym_compute_residual(struct sym_hcb
*np
, struct sym_ccb
*cp
)
3826 int dp_sg
, dp_sgmin
, resid
= 0;
3830 * Check for some data lost or just thrown away.
3831 * We are not required to be quite accurate in this
3832 * situation. Btw, if we are odd for output and the
3833 * device claims some more data, it may well happen
3834 * than our residual be zero. :-)
3836 if (cp
->xerr_status
& (XE_EXTRA_DATA
|XE_SODL_UNRUN
|XE_SWIDE_OVRUN
)) {
3837 if (cp
->xerr_status
& XE_EXTRA_DATA
)
3838 resid
-= cp
->extra_bytes
;
3839 if (cp
->xerr_status
& XE_SODL_UNRUN
)
3841 if (cp
->xerr_status
& XE_SWIDE_OVRUN
)
3846 * If all data has been transferred,
3847 * there is no residual.
3849 if (cp
->phys
.head
.lastp
== sym_goalp(cp
))
3853 * If no data transfer occurs, or if the data
3854 * pointer is weird, return full residual.
3856 if (cp
->startp
== cp
->phys
.head
.lastp
||
3857 sym_evaluate_dp(np
, cp
, scr_to_cpu(cp
->phys
.head
.lastp
),
3859 return cp
->data_len
;
3863 * If we were auto-sensing, then we are done.
3865 if (cp
->host_flags
& HF_SENSE
) {
3870 * We are now full comfortable in the computation
3871 * of the data residual (2's complement).
3873 dp_sgmin
= SYM_CONF_MAX_SG
- cp
->segments
;
3874 resid
= -cp
->ext_ofs
;
3875 for (dp_sg
= cp
->ext_sg
; dp_sg
< SYM_CONF_MAX_SG
; ++dp_sg
) {
3876 u_int tmp
= scr_to_cpu(cp
->phys
.data
[dp_sg
].size
);
3877 resid
+= (tmp
& 0xffffff);
3881 * Hopefully, the result is not too wrong.
3887 * Negotiation for WIDE and SYNCHRONOUS DATA TRANSFER.
3889 * When we try to negotiate, we append the negotiation message
3890 * to the identify and (maybe) simple tag message.
3891 * The host status field is set to HS_NEGOTIATE to mark this
3894 * If the target doesn't answer this message immediately
3895 * (as required by the standard), the SIR_NEGO_FAILED interrupt
3896 * will be raised eventually.
3897 * The handler removes the HS_NEGOTIATE status, and sets the
3898 * negotiated value to the default (async / nowide).
3900 * If we receive a matching answer immediately, we check it
3901 * for validity, and set the values.
3903 * If we receive a Reject message immediately, we assume the
3904 * negotiation has failed, and fall back to standard values.
3906 * If we receive a negotiation message while not in HS_NEGOTIATE
3907 * state, it's a target initiated negotiation. We prepare a
3908 * (hopefully) valid answer, set our parameters, and send back
3909 * this answer to the target.
3911 * If the target doesn't fetch the answer (no message out phase),
3912 * we assume the negotiation has failed, and fall back to default
3913 * settings (SIR_NEGO_PROTO interrupt).
3915 * When we set the values, we adjust them in all ccbs belonging
3916 * to this target, in the controller's register, and in the "phys"
3917 * field of the controller's struct sym_hcb.
3921 * chip handler for SYNCHRONOUS DATA TRANSFER REQUEST (SDTR) message.
3924 sym_sync_nego_check(struct sym_hcb
*np
, int req
, struct sym_ccb
*cp
)
3926 int target
= cp
->target
;
3927 u_char chg
, ofs
, per
, fak
, div
;
3929 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
3930 sym_print_nego_msg(np
, target
, "sync msgin", np
->msgin
);
3934 * Get requested values.
3941 * Check values against our limits.
3944 if (ofs
> np
->maxoffs
)
3945 {chg
= 1; ofs
= np
->maxoffs
;}
3949 if (per
< np
->minsync
)
3950 {chg
= 1; per
= np
->minsync
;}
3954 * Get new chip synchronous parameters value.
3957 if (ofs
&& sym_getsync(np
, 0, per
, &div
, &fak
) < 0)
3960 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
3961 sym_print_addr(cp
->cmd
,
3962 "sdtr: ofs=%d per=%d div=%d fak=%d chg=%d.\n",
3963 ofs
, per
, div
, fak
, chg
);
3967 * If it was an answer we want to change,
3968 * then it isn't acceptable. Reject it.
3976 sym_setsync (np
, target
, ofs
, per
, div
, fak
);
3979 * It was an answer. We are done.
3985 * It was a request. Prepare an answer message.
3987 np
->msgout
[0] = M_EXTENDED
;
3989 np
->msgout
[2] = M_X_SYNC_REQ
;
3990 np
->msgout
[3] = per
;
3991 np
->msgout
[4] = ofs
;
3993 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
3994 sym_print_nego_msg(np
, target
, "sync msgout", np
->msgout
);
3997 np
->msgin
[0] = M_NOOP
;
4002 sym_setsync (np
, target
, 0, 0, 0, 0);
4006 static void sym_sync_nego(struct sym_hcb
*np
, struct sym_tcb
*tp
, struct sym_ccb
*cp
)
4012 * Request or answer ?
4014 if (INB(np
, HS_PRT
) == HS_NEGOTIATE
) {
4015 OUTB(np
, HS_PRT
, HS_BUSY
);
4016 if (cp
->nego_status
&& cp
->nego_status
!= NS_SYNC
)
4022 * Check and apply new values.
4024 result
= sym_sync_nego_check(np
, req
, cp
);
4025 if (result
) /* Not acceptable, reject it */
4027 if (req
) { /* Was a request, send response. */
4028 cp
->nego_status
= NS_SYNC
;
4029 OUTL_DSP(np
, SCRIPTB_BA(np
, sdtr_resp
));
4031 else /* Was a response, we are done. */
4032 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
4036 OUTL_DSP(np
, SCRIPTB_BA(np
, msg_bad
));
4040 * chip handler for PARALLEL PROTOCOL REQUEST (PPR) message.
4043 sym_ppr_nego_check(struct sym_hcb
*np
, int req
, int target
)
4045 struct sym_tcb
*tp
= &np
->target
[target
];
4046 unsigned char fak
, div
;
4049 unsigned char per
= np
->msgin
[3];
4050 unsigned char ofs
= np
->msgin
[5];
4051 unsigned char wide
= np
->msgin
[6];
4052 unsigned char opts
= np
->msgin
[7] & PPR_OPT_MASK
;
4054 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4055 sym_print_nego_msg(np
, target
, "ppr msgin", np
->msgin
);
4059 * Check values against our limits.
4061 if (wide
> np
->maxwide
) {
4065 if (!wide
|| !(np
->features
& FE_U3EN
))
4068 if (opts
!= (np
->msgin
[7] & PPR_OPT_MASK
))
4071 dt
= opts
& PPR_OPT_DT
;
4074 unsigned char maxoffs
= dt
? np
->maxoffs_dt
: np
->maxoffs
;
4075 if (ofs
> maxoffs
) {
4082 unsigned char minsync
= dt
? np
->minsync_dt
: np
->minsync
;
4083 if (per
< minsync
) {
4090 * Get new chip synchronous parameters value.
4093 if (ofs
&& sym_getsync(np
, dt
, per
, &div
, &fak
) < 0)
4097 * If it was an answer we want to change,
4098 * then it isn't acceptable. Reject it.
4106 sym_setpprot(np
, target
, opts
, ofs
, per
, wide
, div
, fak
);
4109 * It was an answer. We are done.
4115 * It was a request. Prepare an answer message.
4117 np
->msgout
[0] = M_EXTENDED
;
4119 np
->msgout
[2] = M_X_PPR_REQ
;
4120 np
->msgout
[3] = per
;
4122 np
->msgout
[5] = ofs
;
4123 np
->msgout
[6] = wide
;
4124 np
->msgout
[7] = opts
;
4126 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4127 sym_print_nego_msg(np
, target
, "ppr msgout", np
->msgout
);
4130 np
->msgin
[0] = M_NOOP
;
4135 sym_setpprot (np
, target
, 0, 0, 0, 0, 0, 0);
4137 * If it is a device response that should result in
4138 * ST, we may want to try a legacy negotiation later.
4140 if (!req
&& !opts
) {
4141 tp
->tgoal
.period
= per
;
4142 tp
->tgoal
.offset
= ofs
;
4143 tp
->tgoal
.width
= wide
;
4144 tp
->tgoal
.iu
= tp
->tgoal
.dt
= tp
->tgoal
.qas
= 0;
4145 tp
->tgoal
.check_nego
= 1;
4150 static void sym_ppr_nego(struct sym_hcb
*np
, struct sym_tcb
*tp
, struct sym_ccb
*cp
)
4156 * Request or answer ?
4158 if (INB(np
, HS_PRT
) == HS_NEGOTIATE
) {
4159 OUTB(np
, HS_PRT
, HS_BUSY
);
4160 if (cp
->nego_status
&& cp
->nego_status
!= NS_PPR
)
4166 * Check and apply new values.
4168 result
= sym_ppr_nego_check(np
, req
, cp
->target
);
4169 if (result
) /* Not acceptable, reject it */
4171 if (req
) { /* Was a request, send response. */
4172 cp
->nego_status
= NS_PPR
;
4173 OUTL_DSP(np
, SCRIPTB_BA(np
, ppr_resp
));
4175 else /* Was a response, we are done. */
4176 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
4180 OUTL_DSP(np
, SCRIPTB_BA(np
, msg_bad
));
4184 * chip handler for WIDE DATA TRANSFER REQUEST (WDTR) message.
4187 sym_wide_nego_check(struct sym_hcb
*np
, int req
, struct sym_ccb
*cp
)
4189 int target
= cp
->target
;
4192 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4193 sym_print_nego_msg(np
, target
, "wide msgin", np
->msgin
);
4197 * Get requested values.
4200 wide
= np
->msgin
[3];
4203 * Check values against our limits.
4205 if (wide
> np
->maxwide
) {
4210 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4211 sym_print_addr(cp
->cmd
, "wdtr: wide=%d chg=%d.\n",
4216 * If it was an answer we want to change,
4217 * then it isn't acceptable. Reject it.
4225 sym_setwide (np
, target
, wide
);
4228 * It was an answer. We are done.
4234 * It was a request. Prepare an answer message.
4236 np
->msgout
[0] = M_EXTENDED
;
4238 np
->msgout
[2] = M_X_WIDE_REQ
;
4239 np
->msgout
[3] = wide
;
4241 np
->msgin
[0] = M_NOOP
;
4243 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4244 sym_print_nego_msg(np
, target
, "wide msgout", np
->msgout
);
4253 static void sym_wide_nego(struct sym_hcb
*np
, struct sym_tcb
*tp
, struct sym_ccb
*cp
)
4259 * Request or answer ?
4261 if (INB(np
, HS_PRT
) == HS_NEGOTIATE
) {
4262 OUTB(np
, HS_PRT
, HS_BUSY
);
4263 if (cp
->nego_status
&& cp
->nego_status
!= NS_WIDE
)
4269 * Check and apply new values.
4271 result
= sym_wide_nego_check(np
, req
, cp
);
4272 if (result
) /* Not acceptable, reject it */
4274 if (req
) { /* Was a request, send response. */
4275 cp
->nego_status
= NS_WIDE
;
4276 OUTL_DSP(np
, SCRIPTB_BA(np
, wdtr_resp
));
4277 } else { /* Was a response. */
4279 * Negotiate for SYNC immediately after WIDE response.
4280 * This allows to negotiate for both WIDE and SYNC on
4281 * a single SCSI command (Suggested by Justin Gibbs).
4283 if (tp
->tgoal
.offset
) {
4284 np
->msgout
[0] = M_EXTENDED
;
4286 np
->msgout
[2] = M_X_SYNC_REQ
;
4287 np
->msgout
[3] = tp
->tgoal
.period
;
4288 np
->msgout
[4] = tp
->tgoal
.offset
;
4290 if (DEBUG_FLAGS
& DEBUG_NEGO
) {
4291 sym_print_nego_msg(np
, cp
->target
,
4292 "sync msgout", np
->msgout
);
4295 cp
->nego_status
= NS_SYNC
;
4296 OUTB(np
, HS_PRT
, HS_NEGOTIATE
);
4297 OUTL_DSP(np
, SCRIPTB_BA(np
, sdtr_resp
));
4300 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
4306 OUTL_DSP(np
, SCRIPTB_BA(np
, msg_bad
));
4310 * Reset DT, SYNC or WIDE to default settings.
4312 * Called when a negotiation does not succeed either
4313 * on rejection or on protocol error.
4315 * A target that understands a PPR message should never
4316 * reject it, and messing with it is very unlikely.
4317 * So, if a PPR makes problems, we may just want to
4318 * try a legacy negotiation later.
4320 static void sym_nego_default(struct sym_hcb
*np
, struct sym_tcb
*tp
, struct sym_ccb
*cp
)
4322 switch (cp
->nego_status
) {
4325 sym_setpprot (np
, cp
->target
, 0, 0, 0, 0, 0, 0);
4327 if (tp
->tgoal
.period
< np
->minsync
)
4328 tp
->tgoal
.period
= np
->minsync
;
4329 if (tp
->tgoal
.offset
> np
->maxoffs
)
4330 tp
->tgoal
.offset
= np
->maxoffs
;
4331 tp
->tgoal
.iu
= tp
->tgoal
.dt
= tp
->tgoal
.qas
= 0;
4332 tp
->tgoal
.check_nego
= 1;
4336 sym_setsync (np
, cp
->target
, 0, 0, 0, 0);
4339 sym_setwide (np
, cp
->target
, 0);
4342 np
->msgin
[0] = M_NOOP
;
4343 np
->msgout
[0] = M_NOOP
;
4344 cp
->nego_status
= 0;
4348 * chip handler for MESSAGE REJECT received in response to
4349 * PPR, WIDE or SYNCHRONOUS negotiation.
4351 static void sym_nego_rejected(struct sym_hcb
*np
, struct sym_tcb
*tp
, struct sym_ccb
*cp
)
4353 sym_nego_default(np
, tp
, cp
);
4354 OUTB(np
, HS_PRT
, HS_BUSY
);
4358 * chip exception handler for programmed interrupts.
4360 static void sym_int_sir (struct sym_hcb
*np
)
4362 u_char num
= INB(np
, nc_dsps
);
4363 u32 dsa
= INL(np
, nc_dsa
);
4364 struct sym_ccb
*cp
= sym_ccb_from_dsa(np
, dsa
);
4365 u_char target
= INB(np
, nc_sdid
) & 0x0f;
4366 struct sym_tcb
*tp
= &np
->target
[target
];
4369 if (DEBUG_FLAGS
& DEBUG_TINY
) printf ("I#%d", num
);
4372 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
4374 * SCRIPTS tell us that we may have to update
4375 * 64 bit DMA segment registers.
4377 case SIR_DMAP_DIRTY
:
4378 sym_update_dmap_regs(np
);
4382 * Command has been completed with error condition
4383 * or has been auto-sensed.
4385 case SIR_COMPLETE_ERROR
:
4386 sym_complete_error(np
, cp
);
4389 * The C code is currently trying to recover from something.
4390 * Typically, user want to abort some command.
4392 case SIR_SCRIPT_STOPPED
:
4393 case SIR_TARGET_SELECTED
:
4394 case SIR_ABORT_SENT
:
4395 sym_sir_task_recovery(np
, num
);
4398 * The device didn't go to MSG OUT phase after having
4399 * been selected with ATN. We donnot want to handle
4402 case SIR_SEL_ATN_NO_MSG_OUT
:
4403 printf ("%s:%d: No MSG OUT phase after selection with ATN.\n",
4404 sym_name (np
), target
);
4407 * The device didn't switch to MSG IN phase after
4408 * having reseleted the initiator.
4410 case SIR_RESEL_NO_MSG_IN
:
4411 printf ("%s:%d: No MSG IN phase after reselection.\n",
4412 sym_name (np
), target
);
4415 * After reselection, the device sent a message that wasn't
4418 case SIR_RESEL_NO_IDENTIFY
:
4419 printf ("%s:%d: No IDENTIFY after reselection.\n",
4420 sym_name (np
), target
);
4423 * The device reselected a LUN we donnot know about.
4425 case SIR_RESEL_BAD_LUN
:
4426 np
->msgout
[0] = M_RESET
;
4429 * The device reselected for an untagged nexus and we
4432 case SIR_RESEL_BAD_I_T_L
:
4433 np
->msgout
[0] = M_ABORT
;
4436 * The device reselected for a tagged nexus that we donnot
4439 case SIR_RESEL_BAD_I_T_L_Q
:
4440 np
->msgout
[0] = M_ABORT_TAG
;
4443 * The SCRIPTS let us know that the device has grabbed
4444 * our message and will abort the job.
4446 case SIR_RESEL_ABORTED
:
4447 np
->lastmsg
= np
->msgout
[0];
4448 np
->msgout
[0] = M_NOOP
;
4449 printf ("%s:%d: message %x sent on bad reselection.\n",
4450 sym_name (np
), target
, np
->lastmsg
);
4453 * The SCRIPTS let us know that a message has been
4454 * successfully sent to the device.
4456 case SIR_MSG_OUT_DONE
:
4457 np
->lastmsg
= np
->msgout
[0];
4458 np
->msgout
[0] = M_NOOP
;
4459 /* Should we really care of that */
4460 if (np
->lastmsg
== M_PARITY
|| np
->lastmsg
== M_ID_ERROR
) {
4462 cp
->xerr_status
&= ~XE_PARITY_ERR
;
4463 if (!cp
->xerr_status
)
4464 OUTOFFB(np
, HF_PRT
, HF_EXT_ERR
);
4469 * The device didn't send a GOOD SCSI status.
4470 * We may have some work to do prior to allow
4471 * the SCRIPTS processor to continue.
4473 case SIR_BAD_SCSI_STATUS
:
4476 sym_sir_bad_scsi_status(np
, num
, cp
);
4479 * We are asked by the SCRIPTS to prepare a
4482 case SIR_REJECT_TO_SEND
:
4483 sym_print_msg(cp
, "M_REJECT to send for ", np
->msgin
);
4484 np
->msgout
[0] = M_REJECT
;
4487 * We have been ODD at the end of a DATA IN
4488 * transfer and the device didn't send a
4489 * IGNORE WIDE RESIDUE message.
4490 * It is a data overrun condition.
4492 case SIR_SWIDE_OVERRUN
:
4494 OUTONB(np
, HF_PRT
, HF_EXT_ERR
);
4495 cp
->xerr_status
|= XE_SWIDE_OVRUN
;
4499 * We have been ODD at the end of a DATA OUT
4501 * It is a data underrun condition.
4503 case SIR_SODL_UNDERRUN
:
4505 OUTONB(np
, HF_PRT
, HF_EXT_ERR
);
4506 cp
->xerr_status
|= XE_SODL_UNRUN
;
4510 * The device wants us to tranfer more data than
4511 * expected or in the wrong direction.
4512 * The number of extra bytes is in scratcha.
4513 * It is a data overrun condition.
4515 case SIR_DATA_OVERRUN
:
4517 OUTONB(np
, HF_PRT
, HF_EXT_ERR
);
4518 cp
->xerr_status
|= XE_EXTRA_DATA
;
4519 cp
->extra_bytes
+= INL(np
, nc_scratcha
);
4523 * The device switched to an illegal phase (4/5).
4527 OUTONB(np
, HF_PRT
, HF_EXT_ERR
);
4528 cp
->xerr_status
|= XE_BAD_PHASE
;
4532 * We received a message.
4534 case SIR_MSG_RECEIVED
:
4537 switch (np
->msgin
[0]) {
4539 * We received an extended message.
4540 * We handle MODIFY DATA POINTER, SDTR, WDTR
4541 * and reject all other extended messages.
4544 switch (np
->msgin
[2]) {
4546 if (DEBUG_FLAGS
& DEBUG_POINTER
)
4547 sym_print_msg(cp
,"modify DP",np
->msgin
);
4548 tmp
= (np
->msgin
[3]<<24) + (np
->msgin
[4]<<16) +
4549 (np
->msgin
[5]<<8) + (np
->msgin
[6]);
4550 sym_modify_dp(np
, tp
, cp
, tmp
);
4553 sym_sync_nego(np
, tp
, cp
);
4556 sym_ppr_nego(np
, tp
, cp
);
4559 sym_wide_nego(np
, tp
, cp
);
4566 * We received a 1/2 byte message not handled from SCRIPTS.
4567 * We are only expecting MESSAGE REJECT and IGNORE WIDE
4568 * RESIDUE messages that haven't been anticipated by
4569 * SCRIPTS on SWIDE full condition. Unanticipated IGNORE
4570 * WIDE RESIDUE messages are aliased as MODIFY DP (-1).
4573 if (DEBUG_FLAGS
& DEBUG_POINTER
)
4574 sym_print_msg(cp
,"ign wide residue", np
->msgin
);
4575 if (cp
->host_flags
& HF_SENSE
)
4576 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
4578 sym_modify_dp(np
, tp
, cp
, -1);
4581 if (INB(np
, HS_PRT
) == HS_NEGOTIATE
)
4582 sym_nego_rejected(np
, tp
, cp
);
4584 sym_print_addr(cp
->cmd
,
4585 "M_REJECT received (%x:%x).\n",
4586 scr_to_cpu(np
->lastmsg
), np
->msgout
[0]);
4595 * We received an unknown message.
4596 * Ignore all MSG IN phases and reject it.
4599 sym_print_msg(cp
, "WEIRD message received", np
->msgin
);
4600 OUTL_DSP(np
, SCRIPTB_BA(np
, msg_weird
));
4603 * Negotiation failed.
4604 * Target does not send us the reply.
4605 * Remove the HS_NEGOTIATE status.
4607 case SIR_NEGO_FAILED
:
4608 OUTB(np
, HS_PRT
, HS_BUSY
);
4610 * Negotiation failed.
4611 * Target does not want answer message.
4613 case SIR_NEGO_PROTO
:
4614 sym_nego_default(np
, tp
, cp
);
4622 OUTL_DSP(np
, SCRIPTB_BA(np
, msg_bad
));
4625 OUTL_DSP(np
, SCRIPTA_BA(np
, clrack
));
4632 * Acquire a control block
4634 struct sym_ccb
*sym_get_ccb (struct sym_hcb
*np
, struct scsi_cmnd
*cmd
, u_char tag_order
)
4636 u_char tn
= cmd
->device
->id
;
4637 u_char ln
= cmd
->device
->lun
;
4638 struct sym_tcb
*tp
= &np
->target
[tn
];
4639 struct sym_lcb
*lp
= sym_lp(tp
, ln
);
4640 u_short tag
= NO_TAG
;
4642 struct sym_ccb
*cp
= NULL
;
4645 * Look for a free CCB
4647 if (sym_que_empty(&np
->free_ccbq
))
4649 qp
= sym_remque_head(&np
->free_ccbq
);
4652 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
4654 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4656 * If the LCB is not yet available and the LUN
4657 * has been probed ok, try to allocate the LCB.
4659 if (!lp
&& sym_is_bit(tp
->lun_map
, ln
)) {
4660 lp
= sym_alloc_lcb(np
, tn
, ln
);
4667 * If the LCB is not available here, then the
4668 * logical unit is not yet discovered. For those
4669 * ones only accept 1 SCSI IO per logical unit,
4670 * since we cannot allow disconnections.
4673 if (!sym_is_bit(tp
->busy0_map
, ln
))
4674 sym_set_bit(tp
->busy0_map
, ln
);
4679 * If we have been asked for a tagged command.
4683 * Debugging purpose.
4685 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4686 assert(lp
->busy_itl
== 0);
4689 * Allocate resources for tags if not yet.
4692 sym_alloc_lcb_tags(np
, tn
, ln
);
4697 * Get a tag for this SCSI IO and set up
4698 * the CCB bus address for reselection,
4699 * and count it for this LUN.
4700 * Toggle reselect path to tagged.
4702 if (lp
->busy_itlq
< SYM_CONF_MAX_TASK
) {
4703 tag
= lp
->cb_tags
[lp
->ia_tag
];
4704 if (++lp
->ia_tag
== SYM_CONF_MAX_TASK
)
4707 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4708 lp
->itlq_tbl
[tag
] = cpu_to_scr(cp
->ccb_ba
);
4710 cpu_to_scr(SCRIPTA_BA(np
, resel_tag
));
4712 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
4713 cp
->tags_si
= lp
->tags_si
;
4714 ++lp
->tags_sum
[cp
->tags_si
];
4722 * This command will not be tagged.
4723 * If we already have either a tagged or untagged
4724 * one, refuse to overlap this untagged one.
4728 * Debugging purpose.
4730 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4731 assert(lp
->busy_itl
== 0 && lp
->busy_itlq
== 0);
4734 * Count this nexus for this LUN.
4735 * Set up the CCB bus address for reselection.
4736 * Toggle reselect path to untagged.
4739 #ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4740 if (lp
->busy_itl
== 1) {
4741 lp
->head
.itl_task_sa
= cpu_to_scr(cp
->ccb_ba
);
4743 cpu_to_scr(SCRIPTA_BA(np
, resel_no_tag
));
4751 * Put the CCB into the busy queue.
4753 sym_insque_tail(&cp
->link_ccbq
, &np
->busy_ccbq
);
4754 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
4756 sym_remque(&cp
->link2_ccbq
);
4757 sym_insque_tail(&cp
->link2_ccbq
, &lp
->waiting_ccbq
);
4762 * Remember all informations needed to free this CCB.
4766 cp
->order
= tag_order
;
4770 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
4771 sym_print_addr(cmd
, "ccb @%p using tag %d.\n", cp
, tag
);
4777 sym_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
4782 * Release one control block
4784 void sym_free_ccb (struct sym_hcb
*np
, struct sym_ccb
*cp
)
4786 struct sym_tcb
*tp
= &np
->target
[cp
->target
];
4787 struct sym_lcb
*lp
= sym_lp(tp
, cp
->lun
);
4789 if (DEBUG_FLAGS
& DEBUG_TAGS
) {
4790 sym_print_addr(cp
->cmd
, "ccb @%p freeing tag %d.\n",
4799 * If tagged, release the tag, set the relect path
4801 if (cp
->tag
!= NO_TAG
) {
4802 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
4803 --lp
->tags_sum
[cp
->tags_si
];
4806 * Free the tag value.
4808 lp
->cb_tags
[lp
->if_tag
] = cp
->tag
;
4809 if (++lp
->if_tag
== SYM_CONF_MAX_TASK
)
4812 * Make the reselect path invalid,
4813 * and uncount this CCB.
4815 lp
->itlq_tbl
[cp
->tag
] = cpu_to_scr(np
->bad_itlq_ba
);
4817 } else { /* Untagged */
4819 * Make the reselect path invalid,
4820 * and uncount this CCB.
4822 lp
->head
.itl_task_sa
= cpu_to_scr(np
->bad_itl_ba
);
4826 * If no JOB active, make the LUN reselect path invalid.
4828 if (lp
->busy_itlq
== 0 && lp
->busy_itl
== 0)
4830 cpu_to_scr(SCRIPTB_BA(np
, resel_bad_lun
));
4833 * Otherwise, we only accept 1 IO per LUN.
4834 * Clear the bit that keeps track of this IO.
4837 sym_clr_bit(tp
->busy0_map
, cp
->lun
);
4840 * We donnot queue more than 1 ccb per target
4841 * with negotiation at any time. If this ccb was
4842 * used for negotiation, clear this info in the tcb.
4844 if (cp
== tp
->nego_cp
)
4847 #ifdef SYM_CONF_IARB_SUPPORT
4849 * If we just complete the last queued CCB,
4850 * clear this info that is no longer relevant.
4852 if (cp
== np
->last_cp
)
4857 * Make this CCB available.
4860 cp
->host_status
= HS_IDLE
;
4861 sym_remque(&cp
->link_ccbq
);
4862 sym_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
4864 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
4866 sym_remque(&cp
->link2_ccbq
);
4867 sym_insque_tail(&cp
->link2_ccbq
, &np
->dummy_ccbq
);
4869 if (cp
->tag
!= NO_TAG
)
4872 --lp
->started_no_tag
;
4880 * Allocate a CCB from memory and initialize its fixed part.
4882 static struct sym_ccb
*sym_alloc_ccb(struct sym_hcb
*np
)
4884 struct sym_ccb
*cp
= NULL
;
4888 * Prevent from allocating more CCBs than we can
4889 * queue to the controller.
4891 if (np
->actccbs
>= SYM_CONF_MAX_START
)
4895 * Allocate memory for this CCB.
4897 cp
= sym_calloc_dma(sizeof(struct sym_ccb
), "CCB");
4907 * Compute the bus address of this ccb.
4909 cp
->ccb_ba
= vtobus(cp
);
4912 * Insert this ccb into the hashed list.
4914 hcode
= CCB_HASH_CODE(cp
->ccb_ba
);
4915 cp
->link_ccbh
= np
->ccbh
[hcode
];
4916 np
->ccbh
[hcode
] = cp
;
4919 * Initialyze the start and restart actions.
4921 cp
->phys
.head
.go
.start
= cpu_to_scr(SCRIPTA_BA(np
, idle
));
4922 cp
->phys
.head
.go
.restart
= cpu_to_scr(SCRIPTB_BA(np
, bad_i_t_l
));
4925 * Initilialyze some other fields.
4927 cp
->phys
.smsg_ext
.addr
= cpu_to_scr(HCB_BA(np
, msgin
[2]));
4930 * Chain into free ccb queue.
4932 sym_insque_head(&cp
->link_ccbq
, &np
->free_ccbq
);
4935 * Chain into optionnal lists.
4937 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
4938 sym_insque_head(&cp
->link2_ccbq
, &np
->dummy_ccbq
);
4943 sym_mfree_dma(cp
, sizeof(*cp
), "CCB");
4948 * Look up a CCB from a DSA value.
4950 static struct sym_ccb
*sym_ccb_from_dsa(struct sym_hcb
*np
, u32 dsa
)
4955 hcode
= CCB_HASH_CODE(dsa
);
4956 cp
= np
->ccbh
[hcode
];
4958 if (cp
->ccb_ba
== dsa
)
4967 * Target control block initialisation.
4968 * Nothing important to do at the moment.
4970 static void sym_init_tcb (struct sym_hcb
*np
, u_char tn
)
4972 #if 0 /* Hmmm... this checking looks paranoid. */
4974 * Check some alignments required by the chip.
4976 assert (((offsetof(struct sym_reg
, nc_sxfer
) ^
4977 offsetof(struct sym_tcb
, head
.sval
)) &3) == 0);
4978 assert (((offsetof(struct sym_reg
, nc_scntl3
) ^
4979 offsetof(struct sym_tcb
, head
.wval
)) &3) == 0);
4984 * Lun control block allocation and initialization.
4986 struct sym_lcb
*sym_alloc_lcb (struct sym_hcb
*np
, u_char tn
, u_char ln
)
4988 struct sym_tcb
*tp
= &np
->target
[tn
];
4989 struct sym_lcb
*lp
= sym_lp(tp
, ln
);
4992 * Already done, just return.
4998 * Donnot allow LUN control block
4999 * allocation for not probed LUNs.
5001 if (!sym_is_bit(tp
->lun_map
, ln
))
5005 * Initialize the target control block if not yet.
5007 sym_init_tcb (np
, tn
);
5010 * Allocate the LCB bus address array.
5011 * Compute the bus address of this table.
5013 if (ln
&& !tp
->luntbl
) {
5016 tp
->luntbl
= sym_calloc_dma(256, "LUNTBL");
5019 for (i
= 0 ; i
< 64 ; i
++)
5020 tp
->luntbl
[i
] = cpu_to_scr(vtobus(&np
->badlun_sa
));
5021 tp
->head
.luntbl_sa
= cpu_to_scr(vtobus(tp
->luntbl
));
5025 * Allocate the table of pointers for LUN(s) > 0, if needed.
5027 if (ln
&& !tp
->lunmp
) {
5028 tp
->lunmp
= kcalloc(SYM_CONF_MAX_LUN
, sizeof(struct sym_lcb
*),
5036 * Make it available to the chip.
5038 lp
= sym_calloc_dma(sizeof(struct sym_lcb
), "LCB");
5043 tp
->luntbl
[ln
] = cpu_to_scr(vtobus(lp
));
5047 tp
->head
.lun0_sa
= cpu_to_scr(vtobus(lp
));
5051 * Let the itl task point to error handling.
5053 lp
->head
.itl_task_sa
= cpu_to_scr(np
->bad_itl_ba
);
5056 * Set the reselect pattern to our default. :)
5058 lp
->head
.resel_sa
= cpu_to_scr(SCRIPTB_BA(np
, resel_bad_lun
));
5061 * Set user capabilities.
5063 lp
->user_flags
= tp
->usrflags
& (SYM_DISC_ENABLED
| SYM_TAGS_ENABLED
);
5065 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5067 * Initialize device queueing.
5069 sym_que_init(&lp
->waiting_ccbq
);
5070 sym_que_init(&lp
->started_ccbq
);
5071 lp
->started_max
= SYM_CONF_MAX_TASK
;
5072 lp
->started_limit
= SYM_CONF_MAX_TASK
;
5075 * If we are busy, count the IO.
5077 if (sym_is_bit(tp
->busy0_map
, ln
)) {
5079 sym_clr_bit(tp
->busy0_map
, ln
);
5086 * Allocate LCB resources for tagged command queuing.
5088 static void sym_alloc_lcb_tags (struct sym_hcb
*np
, u_char tn
, u_char ln
)
5090 struct sym_tcb
*tp
= &np
->target
[tn
];
5091 struct sym_lcb
*lp
= sym_lp(tp
, ln
);
5095 * If LCB not available, try to allocate it.
5097 if (!lp
&& !(lp
= sym_alloc_lcb(np
, tn
, ln
)))
5101 * Allocate the task table and and the tag allocation
5102 * circular buffer. We want both or none.
5104 lp
->itlq_tbl
= sym_calloc_dma(SYM_CONF_MAX_TASK
*4, "ITLQ_TBL");
5107 lp
->cb_tags
= kcalloc(SYM_CONF_MAX_TASK
, 1, GFP_KERNEL
);
5109 sym_mfree_dma(lp
->itlq_tbl
, SYM_CONF_MAX_TASK
*4, "ITLQ_TBL");
5110 lp
->itlq_tbl
= NULL
;
5115 * Initialize the task table with invalid entries.
5117 for (i
= 0 ; i
< SYM_CONF_MAX_TASK
; i
++)
5118 lp
->itlq_tbl
[i
] = cpu_to_scr(np
->notask_ba
);
5121 * Fill up the tag buffer with tag numbers.
5123 for (i
= 0 ; i
< SYM_CONF_MAX_TASK
; i
++)
5127 * Make the task table available to SCRIPTS,
5128 * And accept tagged commands now.
5130 lp
->head
.itlq_tbl_sa
= cpu_to_scr(vtobus(lp
->itlq_tbl
));
5138 * Queue a SCSI IO to the controller.
5140 int sym_queue_scsiio(struct sym_hcb
*np
, struct scsi_cmnd
*cmd
, struct sym_ccb
*cp
)
5142 struct scsi_device
*sdev
= cmd
->device
;
5150 * Keep track of the IO in our CCB.
5155 * Retrieve the target descriptor.
5157 tp
= &np
->target
[cp
->target
];
5160 * Retrieve the lun descriptor.
5162 lp
= sym_lp(tp
, sdev
->lun
);
5164 can_disconnect
= (cp
->tag
!= NO_TAG
) ||
5165 (lp
&& (lp
->curr_flags
& SYM_DISC_ENABLED
));
5167 msgptr
= cp
->scsi_smsg
;
5169 msgptr
[msglen
++] = IDENTIFY(can_disconnect
, sdev
->lun
);
5172 * Build the tag message if present.
5174 if (cp
->tag
!= NO_TAG
) {
5175 u_char order
= cp
->order
;
5183 order
= M_SIMPLE_TAG
;
5185 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
5187 * Avoid too much reordering of SCSI commands.
5188 * The algorithm tries to prevent completion of any
5189 * tagged command from being delayed against more
5190 * than 3 times the max number of queued commands.
5192 if (lp
&& lp
->tags_since
> 3*SYM_CONF_MAX_TAG
) {
5193 lp
->tags_si
= !(lp
->tags_si
);
5194 if (lp
->tags_sum
[lp
->tags_si
]) {
5195 order
= M_ORDERED_TAG
;
5196 if ((DEBUG_FLAGS
& DEBUG_TAGS
)||sym_verbose
>1) {
5198 "ordered tag forced.\n");
5204 msgptr
[msglen
++] = order
;
5207 * For less than 128 tags, actual tags are numbered
5208 * 1,3,5,..2*MAXTAGS+1,since we may have to deal
5209 * with devices that have problems with #TAG 0 or too
5210 * great #TAG numbers. For more tags (up to 256),
5211 * we use directly our tag number.
5213 #if SYM_CONF_MAX_TASK > (512/4)
5214 msgptr
[msglen
++] = cp
->tag
;
5216 msgptr
[msglen
++] = (cp
->tag
<< 1) + 1;
5221 * Build a negotiation message if needed.
5222 * (nego_status is filled by sym_prepare_nego())
5224 cp
->nego_status
= 0;
5225 if (tp
->tgoal
.check_nego
&& !tp
->nego_cp
&& lp
) {
5226 msglen
+= sym_prepare_nego(np
, cp
, msgptr
+ msglen
);
5232 cp
->phys
.head
.go
.start
= cpu_to_scr(SCRIPTA_BA(np
, select
));
5233 cp
->phys
.head
.go
.restart
= cpu_to_scr(SCRIPTA_BA(np
, resel_dsa
));
5238 cp
->phys
.select
.sel_id
= cp
->target
;
5239 cp
->phys
.select
.sel_scntl3
= tp
->head
.wval
;
5240 cp
->phys
.select
.sel_sxfer
= tp
->head
.sval
;
5241 cp
->phys
.select
.sel_scntl4
= tp
->head
.uval
;
5246 cp
->phys
.smsg
.addr
= cpu_to_scr(CCB_BA(cp
, scsi_smsg
));
5247 cp
->phys
.smsg
.size
= cpu_to_scr(msglen
);
5252 cp
->host_xflags
= 0;
5253 cp
->host_status
= cp
->nego_status
? HS_NEGOTIATE
: HS_BUSY
;
5254 cp
->ssss_status
= S_ILLEGAL
;
5255 cp
->xerr_status
= 0;
5257 cp
->extra_bytes
= 0;
5260 * extreme data pointer.
5261 * shall be positive, so -1 is lower than lowest.:)
5267 * Build the CDB and DATA descriptor block
5270 return sym_setup_data_and_start(np
, cmd
, cp
);
5274 * Reset a SCSI target (all LUNs of this target).
5276 int sym_reset_scsi_target(struct sym_hcb
*np
, int target
)
5280 if (target
== np
->myaddr
|| (u_int
)target
>= SYM_CONF_MAX_TARGET
)
5283 tp
= &np
->target
[target
];
5286 np
->istat_sem
= SEM
;
5287 OUTB(np
, nc_istat
, SIGP
|SEM
);
5295 static int sym_abort_ccb(struct sym_hcb
*np
, struct sym_ccb
*cp
, int timed_out
)
5298 * Check that the IO is active.
5300 if (!cp
|| !cp
->host_status
|| cp
->host_status
== HS_WAIT
)
5304 * If a previous abort didn't succeed in time,
5305 * perform a BUS reset.
5308 sym_reset_scsi_bus(np
, 1);
5313 * Mark the CCB for abort and allow time for.
5315 cp
->to_abort
= timed_out
? 2 : 1;
5318 * Tell the SCRIPTS processor to stop and synchronize with us.
5320 np
->istat_sem
= SEM
;
5321 OUTB(np
, nc_istat
, SIGP
|SEM
);
5325 int sym_abort_scsiio(struct sym_hcb
*np
, struct scsi_cmnd
*cmd
, int timed_out
)
5331 * Look up our CCB control block.
5334 FOR_EACH_QUEUED_ELEMENT(&np
->busy_ccbq
, qp
) {
5335 struct sym_ccb
*cp2
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
5336 if (cp2
->cmd
== cmd
) {
5342 return sym_abort_ccb(np
, cp
, timed_out
);
5346 * Complete execution of a SCSI command with extented
5347 * error, SCSI status error, or having been auto-sensed.
5349 * The SCRIPTS processor is not running there, so we
5350 * can safely access IO registers and remove JOBs from
5352 * SCRATCHA is assumed to have been loaded with STARTPOS
5353 * before the SCRIPTS called the C code.
5355 void sym_complete_error(struct sym_hcb
*np
, struct sym_ccb
*cp
)
5357 struct scsi_device
*sdev
;
5358 struct scsi_cmnd
*cmd
;
5365 * Paranoid check. :)
5367 if (!cp
|| !cp
->cmd
)
5372 if (DEBUG_FLAGS
& (DEBUG_TINY
|DEBUG_RESULT
)) {
5373 dev_info(&sdev
->sdev_gendev
, "CCB=%p STAT=%x/%x/%x\n", cp
,
5374 cp
->host_status
, cp
->ssss_status
, cp
->host_flags
);
5378 * Get target and lun pointers.
5380 tp
= &np
->target
[cp
->target
];
5381 lp
= sym_lp(tp
, sdev
->lun
);
5384 * Check for extended errors.
5386 if (cp
->xerr_status
) {
5388 sym_print_xerr(cmd
, cp
->xerr_status
);
5389 if (cp
->host_status
== HS_COMPLETE
)
5390 cp
->host_status
= HS_COMP_ERR
;
5394 * Calculate the residual.
5396 resid
= sym_compute_residual(np
, cp
);
5398 if (!SYM_SETUP_RESIDUAL_SUPPORT
) {/* If user does not want residuals */
5399 resid
= 0; /* throw them away. :) */
5404 printf("XXXX RESID= %d - 0x%x\n", resid
, resid
);
5408 * Dequeue all queued CCBs for that device
5409 * not yet started by SCRIPTS.
5411 i
= (INL(np
, nc_scratcha
) - np
->squeue_ba
) / 4;
5412 i
= sym_dequeue_from_squeue(np
, i
, cp
->target
, sdev
->lun
, -1);
5415 * Restart the SCRIPTS processor.
5417 OUTL_DSP(np
, SCRIPTA_BA(np
, start
));
5419 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5420 if (cp
->host_status
== HS_COMPLETE
&&
5421 cp
->ssss_status
== S_QUEUE_FULL
) {
5422 if (!lp
|| lp
->started_tags
- i
< 2)
5425 * Decrease queue depth as needed.
5427 lp
->started_max
= lp
->started_tags
- i
- 1;
5430 if (sym_verbose
>= 2) {
5431 sym_print_addr(cmd
, " queue depth is now %d\n",
5438 cp
->host_status
= HS_BUSY
;
5439 cp
->ssss_status
= S_ILLEGAL
;
5442 * Let's requeue it to device.
5444 sym_set_cam_status(cmd
, CAM_REQUEUE_REQ
);
5450 * Build result in CAM ccb.
5452 sym_set_cam_result_error(np
, cp
, resid
);
5454 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5458 * Add this one to the COMP queue.
5460 sym_remque(&cp
->link_ccbq
);
5461 sym_insque_head(&cp
->link_ccbq
, &np
->comp_ccbq
);
5464 * Complete all those commands with either error
5465 * or requeue condition.
5467 sym_flush_comp_queue(np
, 0);
5469 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5471 * Donnot start more than 1 command after an error.
5474 sym_start_next_ccbs(np
, lp
, 1);
5479 * Complete execution of a successful SCSI command.
5481 * Only successful commands go to the DONE queue,
5482 * since we need to have the SCRIPTS processor
5483 * stopped on any error condition.
5484 * The SCRIPTS processor is running while we are
5485 * completing successful commands.
5487 void sym_complete_ok (struct sym_hcb
*np
, struct sym_ccb
*cp
)
5491 struct scsi_cmnd
*cmd
;
5495 * Paranoid check. :)
5497 if (!cp
|| !cp
->cmd
)
5499 assert (cp
->host_status
== HS_COMPLETE
);
5507 * Get target and lun pointers.
5509 tp
= &np
->target
[cp
->target
];
5510 lp
= sym_lp(tp
, cp
->lun
);
5513 * Assume device discovered on first success.
5516 sym_set_bit(tp
->lun_map
, cp
->lun
);
5519 * If all data have been transferred, given than no
5520 * extended error did occur, there is no residual.
5523 if (cp
->phys
.head
.lastp
!= sym_goalp(cp
))
5524 resid
= sym_compute_residual(np
, cp
);
5527 * Wrong transfer residuals may be worse than just always
5528 * returning zero. User can disable this feature in
5529 * sym53c8xx.h. Residual support is enabled by default.
5531 if (!SYM_SETUP_RESIDUAL_SUPPORT
)
5535 printf("XXXX RESID= %d - 0x%x\n", resid
, resid
);
5539 * Build result in CAM ccb.
5541 sym_set_cam_result_ok(cp
, cmd
, resid
);
5543 #ifdef SYM_OPT_SNIFF_INQUIRY
5545 * On standard INQUIRY response (EVPD and CmDt
5546 * not set), sniff out device capabilities.
5548 if (cp
->cdb_buf
[0] == INQUIRY
&& !(cp
->cdb_buf
[1] & 0x3))
5549 sym_sniff_inquiry(np
, cmd
, resid
);
5552 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5554 * If max number of started ccbs had been reduced,
5555 * increase it if 200 good status received.
5557 if (lp
&& lp
->started_max
< lp
->started_limit
) {
5559 if (lp
->num_sgood
>= 200) {
5562 if (sym_verbose
>= 2) {
5563 sym_print_addr(cmd
, " queue depth is now %d\n",
5573 sym_free_ccb (np
, cp
);
5575 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5577 * Requeue a couple of awaiting scsi commands.
5579 if (lp
&& !sym_que_empty(&lp
->waiting_ccbq
))
5580 sym_start_next_ccbs(np
, lp
, 2);
5583 * Complete the command.
5585 sym_xpt_done(np
, cmd
);
5589 * Soft-attach the controller.
5591 int sym_hcb_attach(struct Scsi_Host
*shost
, struct sym_fw
*fw
, struct sym_nvram
*nvram
)
5593 struct sym_hcb
*np
= sym_get_hcb(shost
);
5597 * Get some info about the firmware.
5599 np
->scripta_sz
= fw
->a_size
;
5600 np
->scriptb_sz
= fw
->b_size
;
5601 np
->scriptz_sz
= fw
->z_size
;
5602 np
->fw_setup
= fw
->setup
;
5603 np
->fw_patch
= fw
->patch
;
5604 np
->fw_name
= fw
->name
;
5607 * Save setting of some IO registers, so we will
5608 * be able to probe specific implementations.
5610 sym_save_initial_setting (np
);
5613 * Reset the chip now, since it has been reported
5614 * that SCSI clock calibration may not work properly
5615 * if the chip is currently active.
5620 * Prepare controller and devices settings, according
5621 * to chip features, user set-up and driver set-up.
5623 sym_prepare_setting(shost
, np
, nvram
);
5626 * Check the PCI clock frequency.
5627 * Must be performed after prepare_setting since it destroys
5628 * STEST1 that is used to probe for the clock doubler.
5630 i
= sym_getpciclock(np
);
5631 if (i
> 37000 && !(np
->features
& FE_66MHZ
))
5632 printf("%s: PCI BUS clock seems too high: %u KHz.\n",
5636 * Allocate the start queue.
5638 np
->squeue
= sym_calloc_dma(sizeof(u32
)*(MAX_QUEUE
*2),"SQUEUE");
5641 np
->squeue_ba
= vtobus(np
->squeue
);
5644 * Allocate the done queue.
5646 np
->dqueue
= sym_calloc_dma(sizeof(u32
)*(MAX_QUEUE
*2),"DQUEUE");
5649 np
->dqueue_ba
= vtobus(np
->dqueue
);
5652 * Allocate the target bus address array.
5654 np
->targtbl
= sym_calloc_dma(256, "TARGTBL");
5657 np
->targtbl_ba
= vtobus(np
->targtbl
);
5660 * Allocate SCRIPTS areas.
5662 np
->scripta0
= sym_calloc_dma(np
->scripta_sz
, "SCRIPTA0");
5663 np
->scriptb0
= sym_calloc_dma(np
->scriptb_sz
, "SCRIPTB0");
5664 np
->scriptz0
= sym_calloc_dma(np
->scriptz_sz
, "SCRIPTZ0");
5665 if (!np
->scripta0
|| !np
->scriptb0
|| !np
->scriptz0
)
5669 * Allocate the array of lists of CCBs hashed by DSA.
5671 np
->ccbh
= kcalloc(sizeof(struct sym_ccb
**), CCB_HASH_SIZE
, GFP_KERNEL
);
5676 * Initialyze the CCB free and busy queues.
5678 sym_que_init(&np
->free_ccbq
);
5679 sym_que_init(&np
->busy_ccbq
);
5680 sym_que_init(&np
->comp_ccbq
);
5683 * Initialization for optional handling
5684 * of device queueing.
5686 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
5687 sym_que_init(&np
->dummy_ccbq
);
5690 * Allocate some CCB. We need at least ONE.
5692 if (!sym_alloc_ccb(np
))
5696 * Calculate BUS addresses where we are going
5697 * to load the SCRIPTS.
5699 np
->scripta_ba
= vtobus(np
->scripta0
);
5700 np
->scriptb_ba
= vtobus(np
->scriptb0
);
5701 np
->scriptz_ba
= vtobus(np
->scriptz0
);
5704 np
->scripta_ba
= np
->ram_ba
;
5705 if (np
->features
& FE_RAM8K
) {
5707 np
->scriptb_ba
= np
->scripta_ba
+ 4096;
5708 #if 0 /* May get useful for 64 BIT PCI addressing */
5709 np
->scr_ram_seg
= cpu_to_scr(np
->scripta_ba
>> 32);
5717 * Copy scripts to controller instance.
5719 memcpy(np
->scripta0
, fw
->a_base
, np
->scripta_sz
);
5720 memcpy(np
->scriptb0
, fw
->b_base
, np
->scriptb_sz
);
5721 memcpy(np
->scriptz0
, fw
->z_base
, np
->scriptz_sz
);
5724 * Setup variable parts in scripts and compute
5725 * scripts bus addresses used from the C code.
5727 np
->fw_setup(np
, fw
);
5730 * Bind SCRIPTS with physical addresses usable by the
5731 * SCRIPTS processor (as seen from the BUS = BUS addresses).
5733 sym_fw_bind_script(np
, (u32
*) np
->scripta0
, np
->scripta_sz
);
5734 sym_fw_bind_script(np
, (u32
*) np
->scriptb0
, np
->scriptb_sz
);
5735 sym_fw_bind_script(np
, (u32
*) np
->scriptz0
, np
->scriptz_sz
);
5737 #ifdef SYM_CONF_IARB_SUPPORT
5739 * If user wants IARB to be set when we win arbitration
5740 * and have other jobs, compute the max number of consecutive
5741 * settings of IARB hints before we leave devices a chance to
5742 * arbitrate for reselection.
5744 #ifdef SYM_SETUP_IARB_MAX
5745 np
->iarb_max
= SYM_SETUP_IARB_MAX
;
5752 * Prepare the idle and invalid task actions.
5754 np
->idletask
.start
= cpu_to_scr(SCRIPTA_BA(np
, idle
));
5755 np
->idletask
.restart
= cpu_to_scr(SCRIPTB_BA(np
, bad_i_t_l
));
5756 np
->idletask_ba
= vtobus(&np
->idletask
);
5758 np
->notask
.start
= cpu_to_scr(SCRIPTA_BA(np
, idle
));
5759 np
->notask
.restart
= cpu_to_scr(SCRIPTB_BA(np
, bad_i_t_l
));
5760 np
->notask_ba
= vtobus(&np
->notask
);
5762 np
->bad_itl
.start
= cpu_to_scr(SCRIPTA_BA(np
, idle
));
5763 np
->bad_itl
.restart
= cpu_to_scr(SCRIPTB_BA(np
, bad_i_t_l
));
5764 np
->bad_itl_ba
= vtobus(&np
->bad_itl
);
5766 np
->bad_itlq
.start
= cpu_to_scr(SCRIPTA_BA(np
, idle
));
5767 np
->bad_itlq
.restart
= cpu_to_scr(SCRIPTB_BA(np
,bad_i_t_l_q
));
5768 np
->bad_itlq_ba
= vtobus(&np
->bad_itlq
);
5771 * Allocate and prepare the lun JUMP table that is used
5772 * for a target prior the probing of devices (bad lun table).
5773 * A private table will be allocated for the target on the
5774 * first INQUIRY response received.
5776 np
->badluntbl
= sym_calloc_dma(256, "BADLUNTBL");
5780 np
->badlun_sa
= cpu_to_scr(SCRIPTB_BA(np
, resel_bad_lun
));
5781 for (i
= 0 ; i
< 64 ; i
++) /* 64 luns/target, no less */
5782 np
->badluntbl
[i
] = cpu_to_scr(vtobus(&np
->badlun_sa
));
5785 * Prepare the bus address array that contains the bus
5786 * address of each target control block.
5787 * For now, assume all logical units are wrong. :)
5789 for (i
= 0 ; i
< SYM_CONF_MAX_TARGET
; i
++) {
5790 np
->targtbl
[i
] = cpu_to_scr(vtobus(&np
->target
[i
]));
5791 np
->target
[i
].head
.luntbl_sa
=
5792 cpu_to_scr(vtobus(np
->badluntbl
));
5793 np
->target
[i
].head
.lun0_sa
=
5794 cpu_to_scr(vtobus(&np
->badlun_sa
));
5798 * Now check the cache handling of the pci chipset.
5800 if (sym_snooptest (np
)) {
5801 printf("%s: CACHE INCORRECTLY CONFIGURED.\n", sym_name(np
));
5806 * Sigh! we are done.
5815 * Free everything that has been allocated for this device.
5817 void sym_hcb_free(struct sym_hcb
*np
)
5826 sym_mfree_dma(np
->scriptz0
, np
->scriptz_sz
, "SCRIPTZ0");
5828 sym_mfree_dma(np
->scriptb0
, np
->scriptb_sz
, "SCRIPTB0");
5830 sym_mfree_dma(np
->scripta0
, np
->scripta_sz
, "SCRIPTA0");
5832 sym_mfree_dma(np
->squeue
, sizeof(u32
)*(MAX_QUEUE
*2), "SQUEUE");
5834 sym_mfree_dma(np
->dqueue
, sizeof(u32
)*(MAX_QUEUE
*2), "DQUEUE");
5837 while ((qp
= sym_remque_head(&np
->free_ccbq
)) != 0) {
5838 cp
= sym_que_entry(qp
, struct sym_ccb
, link_ccbq
);
5839 sym_mfree_dma(cp
, sizeof(*cp
), "CCB");
5845 sym_mfree_dma(np
->badluntbl
, 256,"BADLUNTBL");
5847 for (target
= 0; target
< SYM_CONF_MAX_TARGET
; target
++) {
5848 tp
= &np
->target
[target
];
5849 for (lun
= 0 ; lun
< SYM_CONF_MAX_LUN
; lun
++) {
5850 lp
= sym_lp(tp
, lun
);
5854 sym_mfree_dma(lp
->itlq_tbl
, SYM_CONF_MAX_TASK
*4,
5857 sym_mfree_dma(lp
, sizeof(*lp
), "LCB");
5859 #if SYM_CONF_MAX_LUN > 1
5864 sym_mfree_dma(np
->targtbl
, 256, "TARGTBL");