aic79xx_pci.c 27 KB

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