aic7xxx_pci.c 60 KB

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