aic7xxx_pci.c 60 KB

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