aic79xx_pci.c 27 KB

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