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
27 * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
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 <dev/pci/pcireg.h>
42 #include <dev/pci/pcivar.h>
43 #include <machine/bus.h>
44 #include <machine/resource.h>
46 #include <sys/malloc.h>
50 #include <dev/ofw/openfirm.h>
51 #include <machine/ofw_machdep.h>
54 #include <dev/isp/isp_freebsd.h>
56 static uint32_t isp_pci_rd_reg(ispsoftc_t *, int);
57 static void isp_pci_wr_reg(ispsoftc_t *, int, uint32_t);
58 static uint32_t isp_pci_rd_reg_1080(ispsoftc_t *, int);
59 static void isp_pci_wr_reg_1080(ispsoftc_t *, int, uint32_t);
60 static uint32_t isp_pci_rd_reg_2400(ispsoftc_t *, int);
61 static void isp_pci_wr_reg_2400(ispsoftc_t *, int, uint32_t);
62 static uint32_t isp_pci_rd_reg_2600(ispsoftc_t *, int);
63 static void isp_pci_wr_reg_2600(ispsoftc_t *, int, uint32_t);
64 static int isp_pci_rd_isr(ispsoftc_t *, uint16_t *, uint16_t *, uint16_t *);
65 static int isp_pci_rd_isr_2300(ispsoftc_t *, uint16_t *, uint16_t *, uint16_t *);
66 static int isp_pci_rd_isr_2400(ispsoftc_t *, uint16_t *, uint16_t *, uint16_t *);
67 static int isp_pci_mbxdma(ispsoftc_t *);
68 static int isp_pci_dmasetup(ispsoftc_t *, XS_T *, void *);
71 static void isp_pci_reset0(ispsoftc_t *);
72 static void isp_pci_reset1(ispsoftc_t *);
73 static void isp_pci_dumpregs(ispsoftc_t *, const char *);
75 static struct ispmdvec mdvec = {
81 isp_common_dmateardown,
86 BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
89 static struct ispmdvec mdvec_1080 = {
95 isp_common_dmateardown,
100 BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
103 static struct ispmdvec mdvec_12160 = {
109 isp_common_dmateardown,
114 BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64
117 static struct ispmdvec mdvec_2100 = {
123 isp_common_dmateardown,
129 static struct ispmdvec mdvec_2200 = {
135 isp_common_dmateardown,
141 static struct ispmdvec mdvec_2300 = {
147 isp_common_dmateardown,
153 static struct ispmdvec mdvec_2400 = {
159 isp_common_dmateardown,
165 static struct ispmdvec mdvec_2500 = {
171 isp_common_dmateardown,
177 static struct ispmdvec mdvec_2600 = {
183 isp_common_dmateardown,
189 #ifndef PCIM_CMD_INVEN
190 #define PCIM_CMD_INVEN 0x10
192 #ifndef PCIM_CMD_BUSMASTEREN
193 #define PCIM_CMD_BUSMASTEREN 0x0004
195 #ifndef PCIM_CMD_PERRESPEN
196 #define PCIM_CMD_PERRESPEN 0x0040
198 #ifndef PCIM_CMD_SEREN
199 #define PCIM_CMD_SEREN 0x0100
201 #ifndef PCIM_CMD_INTX_DISABLE
202 #define PCIM_CMD_INTX_DISABLE 0x0400
206 #define PCIR_COMMAND 0x04
209 #ifndef PCIR_CACHELNSZ
210 #define PCIR_CACHELNSZ 0x0c
213 #ifndef PCIR_LATTIMER
214 #define PCIR_LATTIMER 0x0d
218 #define PCIR_ROMADDR 0x30
221 #ifndef PCI_VENDOR_QLOGIC
222 #define PCI_VENDOR_QLOGIC 0x1077
225 #ifndef PCI_PRODUCT_QLOGIC_ISP1020
226 #define PCI_PRODUCT_QLOGIC_ISP1020 0x1020
229 #ifndef PCI_PRODUCT_QLOGIC_ISP1080
230 #define PCI_PRODUCT_QLOGIC_ISP1080 0x1080
233 #ifndef PCI_PRODUCT_QLOGIC_ISP10160
234 #define PCI_PRODUCT_QLOGIC_ISP10160 0x1016
237 #ifndef PCI_PRODUCT_QLOGIC_ISP12160
238 #define PCI_PRODUCT_QLOGIC_ISP12160 0x1216
241 #ifndef PCI_PRODUCT_QLOGIC_ISP1240
242 #define PCI_PRODUCT_QLOGIC_ISP1240 0x1240
245 #ifndef PCI_PRODUCT_QLOGIC_ISP1280
246 #define PCI_PRODUCT_QLOGIC_ISP1280 0x1280
249 #ifndef PCI_PRODUCT_QLOGIC_ISP2100
250 #define PCI_PRODUCT_QLOGIC_ISP2100 0x2100
253 #ifndef PCI_PRODUCT_QLOGIC_ISP2200
254 #define PCI_PRODUCT_QLOGIC_ISP2200 0x2200
257 #ifndef PCI_PRODUCT_QLOGIC_ISP2300
258 #define PCI_PRODUCT_QLOGIC_ISP2300 0x2300
261 #ifndef PCI_PRODUCT_QLOGIC_ISP2312
262 #define PCI_PRODUCT_QLOGIC_ISP2312 0x2312
265 #ifndef PCI_PRODUCT_QLOGIC_ISP2322
266 #define PCI_PRODUCT_QLOGIC_ISP2322 0x2322
269 #ifndef PCI_PRODUCT_QLOGIC_ISP2422
270 #define PCI_PRODUCT_QLOGIC_ISP2422 0x2422
273 #ifndef PCI_PRODUCT_QLOGIC_ISP2432
274 #define PCI_PRODUCT_QLOGIC_ISP2432 0x2432
277 #ifndef PCI_PRODUCT_QLOGIC_ISP2532
278 #define PCI_PRODUCT_QLOGIC_ISP2532 0x2532
281 #ifndef PCI_PRODUCT_QLOGIC_ISP6312
282 #define PCI_PRODUCT_QLOGIC_ISP6312 0x6312
285 #ifndef PCI_PRODUCT_QLOGIC_ISP6322
286 #define PCI_PRODUCT_QLOGIC_ISP6322 0x6322
289 #ifndef PCI_PRODUCT_QLOGIC_ISP5432
290 #define PCI_PRODUCT_QLOGIC_ISP5432 0x5432
293 #ifndef PCI_PRODUCT_QLOGIC_ISP2031
294 #define PCI_PRODUCT_QLOGIC_ISP2031 0x2031
297 #ifndef PCI_PRODUCT_QLOGIC_ISP8031
298 #define PCI_PRODUCT_QLOGIC_ISP8031 0x8031
301 #define PCI_QLOGIC_ISP5432 \
302 ((PCI_PRODUCT_QLOGIC_ISP5432 << 16) | PCI_VENDOR_QLOGIC)
304 #define PCI_QLOGIC_ISP1020 \
305 ((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
307 #define PCI_QLOGIC_ISP1080 \
308 ((PCI_PRODUCT_QLOGIC_ISP1080 << 16) | PCI_VENDOR_QLOGIC)
310 #define PCI_QLOGIC_ISP10160 \
311 ((PCI_PRODUCT_QLOGIC_ISP10160 << 16) | PCI_VENDOR_QLOGIC)
313 #define PCI_QLOGIC_ISP12160 \
314 ((PCI_PRODUCT_QLOGIC_ISP12160 << 16) | PCI_VENDOR_QLOGIC)
316 #define PCI_QLOGIC_ISP1240 \
317 ((PCI_PRODUCT_QLOGIC_ISP1240 << 16) | PCI_VENDOR_QLOGIC)
319 #define PCI_QLOGIC_ISP1280 \
320 ((PCI_PRODUCT_QLOGIC_ISP1280 << 16) | PCI_VENDOR_QLOGIC)
322 #define PCI_QLOGIC_ISP2100 \
323 ((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC)
325 #define PCI_QLOGIC_ISP2200 \
326 ((PCI_PRODUCT_QLOGIC_ISP2200 << 16) | PCI_VENDOR_QLOGIC)
328 #define PCI_QLOGIC_ISP2300 \
329 ((PCI_PRODUCT_QLOGIC_ISP2300 << 16) | PCI_VENDOR_QLOGIC)
331 #define PCI_QLOGIC_ISP2312 \
332 ((PCI_PRODUCT_QLOGIC_ISP2312 << 16) | PCI_VENDOR_QLOGIC)
334 #define PCI_QLOGIC_ISP2322 \
335 ((PCI_PRODUCT_QLOGIC_ISP2322 << 16) | PCI_VENDOR_QLOGIC)
337 #define PCI_QLOGIC_ISP2422 \
338 ((PCI_PRODUCT_QLOGIC_ISP2422 << 16) | PCI_VENDOR_QLOGIC)
340 #define PCI_QLOGIC_ISP2432 \
341 ((PCI_PRODUCT_QLOGIC_ISP2432 << 16) | PCI_VENDOR_QLOGIC)
343 #define PCI_QLOGIC_ISP2532 \
344 ((PCI_PRODUCT_QLOGIC_ISP2532 << 16) | PCI_VENDOR_QLOGIC)
346 #define PCI_QLOGIC_ISP6312 \
347 ((PCI_PRODUCT_QLOGIC_ISP6312 << 16) | PCI_VENDOR_QLOGIC)
349 #define PCI_QLOGIC_ISP6322 \
350 ((PCI_PRODUCT_QLOGIC_ISP6322 << 16) | PCI_VENDOR_QLOGIC)
352 #define PCI_QLOGIC_ISP2031 \
353 ((PCI_PRODUCT_QLOGIC_ISP2031 << 16) | PCI_VENDOR_QLOGIC)
355 #define PCI_QLOGIC_ISP8031 \
356 ((PCI_PRODUCT_QLOGIC_ISP8031 << 16) | PCI_VENDOR_QLOGIC)
359 * Odd case for some AMI raid cards... We need to *not* attach to this.
361 #define AMI_RAID_SUBVENDOR_ID 0x101e
363 #define PCI_DFLT_LTNCY 0x40
364 #define PCI_DFLT_LNSZ 0x10
366 static int isp_pci_probe (device_t);
367 static int isp_pci_attach (device_t);
368 static int isp_pci_detach (device_t);
371 #define ISP_PCD(isp) ((struct isp_pcisoftc *)isp)->pci_dev
372 struct isp_pcisoftc {
375 struct resource * regs;
376 struct resource * regs1;
377 struct resource * regs2;
387 int16_t pci_poff[_NREG_BLKS];
393 static device_method_t isp_pci_methods[] = {
394 /* Device interface */
395 DEVMETHOD(device_probe, isp_pci_probe),
396 DEVMETHOD(device_attach, isp_pci_attach),
397 DEVMETHOD(device_detach, isp_pci_detach),
401 static driver_t isp_pci_driver = {
402 "isp", isp_pci_methods, sizeof (struct isp_pcisoftc)
404 static devclass_t isp_devclass;
405 DRIVER_MODULE(isp, pci, isp_pci_driver, isp_devclass, 0, 0);
406 MODULE_DEPEND(isp, cam, 1, 1, 1);
407 MODULE_DEPEND(isp, firmware, 1, 1, 1);
408 static int isp_nvports = 0;
411 isp_pci_probe(device_t dev)
413 switch ((pci_get_device(dev) << 16) | (pci_get_vendor(dev))) {
414 case PCI_QLOGIC_ISP1020:
415 device_set_desc(dev, "Qlogic ISP 1020/1040 PCI SCSI Adapter");
417 case PCI_QLOGIC_ISP1080:
418 device_set_desc(dev, "Qlogic ISP 1080 PCI SCSI Adapter");
420 case PCI_QLOGIC_ISP1240:
421 device_set_desc(dev, "Qlogic ISP 1240 PCI SCSI Adapter");
423 case PCI_QLOGIC_ISP1280:
424 device_set_desc(dev, "Qlogic ISP 1280 PCI SCSI Adapter");
426 case PCI_QLOGIC_ISP10160:
427 device_set_desc(dev, "Qlogic ISP 10160 PCI SCSI Adapter");
429 case PCI_QLOGIC_ISP12160:
430 if (pci_get_subvendor(dev) == AMI_RAID_SUBVENDOR_ID) {
433 device_set_desc(dev, "Qlogic ISP 12160 PCI SCSI Adapter");
435 case PCI_QLOGIC_ISP2100:
436 device_set_desc(dev, "Qlogic ISP 2100 PCI FC-AL Adapter");
438 case PCI_QLOGIC_ISP2200:
439 device_set_desc(dev, "Qlogic ISP 2200 PCI FC-AL Adapter");
441 case PCI_QLOGIC_ISP2300:
442 device_set_desc(dev, "Qlogic ISP 2300 PCI FC-AL Adapter");
444 case PCI_QLOGIC_ISP2312:
445 device_set_desc(dev, "Qlogic ISP 2312 PCI FC-AL Adapter");
447 case PCI_QLOGIC_ISP2322:
448 device_set_desc(dev, "Qlogic ISP 2322 PCI FC-AL Adapter");
450 case PCI_QLOGIC_ISP2422:
451 device_set_desc(dev, "Qlogic ISP 2422 PCI FC-AL Adapter");
453 case PCI_QLOGIC_ISP2432:
454 device_set_desc(dev, "Qlogic ISP 2432 PCI FC-AL Adapter");
456 case PCI_QLOGIC_ISP2532:
457 device_set_desc(dev, "Qlogic ISP 2532 PCI FC-AL Adapter");
459 case PCI_QLOGIC_ISP5432:
460 device_set_desc(dev, "Qlogic ISP 5432 PCI FC-AL Adapter");
462 case PCI_QLOGIC_ISP6312:
463 device_set_desc(dev, "Qlogic ISP 6312 PCI FC-AL Adapter");
465 case PCI_QLOGIC_ISP6322:
466 device_set_desc(dev, "Qlogic ISP 6322 PCI FC-AL Adapter");
468 case PCI_QLOGIC_ISP2031:
469 device_set_desc(dev, "Qlogic ISP 2031 PCI FC-AL Adapter");
471 case PCI_QLOGIC_ISP8031:
472 device_set_desc(dev, "Qlogic ISP 8031 PCI FCoE Adapter");
477 if (isp_announced == 0 && bootverbose) {
478 printf("Qlogic ISP Driver, FreeBSD Version %d.%d, "
479 "Core Version %d.%d\n",
480 ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR,
481 ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR);
485 * XXXX: Here is where we might load the f/w module
486 * XXXX: (or increase a reference count to it).
488 return (BUS_PROBE_DEFAULT);
492 isp_get_generic_options(device_t dev, ispsoftc_t *isp)
497 if (resource_int_value(device_get_name(dev), device_get_unit(dev), "fwload_disable", &tval) == 0 && tval != 0) {
498 isp->isp_confopts |= ISP_CFG_NORELOAD;
501 if (resource_int_value(device_get_name(dev), device_get_unit(dev), "ignore_nvram", &tval) == 0 && tval != 0) {
502 isp->isp_confopts |= ISP_CFG_NONVRAM;
505 (void) resource_int_value(device_get_name(dev), device_get_unit(dev), "debug", &tval);
507 isp->isp_dblev = tval;
509 isp->isp_dblev = ISP_LOGWARN|ISP_LOGERR;
512 isp->isp_dblev |= ISP_LOGCONFIG|ISP_LOGINFO;
515 (void) resource_int_value(device_get_name(dev), device_get_unit(dev), "vports", &tval);
516 if (tval > 0 && tval <= 254) {
520 (void) resource_int_value(device_get_name(dev), device_get_unit(dev), "quickboot_time", &tval);
521 isp_quickboot_time = tval;
525 isp_get_specific_options(device_t dev, int chan, ispsoftc_t *isp)
529 char prefix[12], name[16];
534 snprintf(prefix, sizeof(prefix), "chan%d.", chan);
535 snprintf(name, sizeof(name), "%siid", prefix);
536 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
539 ISP_FC_PC(isp, chan)->default_id = 109 - chan;
542 ISP_SPI_PC(isp, chan)->iid = OF_getscsinitid(dev);
544 ISP_SPI_PC(isp, chan)->iid = 7;
549 ISP_FC_PC(isp, chan)->default_id = tval - chan;
551 ISP_SPI_PC(isp, chan)->iid = tval;
553 isp->isp_confopts |= ISP_CFG_OWNLOOPID;
560 snprintf(name, sizeof(name), "%srole", prefix);
561 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
565 case ISP_ROLE_INITIATOR:
566 case ISP_ROLE_TARGET:
568 device_printf(dev, "Chan %d setting role to 0x%x\n", chan, tval);
576 tval = ISP_DEFAULT_ROLES;
578 ISP_FC_PC(isp, chan)->def_role = tval;
581 snprintf(name, sizeof(name), "%sfullduplex", prefix);
582 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
583 name, &tval) == 0 && tval != 0) {
584 isp->isp_confopts |= ISP_CFG_FULL_DUPLEX;
587 snprintf(name, sizeof(name), "%stopology", prefix);
588 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
589 name, (const char **) &sptr) == 0 && sptr != 0) {
590 if (strcmp(sptr, "lport") == 0) {
591 isp->isp_confopts |= ISP_CFG_LPORT;
592 } else if (strcmp(sptr, "nport") == 0) {
593 isp->isp_confopts |= ISP_CFG_NPORT;
594 } else if (strcmp(sptr, "lport-only") == 0) {
595 isp->isp_confopts |= ISP_CFG_LPORT_ONLY;
596 } else if (strcmp(sptr, "nport-only") == 0) {
597 isp->isp_confopts |= ISP_CFG_NPORT_ONLY;
601 #ifdef ISP_FCTAPE_OFF
602 isp->isp_confopts |= ISP_CFG_NOFCTAPE;
604 isp->isp_confopts |= ISP_CFG_FCTAPE;
608 snprintf(name, sizeof(name), "%snofctape", prefix);
609 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
612 isp->isp_confopts &= ~ISP_CFG_FCTAPE;
613 isp->isp_confopts |= ISP_CFG_NOFCTAPE;
617 snprintf(name, sizeof(name), "%sfctape", prefix);
618 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
621 isp->isp_confopts &= ~ISP_CFG_NOFCTAPE;
622 isp->isp_confopts |= ISP_CFG_FCTAPE;
627 * Because the resource_*_value functions can neither return
628 * 64 bit integer values, nor can they be directly coerced
629 * to interpret the right hand side of the assignment as
630 * you want them to interpret it, we have to force WWN
631 * hint replacement to specify WWN strings with a leading
632 * 'w' (e..g w50000000aaaa0001). Sigh.
635 snprintf(name, sizeof(name), "%sportwwn", prefix);
636 tval = resource_string_value(device_get_name(dev), device_get_unit(dev),
637 name, (const char **) &sptr);
638 if (tval == 0 && sptr != 0 && *sptr++ == 'w') {
640 ISP_FC_PC(isp, chan)->def_wwpn = strtouq(sptr, &eptr, 16);
641 if (eptr < sptr + 16 || ISP_FC_PC(isp, chan)->def_wwpn == -1) {
642 device_printf(dev, "mangled portwwn hint '%s'\n", sptr);
643 ISP_FC_PC(isp, chan)->def_wwpn = 0;
648 snprintf(name, sizeof(name), "%snodewwn", prefix);
649 tval = resource_string_value(device_get_name(dev), device_get_unit(dev),
650 name, (const char **) &sptr);
651 if (tval == 0 && sptr != 0 && *sptr++ == 'w') {
653 ISP_FC_PC(isp, chan)->def_wwnn = strtouq(sptr, &eptr, 16);
654 if (eptr < sptr + 16 || ISP_FC_PC(isp, chan)->def_wwnn == 0) {
655 device_printf(dev, "mangled nodewwn hint '%s'\n", sptr);
656 ISP_FC_PC(isp, chan)->def_wwnn = 0;
661 snprintf(name, sizeof(name), "%sloop_down_limit", prefix);
662 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
664 if (tval >= 0 && tval < 0xffff) {
665 ISP_FC_PC(isp, chan)->loop_down_limit = tval;
667 ISP_FC_PC(isp, chan)->loop_down_limit = isp_loop_down_limit;
671 snprintf(name, sizeof(name), "%sgone_device_time", prefix);
672 (void) resource_int_value(device_get_name(dev), device_get_unit(dev),
674 if (tval >= 0 && tval < 0xffff) {
675 ISP_FC_PC(isp, chan)->gone_device_time = tval;
677 ISP_FC_PC(isp, chan)->gone_device_time = isp_gone_device_time;
682 isp_pci_attach(device_t dev)
684 int i, locksetup = 0;
685 uint32_t data, cmd, linesz, did;
686 struct isp_pcisoftc *pcs;
691 pcs = device_get_softc(dev);
693 device_printf(dev, "cannot get softc\n");
696 memset(pcs, 0, sizeof (*pcs));
702 if (sizeof (bus_addr_t) > 4)
703 isp->isp_osinfo.sixtyfourbit = 1;
706 * Get Generic Options
709 isp_get_generic_options(dev, isp);
711 linesz = PCI_DFLT_LNSZ;
712 pcs->irq = pcs->regs = pcs->regs2 = NULL;
713 pcs->rgd = pcs->rtp = pcs->iqd = 0;
716 pcs->pci_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF;
717 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS_OFF;
718 pcs->pci_poff[SXP_BLOCK >> _BLK_REG_SHFT] = PCI_SXP_REGS_OFF;
719 pcs->pci_poff[RISC_BLOCK >> _BLK_REG_SHFT] = PCI_RISC_REGS_OFF;
720 pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF;
722 switch (pci_get_devid(dev)) {
723 case PCI_QLOGIC_ISP1020:
725 isp->isp_mdvec = &mdvec;
726 isp->isp_type = ISP_HA_SCSI_UNKNOWN;
728 case PCI_QLOGIC_ISP1080:
730 isp->isp_mdvec = &mdvec_1080;
731 isp->isp_type = ISP_HA_SCSI_1080;
732 pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = ISP1080_DMA_REGS_OFF;
734 case PCI_QLOGIC_ISP1240:
736 isp->isp_mdvec = &mdvec_1080;
737 isp->isp_type = ISP_HA_SCSI_1240;
739 pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = ISP1080_DMA_REGS_OFF;
741 case PCI_QLOGIC_ISP1280:
743 isp->isp_mdvec = &mdvec_1080;
744 isp->isp_type = ISP_HA_SCSI_1280;
745 pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = ISP1080_DMA_REGS_OFF;
747 case PCI_QLOGIC_ISP10160:
749 isp->isp_mdvec = &mdvec_12160;
750 isp->isp_type = ISP_HA_SCSI_10160;
751 pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = ISP1080_DMA_REGS_OFF;
753 case PCI_QLOGIC_ISP12160:
756 isp->isp_mdvec = &mdvec_12160;
757 isp->isp_type = ISP_HA_SCSI_12160;
758 pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = ISP1080_DMA_REGS_OFF;
760 case PCI_QLOGIC_ISP2100:
762 isp->isp_mdvec = &mdvec_2100;
763 isp->isp_type = ISP_HA_FC_2100;
764 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2100_OFF;
765 if (pci_get_revid(dev) < 3) {
767 * XXX: Need to get the actual revision
768 * XXX: number of the 2100 FB. At any rate,
769 * XXX: lower cache line size for early revision
775 case PCI_QLOGIC_ISP2200:
777 isp->isp_mdvec = &mdvec_2200;
778 isp->isp_type = ISP_HA_FC_2200;
779 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2100_OFF;
781 case PCI_QLOGIC_ISP2300:
783 isp->isp_mdvec = &mdvec_2300;
784 isp->isp_type = ISP_HA_FC_2300;
785 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2300_OFF;
787 case PCI_QLOGIC_ISP2312:
788 case PCI_QLOGIC_ISP6312:
790 isp->isp_mdvec = &mdvec_2300;
791 isp->isp_type = ISP_HA_FC_2312;
792 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2300_OFF;
794 case PCI_QLOGIC_ISP2322:
795 case PCI_QLOGIC_ISP6322:
797 isp->isp_mdvec = &mdvec_2300;
798 isp->isp_type = ISP_HA_FC_2322;
799 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2300_OFF;
801 case PCI_QLOGIC_ISP2422:
802 case PCI_QLOGIC_ISP2432:
804 isp->isp_nchan += isp_nvports;
805 isp->isp_mdvec = &mdvec_2400;
806 isp->isp_type = ISP_HA_FC_2400;
807 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2400_OFF;
809 case PCI_QLOGIC_ISP2532:
811 isp->isp_nchan += isp_nvports;
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;
816 case PCI_QLOGIC_ISP5432:
818 isp->isp_mdvec = &mdvec_2500;
819 isp->isp_type = ISP_HA_FC_2500;
820 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2400_OFF;
822 case PCI_QLOGIC_ISP2031:
823 case PCI_QLOGIC_ISP8031:
825 isp->isp_nchan += isp_nvports;
826 isp->isp_mdvec = &mdvec_2600;
827 isp->isp_type = ISP_HA_FC_2600;
828 pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS2400_OFF;
831 device_printf(dev, "unknown device type\n");
835 isp->isp_revision = pci_get_revid(dev);
838 pcs->rtp = SYS_RES_MEMORY;
839 pcs->rgd = PCIR_BAR(0);
840 pcs->regs = bus_alloc_resource_any(dev, pcs->rtp, &pcs->rgd,
842 pcs->rtp1 = SYS_RES_MEMORY;
843 pcs->rgd1 = PCIR_BAR(2);
844 pcs->regs1 = bus_alloc_resource_any(dev, pcs->rtp1, &pcs->rgd1,
846 pcs->rtp2 = SYS_RES_MEMORY;
847 pcs->rgd2 = PCIR_BAR(4);
848 pcs->regs2 = bus_alloc_resource_any(dev, pcs->rtp2, &pcs->rgd2,
851 pcs->rtp = SYS_RES_MEMORY;
852 pcs->rgd = PCIR_BAR(1);
853 pcs->regs = bus_alloc_resource_any(dev, pcs->rtp, &pcs->rgd,
855 if (pcs->regs == NULL) {
856 pcs->rtp = SYS_RES_IOPORT;
857 pcs->rgd = PCIR_BAR(0);
858 pcs->regs = bus_alloc_resource_any(dev, pcs->rtp,
859 &pcs->rgd, RF_ACTIVE);
862 if (pcs->regs == NULL) {
863 device_printf(dev, "Unable to map any ports\n");
867 device_printf(dev, "Using %s space register mapping\n",
868 (pcs->rtp == SYS_RES_IOPORT)? "I/O" : "Memory");
870 isp->isp_regs = pcs->regs;
871 isp->isp_regs2 = pcs->regs2;
874 psize = sizeof (fcparam);
875 xsize = sizeof (struct isp_fc);
877 psize = sizeof (sdparam);
878 xsize = sizeof (struct isp_spi);
880 psize *= isp->isp_nchan;
881 xsize *= isp->isp_nchan;
882 isp->isp_param = malloc(psize, M_DEVBUF, M_NOWAIT | M_ZERO);
883 if (isp->isp_param == NULL) {
884 device_printf(dev, "cannot allocate parameter data\n");
887 isp->isp_osinfo.pc.ptr = malloc(xsize, M_DEVBUF, M_NOWAIT | M_ZERO);
888 if (isp->isp_osinfo.pc.ptr == NULL) {
889 device_printf(dev, "cannot allocate parameter data\n");
894 * Now that we know who we are (roughly) get/set specific options
896 for (i = 0; i < isp->isp_nchan; i++) {
897 isp_get_specific_options(dev, i, isp);
900 isp->isp_osinfo.fw = NULL;
901 if (isp->isp_osinfo.fw == NULL) {
902 snprintf(fwname, sizeof (fwname), "isp_%04x", did);
903 isp->isp_osinfo.fw = firmware_get(fwname);
905 if (isp->isp_osinfo.fw != NULL) {
906 isp_prt(isp, ISP_LOGCONFIG, "loaded firmware %s", fwname);
907 isp->isp_mdvec->dv_ispfw = isp->isp_osinfo.fw->data;
911 * Make sure that SERR, PERR, WRITE INVALIDATE and BUSMASTER are set.
913 cmd = pci_read_config(dev, PCIR_COMMAND, 2);
914 cmd |= PCIM_CMD_SEREN | PCIM_CMD_PERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_INVEN;
915 if (IS_2300(isp)) { /* per QLogic errata */
916 cmd &= ~PCIM_CMD_INVEN;
918 if (IS_2322(isp) || pci_get_devid(dev) == PCI_QLOGIC_ISP6312) {
919 cmd &= ~PCIM_CMD_INTX_DISABLE;
922 cmd &= ~PCIM_CMD_INTX_DISABLE;
924 pci_write_config(dev, PCIR_COMMAND, cmd, 2);
927 * Make sure the Cache Line Size register is set sensibly.
929 data = pci_read_config(dev, PCIR_CACHELNSZ, 1);
930 if (data == 0 || (linesz != PCI_DFLT_LNSZ && data != linesz)) {
931 isp_prt(isp, ISP_LOGDEBUG0, "set PCI line size to %d from %d", linesz, data);
933 pci_write_config(dev, PCIR_CACHELNSZ, data, 1);
937 * Make sure the Latency Timer is sane.
939 data = pci_read_config(dev, PCIR_LATTIMER, 1);
940 if (data < PCI_DFLT_LTNCY) {
941 data = PCI_DFLT_LTNCY;
942 isp_prt(isp, ISP_LOGDEBUG0, "set PCI latency to %d", data);
943 pci_write_config(dev, PCIR_LATTIMER, data, 1);
947 * Make sure we've disabled the ROM.
949 data = pci_read_config(dev, PCIR_ROMADDR, 4);
951 pci_write_config(dev, PCIR_ROMADDR, data, 4);
954 /* 26XX chips support only MSI-X, so start from them. */
955 pcs->msicount = imin(pci_msix_count(dev), 1);
956 if (pcs->msicount > 0 &&
957 (i = pci_alloc_msix(dev, &pcs->msicount)) == 0) {
963 if (pcs->msicount == 0 && (IS_24XX(isp) || IS_2322(isp))) {
965 * Older chips support both MSI and MSI-X, but I have
966 * feeling that older firmware may not support MSI-X,
967 * but we have no way to check the firmware flag here.
969 pcs->msicount = imin(pci_msi_count(dev), 1);
970 if (pcs->msicount > 0 &&
971 pci_alloc_msi(dev, &pcs->msicount) == 0) {
977 pcs->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &pcs->iqd, RF_ACTIVE | RF_SHAREABLE);
978 if (pcs->irq == NULL) {
979 device_printf(dev, "could not allocate interrupt\n");
983 /* Make sure the lock is set up. */
984 mtx_init(&isp->isp_osinfo.lock, "isp", NULL, MTX_DEF);
987 if (isp_setup_intr(dev, pcs->irq, ISP_IFLAGS, NULL, isp_platform_intr, isp, &pcs->ih)) {
988 device_printf(dev, "could not setup interrupt\n");
993 * Last minute checks...
995 if (IS_23XX(isp) || IS_24XX(isp)) {
996 isp->isp_port = pci_get_function(dev);
1000 * Make sure we're in reset state.
1003 if (isp_reinit(isp, 1) != 0) {
1008 if (isp_attach(isp)) {
1018 (void) bus_teardown_intr(dev, pcs->irq, pcs->ih);
1021 mtx_destroy(&isp->isp_osinfo.lock);
1024 (void) bus_release_resource(dev, SYS_RES_IRQ, pcs->iqd, pcs->irq);
1026 if (pcs->msicount) {
1027 pci_release_msi(dev);
1030 (void) bus_release_resource(dev, pcs->rtp, pcs->rgd, pcs->regs);
1032 (void) bus_release_resource(dev, pcs->rtp1, pcs->rgd1, pcs->regs1);
1034 (void) bus_release_resource(dev, pcs->rtp2, pcs->rgd2, pcs->regs2);
1035 if (pcs->pci_isp.isp_param) {
1036 free(pcs->pci_isp.isp_param, M_DEVBUF);
1037 pcs->pci_isp.isp_param = NULL;
1039 if (pcs->pci_isp.isp_osinfo.pc.ptr) {
1040 free(pcs->pci_isp.isp_osinfo.pc.ptr, M_DEVBUF);
1041 pcs->pci_isp.isp_osinfo.pc.ptr = NULL;
1047 isp_pci_detach(device_t dev)
1049 struct isp_pcisoftc *pcs;
1053 pcs = device_get_softc(dev);
1057 isp = (ispsoftc_t *) pcs;
1058 status = isp_detach(isp);
1064 (void) bus_teardown_intr(dev, pcs->irq, pcs->ih);
1067 mtx_destroy(&isp->isp_osinfo.lock);
1068 (void) bus_release_resource(dev, SYS_RES_IRQ, pcs->iqd, pcs->irq);
1069 if (pcs->msicount) {
1070 pci_release_msi(dev);
1072 (void) bus_release_resource(dev, pcs->rtp, pcs->rgd, pcs->regs);
1074 (void) bus_release_resource(dev, pcs->rtp1, pcs->rgd1, pcs->regs1);
1076 (void) bus_release_resource(dev, pcs->rtp2, pcs->rgd2, pcs->regs2);
1078 * XXX: THERE IS A LOT OF LEAKAGE HERE
1080 if (pcs->pci_isp.isp_param) {
1081 free(pcs->pci_isp.isp_param, M_DEVBUF);
1082 pcs->pci_isp.isp_param = NULL;
1084 if (pcs->pci_isp.isp_osinfo.pc.ptr) {
1085 free(pcs->pci_isp.isp_osinfo.pc.ptr, M_DEVBUF);
1086 pcs->pci_isp.isp_osinfo.pc.ptr = NULL;
1091 #define IspVirt2Off(a, x) \
1092 (((struct isp_pcisoftc *)a)->pci_poff[((x) & _BLK_REG_MASK) >> \
1093 _BLK_REG_SHFT] + ((x) & 0xfff))
1095 #define BXR2(isp, off) bus_read_2((isp)->isp_regs, (off))
1096 #define BXW2(isp, off, v) bus_write_2((isp)->isp_regs, (off), (v))
1097 #define BXR4(isp, off) bus_read_4((isp)->isp_regs, (off))
1098 #define BXW4(isp, off, v) bus_write_4((isp)->isp_regs, (off), (v))
1099 #define B2R4(isp, off) bus_read_4((isp)->isp_regs2, (off))
1100 #define B2W4(isp, off, v) bus_write_4((isp)->isp_regs2, (off), (v))
1102 static ISP_INLINE int
1103 isp_pci_rd_debounced(ispsoftc_t *isp, int off, uint16_t *rp)
1105 uint32_t val0, val1;
1109 val0 = BXR2(isp, IspVirt2Off(isp, off));
1110 val1 = BXR2(isp, IspVirt2Off(isp, off));
1111 } while (val0 != val1 && ++i < 1000);
1120 isp_pci_rd_isr(ispsoftc_t *isp, uint16_t *isrp, uint16_t *semap, uint16_t *info)
1125 if (isp_pci_rd_debounced(isp, BIU_ISR, &isr)) {
1128 if (isp_pci_rd_debounced(isp, BIU_SEMA, &sema)) {
1132 isr = BXR2(isp, IspVirt2Off(isp, BIU_ISR));
1133 sema = BXR2(isp, IspVirt2Off(isp, BIU_SEMA));
1135 isp_prt(isp, ISP_LOGDEBUG3, "ISR 0x%x SEMA 0x%x", isr, sema);
1136 isr &= INT_PENDING_MASK(isp);
1137 sema &= BIU_SEMA_LOCK;
1138 if (isr == 0 && sema == 0) {
1142 if ((*semap = sema) != 0) {
1144 if (isp_pci_rd_debounced(isp, OUTMAILBOX0, info)) {
1148 *info = BXR2(isp, IspVirt2Off(isp, OUTMAILBOX0));
1155 isp_pci_rd_isr_2300(ispsoftc_t *isp, uint16_t *isrp, uint16_t *semap, uint16_t *info)
1157 uint32_t hccr, r2hisr;
1159 if (!(BXR2(isp, IspVirt2Off(isp, BIU_ISR) & BIU2100_ISR_RISC_INT))) {
1163 r2hisr = BXR4(isp, IspVirt2Off(isp, BIU_R2HSTSLO));
1164 isp_prt(isp, ISP_LOGDEBUG3, "RISC2HOST ISR 0x%x", r2hisr);
1165 if ((r2hisr & BIU_R2HST_INTR) == 0) {
1169 switch ((*isrp = r2hisr & BIU_R2HST_ISTAT_MASK)) {
1170 case ISPR2HST_ROM_MBX_OK:
1171 case ISPR2HST_ROM_MBX_FAIL:
1172 case ISPR2HST_MBX_OK:
1173 case ISPR2HST_MBX_FAIL:
1174 case ISPR2HST_ASYNC_EVENT:
1177 case ISPR2HST_RIO_16:
1178 *info = ASYNC_RIO16_1;
1181 case ISPR2HST_FPOST:
1182 *info = ASYNC_CMD_CMPLT;
1185 case ISPR2HST_FPOST_CTIO:
1186 *info = ASYNC_CTIO_DONE;
1189 case ISPR2HST_RSPQ_UPDATE:
1193 hccr = ISP_READ(isp, HCCR);
1194 if (hccr & HCCR_PAUSE) {
1195 ISP_WRITE(isp, HCCR, HCCR_RESET);
1196 isp_prt(isp, ISP_LOGERR, "RISC paused at interrupt (%x->%x)", hccr, ISP_READ(isp, HCCR));
1197 ISP_WRITE(isp, BIU_ICR, 0);
1199 isp_prt(isp, ISP_LOGERR, "unknown interrupt 0x%x\n", r2hisr);
1203 *info = (r2hisr >> 16);
1208 isp_pci_rd_isr_2400(ispsoftc_t *isp, uint16_t *isrp, uint16_t *semap, uint16_t *info)
1212 r2hisr = BXR4(isp, IspVirt2Off(isp, BIU2400_R2HSTSLO));
1213 isp_prt(isp, ISP_LOGDEBUG3, "RISC2HOST ISR 0x%x", r2hisr);
1214 if ((r2hisr & BIU_R2HST_INTR) == 0) {
1218 switch ((*isrp = r2hisr & BIU_R2HST_ISTAT_MASK)) {
1219 case ISPR2HST_ROM_MBX_OK:
1220 case ISPR2HST_ROM_MBX_FAIL:
1221 case ISPR2HST_MBX_OK:
1222 case ISPR2HST_MBX_FAIL:
1223 case ISPR2HST_ASYNC_EVENT:
1226 case ISPR2HST_RSPQ_UPDATE:
1227 case ISPR2HST_RSPQ_UPDATE2:
1228 case ISPR2HST_ATIO_UPDATE:
1229 case ISPR2HST_ATIO_RSPQ_UPDATE:
1230 case ISPR2HST_ATIO_UPDATE2:
1234 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
1235 isp_prt(isp, ISP_LOGERR, "unknown interrupt 0x%x\n", r2hisr);
1238 *info = (r2hisr >> 16);
1243 isp_pci_rd_reg(ispsoftc_t *isp, int regoff)
1248 if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
1250 * We will assume that someone has paused the RISC processor.
1252 oldconf = BXR2(isp, IspVirt2Off(isp, BIU_CONF1));
1253 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), oldconf | BIU_PCI_CONF1_SXP);
1254 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1256 rv = BXR2(isp, IspVirt2Off(isp, regoff));
1257 if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
1258 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), oldconf);
1259 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1265 isp_pci_wr_reg(ispsoftc_t *isp, int regoff, uint32_t val)
1269 if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
1271 * We will assume that someone has paused the RISC processor.
1273 oldconf = BXR2(isp, IspVirt2Off(isp, BIU_CONF1));
1274 BXW2(isp, IspVirt2Off(isp, BIU_CONF1),
1275 oldconf | BIU_PCI_CONF1_SXP);
1276 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1278 BXW2(isp, IspVirt2Off(isp, regoff), val);
1279 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, regoff), 2, -1);
1280 if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
1281 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), oldconf);
1282 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1288 isp_pci_rd_reg_1080(ispsoftc_t *isp, int regoff)
1290 uint32_t rv, oc = 0;
1292 if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
1295 * We will assume that someone has paused the RISC processor.
1297 oc = BXR2(isp, IspVirt2Off(isp, BIU_CONF1));
1298 tc = oc & ~BIU_PCI1080_CONF1_DMA;
1299 if (regoff & SXP_BANK1_SELECT)
1300 tc |= BIU_PCI1080_CONF1_SXP1;
1302 tc |= BIU_PCI1080_CONF1_SXP0;
1303 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), tc);
1304 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1305 } else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
1306 oc = BXR2(isp, IspVirt2Off(isp, BIU_CONF1));
1307 BXW2(isp, IspVirt2Off(isp, BIU_CONF1),
1308 oc | BIU_PCI1080_CONF1_DMA);
1309 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1311 rv = BXR2(isp, IspVirt2Off(isp, regoff));
1313 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), oc);
1314 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1320 isp_pci_wr_reg_1080(ispsoftc_t *isp, int regoff, uint32_t val)
1324 if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
1327 * We will assume that someone has paused the RISC processor.
1329 oc = BXR2(isp, IspVirt2Off(isp, BIU_CONF1));
1330 tc = oc & ~BIU_PCI1080_CONF1_DMA;
1331 if (regoff & SXP_BANK1_SELECT)
1332 tc |= BIU_PCI1080_CONF1_SXP1;
1334 tc |= BIU_PCI1080_CONF1_SXP0;
1335 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), tc);
1336 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1337 } else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
1338 oc = BXR2(isp, IspVirt2Off(isp, BIU_CONF1));
1339 BXW2(isp, IspVirt2Off(isp, BIU_CONF1),
1340 oc | BIU_PCI1080_CONF1_DMA);
1341 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1343 BXW2(isp, IspVirt2Off(isp, regoff), val);
1344 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, regoff), 2, -1);
1346 BXW2(isp, IspVirt2Off(isp, BIU_CONF1), oc);
1347 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, BIU_CONF1), 2, -1);
1352 isp_pci_rd_reg_2400(ispsoftc_t *isp, int regoff)
1355 int block = regoff & _BLK_REG_MASK;
1361 return (BXR2(isp, IspVirt2Off(isp, regoff)));
1363 isp_prt(isp, ISP_LOGERR, "SXP_BLOCK read at 0x%x", regoff);
1364 return (0xffffffff);
1366 isp_prt(isp, ISP_LOGERR, "RISC_BLOCK read at 0x%x", regoff);
1367 return (0xffffffff);
1369 isp_prt(isp, ISP_LOGERR, "DMA_BLOCK read at 0x%x", regoff);
1370 return (0xffffffff);
1372 isp_prt(isp, ISP_LOGERR, "unknown block read at 0x%x", regoff);
1373 return (0xffffffff);
1377 case BIU2400_FLASH_ADDR:
1378 case BIU2400_FLASH_DATA:
1382 case BIU2400_REQINP:
1383 case BIU2400_REQOUTP:
1384 case BIU2400_RSPINP:
1385 case BIU2400_RSPOUTP:
1386 case BIU2400_PRI_REQINP:
1387 case BIU2400_PRI_REQOUTP:
1388 case BIU2400_ATIO_RSPINP:
1389 case BIU2400_ATIO_RSPOUTP:
1394 rv = BXR4(isp, IspVirt2Off(isp, regoff));
1396 case BIU2400_R2HSTSLO:
1397 rv = BXR4(isp, IspVirt2Off(isp, regoff));
1399 case BIU2400_R2HSTSHI:
1400 rv = BXR4(isp, IspVirt2Off(isp, regoff)) >> 16;
1403 isp_prt(isp, ISP_LOGERR, "unknown register read at 0x%x",
1412 isp_pci_wr_reg_2400(ispsoftc_t *isp, int regoff, uint32_t val)
1414 int block = regoff & _BLK_REG_MASK;
1420 BXW2(isp, IspVirt2Off(isp, regoff), val);
1421 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, regoff), 2, -1);
1424 isp_prt(isp, ISP_LOGERR, "SXP_BLOCK write at 0x%x", regoff);
1427 isp_prt(isp, ISP_LOGERR, "RISC_BLOCK write at 0x%x", regoff);
1430 isp_prt(isp, ISP_LOGERR, "DMA_BLOCK write at 0x%x", regoff);
1433 isp_prt(isp, ISP_LOGERR, "unknown block write at 0x%x", regoff);
1438 case BIU2400_FLASH_ADDR:
1439 case BIU2400_FLASH_DATA:
1443 case BIU2400_REQINP:
1444 case BIU2400_REQOUTP:
1445 case BIU2400_RSPINP:
1446 case BIU2400_RSPOUTP:
1447 case BIU2400_PRI_REQINP:
1448 case BIU2400_PRI_REQOUTP:
1449 case BIU2400_ATIO_RSPINP:
1450 case BIU2400_ATIO_RSPOUTP:
1455 BXW4(isp, IspVirt2Off(isp, regoff), val);
1456 #ifdef MEMORYBARRIERW
1457 if (regoff == BIU2400_REQINP ||
1458 regoff == BIU2400_RSPOUTP ||
1459 regoff == BIU2400_PRI_REQINP ||
1460 regoff == BIU2400_ATIO_RSPOUTP)
1461 MEMORYBARRIERW(isp, SYNC_REG,
1462 IspVirt2Off(isp, regoff), 4, -1)
1465 MEMORYBARRIER(isp, SYNC_REG, IspVirt2Off(isp, regoff), 4, -1);
1468 isp_prt(isp, ISP_LOGERR, "unknown register write at 0x%x",
1475 isp_pci_rd_reg_2600(ispsoftc_t *isp, int regoff)
1480 case BIU2400_PRI_REQINP:
1481 case BIU2400_PRI_REQOUTP:
1482 isp_prt(isp, ISP_LOGERR, "unknown register read at 0x%x",
1486 case BIU2400_REQINP:
1487 rv = B2R4(isp, 0x00);
1489 case BIU2400_REQOUTP:
1490 rv = B2R4(isp, 0x04);
1492 case BIU2400_RSPINP:
1493 rv = B2R4(isp, 0x08);
1495 case BIU2400_RSPOUTP:
1496 rv = B2R4(isp, 0x0c);
1498 case BIU2400_ATIO_RSPINP:
1499 rv = B2R4(isp, 0x10);
1501 case BIU2400_ATIO_RSPOUTP:
1502 rv = B2R4(isp, 0x14);
1505 rv = isp_pci_rd_reg_2400(isp, regoff);
1512 isp_pci_wr_reg_2600(ispsoftc_t *isp, int regoff, uint32_t val)
1517 case BIU2400_PRI_REQINP:
1518 case BIU2400_PRI_REQOUTP:
1519 isp_prt(isp, ISP_LOGERR, "unknown register write at 0x%x",
1522 case BIU2400_REQINP:
1525 case BIU2400_REQOUTP:
1528 case BIU2400_RSPINP:
1531 case BIU2400_RSPOUTP:
1534 case BIU2400_ATIO_RSPINP:
1537 case BIU2400_ATIO_RSPOUTP:
1541 isp_pci_wr_reg_2400(isp, regoff, val);
1544 B2W4(isp, off, val);
1554 imc(void *arg, bus_dma_segment_t *segs, int nseg, int error)
1556 struct imush *imushp = (struct imush *) arg;
1558 if (!(imushp->error = error))
1559 imushp->maddr = segs[0].ds_addr;
1563 isp_pci_mbxdma(ispsoftc_t *isp)
1566 uint32_t len, nsegs;
1567 int i, error, cmap = 0;
1568 bus_size_t slim; /* segment size */
1569 bus_addr_t llim; /* low limit of unavailable dma */
1570 bus_addr_t hlim; /* high limit of unavailable dma */
1575 * Already been here? If so, leave...
1577 if (isp->isp_rquest) {
1582 if (isp->isp_maxcmds == 0) {
1583 isp_prt(isp, ISP_LOGERR, "maxcmds not set");
1588 hlim = BUS_SPACE_MAXADDR;
1589 if (IS_ULTRA2(isp) || IS_FC(isp) || IS_1240(isp)) {
1590 if (sizeof (bus_size_t) > 4) {
1591 slim = (bus_size_t) (1ULL << 32);
1593 slim = (bus_size_t) (1UL << 31);
1595 llim = BUS_SPACE_MAXADDR;
1597 llim = BUS_SPACE_MAXADDR_32BIT;
1601 len = isp->isp_maxcmds * sizeof (struct isp_pcmd);
1602 isp->isp_osinfo.pcmd_pool = (struct isp_pcmd *) malloc(len, M_DEVBUF, M_WAITOK | M_ZERO);
1604 if (isp->isp_osinfo.sixtyfourbit) {
1605 nsegs = ISP_NSEG64_MAX;
1607 nsegs = ISP_NSEG_MAX;
1610 if (isp_dma_tag_create(BUS_DMA_ROOTARG(ISP_PCD(isp)), 1, slim, llim, hlim, NULL, NULL, BUS_SPACE_MAXSIZE, nsegs, slim, 0, &isp->isp_osinfo.dmat)) {
1611 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF);
1613 isp_prt(isp, ISP_LOGERR, "could not create master dma tag");
1617 len = sizeof (isp_hdl_t) * isp->isp_maxcmds;
1618 isp->isp_xflist = (isp_hdl_t *) malloc(len, M_DEVBUF, M_WAITOK | M_ZERO);
1619 for (len = 0; len < isp->isp_maxcmds - 1; len++) {
1620 isp->isp_xflist[len].cmd = &isp->isp_xflist[len+1];
1622 isp->isp_xffree = isp->isp_xflist;
1625 * Allocate and map the request queue and a region for external
1626 * DMA addressable command/status structures (22XX and later).
1628 len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
1629 if (isp->isp_type >= ISP_HA_FC_2200)
1630 len += (N_XCMDS * XCMD_SIZE);
1631 if (isp_dma_tag_create(isp->isp_osinfo.dmat, QENTRY_LEN, slim,
1632 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1633 len, 1, len, 0, &isp->isp_osinfo.reqdmat)) {
1634 isp_prt(isp, ISP_LOGERR, "cannot create request DMA tag");
1637 if (bus_dmamem_alloc(isp->isp_osinfo.reqdmat, (void **)&base,
1638 BUS_DMA_COHERENT, &isp->isp_osinfo.reqmap) != 0) {
1639 isp_prt(isp, ISP_LOGERR, "cannot allocate request DMA memory");
1640 bus_dma_tag_destroy(isp->isp_osinfo.reqdmat);
1643 isp->isp_rquest = base;
1645 if (bus_dmamap_load(isp->isp_osinfo.reqdmat, isp->isp_osinfo.reqmap,
1646 base, len, imc, &im, 0) || im.error) {
1647 isp_prt(isp, ISP_LOGERR, "error loading request DMA map %d", im.error);
1650 isp_prt(isp, ISP_LOGDEBUG0, "request area @ 0x%jx/0x%jx",
1651 (uintmax_t)im.maddr, (uintmax_t)len);
1652 isp->isp_rquest_dma = im.maddr;
1653 base += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
1654 im.maddr += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));
1655 if (isp->isp_type >= ISP_HA_FC_2200) {
1656 isp->isp_osinfo.ecmd_dma = im.maddr;
1657 isp->isp_osinfo.ecmd_free = (isp_ecmd_t *)base;
1658 isp->isp_osinfo.ecmd_base = isp->isp_osinfo.ecmd_free;
1659 for (ecmd = isp->isp_osinfo.ecmd_free;
1660 ecmd < &isp->isp_osinfo.ecmd_free[N_XCMDS]; ecmd++) {
1661 if (ecmd == &isp->isp_osinfo.ecmd_free[N_XCMDS - 1])
1664 ecmd->next = ecmd + 1;
1669 * Allocate and map the result queue.
1671 len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp));
1672 if (isp_dma_tag_create(isp->isp_osinfo.dmat, QENTRY_LEN, slim,
1673 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1674 len, 1, len, 0, &isp->isp_osinfo.respdmat)) {
1675 isp_prt(isp, ISP_LOGERR, "cannot create response DMA tag");
1678 if (bus_dmamem_alloc(isp->isp_osinfo.respdmat, (void **)&base,
1679 BUS_DMA_COHERENT, &isp->isp_osinfo.respmap) != 0) {
1680 isp_prt(isp, ISP_LOGERR, "cannot allocate response DMA memory");
1681 bus_dma_tag_destroy(isp->isp_osinfo.respdmat);
1684 isp->isp_result = base;
1686 if (bus_dmamap_load(isp->isp_osinfo.respdmat, isp->isp_osinfo.respmap,
1687 base, len, imc, &im, 0) || im.error) {
1688 isp_prt(isp, ISP_LOGERR, "error loading response DMA map %d", im.error);
1691 isp_prt(isp, ISP_LOGDEBUG0, "response area @ 0x%jx/0x%jx",
1692 (uintmax_t)im.maddr, (uintmax_t)len);
1693 isp->isp_result_dma = im.maddr;
1695 #ifdef ISP_TARGET_MODE
1697 * Allocate and map ATIO queue on 24xx with target mode.
1700 len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp));
1701 if (isp_dma_tag_create(isp->isp_osinfo.dmat, QENTRY_LEN, slim,
1702 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1703 len, 1, len, 0, &isp->isp_osinfo.atiodmat)) {
1704 isp_prt(isp, ISP_LOGERR, "cannot create ATIO DMA tag");
1707 if (bus_dmamem_alloc(isp->isp_osinfo.atiodmat, (void **)&base,
1708 BUS_DMA_COHERENT, &isp->isp_osinfo.atiomap) != 0) {
1709 isp_prt(isp, ISP_LOGERR, "cannot allocate ATIO DMA memory");
1710 bus_dma_tag_destroy(isp->isp_osinfo.atiodmat);
1713 isp->isp_atioq = base;
1715 if (bus_dmamap_load(isp->isp_osinfo.atiodmat, isp->isp_osinfo.atiomap,
1716 base, len, imc, &im, 0) || im.error) {
1717 isp_prt(isp, ISP_LOGERR, "error loading ATIO DMA map %d", im.error);
1720 isp_prt(isp, ISP_LOGDEBUG0, "ATIO area @ 0x%jx/0x%jx",
1721 (uintmax_t)im.maddr, (uintmax_t)len);
1722 isp->isp_atioq_dma = im.maddr;
1727 if (isp_dma_tag_create(isp->isp_osinfo.dmat, 64, slim,
1728 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
1729 2*QENTRY_LEN, 1, 2*QENTRY_LEN, 0, &isp->isp_osinfo.iocbdmat)) {
1732 if (bus_dmamem_alloc(isp->isp_osinfo.iocbdmat,
1733 (void **)&base, BUS_DMA_COHERENT, &isp->isp_osinfo.iocbmap) != 0)
1735 isp->isp_iocb = base;
1737 if (bus_dmamap_load(isp->isp_osinfo.iocbdmat, isp->isp_osinfo.iocbmap,
1738 base, 2*QENTRY_LEN, imc, &im, 0) || im.error)
1740 isp->isp_iocb_dma = im.maddr;
1742 if (isp_dma_tag_create(isp->isp_osinfo.dmat, 64, slim,
1743 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
1744 ISP_FC_SCRLEN, 1, ISP_FC_SCRLEN, 0, &isp->isp_osinfo.scdmat))
1746 for (cmap = 0; cmap < isp->isp_nchan; cmap++) {
1747 struct isp_fc *fc = ISP_FC_PC(isp, cmap);
1748 if (bus_dmamem_alloc(isp->isp_osinfo.scdmat,
1749 (void **)&base, BUS_DMA_COHERENT, &fc->scmap) != 0)
1751 FCPARAM(isp, cmap)->isp_scratch = base;
1753 if (bus_dmamap_load(isp->isp_osinfo.scdmat, fc->scmap,
1754 base, ISP_FC_SCRLEN, imc, &im, 0) || im.error) {
1755 bus_dmamem_free(isp->isp_osinfo.scdmat,
1759 FCPARAM(isp, cmap)->isp_scdma = im.maddr;
1760 if (!IS_2100(isp)) {
1761 for (i = 0; i < INITIAL_NEXUS_COUNT; i++) {
1762 struct isp_nexus *n = malloc(sizeof (struct isp_nexus), M_DEVBUF, M_NOWAIT | M_ZERO);
1764 while (fc->nexus_free_list) {
1765 n = fc->nexus_free_list;
1766 fc->nexus_free_list = n->next;
1771 n->next = fc->nexus_free_list;
1772 fc->nexus_free_list = n;
1778 for (i = 0; i < isp->isp_maxcmds; i++) {
1779 struct isp_pcmd *pcmd = &isp->isp_osinfo.pcmd_pool[i];
1780 error = bus_dmamap_create(isp->isp_osinfo.dmat, 0, &pcmd->dmap);
1782 isp_prt(isp, ISP_LOGERR, "error %d creating per-cmd DMA maps", error);
1784 bus_dmamap_destroy(isp->isp_osinfo.dmat, isp->isp_osinfo.pcmd_pool[i].dmap);
1788 callout_init_mtx(&pcmd->wdog, &isp->isp_osinfo.lock, 0);
1789 if (i == isp->isp_maxcmds-1) {
1792 pcmd->next = &isp->isp_osinfo.pcmd_pool[i+1];
1795 isp->isp_osinfo.pcmd_free = &isp->isp_osinfo.pcmd_pool[0];
1801 while (--cmap >= 0) {
1802 struct isp_fc *fc = ISP_FC_PC(isp, cmap);
1803 bus_dmamap_unload(isp->isp_osinfo.scdmat, fc->scmap);
1804 bus_dmamem_free(isp->isp_osinfo.scdmat,
1805 FCPARAM(isp, cmap)->isp_scratch, fc->scmap);
1806 while (fc->nexus_free_list) {
1807 struct isp_nexus *n = fc->nexus_free_list;
1808 fc->nexus_free_list = n->next;
1812 bus_dma_tag_destroy(isp->isp_osinfo.scdmat);
1813 bus_dmamap_unload(isp->isp_osinfo.iocbdmat, isp->isp_osinfo.iocbmap);
1814 bus_dmamem_free(isp->isp_osinfo.iocbdmat, isp->isp_iocb,
1815 isp->isp_osinfo.iocbmap);
1816 bus_dma_tag_destroy(isp->isp_osinfo.iocbdmat);
1819 if (isp->isp_rquest_dma != 0) {
1820 bus_dmamap_unload(isp->isp_osinfo.reqdmat,
1821 isp->isp_osinfo.reqmap);
1823 if (isp->isp_rquest != NULL) {
1824 bus_dmamem_free(isp->isp_osinfo.reqdmat, isp->isp_rquest,
1825 isp->isp_osinfo.reqmap);
1826 bus_dma_tag_destroy(isp->isp_osinfo.reqdmat);
1828 if (isp->isp_result_dma != 0) {
1829 bus_dmamap_unload(isp->isp_osinfo.respdmat,
1830 isp->isp_osinfo.respmap);
1832 if (isp->isp_result != NULL) {
1833 bus_dmamem_free(isp->isp_osinfo.respdmat, isp->isp_result,
1834 isp->isp_osinfo.respmap);
1835 bus_dma_tag_destroy(isp->isp_osinfo.respdmat);
1837 #ifdef ISP_TARGET_MODE
1839 if (isp->isp_atioq_dma != 0) {
1840 bus_dmamap_unload(isp->isp_osinfo.atiodmat,
1841 isp->isp_osinfo.atiomap);
1843 if (isp->isp_atioq != NULL) {
1844 bus_dmamem_free(isp->isp_osinfo.reqdmat, isp->isp_atioq,
1845 isp->isp_osinfo.atiomap);
1846 bus_dma_tag_destroy(isp->isp_osinfo.atiodmat);
1850 free(isp->isp_xflist, M_DEVBUF);
1851 free(isp->isp_osinfo.pcmd_pool, M_DEVBUF);
1852 isp->isp_rquest = NULL;
1860 void *rq; /* original request */
1865 #define MUSHERR_NOQENTRIES -2
1867 #ifdef ISP_TARGET_MODE
1868 static void tdma2_2(void *, bus_dma_segment_t *, int, bus_size_t, int);
1869 static void tdma2(void *, bus_dma_segment_t *, int, int);
1872 tdma2_2(void *arg, bus_dma_segment_t *dm_segs, int nseg, bus_size_t mapsize, int error)
1876 mp->mapsize = mapsize;
1877 tdma2(arg, dm_segs, nseg, error);
1881 tdma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1885 struct ccb_scsiio *csio;
1889 mp = (mush_t *) arg;
1894 csio = mp->cmd_token;
1898 if (isp->isp_osinfo.sixtyfourbit) {
1899 if (nseg >= ISP_NSEG64_MAX) {
1900 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG64_MAX);
1904 if (rq->req_header.rqs_entry_type == RQSTYPE_CTIO2) {
1905 rq->req_header.rqs_entry_type = RQSTYPE_CTIO3;
1908 if (nseg >= ISP_NSEG_MAX) {
1909 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG_MAX);
1914 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1915 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREWRITE);
1916 ddir = ISP_TO_DEVICE;
1917 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1918 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREREAD);
1919 ddir = ISP_FROM_DEVICE;
1931 error = isp_send_tgt_cmd(isp, rq, dm_segs, nseg, XS_XFRLEN(csio), ddir, &csio->sense_data, csio->sense_len);
1934 mp->error = MUSHERR_NOQENTRIES;
1943 static void dma2_2(void *, bus_dma_segment_t *, int, bus_size_t, int);
1944 static void dma2(void *, bus_dma_segment_t *, int, int);
1947 dma2_2(void *arg, bus_dma_segment_t *dm_segs, int nseg, bus_size_t mapsize, int error)
1951 mp->mapsize = mapsize;
1952 dma2(arg, dm_segs, nseg, error);
1956 dma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1960 struct ccb_scsiio *csio;
1964 mp = (mush_t *) arg;
1969 csio = mp->cmd_token;
1973 if (isp->isp_osinfo.sixtyfourbit) {
1974 if (nseg >= ISP_NSEG64_MAX) {
1975 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG64_MAX);
1979 if (rq->req_header.rqs_entry_type == RQSTYPE_T2RQS) {
1980 rq->req_header.rqs_entry_type = RQSTYPE_T3RQS;
1981 } else if (rq->req_header.rqs_entry_type == RQSTYPE_REQUEST) {
1982 rq->req_header.rqs_entry_type = RQSTYPE_A64;
1985 if (nseg >= ISP_NSEG_MAX) {
1986 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG_MAX);
1991 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1992 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREREAD);
1993 ddir = ISP_FROM_DEVICE;
1994 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1995 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREWRITE);
1996 ddir = ISP_TO_DEVICE;
2006 error = isp_send_cmd(isp, rq, dm_segs, nseg, XS_XFRLEN(csio), ddir, (ispds64_t *)csio->req_map);
2009 mp->error = MUSHERR_NOQENTRIES;
2020 isp_pci_dmasetup(ispsoftc_t *isp, struct ccb_scsiio *csio, void *ff)
2023 void (*eptr)(void *, bus_dma_segment_t *, int, int);
2024 void (*eptr2)(void *, bus_dma_segment_t *, int, bus_size_t, int);
2029 mp->cmd_token = csio;
2034 #ifdef ISP_TARGET_MODE
2035 if (csio->ccb_h.func_code == XPT_CONT_TARGET_IO) {
2046 error = bus_dmamap_load_ccb(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap,
2047 (union ccb *)csio, eptr, mp, 0);
2048 if (error == EINPROGRESS) {
2049 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
2051 isp_prt(isp, ISP_LOGERR, "deferred dma allocation not supported");
2052 } else if (error && mp->error == 0) {
2054 isp_prt(isp, ISP_LOGERR, "error %d in dma mapping code", error);
2059 int retval = CMD_COMPLETE;
2060 if (mp->error == MUSHERR_NOQENTRIES) {
2061 retval = CMD_EAGAIN;
2062 } else if (mp->error == EFBIG) {
2063 csio->ccb_h.status = CAM_REQ_TOO_BIG;
2064 } else if (mp->error == EINVAL) {
2065 csio->ccb_h.status = CAM_REQ_INVALID;
2067 csio->ccb_h.status = CAM_UNREC_HBA_ERROR;
2071 return (CMD_QUEUED);
2075 isp_pci_reset0(ispsoftc_t *isp)
2077 ISP_DISABLE_INTS(isp);
2081 isp_pci_reset1(ispsoftc_t *isp)
2083 if (!IS_24XX(isp)) {
2084 /* Make sure the BIOS is disabled */
2085 isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS);
2087 /* and enable interrupts */
2088 ISP_ENABLE_INTS(isp);
2092 isp_pci_dumpregs(ispsoftc_t *isp, const char *msg)
2094 struct isp_pcisoftc *pcs = (struct isp_pcisoftc *)isp;
2096 printf("%s: %s\n", device_get_nameunit(isp->isp_dev), msg);
2098 printf("%s:\n", device_get_nameunit(isp->isp_dev));
2100 printf(" biu_conf1=%x", ISP_READ(isp, BIU_CONF1));
2102 printf(" biu_csr=%x", ISP_READ(isp, BIU2100_CSR));
2103 printf(" biu_icr=%x biu_isr=%x biu_sema=%x ", ISP_READ(isp, BIU_ICR),
2104 ISP_READ(isp, BIU_ISR), ISP_READ(isp, BIU_SEMA));
2105 printf("risc_hccr=%x\n", ISP_READ(isp, HCCR));
2109 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
2110 printf(" cdma_conf=%x cdma_sts=%x cdma_fifostat=%x\n",
2111 ISP_READ(isp, CDMA_CONF), ISP_READ(isp, CDMA_STATUS),
2112 ISP_READ(isp, CDMA_FIFO_STS));
2113 printf(" ddma_conf=%x ddma_sts=%x ddma_fifostat=%x\n",
2114 ISP_READ(isp, DDMA_CONF), ISP_READ(isp, DDMA_STATUS),
2115 ISP_READ(isp, DDMA_FIFO_STS));
2116 printf(" sxp_int=%x sxp_gross=%x sxp(scsi_ctrl)=%x\n",
2117 ISP_READ(isp, SXP_INTERRUPT),
2118 ISP_READ(isp, SXP_GROSS_ERR),
2119 ISP_READ(isp, SXP_PINS_CTRL));
2120 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
2122 printf(" mbox regs: %x %x %x %x %x\n",
2123 ISP_READ(isp, OUTMAILBOX0), ISP_READ(isp, OUTMAILBOX1),
2124 ISP_READ(isp, OUTMAILBOX2), ISP_READ(isp, OUTMAILBOX3),
2125 ISP_READ(isp, OUTMAILBOX4));
2126 printf(" PCI Status Command/Status=%x\n",
2127 pci_read_config(pcs->pci_dev, PCIR_COMMAND, 1));