sym_hipd.h 33 KB

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