162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Product specific probe and attach routines for:
362306a36Sopenharmony_ci *	aic7901 and aic7902 SCSI controllers
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 1994-2001 Justin T. Gibbs.
662306a36Sopenharmony_ci * Copyright (c) 2000-2002 Adaptec Inc.
762306a36Sopenharmony_ci * All rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
1062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
1162306a36Sopenharmony_ci * are met:
1262306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1362306a36Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
1462306a36Sopenharmony_ci *    without modification.
1562306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1662306a36Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
1762306a36Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
1862306a36Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
1962306a36Sopenharmony_ci *    binary redistribution.
2062306a36Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
2162306a36Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
2262306a36Sopenharmony_ci *    from this software without specific prior written permission.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2562306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2662306a36Sopenharmony_ci * Software Foundation.
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * NO WARRANTY
2962306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3062306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3162306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3262306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3362306a36Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3462306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3562306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3662306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3762306a36Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3862306a36Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3962306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
4062306a36Sopenharmony_ci *
4162306a36Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aic79xx_pci.c#92 $
4262306a36Sopenharmony_ci */
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#include "aic79xx_osm.h"
4562306a36Sopenharmony_ci#include "aic79xx_inline.h"
4662306a36Sopenharmony_ci#include "aic79xx_pci.h"
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistatic inline uint64_t
4962306a36Sopenharmony_ciahd_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
5062306a36Sopenharmony_ci{
5162306a36Sopenharmony_ci	uint64_t id;
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci	id = subvendor
5462306a36Sopenharmony_ci	   | (subdevice << 16)
5562306a36Sopenharmony_ci	   | ((uint64_t)vendor << 32)
5662306a36Sopenharmony_ci	   | ((uint64_t)device << 48);
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	return (id);
5962306a36Sopenharmony_ci}
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#define ID_AIC7902_PCI_REV_A4		0x3
6262306a36Sopenharmony_ci#define ID_AIC7902_PCI_REV_B0		0x10
6362306a36Sopenharmony_ci#define SUBID_HP			0x0E11
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define DEVID_9005_HOSTRAID(id) ((id) & 0x80)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define DEVID_9005_TYPE(id) ((id) & 0xF)
6862306a36Sopenharmony_ci#define		DEVID_9005_TYPE_HBA		0x0	/* Standard Card */
6962306a36Sopenharmony_ci#define		DEVID_9005_TYPE_HBA_2EXT	0x1	/* 2 External Ports */
7062306a36Sopenharmony_ci#define		DEVID_9005_TYPE_IROC		0x8	/* Raid(0,1,10) Card */
7162306a36Sopenharmony_ci#define		DEVID_9005_TYPE_MB		0xF	/* On Motherboard */
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define DEVID_9005_MFUNC(id) ((id) & 0x10)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define DEVID_9005_PACKETIZED(id) ((id) & 0x8000)
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#define SUBID_9005_TYPE(id) ((id) & 0xF)
7862306a36Sopenharmony_ci#define		SUBID_9005_TYPE_HBA		0x0	/* Standard Card */
7962306a36Sopenharmony_ci#define		SUBID_9005_TYPE_MB		0xF	/* On Motherboard */
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define SUBID_9005_AUTOTERM(id)	(((id) & 0x10) == 0)
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define SUBID_9005_LEGACYCONN_FUNC(id) ((id) & 0x20)
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define SUBID_9005_SEEPTYPE(id) (((id) & 0x0C0) >> 6)
8662306a36Sopenharmony_ci#define		SUBID_9005_SEEPTYPE_NONE	0x0
8762306a36Sopenharmony_ci#define		SUBID_9005_SEEPTYPE_4K		0x1
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistatic ahd_device_setup_t ahd_aic7901_setup;
9062306a36Sopenharmony_cistatic ahd_device_setup_t ahd_aic7901A_setup;
9162306a36Sopenharmony_cistatic ahd_device_setup_t ahd_aic7902_setup;
9262306a36Sopenharmony_cistatic ahd_device_setup_t ahd_aic790X_setup;
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_cistatic const struct ahd_pci_identity ahd_pci_ident_table[] =
9562306a36Sopenharmony_ci{
9662306a36Sopenharmony_ci	/* aic7901 based controllers */
9762306a36Sopenharmony_ci	{
9862306a36Sopenharmony_ci		ID_AHA_29320A,
9962306a36Sopenharmony_ci		ID_ALL_MASK,
10062306a36Sopenharmony_ci		"Adaptec 29320A Ultra320 SCSI adapter",
10162306a36Sopenharmony_ci		ahd_aic7901_setup
10262306a36Sopenharmony_ci	},
10362306a36Sopenharmony_ci	{
10462306a36Sopenharmony_ci		ID_AHA_29320ALP,
10562306a36Sopenharmony_ci		ID_ALL_MASK,
10662306a36Sopenharmony_ci		"Adaptec 29320ALP PCIx Ultra320 SCSI adapter",
10762306a36Sopenharmony_ci		ahd_aic7901_setup
10862306a36Sopenharmony_ci	},
10962306a36Sopenharmony_ci	{
11062306a36Sopenharmony_ci		ID_AHA_29320LPE,
11162306a36Sopenharmony_ci		ID_ALL_MASK,
11262306a36Sopenharmony_ci		"Adaptec 29320LPE PCIe Ultra320 SCSI adapter",
11362306a36Sopenharmony_ci		ahd_aic7901_setup
11462306a36Sopenharmony_ci	},
11562306a36Sopenharmony_ci	/* aic7901A based controllers */
11662306a36Sopenharmony_ci	{
11762306a36Sopenharmony_ci		ID_AHA_29320LP,
11862306a36Sopenharmony_ci		ID_ALL_MASK,
11962306a36Sopenharmony_ci		"Adaptec 29320LP Ultra320 SCSI adapter",
12062306a36Sopenharmony_ci		ahd_aic7901A_setup
12162306a36Sopenharmony_ci	},
12262306a36Sopenharmony_ci	/* aic7902 based controllers */
12362306a36Sopenharmony_ci	{
12462306a36Sopenharmony_ci		ID_AHA_29320,
12562306a36Sopenharmony_ci		ID_ALL_MASK,
12662306a36Sopenharmony_ci		"Adaptec 29320 Ultra320 SCSI adapter",
12762306a36Sopenharmony_ci		ahd_aic7902_setup
12862306a36Sopenharmony_ci	},
12962306a36Sopenharmony_ci	{
13062306a36Sopenharmony_ci		ID_AHA_29320B,
13162306a36Sopenharmony_ci		ID_ALL_MASK,
13262306a36Sopenharmony_ci		"Adaptec 29320B Ultra320 SCSI adapter",
13362306a36Sopenharmony_ci		ahd_aic7902_setup
13462306a36Sopenharmony_ci	},
13562306a36Sopenharmony_ci	{
13662306a36Sopenharmony_ci		ID_AHA_39320,
13762306a36Sopenharmony_ci		ID_ALL_MASK,
13862306a36Sopenharmony_ci		"Adaptec 39320 Ultra320 SCSI adapter",
13962306a36Sopenharmony_ci		ahd_aic7902_setup
14062306a36Sopenharmony_ci	},
14162306a36Sopenharmony_ci	{
14262306a36Sopenharmony_ci		ID_AHA_39320_B,
14362306a36Sopenharmony_ci		ID_ALL_MASK,
14462306a36Sopenharmony_ci		"Adaptec 39320 Ultra320 SCSI adapter",
14562306a36Sopenharmony_ci		ahd_aic7902_setup
14662306a36Sopenharmony_ci	},
14762306a36Sopenharmony_ci	{
14862306a36Sopenharmony_ci		ID_AHA_39320_B_DELL,
14962306a36Sopenharmony_ci		ID_ALL_MASK,
15062306a36Sopenharmony_ci		"Adaptec (Dell OEM) 39320 Ultra320 SCSI adapter",
15162306a36Sopenharmony_ci		ahd_aic7902_setup
15262306a36Sopenharmony_ci	},
15362306a36Sopenharmony_ci	{
15462306a36Sopenharmony_ci		ID_AHA_39320A,
15562306a36Sopenharmony_ci		ID_ALL_MASK,
15662306a36Sopenharmony_ci		"Adaptec 39320A Ultra320 SCSI adapter",
15762306a36Sopenharmony_ci		ahd_aic7902_setup
15862306a36Sopenharmony_ci	},
15962306a36Sopenharmony_ci	{
16062306a36Sopenharmony_ci		ID_AHA_39320D,
16162306a36Sopenharmony_ci		ID_ALL_MASK,
16262306a36Sopenharmony_ci		"Adaptec 39320D Ultra320 SCSI adapter",
16362306a36Sopenharmony_ci		ahd_aic7902_setup
16462306a36Sopenharmony_ci	},
16562306a36Sopenharmony_ci	{
16662306a36Sopenharmony_ci		ID_AHA_39320D_HP,
16762306a36Sopenharmony_ci		ID_ALL_MASK,
16862306a36Sopenharmony_ci		"Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
16962306a36Sopenharmony_ci		ahd_aic7902_setup
17062306a36Sopenharmony_ci	},
17162306a36Sopenharmony_ci	{
17262306a36Sopenharmony_ci		ID_AHA_39320D_B,
17362306a36Sopenharmony_ci		ID_ALL_MASK,
17462306a36Sopenharmony_ci		"Adaptec 39320D Ultra320 SCSI adapter",
17562306a36Sopenharmony_ci		ahd_aic7902_setup
17662306a36Sopenharmony_ci	},
17762306a36Sopenharmony_ci	{
17862306a36Sopenharmony_ci		ID_AHA_39320D_B_HP,
17962306a36Sopenharmony_ci		ID_ALL_MASK,
18062306a36Sopenharmony_ci		"Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
18162306a36Sopenharmony_ci		ahd_aic7902_setup
18262306a36Sopenharmony_ci	},
18362306a36Sopenharmony_ci	/* Generic chip probes for devices we don't know 'exactly' */
18462306a36Sopenharmony_ci	{
18562306a36Sopenharmony_ci		ID_AIC7901 & ID_9005_GENERIC_MASK,
18662306a36Sopenharmony_ci		ID_9005_GENERIC_MASK,
18762306a36Sopenharmony_ci		"Adaptec AIC7901 Ultra320 SCSI adapter",
18862306a36Sopenharmony_ci		ahd_aic7901_setup
18962306a36Sopenharmony_ci	},
19062306a36Sopenharmony_ci	{
19162306a36Sopenharmony_ci		ID_AIC7901A & ID_DEV_VENDOR_MASK,
19262306a36Sopenharmony_ci		ID_DEV_VENDOR_MASK,
19362306a36Sopenharmony_ci		"Adaptec AIC7901A Ultra320 SCSI adapter",
19462306a36Sopenharmony_ci		ahd_aic7901A_setup
19562306a36Sopenharmony_ci	},
19662306a36Sopenharmony_ci	{
19762306a36Sopenharmony_ci		ID_AIC7902 & ID_9005_GENERIC_MASK,
19862306a36Sopenharmony_ci		ID_9005_GENERIC_MASK,
19962306a36Sopenharmony_ci		"Adaptec AIC7902 Ultra320 SCSI adapter",
20062306a36Sopenharmony_ci		ahd_aic7902_setup
20162306a36Sopenharmony_ci	}
20262306a36Sopenharmony_ci};
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_cistatic const u_int ahd_num_pci_devs = ARRAY_SIZE(ahd_pci_ident_table);
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci#define	DEVCONFIG		0x40
20762306a36Sopenharmony_ci#define		PCIXINITPAT	0x0000E000ul
20862306a36Sopenharmony_ci#define			PCIXINIT_PCI33_66	0x0000E000ul
20962306a36Sopenharmony_ci#define			PCIXINIT_PCIX50_66	0x0000C000ul
21062306a36Sopenharmony_ci#define			PCIXINIT_PCIX66_100	0x0000A000ul
21162306a36Sopenharmony_ci#define			PCIXINIT_PCIX100_133	0x00008000ul
21262306a36Sopenharmony_ci#define	PCI_BUS_MODES_INDEX(devconfig)	\
21362306a36Sopenharmony_ci	(((devconfig) & PCIXINITPAT) >> 13)
21462306a36Sopenharmony_cistatic const char *pci_bus_modes[] =
21562306a36Sopenharmony_ci{
21662306a36Sopenharmony_ci	"PCI bus mode unknown",
21762306a36Sopenharmony_ci	"PCI bus mode unknown",
21862306a36Sopenharmony_ci	"PCI bus mode unknown",
21962306a36Sopenharmony_ci	"PCI bus mode unknown",
22062306a36Sopenharmony_ci	"PCI-X 101-133MHz",
22162306a36Sopenharmony_ci	"PCI-X 67-100MHz",
22262306a36Sopenharmony_ci	"PCI-X 50-66MHz",
22362306a36Sopenharmony_ci	"PCI 33 or 66MHz"
22462306a36Sopenharmony_ci};
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci#define		TESTMODE	0x00000800ul
22762306a36Sopenharmony_ci#define		IRDY_RST	0x00000200ul
22862306a36Sopenharmony_ci#define		FRAME_RST	0x00000100ul
22962306a36Sopenharmony_ci#define		PCI64BIT	0x00000080ul
23062306a36Sopenharmony_ci#define		MRDCEN		0x00000040ul
23162306a36Sopenharmony_ci#define		ENDIANSEL	0x00000020ul
23262306a36Sopenharmony_ci#define		MIXQWENDIANEN	0x00000008ul
23362306a36Sopenharmony_ci#define		DACEN		0x00000004ul
23462306a36Sopenharmony_ci#define		STPWLEVEL	0x00000002ul
23562306a36Sopenharmony_ci#define		QWENDIANSEL	0x00000001ul
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci#define	DEVCONFIG1		0x44
23862306a36Sopenharmony_ci#define		PREQDIS		0x01
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci#define	CSIZE_LATTIME		0x0c
24162306a36Sopenharmony_ci#define		CACHESIZE	0x000000fful
24262306a36Sopenharmony_ci#define		LATTIME		0x0000ff00ul
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_cistatic int	ahd_check_extport(struct ahd_softc *ahd);
24562306a36Sopenharmony_cistatic void	ahd_configure_termination(struct ahd_softc *ahd,
24662306a36Sopenharmony_ci					  u_int adapter_control);
24762306a36Sopenharmony_cistatic void	ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat);
24862306a36Sopenharmony_cistatic void	ahd_pci_intr(struct ahd_softc *ahd);
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ciconst struct ahd_pci_identity *
25162306a36Sopenharmony_ciahd_find_pci_device(ahd_dev_softc_t pci)
25262306a36Sopenharmony_ci{
25362306a36Sopenharmony_ci	uint64_t  full_id;
25462306a36Sopenharmony_ci	uint16_t  device;
25562306a36Sopenharmony_ci	uint16_t  vendor;
25662306a36Sopenharmony_ci	uint16_t  subdevice;
25762306a36Sopenharmony_ci	uint16_t  subvendor;
25862306a36Sopenharmony_ci	const struct ahd_pci_identity *entry;
25962306a36Sopenharmony_ci	u_int	  i;
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci	vendor = ahd_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
26262306a36Sopenharmony_ci	device = ahd_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
26362306a36Sopenharmony_ci	subvendor = ahd_pci_read_config(pci, PCI_SUBSYSTEM_VENDOR_ID, /*bytes*/2);
26462306a36Sopenharmony_ci	subdevice = ahd_pci_read_config(pci, PCI_SUBSYSTEM_ID, /*bytes*/2);
26562306a36Sopenharmony_ci	full_id = ahd_compose_id(device,
26662306a36Sopenharmony_ci				 vendor,
26762306a36Sopenharmony_ci				 subdevice,
26862306a36Sopenharmony_ci				 subvendor);
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci	/*
27162306a36Sopenharmony_ci	 * Controllers, mask out the IROC/HostRAID bit
27262306a36Sopenharmony_ci	 */
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	full_id &= ID_ALL_IROC_MASK;
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci	for (i = 0; i < ahd_num_pci_devs; i++) {
27762306a36Sopenharmony_ci		entry = &ahd_pci_ident_table[i];
27862306a36Sopenharmony_ci		if (entry->full_id == (full_id & entry->id_mask)) {
27962306a36Sopenharmony_ci			/* Honor exclusion entries. */
28062306a36Sopenharmony_ci			if (entry->name == NULL)
28162306a36Sopenharmony_ci				return (NULL);
28262306a36Sopenharmony_ci			return (entry);
28362306a36Sopenharmony_ci		}
28462306a36Sopenharmony_ci	}
28562306a36Sopenharmony_ci	return (NULL);
28662306a36Sopenharmony_ci}
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ciint
28962306a36Sopenharmony_ciahd_pci_config(struct ahd_softc *ahd, const struct ahd_pci_identity *entry)
29062306a36Sopenharmony_ci{
29162306a36Sopenharmony_ci	u_int		 command;
29262306a36Sopenharmony_ci	uint32_t	 devconfig;
29362306a36Sopenharmony_ci	uint16_t	 subvendor;
29462306a36Sopenharmony_ci	int		 error;
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci	ahd->description = entry->name;
29762306a36Sopenharmony_ci	/*
29862306a36Sopenharmony_ci	 * Record if this is an HP board.
29962306a36Sopenharmony_ci	 */
30062306a36Sopenharmony_ci	subvendor = ahd_pci_read_config(ahd->dev_softc,
30162306a36Sopenharmony_ci					PCI_SUBSYSTEM_VENDOR_ID, /*bytes*/2);
30262306a36Sopenharmony_ci	if (subvendor == SUBID_HP)
30362306a36Sopenharmony_ci		ahd->flags |= AHD_HP_BOARD;
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci	error = entry->setup(ahd);
30662306a36Sopenharmony_ci	if (error != 0)
30762306a36Sopenharmony_ci		return (error);
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
31062306a36Sopenharmony_ci	if ((devconfig & PCIXINITPAT) == PCIXINIT_PCI33_66) {
31162306a36Sopenharmony_ci		ahd->chip |= AHD_PCI;
31262306a36Sopenharmony_ci		/* Disable PCIX workarounds when running in PCI mode. */
31362306a36Sopenharmony_ci		ahd->bugs &= ~AHD_PCIX_BUG_MASK;
31462306a36Sopenharmony_ci	} else {
31562306a36Sopenharmony_ci		ahd->chip |= AHD_PCIX;
31662306a36Sopenharmony_ci	}
31762306a36Sopenharmony_ci	ahd->bus_description = pci_bus_modes[PCI_BUS_MODES_INDEX(devconfig)];
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci	ahd_power_state_change(ahd, AHD_POWER_STATE_D0);
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci	error = ahd_pci_map_registers(ahd);
32262306a36Sopenharmony_ci	if (error != 0)
32362306a36Sopenharmony_ci		return (error);
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci	/*
32662306a36Sopenharmony_ci	 * If we need to support high memory, enable dual
32762306a36Sopenharmony_ci	 * address cycles.  This bit must be set to enable
32862306a36Sopenharmony_ci	 * high address bit generation even if we are on a
32962306a36Sopenharmony_ci	 * 64bit bus (PCI64BIT set in devconfig).
33062306a36Sopenharmony_ci	 */
33162306a36Sopenharmony_ci	if ((ahd->flags & (AHD_39BIT_ADDRESSING|AHD_64BIT_ADDRESSING)) != 0) {
33262306a36Sopenharmony_ci		if (bootverbose)
33362306a36Sopenharmony_ci			printk("%s: Enabling 39Bit Addressing\n",
33462306a36Sopenharmony_ci			       ahd_name(ahd));
33562306a36Sopenharmony_ci		devconfig = ahd_pci_read_config(ahd->dev_softc,
33662306a36Sopenharmony_ci						DEVCONFIG, /*bytes*/4);
33762306a36Sopenharmony_ci		devconfig |= DACEN;
33862306a36Sopenharmony_ci		ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
33962306a36Sopenharmony_ci				     devconfig, /*bytes*/4);
34062306a36Sopenharmony_ci	}
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	/* Ensure busmastering is enabled */
34362306a36Sopenharmony_ci	command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
34462306a36Sopenharmony_ci	command |= PCIM_CMD_BUSMASTEREN;
34562306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci	error = ahd_softc_init(ahd);
34862306a36Sopenharmony_ci	if (error != 0)
34962306a36Sopenharmony_ci		return (error);
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	ahd->bus_intr = ahd_pci_intr;
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_ci	error = ahd_reset(ahd, /*reinit*/FALSE);
35462306a36Sopenharmony_ci	if (error != 0)
35562306a36Sopenharmony_ci		return (ENXIO);
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci	ahd->pci_cachesize =
35862306a36Sopenharmony_ci	    ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME,
35962306a36Sopenharmony_ci				/*bytes*/1) & CACHESIZE;
36062306a36Sopenharmony_ci	ahd->pci_cachesize *= 4;
36162306a36Sopenharmony_ci
36262306a36Sopenharmony_ci	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
36362306a36Sopenharmony_ci	/* See if we have a SEEPROM and perform auto-term */
36462306a36Sopenharmony_ci	error = ahd_check_extport(ahd);
36562306a36Sopenharmony_ci	if (error != 0)
36662306a36Sopenharmony_ci		return (error);
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci	/* Core initialization */
36962306a36Sopenharmony_ci	error = ahd_init(ahd);
37062306a36Sopenharmony_ci	if (error != 0)
37162306a36Sopenharmony_ci		return (error);
37262306a36Sopenharmony_ci	ahd->init_level++;
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci	/*
37562306a36Sopenharmony_ci	 * Allow interrupts now that we are completely setup.
37662306a36Sopenharmony_ci	 */
37762306a36Sopenharmony_ci	return ahd_pci_map_int(ahd);
37862306a36Sopenharmony_ci}
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_civoid __maybe_unused
38162306a36Sopenharmony_ciahd_pci_suspend(struct ahd_softc *ahd)
38262306a36Sopenharmony_ci{
38362306a36Sopenharmony_ci	/*
38462306a36Sopenharmony_ci	 * Save chip register configuration data for chip resets
38562306a36Sopenharmony_ci	 * that occur during runtime and resume events.
38662306a36Sopenharmony_ci	 */
38762306a36Sopenharmony_ci	ahd->suspend_state.pci_state.devconfig =
38862306a36Sopenharmony_ci	    ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
38962306a36Sopenharmony_ci	ahd->suspend_state.pci_state.command =
39062306a36Sopenharmony_ci	    ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/1);
39162306a36Sopenharmony_ci	ahd->suspend_state.pci_state.csize_lattime =
39262306a36Sopenharmony_ci	    ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME, /*bytes*/1);
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci}
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_civoid __maybe_unused
39762306a36Sopenharmony_ciahd_pci_resume(struct ahd_softc *ahd)
39862306a36Sopenharmony_ci{
39962306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
40062306a36Sopenharmony_ci			     ahd->suspend_state.pci_state.devconfig, /*bytes*/4);
40162306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
40262306a36Sopenharmony_ci			     ahd->suspend_state.pci_state.command, /*bytes*/1);
40362306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, CSIZE_LATTIME,
40462306a36Sopenharmony_ci			     ahd->suspend_state.pci_state.csize_lattime, /*bytes*/1);
40562306a36Sopenharmony_ci}
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci/*
40862306a36Sopenharmony_ci * Perform some simple tests that should catch situations where
40962306a36Sopenharmony_ci * our registers are invalidly mapped.
41062306a36Sopenharmony_ci */
41162306a36Sopenharmony_ciint
41262306a36Sopenharmony_ciahd_pci_test_register_access(struct ahd_softc *ahd)
41362306a36Sopenharmony_ci{
41462306a36Sopenharmony_ci	uint32_t cmd;
41562306a36Sopenharmony_ci	u_int	 targpcistat;
41662306a36Sopenharmony_ci	u_int	 pci_status1;
41762306a36Sopenharmony_ci	int	 error;
41862306a36Sopenharmony_ci	uint8_t	 hcntrl;
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ci	error = EIO;
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci	/*
42362306a36Sopenharmony_ci	 * Enable PCI error interrupt status, but suppress NMIs
42462306a36Sopenharmony_ci	 * generated by SERR raised due to target aborts.
42562306a36Sopenharmony_ci	 */
42662306a36Sopenharmony_ci	cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
42762306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
42862306a36Sopenharmony_ci			     cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
42962306a36Sopenharmony_ci
43062306a36Sopenharmony_ci	/*
43162306a36Sopenharmony_ci	 * First a simple test to see if any
43262306a36Sopenharmony_ci	 * registers can be read.  Reading
43362306a36Sopenharmony_ci	 * HCNTRL has no side effects and has
43462306a36Sopenharmony_ci	 * at least one bit that is guaranteed to
43562306a36Sopenharmony_ci	 * be zero so it is a good register to
43662306a36Sopenharmony_ci	 * use for this test.
43762306a36Sopenharmony_ci	 */
43862306a36Sopenharmony_ci	hcntrl = ahd_inb(ahd, HCNTRL);
43962306a36Sopenharmony_ci	if (hcntrl == 0xFF)
44062306a36Sopenharmony_ci		goto fail;
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci	/*
44362306a36Sopenharmony_ci	 * Next create a situation where write combining
44462306a36Sopenharmony_ci	 * or read prefetching could be initiated by the
44562306a36Sopenharmony_ci	 * CPU or host bridge.  Our device does not support
44662306a36Sopenharmony_ci	 * either, so look for data corruption and/or flaged
44762306a36Sopenharmony_ci	 * PCI errors.  First pause without causing another
44862306a36Sopenharmony_ci	 * chip reset.
44962306a36Sopenharmony_ci	 */
45062306a36Sopenharmony_ci	hcntrl &= ~CHIPRST;
45162306a36Sopenharmony_ci	ahd_outb(ahd, HCNTRL, hcntrl|PAUSE);
45262306a36Sopenharmony_ci	while (ahd_is_paused(ahd) == 0)
45362306a36Sopenharmony_ci		;
45462306a36Sopenharmony_ci
45562306a36Sopenharmony_ci	/* Clear any PCI errors that occurred before our driver attached. */
45662306a36Sopenharmony_ci	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
45762306a36Sopenharmony_ci	targpcistat = ahd_inb(ahd, TARGPCISTAT);
45862306a36Sopenharmony_ci	ahd_outb(ahd, TARGPCISTAT, targpcistat);
45962306a36Sopenharmony_ci	pci_status1 = ahd_pci_read_config(ahd->dev_softc,
46062306a36Sopenharmony_ci					  PCIR_STATUS + 1, /*bytes*/1);
46162306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
46262306a36Sopenharmony_ci			     pci_status1, /*bytes*/1);
46362306a36Sopenharmony_ci	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
46462306a36Sopenharmony_ci	ahd_outb(ahd, CLRINT, CLRPCIINT);
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci	ahd_outb(ahd, SEQCTL0, PERRORDIS);
46762306a36Sopenharmony_ci	ahd_outl(ahd, SRAM_BASE, 0x5aa555aa);
46862306a36Sopenharmony_ci	if (ahd_inl(ahd, SRAM_BASE) != 0x5aa555aa)
46962306a36Sopenharmony_ci		goto fail;
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci	if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
47262306a36Sopenharmony_ci		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
47362306a36Sopenharmony_ci		targpcistat = ahd_inb(ahd, TARGPCISTAT);
47462306a36Sopenharmony_ci		if ((targpcistat & STA) != 0)
47562306a36Sopenharmony_ci			goto fail;
47662306a36Sopenharmony_ci	}
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci	error = 0;
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_cifail:
48162306a36Sopenharmony_ci	if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
48262306a36Sopenharmony_ci
48362306a36Sopenharmony_ci		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
48462306a36Sopenharmony_ci		targpcistat = ahd_inb(ahd, TARGPCISTAT);
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci		/* Silently clear any latched errors. */
48762306a36Sopenharmony_ci		ahd_outb(ahd, TARGPCISTAT, targpcistat);
48862306a36Sopenharmony_ci		pci_status1 = ahd_pci_read_config(ahd->dev_softc,
48962306a36Sopenharmony_ci						  PCIR_STATUS + 1, /*bytes*/1);
49062306a36Sopenharmony_ci		ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
49162306a36Sopenharmony_ci				     pci_status1, /*bytes*/1);
49262306a36Sopenharmony_ci		ahd_outb(ahd, CLRINT, CLRPCIINT);
49362306a36Sopenharmony_ci	}
49462306a36Sopenharmony_ci	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS);
49562306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
49662306a36Sopenharmony_ci	return (error);
49762306a36Sopenharmony_ci}
49862306a36Sopenharmony_ci
49962306a36Sopenharmony_ci/*
50062306a36Sopenharmony_ci * Check the external port logic for a serial eeprom
50162306a36Sopenharmony_ci * and termination/cable detection contrls.
50262306a36Sopenharmony_ci */
50362306a36Sopenharmony_cistatic int
50462306a36Sopenharmony_ciahd_check_extport(struct ahd_softc *ahd)
50562306a36Sopenharmony_ci{
50662306a36Sopenharmony_ci	struct	vpd_config vpd;
50762306a36Sopenharmony_ci	struct	seeprom_config *sc;
50862306a36Sopenharmony_ci	u_int	adapter_control;
50962306a36Sopenharmony_ci	int	have_seeprom;
51062306a36Sopenharmony_ci	int	error;
51162306a36Sopenharmony_ci
51262306a36Sopenharmony_ci	sc = ahd->seep_config;
51362306a36Sopenharmony_ci	have_seeprom = ahd_acquire_seeprom(ahd);
51462306a36Sopenharmony_ci	if (have_seeprom) {
51562306a36Sopenharmony_ci		u_int start_addr;
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ci		/*
51862306a36Sopenharmony_ci		 * Fetch VPD for this function and parse it.
51962306a36Sopenharmony_ci		 */
52062306a36Sopenharmony_ci		if (bootverbose)
52162306a36Sopenharmony_ci			printk("%s: Reading VPD from SEEPROM...",
52262306a36Sopenharmony_ci			       ahd_name(ahd));
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ci		/* Address is always in units of 16bit words */
52562306a36Sopenharmony_ci		start_addr = ((2 * sizeof(*sc))
52662306a36Sopenharmony_ci			    + (sizeof(vpd) * (ahd->channel - 'A'))) / 2;
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_ci		error = ahd_read_seeprom(ahd, (uint16_t *)&vpd,
52962306a36Sopenharmony_ci					 start_addr, sizeof(vpd)/2,
53062306a36Sopenharmony_ci					 /*bytestream*/TRUE);
53162306a36Sopenharmony_ci		if (error == 0)
53262306a36Sopenharmony_ci			error = ahd_parse_vpddata(ahd, &vpd);
53362306a36Sopenharmony_ci		if (bootverbose)
53462306a36Sopenharmony_ci			printk("%s: VPD parsing %s\n",
53562306a36Sopenharmony_ci			       ahd_name(ahd),
53662306a36Sopenharmony_ci			       error == 0 ? "successful" : "failed");
53762306a36Sopenharmony_ci
53862306a36Sopenharmony_ci		if (bootverbose)
53962306a36Sopenharmony_ci			printk("%s: Reading SEEPROM...", ahd_name(ahd));
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci		/* Address is always in units of 16bit words */
54262306a36Sopenharmony_ci		start_addr = (sizeof(*sc) / 2) * (ahd->channel - 'A');
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_ci		error = ahd_read_seeprom(ahd, (uint16_t *)sc,
54562306a36Sopenharmony_ci					 start_addr, sizeof(*sc)/2,
54662306a36Sopenharmony_ci					 /*bytestream*/FALSE);
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_ci		if (error != 0) {
54962306a36Sopenharmony_ci			printk("Unable to read SEEPROM\n");
55062306a36Sopenharmony_ci			have_seeprom = 0;
55162306a36Sopenharmony_ci		} else {
55262306a36Sopenharmony_ci			have_seeprom = ahd_verify_cksum(sc);
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci			if (bootverbose) {
55562306a36Sopenharmony_ci				if (have_seeprom == 0)
55662306a36Sopenharmony_ci					printk ("checksum error\n");
55762306a36Sopenharmony_ci				else
55862306a36Sopenharmony_ci					printk ("done.\n");
55962306a36Sopenharmony_ci			}
56062306a36Sopenharmony_ci		}
56162306a36Sopenharmony_ci		ahd_release_seeprom(ahd);
56262306a36Sopenharmony_ci	}
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_ci	if (!have_seeprom) {
56562306a36Sopenharmony_ci		u_int	  nvram_scb;
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_ci		/*
56862306a36Sopenharmony_ci		 * Pull scratch ram settings and treat them as
56962306a36Sopenharmony_ci		 * if they are the contents of an seeprom if
57062306a36Sopenharmony_ci		 * the 'ADPT', 'BIOS', or 'ASPI' signature is found
57162306a36Sopenharmony_ci		 * in SCB 0xFF.  We manually compose the data as 16bit
57262306a36Sopenharmony_ci		 * values to avoid endian issues.
57362306a36Sopenharmony_ci		 */
57462306a36Sopenharmony_ci		ahd_set_scbptr(ahd, 0xFF);
57562306a36Sopenharmony_ci		nvram_scb = ahd_inb_scbram(ahd, SCB_BASE + NVRAM_SCB_OFFSET);
57662306a36Sopenharmony_ci		if (nvram_scb != 0xFF
57762306a36Sopenharmony_ci		 && ((ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
57862306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'D'
57962306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
58062306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'T')
58162306a36Sopenharmony_ci		  || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'B'
58262306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'I'
58362306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'O'
58462306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'S')
58562306a36Sopenharmony_ci		  || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
58662306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'S'
58762306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
58862306a36Sopenharmony_ci		   && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'I'))) {
58962306a36Sopenharmony_ci			uint16_t *sc_data;
59062306a36Sopenharmony_ci			int	  i;
59162306a36Sopenharmony_ci
59262306a36Sopenharmony_ci			ahd_set_scbptr(ahd, nvram_scb);
59362306a36Sopenharmony_ci			sc_data = (uint16_t *)sc;
59462306a36Sopenharmony_ci			for (i = 0; i < 64; i += 2)
59562306a36Sopenharmony_ci				*sc_data++ = ahd_inw_scbram(ahd, SCB_BASE+i);
59662306a36Sopenharmony_ci			have_seeprom = ahd_verify_cksum(sc);
59762306a36Sopenharmony_ci			if (have_seeprom)
59862306a36Sopenharmony_ci				ahd->flags |= AHD_SCB_CONFIG_USED;
59962306a36Sopenharmony_ci		}
60062306a36Sopenharmony_ci	}
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci#ifdef AHD_DEBUG
60362306a36Sopenharmony_ci	if (have_seeprom != 0
60462306a36Sopenharmony_ci	 && (ahd_debug & AHD_DUMP_SEEPROM) != 0) {
60562306a36Sopenharmony_ci		uint16_t *sc_data;
60662306a36Sopenharmony_ci		int	  i;
60762306a36Sopenharmony_ci
60862306a36Sopenharmony_ci		printk("%s: Seeprom Contents:", ahd_name(ahd));
60962306a36Sopenharmony_ci		sc_data = (uint16_t *)sc;
61062306a36Sopenharmony_ci		for (i = 0; i < (sizeof(*sc)); i += 2)
61162306a36Sopenharmony_ci			printk("\n\t0x%.4x", sc_data[i]);
61262306a36Sopenharmony_ci		printk("\n");
61362306a36Sopenharmony_ci	}
61462306a36Sopenharmony_ci#endif
61562306a36Sopenharmony_ci
61662306a36Sopenharmony_ci	if (!have_seeprom) {
61762306a36Sopenharmony_ci		if (bootverbose)
61862306a36Sopenharmony_ci			printk("%s: No SEEPROM available.\n", ahd_name(ahd));
61962306a36Sopenharmony_ci		ahd->flags |= AHD_USEDEFAULTS;
62062306a36Sopenharmony_ci		error = ahd_default_config(ahd);
62162306a36Sopenharmony_ci		adapter_control = CFAUTOTERM|CFSEAUTOTERM;
62262306a36Sopenharmony_ci		kfree(ahd->seep_config);
62362306a36Sopenharmony_ci		ahd->seep_config = NULL;
62462306a36Sopenharmony_ci	} else {
62562306a36Sopenharmony_ci		error = ahd_parse_cfgdata(ahd, sc);
62662306a36Sopenharmony_ci		adapter_control = sc->adapter_control;
62762306a36Sopenharmony_ci	}
62862306a36Sopenharmony_ci	if (error != 0)
62962306a36Sopenharmony_ci		return (error);
63062306a36Sopenharmony_ci
63162306a36Sopenharmony_ci	ahd_configure_termination(ahd, adapter_control);
63262306a36Sopenharmony_ci
63362306a36Sopenharmony_ci	return (0);
63462306a36Sopenharmony_ci}
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_cistatic void
63762306a36Sopenharmony_ciahd_configure_termination(struct ahd_softc *ahd, u_int adapter_control)
63862306a36Sopenharmony_ci{
63962306a36Sopenharmony_ci	int	 error;
64062306a36Sopenharmony_ci	u_int	 sxfrctl1;
64162306a36Sopenharmony_ci	uint8_t	 termctl;
64262306a36Sopenharmony_ci	uint32_t devconfig;
64362306a36Sopenharmony_ci
64462306a36Sopenharmony_ci	devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
64562306a36Sopenharmony_ci	devconfig &= ~STPWLEVEL;
64662306a36Sopenharmony_ci	if ((ahd->flags & AHD_STPWLEVEL_A) != 0)
64762306a36Sopenharmony_ci		devconfig |= STPWLEVEL;
64862306a36Sopenharmony_ci	if (bootverbose)
64962306a36Sopenharmony_ci		printk("%s: STPWLEVEL is %s\n",
65062306a36Sopenharmony_ci		       ahd_name(ahd), (devconfig & STPWLEVEL) ? "on" : "off");
65162306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
65262306a36Sopenharmony_ci
65362306a36Sopenharmony_ci	/* Make sure current sensing is off. */
65462306a36Sopenharmony_ci	if ((ahd->flags & AHD_CURRENT_SENSING) != 0) {
65562306a36Sopenharmony_ci		(void)ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
65662306a36Sopenharmony_ci	}
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci	/*
65962306a36Sopenharmony_ci	 * Read to sense.  Write to set.
66062306a36Sopenharmony_ci	 */
66162306a36Sopenharmony_ci	error = ahd_read_flexport(ahd, FLXADDR_TERMCTL, &termctl);
66262306a36Sopenharmony_ci	if ((adapter_control & CFAUTOTERM) == 0) {
66362306a36Sopenharmony_ci		if (bootverbose)
66462306a36Sopenharmony_ci			printk("%s: Manual Primary Termination\n",
66562306a36Sopenharmony_ci			       ahd_name(ahd));
66662306a36Sopenharmony_ci		termctl &= ~(FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH);
66762306a36Sopenharmony_ci		if ((adapter_control & CFSTERM) != 0)
66862306a36Sopenharmony_ci			termctl |= FLX_TERMCTL_ENPRILOW;
66962306a36Sopenharmony_ci		if ((adapter_control & CFWSTERM) != 0)
67062306a36Sopenharmony_ci			termctl |= FLX_TERMCTL_ENPRIHIGH;
67162306a36Sopenharmony_ci	} else if (error != 0) {
67262306a36Sopenharmony_ci		printk("%s: Primary Auto-Term Sensing failed! "
67362306a36Sopenharmony_ci		       "Using Defaults.\n", ahd_name(ahd));
67462306a36Sopenharmony_ci		termctl = FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH;
67562306a36Sopenharmony_ci	}
67662306a36Sopenharmony_ci
67762306a36Sopenharmony_ci	if ((adapter_control & CFSEAUTOTERM) == 0) {
67862306a36Sopenharmony_ci		if (bootverbose)
67962306a36Sopenharmony_ci			printk("%s: Manual Secondary Termination\n",
68062306a36Sopenharmony_ci			       ahd_name(ahd));
68162306a36Sopenharmony_ci		termctl &= ~(FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH);
68262306a36Sopenharmony_ci		if ((adapter_control & CFSELOWTERM) != 0)
68362306a36Sopenharmony_ci			termctl |= FLX_TERMCTL_ENSECLOW;
68462306a36Sopenharmony_ci		if ((adapter_control & CFSEHIGHTERM) != 0)
68562306a36Sopenharmony_ci			termctl |= FLX_TERMCTL_ENSECHIGH;
68662306a36Sopenharmony_ci	} else if (error != 0) {
68762306a36Sopenharmony_ci		printk("%s: Secondary Auto-Term Sensing failed! "
68862306a36Sopenharmony_ci		       "Using Defaults.\n", ahd_name(ahd));
68962306a36Sopenharmony_ci		termctl |= FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH;
69062306a36Sopenharmony_ci	}
69162306a36Sopenharmony_ci
69262306a36Sopenharmony_ci	/*
69362306a36Sopenharmony_ci	 * Now set the termination based on what we found.
69462306a36Sopenharmony_ci	 */
69562306a36Sopenharmony_ci	sxfrctl1 = ahd_inb(ahd, SXFRCTL1) & ~STPWEN;
69662306a36Sopenharmony_ci	ahd->flags &= ~AHD_TERM_ENB_A;
69762306a36Sopenharmony_ci	if ((termctl & FLX_TERMCTL_ENPRILOW) != 0) {
69862306a36Sopenharmony_ci		ahd->flags |= AHD_TERM_ENB_A;
69962306a36Sopenharmony_ci		sxfrctl1 |= STPWEN;
70062306a36Sopenharmony_ci	}
70162306a36Sopenharmony_ci	/* Must set the latch once in order to be effective. */
70262306a36Sopenharmony_ci	ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
70362306a36Sopenharmony_ci	ahd_outb(ahd, SXFRCTL1, sxfrctl1);
70462306a36Sopenharmony_ci
70562306a36Sopenharmony_ci	error = ahd_write_flexport(ahd, FLXADDR_TERMCTL, termctl);
70662306a36Sopenharmony_ci	if (error != 0) {
70762306a36Sopenharmony_ci		printk("%s: Unable to set termination settings!\n",
70862306a36Sopenharmony_ci		       ahd_name(ahd));
70962306a36Sopenharmony_ci	} else if (bootverbose) {
71062306a36Sopenharmony_ci		printk("%s: Primary High byte termination %sabled\n",
71162306a36Sopenharmony_ci		       ahd_name(ahd),
71262306a36Sopenharmony_ci		       (termctl & FLX_TERMCTL_ENPRIHIGH) ? "En" : "Dis");
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_ci		printk("%s: Primary Low byte termination %sabled\n",
71562306a36Sopenharmony_ci		       ahd_name(ahd),
71662306a36Sopenharmony_ci		       (termctl & FLX_TERMCTL_ENPRILOW) ? "En" : "Dis");
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci		printk("%s: Secondary High byte termination %sabled\n",
71962306a36Sopenharmony_ci		       ahd_name(ahd),
72062306a36Sopenharmony_ci		       (termctl & FLX_TERMCTL_ENSECHIGH) ? "En" : "Dis");
72162306a36Sopenharmony_ci
72262306a36Sopenharmony_ci		printk("%s: Secondary Low byte termination %sabled\n",
72362306a36Sopenharmony_ci		       ahd_name(ahd),
72462306a36Sopenharmony_ci		       (termctl & FLX_TERMCTL_ENSECLOW) ? "En" : "Dis");
72562306a36Sopenharmony_ci	}
72662306a36Sopenharmony_ci	return;
72762306a36Sopenharmony_ci}
72862306a36Sopenharmony_ci
72962306a36Sopenharmony_ci#define	DPE	0x80
73062306a36Sopenharmony_ci#define SSE	0x40
73162306a36Sopenharmony_ci#define	RMA	0x20
73262306a36Sopenharmony_ci#define	RTA	0x10
73362306a36Sopenharmony_ci#define STA	0x08
73462306a36Sopenharmony_ci#define DPR	0x01
73562306a36Sopenharmony_ci
73662306a36Sopenharmony_cistatic const char *split_status_source[] =
73762306a36Sopenharmony_ci{
73862306a36Sopenharmony_ci	"DFF0",
73962306a36Sopenharmony_ci	"DFF1",
74062306a36Sopenharmony_ci	"OVLY",
74162306a36Sopenharmony_ci	"CMC",
74262306a36Sopenharmony_ci};
74362306a36Sopenharmony_ci
74462306a36Sopenharmony_cistatic const char *pci_status_source[] =
74562306a36Sopenharmony_ci{
74662306a36Sopenharmony_ci	"DFF0",
74762306a36Sopenharmony_ci	"DFF1",
74862306a36Sopenharmony_ci	"SG",
74962306a36Sopenharmony_ci	"CMC",
75062306a36Sopenharmony_ci	"OVLY",
75162306a36Sopenharmony_ci	"NONE",
75262306a36Sopenharmony_ci	"MSI",
75362306a36Sopenharmony_ci	"TARG"
75462306a36Sopenharmony_ci};
75562306a36Sopenharmony_ci
75662306a36Sopenharmony_cistatic const char *split_status_strings[] =
75762306a36Sopenharmony_ci{
75862306a36Sopenharmony_ci	"%s: Received split response in %s.\n",
75962306a36Sopenharmony_ci	"%s: Received split completion error message in %s\n",
76062306a36Sopenharmony_ci	"%s: Receive overrun in %s\n",
76162306a36Sopenharmony_ci	"%s: Count not complete in %s\n",
76262306a36Sopenharmony_ci	"%s: Split completion data bucket in %s\n",
76362306a36Sopenharmony_ci	"%s: Split completion address error in %s\n",
76462306a36Sopenharmony_ci	"%s: Split completion byte count error in %s\n",
76562306a36Sopenharmony_ci	"%s: Signaled Target-abort to early terminate a split in %s\n"
76662306a36Sopenharmony_ci};
76762306a36Sopenharmony_ci
76862306a36Sopenharmony_cistatic const char *pci_status_strings[] =
76962306a36Sopenharmony_ci{
77062306a36Sopenharmony_ci	"%s: Data Parity Error has been reported via PERR# in %s\n",
77162306a36Sopenharmony_ci	"%s: Target initial wait state error in %s\n",
77262306a36Sopenharmony_ci	"%s: Split completion read data parity error in %s\n",
77362306a36Sopenharmony_ci	"%s: Split completion address attribute parity error in %s\n",
77462306a36Sopenharmony_ci	"%s: Received a Target Abort in %s\n",
77562306a36Sopenharmony_ci	"%s: Received a Master Abort in %s\n",
77662306a36Sopenharmony_ci	"%s: Signal System Error Detected in %s\n",
77762306a36Sopenharmony_ci	"%s: Address or Write Phase Parity Error Detected in %s.\n"
77862306a36Sopenharmony_ci};
77962306a36Sopenharmony_ci
78062306a36Sopenharmony_cistatic void
78162306a36Sopenharmony_ciahd_pci_intr(struct ahd_softc *ahd)
78262306a36Sopenharmony_ci{
78362306a36Sopenharmony_ci	uint8_t		pci_status[8];
78462306a36Sopenharmony_ci	ahd_mode_state	saved_modes;
78562306a36Sopenharmony_ci	u_int		pci_status1;
78662306a36Sopenharmony_ci	u_int		intstat;
78762306a36Sopenharmony_ci	u_int		i;
78862306a36Sopenharmony_ci	u_int		reg;
78962306a36Sopenharmony_ci
79062306a36Sopenharmony_ci	intstat = ahd_inb(ahd, INTSTAT);
79162306a36Sopenharmony_ci
79262306a36Sopenharmony_ci	if ((intstat & SPLTINT) != 0)
79362306a36Sopenharmony_ci		ahd_pci_split_intr(ahd, intstat);
79462306a36Sopenharmony_ci
79562306a36Sopenharmony_ci	if ((intstat & PCIINT) == 0)
79662306a36Sopenharmony_ci		return;
79762306a36Sopenharmony_ci
79862306a36Sopenharmony_ci	printk("%s: PCI error Interrupt\n", ahd_name(ahd));
79962306a36Sopenharmony_ci	saved_modes = ahd_save_modes(ahd);
80062306a36Sopenharmony_ci	ahd_dump_card_state(ahd);
80162306a36Sopenharmony_ci	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
80262306a36Sopenharmony_ci	for (i = 0, reg = DF0PCISTAT; i < 8; i++, reg++) {
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_ci		if (i == 5)
80562306a36Sopenharmony_ci			continue;
80662306a36Sopenharmony_ci		pci_status[i] = ahd_inb(ahd, reg);
80762306a36Sopenharmony_ci		/* Clear latched errors.  So our interrupt deasserts. */
80862306a36Sopenharmony_ci		ahd_outb(ahd, reg, pci_status[i]);
80962306a36Sopenharmony_ci	}
81062306a36Sopenharmony_ci
81162306a36Sopenharmony_ci	for (i = 0; i < 8; i++) {
81262306a36Sopenharmony_ci		u_int bit;
81362306a36Sopenharmony_ci
81462306a36Sopenharmony_ci		if (i == 5)
81562306a36Sopenharmony_ci			continue;
81662306a36Sopenharmony_ci
81762306a36Sopenharmony_ci		for (bit = 0; bit < 8; bit++) {
81862306a36Sopenharmony_ci
81962306a36Sopenharmony_ci			if ((pci_status[i] & (0x1 << bit)) != 0) {
82062306a36Sopenharmony_ci				const char *s;
82162306a36Sopenharmony_ci
82262306a36Sopenharmony_ci				s = pci_status_strings[bit];
82362306a36Sopenharmony_ci				if (i == 7/*TARG*/ && bit == 3)
82462306a36Sopenharmony_ci					s = "%s: Signaled Target Abort\n";
82562306a36Sopenharmony_ci				printk(s, ahd_name(ahd), pci_status_source[i]);
82662306a36Sopenharmony_ci			}
82762306a36Sopenharmony_ci		}
82862306a36Sopenharmony_ci	}
82962306a36Sopenharmony_ci	pci_status1 = ahd_pci_read_config(ahd->dev_softc,
83062306a36Sopenharmony_ci					  PCIR_STATUS + 1, /*bytes*/1);
83162306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
83262306a36Sopenharmony_ci			     pci_status1, /*bytes*/1);
83362306a36Sopenharmony_ci	ahd_restore_modes(ahd, saved_modes);
83462306a36Sopenharmony_ci	ahd_outb(ahd, CLRINT, CLRPCIINT);
83562306a36Sopenharmony_ci	ahd_unpause(ahd);
83662306a36Sopenharmony_ci}
83762306a36Sopenharmony_ci
83862306a36Sopenharmony_cistatic void
83962306a36Sopenharmony_ciahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
84062306a36Sopenharmony_ci{
84162306a36Sopenharmony_ci	uint8_t		split_status[4];
84262306a36Sopenharmony_ci	uint8_t		split_status1[4];
84362306a36Sopenharmony_ci	uint8_t		sg_split_status[2];
84462306a36Sopenharmony_ci	uint8_t		sg_split_status1[2];
84562306a36Sopenharmony_ci	ahd_mode_state	saved_modes;
84662306a36Sopenharmony_ci	u_int		i;
84762306a36Sopenharmony_ci	uint16_t	pcix_status;
84862306a36Sopenharmony_ci
84962306a36Sopenharmony_ci	/*
85062306a36Sopenharmony_ci	 * Check for splits in all modes.  Modes 0 and 1
85162306a36Sopenharmony_ci	 * additionally have SG engine splits to look at.
85262306a36Sopenharmony_ci	 */
85362306a36Sopenharmony_ci	pcix_status = ahd_pci_read_config(ahd->dev_softc, PCIXR_STATUS,
85462306a36Sopenharmony_ci					  /*bytes*/2);
85562306a36Sopenharmony_ci	printk("%s: PCI Split Interrupt - PCI-X status = 0x%x\n",
85662306a36Sopenharmony_ci	       ahd_name(ahd), pcix_status);
85762306a36Sopenharmony_ci	saved_modes = ahd_save_modes(ahd);
85862306a36Sopenharmony_ci	for (i = 0; i < 4; i++) {
85962306a36Sopenharmony_ci		ahd_set_modes(ahd, i, i);
86062306a36Sopenharmony_ci
86162306a36Sopenharmony_ci		split_status[i] = ahd_inb(ahd, DCHSPLTSTAT0);
86262306a36Sopenharmony_ci		split_status1[i] = ahd_inb(ahd, DCHSPLTSTAT1);
86362306a36Sopenharmony_ci		/* Clear latched errors.  So our interrupt deasserts. */
86462306a36Sopenharmony_ci		ahd_outb(ahd, DCHSPLTSTAT0, split_status[i]);
86562306a36Sopenharmony_ci		ahd_outb(ahd, DCHSPLTSTAT1, split_status1[i]);
86662306a36Sopenharmony_ci		if (i > 1)
86762306a36Sopenharmony_ci			continue;
86862306a36Sopenharmony_ci		sg_split_status[i] = ahd_inb(ahd, SGSPLTSTAT0);
86962306a36Sopenharmony_ci		sg_split_status1[i] = ahd_inb(ahd, SGSPLTSTAT1);
87062306a36Sopenharmony_ci		/* Clear latched errors.  So our interrupt deasserts. */
87162306a36Sopenharmony_ci		ahd_outb(ahd, SGSPLTSTAT0, sg_split_status[i]);
87262306a36Sopenharmony_ci		ahd_outb(ahd, SGSPLTSTAT1, sg_split_status1[i]);
87362306a36Sopenharmony_ci	}
87462306a36Sopenharmony_ci
87562306a36Sopenharmony_ci	for (i = 0; i < 4; i++) {
87662306a36Sopenharmony_ci		u_int bit;
87762306a36Sopenharmony_ci
87862306a36Sopenharmony_ci		for (bit = 0; bit < 8; bit++) {
87962306a36Sopenharmony_ci
88062306a36Sopenharmony_ci			if ((split_status[i] & (0x1 << bit)) != 0)
88162306a36Sopenharmony_ci				printk(split_status_strings[bit], ahd_name(ahd),
88262306a36Sopenharmony_ci				       split_status_source[i]);
88362306a36Sopenharmony_ci
88462306a36Sopenharmony_ci			if (i > 1)
88562306a36Sopenharmony_ci				continue;
88662306a36Sopenharmony_ci
88762306a36Sopenharmony_ci			if ((sg_split_status[i] & (0x1 << bit)) != 0)
88862306a36Sopenharmony_ci				printk(split_status_strings[bit], ahd_name(ahd), "SG");
88962306a36Sopenharmony_ci		}
89062306a36Sopenharmony_ci	}
89162306a36Sopenharmony_ci	/*
89262306a36Sopenharmony_ci	 * Clear PCI-X status bits.
89362306a36Sopenharmony_ci	 */
89462306a36Sopenharmony_ci	ahd_pci_write_config(ahd->dev_softc, PCIXR_STATUS,
89562306a36Sopenharmony_ci			     pcix_status, /*bytes*/2);
89662306a36Sopenharmony_ci	ahd_outb(ahd, CLRINT, CLRSPLTINT);
89762306a36Sopenharmony_ci	ahd_restore_modes(ahd, saved_modes);
89862306a36Sopenharmony_ci}
89962306a36Sopenharmony_ci
90062306a36Sopenharmony_cistatic int
90162306a36Sopenharmony_ciahd_aic7901_setup(struct ahd_softc *ahd)
90262306a36Sopenharmony_ci{
90362306a36Sopenharmony_ci
90462306a36Sopenharmony_ci	ahd->chip = AHD_AIC7901;
90562306a36Sopenharmony_ci	ahd->features = AHD_AIC7901_FE;
90662306a36Sopenharmony_ci	return (ahd_aic790X_setup(ahd));
90762306a36Sopenharmony_ci}
90862306a36Sopenharmony_ci
90962306a36Sopenharmony_cistatic int
91062306a36Sopenharmony_ciahd_aic7901A_setup(struct ahd_softc *ahd)
91162306a36Sopenharmony_ci{
91262306a36Sopenharmony_ci
91362306a36Sopenharmony_ci	ahd->chip = AHD_AIC7901A;
91462306a36Sopenharmony_ci	ahd->features = AHD_AIC7901A_FE;
91562306a36Sopenharmony_ci	return (ahd_aic790X_setup(ahd));
91662306a36Sopenharmony_ci}
91762306a36Sopenharmony_ci
91862306a36Sopenharmony_cistatic int
91962306a36Sopenharmony_ciahd_aic7902_setup(struct ahd_softc *ahd)
92062306a36Sopenharmony_ci{
92162306a36Sopenharmony_ci	ahd->chip = AHD_AIC7902;
92262306a36Sopenharmony_ci	ahd->features = AHD_AIC7902_FE;
92362306a36Sopenharmony_ci	return (ahd_aic790X_setup(ahd));
92462306a36Sopenharmony_ci}
92562306a36Sopenharmony_ci
92662306a36Sopenharmony_cistatic int
92762306a36Sopenharmony_ciahd_aic790X_setup(struct ahd_softc *ahd)
92862306a36Sopenharmony_ci{
92962306a36Sopenharmony_ci	ahd_dev_softc_t pci;
93062306a36Sopenharmony_ci	u_int rev;
93162306a36Sopenharmony_ci
93262306a36Sopenharmony_ci	pci = ahd->dev_softc;
93362306a36Sopenharmony_ci	rev = ahd_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
93462306a36Sopenharmony_ci	if (rev < ID_AIC7902_PCI_REV_A4) {
93562306a36Sopenharmony_ci		printk("%s: Unable to attach to unsupported chip revision %d\n",
93662306a36Sopenharmony_ci		       ahd_name(ahd), rev);
93762306a36Sopenharmony_ci		ahd_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/2);
93862306a36Sopenharmony_ci		return (ENXIO);
93962306a36Sopenharmony_ci	}
94062306a36Sopenharmony_ci	ahd->channel = ahd_get_pci_function(pci) + 'A';
94162306a36Sopenharmony_ci	if (rev < ID_AIC7902_PCI_REV_B0) {
94262306a36Sopenharmony_ci		/*
94362306a36Sopenharmony_ci		 * Enable A series workarounds.
94462306a36Sopenharmony_ci		 */
94562306a36Sopenharmony_ci		ahd->bugs |= AHD_SENT_SCB_UPDATE_BUG|AHD_ABORT_LQI_BUG
94662306a36Sopenharmony_ci			  |  AHD_PKT_BITBUCKET_BUG|AHD_LONG_SETIMO_BUG
94762306a36Sopenharmony_ci			  |  AHD_NLQICRC_DELAYED_BUG|AHD_SCSIRST_BUG
94862306a36Sopenharmony_ci			  |  AHD_LQO_ATNO_BUG|AHD_AUTOFLUSH_BUG
94962306a36Sopenharmony_ci			  |  AHD_CLRLQO_AUTOCLR_BUG|AHD_PCIX_MMAPIO_BUG
95062306a36Sopenharmony_ci			  |  AHD_PCIX_CHIPRST_BUG|AHD_PCIX_SCBRAM_RD_BUG
95162306a36Sopenharmony_ci			  |  AHD_PKTIZED_STATUS_BUG|AHD_PKT_LUN_BUG
95262306a36Sopenharmony_ci			  |  AHD_MDFF_WSCBPTR_BUG|AHD_REG_SLOW_SETTLE_BUG
95362306a36Sopenharmony_ci			  |  AHD_SET_MODE_BUG|AHD_BUSFREEREV_BUG
95462306a36Sopenharmony_ci			  |  AHD_NONPACKFIFO_BUG|AHD_PACED_NEGTABLE_BUG
95562306a36Sopenharmony_ci			  |  AHD_FAINT_LED_BUG;
95662306a36Sopenharmony_ci
95762306a36Sopenharmony_ci		/*
95862306a36Sopenharmony_ci		 * IO Cell parameter setup.
95962306a36Sopenharmony_ci		 */
96062306a36Sopenharmony_ci		AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
96162306a36Sopenharmony_ci
96262306a36Sopenharmony_ci		if ((ahd->flags & AHD_HP_BOARD) == 0)
96362306a36Sopenharmony_ci			AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVA);
96462306a36Sopenharmony_ci	} else {
96562306a36Sopenharmony_ci		/* This is revision B and newer. */
96662306a36Sopenharmony_ci		extern uint32_t aic79xx_slowcrc;
96762306a36Sopenharmony_ci		u_int devconfig1;
96862306a36Sopenharmony_ci
96962306a36Sopenharmony_ci		ahd->features |= AHD_RTI|AHD_NEW_IOCELL_OPTS
97062306a36Sopenharmony_ci			      |  AHD_NEW_DFCNTRL_OPTS|AHD_FAST_CDB_DELIVERY
97162306a36Sopenharmony_ci			      |  AHD_BUSFREEREV_BUG;
97262306a36Sopenharmony_ci		ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_EARLY_REQ_BUG;
97362306a36Sopenharmony_ci
97462306a36Sopenharmony_ci		/* If the user requested that the SLOWCRC bit to be set. */
97562306a36Sopenharmony_ci		if (aic79xx_slowcrc)
97662306a36Sopenharmony_ci			ahd->features |= AHD_AIC79XXB_SLOWCRC;
97762306a36Sopenharmony_ci
97862306a36Sopenharmony_ci		/*
97962306a36Sopenharmony_ci		 * Some issues have been resolved in the 7901B.
98062306a36Sopenharmony_ci		 */
98162306a36Sopenharmony_ci		if ((ahd->features & AHD_MULTI_FUNC) != 0)
98262306a36Sopenharmony_ci			ahd->bugs |= AHD_INTCOLLISION_BUG|AHD_ABORT_LQI_BUG;
98362306a36Sopenharmony_ci
98462306a36Sopenharmony_ci		/*
98562306a36Sopenharmony_ci		 * IO Cell parameter setup.
98662306a36Sopenharmony_ci		 */
98762306a36Sopenharmony_ci		AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
98862306a36Sopenharmony_ci		AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVB);
98962306a36Sopenharmony_ci		AHD_SET_AMPLITUDE(ahd, AHD_AMPLITUDE_DEF);
99062306a36Sopenharmony_ci
99162306a36Sopenharmony_ci		/*
99262306a36Sopenharmony_ci		 * Set the PREQDIS bit for H2B which disables some workaround
99362306a36Sopenharmony_ci		 * that doesn't work on regular PCI busses.
99462306a36Sopenharmony_ci		 * XXX - Find out exactly what this does from the hardware
99562306a36Sopenharmony_ci		 * 	 folks!
99662306a36Sopenharmony_ci		 */
99762306a36Sopenharmony_ci		devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
99862306a36Sopenharmony_ci		ahd_pci_write_config(pci, DEVCONFIG1,
99962306a36Sopenharmony_ci				     devconfig1|PREQDIS, /*bytes*/1);
100062306a36Sopenharmony_ci		devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
100162306a36Sopenharmony_ci	}
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_ci	return (0);
100462306a36Sopenharmony_ci}
1005