Home | History | Annotate | Line # | Download | only in pci
ahc_pci.c revision 1.32.10.1
      1  1.32.10.1      tron /*	$NetBSD: ahc_pci.c,v 1.32.10.1 2003/08/23 06:44:46 tron Exp $	*/
      2        1.2   thorpej 
      3        1.1   mycroft /*
      4        1.1   mycroft  * Product specific probe and attach routines for:
      5       1.22      fvdl  *      3940, 2940, aic7895, aic7890, aic7880,
      6       1.22      fvdl  *	aic7870, aic7860 and aic7850 SCSI controllers
      7        1.1   mycroft  *
      8       1.22      fvdl  * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000 Justin T. Gibbs.
      9        1.1   mycroft  * All rights reserved.
     10        1.1   mycroft  *
     11        1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     12        1.1   mycroft  * modification, are permitted provided that the following conditions
     13        1.1   mycroft  * are met:
     14        1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     15       1.22      fvdl  *    notice, this list of conditions, and the following disclaimer,
     16       1.22      fvdl  *    without modification.
     17       1.22      fvdl  * 2. The name of the author may not be used to endorse or promote products
     18        1.1   mycroft  *    derived from this software without specific prior written permission.
     19        1.1   mycroft  *
     20       1.22      fvdl  * Alternatively, this software may be distributed under the terms of the
     21       1.22      fvdl  * the GNU Public License ("GPL").
     22       1.22      fvdl  *
     23        1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     24        1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25        1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26        1.1   mycroft  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     27        1.1   mycroft  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28        1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29        1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30        1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31        1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33        1.1   mycroft  * SUCH DAMAGE.
     34        1.3  explorer  *
     35       1.22      fvdl  * $FreeBSD: src/sys/dev/aic7xxx/ahc_pci.c,v 1.28 2000/02/09 21:00:22 gibbs Exp $
     36        1.1   mycroft  */
     37       1.31     lukem 
     38       1.31     lukem #include <sys/cdefs.h>
     39  1.32.10.1      tron __KERNEL_RCSID(0, "$NetBSD: ahc_pci.c,v 1.32.10.1 2003/08/23 06:44:46 tron Exp $");
     40        1.1   mycroft 
     41        1.1   mycroft #include <sys/param.h>
     42        1.1   mycroft #include <sys/systm.h>
     43        1.1   mycroft #include <sys/malloc.h>
     44        1.1   mycroft #include <sys/kernel.h>
     45        1.1   mycroft #include <sys/queue.h>
     46        1.1   mycroft #include <sys/device.h>
     47       1.27  jdolecek #include <sys/reboot.h>
     48       1.21   thorpej 
     49        1.1   mycroft #include <machine/bus.h>
     50        1.1   mycroft #include <machine/intr.h>
     51        1.1   mycroft 
     52       1.22      fvdl #include <dev/pci/pcireg.h>
     53       1.22      fvdl #include <dev/pci/pcivar.h>
     54       1.22      fvdl 
     55       1.22      fvdl /* XXXX some i386 on-board chips act weird when memory-mapped */
     56       1.22      fvdl #ifndef __i386__
     57       1.22      fvdl #define AHC_ALLOW_MEMIO
     58       1.22      fvdl #endif
     59       1.22      fvdl 
     60       1.22      fvdl #define AHC_PCI_IOADDR	PCI_MAPREG_START	/* I/O Address */
     61       1.22      fvdl #define AHC_PCI_MEMADDR	(PCI_MAPREG_START + 4)	/* Mem I/O Address */
     62       1.22      fvdl 
     63       1.16    bouyer #include <dev/scsipi/scsi_all.h>
     64       1.16    bouyer #include <dev/scsipi/scsipi_all.h>
     65       1.16    bouyer #include <dev/scsipi/scsiconf.h>
     66        1.1   mycroft 
     67       1.22      fvdl #include <dev/ic/aic7xxxvar.h>
     68       1.22      fvdl #include <dev/ic/smc93cx6var.h>
     69        1.1   mycroft 
     70       1.22      fvdl #include <dev/microcode/aic7xxx/aic7xxx_reg.h>
     71        1.5   thorpej 
     72       1.22      fvdl struct ahc_pci_busdata {
     73       1.22      fvdl 	pci_chipset_tag_t pc;
     74       1.22      fvdl 	pcitag_t tag;
     75       1.22      fvdl 	u_int dev;
     76       1.22      fvdl 	u_int func;
     77       1.22      fvdl };
     78       1.22      fvdl 
     79       1.22      fvdl static __inline u_int64_t
     80       1.22      fvdl ahc_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
     81       1.22      fvdl {
     82       1.22      fvdl 	u_int64_t id;
     83       1.22      fvdl 
     84       1.22      fvdl 	id = subvendor
     85       1.22      fvdl 	   | (subdevice << 16)
     86       1.22      fvdl 	   | ((u_int64_t)vendor << 32)
     87       1.22      fvdl 	   | ((u_int64_t)device << 48);
     88       1.22      fvdl 
     89       1.22      fvdl 	return (id);
     90       1.22      fvdl }
     91       1.22      fvdl 
     92       1.22      fvdl #define ID_ALL_MASK		0xFFFFFFFFFFFFFFFFull
     93       1.22      fvdl #define ID_DEV_VENDOR_MASK	0xFFFFFFFF00000000ull
     94       1.22      fvdl #define ID_AIC7850		0x5078900400000000ull
     95       1.22      fvdl #define ID_AHA_2910_15_20_30C	0x5078900478509004ull
     96       1.22      fvdl #define ID_AIC7855		0x5578900400000000ull
     97       1.22      fvdl #define ID_AIC7859		0x3860900400000000ull
     98       1.22      fvdl #define ID_AHA_2930CU		0x3860900438699004ull
     99       1.22      fvdl #define ID_AIC7860		0x6078900400000000ull
    100       1.22      fvdl #define ID_AIC7860C		0x6078900478609004ull
    101       1.22      fvdl #define ID_AHA_2940AU_0		0x6178900400000000ull
    102       1.22      fvdl #define ID_AHA_2940AU_1		0x6178900478619004ull
    103       1.22      fvdl #define ID_AHA_2940AU_CN	0x2178900478219004ull
    104       1.22      fvdl #define ID_AHA_2930C_VAR	0x6038900438689004ull
    105       1.22      fvdl 
    106       1.22      fvdl #define ID_AIC7870		0x7078900400000000ull
    107       1.22      fvdl #define ID_AHA_2940		0x7178900400000000ull
    108       1.22      fvdl #define ID_AHA_3940		0x7278900400000000ull
    109       1.22      fvdl #define ID_AHA_398X		0x7378900400000000ull
    110       1.22      fvdl #define ID_AHA_2944		0x7478900400000000ull
    111       1.22      fvdl #define ID_AHA_3944		0x7578900400000000ull
    112       1.22      fvdl 
    113       1.22      fvdl #define ID_AIC7880		0x8078900400000000ull
    114       1.22      fvdl #define ID_AIC7880_B		0x8078900478809004ull
    115       1.22      fvdl #define ID_AHA_2940U		0x8178900400000000ull
    116       1.22      fvdl #define ID_AHA_3940U		0x8278900400000000ull
    117       1.22      fvdl #define ID_AHA_2944U		0x8478900400000000ull
    118       1.22      fvdl #define ID_AHA_3944U		0x8578900400000000ull
    119       1.22      fvdl #define ID_AHA_398XU		0x8378900400000000ull
    120       1.22      fvdl #define ID_AHA_4944U		0x8678900400000000ull
    121       1.22      fvdl #define ID_AHA_2940UB		0x8178900478819004ull
    122       1.22      fvdl #define ID_AHA_2930U		0x8878900478889004ull
    123       1.22      fvdl #define ID_AHA_2940U_PRO	0x8778900478879004ull
    124       1.22      fvdl #define ID_AHA_2940U_CN		0x0078900478009004ull
    125       1.22      fvdl 
    126       1.22      fvdl #define ID_AIC7895		0x7895900478959004ull
    127       1.22      fvdl #define ID_AIC7895_RAID_PORT	0x7893900478939004ull
    128       1.22      fvdl #define ID_AHA_2940U_DUAL	0x7895900478919004ull
    129       1.22      fvdl #define ID_AHA_3940AU		0x7895900478929004ull
    130       1.22      fvdl #define ID_AHA_3944AU		0x7895900478949004ull
    131       1.22      fvdl 
    132       1.22      fvdl #define ID_AIC7890		0x001F9005000F9005ull
    133       1.25     soren #define ID_AAA_131U2		0x0013900500039005ull
    134       1.22      fvdl #define ID_AHA_2930U2		0x0011900501819005ull
    135       1.22      fvdl #define ID_AHA_2940U2B		0x00109005A1009005ull
    136       1.22      fvdl #define ID_AHA_2940U2_OEM	0x0010900521809005ull
    137       1.22      fvdl #define ID_AHA_2940U2		0x00109005A1809005ull
    138       1.22      fvdl #define ID_AHA_2950U2B		0x00109005E1009005ull
    139       1.22      fvdl 
    140       1.22      fvdl #define ID_AIC7892		0x008F9005FFFF9005ull
    141  1.32.10.1      tron #define ID_AHA_2915LP		0x0082900502109005ull
    142       1.22      fvdl #define ID_AHA_29160		0x00809005E2A09005ull
    143       1.22      fvdl #define ID_AHA_29160_CPQ	0x00809005E2A00E11ull
    144       1.22      fvdl #define ID_AHA_29160N		0x0080900562A09005ull
    145       1.22      fvdl #define ID_AHA_29160B		0x00809005E2209005ull
    146       1.22      fvdl #define ID_AHA_19160B		0x0081900562A19005ull
    147       1.22      fvdl 
    148       1.22      fvdl #define ID_AIC7896		0x005F9005FFFF9005ull
    149       1.22      fvdl #define ID_AHA_3950U2B_0	0x00509005FFFF9005ull
    150       1.22      fvdl #define ID_AHA_3950U2B_1	0x00509005F5009005ull
    151       1.22      fvdl #define ID_AHA_3950U2D_0	0x00519005FFFF9005ull
    152       1.22      fvdl #define ID_AHA_3950U2D_1	0x00519005B5009005ull
    153       1.22      fvdl 
    154       1.22      fvdl #define ID_AIC7899		0x00CF9005FFFF9005ull
    155       1.22      fvdl #define ID_AHA_3960D		0x00C09005F6209005ull /* AKA AHA-39160 */
    156       1.22      fvdl #define ID_AHA_3960D_CPQ	0x00C09005F6200E11ull
    157       1.22      fvdl 
    158       1.22      fvdl #define ID_AIC7810		0x1078900400000000ull
    159       1.25     soren #define ID_AIC7815		0x7815900400000000ull
    160       1.22      fvdl 
    161       1.22      fvdl typedef int (ahc_device_setup_t)(struct pci_attach_args *, char *,
    162       1.22      fvdl 				 ahc_chip *, ahc_feature *, ahc_flag *);
    163       1.22      fvdl 
    164       1.22      fvdl static ahc_device_setup_t ahc_aic7850_setup;
    165       1.22      fvdl static ahc_device_setup_t ahc_aic7855_setup;
    166       1.22      fvdl static ahc_device_setup_t ahc_aic7859_setup;
    167       1.22      fvdl static ahc_device_setup_t ahc_aic7860_setup;
    168       1.22      fvdl static ahc_device_setup_t ahc_aic7870_setup;
    169       1.22      fvdl static ahc_device_setup_t ahc_aha394X_setup;
    170       1.22      fvdl static ahc_device_setup_t ahc_aha398X_setup;
    171       1.22      fvdl static ahc_device_setup_t ahc_aic7880_setup;
    172       1.22      fvdl static ahc_device_setup_t ahc_2940Pro_setup;
    173       1.22      fvdl static ahc_device_setup_t ahc_aha394XU_setup;
    174       1.22      fvdl static ahc_device_setup_t ahc_aha398XU_setup;
    175       1.22      fvdl static ahc_device_setup_t ahc_aic7890_setup;
    176       1.22      fvdl static ahc_device_setup_t ahc_aic7892_setup;
    177       1.22      fvdl static ahc_device_setup_t ahc_aic7895_setup;
    178       1.22      fvdl static ahc_device_setup_t ahc_aic7896_setup;
    179       1.22      fvdl static ahc_device_setup_t ahc_aic7899_setup;
    180       1.22      fvdl static ahc_device_setup_t ahc_raid_setup;
    181       1.22      fvdl static ahc_device_setup_t ahc_aha394XX_setup;
    182       1.22      fvdl static ahc_device_setup_t ahc_aha398XX_setup;
    183       1.22      fvdl 
    184       1.22      fvdl struct ahc_pci_identity {
    185       1.22      fvdl 	u_int64_t		 full_id;
    186       1.22      fvdl 	u_int64_t		 id_mask;
    187       1.29  jdolecek 	const char		*name;
    188       1.22      fvdl 	ahc_device_setup_t	*setup;
    189       1.22      fvdl };
    190       1.22      fvdl 
    191       1.29  jdolecek const struct ahc_pci_identity ahc_pci_ident_table [] =
    192       1.22      fvdl {
    193       1.22      fvdl 	/* aic7850 based controllers */
    194       1.22      fvdl 	{
    195       1.22      fvdl 		ID_AHA_2910_15_20_30C,
    196       1.22      fvdl 		ID_ALL_MASK,
    197       1.22      fvdl 		"Adaptec 2910/15/20/30C SCSI adapter",
    198       1.22      fvdl 		ahc_aic7850_setup
    199       1.22      fvdl 	},
    200       1.22      fvdl 	/* aic7859 based controllers */
    201       1.22      fvdl 	{
    202       1.22      fvdl 		ID_AHA_2930CU,
    203       1.22      fvdl 		ID_ALL_MASK,
    204       1.22      fvdl 		"Adaptec 2930CU SCSI adapter",
    205       1.22      fvdl 		ahc_aic7859_setup
    206       1.22      fvdl 	},
    207       1.22      fvdl 	/* aic7860 based controllers */
    208       1.22      fvdl 	{
    209       1.22      fvdl 		ID_AHA_2940AU_0 & ID_DEV_VENDOR_MASK,
    210       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    211       1.22      fvdl 		"Adaptec 2940A Ultra SCSI adapter",
    212       1.22      fvdl 		ahc_aic7860_setup
    213       1.22      fvdl 	},
    214       1.22      fvdl 	{
    215       1.22      fvdl 		ID_AHA_2940AU_CN & ID_DEV_VENDOR_MASK,
    216       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    217       1.22      fvdl 		"Adaptec 2940A/CN Ultra SCSI adapter",
    218       1.22      fvdl 		ahc_aic7860_setup
    219       1.22      fvdl 	},
    220       1.22      fvdl 	{
    221       1.22      fvdl 		ID_AHA_2930C_VAR & ID_DEV_VENDOR_MASK,
    222       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    223       1.22      fvdl 		"Adaptec 2930C SCSI adapter (VAR)",
    224       1.22      fvdl 		ahc_aic7860_setup
    225       1.22      fvdl 	},
    226       1.22      fvdl 	/* aic7870 based controllers */
    227       1.22      fvdl 	{
    228       1.22      fvdl 		ID_AHA_2940,
    229       1.22      fvdl 		ID_ALL_MASK,
    230       1.22      fvdl 		"Adaptec 2940 SCSI adapter",
    231       1.22      fvdl 		ahc_aic7870_setup
    232       1.22      fvdl 	},
    233       1.22      fvdl 	{
    234       1.22      fvdl 		ID_AHA_3940,
    235       1.22      fvdl 		ID_ALL_MASK,
    236       1.22      fvdl 		"Adaptec 3940 SCSI adapter",
    237       1.22      fvdl 		ahc_aha394X_setup
    238       1.22      fvdl 	},
    239       1.22      fvdl 	{
    240       1.22      fvdl 		ID_AHA_398X,
    241       1.22      fvdl 		ID_ALL_MASK,
    242       1.22      fvdl 		"Adaptec 398X SCSI RAID adapter",
    243       1.22      fvdl 		ahc_aha398X_setup
    244       1.22      fvdl 	},
    245       1.22      fvdl 	{
    246       1.22      fvdl 		ID_AHA_2944,
    247       1.22      fvdl 		ID_ALL_MASK,
    248       1.22      fvdl 		"Adaptec 2944 SCSI adapter",
    249       1.22      fvdl 		ahc_aic7870_setup
    250       1.22      fvdl 	},
    251       1.22      fvdl 	{
    252       1.22      fvdl 		ID_AHA_3944,
    253       1.22      fvdl 		ID_ALL_MASK,
    254       1.22      fvdl 		"Adaptec 3944 SCSI adapter",
    255       1.22      fvdl 		ahc_aha394X_setup
    256       1.22      fvdl 	},
    257       1.22      fvdl 	/* aic7880 based controllers */
    258       1.22      fvdl 	{
    259       1.22      fvdl 		ID_AHA_2940U & ID_DEV_VENDOR_MASK,
    260       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    261       1.22      fvdl 		"Adaptec 2940 Ultra SCSI adapter",
    262       1.22      fvdl 		ahc_aic7880_setup
    263       1.22      fvdl 	},
    264       1.22      fvdl 	{
    265       1.22      fvdl 		ID_AHA_3940U & ID_DEV_VENDOR_MASK,
    266       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    267       1.22      fvdl 		"Adaptec 3940 Ultra SCSI adapter",
    268       1.22      fvdl 		ahc_aha394XU_setup
    269       1.22      fvdl 	},
    270       1.22      fvdl 	{
    271       1.22      fvdl 		ID_AHA_2944U & ID_DEV_VENDOR_MASK,
    272       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    273       1.22      fvdl 		"Adaptec 2944 Ultra SCSI adapter",
    274       1.22      fvdl 		ahc_aic7880_setup
    275       1.22      fvdl 	},
    276       1.22      fvdl 	{
    277       1.22      fvdl 		ID_AHA_3944U & ID_DEV_VENDOR_MASK,
    278       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    279       1.22      fvdl 		"Adaptec 3944 Ultra SCSI adapter",
    280       1.22      fvdl 		ahc_aha394XU_setup
    281       1.22      fvdl 	},
    282       1.22      fvdl 	{
    283       1.22      fvdl 		ID_AHA_398XU & ID_DEV_VENDOR_MASK,
    284       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    285       1.22      fvdl 		"Adaptec 398X Ultra SCSI RAID adapter",
    286       1.22      fvdl 		ahc_aha398XU_setup
    287       1.22      fvdl 	},
    288       1.22      fvdl 	{
    289       1.22      fvdl 		/*
    290       1.22      fvdl 		 * XXX Don't know the slot numbers
    291       1.22      fvdl 		 * so we can't identify channels
    292       1.22      fvdl 		 */
    293       1.22      fvdl 		ID_AHA_4944U & ID_DEV_VENDOR_MASK,
    294       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    295       1.22      fvdl 		"Adaptec 4944 Ultra SCSI adapter",
    296       1.22      fvdl 		ahc_aic7880_setup
    297       1.22      fvdl 	},
    298       1.22      fvdl 	{
    299       1.22      fvdl 		ID_AHA_2930U & ID_DEV_VENDOR_MASK,
    300       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    301       1.22      fvdl 		"Adaptec 2930 Ultra SCSI adapter",
    302       1.22      fvdl 		ahc_aic7880_setup
    303       1.22      fvdl 	},
    304       1.22      fvdl 	{
    305       1.22      fvdl 		ID_AHA_2940U_PRO & ID_DEV_VENDOR_MASK,
    306       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    307       1.22      fvdl 		"Adaptec 2940 Pro Ultra SCSI adapter",
    308       1.22      fvdl 		ahc_2940Pro_setup
    309       1.22      fvdl 	},
    310       1.22      fvdl 	{
    311       1.22      fvdl 		ID_AHA_2940U_CN & ID_DEV_VENDOR_MASK,
    312       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    313       1.22      fvdl 		"Adaptec 2940/CN Ultra SCSI adapter",
    314       1.22      fvdl 		ahc_aic7880_setup
    315       1.22      fvdl 	},
    316       1.22      fvdl 	/* aic7890 based controllers */
    317       1.22      fvdl 	{
    318       1.22      fvdl 		ID_AHA_2930U2,
    319       1.22      fvdl 		ID_ALL_MASK,
    320       1.22      fvdl 		"Adaptec 2930 Ultra2 SCSI adapter",
    321       1.22      fvdl 		ahc_aic7890_setup
    322       1.22      fvdl 	},
    323       1.22      fvdl 	{
    324       1.22      fvdl 		ID_AHA_2940U2B,
    325       1.22      fvdl 		ID_ALL_MASK,
    326       1.22      fvdl 		"Adaptec 2940B Ultra2 SCSI adapter",
    327       1.22      fvdl 		ahc_aic7890_setup
    328       1.22      fvdl 	},
    329       1.22      fvdl 	{
    330       1.22      fvdl 		ID_AHA_2940U2_OEM,
    331       1.22      fvdl 		ID_ALL_MASK,
    332       1.22      fvdl 		"Adaptec 2940 Ultra2 SCSI adapter (OEM)",
    333       1.22      fvdl 		ahc_aic7890_setup
    334       1.22      fvdl 	},
    335       1.22      fvdl 	{
    336       1.22      fvdl 		ID_AHA_2940U2,
    337       1.22      fvdl 		ID_ALL_MASK,
    338       1.22      fvdl 		"Adaptec 2940 Ultra2 SCSI adapter",
    339       1.22      fvdl 		ahc_aic7890_setup
    340       1.22      fvdl 	},
    341       1.22      fvdl 	{
    342       1.22      fvdl 		ID_AHA_2950U2B,
    343       1.22      fvdl 		ID_ALL_MASK,
    344       1.22      fvdl 		"Adaptec 2950 Ultra2 SCSI adapter",
    345       1.22      fvdl 		ahc_aic7890_setup
    346       1.22      fvdl 	},
    347       1.25     soren 	{
    348       1.25     soren 		ID_AAA_131U2,
    349       1.25     soren 		ID_ALL_MASK,
    350       1.25     soren 		"Adaptec AAA-131 Ultra2 RAID adapter",
    351       1.25     soren 		ahc_aic7890_setup
    352       1.25     soren 	},
    353       1.22      fvdl 	/* aic7892 based controllers */
    354       1.22      fvdl 	{
    355       1.22      fvdl 		ID_AHA_29160,
    356       1.22      fvdl 		ID_ALL_MASK,
    357       1.22      fvdl 		"Adaptec 29160 Ultra160 SCSI adapter",
    358       1.22      fvdl 		ahc_aic7892_setup
    359       1.22      fvdl 	},
    360       1.22      fvdl 	{
    361       1.22      fvdl 		ID_AHA_29160_CPQ,
    362       1.22      fvdl 		ID_ALL_MASK,
    363       1.22      fvdl 		"Adaptec (Compaq OEM) 29160 Ultra160 SCSI adapter",
    364       1.22      fvdl 		ahc_aic7892_setup
    365       1.22      fvdl 	},
    366       1.22      fvdl 	{
    367       1.22      fvdl 		ID_AHA_29160N,
    368       1.22      fvdl 		ID_ALL_MASK,
    369       1.22      fvdl 		"Adaptec 29160N Ultra160 SCSI adapter",
    370       1.22      fvdl 		ahc_aic7892_setup
    371       1.22      fvdl 	},
    372       1.22      fvdl 	{
    373       1.22      fvdl 		ID_AHA_29160B,
    374       1.22      fvdl 		ID_ALL_MASK,
    375       1.22      fvdl 		"Adaptec 29160B Ultra160 SCSI adapter",
    376       1.22      fvdl 		ahc_aic7892_setup
    377       1.22      fvdl 	},
    378       1.22      fvdl 	{
    379       1.22      fvdl 		ID_AHA_19160B,
    380       1.22      fvdl 		ID_ALL_MASK,
    381       1.22      fvdl 		"Adaptec 19160B Ultra160 SCSI adapter",
    382  1.32.10.1      tron 		ahc_aic7892_setup
    383  1.32.10.1      tron 	},
    384  1.32.10.1      tron 	{
    385  1.32.10.1      tron 		ID_AHA_2915LP,
    386  1.32.10.1      tron 		ID_ALL_MASK,
    387  1.32.10.1      tron 		"Adaptec 2915LP Ultra160 SCSI adapter",
    388       1.22      fvdl 		ahc_aic7892_setup
    389       1.22      fvdl 	},
    390       1.22      fvdl 	/* aic7895 based controllers */
    391       1.22      fvdl 	{
    392       1.22      fvdl 		ID_AHA_2940U_DUAL,
    393       1.22      fvdl 		ID_ALL_MASK,
    394       1.22      fvdl 		"Adaptec 2940/DUAL Ultra SCSI adapter",
    395       1.22      fvdl 		ahc_aic7895_setup
    396       1.22      fvdl 	},
    397       1.22      fvdl 	{
    398       1.22      fvdl 		ID_AHA_3940AU,
    399       1.22      fvdl 		ID_ALL_MASK,
    400       1.22      fvdl 		"Adaptec 3940A Ultra SCSI adapter",
    401       1.22      fvdl 		ahc_aic7895_setup
    402       1.22      fvdl 	},
    403       1.22      fvdl 	{
    404       1.22      fvdl 		ID_AHA_3944AU,
    405       1.22      fvdl 		ID_ALL_MASK,
    406       1.22      fvdl 		"Adaptec 3944A Ultra SCSI adapter",
    407       1.22      fvdl 		ahc_aic7895_setup
    408       1.22      fvdl 	},
    409       1.22      fvdl 	/* aic7896/97 based controllers */
    410       1.22      fvdl 	{
    411       1.22      fvdl 		ID_AHA_3950U2B_0,
    412       1.22      fvdl 		ID_ALL_MASK,
    413       1.22      fvdl 		"Adaptec 3950B Ultra2 SCSI adapter",
    414       1.22      fvdl 		ahc_aic7896_setup
    415       1.22      fvdl 	},
    416       1.22      fvdl 	{
    417       1.22      fvdl 		ID_AHA_3950U2B_1,
    418       1.22      fvdl 		ID_ALL_MASK,
    419       1.22      fvdl 		"Adaptec 3950B Ultra2 SCSI adapter",
    420       1.22      fvdl 		ahc_aic7896_setup
    421       1.22      fvdl 	},
    422       1.22      fvdl 	{
    423       1.22      fvdl 		ID_AHA_3950U2D_0,
    424       1.22      fvdl 		ID_ALL_MASK,
    425       1.22      fvdl 		"Adaptec 3950D Ultra2 SCSI adapter",
    426       1.22      fvdl 		ahc_aic7896_setup
    427       1.22      fvdl 	},
    428       1.22      fvdl 	{
    429       1.22      fvdl 		ID_AHA_3950U2D_1,
    430       1.22      fvdl 		ID_ALL_MASK,
    431       1.22      fvdl 		"Adaptec 3950D Ultra2 SCSI adapter",
    432       1.22      fvdl 		ahc_aic7896_setup
    433       1.22      fvdl 	},
    434       1.22      fvdl 	/* aic7899 based controllers */
    435       1.22      fvdl 	{
    436       1.22      fvdl 		ID_AHA_3960D,
    437       1.22      fvdl 		ID_ALL_MASK,
    438       1.22      fvdl 		"Adaptec 3960D Ultra160 SCSI adapter",
    439       1.22      fvdl 		ahc_aic7899_setup
    440       1.22      fvdl 	},
    441       1.22      fvdl 	{
    442       1.22      fvdl 		ID_AHA_3960D_CPQ,
    443       1.22      fvdl 		ID_ALL_MASK,
    444       1.22      fvdl 		"Adaptec (Compaq OEM) 3960D Ultra160 SCSI adapter",
    445       1.22      fvdl 		ahc_aic7899_setup
    446       1.22      fvdl 	},
    447       1.22      fvdl 	/* Generic chip probes for devices we don't know 'exactly' */
    448       1.22      fvdl 	{
    449       1.22      fvdl 		ID_AIC7850 & ID_DEV_VENDOR_MASK,
    450       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    451       1.22      fvdl 		"Adaptec aic7850 SCSI adapter",
    452       1.22      fvdl 		ahc_aic7850_setup
    453       1.22      fvdl 	},
    454       1.22      fvdl 	{
    455       1.22      fvdl 		ID_AIC7855 & ID_DEV_VENDOR_MASK,
    456       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    457       1.22      fvdl 		"Adaptec aic7855 SCSI adapter",
    458       1.22      fvdl 		ahc_aic7855_setup
    459       1.22      fvdl 	},
    460       1.22      fvdl 	{
    461       1.22      fvdl 		ID_AIC7859 & ID_DEV_VENDOR_MASK,
    462       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    463       1.22      fvdl 		"Adaptec aic7859 SCSI adapter",
    464       1.22      fvdl 		ahc_aic7859_setup
    465       1.22      fvdl 	},
    466       1.22      fvdl 	{
    467       1.22      fvdl 		ID_AIC7860 & ID_DEV_VENDOR_MASK,
    468       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    469       1.22      fvdl 		"Adaptec aic7860 SCSI adapter",
    470       1.22      fvdl 		ahc_aic7860_setup
    471       1.22      fvdl 	},
    472       1.22      fvdl 	{
    473       1.22      fvdl 		ID_AIC7870 & ID_DEV_VENDOR_MASK,
    474       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    475       1.22      fvdl 		"Adaptec aic7870 SCSI adapter",
    476       1.22      fvdl 		ahc_aic7870_setup
    477       1.22      fvdl 	},
    478       1.22      fvdl 	{
    479       1.22      fvdl 		ID_AIC7880 & ID_DEV_VENDOR_MASK,
    480       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    481       1.22      fvdl 		"Adaptec aic7880 Ultra SCSI adapter",
    482       1.22      fvdl 		ahc_aic7880_setup
    483       1.22      fvdl 	},
    484       1.22      fvdl 	{
    485       1.22      fvdl 		ID_AIC7890 & ID_DEV_VENDOR_MASK,
    486       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    487       1.22      fvdl 		"Adaptec aic7890/91 Ultra2 SCSI adapter",
    488       1.22      fvdl 		ahc_aic7890_setup
    489       1.22      fvdl 	},
    490       1.22      fvdl 	{
    491       1.22      fvdl 		ID_AIC7892 & ID_DEV_VENDOR_MASK,
    492       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    493       1.22      fvdl 		"Adaptec aic7892 Ultra160 SCSI adapter",
    494       1.22      fvdl 		ahc_aic7892_setup
    495       1.22      fvdl 	},
    496       1.22      fvdl 	{
    497       1.22      fvdl 		ID_AIC7895 & ID_DEV_VENDOR_MASK,
    498       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    499       1.22      fvdl 		"Adaptec aic7895 Ultra SCSI adapter",
    500       1.22      fvdl 		ahc_aic7895_setup
    501       1.22      fvdl 	},
    502       1.22      fvdl 	{
    503       1.22      fvdl 		ID_AIC7895_RAID_PORT & ID_DEV_VENDOR_MASK,
    504       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    505       1.22      fvdl 		"Adaptec aic7895 Ultra SCSI adapter (RAID PORT)",
    506       1.22      fvdl 		ahc_aic7895_setup
    507       1.22      fvdl 	},
    508       1.22      fvdl 	{
    509       1.22      fvdl 		ID_AIC7896 & ID_DEV_VENDOR_MASK,
    510       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    511       1.22      fvdl 		"Adaptec aic7896/97 Ultra2 SCSI adapter",
    512       1.22      fvdl 		ahc_aic7896_setup
    513       1.22      fvdl 	},
    514       1.22      fvdl 	{
    515       1.22      fvdl 		ID_AIC7899 & ID_DEV_VENDOR_MASK,
    516       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    517       1.22      fvdl 		"Adaptec aic7899 Ultra160 SCSI adapter",
    518       1.22      fvdl 		ahc_aic7899_setup
    519       1.22      fvdl 	},
    520       1.22      fvdl 	{
    521       1.22      fvdl 		ID_AIC7810 & ID_DEV_VENDOR_MASK,
    522       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    523       1.22      fvdl 		"Adaptec aic7810 RAID memory controller",
    524       1.22      fvdl 		ahc_raid_setup
    525       1.22      fvdl 	},
    526       1.22      fvdl 	{
    527       1.22      fvdl 		ID_AIC7815 & ID_DEV_VENDOR_MASK,
    528       1.22      fvdl 		ID_DEV_VENDOR_MASK,
    529       1.22      fvdl 		"Adaptec aic7815 RAID memory controller",
    530       1.22      fvdl 		ahc_raid_setup
    531       1.22      fvdl 	}
    532       1.22      fvdl };
    533       1.12       cgd 
    534       1.22      fvdl static const int ahc_num_pci_devs =
    535       1.22      fvdl 	sizeof(ahc_pci_ident_table) / sizeof(*ahc_pci_ident_table);
    536       1.22      fvdl 
    537       1.22      fvdl #define AHC_394X_SLOT_CHANNEL_A	4
    538       1.22      fvdl #define AHC_394X_SLOT_CHANNEL_B	5
    539       1.22      fvdl 
    540       1.22      fvdl #define AHC_398X_SLOT_CHANNEL_A	4
    541       1.22      fvdl #define AHC_398X_SLOT_CHANNEL_B	8
    542       1.22      fvdl #define AHC_398X_SLOT_CHANNEL_C	12
    543        1.1   mycroft 
    544        1.1   mycroft #define	DEVCONFIG		0x40
    545       1.22      fvdl #define		SCBSIZE32	0x00010000	/* aic789X only */
    546       1.22      fvdl #define		MPORTMODE	0x00000400	/* aic7870 only */
    547       1.22      fvdl #define		RAMPSM		0x00000200	/* aic7870 only */
    548       1.22      fvdl #define		VOLSENSE	0x00000100
    549       1.22      fvdl #define		SCBRAMSEL	0x00000080
    550       1.22      fvdl #define		MRDCEN		0x00000040
    551       1.22      fvdl #define		EXTSCBTIME	0x00000020	/* aic7870 only */
    552       1.22      fvdl #define		EXTSCBPEN	0x00000010	/* aic7870 only */
    553       1.22      fvdl #define		BERREN		0x00000008
    554       1.22      fvdl #define		DACEN		0x00000004
    555       1.22      fvdl #define		STPWLEVEL	0x00000002
    556       1.22      fvdl #define		DIFACTNEGEN	0x00000001	/* aic7870 only */
    557        1.1   mycroft 
    558        1.1   mycroft #define	CSIZE_LATTIME		0x0c
    559       1.22      fvdl #define		CACHESIZE	0x0000003f	/* only 5 bits */
    560       1.22      fvdl #define		LATTIME		0x0000ff00
    561        1.1   mycroft 
    562       1.29  jdolecek static const struct ahc_pci_identity *ahc_find_pci_device(pcireg_t, pcireg_t);
    563       1.22      fvdl static int ahc_ext_scbram_present(struct ahc_softc *ahc);
    564       1.22      fvdl static void ahc_ext_scbram_config(struct ahc_softc *ahc, int enable,
    565       1.22      fvdl 				  int pcheck, int fast);
    566       1.22      fvdl static void ahc_probe_ext_scbram(struct ahc_softc *ahc);
    567        1.1   mycroft 
    568       1.10       cgd int ahc_pci_probe __P((struct device *, struct cfdata *, void *));
    569        1.1   mycroft void ahc_pci_attach __P((struct device *, struct device *, void *));
    570        1.1   mycroft 
    571       1.22      fvdl /* Exported for use in the ahc_intr routine */
    572       1.23      fvdl int ahc_pci_intr(struct ahc_softc *ahc);
    573       1.22      fvdl 
    574        1.1   mycroft struct cfattach ahc_pci_ca = {
    575       1.22      fvdl         sizeof(struct ahc_softc), ahc_pci_probe, ahc_pci_attach
    576        1.1   mycroft };
    577        1.1   mycroft 
    578       1.29  jdolecek static const struct ahc_pci_identity *
    579       1.22      fvdl ahc_find_pci_device(id, subid)
    580       1.22      fvdl 	pcireg_t id, subid;
    581       1.22      fvdl {
    582       1.22      fvdl 	u_int64_t  full_id;
    583       1.29  jdolecek 	const struct	   ahc_pci_identity *entry;
    584       1.22      fvdl 	u_int	   i;
    585       1.22      fvdl 
    586       1.22      fvdl 	full_id = ahc_compose_id(PCI_PRODUCT(id), PCI_VENDOR(id),
    587       1.22      fvdl 				 PCI_PRODUCT(subid), PCI_VENDOR(subid));
    588       1.22      fvdl 
    589       1.22      fvdl 	for (i = 0; i < ahc_num_pci_devs; i++) {
    590       1.22      fvdl 		entry = &ahc_pci_ident_table[i];
    591       1.22      fvdl 		if (entry->full_id == (full_id & entry->id_mask))
    592       1.22      fvdl 			return (entry);
    593       1.22      fvdl 	}
    594       1.22      fvdl 	return (NULL);
    595       1.22      fvdl }
    596       1.22      fvdl 
    597        1.1   mycroft int
    598        1.1   mycroft ahc_pci_probe(parent, match, aux)
    599       1.22      fvdl 	struct device *parent;
    600       1.22      fvdl 	struct cfdata *match;
    601       1.22      fvdl 	void *aux;
    602       1.22      fvdl {
    603       1.22      fvdl 	struct pci_attach_args *pa = aux;
    604       1.29  jdolecek 	const struct	   ahc_pci_identity *entry;
    605       1.22      fvdl 	pcireg_t   subid;
    606       1.22      fvdl 
    607       1.22      fvdl 	subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    608       1.22      fvdl 	entry = ahc_find_pci_device(pa->pa_id, subid);
    609       1.22      fvdl 	return entry != NULL ? 1 : 0;
    610        1.1   mycroft }
    611        1.1   mycroft 
    612       1.22      fvdl void
    613        1.1   mycroft ahc_pci_attach(parent, self, aux)
    614       1.22      fvdl 	struct device *parent, *self;
    615       1.22      fvdl 	void *aux;
    616        1.1   mycroft {
    617        1.1   mycroft 	struct pci_attach_args *pa = aux;
    618       1.29  jdolecek 	const struct	   ahc_pci_identity *entry;
    619       1.22      fvdl 	struct		   ahc_softc *ahc = (void *)self;
    620       1.22      fvdl 	pcireg_t	   command;
    621       1.22      fvdl 	ahc_chip	   ahc_t = AHC_NONE;
    622       1.22      fvdl 	ahc_feature	   ahc_fe = AHC_FENONE;
    623       1.22      fvdl 	ahc_flag	   ahc_f = AHC_FNONE;
    624       1.22      fvdl 	u_int		   our_id = 0;
    625       1.22      fvdl 	u_int		   sxfrctl1;
    626       1.22      fvdl 	u_int		   scsiseq;
    627       1.22      fvdl 	int		   error;
    628       1.22      fvdl 	char		   channel;
    629       1.22      fvdl 	pcireg_t	   subid;
    630       1.22      fvdl 	int		   ioh_valid, memh_valid;
    631       1.22      fvdl 	bus_space_tag_t st, iot;
    632       1.22      fvdl 	bus_space_handle_t sh, ioh;
    633       1.22      fvdl #ifdef AHC_ALLOW_MEMIO
    634       1.22      fvdl 	bus_space_tag_t memt;
    635       1.22      fvdl 	bus_space_handle_t memh;
    636       1.24   thorpej 	pcireg_t memtype;
    637       1.22      fvdl #endif
    638        1.1   mycroft 	pci_intr_handle_t ih;
    639        1.1   mycroft 	const char *intrstr;
    640       1.22      fvdl 	struct ahc_pci_busdata *bd;
    641       1.22      fvdl 
    642       1.22      fvdl 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    643       1.22      fvdl 	subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
    644       1.22      fvdl 	entry = ahc_find_pci_device(pa->pa_id, subid);
    645       1.22      fvdl 	if (entry == NULL)
    646       1.22      fvdl 		return;
    647       1.22      fvdl 	error = entry->setup(pa, &channel, &ahc_t, &ahc_fe, &ahc_f);
    648       1.22      fvdl 	if (error != 0)
    649       1.22      fvdl 		return;
    650       1.22      fvdl 
    651       1.22      fvdl 	ioh_valid = memh_valid = 0;
    652       1.22      fvdl 
    653       1.22      fvdl #ifdef AHC_ALLOW_MEMIO
    654       1.24   thorpej 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, AHC_PCI_MEMADDR);
    655       1.24   thorpej 	switch (memtype) {
    656       1.24   thorpej 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
    657       1.24   thorpej 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
    658       1.24   thorpej 		memh_valid = (pci_mapreg_map(pa, AHC_PCI_MEMADDR,
    659       1.24   thorpej 		    memtype, 0, &memt, &memh, NULL, NULL) == 0);
    660       1.24   thorpej 		break;
    661       1.24   thorpej 	default:
    662       1.24   thorpej 		memh_valid = 0;
    663       1.24   thorpej 	}
    664       1.22      fvdl #endif
    665       1.22      fvdl 	ioh_valid = (pci_mapreg_map(pa, AHC_PCI_IOADDR,
    666       1.22      fvdl 	    PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, NULL, NULL) == 0);
    667       1.13       cgd 
    668       1.22      fvdl 	if (ioh_valid) {
    669       1.22      fvdl 		st = iot;
    670       1.22      fvdl 		sh = ioh;
    671       1.22      fvdl #ifdef AHC_ALLOW_MEMIO
    672       1.22      fvdl 	} else if (memh_valid) {
    673       1.13       cgd 		st = memt;
    674       1.13       cgd 		sh = memh;
    675       1.22      fvdl #endif
    676       1.12       cgd 	} else {
    677       1.13       cgd 		printf(": unable to map registers\n");
    678        1.1   mycroft 		return;
    679       1.12       cgd 	}
    680       1.22      fvdl 
    681       1.12       cgd 	printf("\n");
    682       1.22      fvdl 
    683        1.1   mycroft 
    684       1.22      fvdl 	/* Ensure busmastering is enabled */
    685       1.22      fvdl 	command |= PCI_COMMAND_MASTER_ENABLE;;
    686       1.22      fvdl 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
    687        1.1   mycroft 
    688        1.1   mycroft 	/* On all PCI adapters, we allow SCB paging */
    689        1.1   mycroft 	ahc_f |= AHC_PAGESCBS;
    690       1.22      fvdl 	if (ahc_alloc(ahc, sh, st, pa->pa_dmat,
    691       1.22      fvdl 	    ahc_t|AHC_PCI, ahc_fe, ahc_f) < 0)
    692       1.22      fvdl 		return;
    693       1.22      fvdl 
    694       1.22      fvdl 	bd = malloc(sizeof (struct ahc_pci_busdata), M_DEVBUF, M_NOWAIT);
    695       1.22      fvdl 	if (bd == NULL) {
    696       1.22      fvdl 		printf(": unable to allocate bus-specific data\n");
    697       1.22      fvdl 		return;
    698       1.22      fvdl 	}
    699        1.1   mycroft 
    700       1.22      fvdl 	bd->pc = pa->pa_pc;
    701       1.22      fvdl 	bd->tag = pa->pa_tag;
    702       1.22      fvdl 	bd->func = pa->pa_function;
    703       1.22      fvdl 	bd->dev = pa->pa_device;
    704       1.22      fvdl 
    705       1.22      fvdl 	ahc->bus_data = bd;
    706       1.23      fvdl 	ahc->bus_intr = ahc_pci_intr;
    707       1.22      fvdl 	ahc->channel = channel;
    708        1.1   mycroft 
    709       1.22      fvdl 	/* Remeber how the card was setup in case there is no SEEPROM */
    710       1.22      fvdl 	ahc_outb(ahc, HCNTRL, ahc->pause);
    711       1.22      fvdl 	if ((ahc->features & AHC_ULTRA2) != 0)
    712       1.22      fvdl 		our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
    713       1.22      fvdl 	else
    714       1.22      fvdl 		our_id = ahc_inb(ahc, SCSIID) & OID;
    715       1.22      fvdl 	sxfrctl1 = ahc_inb(ahc, SXFRCTL1) & STPWEN;
    716       1.22      fvdl 	scsiseq = ahc_inb(ahc, SCSISEQ);
    717        1.1   mycroft 
    718       1.22      fvdl 	if (ahc_reset(ahc) != 0) {
    719       1.22      fvdl 		/* Failed */
    720       1.22      fvdl 		ahc_free(ahc);
    721       1.22      fvdl 		return;
    722        1.1   mycroft 	}
    723        1.1   mycroft 
    724       1.22      fvdl 	if ((ahc->features & AHC_DT) != 0) {
    725       1.22      fvdl 		u_int optionmode;
    726       1.22      fvdl 		u_int sfunct;
    727       1.22      fvdl 
    728       1.22      fvdl 		/* Perform ALT-Mode Setup */
    729       1.22      fvdl 		sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
    730       1.22      fvdl 		ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
    731       1.22      fvdl 		optionmode = ahc_inb(ahc, OPTIONMODE);
    732       1.30  christos #ifdef DEBUG
    733       1.30  christos 		printf("%s: OptionMode = %x\n", ahc->sc_dev.dv_xname,
    734       1.30  christos 		    optionmode);
    735       1.30  christos #endif
    736       1.22      fvdl 		ahc_outb(ahc, OPTIONMODE, OPTIONMODE_DEFAULTS);
    737       1.22      fvdl 		/* Send CRC info in target mode every 4K */
    738       1.22      fvdl 		ahc_outb(ahc, TARGCRCCNT, 0);
    739       1.22      fvdl 		ahc_outb(ahc, TARGCRCCNT + 1, 0x10);
    740       1.22      fvdl 		ahc_outb(ahc, SFUNCT, sfunct);
    741       1.22      fvdl 
    742       1.22      fvdl 		/* Normal mode setup */
    743       1.22      fvdl 		ahc_outb(ahc, CRCCONTROL1, CRCVALCHKEN|CRCENDCHKEN|CRCREQCHKEN
    744       1.22      fvdl 					  |TARGCRCENDEN|TARGCRCCNTEN);
    745       1.22      fvdl 	}
    746        1.1   mycroft 
    747       1.28  sommerfe 	if (pci_intr_map(pa, &ih)) {
    748        1.8  christos 		printf("%s: couldn't map interrupt\n", ahc->sc_dev.dv_xname);
    749        1.1   mycroft 		ahc_free(ahc);
    750        1.1   mycroft 		return;
    751        1.1   mycroft 	}
    752        1.1   mycroft 	intrstr = pci_intr_string(pa->pa_pc, ih);
    753       1.22      fvdl 	ahc->ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ahc_intr, ahc);
    754       1.22      fvdl 	if (ahc->ih == NULL) {
    755        1.8  christos 		printf("%s: couldn't establish interrupt",
    756        1.1   mycroft 		       ahc->sc_dev.dv_xname);
    757        1.1   mycroft 		if (intrstr != NULL)
    758        1.8  christos 			printf(" at %s", intrstr);
    759        1.8  christos 		printf("\n");
    760        1.1   mycroft 		ahc_free(ahc);
    761        1.1   mycroft 		return;
    762        1.1   mycroft 	}
    763        1.1   mycroft 	if (intrstr != NULL)
    764        1.8  christos 		printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
    765        1.1   mycroft 		       intrstr);
    766       1.21   thorpej 
    767        1.1   mycroft 	/*
    768       1.22      fvdl 	 * Do aic7880/aic7870/aic7860/aic7850 specific initialization
    769        1.1   mycroft 	 */
    770       1.22      fvdl 	{
    771       1.22      fvdl 		u_int8_t sblkctl;
    772       1.22      fvdl 		u_int dscommand0;
    773        1.1   mycroft 
    774       1.22      fvdl 		dscommand0 = ahc_inb(ahc, DSCOMMAND0);
    775       1.22      fvdl 		dscommand0 |= MPARCKEN;
    776       1.22      fvdl 		if ((ahc->features & AHC_ULTRA2) != 0) {
    777        1.1   mycroft 
    778        1.1   mycroft 			/*
    779       1.22      fvdl 			 * DPARCKEN doesn't work correctly on
    780       1.22      fvdl 			 * some MBs so don't use it.
    781        1.1   mycroft 			 */
    782       1.22      fvdl 			dscommand0 &= ~(USCBSIZE32|DPARCKEN);
    783       1.22      fvdl 			dscommand0 |= CACHETHEN;
    784        1.1   mycroft 		}
    785        1.1   mycroft 
    786       1.22      fvdl 		ahc_outb(ahc, DSCOMMAND0, dscommand0);
    787       1.22      fvdl 
    788       1.22      fvdl 		/* See if we have an SEEPROM and perform auto-term */
    789       1.22      fvdl 		check_extport(ahc, &sxfrctl1);
    790       1.22      fvdl 
    791        1.1   mycroft 		/*
    792        1.1   mycroft 		 * Take the LED out of diagnostic mode
    793        1.1   mycroft 		 */
    794       1.22      fvdl 		sblkctl = ahc_inb(ahc, SBLKCTL);
    795       1.22      fvdl 		ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
    796        1.1   mycroft 
    797        1.1   mycroft 		/*
    798        1.1   mycroft 		 * I don't know where this is set in the SEEPROM or by the
    799       1.22      fvdl 		 * BIOS, so we default to 100% on Ultra or slower controllers
    800       1.22      fvdl 		 * and 75% on ULTRA2 controllers.
    801        1.1   mycroft 		 */
    802       1.22      fvdl 		if ((ahc->features & AHC_ULTRA2) != 0) {
    803       1.22      fvdl 			ahc_outb(ahc, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
    804       1.22      fvdl 		} else {
    805       1.22      fvdl 			ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
    806       1.22      fvdl 		}
    807        1.1   mycroft 
    808       1.22      fvdl 		if (ahc->flags & AHC_USEDEFAULTS) {
    809        1.1   mycroft 			/*
    810        1.1   mycroft 			 * PCI Adapter default setup
    811        1.1   mycroft 			 * Should only be used if the adapter does not have
    812        1.1   mycroft 			 * an SEEPROM.
    813        1.1   mycroft 			 */
    814        1.1   mycroft 			/* See if someone else set us up already */
    815       1.22      fvdl 			if (scsiseq != 0) {
    816        1.8  christos 				printf("%s: Using left over BIOS settings\n",
    817        1.1   mycroft 					ahc_name(ahc));
    818        1.1   mycroft 				ahc->flags &= ~AHC_USEDEFAULTS;
    819       1.22      fvdl 			} else {
    820        1.1   mycroft 				/*
    821       1.22      fvdl 				 * Assume only one connector and always turn
    822       1.22      fvdl 				 * on termination.
    823        1.1   mycroft 				 */
    824       1.22      fvdl  				our_id = 0x07;
    825       1.22      fvdl 				sxfrctl1 = STPWEN;
    826        1.1   mycroft 			}
    827       1.22      fvdl 			ahc_outb(ahc, SCSICONF, our_id|ENSPCHK|RESET_SCSI);
    828       1.22      fvdl 
    829       1.22      fvdl 			ahc->our_id = our_id;
    830        1.1   mycroft 		}
    831       1.22      fvdl 	}
    832       1.22      fvdl 
    833       1.22      fvdl 	/*
    834       1.22      fvdl 	 * Take a look to see if we have external SRAM.
    835       1.22      fvdl 	 * We currently do not attempt to use SRAM that is
    836       1.22      fvdl 	 * shared among multiple controllers.
    837       1.22      fvdl 	 */
    838       1.22      fvdl 	ahc_probe_ext_scbram(ahc);
    839       1.22      fvdl 
    840        1.1   mycroft 
    841       1.22      fvdl 	printf("%s: %s ", ahc_name(ahc),
    842       1.22      fvdl 	       ahc_chip_names[ahc->chip & AHC_CHIPID_MASK]);
    843       1.22      fvdl 
    844       1.22      fvdl 	/*
    845       1.22      fvdl 	 * Record our termination setting for the
    846       1.22      fvdl 	 * generic initialization routine.
    847       1.22      fvdl 	 */
    848       1.22      fvdl 	if ((sxfrctl1 & STPWEN) != 0)
    849       1.22      fvdl 		ahc->flags |= AHC_TERM_ENB_A;
    850        1.1   mycroft 
    851       1.22      fvdl 	if (ahc_init(ahc)) {
    852        1.1   mycroft 		ahc_free(ahc);
    853       1.22      fvdl 		return;
    854        1.1   mycroft 	}
    855        1.1   mycroft 
    856        1.1   mycroft 	ahc_attach(ahc);
    857       1.22      fvdl }
    858       1.22      fvdl 
    859       1.22      fvdl /*
    860       1.32       wiz  * Test for the presence of external sram in an
    861       1.22      fvdl  * "unshared" configuration.
    862       1.22      fvdl  */
    863       1.22      fvdl static int
    864       1.22      fvdl ahc_ext_scbram_present(struct ahc_softc *ahc)
    865       1.22      fvdl {
    866       1.22      fvdl 	int ramps;
    867       1.22      fvdl 	int single_user;
    868       1.22      fvdl 	pcireg_t devconfig;
    869       1.22      fvdl 	struct ahc_pci_busdata *bd = ahc->bus_data;
    870       1.22      fvdl 
    871       1.22      fvdl 	devconfig = pci_conf_read(bd->pc, bd->tag, DEVCONFIG);
    872       1.22      fvdl 	single_user = (devconfig & MPORTMODE) != 0;
    873       1.22      fvdl 
    874       1.22      fvdl 	if ((ahc->features & AHC_ULTRA2) != 0)
    875       1.22      fvdl 		ramps = (ahc_inb(ahc, DSCOMMAND0) & RAMPS) != 0;
    876       1.22      fvdl 	else if ((ahc->chip & AHC_CHIPID_MASK) >= AHC_AIC7870)
    877       1.22      fvdl 		ramps = (devconfig & RAMPSM) != 0;
    878       1.22      fvdl 	else
    879       1.22      fvdl 		ramps = 0;
    880       1.22      fvdl 
    881       1.22      fvdl 	if (ramps && single_user)
    882       1.22      fvdl 		return (1);
    883       1.22      fvdl 	return (0);
    884       1.22      fvdl }
    885       1.22      fvdl 
    886       1.22      fvdl /*
    887       1.22      fvdl  * Enable external scbram.
    888       1.22      fvdl  */
    889       1.22      fvdl static void
    890       1.22      fvdl ahc_ext_scbram_config(struct ahc_softc *ahc, int enable, int pcheck, int fast)
    891       1.22      fvdl {
    892       1.22      fvdl 	pcireg_t devconfig;
    893       1.22      fvdl 	struct ahc_pci_busdata *bd = ahc->bus_data;
    894       1.22      fvdl 
    895       1.22      fvdl 	if (ahc->features & AHC_MULTI_FUNC) {
    896       1.22      fvdl 		/*
    897       1.22      fvdl 		 * Set the SCB Base addr (highest address bit)
    898       1.22      fvdl 		 * depending on which channel we are.
    899       1.22      fvdl 		 */
    900       1.22      fvdl 		ahc_outb(ahc, SCBBADDR, (u_int8_t)bd->func);
    901       1.22      fvdl 	}
    902       1.22      fvdl 
    903       1.22      fvdl 	devconfig = pci_conf_read(bd->pc, bd->tag, DEVCONFIG);
    904       1.22      fvdl 	if ((ahc->features & AHC_ULTRA2) != 0) {
    905       1.22      fvdl 		u_int dscommand0;
    906       1.22      fvdl 
    907       1.22      fvdl 		dscommand0 = ahc_inb(ahc, DSCOMMAND0);
    908       1.22      fvdl 		if (enable)
    909       1.22      fvdl 			dscommand0 &= ~INTSCBRAMSEL;
    910       1.22      fvdl 		else
    911       1.22      fvdl 			dscommand0 |= INTSCBRAMSEL;
    912       1.22      fvdl 		ahc_outb(ahc, DSCOMMAND0, dscommand0);
    913       1.22      fvdl 	} else {
    914       1.22      fvdl 		if (fast)
    915       1.22      fvdl 			devconfig &= ~EXTSCBTIME;
    916       1.22      fvdl 		else
    917       1.22      fvdl 			devconfig |= EXTSCBTIME;
    918       1.22      fvdl 		if (enable)
    919       1.22      fvdl 			devconfig &= ~SCBRAMSEL;
    920       1.22      fvdl 		else
    921       1.22      fvdl 			devconfig |= SCBRAMSEL;
    922       1.22      fvdl 	}
    923       1.22      fvdl 	if (pcheck)
    924       1.22      fvdl 		devconfig |= EXTSCBPEN;
    925       1.22      fvdl 	else
    926       1.22      fvdl 		devconfig &= ~EXTSCBPEN;
    927       1.22      fvdl 
    928       1.22      fvdl 	pci_conf_write(bd->pc, bd->tag, DEVCONFIG, devconfig);
    929       1.22      fvdl }
    930       1.22      fvdl 
    931       1.22      fvdl /*
    932       1.22      fvdl  * Take a look to see if we have external SRAM.
    933       1.22      fvdl  * We currently do not attempt to use SRAM that is
    934       1.22      fvdl  * shared among multiple controllers.
    935       1.22      fvdl  */
    936       1.22      fvdl static void
    937       1.22      fvdl ahc_probe_ext_scbram(struct ahc_softc *ahc)
    938       1.22      fvdl {
    939       1.22      fvdl 	int num_scbs;
    940       1.22      fvdl 	int test_num_scbs;
    941       1.22      fvdl 	int enable;
    942       1.22      fvdl 	int pcheck;
    943       1.22      fvdl 	int fast;
    944       1.22      fvdl 
    945       1.22      fvdl 	if (ahc_ext_scbram_present(ahc) == 0)
    946       1.22      fvdl 		return;
    947       1.22      fvdl 
    948       1.22      fvdl 	/*
    949       1.22      fvdl 	 * Probe for the best parameters to use.
    950       1.22      fvdl 	 */
    951       1.22      fvdl 	enable = FALSE;
    952       1.22      fvdl 	pcheck = FALSE;
    953       1.22      fvdl 	fast = FALSE;
    954       1.22      fvdl 	ahc_ext_scbram_config(ahc, /*enable*/TRUE, pcheck, fast);
    955       1.22      fvdl 	num_scbs = ahc_probe_scbs(ahc);
    956       1.22      fvdl 	if (num_scbs == 0) {
    957       1.22      fvdl 		/* The SRAM wasn't really present. */
    958       1.22      fvdl 		goto done;
    959       1.22      fvdl 	}
    960       1.22      fvdl 	enable = TRUE;
    961       1.22      fvdl 
    962       1.22      fvdl 	/*
    963       1.22      fvdl 	 * Clear any outstanding parity error
    964       1.22      fvdl 	 * and ensure that parity error reporting
    965       1.22      fvdl 	 * is enabled.
    966       1.22      fvdl 	 */
    967       1.22      fvdl 	ahc_outb(ahc, SEQCTL, 0);
    968       1.22      fvdl 	ahc_outb(ahc, CLRINT, CLRPARERR);
    969       1.22      fvdl 	ahc_outb(ahc, CLRINT, CLRBRKADRINT);
    970       1.22      fvdl 
    971       1.22      fvdl 	/* Now see if we can do parity */
    972       1.22      fvdl 	ahc_ext_scbram_config(ahc, enable, /*pcheck*/TRUE, fast);
    973       1.22      fvdl 	num_scbs = ahc_probe_scbs(ahc);
    974       1.22      fvdl 	if ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
    975       1.22      fvdl 	 || (ahc_inb(ahc, ERROR) & MPARERR) == 0)
    976       1.22      fvdl 		pcheck = TRUE;
    977       1.22      fvdl 
    978       1.22      fvdl 	/* Clear any resulting parity error */
    979       1.22      fvdl 	ahc_outb(ahc, CLRINT, CLRPARERR);
    980       1.22      fvdl 	ahc_outb(ahc, CLRINT, CLRBRKADRINT);
    981       1.22      fvdl 
    982       1.22      fvdl 	/* Now see if we can do fast timing */
    983       1.22      fvdl 	ahc_ext_scbram_config(ahc, enable, pcheck, /*fast*/TRUE);
    984       1.22      fvdl 	test_num_scbs = ahc_probe_scbs(ahc);
    985       1.22      fvdl 	if (test_num_scbs == num_scbs
    986       1.22      fvdl 	 && ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
    987       1.22      fvdl 	  || (ahc_inb(ahc, ERROR) & MPARERR) == 0))
    988       1.22      fvdl 		fast = TRUE;
    989       1.22      fvdl 
    990       1.22      fvdl done:
    991       1.22      fvdl 	/*
    992       1.22      fvdl 	 * Disable parity error reporting until we
    993       1.22      fvdl 	 * can load instruction ram.
    994       1.22      fvdl 	 */
    995       1.22      fvdl 	ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
    996       1.22      fvdl 	/* Clear any latched parity error */
    997       1.22      fvdl 	ahc_outb(ahc, CLRINT, CLRPARERR);
    998       1.22      fvdl 	ahc_outb(ahc, CLRINT, CLRBRKADRINT);
    999       1.22      fvdl 	if (bootverbose && enable) {
   1000       1.22      fvdl 		printf("%s: External SRAM, %s access%s\n",
   1001       1.22      fvdl 		       ahc_name(ahc), fast ? "fast" : "slow",
   1002       1.22      fvdl 		       pcheck ? ", parity checking enabled" : "");
   1003       1.22      fvdl 
   1004       1.22      fvdl 	}
   1005       1.22      fvdl 	ahc_ext_scbram_config(ahc, enable, pcheck, fast);
   1006       1.22      fvdl }
   1007       1.22      fvdl 
   1008       1.22      fvdl #define	DPE	PCI_STATUS_PARITY_DETECT
   1009       1.22      fvdl #define SSE	PCI_STATUS_SPECIAL_ERROR
   1010       1.22      fvdl #define	RMA	PCI_STATUS_MASTER_ABORT
   1011       1.22      fvdl #define	RTA	PCI_STATUS_MASTER_TARGET_ABORT
   1012       1.22      fvdl #define STA	PCI_STATUS_TARGET_TARGET_ABORT
   1013       1.22      fvdl #define DPR	PCI_STATUS_PARITY_ERROR
   1014       1.22      fvdl 
   1015       1.23      fvdl int
   1016       1.22      fvdl ahc_pci_intr(struct ahc_softc *ahc)
   1017       1.22      fvdl {
   1018       1.22      fvdl 	pcireg_t status1;
   1019       1.22      fvdl 	struct ahc_pci_busdata *bd = ahc->bus_data;
   1020       1.22      fvdl 
   1021       1.23      fvdl 	if ((ahc_inb(ahc, ERROR) & PCIERRSTAT) == 0)
   1022       1.23      fvdl 		return 0;
   1023       1.23      fvdl 
   1024       1.22      fvdl 	status1 = pci_conf_read(bd->pc, bd->tag, PCI_COMMAND_STATUS_REG);
   1025       1.22      fvdl 
   1026       1.22      fvdl 	if (status1 & DPE) {
   1027       1.22      fvdl 		printf("%s: Data Parity Error Detected during address "
   1028       1.22      fvdl 		       "or write data phase\n", ahc_name(ahc));
   1029       1.22      fvdl 	}
   1030       1.22      fvdl 	if (status1 & SSE) {
   1031       1.22      fvdl 		printf("%s: Signal System Error Detected\n", ahc_name(ahc));
   1032       1.22      fvdl 	}
   1033       1.22      fvdl 	if (status1 & RMA) {
   1034       1.22      fvdl 		printf("%s: Received a Master Abort\n", ahc_name(ahc));
   1035       1.22      fvdl 	}
   1036       1.22      fvdl 	if (status1 & RTA) {
   1037       1.22      fvdl 		printf("%s: Received a Target Abort\n", ahc_name(ahc));
   1038       1.22      fvdl 	}
   1039       1.22      fvdl 	if (status1 & STA) {
   1040       1.22      fvdl 		printf("%s: Signaled a Target Abort\n", ahc_name(ahc));
   1041       1.22      fvdl 	}
   1042       1.22      fvdl 	if (status1 & DPR) {
   1043       1.22      fvdl 		printf("%s: Data Parity Error has been reported via PERR#\n",
   1044       1.22      fvdl 		       ahc_name(ahc));
   1045       1.22      fvdl 	}
   1046       1.22      fvdl 	if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
   1047       1.22      fvdl 		printf("%s: Latched PCIERR interrupt with "
   1048       1.22      fvdl 		       "no status bits set\n", ahc_name(ahc));
   1049       1.22      fvdl 	}
   1050       1.22      fvdl 	pci_conf_write(bd->pc, bd->tag, PCI_COMMAND_STATUS_REG, status1);
   1051       1.22      fvdl 
   1052       1.22      fvdl 	if (status1 & (DPR|RMA|RTA)) {
   1053       1.22      fvdl 		ahc_outb(ahc, CLRINT, CLRPARERR);
   1054       1.22      fvdl 	}
   1055       1.23      fvdl 
   1056       1.23      fvdl 	return 1;
   1057       1.22      fvdl }
   1058       1.22      fvdl 
   1059       1.22      fvdl static int
   1060       1.22      fvdl ahc_aic7850_setup(struct pci_attach_args *pa, char *channel,
   1061       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1062       1.22      fvdl {
   1063       1.22      fvdl 	*channel = 'A';
   1064       1.22      fvdl 	*chip = AHC_AIC7850;
   1065       1.22      fvdl 	*features = AHC_AIC7850_FE;
   1066       1.22      fvdl 	return (0);
   1067       1.22      fvdl }
   1068       1.22      fvdl 
   1069       1.22      fvdl static int
   1070       1.22      fvdl ahc_aic7855_setup(struct pci_attach_args *pa, char *channel,
   1071       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1072       1.22      fvdl {
   1073       1.22      fvdl 	*channel = 'A';
   1074       1.22      fvdl 	*chip = AHC_AIC7855;
   1075       1.22      fvdl 	*features = AHC_AIC7855_FE;
   1076       1.22      fvdl 	return (0);
   1077       1.22      fvdl }
   1078       1.22      fvdl 
   1079       1.22      fvdl static int
   1080       1.22      fvdl ahc_aic7859_setup(struct pci_attach_args *pa, char *channel,
   1081       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1082       1.22      fvdl {
   1083       1.22      fvdl 	*channel = 'A';
   1084       1.22      fvdl 	*chip = AHC_AIC7859;
   1085       1.22      fvdl 	*features = AHC_AIC7859_FE;
   1086       1.22      fvdl 	return (0);
   1087       1.22      fvdl }
   1088       1.22      fvdl 
   1089       1.22      fvdl static int
   1090       1.22      fvdl ahc_aic7860_setup(struct pci_attach_args *pa, char *channel,
   1091       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1092       1.22      fvdl {
   1093       1.22      fvdl 	*channel = 'A';
   1094       1.22      fvdl 	*chip = AHC_AIC7860;
   1095       1.22      fvdl 	*features = AHC_AIC7860_FE;
   1096       1.22      fvdl 	return (0);
   1097       1.22      fvdl }
   1098       1.22      fvdl 
   1099       1.22      fvdl static int
   1100       1.22      fvdl ahc_aic7870_setup(struct pci_attach_args *pa, char *channel,
   1101       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1102       1.22      fvdl {
   1103       1.22      fvdl 	*channel = 'A';
   1104       1.22      fvdl 	*chip = AHC_AIC7870;
   1105       1.22      fvdl 	*features = AHC_AIC7870_FE;
   1106       1.22      fvdl 	return (0);
   1107       1.22      fvdl }
   1108       1.22      fvdl 
   1109       1.22      fvdl static int
   1110       1.22      fvdl ahc_aha394X_setup(struct pci_attach_args *pa, char *channel,
   1111       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1112       1.22      fvdl {
   1113       1.22      fvdl 	int error;
   1114       1.22      fvdl 
   1115       1.22      fvdl 	error = ahc_aic7870_setup(pa, channel, chip, features, flags);
   1116       1.22      fvdl 	if (error == 0)
   1117       1.22      fvdl 		error = ahc_aha394XX_setup(pa, channel, chip, features, flags);
   1118       1.22      fvdl 	return (error);
   1119       1.22      fvdl }
   1120       1.22      fvdl 
   1121       1.22      fvdl static int
   1122       1.22      fvdl ahc_aha398X_setup(struct pci_attach_args *pa, char *channel,
   1123       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1124       1.22      fvdl {
   1125       1.22      fvdl 	int error;
   1126       1.22      fvdl 
   1127       1.22      fvdl 	error = ahc_aic7870_setup(pa, channel, chip, features, flags);
   1128       1.22      fvdl 	if (error == 0)
   1129       1.22      fvdl 		error = ahc_aha398XX_setup(pa, channel, chip, features, flags);
   1130       1.22      fvdl 	return (error);
   1131       1.22      fvdl }
   1132       1.22      fvdl 
   1133       1.22      fvdl static int
   1134       1.22      fvdl ahc_aic7880_setup(struct pci_attach_args *pa, char *channel,
   1135       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1136       1.22      fvdl {
   1137       1.22      fvdl 	*channel = 'A';
   1138       1.22      fvdl 	*chip = AHC_AIC7880;
   1139       1.22      fvdl 	*features = AHC_AIC7880_FE;
   1140       1.22      fvdl 	return (0);
   1141       1.22      fvdl }
   1142       1.22      fvdl 
   1143       1.22      fvdl static int
   1144       1.22      fvdl ahc_2940Pro_setup(struct pci_attach_args *pa, char *channel,
   1145       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1146       1.22      fvdl {
   1147       1.22      fvdl 	int error;
   1148       1.22      fvdl 
   1149       1.22      fvdl 	*flags |= AHC_INT50_SPEEDFLEX;
   1150       1.22      fvdl 	error = ahc_aic7880_setup(pa, channel, chip, features, flags);
   1151       1.22      fvdl 	return (0);
   1152       1.22      fvdl }
   1153       1.22      fvdl 
   1154       1.22      fvdl static int
   1155       1.22      fvdl ahc_aha394XU_setup(struct pci_attach_args *pa, char *channel,
   1156       1.22      fvdl 		   ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1157       1.22      fvdl {
   1158       1.22      fvdl 	int error;
   1159       1.22      fvdl 
   1160       1.22      fvdl 	error = ahc_aic7880_setup(pa, channel, chip, features, flags);
   1161       1.22      fvdl 	if (error == 0)
   1162       1.22      fvdl 		error = ahc_aha394XX_setup(pa, channel, chip, features, flags);
   1163       1.22      fvdl 	return (error);
   1164       1.22      fvdl }
   1165       1.22      fvdl 
   1166       1.22      fvdl static int
   1167       1.22      fvdl ahc_aha398XU_setup(struct pci_attach_args *pa, char *channel,
   1168       1.22      fvdl 		   ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1169       1.22      fvdl {
   1170       1.22      fvdl 	int error;
   1171       1.22      fvdl 
   1172       1.22      fvdl 	error = ahc_aic7880_setup(pa, channel, chip, features, flags);
   1173       1.22      fvdl 	if (error == 0)
   1174       1.22      fvdl 		error = ahc_aha398XX_setup(pa, channel, chip, features, flags);
   1175       1.22      fvdl 	return (error);
   1176       1.22      fvdl }
   1177       1.22      fvdl 
   1178       1.22      fvdl static int
   1179       1.22      fvdl ahc_aic7890_setup(struct pci_attach_args *pa, char *channel,
   1180       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1181       1.22      fvdl {
   1182       1.22      fvdl 	*channel = 'A';
   1183       1.22      fvdl 	*chip = AHC_AIC7890;
   1184       1.22      fvdl 	*features = AHC_AIC7890_FE;
   1185       1.22      fvdl 	*flags |= AHC_NEWEEPROM_FMT;
   1186       1.22      fvdl 	return (0);
   1187       1.22      fvdl }
   1188       1.22      fvdl 
   1189       1.22      fvdl static int
   1190       1.22      fvdl ahc_aic7892_setup(struct pci_attach_args *pa, char *channel,
   1191       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1192       1.22      fvdl {
   1193       1.22      fvdl 	*channel = 'A';
   1194       1.22      fvdl 	*chip = AHC_AIC7892;
   1195       1.22      fvdl 	*features = AHC_AIC7892_FE;
   1196       1.22      fvdl 	*flags |= AHC_NEWEEPROM_FMT;
   1197       1.22      fvdl 	return (0);
   1198       1.22      fvdl }
   1199       1.22      fvdl 
   1200       1.22      fvdl static int
   1201       1.22      fvdl ahc_aic7895_setup(struct pci_attach_args *pa, char *channel,
   1202       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1203       1.22      fvdl {
   1204       1.22      fvdl 	pcireg_t devconfig;
   1205       1.22      fvdl 
   1206       1.22      fvdl 	*channel = pa->pa_function == 1 ? 'B' : 'A';
   1207       1.22      fvdl 	*chip = AHC_AIC7895;
   1208       1.22      fvdl 	/* The 'C' revision of the aic7895 has a few additional features */
   1209       1.22      fvdl 	if (PCI_REVISION(pa->pa_class) >= 4)
   1210       1.22      fvdl 		*features = AHC_AIC7895C_FE;
   1211       1.22      fvdl 	else
   1212       1.22      fvdl 		*features = AHC_AIC7895_FE;
   1213       1.22      fvdl 	*flags |= AHC_NEWEEPROM_FMT;
   1214       1.22      fvdl 	devconfig = pci_conf_read(pa->pa_pc, pa->pa_tag, DEVCONFIG);
   1215       1.22      fvdl 	devconfig &= ~SCBSIZE32;
   1216       1.22      fvdl 	pci_conf_write(pa->pa_pc, pa->pa_tag, DEVCONFIG, devconfig);
   1217       1.22      fvdl 	return (0);
   1218       1.22      fvdl }
   1219       1.22      fvdl 
   1220       1.22      fvdl static int
   1221       1.22      fvdl ahc_aic7896_setup(struct pci_attach_args *pa, char *channel,
   1222       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1223       1.22      fvdl {
   1224       1.22      fvdl 	*channel = pa->pa_function == 1 ? 'B' : 'A';
   1225       1.22      fvdl 	*chip = AHC_AIC7896;
   1226       1.22      fvdl 	*features = AHC_AIC7896_FE;
   1227       1.22      fvdl 	*flags |= AHC_NEWEEPROM_FMT;
   1228       1.22      fvdl 	return (0);
   1229       1.22      fvdl }
   1230       1.22      fvdl 
   1231       1.22      fvdl static int
   1232       1.22      fvdl ahc_aic7899_setup(struct pci_attach_args *pa, char *channel,
   1233       1.22      fvdl 		  ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1234       1.22      fvdl {
   1235       1.22      fvdl 	*channel = pa->pa_function == 1 ? 'B' : 'A';
   1236       1.22      fvdl 	*chip = AHC_AIC7899;
   1237       1.22      fvdl 	*features = AHC_AIC7899_FE;
   1238       1.22      fvdl 	*flags |= AHC_NEWEEPROM_FMT;
   1239       1.22      fvdl 	return (0);
   1240       1.22      fvdl }
   1241       1.22      fvdl 
   1242       1.22      fvdl static int
   1243       1.22      fvdl ahc_raid_setup(struct pci_attach_args *pa, char *channel,
   1244       1.22      fvdl 	       ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1245       1.22      fvdl {
   1246       1.26     soren 	printf(": RAID functionality unsupported\n");
   1247       1.22      fvdl 	return (ENXIO);
   1248       1.22      fvdl }
   1249       1.22      fvdl 
   1250       1.22      fvdl static int
   1251       1.22      fvdl ahc_aha394XX_setup(struct pci_attach_args *pa, char *channel,
   1252       1.22      fvdl 		   ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1253       1.22      fvdl {
   1254       1.22      fvdl 	switch (pa->pa_device) {
   1255       1.22      fvdl 	case AHC_394X_SLOT_CHANNEL_A:
   1256       1.22      fvdl 		*channel = 'A';
   1257       1.22      fvdl 		break;
   1258       1.22      fvdl 	case AHC_394X_SLOT_CHANNEL_B:
   1259       1.22      fvdl 		*channel = 'B';
   1260       1.22      fvdl 		break;
   1261       1.22      fvdl 	default:
   1262       1.22      fvdl 		printf("adapter at unexpected slot %d\n"
   1263       1.22      fvdl 		       "unable to map to a channel\n",
   1264       1.22      fvdl 		       pa->pa_device);
   1265       1.22      fvdl 		*channel = 'A';
   1266       1.22      fvdl 	}
   1267       1.22      fvdl 	return (0);
   1268       1.22      fvdl }
   1269       1.22      fvdl 
   1270       1.22      fvdl static int
   1271       1.22      fvdl ahc_aha398XX_setup(struct pci_attach_args *pa, char *channel,
   1272       1.22      fvdl 		   ahc_chip *chip, ahc_feature *features, ahc_flag *flags)
   1273       1.22      fvdl {
   1274       1.22      fvdl 	switch (pa->pa_device) {
   1275       1.22      fvdl 	case AHC_398X_SLOT_CHANNEL_A:
   1276       1.22      fvdl 		*channel = 'A';
   1277       1.22      fvdl 		break;
   1278       1.22      fvdl 	case AHC_398X_SLOT_CHANNEL_B:
   1279       1.22      fvdl 		*channel = 'B';
   1280       1.22      fvdl 		break;
   1281       1.22      fvdl 	case AHC_398X_SLOT_CHANNEL_C:
   1282       1.22      fvdl 		*channel = 'C';
   1283       1.22      fvdl 		break;
   1284       1.22      fvdl 	default:
   1285       1.22      fvdl 		printf("adapter at unexpected slot %d\n"
   1286       1.22      fvdl 		       "unable to map to a channel\n",
   1287       1.22      fvdl 		       pa->pa_device);
   1288       1.22      fvdl 		*channel = 'A';
   1289       1.22      fvdl 	}
   1290       1.22      fvdl 	*flags |= AHC_LARGE_SEEPROM;
   1291       1.22      fvdl 	return (0);
   1292        1.1   mycroft }
   1293