aic79xx.h 48 KB

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