aic7xxx.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. /*
  2. * Core definitions and data structures shareable across OS platforms.
  3. *
  4. * Copyright (c) 1994-2001 Justin T. Gibbs.
  5. * Copyright (c) 2000-2001 Adaptec Inc.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions, and the following disclaimer,
  13. * without modification.
  14. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  15. * substantially similar to the "NO WARRANTY" disclaimer below
  16. * ("Disclaimer") and any redistribution must be conditioned upon
  17. * including a substantially similar Disclaimer requirement for further
  18. * binary redistribution.
  19. * 3. Neither the names of the above-listed copyright holders nor the names
  20. * of any contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * Alternatively, this software may be distributed under the terms of the
  24. * GNU General Public License ("GPL") version 2 as published by the Free
  25. * Software Foundation.
  26. *
  27. * NO WARRANTY
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  37. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGES.
  39. *
  40. * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#85 $
  41. *
  42. * $FreeBSD$
  43. */
  44. #ifndef _AIC7XXX_H_
  45. #define _AIC7XXX_H_
  46. /* Register Definitions */
  47. #include "aic7xxx_reg.h"
  48. /************************* Forward Declarations *******************************/
  49. struct ahc_platform_data;
  50. struct scb_platform_data;
  51. struct seeprom_descriptor;
  52. /****************************** Useful Macros *********************************/
  53. #ifndef TRUE
  54. #define TRUE 1
  55. #endif
  56. #ifndef FALSE
  57. #define FALSE 0
  58. #endif
  59. #define ALL_CHANNELS '\0'
  60. #define ALL_TARGETS_MASK 0xFFFF
  61. #define INITIATOR_WILDCARD (~0)
  62. #define SCSIID_TARGET(ahc, scsiid) \
  63. (((scsiid) & ((((ahc)->features & AHC_TWIN) != 0) ? TWIN_TID : TID)) \
  64. >> TID_SHIFT)
  65. #define SCSIID_OUR_ID(scsiid) \
  66. ((scsiid) & OID)
  67. #define SCSIID_CHANNEL(ahc, scsiid) \
  68. ((((ahc)->features & AHC_TWIN) != 0) \
  69. ? ((((scsiid) & TWIN_CHNLB) != 0) ? 'B' : 'A') \
  70. : 'A')
  71. #define SCB_IS_SCSIBUS_B(ahc, scb) \
  72. (SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid) == 'B')
  73. #define SCB_GET_OUR_ID(scb) \
  74. SCSIID_OUR_ID((scb)->hscb->scsiid)
  75. #define SCB_GET_TARGET(ahc, scb) \
  76. SCSIID_TARGET((ahc), (scb)->hscb->scsiid)
  77. #define SCB_GET_CHANNEL(ahc, scb) \
  78. SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid)
  79. #define SCB_GET_LUN(scb) \
  80. ((scb)->hscb->lun & LID)
  81. #define SCB_GET_TARGET_OFFSET(ahc, scb) \
  82. (SCB_GET_TARGET(ahc, scb) + (SCB_IS_SCSIBUS_B(ahc, scb) ? 8 : 0))
  83. #define SCB_GET_TARGET_MASK(ahc, scb) \
  84. (0x01 << (SCB_GET_TARGET_OFFSET(ahc, scb)))
  85. #ifdef AHC_DEBUG
  86. #define SCB_IS_SILENT(scb) \
  87. ((ahc_debug & AHC_SHOW_MASKED_ERRORS) == 0 \
  88. && (((scb)->flags & SCB_SILENT) != 0))
  89. #else
  90. #define SCB_IS_SILENT(scb) \
  91. (((scb)->flags & SCB_SILENT) != 0)
  92. #endif
  93. #define TCL_TARGET_OFFSET(tcl) \
  94. ((((tcl) >> 4) & TID) >> 4)
  95. #define TCL_LUN(tcl) \
  96. (tcl & (AHC_NUM_LUNS - 1))
  97. #define BUILD_TCL(scsiid, lun) \
  98. ((lun) | (((scsiid) & TID) << 4))
  99. #ifndef AHC_TARGET_MODE
  100. #undef AHC_TMODE_ENABLE
  101. #define AHC_TMODE_ENABLE 0
  102. #endif
  103. /**************************** Driver Constants ********************************/
  104. /*
  105. * The maximum number of supported targets.
  106. */
  107. #define AHC_NUM_TARGETS 16
  108. /*
  109. * The maximum number of supported luns.
  110. * The identify message only supports 64 luns in SPI3.
  111. * You can have 2^64 luns when information unit transfers are enabled,
  112. * but it is doubtful this driver will ever support IUTs.
  113. */
  114. #define AHC_NUM_LUNS 64
  115. /*
  116. * The maximum transfer per S/G segment.
  117. */
  118. #define AHC_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */
  119. /*
  120. * The maximum amount of SCB storage in hardware on a controller.
  121. * This value represents an upper bound. Controllers vary in the number
  122. * they actually support.
  123. */
  124. #define AHC_SCB_MAX 255
  125. /*
  126. * The maximum number of concurrent transactions supported per driver instance.
  127. * Sequencer Control Blocks (SCBs) store per-transaction information. Although
  128. * the space for SCBs on the host adapter varies by model, the driver will
  129. * page the SCBs between host and controller memory as needed. We are limited
  130. * to 253 because:
  131. * 1) The 8bit nature of the RISC engine holds us to an 8bit value.
  132. * 2) We reserve one value, 255, to represent the invalid element.
  133. * 3) Our input queue scheme requires one SCB to always be reserved
  134. * in advance of queuing any SCBs. This takes us down to 254.
  135. * 4) To handle our output queue correctly on machines that only
  136. * support 32bit stores, we must clear the array 4 bytes at a
  137. * time. To avoid colliding with a DMA write from the sequencer,
  138. * we must be sure that 4 slots are empty when we write to clear
  139. * the queue. This reduces us to 253 SCBs: 1 that just completed
  140. * and the known three additional empty slots in the queue that
  141. * precede it.
  142. */
  143. #define AHC_MAX_QUEUE 253
  144. /*
  145. * The maximum amount of SCB storage we allocate in host memory. This
  146. * number should reflect the 1 additional SCB we require to handle our
  147. * qinfifo mechanism.
  148. */
  149. #define AHC_SCB_MAX_ALLOC (AHC_MAX_QUEUE+1)
  150. /*
  151. * Ring Buffer of incoming target commands.
  152. * We allocate 256 to simplify the logic in the sequencer
  153. * by using the natural wrap point of an 8bit counter.
  154. */
  155. #define AHC_TMODE_CMDS 256
  156. /* Reset line assertion time in us */
  157. #define AHC_BUSRESET_DELAY 25
  158. /******************* Chip Characteristics/Operating Settings *****************/
  159. /*
  160. * Chip Type
  161. * The chip order is from least sophisticated to most sophisticated.
  162. */
  163. typedef enum {
  164. AHC_NONE = 0x0000,
  165. AHC_CHIPID_MASK = 0x00FF,
  166. AHC_AIC7770 = 0x0001,
  167. AHC_AIC7850 = 0x0002,
  168. AHC_AIC7855 = 0x0003,
  169. AHC_AIC7859 = 0x0004,
  170. AHC_AIC7860 = 0x0005,
  171. AHC_AIC7870 = 0x0006,
  172. AHC_AIC7880 = 0x0007,
  173. AHC_AIC7895 = 0x0008,
  174. AHC_AIC7895C = 0x0009,
  175. AHC_AIC7890 = 0x000a,
  176. AHC_AIC7896 = 0x000b,
  177. AHC_AIC7892 = 0x000c,
  178. AHC_AIC7899 = 0x000d,
  179. AHC_VL = 0x0100, /* Bus type VL */
  180. AHC_EISA = 0x0200, /* Bus type EISA */
  181. AHC_PCI = 0x0400, /* Bus type PCI */
  182. AHC_BUS_MASK = 0x0F00
  183. } ahc_chip;
  184. /*
  185. * Features available in each chip type.
  186. */
  187. typedef enum {
  188. AHC_FENONE = 0x00000,
  189. AHC_ULTRA = 0x00001, /* Supports 20MHz Transfers */
  190. AHC_ULTRA2 = 0x00002, /* Supports 40MHz Transfers */
  191. AHC_WIDE = 0x00004, /* Wide Channel */
  192. AHC_TWIN = 0x00008, /* Twin Channel */
  193. AHC_MORE_SRAM = 0x00010, /* 80 bytes instead of 64 */
  194. AHC_CMD_CHAN = 0x00020, /* Has a Command DMA Channel */
  195. AHC_QUEUE_REGS = 0x00040, /* Has Queue management registers */
  196. AHC_SG_PRELOAD = 0x00080, /* Can perform auto-SG preload */
  197. AHC_SPIOCAP = 0x00100, /* Has a Serial Port I/O Cap Register */
  198. AHC_MULTI_TID = 0x00200, /* Has bitmask of TIDs for select-in */
  199. AHC_HS_MAILBOX = 0x00400, /* Has HS_MAILBOX register */
  200. AHC_DT = 0x00800, /* Double Transition transfers */
  201. AHC_NEW_TERMCTL = 0x01000, /* Newer termination scheme */
  202. AHC_MULTI_FUNC = 0x02000, /* Multi-Function Twin Channel Device */
  203. AHC_LARGE_SCBS = 0x04000, /* 64byte SCBs */
  204. AHC_AUTORATE = 0x08000, /* Automatic update of SCSIRATE/OFFSET*/
  205. AHC_AUTOPAUSE = 0x10000, /* Automatic pause on register access */
  206. AHC_TARGETMODE = 0x20000, /* Has tested target mode support */
  207. AHC_MULTIROLE = 0x40000, /* Space for two roles at a time */
  208. AHC_REMOVABLE = 0x80000, /* Hot-Swap supported */
  209. AHC_HVD = 0x100000, /* HVD rather than SE */
  210. AHC_AIC7770_FE = AHC_FENONE,
  211. /*
  212. * The real 7850 does not support Ultra modes, but there are
  213. * several cards that use the generic 7850 PCI ID even though
  214. * they are using an Ultra capable chip (7859/7860). We start
  215. * out with the AHC_ULTRA feature set and then check the DEVSTATUS
  216. * register to determine if the capability is really present.
  217. */
  218. AHC_AIC7850_FE = AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA,
  219. AHC_AIC7860_FE = AHC_AIC7850_FE,
  220. AHC_AIC7870_FE = AHC_TARGETMODE|AHC_AUTOPAUSE,
  221. AHC_AIC7880_FE = AHC_AIC7870_FE|AHC_ULTRA,
  222. /*
  223. * Although we have space for both the initiator and
  224. * target roles on ULTRA2 chips, we currently disable
  225. * the initiator role to allow multi-scsi-id target mode
  226. * configurations. We can only respond on the same SCSI
  227. * ID as our initiator role if we allow initiator operation.
  228. * At some point, we should add a configuration knob to
  229. * allow both roles to be loaded.
  230. */
  231. AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2
  232. |AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_MULTI_TID
  233. |AHC_HS_MAILBOX|AHC_NEW_TERMCTL|AHC_LARGE_SCBS
  234. |AHC_TARGETMODE,
  235. AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_DT|AHC_AUTORATE|AHC_AUTOPAUSE,
  236. AHC_AIC7895_FE = AHC_AIC7880_FE|AHC_MORE_SRAM|AHC_AUTOPAUSE
  237. |AHC_CMD_CHAN|AHC_MULTI_FUNC|AHC_LARGE_SCBS,
  238. AHC_AIC7895C_FE = AHC_AIC7895_FE|AHC_MULTI_TID,
  239. AHC_AIC7896_FE = AHC_AIC7890_FE|AHC_MULTI_FUNC,
  240. AHC_AIC7899_FE = AHC_AIC7892_FE|AHC_MULTI_FUNC
  241. } ahc_feature;
  242. /*
  243. * Bugs in the silicon that we work around in software.
  244. */
  245. typedef enum {
  246. AHC_BUGNONE = 0x00,
  247. /*
  248. * On all chips prior to the U2 product line,
  249. * the WIDEODD S/G segment feature does not
  250. * work during scsi->HostBus transfers.
  251. */
  252. AHC_TMODE_WIDEODD_BUG = 0x01,
  253. /*
  254. * On the aic7890/91 Rev 0 chips, the autoflush
  255. * feature does not work. A manual flush of
  256. * the DMA FIFO is required.
  257. */
  258. AHC_AUTOFLUSH_BUG = 0x02,
  259. /*
  260. * On many chips, cacheline streaming does not work.
  261. */
  262. AHC_CACHETHEN_BUG = 0x04,
  263. /*
  264. * On the aic7896/97 chips, cacheline
  265. * streaming must be enabled.
  266. */
  267. AHC_CACHETHEN_DIS_BUG = 0x08,
  268. /*
  269. * PCI 2.1 Retry failure on non-empty data fifo.
  270. */
  271. AHC_PCI_2_1_RETRY_BUG = 0x10,
  272. /*
  273. * Controller does not handle cacheline residuals
  274. * properly on S/G segments if PCI MWI instructions
  275. * are allowed.
  276. */
  277. AHC_PCI_MWI_BUG = 0x20,
  278. /*
  279. * An SCB upload using the SCB channel's
  280. * auto array entry copy feature may
  281. * corrupt data. This appears to only
  282. * occur on 66MHz systems.
  283. */
  284. AHC_SCBCHAN_UPLOAD_BUG = 0x40
  285. } ahc_bug;
  286. /*
  287. * Configuration specific settings.
  288. * The driver determines these settings by probing the
  289. * chip/controller's configuration.
  290. */
  291. typedef enum {
  292. AHC_FNONE = 0x000,
  293. AHC_PRIMARY_CHANNEL = 0x003, /*
  294. * The channel that should
  295. * be probed first.
  296. */
  297. AHC_USEDEFAULTS = 0x004, /*
  298. * For cards without an seeprom
  299. * or a BIOS to initialize the chip's
  300. * SRAM, we use the default target
  301. * settings.
  302. */
  303. AHC_SEQUENCER_DEBUG = 0x008,
  304. AHC_SHARED_SRAM = 0x010,
  305. AHC_LARGE_SEEPROM = 0x020, /* Uses C56_66 not C46 */
  306. AHC_RESET_BUS_A = 0x040,
  307. AHC_RESET_BUS_B = 0x080,
  308. AHC_EXTENDED_TRANS_A = 0x100,
  309. AHC_EXTENDED_TRANS_B = 0x200,
  310. AHC_TERM_ENB_A = 0x400,
  311. AHC_TERM_ENB_B = 0x800,
  312. AHC_INITIATORROLE = 0x1000, /*
  313. * Allow initiator operations on
  314. * this controller.
  315. */
  316. AHC_TARGETROLE = 0x2000, /*
  317. * Allow target operations on this
  318. * controller.
  319. */
  320. AHC_NEWEEPROM_FMT = 0x4000,
  321. AHC_TQINFIFO_BLOCKED = 0x10000, /* Blocked waiting for ATIOs */
  322. AHC_INT50_SPEEDFLEX = 0x20000, /*
  323. * Internal 50pin connector
  324. * sits behind an aic3860
  325. */
  326. AHC_SCB_BTT = 0x40000, /*
  327. * The busy targets table is
  328. * stored in SCB space rather
  329. * than SRAM.
  330. */
  331. AHC_BIOS_ENABLED = 0x80000,
  332. AHC_ALL_INTERRUPTS = 0x100000,
  333. AHC_PAGESCBS = 0x400000, /* Enable SCB paging */
  334. AHC_EDGE_INTERRUPT = 0x800000, /* Device uses edge triggered ints */
  335. AHC_39BIT_ADDRESSING = 0x1000000, /* Use 39 bit addressing scheme. */
  336. AHC_LSCBS_ENABLED = 0x2000000, /* 64Byte SCBs enabled */
  337. AHC_SCB_CONFIG_USED = 0x4000000, /* No SEEPROM but SCB2 had info. */
  338. AHC_NO_BIOS_INIT = 0x8000000, /* No BIOS left over settings. */
  339. AHC_DISABLE_PCI_PERR = 0x10000000,
  340. AHC_HAS_TERM_LOGIC = 0x20000000
  341. } ahc_flag;
  342. /************************* Hardware SCB Definition ***************************/
  343. /*
  344. * The driver keeps up to MAX_SCB scb structures per card in memory. The SCB
  345. * consists of a "hardware SCB" mirroring the fields available on the card
  346. * and additional information the kernel stores for each transaction.
  347. *
  348. * To minimize space utilization, a portion of the hardware scb stores
  349. * different data during different portions of a SCSI transaction.
  350. * As initialized by the host driver for the initiator role, this area
  351. * contains the SCSI cdb (or a pointer to the cdb) to be executed. After
  352. * the cdb has been presented to the target, this area serves to store
  353. * residual transfer information and the SCSI status byte.
  354. * For the target role, the contents of this area do not change, but
  355. * still serve a different purpose than for the initiator role. See
  356. * struct target_data for details.
  357. */
  358. /*
  359. * Status information embedded in the shared poriton of
  360. * an SCB after passing the cdb to the target. The kernel
  361. * driver will only read this data for transactions that
  362. * complete abnormally (non-zero status byte).
  363. */
  364. struct status_pkt {
  365. uint32_t residual_datacnt; /* Residual in the current S/G seg */
  366. uint32_t residual_sg_ptr; /* The next S/G for this transfer */
  367. uint8_t scsi_status; /* Standard SCSI status byte */
  368. };
  369. /*
  370. * Target mode version of the shared data SCB segment.
  371. */
  372. struct target_data {
  373. uint32_t residual_datacnt; /* Residual in the current S/G seg */
  374. uint32_t residual_sg_ptr; /* The next S/G for this transfer */
  375. uint8_t scsi_status; /* SCSI status to give to initiator */
  376. uint8_t target_phases; /* Bitmap of phases to execute */
  377. uint8_t data_phase; /* Data-In or Data-Out */
  378. uint8_t initiator_tag; /* Initiator's transaction tag */
  379. };
  380. struct hardware_scb {
  381. /*0*/ union {
  382. /*
  383. * If the cdb is 12 bytes or less, we embed it directly
  384. * in the SCB. For longer cdbs, we embed the address
  385. * of the cdb payload as seen by the chip and a DMA
  386. * is used to pull it in.
  387. */
  388. uint8_t cdb[12];
  389. uint32_t cdb_ptr;
  390. struct status_pkt status;
  391. struct target_data tdata;
  392. } shared_data;
  393. /*
  394. * A word about residuals.
  395. * The scb is presented to the sequencer with the dataptr and datacnt
  396. * fields initialized to the contents of the first S/G element to
  397. * transfer. The sgptr field is initialized to the bus address for
  398. * the S/G element that follows the first in the in core S/G array
  399. * or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid
  400. * S/G entry for this transfer (single S/G element transfer with the
  401. * first elements address and length preloaded in the dataptr/datacnt
  402. * fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL.
  403. * The SG_FULL_RESID flag ensures that the residual will be correctly
  404. * noted even if no data transfers occur. Once the data phase is entered,
  405. * the residual sgptr and datacnt are loaded from the sgptr and the
  406. * datacnt fields. After each S/G element's dataptr and length are
  407. * loaded into the hardware, the residual sgptr is advanced. After
  408. * each S/G element is expired, its datacnt field is checked to see
  409. * if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the
  410. * residual sg ptr and the transfer is considered complete. If the
  411. * sequencer determines that there is a residual in the tranfer, it
  412. * will set the SG_RESID_VALID flag in sgptr and dma the scb back into
  413. * host memory. To sumarize:
  414. *
  415. * Sequencer:
  416. * o A residual has occurred if SG_FULL_RESID is set in sgptr,
  417. * or residual_sgptr does not have SG_LIST_NULL set.
  418. *
  419. * o We are transferring the last segment if residual_datacnt has
  420. * the SG_LAST_SEG flag set.
  421. *
  422. * Host:
  423. * o A residual has occurred if a completed scb has the
  424. * SG_RESID_VALID flag set.
  425. *
  426. * o residual_sgptr and sgptr refer to the "next" sg entry
  427. * and so may point beyond the last valid sg entry for the
  428. * transfer.
  429. */
  430. /*12*/ uint32_t dataptr;
  431. /*16*/ uint32_t datacnt; /*
  432. * Byte 3 (numbered from 0) of
  433. * the datacnt is really the
  434. * 4th byte in that data address.
  435. */
  436. /*20*/ uint32_t sgptr;
  437. #define SG_PTR_MASK 0xFFFFFFF8
  438. /*24*/ uint8_t control; /* See SCB_CONTROL in aic7xxx.reg for details */
  439. /*25*/ uint8_t scsiid; /* what to load in the SCSIID register */
  440. /*26*/ uint8_t lun;
  441. /*27*/ uint8_t tag; /*
  442. * Index into our kernel SCB array.
  443. * Also used as the tag for tagged I/O
  444. */
  445. /*28*/ uint8_t cdb_len;
  446. /*29*/ uint8_t scsirate; /* Value for SCSIRATE register */
  447. /*30*/ uint8_t scsioffset; /* Value for SCSIOFFSET register */
  448. /*31*/ uint8_t next; /*
  449. * Used for threading SCBs in the
  450. * "Waiting for Selection" and
  451. * "Disconnected SCB" lists down
  452. * in the sequencer.
  453. */
  454. /*32*/ uint8_t cdb32[32]; /*
  455. * CDB storage for cdbs of size
  456. * 13->32. We store them here
  457. * because hardware scbs are
  458. * allocated from DMA safe
  459. * memory so we are guaranteed
  460. * the controller can access
  461. * this data.
  462. */
  463. };
  464. /************************ Kernel SCB Definitions ******************************/
  465. /*
  466. * Some fields of the SCB are OS dependent. Here we collect the
  467. * definitions for elements that all OS platforms need to include
  468. * in there SCB definition.
  469. */
  470. /*
  471. * Definition of a scatter/gather element as transferred to the controller.
  472. * The aic7xxx chips only support a 24bit length. We use the top byte of
  473. * the length to store additional address bits and a flag to indicate
  474. * that a given segment terminates the transfer. This gives us an
  475. * addressable range of 512GB on machines with 64bit PCI or with chips
  476. * that can support dual address cycles on 32bit PCI busses.
  477. */
  478. struct ahc_dma_seg {
  479. uint32_t addr;
  480. uint32_t len;
  481. #define AHC_DMA_LAST_SEG 0x80000000
  482. #define AHC_SG_HIGH_ADDR_MASK 0x7F000000
  483. #define AHC_SG_LEN_MASK 0x00FFFFFF
  484. };
  485. struct sg_map_node {
  486. bus_dmamap_t sg_dmamap;
  487. dma_addr_t sg_physaddr;
  488. struct ahc_dma_seg* sg_vaddr;
  489. SLIST_ENTRY(sg_map_node) links;
  490. };
  491. /*
  492. * The current state of this SCB.
  493. */
  494. typedef enum {
  495. SCB_FREE = 0x0000,
  496. SCB_OTHERTCL_TIMEOUT = 0x0002,/*
  497. * Another device was active
  498. * during the first timeout for
  499. * this SCB so we gave ourselves
  500. * an additional timeout period
  501. * in case it was hogging the
  502. * bus.
  503. */
  504. SCB_DEVICE_RESET = 0x0004,
  505. SCB_SENSE = 0x0008,
  506. SCB_CDB32_PTR = 0x0010,
  507. SCB_RECOVERY_SCB = 0x0020,
  508. SCB_AUTO_NEGOTIATE = 0x0040,/* Negotiate to achieve goal. */
  509. SCB_NEGOTIATE = 0x0080,/* Negotiation forced for command. */
  510. SCB_ABORT = 0x0100,
  511. SCB_UNTAGGEDQ = 0x0200,
  512. SCB_ACTIVE = 0x0400,
  513. SCB_TARGET_IMMEDIATE = 0x0800,
  514. SCB_TRANSMISSION_ERROR = 0x1000,/*
  515. * We detected a parity or CRC
  516. * error that has effected the
  517. * payload of the command. This
  518. * flag is checked when normal
  519. * status is returned to catch
  520. * the case of a target not
  521. * responding to our attempt
  522. * to report the error.
  523. */
  524. SCB_TARGET_SCB = 0x2000,
  525. SCB_SILENT = 0x4000 /*
  526. * Be quiet about transmission type
  527. * errors. They are expected and we
  528. * don't want to upset the user. This
  529. * flag is typically used during DV.
  530. */
  531. } scb_flag;
  532. struct scb {
  533. struct hardware_scb *hscb;
  534. union {
  535. SLIST_ENTRY(scb) sle;
  536. TAILQ_ENTRY(scb) tqe;
  537. } links;
  538. LIST_ENTRY(scb) pending_links;
  539. ahc_io_ctx_t io_ctx;
  540. struct ahc_softc *ahc_softc;
  541. scb_flag flags;
  542. #ifndef __linux__
  543. bus_dmamap_t dmamap;
  544. #endif
  545. struct scb_platform_data *platform_data;
  546. struct sg_map_node *sg_map;
  547. struct ahc_dma_seg *sg_list;
  548. dma_addr_t sg_list_phys;
  549. u_int sg_count;/* How full ahc_dma_seg is */
  550. };
  551. struct scb_data {
  552. SLIST_HEAD(, scb) free_scbs; /*
  553. * Pool of SCBs ready to be assigned
  554. * commands to execute.
  555. */
  556. struct scb *scbindex[256]; /*
  557. * Mapping from tag to SCB.
  558. * As tag identifiers are an
  559. * 8bit value, we provide space
  560. * for all possible tag values.
  561. * Any lookups to entries at or
  562. * above AHC_SCB_MAX_ALLOC will
  563. * always fail.
  564. */
  565. struct hardware_scb *hscbs; /* Array of hardware SCBs */
  566. struct scb *scbarray; /* Array of kernel SCBs */
  567. struct scsi_sense_data *sense; /* Per SCB sense data */
  568. /*
  569. * "Bus" addresses of our data structures.
  570. */
  571. bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */
  572. bus_dmamap_t hscb_dmamap;
  573. dma_addr_t hscb_busaddr;
  574. bus_dma_tag_t sense_dmat;
  575. bus_dmamap_t sense_dmamap;
  576. dma_addr_t sense_busaddr;
  577. bus_dma_tag_t sg_dmat; /* dmat for our sg segments */
  578. SLIST_HEAD(, sg_map_node) sg_maps;
  579. uint8_t numscbs;
  580. uint8_t maxhscbs; /* Number of SCBs on the card */
  581. uint8_t init_level; /*
  582. * How far we've initialized
  583. * this structure.
  584. */
  585. };
  586. /************************ Target Mode Definitions *****************************/
  587. /*
  588. * Connection descriptor for select-in requests in target mode.
  589. */
  590. struct target_cmd {
  591. uint8_t scsiid; /* Our ID and the initiator's ID */
  592. uint8_t identify; /* Identify message */
  593. uint8_t bytes[22]; /*
  594. * Bytes contains any additional message
  595. * bytes terminated by 0xFF. The remainder
  596. * is the cdb to execute.
  597. */
  598. uint8_t cmd_valid; /*
  599. * When a command is complete, the firmware
  600. * will set cmd_valid to all bits set.
  601. * After the host has seen the command,
  602. * the bits are cleared. This allows us
  603. * to just peek at host memory to determine
  604. * if more work is complete. cmd_valid is on
  605. * an 8 byte boundary to simplify setting
  606. * it on aic7880 hardware which only has
  607. * limited direct access to the DMA FIFO.
  608. */
  609. uint8_t pad[7];
  610. };
  611. /*
  612. * Number of events we can buffer up if we run out
  613. * of immediate notify ccbs.
  614. */
  615. #define AHC_TMODE_EVENT_BUFFER_SIZE 8
  616. struct ahc_tmode_event {
  617. uint8_t initiator_id;
  618. uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */
  619. #define EVENT_TYPE_BUS_RESET 0xFF
  620. uint8_t event_arg;
  621. };
  622. /*
  623. * Per enabled lun target mode state.
  624. * As this state is directly influenced by the host OS'es target mode
  625. * environment, we let the OS module define it. Forward declare the
  626. * structure here so we can store arrays of them, etc. in OS neutral
  627. * data structures.
  628. */
  629. #ifdef AHC_TARGET_MODE
  630. struct ahc_tmode_lstate {
  631. struct cam_path *path;
  632. struct ccb_hdr_slist accept_tios;
  633. struct ccb_hdr_slist immed_notifies;
  634. struct ahc_tmode_event event_buffer[AHC_TMODE_EVENT_BUFFER_SIZE];
  635. uint8_t event_r_idx;
  636. uint8_t event_w_idx;
  637. };
  638. #else
  639. struct ahc_tmode_lstate;
  640. #endif
  641. /******************** Transfer Negotiation Datastructures *********************/
  642. #define AHC_TRANS_CUR 0x01 /* Modify current neogtiation status */
  643. #define AHC_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */
  644. #define AHC_TRANS_GOAL 0x04 /* Modify negotiation goal */
  645. #define AHC_TRANS_USER 0x08 /* Modify user negotiation settings */
  646. #define AHC_WIDTH_UNKNOWN 0xFF
  647. #define AHC_PERIOD_UNKNOWN 0xFF
  648. #define AHC_OFFSET_UNKNOWN 0xFF
  649. #define AHC_PPR_OPTS_UNKNOWN 0xFF
  650. /*
  651. * Transfer Negotiation Information.
  652. */
  653. struct ahc_transinfo {
  654. uint8_t protocol_version; /* SCSI Revision level */
  655. uint8_t transport_version; /* SPI Revision level */
  656. uint8_t width; /* Bus width */
  657. uint8_t period; /* Sync rate factor */
  658. uint8_t offset; /* Sync offset */
  659. uint8_t ppr_options; /* Parallel Protocol Request options */
  660. };
  661. /*
  662. * Per-initiator current, goal and user transfer negotiation information. */
  663. struct ahc_initiator_tinfo {
  664. uint8_t scsirate; /* Computed value for SCSIRATE reg */
  665. struct ahc_transinfo curr;
  666. struct ahc_transinfo goal;
  667. struct ahc_transinfo user;
  668. };
  669. /*
  670. * Per enabled target ID state.
  671. * Pointers to lun target state as well as sync/wide negotiation information
  672. * for each initiator<->target mapping. For the initiator role we pretend
  673. * that we are the target and the targets are the initiators since the
  674. * negotiation is the same regardless of role.
  675. */
  676. struct ahc_tmode_tstate {
  677. struct ahc_tmode_lstate* enabled_luns[AHC_NUM_LUNS];
  678. struct ahc_initiator_tinfo transinfo[AHC_NUM_TARGETS];
  679. /*
  680. * Per initiator state bitmasks.
  681. */
  682. uint16_t auto_negotiate;/* Auto Negotiation Required */
  683. uint16_t ultraenb; /* Using ultra sync rate */
  684. uint16_t discenable; /* Disconnection allowed */
  685. uint16_t tagenable; /* Tagged Queuing allowed */
  686. };
  687. /*
  688. * Data structure for our table of allowed synchronous transfer rates.
  689. */
  690. struct ahc_syncrate {
  691. u_int sxfr_u2; /* Value of the SXFR parameter for Ultra2+ Chips */
  692. u_int sxfr; /* Value of the SXFR parameter for <= Ultra Chips */
  693. #define ULTRA_SXFR 0x100 /* Rate Requires Ultra Mode set */
  694. #define ST_SXFR 0x010 /* Rate Single Transition Only */
  695. #define DT_SXFR 0x040 /* Rate Double Transition Only */
  696. uint8_t period; /* Period to send to SCSI target */
  697. const char *rate;
  698. };
  699. /* Safe and valid period for async negotiations. */
  700. #define AHC_ASYNC_XFER_PERIOD 0x45
  701. #define AHC_ULTRA2_XFER_PERIOD 0x0a
  702. /*
  703. * Indexes into our table of syncronous transfer rates.
  704. */
  705. #define AHC_SYNCRATE_DT 0
  706. #define AHC_SYNCRATE_ULTRA2 1
  707. #define AHC_SYNCRATE_ULTRA 3
  708. #define AHC_SYNCRATE_FAST 6
  709. #define AHC_SYNCRATE_MAX AHC_SYNCRATE_DT
  710. #define AHC_SYNCRATE_MIN 13
  711. /***************************** Lookup Tables **********************************/
  712. /*
  713. * Phase -> name and message out response
  714. * to parity errors in each phase table.
  715. */
  716. struct ahc_phase_table_entry {
  717. uint8_t phase;
  718. uint8_t mesg_out; /* Message response to parity errors */
  719. char *phasemsg;
  720. };
  721. /************************** Serial EEPROM Format ******************************/
  722. struct seeprom_config {
  723. /*
  724. * Per SCSI ID Configuration Flags
  725. */
  726. uint16_t device_flags[16]; /* words 0-15 */
  727. #define CFXFER 0x0007 /* synchronous transfer rate */
  728. #define CFSYNCH 0x0008 /* enable synchronous transfer */
  729. #define CFDISC 0x0010 /* enable disconnection */
  730. #define CFWIDEB 0x0020 /* wide bus device */
  731. #define CFSYNCHISULTRA 0x0040 /* CFSYNCH is an ultra offset (2940AU)*/
  732. #define CFSYNCSINGLE 0x0080 /* Single-Transition signalling */
  733. #define CFSTART 0x0100 /* send start unit SCSI command */
  734. #define CFINCBIOS 0x0200 /* include in BIOS scan */
  735. #define CFRNFOUND 0x0400 /* report even if not found */
  736. #define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */
  737. #define CFWBCACHEENB 0x4000 /* Enable W-Behind Cache on disks */
  738. #define CFWBCACHENOP 0xc000 /* Don't touch W-Behind Cache */
  739. /*
  740. * BIOS Control Bits
  741. */
  742. uint16_t bios_control; /* word 16 */
  743. #define CFSUPREM 0x0001 /* support all removeable drives */
  744. #define CFSUPREMB 0x0002 /* support removeable boot drives */
  745. #define CFBIOSEN 0x0004 /* BIOS enabled */
  746. #define CFBIOS_BUSSCAN 0x0008 /* Have the BIOS Scan the Bus */
  747. #define CFSM2DRV 0x0010 /* support more than two drives */
  748. #define CFSTPWLEVEL 0x0010 /* Termination level control */
  749. #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
  750. #define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */
  751. #define CFTERM_MENU 0x0040 /* BIOS displays termination menu */
  752. #define CFEXTEND 0x0080 /* extended translation enabled */
  753. #define CFSCAMEN 0x0100 /* SCAM enable */
  754. #define CFMSG_LEVEL 0x0600 /* BIOS Message Level */
  755. #define CFMSG_VERBOSE 0x0000
  756. #define CFMSG_SILENT 0x0200
  757. #define CFMSG_DIAG 0x0400
  758. #define CFBOOTCD 0x0800 /* Support Bootable CD-ROM */
  759. /* UNUSED 0xff00 */
  760. /*
  761. * Host Adapter Control Bits
  762. */
  763. uint16_t adapter_control; /* word 17 */
  764. #define CFAUTOTERM 0x0001 /* Perform Auto termination */
  765. #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable */
  766. #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */
  767. #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */
  768. #define CFSTERM 0x0004 /* SCSI low byte termination */
  769. #define CFWSTERM 0x0008 /* SCSI high byte termination */
  770. #define CFSPARITY 0x0010 /* SCSI parity */
  771. #define CF284XSTERM 0x0020 /* SCSI low byte term (284x cards) */
  772. #define CFMULTILUN 0x0020
  773. #define CFRESETB 0x0040 /* reset SCSI bus at boot */
  774. #define CFCLUSTERENB 0x0080 /* Cluster Enable */
  775. #define CFBOOTCHAN 0x0300 /* probe this channel first */
  776. #define CFBOOTCHANSHIFT 8
  777. #define CFSEAUTOTERM 0x0400 /* Ultra2 Perform secondary Auto Term*/
  778. #define CFSELOWTERM 0x0800 /* Ultra2 secondary low term */
  779. #define CFSEHIGHTERM 0x1000 /* Ultra2 secondary high term */
  780. #define CFENABLEDV 0x4000 /* Perform Domain Validation*/
  781. /*
  782. * Bus Release Time, Host Adapter ID
  783. */
  784. uint16_t brtime_id; /* word 18 */
  785. #define CFSCSIID 0x000f /* host adapter SCSI ID */
  786. /* UNUSED 0x00f0 */
  787. #define CFBRTIME 0xff00 /* bus release time */
  788. /*
  789. * Maximum targets
  790. */
  791. uint16_t max_targets; /* word 19 */
  792. #define CFMAXTARG 0x00ff /* maximum targets */
  793. #define CFBOOTLUN 0x0f00 /* Lun to boot from */
  794. #define CFBOOTID 0xf000 /* Target to boot from */
  795. uint16_t res_1[10]; /* words 20-29 */
  796. uint16_t signature; /* Signature == 0x250 */
  797. #define CFSIGNATURE 0x250
  798. #define CFSIGNATURE2 0x300
  799. uint16_t checksum; /* word 31 */
  800. };
  801. /**************************** Message Buffer *********************************/
  802. typedef enum {
  803. MSG_TYPE_NONE = 0x00,
  804. MSG_TYPE_INITIATOR_MSGOUT = 0x01,
  805. MSG_TYPE_INITIATOR_MSGIN = 0x02,
  806. MSG_TYPE_TARGET_MSGOUT = 0x03,
  807. MSG_TYPE_TARGET_MSGIN = 0x04
  808. } ahc_msg_type;
  809. typedef enum {
  810. MSGLOOP_IN_PROG,
  811. MSGLOOP_MSGCOMPLETE,
  812. MSGLOOP_TERMINATED
  813. } msg_loop_stat;
  814. /*********************** Software Configuration Structure *********************/
  815. TAILQ_HEAD(scb_tailq, scb);
  816. struct ahc_aic7770_softc {
  817. /*
  818. * Saved register state used for chip_init().
  819. */
  820. uint8_t busspd;
  821. uint8_t bustime;
  822. };
  823. struct ahc_pci_softc {
  824. /*
  825. * Saved register state used for chip_init().
  826. */
  827. uint32_t devconfig;
  828. uint16_t targcrccnt;
  829. uint8_t command;
  830. uint8_t csize_lattime;
  831. uint8_t optionmode;
  832. uint8_t crccontrol1;
  833. uint8_t dscommand0;
  834. uint8_t dspcistatus;
  835. uint8_t scbbaddr;
  836. uint8_t dff_thrsh;
  837. };
  838. union ahc_bus_softc {
  839. struct ahc_aic7770_softc aic7770_softc;
  840. struct ahc_pci_softc pci_softc;
  841. };
  842. typedef void (*ahc_bus_intr_t)(struct ahc_softc *);
  843. typedef int (*ahc_bus_chip_init_t)(struct ahc_softc *);
  844. typedef int (*ahc_bus_suspend_t)(struct ahc_softc *);
  845. typedef int (*ahc_bus_resume_t)(struct ahc_softc *);
  846. typedef void ahc_callback_t (void *);
  847. struct ahc_softc {
  848. bus_space_tag_t tag;
  849. bus_space_handle_t bsh;
  850. #ifndef __linux__
  851. bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */
  852. #endif
  853. struct scb_data *scb_data;
  854. struct scb *next_queued_scb;
  855. /*
  856. * SCBs that have been sent to the controller
  857. */
  858. BSD_LIST_HEAD(, scb) pending_scbs;
  859. /*
  860. * Counting lock for deferring the release of additional
  861. * untagged transactions from the untagged_queues. When
  862. * the lock is decremented to 0, all queues in the
  863. * untagged_queues array are run.
  864. */
  865. u_int untagged_queue_lock;
  866. /*
  867. * Per-target queue of untagged-transactions. The
  868. * transaction at the head of the queue is the
  869. * currently pending untagged transaction for the
  870. * target. The driver only allows a single untagged
  871. * transaction per target.
  872. */
  873. struct scb_tailq untagged_queues[AHC_NUM_TARGETS];
  874. /*
  875. * Bus attachment specific data.
  876. */
  877. union ahc_bus_softc bus_softc;
  878. /*
  879. * Platform specific data.
  880. */
  881. struct ahc_platform_data *platform_data;
  882. /*
  883. * Platform specific device information.
  884. */
  885. ahc_dev_softc_t dev_softc;
  886. struct device *dev;
  887. /*
  888. * Bus specific device information.
  889. */
  890. ahc_bus_intr_t bus_intr;
  891. /*
  892. * Bus specific initialization required
  893. * after a chip reset.
  894. */
  895. ahc_bus_chip_init_t bus_chip_init;
  896. /*
  897. * Target mode related state kept on a per enabled lun basis.
  898. * Targets that are not enabled will have null entries.
  899. * As an initiator, we keep one target entry for our initiator
  900. * ID to store our sync/wide transfer settings.
  901. */
  902. struct ahc_tmode_tstate *enabled_targets[AHC_NUM_TARGETS];
  903. /*
  904. * The black hole device responsible for handling requests for
  905. * disabled luns on enabled targets.
  906. */
  907. struct ahc_tmode_lstate *black_hole;
  908. /*
  909. * Device instance currently on the bus awaiting a continue TIO
  910. * for a command that was not given the disconnect priveledge.
  911. */
  912. struct ahc_tmode_lstate *pending_device;
  913. /*
  914. * Card characteristics
  915. */
  916. ahc_chip chip;
  917. ahc_feature features;
  918. ahc_bug bugs;
  919. ahc_flag flags;
  920. struct seeprom_config *seep_config;
  921. /* Values to store in the SEQCTL register for pause and unpause */
  922. uint8_t unpause;
  923. uint8_t pause;
  924. /* Command Queues */
  925. uint8_t qoutfifonext;
  926. uint8_t qinfifonext;
  927. uint8_t *qoutfifo;
  928. uint8_t *qinfifo;
  929. /* Critical Section Data */
  930. struct cs *critical_sections;
  931. u_int num_critical_sections;
  932. /* Channel Names ('A', 'B', etc.) */
  933. char channel;
  934. char channel_b;
  935. /* Initiator Bus ID */
  936. uint8_t our_id;
  937. uint8_t our_id_b;
  938. /*
  939. * PCI error detection.
  940. */
  941. int unsolicited_ints;
  942. /*
  943. * Target incoming command FIFO.
  944. */
  945. struct target_cmd *targetcmds;
  946. uint8_t tqinfifonext;
  947. /*
  948. * Cached copy of the sequencer control register.
  949. */
  950. uint8_t seqctl;
  951. /*
  952. * Incoming and outgoing message handling.
  953. */
  954. uint8_t send_msg_perror;
  955. ahc_msg_type msg_type;
  956. uint8_t msgout_buf[12];/* Message we are sending */
  957. uint8_t msgin_buf[12];/* Message we are receiving */
  958. u_int msgout_len; /* Length of message to send */
  959. u_int msgout_index; /* Current index in msgout */
  960. u_int msgin_index; /* Current index in msgin */
  961. /*
  962. * Mapping information for data structures shared
  963. * between the sequencer and kernel.
  964. */
  965. bus_dma_tag_t parent_dmat;
  966. bus_dma_tag_t shared_data_dmat;
  967. bus_dmamap_t shared_data_dmamap;
  968. dma_addr_t shared_data_busaddr;
  969. /*
  970. * Bus address of the one byte buffer used to
  971. * work-around a DMA bug for chips <= aic7880
  972. * in target mode.
  973. */
  974. dma_addr_t dma_bug_buf;
  975. /* Number of enabled target mode device on this card */
  976. u_int enabled_luns;
  977. /* Initialization level of this data structure */
  978. u_int init_level;
  979. /* PCI cacheline size. */
  980. u_int pci_cachesize;
  981. /*
  982. * Count of parity errors we have seen as a target.
  983. * We auto-disable parity error checking after seeing
  984. * AHC_PCI_TARGET_PERR_THRESH number of errors.
  985. */
  986. u_int pci_target_perr_count;
  987. #define AHC_PCI_TARGET_PERR_THRESH 10
  988. /* Maximum number of sequencer instructions supported. */
  989. u_int instruction_ram_size;
  990. /* Per-Unit descriptive information */
  991. const char *description;
  992. char *name;
  993. int unit;
  994. /* Selection Timer settings */
  995. int seltime;
  996. int seltime_b;
  997. uint16_t user_discenable;/* Disconnection allowed */
  998. uint16_t user_tagenable;/* Tagged Queuing allowed */
  999. };
  1000. /************************ Active Device Information ***************************/
  1001. typedef enum {
  1002. ROLE_UNKNOWN,
  1003. ROLE_INITIATOR,
  1004. ROLE_TARGET
  1005. } role_t;
  1006. struct ahc_devinfo {
  1007. int our_scsiid;
  1008. int target_offset;
  1009. uint16_t target_mask;
  1010. u_int target;
  1011. u_int lun;
  1012. char channel;
  1013. role_t role; /*
  1014. * Only guaranteed to be correct if not
  1015. * in the busfree state.
  1016. */
  1017. };
  1018. /****************************** PCI Structures ********************************/
  1019. typedef int (ahc_device_setup_t)(struct ahc_softc *);
  1020. struct ahc_pci_identity {
  1021. uint64_t full_id;
  1022. uint64_t id_mask;
  1023. const char *name;
  1024. ahc_device_setup_t *setup;
  1025. };
  1026. /***************************** VL/EISA Declarations ***************************/
  1027. struct aic7770_identity {
  1028. uint32_t full_id;
  1029. uint32_t id_mask;
  1030. const char *name;
  1031. ahc_device_setup_t *setup;
  1032. };
  1033. extern struct aic7770_identity aic7770_ident_table[];
  1034. extern const int ahc_num_aic7770_devs;
  1035. #define AHC_EISA_SLOT_OFFSET 0xc00
  1036. #define AHC_EISA_IOSIZE 0x100
  1037. /*************************** Function Declarations ****************************/
  1038. /******************************************************************************/
  1039. /***************************** PCI Front End *********************************/
  1040. const struct ahc_pci_identity *ahc_find_pci_device(ahc_dev_softc_t);
  1041. int ahc_pci_config(struct ahc_softc *,
  1042. const struct ahc_pci_identity *);
  1043. int ahc_pci_test_register_access(struct ahc_softc *);
  1044. #ifdef CONFIG_PM
  1045. void ahc_pci_resume(struct ahc_softc *ahc);
  1046. #endif
  1047. /*************************** EISA/VL Front End ********************************/
  1048. struct aic7770_identity *aic7770_find_device(uint32_t);
  1049. int aic7770_config(struct ahc_softc *ahc,
  1050. struct aic7770_identity *,
  1051. u_int port);
  1052. /************************** SCB and SCB queue management **********************/
  1053. int ahc_probe_scbs(struct ahc_softc *);
  1054. void ahc_qinfifo_requeue_tail(struct ahc_softc *ahc,
  1055. struct scb *scb);
  1056. int ahc_match_scb(struct ahc_softc *ahc, struct scb *scb,
  1057. int target, char channel, int lun,
  1058. u_int tag, role_t role);
  1059. /****************************** Initialization ********************************/
  1060. struct ahc_softc *ahc_alloc(void *platform_arg, char *name);
  1061. int ahc_softc_init(struct ahc_softc *);
  1062. void ahc_controller_info(struct ahc_softc *ahc, char *buf);
  1063. int ahc_chip_init(struct ahc_softc *ahc);
  1064. int ahc_init(struct ahc_softc *ahc);
  1065. void ahc_intr_enable(struct ahc_softc *ahc, int enable);
  1066. void ahc_pause_and_flushwork(struct ahc_softc *ahc);
  1067. #ifdef CONFIG_PM
  1068. int ahc_suspend(struct ahc_softc *ahc);
  1069. int ahc_resume(struct ahc_softc *ahc);
  1070. #endif
  1071. void ahc_set_unit(struct ahc_softc *, int);
  1072. void ahc_set_name(struct ahc_softc *, char *);
  1073. void ahc_free(struct ahc_softc *ahc);
  1074. int ahc_reset(struct ahc_softc *ahc, int reinit);
  1075. /***************************** Error Recovery *********************************/
  1076. typedef enum {
  1077. SEARCH_COMPLETE,
  1078. SEARCH_COUNT,
  1079. SEARCH_REMOVE
  1080. } ahc_search_action;
  1081. int ahc_search_qinfifo(struct ahc_softc *ahc, int target,
  1082. char channel, int lun, u_int tag,
  1083. role_t role, uint32_t status,
  1084. ahc_search_action action);
  1085. int ahc_search_untagged_queues(struct ahc_softc *ahc,
  1086. ahc_io_ctx_t ctx,
  1087. int target, char channel,
  1088. int lun, uint32_t status,
  1089. ahc_search_action action);
  1090. int ahc_search_disc_list(struct ahc_softc *ahc, int target,
  1091. char channel, int lun, u_int tag,
  1092. int stop_on_first, int remove,
  1093. int save_state);
  1094. int ahc_reset_channel(struct ahc_softc *ahc, char channel,
  1095. int initiate_reset);
  1096. /*************************** Utility Functions ********************************/
  1097. void ahc_compile_devinfo(struct ahc_devinfo *devinfo,
  1098. u_int our_id, u_int target,
  1099. u_int lun, char channel,
  1100. role_t role);
  1101. /************************** Transfer Negotiation ******************************/
  1102. const struct ahc_syncrate* ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
  1103. u_int *ppr_options, u_int maxsync);
  1104. u_int ahc_find_period(struct ahc_softc *ahc,
  1105. u_int scsirate, u_int maxsync);
  1106. /*
  1107. * Negotiation types. These are used to qualify if we should renegotiate
  1108. * even if our goal and current transport parameters are identical.
  1109. */
  1110. typedef enum {
  1111. AHC_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */
  1112. AHC_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */
  1113. AHC_NEG_ALWAYS /* Renegotiat even if goal is async. */
  1114. } ahc_neg_type;
  1115. int ahc_update_neg_request(struct ahc_softc*,
  1116. struct ahc_devinfo*,
  1117. struct ahc_tmode_tstate*,
  1118. struct ahc_initiator_tinfo*,
  1119. ahc_neg_type);
  1120. void ahc_set_width(struct ahc_softc *ahc,
  1121. struct ahc_devinfo *devinfo,
  1122. u_int width, u_int type, int paused);
  1123. void ahc_set_syncrate(struct ahc_softc *ahc,
  1124. struct ahc_devinfo *devinfo,
  1125. const struct ahc_syncrate *syncrate,
  1126. u_int period, u_int offset,
  1127. u_int ppr_options,
  1128. u_int type, int paused);
  1129. typedef enum {
  1130. AHC_QUEUE_NONE,
  1131. AHC_QUEUE_BASIC,
  1132. AHC_QUEUE_TAGGED
  1133. } ahc_queue_alg;
  1134. /**************************** Target Mode *************************************/
  1135. #ifdef AHC_TARGET_MODE
  1136. void ahc_send_lstate_events(struct ahc_softc *,
  1137. struct ahc_tmode_lstate *);
  1138. void ahc_handle_en_lun(struct ahc_softc *ahc,
  1139. struct cam_sim *sim, union ccb *ccb);
  1140. cam_status ahc_find_tmode_devs(struct ahc_softc *ahc,
  1141. struct cam_sim *sim, union ccb *ccb,
  1142. struct ahc_tmode_tstate **tstate,
  1143. struct ahc_tmode_lstate **lstate,
  1144. int notfound_failure);
  1145. #ifndef AHC_TMODE_ENABLE
  1146. #define AHC_TMODE_ENABLE 0
  1147. #endif
  1148. #endif
  1149. /******************************* Debug ***************************************/
  1150. #ifdef AHC_DEBUG
  1151. extern uint32_t ahc_debug;
  1152. #define AHC_SHOW_MISC 0x0001
  1153. #define AHC_SHOW_SENSE 0x0002
  1154. #define AHC_DUMP_SEEPROM 0x0004
  1155. #define AHC_SHOW_TERMCTL 0x0008
  1156. #define AHC_SHOW_MEMORY 0x0010
  1157. #define AHC_SHOW_MESSAGES 0x0020
  1158. #define AHC_SHOW_DV 0x0040
  1159. #define AHC_SHOW_SELTO 0x0080
  1160. #define AHC_SHOW_QFULL 0x0200
  1161. #define AHC_SHOW_QUEUE 0x0400
  1162. #define AHC_SHOW_TQIN 0x0800
  1163. #define AHC_SHOW_MASKED_ERRORS 0x1000
  1164. #define AHC_DEBUG_SEQUENCER 0x2000
  1165. #endif
  1166. void ahc_print_devinfo(struct ahc_softc *ahc,
  1167. struct ahc_devinfo *dev);
  1168. void ahc_dump_card_state(struct ahc_softc *ahc);
  1169. int ahc_print_register(const ahc_reg_parse_entry_t *table,
  1170. u_int num_entries,
  1171. const char *name,
  1172. u_int address,
  1173. u_int value,
  1174. u_int *cur_column,
  1175. u_int wrap_point);
  1176. /******************************* SEEPROM *************************************/
  1177. int ahc_acquire_seeprom(struct ahc_softc *ahc,
  1178. struct seeprom_descriptor *sd);
  1179. void ahc_release_seeprom(struct seeprom_descriptor *sd);
  1180. #endif /* _AIC7XXX_H_ */