aic7xxx_pci.c 60 KB

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