aic7xxx.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  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. 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. /*
  887. * Bus specific device information.
  888. */
  889. ahc_bus_intr_t bus_intr;
  890. /*
  891. * Bus specific initialization required
  892. * after a chip reset.
  893. */
  894. ahc_bus_chip_init_t bus_chip_init;
  895. /*
  896. * Target mode related state kept on a per enabled lun basis.
  897. * Targets that are not enabled will have null entries.
  898. * As an initiator, we keep one target entry for our initiator
  899. * ID to store our sync/wide transfer settings.
  900. */
  901. struct ahc_tmode_tstate *enabled_targets[AHC_NUM_TARGETS];
  902. /*
  903. * The black hole device responsible for handling requests for
  904. * disabled luns on enabled targets.
  905. */
  906. struct ahc_tmode_lstate *black_hole;
  907. /*
  908. * Device instance currently on the bus awaiting a continue TIO
  909. * for a command that was not given the disconnect priveledge.
  910. */
  911. struct ahc_tmode_lstate *pending_device;
  912. /*
  913. * Card characteristics
  914. */
  915. ahc_chip chip;
  916. ahc_feature features;
  917. ahc_bug bugs;
  918. ahc_flag flags;
  919. struct seeprom_config *seep_config;
  920. /* Values to store in the SEQCTL register for pause and unpause */
  921. uint8_t unpause;
  922. uint8_t pause;
  923. /* Command Queues */
  924. uint8_t qoutfifonext;
  925. uint8_t qinfifonext;
  926. uint8_t *qoutfifo;
  927. uint8_t *qinfifo;
  928. /* Critical Section Data */
  929. struct cs *critical_sections;
  930. u_int num_critical_sections;
  931. /* Channel Names ('A', 'B', etc.) */
  932. char channel;
  933. char channel_b;
  934. /* Initiator Bus ID */
  935. uint8_t our_id;
  936. uint8_t our_id_b;
  937. /*
  938. * PCI error detection.
  939. */
  940. int unsolicited_ints;
  941. /*
  942. * Target incoming command FIFO.
  943. */
  944. struct target_cmd *targetcmds;
  945. uint8_t tqinfifonext;
  946. /*
  947. * Cached copy of the sequencer control register.
  948. */
  949. uint8_t seqctl;
  950. /*
  951. * Incoming and outgoing message handling.
  952. */
  953. uint8_t send_msg_perror;
  954. ahc_msg_type msg_type;
  955. uint8_t msgout_buf[12];/* Message we are sending */
  956. uint8_t msgin_buf[12];/* Message we are receiving */
  957. u_int msgout_len; /* Length of message to send */
  958. u_int msgout_index; /* Current index in msgout */
  959. u_int msgin_index; /* Current index in msgin */
  960. /*
  961. * Mapping information for data structures shared
  962. * between the sequencer and kernel.
  963. */
  964. bus_dma_tag_t parent_dmat;
  965. bus_dma_tag_t shared_data_dmat;
  966. bus_dmamap_t shared_data_dmamap;
  967. dma_addr_t shared_data_busaddr;
  968. /*
  969. * Bus address of the one byte buffer used to
  970. * work-around a DMA bug for chips <= aic7880
  971. * in target mode.
  972. */
  973. dma_addr_t dma_bug_buf;
  974. /* Number of enabled target mode device on this card */
  975. u_int enabled_luns;
  976. /* Initialization level of this data structure */
  977. u_int init_level;
  978. /* PCI cacheline size. */
  979. u_int pci_cachesize;
  980. /*
  981. * Count of parity errors we have seen as a target.
  982. * We auto-disable parity error checking after seeing
  983. * AHC_PCI_TARGET_PERR_THRESH number of errors.
  984. */
  985. u_int pci_target_perr_count;
  986. #define AHC_PCI_TARGET_PERR_THRESH 10
  987. /* Maximum number of sequencer instructions supported. */
  988. u_int instruction_ram_size;
  989. /* Per-Unit descriptive information */
  990. const char *description;
  991. char *name;
  992. int unit;
  993. /* Selection Timer settings */
  994. int seltime;
  995. int seltime_b;
  996. uint16_t user_discenable;/* Disconnection allowed */
  997. uint16_t user_tagenable;/* Tagged Queuing allowed */
  998. };
  999. /************************ Active Device Information ***************************/
  1000. typedef enum {
  1001. ROLE_UNKNOWN,
  1002. ROLE_INITIATOR,
  1003. ROLE_TARGET
  1004. } role_t;
  1005. struct ahc_devinfo {
  1006. int our_scsiid;
  1007. int target_offset;
  1008. uint16_t target_mask;
  1009. u_int target;
  1010. u_int lun;
  1011. char channel;
  1012. role_t role; /*
  1013. * Only guaranteed to be correct if not
  1014. * in the busfree state.
  1015. */
  1016. };
  1017. /****************************** PCI Structures ********************************/
  1018. typedef int (ahc_device_setup_t)(struct ahc_softc *);
  1019. struct ahc_pci_identity {
  1020. uint64_t full_id;
  1021. uint64_t id_mask;
  1022. const char *name;
  1023. ahc_device_setup_t *setup;
  1024. };
  1025. /***************************** VL/EISA Declarations ***************************/
  1026. struct aic7770_identity {
  1027. uint32_t full_id;
  1028. uint32_t id_mask;
  1029. const char *name;
  1030. ahc_device_setup_t *setup;
  1031. };
  1032. extern struct aic7770_identity aic7770_ident_table[];
  1033. extern const int ahc_num_aic7770_devs;
  1034. #define AHC_EISA_SLOT_OFFSET 0xc00
  1035. #define AHC_EISA_IOSIZE 0x100
  1036. /*************************** Function Declarations ****************************/
  1037. /******************************************************************************/
  1038. /***************************** PCI Front End *********************************/
  1039. const struct ahc_pci_identity *ahc_find_pci_device(ahc_dev_softc_t);
  1040. int ahc_pci_config(struct ahc_softc *,
  1041. const struct ahc_pci_identity *);
  1042. int ahc_pci_test_register_access(struct ahc_softc *);
  1043. #ifdef CONFIG_PM
  1044. void ahc_pci_resume(struct ahc_softc *ahc);
  1045. #endif
  1046. /*************************** EISA/VL Front End ********************************/
  1047. struct aic7770_identity *aic7770_find_device(uint32_t);
  1048. int aic7770_config(struct ahc_softc *ahc,
  1049. struct aic7770_identity *,
  1050. u_int port);
  1051. /************************** SCB and SCB queue management **********************/
  1052. int ahc_probe_scbs(struct ahc_softc *);
  1053. void ahc_qinfifo_requeue_tail(struct ahc_softc *ahc,
  1054. struct scb *scb);
  1055. int ahc_match_scb(struct ahc_softc *ahc, struct scb *scb,
  1056. int target, char channel, int lun,
  1057. u_int tag, role_t role);
  1058. /****************************** Initialization ********************************/
  1059. struct ahc_softc *ahc_alloc(void *platform_arg, char *name);
  1060. int ahc_softc_init(struct ahc_softc *);
  1061. void ahc_controller_info(struct ahc_softc *ahc, char *buf);
  1062. int ahc_chip_init(struct ahc_softc *ahc);
  1063. int ahc_init(struct ahc_softc *ahc);
  1064. void ahc_intr_enable(struct ahc_softc *ahc, int enable);
  1065. void ahc_pause_and_flushwork(struct ahc_softc *ahc);
  1066. #ifdef CONFIG_PM
  1067. int ahc_suspend(struct ahc_softc *ahc);
  1068. int ahc_resume(struct ahc_softc *ahc);
  1069. #endif
  1070. void ahc_set_unit(struct ahc_softc *, int);
  1071. void ahc_set_name(struct ahc_softc *, char *);
  1072. void ahc_free(struct ahc_softc *ahc);
  1073. int ahc_reset(struct ahc_softc *ahc, int reinit);
  1074. /***************************** Error Recovery *********************************/
  1075. typedef enum {
  1076. SEARCH_COMPLETE,
  1077. SEARCH_COUNT,
  1078. SEARCH_REMOVE
  1079. } ahc_search_action;
  1080. int ahc_search_qinfifo(struct ahc_softc *ahc, int target,
  1081. char channel, int lun, u_int tag,
  1082. role_t role, uint32_t status,
  1083. ahc_search_action action);
  1084. int ahc_search_untagged_queues(struct ahc_softc *ahc,
  1085. ahc_io_ctx_t ctx,
  1086. int target, char channel,
  1087. int lun, uint32_t status,
  1088. ahc_search_action action);
  1089. int ahc_search_disc_list(struct ahc_softc *ahc, int target,
  1090. char channel, int lun, u_int tag,
  1091. int stop_on_first, int remove,
  1092. int save_state);
  1093. int ahc_reset_channel(struct ahc_softc *ahc, char channel,
  1094. int initiate_reset);
  1095. /*************************** Utility Functions ********************************/
  1096. void ahc_compile_devinfo(struct ahc_devinfo *devinfo,
  1097. u_int our_id, u_int target,
  1098. u_int lun, char channel,
  1099. role_t role);
  1100. /************************** Transfer Negotiation ******************************/
  1101. const struct ahc_syncrate* ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
  1102. u_int *ppr_options, u_int maxsync);
  1103. u_int ahc_find_period(struct ahc_softc *ahc,
  1104. u_int scsirate, u_int maxsync);
  1105. /*
  1106. * Negotiation types. These are used to qualify if we should renegotiate
  1107. * even if our goal and current transport parameters are identical.
  1108. */
  1109. typedef enum {
  1110. AHC_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */
  1111. AHC_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */
  1112. AHC_NEG_ALWAYS /* Renegotiat even if goal is async. */
  1113. } ahc_neg_type;
  1114. int ahc_update_neg_request(struct ahc_softc*,
  1115. struct ahc_devinfo*,
  1116. struct ahc_tmode_tstate*,
  1117. struct ahc_initiator_tinfo*,
  1118. ahc_neg_type);
  1119. void ahc_set_width(struct ahc_softc *ahc,
  1120. struct ahc_devinfo *devinfo,
  1121. u_int width, u_int type, int paused);
  1122. void ahc_set_syncrate(struct ahc_softc *ahc,
  1123. struct ahc_devinfo *devinfo,
  1124. const struct ahc_syncrate *syncrate,
  1125. u_int period, u_int offset,
  1126. u_int ppr_options,
  1127. u_int type, int paused);
  1128. typedef enum {
  1129. AHC_QUEUE_NONE,
  1130. AHC_QUEUE_BASIC,
  1131. AHC_QUEUE_TAGGED
  1132. } ahc_queue_alg;
  1133. /**************************** Target Mode *************************************/
  1134. #ifdef AHC_TARGET_MODE
  1135. void ahc_send_lstate_events(struct ahc_softc *,
  1136. struct ahc_tmode_lstate *);
  1137. void ahc_handle_en_lun(struct ahc_softc *ahc,
  1138. struct cam_sim *sim, union ccb *ccb);
  1139. cam_status ahc_find_tmode_devs(struct ahc_softc *ahc,
  1140. struct cam_sim *sim, union ccb *ccb,
  1141. struct ahc_tmode_tstate **tstate,
  1142. struct ahc_tmode_lstate **lstate,
  1143. int notfound_failure);
  1144. #ifndef AHC_TMODE_ENABLE
  1145. #define AHC_TMODE_ENABLE 0
  1146. #endif
  1147. #endif
  1148. /******************************* Debug ***************************************/
  1149. #ifdef AHC_DEBUG
  1150. extern uint32_t ahc_debug;
  1151. #define AHC_SHOW_MISC 0x0001
  1152. #define AHC_SHOW_SENSE 0x0002
  1153. #define AHC_DUMP_SEEPROM 0x0004
  1154. #define AHC_SHOW_TERMCTL 0x0008
  1155. #define AHC_SHOW_MEMORY 0x0010
  1156. #define AHC_SHOW_MESSAGES 0x0020
  1157. #define AHC_SHOW_DV 0x0040
  1158. #define AHC_SHOW_SELTO 0x0080
  1159. #define AHC_SHOW_QFULL 0x0200
  1160. #define AHC_SHOW_QUEUE 0x0400
  1161. #define AHC_SHOW_TQIN 0x0800
  1162. #define AHC_SHOW_MASKED_ERRORS 0x1000
  1163. #define AHC_DEBUG_SEQUENCER 0x2000
  1164. #endif
  1165. void ahc_print_devinfo(struct ahc_softc *ahc,
  1166. struct ahc_devinfo *dev);
  1167. void ahc_dump_card_state(struct ahc_softc *ahc);
  1168. int ahc_print_register(const ahc_reg_parse_entry_t *table,
  1169. u_int num_entries,
  1170. const char *name,
  1171. u_int address,
  1172. u_int value,
  1173. u_int *cur_column,
  1174. u_int wrap_point);
  1175. /******************************* SEEPROM *************************************/
  1176. int ahc_acquire_seeprom(struct ahc_softc *ahc,
  1177. struct seeprom_descriptor *sd);
  1178. void ahc_release_seeprom(struct seeprom_descriptor *sd);
  1179. #endif /* _AIC7XXX_H_ */