aic7xxx_pci.c 60 KB

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