sym_hipd.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  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 reasonable 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. unsigned int renego:2;
  319. };
  320. /*
  321. * Global TCB HEADER.
  322. *
  323. * Due to lack of indirect addressing on earlier NCR chips,
  324. * this substructure is copied from the TCB to a global
  325. * address after selection.
  326. * For SYMBIOS chips that support LOAD/STORE this copy is
  327. * not needed and thus not performed.
  328. */
  329. struct sym_tcbh {
  330. /*
  331. * Scripts bus addresses of LUN table accessed from scripts.
  332. * LUN #0 is a special case, since multi-lun devices are rare,
  333. * and we we want to speed-up the general case and not waste
  334. * resources.
  335. */
  336. u32 luntbl_sa; /* bus address of this table */
  337. u32 lun0_sa; /* bus address of LCB #0 */
  338. /*
  339. * Actual SYNC/WIDE IO registers value for this target.
  340. * 'sval', 'wval' and 'uval' are read from SCRIPTS and
  341. * so have alignment constraints.
  342. */
  343. /*0*/ u_char uval; /* -> SCNTL4 register */
  344. /*1*/ u_char sval; /* -> SXFER io register */
  345. /*2*/ u_char filler1;
  346. /*3*/ u_char wval; /* -> SCNTL3 io register */
  347. };
  348. /*
  349. * Target Control Block
  350. */
  351. struct sym_tcb {
  352. /*
  353. * TCB header.
  354. * Assumed at offset 0.
  355. */
  356. /*0*/ struct sym_tcbh head;
  357. /*
  358. * LUN table used by the SCRIPTS processor.
  359. * An array of bus addresses is used on reselection.
  360. */
  361. u32 *luntbl; /* LCBs bus address table */
  362. int nlcb; /* Number of valid LCBs (including LUN #0) */
  363. /*
  364. * LUN table used by the C code.
  365. */
  366. struct sym_lcb *lun0p; /* LCB of LUN #0 (usual case) */
  367. #if SYM_CONF_MAX_LUN > 1
  368. struct sym_lcb **lunmp; /* Other LCBs [1..MAX_LUN] */
  369. #endif
  370. #ifdef SYM_HAVE_STCB
  371. /*
  372. * O/S specific data structure.
  373. */
  374. struct sym_stcb s;
  375. #endif
  376. /* Transfer goal */
  377. struct sym_trans tgoal;
  378. /* Last printed transfer speed */
  379. struct sym_trans tprint;
  380. /*
  381. * Keep track of the CCB used for the negotiation in order
  382. * to ensure that only 1 negotiation is queued at a time.
  383. */
  384. struct sym_ccb * nego_cp; /* CCB used for the nego */
  385. /*
  386. * Set when we want to reset the device.
  387. */
  388. u_char to_reset;
  389. /*
  390. * Other user settable limits and options.
  391. * These limits are read from the NVRAM if present.
  392. */
  393. unsigned char usrflags;
  394. unsigned char usr_period;
  395. unsigned char usr_width;
  396. unsigned short usrtags;
  397. struct scsi_target *starget;
  398. };
  399. /*
  400. * Global LCB HEADER.
  401. *
  402. * Due to lack of indirect addressing on earlier NCR chips,
  403. * this substructure is copied from the LCB to a global
  404. * address after selection.
  405. * For SYMBIOS chips that support LOAD/STORE this copy is
  406. * not needed and thus not performed.
  407. */
  408. struct sym_lcbh {
  409. /*
  410. * SCRIPTS address jumped by SCRIPTS on reselection.
  411. * For not probed logical units, this address points to
  412. * SCRIPTS that deal with bad LU handling (must be at
  413. * offset zero of the LCB for that reason).
  414. */
  415. /*0*/ u32 resel_sa;
  416. /*
  417. * Task (bus address of a CCB) read from SCRIPTS that points
  418. * to the unique ITL nexus allowed to be disconnected.
  419. */
  420. u32 itl_task_sa;
  421. /*
  422. * Task table bus address (read from SCRIPTS).
  423. */
  424. u32 itlq_tbl_sa;
  425. };
  426. /*
  427. * Logical Unit Control Block
  428. */
  429. struct sym_lcb {
  430. /*
  431. * TCB header.
  432. * Assumed at offset 0.
  433. */
  434. /*0*/ struct sym_lcbh head;
  435. /*
  436. * Task table read from SCRIPTS that contains pointers to
  437. * ITLQ nexuses. The bus address read from SCRIPTS is
  438. * inside the header.
  439. */
  440. u32 *itlq_tbl; /* Kernel virtual address */
  441. /*
  442. * Busy CCBs management.
  443. */
  444. u_short busy_itlq; /* Number of busy tagged CCBs */
  445. u_short busy_itl; /* Number of busy untagged CCBs */
  446. /*
  447. * Circular tag allocation buffer.
  448. */
  449. u_short ia_tag; /* Tag allocation index */
  450. u_short if_tag; /* Tag release index */
  451. u_char *cb_tags; /* Circular tags buffer */
  452. /*
  453. * O/S specific data structure.
  454. */
  455. #ifdef SYM_HAVE_SLCB
  456. struct sym_slcb s;
  457. #endif
  458. #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
  459. /*
  460. * Optionnaly the driver can handle device queueing,
  461. * and requeues internally command to redo.
  462. */
  463. SYM_QUEHEAD waiting_ccbq;
  464. SYM_QUEHEAD started_ccbq;
  465. int num_sgood;
  466. u_short started_tags;
  467. u_short started_no_tag;
  468. u_short started_max;
  469. u_short started_limit;
  470. #endif
  471. #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
  472. /*
  473. * Optionally the driver can try to prevent SCSI
  474. * IOs from being reordered too much.
  475. */
  476. u_char tags_si; /* Current index to tags sum */
  477. u_short tags_sum[2]; /* Tags sum counters */
  478. u_short tags_since; /* # of tags since last switch */
  479. #endif
  480. /*
  481. * Set when we want to clear all tasks.
  482. */
  483. u_char to_clear;
  484. /*
  485. * Capabilities.
  486. */
  487. u_char user_flags;
  488. u_char curr_flags;
  489. };
  490. /*
  491. * Action from SCRIPTS on a task.
  492. * Is part of the CCB, but is also used separately to plug
  493. * error handling action to perform from SCRIPTS.
  494. */
  495. struct sym_actscr {
  496. u32 start; /* Jumped by SCRIPTS after selection */
  497. u32 restart; /* Jumped by SCRIPTS on relection */
  498. };
  499. /*
  500. * Phase mismatch context.
  501. *
  502. * It is part of the CCB and is used as parameters for the
  503. * DATA pointer. We need two contexts to handle correctly the
  504. * SAVED DATA POINTER.
  505. */
  506. struct sym_pmc {
  507. struct sym_tblmove sg; /* Updated interrupted SG block */
  508. u32 ret; /* SCRIPT return address */
  509. };
  510. /*
  511. * LUN control block lookup.
  512. * We use a direct pointer for LUN #0, and a table of
  513. * pointers which is only allocated for devices that support
  514. * LUN(s) > 0.
  515. */
  516. #if SYM_CONF_MAX_LUN <= 1
  517. #define sym_lp(tp, lun) (!lun) ? (tp)->lun0p : NULL
  518. #else
  519. #define sym_lp(tp, lun) \
  520. (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[((u8)lun)] : NULL
  521. #endif
  522. /*
  523. * Status are used by the host and the script processor.
  524. *
  525. * The last four bytes (status[4]) are copied to the
  526. * scratchb register (declared as scr0..scr3) just after the
  527. * select/reselect, and copied back just after disconnecting.
  528. * Inside the script the XX_REG are used.
  529. */
  530. /*
  531. * Last four bytes (script)
  532. */
  533. #define HX_REG scr0
  534. #define HX_PRT nc_scr0
  535. #define HS_REG scr1
  536. #define HS_PRT nc_scr1
  537. #define SS_REG scr2
  538. #define SS_PRT nc_scr2
  539. #define HF_REG scr3
  540. #define HF_PRT nc_scr3
  541. /*
  542. * Last four bytes (host)
  543. */
  544. #define host_xflags phys.head.status[0]
  545. #define host_status phys.head.status[1]
  546. #define ssss_status phys.head.status[2]
  547. #define host_flags phys.head.status[3]
  548. /*
  549. * Host flags
  550. */
  551. #define HF_IN_PM0 1u
  552. #define HF_IN_PM1 (1u<<1)
  553. #define HF_ACT_PM (1u<<2)
  554. #define HF_DP_SAVED (1u<<3)
  555. #define HF_SENSE (1u<<4)
  556. #define HF_EXT_ERR (1u<<5)
  557. #define HF_DATA_IN (1u<<6)
  558. #ifdef SYM_CONF_IARB_SUPPORT
  559. #define HF_HINT_IARB (1u<<7)
  560. #endif
  561. /*
  562. * More host flags
  563. */
  564. #if SYM_CONF_DMA_ADDRESSING_MODE == 2
  565. #define HX_DMAP_DIRTY (1u<<7)
  566. #endif
  567. /*
  568. * Global CCB HEADER.
  569. *
  570. * Due to lack of indirect addressing on earlier NCR chips,
  571. * this substructure is copied from the ccb to a global
  572. * address after selection (or reselection) and copied back
  573. * before disconnect.
  574. * For SYMBIOS chips that support LOAD/STORE this copy is
  575. * not needed and thus not performed.
  576. */
  577. struct sym_ccbh {
  578. /*
  579. * Start and restart SCRIPTS addresses (must be at 0).
  580. */
  581. /*0*/ struct sym_actscr go;
  582. /*
  583. * SCRIPTS jump address that deal with data pointers.
  584. * 'savep' points to the position in the script responsible
  585. * for the actual transfer of data.
  586. * It's written on reception of a SAVE_DATA_POINTER message.
  587. */
  588. u32 savep; /* Jump address to saved data pointer */
  589. u32 lastp; /* SCRIPTS address at end of data */
  590. /*
  591. * Status fields.
  592. */
  593. u8 status[4];
  594. };
  595. /*
  596. * GET/SET the value of the data pointer used by SCRIPTS.
  597. *
  598. * We must distinguish between the LOAD/STORE-based SCRIPTS
  599. * that use directly the header in the CCB, and the NCR-GENERIC
  600. * SCRIPTS that use the copy of the header in the HCB.
  601. */
  602. #if SYM_CONF_GENERIC_SUPPORT
  603. #define sym_set_script_dp(np, cp, dp) \
  604. do { \
  605. if (np->features & FE_LDSTR) \
  606. cp->phys.head.lastp = cpu_to_scr(dp); \
  607. else \
  608. np->ccb_head.lastp = cpu_to_scr(dp); \
  609. } while (0)
  610. #define sym_get_script_dp(np, cp) \
  611. scr_to_cpu((np->features & FE_LDSTR) ? \
  612. cp->phys.head.lastp : np->ccb_head.lastp)
  613. #else
  614. #define sym_set_script_dp(np, cp, dp) \
  615. do { \
  616. cp->phys.head.lastp = cpu_to_scr(dp); \
  617. } while (0)
  618. #define sym_get_script_dp(np, cp) (cp->phys.head.lastp)
  619. #endif
  620. /*
  621. * Data Structure Block
  622. *
  623. * During execution of a ccb by the script processor, the
  624. * DSA (data structure address) register points to this
  625. * substructure of the ccb.
  626. */
  627. struct sym_dsb {
  628. /*
  629. * CCB header.
  630. * Also assumed at offset 0 of the sym_ccb structure.
  631. */
  632. /*0*/ struct sym_ccbh head;
  633. /*
  634. * Phase mismatch contexts.
  635. * We need two to handle correctly the SAVED DATA POINTER.
  636. * MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic
  637. * for address calculation from SCRIPTS.
  638. */
  639. struct sym_pmc pm0;
  640. struct sym_pmc pm1;
  641. /*
  642. * Table data for Script
  643. */
  644. struct sym_tblsel select;
  645. struct sym_tblmove smsg;
  646. struct sym_tblmove smsg_ext;
  647. struct sym_tblmove cmd;
  648. struct sym_tblmove sense;
  649. struct sym_tblmove wresid;
  650. struct sym_tblmove data [SYM_CONF_MAX_SG];
  651. };
  652. /*
  653. * Our Command Control Block
  654. */
  655. struct sym_ccb {
  656. /*
  657. * This is the data structure which is pointed by the DSA
  658. * register when it is executed by the script processor.
  659. * It must be the first entry.
  660. */
  661. struct sym_dsb phys;
  662. /*
  663. * Pointer to CAM ccb and related stuff.
  664. */
  665. struct scsi_cmnd *cmd; /* CAM scsiio ccb */
  666. u8 cdb_buf[16]; /* Copy of CDB */
  667. #define SYM_SNS_BBUF_LEN 32
  668. u8 sns_bbuf[SYM_SNS_BBUF_LEN]; /* Bounce buffer for sense data */
  669. int data_len; /* Total data length */
  670. int segments; /* Number of SG segments */
  671. u8 order; /* Tag type (if tagged command) */
  672. unsigned char odd_byte_adjustment; /* odd-sized req on wide bus */
  673. u_char nego_status; /* Negotiation status */
  674. u_char xerr_status; /* Extended error flags */
  675. u32 extra_bytes; /* Extraneous bytes transferred */
  676. /*
  677. * Message areas.
  678. * We prepare a message to be sent after selection.
  679. * We may use a second one if the command is rescheduled
  680. * due to CHECK_CONDITION or COMMAND TERMINATED.
  681. * Contents are IDENTIFY and SIMPLE_TAG.
  682. * While negotiating sync or wide transfer,
  683. * a SDTR or WDTR message is appended.
  684. */
  685. u_char scsi_smsg [12];
  686. u_char scsi_smsg2[12];
  687. /*
  688. * Auto request sense related fields.
  689. */
  690. u_char sensecmd[6]; /* Request Sense command */
  691. u_char sv_scsi_status; /* Saved SCSI status */
  692. u_char sv_xerr_status; /* Saved extended status */
  693. int sv_resid; /* Saved residual */
  694. /*
  695. * Other fields.
  696. */
  697. u32 ccb_ba; /* BUS address of this CCB */
  698. u_short tag; /* Tag for this transfer */
  699. /* NO_TAG means no tag */
  700. u_char target;
  701. u_char lun;
  702. struct sym_ccb *link_ccbh; /* Host adapter CCB hash chain */
  703. SYM_QUEHEAD link_ccbq; /* Link to free/busy CCB queue */
  704. u32 startp; /* Initial data pointer */
  705. u32 goalp; /* Expected last data pointer */
  706. int ext_sg; /* Extreme data pointer, used */
  707. int ext_ofs; /* to calculate the residual. */
  708. #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
  709. SYM_QUEHEAD link2_ccbq; /* Link for device queueing */
  710. u_char started; /* CCB queued to the squeue */
  711. #endif
  712. u_char to_abort; /* Want this IO to be aborted */
  713. #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
  714. u_char tags_si; /* Lun tags sum index (0,1) */
  715. #endif
  716. };
  717. #define CCB_BA(cp,lbl) cpu_to_scr(cp->ccb_ba + offsetof(struct sym_ccb, lbl))
  718. typedef struct device *m_pool_ident_t;
  719. /*
  720. * Host Control Block
  721. */
  722. struct sym_hcb {
  723. /*
  724. * Global headers.
  725. * Due to poorness of addressing capabilities, earlier
  726. * chips (810, 815, 825) copy part of the data structures
  727. * (CCB, TCB and LCB) in fixed areas.
  728. */
  729. #if SYM_CONF_GENERIC_SUPPORT
  730. struct sym_ccbh ccb_head;
  731. struct sym_tcbh tcb_head;
  732. struct sym_lcbh lcb_head;
  733. #endif
  734. /*
  735. * Idle task and invalid task actions and
  736. * their bus addresses.
  737. */
  738. struct sym_actscr idletask, notask, bad_itl, bad_itlq;
  739. u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba;
  740. /*
  741. * Dummy lun table to protect us against target
  742. * returning bad lun number on reselection.
  743. */
  744. u32 *badluntbl; /* Table physical address */
  745. u32 badlun_sa; /* SCRIPT handler BUS address */
  746. /*
  747. * Bus address of this host control block.
  748. */
  749. u32 hcb_ba;
  750. /*
  751. * Bit 32-63 of the on-chip RAM bus address in LE format.
  752. * The START_RAM64 script loads the MMRS and MMWS from this
  753. * field.
  754. */
  755. u32 scr_ram_seg;
  756. /*
  757. * Initial value of some IO register bits.
  758. * These values are assumed to have been set by BIOS, and may
  759. * be used to probe adapter implementation differences.
  760. */
  761. u_char sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
  762. sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4,
  763. sv_stest1;
  764. /*
  765. * Actual initial value of IO register bits used by the
  766. * driver. They are loaded at initialisation according to
  767. * features that are to be enabled/disabled.
  768. */
  769. u_char rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4,
  770. rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4;
  771. /*
  772. * Target data.
  773. */
  774. struct sym_tcb target[SYM_CONF_MAX_TARGET];
  775. /*
  776. * Target control block bus address array used by the SCRIPT
  777. * on reselection.
  778. */
  779. u32 *targtbl;
  780. u32 targtbl_ba;
  781. /*
  782. * DMA pool handle for this HBA.
  783. */
  784. m_pool_ident_t bus_dmat;
  785. /*
  786. * O/S specific data structure
  787. */
  788. struct sym_shcb s;
  789. /*
  790. * Physical bus addresses of the chip.
  791. */
  792. u32 mmio_ba; /* MMIO 32 bit BUS address */
  793. u32 ram_ba; /* RAM 32 bit BUS address */
  794. /*
  795. * SCRIPTS virtual and physical bus addresses.
  796. * 'script' is loaded in the on-chip RAM if present.
  797. * 'scripth' stays in main memory for all chips except the
  798. * 53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM.
  799. */
  800. u_char *scripta0; /* Copy of scripts A, B, Z */
  801. u_char *scriptb0;
  802. u_char *scriptz0;
  803. u32 scripta_ba; /* Actual scripts A, B, Z */
  804. u32 scriptb_ba; /* 32 bit bus addresses. */
  805. u32 scriptz_ba;
  806. u_short scripta_sz; /* Actual size of script A, B, Z*/
  807. u_short scriptb_sz;
  808. u_short scriptz_sz;
  809. /*
  810. * Bus addresses, setup and patch methods for
  811. * the selected firmware.
  812. */
  813. struct sym_fwa_ba fwa_bas; /* Useful SCRIPTA bus addresses */
  814. struct sym_fwb_ba fwb_bas; /* Useful SCRIPTB bus addresses */
  815. struct sym_fwz_ba fwz_bas; /* Useful SCRIPTZ bus addresses */
  816. void (*fw_setup)(struct sym_hcb *np, struct sym_fw *fw);
  817. void (*fw_patch)(struct Scsi_Host *);
  818. char *fw_name;
  819. /*
  820. * General controller parameters and configuration.
  821. */
  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. #if SYM_CONF_DMA_ADDRESSING_MODE == 0
  925. #define use_dac(np) 0
  926. #define set_dac(np) do { } while (0)
  927. #else
  928. #define use_dac(np) (np)->use_dac
  929. #define set_dac(np) (np)->use_dac = 1
  930. #endif
  931. #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl))
  932. /*
  933. * FIRMWARES (sym_fw.c)
  934. */
  935. struct sym_fw * sym_find_firmware(struct sym_chip *chip);
  936. void sym_fw_bind_script(struct sym_hcb *np, u32 *start, int len);
  937. /*
  938. * Driver methods called from O/S specific code.
  939. */
  940. char *sym_driver_name(void);
  941. void sym_print_xerr(struct scsi_cmnd *cmd, int x_status);
  942. int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int);
  943. struct sym_chip *sym_lookup_chip_table(u_short device_id, u_char revision);
  944. #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
  945. void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn);
  946. #else
  947. void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp);
  948. #endif
  949. void sym_start_up(struct Scsi_Host *, int reason);
  950. irqreturn_t sym_interrupt(struct Scsi_Host *);
  951. int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int task);
  952. struct sym_ccb *sym_get_ccb(struct sym_hcb *np, struct scsi_cmnd *cmd, u_char tag_order);
  953. void sym_free_ccb(struct sym_hcb *np, struct sym_ccb *cp);
  954. struct sym_lcb *sym_alloc_lcb(struct sym_hcb *np, u_char tn, u_char ln);
  955. int sym_free_lcb(struct sym_hcb *np, u_char tn, u_char ln);
  956. int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
  957. int sym_abort_scsiio(struct sym_hcb *np, struct scsi_cmnd *ccb, int timed_out);
  958. int sym_reset_scsi_target(struct sym_hcb *np, int target);
  959. void sym_hcb_free(struct sym_hcb *np);
  960. int sym_hcb_attach(struct Scsi_Host *shost, struct sym_fw *fw, struct sym_nvram *nvram);
  961. /*
  962. * Build a scatter/gather entry.
  963. *
  964. * For 64 bit systems, we use the 8 upper bits of the size field
  965. * to provide bus address bits 32-39 to the SCRIPTS processor.
  966. * This allows the 895A, 896, 1010 to address up to 1 TB of memory.
  967. */
  968. #if SYM_CONF_DMA_ADDRESSING_MODE == 0
  969. #define DMA_DAC_MASK DMA_BIT_MASK(32)
  970. #define sym_build_sge(np, data, badd, len) \
  971. do { \
  972. (data)->addr = cpu_to_scr(badd); \
  973. (data)->size = cpu_to_scr(len); \
  974. } while (0)
  975. #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
  976. #define DMA_DAC_MASK DMA_BIT_MASK(40)
  977. #define sym_build_sge(np, data, badd, len) \
  978. do { \
  979. (data)->addr = cpu_to_scr(badd); \
  980. (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len); \
  981. } while (0)
  982. #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
  983. #define DMA_DAC_MASK DMA_BIT_MASK(64)
  984. int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s);
  985. static inline void
  986. sym_build_sge(struct sym_hcb *np, struct sym_tblmove *data, u64 badd, int len)
  987. {
  988. u32 h = (badd>>32);
  989. int s = (h&SYM_DMAP_MASK);
  990. if (h != np->dmap_bah[s])
  991. goto bad;
  992. good:
  993. (data)->addr = cpu_to_scr(badd);
  994. (data)->size = cpu_to_scr((s<<24) + len);
  995. return;
  996. bad:
  997. s = sym_lookup_dmap(np, h, s);
  998. goto good;
  999. }
  1000. #else
  1001. #error "Unsupported DMA addressing mode"
  1002. #endif
  1003. /*
  1004. * MEMORY ALLOCATOR.
  1005. */
  1006. #define sym_get_mem_cluster() \
  1007. (void *) __get_free_pages(GFP_ATOMIC, SYM_MEM_PAGE_ORDER)
  1008. #define sym_free_mem_cluster(p) \
  1009. free_pages((unsigned long)p, SYM_MEM_PAGE_ORDER)
  1010. /*
  1011. * Link between free memory chunks of a given size.
  1012. */
  1013. typedef struct sym_m_link {
  1014. struct sym_m_link *next;
  1015. } *m_link_p;
  1016. /*
  1017. * Virtual to bus physical translation for a given cluster.
  1018. * Such a structure is only useful with DMA abstraction.
  1019. */
  1020. typedef struct sym_m_vtob { /* Virtual to Bus address translation */
  1021. struct sym_m_vtob *next;
  1022. void *vaddr; /* Virtual address */
  1023. dma_addr_t baddr; /* Bus physical address */
  1024. } *m_vtob_p;
  1025. /* Hash this stuff a bit to speed up translations */
  1026. #define VTOB_HASH_SHIFT 5
  1027. #define VTOB_HASH_SIZE (1UL << VTOB_HASH_SHIFT)
  1028. #define VTOB_HASH_MASK (VTOB_HASH_SIZE-1)
  1029. #define VTOB_HASH_CODE(m) \
  1030. ((((unsigned long)(m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK)
  1031. /*
  1032. * Memory pool of a given kind.
  1033. * Ideally, we want to use:
  1034. * 1) 1 pool for memory we donnot need to involve in DMA.
  1035. * 2) The same pool for controllers that require same DMA
  1036. * constraints and features.
  1037. * The OS specific m_pool_id_t thing and the sym_m_pool_match()
  1038. * method are expected to tell the driver about.
  1039. */
  1040. typedef struct sym_m_pool {
  1041. m_pool_ident_t dev_dmat; /* Identifies the pool (see above) */
  1042. void * (*get_mem_cluster)(struct sym_m_pool *);
  1043. #ifdef SYM_MEM_FREE_UNUSED
  1044. void (*free_mem_cluster)(struct sym_m_pool *, void *);
  1045. #endif
  1046. #define M_GET_MEM_CLUSTER() mp->get_mem_cluster(mp)
  1047. #define M_FREE_MEM_CLUSTER(p) mp->free_mem_cluster(mp, p)
  1048. int nump;
  1049. m_vtob_p vtob[VTOB_HASH_SIZE];
  1050. struct sym_m_pool *next;
  1051. struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
  1052. } *m_pool_p;
  1053. /*
  1054. * Alloc, free and translate addresses to bus physical
  1055. * for DMAable memory.
  1056. */
  1057. void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name);
  1058. void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name);
  1059. dma_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m);
  1060. /*
  1061. * Verbs used by the driver code for DMAable memory handling.
  1062. * The _uvptv_ macro avoids a nasty warning about pointer to volatile
  1063. * being discarded.
  1064. */
  1065. #define _uvptv_(p) ((void *)((u_long)(p)))
  1066. #define _sym_calloc_dma(np, l, n) __sym_calloc_dma(np->bus_dmat, l, n)
  1067. #define _sym_mfree_dma(np, p, l, n) \
  1068. __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n)
  1069. #define sym_calloc_dma(l, n) _sym_calloc_dma(np, l, n)
  1070. #define sym_mfree_dma(p, l, n) _sym_mfree_dma(np, p, l, n)
  1071. #define vtobus(p) __vtobus(np->bus_dmat, _uvptv_(p))
  1072. /*
  1073. * We have to provide the driver memory allocator with methods for
  1074. * it to maintain virtual to bus physical address translations.
  1075. */
  1076. #define sym_m_pool_match(mp_id1, mp_id2) (mp_id1 == mp_id2)
  1077. static inline void *sym_m_get_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
  1078. {
  1079. void *vaddr = NULL;
  1080. dma_addr_t baddr = 0;
  1081. vaddr = dma_alloc_coherent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE, &baddr,
  1082. GFP_ATOMIC);
  1083. if (vaddr) {
  1084. vbp->vaddr = vaddr;
  1085. vbp->baddr = baddr;
  1086. }
  1087. return vaddr;
  1088. }
  1089. static inline void sym_m_free_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
  1090. {
  1091. dma_free_coherent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE, vbp->vaddr,
  1092. vbp->baddr);
  1093. }
  1094. #endif /* SYM_HIPD_H */