Home | History | Annotate | Line # | Download | only in pci
isp_pci.c revision 1.66.2.12
      1  1.66.2.11   nathanw /* $NetBSD: isp_pci.c,v 1.66.2.12 2002/10/18 02:43:09 nathanw Exp $ */
      2       1.56    mjacob /*
      3       1.56    mjacob  * This driver, which is contained in NetBSD in the files:
      4       1.56    mjacob  *
      5       1.56    mjacob  *	sys/dev/ic/isp.c
      6       1.62       wiz  *	sys/dev/ic/isp_inline.h
      7       1.62       wiz  *	sys/dev/ic/isp_netbsd.c
      8       1.62       wiz  *	sys/dev/ic/isp_netbsd.h
      9       1.62       wiz  *	sys/dev/ic/isp_target.c
     10       1.62       wiz  *	sys/dev/ic/isp_target.h
     11       1.62       wiz  *	sys/dev/ic/isp_tpublic.h
     12       1.62       wiz  *	sys/dev/ic/ispmbox.h
     13       1.62       wiz  *	sys/dev/ic/ispreg.h
     14       1.62       wiz  *	sys/dev/ic/ispvar.h
     15       1.56    mjacob  *	sys/microcode/isp/asm_sbus.h
     16       1.56    mjacob  *	sys/microcode/isp/asm_1040.h
     17       1.56    mjacob  *	sys/microcode/isp/asm_1080.h
     18       1.56    mjacob  *	sys/microcode/isp/asm_12160.h
     19       1.56    mjacob  *	sys/microcode/isp/asm_2100.h
     20       1.56    mjacob  *	sys/microcode/isp/asm_2200.h
     21       1.56    mjacob  *	sys/pci/isp_pci.c
     22       1.56    mjacob  *	sys/sbus/isp_sbus.c
     23       1.56    mjacob  *
     24       1.56    mjacob  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     25       1.56    mjacob  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     26       1.56    mjacob  * Linux versions. This tends to be an interesting maintenance problem.
     27       1.56    mjacob  *
     28       1.56    mjacob  * Please coordinate with Matthew Jacob on changes you wish to make here.
     29       1.56    mjacob  */
     30        1.1       cgd /*
     31        1.1       cgd  * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
     32       1.41    mjacob  */
     33       1.41    mjacob /*
     34       1.41    mjacob  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     35        1.1       cgd  * All rights reserved.
     36        1.1       cgd  *
     37   1.66.2.1   nathanw  * Additional Copyright (C) 2000, 2001 by Matthew Jacob
     38   1.66.2.1   nathanw  *
     39        1.1       cgd  * Redistribution and use in source and binary forms, with or without
     40        1.1       cgd  * modification, are permitted provided that the following conditions
     41        1.1       cgd  * are met:
     42        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     43       1.41    mjacob  *    notice, this list of conditions and the following disclaimer.
     44   1.66.2.1   nathanw  * 2. The name of the author may not be used to endorse or promote products
     45       1.41    mjacob  *    derived from this software without specific prior written permission
     46       1.21    mjacob  *
     47       1.41    mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48       1.41    mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49       1.41    mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50       1.41    mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51       1.41    mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52       1.41    mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53       1.41    mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54       1.41    mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55       1.41    mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56       1.41    mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57        1.1       cgd  */
     58   1.66.2.6   nathanw 
     59   1.66.2.6   nathanw #include <sys/cdefs.h>
     60  1.66.2.11   nathanw __KERNEL_RCSID(0, "$NetBSD: isp_pci.c,v 1.66.2.12 2002/10/18 02:43:09 nathanw Exp $");
     61        1.1       cgd 
     62       1.21    mjacob #include <dev/ic/isp_netbsd.h>
     63        1.1       cgd #include <dev/pci/pcireg.h>
     64        1.1       cgd #include <dev/pci/pcivar.h>
     65        1.1       cgd #include <dev/pci/pcidevs.h>
     66       1.60    mjacob #include <uvm/uvm_extern.h>
     67       1.65    mjacob #include <sys/reboot.h>
     68        1.3       cgd 
     69   1.66.2.1   nathanw static u_int16_t isp_pci_rd_reg(struct ispsoftc *, int);
     70   1.66.2.1   nathanw static void isp_pci_wr_reg(struct ispsoftc *, int, u_int16_t);
     71       1.52    mjacob #if !(defined(ISP_DISABLE_1080_SUPPORT) && defined(ISP_DISABLE_12160_SUPPORT))
     72   1.66.2.1   nathanw static u_int16_t isp_pci_rd_reg_1080(struct ispsoftc *, int);
     73   1.66.2.1   nathanw static void isp_pci_wr_reg_1080(struct ispsoftc *, int, u_int16_t);
     74       1.36    mjacob #endif
     75   1.66.2.4   nathanw static int
     76   1.66.2.4   nathanw isp_pci_rd_isr(struct ispsoftc *, u_int16_t *, u_int16_t *, u_int16_t *);
     77   1.66.2.4   nathanw static int
     78   1.66.2.4   nathanw isp_pci_rd_isr_2300(struct ispsoftc *, u_int16_t *, u_int16_t *, u_int16_t *);
     79   1.66.2.1   nathanw static int isp_pci_mbxdma(struct ispsoftc *);
     80   1.66.2.1   nathanw static int isp_pci_dmasetup(struct ispsoftc *, XS_T *, ispreq_t *,
     81   1.66.2.1   nathanw     u_int16_t *, u_int16_t);
     82   1.66.2.1   nathanw static void isp_pci_dmateardown(struct ispsoftc *, XS_T *, u_int16_t);
     83   1.66.2.1   nathanw static void isp_pci_reset1(struct ispsoftc *);
     84   1.66.2.1   nathanw static void isp_pci_dumpregs(struct ispsoftc *, const char *);
     85   1.66.2.1   nathanw static int isp_pci_intr(void *);
     86        1.1       cgd 
     87       1.52    mjacob #if	defined(ISP_DISABLE_1020_SUPPORT)
     88       1.47    mjacob #define	ISP_1040_RISC_CODE	NULL
     89       1.52    mjacob #else
     90   1.66.2.9   nathanw #define	ISP_1040_RISC_CODE	(u_int16_t *) isp_1040_risc_code
     91       1.52    mjacob #include <dev/microcode/isp/asm_1040.h>
     92       1.47    mjacob #endif
     93       1.52    mjacob 
     94       1.52    mjacob #if	defined(ISP_DISABLE_1080_SUPPORT)
     95       1.47    mjacob #define	ISP_1080_RISC_CODE	NULL
     96       1.52    mjacob #else
     97   1.66.2.9   nathanw #define	ISP_1080_RISC_CODE	(u_int16_t *) isp_1080_risc_code
     98       1.52    mjacob #include <dev/microcode/isp/asm_1080.h>
     99       1.47    mjacob #endif
    100       1.52    mjacob 
    101       1.52    mjacob #if	defined(ISP_DISABLE_12160_SUPPORT)
    102       1.50    mjacob #define	ISP_12160_RISC_CODE	NULL
    103       1.52    mjacob #else
    104   1.66.2.9   nathanw #define	ISP_12160_RISC_CODE	(u_int16_t *) isp_12160_risc_code
    105       1.52    mjacob #include <dev/microcode/isp/asm_12160.h>
    106       1.50    mjacob #endif
    107       1.52    mjacob 
    108       1.52    mjacob #if	defined(ISP_DISABLE_2100_SUPPORT)
    109       1.47    mjacob #define	ISP_2100_RISC_CODE	NULL
    110       1.52    mjacob #else
    111   1.66.2.9   nathanw #define	ISP_2100_RISC_CODE	(u_int16_t *) isp_2100_risc_code
    112       1.52    mjacob #include <dev/microcode/isp/asm_2100.h>
    113       1.47    mjacob #endif
    114       1.52    mjacob 
    115       1.52    mjacob #if	defined(ISP_DISABLE_2200_SUPPORT)
    116       1.47    mjacob #define	ISP_2200_RISC_CODE	NULL
    117       1.52    mjacob #else
    118   1.66.2.9   nathanw #define	ISP_2200_RISC_CODE	(u_int16_t *) isp_2200_risc_code
    119       1.52    mjacob #include <dev/microcode/isp/asm_2200.h>
    120       1.47    mjacob #endif
    121       1.47    mjacob 
    122   1.66.2.4   nathanw #if	defined(ISP_DISABLE_2300_SUPPORT)
    123   1.66.2.4   nathanw #define	ISP_2300_RISC_CODE	NULL
    124   1.66.2.4   nathanw #else
    125   1.66.2.9   nathanw #define	ISP_2300_RISC_CODE	(u_int16_t *) isp_2300_risc_code
    126   1.66.2.4   nathanw #include <dev/microcode/isp/asm_2300.h>
    127   1.66.2.4   nathanw #endif
    128   1.66.2.4   nathanw 
    129       1.36    mjacob #ifndef	ISP_DISABLE_1020_SUPPORT
    130        1.1       cgd static struct ispmdvec mdvec = {
    131   1.66.2.4   nathanw 	isp_pci_rd_isr,
    132        1.1       cgd 	isp_pci_rd_reg,
    133        1.1       cgd 	isp_pci_wr_reg,
    134        1.1       cgd 	isp_pci_mbxdma,
    135        1.1       cgd 	isp_pci_dmasetup,
    136       1.13   thorpej 	isp_pci_dmateardown,
    137        1.1       cgd 	NULL,
    138        1.1       cgd 	isp_pci_reset1,
    139       1.15    mjacob 	isp_pci_dumpregs,
    140       1.47    mjacob 	ISP_1040_RISC_CODE,
    141       1.53    mjacob 	BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
    142       1.15    mjacob };
    143       1.36    mjacob #endif
    144       1.36    mjacob 
    145       1.36    mjacob #ifndef	ISP_DISABLE_1080_SUPPORT
    146       1.36    mjacob static struct ispmdvec mdvec_1080 = {
    147   1.66.2.4   nathanw 	isp_pci_rd_isr,
    148       1.36    mjacob 	isp_pci_rd_reg_1080,
    149       1.36    mjacob 	isp_pci_wr_reg_1080,
    150       1.36    mjacob 	isp_pci_mbxdma,
    151       1.36    mjacob 	isp_pci_dmasetup,
    152       1.36    mjacob 	isp_pci_dmateardown,
    153       1.36    mjacob 	NULL,
    154       1.36    mjacob 	isp_pci_reset1,
    155       1.36    mjacob 	isp_pci_dumpregs,
    156       1.47    mjacob 	ISP_1080_RISC_CODE,
    157       1.53    mjacob 	BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
    158       1.36    mjacob };
    159       1.36    mjacob #endif
    160       1.15    mjacob 
    161       1.50    mjacob #ifndef	ISP_DISABLE_12160_SUPPORT
    162       1.50    mjacob static struct ispmdvec mdvec_12160 = {
    163   1.66.2.4   nathanw 	isp_pci_rd_isr,
    164       1.50    mjacob 	isp_pci_rd_reg_1080,
    165       1.50    mjacob 	isp_pci_wr_reg_1080,
    166       1.50    mjacob 	isp_pci_mbxdma,
    167       1.50    mjacob 	isp_pci_dmasetup,
    168       1.50    mjacob 	isp_pci_dmateardown,
    169       1.50    mjacob 	NULL,
    170       1.50    mjacob 	isp_pci_reset1,
    171       1.50    mjacob 	isp_pci_dumpregs,
    172       1.50    mjacob 	ISP_12160_RISC_CODE,
    173       1.53    mjacob 	BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
    174       1.50    mjacob };
    175       1.50    mjacob #endif
    176       1.50    mjacob 
    177       1.36    mjacob #ifndef	ISP_DISABLE_2100_SUPPORT
    178       1.15    mjacob static struct ispmdvec mdvec_2100 = {
    179   1.66.2.4   nathanw 	isp_pci_rd_isr,
    180       1.15    mjacob 	isp_pci_rd_reg,
    181       1.15    mjacob 	isp_pci_wr_reg,
    182       1.15    mjacob 	isp_pci_mbxdma,
    183       1.15    mjacob 	isp_pci_dmasetup,
    184       1.15    mjacob 	isp_pci_dmateardown,
    185       1.15    mjacob 	NULL,
    186       1.15    mjacob 	isp_pci_reset1,
    187       1.15    mjacob 	isp_pci_dumpregs,
    188       1.53    mjacob 	ISP_2100_RISC_CODE
    189        1.1       cgd };
    190       1.36    mjacob #endif
    191        1.1       cgd 
    192       1.41    mjacob #ifndef	ISP_DISABLE_2200_SUPPORT
    193       1.41    mjacob static struct ispmdvec mdvec_2200 = {
    194   1.66.2.4   nathanw 	isp_pci_rd_isr,
    195       1.41    mjacob 	isp_pci_rd_reg,
    196       1.41    mjacob 	isp_pci_wr_reg,
    197       1.41    mjacob 	isp_pci_mbxdma,
    198       1.41    mjacob 	isp_pci_dmasetup,
    199       1.41    mjacob 	isp_pci_dmateardown,
    200       1.41    mjacob 	NULL,
    201       1.41    mjacob 	isp_pci_reset1,
    202       1.41    mjacob 	isp_pci_dumpregs,
    203       1.53    mjacob 	ISP_2200_RISC_CODE
    204       1.41    mjacob };
    205       1.41    mjacob #endif
    206       1.41    mjacob 
    207   1.66.2.4   nathanw #ifndef	ISP_DISABLE_2300_SUPPORT
    208   1.66.2.4   nathanw static struct ispmdvec mdvec_2300 = {
    209   1.66.2.4   nathanw 	isp_pci_rd_isr_2300,
    210   1.66.2.4   nathanw 	isp_pci_rd_reg,
    211   1.66.2.4   nathanw 	isp_pci_wr_reg,
    212   1.66.2.4   nathanw 	isp_pci_mbxdma,
    213   1.66.2.4   nathanw 	isp_pci_dmasetup,
    214   1.66.2.4   nathanw 	isp_pci_dmateardown,
    215   1.66.2.4   nathanw 	NULL,
    216   1.66.2.4   nathanw 	isp_pci_reset1,
    217   1.66.2.4   nathanw 	isp_pci_dumpregs,
    218   1.66.2.4   nathanw 	ISP_2300_RISC_CODE
    219   1.66.2.4   nathanw };
    220   1.66.2.4   nathanw #endif
    221   1.66.2.4   nathanw 
    222       1.36    mjacob #ifndef	PCI_VENDOR_QLOGIC
    223       1.36    mjacob #define	PCI_VENDOR_QLOGIC	0x1077
    224       1.36    mjacob #endif
    225       1.36    mjacob 
    226       1.36    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP1020
    227       1.36    mjacob #define	PCI_PRODUCT_QLOGIC_ISP1020	0x1020
    228       1.36    mjacob #endif
    229       1.36    mjacob 
    230       1.36    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP1080
    231       1.36    mjacob #define	PCI_PRODUCT_QLOGIC_ISP1080	0x1080
    232       1.36    mjacob #endif
    233       1.36    mjacob 
    234       1.36    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP1240
    235       1.36    mjacob #define	PCI_PRODUCT_QLOGIC_ISP1240	0x1240
    236       1.36    mjacob #endif
    237        1.1       cgd 
    238       1.48    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP1280
    239       1.48    mjacob #define	PCI_PRODUCT_QLOGIC_ISP1280	0x1280
    240       1.48    mjacob #endif
    241       1.48    mjacob 
    242       1.50    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP12160
    243       1.53    mjacob #define	PCI_PRODUCT_QLOGIC_ISP12160	0x1216
    244       1.50    mjacob #endif
    245       1.50    mjacob 
    246       1.15    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP2100
    247       1.15    mjacob #define	PCI_PRODUCT_QLOGIC_ISP2100	0x2100
    248       1.15    mjacob #endif
    249       1.36    mjacob 
    250       1.41    mjacob #ifndef	PCI_PRODUCT_QLOGIC_ISP2200
    251       1.41    mjacob #define	PCI_PRODUCT_QLOGIC_ISP2200	0x2200
    252       1.41    mjacob #endif
    253       1.41    mjacob 
    254   1.66.2.4   nathanw #ifndef	PCI_PRODUCT_QLOGIC_ISP2300
    255   1.66.2.4   nathanw #define	PCI_PRODUCT_QLOGIC_ISP2300	0x2300
    256   1.66.2.4   nathanw #endif
    257   1.66.2.4   nathanw 
    258   1.66.2.4   nathanw #ifndef	PCI_PRODUCT_QLOGIC_ISP2312
    259   1.66.2.4   nathanw #define	PCI_PRODUCT_QLOGIC_ISP2312	0x2312
    260   1.66.2.4   nathanw #endif
    261   1.66.2.4   nathanw 
    262       1.36    mjacob #define	PCI_QLOGIC_ISP	((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
    263       1.36    mjacob 
    264       1.36    mjacob #define	PCI_QLOGIC_ISP1080	\
    265       1.36    mjacob 	((PCI_PRODUCT_QLOGIC_ISP1080 << 16) | PCI_VENDOR_QLOGIC)
    266       1.36    mjacob 
    267       1.36    mjacob #define	PCI_QLOGIC_ISP1240	\
    268       1.36    mjacob 	((PCI_PRODUCT_QLOGIC_ISP1240 << 16) | PCI_VENDOR_QLOGIC)
    269       1.36    mjacob 
    270       1.48    mjacob #define	PCI_QLOGIC_ISP1280	\
    271       1.48    mjacob 	((PCI_PRODUCT_QLOGIC_ISP1280 << 16) | PCI_VENDOR_QLOGIC)
    272       1.48    mjacob 
    273       1.50    mjacob #define	PCI_QLOGIC_ISP12160	\
    274       1.50    mjacob 	((PCI_PRODUCT_QLOGIC_ISP12160 << 16) | PCI_VENDOR_QLOGIC)
    275       1.50    mjacob 
    276       1.15    mjacob #define	PCI_QLOGIC_ISP2100	\
    277       1.15    mjacob 	((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC)
    278       1.15    mjacob 
    279       1.41    mjacob #define	PCI_QLOGIC_ISP2200	\
    280       1.41    mjacob 	((PCI_PRODUCT_QLOGIC_ISP2200 << 16) | PCI_VENDOR_QLOGIC)
    281       1.41    mjacob 
    282   1.66.2.4   nathanw #define	PCI_QLOGIC_ISP2300	\
    283   1.66.2.4   nathanw 	((PCI_PRODUCT_QLOGIC_ISP2300 << 16) | PCI_VENDOR_QLOGIC)
    284   1.66.2.4   nathanw 
    285   1.66.2.4   nathanw #define	PCI_QLOGIC_ISP2312	\
    286   1.66.2.4   nathanw 	((PCI_PRODUCT_QLOGIC_ISP2312 << 16) | PCI_VENDOR_QLOGIC)
    287   1.66.2.4   nathanw 
    288       1.44    mjacob #define	IO_MAP_REG	0x10
    289       1.44    mjacob #define	MEM_MAP_REG	0x14
    290       1.39    mjacob #define	PCIR_ROMADDR	0x30
    291       1.39    mjacob 
    292       1.39    mjacob #define	PCI_DFLT_LTNCY	0x40
    293       1.39    mjacob #define	PCI_DFLT_LNSZ	0x10
    294        1.6       cgd 
    295        1.1       cgd 
    296   1.66.2.1   nathanw static int isp_pci_probe(struct device *, struct cfdata *, void *);
    297   1.66.2.1   nathanw static void isp_pci_attach(struct device *, struct device *, void *);
    298        1.1       cgd 
    299        1.1       cgd struct isp_pcisoftc {
    300        1.1       cgd 	struct ispsoftc		pci_isp;
    301       1.15    mjacob 	pci_chipset_tag_t	pci_pc;
    302       1.15    mjacob 	pcitag_t		pci_tag;
    303        1.6       cgd 	bus_space_tag_t		pci_st;
    304        1.6       cgd 	bus_space_handle_t	pci_sh;
    305       1.45    mjacob 	bus_dmamap_t		*pci_xfer_dmap;
    306        1.1       cgd 	void *			pci_ih;
    307       1.36    mjacob 	int16_t			pci_poff[_NREG_BLKS];
    308        1.1       cgd };
    309        1.1       cgd 
    310  1.66.2.12   nathanw CFATTACH_DECL(isp_pci, sizeof (struct isp_pcisoftc),
    311  1.66.2.12   nathanw     isp_pci_probe, isp_pci_attach, NULL, NULL);
    312        1.1       cgd 
    313       1.55    mjacob #ifdef	DEBUG
    314       1.63    mjacob const char vstring[] =
    315       1.53    mjacob     "Qlogic ISP Driver, NetBSD (pci) Platform Version %d.%d Core Version %d.%d";
    316       1.55    mjacob #endif
    317       1.53    mjacob 
    318        1.1       cgd static int
    319   1.66.2.1   nathanw isp_pci_probe(struct device *parent, struct cfdata *match, void *aux)
    320       1.44    mjacob {
    321       1.44    mjacob 	struct pci_attach_args *pa = aux;
    322       1.44    mjacob 	switch (pa->pa_id) {
    323       1.36    mjacob #ifndef	ISP_DISABLE_1020_SUPPORT
    324       1.36    mjacob 	case PCI_QLOGIC_ISP:
    325       1.36    mjacob 		return (1);
    326       1.36    mjacob #endif
    327       1.36    mjacob #ifndef	ISP_DISABLE_1080_SUPPORT
    328       1.36    mjacob 	case PCI_QLOGIC_ISP1080:
    329       1.40    mjacob 	case PCI_QLOGIC_ISP1240:
    330       1.48    mjacob 	case PCI_QLOGIC_ISP1280:
    331       1.36    mjacob 		return (1);
    332       1.36    mjacob #endif
    333       1.50    mjacob #ifndef	ISP_DISABLE_12160_SUPPORT
    334       1.50    mjacob 	case PCI_QLOGIC_ISP12160:
    335       1.50    mjacob 		return (1);
    336       1.50    mjacob #endif
    337       1.36    mjacob #ifndef	ISP_DISABLE_2100_SUPPORT
    338       1.36    mjacob 	case PCI_QLOGIC_ISP2100:
    339        1.1       cgd 		return (1);
    340       1.36    mjacob #endif
    341       1.41    mjacob #ifndef	ISP_DISABLE_2200_SUPPORT
    342       1.41    mjacob 	case PCI_QLOGIC_ISP2200:
    343       1.41    mjacob 		return (1);
    344       1.41    mjacob #endif
    345   1.66.2.4   nathanw #ifndef	ISP_DISABLE_2300_SUPPORT
    346   1.66.2.4   nathanw 	case PCI_QLOGIC_ISP2300:
    347   1.66.2.4   nathanw 	case PCI_QLOGIC_ISP2312:
    348   1.66.2.4   nathanw 		return (1);
    349   1.66.2.4   nathanw #endif
    350       1.36    mjacob 	default:
    351        1.1       cgd 		return (0);
    352        1.1       cgd 	}
    353        1.1       cgd }
    354        1.1       cgd 
    355        1.1       cgd 
    356       1.44    mjacob static void
    357   1.66.2.1   nathanw isp_pci_attach(struct device *parent, struct device *self, void *aux)
    358        1.1       cgd {
    359       1.29    mjacob #ifdef	DEBUG
    360       1.27   thorpej 	static char oneshot = 1;
    361       1.27   thorpej #endif
    362  1.66.2.10   nathanw 	static const char nomem[] = "\n%s: no mem for sdparam table\n";
    363       1.47    mjacob 	u_int32_t data, rev, linesz = PCI_DFLT_LNSZ;
    364        1.1       cgd 	struct pci_attach_args *pa = aux;
    365        1.1       cgd 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) self;
    366       1.21    mjacob 	struct ispsoftc *isp = &pcs->pci_isp;
    367       1.11       cgd 	bus_space_tag_t st, iot, memt;
    368       1.11       cgd 	bus_space_handle_t sh, ioh, memh;
    369        1.1       cgd 	pci_intr_handle_t ih;
    370  1.66.2.10   nathanw 	char *dstring;
    371        1.1       cgd 	const char *intrstr;
    372       1.53    mjacob 	int ioh_valid, memh_valid;
    373        1.1       cgd 
    374       1.12       cgd 	ioh_valid = (pci_mapreg_map(pa, IO_MAP_REG,
    375       1.11       cgd 	    PCI_MAPREG_TYPE_IO, 0,
    376       1.11       cgd 	    &iot, &ioh, NULL, NULL) == 0);
    377       1.12       cgd 	memh_valid = (pci_mapreg_map(pa, MEM_MAP_REG,
    378       1.11       cgd 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    379       1.11       cgd 	    &memt, &memh, NULL, NULL) == 0);
    380       1.11       cgd 	if (memh_valid) {
    381       1.11       cgd 		st = memt;
    382       1.11       cgd 		sh = memh;
    383       1.11       cgd 	} else if (ioh_valid) {
    384       1.11       cgd 		st = iot;
    385       1.11       cgd 		sh = ioh;
    386        1.6       cgd 	} else {
    387       1.11       cgd 		printf(": unable to map device registers\n");
    388        1.9       cgd 		return;
    389        1.1       cgd 	}
    390  1.66.2.10   nathanw 	dstring = "\n";
    391        1.1       cgd 
    392        1.6       cgd 	pcs->pci_st = st;
    393        1.6       cgd 	pcs->pci_sh = sh;
    394       1.15    mjacob 	pcs->pci_pc = pa->pa_pc;
    395       1.15    mjacob 	pcs->pci_tag = pa->pa_tag;
    396       1.36    mjacob 	pcs->pci_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF;
    397       1.36    mjacob 	pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS_OFF;
    398       1.36    mjacob 	pcs->pci_poff[SXP_BLOCK >> _BLK_REG_SHFT] = PCI_SXP_REGS_OFF;
    399       1.36    mjacob 	pcs->pci_poff[RISC_BLOCK >> _BLK_REG_SHFT] = PCI_RISC_REGS_OFF;
    400       1.36    mjacob 	pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF;
    401       1.47    mjacob 	rev = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0xff;
    402       1.36    mjacob 
    403       1.36    mjacob #ifndef	ISP_DISABLE_1020_SUPPORT
    404       1.15    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP) {
    405  1.66.2.10   nathanw 		dstring = ": QLogic 1020 Ultra Wide SCSI HBA\n";
    406       1.21    mjacob 		isp->isp_mdvec = &mdvec;
    407       1.21    mjacob 		isp->isp_type = ISP_HA_SCSI_UNKNOWN;
    408       1.21    mjacob 		isp->isp_param = malloc(sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    409       1.21    mjacob 		if (isp->isp_param == NULL) {
    410       1.40    mjacob 			printf(nomem, isp->isp_name);
    411       1.21    mjacob 			return;
    412       1.15    mjacob 		}
    413   1.66.2.3   nathanw 		memset(isp->isp_param, 0, sizeof (sdparam));
    414       1.36    mjacob 	}
    415       1.36    mjacob #endif
    416       1.36    mjacob #ifndef	ISP_DISABLE_1080_SUPPORT
    417       1.36    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP1080) {
    418  1.66.2.10   nathanw 		dstring = ": QLogic 1080 Ultra-2 Wide SCSI HBA\n";
    419       1.36    mjacob 		isp->isp_mdvec = &mdvec_1080;
    420       1.36    mjacob 		isp->isp_type = ISP_HA_SCSI_1080;
    421       1.36    mjacob 		isp->isp_param = malloc(sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    422       1.36    mjacob 		if (isp->isp_param == NULL) {
    423       1.40    mjacob 			printf(nomem, isp->isp_name);
    424       1.36    mjacob 			return;
    425       1.36    mjacob 		}
    426   1.66.2.3   nathanw 		memset(isp->isp_param, 0, sizeof (sdparam));
    427       1.36    mjacob 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    428       1.36    mjacob 		    ISP1080_DMA_REGS_OFF;
    429       1.36    mjacob 	}
    430       1.40    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP1240) {
    431  1.66.2.10   nathanw 		dstring = ": QLogic Dual Channel Ultra Wide SCSI HBA\n";
    432       1.40    mjacob 		isp->isp_mdvec = &mdvec_1080;
    433       1.48    mjacob 		isp->isp_type = ISP_HA_SCSI_1240;
    434       1.48    mjacob 		isp->isp_param =
    435       1.48    mjacob 		    malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    436       1.48    mjacob 		if (isp->isp_param == NULL) {
    437       1.48    mjacob 			printf(nomem, isp->isp_name);
    438       1.48    mjacob 			return;
    439       1.48    mjacob 		}
    440   1.66.2.3   nathanw 		memset(isp->isp_param, 0, 2 * sizeof (sdparam));
    441       1.48    mjacob 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    442       1.48    mjacob 		    ISP1080_DMA_REGS_OFF;
    443       1.48    mjacob 	}
    444       1.48    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP1280) {
    445  1.66.2.10   nathanw 		dstring = ": QLogic Dual Channel Ultra-2 Wide SCSI HBA\n";
    446       1.48    mjacob 		isp->isp_mdvec = &mdvec_1080;
    447       1.48    mjacob 		isp->isp_type = ISP_HA_SCSI_1280;
    448       1.40    mjacob 		isp->isp_param =
    449       1.40    mjacob 		    malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    450       1.40    mjacob 		if (isp->isp_param == NULL) {
    451       1.40    mjacob 			printf(nomem, isp->isp_name);
    452       1.40    mjacob 			return;
    453       1.40    mjacob 		}
    454   1.66.2.3   nathanw 		memset(isp->isp_param, 0, 2 * sizeof (sdparam));
    455       1.40    mjacob 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    456       1.40    mjacob 		    ISP1080_DMA_REGS_OFF;
    457       1.40    mjacob 	}
    458       1.36    mjacob #endif
    459       1.50    mjacob #ifndef	ISP_DISABLE_12160_SUPPORT
    460       1.50    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP12160) {
    461  1.66.2.10   nathanw 		dstring = ": QLogic Dual Channel Ultra-3 Wide SCSI HBA\n";
    462       1.50    mjacob 		isp->isp_mdvec = &mdvec_12160;
    463       1.50    mjacob 		isp->isp_type = ISP_HA_SCSI_12160;
    464       1.50    mjacob 		isp->isp_param =
    465       1.50    mjacob 		    malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
    466       1.50    mjacob 		if (isp->isp_param == NULL) {
    467       1.50    mjacob 			printf(nomem, isp->isp_name);
    468       1.50    mjacob 			return;
    469       1.50    mjacob 		}
    470   1.66.2.3   nathanw 		memset(isp->isp_param, 0, 2 * sizeof (sdparam));
    471       1.50    mjacob 		pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
    472       1.50    mjacob 		    ISP1080_DMA_REGS_OFF;
    473       1.50    mjacob 	}
    474       1.50    mjacob #endif
    475       1.36    mjacob #ifndef	ISP_DISABLE_2100_SUPPORT
    476       1.36    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP2100) {
    477  1.66.2.10   nathanw 		dstring = ": QLogic FC-AL HBA\n";
    478       1.21    mjacob 		isp->isp_mdvec = &mdvec_2100;
    479       1.21    mjacob 		isp->isp_type = ISP_HA_FC_2100;
    480       1.21    mjacob 		isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
    481       1.21    mjacob 		if (isp->isp_param == NULL) {
    482       1.40    mjacob 			printf(nomem, isp->isp_name);
    483       1.21    mjacob 			return;
    484       1.15    mjacob 		}
    485   1.66.2.3   nathanw 		memset(isp->isp_param, 0, sizeof (fcparam));
    486       1.36    mjacob 		pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
    487       1.36    mjacob 		    PCI_MBOX_REGS2100_OFF;
    488       1.47    mjacob 		if (rev < 3) {
    489       1.39    mjacob 			/*
    490       1.39    mjacob 			 * XXX: Need to get the actual revision
    491       1.39    mjacob 			 * XXX: number of the 2100 FB. At any rate,
    492       1.39    mjacob 			 * XXX: lower cache line size for early revision
    493       1.39    mjacob 			 * XXX; boards.
    494       1.39    mjacob 			 */
    495       1.39    mjacob 			linesz = 1;
    496       1.39    mjacob 		}
    497       1.15    mjacob 	}
    498       1.36    mjacob #endif
    499       1.41    mjacob #ifndef	ISP_DISABLE_2200_SUPPORT
    500       1.41    mjacob 	if (pa->pa_id == PCI_QLOGIC_ISP2200) {
    501  1.66.2.10   nathanw 		dstring = ": QLogic FC-AL and Fabric HBA\n";
    502       1.41    mjacob 		isp->isp_mdvec = &mdvec_2200;
    503       1.41    mjacob 		isp->isp_type = ISP_HA_FC_2200;
    504       1.41    mjacob 		isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
    505       1.41    mjacob 		if (isp->isp_param == NULL) {
    506       1.41    mjacob 			printf(nomem, isp->isp_name);
    507       1.41    mjacob 			return;
    508       1.41    mjacob 		}
    509   1.66.2.3   nathanw 		memset(isp->isp_param, 0, sizeof (fcparam));
    510       1.41    mjacob 		pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
    511       1.41    mjacob 		    PCI_MBOX_REGS2100_OFF;
    512       1.41    mjacob 		data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG);
    513       1.41    mjacob 	}
    514       1.41    mjacob #endif
    515   1.66.2.4   nathanw #ifndef	ISP_DISABLE_2300_SUPPORT
    516   1.66.2.4   nathanw 	if (pa->pa_id == PCI_QLOGIC_ISP2300 ||
    517   1.66.2.4   nathanw 	    pa->pa_id == PCI_QLOGIC_ISP2312) {
    518   1.66.2.4   nathanw 		isp->isp_mdvec = &mdvec_2300;
    519   1.66.2.8   nathanw 		if (pa->pa_id == PCI_QLOGIC_ISP2300) {
    520  1.66.2.10   nathanw 			dstring = ": QLogic FC-AL and 2Gbps Fabric HBA\n";
    521   1.66.2.8   nathanw 			isp->isp_type = ISP_HA_FC_2300;
    522   1.66.2.8   nathanw 		} else {
    523  1.66.2.10   nathanw 			dstring =
    524  1.66.2.10   nathanw 			    ": QLogic Dual Port FC-AL and 2Gbps Fabric HBA\n";
    525   1.66.2.8   nathanw 			isp->isp_type = ISP_HA_FC_2312;
    526   1.66.2.8   nathanw 			isp->isp_port = pa->pa_function;
    527   1.66.2.8   nathanw 		}
    528   1.66.2.4   nathanw 		isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
    529   1.66.2.4   nathanw 		if (isp->isp_param == NULL) {
    530   1.66.2.4   nathanw 			printf(nomem, isp->isp_name);
    531   1.66.2.4   nathanw 			return;
    532   1.66.2.4   nathanw 		}
    533   1.66.2.4   nathanw 		memset(isp->isp_param, 0, sizeof (fcparam));
    534   1.66.2.4   nathanw 		pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
    535   1.66.2.4   nathanw 		    PCI_MBOX_REGS2300_OFF;
    536   1.66.2.4   nathanw 		data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG);
    537   1.66.2.4   nathanw 	}
    538   1.66.2.4   nathanw #endif
    539       1.53    mjacob 	/*
    540       1.53    mjacob 	 * Set up logging levels.
    541       1.53    mjacob 	 */
    542       1.53    mjacob #ifdef	ISP_LOGDEFAULT
    543       1.53    mjacob 	isp->isp_dblev = ISP_LOGDEFAULT;
    544       1.53    mjacob #else
    545       1.65    mjacob 	isp->isp_dblev = ISP_LOGWARN|ISP_LOGERR;
    546       1.65    mjacob 	if (bootverbose)
    547       1.65    mjacob 		isp->isp_dblev |= ISP_LOGCONFIG|ISP_LOGINFO;
    548       1.53    mjacob #ifdef	SCSIDEBUG
    549  1.66.2.10   nathanw 	isp->isp_dblev |= ISP_LOGDEBUG0|ISP_LOGDEBUG1|ISP_LOGDEBUG2;
    550       1.53    mjacob #endif
    551       1.53    mjacob #endif
    552  1.66.2.10   nathanw 	if (isp->isp_dblev & ISP_LOGCONFIG) {
    553  1.66.2.10   nathanw 		printf("\n");
    554  1.66.2.10   nathanw 	} else {
    555  1.66.2.10   nathanw 		printf(dstring);
    556  1.66.2.10   nathanw 	}
    557       1.57    mjacob 
    558       1.54    mjacob #ifdef	DEBUG
    559       1.53    mjacob 	if (oneshot) {
    560       1.53    mjacob 		oneshot = 0;
    561       1.53    mjacob 		isp_prt(isp, ISP_LOGCONFIG, vstring,
    562       1.53    mjacob 		    ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR,
    563       1.53    mjacob 		    ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR);
    564       1.53    mjacob 	}
    565       1.54    mjacob #endif
    566       1.53    mjacob 
    567   1.66.2.7   nathanw 	isp->isp_dmatag = pa->pa_dmat;
    568       1.47    mjacob 	isp->isp_revision = rev;
    569       1.36    mjacob 
    570       1.35    mjacob 	/*
    571       1.35    mjacob 	 * Make sure that command register set sanely.
    572       1.35    mjacob 	 */
    573       1.35    mjacob 	data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    574       1.35    mjacob 	data |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE;
    575       1.36    mjacob 
    576       1.35    mjacob 	/*
    577       1.35    mjacob 	 * Not so sure about these- but I think it's important that they get
    578       1.35    mjacob 	 * enabled......
    579       1.35    mjacob 	 */
    580       1.35    mjacob 	data |= PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
    581   1.66.2.8   nathanw 	if (IS_2300(isp)) {	/* per QLogic errata */
    582   1.66.2.8   nathanw 		data &= ~PCI_COMMAND_INVALIDATE_ENABLE;
    583   1.66.2.8   nathanw 	}
    584  1.66.2.10   nathanw 	if (IS_23XX(isp)) {
    585  1.66.2.10   nathanw 		isp->isp_touched = 1;
    586  1.66.2.10   nathanw 	}
    587       1.35    mjacob 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, data);
    588       1.36    mjacob 
    589       1.35    mjacob 	/*
    590       1.39    mjacob 	 * Make sure that the latency timer, cache line size,
    591       1.39    mjacob 	 * and ROM is disabled.
    592       1.35    mjacob 	 */
    593       1.35    mjacob 	data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    594       1.35    mjacob 	data &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    595       1.35    mjacob 	data &= ~(PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT);
    596       1.39    mjacob 	data |= (PCI_DFLT_LTNCY	<< PCI_LATTIMER_SHIFT);
    597       1.39    mjacob 	data |= (linesz << PCI_CACHELINE_SHIFT);
    598       1.35    mjacob 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, data);
    599       1.39    mjacob 
    600       1.39    mjacob 	data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCIR_ROMADDR);
    601       1.39    mjacob 	data &= ~1;
    602       1.39    mjacob 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCIR_ROMADDR, data);
    603       1.35    mjacob 
    604       1.64  sommerfe 	if (pci_intr_map(pa, &ih)) {
    605       1.21    mjacob 		printf("%s: couldn't map interrupt\n", isp->isp_name);
    606       1.21    mjacob 		free(isp->isp_param, M_DEVBUF);
    607        1.1       cgd 		return;
    608        1.1       cgd 	}
    609        1.1       cgd 	intrstr = pci_intr_string(pa->pa_pc, ih);
    610        1.1       cgd 	if (intrstr == NULL)
    611        1.1       cgd 		intrstr = "<I dunno>";
    612       1.44    mjacob 	pcs->pci_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO,
    613       1.44    mjacob 	    isp_pci_intr, isp);
    614        1.1       cgd 	if (pcs->pci_ih == NULL) {
    615        1.1       cgd 		printf("%s: couldn't establish interrupt at %s\n",
    616       1.21    mjacob 			isp->isp_name, intrstr);
    617       1.36    mjacob 		free(isp->isp_param, M_DEVBUF);
    618       1.36    mjacob 		return;
    619       1.36    mjacob 	}
    620       1.53    mjacob 
    621       1.36    mjacob 	printf("%s: interrupting at %s\n", isp->isp_name, intrstr);
    622       1.36    mjacob 
    623       1.43    mjacob 	if (IS_FC(isp)) {
    624       1.53    mjacob 		DEFAULT_NODEWWN(isp) = 0x400000007F000002;
    625       1.57    mjacob 		DEFAULT_PORTWWN(isp) = 0x400000007F000002;
    626       1.43    mjacob 	}
    627       1.41    mjacob 
    628       1.49    mjacob 	isp->isp_confopts = self->dv_cfdata->cf_flags;
    629       1.66    mjacob 	isp->isp_role = ISP_DEFAULT_ROLES;
    630       1.36    mjacob 	ISP_LOCK(isp);
    631       1.53    mjacob 	isp->isp_osinfo.no_mbox_ints = 1;
    632       1.36    mjacob 	isp_reset(isp);
    633       1.36    mjacob 	if (isp->isp_state != ISP_RESETSTATE) {
    634       1.36    mjacob 		ISP_UNLOCK(isp);
    635       1.36    mjacob 		free(isp->isp_param, M_DEVBUF);
    636       1.36    mjacob 		return;
    637       1.36    mjacob 	}
    638       1.53    mjacob 	ENABLE_INTS(isp);
    639       1.36    mjacob 	isp_init(isp);
    640       1.36    mjacob 	if (isp->isp_state != ISP_INITSTATE) {
    641       1.21    mjacob 		isp_uninit(isp);
    642       1.22    mjacob 		ISP_UNLOCK(isp);
    643       1.21    mjacob 		free(isp->isp_param, M_DEVBUF);
    644        1.1       cgd 		return;
    645        1.1       cgd 	}
    646        1.1       cgd 	/*
    647       1.53    mjacob 	 * Do platform attach.
    648        1.1       cgd 	 */
    649       1.53    mjacob 	ISP_UNLOCK(isp);
    650       1.21    mjacob 	isp_attach(isp);
    651       1.21    mjacob 	if (isp->isp_state != ISP_RUNSTATE) {
    652       1.53    mjacob 		ISP_LOCK(isp);
    653       1.21    mjacob 		isp_uninit(isp);
    654       1.21    mjacob 		free(isp->isp_param, M_DEVBUF);
    655       1.53    mjacob 		ISP_UNLOCK(isp);
    656        1.1       cgd 	}
    657        1.1       cgd }
    658        1.1       cgd 
    659   1.66.2.4   nathanw #define	IspVirt2Off(a, x)	\
    660   1.66.2.4   nathanw 	(((struct isp_pcisoftc *)a)->pci_poff[((x) & _BLK_REG_MASK) >> \
    661   1.66.2.4   nathanw 	_BLK_REG_SHFT] + ((x) & 0xff))
    662   1.66.2.4   nathanw 
    663   1.66.2.4   nathanw #define	BXR2(pcs, off)		\
    664   1.66.2.4   nathanw 	bus_space_read_2(pcs->pci_st, pcs->pci_sh, off)
    665   1.66.2.4   nathanw #define	BXW2(pcs, off, v)	\
    666   1.66.2.4   nathanw 	bus_space_write_2(pcs->pci_st, pcs->pci_sh, off, v)
    667   1.66.2.4   nathanw 
    668   1.66.2.4   nathanw 
    669   1.66.2.4   nathanw static INLINE int
    670   1.66.2.4   nathanw isp_pci_rd_debounced(struct ispsoftc *isp, int off, u_int16_t *rp)
    671   1.66.2.4   nathanw {
    672   1.66.2.4   nathanw 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    673   1.66.2.4   nathanw 	u_int16_t val0, val1;
    674   1.66.2.4   nathanw 	int i = 0;
    675   1.66.2.4   nathanw 
    676   1.66.2.4   nathanw 	do {
    677   1.66.2.4   nathanw 		val0 = BXR2(pcs, IspVirt2Off(isp, off));
    678   1.66.2.4   nathanw 		val1 = BXR2(pcs, IspVirt2Off(isp, off));
    679   1.66.2.4   nathanw 	} while (val0 != val1 && ++i < 1000);
    680   1.66.2.4   nathanw 	if (val0 != val1) {
    681   1.66.2.4   nathanw 		return (1);
    682   1.66.2.4   nathanw 	}
    683   1.66.2.4   nathanw 	*rp = val0;
    684   1.66.2.4   nathanw 	return (0);
    685   1.66.2.4   nathanw }
    686   1.66.2.4   nathanw 
    687   1.66.2.4   nathanw static int
    688   1.66.2.4   nathanw isp_pci_rd_isr(struct ispsoftc *isp, u_int16_t *isrp,
    689   1.66.2.4   nathanw     u_int16_t *semap, u_int16_t *mbp)
    690   1.66.2.4   nathanw {
    691   1.66.2.4   nathanw 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    692   1.66.2.4   nathanw 	u_int16_t isr, sema;
    693   1.66.2.4   nathanw 
    694   1.66.2.4   nathanw 	if (IS_2100(isp)) {
    695   1.66.2.4   nathanw 		if (isp_pci_rd_debounced(isp, BIU_ISR, &isr)) {
    696   1.66.2.4   nathanw 		    return (0);
    697   1.66.2.4   nathanw 		}
    698   1.66.2.4   nathanw 		if (isp_pci_rd_debounced(isp, BIU_SEMA, &sema)) {
    699   1.66.2.4   nathanw 		    return (0);
    700   1.66.2.4   nathanw 		}
    701   1.66.2.4   nathanw 	} else {
    702   1.66.2.4   nathanw 		isr = BXR2(pcs, IspVirt2Off(isp, BIU_ISR));
    703   1.66.2.4   nathanw 		sema = BXR2(pcs, IspVirt2Off(isp, BIU_SEMA));
    704   1.66.2.4   nathanw 	}
    705   1.66.2.4   nathanw 	isp_prt(isp, ISP_LOGDEBUG3, "ISR 0x%x SEMA 0x%x", isr, sema);
    706   1.66.2.4   nathanw 	isr &= INT_PENDING_MASK(isp);
    707   1.66.2.4   nathanw 	sema &= BIU_SEMA_LOCK;
    708   1.66.2.4   nathanw 	if (isr == 0 && sema == 0) {
    709   1.66.2.4   nathanw 		return (0);
    710   1.66.2.4   nathanw 	}
    711   1.66.2.4   nathanw 	*isrp = isr;
    712   1.66.2.4   nathanw 	if ((*semap = sema) != 0) {
    713   1.66.2.4   nathanw 		if (IS_2100(isp)) {
    714   1.66.2.4   nathanw 			if (isp_pci_rd_debounced(isp, OUTMAILBOX0, mbp)) {
    715   1.66.2.4   nathanw 				return (0);
    716   1.66.2.4   nathanw 			}
    717   1.66.2.4   nathanw 		} else {
    718   1.66.2.4   nathanw 			*mbp = BXR2(pcs, IspVirt2Off(isp, OUTMAILBOX0));
    719   1.66.2.4   nathanw 		}
    720   1.66.2.4   nathanw 	}
    721   1.66.2.4   nathanw 	return (1);
    722   1.66.2.4   nathanw }
    723   1.66.2.4   nathanw 
    724   1.66.2.4   nathanw #ifndef	ISP_DISABLE_2300_SUPPORT
    725   1.66.2.4   nathanw static int
    726   1.66.2.4   nathanw isp_pci_rd_isr_2300(struct ispsoftc *isp, u_int16_t *isrp,
    727   1.66.2.4   nathanw     u_int16_t *semap, u_int16_t *mbox0p)
    728   1.66.2.4   nathanw {
    729   1.66.2.4   nathanw 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    730   1.66.2.4   nathanw 	u_int32_t r2hisr;
    731   1.66.2.4   nathanw 
    732   1.66.2.5   nathanw 	if (!(BXR2(pcs, IspVirt2Off(isp, BIU_ISR)) & BIU2100_ISR_RISC_INT)) {
    733   1.66.2.5   nathanw 		*isrp = 0;
    734   1.66.2.5   nathanw 		return (0);
    735   1.66.2.5   nathanw 	}
    736   1.66.2.4   nathanw 	r2hisr = bus_space_read_4(pcs->pci_st, pcs->pci_sh,
    737   1.66.2.4   nathanw 	    IspVirt2Off(pcs, BIU_R2HSTSLO));
    738   1.66.2.4   nathanw 	isp_prt(isp, ISP_LOGDEBUG3, "RISC2HOST ISR 0x%x", r2hisr);
    739   1.66.2.4   nathanw 	if ((r2hisr & BIU_R2HST_INTR) == 0) {
    740   1.66.2.4   nathanw 		*isrp = 0;
    741   1.66.2.4   nathanw 		return (0);
    742   1.66.2.4   nathanw 	}
    743   1.66.2.4   nathanw 	switch (r2hisr & BIU_R2HST_ISTAT_MASK) {
    744   1.66.2.4   nathanw 	case ISPR2HST_ROM_MBX_OK:
    745   1.66.2.4   nathanw 	case ISPR2HST_ROM_MBX_FAIL:
    746   1.66.2.4   nathanw 	case ISPR2HST_MBX_OK:
    747   1.66.2.4   nathanw 	case ISPR2HST_MBX_FAIL:
    748   1.66.2.4   nathanw 	case ISPR2HST_ASYNC_EVENT:
    749  1.66.2.11   nathanw 		*isrp = r2hisr & 0xffff;
    750  1.66.2.11   nathanw 		*mbox0p = (r2hisr >> 16);
    751  1.66.2.11   nathanw 		*semap = 1;
    752  1.66.2.11   nathanw 		return (1);
    753   1.66.2.8   nathanw 	case ISPR2HST_RIO_16:
    754  1.66.2.11   nathanw 		*isrp = r2hisr & 0xffff;
    755  1.66.2.11   nathanw 		*mbox0p = ASYNC_RIO1;
    756  1.66.2.11   nathanw 		*semap = 1;
    757  1.66.2.11   nathanw 		return (1);
    758   1.66.2.4   nathanw 	case ISPR2HST_FPOST:
    759  1.66.2.11   nathanw 		*isrp = r2hisr & 0xffff;
    760  1.66.2.11   nathanw 		*mbox0p = ASYNC_CMD_CMPLT;
    761  1.66.2.11   nathanw 		*semap = 1;
    762  1.66.2.11   nathanw 		return (1);
    763   1.66.2.4   nathanw 	case ISPR2HST_FPOST_CTIO:
    764   1.66.2.4   nathanw 		*isrp = r2hisr & 0xffff;
    765  1.66.2.11   nathanw 		*mbox0p = ASYNC_CTIO_DONE;
    766   1.66.2.4   nathanw 		*semap = 1;
    767   1.66.2.4   nathanw 		return (1);
    768   1.66.2.4   nathanw 	case ISPR2HST_RSPQ_UPDATE:
    769   1.66.2.4   nathanw 		*isrp = r2hisr & 0xffff;
    770   1.66.2.4   nathanw 		*mbox0p = 0;
    771   1.66.2.4   nathanw 		*semap = 0;
    772   1.66.2.4   nathanw 		return (1);
    773   1.66.2.4   nathanw 	default:
    774   1.66.2.4   nathanw 		return (0);
    775   1.66.2.4   nathanw 	}
    776   1.66.2.4   nathanw }
    777   1.66.2.4   nathanw #endif
    778   1.66.2.4   nathanw 
    779        1.1       cgd static u_int16_t
    780   1.66.2.1   nathanw isp_pci_rd_reg(struct ispsoftc *isp, int regoff)
    781        1.1       cgd {
    782       1.15    mjacob 	u_int16_t rv;
    783        1.1       cgd 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    784   1.66.2.4   nathanw 	int oldconf = 0;
    785       1.15    mjacob 
    786       1.36    mjacob 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    787        1.1       cgd 		/*
    788       1.15    mjacob 		 * We will assume that someone has paused the RISC processor.
    789        1.1       cgd 		 */
    790   1.66.2.4   nathanw 		oldconf = BXR2(pcs, IspVirt2Off(isp, BIU_CONF1));
    791   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1),
    792   1.66.2.4   nathanw 		    oldconf | BIU_PCI_CONF1_SXP);
    793   1.66.2.4   nathanw 	}
    794   1.66.2.4   nathanw 	rv = BXR2(pcs, IspVirt2Off(isp, regoff));
    795       1.36    mjacob 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    796   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1), oldconf);
    797       1.15    mjacob 	}
    798       1.15    mjacob 	return (rv);
    799        1.1       cgd }
    800        1.1       cgd 
    801        1.1       cgd static void
    802   1.66.2.1   nathanw isp_pci_wr_reg(struct ispsoftc *isp, int regoff, u_int16_t val)
    803        1.1       cgd {
    804        1.1       cgd 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    805   1.66.2.4   nathanw 	int oldconf = 0;
    806       1.36    mjacob 
    807       1.36    mjacob 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    808        1.1       cgd 		/*
    809       1.15    mjacob 		 * We will assume that someone has paused the RISC processor.
    810        1.1       cgd 		 */
    811   1.66.2.4   nathanw 		oldconf = BXR2(pcs, IspVirt2Off(isp, BIU_CONF1));
    812   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1),
    813   1.66.2.4   nathanw 		    oldconf | BIU_PCI_CONF1_SXP);
    814   1.66.2.4   nathanw 	}
    815   1.66.2.4   nathanw 	BXW2(pcs, IspVirt2Off(isp, regoff), val);
    816       1.36    mjacob 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
    817   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1), oldconf);
    818       1.36    mjacob 	}
    819       1.36    mjacob }
    820       1.36    mjacob 
    821       1.52    mjacob #if !(defined(ISP_DISABLE_1080_SUPPORT) && defined(ISP_DISABLE_12160_SUPPORT))
    822       1.36    mjacob static u_int16_t
    823   1.66.2.1   nathanw isp_pci_rd_reg_1080(struct ispsoftc *isp, int regoff)
    824       1.36    mjacob {
    825       1.48    mjacob 	u_int16_t rv, oc = 0;
    826       1.36    mjacob 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    827       1.36    mjacob 
    828   1.66.2.4   nathanw 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK ||
    829   1.66.2.4   nathanw 	    (regoff & _BLK_REG_MASK) == (SXP_BLOCK|SXP_BANK1_SELECT)) {
    830       1.48    mjacob 		u_int16_t tc;
    831       1.36    mjacob 		/*
    832       1.36    mjacob 		 * We will assume that someone has paused the RISC processor.
    833       1.36    mjacob 		 */
    834   1.66.2.4   nathanw 		oc = BXR2(pcs, IspVirt2Off(isp, BIU_CONF1));
    835       1.48    mjacob 		tc = oc & ~BIU_PCI1080_CONF1_DMA;
    836   1.66.2.4   nathanw 		if (regoff & SXP_BANK1_SELECT)
    837   1.66.2.4   nathanw 			tc |= BIU_PCI1080_CONF1_SXP1;
    838   1.66.2.4   nathanw 		else
    839       1.48    mjacob 			tc |= BIU_PCI1080_CONF1_SXP0;
    840   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1), tc);
    841       1.36    mjacob 	} else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
    842   1.66.2.4   nathanw 		oc = BXR2(pcs, IspVirt2Off(isp, BIU_CONF1));
    843   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1),
    844   1.66.2.4   nathanw 		    oc | BIU_PCI1080_CONF1_DMA);
    845   1.66.2.4   nathanw 	}
    846   1.66.2.4   nathanw 	rv = BXR2(pcs, IspVirt2Off(isp, regoff));
    847       1.48    mjacob 	if (oc) {
    848   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1), oc);
    849       1.36    mjacob 	}
    850       1.36    mjacob 	return (rv);
    851       1.36    mjacob }
    852       1.36    mjacob 
    853       1.36    mjacob static void
    854   1.66.2.1   nathanw isp_pci_wr_reg_1080(struct ispsoftc *isp, int regoff, u_int16_t val)
    855       1.36    mjacob {
    856       1.36    mjacob 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
    857   1.66.2.4   nathanw 	int oc = 0;
    858       1.36    mjacob 
    859   1.66.2.4   nathanw 	if ((regoff & _BLK_REG_MASK) == SXP_BLOCK ||
    860   1.66.2.4   nathanw 	    (regoff & _BLK_REG_MASK) == (SXP_BLOCK|SXP_BANK1_SELECT)) {
    861       1.48    mjacob 		u_int16_t tc;
    862       1.36    mjacob 		/*
    863       1.36    mjacob 		 * We will assume that someone has paused the RISC processor.
    864       1.36    mjacob 		 */
    865   1.66.2.4   nathanw 		oc = BXR2(pcs, IspVirt2Off(isp, BIU_CONF1));
    866       1.48    mjacob 		tc = oc & ~BIU_PCI1080_CONF1_DMA;
    867   1.66.2.4   nathanw 		if (regoff & SXP_BANK1_SELECT)
    868   1.66.2.4   nathanw 			tc |= BIU_PCI1080_CONF1_SXP1;
    869   1.66.2.4   nathanw 		else
    870       1.48    mjacob 			tc |= BIU_PCI1080_CONF1_SXP0;
    871   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1), tc);
    872       1.36    mjacob 	} else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
    873   1.66.2.4   nathanw 		oc = BXR2(pcs, IspVirt2Off(isp, BIU_CONF1));
    874   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1),
    875   1.66.2.4   nathanw 		    oc | BIU_PCI1080_CONF1_DMA);
    876   1.66.2.4   nathanw 	}
    877   1.66.2.4   nathanw 	BXW2(pcs, IspVirt2Off(isp, regoff), val);
    878       1.48    mjacob 	if (oc) {
    879   1.66.2.4   nathanw 		BXW2(pcs, IspVirt2Off(isp, BIU_CONF1), oc);
    880       1.15    mjacob 	}
    881        1.1       cgd }
    882       1.36    mjacob #endif
    883        1.1       cgd 
    884       1.13   thorpej static int
    885   1.66.2.1   nathanw isp_pci_mbxdma(struct ispsoftc *isp)
    886        1.1       cgd {
    887       1.53    mjacob 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
    888   1.66.2.7   nathanw 	bus_dma_tag_t dmat = isp->isp_dmatag;
    889       1.53    mjacob 	bus_dma_segment_t sg;
    890       1.13   thorpej 	bus_size_t len;
    891       1.15    mjacob 	fcparam *fcp;
    892       1.53    mjacob 	int rs, i;
    893       1.13   thorpej 
    894       1.43    mjacob 	if (isp->isp_rquest_dma)	/* been here before? */
    895       1.43    mjacob 		return (0);
    896       1.43    mjacob 
    897   1.66.2.2   nathanw 	len = isp->isp_maxcmds * sizeof (XS_T *);
    898       1.53    mjacob 	isp->isp_xflist = (XS_T **) malloc(len, M_DEVBUF, M_WAITOK);
    899       1.43    mjacob 	if (isp->isp_xflist == NULL) {
    900       1.53    mjacob 		isp_prt(isp, ISP_LOGERR, "cannot malloc xflist array");
    901       1.43    mjacob 		return (1);
    902       1.43    mjacob 	}
    903   1.66.2.3   nathanw 	memset(isp->isp_xflist, 0, len);
    904       1.45    mjacob 	len = isp->isp_maxcmds * sizeof (bus_dmamap_t);
    905       1.53    mjacob 	pcs->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_WAITOK);
    906       1.53    mjacob 	if (pcs->pci_xfer_dmap == NULL) {
    907       1.53    mjacob 		free(isp->isp_xflist, M_DEVBUF);
    908       1.53    mjacob 		isp->isp_xflist = NULL;
    909       1.53    mjacob 		isp_prt(isp, ISP_LOGERR, "cannot malloc dma map array");
    910       1.53    mjacob 		return (1);
    911       1.53    mjacob 	}
    912       1.53    mjacob 	for (i = 0; i < isp->isp_maxcmds; i++) {
    913       1.59   thorpej 		if (bus_dmamap_create(dmat, MAXPHYS, (MAXPHYS / PAGE_SIZE) + 1,
    914       1.53    mjacob 		    MAXPHYS, 0, BUS_DMA_NOWAIT, &pcs->pci_xfer_dmap[i])) {
    915       1.53    mjacob 			isp_prt(isp, ISP_LOGERR, "cannot create dma maps");
    916       1.53    mjacob 			break;
    917       1.53    mjacob 		}
    918       1.53    mjacob 	}
    919       1.53    mjacob 	if (i < isp->isp_maxcmds) {
    920       1.53    mjacob 		while (--i >= 0) {
    921       1.53    mjacob 			bus_dmamap_destroy(dmat, pcs->pci_xfer_dmap[i]);
    922       1.53    mjacob 		}
    923       1.53    mjacob 		free(isp->isp_xflist, M_DEVBUF);
    924       1.53    mjacob 		free(pcs->pci_xfer_dmap, M_DEVBUF);
    925       1.53    mjacob 		isp->isp_xflist = NULL;
    926       1.53    mjacob 		pcs->pci_xfer_dmap = NULL;
    927       1.45    mjacob 		return (1);
    928       1.45    mjacob 	}
    929       1.43    mjacob 
    930       1.13   thorpej 	/*
    931       1.13   thorpej 	 * Allocate and map the request queue.
    932       1.13   thorpej 	 */
    933       1.53    mjacob 	len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
    934       1.59   thorpej 	if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
    935       1.59   thorpej 			     BUS_DMA_NOWAIT) ||
    936   1.66.2.7   nathanw 	    bus_dmamem_map(isp->isp_dmatag, &sg, rs, len,
    937       1.53    mjacob 	    (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    938       1.53    mjacob 		goto dmafail;
    939       1.53    mjacob 	}
    940       1.53    mjacob 
    941       1.53    mjacob 	if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    942   1.66.2.7   nathanw 	    &isp->isp_rqdmap) || bus_dmamap_load(dmat, isp->isp_rqdmap,
    943   1.66.2.7   nathanw 	    (caddr_t)isp->isp_rquest, len, NULL,
    944       1.53    mjacob 	    BUS_DMA_NOWAIT)) {
    945       1.53    mjacob 		goto dmafail;
    946       1.53    mjacob 	}
    947   1.66.2.7   nathanw 	isp->isp_rquest_dma = isp->isp_rqdmap->dm_segs[0].ds_addr;
    948       1.13   thorpej 
    949       1.13   thorpej 	/*
    950       1.13   thorpej 	 * Allocate and map the result queue.
    951       1.13   thorpej 	 */
    952       1.53    mjacob 	len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp));
    953       1.59   thorpej 	if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
    954       1.59   thorpej 			     BUS_DMA_NOWAIT) ||
    955       1.53    mjacob 	    bus_dmamem_map(dmat, &sg, rs, len, (caddr_t *)&isp->isp_result,
    956       1.53    mjacob 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    957       1.53    mjacob 		goto dmafail;
    958       1.53    mjacob 	}
    959       1.53    mjacob 	if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    960   1.66.2.7   nathanw 	    &isp->isp_rsdmap) || bus_dmamap_load(isp->isp_dmatag,
    961   1.66.2.7   nathanw 	    isp->isp_rsdmap, (caddr_t)isp->isp_result, len, NULL,
    962       1.53    mjacob 	    BUS_DMA_NOWAIT)) {
    963       1.53    mjacob 		goto dmafail;
    964       1.53    mjacob 	}
    965   1.66.2.7   nathanw 	isp->isp_result_dma = isp->isp_rsdmap->dm_segs[0].ds_addr;
    966        1.1       cgd 
    967       1.41    mjacob 	if (IS_SCSI(isp)) {
    968       1.15    mjacob 		return (0);
    969       1.15    mjacob 	}
    970        1.1       cgd 
    971       1.15    mjacob 	fcp = isp->isp_param;
    972       1.15    mjacob 	len = ISP2100_SCRLEN;
    973       1.59   thorpej 	if (bus_dmamem_alloc(dmat, len, PAGE_SIZE, 0, &sg, 1, &rs,
    974       1.59   thorpej 			     BUS_DMA_NOWAIT) ||
    975       1.53    mjacob 	    bus_dmamem_map(dmat, &sg, rs, len, (caddr_t *)&fcp->isp_scratch,
    976       1.53    mjacob 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    977       1.53    mjacob 		goto dmafail;
    978       1.53    mjacob 	}
    979       1.53    mjacob 	if (bus_dmamap_create(dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
    980   1.66.2.7   nathanw 	    &isp->isp_scdmap) || bus_dmamap_load(dmat,
    981   1.66.2.7   nathanw 	    isp->isp_scdmap, (caddr_t)fcp->isp_scratch, len, NULL,
    982       1.53    mjacob 	    BUS_DMA_NOWAIT)) {
    983       1.53    mjacob 		goto dmafail;
    984       1.53    mjacob 	}
    985   1.66.2.7   nathanw 	fcp->isp_scdma = isp->isp_scdmap->dm_segs[0].ds_addr;
    986       1.13   thorpej 	return (0);
    987       1.53    mjacob dmafail:
    988       1.53    mjacob 	isp_prt(isp, ISP_LOGERR, "mailbox dma setup failure");
    989       1.53    mjacob 	for (i = 0; i < isp->isp_maxcmds; i++) {
    990       1.53    mjacob 		bus_dmamap_destroy(dmat, pcs->pci_xfer_dmap[i]);
    991       1.53    mjacob 	}
    992       1.53    mjacob 	free(isp->isp_xflist, M_DEVBUF);
    993       1.53    mjacob 	free(pcs->pci_xfer_dmap, M_DEVBUF);
    994       1.53    mjacob 	isp->isp_xflist = NULL;
    995       1.53    mjacob 	pcs->pci_xfer_dmap = NULL;
    996       1.53    mjacob 	return (1);
    997        1.1       cgd }
    998        1.1       cgd 
    999        1.1       cgd static int
   1000   1.66.2.1   nathanw isp_pci_dmasetup(struct ispsoftc *isp, struct scsipi_xfer *xs, ispreq_t *rq,
   1001   1.66.2.7   nathanw     u_int16_t *nxtip, u_int16_t optr)
   1002        1.1       cgd {
   1003       1.53    mjacob 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
   1004       1.52    mjacob 	bus_dmamap_t dmap;
   1005   1.66.2.7   nathanw 	u_int16_t starti = isp->isp_reqidx, nxti = *nxtip;
   1006   1.66.2.7   nathanw 	ispreq_t *qep;
   1007       1.17    mjacob 	int segcnt, seg, error, ovseg, seglim, drq;
   1008        1.1       cgd 
   1009   1.66.2.7   nathanw 	qep = (ispreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, starti);
   1010       1.53    mjacob 	dmap = pcs->pci_xfer_dmap[isp_handle_index(rq->req_handle)];
   1011        1.1       cgd 	if (xs->datalen == 0) {
   1012        1.1       cgd 		rq->req_seg_count = 1;
   1013       1.26    mjacob 		goto mbxsync;
   1014        1.1       cgd 	}
   1015       1.42   thorpej 	if (xs->xs_control & XS_CTL_DATA_IN) {
   1016       1.17    mjacob 		drq = REQFLAG_DATA_IN;
   1017        1.1       cgd 	} else {
   1018       1.17    mjacob 		drq = REQFLAG_DATA_OUT;
   1019        1.1       cgd 	}
   1020        1.1       cgd 
   1021       1.41    mjacob 	if (IS_FC(isp)) {
   1022       1.15    mjacob 		seglim = ISP_RQDSEG_T2;
   1023       1.15    mjacob 		((ispreqt2_t *)rq)->req_totalcnt = xs->datalen;
   1024       1.17    mjacob 		((ispreqt2_t *)rq)->req_flags |= drq;
   1025       1.15    mjacob 	} else {
   1026       1.17    mjacob 		rq->req_flags |= drq;
   1027       1.51    mjacob 		if (XS_CDBLEN(xs) > 12) {
   1028       1.51    mjacob 			seglim = 0;
   1029       1.51    mjacob 		} else {
   1030       1.51    mjacob 			seglim = ISP_RQDSEG;
   1031       1.51    mjacob 		}
   1032       1.15    mjacob 	}
   1033   1.66.2.7   nathanw 	error = bus_dmamap_load(isp->isp_dmatag, dmap, xs->data, xs->datalen,
   1034   1.66.2.1   nathanw 	    NULL, ((xs->xs_control & XS_CTL_NOSLEEP) ?
   1035   1.66.2.3   nathanw 	    BUS_DMA_NOWAIT : BUS_DMA_WAITOK) | BUS_DMA_STREAMING |
   1036   1.66.2.3   nathanw 	    ((xs->xs_control & XS_CTL_DATA_IN) ? BUS_DMA_READ : BUS_DMA_WRITE));
   1037       1.21    mjacob 	if (error) {
   1038  1.66.2.11   nathanw 		isp_prt(isp, ISP_LOGWARN, "unable to load dma (%d)", error);
   1039       1.21    mjacob 		XS_SETERR(xs, HBA_BOTCH);
   1040  1.66.2.10   nathanw 		if (error == EAGAIN || error == ENOMEM)
   1041  1.66.2.10   nathanw 			return (CMD_EAGAIN);
   1042  1.66.2.10   nathanw 		else
   1043  1.66.2.10   nathanw 			return (CMD_COMPLETE);
   1044       1.21    mjacob 	}
   1045       1.13   thorpej 
   1046       1.13   thorpej 	segcnt = dmap->dm_nsegs;
   1047       1.13   thorpej 
   1048       1.57    mjacob 	isp_prt(isp, ISP_LOGDEBUG2, "%d byte %s %p in %d segs",
   1049       1.57    mjacob 	    xs->datalen, (xs->xs_control & XS_CTL_DATA_IN)? "read to" :
   1050       1.57    mjacob 	    "write from", xs->data, segcnt);
   1051       1.57    mjacob 
   1052       1.13   thorpej 	for (seg = 0, rq->req_seg_count = 0;
   1053       1.56    mjacob 	    seglim && seg < segcnt && rq->req_seg_count < seglim;
   1054       1.44    mjacob 	    seg++, rq->req_seg_count++) {
   1055       1.41    mjacob 		if (IS_FC(isp)) {
   1056       1.15    mjacob 			ispreqt2_t *rq2 = (ispreqt2_t *)rq;
   1057       1.15    mjacob 			rq2->req_dataseg[rq2->req_seg_count].ds_count =
   1058       1.15    mjacob 			    dmap->dm_segs[seg].ds_len;
   1059       1.15    mjacob 			rq2->req_dataseg[rq2->req_seg_count].ds_base =
   1060       1.15    mjacob 			    dmap->dm_segs[seg].ds_addr;
   1061       1.15    mjacob 		} else {
   1062       1.15    mjacob 			rq->req_dataseg[rq->req_seg_count].ds_count =
   1063       1.15    mjacob 			    dmap->dm_segs[seg].ds_len;
   1064       1.15    mjacob 			rq->req_dataseg[rq->req_seg_count].ds_base =
   1065       1.15    mjacob 			    dmap->dm_segs[seg].ds_addr;
   1066       1.15    mjacob 		}
   1067       1.63    mjacob 		isp_prt(isp, ISP_LOGDEBUG2, "seg0.[%d]={0x%lx,%lu}",
   1068       1.63    mjacob 		    rq->req_seg_count, (long) dmap->dm_segs[seg].ds_addr,
   1069       1.63    mjacob 		    (unsigned long) dmap->dm_segs[seg].ds_len);
   1070        1.1       cgd 	}
   1071        1.1       cgd 
   1072   1.66.2.7   nathanw 	if (seg == segcnt) {
   1073       1.26    mjacob 		goto dmasync;
   1074   1.66.2.7   nathanw 	}
   1075        1.1       cgd 
   1076        1.1       cgd 	do {
   1077   1.66.2.7   nathanw 		u_int16_t onxti;
   1078   1.66.2.7   nathanw 		ispcontreq_t *crq, *cqe, local;
   1079   1.66.2.7   nathanw 
   1080   1.66.2.7   nathanw 		crq = &local;
   1081   1.66.2.7   nathanw 
   1082   1.66.2.7   nathanw 		cqe = (ispcontreq_t *) ISP_QUEUE_ENTRY(isp->isp_rquest, nxti);
   1083   1.66.2.7   nathanw 		onxti = nxti;
   1084   1.66.2.7   nathanw 		nxti = ISP_NXT_QENTRY(onxti, RQUEST_QUEUE_LEN(isp));
   1085   1.66.2.7   nathanw 		if (nxti == optr) {
   1086  1.66.2.11   nathanw 			isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGERR, "Request Queue Overflow++");
   1087   1.66.2.7   nathanw 			bus_dmamap_unload(isp->isp_dmatag, dmap);
   1088       1.21    mjacob 			XS_SETERR(xs, HBA_BOTCH);
   1089       1.52    mjacob 			return (CMD_EAGAIN);
   1090        1.1       cgd 		}
   1091        1.1       cgd 		rq->req_header.rqs_entry_count++;
   1092   1.66.2.3   nathanw 		memset((void *)crq, 0, sizeof (*crq));
   1093        1.1       cgd 		crq->req_header.rqs_entry_count = 1;
   1094        1.1       cgd 		crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
   1095       1.13   thorpej 
   1096       1.13   thorpej 		for (ovseg = 0; seg < segcnt && ovseg < ISP_CDSEG;
   1097       1.13   thorpej 		    rq->req_seg_count++, seg++, ovseg++) {
   1098       1.13   thorpej 			crq->req_dataseg[ovseg].ds_count =
   1099       1.13   thorpej 			    dmap->dm_segs[seg].ds_len;
   1100       1.13   thorpej 			crq->req_dataseg[ovseg].ds_base =
   1101       1.13   thorpej 			    dmap->dm_segs[seg].ds_addr;
   1102       1.63    mjacob 			isp_prt(isp, ISP_LOGDEBUG2, "seg%d.[%d]={0x%lx,%lu}",
   1103       1.57    mjacob 			    rq->req_header.rqs_entry_count - 1,
   1104       1.63    mjacob 			    rq->req_seg_count, (long)dmap->dm_segs[seg].ds_addr,
   1105       1.63    mjacob 			    (unsigned long) dmap->dm_segs[seg].ds_len);
   1106        1.1       cgd 		}
   1107   1.66.2.7   nathanw 		isp_put_cont_req(isp, crq, cqe);
   1108   1.66.2.7   nathanw 		MEMORYBARRIER(isp, SYNC_REQUEST, onxti, QENTRY_LEN);
   1109       1.13   thorpej 	} while (seg < segcnt);
   1110       1.56    mjacob 
   1111       1.13   thorpej 
   1112       1.26    mjacob dmasync:
   1113   1.66.2.7   nathanw 	bus_dmamap_sync(isp->isp_dmatag, dmap, 0, dmap->dm_mapsize,
   1114       1.42   thorpej 	    (xs->xs_control & XS_CTL_DATA_IN) ?  BUS_DMASYNC_PREREAD :
   1115       1.30    mjacob 	    BUS_DMASYNC_PREWRITE);
   1116       1.26    mjacob 
   1117       1.26    mjacob mbxsync:
   1118   1.66.2.7   nathanw 	switch (rq->req_header.rqs_entry_type) {
   1119   1.66.2.7   nathanw 	case RQSTYPE_REQUEST:
   1120   1.66.2.7   nathanw 		isp_put_request(isp, rq, qep);
   1121   1.66.2.7   nathanw 		break;
   1122   1.66.2.7   nathanw 	case RQSTYPE_CMDONLY:
   1123   1.66.2.7   nathanw 		isp_put_extended_request(isp, (ispextreq_t *)rq,
   1124   1.66.2.7   nathanw 		    (ispextreq_t *)qep);
   1125   1.66.2.7   nathanw 		break;
   1126   1.66.2.7   nathanw 	case RQSTYPE_T2RQS:
   1127   1.66.2.7   nathanw 		isp_put_request_t2(isp, (ispreqt2_t *) rq, (ispreqt2_t *) qep);
   1128   1.66.2.7   nathanw 		break;
   1129   1.66.2.7   nathanw 	}
   1130   1.66.2.7   nathanw 	*nxtip = nxti;
   1131       1.30    mjacob 	return (CMD_QUEUED);
   1132       1.26    mjacob }
   1133       1.26    mjacob 
   1134       1.26    mjacob static int
   1135   1.66.2.1   nathanw isp_pci_intr(void *arg)
   1136       1.26    mjacob {
   1137   1.66.2.4   nathanw 	u_int16_t isr, sema, mbox;
   1138   1.66.2.4   nathanw 	struct ispsoftc *isp = arg;
   1139   1.66.2.4   nathanw 
   1140   1.66.2.4   nathanw 	isp->isp_intcnt++;
   1141   1.66.2.4   nathanw 	if (ISP_READ_ISR(isp, &isr, &sema, &mbox) == 0) {
   1142   1.66.2.4   nathanw 		isp->isp_intbogus++;
   1143   1.66.2.4   nathanw 		return (0);
   1144   1.66.2.4   nathanw 	} else {
   1145   1.66.2.4   nathanw 		isp->isp_osinfo.onintstack = 1;
   1146   1.66.2.4   nathanw 		isp_intr(isp, isr, sema, mbox);
   1147   1.66.2.4   nathanw 		isp->isp_osinfo.onintstack = 0;
   1148   1.66.2.4   nathanw 		return (1);
   1149   1.66.2.4   nathanw 	}
   1150       1.13   thorpej }
   1151       1.13   thorpej 
   1152       1.13   thorpej static void
   1153   1.66.2.1   nathanw isp_pci_dmateardown(struct ispsoftc *isp, XS_T *xs, u_int16_t handle)
   1154       1.13   thorpej {
   1155       1.53    mjacob 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
   1156       1.53    mjacob 	bus_dmamap_t dmap = pcs->pci_xfer_dmap[isp_handle_index(handle)];
   1157   1.66.2.7   nathanw 	bus_dmamap_sync(isp->isp_dmatag, dmap, 0, dmap->dm_mapsize,
   1158       1.42   thorpej 	    xs->xs_control & XS_CTL_DATA_IN ?
   1159       1.13   thorpej 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
   1160   1.66.2.7   nathanw 	bus_dmamap_unload(isp->isp_dmatag, dmap);
   1161        1.1       cgd }
   1162        1.1       cgd 
   1163        1.1       cgd static void
   1164   1.66.2.1   nathanw isp_pci_reset1(struct ispsoftc *isp)
   1165        1.1       cgd {
   1166        1.1       cgd 	/* Make sure the BIOS is disabled */
   1167        1.1       cgd 	isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS);
   1168   1.66.2.8   nathanw 	if (isp->isp_osinfo.no_mbox_ints == 0) {
   1169   1.66.2.8   nathanw 		ENABLE_INTS(isp);
   1170   1.66.2.8   nathanw 	}
   1171   1.66.2.8   nathanw 
   1172       1.15    mjacob }
   1173       1.15    mjacob 
   1174       1.15    mjacob static void
   1175   1.66.2.1   nathanw isp_pci_dumpregs(struct ispsoftc *isp, const char *msg)
   1176       1.15    mjacob {
   1177       1.53    mjacob 	struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
   1178       1.53    mjacob 	if (msg)
   1179       1.53    mjacob 		printf("%s: %s\n", isp->isp_name, msg);
   1180       1.53    mjacob 	if (IS_SCSI(isp))
   1181       1.53    mjacob 		printf("    biu_conf1=%x", ISP_READ(isp, BIU_CONF1));
   1182       1.53    mjacob 	else
   1183       1.53    mjacob 		printf("    biu_csr=%x", ISP_READ(isp, BIU2100_CSR));
   1184       1.53    mjacob 	printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp, BIU_ICR),
   1185       1.53    mjacob 	    ISP_READ(isp, BIU_ISR), ISP_READ(isp, BIU_SEMA));
   1186       1.53    mjacob 	printf("risc_hccr=%x\n", ISP_READ(isp, HCCR));
   1187       1.53    mjacob 
   1188       1.53    mjacob 
   1189       1.53    mjacob 	if (IS_SCSI(isp)) {
   1190       1.53    mjacob 		ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
   1191       1.53    mjacob 		printf("    cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n",
   1192       1.53    mjacob 			ISP_READ(isp, CDMA_CONF), ISP_READ(isp, CDMA_STATUS),
   1193       1.53    mjacob 			ISP_READ(isp, CDMA_FIFO_STS));
   1194       1.53    mjacob 		printf("    ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n",
   1195       1.53    mjacob 			ISP_READ(isp, DDMA_CONF), ISP_READ(isp, DDMA_STATUS),
   1196       1.53    mjacob 			ISP_READ(isp, DDMA_FIFO_STS));
   1197       1.53    mjacob 		printf("    sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n",
   1198       1.53    mjacob 			ISP_READ(isp, SXP_INTERRUPT),
   1199       1.53    mjacob 			ISP_READ(isp, SXP_GROSS_ERR),
   1200       1.53    mjacob 			ISP_READ(isp, SXP_PINS_CTRL));
   1201       1.53    mjacob 		ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
   1202       1.53    mjacob 	}
   1203       1.53    mjacob 	printf("    mbox regs: %x %x %x %x %x\n",
   1204       1.53    mjacob 	    ISP_READ(isp, OUTMAILBOX0), ISP_READ(isp, OUTMAILBOX1),
   1205       1.53    mjacob 	    ISP_READ(isp, OUTMAILBOX2), ISP_READ(isp, OUTMAILBOX3),
   1206       1.53    mjacob 	    ISP_READ(isp, OUTMAILBOX4));
   1207       1.53    mjacob 	printf("    PCI Status Command/Status=%x\n",
   1208       1.53    mjacob 	    pci_conf_read(pcs->pci_pc, pcs->pci_tag, PCI_COMMAND_STATUS_REG));
   1209        1.1       cgd }
   1210