2 * Copyright (c) 1997-2008 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice immediately at the beginning of the file, without modification,
10 * this list of conditions, and the following disclaimer.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/dev/isp/isp_pci.c,v 1.159 2011/11/16 02:52:24 mjacob Exp $
29 * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/linker.h>
38 #include <sys/firmware.h>
40 #include <sys/stdint.h>
41 #include <bus/pci/pcireg.h>
42 #include <bus/pci/pcivar.h>
44 #include <sys/malloc.h>
47 #include <dev/disk/isp/isp_freebsd.h>
49 static uint32_t isp_pci_rd_reg(ispsoftc_t
*, int);
50 static void isp_pci_wr_reg(ispsoftc_t
*, int, uint32_t);
51 static uint32_t isp_pci_rd_reg_1080(ispsoftc_t
*, int);
52 static void isp_pci_wr_reg_1080(ispsoftc_t
*, int, uint32_t);
53 static uint32_t isp_pci_rd_reg_2400(ispsoftc_t
*, int);
54 static void isp_pci_wr_reg_2400(ispsoftc_t
*, int, uint32_t);
55 static int isp_pci_rd_isr(ispsoftc_t
*, uint32_t *, uint16_t *, uint16_t *);
56 static int isp_pci_rd_isr_2300(ispsoftc_t
*, uint32_t *, uint16_t *, uint16_t *);
57 static int isp_pci_rd_isr_2400(ispsoftc_t
*, uint32_t *, uint16_t *, uint16_t *);
58 static int isp_pci_mbxdma(ispsoftc_t
*);
59 static int isp_pci_dmasetup(ispsoftc_t
*, XS_T
*, void *);
62 static void isp_pci_reset0(ispsoftc_t
*);
63 static void isp_pci_reset1(ispsoftc_t
*);
64 static void isp_pci_dumpregs(ispsoftc_t
*, const char *);
66 static struct ispmdvec mdvec
= {
72 isp_common_dmateardown
,
77 BIU_BURST_ENABLE
|BIU_PCI_CONF1_FIFO_64
80 static struct ispmdvec mdvec_1080
= {
86 isp_common_dmateardown
,
91 BIU_BURST_ENABLE
|BIU_PCI_CONF1_FIFO_64
94 static struct ispmdvec mdvec_12160
= {
100 isp_common_dmateardown
,
105 BIU_BURST_ENABLE
|BIU_PCI_CONF1_FIFO_64
108 static struct ispmdvec mdvec_2100
= {
114 isp_common_dmateardown
,
120 static struct ispmdvec mdvec_2200
= {
126 isp_common_dmateardown
,
132 static struct ispmdvec mdvec_2300
= {
138 isp_common_dmateardown
,
144 static struct ispmdvec mdvec_2400
= {
150 isp_common_dmateardown
,
156 static struct ispmdvec mdvec_2500
= {
162 isp_common_dmateardown
,
168 #ifndef PCIM_CMD_INVEN
169 #define PCIM_CMD_INVEN 0x10
171 #ifndef PCIM_CMD_BUSMASTEREN
172 #define PCIM_CMD_BUSMASTEREN 0x0004
174 #ifndef PCIM_CMD_PERRESPEN
175 #define PCIM_CMD_PERRESPEN 0x0040
177 #ifndef PCIM_CMD_SEREN
178 #define PCIM_CMD_SEREN 0x0100
180 #ifndef PCIM_CMD_INTX_DISABLE
181 #define PCIM_CMD_INTX_DISABLE 0x0400
185 #define PCIR_COMMAND 0x04
188 #ifndef PCIR_CACHELNSZ
189 #define PCIR_CACHELNSZ 0x0c
192 #ifndef PCIR_LATTIMER
193 #define PCIR_LATTIMER 0x0d
197 #define PCIR_ROMADDR 0x30
200 #ifndef PCI_VENDOR_QLOGIC
201 #define PCI_VENDOR_QLOGIC 0x1077
204 #ifndef PCI_PRODUCT_QLOGIC_ISP1020
205 #define PCI_PRODUCT_QLOGIC_ISP1020 0x1020
208 #ifndef PCI_PRODUCT_QLOGIC_ISP1080
209 #define PCI_PRODUCT_QLOGIC_ISP1080 0x1080
212 #ifndef PCI_PRODUCT_QLOGIC_ISP10160
213 #define PCI_PRODUCT_QLOGIC_ISP10160 0x1016
216 #ifndef PCI_PRODUCT_QLOGIC_ISP12160
217 #define PCI_PRODUCT_QLOGIC_ISP12160 0x1216
220 #ifndef PCI_PRODUCT_QLOGIC_ISP1240
221 #define PCI_PRODUCT_QLOGIC_ISP1240 0x1240
224 #ifndef PCI_PRODUCT_QLOGIC_ISP1280
225 #define PCI_PRODUCT_QLOGIC_ISP1280 0x1280
228 #ifndef PCI_PRODUCT_QLOGIC_ISP2100
229 #define PCI_PRODUCT_QLOGIC_ISP2100 0x2100
232 #ifndef PCI_PRODUCT_QLOGIC_ISP2200
233 #define PCI_PRODUCT_QLOGIC_ISP2200 0x2200
236 #ifndef PCI_PRODUCT_QLOGIC_ISP2300
237 #define PCI_PRODUCT_QLOGIC_ISP2300 0x2300
240 #ifndef PCI_PRODUCT_QLOGIC_ISP2312
241 #define PCI_PRODUCT_QLOGIC_ISP2312 0x2312
244 #ifndef PCI_PRODUCT_QLOGIC_ISP2322
245 #define PCI_PRODUCT_QLOGIC_ISP2322 0x2322
248 #ifndef PCI_PRODUCT_QLOGIC_ISP2422
249 #define PCI_PRODUCT_QLOGIC_ISP2422 0x2422
252 #ifndef PCI_PRODUCT_QLOGIC_ISP2432
253 #define PCI_PRODUCT_QLOGIC_ISP2432 0x2432
256 #ifndef PCI_PRODUCT_QLOGIC_ISP2532
257 #define PCI_PRODUCT_QLOGIC_ISP2532 0x2532
260 #ifndef PCI_PRODUCT_QLOGIC_ISP6312
261 #define PCI_PRODUCT_QLOGIC_ISP6312 0x6312
264 #ifndef PCI_PRODUCT_QLOGIC_ISP6322
265 #define PCI_PRODUCT_QLOGIC_ISP6322 0x6322
268 #ifndef PCI_PRODUCT_QLOGIC_ISP5432
269 #define PCI_PRODUCT_QLOGIC_ISP5432 0x5432
272 #define PCI_QLOGIC_ISP5432 \
273 ((PCI_PRODUCT_QLOGIC_ISP5432 << 16) | PCI_VENDOR_QLOGIC)
275 #define PCI_QLOGIC_ISP1020 \
276 ((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
278 #define PCI_QLOGIC_ISP1080 \
279 ((PCI_PRODUCT_QLOGIC_ISP1080 << 16) | PCI_VENDOR_QLOGIC)
281 #define PCI_QLOGIC_ISP10160 \
282 ((PCI_PRODUCT_QLOGIC_ISP10160 << 16) | PCI_VENDOR_QLOGIC)
284 #define PCI_QLOGIC_ISP12160 \
285 ((PCI_PRODUCT_QLOGIC_ISP12160 << 16) | PCI_VENDOR_QLOGIC)
287 #define PCI_QLOGIC_ISP1240 \
288 ((PCI_PRODUCT_QLOGIC_ISP1240 << 16) | PCI_VENDOR_QLOGIC)
290 #define PCI_QLOGIC_ISP1280 \
291 ((PCI_PRODUCT_QLOGIC_ISP1280 << 16) | PCI_VENDOR_QLOGIC)
293 #define PCI_QLOGIC_ISP2100 \
294 ((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC)
296 #define PCI_QLOGIC_ISP2200 \
297 ((PCI_PRODUCT_QLOGIC_ISP2200 << 16) | PCI_VENDOR_QLOGIC)
299 #define PCI_QLOGIC_ISP2300 \
300 ((PCI_PRODUCT_QLOGIC_ISP2300 << 16) | PCI_VENDOR_QLOGIC)
302 #define PCI_QLOGIC_ISP2312 \
303 ((PCI_PRODUCT_QLOGIC_ISP2312 << 16) | PCI_VENDOR_QLOGIC)
305 #define PCI_QLOGIC_ISP2322 \
306 ((PCI_PRODUCT_QLOGIC_ISP2322 << 16) | PCI_VENDOR_QLOGIC)
308 #define PCI_QLOGIC_ISP2422 \
309 ((PCI_PRODUCT_QLOGIC_ISP2422 << 16) | PCI_VENDOR_QLOGIC)
311 #define PCI_QLOGIC_ISP2432 \
312 ((PCI_PRODUCT_QLOGIC_ISP2432 << 16) | PCI_VENDOR_QLOGIC)
314 #define PCI_QLOGIC_ISP2532 \
315 ((PCI_PRODUCT_QLOGIC_ISP2532 << 16) | PCI_VENDOR_QLOGIC)
317 #define PCI_QLOGIC_ISP6312 \
318 ((PCI_PRODUCT_QLOGIC_ISP6312 << 16) | PCI_VENDOR_QLOGIC)
320 #define PCI_QLOGIC_ISP6322 \
321 ((PCI_PRODUCT_QLOGIC_ISP6322 << 16) | PCI_VENDOR_QLOGIC)
324 * Odd case for some AMI raid cards... We need to *not* attach to this.
326 #define AMI_RAID_SUBVENDOR_ID 0x101e
328 #define IO_MAP_REG 0x10
329 #define MEM_MAP_REG 0x14
331 #define PCI_DFLT_LTNCY 0x40
332 #define PCI_DFLT_LNSZ 0x10
334 static int isp_pci_probe (device_t
);
335 static int isp_pci_attach (device_t
);
336 static int isp_pci_detach (device_t
);
339 #define ISP_PCD(isp) ((struct isp_pcisoftc *)isp)->pci_dev
340 struct isp_pcisoftc
{
343 struct resource
* regs
;
350 int16_t pci_poff
[_NREG_BLKS
];
354 static int isp_msi_enable
= 1;
355 TUNABLE_INT("hw.isp.msi.enable", &isp_msi_enable
);
357 static device_method_t isp_pci_methods
[] = {
358 /* Device interface */
359 DEVMETHOD(device_probe
, isp_pci_probe
),
360 DEVMETHOD(device_attach
, isp_pci_attach
),
361 DEVMETHOD(device_detach
, isp_pci_detach
),
365 static driver_t isp_pci_driver
= {
366 "isp", isp_pci_methods
, sizeof (struct isp_pcisoftc
)
368 static devclass_t isp_devclass
;
369 DRIVER_MODULE(isp
, pci
, isp_pci_driver
, isp_devclass
, NULL
, NULL
);
372 isp_pci_probe(device_t dev
)
374 switch ((pci_get_device(dev
) << 16) | (pci_get_vendor(dev
))) {
375 case PCI_QLOGIC_ISP1020
:
376 device_set_desc(dev
, "Qlogic ISP 1020/1040 PCI SCSI Adapter");
378 case PCI_QLOGIC_ISP1080
:
379 device_set_desc(dev
, "Qlogic ISP 1080 PCI SCSI Adapter");
381 case PCI_QLOGIC_ISP1240
:
382 device_set_desc(dev
, "Qlogic ISP 1240 PCI SCSI Adapter");
384 case PCI_QLOGIC_ISP1280
:
385 device_set_desc(dev
, "Qlogic ISP 1280 PCI SCSI Adapter");
387 case PCI_QLOGIC_ISP10160
:
388 device_set_desc(dev
, "Qlogic ISP 10160 PCI SCSI Adapter");
390 case PCI_QLOGIC_ISP12160
:
391 if (pci_get_subvendor(dev
) == AMI_RAID_SUBVENDOR_ID
) {
394 device_set_desc(dev
, "Qlogic ISP 12160 PCI SCSI Adapter");
396 case PCI_QLOGIC_ISP2100
:
397 device_set_desc(dev
, "Qlogic ISP 2100 PCI FC-AL Adapter");
399 case PCI_QLOGIC_ISP2200
:
400 device_set_desc(dev
, "Qlogic ISP 2200 PCI FC-AL Adapter");
402 case PCI_QLOGIC_ISP2300
:
403 device_set_desc(dev
, "Qlogic ISP 2300 PCI FC-AL Adapter");
405 case PCI_QLOGIC_ISP2312
:
406 device_set_desc(dev
, "Qlogic ISP 2312 PCI FC-AL Adapter");
408 case PCI_QLOGIC_ISP2322
:
409 device_set_desc(dev
, "Qlogic ISP 2322 PCI FC-AL Adapter");
411 case PCI_QLOGIC_ISP2422
:
412 device_set_desc(dev
, "Qlogic ISP 2422 PCI FC-AL Adapter");
414 case PCI_QLOGIC_ISP2432
:
415 device_set_desc(dev
, "Qlogic ISP 2432 PCI FC-AL Adapter");
417 case PCI_QLOGIC_ISP2532
:
418 device_set_desc(dev
, "Qlogic ISP 2532 PCI FC-AL Adapter");
420 case PCI_QLOGIC_ISP5432
:
421 device_set_desc(dev
, "Qlogic ISP 5432 PCI FC-AL Adapter");
423 case PCI_QLOGIC_ISP6312
:
424 device_set_desc(dev
, "Qlogic ISP 6312 PCI FC-AL Adapter");
426 case PCI_QLOGIC_ISP6322
:
427 device_set_desc(dev
, "Qlogic ISP 6322 PCI FC-AL Adapter");
432 if (isp_announced
== 0 && bootverbose
) {
433 kprintf("Qlogic ISP Driver, FreeBSD Version %d.%d, "
434 "Core Version %d.%d\n",
435 ISP_PLATFORM_VERSION_MAJOR
, ISP_PLATFORM_VERSION_MINOR
,
436 ISP_CORE_VERSION_MAJOR
, ISP_CORE_VERSION_MINOR
);
440 * XXXX: Here is where we might load the f/w module
441 * XXXX: (or increase a reference count to it).
443 return (BUS_PROBE_DEFAULT
);
447 isp_get_generic_options(device_t dev
, ispsoftc_t
*isp
, int *nvp
)
452 * Figure out if we're supposed to skip this one.
455 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "disable", &tval
) == 0 && tval
) {
456 device_printf(dev
, "disabled at user request\n");
457 isp
->isp_osinfo
.disabled
= 1;
462 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "fwload_disable", &tval
) == 0 && tval
!= 0) {
463 isp
->isp_confopts
|= ISP_CFG_NORELOAD
;
466 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "ignore_nvram", &tval
) == 0 && tval
!= 0) {
467 isp
->isp_confopts
|= ISP_CFG_NONVRAM
;
470 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "debug", &tval
);
472 isp
->isp_dblev
= tval
;
474 isp
->isp_dblev
= ISP_LOGWARN
|ISP_LOGERR
;
477 isp
->isp_dblev
|= ISP_LOGCONFIG
|ISP_LOGINFO
;
479 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "vports", &tval
);
480 if (tval
> 0 && tval
< 127) {
486 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "autoconfig", &tval
);
487 isp_autoconfig
= tval
;
489 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "quickboot_time", &tval
);
490 isp_quickboot_time
= tval
;
493 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "forcemulti", &tval
) == 0 && tval
!= 0) {
494 isp
->isp_osinfo
.forcemulti
= 1;
499 isp_get_pci_options(device_t dev
, int *m1
, int *m2
)
503 * Which we should try first - memory mapping or i/o mapping?
505 * We used to try memory first followed by i/o on alpha, otherwise
506 * the reverse, but we should just try memory first all the time now.
508 *m1
= PCIM_CMD_MEMEN
;
509 *m2
= PCIM_CMD_PORTEN
;
512 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "prefer_iomap", &tval
) == 0 && tval
!= 0) {
513 *m1
= PCIM_CMD_PORTEN
;
514 *m2
= PCIM_CMD_MEMEN
;
517 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "prefer_memmap", &tval
) == 0 && tval
!= 0) {
518 *m1
= PCIM_CMD_MEMEN
;
519 *m2
= PCIM_CMD_PORTEN
;
524 isp_get_specific_options(device_t dev
, int chan
, ispsoftc_t
*isp
)
529 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "iid", &tval
)) {
531 ISP_FC_PC(isp
, chan
)->default_id
= 109 - chan
;
533 ISP_SPI_PC(isp
, chan
)->iid
= 7;
537 ISP_FC_PC(isp
, chan
)->default_id
= tval
- chan
;
539 ISP_SPI_PC(isp
, chan
)->iid
= tval
;
541 isp
->isp_confopts
|= ISP_CFG_OWNLOOPID
;
545 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "role", &tval
) == 0) {
548 case ISP_ROLE_INITIATOR
:
549 case ISP_ROLE_TARGET
:
550 case ISP_ROLE_INITIATOR
|ISP_ROLE_TARGET
:
551 device_printf(dev
, "setting role to 0x%x\n", tval
);
559 tval
= ISP_DEFAULT_ROLES
;
563 ISP_SPI_PC(isp
, chan
)->def_role
= tval
;
566 ISP_FC_PC(isp
, chan
)->def_role
= tval
;
569 if (resource_int_value(device_get_name(dev
), device_get_unit(dev
), "fullduplex", &tval
) == 0 && tval
!= 0) {
570 isp
->isp_confopts
|= ISP_CFG_FULL_DUPLEX
;
573 if (resource_string_value(device_get_name(dev
), device_get_unit(dev
), "topology", &sptr
) == 0 && sptr
!= NULL
) {
574 if (strcmp(sptr
, "lport") == 0) {
575 isp
->isp_confopts
|= ISP_CFG_LPORT
;
576 } else if (strcmp(sptr
, "nport") == 0) {
577 isp
->isp_confopts
|= ISP_CFG_NPORT
;
578 } else if (strcmp(sptr
, "lport-only") == 0) {
579 isp
->isp_confopts
|= ISP_CFG_LPORT_ONLY
;
580 } else if (strcmp(sptr
, "nport-only") == 0) {
581 isp
->isp_confopts
|= ISP_CFG_NPORT_ONLY
;
586 * Because the resource_*_value functions can neither return
587 * 64 bit integer values, nor can they be directly coerced
588 * to interpret the right hand side of the assignment as
589 * you want them to interpret it, we have to force WWN
590 * hint replacement to specify WWN strings with a leading
591 * 'w' (e..g w50000000aaaa0001). Sigh.
594 tval
= resource_string_value(device_get_name(dev
), device_get_unit(dev
), "portwwn", &sptr
);
595 if (tval
== 0 && sptr
!= NULL
&& *sptr
++ == 'w') {
597 ISP_FC_PC(isp
, chan
)->def_wwpn
= strtouq(sptr
, &eptr
, 16);
598 if (eptr
< sptr
+ 16 || ISP_FC_PC(isp
, chan
)->def_wwpn
== -1) {
599 device_printf(dev
, "mangled portwwn hint '%s'\n", sptr
);
600 ISP_FC_PC(isp
, chan
)->def_wwpn
= 0;
605 tval
= resource_string_value(device_get_name(dev
), device_get_unit(dev
), "nodewwn", &sptr
);
606 if (tval
== 0 && sptr
!= NULL
&& *sptr
++ == 'w') {
608 ISP_FC_PC(isp
, chan
)->def_wwnn
= strtouq(sptr
, &eptr
, 16);
609 if (eptr
< sptr
+ 16 || ISP_FC_PC(isp
, chan
)->def_wwnn
== 0) {
610 device_printf(dev
, "mangled nodewwn hint '%s'\n", sptr
);
611 ISP_FC_PC(isp
, chan
)->def_wwnn
= 0;
616 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "hysteresis", &tval
);
617 if (tval
>= 0 && tval
< 256) {
618 ISP_FC_PC(isp
, chan
)->hysteresis
= tval
;
620 ISP_FC_PC(isp
, chan
)->hysteresis
= isp_fabric_hysteresis
;
624 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "loop_down_limit", &tval
);
625 if (tval
>= 0 && tval
< 0xffff) {
626 ISP_FC_PC(isp
, chan
)->loop_down_limit
= tval
;
628 ISP_FC_PC(isp
, chan
)->loop_down_limit
= isp_loop_down_limit
;
632 (void) resource_int_value(device_get_name(dev
), device_get_unit(dev
), "gone_device_time", &tval
);
633 if (tval
>= 0 && tval
< 0xffff) {
634 ISP_FC_PC(isp
, chan
)->gone_device_time
= tval
;
636 ISP_FC_PC(isp
, chan
)->gone_device_time
= isp_gone_device_time
;
641 isp_pci_attach(device_t dev
)
643 int i
, m1
, m2
, locksetup
= 0;
645 uint32_t data
, cmd
, linesz
, did
;
646 struct isp_pcisoftc
*pcs
;
652 pcs
= device_get_softc(dev
);
654 device_printf(dev
, "cannot get softc\n");
657 memset(pcs
, 0, sizeof (*pcs
));
665 * Get Generic Options
667 isp_get_generic_options(dev
, isp
, &isp_nvports
);
670 * Check to see if options have us disabled
672 if (isp
->isp_osinfo
.disabled
) {
674 * But return zero to preserve unit numbering
680 * Get PCI options- which in this case are just mapping preferences.
682 isp_get_pci_options(dev
, &m1
, &m2
);
684 linesz
= PCI_DFLT_LNSZ
;
685 pcs
->irq
= pcs
->regs
= NULL
;
686 pcs
->rgd
= pcs
->rtp
= pcs
->iqd
= 0;
688 cmd
= pci_read_config(dev
, PCIR_COMMAND
, 2);
690 pcs
->rtp
= (m1
== PCIM_CMD_MEMEN
)? SYS_RES_MEMORY
: SYS_RES_IOPORT
;
691 pcs
->rgd
= (m1
== PCIM_CMD_MEMEN
)? MEM_MAP_REG
: IO_MAP_REG
;
692 pcs
->regs
= bus_alloc_resource_any(dev
, pcs
->rtp
, &pcs
->rgd
, RF_ACTIVE
);
694 if (pcs
->regs
== NULL
&& (cmd
& m2
)) {
695 pcs
->rtp
= (m2
== PCIM_CMD_MEMEN
)? SYS_RES_MEMORY
: SYS_RES_IOPORT
;
696 pcs
->rgd
= (m2
== PCIM_CMD_MEMEN
)? MEM_MAP_REG
: IO_MAP_REG
;
697 pcs
->regs
= bus_alloc_resource_any(dev
, pcs
->rtp
, &pcs
->rgd
, RF_ACTIVE
);
699 if (pcs
->regs
== NULL
) {
700 device_printf(dev
, "unable to map any ports\n");
704 device_printf(dev
, "using %s space register mapping\n", (pcs
->rgd
== IO_MAP_REG
)? "I/O" : "Memory");
706 isp
->isp_bus_tag
= rman_get_bustag(pcs
->regs
);
707 isp
->isp_bus_handle
= rman_get_bushandle(pcs
->regs
);
710 pcs
->pci_poff
[BIU_BLOCK
>> _BLK_REG_SHFT
] = BIU_REGS_OFF
;
711 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS_OFF
;
712 pcs
->pci_poff
[SXP_BLOCK
>> _BLK_REG_SHFT
] = PCI_SXP_REGS_OFF
;
713 pcs
->pci_poff
[RISC_BLOCK
>> _BLK_REG_SHFT
] = PCI_RISC_REGS_OFF
;
714 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = DMA_REGS_OFF
;
716 switch (pci_get_devid(dev
)) {
717 case PCI_QLOGIC_ISP1020
:
719 isp
->isp_mdvec
= &mdvec
;
720 isp
->isp_type
= ISP_HA_SCSI_UNKNOWN
;
722 case PCI_QLOGIC_ISP1080
:
724 isp
->isp_mdvec
= &mdvec_1080
;
725 isp
->isp_type
= ISP_HA_SCSI_1080
;
726 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = ISP1080_DMA_REGS_OFF
;
728 case PCI_QLOGIC_ISP1240
:
730 isp
->isp_mdvec
= &mdvec_1080
;
731 isp
->isp_type
= ISP_HA_SCSI_1240
;
733 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = ISP1080_DMA_REGS_OFF
;
735 case PCI_QLOGIC_ISP1280
:
737 isp
->isp_mdvec
= &mdvec_1080
;
738 isp
->isp_type
= ISP_HA_SCSI_1280
;
739 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = ISP1080_DMA_REGS_OFF
;
741 case PCI_QLOGIC_ISP10160
:
743 isp
->isp_mdvec
= &mdvec_12160
;
744 isp
->isp_type
= ISP_HA_SCSI_10160
;
745 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = ISP1080_DMA_REGS_OFF
;
747 case PCI_QLOGIC_ISP12160
:
750 isp
->isp_mdvec
= &mdvec_12160
;
751 isp
->isp_type
= ISP_HA_SCSI_12160
;
752 pcs
->pci_poff
[DMA_BLOCK
>> _BLK_REG_SHFT
] = ISP1080_DMA_REGS_OFF
;
754 case PCI_QLOGIC_ISP2100
:
756 isp
->isp_mdvec
= &mdvec_2100
;
757 isp
->isp_type
= ISP_HA_FC_2100
;
758 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2100_OFF
;
759 if (pci_get_revid(dev
) < 3) {
761 * XXX: Need to get the actual revision
762 * XXX: number of the 2100 FB. At any rate,
763 * XXX: lower cache line size for early revision
769 case PCI_QLOGIC_ISP2200
:
771 isp
->isp_mdvec
= &mdvec_2200
;
772 isp
->isp_type
= ISP_HA_FC_2200
;
773 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2100_OFF
;
775 case PCI_QLOGIC_ISP2300
:
777 isp
->isp_mdvec
= &mdvec_2300
;
778 isp
->isp_type
= ISP_HA_FC_2300
;
779 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2300_OFF
;
781 case PCI_QLOGIC_ISP2312
:
782 case PCI_QLOGIC_ISP6312
:
784 isp
->isp_mdvec
= &mdvec_2300
;
785 isp
->isp_type
= ISP_HA_FC_2312
;
786 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2300_OFF
;
788 case PCI_QLOGIC_ISP2322
:
789 case PCI_QLOGIC_ISP6322
:
791 isp
->isp_mdvec
= &mdvec_2300
;
792 isp
->isp_type
= ISP_HA_FC_2322
;
793 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2300_OFF
;
795 case PCI_QLOGIC_ISP2422
:
796 case PCI_QLOGIC_ISP2432
:
798 isp
->isp_nchan
+= isp_nvports
;
799 isp
->isp_mdvec
= &mdvec_2400
;
800 isp
->isp_type
= ISP_HA_FC_2400
;
801 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2400_OFF
;
803 case PCI_QLOGIC_ISP2532
:
805 isp
->isp_nchan
+= isp_nvports
;
806 isp
->isp_mdvec
= &mdvec_2500
;
807 isp
->isp_type
= ISP_HA_FC_2500
;
808 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2400_OFF
;
810 case PCI_QLOGIC_ISP5432
:
812 isp
->isp_mdvec
= &mdvec_2500
;
813 isp
->isp_type
= ISP_HA_FC_2500
;
814 pcs
->pci_poff
[MBOX_BLOCK
>> _BLK_REG_SHFT
] = PCI_MBOX_REGS2400_OFF
;
817 device_printf(dev
, "unknown device type\n");
821 isp
->isp_revision
= pci_get_revid(dev
);
824 psize
= sizeof (fcparam
);
825 xsize
= sizeof (struct isp_fc
);
827 psize
= sizeof (sdparam
);
828 xsize
= sizeof (struct isp_spi
);
830 psize
*= isp
->isp_nchan
;
831 xsize
*= isp
->isp_nchan
;
832 isp
->isp_param
= kmalloc(psize
, M_DEVBUF
, M_NOWAIT
| M_ZERO
);
833 if (isp
->isp_param
== NULL
) {
834 device_printf(dev
, "cannot allocate parameter data\n");
837 isp
->isp_osinfo
.pc
.ptr
= kmalloc(xsize
, M_DEVBUF
, M_NOWAIT
| M_ZERO
);
838 if (isp
->isp_osinfo
.pc
.ptr
== NULL
) {
839 device_printf(dev
, "cannot allocate parameter data\n");
844 * Now that we know who we are (roughly) get/set specific options
846 for (i
= 0; i
< isp
->isp_nchan
; i
++) {
847 isp_get_specific_options(dev
, i
, isp
);
851 * The 'it' suffix really only matters for SCSI cards in target mode.
853 isp
->isp_osinfo
.fw
= NULL
;
854 if (IS_SCSI(isp
) && (ISP_SPI_PC(isp
, 0)->def_role
& ISP_ROLE_TARGET
)) {
855 ksnprintf(fwname
, sizeof (fwname
), "isp_%04x_it", did
);
856 isp
->isp_osinfo
.fw
= firmware_get(fwname
);
857 } else if (IS_24XX(isp
) && (isp
->isp_nchan
> 1 || isp
->isp_osinfo
.forcemulti
)) {
858 ksnprintf(fwname
, sizeof (fwname
), "isp_%04x_multi", did
);
859 isp
->isp_osinfo
.fw
= firmware_get(fwname
);
861 if (isp
->isp_osinfo
.fw
== NULL
) {
862 ksnprintf(fwname
, sizeof (fwname
), "isp_%04x", did
);
863 #ifdef USE_SMALLER_2100_FIRMWARE
865 ksnprintf(fwname
, sizeof (fwname
), "%s_variant_1", fwname
);
868 isp
->isp_osinfo
.fw
= firmware_get(fwname
);
870 if (isp
->isp_osinfo
.fw
!= NULL
) {
871 isp
->isp_mdvec
->dv_ispfw
= isp
->isp_osinfo
.fw
->data
;
875 * Make sure that SERR, PERR, WRITE INVALIDATE and BUSMASTER
878 cmd
|= PCIM_CMD_SEREN
| PCIM_CMD_PERRESPEN
|
879 PCIM_CMD_BUSMASTEREN
| PCIM_CMD_INVEN
;
881 if (IS_2300(isp
)) { /* per QLogic errata */
882 cmd
&= ~PCIM_CMD_INVEN
;
885 if (IS_2322(isp
) || pci_get_devid(dev
) == PCI_QLOGIC_ISP6312
) {
886 cmd
&= ~PCIM_CMD_INTX_DISABLE
;
890 cmd
&= ~PCIM_CMD_INTX_DISABLE
;
893 pci_write_config(dev
, PCIR_COMMAND
, cmd
, 2);
896 * Make sure the Cache Line Size register is set sensibly.
898 data
= pci_read_config(dev
, PCIR_CACHELNSZ
, 1);
899 if (data
== 0 || (linesz
!= PCI_DFLT_LNSZ
&& data
!= linesz
)) {
900 isp_prt(isp
, ISP_LOGCONFIG
, "set PCI line size to %d from %d", linesz
, data
);
902 pci_write_config(dev
, PCIR_CACHELNSZ
, data
, 1);
906 * Make sure the Latency Timer is sane.
908 data
= pci_read_config(dev
, PCIR_LATTIMER
, 1);
909 if (data
< PCI_DFLT_LTNCY
) {
910 data
= PCI_DFLT_LTNCY
;
911 isp_prt(isp
, ISP_LOGCONFIG
, "set PCI latency to %d", data
);
912 pci_write_config(dev
, PCIR_LATTIMER
, data
, 1);
916 * Make sure we've disabled the ROM.
918 data
= pci_read_config(dev
, PCIR_ROMADDR
, 4);
920 pci_write_config(dev
, PCIR_ROMADDR
, data
, 4);
922 pcs
->irq_type
= pci_alloc_1intr(dev
, isp_msi_enable
, &pcs
->iqd
,
924 pcs
->irq
= bus_alloc_resource_any(dev
, SYS_RES_IRQ
, &pcs
->iqd
,
926 if (pcs
->irq
== NULL
) {
927 device_printf(dev
, "could not allocate interrupt\n");
931 /* Make sure the lock is set up. */
932 lockinit(&isp
->isp_osinfo
.lock
, "isp", 0, LK_CANRECURSE
);
935 if (isp_setup_intr(dev
, pcs
->irq
, ISP_IFLAGS
, isp_platform_intr
, isp
, &pcs
->ih
, NULL
)) {
936 device_printf(dev
, "could not setup interrupt\n");
941 * Last minute checks...
943 if (IS_23XX(isp
) || IS_24XX(isp
)) {
944 isp
->isp_port
= pci_get_function(dev
);
948 * Make sure we're in reset state.
952 if (isp
->isp_state
!= ISP_RESETSTATE
) {
957 if (isp
->isp_state
== ISP_INITSTATE
) {
958 isp
->isp_state
= ISP_RUNSTATE
;
961 if (isp_attach(isp
)) {
971 (void) bus_teardown_intr(dev
, pcs
->irq
, pcs
->ih
);
974 lockuninit(&isp
->isp_osinfo
.lock
);
977 (void) bus_release_resource(dev
, SYS_RES_IRQ
, pcs
->iqd
, pcs
->irq
);
979 if (pcs
->irq_type
== PCI_INTR_TYPE_MSI
) {
980 pci_release_msi(dev
);
983 (void) bus_release_resource(dev
, pcs
->rtp
, pcs
->rgd
, pcs
->regs
);
985 if (pcs
->pci_isp
.isp_param
) {
986 kfree(pcs
->pci_isp
.isp_param
, M_DEVBUF
);
987 pcs
->pci_isp
.isp_param
= NULL
;
989 if (pcs
->pci_isp
.isp_osinfo
.pc
.ptr
) {
990 kfree(pcs
->pci_isp
.isp_osinfo
.pc
.ptr
, M_DEVBUF
);
991 pcs
->pci_isp
.isp_osinfo
.pc
.ptr
= NULL
;
997 isp_pci_detach(device_t dev
)
999 struct isp_pcisoftc
*pcs
;
1003 pcs
= device_get_softc(dev
);
1007 isp
= (ispsoftc_t
*) pcs
;
1008 status
= isp_detach(isp
);
1014 (void) bus_teardown_intr(dev
, pcs
->irq
, pcs
->ih
);
1017 lockuninit(&isp
->isp_osinfo
.lock
);
1018 (void) bus_release_resource(dev
, SYS_RES_IRQ
, pcs
->iqd
, pcs
->irq
);
1019 if (pcs
->irq_type
== PCI_INTR_TYPE_MSI
) {
1020 pci_release_msi(dev
);
1022 (void) bus_release_resource(dev
, pcs
->rtp
, pcs
->rgd
, pcs
->regs
);
1023 if (pcs
->pci_isp
.isp_param
) {
1024 kfree(pcs
->pci_isp
.isp_param
, M_DEVBUF
);
1025 pcs
->pci_isp
.isp_param
= NULL
;
1027 if (pcs
->pci_isp
.isp_osinfo
.pc
.ptr
) {
1028 kfree(pcs
->pci_isp
.isp_osinfo
.pc
.ptr
, M_DEVBUF
);
1029 pcs
->pci_isp
.isp_osinfo
.pc
.ptr
= NULL
;
1034 #define IspVirt2Off(a, x) \
1035 (((struct isp_pcisoftc *)a)->pci_poff[((x) & _BLK_REG_MASK) >> \
1036 _BLK_REG_SHFT] + ((x) & 0xfff))
1038 #define BXR2(isp, off) \
1039 bus_space_read_2(isp->isp_bus_tag, isp->isp_bus_handle, off)
1040 #define BXW2(isp, off, v) \
1041 bus_space_write_2(isp->isp_bus_tag, isp->isp_bus_handle, off, v)
1042 #define BXR4(isp, off) \
1043 bus_space_read_4(isp->isp_bus_tag, isp->isp_bus_handle, off)
1044 #define BXW4(isp, off, v) \
1045 bus_space_write_4(isp->isp_bus_tag, isp->isp_bus_handle, off, v)
1048 static ISP_INLINE
int
1049 isp_pci_rd_debounced(ispsoftc_t
*isp
, int off
, uint16_t *rp
)
1051 uint32_t val0
, val1
;
1055 val0
= BXR2(isp
, IspVirt2Off(isp
, off
));
1056 val1
= BXR2(isp
, IspVirt2Off(isp
, off
));
1057 } while (val0
!= val1
&& ++i
< 1000);
1066 isp_pci_rd_isr(ispsoftc_t
*isp
, uint32_t *isrp
, uint16_t *semap
, uint16_t *mbp
)
1071 if (isp_pci_rd_debounced(isp
, BIU_ISR
, &isr
)) {
1074 if (isp_pci_rd_debounced(isp
, BIU_SEMA
, &sema
)) {
1078 isr
= BXR2(isp
, IspVirt2Off(isp
, BIU_ISR
));
1079 sema
= BXR2(isp
, IspVirt2Off(isp
, BIU_SEMA
));
1081 isp_prt(isp
, ISP_LOGDEBUG3
, "ISR 0x%x SEMA 0x%x", isr
, sema
);
1082 isr
&= INT_PENDING_MASK(isp
);
1083 sema
&= BIU_SEMA_LOCK
;
1084 if (isr
== 0 && sema
== 0) {
1088 if ((*semap
= sema
) != 0) {
1090 if (isp_pci_rd_debounced(isp
, OUTMAILBOX0
, mbp
)) {
1094 *mbp
= BXR2(isp
, IspVirt2Off(isp
, OUTMAILBOX0
));
1101 isp_pci_rd_isr_2300(ispsoftc_t
*isp
, uint32_t *isrp
, uint16_t *semap
, uint16_t *mbox0p
)
1106 if (!(BXR2(isp
, IspVirt2Off(isp
, BIU_ISR
) & BIU2100_ISR_RISC_INT
))) {
1110 r2hisr
= BXR4(isp
, IspVirt2Off(isp
, BIU_R2HSTSLO
));
1111 isp_prt(isp
, ISP_LOGDEBUG3
, "RISC2HOST ISR 0x%x", r2hisr
);
1112 if ((r2hisr
& BIU_R2HST_INTR
) == 0) {
1116 switch (r2hisr
& BIU_R2HST_ISTAT_MASK
) {
1117 case ISPR2HST_ROM_MBX_OK
:
1118 case ISPR2HST_ROM_MBX_FAIL
:
1119 case ISPR2HST_MBX_OK
:
1120 case ISPR2HST_MBX_FAIL
:
1121 case ISPR2HST_ASYNC_EVENT
:
1122 *isrp
= r2hisr
& 0xffff;
1123 *mbox0p
= (r2hisr
>> 16);
1126 case ISPR2HST_RIO_16
:
1127 *isrp
= r2hisr
& 0xffff;
1128 *mbox0p
= ASYNC_RIO16_1
;
1131 case ISPR2HST_FPOST
:
1132 *isrp
= r2hisr
& 0xffff;
1133 *mbox0p
= ASYNC_CMD_CMPLT
;
1136 case ISPR2HST_FPOST_CTIO
:
1137 *isrp
= r2hisr
& 0xffff;
1138 *mbox0p
= ASYNC_CTIO_DONE
;
1141 case ISPR2HST_RSPQ_UPDATE
:
1142 *isrp
= r2hisr
& 0xffff;
1147 hccr
= ISP_READ(isp
, HCCR
);
1148 if (hccr
& HCCR_PAUSE
) {
1149 ISP_WRITE(isp
, HCCR
, HCCR_RESET
);
1150 isp_prt(isp
, ISP_LOGERR
, "RISC paused at interrupt (%x->%x)", hccr
, ISP_READ(isp
, HCCR
));
1151 ISP_WRITE(isp
, BIU_ICR
, 0);
1153 isp_prt(isp
, ISP_LOGERR
, "unknown interrupt 0x%x\n", r2hisr
);
1160 isp_pci_rd_isr_2400(ispsoftc_t
*isp
, uint32_t *isrp
, uint16_t *semap
, uint16_t *mbox0p
)
1164 r2hisr
= BXR4(isp
, IspVirt2Off(isp
, BIU2400_R2HSTSLO
));
1165 isp_prt(isp
, ISP_LOGDEBUG3
, "RISC2HOST ISR 0x%x", r2hisr
);
1166 if ((r2hisr
& BIU2400_R2HST_INTR
) == 0) {
1170 switch (r2hisr
& BIU2400_R2HST_ISTAT_MASK
) {
1171 case ISP2400R2HST_ROM_MBX_OK
:
1172 case ISP2400R2HST_ROM_MBX_FAIL
:
1173 case ISP2400R2HST_MBX_OK
:
1174 case ISP2400R2HST_MBX_FAIL
:
1175 case ISP2400R2HST_ASYNC_EVENT
:
1176 *isrp
= r2hisr
& 0xffff;
1177 *mbox0p
= (r2hisr
>> 16);
1180 case ISP2400R2HST_RSPQ_UPDATE
:
1181 case ISP2400R2HST_ATIO_RSPQ_UPDATE
:
1182 case ISP2400R2HST_ATIO_RQST_UPDATE
:
1183 *isrp
= r2hisr
& 0xffff;
1188 ISP_WRITE(isp
, BIU2400_HCCR
, HCCR_2400_CMD_CLEAR_RISC_INT
);
1189 isp_prt(isp
, ISP_LOGERR
, "unknown interrupt 0x%x\n", r2hisr
);
1195 isp_pci_rd_reg(ispsoftc_t
*isp
, int regoff
)
1200 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1202 * We will assume that someone has paused the RISC processor.
1204 oldconf
= BXR2(isp
, IspVirt2Off(isp
, BIU_CONF1
));
1205 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), oldconf
| BIU_PCI_CONF1_SXP
);
1206 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1208 rv
= BXR2(isp
, IspVirt2Off(isp
, regoff
));
1209 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1210 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), oldconf
);
1211 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1217 isp_pci_wr_reg(ispsoftc_t
*isp
, int regoff
, uint32_t val
)
1221 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1223 * We will assume that someone has paused the RISC processor.
1225 oldconf
= BXR2(isp
, IspVirt2Off(isp
, BIU_CONF1
));
1226 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
),
1227 oldconf
| BIU_PCI_CONF1_SXP
);
1228 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1230 BXW2(isp
, IspVirt2Off(isp
, regoff
), val
);
1231 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, regoff
), 2, -1);
1232 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1233 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), oldconf
);
1234 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1240 isp_pci_rd_reg_1080(ispsoftc_t
*isp
, int regoff
)
1242 uint32_t rv
, oc
= 0;
1244 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1247 * We will assume that someone has paused the RISC processor.
1249 oc
= BXR2(isp
, IspVirt2Off(isp
, BIU_CONF1
));
1250 tc
= oc
& ~BIU_PCI1080_CONF1_DMA
;
1251 if (regoff
& SXP_BANK1_SELECT
)
1252 tc
|= BIU_PCI1080_CONF1_SXP1
;
1254 tc
|= BIU_PCI1080_CONF1_SXP0
;
1255 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), tc
);
1256 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1257 } else if ((regoff
& _BLK_REG_MASK
) == DMA_BLOCK
) {
1258 oc
= BXR2(isp
, IspVirt2Off(isp
, BIU_CONF1
));
1259 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
),
1260 oc
| BIU_PCI1080_CONF1_DMA
);
1261 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1263 rv
= BXR2(isp
, IspVirt2Off(isp
, regoff
));
1265 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), oc
);
1266 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1272 isp_pci_wr_reg_1080(ispsoftc_t
*isp
, int regoff
, uint32_t val
)
1276 if ((regoff
& _BLK_REG_MASK
) == SXP_BLOCK
) {
1279 * We will assume that someone has paused the RISC processor.
1281 oc
= BXR2(isp
, IspVirt2Off(isp
, BIU_CONF1
));
1282 tc
= oc
& ~BIU_PCI1080_CONF1_DMA
;
1283 if (regoff
& SXP_BANK1_SELECT
)
1284 tc
|= BIU_PCI1080_CONF1_SXP1
;
1286 tc
|= BIU_PCI1080_CONF1_SXP0
;
1287 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), tc
);
1288 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1289 } else if ((regoff
& _BLK_REG_MASK
) == DMA_BLOCK
) {
1290 oc
= BXR2(isp
, IspVirt2Off(isp
, BIU_CONF1
));
1291 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
),
1292 oc
| BIU_PCI1080_CONF1_DMA
);
1293 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1295 BXW2(isp
, IspVirt2Off(isp
, regoff
), val
);
1296 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, regoff
), 2, -1);
1298 BXW2(isp
, IspVirt2Off(isp
, BIU_CONF1
), oc
);
1299 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, BIU_CONF1
), 2, -1);
1304 isp_pci_rd_reg_2400(ispsoftc_t
*isp
, int regoff
)
1307 int block
= regoff
& _BLK_REG_MASK
;
1313 return (BXR2(isp
, IspVirt2Off(isp
, regoff
)));
1315 isp_prt(isp
, ISP_LOGWARN
, "SXP_BLOCK read at 0x%x", regoff
);
1316 return (0xffffffff);
1318 isp_prt(isp
, ISP_LOGWARN
, "RISC_BLOCK read at 0x%x", regoff
);
1319 return (0xffffffff);
1321 isp_prt(isp
, ISP_LOGWARN
, "DMA_BLOCK read at 0x%x", regoff
);
1322 return (0xffffffff);
1324 isp_prt(isp
, ISP_LOGWARN
, "unknown block read at 0x%x", regoff
);
1325 return (0xffffffff);
1330 case BIU2400_FLASH_ADDR
:
1331 case BIU2400_FLASH_DATA
:
1335 case BIU2400_REQINP
:
1336 case BIU2400_REQOUTP
:
1337 case BIU2400_RSPINP
:
1338 case BIU2400_RSPOUTP
:
1339 case BIU2400_PRI_REQINP
:
1340 case BIU2400_PRI_REQOUTP
:
1341 case BIU2400_ATIO_RSPINP
:
1342 case BIU2400_ATIO_RSPOUTP
:
1347 rv
= BXR4(isp
, IspVirt2Off(isp
, regoff
));
1349 case BIU2400_R2HSTSLO
:
1350 rv
= BXR4(isp
, IspVirt2Off(isp
, regoff
));
1352 case BIU2400_R2HSTSHI
:
1353 rv
= BXR4(isp
, IspVirt2Off(isp
, regoff
)) >> 16;
1356 isp_prt(isp
, ISP_LOGERR
,
1357 "isp_pci_rd_reg_2400: unknown offset %x", regoff
);
1365 isp_pci_wr_reg_2400(ispsoftc_t
*isp
, int regoff
, uint32_t val
)
1367 int block
= regoff
& _BLK_REG_MASK
;
1373 BXW2(isp
, IspVirt2Off(isp
, regoff
), val
);
1374 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, regoff
), 2, -1);
1377 isp_prt(isp
, ISP_LOGWARN
, "SXP_BLOCK write at 0x%x", regoff
);
1380 isp_prt(isp
, ISP_LOGWARN
, "RISC_BLOCK write at 0x%x", regoff
);
1383 isp_prt(isp
, ISP_LOGWARN
, "DMA_BLOCK write at 0x%x", regoff
);
1386 isp_prt(isp
, ISP_LOGWARN
, "unknown block write at 0x%x",
1392 case BIU2400_FLASH_ADDR
:
1393 case BIU2400_FLASH_DATA
:
1397 case BIU2400_REQINP
:
1398 case BIU2400_REQOUTP
:
1399 case BIU2400_RSPINP
:
1400 case BIU2400_RSPOUTP
:
1401 case BIU2400_PRI_REQINP
:
1402 case BIU2400_PRI_REQOUTP
:
1403 case BIU2400_ATIO_RSPINP
:
1404 case BIU2400_ATIO_RSPOUTP
:
1409 BXW4(isp
, IspVirt2Off(isp
, regoff
), val
);
1410 MEMORYBARRIER(isp
, SYNC_REG
, IspVirt2Off(isp
, regoff
), 4, -1);
1413 isp_prt(isp
, ISP_LOGERR
,
1414 "isp_pci_wr_reg_2400: bad offset 0x%x", regoff
);
1427 static void imc(void *, bus_dma_segment_t
*, int, int);
1428 static void imc1(void *, bus_dma_segment_t
*, int, int);
1431 imc(void *arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
1433 struct imush
*imushp
= (struct imush
*) arg
;
1436 imushp
->error
= error
;
1440 imushp
->error
= EINVAL
;
1443 isp_prt(imushp
->isp
, ISP_LOGDEBUG0
, "request/result area @ 0x%jx/0x%jx", (uintmax_t) segs
->ds_addr
, (uintmax_t) segs
->ds_len
);
1444 imushp
->isp
->isp_rquest
= imushp
->vbase
;
1445 imushp
->isp
->isp_rquest_dma
= segs
->ds_addr
;
1446 segs
->ds_addr
+= ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(imushp
->isp
));
1447 imushp
->vbase
+= ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(imushp
->isp
));
1448 imushp
->isp
->isp_result_dma
= segs
->ds_addr
;
1449 imushp
->isp
->isp_result
= imushp
->vbase
;
1451 #ifdef ISP_TARGET_MODE
1452 if (IS_24XX(imushp
->isp
)) {
1453 segs
->ds_addr
+= ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(imushp
->isp
));
1454 imushp
->vbase
+= ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(imushp
->isp
));
1455 imushp
->isp
->isp_atioq_dma
= segs
->ds_addr
;
1456 imushp
->isp
->isp_atioq
= imushp
->vbase
;
1462 imc1(void *arg
, bus_dma_segment_t
*segs
, int nseg
, int error
)
1464 struct imush
*imushp
= (struct imush
*) arg
;
1466 imushp
->error
= error
;
1470 imushp
->error
= EINVAL
;
1473 isp_prt(imushp
->isp
, ISP_LOGDEBUG0
, "scdma @ 0x%jx/0x%jx", (uintmax_t) segs
->ds_addr
, (uintmax_t) segs
->ds_len
);
1474 FCPARAM(imushp
->isp
, imushp
->chan
)->isp_scdma
= segs
->ds_addr
;
1475 FCPARAM(imushp
->isp
, imushp
->chan
)->isp_scratch
= imushp
->vbase
;
1479 isp_pci_mbxdma(ispsoftc_t
*isp
)
1483 int i
, error
, ns
, cmap
= 0;
1484 bus_size_t slim
; /* segment size */
1485 bus_addr_t llim
; /* low limit of unavailable dma */
1486 bus_addr_t hlim
; /* high limit of unavailable dma */
1490 * Already been here? If so, leave...
1492 if (isp
->isp_rquest
) {
1497 if (isp
->isp_maxcmds
== 0) {
1498 isp_prt(isp
, ISP_LOGERR
, "maxcmds not set");
1503 hlim
= BUS_SPACE_MAXADDR
;
1504 if (IS_ULTRA2(isp
) || IS_FC(isp
) || IS_1240(isp
)) {
1505 if (sizeof (bus_size_t
) > 4) {
1506 slim
= (bus_size_t
) (1ULL << 32);
1508 slim
= (bus_size_t
) (1UL << 31);
1510 llim
= BUS_SPACE_MAXADDR
;
1512 llim
= BUS_SPACE_MAXADDR_32BIT
;
1516 len
= isp
->isp_maxcmds
* sizeof (struct isp_pcmd
);
1517 isp
->isp_osinfo
.pcmd_pool
= (struct isp_pcmd
*) kmalloc(len
, M_DEVBUF
, M_WAITOK
| M_ZERO
);
1518 if (isp
->isp_osinfo
.pcmd_pool
== NULL
) {
1519 isp_prt(isp
, ISP_LOGERR
, "cannot allocate pcmds");
1525 * XXX: We don't really support 64 bit target mode for parallel scsi yet
1527 #ifdef ISP_TARGET_MODE
1528 if (IS_SCSI(isp
) && sizeof (bus_addr_t
) > 4) {
1529 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1530 isp_prt(isp
, ISP_LOGERR
, "we cannot do DAC for SPI cards yet");
1536 if (isp_dma_tag_create(NULL
, 1, slim
, llim
, hlim
, NULL
, NULL
, BUS_SPACE_MAXSIZE
, ISP_NSEGS
, slim
, 0, &isp
->isp_osinfo
.dmat
)) {
1537 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1539 isp_prt(isp
, ISP_LOGERR
, "could not create master dma tag");
1543 len
= sizeof (isp_hdl_t
) * isp
->isp_maxcmds
;
1544 isp
->isp_xflist
= (isp_hdl_t
*) kmalloc(len
, M_DEVBUF
, M_WAITOK
| M_ZERO
);
1545 if (isp
->isp_xflist
== NULL
) {
1546 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1548 isp_prt(isp
, ISP_LOGERR
, "cannot alloc xflist array");
1551 for (len
= 0; len
< isp
->isp_maxcmds
- 1; len
++) {
1552 isp
->isp_xflist
[len
].cmd
= &isp
->isp_xflist
[len
+1];
1554 isp
->isp_xffree
= isp
->isp_xflist
;
1555 #ifdef ISP_TARGET_MODE
1556 len
= sizeof (isp_hdl_t
) * isp
->isp_maxcmds
;
1557 isp
->isp_tgtlist
= (isp_hdl_t
*) kmalloc(len
, M_DEVBUF
, M_WAITOK
| M_ZERO
);
1558 if (isp
->isp_tgtlist
== NULL
) {
1559 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1560 kfree(isp
->isp_xflist
, M_DEVBUF
);
1562 isp_prt(isp
, ISP_LOGERR
, "cannot alloc tgtlist array");
1565 for (len
= 0; len
< isp
->isp_maxcmds
- 1; len
++) {
1566 isp
->isp_tgtlist
[len
].cmd
= &isp
->isp_tgtlist
[len
+1];
1568 isp
->isp_tgtfree
= isp
->isp_tgtlist
;
1572 * Allocate and map the request and result queues (and ATIO queue
1573 * if we're a 2400 supporting target mode).
1575 len
= ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp
));
1576 len
+= ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp
));
1577 #ifdef ISP_TARGET_MODE
1579 len
+= ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp
));
1583 ns
= (len
/ PAGE_SIZE
) + 1;
1586 * Create a tag for the control spaces. We don't always need this
1587 * to be 32 bits, but we do this for simplicity and speed's sake.
1589 if (isp_dma_tag_create(isp
->isp_osinfo
.dmat
, QENTRY_LEN
, slim
, BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
, len
, ns
, slim
, 0, &isp
->isp_osinfo
.cdmat
)) {
1590 isp_prt(isp
, ISP_LOGERR
, "cannot create a dma tag for control spaces");
1591 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1592 kfree(isp
->isp_xflist
, M_DEVBUF
);
1593 #ifdef ISP_TARGET_MODE
1594 kfree(isp
->isp_tgtlist
, M_DEVBUF
);
1600 if (bus_dmamem_alloc(isp
->isp_osinfo
.cdmat
, (void **)&base
, BUS_DMA_NOWAIT
| BUS_DMA_COHERENT
, &isp
->isp_osinfo
.cdmap
) != 0) {
1601 isp_prt(isp
, ISP_LOGERR
, "cannot allocate %d bytes of CCB memory", len
);
1602 bus_dma_tag_destroy(isp
->isp_osinfo
.cdmat
);
1603 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1604 kfree(isp
->isp_xflist
, M_DEVBUF
);
1605 #ifdef ISP_TARGET_MODE
1606 kfree(isp
->isp_tgtlist
, M_DEVBUF
);
1617 bus_dmamap_load(isp
->isp_osinfo
.cdmat
, isp
->isp_osinfo
.cdmap
, base
, len
, imc
, &im
, 0);
1619 isp_prt(isp
, ISP_LOGERR
, "error %d loading dma map for control areas", im
.error
);
1624 for (cmap
= 0; cmap
< isp
->isp_nchan
; cmap
++) {
1625 struct isp_fc
*fc
= ISP_FC_PC(isp
, cmap
);
1626 if (isp_dma_tag_create(isp
->isp_osinfo
.dmat
, 64, slim
, BUS_SPACE_MAXADDR_32BIT
, BUS_SPACE_MAXADDR
, NULL
, NULL
, ISP_FC_SCRLEN
, 1, slim
, 0, &fc
->tdmat
)) {
1629 if (bus_dmamem_alloc(fc
->tdmat
, (void **)&base
, BUS_DMA_NOWAIT
| BUS_DMA_COHERENT
, &fc
->tdmap
) != 0) {
1630 bus_dma_tag_destroy(fc
->tdmat
);
1637 bus_dmamap_load(fc
->tdmat
, fc
->tdmap
, base
, ISP_FC_SCRLEN
, imc1
, &im
, 0);
1639 bus_dmamem_free(fc
->tdmat
, base
, fc
->tdmap
);
1640 bus_dma_tag_destroy(fc
->tdmat
);
1646 for (i
= 0; i
< isp
->isp_maxcmds
; i
++) {
1647 struct isp_pcmd
*pcmd
= &isp
->isp_osinfo
.pcmd_pool
[i
];
1648 error
= bus_dmamap_create(isp
->isp_osinfo
.dmat
, 0, &pcmd
->dmap
);
1650 isp_prt(isp
, ISP_LOGERR
, "error %d creating per-cmd DMA maps", error
);
1652 bus_dmamap_destroy(isp
->isp_osinfo
.dmat
, isp
->isp_osinfo
.pcmd_pool
[i
].dmap
);
1656 callout_init(&pcmd
->wdog
);
1657 if (i
== isp
->isp_maxcmds
-1) {
1660 pcmd
->next
= &isp
->isp_osinfo
.pcmd_pool
[i
+1];
1663 isp
->isp_osinfo
.pcmd_free
= &isp
->isp_osinfo
.pcmd_pool
[0];
1668 while (--cmap
>= 0) {
1669 struct isp_fc
*fc
= ISP_FC_PC(isp
, cmap
);
1670 bus_dmamem_free(fc
->tdmat
, base
, fc
->tdmap
);
1671 bus_dma_tag_destroy(fc
->tdmat
);
1673 bus_dmamem_free(isp
->isp_osinfo
.cdmat
, base
, isp
->isp_osinfo
.cdmap
);
1674 bus_dma_tag_destroy(isp
->isp_osinfo
.cdmat
);
1675 kfree(isp
->isp_xflist
, M_DEVBUF
);
1676 #ifdef ISP_TARGET_MODE
1677 kfree(isp
->isp_tgtlist
, M_DEVBUF
);
1679 kfree(isp
->isp_osinfo
.pcmd_pool
, M_DEVBUF
);
1680 isp
->isp_rquest
= NULL
;
1688 void *rq
; /* original request */
1693 #define MUSHERR_NOQENTRIES -2
1695 #ifdef ISP_TARGET_MODE
1696 static void tdma2_2(void *, bus_dma_segment_t
*, int, bus_size_t
, int);
1697 static void tdma2(void *, bus_dma_segment_t
*, int, int);
1700 tdma2_2(void *arg
, bus_dma_segment_t
*dm_segs
, int nseg
, bus_size_t mapsize
, int error
)
1704 mp
->mapsize
= mapsize
;
1705 tdma2(arg
, dm_segs
, nseg
, error
);
1709 tdma2(void *arg
, bus_dma_segment_t
*dm_segs
, int nseg
, int error
)
1713 struct ccb_scsiio
*csio
;
1717 mp
= (mush_t
*) arg
;
1722 csio
= mp
->cmd_token
;
1726 if (sizeof (bus_addr_t
) > 4) {
1727 if (nseg
>= ISP_NSEG64_MAX
) {
1728 isp_prt(isp
, ISP_LOGERR
, "number of segments (%d) exceed maximum we can support (%d)", nseg
, ISP_NSEG64_MAX
);
1732 if (rq
->req_header
.rqs_entry_type
== RQSTYPE_CTIO2
) {
1733 rq
->req_header
.rqs_entry_type
= RQSTYPE_CTIO3
;
1736 if (nseg
>= ISP_NSEG_MAX
) {
1737 isp_prt(isp
, ISP_LOGERR
, "number of segments (%d) exceed maximum we can support (%d)", nseg
, ISP_NSEG_MAX
);
1742 if ((csio
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_IN
) {
1743 bus_dmamap_sync(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
, BUS_DMASYNC_PREWRITE
);
1744 ddir
= ISP_TO_DEVICE
;
1745 } else if ((csio
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_OUT
) {
1746 bus_dmamap_sync(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
, BUS_DMASYNC_PREREAD
);
1747 ddir
= ISP_FROM_DEVICE
;
1759 if (isp_send_tgt_cmd(isp
, rq
, dm_segs
, nseg
, XS_XFRLEN(csio
), ddir
, &csio
->sense_data
, csio
->sense_len
) != CMD_QUEUED
) {
1760 mp
->error
= MUSHERR_NOQENTRIES
;
1765 static void dma2_2(void *, bus_dma_segment_t
*, int, bus_size_t
, int);
1766 static void dma2(void *, bus_dma_segment_t
*, int, int);
1769 dma2_2(void *arg
, bus_dma_segment_t
*dm_segs
, int nseg
, bus_size_t mapsize
, int error
)
1773 mp
->mapsize
= mapsize
;
1774 dma2(arg
, dm_segs
, nseg
, error
);
1778 dma2(void *arg
, bus_dma_segment_t
*dm_segs
, int nseg
, int error
)
1782 struct ccb_scsiio
*csio
;
1786 mp
= (mush_t
*) arg
;
1791 csio
= mp
->cmd_token
;
1795 if (sizeof (bus_addr_t
) > 4) {
1796 if (nseg
>= ISP_NSEG64_MAX
) {
1797 isp_prt(isp
, ISP_LOGERR
, "number of segments (%d) exceed maximum we can support (%d)", nseg
, ISP_NSEG64_MAX
);
1801 if (rq
->req_header
.rqs_entry_type
== RQSTYPE_T2RQS
) {
1802 rq
->req_header
.rqs_entry_type
= RQSTYPE_T3RQS
;
1803 } else if (rq
->req_header
.rqs_entry_type
== RQSTYPE_REQUEST
) {
1804 rq
->req_header
.rqs_entry_type
= RQSTYPE_A64
;
1807 if (nseg
>= ISP_NSEG_MAX
) {
1808 isp_prt(isp
, ISP_LOGERR
, "number of segments (%d) exceed maximum we can support (%d)", nseg
, ISP_NSEG_MAX
);
1813 if ((csio
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_IN
) {
1814 bus_dmamap_sync(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
, BUS_DMASYNC_PREREAD
);
1815 ddir
= ISP_FROM_DEVICE
;
1816 } else if ((csio
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_OUT
) {
1817 bus_dmamap_sync(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
, BUS_DMASYNC_PREWRITE
);
1818 ddir
= ISP_TO_DEVICE
;
1828 if (isp_send_cmd(isp
, rq
, dm_segs
, nseg
, XS_XFRLEN(csio
), ddir
) != CMD_QUEUED
) {
1829 mp
->error
= MUSHERR_NOQENTRIES
;
1834 isp_pci_dmasetup(ispsoftc_t
*isp
, struct ccb_scsiio
*csio
, void *ff
)
1837 void (*eptr
)(void *, bus_dma_segment_t
*, int, int);
1838 void (*eptr2
)(void *, bus_dma_segment_t
*, int, bus_size_t
, int);
1842 mp
->cmd_token
= csio
;
1847 #ifdef ISP_TARGET_MODE
1848 if (csio
->ccb_h
.func_code
== XPT_CONT_TARGET_IO
) {
1859 if ((csio
->ccb_h
.flags
& CAM_DIR_MASK
) == CAM_DIR_NONE
|| (csio
->dxfer_len
== 0)) {
1860 (*eptr
)(mp
, NULL
, 0, 0);
1861 } else if ((csio
->ccb_h
.flags
& CAM_SCATTER_VALID
) == 0) {
1862 if ((csio
->ccb_h
.flags
& CAM_DATA_PHYS
) == 0) {
1864 error
= bus_dmamap_load(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
, csio
->data_ptr
, csio
->dxfer_len
, eptr
, mp
, 0);
1866 xpt_print(csio
->ccb_h
.path
, "%s: bus_dmamap_load " "ptr %p len %d returned %d\n", __func__
, csio
->data_ptr
, csio
->dxfer_len
, error
);
1869 if (error
== EINPROGRESS
) {
1870 bus_dmamap_unload(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
);
1872 isp_prt(isp
, ISP_LOGERR
, "deferred dma allocation not supported");
1873 } else if (error
&& mp
->error
== 0) {
1875 isp_prt(isp
, ISP_LOGERR
, "error %d in dma mapping code", error
);
1880 /* Pointer to physical buffer */
1881 struct bus_dma_segment seg
;
1882 seg
.ds_addr
= (bus_addr_t
)(vm_offset_t
)csio
->data_ptr
;
1883 seg
.ds_len
= csio
->dxfer_len
;
1884 (*eptr
)(mp
, &seg
, 1, 0);
1887 struct bus_dma_segment
*segs
;
1889 if ((csio
->ccb_h
.flags
& CAM_DATA_PHYS
) != 0) {
1890 isp_prt(isp
, ISP_LOGERR
, "Physical segment pointers unsupported");
1892 } else if ((csio
->ccb_h
.flags
& CAM_SG_LIST_PHYS
) == 0) {
1897 * We're taking advantage of the fact that
1898 * the pointer/length sizes and layout of the iovec
1899 * structure are the same as the bus_dma_segment
1900 * structure. This might be a little dangerous,
1901 * but only if they change the structures, which
1904 KASSERT((sizeof (sguio
.uio_iov
) == sizeof (csio
->data_ptr
) &&
1905 sizeof (sguio
.uio_iovcnt
) >= sizeof (csio
->sglist_cnt
) &&
1906 sizeof (sguio
.uio_resid
) >= sizeof (csio
->dxfer_len
)), ("Ken's assumption failed"));
1907 sguio
.uio_iov
= (struct iovec
*)csio
->data_ptr
;
1908 sguio
.uio_iovcnt
= csio
->sglist_cnt
;
1909 sguio
.uio_resid
= csio
->dxfer_len
;
1910 sguio
.uio_segflg
= UIO_SYSSPACE
;
1912 error
= bus_dmamap_load_uio(isp
->isp_osinfo
.dmat
, PISP_PCMD(csio
)->dmap
, &sguio
, eptr2
, mp
, 0);
1914 if (error
!= 0 && mp
->error
== 0) {
1915 isp_prt(isp
, ISP_LOGERR
, "error %d in dma mapping code", error
);
1919 /* Just use the segments provided */
1920 segs
= (struct bus_dma_segment
*) csio
->data_ptr
;
1921 (*eptr
)(mp
, segs
, csio
->sglist_cnt
, 0);
1925 int retval
= CMD_COMPLETE
;
1926 if (mp
->error
== MUSHERR_NOQENTRIES
) {
1927 retval
= CMD_EAGAIN
;
1928 } else if (mp
->error
== EFBIG
) {
1929 XS_SETERR(csio
, CAM_REQ_TOO_BIG
);
1930 } else if (mp
->error
== EINVAL
) {
1931 XS_SETERR(csio
, CAM_REQ_INVALID
);
1933 XS_SETERR(csio
, CAM_UNREC_HBA_ERROR
);
1937 return (CMD_QUEUED
);
1941 isp_pci_reset0(ispsoftc_t
*isp
)
1943 ISP_DISABLE_INTS(isp
);
1947 isp_pci_reset1(ispsoftc_t
*isp
)
1949 if (!IS_24XX(isp
)) {
1950 /* Make sure the BIOS is disabled */
1951 isp_pci_wr_reg(isp
, HCCR
, PCI_HCCR_CMD_BIOS
);
1953 /* and enable interrupts */
1954 ISP_ENABLE_INTS(isp
);
1958 isp_pci_dumpregs(ispsoftc_t
*isp
, const char *msg
)
1960 struct isp_pcisoftc
*pcs
= (struct isp_pcisoftc
*)isp
;
1962 kprintf("%s: %s\n", device_get_nameunit(isp
->isp_dev
), msg
);
1964 kprintf("%s:\n", device_get_nameunit(isp
->isp_dev
));
1966 kprintf(" biu_conf1=%x", ISP_READ(isp
, BIU_CONF1
));
1968 kprintf(" biu_csr=%x", ISP_READ(isp
, BIU2100_CSR
));
1969 kprintf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp
, BIU_ICR
),
1970 ISP_READ(isp
, BIU_ISR
), ISP_READ(isp
, BIU_SEMA
));
1971 kprintf("risc_hccr=%x\n", ISP_READ(isp
, HCCR
));
1975 ISP_WRITE(isp
, HCCR
, HCCR_CMD_PAUSE
);
1976 kprintf(" cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n",
1977 ISP_READ(isp
, CDMA_CONF
), ISP_READ(isp
, CDMA_STATUS
),
1978 ISP_READ(isp
, CDMA_FIFO_STS
));
1979 kprintf(" ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n",
1980 ISP_READ(isp
, DDMA_CONF
), ISP_READ(isp
, DDMA_STATUS
),
1981 ISP_READ(isp
, DDMA_FIFO_STS
));
1982 kprintf(" sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n",
1983 ISP_READ(isp
, SXP_INTERRUPT
),
1984 ISP_READ(isp
, SXP_GROSS_ERR
),
1985 ISP_READ(isp
, SXP_PINS_CTRL
));
1986 ISP_WRITE(isp
, HCCR
, HCCR_CMD_RELEASE
);
1988 kprintf(" mbox regs: %x %x %x %x %x\n",
1989 ISP_READ(isp
, OUTMAILBOX0
), ISP_READ(isp
, OUTMAILBOX1
),
1990 ISP_READ(isp
, OUTMAILBOX2
), ISP_READ(isp
, OUTMAILBOX3
),
1991 ISP_READ(isp
, OUTMAILBOX4
));
1992 kprintf(" PCI Status Command/Status=%x\n",
1993 pci_read_config(pcs
->pci_dev
, PCIR_COMMAND
, 1));