sym_hipd.h 35 KB

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