aic7xxx_pci.c 61 KB

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