aic7xxx_pci.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407
  1. /*
  2. * Product specific probe and attach routines for:
  3. * 3940, 2940, aic7895, aic7890, aic7880,
  4. * aic7870, aic7860 and aic7850 SCSI controllers
  5. *
  6. * Copyright (c) 1994-2001 Justin T. Gibbs.
  7. * Copyright (c) 2000-2001 Adaptec Inc.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. *
  42. * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_pci.c#69 $
  43. *
  44. * $FreeBSD$
  45. */
  46. #ifdef __linux__
  47. #include "aic7xxx_osm.h"
  48. #include "aic7xxx_inline.h"
  49. #include "aic7xxx_93cx6.h"
  50. #else
  51. #include <dev/aic7xxx/aic7xxx_osm.h>
  52. #include <dev/aic7xxx/aic7xxx_inline.h>
  53. #include <dev/aic7xxx/aic7xxx_93cx6.h>
  54. #endif
  55. #include "aic7xxx_pci.h"
  56. static __inline uint64_t
  57. ahc_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
  58. {
  59. uint64_t id;
  60. id = subvendor
  61. | (subdevice << 16)
  62. | ((uint64_t)vendor << 32)
  63. | ((uint64_t)device << 48);
  64. return (id);
  65. }
  66. #define AHC_PCI_IOADDR PCIR_MAPS /* I/O Address */
  67. #define AHC_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */
  68. #define DEVID_9005_TYPE(id) ((id) & 0xF)
  69. #define DEVID_9005_TYPE_HBA 0x0 /* Standard Card */
  70. #define DEVID_9005_TYPE_AAA 0x3 /* RAID Card */
  71. #define DEVID_9005_TYPE_SISL 0x5 /* Container ROMB */
  72. #define DEVID_9005_TYPE_MB 0xF /* On Motherboard */
  73. #define DEVID_9005_MAXRATE(id) (((id) & 0x30) >> 4)
  74. #define DEVID_9005_MAXRATE_U160 0x0
  75. #define DEVID_9005_MAXRATE_ULTRA2 0x1
  76. #define DEVID_9005_MAXRATE_ULTRA 0x2
  77. #define DEVID_9005_MAXRATE_FAST 0x3
  78. #define DEVID_9005_MFUNC(id) (((id) & 0x40) >> 6)
  79. #define DEVID_9005_CLASS(id) (((id) & 0xFF00) >> 8)
  80. #define DEVID_9005_CLASS_SPI 0x0 /* Parallel SCSI */
  81. #define SUBID_9005_TYPE(id) ((id) & 0xF)
  82. #define SUBID_9005_TYPE_MB 0xF /* On Motherboard */
  83. #define SUBID_9005_TYPE_CARD 0x0 /* Standard Card */
  84. #define SUBID_9005_TYPE_LCCARD 0x1 /* Low Cost Card */
  85. #define SUBID_9005_TYPE_RAID 0x3 /* Combined with Raid */
  86. #define SUBID_9005_TYPE_KNOWN(id) \
  87. ((((id) & 0xF) == SUBID_9005_TYPE_MB) \
  88. || (((id) & 0xF) == SUBID_9005_TYPE_CARD) \
  89. || (((id) & 0xF) == SUBID_9005_TYPE_LCCARD) \
  90. || (((id) & 0xF) == SUBID_9005_TYPE_RAID))
  91. #define SUBID_9005_MAXRATE(id) (((id) & 0x30) >> 4)
  92. #define SUBID_9005_MAXRATE_ULTRA2 0x0
  93. #define SUBID_9005_MAXRATE_ULTRA 0x1
  94. #define SUBID_9005_MAXRATE_U160 0x2
  95. #define SUBID_9005_MAXRATE_RESERVED 0x3
  96. #define SUBID_9005_SEEPTYPE(id) \
  97. ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
  98. ? ((id) & 0xC0) >> 6 \
  99. : ((id) & 0x300) >> 8)
  100. #define SUBID_9005_SEEPTYPE_NONE 0x0
  101. #define SUBID_9005_SEEPTYPE_1K 0x1
  102. #define SUBID_9005_SEEPTYPE_2K_4K 0x2
  103. #define SUBID_9005_SEEPTYPE_RESERVED 0x3
  104. #define SUBID_9005_AUTOTERM(id) \
  105. ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
  106. ? (((id) & 0x400) >> 10) == 0 \
  107. : (((id) & 0x40) >> 6) == 0)
  108. #define SUBID_9005_NUMCHAN(id) \
  109. ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
  110. ? ((id) & 0x300) >> 8 \
  111. : ((id) & 0xC00) >> 10)
  112. #define SUBID_9005_LEGACYCONN(id) \
  113. ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
  114. ? 0 \
  115. : ((id) & 0x80) >> 7)
  116. #define SUBID_9005_MFUNCENB(id) \
  117. ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
  118. ? ((id) & 0x800) >> 11 \
  119. : ((id) & 0x1000) >> 12)
  120. /*
  121. * Informational only. Should use chip register to be
  122. * certain, but may be use in identification strings.
  123. */
  124. #define SUBID_9005_CARD_SCSIWIDTH_MASK 0x2000
  125. #define SUBID_9005_CARD_PCIWIDTH_MASK 0x4000
  126. #define SUBID_9005_CARD_SEDIFF_MASK 0x8000
  127. static ahc_device_setup_t ahc_aic785X_setup;
  128. static ahc_device_setup_t ahc_aic7860_setup;
  129. static ahc_device_setup_t ahc_apa1480_setup;
  130. static ahc_device_setup_t ahc_aic7870_setup;
  131. static ahc_device_setup_t ahc_aha394X_setup;
  132. static ahc_device_setup_t ahc_aha494X_setup;
  133. static ahc_device_setup_t ahc_aha398X_setup;
  134. static ahc_device_setup_t ahc_aic7880_setup;
  135. static ahc_device_setup_t ahc_aha2940Pro_setup;
  136. static ahc_device_setup_t ahc_aha394XU_setup;
  137. static ahc_device_setup_t ahc_aha398XU_setup;
  138. static ahc_device_setup_t ahc_aic7890_setup;
  139. static ahc_device_setup_t ahc_aic7892_setup;
  140. static ahc_device_setup_t ahc_aic7895_setup;
  141. static ahc_device_setup_t ahc_aic7896_setup;
  142. static ahc_device_setup_t ahc_aic7899_setup;
  143. static ahc_device_setup_t ahc_aha29160C_setup;
  144. static ahc_device_setup_t ahc_raid_setup;
  145. static ahc_device_setup_t ahc_aha394XX_setup;
  146. static ahc_device_setup_t ahc_aha494XX_setup;
  147. static ahc_device_setup_t ahc_aha398XX_setup;
  148. struct ahc_pci_identity ahc_pci_ident_table [] =
  149. {
  150. /* aic7850 based controllers */
  151. {
  152. ID_AHA_2902_04_10_15_20C_30C,
  153. ID_ALL_MASK,
  154. "Adaptec 2902/04/10/15/20C/30C SCSI adapter",
  155. ahc_aic785X_setup
  156. },
  157. /* aic7860 based controllers */
  158. {
  159. ID_AHA_2930CU,
  160. ID_ALL_MASK,
  161. "Adaptec 2930CU SCSI adapter",
  162. ahc_aic7860_setup
  163. },
  164. {
  165. ID_AHA_1480A & ID_DEV_VENDOR_MASK,
  166. ID_DEV_VENDOR_MASK,
  167. "Adaptec 1480A Ultra SCSI adapter",
  168. ahc_apa1480_setup
  169. },
  170. {
  171. ID_AHA_2940AU_0 & ID_DEV_VENDOR_MASK,
  172. ID_DEV_VENDOR_MASK,
  173. "Adaptec 2940A Ultra SCSI adapter",
  174. ahc_aic7860_setup
  175. },
  176. {
  177. ID_AHA_2940AU_CN & ID_DEV_VENDOR_MASK,
  178. ID_DEV_VENDOR_MASK,
  179. "Adaptec 2940A/CN Ultra SCSI adapter",
  180. ahc_aic7860_setup
  181. },
  182. {
  183. ID_AHA_2930C_VAR & ID_DEV_VENDOR_MASK,
  184. ID_DEV_VENDOR_MASK,
  185. "Adaptec 2930C Ultra SCSI adapter (VAR)",
  186. ahc_aic7860_setup
  187. },
  188. /* aic7870 based controllers */
  189. {
  190. ID_AHA_2940,
  191. ID_ALL_MASK,
  192. "Adaptec 2940 SCSI adapter",
  193. ahc_aic7870_setup
  194. },
  195. {
  196. ID_AHA_3940,
  197. ID_ALL_MASK,
  198. "Adaptec 3940 SCSI adapter",
  199. ahc_aha394X_setup
  200. },
  201. {
  202. ID_AHA_398X,
  203. ID_ALL_MASK,
  204. "Adaptec 398X SCSI RAID adapter",
  205. ahc_aha398X_setup
  206. },
  207. {
  208. ID_AHA_2944,
  209. ID_ALL_MASK,
  210. "Adaptec 2944 SCSI adapter",
  211. ahc_aic7870_setup
  212. },
  213. {
  214. ID_AHA_3944,
  215. ID_ALL_MASK,
  216. "Adaptec 3944 SCSI adapter",
  217. ahc_aha394X_setup
  218. },
  219. {
  220. ID_AHA_4944,
  221. ID_ALL_MASK,
  222. "Adaptec 4944 SCSI adapter",
  223. ahc_aha494X_setup
  224. },
  225. /* aic7880 based controllers */
  226. {
  227. ID_AHA_2940U & ID_DEV_VENDOR_MASK,
  228. ID_DEV_VENDOR_MASK,
  229. "Adaptec 2940 Ultra SCSI adapter",
  230. ahc_aic7880_setup
  231. },
  232. {
  233. ID_AHA_3940U & ID_DEV_VENDOR_MASK,
  234. ID_DEV_VENDOR_MASK,
  235. "Adaptec 3940 Ultra SCSI adapter",
  236. ahc_aha394XU_setup
  237. },
  238. {
  239. ID_AHA_2944U & ID_DEV_VENDOR_MASK,
  240. ID_DEV_VENDOR_MASK,
  241. "Adaptec 2944 Ultra SCSI adapter",
  242. ahc_aic7880_setup
  243. },
  244. {
  245. ID_AHA_3944U & ID_DEV_VENDOR_MASK,
  246. ID_DEV_VENDOR_MASK,
  247. "Adaptec 3944 Ultra SCSI adapter",
  248. ahc_aha394XU_setup
  249. },
  250. {
  251. ID_AHA_398XU & ID_DEV_VENDOR_MASK,
  252. ID_DEV_VENDOR_MASK,
  253. "Adaptec 398X Ultra SCSI RAID adapter",
  254. ahc_aha398XU_setup
  255. },
  256. {
  257. /*
  258. * XXX Don't know the slot numbers
  259. * so we can't identify channels
  260. */
  261. ID_AHA_4944U & ID_DEV_VENDOR_MASK,
  262. ID_DEV_VENDOR_MASK,
  263. "Adaptec 4944 Ultra SCSI adapter",
  264. ahc_aic7880_setup
  265. },
  266. {
  267. ID_AHA_2930U & ID_DEV_VENDOR_MASK,
  268. ID_DEV_VENDOR_MASK,
  269. "Adaptec 2930 Ultra SCSI adapter",
  270. ahc_aic7880_setup
  271. },
  272. {
  273. ID_AHA_2940U_PRO & ID_DEV_VENDOR_MASK,
  274. ID_DEV_VENDOR_MASK,
  275. "Adaptec 2940 Pro Ultra SCSI adapter",
  276. ahc_aha2940Pro_setup
  277. },
  278. {
  279. ID_AHA_2940U_CN & ID_DEV_VENDOR_MASK,
  280. ID_DEV_VENDOR_MASK,
  281. "Adaptec 2940/CN Ultra SCSI adapter",
  282. ahc_aic7880_setup
  283. },
  284. /* Ignore all SISL (AAC on MB) based controllers. */
  285. {
  286. ID_9005_SISL_ID,
  287. ID_9005_SISL_MASK,
  288. NULL,
  289. NULL
  290. },
  291. /* aic7890 based controllers */
  292. {
  293. ID_AHA_2930U2,
  294. ID_ALL_MASK,
  295. "Adaptec 2930 Ultra2 SCSI adapter",
  296. ahc_aic7890_setup
  297. },
  298. {
  299. ID_AHA_2940U2B,
  300. ID_ALL_MASK,
  301. "Adaptec 2940B Ultra2 SCSI adapter",
  302. ahc_aic7890_setup
  303. },
  304. {
  305. ID_AHA_2940U2_OEM,
  306. ID_ALL_MASK,
  307. "Adaptec 2940 Ultra2 SCSI adapter (OEM)",
  308. ahc_aic7890_setup
  309. },
  310. {
  311. ID_AHA_2940U2,
  312. ID_ALL_MASK,
  313. "Adaptec 2940 Ultra2 SCSI adapter",
  314. ahc_aic7890_setup
  315. },
  316. {
  317. ID_AHA_2950U2B,
  318. ID_ALL_MASK,
  319. "Adaptec 2950 Ultra2 SCSI adapter",
  320. ahc_aic7890_setup
  321. },
  322. {
  323. ID_AIC7890_ARO,
  324. ID_ALL_MASK,
  325. "Adaptec aic7890/91 Ultra2 SCSI adapter (ARO)",
  326. ahc_aic7890_setup
  327. },
  328. {
  329. ID_AAA_131U2,
  330. ID_ALL_MASK,
  331. "Adaptec AAA-131 Ultra2 RAID adapter",
  332. ahc_aic7890_setup
  333. },
  334. /* aic7892 based controllers */
  335. {
  336. ID_AHA_29160,
  337. ID_ALL_MASK,
  338. "Adaptec 29160 Ultra160 SCSI adapter",
  339. ahc_aic7892_setup
  340. },
  341. {
  342. ID_AHA_29160_CPQ,
  343. ID_ALL_MASK,
  344. "Adaptec (Compaq OEM) 29160 Ultra160 SCSI adapter",
  345. ahc_aic7892_setup
  346. },
  347. {
  348. ID_AHA_29160N,
  349. ID_ALL_MASK,
  350. "Adaptec 29160N Ultra160 SCSI adapter",
  351. ahc_aic7892_setup
  352. },
  353. {
  354. ID_AHA_29160C,
  355. ID_ALL_MASK,
  356. "Adaptec 29160C Ultra160 SCSI adapter",
  357. ahc_aha29160C_setup
  358. },
  359. {
  360. ID_AHA_29160B,
  361. ID_ALL_MASK,
  362. "Adaptec 29160B Ultra160 SCSI adapter",
  363. ahc_aic7892_setup
  364. },
  365. {
  366. ID_AHA_19160B,
  367. ID_ALL_MASK,
  368. "Adaptec 19160B Ultra160 SCSI adapter",
  369. ahc_aic7892_setup
  370. },
  371. {
  372. ID_AIC7892_ARO,
  373. ID_ALL_MASK,
  374. "Adaptec aic7892 Ultra160 SCSI adapter (ARO)",
  375. ahc_aic7892_setup
  376. },
  377. /* aic7895 based controllers */
  378. {
  379. ID_AHA_2940U_DUAL,
  380. ID_ALL_MASK,
  381. "Adaptec 2940/DUAL Ultra SCSI adapter",
  382. ahc_aic7895_setup
  383. },
  384. {
  385. ID_AHA_3940AU,
  386. ID_ALL_MASK,
  387. "Adaptec 3940A Ultra SCSI adapter",
  388. ahc_aic7895_setup
  389. },
  390. {
  391. ID_AHA_3944AU,
  392. ID_ALL_MASK,
  393. "Adaptec 3944A Ultra SCSI adapter",
  394. ahc_aic7895_setup
  395. },
  396. {
  397. ID_AIC7895_ARO,
  398. ID_AIC7895_ARO_MASK,
  399. "Adaptec aic7895 Ultra SCSI adapter (ARO)",
  400. ahc_aic7895_setup
  401. },
  402. /* aic7896/97 based controllers */
  403. {
  404. ID_AHA_3950U2B_0,
  405. ID_ALL_MASK,
  406. "Adaptec 3950B Ultra2 SCSI adapter",
  407. ahc_aic7896_setup
  408. },
  409. {
  410. ID_AHA_3950U2B_1,
  411. ID_ALL_MASK,
  412. "Adaptec 3950B Ultra2 SCSI adapter",
  413. ahc_aic7896_setup
  414. },
  415. {
  416. ID_AHA_3950U2D_0,
  417. ID_ALL_MASK,
  418. "Adaptec 3950D Ultra2 SCSI adapter",
  419. ahc_aic7896_setup
  420. },
  421. {
  422. ID_AHA_3950U2D_1,
  423. ID_ALL_MASK,
  424. "Adaptec 3950D Ultra2 SCSI adapter",
  425. ahc_aic7896_setup
  426. },
  427. {
  428. ID_AIC7896_ARO,
  429. ID_ALL_MASK,
  430. "Adaptec aic7896/97 Ultra2 SCSI adapter (ARO)",
  431. ahc_aic7896_setup
  432. },
  433. /* aic7899 based controllers */
  434. {
  435. ID_AHA_3960D,
  436. ID_ALL_MASK,
  437. "Adaptec 3960D Ultra160 SCSI adapter",
  438. ahc_aic7899_setup
  439. },
  440. {
  441. ID_AHA_3960D_CPQ,
  442. ID_ALL_MASK,
  443. "Adaptec (Compaq OEM) 3960D Ultra160 SCSI adapter",
  444. ahc_aic7899_setup
  445. },
  446. {
  447. ID_AIC7899_ARO,
  448. ID_ALL_MASK,
  449. "Adaptec aic7899 Ultra160 SCSI adapter (ARO)",
  450. ahc_aic7899_setup
  451. },
  452. /* Generic chip probes for devices we don't know 'exactly' */
  453. {
  454. ID_AIC7850 & ID_DEV_VENDOR_MASK,
  455. ID_DEV_VENDOR_MASK,
  456. "Adaptec aic7850 SCSI adapter",
  457. ahc_aic785X_setup
  458. },
  459. {
  460. ID_AIC7855 & ID_DEV_VENDOR_MASK,
  461. ID_DEV_VENDOR_MASK,
  462. "Adaptec aic7855 SCSI adapter",
  463. ahc_aic785X_setup
  464. },
  465. {
  466. ID_AIC7859 & ID_DEV_VENDOR_MASK,
  467. ID_DEV_VENDOR_MASK,
  468. "Adaptec aic7859 SCSI adapter",
  469. ahc_aic7860_setup
  470. },
  471. {
  472. ID_AIC7860 & ID_DEV_VENDOR_MASK,
  473. ID_DEV_VENDOR_MASK,
  474. "Adaptec aic7860 Ultra SCSI adapter",
  475. ahc_aic7860_setup
  476. },
  477. {
  478. ID_AIC7870 & ID_DEV_VENDOR_MASK,
  479. ID_DEV_VENDOR_MASK,
  480. "Adaptec aic7870 SCSI adapter",
  481. ahc_aic7870_setup
  482. },
  483. {
  484. ID_AIC7880 & ID_DEV_VENDOR_MASK,
  485. ID_DEV_VENDOR_MASK,
  486. "Adaptec aic7880 Ultra SCSI adapter",
  487. ahc_aic7880_setup
  488. },
  489. {
  490. ID_AIC7890 & ID_9005_GENERIC_MASK,
  491. ID_9005_GENERIC_MASK,
  492. "Adaptec aic7890/91 Ultra2 SCSI adapter",
  493. ahc_aic7890_setup
  494. },
  495. {
  496. ID_AIC7892 & ID_9005_GENERIC_MASK,
  497. ID_9005_GENERIC_MASK,
  498. "Adaptec aic7892 Ultra160 SCSI adapter",
  499. ahc_aic7892_setup
  500. },
  501. {
  502. ID_AIC7895 & ID_DEV_VENDOR_MASK,
  503. ID_DEV_VENDOR_MASK,
  504. "Adaptec aic7895 Ultra SCSI adapter",
  505. ahc_aic7895_setup
  506. },
  507. {
  508. ID_AIC7896 & ID_9005_GENERIC_MASK,
  509. ID_9005_GENERIC_MASK,
  510. "Adaptec aic7896/97 Ultra2 SCSI adapter",
  511. ahc_aic7896_setup
  512. },
  513. {
  514. ID_AIC7899 & ID_9005_GENERIC_MASK,
  515. ID_9005_GENERIC_MASK,
  516. "Adaptec aic7899 Ultra160 SCSI adapter",
  517. ahc_aic7899_setup
  518. },
  519. {
  520. ID_AIC7810 & ID_DEV_VENDOR_MASK,
  521. ID_DEV_VENDOR_MASK,
  522. "Adaptec aic7810 RAID memory controller",
  523. ahc_raid_setup
  524. },
  525. {
  526. ID_AIC7815 & ID_DEV_VENDOR_MASK,
  527. ID_DEV_VENDOR_MASK,
  528. "Adaptec aic7815 RAID memory controller",
  529. ahc_raid_setup
  530. }
  531. };
  532. const u_int ahc_num_pci_devs = NUM_ELEMENTS(ahc_pci_ident_table);
  533. #define AHC_394X_SLOT_CHANNEL_A 4
  534. #define AHC_394X_SLOT_CHANNEL_B 5
  535. #define AHC_398X_SLOT_CHANNEL_A 4
  536. #define AHC_398X_SLOT_CHANNEL_B 8
  537. #define AHC_398X_SLOT_CHANNEL_C 12
  538. #define AHC_494X_SLOT_CHANNEL_A 4
  539. #define AHC_494X_SLOT_CHANNEL_B 5
  540. #define AHC_494X_SLOT_CHANNEL_C 6
  541. #define AHC_494X_SLOT_CHANNEL_D 7
  542. #define DEVCONFIG 0x40
  543. #define PCIERRGENDIS 0x80000000ul
  544. #define SCBSIZE32 0x00010000ul /* aic789X only */
  545. #define REXTVALID 0x00001000ul /* ultra cards only */
  546. #define MPORTMODE 0x00000400ul /* aic7870+ only */
  547. #define RAMPSM 0x00000200ul /* aic7870+ only */
  548. #define VOLSENSE 0x00000100ul
  549. #define PCI64BIT 0x00000080ul /* 64Bit PCI bus (Ultra2 Only)*/
  550. #define SCBRAMSEL 0x00000080ul
  551. #define MRDCEN 0x00000040ul
  552. #define EXTSCBTIME 0x00000020ul /* aic7870 only */
  553. #define EXTSCBPEN 0x00000010ul /* aic7870 only */
  554. #define BERREN 0x00000008ul
  555. #define DACEN 0x00000004ul
  556. #define STPWLEVEL 0x00000002ul
  557. #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
  558. #define CSIZE_LATTIME 0x0c
  559. #define CACHESIZE 0x0000003ful /* only 5 bits */
  560. #define LATTIME 0x0000ff00ul
  561. /* PCI STATUS definitions */
  562. #define DPE 0x80
  563. #define SSE 0x40
  564. #define RMA 0x20
  565. #define RTA 0x10
  566. #define STA 0x08
  567. #define DPR 0x01
  568. static int ahc_9005_subdevinfo_valid(uint16_t vendor, uint16_t device,
  569. uint16_t subvendor, uint16_t subdevice);
  570. static int ahc_ext_scbram_present(struct ahc_softc *ahc);
  571. static void ahc_scbram_config(struct ahc_softc *ahc, int enable,
  572. int pcheck, int fast, int large);
  573. static void ahc_probe_ext_scbram(struct ahc_softc *ahc);
  574. static void check_extport(struct ahc_softc *ahc, u_int *sxfrctl1);
  575. static void ahc_parse_pci_eeprom(struct ahc_softc *ahc,
  576. struct seeprom_config *sc);
  577. static void configure_termination(struct ahc_softc *ahc,
  578. struct seeprom_descriptor *sd,
  579. u_int adapter_control,
  580. u_int *sxfrctl1);
  581. static void ahc_new_term_detect(struct ahc_softc *ahc,
  582. int *enableSEC_low,
  583. int *enableSEC_high,
  584. int *enablePRI_low,
  585. int *enablePRI_high,
  586. int *eeprom_present);
  587. static void aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
  588. int *internal68_present,
  589. int *externalcable_present,
  590. int *eeprom_present);
  591. static void aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
  592. int *externalcable_present,
  593. int *eeprom_present);
  594. static void write_brdctl(struct ahc_softc *ahc, uint8_t value);
  595. static uint8_t read_brdctl(struct ahc_softc *ahc);
  596. static void ahc_pci_intr(struct ahc_softc *ahc);
  597. static int ahc_pci_chip_init(struct ahc_softc *ahc);
  598. static int ahc_pci_suspend(struct ahc_softc *ahc);
  599. static int ahc_pci_resume(struct ahc_softc *ahc);
  600. static int
  601. ahc_9005_subdevinfo_valid(uint16_t device, uint16_t vendor,
  602. uint16_t subdevice, uint16_t subvendor)
  603. {
  604. int result;
  605. /* Default to invalid. */
  606. result = 0;
  607. if (vendor == 0x9005
  608. && subvendor == 0x9005
  609. && subdevice != device
  610. && SUBID_9005_TYPE_KNOWN(subdevice) != 0) {
  611. switch (SUBID_9005_TYPE(subdevice)) {
  612. case SUBID_9005_TYPE_MB:
  613. break;
  614. case SUBID_9005_TYPE_CARD:
  615. case SUBID_9005_TYPE_LCCARD:
  616. /*
  617. * Currently only trust Adaptec cards to
  618. * get the sub device info correct.
  619. */
  620. if (DEVID_9005_TYPE(device) == DEVID_9005_TYPE_HBA)
  621. result = 1;
  622. break;
  623. case SUBID_9005_TYPE_RAID:
  624. break;
  625. default:
  626. break;
  627. }
  628. }
  629. return (result);
  630. }
  631. struct ahc_pci_identity *
  632. ahc_find_pci_device(ahc_dev_softc_t pci)
  633. {
  634. uint64_t full_id;
  635. uint16_t device;
  636. uint16_t vendor;
  637. uint16_t subdevice;
  638. uint16_t subvendor;
  639. struct ahc_pci_identity *entry;
  640. u_int i;
  641. vendor = ahc_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
  642. device = ahc_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
  643. subvendor = ahc_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
  644. subdevice = ahc_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
  645. full_id = ahc_compose_id(device, vendor, subdevice, subvendor);
  646. /*
  647. * If the second function is not hooked up, ignore it.
  648. * Unfortunately, not all MB vendors implement the
  649. * subdevice ID as per the Adaptec spec, so do our best
  650. * to sanity check it prior to accepting the subdevice
  651. * ID as valid.
  652. */
  653. if (ahc_get_pci_function(pci) > 0
  654. && ahc_9005_subdevinfo_valid(vendor, device, subvendor, subdevice)
  655. && SUBID_9005_MFUNCENB(subdevice) == 0)
  656. return (NULL);
  657. for (i = 0; i < ahc_num_pci_devs; i++) {
  658. entry = &ahc_pci_ident_table[i];
  659. if (entry->full_id == (full_id & entry->id_mask)) {
  660. /* Honor exclusion entries. */
  661. if (entry->name == NULL)
  662. return (NULL);
  663. return (entry);
  664. }
  665. }
  666. return (NULL);
  667. }
  668. int
  669. ahc_pci_config(struct ahc_softc *ahc, struct ahc_pci_identity *entry)
  670. {
  671. u_long l;
  672. u_int command;
  673. u_int our_id;
  674. u_int sxfrctl1;
  675. u_int scsiseq;
  676. u_int dscommand0;
  677. uint32_t devconfig;
  678. int error;
  679. uint8_t sblkctl;
  680. our_id = 0;
  681. error = entry->setup(ahc);
  682. if (error != 0)
  683. return (error);
  684. ahc->chip |= AHC_PCI;
  685. ahc->description = entry->name;
  686. pci_set_power_state(ahc->dev_softc, AHC_POWER_STATE_D0);
  687. error = ahc_pci_map_registers(ahc);
  688. if (error != 0)
  689. return (error);
  690. /*
  691. * Before we continue probing the card, ensure that
  692. * its interrupts are *disabled*. We don't want
  693. * a misstep to hang the machine in an interrupt
  694. * storm.
  695. */
  696. ahc_intr_enable(ahc, FALSE);
  697. devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
  698. /*
  699. * If we need to support high memory, enable dual
  700. * address cycles. This bit must be set to enable
  701. * high address bit generation even if we are on a
  702. * 64bit bus (PCI64BIT set in devconfig).
  703. */
  704. if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
  705. if (bootverbose)
  706. printf("%s: Enabling 39Bit Addressing\n",
  707. ahc_name(ahc));
  708. devconfig |= DACEN;
  709. }
  710. /* Ensure that pci error generation, a test feature, is disabled. */
  711. devconfig |= PCIERRGENDIS;
  712. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
  713. /* Ensure busmastering is enabled */
  714. command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
  715. command |= PCIM_CMD_BUSMASTEREN;
  716. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
  717. /* On all PCI adapters, we allow SCB paging */
  718. ahc->flags |= AHC_PAGESCBS;
  719. error = ahc_softc_init(ahc);
  720. if (error != 0)
  721. return (error);
  722. /*
  723. * Disable PCI parity error checking. Users typically
  724. * do this to work around broken PCI chipsets that get
  725. * the parity timing wrong and thus generate lots of spurious
  726. * errors. The chip only allows us to disable *all* parity
  727. * error reporting when doing this, so CIO bus, scb ram, and
  728. * scratch ram parity errors will be ignored too.
  729. */
  730. if ((ahc->flags & AHC_DISABLE_PCI_PERR) != 0)
  731. ahc->seqctl |= FAILDIS;
  732. ahc->bus_intr = ahc_pci_intr;
  733. ahc->bus_chip_init = ahc_pci_chip_init;
  734. ahc->bus_suspend = ahc_pci_suspend;
  735. ahc->bus_resume = ahc_pci_resume;
  736. /* Remeber how the card was setup in case there is no SEEPROM */
  737. if ((ahc_inb(ahc, HCNTRL) & POWRDN) == 0) {
  738. ahc_pause(ahc);
  739. if ((ahc->features & AHC_ULTRA2) != 0)
  740. our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
  741. else
  742. our_id = ahc_inb(ahc, SCSIID) & OID;
  743. sxfrctl1 = ahc_inb(ahc, SXFRCTL1) & STPWEN;
  744. scsiseq = ahc_inb(ahc, SCSISEQ);
  745. } else {
  746. sxfrctl1 = STPWEN;
  747. our_id = 7;
  748. scsiseq = 0;
  749. }
  750. error = ahc_reset(ahc, /*reinit*/FALSE);
  751. if (error != 0)
  752. return (ENXIO);
  753. if ((ahc->features & AHC_DT) != 0) {
  754. u_int sfunct;
  755. /* Perform ALT-Mode Setup */
  756. sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
  757. ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
  758. ahc_outb(ahc, OPTIONMODE,
  759. OPTIONMODE_DEFAULTS|AUTOACKEN|BUSFREEREV|EXPPHASEDIS);
  760. ahc_outb(ahc, SFUNCT, sfunct);
  761. /* Normal mode setup */
  762. ahc_outb(ahc, CRCCONTROL1, CRCVALCHKEN|CRCENDCHKEN|CRCREQCHKEN
  763. |TARGCRCENDEN);
  764. }
  765. dscommand0 = ahc_inb(ahc, DSCOMMAND0);
  766. dscommand0 |= MPARCKEN|CACHETHEN;
  767. if ((ahc->features & AHC_ULTRA2) != 0) {
  768. /*
  769. * DPARCKEN doesn't work correctly on
  770. * some MBs so don't use it.
  771. */
  772. dscommand0 &= ~DPARCKEN;
  773. }
  774. /*
  775. * Handle chips that must have cache line
  776. * streaming (dis/en)abled.
  777. */
  778. if ((ahc->bugs & AHC_CACHETHEN_DIS_BUG) != 0)
  779. dscommand0 |= CACHETHEN;
  780. if ((ahc->bugs & AHC_CACHETHEN_BUG) != 0)
  781. dscommand0 &= ~CACHETHEN;
  782. ahc_outb(ahc, DSCOMMAND0, dscommand0);
  783. ahc->pci_cachesize =
  784. ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME,
  785. /*bytes*/1) & CACHESIZE;
  786. ahc->pci_cachesize *= 4;
  787. if ((ahc->bugs & AHC_PCI_2_1_RETRY_BUG) != 0
  788. && ahc->pci_cachesize == 4) {
  789. ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME,
  790. 0, /*bytes*/1);
  791. ahc->pci_cachesize = 0;
  792. }
  793. /*
  794. * We cannot perform ULTRA speeds without the presense
  795. * of the external precision resistor.
  796. */
  797. if ((ahc->features & AHC_ULTRA) != 0) {
  798. uint32_t devconfig;
  799. devconfig = ahc_pci_read_config(ahc->dev_softc,
  800. DEVCONFIG, /*bytes*/4);
  801. if ((devconfig & REXTVALID) == 0)
  802. ahc->features &= ~AHC_ULTRA;
  803. }
  804. /* See if we have a SEEPROM and perform auto-term */
  805. check_extport(ahc, &sxfrctl1);
  806. /*
  807. * Take the LED out of diagnostic mode
  808. */
  809. sblkctl = ahc_inb(ahc, SBLKCTL);
  810. ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
  811. if ((ahc->features & AHC_ULTRA2) != 0) {
  812. ahc_outb(ahc, DFF_THRSH, RD_DFTHRSH_MAX|WR_DFTHRSH_MAX);
  813. } else {
  814. ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
  815. }
  816. if (ahc->flags & AHC_USEDEFAULTS) {
  817. /*
  818. * PCI Adapter default setup
  819. * Should only be used if the adapter does not have
  820. * a SEEPROM.
  821. */
  822. /* See if someone else set us up already */
  823. if ((ahc->flags & AHC_NO_BIOS_INIT) == 0
  824. && scsiseq != 0) {
  825. printf("%s: Using left over BIOS settings\n",
  826. ahc_name(ahc));
  827. ahc->flags &= ~AHC_USEDEFAULTS;
  828. ahc->flags |= AHC_BIOS_ENABLED;
  829. } else {
  830. /*
  831. * Assume only one connector and always turn
  832. * on termination.
  833. */
  834. our_id = 0x07;
  835. sxfrctl1 = STPWEN;
  836. }
  837. ahc_outb(ahc, SCSICONF, our_id|ENSPCHK|RESET_SCSI);
  838. ahc->our_id = our_id;
  839. }
  840. /*
  841. * Take a look to see if we have external SRAM.
  842. * We currently do not attempt to use SRAM that is
  843. * shared among multiple controllers.
  844. */
  845. ahc_probe_ext_scbram(ahc);
  846. /*
  847. * Record our termination setting for the
  848. * generic initialization routine.
  849. */
  850. if ((sxfrctl1 & STPWEN) != 0)
  851. ahc->flags |= AHC_TERM_ENB_A;
  852. /*
  853. * Save chip register configuration data for chip resets
  854. * that occur during runtime and resume events.
  855. */
  856. ahc->bus_softc.pci_softc.devconfig =
  857. ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
  858. ahc->bus_softc.pci_softc.command =
  859. ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1);
  860. ahc->bus_softc.pci_softc.csize_lattime =
  861. ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1);
  862. ahc->bus_softc.pci_softc.dscommand0 = ahc_inb(ahc, DSCOMMAND0);
  863. ahc->bus_softc.pci_softc.dspcistatus = ahc_inb(ahc, DSPCISTATUS);
  864. if ((ahc->features & AHC_DT) != 0) {
  865. u_int sfunct;
  866. sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
  867. ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
  868. ahc->bus_softc.pci_softc.optionmode = ahc_inb(ahc, OPTIONMODE);
  869. ahc->bus_softc.pci_softc.targcrccnt = ahc_inw(ahc, TARGCRCCNT);
  870. ahc_outb(ahc, SFUNCT, sfunct);
  871. ahc->bus_softc.pci_softc.crccontrol1 =
  872. ahc_inb(ahc, CRCCONTROL1);
  873. }
  874. if ((ahc->features & AHC_MULTI_FUNC) != 0)
  875. ahc->bus_softc.pci_softc.scbbaddr = ahc_inb(ahc, SCBBADDR);
  876. if ((ahc->features & AHC_ULTRA2) != 0)
  877. ahc->bus_softc.pci_softc.dff_thrsh = ahc_inb(ahc, DFF_THRSH);
  878. /* Core initialization */
  879. error = ahc_init(ahc);
  880. if (error != 0)
  881. return (error);
  882. /*
  883. * Allow interrupts now that we are completely setup.
  884. */
  885. error = ahc_pci_map_int(ahc);
  886. if (error != 0)
  887. return (error);
  888. ahc_list_lock(&l);
  889. /*
  890. * Link this softc in with all other ahc instances.
  891. */
  892. ahc_softc_insert(ahc);
  893. ahc_list_unlock(&l);
  894. return (0);
  895. }
  896. /*
  897. * Test for the presense of external sram in an
  898. * "unshared" configuration.
  899. */
  900. static int
  901. ahc_ext_scbram_present(struct ahc_softc *ahc)
  902. {
  903. u_int chip;
  904. int ramps;
  905. int single_user;
  906. uint32_t devconfig;
  907. chip = ahc->chip & AHC_CHIPID_MASK;
  908. devconfig = ahc_pci_read_config(ahc->dev_softc,
  909. DEVCONFIG, /*bytes*/4);
  910. single_user = (devconfig & MPORTMODE) != 0;
  911. if ((ahc->features & AHC_ULTRA2) != 0)
  912. ramps = (ahc_inb(ahc, DSCOMMAND0) & RAMPS) != 0;
  913. else if (chip == AHC_AIC7895 || chip == AHC_AIC7895C)
  914. /*
  915. * External SCBRAM arbitration is flakey
  916. * on these chips. Unfortunately this means
  917. * we don't use the extra SCB ram space on the
  918. * 3940AUW.
  919. */
  920. ramps = 0;
  921. else if (chip >= AHC_AIC7870)
  922. ramps = (devconfig & RAMPSM) != 0;
  923. else
  924. ramps = 0;
  925. if (ramps && single_user)
  926. return (1);
  927. return (0);
  928. }
  929. /*
  930. * Enable external scbram.
  931. */
  932. static void
  933. ahc_scbram_config(struct ahc_softc *ahc, int enable, int pcheck,
  934. int fast, int large)
  935. {
  936. uint32_t devconfig;
  937. if (ahc->features & AHC_MULTI_FUNC) {
  938. /*
  939. * Set the SCB Base addr (highest address bit)
  940. * depending on which channel we are.
  941. */
  942. ahc_outb(ahc, SCBBADDR, ahc_get_pci_function(ahc->dev_softc));
  943. }
  944. ahc->flags &= ~AHC_LSCBS_ENABLED;
  945. if (large)
  946. ahc->flags |= AHC_LSCBS_ENABLED;
  947. devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
  948. if ((ahc->features & AHC_ULTRA2) != 0) {
  949. u_int dscommand0;
  950. dscommand0 = ahc_inb(ahc, DSCOMMAND0);
  951. if (enable)
  952. dscommand0 &= ~INTSCBRAMSEL;
  953. else
  954. dscommand0 |= INTSCBRAMSEL;
  955. if (large)
  956. dscommand0 &= ~USCBSIZE32;
  957. else
  958. dscommand0 |= USCBSIZE32;
  959. ahc_outb(ahc, DSCOMMAND0, dscommand0);
  960. } else {
  961. if (fast)
  962. devconfig &= ~EXTSCBTIME;
  963. else
  964. devconfig |= EXTSCBTIME;
  965. if (enable)
  966. devconfig &= ~SCBRAMSEL;
  967. else
  968. devconfig |= SCBRAMSEL;
  969. if (large)
  970. devconfig &= ~SCBSIZE32;
  971. else
  972. devconfig |= SCBSIZE32;
  973. }
  974. if (pcheck)
  975. devconfig |= EXTSCBPEN;
  976. else
  977. devconfig &= ~EXTSCBPEN;
  978. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
  979. }
  980. /*
  981. * Take a look to see if we have external SRAM.
  982. * We currently do not attempt to use SRAM that is
  983. * shared among multiple controllers.
  984. */
  985. static void
  986. ahc_probe_ext_scbram(struct ahc_softc *ahc)
  987. {
  988. int num_scbs;
  989. int test_num_scbs;
  990. int enable;
  991. int pcheck;
  992. int fast;
  993. int large;
  994. enable = FALSE;
  995. pcheck = FALSE;
  996. fast = FALSE;
  997. large = FALSE;
  998. num_scbs = 0;
  999. if (ahc_ext_scbram_present(ahc) == 0)
  1000. goto done;
  1001. /*
  1002. * Probe for the best parameters to use.
  1003. */
  1004. ahc_scbram_config(ahc, /*enable*/TRUE, pcheck, fast, large);
  1005. num_scbs = ahc_probe_scbs(ahc);
  1006. if (num_scbs == 0) {
  1007. /* The SRAM wasn't really present. */
  1008. goto done;
  1009. }
  1010. enable = TRUE;
  1011. /*
  1012. * Clear any outstanding parity error
  1013. * and ensure that parity error reporting
  1014. * is enabled.
  1015. */
  1016. ahc_outb(ahc, SEQCTL, 0);
  1017. ahc_outb(ahc, CLRINT, CLRPARERR);
  1018. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1019. /* Now see if we can do parity */
  1020. ahc_scbram_config(ahc, enable, /*pcheck*/TRUE, fast, large);
  1021. num_scbs = ahc_probe_scbs(ahc);
  1022. if ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
  1023. || (ahc_inb(ahc, ERROR) & MPARERR) == 0)
  1024. pcheck = TRUE;
  1025. /* Clear any resulting parity error */
  1026. ahc_outb(ahc, CLRINT, CLRPARERR);
  1027. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1028. /* Now see if we can do fast timing */
  1029. ahc_scbram_config(ahc, enable, pcheck, /*fast*/TRUE, large);
  1030. test_num_scbs = ahc_probe_scbs(ahc);
  1031. if (test_num_scbs == num_scbs
  1032. && ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
  1033. || (ahc_inb(ahc, ERROR) & MPARERR) == 0))
  1034. fast = TRUE;
  1035. /*
  1036. * See if we can use large SCBs and still maintain
  1037. * the same overall count of SCBs.
  1038. */
  1039. if ((ahc->features & AHC_LARGE_SCBS) != 0) {
  1040. ahc_scbram_config(ahc, enable, pcheck, fast, /*large*/TRUE);
  1041. test_num_scbs = ahc_probe_scbs(ahc);
  1042. if (test_num_scbs >= num_scbs) {
  1043. large = TRUE;
  1044. num_scbs = test_num_scbs;
  1045. if (num_scbs >= 64) {
  1046. /*
  1047. * We have enough space to move the
  1048. * "busy targets table" into SCB space
  1049. * and make it qualify all the way to the
  1050. * lun level.
  1051. */
  1052. ahc->flags |= AHC_SCB_BTT;
  1053. }
  1054. }
  1055. }
  1056. done:
  1057. /*
  1058. * Disable parity error reporting until we
  1059. * can load instruction ram.
  1060. */
  1061. ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
  1062. /* Clear any latched parity error */
  1063. ahc_outb(ahc, CLRINT, CLRPARERR);
  1064. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1065. if (bootverbose && enable) {
  1066. printf("%s: External SRAM, %s access%s, %dbytes/SCB\n",
  1067. ahc_name(ahc), fast ? "fast" : "slow",
  1068. pcheck ? ", parity checking enabled" : "",
  1069. large ? 64 : 32);
  1070. }
  1071. ahc_scbram_config(ahc, enable, pcheck, fast, large);
  1072. }
  1073. /*
  1074. * Perform some simple tests that should catch situations where
  1075. * our registers are invalidly mapped.
  1076. */
  1077. int
  1078. ahc_pci_test_register_access(struct ahc_softc *ahc)
  1079. {
  1080. int error;
  1081. u_int status1;
  1082. uint32_t cmd;
  1083. uint8_t hcntrl;
  1084. error = EIO;
  1085. /*
  1086. * Enable PCI error interrupt status, but suppress NMIs
  1087. * generated by SERR raised due to target aborts.
  1088. */
  1089. cmd = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
  1090. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
  1091. cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
  1092. /*
  1093. * First a simple test to see if any
  1094. * registers can be read. Reading
  1095. * HCNTRL has no side effects and has
  1096. * at least one bit that is guaranteed to
  1097. * be zero so it is a good register to
  1098. * use for this test.
  1099. */
  1100. hcntrl = ahc_inb(ahc, HCNTRL);
  1101. if (hcntrl == 0xFF)
  1102. goto fail;
  1103. /*
  1104. * Next create a situation where write combining
  1105. * or read prefetching could be initiated by the
  1106. * CPU or host bridge. Our device does not support
  1107. * either, so look for data corruption and/or flagged
  1108. * PCI errors. First pause without causing another
  1109. * chip reset.
  1110. */
  1111. hcntrl &= ~CHIPRST;
  1112. ahc_outb(ahc, HCNTRL, hcntrl|PAUSE);
  1113. while (ahc_is_paused(ahc) == 0)
  1114. ;
  1115. /* Clear any PCI errors that occurred before our driver attached. */
  1116. status1 = ahc_pci_read_config(ahc->dev_softc,
  1117. PCIR_STATUS + 1, /*bytes*/1);
  1118. ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
  1119. status1, /*bytes*/1);
  1120. ahc_outb(ahc, CLRINT, CLRPARERR);
  1121. ahc_outb(ahc, SEQCTL, PERRORDIS);
  1122. ahc_outb(ahc, SCBPTR, 0);
  1123. ahc_outl(ahc, SCB_BASE, 0x5aa555aa);
  1124. if (ahc_inl(ahc, SCB_BASE) != 0x5aa555aa)
  1125. goto fail;
  1126. status1 = ahc_pci_read_config(ahc->dev_softc,
  1127. PCIR_STATUS + 1, /*bytes*/1);
  1128. if ((status1 & STA) != 0)
  1129. goto fail;
  1130. error = 0;
  1131. fail:
  1132. /* Silently clear any latched errors. */
  1133. status1 = ahc_pci_read_config(ahc->dev_softc,
  1134. PCIR_STATUS + 1, /*bytes*/1);
  1135. ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
  1136. status1, /*bytes*/1);
  1137. ahc_outb(ahc, CLRINT, CLRPARERR);
  1138. ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
  1139. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
  1140. return (error);
  1141. }
  1142. /*
  1143. * Check the external port logic for a serial eeprom
  1144. * and termination/cable detection contrls.
  1145. */
  1146. static void
  1147. check_extport(struct ahc_softc *ahc, u_int *sxfrctl1)
  1148. {
  1149. struct seeprom_descriptor sd;
  1150. struct seeprom_config *sc;
  1151. int have_seeprom;
  1152. int have_autoterm;
  1153. sd.sd_ahc = ahc;
  1154. sd.sd_control_offset = SEECTL;
  1155. sd.sd_status_offset = SEECTL;
  1156. sd.sd_dataout_offset = SEECTL;
  1157. sc = ahc->seep_config;
  1158. /*
  1159. * For some multi-channel devices, the c46 is simply too
  1160. * small to work. For the other controller types, we can
  1161. * get our information from either SEEPROM type. Set the
  1162. * type to start our probe with accordingly.
  1163. */
  1164. if (ahc->flags & AHC_LARGE_SEEPROM)
  1165. sd.sd_chip = C56_66;
  1166. else
  1167. sd.sd_chip = C46;
  1168. sd.sd_MS = SEEMS;
  1169. sd.sd_RDY = SEERDY;
  1170. sd.sd_CS = SEECS;
  1171. sd.sd_CK = SEECK;
  1172. sd.sd_DO = SEEDO;
  1173. sd.sd_DI = SEEDI;
  1174. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  1175. if (have_seeprom) {
  1176. if (bootverbose)
  1177. printf("%s: Reading SEEPROM...", ahc_name(ahc));
  1178. for (;;) {
  1179. u_int start_addr;
  1180. start_addr = 32 * (ahc->channel - 'A');
  1181. have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
  1182. start_addr,
  1183. sizeof(*sc)/2);
  1184. if (have_seeprom)
  1185. have_seeprom = ahc_verify_cksum(sc);
  1186. if (have_seeprom != 0 || sd.sd_chip == C56_66) {
  1187. if (bootverbose) {
  1188. if (have_seeprom == 0)
  1189. printf ("checksum error\n");
  1190. else
  1191. printf ("done.\n");
  1192. }
  1193. break;
  1194. }
  1195. sd.sd_chip = C56_66;
  1196. }
  1197. ahc_release_seeprom(&sd);
  1198. }
  1199. if (!have_seeprom) {
  1200. /*
  1201. * Pull scratch ram settings and treat them as
  1202. * if they are the contents of an seeprom if
  1203. * the 'ADPT' signature is found in SCB2.
  1204. * We manually compose the data as 16bit values
  1205. * to avoid endian issues.
  1206. */
  1207. ahc_outb(ahc, SCBPTR, 2);
  1208. if (ahc_inb(ahc, SCB_BASE) == 'A'
  1209. && ahc_inb(ahc, SCB_BASE + 1) == 'D'
  1210. && ahc_inb(ahc, SCB_BASE + 2) == 'P'
  1211. && ahc_inb(ahc, SCB_BASE + 3) == 'T') {
  1212. uint16_t *sc_data;
  1213. int i;
  1214. sc_data = (uint16_t *)sc;
  1215. for (i = 0; i < 32; i++, sc_data++) {
  1216. int j;
  1217. j = i * 2;
  1218. *sc_data = ahc_inb(ahc, SRAM_BASE + j)
  1219. | ahc_inb(ahc, SRAM_BASE + j + 1) << 8;
  1220. }
  1221. have_seeprom = ahc_verify_cksum(sc);
  1222. if (have_seeprom)
  1223. ahc->flags |= AHC_SCB_CONFIG_USED;
  1224. }
  1225. /*
  1226. * Clear any SCB parity errors in case this data and
  1227. * its associated parity was not initialized by the BIOS
  1228. */
  1229. ahc_outb(ahc, CLRINT, CLRPARERR);
  1230. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1231. }
  1232. if (!have_seeprom) {
  1233. if (bootverbose)
  1234. printf("%s: No SEEPROM available.\n", ahc_name(ahc));
  1235. ahc->flags |= AHC_USEDEFAULTS;
  1236. free(ahc->seep_config, M_DEVBUF);
  1237. ahc->seep_config = NULL;
  1238. sc = NULL;
  1239. } else {
  1240. ahc_parse_pci_eeprom(ahc, sc);
  1241. }
  1242. /*
  1243. * Cards that have the external logic necessary to talk to
  1244. * a SEEPROM, are almost certain to have the remaining logic
  1245. * necessary for auto-termination control. This assumption
  1246. * hasn't failed yet...
  1247. */
  1248. have_autoterm = have_seeprom;
  1249. /*
  1250. * Some low-cost chips have SEEPROM and auto-term control built
  1251. * in, instead of using a GAL. They can tell us directly
  1252. * if the termination logic is enabled.
  1253. */
  1254. if ((ahc->features & AHC_SPIOCAP) != 0) {
  1255. if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) == 0)
  1256. have_autoterm = FALSE;
  1257. }
  1258. if (have_autoterm) {
  1259. ahc->flags |= AHC_HAS_TERM_LOGIC;
  1260. ahc_acquire_seeprom(ahc, &sd);
  1261. configure_termination(ahc, &sd, sc->adapter_control, sxfrctl1);
  1262. ahc_release_seeprom(&sd);
  1263. } else if (have_seeprom) {
  1264. *sxfrctl1 &= ~STPWEN;
  1265. if ((sc->adapter_control & CFSTERM) != 0)
  1266. *sxfrctl1 |= STPWEN;
  1267. if (bootverbose)
  1268. printf("%s: Low byte termination %sabled\n",
  1269. ahc_name(ahc),
  1270. (*sxfrctl1 & STPWEN) ? "en" : "dis");
  1271. }
  1272. }
  1273. static void
  1274. ahc_parse_pci_eeprom(struct ahc_softc *ahc, struct seeprom_config *sc)
  1275. {
  1276. /*
  1277. * Put the data we've collected down into SRAM
  1278. * where ahc_init will find it.
  1279. */
  1280. int i;
  1281. int max_targ = sc->max_targets & CFMAXTARG;
  1282. u_int scsi_conf;
  1283. uint16_t discenable;
  1284. uint16_t ultraenb;
  1285. discenable = 0;
  1286. ultraenb = 0;
  1287. if ((sc->adapter_control & CFULTRAEN) != 0) {
  1288. /*
  1289. * Determine if this adapter has a "newstyle"
  1290. * SEEPROM format.
  1291. */
  1292. for (i = 0; i < max_targ; i++) {
  1293. if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0) {
  1294. ahc->flags |= AHC_NEWEEPROM_FMT;
  1295. break;
  1296. }
  1297. }
  1298. }
  1299. for (i = 0; i < max_targ; i++) {
  1300. u_int scsirate;
  1301. uint16_t target_mask;
  1302. target_mask = 0x01 << i;
  1303. if (sc->device_flags[i] & CFDISC)
  1304. discenable |= target_mask;
  1305. if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
  1306. if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0)
  1307. ultraenb |= target_mask;
  1308. } else if ((sc->adapter_control & CFULTRAEN) != 0) {
  1309. ultraenb |= target_mask;
  1310. }
  1311. if ((sc->device_flags[i] & CFXFER) == 0x04
  1312. && (ultraenb & target_mask) != 0) {
  1313. /* Treat 10MHz as a non-ultra speed */
  1314. sc->device_flags[i] &= ~CFXFER;
  1315. ultraenb &= ~target_mask;
  1316. }
  1317. if ((ahc->features & AHC_ULTRA2) != 0) {
  1318. u_int offset;
  1319. if (sc->device_flags[i] & CFSYNCH)
  1320. offset = MAX_OFFSET_ULTRA2;
  1321. else
  1322. offset = 0;
  1323. ahc_outb(ahc, TARG_OFFSET + i, offset);
  1324. /*
  1325. * The ultra enable bits contain the
  1326. * high bit of the ultra2 sync rate
  1327. * field.
  1328. */
  1329. scsirate = (sc->device_flags[i] & CFXFER)
  1330. | ((ultraenb & target_mask) ? 0x8 : 0x0);
  1331. if (sc->device_flags[i] & CFWIDEB)
  1332. scsirate |= WIDEXFER;
  1333. } else {
  1334. scsirate = (sc->device_flags[i] & CFXFER) << 4;
  1335. if (sc->device_flags[i] & CFSYNCH)
  1336. scsirate |= SOFS;
  1337. if (sc->device_flags[i] & CFWIDEB)
  1338. scsirate |= WIDEXFER;
  1339. }
  1340. ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
  1341. }
  1342. ahc->our_id = sc->brtime_id & CFSCSIID;
  1343. scsi_conf = (ahc->our_id & 0x7);
  1344. if (sc->adapter_control & CFSPARITY)
  1345. scsi_conf |= ENSPCHK;
  1346. if (sc->adapter_control & CFRESETB)
  1347. scsi_conf |= RESET_SCSI;
  1348. ahc->flags |= (sc->adapter_control & CFBOOTCHAN) >> CFBOOTCHANSHIFT;
  1349. if (sc->bios_control & CFEXTEND)
  1350. ahc->flags |= AHC_EXTENDED_TRANS_A;
  1351. if (sc->bios_control & CFBIOSEN)
  1352. ahc->flags |= AHC_BIOS_ENABLED;
  1353. if (ahc->features & AHC_ULTRA
  1354. && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
  1355. /* Should we enable Ultra mode? */
  1356. if (!(sc->adapter_control & CFULTRAEN))
  1357. /* Treat us as a non-ultra card */
  1358. ultraenb = 0;
  1359. }
  1360. if (sc->signature == CFSIGNATURE
  1361. || sc->signature == CFSIGNATURE2) {
  1362. uint32_t devconfig;
  1363. /* Honor the STPWLEVEL settings */
  1364. devconfig = ahc_pci_read_config(ahc->dev_softc,
  1365. DEVCONFIG, /*bytes*/4);
  1366. devconfig &= ~STPWLEVEL;
  1367. if ((sc->bios_control & CFSTPWLEVEL) != 0)
  1368. devconfig |= STPWLEVEL;
  1369. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
  1370. devconfig, /*bytes*/4);
  1371. }
  1372. /* Set SCSICONF info */
  1373. ahc_outb(ahc, SCSICONF, scsi_conf);
  1374. ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
  1375. ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
  1376. ahc_outb(ahc, ULTRA_ENB, ultraenb & 0xff);
  1377. ahc_outb(ahc, ULTRA_ENB + 1, (ultraenb >> 8) & 0xff);
  1378. }
  1379. static void
  1380. configure_termination(struct ahc_softc *ahc,
  1381. struct seeprom_descriptor *sd,
  1382. u_int adapter_control,
  1383. u_int *sxfrctl1)
  1384. {
  1385. uint8_t brddat;
  1386. brddat = 0;
  1387. /*
  1388. * Update the settings in sxfrctl1 to match the
  1389. * termination settings
  1390. */
  1391. *sxfrctl1 = 0;
  1392. /*
  1393. * SEECS must be on for the GALS to latch
  1394. * the data properly. Be sure to leave MS
  1395. * on or we will release the seeprom.
  1396. */
  1397. SEEPROM_OUTB(sd, sd->sd_MS | sd->sd_CS);
  1398. if ((adapter_control & CFAUTOTERM) != 0
  1399. || (ahc->features & AHC_NEW_TERMCTL) != 0) {
  1400. int internal50_present;
  1401. int internal68_present;
  1402. int externalcable_present;
  1403. int eeprom_present;
  1404. int enableSEC_low;
  1405. int enableSEC_high;
  1406. int enablePRI_low;
  1407. int enablePRI_high;
  1408. int sum;
  1409. enableSEC_low = 0;
  1410. enableSEC_high = 0;
  1411. enablePRI_low = 0;
  1412. enablePRI_high = 0;
  1413. if ((ahc->features & AHC_NEW_TERMCTL) != 0) {
  1414. ahc_new_term_detect(ahc, &enableSEC_low,
  1415. &enableSEC_high,
  1416. &enablePRI_low,
  1417. &enablePRI_high,
  1418. &eeprom_present);
  1419. if ((adapter_control & CFSEAUTOTERM) == 0) {
  1420. if (bootverbose)
  1421. printf("%s: Manual SE Termination\n",
  1422. ahc_name(ahc));
  1423. enableSEC_low = (adapter_control & CFSELOWTERM);
  1424. enableSEC_high =
  1425. (adapter_control & CFSEHIGHTERM);
  1426. }
  1427. if ((adapter_control & CFAUTOTERM) == 0) {
  1428. if (bootverbose)
  1429. printf("%s: Manual LVD Termination\n",
  1430. ahc_name(ahc));
  1431. enablePRI_low = (adapter_control & CFSTERM);
  1432. enablePRI_high = (adapter_control & CFWSTERM);
  1433. }
  1434. /* Make the table calculations below happy */
  1435. internal50_present = 0;
  1436. internal68_present = 1;
  1437. externalcable_present = 1;
  1438. } else if ((ahc->features & AHC_SPIOCAP) != 0) {
  1439. aic785X_cable_detect(ahc, &internal50_present,
  1440. &externalcable_present,
  1441. &eeprom_present);
  1442. /* Can never support a wide connector. */
  1443. internal68_present = 0;
  1444. } else {
  1445. aic787X_cable_detect(ahc, &internal50_present,
  1446. &internal68_present,
  1447. &externalcable_present,
  1448. &eeprom_present);
  1449. }
  1450. if ((ahc->features & AHC_WIDE) == 0)
  1451. internal68_present = 0;
  1452. if (bootverbose
  1453. && (ahc->features & AHC_ULTRA2) == 0) {
  1454. printf("%s: internal 50 cable %s present",
  1455. ahc_name(ahc),
  1456. internal50_present ? "is":"not");
  1457. if ((ahc->features & AHC_WIDE) != 0)
  1458. printf(", internal 68 cable %s present",
  1459. internal68_present ? "is":"not");
  1460. printf("\n%s: external cable %s present\n",
  1461. ahc_name(ahc),
  1462. externalcable_present ? "is":"not");
  1463. }
  1464. if (bootverbose)
  1465. printf("%s: BIOS eeprom %s present\n",
  1466. ahc_name(ahc), eeprom_present ? "is" : "not");
  1467. if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0) {
  1468. /*
  1469. * The 50 pin connector is a separate bus,
  1470. * so force it to always be terminated.
  1471. * In the future, perform current sensing
  1472. * to determine if we are in the middle of
  1473. * a properly terminated bus.
  1474. */
  1475. internal50_present = 0;
  1476. }
  1477. /*
  1478. * Now set the termination based on what
  1479. * we found.
  1480. * Flash Enable = BRDDAT7
  1481. * Secondary High Term Enable = BRDDAT6
  1482. * Secondary Low Term Enable = BRDDAT5 (7890)
  1483. * Primary High Term Enable = BRDDAT4 (7890)
  1484. */
  1485. if ((ahc->features & AHC_ULTRA2) == 0
  1486. && (internal50_present != 0)
  1487. && (internal68_present != 0)
  1488. && (externalcable_present != 0)) {
  1489. printf("%s: Illegal cable configuration!!. "
  1490. "Only two connectors on the "
  1491. "adapter may be used at a "
  1492. "time!\n", ahc_name(ahc));
  1493. /*
  1494. * Pretend there are no cables in the hope
  1495. * that having all of the termination on
  1496. * gives us a more stable bus.
  1497. */
  1498. internal50_present = 0;
  1499. internal68_present = 0;
  1500. externalcable_present = 0;
  1501. }
  1502. if ((ahc->features & AHC_WIDE) != 0
  1503. && ((externalcable_present == 0)
  1504. || (internal68_present == 0)
  1505. || (enableSEC_high != 0))) {
  1506. brddat |= BRDDAT6;
  1507. if (bootverbose) {
  1508. if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
  1509. printf("%s: 68 pin termination "
  1510. "Enabled\n", ahc_name(ahc));
  1511. else
  1512. printf("%s: %sHigh byte termination "
  1513. "Enabled\n", ahc_name(ahc),
  1514. enableSEC_high ? "Secondary "
  1515. : "");
  1516. }
  1517. }
  1518. sum = internal50_present + internal68_present
  1519. + externalcable_present;
  1520. if (sum < 2 || (enableSEC_low != 0)) {
  1521. if ((ahc->features & AHC_ULTRA2) != 0)
  1522. brddat |= BRDDAT5;
  1523. else
  1524. *sxfrctl1 |= STPWEN;
  1525. if (bootverbose) {
  1526. if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
  1527. printf("%s: 50 pin termination "
  1528. "Enabled\n", ahc_name(ahc));
  1529. else
  1530. printf("%s: %sLow byte termination "
  1531. "Enabled\n", ahc_name(ahc),
  1532. enableSEC_low ? "Secondary "
  1533. : "");
  1534. }
  1535. }
  1536. if (enablePRI_low != 0) {
  1537. *sxfrctl1 |= STPWEN;
  1538. if (bootverbose)
  1539. printf("%s: Primary Low Byte termination "
  1540. "Enabled\n", ahc_name(ahc));
  1541. }
  1542. /*
  1543. * Setup STPWEN before setting up the rest of
  1544. * the termination per the tech note on the U160 cards.
  1545. */
  1546. ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
  1547. if (enablePRI_high != 0) {
  1548. brddat |= BRDDAT4;
  1549. if (bootverbose)
  1550. printf("%s: Primary High Byte "
  1551. "termination Enabled\n",
  1552. ahc_name(ahc));
  1553. }
  1554. write_brdctl(ahc, brddat);
  1555. } else {
  1556. if ((adapter_control & CFSTERM) != 0) {
  1557. *sxfrctl1 |= STPWEN;
  1558. if (bootverbose)
  1559. printf("%s: %sLow byte termination Enabled\n",
  1560. ahc_name(ahc),
  1561. (ahc->features & AHC_ULTRA2) ? "Primary "
  1562. : "");
  1563. }
  1564. if ((adapter_control & CFWSTERM) != 0
  1565. && (ahc->features & AHC_WIDE) != 0) {
  1566. brddat |= BRDDAT6;
  1567. if (bootverbose)
  1568. printf("%s: %sHigh byte termination Enabled\n",
  1569. ahc_name(ahc),
  1570. (ahc->features & AHC_ULTRA2)
  1571. ? "Secondary " : "");
  1572. }
  1573. /*
  1574. * Setup STPWEN before setting up the rest of
  1575. * the termination per the tech note on the U160 cards.
  1576. */
  1577. ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
  1578. if ((ahc->features & AHC_WIDE) != 0)
  1579. write_brdctl(ahc, brddat);
  1580. }
  1581. SEEPROM_OUTB(sd, sd->sd_MS); /* Clear CS */
  1582. }
  1583. static void
  1584. ahc_new_term_detect(struct ahc_softc *ahc, int *enableSEC_low,
  1585. int *enableSEC_high, int *enablePRI_low,
  1586. int *enablePRI_high, int *eeprom_present)
  1587. {
  1588. uint8_t brdctl;
  1589. /*
  1590. * BRDDAT7 = Eeprom
  1591. * BRDDAT6 = Enable Secondary High Byte termination
  1592. * BRDDAT5 = Enable Secondary Low Byte termination
  1593. * BRDDAT4 = Enable Primary high byte termination
  1594. * BRDDAT3 = Enable Primary low byte termination
  1595. */
  1596. brdctl = read_brdctl(ahc);
  1597. *eeprom_present = brdctl & BRDDAT7;
  1598. *enableSEC_high = (brdctl & BRDDAT6);
  1599. *enableSEC_low = (brdctl & BRDDAT5);
  1600. *enablePRI_high = (brdctl & BRDDAT4);
  1601. *enablePRI_low = (brdctl & BRDDAT3);
  1602. }
  1603. static void
  1604. aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
  1605. int *internal68_present, int *externalcable_present,
  1606. int *eeprom_present)
  1607. {
  1608. uint8_t brdctl;
  1609. /*
  1610. * First read the status of our cables.
  1611. * Set the rom bank to 0 since the
  1612. * bank setting serves as a multiplexor
  1613. * for the cable detection logic.
  1614. * BRDDAT5 controls the bank switch.
  1615. */
  1616. write_brdctl(ahc, 0);
  1617. /*
  1618. * Now read the state of the internal
  1619. * connectors. BRDDAT6 is INT50 and
  1620. * BRDDAT7 is INT68.
  1621. */
  1622. brdctl = read_brdctl(ahc);
  1623. *internal50_present = (brdctl & BRDDAT6) ? 0 : 1;
  1624. *internal68_present = (brdctl & BRDDAT7) ? 0 : 1;
  1625. /*
  1626. * Set the rom bank to 1 and determine
  1627. * the other signals.
  1628. */
  1629. write_brdctl(ahc, BRDDAT5);
  1630. /*
  1631. * Now read the state of the external
  1632. * connectors. BRDDAT6 is EXT68 and
  1633. * BRDDAT7 is EPROMPS.
  1634. */
  1635. brdctl = read_brdctl(ahc);
  1636. *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
  1637. *eeprom_present = (brdctl & BRDDAT7) ? 1 : 0;
  1638. }
  1639. static void
  1640. aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
  1641. int *externalcable_present, int *eeprom_present)
  1642. {
  1643. uint8_t brdctl;
  1644. uint8_t spiocap;
  1645. spiocap = ahc_inb(ahc, SPIOCAP);
  1646. spiocap &= ~SOFTCMDEN;
  1647. spiocap |= EXT_BRDCTL;
  1648. ahc_outb(ahc, SPIOCAP, spiocap);
  1649. ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
  1650. ahc_flush_device_writes(ahc);
  1651. ahc_delay(500);
  1652. ahc_outb(ahc, BRDCTL, 0);
  1653. ahc_flush_device_writes(ahc);
  1654. ahc_delay(500);
  1655. brdctl = ahc_inb(ahc, BRDCTL);
  1656. *internal50_present = (brdctl & BRDDAT5) ? 0 : 1;
  1657. *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
  1658. *eeprom_present = (ahc_inb(ahc, SPIOCAP) & EEPROM) ? 1 : 0;
  1659. }
  1660. int
  1661. ahc_acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
  1662. {
  1663. int wait;
  1664. if ((ahc->features & AHC_SPIOCAP) != 0
  1665. && (ahc_inb(ahc, SPIOCAP) & SEEPROM) == 0)
  1666. return (0);
  1667. /*
  1668. * Request access of the memory port. When access is
  1669. * granted, SEERDY will go high. We use a 1 second
  1670. * timeout which should be near 1 second more than
  1671. * is needed. Reason: after the chip reset, there
  1672. * should be no contention.
  1673. */
  1674. SEEPROM_OUTB(sd, sd->sd_MS);
  1675. wait = 1000; /* 1 second timeout in msec */
  1676. while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
  1677. ahc_delay(1000); /* delay 1 msec */
  1678. }
  1679. if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
  1680. SEEPROM_OUTB(sd, 0);
  1681. return (0);
  1682. }
  1683. return(1);
  1684. }
  1685. void
  1686. ahc_release_seeprom(struct seeprom_descriptor *sd)
  1687. {
  1688. /* Release access to the memory port and the serial EEPROM. */
  1689. SEEPROM_OUTB(sd, 0);
  1690. }
  1691. static void
  1692. write_brdctl(struct ahc_softc *ahc, uint8_t value)
  1693. {
  1694. uint8_t brdctl;
  1695. if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
  1696. brdctl = BRDSTB;
  1697. if (ahc->channel == 'B')
  1698. brdctl |= BRDCS;
  1699. } else if ((ahc->features & AHC_ULTRA2) != 0) {
  1700. brdctl = 0;
  1701. } else {
  1702. brdctl = BRDSTB|BRDCS;
  1703. }
  1704. ahc_outb(ahc, BRDCTL, brdctl);
  1705. ahc_flush_device_writes(ahc);
  1706. brdctl |= value;
  1707. ahc_outb(ahc, BRDCTL, brdctl);
  1708. ahc_flush_device_writes(ahc);
  1709. if ((ahc->features & AHC_ULTRA2) != 0)
  1710. brdctl |= BRDSTB_ULTRA2;
  1711. else
  1712. brdctl &= ~BRDSTB;
  1713. ahc_outb(ahc, BRDCTL, brdctl);
  1714. ahc_flush_device_writes(ahc);
  1715. if ((ahc->features & AHC_ULTRA2) != 0)
  1716. brdctl = 0;
  1717. else
  1718. brdctl &= ~BRDCS;
  1719. ahc_outb(ahc, BRDCTL, brdctl);
  1720. }
  1721. static uint8_t
  1722. read_brdctl(struct ahc_softc *ahc)
  1723. {
  1724. uint8_t brdctl;
  1725. uint8_t value;
  1726. if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
  1727. brdctl = BRDRW;
  1728. if (ahc->channel == 'B')
  1729. brdctl |= BRDCS;
  1730. } else if ((ahc->features & AHC_ULTRA2) != 0) {
  1731. brdctl = BRDRW_ULTRA2;
  1732. } else {
  1733. brdctl = BRDRW|BRDCS;
  1734. }
  1735. ahc_outb(ahc, BRDCTL, brdctl);
  1736. ahc_flush_device_writes(ahc);
  1737. value = ahc_inb(ahc, BRDCTL);
  1738. ahc_outb(ahc, BRDCTL, 0);
  1739. return (value);
  1740. }
  1741. static void
  1742. ahc_pci_intr(struct ahc_softc *ahc)
  1743. {
  1744. u_int error;
  1745. u_int status1;
  1746. error = ahc_inb(ahc, ERROR);
  1747. if ((error & PCIERRSTAT) == 0)
  1748. return;
  1749. status1 = ahc_pci_read_config(ahc->dev_softc,
  1750. PCIR_STATUS + 1, /*bytes*/1);
  1751. printf("%s: PCI error Interrupt at seqaddr = 0x%x\n",
  1752. ahc_name(ahc),
  1753. ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
  1754. if (status1 & DPE) {
  1755. ahc->pci_target_perr_count++;
  1756. printf("%s: Data Parity Error Detected during address "
  1757. "or write data phase\n", ahc_name(ahc));
  1758. }
  1759. if (status1 & SSE) {
  1760. printf("%s: Signal System Error Detected\n", ahc_name(ahc));
  1761. }
  1762. if (status1 & RMA) {
  1763. printf("%s: Received a Master Abort\n", ahc_name(ahc));
  1764. }
  1765. if (status1 & RTA) {
  1766. printf("%s: Received a Target Abort\n", ahc_name(ahc));
  1767. }
  1768. if (status1 & STA) {
  1769. printf("%s: Signaled a Target Abort\n", ahc_name(ahc));
  1770. }
  1771. if (status1 & DPR) {
  1772. printf("%s: Data Parity Error has been reported via PERR#\n",
  1773. ahc_name(ahc));
  1774. }
  1775. /* Clear latched errors. */
  1776. ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
  1777. status1, /*bytes*/1);
  1778. if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
  1779. printf("%s: Latched PCIERR interrupt with "
  1780. "no status bits set\n", ahc_name(ahc));
  1781. } else {
  1782. ahc_outb(ahc, CLRINT, CLRPARERR);
  1783. }
  1784. if (ahc->pci_target_perr_count > AHC_PCI_TARGET_PERR_THRESH) {
  1785. printf(
  1786. "%s: WARNING WARNING WARNING WARNING\n"
  1787. "%s: Too many PCI parity errors observed as a target.\n"
  1788. "%s: Some device on this bus is generating bad parity.\n"
  1789. "%s: This is an error *observed by*, not *generated by*, this controller.\n"
  1790. "%s: PCI parity error checking has been disabled.\n"
  1791. "%s: WARNING WARNING WARNING WARNING\n",
  1792. ahc_name(ahc), ahc_name(ahc), ahc_name(ahc),
  1793. ahc_name(ahc), ahc_name(ahc), ahc_name(ahc));
  1794. ahc->seqctl |= FAILDIS;
  1795. ahc_outb(ahc, SEQCTL, ahc->seqctl);
  1796. }
  1797. ahc_unpause(ahc);
  1798. }
  1799. static int
  1800. ahc_pci_chip_init(struct ahc_softc *ahc)
  1801. {
  1802. ahc_outb(ahc, DSCOMMAND0, ahc->bus_softc.pci_softc.dscommand0);
  1803. ahc_outb(ahc, DSPCISTATUS, ahc->bus_softc.pci_softc.dspcistatus);
  1804. if ((ahc->features & AHC_DT) != 0) {
  1805. u_int sfunct;
  1806. sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
  1807. ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
  1808. ahc_outb(ahc, OPTIONMODE, ahc->bus_softc.pci_softc.optionmode);
  1809. ahc_outw(ahc, TARGCRCCNT, ahc->bus_softc.pci_softc.targcrccnt);
  1810. ahc_outb(ahc, SFUNCT, sfunct);
  1811. ahc_outb(ahc, CRCCONTROL1,
  1812. ahc->bus_softc.pci_softc.crccontrol1);
  1813. }
  1814. if ((ahc->features & AHC_MULTI_FUNC) != 0)
  1815. ahc_outb(ahc, SCBBADDR, ahc->bus_softc.pci_softc.scbbaddr);
  1816. if ((ahc->features & AHC_ULTRA2) != 0)
  1817. ahc_outb(ahc, DFF_THRSH, ahc->bus_softc.pci_softc.dff_thrsh);
  1818. return (ahc_chip_init(ahc));
  1819. }
  1820. static int
  1821. ahc_pci_suspend(struct ahc_softc *ahc)
  1822. {
  1823. return (ahc_suspend(ahc));
  1824. }
  1825. static int
  1826. ahc_pci_resume(struct ahc_softc *ahc)
  1827. {
  1828. pci_set_power_state(ahc->dev_softc, AHC_POWER_STATE_D0);
  1829. /*
  1830. * We assume that the OS has restored our register
  1831. * mappings, etc. Just update the config space registers
  1832. * that the OS doesn't know about and rely on our chip
  1833. * reset handler to handle the rest.
  1834. */
  1835. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4,
  1836. ahc->bus_softc.pci_softc.devconfig);
  1837. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1,
  1838. ahc->bus_softc.pci_softc.command);
  1839. ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1,
  1840. ahc->bus_softc.pci_softc.csize_lattime);
  1841. if ((ahc->flags & AHC_HAS_TERM_LOGIC) != 0) {
  1842. struct seeprom_descriptor sd;
  1843. u_int sxfrctl1;
  1844. sd.sd_ahc = ahc;
  1845. sd.sd_control_offset = SEECTL;
  1846. sd.sd_status_offset = SEECTL;
  1847. sd.sd_dataout_offset = SEECTL;
  1848. ahc_acquire_seeprom(ahc, &sd);
  1849. configure_termination(ahc, &sd,
  1850. ahc->seep_config->adapter_control,
  1851. &sxfrctl1);
  1852. ahc_release_seeprom(&sd);
  1853. }
  1854. return (ahc_resume(ahc));
  1855. }
  1856. static int
  1857. ahc_aic785X_setup(struct ahc_softc *ahc)
  1858. {
  1859. ahc_dev_softc_t pci;
  1860. uint8_t rev;
  1861. pci = ahc->dev_softc;
  1862. ahc->channel = 'A';
  1863. ahc->chip = AHC_AIC7850;
  1864. ahc->features = AHC_AIC7850_FE;
  1865. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1866. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1867. if (rev >= 1)
  1868. ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
  1869. ahc->instruction_ram_size = 512;
  1870. return (0);
  1871. }
  1872. static int
  1873. ahc_aic7860_setup(struct ahc_softc *ahc)
  1874. {
  1875. ahc_dev_softc_t pci;
  1876. uint8_t rev;
  1877. pci = ahc->dev_softc;
  1878. ahc->channel = 'A';
  1879. ahc->chip = AHC_AIC7860;
  1880. ahc->features = AHC_AIC7860_FE;
  1881. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1882. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1883. if (rev >= 1)
  1884. ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
  1885. ahc->instruction_ram_size = 512;
  1886. return (0);
  1887. }
  1888. static int
  1889. ahc_apa1480_setup(struct ahc_softc *ahc)
  1890. {
  1891. int error;
  1892. error = ahc_aic7860_setup(ahc);
  1893. if (error != 0)
  1894. return (error);
  1895. ahc->features |= AHC_REMOVABLE;
  1896. return (0);
  1897. }
  1898. static int
  1899. ahc_aic7870_setup(struct ahc_softc *ahc)
  1900. {
  1901. ahc->channel = 'A';
  1902. ahc->chip = AHC_AIC7870;
  1903. ahc->features = AHC_AIC7870_FE;
  1904. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1905. ahc->instruction_ram_size = 512;
  1906. return (0);
  1907. }
  1908. static int
  1909. ahc_aha394X_setup(struct ahc_softc *ahc)
  1910. {
  1911. int error;
  1912. error = ahc_aic7870_setup(ahc);
  1913. if (error == 0)
  1914. error = ahc_aha394XX_setup(ahc);
  1915. return (error);
  1916. }
  1917. static int
  1918. ahc_aha398X_setup(struct ahc_softc *ahc)
  1919. {
  1920. int error;
  1921. error = ahc_aic7870_setup(ahc);
  1922. if (error == 0)
  1923. error = ahc_aha398XX_setup(ahc);
  1924. return (error);
  1925. }
  1926. static int
  1927. ahc_aha494X_setup(struct ahc_softc *ahc)
  1928. {
  1929. int error;
  1930. error = ahc_aic7870_setup(ahc);
  1931. if (error == 0)
  1932. error = ahc_aha494XX_setup(ahc);
  1933. return (error);
  1934. }
  1935. static int
  1936. ahc_aic7880_setup(struct ahc_softc *ahc)
  1937. {
  1938. ahc_dev_softc_t pci;
  1939. uint8_t rev;
  1940. pci = ahc->dev_softc;
  1941. ahc->channel = 'A';
  1942. ahc->chip = AHC_AIC7880;
  1943. ahc->features = AHC_AIC7880_FE;
  1944. ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
  1945. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1946. if (rev >= 1) {
  1947. ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
  1948. } else {
  1949. ahc->bugs |= AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1950. }
  1951. ahc->instruction_ram_size = 512;
  1952. return (0);
  1953. }
  1954. static int
  1955. ahc_aha2940Pro_setup(struct ahc_softc *ahc)
  1956. {
  1957. ahc->flags |= AHC_INT50_SPEEDFLEX;
  1958. return (ahc_aic7880_setup(ahc));
  1959. }
  1960. static int
  1961. ahc_aha394XU_setup(struct ahc_softc *ahc)
  1962. {
  1963. int error;
  1964. error = ahc_aic7880_setup(ahc);
  1965. if (error == 0)
  1966. error = ahc_aha394XX_setup(ahc);
  1967. return (error);
  1968. }
  1969. static int
  1970. ahc_aha398XU_setup(struct ahc_softc *ahc)
  1971. {
  1972. int error;
  1973. error = ahc_aic7880_setup(ahc);
  1974. if (error == 0)
  1975. error = ahc_aha398XX_setup(ahc);
  1976. return (error);
  1977. }
  1978. static int
  1979. ahc_aic7890_setup(struct ahc_softc *ahc)
  1980. {
  1981. ahc_dev_softc_t pci;
  1982. uint8_t rev;
  1983. pci = ahc->dev_softc;
  1984. ahc->channel = 'A';
  1985. ahc->chip = AHC_AIC7890;
  1986. ahc->features = AHC_AIC7890_FE;
  1987. ahc->flags |= AHC_NEWEEPROM_FMT;
  1988. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1989. if (rev == 0)
  1990. ahc->bugs |= AHC_AUTOFLUSH_BUG|AHC_CACHETHEN_BUG;
  1991. ahc->instruction_ram_size = 768;
  1992. return (0);
  1993. }
  1994. static int
  1995. ahc_aic7892_setup(struct ahc_softc *ahc)
  1996. {
  1997. ahc->channel = 'A';
  1998. ahc->chip = AHC_AIC7892;
  1999. ahc->features = AHC_AIC7892_FE;
  2000. ahc->flags |= AHC_NEWEEPROM_FMT;
  2001. ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
  2002. ahc->instruction_ram_size = 1024;
  2003. return (0);
  2004. }
  2005. static int
  2006. ahc_aic7895_setup(struct ahc_softc *ahc)
  2007. {
  2008. ahc_dev_softc_t pci;
  2009. uint8_t rev;
  2010. pci = ahc->dev_softc;
  2011. ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
  2012. /*
  2013. * The 'C' revision of the aic7895 has a few additional features.
  2014. */
  2015. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  2016. if (rev >= 4) {
  2017. ahc->chip = AHC_AIC7895C;
  2018. ahc->features = AHC_AIC7895C_FE;
  2019. } else {
  2020. u_int command;
  2021. ahc->chip = AHC_AIC7895;
  2022. ahc->features = AHC_AIC7895_FE;
  2023. /*
  2024. * The BIOS disables the use of MWI transactions
  2025. * since it does not have the MWI bug work around
  2026. * we have. Disabling MWI reduces performance, so
  2027. * turn it on again.
  2028. */
  2029. command = ahc_pci_read_config(pci, PCIR_COMMAND, /*bytes*/1);
  2030. command |= PCIM_CMD_MWRICEN;
  2031. ahc_pci_write_config(pci, PCIR_COMMAND, command, /*bytes*/1);
  2032. ahc->bugs |= AHC_PCI_MWI_BUG;
  2033. }
  2034. /*
  2035. * XXX Does CACHETHEN really not work??? What about PCI retry?
  2036. * on C level chips. Need to test, but for now, play it safe.
  2037. */
  2038. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_PCI_2_1_RETRY_BUG
  2039. | AHC_CACHETHEN_BUG;
  2040. #if 0
  2041. uint32_t devconfig;
  2042. /*
  2043. * Cachesize must also be zero due to stray DAC
  2044. * problem when sitting behind some bridges.
  2045. */
  2046. ahc_pci_write_config(pci, CSIZE_LATTIME, 0, /*bytes*/1);
  2047. devconfig = ahc_pci_read_config(pci, DEVCONFIG, /*bytes*/1);
  2048. devconfig |= MRDCEN;
  2049. ahc_pci_write_config(pci, DEVCONFIG, devconfig, /*bytes*/1);
  2050. #endif
  2051. ahc->flags |= AHC_NEWEEPROM_FMT;
  2052. ahc->instruction_ram_size = 512;
  2053. return (0);
  2054. }
  2055. static int
  2056. ahc_aic7896_setup(struct ahc_softc *ahc)
  2057. {
  2058. ahc_dev_softc_t pci;
  2059. pci = ahc->dev_softc;
  2060. ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
  2061. ahc->chip = AHC_AIC7896;
  2062. ahc->features = AHC_AIC7896_FE;
  2063. ahc->flags |= AHC_NEWEEPROM_FMT;
  2064. ahc->bugs |= AHC_CACHETHEN_DIS_BUG;
  2065. ahc->instruction_ram_size = 768;
  2066. return (0);
  2067. }
  2068. static int
  2069. ahc_aic7899_setup(struct ahc_softc *ahc)
  2070. {
  2071. ahc_dev_softc_t pci;
  2072. pci = ahc->dev_softc;
  2073. ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
  2074. ahc->chip = AHC_AIC7899;
  2075. ahc->features = AHC_AIC7899_FE;
  2076. ahc->flags |= AHC_NEWEEPROM_FMT;
  2077. ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
  2078. ahc->instruction_ram_size = 1024;
  2079. return (0);
  2080. }
  2081. static int
  2082. ahc_aha29160C_setup(struct ahc_softc *ahc)
  2083. {
  2084. int error;
  2085. error = ahc_aic7899_setup(ahc);
  2086. if (error != 0)
  2087. return (error);
  2088. ahc->features |= AHC_REMOVABLE;
  2089. return (0);
  2090. }
  2091. static int
  2092. ahc_raid_setup(struct ahc_softc *ahc)
  2093. {
  2094. printf("RAID functionality unsupported\n");
  2095. return (ENXIO);
  2096. }
  2097. static int
  2098. ahc_aha394XX_setup(struct ahc_softc *ahc)
  2099. {
  2100. ahc_dev_softc_t pci;
  2101. pci = ahc->dev_softc;
  2102. switch (ahc_get_pci_slot(pci)) {
  2103. case AHC_394X_SLOT_CHANNEL_A:
  2104. ahc->channel = 'A';
  2105. break;
  2106. case AHC_394X_SLOT_CHANNEL_B:
  2107. ahc->channel = 'B';
  2108. break;
  2109. default:
  2110. printf("adapter at unexpected slot %d\n"
  2111. "unable to map to a channel\n",
  2112. ahc_get_pci_slot(pci));
  2113. ahc->channel = 'A';
  2114. }
  2115. return (0);
  2116. }
  2117. static int
  2118. ahc_aha398XX_setup(struct ahc_softc *ahc)
  2119. {
  2120. ahc_dev_softc_t pci;
  2121. pci = ahc->dev_softc;
  2122. switch (ahc_get_pci_slot(pci)) {
  2123. case AHC_398X_SLOT_CHANNEL_A:
  2124. ahc->channel = 'A';
  2125. break;
  2126. case AHC_398X_SLOT_CHANNEL_B:
  2127. ahc->channel = 'B';
  2128. break;
  2129. case AHC_398X_SLOT_CHANNEL_C:
  2130. ahc->channel = 'C';
  2131. break;
  2132. default:
  2133. printf("adapter at unexpected slot %d\n"
  2134. "unable to map to a channel\n",
  2135. ahc_get_pci_slot(pci));
  2136. ahc->channel = 'A';
  2137. break;
  2138. }
  2139. ahc->flags |= AHC_LARGE_SEEPROM;
  2140. return (0);
  2141. }
  2142. static int
  2143. ahc_aha494XX_setup(struct ahc_softc *ahc)
  2144. {
  2145. ahc_dev_softc_t pci;
  2146. pci = ahc->dev_softc;
  2147. switch (ahc_get_pci_slot(pci)) {
  2148. case AHC_494X_SLOT_CHANNEL_A:
  2149. ahc->channel = 'A';
  2150. break;
  2151. case AHC_494X_SLOT_CHANNEL_B:
  2152. ahc->channel = 'B';
  2153. break;
  2154. case AHC_494X_SLOT_CHANNEL_C:
  2155. ahc->channel = 'C';
  2156. break;
  2157. case AHC_494X_SLOT_CHANNEL_D:
  2158. ahc->channel = 'D';
  2159. break;
  2160. default:
  2161. printf("adapter at unexpected slot %d\n"
  2162. "unable to map to a channel\n",
  2163. ahc_get_pci_slot(pci));
  2164. ahc->channel = 'A';
  2165. }
  2166. ahc->flags |= AHC_LARGE_SEEPROM;
  2167. return (0);
  2168. }