2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
7 * This driver is derived from the Linux sym53c8xx driver.
8 * Copyright (C) 1998-2000 Gerard Roudier
10 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
11 * a port of the FreeBSD ncr driver to Linux-1.2.13.
13 * The original ncr driver has been written for 386bsd and FreeBSD by
14 * Wolfgang Stanglmeier <wolf@cologne.de>
15 * Stefan Esser <se@mi.Uni-Koeln.de>
16 * Copyright (C) 1994 Wolfgang Stanglmeier
18 * Other major contributions:
20 * NVRAM detection and reading.
21 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23 *-----------------------------------------------------------------------------
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. The name of the author may not be used to endorse or promote products
31 * derived from this software without specific prior written permission.
33 * Where this Software is combined with software released under the terms of
34 * the GNU Public License ("GPL") and the terms of the GPL would require the
35 * combined work to also be released under the terms of the GPL, the terms
36 * and conditions of this License will apply in addition to those of the
37 * GPL with the exception of any terms or conditions of this License that
38 * conflict with, or are expressly prohibited by, the GPL.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * Generic driver options.
59 * They may be defined in platform specific headers, if they
62 * SYM_OPT_HANDLE_DIR_UNKNOWN
63 * When this option is set, the SCRIPTS used by the driver
64 * are able to handle SCSI transfers with direction not
66 * (set for Linux-2.0.X)
68 * SYM_OPT_HANDLE_DEVICE_QUEUEING
69 * When this option is set, the driver will use a queue per
70 * device and handle QUEUE FULL status requeuing internally.
72 * SYM_OPT_LIMIT_COMMAND_REORDERING
73 * When this option is set, the driver tries to limit tagged
74 * command reordering to some reasonnable value.
78 #define SYM_OPT_HANDLE_DIR_UNKNOWN
79 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
80 #define SYM_OPT_LIMIT_COMMAND_REORDERING
84 * Active debugging tags and verbosity.
85 * Both DEBUG_FLAGS and sym_verbose can be redefined
86 * by the platform specific code to something else.
88 #define DEBUG_ALLOC (0x0001)
89 #define DEBUG_PHASE (0x0002)
90 #define DEBUG_POLL (0x0004)
91 #define DEBUG_QUEUE (0x0008)
92 #define DEBUG_RESULT (0x0010)
93 #define DEBUG_SCATTER (0x0020)
94 #define DEBUG_SCRIPT (0x0040)
95 #define DEBUG_TINY (0x0080)
96 #define DEBUG_TIMING (0x0100)
97 #define DEBUG_NEGO (0x0200)
98 #define DEBUG_TAGS (0x0400)
99 #define DEBUG_POINTER (0x0800)
102 #define DEBUG_FLAGS (0x0000)
106 #define sym_verbose (np->verbose)
110 * These ones should have been already defined.
113 #define assert(expression) { \
114 if (!(expression)) { \
116 "assertion \"%s\" failed: file \"%s\", line %d\n", \
118 __FILE__, __LINE__); \
124 * Number of tasks per device we want to handle.
126 #if SYM_CONF_MAX_TAG_ORDER > 8
127 #error "more than 256 tags per logical unit not allowed."
129 #define SYM_CONF_MAX_TASK (1<<SYM_CONF_MAX_TAG_ORDER)
132 * Donnot use more tasks that we can handle.
134 #ifndef SYM_CONF_MAX_TAG
135 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
137 #if SYM_CONF_MAX_TAG > SYM_CONF_MAX_TASK
138 #undef SYM_CONF_MAX_TAG
139 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
143 * This one means 'NO TAG for this job'
148 * Number of SCSI targets.
150 #if SYM_CONF_MAX_TARGET > 16
151 #error "more than 16 targets not allowed."
155 * Number of logical units per target.
157 #if SYM_CONF_MAX_LUN > 64
158 #error "more than 64 logical units per target not allowed."
162 * Asynchronous pre-scaler (ns). Shall be 40 for
163 * the SCSI timings to be compliant.
165 #define SYM_CONF_MIN_ASYNC (40)
168 * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
169 * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized.
170 * (1 PAGE at a time is just fine).
172 #define SYM_MEM_SHIFT 4
173 #define SYM_MEM_CLUSTER_SIZE (1UL << SYM_MEM_CLUSTER_SHIFT)
174 #define SYM_MEM_CLUSTER_MASK (SYM_MEM_CLUSTER_SIZE-1)
177 * Number of entries in the START and DONE queues.
179 * We limit to 1 PAGE in order to succeed allocation of
180 * these queues. Each entry is 8 bytes long (2 DWORDS).
182 #ifdef SYM_CONF_MAX_START
183 #define SYM_CONF_MAX_QUEUE (SYM_CONF_MAX_START+2)
185 #define SYM_CONF_MAX_QUEUE (7*SYM_CONF_MAX_TASK+2)
186 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
189 #if SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8
190 #undef SYM_CONF_MAX_QUEUE
191 #define SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8)
192 #undef SYM_CONF_MAX_START
193 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
197 * For this one, we want a short name :-)
199 #define MAX_QUEUE SYM_CONF_MAX_QUEUE
202 * Common definitions for both bus space based and legacy IO methods.
204 #define INB(r) INB_OFF(offsetof(struct sym_reg,r))
205 #define INW(r) INW_OFF(offsetof(struct sym_reg,r))
206 #define INL(r) INL_OFF(offsetof(struct sym_reg,r))
208 #define OUTB(r, v) OUTB_OFF(offsetof(struct sym_reg,r), (v))
209 #define OUTW(r, v) OUTW_OFF(offsetof(struct sym_reg,r), (v))
210 #define OUTL(r, v) OUTL_OFF(offsetof(struct sym_reg,r), (v))
212 #define OUTONB(r, m) OUTB(r, INB(r) | (m))
213 #define OUTOFFB(r, m) OUTB(r, INB(r) & ~(m))
214 #define OUTONW(r, m) OUTW(r, INW(r) | (m))
215 #define OUTOFFW(r, m) OUTW(r, INW(r) & ~(m))
216 #define OUTONL(r, m) OUTL(r, INL(r) | (m))
217 #define OUTOFFL(r, m) OUTL(r, INL(r) & ~(m))
220 * We normally want the chip to have a consistent view
221 * of driver internal data structures when we restart it.
224 #define OUTL_DSP(v) \
226 MEMORY_WRITE_BARRIER(); \
227 OUTL (nc_dsp, (v)); \
230 #define OUTONB_STD() \
232 MEMORY_WRITE_BARRIER(); \
233 OUTONB (nc_dcntl, (STD|NOCOM)); \
237 * Command control block states.
241 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
242 #define HS_DISCONNECT (3) /* Disconnected by target */
243 #define HS_WAIT (4) /* waiting for resource */
245 #define HS_DONEMASK (0x80)
246 #define HS_COMPLETE (4|HS_DONEMASK)
247 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
248 #define HS_UNEXPECTED (6|HS_DONEMASK) /* Unexpected disconnect */
249 #define HS_COMP_ERR (7|HS_DONEMASK) /* Completed with error */
252 * Software Interrupt Codes
254 #define SIR_BAD_SCSI_STATUS (1)
255 #define SIR_SEL_ATN_NO_MSG_OUT (2)
256 #define SIR_MSG_RECEIVED (3)
257 #define SIR_MSG_WEIRD (4)
258 #define SIR_NEGO_FAILED (5)
259 #define SIR_NEGO_PROTO (6)
260 #define SIR_SCRIPT_STOPPED (7)
261 #define SIR_REJECT_TO_SEND (8)
262 #define SIR_SWIDE_OVERRUN (9)
263 #define SIR_SODL_UNDERRUN (10)
264 #define SIR_RESEL_NO_MSG_IN (11)
265 #define SIR_RESEL_NO_IDENTIFY (12)
266 #define SIR_RESEL_BAD_LUN (13)
267 #define SIR_TARGET_SELECTED (14)
268 #define SIR_RESEL_BAD_I_T_L (15)
269 #define SIR_RESEL_BAD_I_T_L_Q (16)
270 #define SIR_ABORT_SENT (17)
271 #define SIR_RESEL_ABORTED (18)
272 #define SIR_MSG_OUT_DONE (19)
273 #define SIR_COMPLETE_ERROR (20)
274 #define SIR_DATA_OVERRUN (21)
275 #define SIR_BAD_PHASE (22)
276 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
277 #define SIR_DMAP_DIRTY (23)
284 * Extended error bit codes.
285 * xerr_status field of struct sym_ccb.
287 #define XE_EXTRA_DATA (1) /* unexpected data phase */
288 #define XE_BAD_PHASE (1<<1) /* illegal phase (4/5) */
289 #define XE_PARITY_ERR (1<<2) /* unrecovered SCSI parity error */
290 #define XE_SODL_UNRUN (1<<3) /* ODD transfer in DATA OUT phase */
291 #define XE_SWIDE_OVRUN (1<<4) /* ODD transfer in DATA IN phase */
294 * Negotiation status.
295 * nego_status field of struct sym_ccb.
302 * A CCB hashed table is used to retrieve CCB address
305 #define CCB_HASH_SHIFT 8
306 #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT)
307 #define CCB_HASH_MASK (CCB_HASH_SIZE-1)
309 #define CCB_HASH_CODE(dsa) \
310 (((dsa) >> (_LGRU16_(sizeof(struct sym_ccb)))) & CCB_HASH_MASK)
312 #define CCB_HASH_CODE(dsa) (((dsa) >> 9) & CCB_HASH_MASK)
315 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
317 * We may want to use segment registers for 64 bit DMA.
318 * 16 segments registers -> up to 64 GB addressable.
320 #define SYM_DMAP_SHIFT (4)
321 #define SYM_DMAP_SIZE (1u<<SYM_DMAP_SHIFT)
322 #define SYM_DMAP_MASK (SYM_DMAP_SIZE-1)
328 #define SYM_DISC_ENABLED (1)
329 #define SYM_TAGS_ENABLED (1<<1)
330 #define SYM_SCAN_BOOT_DISABLED (1<<2)
331 #define SYM_SCAN_LUNS_DISABLED (1<<3)
334 * Host adapter miscellaneous flags.
336 #define SYM_AVOID_BUS_RESET (1)
337 #define SYM_SCAN_TARGETS_HILO (1<<1)
342 #define SYM_SNOOP_TIMEOUT (10000000)
347 * Gather negotiable parameters value
355 u8 options; /* PPR options */
359 struct sym_trans curr;
360 struct sym_trans goal;
361 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
362 struct sym_trans prev;
369 * Due to lack of indirect addressing on earlier NCR chips,
370 * this substructure is copied from the TCB to a global
371 * address after selection.
372 * For SYMBIOS chips that support LOAD/STORE this copy is
373 * not needed and thus not performed.
377 * Scripts bus addresses of LUN table accessed from scripts.
378 * LUN #0 is a special case, since multi-lun devices are rare,
379 * and we we want to speed-up the general case and not waste
382 u32 luntbl_sa; /* bus address of this table */
383 u32 lun0_sa; /* bus address of LCB #0 */
385 * Actual SYNC/WIDE IO registers value for this target.
386 * 'sval', 'wval' and 'uval' are read from SCRIPTS and
387 * so have alignment constraints.
389 /*0*/ u_char uval; /* -> SCNTL4 register */
390 /*1*/ u_char sval; /* -> SXFER io register */
391 /*2*/ u_char filler1;
392 /*3*/ u_char wval; /* -> SCNTL3 io register */
396 * Target Control Block
401 * Assumed at offset 0.
403 /*0*/ struct sym_tcbh head;
406 * LUN table used by the SCRIPTS processor.
407 * An array of bus addresses is used on reselection.
409 u32 *luntbl; /* LCBs bus address table */
412 * LUN table used by the C code.
414 lcb_p lun0p; /* LCB of LUN #0 (usual case) */
415 #if SYM_CONF_MAX_LUN > 1
416 lcb_p *lunmp; /* Other LCBs [1..MAX_LUN] */
420 * Bitmap that tells about LUNs that succeeded at least
421 * 1 IO and therefore assumed to be a real device.
422 * Avoid useless allocation of the LCB structure.
424 u32 lun_map[(SYM_CONF_MAX_LUN+31)/32];
427 * Bitmap that tells about LUNs that haven't yet an LCB
428 * allocated (not discovered or LCB allocation failed).
430 u32 busy0_map[(SYM_CONF_MAX_LUN+31)/32];
434 * O/S specific data structure.
440 * Transfer capabilities (SIP)
442 struct sym_tinfo tinfo;
445 * Keep track of the CCB used for the negotiation in order
446 * to ensure that only 1 negotiation is queued at a time.
448 ccb_p nego_cp; /* CCB used for the nego */
451 * Set when we want to reset the device.
456 * Other user settable limits and options.
457 * These limits are read from the NVRAM if present.
461 struct scsi_device *sdev;
467 * Due to lack of indirect addressing on earlier NCR chips,
468 * this substructure is copied from the LCB to a global
469 * address after selection.
470 * For SYMBIOS chips that support LOAD/STORE this copy is
471 * not needed and thus not performed.
475 * SCRIPTS address jumped by SCRIPTS on reselection.
476 * For not probed logical units, this address points to
477 * SCRIPTS that deal with bad LU handling (must be at
478 * offset zero of the LCB for that reason).
483 * Task (bus address of a CCB) read from SCRIPTS that points
484 * to the unique ITL nexus allowed to be disconnected.
489 * Task table bus address (read from SCRIPTS).
495 * Logical Unit Control Block
500 * Assumed at offset 0.
502 /*0*/ struct sym_lcbh head;
505 * Task table read from SCRIPTS that contains pointers to
506 * ITLQ nexuses. The bus address read from SCRIPTS is
509 u32 *itlq_tbl; /* Kernel virtual address */
512 * Busy CCBs management.
514 u_short busy_itlq; /* Number of busy tagged CCBs */
515 u_short busy_itl; /* Number of busy untagged CCBs */
518 * Circular tag allocation buffer.
520 u_short ia_tag; /* Tag allocation index */
521 u_short if_tag; /* Tag release index */
522 u_char *cb_tags; /* Circular tags buffer */
525 * O/S specific data structure.
531 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
533 * Optionnaly the driver can handle device queueing,
534 * and requeues internally command to redo.
541 u_short started_tags;
542 u_short started_no_tag;
544 u_short started_limit;
547 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
549 * Optionnaly the driver can try to prevent SCSI
550 * IOs from being too much reordering.
552 u_char tags_si; /* Current index to tags sum */
553 u_short tags_sum[2]; /* Tags sum counters */
554 u_short tags_since; /* # of tags since last switch */
558 * Set when we want to clear all tasks.
570 * Action from SCRIPTS on a task.
571 * Is part of the CCB, but is also used separately to plug
572 * error handling action to perform from SCRIPTS.
575 u32 start; /* Jumped by SCRIPTS after selection */
576 u32 restart; /* Jumped by SCRIPTS on relection */
580 * Phase mismatch context.
582 * It is part of the CCB and is used as parameters for the
583 * DATA pointer. We need two contexts to handle correctly the
584 * SAVED DATA POINTER.
587 struct sym_tblmove sg; /* Updated interrupted SG block */
588 u32 ret; /* SCRIPT return address */
592 * LUN control block lookup.
593 * We use a direct pointer for LUN #0, and a table of
594 * pointers which is only allocated for devices that support
597 #if SYM_CONF_MAX_LUN <= 1
598 #define sym_lp(np, tp, lun) (!lun) ? (tp)->lun0p : NULL
600 #define sym_lp(np, tp, lun) \
601 (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[(lun)] : NULL
605 * Status are used by the host and the script processor.
607 * The last four bytes (status[4]) are copied to the
608 * scratchb register (declared as scr0..scr3) just after the
609 * select/reselect, and copied back just after disconnecting.
610 * Inside the script the XX_REG are used.
614 * Last four bytes (script)
617 #define HX_PRT nc_scr0
619 #define HS_PRT nc_scr1
621 #define SS_PRT nc_scr2
623 #define HF_PRT nc_scr3
626 * Last four bytes (host)
628 #define host_xflags phys.head.status[0]
629 #define host_status phys.head.status[1]
630 #define ssss_status phys.head.status[2]
631 #define host_flags phys.head.status[3]
637 #define HF_IN_PM1 (1u<<1)
638 #define HF_ACT_PM (1u<<2)
639 #define HF_DP_SAVED (1u<<3)
640 #define HF_SENSE (1u<<4)
641 #define HF_EXT_ERR (1u<<5)
642 #define HF_DATA_IN (1u<<6)
643 #ifdef SYM_CONF_IARB_SUPPORT
644 #define HF_HINT_IARB (1u<<7)
650 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
651 #define HX_DMAP_DIRTY (1u<<7)
657 * Due to lack of indirect addressing on earlier NCR chips,
658 * this substructure is copied from the ccb to a global
659 * address after selection (or reselection) and copied back
661 * For SYMBIOS chips that support LOAD/STORE this copy is
662 * not needed and thus not performed.
667 * Start and restart SCRIPTS addresses (must be at 0).
669 /*0*/ struct sym_actscr go;
672 * SCRIPTS jump address that deal with data pointers.
673 * 'savep' points to the position in the script responsible
674 * for the actual transfer of data.
675 * It's written on reception of a SAVE_DATA_POINTER message.
677 u32 savep; /* Jump address to saved data pointer */
678 u32 lastp; /* SCRIPTS address at end of data */
679 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
690 * GET/SET the value of the data pointer used by SCRIPTS.
692 * We must distinguish between the LOAD/STORE-based SCRIPTS
693 * that use directly the header in the CCB, and the NCR-GENERIC
694 * SCRIPTS that use the copy of the header in the HCB.
696 #if SYM_CONF_GENERIC_SUPPORT
697 #define sym_set_script_dp(np, cp, dp) \
699 if (np->features & FE_LDSTR) \
700 cp->phys.head.lastp = cpu_to_scr(dp); \
702 np->ccb_head.lastp = cpu_to_scr(dp); \
704 #define sym_get_script_dp(np, cp) \
705 scr_to_cpu((np->features & FE_LDSTR) ? \
706 cp->phys.head.lastp : np->ccb_head.lastp)
708 #define sym_set_script_dp(np, cp, dp) \
710 cp->phys.head.lastp = cpu_to_scr(dp); \
713 #define sym_get_script_dp(np, cp) (cp->phys.head.lastp)
717 * Data Structure Block
719 * During execution of a ccb by the script processor, the
720 * DSA (data structure address) register points to this
721 * substructure of the ccb.
726 * Also assumed at offset 0 of the sym_ccb structure.
728 /*0*/ struct sym_ccbh head;
731 * Phase mismatch contexts.
732 * We need two to handle correctly the SAVED DATA POINTER.
733 * MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic
734 * for address calculation from SCRIPTS.
740 * Table data for Script
742 struct sym_tblsel select;
743 struct sym_tblmove smsg;
744 struct sym_tblmove smsg_ext;
745 struct sym_tblmove cmd;
746 struct sym_tblmove sense;
747 struct sym_tblmove wresid;
748 struct sym_tblmove data [SYM_CONF_MAX_SG];
752 * Our Command Control Block
756 * This is the data structure which is pointed by the DSA
757 * register when it is executed by the script processor.
758 * It must be the first entry.
763 * Pointer to CAM ccb and related stuff.
765 cam_ccb_p cam_ccb; /* CAM scsiio ccb */
766 u8 cdb_buf[16]; /* Copy of CDB */
767 u8 *sns_bbuf; /* Bounce buffer for sense data */
768 #ifndef SYM_SNS_BBUF_LEN
769 #define SYM_SNS_BBUF_LEN (32)
771 int data_len; /* Total data length */
772 int segments; /* Number of SG segments */
774 u8 order; /* Tag type (if tagged command) */
777 * Miscellaneous status'.
779 u_char nego_status; /* Negotiation status */
780 u_char xerr_status; /* Extended error flags */
781 u32 extra_bytes; /* Extraneous bytes transferred */
785 * We prepare a message to be sent after selection.
786 * We may use a second one if the command is rescheduled
787 * due to CHECK_CONDITION or COMMAND TERMINATED.
788 * Contents are IDENTIFY and SIMPLE_TAG.
789 * While negotiating sync or wide transfer,
790 * a SDTR or WDTR message is appended.
792 u_char scsi_smsg [12];
793 u_char scsi_smsg2[12];
796 * Auto request sense related fields.
798 u_char sensecmd[6]; /* Request Sense command */
799 u_char sv_scsi_status; /* Saved SCSI status */
800 u_char sv_xerr_status; /* Saved extended status */
801 int sv_resid; /* Saved residual */
804 * O/S specific data structure.
812 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
813 SYM_QUEHEAD tmo_linkq; /* Optional timeout handling */
814 u_int tmo_clock; /* (link and dealine value) */
816 u32 ccb_ba; /* BUS address of this CCB */
817 u_short tag; /* Tag for this transfer */
818 /* NO_TAG means no tag */
821 ccb_p link_ccbh; /* Host adapter CCB hash chain */
823 link_ccbq; /* Link to free/busy CCB queue */
824 u32 startp; /* Initial data pointer */
825 u32 goalp; /* Expected last data pointer */
826 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
829 int ext_sg; /* Extreme data pointer, used */
830 int ext_ofs; /* to calculate the residual. */
831 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
833 link2_ccbq; /* Link for device queueing */
834 u_char started; /* CCB queued to the squeue */
836 u_char to_abort; /* Want this IO to be aborted */
837 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
838 u_char tags_si; /* Lun tags sum index (0,1) */
842 #define CCB_BA(cp,lbl) (cp->ccb_ba + offsetof(struct sym_ccb, lbl))
844 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
845 #define sym_goalp(cp) ((cp->host_flags & HF_DATA_IN) ? cp->goalp : cp->wgoalp)
847 #define sym_goalp(cp) (cp->goalp)
856 * Due to poorness of addressing capabilities, earlier
857 * chips (810, 815, 825) copy part of the data structures
858 * (CCB, TCB and LCB) in fixed areas.
860 #if SYM_CONF_GENERIC_SUPPORT
861 struct sym_ccbh ccb_head;
862 struct sym_tcbh tcb_head;
863 struct sym_lcbh lcb_head;
866 * Idle task and invalid task actions and
867 * their bus addresses.
869 struct sym_actscr idletask, notask, bad_itl, bad_itlq;
870 u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba;
873 * Dummy lun table to protect us against target
874 * returning bad lun number on reselection.
876 u32 *badluntbl; /* Table physical address */
877 u32 badlun_sa; /* SCRIPT handler BUS address */
880 * Bus address of this host control block.
885 * Bit 32-63 of the on-chip RAM bus address in LE format.
886 * The START_RAM64 script loads the MMRS and MMWS from this
892 * Initial value of some IO register bits.
893 * These values are assumed to have been set by BIOS, and may
894 * be used to probe adapter implementation differences.
896 u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
897 sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4,
901 * Actual initial value of IO register bits used by the
902 * driver. They are loaded at initialisation according to
903 * features that are to be enabled/disabled.
905 u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4,
906 rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4;
911 struct sym_tcb target[SYM_CONF_MAX_TARGET];
914 * Target control block bus address array used by the SCRIPT
921 * DMA pool handle for this HBA.
923 m_pool_ident_t bus_dmat;
926 * O/S specific data structure
931 * Physical bus addresses of the chip.
933 u32 mmio_ba; /* MMIO 32 bit BUS address */
934 int mmio_ws; /* MMIO Window size */
936 u32 ram_ba; /* RAM 32 bit BUS address */
937 int ram_ws; /* RAM window size */
940 * SCRIPTS virtual and physical bus addresses.
941 * 'script' is loaded in the on-chip RAM if present.
942 * 'scripth' stays in main memory for all chips except the
943 * 53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM.
945 u_char *scripta0; /* Copy of scripts A, B, Z */
948 u32 scripta_ba; /* Actual scripts A, B, Z */
949 u32 scriptb_ba; /* 32 bit bus addresses. */
951 u_short scripta_sz; /* Actual size of script A, B, Z*/
956 * Bus addresses, setup and patch methods for
957 * the selected firmware.
959 struct sym_fwa_ba fwa_bas; /* Useful SCRIPTA bus addresses */
960 struct sym_fwb_ba fwb_bas; /* Useful SCRIPTB bus addresses */
961 struct sym_fwz_ba fwz_bas; /* Useful SCRIPTZ bus addresses */
962 void (*fw_setup)(hcb_p np, struct sym_fw *fw);
963 void (*fw_patch)(hcb_p np);
967 * General controller parameters and configuration.
969 u_short device_id; /* PCI device id */
970 u_char revision_id; /* PCI device revision id */
971 u_int features; /* Chip features map */
972 u_char myaddr; /* SCSI id of the adapter */
973 u_char maxburst; /* log base 2 of dwords burst */
974 u_char maxwide; /* Maximum transfer width */
975 u_char minsync; /* Min sync period factor (ST) */
976 u_char maxsync; /* Max sync period factor (ST) */
977 u_char maxoffs; /* Max scsi offset (ST) */
978 u_char minsync_dt; /* Min sync period factor (DT) */
979 u_char maxsync_dt; /* Max sync period factor (DT) */
980 u_char maxoffs_dt; /* Max scsi offset (DT) */
981 u_char multiplier; /* Clock multiplier (1,2,4) */
982 u_char clock_divn; /* Number of clock divisors */
983 u32 clock_khz; /* SCSI clock frequency in KHz */
984 u32 pciclk_khz; /* Estimated PCI clock in KHz */
986 * Start queue management.
987 * It is filled up by the host processor and accessed by the
988 * SCRIPTS processor in order to start SCSI commands.
990 volatile /* Prevent code optimizations */
991 u32 *squeue; /* Start queue virtual address */
992 u32 squeue_ba; /* Start queue BUS address */
993 u_short squeueput; /* Next free slot of the queue */
994 u_short actccbs; /* Number of allocated CCBs */
997 * Command completion queue.
998 * It is the same size as the start queue to avoid overflow.
1000 u_short dqueueget; /* Next position to scan */
1001 volatile /* Prevent code optimizations */
1002 u32 *dqueue; /* Completion (done) queue */
1003 u32 dqueue_ba; /* Done queue BUS address */
1006 * Miscellaneous buffers accessed by the scripts-processor.
1007 * They shall be DWORD aligned, because they may be read or
1008 * written with a script command.
1010 u_char msgout[8]; /* Buffer for MESSAGE OUT */
1011 u_char msgin [8]; /* Buffer for MESSAGE IN */
1012 u32 lastmsg; /* Last SCSI message sent */
1013 u32 scratch; /* Scratch for SCSI receive */
1014 /* Also used for cache test */
1016 * Miscellaneous configuration and status parameters.
1018 u_char usrflags; /* Miscellaneous user flags */
1019 u_char scsi_mode; /* Current SCSI BUS mode */
1020 u_char verbose; /* Verbosity for this controller*/
1023 * CCB lists and queue.
1025 ccb_p *ccbh; /* CCBs hashed by DSA value */
1026 /* CCB_HASH_SIZE lists of CCBs */
1027 SYM_QUEHEAD free_ccbq; /* Queue of available CCBs */
1028 SYM_QUEHEAD busy_ccbq; /* Queue of busy CCBs */
1031 * During error handling and/or recovery,
1032 * active CCBs that are to be completed with
1033 * error or requeued are moved from the busy_ccbq
1034 * to the comp_ccbq prior to completion.
1036 SYM_QUEHEAD comp_ccbq;
1038 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1039 SYM_QUEHEAD dummy_ccbq;
1042 * Optional handling of IO timeouts.
1044 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
1045 SYM_QUEHEAD tmo0_ccbq;
1046 SYM_QUEHEAD *tmo_ccbq; /* [2*SYM_TIMEOUT_ORDER_MAX] */
1052 * IMMEDIATE ARBITRATION (IARB) control.
1054 * We keep track in 'last_cp' of the last CCB that has been
1055 * queued to the SCRIPTS processor and clear 'last_cp' when
1056 * this CCB completes. If last_cp is not zero at the moment
1057 * we queue a new CCB, we set a flag in 'last_cp' that is
1058 * used by the SCRIPTS as a hint for setting IARB.
1059 * We donnot set more than 'iarb_max' consecutive hints for
1060 * IARB in order to leave devices a chance to reselect.
1061 * By the way, any non zero value of 'iarb_max' is unfair. :)
1063 #ifdef SYM_CONF_IARB_SUPPORT
1064 u_short iarb_max; /* Max. # consecutive IARB hints*/
1065 u_short iarb_count; /* Actual # of these hints */
1070 * Command abort handling.
1071 * We need to synchronize tightly with the SCRIPTS
1072 * processor in order to handle things correctly.
1074 u_char abrt_msg[4]; /* Message to send buffer */
1075 struct sym_tblmove abrt_tbl; /* Table for the MOV of it */
1076 struct sym_tblsel abrt_sel; /* Sync params for selection */
1077 u_char istat_sem; /* Tells the chip to stop (SEM) */
1080 * 64 bit DMA handling.
1082 #if SYM_CONF_DMA_ADDRESSING_MODE != 0
1083 u_char use_dac; /* Use PCI DAC cycles */
1084 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1085 u_char dmap_dirty; /* Dma segments registers dirty */
1086 u32 dmap_bah[SYM_DMAP_SIZE];/* Segment registers map */
1091 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl))
1095 * FIRMWARES (sym_fw.c)
1097 struct sym_fw * sym_find_firmware(struct sym_pci_chip *chip);
1098 void sym_fw_bind_script (hcb_p np, u32 *start, int len);
1101 * Driver methods called from O/S specific code.
1103 char *sym_driver_name(void);
1104 void sym_print_xerr(ccb_p cp, int x_status);
1105 int sym_reset_scsi_bus(hcb_p np, int enab_int);
1106 struct sym_pci_chip *
1107 sym_lookup_pci_chip_table (u_short device_id, u_char revision);
1108 void sym_put_start_queue(hcb_p np, ccb_p cp);
1109 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1110 void sym_start_next_ccbs(hcb_p np, lcb_p lp, int maxn);
1112 void sym_start_up (hcb_p np, int reason);
1113 void sym_interrupt (hcb_p np);
1114 void sym_flush_comp_queue(hcb_p np, int cam_status);
1115 int sym_clear_tasks(hcb_p np, int cam_status, int target, int lun, int task);
1116 ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order);
1117 void sym_free_ccb (hcb_p np, ccb_p cp);
1118 lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln);
1119 int sym_queue_scsiio(hcb_p np, cam_scsiio_p csio, ccb_p cp);
1120 int sym_abort_scsiio(hcb_p np, cam_ccb_p ccb, int timed_out);
1121 int sym_abort_ccb(hcb_p np, ccb_p cp, int timed_out);
1122 int sym_reset_scsi_target(hcb_p np, int target);
1123 void sym_hcb_free(hcb_p np);
1125 #ifdef SYM_OPT_NVRAM_PRE_READ
1126 int sym_hcb_attach(hcb_p np, struct sym_fw *fw, struct sym_nvram *nvram);
1128 int sym_hcb_attach(hcb_p np, struct sym_fw *fw);
1132 * Optionnaly, the driver may handle IO timeouts.
1134 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
1135 int sym_abort_ccb(hcb_p np, ccb_p cp, int timed_out);
1136 void sym_timeout_ccb(hcb_p np, ccb_p cp, u_int ticks);
1137 static void __inline sym_untimeout_ccb(hcb_p np, ccb_p cp)
1139 sym_remque(&cp->tmo_linkq);
1140 sym_insque_head(&cp->tmo_linkq, &np->tmo0_ccbq);
1142 void sym_clock(hcb_p np);
1143 #endif /* SYM_OPT_HANDLE_IO_TIMEOUT */
1146 * Optionnaly, the driver may provide a function
1147 * to announce transfer rate changes.
1149 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
1150 void sym_announce_transfer_rate(hcb_p np, int target);
1154 * Build a scatter/gather entry.
1156 * For 64 bit systems, we use the 8 upper bits of the size field
1157 * to provide bus address bits 32-39 to the SCRIPTS processor.
1158 * This allows the 895A, 896, 1010 to address up to 1 TB of memory.
1161 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
1162 #define sym_build_sge(np, data, badd, len) \
1164 (data)->addr = cpu_to_scr(badd); \
1165 (data)->size = cpu_to_scr(len); \
1167 #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
1168 #define sym_build_sge(np, data, badd, len) \
1170 (data)->addr = cpu_to_scr(badd); \
1171 (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len); \
1173 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1174 int sym_lookup_dmap(hcb_p np, u32 h, int s);
1175 static __inline void
1176 sym_build_sge(hcb_p np, struct sym_tblmove *data, u64 badd, int len)
1179 int s = (h&SYM_DMAP_MASK);
1181 if (h != np->dmap_bah[s])
1184 (data)->addr = cpu_to_scr(badd);
1185 (data)->size = cpu_to_scr((s<<24) + len);
1188 s = sym_lookup_dmap(np, h, s);
1192 #error "Unsupported DMA addressing mode"
1196 * Set up data pointers used by SCRIPTS.
1197 * Called from O/S specific code.
1199 static inline void sym_setup_data_pointers(struct sym_hcb *np,
1200 struct sym_ccb *cp, int dir)
1205 * No segments means no data.
1211 * Set the data pointer.
1214 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1215 case CAM_DIR_UNKNOWN:
1218 goalp = SCRIPTA_BA (np, data_out2) + 8;
1219 lastp = goalp - 8 - (cp->segments * (2*4));
1220 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1221 cp->wgoalp = cpu_to_scr(goalp);
1222 if (dir != CAM_DIR_UNKNOWN)
1224 cp->phys.head.wlastp = cpu_to_scr(lastp);
1230 cp->host_flags |= HF_DATA_IN;
1231 goalp = SCRIPTA_BA (np, data_in2) + 8;
1232 lastp = goalp - 8 - (cp->segments * (2*4));
1236 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1237 cp->host_flags |= HF_DATA_IN;
1239 lastp = goalp = SCRIPTB_BA (np, no_data);
1244 * Set all pointers values needed by SCRIPTS.
1246 cp->phys.head.lastp = cpu_to_scr(lastp);
1247 cp->phys.head.savep = cpu_to_scr(lastp);
1248 cp->startp = cp->phys.head.savep;
1249 cp->goalp = cpu_to_scr(goalp);
1251 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1253 * If direction is unknown, start at data_io.
1255 if (dir == CAM_DIR_UNKNOWN)
1256 cp->phys.head.savep = cpu_to_scr(SCRIPTB_BA (np, data_io));
1265 * Link between free memory chunks of a given size.
1267 typedef struct sym_m_link {
1268 struct sym_m_link *next;
1272 * Virtual to bus physical translation for a given cluster.
1273 * Such a structure is only useful with DMA abstraction.
1275 typedef struct sym_m_vtob { /* Virtual to Bus address translation */
1276 struct sym_m_vtob *next;
1277 #ifdef SYM_HAVE_M_SVTOB
1278 struct sym_m_svtob s; /* OS specific data structure */
1280 m_addr_t vaddr; /* Virtual address */
1281 m_addr_t baddr; /* Bus physical address */
1284 /* Hash this stuff a bit to speed up translations */
1285 #define VTOB_HASH_SHIFT 5
1286 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
1287 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
1288 #define VTOB_HASH_CODE(m) \
1289 ((((m_addr_t) (m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK)
1292 * Memory pool of a given kind.
1293 * Ideally, we want to use:
1294 * 1) 1 pool for memory we donnot need to involve in DMA.
1295 * 2) The same pool for controllers that require same DMA
1296 * constraints and features.
1297 * The OS specific m_pool_id_t thing and the sym_m_pool_match()
1298 * method are expected to tell the driver about.
1300 typedef struct sym_m_pool {
1301 m_pool_ident_t dev_dmat; /* Identifies the pool (see above) */
1302 m_addr_t (*get_mem_cluster)(struct sym_m_pool *);
1303 #ifdef SYM_MEM_FREE_UNUSED
1304 void (*free_mem_cluster)(struct sym_m_pool *, m_addr_t);
1306 #define M_GET_MEM_CLUSTER() mp->get_mem_cluster(mp)
1307 #define M_FREE_MEM_CLUSTER(p) mp->free_mem_cluster(mp, p)
1308 #ifdef SYM_HAVE_M_SPOOL
1309 struct sym_m_spool s; /* OS specific data structure */
1312 m_vtob_p vtob[VTOB_HASH_SIZE];
1313 struct sym_m_pool *next;
1314 struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
1318 * Alloc and free non DMAable memory.
1320 void sym_mfree_unlocked(void *ptr, int size, char *name);
1321 void *sym_calloc_unlocked(int size, char *name);
1324 * Alloc, free and translate addresses to bus physical
1325 * for DMAable memory.
1327 void *__sym_calloc_dma_unlocked(m_pool_ident_t dev_dmat, int size, char *name);
1329 __sym_mfree_dma_unlocked(m_pool_ident_t dev_dmat, void *m,int size, char *name);
1330 u32 __vtobus_unlocked(m_pool_ident_t dev_dmat, void *m);
1333 * Verbs used by the driver code for DMAable memory handling.
1334 * The _uvptv_ macro avoids a nasty warning about pointer to volatile
1337 #define _uvptv_(p) ((void *)((u_long)(p)))
1339 #define _sym_calloc_dma(np, l, n) __sym_calloc_dma(np->bus_dmat, l, n)
1340 #define _sym_mfree_dma(np, p, l, n) \
1341 __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n)
1342 #define sym_calloc_dma(l, n) _sym_calloc_dma(np, l, n)
1343 #define sym_mfree_dma(p, l, n) _sym_mfree_dma(np, p, l, n)
1344 #define _vtobus(np, p) __vtobus(np->bus_dmat, _uvptv_(p))
1345 #define vtobus(p) _vtobus(np, p)
1348 * Override some function names.
1350 #define PRINT_ADDR sym_print_addr
1351 #define PRINT_TARGET sym_print_target
1352 #define PRINT_LUN sym_print_lun
1353 #define MDELAY sym_mdelay
1354 #define UDELAY sym_udelay
1356 #endif /* SYM_HIPD_H */