sym_hipd.h 35 KB

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