sym_hipd.h 33 KB

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