aic7xxx_pci.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401
  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_int command;
  672. u_int our_id;
  673. u_int sxfrctl1;
  674. u_int scsiseq;
  675. u_int dscommand0;
  676. uint32_t devconfig;
  677. int error;
  678. uint8_t sblkctl;
  679. our_id = 0;
  680. error = entry->setup(ahc);
  681. if (error != 0)
  682. return (error);
  683. ahc->chip |= AHC_PCI;
  684. ahc->description = entry->name;
  685. pci_set_power_state(ahc->dev_softc, AHC_POWER_STATE_D0);
  686. error = ahc_pci_map_registers(ahc);
  687. if (error != 0)
  688. return (error);
  689. /*
  690. * Before we continue probing the card, ensure that
  691. * its interrupts are *disabled*. We don't want
  692. * a misstep to hang the machine in an interrupt
  693. * storm.
  694. */
  695. ahc_intr_enable(ahc, FALSE);
  696. devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
  697. /*
  698. * If we need to support high memory, enable dual
  699. * address cycles. This bit must be set to enable
  700. * high address bit generation even if we are on a
  701. * 64bit bus (PCI64BIT set in devconfig).
  702. */
  703. if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
  704. if (bootverbose)
  705. printf("%s: Enabling 39Bit Addressing\n",
  706. ahc_name(ahc));
  707. devconfig |= DACEN;
  708. }
  709. /* Ensure that pci error generation, a test feature, is disabled. */
  710. devconfig |= PCIERRGENDIS;
  711. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
  712. /* Ensure busmastering is enabled */
  713. command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
  714. command |= PCIM_CMD_BUSMASTEREN;
  715. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
  716. /* On all PCI adapters, we allow SCB paging */
  717. ahc->flags |= AHC_PAGESCBS;
  718. error = ahc_softc_init(ahc);
  719. if (error != 0)
  720. return (error);
  721. /*
  722. * Disable PCI parity error checking. Users typically
  723. * do this to work around broken PCI chipsets that get
  724. * the parity timing wrong and thus generate lots of spurious
  725. * errors. The chip only allows us to disable *all* parity
  726. * error reporting when doing this, so CIO bus, scb ram, and
  727. * scratch ram parity errors will be ignored too.
  728. */
  729. if ((ahc->flags & AHC_DISABLE_PCI_PERR) != 0)
  730. ahc->seqctl |= FAILDIS;
  731. ahc->bus_intr = ahc_pci_intr;
  732. ahc->bus_chip_init = ahc_pci_chip_init;
  733. ahc->bus_suspend = ahc_pci_suspend;
  734. ahc->bus_resume = ahc_pci_resume;
  735. /* Remeber how the card was setup in case there is no SEEPROM */
  736. if ((ahc_inb(ahc, HCNTRL) & POWRDN) == 0) {
  737. ahc_pause(ahc);
  738. if ((ahc->features & AHC_ULTRA2) != 0)
  739. our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
  740. else
  741. our_id = ahc_inb(ahc, SCSIID) & OID;
  742. sxfrctl1 = ahc_inb(ahc, SXFRCTL1) & STPWEN;
  743. scsiseq = ahc_inb(ahc, SCSISEQ);
  744. } else {
  745. sxfrctl1 = STPWEN;
  746. our_id = 7;
  747. scsiseq = 0;
  748. }
  749. error = ahc_reset(ahc, /*reinit*/FALSE);
  750. if (error != 0)
  751. return (ENXIO);
  752. if ((ahc->features & AHC_DT) != 0) {
  753. u_int sfunct;
  754. /* Perform ALT-Mode Setup */
  755. sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
  756. ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
  757. ahc_outb(ahc, OPTIONMODE,
  758. OPTIONMODE_DEFAULTS|AUTOACKEN|BUSFREEREV|EXPPHASEDIS);
  759. ahc_outb(ahc, SFUNCT, sfunct);
  760. /* Normal mode setup */
  761. ahc_outb(ahc, CRCCONTROL1, CRCVALCHKEN|CRCENDCHKEN|CRCREQCHKEN
  762. |TARGCRCENDEN);
  763. }
  764. dscommand0 = ahc_inb(ahc, DSCOMMAND0);
  765. dscommand0 |= MPARCKEN|CACHETHEN;
  766. if ((ahc->features & AHC_ULTRA2) != 0) {
  767. /*
  768. * DPARCKEN doesn't work correctly on
  769. * some MBs so don't use it.
  770. */
  771. dscommand0 &= ~DPARCKEN;
  772. }
  773. /*
  774. * Handle chips that must have cache line
  775. * streaming (dis/en)abled.
  776. */
  777. if ((ahc->bugs & AHC_CACHETHEN_DIS_BUG) != 0)
  778. dscommand0 |= CACHETHEN;
  779. if ((ahc->bugs & AHC_CACHETHEN_BUG) != 0)
  780. dscommand0 &= ~CACHETHEN;
  781. ahc_outb(ahc, DSCOMMAND0, dscommand0);
  782. ahc->pci_cachesize =
  783. ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME,
  784. /*bytes*/1) & CACHESIZE;
  785. ahc->pci_cachesize *= 4;
  786. if ((ahc->bugs & AHC_PCI_2_1_RETRY_BUG) != 0
  787. && ahc->pci_cachesize == 4) {
  788. ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME,
  789. 0, /*bytes*/1);
  790. ahc->pci_cachesize = 0;
  791. }
  792. /*
  793. * We cannot perform ULTRA speeds without the presense
  794. * of the external precision resistor.
  795. */
  796. if ((ahc->features & AHC_ULTRA) != 0) {
  797. uint32_t devconfig;
  798. devconfig = ahc_pci_read_config(ahc->dev_softc,
  799. DEVCONFIG, /*bytes*/4);
  800. if ((devconfig & REXTVALID) == 0)
  801. ahc->features &= ~AHC_ULTRA;
  802. }
  803. /* See if we have a SEEPROM and perform auto-term */
  804. check_extport(ahc, &sxfrctl1);
  805. /*
  806. * Take the LED out of diagnostic mode
  807. */
  808. sblkctl = ahc_inb(ahc, SBLKCTL);
  809. ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
  810. if ((ahc->features & AHC_ULTRA2) != 0) {
  811. ahc_outb(ahc, DFF_THRSH, RD_DFTHRSH_MAX|WR_DFTHRSH_MAX);
  812. } else {
  813. ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
  814. }
  815. if (ahc->flags & AHC_USEDEFAULTS) {
  816. /*
  817. * PCI Adapter default setup
  818. * Should only be used if the adapter does not have
  819. * a SEEPROM.
  820. */
  821. /* See if someone else set us up already */
  822. if ((ahc->flags & AHC_NO_BIOS_INIT) == 0
  823. && scsiseq != 0) {
  824. printf("%s: Using left over BIOS settings\n",
  825. ahc_name(ahc));
  826. ahc->flags &= ~AHC_USEDEFAULTS;
  827. ahc->flags |= AHC_BIOS_ENABLED;
  828. } else {
  829. /*
  830. * Assume only one connector and always turn
  831. * on termination.
  832. */
  833. our_id = 0x07;
  834. sxfrctl1 = STPWEN;
  835. }
  836. ahc_outb(ahc, SCSICONF, our_id|ENSPCHK|RESET_SCSI);
  837. ahc->our_id = our_id;
  838. }
  839. /*
  840. * Take a look to see if we have external SRAM.
  841. * We currently do not attempt to use SRAM that is
  842. * shared among multiple controllers.
  843. */
  844. ahc_probe_ext_scbram(ahc);
  845. /*
  846. * Record our termination setting for the
  847. * generic initialization routine.
  848. */
  849. if ((sxfrctl1 & STPWEN) != 0)
  850. ahc->flags |= AHC_TERM_ENB_A;
  851. /*
  852. * Save chip register configuration data for chip resets
  853. * that occur during runtime and resume events.
  854. */
  855. ahc->bus_softc.pci_softc.devconfig =
  856. ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
  857. ahc->bus_softc.pci_softc.command =
  858. ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1);
  859. ahc->bus_softc.pci_softc.csize_lattime =
  860. ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1);
  861. ahc->bus_softc.pci_softc.dscommand0 = ahc_inb(ahc, DSCOMMAND0);
  862. ahc->bus_softc.pci_softc.dspcistatus = ahc_inb(ahc, DSPCISTATUS);
  863. if ((ahc->features & AHC_DT) != 0) {
  864. u_int sfunct;
  865. sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
  866. ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
  867. ahc->bus_softc.pci_softc.optionmode = ahc_inb(ahc, OPTIONMODE);
  868. ahc->bus_softc.pci_softc.targcrccnt = ahc_inw(ahc, TARGCRCCNT);
  869. ahc_outb(ahc, SFUNCT, sfunct);
  870. ahc->bus_softc.pci_softc.crccontrol1 =
  871. ahc_inb(ahc, CRCCONTROL1);
  872. }
  873. if ((ahc->features & AHC_MULTI_FUNC) != 0)
  874. ahc->bus_softc.pci_softc.scbbaddr = ahc_inb(ahc, SCBBADDR);
  875. if ((ahc->features & AHC_ULTRA2) != 0)
  876. ahc->bus_softc.pci_softc.dff_thrsh = ahc_inb(ahc, DFF_THRSH);
  877. /* Core initialization */
  878. error = ahc_init(ahc);
  879. if (error != 0)
  880. return (error);
  881. /*
  882. * Allow interrupts now that we are completely setup.
  883. */
  884. error = ahc_pci_map_int(ahc);
  885. if (error != 0)
  886. return (error);
  887. ahc->init_level++;
  888. return (0);
  889. }
  890. /*
  891. * Test for the presense of external sram in an
  892. * "unshared" configuration.
  893. */
  894. static int
  895. ahc_ext_scbram_present(struct ahc_softc *ahc)
  896. {
  897. u_int chip;
  898. int ramps;
  899. int single_user;
  900. uint32_t devconfig;
  901. chip = ahc->chip & AHC_CHIPID_MASK;
  902. devconfig = ahc_pci_read_config(ahc->dev_softc,
  903. DEVCONFIG, /*bytes*/4);
  904. single_user = (devconfig & MPORTMODE) != 0;
  905. if ((ahc->features & AHC_ULTRA2) != 0)
  906. ramps = (ahc_inb(ahc, DSCOMMAND0) & RAMPS) != 0;
  907. else if (chip == AHC_AIC7895 || chip == AHC_AIC7895C)
  908. /*
  909. * External SCBRAM arbitration is flakey
  910. * on these chips. Unfortunately this means
  911. * we don't use the extra SCB ram space on the
  912. * 3940AUW.
  913. */
  914. ramps = 0;
  915. else if (chip >= AHC_AIC7870)
  916. ramps = (devconfig & RAMPSM) != 0;
  917. else
  918. ramps = 0;
  919. if (ramps && single_user)
  920. return (1);
  921. return (0);
  922. }
  923. /*
  924. * Enable external scbram.
  925. */
  926. static void
  927. ahc_scbram_config(struct ahc_softc *ahc, int enable, int pcheck,
  928. int fast, int large)
  929. {
  930. uint32_t devconfig;
  931. if (ahc->features & AHC_MULTI_FUNC) {
  932. /*
  933. * Set the SCB Base addr (highest address bit)
  934. * depending on which channel we are.
  935. */
  936. ahc_outb(ahc, SCBBADDR, ahc_get_pci_function(ahc->dev_softc));
  937. }
  938. ahc->flags &= ~AHC_LSCBS_ENABLED;
  939. if (large)
  940. ahc->flags |= AHC_LSCBS_ENABLED;
  941. devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
  942. if ((ahc->features & AHC_ULTRA2) != 0) {
  943. u_int dscommand0;
  944. dscommand0 = ahc_inb(ahc, DSCOMMAND0);
  945. if (enable)
  946. dscommand0 &= ~INTSCBRAMSEL;
  947. else
  948. dscommand0 |= INTSCBRAMSEL;
  949. if (large)
  950. dscommand0 &= ~USCBSIZE32;
  951. else
  952. dscommand0 |= USCBSIZE32;
  953. ahc_outb(ahc, DSCOMMAND0, dscommand0);
  954. } else {
  955. if (fast)
  956. devconfig &= ~EXTSCBTIME;
  957. else
  958. devconfig |= EXTSCBTIME;
  959. if (enable)
  960. devconfig &= ~SCBRAMSEL;
  961. else
  962. devconfig |= SCBRAMSEL;
  963. if (large)
  964. devconfig &= ~SCBSIZE32;
  965. else
  966. devconfig |= SCBSIZE32;
  967. }
  968. if (pcheck)
  969. devconfig |= EXTSCBPEN;
  970. else
  971. devconfig &= ~EXTSCBPEN;
  972. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
  973. }
  974. /*
  975. * Take a look to see if we have external SRAM.
  976. * We currently do not attempt to use SRAM that is
  977. * shared among multiple controllers.
  978. */
  979. static void
  980. ahc_probe_ext_scbram(struct ahc_softc *ahc)
  981. {
  982. int num_scbs;
  983. int test_num_scbs;
  984. int enable;
  985. int pcheck;
  986. int fast;
  987. int large;
  988. enable = FALSE;
  989. pcheck = FALSE;
  990. fast = FALSE;
  991. large = FALSE;
  992. num_scbs = 0;
  993. if (ahc_ext_scbram_present(ahc) == 0)
  994. goto done;
  995. /*
  996. * Probe for the best parameters to use.
  997. */
  998. ahc_scbram_config(ahc, /*enable*/TRUE, pcheck, fast, large);
  999. num_scbs = ahc_probe_scbs(ahc);
  1000. if (num_scbs == 0) {
  1001. /* The SRAM wasn't really present. */
  1002. goto done;
  1003. }
  1004. enable = TRUE;
  1005. /*
  1006. * Clear any outstanding parity error
  1007. * and ensure that parity error reporting
  1008. * is enabled.
  1009. */
  1010. ahc_outb(ahc, SEQCTL, 0);
  1011. ahc_outb(ahc, CLRINT, CLRPARERR);
  1012. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1013. /* Now see if we can do parity */
  1014. ahc_scbram_config(ahc, enable, /*pcheck*/TRUE, fast, large);
  1015. num_scbs = ahc_probe_scbs(ahc);
  1016. if ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
  1017. || (ahc_inb(ahc, ERROR) & MPARERR) == 0)
  1018. pcheck = TRUE;
  1019. /* Clear any resulting parity error */
  1020. ahc_outb(ahc, CLRINT, CLRPARERR);
  1021. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1022. /* Now see if we can do fast timing */
  1023. ahc_scbram_config(ahc, enable, pcheck, /*fast*/TRUE, large);
  1024. test_num_scbs = ahc_probe_scbs(ahc);
  1025. if (test_num_scbs == num_scbs
  1026. && ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
  1027. || (ahc_inb(ahc, ERROR) & MPARERR) == 0))
  1028. fast = TRUE;
  1029. /*
  1030. * See if we can use large SCBs and still maintain
  1031. * the same overall count of SCBs.
  1032. */
  1033. if ((ahc->features & AHC_LARGE_SCBS) != 0) {
  1034. ahc_scbram_config(ahc, enable, pcheck, fast, /*large*/TRUE);
  1035. test_num_scbs = ahc_probe_scbs(ahc);
  1036. if (test_num_scbs >= num_scbs) {
  1037. large = TRUE;
  1038. num_scbs = test_num_scbs;
  1039. if (num_scbs >= 64) {
  1040. /*
  1041. * We have enough space to move the
  1042. * "busy targets table" into SCB space
  1043. * and make it qualify all the way to the
  1044. * lun level.
  1045. */
  1046. ahc->flags |= AHC_SCB_BTT;
  1047. }
  1048. }
  1049. }
  1050. done:
  1051. /*
  1052. * Disable parity error reporting until we
  1053. * can load instruction ram.
  1054. */
  1055. ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
  1056. /* Clear any latched parity error */
  1057. ahc_outb(ahc, CLRINT, CLRPARERR);
  1058. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1059. if (bootverbose && enable) {
  1060. printf("%s: External SRAM, %s access%s, %dbytes/SCB\n",
  1061. ahc_name(ahc), fast ? "fast" : "slow",
  1062. pcheck ? ", parity checking enabled" : "",
  1063. large ? 64 : 32);
  1064. }
  1065. ahc_scbram_config(ahc, enable, pcheck, fast, large);
  1066. }
  1067. /*
  1068. * Perform some simple tests that should catch situations where
  1069. * our registers are invalidly mapped.
  1070. */
  1071. int
  1072. ahc_pci_test_register_access(struct ahc_softc *ahc)
  1073. {
  1074. int error;
  1075. u_int status1;
  1076. uint32_t cmd;
  1077. uint8_t hcntrl;
  1078. error = EIO;
  1079. /*
  1080. * Enable PCI error interrupt status, but suppress NMIs
  1081. * generated by SERR raised due to target aborts.
  1082. */
  1083. cmd = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
  1084. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
  1085. cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
  1086. /*
  1087. * First a simple test to see if any
  1088. * registers can be read. Reading
  1089. * HCNTRL has no side effects and has
  1090. * at least one bit that is guaranteed to
  1091. * be zero so it is a good register to
  1092. * use for this test.
  1093. */
  1094. hcntrl = ahc_inb(ahc, HCNTRL);
  1095. if (hcntrl == 0xFF)
  1096. goto fail;
  1097. /*
  1098. * Next create a situation where write combining
  1099. * or read prefetching could be initiated by the
  1100. * CPU or host bridge. Our device does not support
  1101. * either, so look for data corruption and/or flagged
  1102. * PCI errors. First pause without causing another
  1103. * chip reset.
  1104. */
  1105. hcntrl &= ~CHIPRST;
  1106. ahc_outb(ahc, HCNTRL, hcntrl|PAUSE);
  1107. while (ahc_is_paused(ahc) == 0)
  1108. ;
  1109. /* Clear any PCI errors that occurred before our driver attached. */
  1110. status1 = ahc_pci_read_config(ahc->dev_softc,
  1111. PCIR_STATUS + 1, /*bytes*/1);
  1112. ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
  1113. status1, /*bytes*/1);
  1114. ahc_outb(ahc, CLRINT, CLRPARERR);
  1115. ahc_outb(ahc, SEQCTL, PERRORDIS);
  1116. ahc_outb(ahc, SCBPTR, 0);
  1117. ahc_outl(ahc, SCB_BASE, 0x5aa555aa);
  1118. if (ahc_inl(ahc, SCB_BASE) != 0x5aa555aa)
  1119. goto fail;
  1120. status1 = ahc_pci_read_config(ahc->dev_softc,
  1121. PCIR_STATUS + 1, /*bytes*/1);
  1122. if ((status1 & STA) != 0)
  1123. goto fail;
  1124. error = 0;
  1125. fail:
  1126. /* Silently clear any latched errors. */
  1127. status1 = ahc_pci_read_config(ahc->dev_softc,
  1128. PCIR_STATUS + 1, /*bytes*/1);
  1129. ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
  1130. status1, /*bytes*/1);
  1131. ahc_outb(ahc, CLRINT, CLRPARERR);
  1132. ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
  1133. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
  1134. return (error);
  1135. }
  1136. /*
  1137. * Check the external port logic for a serial eeprom
  1138. * and termination/cable detection contrls.
  1139. */
  1140. static void
  1141. check_extport(struct ahc_softc *ahc, u_int *sxfrctl1)
  1142. {
  1143. struct seeprom_descriptor sd;
  1144. struct seeprom_config *sc;
  1145. int have_seeprom;
  1146. int have_autoterm;
  1147. sd.sd_ahc = ahc;
  1148. sd.sd_control_offset = SEECTL;
  1149. sd.sd_status_offset = SEECTL;
  1150. sd.sd_dataout_offset = SEECTL;
  1151. sc = ahc->seep_config;
  1152. /*
  1153. * For some multi-channel devices, the c46 is simply too
  1154. * small to work. For the other controller types, we can
  1155. * get our information from either SEEPROM type. Set the
  1156. * type to start our probe with accordingly.
  1157. */
  1158. if (ahc->flags & AHC_LARGE_SEEPROM)
  1159. sd.sd_chip = C56_66;
  1160. else
  1161. sd.sd_chip = C46;
  1162. sd.sd_MS = SEEMS;
  1163. sd.sd_RDY = SEERDY;
  1164. sd.sd_CS = SEECS;
  1165. sd.sd_CK = SEECK;
  1166. sd.sd_DO = SEEDO;
  1167. sd.sd_DI = SEEDI;
  1168. have_seeprom = ahc_acquire_seeprom(ahc, &sd);
  1169. if (have_seeprom) {
  1170. if (bootverbose)
  1171. printf("%s: Reading SEEPROM...", ahc_name(ahc));
  1172. for (;;) {
  1173. u_int start_addr;
  1174. start_addr = 32 * (ahc->channel - 'A');
  1175. have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
  1176. start_addr,
  1177. sizeof(*sc)/2);
  1178. if (have_seeprom)
  1179. have_seeprom = ahc_verify_cksum(sc);
  1180. if (have_seeprom != 0 || sd.sd_chip == C56_66) {
  1181. if (bootverbose) {
  1182. if (have_seeprom == 0)
  1183. printf ("checksum error\n");
  1184. else
  1185. printf ("done.\n");
  1186. }
  1187. break;
  1188. }
  1189. sd.sd_chip = C56_66;
  1190. }
  1191. ahc_release_seeprom(&sd);
  1192. }
  1193. if (!have_seeprom) {
  1194. /*
  1195. * Pull scratch ram settings and treat them as
  1196. * if they are the contents of an seeprom if
  1197. * the 'ADPT' signature is found in SCB2.
  1198. * We manually compose the data as 16bit values
  1199. * to avoid endian issues.
  1200. */
  1201. ahc_outb(ahc, SCBPTR, 2);
  1202. if (ahc_inb(ahc, SCB_BASE) == 'A'
  1203. && ahc_inb(ahc, SCB_BASE + 1) == 'D'
  1204. && ahc_inb(ahc, SCB_BASE + 2) == 'P'
  1205. && ahc_inb(ahc, SCB_BASE + 3) == 'T') {
  1206. uint16_t *sc_data;
  1207. int i;
  1208. sc_data = (uint16_t *)sc;
  1209. for (i = 0; i < 32; i++, sc_data++) {
  1210. int j;
  1211. j = i * 2;
  1212. *sc_data = ahc_inb(ahc, SRAM_BASE + j)
  1213. | ahc_inb(ahc, SRAM_BASE + j + 1) << 8;
  1214. }
  1215. have_seeprom = ahc_verify_cksum(sc);
  1216. if (have_seeprom)
  1217. ahc->flags |= AHC_SCB_CONFIG_USED;
  1218. }
  1219. /*
  1220. * Clear any SCB parity errors in case this data and
  1221. * its associated parity was not initialized by the BIOS
  1222. */
  1223. ahc_outb(ahc, CLRINT, CLRPARERR);
  1224. ahc_outb(ahc, CLRINT, CLRBRKADRINT);
  1225. }
  1226. if (!have_seeprom) {
  1227. if (bootverbose)
  1228. printf("%s: No SEEPROM available.\n", ahc_name(ahc));
  1229. ahc->flags |= AHC_USEDEFAULTS;
  1230. free(ahc->seep_config, M_DEVBUF);
  1231. ahc->seep_config = NULL;
  1232. sc = NULL;
  1233. } else {
  1234. ahc_parse_pci_eeprom(ahc, sc);
  1235. }
  1236. /*
  1237. * Cards that have the external logic necessary to talk to
  1238. * a SEEPROM, are almost certain to have the remaining logic
  1239. * necessary for auto-termination control. This assumption
  1240. * hasn't failed yet...
  1241. */
  1242. have_autoterm = have_seeprom;
  1243. /*
  1244. * Some low-cost chips have SEEPROM and auto-term control built
  1245. * in, instead of using a GAL. They can tell us directly
  1246. * if the termination logic is enabled.
  1247. */
  1248. if ((ahc->features & AHC_SPIOCAP) != 0) {
  1249. if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) == 0)
  1250. have_autoterm = FALSE;
  1251. }
  1252. if (have_autoterm) {
  1253. ahc->flags |= AHC_HAS_TERM_LOGIC;
  1254. ahc_acquire_seeprom(ahc, &sd);
  1255. configure_termination(ahc, &sd, sc->adapter_control, sxfrctl1);
  1256. ahc_release_seeprom(&sd);
  1257. } else if (have_seeprom) {
  1258. *sxfrctl1 &= ~STPWEN;
  1259. if ((sc->adapter_control & CFSTERM) != 0)
  1260. *sxfrctl1 |= STPWEN;
  1261. if (bootverbose)
  1262. printf("%s: Low byte termination %sabled\n",
  1263. ahc_name(ahc),
  1264. (*sxfrctl1 & STPWEN) ? "en" : "dis");
  1265. }
  1266. }
  1267. static void
  1268. ahc_parse_pci_eeprom(struct ahc_softc *ahc, struct seeprom_config *sc)
  1269. {
  1270. /*
  1271. * Put the data we've collected down into SRAM
  1272. * where ahc_init will find it.
  1273. */
  1274. int i;
  1275. int max_targ = sc->max_targets & CFMAXTARG;
  1276. u_int scsi_conf;
  1277. uint16_t discenable;
  1278. uint16_t ultraenb;
  1279. discenable = 0;
  1280. ultraenb = 0;
  1281. if ((sc->adapter_control & CFULTRAEN) != 0) {
  1282. /*
  1283. * Determine if this adapter has a "newstyle"
  1284. * SEEPROM format.
  1285. */
  1286. for (i = 0; i < max_targ; i++) {
  1287. if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0) {
  1288. ahc->flags |= AHC_NEWEEPROM_FMT;
  1289. break;
  1290. }
  1291. }
  1292. }
  1293. for (i = 0; i < max_targ; i++) {
  1294. u_int scsirate;
  1295. uint16_t target_mask;
  1296. target_mask = 0x01 << i;
  1297. if (sc->device_flags[i] & CFDISC)
  1298. discenable |= target_mask;
  1299. if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
  1300. if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0)
  1301. ultraenb |= target_mask;
  1302. } else if ((sc->adapter_control & CFULTRAEN) != 0) {
  1303. ultraenb |= target_mask;
  1304. }
  1305. if ((sc->device_flags[i] & CFXFER) == 0x04
  1306. && (ultraenb & target_mask) != 0) {
  1307. /* Treat 10MHz as a non-ultra speed */
  1308. sc->device_flags[i] &= ~CFXFER;
  1309. ultraenb &= ~target_mask;
  1310. }
  1311. if ((ahc->features & AHC_ULTRA2) != 0) {
  1312. u_int offset;
  1313. if (sc->device_flags[i] & CFSYNCH)
  1314. offset = MAX_OFFSET_ULTRA2;
  1315. else
  1316. offset = 0;
  1317. ahc_outb(ahc, TARG_OFFSET + i, offset);
  1318. /*
  1319. * The ultra enable bits contain the
  1320. * high bit of the ultra2 sync rate
  1321. * field.
  1322. */
  1323. scsirate = (sc->device_flags[i] & CFXFER)
  1324. | ((ultraenb & target_mask) ? 0x8 : 0x0);
  1325. if (sc->device_flags[i] & CFWIDEB)
  1326. scsirate |= WIDEXFER;
  1327. } else {
  1328. scsirate = (sc->device_flags[i] & CFXFER) << 4;
  1329. if (sc->device_flags[i] & CFSYNCH)
  1330. scsirate |= SOFS;
  1331. if (sc->device_flags[i] & CFWIDEB)
  1332. scsirate |= WIDEXFER;
  1333. }
  1334. ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
  1335. }
  1336. ahc->our_id = sc->brtime_id & CFSCSIID;
  1337. scsi_conf = (ahc->our_id & 0x7);
  1338. if (sc->adapter_control & CFSPARITY)
  1339. scsi_conf |= ENSPCHK;
  1340. if (sc->adapter_control & CFRESETB)
  1341. scsi_conf |= RESET_SCSI;
  1342. ahc->flags |= (sc->adapter_control & CFBOOTCHAN) >> CFBOOTCHANSHIFT;
  1343. if (sc->bios_control & CFEXTEND)
  1344. ahc->flags |= AHC_EXTENDED_TRANS_A;
  1345. if (sc->bios_control & CFBIOSEN)
  1346. ahc->flags |= AHC_BIOS_ENABLED;
  1347. if (ahc->features & AHC_ULTRA
  1348. && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
  1349. /* Should we enable Ultra mode? */
  1350. if (!(sc->adapter_control & CFULTRAEN))
  1351. /* Treat us as a non-ultra card */
  1352. ultraenb = 0;
  1353. }
  1354. if (sc->signature == CFSIGNATURE
  1355. || sc->signature == CFSIGNATURE2) {
  1356. uint32_t devconfig;
  1357. /* Honor the STPWLEVEL settings */
  1358. devconfig = ahc_pci_read_config(ahc->dev_softc,
  1359. DEVCONFIG, /*bytes*/4);
  1360. devconfig &= ~STPWLEVEL;
  1361. if ((sc->bios_control & CFSTPWLEVEL) != 0)
  1362. devconfig |= STPWLEVEL;
  1363. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
  1364. devconfig, /*bytes*/4);
  1365. }
  1366. /* Set SCSICONF info */
  1367. ahc_outb(ahc, SCSICONF, scsi_conf);
  1368. ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
  1369. ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
  1370. ahc_outb(ahc, ULTRA_ENB, ultraenb & 0xff);
  1371. ahc_outb(ahc, ULTRA_ENB + 1, (ultraenb >> 8) & 0xff);
  1372. }
  1373. static void
  1374. configure_termination(struct ahc_softc *ahc,
  1375. struct seeprom_descriptor *sd,
  1376. u_int adapter_control,
  1377. u_int *sxfrctl1)
  1378. {
  1379. uint8_t brddat;
  1380. brddat = 0;
  1381. /*
  1382. * Update the settings in sxfrctl1 to match the
  1383. * termination settings
  1384. */
  1385. *sxfrctl1 = 0;
  1386. /*
  1387. * SEECS must be on for the GALS to latch
  1388. * the data properly. Be sure to leave MS
  1389. * on or we will release the seeprom.
  1390. */
  1391. SEEPROM_OUTB(sd, sd->sd_MS | sd->sd_CS);
  1392. if ((adapter_control & CFAUTOTERM) != 0
  1393. || (ahc->features & AHC_NEW_TERMCTL) != 0) {
  1394. int internal50_present;
  1395. int internal68_present;
  1396. int externalcable_present;
  1397. int eeprom_present;
  1398. int enableSEC_low;
  1399. int enableSEC_high;
  1400. int enablePRI_low;
  1401. int enablePRI_high;
  1402. int sum;
  1403. enableSEC_low = 0;
  1404. enableSEC_high = 0;
  1405. enablePRI_low = 0;
  1406. enablePRI_high = 0;
  1407. if ((ahc->features & AHC_NEW_TERMCTL) != 0) {
  1408. ahc_new_term_detect(ahc, &enableSEC_low,
  1409. &enableSEC_high,
  1410. &enablePRI_low,
  1411. &enablePRI_high,
  1412. &eeprom_present);
  1413. if ((adapter_control & CFSEAUTOTERM) == 0) {
  1414. if (bootverbose)
  1415. printf("%s: Manual SE Termination\n",
  1416. ahc_name(ahc));
  1417. enableSEC_low = (adapter_control & CFSELOWTERM);
  1418. enableSEC_high =
  1419. (adapter_control & CFSEHIGHTERM);
  1420. }
  1421. if ((adapter_control & CFAUTOTERM) == 0) {
  1422. if (bootverbose)
  1423. printf("%s: Manual LVD Termination\n",
  1424. ahc_name(ahc));
  1425. enablePRI_low = (adapter_control & CFSTERM);
  1426. enablePRI_high = (adapter_control & CFWSTERM);
  1427. }
  1428. /* Make the table calculations below happy */
  1429. internal50_present = 0;
  1430. internal68_present = 1;
  1431. externalcable_present = 1;
  1432. } else if ((ahc->features & AHC_SPIOCAP) != 0) {
  1433. aic785X_cable_detect(ahc, &internal50_present,
  1434. &externalcable_present,
  1435. &eeprom_present);
  1436. /* Can never support a wide connector. */
  1437. internal68_present = 0;
  1438. } else {
  1439. aic787X_cable_detect(ahc, &internal50_present,
  1440. &internal68_present,
  1441. &externalcable_present,
  1442. &eeprom_present);
  1443. }
  1444. if ((ahc->features & AHC_WIDE) == 0)
  1445. internal68_present = 0;
  1446. if (bootverbose
  1447. && (ahc->features & AHC_ULTRA2) == 0) {
  1448. printf("%s: internal 50 cable %s present",
  1449. ahc_name(ahc),
  1450. internal50_present ? "is":"not");
  1451. if ((ahc->features & AHC_WIDE) != 0)
  1452. printf(", internal 68 cable %s present",
  1453. internal68_present ? "is":"not");
  1454. printf("\n%s: external cable %s present\n",
  1455. ahc_name(ahc),
  1456. externalcable_present ? "is":"not");
  1457. }
  1458. if (bootverbose)
  1459. printf("%s: BIOS eeprom %s present\n",
  1460. ahc_name(ahc), eeprom_present ? "is" : "not");
  1461. if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0) {
  1462. /*
  1463. * The 50 pin connector is a separate bus,
  1464. * so force it to always be terminated.
  1465. * In the future, perform current sensing
  1466. * to determine if we are in the middle of
  1467. * a properly terminated bus.
  1468. */
  1469. internal50_present = 0;
  1470. }
  1471. /*
  1472. * Now set the termination based on what
  1473. * we found.
  1474. * Flash Enable = BRDDAT7
  1475. * Secondary High Term Enable = BRDDAT6
  1476. * Secondary Low Term Enable = BRDDAT5 (7890)
  1477. * Primary High Term Enable = BRDDAT4 (7890)
  1478. */
  1479. if ((ahc->features & AHC_ULTRA2) == 0
  1480. && (internal50_present != 0)
  1481. && (internal68_present != 0)
  1482. && (externalcable_present != 0)) {
  1483. printf("%s: Illegal cable configuration!!. "
  1484. "Only two connectors on the "
  1485. "adapter may be used at a "
  1486. "time!\n", ahc_name(ahc));
  1487. /*
  1488. * Pretend there are no cables in the hope
  1489. * that having all of the termination on
  1490. * gives us a more stable bus.
  1491. */
  1492. internal50_present = 0;
  1493. internal68_present = 0;
  1494. externalcable_present = 0;
  1495. }
  1496. if ((ahc->features & AHC_WIDE) != 0
  1497. && ((externalcable_present == 0)
  1498. || (internal68_present == 0)
  1499. || (enableSEC_high != 0))) {
  1500. brddat |= BRDDAT6;
  1501. if (bootverbose) {
  1502. if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
  1503. printf("%s: 68 pin termination "
  1504. "Enabled\n", ahc_name(ahc));
  1505. else
  1506. printf("%s: %sHigh byte termination "
  1507. "Enabled\n", ahc_name(ahc),
  1508. enableSEC_high ? "Secondary "
  1509. : "");
  1510. }
  1511. }
  1512. sum = internal50_present + internal68_present
  1513. + externalcable_present;
  1514. if (sum < 2 || (enableSEC_low != 0)) {
  1515. if ((ahc->features & AHC_ULTRA2) != 0)
  1516. brddat |= BRDDAT5;
  1517. else
  1518. *sxfrctl1 |= STPWEN;
  1519. if (bootverbose) {
  1520. if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
  1521. printf("%s: 50 pin termination "
  1522. "Enabled\n", ahc_name(ahc));
  1523. else
  1524. printf("%s: %sLow byte termination "
  1525. "Enabled\n", ahc_name(ahc),
  1526. enableSEC_low ? "Secondary "
  1527. : "");
  1528. }
  1529. }
  1530. if (enablePRI_low != 0) {
  1531. *sxfrctl1 |= STPWEN;
  1532. if (bootverbose)
  1533. printf("%s: Primary Low Byte termination "
  1534. "Enabled\n", ahc_name(ahc));
  1535. }
  1536. /*
  1537. * Setup STPWEN before setting up the rest of
  1538. * the termination per the tech note on the U160 cards.
  1539. */
  1540. ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
  1541. if (enablePRI_high != 0) {
  1542. brddat |= BRDDAT4;
  1543. if (bootverbose)
  1544. printf("%s: Primary High Byte "
  1545. "termination Enabled\n",
  1546. ahc_name(ahc));
  1547. }
  1548. write_brdctl(ahc, brddat);
  1549. } else {
  1550. if ((adapter_control & CFSTERM) != 0) {
  1551. *sxfrctl1 |= STPWEN;
  1552. if (bootverbose)
  1553. printf("%s: %sLow byte termination Enabled\n",
  1554. ahc_name(ahc),
  1555. (ahc->features & AHC_ULTRA2) ? "Primary "
  1556. : "");
  1557. }
  1558. if ((adapter_control & CFWSTERM) != 0
  1559. && (ahc->features & AHC_WIDE) != 0) {
  1560. brddat |= BRDDAT6;
  1561. if (bootverbose)
  1562. printf("%s: %sHigh byte termination Enabled\n",
  1563. ahc_name(ahc),
  1564. (ahc->features & AHC_ULTRA2)
  1565. ? "Secondary " : "");
  1566. }
  1567. /*
  1568. * Setup STPWEN before setting up the rest of
  1569. * the termination per the tech note on the U160 cards.
  1570. */
  1571. ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
  1572. if ((ahc->features & AHC_WIDE) != 0)
  1573. write_brdctl(ahc, brddat);
  1574. }
  1575. SEEPROM_OUTB(sd, sd->sd_MS); /* Clear CS */
  1576. }
  1577. static void
  1578. ahc_new_term_detect(struct ahc_softc *ahc, int *enableSEC_low,
  1579. int *enableSEC_high, int *enablePRI_low,
  1580. int *enablePRI_high, int *eeprom_present)
  1581. {
  1582. uint8_t brdctl;
  1583. /*
  1584. * BRDDAT7 = Eeprom
  1585. * BRDDAT6 = Enable Secondary High Byte termination
  1586. * BRDDAT5 = Enable Secondary Low Byte termination
  1587. * BRDDAT4 = Enable Primary high byte termination
  1588. * BRDDAT3 = Enable Primary low byte termination
  1589. */
  1590. brdctl = read_brdctl(ahc);
  1591. *eeprom_present = brdctl & BRDDAT7;
  1592. *enableSEC_high = (brdctl & BRDDAT6);
  1593. *enableSEC_low = (brdctl & BRDDAT5);
  1594. *enablePRI_high = (brdctl & BRDDAT4);
  1595. *enablePRI_low = (brdctl & BRDDAT3);
  1596. }
  1597. static void
  1598. aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
  1599. int *internal68_present, int *externalcable_present,
  1600. int *eeprom_present)
  1601. {
  1602. uint8_t brdctl;
  1603. /*
  1604. * First read the status of our cables.
  1605. * Set the rom bank to 0 since the
  1606. * bank setting serves as a multiplexor
  1607. * for the cable detection logic.
  1608. * BRDDAT5 controls the bank switch.
  1609. */
  1610. write_brdctl(ahc, 0);
  1611. /*
  1612. * Now read the state of the internal
  1613. * connectors. BRDDAT6 is INT50 and
  1614. * BRDDAT7 is INT68.
  1615. */
  1616. brdctl = read_brdctl(ahc);
  1617. *internal50_present = (brdctl & BRDDAT6) ? 0 : 1;
  1618. *internal68_present = (brdctl & BRDDAT7) ? 0 : 1;
  1619. /*
  1620. * Set the rom bank to 1 and determine
  1621. * the other signals.
  1622. */
  1623. write_brdctl(ahc, BRDDAT5);
  1624. /*
  1625. * Now read the state of the external
  1626. * connectors. BRDDAT6 is EXT68 and
  1627. * BRDDAT7 is EPROMPS.
  1628. */
  1629. brdctl = read_brdctl(ahc);
  1630. *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
  1631. *eeprom_present = (brdctl & BRDDAT7) ? 1 : 0;
  1632. }
  1633. static void
  1634. aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
  1635. int *externalcable_present, int *eeprom_present)
  1636. {
  1637. uint8_t brdctl;
  1638. uint8_t spiocap;
  1639. spiocap = ahc_inb(ahc, SPIOCAP);
  1640. spiocap &= ~SOFTCMDEN;
  1641. spiocap |= EXT_BRDCTL;
  1642. ahc_outb(ahc, SPIOCAP, spiocap);
  1643. ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
  1644. ahc_flush_device_writes(ahc);
  1645. ahc_delay(500);
  1646. ahc_outb(ahc, BRDCTL, 0);
  1647. ahc_flush_device_writes(ahc);
  1648. ahc_delay(500);
  1649. brdctl = ahc_inb(ahc, BRDCTL);
  1650. *internal50_present = (brdctl & BRDDAT5) ? 0 : 1;
  1651. *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
  1652. *eeprom_present = (ahc_inb(ahc, SPIOCAP) & EEPROM) ? 1 : 0;
  1653. }
  1654. int
  1655. ahc_acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
  1656. {
  1657. int wait;
  1658. if ((ahc->features & AHC_SPIOCAP) != 0
  1659. && (ahc_inb(ahc, SPIOCAP) & SEEPROM) == 0)
  1660. return (0);
  1661. /*
  1662. * Request access of the memory port. When access is
  1663. * granted, SEERDY will go high. We use a 1 second
  1664. * timeout which should be near 1 second more than
  1665. * is needed. Reason: after the chip reset, there
  1666. * should be no contention.
  1667. */
  1668. SEEPROM_OUTB(sd, sd->sd_MS);
  1669. wait = 1000; /* 1 second timeout in msec */
  1670. while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
  1671. ahc_delay(1000); /* delay 1 msec */
  1672. }
  1673. if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
  1674. SEEPROM_OUTB(sd, 0);
  1675. return (0);
  1676. }
  1677. return(1);
  1678. }
  1679. void
  1680. ahc_release_seeprom(struct seeprom_descriptor *sd)
  1681. {
  1682. /* Release access to the memory port and the serial EEPROM. */
  1683. SEEPROM_OUTB(sd, 0);
  1684. }
  1685. static void
  1686. write_brdctl(struct ahc_softc *ahc, uint8_t value)
  1687. {
  1688. uint8_t brdctl;
  1689. if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
  1690. brdctl = BRDSTB;
  1691. if (ahc->channel == 'B')
  1692. brdctl |= BRDCS;
  1693. } else if ((ahc->features & AHC_ULTRA2) != 0) {
  1694. brdctl = 0;
  1695. } else {
  1696. brdctl = BRDSTB|BRDCS;
  1697. }
  1698. ahc_outb(ahc, BRDCTL, brdctl);
  1699. ahc_flush_device_writes(ahc);
  1700. brdctl |= value;
  1701. ahc_outb(ahc, BRDCTL, brdctl);
  1702. ahc_flush_device_writes(ahc);
  1703. if ((ahc->features & AHC_ULTRA2) != 0)
  1704. brdctl |= BRDSTB_ULTRA2;
  1705. else
  1706. brdctl &= ~BRDSTB;
  1707. ahc_outb(ahc, BRDCTL, brdctl);
  1708. ahc_flush_device_writes(ahc);
  1709. if ((ahc->features & AHC_ULTRA2) != 0)
  1710. brdctl = 0;
  1711. else
  1712. brdctl &= ~BRDCS;
  1713. ahc_outb(ahc, BRDCTL, brdctl);
  1714. }
  1715. static uint8_t
  1716. read_brdctl(struct ahc_softc *ahc)
  1717. {
  1718. uint8_t brdctl;
  1719. uint8_t value;
  1720. if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
  1721. brdctl = BRDRW;
  1722. if (ahc->channel == 'B')
  1723. brdctl |= BRDCS;
  1724. } else if ((ahc->features & AHC_ULTRA2) != 0) {
  1725. brdctl = BRDRW_ULTRA2;
  1726. } else {
  1727. brdctl = BRDRW|BRDCS;
  1728. }
  1729. ahc_outb(ahc, BRDCTL, brdctl);
  1730. ahc_flush_device_writes(ahc);
  1731. value = ahc_inb(ahc, BRDCTL);
  1732. ahc_outb(ahc, BRDCTL, 0);
  1733. return (value);
  1734. }
  1735. static void
  1736. ahc_pci_intr(struct ahc_softc *ahc)
  1737. {
  1738. u_int error;
  1739. u_int status1;
  1740. error = ahc_inb(ahc, ERROR);
  1741. if ((error & PCIERRSTAT) == 0)
  1742. return;
  1743. status1 = ahc_pci_read_config(ahc->dev_softc,
  1744. PCIR_STATUS + 1, /*bytes*/1);
  1745. printf("%s: PCI error Interrupt at seqaddr = 0x%x\n",
  1746. ahc_name(ahc),
  1747. ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
  1748. if (status1 & DPE) {
  1749. ahc->pci_target_perr_count++;
  1750. printf("%s: Data Parity Error Detected during address "
  1751. "or write data phase\n", ahc_name(ahc));
  1752. }
  1753. if (status1 & SSE) {
  1754. printf("%s: Signal System Error Detected\n", ahc_name(ahc));
  1755. }
  1756. if (status1 & RMA) {
  1757. printf("%s: Received a Master Abort\n", ahc_name(ahc));
  1758. }
  1759. if (status1 & RTA) {
  1760. printf("%s: Received a Target Abort\n", ahc_name(ahc));
  1761. }
  1762. if (status1 & STA) {
  1763. printf("%s: Signaled a Target Abort\n", ahc_name(ahc));
  1764. }
  1765. if (status1 & DPR) {
  1766. printf("%s: Data Parity Error has been reported via PERR#\n",
  1767. ahc_name(ahc));
  1768. }
  1769. /* Clear latched errors. */
  1770. ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
  1771. status1, /*bytes*/1);
  1772. if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
  1773. printf("%s: Latched PCIERR interrupt with "
  1774. "no status bits set\n", ahc_name(ahc));
  1775. } else {
  1776. ahc_outb(ahc, CLRINT, CLRPARERR);
  1777. }
  1778. if (ahc->pci_target_perr_count > AHC_PCI_TARGET_PERR_THRESH) {
  1779. printf(
  1780. "%s: WARNING WARNING WARNING WARNING\n"
  1781. "%s: Too many PCI parity errors observed as a target.\n"
  1782. "%s: Some device on this bus is generating bad parity.\n"
  1783. "%s: This is an error *observed by*, not *generated by*, this controller.\n"
  1784. "%s: PCI parity error checking has been disabled.\n"
  1785. "%s: WARNING WARNING WARNING WARNING\n",
  1786. ahc_name(ahc), ahc_name(ahc), ahc_name(ahc),
  1787. ahc_name(ahc), ahc_name(ahc), ahc_name(ahc));
  1788. ahc->seqctl |= FAILDIS;
  1789. ahc_outb(ahc, SEQCTL, ahc->seqctl);
  1790. }
  1791. ahc_unpause(ahc);
  1792. }
  1793. static int
  1794. ahc_pci_chip_init(struct ahc_softc *ahc)
  1795. {
  1796. ahc_outb(ahc, DSCOMMAND0, ahc->bus_softc.pci_softc.dscommand0);
  1797. ahc_outb(ahc, DSPCISTATUS, ahc->bus_softc.pci_softc.dspcistatus);
  1798. if ((ahc->features & AHC_DT) != 0) {
  1799. u_int sfunct;
  1800. sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
  1801. ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
  1802. ahc_outb(ahc, OPTIONMODE, ahc->bus_softc.pci_softc.optionmode);
  1803. ahc_outw(ahc, TARGCRCCNT, ahc->bus_softc.pci_softc.targcrccnt);
  1804. ahc_outb(ahc, SFUNCT, sfunct);
  1805. ahc_outb(ahc, CRCCONTROL1,
  1806. ahc->bus_softc.pci_softc.crccontrol1);
  1807. }
  1808. if ((ahc->features & AHC_MULTI_FUNC) != 0)
  1809. ahc_outb(ahc, SCBBADDR, ahc->bus_softc.pci_softc.scbbaddr);
  1810. if ((ahc->features & AHC_ULTRA2) != 0)
  1811. ahc_outb(ahc, DFF_THRSH, ahc->bus_softc.pci_softc.dff_thrsh);
  1812. return (ahc_chip_init(ahc));
  1813. }
  1814. static int
  1815. ahc_pci_suspend(struct ahc_softc *ahc)
  1816. {
  1817. return (ahc_suspend(ahc));
  1818. }
  1819. static int
  1820. ahc_pci_resume(struct ahc_softc *ahc)
  1821. {
  1822. pci_set_power_state(ahc->dev_softc, AHC_POWER_STATE_D0);
  1823. /*
  1824. * We assume that the OS has restored our register
  1825. * mappings, etc. Just update the config space registers
  1826. * that the OS doesn't know about and rely on our chip
  1827. * reset handler to handle the rest.
  1828. */
  1829. ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4,
  1830. ahc->bus_softc.pci_softc.devconfig);
  1831. ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1,
  1832. ahc->bus_softc.pci_softc.command);
  1833. ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1,
  1834. ahc->bus_softc.pci_softc.csize_lattime);
  1835. if ((ahc->flags & AHC_HAS_TERM_LOGIC) != 0) {
  1836. struct seeprom_descriptor sd;
  1837. u_int sxfrctl1;
  1838. sd.sd_ahc = ahc;
  1839. sd.sd_control_offset = SEECTL;
  1840. sd.sd_status_offset = SEECTL;
  1841. sd.sd_dataout_offset = SEECTL;
  1842. ahc_acquire_seeprom(ahc, &sd);
  1843. configure_termination(ahc, &sd,
  1844. ahc->seep_config->adapter_control,
  1845. &sxfrctl1);
  1846. ahc_release_seeprom(&sd);
  1847. }
  1848. return (ahc_resume(ahc));
  1849. }
  1850. static int
  1851. ahc_aic785X_setup(struct ahc_softc *ahc)
  1852. {
  1853. ahc_dev_softc_t pci;
  1854. uint8_t rev;
  1855. pci = ahc->dev_softc;
  1856. ahc->channel = 'A';
  1857. ahc->chip = AHC_AIC7850;
  1858. ahc->features = AHC_AIC7850_FE;
  1859. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1860. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1861. if (rev >= 1)
  1862. ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
  1863. ahc->instruction_ram_size = 512;
  1864. return (0);
  1865. }
  1866. static int
  1867. ahc_aic7860_setup(struct ahc_softc *ahc)
  1868. {
  1869. ahc_dev_softc_t pci;
  1870. uint8_t rev;
  1871. pci = ahc->dev_softc;
  1872. ahc->channel = 'A';
  1873. ahc->chip = AHC_AIC7860;
  1874. ahc->features = AHC_AIC7860_FE;
  1875. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1876. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1877. if (rev >= 1)
  1878. ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
  1879. ahc->instruction_ram_size = 512;
  1880. return (0);
  1881. }
  1882. static int
  1883. ahc_apa1480_setup(struct ahc_softc *ahc)
  1884. {
  1885. int error;
  1886. error = ahc_aic7860_setup(ahc);
  1887. if (error != 0)
  1888. return (error);
  1889. ahc->features |= AHC_REMOVABLE;
  1890. return (0);
  1891. }
  1892. static int
  1893. ahc_aic7870_setup(struct ahc_softc *ahc)
  1894. {
  1895. ahc->channel = 'A';
  1896. ahc->chip = AHC_AIC7870;
  1897. ahc->features = AHC_AIC7870_FE;
  1898. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1899. ahc->instruction_ram_size = 512;
  1900. return (0);
  1901. }
  1902. static int
  1903. ahc_aha394X_setup(struct ahc_softc *ahc)
  1904. {
  1905. int error;
  1906. error = ahc_aic7870_setup(ahc);
  1907. if (error == 0)
  1908. error = ahc_aha394XX_setup(ahc);
  1909. return (error);
  1910. }
  1911. static int
  1912. ahc_aha398X_setup(struct ahc_softc *ahc)
  1913. {
  1914. int error;
  1915. error = ahc_aic7870_setup(ahc);
  1916. if (error == 0)
  1917. error = ahc_aha398XX_setup(ahc);
  1918. return (error);
  1919. }
  1920. static int
  1921. ahc_aha494X_setup(struct ahc_softc *ahc)
  1922. {
  1923. int error;
  1924. error = ahc_aic7870_setup(ahc);
  1925. if (error == 0)
  1926. error = ahc_aha494XX_setup(ahc);
  1927. return (error);
  1928. }
  1929. static int
  1930. ahc_aic7880_setup(struct ahc_softc *ahc)
  1931. {
  1932. ahc_dev_softc_t pci;
  1933. uint8_t rev;
  1934. pci = ahc->dev_softc;
  1935. ahc->channel = 'A';
  1936. ahc->chip = AHC_AIC7880;
  1937. ahc->features = AHC_AIC7880_FE;
  1938. ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
  1939. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1940. if (rev >= 1) {
  1941. ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
  1942. } else {
  1943. ahc->bugs |= AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
  1944. }
  1945. ahc->instruction_ram_size = 512;
  1946. return (0);
  1947. }
  1948. static int
  1949. ahc_aha2940Pro_setup(struct ahc_softc *ahc)
  1950. {
  1951. ahc->flags |= AHC_INT50_SPEEDFLEX;
  1952. return (ahc_aic7880_setup(ahc));
  1953. }
  1954. static int
  1955. ahc_aha394XU_setup(struct ahc_softc *ahc)
  1956. {
  1957. int error;
  1958. error = ahc_aic7880_setup(ahc);
  1959. if (error == 0)
  1960. error = ahc_aha394XX_setup(ahc);
  1961. return (error);
  1962. }
  1963. static int
  1964. ahc_aha398XU_setup(struct ahc_softc *ahc)
  1965. {
  1966. int error;
  1967. error = ahc_aic7880_setup(ahc);
  1968. if (error == 0)
  1969. error = ahc_aha398XX_setup(ahc);
  1970. return (error);
  1971. }
  1972. static int
  1973. ahc_aic7890_setup(struct ahc_softc *ahc)
  1974. {
  1975. ahc_dev_softc_t pci;
  1976. uint8_t rev;
  1977. pci = ahc->dev_softc;
  1978. ahc->channel = 'A';
  1979. ahc->chip = AHC_AIC7890;
  1980. ahc->features = AHC_AIC7890_FE;
  1981. ahc->flags |= AHC_NEWEEPROM_FMT;
  1982. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  1983. if (rev == 0)
  1984. ahc->bugs |= AHC_AUTOFLUSH_BUG|AHC_CACHETHEN_BUG;
  1985. ahc->instruction_ram_size = 768;
  1986. return (0);
  1987. }
  1988. static int
  1989. ahc_aic7892_setup(struct ahc_softc *ahc)
  1990. {
  1991. ahc->channel = 'A';
  1992. ahc->chip = AHC_AIC7892;
  1993. ahc->features = AHC_AIC7892_FE;
  1994. ahc->flags |= AHC_NEWEEPROM_FMT;
  1995. ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
  1996. ahc->instruction_ram_size = 1024;
  1997. return (0);
  1998. }
  1999. static int
  2000. ahc_aic7895_setup(struct ahc_softc *ahc)
  2001. {
  2002. ahc_dev_softc_t pci;
  2003. uint8_t rev;
  2004. pci = ahc->dev_softc;
  2005. ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
  2006. /*
  2007. * The 'C' revision of the aic7895 has a few additional features.
  2008. */
  2009. rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  2010. if (rev >= 4) {
  2011. ahc->chip = AHC_AIC7895C;
  2012. ahc->features = AHC_AIC7895C_FE;
  2013. } else {
  2014. u_int command;
  2015. ahc->chip = AHC_AIC7895;
  2016. ahc->features = AHC_AIC7895_FE;
  2017. /*
  2018. * The BIOS disables the use of MWI transactions
  2019. * since it does not have the MWI bug work around
  2020. * we have. Disabling MWI reduces performance, so
  2021. * turn it on again.
  2022. */
  2023. command = ahc_pci_read_config(pci, PCIR_COMMAND, /*bytes*/1);
  2024. command |= PCIM_CMD_MWRICEN;
  2025. ahc_pci_write_config(pci, PCIR_COMMAND, command, /*bytes*/1);
  2026. ahc->bugs |= AHC_PCI_MWI_BUG;
  2027. }
  2028. /*
  2029. * XXX Does CACHETHEN really not work??? What about PCI retry?
  2030. * on C level chips. Need to test, but for now, play it safe.
  2031. */
  2032. ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_PCI_2_1_RETRY_BUG
  2033. | AHC_CACHETHEN_BUG;
  2034. #if 0
  2035. uint32_t devconfig;
  2036. /*
  2037. * Cachesize must also be zero due to stray DAC
  2038. * problem when sitting behind some bridges.
  2039. */
  2040. ahc_pci_write_config(pci, CSIZE_LATTIME, 0, /*bytes*/1);
  2041. devconfig = ahc_pci_read_config(pci, DEVCONFIG, /*bytes*/1);
  2042. devconfig |= MRDCEN;
  2043. ahc_pci_write_config(pci, DEVCONFIG, devconfig, /*bytes*/1);
  2044. #endif
  2045. ahc->flags |= AHC_NEWEEPROM_FMT;
  2046. ahc->instruction_ram_size = 512;
  2047. return (0);
  2048. }
  2049. static int
  2050. ahc_aic7896_setup(struct ahc_softc *ahc)
  2051. {
  2052. ahc_dev_softc_t pci;
  2053. pci = ahc->dev_softc;
  2054. ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
  2055. ahc->chip = AHC_AIC7896;
  2056. ahc->features = AHC_AIC7896_FE;
  2057. ahc->flags |= AHC_NEWEEPROM_FMT;
  2058. ahc->bugs |= AHC_CACHETHEN_DIS_BUG;
  2059. ahc->instruction_ram_size = 768;
  2060. return (0);
  2061. }
  2062. static int
  2063. ahc_aic7899_setup(struct ahc_softc *ahc)
  2064. {
  2065. ahc_dev_softc_t pci;
  2066. pci = ahc->dev_softc;
  2067. ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
  2068. ahc->chip = AHC_AIC7899;
  2069. ahc->features = AHC_AIC7899_FE;
  2070. ahc->flags |= AHC_NEWEEPROM_FMT;
  2071. ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
  2072. ahc->instruction_ram_size = 1024;
  2073. return (0);
  2074. }
  2075. static int
  2076. ahc_aha29160C_setup(struct ahc_softc *ahc)
  2077. {
  2078. int error;
  2079. error = ahc_aic7899_setup(ahc);
  2080. if (error != 0)
  2081. return (error);
  2082. ahc->features |= AHC_REMOVABLE;
  2083. return (0);
  2084. }
  2085. static int
  2086. ahc_raid_setup(struct ahc_softc *ahc)
  2087. {
  2088. printf("RAID functionality unsupported\n");
  2089. return (ENXIO);
  2090. }
  2091. static int
  2092. ahc_aha394XX_setup(struct ahc_softc *ahc)
  2093. {
  2094. ahc_dev_softc_t pci;
  2095. pci = ahc->dev_softc;
  2096. switch (ahc_get_pci_slot(pci)) {
  2097. case AHC_394X_SLOT_CHANNEL_A:
  2098. ahc->channel = 'A';
  2099. break;
  2100. case AHC_394X_SLOT_CHANNEL_B:
  2101. ahc->channel = 'B';
  2102. break;
  2103. default:
  2104. printf("adapter at unexpected slot %d\n"
  2105. "unable to map to a channel\n",
  2106. ahc_get_pci_slot(pci));
  2107. ahc->channel = 'A';
  2108. }
  2109. return (0);
  2110. }
  2111. static int
  2112. ahc_aha398XX_setup(struct ahc_softc *ahc)
  2113. {
  2114. ahc_dev_softc_t pci;
  2115. pci = ahc->dev_softc;
  2116. switch (ahc_get_pci_slot(pci)) {
  2117. case AHC_398X_SLOT_CHANNEL_A:
  2118. ahc->channel = 'A';
  2119. break;
  2120. case AHC_398X_SLOT_CHANNEL_B:
  2121. ahc->channel = 'B';
  2122. break;
  2123. case AHC_398X_SLOT_CHANNEL_C:
  2124. ahc->channel = 'C';
  2125. break;
  2126. default:
  2127. printf("adapter at unexpected slot %d\n"
  2128. "unable to map to a channel\n",
  2129. ahc_get_pci_slot(pci));
  2130. ahc->channel = 'A';
  2131. break;
  2132. }
  2133. ahc->flags |= AHC_LARGE_SEEPROM;
  2134. return (0);
  2135. }
  2136. static int
  2137. ahc_aha494XX_setup(struct ahc_softc *ahc)
  2138. {
  2139. ahc_dev_softc_t pci;
  2140. pci = ahc->dev_softc;
  2141. switch (ahc_get_pci_slot(pci)) {
  2142. case AHC_494X_SLOT_CHANNEL_A:
  2143. ahc->channel = 'A';
  2144. break;
  2145. case AHC_494X_SLOT_CHANNEL_B:
  2146. ahc->channel = 'B';
  2147. break;
  2148. case AHC_494X_SLOT_CHANNEL_C:
  2149. ahc->channel = 'C';
  2150. break;
  2151. case AHC_494X_SLOT_CHANNEL_D:
  2152. ahc->channel = 'D';
  2153. break;
  2154. default:
  2155. printf("adapter at unexpected slot %d\n"
  2156. "unable to map to a channel\n",
  2157. ahc_get_pci_slot(pci));
  2158. ahc->channel = 'A';
  2159. }
  2160. ahc->flags |= AHC_LARGE_SEEPROM;
  2161. return (0);
  2162. }