aic7xxx_pci.c 60 KB

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