aic79xx.h 45 KB

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