13a31b7ebSMike Smith /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 43a31b7ebSMike Smith * Copyright (c) 2001 Michael Smith 5c6131460SPaul Saab * Copyright (c) 2004 Paul Saab 63a31b7ebSMike Smith * All rights reserved. 73a31b7ebSMike Smith * 83a31b7ebSMike Smith * Redistribution and use in source and binary forms, with or without 93a31b7ebSMike Smith * modification, are permitted provided that the following conditions 103a31b7ebSMike Smith * are met: 113a31b7ebSMike Smith * 1. Redistributions of source code must retain the above copyright 123a31b7ebSMike Smith * notice, this list of conditions and the following disclaimer. 133a31b7ebSMike Smith * 2. Redistributions in binary form must reproduce the above copyright 143a31b7ebSMike Smith * notice, this list of conditions and the following disclaimer in the 153a31b7ebSMike Smith * documentation and/or other materials provided with the distribution. 163a31b7ebSMike Smith * 173a31b7ebSMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 183a31b7ebSMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 193a31b7ebSMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 203a31b7ebSMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 213a31b7ebSMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 223a31b7ebSMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 233a31b7ebSMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 243a31b7ebSMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 253a31b7ebSMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 263a31b7ebSMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 273a31b7ebSMike Smith * SUCH DAMAGE. 283a31b7ebSMike Smith */ 293a31b7ebSMike Smith 303a31b7ebSMike Smith /* 313a31b7ebSMike Smith * Common Interface for SCSI-3 Support driver. 323a31b7ebSMike Smith * 333a31b7ebSMike Smith * CISS claims to provide a common interface between a generic SCSI 343a31b7ebSMike Smith * transport and an intelligent host adapter. 353a31b7ebSMike Smith * 363a31b7ebSMike Smith * This driver supports CISS as defined in the document "CISS Command 373a31b7ebSMike Smith * Interface for SCSI-3 Support Open Specification", Version 1.04, 383a31b7ebSMike Smith * Valence Number 1, dated 20001127, produced by Compaq Computer 393a31b7ebSMike Smith * Corporation. This document appears to be a hastily and somewhat 403a31b7ebSMike Smith * arbitrarlily cut-down version of a larger (and probably even more 413a31b7ebSMike Smith * chaotic and inconsistent) Compaq internal document. Various 423a31b7ebSMike Smith * details were also gleaned from Compaq's "cciss" driver for Linux. 433a31b7ebSMike Smith * 443a31b7ebSMike Smith * We provide a shim layer between the CISS interface and CAM, 453a31b7ebSMike Smith * offloading most of the queueing and being-a-disk chores onto CAM. 463a31b7ebSMike Smith * Entry to the driver is via the PCI bus attachment (ciss_probe, 473a31b7ebSMike Smith * ciss_attach, etc) and via the CAM interface (ciss_cam_action, 483a31b7ebSMike Smith * ciss_cam_poll). The Compaq CISS adapters are, however, poor SCSI 493a31b7ebSMike Smith * citizens and we have to fake up some responses to get reasonable 503a31b7ebSMike Smith * behaviour out of them. In addition, the CISS command set is by no 513a31b7ebSMike Smith * means adequate to support the functionality of a RAID controller, 523a31b7ebSMike Smith * and thus the supported Compaq adapters utilise portions of the 533a31b7ebSMike Smith * control protocol from earlier Compaq adapter families. 543a31b7ebSMike Smith * 553a31b7ebSMike Smith * Note that we only support the "simple" transport layer over PCI. 563a31b7ebSMike Smith * This interface (ab)uses the I2O register set (specifically the post 573a31b7ebSMike Smith * queues) to exchange commands with the adapter. Other interfaces 583a31b7ebSMike Smith * are available, but we aren't supposed to know about them, and it is 593a31b7ebSMike Smith * dubious whether they would provide major performance improvements 603a31b7ebSMike Smith * except under extreme load. 613a31b7ebSMike Smith * 623a31b7ebSMike Smith * Currently the only supported CISS adapters are the Compaq Smart 633a31b7ebSMike Smith * Array 5* series (5300, 5i, 532). Even with only three adapters, 643a31b7ebSMike Smith * Compaq still manage to have interface variations. 653a31b7ebSMike Smith * 663a31b7ebSMike Smith * 673a31b7ebSMike Smith * Thanks must go to Fred Harris and Darryl DeVinney at Compaq, as 683a31b7ebSMike Smith * well as Paul Saab at Yahoo! for their assistance in making this 693a31b7ebSMike Smith * driver happen. 70c6131460SPaul Saab * 71c6131460SPaul Saab * More thanks must go to John Cagle at HP for the countless hours 72c6131460SPaul Saab * spent making this driver "work" with the MSA* series storage 73c6131460SPaul Saab * enclosures. Without his help (and nagging), this driver could not 74c6131460SPaul Saab * be used with these enclosures. 753a31b7ebSMike Smith */ 763a31b7ebSMike Smith 773a31b7ebSMike Smith #include <sys/param.h> 783a31b7ebSMike Smith #include <sys/systm.h> 793a31b7ebSMike Smith #include <sys/malloc.h> 803a31b7ebSMike Smith #include <sys/kernel.h> 813a31b7ebSMike Smith #include <sys/bus.h> 823a31b7ebSMike Smith #include <sys/conf.h> 833a31b7ebSMike Smith #include <sys/stat.h> 84c6131460SPaul Saab #include <sys/kthread.h> 85c6131460SPaul Saab #include <sys/queue.h> 8617c0792dSPaul Saab #include <sys/sysctl.h> 873a31b7ebSMike Smith 883a31b7ebSMike Smith #include <cam/cam.h> 893a31b7ebSMike Smith #include <cam/cam_ccb.h> 903a31b7ebSMike Smith #include <cam/cam_periph.h> 913a31b7ebSMike Smith #include <cam/cam_sim.h> 923a31b7ebSMike Smith #include <cam/cam_xpt_sim.h> 933a31b7ebSMike Smith #include <cam/scsi/scsi_all.h> 943a31b7ebSMike Smith #include <cam/scsi/scsi_message.h> 953a31b7ebSMike Smith 963a31b7ebSMike Smith #include <machine/bus.h> 973a31b7ebSMike Smith #include <machine/endian.h> 983a31b7ebSMike Smith #include <machine/resource.h> 993a31b7ebSMike Smith #include <sys/rman.h> 1003a31b7ebSMike Smith 1014fbd232cSWarner Losh #include <dev/pci/pcireg.h> 1024fbd232cSWarner Losh #include <dev/pci/pcivar.h> 1033a31b7ebSMike Smith 1043a31b7ebSMike Smith #include <dev/ciss/cissreg.h> 1053a31b7ebSMike Smith #include <dev/ciss/cissio.h> 10622657ce1SScott Long #include <dev/ciss/cissvar.h> 1073a31b7ebSMike Smith 1082e3d6d0fSWarner Losh #ifdef CISS_DEBUG 1092e3d6d0fSWarner Losh #include "opt_ddb.h" 1102e3d6d0fSWarner Losh #endif 1112e3d6d0fSWarner Losh 112d745c852SEd Schouten static MALLOC_DEFINE(CISS_MALLOC_CLASS, "ciss_data", 113d745c852SEd Schouten "ciss internal data buffers"); 1143a31b7ebSMike Smith 1153a31b7ebSMike Smith /* pci interface */ 1163a31b7ebSMike Smith static int ciss_lookup(device_t dev); 1173a31b7ebSMike Smith static int ciss_probe(device_t dev); 1183a31b7ebSMike Smith static int ciss_attach(device_t dev); 1193a31b7ebSMike Smith static int ciss_detach(device_t dev); 1203a31b7ebSMike Smith static int ciss_shutdown(device_t dev); 1213a31b7ebSMike Smith 1223a31b7ebSMike Smith /* (de)initialisation functions, control wrappers */ 1233a31b7ebSMike Smith static int ciss_init_pci(struct ciss_softc *sc); 12422657ce1SScott Long static int ciss_setup_msix(struct ciss_softc *sc); 12522657ce1SScott Long static int ciss_init_perf(struct ciss_softc *sc); 1263a31b7ebSMike Smith static int ciss_wait_adapter(struct ciss_softc *sc); 1273a31b7ebSMike Smith static int ciss_flush_adapter(struct ciss_softc *sc); 1283a31b7ebSMike Smith static int ciss_init_requests(struct ciss_softc *sc); 1293a31b7ebSMike Smith static void ciss_command_map_helper(void *arg, bus_dma_segment_t *segs, 1303a31b7ebSMike Smith int nseg, int error); 1313a31b7ebSMike Smith static int ciss_identify_adapter(struct ciss_softc *sc); 1323a31b7ebSMike Smith static int ciss_init_logical(struct ciss_softc *sc); 133c6131460SPaul Saab static int ciss_init_physical(struct ciss_softc *sc); 1341fe6c4eeSScott Long static int ciss_filter_physical(struct ciss_softc *sc, struct ciss_lun_report *cll); 1353a31b7ebSMike Smith static int ciss_identify_logical(struct ciss_softc *sc, struct ciss_ldrive *ld); 1363a31b7ebSMike Smith static int ciss_get_ldrive_status(struct ciss_softc *sc, struct ciss_ldrive *ld); 1373a31b7ebSMike Smith static int ciss_update_config(struct ciss_softc *sc); 13888c78a38SPaul Saab static int ciss_accept_media(struct ciss_softc *sc, struct ciss_ldrive *ld); 13917c0792dSPaul Saab static void ciss_init_sysctl(struct ciss_softc *sc); 14017c0792dSPaul Saab static void ciss_soft_reset(struct ciss_softc *sc); 1413a31b7ebSMike Smith static void ciss_free(struct ciss_softc *sc); 142c6131460SPaul Saab static void ciss_spawn_notify_thread(struct ciss_softc *sc); 143c6131460SPaul Saab static void ciss_kill_notify_thread(struct ciss_softc *sc); 1443a31b7ebSMike Smith 1453a31b7ebSMike Smith /* request submission/completion */ 1463a31b7ebSMike Smith static int ciss_start(struct ciss_request *cr); 14722657ce1SScott Long static void ciss_done(struct ciss_softc *sc, cr_qhead_t *qh); 14822657ce1SScott Long static void ciss_perf_done(struct ciss_softc *sc, cr_qhead_t *qh); 1493a31b7ebSMike Smith static void ciss_intr(void *arg); 15022657ce1SScott Long static void ciss_perf_intr(void *arg); 15122657ce1SScott Long static void ciss_perf_msi_intr(void *arg); 15222657ce1SScott Long static void ciss_complete(struct ciss_softc *sc, cr_qhead_t *qh); 15322657ce1SScott Long static int _ciss_report_request(struct ciss_request *cr, int *command_status, int *scsi_status, const char *func); 1543a31b7ebSMike Smith static int ciss_synch_request(struct ciss_request *cr, int timeout); 1553a31b7ebSMike Smith static int ciss_poll_request(struct ciss_request *cr, int timeout); 1563a31b7ebSMike Smith static int ciss_wait_request(struct ciss_request *cr, int timeout); 1576197ca15SPeter Wemm #if 0 1583a31b7ebSMike Smith static int ciss_abort_request(struct ciss_request *cr); 1596197ca15SPeter Wemm #endif 1603a31b7ebSMike Smith 1613a31b7ebSMike Smith /* request queueing */ 1623a31b7ebSMike Smith static int ciss_get_request(struct ciss_softc *sc, struct ciss_request **crp); 1633a31b7ebSMike Smith static void ciss_preen_command(struct ciss_request *cr); 1643a31b7ebSMike Smith static void ciss_release_request(struct ciss_request *cr); 1653a31b7ebSMike Smith 1663a31b7ebSMike Smith /* request helpers */ 1673a31b7ebSMike Smith static int ciss_get_bmic_request(struct ciss_softc *sc, struct ciss_request **crp, 1683a31b7ebSMike Smith int opcode, void **bufp, size_t bufsize); 1693a31b7ebSMike Smith static int ciss_user_command(struct ciss_softc *sc, IOCTL_Command_struct *ioc); 1703a31b7ebSMike Smith 1713a31b7ebSMike Smith /* DMA map/unmap */ 1723a31b7ebSMike Smith static int ciss_map_request(struct ciss_request *cr); 1733a31b7ebSMike Smith static void ciss_request_map_helper(void *arg, bus_dma_segment_t *segs, 1743a31b7ebSMike Smith int nseg, int error); 1753a31b7ebSMike Smith static void ciss_unmap_request(struct ciss_request *cr); 1763a31b7ebSMike Smith 1773a31b7ebSMike Smith /* CAM interface */ 1783a31b7ebSMike Smith static int ciss_cam_init(struct ciss_softc *sc); 179c6131460SPaul Saab static void ciss_cam_rescan_target(struct ciss_softc *sc, 180c6131460SPaul Saab int bus, int target); 1813a31b7ebSMike Smith static void ciss_cam_action(struct cam_sim *sim, union ccb *ccb); 1823a31b7ebSMike Smith static int ciss_cam_action_io(struct cam_sim *sim, struct ccb_scsiio *csio); 1833a31b7ebSMike Smith static int ciss_cam_emulate(struct ciss_softc *sc, struct ccb_scsiio *csio); 1843a31b7ebSMike Smith static void ciss_cam_poll(struct cam_sim *sim); 1853a31b7ebSMike Smith static void ciss_cam_complete(struct ciss_request *cr); 1863a31b7ebSMike Smith static void ciss_cam_complete_fixup(struct ciss_softc *sc, struct ccb_scsiio *csio); 187c6131460SPaul Saab static int ciss_name_device(struct ciss_softc *sc, int bus, int target); 1883a31b7ebSMike Smith 1893a31b7ebSMike Smith /* periodic status monitoring */ 1903a31b7ebSMike Smith static void ciss_periodic(void *arg); 19154d02e0aSMitsuru IWASAKI static void ciss_nop_complete(struct ciss_request *cr); 192e08d902aSMitsuru IWASAKI static void ciss_disable_adapter(struct ciss_softc *sc); 1933a31b7ebSMike Smith static void ciss_notify_event(struct ciss_softc *sc); 1943a31b7ebSMike Smith static void ciss_notify_complete(struct ciss_request *cr); 1953a31b7ebSMike Smith static int ciss_notify_abort(struct ciss_softc *sc); 1963a31b7ebSMike Smith static int ciss_notify_abort_bmic(struct ciss_softc *sc); 1971fe6c4eeSScott Long static void ciss_notify_hotplug(struct ciss_softc *sc, struct ciss_notify *cn); 1983a31b7ebSMike Smith static void ciss_notify_logical(struct ciss_softc *sc, struct ciss_notify *cn); 1993a31b7ebSMike Smith static void ciss_notify_physical(struct ciss_softc *sc, struct ciss_notify *cn); 2003a31b7ebSMike Smith 2013a31b7ebSMike Smith /* debugging output */ 2022e3d6d0fSWarner Losh #ifdef DDB 2033a31b7ebSMike Smith static void ciss_print_request(struct ciss_request *cr); 2042e3d6d0fSWarner Losh #endif 2053a31b7ebSMike Smith static void ciss_print_ldrive(struct ciss_softc *sc, struct ciss_ldrive *ld); 2063a31b7ebSMike Smith static const char *ciss_name_ldrive_status(int status); 2073a31b7ebSMike Smith static int ciss_decode_ldrive_status(int status); 2083a31b7ebSMike Smith static const char *ciss_name_ldrive_org(int org); 2093a31b7ebSMike Smith static const char *ciss_name_command_status(int status); 2103a31b7ebSMike Smith 2113a31b7ebSMike Smith /* 2123a31b7ebSMike Smith * PCI bus interface. 2133a31b7ebSMike Smith */ 2143a31b7ebSMike Smith static device_method_t ciss_methods[] = { 2153a31b7ebSMike Smith /* Device interface */ 2163a31b7ebSMike Smith DEVMETHOD(device_probe, ciss_probe), 2173a31b7ebSMike Smith DEVMETHOD(device_attach, ciss_attach), 2183a31b7ebSMike Smith DEVMETHOD(device_detach, ciss_detach), 2193a31b7ebSMike Smith DEVMETHOD(device_shutdown, ciss_shutdown), 2203a31b7ebSMike Smith { 0, 0 } 2213a31b7ebSMike Smith }; 2223a31b7ebSMike Smith 2233a31b7ebSMike Smith static driver_t ciss_pci_driver = { 2243a31b7ebSMike Smith "ciss", 2253a31b7ebSMike Smith ciss_methods, 2263a31b7ebSMike Smith sizeof(struct ciss_softc) 2273a31b7ebSMike Smith }; 2283a31b7ebSMike Smith 2293a31b7ebSMike Smith /* 2303a31b7ebSMike Smith * Control device interface. 2313a31b7ebSMike Smith */ 2323a31b7ebSMike Smith static d_open_t ciss_open; 2333a31b7ebSMike Smith static d_close_t ciss_close; 2343a31b7ebSMike Smith static d_ioctl_t ciss_ioctl; 2353a31b7ebSMike Smith 2363a31b7ebSMike Smith static struct cdevsw ciss_cdevsw = { 237dc08ffecSPoul-Henning Kamp .d_version = D_VERSION, 238975b7318SScott Long .d_flags = 0, 2397ac40f5fSPoul-Henning Kamp .d_open = ciss_open, 2407ac40f5fSPoul-Henning Kamp .d_close = ciss_close, 2417ac40f5fSPoul-Henning Kamp .d_ioctl = ciss_ioctl, 2427ac40f5fSPoul-Henning Kamp .d_name = "ciss", 2433a31b7ebSMike Smith }; 2443a31b7ebSMike Smith 24574575d14SPeter Eriksson SYSCTL_NODE(_hw, OID_AUTO, ciss, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "CISS sysctl tunables"); 24674575d14SPeter Eriksson 24774575d14SPeter Eriksson /* 248*fd95966aSPeter Eriksson * This tunable can be used to force a specific initiator id 249*fd95966aSPeter Eriksson */ 250*fd95966aSPeter Eriksson static int ciss_initiator_id = CAM_TARGET_WILDCARD; 251*fd95966aSPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, initiator_id, CTLFLAG_RDTUN, 252*fd95966aSPeter Eriksson &ciss_initiator_id, 0, 253*fd95966aSPeter Eriksson "force a specific initiator id"); 254*fd95966aSPeter Eriksson 255*fd95966aSPeter Eriksson /* 256*fd95966aSPeter Eriksson * This tunable can be used to force a specific initiator id 25774575d14SPeter Eriksson */ 25874575d14SPeter Eriksson static int ciss_base_transfer_speed = 132 * 1024; 25974575d14SPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, base_transfer_speed, CTLFLAG_RDTUN, 26074575d14SPeter Eriksson &ciss_base_transfer_speed, 0, 26174575d14SPeter Eriksson "force a specific base transfer_speed"); 26274575d14SPeter Eriksson 2631fe6c4eeSScott Long /* 264f373e6b8SPeter Eriksson * This tunable can be set to make the driver be more verbose 265f373e6b8SPeter Eriksson */ 266f373e6b8SPeter Eriksson static int ciss_verbose = 0; 267f373e6b8SPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, verbose, CTLFLAG_RWTUN, &ciss_verbose, 0, 268f373e6b8SPeter Eriksson "enable verbose messages"); 269f373e6b8SPeter Eriksson 270f373e6b8SPeter Eriksson /* 2711fe6c4eeSScott Long * This tunable can be set at boot time and controls whether physical devices 2721fe6c4eeSScott Long * that are marked hidden by the firmware should be exposed anyways. 2731fe6c4eeSScott Long */ 2741fe6c4eeSScott Long static unsigned int ciss_expose_hidden_physical = 0; 2751fe6c4eeSScott Long TUNABLE_INT("hw.ciss.expose_hidden_physical", &ciss_expose_hidden_physical); 276a3556435SPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, expose_hidden_physical, CTLFLAG_RWTUN, 277a3556435SPeter Eriksson &ciss_expose_hidden_physical, 0, 278a3556435SPeter Eriksson "expose hidden physical drives"); 2791fe6c4eeSScott Long 2805a3c4d69SMitsuru IWASAKI static unsigned int ciss_nop_message_heartbeat = 0; 2815a3c4d69SMitsuru IWASAKI TUNABLE_INT("hw.ciss.nop_message_heartbeat", &ciss_nop_message_heartbeat); 282cec58bbaSPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, nop_message_heartbeat, CTLFLAG_RWTUN, 283cec58bbaSPeter Eriksson &ciss_nop_message_heartbeat, 0, 284cec58bbaSPeter Eriksson "nop heartbeat messages"); 2855a3c4d69SMitsuru IWASAKI 28622657ce1SScott Long /* 28722657ce1SScott Long * This tunable can force a particular transport to be used: 28822657ce1SScott Long * <= 0 : use default 28922657ce1SScott Long * 1 : force simple 29022657ce1SScott Long * 2 : force performant 29122657ce1SScott Long */ 29222657ce1SScott Long static int ciss_force_transport = 0; 29322657ce1SScott Long TUNABLE_INT("hw.ciss.force_transport", &ciss_force_transport); 29477af8c6dSPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, force_transport, CTLFLAG_RDTUN, 29577af8c6dSPeter Eriksson &ciss_force_transport, 0, 29677af8c6dSPeter Eriksson "use default (0), force simple (1) or force performant (2) transport"); 29722657ce1SScott Long 29822657ce1SScott Long /* 29922657ce1SScott Long * This tunable can force a particular interrupt delivery method to be used: 30022657ce1SScott Long * <= 0 : use default 30122657ce1SScott Long * 1 : force INTx 30222657ce1SScott Long * 2 : force MSIX 30322657ce1SScott Long */ 30422657ce1SScott Long static int ciss_force_interrupt = 0; 30522657ce1SScott Long TUNABLE_INT("hw.ciss.force_interrupt", &ciss_force_interrupt); 3067c74337eSPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, force_interrupt, CTLFLAG_RDTUN, 3077c74337eSPeter Eriksson &ciss_force_interrupt, 0, 3087c74337eSPeter Eriksson "use default (0), force INTx (1) or force MSIx(2) interrupts"); 30922657ce1SScott Long 3103a31b7ebSMike Smith /************************************************************************ 3113a31b7ebSMike Smith * CISS adapters amazingly don't have a defined programming interface 3123a31b7ebSMike Smith * value. (One could say some very despairing things about PCI and 3133a31b7ebSMike Smith * people just not getting the general idea.) So we are forced to 3143a31b7ebSMike Smith * stick with matching against subvendor/subdevice, and thus have to 3153a31b7ebSMike Smith * be updated for every new CISS adapter that appears. 3163a31b7ebSMike Smith */ 3174e2ddfbaSWarner Losh #define CISS_BOARD_UNKNOWN 0 3182fdaa90dSScott Long #define CISS_BOARD_SA5 1 3192fdaa90dSScott Long #define CISS_BOARD_SA5B 2 3202fdaa90dSScott Long #define CISS_BOARD_NOMSI (1<<4) 321ee4827b2SSean Bruno #define CISS_BOARD_SIMPLE (1<<5) 3223a31b7ebSMike Smith 3233a31b7ebSMike Smith static struct 3243a31b7ebSMike Smith { 3253a31b7ebSMike Smith u_int16_t subvendor; 3263a31b7ebSMike Smith u_int16_t subdevice; 3273a31b7ebSMike Smith int flags; 3283a31b7ebSMike Smith char *desc; 3293a31b7ebSMike Smith } ciss_vendor_data[] = { 330ee4827b2SSean Bruno { 0x0e11, 0x4070, CISS_BOARD_SA5|CISS_BOARD_NOMSI|CISS_BOARD_SIMPLE, 331ee4827b2SSean Bruno "Compaq Smart Array 5300" }, 3322fdaa90dSScott Long { 0x0e11, 0x4080, CISS_BOARD_SA5B|CISS_BOARD_NOMSI, "Compaq Smart Array 5i" }, 3332fdaa90dSScott Long { 0x0e11, 0x4082, CISS_BOARD_SA5B|CISS_BOARD_NOMSI, "Compaq Smart Array 532" }, 3342fdaa90dSScott Long { 0x0e11, 0x4083, CISS_BOARD_SA5B|CISS_BOARD_NOMSI, "HP Smart Array 5312" }, 335b26392c7SPaul Saab { 0x0e11, 0x4091, CISS_BOARD_SA5, "HP Smart Array 6i" }, 3369e7313bbSPaul Saab { 0x0e11, 0x409A, CISS_BOARD_SA5, "HP Smart Array 641" }, 3379e7313bbSPaul Saab { 0x0e11, 0x409B, CISS_BOARD_SA5, "HP Smart Array 642" }, 3389e7313bbSPaul Saab { 0x0e11, 0x409C, CISS_BOARD_SA5, "HP Smart Array 6400" }, 3399e7313bbSPaul Saab { 0x0e11, 0x409D, CISS_BOARD_SA5, "HP Smart Array 6400 EM" }, 340cad572c4SPaul Saab { 0x103C, 0x3211, CISS_BOARD_SA5, "HP Smart Array E200i" }, 341cad572c4SPaul Saab { 0x103C, 0x3212, CISS_BOARD_SA5, "HP Smart Array E200" }, 342cad572c4SPaul Saab { 0x103C, 0x3213, CISS_BOARD_SA5, "HP Smart Array E200i" }, 343cad572c4SPaul Saab { 0x103C, 0x3214, CISS_BOARD_SA5, "HP Smart Array E200i" }, 344cad572c4SPaul Saab { 0x103C, 0x3215, CISS_BOARD_SA5, "HP Smart Array E200i" }, 345b612d5e1SPaul Saab { 0x103C, 0x3220, CISS_BOARD_SA5, "HP Smart Array" }, 346b612d5e1SPaul Saab { 0x103C, 0x3222, CISS_BOARD_SA5, "HP Smart Array" }, 3474bb10cf1SPaul Saab { 0x103C, 0x3223, CISS_BOARD_SA5, "HP Smart Array P800" }, 348f3f82767SPaul Saab { 0x103C, 0x3225, CISS_BOARD_SA5, "HP Smart Array P600" }, 349b612d5e1SPaul Saab { 0x103C, 0x3230, CISS_BOARD_SA5, "HP Smart Array" }, 350cad572c4SPaul Saab { 0x103C, 0x3231, CISS_BOARD_SA5, "HP Smart Array" }, 351b612d5e1SPaul Saab { 0x103C, 0x3232, CISS_BOARD_SA5, "HP Smart Array" }, 352b612d5e1SPaul Saab { 0x103C, 0x3233, CISS_BOARD_SA5, "HP Smart Array" }, 353cad572c4SPaul Saab { 0x103C, 0x3234, CISS_BOARD_SA5, "HP Smart Array P400" }, 354cad572c4SPaul Saab { 0x103C, 0x3235, CISS_BOARD_SA5, "HP Smart Array P400i" }, 355b612d5e1SPaul Saab { 0x103C, 0x3236, CISS_BOARD_SA5, "HP Smart Array" }, 3567b6d3d4cSScott Long { 0x103C, 0x3237, CISS_BOARD_SA5, "HP Smart Array E500" }, 357b612d5e1SPaul Saab { 0x103C, 0x3238, CISS_BOARD_SA5, "HP Smart Array" }, 358b612d5e1SPaul Saab { 0x103C, 0x3239, CISS_BOARD_SA5, "HP Smart Array" }, 359b612d5e1SPaul Saab { 0x103C, 0x323A, CISS_BOARD_SA5, "HP Smart Array" }, 360b612d5e1SPaul Saab { 0x103C, 0x323B, CISS_BOARD_SA5, "HP Smart Array" }, 361b612d5e1SPaul Saab { 0x103C, 0x323C, CISS_BOARD_SA5, "HP Smart Array" }, 3627b6d3d4cSScott Long { 0x103C, 0x323D, CISS_BOARD_SA5, "HP Smart Array P700m" }, 363160b4e6bSPaul Saab { 0x103C, 0x3241, CISS_BOARD_SA5, "HP Smart Array P212" }, 364160b4e6bSPaul Saab { 0x103C, 0x3243, CISS_BOARD_SA5, "HP Smart Array P410" }, 365160b4e6bSPaul Saab { 0x103C, 0x3245, CISS_BOARD_SA5, "HP Smart Array P410i" }, 366160b4e6bSPaul Saab { 0x103C, 0x3247, CISS_BOARD_SA5, "HP Smart Array P411" }, 367160b4e6bSPaul Saab { 0x103C, 0x3249, CISS_BOARD_SA5, "HP Smart Array P812" }, 3687b6d3d4cSScott Long { 0x103C, 0x324A, CISS_BOARD_SA5, "HP Smart Array P712m" }, 3697b6d3d4cSScott Long { 0x103C, 0x324B, CISS_BOARD_SA5, "HP Smart Array" }, 370e17ef005SSean Bruno { 0x103C, 0x3350, CISS_BOARD_SA5, "HP Smart Array P222" }, 3715564c1cdSSean Bruno { 0x103C, 0x3351, CISS_BOARD_SA5, "HP Smart Array P420" }, 372e17ef005SSean Bruno { 0x103C, 0x3352, CISS_BOARD_SA5, "HP Smart Array P421" }, 373e17ef005SSean Bruno { 0x103C, 0x3353, CISS_BOARD_SA5, "HP Smart Array P822" }, 374e17ef005SSean Bruno { 0x103C, 0x3354, CISS_BOARD_SA5, "HP Smart Array P420i" }, 375e17ef005SSean Bruno { 0x103C, 0x3355, CISS_BOARD_SA5, "HP Smart Array P220i" }, 376e17ef005SSean Bruno { 0x103C, 0x3356, CISS_BOARD_SA5, "HP Smart Array P721m" }, 377ec5d9810SSean Bruno { 0x103C, 0x1920, CISS_BOARD_SA5, "HP Smart Array P430i" }, 378ec5d9810SSean Bruno { 0x103C, 0x1921, CISS_BOARD_SA5, "HP Smart Array P830i" }, 379ec5d9810SSean Bruno { 0x103C, 0x1922, CISS_BOARD_SA5, "HP Smart Array P430" }, 380ec5d9810SSean Bruno { 0x103C, 0x1923, CISS_BOARD_SA5, "HP Smart Array P431" }, 381ec5d9810SSean Bruno { 0x103C, 0x1924, CISS_BOARD_SA5, "HP Smart Array P830" }, 382ec5d9810SSean Bruno { 0x103C, 0x1926, CISS_BOARD_SA5, "HP Smart Array P731m" }, 383ec5d9810SSean Bruno { 0x103C, 0x1928, CISS_BOARD_SA5, "HP Smart Array P230i" }, 384ec5d9810SSean Bruno { 0x103C, 0x1929, CISS_BOARD_SA5, "HP Smart Array P530" }, 385ec5d9810SSean Bruno { 0x103C, 0x192A, CISS_BOARD_SA5, "HP Smart Array P531" }, 386bf10f1a0SSean Bruno { 0x103C, 0x21BD, CISS_BOARD_SA5, "HP Smart Array P244br" }, 387bf10f1a0SSean Bruno { 0x103C, 0x21BE, CISS_BOARD_SA5, "HP Smart Array P741m" }, 388bf10f1a0SSean Bruno { 0x103C, 0x21BF, CISS_BOARD_SA5, "HP Smart Array H240ar" }, 389bf10f1a0SSean Bruno { 0x103C, 0x21C0, CISS_BOARD_SA5, "HP Smart Array P440ar" }, 390bf10f1a0SSean Bruno { 0x103C, 0x21C1, CISS_BOARD_SA5, "HP Smart Array P840ar" }, 391bf10f1a0SSean Bruno { 0x103C, 0x21C2, CISS_BOARD_SA5, "HP Smart Array P440" }, 392bf10f1a0SSean Bruno { 0x103C, 0x21C3, CISS_BOARD_SA5, "HP Smart Array P441" }, 393bf10f1a0SSean Bruno { 0x103C, 0x21C5, CISS_BOARD_SA5, "HP Smart Array P841" }, 394bf10f1a0SSean Bruno { 0x103C, 0x21C6, CISS_BOARD_SA5, "HP Smart Array H244br" }, 395bf10f1a0SSean Bruno { 0x103C, 0x21C7, CISS_BOARD_SA5, "HP Smart Array H240" }, 396bf10f1a0SSean Bruno { 0x103C, 0x21C8, CISS_BOARD_SA5, "HP Smart Array H241" }, 397bf10f1a0SSean Bruno { 0x103C, 0x21CA, CISS_BOARD_SA5, "HP Smart Array P246br" }, 398bf10f1a0SSean Bruno { 0x103C, 0x21CB, CISS_BOARD_SA5, "HP Smart Array P840" }, 399d3d9a343SScott Long { 0x103C, 0x21CC, CISS_BOARD_SA5, "HP Smart Array P542d" }, 400bf10f1a0SSean Bruno { 0x103C, 0x21CD, CISS_BOARD_SA5, "HP Smart Array P240nr" }, 401bf10f1a0SSean Bruno { 0x103C, 0x21CE, CISS_BOARD_SA5, "HP Smart Array H240nr" }, 4024a6a94d8SArchie Cobbs { 0, 0, 0, NULL } 4033a31b7ebSMike Smith }; 4043a31b7ebSMike Smith 4056b66c298SJohn Baldwin DRIVER_MODULE(ciss, pci, ciss_pci_driver, 0, 0); 4064322d107SWarner Losh MODULE_PNP_INFO("U16:vendor;U16:device;", pci, ciss, ciss_vendor_data, 407329e817fSWarner Losh nitems(ciss_vendor_data) - 1); 4084322d107SWarner Losh MODULE_DEPEND(ciss, cam, 1, 1, 1); 4094322d107SWarner Losh MODULE_DEPEND(ciss, pci, 1, 1, 1); 4104322d107SWarner Losh 4113a31b7ebSMike Smith /************************************************************************ 4123a31b7ebSMike Smith * Find a match for the device in our list of known adapters. 4133a31b7ebSMike Smith */ 4143a31b7ebSMike Smith static int 4153a31b7ebSMike Smith ciss_lookup(device_t dev) 4163a31b7ebSMike Smith { 4173a31b7ebSMike Smith int i; 4183a31b7ebSMike Smith 4193a31b7ebSMike Smith for (i = 0; ciss_vendor_data[i].desc != NULL; i++) 4203a31b7ebSMike Smith if ((pci_get_subvendor(dev) == ciss_vendor_data[i].subvendor) && 4213a31b7ebSMike Smith (pci_get_subdevice(dev) == ciss_vendor_data[i].subdevice)) { 4223a31b7ebSMike Smith return(i); 4233a31b7ebSMike Smith } 4243a31b7ebSMike Smith return(-1); 4253a31b7ebSMike Smith } 4263a31b7ebSMike Smith 4273a31b7ebSMike Smith /************************************************************************ 4283a31b7ebSMike Smith * Match a known CISS adapter. 4293a31b7ebSMike Smith */ 4303a31b7ebSMike Smith static int 4313a31b7ebSMike Smith ciss_probe(device_t dev) 4323a31b7ebSMike Smith { 4333a31b7ebSMike Smith int i; 4343a31b7ebSMike Smith 4353a31b7ebSMike Smith i = ciss_lookup(dev); 4363a31b7ebSMike Smith if (i != -1) { 4373a31b7ebSMike Smith device_set_desc(dev, ciss_vendor_data[i].desc); 438538565c4SWarner Losh return(BUS_PROBE_DEFAULT); 4393a31b7ebSMike Smith } 4403a31b7ebSMike Smith return(ENOENT); 4413a31b7ebSMike Smith } 4423a31b7ebSMike Smith 4433a31b7ebSMike Smith /************************************************************************ 4443a31b7ebSMike Smith * Attach the driver to this adapter. 4453a31b7ebSMike Smith */ 4463a31b7ebSMike Smith static int 4473a31b7ebSMike Smith ciss_attach(device_t dev) 4483a31b7ebSMike Smith { 4493a31b7ebSMike Smith struct ciss_softc *sc; 450d69c9c78SScott Long int error; 4513a31b7ebSMike Smith 4523a31b7ebSMike Smith debug_called(1); 4533a31b7ebSMike Smith 4543a31b7ebSMike Smith #ifdef CISS_DEBUG 4553a31b7ebSMike Smith /* print structure/union sizes */ 4563a31b7ebSMike Smith debug_struct(ciss_command); 4573a31b7ebSMike Smith debug_struct(ciss_header); 4583a31b7ebSMike Smith debug_union(ciss_device_address); 4593a31b7ebSMike Smith debug_struct(ciss_cdb); 4603a31b7ebSMike Smith debug_struct(ciss_report_cdb); 4613a31b7ebSMike Smith debug_struct(ciss_notify_cdb); 4623a31b7ebSMike Smith debug_struct(ciss_notify); 4633a31b7ebSMike Smith debug_struct(ciss_message_cdb); 4643a31b7ebSMike Smith debug_struct(ciss_error_info_pointer); 4653a31b7ebSMike Smith debug_struct(ciss_error_info); 4663a31b7ebSMike Smith debug_struct(ciss_sg_entry); 4673a31b7ebSMike Smith debug_struct(ciss_config_table); 4683a31b7ebSMike Smith debug_struct(ciss_bmic_cdb); 4693a31b7ebSMike Smith debug_struct(ciss_bmic_id_ldrive); 4703a31b7ebSMike Smith debug_struct(ciss_bmic_id_lstatus); 4713a31b7ebSMike Smith debug_struct(ciss_bmic_id_table); 4723a31b7ebSMike Smith debug_struct(ciss_bmic_id_pdrive); 4733a31b7ebSMike Smith debug_struct(ciss_bmic_blink_pdrive); 4743a31b7ebSMike Smith debug_struct(ciss_bmic_flush_cache); 4753a31b7ebSMike Smith debug_const(CISS_MAX_REQUESTS); 4763a31b7ebSMike Smith debug_const(CISS_MAX_LOGICAL); 4773a31b7ebSMike Smith debug_const(CISS_INTERRUPT_COALESCE_DELAY); 4783a31b7ebSMike Smith debug_const(CISS_INTERRUPT_COALESCE_COUNT); 4793a31b7ebSMike Smith debug_const(CISS_COMMAND_ALLOC_SIZE); 4803a31b7ebSMike Smith debug_const(CISS_COMMAND_SG_LENGTH); 4813a31b7ebSMike Smith 4823a31b7ebSMike Smith debug_type(cciss_pci_info_struct); 4833a31b7ebSMike Smith debug_type(cciss_coalint_struct); 4843a31b7ebSMike Smith debug_type(cciss_coalint_struct); 4853a31b7ebSMike Smith debug_type(NodeName_type); 4863a31b7ebSMike Smith debug_type(NodeName_type); 4873a31b7ebSMike Smith debug_type(Heartbeat_type); 4883a31b7ebSMike Smith debug_type(BusTypes_type); 4893a31b7ebSMike Smith debug_type(FirmwareVer_type); 4903a31b7ebSMike Smith debug_type(DriverVer_type); 4913a31b7ebSMike Smith debug_type(IOCTL_Command_struct); 4923a31b7ebSMike Smith #endif 4933a31b7ebSMike Smith 4943a31b7ebSMike Smith sc = device_get_softc(dev); 4953a31b7ebSMike Smith sc->ciss_dev = dev; 49664a026bdSGavin Atkinson mtx_init(&sc->ciss_mtx, "cissmtx", NULL, MTX_DEF); 497aa1385cdSJohn Baldwin callout_init_mtx(&sc->ciss_periodic, &sc->ciss_mtx, 0); 4983a31b7ebSMike Smith 4993a31b7ebSMike Smith /* 5003a31b7ebSMike Smith * Do PCI-specific init. 5013a31b7ebSMike Smith */ 5023a31b7ebSMike Smith if ((error = ciss_init_pci(sc)) != 0) 5033a31b7ebSMike Smith goto out; 5043a31b7ebSMike Smith 5053a31b7ebSMike Smith /* 5063a31b7ebSMike Smith * Initialise driver queues. 5073a31b7ebSMike Smith */ 5083a31b7ebSMike Smith ciss_initq_free(sc); 509c6131460SPaul Saab ciss_initq_notify(sc); 5103a31b7ebSMike Smith 5113a31b7ebSMike Smith /* 512b790c193SPedro F. Giffuni * Initialize device sysctls. 51317c0792dSPaul Saab */ 51417c0792dSPaul Saab ciss_init_sysctl(sc); 51517c0792dSPaul Saab 51617c0792dSPaul Saab /* 5173a31b7ebSMike Smith * Initialise command/request pool. 5183a31b7ebSMike Smith */ 5193a31b7ebSMike Smith if ((error = ciss_init_requests(sc)) != 0) 5203a31b7ebSMike Smith goto out; 5213a31b7ebSMike Smith 5223a31b7ebSMike Smith /* 5233a31b7ebSMike Smith * Get adapter information. 5243a31b7ebSMike Smith */ 5253a31b7ebSMike Smith if ((error = ciss_identify_adapter(sc)) != 0) 5263a31b7ebSMike Smith goto out; 5273a31b7ebSMike Smith 5283a31b7ebSMike Smith /* 529c6131460SPaul Saab * Find all the physical devices. 530c6131460SPaul Saab */ 531c6131460SPaul Saab if ((error = ciss_init_physical(sc)) != 0) 532c6131460SPaul Saab goto out; 533c6131460SPaul Saab 534c6131460SPaul Saab /* 5353a31b7ebSMike Smith * Build our private table of logical devices. 5363a31b7ebSMike Smith */ 5373a31b7ebSMike Smith if ((error = ciss_init_logical(sc)) != 0) 5383a31b7ebSMike Smith goto out; 5393a31b7ebSMike Smith 5403a31b7ebSMike Smith /* 5413a31b7ebSMike Smith * Enable interrupts so that the CAM scan can complete. 5423a31b7ebSMike Smith */ 5433a31b7ebSMike Smith CISS_TL_SIMPLE_ENABLE_INTERRUPTS(sc); 5443a31b7ebSMike Smith 5453a31b7ebSMike Smith /* 5463a31b7ebSMike Smith * Initialise the CAM interface. 5473a31b7ebSMike Smith */ 5483a31b7ebSMike Smith if ((error = ciss_cam_init(sc)) != 0) 5493a31b7ebSMike Smith goto out; 5503a31b7ebSMike Smith 5513a31b7ebSMike Smith /* 5523a31b7ebSMike Smith * Start the heartbeat routine and event chain. 5533a31b7ebSMike Smith */ 5543a31b7ebSMike Smith ciss_periodic(sc); 5553a31b7ebSMike Smith 5563a31b7ebSMike Smith /* 5573a31b7ebSMike Smith * Create the control device. 5583a31b7ebSMike Smith */ 5593a31b7ebSMike Smith sc->ciss_dev_t = make_dev(&ciss_cdevsw, device_get_unit(sc->ciss_dev), 5603a31b7ebSMike Smith UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, 5613a31b7ebSMike Smith "ciss%d", device_get_unit(sc->ciss_dev)); 5623a31b7ebSMike Smith sc->ciss_dev_t->si_drv1 = sc; 5633a31b7ebSMike Smith 5643a31b7ebSMike Smith /* 5653a31b7ebSMike Smith * The adapter is running; synchronous commands can now sleep 5663a31b7ebSMike Smith * waiting for an interrupt to signal completion. 5673a31b7ebSMike Smith */ 5683a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_RUNNING; 5693a31b7ebSMike Smith 570c6131460SPaul Saab ciss_spawn_notify_thread(sc); 571c6131460SPaul Saab 5723a31b7ebSMike Smith error = 0; 5733a31b7ebSMike Smith out: 57464a026bdSGavin Atkinson if (error != 0) { 57564a026bdSGavin Atkinson /* ciss_free() expects the mutex to be held */ 57664a026bdSGavin Atkinson mtx_lock(&sc->ciss_mtx); 5773a31b7ebSMike Smith ciss_free(sc); 57864a026bdSGavin Atkinson } 5793a31b7ebSMike Smith return(error); 5803a31b7ebSMike Smith } 5813a31b7ebSMike Smith 5823a31b7ebSMike Smith /************************************************************************ 5833a31b7ebSMike Smith * Detach the driver from this adapter. 5843a31b7ebSMike Smith */ 5853a31b7ebSMike Smith static int 5863a31b7ebSMike Smith ciss_detach(device_t dev) 5873a31b7ebSMike Smith { 5883a31b7ebSMike Smith struct ciss_softc *sc = device_get_softc(dev); 5893a31b7ebSMike Smith 5903a31b7ebSMike Smith debug_called(1); 5913a31b7ebSMike Smith 592975b7318SScott Long mtx_lock(&sc->ciss_mtx); 593975b7318SScott Long if (sc->ciss_flags & CISS_FLAG_CONTROL_OPEN) { 594975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 595ffdf82e1SPaul Saab return (EBUSY); 596975b7318SScott Long } 597ffdf82e1SPaul Saab 5983a31b7ebSMike Smith /* flush adapter cache */ 5993a31b7ebSMike Smith ciss_flush_adapter(sc); 6003a31b7ebSMike Smith 601975b7318SScott Long /* release all resources. The mutex is released and freed here too. */ 6023a31b7ebSMike Smith ciss_free(sc); 6033a31b7ebSMike Smith 6043a31b7ebSMike Smith return(0); 6053a31b7ebSMike Smith } 6063a31b7ebSMike Smith 6073a31b7ebSMike Smith /************************************************************************ 6083a31b7ebSMike Smith * Prepare adapter for system shutdown. 6093a31b7ebSMike Smith */ 6103a31b7ebSMike Smith static int 6113a31b7ebSMike Smith ciss_shutdown(device_t dev) 6123a31b7ebSMike Smith { 6133a31b7ebSMike Smith struct ciss_softc *sc = device_get_softc(dev); 6143a31b7ebSMike Smith 6153a31b7ebSMike Smith debug_called(1); 6163a31b7ebSMike Smith 617d4a4ddc6SScott Long mtx_lock(&sc->ciss_mtx); 6183a31b7ebSMike Smith /* flush adapter cache */ 6193a31b7ebSMike Smith ciss_flush_adapter(sc); 6203a31b7ebSMike Smith 62117c0792dSPaul Saab if (sc->ciss_soft_reset) 62217c0792dSPaul Saab ciss_soft_reset(sc); 623d4a4ddc6SScott Long mtx_unlock(&sc->ciss_mtx); 62417c0792dSPaul Saab 6253a31b7ebSMike Smith return(0); 6263a31b7ebSMike Smith } 6273a31b7ebSMike Smith 62817c0792dSPaul Saab static void 62917c0792dSPaul Saab ciss_init_sysctl(struct ciss_softc *sc) 63017c0792dSPaul Saab { 63117c0792dSPaul Saab 63217c0792dSPaul Saab SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->ciss_dev), 63317c0792dSPaul Saab SYSCTL_CHILDREN(device_get_sysctl_tree(sc->ciss_dev)), 63417c0792dSPaul Saab OID_AUTO, "soft_reset", CTLFLAG_RW, &sc->ciss_soft_reset, 0, ""); 63517c0792dSPaul Saab } 63617c0792dSPaul Saab 6373a31b7ebSMike Smith /************************************************************************ 6383a31b7ebSMike Smith * Perform PCI-specific attachment actions. 6393a31b7ebSMike Smith */ 6403a31b7ebSMike Smith static int 6413a31b7ebSMike Smith ciss_init_pci(struct ciss_softc *sc) 6423a31b7ebSMike Smith { 6433a31b7ebSMike Smith uintptr_t cbase, csize, cofs; 64422657ce1SScott Long uint32_t method, supported_methods; 645d69c9c78SScott Long int error, sqmask, i; 64622657ce1SScott Long void *intr; 6473a31b7ebSMike Smith 6483a31b7ebSMike Smith debug_called(1); 6493a31b7ebSMike Smith 6503a31b7ebSMike Smith /* 651d69c9c78SScott Long * Work out adapter type. 652d69c9c78SScott Long */ 653d69c9c78SScott Long i = ciss_lookup(sc->ciss_dev); 654d69c9c78SScott Long if (i < 0) { 655d69c9c78SScott Long ciss_printf(sc, "unknown adapter type\n"); 656d69c9c78SScott Long return (ENXIO); 657d69c9c78SScott Long } 658d69c9c78SScott Long 659d69c9c78SScott Long if (ciss_vendor_data[i].flags & CISS_BOARD_SA5) { 660d69c9c78SScott Long sqmask = CISS_TL_SIMPLE_INTR_OPQ_SA5; 661d69c9c78SScott Long } else if (ciss_vendor_data[i].flags & CISS_BOARD_SA5B) { 662d69c9c78SScott Long sqmask = CISS_TL_SIMPLE_INTR_OPQ_SA5B; 663d69c9c78SScott Long } else { 664d69c9c78SScott Long /* 665d69c9c78SScott Long * XXX Big hammer, masks/unmasks all possible interrupts. This should 666d69c9c78SScott Long * work on all hardware variants. Need to add code to handle the 667b790c193SPedro F. Giffuni * "controller crashed" interrupt bit that this unmasks. 668d69c9c78SScott Long */ 669d69c9c78SScott Long sqmask = ~0; 670d69c9c78SScott Long } 671d69c9c78SScott Long 672d69c9c78SScott Long /* 6733a31b7ebSMike Smith * Allocate register window first (we need this to find the config 6743a31b7ebSMike Smith * struct). 6753a31b7ebSMike Smith */ 6763a31b7ebSMike Smith error = ENXIO; 6773a31b7ebSMike Smith sc->ciss_regs_rid = CISS_TL_SIMPLE_BAR_REGS; 6783a31b7ebSMike Smith if ((sc->ciss_regs_resource = 6795f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, 6805f96beb9SNate Lawson &sc->ciss_regs_rid, RF_ACTIVE)) == NULL) { 6813a31b7ebSMike Smith ciss_printf(sc, "can't allocate register window\n"); 6823a31b7ebSMike Smith return(ENXIO); 6833a31b7ebSMike Smith } 6843a31b7ebSMike Smith sc->ciss_regs_bhandle = rman_get_bushandle(sc->ciss_regs_resource); 6853a31b7ebSMike Smith sc->ciss_regs_btag = rman_get_bustag(sc->ciss_regs_resource); 6863a31b7ebSMike Smith 6873a31b7ebSMike Smith /* 6883a31b7ebSMike Smith * Find the BAR holding the config structure. If it's not the one 6893a31b7ebSMike Smith * we already mapped for registers, map it too. 6903a31b7ebSMike Smith */ 6913a31b7ebSMike Smith sc->ciss_cfg_rid = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_BAR) & 0xffff; 6923a31b7ebSMike Smith if (sc->ciss_cfg_rid != sc->ciss_regs_rid) { 6933a31b7ebSMike Smith if ((sc->ciss_cfg_resource = 6945f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, 6955f96beb9SNate Lawson &sc->ciss_cfg_rid, RF_ACTIVE)) == NULL) { 6963a31b7ebSMike Smith ciss_printf(sc, "can't allocate config window\n"); 6973a31b7ebSMike Smith return(ENXIO); 6983a31b7ebSMike Smith } 6993a31b7ebSMike Smith cbase = (uintptr_t)rman_get_virtual(sc->ciss_cfg_resource); 7003a31b7ebSMike Smith csize = rman_get_end(sc->ciss_cfg_resource) - 7013a31b7ebSMike Smith rman_get_start(sc->ciss_cfg_resource) + 1; 7023a31b7ebSMike Smith } else { 7033a31b7ebSMike Smith cbase = (uintptr_t)rman_get_virtual(sc->ciss_regs_resource); 7043a31b7ebSMike Smith csize = rman_get_end(sc->ciss_regs_resource) - 7053a31b7ebSMike Smith rman_get_start(sc->ciss_regs_resource) + 1; 7063a31b7ebSMike Smith } 7073a31b7ebSMike Smith cofs = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_OFF); 7083a31b7ebSMike Smith 7093a31b7ebSMike Smith /* 7103a31b7ebSMike Smith * Use the base/size/offset values we just calculated to 7113a31b7ebSMike Smith * sanity-check the config structure. If it's OK, point to it. 7123a31b7ebSMike Smith */ 7133a31b7ebSMike Smith if ((cofs + sizeof(struct ciss_config_table)) > csize) { 7143a31b7ebSMike Smith ciss_printf(sc, "config table outside window\n"); 7153a31b7ebSMike Smith return(ENXIO); 7163a31b7ebSMike Smith } 7173a31b7ebSMike Smith sc->ciss_cfg = (struct ciss_config_table *)(cbase + cofs); 7183a31b7ebSMike Smith debug(1, "config struct at %p", sc->ciss_cfg); 7193a31b7ebSMike Smith 7203a31b7ebSMike Smith /* 72122657ce1SScott Long * Calculate the number of request structures/commands we are 72222657ce1SScott Long * going to provide for this adapter. 72322657ce1SScott Long */ 72422657ce1SScott Long sc->ciss_max_requests = min(CISS_MAX_REQUESTS, sc->ciss_cfg->max_outstanding_commands); 72522657ce1SScott Long 72622657ce1SScott Long /* 7273a31b7ebSMike Smith * Validate the config structure. If we supported other transport 7283a31b7ebSMike Smith * methods, we could select amongst them at this point in time. 7293a31b7ebSMike Smith */ 7303a31b7ebSMike Smith if (strncmp(sc->ciss_cfg->signature, "CISS", 4)) { 7313a31b7ebSMike Smith ciss_printf(sc, "config signature mismatch (got '%c%c%c%c')\n", 7323a31b7ebSMike Smith sc->ciss_cfg->signature[0], sc->ciss_cfg->signature[1], 7333a31b7ebSMike Smith sc->ciss_cfg->signature[2], sc->ciss_cfg->signature[3]); 7343a31b7ebSMike Smith return(ENXIO); 7353a31b7ebSMike Smith } 7363a31b7ebSMike Smith 7373a31b7ebSMike Smith /* 73822657ce1SScott Long * Select the mode of operation, prefer Performant. 7393a31b7ebSMike Smith */ 74022657ce1SScott Long if (!(sc->ciss_cfg->supported_methods & 74122657ce1SScott Long (CISS_TRANSPORT_METHOD_SIMPLE | CISS_TRANSPORT_METHOD_PERF))) { 74222657ce1SScott Long ciss_printf(sc, "No supported transport layers: 0x%x\n", 74322657ce1SScott Long sc->ciss_cfg->supported_methods); 7443a31b7ebSMike Smith } 74522657ce1SScott Long 74622657ce1SScott Long switch (ciss_force_transport) { 74722657ce1SScott Long case 1: 74822657ce1SScott Long supported_methods = CISS_TRANSPORT_METHOD_SIMPLE; 74922657ce1SScott Long break; 75022657ce1SScott Long case 2: 75122657ce1SScott Long supported_methods = CISS_TRANSPORT_METHOD_PERF; 75222657ce1SScott Long break; 75322657ce1SScott Long default: 754ee4827b2SSean Bruno /* 755ee4827b2SSean Bruno * Override the capabilities of the BOARD and specify SIMPLE 756ee4827b2SSean Bruno * MODE 757ee4827b2SSean Bruno */ 758ee4827b2SSean Bruno if (ciss_vendor_data[i].flags & CISS_BOARD_SIMPLE) 759ee4827b2SSean Bruno supported_methods = CISS_TRANSPORT_METHOD_SIMPLE; 760ee4827b2SSean Bruno else 76122657ce1SScott Long supported_methods = sc->ciss_cfg->supported_methods; 76222657ce1SScott Long break; 76322657ce1SScott Long } 76422657ce1SScott Long 76522657ce1SScott Long setup: 7662fdaa90dSScott Long if ((supported_methods & CISS_TRANSPORT_METHOD_PERF) != 0) { 76722657ce1SScott Long method = CISS_TRANSPORT_METHOD_PERF; 76822657ce1SScott Long sc->ciss_perf = (struct ciss_perf_config *)(cbase + cofs + 76922657ce1SScott Long sc->ciss_cfg->transport_offset); 77022657ce1SScott Long if (ciss_init_perf(sc)) { 77122657ce1SScott Long supported_methods &= ~method; 77222657ce1SScott Long goto setup; 77322657ce1SScott Long } 77422657ce1SScott Long } else if (supported_methods & CISS_TRANSPORT_METHOD_SIMPLE) { 77522657ce1SScott Long method = CISS_TRANSPORT_METHOD_SIMPLE; 77622657ce1SScott Long } else { 77722657ce1SScott Long ciss_printf(sc, "No supported transport methods: 0x%x\n", 77822657ce1SScott Long sc->ciss_cfg->supported_methods); 77922657ce1SScott Long return(ENXIO); 78022657ce1SScott Long } 78122657ce1SScott Long 78222657ce1SScott Long /* 78322657ce1SScott Long * Tell it we're using the low 4GB of RAM. Set the default interrupt 78422657ce1SScott Long * coalescing options. 78522657ce1SScott Long */ 78622657ce1SScott Long sc->ciss_cfg->requested_method = method; 7873a31b7ebSMike Smith sc->ciss_cfg->command_physlimit = 0; 7883a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay = CISS_INTERRUPT_COALESCE_DELAY; 7893a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count = CISS_INTERRUPT_COALESCE_COUNT; 7903a31b7ebSMike Smith 791a891a3bfSPaul Saab #ifdef __i386__ 792a891a3bfSPaul Saab sc->ciss_cfg->host_driver |= CISS_DRIVER_SCSI_PREFETCH; 793a891a3bfSPaul Saab #endif 794a891a3bfSPaul Saab 7953a31b7ebSMike Smith if (ciss_update_config(sc)) { 7963a31b7ebSMike Smith ciss_printf(sc, "adapter refuses to accept config update (IDBR 0x%x)\n", 7973a31b7ebSMike Smith CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IDBR)); 7983a31b7ebSMike Smith return(ENXIO); 7993a31b7ebSMike Smith } 80022657ce1SScott Long if ((sc->ciss_cfg->active_method & method) == 0) { 80122657ce1SScott Long supported_methods &= ~method; 80222657ce1SScott Long if (supported_methods == 0) { 80322657ce1SScott Long ciss_printf(sc, "adapter refuses to go into available transports " 80422657ce1SScott Long "mode (0x%x, 0x%x)\n", supported_methods, 80522657ce1SScott Long sc->ciss_cfg->active_method); 8063a31b7ebSMike Smith return(ENXIO); 80722657ce1SScott Long } else 80822657ce1SScott Long goto setup; 8093a31b7ebSMike Smith } 8103a31b7ebSMike Smith 8113a31b7ebSMike Smith /* 8123a31b7ebSMike Smith * Wait for the adapter to come ready. 8133a31b7ebSMike Smith */ 8143a31b7ebSMike Smith if ((error = ciss_wait_adapter(sc)) != 0) 8153a31b7ebSMike Smith return(error); 8163a31b7ebSMike Smith 81722657ce1SScott Long /* Prepare to possibly use MSIX and/or PERFORMANT interrupts. Normal 81822657ce1SScott Long * interrupts have a rid of 0, this will be overridden if MSIX is used. 81922657ce1SScott Long */ 82022657ce1SScott Long sc->ciss_irq_rid[0] = 0; 82122657ce1SScott Long if (method == CISS_TRANSPORT_METHOD_PERF) { 82222657ce1SScott Long ciss_printf(sc, "PERFORMANT Transport\n"); 823d69c9c78SScott Long if ((ciss_force_interrupt != 1) && (ciss_setup_msix(sc) == 0)) { 82422657ce1SScott Long intr = ciss_perf_msi_intr; 825d69c9c78SScott Long } else { 82622657ce1SScott Long intr = ciss_perf_intr; 827d69c9c78SScott Long } 828b23be3e0SScott Long /* XXX The docs say that the 0x01 bit is only for SAS controllers. 829b23be3e0SScott Long * Unfortunately, there is no good way to know if this is a SAS 830b23be3e0SScott Long * controller. Hopefully enabling this bit universally will work OK. 831b23be3e0SScott Long * It seems to work fine for SA6i controllers. 832b23be3e0SScott Long */ 833b23be3e0SScott Long sc->ciss_interrupt_mask = CISS_TL_PERF_INTR_OPQ | CISS_TL_PERF_INTR_MSI; 834b23be3e0SScott Long 83522657ce1SScott Long } else { 83622657ce1SScott Long ciss_printf(sc, "SIMPLE Transport\n"); 83722657ce1SScott Long /* MSIX doesn't seem to work in SIMPLE mode, only enable if it forced */ 83822657ce1SScott Long if (ciss_force_interrupt == 2) 83922657ce1SScott Long /* If this fails, we automatically revert to INTx */ 84022657ce1SScott Long ciss_setup_msix(sc); 84122657ce1SScott Long sc->ciss_perf = NULL; 84222657ce1SScott Long intr = ciss_intr; 843d69c9c78SScott Long sc->ciss_interrupt_mask = sqmask; 84422657ce1SScott Long } 84522657ce1SScott Long 8463a31b7ebSMike Smith /* 8473a31b7ebSMike Smith * Turn off interrupts before we go routing anything. 8483a31b7ebSMike Smith */ 8493a31b7ebSMike Smith CISS_TL_SIMPLE_DISABLE_INTERRUPTS(sc); 8503a31b7ebSMike Smith 8513a31b7ebSMike Smith /* 8523a31b7ebSMike Smith * Allocate and set up our interrupt. 8533a31b7ebSMike Smith */ 8543a31b7ebSMike Smith if ((sc->ciss_irq_resource = 85522657ce1SScott Long bus_alloc_resource_any(sc->ciss_dev, SYS_RES_IRQ, &sc->ciss_irq_rid[0], 8563a31b7ebSMike Smith RF_ACTIVE | RF_SHAREABLE)) == NULL) { 8573a31b7ebSMike Smith ciss_printf(sc, "can't allocate interrupt\n"); 8583a31b7ebSMike Smith return(ENXIO); 8593a31b7ebSMike Smith } 86022657ce1SScott Long 861cc850363SPeter Wemm if (bus_setup_intr(sc->ciss_dev, sc->ciss_irq_resource, 86222657ce1SScott Long INTR_TYPE_CAM|INTR_MPSAFE, NULL, intr, sc, 8633a31b7ebSMike Smith &sc->ciss_intr)) { 8643a31b7ebSMike Smith ciss_printf(sc, "can't set up interrupt\n"); 8653a31b7ebSMike Smith return(ENXIO); 8663a31b7ebSMike Smith } 8673a31b7ebSMike Smith 8683a31b7ebSMike Smith /* 8693a31b7ebSMike Smith * Allocate the parent bus DMA tag appropriate for our PCI 8703a31b7ebSMike Smith * interface. 8713a31b7ebSMike Smith * 8723a31b7ebSMike Smith * Note that "simple" adapters can only address within a 32-bit 8733a31b7ebSMike Smith * span. 8743a31b7ebSMike Smith */ 875b6f97155SScott Long if (bus_dma_tag_create(bus_get_dma_tag(sc->ciss_dev),/* PCI parent */ 8763a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 877639717c8SPaul Saab BUS_SPACE_MAXADDR, /* lowaddr */ 8783a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 8793a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 880639717c8SPaul Saab BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 8816f954fb3SAlexander Motin BUS_SPACE_UNRESTRICTED, /* nsegments */ 8823a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 88322657ce1SScott Long 0, /* flags */ 884f6b1c44dSScott Long NULL, NULL, /* lockfunc, lockarg */ 8853a31b7ebSMike Smith &sc->ciss_parent_dmat)) { 8863a31b7ebSMike Smith ciss_printf(sc, "can't allocate parent DMA tag\n"); 8873a31b7ebSMike Smith return(ENOMEM); 8883a31b7ebSMike Smith } 8893a31b7ebSMike Smith 8903a31b7ebSMike Smith /* 8913a31b7ebSMike Smith * Create DMA tag for mapping buffers into adapter-addressable 8923a31b7ebSMike Smith * space. 8933a31b7ebSMike Smith */ 8943a31b7ebSMike Smith if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 8953a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 8963a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* lowaddr */ 8973a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 8983a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 8996f954fb3SAlexander Motin (CISS_MAX_SG_ELEMENTS - 1) * PAGE_SIZE, /* maxsize */ 9006f954fb3SAlexander Motin CISS_MAX_SG_ELEMENTS, /* nsegments */ 9013a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 90222657ce1SScott Long BUS_DMA_ALLOCNOW, /* flags */ 903975b7318SScott Long busdma_lock_mutex, &sc->ciss_mtx, /* lockfunc, lockarg */ 9043a31b7ebSMike Smith &sc->ciss_buffer_dmat)) { 9053a31b7ebSMike Smith ciss_printf(sc, "can't allocate buffer DMA tag\n"); 9063a31b7ebSMike Smith return(ENOMEM); 9073a31b7ebSMike Smith } 9083a31b7ebSMike Smith return(0); 9093a31b7ebSMike Smith } 9103a31b7ebSMike Smith 9113a31b7ebSMike Smith /************************************************************************ 91222657ce1SScott Long * Setup MSI/MSIX operation (Performant only) 9132fdaa90dSScott Long * Four interrupts are available, but we only use 1 right now. If MSI-X 9142fdaa90dSScott Long * isn't avaialble, try using MSI instead. 91522657ce1SScott Long */ 91622657ce1SScott Long static int 91722657ce1SScott Long ciss_setup_msix(struct ciss_softc *sc) 91822657ce1SScott Long { 91922657ce1SScott Long int val, i; 92022657ce1SScott Long 92122657ce1SScott Long /* Weed out devices that don't actually support MSI */ 9222fdaa90dSScott Long i = ciss_lookup(sc->ciss_dev); 9232fdaa90dSScott Long if (ciss_vendor_data[i].flags & CISS_BOARD_NOMSI) 92422657ce1SScott Long return (EINVAL); 92522657ce1SScott Long 9262fdaa90dSScott Long /* 9272fdaa90dSScott Long * Only need to use the minimum number of MSI vectors, as the driver 9282fdaa90dSScott Long * doesn't support directed MSIX interrupts. 9292fdaa90dSScott Long */ 93022657ce1SScott Long val = pci_msix_count(sc->ciss_dev); 9312fdaa90dSScott Long if (val < CISS_MSI_COUNT) { 9322fdaa90dSScott Long val = pci_msi_count(sc->ciss_dev); 9332fdaa90dSScott Long device_printf(sc->ciss_dev, "got %d MSI messages]\n", val); 934b23be3e0SScott Long if (val < CISS_MSI_COUNT) 935b23be3e0SScott Long return (EINVAL); 9362fdaa90dSScott Long } 937b23be3e0SScott Long val = MIN(val, CISS_MSI_COUNT); 9382fdaa90dSScott Long if (pci_alloc_msix(sc->ciss_dev, &val) != 0) { 9392fdaa90dSScott Long if (pci_alloc_msi(sc->ciss_dev, &val) != 0) 94022657ce1SScott Long return (EINVAL); 9412fdaa90dSScott Long } 94222657ce1SScott Long 94322657ce1SScott Long sc->ciss_msi = val; 944f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) 9452fdaa90dSScott Long ciss_printf(sc, "Using %d MSIX interrupt%s\n", val, 9462fdaa90dSScott Long (val != 1) ? "s" : ""); 94722657ce1SScott Long 9482fdaa90dSScott Long for (i = 0; i < val; i++) 94922657ce1SScott Long sc->ciss_irq_rid[i] = i + 1; 95022657ce1SScott Long 95122657ce1SScott Long return (0); 95222657ce1SScott Long 95322657ce1SScott Long } 95422657ce1SScott Long 95522657ce1SScott Long /************************************************************************ 95622657ce1SScott Long * Setup the Performant structures. 95722657ce1SScott Long */ 95822657ce1SScott Long static int 95922657ce1SScott Long ciss_init_perf(struct ciss_softc *sc) 96022657ce1SScott Long { 96122657ce1SScott Long struct ciss_perf_config *pc = sc->ciss_perf; 96222657ce1SScott Long int reply_size; 96322657ce1SScott Long 96422657ce1SScott Long /* 96522657ce1SScott Long * Create the DMA tag for the reply queue. 96622657ce1SScott Long */ 96722657ce1SScott Long reply_size = sizeof(uint64_t) * sc->ciss_max_requests; 96822657ce1SScott Long if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 96922657ce1SScott Long 1, 0, /* alignment, boundary */ 97022657ce1SScott Long BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 97122657ce1SScott Long BUS_SPACE_MAXADDR, /* highaddr */ 97222657ce1SScott Long NULL, NULL, /* filter, filterarg */ 97322657ce1SScott Long reply_size, 1, /* maxsize, nsegments */ 97422657ce1SScott Long BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 97522657ce1SScott Long 0, /* flags */ 97622657ce1SScott Long NULL, NULL, /* lockfunc, lockarg */ 97722657ce1SScott Long &sc->ciss_reply_dmat)) { 97822657ce1SScott Long ciss_printf(sc, "can't allocate reply DMA tag\n"); 97922657ce1SScott Long return(ENOMEM); 98022657ce1SScott Long } 98122657ce1SScott Long /* 98222657ce1SScott Long * Allocate memory and make it available for DMA. 98322657ce1SScott Long */ 98422657ce1SScott Long if (bus_dmamem_alloc(sc->ciss_reply_dmat, (void **)&sc->ciss_reply, 98522657ce1SScott Long BUS_DMA_NOWAIT, &sc->ciss_reply_map)) { 98622657ce1SScott Long ciss_printf(sc, "can't allocate reply memory\n"); 98722657ce1SScott Long return(ENOMEM); 98822657ce1SScott Long } 98922657ce1SScott Long bus_dmamap_load(sc->ciss_reply_dmat, sc->ciss_reply_map, sc->ciss_reply, 99022657ce1SScott Long reply_size, ciss_command_map_helper, &sc->ciss_reply_phys, 0); 99122657ce1SScott Long bzero(sc->ciss_reply, reply_size); 99222657ce1SScott Long 99322657ce1SScott Long sc->ciss_cycle = 0x1; 99422657ce1SScott Long sc->ciss_rqidx = 0; 99522657ce1SScott Long 99622657ce1SScott Long /* 99722657ce1SScott Long * Preload the fetch table with common command sizes. This allows the 99822657ce1SScott Long * hardware to not waste bus cycles for typical i/o commands, but also not 99922657ce1SScott Long * tax the driver to be too exact in choosing sizes. The table is optimized 100022657ce1SScott Long * for page-aligned i/o's, but since most i/o comes from the various pagers, 100122657ce1SScott Long * it's a reasonable assumption to make. 100222657ce1SScott Long */ 100322657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_NONE] = (sizeof(struct ciss_command) + 15) / 16; 100422657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_1] = 100522657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 1 + 15) / 16; 100622657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_2] = 100722657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 2 + 15) / 16; 100822657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_4] = 100922657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 4 + 15) / 16; 101022657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_8] = 101122657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 8 + 15) / 16; 101222657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_16] = 101322657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 16 + 15) / 16; 101422657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_32] = 101522657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 32 + 15) / 16; 101622657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_MAX] = (CISS_COMMAND_ALLOC_SIZE + 15) / 16; 101722657ce1SScott Long 101822657ce1SScott Long pc->rq_size = sc->ciss_max_requests; /* XXX less than the card supports? */ 101922657ce1SScott Long pc->rq_count = 1; /* XXX Hardcode for a single queue */ 102022657ce1SScott Long pc->rq_bank_hi = 0; 102122657ce1SScott Long pc->rq_bank_lo = 0; 102222657ce1SScott Long pc->rq[0].rq_addr_hi = 0x0; 102322657ce1SScott Long pc->rq[0].rq_addr_lo = sc->ciss_reply_phys; 102422657ce1SScott Long 102522657ce1SScott Long return(0); 102622657ce1SScott Long } 102722657ce1SScott Long 102822657ce1SScott Long /************************************************************************ 10293a31b7ebSMike Smith * Wait for the adapter to come ready. 10303a31b7ebSMike Smith */ 10313a31b7ebSMike Smith static int 10323a31b7ebSMike Smith ciss_wait_adapter(struct ciss_softc *sc) 10333a31b7ebSMike Smith { 10343a31b7ebSMike Smith int i; 10353a31b7ebSMike Smith 10363a31b7ebSMike Smith debug_called(1); 10373a31b7ebSMike Smith 10383a31b7ebSMike Smith /* 10393a31b7ebSMike Smith * Wait for the adapter to come ready. 10403a31b7ebSMike Smith */ 10413a31b7ebSMike Smith if (!(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY)) { 10423a31b7ebSMike Smith ciss_printf(sc, "waiting for adapter to come ready...\n"); 10433a31b7ebSMike Smith for (i = 0; !(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY); i++) { 10443a31b7ebSMike Smith DELAY(1000000); /* one second */ 10453a31b7ebSMike Smith if (i > 30) { 10463a31b7ebSMike Smith ciss_printf(sc, "timed out waiting for adapter to come ready\n"); 10473a31b7ebSMike Smith return(EIO); 10483a31b7ebSMike Smith } 10493a31b7ebSMike Smith } 10503a31b7ebSMike Smith } 10513a31b7ebSMike Smith return(0); 10523a31b7ebSMike Smith } 10533a31b7ebSMike Smith 10543a31b7ebSMike Smith /************************************************************************ 10553a31b7ebSMike Smith * Flush the adapter cache. 10563a31b7ebSMike Smith */ 10573a31b7ebSMike Smith static int 10583a31b7ebSMike Smith ciss_flush_adapter(struct ciss_softc *sc) 10593a31b7ebSMike Smith { 10603a31b7ebSMike Smith struct ciss_request *cr; 10613a31b7ebSMike Smith struct ciss_bmic_flush_cache *cbfc; 10623a31b7ebSMike Smith int error, command_status; 10633a31b7ebSMike Smith 10643a31b7ebSMike Smith debug_called(1); 10653a31b7ebSMike Smith 10663a31b7ebSMike Smith cr = NULL; 10673a31b7ebSMike Smith cbfc = NULL; 10683a31b7ebSMike Smith 10693a31b7ebSMike Smith /* 10703a31b7ebSMike Smith * Build a BMIC request to flush the cache. We don't disable 10713a31b7ebSMike Smith * it, as we may be going to do more I/O (eg. we are emulating 10723a31b7ebSMike Smith * the Synchronise Cache command). 10733a31b7ebSMike Smith */ 10743a31b7ebSMike Smith if ((cbfc = malloc(sizeof(*cbfc), CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 10753a31b7ebSMike Smith error = ENOMEM; 10763a31b7ebSMike Smith goto out; 10773a31b7ebSMike Smith } 10783a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_FLUSH_CACHE, 10793a31b7ebSMike Smith (void **)&cbfc, sizeof(*cbfc))) != 0) 10803a31b7ebSMike Smith goto out; 10813a31b7ebSMike Smith 10823a31b7ebSMike Smith /* 10833a31b7ebSMike Smith * Submit the request and wait for it to complete. 10843a31b7ebSMike Smith */ 10853a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 10863a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC FLUSH_CACHE command (%d)\n", error); 10873a31b7ebSMike Smith goto out; 10883a31b7ebSMike Smith } 10893a31b7ebSMike Smith 10903a31b7ebSMike Smith /* 10913a31b7ebSMike Smith * Check response. 10923a31b7ebSMike Smith */ 10933a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 10943a31b7ebSMike Smith switch(command_status) { 10953a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 10963a31b7ebSMike Smith break; 10973a31b7ebSMike Smith default: 10983a31b7ebSMike Smith ciss_printf(sc, "error flushing cache (%s)\n", 10993a31b7ebSMike Smith ciss_name_command_status(command_status)); 11003a31b7ebSMike Smith error = EIO; 11013a31b7ebSMike Smith goto out; 11023a31b7ebSMike Smith } 11033a31b7ebSMike Smith 11043a31b7ebSMike Smith out: 11053a31b7ebSMike Smith if (cbfc != NULL) 11063a31b7ebSMike Smith free(cbfc, CISS_MALLOC_CLASS); 11073a31b7ebSMike Smith if (cr != NULL) 11083a31b7ebSMike Smith ciss_release_request(cr); 11093a31b7ebSMike Smith return(error); 11103a31b7ebSMike Smith } 11113a31b7ebSMike Smith 111217c0792dSPaul Saab static void 111317c0792dSPaul Saab ciss_soft_reset(struct ciss_softc *sc) 111417c0792dSPaul Saab { 111517c0792dSPaul Saab struct ciss_request *cr = NULL; 111617c0792dSPaul Saab struct ciss_command *cc; 111717c0792dSPaul Saab int i, error = 0; 111817c0792dSPaul Saab 111917c0792dSPaul Saab for (i = 0; i < sc->ciss_max_logical_bus; i++) { 112017c0792dSPaul Saab /* only reset proxy controllers */ 112117c0792dSPaul Saab if (sc->ciss_controllers[i].physical.bus == 0) 112217c0792dSPaul Saab continue; 112317c0792dSPaul Saab 112417c0792dSPaul Saab if ((error = ciss_get_request(sc, &cr)) != 0) 112517c0792dSPaul Saab break; 112617c0792dSPaul Saab 112717c0792dSPaul Saab if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_SOFT_RESET, 112817c0792dSPaul Saab NULL, 0)) != 0) 112917c0792dSPaul Saab break; 113017c0792dSPaul Saab 11312fdaa90dSScott Long cc = cr->cr_cc; 113217c0792dSPaul Saab cc->header.address = sc->ciss_controllers[i]; 113317c0792dSPaul Saab 113417c0792dSPaul Saab if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) 113517c0792dSPaul Saab break; 113617c0792dSPaul Saab 113717c0792dSPaul Saab ciss_release_request(cr); 113817c0792dSPaul Saab } 113917c0792dSPaul Saab 114017c0792dSPaul Saab if (error) 114117c0792dSPaul Saab ciss_printf(sc, "error resetting controller (%d)\n", error); 114217c0792dSPaul Saab 114317c0792dSPaul Saab if (cr != NULL) 114417c0792dSPaul Saab ciss_release_request(cr); 114517c0792dSPaul Saab } 114617c0792dSPaul Saab 11473a31b7ebSMike Smith /************************************************************************ 11483a31b7ebSMike Smith * Allocate memory for the adapter command structures, initialise 11493a31b7ebSMike Smith * the request structures. 11503a31b7ebSMike Smith * 11513a31b7ebSMike Smith * Note that the entire set of commands are allocated in a single 11523a31b7ebSMike Smith * contiguous slab. 11533a31b7ebSMike Smith */ 11543a31b7ebSMike Smith static int 11553a31b7ebSMike Smith ciss_init_requests(struct ciss_softc *sc) 11563a31b7ebSMike Smith { 11573a31b7ebSMike Smith struct ciss_request *cr; 11583a31b7ebSMike Smith int i; 11593a31b7ebSMike Smith 11603a31b7ebSMike Smith debug_called(1); 11613a31b7ebSMike Smith 1162f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) 11633a31b7ebSMike Smith ciss_printf(sc, "using %d of %d available commands\n", 11643a31b7ebSMike Smith sc->ciss_max_requests, sc->ciss_cfg->max_outstanding_commands); 11653a31b7ebSMike Smith 11663a31b7ebSMike Smith /* 11673a31b7ebSMike Smith * Create the DMA tag for commands. 11683a31b7ebSMike Smith */ 11693a31b7ebSMike Smith if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 117022657ce1SScott Long 32, 0, /* alignment, boundary */ 1171639717c8SPaul Saab BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 11723a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 11733a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 11743a31b7ebSMike Smith CISS_COMMAND_ALLOC_SIZE * 11753a31b7ebSMike Smith sc->ciss_max_requests, 1, /* maxsize, nsegments */ 11763a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 117722657ce1SScott Long 0, /* flags */ 1178639717c8SPaul Saab NULL, NULL, /* lockfunc, lockarg */ 11793a31b7ebSMike Smith &sc->ciss_command_dmat)) { 11803a31b7ebSMike Smith ciss_printf(sc, "can't allocate command DMA tag\n"); 11813a31b7ebSMike Smith return(ENOMEM); 11823a31b7ebSMike Smith } 11833a31b7ebSMike Smith /* 11843a31b7ebSMike Smith * Allocate memory and make it available for DMA. 11853a31b7ebSMike Smith */ 11863a31b7ebSMike Smith if (bus_dmamem_alloc(sc->ciss_command_dmat, (void **)&sc->ciss_command, 11873a31b7ebSMike Smith BUS_DMA_NOWAIT, &sc->ciss_command_map)) { 11883a31b7ebSMike Smith ciss_printf(sc, "can't allocate command memory\n"); 11893a31b7ebSMike Smith return(ENOMEM); 11903a31b7ebSMike Smith } 11913a31b7ebSMike Smith bus_dmamap_load(sc->ciss_command_dmat, sc->ciss_command_map,sc->ciss_command, 1192be241f79SPaul Saab CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests, 119322657ce1SScott Long ciss_command_map_helper, &sc->ciss_command_phys, 0); 11943a31b7ebSMike Smith bzero(sc->ciss_command, CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests); 11953a31b7ebSMike Smith 11963a31b7ebSMike Smith /* 11973a31b7ebSMike Smith * Set up the request and command structures, push requests onto 11983a31b7ebSMike Smith * the free queue. 11993a31b7ebSMike Smith */ 12003a31b7ebSMike Smith for (i = 1; i < sc->ciss_max_requests; i++) { 12013a31b7ebSMike Smith cr = &sc->ciss_request[i]; 12023a31b7ebSMike Smith cr->cr_sc = sc; 12033a31b7ebSMike Smith cr->cr_tag = i; 12042fdaa90dSScott Long cr->cr_cc = (struct ciss_command *)((uintptr_t)sc->ciss_command + 12052fdaa90dSScott Long CISS_COMMAND_ALLOC_SIZE * i); 12062fdaa90dSScott Long cr->cr_ccphys = sc->ciss_command_phys + CISS_COMMAND_ALLOC_SIZE * i; 12073284b9eeSPaul Saab bus_dmamap_create(sc->ciss_buffer_dmat, 0, &cr->cr_datamap); 12083a31b7ebSMike Smith ciss_enqueue_free(cr); 12093a31b7ebSMike Smith } 12103a31b7ebSMike Smith return(0); 12113a31b7ebSMike Smith } 12123a31b7ebSMike Smith 12133a31b7ebSMike Smith static void 12143a31b7ebSMike Smith ciss_command_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error) 12153a31b7ebSMike Smith { 121622657ce1SScott Long uint32_t *addr; 12173a31b7ebSMike Smith 121822657ce1SScott Long addr = arg; 121922657ce1SScott Long *addr = segs[0].ds_addr; 12203a31b7ebSMike Smith } 12213a31b7ebSMike Smith 12223a31b7ebSMike Smith /************************************************************************ 12233a31b7ebSMike Smith * Identify the adapter, print some information about it. 12243a31b7ebSMike Smith */ 12253a31b7ebSMike Smith static int 12263a31b7ebSMike Smith ciss_identify_adapter(struct ciss_softc *sc) 12273a31b7ebSMike Smith { 12283a31b7ebSMike Smith struct ciss_request *cr; 12293a31b7ebSMike Smith int error, command_status; 12303a31b7ebSMike Smith 12313a31b7ebSMike Smith debug_called(1); 12323a31b7ebSMike Smith 12333a31b7ebSMike Smith cr = NULL; 12343a31b7ebSMike Smith 12353a31b7ebSMike Smith /* 12363a31b7ebSMike Smith * Get a request, allocate storage for the adapter data. 12373a31b7ebSMike Smith */ 12383a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_CTLR, 12393a31b7ebSMike Smith (void **)&sc->ciss_id, 12403a31b7ebSMike Smith sizeof(*sc->ciss_id))) != 0) 12413a31b7ebSMike Smith goto out; 12423a31b7ebSMike Smith 12433a31b7ebSMike Smith /* 12443a31b7ebSMike Smith * Submit the request and wait for it to complete. 12453a31b7ebSMike Smith */ 12463a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 12473a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC ID_CTLR command (%d)\n", error); 12483a31b7ebSMike Smith goto out; 12493a31b7ebSMike Smith } 12503a31b7ebSMike Smith 12513a31b7ebSMike Smith /* 12523a31b7ebSMike Smith * Check response. 12533a31b7ebSMike Smith */ 12543a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 12553a31b7ebSMike Smith switch(command_status) { 12563a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 12573a31b7ebSMike Smith break; 12583a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 12593a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 12603a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading adapter information\n"); 12613a31b7ebSMike Smith default: 12623a31b7ebSMike Smith ciss_printf(sc, "error reading adapter information (%s)\n", 12633a31b7ebSMike Smith ciss_name_command_status(command_status)); 12643a31b7ebSMike Smith error = EIO; 12653a31b7ebSMike Smith goto out; 12663a31b7ebSMike Smith } 12673a31b7ebSMike Smith 12683a31b7ebSMike Smith /* sanity-check reply */ 12690fb31ed0SSean Bruno if (!(sc->ciss_id->controller_flags & CONTROLLER_FLAGS_BIG_MAP_SUPPORT)) { 12703a31b7ebSMike Smith ciss_printf(sc, "adapter does not support BIG_MAP\n"); 12713a31b7ebSMike Smith error = ENXIO; 12723a31b7ebSMike Smith goto out; 12733a31b7ebSMike Smith } 12743a31b7ebSMike Smith 1275d4aa427fSPaul Saab #if 0 12763a31b7ebSMike Smith /* XXX later revisions may not need this */ 12773a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_FAKE_SYNCH; 1278d4aa427fSPaul Saab #endif 12793a31b7ebSMike Smith 12803a31b7ebSMike Smith /* XXX only really required for old 5300 adapters? */ 12813a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_BMIC_ABORT; 12823a31b7ebSMike Smith 1283e3edca22SSean Bruno /* 1284e3edca22SSean Bruno * Earlier controller specs do not contain these config 1285e3edca22SSean Bruno * entries, so assume that a 0 means its old and assign 1286e3edca22SSean Bruno * these values to the defaults that were established 1287e3edca22SSean Bruno * when this driver was developed for them 1288e3edca22SSean Bruno */ 1289e3edca22SSean Bruno if (sc->ciss_cfg->max_logical_supported == 0) 1290e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported = CISS_MAX_LOGICAL; 1291e3edca22SSean Bruno if (sc->ciss_cfg->max_physical_supported == 0) 1292e3edca22SSean Bruno sc->ciss_cfg->max_physical_supported = CISS_MAX_PHYSICAL; 12933a31b7ebSMike Smith /* print information */ 1294f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 12953a31b7ebSMike Smith ciss_printf(sc, " %d logical drive%s configured\n", 12963a31b7ebSMike Smith sc->ciss_id->configured_logical_drives, 12973a31b7ebSMike Smith (sc->ciss_id->configured_logical_drives == 1) ? "" : "s"); 12983a31b7ebSMike Smith ciss_printf(sc, " firmware %4.4s\n", sc->ciss_id->running_firmware_revision); 12990fb31ed0SSean Bruno ciss_printf(sc, " %d SCSI channels\n", sc->ciss_id->scsi_chip_count); 13003a31b7ebSMike Smith 1301f373e6b8SPeter Eriksson if (ciss_verbose > 1) { 1302f373e6b8SPeter Eriksson ciss_printf(sc, " %d FC channels\n", sc->ciss_id->fibre_chip_count); 1303f373e6b8SPeter Eriksson ciss_printf(sc, " %d enclosures\n", sc->ciss_id->bEnclosureCount); 1304f373e6b8SPeter Eriksson ciss_printf(sc, " %d expanders\n", sc->ciss_id->bExpanderCount); 1305f373e6b8SPeter Eriksson ciss_printf(sc, " maximum blocks: %d\n", sc->ciss_id->maximum_blocks); 1306f373e6b8SPeter Eriksson ciss_printf(sc, " controller clock: %d\n", sc->ciss_id->controller_clock); 1307f373e6b8SPeter Eriksson ciss_printf(sc, " %d MB controller memory\n", sc->ciss_id->total_controller_mem_mb); 1308f373e6b8SPeter Eriksson } 1309f373e6b8SPeter Eriksson 13103a31b7ebSMike Smith ciss_printf(sc, " signature '%.4s'\n", sc->ciss_cfg->signature); 13113a31b7ebSMike Smith ciss_printf(sc, " valence %d\n", sc->ciss_cfg->valence); 13123a31b7ebSMike Smith ciss_printf(sc, " supported I/O methods 0x%b\n", 13133a31b7ebSMike Smith sc->ciss_cfg->supported_methods, 13143a31b7ebSMike Smith "\20\1READY\2simple\3performant\4MEMQ\n"); 13153a31b7ebSMike Smith ciss_printf(sc, " active I/O method 0x%b\n", 13163a31b7ebSMike Smith sc->ciss_cfg->active_method, "\20\2simple\3performant\4MEMQ\n"); 13173a31b7ebSMike Smith ciss_printf(sc, " 4G page base 0x%08x\n", 13183a31b7ebSMike Smith sc->ciss_cfg->command_physlimit); 13193a31b7ebSMike Smith ciss_printf(sc, " interrupt coalesce delay %dus\n", 13203a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay); 13213a31b7ebSMike Smith ciss_printf(sc, " interrupt coalesce count %d\n", 13223a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count); 13233a31b7ebSMike Smith ciss_printf(sc, " max outstanding commands %d\n", 13243a31b7ebSMike Smith sc->ciss_cfg->max_outstanding_commands); 13253a31b7ebSMike Smith ciss_printf(sc, " bus types 0x%b\n", sc->ciss_cfg->bus_types, 13263a31b7ebSMike Smith "\20\1ultra2\2ultra3\10fibre1\11fibre2\n"); 13273a31b7ebSMike Smith ciss_printf(sc, " server name '%.16s'\n", sc->ciss_cfg->server_name); 13283a31b7ebSMike Smith ciss_printf(sc, " heartbeat 0x%x\n", sc->ciss_cfg->heartbeat); 13295f8cb13cSAlexander Motin ciss_printf(sc, " max logical volumes: %d\n", sc->ciss_cfg->max_logical_supported); 1330e3edca22SSean Bruno ciss_printf(sc, " max physical disks supported: %d\n", sc->ciss_cfg->max_physical_supported); 1331e3edca22SSean Bruno ciss_printf(sc, " max physical disks per logical volume: %d\n", sc->ciss_cfg->max_physical_per_logical); 13320fb31ed0SSean Bruno ciss_printf(sc, " JBOD Support is %s\n", (sc->ciss_id->uiYetMoreControllerFlags & YMORE_CONTROLLER_FLAGS_JBOD_SUPPORTED) ? 13330fb31ed0SSean Bruno "Available" : "Unavailable"); 13340fb31ed0SSean Bruno ciss_printf(sc, " JBOD Mode is %s\n", (sc->ciss_id->PowerUPNvramFlags & PWR_UP_FLAG_JBOD_ENABLED) ? 13350fb31ed0SSean Bruno "Enabled" : "Disabled"); 13363a31b7ebSMike Smith } 13373a31b7ebSMike Smith 13383a31b7ebSMike Smith out: 13393a31b7ebSMike Smith if (error) { 13403a31b7ebSMike Smith if (sc->ciss_id != NULL) { 13413a31b7ebSMike Smith free(sc->ciss_id, CISS_MALLOC_CLASS); 13423a31b7ebSMike Smith sc->ciss_id = NULL; 13433a31b7ebSMike Smith } 13443a31b7ebSMike Smith } 13453a31b7ebSMike Smith if (cr != NULL) 13463a31b7ebSMike Smith ciss_release_request(cr); 13473a31b7ebSMike Smith return(error); 13483a31b7ebSMike Smith } 13493a31b7ebSMike Smith 13503a31b7ebSMike Smith /************************************************************************ 1351c6131460SPaul Saab * Helper routine for generating a list of logical and physical luns. 13523a31b7ebSMike Smith */ 1353c6131460SPaul Saab static struct ciss_lun_report * 1354c6131460SPaul Saab ciss_report_luns(struct ciss_softc *sc, int opcode, int nunits) 13553a31b7ebSMike Smith { 13563a31b7ebSMike Smith struct ciss_request *cr; 13573a31b7ebSMike Smith struct ciss_command *cc; 13583a31b7ebSMike Smith struct ciss_report_cdb *crc; 13593a31b7ebSMike Smith struct ciss_lun_report *cll; 13603a31b7ebSMike Smith int command_status; 1361c6131460SPaul Saab int report_size; 1362c6131460SPaul Saab int error = 0; 13633a31b7ebSMike Smith 13643a31b7ebSMike Smith debug_called(1); 13653a31b7ebSMike Smith 13663a31b7ebSMike Smith cr = NULL; 13673a31b7ebSMike Smith cll = NULL; 13683a31b7ebSMike Smith 13693a31b7ebSMike Smith /* 13703a31b7ebSMike Smith * Get a request, allocate storage for the address list. 13713a31b7ebSMike Smith */ 13723a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 13733a31b7ebSMike Smith goto out; 1374c6131460SPaul Saab report_size = sizeof(*cll) + nunits * sizeof(union ciss_device_address); 13753a31b7ebSMike Smith if ((cll = malloc(report_size, CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 1376c6131460SPaul Saab ciss_printf(sc, "can't allocate memory for lun report\n"); 13773a31b7ebSMike Smith error = ENOMEM; 13783a31b7ebSMike Smith goto out; 13793a31b7ebSMike Smith } 13803a31b7ebSMike Smith 13813a31b7ebSMike Smith /* 1382c6131460SPaul Saab * Build the Report Logical/Physical LUNs command. 13833a31b7ebSMike Smith */ 13842fdaa90dSScott Long cc = cr->cr_cc; 13853a31b7ebSMike Smith cr->cr_data = cll; 13863a31b7ebSMike Smith cr->cr_length = report_size; 13873a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 13883a31b7ebSMike Smith 13893a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 13903a31b7ebSMike Smith cc->header.address.physical.bus = 0; 13913a31b7ebSMike Smith cc->header.address.physical.target = 0; 13923a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*crc); 13933a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 13943a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 13953a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 13963a31b7ebSMike Smith cc->cdb.timeout = 30; /* XXX better suggestions? */ 13973a31b7ebSMike Smith 13983a31b7ebSMike Smith crc = (struct ciss_report_cdb *)&(cc->cdb.cdb[0]); 13993a31b7ebSMike Smith bzero(crc, sizeof(*crc)); 1400c6131460SPaul Saab crc->opcode = opcode; 14013a31b7ebSMike Smith crc->length = htonl(report_size); /* big-endian field */ 14023a31b7ebSMike Smith cll->list_size = htonl(report_size - sizeof(*cll)); /* big-endian field */ 14033a31b7ebSMike Smith 14043a31b7ebSMike Smith /* 14053a31b7ebSMike Smith * Submit the request and wait for it to complete. (timeout 14063a31b7ebSMike Smith * here should be much greater than above) 14073a31b7ebSMike Smith */ 14083a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 1409c6131460SPaul Saab ciss_printf(sc, "error sending %d LUN command (%d)\n", opcode, error); 14103a31b7ebSMike Smith goto out; 14113a31b7ebSMike Smith } 14123a31b7ebSMike Smith 14133a31b7ebSMike Smith /* 14143a31b7ebSMike Smith * Check response. Note that data over/underrun is OK. 14153a31b7ebSMike Smith */ 14163a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 14173a31b7ebSMike Smith switch(command_status) { 14183a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 14193a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: /* buffer too large, not bad */ 14203a31b7ebSMike Smith break; 14213a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 1422c6131460SPaul Saab ciss_printf(sc, "WARNING: more units than driver limit (%d)\n", 1423e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported); 14243a31b7ebSMike Smith break; 14253a31b7ebSMike Smith default: 14263a31b7ebSMike Smith ciss_printf(sc, "error detecting logical drive configuration (%s)\n", 14273a31b7ebSMike Smith ciss_name_command_status(command_status)); 14283a31b7ebSMike Smith error = EIO; 14293a31b7ebSMike Smith goto out; 14303a31b7ebSMike Smith } 14313a31b7ebSMike Smith ciss_release_request(cr); 14323a31b7ebSMike Smith cr = NULL; 14333a31b7ebSMike Smith 1434c6131460SPaul Saab out: 1435c6131460SPaul Saab if (cr != NULL) 1436c6131460SPaul Saab ciss_release_request(cr); 1437c6131460SPaul Saab if (error && cll != NULL) { 1438c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 1439c6131460SPaul Saab cll = NULL; 1440c6131460SPaul Saab } 1441c6131460SPaul Saab return(cll); 1442c6131460SPaul Saab } 1443c6131460SPaul Saab 1444c6131460SPaul Saab /************************************************************************ 1445c6131460SPaul Saab * Find logical drives on the adapter. 1446c6131460SPaul Saab */ 1447c6131460SPaul Saab static int 1448c6131460SPaul Saab ciss_init_logical(struct ciss_softc *sc) 1449c6131460SPaul Saab { 1450c6131460SPaul Saab struct ciss_lun_report *cll; 1451c6131460SPaul Saab int error = 0, i, j; 1452c6131460SPaul Saab int ndrives; 1453c6131460SPaul Saab 1454c6131460SPaul Saab debug_called(1); 1455c6131460SPaul Saab 1456c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_LOGICAL_LUNS, 1457e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported); 1458c6131460SPaul Saab if (cll == NULL) { 1459c6131460SPaul Saab error = ENXIO; 1460c6131460SPaul Saab goto out; 1461c6131460SPaul Saab } 1462c6131460SPaul Saab 14633a31b7ebSMike Smith /* sanity-check reply */ 14643a31b7ebSMike Smith ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 1465e3edca22SSean Bruno if ((ndrives < 0) || (ndrives > sc->ciss_cfg->max_logical_supported)) { 14663a31b7ebSMike Smith ciss_printf(sc, "adapter claims to report absurd number of logical drives (%d > %d)\n", 1467e3edca22SSean Bruno ndrives, sc->ciss_cfg->max_logical_supported); 1468c6131460SPaul Saab error = ENXIO; 1469c6131460SPaul Saab goto out; 14703a31b7ebSMike Smith } 14713a31b7ebSMike Smith 14723a31b7ebSMike Smith /* 14733a31b7ebSMike Smith * Save logical drive information. 14743a31b7ebSMike Smith */ 1475f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 1476c6131460SPaul Saab ciss_printf(sc, "%d logical drive%s\n", 1477c6131460SPaul Saab ndrives, (ndrives > 1 || ndrives == 0) ? "s" : ""); 1478c6131460SPaul Saab } 1479c6131460SPaul Saab 1480c6131460SPaul Saab sc->ciss_logical = 1481ac2fffa4SPedro F. Giffuni malloc(sc->ciss_max_logical_bus * sizeof(struct ciss_ldrive *), 1482c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1483c6131460SPaul Saab if (sc->ciss_logical == NULL) { 1484c6131460SPaul Saab error = ENXIO; 1485c6131460SPaul Saab goto out; 1486c6131460SPaul Saab } 1487c6131460SPaul Saab 14885eae46afSConrad Meyer for (i = 0; i < sc->ciss_max_logical_bus; i++) { 1489c6131460SPaul Saab sc->ciss_logical[i] = 1490ac2fffa4SPedro F. Giffuni malloc(sc->ciss_cfg->max_logical_supported * 1491e3edca22SSean Bruno sizeof(struct ciss_ldrive), 1492c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1493c6131460SPaul Saab if (sc->ciss_logical[i] == NULL) { 1494c6131460SPaul Saab error = ENXIO; 1495c6131460SPaul Saab goto out; 1496c6131460SPaul Saab } 1497c6131460SPaul Saab 1498e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) 1499c6131460SPaul Saab sc->ciss_logical[i][j].cl_status = CISS_LD_NONEXISTENT; 1500c6131460SPaul Saab } 1501c6131460SPaul Saab 1502e3edca22SSean Bruno for (i = 0; i < sc->ciss_cfg->max_logical_supported; i++) { 15033a31b7ebSMike Smith if (i < ndrives) { 1504c6131460SPaul Saab struct ciss_ldrive *ld; 1505c6131460SPaul Saab int bus, target; 1506c6131460SPaul Saab 1507c6131460SPaul Saab bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); 1508c6131460SPaul Saab target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); 1509c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 1510c6131460SPaul Saab 1511c6131460SPaul Saab ld->cl_address = cll->lun[i]; 1512c6131460SPaul Saab ld->cl_controller = &sc->ciss_controllers[bus]; 1513c6131460SPaul Saab if (ciss_identify_logical(sc, ld) != 0) 15143a31b7ebSMike Smith continue; 15153a31b7ebSMike Smith /* 15163a31b7ebSMike Smith * If the drive has had media exchanged, we should bring it online. 15173a31b7ebSMike Smith */ 1518c6131460SPaul Saab if (ld->cl_lstatus->media_exchanged) 151988c78a38SPaul Saab ciss_accept_media(sc, ld); 15203a31b7ebSMike Smith } 15213a31b7ebSMike Smith } 15223a31b7ebSMike Smith 15233a31b7ebSMike Smith out: 15243a31b7ebSMike Smith if (cll != NULL) 15253a31b7ebSMike Smith free(cll, CISS_MALLOC_CLASS); 15263a31b7ebSMike Smith return(error); 15273a31b7ebSMike Smith } 15283a31b7ebSMike Smith 1529440baa08SPaul Saab static int 1530c6131460SPaul Saab ciss_init_physical(struct ciss_softc *sc) 1531c6131460SPaul Saab { 1532c6131460SPaul Saab struct ciss_lun_report *cll; 1533c6131460SPaul Saab int error = 0, i; 1534c6131460SPaul Saab int nphys; 153579ed7cb3SScott Long int bus; 1536c6131460SPaul Saab 1537c6131460SPaul Saab debug_called(1); 1538c6131460SPaul Saab 15391fe6c4eeSScott Long bus = 0; 15401fe6c4eeSScott Long 1541c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_PHYSICAL_LUNS, 1542e3edca22SSean Bruno sc->ciss_cfg->max_physical_supported); 1543c6131460SPaul Saab if (cll == NULL) { 1544c6131460SPaul Saab error = ENXIO; 1545c6131460SPaul Saab goto out; 1546c6131460SPaul Saab } 1547c6131460SPaul Saab 1548c6131460SPaul Saab nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 1549c6131460SPaul Saab 1550f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 1551c6131460SPaul Saab ciss_printf(sc, "%d physical device%s\n", 1552c6131460SPaul Saab nphys, (nphys > 1 || nphys == 0) ? "s" : ""); 1553c6131460SPaul Saab } 1554c6131460SPaul Saab 155545645518SPeter Eriksson /* Per-controller highest target number seen */ 155645645518SPeter Eriksson sc->ciss_max_physical_target = 0; 155745645518SPeter Eriksson 1558c6131460SPaul Saab /* 15591fe6c4eeSScott Long * Figure out the bus mapping. 15601fe6c4eeSScott Long * Logical buses include both the local logical bus for local arrays and 15611fe6c4eeSScott Long * proxy buses for remote arrays. Physical buses are numbered by the 15621fe6c4eeSScott Long * controller and represent physical buses that hold physical devices. 15631fe6c4eeSScott Long * We shift these bus numbers so that everything fits into a single flat 15641fe6c4eeSScott Long * numbering space for CAM. Logical buses occupy the first 32 CAM bus 15651fe6c4eeSScott Long * numbers, and the physical bus numbers are shifted to be above that. 15661fe6c4eeSScott Long * This results in the various driver arrays being indexed as follows: 15671fe6c4eeSScott Long * 15681fe6c4eeSScott Long * ciss_controllers[] - indexed by logical bus 15691fe6c4eeSScott Long * ciss_cam_sim[] - indexed by both logical and physical, with physical 15701fe6c4eeSScott Long * being shifted by 32. 15711fe6c4eeSScott Long * ciss_logical[][] - indexed by logical bus 15721fe6c4eeSScott Long * ciss_physical[][] - indexed by physical bus 15731fe6c4eeSScott Long * 15741fe6c4eeSScott Long * XXX This is getting more and more hackish. CISS really doesn't play 15751fe6c4eeSScott Long * well with a standard SCSI model; devices are addressed via magic 15761fe6c4eeSScott Long * cookies, not via b/t/l addresses. Since there is no way to store 15771fe6c4eeSScott Long * the cookie in the CAM device object, we have to keep these lookup 15781fe6c4eeSScott Long * tables handy so that the devices can be found quickly at the cost 15791fe6c4eeSScott Long * of wasting memory and having a convoluted lookup scheme. This 15801fe6c4eeSScott Long * driver should probably be converted to block interface. 15811fe6c4eeSScott Long */ 15821fe6c4eeSScott Long /* 1583c6131460SPaul Saab * If the L2 and L3 SCSI addresses are 0, this signifies a proxy 1584c6131460SPaul Saab * controller. A proxy controller is another physical controller 1585c6131460SPaul Saab * behind the primary PCI controller. We need to know about this 1586c6131460SPaul Saab * so that BMIC commands can be properly targeted. There can be 1587c6131460SPaul Saab * proxy controllers attached to a single PCI controller, so 1588c6131460SPaul Saab * find the highest numbered one so the array can be properly 1589c6131460SPaul Saab * sized. 1590c6131460SPaul Saab */ 15911fe6c4eeSScott Long sc->ciss_max_logical_bus = 1; 1592c6131460SPaul Saab for (i = 0; i < nphys; i++) { 1593c6131460SPaul Saab if (cll->lun[i].physical.extra_address == 0) { 15941fe6c4eeSScott Long bus = cll->lun[i].physical.bus; 15951fe6c4eeSScott Long sc->ciss_max_logical_bus = max(sc->ciss_max_logical_bus, bus) + 1; 15961fe6c4eeSScott Long } else { 15971fe6c4eeSScott Long bus = CISS_EXTRA_BUS2(cll->lun[i].physical.extra_address); 15981fe6c4eeSScott Long sc->ciss_max_physical_bus = max(sc->ciss_max_physical_bus, bus); 1599c6131460SPaul Saab } 1600c6131460SPaul Saab } 1601c6131460SPaul Saab 1602c6131460SPaul Saab sc->ciss_controllers = 1603ac2fffa4SPedro F. Giffuni malloc(sc->ciss_max_logical_bus * sizeof (union ciss_device_address), 1604c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1605c6131460SPaul Saab 1606c6131460SPaul Saab if (sc->ciss_controllers == NULL) { 1607c6131460SPaul Saab ciss_printf(sc, "Could not allocate memory for controller map\n"); 1608c6131460SPaul Saab error = ENOMEM; 1609c6131460SPaul Saab goto out; 1610c6131460SPaul Saab } 1611c6131460SPaul Saab 1612c6131460SPaul Saab /* setup a map of controller addresses */ 1613c6131460SPaul Saab for (i = 0; i < nphys; i++) { 1614c6131460SPaul Saab if (cll->lun[i].physical.extra_address == 0) { 1615c6131460SPaul Saab sc->ciss_controllers[cll->lun[i].physical.bus] = cll->lun[i]; 1616c6131460SPaul Saab } 1617c6131460SPaul Saab } 1618c6131460SPaul Saab 16191fe6c4eeSScott Long sc->ciss_physical = 1620ac2fffa4SPedro F. Giffuni malloc(sc->ciss_max_physical_bus * sizeof(struct ciss_pdrive *), 16211fe6c4eeSScott Long CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 16221fe6c4eeSScott Long if (sc->ciss_physical == NULL) { 16231fe6c4eeSScott Long ciss_printf(sc, "Could not allocate memory for physical device map\n"); 16241fe6c4eeSScott Long error = ENOMEM; 16251fe6c4eeSScott Long goto out; 16261fe6c4eeSScott Long } 16271fe6c4eeSScott Long 16281fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_physical_bus; i++) { 16291fe6c4eeSScott Long sc->ciss_physical[i] = 16301fe6c4eeSScott Long malloc(sizeof(struct ciss_pdrive) * CISS_MAX_PHYSTGT, 16311fe6c4eeSScott Long CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 16321fe6c4eeSScott Long if (sc->ciss_physical[i] == NULL) { 16331fe6c4eeSScott Long ciss_printf(sc, "Could not allocate memory for target map\n"); 16341fe6c4eeSScott Long error = ENOMEM; 16351fe6c4eeSScott Long goto out; 16361fe6c4eeSScott Long } 16371fe6c4eeSScott Long } 16381fe6c4eeSScott Long 16391fe6c4eeSScott Long ciss_filter_physical(sc, cll); 164045645518SPeter Eriksson if (bootverbose || ciss_verbose) 164145645518SPeter Eriksson ciss_printf(sc, "max physical target id: %d\n", sc->ciss_max_physical_target); 16421fe6c4eeSScott Long 1643c6131460SPaul Saab out: 1644c6131460SPaul Saab if (cll != NULL) 1645c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 1646c6131460SPaul Saab 1647c6131460SPaul Saab return(error); 1648c6131460SPaul Saab } 1649c6131460SPaul Saab 1650c6131460SPaul Saab static int 16511fe6c4eeSScott Long ciss_filter_physical(struct ciss_softc *sc, struct ciss_lun_report *cll) 16521fe6c4eeSScott Long { 16531fe6c4eeSScott Long u_int32_t ea; 16541fe6c4eeSScott Long int i, nphys; 16551fe6c4eeSScott Long int bus, target; 16561fe6c4eeSScott Long 16571fe6c4eeSScott Long nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 16581fe6c4eeSScott Long for (i = 0; i < nphys; i++) { 16591fe6c4eeSScott Long if (cll->lun[i].physical.extra_address == 0) 16601fe6c4eeSScott Long continue; 16611fe6c4eeSScott Long 16621fe6c4eeSScott Long /* 16631fe6c4eeSScott Long * Filter out devices that we don't want. Level 3 LUNs could 16641fe6c4eeSScott Long * probably be supported, but the docs don't give enough of a 16651fe6c4eeSScott Long * hint to know how. 16661fe6c4eeSScott Long * 16671fe6c4eeSScott Long * The mode field of the physical address is likely set to have 16681fe6c4eeSScott Long * hard disks masked out. Honor it unless the user has overridden 16691fe6c4eeSScott Long * us with the tunable. We also munge the inquiry data for these 16701fe6c4eeSScott Long * disks so that they only show up as passthrough devices. Keeping 16711fe6c4eeSScott Long * them visible in this fashion is useful for doing things like 16721fe6c4eeSScott Long * flashing firmware. 16731fe6c4eeSScott Long */ 16741fe6c4eeSScott Long ea = cll->lun[i].physical.extra_address; 16751fe6c4eeSScott Long if ((CISS_EXTRA_BUS3(ea) != 0) || (CISS_EXTRA_TARGET3(ea) != 0) || 16761fe6c4eeSScott Long (CISS_EXTRA_MODE2(ea) == 0x3)) 16771fe6c4eeSScott Long continue; 16781fe6c4eeSScott Long if ((ciss_expose_hidden_physical == 0) && 16791fe6c4eeSScott Long (cll->lun[i].physical.mode == CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL)) 16801fe6c4eeSScott Long continue; 16811fe6c4eeSScott Long 16821fe6c4eeSScott Long /* 16831fe6c4eeSScott Long * Note: CISS firmware numbers physical busses starting at '1', not 16841fe6c4eeSScott Long * '0'. This numbering is internal to the firmware and is only 16851fe6c4eeSScott Long * used as a hint here. 16861fe6c4eeSScott Long */ 16871fe6c4eeSScott Long bus = CISS_EXTRA_BUS2(ea) - 1; 16881fe6c4eeSScott Long target = CISS_EXTRA_TARGET2(ea); 16891fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_address = cll->lun[i]; 16901fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_online = 1; 169145645518SPeter Eriksson 169245645518SPeter Eriksson if ((target > sc->ciss_max_physical_target) && 169345645518SPeter Eriksson (cll->lun[i].physical.mode != CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL)) 169445645518SPeter Eriksson sc->ciss_max_physical_target = target; 16951fe6c4eeSScott Long } 16961fe6c4eeSScott Long 16971fe6c4eeSScott Long return (0); 16981fe6c4eeSScott Long } 16991fe6c4eeSScott Long 17001fe6c4eeSScott Long static int 1701440baa08SPaul Saab ciss_inquiry_logical(struct ciss_softc *sc, struct ciss_ldrive *ld) 1702440baa08SPaul Saab { 1703440baa08SPaul Saab struct ciss_request *cr; 1704440baa08SPaul Saab struct ciss_command *cc; 1705440baa08SPaul Saab struct scsi_inquiry *inq; 1706440baa08SPaul Saab int error; 1707440baa08SPaul Saab int command_status; 1708440baa08SPaul Saab 1709440baa08SPaul Saab cr = NULL; 1710440baa08SPaul Saab 1711440baa08SPaul Saab bzero(&ld->cl_geometry, sizeof(ld->cl_geometry)); 1712440baa08SPaul Saab 1713440baa08SPaul Saab if ((error = ciss_get_request(sc, &cr)) != 0) 1714440baa08SPaul Saab goto out; 1715440baa08SPaul Saab 17162fdaa90dSScott Long cc = cr->cr_cc; 1717440baa08SPaul Saab cr->cr_data = &ld->cl_geometry; 1718440baa08SPaul Saab cr->cr_length = sizeof(ld->cl_geometry); 1719440baa08SPaul Saab cr->cr_flags = CISS_REQ_DATAIN; 1720440baa08SPaul Saab 1721c6131460SPaul Saab cc->header.address = ld->cl_address; 1722440baa08SPaul Saab cc->cdb.cdb_length = 6; 1723440baa08SPaul Saab cc->cdb.type = CISS_CDB_TYPE_COMMAND; 1724440baa08SPaul Saab cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 1725440baa08SPaul Saab cc->cdb.direction = CISS_CDB_DIRECTION_READ; 1726440baa08SPaul Saab cc->cdb.timeout = 30; 1727440baa08SPaul Saab 1728440baa08SPaul Saab inq = (struct scsi_inquiry *)&(cc->cdb.cdb[0]); 1729440baa08SPaul Saab inq->opcode = INQUIRY; 1730440baa08SPaul Saab inq->byte2 = SI_EVPD; 1731440baa08SPaul Saab inq->page_code = CISS_VPD_LOGICAL_DRIVE_GEOMETRY; 1732130f4520SKenneth D. Merry scsi_ulto2b(sizeof(ld->cl_geometry), inq->length); 1733440baa08SPaul Saab 1734440baa08SPaul Saab if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 1735440baa08SPaul Saab ciss_printf(sc, "error getting geometry (%d)\n", error); 1736440baa08SPaul Saab goto out; 1737440baa08SPaul Saab } 1738440baa08SPaul Saab 1739440baa08SPaul Saab ciss_report_request(cr, &command_status, NULL); 1740440baa08SPaul Saab switch(command_status) { 1741440baa08SPaul Saab case CISS_CMD_STATUS_SUCCESS: 1742440baa08SPaul Saab case CISS_CMD_STATUS_DATA_UNDERRUN: 1743440baa08SPaul Saab break; 1744440baa08SPaul Saab case CISS_CMD_STATUS_DATA_OVERRUN: 1745440baa08SPaul Saab ciss_printf(sc, "WARNING: Data overrun\n"); 1746440baa08SPaul Saab break; 1747440baa08SPaul Saab default: 1748440baa08SPaul Saab ciss_printf(sc, "Error detecting logical drive geometry (%s)\n", 1749440baa08SPaul Saab ciss_name_command_status(command_status)); 1750440baa08SPaul Saab break; 1751440baa08SPaul Saab } 1752440baa08SPaul Saab 1753440baa08SPaul Saab out: 1754440baa08SPaul Saab if (cr != NULL) 1755440baa08SPaul Saab ciss_release_request(cr); 1756440baa08SPaul Saab return(error); 1757440baa08SPaul Saab } 17583a31b7ebSMike Smith /************************************************************************ 17593a31b7ebSMike Smith * Identify a logical drive, initialise state related to it. 17603a31b7ebSMike Smith */ 17613a31b7ebSMike Smith static int 17623a31b7ebSMike Smith ciss_identify_logical(struct ciss_softc *sc, struct ciss_ldrive *ld) 17633a31b7ebSMike Smith { 17643a31b7ebSMike Smith struct ciss_request *cr; 17653a31b7ebSMike Smith struct ciss_command *cc; 17663a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 17673a31b7ebSMike Smith int error, command_status; 17683a31b7ebSMike Smith 17693a31b7ebSMike Smith debug_called(1); 17703a31b7ebSMike Smith 17713a31b7ebSMike Smith cr = NULL; 17723a31b7ebSMike Smith 17733a31b7ebSMike Smith /* 17743a31b7ebSMike Smith * Build a BMIC request to fetch the drive ID. 17753a31b7ebSMike Smith */ 17763a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_LDRIVE, 17773a31b7ebSMike Smith (void **)&ld->cl_ldrive, 17783a31b7ebSMike Smith sizeof(*ld->cl_ldrive))) != 0) 17793a31b7ebSMike Smith goto out; 17802fdaa90dSScott Long cc = cr->cr_cc; 1781c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 17823a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1783c6131460SPaul Saab cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 17843a31b7ebSMike Smith 17853a31b7ebSMike Smith /* 17863a31b7ebSMike Smith * Submit the request and wait for it to complete. 17873a31b7ebSMike Smith */ 17883a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 17893a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC LDRIVE command (%d)\n", error); 17903a31b7ebSMike Smith goto out; 17913a31b7ebSMike Smith } 17923a31b7ebSMike Smith 17933a31b7ebSMike Smith /* 17943a31b7ebSMike Smith * Check response. 17953a31b7ebSMike Smith */ 17963a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 17973a31b7ebSMike Smith switch(command_status) { 17983a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 17993a31b7ebSMike Smith break; 18003a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 18013a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 18023a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading logical drive ID\n"); 18033a31b7ebSMike Smith default: 18043a31b7ebSMike Smith ciss_printf(sc, "error reading logical drive ID (%s)\n", 18053a31b7ebSMike Smith ciss_name_command_status(command_status)); 18063a31b7ebSMike Smith error = EIO; 18073a31b7ebSMike Smith goto out; 18083a31b7ebSMike Smith } 18093a31b7ebSMike Smith ciss_release_request(cr); 18103a31b7ebSMike Smith cr = NULL; 18113a31b7ebSMike Smith 18123a31b7ebSMike Smith /* 18133a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive status. 18143a31b7ebSMike Smith */ 18153a31b7ebSMike Smith if ((error = ciss_get_ldrive_status(sc, ld)) != 0) 18163a31b7ebSMike Smith goto out; 18173a31b7ebSMike Smith 18183a31b7ebSMike Smith /* 1819440baa08SPaul Saab * Get the logical drive geometry. 1820440baa08SPaul Saab */ 1821440baa08SPaul Saab if ((error = ciss_inquiry_logical(sc, ld)) != 0) 1822440baa08SPaul Saab goto out; 1823440baa08SPaul Saab 1824440baa08SPaul Saab /* 18253a31b7ebSMike Smith * Print the drive's basic characteristics. 18263a31b7ebSMike Smith */ 1827f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 1828c6131460SPaul Saab ciss_printf(sc, "logical drive (b%dt%d): %s, %dMB ", 1829c6131460SPaul Saab CISS_LUN_TO_BUS(ld->cl_address.logical.lun), 1830c6131460SPaul Saab CISS_LUN_TO_TARGET(ld->cl_address.logical.lun), 183179adbf76SPaul Saab ciss_name_ldrive_org(ld->cl_ldrive->fault_tolerance), 18323a31b7ebSMike Smith ((ld->cl_ldrive->blocks_available / (1024 * 1024)) * 18333a31b7ebSMike Smith ld->cl_ldrive->block_size)); 18343a31b7ebSMike Smith 18353a31b7ebSMike Smith ciss_print_ldrive(sc, ld); 18363a31b7ebSMike Smith } 18373a31b7ebSMike Smith out: 18383a31b7ebSMike Smith if (error != 0) { 18393a31b7ebSMike Smith /* make the drive not-exist */ 18403a31b7ebSMike Smith ld->cl_status = CISS_LD_NONEXISTENT; 18413a31b7ebSMike Smith if (ld->cl_ldrive != NULL) { 18423a31b7ebSMike Smith free(ld->cl_ldrive, CISS_MALLOC_CLASS); 18433a31b7ebSMike Smith ld->cl_ldrive = NULL; 18443a31b7ebSMike Smith } 18453a31b7ebSMike Smith if (ld->cl_lstatus != NULL) { 18463a31b7ebSMike Smith free(ld->cl_lstatus, CISS_MALLOC_CLASS); 18473a31b7ebSMike Smith ld->cl_lstatus = NULL; 18483a31b7ebSMike Smith } 18493a31b7ebSMike Smith } 18503a31b7ebSMike Smith if (cr != NULL) 18513a31b7ebSMike Smith ciss_release_request(cr); 18523a31b7ebSMike Smith 18533a31b7ebSMike Smith return(error); 18543a31b7ebSMike Smith } 18553a31b7ebSMike Smith 18563a31b7ebSMike Smith /************************************************************************ 18573a31b7ebSMike Smith * Get status for a logical drive. 18583a31b7ebSMike Smith * 18593a31b7ebSMike Smith * XXX should we also do this in response to Test Unit Ready? 18603a31b7ebSMike Smith */ 18613a31b7ebSMike Smith static int 18623a31b7ebSMike Smith ciss_get_ldrive_status(struct ciss_softc *sc, struct ciss_ldrive *ld) 18633a31b7ebSMike Smith { 18643a31b7ebSMike Smith struct ciss_request *cr; 18653a31b7ebSMike Smith struct ciss_command *cc; 18663a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 18673a31b7ebSMike Smith int error, command_status; 18683a31b7ebSMike Smith 18693a31b7ebSMike Smith /* 18703a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive status. 18713a31b7ebSMike Smith */ 18723a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_LSTATUS, 18733a31b7ebSMike Smith (void **)&ld->cl_lstatus, 18743a31b7ebSMike Smith sizeof(*ld->cl_lstatus))) != 0) 18753a31b7ebSMike Smith goto out; 18762fdaa90dSScott Long cc = cr->cr_cc; 1877c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 18783a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1879c6131460SPaul Saab cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 18803a31b7ebSMike Smith 18813a31b7ebSMike Smith /* 18823a31b7ebSMike Smith * Submit the request and wait for it to complete. 18833a31b7ebSMike Smith */ 18843a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 18853a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC LSTATUS command (%d)\n", error); 18863a31b7ebSMike Smith goto out; 18873a31b7ebSMike Smith } 18883a31b7ebSMike Smith 18893a31b7ebSMike Smith /* 18903a31b7ebSMike Smith * Check response. 18913a31b7ebSMike Smith */ 18923a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 18933a31b7ebSMike Smith switch(command_status) { 18943a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 18953a31b7ebSMike Smith break; 18963a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 18973a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 18983a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading logical drive status\n"); 18993a31b7ebSMike Smith default: 19003a31b7ebSMike Smith ciss_printf(sc, "error reading logical drive status (%s)\n", 19013a31b7ebSMike Smith ciss_name_command_status(command_status)); 19023a31b7ebSMike Smith error = EIO; 19033a31b7ebSMike Smith goto out; 19043a31b7ebSMike Smith } 19053a31b7ebSMike Smith 19063a31b7ebSMike Smith /* 19073a31b7ebSMike Smith * Set the drive's summary status based on the returned status. 19083a31b7ebSMike Smith * 19093a31b7ebSMike Smith * XXX testing shows that a failed JBOD drive comes back at next 19103a31b7ebSMike Smith * boot in "queued for expansion" mode. WTF? 19113a31b7ebSMike Smith */ 19123a31b7ebSMike Smith ld->cl_status = ciss_decode_ldrive_status(ld->cl_lstatus->status); 19133a31b7ebSMike Smith 19143a31b7ebSMike Smith out: 19153a31b7ebSMike Smith if (cr != NULL) 19163a31b7ebSMike Smith ciss_release_request(cr); 19173a31b7ebSMike Smith return(error); 19183a31b7ebSMike Smith } 19193a31b7ebSMike Smith 19203a31b7ebSMike Smith /************************************************************************ 19213a31b7ebSMike Smith * Notify the adapter of a config update. 19223a31b7ebSMike Smith */ 19233a31b7ebSMike Smith static int 19243a31b7ebSMike Smith ciss_update_config(struct ciss_softc *sc) 19253a31b7ebSMike Smith { 19263a31b7ebSMike Smith int i; 19273a31b7ebSMike Smith 19283a31b7ebSMike Smith debug_called(1); 19293a31b7ebSMike Smith 19303a31b7ebSMike Smith CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IDBR, CISS_TL_SIMPLE_IDBR_CFG_TABLE); 19313a31b7ebSMike Smith for (i = 0; i < 1000; i++) { 19323a31b7ebSMike Smith if (!(CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IDBR) & 19333a31b7ebSMike Smith CISS_TL_SIMPLE_IDBR_CFG_TABLE)) { 19343a31b7ebSMike Smith return(0); 19353a31b7ebSMike Smith } 19363a31b7ebSMike Smith DELAY(1000); 19373a31b7ebSMike Smith } 19383a31b7ebSMike Smith return(1); 19393a31b7ebSMike Smith } 19403a31b7ebSMike Smith 19413a31b7ebSMike Smith /************************************************************************ 19423a31b7ebSMike Smith * Accept new media into a logical drive. 19433a31b7ebSMike Smith * 19443a31b7ebSMike Smith * XXX The drive has previously been offline; it would be good if we 19453a31b7ebSMike Smith * could make sure it's not open right now. 19463a31b7ebSMike Smith */ 19473a31b7ebSMike Smith static int 194888c78a38SPaul Saab ciss_accept_media(struct ciss_softc *sc, struct ciss_ldrive *ld) 19493a31b7ebSMike Smith { 19503a31b7ebSMike Smith struct ciss_request *cr; 19513a31b7ebSMike Smith struct ciss_command *cc; 19523a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 195388c78a38SPaul Saab int command_status; 195488c78a38SPaul Saab int error = 0, ldrive; 1955609caf8dSPaul Saab 1956609caf8dSPaul Saab ldrive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 19573a31b7ebSMike Smith 19583ea59fd3SSean Bruno debug(0, "bringing logical drive %d back online", ldrive); 19593a31b7ebSMike Smith 19603a31b7ebSMike Smith /* 19613a31b7ebSMike Smith * Build a CISS BMIC command to bring the drive back online. 19623a31b7ebSMike Smith */ 19633a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ACCEPT_MEDIA, 19643a31b7ebSMike Smith NULL, 0)) != 0) 19653a31b7ebSMike Smith goto out; 19662fdaa90dSScott Long cc = cr->cr_cc; 1967c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 19683a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1969609caf8dSPaul Saab cbc->log_drive = ldrive; 19703a31b7ebSMike Smith 19713a31b7ebSMike Smith /* 19723a31b7ebSMike Smith * Submit the request and wait for it to complete. 19733a31b7ebSMike Smith */ 19743a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 197588c78a38SPaul Saab ciss_printf(sc, "error sending BMIC ACCEPT MEDIA command (%d)\n", error); 19763a31b7ebSMike Smith goto out; 19773a31b7ebSMike Smith } 19783a31b7ebSMike Smith 19793a31b7ebSMike Smith /* 19803a31b7ebSMike Smith * Check response. 19813a31b7ebSMike Smith */ 19823a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 19833a31b7ebSMike Smith switch(command_status) { 19843a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* all OK */ 19853a31b7ebSMike Smith /* we should get a logical drive status changed event here */ 19863a31b7ebSMike Smith break; 19873a31b7ebSMike Smith default: 19883a31b7ebSMike Smith ciss_printf(cr->cr_sc, "error accepting media into failed logical drive (%s)\n", 19893a31b7ebSMike Smith ciss_name_command_status(command_status)); 19903a31b7ebSMike Smith break; 19913a31b7ebSMike Smith } 199288c78a38SPaul Saab 199388c78a38SPaul Saab out: 199488c78a38SPaul Saab if (cr != NULL) 19953a31b7ebSMike Smith ciss_release_request(cr); 199688c78a38SPaul Saab return(error); 19973a31b7ebSMike Smith } 19983a31b7ebSMike Smith 19993a31b7ebSMike Smith /************************************************************************ 20003a31b7ebSMike Smith * Release adapter resources. 20013a31b7ebSMike Smith */ 20023a31b7ebSMike Smith static void 20033a31b7ebSMike Smith ciss_free(struct ciss_softc *sc) 20043a31b7ebSMike Smith { 20053284b9eeSPaul Saab struct ciss_request *cr; 2006ee626b40SPaul Saab int i, j; 20073284b9eeSPaul Saab 20083a31b7ebSMike Smith debug_called(1); 20093a31b7ebSMike Smith 20103a31b7ebSMike Smith /* we're going away */ 20113a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_ABORTING; 20123a31b7ebSMike Smith 20133a31b7ebSMike Smith /* terminate the periodic heartbeat routine */ 20142472e51eSScott Long callout_stop(&sc->ciss_periodic); 20153a31b7ebSMike Smith 20163a31b7ebSMike Smith /* cancel the Event Notify chain */ 20173a31b7ebSMike Smith ciss_notify_abort(sc); 20183a31b7ebSMike Smith 2019c6131460SPaul Saab ciss_kill_notify_thread(sc); 2020c6131460SPaul Saab 20212472e51eSScott Long /* disconnect from CAM */ 20222472e51eSScott Long if (sc->ciss_cam_sim) { 20232472e51eSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 20242472e51eSScott Long if (sc->ciss_cam_sim[i]) { 20252472e51eSScott Long xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); 20262472e51eSScott Long cam_sim_free(sc->ciss_cam_sim[i], 0); 20272472e51eSScott Long } 20282472e51eSScott Long } 20292472e51eSScott Long for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 20302472e51eSScott Long CISS_PHYSICAL_BASE; i++) { 20312472e51eSScott Long if (sc->ciss_cam_sim[i]) { 20322472e51eSScott Long xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); 20332472e51eSScott Long cam_sim_free(sc->ciss_cam_sim[i], 0); 20342472e51eSScott Long } 20352472e51eSScott Long } 20362472e51eSScott Long free(sc->ciss_cam_sim, CISS_MALLOC_CLASS); 20372472e51eSScott Long } 20382472e51eSScott Long if (sc->ciss_cam_devq) 20392472e51eSScott Long cam_simq_free(sc->ciss_cam_devq); 20402472e51eSScott Long 204178d03361SPaul Saab /* remove the control device */ 20422472e51eSScott Long mtx_unlock(&sc->ciss_mtx); 204378d03361SPaul Saab if (sc->ciss_dev_t != NULL) 204478d03361SPaul Saab destroy_dev(sc->ciss_dev_t); 204578d03361SPaul Saab 20462472e51eSScott Long /* Final cleanup of the callout. */ 20472472e51eSScott Long callout_drain(&sc->ciss_periodic); 20482472e51eSScott Long mtx_destroy(&sc->ciss_mtx); 20492472e51eSScott Long 20503a31b7ebSMike Smith /* free the controller data */ 20513a31b7ebSMike Smith if (sc->ciss_id != NULL) 20523a31b7ebSMike Smith free(sc->ciss_id, CISS_MALLOC_CLASS); 20533a31b7ebSMike Smith 20543a31b7ebSMike Smith /* release I/O resources */ 20553a31b7ebSMike Smith if (sc->ciss_regs_resource != NULL) 20563a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, 20573a31b7ebSMike Smith sc->ciss_regs_rid, sc->ciss_regs_resource); 20583a31b7ebSMike Smith if (sc->ciss_cfg_resource != NULL) 20593a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, 20603a31b7ebSMike Smith sc->ciss_cfg_rid, sc->ciss_cfg_resource); 20613a31b7ebSMike Smith if (sc->ciss_intr != NULL) 20623a31b7ebSMike Smith bus_teardown_intr(sc->ciss_dev, sc->ciss_irq_resource, sc->ciss_intr); 20633a31b7ebSMike Smith if (sc->ciss_irq_resource != NULL) 20643a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_IRQ, 206522657ce1SScott Long sc->ciss_irq_rid[0], sc->ciss_irq_resource); 206622657ce1SScott Long if (sc->ciss_msi) 206722657ce1SScott Long pci_release_msi(sc->ciss_dev); 20683284b9eeSPaul Saab 20693284b9eeSPaul Saab while ((cr = ciss_dequeue_free(sc)) != NULL) 20703284b9eeSPaul Saab bus_dmamap_destroy(sc->ciss_buffer_dmat, cr->cr_datamap); 20713a31b7ebSMike Smith if (sc->ciss_buffer_dmat) 20723a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_buffer_dmat); 20733a31b7ebSMike Smith 20743a31b7ebSMike Smith /* destroy command memory and DMA tag */ 20753a31b7ebSMike Smith if (sc->ciss_command != NULL) { 20763a31b7ebSMike Smith bus_dmamap_unload(sc->ciss_command_dmat, sc->ciss_command_map); 20773a31b7ebSMike Smith bus_dmamem_free(sc->ciss_command_dmat, sc->ciss_command, sc->ciss_command_map); 20783a31b7ebSMike Smith } 20793284b9eeSPaul Saab if (sc->ciss_command_dmat) 20803a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_command_dmat); 20813a31b7ebSMike Smith 208222657ce1SScott Long if (sc->ciss_reply) { 208322657ce1SScott Long bus_dmamap_unload(sc->ciss_reply_dmat, sc->ciss_reply_map); 208422657ce1SScott Long bus_dmamem_free(sc->ciss_reply_dmat, sc->ciss_reply, sc->ciss_reply_map); 208522657ce1SScott Long } 208622657ce1SScott Long if (sc->ciss_reply_dmat) 208722657ce1SScott Long bus_dma_tag_destroy(sc->ciss_reply_dmat); 208822657ce1SScott Long 208922657ce1SScott Long /* destroy DMA tags */ 209022657ce1SScott Long if (sc->ciss_parent_dmat) 209122657ce1SScott Long bus_dma_tag_destroy(sc->ciss_parent_dmat); 2092c6131460SPaul Saab if (sc->ciss_logical) { 20935eae46afSConrad Meyer for (i = 0; i < sc->ciss_max_logical_bus; i++) { 2094e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { 2095ee626b40SPaul Saab if (sc->ciss_logical[i][j].cl_ldrive) 2096ee626b40SPaul Saab free(sc->ciss_logical[i][j].cl_ldrive, CISS_MALLOC_CLASS); 2097ee626b40SPaul Saab if (sc->ciss_logical[i][j].cl_lstatus) 2098ee626b40SPaul Saab free(sc->ciss_logical[i][j].cl_lstatus, CISS_MALLOC_CLASS); 2099ee626b40SPaul Saab } 2100c6131460SPaul Saab free(sc->ciss_logical[i], CISS_MALLOC_CLASS); 2101ee626b40SPaul Saab } 2102c6131460SPaul Saab free(sc->ciss_logical, CISS_MALLOC_CLASS); 2103c6131460SPaul Saab } 2104c6131460SPaul Saab 21051fe6c4eeSScott Long if (sc->ciss_physical) { 21061fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_physical_bus; i++) 21071fe6c4eeSScott Long free(sc->ciss_physical[i], CISS_MALLOC_CLASS); 21081fe6c4eeSScott Long free(sc->ciss_physical, CISS_MALLOC_CLASS); 21091fe6c4eeSScott Long } 21101fe6c4eeSScott Long 2111c6131460SPaul Saab if (sc->ciss_controllers) 2112c6131460SPaul Saab free(sc->ciss_controllers, CISS_MALLOC_CLASS); 2113975b7318SScott Long 21143a31b7ebSMike Smith } 21153a31b7ebSMike Smith 21163a31b7ebSMike Smith /************************************************************************ 21173a31b7ebSMike Smith * Give a command to the adapter. 21183a31b7ebSMike Smith * 21193a31b7ebSMike Smith * Note that this uses the simple transport layer directly. If we 21203a31b7ebSMike Smith * want to add support for other layers, we'll need a switch of some 21213a31b7ebSMike Smith * sort. 21223a31b7ebSMike Smith * 21233a31b7ebSMike Smith * Note that the simple transport layer has no way of refusing a 21243a31b7ebSMike Smith * command; we only have as many request structures as the adapter 21253a31b7ebSMike Smith * supports commands, so we don't have to check (this presumes that 21263a31b7ebSMike Smith * the adapter can handle commands as fast as we throw them at it). 21273a31b7ebSMike Smith */ 21283a31b7ebSMike Smith static int 21293a31b7ebSMike Smith ciss_start(struct ciss_request *cr) 21303a31b7ebSMike Smith { 21313a31b7ebSMike Smith int error; 21323a31b7ebSMike Smith 2133fa911920SScott Long debug(2, "post command %d tag %d ", cr->cr_tag, cr->cr_cc->header.host_tag); 21343a31b7ebSMike Smith 21353a31b7ebSMike Smith /* 21363a31b7ebSMike Smith * Map the request's data. 21373a31b7ebSMike Smith */ 21383a31b7ebSMike Smith if ((error = ciss_map_request(cr))) 21393a31b7ebSMike Smith return(error); 21403a31b7ebSMike Smith 21413a31b7ebSMike Smith #if 0 21423a31b7ebSMike Smith ciss_print_request(cr); 21433a31b7ebSMike Smith #endif 21443a31b7ebSMike Smith 21453a31b7ebSMike Smith return(0); 21463a31b7ebSMike Smith } 21473a31b7ebSMike Smith 21483a31b7ebSMike Smith /************************************************************************ 21493a31b7ebSMike Smith * Fetch completed request(s) from the adapter, queue them for 21503a31b7ebSMike Smith * completion handling. 21513a31b7ebSMike Smith * 21523a31b7ebSMike Smith * Note that this uses the simple transport layer directly. If we 21533a31b7ebSMike Smith * want to add support for other layers, we'll need a switch of some 21543a31b7ebSMike Smith * sort. 21553a31b7ebSMike Smith * 21563a31b7ebSMike Smith * Note that the simple transport mechanism does not require any 21573a31b7ebSMike Smith * reentrancy protection; the OPQ read is atomic. If there is a 21583a31b7ebSMike Smith * chance of a race with something else that might move the request 21593a31b7ebSMike Smith * off the busy list, then we will have to lock against that 21603a31b7ebSMike Smith * (eg. timeouts, etc.) 21613a31b7ebSMike Smith */ 21623a31b7ebSMike Smith static void 216322657ce1SScott Long ciss_done(struct ciss_softc *sc, cr_qhead_t *qh) 21643a31b7ebSMike Smith { 21653a31b7ebSMike Smith struct ciss_request *cr; 21663a31b7ebSMike Smith struct ciss_command *cc; 21673a31b7ebSMike Smith u_int32_t tag, index; 21683a31b7ebSMike Smith 21693a31b7ebSMike Smith debug_called(3); 21703a31b7ebSMike Smith 21713a31b7ebSMike Smith /* 21723a31b7ebSMike Smith * Loop quickly taking requests from the adapter and moving them 217322657ce1SScott Long * to the completed queue. 21743a31b7ebSMike Smith */ 21753a31b7ebSMike Smith for (;;) { 21763a31b7ebSMike Smith tag = CISS_TL_SIMPLE_FETCH_CMD(sc); 21773a31b7ebSMike Smith if (tag == CISS_TL_SIMPLE_OPQ_EMPTY) 21783a31b7ebSMike Smith break; 21793a31b7ebSMike Smith index = tag >> 2; 21803a31b7ebSMike Smith debug(2, "completed command %d%s", index, 21813a31b7ebSMike Smith (tag & CISS_HDR_HOST_TAG_ERROR) ? " with error" : ""); 21823a31b7ebSMike Smith if (index >= sc->ciss_max_requests) { 21833a31b7ebSMike Smith ciss_printf(sc, "completed invalid request %d (0x%x)\n", index, tag); 21843a31b7ebSMike Smith continue; 21853a31b7ebSMike Smith } 21863a31b7ebSMike Smith cr = &(sc->ciss_request[index]); 21872fdaa90dSScott Long cc = cr->cr_cc; 21883a31b7ebSMike Smith cc->header.host_tag = tag; /* not updated by adapter */ 218922657ce1SScott Long ciss_enqueue_complete(cr, qh); 21903a31b7ebSMike Smith } 21913a31b7ebSMike Smith 219222657ce1SScott Long } 219322657ce1SScott Long 219422657ce1SScott Long static void 219522657ce1SScott Long ciss_perf_done(struct ciss_softc *sc, cr_qhead_t *qh) 219622657ce1SScott Long { 219722657ce1SScott Long struct ciss_request *cr; 219822657ce1SScott Long struct ciss_command *cc; 219922657ce1SScott Long u_int32_t tag, index; 220022657ce1SScott Long 220122657ce1SScott Long debug_called(3); 220222657ce1SScott Long 22033a31b7ebSMike Smith /* 220422657ce1SScott Long * Loop quickly taking requests from the adapter and moving them 220522657ce1SScott Long * to the completed queue. 22063a31b7ebSMike Smith */ 220722657ce1SScott Long for (;;) { 220822657ce1SScott Long tag = sc->ciss_reply[sc->ciss_rqidx]; 220922657ce1SScott Long if ((tag & CISS_CYCLE_MASK) != sc->ciss_cycle) 221022657ce1SScott Long break; 221122657ce1SScott Long index = tag >> 2; 221222657ce1SScott Long debug(2, "completed command %d%s\n", index, 221322657ce1SScott Long (tag & CISS_HDR_HOST_TAG_ERROR) ? " with error" : ""); 221422657ce1SScott Long if (index < sc->ciss_max_requests) { 221522657ce1SScott Long cr = &(sc->ciss_request[index]); 22162fdaa90dSScott Long cc = cr->cr_cc; 221722657ce1SScott Long cc->header.host_tag = tag; /* not updated by adapter */ 221822657ce1SScott Long ciss_enqueue_complete(cr, qh); 221922657ce1SScott Long } else { 222022657ce1SScott Long ciss_printf(sc, "completed invalid request %d (0x%x)\n", index, tag); 222122657ce1SScott Long } 222222657ce1SScott Long if (++sc->ciss_rqidx == sc->ciss_max_requests) { 222322657ce1SScott Long sc->ciss_rqidx = 0; 222422657ce1SScott Long sc->ciss_cycle ^= 1; 222522657ce1SScott Long } 222622657ce1SScott Long } 222722657ce1SScott Long 22283a31b7ebSMike Smith } 22293a31b7ebSMike Smith 22303a31b7ebSMike Smith /************************************************************************ 22313a31b7ebSMike Smith * Take an interrupt from the adapter. 22323a31b7ebSMike Smith */ 22333a31b7ebSMike Smith static void 22343a31b7ebSMike Smith ciss_intr(void *arg) 22353a31b7ebSMike Smith { 223622657ce1SScott Long cr_qhead_t qh; 22373a31b7ebSMike Smith struct ciss_softc *sc = (struct ciss_softc *)arg; 22383a31b7ebSMike Smith 22393a31b7ebSMike Smith /* 22403a31b7ebSMike Smith * The only interrupt we recognise indicates that there are 22413a31b7ebSMike Smith * entries in the outbound post queue. 22423a31b7ebSMike Smith */ 224322657ce1SScott Long STAILQ_INIT(&qh); 224422657ce1SScott Long ciss_done(sc, &qh); 2245975b7318SScott Long mtx_lock(&sc->ciss_mtx); 224622657ce1SScott Long ciss_complete(sc, &qh); 2247975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 22483a31b7ebSMike Smith } 22493a31b7ebSMike Smith 225022657ce1SScott Long static void 225122657ce1SScott Long ciss_perf_intr(void *arg) 225222657ce1SScott Long { 225322657ce1SScott Long struct ciss_softc *sc = (struct ciss_softc *)arg; 225422657ce1SScott Long 225522657ce1SScott Long /* Clear the interrupt and flush the bridges. Docs say that the flush 225622657ce1SScott Long * needs to be done twice, which doesn't seem right. 225722657ce1SScott Long */ 225822657ce1SScott Long CISS_TL_PERF_CLEAR_INT(sc); 225922657ce1SScott Long CISS_TL_PERF_FLUSH_INT(sc); 226022657ce1SScott Long 226122657ce1SScott Long ciss_perf_msi_intr(sc); 226222657ce1SScott Long } 226322657ce1SScott Long 226422657ce1SScott Long static void 226522657ce1SScott Long ciss_perf_msi_intr(void *arg) 226622657ce1SScott Long { 226722657ce1SScott Long cr_qhead_t qh; 226822657ce1SScott Long struct ciss_softc *sc = (struct ciss_softc *)arg; 226922657ce1SScott Long 227022657ce1SScott Long STAILQ_INIT(&qh); 227122657ce1SScott Long ciss_perf_done(sc, &qh); 227222657ce1SScott Long mtx_lock(&sc->ciss_mtx); 227322657ce1SScott Long ciss_complete(sc, &qh); 227422657ce1SScott Long mtx_unlock(&sc->ciss_mtx); 227522657ce1SScott Long } 227622657ce1SScott Long 22773a31b7ebSMike Smith /************************************************************************ 22783a31b7ebSMike Smith * Process completed requests. 22793a31b7ebSMike Smith * 22803a31b7ebSMike Smith * Requests can be completed in three fashions: 22813a31b7ebSMike Smith * 22823a31b7ebSMike Smith * - by invoking a callback function (cr_complete is non-null) 22833a31b7ebSMike Smith * - by waking up a sleeper (cr_flags has CISS_REQ_SLEEP set) 22843a31b7ebSMike Smith * - by clearing the CISS_REQ_POLL flag in interrupt/timeout context 22853a31b7ebSMike Smith */ 22863a31b7ebSMike Smith static void 228722657ce1SScott Long ciss_complete(struct ciss_softc *sc, cr_qhead_t *qh) 22883a31b7ebSMike Smith { 22893a31b7ebSMike Smith struct ciss_request *cr; 22903a31b7ebSMike Smith 22913a31b7ebSMike Smith debug_called(2); 22923a31b7ebSMike Smith 22933a31b7ebSMike Smith /* 22943a31b7ebSMike Smith * Loop taking requests off the completed queue and performing 22953a31b7ebSMike Smith * completion processing on them. 22963a31b7ebSMike Smith */ 22973a31b7ebSMike Smith for (;;) { 229822657ce1SScott Long if ((cr = ciss_dequeue_complete(sc, qh)) == NULL) 22993a31b7ebSMike Smith break; 23003a31b7ebSMike Smith ciss_unmap_request(cr); 23013a31b7ebSMike Smith 230222657ce1SScott Long if ((cr->cr_flags & CISS_REQ_BUSY) == 0) 230322657ce1SScott Long ciss_printf(sc, "WARNING: completing non-busy request\n"); 230422657ce1SScott Long cr->cr_flags &= ~CISS_REQ_BUSY; 230522657ce1SScott Long 23063a31b7ebSMike Smith /* 23073a31b7ebSMike Smith * If the request has a callback, invoke it. 23083a31b7ebSMike Smith */ 23093a31b7ebSMike Smith if (cr->cr_complete != NULL) { 23103a31b7ebSMike Smith cr->cr_complete(cr); 23113a31b7ebSMike Smith continue; 23123a31b7ebSMike Smith } 23133a31b7ebSMike Smith 23143a31b7ebSMike Smith /* 23153a31b7ebSMike Smith * If someone is sleeping on this request, wake them up. 23163a31b7ebSMike Smith */ 23173a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_SLEEP) { 23183a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_SLEEP; 23193a31b7ebSMike Smith wakeup(cr); 23203a31b7ebSMike Smith continue; 23213a31b7ebSMike Smith } 23223a31b7ebSMike Smith 23233a31b7ebSMike Smith /* 23243a31b7ebSMike Smith * If someone is polling this request for completion, signal. 23253a31b7ebSMike Smith */ 23263a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_POLL) { 23273a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_POLL; 23283a31b7ebSMike Smith continue; 23293a31b7ebSMike Smith } 23303a31b7ebSMike Smith 23313a31b7ebSMike Smith /* 23323a31b7ebSMike Smith * Give up and throw the request back on the free queue. This 23333a31b7ebSMike Smith * should never happen; resources will probably be lost. 23343a31b7ebSMike Smith */ 23353a31b7ebSMike Smith ciss_printf(sc, "WARNING: completed command with no submitter\n"); 23363a31b7ebSMike Smith ciss_enqueue_free(cr); 23373a31b7ebSMike Smith } 23383a31b7ebSMike Smith } 23393a31b7ebSMike Smith 23403a31b7ebSMike Smith /************************************************************************ 23413a31b7ebSMike Smith * Report on the completion status of a request, and pass back SCSI 23423a31b7ebSMike Smith * and command status values. 23433a31b7ebSMike Smith */ 23443a31b7ebSMike Smith static int 234522657ce1SScott Long _ciss_report_request(struct ciss_request *cr, int *command_status, int *scsi_status, const char *func) 23463a31b7ebSMike Smith { 23473a31b7ebSMike Smith struct ciss_command *cc; 23483a31b7ebSMike Smith struct ciss_error_info *ce; 23493a31b7ebSMike Smith 23503a31b7ebSMike Smith debug_called(2); 23513a31b7ebSMike Smith 23522fdaa90dSScott Long cc = cr->cr_cc; 23533a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 23543a31b7ebSMike Smith 23553a31b7ebSMike Smith /* 23563a31b7ebSMike Smith * We don't consider data under/overrun an error for the Report 2357cafc8393SPeter Eriksson * Logical/Physical LUNs, INQUIRY & RECEIVE_DIAGNOSTIC commands. 23583a31b7ebSMike Smith */ 23593a31b7ebSMike Smith if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) && 23602514c5bfSPaul Saab ((ce->command_status == CISS_CMD_STATUS_DATA_OVERRUN) || 23612514c5bfSPaul Saab (ce->command_status == CISS_CMD_STATUS_DATA_UNDERRUN)) && 23623a31b7ebSMike Smith ((cc->cdb.cdb[0] == CISS_OPCODE_REPORT_LOGICAL_LUNS) || 23632514c5bfSPaul Saab (cc->cdb.cdb[0] == CISS_OPCODE_REPORT_PHYSICAL_LUNS) || 2364cafc8393SPeter Eriksson (cc->cdb.cdb[0] == RECEIVE_DIAGNOSTIC) || 23652514c5bfSPaul Saab (cc->cdb.cdb[0] == INQUIRY))) { 23663a31b7ebSMike Smith cc->header.host_tag &= ~CISS_HDR_HOST_TAG_ERROR; 23673a31b7ebSMike Smith debug(2, "ignoring irrelevant under/overrun error"); 23683a31b7ebSMike Smith } 23693a31b7ebSMike Smith 23703a31b7ebSMike Smith /* 23713a31b7ebSMike Smith * Check the command's error bit, if clear, there's no status and 23723a31b7ebSMike Smith * everything is OK. 23733a31b7ebSMike Smith */ 23743a31b7ebSMike Smith if (!(cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR)) { 23753a31b7ebSMike Smith if (scsi_status != NULL) 23763a31b7ebSMike Smith *scsi_status = SCSI_STATUS_OK; 23773a31b7ebSMike Smith if (command_status != NULL) 23783a31b7ebSMike Smith *command_status = CISS_CMD_STATUS_SUCCESS; 23793a31b7ebSMike Smith return(0); 23803a31b7ebSMike Smith } else { 23813a31b7ebSMike Smith if (command_status != NULL) 23823a31b7ebSMike Smith *command_status = ce->command_status; 23833a31b7ebSMike Smith if (scsi_status != NULL) { 2384e8144a13SAlexander Motin if (ce->command_status == CISS_CMD_STATUS_DATA_UNDERRUN) { 2385e8144a13SAlexander Motin *scsi_status = SCSI_STATUS_OK; 2386e8144a13SAlexander Motin } else if (ce->command_status == CISS_CMD_STATUS_TARGET_STATUS) { 23873a31b7ebSMike Smith *scsi_status = ce->scsi_status; 23883a31b7ebSMike Smith } else { 23893a31b7ebSMike Smith *scsi_status = -1; 23903a31b7ebSMike Smith } 23913a31b7ebSMike Smith } 2392d8b02467SPeter Eriksson if ((bootverbose || ciss_verbose > 3 || (ciss_verbose > 2 && ce->scsi_status != 0)) && 2393d8b02467SPeter Eriksson (ce->command_status != CISS_CMD_STATUS_DATA_UNDERRUN)) { 2394d8b02467SPeter Eriksson ciss_printf(cr->cr_sc, "command status 0x%x (%s) scsi status 0x%x (opcode 0x%02x)\n", 23953a31b7ebSMike Smith ce->command_status, ciss_name_command_status(ce->command_status), 2396d8b02467SPeter Eriksson ce->scsi_status, 2397d8b02467SPeter Eriksson cc->cdb.cdb[0]); 2398d8b02467SPeter Eriksson } 23993a31b7ebSMike Smith if (ce->command_status == CISS_CMD_STATUS_INVALID_COMMAND) { 240022657ce1SScott Long ciss_printf(cr->cr_sc, "invalid command, offense size %d at %d, value 0x%x, function %s\n", 24013a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_size, 24023a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_offset, 240322657ce1SScott Long ce->additional_error_info.invalid_command.offense_value, 240422657ce1SScott Long func); 24053a31b7ebSMike Smith } 24063a31b7ebSMike Smith } 2407c6131460SPaul Saab #if 0 2408c6131460SPaul Saab ciss_print_request(cr); 2409c6131460SPaul Saab #endif 24103a31b7ebSMike Smith return(1); 24113a31b7ebSMike Smith } 24123a31b7ebSMike Smith 24133a31b7ebSMike Smith /************************************************************************ 24143a31b7ebSMike Smith * Issue a request and don't return until it's completed. 24153a31b7ebSMike Smith * 24163a31b7ebSMike Smith * Depending on adapter status, we may poll or sleep waiting for 24173a31b7ebSMike Smith * completion. 24183a31b7ebSMike Smith */ 24193a31b7ebSMike Smith static int 24203a31b7ebSMike Smith ciss_synch_request(struct ciss_request *cr, int timeout) 24213a31b7ebSMike Smith { 24223a31b7ebSMike Smith if (cr->cr_sc->ciss_flags & CISS_FLAG_RUNNING) { 24233a31b7ebSMike Smith return(ciss_wait_request(cr, timeout)); 24243a31b7ebSMike Smith } else { 24253a31b7ebSMike Smith return(ciss_poll_request(cr, timeout)); 24263a31b7ebSMike Smith } 24273a31b7ebSMike Smith } 24283a31b7ebSMike Smith 24293a31b7ebSMike Smith /************************************************************************ 24303a31b7ebSMike Smith * Issue a request and poll for completion. 24313a31b7ebSMike Smith * 24323a31b7ebSMike Smith * Timeout in milliseconds. 24333a31b7ebSMike Smith */ 24343a31b7ebSMike Smith static int 24353a31b7ebSMike Smith ciss_poll_request(struct ciss_request *cr, int timeout) 24363a31b7ebSMike Smith { 243722657ce1SScott Long cr_qhead_t qh; 243822657ce1SScott Long struct ciss_softc *sc; 24393a31b7ebSMike Smith int error; 24403a31b7ebSMike Smith 24413a31b7ebSMike Smith debug_called(2); 24423a31b7ebSMike Smith 244322657ce1SScott Long STAILQ_INIT(&qh); 244422657ce1SScott Long sc = cr->cr_sc; 24453a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_POLL; 24463a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) 24473a31b7ebSMike Smith return(error); 24483a31b7ebSMike Smith 24493a31b7ebSMike Smith do { 245022657ce1SScott Long if (sc->ciss_perf) 245122657ce1SScott Long ciss_perf_done(sc, &qh); 245222657ce1SScott Long else 245322657ce1SScott Long ciss_done(sc, &qh); 245422657ce1SScott Long ciss_complete(sc, &qh); 24553a31b7ebSMike Smith if (!(cr->cr_flags & CISS_REQ_POLL)) 24563a31b7ebSMike Smith return(0); 24573a31b7ebSMike Smith DELAY(1000); 24583a31b7ebSMike Smith } while (timeout-- >= 0); 24593a31b7ebSMike Smith return(EWOULDBLOCK); 24603a31b7ebSMike Smith } 24613a31b7ebSMike Smith 24623a31b7ebSMike Smith /************************************************************************ 24633a31b7ebSMike Smith * Issue a request and sleep waiting for completion. 24643a31b7ebSMike Smith * 24653a31b7ebSMike Smith * Timeout in milliseconds. Note that a spurious wakeup will reset 24663a31b7ebSMike Smith * the timeout. 24673a31b7ebSMike Smith */ 24683a31b7ebSMike Smith static int 24693a31b7ebSMike Smith ciss_wait_request(struct ciss_request *cr, int timeout) 24703a31b7ebSMike Smith { 247122657ce1SScott Long int error; 24723a31b7ebSMike Smith 24733a31b7ebSMike Smith debug_called(2); 24743a31b7ebSMike Smith 24753a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_SLEEP; 24763a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) 24773a31b7ebSMike Smith return(error); 24783a31b7ebSMike Smith 247940f05b02SPaul Saab while ((cr->cr_flags & CISS_REQ_SLEEP) && (error != EWOULDBLOCK)) { 248085c9dd9dSSteven Hartland error = msleep_sbt(cr, &cr->cr_sc->ciss_mtx, PRIBIO, "cissREQ", 248185c9dd9dSSteven Hartland SBT_1MS * timeout, 0, 0); 24823a31b7ebSMike Smith } 24833a31b7ebSMike Smith return(error); 24843a31b7ebSMike Smith } 24853a31b7ebSMike Smith 24866197ca15SPeter Wemm #if 0 24873a31b7ebSMike Smith /************************************************************************ 24883a31b7ebSMike Smith * Abort a request. Note that a potential exists here to race the 24893a31b7ebSMike Smith * request being completed; the caller must deal with this. 24903a31b7ebSMike Smith */ 24913a31b7ebSMike Smith static int 24923a31b7ebSMike Smith ciss_abort_request(struct ciss_request *ar) 24933a31b7ebSMike Smith { 24943a31b7ebSMike Smith struct ciss_request *cr; 24953a31b7ebSMike Smith struct ciss_command *cc; 24963a31b7ebSMike Smith struct ciss_message_cdb *cmc; 24973a31b7ebSMike Smith int error; 24983a31b7ebSMike Smith 24993a31b7ebSMike Smith debug_called(1); 25003a31b7ebSMike Smith 25013a31b7ebSMike Smith /* get a request */ 25023a31b7ebSMike Smith if ((error = ciss_get_request(ar->cr_sc, &cr)) != 0) 25033a31b7ebSMike Smith return(error); 25043a31b7ebSMike Smith 25053a31b7ebSMike Smith /* build the abort command */ 25062fdaa90dSScott Long cc = cr->cr_cc; 25073a31b7ebSMike Smith cc->header.address.mode.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; /* addressing? */ 25083a31b7ebSMike Smith cc->header.address.physical.target = 0; 25093a31b7ebSMike Smith cc->header.address.physical.bus = 0; 25103a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cmc); 25113a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_MESSAGE; 25123a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 25133a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_NONE; 25143a31b7ebSMike Smith cc->cdb.timeout = 30; 25153a31b7ebSMike Smith 25163a31b7ebSMike Smith cmc = (struct ciss_message_cdb *)&(cc->cdb.cdb[0]); 25173a31b7ebSMike Smith cmc->opcode = CISS_OPCODE_MESSAGE_ABORT; 25183a31b7ebSMike Smith cmc->type = CISS_MESSAGE_ABORT_TASK; 25193a31b7ebSMike Smith cmc->abort_tag = ar->cr_tag; /* endianness?? */ 25203a31b7ebSMike Smith 25213a31b7ebSMike Smith /* 25223a31b7ebSMike Smith * Send the request and wait for a response. If we believe we 25233a31b7ebSMike Smith * aborted the request OK, clear the flag that indicates it's 25243a31b7ebSMike Smith * running. 25253a31b7ebSMike Smith */ 25263a31b7ebSMike Smith error = ciss_synch_request(cr, 35 * 1000); 25273a31b7ebSMike Smith if (!error) 25283a31b7ebSMike Smith error = ciss_report_request(cr, NULL, NULL); 25293a31b7ebSMike Smith ciss_release_request(cr); 25303a31b7ebSMike Smith 25313a31b7ebSMike Smith return(error); 25323a31b7ebSMike Smith } 25336197ca15SPeter Wemm #endif 25343a31b7ebSMike Smith 25353a31b7ebSMike Smith /************************************************************************ 25363a31b7ebSMike Smith * Fetch and initialise a request 25373a31b7ebSMike Smith */ 25383a31b7ebSMike Smith static int 25393a31b7ebSMike Smith ciss_get_request(struct ciss_softc *sc, struct ciss_request **crp) 25403a31b7ebSMike Smith { 25413a31b7ebSMike Smith struct ciss_request *cr; 25423a31b7ebSMike Smith 25433a31b7ebSMike Smith debug_called(2); 25443a31b7ebSMike Smith 25453a31b7ebSMike Smith /* 25463a31b7ebSMike Smith * Get a request and clean it up. 25473a31b7ebSMike Smith */ 25483a31b7ebSMike Smith if ((cr = ciss_dequeue_free(sc)) == NULL) 25493a31b7ebSMike Smith return(ENOMEM); 25503a31b7ebSMike Smith 25513a31b7ebSMike Smith cr->cr_data = NULL; 25523a31b7ebSMike Smith cr->cr_flags = 0; 25533a31b7ebSMike Smith cr->cr_complete = NULL; 2554639717c8SPaul Saab cr->cr_private = NULL; 255522657ce1SScott Long cr->cr_sg_tag = CISS_SG_MAX; /* Backstop to prevent accidents */ 25563a31b7ebSMike Smith 25573a31b7ebSMike Smith ciss_preen_command(cr); 25583a31b7ebSMike Smith *crp = cr; 25593a31b7ebSMike Smith return(0); 25603a31b7ebSMike Smith } 25613a31b7ebSMike Smith 25623a31b7ebSMike Smith static void 25633a31b7ebSMike Smith ciss_preen_command(struct ciss_request *cr) 25643a31b7ebSMike Smith { 25653a31b7ebSMike Smith struct ciss_command *cc; 25663a31b7ebSMike Smith u_int32_t cmdphys; 25673a31b7ebSMike Smith 25683a31b7ebSMike Smith /* 25693a31b7ebSMike Smith * Clean up the command structure. 25703a31b7ebSMike Smith * 25713a31b7ebSMike Smith * Note that we set up the error_info structure here, since the 25723a31b7ebSMike Smith * length can be overwritten by any command. 25733a31b7ebSMike Smith */ 25742fdaa90dSScott Long cc = cr->cr_cc; 25753a31b7ebSMike Smith cc->header.sg_in_list = 0; /* kinda inefficient this way */ 25763a31b7ebSMike Smith cc->header.sg_total = 0; 25773a31b7ebSMike Smith cc->header.host_tag = cr->cr_tag << 2; 25783a31b7ebSMike Smith cc->header.host_tag_zeroes = 0; 25793d3ddb44SSean Bruno bzero(&(cc->sg[0]), CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)); 25802fdaa90dSScott Long cmdphys = cr->cr_ccphys; 25813a31b7ebSMike Smith cc->error_info.error_info_address = cmdphys + sizeof(struct ciss_command); 25823a31b7ebSMike Smith cc->error_info.error_info_length = CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command); 25833a31b7ebSMike Smith } 25843a31b7ebSMike Smith 25853a31b7ebSMike Smith /************************************************************************ 25863a31b7ebSMike Smith * Release a request to the free list. 25873a31b7ebSMike Smith */ 25883a31b7ebSMike Smith static void 25893a31b7ebSMike Smith ciss_release_request(struct ciss_request *cr) 25903a31b7ebSMike Smith { 25913a31b7ebSMike Smith 25923a31b7ebSMike Smith debug_called(2); 25933a31b7ebSMike Smith 25943a31b7ebSMike Smith /* release the request to the free queue */ 25953a31b7ebSMike Smith ciss_requeue_free(cr); 25963a31b7ebSMike Smith } 25973a31b7ebSMike Smith 25983a31b7ebSMike Smith /************************************************************************ 25993a31b7ebSMike Smith * Allocate a request that will be used to send a BMIC command. Do some 26003a31b7ebSMike Smith * of the common setup here to avoid duplicating it everywhere else. 26013a31b7ebSMike Smith */ 26023a31b7ebSMike Smith static int 26033a31b7ebSMike Smith ciss_get_bmic_request(struct ciss_softc *sc, struct ciss_request **crp, 26043a31b7ebSMike Smith int opcode, void **bufp, size_t bufsize) 26053a31b7ebSMike Smith { 26063a31b7ebSMike Smith struct ciss_request *cr; 26073a31b7ebSMike Smith struct ciss_command *cc; 26083a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 26093a31b7ebSMike Smith void *buf; 26103a31b7ebSMike Smith int error; 26113a31b7ebSMike Smith int dataout; 26123a31b7ebSMike Smith 26133a31b7ebSMike Smith debug_called(2); 26143a31b7ebSMike Smith 26153a31b7ebSMike Smith cr = NULL; 26163a31b7ebSMike Smith buf = NULL; 26173a31b7ebSMike Smith 26183a31b7ebSMike Smith /* 26193a31b7ebSMike Smith * Get a request. 26203a31b7ebSMike Smith */ 26213a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 26223a31b7ebSMike Smith goto out; 26233a31b7ebSMike Smith 26243a31b7ebSMike Smith /* 26253a31b7ebSMike Smith * Allocate data storage if requested, determine the data direction. 26263a31b7ebSMike Smith */ 26273a31b7ebSMike Smith dataout = 0; 26283a31b7ebSMike Smith if ((bufsize > 0) && (bufp != NULL)) { 26293a31b7ebSMike Smith if (*bufp == NULL) { 26303a31b7ebSMike Smith if ((buf = malloc(bufsize, CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 26313a31b7ebSMike Smith error = ENOMEM; 26323a31b7ebSMike Smith goto out; 26333a31b7ebSMike Smith } 26343a31b7ebSMike Smith } else { 26353a31b7ebSMike Smith buf = *bufp; 26363a31b7ebSMike Smith dataout = 1; /* we are given a buffer, so we are writing */ 26373a31b7ebSMike Smith } 26383a31b7ebSMike Smith } 26393a31b7ebSMike Smith 26403a31b7ebSMike Smith /* 26413a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive ID. 26423a31b7ebSMike Smith */ 26433a31b7ebSMike Smith cr->cr_data = buf; 26443a31b7ebSMike Smith cr->cr_length = bufsize; 26453a31b7ebSMike Smith if (!dataout) 26463a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 26473a31b7ebSMike Smith 26482fdaa90dSScott Long cc = cr->cr_cc; 26493a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 26503a31b7ebSMike Smith cc->header.address.physical.bus = 0; 26513a31b7ebSMike Smith cc->header.address.physical.target = 0; 26523a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cbc); 26533a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 26543a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 26553a31b7ebSMike Smith cc->cdb.direction = dataout ? CISS_CDB_DIRECTION_WRITE : CISS_CDB_DIRECTION_READ; 26563a31b7ebSMike Smith cc->cdb.timeout = 0; 26573a31b7ebSMike Smith 26583a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 26593a31b7ebSMike Smith bzero(cbc, sizeof(*cbc)); 26603a31b7ebSMike Smith cbc->opcode = dataout ? CISS_ARRAY_CONTROLLER_WRITE : CISS_ARRAY_CONTROLLER_READ; 26613a31b7ebSMike Smith cbc->bmic_opcode = opcode; 26623a31b7ebSMike Smith cbc->size = htons((u_int16_t)bufsize); 26633a31b7ebSMike Smith 26643a31b7ebSMike Smith out: 26653a31b7ebSMike Smith if (error) { 26663a31b7ebSMike Smith if (cr != NULL) 26673a31b7ebSMike Smith ciss_release_request(cr); 26683a31b7ebSMike Smith } else { 26693a31b7ebSMike Smith *crp = cr; 26703a31b7ebSMike Smith if ((bufp != NULL) && (*bufp == NULL) && (buf != NULL)) 26713a31b7ebSMike Smith *bufp = buf; 26723a31b7ebSMike Smith } 26733a31b7ebSMike Smith return(error); 26743a31b7ebSMike Smith } 26753a31b7ebSMike Smith 26763a31b7ebSMike Smith /************************************************************************ 26773a31b7ebSMike Smith * Handle a command passed in from userspace. 26783a31b7ebSMike Smith */ 26793a31b7ebSMike Smith static int 26803a31b7ebSMike Smith ciss_user_command(struct ciss_softc *sc, IOCTL_Command_struct *ioc) 26813a31b7ebSMike Smith { 26823a31b7ebSMike Smith struct ciss_request *cr; 26833a31b7ebSMike Smith struct ciss_command *cc; 26843a31b7ebSMike Smith struct ciss_error_info *ce; 26853c63a8b4SPaul Saab int error = 0; 26863a31b7ebSMike Smith 26873a31b7ebSMike Smith debug_called(1); 26883a31b7ebSMike Smith 26893a31b7ebSMike Smith cr = NULL; 26903a31b7ebSMike Smith 26913a31b7ebSMike Smith /* 26923a31b7ebSMike Smith * Get a request. 26933a31b7ebSMike Smith */ 2694f83695f5SPaul Saab while (ciss_get_request(sc, &cr) != 0) 2695975b7318SScott Long msleep(sc, &sc->ciss_mtx, PPAUSE, "cissREQ", hz); 26962fdaa90dSScott Long cc = cr->cr_cc; 26973a31b7ebSMike Smith 26983a31b7ebSMike Smith /* 26993a31b7ebSMike Smith * Allocate an in-kernel databuffer if required, copy in user data. 27003a31b7ebSMike Smith */ 2701744c0d23SScott Long mtx_unlock(&sc->ciss_mtx); 27023a31b7ebSMike Smith cr->cr_length = ioc->buf_size; 27033a31b7ebSMike Smith if (ioc->buf_size > 0) { 2704975b7318SScott Long if ((cr->cr_data = malloc(ioc->buf_size, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 27053a31b7ebSMike Smith error = ENOMEM; 2706744c0d23SScott Long goto out_unlocked; 27073a31b7ebSMike Smith } 27083a31b7ebSMike Smith if ((error = copyin(ioc->buf, cr->cr_data, ioc->buf_size))) { 27093a31b7ebSMike Smith debug(0, "copyin: bad data buffer %p/%d", ioc->buf, ioc->buf_size); 2710744c0d23SScott Long goto out_unlocked; 27113a31b7ebSMike Smith } 27123a31b7ebSMike Smith } 27133a31b7ebSMike Smith 27143a31b7ebSMike Smith /* 27153a31b7ebSMike Smith * Build the request based on the user command. 27163a31b7ebSMike Smith */ 27173a31b7ebSMike Smith bcopy(&ioc->LUN_info, &cc->header.address, sizeof(cc->header.address)); 27183a31b7ebSMike Smith bcopy(&ioc->Request, &cc->cdb, sizeof(cc->cdb)); 27193a31b7ebSMike Smith 27203a31b7ebSMike Smith /* XXX anything else to populate here? */ 2721744c0d23SScott Long mtx_lock(&sc->ciss_mtx); 27223a31b7ebSMike Smith 27233a31b7ebSMike Smith /* 27243a31b7ebSMike Smith * Run the command. 27253a31b7ebSMike Smith */ 27263a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000))) { 27273a31b7ebSMike Smith debug(0, "request failed - %d", error); 27283a31b7ebSMike Smith goto out; 27293a31b7ebSMike Smith } 27303a31b7ebSMike Smith 27313a31b7ebSMike Smith /* 27323c63a8b4SPaul Saab * Check to see if the command succeeded. 27333a31b7ebSMike Smith */ 27343a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 27353c6b8353SPaul Saab if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) == 0) 27363c63a8b4SPaul Saab bzero(ce, sizeof(*ce)); 27373c63a8b4SPaul Saab 27383c63a8b4SPaul Saab /* 27393c63a8b4SPaul Saab * Copy the results back to the user. 27403c63a8b4SPaul Saab */ 27413a31b7ebSMike Smith bcopy(ce, &ioc->error_info, sizeof(*ce)); 2742744c0d23SScott Long mtx_unlock(&sc->ciss_mtx); 27433a31b7ebSMike Smith if ((ioc->buf_size > 0) && 27443a31b7ebSMike Smith (error = copyout(cr->cr_data, ioc->buf, ioc->buf_size))) { 27453a31b7ebSMike Smith debug(0, "copyout: bad data buffer %p/%d", ioc->buf, ioc->buf_size); 2746744c0d23SScott Long goto out_unlocked; 27473a31b7ebSMike Smith } 27483a31b7ebSMike Smith 27493a31b7ebSMike Smith /* done OK */ 27503a31b7ebSMike Smith error = 0; 27513a31b7ebSMike Smith 2752744c0d23SScott Long out_unlocked: 2753744c0d23SScott Long mtx_lock(&sc->ciss_mtx); 2754744c0d23SScott Long 27553a31b7ebSMike Smith out: 27563a31b7ebSMike Smith if ((cr != NULL) && (cr->cr_data != NULL)) 27573a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 27583a31b7ebSMike Smith if (cr != NULL) 27593a31b7ebSMike Smith ciss_release_request(cr); 27603a31b7ebSMike Smith return(error); 27613a31b7ebSMike Smith } 27623a31b7ebSMike Smith 27633a31b7ebSMike Smith /************************************************************************ 27643a31b7ebSMike Smith * Map a request into bus-visible space, initialise the scatter/gather 27653a31b7ebSMike Smith * list. 27663a31b7ebSMike Smith */ 27673a31b7ebSMike Smith static int 27683a31b7ebSMike Smith ciss_map_request(struct ciss_request *cr) 27693a31b7ebSMike Smith { 27703a31b7ebSMike Smith struct ciss_softc *sc; 2771639717c8SPaul Saab int error = 0; 27723a31b7ebSMike Smith 27733a31b7ebSMike Smith debug_called(2); 27743a31b7ebSMike Smith 27753a31b7ebSMike Smith sc = cr->cr_sc; 27763a31b7ebSMike Smith 27773a31b7ebSMike Smith /* check that mapping is necessary */ 2778639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_MAPPED) 27793a31b7ebSMike Smith return(0); 27803a31b7ebSMike Smith 27813a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_MAPPED; 2782639717c8SPaul Saab 2783639717c8SPaul Saab bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, 2784639717c8SPaul Saab BUS_DMASYNC_PREWRITE); 2785639717c8SPaul Saab 2786639717c8SPaul Saab if (cr->cr_data != NULL) { 2787dd0b4fb6SKonstantin Belousov if (cr->cr_flags & CISS_REQ_CCB) 2788dd0b4fb6SKonstantin Belousov error = bus_dmamap_load_ccb(sc->ciss_buffer_dmat, 2789dd0b4fb6SKonstantin Belousov cr->cr_datamap, cr->cr_data, 2790dd0b4fb6SKonstantin Belousov ciss_request_map_helper, cr, 0); 2791dd0b4fb6SKonstantin Belousov else 2792639717c8SPaul Saab error = bus_dmamap_load(sc->ciss_buffer_dmat, cr->cr_datamap, 2793639717c8SPaul Saab cr->cr_data, cr->cr_length, 2794639717c8SPaul Saab ciss_request_map_helper, cr, 0); 2795639717c8SPaul Saab if (error != 0) 2796639717c8SPaul Saab return (error); 2797639717c8SPaul Saab } else { 2798639717c8SPaul Saab /* 2799639717c8SPaul Saab * Post the command to the adapter. 2800639717c8SPaul Saab */ 280122657ce1SScott Long cr->cr_sg_tag = CISS_SG_NONE; 280222657ce1SScott Long cr->cr_flags |= CISS_REQ_BUSY; 280322657ce1SScott Long if (sc->ciss_perf) 280422657ce1SScott Long CISS_TL_PERF_POST_CMD(sc, cr); 280522657ce1SScott Long else 28062fdaa90dSScott Long CISS_TL_SIMPLE_POST_CMD(sc, cr->cr_ccphys); 2807639717c8SPaul Saab } 2808639717c8SPaul Saab 28093a31b7ebSMike Smith return(0); 28103a31b7ebSMike Smith } 28113a31b7ebSMike Smith 28123a31b7ebSMike Smith static void 28133a31b7ebSMike Smith ciss_request_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error) 28143a31b7ebSMike Smith { 28153a31b7ebSMike Smith struct ciss_command *cc; 2816639717c8SPaul Saab struct ciss_request *cr; 2817639717c8SPaul Saab struct ciss_softc *sc; 28183a31b7ebSMike Smith int i; 28193a31b7ebSMike Smith 28203a31b7ebSMike Smith debug_called(2); 28213a31b7ebSMike Smith 2822639717c8SPaul Saab cr = (struct ciss_request *)arg; 2823639717c8SPaul Saab sc = cr->cr_sc; 28242fdaa90dSScott Long cc = cr->cr_cc; 2825639717c8SPaul Saab 28263a31b7ebSMike Smith for (i = 0; i < nseg; i++) { 28273a31b7ebSMike Smith cc->sg[i].address = segs[i].ds_addr; 28283a31b7ebSMike Smith cc->sg[i].length = segs[i].ds_len; 28293a31b7ebSMike Smith cc->sg[i].extension = 0; 28303a31b7ebSMike Smith } 28313a31b7ebSMike Smith /* we leave the s/g table entirely within the command */ 28323a31b7ebSMike Smith cc->header.sg_in_list = nseg; 28333a31b7ebSMike Smith cc->header.sg_total = nseg; 2834639717c8SPaul Saab 2835639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_DATAIN) 2836639717c8SPaul Saab bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREREAD); 2837639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_DATAOUT) 2838639717c8SPaul Saab bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREWRITE); 2839639717c8SPaul Saab 284062fdee1dSScott Long if (nseg == 0) 284122657ce1SScott Long cr->cr_sg_tag = CISS_SG_NONE; 284222657ce1SScott Long else if (nseg == 1) 284322657ce1SScott Long cr->cr_sg_tag = CISS_SG_1; 284422657ce1SScott Long else if (nseg == 2) 284522657ce1SScott Long cr->cr_sg_tag = CISS_SG_2; 284622657ce1SScott Long else if (nseg <= 4) 284722657ce1SScott Long cr->cr_sg_tag = CISS_SG_4; 284822657ce1SScott Long else if (nseg <= 8) 284922657ce1SScott Long cr->cr_sg_tag = CISS_SG_8; 285022657ce1SScott Long else if (nseg <= 16) 285122657ce1SScott Long cr->cr_sg_tag = CISS_SG_16; 285222657ce1SScott Long else if (nseg <= 32) 285322657ce1SScott Long cr->cr_sg_tag = CISS_SG_32; 285422657ce1SScott Long else 285522657ce1SScott Long cr->cr_sg_tag = CISS_SG_MAX; 285622657ce1SScott Long 2857639717c8SPaul Saab /* 2858639717c8SPaul Saab * Post the command to the adapter. 2859639717c8SPaul Saab */ 286022657ce1SScott Long cr->cr_flags |= CISS_REQ_BUSY; 286122657ce1SScott Long if (sc->ciss_perf) 286222657ce1SScott Long CISS_TL_PERF_POST_CMD(sc, cr); 286322657ce1SScott Long else 28642fdaa90dSScott Long CISS_TL_SIMPLE_POST_CMD(sc, cr->cr_ccphys); 28653a31b7ebSMike Smith } 28663a31b7ebSMike Smith 28673a31b7ebSMike Smith /************************************************************************ 28683a31b7ebSMike Smith * Unmap a request from bus-visible space. 28693a31b7ebSMike Smith */ 28703a31b7ebSMike Smith static void 28713a31b7ebSMike Smith ciss_unmap_request(struct ciss_request *cr) 28723a31b7ebSMike Smith { 28733a31b7ebSMike Smith struct ciss_softc *sc; 28743a31b7ebSMike Smith 28753a31b7ebSMike Smith debug_called(2); 28763a31b7ebSMike Smith 28773a31b7ebSMike Smith sc = cr->cr_sc; 28783a31b7ebSMike Smith 28793a31b7ebSMike Smith /* check that unmapping is necessary */ 2880639717c8SPaul Saab if ((cr->cr_flags & CISS_REQ_MAPPED) == 0) 28813a31b7ebSMike Smith return; 28823a31b7ebSMike Smith 2883639717c8SPaul Saab bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, 2884639717c8SPaul Saab BUS_DMASYNC_POSTWRITE); 2885639717c8SPaul Saab 2886639717c8SPaul Saab if (cr->cr_data == NULL) 2887639717c8SPaul Saab goto out; 2888639717c8SPaul Saab 28893a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_DATAIN) 28903a31b7ebSMike Smith bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTREAD); 28913a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_DATAOUT) 28923a31b7ebSMike Smith bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTWRITE); 28933a31b7ebSMike Smith 28943a31b7ebSMike Smith bus_dmamap_unload(sc->ciss_buffer_dmat, cr->cr_datamap); 2895639717c8SPaul Saab out: 28963a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_MAPPED; 28973a31b7ebSMike Smith } 28983a31b7ebSMike Smith 28993a31b7ebSMike Smith /************************************************************************ 29003a31b7ebSMike Smith * Attach the driver to CAM. 29013a31b7ebSMike Smith * 29023a31b7ebSMike Smith * We put all the logical drives on a single SCSI bus. 29033a31b7ebSMike Smith */ 29043a31b7ebSMike Smith static int 29053a31b7ebSMike Smith ciss_cam_init(struct ciss_softc *sc) 29063a31b7ebSMike Smith { 29071fe6c4eeSScott Long int i, maxbus; 29083a31b7ebSMike Smith 29093a31b7ebSMike Smith debug_called(1); 29103a31b7ebSMike Smith 29113a31b7ebSMike Smith /* 29123a31b7ebSMike Smith * Allocate a devq. We can reuse this for the masked physical 29133a31b7ebSMike Smith * devices if we decide to export these as well. 29143a31b7ebSMike Smith */ 291595dab4f2SAlexander Motin if ((sc->ciss_cam_devq = cam_simq_alloc(sc->ciss_max_requests - 2)) == NULL) { 29163a31b7ebSMike Smith ciss_printf(sc, "can't allocate CAM SIM queue\n"); 29173a31b7ebSMike Smith return(ENOMEM); 29183a31b7ebSMike Smith } 29193a31b7ebSMike Smith 29203a31b7ebSMike Smith /* 29213a31b7ebSMike Smith * Create a SIM. 29221fe6c4eeSScott Long * 29231fe6c4eeSScott Long * This naturally wastes a bit of memory. The alternative is to allocate 29241fe6c4eeSScott Long * and register each bus as it is found, and then track them on a linked 29251fe6c4eeSScott Long * list. Unfortunately, the driver has a few places where it needs to 29261fe6c4eeSScott Long * look up the SIM based solely on bus number, and it's unclear whether 29271fe6c4eeSScott Long * a list traversal would work for these situations. 29283a31b7ebSMike Smith */ 29291fe6c4eeSScott Long maxbus = max(sc->ciss_max_logical_bus, sc->ciss_max_physical_bus + 29301fe6c4eeSScott Long CISS_PHYSICAL_BASE); 2931ac2fffa4SPedro F. Giffuni sc->ciss_cam_sim = malloc(maxbus * sizeof(struct cam_sim*), 2932c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 2933c6131460SPaul Saab if (sc->ciss_cam_sim == NULL) { 2934c6131460SPaul Saab ciss_printf(sc, "can't allocate memory for controller SIM\n"); 2935c6131460SPaul Saab return(ENOMEM); 2936c6131460SPaul Saab } 2937c6131460SPaul Saab 29381fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 2939c6131460SPaul Saab if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, 2940c6131460SPaul Saab "ciss", sc, 29412aa6b972SPaul Saab device_get_unit(sc->ciss_dev), 294245650f52SScott Long &sc->ciss_mtx, 294322657ce1SScott Long 2, 2944d4aa427fSPaul Saab sc->ciss_max_requests - 2, 29453a31b7ebSMike Smith sc->ciss_cam_devq)) == NULL) { 2946c6131460SPaul Saab ciss_printf(sc, "can't allocate CAM SIM for controller %d\n", i); 29473a31b7ebSMike Smith return(ENOMEM); 29483a31b7ebSMike Smith } 29493a31b7ebSMike Smith 29503a31b7ebSMike Smith /* 2951c6131460SPaul Saab * Register bus with this SIM. 29523a31b7ebSMike Smith */ 2953975b7318SScott Long mtx_lock(&sc->ciss_mtx); 29541fe6c4eeSScott Long if (i == 0 || sc->ciss_controllers[i].physical.bus != 0) { 2955b50569b7SScott Long if (xpt_bus_register(sc->ciss_cam_sim[i], sc->ciss_dev, i) != 0) { 29561fe6c4eeSScott Long ciss_printf(sc, "can't register SCSI bus %d\n", i); 2957975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 29581fe6c4eeSScott Long return (ENXIO); 29591fe6c4eeSScott Long } 29601fe6c4eeSScott Long } 2961975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 29621fe6c4eeSScott Long } 29631fe6c4eeSScott Long 29641fe6c4eeSScott Long for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 29651fe6c4eeSScott Long CISS_PHYSICAL_BASE; i++) { 29661fe6c4eeSScott Long if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, 29671fe6c4eeSScott Long "ciss", sc, 29681fe6c4eeSScott Long device_get_unit(sc->ciss_dev), 2969975b7318SScott Long &sc->ciss_mtx, 1, 29701fe6c4eeSScott Long sc->ciss_max_requests - 2, 29711fe6c4eeSScott Long sc->ciss_cam_devq)) == NULL) { 29721fe6c4eeSScott Long ciss_printf(sc, "can't allocate CAM SIM for controller %d\n", i); 29731fe6c4eeSScott Long return (ENOMEM); 29741fe6c4eeSScott Long } 29751fe6c4eeSScott Long 2976975b7318SScott Long mtx_lock(&sc->ciss_mtx); 2977b50569b7SScott Long if (xpt_bus_register(sc->ciss_cam_sim[i], sc->ciss_dev, i) != 0) { 2978c6131460SPaul Saab ciss_printf(sc, "can't register SCSI bus %d\n", i); 2979975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 29803a31b7ebSMike Smith return (ENXIO); 29813a31b7ebSMike Smith } 2982975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 2983c6131460SPaul Saab } 29843a31b7ebSMike Smith 29853a31b7ebSMike Smith return(0); 29863a31b7ebSMike Smith } 29873a31b7ebSMike Smith 29883a31b7ebSMike Smith /************************************************************************ 29893a31b7ebSMike Smith * Initiate a rescan of the 'logical devices' SIM 29903a31b7ebSMike Smith */ 29913a31b7ebSMike Smith static void 2992c6131460SPaul Saab ciss_cam_rescan_target(struct ciss_softc *sc, int bus, int target) 29933a31b7ebSMike Smith { 29943a31b7ebSMike Smith union ccb *ccb; 29953a31b7ebSMike Smith 29963a31b7ebSMike Smith debug_called(1); 29973a31b7ebSMike Smith 299883c5d981SAlexander Motin if ((ccb = xpt_alloc_ccb_nowait()) == NULL) { 29993a31b7ebSMike Smith ciss_printf(sc, "rescan failed (can't allocate CCB)\n"); 30003a31b7ebSMike Smith return; 30013a31b7ebSMike Smith } 30023a31b7ebSMike Smith 3003e5dfa058SAlexander Motin if (xpt_create_path(&ccb->ccb_h.path, NULL, 300483c5d981SAlexander Motin cam_sim_path(sc->ciss_cam_sim[bus]), 3005c6131460SPaul Saab target, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 30063a31b7ebSMike Smith ciss_printf(sc, "rescan failed (can't create path)\n"); 300783c5d981SAlexander Motin xpt_free_ccb(ccb); 30083a31b7ebSMike Smith return; 30093a31b7ebSMike Smith } 301083c5d981SAlexander Motin xpt_rescan(ccb); 30113a31b7ebSMike Smith /* scan is now in progress */ 30123a31b7ebSMike Smith } 30133a31b7ebSMike Smith 30143a31b7ebSMike Smith /************************************************************************ 30153a31b7ebSMike Smith * Handle requests coming from CAM 30163a31b7ebSMike Smith */ 30173a31b7ebSMike Smith static void 30183a31b7ebSMike Smith ciss_cam_action(struct cam_sim *sim, union ccb *ccb) 30193a31b7ebSMike Smith { 3020440baa08SPaul Saab struct ciss_softc *sc; 3021440baa08SPaul Saab struct ccb_scsiio *csio; 3022c6131460SPaul Saab int bus, target; 30231fe6c4eeSScott Long int physical; 3024440baa08SPaul Saab 3025440baa08SPaul Saab sc = cam_sim_softc(sim); 3026c6131460SPaul Saab bus = cam_sim_bus(sim); 3027440baa08SPaul Saab csio = (struct ccb_scsiio *)&ccb->csio; 3028440baa08SPaul Saab target = csio->ccb_h.target_id; 30291fe6c4eeSScott Long physical = CISS_IS_PHYSICAL(bus); 3030440baa08SPaul Saab 30313a31b7ebSMike Smith switch (ccb->ccb_h.func_code) { 30323a31b7ebSMike Smith /* perform SCSI I/O */ 30333a31b7ebSMike Smith case XPT_SCSI_IO: 3034440baa08SPaul Saab if (!ciss_cam_action_io(sim, csio)) 30353a31b7ebSMike Smith return; 30363a31b7ebSMike Smith break; 30373a31b7ebSMike Smith 30383a31b7ebSMike Smith /* perform geometry calculations */ 30393a31b7ebSMike Smith case XPT_CALC_GEOMETRY: 30403a31b7ebSMike Smith { 30413a31b7ebSMike Smith struct ccb_calc_geometry *ccg = &ccb->ccg; 30421fe6c4eeSScott Long struct ciss_ldrive *ld; 30433a31b7ebSMike Smith 30443a31b7ebSMike Smith debug(1, "XPT_CALC_GEOMETRY %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 30453a31b7ebSMike Smith 30461fe6c4eeSScott Long ld = NULL; 30471fe6c4eeSScott Long if (!physical) 30481fe6c4eeSScott Long ld = &sc->ciss_logical[bus][target]; 30491fe6c4eeSScott Long 30503a31b7ebSMike Smith /* 3051440baa08SPaul Saab * Use the cached geometry settings unless the fault tolerance 3052440baa08SPaul Saab * is invalid. 30533a31b7ebSMike Smith */ 30541fe6c4eeSScott Long if (physical || ld->cl_geometry.fault_tolerance == 0xFF) { 3055440baa08SPaul Saab u_int32_t secs_per_cylinder; 3056440baa08SPaul Saab 30573a31b7ebSMike Smith ccg->heads = 255; 30583a31b7ebSMike Smith ccg->secs_per_track = 32; 30593a31b7ebSMike Smith secs_per_cylinder = ccg->heads * ccg->secs_per_track; 30603a31b7ebSMike Smith ccg->cylinders = ccg->volume_size / secs_per_cylinder; 3061440baa08SPaul Saab } else { 3062440baa08SPaul Saab ccg->heads = ld->cl_geometry.heads; 3063440baa08SPaul Saab ccg->secs_per_track = ld->cl_geometry.sectors; 3064440baa08SPaul Saab ccg->cylinders = ntohs(ld->cl_geometry.cylinders); 3065440baa08SPaul Saab } 30663a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_CMP; 30673a31b7ebSMike Smith break; 30683a31b7ebSMike Smith } 30693a31b7ebSMike Smith 30703a31b7ebSMike Smith /* handle path attribute inquiry */ 30713a31b7ebSMike Smith case XPT_PATH_INQ: 30723a31b7ebSMike Smith { 30733a31b7ebSMike Smith struct ccb_pathinq *cpi = &ccb->cpi; 3074bdde5705SSean Bruno int sg_length; 30753a31b7ebSMike Smith 30763a31b7ebSMike Smith debug(1, "XPT_PATH_INQ %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 30773a31b7ebSMike Smith 30783a31b7ebSMike Smith cpi->version_num = 1; 30793a31b7ebSMike Smith cpi->hba_inquiry = PI_TAG_ABLE; /* XXX is this correct? */ 30803a31b7ebSMike Smith cpi->target_sprt = 0; 30813a31b7ebSMike Smith cpi->hba_misc = 0; 308245645518SPeter Eriksson cpi->max_target = MAX(sc->ciss_max_physical_target, sc->ciss_cfg->max_logical_supported); 30833a31b7ebSMike Smith cpi->max_lun = 0; /* 'logical drive' channel only */ 3084*fd95966aSPeter Eriksson if (ciss_initiator_id != CAM_TARGET_WILDCARD) 3085*fd95966aSPeter Eriksson cpi->initiator_id = ciss_initiator_id; 3086*fd95966aSPeter Eriksson else 3087e3edca22SSean Bruno cpi->initiator_id = sc->ciss_cfg->max_logical_supported; 30884195c7deSAlan Somers strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 30894195c7deSAlan Somers strlcpy(cpi->hba_vid, "CISS", HBA_IDLEN); 30904195c7deSAlan Somers strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 30913a31b7ebSMike Smith cpi->unit_number = cam_sim_unit(sim); 30923a31b7ebSMike Smith cpi->bus_id = cam_sim_bus(sim); 309374575d14SPeter Eriksson cpi->base_transfer_speed = ciss_base_transfer_speed; 3094fa9ed865SMatt Jacob cpi->transport = XPORT_SPI; 3095fa9ed865SMatt Jacob cpi->transport_version = 2; 3096fa9ed865SMatt Jacob cpi->protocol = PROTO_SCSI; 3097fa9ed865SMatt Jacob cpi->protocol_version = SCSI_REV_2; 3098bdde5705SSean Bruno if (sc->ciss_cfg->max_sg_length == 0) { 3099e8e4cdbaSSean Bruno sg_length = 17; 3100bdde5705SSean Bruno } else { 3101bdde5705SSean Bruno /* XXX Fix for ZMR cards that advertise max_sg_length == 32 3102bdde5705SSean Bruno * Confusing bit here. max_sg_length is usually a power of 2. We always 3103bdde5705SSean Bruno * need to subtract 1 to account for partial pages. Then we need to 3104bdde5705SSean Bruno * align on a valid PAGE_SIZE so we round down to the nearest power of 2. 3105bdde5705SSean Bruno * Add 1 so we can then subtract it out in the assignment to maxio. 3106bdde5705SSean Bruno * The reason for all these shenanigans is to create a maxio value that 3107bdde5705SSean Bruno * creates IO operations to volumes that yield consistent operations 3108bdde5705SSean Bruno * with good performance. 3109bdde5705SSean Bruno */ 3110bdde5705SSean Bruno sg_length = sc->ciss_cfg->max_sg_length - 1; 3111bdde5705SSean Bruno sg_length = (1 << (fls(sg_length) - 1)) + 1; 3112bdde5705SSean Bruno } 3113bdde5705SSean Bruno cpi->maxio = (min(CISS_MAX_SG_ELEMENTS, sg_length) - 1) * PAGE_SIZE; 31143a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_CMP; 31153a31b7ebSMike Smith break; 31163a31b7ebSMike Smith } 31173a31b7ebSMike Smith 31183a31b7ebSMike Smith case XPT_GET_TRAN_SETTINGS: 31193a31b7ebSMike Smith { 31203a31b7ebSMike Smith struct ccb_trans_settings *cts = &ccb->cts; 312163b9228bSScott Long struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi; 312263b9228bSScott Long struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi; 31233a31b7ebSMike Smith 3124fa911920SScott Long debug(1, "XPT_GET_TRAN_SETTINGS %d:%d", cam_sim_bus(sim), 3125fa911920SScott Long ctl->ccb_h.target_id); 31263a31b7ebSMike Smith /* disconnect always OK */ 3127fa9ed865SMatt Jacob cts->protocol = PROTO_SCSI; 3128fa9ed865SMatt Jacob cts->protocol_version = SCSI_REV_2; 3129fa9ed865SMatt Jacob cts->transport = XPORT_SPI; 3130fa9ed865SMatt Jacob cts->transport_version = 2; 3131fa9ed865SMatt Jacob 3132fa9ed865SMatt Jacob spi->valid = CTS_SPI_VALID_DISC; 3133fa9ed865SMatt Jacob spi->flags = CTS_SPI_FLAGS_DISC_ENB; 31343a31b7ebSMike Smith 313563b9228bSScott Long scsi->valid = CTS_SCSI_VALID_TQ; 313663b9228bSScott Long scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; 313763b9228bSScott Long 31383a31b7ebSMike Smith cts->ccb_h.status = CAM_REQ_CMP; 31393a31b7ebSMike Smith break; 31403a31b7ebSMike Smith } 31413a31b7ebSMike Smith 31423a31b7ebSMike Smith default: /* we can't do this */ 31433a31b7ebSMike Smith debug(1, "unspported func_code = 0x%x", ccb->ccb_h.func_code); 31443a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_INVALID; 31453a31b7ebSMike Smith break; 31463a31b7ebSMike Smith } 31473a31b7ebSMike Smith 31483a31b7ebSMike Smith xpt_done(ccb); 31493a31b7ebSMike Smith } 31503a31b7ebSMike Smith 31513a31b7ebSMike Smith /************************************************************************ 31523a31b7ebSMike Smith * Handle a CAM SCSI I/O request. 31533a31b7ebSMike Smith */ 31543a31b7ebSMike Smith static int 31553a31b7ebSMike Smith ciss_cam_action_io(struct cam_sim *sim, struct ccb_scsiio *csio) 31563a31b7ebSMike Smith { 31573a31b7ebSMike Smith struct ciss_softc *sc; 31583a31b7ebSMike Smith int bus, target; 31593a31b7ebSMike Smith struct ciss_request *cr; 31603a31b7ebSMike Smith struct ciss_command *cc; 31613a31b7ebSMike Smith int error; 31623a31b7ebSMike Smith 31633a31b7ebSMike Smith sc = cam_sim_softc(sim); 31643a31b7ebSMike Smith bus = cam_sim_bus(sim); 31653a31b7ebSMike Smith target = csio->ccb_h.target_id; 31663a31b7ebSMike Smith 31673a31b7ebSMike Smith debug(2, "XPT_SCSI_IO %d:%d:%d", bus, target, csio->ccb_h.target_lun); 31683a31b7ebSMike Smith 31693a31b7ebSMike Smith /* check that the CDB pointer is not to a physical address */ 31703a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_CDB_POINTER) && (csio->ccb_h.flags & CAM_CDB_PHYS)) { 31713a31b7ebSMike Smith debug(3, " CDB pointer is to physical address"); 31723a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 31733a31b7ebSMike Smith } 31743a31b7ebSMike Smith 31753a31b7ebSMike Smith /* abandon aborted ccbs or those that have failed validation */ 31763a31b7ebSMike Smith if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) { 31773a31b7ebSMike Smith debug(3, "abandoning CCB due to abort/validation failure"); 31783a31b7ebSMike Smith return(EINVAL); 31793a31b7ebSMike Smith } 31803a31b7ebSMike Smith 31813a31b7ebSMike Smith /* handle emulation of some SCSI commands ourself */ 31823a31b7ebSMike Smith if (ciss_cam_emulate(sc, csio)) 31833a31b7ebSMike Smith return(0); 31843a31b7ebSMike Smith 31853a31b7ebSMike Smith /* 31863a31b7ebSMike Smith * Get a request to manage this command. If we can't, return the 31873a31b7ebSMike Smith * ccb, freeze the queue and flag so that we unfreeze it when a 31883a31b7ebSMike Smith * request completes. 31893a31b7ebSMike Smith */ 31903a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) { 31911fe6c4eeSScott Long xpt_freeze_simq(sim, 1); 319295dab4f2SAlexander Motin sc->ciss_flags |= CISS_FLAG_BUSY; 31933a31b7ebSMike Smith csio->ccb_h.status |= CAM_REQUEUE_REQ; 31943a31b7ebSMike Smith return(error); 31953a31b7ebSMike Smith } 31963a31b7ebSMike Smith 31973a31b7ebSMike Smith /* 31983a31b7ebSMike Smith * Build the command. 31993a31b7ebSMike Smith */ 32002fdaa90dSScott Long cc = cr->cr_cc; 3201dd0b4fb6SKonstantin Belousov cr->cr_data = csio; 32023a31b7ebSMike Smith cr->cr_length = csio->dxfer_len; 32033a31b7ebSMike Smith cr->cr_complete = ciss_cam_complete; 32043a31b7ebSMike Smith cr->cr_private = csio; 32053a31b7ebSMike Smith 3206c6131460SPaul Saab /* 3207c6131460SPaul Saab * Target the right logical volume. 3208c6131460SPaul Saab */ 32091fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) 32101fe6c4eeSScott Long cc->header.address = 32111fe6c4eeSScott Long sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_address; 32121fe6c4eeSScott Long else 32131fe6c4eeSScott Long cc->header.address = 32141fe6c4eeSScott Long sc->ciss_logical[bus][target].cl_address; 32153a31b7ebSMike Smith cc->cdb.cdb_length = csio->cdb_len; 32163a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 32173a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; /* XXX ordered tags? */ 32183a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) { 3219dd0b4fb6SKonstantin Belousov cr->cr_flags = CISS_REQ_DATAOUT | CISS_REQ_CCB; 32203a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; 32213a31b7ebSMike Smith } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 3222dd0b4fb6SKonstantin Belousov cr->cr_flags = CISS_REQ_DATAIN | CISS_REQ_CCB; 32233a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 32243a31b7ebSMike Smith } else { 3225dd0b4fb6SKonstantin Belousov cr->cr_data = NULL; 32263a31b7ebSMike Smith cr->cr_flags = 0; 32273a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_NONE; 32283a31b7ebSMike Smith } 32293a31b7ebSMike Smith cc->cdb.timeout = (csio->ccb_h.timeout / 1000) + 1; 32303a31b7ebSMike Smith if (csio->ccb_h.flags & CAM_CDB_POINTER) { 32313a31b7ebSMike Smith bcopy(csio->cdb_io.cdb_ptr, &cc->cdb.cdb[0], csio->cdb_len); 32323a31b7ebSMike Smith } else { 32333a31b7ebSMike Smith bcopy(csio->cdb_io.cdb_bytes, &cc->cdb.cdb[0], csio->cdb_len); 32343a31b7ebSMike Smith } 32353a31b7ebSMike Smith 32363a31b7ebSMike Smith /* 32373a31b7ebSMike Smith * Submit the request to the adapter. 32383a31b7ebSMike Smith * 32393a31b7ebSMike Smith * Note that this may fail if we're unable to map the request (and 32403a31b7ebSMike Smith * if we ever learn a transport layer other than simple, may fail 32413a31b7ebSMike Smith * if the adapter rejects the command). 32423a31b7ebSMike Smith */ 32433a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) { 32441fe6c4eeSScott Long xpt_freeze_simq(sim, 1); 3245639717c8SPaul Saab csio->ccb_h.status |= CAM_RELEASE_SIMQ; 32460a65b79fSAlexander Motin if (error == EINPROGRESS) { 3247639717c8SPaul Saab error = 0; 3248639717c8SPaul Saab } else { 32493a31b7ebSMike Smith csio->ccb_h.status |= CAM_REQUEUE_REQ; 32503a31b7ebSMike Smith ciss_release_request(cr); 3251639717c8SPaul Saab } 32523a31b7ebSMike Smith return(error); 32533a31b7ebSMike Smith } 32543a31b7ebSMike Smith 32553a31b7ebSMike Smith return(0); 32563a31b7ebSMike Smith } 32573a31b7ebSMike Smith 32583a31b7ebSMike Smith /************************************************************************ 32593a31b7ebSMike Smith * Emulate SCSI commands the adapter doesn't handle as we might like. 32603a31b7ebSMike Smith */ 32613a31b7ebSMike Smith static int 32623a31b7ebSMike Smith ciss_cam_emulate(struct ciss_softc *sc, struct ccb_scsiio *csio) 32633a31b7ebSMike Smith { 3264c6131460SPaul Saab int bus, target; 32653a31b7ebSMike Smith u_int8_t opcode; 32663a31b7ebSMike Smith 32673a31b7ebSMike Smith target = csio->ccb_h.target_id; 3268c6131460SPaul Saab bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); 32693a31b7ebSMike Smith opcode = (csio->ccb_h.flags & CAM_CDB_POINTER) ? 32703a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]; 32713a31b7ebSMike Smith 32721fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) { 32731fe6c4eeSScott Long if (sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_online != 1) { 32740a65b79fSAlexander Motin csio->ccb_h.status |= CAM_SEL_TIMEOUT; 32751fe6c4eeSScott Long xpt_done((union ccb *)csio); 32761fe6c4eeSScott Long return(1); 32771fe6c4eeSScott Long } else 32781fe6c4eeSScott Long return(0); 32791fe6c4eeSScott Long } 32801fe6c4eeSScott Long 32813a31b7ebSMike Smith /* 32826f71a953SPaul Saab * Handle requests for volumes that don't exist or are not online. 32836f71a953SPaul Saab * A selection timeout is slightly better than an illegal request. 32846f71a953SPaul Saab * Other errors might be better. 32853a31b7ebSMike Smith */ 32866f71a953SPaul Saab if (sc->ciss_logical[bus][target].cl_status != CISS_LD_ONLINE) { 32870a65b79fSAlexander Motin csio->ccb_h.status |= CAM_SEL_TIMEOUT; 32883a31b7ebSMike Smith xpt_done((union ccb *)csio); 32893a31b7ebSMike Smith return(1); 32903a31b7ebSMike Smith } 32913a31b7ebSMike Smith 32923a31b7ebSMike Smith /* if we have to fake Synchronise Cache */ 32933a31b7ebSMike Smith if (sc->ciss_flags & CISS_FLAG_FAKE_SYNCH) { 32943a31b7ebSMike Smith /* 32953a31b7ebSMike Smith * If this is a Synchronise Cache command, typically issued when 32963a31b7ebSMike Smith * a device is closed, flush the adapter and complete now. 32973a31b7ebSMike Smith */ 32983a31b7ebSMike Smith if (((csio->ccb_h.flags & CAM_CDB_POINTER) ? 32993a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) { 33003a31b7ebSMike Smith ciss_flush_adapter(sc); 33010a65b79fSAlexander Motin csio->ccb_h.status |= CAM_REQ_CMP; 33023a31b7ebSMike Smith xpt_done((union ccb *)csio); 33033a31b7ebSMike Smith return(1); 33043a31b7ebSMike Smith } 33053a31b7ebSMike Smith } 33063a31b7ebSMike Smith 3307a1abcc4fSSean Bruno /* 3308a1abcc4fSSean Bruno * A CISS target can only ever have one lun per target. REPORT_LUNS requires 3309a1abcc4fSSean Bruno * at least one LUN field to be pre created for us, so snag it and fill in 3310a1abcc4fSSean Bruno * the least significant byte indicating 1 LUN here. Emulate the command 3311a1abcc4fSSean Bruno * return to shut up warning on console of a CDB error. swb 3312a1abcc4fSSean Bruno */ 3313a1abcc4fSSean Bruno if (opcode == REPORT_LUNS && csio->dxfer_len > 0) { 3314a1abcc4fSSean Bruno csio->data_ptr[3] = 8; 3315a1abcc4fSSean Bruno csio->ccb_h.status |= CAM_REQ_CMP; 3316a1abcc4fSSean Bruno xpt_done((union ccb *)csio); 3317a1abcc4fSSean Bruno return(1); 3318a1abcc4fSSean Bruno } 3319a1abcc4fSSean Bruno 33203a31b7ebSMike Smith return(0); 33213a31b7ebSMike Smith } 33223a31b7ebSMike Smith 33233a31b7ebSMike Smith /************************************************************************ 33243a31b7ebSMike Smith * Check for possibly-completed commands. 33253a31b7ebSMike Smith */ 33263a31b7ebSMike Smith static void 33273a31b7ebSMike Smith ciss_cam_poll(struct cam_sim *sim) 33283a31b7ebSMike Smith { 332922657ce1SScott Long cr_qhead_t qh; 33303a31b7ebSMike Smith struct ciss_softc *sc = cam_sim_softc(sim); 33313a31b7ebSMike Smith 33323a31b7ebSMike Smith debug_called(2); 33333a31b7ebSMike Smith 333422657ce1SScott Long STAILQ_INIT(&qh); 333522657ce1SScott Long if (sc->ciss_perf) 333622657ce1SScott Long ciss_perf_done(sc, &qh); 333722657ce1SScott Long else 333822657ce1SScott Long ciss_done(sc, &qh); 333922657ce1SScott Long ciss_complete(sc, &qh); 33403a31b7ebSMike Smith } 33413a31b7ebSMike Smith 33423a31b7ebSMike Smith /************************************************************************ 33433a31b7ebSMike Smith * Handle completion of a command - pass results back through the CCB 33443a31b7ebSMike Smith */ 33453a31b7ebSMike Smith static void 33463a31b7ebSMike Smith ciss_cam_complete(struct ciss_request *cr) 33473a31b7ebSMike Smith { 33483a31b7ebSMike Smith struct ciss_softc *sc; 33493a31b7ebSMike Smith struct ciss_command *cc; 33503a31b7ebSMike Smith struct ciss_error_info *ce; 33513a31b7ebSMike Smith struct ccb_scsiio *csio; 33523a31b7ebSMike Smith int scsi_status; 33533a31b7ebSMike Smith int command_status; 33543a31b7ebSMike Smith 33553a31b7ebSMike Smith debug_called(2); 33563a31b7ebSMike Smith 33573a31b7ebSMike Smith sc = cr->cr_sc; 33582fdaa90dSScott Long cc = cr->cr_cc; 33593a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 33603a31b7ebSMike Smith csio = (struct ccb_scsiio *)cr->cr_private; 33613a31b7ebSMike Smith 33623a31b7ebSMike Smith /* 33633a31b7ebSMike Smith * Extract status values from request. 33643a31b7ebSMike Smith */ 33653a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 3366e8144a13SAlexander Motin switch(command_status) { 3367e8144a13SAlexander Motin case CISS_CMD_STATUS_DATA_UNDERRUN: 3368e8144a13SAlexander Motin csio->resid = ce->residual_count; 3369e8144a13SAlexander Motin /* FALLTHROUGH */ 3370e8144a13SAlexander Motin case CISS_CMD_STATUS_SUCCESS: 33713a31b7ebSMike Smith csio->scsi_status = scsi_status; 33723a31b7ebSMike Smith debug(2, "SCSI_STATUS_OK"); 33730a65b79fSAlexander Motin csio->ccb_h.status |= CAM_REQ_CMP; 33743a31b7ebSMike Smith break; 3375e8144a13SAlexander Motin case CISS_CMD_STATUS_TARGET_STATUS: 3376e8144a13SAlexander Motin csio->scsi_status = scsi_status; 33773a31b7ebSMike Smith bzero(&csio->sense_data, SSD_FULL_SIZE); 33783a31b7ebSMike Smith bcopy(&ce->sense_info[0], &csio->sense_data, ce->sense_length); 33791cc052e8SKenneth D. Merry if (csio->sense_len > ce->sense_length) 33801cc052e8SKenneth D. Merry csio->sense_resid = csio->sense_len - ce->sense_length; 33811cc052e8SKenneth D. Merry else 33821cc052e8SKenneth D. Merry csio->sense_resid = 0; 33833a31b7ebSMike Smith csio->resid = ce->residual_count; 33840a65b79fSAlexander Motin csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; 33853a31b7ebSMike Smith break; 3386e8144a13SAlexander Motin case CISS_CMD_STATUS_DATA_OVERRUN: 3387e8144a13SAlexander Motin csio->ccb_h.status |= CAM_DATA_RUN_ERR; 33883a31b7ebSMike Smith break; 33893a31b7ebSMike Smith default: 33900a65b79fSAlexander Motin csio->ccb_h.status |= CAM_REQ_CMP_ERR; 33913a31b7ebSMike Smith break; 33923a31b7ebSMike Smith } 33933a31b7ebSMike Smith 33943a31b7ebSMike Smith /* handle post-command fixup */ 33953a31b7ebSMike Smith ciss_cam_complete_fixup(sc, csio); 33963a31b7ebSMike Smith 33973a31b7ebSMike Smith ciss_release_request(cr); 339895dab4f2SAlexander Motin if (sc->ciss_flags & CISS_FLAG_BUSY) { 339995dab4f2SAlexander Motin sc->ciss_flags &= ~CISS_FLAG_BUSY; 340095dab4f2SAlexander Motin if (csio->ccb_h.status & CAM_RELEASE_SIMQ) 340195dab4f2SAlexander Motin xpt_release_simq(xpt_path_sim(csio->ccb_h.path), 0); 340295dab4f2SAlexander Motin else 340395dab4f2SAlexander Motin csio->ccb_h.status |= CAM_RELEASE_SIMQ; 340495dab4f2SAlexander Motin } 340522657ce1SScott Long xpt_done((union ccb *)csio); 34063a31b7ebSMike Smith } 34073a31b7ebSMike Smith 34083a31b7ebSMike Smith /******************************************************************************** 34093a31b7ebSMike Smith * Fix up the result of some commands here. 34103a31b7ebSMike Smith */ 34113a31b7ebSMike Smith static void 34123a31b7ebSMike Smith ciss_cam_complete_fixup(struct ciss_softc *sc, struct ccb_scsiio *csio) 34133a31b7ebSMike Smith { 34143a31b7ebSMike Smith struct scsi_inquiry_data *inq; 34153a31b7ebSMike Smith struct ciss_ldrive *cl; 341657ae362cSAlexander Motin uint8_t *cdb; 3417c6131460SPaul Saab int bus, target; 34183a31b7ebSMike Smith 341957ae362cSAlexander Motin cdb = (csio->ccb_h.flags & CAM_CDB_POINTER) ? 342057ae362cSAlexander Motin (uint8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes; 342157ae362cSAlexander Motin if (cdb[0] == INQUIRY && 342257ae362cSAlexander Motin (cdb[1] & SI_EVPD) == 0 && 342357ae362cSAlexander Motin (csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN && 342457ae362cSAlexander Motin csio->dxfer_len >= SHORT_INQUIRY_LENGTH) { 34253a31b7ebSMike Smith inq = (struct scsi_inquiry_data *)csio->data_ptr; 34263a31b7ebSMike Smith target = csio->ccb_h.target_id; 3427c6131460SPaul Saab bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); 34281fe6c4eeSScott Long 34291fe6c4eeSScott Long /* 34300fb31ed0SSean Bruno * If the controller is in JBOD mode, there are no logical volumes. 34310fb31ed0SSean Bruno * Let the disks be probed and dealt with via CAM. Else, mask off 34320fb31ed0SSean Bruno * the physical disks and setup the parts of the inq structure for 34330fb31ed0SSean Bruno * the logical volume. swb 34341fe6c4eeSScott Long */ 34350fb31ed0SSean Bruno if( !(sc->ciss_id->PowerUPNvramFlags & PWR_UP_FLAG_JBOD_ENABLED)){ 34361fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) { 34371fe6c4eeSScott Long if (SID_TYPE(inq) == T_DIRECT) 34381fe6c4eeSScott Long inq->device = (inq->device & 0xe0) | T_NODEVICE; 34391fe6c4eeSScott Long return; 34401fe6c4eeSScott Long } 3441c6131460SPaul Saab cl = &sc->ciss_logical[bus][target]; 34423a31b7ebSMike Smith 34431e8b29a4SSean Bruno padstr(inq->vendor, "HP", 3444a9112e5dSSean Bruno SID_VENDOR_SIZE); 3445a9112e5dSSean Bruno padstr(inq->product, 3446a9112e5dSSean Bruno ciss_name_ldrive_org(cl->cl_ldrive->fault_tolerance), 3447a9112e5dSSean Bruno SID_PRODUCT_SIZE); 3448a9112e5dSSean Bruno padstr(inq->revision, 3449a9112e5dSSean Bruno ciss_name_ldrive_status(cl->cl_lstatus->status), 3450a9112e5dSSean Bruno SID_REVISION_SIZE); 34513a31b7ebSMike Smith } 34523a31b7ebSMike Smith } 34530fb31ed0SSean Bruno } 34543a31b7ebSMike Smith 34553a31b7ebSMike Smith /******************************************************************************** 34563a31b7ebSMike Smith * Name the device at (target) 34573a31b7ebSMike Smith * 34583a31b7ebSMike Smith * XXX is this strictly correct? 34593a31b7ebSMike Smith */ 346037c84183SPoul-Henning Kamp static int 3461c6131460SPaul Saab ciss_name_device(struct ciss_softc *sc, int bus, int target) 34623a31b7ebSMike Smith { 34633a31b7ebSMike Smith struct cam_periph *periph; 3464739a9399SSean Bruno struct cam_path *path; 3465739a9399SSean Bruno int status; 34663a31b7ebSMike Smith 3467d49f1379SPaul Saab if (CISS_IS_PHYSICAL(bus)) 34681fe6c4eeSScott Long return (0); 3469739a9399SSean Bruno 3470739a9399SSean Bruno status = xpt_create_path(&path, NULL, cam_sim_path(sc->ciss_cam_sim[bus]), 3471739a9399SSean Bruno target, 0); 3472739a9399SSean Bruno 3473739a9399SSean Bruno if (status == CAM_REQ_CMP) { 3474739a9399SSean Bruno xpt_path_lock(path); 3475739a9399SSean Bruno periph = cam_periph_find(path, NULL); 347697ed09b5SSean Bruno xpt_path_unlock(path); 347797ed09b5SSean Bruno xpt_free_path(path); 347897ed09b5SSean Bruno if (periph != NULL) { 34791fe6c4eeSScott Long sprintf(sc->ciss_logical[bus][target].cl_name, "%s%d", 34801fe6c4eeSScott Long periph->periph_name, periph->unit_number); 34813a31b7ebSMike Smith return(0); 34823a31b7ebSMike Smith } 348397ed09b5SSean Bruno } 3484c6131460SPaul Saab sc->ciss_logical[bus][target].cl_name[0] = 0; 34853a31b7ebSMike Smith return(ENOENT); 34863a31b7ebSMike Smith } 34873a31b7ebSMike Smith 34883a31b7ebSMike Smith /************************************************************************ 34893a31b7ebSMike Smith * Periodic status monitoring. 34903a31b7ebSMike Smith */ 34913a31b7ebSMike Smith static void 34923a31b7ebSMike Smith ciss_periodic(void *arg) 34933a31b7ebSMike Smith { 34943a31b7ebSMike Smith struct ciss_softc *sc; 3495e08d902aSMitsuru IWASAKI struct ciss_request *cr = NULL; 3496e08d902aSMitsuru IWASAKI struct ciss_command *cc = NULL; 3497e08d902aSMitsuru IWASAKI int error = 0; 34983a31b7ebSMike Smith 34993a31b7ebSMike Smith debug_called(1); 35003a31b7ebSMike Smith 35013a31b7ebSMike Smith sc = (struct ciss_softc *)arg; 35023a31b7ebSMike Smith 35033a31b7ebSMike Smith /* 35043a31b7ebSMike Smith * Check the adapter heartbeat. 35053a31b7ebSMike Smith */ 35063a31b7ebSMike Smith if (sc->ciss_cfg->heartbeat == sc->ciss_heartbeat) { 35073a31b7ebSMike Smith sc->ciss_heart_attack++; 35083a31b7ebSMike Smith debug(0, "adapter heart attack in progress 0x%x/%d", 35093a31b7ebSMike Smith sc->ciss_heartbeat, sc->ciss_heart_attack); 35103a31b7ebSMike Smith if (sc->ciss_heart_attack == 3) { 35113a31b7ebSMike Smith ciss_printf(sc, "ADAPTER HEARTBEAT FAILED\n"); 3512e08d902aSMitsuru IWASAKI ciss_disable_adapter(sc); 3513e08d902aSMitsuru IWASAKI return; 35143a31b7ebSMike Smith } 35153a31b7ebSMike Smith } else { 35163a31b7ebSMike Smith sc->ciss_heartbeat = sc->ciss_cfg->heartbeat; 35173a31b7ebSMike Smith sc->ciss_heart_attack = 0; 35183a31b7ebSMike Smith debug(3, "new heartbeat 0x%x", sc->ciss_heartbeat); 35193a31b7ebSMike Smith } 35203a31b7ebSMike Smith 35213a31b7ebSMike Smith /* 3522e08d902aSMitsuru IWASAKI * Send the NOP message and wait for a response. 3523e08d902aSMitsuru IWASAKI */ 35245a3c4d69SMitsuru IWASAKI if (ciss_nop_message_heartbeat != 0 && (error = ciss_get_request(sc, &cr)) == 0) { 35252fdaa90dSScott Long cc = cr->cr_cc; 352654d02e0aSMitsuru IWASAKI cr->cr_complete = ciss_nop_complete; 3527e08d902aSMitsuru IWASAKI cc->cdb.cdb_length = 1; 3528e08d902aSMitsuru IWASAKI cc->cdb.type = CISS_CDB_TYPE_MESSAGE; 3529e08d902aSMitsuru IWASAKI cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 3530e08d902aSMitsuru IWASAKI cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; 3531e08d902aSMitsuru IWASAKI cc->cdb.timeout = 0; 3532e08d902aSMitsuru IWASAKI cc->cdb.cdb[0] = CISS_OPCODE_MESSAGE_NOP; 3533e08d902aSMitsuru IWASAKI 353454d02e0aSMitsuru IWASAKI if ((error = ciss_start(cr)) != 0) { 3535e08d902aSMitsuru IWASAKI ciss_printf(sc, "SENDING NOP MESSAGE FAILED\n"); 3536e08d902aSMitsuru IWASAKI } 3537e08d902aSMitsuru IWASAKI } 3538e08d902aSMitsuru IWASAKI 3539e08d902aSMitsuru IWASAKI /* 35403a31b7ebSMike Smith * If the notify event request has died for some reason, or has 35413a31b7ebSMike Smith * not started yet, restart it. 35423a31b7ebSMike Smith */ 35433a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) { 35443a31b7ebSMike Smith debug(0, "(re)starting Event Notify chain"); 35453a31b7ebSMike Smith ciss_notify_event(sc); 35463a31b7ebSMike Smith } 35473a31b7ebSMike Smith 35483a31b7ebSMike Smith /* 35493a31b7ebSMike Smith * Reschedule. 35503a31b7ebSMike Smith */ 3551975b7318SScott Long callout_reset(&sc->ciss_periodic, CISS_HEARTBEAT_RATE * hz, ciss_periodic, sc); 35523a31b7ebSMike Smith } 35533a31b7ebSMike Smith 355454d02e0aSMitsuru IWASAKI static void 355554d02e0aSMitsuru IWASAKI ciss_nop_complete(struct ciss_request *cr) 355654d02e0aSMitsuru IWASAKI { 355754d02e0aSMitsuru IWASAKI struct ciss_softc *sc; 35580aeee4bdSMitsuru IWASAKI static int first_time = 1; 355954d02e0aSMitsuru IWASAKI 356054d02e0aSMitsuru IWASAKI sc = cr->cr_sc; 356154d02e0aSMitsuru IWASAKI if (ciss_report_request(cr, NULL, NULL) != 0) { 35620aeee4bdSMitsuru IWASAKI if (first_time == 1) { 35630aeee4bdSMitsuru IWASAKI first_time = 0; 35640aeee4bdSMitsuru IWASAKI ciss_printf(sc, "SENDING NOP MESSAGE FAILED (not logging anymore)\n"); 35650aeee4bdSMitsuru IWASAKI } 356654d02e0aSMitsuru IWASAKI } 356754d02e0aSMitsuru IWASAKI 356854d02e0aSMitsuru IWASAKI ciss_release_request(cr); 356954d02e0aSMitsuru IWASAKI } 357054d02e0aSMitsuru IWASAKI 35713a31b7ebSMike Smith /************************************************************************ 3572e08d902aSMitsuru IWASAKI * Disable the adapter. 3573e08d902aSMitsuru IWASAKI * 3574e08d902aSMitsuru IWASAKI * The all requests in completed queue is failed with hardware error. 3575e08d902aSMitsuru IWASAKI * This will cause failover in a multipath configuration. 3576e08d902aSMitsuru IWASAKI */ 3577e08d902aSMitsuru IWASAKI static void 3578e08d902aSMitsuru IWASAKI ciss_disable_adapter(struct ciss_softc *sc) 3579e08d902aSMitsuru IWASAKI { 358022657ce1SScott Long cr_qhead_t qh; 3581e08d902aSMitsuru IWASAKI struct ciss_request *cr; 3582e08d902aSMitsuru IWASAKI struct ciss_command *cc; 3583e08d902aSMitsuru IWASAKI struct ciss_error_info *ce; 358422657ce1SScott Long int i; 3585e08d902aSMitsuru IWASAKI 3586e08d902aSMitsuru IWASAKI CISS_TL_SIMPLE_DISABLE_INTERRUPTS(sc); 3587e08d902aSMitsuru IWASAKI pci_disable_busmaster(sc->ciss_dev); 3588e08d902aSMitsuru IWASAKI sc->ciss_flags &= ~CISS_FLAG_RUNNING; 3589e08d902aSMitsuru IWASAKI 3590d26ae2c1SAlexander Motin STAILQ_INIT(&qh); 359122657ce1SScott Long for (i = 1; i < sc->ciss_max_requests; i++) { 359222657ce1SScott Long cr = &sc->ciss_request[i]; 359322657ce1SScott Long if ((cr->cr_flags & CISS_REQ_BUSY) == 0) 359422657ce1SScott Long continue; 3595e08d902aSMitsuru IWASAKI 35962fdaa90dSScott Long cc = cr->cr_cc; 3597e08d902aSMitsuru IWASAKI ce = (struct ciss_error_info *)&(cc->sg[0]); 3598e08d902aSMitsuru IWASAKI ce->command_status = CISS_CMD_STATUS_HARDWARE_ERROR; 359922657ce1SScott Long ciss_enqueue_complete(cr, &qh); 3600e08d902aSMitsuru IWASAKI } 3601e08d902aSMitsuru IWASAKI 3602e08d902aSMitsuru IWASAKI for (;;) { 360322657ce1SScott Long if ((cr = ciss_dequeue_complete(sc, &qh)) == NULL) 3604e08d902aSMitsuru IWASAKI break; 3605e08d902aSMitsuru IWASAKI 3606e08d902aSMitsuru IWASAKI /* 3607e08d902aSMitsuru IWASAKI * If the request has a callback, invoke it. 3608e08d902aSMitsuru IWASAKI */ 3609e08d902aSMitsuru IWASAKI if (cr->cr_complete != NULL) { 3610e08d902aSMitsuru IWASAKI cr->cr_complete(cr); 3611e08d902aSMitsuru IWASAKI continue; 3612e08d902aSMitsuru IWASAKI } 3613e08d902aSMitsuru IWASAKI 3614e08d902aSMitsuru IWASAKI /* 3615e08d902aSMitsuru IWASAKI * If someone is sleeping on this request, wake them up. 3616e08d902aSMitsuru IWASAKI */ 3617e08d902aSMitsuru IWASAKI if (cr->cr_flags & CISS_REQ_SLEEP) { 3618e08d902aSMitsuru IWASAKI cr->cr_flags &= ~CISS_REQ_SLEEP; 3619e08d902aSMitsuru IWASAKI wakeup(cr); 3620e08d902aSMitsuru IWASAKI continue; 3621e08d902aSMitsuru IWASAKI } 3622e08d902aSMitsuru IWASAKI } 3623e08d902aSMitsuru IWASAKI } 3624e08d902aSMitsuru IWASAKI 3625e08d902aSMitsuru IWASAKI /************************************************************************ 36263a31b7ebSMike Smith * Request a notification response from the adapter. 36273a31b7ebSMike Smith * 36283a31b7ebSMike Smith * If (cr) is NULL, this is the first request of the adapter, so 36293a31b7ebSMike Smith * reset the adapter's message pointer and start with the oldest 36303a31b7ebSMike Smith * message available. 36313a31b7ebSMike Smith */ 36323a31b7ebSMike Smith static void 36333a31b7ebSMike Smith ciss_notify_event(struct ciss_softc *sc) 36343a31b7ebSMike Smith { 36353a31b7ebSMike Smith struct ciss_request *cr; 36363a31b7ebSMike Smith struct ciss_command *cc; 36373a31b7ebSMike Smith struct ciss_notify_cdb *cnc; 36383a31b7ebSMike Smith int error; 36393a31b7ebSMike Smith 36403a31b7ebSMike Smith debug_called(1); 36413a31b7ebSMike Smith 36423a31b7ebSMike Smith cr = sc->ciss_periodic_notify; 36433a31b7ebSMike Smith 36443a31b7ebSMike Smith /* get a request if we don't already have one */ 36453a31b7ebSMike Smith if (cr == NULL) { 36463a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) { 36473a31b7ebSMike Smith debug(0, "can't get notify event request"); 36483a31b7ebSMike Smith goto out; 36493a31b7ebSMike Smith } 36503a31b7ebSMike Smith sc->ciss_periodic_notify = cr; 36513a31b7ebSMike Smith cr->cr_complete = ciss_notify_complete; 36523a31b7ebSMike Smith debug(1, "acquired request %d", cr->cr_tag); 36533a31b7ebSMike Smith } 36543a31b7ebSMike Smith 36553a31b7ebSMike Smith /* 36563a31b7ebSMike Smith * Get a databuffer if we don't already have one, note that the 36573a31b7ebSMike Smith * adapter command wants a larger buffer than the actual 36583a31b7ebSMike Smith * structure. 36593a31b7ebSMike Smith */ 36603a31b7ebSMike Smith if (cr->cr_data == NULL) { 36613a31b7ebSMike Smith if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 36623a31b7ebSMike Smith debug(0, "can't get notify event request buffer"); 36633a31b7ebSMike Smith error = ENOMEM; 36643a31b7ebSMike Smith goto out; 36653a31b7ebSMike Smith } 36663a31b7ebSMike Smith cr->cr_length = CISS_NOTIFY_DATA_SIZE; 36673a31b7ebSMike Smith } 36683a31b7ebSMike Smith 36693a31b7ebSMike Smith /* re-setup the request's command (since we never release it) XXX overkill*/ 36703a31b7ebSMike Smith ciss_preen_command(cr); 36713a31b7ebSMike Smith 36723a31b7ebSMike Smith /* (re)build the notify event command */ 36732fdaa90dSScott Long cc = cr->cr_cc; 36743a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 36753a31b7ebSMike Smith cc->header.address.physical.bus = 0; 36763a31b7ebSMike Smith cc->header.address.physical.target = 0; 36773a31b7ebSMike Smith 36783a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cnc); 36793a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 36803a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 36813a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 36823a31b7ebSMike Smith cc->cdb.timeout = 0; /* no timeout, we hope */ 36833a31b7ebSMike Smith 36843a31b7ebSMike Smith cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); 36853a31b7ebSMike Smith bzero(cr->cr_data, CISS_NOTIFY_DATA_SIZE); 36863a31b7ebSMike Smith cnc->opcode = CISS_OPCODE_READ; 36873a31b7ebSMike Smith cnc->command = CISS_COMMAND_NOTIFY_ON_EVENT; 36883a31b7ebSMike Smith cnc->timeout = 0; /* no timeout, we hope */ 36893a31b7ebSMike Smith cnc->synchronous = 0; 36903a31b7ebSMike Smith cnc->ordered = 0; 36913a31b7ebSMike Smith cnc->seek_to_oldest = 0; 36922e80ca8aSPaul Saab if ((sc->ciss_flags & CISS_FLAG_RUNNING) == 0) 36932e80ca8aSPaul Saab cnc->new_only = 1; 36942e80ca8aSPaul Saab else 36953a31b7ebSMike Smith cnc->new_only = 0; 36963a31b7ebSMike Smith cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); 36973a31b7ebSMike Smith 36983a31b7ebSMike Smith /* submit the request */ 36993a31b7ebSMike Smith error = ciss_start(cr); 37003a31b7ebSMike Smith 37013a31b7ebSMike Smith out: 37023a31b7ebSMike Smith if (error) { 37033a31b7ebSMike Smith if (cr != NULL) { 37043a31b7ebSMike Smith if (cr->cr_data != NULL) 37053a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 37063a31b7ebSMike Smith ciss_release_request(cr); 37073a31b7ebSMike Smith } 37083a31b7ebSMike Smith sc->ciss_periodic_notify = NULL; 37093a31b7ebSMike Smith debug(0, "can't submit notify event request"); 37103a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 37113a31b7ebSMike Smith } else { 37123a31b7ebSMike Smith debug(1, "notify event submitted"); 37133a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_NOTIFY_OK; 37143a31b7ebSMike Smith } 37153a31b7ebSMike Smith } 37163a31b7ebSMike Smith 37173a31b7ebSMike Smith static void 37183a31b7ebSMike Smith ciss_notify_complete(struct ciss_request *cr) 37193a31b7ebSMike Smith { 37203a31b7ebSMike Smith struct ciss_notify *cn; 37213a31b7ebSMike Smith struct ciss_softc *sc; 37223a31b7ebSMike Smith int scsi_status; 37233a31b7ebSMike Smith int command_status; 37243a31b7ebSMike Smith debug_called(1); 37253a31b7ebSMike Smith 37263a31b7ebSMike Smith cn = (struct ciss_notify *)cr->cr_data; 37273a31b7ebSMike Smith sc = cr->cr_sc; 37283a31b7ebSMike Smith 37293a31b7ebSMike Smith /* 37303a31b7ebSMike Smith * Report request results, decode status. 37313a31b7ebSMike Smith */ 37323a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 37333a31b7ebSMike Smith 37343a31b7ebSMike Smith /* 37353a31b7ebSMike Smith * Abort the chain on a fatal error. 37363a31b7ebSMike Smith * 37373a31b7ebSMike Smith * XXX which of these are actually errors? 37383a31b7ebSMike Smith */ 37393a31b7ebSMike Smith if ((command_status != CISS_CMD_STATUS_SUCCESS) && 37403a31b7ebSMike Smith (command_status != CISS_CMD_STATUS_TARGET_STATUS) && 37413a31b7ebSMike Smith (command_status != CISS_CMD_STATUS_TIMEOUT)) { /* XXX timeout? */ 37423a31b7ebSMike Smith ciss_printf(sc, "fatal error in Notify Event request (%s)\n", 37433a31b7ebSMike Smith ciss_name_command_status(command_status)); 37443a31b7ebSMike Smith ciss_release_request(cr); 37453a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 37463a31b7ebSMike Smith return; 37473a31b7ebSMike Smith } 37483a31b7ebSMike Smith 37493a31b7ebSMike Smith /* 37503a31b7ebSMike Smith * If the adapter gave us a text message, print it. 37513a31b7ebSMike Smith */ 37523a31b7ebSMike Smith if (cn->message[0] != 0) 37533a31b7ebSMike Smith ciss_printf(sc, "*** %.80s\n", cn->message); 37543a31b7ebSMike Smith 37553a31b7ebSMike Smith debug(0, "notify event class %d subclass %d detail %d", 37563a31b7ebSMike Smith cn->class, cn->subclass, cn->detail); 37573a31b7ebSMike Smith 37583a31b7ebSMike Smith /* 37593a31b7ebSMike Smith * If the response indicates that the notifier has been aborted, 37603a31b7ebSMike Smith * release the notifier command. 37613a31b7ebSMike Smith */ 37623a31b7ebSMike Smith if ((cn->class == CISS_NOTIFY_NOTIFIER) && 37633a31b7ebSMike Smith (cn->subclass == CISS_NOTIFY_NOTIFIER_STATUS) && 37643a31b7ebSMike Smith (cn->detail == 1)) { 37653a31b7ebSMike Smith debug(0, "notifier exiting"); 37663a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 37673a31b7ebSMike Smith ciss_release_request(cr); 37683a31b7ebSMike Smith sc->ciss_periodic_notify = NULL; 37693a31b7ebSMike Smith wakeup(&sc->ciss_periodic_notify); 3770c6131460SPaul Saab } else { 3771c6131460SPaul Saab /* Handle notify events in a kernel thread */ 3772c6131460SPaul Saab ciss_enqueue_notify(cr); 3773c6131460SPaul Saab sc->ciss_periodic_notify = NULL; 3774c6131460SPaul Saab wakeup(&sc->ciss_periodic_notify); 3775c6131460SPaul Saab wakeup(&sc->ciss_notify); 37763a31b7ebSMike Smith } 37773a31b7ebSMike Smith /* 37783a31b7ebSMike Smith * Send a new notify event command, if we're not aborting. 37793a31b7ebSMike Smith */ 37803a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_ABORTING)) { 37813a31b7ebSMike Smith ciss_notify_event(sc); 37823a31b7ebSMike Smith } 37833a31b7ebSMike Smith } 37843a31b7ebSMike Smith 37853a31b7ebSMike Smith /************************************************************************ 37863a31b7ebSMike Smith * Abort the Notify Event chain. 37873a31b7ebSMike Smith * 37883a31b7ebSMike Smith * Note that we can't just abort the command in progress; we have to 37893a31b7ebSMike Smith * explicitly issue an Abort Notify Event command in order for the 37903a31b7ebSMike Smith * adapter to clean up correctly. 37913a31b7ebSMike Smith * 37923a31b7ebSMike Smith * If we are called with CISS_FLAG_ABORTING set in the adapter softc, 37933a31b7ebSMike Smith * the chain will not restart itself. 37943a31b7ebSMike Smith */ 37953a31b7ebSMike Smith static int 37963a31b7ebSMike Smith ciss_notify_abort(struct ciss_softc *sc) 37973a31b7ebSMike Smith { 37983a31b7ebSMike Smith struct ciss_request *cr; 37993a31b7ebSMike Smith struct ciss_command *cc; 38003a31b7ebSMike Smith struct ciss_notify_cdb *cnc; 380122657ce1SScott Long int error, command_status, scsi_status; 38023a31b7ebSMike Smith 38033a31b7ebSMike Smith debug_called(1); 38043a31b7ebSMike Smith 38053a31b7ebSMike Smith cr = NULL; 38063a31b7ebSMike Smith error = 0; 38073a31b7ebSMike Smith 38083a31b7ebSMike Smith /* verify that there's an outstanding command */ 38093a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) 38103a31b7ebSMike Smith goto out; 38113a31b7ebSMike Smith 38123a31b7ebSMike Smith /* get a command to issue the abort with */ 38133a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr))) 38143a31b7ebSMike Smith goto out; 38153a31b7ebSMike Smith 38163a31b7ebSMike Smith /* get a buffer for the result */ 38173a31b7ebSMike Smith if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 38183a31b7ebSMike Smith debug(0, "can't get notify event request buffer"); 38193a31b7ebSMike Smith error = ENOMEM; 38203a31b7ebSMike Smith goto out; 38213a31b7ebSMike Smith } 38223a31b7ebSMike Smith cr->cr_length = CISS_NOTIFY_DATA_SIZE; 38233a31b7ebSMike Smith 38243a31b7ebSMike Smith /* build the CDB */ 38252fdaa90dSScott Long cc = cr->cr_cc; 38263a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 38273a31b7ebSMike Smith cc->header.address.physical.bus = 0; 38283a31b7ebSMike Smith cc->header.address.physical.target = 0; 38293a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cnc); 38303a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 38313a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 38323a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 38333a31b7ebSMike Smith cc->cdb.timeout = 0; /* no timeout, we hope */ 38343a31b7ebSMike Smith 38353a31b7ebSMike Smith cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); 38363a31b7ebSMike Smith bzero(cnc, sizeof(*cnc)); 38373a31b7ebSMike Smith cnc->opcode = CISS_OPCODE_WRITE; 38383a31b7ebSMike Smith cnc->command = CISS_COMMAND_ABORT_NOTIFY; 38393a31b7ebSMike Smith cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); 38402e3d6d0fSWarner Losh #if 0 38413a31b7ebSMike Smith ciss_print_request(cr); 38422e3d6d0fSWarner Losh #endif 38433a31b7ebSMike Smith 38443a31b7ebSMike Smith /* 38453a31b7ebSMike Smith * Submit the request and wait for it to complete. 38463a31b7ebSMike Smith */ 38473a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 38483a31b7ebSMike Smith ciss_printf(sc, "Abort Notify Event command failed (%d)\n", error); 38493a31b7ebSMike Smith goto out; 38503a31b7ebSMike Smith } 38513a31b7ebSMike Smith 38523a31b7ebSMike Smith /* 38533a31b7ebSMike Smith * Check response. 38543a31b7ebSMike Smith */ 38553a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 38563a31b7ebSMike Smith switch(command_status) { 38573a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 38583a31b7ebSMike Smith break; 38593a31b7ebSMike Smith case CISS_CMD_STATUS_INVALID_COMMAND: 38603a31b7ebSMike Smith /* 38613a31b7ebSMike Smith * Some older adapters don't support the CISS version of this 38623a31b7ebSMike Smith * command. Fall back to using the BMIC version. 38633a31b7ebSMike Smith */ 38643a31b7ebSMike Smith error = ciss_notify_abort_bmic(sc); 38653a31b7ebSMike Smith if (error != 0) 38663a31b7ebSMike Smith goto out; 38673a31b7ebSMike Smith break; 38683a31b7ebSMike Smith 38693a31b7ebSMike Smith case CISS_CMD_STATUS_TARGET_STATUS: 38703a31b7ebSMike Smith /* 38713a31b7ebSMike Smith * This can happen if the adapter thinks there wasn't an outstanding 38723a31b7ebSMike Smith * Notify Event command but we did. We clean up here. 38733a31b7ebSMike Smith */ 38743a31b7ebSMike Smith if (scsi_status == CISS_SCSI_STATUS_CHECK_CONDITION) { 38753a31b7ebSMike Smith if (sc->ciss_periodic_notify != NULL) 38763a31b7ebSMike Smith ciss_release_request(sc->ciss_periodic_notify); 38773a31b7ebSMike Smith error = 0; 38783a31b7ebSMike Smith goto out; 38793a31b7ebSMike Smith } 38803a31b7ebSMike Smith /* FALLTHROUGH */ 38813a31b7ebSMike Smith 38823a31b7ebSMike Smith default: 38833a31b7ebSMike Smith ciss_printf(sc, "Abort Notify Event command failed (%s)\n", 38843a31b7ebSMike Smith ciss_name_command_status(command_status)); 38853a31b7ebSMike Smith error = EIO; 38863a31b7ebSMike Smith goto out; 38873a31b7ebSMike Smith } 38883a31b7ebSMike Smith 38893a31b7ebSMike Smith /* 38903a31b7ebSMike Smith * Sleep waiting for the notifier command to complete. Note 38913a31b7ebSMike Smith * that if it doesn't, we may end up in a bad situation, since 38923a31b7ebSMike Smith * the adapter may deliver it later. Also note that the adapter 38933a31b7ebSMike Smith * requires the Notify Event command to be cancelled in order to 38943a31b7ebSMike Smith * maintain internal bookkeeping. 38953a31b7ebSMike Smith */ 38963a31b7ebSMike Smith while (sc->ciss_periodic_notify != NULL) { 3897975b7318SScott Long error = msleep(&sc->ciss_periodic_notify, &sc->ciss_mtx, PRIBIO, "cissNEA", hz * 5); 38983a31b7ebSMike Smith if (error == EWOULDBLOCK) { 38993a31b7ebSMike Smith ciss_printf(sc, "Notify Event command failed to abort, adapter may wedge.\n"); 39003a31b7ebSMike Smith break; 39013a31b7ebSMike Smith } 39023a31b7ebSMike Smith } 39033a31b7ebSMike Smith 39043a31b7ebSMike Smith out: 39053a31b7ebSMike Smith /* release the cancel request */ 39063a31b7ebSMike Smith if (cr != NULL) { 39073a31b7ebSMike Smith if (cr->cr_data != NULL) 39083a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 39093a31b7ebSMike Smith ciss_release_request(cr); 39103a31b7ebSMike Smith } 39113a31b7ebSMike Smith if (error == 0) 39123a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 39133a31b7ebSMike Smith return(error); 39143a31b7ebSMike Smith } 39153a31b7ebSMike Smith 39163a31b7ebSMike Smith /************************************************************************ 39173a31b7ebSMike Smith * Abort the Notify Event chain using a BMIC command. 39183a31b7ebSMike Smith */ 39193a31b7ebSMike Smith static int 39203a31b7ebSMike Smith ciss_notify_abort_bmic(struct ciss_softc *sc) 39213a31b7ebSMike Smith { 39223a31b7ebSMike Smith struct ciss_request *cr; 39233a31b7ebSMike Smith int error, command_status; 39243a31b7ebSMike Smith 39253a31b7ebSMike Smith debug_called(1); 39263a31b7ebSMike Smith 39273a31b7ebSMike Smith cr = NULL; 39283a31b7ebSMike Smith error = 0; 39293a31b7ebSMike Smith 39303a31b7ebSMike Smith /* verify that there's an outstanding command */ 39313a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) 39323a31b7ebSMike Smith goto out; 39333a31b7ebSMike Smith 39343a31b7ebSMike Smith /* 39353a31b7ebSMike Smith * Build a BMIC command to cancel the Notify on Event command. 39363a31b7ebSMike Smith * 39373a31b7ebSMike Smith * Note that we are sending a CISS opcode here. Odd. 39383a31b7ebSMike Smith */ 39393a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_COMMAND_ABORT_NOTIFY, 39403a31b7ebSMike Smith NULL, 0)) != 0) 39413a31b7ebSMike Smith goto out; 39423a31b7ebSMike Smith 39433a31b7ebSMike Smith /* 39443a31b7ebSMike Smith * Submit the request and wait for it to complete. 39453a31b7ebSMike Smith */ 39463a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 39473a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC Cancel Notify on Event command (%d)\n", error); 39483a31b7ebSMike Smith goto out; 39493a31b7ebSMike Smith } 39503a31b7ebSMike Smith 39513a31b7ebSMike Smith /* 39523a31b7ebSMike Smith * Check response. 39533a31b7ebSMike Smith */ 39543a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 39553a31b7ebSMike Smith switch(command_status) { 39563a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 39573a31b7ebSMike Smith break; 39583a31b7ebSMike Smith default: 39593a31b7ebSMike Smith ciss_printf(sc, "error cancelling Notify on Event (%s)\n", 39603a31b7ebSMike Smith ciss_name_command_status(command_status)); 39613a31b7ebSMike Smith error = EIO; 39623a31b7ebSMike Smith goto out; 39633a31b7ebSMike Smith } 39643a31b7ebSMike Smith 39653a31b7ebSMike Smith out: 39663a31b7ebSMike Smith if (cr != NULL) 39673a31b7ebSMike Smith ciss_release_request(cr); 39683a31b7ebSMike Smith return(error); 39693a31b7ebSMike Smith } 39703a31b7ebSMike Smith 39713a31b7ebSMike Smith /************************************************************************ 3972c6131460SPaul Saab * Handle rescanning all the logical volumes when a notify event 3973c6131460SPaul Saab * causes the drives to come online or offline. 3974c6131460SPaul Saab */ 3975c6131460SPaul Saab static void 3976c6131460SPaul Saab ciss_notify_rescan_logical(struct ciss_softc *sc) 3977c6131460SPaul Saab { 3978c6131460SPaul Saab struct ciss_lun_report *cll; 3979c6131460SPaul Saab struct ciss_ldrive *ld; 3980c6131460SPaul Saab int i, j, ndrives; 3981c6131460SPaul Saab 3982c6131460SPaul Saab /* 3983c6131460SPaul Saab * We must rescan all logical volumes to get the right logical 3984c6131460SPaul Saab * drive address. 3985c6131460SPaul Saab */ 3986c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_LOGICAL_LUNS, 3987e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported); 3988c6131460SPaul Saab if (cll == NULL) 3989c6131460SPaul Saab return; 3990c6131460SPaul Saab 3991c6131460SPaul Saab ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 3992c6131460SPaul Saab 3993c6131460SPaul Saab /* 3994c6131460SPaul Saab * Delete any of the drives which were destroyed by the 3995c6131460SPaul Saab * firmware. 3996c6131460SPaul Saab */ 39971fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 3998e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { 3999c6131460SPaul Saab ld = &sc->ciss_logical[i][j]; 4000c6131460SPaul Saab 4001c6131460SPaul Saab if (ld->cl_update == 0) 4002c6131460SPaul Saab continue; 4003c6131460SPaul Saab 4004c6131460SPaul Saab if (ld->cl_status != CISS_LD_ONLINE) { 4005c6131460SPaul Saab ciss_cam_rescan_target(sc, i, j); 4006c6131460SPaul Saab ld->cl_update = 0; 4007c6131460SPaul Saab if (ld->cl_ldrive) 4008c6131460SPaul Saab free(ld->cl_ldrive, CISS_MALLOC_CLASS); 4009c6131460SPaul Saab if (ld->cl_lstatus) 4010c6131460SPaul Saab free(ld->cl_lstatus, CISS_MALLOC_CLASS); 4011c6131460SPaul Saab 4012c6131460SPaul Saab ld->cl_ldrive = NULL; 4013c6131460SPaul Saab ld->cl_lstatus = NULL; 4014c6131460SPaul Saab } 4015c6131460SPaul Saab } 4016c6131460SPaul Saab } 4017c6131460SPaul Saab 4018c6131460SPaul Saab /* 4019c6131460SPaul Saab * Scan for new drives. 4020c6131460SPaul Saab */ 4021c6131460SPaul Saab for (i = 0; i < ndrives; i++) { 4022c6131460SPaul Saab int bus, target; 4023c6131460SPaul Saab 4024c6131460SPaul Saab bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); 4025c6131460SPaul Saab target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); 4026c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 4027c6131460SPaul Saab 4028c6131460SPaul Saab if (ld->cl_update == 0) 4029c6131460SPaul Saab continue; 4030c6131460SPaul Saab 40315cf5a430SPaul Saab ld->cl_update = 0; 4032c6131460SPaul Saab ld->cl_address = cll->lun[i]; 4033c6131460SPaul Saab ld->cl_controller = &sc->ciss_controllers[bus]; 4034c6131460SPaul Saab if (ciss_identify_logical(sc, ld) == 0) { 4035c6131460SPaul Saab ciss_cam_rescan_target(sc, bus, target); 4036c6131460SPaul Saab } 4037c6131460SPaul Saab } 4038c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 4039c6131460SPaul Saab } 4040c6131460SPaul Saab 4041c6131460SPaul Saab /************************************************************************ 40423a31b7ebSMike Smith * Handle a notify event relating to the status of a logical drive. 40433a31b7ebSMike Smith * 40443a31b7ebSMike Smith * XXX need to be able to defer some of these to properly handle 40453a31b7ebSMike Smith * calling the "ID Physical drive" command, unless the 'extended' 40463a31b7ebSMike Smith * drive IDs are always in BIG_MAP format. 40473a31b7ebSMike Smith */ 40483a31b7ebSMike Smith static void 40493a31b7ebSMike Smith ciss_notify_logical(struct ciss_softc *sc, struct ciss_notify *cn) 40503a31b7ebSMike Smith { 40513a31b7ebSMike Smith struct ciss_ldrive *ld; 4052e6aa1412SSean Bruno int ostatus, bus, target; 40533a31b7ebSMike Smith 40543a31b7ebSMike Smith debug_called(2); 40553a31b7ebSMike Smith 4056c6131460SPaul Saab bus = cn->device.physical.bus; 4057c6131460SPaul Saab target = cn->data.logical_status.logical_drive; 4058c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 40593a31b7ebSMike Smith 40603a31b7ebSMike Smith switch (cn->subclass) { 40613a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_STATUS: 40623a31b7ebSMike Smith switch (cn->detail) { 40633a31b7ebSMike Smith case 0: 4064c6131460SPaul Saab ciss_name_device(sc, bus, target); 40653a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) changed status %s->%s, spare status 0x%b\n", 40663a31b7ebSMike Smith cn->data.logical_status.logical_drive, ld->cl_name, 40673a31b7ebSMike Smith ciss_name_ldrive_status(cn->data.logical_status.previous_state), 40683a31b7ebSMike Smith ciss_name_ldrive_status(cn->data.logical_status.new_state), 40693a31b7ebSMike Smith cn->data.logical_status.spare_state, 40703a31b7ebSMike Smith "\20\1configured\2rebuilding\3failed\4in use\5available\n"); 40713a31b7ebSMike Smith 40723a31b7ebSMike Smith /* 40733a31b7ebSMike Smith * Update our idea of the drive's status. 40743a31b7ebSMike Smith */ 4075e6aa1412SSean Bruno ostatus = ciss_decode_ldrive_status(cn->data.logical_status.previous_state); 40763a31b7ebSMike Smith ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); 4077d4aa427fSPaul Saab if (ld->cl_lstatus != NULL) 40783a31b7ebSMike Smith ld->cl_lstatus->status = cn->data.logical_status.new_state; 40793a31b7ebSMike Smith 4080d4aa427fSPaul Saab /* 4081d4aa427fSPaul Saab * Have CAM rescan the drive if its status has changed. 4082d4aa427fSPaul Saab */ 4083e6aa1412SSean Bruno if (ostatus != ld->cl_status) { 4084c6131460SPaul Saab ld->cl_update = 1; 4085c6131460SPaul Saab ciss_notify_rescan_logical(sc); 4086c6131460SPaul Saab } 4087d4aa427fSPaul Saab 40883a31b7ebSMike Smith break; 40893a31b7ebSMike Smith 40903a31b7ebSMike Smith case 1: /* logical drive has recognised new media, needs Accept Media Exchange */ 4091c6131460SPaul Saab ciss_name_device(sc, bus, target); 40923a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) media exchanged, ready to go online\n", 40933a31b7ebSMike Smith cn->data.logical_status.logical_drive, ld->cl_name); 409488c78a38SPaul Saab ciss_accept_media(sc, ld); 4095139233cbSPaul Saab 4096139233cbSPaul Saab ld->cl_update = 1; 4097139233cbSPaul Saab ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); 4098139233cbSPaul Saab ciss_notify_rescan_logical(sc); 40993a31b7ebSMike Smith break; 41003a31b7ebSMike Smith 41013a31b7ebSMike Smith case 2: 41023a31b7ebSMike Smith case 3: 41033a31b7ebSMike Smith ciss_printf(sc, "rebuild of logical drive %d (%s) failed due to %s error\n", 41043a31b7ebSMike Smith cn->data.rebuild_aborted.logical_drive, 4105c6131460SPaul Saab ld->cl_name, 41063a31b7ebSMike Smith (cn->detail == 2) ? "read" : "write"); 41073a31b7ebSMike Smith break; 41083a31b7ebSMike Smith } 41093a31b7ebSMike Smith break; 41103a31b7ebSMike Smith 41113a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_ERROR: 41123a31b7ebSMike Smith if (cn->detail == 0) { 41133a31b7ebSMike Smith ciss_printf(sc, "FATAL I/O ERROR on logical drive %d (%s), SCSI port %d ID %d\n", 41143a31b7ebSMike Smith cn->data.io_error.logical_drive, 4115c6131460SPaul Saab ld->cl_name, 41163a31b7ebSMike Smith cn->data.io_error.failure_bus, 41173a31b7ebSMike Smith cn->data.io_error.failure_drive); 41183a31b7ebSMike Smith /* XXX should we take the drive down at this point, or will we be told? */ 41193a31b7ebSMike Smith } 41203a31b7ebSMike Smith break; 41213a31b7ebSMike Smith 41223a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_SURFACE: 41233a31b7ebSMike Smith if (cn->detail == 0) 41243a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) completed consistency initialisation\n", 41253a31b7ebSMike Smith cn->data.consistency_completed.logical_drive, 4126c6131460SPaul Saab ld->cl_name); 41273a31b7ebSMike Smith break; 41283a31b7ebSMike Smith } 41293a31b7ebSMike Smith } 41303a31b7ebSMike Smith 41313a31b7ebSMike Smith /************************************************************************ 41323a31b7ebSMike Smith * Handle a notify event relating to the status of a physical drive. 41333a31b7ebSMike Smith */ 41343a31b7ebSMike Smith static void 41353a31b7ebSMike Smith ciss_notify_physical(struct ciss_softc *sc, struct ciss_notify *cn) 41363a31b7ebSMike Smith { 4137c6131460SPaul Saab } 41383a31b7ebSMike Smith 4139c6131460SPaul Saab /************************************************************************ 41401fe6c4eeSScott Long * Handle a notify event relating to the status of a physical drive. 41411fe6c4eeSScott Long */ 41421fe6c4eeSScott Long static void 41431fe6c4eeSScott Long ciss_notify_hotplug(struct ciss_softc *sc, struct ciss_notify *cn) 41441fe6c4eeSScott Long { 4145c1885ab8SPaul Saab struct ciss_lun_report *cll = NULL; 41461fe6c4eeSScott Long int bus, target; 41471fe6c4eeSScott Long 41481fe6c4eeSScott Long switch (cn->subclass) { 41491fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG_PHYSICAL: 41501fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG_NONDISK: 41511fe6c4eeSScott Long bus = CISS_BIG_MAP_BUS(sc, cn->data.drive.big_physical_drive_number); 41521fe6c4eeSScott Long target = 41531fe6c4eeSScott Long CISS_BIG_MAP_TARGET(sc, cn->data.drive.big_physical_drive_number); 41541fe6c4eeSScott Long 41551fe6c4eeSScott Long if (cn->detail == 0) { 41561fe6c4eeSScott Long /* 41571fe6c4eeSScott Long * Mark the device offline so that it'll start producing selection 41581fe6c4eeSScott Long * timeouts to the upper layer. 41591fe6c4eeSScott Long */ 41605f265711SScott Long if ((bus >= 0) && (target >= 0)) 41611fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_online = 0; 41621fe6c4eeSScott Long } else { 41631fe6c4eeSScott Long /* 41641fe6c4eeSScott Long * Rescan the physical lun list for new items 41651fe6c4eeSScott Long */ 41661fe6c4eeSScott Long cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_PHYSICAL_LUNS, 4167e3edca22SSean Bruno sc->ciss_cfg->max_physical_supported); 41681fe6c4eeSScott Long if (cll == NULL) { 41691fe6c4eeSScott Long ciss_printf(sc, "Warning, cannot get physical lun list\n"); 41701fe6c4eeSScott Long break; 41711fe6c4eeSScott Long } 41721fe6c4eeSScott Long ciss_filter_physical(sc, cll); 41731fe6c4eeSScott Long } 41741fe6c4eeSScott Long break; 41751fe6c4eeSScott Long 41761fe6c4eeSScott Long default: 41771fe6c4eeSScott Long ciss_printf(sc, "Unknown hotplug event %d\n", cn->subclass); 41781fe6c4eeSScott Long return; 41791fe6c4eeSScott Long } 4180c1885ab8SPaul Saab 4181c1885ab8SPaul Saab if (cll != NULL) 4182c1885ab8SPaul Saab free(cll, CISS_MALLOC_CLASS); 41831fe6c4eeSScott Long } 41841fe6c4eeSScott Long 41851fe6c4eeSScott Long /************************************************************************ 4186c6131460SPaul Saab * Handle deferred processing of notify events. Notify events may need 4187c6131460SPaul Saab * sleep which is unsafe during an interrupt. 4188c6131460SPaul Saab */ 4189c6131460SPaul Saab static void 4190c6131460SPaul Saab ciss_notify_thread(void *arg) 4191c6131460SPaul Saab { 4192c6131460SPaul Saab struct ciss_softc *sc; 4193c6131460SPaul Saab struct ciss_request *cr; 4194c6131460SPaul Saab struct ciss_notify *cn; 4195c6131460SPaul Saab 4196c6131460SPaul Saab sc = (struct ciss_softc *)arg; 4197975b7318SScott Long mtx_lock(&sc->ciss_mtx); 4198c6131460SPaul Saab 4199c6131460SPaul Saab for (;;) { 420022657ce1SScott Long if (STAILQ_EMPTY(&sc->ciss_notify) != 0 && 4201c6131460SPaul Saab (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) == 0) { 4202975b7318SScott Long msleep(&sc->ciss_notify, &sc->ciss_mtx, PUSER, "idle", 0); 4203c6131460SPaul Saab } 4204c6131460SPaul Saab 4205c6131460SPaul Saab if (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) 4206c6131460SPaul Saab break; 4207c6131460SPaul Saab 4208c6131460SPaul Saab cr = ciss_dequeue_notify(sc); 4209c6131460SPaul Saab 4210c6131460SPaul Saab if (cr == NULL) 4211c6131460SPaul Saab panic("cr null"); 4212c6131460SPaul Saab cn = (struct ciss_notify *)cr->cr_data; 4213c6131460SPaul Saab 4214c6131460SPaul Saab switch (cn->class) { 42151fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG: 42161fe6c4eeSScott Long ciss_notify_hotplug(sc, cn); 42171fe6c4eeSScott Long break; 4218c6131460SPaul Saab case CISS_NOTIFY_LOGICAL: 4219c6131460SPaul Saab ciss_notify_logical(sc, cn); 4220c6131460SPaul Saab break; 4221c6131460SPaul Saab case CISS_NOTIFY_PHYSICAL: 4222c6131460SPaul Saab ciss_notify_physical(sc, cn); 4223c6131460SPaul Saab break; 4224c6131460SPaul Saab } 4225c6131460SPaul Saab 4226c6131460SPaul Saab ciss_release_request(cr); 4227c6131460SPaul Saab } 4228c6131460SPaul Saab sc->ciss_notify_thread = NULL; 4229c6131460SPaul Saab wakeup(&sc->ciss_notify_thread); 4230c6131460SPaul Saab 4231975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 42323745c395SJulian Elischer kproc_exit(0); 4233c6131460SPaul Saab } 4234c6131460SPaul Saab 4235c6131460SPaul Saab /************************************************************************ 4236c6131460SPaul Saab * Start the notification kernel thread. 4237c6131460SPaul Saab */ 4238c6131460SPaul Saab static void 4239c6131460SPaul Saab ciss_spawn_notify_thread(struct ciss_softc *sc) 4240c6131460SPaul Saab { 4241c6131460SPaul Saab 42423745c395SJulian Elischer if (kproc_create((void(*)(void *))ciss_notify_thread, sc, 4243c6131460SPaul Saab &sc->ciss_notify_thread, 0, 0, "ciss_notify%d", 4244c6131460SPaul Saab device_get_unit(sc->ciss_dev))) 4245c6131460SPaul Saab panic("Could not create notify thread\n"); 4246c6131460SPaul Saab } 4247c6131460SPaul Saab 4248c6131460SPaul Saab /************************************************************************ 4249c6131460SPaul Saab * Kill the notification kernel thread. 4250c6131460SPaul Saab */ 4251c6131460SPaul Saab static void 4252c6131460SPaul Saab ciss_kill_notify_thread(struct ciss_softc *sc) 4253c6131460SPaul Saab { 4254c6131460SPaul Saab 4255c6131460SPaul Saab if (sc->ciss_notify_thread == NULL) 4256c6131460SPaul Saab return; 4257c6131460SPaul Saab 4258c6131460SPaul Saab sc->ciss_flags |= CISS_FLAG_THREAD_SHUT; 4259c6131460SPaul Saab wakeup(&sc->ciss_notify); 4260975b7318SScott Long msleep(&sc->ciss_notify_thread, &sc->ciss_mtx, PUSER, "thtrm", 0); 42613a31b7ebSMike Smith } 42623a31b7ebSMike Smith 42633a31b7ebSMike Smith /************************************************************************ 42643a31b7ebSMike Smith * Print a request. 42653a31b7ebSMike Smith */ 42662e3d6d0fSWarner Losh #ifdef DDB 42673a31b7ebSMike Smith static void 42683a31b7ebSMike Smith ciss_print_request(struct ciss_request *cr) 42693a31b7ebSMike Smith { 42703a31b7ebSMike Smith struct ciss_softc *sc; 42713a31b7ebSMike Smith struct ciss_command *cc; 42723a31b7ebSMike Smith int i; 42733a31b7ebSMike Smith 42743a31b7ebSMike Smith sc = cr->cr_sc; 42752fdaa90dSScott Long cc = cr->cr_cc; 42763a31b7ebSMike Smith 42773a31b7ebSMike Smith ciss_printf(sc, "REQUEST @ %p\n", cr); 42783a31b7ebSMike Smith ciss_printf(sc, " data %p/%d tag %d flags %b\n", 42793a31b7ebSMike Smith cr->cr_data, cr->cr_length, cr->cr_tag, cr->cr_flags, 42803a31b7ebSMike Smith "\20\1mapped\2sleep\3poll\4dataout\5datain\n"); 42813a31b7ebSMike Smith ciss_printf(sc, " sg list/total %d/%d host tag 0x%x\n", 42823a31b7ebSMike Smith cc->header.sg_in_list, cc->header.sg_total, cc->header.host_tag); 42833a31b7ebSMike Smith switch(cc->header.address.mode.mode) { 42843a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_PERIPHERAL: 42853a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL: 42863a31b7ebSMike Smith ciss_printf(sc, " physical bus %d target %d\n", 42873a31b7ebSMike Smith cc->header.address.physical.bus, cc->header.address.physical.target); 42883a31b7ebSMike Smith break; 42893a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_LOGICAL: 42903a31b7ebSMike Smith ciss_printf(sc, " logical unit %d\n", cc->header.address.logical.lun); 42913a31b7ebSMike Smith break; 42923a31b7ebSMike Smith } 42933a31b7ebSMike Smith ciss_printf(sc, " %s cdb length %d type %s attribute %s\n", 42943a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_NONE) ? "no-I/O" : 42953a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_READ) ? "READ" : 42963a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_WRITE) ? "WRITE" : "??", 42973a31b7ebSMike Smith cc->cdb.cdb_length, 42983a31b7ebSMike Smith (cc->cdb.type == CISS_CDB_TYPE_COMMAND) ? "command" : 42993a31b7ebSMike Smith (cc->cdb.type == CISS_CDB_TYPE_MESSAGE) ? "message" : "??", 43003a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_UNTAGGED) ? "untagged" : 43013a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_SIMPLE) ? "simple" : 43023a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_HEAD_OF_QUEUE) ? "head-of-queue" : 43033a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_ORDERED) ? "ordered" : 43043a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_AUTO_CONTINGENT) ? "auto-contingent" : "??"); 43053a31b7ebSMike Smith ciss_printf(sc, " %*D\n", cc->cdb.cdb_length, &cc->cdb.cdb[0], " "); 43063a31b7ebSMike Smith 43073a31b7ebSMike Smith if (cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) { 43083a31b7ebSMike Smith /* XXX print error info */ 43093a31b7ebSMike Smith } else { 43103a31b7ebSMike Smith /* since we don't use chained s/g, don't support it here */ 43113a31b7ebSMike Smith for (i = 0; i < cc->header.sg_in_list; i++) { 43123a31b7ebSMike Smith if ((i % 4) == 0) 43133a31b7ebSMike Smith ciss_printf(sc, " "); 43143a31b7ebSMike Smith printf("0x%08x/%d ", (u_int32_t)cc->sg[i].address, cc->sg[i].length); 43153a31b7ebSMike Smith if ((((i + 1) % 4) == 0) || (i == (cc->header.sg_in_list - 1))) 43163a31b7ebSMike Smith printf("\n"); 43173a31b7ebSMike Smith } 43183a31b7ebSMike Smith } 43193a31b7ebSMike Smith } 43202e3d6d0fSWarner Losh #endif 43213a31b7ebSMike Smith 43223a31b7ebSMike Smith /************************************************************************ 43233a31b7ebSMike Smith * Print information about the status of a logical drive. 43243a31b7ebSMike Smith */ 43253a31b7ebSMike Smith static void 43263a31b7ebSMike Smith ciss_print_ldrive(struct ciss_softc *sc, struct ciss_ldrive *ld) 43273a31b7ebSMike Smith { 43283a31b7ebSMike Smith int bus, target, i; 43293a31b7ebSMike Smith 4330d4aa427fSPaul Saab if (ld->cl_lstatus == NULL) { 4331d4aa427fSPaul Saab printf("does not exist\n"); 4332d4aa427fSPaul Saab return; 4333d4aa427fSPaul Saab } 4334d4aa427fSPaul Saab 43353a31b7ebSMike Smith /* print drive status */ 43363a31b7ebSMike Smith switch(ld->cl_lstatus->status) { 43373a31b7ebSMike Smith case CISS_LSTATUS_OK: 43383a31b7ebSMike Smith printf("online\n"); 43393a31b7ebSMike Smith break; 43403a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 43413a31b7ebSMike Smith printf("in interim recovery mode\n"); 43423a31b7ebSMike Smith break; 43433a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 43443a31b7ebSMike Smith printf("ready to begin recovery\n"); 43453a31b7ebSMike Smith break; 43463a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 43473a31b7ebSMike Smith bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); 43483a31b7ebSMike Smith target = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); 43493a31b7ebSMike Smith printf("being recovered, working on physical drive %d.%d, %u blocks remaining\n", 43503a31b7ebSMike Smith bus, target, ld->cl_lstatus->blocks_to_recover); 43513a31b7ebSMike Smith break; 43523a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 43533a31b7ebSMike Smith printf("being expanded, %u blocks remaining\n", 43543a31b7ebSMike Smith ld->cl_lstatus->blocks_to_recover); 43553a31b7ebSMike Smith break; 43563a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 43573a31b7ebSMike Smith printf("queued for expansion\n"); 43583a31b7ebSMike Smith break; 43593a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 43603a31b7ebSMike Smith printf("queued for expansion\n"); 43613a31b7ebSMike Smith break; 43623a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 43633a31b7ebSMike Smith printf("wrong physical drive inserted\n"); 43643a31b7ebSMike Smith break; 43653a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 43663a31b7ebSMike Smith printf("missing a needed physical drive\n"); 43673a31b7ebSMike Smith break; 43683a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 43693a31b7ebSMike Smith printf("becoming ready\n"); 43703a31b7ebSMike Smith break; 43713a31b7ebSMike Smith } 43723a31b7ebSMike Smith 4373d4aa427fSPaul Saab /* print failed physical drives */ 43743a31b7ebSMike Smith for (i = 0; i < CISS_BIG_MAP_ENTRIES / 8; i++) { 43753a31b7ebSMike Smith bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_failure_map[i]); 43763a31b7ebSMike Smith target = CISS_BIG_MAP_TARGET(sc, ld->cl_lstatus->drive_failure_map[i]); 43773a31b7ebSMike Smith if (bus == -1) 43783a31b7ebSMike Smith continue; 43793a31b7ebSMike Smith ciss_printf(sc, "physical drive %d:%d (%x) failed\n", bus, target, 43803a31b7ebSMike Smith ld->cl_lstatus->drive_failure_map[i]); 43813a31b7ebSMike Smith } 43823a31b7ebSMike Smith } 43833a31b7ebSMike Smith 4384b27556e0SSean Bruno #ifdef DDB 4385b27556e0SSean Bruno #include <ddb/ddb.h> 4386d4aa427fSPaul Saab /************************************************************************ 4387d4aa427fSPaul Saab * Print information about the controller/driver. 4388d4aa427fSPaul Saab */ 4389d4aa427fSPaul Saab static void 4390d4aa427fSPaul Saab ciss_print_adapter(struct ciss_softc *sc) 4391d4aa427fSPaul Saab { 4392609caf8dSPaul Saab int i, j; 4393d4aa427fSPaul Saab 4394d4aa427fSPaul Saab ciss_printf(sc, "ADAPTER:\n"); 4395d4aa427fSPaul Saab for (i = 0; i < CISSQ_COUNT; i++) { 4396d4aa427fSPaul Saab ciss_printf(sc, "%s %d/%d\n", 4397d4aa427fSPaul Saab i == 0 ? "free" : 4398d4aa427fSPaul Saab i == 1 ? "busy" : "complete", 4399d4aa427fSPaul Saab sc->ciss_qstat[i].q_length, 4400d4aa427fSPaul Saab sc->ciss_qstat[i].q_max); 4401d4aa427fSPaul Saab } 4402d4aa427fSPaul Saab ciss_printf(sc, "max_requests %d\n", sc->ciss_max_requests); 4403d4aa427fSPaul Saab ciss_printf(sc, "flags %b\n", sc->ciss_flags, 4404d4aa427fSPaul Saab "\20\1notify_ok\2control_open\3aborting\4running\21fake_synch\22bmic_abort\n"); 4405d4aa427fSPaul Saab 44061fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 4407e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { 4408d4aa427fSPaul Saab ciss_printf(sc, "LOGICAL DRIVE %d: ", i); 4409609caf8dSPaul Saab ciss_print_ldrive(sc, &sc->ciss_logical[i][j]); 4410609caf8dSPaul Saab } 4411d4aa427fSPaul Saab } 4412d4aa427fSPaul Saab 44131fe6c4eeSScott Long /* XXX Should physical drives be printed out here? */ 44141fe6c4eeSScott Long 4415d4aa427fSPaul Saab for (i = 1; i < sc->ciss_max_requests; i++) 4416d4aa427fSPaul Saab ciss_print_request(sc->ciss_request + i); 4417d4aa427fSPaul Saab } 4418d4aa427fSPaul Saab 4419d4aa427fSPaul Saab /* DDB hook */ 4420b27556e0SSean Bruno DB_COMMAND(ciss_prt, db_ciss_prt) 4421d4aa427fSPaul Saab { 4422d4aa427fSPaul Saab struct ciss_softc *sc; 442311f9f6eaSSean Bruno devclass_t dc; 442411f9f6eaSSean Bruno int maxciss, i; 4425d4aa427fSPaul Saab 442611f9f6eaSSean Bruno dc = devclass_find("ciss"); 442711f9f6eaSSean Bruno if ( dc == NULL ) { 442811f9f6eaSSean Bruno printf("%s: can't find devclass!\n", __func__); 442911f9f6eaSSean Bruno return; 443011f9f6eaSSean Bruno } 443111f9f6eaSSean Bruno maxciss = devclass_get_maxunit(dc); 443211f9f6eaSSean Bruno for (i = 0; i < maxciss; i++) { 443311f9f6eaSSean Bruno sc = devclass_get_softc(dc, i); 4434d4aa427fSPaul Saab ciss_print_adapter(sc); 4435d4aa427fSPaul Saab } 4436d4aa427fSPaul Saab } 4437d4aa427fSPaul Saab #endif 4438d4aa427fSPaul Saab 44393a31b7ebSMike Smith /************************************************************************ 44403a31b7ebSMike Smith * Return a name for a logical drive status value. 44413a31b7ebSMike Smith */ 44423a31b7ebSMike Smith static const char * 44433a31b7ebSMike Smith ciss_name_ldrive_status(int status) 44443a31b7ebSMike Smith { 44453a31b7ebSMike Smith switch (status) { 44463a31b7ebSMike Smith case CISS_LSTATUS_OK: 44473a31b7ebSMike Smith return("OK"); 44483a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 44493a31b7ebSMike Smith return("failed"); 44503a31b7ebSMike Smith case CISS_LSTATUS_NOT_CONFIGURED: 44513a31b7ebSMike Smith return("not configured"); 44523a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 44533a31b7ebSMike Smith return("interim recovery"); 44543a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 44553a31b7ebSMike Smith return("ready for recovery"); 44563a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 44573a31b7ebSMike Smith return("recovering"); 44583a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 44593a31b7ebSMike Smith return("wrong physical drive inserted"); 44603a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 44613a31b7ebSMike Smith return("missing physical drive"); 44623a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 44633a31b7ebSMike Smith return("expanding"); 44643a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 44653a31b7ebSMike Smith return("becoming ready"); 44663a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 44673a31b7ebSMike Smith return("queued for expansion"); 44683a31b7ebSMike Smith } 44693a31b7ebSMike Smith return("unknown status"); 44703a31b7ebSMike Smith } 44713a31b7ebSMike Smith 44723a31b7ebSMike Smith /************************************************************************ 44733a31b7ebSMike Smith * Return an online/offline/nonexistent value for a logical drive 44743a31b7ebSMike Smith * status value. 44753a31b7ebSMike Smith */ 44763a31b7ebSMike Smith static int 44773a31b7ebSMike Smith ciss_decode_ldrive_status(int status) 44783a31b7ebSMike Smith { 44793a31b7ebSMike Smith switch(status) { 44803a31b7ebSMike Smith case CISS_LSTATUS_NOT_CONFIGURED: 44813a31b7ebSMike Smith return(CISS_LD_NONEXISTENT); 44823a31b7ebSMike Smith 44833a31b7ebSMike Smith case CISS_LSTATUS_OK: 44843a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 44853a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 44863a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 44873a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 44883a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 44893a31b7ebSMike Smith return(CISS_LD_ONLINE); 44903a31b7ebSMike Smith 44913a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 44923a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 44933a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 44943a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 44953a31b7ebSMike Smith default: 44963a31b7ebSMike Smith return(CISS_LD_OFFLINE); 44973a31b7ebSMike Smith } 44983a31b7ebSMike Smith } 44993a31b7ebSMike Smith 45003a31b7ebSMike Smith /************************************************************************ 45013a31b7ebSMike Smith * Return a name for a logical drive's organisation. 45023a31b7ebSMike Smith */ 45033a31b7ebSMike Smith static const char * 45043a31b7ebSMike Smith ciss_name_ldrive_org(int org) 45053a31b7ebSMike Smith { 45063a31b7ebSMike Smith switch(org) { 45073a31b7ebSMike Smith case CISS_LDRIVE_RAID0: 45083a31b7ebSMike Smith return("RAID 0"); 45093a31b7ebSMike Smith case CISS_LDRIVE_RAID1: 4510d000b49dSKonstantin Belousov return("RAID 1(1+0)"); 45113a31b7ebSMike Smith case CISS_LDRIVE_RAID4: 45123a31b7ebSMike Smith return("RAID 4"); 45133a31b7ebSMike Smith case CISS_LDRIVE_RAID5: 45143a31b7ebSMike Smith return("RAID 5"); 4515aaf8327bSPaul Saab case CISS_LDRIVE_RAID51: 4516aaf8327bSPaul Saab return("RAID 5+1"); 4517aaf8327bSPaul Saab case CISS_LDRIVE_RAIDADG: 4518aaf8327bSPaul Saab return("RAID ADG"); 45193a31b7ebSMike Smith } 4520b790c193SPedro F. Giffuni return("unknown"); 45213a31b7ebSMike Smith } 45223a31b7ebSMike Smith 45233a31b7ebSMike Smith /************************************************************************ 45243a31b7ebSMike Smith * Return a name for a command status value. 45253a31b7ebSMike Smith */ 45263a31b7ebSMike Smith static const char * 45273a31b7ebSMike Smith ciss_name_command_status(int status) 45283a31b7ebSMike Smith { 45293a31b7ebSMike Smith switch(status) { 45303a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 45313a31b7ebSMike Smith return("success"); 45323a31b7ebSMike Smith case CISS_CMD_STATUS_TARGET_STATUS: 45333a31b7ebSMike Smith return("target status"); 45343a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 45353a31b7ebSMike Smith return("data underrun"); 45363a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 45373a31b7ebSMike Smith return("data overrun"); 45383a31b7ebSMike Smith case CISS_CMD_STATUS_INVALID_COMMAND: 45393a31b7ebSMike Smith return("invalid command"); 45403a31b7ebSMike Smith case CISS_CMD_STATUS_PROTOCOL_ERROR: 45413a31b7ebSMike Smith return("protocol error"); 45423a31b7ebSMike Smith case CISS_CMD_STATUS_HARDWARE_ERROR: 45433a31b7ebSMike Smith return("hardware error"); 45443a31b7ebSMike Smith case CISS_CMD_STATUS_CONNECTION_LOST: 45453a31b7ebSMike Smith return("connection lost"); 45463a31b7ebSMike Smith case CISS_CMD_STATUS_ABORTED: 45473a31b7ebSMike Smith return("aborted"); 45483a31b7ebSMike Smith case CISS_CMD_STATUS_ABORT_FAILED: 45493a31b7ebSMike Smith return("abort failed"); 45503a31b7ebSMike Smith case CISS_CMD_STATUS_UNSOLICITED_ABORT: 45513a31b7ebSMike Smith return("unsolicited abort"); 45523a31b7ebSMike Smith case CISS_CMD_STATUS_TIMEOUT: 45533a31b7ebSMike Smith return("timeout"); 45543a31b7ebSMike Smith case CISS_CMD_STATUS_UNABORTABLE: 45553a31b7ebSMike Smith return("unabortable"); 45563a31b7ebSMike Smith } 45573a31b7ebSMike Smith return("unknown status"); 45583a31b7ebSMike Smith } 45593a31b7ebSMike Smith 45603a31b7ebSMike Smith /************************************************************************ 45613a31b7ebSMike Smith * Handle an open on the control device. 45623a31b7ebSMike Smith */ 45633a31b7ebSMike Smith static int 456400b4e54aSWarner Losh ciss_open(struct cdev *dev, int flags, int fmt, struct thread *p) 45653a31b7ebSMike Smith { 45663a31b7ebSMike Smith struct ciss_softc *sc; 45673a31b7ebSMike Smith 45683a31b7ebSMike Smith debug_called(1); 45693a31b7ebSMike Smith 45703a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 45713a31b7ebSMike Smith 45723a31b7ebSMike Smith /* we might want to veto if someone already has us open */ 45733a31b7ebSMike Smith 4574975b7318SScott Long mtx_lock(&sc->ciss_mtx); 45753a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_CONTROL_OPEN; 4576975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 45773a31b7ebSMike Smith return(0); 45783a31b7ebSMike Smith } 45793a31b7ebSMike Smith 45803a31b7ebSMike Smith /************************************************************************ 45813a31b7ebSMike Smith * Handle the last close on the control device. 45823a31b7ebSMike Smith */ 45833a31b7ebSMike Smith static int 458400b4e54aSWarner Losh ciss_close(struct cdev *dev, int flags, int fmt, struct thread *p) 45853a31b7ebSMike Smith { 45863a31b7ebSMike Smith struct ciss_softc *sc; 45873a31b7ebSMike Smith 45883a31b7ebSMike Smith debug_called(1); 45893a31b7ebSMike Smith 45903a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 45913a31b7ebSMike Smith 4592975b7318SScott Long mtx_lock(&sc->ciss_mtx); 45933a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_CONTROL_OPEN; 4594975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 45953a31b7ebSMike Smith return (0); 45963a31b7ebSMike Smith } 45973a31b7ebSMike Smith 45983a31b7ebSMike Smith /******************************************************************************** 45993a31b7ebSMike Smith * Handle adapter-specific control operations. 46003a31b7ebSMike Smith * 46013a31b7ebSMike Smith * Note that the API here is compatible with the Linux driver, in order to 46023a31b7ebSMike Smith * simplify the porting of Compaq's userland tools. 46033a31b7ebSMike Smith */ 46043a31b7ebSMike Smith static int 460500b4e54aSWarner Losh ciss_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *p) 46063a31b7ebSMike Smith { 46073a31b7ebSMike Smith struct ciss_softc *sc; 46087caeec6aSPaul Saab IOCTL_Command_struct *ioc = (IOCTL_Command_struct *)addr; 46097caeec6aSPaul Saab #ifdef __amd64__ 46107caeec6aSPaul Saab IOCTL_Command_struct32 *ioc32 = (IOCTL_Command_struct32 *)addr; 46117caeec6aSPaul Saab IOCTL_Command_struct ioc_swab; 46127caeec6aSPaul Saab #endif 46133a31b7ebSMike Smith int error; 46143a31b7ebSMike Smith 46153a31b7ebSMike Smith debug_called(1); 46163a31b7ebSMike Smith 46173a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 46183a31b7ebSMike Smith error = 0; 4619975b7318SScott Long mtx_lock(&sc->ciss_mtx); 46203a31b7ebSMike Smith 46213a31b7ebSMike Smith switch(cmd) { 462222657ce1SScott Long case CCISS_GETQSTATS: 462322657ce1SScott Long { 462422657ce1SScott Long union ciss_statrequest *cr = (union ciss_statrequest *)addr; 462522657ce1SScott Long 462622657ce1SScott Long switch (cr->cs_item) { 462722657ce1SScott Long case CISSQ_FREE: 462822657ce1SScott Long case CISSQ_NOTIFY: 462922657ce1SScott Long bcopy(&sc->ciss_qstat[cr->cs_item], &cr->cs_qstat, 463022657ce1SScott Long sizeof(struct ciss_qstat)); 463122657ce1SScott Long break; 463222657ce1SScott Long default: 463322657ce1SScott Long error = ENOIOCTL; 463422657ce1SScott Long break; 463522657ce1SScott Long } 463622657ce1SScott Long 463722657ce1SScott Long break; 463822657ce1SScott Long } 463922657ce1SScott Long 46403a31b7ebSMike Smith case CCISS_GETPCIINFO: 46413a31b7ebSMike Smith { 46423a31b7ebSMike Smith cciss_pci_info_struct *pis = (cciss_pci_info_struct *)addr; 46433a31b7ebSMike Smith 46443a31b7ebSMike Smith pis->bus = pci_get_bus(sc->ciss_dev); 46453a31b7ebSMike Smith pis->dev_fn = pci_get_slot(sc->ciss_dev); 4646e17ef005SSean Bruno pis->board_id = (pci_get_subvendor(sc->ciss_dev) << 16) | 4647e17ef005SSean Bruno pci_get_subdevice(sc->ciss_dev); 46483a31b7ebSMike Smith 46493a31b7ebSMike Smith break; 46503a31b7ebSMike Smith } 46513a31b7ebSMike Smith 46523a31b7ebSMike Smith case CCISS_GETINTINFO: 46533a31b7ebSMike Smith { 46543a31b7ebSMike Smith cciss_coalint_struct *cis = (cciss_coalint_struct *)addr; 46553a31b7ebSMike Smith 46563a31b7ebSMike Smith cis->delay = sc->ciss_cfg->interrupt_coalesce_delay; 46573a31b7ebSMike Smith cis->count = sc->ciss_cfg->interrupt_coalesce_count; 46583a31b7ebSMike Smith 46593a31b7ebSMike Smith break; 46603a31b7ebSMike Smith } 46613a31b7ebSMike Smith 46623a31b7ebSMike Smith case CCISS_SETINTINFO: 46633a31b7ebSMike Smith { 46643a31b7ebSMike Smith cciss_coalint_struct *cis = (cciss_coalint_struct *)addr; 46653a31b7ebSMike Smith 46663a31b7ebSMike Smith if ((cis->delay == 0) && (cis->count == 0)) { 46673a31b7ebSMike Smith error = EINVAL; 46683a31b7ebSMike Smith break; 46693a31b7ebSMike Smith } 46703a31b7ebSMike Smith 46713a31b7ebSMike Smith /* 46723a31b7ebSMike Smith * XXX apparently this is only safe if the controller is idle, 46733a31b7ebSMike Smith * we should suspend it before doing this. 46743a31b7ebSMike Smith */ 46753a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay = cis->delay; 46763a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count = cis->count; 46773a31b7ebSMike Smith 46783a31b7ebSMike Smith if (ciss_update_config(sc)) 46793a31b7ebSMike Smith error = EIO; 46803a31b7ebSMike Smith 46813a31b7ebSMike Smith /* XXX resume the controller here */ 46823a31b7ebSMike Smith break; 46833a31b7ebSMike Smith } 46843a31b7ebSMike Smith 46853a31b7ebSMike Smith case CCISS_GETNODENAME: 46863a31b7ebSMike Smith bcopy(sc->ciss_cfg->server_name, (NodeName_type *)addr, 46873a31b7ebSMike Smith sizeof(NodeName_type)); 46883a31b7ebSMike Smith break; 46893a31b7ebSMike Smith 46903a31b7ebSMike Smith case CCISS_SETNODENAME: 46913a31b7ebSMike Smith bcopy((NodeName_type *)addr, sc->ciss_cfg->server_name, 46923a31b7ebSMike Smith sizeof(NodeName_type)); 46933a31b7ebSMike Smith if (ciss_update_config(sc)) 46943a31b7ebSMike Smith error = EIO; 46953a31b7ebSMike Smith break; 46963a31b7ebSMike Smith 46973a31b7ebSMike Smith case CCISS_GETHEARTBEAT: 46983a31b7ebSMike Smith *(Heartbeat_type *)addr = sc->ciss_cfg->heartbeat; 46993a31b7ebSMike Smith break; 47003a31b7ebSMike Smith 47013a31b7ebSMike Smith case CCISS_GETBUSTYPES: 47023a31b7ebSMike Smith *(BusTypes_type *)addr = sc->ciss_cfg->bus_types; 47033a31b7ebSMike Smith break; 47043a31b7ebSMike Smith 47053a31b7ebSMike Smith case CCISS_GETFIRMVER: 47063a31b7ebSMike Smith bcopy(sc->ciss_id->running_firmware_revision, (FirmwareVer_type *)addr, 47073a31b7ebSMike Smith sizeof(FirmwareVer_type)); 47083a31b7ebSMike Smith break; 47093a31b7ebSMike Smith 47103a31b7ebSMike Smith case CCISS_GETDRIVERVER: 47113a31b7ebSMike Smith *(DriverVer_type *)addr = CISS_DRIVER_VERSION; 47123a31b7ebSMike Smith break; 47133a31b7ebSMike Smith 47143a31b7ebSMike Smith case CCISS_REVALIDVOLS: 47153a31b7ebSMike Smith /* 47163a31b7ebSMike Smith * This is a bit ugly; to do it "right" we really need 47173a31b7ebSMike Smith * to find any disks that have changed, kick CAM off them, 47183a31b7ebSMike Smith * then rescan only these disks. It'd be nice if they 47193a31b7ebSMike Smith * a) told us which disk(s) they were going to play with, 47203a31b7ebSMike Smith * and b) which ones had arrived. 8( 47213a31b7ebSMike Smith */ 47223a31b7ebSMike Smith break; 47233a31b7ebSMike Smith 47247caeec6aSPaul Saab #ifdef __amd64__ 47257caeec6aSPaul Saab case CCISS_PASSTHRU32: 47267caeec6aSPaul Saab ioc_swab.LUN_info = ioc32->LUN_info; 47277caeec6aSPaul Saab ioc_swab.Request = ioc32->Request; 47287caeec6aSPaul Saab ioc_swab.error_info = ioc32->error_info; 47297caeec6aSPaul Saab ioc_swab.buf_size = ioc32->buf_size; 47307caeec6aSPaul Saab ioc_swab.buf = (u_int8_t *)(uintptr_t)ioc32->buf; 47317caeec6aSPaul Saab ioc = &ioc_swab; 47327caeec6aSPaul Saab /* FALLTHROUGH */ 47337caeec6aSPaul Saab #endif 47347caeec6aSPaul Saab 47353a31b7ebSMike Smith case CCISS_PASSTHRU: 47367caeec6aSPaul Saab error = ciss_user_command(sc, ioc); 47373a31b7ebSMike Smith break; 47383a31b7ebSMike Smith 47393a31b7ebSMike Smith default: 47403a31b7ebSMike Smith debug(0, "unknown ioctl 0x%lx", cmd); 47413a31b7ebSMike Smith 47423a31b7ebSMike Smith debug(1, "CCISS_GETPCIINFO: 0x%lx", CCISS_GETPCIINFO); 47433a31b7ebSMike Smith debug(1, "CCISS_GETINTINFO: 0x%lx", CCISS_GETINTINFO); 47443a31b7ebSMike Smith debug(1, "CCISS_SETINTINFO: 0x%lx", CCISS_SETINTINFO); 47453a31b7ebSMike Smith debug(1, "CCISS_GETNODENAME: 0x%lx", CCISS_GETNODENAME); 47463a31b7ebSMike Smith debug(1, "CCISS_SETNODENAME: 0x%lx", CCISS_SETNODENAME); 47473a31b7ebSMike Smith debug(1, "CCISS_GETHEARTBEAT: 0x%lx", CCISS_GETHEARTBEAT); 47483a31b7ebSMike Smith debug(1, "CCISS_GETBUSTYPES: 0x%lx", CCISS_GETBUSTYPES); 47493a31b7ebSMike Smith debug(1, "CCISS_GETFIRMVER: 0x%lx", CCISS_GETFIRMVER); 47503a31b7ebSMike Smith debug(1, "CCISS_GETDRIVERVER: 0x%lx", CCISS_GETDRIVERVER); 47513a31b7ebSMike Smith debug(1, "CCISS_REVALIDVOLS: 0x%lx", CCISS_REVALIDVOLS); 47523a31b7ebSMike Smith debug(1, "CCISS_PASSTHRU: 0x%lx", CCISS_PASSTHRU); 47533a31b7ebSMike Smith 47543a31b7ebSMike Smith error = ENOIOCTL; 47553a31b7ebSMike Smith break; 47563a31b7ebSMike Smith } 47573a31b7ebSMike Smith 4758975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 47593a31b7ebSMike Smith return(error); 47603a31b7ebSMike Smith } 4761