Home | History | Annotate | Line # | Download | only in pci
aac_pci.c revision 1.19.8.1
      1  1.19.8.1        ad /*	$NetBSD: aac_pci.c,v 1.19.8.1 2007/03/13 16:50:24 ad Exp $	*/
      2       1.1        ad 
      3       1.1        ad /*-
      4       1.1        ad  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5       1.1        ad  * All rights reserved.
      6       1.1        ad  *
      7       1.1        ad  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1        ad  * by Andrew Doran.
      9       1.1        ad  *
     10       1.1        ad  * Redistribution and use in source and binary forms, with or without
     11       1.1        ad  * modification, are permitted provided that the following conditions
     12       1.1        ad  * are met:
     13       1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14       1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15       1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17       1.1        ad  *    documentation and/or other materials provided with the distribution.
     18       1.1        ad  * 3. All advertising materials mentioning features or use of this software
     19       1.1        ad  *    must display the following acknowledgement:
     20       1.1        ad  *        This product includes software developed by the NetBSD
     21       1.1        ad  *        Foundation, Inc. and its contributors.
     22       1.1        ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1        ad  *    contributors may be used to endorse or promote products derived
     24       1.1        ad  *    from this software without specific prior written permission.
     25       1.1        ad  *
     26       1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1        ad  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1        ad  */
     38       1.1        ad 
     39       1.1        ad /*-
     40       1.1        ad  * Copyright (c) 2000 Michael Smith
     41       1.1        ad  * Copyright (c) 2000 BSDi
     42       1.1        ad  * Copyright (c) 2000 Niklas Hallqvist
     43       1.1        ad  * All rights reserved.
     44       1.1        ad  *
     45       1.1        ad  * Redistribution and use in source and binary forms, with or without
     46       1.1        ad  * modification, are permitted provided that the following conditions
     47       1.1        ad  * are met:
     48       1.1        ad  * 1. Redistributions of source code must retain the above copyright
     49       1.1        ad  *    notice, this list of conditions and the following disclaimer.
     50       1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     51       1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     52       1.1        ad  *    documentation and/or other materials provided with the distribution.
     53       1.1        ad  *
     54       1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     55       1.1        ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56       1.1        ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57       1.1        ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     58       1.1        ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59       1.1        ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60       1.1        ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61       1.1        ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62       1.1        ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63       1.1        ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64       1.1        ad  * SUCH DAMAGE.
     65       1.1        ad  *
     66       1.1        ad  * from FreeBSD: aac_pci.c,v 1.1 2000/09/13 03:20:34 msmith Exp
     67       1.1        ad  * via OpenBSD: aac_pci.c,v 1.7 2002/03/14 01:26:58 millert Exp
     68       1.1        ad  */
     69       1.1        ad 
     70       1.1        ad /*
     71       1.1        ad  * PCI front-end for the `aac' driver.
     72       1.1        ad  */
     73       1.1        ad 
     74       1.1        ad #include <sys/cdefs.h>
     75  1.19.8.1        ad __KERNEL_RCSID(0, "$NetBSD: aac_pci.c,v 1.19.8.1 2007/03/13 16:50:24 ad Exp $");
     76       1.1        ad 
     77       1.1        ad #include <sys/param.h>
     78       1.1        ad #include <sys/systm.h>
     79       1.1        ad #include <sys/device.h>
     80       1.1        ad #include <sys/kernel.h>
     81       1.1        ad #include <sys/malloc.h>
     82       1.1        ad #include <sys/queue.h>
     83       1.1        ad 
     84       1.1        ad #include <machine/bus.h>
     85       1.1        ad #include <machine/endian.h>
     86       1.1        ad #include <machine/intr.h>
     87       1.1        ad 
     88       1.1        ad #include <dev/pci/pcidevs.h>
     89       1.1        ad #include <dev/pci/pcireg.h>
     90       1.1        ad #include <dev/pci/pcivar.h>
     91       1.1        ad 
     92       1.1        ad #include <dev/ic/aacreg.h>
     93       1.1        ad #include <dev/ic/aacvar.h>
     94       1.1        ad 
     95      1.11     perry /* i960Rx interface */
     96      1.15   thorpej static int	aac_rx_get_fwstatus(struct aac_softc *);
     97      1.15   thorpej static void	aac_rx_qnotify(struct aac_softc *, int);
     98      1.15   thorpej static int	aac_rx_get_istatus(struct aac_softc *);
     99      1.15   thorpej static void	aac_rx_clear_istatus(struct aac_softc *, int);
    100      1.15   thorpej static void	aac_rx_set_mailbox(struct aac_softc *, u_int32_t, u_int32_t,
    101       1.1        ad 			   u_int32_t, u_int32_t, u_int32_t);
    102      1.15   thorpej static uint32_t aac_rx_get_mailbox(struct aac_softc *, int);
    103      1.15   thorpej static void	aac_rx_set_interrupts(struct aac_softc *, int);
    104       1.1        ad 
    105       1.1        ad /* StrongARM interface */
    106      1.15   thorpej static int	aac_sa_get_fwstatus(struct aac_softc *);
    107      1.15   thorpej static void	aac_sa_qnotify(struct aac_softc *, int);
    108      1.15   thorpej static int	aac_sa_get_istatus(struct aac_softc *);
    109      1.15   thorpej static void	aac_sa_clear_istatus(struct aac_softc *, int);
    110      1.15   thorpej static void	aac_sa_set_mailbox(struct aac_softc *, u_int32_t, u_int32_t,
    111       1.1        ad 			   u_int32_t, u_int32_t, u_int32_t);
    112      1.15   thorpej static uint32_t aac_sa_get_mailbox(struct aac_softc *, int);
    113      1.15   thorpej static void	aac_sa_set_interrupts(struct aac_softc *, int);
    114       1.1        ad 
    115      1.15   thorpej static const struct aac_interface aac_rx_interface = {
    116       1.1        ad 	aac_rx_get_fwstatus,
    117       1.1        ad 	aac_rx_qnotify,
    118       1.1        ad 	aac_rx_get_istatus,
    119       1.1        ad 	aac_rx_clear_istatus,
    120       1.1        ad 	aac_rx_set_mailbox,
    121      1.12    briggs 	aac_rx_get_mailbox,
    122       1.1        ad 	aac_rx_set_interrupts
    123       1.1        ad };
    124       1.1        ad 
    125      1.15   thorpej static const struct aac_interface aac_sa_interface = {
    126       1.1        ad 	aac_sa_get_fwstatus,
    127       1.1        ad 	aac_sa_qnotify,
    128       1.1        ad 	aac_sa_get_istatus,
    129       1.1        ad 	aac_sa_clear_istatus,
    130       1.1        ad 	aac_sa_set_mailbox,
    131      1.12    briggs 	aac_sa_get_mailbox,
    132       1.1        ad 	aac_sa_set_interrupts
    133       1.1        ad };
    134       1.1        ad 
    135      1.17  christos static struct aac_ident {
    136       1.1        ad 	u_short	vendor;
    137       1.1        ad 	u_short	device;
    138       1.1        ad 	u_short	subvendor;
    139       1.1        ad 	u_short	subdevice;
    140       1.1        ad 	u_short	hwif;
    141       1.1        ad 	u_short	quirks;
    142       1.1        ad 	const char	*prodstr;
    143      1.17  christos } const aac_ident[] = {
    144       1.1        ad 	{
    145       1.1        ad 		PCI_VENDOR_DELL,
    146       1.1        ad 		PCI_PRODUCT_DELL_PERC_2SI,
    147       1.1        ad 		PCI_VENDOR_DELL,
    148       1.1        ad 		PCI_PRODUCT_DELL_PERC_2SI,
    149       1.1        ad 		AAC_HWIF_I960RX,
    150       1.1        ad 		0,
    151       1.1        ad 		"Dell PERC 2/Si"
    152       1.1        ad 	},
    153       1.1        ad 	{
    154       1.1        ad 		PCI_VENDOR_DELL,
    155       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI,
    156       1.1        ad 		PCI_VENDOR_DELL,
    157       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI,
    158       1.1        ad 		AAC_HWIF_I960RX,
    159       1.1        ad 		0,
    160       1.1        ad 		"Dell PERC 3/Di"
    161       1.1        ad 	},
    162       1.1        ad 	{
    163       1.1        ad 		PCI_VENDOR_DELL,
    164       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI,
    165       1.1        ad 		PCI_VENDOR_DELL,
    166       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI_SUB2,
    167       1.1        ad 		AAC_HWIF_I960RX,
    168       1.1        ad 		0,
    169       1.1        ad 		"Dell PERC 3/Di"
    170       1.1        ad 	},
    171       1.1        ad 	{
    172       1.1        ad 		PCI_VENDOR_DELL,
    173       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI,
    174       1.1        ad 		PCI_VENDOR_DELL,
    175       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI_SUB3,
    176       1.1        ad 		AAC_HWIF_I960RX,
    177       1.1        ad 		0,
    178       1.1        ad 		"Dell PERC 3/Di"
    179       1.1        ad 	},
    180       1.1        ad 	{
    181       1.1        ad 		PCI_VENDOR_DELL,
    182       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI_2,
    183       1.1        ad 		PCI_VENDOR_DELL,
    184       1.1        ad 		PCI_PRODUCT_DELL_PERC_3DI_2_SUB,
    185       1.3        ad 		AAC_HWIF_I960RX,
    186       1.3        ad 		0,
    187       1.3        ad 		"Dell PERC 3/Di"
    188       1.3        ad 	},
    189       1.3        ad         {
    190       1.3        ad 		PCI_VENDOR_DELL,
    191       1.3        ad 		PCI_PRODUCT_DELL_PERC_3DI_3,
    192       1.3        ad 		PCI_VENDOR_DELL,
    193       1.3        ad 		PCI_PRODUCT_DELL_PERC_3DI_3_SUB,
    194       1.3        ad 		AAC_HWIF_I960RX,
    195       1.3        ad 		0,
    196       1.3        ad 		"Dell PERC 3/Di"
    197       1.3        ad 	},
    198       1.3        ad 	{
    199       1.3        ad 		PCI_VENDOR_DELL,
    200       1.3        ad 		PCI_PRODUCT_DELL_PERC_3DI_3,
    201       1.3        ad 		PCI_VENDOR_DELL,
    202       1.3        ad 		PCI_PRODUCT_DELL_PERC_3DI_3_SUB2,
    203       1.3        ad 		AAC_HWIF_I960RX,
    204       1.3        ad 		0,
    205       1.3        ad 		"Dell PERC 3/Di"
    206       1.3        ad 	},
    207       1.3        ad 	{
    208       1.3        ad 		PCI_VENDOR_DELL,
    209       1.3        ad 		PCI_PRODUCT_DELL_PERC_3DI_3,
    210       1.3        ad 		PCI_VENDOR_DELL,
    211       1.3        ad 		PCI_PRODUCT_DELL_PERC_3DI_3_SUB3,
    212       1.1        ad 		AAC_HWIF_I960RX,
    213       1.1        ad 		0,
    214       1.1        ad 		"Dell PERC 3/Di"
    215       1.1        ad 	},
    216       1.1        ad 	{
    217       1.1        ad 		PCI_VENDOR_DELL,
    218       1.1        ad 		PCI_PRODUCT_DELL_PERC_3SI,
    219       1.1        ad 		PCI_VENDOR_DELL,
    220       1.1        ad 		PCI_PRODUCT_DELL_PERC_3SI,
    221       1.1        ad 		AAC_HWIF_I960RX,
    222       1.1        ad 		0,
    223       1.1        ad 		"Dell PERC 3/Si"
    224       1.1        ad 	},
    225       1.1        ad 	{
    226       1.1        ad 		PCI_VENDOR_DELL,
    227       1.1        ad 		PCI_PRODUCT_DELL_PERC_3SI_2,
    228       1.1        ad 		PCI_VENDOR_DELL,
    229       1.1        ad 		PCI_PRODUCT_DELL_PERC_3SI_2_SUB,
    230       1.1        ad 		AAC_HWIF_I960RX,
    231       1.1        ad 		0,
    232       1.1        ad 		"Dell PERC 3/Si"
    233       1.1        ad 	},
    234       1.1        ad 	{
    235       1.1        ad 		PCI_VENDOR_ADP2,
    236      1.14    martti 		PCI_PRODUCT_ADP2_ASR2200S,
    237      1.14    martti 		PCI_VENDOR_DELL,
    238      1.14    martti 		PCI_PRODUCT_DELL_CERC_1_5,
    239      1.14    martti 		AAC_HWIF_I960RX,
    240      1.14    martti 		AAC_QUIRK_NO4GB,
    241      1.14    martti 		"Dell CERC SATA RAID 1.5/6ch"
    242      1.14    martti 	},
    243      1.14    martti 	{
    244      1.14    martti 		PCI_VENDOR_ADP2,
    245       1.1        ad 		PCI_PRODUCT_ADP2_AAC2622,
    246       1.1        ad 		PCI_VENDOR_ADP2,
    247       1.1        ad 		PCI_PRODUCT_ADP2_AAC2622,
    248       1.1        ad 		AAC_HWIF_I960RX,
    249       1.1        ad 		0,
    250       1.1        ad 		"Adaptec ADP-2622"
    251       1.1        ad 	},
    252       1.1        ad 	{
    253       1.1        ad 		PCI_VENDOR_ADP2,
    254       1.1        ad 		PCI_PRODUCT_ADP2_ASR2200S,
    255       1.1        ad 		PCI_VENDOR_ADP2,
    256       1.8  gendalia 		PCI_PRODUCT_ADP2_ASR2200S_SUB2M,
    257       1.8  gendalia 		AAC_HWIF_I960RX,
    258       1.8  gendalia 		0,
    259       1.8  gendalia 		"Adaptec ASR-2200S"
    260       1.8  gendalia 	},
    261       1.8  gendalia 	{
    262       1.8  gendalia 		PCI_VENDOR_ADP2,
    263       1.8  gendalia 		PCI_PRODUCT_ADP2_ASR2200S,
    264       1.8  gendalia 		PCI_VENDOR_DELL,
    265       1.8  gendalia 		PCI_PRODUCT_ADP2_ASR2200S_SUB2M,
    266       1.8  gendalia 		AAC_HWIF_I960RX,
    267       1.8  gendalia 		0,
    268       1.8  gendalia 		"Dell PERC 320/DC"
    269       1.8  gendalia 	},
    270       1.8  gendalia 	{
    271       1.8  gendalia 		PCI_VENDOR_ADP2,
    272       1.8  gendalia 		PCI_PRODUCT_ADP2_ASR2200S,
    273       1.8  gendalia 		PCI_VENDOR_ADP2,
    274       1.1        ad 		PCI_PRODUCT_ADP2_ASR2200S,
    275       1.1        ad 		AAC_HWIF_I960RX,
    276       1.1        ad 		0,
    277       1.1        ad 		"Adaptec ASR-2200S"
    278       1.1        ad 	},
    279       1.1        ad 	{
    280       1.1        ad 		PCI_VENDOR_ADP2,
    281       1.1        ad 		PCI_PRODUCT_ADP2_ASR2200S,
    282       1.1        ad 		PCI_VENDOR_ADP2,
    283      1.10  gendalia 		PCI_PRODUCT_ADP2_AAR2810SA,
    284      1.10  gendalia 		AAC_HWIF_I960RX,
    285      1.10  gendalia 		0,
    286      1.10  gendalia 		"Adaptec AAR-2810SA"
    287      1.10  gendalia 	},
    288      1.10  gendalia 	{
    289      1.10  gendalia 		PCI_VENDOR_ADP2,
    290      1.10  gendalia 		PCI_PRODUCT_ADP2_ASR2200S,
    291      1.10  gendalia 		PCI_VENDOR_ADP2,
    292       1.1        ad 		PCI_PRODUCT_ADP2_ASR2120S,
    293       1.1        ad 		AAC_HWIF_I960RX,
    294       1.1        ad 		0,
    295       1.1        ad 		"Adaptec ASR-2120S"
    296       1.1        ad 	},
    297       1.1        ad 	{
    298       1.9  jdolecek 		PCI_VENDOR_ADP2,
    299       1.9  jdolecek 		PCI_PRODUCT_ADP2_ASR2200S,
    300       1.9  jdolecek 		PCI_VENDOR_ADP2,
    301      1.13      tron 		PCI_PRODUCT_ADP2_ASR2410SA,
    302       1.9  jdolecek 		AAC_HWIF_I960RX,
    303       1.9  jdolecek 		0,
    304       1.9  jdolecek 		"Adaptec ASR-2410SA"
    305       1.9  jdolecek 	},
    306       1.9  jdolecek 	{
    307  1.19.8.1        ad 		PCI_VENDOR_ADP2,
    308  1.19.8.1        ad 		PCI_PRODUCT_ADP2_ASR2200S,
    309  1.19.8.1        ad 		PCI_VENDOR_HP,
    310  1.19.8.1        ad 		PCI_PRODUCT_ADP2_HP_M110_G2,
    311  1.19.8.1        ad 		AAC_HWIF_I960RX,
    312  1.19.8.1        ad 		0,
    313  1.19.8.1        ad 		"HP ML110 G2 (Adaptec ASR-2610SA)"
    314  1.19.8.1        ad 	},
    315  1.19.8.1        ad 	{
    316       1.1        ad 		PCI_VENDOR_DEC,
    317       1.2  augustss 		PCI_PRODUCT_DEC_21554,
    318       1.1        ad 		PCI_VENDOR_ADP2,
    319       1.1        ad 		PCI_PRODUCT_ADP2_AAC364,
    320       1.1        ad 		AAC_HWIF_STRONGARM,
    321       1.1        ad 		0,
    322       1.1        ad 		"Adaptec AAC-364"
    323       1.1        ad 	},
    324       1.1        ad 	{
    325       1.1        ad 		PCI_VENDOR_DEC,
    326       1.2  augustss 		PCI_PRODUCT_DEC_21554,
    327       1.1        ad 		PCI_VENDOR_ADP2,
    328       1.1        ad 		PCI_PRODUCT_ADP2_ASR5400S,
    329       1.1        ad 		AAC_HWIF_STRONGARM,
    330       1.1        ad 		0,
    331       1.1        ad 		"Adaptec ASR-5400S"
    332       1.1        ad 	},
    333       1.1        ad 	{
    334       1.1        ad 		PCI_VENDOR_DEC,
    335       1.2  augustss 		PCI_PRODUCT_DEC_21554,
    336       1.1        ad 		PCI_VENDOR_ADP2,
    337       1.1        ad 		PCI_PRODUCT_ADP2_PERC_2QC,
    338       1.1        ad 		AAC_HWIF_STRONGARM,
    339       1.1        ad 		AAC_QUIRK_PERC2QC,
    340       1.1        ad 		"Dell PERC 2/QC"
    341       1.1        ad 	},
    342       1.1        ad 	{
    343       1.1        ad 		PCI_VENDOR_DEC,
    344       1.2  augustss 		PCI_PRODUCT_DEC_21554,
    345       1.1        ad 		PCI_VENDOR_ADP2,
    346       1.1        ad 		PCI_PRODUCT_ADP2_PERC_3QC,
    347       1.1        ad 		AAC_HWIF_STRONGARM,
    348       1.1        ad 		0,
    349       1.1        ad 		"Dell PERC 3/QC"
    350       1.1        ad 	},
    351       1.1        ad 	{
    352       1.1        ad 		PCI_VENDOR_DEC,
    353       1.2  augustss 		PCI_PRODUCT_DEC_21554,
    354       1.1        ad 		PCI_VENDOR_HP,
    355       1.1        ad 		PCI_PRODUCT_HP_NETRAID_4M,
    356       1.1        ad 		AAC_HWIF_STRONGARM,
    357       1.1        ad 		0,
    358       1.1        ad 		"HP NetRAID-4M"
    359       1.1        ad 	},
    360       1.1        ad };
    361       1.1        ad 
    362      1.15   thorpej static const struct aac_ident *
    363       1.1        ad aac_find_ident(struct pci_attach_args *pa)
    364       1.1        ad {
    365       1.1        ad 	const struct aac_ident *m, *mm;
    366       1.1        ad 	u_int32_t subsysid;
    367       1.1        ad 
    368       1.1        ad 	m = aac_ident;
    369       1.1        ad 	mm = aac_ident + (sizeof(aac_ident) / sizeof(aac_ident[0]));
    370       1.1        ad 
    371       1.1        ad 	while (m < mm) {
    372       1.1        ad 		if (m->vendor == PCI_VENDOR(pa->pa_id) &&
    373       1.1        ad 		    m->device == PCI_PRODUCT(pa->pa_id)) {
    374       1.1        ad 			subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag,
    375       1.1        ad 			    PCI_SUBSYS_ID_REG);
    376       1.1        ad 			if (m->subvendor == PCI_VENDOR(subsysid) &&
    377       1.1        ad 			    m->subdevice == PCI_PRODUCT(subsysid))
    378       1.1        ad 				return (m);
    379       1.1        ad 		}
    380       1.1        ad 		m++;
    381       1.1        ad 	}
    382       1.1        ad 
    383       1.1        ad 	return (NULL);
    384       1.1        ad }
    385       1.1        ad 
    386      1.15   thorpej static int
    387      1.19  christos aac_pci_match(struct device *parent, struct cfdata *match,
    388      1.18  christos     void *aux)
    389       1.1        ad {
    390       1.1        ad 	struct pci_attach_args *pa;
    391       1.1        ad 
    392       1.1        ad 	pa = aux;
    393       1.1        ad 
    394       1.1        ad 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O)
    395       1.1        ad 		return (0);
    396       1.1        ad 
    397       1.1        ad 	return (aac_find_ident(pa) != NULL);
    398       1.1        ad }
    399       1.1        ad 
    400      1.15   thorpej static void
    401      1.19  christos aac_pci_attach(struct device *parent, struct device *self, void *aux)
    402       1.1        ad {
    403       1.1        ad 	struct pci_attach_args *pa;
    404       1.1        ad 	pci_chipset_tag_t pc;
    405       1.1        ad 	struct aac_softc *sc;
    406       1.1        ad 	u_int16_t command;
    407       1.1        ad 	bus_addr_t membase;
    408       1.1        ad 	bus_size_t memsize;
    409       1.1        ad 	pci_intr_handle_t ih;
    410       1.1        ad 	const char *intrstr;
    411       1.1        ad 	int state;
    412       1.1        ad 	const struct aac_ident *m;
    413       1.1        ad 
    414       1.1        ad 	pa = aux;
    415       1.1        ad 	pc = pa->pa_pc;
    416       1.1        ad 	sc = (struct aac_softc *)self;
    417       1.1        ad 	state = 0;
    418       1.1        ad 
    419       1.7   thorpej 	aprint_naive(": RAID controller\n");
    420       1.7   thorpej 	aprint_normal(": ");
    421       1.1        ad 
    422       1.1        ad 	/*
    423       1.1        ad 	 * Verify that the adapter is correctly set up in PCI space.
    424       1.1        ad 	 */
    425       1.1        ad 	command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    426       1.1        ad 	command |= PCI_COMMAND_MASTER_ENABLE;
    427       1.1        ad 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
    428       1.1        ad 	command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    429       1.1        ad 	AAC_DPRINTF(AAC_D_MISC, ("pci command status reg 0x08x "));
    430       1.1        ad 
    431       1.1        ad 	if ((command & PCI_COMMAND_MASTER_ENABLE) == 0) {
    432       1.7   thorpej 		aprint_error("can't enable bus-master feature\n");
    433       1.1        ad 		goto bail_out;
    434       1.1        ad 	}
    435       1.1        ad 
    436       1.1        ad 	if ((command & PCI_COMMAND_MEM_ENABLE) == 0) {
    437       1.7   thorpej 		aprint_error("memory window not available\n");
    438       1.1        ad 		goto bail_out;
    439       1.1        ad 	}
    440       1.1        ad 
    441       1.1        ad 	/*
    442       1.1        ad 	 * Map control/status registers.
    443       1.1        ad 	 */
    444       1.1        ad 	if (pci_mapreg_map(pa, PCI_MAPREG_START,
    445       1.1        ad 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_memt,
    446       1.1        ad 	    &sc->sc_memh, &membase, &memsize)) {
    447       1.7   thorpej 		aprint_error("can't find mem space\n");
    448       1.1        ad 		goto bail_out;
    449       1.1        ad 	}
    450       1.1        ad 	state++;
    451       1.1        ad 
    452       1.1        ad 	if (pci_intr_map(pa, &ih)) {
    453       1.7   thorpej 		aprint_error("couldn't map interrupt\n");
    454       1.1        ad 		goto bail_out;
    455       1.1        ad 	}
    456       1.1        ad 	intrstr = pci_intr_string(pc, ih);
    457       1.1        ad 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, aac_intr, sc);
    458       1.1        ad 	if (sc->sc_ih == NULL) {
    459       1.7   thorpej 		aprint_error("couldn't establish interrupt");
    460       1.1        ad 		if (intrstr != NULL)
    461       1.7   thorpej 			aprint_normal(" at %s", intrstr);
    462       1.7   thorpej 		aprint_normal("\n");
    463       1.1        ad 		goto bail_out;
    464       1.1        ad 	}
    465       1.1        ad 	state++;
    466       1.1        ad 
    467       1.1        ad 	sc->sc_dmat = pa->pa_dmat;
    468       1.1        ad 
    469       1.1        ad 	m = aac_find_ident(pa);
    470       1.7   thorpej 	aprint_normal("%s\n", m->prodstr);
    471       1.1        ad 	if (intrstr != NULL)
    472       1.7   thorpej 		aprint_normal("%s: interrupting at %s\n",
    473       1.7   thorpej 		    sc->sc_dv.dv_xname, intrstr);
    474       1.1        ad 
    475       1.1        ad 	sc->sc_hwif = m->hwif;
    476       1.1        ad 	sc->sc_quirks = m->quirks;
    477       1.1        ad 	switch (sc->sc_hwif) {
    478       1.1        ad 		case AAC_HWIF_I960RX:
    479       1.1        ad 			AAC_DPRINTF(AAC_D_MISC,
    480       1.1        ad 			    ("set hardware up for i960Rx"));
    481       1.1        ad 			sc->sc_if = aac_rx_interface;
    482       1.1        ad 			break;
    483       1.1        ad 
    484       1.1        ad 		case AAC_HWIF_STRONGARM:
    485       1.1        ad 			AAC_DPRINTF(AAC_D_MISC,
    486       1.1        ad 			    ("set hardware up for StrongARM"));
    487       1.1        ad 			sc->sc_if = aac_sa_interface;
    488       1.1        ad 			break;
    489       1.1        ad 	}
    490       1.1        ad 
    491       1.1        ad 	if (!aac_attach(sc))
    492       1.1        ad 		return;
    493       1.1        ad 
    494       1.1        ad  bail_out:
    495       1.1        ad 	if (state > 1)
    496       1.1        ad 		pci_intr_disestablish(pc, sc->sc_ih);
    497       1.1        ad 	if (state > 0)
    498       1.1        ad 		bus_space_unmap(sc->sc_memt, sc->sc_memh, memsize);
    499       1.1        ad }
    500       1.1        ad 
    501      1.15   thorpej CFATTACH_DECL(aac_pci, sizeof(struct aac_softc),
    502      1.15   thorpej     aac_pci_match, aac_pci_attach, NULL, NULL);
    503      1.15   thorpej 
    504       1.1        ad /*
    505       1.1        ad  * Read the current firmware status word.
    506       1.1        ad  */
    507      1.15   thorpej static int
    508       1.1        ad aac_sa_get_fwstatus(struct aac_softc *sc)
    509       1.1        ad {
    510       1.1        ad 
    511       1.1        ad 	return (AAC_GETREG4(sc, AAC_SA_FWSTATUS));
    512       1.1        ad }
    513       1.1        ad 
    514      1.15   thorpej static int
    515       1.1        ad aac_rx_get_fwstatus(struct aac_softc *sc)
    516       1.1        ad {
    517       1.1        ad 
    518       1.1        ad 	return (AAC_GETREG4(sc, AAC_RX_FWSTATUS));
    519       1.1        ad }
    520       1.1        ad 
    521       1.1        ad /*
    522       1.1        ad  * Notify the controller of a change in a given queue
    523       1.1        ad  */
    524       1.1        ad 
    525      1.15   thorpej static void
    526       1.1        ad aac_sa_qnotify(struct aac_softc *sc, int qbit)
    527       1.1        ad {
    528       1.1        ad 
    529       1.1        ad 	AAC_SETREG2(sc, AAC_SA_DOORBELL1_SET, qbit);
    530       1.1        ad }
    531       1.1        ad 
    532      1.15   thorpej static void
    533       1.1        ad aac_rx_qnotify(struct aac_softc *sc, int qbit)
    534       1.1        ad {
    535       1.1        ad 
    536       1.1        ad 	AAC_SETREG4(sc, AAC_RX_IDBR, qbit);
    537       1.1        ad }
    538       1.1        ad 
    539       1.1        ad /*
    540       1.1        ad  * Get the interrupt reason bits
    541       1.1        ad  */
    542      1.15   thorpej static int
    543       1.1        ad aac_sa_get_istatus(struct aac_softc *sc)
    544       1.1        ad {
    545       1.1        ad 
    546       1.1        ad 	return (AAC_GETREG2(sc, AAC_SA_DOORBELL0));
    547       1.1        ad }
    548       1.1        ad 
    549      1.15   thorpej static int
    550       1.1        ad aac_rx_get_istatus(struct aac_softc *sc)
    551       1.1        ad {
    552       1.1        ad 
    553       1.1        ad 	return (AAC_GETREG4(sc, AAC_RX_ODBR));
    554       1.1        ad }
    555       1.1        ad 
    556       1.1        ad /*
    557       1.1        ad  * Clear some interrupt reason bits
    558       1.1        ad  */
    559      1.15   thorpej static void
    560       1.1        ad aac_sa_clear_istatus(struct aac_softc *sc, int mask)
    561       1.1        ad {
    562       1.1        ad 
    563       1.1        ad 	AAC_SETREG2(sc, AAC_SA_DOORBELL0_CLEAR, mask);
    564       1.1        ad }
    565       1.1        ad 
    566      1.15   thorpej static void
    567       1.1        ad aac_rx_clear_istatus(struct aac_softc *sc, int mask)
    568       1.1        ad {
    569       1.1        ad 
    570       1.1        ad 	AAC_SETREG4(sc, AAC_RX_ODBR, mask);
    571       1.1        ad }
    572       1.1        ad 
    573       1.1        ad /*
    574       1.1        ad  * Populate the mailbox and set the command word
    575       1.1        ad  */
    576      1.15   thorpej static void
    577       1.1        ad aac_sa_set_mailbox(struct aac_softc *sc, u_int32_t command,
    578       1.1        ad 		   u_int32_t arg0, u_int32_t arg1, u_int32_t arg2,
    579       1.1        ad 		   u_int32_t arg3)
    580       1.1        ad {
    581       1.1        ad 
    582       1.1        ad 	AAC_SETREG4(sc, AAC_SA_MAILBOX, command);
    583       1.1        ad 	AAC_SETREG4(sc, AAC_SA_MAILBOX + 4, arg0);
    584       1.1        ad 	AAC_SETREG4(sc, AAC_SA_MAILBOX + 8, arg1);
    585       1.1        ad 	AAC_SETREG4(sc, AAC_SA_MAILBOX + 12, arg2);
    586       1.1        ad 	AAC_SETREG4(sc, AAC_SA_MAILBOX + 16, arg3);
    587       1.1        ad }
    588       1.1        ad 
    589      1.15   thorpej static void
    590       1.1        ad aac_rx_set_mailbox(struct aac_softc *sc, u_int32_t command,
    591       1.1        ad 		   u_int32_t arg0, u_int32_t arg1, u_int32_t arg2,
    592       1.1        ad 		   u_int32_t arg3)
    593       1.1        ad {
    594       1.1        ad 
    595       1.1        ad 	AAC_SETREG4(sc, AAC_RX_MAILBOX, command);
    596       1.1        ad 	AAC_SETREG4(sc, AAC_RX_MAILBOX + 4, arg0);
    597       1.1        ad 	AAC_SETREG4(sc, AAC_RX_MAILBOX + 8, arg1);
    598       1.1        ad 	AAC_SETREG4(sc, AAC_RX_MAILBOX + 12, arg2);
    599       1.1        ad 	AAC_SETREG4(sc, AAC_RX_MAILBOX + 16, arg3);
    600       1.1        ad }
    601       1.1        ad 
    602       1.1        ad /*
    603      1.12    briggs  * Fetch the specified mailbox
    604       1.1        ad  */
    605      1.15   thorpej static uint32_t
    606      1.12    briggs aac_sa_get_mailbox(struct aac_softc *sc, int mb)
    607       1.1        ad {
    608       1.1        ad 
    609      1.12    briggs 	return (AAC_GETREG4(sc, AAC_SA_MAILBOX + (mb * 4)));
    610       1.1        ad }
    611       1.1        ad 
    612      1.15   thorpej static uint32_t
    613      1.12    briggs aac_rx_get_mailbox(struct aac_softc *sc, int mb)
    614       1.1        ad {
    615       1.1        ad 
    616      1.12    briggs 	return (AAC_GETREG4(sc, AAC_RX_MAILBOX + (mb * 4)));
    617       1.1        ad }
    618       1.1        ad 
    619       1.1        ad /*
    620       1.1        ad  * Set/clear interrupt masks
    621       1.1        ad  */
    622      1.15   thorpej static void
    623       1.1        ad aac_sa_set_interrupts(struct aac_softc *sc, int enable)
    624       1.1        ad {
    625       1.1        ad 
    626       1.1        ad 	if (enable)
    627       1.1        ad 		AAC_SETREG2((sc), AAC_SA_MASK0_CLEAR, AAC_DB_INTERRUPTS);
    628       1.1        ad 	else
    629       1.1        ad 		AAC_SETREG2((sc), AAC_SA_MASK0_SET, ~0);
    630       1.1        ad }
    631       1.1        ad 
    632      1.15   thorpej static void
    633       1.1        ad aac_rx_set_interrupts(struct aac_softc *sc, int enable)
    634       1.1        ad {
    635       1.1        ad 
    636       1.1        ad 	if (enable)
    637       1.1        ad 		AAC_SETREG4(sc, AAC_RX_OIMR, ~AAC_DB_INTERRUPTS);
    638       1.1        ad 	else
    639       1.1        ad 		AAC_SETREG4(sc, AAC_RX_OIMR, ~0);
    640       1.1        ad }
    641