GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / scsi / sym53c8xx_2 / sym_hipd.h
blobdb606a304ac006aae6fa500207e8b384a5f10099
1 /*
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 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 #include <linux/gfp.h>
42 #ifndef SYM_HIPD_H
43 #define SYM_HIPD_H
46 * Generic driver options.
48 * They may be defined in platform specific headers, if they
49 * are useful.
51 * SYM_OPT_HANDLE_DEVICE_QUEUEING
52 * When this option is set, the driver will use a queue per
53 * device and handle QUEUE FULL status requeuing internally.
55 * SYM_OPT_LIMIT_COMMAND_REORDERING
56 * When this option is set, the driver tries to limit tagged
57 * command reordering to some reasonable value.
58 * (set for Linux)
62 * Active debugging tags and verbosity.
63 * Both DEBUG_FLAGS and sym_verbose can be redefined
64 * by the platform specific code to something else.
66 #define DEBUG_ALLOC (0x0001)
67 #define DEBUG_PHASE (0x0002)
68 #define DEBUG_POLL (0x0004)
69 #define DEBUG_QUEUE (0x0008)
70 #define DEBUG_RESULT (0x0010)
71 #define DEBUG_SCATTER (0x0020)
72 #define DEBUG_SCRIPT (0x0040)
73 #define DEBUG_TINY (0x0080)
74 #define DEBUG_TIMING (0x0100)
75 #define DEBUG_NEGO (0x0200)
76 #define DEBUG_TAGS (0x0400)
77 #define DEBUG_POINTER (0x0800)
79 #ifndef DEBUG_FLAGS
80 #define DEBUG_FLAGS (0x0000)
81 #endif
83 #ifndef sym_verbose
84 #define sym_verbose (np->verbose)
85 #endif
88 * These ones should have been already defined.
90 #ifndef assert
91 #define assert(expression) { \
92 if (!(expression)) { \
93 (void)panic( \
94 "assertion \"%s\" failed: file \"%s\", line %d\n", \
95 #expression, \
96 __FILE__, __LINE__); \
97 } \
99 #endif
102 * Number of tasks per device we want to handle.
104 #if SYM_CONF_MAX_TAG_ORDER > 8
105 #error "more than 256 tags per logical unit not allowed."
106 #endif
107 #define SYM_CONF_MAX_TASK (1<<SYM_CONF_MAX_TAG_ORDER)
110 * Donnot use more tasks that we can handle.
112 #ifndef SYM_CONF_MAX_TAG
113 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
114 #endif
115 #if SYM_CONF_MAX_TAG > SYM_CONF_MAX_TASK
116 #undef SYM_CONF_MAX_TAG
117 #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK
118 #endif
121 * This one means 'NO TAG for this job'
123 #define NO_TAG (256)
126 * Number of SCSI targets.
128 #if SYM_CONF_MAX_TARGET > 16
129 #error "more than 16 targets not allowed."
130 #endif
133 * Number of logical units per target.
135 #if SYM_CONF_MAX_LUN > 64
136 #error "more than 64 logical units per target not allowed."
137 #endif
140 * Asynchronous pre-scaler (ns). Shall be 40 for
141 * the SCSI timings to be compliant.
143 #define SYM_CONF_MIN_ASYNC (40)
147 * MEMORY ALLOCATOR.
150 #define SYM_MEM_WARN 1 /* Warn on failed operations */
152 #define SYM_MEM_PAGE_ORDER 0 /* 1 PAGE maximum */
153 #define SYM_MEM_CLUSTER_SHIFT (PAGE_SHIFT+SYM_MEM_PAGE_ORDER)
154 #define SYM_MEM_FREE_UNUSED /* Free unused pages immediately */
156 * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
157 * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized.
158 * (1 PAGE at a time is just fine).
160 #define SYM_MEM_SHIFT 4
161 #define SYM_MEM_CLUSTER_SIZE (1UL << SYM_MEM_CLUSTER_SHIFT)
162 #define SYM_MEM_CLUSTER_MASK (SYM_MEM_CLUSTER_SIZE-1)
165 * Number of entries in the START and DONE queues.
167 * We limit to 1 PAGE in order to succeed allocation of
168 * these queues. Each entry is 8 bytes long (2 DWORDS).
170 #ifdef SYM_CONF_MAX_START
171 #define SYM_CONF_MAX_QUEUE (SYM_CONF_MAX_START+2)
172 #else
173 #define SYM_CONF_MAX_QUEUE (7*SYM_CONF_MAX_TASK+2)
174 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
175 #endif
177 #if SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8
178 #undef SYM_CONF_MAX_QUEUE
179 #define SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8)
180 #undef SYM_CONF_MAX_START
181 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
182 #endif
185 * For this one, we want a short name :-)
187 #define MAX_QUEUE SYM_CONF_MAX_QUEUE
190 * Common definitions for both bus space based and legacy IO methods.
193 #define INB_OFF(np, o) ioread8(np->s.ioaddr + (o))
194 #define INW_OFF(np, o) ioread16(np->s.ioaddr + (o))
195 #define INL_OFF(np, o) ioread32(np->s.ioaddr + (o))
197 #define OUTB_OFF(np, o, val) iowrite8((val), np->s.ioaddr + (o))
198 #define OUTW_OFF(np, o, val) iowrite16((val), np->s.ioaddr + (o))
199 #define OUTL_OFF(np, o, val) iowrite32((val), np->s.ioaddr + (o))
201 #define INB(np, r) INB_OFF(np, offsetof(struct sym_reg, r))
202 #define INW(np, r) INW_OFF(np, offsetof(struct sym_reg, r))
203 #define INL(np, r) INL_OFF(np, offsetof(struct sym_reg, r))
205 #define OUTB(np, r, v) OUTB_OFF(np, offsetof(struct sym_reg, r), (v))
206 #define OUTW(np, r, v) OUTW_OFF(np, offsetof(struct sym_reg, r), (v))
207 #define OUTL(np, r, v) OUTL_OFF(np, offsetof(struct sym_reg, r), (v))
209 #define OUTONB(np, r, m) OUTB(np, r, INB(np, r) | (m))
210 #define OUTOFFB(np, r, m) OUTB(np, r, INB(np, r) & ~(m))
211 #define OUTONW(np, r, m) OUTW(np, r, INW(np, r) | (m))
212 #define OUTOFFW(np, r, m) OUTW(np, r, INW(np, r) & ~(m))
213 #define OUTONL(np, r, m) OUTL(np, r, INL(np, r) | (m))
214 #define OUTOFFL(np, r, m) OUTL(np, r, INL(np, r) & ~(m))
217 * We normally want the chip to have a consistent view
218 * of driver internal data structures when we restart it.
219 * Thus these macros.
221 #define OUTL_DSP(np, v) \
222 do { \
223 MEMORY_WRITE_BARRIER(); \
224 OUTL(np, nc_dsp, (v)); \
225 } while (0)
227 #define OUTONB_STD() \
228 do { \
229 MEMORY_WRITE_BARRIER(); \
230 OUTONB(np, nc_dcntl, (STD|NOCOM)); \
231 } while (0)
234 * Command control block states.
236 #define HS_IDLE (0)
237 #define HS_BUSY (1)
238 #define HS_NEGOTIATE (2) /* sync/wide data transfer*/
239 #define HS_DISCONNECT (3) /* Disconnected by target */
240 #define HS_WAIT (4) /* waiting for resource */
242 #define HS_DONEMASK (0x80)
243 #define HS_COMPLETE (4|HS_DONEMASK)
244 #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */
245 #define HS_UNEXPECTED (6|HS_DONEMASK) /* Unexpected disconnect */
246 #define HS_COMP_ERR (7|HS_DONEMASK) /* Completed with error */
249 * Software Interrupt Codes
251 #define SIR_BAD_SCSI_STATUS (1)
252 #define SIR_SEL_ATN_NO_MSG_OUT (2)
253 #define SIR_MSG_RECEIVED (3)
254 #define SIR_MSG_WEIRD (4)
255 #define SIR_NEGO_FAILED (5)
256 #define SIR_NEGO_PROTO (6)
257 #define SIR_SCRIPT_STOPPED (7)
258 #define SIR_REJECT_TO_SEND (8)
259 #define SIR_SWIDE_OVERRUN (9)
260 #define SIR_SODL_UNDERRUN (10)
261 #define SIR_RESEL_NO_MSG_IN (11)
262 #define SIR_RESEL_NO_IDENTIFY (12)
263 #define SIR_RESEL_BAD_LUN (13)
264 #define SIR_TARGET_SELECTED (14)
265 #define SIR_RESEL_BAD_I_T_L (15)
266 #define SIR_RESEL_BAD_I_T_L_Q (16)
267 #define SIR_ABORT_SENT (17)
268 #define SIR_RESEL_ABORTED (18)
269 #define SIR_MSG_OUT_DONE (19)
270 #define SIR_COMPLETE_ERROR (20)
271 #define SIR_DATA_OVERRUN (21)
272 #define SIR_BAD_PHASE (22)
273 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
274 #define SIR_DMAP_DIRTY (23)
275 #define SIR_MAX (23)
276 #else
277 #define SIR_MAX (22)
278 #endif
281 * Extended error bit codes.
282 * xerr_status field of struct sym_ccb.
284 #define XE_EXTRA_DATA (1) /* unexpected data phase */
285 #define XE_BAD_PHASE (1<<1) /* illegal phase (4/5) */
286 #define XE_PARITY_ERR (1<<2) /* unrecovered SCSI parity error */
287 #define XE_SODL_UNRUN (1<<3) /* ODD transfer in DATA OUT phase */
288 #define XE_SWIDE_OVRUN (1<<4) /* ODD transfer in DATA IN phase */
291 * Negotiation status.
292 * nego_status field of struct sym_ccb.
294 #define NS_SYNC (1)
295 #define NS_WIDE (2)
296 #define NS_PPR (3)
299 * A CCB hashed table is used to retrieve CCB address
300 * from DSA value.
302 #define CCB_HASH_SHIFT 8
303 #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT)
304 #define CCB_HASH_MASK (CCB_HASH_SIZE-1)
305 #define CCB_HASH_CODE(dsa) \
306 (((dsa) >> (_LGRU16_(sizeof(struct sym_ccb)))) & CCB_HASH_MASK)
308 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
310 * We may want to use segment registers for 64 bit DMA.
311 * 16 segments registers -> up to 64 GB addressable.
313 #define SYM_DMAP_SHIFT (4)
314 #define SYM_DMAP_SIZE (1u<<SYM_DMAP_SHIFT)
315 #define SYM_DMAP_MASK (SYM_DMAP_SIZE-1)
316 #endif
319 * Device flags.
321 #define SYM_DISC_ENABLED (1)
322 #define SYM_TAGS_ENABLED (1<<1)
323 #define SYM_SCAN_BOOT_DISABLED (1<<2)
324 #define SYM_SCAN_LUNS_DISABLED (1<<3)
327 * Host adapter miscellaneous flags.
329 #define SYM_AVOID_BUS_RESET (1)
332 * Misc.
334 #define SYM_SNOOP_TIMEOUT (10000000)
335 #define BUS_8_BIT 0
336 #define BUS_16_BIT 1
339 * Gather negotiable parameters value
341 struct sym_trans {
342 u8 period;
343 u8 offset;
344 unsigned int width:1;
345 unsigned int iu:1;
346 unsigned int dt:1;
347 unsigned int qas:1;
348 unsigned int check_nego:1;
349 unsigned int renego:2;
353 * Global TCB HEADER.
355 * Due to lack of indirect addressing on earlier NCR chips,
356 * this substructure is copied from the TCB to a global
357 * address after selection.
358 * For SYMBIOS chips that support LOAD/STORE this copy is
359 * not needed and thus not performed.
361 struct sym_tcbh {
363 * Scripts bus addresses of LUN table accessed from scripts.
364 * LUN #0 is a special case, since multi-lun devices are rare,
365 * and we we want to speed-up the general case and not waste
366 * resources.
368 u32 luntbl_sa; /* bus address of this table */
369 u32 lun0_sa; /* bus address of LCB #0 */
371 * Actual SYNC/WIDE IO registers value for this target.
372 * 'sval', 'wval' and 'uval' are read from SCRIPTS and
373 * so have alignment constraints.
375 /*0*/ u_char uval; /* -> SCNTL4 register */
376 /*1*/ u_char sval; /* -> SXFER io register */
377 /*2*/ u_char filler1;
378 /*3*/ u_char wval; /* -> SCNTL3 io register */
382 * Target Control Block
384 struct sym_tcb {
386 * TCB header.
387 * Assumed at offset 0.
389 /*0*/ struct sym_tcbh head;
392 * LUN table used by the SCRIPTS processor.
393 * An array of bus addresses is used on reselection.
395 u32 *luntbl; /* LCBs bus address table */
396 int nlcb; /* Number of valid LCBs (including LUN #0) */
399 * LUN table used by the C code.
401 struct sym_lcb *lun0p; /* LCB of LUN #0 (usual case) */
402 #if SYM_CONF_MAX_LUN > 1
403 struct sym_lcb **lunmp; /* Other LCBs [1..MAX_LUN] */
404 #endif
406 #ifdef SYM_HAVE_STCB
408 * O/S specific data structure.
410 struct sym_stcb s;
411 #endif
413 /* Transfer goal */
414 struct sym_trans tgoal;
416 /* Last printed transfer speed */
417 struct sym_trans tprint;
420 * Keep track of the CCB used for the negotiation in order
421 * to ensure that only 1 negotiation is queued at a time.
423 struct sym_ccb * nego_cp; /* CCB used for the nego */
426 * Set when we want to reset the device.
428 u_char to_reset;
431 * Other user settable limits and options.
432 * These limits are read from the NVRAM if present.
434 unsigned char usrflags;
435 unsigned char usr_period;
436 unsigned char usr_width;
437 unsigned short usrtags;
438 struct scsi_target *starget;
442 * Global LCB HEADER.
444 * Due to lack of indirect addressing on earlier NCR chips,
445 * this substructure is copied from the LCB to a global
446 * address after selection.
447 * For SYMBIOS chips that support LOAD/STORE this copy is
448 * not needed and thus not performed.
450 struct sym_lcbh {
452 * SCRIPTS address jumped by SCRIPTS on reselection.
453 * For not probed logical units, this address points to
454 * SCRIPTS that deal with bad LU handling (must be at
455 * offset zero of the LCB for that reason).
457 /*0*/ u32 resel_sa;
460 * Task (bus address of a CCB) read from SCRIPTS that points
461 * to the unique ITL nexus allowed to be disconnected.
463 u32 itl_task_sa;
466 * Task table bus address (read from SCRIPTS).
468 u32 itlq_tbl_sa;
472 * Logical Unit Control Block
474 struct sym_lcb {
476 * TCB header.
477 * Assumed at offset 0.
479 /*0*/ struct sym_lcbh head;
482 * Task table read from SCRIPTS that contains pointers to
483 * ITLQ nexuses. The bus address read from SCRIPTS is
484 * inside the header.
486 u32 *itlq_tbl; /* Kernel virtual address */
489 * Busy CCBs management.
491 u_short busy_itlq; /* Number of busy tagged CCBs */
492 u_short busy_itl; /* Number of busy untagged CCBs */
495 * Circular tag allocation buffer.
497 u_short ia_tag; /* Tag allocation index */
498 u_short if_tag; /* Tag release index */
499 u_char *cb_tags; /* Circular tags buffer */
502 * O/S specific data structure.
504 #ifdef SYM_HAVE_SLCB
505 struct sym_slcb s;
506 #endif
508 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
510 * Optionnaly the driver can handle device queueing,
511 * and requeues internally command to redo.
513 SYM_QUEHEAD waiting_ccbq;
514 SYM_QUEHEAD started_ccbq;
515 int num_sgood;
516 u_short started_tags;
517 u_short started_no_tag;
518 u_short started_max;
519 u_short started_limit;
520 #endif
522 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
524 * Optionally the driver can try to prevent SCSI
525 * IOs from being reordered too much.
527 u_char tags_si; /* Current index to tags sum */
528 u_short tags_sum[2]; /* Tags sum counters */
529 u_short tags_since; /* # of tags since last switch */
530 #endif
533 * Set when we want to clear all tasks.
535 u_char to_clear;
538 * Capabilities.
540 u_char user_flags;
541 u_char curr_flags;
545 * Action from SCRIPTS on a task.
546 * Is part of the CCB, but is also used separately to plug
547 * error handling action to perform from SCRIPTS.
549 struct sym_actscr {
550 u32 start; /* Jumped by SCRIPTS after selection */
551 u32 restart; /* Jumped by SCRIPTS on relection */
555 * Phase mismatch context.
557 * It is part of the CCB and is used as parameters for the
558 * DATA pointer. We need two contexts to handle correctly the
559 * SAVED DATA POINTER.
561 struct sym_pmc {
562 struct sym_tblmove sg; /* Updated interrupted SG block */
563 u32 ret; /* SCRIPT return address */
567 * LUN control block lookup.
568 * We use a direct pointer for LUN #0, and a table of
569 * pointers which is only allocated for devices that support
570 * LUN(s) > 0.
572 #if SYM_CONF_MAX_LUN <= 1
573 #define sym_lp(tp, lun) (!lun) ? (tp)->lun0p : NULL
574 #else
575 #define sym_lp(tp, lun) \
576 (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[(lun)] : NULL
577 #endif
580 * Status are used by the host and the script processor.
582 * The last four bytes (status[4]) are copied to the
583 * scratchb register (declared as scr0..scr3) just after the
584 * select/reselect, and copied back just after disconnecting.
585 * Inside the script the XX_REG are used.
589 * Last four bytes (script)
591 #define HX_REG scr0
592 #define HX_PRT nc_scr0
593 #define HS_REG scr1
594 #define HS_PRT nc_scr1
595 #define SS_REG scr2
596 #define SS_PRT nc_scr2
597 #define HF_REG scr3
598 #define HF_PRT nc_scr3
601 * Last four bytes (host)
603 #define host_xflags phys.head.status[0]
604 #define host_status phys.head.status[1]
605 #define ssss_status phys.head.status[2]
606 #define host_flags phys.head.status[3]
609 * Host flags
611 #define HF_IN_PM0 1u
612 #define HF_IN_PM1 (1u<<1)
613 #define HF_ACT_PM (1u<<2)
614 #define HF_DP_SAVED (1u<<3)
615 #define HF_SENSE (1u<<4)
616 #define HF_EXT_ERR (1u<<5)
617 #define HF_DATA_IN (1u<<6)
618 #ifdef SYM_CONF_IARB_SUPPORT
619 #define HF_HINT_IARB (1u<<7)
620 #endif
623 * More host flags
625 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
626 #define HX_DMAP_DIRTY (1u<<7)
627 #endif
630 * Global CCB HEADER.
632 * Due to lack of indirect addressing on earlier NCR chips,
633 * this substructure is copied from the ccb to a global
634 * address after selection (or reselection) and copied back
635 * before disconnect.
636 * For SYMBIOS chips that support LOAD/STORE this copy is
637 * not needed and thus not performed.
640 struct sym_ccbh {
642 * Start and restart SCRIPTS addresses (must be at 0).
644 /*0*/ struct sym_actscr go;
647 * SCRIPTS jump address that deal with data pointers.
648 * 'savep' points to the position in the script responsible
649 * for the actual transfer of data.
650 * It's written on reception of a SAVE_DATA_POINTER message.
652 u32 savep; /* Jump address to saved data pointer */
653 u32 lastp; /* SCRIPTS address at end of data */
656 * Status fields.
658 u8 status[4];
662 * GET/SET the value of the data pointer used by SCRIPTS.
664 * We must distinguish between the LOAD/STORE-based SCRIPTS
665 * that use directly the header in the CCB, and the NCR-GENERIC
666 * SCRIPTS that use the copy of the header in the HCB.
668 #if SYM_CONF_GENERIC_SUPPORT
669 #define sym_set_script_dp(np, cp, dp) \
670 do { \
671 if (np->features & FE_LDSTR) \
672 cp->phys.head.lastp = cpu_to_scr(dp); \
673 else \
674 np->ccb_head.lastp = cpu_to_scr(dp); \
675 } while (0)
676 #define sym_get_script_dp(np, cp) \
677 scr_to_cpu((np->features & FE_LDSTR) ? \
678 cp->phys.head.lastp : np->ccb_head.lastp)
679 #else
680 #define sym_set_script_dp(np, cp, dp) \
681 do { \
682 cp->phys.head.lastp = cpu_to_scr(dp); \
683 } while (0)
685 #define sym_get_script_dp(np, cp) (cp->phys.head.lastp)
686 #endif
689 * Data Structure Block
691 * During execution of a ccb by the script processor, the
692 * DSA (data structure address) register points to this
693 * substructure of the ccb.
695 struct sym_dsb {
697 * CCB header.
698 * Also assumed at offset 0 of the sym_ccb structure.
700 /*0*/ struct sym_ccbh head;
703 * Phase mismatch contexts.
704 * We need two to handle correctly the SAVED DATA POINTER.
705 * MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic
706 * for address calculation from SCRIPTS.
708 struct sym_pmc pm0;
709 struct sym_pmc pm1;
712 * Table data for Script
714 struct sym_tblsel select;
715 struct sym_tblmove smsg;
716 struct sym_tblmove smsg_ext;
717 struct sym_tblmove cmd;
718 struct sym_tblmove sense;
719 struct sym_tblmove wresid;
720 struct sym_tblmove data [SYM_CONF_MAX_SG];
724 * Our Command Control Block
726 struct sym_ccb {
728 * This is the data structure which is pointed by the DSA
729 * register when it is executed by the script processor.
730 * It must be the first entry.
732 struct sym_dsb phys;
735 * Pointer to CAM ccb and related stuff.
737 struct scsi_cmnd *cmd; /* CAM scsiio ccb */
738 u8 cdb_buf[16]; /* Copy of CDB */
739 #define SYM_SNS_BBUF_LEN 32
740 u8 sns_bbuf[SYM_SNS_BBUF_LEN]; /* Bounce buffer for sense data */
741 int data_len; /* Total data length */
742 int segments; /* Number of SG segments */
744 u8 order; /* Tag type (if tagged command) */
745 unsigned char odd_byte_adjustment; /* odd-sized req on wide bus */
747 u_char nego_status; /* Negotiation status */
748 u_char xerr_status; /* Extended error flags */
749 u32 extra_bytes; /* Extraneous bytes transferred */
752 * Message areas.
753 * We prepare a message to be sent after selection.
754 * We may use a second one if the command is rescheduled
755 * due to CHECK_CONDITION or COMMAND TERMINATED.
756 * Contents are IDENTIFY and SIMPLE_TAG.
757 * While negotiating sync or wide transfer,
758 * a SDTR or WDTR message is appended.
760 u_char scsi_smsg [12];
761 u_char scsi_smsg2[12];
764 * Auto request sense related fields.
766 u_char sensecmd[6]; /* Request Sense command */
767 u_char sv_scsi_status; /* Saved SCSI status */
768 u_char sv_xerr_status; /* Saved extended status */
769 int sv_resid; /* Saved residual */
772 * Other fields.
774 u32 ccb_ba; /* BUS address of this CCB */
775 u_short tag; /* Tag for this transfer */
776 /* NO_TAG means no tag */
777 u_char target;
778 u_char lun;
779 struct sym_ccb *link_ccbh; /* Host adapter CCB hash chain */
780 SYM_QUEHEAD link_ccbq; /* Link to free/busy CCB queue */
781 u32 startp; /* Initial data pointer */
782 u32 goalp; /* Expected last data pointer */
783 int ext_sg; /* Extreme data pointer, used */
784 int ext_ofs; /* to calculate the residual. */
785 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
786 SYM_QUEHEAD link2_ccbq; /* Link for device queueing */
787 u_char started; /* CCB queued to the squeue */
788 #endif
789 u_char to_abort; /* Want this IO to be aborted */
790 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
791 u_char tags_si; /* Lun tags sum index (0,1) */
792 #endif
795 #define CCB_BA(cp,lbl) cpu_to_scr(cp->ccb_ba + offsetof(struct sym_ccb, lbl))
797 typedef struct device *m_pool_ident_t;
800 * Host Control Block
802 struct sym_hcb {
804 * Global headers.
805 * Due to poorness of addressing capabilities, earlier
806 * chips (810, 815, 825) copy part of the data structures
807 * (CCB, TCB and LCB) in fixed areas.
809 #if SYM_CONF_GENERIC_SUPPORT
810 struct sym_ccbh ccb_head;
811 struct sym_tcbh tcb_head;
812 struct sym_lcbh lcb_head;
813 #endif
815 * Idle task and invalid task actions and
816 * their bus addresses.
818 struct sym_actscr idletask, notask, bad_itl, bad_itlq;
819 u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba;
822 * Dummy lun table to protect us against target
823 * returning bad lun number on reselection.
825 u32 *badluntbl; /* Table physical address */
826 u32 badlun_sa; /* SCRIPT handler BUS address */
829 * Bus address of this host control block.
831 u32 hcb_ba;
834 * Bit 32-63 of the on-chip RAM bus address in LE format.
835 * The START_RAM64 script loads the MMRS and MMWS from this
836 * field.
838 u32 scr_ram_seg;
841 * Initial value of some IO register bits.
842 * These values are assumed to have been set by BIOS, and may
843 * be used to probe adapter implementation differences.
845 u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
846 sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4,
847 sv_stest1;
850 * Actual initial value of IO register bits used by the
851 * driver. They are loaded at initialisation according to
852 * features that are to be enabled/disabled.
854 u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4,
855 rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4;
858 * Target data.
860 struct sym_tcb target[SYM_CONF_MAX_TARGET];
863 * Target control block bus address array used by the SCRIPT
864 * on reselection.
866 u32 *targtbl;
867 u32 targtbl_ba;
870 * DMA pool handle for this HBA.
872 m_pool_ident_t bus_dmat;
875 * O/S specific data structure
877 struct sym_shcb s;
880 * Physical bus addresses of the chip.
882 u32 mmio_ba; /* MMIO 32 bit BUS address */
883 u32 ram_ba; /* RAM 32 bit BUS address */
886 * SCRIPTS virtual and physical bus addresses.
887 * 'script' is loaded in the on-chip RAM if present.
888 * 'scripth' stays in main memory for all chips except the
889 * 53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM.
891 u_char *scripta0; /* Copy of scripts A, B, Z */
892 u_char *scriptb0;
893 u_char *scriptz0;
894 u32 scripta_ba; /* Actual scripts A, B, Z */
895 u32 scriptb_ba; /* 32 bit bus addresses. */
896 u32 scriptz_ba;
897 u_short scripta_sz; /* Actual size of script A, B, Z*/
898 u_short scriptb_sz;
899 u_short scriptz_sz;
902 * Bus addresses, setup and patch methods for
903 * the selected firmware.
905 struct sym_fwa_ba fwa_bas; /* Useful SCRIPTA bus addresses */
906 struct sym_fwb_ba fwb_bas; /* Useful SCRIPTB bus addresses */
907 struct sym_fwz_ba fwz_bas; /* Useful SCRIPTZ bus addresses */
908 void (*fw_setup)(struct sym_hcb *np, struct sym_fw *fw);
909 void (*fw_patch)(struct Scsi_Host *);
910 char *fw_name;
913 * General controller parameters and configuration.
915 u_int features; /* Chip features map */
916 u_char myaddr; /* SCSI id of the adapter */
917 u_char maxburst; /* log base 2 of dwords burst */
918 u_char maxwide; /* Maximum transfer width */
919 u_char minsync; /* Min sync period factor (ST) */
920 u_char maxsync; /* Max sync period factor (ST) */
921 u_char maxoffs; /* Max scsi offset (ST) */
922 u_char minsync_dt; /* Min sync period factor (DT) */
923 u_char maxsync_dt; /* Max sync period factor (DT) */
924 u_char maxoffs_dt; /* Max scsi offset (DT) */
925 u_char multiplier; /* Clock multiplier (1,2,4) */
926 u_char clock_divn; /* Number of clock divisors */
927 u32 clock_khz; /* SCSI clock frequency in KHz */
928 u32 pciclk_khz; /* Estimated PCI clock in KHz */
930 * Start queue management.
931 * It is filled up by the host processor and accessed by the
932 * SCRIPTS processor in order to start SCSI commands.
934 volatile /* Prevent code optimizations */
935 u32 *squeue; /* Start queue virtual address */
936 u32 squeue_ba; /* Start queue BUS address */
937 u_short squeueput; /* Next free slot of the queue */
938 u_short actccbs; /* Number of allocated CCBs */
941 * Command completion queue.
942 * It is the same size as the start queue to avoid overflow.
944 u_short dqueueget; /* Next position to scan */
945 volatile /* Prevent code optimizations */
946 u32 *dqueue; /* Completion (done) queue */
947 u32 dqueue_ba; /* Done queue BUS address */
950 * Miscellaneous buffers accessed by the scripts-processor.
951 * They shall be DWORD aligned, because they may be read or
952 * written with a script command.
954 u_char msgout[8]; /* Buffer for MESSAGE OUT */
955 u_char msgin [8]; /* Buffer for MESSAGE IN */
956 u32 lastmsg; /* Last SCSI message sent */
957 u32 scratch; /* Scratch for SCSI receive */
958 /* Also used for cache test */
960 * Miscellaneous configuration and status parameters.
962 u_char usrflags; /* Miscellaneous user flags */
963 u_char scsi_mode; /* Current SCSI BUS mode */
964 u_char verbose; /* Verbosity for this controller*/
967 * CCB lists and queue.
969 struct sym_ccb **ccbh; /* CCBs hashed by DSA value */
970 /* CCB_HASH_SIZE lists of CCBs */
971 SYM_QUEHEAD free_ccbq; /* Queue of available CCBs */
972 SYM_QUEHEAD busy_ccbq; /* Queue of busy CCBs */
975 * During error handling and/or recovery,
976 * active CCBs that are to be completed with
977 * error or requeued are moved from the busy_ccbq
978 * to the comp_ccbq prior to completion.
980 SYM_QUEHEAD comp_ccbq;
982 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
983 SYM_QUEHEAD dummy_ccbq;
984 #endif
987 * IMMEDIATE ARBITRATION (IARB) control.
989 * We keep track in 'last_cp' of the last CCB that has been
990 * queued to the SCRIPTS processor and clear 'last_cp' when
991 * this CCB completes. If last_cp is not zero at the moment
992 * we queue a new CCB, we set a flag in 'last_cp' that is
993 * used by the SCRIPTS as a hint for setting IARB.
994 * We donnot set more than 'iarb_max' consecutive hints for
995 * IARB in order to leave devices a chance to reselect.
996 * By the way, any non zero value of 'iarb_max' is unfair. :)
998 #ifdef SYM_CONF_IARB_SUPPORT
999 u_short iarb_max; /* Max. # consecutive IARB hints*/
1000 u_short iarb_count; /* Actual # of these hints */
1001 struct sym_ccb * last_cp;
1002 #endif
1005 * Command abort handling.
1006 * We need to synchronize tightly with the SCRIPTS
1007 * processor in order to handle things correctly.
1009 u_char abrt_msg[4]; /* Message to send buffer */
1010 struct sym_tblmove abrt_tbl; /* Table for the MOV of it */
1011 struct sym_tblsel abrt_sel; /* Sync params for selection */
1012 u_char istat_sem; /* Tells the chip to stop (SEM) */
1015 * 64 bit DMA handling.
1017 #if SYM_CONF_DMA_ADDRESSING_MODE != 0
1018 u_char use_dac; /* Use PCI DAC cycles */
1019 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
1020 u_char dmap_dirty; /* Dma segments registers dirty */
1021 u32 dmap_bah[SYM_DMAP_SIZE];/* Segment registers map */
1022 #endif
1023 #endif
1026 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
1027 #define use_dac(np) 0
1028 #define set_dac(np) do { } while (0)
1029 #else
1030 #define use_dac(np) (np)->use_dac
1031 #define set_dac(np) (np)->use_dac = 1
1032 #endif
1034 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl))
1038 * FIRMWARES (sym_fw.c)
1040 struct sym_fw * sym_find_firmware(struct sym_chip *chip);
1041 void sym_fw_bind_script(struct sym_hcb *np, u32 *start, int len);
1044 * Driver methods called from O/S specific code.
1046 char *sym_driver_name(void);
1047 void sym_print_xerr(struct scsi_cmnd *cmd, int x_status);
1048 int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int);
1049 struct sym_chip *sym_lookup_chip_table(u_short device_id, u_char revision);
1050 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1051 void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn);
1052 #else
1053 void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp);
1054 #endif
1055 void sym_start_up(struct Scsi_Host *, int reason);
1056 irqreturn_t sym_interrupt(struct Scsi_Host *);
1057 int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int task);
1058 struct sym_ccb *sym_get_ccb(struct sym_hcb *np, struct scsi_cmnd *cmd, u_char tag_order);
1059 void sym_free_ccb(struct sym_hcb *np, struct sym_ccb *cp);
1060 struct sym_lcb *sym_alloc_lcb(struct sym_hcb *np, u_char tn, u_char ln);
1061 int sym_free_lcb(struct sym_hcb *np, u_char tn, u_char ln);
1062 int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
1063 int sym_abort_scsiio(struct sym_hcb *np, struct scsi_cmnd *ccb, int timed_out);
1064 int sym_reset_scsi_target(struct sym_hcb *np, int target);
1065 void sym_hcb_free(struct sym_hcb *np);
1066 int sym_hcb_attach(struct Scsi_Host *shost, struct sym_fw *fw, struct sym_nvram *nvram);
1069 * Build a scatter/gather entry.
1071 * For 64 bit systems, we use the 8 upper bits of the size field
1072 * to provide bus address bits 32-39 to the SCRIPTS processor.
1073 * This allows the 895A, 896, 1010 to address up to 1 TB of memory.
1076 #if SYM_CONF_DMA_ADDRESSING_MODE == 0
1077 #define DMA_DAC_MASK DMA_BIT_MASK(32)
1078 #define sym_build_sge(np, data, badd, len) \
1079 do { \
1080 (data)->addr = cpu_to_scr(badd); \
1081 (data)->size = cpu_to_scr(len); \
1082 } while (0)
1083 #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
1084 #define DMA_DAC_MASK DMA_BIT_MASK(40)
1085 #define sym_build_sge(np, data, badd, len) \
1086 do { \
1087 (data)->addr = cpu_to_scr(badd); \
1088 (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len); \
1089 } while (0)
1090 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1091 #define DMA_DAC_MASK DMA_BIT_MASK(64)
1092 int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s);
1093 static inline void
1094 sym_build_sge(struct sym_hcb *np, struct sym_tblmove *data, u64 badd, int len)
1096 u32 h = (badd>>32);
1097 int s = (h&SYM_DMAP_MASK);
1099 if (h != np->dmap_bah[s])
1100 goto bad;
1101 good:
1102 (data)->addr = cpu_to_scr(badd);
1103 (data)->size = cpu_to_scr((s<<24) + len);
1104 return;
1105 bad:
1106 s = sym_lookup_dmap(np, h, s);
1107 goto good;
1109 #else
1110 #error "Unsupported DMA addressing mode"
1111 #endif
1114 * MEMORY ALLOCATOR.
1117 #define sym_get_mem_cluster() \
1118 (void *) __get_free_pages(GFP_ATOMIC, SYM_MEM_PAGE_ORDER)
1119 #define sym_free_mem_cluster(p) \
1120 free_pages((unsigned long)p, SYM_MEM_PAGE_ORDER)
1123 * Link between free memory chunks of a given size.
1125 typedef struct sym_m_link {
1126 struct sym_m_link *next;
1127 } *m_link_p;
1130 * Virtual to bus physical translation for a given cluster.
1131 * Such a structure is only useful with DMA abstraction.
1133 typedef struct sym_m_vtob { /* Virtual to Bus address translation */
1134 struct sym_m_vtob *next;
1135 void *vaddr; /* Virtual address */
1136 dma_addr_t baddr; /* Bus physical address */
1137 } *m_vtob_p;
1139 /* Hash this stuff a bit to speed up translations */
1140 #define VTOB_HASH_SHIFT 5
1141 #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
1142 #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
1143 #define VTOB_HASH_CODE(m) \
1144 ((((unsigned long)(m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK)
1147 * Memory pool of a given kind.
1148 * Ideally, we want to use:
1149 * 1) 1 pool for memory we donnot need to involve in DMA.
1150 * 2) The same pool for controllers that require same DMA
1151 * constraints and features.
1152 * The OS specific m_pool_id_t thing and the sym_m_pool_match()
1153 * method are expected to tell the driver about.
1155 typedef struct sym_m_pool {
1156 m_pool_ident_t dev_dmat; /* Identifies the pool (see above) */
1157 void * (*get_mem_cluster)(struct sym_m_pool *);
1158 #ifdef SYM_MEM_FREE_UNUSED
1159 void (*free_mem_cluster)(struct sym_m_pool *, void *);
1160 #endif
1161 #define M_GET_MEM_CLUSTER() mp->get_mem_cluster(mp)
1162 #define M_FREE_MEM_CLUSTER(p) mp->free_mem_cluster(mp, p)
1163 int nump;
1164 m_vtob_p vtob[VTOB_HASH_SIZE];
1165 struct sym_m_pool *next;
1166 struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
1167 } *m_pool_p;
1170 * Alloc, free and translate addresses to bus physical
1171 * for DMAable memory.
1173 void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name);
1174 void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name);
1175 dma_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m);
1178 * Verbs used by the driver code for DMAable memory handling.
1179 * The _uvptv_ macro avoids a nasty warning about pointer to volatile
1180 * being discarded.
1182 #define _uvptv_(p) ((void *)((u_long)(p)))
1184 #define _sym_calloc_dma(np, l, n) __sym_calloc_dma(np->bus_dmat, l, n)
1185 #define _sym_mfree_dma(np, p, l, n) \
1186 __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n)
1187 #define sym_calloc_dma(l, n) _sym_calloc_dma(np, l, n)
1188 #define sym_mfree_dma(p, l, n) _sym_mfree_dma(np, p, l, n)
1189 #define vtobus(p) __vtobus(np->bus_dmat, _uvptv_(p))
1192 * We have to provide the driver memory allocator with methods for
1193 * it to maintain virtual to bus physical address translations.
1196 #define sym_m_pool_match(mp_id1, mp_id2) (mp_id1 == mp_id2)
1198 static inline void *sym_m_get_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
1200 void *vaddr = NULL;
1201 dma_addr_t baddr = 0;
1203 vaddr = dma_alloc_coherent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE, &baddr,
1204 GFP_ATOMIC);
1205 if (vaddr) {
1206 vbp->vaddr = vaddr;
1207 vbp->baddr = baddr;
1209 return vaddr;
1212 static inline void sym_m_free_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
1214 dma_free_coherent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE, vbp->vaddr,
1215 vbp->baddr);
1218 #endif /* SYM_HIPD_H */