sym_hipd.h 35 KB

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