aic7xxx_pci.c 60 KB

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