aic79xx.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479
  1. /*
  2. * Core definitions and data structures shareable across OS platforms.
  3. *
  4. * Copyright (c) 1994-2002 Justin T. Gibbs.
  5. * Copyright (c) 2000-2002 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/aic79xx.h#109 $
  41. *
  42. * $FreeBSD$
  43. */
  44. #ifndef _AIC79XX_H_
  45. #define _AIC79XX_H_
  46. /* Register Definitions */
  47. #include "aic79xx_reg.h"
  48. /************************* Forward Declarations *******************************/
  49. struct ahd_platform_data;
  50. struct scb_platform_data;
  51. /****************************** Useful Macros *********************************/
  52. #ifndef TRUE
  53. #define TRUE 1
  54. #endif
  55. #ifndef FALSE
  56. #define FALSE 0
  57. #endif
  58. #define ALL_CHANNELS '\0'
  59. #define ALL_TARGETS_MASK 0xFFFF
  60. #define INITIATOR_WILDCARD (~0)
  61. #define SCB_LIST_NULL 0xFF00
  62. #define SCB_LIST_NULL_LE (ahd_htole16(SCB_LIST_NULL))
  63. #define QOUTFIFO_ENTRY_VALID 0x80
  64. #define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
  65. #define SCSIID_TARGET(ahd, scsiid) \
  66. (((scsiid) & TID) >> TID_SHIFT)
  67. #define SCSIID_OUR_ID(scsiid) \
  68. ((scsiid) & OID)
  69. #define SCSIID_CHANNEL(ahd, scsiid) ('A')
  70. #define SCB_IS_SCSIBUS_B(ahd, scb) (0)
  71. #define SCB_GET_OUR_ID(scb) \
  72. SCSIID_OUR_ID((scb)->hscb->scsiid)
  73. #define SCB_GET_TARGET(ahd, scb) \
  74. SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
  75. #define SCB_GET_CHANNEL(ahd, scb) \
  76. SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
  77. #define SCB_GET_LUN(scb) \
  78. ((scb)->hscb->lun)
  79. #define SCB_GET_TARGET_OFFSET(ahd, scb) \
  80. SCB_GET_TARGET(ahd, scb)
  81. #define SCB_GET_TARGET_MASK(ahd, scb) \
  82. (0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
  83. #ifdef AHD_DEBUG
  84. #define SCB_IS_SILENT(scb) \
  85. ((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0 \
  86. && (((scb)->flags & SCB_SILENT) != 0))
  87. #else
  88. #define SCB_IS_SILENT(scb) \
  89. (((scb)->flags & SCB_SILENT) != 0)
  90. #endif
  91. /*
  92. * TCLs have the following format: TTTTLLLLLLLL
  93. */
  94. #define TCL_TARGET_OFFSET(tcl) \
  95. ((((tcl) >> 4) & TID) >> 4)
  96. #define TCL_LUN(tcl) \
  97. (tcl & (AHD_NUM_LUNS - 1))
  98. #define BUILD_TCL(scsiid, lun) \
  99. ((lun) | (((scsiid) & TID) << 4))
  100. #define BUILD_TCL_RAW(target, channel, lun) \
  101. ((lun) | ((target) << 8))
  102. #define SCB_GET_TAG(scb) \
  103. ahd_le16toh(scb->hscb->tag)
  104. #ifndef AHD_TARGET_MODE
  105. #undef AHD_TMODE_ENABLE
  106. #define AHD_TMODE_ENABLE 0
  107. #endif
  108. #define AHD_BUILD_COL_IDX(target, lun) \
  109. (((lun) << 4) | target)
  110. #define AHD_GET_SCB_COL_IDX(ahd, scb) \
  111. ((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
  112. #define AHD_SET_SCB_COL_IDX(scb, col_idx) \
  113. do { \
  114. (scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID; \
  115. (scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1); \
  116. } while (0)
  117. #define AHD_COPY_SCB_COL_IDX(dst, src) \
  118. do { \
  119. dst->hscb->scsiid = src->hscb->scsiid; \
  120. dst->hscb->lun = src->hscb->lun; \
  121. } while (0)
  122. #define AHD_NEVER_COL_IDX 0xFFFF
  123. /**************************** Driver Constants ********************************/
  124. /*
  125. * The maximum number of supported targets.
  126. */
  127. #define AHD_NUM_TARGETS 16
  128. /*
  129. * The maximum number of supported luns.
  130. * The identify message only supports 64 luns in non-packetized transfers.
  131. * You can have 2^64 luns when information unit transfers are enabled,
  132. * but until we see a need to support that many, we support 256.
  133. */
  134. #define AHD_NUM_LUNS_NONPKT 64
  135. #define AHD_NUM_LUNS 256
  136. /*
  137. * The maximum transfer per S/G segment.
  138. */
  139. #define AHD_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */
  140. /*
  141. * The maximum amount of SCB storage in hardware on a controller.
  142. * This value represents an upper bound. Due to software design,
  143. * we may not be able to use this number.
  144. */
  145. #define AHD_SCB_MAX 512
  146. /*
  147. * The maximum number of concurrent transactions supported per driver instance.
  148. * Sequencer Control Blocks (SCBs) store per-transaction information.
  149. */
  150. #define AHD_MAX_QUEUE AHD_SCB_MAX
  151. /*
  152. * Define the size of our QIN and QOUT FIFOs. They must be a power of 2
  153. * in size and accommodate as many transactions as can be queued concurrently.
  154. */
  155. #define AHD_QIN_SIZE AHD_MAX_QUEUE
  156. #define AHD_QOUT_SIZE AHD_MAX_QUEUE
  157. #define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
  158. /*
  159. * The maximum amount of SCB storage we allocate in host memory.
  160. */
  161. #define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
  162. /*
  163. * Ring Buffer of incoming target commands.
  164. * We allocate 256 to simplify the logic in the sequencer
  165. * by using the natural wrap point of an 8bit counter.
  166. */
  167. #define AHD_TMODE_CMDS 256
  168. /* Reset line assertion time in us */
  169. #define AHD_BUSRESET_DELAY 25
  170. /******************* Chip Characteristics/Operating Settings *****************/
  171. /*
  172. * Chip Type
  173. * The chip order is from least sophisticated to most sophisticated.
  174. */
  175. typedef enum {
  176. AHD_NONE = 0x0000,
  177. AHD_CHIPID_MASK = 0x00FF,
  178. AHD_AIC7901 = 0x0001,
  179. AHD_AIC7902 = 0x0002,
  180. AHD_AIC7901A = 0x0003,
  181. AHD_PCI = 0x0100, /* Bus type PCI */
  182. AHD_PCIX = 0x0200, /* Bus type PCIX */
  183. AHD_BUS_MASK = 0x0F00
  184. } ahd_chip;
  185. /*
  186. * Features available in each chip type.
  187. */
  188. typedef enum {
  189. AHD_FENONE = 0x00000,
  190. AHD_WIDE = 0x00001,/* Wide Channel */
  191. AHD_AIC79XXB_SLOWCRC = 0x00002,/* SLOWCRC bit should be set */
  192. AHD_MULTI_FUNC = 0x00100,/* Multi-Function/Channel Device */
  193. AHD_TARGETMODE = 0x01000,/* Has tested target mode support */
  194. AHD_MULTIROLE = 0x02000,/* Space for two roles at a time */
  195. AHD_RTI = 0x04000,/* Retained Training Support */
  196. AHD_NEW_IOCELL_OPTS = 0x08000,/* More Signal knobs in the IOCELL */
  197. AHD_NEW_DFCNTRL_OPTS = 0x10000,/* SCSIENWRDIS bit */
  198. AHD_FAST_CDB_DELIVERY = 0x20000,/* CDB acks released to Output Sync */
  199. AHD_REMOVABLE = 0x00000,/* Hot-Swap supported - None so far*/
  200. AHD_AIC7901_FE = AHD_FENONE,
  201. AHD_AIC7901A_FE = AHD_FENONE,
  202. AHD_AIC7902_FE = AHD_MULTI_FUNC
  203. } ahd_feature;
  204. /*
  205. * Bugs in the silicon that we work around in software.
  206. */
  207. typedef enum {
  208. AHD_BUGNONE = 0x0000,
  209. /*
  210. * Rev A hardware fails to update LAST/CURR/NEXTSCB
  211. * correctly in certain packetized selection cases.
  212. */
  213. AHD_SENT_SCB_UPDATE_BUG = 0x0001,
  214. /* The wrong SCB is accessed to check the abort pending bit. */
  215. AHD_ABORT_LQI_BUG = 0x0002,
  216. /* Packetized bitbucket crosses packet boundaries. */
  217. AHD_PKT_BITBUCKET_BUG = 0x0004,
  218. /* The selection timer runs twice as long as its setting. */
  219. AHD_LONG_SETIMO_BUG = 0x0008,
  220. /* The Non-LQ CRC error status is delayed until phase change. */
  221. AHD_NLQICRC_DELAYED_BUG = 0x0010,
  222. /* The chip must be reset for all outgoing bus resets. */
  223. AHD_SCSIRST_BUG = 0x0020,
  224. /* Some PCIX fields must be saved and restored across chip reset. */
  225. AHD_PCIX_CHIPRST_BUG = 0x0040,
  226. /* MMAPIO is not functional in PCI-X mode. */
  227. AHD_PCIX_MMAPIO_BUG = 0x0080,
  228. /* Reads to SCBRAM fail to reset the discard timer. */
  229. AHD_PCIX_SCBRAM_RD_BUG = 0x0100,
  230. /* Bug workarounds that can be disabled on non-PCIX busses. */
  231. AHD_PCIX_BUG_MASK = AHD_PCIX_CHIPRST_BUG
  232. | AHD_PCIX_MMAPIO_BUG
  233. | AHD_PCIX_SCBRAM_RD_BUG,
  234. /*
  235. * LQOSTOP0 status set even for forced selections with ATN
  236. * to perform non-packetized message delivery.
  237. */
  238. AHD_LQO_ATNO_BUG = 0x0200,
  239. /* FIFO auto-flush does not always trigger. */
  240. AHD_AUTOFLUSH_BUG = 0x0400,
  241. /* The CLRLQO registers are not self-clearing. */
  242. AHD_CLRLQO_AUTOCLR_BUG = 0x0800,
  243. /* The PACKETIZED status bit refers to the previous connection. */
  244. AHD_PKTIZED_STATUS_BUG = 0x1000,
  245. /* "Short Luns" are not placed into outgoing LQ packets correctly. */
  246. AHD_PKT_LUN_BUG = 0x2000,
  247. /*
  248. * Only the FIFO allocated to the non-packetized connection may
  249. * be in use during a non-packetzied connection.
  250. */
  251. AHD_NONPACKFIFO_BUG = 0x4000,
  252. /*
  253. * Writing to a DFF SCBPTR register may fail if concurent with
  254. * a hardware write to the other DFF SCBPTR register. This is
  255. * not currently a concern in our sequencer since all chips with
  256. * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
  257. * occur in non-packetized connections.
  258. */
  259. AHD_MDFF_WSCBPTR_BUG = 0x8000,
  260. /* SGHADDR updates are slow. */
  261. AHD_REG_SLOW_SETTLE_BUG = 0x10000,
  262. /*
  263. * Changing the MODE_PTR coincident with an interrupt that
  264. * switches to a different mode will cause the interrupt to
  265. * be in the mode written outside of interrupt context.
  266. */
  267. AHD_SET_MODE_BUG = 0x20000,
  268. /* Non-packetized busfree revision does not work. */
  269. AHD_BUSFREEREV_BUG = 0x40000,
  270. /*
  271. * Paced transfers are indicated with a non-standard PPR
  272. * option bit in the neg table, 160MHz is indicated by
  273. * sync factor 0x7, and the offset if off by a factor of 2.
  274. */
  275. AHD_PACED_NEGTABLE_BUG = 0x80000,
  276. /* LQOOVERRUN false positives. */
  277. AHD_LQOOVERRUN_BUG = 0x100000,
  278. /*
  279. * Controller write to INTSTAT will lose to a host
  280. * write to CLRINT.
  281. */
  282. AHD_INTCOLLISION_BUG = 0x200000,
  283. /*
  284. * The GEM318 violates the SCSI spec by not waiting
  285. * the mandated bus settle delay between phase changes
  286. * in some situations. Some aic79xx chip revs. are more
  287. * strict in this regard and will treat REQ assertions
  288. * that fall within the bus settle delay window as
  289. * glitches. This flag tells the firmware to tolerate
  290. * early REQ assertions.
  291. */
  292. AHD_EARLY_REQ_BUG = 0x400000,
  293. /*
  294. * The LED does not stay on long enough in packetized modes.
  295. */
  296. AHD_FAINT_LED_BUG = 0x800000
  297. } ahd_bug;
  298. /*
  299. * Configuration specific settings.
  300. * The driver determines these settings by probing the
  301. * chip/controller's configuration.
  302. */
  303. typedef enum {
  304. AHD_FNONE = 0x00000,
  305. AHD_BOOT_CHANNEL = 0x00001,/* We were set as the boot channel. */
  306. AHD_USEDEFAULTS = 0x00004,/*
  307. * For cards without an seeprom
  308. * or a BIOS to initialize the chip's
  309. * SRAM, we use the default target
  310. * settings.
  311. */
  312. AHD_SEQUENCER_DEBUG = 0x00008,
  313. AHD_RESET_BUS_A = 0x00010,
  314. AHD_EXTENDED_TRANS_A = 0x00020,
  315. AHD_TERM_ENB_A = 0x00040,
  316. AHD_SPCHK_ENB_A = 0x00080,
  317. AHD_STPWLEVEL_A = 0x00100,
  318. AHD_INITIATORROLE = 0x00200,/*
  319. * Allow initiator operations on
  320. * this controller.
  321. */
  322. AHD_TARGETROLE = 0x00400,/*
  323. * Allow target operations on this
  324. * controller.
  325. */
  326. AHD_RESOURCE_SHORTAGE = 0x00800,
  327. AHD_TQINFIFO_BLOCKED = 0x01000,/* Blocked waiting for ATIOs */
  328. AHD_INT50_SPEEDFLEX = 0x02000,/*
  329. * Internal 50pin connector
  330. * sits behind an aic3860
  331. */
  332. AHD_BIOS_ENABLED = 0x04000,
  333. AHD_ALL_INTERRUPTS = 0x08000,
  334. AHD_39BIT_ADDRESSING = 0x10000,/* Use 39 bit addressing scheme. */
  335. AHD_64BIT_ADDRESSING = 0x20000,/* Use 64 bit addressing scheme. */
  336. AHD_CURRENT_SENSING = 0x40000,
  337. AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */
  338. AHD_HP_BOARD = 0x100000,
  339. AHD_BUS_RESET_ACTIVE = 0x200000,
  340. AHD_UPDATE_PEND_CMDS = 0x400000,
  341. AHD_RUNNING_QOUTFIFO = 0x800000,
  342. AHD_HAD_FIRST_SEL = 0x1000000
  343. } ahd_flag;
  344. /************************* Hardware SCB Definition ***************************/
  345. /*
  346. * The driver keeps up to MAX_SCB scb structures per card in memory. The SCB
  347. * consists of a "hardware SCB" mirroring the fields available on the card
  348. * and additional information the kernel stores for each transaction.
  349. *
  350. * To minimize space utilization, a portion of the hardware scb stores
  351. * different data during different portions of a SCSI transaction.
  352. * As initialized by the host driver for the initiator role, this area
  353. * contains the SCSI cdb (or a pointer to the cdb) to be executed. After
  354. * the cdb has been presented to the target, this area serves to store
  355. * residual transfer information and the SCSI status byte.
  356. * For the target role, the contents of this area do not change, but
  357. * still serve a different purpose than for the initiator role. See
  358. * struct target_data for details.
  359. */
  360. /*
  361. * Status information embedded in the shared poriton of
  362. * an SCB after passing the cdb to the target. The kernel
  363. * driver will only read this data for transactions that
  364. * complete abnormally.
  365. */
  366. struct initiator_status {
  367. uint32_t residual_datacnt; /* Residual in the current S/G seg */
  368. uint32_t residual_sgptr; /* The next S/G for this transfer */
  369. uint8_t scsi_status; /* Standard SCSI status byte */
  370. };
  371. struct target_status {
  372. uint32_t residual_datacnt; /* Residual in the current S/G seg */
  373. uint32_t residual_sgptr; /* The next S/G for this transfer */
  374. uint8_t scsi_status; /* SCSI status to give to initiator */
  375. uint8_t target_phases; /* Bitmap of phases to execute */
  376. uint8_t data_phase; /* Data-In or Data-Out */
  377. uint8_t initiator_tag; /* Initiator's transaction tag */
  378. };
  379. /*
  380. * Initiator mode SCB shared data area.
  381. * If the embedded CDB is 12 bytes or less, we embed
  382. * the sense buffer address in the SCB. This allows
  383. * us to retrieve sense information without interrupting
  384. * the host in packetized mode.
  385. */
  386. typedef uint32_t sense_addr_t;
  387. #define MAX_CDB_LEN 16
  388. #define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
  389. union initiator_data {
  390. struct {
  391. uint64_t cdbptr;
  392. uint8_t cdblen;
  393. } cdb_from_host;
  394. uint8_t cdb[MAX_CDB_LEN];
  395. struct {
  396. uint8_t cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
  397. sense_addr_t sense_addr;
  398. } cdb_plus_saddr;
  399. };
  400. /*
  401. * Target mode version of the shared data SCB segment.
  402. */
  403. struct target_data {
  404. uint32_t spare[2];
  405. uint8_t scsi_status; /* SCSI status to give to initiator */
  406. uint8_t target_phases; /* Bitmap of phases to execute */
  407. uint8_t data_phase; /* Data-In or Data-Out */
  408. uint8_t initiator_tag; /* Initiator's transaction tag */
  409. };
  410. struct hardware_scb {
  411. /*0*/ union {
  412. union initiator_data idata;
  413. struct target_data tdata;
  414. struct initiator_status istatus;
  415. struct target_status tstatus;
  416. } shared_data;
  417. /*
  418. * A word about residuals.
  419. * The scb is presented to the sequencer with the dataptr and datacnt
  420. * fields initialized to the contents of the first S/G element to
  421. * transfer. The sgptr field is initialized to the bus address for
  422. * the S/G element that follows the first in the in core S/G array
  423. * or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid
  424. * S/G entry for this transfer (single S/G element transfer with the
  425. * first elements address and length preloaded in the dataptr/datacnt
  426. * fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL.
  427. * The SG_FULL_RESID flag ensures that the residual will be correctly
  428. * noted even if no data transfers occur. Once the data phase is entered,
  429. * the residual sgptr and datacnt are loaded from the sgptr and the
  430. * datacnt fields. After each S/G element's dataptr and length are
  431. * loaded into the hardware, the residual sgptr is advanced. After
  432. * each S/G element is expired, its datacnt field is checked to see
  433. * if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the
  434. * residual sg ptr and the transfer is considered complete. If the
  435. * sequencer determines that there is a residual in the tranfer, or
  436. * there is non-zero status, it will set the SG_STATUS_VALID flag in
  437. * sgptr and dma the scb back into host memory. To sumarize:
  438. *
  439. * Sequencer:
  440. * o A residual has occurred if SG_FULL_RESID is set in sgptr,
  441. * or residual_sgptr does not have SG_LIST_NULL set.
  442. *
  443. * o We are transferring the last segment if residual_datacnt has
  444. * the SG_LAST_SEG flag set.
  445. *
  446. * Host:
  447. * o A residual can only have occurred if a completed scb has the
  448. * SG_STATUS_VALID flag set. Inspection of the SCSI status field,
  449. * the residual_datacnt, and the residual_sgptr field will tell
  450. * for sure.
  451. *
  452. * o residual_sgptr and sgptr refer to the "next" sg entry
  453. * and so may point beyond the last valid sg entry for the
  454. * transfer.
  455. */
  456. #define SG_PTR_MASK 0xFFFFFFF8
  457. /*16*/ uint16_t tag; /* Reused by Sequencer. */
  458. /*18*/ uint8_t control; /* See SCB_CONTROL in aic79xx.reg for details */
  459. /*19*/ uint8_t scsiid; /*
  460. * Selection out Id
  461. * Our Id (bits 0-3) Their ID (bits 4-7)
  462. */
  463. /*20*/ uint8_t lun;
  464. /*21*/ uint8_t task_attribute;
  465. /*22*/ uint8_t cdb_len;
  466. /*23*/ uint8_t task_management;
  467. /*24*/ uint64_t dataptr;
  468. /*32*/ uint32_t datacnt; /* Byte 3 is spare. */
  469. /*36*/ uint32_t sgptr;
  470. /*40*/ uint32_t hscb_busaddr;
  471. /*44*/ uint32_t next_hscb_busaddr;
  472. /********** Long lun field only downloaded for full 8 byte lun support ********/
  473. /*48*/ uint8_t pkt_long_lun[8];
  474. /******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
  475. /*56*/ uint8_t spare[8];
  476. };
  477. /************************ Kernel SCB Definitions ******************************/
  478. /*
  479. * Some fields of the SCB are OS dependent. Here we collect the
  480. * definitions for elements that all OS platforms need to include
  481. * in there SCB definition.
  482. */
  483. /*
  484. * Definition of a scatter/gather element as transferred to the controller.
  485. * The aic7xxx chips only support a 24bit length. We use the top byte of
  486. * the length to store additional address bits and a flag to indicate
  487. * that a given segment terminates the transfer. This gives us an
  488. * addressable range of 512GB on machines with 64bit PCI or with chips
  489. * that can support dual address cycles on 32bit PCI busses.
  490. */
  491. struct ahd_dma_seg {
  492. uint32_t addr;
  493. uint32_t len;
  494. #define AHD_DMA_LAST_SEG 0x80000000
  495. #define AHD_SG_HIGH_ADDR_MASK 0x7F000000
  496. #define AHD_SG_LEN_MASK 0x00FFFFFF
  497. };
  498. struct ahd_dma64_seg {
  499. uint64_t addr;
  500. uint32_t len;
  501. uint32_t pad;
  502. };
  503. struct map_node {
  504. bus_dmamap_t dmamap;
  505. dma_addr_t physaddr;
  506. uint8_t *vaddr;
  507. SLIST_ENTRY(map_node) links;
  508. };
  509. /*
  510. * The current state of this SCB.
  511. */
  512. typedef enum {
  513. SCB_FLAG_NONE = 0x00000,
  514. SCB_TRANSMISSION_ERROR = 0x00001,/*
  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_OTHERTCL_TIMEOUT = 0x00002,/*
  525. * Another device was active
  526. * during the first timeout for
  527. * this SCB so we gave ourselves
  528. * an additional timeout period
  529. * in case it was hogging the
  530. * bus.
  531. */
  532. SCB_DEVICE_RESET = 0x00004,
  533. SCB_SENSE = 0x00008,
  534. SCB_CDB32_PTR = 0x00010,
  535. SCB_RECOVERY_SCB = 0x00020,
  536. SCB_AUTO_NEGOTIATE = 0x00040,/* Negotiate to achieve goal. */
  537. SCB_NEGOTIATE = 0x00080,/* Negotiation forced for command. */
  538. SCB_ABORT = 0x00100,
  539. SCB_ACTIVE = 0x00200,
  540. SCB_TARGET_IMMEDIATE = 0x00400,
  541. SCB_PACKETIZED = 0x00800,
  542. SCB_EXPECT_PPR_BUSFREE = 0x01000,
  543. SCB_PKT_SENSE = 0x02000,
  544. SCB_EXTERNAL_RESET = 0x04000,/* Device was reset externally */
  545. SCB_ON_COL_LIST = 0x08000,
  546. SCB_SILENT = 0x10000 /*
  547. * Be quiet about transmission type
  548. * errors. They are expected and we
  549. * don't want to upset the user. This
  550. * flag is typically used during DV.
  551. */
  552. } scb_flag;
  553. struct scb {
  554. struct hardware_scb *hscb;
  555. union {
  556. SLIST_ENTRY(scb) sle;
  557. LIST_ENTRY(scb) le;
  558. TAILQ_ENTRY(scb) tqe;
  559. } links;
  560. union {
  561. SLIST_ENTRY(scb) sle;
  562. LIST_ENTRY(scb) le;
  563. TAILQ_ENTRY(scb) tqe;
  564. } links2;
  565. #define pending_links links2.le
  566. #define collision_links links2.le
  567. struct scb *col_scb;
  568. ahd_io_ctx_t io_ctx;
  569. struct ahd_softc *ahd_softc;
  570. scb_flag flags;
  571. #ifndef __linux__
  572. bus_dmamap_t dmamap;
  573. #endif
  574. struct scb_platform_data *platform_data;
  575. struct map_node *hscb_map;
  576. struct map_node *sg_map;
  577. struct map_node *sense_map;
  578. void *sg_list;
  579. uint8_t *sense_data;
  580. dma_addr_t sg_list_busaddr;
  581. dma_addr_t sense_busaddr;
  582. u_int sg_count;/* How full ahd_dma_seg is */
  583. #define AHD_MAX_LQ_CRC_ERRORS 5
  584. u_int crc_retry_count;
  585. };
  586. TAILQ_HEAD(scb_tailq, scb);
  587. LIST_HEAD(scb_list, scb);
  588. struct scb_data {
  589. /*
  590. * TAILQ of lists of free SCBs grouped by device
  591. * collision domains.
  592. */
  593. struct scb_tailq free_scbs;
  594. /*
  595. * Per-device lists of SCBs whose tag ID would collide
  596. * with an already active tag on the device.
  597. */
  598. struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
  599. /*
  600. * SCBs that will not collide with any active device.
  601. */
  602. struct scb_list any_dev_free_scb_list;
  603. /*
  604. * Mapping from tag to SCB.
  605. */
  606. struct scb *scbindex[AHD_SCB_MAX];
  607. /*
  608. * "Bus" addresses of our data structures.
  609. */
  610. bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */
  611. bus_dma_tag_t sg_dmat; /* dmat for our sg segments */
  612. bus_dma_tag_t sense_dmat; /* dmat for our sense buffers */
  613. SLIST_HEAD(, map_node) hscb_maps;
  614. SLIST_HEAD(, map_node) sg_maps;
  615. SLIST_HEAD(, map_node) sense_maps;
  616. int scbs_left; /* unallocated scbs in head map_node */
  617. int sgs_left; /* unallocated sgs in head map_node */
  618. int sense_left; /* unallocated sense in head map_node */
  619. uint16_t numscbs;
  620. uint16_t maxhscbs; /* Number of SCBs on the card */
  621. uint8_t init_level; /*
  622. * How far we've initialized
  623. * this structure.
  624. */
  625. };
  626. /************************ Target Mode Definitions *****************************/
  627. /*
  628. * Connection descriptor for select-in requests in target mode.
  629. */
  630. struct target_cmd {
  631. uint8_t scsiid; /* Our ID and the initiator's ID */
  632. uint8_t identify; /* Identify message */
  633. uint8_t bytes[22]; /*
  634. * Bytes contains any additional message
  635. * bytes terminated by 0xFF. The remainder
  636. * is the cdb to execute.
  637. */
  638. uint8_t cmd_valid; /*
  639. * When a command is complete, the firmware
  640. * will set cmd_valid to all bits set.
  641. * After the host has seen the command,
  642. * the bits are cleared. This allows us
  643. * to just peek at host memory to determine
  644. * if more work is complete. cmd_valid is on
  645. * an 8 byte boundary to simplify setting
  646. * it on aic7880 hardware which only has
  647. * limited direct access to the DMA FIFO.
  648. */
  649. uint8_t pad[7];
  650. };
  651. /*
  652. * Number of events we can buffer up if we run out
  653. * of immediate notify ccbs.
  654. */
  655. #define AHD_TMODE_EVENT_BUFFER_SIZE 8
  656. struct ahd_tmode_event {
  657. uint8_t initiator_id;
  658. uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */
  659. #define EVENT_TYPE_BUS_RESET 0xFF
  660. uint8_t event_arg;
  661. };
  662. /*
  663. * Per enabled lun target mode state.
  664. * As this state is directly influenced by the host OS'es target mode
  665. * environment, we let the OS module define it. Forward declare the
  666. * structure here so we can store arrays of them, etc. in OS neutral
  667. * data structures.
  668. */
  669. #ifdef AHD_TARGET_MODE
  670. struct ahd_tmode_lstate {
  671. struct cam_path *path;
  672. struct ccb_hdr_slist accept_tios;
  673. struct ccb_hdr_slist immed_notifies;
  674. struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
  675. uint8_t event_r_idx;
  676. uint8_t event_w_idx;
  677. };
  678. #else
  679. struct ahd_tmode_lstate;
  680. #endif
  681. /******************** Transfer Negotiation Datastructures *********************/
  682. #define AHD_TRANS_CUR 0x01 /* Modify current neogtiation status */
  683. #define AHD_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */
  684. #define AHD_TRANS_GOAL 0x04 /* Modify negotiation goal */
  685. #define AHD_TRANS_USER 0x08 /* Modify user negotiation settings */
  686. #define AHD_PERIOD_10MHz 0x19
  687. #define AHD_WIDTH_UNKNOWN 0xFF
  688. #define AHD_PERIOD_UNKNOWN 0xFF
  689. #define AHD_OFFSET_UNKNOWN 0xFF
  690. #define AHD_PPR_OPTS_UNKNOWN 0xFF
  691. /*
  692. * Transfer Negotiation Information.
  693. */
  694. struct ahd_transinfo {
  695. uint8_t protocol_version; /* SCSI Revision level */
  696. uint8_t transport_version; /* SPI Revision level */
  697. uint8_t width; /* Bus width */
  698. uint8_t period; /* Sync rate factor */
  699. uint8_t offset; /* Sync offset */
  700. uint8_t ppr_options; /* Parallel Protocol Request options */
  701. };
  702. /*
  703. * Per-initiator current, goal and user transfer negotiation information. */
  704. struct ahd_initiator_tinfo {
  705. struct ahd_transinfo curr;
  706. struct ahd_transinfo goal;
  707. struct ahd_transinfo user;
  708. };
  709. /*
  710. * Per enabled target ID state.
  711. * Pointers to lun target state as well as sync/wide negotiation information
  712. * for each initiator<->target mapping. For the initiator role we pretend
  713. * that we are the target and the targets are the initiators since the
  714. * negotiation is the same regardless of role.
  715. */
  716. struct ahd_tmode_tstate {
  717. struct ahd_tmode_lstate* enabled_luns[AHD_NUM_LUNS];
  718. struct ahd_initiator_tinfo transinfo[AHD_NUM_TARGETS];
  719. /*
  720. * Per initiator state bitmasks.
  721. */
  722. uint16_t auto_negotiate;/* Auto Negotiation Required */
  723. uint16_t discenable; /* Disconnection allowed */
  724. uint16_t tagenable; /* Tagged Queuing allowed */
  725. };
  726. /*
  727. * Points of interest along the negotiated transfer scale.
  728. */
  729. #define AHD_SYNCRATE_160 0x8
  730. #define AHD_SYNCRATE_PACED 0x8
  731. #define AHD_SYNCRATE_DT 0x9
  732. #define AHD_SYNCRATE_ULTRA2 0xa
  733. #define AHD_SYNCRATE_ULTRA 0xc
  734. #define AHD_SYNCRATE_FAST 0x19
  735. #define AHD_SYNCRATE_MIN_DT AHD_SYNCRATE_FAST
  736. #define AHD_SYNCRATE_SYNC 0x32
  737. #define AHD_SYNCRATE_MIN 0x60
  738. #define AHD_SYNCRATE_ASYNC 0xFF
  739. #define AHD_SYNCRATE_MAX AHD_SYNCRATE_160
  740. /* Safe and valid period for async negotiations. */
  741. #define AHD_ASYNC_XFER_PERIOD 0x44
  742. /*
  743. * In RevA, the synctable uses a 120MHz rate for the period
  744. * factor 8 and 160MHz for the period factor 7. The 120MHz
  745. * rate never made it into the official SCSI spec, so we must
  746. * compensate when setting the negotiation table for Rev A
  747. * parts.
  748. */
  749. #define AHD_SYNCRATE_REVA_120 0x8
  750. #define AHD_SYNCRATE_REVA_160 0x7
  751. /***************************** Lookup Tables **********************************/
  752. /*
  753. * Phase -> name and message out response
  754. * to parity errors in each phase table.
  755. */
  756. struct ahd_phase_table_entry {
  757. uint8_t phase;
  758. uint8_t mesg_out; /* Message response to parity errors */
  759. const char *phasemsg;
  760. };
  761. /************************** Serial EEPROM Format ******************************/
  762. struct seeprom_config {
  763. /*
  764. * Per SCSI ID Configuration Flags
  765. */
  766. uint16_t device_flags[16]; /* words 0-15 */
  767. #define CFXFER 0x003F /* synchronous transfer rate */
  768. #define CFXFER_ASYNC 0x3F
  769. #define CFQAS 0x0040 /* Negotiate QAS */
  770. #define CFPACKETIZED 0x0080 /* Negotiate Packetized Transfers */
  771. #define CFSTART 0x0100 /* send start unit SCSI command */
  772. #define CFINCBIOS 0x0200 /* include in BIOS scan */
  773. #define CFDISC 0x0400 /* enable disconnection */
  774. #define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */
  775. #define CFWIDEB 0x1000 /* wide bus device */
  776. #define CFHOSTMANAGED 0x8000 /* Managed by a RAID controller */
  777. /*
  778. * BIOS Control Bits
  779. */
  780. uint16_t bios_control; /* word 16 */
  781. #define CFSUPREM 0x0001 /* support all removeable drives */
  782. #define CFSUPREMB 0x0002 /* support removeable boot drives */
  783. #define CFBIOSSTATE 0x000C /* BIOS Action State */
  784. #define CFBS_DISABLED 0x00
  785. #define CFBS_ENABLED 0x04
  786. #define CFBS_DISABLED_SCAN 0x08
  787. #define CFENABLEDV 0x0010 /* Perform Domain Validation */
  788. #define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */
  789. #define CFSPARITY 0x0040 /* SCSI parity */
  790. #define CFEXTEND 0x0080 /* extended translation enabled */
  791. #define CFBOOTCD 0x0100 /* Support Bootable CD-ROM */
  792. #define CFMSG_LEVEL 0x0600 /* BIOS Message Level */
  793. #define CFMSG_VERBOSE 0x0000
  794. #define CFMSG_SILENT 0x0200
  795. #define CFMSG_DIAG 0x0400
  796. #define CFRESETB 0x0800 /* reset SCSI bus at boot */
  797. /* UNUSED 0xf000 */
  798. /*
  799. * Host Adapter Control Bits
  800. */
  801. uint16_t adapter_control; /* word 17 */
  802. #define CFAUTOTERM 0x0001 /* Perform Auto termination */
  803. #define CFSTERM 0x0002 /* SCSI low byte termination */
  804. #define CFWSTERM 0x0004 /* SCSI high byte termination */
  805. #define CFSEAUTOTERM 0x0008 /* Ultra2 Perform secondary Auto Term*/
  806. #define CFSELOWTERM 0x0010 /* Ultra2 secondary low term */
  807. #define CFSEHIGHTERM 0x0020 /* Ultra2 secondary high term */
  808. #define CFSTPWLEVEL 0x0040 /* Termination level control */
  809. #define CFBIOSAUTOTERM 0x0080 /* Perform Auto termination */
  810. #define CFTERM_MENU 0x0100 /* BIOS displays termination menu */
  811. #define CFCLUSTERENB 0x8000 /* Cluster Enable */
  812. /*
  813. * Bus Release Time, Host Adapter ID
  814. */
  815. uint16_t brtime_id; /* word 18 */
  816. #define CFSCSIID 0x000f /* host adapter SCSI ID */
  817. /* UNUSED 0x00f0 */
  818. #define CFBRTIME 0xff00 /* bus release time/PCI Latency Time */
  819. /*
  820. * Maximum targets
  821. */
  822. uint16_t max_targets; /* word 19 */
  823. #define CFMAXTARG 0x00ff /* maximum targets */
  824. #define CFBOOTLUN 0x0f00 /* Lun to boot from */
  825. #define CFBOOTID 0xf000 /* Target to boot from */
  826. uint16_t res_1[10]; /* words 20-29 */
  827. uint16_t signature; /* BIOS Signature */
  828. #define CFSIGNATURE 0x400
  829. uint16_t checksum; /* word 31 */
  830. };
  831. /*
  832. * Vital Product Data used during POST and by the BIOS.
  833. */
  834. struct vpd_config {
  835. uint8_t bios_flags;
  836. #define VPDMASTERBIOS 0x0001
  837. #define VPDBOOTHOST 0x0002
  838. uint8_t reserved_1[21];
  839. uint8_t resource_type;
  840. uint8_t resource_len[2];
  841. uint8_t resource_data[8];
  842. uint8_t vpd_tag;
  843. uint16_t vpd_len;
  844. uint8_t vpd_keyword[2];
  845. uint8_t length;
  846. uint8_t revision;
  847. uint8_t device_flags;
  848. uint8_t termnation_menus[2];
  849. uint8_t fifo_threshold;
  850. uint8_t end_tag;
  851. uint8_t vpd_checksum;
  852. uint16_t default_target_flags;
  853. uint16_t default_bios_flags;
  854. uint16_t default_ctrl_flags;
  855. uint8_t default_irq;
  856. uint8_t pci_lattime;
  857. uint8_t max_target;
  858. uint8_t boot_lun;
  859. uint16_t signature;
  860. uint8_t reserved_2;
  861. uint8_t checksum;
  862. uint8_t reserved_3[4];
  863. };
  864. /****************************** Flexport Logic ********************************/
  865. #define FLXADDR_TERMCTL 0x0
  866. #define FLX_TERMCTL_ENSECHIGH 0x8
  867. #define FLX_TERMCTL_ENSECLOW 0x4
  868. #define FLX_TERMCTL_ENPRIHIGH 0x2
  869. #define FLX_TERMCTL_ENPRILOW 0x1
  870. #define FLXADDR_ROMSTAT_CURSENSECTL 0x1
  871. #define FLX_ROMSTAT_SEECFG 0xF0
  872. #define FLX_ROMSTAT_EECFG 0x0F
  873. #define FLX_ROMSTAT_SEE_93C66 0x00
  874. #define FLX_ROMSTAT_SEE_NONE 0xF0
  875. #define FLX_ROMSTAT_EE_512x8 0x0
  876. #define FLX_ROMSTAT_EE_1MBx8 0x1
  877. #define FLX_ROMSTAT_EE_2MBx8 0x2
  878. #define FLX_ROMSTAT_EE_4MBx8 0x3
  879. #define FLX_ROMSTAT_EE_16MBx8 0x4
  880. #define CURSENSE_ENB 0x1
  881. #define FLXADDR_FLEXSTAT 0x2
  882. #define FLX_FSTAT_BUSY 0x1
  883. #define FLXADDR_CURRENT_STAT 0x4
  884. #define FLX_CSTAT_SEC_HIGH 0xC0
  885. #define FLX_CSTAT_SEC_LOW 0x30
  886. #define FLX_CSTAT_PRI_HIGH 0x0C
  887. #define FLX_CSTAT_PRI_LOW 0x03
  888. #define FLX_CSTAT_MASK 0x03
  889. #define FLX_CSTAT_SHIFT 2
  890. #define FLX_CSTAT_OKAY 0x0
  891. #define FLX_CSTAT_OVER 0x1
  892. #define FLX_CSTAT_UNDER 0x2
  893. #define FLX_CSTAT_INVALID 0x3
  894. int ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
  895. u_int start_addr, u_int count, int bstream);
  896. int ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
  897. u_int start_addr, u_int count);
  898. int ahd_verify_cksum(struct seeprom_config *sc);
  899. int ahd_acquire_seeprom(struct ahd_softc *ahd);
  900. void ahd_release_seeprom(struct ahd_softc *ahd);
  901. /**************************** Message Buffer *********************************/
  902. typedef enum {
  903. MSG_FLAG_NONE = 0x00,
  904. MSG_FLAG_EXPECT_PPR_BUSFREE = 0x01,
  905. MSG_FLAG_IU_REQ_CHANGED = 0x02,
  906. MSG_FLAG_EXPECT_IDE_BUSFREE = 0x04,
  907. MSG_FLAG_EXPECT_QASREJ_BUSFREE = 0x08,
  908. MSG_FLAG_PACKETIZED = 0x10
  909. } ahd_msg_flags;
  910. typedef enum {
  911. MSG_TYPE_NONE = 0x00,
  912. MSG_TYPE_INITIATOR_MSGOUT = 0x01,
  913. MSG_TYPE_INITIATOR_MSGIN = 0x02,
  914. MSG_TYPE_TARGET_MSGOUT = 0x03,
  915. MSG_TYPE_TARGET_MSGIN = 0x04
  916. } ahd_msg_type;
  917. typedef enum {
  918. MSGLOOP_IN_PROG,
  919. MSGLOOP_MSGCOMPLETE,
  920. MSGLOOP_TERMINATED
  921. } msg_loop_stat;
  922. /*********************** Software Configuration Structure *********************/
  923. struct ahd_suspend_channel_state {
  924. uint8_t scsiseq;
  925. uint8_t sxfrctl0;
  926. uint8_t sxfrctl1;
  927. uint8_t simode0;
  928. uint8_t simode1;
  929. uint8_t seltimer;
  930. uint8_t seqctl;
  931. };
  932. struct ahd_suspend_pci_state {
  933. uint32_t devconfig;
  934. uint8_t command;
  935. uint8_t csize_lattime;
  936. };
  937. struct ahd_suspend_state {
  938. struct ahd_suspend_channel_state channel[2];
  939. struct ahd_suspend_pci_state pci_state;
  940. uint8_t optionmode;
  941. uint8_t dscommand0;
  942. uint8_t dspcistatus;
  943. /* hsmailbox */
  944. uint8_t crccontrol1;
  945. uint8_t scbbaddr;
  946. /* Host and sequencer SCB counts */
  947. uint8_t dff_thrsh;
  948. uint8_t *scratch_ram;
  949. uint8_t *btt;
  950. };
  951. typedef void (*ahd_bus_intr_t)(struct ahd_softc *);
  952. typedef enum {
  953. AHD_MODE_DFF0,
  954. AHD_MODE_DFF1,
  955. AHD_MODE_CCHAN,
  956. AHD_MODE_SCSI,
  957. AHD_MODE_CFG,
  958. AHD_MODE_UNKNOWN
  959. } ahd_mode;
  960. #define AHD_MK_MSK(x) (0x01 << (x))
  961. #define AHD_MODE_DFF0_MSK AHD_MK_MSK(AHD_MODE_DFF0)
  962. #define AHD_MODE_DFF1_MSK AHD_MK_MSK(AHD_MODE_DFF1)
  963. #define AHD_MODE_CCHAN_MSK AHD_MK_MSK(AHD_MODE_CCHAN)
  964. #define AHD_MODE_SCSI_MSK AHD_MK_MSK(AHD_MODE_SCSI)
  965. #define AHD_MODE_CFG_MSK AHD_MK_MSK(AHD_MODE_CFG)
  966. #define AHD_MODE_UNKNOWN_MSK AHD_MK_MSK(AHD_MODE_UNKNOWN)
  967. #define AHD_MODE_ANY_MSK (~0)
  968. typedef uint8_t ahd_mode_state;
  969. typedef void ahd_callback_t (void *);
  970. struct ahd_completion
  971. {
  972. uint16_t tag;
  973. uint8_t sg_status;
  974. uint8_t valid_tag;
  975. };
  976. struct ahd_softc {
  977. bus_space_tag_t tags[2];
  978. bus_space_handle_t bshs[2];
  979. #ifndef __linux__
  980. bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */
  981. #endif
  982. struct scb_data scb_data;
  983. struct hardware_scb *next_queued_hscb;
  984. struct map_node *next_queued_hscb_map;
  985. /*
  986. * SCBs that have been sent to the controller
  987. */
  988. LIST_HEAD(, scb) pending_scbs;
  989. /*
  990. * Current register window mode information.
  991. */
  992. ahd_mode dst_mode;
  993. ahd_mode src_mode;
  994. /*
  995. * Saved register window mode information
  996. * used for restore on next unpause.
  997. */
  998. ahd_mode saved_dst_mode;
  999. ahd_mode saved_src_mode;
  1000. /*
  1001. * Platform specific data.
  1002. */
  1003. struct ahd_platform_data *platform_data;
  1004. /*
  1005. * Platform specific device information.
  1006. */
  1007. ahd_dev_softc_t dev_softc;
  1008. /*
  1009. * Bus specific device information.
  1010. */
  1011. ahd_bus_intr_t bus_intr;
  1012. /*
  1013. * Target mode related state kept on a per enabled lun basis.
  1014. * Targets that are not enabled will have null entries.
  1015. * As an initiator, we keep one target entry for our initiator
  1016. * ID to store our sync/wide transfer settings.
  1017. */
  1018. struct ahd_tmode_tstate *enabled_targets[AHD_NUM_TARGETS];
  1019. /*
  1020. * The black hole device responsible for handling requests for
  1021. * disabled luns on enabled targets.
  1022. */
  1023. struct ahd_tmode_lstate *black_hole;
  1024. /*
  1025. * Device instance currently on the bus awaiting a continue TIO
  1026. * for a command that was not given the disconnect priveledge.
  1027. */
  1028. struct ahd_tmode_lstate *pending_device;
  1029. /*
  1030. * Timer handles for timer driven callbacks.
  1031. */
  1032. ahd_timer_t reset_timer;
  1033. ahd_timer_t stat_timer;
  1034. /*
  1035. * Statistics.
  1036. */
  1037. #define AHD_STAT_UPDATE_US 250000 /* 250ms */
  1038. #define AHD_STAT_BUCKETS 4
  1039. u_int cmdcmplt_bucket;
  1040. uint32_t cmdcmplt_counts[AHD_STAT_BUCKETS];
  1041. uint32_t cmdcmplt_total;
  1042. /*
  1043. * Card characteristics
  1044. */
  1045. ahd_chip chip;
  1046. ahd_feature features;
  1047. ahd_bug bugs;
  1048. ahd_flag flags;
  1049. struct seeprom_config *seep_config;
  1050. /* Command Queues */
  1051. struct ahd_completion *qoutfifo;
  1052. uint16_t qoutfifonext;
  1053. uint16_t qoutfifonext_valid_tag;
  1054. uint16_t qinfifonext;
  1055. uint16_t qinfifo[AHD_SCB_MAX];
  1056. /*
  1057. * Our qfreeze count. The sequencer compares
  1058. * this value with its own counter to determine
  1059. * whether to allow selections to occur.
  1060. */
  1061. uint16_t qfreeze_cnt;
  1062. /* Values to store in the SEQCTL register for pause and unpause */
  1063. uint8_t unpause;
  1064. uint8_t pause;
  1065. /* Critical Section Data */
  1066. struct cs *critical_sections;
  1067. u_int num_critical_sections;
  1068. /* Buffer for handling packetized bitbucket. */
  1069. uint8_t *overrun_buf;
  1070. /* Links for chaining softcs */
  1071. TAILQ_ENTRY(ahd_softc) links;
  1072. /* Channel Names ('A', 'B', etc.) */
  1073. char channel;
  1074. /* Initiator Bus ID */
  1075. uint8_t our_id;
  1076. /*
  1077. * Target incoming command FIFO.
  1078. */
  1079. struct target_cmd *targetcmds;
  1080. uint8_t tqinfifonext;
  1081. /*
  1082. * Cached verson of the hs_mailbox so we can avoid
  1083. * pausing the sequencer during mailbox updates.
  1084. */
  1085. uint8_t hs_mailbox;
  1086. /*
  1087. * Incoming and outgoing message handling.
  1088. */
  1089. uint8_t send_msg_perror;
  1090. ahd_msg_flags msg_flags;
  1091. ahd_msg_type msg_type;
  1092. uint8_t msgout_buf[12];/* Message we are sending */
  1093. uint8_t msgin_buf[12];/* Message we are receiving */
  1094. u_int msgout_len; /* Length of message to send */
  1095. u_int msgout_index; /* Current index in msgout */
  1096. u_int msgin_index; /* Current index in msgin */
  1097. /*
  1098. * Mapping information for data structures shared
  1099. * between the sequencer and kernel.
  1100. */
  1101. bus_dma_tag_t parent_dmat;
  1102. bus_dma_tag_t shared_data_dmat;
  1103. struct map_node shared_data_map;
  1104. /* Information saved through suspend/resume cycles */
  1105. struct ahd_suspend_state suspend_state;
  1106. /* Number of enabled target mode device on this card */
  1107. u_int enabled_luns;
  1108. /* Initialization level of this data structure */
  1109. u_int init_level;
  1110. /* PCI cacheline size. */
  1111. u_int pci_cachesize;
  1112. /* IO Cell Parameters */
  1113. uint8_t iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
  1114. u_int stack_size;
  1115. uint16_t *saved_stack;
  1116. /* Per-Unit descriptive information */
  1117. const char *description;
  1118. const char *bus_description;
  1119. char *name;
  1120. int unit;
  1121. /* Selection Timer settings */
  1122. int seltime;
  1123. /*
  1124. * Interrupt coalescing settings.
  1125. */
  1126. #define AHD_INT_COALESCING_TIMER_DEFAULT 250 /*us*/
  1127. #define AHD_INT_COALESCING_MAXCMDS_DEFAULT 10
  1128. #define AHD_INT_COALESCING_MAXCMDS_MAX 127
  1129. #define AHD_INT_COALESCING_MINCMDS_DEFAULT 5
  1130. #define AHD_INT_COALESCING_MINCMDS_MAX 127
  1131. #define AHD_INT_COALESCING_THRESHOLD_DEFAULT 2000
  1132. #define AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT 1000
  1133. u_int int_coalescing_timer;
  1134. u_int int_coalescing_maxcmds;
  1135. u_int int_coalescing_mincmds;
  1136. u_int int_coalescing_threshold;
  1137. u_int int_coalescing_stop_threshold;
  1138. uint16_t user_discenable;/* Disconnection allowed */
  1139. uint16_t user_tagenable;/* Tagged Queuing allowed */
  1140. };
  1141. /*************************** IO Cell Configuration ****************************/
  1142. #define AHD_PRECOMP_SLEW_INDEX \
  1143. (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
  1144. #define AHD_AMPLITUDE_INDEX \
  1145. (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
  1146. #define AHD_SET_SLEWRATE(ahd, new_slew) \
  1147. do { \
  1148. (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK; \
  1149. (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \
  1150. (((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK); \
  1151. } while (0)
  1152. #define AHD_SET_PRECOMP(ahd, new_pcomp) \
  1153. do { \
  1154. (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK; \
  1155. (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \
  1156. (((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK); \
  1157. } while (0)
  1158. #define AHD_SET_AMPLITUDE(ahd, new_amp) \
  1159. do { \
  1160. (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK; \
  1161. (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |= \
  1162. (((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK); \
  1163. } while (0)
  1164. /************************ Active Device Information ***************************/
  1165. typedef enum {
  1166. ROLE_UNKNOWN,
  1167. ROLE_INITIATOR,
  1168. ROLE_TARGET
  1169. } role_t;
  1170. struct ahd_devinfo {
  1171. int our_scsiid;
  1172. int target_offset;
  1173. uint16_t target_mask;
  1174. u_int target;
  1175. u_int lun;
  1176. char channel;
  1177. role_t role; /*
  1178. * Only guaranteed to be correct if not
  1179. * in the busfree state.
  1180. */
  1181. };
  1182. /****************************** PCI Structures ********************************/
  1183. #define AHD_PCI_IOADDR0 PCIR_BAR(0) /* I/O BAR*/
  1184. #define AHD_PCI_MEMADDR PCIR_BAR(1) /* Memory BAR */
  1185. #define AHD_PCI_IOADDR1 PCIR_BAR(3) /* Second I/O BAR */
  1186. typedef int (ahd_device_setup_t)(struct ahd_softc *);
  1187. struct ahd_pci_identity {
  1188. uint64_t full_id;
  1189. uint64_t id_mask;
  1190. const char *name;
  1191. ahd_device_setup_t *setup;
  1192. };
  1193. /***************************** VL/EISA Declarations ***************************/
  1194. struct aic7770_identity {
  1195. uint32_t full_id;
  1196. uint32_t id_mask;
  1197. const char *name;
  1198. ahd_device_setup_t *setup;
  1199. };
  1200. extern struct aic7770_identity aic7770_ident_table [];
  1201. extern const int ahd_num_aic7770_devs;
  1202. #define AHD_EISA_SLOT_OFFSET 0xc00
  1203. #define AHD_EISA_IOSIZE 0x100
  1204. /*************************** Function Declarations ****************************/
  1205. /******************************************************************************/
  1206. /***************************** PCI Front End *********************************/
  1207. const struct ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
  1208. int ahd_pci_config(struct ahd_softc *,
  1209. const struct ahd_pci_identity *);
  1210. int ahd_pci_test_register_access(struct ahd_softc *);
  1211. #ifdef CONFIG_PM
  1212. void ahd_pci_suspend(struct ahd_softc *);
  1213. void ahd_pci_resume(struct ahd_softc *);
  1214. #endif
  1215. /************************** SCB and SCB queue management **********************/
  1216. void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
  1217. struct scb *scb);
  1218. /****************************** Initialization ********************************/
  1219. struct ahd_softc *ahd_alloc(void *platform_arg, char *name);
  1220. int ahd_softc_init(struct ahd_softc *);
  1221. void ahd_controller_info(struct ahd_softc *ahd, char *buf);
  1222. int ahd_init(struct ahd_softc *ahd);
  1223. #ifdef CONFIG_PM
  1224. int ahd_suspend(struct ahd_softc *ahd);
  1225. void ahd_resume(struct ahd_softc *ahd);
  1226. #endif
  1227. int ahd_default_config(struct ahd_softc *ahd);
  1228. int ahd_parse_vpddata(struct ahd_softc *ahd,
  1229. struct vpd_config *vpd);
  1230. int ahd_parse_cfgdata(struct ahd_softc *ahd,
  1231. struct seeprom_config *sc);
  1232. void ahd_intr_enable(struct ahd_softc *ahd, int enable);
  1233. void ahd_pause_and_flushwork(struct ahd_softc *ahd);
  1234. void ahd_set_unit(struct ahd_softc *, int);
  1235. void ahd_set_name(struct ahd_softc *, char *);
  1236. struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
  1237. void ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
  1238. void ahd_free(struct ahd_softc *ahd);
  1239. int ahd_reset(struct ahd_softc *ahd, int reinit);
  1240. int ahd_write_flexport(struct ahd_softc *ahd,
  1241. u_int addr, u_int value);
  1242. int ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
  1243. uint8_t *value);
  1244. /***************************** Error Recovery *********************************/
  1245. typedef enum {
  1246. SEARCH_COMPLETE,
  1247. SEARCH_COUNT,
  1248. SEARCH_REMOVE,
  1249. SEARCH_PRINT
  1250. } ahd_search_action;
  1251. int ahd_search_qinfifo(struct ahd_softc *ahd, int target,
  1252. char channel, int lun, u_int tag,
  1253. role_t role, uint32_t status,
  1254. ahd_search_action action);
  1255. int ahd_search_disc_list(struct ahd_softc *ahd, int target,
  1256. char channel, int lun, u_int tag,
  1257. int stop_on_first, int remove,
  1258. int save_state);
  1259. int ahd_reset_channel(struct ahd_softc *ahd, char channel,
  1260. int initiate_reset);
  1261. /*************************** Utility Functions ********************************/
  1262. void ahd_compile_devinfo(struct ahd_devinfo *devinfo,
  1263. u_int our_id, u_int target,
  1264. u_int lun, char channel,
  1265. role_t role);
  1266. /************************** Transfer Negotiation ******************************/
  1267. void ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
  1268. u_int *ppr_options, u_int maxsync);
  1269. /*
  1270. * Negotiation types. These are used to qualify if we should renegotiate
  1271. * even if our goal and current transport parameters are identical.
  1272. */
  1273. typedef enum {
  1274. AHD_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */
  1275. AHD_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */
  1276. AHD_NEG_ALWAYS /* Renegotiat even if goal is async. */
  1277. } ahd_neg_type;
  1278. int ahd_update_neg_request(struct ahd_softc*,
  1279. struct ahd_devinfo*,
  1280. struct ahd_tmode_tstate*,
  1281. struct ahd_initiator_tinfo*,
  1282. ahd_neg_type);
  1283. void ahd_set_width(struct ahd_softc *ahd,
  1284. struct ahd_devinfo *devinfo,
  1285. u_int width, u_int type, int paused);
  1286. void ahd_set_syncrate(struct ahd_softc *ahd,
  1287. struct ahd_devinfo *devinfo,
  1288. u_int period, u_int offset,
  1289. u_int ppr_options,
  1290. u_int type, int paused);
  1291. typedef enum {
  1292. AHD_QUEUE_NONE,
  1293. AHD_QUEUE_BASIC,
  1294. AHD_QUEUE_TAGGED
  1295. } ahd_queue_alg;
  1296. /**************************** Target Mode *************************************/
  1297. #ifdef AHD_TARGET_MODE
  1298. void ahd_send_lstate_events(struct ahd_softc *,
  1299. struct ahd_tmode_lstate *);
  1300. void ahd_handle_en_lun(struct ahd_softc *ahd,
  1301. struct cam_sim *sim, union ccb *ccb);
  1302. cam_status ahd_find_tmode_devs(struct ahd_softc *ahd,
  1303. struct cam_sim *sim, union ccb *ccb,
  1304. struct ahd_tmode_tstate **tstate,
  1305. struct ahd_tmode_lstate **lstate,
  1306. int notfound_failure);
  1307. #ifndef AHD_TMODE_ENABLE
  1308. #define AHD_TMODE_ENABLE 0
  1309. #endif
  1310. #endif
  1311. /******************************* Debug ***************************************/
  1312. #ifdef AHD_DEBUG
  1313. extern uint32_t ahd_debug;
  1314. #define AHD_SHOW_MISC 0x00001
  1315. #define AHD_SHOW_SENSE 0x00002
  1316. #define AHD_SHOW_RECOVERY 0x00004
  1317. #define AHD_DUMP_SEEPROM 0x00008
  1318. #define AHD_SHOW_TERMCTL 0x00010
  1319. #define AHD_SHOW_MEMORY 0x00020
  1320. #define AHD_SHOW_MESSAGES 0x00040
  1321. #define AHD_SHOW_MODEPTR 0x00080
  1322. #define AHD_SHOW_SELTO 0x00100
  1323. #define AHD_SHOW_FIFOS 0x00200
  1324. #define AHD_SHOW_QFULL 0x00400
  1325. #define AHD_SHOW_DV 0x00800
  1326. #define AHD_SHOW_MASKED_ERRORS 0x01000
  1327. #define AHD_SHOW_QUEUE 0x02000
  1328. #define AHD_SHOW_TQIN 0x04000
  1329. #define AHD_SHOW_SG 0x08000
  1330. #define AHD_SHOW_INT_COALESCING 0x10000
  1331. #define AHD_DEBUG_SEQUENCER 0x20000
  1332. #endif
  1333. void ahd_print_devinfo(struct ahd_softc *ahd,
  1334. struct ahd_devinfo *devinfo);
  1335. void ahd_dump_card_state(struct ahd_softc *ahd);
  1336. int ahd_print_register(const ahd_reg_parse_entry_t *table,
  1337. u_int num_entries,
  1338. const char *name,
  1339. u_int address,
  1340. u_int value,
  1341. u_int *cur_column,
  1342. u_int wrap_point);
  1343. #endif /* _AIC79XX_H_ */