1 /* $NetBSD: isp_pci.c,v 1.109 2009/06/25 23:44:02 mjacob Exp $ */
3 * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
6 * Additional Copyright (C) 2000-2007 by Matthew Jacob
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
36 * 24XX 4Gb material support provided by MetrumRG Associates.
37 * Many thanks are due to them.
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: isp_pci.c,v 1.109 2009/06/25 23:44:02 mjacob Exp $");
43 #include <dev/ic/isp_netbsd.h>
44 #include <dev/pci/pcireg.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pcidevs.h>
47 #include <uvm/uvm_extern.h>
48 #include <sys/reboot.h>
50 static uint32_t isp_pci_rd_reg(struct ispsoftc
*, int);
51 static void isp_pci_wr_reg(struct ispsoftc
*, int, uint32_t);
52 #if !(defined(ISP_DISABLE_1080_SUPPORT) && defined(ISP_DISABLE_12160_SUPPORT))
53 static uint32_t isp_pci_rd_reg_1080(struct ispsoftc
*, int);
54 static void isp_pci_wr_reg_1080(struct ispsoftc
*, int, uint32_t);
56 #if !defined(ISP_DISABLE_2100_SUPPORT) && \
57 !defined(ISP_DISABLE_2200_SUPPORT) && \
58 !defined(ISP_DISABLE_1020_SUPPORT) && \
59 !defined(ISP_DISABLE_1080_SUPPORT) && \
60 !defined(ISP_DISABLE_12160_SUPPORT)
62 isp_pci_rd_isr(struct ispsoftc
*, uint32_t *, uint16_t *, uint16_t *);
64 #if !(defined(ISP_DISABLE_2300_SUPPORT) && defined(ISP_DISABLE_2322_SUPPORT))
66 isp_pci_rd_isr_2300(struct ispsoftc
*, uint32_t *, uint16_t *, uint16_t *);
68 #if !defined(ISP_DISABLE_2400_SUPPORT)
69 static uint32_t isp_pci_rd_reg_2400(struct ispsoftc
*, int);
70 static void isp_pci_wr_reg_2400(struct ispsoftc
*, int, uint32_t);
72 isp_pci_rd_isr_2400(struct ispsoftc
*, uint32_t *, uint16_t *, uint16_t *);
74 static int isp_pci_mbxdma(struct ispsoftc
*);
75 static int isp_pci_dmasetup(struct ispsoftc
*, XS_T
*, void *);
76 static void isp_pci_dmateardown(struct ispsoftc
*, XS_T
*, uint32_t);
77 static void isp_pci_reset0(struct ispsoftc
*);
78 static void isp_pci_reset1(struct ispsoftc
*);
79 static void isp_pci_dumpregs(struct ispsoftc
*, const char *);
80 static int isp_pci_intr(void *);
82 #if defined(ISP_DISABLE_1020_SUPPORT) || defined(ISP_DISABLE_FW)
83 #define ISP_1040_RISC_CODE NULL
85 #define ISP_1040_RISC_CODE (const uint16_t *) isp_1040_risc_code
86 #include <dev/microcode/isp/asm_1040.h>
89 #if defined(ISP_DISABLE_1080_SUPPORT) || defined(ISP_DISABLE_FW)
90 #define ISP_1080_RISC_CODE NULL
92 #define ISP_1080_RISC_CODE (const uint16_t *) isp_1080_risc_code
93 #include <dev/microcode/isp/asm_1080.h>
96 #if defined(ISP_DISABLE_12160_SUPPORT) || defined(ISP_DISABLE_FW)
97 #define ISP_12160_RISC_CODE NULL
99 #define ISP_12160_RISC_CODE (const uint16_t *) isp_12160_risc_code
100 #include <dev/microcode/isp/asm_12160.h>
103 #if defined(ISP_DISABLE_2100_SUPPORT) || defined(ISP_DISABLE_FW)
104 #define ISP_2100_RISC_CODE NULL
106 #define ISP_2100_RISC_CODE (const uint16_t *) isp_2100_risc_code
107 #include <dev/microcode/isp/asm_2100.h>
110 #if defined(ISP_DISABLE_2200_SUPPORT) || defined(ISP_DISABLE_FW)
111 #define ISP_2200_RISC_CODE NULL
113 #define ISP_2200_RISC_CODE (const uint16_t *) isp_2200_risc_code
114 #include <dev/microcode/isp/asm_2200.h>
117 #if defined(ISP_DISABLE_2300_SUPPORT) || defined(ISP_DISABLE_FW)
118 #define ISP_2300_RISC_CODE NULL
120 #define ISP_2300_RISC_CODE (const uint16_t *) isp_2300_risc_code
121 #include <dev/microcode/isp/asm_2300.h>
123 #if defined(ISP_DISABLE_2322_SUPPORT) || defined(ISP_DISABLE_FW)
124 #define ISP_2322_RISC_CODE NULL
126 #define ISP_2322_RISC_CODE (const uint16_t *) isp_2322_risc_code
127 #include <dev/microcode/isp/asm_2322.h>
130 #if defined(ISP_DISABLE_2400_SUPPORT) || defined(ISP_DISABLE_FW)
131 #define ISP_2400_RISC_CODE NULL
132 #define ISP_2500_RISC_CODE NULL
134 #define ISP_2400_RISC_CODE (const uint32_t *) isp_2400_risc_code
135 #define ISP_2500_RISC_CODE (const uint32_t *) isp_2500_risc_code
136 #include <dev/microcode/isp/asm_2400.h>
137 #include <dev/microcode/isp/asm_2500.h>
140 #ifndef ISP_DISABLE_1020_SUPPORT
141 static struct ispmdvec mdvec
= {
152 BIU_BURST_ENABLE
|BIU_PCI_CONF1_FIFO_64
,
157 #ifndef ISP_DISABLE_1080_SUPPORT
158 static struct ispmdvec mdvec_1080
= {
169 BIU_BURST_ENABLE
|BIU_PCI_CONF1_FIFO_64
,
174 #ifndef ISP_DISABLE_12160_SUPPORT
175 static struct ispmdvec mdvec_12160
= {
186 BIU_BURST_ENABLE
|BIU_PCI_CONF1_FIFO_64
,
191 #ifndef ISP_DISABLE_2100_SUPPORT
192 static struct ispmdvec mdvec_2100
= {
208 #ifndef ISP_DISABLE_2200_SUPPORT
209 static struct ispmdvec mdvec_2200
= {
225 #ifndef ISP_DISABLE_2300_SUPPORT
226 static struct ispmdvec mdvec_2300
= {
242 #ifndef ISP_DISABLE_2322_SUPPORT
243 static struct ispmdvec mdvec_2322
= {
259 #ifndef ISP_DISABLE_2400_SUPPORT
260 static struct ispmdvec mdvec_2400
= {
274 static struct ispmdvec mdvec_2500
= {
290 #ifndef PCI_VENDOR_QLOGIC
291 #define PCI_VENDOR_QLOGIC 0x1077
294 #ifndef PCI_PRODUCT_QLOGIC_ISP1020
295 #define PCI_PRODUCT_QLOGIC_ISP1020 0x1020
298 #ifndef PCI_PRODUCT_QLOGIC_ISP1080
299 #define PCI_PRODUCT_QLOGIC_ISP1080 0x1080
302 #ifndef PCI_PRODUCT_QLOGIC_ISP1240
303 #define PCI_PRODUCT_QLOGIC_ISP1240 0x1240
306 #ifndef PCI_PRODUCT_QLOGIC_ISP1280
307 #define PCI_PRODUCT_QLOGIC_ISP1280 0x1280
310 #ifndef PCI_PRODUCT_QLOGIC_ISP10160
311 #define PCI_PRODUCT_QLOGIC_ISP10160 0x1016
314 #ifndef PCI_PRODUCT_QLOGIC_ISP12160
315 #define PCI_PRODUCT_QLOGIC_ISP12160 0x1216
318 #ifndef PCI_PRODUCT_QLOGIC_ISP2100
319 #define PCI_PRODUCT_QLOGIC_ISP2100 0x2100
322 #ifndef PCI_PRODUCT_QLOGIC_ISP2200
323 #define PCI_PRODUCT_QLOGIC_ISP2200 0x2200
326 #ifndef PCI_PRODUCT_QLOGIC_ISP2300
327 #define PCI_PRODUCT_QLOGIC_ISP2300 0x2300
330 #ifndef PCI_PRODUCT_QLOGIC_ISP2312
331 #define PCI_PRODUCT_QLOGIC_ISP2312 0x2312
334 #ifndef PCI_PRODUCT_QLOGIC_ISP2322
335 #define PCI_PRODUCT_QLOGIC_ISP2322 0x2322
338 #ifndef PCI_PRODUCT_QLOGIC_ISP2422
339 #define PCI_PRODUCT_QLOGIC_ISP2422 0x2422
342 #ifndef PCI_PRODUCT_QLOGIC_ISP2432
343 #define PCI_PRODUCT_QLOGIC_ISP2432 0x2432
346 #ifndef PCI_PRODUCT_QLOGIC_ISP2532
347 #define PCI_PRODUCT_QLOGIC_ISP2532 0x2532
350 #ifndef PCI_PRODUCT_QLOGIC_ISP6312
351 #define PCI_PRODUCT_QLOGIC_ISP6312 0x6312
354 #ifndef PCI_PRODUCT_QLOGIC_ISP6322
355 #define PCI_PRODUCT_QLOGIC_ISP6322 0x6322
359 #define PCI_QLOGIC_ISP ((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
361 #define PCI_QLOGIC_ISP1080 \
362 ((PCI_PRODUCT_QLOGIC_ISP1080 << 16) | PCI_VENDOR_QLOGIC)
364 #define PCI_QLOGIC_ISP10160 \
365 ((PCI_PRODUCT_QLOGIC_ISP10160 << 16) | PCI_VENDOR_QLOGIC)
367 #define PCI_QLOGIC_ISP12160 \
368 ((PCI_PRODUCT_QLOGIC_ISP12160 << 16) | PCI_VENDOR_QLOGIC)
370 #define PCI_QLOGIC_ISP1240 \
371 ((PCI_PRODUCT_QLOGIC_ISP1240 << 16) | PCI_VENDOR_QLOGIC)
373 #define PCI_QLOGIC_ISP1280 \
374 ((PCI_PRODUCT_QLOGIC_ISP1280 << 16) | PCI_VENDOR_QLOGIC)
376 #define PCI_QLOGIC_ISP2100 \
377 ((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC)
379 #define PCI_QLOGIC_ISP2200 \
380 ((PCI_PRODUCT_QLOGIC_ISP2200 << 16) | PCI_VENDOR_QLOGIC)
382 #define PCI_QLOGIC_ISP2300 \
383 ((PCI_PRODUCT_QLOGIC_ISP2300 << 16) | PCI_VENDOR_QLOGIC)
385 #define PCI_QLOGIC_ISP2312 \
386 ((PCI_PRODUCT_QLOGIC_ISP2312 << 16) | PCI_VENDOR_QLOGIC)
388 #define PCI_QLOGIC_ISP2322 \
389 ((PCI_PRODUCT_QLOGIC_ISP2322 << 16) | PCI_VENDOR_QLOGIC)
391 #define PCI_QLOGIC_ISP2422 \
392 ((PCI_PRODUCT_QLOGIC_ISP2422 << 16) | PCI_VENDOR_QLOGIC)
394 #define PCI_QLOGIC_ISP2432 \
395 ((PCI_PRODUCT_QLOGIC_ISP2432 << 16) | PCI_VENDOR_QLOGIC)
397 #define PCI_QLOGIC_ISP2532 \
398 ((PCI_PRODUCT_QLOGIC_ISP2532 << 16) | PCI_VENDOR_QLOGIC)
400 #define PCI_QLOGIC_ISP6312 \
401 ((PCI_PRODUCT_QLOGIC_ISP6312 << 16) | PCI_VENDOR_QLOGIC)
403 #define PCI_QLOGIC_ISP6322 \
404 ((PCI_PRODUCT_QLOGIC_ISP6322 << 16) | PCI_VENDOR_QLOGIC)
406 #define IO_MAP_REG 0x10
407 #define MEM_MAP_REG 0x14
408 #define PCIR_ROMADDR 0x30
410 #define PCI_DFLT_LTNCY 0x40
411 #define PCI_DFLT_LNSZ 0x10
413 static int isp_pci_probe(device_t
, cfdata_t
, void *);
414 static void isp_pci_attach(device_t
, device_t
, void *);
416 struct isp_pcisoftc
{
417 struct ispsoftc pci_isp
;
418 pci_chipset_tag_t pci_pc
;
420 bus_space_tag_t pci_st
;
421 bus_space_handle_t pci_sh
;
422 bus_dmamap_t
*pci_xfer_dmap
;
424 int16_t pci_poff
[_NREG_BLKS
];
427 CFATTACH_DECL_NEW(isp_pci
, sizeof (struct isp_pcisoftc
),
428 isp_pci_probe
, isp_pci_attach
, NULL
, NULL
);
431 isp_pci_probe(device_t parent
, cfdata_t match
, void *aux
)
433 struct pci_attach_args
*pa
= aux
;
435 #ifndef ISP_DISABLE_1020_SUPPORT
439 #ifndef ISP_DISABLE_1080_SUPPORT
440 case PCI_QLOGIC_ISP1080
:
441 case PCI_QLOGIC_ISP1240
:
442 case PCI_QLOGIC_ISP1280
:
445 #ifndef ISP_DISABLE_12160_SUPPORT
446 case PCI_QLOGIC_ISP10160
:
447 case PCI_QLOGIC_ISP12160
:
450 #ifndef ISP_DISABLE_2100_SUPPORT
451 case PCI_QLOGIC_ISP2100
:
454 #ifndef ISP_DISABLE_2200_SUPPORT
455 case PCI_QLOGIC_ISP2200
:
458 #ifndef ISP_DISABLE_2300_SUPPORT
459 case PCI_QLOGIC_ISP2300
:
460 case PCI_QLOGIC_ISP2312
:
461 case PCI_QLOGIC_ISP6312
:
463 #ifndef ISP_DISABLE_2322_SUPPORT
464 case PCI_QLOGIC_ISP2322
:
465 case PCI_QLOGIC_ISP6322
:
468 #ifndef ISP_DISABLE_2400_SUPPORT
469 case PCI_QLOGIC_ISP2422
:
470 case PCI_QLOGIC_ISP2432
:
471 case PCI_QLOGIC_ISP2532
:
480 isp_pci_attach(device_t parent
, device_t self
, void *aux
)
482 static const char nomem
[] = "\n%s: no mem for sdparam table\n";
483 uint32_t data
, rev
, linesz
= PCI_DFLT_LNSZ
;
484 struct pci_attach_args
*pa
= aux
;
485 struct isp_pcisoftc
*pcs
= device_private(self
);
486 struct ispsoftc
*isp
= &pcs
->pci_isp
;
487 bus_space_tag_t st
, iot
, memt
;
488 bus_space_handle_t sh
, ioh
, memh
;
489 pci_intr_handle_t ih
;
493 int ioh_valid
, memh_valid
;
496 isp
->isp_osinfo
.dev
= self
;
498 ioh_valid
= (pci_mapreg_map(pa
, IO_MAP_REG
,
499 PCI_MAPREG_TYPE_IO
, 0,
500 &iot
, &ioh
, NULL
, NULL
) == 0);
502 mem_type
= pci_mapreg_type(pa
->pa_pc
, pa
->pa_tag
, MEM_MAP_REG
);
503 if (PCI_MAPREG_TYPE(mem_type
) != PCI_MAPREG_TYPE_MEM
) {
505 } else if (PCI_MAPREG_MEM_TYPE(mem_type
) != PCI_MAPREG_MEM_TYPE_32BIT
&&
506 PCI_MAPREG_MEM_TYPE(mem_type
) != PCI_MAPREG_MEM_TYPE_64BIT
) {
509 memh_valid
= (pci_mapreg_map(pa
, MEM_MAP_REG
, mem_type
, 0,
510 &memt
, &memh
, NULL
, NULL
) == 0);
515 } else if (ioh_valid
) {
519 printf(": unable to map device registers\n");
529 pcs
->pci_pc
= pa
->pa_pc
;
530 pcs
->pci_tag
= pa
->pa_tag
;
531 pcs
->pci_poff
[BIU_BLOCK
>> _BLK_REG_SHFT
] = BIU_REGS_OFF
;
532 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS_OFF
;
533 pcs
->pci_poff
[SXP_BLOCK
>> _BLK_REG_SHFT
] = PCI_SXP_REGS_OFF
;
534 pcs
->pci_poff
[RISC_BLOCK
>> _BLK_REG_SHFT
] = PCI_RISC_REGS_OFF
;
535 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = DMA_REGS_OFF
;
536 rev
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_CLASS_REG
) & 0xff;
539 #ifndef ISP_DISABLE_1020_SUPPORT
540 if (pa
->pa_id
== PCI_QLOGIC_ISP
) {
541 dstring
= ": QLogic 1020 Fast Wide SCSI HBA\n";
542 isp
->isp_mdvec
= &mdvec
;
543 isp
->isp_type
= ISP_HA_SCSI_UNKNOWN
;
544 mamt
= sizeof (sdparam
);
547 #ifndef ISP_DISABLE_1080_SUPPORT
548 if (pa
->pa_id
== PCI_QLOGIC_ISP1080
) {
549 dstring
= ": QLogic 1080 Ultra-2 Wide SCSI HBA\n";
550 isp
->isp_mdvec
= &mdvec_1080
;
551 isp
->isp_type
= ISP_HA_SCSI_1080
;
552 mamt
= sizeof (sdparam
);
553 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] =
554 ISP1080_DMA_REGS_OFF
;
556 if (pa
->pa_id
== PCI_QLOGIC_ISP1240
) {
557 dstring
= ": QLogic Dual Channel Ultra Wide SCSI HBA\n";
558 isp
->isp_mdvec
= &mdvec_1080
;
559 isp
->isp_type
= ISP_HA_SCSI_1240
;
561 mamt
= sizeof (sdparam
) * 2;
562 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] =
563 ISP1080_DMA_REGS_OFF
;
565 if (pa
->pa_id
== PCI_QLOGIC_ISP1280
) {
566 dstring
= ": QLogic Dual Channel Ultra-2 Wide SCSI HBA\n";
567 isp
->isp_mdvec
= &mdvec_1080
;
568 isp
->isp_type
= ISP_HA_SCSI_1280
;
570 mamt
= sizeof (sdparam
) * 2;
571 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] =
572 ISP1080_DMA_REGS_OFF
;
575 #ifndef ISP_DISABLE_12160_SUPPORT
576 if (pa
->pa_id
== PCI_QLOGIC_ISP10160
) {
577 dstring
= ": QLogic Ultra-3 Wide SCSI HBA\n";
578 isp
->isp_mdvec
= &mdvec_12160
;
579 isp
->isp_type
= ISP_HA_SCSI_10160
;
580 mamt
= sizeof (sdparam
);
581 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] =
582 ISP1080_DMA_REGS_OFF
;
584 if (pa
->pa_id
== PCI_QLOGIC_ISP12160
) {
585 dstring
= ": QLogic Dual Channel Ultra-3 Wide SCSI HBA\n";
586 isp
->isp_mdvec
= &mdvec_12160
;
587 isp
->isp_type
= ISP_HA_SCSI_12160
;
589 mamt
= sizeof (sdparam
) * 2;
590 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] =
591 ISP1080_DMA_REGS_OFF
;
594 #ifndef ISP_DISABLE_2100_SUPPORT
595 if (pa
->pa_id
== PCI_QLOGIC_ISP2100
) {
596 dstring
= ": QLogic FC-AL HBA\n";
597 isp
->isp_mdvec
= &mdvec_2100
;
598 isp
->isp_type
= ISP_HA_FC_2100
;
599 mamt
= sizeof (fcparam
);
600 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] =
601 PCI_MBOX_REGS2100_OFF
;
604 * XXX: Need to get the actual revision
605 * XXX: number of the 2100 FB. At any rate,
606 * XXX: lower cache line size for early revision
613 #ifndef ISP_DISABLE_2200_SUPPORT
614 if (pa
->pa_id
== PCI_QLOGIC_ISP2200
) {
615 dstring
= ": QLogic FC-AL and Fabric HBA\n";
616 isp
->isp_mdvec
= &mdvec_2200
;
617 isp
->isp_type
= ISP_HA_FC_2200
;
618 mamt
= sizeof (fcparam
);
619 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] =
620 PCI_MBOX_REGS2100_OFF
;
621 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_CLASS_REG
);
624 #ifndef ISP_DISABLE_2300_SUPPORT
625 if (pa
->pa_id
== PCI_QLOGIC_ISP2300
||
626 pa
->pa_id
== PCI_QLOGIC_ISP2312
||
627 pa
->pa_id
== PCI_QLOGIC_ISP6312
) {
628 isp
->isp_mdvec
= &mdvec_2300
;
629 if (pa
->pa_id
== PCI_QLOGIC_ISP2300
||
630 pa
->pa_id
== PCI_QLOGIC_ISP6312
) {
631 dstring
= ": QLogic FC-AL and 2Gbps Fabric HBA\n";
632 isp
->isp_type
= ISP_HA_FC_2300
;
635 ": QLogic Dual Port FC-AL and 2Gbps Fabric HBA\n";
636 isp
->isp_port
= pa
->pa_function
;
638 isp
->isp_type
= ISP_HA_FC_2312
;
639 mamt
= sizeof (fcparam
);
640 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] =
641 PCI_MBOX_REGS2300_OFF
;
642 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_CLASS_REG
);
645 #ifndef ISP_DISABLE_2322_SUPPORT
646 if (pa
->pa_id
== PCI_QLOGIC_ISP2322
||
647 pa
->pa_id
== PCI_QLOGIC_ISP6322
) {
648 isp
->isp_mdvec
= &mdvec_2322
;
649 dstring
= ": QLogic FC-AL and 2Gbps Fabric PCI-E HBA\n";
650 isp
->isp_type
= ISP_HA_FC_2322
;
651 isp
->isp_port
= pa
->pa_function
;
652 mamt
= sizeof (fcparam
);
653 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] =
654 PCI_MBOX_REGS2300_OFF
;
655 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_CLASS_REG
);
658 #ifndef ISP_DISABLE_2400_SUPPORT
659 if (pa
->pa_id
== PCI_QLOGIC_ISP2422
||
660 pa
->pa_id
== PCI_QLOGIC_ISP2432
) {
661 isp
->isp_mdvec
= &mdvec_2400
;
662 if (pa
->pa_id
== PCI_QLOGIC_ISP2422
) {
663 dstring
= ": QLogic FC-AL and 4Gbps Fabric PCI-X HBA\n";
665 dstring
= ": QLogic FC-AL and 4Gbps Fabric PCI-E HBA\n";
667 isp
->isp_type
= ISP_HA_FC_2400
;
668 mamt
= sizeof (fcparam
);
669 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] =
670 PCI_MBOX_REGS2400_OFF
;
671 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_CLASS_REG
);
673 if (pa
->pa_id
== PCI_QLOGIC_ISP2532
) {
674 isp
->isp_mdvec
= &mdvec_2500
;
675 dstring
= ": QLogic FC-AL and 8Gbps Fabric PCI-E HBA\n";
676 isp
->isp_type
= ISP_HA_FC_2500
;
677 mamt
= sizeof (fcparam
);
678 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] =
679 PCI_MBOX_REGS2400_OFF
;
680 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_CLASS_REG
);
687 isp
->isp_param
= malloc(mamt
, M_DEVBUF
, M_NOWAIT
);
688 if (isp
->isp_param
== NULL
) {
689 printf(nomem
, device_xname(self
));
692 memset(isp
->isp_param
, 0, mamt
);
693 mamt
= sizeof (struct scsipi_channel
) * isp
->isp_nchan
;
694 isp
->isp_osinfo
.chan
= malloc(mamt
, M_DEVBUF
, M_NOWAIT
);
695 if (isp
->isp_osinfo
.chan
== NULL
) {
696 free(isp
->isp_param
, M_DEVBUF
);
697 printf(nomem
, device_xname(self
));
700 memset(isp
->isp_osinfo
.chan
, 0, mamt
);
701 isp
->isp_osinfo
.adapter
.adapt_nchannels
= isp
->isp_nchan
;
704 * Set up logging levels.
706 #ifdef ISP_LOGDEFAULT
707 isp
->isp_dblev
= ISP_LOGDEFAULT
;
709 isp
->isp_dblev
= ISP_LOGWARN
|ISP_LOGERR
;
711 isp
->isp_dblev
|= ISP_LOGCONFIG
|ISP_LOGINFO
;
713 isp
->isp_dblev
|= ISP_LOGDEBUG0
|ISP_LOGDEBUG1
|ISP_LOGDEBUG2
;
716 if (isp
->isp_dblev
& ISP_LOGCONFIG
) {
722 isp
->isp_dmatag
= pa
->pa_dmat
;
723 isp
->isp_revision
= rev
;
726 * Make sure that command register set sanely.
728 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
);
729 data
|= PCI_COMMAND_MASTER_ENABLE
| PCI_COMMAND_INVALIDATE_ENABLE
;
732 * Not so sure about these- but I think it's important that they get
735 data
|= PCI_COMMAND_PARITY_ENABLE
| PCI_COMMAND_SERR_ENABLE
;
736 if (IS_2300(isp
)) { /* per QLogic errata */
737 data
&= ~PCI_COMMAND_INVALIDATE_ENABLE
;
739 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
, data
);
742 * Make sure that the latency timer, cache line size,
743 * and ROM is disabled.
745 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_BHLC_REG
);
746 data
&= ~(PCI_LATTIMER_MASK
<< PCI_LATTIMER_SHIFT
);
747 data
&= ~(PCI_CACHELINE_MASK
<< PCI_CACHELINE_SHIFT
);
748 data
|= (PCI_DFLT_LTNCY
<< PCI_LATTIMER_SHIFT
);
749 data
|= (linesz
<< PCI_CACHELINE_SHIFT
);
750 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCI_BHLC_REG
, data
);
752 data
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCIR_ROMADDR
);
754 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCIR_ROMADDR
, data
);
756 if (pci_intr_map(pa
, &ih
)) {
757 aprint_error_dev(self
, "couldn't map interrupt\n");
758 free(isp
->isp_param
, M_DEVBUF
);
759 free(isp
->isp_osinfo
.chan
, M_DEVBUF
);
762 intrstr
= pci_intr_string(pa
->pa_pc
, ih
);
764 intrstr
= "<I dunno>";
765 pcs
->pci_ih
= pci_intr_establish(pa
->pa_pc
, ih
, IPL_BIO
,
767 if (pcs
->pci_ih
== NULL
) {
768 aprint_error_dev(self
, "couldn't establish interrupt at %s\n",
770 free(isp
->isp_param
, M_DEVBUF
);
771 free(isp
->isp_osinfo
.chan
, M_DEVBUF
);
775 printf("%s: interrupting at %s\n", device_xname(self
), intrstr
);
777 isp
->isp_confopts
= device_cfdata(self
)->cf_flags
;
780 if (isp
->isp_state
!= ISP_RESETSTATE
) {
782 free(isp
->isp_param
, M_DEVBUF
);
783 free(isp
->isp_osinfo
.chan
, M_DEVBUF
);
787 if (isp
->isp_state
!= ISP_INITSTATE
) {
790 free(isp
->isp_param
, M_DEVBUF
);
791 free(isp
->isp_osinfo
.chan
, M_DEVBUF
);
795 * Do platform attach.
801 #define IspVirt2Off(a, x) \
802 (((struct isp_pcisoftc *)a)->pci_poff[((x) & _BLK_REG_MASK) >> \
803 _BLK_REG_SHFT] + ((x) & 0xff))
805 #define BXR2(pcs, off) \
806 bus_space_read_2(pcs->pci_st, pcs->pci_sh, off)
807 #define BXW2(pcs, off, v) \
808 bus_space_write_2(pcs->pci_st, pcs->pci_sh, off, v)
809 #define BXR4(pcs, off) \
810 bus_space_read_4(pcs->pci_st, pcs->pci_sh, off)
811 #define BXW4(pcs, off, v) \
812 bus_space_write_4(pcs->pci_st, pcs->pci_sh, off, v)
816 isp_pci_rd_debounced(struct ispsoftc
*isp
, int off
, uint16_t *rp
)
818 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
823 val0
= BXR2(pcs
, IspVirt2Off(isp
, off
));
824 val1
= BXR2(pcs
, IspVirt2Off(isp
, off
));
825 } while (val0
!= val1
&& ++i
< 1000);
833 #if !defined(ISP_DISABLE_2100_SUPPORT) && \
834 !defined(ISP_DISABLE_2200_SUPPORT) && \
835 !defined(ISP_DISABLE_1020_SUPPORT) && \
836 !defined(ISP_DISABLE_1080_SUPPORT) && \
837 !defined(ISP_DISABLE_12160_SUPPORT)
839 isp_pci_rd_isr(struct ispsoftc
*isp
, uint32_t *isrp
,
840 uint16_t *semap
, uint16_t *mbp
)
842 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
846 if (isp_pci_rd_debounced(isp
, BIU_ISR
, &isr
)) {
849 if (isp_pci_rd_debounced(isp
, BIU_SEMA
, &sema
)) {
853 isr
= BXR2(pcs
, IspVirt2Off(isp
, BIU_ISR
));
854 sema
= BXR2(pcs
, IspVirt2Off(isp
, BIU_SEMA
));
856 isp_prt(isp
, ISP_LOGDEBUG3
, "ISR 0x%x SEMA 0x%x", isr
, sema
);
857 isr
&= INT_PENDING_MASK(isp
);
858 sema
&= BIU_SEMA_LOCK
;
859 if (isr
== 0 && sema
== 0) {
863 if ((*semap
= sema
) != 0) {
865 if (isp_pci_rd_debounced(isp
, OUTMAILBOX0
, mbp
)) {
869 *mbp
= BXR2(pcs
, IspVirt2Off(isp
, OUTMAILBOX0
));
876 #if !(defined(ISP_DISABLE_2300_SUPPORT) || defined(ISP_DISABLE_2322_SUPPORT))
878 isp_pci_rd_isr_2300(struct ispsoftc
*isp
, uint32_t *isrp
,
879 uint16_t *semap
, uint16_t *mbox0p
)
881 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
884 if (!(BXR2(pcs
, IspVirt2Off(isp
, BIU_ISR
)) & BIU2100_ISR_RISC_INT
)) {
888 r2hisr
= bus_space_read_4(pcs
->pci_st
, pcs
->pci_sh
,
889 IspVirt2Off(pcs
, BIU_R2HSTSLO
));
890 isp_prt(isp
, ISP_LOGDEBUG3
, "RISC2HOST ISR 0x%x", r2hisr
);
891 if ((r2hisr
& BIU_R2HST_INTR
) == 0) {
895 switch (r2hisr
& BIU_R2HST_ISTAT_MASK
) {
896 case ISPR2HST_ROM_MBX_OK
:
897 case ISPR2HST_ROM_MBX_FAIL
:
898 case ISPR2HST_MBX_OK
:
899 case ISPR2HST_MBX_FAIL
:
900 case ISPR2HST_ASYNC_EVENT
:
901 *isrp
= r2hisr
& 0xffff;
902 *mbox0p
= (r2hisr
>> 16);
905 case ISPR2HST_RIO_16
:
906 *isrp
= r2hisr
& 0xffff;
907 *mbox0p
= ASYNC_RIO1
;
911 *isrp
= r2hisr
& 0xffff;
912 *mbox0p
= ASYNC_CMD_CMPLT
;
915 case ISPR2HST_FPOST_CTIO
:
916 *isrp
= r2hisr
& 0xffff;
917 *mbox0p
= ASYNC_CTIO_DONE
;
920 case ISPR2HST_RSPQ_UPDATE
:
921 *isrp
= r2hisr
& 0xffff;
931 #ifndef ISP_DISABLE_2400_SUPPORT
933 isp_pci_rd_isr_2400(ispsoftc_t
*isp
, uint32_t *isrp
,
934 uint16_t *semap
, uint16_t *mbox0p
)
936 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
939 r2hisr
= BXR4(pcs
, IspVirt2Off(pcs
, BIU2400_R2HSTSLO
));
940 isp_prt(isp
, ISP_LOGDEBUG3
, "RISC2HOST ISR 0x%x", r2hisr
);
941 if ((r2hisr
& BIU2400_R2HST_INTR
) == 0) {
945 switch (r2hisr
& BIU2400_R2HST_ISTAT_MASK
) {
946 case ISP2400R2HST_ROM_MBX_OK
:
947 case ISP2400R2HST_ROM_MBX_FAIL
:
948 case ISP2400R2HST_MBX_OK
:
949 case ISP2400R2HST_MBX_FAIL
:
950 case ISP2400R2HST_ASYNC_EVENT
:
951 *isrp
= r2hisr
& 0xffff;
952 *mbox0p
= (r2hisr
>> 16);
955 case ISP2400R2HST_RSPQ_UPDATE
:
956 case ISP2400R2HST_ATIO_RSPQ_UPDATE
:
957 case ISP2400R2HST_ATIO_RQST_UPDATE
:
958 *isrp
= r2hisr
& 0xffff;
963 ISP_WRITE(isp
, BIU2400_HCCR
, HCCR_2400_CMD_CLEAR_RISC_INT
);
964 isp_prt(isp
, ISP_LOGERR
, "unknown interrupt 0x%x\n", r2hisr
);
970 isp_pci_rd_reg_2400(ispsoftc_t
*isp
, int regoff
)
972 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
974 int block
= regoff
& _BLK_REG_MASK
;
980 return (BXR2(pcs
, IspVirt2Off(pcs
, regoff
)));
982 isp_prt(isp
, ISP_LOGWARN
, "SXP_BLOCK read at 0x%x", regoff
);
985 isp_prt(isp
, ISP_LOGWARN
, "RISC_BLOCK read at 0x%x", regoff
);
988 isp_prt(isp
, ISP_LOGWARN
, "DMA_BLOCK read at 0x%x", regoff
);
991 isp_prt(isp
, ISP_LOGWARN
, "unknown block read at 0x%x", regoff
);
997 case BIU2400_FLASH_ADDR
:
998 case BIU2400_FLASH_DATA
:
1002 case BIU2400_REQINP
:
1003 case BIU2400_REQOUTP
:
1004 case BIU2400_RSPINP
:
1005 case BIU2400_RSPOUTP
:
1006 case BIU2400_PRI_REQINP
:
1007 case BIU2400_PRI_REQOUTP
:
1008 case BIU2400_ATIO_RSPINP
:
1009 case BIU2400_ATIO_RSPOUTP
:
1014 rv
= BXR4(pcs
, IspVirt2Off(pcs
, regoff
));
1016 case BIU2400_R2HSTSLO
:
1017 rv
= BXR4(pcs
, IspVirt2Off(pcs
, regoff
));
1019 case BIU2400_R2HSTSHI
:
1020 rv
= BXR4(pcs
, IspVirt2Off(pcs
, regoff
)) >> 16;
1023 isp_prt(isp
, ISP_LOGERR
,
1024 "isp_pci_rd_reg_2400: unknown offset %x", regoff
);
1032 isp_pci_wr_reg_2400(ispsoftc_t
*isp
, int regoff
, uint32_t val
)
1034 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
1035 int block
= regoff
& _BLK_REG_MASK
;
1042 BXW2(pcs
, IspVirt2Off(pcs
, regoff
), val
);
1043 junk
= BXR2(pcs
, IspVirt2Off(pcs
, regoff
));
1046 isp_prt(isp
, ISP_LOGWARN
, "SXP_BLOCK write at 0x%x", regoff
);
1049 isp_prt(isp
, ISP_LOGWARN
, "RISC_BLOCK write at 0x%x", regoff
);
1052 isp_prt(isp
, ISP_LOGWARN
, "DMA_BLOCK write at 0x%x", regoff
);
1055 isp_prt(isp
, ISP_LOGWARN
, "unknown block write at 0x%x",
1061 case BIU2400_FLASH_ADDR
:
1062 case BIU2400_FLASH_DATA
:
1066 case BIU2400_REQINP
:
1067 case BIU2400_REQOUTP
:
1068 case BIU2400_RSPINP
:
1069 case BIU2400_RSPOUTP
:
1070 case BIU2400_PRI_REQINP
:
1071 case BIU2400_PRI_REQOUTP
:
1072 case BIU2400_ATIO_RSPINP
:
1073 case BIU2400_ATIO_RSPOUTP
:
1078 BXW4(pcs
, IspVirt2Off(pcs
, regoff
), val
);
1079 junk
= BXR4(pcs
, IspVirt2Off(pcs
, regoff
));
1082 isp_prt(isp
, ISP_LOGERR
,
1083 "isp_pci_wr_reg_2400: bad offset 0x%x", regoff
);
1090 isp_pci_rd_reg(struct ispsoftc
*isp
, int regoff
)
1093 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
1096 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1098 * We will assume that someone has paused the RISC processor.
1100 oldconf
= BXR2(pcs
, IspVirt2Off(isp
, BIU_CONF1
));
1101 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
),
1102 oldconf
| BIU_PCI_CONF1_SXP
);
1104 rv
= BXR2(pcs
, IspVirt2Off(isp
, regoff
));
1105 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1106 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
), oldconf
);
1112 isp_pci_wr_reg(struct ispsoftc
*isp
, int regoff
, uint32_t val
)
1114 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
1117 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1119 * We will assume that someone has paused the RISC processor.
1121 oldconf
= BXR2(pcs
, IspVirt2Off(isp
, BIU_CONF1
));
1122 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
),
1123 oldconf
| BIU_PCI_CONF1_SXP
);
1125 BXW2(pcs
, IspVirt2Off(isp
, regoff
), val
);
1126 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1127 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
), oldconf
);
1131 #if !(defined(ISP_DISABLE_1080_SUPPORT) && defined(ISP_DISABLE_12160_SUPPORT))
1133 isp_pci_rd_reg_1080(struct ispsoftc
*isp
, int regoff
)
1135 uint16_t rv
, oc
= 0;
1136 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
1138 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
||
1139 (regoff
& _BLK_REG_MASK
) == (SXP_BLOCK
|SXP_BANK1_SELECT
)) {
1142 * We will assume that someone has paused the RISC processor.
1144 oc
= BXR2(pcs
, IspVirt2Off(isp
, BIU_CONF1
));
1145 tc
= oc
& ~BIU_PCI1080_CONF1_DMA
;
1146 if (regoff
& SXP_BANK1_SELECT
)
1147 tc
|= BIU_PCI1080_CONF1_SXP1
;
1149 tc
|= BIU_PCI1080_CONF1_SXP0
;
1150 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
), tc
);
1151 } else if ((regoff
& _BLK_REG_MASK
) == DMA_BLOCK
) {
1152 oc
= BXR2(pcs
, IspVirt2Off(isp
, BIU_CONF1
));
1153 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
),
1154 oc
| BIU_PCI1080_CONF1_DMA
);
1156 rv
= BXR2(pcs
, IspVirt2Off(isp
, regoff
));
1158 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
), oc
);
1164 isp_pci_wr_reg_1080(struct ispsoftc
*isp
, int regoff
, uint32_t val
)
1166 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*) isp
;
1169 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
||
1170 (regoff
& _BLK_REG_MASK
) == (SXP_BLOCK
|SXP_BANK1_SELECT
)) {
1173 * We will assume that someone has paused the RISC processor.
1175 oc
= BXR2(pcs
, IspVirt2Off(isp
, BIU_CONF1
));
1176 tc
= oc
& ~BIU_PCI1080_CONF1_DMA
;
1177 if (regoff
& SXP_BANK1_SELECT
)
1178 tc
|= BIU_PCI1080_CONF1_SXP1
;
1180 tc
|= BIU_PCI1080_CONF1_SXP0
;
1181 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
), tc
);
1182 } else if ((regoff
& _BLK_REG_MASK
) == DMA_BLOCK
) {
1183 oc
= BXR2(pcs
, IspVirt2Off(isp
, BIU_CONF1
));
1184 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
),
1185 oc
| BIU_PCI1080_CONF1_DMA
);
1187 BXW2(pcs
, IspVirt2Off(isp
, regoff
), val
);
1189 BXW2(pcs
, IspVirt2Off(isp
, BIU_CONF1
), oc
);
1195 isp_pci_mbxdma(struct ispsoftc
*isp
)
1197 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*)isp
;
1198 bus_dma_tag_t dmat
= isp
->isp_dmatag
;
1199 bus_dma_segment_t sg
;
1200 bus_size_t len
, dbound
;
1204 if (isp
->isp_rquest_dma
) /* been here before? */
1207 if (isp
->isp_type
<= ISP_HA_SCSI_1040B
) {
1211 * For 32-bit PCI DMA, the range is 32 bits or zero :-)
1215 len
= isp
->isp_maxcmds
* sizeof (XS_T
*);
1216 isp
->isp_xflist
= (XS_T
**) malloc(len
, M_DEVBUF
, M_WAITOK
);
1217 if (isp
->isp_xflist
== NULL
) {
1218 isp_prt(isp
, ISP_LOGERR
, "cannot malloc xflist array");
1221 memset(isp
->isp_xflist
, 0, len
);
1222 len
= isp
->isp_maxcmds
* sizeof (bus_dmamap_t
);
1223 pcs
->pci_xfer_dmap
= (bus_dmamap_t
*) malloc(len
, M_DEVBUF
, M_WAITOK
);
1224 if (pcs
->pci_xfer_dmap
== NULL
) {
1225 free(isp
->isp_xflist
, M_DEVBUF
);
1226 isp
->isp_xflist
= NULL
;
1227 isp_prt(isp
, ISP_LOGERR
, "cannot malloc DMA map array");
1230 for (i
= 0; i
< isp
->isp_maxcmds
; i
++) {
1231 if (bus_dmamap_create(dmat
, MAXPHYS
, (MAXPHYS
/ PAGE_SIZE
) + 1,
1232 MAXPHYS
, dbound
, BUS_DMA_NOWAIT
, &pcs
->pci_xfer_dmap
[i
])) {
1233 isp_prt(isp
, ISP_LOGERR
, "cannot create DMA maps");
1237 if (i
< isp
->isp_maxcmds
) {
1239 bus_dmamap_destroy(dmat
, pcs
->pci_xfer_dmap
[i
]);
1241 free(isp
->isp_xflist
, M_DEVBUF
);
1242 free(pcs
->pci_xfer_dmap
, M_DEVBUF
);
1243 isp
->isp_xflist
= NULL
;
1244 pcs
->pci_xfer_dmap
= NULL
;
1249 * Allocate and map the request queue.
1251 len
= ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp
));
1252 if (bus_dmamem_alloc(dmat
, len
, PAGE_SIZE
, 0, &sg
, 1, &rs
, 0)) {
1255 if (bus_dmamem_map(isp
->isp_dmatag
, &sg
, rs
, len
,
1256 (void *)&isp
->isp_rquest
, BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
)) {
1259 if (bus_dmamap_create(dmat
, len
, 1, len
, dbound
, BUS_DMA_NOWAIT
,
1260 &isp
->isp_rqdmap
)) {
1263 if (bus_dmamap_load(dmat
, isp
->isp_rqdmap
, isp
->isp_rquest
, len
, NULL
,
1267 isp
->isp_rquest_dma
= isp
->isp_rqdmap
->dm_segs
[0].ds_addr
;
1270 * Allocate and map the result queue.
1272 len
= ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp
));
1273 if (bus_dmamem_alloc(dmat
, len
, PAGE_SIZE
, 0, &sg
, 1, &rs
,
1277 if (bus_dmamem_map(dmat
, &sg
, rs
, len
,
1278 (void *)&isp
->isp_result
, BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
)) {
1281 if (bus_dmamap_create(dmat
, len
, 1, len
, dbound
, BUS_DMA_NOWAIT
,
1282 &isp
->isp_rsdmap
)) {
1285 if (bus_dmamap_load(dmat
, isp
->isp_rsdmap
, isp
->isp_result
, len
, NULL
,
1289 isp
->isp_result_dma
= isp
->isp_rsdmap
->dm_segs
[0].ds_addr
;
1296 * Allocate and map an FC scratch area
1298 fcp
= isp
->isp_param
;
1299 len
= ISP_FC_SCRLEN
;
1300 if (bus_dmamem_alloc(dmat
, len
, sizeof (uint64_t), 0, &sg
, 1, &rs
,
1304 if (bus_dmamem_map(dmat
, &sg
, rs
, len
,
1305 (void *)&fcp
->isp_scratch
, BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
)) {
1308 if (bus_dmamap_create(dmat
, len
, 1, len
, dbound
, BUS_DMA_NOWAIT
,
1309 &isp
->isp_scdmap
)) {
1312 if (bus_dmamap_load(dmat
, isp
->isp_scdmap
, fcp
->isp_scratch
, len
, NULL
,
1316 fcp
->isp_scdma
= isp
->isp_scdmap
->dm_segs
[0].ds_addr
;
1319 isp_prt(isp
, ISP_LOGERR
, "mailbox DMA setup failure");
1320 for (i
= 0; i
< isp
->isp_maxcmds
; i
++) {
1321 bus_dmamap_destroy(dmat
, pcs
->pci_xfer_dmap
[i
]);
1323 free(isp
->isp_xflist
, M_DEVBUF
);
1324 free(pcs
->pci_xfer_dmap
, M_DEVBUF
);
1325 isp
->isp_xflist
= NULL
;
1326 pcs
->pci_xfer_dmap
= NULL
;
1331 isp_pci_dmasetup(struct ispsoftc
*isp
, struct scsipi_xfer
*xs
, void *arg
)
1333 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*)isp
;
1336 bus_dma_segment_t
*dm_segs
;
1340 dmap
= pcs
->pci_xfer_dmap
[isp_handle_index(rq
->req_handle
)];
1341 if (xs
->datalen
== 0) {
1347 uint32_t flag
, flg2
;
1349 if (sizeof (bus_addr_t
) > 4) {
1350 if (rq
->req_header
.rqs_entry_type
== RQSTYPE_T2RQS
) {
1351 rq
->req_header
.rqs_entry_type
= RQSTYPE_T3RQS
;
1352 } else if (rq
->req_header
.rqs_entry_type
== RQSTYPE_REQUEST
) {
1353 rq
->req_header
.rqs_entry_type
= RQSTYPE_A64
;
1357 if (xs
->xs_control
& XS_CTL_DATA_IN
) {
1358 flg2
= BUS_DMASYNC_PREREAD
;
1359 flag
= BUS_DMA_READ
;
1360 ddir
= ISP_FROM_DEVICE
;
1362 flg2
= BUS_DMASYNC_PREWRITE
;
1363 flag
= BUS_DMA_WRITE
;
1364 ddir
= ISP_TO_DEVICE
;
1366 error
= bus_dmamap_load(isp
->isp_dmatag
, dmap
, xs
->data
, xs
->datalen
,
1367 NULL
, ((xs
->xs_control
& XS_CTL_NOSLEEP
) ? BUS_DMA_NOWAIT
: BUS_DMA_WAITOK
) | BUS_DMA_STREAMING
| flag
);
1369 isp_prt(isp
, ISP_LOGWARN
, "unable to load DMA (%d)", error
);
1370 XS_SETERR(xs
, HBA_BOTCH
);
1371 if (error
== EAGAIN
|| error
== ENOMEM
) {
1372 return (CMD_EAGAIN
);
1374 return (CMD_COMPLETE
);
1377 dm_segs
= dmap
->dm_segs
;
1378 nsegs
= dmap
->dm_nsegs
;
1379 bus_dmamap_sync(isp
->isp_dmatag
, dmap
, 0, dmap
->dm_mapsize
, flg2
);
1382 if (isp_send_cmd(isp
, rq
, dm_segs
, nsegs
, xs
->datalen
, ddir
) != CMD_QUEUED
) {
1383 return (CMD_EAGAIN
);
1385 return (CMD_QUEUED
);
1390 isp_pci_intr(void *arg
)
1393 uint16_t sema
, mbox
;
1394 struct ispsoftc
*isp
= arg
;
1397 if (ISP_READ_ISR(isp
, &isr
, &sema
, &mbox
) == 0) {
1398 isp
->isp_intbogus
++;
1401 isp
->isp_osinfo
.onintstack
= 1;
1402 isp_intr(isp
, isr
, sema
, mbox
);
1403 isp
->isp_osinfo
.onintstack
= 0;
1409 isp_pci_dmateardown(struct ispsoftc
*isp
, XS_T
*xs
, uint32_t handle
)
1411 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*)isp
;
1412 bus_dmamap_t dmap
= pcs
->pci_xfer_dmap
[isp_handle_index(handle
)];
1413 bus_dmamap_sync(isp
->isp_dmatag
, dmap
, 0, dmap
->dm_mapsize
,
1414 xs
->xs_control
& XS_CTL_DATA_IN
?
1415 BUS_DMASYNC_POSTREAD
: BUS_DMASYNC_POSTWRITE
);
1416 bus_dmamap_unload(isp
->isp_dmatag
, dmap
);
1420 isp_pci_reset0(ispsoftc_t
*isp
)
1422 ISP_DISABLE_INTS(isp
);
1426 isp_pci_reset1(ispsoftc_t
*isp
)
1428 if (!IS_24XX(isp
)) {
1429 /* Make sure the BIOS is disabled */
1430 isp_pci_wr_reg(isp
, HCCR
, PCI_HCCR_CMD_BIOS
);
1432 /* and enable interrupts */
1433 ISP_ENABLE_INTS(isp
);
1437 isp_pci_dumpregs(struct ispsoftc
*isp
, const char *msg
)
1439 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*)isp
;
1441 printf("%s: %s\n", device_xname(isp
->isp_osinfo
.dev
), msg
);
1443 printf(" biu_conf1=%x", ISP_READ(isp
, BIU_CONF1
));
1445 printf(" biu_csr=%x", ISP_READ(isp
, BIU2100_CSR
));
1446 printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp
, BIU_ICR
),
1447 ISP_READ(isp
, BIU_ISR
), ISP_READ(isp
, BIU_SEMA
));
1448 printf("risc_hccr=%x\n", ISP_READ(isp
, HCCR
));
1452 ISP_WRITE(isp
, HCCR
, HCCR_CMD_PAUSE
);
1453 printf(" cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n",
1454 ISP_READ(isp
, CDMA_CONF
), ISP_READ(isp
, CDMA_STATUS
),
1455 ISP_READ(isp
, CDMA_FIFO_STS
));
1456 printf(" ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n",
1457 ISP_READ(isp
, DDMA_CONF
), ISP_READ(isp
, DDMA_STATUS
),
1458 ISP_READ(isp
, DDMA_FIFO_STS
));
1459 printf(" sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n",
1460 ISP_READ(isp
, SXP_INTERRUPT
),
1461 ISP_READ(isp
, SXP_GROSS_ERR
),
1462 ISP_READ(isp
, SXP_PINS_CTRL
));
1463 ISP_WRITE(isp
, HCCR
, HCCR_CMD_RELEASE
);
1465 printf(" mbox regs: %x %x %x %x %x\n",
1466 ISP_READ(isp
, OUTMAILBOX0
), ISP_READ(isp
, OUTMAILBOX1
),
1467 ISP_READ(isp
, OUTMAILBOX2
), ISP_READ(isp
, OUTMAILBOX3
),
1468 ISP_READ(isp
, OUTMAILBOX4
));
1469 printf(" PCI Status Command/Status=%x\n",
1470 pci_conf_read(pcs
->pci_pc
, pcs
->pci_tag
, PCI_COMMAND_STATUS_REG
));