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_SNIFF_INQUIRY
73 * When this option is set, the driver sniff out successful
74 * INQUIRY response and performs negotiations accordingly.
77 * SYM_OPT_LIMIT_COMMAND_REORDERING
78 * When this option is set, the driver tries to limit tagged
79 * command reordering to some reasonnable value.
83 #define SYM_OPT_HANDLE_DIR_UNKNOWN
84 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
85 #define SYM_OPT_SNIFF_INQUIRY
86 #define SYM_OPT_LIMIT_COMMAND_REORDERING
90 * Active debugging tags and verbosity.
91 * Both DEBUG_FLAGS and sym_verbose can be redefined
92 * by the platform specific code to something else.
94 #define DEBUG_ALLOC (0x0001)
95 #define DEBUG_PHASE (0x0002)
96 #define DEBUG_POLL (0x0004)
97 #define DEBUG_QUEUE (0x0008)
98 #define DEBUG_RESULT (0x0010)
99 #define DEBUG_SCATTER (0x0020)
100 #define DEBUG_SCRIPT (0x0040)
101 #define DEBUG_TINY (0x0080)
102 #define DEBUG_TIMING (0x0100)
103 #define DEBUG_NEGO (0x0200)
104 #define DEBUG_TAGS (0x0400)
105 #define DEBUG_POINTER (0x0800)
108 #define DEBUG_FLAGS (0x0000)
112 #define sym_verbose (np->verbose)
116 * These ones should have been already defined.
119 #define assert(expression) { \
120 if (!(expression)) { \
122 "assertion \"%s\" failed: file \"%s\", line %d\n", \
124 __FILE__, __LINE__); \
130 * Number of tasks per device we want to handle.
132 #if SYM_CONF_MAX_TAG_ORDER > 8
133 #error "more than 256 tags per logical unit not allowed."
135 #define SYM_CONF_MAX_TASK (1<<SYM_CONF_MAX_TAG_ORDER)
138 * Donnot use more tasks that we can handle.
140 #ifndef SYM_CONF_MAX_TAG
141 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
143 #if SYM_CONF_MAX_TAG > SYM_CONF_MAX_TASK
144 #undef SYM_CONF_MAX_TAG
145 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
149 * This one means 'NO TAG for this job'
154 * Number of SCSI targets.
156 #if SYM_CONF_MAX_TARGET > 16
157 #error "more than 16 targets not allowed."
161 * Number of logical units per target.
163 #if SYM_CONF_MAX_LUN > 64
164 #error "more than 64 logical units per target not allowed."
168 * Asynchronous pre-scaler (ns). Shall be 40 for
169 * the SCSI timings to be compliant.
171 #define SYM_CONF_MIN_ASYNC (40)
174 * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
175 * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized.
176 * (1 PAGE at a time is just fine).
178 #define SYM_MEM_SHIFT 4
179 #define SYM_MEM_CLUSTER_SIZE (1UL << SYM_MEM_CLUSTER_SHIFT)
180 #define SYM_MEM_CLUSTER_MASK (SYM_MEM_CLUSTER_SIZE-1)
183 * Number of entries in the START and DONE queues.
185 * We limit to 1 PAGE in order to succeed allocation of
186 * these queues. Each entry is 8 bytes long (2 DWORDS).
188 #ifdef SYM_CONF_MAX_START
189 #define SYM_CONF_MAX_QUEUE (SYM_CONF_MAX_START+2)
191 #define SYM_CONF_MAX_QUEUE (7*SYM_CONF_MAX_TASK+2)
192 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
195 #if SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8
196 #undef SYM_CONF_MAX_QUEUE
197 #define SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8)
198 #undef SYM_CONF_MAX_START
199 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
203 * For this one, we want a short name :-)
205 #define MAX_QUEUE SYM_CONF_MAX_QUEUE
208 * Common definitions for both bus space based and legacy IO methods.
210 #define INB(r) INB_OFF(offsetof(struct sym_reg,r))
211 #define INW(r) INW_OFF(offsetof(struct sym_reg,r))
212 #define INL(r) INL_OFF(offsetof(struct sym_reg,r))
214 #define OUTB(r, v) OUTB_OFF(offsetof(struct sym_reg,r), (v))
215 #define OUTW(r, v) OUTW_OFF(offsetof(struct sym_reg,r), (v))
216 #define OUTL(r, v) OUTL_OFF(offsetof(struct sym_reg,r), (v))
218 #define OUTONB(r, m) OUTB(r, INB(r) | (m))
219 #define OUTOFFB(r, m) OUTB(r, INB(r) & ~(m))
220 #define OUTONW(r, m) OUTW(r, INW(r) | (m))
221 #define OUTOFFW(r, m) OUTW(r, INW(r) & ~(m))
222 #define OUTONL(r, m) OUTL(r, INL(r) | (m))
223 #define OUTOFFL(r, m) OUTL(r, INL(r) & ~(m))
226 * We normally want the chip to have a consistent view
227 * of driver internal data structures when we restart it.
230 #define OUTL_DSP(v) \
232 MEMORY_WRITE_BARRIER(); \
233 OUTL (nc_dsp, (v)); \
236 #define OUTONB_STD() \
238 MEMORY_WRITE_BARRIER(); \
239 OUTONB (nc_dcntl, (STD|NOCOM)); \
243 * Command control block states.
247 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
248 #define HS_DISCONNECT (3) /* Disconnected by target */
249 #define HS_WAIT (4) /* waiting for resource */
251 #define HS_DONEMASK (0x80)
252 #define HS_COMPLETE (4|HS_DONEMASK)
253 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
254 #define HS_UNEXPECTED (6|HS_DONEMASK) /* Unexpected disconnect */
255 #define HS_COMP_ERR (7|HS_DONEMASK) /* Completed with error */
258 * Software Interrupt Codes
260 #define SIR_BAD_SCSI_STATUS (1)
261 #define SIR_SEL_ATN_NO_MSG_OUT (2)
262 #define SIR_MSG_RECEIVED (3)
263 #define SIR_MSG_WEIRD (4)
264 #define SIR_NEGO_FAILED (5)
265 #define SIR_NEGO_PROTO (6)
266 #define SIR_SCRIPT_STOPPED (7)
267 #define SIR_REJECT_TO_SEND (8)
268 #define SIR_SWIDE_OVERRUN (9)
269 #define SIR_SODL_UNDERRUN (10)
270 #define SIR_RESEL_NO_MSG_IN (11)
271 #define SIR_RESEL_NO_IDENTIFY (12)
272 #define SIR_RESEL_BAD_LUN (13)
273 #define SIR_TARGET_SELECTED (14)
274 #define SIR_RESEL_BAD_I_T_L (15)
275 #define SIR_RESEL_BAD_I_T_L_Q (16)
276 #define SIR_ABORT_SENT (17)
277 #define SIR_RESEL_ABORTED (18)
278 #define SIR_MSG_OUT_DONE (19)
279 #define SIR_COMPLETE_ERROR (20)
280 #define SIR_DATA_OVERRUN (21)
281 #define SIR_BAD_PHASE (22)
282 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
283 #define SIR_DMAP_DIRTY (23)
290 * Extended error bit codes.
291 * xerr_status field of struct sym_ccb.
293 #define XE_EXTRA_DATA (1) /* unexpected data phase */
294 #define XE_BAD_PHASE (1<<1) /* illegal phase (4/5) */
295 #define XE_PARITY_ERR (1<<2) /* unrecovered SCSI parity error */
296 #define XE_SODL_UNRUN (1<<3) /* ODD transfer in DATA OUT phase */
297 #define XE_SWIDE_OVRUN (1<<4) /* ODD transfer in DATA IN phase */
300 * Negotiation status.
301 * nego_status field of struct sym_ccb.
308 * A CCB hashed table is used to retrieve CCB address
311 #define CCB_HASH_SHIFT 8
312 #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT)
313 #define CCB_HASH_MASK (CCB_HASH_SIZE-1)
315 #define CCB_HASH_CODE(dsa) \
316 (((dsa) >> (_LGRU16_(sizeof(struct sym_ccb)))) & CCB_HASH_MASK)
318 #define CCB_HASH_CODE(dsa) (((dsa) >> 9) & CCB_HASH_MASK)
321 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
323 * We may want to use segment registers for 64 bit DMA.
324 * 16 segments registers -> up to 64 GB addressable.
326 #define SYM_DMAP_SHIFT (4)
327 #define SYM_DMAP_SIZE (1u<<SYM_DMAP_SHIFT)
328 #define SYM_DMAP_MASK (SYM_DMAP_SIZE-1)
334 #define SYM_DISC_ENABLED (1)
335 #define SYM_TAGS_ENABLED (1<<1)
336 #define SYM_SCAN_BOOT_DISABLED (1<<2)
337 #define SYM_SCAN_LUNS_DISABLED (1<<3)
340 * Host adapter miscellaneous flags.
342 #define SYM_AVOID_BUS_RESET (1)
343 #define SYM_SCAN_TARGETS_HILO (1<<1)
348 #define SYM_SNOOP_TIMEOUT (10000000)
353 * Gather negotiable parameters value
361 u8 options; /* PPR options */
365 struct sym_trans curr;
366 struct sym_trans goal;
367 struct sym_trans user;
368 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
369 struct sym_trans prev;
376 * Due to lack of indirect addressing on earlier NCR chips,
377 * this substructure is copied from the TCB to a global
378 * address after selection.
379 * For SYMBIOS chips that support LOAD/STORE this copy is
380 * not needed and thus not performed.
384 * Scripts bus addresses of LUN table accessed from scripts.
385 * LUN #0 is a special case, since multi-lun devices are rare,
386 * and we we want to speed-up the general case and not waste
389 u32 luntbl_sa; /* bus address of this table */
390 u32 lun0_sa; /* bus address of LCB #0 */
392 * Actual SYNC/WIDE IO registers value for this target.
393 * 'sval', 'wval' and 'uval' are read from SCRIPTS and
394 * so have alignment constraints.
396 /*0*/ u_char uval; /* -> SCNTL4 register */
397 /*1*/ u_char sval; /* -> SXFER io register */
398 /*2*/ u_char filler1;
399 /*3*/ u_char wval; /* -> SCNTL3 io register */
403 * Target Control Block
408 * Assumed at offset 0.
410 /*0*/ struct sym_tcbh head;
413 * LUN table used by the SCRIPTS processor.
414 * An array of bus addresses is used on reselection.
416 u32 *luntbl; /* LCBs bus address table */
419 * LUN table used by the C code.
421 lcb_p lun0p; /* LCB of LUN #0 (usual case) */
422 #if SYM_CONF_MAX_LUN > 1
423 lcb_p *lunmp; /* Other LCBs [1..MAX_LUN] */
427 * Bitmap that tells about LUNs that succeeded at least
428 * 1 IO and therefore assumed to be a real device.
429 * Avoid useless allocation of the LCB structure.
431 u32 lun_map[(SYM_CONF_MAX_LUN+31)/32];
434 * Bitmap that tells about LUNs that haven't yet an LCB
435 * allocated (not discovered or LCB allocation failed).
437 u32 busy0_map[(SYM_CONF_MAX_LUN+31)/32];
441 * O/S specific data structure.
447 * Transfer capabilities (SIP)
449 struct sym_tinfo tinfo;
452 * Keep track of the CCB used for the negotiation in order
453 * to ensure that only 1 negotiation is queued at a time.
455 ccb_p nego_cp; /* CCB used for the nego */
458 * Set when we want to reset the device.
463 * Other user settable limits and options.
464 * These limits are read from the NVRAM if present.
469 #ifdef SYM_OPT_SNIFF_INQUIRY
471 * Some minimal information from INQUIRY response.
473 u32 cmdq_map[(SYM_CONF_MAX_LUN+31)/32];
477 u_char inq_byte7_valid;
485 * Due to lack of indirect addressing on earlier NCR chips,
486 * this substructure is copied from the LCB to a global
487 * address after selection.
488 * For SYMBIOS chips that support LOAD/STORE this copy is
489 * not needed and thus not performed.
493 * SCRIPTS address jumped by SCRIPTS on reselection.
494 * For not probed logical units, this address points to
495 * SCRIPTS that deal with bad LU handling (must be at
496 * offset zero of the LCB for that reason).
501 * Task (bus address of a CCB) read from SCRIPTS that points
502 * to the unique ITL nexus allowed to be disconnected.
507 * Task table bus address (read from SCRIPTS).
513 * Logical Unit Control Block
518 * Assumed at offset 0.
520 /*0*/ struct sym_lcbh head;
523 * Task table read from SCRIPTS that contains pointers to
524 * ITLQ nexuses. The bus address read from SCRIPTS is
527 u32 *itlq_tbl; /* Kernel virtual address */
530 * Busy CCBs management.
532 u_short busy_itlq; /* Number of busy tagged CCBs */
533 u_short busy_itl; /* Number of busy untagged CCBs */
536 * Circular tag allocation buffer.
538 u_short ia_tag; /* Tag allocation index */
539 u_short if_tag; /* Tag release index */
540 u_char *cb_tags; /* Circular tags buffer */
543 * O/S specific data structure.
549 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
551 * Optionnaly the driver can handle device queueing,
552 * and requeues internally command to redo.
559 u_short started_tags;
560 u_short started_no_tag;
562 u_short started_limit;
565 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
567 * Optionnaly the driver can try to prevent SCSI
568 * IOs from being too much reordering.
570 u_char tags_si; /* Current index to tags sum */
571 u_short tags_sum[2]; /* Tags sum counters */
572 u_short tags_since; /* # of tags since last switch */
576 * Set when we want to clear all tasks.
588 * Action from SCRIPTS on a task.
589 * Is part of the CCB, but is also used separately to plug
590 * error handling action to perform from SCRIPTS.
593 u32 start; /* Jumped by SCRIPTS after selection */
594 u32 restart; /* Jumped by SCRIPTS on relection */
598 * Phase mismatch context.
600 * It is part of the CCB and is used as parameters for the
601 * DATA pointer. We need two contexts to handle correctly the
602 * SAVED DATA POINTER.
605 struct sym_tblmove sg; /* Updated interrupted SG block */
606 u32 ret; /* SCRIPT return address */
610 * LUN control block lookup.
611 * We use a direct pointer for LUN #0, and a table of
612 * pointers which is only allocated for devices that support
615 #if SYM_CONF_MAX_LUN <= 1
616 #define sym_lp(np, tp, lun) (!lun) ? (tp)->lun0p : 0
618 #define sym_lp(np, tp, lun) \
619 (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[(lun)] : 0
623 * Status are used by the host and the script processor.
625 * The last four bytes (status[4]) are copied to the
626 * scratchb register (declared as scr0..scr3) just after the
627 * select/reselect, and copied back just after disconnecting.
628 * Inside the script the XX_REG are used.
632 * Last four bytes (script)
635 #define HX_PRT nc_scr0
637 #define HS_PRT nc_scr1
639 #define SS_PRT nc_scr2
641 #define HF_PRT nc_scr3
644 * Last four bytes (host)
646 #define host_xflags phys.head.status[0]
647 #define host_status phys.head.status[1]
648 #define ssss_status phys.head.status[2]
649 #define host_flags phys.head.status[3]
655 #define HF_IN_PM1 (1u<<1)
656 #define HF_ACT_PM (1u<<2)
657 #define HF_DP_SAVED (1u<<3)
658 #define HF_SENSE (1u<<4)
659 #define HF_EXT_ERR (1u<<5)
660 #define HF_DATA_IN (1u<<6)
661 #ifdef SYM_CONF_IARB_SUPPORT
662 #define HF_HINT_IARB (1u<<7)
668 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
669 #define HX_DMAP_DIRTY (1u<<7)
675 * Due to lack of indirect addressing on earlier NCR chips,
676 * this substructure is copied from the ccb to a global
677 * address after selection (or reselection) and copied back
679 * For SYMBIOS chips that support LOAD/STORE this copy is
680 * not needed and thus not performed.
685 * Start and restart SCRIPTS addresses (must be at 0).
687 /*0*/ struct sym_actscr go;
690 * SCRIPTS jump address that deal with data pointers.
691 * 'savep' points to the position in the script responsible
692 * for the actual transfer of data.
693 * It's written on reception of a SAVE_DATA_POINTER message.
695 u32 savep; /* Jump address to saved data pointer */
696 u32 lastp; /* SCRIPTS address at end of data */
697 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
708 * GET/SET the value of the data pointer used by SCRIPTS.
710 * We must distinguish between the LOAD/STORE-based SCRIPTS
711 * that use directly the header in the CCB, and the NCR-GENERIC
712 * SCRIPTS that use the copy of the header in the HCB.
714 #if SYM_CONF_GENERIC_SUPPORT
715 #define sym_set_script_dp(np, cp, dp) \
717 if (np->features & FE_LDSTR) \
718 cp->phys.head.lastp = cpu_to_scr(dp); \
720 np->ccb_head.lastp = cpu_to_scr(dp); \
722 #define sym_get_script_dp(np, cp) \
723 scr_to_cpu((np->features & FE_LDSTR) ? \
724 cp->phys.head.lastp : np->ccb_head.lastp)
726 #define sym_set_script_dp(np, cp, dp) \
728 cp->phys.head.lastp = cpu_to_scr(dp); \
731 #define sym_get_script_dp(np, cp) (cp->phys.head.lastp)
735 * Data Structure Block
737 * During execution of a ccb by the script processor, the
738 * DSA (data structure address) register points to this
739 * substructure of the ccb.
744 * Also assumed at offset 0 of the sym_ccb structure.
746 /*0*/ struct sym_ccbh head;
749 * Phase mismatch contexts.
750 * We need two to handle correctly the SAVED DATA POINTER.
751 * MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic
752 * for address calculation from SCRIPTS.
758 * Table data for Script
760 struct sym_tblsel select;
761 struct sym_tblmove smsg;
762 struct sym_tblmove smsg_ext;
763 struct sym_tblmove cmd;
764 struct sym_tblmove sense;
765 struct sym_tblmove wresid;
766 struct sym_tblmove data [SYM_CONF_MAX_SG];
770 * Our Command Control Block
774 * This is the data structure which is pointed by the DSA
775 * register when it is executed by the script processor.
776 * It must be the first entry.
781 * Pointer to CAM ccb and related stuff.
783 cam_ccb_p cam_ccb; /* CAM scsiio ccb */
784 u8 cdb_buf[16]; /* Copy of CDB */
785 u8 *sns_bbuf; /* Bounce buffer for sense data */
786 #ifndef SYM_SNS_BBUF_LEN
787 #define SYM_SNS_BBUF_LEN (32)
789 int data_len; /* Total data length */
790 int segments; /* Number of SG segments */
792 u8 order; /* Tag type (if tagged command) */
795 * Miscellaneous status'.
797 u_char nego_status; /* Negotiation status */
798 u_char xerr_status; /* Extended error flags */
799 u32 extra_bytes; /* Extraneous bytes transferred */
803 * We prepare a message to be sent after selection.
804 * We may use a second one if the command is rescheduled
805 * due to CHECK_CONDITION or COMMAND TERMINATED.
806 * Contents are IDENTIFY and SIMPLE_TAG.
807 * While negotiating sync or wide transfer,
808 * a SDTR or WDTR message is appended.
810 u_char scsi_smsg [12];
811 u_char scsi_smsg2[12];
814 * Auto request sense related fields.
816 u_char sensecmd[6]; /* Request Sense command */
817 u_char sv_scsi_status; /* Saved SCSI status */
818 u_char sv_xerr_status; /* Saved extended status */
819 int sv_resid; /* Saved residual */
822 * O/S specific data structure.
830 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
831 SYM_QUEHEAD tmo_linkq; /* Optional timeout handling */
832 u_int tmo_clock; /* (link and dealine value) */
834 u32 ccb_ba; /* BUS address of this CCB */
835 u_short tag; /* Tag for this transfer */
836 /* NO_TAG means no tag */
839 ccb_p link_ccbh; /* Host adapter CCB hash chain */
841 link_ccbq; /* Link to free/busy CCB queue */
842 u32 startp; /* Initial data pointer */
843 u32 goalp; /* Expected last data pointer */
844 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
847 int ext_sg; /* Extreme data pointer, used */
848 int ext_ofs; /* to calculate the residual. */
849 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
851 link2_ccbq; /* Link for device queueing */
852 u_char started; /* CCB queued to the squeue */
854 u_char to_abort; /* Want this IO to be aborted */
855 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
856 u_char tags_si; /* Lun tags sum index (0,1) */
860 #define CCB_BA(cp,lbl) (cp->ccb_ba + offsetof(struct sym_ccb, lbl))
862 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
863 #define sym_goalp(cp) ((cp->host_flags & HF_DATA_IN) ? cp->goalp : cp->wgoalp)
865 #define sym_goalp(cp) (cp->goalp)
874 * Due to poorness of addressing capabilities, earlier
875 * chips (810, 815, 825) copy part of the data structures
876 * (CCB, TCB and LCB) in fixed areas.
878 #if SYM_CONF_GENERIC_SUPPORT
879 struct sym_ccbh ccb_head;
880 struct sym_tcbh tcb_head;
881 struct sym_lcbh lcb_head;
884 * Idle task and invalid task actions and
885 * their bus addresses.
887 struct sym_actscr idletask, notask, bad_itl, bad_itlq;
888 u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba;
891 * Dummy lun table to protect us against target
892 * returning bad lun number on reselection.
894 u32 *badluntbl; /* Table physical address */
895 u32 badlun_sa; /* SCRIPT handler BUS address */
898 * Bus address of this host control block.
903 * Bit 32-63 of the on-chip RAM bus address in LE format.
904 * The START_RAM64 script loads the MMRS and MMWS from this
910 * Initial value of some IO register bits.
911 * These values are assumed to have been set by BIOS, and may
912 * be used to probe adapter implementation differences.
914 u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
915 sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4,
919 * Actual initial value of IO register bits used by the
920 * driver. They are loaded at initialisation according to
921 * features that are to be enabled/disabled.
923 u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4,
924 rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4;
929 struct sym_tcb target[SYM_CONF_MAX_TARGET];
932 * Target control block bus address array used by the SCRIPT
939 * DMA pool handle for this HBA.
941 m_pool_ident_t bus_dmat;
944 * O/S specific data structure
949 * Physical bus addresses of the chip.
951 u32 mmio_ba; /* MMIO 32 bit BUS address */
952 int mmio_ws; /* MMIO Window size */
954 u32 ram_ba; /* RAM 32 bit BUS address */
955 int ram_ws; /* RAM window size */
958 * SCRIPTS virtual and physical bus addresses.
959 * 'script' is loaded in the on-chip RAM if present.
960 * 'scripth' stays in main memory for all chips except the
961 * 53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM.
963 u_char *scripta0; /* Copy of scripts A, B, Z */
966 u32 scripta_ba; /* Actual scripts A, B, Z */
967 u32 scriptb_ba; /* 32 bit bus addresses. */
969 u_short scripta_sz; /* Actual size of script A, B, Z*/
974 * Bus addresses, setup and patch methods for
975 * the selected firmware.
977 struct sym_fwa_ba fwa_bas; /* Useful SCRIPTA bus addresses */
978 struct sym_fwb_ba fwb_bas; /* Useful SCRIPTB bus addresses */
979 struct sym_fwz_ba fwz_bas; /* Useful SCRIPTZ bus addresses */
980 void (*fw_setup)(hcb_p np, struct sym_fw *fw);
981 void (*fw_patch)(hcb_p np);
985 * General controller parameters and configuration.
987 u_short device_id; /* PCI device id */
988 u_char revision_id; /* PCI device revision id */
989 u_int features; /* Chip features map */
990 u_char myaddr; /* SCSI id of the adapter */
991 u_char maxburst; /* log base 2 of dwords burst */
992 u_char maxwide; /* Maximum transfer width */
993 u_char minsync; /* Min sync period factor (ST) */
994 u_char maxsync; /* Max sync period factor (ST) */
995 u_char maxoffs; /* Max scsi offset (ST) */
996 u_char minsync_dt; /* Min sync period factor (DT) */
997 u_char maxsync_dt; /* Max sync period factor (DT) */
998 u_char maxoffs_dt; /* Max scsi offset (DT) */
999 u_char multiplier; /* Clock multiplier (1,2,4) */
1000 u_char clock_divn; /* Number of clock divisors */
1001 u32 clock_khz; /* SCSI clock frequency in KHz */
1002 u32 pciclk_khz; /* Estimated PCI clock in KHz */
1004 * Start queue management.
1005 * It is filled up by the host processor and accessed by the
1006 * SCRIPTS processor in order to start SCSI commands.
1008 volatile /* Prevent code optimizations */
1009 u32 *squeue; /* Start queue virtual address */
1010 u32 squeue_ba; /* Start queue BUS address */
1011 u_short squeueput; /* Next free slot of the queue */
1012 u_short actccbs; /* Number of allocated CCBs */
1015 * Command completion queue.
1016 * It is the same size as the start queue to avoid overflow.
1018 u_short dqueueget; /* Next position to scan */
1019 volatile /* Prevent code optimizations */
1020 u32 *dqueue; /* Completion (done) queue */
1021 u32 dqueue_ba; /* Done queue BUS address */
1024 * Miscellaneous buffers accessed by the scripts-processor.
1025 * They shall be DWORD aligned, because they may be read or
1026 * written with a script command.
1028 u_char msgout[8]; /* Buffer for MESSAGE OUT */
1029 u_char msgin [8]; /* Buffer for MESSAGE IN */
1030 u32 lastmsg; /* Last SCSI message sent */
1031 u32 scratch; /* Scratch for SCSI receive */
1032 /* Also used for cache test */
1034 * Miscellaneous configuration and status parameters.
1036 u_char usrflags; /* Miscellaneous user flags */
1037 u_char scsi_mode; /* Current SCSI BUS mode */
1038 u_char verbose; /* Verbosity for this controller*/
1041 * CCB lists and queue.
1043 ccb_p *ccbh; /* CCBs hashed by DSA value */
1044 /* CCB_HASH_SIZE lists of CCBs */
1045 SYM_QUEHEAD free_ccbq; /* Queue of available CCBs */
1046 SYM_QUEHEAD busy_ccbq; /* Queue of busy CCBs */
1049 * During error handling and/or recovery,
1050 * active CCBs that are to be completed with
1051 * error or requeued are moved from the busy_ccbq
1052 * to the comp_ccbq prior to completion.
1054 SYM_QUEHEAD comp_ccbq;
1056 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1057 SYM_QUEHEAD dummy_ccbq;
1060 * Optional handling of IO timeouts.
1062 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
1063 SYM_QUEHEAD tmo0_ccbq;
1064 SYM_QUEHEAD *tmo_ccbq; /* [2*SYM_TIMEOUT_ORDER_MAX] */
1070 * IMMEDIATE ARBITRATION (IARB) control.
1072 * We keep track in 'last_cp' of the last CCB that has been
1073 * queued to the SCRIPTS processor and clear 'last_cp' when
1074 * this CCB completes. If last_cp is not zero at the moment
1075 * we queue a new CCB, we set a flag in 'last_cp' that is
1076 * used by the SCRIPTS as a hint for setting IARB.
1077 * We donnot set more than 'iarb_max' consecutive hints for
1078 * IARB in order to leave devices a chance to reselect.
1079 * By the way, any non zero value of 'iarb_max' is unfair. :)
1081 #ifdef SYM_CONF_IARB_SUPPORT
1082 u_short iarb_max; /* Max. # consecutive IARB hints*/
1083 u_short iarb_count; /* Actual # of these hints */
1088 * Command abort handling.
1089 * We need to synchronize tightly with the SCRIPTS
1090 * processor in order to handle things correctly.
1092 u_char abrt_msg[4]; /* Message to send buffer */
1093 struct sym_tblmove abrt_tbl; /* Table for the MOV of it */
1094 struct sym_tblsel abrt_sel; /* Sync params for selection */
1095 u_char istat_sem; /* Tells the chip to stop (SEM) */
1098 * 64 bit DMA handling.
1100 #if SYM_CONF_DMA_ADDRESSING_MODE != 0
1101 u_char use_dac; /* Use PCI DAC cycles */
1102 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1103 u_char dmap_dirty; /* Dma segments registers dirty */
1104 u32 dmap_bah[SYM_DMAP_SIZE];/* Segment registers map */
1109 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl))
1113 * FIRMWARES (sym_fw.c)
1115 struct sym_fw * sym_find_firmware(struct sym_pci_chip *chip);
1116 void sym_fw_bind_script (hcb_p np, u32 *start, int len);
1119 * Driver methods called from O/S specific code.
1121 char *sym_driver_name(void);
1122 void sym_print_xerr(ccb_p cp, int x_status);
1123 int sym_reset_scsi_bus(hcb_p np, int enab_int);
1124 struct sym_pci_chip *
1125 sym_lookup_pci_chip_table (u_short device_id, u_char revision);
1126 void sym_put_start_queue(hcb_p np, ccb_p cp);
1127 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1128 void sym_start_next_ccbs(hcb_p np, lcb_p lp, int maxn);
1130 void sym_start_up (hcb_p np, int reason);
1131 void sym_interrupt (hcb_p np);
1132 void sym_flush_comp_queue(hcb_p np, int cam_status);
1133 int sym_clear_tasks(hcb_p np, int cam_status, int target, int lun, int task);
1134 ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order);
1135 void sym_free_ccb (hcb_p np, ccb_p cp);
1136 lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln);
1137 int sym_queue_scsiio(hcb_p np, cam_scsiio_p csio, ccb_p cp);
1138 int sym_abort_scsiio(hcb_p np, cam_ccb_p ccb, int timed_out);
1139 int sym_abort_ccb(hcb_p np, ccb_p cp, int timed_out);
1140 int sym_reset_scsi_target(hcb_p np, int target);
1141 void sym_hcb_free(hcb_p np);
1143 #ifdef SYM_OPT_NVRAM_PRE_READ
1144 int sym_hcb_attach(hcb_p np, struct sym_fw *fw, struct sym_nvram *nvram);
1146 int sym_hcb_attach(hcb_p np, struct sym_fw *fw);
1150 * Optionnaly, the driver may handle IO timeouts.
1152 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
1153 int sym_abort_ccb(hcb_p np, ccb_p cp, int timed_out);
1154 void sym_timeout_ccb(hcb_p np, ccb_p cp, u_int ticks);
1155 static void __inline sym_untimeout_ccb(hcb_p np, ccb_p cp)
1157 sym_remque(&cp->tmo_linkq);
1158 sym_insque_head(&cp->tmo_linkq, &np->tmo0_ccbq);
1160 void sym_clock(hcb_p np);
1161 #endif /* SYM_OPT_HANDLE_IO_TIMEOUT */
1164 * Optionnaly, the driver may provide a function
1165 * to announce transfer rate changes.
1167 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
1168 void sym_announce_transfer_rate(hcb_p np, int target);
1172 * Optionnaly, the driver may sniff inquiry data.
1174 #ifdef SYM_OPT_SNIFF_INQUIRY
1175 #define INQ7_CMDQ (0x02)
1176 #define INQ7_SYNC (0x10)
1177 #define INQ7_WIDE16 (0x20)
1179 #define INQ56_CLOCKING (3<<2)
1180 #define INQ56_ST_ONLY (0<<2)
1181 #define INQ56_DT_ONLY (1<<2)
1182 #define INQ56_ST_DT (3<<2)
1184 void sym_update_trans_settings(hcb_p np, tcb_p tp);
1186 __sym_sniff_inquiry(hcb_p np, u_char tn, u_char ln,
1187 u_char *inq_data, int inq_len);
1192 * Build a scatter/gather entry.
1194 * For 64 bit systems, we use the 8 upper bits of the size field
1195 * to provide bus address bits 32-39 to the SCRIPTS processor.
1196 * This allows the 895A, 896, 1010 to address up to 1 TB of memory.
1199 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
1200 #define sym_build_sge(np, data, badd, len) \
1202 (data)->addr = cpu_to_scr(badd); \
1203 (data)->size = cpu_to_scr(len); \
1205 #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
1206 #define sym_build_sge(np, data, badd, len) \
1208 (data)->addr = cpu_to_scr(badd); \
1209 (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len); \
1211 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1212 int sym_lookup_dmap(hcb_p np, u32 h, int s);
1213 static __inline void
1214 sym_build_sge(hcb_p np, struct sym_tblmove *data, u64 badd, int len)
1217 int s = (h&SYM_DMAP_MASK);
1219 if (h != np->dmap_bah[s])
1222 (data)->addr = cpu_to_scr(badd);
1223 (data)->size = cpu_to_scr((s<<24) + len);
1226 s = sym_lookup_dmap(np, h, s);
1230 #error "Unsupported DMA addressing mode"
1234 * Set up data pointers used by SCRIPTS.
1235 * Called from O/S specific code.
1237 static inline void sym_setup_data_pointers(struct sym_hcb *np,
1238 struct sym_ccb *cp, int dir)
1243 * No segments means no data.
1249 * Set the data pointer.
1252 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1253 case CAM_DIR_UNKNOWN:
1256 goalp = SCRIPTA_BA (np, data_out2) + 8;
1257 lastp = goalp - 8 - (cp->segments * (2*4));
1258 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1259 cp->wgoalp = cpu_to_scr(goalp);
1260 if (dir != CAM_DIR_UNKNOWN)
1262 cp->phys.head.wlastp = cpu_to_scr(lastp);
1268 cp->host_flags |= HF_DATA_IN;
1269 goalp = SCRIPTA_BA (np, data_in2) + 8;
1270 lastp = goalp - 8 - (cp->segments * (2*4));
1274 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1275 cp->host_flags |= HF_DATA_IN;
1277 lastp = goalp = SCRIPTB_BA (np, no_data);
1282 * Set all pointers values needed by SCRIPTS.
1284 cp->phys.head.lastp = cpu_to_scr(lastp);
1285 cp->phys.head.savep = cpu_to_scr(lastp);
1286 cp->startp = cp->phys.head.savep;
1287 cp->goalp = cpu_to_scr(goalp);
1289 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1291 * If direction is unknown, start at data_io.
1293 if (dir == CAM_DIR_UNKNOWN)
1294 cp->phys.head.savep = cpu_to_scr(SCRIPTB_BA (np, data_io));
1303 * Link between free memory chunks of a given size.
1305 typedef struct sym_m_link {
1306 struct sym_m_link *next;
1310 * Virtual to bus physical translation for a given cluster.
1311 * Such a structure is only useful with DMA abstraction.
1313 typedef struct sym_m_vtob { /* Virtual to Bus address translation */
1314 struct sym_m_vtob *next;
1315 #ifdef SYM_HAVE_M_SVTOB
1316 struct sym_m_svtob s; /* OS specific data structure */
1318 m_addr_t vaddr; /* Virtual address */
1319 m_addr_t baddr; /* Bus physical address */
1322 /* Hash this stuff a bit to speed up translations */
1323 #define VTOB_HASH_SHIFT 5
1324 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
1325 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
1326 #define VTOB_HASH_CODE(m) \
1327 ((((m_addr_t) (m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK)
1330 * Memory pool of a given kind.
1331 * Ideally, we want to use:
1332 * 1) 1 pool for memory we donnot need to involve in DMA.
1333 * 2) The same pool for controllers that require same DMA
1334 * constraints and features.
1335 * The OS specific m_pool_id_t thing and the sym_m_pool_match()
1336 * method are expected to tell the driver about.
1338 typedef struct sym_m_pool {
1339 m_pool_ident_t dev_dmat; /* Identifies the pool (see above) */
1340 m_addr_t (*get_mem_cluster)(struct sym_m_pool *);
1341 #ifdef SYM_MEM_FREE_UNUSED
1342 void (*free_mem_cluster)(struct sym_m_pool *, m_addr_t);
1344 #define M_GET_MEM_CLUSTER() mp->get_mem_cluster(mp)
1345 #define M_FREE_MEM_CLUSTER(p) mp->free_mem_cluster(mp, p)
1346 #ifdef SYM_HAVE_M_SPOOL
1347 struct sym_m_spool s; /* OS specific data structure */
1350 m_vtob_p vtob[VTOB_HASH_SIZE];
1351 struct sym_m_pool *next;
1352 struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
1356 * Alloc and free non DMAable memory.
1358 void sym_mfree_unlocked(void *ptr, int size, char *name);
1359 void *sym_calloc_unlocked(int size, char *name);
1362 * Alloc, free and translate addresses to bus physical
1363 * for DMAable memory.
1365 void *__sym_calloc_dma_unlocked(m_pool_ident_t dev_dmat, int size, char *name);
1367 __sym_mfree_dma_unlocked(m_pool_ident_t dev_dmat, void *m,int size, char *name);
1368 u32 __vtobus_unlocked(m_pool_ident_t dev_dmat, void *m);
1371 * Verbs used by the driver code for DMAable memory handling.
1372 * The _uvptv_ macro avoids a nasty warning about pointer to volatile
1375 #define _uvptv_(p) ((void *)((u_long)(p)))
1377 #define _sym_calloc_dma(np, l, n) __sym_calloc_dma(np->bus_dmat, l, n)
1378 #define _sym_mfree_dma(np, p, l, n) \
1379 __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n)
1380 #define sym_calloc_dma(l, n) _sym_calloc_dma(np, l, n)
1381 #define sym_mfree_dma(p, l, n) _sym_mfree_dma(np, p, l, n)
1382 #define _vtobus(np, p) __vtobus(np->bus_dmat, _uvptv_(p))
1383 #define vtobus(p) _vtobus(np, p)
1386 * Override some function names.
1388 #define PRINT_ADDR sym_print_addr
1389 #define PRINT_TARGET sym_print_target
1390 #define PRINT_LUN sym_print_lun
1391 #define MDELAY sym_mdelay
1392 #define UDELAY sym_udelay
1394 #endif /* SYM_HIPD_H */