aic7xxx.h 43 KB

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