aic79xx_pci.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. uint32_t devconfig;
  307. if (bootverbose)
  308. printf("%s: Enabling 39Bit Addressing\n",
  309. ahd_name(ahd));
  310. devconfig = ahd_pci_read_config(ahd->dev_softc,
  311. DEVCONFIG, /*bytes*/4);
  312. devconfig |= DACEN;
  313. ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
  314. devconfig, /*bytes*/4);
  315. }
  316. /* Ensure busmastering is enabled */
  317. command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
  318. command |= PCIM_CMD_BUSMASTEREN;
  319. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
  320. error = ahd_softc_init(ahd);
  321. if (error != 0)
  322. return (error);
  323. ahd->bus_intr = ahd_pci_intr;
  324. error = ahd_reset(ahd, /*reinit*/FALSE);
  325. if (error != 0)
  326. return (ENXIO);
  327. ahd->pci_cachesize =
  328. ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME,
  329. /*bytes*/1) & CACHESIZE;
  330. ahd->pci_cachesize *= 4;
  331. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  332. /* See if we have a SEEPROM and perform auto-term */
  333. error = ahd_check_extport(ahd);
  334. if (error != 0)
  335. return (error);
  336. /* Core initialization */
  337. error = ahd_init(ahd);
  338. if (error != 0)
  339. return (error);
  340. /*
  341. * Allow interrupts now that we are completely setup.
  342. */
  343. error = ahd_pci_map_int(ahd);
  344. if (!error)
  345. ahd->init_level++;
  346. return error;
  347. }
  348. #ifdef CONFIG_PM
  349. void
  350. ahd_pci_suspend(struct ahd_softc *ahd)
  351. {
  352. /*
  353. * Save chip register configuration data for chip resets
  354. * that occur during runtime and resume events.
  355. */
  356. ahd->suspend_state.pci_state.devconfig =
  357. ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
  358. ahd->suspend_state.pci_state.command =
  359. ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/1);
  360. ahd->suspend_state.pci_state.csize_lattime =
  361. ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME, /*bytes*/1);
  362. }
  363. void
  364. ahd_pci_resume(struct ahd_softc *ahd)
  365. {
  366. ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
  367. ahd->suspend_state.pci_state.devconfig, /*bytes*/4);
  368. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
  369. ahd->suspend_state.pci_state.command, /*bytes*/1);
  370. ahd_pci_write_config(ahd->dev_softc, CSIZE_LATTIME,
  371. ahd->suspend_state.pci_state.csize_lattime, /*bytes*/1);
  372. }
  373. #endif
  374. /*
  375. * Perform some simple tests that should catch situations where
  376. * our registers are invalidly mapped.
  377. */
  378. int
  379. ahd_pci_test_register_access(struct ahd_softc *ahd)
  380. {
  381. uint32_t cmd;
  382. u_int targpcistat;
  383. u_int pci_status1;
  384. int error;
  385. uint8_t hcntrl;
  386. error = EIO;
  387. /*
  388. * Enable PCI error interrupt status, but suppress NMIs
  389. * generated by SERR raised due to target aborts.
  390. */
  391. cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
  392. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
  393. cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
  394. /*
  395. * First a simple test to see if any
  396. * registers can be read. Reading
  397. * HCNTRL has no side effects and has
  398. * at least one bit that is guaranteed to
  399. * be zero so it is a good register to
  400. * use for this test.
  401. */
  402. hcntrl = ahd_inb(ahd, HCNTRL);
  403. if (hcntrl == 0xFF)
  404. goto fail;
  405. /*
  406. * Next create a situation where write combining
  407. * or read prefetching could be initiated by the
  408. * CPU or host bridge. Our device does not support
  409. * either, so look for data corruption and/or flaged
  410. * PCI errors. First pause without causing another
  411. * chip reset.
  412. */
  413. hcntrl &= ~CHIPRST;
  414. ahd_outb(ahd, HCNTRL, hcntrl|PAUSE);
  415. while (ahd_is_paused(ahd) == 0)
  416. ;
  417. /* Clear any PCI errors that occurred before our driver attached. */
  418. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  419. targpcistat = ahd_inb(ahd, TARGPCISTAT);
  420. ahd_outb(ahd, TARGPCISTAT, targpcistat);
  421. pci_status1 = ahd_pci_read_config(ahd->dev_softc,
  422. PCIR_STATUS + 1, /*bytes*/1);
  423. ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
  424. pci_status1, /*bytes*/1);
  425. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  426. ahd_outb(ahd, CLRINT, CLRPCIINT);
  427. ahd_outb(ahd, SEQCTL0, PERRORDIS);
  428. ahd_outl(ahd, SRAM_BASE, 0x5aa555aa);
  429. if (ahd_inl(ahd, SRAM_BASE) != 0x5aa555aa)
  430. goto fail;
  431. if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
  432. u_int targpcistat;
  433. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  434. targpcistat = ahd_inb(ahd, TARGPCISTAT);
  435. if ((targpcistat & STA) != 0)
  436. goto fail;
  437. }
  438. error = 0;
  439. fail:
  440. if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
  441. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  442. targpcistat = ahd_inb(ahd, TARGPCISTAT);
  443. /* Silently clear any latched errors. */
  444. ahd_outb(ahd, TARGPCISTAT, targpcistat);
  445. pci_status1 = ahd_pci_read_config(ahd->dev_softc,
  446. PCIR_STATUS + 1, /*bytes*/1);
  447. ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
  448. pci_status1, /*bytes*/1);
  449. ahd_outb(ahd, CLRINT, CLRPCIINT);
  450. }
  451. ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS);
  452. ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
  453. return (error);
  454. }
  455. /*
  456. * Check the external port logic for a serial eeprom
  457. * and termination/cable detection contrls.
  458. */
  459. static int
  460. ahd_check_extport(struct ahd_softc *ahd)
  461. {
  462. struct vpd_config vpd;
  463. struct seeprom_config *sc;
  464. u_int adapter_control;
  465. int have_seeprom;
  466. int error;
  467. sc = ahd->seep_config;
  468. have_seeprom = ahd_acquire_seeprom(ahd);
  469. if (have_seeprom) {
  470. u_int start_addr;
  471. /*
  472. * Fetch VPD for this function and parse it.
  473. */
  474. if (bootverbose)
  475. printf("%s: Reading VPD from SEEPROM...",
  476. ahd_name(ahd));
  477. /* Address is always in units of 16bit words */
  478. start_addr = ((2 * sizeof(*sc))
  479. + (sizeof(vpd) * (ahd->channel - 'A'))) / 2;
  480. error = ahd_read_seeprom(ahd, (uint16_t *)&vpd,
  481. start_addr, sizeof(vpd)/2,
  482. /*bytestream*/TRUE);
  483. if (error == 0)
  484. error = ahd_parse_vpddata(ahd, &vpd);
  485. if (bootverbose)
  486. printf("%s: VPD parsing %s\n",
  487. ahd_name(ahd),
  488. error == 0 ? "successful" : "failed");
  489. if (bootverbose)
  490. printf("%s: Reading SEEPROM...", ahd_name(ahd));
  491. /* Address is always in units of 16bit words */
  492. start_addr = (sizeof(*sc) / 2) * (ahd->channel - 'A');
  493. error = ahd_read_seeprom(ahd, (uint16_t *)sc,
  494. start_addr, sizeof(*sc)/2,
  495. /*bytestream*/FALSE);
  496. if (error != 0) {
  497. printf("Unable to read SEEPROM\n");
  498. have_seeprom = 0;
  499. } else {
  500. have_seeprom = ahd_verify_cksum(sc);
  501. if (bootverbose) {
  502. if (have_seeprom == 0)
  503. printf ("checksum error\n");
  504. else
  505. printf ("done.\n");
  506. }
  507. }
  508. ahd_release_seeprom(ahd);
  509. }
  510. if (!have_seeprom) {
  511. u_int nvram_scb;
  512. /*
  513. * Pull scratch ram settings and treat them as
  514. * if they are the contents of an seeprom if
  515. * the 'ADPT', 'BIOS', or 'ASPI' signature is found
  516. * in SCB 0xFF. We manually compose the data as 16bit
  517. * values to avoid endian issues.
  518. */
  519. ahd_set_scbptr(ahd, 0xFF);
  520. nvram_scb = ahd_inb_scbram(ahd, SCB_BASE + NVRAM_SCB_OFFSET);
  521. if (nvram_scb != 0xFF
  522. && ((ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
  523. && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'D'
  524. && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
  525. && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'T')
  526. || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'B'
  527. && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'I'
  528. && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'O'
  529. && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'S')
  530. || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
  531. && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'S'
  532. && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
  533. && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'I'))) {
  534. uint16_t *sc_data;
  535. int i;
  536. ahd_set_scbptr(ahd, nvram_scb);
  537. sc_data = (uint16_t *)sc;
  538. for (i = 0; i < 64; i += 2)
  539. *sc_data++ = ahd_inw_scbram(ahd, SCB_BASE+i);
  540. have_seeprom = ahd_verify_cksum(sc);
  541. if (have_seeprom)
  542. ahd->flags |= AHD_SCB_CONFIG_USED;
  543. }
  544. }
  545. #ifdef AHD_DEBUG
  546. if (have_seeprom != 0
  547. && (ahd_debug & AHD_DUMP_SEEPROM) != 0) {
  548. uint16_t *sc_data;
  549. int i;
  550. printf("%s: Seeprom Contents:", ahd_name(ahd));
  551. sc_data = (uint16_t *)sc;
  552. for (i = 0; i < (sizeof(*sc)); i += 2)
  553. printf("\n\t0x%.4x", sc_data[i]);
  554. printf("\n");
  555. }
  556. #endif
  557. if (!have_seeprom) {
  558. if (bootverbose)
  559. printf("%s: No SEEPROM available.\n", ahd_name(ahd));
  560. ahd->flags |= AHD_USEDEFAULTS;
  561. error = ahd_default_config(ahd);
  562. adapter_control = CFAUTOTERM|CFSEAUTOTERM;
  563. free(ahd->seep_config, M_DEVBUF);
  564. ahd->seep_config = NULL;
  565. } else {
  566. error = ahd_parse_cfgdata(ahd, sc);
  567. adapter_control = sc->adapter_control;
  568. }
  569. if (error != 0)
  570. return (error);
  571. ahd_configure_termination(ahd, adapter_control);
  572. return (0);
  573. }
  574. static void
  575. ahd_configure_termination(struct ahd_softc *ahd, u_int adapter_control)
  576. {
  577. int error;
  578. u_int sxfrctl1;
  579. uint8_t termctl;
  580. uint32_t devconfig;
  581. devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
  582. devconfig &= ~STPWLEVEL;
  583. if ((ahd->flags & AHD_STPWLEVEL_A) != 0)
  584. devconfig |= STPWLEVEL;
  585. if (bootverbose)
  586. printf("%s: STPWLEVEL is %s\n",
  587. ahd_name(ahd), (devconfig & STPWLEVEL) ? "on" : "off");
  588. ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
  589. /* Make sure current sensing is off. */
  590. if ((ahd->flags & AHD_CURRENT_SENSING) != 0) {
  591. (void)ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
  592. }
  593. /*
  594. * Read to sense. Write to set.
  595. */
  596. error = ahd_read_flexport(ahd, FLXADDR_TERMCTL, &termctl);
  597. if ((adapter_control & CFAUTOTERM) == 0) {
  598. if (bootverbose)
  599. printf("%s: Manual Primary Termination\n",
  600. ahd_name(ahd));
  601. termctl &= ~(FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH);
  602. if ((adapter_control & CFSTERM) != 0)
  603. termctl |= FLX_TERMCTL_ENPRILOW;
  604. if ((adapter_control & CFWSTERM) != 0)
  605. termctl |= FLX_TERMCTL_ENPRIHIGH;
  606. } else if (error != 0) {
  607. printf("%s: Primary Auto-Term Sensing failed! "
  608. "Using Defaults.\n", ahd_name(ahd));
  609. termctl = FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH;
  610. }
  611. if ((adapter_control & CFSEAUTOTERM) == 0) {
  612. if (bootverbose)
  613. printf("%s: Manual Secondary Termination\n",
  614. ahd_name(ahd));
  615. termctl &= ~(FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH);
  616. if ((adapter_control & CFSELOWTERM) != 0)
  617. termctl |= FLX_TERMCTL_ENSECLOW;
  618. if ((adapter_control & CFSEHIGHTERM) != 0)
  619. termctl |= FLX_TERMCTL_ENSECHIGH;
  620. } else if (error != 0) {
  621. printf("%s: Secondary Auto-Term Sensing failed! "
  622. "Using Defaults.\n", ahd_name(ahd));
  623. termctl |= FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH;
  624. }
  625. /*
  626. * Now set the termination based on what we found.
  627. */
  628. sxfrctl1 = ahd_inb(ahd, SXFRCTL1) & ~STPWEN;
  629. ahd->flags &= ~AHD_TERM_ENB_A;
  630. if ((termctl & FLX_TERMCTL_ENPRILOW) != 0) {
  631. ahd->flags |= AHD_TERM_ENB_A;
  632. sxfrctl1 |= STPWEN;
  633. }
  634. /* Must set the latch once in order to be effective. */
  635. ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
  636. ahd_outb(ahd, SXFRCTL1, sxfrctl1);
  637. error = ahd_write_flexport(ahd, FLXADDR_TERMCTL, termctl);
  638. if (error != 0) {
  639. printf("%s: Unable to set termination settings!\n",
  640. ahd_name(ahd));
  641. } else if (bootverbose) {
  642. printf("%s: Primary High byte termination %sabled\n",
  643. ahd_name(ahd),
  644. (termctl & FLX_TERMCTL_ENPRIHIGH) ? "En" : "Dis");
  645. printf("%s: Primary Low byte termination %sabled\n",
  646. ahd_name(ahd),
  647. (termctl & FLX_TERMCTL_ENPRILOW) ? "En" : "Dis");
  648. printf("%s: Secondary High byte termination %sabled\n",
  649. ahd_name(ahd),
  650. (termctl & FLX_TERMCTL_ENSECHIGH) ? "En" : "Dis");
  651. printf("%s: Secondary Low byte termination %sabled\n",
  652. ahd_name(ahd),
  653. (termctl & FLX_TERMCTL_ENSECLOW) ? "En" : "Dis");
  654. }
  655. return;
  656. }
  657. #define DPE 0x80
  658. #define SSE 0x40
  659. #define RMA 0x20
  660. #define RTA 0x10
  661. #define STA 0x08
  662. #define DPR 0x01
  663. static const char *split_status_source[] =
  664. {
  665. "DFF0",
  666. "DFF1",
  667. "OVLY",
  668. "CMC",
  669. };
  670. static const char *pci_status_source[] =
  671. {
  672. "DFF0",
  673. "DFF1",
  674. "SG",
  675. "CMC",
  676. "OVLY",
  677. "NONE",
  678. "MSI",
  679. "TARG"
  680. };
  681. static const char *split_status_strings[] =
  682. {
  683. "%s: Received split response in %s.\n",
  684. "%s: Received split completion error message in %s\n",
  685. "%s: Receive overrun in %s\n",
  686. "%s: Count not complete in %s\n",
  687. "%s: Split completion data bucket in %s\n",
  688. "%s: Split completion address error in %s\n",
  689. "%s: Split completion byte count error in %s\n",
  690. "%s: Signaled Target-abort to early terminate a split in %s\n"
  691. };
  692. static const char *pci_status_strings[] =
  693. {
  694. "%s: Data Parity Error has been reported via PERR# in %s\n",
  695. "%s: Target initial wait state error in %s\n",
  696. "%s: Split completion read data parity error in %s\n",
  697. "%s: Split completion address attribute parity error in %s\n",
  698. "%s: Received a Target Abort in %s\n",
  699. "%s: Received a Master Abort in %s\n",
  700. "%s: Signal System Error Detected in %s\n",
  701. "%s: Address or Write Phase Parity Error Detected in %s.\n"
  702. };
  703. static void
  704. ahd_pci_intr(struct ahd_softc *ahd)
  705. {
  706. uint8_t pci_status[8];
  707. ahd_mode_state saved_modes;
  708. u_int pci_status1;
  709. u_int intstat;
  710. u_int i;
  711. u_int reg;
  712. intstat = ahd_inb(ahd, INTSTAT);
  713. if ((intstat & SPLTINT) != 0)
  714. ahd_pci_split_intr(ahd, intstat);
  715. if ((intstat & PCIINT) == 0)
  716. return;
  717. printf("%s: PCI error Interrupt\n", ahd_name(ahd));
  718. saved_modes = ahd_save_modes(ahd);
  719. ahd_dump_card_state(ahd);
  720. ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
  721. for (i = 0, reg = DF0PCISTAT; i < 8; i++, reg++) {
  722. if (i == 5)
  723. continue;
  724. pci_status[i] = ahd_inb(ahd, reg);
  725. /* Clear latched errors. So our interrupt deasserts. */
  726. ahd_outb(ahd, reg, pci_status[i]);
  727. }
  728. for (i = 0; i < 8; i++) {
  729. u_int bit;
  730. if (i == 5)
  731. continue;
  732. for (bit = 0; bit < 8; bit++) {
  733. if ((pci_status[i] & (0x1 << bit)) != 0) {
  734. static const char *s;
  735. s = pci_status_strings[bit];
  736. if (i == 7/*TARG*/ && bit == 3)
  737. s = "%s: Signaled Target Abort\n";
  738. printf(s, ahd_name(ahd), pci_status_source[i]);
  739. }
  740. }
  741. }
  742. pci_status1 = ahd_pci_read_config(ahd->dev_softc,
  743. PCIR_STATUS + 1, /*bytes*/1);
  744. ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
  745. pci_status1, /*bytes*/1);
  746. ahd_restore_modes(ahd, saved_modes);
  747. ahd_outb(ahd, CLRINT, CLRPCIINT);
  748. ahd_unpause(ahd);
  749. }
  750. static void
  751. ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
  752. {
  753. uint8_t split_status[4];
  754. uint8_t split_status1[4];
  755. uint8_t sg_split_status[2];
  756. uint8_t sg_split_status1[2];
  757. ahd_mode_state saved_modes;
  758. u_int i;
  759. uint16_t pcix_status;
  760. /*
  761. * Check for splits in all modes. Modes 0 and 1
  762. * additionally have SG engine splits to look at.
  763. */
  764. pcix_status = ahd_pci_read_config(ahd->dev_softc, PCIXR_STATUS,
  765. /*bytes*/2);
  766. printf("%s: PCI Split Interrupt - PCI-X status = 0x%x\n",
  767. ahd_name(ahd), pcix_status);
  768. saved_modes = ahd_save_modes(ahd);
  769. for (i = 0; i < 4; i++) {
  770. ahd_set_modes(ahd, i, i);
  771. split_status[i] = ahd_inb(ahd, DCHSPLTSTAT0);
  772. split_status1[i] = ahd_inb(ahd, DCHSPLTSTAT1);
  773. /* Clear latched errors. So our interrupt deasserts. */
  774. ahd_outb(ahd, DCHSPLTSTAT0, split_status[i]);
  775. ahd_outb(ahd, DCHSPLTSTAT1, split_status1[i]);
  776. if (i > 1)
  777. continue;
  778. sg_split_status[i] = ahd_inb(ahd, SGSPLTSTAT0);
  779. sg_split_status1[i] = ahd_inb(ahd, SGSPLTSTAT1);
  780. /* Clear latched errors. So our interrupt deasserts. */
  781. ahd_outb(ahd, SGSPLTSTAT0, sg_split_status[i]);
  782. ahd_outb(ahd, SGSPLTSTAT1, sg_split_status1[i]);
  783. }
  784. for (i = 0; i < 4; i++) {
  785. u_int bit;
  786. for (bit = 0; bit < 8; bit++) {
  787. if ((split_status[i] & (0x1 << bit)) != 0) {
  788. static const char *s;
  789. s = split_status_strings[bit];
  790. printf(s, ahd_name(ahd),
  791. split_status_source[i]);
  792. }
  793. if (i > 1)
  794. continue;
  795. if ((sg_split_status[i] & (0x1 << bit)) != 0) {
  796. static const char *s;
  797. s = split_status_strings[bit];
  798. printf(s, ahd_name(ahd), "SG");
  799. }
  800. }
  801. }
  802. /*
  803. * Clear PCI-X status bits.
  804. */
  805. ahd_pci_write_config(ahd->dev_softc, PCIXR_STATUS,
  806. pcix_status, /*bytes*/2);
  807. ahd_outb(ahd, CLRINT, CLRSPLTINT);
  808. ahd_restore_modes(ahd, saved_modes);
  809. }
  810. static int
  811. ahd_aic7901_setup(struct ahd_softc *ahd)
  812. {
  813. ahd->chip = AHD_AIC7901;
  814. ahd->features = AHD_AIC7901_FE;
  815. return (ahd_aic790X_setup(ahd));
  816. }
  817. static int
  818. ahd_aic7901A_setup(struct ahd_softc *ahd)
  819. {
  820. ahd->chip = AHD_AIC7901A;
  821. ahd->features = AHD_AIC7901A_FE;
  822. return (ahd_aic790X_setup(ahd));
  823. }
  824. static int
  825. ahd_aic7902_setup(struct ahd_softc *ahd)
  826. {
  827. ahd->chip = AHD_AIC7902;
  828. ahd->features = AHD_AIC7902_FE;
  829. return (ahd_aic790X_setup(ahd));
  830. }
  831. static int
  832. ahd_aic790X_setup(struct ahd_softc *ahd)
  833. {
  834. ahd_dev_softc_t pci;
  835. u_int rev;
  836. pci = ahd->dev_softc;
  837. rev = ahd_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
  838. if (rev < ID_AIC7902_PCI_REV_A4) {
  839. printf("%s: Unable to attach to unsupported chip revision %d\n",
  840. ahd_name(ahd), rev);
  841. ahd_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/2);
  842. return (ENXIO);
  843. }
  844. ahd->channel = ahd_get_pci_function(pci) + 'A';
  845. if (rev < ID_AIC7902_PCI_REV_B0) {
  846. /*
  847. * Enable A series workarounds.
  848. */
  849. ahd->bugs |= AHD_SENT_SCB_UPDATE_BUG|AHD_ABORT_LQI_BUG
  850. | AHD_PKT_BITBUCKET_BUG|AHD_LONG_SETIMO_BUG
  851. | AHD_NLQICRC_DELAYED_BUG|AHD_SCSIRST_BUG
  852. | AHD_LQO_ATNO_BUG|AHD_AUTOFLUSH_BUG
  853. | AHD_CLRLQO_AUTOCLR_BUG|AHD_PCIX_MMAPIO_BUG
  854. | AHD_PCIX_CHIPRST_BUG|AHD_PCIX_SCBRAM_RD_BUG
  855. | AHD_PKTIZED_STATUS_BUG|AHD_PKT_LUN_BUG
  856. | AHD_MDFF_WSCBPTR_BUG|AHD_REG_SLOW_SETTLE_BUG
  857. | AHD_SET_MODE_BUG|AHD_BUSFREEREV_BUG
  858. | AHD_NONPACKFIFO_BUG|AHD_PACED_NEGTABLE_BUG
  859. | AHD_FAINT_LED_BUG;
  860. /*
  861. * IO Cell parameter setup.
  862. */
  863. AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
  864. if ((ahd->flags & AHD_HP_BOARD) == 0)
  865. AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVA);
  866. } else {
  867. /* This is revision B and newer. */
  868. extern uint32_t aic79xx_slowcrc;
  869. u_int devconfig1;
  870. ahd->features |= AHD_RTI|AHD_NEW_IOCELL_OPTS
  871. | AHD_NEW_DFCNTRL_OPTS|AHD_FAST_CDB_DELIVERY
  872. | AHD_BUSFREEREV_BUG;
  873. ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_EARLY_REQ_BUG;
  874. /* If the user requested that the SLOWCRC bit to be set. */
  875. if (aic79xx_slowcrc)
  876. ahd->features |= AHD_AIC79XXB_SLOWCRC;
  877. /*
  878. * Some issues have been resolved in the 7901B.
  879. */
  880. if ((ahd->features & AHD_MULTI_FUNC) != 0)
  881. ahd->bugs |= AHD_INTCOLLISION_BUG|AHD_ABORT_LQI_BUG;
  882. /*
  883. * IO Cell parameter setup.
  884. */
  885. AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
  886. AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVB);
  887. AHD_SET_AMPLITUDE(ahd, AHD_AMPLITUDE_DEF);
  888. /*
  889. * Set the PREQDIS bit for H2B which disables some workaround
  890. * that doesn't work on regular PCI busses.
  891. * XXX - Find out exactly what this does from the hardware
  892. * folks!
  893. */
  894. devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
  895. ahd_pci_write_config(pci, DEVCONFIG1,
  896. devconfig1|PREQDIS, /*bytes*/1);
  897. devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
  898. }
  899. return (0);
  900. }