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_NO_BUS_MEMORY_MAPPING
63 * When this option is set, the driver will not load the
64 * on-chip RAM using MMIO, but let the SCRIPTS processor
65 * do the work using MOVE MEMORY instructions.
68 * SYM_OPT_HANDLE_DIR_UNKNOWN
69 * When this option is set, the SCRIPTS used by the driver
70 * are able to handle SCSI transfers with direction not
72 * (set for Linux-2.0.X)
74 * SYM_OPT_HANDLE_DEVICE_QUEUEING
75 * When this option is set, the driver will use a queue per
76 * device and handle QUEUE FULL status requeuing internally.
78 * SYM_OPT_BUS_DMA_ABSTRACTION
79 * When this option is set, the driver allocator is responsible
80 * of maintaining bus physical addresses and so provides virtual
81 * to bus physical address translation of driver data structures.
82 * (set for FreeBSD-4 and Linux 2.3)
84 * SYM_OPT_SNIFF_INQUIRY
85 * When this option is set, the driver sniff out successful
86 * INQUIRY response and performs negotiations accordingly.
89 * SYM_OPT_LIMIT_COMMAND_REORDERING
90 * When this option is set, the driver tries to limit tagged
91 * command reordering to some reasonnable value.
95 #define SYM_OPT_NO_BUS_MEMORY_MAPPING
96 #define SYM_OPT_HANDLE_DIR_UNKNOWN
97 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
98 #define SYM_OPT_BUS_DMA_ABSTRACTION
99 #define SYM_OPT_SNIFF_INQUIRY
100 #define SYM_OPT_LIMIT_COMMAND_REORDERING
104 * Active debugging tags and verbosity.
105 * Both DEBUG_FLAGS and sym_verbose can be redefined
106 * by the platform specific code to something else.
108 #define DEBUG_ALLOC (0x0001)
109 #define DEBUG_PHASE (0x0002)
110 #define DEBUG_POLL (0x0004)
111 #define DEBUG_QUEUE (0x0008)
112 #define DEBUG_RESULT (0x0010)
113 #define DEBUG_SCATTER (0x0020)
114 #define DEBUG_SCRIPT (0x0040)
115 #define DEBUG_TINY (0x0080)
116 #define DEBUG_TIMING (0x0100)
117 #define DEBUG_NEGO (0x0200)
118 #define DEBUG_TAGS (0x0400)
119 #define DEBUG_POINTER (0x0800)
122 #define DEBUG_FLAGS (0x0000)
126 #define sym_verbose (np->verbose)
130 * These ones should have been already defined.
133 #define offsetof(t, m) ((size_t) (&((t *)0)->m))
136 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
139 #define assert(expression) { \
140 if (!(expression)) { \
142 "assertion \"%s\" failed: file \"%s\", line %d\n", \
144 __FILE__, __LINE__); \
150 * Number of tasks per device we want to handle.
152 #if SYM_CONF_MAX_TAG_ORDER > 8
153 #error "more than 256 tags per logical unit not allowed."
155 #define SYM_CONF_MAX_TASK (1<<SYM_CONF_MAX_TAG_ORDER)
158 * Donnot use more tasks that we can handle.
160 #ifndef SYM_CONF_MAX_TAG
161 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
163 #if SYM_CONF_MAX_TAG > SYM_CONF_MAX_TASK
164 #undef SYM_CONF_MAX_TAG
165 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
169 * This one means 'NO TAG for this job'
174 * Number of SCSI targets.
176 #if SYM_CONF_MAX_TARGET > 16
177 #error "more than 16 targets not allowed."
181 * Number of logical units per target.
183 #if SYM_CONF_MAX_LUN > 64
184 #error "more than 64 logical units per target not allowed."
188 * Asynchronous pre-scaler (ns). Shall be 40 for
189 * the SCSI timings to be compliant.
191 #define SYM_CONF_MIN_ASYNC (40)
194 * Number of entries in the START and DONE queues.
196 * We limit to 1 PAGE in order to succeed allocation of
197 * these queues. Each entry is 8 bytes long (2 DWORDS).
199 #ifdef SYM_CONF_MAX_START
200 #define SYM_CONF_MAX_QUEUE (SYM_CONF_MAX_START+2)
202 #define SYM_CONF_MAX_QUEUE (7*SYM_CONF_MAX_TASK+2)
203 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
206 #if SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8
207 #undef SYM_CONF_MAX_QUEUE
208 #define SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8)
209 #undef SYM_CONF_MAX_START
210 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
214 * For this one, we want a short name :-)
216 #define MAX_QUEUE SYM_CONF_MAX_QUEUE
219 * Union of supported NVRAM formats.
223 #define SYM_SYMBIOS_NVRAM (1)
224 #define SYM_TEKRAM_NVRAM (2)
225 #if SYM_CONF_NVRAM_SUPPORT
227 Symbios_nvram Symbios;
234 * Common definitions for both bus space based and legacy IO methods.
236 #define INB(r) INB_OFF(offsetof(struct sym_reg,r))
237 #define INW(r) INW_OFF(offsetof(struct sym_reg,r))
238 #define INL(r) INL_OFF(offsetof(struct sym_reg,r))
240 #define OUTB(r, v) OUTB_OFF(offsetof(struct sym_reg,r), (v))
241 #define OUTW(r, v) OUTW_OFF(offsetof(struct sym_reg,r), (v))
242 #define OUTL(r, v) OUTL_OFF(offsetof(struct sym_reg,r), (v))
244 #define OUTONB(r, m) OUTB(r, INB(r) | (m))
245 #define OUTOFFB(r, m) OUTB(r, INB(r) & ~(m))
246 #define OUTONW(r, m) OUTW(r, INW(r) | (m))
247 #define OUTOFFW(r, m) OUTW(r, INW(r) & ~(m))
248 #define OUTONL(r, m) OUTL(r, INL(r) | (m))
249 #define OUTOFFL(r, m) OUTL(r, INL(r) & ~(m))
252 * We normally want the chip to have a consistent view
253 * of driver internal data structures when we restart it.
256 #define OUTL_DSP(v) \
258 MEMORY_WRITE_BARRIER(); \
259 OUTL (nc_dsp, (v)); \
262 #define OUTONB_STD() \
264 MEMORY_WRITE_BARRIER(); \
265 OUTONB (nc_dcntl, (STD|NOCOM)); \
269 * Command control block states.
273 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
274 #define HS_DISCONNECT (3) /* Disconnected by target */
275 #define HS_WAIT (4) /* waiting for resource */
277 #define HS_DONEMASK (0x80)
278 #define HS_COMPLETE (4|HS_DONEMASK)
279 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
280 #define HS_UNEXPECTED (6|HS_DONEMASK) /* Unexpected disconnect */
281 #define HS_COMP_ERR (7|HS_DONEMASK) /* Completed with error */
284 * Software Interrupt Codes
286 #define SIR_BAD_SCSI_STATUS (1)
287 #define SIR_SEL_ATN_NO_MSG_OUT (2)
288 #define SIR_MSG_RECEIVED (3)
289 #define SIR_MSG_WEIRD (4)
290 #define SIR_NEGO_FAILED (5)
291 #define SIR_NEGO_PROTO (6)
292 #define SIR_SCRIPT_STOPPED (7)
293 #define SIR_REJECT_TO_SEND (8)
294 #define SIR_SWIDE_OVERRUN (9)
295 #define SIR_SODL_UNDERRUN (10)
296 #define SIR_RESEL_NO_MSG_IN (11)
297 #define SIR_RESEL_NO_IDENTIFY (12)
298 #define SIR_RESEL_BAD_LUN (13)
299 #define SIR_TARGET_SELECTED (14)
300 #define SIR_RESEL_BAD_I_T_L (15)
301 #define SIR_RESEL_BAD_I_T_L_Q (16)
302 #define SIR_ABORT_SENT (17)
303 #define SIR_RESEL_ABORTED (18)
304 #define SIR_MSG_OUT_DONE (19)
305 #define SIR_COMPLETE_ERROR (20)
306 #define SIR_DATA_OVERRUN (21)
307 #define SIR_BAD_PHASE (22)
308 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
309 #define SIR_DMAP_DIRTY (23)
316 * Extended error bit codes.
317 * xerr_status field of struct sym_ccb.
319 #define XE_EXTRA_DATA (1) /* unexpected data phase */
320 #define XE_BAD_PHASE (1<<1) /* illegal phase (4/5) */
321 #define XE_PARITY_ERR (1<<2) /* unrecovered SCSI parity error */
322 #define XE_SODL_UNRUN (1<<3) /* ODD transfer in DATA OUT phase */
323 #define XE_SWIDE_OVRUN (1<<4) /* ODD transfer in DATA IN phase */
326 * Negotiation status.
327 * nego_status field of struct sym_ccb.
334 * A CCB hashed table is used to retrieve CCB address
337 #define CCB_HASH_SHIFT 8
338 #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT)
339 #define CCB_HASH_MASK (CCB_HASH_SIZE-1)
341 #define CCB_HASH_CODE(dsa) \
342 (((dsa) >> (_LGRU16_(sizeof(struct sym_ccb)))) & CCB_HASH_MASK)
344 #define CCB_HASH_CODE(dsa) (((dsa) >> 9) & CCB_HASH_MASK)
347 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
349 * We may want to use segment registers for 64 bit DMA.
350 * 16 segments registers -> up to 64 GB addressable.
352 #define SYM_DMAP_SHIFT (4)
353 #define SYM_DMAP_SIZE (1u<<SYM_DMAP_SHIFT)
354 #define SYM_DMAP_MASK (SYM_DMAP_SIZE-1)
360 #define SYM_DISC_ENABLED (1)
361 #define SYM_TAGS_ENABLED (1<<1)
362 #define SYM_SCAN_BOOT_DISABLED (1<<2)
363 #define SYM_SCAN_LUNS_DISABLED (1<<3)
366 * Host adapter miscellaneous flags.
368 #define SYM_AVOID_BUS_RESET (1)
369 #define SYM_SCAN_TARGETS_HILO (1<<1)
374 #define SYM_SNOOP_TIMEOUT (10000000)
379 * Gather negotiable parameters value
387 u8 options; /* PPR options */
391 struct sym_trans curr;
392 struct sym_trans goal;
393 struct sym_trans user;
394 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
395 struct sym_trans prev;
402 * Due to lack of indirect addressing on earlier NCR chips,
403 * this substructure is copied from the TCB to a global
404 * address after selection.
405 * For SYMBIOS chips that support LOAD/STORE this copy is
406 * not needed and thus not performed.
410 * Scripts bus addresses of LUN table accessed from scripts.
411 * LUN #0 is a special case, since multi-lun devices are rare,
412 * and we we want to speed-up the general case and not waste
415 u32 luntbl_sa; /* bus address of this table */
416 u32 lun0_sa; /* bus address of LCB #0 */
418 * Actual SYNC/WIDE IO registers value for this target.
419 * 'sval', 'wval' and 'uval' are read from SCRIPTS and
420 * so have alignment constraints.
422 /*0*/ u_char uval; /* -> SCNTL4 register */
423 /*1*/ u_char sval; /* -> SXFER io register */
424 /*2*/ u_char filler1;
425 /*3*/ u_char wval; /* -> SCNTL3 io register */
429 * Target Control Block
434 * Assumed at offset 0.
436 /*0*/ struct sym_tcbh head;
439 * LUN table used by the SCRIPTS processor.
440 * An array of bus addresses is used on reselection.
442 u32 *luntbl; /* LCBs bus address table */
445 * LUN table used by the C code.
447 lcb_p lun0p; /* LCB of LUN #0 (usual case) */
448 #if SYM_CONF_MAX_LUN > 1
449 lcb_p *lunmp; /* Other LCBs [1..MAX_LUN] */
453 * Bitmap that tells about LUNs that succeeded at least
454 * 1 IO and therefore assumed to be a real device.
455 * Avoid useless allocation of the LCB structure.
457 u32 lun_map[(SYM_CONF_MAX_LUN+31)/32];
460 * Bitmap that tells about LUNs that haven't yet an LCB
461 * allocated (not discovered or LCB allocation failed).
463 u32 busy0_map[(SYM_CONF_MAX_LUN+31)/32];
467 * O/S specific data structure.
473 * Transfer capabilities (SIP)
475 struct sym_tinfo tinfo;
478 * Keep track of the CCB used for the negotiation in order
479 * to ensure that only 1 negotiation is queued at a time.
481 ccb_p nego_cp; /* CCB used for the nego */
484 * Set when we want to reset the device.
489 * Other user settable limits and options.
490 * These limits are read from the NVRAM if present.
495 #ifdef SYM_OPT_SNIFF_INQUIRY
497 * Some minimal information from INQUIRY response.
499 u32 cmdq_map[(SYM_CONF_MAX_LUN+31)/32];
503 u_char inq_byte7_valid;
511 * Due to lack of indirect addressing on earlier NCR chips,
512 * this substructure is copied from the LCB to a global
513 * address after selection.
514 * For SYMBIOS chips that support LOAD/STORE this copy is
515 * not needed and thus not performed.
519 * SCRIPTS address jumped by SCRIPTS on reselection.
520 * For not probed logical units, this address points to
521 * SCRIPTS that deal with bad LU handling (must be at
522 * offset zero of the LCB for that reason).
527 * Task (bus address of a CCB) read from SCRIPTS that points
528 * to the unique ITL nexus allowed to be disconnected.
533 * Task table bus address (read from SCRIPTS).
539 * Logical Unit Control Block
544 * Assumed at offset 0.
546 /*0*/ struct sym_lcbh head;
549 * Task table read from SCRIPTS that contains pointers to
550 * ITLQ nexuses. The bus address read from SCRIPTS is
553 u32 *itlq_tbl; /* Kernel virtual address */
556 * Busy CCBs management.
558 u_short busy_itlq; /* Number of busy tagged CCBs */
559 u_short busy_itl; /* Number of busy untagged CCBs */
562 * Circular tag allocation buffer.
564 u_short ia_tag; /* Tag allocation index */
565 u_short if_tag; /* Tag release index */
566 u_char *cb_tags; /* Circular tags buffer */
569 * O/S specific data structure.
575 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
577 * Optionnaly the driver can handle device queueing,
578 * and requeues internally command to redo.
585 u_short started_tags;
586 u_short started_no_tag;
588 u_short started_limit;
591 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
593 * Optionnaly the driver can try to prevent SCSI
594 * IOs from being too much reordering.
596 u_char tags_si; /* Current index to tags sum */
597 u_short tags_sum[2]; /* Tags sum counters */
598 u_short tags_since; /* # of tags since last switch */
602 * Set when we want to clear all tasks.
614 * Action from SCRIPTS on a task.
615 * Is part of the CCB, but is also used separately to plug
616 * error handling action to perform from SCRIPTS.
619 u32 start; /* Jumped by SCRIPTS after selection */
620 u32 restart; /* Jumped by SCRIPTS on relection */
624 * Phase mismatch context.
626 * It is part of the CCB and is used as parameters for the
627 * DATA pointer. We need two contexts to handle correctly the
628 * SAVED DATA POINTER.
631 struct sym_tblmove sg; /* Updated interrupted SG block */
632 u32 ret; /* SCRIPT return address */
636 * LUN control block lookup.
637 * We use a direct pointer for LUN #0, and a table of
638 * pointers which is only allocated for devices that support
641 #if SYM_CONF_MAX_LUN <= 1
642 #define sym_lp(np, tp, lun) (!lun) ? (tp)->lun0p : 0
644 #define sym_lp(np, tp, lun) \
645 (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[(lun)] : 0
649 * Status are used by the host and the script processor.
651 * The last four bytes (status[4]) are copied to the
652 * scratchb register (declared as scr0..scr3) just after the
653 * select/reselect, and copied back just after disconnecting.
654 * Inside the script the XX_REG are used.
658 * Last four bytes (script)
661 #define HX_PRT nc_scr0
663 #define HS_PRT nc_scr1
665 #define SS_PRT nc_scr2
667 #define HF_PRT nc_scr3
670 * Last four bytes (host)
672 #define host_xflags phys.head.status[0]
673 #define host_status phys.head.status[1]
674 #define ssss_status phys.head.status[2]
675 #define host_flags phys.head.status[3]
681 #define HF_IN_PM1 (1u<<1)
682 #define HF_ACT_PM (1u<<2)
683 #define HF_DP_SAVED (1u<<3)
684 #define HF_SENSE (1u<<4)
685 #define HF_EXT_ERR (1u<<5)
686 #define HF_DATA_IN (1u<<6)
687 #ifdef SYM_CONF_IARB_SUPPORT
688 #define HF_HINT_IARB (1u<<7)
694 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
695 #define HX_DMAP_DIRTY (1u<<7)
701 * Due to lack of indirect addressing on earlier NCR chips,
702 * this substructure is copied from the ccb to a global
703 * address after selection (or reselection) and copied back
705 * For SYMBIOS chips that support LOAD/STORE this copy is
706 * not needed and thus not performed.
711 * Start and restart SCRIPTS addresses (must be at 0).
713 /*0*/ struct sym_actscr go;
716 * SCRIPTS jump address that deal with data pointers.
717 * 'savep' points to the position in the script responsible
718 * for the actual transfer of data.
719 * It's written on reception of a SAVE_DATA_POINTER message.
721 u32 savep; /* Jump address to saved data pointer */
722 u32 lastp; /* SCRIPTS address at end of data */
723 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
734 * GET/SET the value of the data pointer used by SCRIPTS.
736 * We must distinguish between the LOAD/STORE-based SCRIPTS
737 * that use directly the header in the CCB, and the NCR-GENERIC
738 * SCRIPTS that use the copy of the header in the HCB.
740 #if SYM_CONF_GENERIC_SUPPORT
741 #define sym_set_script_dp(np, cp, dp) \
743 if (np->features & FE_LDSTR) \
744 cp->phys.head.lastp = cpu_to_scr(dp); \
746 np->ccb_head.lastp = cpu_to_scr(dp); \
748 #define sym_get_script_dp(np, cp) \
749 scr_to_cpu((np->features & FE_LDSTR) ? \
750 cp->phys.head.lastp : np->ccb_head.lastp)
752 #define sym_set_script_dp(np, cp, dp) \
754 cp->phys.head.lastp = cpu_to_scr(dp); \
757 #define sym_get_script_dp(np, cp) (cp->phys.head.lastp)
761 * Data Structure Block
763 * During execution of a ccb by the script processor, the
764 * DSA (data structure address) register points to this
765 * substructure of the ccb.
770 * Also assumed at offset 0 of the sym_ccb structure.
772 /*0*/ struct sym_ccbh head;
775 * Phase mismatch contexts.
776 * We need two to handle correctly the SAVED DATA POINTER.
777 * MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic
778 * for address calculation from SCRIPTS.
784 * Table data for Script
786 struct sym_tblsel select;
787 struct sym_tblmove smsg;
788 struct sym_tblmove smsg_ext;
789 struct sym_tblmove cmd;
790 struct sym_tblmove sense;
791 struct sym_tblmove wresid;
792 struct sym_tblmove data [SYM_CONF_MAX_SG];
796 * Our Command Control Block
800 * This is the data structure which is pointed by the DSA
801 * register when it is executed by the script processor.
802 * It must be the first entry.
807 * Pointer to CAM ccb and related stuff.
809 cam_ccb_p cam_ccb; /* CAM scsiio ccb */
810 u8 cdb_buf[16]; /* Copy of CDB */
811 u8 *sns_bbuf; /* Bounce buffer for sense data */
812 #ifndef SYM_SNS_BBUF_LEN
813 #define SYM_SNS_BBUF_LEN (32)
815 int data_len; /* Total data length */
816 int segments; /* Number of SG segments */
818 u8 order; /* Tag type (if tagged command) */
821 * Miscellaneous status'.
823 u_char nego_status; /* Negotiation status */
824 u_char xerr_status; /* Extended error flags */
825 u32 extra_bytes; /* Extraneous bytes transferred */
829 * We prepare a message to be sent after selection.
830 * We may use a second one if the command is rescheduled
831 * due to CHECK_CONDITION or COMMAND TERMINATED.
832 * Contents are IDENTIFY and SIMPLE_TAG.
833 * While negotiating sync or wide transfer,
834 * a SDTR or WDTR message is appended.
836 u_char scsi_smsg [12];
837 u_char scsi_smsg2[12];
840 * Auto request sense related fields.
842 u_char sensecmd[6]; /* Request Sense command */
843 u_char sv_scsi_status; /* Saved SCSI status */
844 u_char sv_xerr_status; /* Saved extended status */
845 int sv_resid; /* Saved residual */
848 * O/S specific data structure.
856 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
857 SYM_QUEHEAD tmo_linkq; /* Optional timeout handling */
858 u_int tmo_clock; /* (link and dealine value) */
860 u32 ccb_ba; /* BUS address of this CCB */
861 u_short tag; /* Tag for this transfer */
862 /* NO_TAG means no tag */
865 ccb_p link_ccbh; /* Host adapter CCB hash chain */
867 link_ccbq; /* Link to free/busy CCB queue */
868 u32 startp; /* Initial data pointer */
869 u32 goalp; /* Expected last data pointer */
870 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
873 int ext_sg; /* Extreme data pointer, used */
874 int ext_ofs; /* to calculate the residual. */
875 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
877 link2_ccbq; /* Link for device queueing */
878 u_char started; /* CCB queued to the squeue */
880 u_char to_abort; /* Want this IO to be aborted */
881 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
882 u_char tags_si; /* Lun tags sum index (0,1) */
886 #define CCB_BA(cp,lbl) (cp->ccb_ba + offsetof(struct sym_ccb, lbl))
888 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
889 #define sym_goalp(cp) ((cp->host_flags & HF_DATA_IN) ? cp->goalp : cp->wgoalp)
891 #define sym_goalp(cp) (cp->goalp)
900 * Due to poorness of addressing capabilities, earlier
901 * chips (810, 815, 825) copy part of the data structures
902 * (CCB, TCB and LCB) in fixed areas.
904 #if SYM_CONF_GENERIC_SUPPORT
905 struct sym_ccbh ccb_head;
906 struct sym_tcbh tcb_head;
907 struct sym_lcbh lcb_head;
910 * Idle task and invalid task actions and
911 * their bus addresses.
913 struct sym_actscr idletask, notask, bad_itl, bad_itlq;
914 u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba;
917 * Dummy lun table to protect us against target
918 * returning bad lun number on reselection.
920 u32 *badluntbl; /* Table physical address */
921 u32 badlun_sa; /* SCRIPT handler BUS address */
924 * Bus address of this host control block.
929 * Bit 32-63 of the on-chip RAM bus address in LE format.
930 * The START_RAM64 script loads the MMRS and MMWS from this
936 * Initial value of some IO register bits.
937 * These values are assumed to have been set by BIOS, and may
938 * be used to probe adapter implementation differences.
940 u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
941 sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4,
945 * Actual initial value of IO register bits used by the
946 * driver. They are loaded at initialisation according to
947 * features that are to be enabled/disabled.
949 u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4,
950 rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4;
955 struct sym_tcb target[SYM_CONF_MAX_TARGET];
958 * Target control block bus address array used by the SCRIPT
965 * DMA pool handle for this HBA.
967 #ifdef SYM_OPT_BUS_DMA_ABSTRACTION
968 m_pool_ident_t bus_dmat;
972 * O/S specific data structure
977 * Physical bus addresses of the chip.
979 u32 mmio_ba; /* MMIO 32 bit BUS address */
980 int mmio_ws; /* MMIO Window size */
982 u32 ram_ba; /* RAM 32 bit BUS address */
983 int ram_ws; /* RAM window size */
986 * SCRIPTS virtual and physical bus addresses.
987 * 'script' is loaded in the on-chip RAM if present.
988 * 'scripth' stays in main memory for all chips except the
989 * 53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM.
991 u_char *scripta0; /* Copy of scripts A, B, Z */
994 u32 scripta_ba; /* Actual scripts A, B, Z */
995 u32 scriptb_ba; /* 32 bit bus addresses. */
997 u_short scripta_sz; /* Actual size of script A, B, Z*/
1002 * Bus addresses, setup and patch methods for
1003 * the selected firmware.
1005 struct sym_fwa_ba fwa_bas; /* Useful SCRIPTA bus addresses */
1006 struct sym_fwb_ba fwb_bas; /* Useful SCRIPTB bus addresses */
1007 struct sym_fwz_ba fwz_bas; /* Useful SCRIPTZ bus addresses */
1008 void (*fw_setup)(hcb_p np, struct sym_fw *fw);
1009 void (*fw_patch)(hcb_p np);
1013 * General controller parameters and configuration.
1015 u_short device_id; /* PCI device id */
1016 u_char revision_id; /* PCI device revision id */
1017 u_int features; /* Chip features map */
1018 u_char myaddr; /* SCSI id of the adapter */
1019 u_char maxburst; /* log base 2 of dwords burst */
1020 u_char maxwide; /* Maximum transfer width */
1021 u_char minsync; /* Min sync period factor (ST) */
1022 u_char maxsync; /* Max sync period factor (ST) */
1023 u_char maxoffs; /* Max scsi offset (ST) */
1024 u_char minsync_dt; /* Min sync period factor (DT) */
1025 u_char maxsync_dt; /* Max sync period factor (DT) */
1026 u_char maxoffs_dt; /* Max scsi offset (DT) */
1027 u_char multiplier; /* Clock multiplier (1,2,4) */
1028 u_char clock_divn; /* Number of clock divisors */
1029 u32 clock_khz; /* SCSI clock frequency in KHz */
1030 u32 pciclk_khz; /* Estimated PCI clock in KHz */
1032 * Start queue management.
1033 * It is filled up by the host processor and accessed by the
1034 * SCRIPTS processor in order to start SCSI commands.
1036 volatile /* Prevent code optimizations */
1037 u32 *squeue; /* Start queue virtual address */
1038 u32 squeue_ba; /* Start queue BUS address */
1039 u_short squeueput; /* Next free slot of the queue */
1040 u_short actccbs; /* Number of allocated CCBs */
1043 * Command completion queue.
1044 * It is the same size as the start queue to avoid overflow.
1046 u_short dqueueget; /* Next position to scan */
1047 volatile /* Prevent code optimizations */
1048 u32 *dqueue; /* Completion (done) queue */
1049 u32 dqueue_ba; /* Done queue BUS address */
1052 * Miscellaneous buffers accessed by the scripts-processor.
1053 * They shall be DWORD aligned, because they may be read or
1054 * written with a script command.
1056 u_char msgout[8]; /* Buffer for MESSAGE OUT */
1057 u_char msgin [8]; /* Buffer for MESSAGE IN */
1058 u32 lastmsg; /* Last SCSI message sent */
1059 u32 scratch; /* Scratch for SCSI receive */
1060 /* Also used for cache test */
1062 * Miscellaneous configuration and status parameters.
1064 u_char usrflags; /* Miscellaneous user flags */
1065 u_char scsi_mode; /* Current SCSI BUS mode */
1066 u_char verbose; /* Verbosity for this controller*/
1069 * CCB lists and queue.
1071 ccb_p *ccbh; /* CCBs hashed by DSA value */
1072 /* CCB_HASH_SIZE lists of CCBs */
1073 SYM_QUEHEAD free_ccbq; /* Queue of available CCBs */
1074 SYM_QUEHEAD busy_ccbq; /* Queue of busy CCBs */
1077 * During error handling and/or recovery,
1078 * active CCBs that are to be completed with
1079 * error or requeued are moved from the busy_ccbq
1080 * to the comp_ccbq prior to completion.
1082 SYM_QUEHEAD comp_ccbq;
1084 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1085 SYM_QUEHEAD dummy_ccbq;
1088 * Optional handling of IO timeouts.
1090 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
1091 SYM_QUEHEAD tmo0_ccbq;
1092 SYM_QUEHEAD *tmo_ccbq; /* [2*SYM_TIMEOUT_ORDER_MAX] */
1098 * IMMEDIATE ARBITRATION (IARB) control.
1100 * We keep track in 'last_cp' of the last CCB that has been
1101 * queued to the SCRIPTS processor and clear 'last_cp' when
1102 * this CCB completes. If last_cp is not zero at the moment
1103 * we queue a new CCB, we set a flag in 'last_cp' that is
1104 * used by the SCRIPTS as a hint for setting IARB.
1105 * We donnot set more than 'iarb_max' consecutive hints for
1106 * IARB in order to leave devices a chance to reselect.
1107 * By the way, any non zero value of 'iarb_max' is unfair. :)
1109 #ifdef SYM_CONF_IARB_SUPPORT
1110 u_short iarb_max; /* Max. # consecutive IARB hints*/
1111 u_short iarb_count; /* Actual # of these hints */
1116 * Command abort handling.
1117 * We need to synchronize tightly with the SCRIPTS
1118 * processor in order to handle things correctly.
1120 u_char abrt_msg[4]; /* Message to send buffer */
1121 struct sym_tblmove abrt_tbl; /* Table for the MOV of it */
1122 struct sym_tblsel abrt_sel; /* Sync params for selection */
1123 u_char istat_sem; /* Tells the chip to stop (SEM) */
1126 * 64 bit DMA handling.
1128 #if SYM_CONF_DMA_ADDRESSING_MODE != 0
1129 u_char use_dac; /* Use PCI DAC cycles */
1130 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1131 u_char dmap_dirty; /* Dma segments registers dirty */
1132 u32 dmap_bah[SYM_DMAP_SIZE];/* Segment registers map */
1137 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl))
1140 * NVRAM reading (sym_nvram.c).
1142 void sym_nvram_setup_host (hcb_p np, struct sym_nvram *nvram);
1143 void sym_nvram_setup_target (hcb_p np, int target, struct sym_nvram *nvp);
1144 int sym_read_nvram (sdev_p np, struct sym_nvram *nvp);
1147 * FIRMWARES (sym_fw.c)
1149 struct sym_fw * sym_find_firmware(struct sym_pci_chip *chip);
1150 void sym_fw_bind_script (hcb_p np, u32 *start, int len);
1153 * Driver methods called from O/S specific code.
1155 char *sym_driver_name(void);
1156 void sym_print_xerr(ccb_p cp, int x_status);
1157 int sym_reset_scsi_bus(hcb_p np, int enab_int);
1158 struct sym_pci_chip *
1159 sym_lookup_pci_chip_table (u_short device_id, u_char revision);
1160 void sym_put_start_queue(hcb_p np, ccb_p cp);
1161 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1162 void sym_start_next_ccbs(hcb_p np, lcb_p lp, int maxn);
1164 void sym_start_up (hcb_p np, int reason);
1165 void sym_interrupt (hcb_p np);
1166 void sym_flush_comp_queue(hcb_p np, int cam_status);
1167 int sym_clear_tasks(hcb_p np, int cam_status, int target, int lun, int task);
1168 ccb_p sym_get_ccb (hcb_p np, u_char tn, u_char ln, u_char tag_order);
1169 void sym_free_ccb (hcb_p np, ccb_p cp);
1170 lcb_p sym_alloc_lcb (hcb_p np, u_char tn, u_char ln);
1171 int sym_queue_scsiio(hcb_p np, cam_scsiio_p csio, ccb_p cp);
1172 int sym_abort_scsiio(hcb_p np, cam_ccb_p ccb, int timed_out);
1173 int sym_abort_ccb(hcb_p np, ccb_p cp, int timed_out);
1174 int sym_reset_scsi_target(hcb_p np, int target);
1175 void sym_hcb_free(hcb_p np);
1177 #ifdef SYM_OPT_NVRAM_PRE_READ
1178 int sym_hcb_attach(hcb_p np, struct sym_fw *fw, struct sym_nvram *nvram);
1180 int sym_hcb_attach(hcb_p np, struct sym_fw *fw);
1184 * Optionnaly, the driver may handle IO timeouts.
1186 #ifdef SYM_OPT_HANDLE_IO_TIMEOUT
1187 int sym_abort_ccb(hcb_p np, ccb_p cp, int timed_out);
1188 void sym_timeout_ccb(hcb_p np, ccb_p cp, u_int ticks);
1189 static void __inline sym_untimeout_ccb(hcb_p np, ccb_p cp)
1191 sym_remque(&cp->tmo_linkq);
1192 sym_insque_head(&cp->tmo_linkq, &np->tmo0_ccbq);
1194 void sym_clock(hcb_p np);
1195 #endif /* SYM_OPT_HANDLE_IO_TIMEOUT */
1198 * Optionnaly, the driver may provide a function
1199 * to announce transfer rate changes.
1201 #ifdef SYM_OPT_ANNOUNCE_TRANSFER_RATE
1202 void sym_announce_transfer_rate(hcb_p np, int target);
1206 * Optionnaly, the driver may sniff inquiry data.
1208 #ifdef SYM_OPT_SNIFF_INQUIRY
1209 #define INQ7_CMDQ (0x02)
1210 #define INQ7_SYNC (0x10)
1211 #define INQ7_WIDE16 (0x20)
1213 #define INQ56_CLOCKING (3<<2)
1214 #define INQ56_ST_ONLY (0<<2)
1215 #define INQ56_DT_ONLY (1<<2)
1216 #define INQ56_ST_DT (3<<2)
1218 void sym_update_trans_settings(hcb_p np, tcb_p tp);
1220 __sym_sniff_inquiry(hcb_p np, u_char tn, u_char ln,
1221 u_char *inq_data, int inq_len);
1226 * Build a scatter/gather entry.
1228 * For 64 bit systems, we use the 8 upper bits of the size field
1229 * to provide bus address bits 32-39 to the SCRIPTS processor.
1230 * This allows the 895A, 896, 1010 to address up to 1 TB of memory.
1233 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
1234 #define sym_build_sge(np, data, badd, len) \
1236 (data)->addr = cpu_to_scr(badd); \
1237 (data)->size = cpu_to_scr(len); \
1239 #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
1240 #define sym_build_sge(np, data, badd, len) \
1242 (data)->addr = cpu_to_scr(badd); \
1243 (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len); \
1245 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1246 int sym_lookup_dmap(hcb_p np, u32 h, int s);
1247 static __inline void
1248 sym_build_sge(hcb_p np, struct sym_tblmove *data, u64 badd, int len)
1251 int s = (h&SYM_DMAP_MASK);
1253 if (h != np->dmap_bah[s])
1256 (data)->addr = cpu_to_scr(badd);
1257 (data)->size = cpu_to_scr((s<<24) + len);
1260 s = sym_lookup_dmap(np, h, s);
1264 #error "Unsupported DMA addressing mode"
1268 * Set up data pointers used by SCRIPTS.
1269 * Called from O/S specific code.
1271 static void __inline
1272 sym_setup_data_pointers(hcb_p np, ccb_p cp, int dir)
1277 * No segments means no data.
1283 * Set the data pointer.
1286 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1287 case CAM_DIR_UNKNOWN:
1290 goalp = SCRIPTA_BA (np, data_out2) + 8;
1291 lastp = goalp - 8 - (cp->segments * (2*4));
1292 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1293 cp->wgoalp = cpu_to_scr(goalp);
1294 if (dir != CAM_DIR_UNKNOWN)
1296 cp->phys.head.wlastp = cpu_to_scr(lastp);
1302 cp->host_flags |= HF_DATA_IN;
1303 goalp = SCRIPTA_BA (np, data_in2) + 8;
1304 lastp = goalp - 8 - (cp->segments * (2*4));
1308 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1309 cp->host_flags |= HF_DATA_IN;
1311 lastp = goalp = SCRIPTB_BA (np, no_data);
1316 * Set all pointers values needed by SCRIPTS.
1318 cp->phys.head.lastp = cpu_to_scr(lastp);
1319 cp->phys.head.savep = cpu_to_scr(lastp);
1320 cp->startp = cp->phys.head.savep;
1321 cp->goalp = cpu_to_scr(goalp);
1323 #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
1325 * If direction is unknown, start at data_io.
1327 if (dir == CAM_DIR_UNKNOWN)
1328 cp->phys.head.savep = cpu_to_scr(SCRIPTB_BA (np, data_io));
1337 * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
1338 * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized.
1339 * (1 PAGE at a time is just fine).
1341 #define SYM_MEM_SHIFT 4
1342 #define SYM_MEM_CLUSTER_SIZE (1UL << SYM_MEM_CLUSTER_SHIFT)
1343 #define SYM_MEM_CLUSTER_MASK (SYM_MEM_CLUSTER_SIZE-1)
1346 * Link between free memory chunks of a given size.
1348 typedef struct sym_m_link {
1349 struct sym_m_link *next;
1353 * Virtual to bus physical translation for a given cluster.
1354 * Such a structure is only useful with DMA abstraction.
1356 #ifdef SYM_OPT_BUS_DMA_ABSTRACTION
1357 typedef struct sym_m_vtob { /* Virtual to Bus address translation */
1358 struct sym_m_vtob *next;
1359 #ifdef SYM_HAVE_M_SVTOB
1360 struct sym_m_svtob s; /* OS specific data structure */
1362 m_addr_t vaddr; /* Virtual address */
1363 m_addr_t baddr; /* Bus physical address */
1366 /* Hash this stuff a bit to speed up translations */
1367 #define VTOB_HASH_SHIFT 5
1368 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
1369 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
1370 #define VTOB_HASH_CODE(m) \
1371 ((((m_addr_t) (m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK)
1372 #endif /* SYM_OPT_BUS_DMA_ABSTRACTION */
1375 * Memory pool of a given kind.
1376 * Ideally, we want to use:
1377 * 1) 1 pool for memory we donnot need to involve in DMA.
1378 * 2) The same pool for controllers that require same DMA
1379 * constraints and features.
1380 * The OS specific m_pool_id_t thing and the sym_m_pool_match()
1381 * method are expected to tell the driver about.
1383 typedef struct sym_m_pool {
1384 #ifdef SYM_OPT_BUS_DMA_ABSTRACTION
1385 m_pool_ident_t dev_dmat; /* Identifies the pool (see above) */
1386 m_addr_t (*get_mem_cluster)(struct sym_m_pool *);
1387 #ifdef SYM_MEM_FREE_UNUSED
1388 void (*free_mem_cluster)(struct sym_m_pool *, m_addr_t);
1390 #define M_GET_MEM_CLUSTER() mp->get_mem_cluster(mp)
1391 #define M_FREE_MEM_CLUSTER(p) mp->free_mem_cluster(mp, p)
1392 #ifdef SYM_HAVE_M_SPOOL
1393 struct sym_m_spool s; /* OS specific data structure */
1396 m_vtob_p vtob[VTOB_HASH_SIZE];
1397 struct sym_m_pool *next;
1399 #define M_GET_MEM_CLUSTER() sym_get_mem_cluster()
1400 #define M_FREE_MEM_CLUSTER(p) sym_free_mem_cluster(p)
1401 #endif /* SYM_OPT_BUS_DMA_ABSTRACTION */
1402 struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
1406 * Alloc and free non DMAable memory.
1408 void sym_mfree_unlocked(void *ptr, int size, char *name);
1409 void *sym_calloc_unlocked(int size, char *name);
1412 * Alloc, free and translate addresses to bus physical
1413 * for DMAable memory.
1415 #ifdef SYM_OPT_BUS_DMA_ABSTRACTION
1416 void *__sym_calloc_dma_unlocked(m_pool_ident_t dev_dmat, int size, char *name);
1418 __sym_mfree_dma_unlocked(m_pool_ident_t dev_dmat, void *m,int size, char *name);
1419 u32 __vtobus_unlocked(m_pool_ident_t dev_dmat, void *m);
1423 * Verbs used by the driver code for DMAable memory handling.
1424 * The _uvptv_ macro avoids a nasty warning about pointer to volatile
1427 #define _uvptv_(p) ((void *)((u_long)(p)))
1429 #define _sym_calloc_dma(np, l, n) __sym_calloc_dma(np->bus_dmat, l, n)
1430 #define _sym_mfree_dma(np, p, l, n) \
1431 __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n)
1432 #define sym_calloc_dma(l, n) _sym_calloc_dma(np, l, n)
1433 #define sym_mfree_dma(p, l, n) _sym_mfree_dma(np, p, l, n)
1434 #define _vtobus(np, p) __vtobus(np->bus_dmat, _uvptv_(p))
1435 #define vtobus(p) _vtobus(np, p)
1438 * Override some function names.
1440 #define PRINT_ADDR sym_print_addr
1441 #define PRINT_TARGET sym_print_target
1442 #define PRINT_LUN sym_print_lun
1443 #define MDELAY sym_mdelay
1444 #define UDELAY sym_udelay
1446 #endif /* SYM_HIPD_H */