aic79xx.h 48 KB

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