From b4df2201300946a00c0dbad92bae0835d5758e16 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Wed, 19 Mar 2014 19:58:36 +0100 Subject: [PATCH] aac(4): Sync with FreeBSD. Some bug fixes, static/const, etc. Also, add MSI support and use callout_init_mp(). --- share/man/man4/aac.4 | 10 ++- sys/dev/raid/aac/aac.c | 78 +++++++---------- sys/dev/raid/aac/aac_cam.c | 77 ++++++++++------- sys/dev/raid/aac/aac_debug.c | 2 +- sys/dev/raid/aac/aac_disk.c | 6 +- sys/dev/raid/aac/aac_ioctl.h | 2 +- sys/dev/raid/aac/aac_linux.c | 2 +- sys/dev/raid/aac/aac_pci.c | 153 +++++++++++++++++----------------- sys/dev/raid/aac/aac_tables.h | 13 +-- sys/dev/raid/aac/aacreg.h | 2 +- sys/dev/raid/aac/aacvar.h | 59 ++++++------- 11 files changed, 208 insertions(+), 196 deletions(-) diff --git a/share/man/man4/aac.4 b/share/man/man4/aac.4 index 381f45487b..38ce0a231c 100644 --- a/share/man/man4/aac.4 +++ b/share/man/man4/aac.4 @@ -22,8 +22,8 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/share/man/man4/aac.4,v 1.41 2009/07/11 08:10:18 jkim Exp $ -.Dd January 7, 2011 +.\" $FreeBSD: head/share/man/man4/aac.4 195614 2009-07-11 08:10:18Z jkim $ +.Dd March 19, 2014 .Dt AAC 4 .Os .Sh NAME @@ -86,6 +86,12 @@ Linux-compatible .Xr ioctl 2 interface for the management device will be enabled and will allow Linux-based management applications to control the card. +.Sh LOADER TUNABLES +.Bl -tag -width indent +.It Va hw.aac.msi.enable +By default, the driver will use MSI if it is supported. +This behavior can be turned off by setting this tunable to 0. +.El .Sh HARDWARE Controllers supported by the .Nm diff --git a/sys/dev/raid/aac/aac.c b/sys/dev/raid/aac/aac.c index b5613ae025..cc4777989a 100644 --- a/sys/dev/raid/aac/aac.c +++ b/sys/dev/raid/aac/aac.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac.c,v 1.170 2012/02/13 16:48:49 emaste Exp $ + * $FreeBSD: head/sys/dev/aac/aac.c 260044 2013-12-29 17:37:32Z marius $ */ /* @@ -114,7 +114,7 @@ static void aac_sa_set_mailbox(struct aac_softc *sc, u_int32_t command, static int aac_sa_get_mailbox(struct aac_softc *sc, int mb); static void aac_sa_set_interrupts(struct aac_softc *sc, int enable); -struct aac_interface aac_sa_interface = { +const struct aac_interface aac_sa_interface = { aac_sa_get_fwstatus, aac_sa_qnotify, aac_sa_get_istatus, @@ -139,7 +139,7 @@ static int aac_rx_send_command(struct aac_softc *sc, struct aac_command *cm); static int aac_rx_get_outb_queue(struct aac_softc *sc); static void aac_rx_set_outb_queue(struct aac_softc *sc, int index); -struct aac_interface aac_rx_interface = { +const struct aac_interface aac_rx_interface = { aac_rx_get_fwstatus, aac_rx_qnotify, aac_rx_get_istatus, @@ -166,7 +166,7 @@ static int aac_rkt_send_command(struct aac_softc *sc, struct aac_command *cm); static int aac_rkt_get_outb_queue(struct aac_softc *sc); static void aac_rkt_set_outb_queue(struct aac_softc *sc, int index); -struct aac_interface aac_rkt_interface = { +const struct aac_interface aac_rkt_interface = { aac_rkt_get_fwstatus, aac_rkt_qnotify, aac_rkt_get_istatus, @@ -180,8 +180,8 @@ struct aac_interface aac_rkt_interface = { }; /* Debugging and Diagnostics */ -static void aac_describe_controller(struct aac_softc *sc); -static char *aac_describe_code(struct aac_code_lookup *table, +static void aac_describe_controller(struct aac_softc *sc); +static const char *aac_describe_code(const struct aac_code_lookup *table, u_int32_t code); /* Management Interface */ @@ -220,7 +220,7 @@ static struct dev_ops aac_ops = { static MALLOC_DEFINE(M_AACBUF, "aacbuf", "Buffers for the AAC driver"); /* sysctl node */ -static SYSCTL_NODE(_hw, OID_AUTO, aac, CTLFLAG_RD, 0, "AAC driver parameters"); +SYSCTL_NODE(_hw, OID_AUTO, aac, CTLFLAG_RD, 0, "AAC driver parameters"); /* * Device Interface @@ -268,7 +268,7 @@ aac_attach(struct aac_softc *sc) TAILQ_INIT(&sc->aac_ev_cmfree); /* Initialize the clock daemon callout. */ - callout_init(&sc->aac_daemontime); + callout_init_mp(&sc->aac_daemontime); /* * Initialize the adapter. @@ -372,8 +372,8 @@ aac_daemon(void *arg) *(uint32_t *)fib->data = tv.tv_sec; aac_sync_fib(sc, SendHostTime, 0, fib, sizeof(uint32_t)); aac_release_sync_fib(sc); - lockmgr(&sc->aac_io_lock, LK_RELEASE); callout_reset(&sc->aac_daemontime, 30 * 60 * hz, aac_daemon, sc); + lockmgr(&sc->aac_io_lock, LK_RELEASE); } void @@ -389,8 +389,6 @@ aac_add_event(struct aac_softc *sc, struct aac_event *event) event->ev_type); break; } - - return; } /* @@ -637,9 +635,12 @@ aac_free(struct aac_softc *sc) /* disconnect the interrupt handler */ if (sc->aac_intr) bus_teardown_intr(sc->aac_dev, sc->aac_irq, sc->aac_intr); - if (sc->aac_irq != NULL) - bus_release_resource(sc->aac_dev, SYS_RES_IRQ, sc->aac_irq_rid, - sc->aac_irq); + if (sc->aac_irq != NULL) { + bus_release_resource(sc->aac_dev, SYS_RES_IRQ, + rman_get_rid(sc->aac_irq), sc->aac_irq); + if (sc->aac_irq_type == PCI_INTR_TYPE_MSI) + pci_release_msi(sc->aac_dev); + } /* destroy data-transfer DMA tag */ if (sc->aac_buffer_dmat) @@ -652,10 +653,10 @@ aac_free(struct aac_softc *sc) /* release the register window mapping */ if (sc->aac_regs_res0 != NULL) bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, - sc->aac_regs_rid0, sc->aac_regs_res0); + rman_get_rid(sc->aac_regs_res0), sc->aac_regs_res0); if (sc->aac_hwif == AAC_HWIF_NARK && sc->aac_regs_res1 != NULL) bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, - sc->aac_regs_rid1, sc->aac_regs_res1); + rman_get_rid(sc->aac_regs_res1), sc->aac_regs_res1); dev_ops_remove_minor(&aac_ops, device_get_unit(sc->aac_dev)); sysctl_ctx_free(&sc->aac_sysctl_ctx); @@ -1335,8 +1336,6 @@ aac_bio_complete(struct aac_command *cm) } else { bp->b_error = EIO; bp->b_flags |= B_ERROR; - /* pass an error string out to the disk layer */ - code = aac_describe_code(aac_command_status_table, status); } aac_biodone(bio, code); } @@ -1633,8 +1632,6 @@ aac_map_command_sg(void *arg, bus_dma_segment_t *segs, int nseg, int error) aac_requeue_ready(cm); } } - - return; } /* @@ -1686,7 +1683,7 @@ static int aac_check_firmware(struct aac_softc *sc) { u_int32_t code, major, minor, options = 0, atu_size = 0; - int status; + int rid, status; time_t then; fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); @@ -1764,7 +1761,7 @@ aac_check_firmware(struct aac_softc *sc) sc->flags |= AAC_FLAGS_SG_64BIT; } if ((options & AAC_SUPPORTED_NEW_COMM) - && sc->aac_if.aif_send_command) + && sc->aac_if->aif_send_command) sc->flags |= AAC_FLAGS_NEW_COMM; if (options & AAC_SUPPORTED_64BIT_ARRAYSIZE) sc->flags |= AAC_FLAGS_ARRAY_64BIT; @@ -1775,17 +1772,15 @@ aac_check_firmware(struct aac_softc *sc) /* Remap mem. resource, if required */ if ((sc->flags & AAC_FLAGS_NEW_COMM) && - atu_size > rman_get_size(sc->aac_regs_res1)) { - bus_release_resource( - sc->aac_dev, SYS_RES_MEMORY, - sc->aac_regs_rid1, sc->aac_regs_res1); - sc->aac_regs_res1 = bus_alloc_resource( - sc->aac_dev, SYS_RES_MEMORY, &sc->aac_regs_rid1, - 0ul, ~0ul, atu_size, RF_ACTIVE); + atu_size > rman_get_size(sc->aac_regs_res1)) { + rid = rman_get_rid(sc->aac_regs_res1); + bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, rid, + sc->aac_regs_res1); + sc->aac_regs_res1 = bus_alloc_resource(sc->aac_dev, + SYS_RES_MEMORY, &rid, 0ul, ~0ul, atu_size, RF_ACTIVE); if (sc->aac_regs_res1 == NULL) { sc->aac_regs_res1 = bus_alloc_resource_any( - sc->aac_dev, SYS_RES_MEMORY, - &sc->aac_regs_rid1, RF_ACTIVE); + sc->aac_dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->aac_regs_res1 == NULL) { device_printf(sc->aac_dev, "couldn't allocate register window\n"); @@ -1798,7 +1793,6 @@ aac_check_firmware(struct aac_softc *sc) if (sc->aac_hwif == AAC_HWIF_NARK) { sc->aac_regs_res0 = sc->aac_regs_res1; - sc->aac_regs_rid0 = sc->aac_regs_rid1; sc->aac_btag0 = sc->aac_btag1; sc->aac_bhandle0 = sc->aac_bhandle1; } @@ -2002,14 +1996,7 @@ out: static int aac_setup_intr(struct aac_softc *sc) { - sc->aac_irq_rid = 0; - if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ, - &sc->aac_irq_rid, - RF_SHAREABLE | - RF_ACTIVE)) == NULL) { - device_printf(sc->aac_dev, "can't allocate interrupt\n"); - return (EINVAL); - } + if (sc->flags & AAC_FLAGS_NEW_COMM) { if (bus_setup_intr(sc->aac_dev, sc->aac_irq, INTR_MPSAFE, @@ -2120,7 +2107,7 @@ aac_sync_fib(struct aac_softc *sc, u_int32_t command, u_int32_t xferstate, * Note that the queue implementation here is a little funky; neither the PI or * CI will ever be zero. This behaviour is a controller feature. */ -static struct { +static const struct { int size; int notify; } aac_qinfo[] = { @@ -2376,7 +2363,6 @@ aac_timeout(struct aac_softc *sc) "longer running! code= 0x%x\n", code); } } - return; } /* @@ -2787,8 +2773,8 @@ aac_describe_controller(struct aac_softc *sc) * Look up a text description of a numeric error code and return a pointer to * same. */ -static char * -aac_describe_code(struct aac_code_lookup *table, u_int32_t code) +static const char * +aac_describe_code(const struct aac_code_lookup *table, u_int32_t code) { int i; @@ -3414,8 +3400,6 @@ aac_handle_aif(struct aac_softc *sc, struct aac_fib *fib) KNOTE(&sc->rcv_kq.ki_note, 0); /* token may have been lost */ lockmgr(&sc->aac_aifq_lock, LK_RELEASE); - - return; } /* @@ -3825,6 +3809,4 @@ aac_get_bus_info(struct aac_softc *sc) if (found) bus_generic_attach(sc->aac_dev); - - return; } diff --git a/sys/dev/raid/aac/aac_cam.c b/sys/dev/raid/aac/aac_cam.c index 15815fec9a..821d8a355e 100644 --- a/sys/dev/raid/aac/aac_cam.c +++ b/sys/dev/raid/aac/aac_cam.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac_cam.c,v 1.42 2011/11/07 06:44:47 ed Exp $ + * $FreeBSD: head/sys/dev/aac/aac_cam.c 251115 2013-05-30 00:11:22Z marius $ */ /* @@ -532,6 +532,53 @@ aac_cam_poll(struct cam_sim *sim) */ } +static void +aac_cam_fix_inquiry(struct aac_softc *sc, union ccb *ccb) +{ + struct scsi_inquiry_data *inq; + uint8_t *data; + uint8_t device, qual; + + /* If this is an inquiry command, fake things out */ + if (ccb->ccb_h.flags & CAM_CDB_POINTER) + data = ccb->csio.cdb_io.cdb_ptr; + else + data = ccb->csio.cdb_io.cdb_bytes; + + if (data[0] != INQUIRY) + return; + + if (ccb->ccb_h.status == CAM_REQ_CMP) { + inq = (struct scsi_inquiry_data *)ccb->csio.data_ptr; + device = SID_TYPE(inq); + qual = SID_QUAL(inq); + + /* + * We want DASD and PROC devices to only be + * visible through the pass device. + */ + if (((device == T_DIRECT) || + (device == T_PROCESSOR) || + (sc->flags & AAC_FLAGS_CAM_PASSONLY))) { + /* + * Some aac(4) adapters will always report that a direct + * access device is offline in response to a INQUIRY + * command that does not retreive vital product data. + * Force the qualifier to connected so that upper layers + * correctly recognize that a disk is present. + */ + if ((data[1] & SI_EVPD) == 0 && device == T_DIRECT && + qual == SID_QUAL_LU_OFFLINE) + qual = SID_QUAL_LU_CONNECTED; + ccb->csio.data_ptr[0] = (qual << 5) | T_NODEVICE; + } + } else if (ccb->ccb_h.status == CAM_SEL_TIMEOUT && + ccb->ccb_h.target_lun != 0) { + /* fix for INQUIRYs on Lun>0 */ + ccb->ccb_h.status = CAM_DEV_NOT_THERE; + } +} + static void aac_cam_complete(struct aac_command *cm) { @@ -557,8 +604,6 @@ aac_cam_complete(struct aac_command *cm) /* Take care of SCSI_IO ops. */ if (ccb->ccb_h.func_code == XPT_SCSI_IO) { - u_int8_t command, device; - ccb->csio.scsi_status = srbr->scsi_status; /* Take care of autosense */ @@ -578,31 +623,7 @@ aac_cam_complete(struct aac_command *cm) // scsi_sense_print(&ccb->csio); } - /* If this is an inquiry command, fake things out */ - if (ccb->ccb_h.flags & CAM_CDB_POINTER) - command = ccb->csio.cdb_io.cdb_ptr[0]; - else - command = ccb->csio.cdb_io.cdb_bytes[0]; - - if (command == INQUIRY) { - if (ccb->ccb_h.status == CAM_REQ_CMP) { - device = ccb->csio.data_ptr[0] & 0x1f; - /* - * We want DASD and PROC devices to only be - * visible through the pass device. - */ - if ((device == T_DIRECT) || - (device == T_PROCESSOR) || - (sc->flags & AAC_FLAGS_CAM_PASSONLY)) - ccb->csio.data_ptr[0] = - ((ccb->csio.data_ptr[0] & 0xe0) | - T_NODEVICE); - } else if (ccb->ccb_h.status == CAM_SEL_TIMEOUT && - ccb->ccb_h.target_lun != 0) { - /* fix for INQUIRYs on Lun>0 */ - ccb->ccb_h.status = CAM_DEV_NOT_THERE; - } - } + aac_cam_fix_inquiry(sc, ccb); } } diff --git a/sys/dev/raid/aac/aac_debug.c b/sys/dev/raid/aac/aac_debug.c index 6bffdc63b0..3eb7c0bbe1 100644 --- a/sys/dev/raid/aac/aac_debug.c +++ b/sys/dev/raid/aac/aac_debug.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac_debug.c,v 1.26 2010/04/13 00:33:07 emaste Exp $ + * $FreeBSD: head/sys/dev/aac/aac_debug.c 242823 2012-11-09 13:58:52Z rdivacky $ */ /* diff --git a/sys/dev/raid/aac/aac_disk.c b/sys/dev/raid/aac/aac_disk.c index f5f39e653a..5993b8ba01 100644 --- a/sys/dev/raid/aac/aac_disk.c +++ b/sys/dev/raid/aac/aac_disk.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac_disk.c,v 1.50 2012/07/07 17:20:24 eadler Exp $ + * $FreeBSD: head/sys/dev/aac/aac_disk.c 251115 2013-05-30 00:11:22Z marius $ */ #include "opt_aac.h" @@ -355,8 +355,8 @@ aac_biodone(struct bio *bio, const char *code) devstat_end_transaction_buf(&sc->ad_stats, bp); if (bp->b_flags & B_ERROR) { - diskerr(bio, sc->ad_dev_t, - code, 0, 0); + bp->b_resid = bp->b_bcount; + diskerr(bio, sc->ad_dev_t, code, 0, 0); } biodone(bio); diff --git a/sys/dev/raid/aac/aac_ioctl.h b/sys/dev/raid/aac/aac_ioctl.h index e2662032db..b0bf74373a 100644 --- a/sys/dev/raid/aac/aac_ioctl.h +++ b/sys/dev/raid/aac/aac_ioctl.h @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/sys/aac_ioctl.h,v 1.15 2011/02/21 09:01:34 brucec Exp $ + * $FreeBSD: head/sys/sys/aac_ioctl.h 218909 2011-02-21 09:01:34Z brucec $ */ #include diff --git a/sys/dev/raid/aac/aac_linux.c b/sys/dev/raid/aac/aac_linux.c index 2f567fcb71..60f0964466 100644 --- a/sys/dev/raid/aac/aac_linux.c +++ b/sys/dev/raid/aac/aac_linux.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac_linux.c,v 1.4 2006/12/20 17:10:53 delphij Exp $ + * $FreeBSD: head/sys/dev/aac/aac_linux.c 165393 2006-12-20 17:10:53Z delphij $ */ /* diff --git a/sys/dev/raid/aac/aac_pci.c b/sys/dev/raid/aac/aac_pci.c index 39c70e480b..78eb928ff2 100644 --- a/sys/dev/raid/aac/aac_pci.c +++ b/sys/dev/raid/aac/aac_pci.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac_pci.c,v 1.74 2010/04/13 01:16:15 emaste Exp $ + * $FreeBSD: head/sys/dev/aac/aac_pci.c 254005 2013-08-06 19:14:02Z marius $ */ /* @@ -57,6 +57,9 @@ static int aac_pci_probe(device_t dev); static int aac_pci_attach(device_t dev); +static int aac_msi_enable = 1; +TUNABLE_INT("hw.mfi.msi.enable", &aac_msi_enable); + static device_method_t aac_methods[] = { /* Device interface */ DEVMETHOD(device_probe, aac_pci_probe), @@ -65,8 +68,6 @@ static device_method_t aac_methods[] = { DEVMETHOD(device_suspend, aac_suspend), DEVMETHOD(device_resume, aac_resume), - DEVMETHOD(bus_print_child, bus_generic_print_child), - DEVMETHOD(bus_driver_added, bus_generic_driver_added), DEVMETHOD_END }; @@ -82,7 +83,7 @@ DRIVER_MODULE(aac, pci, aac_pci_driver, aac_devclass, NULL, NULL); MODULE_DEPEND(aac, pci, 1, 1, 1); -struct aac_ident +static const struct aac_ident { u_int16_t vendor; u_int16_t device; @@ -90,7 +91,7 @@ struct aac_ident u_int16_t subdevice; int hwif; int quirks; - char *desc; + const char *desc; } aac_identifiers[] = { {0x1028, 0x0001, 0x1028, 0x0001, AAC_HWIF_I960RX, 0, "Dell PERC 2/Si"}, @@ -134,11 +135,10 @@ struct aac_ident "Adaptec SATA RAID 21610SA"}, {0x9005, 0x0285, 0x103c, 0x3227, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB, "HP ML110 G2 (Adaptec 2610SA)"}, - {0x9005, 0x0286, 0x9005, 0x028c, AAC_HWIF_RKT, 0, + {0x9005, 0x0286, 0x9005, 0x028c, AAC_HWIF_RKT, AAC_FLAGS_NOMSI, "Adaptec SCSI RAID 2230S"}, {0x9005, 0x0286, 0x9005, 0x028d, AAC_HWIF_RKT, 0, "Adaptec SCSI RAID 2130S"}, - {0x9005, 0x0285, 0x9005, 0x0287, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB | AAC_FLAGS_256FIBS, "Adaptec SCSI RAID 2200S"}, {0x9005, 0x0285, 0x17aa, 0x0286, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB | @@ -153,7 +153,7 @@ struct aac_ident "Adaptec SCSI RAID 2020ZCR"}, {0x9005, 0x0285, 0x9005, 0x028b, AAC_HWIF_I960RX, 0, "Adaptec SCSI RAID 2025ZCR"}, - {0x9005, 0x0286, 0x9005, 0x029b, AAC_HWIF_RKT, 0, + {0x9005, 0x0286, 0x9005, 0x029b, AAC_HWIF_RKT, AAC_FLAGS_NOMSI, "Adaptec SATA RAID 2820SA"}, {0x9005, 0x0286, 0x9005, 0x029c, AAC_HWIF_RKT, 0, "Adaptec SATA RAID 2620SA"}, @@ -275,7 +275,8 @@ struct aac_ident "AOC-USAS-S8iR-LP"}, {0, 0, 0, 0, 0, 0, 0} }; -struct aac_ident + +static const struct aac_ident aac_family_identifiers[] = { {0x9005, 0x0285, 0, 0, AAC_HWIF_I960RX, 0, "Adaptec RAID Controller"}, @@ -284,10 +285,10 @@ aac_family_identifiers[] = { {0, 0, 0, 0, 0, 0, 0} }; -static struct aac_ident * +static const struct aac_ident * aac_find_ident(device_t dev) { - struct aac_ident *m; + const struct aac_ident *m; u_int16_t vendid, devid, sub_vendid, sub_devid; vendid = pci_get_vendor(dev); @@ -306,7 +307,6 @@ aac_find_ident(device_t dev) if ((m->vendor == vendid) && (m->device == devid)) return (m); } - return (NULL); } @@ -316,7 +316,7 @@ aac_find_ident(device_t dev) static int aac_pci_probe(device_t dev) { - struct aac_ident *id; + const struct aac_ident *id; fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); @@ -334,9 +334,9 @@ static int aac_pci_attach(device_t dev) { struct aac_softc *sc; - struct aac_ident *id; - int error; - u_int32_t command; + const struct aac_ident *id; + int error, rid; + u_int irq_flags; fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, ""); @@ -344,7 +344,6 @@ aac_pci_attach(device_t dev) * Initialise softc. */ sc = device_get_softc(dev); - bzero(sc, sizeof(*sc)); sc->aac_dev = dev; /* assume failure is 'not configured' */ @@ -353,55 +352,92 @@ aac_pci_attach(device_t dev) /* * Verify that the adapter is correctly set up in PCI space. */ - command = pci_read_config(sc->aac_dev, PCIR_COMMAND, 2); - command |= PCIM_CMD_BUSMASTEREN; - pci_write_config(dev, PCIR_COMMAND, command, 2); - command = pci_read_config(sc->aac_dev, PCIR_COMMAND, 2); - if (!(command & PCIM_CMD_BUSMASTEREN)) { - device_printf(sc->aac_dev, "can't enable bus-master feature\n"); + pci_enable_busmaster(dev); + if (!(pci_read_config(dev, PCIR_COMMAND, 2) & PCIM_CMD_BUSMASTEREN)) { + device_printf(dev, "can't enable bus-master feature\n"); goto out; } - if ((command & PCIM_CMD_MEMEN) == 0) { - device_printf(sc->aac_dev, "memory window not available\n"); + + /* + * Detect the hardware interface version, set up the bus interface + * indirection. + */ + id = aac_find_ident(dev); + sc->aac_hwif = id->hwif; + switch(sc->aac_hwif) { + case AAC_HWIF_I960RX: + case AAC_HWIF_NARK: + fwprintf(sc, HBA_FLAGS_DBG_INIT_B, + "set hardware up for i960Rx/NARK"); + sc->aac_if = &aac_rx_interface; + break; + case AAC_HWIF_STRONGARM: + fwprintf(sc, HBA_FLAGS_DBG_INIT_B, + "set hardware up for StrongARM"); + sc->aac_if = &aac_sa_interface; + break; + case AAC_HWIF_RKT: + fwprintf(sc, HBA_FLAGS_DBG_INIT_B, + "set hardware up for Rocket/MIPS"); + sc->aac_if = &aac_rkt_interface; + break; + default: + sc->aac_hwif = AAC_HWIF_UNKNOWN; + device_printf(dev, "unknown hardware type\n"); goto out; } + /* Set up quirks */ + sc->flags = id->quirks; + /* - * Allocate the PCI register window. + * Allocate the PCI register window(s). */ - sc->aac_regs_rid0 = PCIR_BAR(0); - if ((sc->aac_regs_res0 = bus_alloc_resource_any(sc->aac_dev, - SYS_RES_MEMORY, &sc->aac_regs_rid0, RF_ACTIVE)) == NULL) { - device_printf(sc->aac_dev, - "couldn't allocate register window 0\n"); + rid = PCIR_BAR(0); + if ((sc->aac_regs_res0 = bus_alloc_resource_any(dev, + SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) { + device_printf(dev, "can't allocate register window 0\n"); goto out; } sc->aac_btag0 = rman_get_bustag(sc->aac_regs_res0); sc->aac_bhandle0 = rman_get_bushandle(sc->aac_regs_res0); if (sc->aac_hwif == AAC_HWIF_NARK) { - sc->aac_regs_rid1 = PCIR_BAR(1); - if ((sc->aac_regs_res1 = bus_alloc_resource_any(sc->aac_dev, - SYS_RES_MEMORY, &sc->aac_regs_rid1, RF_ACTIVE)) == NULL) { - device_printf(sc->aac_dev, - "couldn't allocate register window 1\n"); + rid = PCIR_BAR(1); + if ((sc->aac_regs_res1 = bus_alloc_resource_any(dev, + SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) { + device_printf(dev, + "can't allocate register window 1\n"); goto out; } sc->aac_btag1 = rman_get_bustag(sc->aac_regs_res1); sc->aac_bhandle1 = rman_get_bushandle(sc->aac_regs_res1); } else { sc->aac_regs_res1 = sc->aac_regs_res0; - sc->aac_regs_rid1 = sc->aac_regs_rid0; sc->aac_btag1 = sc->aac_btag0; sc->aac_bhandle1 = sc->aac_bhandle0; } + /* + * Allocate the interrupt. + */ + sc->aac_irq_rid = 0; + if ((sc->flags & AAC_FLAGS_NOMSI) != 0) + aac_msi_enable = 0; + sc->aac_irq_type = pci_alloc_1intr(sc->aac_dev, aac_msi_enable, + &sc->aac_irq_rid, &irq_flags); + if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ, + &sc->aac_irq_rid, irq_flags)) == NULL) { + device_printf(dev, "can't allocate interrupt\n"); + goto out; + } + /* * Allocate the parent bus DMA tag appropriate for our PCI interface. * * Note that some of these controllers are 64-bit capable. */ - if (bus_dma_tag_create(NULL, /* parent */ + if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */ PAGE_SIZE, 0, /* algnmnt, boundary */ BUS_SPACE_MAXADDR, /* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ @@ -411,40 +447,10 @@ aac_pci_attach(device_t dev) BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 0, /* flags */ &sc->aac_parent_dmat)) { - device_printf(sc->aac_dev, "can't allocate parent DMA tag\n"); + device_printf(dev, "can't allocate parent DMA tag\n"); goto out; } - /* - * Detect the hardware interface version, set up the bus interface - * indirection. - */ - id = aac_find_ident(dev); - sc->aac_hwif = id->hwif; - switch(sc->aac_hwif) { - case AAC_HWIF_I960RX: - case AAC_HWIF_NARK: - fwprintf(sc, HBA_FLAGS_DBG_INIT_B, "set hardware up for i960Rx/NARK"); - sc->aac_if = aac_rx_interface; - break; - case AAC_HWIF_STRONGARM: - fwprintf(sc, HBA_FLAGS_DBG_INIT_B, "set hardware up for StrongARM"); - sc->aac_if = aac_sa_interface; - break; - case AAC_HWIF_RKT: - fwprintf(sc, HBA_FLAGS_DBG_INIT_B, "set hardware up for Rocket/MIPS"); - sc->aac_if = aac_rkt_interface; - break; - default: - sc->aac_hwif = AAC_HWIF_UNKNOWN; - device_printf(sc->aac_dev, "unknown hardware type\n"); - error = ENXIO; - goto out; - } - - /* Set up quirks */ - sc->flags = id->quirks; - /* * Do bus-independent initialisation. */ @@ -499,19 +505,14 @@ aacch_probe(device_t dev) } static int -aacch_attach(device_t dev) +aacch_attach(device_t dev __unused) { - struct aacch_softc *sc; - - sc = device_get_softc(dev); - - sc->dev = dev; return (0); } static int -aacch_detach(device_t dev) +aacch_detach(device_t dev __unused) { return (0); diff --git a/sys/dev/raid/aac/aac_tables.h b/sys/dev/raid/aac/aac_tables.h index ae26799229..b73425f8cf 100644 --- a/sys/dev/raid/aac/aac_tables.h +++ b/sys/dev/raid/aac/aac_tables.h @@ -24,16 +24,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aac_tables.h,v 1.8 2010/04/13 12:10:55 emaste Exp $ + * $FreeBSD: head/sys/dev/aac/aac_tables.h 247570 2013-03-01 19:55:10Z marius $ */ +#if 0 /* * Status codes for block read/write commands, etc. * * XXX many of these would not normally be returned, as they are * relevant only to FSA operations. */ -static struct aac_code_lookup aac_command_status_table[] = { +static const struct aac_code_lookup aac_command_status_table[] = { {"OK", ST_OK}, {"operation not permitted", ST_PERM}, {"not found", ST_NOENT}, @@ -75,8 +76,9 @@ static struct aac_code_lookup aac_command_status_table[] = { }; #define AAC_COMMAND_STATUS(x) aac_describe_code(aac_command_status_table, x) +#endif -static struct aac_code_lookup aac_cpu_variant[] = { +static const struct aac_code_lookup aac_cpu_variant[] = { {"i960JX", CPUI960_JX}, {"i960CX", CPUI960_CX}, {"i960HX", CPUI960_HX}, @@ -93,7 +95,7 @@ static struct aac_code_lookup aac_cpu_variant[] = { {"Unknown processor", 0} }; -static struct aac_code_lookup aac_battery_platform[] = { +static const struct aac_code_lookup aac_battery_platform[] = { {"required battery present", PLATFORM_BAT_REQ_PRESENT}, {"REQUIRED BATTERY NOT PRESENT", PLATFORM_BAT_REQ_NOTPRESENT}, {"optional battery present", PLATFORM_BAT_OPT_PRESENT}, @@ -103,7 +105,7 @@ static struct aac_code_lookup aac_battery_platform[] = { {"unknown battery platform", 0} }; -static struct aac_code_lookup aac_container_types[] = { +static const struct aac_code_lookup aac_container_types[] = { {"Volume", CT_VOLUME}, {"RAID 1 (Mirror)", CT_MIRROR}, {"RAID 0 (Stripe)", CT_STRIPE}, @@ -126,4 +128,3 @@ static struct aac_code_lookup aac_container_types[] = { {NULL, 0}, {"unknown", 0} }; - diff --git a/sys/dev/raid/aac/aacreg.h b/sys/dev/raid/aac/aacreg.h index 17fe7ce34a..4f5b3889ac 100644 --- a/sys/dev/raid/aac/aacreg.h +++ b/sys/dev/raid/aac/aacreg.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aacreg.h,v 1.34 2010/09/29 14:22:00 emaste Exp $ + * $FreeBSD: head/sys/dev/aac/aacreg.h 213272 2010-09-29 14:22:00Z emaste $ */ /* diff --git a/sys/dev/raid/aac/aacvar.h b/sys/dev/raid/aac/aacvar.h index d77245b13b..3284a0cdf4 100644 --- a/sys/dev/raid/aac/aacvar.h +++ b/sys/dev/raid/aac/aacvar.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.63 2011/06/10 20:23:56 attilio Exp $ + * $FreeBSD: head/sys/dev/aac/aacvar.h 258780 2013-11-30 22:17:27Z eadler $ */ #include @@ -39,6 +39,8 @@ #include #include +SYSCTL_DECL(_hw_aac); + #define AAC_TYPE_DEVO 1 #define AAC_TYPE_ALPHA 2 #define AAC_TYPE_BETA 3 @@ -61,7 +63,7 @@ * The firmware interface allows for a 16-bit s/g list length. We limit * ourselves to a reasonable maximum and ensure alignment. */ -#define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */ +#define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */ /* * We allocate a small set of FIBs for the adapter to use to send us messages. @@ -159,13 +161,13 @@ struct aac_command struct aac_fib *cm_fib; /* FIB associated with this * command */ u_int64_t cm_fibphys; /* bus address of the FIB */ - struct bio *cm_data; /* pointer to data in kernel + void *cm_data; /* pointer to data in kernel * space */ u_int32_t cm_datalen; /* data length */ bus_dmamap_t cm_datamap; /* DMA map for bio data */ struct aac_sg_table *cm_sgtable; /* pointer to s/g table in * command */ - int cm_flags; + u_int cm_flags; #define AAC_CMD_MAPPED (1<<0) /* command has had its data * mapped */ #define AAC_CMD_DATAIN (1<<1) /* command involves data moving @@ -183,7 +185,7 @@ struct aac_command #define AAC_QUEUE_FRZN (1<<9) /* Freeze the processing of * commands on the queue. */ - void (* cm_complete)(struct aac_command *cm); + void (*cm_complete)(struct aac_command *cm); void *cm_private; time_t cm_timestamp; /* command creation time */ int cm_queue; @@ -223,7 +225,7 @@ struct aac_common { /* buffer for text messages from the controller */ char ac_printf[AAC_PRINTF_BUFSIZE]; - + /* fib for synchronous commands */ struct aac_fib ac_sync_fib; }; @@ -246,27 +248,27 @@ struct aac_interface int (*aif_get_outb_queue)(struct aac_softc *sc); void (*aif_set_outb_queue)(struct aac_softc *sc, int index); }; -extern struct aac_interface aac_rx_interface; -extern struct aac_interface aac_sa_interface; -extern struct aac_interface aac_rkt_interface; - -#define AAC_GET_FWSTATUS(sc) ((sc)->aac_if.aif_get_fwstatus((sc))) -#define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if.aif_qnotify((sc), (qbit))) -#define AAC_GET_ISTATUS(sc) ((sc)->aac_if.aif_get_istatus((sc))) -#define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if.aif_clr_istatus((sc), \ +extern const struct aac_interface aac_rx_interface; +extern const struct aac_interface aac_sa_interface; +extern const struct aac_interface aac_rkt_interface; + +#define AAC_GET_FWSTATUS(sc) ((sc)->aac_if->aif_get_fwstatus((sc))) +#define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if->aif_qnotify((sc), (qbit))) +#define AAC_GET_ISTATUS(sc) ((sc)->aac_if->aif_get_istatus((sc))) +#define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if->aif_clr_istatus((sc), \ (mask))) #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ - ((sc)->aac_if.aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \ + ((sc)->aac_if->aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \ (arg3))) -#define AAC_GET_MAILBOX(sc, mb) ((sc)->aac_if.aif_get_mailbox((sc), \ +#define AAC_GET_MAILBOX(sc, mb) ((sc)->aac_if->aif_get_mailbox((sc), \ (mb))) -#define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ +#define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if->aif_set_interrupts((sc), \ 0)) -#define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ +#define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if->aif_set_interrupts((sc), \ 1)) -#define AAC_SEND_COMMAND(sc, cm) ((sc)->aac_if.aif_send_command((sc), (cm))) -#define AAC_GET_OUTB_QUEUE(sc) ((sc)->aac_if.aif_get_outb_queue((sc))) -#define AAC_SET_OUTB_QUEUE(sc, idx) ((sc)->aac_if.aif_set_outb_queue((sc), (idx))) +#define AAC_SEND_COMMAND(sc, cm) ((sc)->aac_if->aif_send_command((sc), (cm))) +#define AAC_GET_OUTB_QUEUE(sc) ((sc)->aac_if->aif_get_outb_queue((sc))) +#define AAC_SET_OUTB_QUEUE(sc, idx) ((sc)->aac_if->aif_set_outb_queue((sc), (idx))) #define AAC_MEM0_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag0, \ sc->aac_bhandle0, reg, val) @@ -310,15 +312,16 @@ struct aac_softc /* bus connections */ device_t aac_dev; struct resource *aac_regs_res0, *aac_regs_res1; /* reg. if. window */ - int aac_regs_rid0, aac_regs_rid1; /* resource ID */ bus_space_handle_t aac_bhandle0, aac_bhandle1; /* bus space handle */ bus_space_tag_t aac_btag0, aac_btag1; /* bus space tag */ bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */ bus_dma_tag_t aac_buffer_dmat; /* data buffer/command * DMA tag */ + struct resource *aac_irq; /* interrupt */ - int aac_irq_rid; void *aac_intr; /* interrupt handle */ + int aac_irq_rid; + int aac_irq_type; eventhandler_tag eh; /* controller features, limits and status */ @@ -342,7 +345,7 @@ struct aac_softc * DMA map */ struct aac_common *aac_common; u_int32_t aac_common_busaddr; - struct aac_interface aac_if; + const struct aac_interface *aac_if; /* command/fib resources */ bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocing FIBs */ @@ -409,12 +412,13 @@ struct aac_softc #define AAC_FLAGS_NO4GB (1 << 6) /* Can't access host mem >2GB */ #define AAC_FLAGS_256FIBS (1 << 7) /* Can only do 256 commands */ #define AAC_FLAGS_BROKEN_MEMMAP (1 << 8) /* Broken HostPhysMemPages */ -#define AAC_FLAGS_SLAVE (1 << 9) +#define AAC_FLAGS_SLAVE (1 << 9) #define AAC_FLAGS_MASTER (1 << 10) #define AAC_FLAGS_NEW_COMM (1 << 11) /* New comm. interface supported */ #define AAC_FLAGS_RAW_IO (1 << 12) /* Raw I/O interface */ #define AAC_FLAGS_ARRAY_64BIT (1 << 13) /* 64-bit array size */ #define AAC_FLAGS_LBA_64BIT (1 << 14) /* 64-bit LBA support */ +#define AAC_FLAGS_NOMSI (1U << 31) /* Broken MSI */ u_int32_t supported_options; u_int32_t scsi_method_id; @@ -505,7 +509,7 @@ extern void aac_print_aif(struct aac_softc *sc, #endif struct aac_code_lookup { - char *string; + const char *string; u_int32_t code; }; @@ -530,7 +534,6 @@ struct aac_code_lookup { sc->aac_qstat[qname].q_max = 0; \ } while (0) - #define AACQ_COMMAND_QUEUE(name, index) \ static __inline void \ aac_initq_ ## name (struct aac_softc *sc) \ @@ -587,7 +590,6 @@ aac_remove_ ## name (struct aac_command *cm) \ cm->cm_flags &= ~AAC_ON_ ## index; \ AACQ_REMOVE(cm->cm_sc, index); \ } \ -struct hack AACQ_COMMAND_QUEUE(free, AACQ_FREE); AACQ_COMMAND_QUEUE(ready, AACQ_READY); @@ -643,7 +645,6 @@ aac_alloc_sync_fib(struct aac_softc *sc, struct aac_fib **fib) *fib = &sc->aac_common->ac_sync_fib; return (0); } - static __inline void aac_release_sync_fib(struct aac_softc *sc) { -- 2.41.0