Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family |
| 3 | * of PCI-SCSI IO processors. |
| 4 | * |
| 5 | * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr> |
| 6 | * |
| 7 | * This driver is derived from the Linux sym53c8xx driver. |
| 8 | * Copyright (C) 1998-2000 Gerard Roudier |
| 9 | * |
| 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. |
| 12 | * |
| 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 |
| 17 | * |
| 18 | * Other major contributions: |
| 19 | * |
| 20 | * NVRAM detection and reading. |
| 21 | * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk> |
| 22 | * |
| 23 | *----------------------------------------------------------------------------- |
| 24 | * |
| 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. |
| 29 | * |
| 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. |
| 34 | * |
| 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 |
| 38 | */ |
| 39 | |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 40 | #include <linux/gfp.h> |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #ifndef SYM_HIPD_H |
| 43 | #define SYM_HIPD_H |
| 44 | |
| 45 | /* |
| 46 | * Generic driver options. |
| 47 | * |
| 48 | * They may be defined in platform specific headers, if they |
| 49 | * are useful. |
| 50 | * |
| 51 | * SYM_OPT_HANDLE_DIR_UNKNOWN |
| 52 | * When this option is set, the SCRIPTS used by the driver |
| 53 | * are able to handle SCSI transfers with direction not |
| 54 | * supplied by user. |
| 55 | * (set for Linux-2.0.X) |
| 56 | * |
| 57 | * SYM_OPT_HANDLE_DEVICE_QUEUEING |
| 58 | * When this option is set, the driver will use a queue per |
| 59 | * device and handle QUEUE FULL status requeuing internally. |
| 60 | * |
| 61 | * SYM_OPT_LIMIT_COMMAND_REORDERING |
| 62 | * When this option is set, the driver tries to limit tagged |
| 63 | * command reordering to some reasonnable value. |
| 64 | * (set for Linux) |
| 65 | */ |
| 66 | #if 0 |
| 67 | #define SYM_OPT_HANDLE_DIR_UNKNOWN |
| 68 | #define SYM_OPT_HANDLE_DEVICE_QUEUEING |
| 69 | #define SYM_OPT_LIMIT_COMMAND_REORDERING |
| 70 | #endif |
| 71 | |
| 72 | /* |
| 73 | * Active debugging tags and verbosity. |
| 74 | * Both DEBUG_FLAGS and sym_verbose can be redefined |
| 75 | * by the platform specific code to something else. |
| 76 | */ |
| 77 | #define DEBUG_ALLOC (0x0001) |
| 78 | #define DEBUG_PHASE (0x0002) |
| 79 | #define DEBUG_POLL (0x0004) |
| 80 | #define DEBUG_QUEUE (0x0008) |
| 81 | #define DEBUG_RESULT (0x0010) |
| 82 | #define DEBUG_SCATTER (0x0020) |
| 83 | #define DEBUG_SCRIPT (0x0040) |
| 84 | #define DEBUG_TINY (0x0080) |
| 85 | #define DEBUG_TIMING (0x0100) |
| 86 | #define DEBUG_NEGO (0x0200) |
| 87 | #define DEBUG_TAGS (0x0400) |
| 88 | #define DEBUG_POINTER (0x0800) |
| 89 | |
| 90 | #ifndef DEBUG_FLAGS |
| 91 | #define DEBUG_FLAGS (0x0000) |
| 92 | #endif |
| 93 | |
| 94 | #ifndef sym_verbose |
| 95 | #define sym_verbose (np->verbose) |
| 96 | #endif |
| 97 | |
| 98 | /* |
| 99 | * These ones should have been already defined. |
| 100 | */ |
| 101 | #ifndef assert |
| 102 | #define assert(expression) { \ |
| 103 | if (!(expression)) { \ |
| 104 | (void)panic( \ |
| 105 | "assertion \"%s\" failed: file \"%s\", line %d\n", \ |
| 106 | #expression, \ |
| 107 | __FILE__, __LINE__); \ |
| 108 | } \ |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | /* |
| 113 | * Number of tasks per device we want to handle. |
| 114 | */ |
| 115 | #if SYM_CONF_MAX_TAG_ORDER > 8 |
| 116 | #error "more than 256 tags per logical unit not allowed." |
| 117 | #endif |
| 118 | #define SYM_CONF_MAX_TASK (1<<SYM_CONF_MAX_TAG_ORDER) |
| 119 | |
| 120 | /* |
| 121 | * Donnot use more tasks that we can handle. |
| 122 | */ |
| 123 | #ifndef SYM_CONF_MAX_TAG |
| 124 | #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK |
| 125 | #endif |
| 126 | #if SYM_CONF_MAX_TAG > SYM_CONF_MAX_TASK |
| 127 | #undef SYM_CONF_MAX_TAG |
| 128 | #define SYM_CONF_MAX_TAG SYM_CONF_MAX_TASK |
| 129 | #endif |
| 130 | |
| 131 | /* |
| 132 | * This one means 'NO TAG for this job' |
| 133 | */ |
| 134 | #define NO_TAG (256) |
| 135 | |
| 136 | /* |
| 137 | * Number of SCSI targets. |
| 138 | */ |
| 139 | #if SYM_CONF_MAX_TARGET > 16 |
| 140 | #error "more than 16 targets not allowed." |
| 141 | #endif |
| 142 | |
| 143 | /* |
| 144 | * Number of logical units per target. |
| 145 | */ |
| 146 | #if SYM_CONF_MAX_LUN > 64 |
| 147 | #error "more than 64 logical units per target not allowed." |
| 148 | #endif |
| 149 | |
| 150 | /* |
| 151 | * Asynchronous pre-scaler (ns). Shall be 40 for |
| 152 | * the SCSI timings to be compliant. |
| 153 | */ |
| 154 | #define SYM_CONF_MIN_ASYNC (40) |
| 155 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * MEMORY ALLOCATOR. |
| 159 | */ |
| 160 | |
| 161 | #define SYM_MEM_WARN 1 /* Warn on failed operations */ |
| 162 | |
| 163 | #define SYM_MEM_PAGE_ORDER 0 /* 1 PAGE maximum */ |
| 164 | #define SYM_MEM_CLUSTER_SHIFT (PAGE_SHIFT+SYM_MEM_PAGE_ORDER) |
| 165 | #define SYM_MEM_FREE_UNUSED /* Free unused pages immediately */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* |
| 167 | * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16. |
| 168 | * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized. |
| 169 | * (1 PAGE at a time is just fine). |
| 170 | */ |
| 171 | #define SYM_MEM_SHIFT 4 |
| 172 | #define SYM_MEM_CLUSTER_SIZE (1UL << SYM_MEM_CLUSTER_SHIFT) |
| 173 | #define SYM_MEM_CLUSTER_MASK (SYM_MEM_CLUSTER_SIZE-1) |
| 174 | |
| 175 | /* |
| 176 | * Number of entries in the START and DONE queues. |
| 177 | * |
| 178 | * We limit to 1 PAGE in order to succeed allocation of |
| 179 | * these queues. Each entry is 8 bytes long (2 DWORDS). |
| 180 | */ |
| 181 | #ifdef SYM_CONF_MAX_START |
| 182 | #define SYM_CONF_MAX_QUEUE (SYM_CONF_MAX_START+2) |
| 183 | #else |
| 184 | #define SYM_CONF_MAX_QUEUE (7*SYM_CONF_MAX_TASK+2) |
| 185 | #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2) |
| 186 | #endif |
| 187 | |
| 188 | #if SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8 |
| 189 | #undef SYM_CONF_MAX_QUEUE |
| 190 | #define SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8) |
| 191 | #undef SYM_CONF_MAX_START |
| 192 | #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2) |
| 193 | #endif |
| 194 | |
| 195 | /* |
| 196 | * For this one, we want a short name :-) |
| 197 | */ |
| 198 | #define MAX_QUEUE SYM_CONF_MAX_QUEUE |
| 199 | |
| 200 | /* |
| 201 | * Common definitions for both bus space based and legacy IO methods. |
| 202 | */ |
| 203 | |
| 204 | #define INB_OFF(np, o) ioread8(np->s.ioaddr + (o)) |
| 205 | #define INW_OFF(np, o) ioread16(np->s.ioaddr + (o)) |
| 206 | #define INL_OFF(np, o) ioread32(np->s.ioaddr + (o)) |
| 207 | |
| 208 | #define OUTB_OFF(np, o, val) iowrite8((val), np->s.ioaddr + (o)) |
| 209 | #define OUTW_OFF(np, o, val) iowrite16((val), np->s.ioaddr + (o)) |
| 210 | #define OUTL_OFF(np, o, val) iowrite32((val), np->s.ioaddr + (o)) |
| 211 | |
| 212 | #define INB(np, r) INB_OFF(np, offsetof(struct sym_reg, r)) |
| 213 | #define INW(np, r) INW_OFF(np, offsetof(struct sym_reg, r)) |
| 214 | #define INL(np, r) INL_OFF(np, offsetof(struct sym_reg, r)) |
| 215 | |
| 216 | #define OUTB(np, r, v) OUTB_OFF(np, offsetof(struct sym_reg, r), (v)) |
| 217 | #define OUTW(np, r, v) OUTW_OFF(np, offsetof(struct sym_reg, r), (v)) |
| 218 | #define OUTL(np, r, v) OUTL_OFF(np, offsetof(struct sym_reg, r), (v)) |
| 219 | |
| 220 | #define OUTONB(np, r, m) OUTB(np, r, INB(np, r) | (m)) |
| 221 | #define OUTOFFB(np, r, m) OUTB(np, r, INB(np, r) & ~(m)) |
| 222 | #define OUTONW(np, r, m) OUTW(np, r, INW(np, r) | (m)) |
| 223 | #define OUTOFFW(np, r, m) OUTW(np, r, INW(np, r) & ~(m)) |
| 224 | #define OUTONL(np, r, m) OUTL(np, r, INL(np, r) | (m)) |
| 225 | #define OUTOFFL(np, r, m) OUTL(np, r, INL(np, r) & ~(m)) |
| 226 | |
| 227 | /* |
| 228 | * We normally want the chip to have a consistent view |
| 229 | * of driver internal data structures when we restart it. |
| 230 | * Thus these macros. |
| 231 | */ |
| 232 | #define OUTL_DSP(np, v) \ |
| 233 | do { \ |
| 234 | MEMORY_WRITE_BARRIER(); \ |
| 235 | OUTL(np, nc_dsp, (v)); \ |
| 236 | } while (0) |
| 237 | |
| 238 | #define OUTONB_STD() \ |
| 239 | do { \ |
| 240 | MEMORY_WRITE_BARRIER(); \ |
| 241 | OUTONB(np, nc_dcntl, (STD|NOCOM)); \ |
| 242 | } while (0) |
| 243 | |
| 244 | /* |
| 245 | * Command control block states. |
| 246 | */ |
| 247 | #define HS_IDLE (0) |
| 248 | #define HS_BUSY (1) |
| 249 | #define HS_NEGOTIATE (2) /* sync/wide data transfer*/ |
| 250 | #define HS_DISCONNECT (3) /* Disconnected by target */ |
| 251 | #define HS_WAIT (4) /* waiting for resource */ |
| 252 | |
| 253 | #define HS_DONEMASK (0x80) |
| 254 | #define HS_COMPLETE (4|HS_DONEMASK) |
| 255 | #define HS_SEL_TIMEOUT (5|HS_DONEMASK) /* Selection timeout */ |
| 256 | #define HS_UNEXPECTED (6|HS_DONEMASK) /* Unexpected disconnect */ |
| 257 | #define HS_COMP_ERR (7|HS_DONEMASK) /* Completed with error */ |
| 258 | |
| 259 | /* |
| 260 | * Software Interrupt Codes |
| 261 | */ |
| 262 | #define SIR_BAD_SCSI_STATUS (1) |
| 263 | #define SIR_SEL_ATN_NO_MSG_OUT (2) |
| 264 | #define SIR_MSG_RECEIVED (3) |
| 265 | #define SIR_MSG_WEIRD (4) |
| 266 | #define SIR_NEGO_FAILED (5) |
| 267 | #define SIR_NEGO_PROTO (6) |
| 268 | #define SIR_SCRIPT_STOPPED (7) |
| 269 | #define SIR_REJECT_TO_SEND (8) |
| 270 | #define SIR_SWIDE_OVERRUN (9) |
| 271 | #define SIR_SODL_UNDERRUN (10) |
| 272 | #define SIR_RESEL_NO_MSG_IN (11) |
| 273 | #define SIR_RESEL_NO_IDENTIFY (12) |
| 274 | #define SIR_RESEL_BAD_LUN (13) |
| 275 | #define SIR_TARGET_SELECTED (14) |
| 276 | #define SIR_RESEL_BAD_I_T_L (15) |
| 277 | #define SIR_RESEL_BAD_I_T_L_Q (16) |
| 278 | #define SIR_ABORT_SENT (17) |
| 279 | #define SIR_RESEL_ABORTED (18) |
| 280 | #define SIR_MSG_OUT_DONE (19) |
| 281 | #define SIR_COMPLETE_ERROR (20) |
| 282 | #define SIR_DATA_OVERRUN (21) |
| 283 | #define SIR_BAD_PHASE (22) |
| 284 | #if SYM_CONF_DMA_ADDRESSING_MODE == 2 |
| 285 | #define SIR_DMAP_DIRTY (23) |
| 286 | #define SIR_MAX (23) |
| 287 | #else |
| 288 | #define SIR_MAX (22) |
| 289 | #endif |
| 290 | |
| 291 | /* |
| 292 | * Extended error bit codes. |
| 293 | * xerr_status field of struct sym_ccb. |
| 294 | */ |
| 295 | #define XE_EXTRA_DATA (1) /* unexpected data phase */ |
| 296 | #define XE_BAD_PHASE (1<<1) /* illegal phase (4/5) */ |
| 297 | #define XE_PARITY_ERR (1<<2) /* unrecovered SCSI parity error */ |
| 298 | #define XE_SODL_UNRUN (1<<3) /* ODD transfer in DATA OUT phase */ |
| 299 | #define XE_SWIDE_OVRUN (1<<4) /* ODD transfer in DATA IN phase */ |
| 300 | |
| 301 | /* |
| 302 | * Negotiation status. |
| 303 | * nego_status field of struct sym_ccb. |
| 304 | */ |
| 305 | #define NS_SYNC (1) |
| 306 | #define NS_WIDE (2) |
| 307 | #define NS_PPR (3) |
| 308 | |
| 309 | /* |
| 310 | * A CCB hashed table is used to retrieve CCB address |
| 311 | * from DSA value. |
| 312 | */ |
| 313 | #define CCB_HASH_SHIFT 8 |
| 314 | #define CCB_HASH_SIZE (1UL << CCB_HASH_SHIFT) |
| 315 | #define CCB_HASH_MASK (CCB_HASH_SIZE-1) |
| 316 | #if 1 |
| 317 | #define CCB_HASH_CODE(dsa) \ |
| 318 | (((dsa) >> (_LGRU16_(sizeof(struct sym_ccb)))) & CCB_HASH_MASK) |
| 319 | #else |
| 320 | #define CCB_HASH_CODE(dsa) (((dsa) >> 9) & CCB_HASH_MASK) |
| 321 | #endif |
| 322 | |
| 323 | #if SYM_CONF_DMA_ADDRESSING_MODE == 2 |
| 324 | /* |
| 325 | * We may want to use segment registers for 64 bit DMA. |
| 326 | * 16 segments registers -> up to 64 GB addressable. |
| 327 | */ |
| 328 | #define SYM_DMAP_SHIFT (4) |
| 329 | #define SYM_DMAP_SIZE (1u<<SYM_DMAP_SHIFT) |
| 330 | #define SYM_DMAP_MASK (SYM_DMAP_SIZE-1) |
| 331 | #endif |
| 332 | |
| 333 | /* |
| 334 | * Device flags. |
| 335 | */ |
| 336 | #define SYM_DISC_ENABLED (1) |
| 337 | #define SYM_TAGS_ENABLED (1<<1) |
| 338 | #define SYM_SCAN_BOOT_DISABLED (1<<2) |
| 339 | #define SYM_SCAN_LUNS_DISABLED (1<<3) |
| 340 | |
| 341 | /* |
| 342 | * Host adapter miscellaneous flags. |
| 343 | */ |
| 344 | #define SYM_AVOID_BUS_RESET (1) |
| 345 | |
| 346 | /* |
| 347 | * Misc. |
| 348 | */ |
| 349 | #define SYM_SNOOP_TIMEOUT (10000000) |
| 350 | #define BUS_8_BIT 0 |
| 351 | #define BUS_16_BIT 1 |
| 352 | |
| 353 | /* |
| 354 | * Gather negotiable parameters value |
| 355 | */ |
| 356 | struct sym_trans { |
| 357 | u8 period; |
| 358 | u8 offset; |
| 359 | unsigned int width:1; |
| 360 | unsigned int iu:1; |
| 361 | unsigned int dt:1; |
| 362 | unsigned int qas:1; |
| 363 | unsigned int check_nego:1; |
| 364 | }; |
| 365 | |
| 366 | /* |
| 367 | * Global TCB HEADER. |
| 368 | * |
| 369 | * Due to lack of indirect addressing on earlier NCR chips, |
| 370 | * this substructure is copied from the TCB to a global |
| 371 | * address after selection. |
| 372 | * For SYMBIOS chips that support LOAD/STORE this copy is |
| 373 | * not needed and thus not performed. |
| 374 | */ |
| 375 | struct sym_tcbh { |
| 376 | /* |
| 377 | * Scripts bus addresses of LUN table accessed from scripts. |
| 378 | * LUN #0 is a special case, since multi-lun devices are rare, |
| 379 | * and we we want to speed-up the general case and not waste |
| 380 | * resources. |
| 381 | */ |
| 382 | u32 luntbl_sa; /* bus address of this table */ |
| 383 | u32 lun0_sa; /* bus address of LCB #0 */ |
| 384 | /* |
| 385 | * Actual SYNC/WIDE IO registers value for this target. |
| 386 | * 'sval', 'wval' and 'uval' are read from SCRIPTS and |
| 387 | * so have alignment constraints. |
| 388 | */ |
| 389 | /*0*/ u_char uval; /* -> SCNTL4 register */ |
| 390 | /*1*/ u_char sval; /* -> SXFER io register */ |
| 391 | /*2*/ u_char filler1; |
| 392 | /*3*/ u_char wval; /* -> SCNTL3 io register */ |
| 393 | }; |
| 394 | |
| 395 | /* |
| 396 | * Target Control Block |
| 397 | */ |
| 398 | struct sym_tcb { |
| 399 | /* |
| 400 | * TCB header. |
| 401 | * Assumed at offset 0. |
| 402 | */ |
| 403 | /*0*/ struct sym_tcbh head; |
| 404 | |
| 405 | /* |
| 406 | * LUN table used by the SCRIPTS processor. |
| 407 | * An array of bus addresses is used on reselection. |
| 408 | */ |
| 409 | u32 *luntbl; /* LCBs bus address table */ |
| 410 | |
| 411 | /* |
| 412 | * LUN table used by the C code. |
| 413 | */ |
| 414 | struct sym_lcb *lun0p; /* LCB of LUN #0 (usual case) */ |
| 415 | #if SYM_CONF_MAX_LUN > 1 |
| 416 | struct sym_lcb **lunmp; /* Other LCBs [1..MAX_LUN] */ |
| 417 | #endif |
| 418 | |
| 419 | /* |
| 420 | * Bitmap that tells about LUNs that succeeded at least |
| 421 | * 1 IO and therefore assumed to be a real device. |
| 422 | * Avoid useless allocation of the LCB structure. |
| 423 | */ |
| 424 | u32 lun_map[(SYM_CONF_MAX_LUN+31)/32]; |
| 425 | |
| 426 | /* |
| 427 | * Bitmap that tells about LUNs that haven't yet an LCB |
| 428 | * allocated (not discovered or LCB allocation failed). |
| 429 | */ |
| 430 | u32 busy0_map[(SYM_CONF_MAX_LUN+31)/32]; |
| 431 | |
| 432 | #ifdef SYM_HAVE_STCB |
| 433 | /* |
| 434 | * O/S specific data structure. |
| 435 | */ |
| 436 | struct sym_stcb s; |
| 437 | #endif |
| 438 | |
| 439 | /* Transfer goal */ |
| 440 | struct sym_trans tgoal; |
| 441 | |
| 442 | /* |
| 443 | * Keep track of the CCB used for the negotiation in order |
| 444 | * to ensure that only 1 negotiation is queued at a time. |
| 445 | */ |
| 446 | struct sym_ccb * nego_cp; /* CCB used for the nego */ |
| 447 | |
| 448 | /* |
| 449 | * Set when we want to reset the device. |
| 450 | */ |
| 451 | u_char to_reset; |
| 452 | |
| 453 | /* |
| 454 | * Other user settable limits and options. |
| 455 | * These limits are read from the NVRAM if present. |
| 456 | */ |
| 457 | u_char usrflags; |
| 458 | u_short usrtags; |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 459 | struct scsi_target *starget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | }; |
| 461 | |
| 462 | /* |
| 463 | * Global LCB HEADER. |
| 464 | * |
| 465 | * Due to lack of indirect addressing on earlier NCR chips, |
| 466 | * this substructure is copied from the LCB to a global |
| 467 | * address after selection. |
| 468 | * For SYMBIOS chips that support LOAD/STORE this copy is |
| 469 | * not needed and thus not performed. |
| 470 | */ |
| 471 | struct sym_lcbh { |
| 472 | /* |
| 473 | * SCRIPTS address jumped by SCRIPTS on reselection. |
| 474 | * For not probed logical units, this address points to |
| 475 | * SCRIPTS that deal with bad LU handling (must be at |
| 476 | * offset zero of the LCB for that reason). |
| 477 | */ |
| 478 | /*0*/ u32 resel_sa; |
| 479 | |
| 480 | /* |
| 481 | * Task (bus address of a CCB) read from SCRIPTS that points |
| 482 | * to the unique ITL nexus allowed to be disconnected. |
| 483 | */ |
| 484 | u32 itl_task_sa; |
| 485 | |
| 486 | /* |
| 487 | * Task table bus address (read from SCRIPTS). |
| 488 | */ |
| 489 | u32 itlq_tbl_sa; |
| 490 | }; |
| 491 | |
| 492 | /* |
| 493 | * Logical Unit Control Block |
| 494 | */ |
| 495 | struct sym_lcb { |
| 496 | /* |
| 497 | * TCB header. |
| 498 | * Assumed at offset 0. |
| 499 | */ |
| 500 | /*0*/ struct sym_lcbh head; |
| 501 | |
| 502 | /* |
| 503 | * Task table read from SCRIPTS that contains pointers to |
| 504 | * ITLQ nexuses. The bus address read from SCRIPTS is |
| 505 | * inside the header. |
| 506 | */ |
| 507 | u32 *itlq_tbl; /* Kernel virtual address */ |
| 508 | |
| 509 | /* |
| 510 | * Busy CCBs management. |
| 511 | */ |
| 512 | u_short busy_itlq; /* Number of busy tagged CCBs */ |
| 513 | u_short busy_itl; /* Number of busy untagged CCBs */ |
| 514 | |
| 515 | /* |
| 516 | * Circular tag allocation buffer. |
| 517 | */ |
| 518 | u_short ia_tag; /* Tag allocation index */ |
| 519 | u_short if_tag; /* Tag release index */ |
| 520 | u_char *cb_tags; /* Circular tags buffer */ |
| 521 | |
| 522 | /* |
| 523 | * O/S specific data structure. |
| 524 | */ |
| 525 | #ifdef SYM_HAVE_SLCB |
| 526 | struct sym_slcb s; |
| 527 | #endif |
| 528 | |
| 529 | #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING |
| 530 | /* |
| 531 | * Optionnaly the driver can handle device queueing, |
| 532 | * and requeues internally command to redo. |
| 533 | */ |
| 534 | SYM_QUEHEAD waiting_ccbq; |
| 535 | SYM_QUEHEAD started_ccbq; |
| 536 | int num_sgood; |
| 537 | u_short started_tags; |
| 538 | u_short started_no_tag; |
| 539 | u_short started_max; |
| 540 | u_short started_limit; |
| 541 | #endif |
| 542 | |
| 543 | #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING |
| 544 | /* |
| 545 | * Optionally the driver can try to prevent SCSI |
| 546 | * IOs from being reordered too much. |
| 547 | */ |
| 548 | u_char tags_si; /* Current index to tags sum */ |
| 549 | u_short tags_sum[2]; /* Tags sum counters */ |
| 550 | u_short tags_since; /* # of tags since last switch */ |
| 551 | #endif |
| 552 | |
| 553 | /* |
| 554 | * Set when we want to clear all tasks. |
| 555 | */ |
| 556 | u_char to_clear; |
| 557 | |
| 558 | /* |
| 559 | * Capabilities. |
| 560 | */ |
| 561 | u_char user_flags; |
| 562 | u_char curr_flags; |
| 563 | }; |
| 564 | |
| 565 | /* |
| 566 | * Action from SCRIPTS on a task. |
| 567 | * Is part of the CCB, but is also used separately to plug |
| 568 | * error handling action to perform from SCRIPTS. |
| 569 | */ |
| 570 | struct sym_actscr { |
| 571 | u32 start; /* Jumped by SCRIPTS after selection */ |
| 572 | u32 restart; /* Jumped by SCRIPTS on relection */ |
| 573 | }; |
| 574 | |
| 575 | /* |
| 576 | * Phase mismatch context. |
| 577 | * |
| 578 | * It is part of the CCB and is used as parameters for the |
| 579 | * DATA pointer. We need two contexts to handle correctly the |
| 580 | * SAVED DATA POINTER. |
| 581 | */ |
| 582 | struct sym_pmc { |
| 583 | struct sym_tblmove sg; /* Updated interrupted SG block */ |
| 584 | u32 ret; /* SCRIPT return address */ |
| 585 | }; |
| 586 | |
| 587 | /* |
| 588 | * LUN control block lookup. |
| 589 | * We use a direct pointer for LUN #0, and a table of |
| 590 | * pointers which is only allocated for devices that support |
| 591 | * LUN(s) > 0. |
| 592 | */ |
| 593 | #if SYM_CONF_MAX_LUN <= 1 |
| 594 | #define sym_lp(tp, lun) (!lun) ? (tp)->lun0p : NULL |
| 595 | #else |
| 596 | #define sym_lp(tp, lun) \ |
| 597 | (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[(lun)] : NULL |
| 598 | #endif |
| 599 | |
| 600 | /* |
| 601 | * Status are used by the host and the script processor. |
| 602 | * |
| 603 | * The last four bytes (status[4]) are copied to the |
| 604 | * scratchb register (declared as scr0..scr3) just after the |
| 605 | * select/reselect, and copied back just after disconnecting. |
| 606 | * Inside the script the XX_REG are used. |
| 607 | */ |
| 608 | |
| 609 | /* |
| 610 | * Last four bytes (script) |
| 611 | */ |
| 612 | #define HX_REG scr0 |
| 613 | #define HX_PRT nc_scr0 |
| 614 | #define HS_REG scr1 |
| 615 | #define HS_PRT nc_scr1 |
| 616 | #define SS_REG scr2 |
| 617 | #define SS_PRT nc_scr2 |
| 618 | #define HF_REG scr3 |
| 619 | #define HF_PRT nc_scr3 |
| 620 | |
| 621 | /* |
| 622 | * Last four bytes (host) |
| 623 | */ |
| 624 | #define host_xflags phys.head.status[0] |
| 625 | #define host_status phys.head.status[1] |
| 626 | #define ssss_status phys.head.status[2] |
| 627 | #define host_flags phys.head.status[3] |
| 628 | |
| 629 | /* |
| 630 | * Host flags |
| 631 | */ |
| 632 | #define HF_IN_PM0 1u |
| 633 | #define HF_IN_PM1 (1u<<1) |
| 634 | #define HF_ACT_PM (1u<<2) |
| 635 | #define HF_DP_SAVED (1u<<3) |
| 636 | #define HF_SENSE (1u<<4) |
| 637 | #define HF_EXT_ERR (1u<<5) |
| 638 | #define HF_DATA_IN (1u<<6) |
| 639 | #ifdef SYM_CONF_IARB_SUPPORT |
| 640 | #define HF_HINT_IARB (1u<<7) |
| 641 | #endif |
| 642 | |
| 643 | /* |
| 644 | * More host flags |
| 645 | */ |
| 646 | #if SYM_CONF_DMA_ADDRESSING_MODE == 2 |
| 647 | #define HX_DMAP_DIRTY (1u<<7) |
| 648 | #endif |
| 649 | |
| 650 | /* |
| 651 | * Global CCB HEADER. |
| 652 | * |
| 653 | * Due to lack of indirect addressing on earlier NCR chips, |
| 654 | * this substructure is copied from the ccb to a global |
| 655 | * address after selection (or reselection) and copied back |
| 656 | * before disconnect. |
| 657 | * For SYMBIOS chips that support LOAD/STORE this copy is |
| 658 | * not needed and thus not performed. |
| 659 | */ |
| 660 | |
| 661 | struct sym_ccbh { |
| 662 | /* |
| 663 | * Start and restart SCRIPTS addresses (must be at 0). |
| 664 | */ |
| 665 | /*0*/ struct sym_actscr go; |
| 666 | |
| 667 | /* |
| 668 | * SCRIPTS jump address that deal with data pointers. |
| 669 | * 'savep' points to the position in the script responsible |
| 670 | * for the actual transfer of data. |
| 671 | * It's written on reception of a SAVE_DATA_POINTER message. |
| 672 | */ |
| 673 | u32 savep; /* Jump address to saved data pointer */ |
| 674 | u32 lastp; /* SCRIPTS address at end of data */ |
| 675 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
| 676 | u32 wlastp; |
| 677 | #endif |
| 678 | |
| 679 | /* |
| 680 | * Status fields. |
| 681 | */ |
| 682 | u8 status[4]; |
| 683 | }; |
| 684 | |
| 685 | /* |
| 686 | * GET/SET the value of the data pointer used by SCRIPTS. |
| 687 | * |
| 688 | * We must distinguish between the LOAD/STORE-based SCRIPTS |
| 689 | * that use directly the header in the CCB, and the NCR-GENERIC |
| 690 | * SCRIPTS that use the copy of the header in the HCB. |
| 691 | */ |
| 692 | #if SYM_CONF_GENERIC_SUPPORT |
| 693 | #define sym_set_script_dp(np, cp, dp) \ |
| 694 | do { \ |
| 695 | if (np->features & FE_LDSTR) \ |
| 696 | cp->phys.head.lastp = cpu_to_scr(dp); \ |
| 697 | else \ |
| 698 | np->ccb_head.lastp = cpu_to_scr(dp); \ |
| 699 | } while (0) |
| 700 | #define sym_get_script_dp(np, cp) \ |
| 701 | scr_to_cpu((np->features & FE_LDSTR) ? \ |
| 702 | cp->phys.head.lastp : np->ccb_head.lastp) |
| 703 | #else |
| 704 | #define sym_set_script_dp(np, cp, dp) \ |
| 705 | do { \ |
| 706 | cp->phys.head.lastp = cpu_to_scr(dp); \ |
| 707 | } while (0) |
| 708 | |
| 709 | #define sym_get_script_dp(np, cp) (cp->phys.head.lastp) |
| 710 | #endif |
| 711 | |
| 712 | /* |
| 713 | * Data Structure Block |
| 714 | * |
| 715 | * During execution of a ccb by the script processor, the |
| 716 | * DSA (data structure address) register points to this |
| 717 | * substructure of the ccb. |
| 718 | */ |
| 719 | struct sym_dsb { |
| 720 | /* |
| 721 | * CCB header. |
| 722 | * Also assumed at offset 0 of the sym_ccb structure. |
| 723 | */ |
| 724 | /*0*/ struct sym_ccbh head; |
| 725 | |
| 726 | /* |
| 727 | * Phase mismatch contexts. |
| 728 | * We need two to handle correctly the SAVED DATA POINTER. |
| 729 | * MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic |
| 730 | * for address calculation from SCRIPTS. |
| 731 | */ |
| 732 | struct sym_pmc pm0; |
| 733 | struct sym_pmc pm1; |
| 734 | |
| 735 | /* |
| 736 | * Table data for Script |
| 737 | */ |
| 738 | struct sym_tblsel select; |
| 739 | struct sym_tblmove smsg; |
| 740 | struct sym_tblmove smsg_ext; |
| 741 | struct sym_tblmove cmd; |
| 742 | struct sym_tblmove sense; |
| 743 | struct sym_tblmove wresid; |
| 744 | struct sym_tblmove data [SYM_CONF_MAX_SG]; |
| 745 | }; |
| 746 | |
| 747 | /* |
| 748 | * Our Command Control Block |
| 749 | */ |
| 750 | struct sym_ccb { |
| 751 | /* |
| 752 | * This is the data structure which is pointed by the DSA |
| 753 | * register when it is executed by the script processor. |
| 754 | * It must be the first entry. |
| 755 | */ |
| 756 | struct sym_dsb phys; |
| 757 | |
| 758 | /* |
| 759 | * Pointer to CAM ccb and related stuff. |
| 760 | */ |
| 761 | struct scsi_cmnd *cmd; /* CAM scsiio ccb */ |
| 762 | u8 cdb_buf[16]; /* Copy of CDB */ |
| 763 | #define SYM_SNS_BBUF_LEN 32 |
| 764 | u8 sns_bbuf[SYM_SNS_BBUF_LEN]; /* Bounce buffer for sense data */ |
| 765 | int data_len; /* Total data length */ |
| 766 | int segments; /* Number of SG segments */ |
| 767 | |
| 768 | u8 order; /* Tag type (if tagged command) */ |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 769 | unsigned char odd_byte_adjustment; /* odd-sized req on wide bus */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | u_char nego_status; /* Negotiation status */ |
| 772 | u_char xerr_status; /* Extended error flags */ |
| 773 | u32 extra_bytes; /* Extraneous bytes transferred */ |
| 774 | |
| 775 | /* |
| 776 | * Message areas. |
| 777 | * We prepare a message to be sent after selection. |
| 778 | * We may use a second one if the command is rescheduled |
| 779 | * due to CHECK_CONDITION or COMMAND TERMINATED. |
| 780 | * Contents are IDENTIFY and SIMPLE_TAG. |
| 781 | * While negotiating sync or wide transfer, |
| 782 | * a SDTR or WDTR message is appended. |
| 783 | */ |
| 784 | u_char scsi_smsg [12]; |
| 785 | u_char scsi_smsg2[12]; |
| 786 | |
| 787 | /* |
| 788 | * Auto request sense related fields. |
| 789 | */ |
| 790 | u_char sensecmd[6]; /* Request Sense command */ |
| 791 | u_char sv_scsi_status; /* Saved SCSI status */ |
| 792 | u_char sv_xerr_status; /* Saved extended status */ |
| 793 | int sv_resid; /* Saved residual */ |
| 794 | |
| 795 | /* |
| 796 | * Other fields. |
| 797 | */ |
| 798 | u32 ccb_ba; /* BUS address of this CCB */ |
| 799 | u_short tag; /* Tag for this transfer */ |
| 800 | /* NO_TAG means no tag */ |
| 801 | u_char target; |
| 802 | u_char lun; |
| 803 | struct sym_ccb *link_ccbh; /* Host adapter CCB hash chain */ |
| 804 | SYM_QUEHEAD link_ccbq; /* Link to free/busy CCB queue */ |
| 805 | u32 startp; /* Initial data pointer */ |
| 806 | u32 goalp; /* Expected last data pointer */ |
| 807 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
| 808 | u32 wgoalp; |
| 809 | #endif |
| 810 | int ext_sg; /* Extreme data pointer, used */ |
| 811 | int ext_ofs; /* to calculate the residual. */ |
| 812 | #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING |
| 813 | SYM_QUEHEAD link2_ccbq; /* Link for device queueing */ |
| 814 | u_char started; /* CCB queued to the squeue */ |
| 815 | #endif |
| 816 | u_char to_abort; /* Want this IO to be aborted */ |
| 817 | #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING |
| 818 | u_char tags_si; /* Lun tags sum index (0,1) */ |
| 819 | #endif |
| 820 | }; |
| 821 | |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 822 | #define CCB_BA(cp,lbl) cpu_to_scr(cp->ccb_ba + offsetof(struct sym_ccb, lbl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
| 825 | #define sym_goalp(cp) ((cp->host_flags & HF_DATA_IN) ? cp->goalp : cp->wgoalp) |
| 826 | #else |
| 827 | #define sym_goalp(cp) (cp->goalp) |
| 828 | #endif |
| 829 | |
| 830 | typedef struct device *m_pool_ident_t; |
| 831 | |
| 832 | /* |
| 833 | * Host Control Block |
| 834 | */ |
| 835 | struct sym_hcb { |
| 836 | /* |
| 837 | * Global headers. |
| 838 | * Due to poorness of addressing capabilities, earlier |
| 839 | * chips (810, 815, 825) copy part of the data structures |
| 840 | * (CCB, TCB and LCB) in fixed areas. |
| 841 | */ |
| 842 | #if SYM_CONF_GENERIC_SUPPORT |
| 843 | struct sym_ccbh ccb_head; |
| 844 | struct sym_tcbh tcb_head; |
| 845 | struct sym_lcbh lcb_head; |
| 846 | #endif |
| 847 | /* |
| 848 | * Idle task and invalid task actions and |
| 849 | * their bus addresses. |
| 850 | */ |
| 851 | struct sym_actscr idletask, notask, bad_itl, bad_itlq; |
| 852 | u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba; |
| 853 | |
| 854 | /* |
| 855 | * Dummy lun table to protect us against target |
| 856 | * returning bad lun number on reselection. |
| 857 | */ |
| 858 | u32 *badluntbl; /* Table physical address */ |
| 859 | u32 badlun_sa; /* SCRIPT handler BUS address */ |
| 860 | |
| 861 | /* |
| 862 | * Bus address of this host control block. |
| 863 | */ |
| 864 | u32 hcb_ba; |
| 865 | |
| 866 | /* |
| 867 | * Bit 32-63 of the on-chip RAM bus address in LE format. |
| 868 | * The START_RAM64 script loads the MMRS and MMWS from this |
| 869 | * field. |
| 870 | */ |
| 871 | u32 scr_ram_seg; |
| 872 | |
| 873 | /* |
| 874 | * Initial value of some IO register bits. |
| 875 | * These values are assumed to have been set by BIOS, and may |
| 876 | * be used to probe adapter implementation differences. |
| 877 | */ |
| 878 | u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4, |
| 879 | sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4, |
| 880 | sv_stest1; |
| 881 | |
| 882 | /* |
| 883 | * Actual initial value of IO register bits used by the |
| 884 | * driver. They are loaded at initialisation according to |
| 885 | * features that are to be enabled/disabled. |
| 886 | */ |
| 887 | u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4, |
| 888 | rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4; |
| 889 | |
| 890 | /* |
| 891 | * Target data. |
| 892 | */ |
| 893 | struct sym_tcb target[SYM_CONF_MAX_TARGET]; |
| 894 | |
| 895 | /* |
| 896 | * Target control block bus address array used by the SCRIPT |
| 897 | * on reselection. |
| 898 | */ |
| 899 | u32 *targtbl; |
| 900 | u32 targtbl_ba; |
| 901 | |
| 902 | /* |
| 903 | * DMA pool handle for this HBA. |
| 904 | */ |
| 905 | m_pool_ident_t bus_dmat; |
| 906 | |
| 907 | /* |
| 908 | * O/S specific data structure |
| 909 | */ |
| 910 | struct sym_shcb s; |
| 911 | |
| 912 | /* |
| 913 | * Physical bus addresses of the chip. |
| 914 | */ |
| 915 | u32 mmio_ba; /* MMIO 32 bit BUS address */ |
| 916 | int mmio_ws; /* MMIO Window size */ |
| 917 | |
| 918 | u32 ram_ba; /* RAM 32 bit BUS address */ |
| 919 | int ram_ws; /* RAM window size */ |
| 920 | |
| 921 | /* |
| 922 | * SCRIPTS virtual and physical bus addresses. |
| 923 | * 'script' is loaded in the on-chip RAM if present. |
| 924 | * 'scripth' stays in main memory for all chips except the |
| 925 | * 53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM. |
| 926 | */ |
| 927 | u_char *scripta0; /* Copy of scripts A, B, Z */ |
| 928 | u_char *scriptb0; |
| 929 | u_char *scriptz0; |
| 930 | u32 scripta_ba; /* Actual scripts A, B, Z */ |
| 931 | u32 scriptb_ba; /* 32 bit bus addresses. */ |
| 932 | u32 scriptz_ba; |
| 933 | u_short scripta_sz; /* Actual size of script A, B, Z*/ |
| 934 | u_short scriptb_sz; |
| 935 | u_short scriptz_sz; |
| 936 | |
| 937 | /* |
| 938 | * Bus addresses, setup and patch methods for |
| 939 | * the selected firmware. |
| 940 | */ |
| 941 | struct sym_fwa_ba fwa_bas; /* Useful SCRIPTA bus addresses */ |
| 942 | struct sym_fwb_ba fwb_bas; /* Useful SCRIPTB bus addresses */ |
| 943 | struct sym_fwz_ba fwz_bas; /* Useful SCRIPTZ bus addresses */ |
| 944 | void (*fw_setup)(struct sym_hcb *np, struct sym_fw *fw); |
| 945 | void (*fw_patch)(struct sym_hcb *np); |
| 946 | char *fw_name; |
| 947 | |
| 948 | /* |
| 949 | * General controller parameters and configuration. |
| 950 | */ |
| 951 | u_short device_id; /* PCI device id */ |
| 952 | u_char revision_id; /* PCI device revision id */ |
| 953 | u_int features; /* Chip features map */ |
| 954 | u_char myaddr; /* SCSI id of the adapter */ |
| 955 | u_char maxburst; /* log base 2 of dwords burst */ |
| 956 | u_char maxwide; /* Maximum transfer width */ |
| 957 | u_char minsync; /* Min sync period factor (ST) */ |
| 958 | u_char maxsync; /* Max sync period factor (ST) */ |
| 959 | u_char maxoffs; /* Max scsi offset (ST) */ |
| 960 | u_char minsync_dt; /* Min sync period factor (DT) */ |
| 961 | u_char maxsync_dt; /* Max sync period factor (DT) */ |
| 962 | u_char maxoffs_dt; /* Max scsi offset (DT) */ |
| 963 | u_char multiplier; /* Clock multiplier (1,2,4) */ |
| 964 | u_char clock_divn; /* Number of clock divisors */ |
| 965 | u32 clock_khz; /* SCSI clock frequency in KHz */ |
| 966 | u32 pciclk_khz; /* Estimated PCI clock in KHz */ |
| 967 | /* |
| 968 | * Start queue management. |
| 969 | * It is filled up by the host processor and accessed by the |
| 970 | * SCRIPTS processor in order to start SCSI commands. |
| 971 | */ |
| 972 | volatile /* Prevent code optimizations */ |
| 973 | u32 *squeue; /* Start queue virtual address */ |
| 974 | u32 squeue_ba; /* Start queue BUS address */ |
| 975 | u_short squeueput; /* Next free slot of the queue */ |
| 976 | u_short actccbs; /* Number of allocated CCBs */ |
| 977 | |
| 978 | /* |
| 979 | * Command completion queue. |
| 980 | * It is the same size as the start queue to avoid overflow. |
| 981 | */ |
| 982 | u_short dqueueget; /* Next position to scan */ |
| 983 | volatile /* Prevent code optimizations */ |
| 984 | u32 *dqueue; /* Completion (done) queue */ |
| 985 | u32 dqueue_ba; /* Done queue BUS address */ |
| 986 | |
| 987 | /* |
| 988 | * Miscellaneous buffers accessed by the scripts-processor. |
| 989 | * They shall be DWORD aligned, because they may be read or |
| 990 | * written with a script command. |
| 991 | */ |
| 992 | u_char msgout[8]; /* Buffer for MESSAGE OUT */ |
| 993 | u_char msgin [8]; /* Buffer for MESSAGE IN */ |
| 994 | u32 lastmsg; /* Last SCSI message sent */ |
| 995 | u32 scratch; /* Scratch for SCSI receive */ |
| 996 | /* Also used for cache test */ |
| 997 | /* |
| 998 | * Miscellaneous configuration and status parameters. |
| 999 | */ |
| 1000 | u_char usrflags; /* Miscellaneous user flags */ |
| 1001 | u_char scsi_mode; /* Current SCSI BUS mode */ |
| 1002 | u_char verbose; /* Verbosity for this controller*/ |
| 1003 | |
| 1004 | /* |
| 1005 | * CCB lists and queue. |
| 1006 | */ |
| 1007 | struct sym_ccb **ccbh; /* CCBs hashed by DSA value */ |
| 1008 | /* CCB_HASH_SIZE lists of CCBs */ |
| 1009 | SYM_QUEHEAD free_ccbq; /* Queue of available CCBs */ |
| 1010 | SYM_QUEHEAD busy_ccbq; /* Queue of busy CCBs */ |
| 1011 | |
| 1012 | /* |
| 1013 | * During error handling and/or recovery, |
| 1014 | * active CCBs that are to be completed with |
| 1015 | * error or requeued are moved from the busy_ccbq |
| 1016 | * to the comp_ccbq prior to completion. |
| 1017 | */ |
| 1018 | SYM_QUEHEAD comp_ccbq; |
| 1019 | |
| 1020 | #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING |
| 1021 | SYM_QUEHEAD dummy_ccbq; |
| 1022 | #endif |
| 1023 | |
| 1024 | /* |
| 1025 | * IMMEDIATE ARBITRATION (IARB) control. |
| 1026 | * |
| 1027 | * We keep track in 'last_cp' of the last CCB that has been |
| 1028 | * queued to the SCRIPTS processor and clear 'last_cp' when |
| 1029 | * this CCB completes. If last_cp is not zero at the moment |
| 1030 | * we queue a new CCB, we set a flag in 'last_cp' that is |
| 1031 | * used by the SCRIPTS as a hint for setting IARB. |
| 1032 | * We donnot set more than 'iarb_max' consecutive hints for |
| 1033 | * IARB in order to leave devices a chance to reselect. |
| 1034 | * By the way, any non zero value of 'iarb_max' is unfair. :) |
| 1035 | */ |
| 1036 | #ifdef SYM_CONF_IARB_SUPPORT |
| 1037 | u_short iarb_max; /* Max. # consecutive IARB hints*/ |
| 1038 | u_short iarb_count; /* Actual # of these hints */ |
| 1039 | struct sym_ccb * last_cp; |
| 1040 | #endif |
| 1041 | |
| 1042 | /* |
| 1043 | * Command abort handling. |
| 1044 | * We need to synchronize tightly with the SCRIPTS |
| 1045 | * processor in order to handle things correctly. |
| 1046 | */ |
| 1047 | u_char abrt_msg[4]; /* Message to send buffer */ |
| 1048 | struct sym_tblmove abrt_tbl; /* Table for the MOV of it */ |
| 1049 | struct sym_tblsel abrt_sel; /* Sync params for selection */ |
| 1050 | u_char istat_sem; /* Tells the chip to stop (SEM) */ |
| 1051 | |
| 1052 | /* |
| 1053 | * 64 bit DMA handling. |
| 1054 | */ |
| 1055 | #if SYM_CONF_DMA_ADDRESSING_MODE != 0 |
| 1056 | u_char use_dac; /* Use PCI DAC cycles */ |
| 1057 | #if SYM_CONF_DMA_ADDRESSING_MODE == 2 |
| 1058 | u_char dmap_dirty; /* Dma segments registers dirty */ |
| 1059 | u32 dmap_bah[SYM_DMAP_SIZE];/* Segment registers map */ |
| 1060 | #endif |
| 1061 | #endif |
| 1062 | }; |
| 1063 | |
| 1064 | #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl)) |
| 1065 | |
| 1066 | |
| 1067 | /* |
| 1068 | * FIRMWARES (sym_fw.c) |
| 1069 | */ |
| 1070 | struct sym_fw * sym_find_firmware(struct sym_chip *chip); |
| 1071 | void sym_fw_bind_script(struct sym_hcb *np, u32 *start, int len); |
| 1072 | |
| 1073 | /* |
| 1074 | * Driver methods called from O/S specific code. |
| 1075 | */ |
| 1076 | char *sym_driver_name(void); |
| 1077 | void sym_print_xerr(struct scsi_cmnd *cmd, int x_status); |
| 1078 | int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int); |
| 1079 | struct sym_chip *sym_lookup_chip_table(u_short device_id, u_char revision); |
| 1080 | void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp); |
| 1081 | #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING |
| 1082 | void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn); |
| 1083 | #endif |
| 1084 | void sym_start_up(struct sym_hcb *np, int reason); |
| 1085 | void sym_interrupt(struct sym_hcb *np); |
| 1086 | int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int task); |
| 1087 | struct sym_ccb *sym_get_ccb(struct sym_hcb *np, struct scsi_cmnd *cmd, u_char tag_order); |
| 1088 | void sym_free_ccb(struct sym_hcb *np, struct sym_ccb *cp); |
| 1089 | struct sym_lcb *sym_alloc_lcb(struct sym_hcb *np, u_char tn, u_char ln); |
| 1090 | int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp); |
| 1091 | int sym_abort_scsiio(struct sym_hcb *np, struct scsi_cmnd *ccb, int timed_out); |
| 1092 | int sym_reset_scsi_target(struct sym_hcb *np, int target); |
| 1093 | void sym_hcb_free(struct sym_hcb *np); |
| 1094 | int sym_hcb_attach(struct Scsi_Host *shost, struct sym_fw *fw, struct sym_nvram *nvram); |
| 1095 | |
| 1096 | /* |
| 1097 | * Build a scatter/gather entry. |
| 1098 | * |
| 1099 | * For 64 bit systems, we use the 8 upper bits of the size field |
| 1100 | * to provide bus address bits 32-39 to the SCRIPTS processor. |
| 1101 | * This allows the 895A, 896, 1010 to address up to 1 TB of memory. |
| 1102 | */ |
| 1103 | |
| 1104 | #if SYM_CONF_DMA_ADDRESSING_MODE == 0 |
| 1105 | #define sym_build_sge(np, data, badd, len) \ |
| 1106 | do { \ |
| 1107 | (data)->addr = cpu_to_scr(badd); \ |
| 1108 | (data)->size = cpu_to_scr(len); \ |
| 1109 | } while (0) |
| 1110 | #elif SYM_CONF_DMA_ADDRESSING_MODE == 1 |
| 1111 | #define sym_build_sge(np, data, badd, len) \ |
| 1112 | do { \ |
| 1113 | (data)->addr = cpu_to_scr(badd); \ |
| 1114 | (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len); \ |
| 1115 | } while (0) |
| 1116 | #elif SYM_CONF_DMA_ADDRESSING_MODE == 2 |
| 1117 | int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s); |
| 1118 | static __inline void |
| 1119 | sym_build_sge(struct sym_hcb *np, struct sym_tblmove *data, u64 badd, int len) |
| 1120 | { |
| 1121 | u32 h = (badd>>32); |
| 1122 | int s = (h&SYM_DMAP_MASK); |
| 1123 | |
| 1124 | if (h != np->dmap_bah[s]) |
| 1125 | goto bad; |
| 1126 | good: |
| 1127 | (data)->addr = cpu_to_scr(badd); |
| 1128 | (data)->size = cpu_to_scr((s<<24) + len); |
| 1129 | return; |
| 1130 | bad: |
| 1131 | s = sym_lookup_dmap(np, h, s); |
| 1132 | goto good; |
| 1133 | } |
| 1134 | #else |
| 1135 | #error "Unsupported DMA addressing mode" |
| 1136 | #endif |
| 1137 | |
| 1138 | /* |
| 1139 | * Set up data pointers used by SCRIPTS. |
| 1140 | * Called from O/S specific code. |
| 1141 | */ |
| 1142 | static inline void sym_setup_data_pointers(struct sym_hcb *np, |
| 1143 | struct sym_ccb *cp, int dir) |
| 1144 | { |
| 1145 | u32 lastp, goalp; |
| 1146 | |
| 1147 | /* |
| 1148 | * No segments means no data. |
| 1149 | */ |
| 1150 | if (!cp->segments) |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1151 | dir = DMA_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | |
| 1153 | /* |
| 1154 | * Set the data pointer. |
| 1155 | */ |
| 1156 | switch(dir) { |
| 1157 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1158 | case DMA_BIDIRECTIONAL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | #endif |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1160 | case DMA_TO_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | goalp = SCRIPTA_BA(np, data_out2) + 8; |
| 1162 | lastp = goalp - 8 - (cp->segments * (2*4)); |
| 1163 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
| 1164 | cp->wgoalp = cpu_to_scr(goalp); |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1165 | if (dir != DMA_BIDIRECTIONAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | break; |
| 1167 | cp->phys.head.wlastp = cpu_to_scr(lastp); |
| 1168 | /* fall through */ |
| 1169 | #else |
| 1170 | break; |
| 1171 | #endif |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1172 | case DMA_FROM_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | cp->host_flags |= HF_DATA_IN; |
| 1174 | goalp = SCRIPTA_BA(np, data_in2) + 8; |
| 1175 | lastp = goalp - 8 - (cp->segments * (2*4)); |
| 1176 | break; |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1177 | case DMA_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | default: |
| 1179 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
| 1180 | cp->host_flags |= HF_DATA_IN; |
| 1181 | #endif |
| 1182 | lastp = goalp = SCRIPTB_BA(np, no_data); |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | /* |
| 1187 | * Set all pointers values needed by SCRIPTS. |
| 1188 | */ |
| 1189 | cp->phys.head.lastp = cpu_to_scr(lastp); |
| 1190 | cp->phys.head.savep = cpu_to_scr(lastp); |
| 1191 | cp->startp = cp->phys.head.savep; |
| 1192 | cp->goalp = cpu_to_scr(goalp); |
| 1193 | |
| 1194 | #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN |
| 1195 | /* |
| 1196 | * If direction is unknown, start at data_io. |
| 1197 | */ |
Matthew Wilcox | 53222b9 | 2005-05-20 19:15:43 +0100 | [diff] [blame] | 1198 | if (dir == DMA_BIDIRECTIONAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | cp->phys.head.savep = cpu_to_scr(SCRIPTB_BA(np, data_io)); |
| 1200 | #endif |
| 1201 | } |
| 1202 | |
| 1203 | /* |
| 1204 | * MEMORY ALLOCATOR. |
| 1205 | */ |
| 1206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | #define sym_get_mem_cluster() \ |
| 1208 | (void *) __get_free_pages(GFP_ATOMIC, SYM_MEM_PAGE_ORDER) |
| 1209 | #define sym_free_mem_cluster(p) \ |
| 1210 | free_pages((unsigned long)p, SYM_MEM_PAGE_ORDER) |
| 1211 | |
| 1212 | /* |
| 1213 | * Link between free memory chunks of a given size. |
| 1214 | */ |
| 1215 | typedef struct sym_m_link { |
| 1216 | struct sym_m_link *next; |
| 1217 | } *m_link_p; |
| 1218 | |
| 1219 | /* |
| 1220 | * Virtual to bus physical translation for a given cluster. |
| 1221 | * Such a structure is only useful with DMA abstraction. |
| 1222 | */ |
| 1223 | typedef struct sym_m_vtob { /* Virtual to Bus address translation */ |
| 1224 | struct sym_m_vtob *next; |
| 1225 | void *vaddr; /* Virtual address */ |
| 1226 | dma_addr_t baddr; /* Bus physical address */ |
| 1227 | } *m_vtob_p; |
| 1228 | |
| 1229 | /* Hash this stuff a bit to speed up translations */ |
| 1230 | #define VTOB_HASH_SHIFT 5 |
| 1231 | #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT) |
| 1232 | #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1) |
| 1233 | #define VTOB_HASH_CODE(m) \ |
| 1234 | ((((unsigned long)(m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK) |
| 1235 | |
| 1236 | /* |
| 1237 | * Memory pool of a given kind. |
| 1238 | * Ideally, we want to use: |
| 1239 | * 1) 1 pool for memory we donnot need to involve in DMA. |
| 1240 | * 2) The same pool for controllers that require same DMA |
| 1241 | * constraints and features. |
| 1242 | * The OS specific m_pool_id_t thing and the sym_m_pool_match() |
| 1243 | * method are expected to tell the driver about. |
| 1244 | */ |
| 1245 | typedef struct sym_m_pool { |
| 1246 | m_pool_ident_t dev_dmat; /* Identifies the pool (see above) */ |
| 1247 | void * (*get_mem_cluster)(struct sym_m_pool *); |
| 1248 | #ifdef SYM_MEM_FREE_UNUSED |
| 1249 | void (*free_mem_cluster)(struct sym_m_pool *, void *); |
| 1250 | #endif |
| 1251 | #define M_GET_MEM_CLUSTER() mp->get_mem_cluster(mp) |
| 1252 | #define M_FREE_MEM_CLUSTER(p) mp->free_mem_cluster(mp, p) |
| 1253 | int nump; |
| 1254 | m_vtob_p vtob[VTOB_HASH_SIZE]; |
| 1255 | struct sym_m_pool *next; |
| 1256 | struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1]; |
| 1257 | } *m_pool_p; |
| 1258 | |
| 1259 | /* |
| 1260 | * Alloc, free and translate addresses to bus physical |
| 1261 | * for DMAable memory. |
| 1262 | */ |
| 1263 | void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name); |
| 1264 | void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name); |
| 1265 | dma_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m); |
| 1266 | |
| 1267 | /* |
| 1268 | * Verbs used by the driver code for DMAable memory handling. |
| 1269 | * The _uvptv_ macro avoids a nasty warning about pointer to volatile |
| 1270 | * being discarded. |
| 1271 | */ |
| 1272 | #define _uvptv_(p) ((void *)((u_long)(p))) |
| 1273 | |
| 1274 | #define _sym_calloc_dma(np, l, n) __sym_calloc_dma(np->bus_dmat, l, n) |
| 1275 | #define _sym_mfree_dma(np, p, l, n) \ |
| 1276 | __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n) |
| 1277 | #define sym_calloc_dma(l, n) _sym_calloc_dma(np, l, n) |
| 1278 | #define sym_mfree_dma(p, l, n) _sym_mfree_dma(np, p, l, n) |
| 1279 | #define vtobus(p) __vtobus(np->bus_dmat, _uvptv_(p)) |
| 1280 | |
| 1281 | /* |
| 1282 | * We have to provide the driver memory allocator with methods for |
| 1283 | * it to maintain virtual to bus physical address translations. |
| 1284 | */ |
| 1285 | |
| 1286 | #define sym_m_pool_match(mp_id1, mp_id2) (mp_id1 == mp_id2) |
| 1287 | |
| 1288 | static __inline void *sym_m_get_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp) |
| 1289 | { |
| 1290 | void *vaddr = NULL; |
| 1291 | dma_addr_t baddr = 0; |
| 1292 | |
| 1293 | vaddr = dma_alloc_coherent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE, &baddr, |
| 1294 | GFP_ATOMIC); |
| 1295 | if (vaddr) { |
| 1296 | vbp->vaddr = vaddr; |
| 1297 | vbp->baddr = baddr; |
| 1298 | } |
| 1299 | return vaddr; |
| 1300 | } |
| 1301 | |
| 1302 | static __inline void sym_m_free_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp) |
| 1303 | { |
| 1304 | dma_free_coherent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE, vbp->vaddr, |
| 1305 | vbp->baddr); |
| 1306 | } |
| 1307 | |
| 1308 | #endif /* SYM_HIPD_H */ |