aic79xx_pci.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. /*
  2. * Product specific probe and attach routines for:
  3. * aic7901 and aic7902 SCSI controllers
  4. *
  5. * Copyright (c) 1994-2001 Justin T. Gibbs.
  6. * Copyright (c) 2000-2002 Adaptec Inc.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions, and the following disclaimer,
  14. * without modification.
  15. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  16. * substantially similar to the "NO WARRANTY" disclaimer below
  17. * ("Disclaimer") and any redistribution must be conditioned upon
  18. * including a substantially similar Disclaimer requirement for further
  19. * binary redistribution.
  20. * 3. Neither the names of the above-listed copyright holders nor the names
  21. * of any contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * Alternatively, this software may be distributed under the terms of the
  25. * GNU General Public License ("GPL") version 2 as published by the Free
  26. * Software Foundation.
  27. *
  28. * NO WARRANTY
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  32. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  37. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  38. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGES.
  40. *
  41. * $Id: //depot/aic7xxx/aic7xxx/aic79xx_pci.c#92 $
  42. */
  43. #ifdef __linux__
  44. #include "aic79xx_osm.h"
  45. #include "aic79xx_inline.h"
  46. #else
  47. #include <dev/aic7xxx/aic79xx_osm.h>
  48. #include <dev/aic7xxx/aic79xx_inline.h>
  49. #endif
  50. #include "aic79xx_pci.h"
  51. static __inline uint64_t
  52. ahd_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
  53. {
  54. uint64_t id;
  55. id = subvendor
  56. | (subdevice << 16)
  57. | ((uint64_t)vendor << 32)
  58. | ((uint64_t)device << 48);
  59. return (id);
  60. }
  61. #define ID_AIC7902_PCI_REV_A4 0x3
  62. #define ID_AIC7902_PCI_REV_B0 0x10
  63. #define SUBID_HP 0x0E11
  64. #define DEVID_9005_HOSTRAID(id) ((id) & 0x80)
  65. #define DEVID_9005_TYPE(id) ((id) & 0xF)
  66. #define DEVID_9005_TYPE_HBA 0x0 /* Standard Card */
  67. #define DEVID_9005_TYPE_HBA_2EXT 0x1 /* 2 External Ports */
  68. #define DEVID_9005_TYPE_IROC 0x8 /* Raid(0,1,10) Card */
  69. #define DEVID_9005_TYPE_MB 0xF /* On Motherboard */
  70. #define DEVID_9005_MFUNC(id) ((id) & 0x10)
  71. #define DEVID_9005_PACKETIZED(id) ((id) & 0x8000)
  72. #define SUBID_9005_TYPE(id) ((id) & 0xF)
  73. #define SUBID_9005_TYPE_HBA 0x0 /* Standard Card */
  74. #define SUBID_9005_TYPE_MB 0xF /* On Motherboard */
  75. #define SUBID_9005_AUTOTERM(id) (((id) & 0x10) == 0)
  76. #define SUBID_9005_LEGACYCONN_FUNC(id) ((id) & 0x20)
  77. #define SUBID_9005_SEEPTYPE(id) ((id) & 0x0C0) >> 6)
  78. #define SUBID_9005_SEEPTYPE_NONE 0x0
  79. #define SUBID_9005_SEEPTYPE_4K 0x1
  80. static ahd_device_setup_t ahd_aic7901_setup;
  81. static ahd_device_setup_t ahd_aic7901A_setup;
  82. static ahd_device_setup_t ahd_aic7902_setup;
  83. static ahd_device_setup_t ahd_aic790X_setup;
  84. struct ahd_pci_identity ahd_pci_ident_table [] =
  85. {
  86. /* aic7901 based controllers */
  87. {
  88. ID_AHA_29320A,
  89. ID_ALL_MASK,
  90. "Adaptec 29320A Ultra320 SCSI adapter",
  91. ahd_aic7901_setup
  92. },
  93. {
  94. ID_AHA_29320ALP,
  95. ID_ALL_MASK,
  96. "Adaptec 29320ALP Ultra320 SCSI adapter",
  97. ahd_aic7901_setup
  98. },
  99. /* aic7901A based controllers */
  100. {
  101. ID_AHA_29320LP,
  102. ID_ALL_MASK,
  103. "Adaptec 29320LP Ultra320 SCSI adapter",
  104. ahd_aic7901A_setup
  105. },
  106. /* aic7902 based controllers */
  107. {
  108. ID_AHA_29320,
  109. ID_ALL_MASK,
  110. "Adaptec 29320 Ultra320 SCSI adapter",
  111. ahd_aic7902_setup
  112. },
  113. {
  114. ID_AHA_29320B,
  115. ID_ALL_MASK,
  116. "Adaptec 29320B Ultra320 SCSI adapter",
  117. ahd_aic7902_setup
  118. },
  119. {
  120. ID_AHA_39320,
  121. ID_ALL_MASK,
  122. "Adaptec 39320 Ultra320 SCSI adapter",
  123. ahd_aic7902_setup
  124. },
  125. {
  126. ID_AHA_39320_B,
  127. ID_ALL_MASK,
  128. "Adaptec 39320 Ultra320 SCSI adapter",
  129. ahd_aic7902_setup
  130. },
  131. {
  132. ID_AHA_39320_B_DELL,
  133. ID_ALL_MASK,
  134. "Adaptec (Dell OEM) 39320 Ultra320 SCSI adapter",
  135. ahd_aic7902_setup
  136. },
  137. {
  138. ID_AHA_39320A,
  139. ID_ALL_MASK,
  140. "Adaptec 39320A Ultra320 SCSI adapter",
  141. ahd_aic7902_setup
  142. },
  143. {
  144. ID_AHA_39320D,
  145. ID_ALL_MASK,
  146. "Adaptec 39320D Ultra320 SCSI adapter",
  147. ahd_aic7902_setup
  148. },
  149. {
  150. ID_AHA_39320D_HP,
  151. ID_ALL_MASK,
  152. "Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
  153. ahd_aic7902_setup
  154. },
  155. {
  156. ID_AHA_39320D_B,
  157. ID_ALL_MASK,
  158. "Adaptec 39320D Ultra320 SCSI adapter",
  159. ahd_aic7902_setup
  160. },
  161. {
  162. ID_AHA_39320D_B_HP,
  163. ID_ALL_MASK,
  164. "Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
  165. ahd_aic7902_setup
  166. },
  167. /* Generic chip probes for devices we don't know 'exactly' */
  168. {
  169. ID_AIC7901 & ID_9005_GENERIC_MASK,
  170. ID_9005_GENERIC_MASK,
  171. "Adaptec AIC7901 Ultra320 SCSI adapter",
  172. ahd_aic7901_setup
  173. },
  174. {
  175. ID_AIC7901A & ID_DEV_VENDOR_MASK,
  176. ID_DEV_VENDOR_MASK,
  177. "Adaptec AIC7901A Ultra320 SCSI adapter",
  178. ahd_aic7901A_setup
  179. },
  180. {
  181. ID_AIC7902 & ID_9005_GENERIC_MASK,
  182. ID_9005_GENERIC_MASK,
  183. "Adaptec AIC7902 Ultra320 SCSI adapter",
  184. ahd_aic7902_setup
  185. }
  186. };
  187. const u_int ahd_num_pci_devs = ARRAY_SIZE(ahd_pci_ident_table);
  188. #define DEVCONFIG 0x40
  189. #define PCIXINITPAT 0x0000E000ul
  190. #define PCIXINIT_PCI33_66 0x0000E000ul
  191. #define PCIXINIT_PCIX50_66 0x0000C000ul
  192. #define PCIXINIT_PCIX66_100 0x0000A000ul
  193. #define PCIXINIT_PCIX100_133 0x00008000ul
  194. #define PCI_BUS_MODES_INDEX(devconfig) \
  195. (((devconfig) & PCIXINITPAT) >> 13)
  196. static const char *pci_bus_modes[] =
  197. {
  198. "PCI bus mode unknown",
  199. "PCI bus mode unknown",
  200. "PCI bus mode unknown",
  201. "PCI bus mode unknown",
  202. "PCI-X 101-133Mhz",
  203. "PCI-X 67-100Mhz",
  204. "PCI-X 50-66Mhz",
  205. "PCI 33 or 66Mhz"
  206. };
  207. #define TESTMODE 0x00000800ul
  208. #define IRDY_RST 0x00000200ul
  209. #define FRAME_RST 0x00000100ul
  210. #define PCI64BIT 0x00000080ul
  211. #define MRDCEN 0x00000040ul
  212. #define ENDIANSEL 0x00000020ul
  213. #define MIXQWENDIANEN 0x00000008ul
  214. #define DACEN 0x00000004ul
  215. #define STPWLEVEL 0x00000002ul
  216. #define QWENDIANSEL 0x00000001ul
  217. #define DEVCONFIG1 0x44
  218. #define PREQDIS 0x01
  219. #define CSIZE_LATTIME 0x0c
  220. #define CACHESIZE 0x000000fful
  221. #define LATTIME 0x0000ff00ul
  222. static int ahd_check_extport(struct ahd_softc *ahd);
  223. static void ahd_configure_termination(struct ahd_softc *ahd,
  224. u_int adapter_control);
  225. static void ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat);
  226. struct ahd_pci_identity *
  227. ahd_find_pci_device(ahd_dev_softc_t pci)
  228. {
  229. uint64_t full_id;
  230. uint16_t device;
  231. uint16_t vendor;
  232. uint16_t subdevice;
  233. uint16_t subvendor;
  234. struct ahd_pci_identity *entry;
  235. u_int i;
  236. vendor = ahd_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
  237. device = ahd_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
  238. subvendor = ahd_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
  239. subdevice = ahd_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
  240. full_id = ahd_compose_id(device,
  241. vendor,
  242. subdevice,
  243. subvendor);
  244. /*
  245. * Controllers, mask out the IROC/HostRAID bit
  246. */
  247. full_id &= ID_ALL_IROC_MASK;
  248. for (i = 0; i < ahd_num_pci_devs; i++) {
  249. entry = &ahd_pci_ident_table[i];
  250. if (entry->full_id == (full_id & entry->id_mask)) {
  251. /* Honor exclusion entries. */
  252. if (entry->name == NULL)
  253. return (NULL);
  254. return (entry);
  255. }
  256. }
  257. return (NULL);
  258. }
  259. int
  260. ahd_pci_config(struct ahd_softc *ahd, struct ahd_pci_identity *entry)
  261. {
  262. struct scb_data *shared_scb_data;
  263. u_int command;
  264. uint32_t devconfig;
  265. uint16_t subvendor;
  266. int error;
  267. shared_scb_data = NULL;
  268. ahd->description = entry->name;
  269. /*
  270. * Record if this is an HP board.
  271. */
  272. subvendor = ahd_pci_read_config(ahd->dev_softc,
  273. PCIR_SUBVEND_0, /*bytes*/2);
  274. if (subvendor == SUBID_HP)
  275. ahd->flags |= AHD_HP_BOARD;
  276. error = entry->setup(ahd);
  277. if (error != 0)
  278. return (error);
  279. devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
  280. if ((devconfig & PCIXINITPAT) == PCIXINIT_PCI33_66) {
  281. ahd->chip |= AHD_PCI;
  282. /* Disable PCIX workarounds when running in PCI mode. */
  283. ahd->bugs &= ~AHD_PCIX_BUG_MASK;
  284. } else {
  285. ahd->chip |= AHD_PCIX;
  286. }
  287. ahd->bus_description = pci_bus_modes[PCI_BUS_MODES_INDEX(devconfig)];
  288. ahd_power_state_change(ahd, AHD_POWER_STATE_D0);
  289. error = ahd_pci_map_registers(ahd);
  290. if (error != 0)
  291. return (error);
  292. /*
  293. * If we need to support high memory, enable dual
  294. * address cycles. This bit must be set to enable
  295. * high address bit generation even if we are on a
  296. * 64bit bus (PCI64BIT set in devconfig).
  297. */
  298. if ((ahd->flags & (AHD_39BIT_ADDRESSING|AHD_64BIT_ADDRESSING)) != 0) {
  299. uint32_t devconfig;
  300. if (bootverbose)
  301. printf("%s: Enabling 39Bit Addressing\n",
  302. ahd_name(ahd));
  303. devconfig = ahd_pci_read_config(ahd->dev_softc,
  304. DEVCONFIG, /*bytes*/4);
  305. devconfig |= DACEN;
  306. ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
  307. devconfig, /*bytes*/4);
  308. }
  309. /* Ensure busmastering is enabled */
  310. command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
  311. command |= PCIM_CMD_BUSMASTEREN;
  312. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
  313. error = ahd_softc_init(ahd);
  314. if (error != 0)
  315. return (error);
  316. ahd->bus_intr = ahd_pci_intr;
  317. error = ahd_reset(ahd, /*reinit*/FALSE);
  318. if (error != 0)
  319. return (ENXIO);
  320. ahd->pci_cachesize =
  321. ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME,
  322. /*bytes*/1) & CACHESIZE;
  323. ahd->pci_cachesize *= 4;
  324. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  325. /* See if we have a SEEPROM and perform auto-term */
  326. error = ahd_check_extport(ahd);
  327. if (error != 0)
  328. return (error);
  329. /* Core initialization */
  330. error = ahd_init(ahd);
  331. if (error != 0)
  332. return (error);
  333. /*
  334. * Allow interrupts now that we are completely setup.
  335. */
  336. error = ahd_pci_map_int(ahd);
  337. if (!error)
  338. ahd->init_level++;
  339. return error;
  340. }
  341. /*
  342. * Perform some simple tests that should catch situations where
  343. * our registers are invalidly mapped.
  344. */
  345. int
  346. ahd_pci_test_register_access(struct ahd_softc *ahd)
  347. {
  348. uint32_t cmd;
  349. u_int targpcistat;
  350. u_int pci_status1;
  351. int error;
  352. uint8_t hcntrl;
  353. error = EIO;
  354. /*
  355. * Enable PCI error interrupt status, but suppress NMIs
  356. * generated by SERR raised due to target aborts.
  357. */
  358. cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
  359. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
  360. cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
  361. /*
  362. * First a simple test to see if any
  363. * registers can be read. Reading
  364. * HCNTRL has no side effects and has
  365. * at least one bit that is guaranteed to
  366. * be zero so it is a good register to
  367. * use for this test.
  368. */
  369. hcntrl = ahd_inb(ahd, HCNTRL);
  370. if (hcntrl == 0xFF)
  371. goto fail;
  372. /*
  373. * Next create a situation where write combining
  374. * or read prefetching could be initiated by the
  375. * CPU or host bridge. Our device does not support
  376. * either, so look for data corruption and/or flaged
  377. * PCI errors. First pause without causing another
  378. * chip reset.
  379. */
  380. hcntrl &= ~CHIPRST;
  381. ahd_outb(ahd, HCNTRL, hcntrl|PAUSE);
  382. while (ahd_is_paused(ahd) == 0)
  383. ;
  384. /* Clear any PCI errors that occurred before our driver attached. */
  385. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  386. targpcistat = ahd_inb(ahd, TARGPCISTAT);
  387. ahd_outb(ahd, TARGPCISTAT, targpcistat);
  388. pci_status1 = ahd_pci_read_config(ahd->dev_softc,
  389. PCIR_STATUS + 1, /*bytes*/1);
  390. ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
  391. pci_status1, /*bytes*/1);
  392. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  393. ahd_outb(ahd, CLRINT, CLRPCIINT);
  394. ahd_outb(ahd, SEQCTL0, PERRORDIS);
  395. ahd_outl(ahd, SRAM_BASE, 0x5aa555aa);
  396. if (ahd_inl(ahd, SRAM_BASE) != 0x5aa555aa)
  397. goto fail;
  398. if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
  399. u_int targpcistat;
  400. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  401. targpcistat = ahd_inb(ahd, TARGPCISTAT);
  402. if ((targpcistat & STA) != 0)
  403. goto fail;
  404. }
  405. error = 0;
  406. fail:
  407. if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
  408. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  409. targpcistat = ahd_inb(ahd, TARGPCISTAT);
  410. /* Silently clear any latched errors. */
  411. ahd_outb(ahd, TARGPCISTAT, targpcistat);
  412. pci_status1 = ahd_pci_read_config(ahd->dev_softc,
  413. PCIR_STATUS + 1, /*bytes*/1);
  414. ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
  415. pci_status1, /*bytes*/1);
  416. ahd_outb(ahd, CLRINT, CLRPCIINT);
  417. }
  418. ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS);
  419. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
  420. return (error);
  421. }
  422. /*
  423. * Check the external port logic for a serial eeprom
  424. * and termination/cable detection contrls.
  425. */
  426. static int
  427. ahd_check_extport(struct ahd_softc *ahd)
  428. {
  429. struct vpd_config vpd;
  430. struct seeprom_config *sc;
  431. u_int adapter_control;
  432. int have_seeprom;
  433. int error;
  434. sc = ahd->seep_config;
  435. have_seeprom = ahd_acquire_seeprom(ahd);
  436. if (have_seeprom) {
  437. u_int start_addr;
  438. /*
  439. * Fetch VPD for this function and parse it.
  440. */
  441. if (bootverbose)
  442. printf("%s: Reading VPD from SEEPROM...",
  443. ahd_name(ahd));
  444. /* Address is always in units of 16bit words */
  445. start_addr = ((2 * sizeof(*sc))
  446. + (sizeof(vpd) * (ahd->channel - 'A'))) / 2;
  447. error = ahd_read_seeprom(ahd, (uint16_t *)&vpd,
  448. start_addr, sizeof(vpd)/2,
  449. /*bytestream*/TRUE);
  450. if (error == 0)
  451. error = ahd_parse_vpddata(ahd, &vpd);
  452. if (bootverbose)
  453. printf("%s: VPD parsing %s\n",
  454. ahd_name(ahd),
  455. error == 0 ? "successful" : "failed");
  456. if (bootverbose)
  457. printf("%s: Reading SEEPROM...", ahd_name(ahd));
  458. /* Address is always in units of 16bit words */
  459. start_addr = (sizeof(*sc) / 2) * (ahd->channel - 'A');
  460. error = ahd_read_seeprom(ahd, (uint16_t *)sc,
  461. start_addr, sizeof(*sc)/2,
  462. /*bytestream*/FALSE);
  463. if (error != 0) {
  464. printf("Unable to read SEEPROM\n");
  465. have_seeprom = 0;
  466. } else {
  467. have_seeprom = ahd_verify_cksum(sc);
  468. if (bootverbose) {
  469. if (have_seeprom == 0)
  470. printf ("checksum error\n");
  471. else
  472. printf ("done.\n");
  473. }
  474. }
  475. ahd_release_seeprom(ahd);
  476. }
  477. if (!have_seeprom) {
  478. u_int nvram_scb;
  479. /*
  480. * Pull scratch ram settings and treat them as
  481. * if they are the contents of an seeprom if
  482. * the 'ADPT', 'BIOS', or 'ASPI' signature is found
  483. * in SCB 0xFF. We manually compose the data as 16bit
  484. * values to avoid endian issues.
  485. */
  486. ahd_set_scbptr(ahd, 0xFF);
  487. nvram_scb = ahd_inb_scbram(ahd, SCB_BASE + NVRAM_SCB_OFFSET);
  488. if (nvram_scb != 0xFF
  489. && ((ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
  490. && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'D'
  491. && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
  492. && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'T')
  493. || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'B'
  494. && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'I'
  495. && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'O'
  496. && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'S')
  497. || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
  498. && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'S'
  499. && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
  500. && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'I'))) {
  501. uint16_t *sc_data;
  502. int i;
  503. ahd_set_scbptr(ahd, nvram_scb);
  504. sc_data = (uint16_t *)sc;
  505. for (i = 0; i < 64; i += 2)
  506. *sc_data++ = ahd_inw_scbram(ahd, SCB_BASE+i);
  507. have_seeprom = ahd_verify_cksum(sc);
  508. if (have_seeprom)
  509. ahd->flags |= AHD_SCB_CONFIG_USED;
  510. }
  511. }
  512. #ifdef AHD_DEBUG
  513. if (have_seeprom != 0
  514. && (ahd_debug & AHD_DUMP_SEEPROM) != 0) {
  515. uint16_t *sc_data;
  516. int i;
  517. printf("%s: Seeprom Contents:", ahd_name(ahd));
  518. sc_data = (uint16_t *)sc;
  519. for (i = 0; i < (sizeof(*sc)); i += 2)
  520. printf("\n\t0x%.4x", sc_data[i]);
  521. printf("\n");
  522. }
  523. #endif
  524. if (!have_seeprom) {
  525. if (bootverbose)
  526. printf("%s: No SEEPROM available.\n", ahd_name(ahd));
  527. ahd->flags |= AHD_USEDEFAULTS;
  528. error = ahd_default_config(ahd);
  529. adapter_control = CFAUTOTERM|CFSEAUTOTERM;
  530. free(ahd->seep_config, M_DEVBUF);
  531. ahd->seep_config = NULL;
  532. } else {
  533. error = ahd_parse_cfgdata(ahd, sc);
  534. adapter_control = sc->adapter_control;
  535. }
  536. if (error != 0)
  537. return (error);
  538. ahd_configure_termination(ahd, adapter_control);
  539. return (0);
  540. }
  541. static void
  542. ahd_configure_termination(struct ahd_softc *ahd, u_int adapter_control)
  543. {
  544. int error;
  545. u_int sxfrctl1;
  546. uint8_t termctl;
  547. uint32_t devconfig;
  548. devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
  549. devconfig &= ~STPWLEVEL;
  550. if ((ahd->flags & AHD_STPWLEVEL_A) != 0)
  551. devconfig |= STPWLEVEL;
  552. if (bootverbose)
  553. printf("%s: STPWLEVEL is %s\n",
  554. ahd_name(ahd), (devconfig & STPWLEVEL) ? "on" : "off");
  555. ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
  556. /* Make sure current sensing is off. */
  557. if ((ahd->flags & AHD_CURRENT_SENSING) != 0) {
  558. (void)ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
  559. }
  560. /*
  561. * Read to sense. Write to set.
  562. */
  563. error = ahd_read_flexport(ahd, FLXADDR_TERMCTL, &termctl);
  564. if ((adapter_control & CFAUTOTERM) == 0) {
  565. if (bootverbose)
  566. printf("%s: Manual Primary Termination\n",
  567. ahd_name(ahd));
  568. termctl &= ~(FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH);
  569. if ((adapter_control & CFSTERM) != 0)
  570. termctl |= FLX_TERMCTL_ENPRILOW;
  571. if ((adapter_control & CFWSTERM) != 0)
  572. termctl |= FLX_TERMCTL_ENPRIHIGH;
  573. } else if (error != 0) {
  574. printf("%s: Primary Auto-Term Sensing failed! "
  575. "Using Defaults.\n", ahd_name(ahd));
  576. termctl = FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH;
  577. }
  578. if ((adapter_control & CFSEAUTOTERM) == 0) {
  579. if (bootverbose)
  580. printf("%s: Manual Secondary Termination\n",
  581. ahd_name(ahd));
  582. termctl &= ~(FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH);
  583. if ((adapter_control & CFSELOWTERM) != 0)
  584. termctl |= FLX_TERMCTL_ENSECLOW;
  585. if ((adapter_control & CFSEHIGHTERM) != 0)
  586. termctl |= FLX_TERMCTL_ENSECHIGH;
  587. } else if (error != 0) {
  588. printf("%s: Secondary Auto-Term Sensing failed! "
  589. "Using Defaults.\n", ahd_name(ahd));
  590. termctl |= FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH;
  591. }
  592. /*
  593. * Now set the termination based on what we found.
  594. */
  595. sxfrctl1 = ahd_inb(ahd, SXFRCTL1) & ~STPWEN;
  596. ahd->flags &= ~AHD_TERM_ENB_A;
  597. if ((termctl & FLX_TERMCTL_ENPRILOW) != 0) {
  598. ahd->flags |= AHD_TERM_ENB_A;
  599. sxfrctl1 |= STPWEN;
  600. }
  601. /* Must set the latch once in order to be effective. */
  602. ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
  603. ahd_outb(ahd, SXFRCTL1, sxfrctl1);
  604. error = ahd_write_flexport(ahd, FLXADDR_TERMCTL, termctl);
  605. if (error != 0) {
  606. printf("%s: Unable to set termination settings!\n",
  607. ahd_name(ahd));
  608. } else if (bootverbose) {
  609. printf("%s: Primary High byte termination %sabled\n",
  610. ahd_name(ahd),
  611. (termctl & FLX_TERMCTL_ENPRIHIGH) ? "En" : "Dis");
  612. printf("%s: Primary Low byte termination %sabled\n",
  613. ahd_name(ahd),
  614. (termctl & FLX_TERMCTL_ENPRILOW) ? "En" : "Dis");
  615. printf("%s: Secondary High byte termination %sabled\n",
  616. ahd_name(ahd),
  617. (termctl & FLX_TERMCTL_ENSECHIGH) ? "En" : "Dis");
  618. printf("%s: Secondary Low byte termination %sabled\n",
  619. ahd_name(ahd),
  620. (termctl & FLX_TERMCTL_ENSECLOW) ? "En" : "Dis");
  621. }
  622. return;
  623. }
  624. #define DPE 0x80
  625. #define SSE 0x40
  626. #define RMA 0x20
  627. #define RTA 0x10
  628. #define STA 0x08
  629. #define DPR 0x01
  630. static const char *split_status_source[] =
  631. {
  632. "DFF0",
  633. "DFF1",
  634. "OVLY",
  635. "CMC",
  636. };
  637. static const char *pci_status_source[] =
  638. {
  639. "DFF0",
  640. "DFF1",
  641. "SG",
  642. "CMC",
  643. "OVLY",
  644. "NONE",
  645. "MSI",
  646. "TARG"
  647. };
  648. static const char *split_status_strings[] =
  649. {
  650. "%s: Received split response in %s.\n",
  651. "%s: Received split completion error message in %s\n",
  652. "%s: Receive overrun in %s\n",
  653. "%s: Count not complete in %s\n",
  654. "%s: Split completion data bucket in %s\n",
  655. "%s: Split completion address error in %s\n",
  656. "%s: Split completion byte count error in %s\n",
  657. "%s: Signaled Target-abort to early terminate a split in %s\n"
  658. };
  659. static const char *pci_status_strings[] =
  660. {
  661. "%s: Data Parity Error has been reported via PERR# in %s\n",
  662. "%s: Target initial wait state error in %s\n",
  663. "%s: Split completion read data parity error in %s\n",
  664. "%s: Split completion address attribute parity error in %s\n",
  665. "%s: Received a Target Abort in %s\n",
  666. "%s: Received a Master Abort in %s\n",
  667. "%s: Signal System Error Detected in %s\n",
  668. "%s: Address or Write Phase Parity Error Detected in %s.\n"
  669. };
  670. void
  671. ahd_pci_intr(struct ahd_softc *ahd)
  672. {
  673. uint8_t pci_status[8];
  674. ahd_mode_state saved_modes;
  675. u_int pci_status1;
  676. u_int intstat;
  677. u_int i;
  678. u_int reg;
  679. intstat = ahd_inb(ahd, INTSTAT);
  680. if ((intstat & SPLTINT) != 0)
  681. ahd_pci_split_intr(ahd, intstat);
  682. if ((intstat & PCIINT) == 0)
  683. return;
  684. printf("%s: PCI error Interrupt\n", ahd_name(ahd));
  685. saved_modes = ahd_save_modes(ahd);
  686. ahd_dump_card_state(ahd);
  687. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  688. for (i = 0, reg = DF0PCISTAT; i < 8; i++, reg++) {
  689. if (i == 5)
  690. continue;
  691. pci_status[i] = ahd_inb(ahd, reg);
  692. /* Clear latched errors. So our interrupt deasserts. */
  693. ahd_outb(ahd, reg, pci_status[i]);
  694. }
  695. for (i = 0; i < 8; i++) {
  696. u_int bit;
  697. if (i == 5)
  698. continue;
  699. for (bit = 0; bit < 8; bit++) {
  700. if ((pci_status[i] & (0x1 << bit)) != 0) {
  701. static const char *s;
  702. s = pci_status_strings[bit];
  703. if (i == 7/*TARG*/ && bit == 3)
  704. s = "%s: Signaled Target Abort\n";
  705. printf(s, ahd_name(ahd), pci_status_source[i]);
  706. }
  707. }
  708. }
  709. pci_status1 = ahd_pci_read_config(ahd->dev_softc,
  710. PCIR_STATUS + 1, /*bytes*/1);
  711. ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
  712. pci_status1, /*bytes*/1);
  713. ahd_restore_modes(ahd, saved_modes);
  714. ahd_outb(ahd, CLRINT, CLRPCIINT);
  715. ahd_unpause(ahd);
  716. }
  717. static void
  718. ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
  719. {
  720. uint8_t split_status[4];
  721. uint8_t split_status1[4];
  722. uint8_t sg_split_status[2];
  723. uint8_t sg_split_status1[2];
  724. ahd_mode_state saved_modes;
  725. u_int i;
  726. uint16_t pcix_status;
  727. /*
  728. * Check for splits in all modes. Modes 0 and 1
  729. * additionally have SG engine splits to look at.
  730. */
  731. pcix_status = ahd_pci_read_config(ahd->dev_softc, PCIXR_STATUS,
  732. /*bytes*/2);
  733. printf("%s: PCI Split Interrupt - PCI-X status = 0x%x\n",
  734. ahd_name(ahd), pcix_status);
  735. saved_modes = ahd_save_modes(ahd);
  736. for (i = 0; i < 4; i++) {
  737. ahd_set_modes(ahd, i, i);
  738. split_status[i] = ahd_inb(ahd, DCHSPLTSTAT0);
  739. split_status1[i] = ahd_inb(ahd, DCHSPLTSTAT1);
  740. /* Clear latched errors. So our interrupt deasserts. */
  741. ahd_outb(ahd, DCHSPLTSTAT0, split_status[i]);
  742. ahd_outb(ahd, DCHSPLTSTAT1, split_status1[i]);
  743. if (i > 1)
  744. continue;
  745. sg_split_status[i] = ahd_inb(ahd, SGSPLTSTAT0);
  746. sg_split_status1[i] = ahd_inb(ahd, SGSPLTSTAT1);
  747. /* Clear latched errors. So our interrupt deasserts. */
  748. ahd_outb(ahd, SGSPLTSTAT0, sg_split_status[i]);
  749. ahd_outb(ahd, SGSPLTSTAT1, sg_split_status1[i]);
  750. }
  751. for (i = 0; i < 4; i++) {
  752. u_int bit;
  753. for (bit = 0; bit < 8; bit++) {
  754. if ((split_status[i] & (0x1 << bit)) != 0) {
  755. static const char *s;
  756. s = split_status_strings[bit];
  757. printf(s, ahd_name(ahd),
  758. split_status_source[i]);
  759. }
  760. if (i > 1)
  761. continue;
  762. if ((sg_split_status[i] & (0x1 << bit)) != 0) {
  763. static const char *s;
  764. s = split_status_strings[bit];
  765. printf(s, ahd_name(ahd), "SG");
  766. }
  767. }
  768. }
  769. /*
  770. * Clear PCI-X status bits.
  771. */
  772. ahd_pci_write_config(ahd->dev_softc, PCIXR_STATUS,
  773. pcix_status, /*bytes*/2);
  774. ahd_outb(ahd, CLRINT, CLRSPLTINT);
  775. ahd_restore_modes(ahd, saved_modes);
  776. }
  777. static int
  778. ahd_aic7901_setup(struct ahd_softc *ahd)
  779. {
  780. ahd->chip = AHD_AIC7901;
  781. ahd->features = AHD_AIC7901_FE;
  782. return (ahd_aic790X_setup(ahd));
  783. }
  784. static int
  785. ahd_aic7901A_setup(struct ahd_softc *ahd)
  786. {
  787. ahd->chip = AHD_AIC7901A;
  788. ahd->features = AHD_AIC7901A_FE;
  789. return (ahd_aic790X_setup(ahd));
  790. }
  791. static int
  792. ahd_aic7902_setup(struct ahd_softc *ahd)
  793. {
  794. ahd->chip = AHD_AIC7902;
  795. ahd->features = AHD_AIC7902_FE;
  796. return (ahd_aic790X_setup(ahd));
  797. }
  798. static int
  799. ahd_aic790X_setup(struct ahd_softc *ahd)
  800. {
  801. ahd_dev_softc_t pci;
  802. u_int rev;
  803. pci = ahd->dev_softc;
  804. rev = ahd_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  805. if (rev < ID_AIC7902_PCI_REV_A4) {
  806. printf("%s: Unable to attach to unsupported chip revision %d\n",
  807. ahd_name(ahd), rev);
  808. ahd_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/2);
  809. return (ENXIO);
  810. }
  811. ahd->channel = ahd_get_pci_function(pci) + 'A';
  812. if (rev < ID_AIC7902_PCI_REV_B0) {
  813. /*
  814. * Enable A series workarounds.
  815. */
  816. ahd->bugs |= AHD_SENT_SCB_UPDATE_BUG|AHD_ABORT_LQI_BUG
  817. | AHD_PKT_BITBUCKET_BUG|AHD_LONG_SETIMO_BUG
  818. | AHD_NLQICRC_DELAYED_BUG|AHD_SCSIRST_BUG
  819. | AHD_LQO_ATNO_BUG|AHD_AUTOFLUSH_BUG
  820. | AHD_CLRLQO_AUTOCLR_BUG|AHD_PCIX_MMAPIO_BUG
  821. | AHD_PCIX_CHIPRST_BUG|AHD_PCIX_SCBRAM_RD_BUG
  822. | AHD_PKTIZED_STATUS_BUG|AHD_PKT_LUN_BUG
  823. | AHD_MDFF_WSCBPTR_BUG|AHD_REG_SLOW_SETTLE_BUG
  824. | AHD_SET_MODE_BUG|AHD_BUSFREEREV_BUG
  825. | AHD_NONPACKFIFO_BUG|AHD_PACED_NEGTABLE_BUG
  826. | AHD_FAINT_LED_BUG;
  827. /*
  828. * IO Cell paramter setup.
  829. */
  830. AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
  831. if ((ahd->flags & AHD_HP_BOARD) == 0)
  832. AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVA);
  833. } else {
  834. /* This is revision B and newer. */
  835. extern uint32_t aic79xx_slowcrc;
  836. u_int devconfig1;
  837. ahd->features |= AHD_RTI|AHD_NEW_IOCELL_OPTS
  838. | AHD_NEW_DFCNTRL_OPTS|AHD_FAST_CDB_DELIVERY
  839. | AHD_BUSFREEREV_BUG;
  840. ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_EARLY_REQ_BUG;
  841. /* If the user requested the the SLOWCRC bit to be set. */
  842. if (aic79xx_slowcrc)
  843. ahd->features |= AHD_AIC79XXB_SLOWCRC;
  844. /*
  845. * Some issues have been resolved in the 7901B.
  846. */
  847. if ((ahd->features & AHD_MULTI_FUNC) != 0)
  848. ahd->bugs |= AHD_INTCOLLISION_BUG|AHD_ABORT_LQI_BUG;
  849. /*
  850. * IO Cell paramter setup.
  851. */
  852. AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
  853. AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVB);
  854. AHD_SET_AMPLITUDE(ahd, AHD_AMPLITUDE_DEF);
  855. /*
  856. * Set the PREQDIS bit for H2B which disables some workaround
  857. * that doesn't work on regular PCI busses.
  858. * XXX - Find out exactly what this does from the hardware
  859. * folks!
  860. */
  861. devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
  862. ahd_pci_write_config(pci, DEVCONFIG1,
  863. devconfig1|PREQDIS, /*bytes*/1);
  864. devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
  865. }
  866. return (0);
  867. }