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 /* 24874575d14SPeter Eriksson * This tunable can be used to force a specific value for transfer speed. 24974575d14SPeter Eriksson */ 25074575d14SPeter Eriksson static int ciss_base_transfer_speed = 132 * 1024; 25174575d14SPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, base_transfer_speed, CTLFLAG_RDTUN, 25274575d14SPeter Eriksson &ciss_base_transfer_speed, 0, 25374575d14SPeter Eriksson "force a specific base transfer_speed"); 25474575d14SPeter Eriksson 2551fe6c4eeSScott Long /* 256f373e6b8SPeter Eriksson * This tunable can be set to make the driver be more verbose 257f373e6b8SPeter Eriksson */ 258f373e6b8SPeter Eriksson static int ciss_verbose = 0; 259f373e6b8SPeter Eriksson SYSCTL_INT(_hw_ciss, OID_AUTO, verbose, CTLFLAG_RWTUN, &ciss_verbose, 0, 260f373e6b8SPeter Eriksson "enable verbose messages"); 261f373e6b8SPeter Eriksson 262f373e6b8SPeter Eriksson /* 2631fe6c4eeSScott Long * This tunable can be set at boot time and controls whether physical devices 2641fe6c4eeSScott Long * that are marked hidden by the firmware should be exposed anyways. 2651fe6c4eeSScott Long */ 2661fe6c4eeSScott Long static unsigned int ciss_expose_hidden_physical = 0; 2671fe6c4eeSScott Long TUNABLE_INT("hw.ciss.expose_hidden_physical", &ciss_expose_hidden_physical); 2681fe6c4eeSScott Long 2695a3c4d69SMitsuru IWASAKI static unsigned int ciss_nop_message_heartbeat = 0; 2705a3c4d69SMitsuru IWASAKI TUNABLE_INT("hw.ciss.nop_message_heartbeat", &ciss_nop_message_heartbeat); 2715a3c4d69SMitsuru IWASAKI 27222657ce1SScott Long /* 27322657ce1SScott Long * This tunable can force a particular transport to be used: 27422657ce1SScott Long * <= 0 : use default 27522657ce1SScott Long * 1 : force simple 27622657ce1SScott Long * 2 : force performant 27722657ce1SScott Long */ 27822657ce1SScott Long static int ciss_force_transport = 0; 27922657ce1SScott Long TUNABLE_INT("hw.ciss.force_transport", &ciss_force_transport); 28022657ce1SScott Long 28122657ce1SScott Long /* 28222657ce1SScott Long * This tunable can force a particular interrupt delivery method to be used: 28322657ce1SScott Long * <= 0 : use default 28422657ce1SScott Long * 1 : force INTx 28522657ce1SScott Long * 2 : force MSIX 28622657ce1SScott Long */ 28722657ce1SScott Long static int ciss_force_interrupt = 0; 28822657ce1SScott Long TUNABLE_INT("hw.ciss.force_interrupt", &ciss_force_interrupt); 28922657ce1SScott Long 2903a31b7ebSMike Smith /************************************************************************ 2913a31b7ebSMike Smith * CISS adapters amazingly don't have a defined programming interface 2923a31b7ebSMike Smith * value. (One could say some very despairing things about PCI and 2933a31b7ebSMike Smith * people just not getting the general idea.) So we are forced to 2943a31b7ebSMike Smith * stick with matching against subvendor/subdevice, and thus have to 2953a31b7ebSMike Smith * be updated for every new CISS adapter that appears. 2963a31b7ebSMike Smith */ 2974e2ddfbaSWarner Losh #define CISS_BOARD_UNKNOWN 0 2982fdaa90dSScott Long #define CISS_BOARD_SA5 1 2992fdaa90dSScott Long #define CISS_BOARD_SA5B 2 3002fdaa90dSScott Long #define CISS_BOARD_NOMSI (1<<4) 301ee4827b2SSean Bruno #define CISS_BOARD_SIMPLE (1<<5) 3023a31b7ebSMike Smith 3033a31b7ebSMike Smith static struct 3043a31b7ebSMike Smith { 3053a31b7ebSMike Smith u_int16_t subvendor; 3063a31b7ebSMike Smith u_int16_t subdevice; 3073a31b7ebSMike Smith int flags; 3083a31b7ebSMike Smith char *desc; 3093a31b7ebSMike Smith } ciss_vendor_data[] = { 310ee4827b2SSean Bruno { 0x0e11, 0x4070, CISS_BOARD_SA5|CISS_BOARD_NOMSI|CISS_BOARD_SIMPLE, 311ee4827b2SSean Bruno "Compaq Smart Array 5300" }, 3122fdaa90dSScott Long { 0x0e11, 0x4080, CISS_BOARD_SA5B|CISS_BOARD_NOMSI, "Compaq Smart Array 5i" }, 3132fdaa90dSScott Long { 0x0e11, 0x4082, CISS_BOARD_SA5B|CISS_BOARD_NOMSI, "Compaq Smart Array 532" }, 3142fdaa90dSScott Long { 0x0e11, 0x4083, CISS_BOARD_SA5B|CISS_BOARD_NOMSI, "HP Smart Array 5312" }, 315b26392c7SPaul Saab { 0x0e11, 0x4091, CISS_BOARD_SA5, "HP Smart Array 6i" }, 3169e7313bbSPaul Saab { 0x0e11, 0x409A, CISS_BOARD_SA5, "HP Smart Array 641" }, 3179e7313bbSPaul Saab { 0x0e11, 0x409B, CISS_BOARD_SA5, "HP Smart Array 642" }, 3189e7313bbSPaul Saab { 0x0e11, 0x409C, CISS_BOARD_SA5, "HP Smart Array 6400" }, 3199e7313bbSPaul Saab { 0x0e11, 0x409D, CISS_BOARD_SA5, "HP Smart Array 6400 EM" }, 320cad572c4SPaul Saab { 0x103C, 0x3211, CISS_BOARD_SA5, "HP Smart Array E200i" }, 321cad572c4SPaul Saab { 0x103C, 0x3212, CISS_BOARD_SA5, "HP Smart Array E200" }, 322cad572c4SPaul Saab { 0x103C, 0x3213, CISS_BOARD_SA5, "HP Smart Array E200i" }, 323cad572c4SPaul Saab { 0x103C, 0x3214, CISS_BOARD_SA5, "HP Smart Array E200i" }, 324cad572c4SPaul Saab { 0x103C, 0x3215, CISS_BOARD_SA5, "HP Smart Array E200i" }, 325b612d5e1SPaul Saab { 0x103C, 0x3220, CISS_BOARD_SA5, "HP Smart Array" }, 326b612d5e1SPaul Saab { 0x103C, 0x3222, CISS_BOARD_SA5, "HP Smart Array" }, 3274bb10cf1SPaul Saab { 0x103C, 0x3223, CISS_BOARD_SA5, "HP Smart Array P800" }, 328f3f82767SPaul Saab { 0x103C, 0x3225, CISS_BOARD_SA5, "HP Smart Array P600" }, 329b612d5e1SPaul Saab { 0x103C, 0x3230, CISS_BOARD_SA5, "HP Smart Array" }, 330cad572c4SPaul Saab { 0x103C, 0x3231, CISS_BOARD_SA5, "HP Smart Array" }, 331b612d5e1SPaul Saab { 0x103C, 0x3232, CISS_BOARD_SA5, "HP Smart Array" }, 332b612d5e1SPaul Saab { 0x103C, 0x3233, CISS_BOARD_SA5, "HP Smart Array" }, 333cad572c4SPaul Saab { 0x103C, 0x3234, CISS_BOARD_SA5, "HP Smart Array P400" }, 334cad572c4SPaul Saab { 0x103C, 0x3235, CISS_BOARD_SA5, "HP Smart Array P400i" }, 335b612d5e1SPaul Saab { 0x103C, 0x3236, CISS_BOARD_SA5, "HP Smart Array" }, 3367b6d3d4cSScott Long { 0x103C, 0x3237, CISS_BOARD_SA5, "HP Smart Array E500" }, 337b612d5e1SPaul Saab { 0x103C, 0x3238, CISS_BOARD_SA5, "HP Smart Array" }, 338b612d5e1SPaul Saab { 0x103C, 0x3239, CISS_BOARD_SA5, "HP Smart Array" }, 339b612d5e1SPaul Saab { 0x103C, 0x323A, CISS_BOARD_SA5, "HP Smart Array" }, 340b612d5e1SPaul Saab { 0x103C, 0x323B, CISS_BOARD_SA5, "HP Smart Array" }, 341b612d5e1SPaul Saab { 0x103C, 0x323C, CISS_BOARD_SA5, "HP Smart Array" }, 3427b6d3d4cSScott Long { 0x103C, 0x323D, CISS_BOARD_SA5, "HP Smart Array P700m" }, 343160b4e6bSPaul Saab { 0x103C, 0x3241, CISS_BOARD_SA5, "HP Smart Array P212" }, 344160b4e6bSPaul Saab { 0x103C, 0x3243, CISS_BOARD_SA5, "HP Smart Array P410" }, 345160b4e6bSPaul Saab { 0x103C, 0x3245, CISS_BOARD_SA5, "HP Smart Array P410i" }, 346160b4e6bSPaul Saab { 0x103C, 0x3247, CISS_BOARD_SA5, "HP Smart Array P411" }, 347160b4e6bSPaul Saab { 0x103C, 0x3249, CISS_BOARD_SA5, "HP Smart Array P812" }, 3487b6d3d4cSScott Long { 0x103C, 0x324A, CISS_BOARD_SA5, "HP Smart Array P712m" }, 3497b6d3d4cSScott Long { 0x103C, 0x324B, CISS_BOARD_SA5, "HP Smart Array" }, 350e17ef005SSean Bruno { 0x103C, 0x3350, CISS_BOARD_SA5, "HP Smart Array P222" }, 3515564c1cdSSean Bruno { 0x103C, 0x3351, CISS_BOARD_SA5, "HP Smart Array P420" }, 352e17ef005SSean Bruno { 0x103C, 0x3352, CISS_BOARD_SA5, "HP Smart Array P421" }, 353e17ef005SSean Bruno { 0x103C, 0x3353, CISS_BOARD_SA5, "HP Smart Array P822" }, 354e17ef005SSean Bruno { 0x103C, 0x3354, CISS_BOARD_SA5, "HP Smart Array P420i" }, 355e17ef005SSean Bruno { 0x103C, 0x3355, CISS_BOARD_SA5, "HP Smart Array P220i" }, 356e17ef005SSean Bruno { 0x103C, 0x3356, CISS_BOARD_SA5, "HP Smart Array P721m" }, 357ec5d9810SSean Bruno { 0x103C, 0x1920, CISS_BOARD_SA5, "HP Smart Array P430i" }, 358ec5d9810SSean Bruno { 0x103C, 0x1921, CISS_BOARD_SA5, "HP Smart Array P830i" }, 359ec5d9810SSean Bruno { 0x103C, 0x1922, CISS_BOARD_SA5, "HP Smart Array P430" }, 360ec5d9810SSean Bruno { 0x103C, 0x1923, CISS_BOARD_SA5, "HP Smart Array P431" }, 361ec5d9810SSean Bruno { 0x103C, 0x1924, CISS_BOARD_SA5, "HP Smart Array P830" }, 362ec5d9810SSean Bruno { 0x103C, 0x1926, CISS_BOARD_SA5, "HP Smart Array P731m" }, 363ec5d9810SSean Bruno { 0x103C, 0x1928, CISS_BOARD_SA5, "HP Smart Array P230i" }, 364ec5d9810SSean Bruno { 0x103C, 0x1929, CISS_BOARD_SA5, "HP Smart Array P530" }, 365ec5d9810SSean Bruno { 0x103C, 0x192A, CISS_BOARD_SA5, "HP Smart Array P531" }, 366bf10f1a0SSean Bruno { 0x103C, 0x21BD, CISS_BOARD_SA5, "HP Smart Array P244br" }, 367bf10f1a0SSean Bruno { 0x103C, 0x21BE, CISS_BOARD_SA5, "HP Smart Array P741m" }, 368bf10f1a0SSean Bruno { 0x103C, 0x21BF, CISS_BOARD_SA5, "HP Smart Array H240ar" }, 369bf10f1a0SSean Bruno { 0x103C, 0x21C0, CISS_BOARD_SA5, "HP Smart Array P440ar" }, 370bf10f1a0SSean Bruno { 0x103C, 0x21C1, CISS_BOARD_SA5, "HP Smart Array P840ar" }, 371bf10f1a0SSean Bruno { 0x103C, 0x21C2, CISS_BOARD_SA5, "HP Smart Array P440" }, 372bf10f1a0SSean Bruno { 0x103C, 0x21C3, CISS_BOARD_SA5, "HP Smart Array P441" }, 373bf10f1a0SSean Bruno { 0x103C, 0x21C5, CISS_BOARD_SA5, "HP Smart Array P841" }, 374bf10f1a0SSean Bruno { 0x103C, 0x21C6, CISS_BOARD_SA5, "HP Smart Array H244br" }, 375bf10f1a0SSean Bruno { 0x103C, 0x21C7, CISS_BOARD_SA5, "HP Smart Array H240" }, 376bf10f1a0SSean Bruno { 0x103C, 0x21C8, CISS_BOARD_SA5, "HP Smart Array H241" }, 377bf10f1a0SSean Bruno { 0x103C, 0x21CA, CISS_BOARD_SA5, "HP Smart Array P246br" }, 378bf10f1a0SSean Bruno { 0x103C, 0x21CB, CISS_BOARD_SA5, "HP Smart Array P840" }, 379d3d9a343SScott Long { 0x103C, 0x21CC, CISS_BOARD_SA5, "HP Smart Array P542d" }, 380bf10f1a0SSean Bruno { 0x103C, 0x21CD, CISS_BOARD_SA5, "HP Smart Array P240nr" }, 381bf10f1a0SSean Bruno { 0x103C, 0x21CE, CISS_BOARD_SA5, "HP Smart Array H240nr" }, 3824a6a94d8SArchie Cobbs { 0, 0, 0, NULL } 3833a31b7ebSMike Smith }; 3843a31b7ebSMike Smith 3856b66c298SJohn Baldwin DRIVER_MODULE(ciss, pci, ciss_pci_driver, 0, 0); 3864322d107SWarner Losh MODULE_PNP_INFO("U16:vendor;U16:device;", pci, ciss, ciss_vendor_data, 387329e817fSWarner Losh nitems(ciss_vendor_data) - 1); 3884322d107SWarner Losh MODULE_DEPEND(ciss, cam, 1, 1, 1); 3894322d107SWarner Losh MODULE_DEPEND(ciss, pci, 1, 1, 1); 3904322d107SWarner Losh 3913a31b7ebSMike Smith /************************************************************************ 3923a31b7ebSMike Smith * Find a match for the device in our list of known adapters. 3933a31b7ebSMike Smith */ 3943a31b7ebSMike Smith static int 3953a31b7ebSMike Smith ciss_lookup(device_t dev) 3963a31b7ebSMike Smith { 3973a31b7ebSMike Smith int i; 3983a31b7ebSMike Smith 3993a31b7ebSMike Smith for (i = 0; ciss_vendor_data[i].desc != NULL; i++) 4003a31b7ebSMike Smith if ((pci_get_subvendor(dev) == ciss_vendor_data[i].subvendor) && 4013a31b7ebSMike Smith (pci_get_subdevice(dev) == ciss_vendor_data[i].subdevice)) { 4023a31b7ebSMike Smith return(i); 4033a31b7ebSMike Smith } 4043a31b7ebSMike Smith return(-1); 4053a31b7ebSMike Smith } 4063a31b7ebSMike Smith 4073a31b7ebSMike Smith /************************************************************************ 4083a31b7ebSMike Smith * Match a known CISS adapter. 4093a31b7ebSMike Smith */ 4103a31b7ebSMike Smith static int 4113a31b7ebSMike Smith ciss_probe(device_t dev) 4123a31b7ebSMike Smith { 4133a31b7ebSMike Smith int i; 4143a31b7ebSMike Smith 4153a31b7ebSMike Smith i = ciss_lookup(dev); 4163a31b7ebSMike Smith if (i != -1) { 4173a31b7ebSMike Smith device_set_desc(dev, ciss_vendor_data[i].desc); 418538565c4SWarner Losh return(BUS_PROBE_DEFAULT); 4193a31b7ebSMike Smith } 4203a31b7ebSMike Smith return(ENOENT); 4213a31b7ebSMike Smith } 4223a31b7ebSMike Smith 4233a31b7ebSMike Smith /************************************************************************ 4243a31b7ebSMike Smith * Attach the driver to this adapter. 4253a31b7ebSMike Smith */ 4263a31b7ebSMike Smith static int 4273a31b7ebSMike Smith ciss_attach(device_t dev) 4283a31b7ebSMike Smith { 4293a31b7ebSMike Smith struct ciss_softc *sc; 430d69c9c78SScott Long int error; 4313a31b7ebSMike Smith 4323a31b7ebSMike Smith debug_called(1); 4333a31b7ebSMike Smith 4343a31b7ebSMike Smith #ifdef CISS_DEBUG 4353a31b7ebSMike Smith /* print structure/union sizes */ 4363a31b7ebSMike Smith debug_struct(ciss_command); 4373a31b7ebSMike Smith debug_struct(ciss_header); 4383a31b7ebSMike Smith debug_union(ciss_device_address); 4393a31b7ebSMike Smith debug_struct(ciss_cdb); 4403a31b7ebSMike Smith debug_struct(ciss_report_cdb); 4413a31b7ebSMike Smith debug_struct(ciss_notify_cdb); 4423a31b7ebSMike Smith debug_struct(ciss_notify); 4433a31b7ebSMike Smith debug_struct(ciss_message_cdb); 4443a31b7ebSMike Smith debug_struct(ciss_error_info_pointer); 4453a31b7ebSMike Smith debug_struct(ciss_error_info); 4463a31b7ebSMike Smith debug_struct(ciss_sg_entry); 4473a31b7ebSMike Smith debug_struct(ciss_config_table); 4483a31b7ebSMike Smith debug_struct(ciss_bmic_cdb); 4493a31b7ebSMike Smith debug_struct(ciss_bmic_id_ldrive); 4503a31b7ebSMike Smith debug_struct(ciss_bmic_id_lstatus); 4513a31b7ebSMike Smith debug_struct(ciss_bmic_id_table); 4523a31b7ebSMike Smith debug_struct(ciss_bmic_id_pdrive); 4533a31b7ebSMike Smith debug_struct(ciss_bmic_blink_pdrive); 4543a31b7ebSMike Smith debug_struct(ciss_bmic_flush_cache); 4553a31b7ebSMike Smith debug_const(CISS_MAX_REQUESTS); 4563a31b7ebSMike Smith debug_const(CISS_MAX_LOGICAL); 4573a31b7ebSMike Smith debug_const(CISS_INTERRUPT_COALESCE_DELAY); 4583a31b7ebSMike Smith debug_const(CISS_INTERRUPT_COALESCE_COUNT); 4593a31b7ebSMike Smith debug_const(CISS_COMMAND_ALLOC_SIZE); 4603a31b7ebSMike Smith debug_const(CISS_COMMAND_SG_LENGTH); 4613a31b7ebSMike Smith 4623a31b7ebSMike Smith debug_type(cciss_pci_info_struct); 4633a31b7ebSMike Smith debug_type(cciss_coalint_struct); 4643a31b7ebSMike Smith debug_type(cciss_coalint_struct); 4653a31b7ebSMike Smith debug_type(NodeName_type); 4663a31b7ebSMike Smith debug_type(NodeName_type); 4673a31b7ebSMike Smith debug_type(Heartbeat_type); 4683a31b7ebSMike Smith debug_type(BusTypes_type); 4693a31b7ebSMike Smith debug_type(FirmwareVer_type); 4703a31b7ebSMike Smith debug_type(DriverVer_type); 4713a31b7ebSMike Smith debug_type(IOCTL_Command_struct); 4723a31b7ebSMike Smith #endif 4733a31b7ebSMike Smith 4743a31b7ebSMike Smith sc = device_get_softc(dev); 4753a31b7ebSMike Smith sc->ciss_dev = dev; 47664a026bdSGavin Atkinson mtx_init(&sc->ciss_mtx, "cissmtx", NULL, MTX_DEF); 477aa1385cdSJohn Baldwin callout_init_mtx(&sc->ciss_periodic, &sc->ciss_mtx, 0); 4783a31b7ebSMike Smith 4793a31b7ebSMike Smith /* 4803a31b7ebSMike Smith * Do PCI-specific init. 4813a31b7ebSMike Smith */ 4823a31b7ebSMike Smith if ((error = ciss_init_pci(sc)) != 0) 4833a31b7ebSMike Smith goto out; 4843a31b7ebSMike Smith 4853a31b7ebSMike Smith /* 4863a31b7ebSMike Smith * Initialise driver queues. 4873a31b7ebSMike Smith */ 4883a31b7ebSMike Smith ciss_initq_free(sc); 489c6131460SPaul Saab ciss_initq_notify(sc); 4903a31b7ebSMike Smith 4913a31b7ebSMike Smith /* 492b790c193SPedro F. Giffuni * Initialize device sysctls. 49317c0792dSPaul Saab */ 49417c0792dSPaul Saab ciss_init_sysctl(sc); 49517c0792dSPaul Saab 49617c0792dSPaul Saab /* 4973a31b7ebSMike Smith * Initialise command/request pool. 4983a31b7ebSMike Smith */ 4993a31b7ebSMike Smith if ((error = ciss_init_requests(sc)) != 0) 5003a31b7ebSMike Smith goto out; 5013a31b7ebSMike Smith 5023a31b7ebSMike Smith /* 5033a31b7ebSMike Smith * Get adapter information. 5043a31b7ebSMike Smith */ 5053a31b7ebSMike Smith if ((error = ciss_identify_adapter(sc)) != 0) 5063a31b7ebSMike Smith goto out; 5073a31b7ebSMike Smith 5083a31b7ebSMike Smith /* 509c6131460SPaul Saab * Find all the physical devices. 510c6131460SPaul Saab */ 511c6131460SPaul Saab if ((error = ciss_init_physical(sc)) != 0) 512c6131460SPaul Saab goto out; 513c6131460SPaul Saab 514c6131460SPaul Saab /* 5153a31b7ebSMike Smith * Build our private table of logical devices. 5163a31b7ebSMike Smith */ 5173a31b7ebSMike Smith if ((error = ciss_init_logical(sc)) != 0) 5183a31b7ebSMike Smith goto out; 5193a31b7ebSMike Smith 5203a31b7ebSMike Smith /* 5213a31b7ebSMike Smith * Enable interrupts so that the CAM scan can complete. 5223a31b7ebSMike Smith */ 5233a31b7ebSMike Smith CISS_TL_SIMPLE_ENABLE_INTERRUPTS(sc); 5243a31b7ebSMike Smith 5253a31b7ebSMike Smith /* 5263a31b7ebSMike Smith * Initialise the CAM interface. 5273a31b7ebSMike Smith */ 5283a31b7ebSMike Smith if ((error = ciss_cam_init(sc)) != 0) 5293a31b7ebSMike Smith goto out; 5303a31b7ebSMike Smith 5313a31b7ebSMike Smith /* 5323a31b7ebSMike Smith * Start the heartbeat routine and event chain. 5333a31b7ebSMike Smith */ 5343a31b7ebSMike Smith ciss_periodic(sc); 5353a31b7ebSMike Smith 5363a31b7ebSMike Smith /* 5373a31b7ebSMike Smith * Create the control device. 5383a31b7ebSMike Smith */ 5393a31b7ebSMike Smith sc->ciss_dev_t = make_dev(&ciss_cdevsw, device_get_unit(sc->ciss_dev), 5403a31b7ebSMike Smith UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, 5413a31b7ebSMike Smith "ciss%d", device_get_unit(sc->ciss_dev)); 5423a31b7ebSMike Smith sc->ciss_dev_t->si_drv1 = sc; 5433a31b7ebSMike Smith 5443a31b7ebSMike Smith /* 5453a31b7ebSMike Smith * The adapter is running; synchronous commands can now sleep 5463a31b7ebSMike Smith * waiting for an interrupt to signal completion. 5473a31b7ebSMike Smith */ 5483a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_RUNNING; 5493a31b7ebSMike Smith 550c6131460SPaul Saab ciss_spawn_notify_thread(sc); 551c6131460SPaul Saab 5523a31b7ebSMike Smith error = 0; 5533a31b7ebSMike Smith out: 55464a026bdSGavin Atkinson if (error != 0) { 55564a026bdSGavin Atkinson /* ciss_free() expects the mutex to be held */ 55664a026bdSGavin Atkinson mtx_lock(&sc->ciss_mtx); 5573a31b7ebSMike Smith ciss_free(sc); 55864a026bdSGavin Atkinson } 5593a31b7ebSMike Smith return(error); 5603a31b7ebSMike Smith } 5613a31b7ebSMike Smith 5623a31b7ebSMike Smith /************************************************************************ 5633a31b7ebSMike Smith * Detach the driver from this adapter. 5643a31b7ebSMike Smith */ 5653a31b7ebSMike Smith static int 5663a31b7ebSMike Smith ciss_detach(device_t dev) 5673a31b7ebSMike Smith { 5683a31b7ebSMike Smith struct ciss_softc *sc = device_get_softc(dev); 5693a31b7ebSMike Smith 5703a31b7ebSMike Smith debug_called(1); 5713a31b7ebSMike Smith 572975b7318SScott Long mtx_lock(&sc->ciss_mtx); 573975b7318SScott Long if (sc->ciss_flags & CISS_FLAG_CONTROL_OPEN) { 574975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 575ffdf82e1SPaul Saab return (EBUSY); 576975b7318SScott Long } 577ffdf82e1SPaul Saab 5783a31b7ebSMike Smith /* flush adapter cache */ 5793a31b7ebSMike Smith ciss_flush_adapter(sc); 5803a31b7ebSMike Smith 581975b7318SScott Long /* release all resources. The mutex is released and freed here too. */ 5823a31b7ebSMike Smith ciss_free(sc); 5833a31b7ebSMike Smith 5843a31b7ebSMike Smith return(0); 5853a31b7ebSMike Smith } 5863a31b7ebSMike Smith 5873a31b7ebSMike Smith /************************************************************************ 5883a31b7ebSMike Smith * Prepare adapter for system shutdown. 5893a31b7ebSMike Smith */ 5903a31b7ebSMike Smith static int 5913a31b7ebSMike Smith ciss_shutdown(device_t dev) 5923a31b7ebSMike Smith { 5933a31b7ebSMike Smith struct ciss_softc *sc = device_get_softc(dev); 5943a31b7ebSMike Smith 5953a31b7ebSMike Smith debug_called(1); 5963a31b7ebSMike Smith 597d4a4ddc6SScott Long mtx_lock(&sc->ciss_mtx); 5983a31b7ebSMike Smith /* flush adapter cache */ 5993a31b7ebSMike Smith ciss_flush_adapter(sc); 6003a31b7ebSMike Smith 60117c0792dSPaul Saab if (sc->ciss_soft_reset) 60217c0792dSPaul Saab ciss_soft_reset(sc); 603d4a4ddc6SScott Long mtx_unlock(&sc->ciss_mtx); 60417c0792dSPaul Saab 6053a31b7ebSMike Smith return(0); 6063a31b7ebSMike Smith } 6073a31b7ebSMike Smith 60817c0792dSPaul Saab static void 60917c0792dSPaul Saab ciss_init_sysctl(struct ciss_softc *sc) 61017c0792dSPaul Saab { 61117c0792dSPaul Saab 61217c0792dSPaul Saab SYSCTL_ADD_INT(device_get_sysctl_ctx(sc->ciss_dev), 61317c0792dSPaul Saab SYSCTL_CHILDREN(device_get_sysctl_tree(sc->ciss_dev)), 61417c0792dSPaul Saab OID_AUTO, "soft_reset", CTLFLAG_RW, &sc->ciss_soft_reset, 0, ""); 61517c0792dSPaul Saab } 61617c0792dSPaul Saab 6173a31b7ebSMike Smith /************************************************************************ 6183a31b7ebSMike Smith * Perform PCI-specific attachment actions. 6193a31b7ebSMike Smith */ 6203a31b7ebSMike Smith static int 6213a31b7ebSMike Smith ciss_init_pci(struct ciss_softc *sc) 6223a31b7ebSMike Smith { 6233a31b7ebSMike Smith uintptr_t cbase, csize, cofs; 62422657ce1SScott Long uint32_t method, supported_methods; 625d69c9c78SScott Long int error, sqmask, i; 62622657ce1SScott Long void *intr; 6273a31b7ebSMike Smith 6283a31b7ebSMike Smith debug_called(1); 6293a31b7ebSMike Smith 6303a31b7ebSMike Smith /* 631d69c9c78SScott Long * Work out adapter type. 632d69c9c78SScott Long */ 633d69c9c78SScott Long i = ciss_lookup(sc->ciss_dev); 634d69c9c78SScott Long if (i < 0) { 635d69c9c78SScott Long ciss_printf(sc, "unknown adapter type\n"); 636d69c9c78SScott Long return (ENXIO); 637d69c9c78SScott Long } 638d69c9c78SScott Long 639d69c9c78SScott Long if (ciss_vendor_data[i].flags & CISS_BOARD_SA5) { 640d69c9c78SScott Long sqmask = CISS_TL_SIMPLE_INTR_OPQ_SA5; 641d69c9c78SScott Long } else if (ciss_vendor_data[i].flags & CISS_BOARD_SA5B) { 642d69c9c78SScott Long sqmask = CISS_TL_SIMPLE_INTR_OPQ_SA5B; 643d69c9c78SScott Long } else { 644d69c9c78SScott Long /* 645d69c9c78SScott Long * XXX Big hammer, masks/unmasks all possible interrupts. This should 646d69c9c78SScott Long * work on all hardware variants. Need to add code to handle the 647b790c193SPedro F. Giffuni * "controller crashed" interrupt bit that this unmasks. 648d69c9c78SScott Long */ 649d69c9c78SScott Long sqmask = ~0; 650d69c9c78SScott Long } 651d69c9c78SScott Long 652d69c9c78SScott Long /* 6533a31b7ebSMike Smith * Allocate register window first (we need this to find the config 6543a31b7ebSMike Smith * struct). 6553a31b7ebSMike Smith */ 6563a31b7ebSMike Smith error = ENXIO; 6573a31b7ebSMike Smith sc->ciss_regs_rid = CISS_TL_SIMPLE_BAR_REGS; 6583a31b7ebSMike Smith if ((sc->ciss_regs_resource = 6595f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, 6605f96beb9SNate Lawson &sc->ciss_regs_rid, RF_ACTIVE)) == NULL) { 6613a31b7ebSMike Smith ciss_printf(sc, "can't allocate register window\n"); 6623a31b7ebSMike Smith return(ENXIO); 6633a31b7ebSMike Smith } 6643a31b7ebSMike Smith sc->ciss_regs_bhandle = rman_get_bushandle(sc->ciss_regs_resource); 6653a31b7ebSMike Smith sc->ciss_regs_btag = rman_get_bustag(sc->ciss_regs_resource); 6663a31b7ebSMike Smith 6673a31b7ebSMike Smith /* 6683a31b7ebSMike Smith * Find the BAR holding the config structure. If it's not the one 6693a31b7ebSMike Smith * we already mapped for registers, map it too. 6703a31b7ebSMike Smith */ 6713a31b7ebSMike Smith sc->ciss_cfg_rid = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_BAR) & 0xffff; 6723a31b7ebSMike Smith if (sc->ciss_cfg_rid != sc->ciss_regs_rid) { 6733a31b7ebSMike Smith if ((sc->ciss_cfg_resource = 6745f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, 6755f96beb9SNate Lawson &sc->ciss_cfg_rid, RF_ACTIVE)) == NULL) { 6763a31b7ebSMike Smith ciss_printf(sc, "can't allocate config window\n"); 6773a31b7ebSMike Smith return(ENXIO); 6783a31b7ebSMike Smith } 6793a31b7ebSMike Smith cbase = (uintptr_t)rman_get_virtual(sc->ciss_cfg_resource); 6803a31b7ebSMike Smith csize = rman_get_end(sc->ciss_cfg_resource) - 6813a31b7ebSMike Smith rman_get_start(sc->ciss_cfg_resource) + 1; 6823a31b7ebSMike Smith } else { 6833a31b7ebSMike Smith cbase = (uintptr_t)rman_get_virtual(sc->ciss_regs_resource); 6843a31b7ebSMike Smith csize = rman_get_end(sc->ciss_regs_resource) - 6853a31b7ebSMike Smith rman_get_start(sc->ciss_regs_resource) + 1; 6863a31b7ebSMike Smith } 6873a31b7ebSMike Smith cofs = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_OFF); 6883a31b7ebSMike Smith 6893a31b7ebSMike Smith /* 6903a31b7ebSMike Smith * Use the base/size/offset values we just calculated to 6913a31b7ebSMike Smith * sanity-check the config structure. If it's OK, point to it. 6923a31b7ebSMike Smith */ 6933a31b7ebSMike Smith if ((cofs + sizeof(struct ciss_config_table)) > csize) { 6943a31b7ebSMike Smith ciss_printf(sc, "config table outside window\n"); 6953a31b7ebSMike Smith return(ENXIO); 6963a31b7ebSMike Smith } 6973a31b7ebSMike Smith sc->ciss_cfg = (struct ciss_config_table *)(cbase + cofs); 6983a31b7ebSMike Smith debug(1, "config struct at %p", sc->ciss_cfg); 6993a31b7ebSMike Smith 7003a31b7ebSMike Smith /* 70122657ce1SScott Long * Calculate the number of request structures/commands we are 70222657ce1SScott Long * going to provide for this adapter. 70322657ce1SScott Long */ 70422657ce1SScott Long sc->ciss_max_requests = min(CISS_MAX_REQUESTS, sc->ciss_cfg->max_outstanding_commands); 70522657ce1SScott Long 70622657ce1SScott Long /* 7073a31b7ebSMike Smith * Validate the config structure. If we supported other transport 7083a31b7ebSMike Smith * methods, we could select amongst them at this point in time. 7093a31b7ebSMike Smith */ 7103a31b7ebSMike Smith if (strncmp(sc->ciss_cfg->signature, "CISS", 4)) { 7113a31b7ebSMike Smith ciss_printf(sc, "config signature mismatch (got '%c%c%c%c')\n", 7123a31b7ebSMike Smith sc->ciss_cfg->signature[0], sc->ciss_cfg->signature[1], 7133a31b7ebSMike Smith sc->ciss_cfg->signature[2], sc->ciss_cfg->signature[3]); 7143a31b7ebSMike Smith return(ENXIO); 7153a31b7ebSMike Smith } 7163a31b7ebSMike Smith 7173a31b7ebSMike Smith /* 71822657ce1SScott Long * Select the mode of operation, prefer Performant. 7193a31b7ebSMike Smith */ 72022657ce1SScott Long if (!(sc->ciss_cfg->supported_methods & 72122657ce1SScott Long (CISS_TRANSPORT_METHOD_SIMPLE | CISS_TRANSPORT_METHOD_PERF))) { 72222657ce1SScott Long ciss_printf(sc, "No supported transport layers: 0x%x\n", 72322657ce1SScott Long sc->ciss_cfg->supported_methods); 7243a31b7ebSMike Smith } 72522657ce1SScott Long 72622657ce1SScott Long switch (ciss_force_transport) { 72722657ce1SScott Long case 1: 72822657ce1SScott Long supported_methods = CISS_TRANSPORT_METHOD_SIMPLE; 72922657ce1SScott Long break; 73022657ce1SScott Long case 2: 73122657ce1SScott Long supported_methods = CISS_TRANSPORT_METHOD_PERF; 73222657ce1SScott Long break; 73322657ce1SScott Long default: 734ee4827b2SSean Bruno /* 735ee4827b2SSean Bruno * Override the capabilities of the BOARD and specify SIMPLE 736ee4827b2SSean Bruno * MODE 737ee4827b2SSean Bruno */ 738ee4827b2SSean Bruno if (ciss_vendor_data[i].flags & CISS_BOARD_SIMPLE) 739ee4827b2SSean Bruno supported_methods = CISS_TRANSPORT_METHOD_SIMPLE; 740ee4827b2SSean Bruno else 74122657ce1SScott Long supported_methods = sc->ciss_cfg->supported_methods; 74222657ce1SScott Long break; 74322657ce1SScott Long } 74422657ce1SScott Long 74522657ce1SScott Long setup: 7462fdaa90dSScott Long if ((supported_methods & CISS_TRANSPORT_METHOD_PERF) != 0) { 74722657ce1SScott Long method = CISS_TRANSPORT_METHOD_PERF; 74822657ce1SScott Long sc->ciss_perf = (struct ciss_perf_config *)(cbase + cofs + 74922657ce1SScott Long sc->ciss_cfg->transport_offset); 75022657ce1SScott Long if (ciss_init_perf(sc)) { 75122657ce1SScott Long supported_methods &= ~method; 75222657ce1SScott Long goto setup; 75322657ce1SScott Long } 75422657ce1SScott Long } else if (supported_methods & CISS_TRANSPORT_METHOD_SIMPLE) { 75522657ce1SScott Long method = CISS_TRANSPORT_METHOD_SIMPLE; 75622657ce1SScott Long } else { 75722657ce1SScott Long ciss_printf(sc, "No supported transport methods: 0x%x\n", 75822657ce1SScott Long sc->ciss_cfg->supported_methods); 75922657ce1SScott Long return(ENXIO); 76022657ce1SScott Long } 76122657ce1SScott Long 76222657ce1SScott Long /* 76322657ce1SScott Long * Tell it we're using the low 4GB of RAM. Set the default interrupt 76422657ce1SScott Long * coalescing options. 76522657ce1SScott Long */ 76622657ce1SScott Long sc->ciss_cfg->requested_method = method; 7673a31b7ebSMike Smith sc->ciss_cfg->command_physlimit = 0; 7683a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay = CISS_INTERRUPT_COALESCE_DELAY; 7693a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count = CISS_INTERRUPT_COALESCE_COUNT; 7703a31b7ebSMike Smith 771a891a3bfSPaul Saab #ifdef __i386__ 772a891a3bfSPaul Saab sc->ciss_cfg->host_driver |= CISS_DRIVER_SCSI_PREFETCH; 773a891a3bfSPaul Saab #endif 774a891a3bfSPaul Saab 7753a31b7ebSMike Smith if (ciss_update_config(sc)) { 7763a31b7ebSMike Smith ciss_printf(sc, "adapter refuses to accept config update (IDBR 0x%x)\n", 7773a31b7ebSMike Smith CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IDBR)); 7783a31b7ebSMike Smith return(ENXIO); 7793a31b7ebSMike Smith } 78022657ce1SScott Long if ((sc->ciss_cfg->active_method & method) == 0) { 78122657ce1SScott Long supported_methods &= ~method; 78222657ce1SScott Long if (supported_methods == 0) { 78322657ce1SScott Long ciss_printf(sc, "adapter refuses to go into available transports " 78422657ce1SScott Long "mode (0x%x, 0x%x)\n", supported_methods, 78522657ce1SScott Long sc->ciss_cfg->active_method); 7863a31b7ebSMike Smith return(ENXIO); 78722657ce1SScott Long } else 78822657ce1SScott Long goto setup; 7893a31b7ebSMike Smith } 7903a31b7ebSMike Smith 7913a31b7ebSMike Smith /* 7923a31b7ebSMike Smith * Wait for the adapter to come ready. 7933a31b7ebSMike Smith */ 7943a31b7ebSMike Smith if ((error = ciss_wait_adapter(sc)) != 0) 7953a31b7ebSMike Smith return(error); 7963a31b7ebSMike Smith 79722657ce1SScott Long /* Prepare to possibly use MSIX and/or PERFORMANT interrupts. Normal 79822657ce1SScott Long * interrupts have a rid of 0, this will be overridden if MSIX is used. 79922657ce1SScott Long */ 80022657ce1SScott Long sc->ciss_irq_rid[0] = 0; 80122657ce1SScott Long if (method == CISS_TRANSPORT_METHOD_PERF) { 80222657ce1SScott Long ciss_printf(sc, "PERFORMANT Transport\n"); 803d69c9c78SScott Long if ((ciss_force_interrupt != 1) && (ciss_setup_msix(sc) == 0)) { 80422657ce1SScott Long intr = ciss_perf_msi_intr; 805d69c9c78SScott Long } else { 80622657ce1SScott Long intr = ciss_perf_intr; 807d69c9c78SScott Long } 808b23be3e0SScott Long /* XXX The docs say that the 0x01 bit is only for SAS controllers. 809b23be3e0SScott Long * Unfortunately, there is no good way to know if this is a SAS 810b23be3e0SScott Long * controller. Hopefully enabling this bit universally will work OK. 811b23be3e0SScott Long * It seems to work fine for SA6i controllers. 812b23be3e0SScott Long */ 813b23be3e0SScott Long sc->ciss_interrupt_mask = CISS_TL_PERF_INTR_OPQ | CISS_TL_PERF_INTR_MSI; 814b23be3e0SScott Long 81522657ce1SScott Long } else { 81622657ce1SScott Long ciss_printf(sc, "SIMPLE Transport\n"); 81722657ce1SScott Long /* MSIX doesn't seem to work in SIMPLE mode, only enable if it forced */ 81822657ce1SScott Long if (ciss_force_interrupt == 2) 81922657ce1SScott Long /* If this fails, we automatically revert to INTx */ 82022657ce1SScott Long ciss_setup_msix(sc); 82122657ce1SScott Long sc->ciss_perf = NULL; 82222657ce1SScott Long intr = ciss_intr; 823d69c9c78SScott Long sc->ciss_interrupt_mask = sqmask; 82422657ce1SScott Long } 82522657ce1SScott Long 8263a31b7ebSMike Smith /* 8273a31b7ebSMike Smith * Turn off interrupts before we go routing anything. 8283a31b7ebSMike Smith */ 8293a31b7ebSMike Smith CISS_TL_SIMPLE_DISABLE_INTERRUPTS(sc); 8303a31b7ebSMike Smith 8313a31b7ebSMike Smith /* 8323a31b7ebSMike Smith * Allocate and set up our interrupt. 8333a31b7ebSMike Smith */ 8343a31b7ebSMike Smith if ((sc->ciss_irq_resource = 83522657ce1SScott Long bus_alloc_resource_any(sc->ciss_dev, SYS_RES_IRQ, &sc->ciss_irq_rid[0], 8363a31b7ebSMike Smith RF_ACTIVE | RF_SHAREABLE)) == NULL) { 8373a31b7ebSMike Smith ciss_printf(sc, "can't allocate interrupt\n"); 8383a31b7ebSMike Smith return(ENXIO); 8393a31b7ebSMike Smith } 84022657ce1SScott Long 841cc850363SPeter Wemm if (bus_setup_intr(sc->ciss_dev, sc->ciss_irq_resource, 84222657ce1SScott Long INTR_TYPE_CAM|INTR_MPSAFE, NULL, intr, sc, 8433a31b7ebSMike Smith &sc->ciss_intr)) { 8443a31b7ebSMike Smith ciss_printf(sc, "can't set up interrupt\n"); 8453a31b7ebSMike Smith return(ENXIO); 8463a31b7ebSMike Smith } 8473a31b7ebSMike Smith 8483a31b7ebSMike Smith /* 8493a31b7ebSMike Smith * Allocate the parent bus DMA tag appropriate for our PCI 8503a31b7ebSMike Smith * interface. 8513a31b7ebSMike Smith * 8523a31b7ebSMike Smith * Note that "simple" adapters can only address within a 32-bit 8533a31b7ebSMike Smith * span. 8543a31b7ebSMike Smith */ 855b6f97155SScott Long if (bus_dma_tag_create(bus_get_dma_tag(sc->ciss_dev),/* PCI parent */ 8563a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 857639717c8SPaul Saab BUS_SPACE_MAXADDR, /* lowaddr */ 8583a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 8593a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 860639717c8SPaul Saab BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 8616f954fb3SAlexander Motin BUS_SPACE_UNRESTRICTED, /* nsegments */ 8623a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 86322657ce1SScott Long 0, /* flags */ 864f6b1c44dSScott Long NULL, NULL, /* lockfunc, lockarg */ 8653a31b7ebSMike Smith &sc->ciss_parent_dmat)) { 8663a31b7ebSMike Smith ciss_printf(sc, "can't allocate parent DMA tag\n"); 8673a31b7ebSMike Smith return(ENOMEM); 8683a31b7ebSMike Smith } 8693a31b7ebSMike Smith 8703a31b7ebSMike Smith /* 8713a31b7ebSMike Smith * Create DMA tag for mapping buffers into adapter-addressable 8723a31b7ebSMike Smith * space. 8733a31b7ebSMike Smith */ 8743a31b7ebSMike Smith if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 8753a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 8763a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* lowaddr */ 8773a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 8783a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 8796f954fb3SAlexander Motin (CISS_MAX_SG_ELEMENTS - 1) * PAGE_SIZE, /* maxsize */ 8806f954fb3SAlexander Motin CISS_MAX_SG_ELEMENTS, /* nsegments */ 8813a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 88222657ce1SScott Long BUS_DMA_ALLOCNOW, /* flags */ 883975b7318SScott Long busdma_lock_mutex, &sc->ciss_mtx, /* lockfunc, lockarg */ 8843a31b7ebSMike Smith &sc->ciss_buffer_dmat)) { 8853a31b7ebSMike Smith ciss_printf(sc, "can't allocate buffer DMA tag\n"); 8863a31b7ebSMike Smith return(ENOMEM); 8873a31b7ebSMike Smith } 8883a31b7ebSMike Smith return(0); 8893a31b7ebSMike Smith } 8903a31b7ebSMike Smith 8913a31b7ebSMike Smith /************************************************************************ 89222657ce1SScott Long * Setup MSI/MSIX operation (Performant only) 8932fdaa90dSScott Long * Four interrupts are available, but we only use 1 right now. If MSI-X 8942fdaa90dSScott Long * isn't avaialble, try using MSI instead. 89522657ce1SScott Long */ 89622657ce1SScott Long static int 89722657ce1SScott Long ciss_setup_msix(struct ciss_softc *sc) 89822657ce1SScott Long { 89922657ce1SScott Long int val, i; 90022657ce1SScott Long 90122657ce1SScott Long /* Weed out devices that don't actually support MSI */ 9022fdaa90dSScott Long i = ciss_lookup(sc->ciss_dev); 9032fdaa90dSScott Long if (ciss_vendor_data[i].flags & CISS_BOARD_NOMSI) 90422657ce1SScott Long return (EINVAL); 90522657ce1SScott Long 9062fdaa90dSScott Long /* 9072fdaa90dSScott Long * Only need to use the minimum number of MSI vectors, as the driver 9082fdaa90dSScott Long * doesn't support directed MSIX interrupts. 9092fdaa90dSScott Long */ 91022657ce1SScott Long val = pci_msix_count(sc->ciss_dev); 9112fdaa90dSScott Long if (val < CISS_MSI_COUNT) { 9122fdaa90dSScott Long val = pci_msi_count(sc->ciss_dev); 9132fdaa90dSScott Long device_printf(sc->ciss_dev, "got %d MSI messages]\n", val); 914b23be3e0SScott Long if (val < CISS_MSI_COUNT) 915b23be3e0SScott Long return (EINVAL); 9162fdaa90dSScott Long } 917b23be3e0SScott Long val = MIN(val, CISS_MSI_COUNT); 9182fdaa90dSScott Long if (pci_alloc_msix(sc->ciss_dev, &val) != 0) { 9192fdaa90dSScott Long if (pci_alloc_msi(sc->ciss_dev, &val) != 0) 92022657ce1SScott Long return (EINVAL); 9212fdaa90dSScott Long } 92222657ce1SScott Long 92322657ce1SScott Long sc->ciss_msi = val; 924f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) 9252fdaa90dSScott Long ciss_printf(sc, "Using %d MSIX interrupt%s\n", val, 9262fdaa90dSScott Long (val != 1) ? "s" : ""); 92722657ce1SScott Long 9282fdaa90dSScott Long for (i = 0; i < val; i++) 92922657ce1SScott Long sc->ciss_irq_rid[i] = i + 1; 93022657ce1SScott Long 93122657ce1SScott Long return (0); 93222657ce1SScott Long 93322657ce1SScott Long } 93422657ce1SScott Long 93522657ce1SScott Long /************************************************************************ 93622657ce1SScott Long * Setup the Performant structures. 93722657ce1SScott Long */ 93822657ce1SScott Long static int 93922657ce1SScott Long ciss_init_perf(struct ciss_softc *sc) 94022657ce1SScott Long { 94122657ce1SScott Long struct ciss_perf_config *pc = sc->ciss_perf; 94222657ce1SScott Long int reply_size; 94322657ce1SScott Long 94422657ce1SScott Long /* 94522657ce1SScott Long * Create the DMA tag for the reply queue. 94622657ce1SScott Long */ 94722657ce1SScott Long reply_size = sizeof(uint64_t) * sc->ciss_max_requests; 94822657ce1SScott Long if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 94922657ce1SScott Long 1, 0, /* alignment, boundary */ 95022657ce1SScott Long BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 95122657ce1SScott Long BUS_SPACE_MAXADDR, /* highaddr */ 95222657ce1SScott Long NULL, NULL, /* filter, filterarg */ 95322657ce1SScott Long reply_size, 1, /* maxsize, nsegments */ 95422657ce1SScott Long BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 95522657ce1SScott Long 0, /* flags */ 95622657ce1SScott Long NULL, NULL, /* lockfunc, lockarg */ 95722657ce1SScott Long &sc->ciss_reply_dmat)) { 95822657ce1SScott Long ciss_printf(sc, "can't allocate reply DMA tag\n"); 95922657ce1SScott Long return(ENOMEM); 96022657ce1SScott Long } 96122657ce1SScott Long /* 96222657ce1SScott Long * Allocate memory and make it available for DMA. 96322657ce1SScott Long */ 96422657ce1SScott Long if (bus_dmamem_alloc(sc->ciss_reply_dmat, (void **)&sc->ciss_reply, 96522657ce1SScott Long BUS_DMA_NOWAIT, &sc->ciss_reply_map)) { 96622657ce1SScott Long ciss_printf(sc, "can't allocate reply memory\n"); 96722657ce1SScott Long return(ENOMEM); 96822657ce1SScott Long } 96922657ce1SScott Long bus_dmamap_load(sc->ciss_reply_dmat, sc->ciss_reply_map, sc->ciss_reply, 97022657ce1SScott Long reply_size, ciss_command_map_helper, &sc->ciss_reply_phys, 0); 97122657ce1SScott Long bzero(sc->ciss_reply, reply_size); 97222657ce1SScott Long 97322657ce1SScott Long sc->ciss_cycle = 0x1; 97422657ce1SScott Long sc->ciss_rqidx = 0; 97522657ce1SScott Long 97622657ce1SScott Long /* 97722657ce1SScott Long * Preload the fetch table with common command sizes. This allows the 97822657ce1SScott Long * hardware to not waste bus cycles for typical i/o commands, but also not 97922657ce1SScott Long * tax the driver to be too exact in choosing sizes. The table is optimized 98022657ce1SScott Long * for page-aligned i/o's, but since most i/o comes from the various pagers, 98122657ce1SScott Long * it's a reasonable assumption to make. 98222657ce1SScott Long */ 98322657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_NONE] = (sizeof(struct ciss_command) + 15) / 16; 98422657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_1] = 98522657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 1 + 15) / 16; 98622657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_2] = 98722657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 2 + 15) / 16; 98822657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_4] = 98922657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 4 + 15) / 16; 99022657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_8] = 99122657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 8 + 15) / 16; 99222657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_16] = 99322657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 16 + 15) / 16; 99422657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_32] = 99522657ce1SScott Long (sizeof(struct ciss_command) + sizeof(struct ciss_sg_entry) * 32 + 15) / 16; 99622657ce1SScott Long pc->fetch_count[CISS_SG_FETCH_MAX] = (CISS_COMMAND_ALLOC_SIZE + 15) / 16; 99722657ce1SScott Long 99822657ce1SScott Long pc->rq_size = sc->ciss_max_requests; /* XXX less than the card supports? */ 99922657ce1SScott Long pc->rq_count = 1; /* XXX Hardcode for a single queue */ 100022657ce1SScott Long pc->rq_bank_hi = 0; 100122657ce1SScott Long pc->rq_bank_lo = 0; 100222657ce1SScott Long pc->rq[0].rq_addr_hi = 0x0; 100322657ce1SScott Long pc->rq[0].rq_addr_lo = sc->ciss_reply_phys; 100422657ce1SScott Long 100522657ce1SScott Long return(0); 100622657ce1SScott Long } 100722657ce1SScott Long 100822657ce1SScott Long /************************************************************************ 10093a31b7ebSMike Smith * Wait for the adapter to come ready. 10103a31b7ebSMike Smith */ 10113a31b7ebSMike Smith static int 10123a31b7ebSMike Smith ciss_wait_adapter(struct ciss_softc *sc) 10133a31b7ebSMike Smith { 10143a31b7ebSMike Smith int i; 10153a31b7ebSMike Smith 10163a31b7ebSMike Smith debug_called(1); 10173a31b7ebSMike Smith 10183a31b7ebSMike Smith /* 10193a31b7ebSMike Smith * Wait for the adapter to come ready. 10203a31b7ebSMike Smith */ 10213a31b7ebSMike Smith if (!(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY)) { 10223a31b7ebSMike Smith ciss_printf(sc, "waiting for adapter to come ready...\n"); 10233a31b7ebSMike Smith for (i = 0; !(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY); i++) { 10243a31b7ebSMike Smith DELAY(1000000); /* one second */ 10253a31b7ebSMike Smith if (i > 30) { 10263a31b7ebSMike Smith ciss_printf(sc, "timed out waiting for adapter to come ready\n"); 10273a31b7ebSMike Smith return(EIO); 10283a31b7ebSMike Smith } 10293a31b7ebSMike Smith } 10303a31b7ebSMike Smith } 10313a31b7ebSMike Smith return(0); 10323a31b7ebSMike Smith } 10333a31b7ebSMike Smith 10343a31b7ebSMike Smith /************************************************************************ 10353a31b7ebSMike Smith * Flush the adapter cache. 10363a31b7ebSMike Smith */ 10373a31b7ebSMike Smith static int 10383a31b7ebSMike Smith ciss_flush_adapter(struct ciss_softc *sc) 10393a31b7ebSMike Smith { 10403a31b7ebSMike Smith struct ciss_request *cr; 10413a31b7ebSMike Smith struct ciss_bmic_flush_cache *cbfc; 10423a31b7ebSMike Smith int error, command_status; 10433a31b7ebSMike Smith 10443a31b7ebSMike Smith debug_called(1); 10453a31b7ebSMike Smith 10463a31b7ebSMike Smith cr = NULL; 10473a31b7ebSMike Smith cbfc = NULL; 10483a31b7ebSMike Smith 10493a31b7ebSMike Smith /* 10503a31b7ebSMike Smith * Build a BMIC request to flush the cache. We don't disable 10513a31b7ebSMike Smith * it, as we may be going to do more I/O (eg. we are emulating 10523a31b7ebSMike Smith * the Synchronise Cache command). 10533a31b7ebSMike Smith */ 10543a31b7ebSMike Smith if ((cbfc = malloc(sizeof(*cbfc), CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 10553a31b7ebSMike Smith error = ENOMEM; 10563a31b7ebSMike Smith goto out; 10573a31b7ebSMike Smith } 10583a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_FLUSH_CACHE, 10593a31b7ebSMike Smith (void **)&cbfc, sizeof(*cbfc))) != 0) 10603a31b7ebSMike Smith goto out; 10613a31b7ebSMike Smith 10623a31b7ebSMike Smith /* 10633a31b7ebSMike Smith * Submit the request and wait for it to complete. 10643a31b7ebSMike Smith */ 10653a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 10663a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC FLUSH_CACHE command (%d)\n", error); 10673a31b7ebSMike Smith goto out; 10683a31b7ebSMike Smith } 10693a31b7ebSMike Smith 10703a31b7ebSMike Smith /* 10713a31b7ebSMike Smith * Check response. 10723a31b7ebSMike Smith */ 10733a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 10743a31b7ebSMike Smith switch(command_status) { 10753a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 10763a31b7ebSMike Smith break; 10773a31b7ebSMike Smith default: 10783a31b7ebSMike Smith ciss_printf(sc, "error flushing cache (%s)\n", 10793a31b7ebSMike Smith ciss_name_command_status(command_status)); 10803a31b7ebSMike Smith error = EIO; 10813a31b7ebSMike Smith goto out; 10823a31b7ebSMike Smith } 10833a31b7ebSMike Smith 10843a31b7ebSMike Smith out: 10853a31b7ebSMike Smith if (cbfc != NULL) 10863a31b7ebSMike Smith free(cbfc, CISS_MALLOC_CLASS); 10873a31b7ebSMike Smith if (cr != NULL) 10883a31b7ebSMike Smith ciss_release_request(cr); 10893a31b7ebSMike Smith return(error); 10903a31b7ebSMike Smith } 10913a31b7ebSMike Smith 109217c0792dSPaul Saab static void 109317c0792dSPaul Saab ciss_soft_reset(struct ciss_softc *sc) 109417c0792dSPaul Saab { 109517c0792dSPaul Saab struct ciss_request *cr = NULL; 109617c0792dSPaul Saab struct ciss_command *cc; 109717c0792dSPaul Saab int i, error = 0; 109817c0792dSPaul Saab 109917c0792dSPaul Saab for (i = 0; i < sc->ciss_max_logical_bus; i++) { 110017c0792dSPaul Saab /* only reset proxy controllers */ 110117c0792dSPaul Saab if (sc->ciss_controllers[i].physical.bus == 0) 110217c0792dSPaul Saab continue; 110317c0792dSPaul Saab 110417c0792dSPaul Saab if ((error = ciss_get_request(sc, &cr)) != 0) 110517c0792dSPaul Saab break; 110617c0792dSPaul Saab 110717c0792dSPaul Saab if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_SOFT_RESET, 110817c0792dSPaul Saab NULL, 0)) != 0) 110917c0792dSPaul Saab break; 111017c0792dSPaul Saab 11112fdaa90dSScott Long cc = cr->cr_cc; 111217c0792dSPaul Saab cc->header.address = sc->ciss_controllers[i]; 111317c0792dSPaul Saab 111417c0792dSPaul Saab if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) 111517c0792dSPaul Saab break; 111617c0792dSPaul Saab 111717c0792dSPaul Saab ciss_release_request(cr); 111817c0792dSPaul Saab } 111917c0792dSPaul Saab 112017c0792dSPaul Saab if (error) 112117c0792dSPaul Saab ciss_printf(sc, "error resetting controller (%d)\n", error); 112217c0792dSPaul Saab 112317c0792dSPaul Saab if (cr != NULL) 112417c0792dSPaul Saab ciss_release_request(cr); 112517c0792dSPaul Saab } 112617c0792dSPaul Saab 11273a31b7ebSMike Smith /************************************************************************ 11283a31b7ebSMike Smith * Allocate memory for the adapter command structures, initialise 11293a31b7ebSMike Smith * the request structures. 11303a31b7ebSMike Smith * 11313a31b7ebSMike Smith * Note that the entire set of commands are allocated in a single 11323a31b7ebSMike Smith * contiguous slab. 11333a31b7ebSMike Smith */ 11343a31b7ebSMike Smith static int 11353a31b7ebSMike Smith ciss_init_requests(struct ciss_softc *sc) 11363a31b7ebSMike Smith { 11373a31b7ebSMike Smith struct ciss_request *cr; 11383a31b7ebSMike Smith int i; 11393a31b7ebSMike Smith 11403a31b7ebSMike Smith debug_called(1); 11413a31b7ebSMike Smith 1142f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) 11433a31b7ebSMike Smith ciss_printf(sc, "using %d of %d available commands\n", 11443a31b7ebSMike Smith sc->ciss_max_requests, sc->ciss_cfg->max_outstanding_commands); 11453a31b7ebSMike Smith 11463a31b7ebSMike Smith /* 11473a31b7ebSMike Smith * Create the DMA tag for commands. 11483a31b7ebSMike Smith */ 11493a31b7ebSMike Smith if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 115022657ce1SScott Long 32, 0, /* alignment, boundary */ 1151639717c8SPaul Saab BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 11523a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 11533a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 11543a31b7ebSMike Smith CISS_COMMAND_ALLOC_SIZE * 11553a31b7ebSMike Smith sc->ciss_max_requests, 1, /* maxsize, nsegments */ 11563a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 115722657ce1SScott Long 0, /* flags */ 1158639717c8SPaul Saab NULL, NULL, /* lockfunc, lockarg */ 11593a31b7ebSMike Smith &sc->ciss_command_dmat)) { 11603a31b7ebSMike Smith ciss_printf(sc, "can't allocate command DMA tag\n"); 11613a31b7ebSMike Smith return(ENOMEM); 11623a31b7ebSMike Smith } 11633a31b7ebSMike Smith /* 11643a31b7ebSMike Smith * Allocate memory and make it available for DMA. 11653a31b7ebSMike Smith */ 11663a31b7ebSMike Smith if (bus_dmamem_alloc(sc->ciss_command_dmat, (void **)&sc->ciss_command, 11673a31b7ebSMike Smith BUS_DMA_NOWAIT, &sc->ciss_command_map)) { 11683a31b7ebSMike Smith ciss_printf(sc, "can't allocate command memory\n"); 11693a31b7ebSMike Smith return(ENOMEM); 11703a31b7ebSMike Smith } 11713a31b7ebSMike Smith bus_dmamap_load(sc->ciss_command_dmat, sc->ciss_command_map,sc->ciss_command, 1172be241f79SPaul Saab CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests, 117322657ce1SScott Long ciss_command_map_helper, &sc->ciss_command_phys, 0); 11743a31b7ebSMike Smith bzero(sc->ciss_command, CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests); 11753a31b7ebSMike Smith 11763a31b7ebSMike Smith /* 11773a31b7ebSMike Smith * Set up the request and command structures, push requests onto 11783a31b7ebSMike Smith * the free queue. 11793a31b7ebSMike Smith */ 11803a31b7ebSMike Smith for (i = 1; i < sc->ciss_max_requests; i++) { 11813a31b7ebSMike Smith cr = &sc->ciss_request[i]; 11823a31b7ebSMike Smith cr->cr_sc = sc; 11833a31b7ebSMike Smith cr->cr_tag = i; 11842fdaa90dSScott Long cr->cr_cc = (struct ciss_command *)((uintptr_t)sc->ciss_command + 11852fdaa90dSScott Long CISS_COMMAND_ALLOC_SIZE * i); 11862fdaa90dSScott Long cr->cr_ccphys = sc->ciss_command_phys + CISS_COMMAND_ALLOC_SIZE * i; 11873284b9eeSPaul Saab bus_dmamap_create(sc->ciss_buffer_dmat, 0, &cr->cr_datamap); 11883a31b7ebSMike Smith ciss_enqueue_free(cr); 11893a31b7ebSMike Smith } 11903a31b7ebSMike Smith return(0); 11913a31b7ebSMike Smith } 11923a31b7ebSMike Smith 11933a31b7ebSMike Smith static void 11943a31b7ebSMike Smith ciss_command_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error) 11953a31b7ebSMike Smith { 119622657ce1SScott Long uint32_t *addr; 11973a31b7ebSMike Smith 119822657ce1SScott Long addr = arg; 119922657ce1SScott Long *addr = segs[0].ds_addr; 12003a31b7ebSMike Smith } 12013a31b7ebSMike Smith 12023a31b7ebSMike Smith /************************************************************************ 12033a31b7ebSMike Smith * Identify the adapter, print some information about it. 12043a31b7ebSMike Smith */ 12053a31b7ebSMike Smith static int 12063a31b7ebSMike Smith ciss_identify_adapter(struct ciss_softc *sc) 12073a31b7ebSMike Smith { 12083a31b7ebSMike Smith struct ciss_request *cr; 12093a31b7ebSMike Smith int error, command_status; 12103a31b7ebSMike Smith 12113a31b7ebSMike Smith debug_called(1); 12123a31b7ebSMike Smith 12133a31b7ebSMike Smith cr = NULL; 12143a31b7ebSMike Smith 12153a31b7ebSMike Smith /* 12163a31b7ebSMike Smith * Get a request, allocate storage for the adapter data. 12173a31b7ebSMike Smith */ 12183a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_CTLR, 12193a31b7ebSMike Smith (void **)&sc->ciss_id, 12203a31b7ebSMike Smith sizeof(*sc->ciss_id))) != 0) 12213a31b7ebSMike Smith goto out; 12223a31b7ebSMike Smith 12233a31b7ebSMike Smith /* 12243a31b7ebSMike Smith * Submit the request and wait for it to complete. 12253a31b7ebSMike Smith */ 12263a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 12273a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC ID_CTLR command (%d)\n", error); 12283a31b7ebSMike Smith goto out; 12293a31b7ebSMike Smith } 12303a31b7ebSMike Smith 12313a31b7ebSMike Smith /* 12323a31b7ebSMike Smith * Check response. 12333a31b7ebSMike Smith */ 12343a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 12353a31b7ebSMike Smith switch(command_status) { 12363a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 12373a31b7ebSMike Smith break; 12383a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 12393a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 12403a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading adapter information\n"); 12413a31b7ebSMike Smith default: 12423a31b7ebSMike Smith ciss_printf(sc, "error reading adapter information (%s)\n", 12433a31b7ebSMike Smith ciss_name_command_status(command_status)); 12443a31b7ebSMike Smith error = EIO; 12453a31b7ebSMike Smith goto out; 12463a31b7ebSMike Smith } 12473a31b7ebSMike Smith 12483a31b7ebSMike Smith /* sanity-check reply */ 12490fb31ed0SSean Bruno if (!(sc->ciss_id->controller_flags & CONTROLLER_FLAGS_BIG_MAP_SUPPORT)) { 12503a31b7ebSMike Smith ciss_printf(sc, "adapter does not support BIG_MAP\n"); 12513a31b7ebSMike Smith error = ENXIO; 12523a31b7ebSMike Smith goto out; 12533a31b7ebSMike Smith } 12543a31b7ebSMike Smith 1255d4aa427fSPaul Saab #if 0 12563a31b7ebSMike Smith /* XXX later revisions may not need this */ 12573a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_FAKE_SYNCH; 1258d4aa427fSPaul Saab #endif 12593a31b7ebSMike Smith 12603a31b7ebSMike Smith /* XXX only really required for old 5300 adapters? */ 12613a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_BMIC_ABORT; 12623a31b7ebSMike Smith 1263e3edca22SSean Bruno /* 1264e3edca22SSean Bruno * Earlier controller specs do not contain these config 1265e3edca22SSean Bruno * entries, so assume that a 0 means its old and assign 1266e3edca22SSean Bruno * these values to the defaults that were established 1267e3edca22SSean Bruno * when this driver was developed for them 1268e3edca22SSean Bruno */ 1269e3edca22SSean Bruno if (sc->ciss_cfg->max_logical_supported == 0) 1270e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported = CISS_MAX_LOGICAL; 1271e3edca22SSean Bruno if (sc->ciss_cfg->max_physical_supported == 0) 1272e3edca22SSean Bruno sc->ciss_cfg->max_physical_supported = CISS_MAX_PHYSICAL; 12733a31b7ebSMike Smith /* print information */ 1274f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 12753a31b7ebSMike Smith ciss_printf(sc, " %d logical drive%s configured\n", 12763a31b7ebSMike Smith sc->ciss_id->configured_logical_drives, 12773a31b7ebSMike Smith (sc->ciss_id->configured_logical_drives == 1) ? "" : "s"); 12783a31b7ebSMike Smith ciss_printf(sc, " firmware %4.4s\n", sc->ciss_id->running_firmware_revision); 12790fb31ed0SSean Bruno ciss_printf(sc, " %d SCSI channels\n", sc->ciss_id->scsi_chip_count); 12803a31b7ebSMike Smith 1281f373e6b8SPeter Eriksson if (ciss_verbose > 1) { 1282f373e6b8SPeter Eriksson ciss_printf(sc, " %d FC channels\n", sc->ciss_id->fibre_chip_count); 1283f373e6b8SPeter Eriksson ciss_printf(sc, " %d enclosures\n", sc->ciss_id->bEnclosureCount); 1284f373e6b8SPeter Eriksson ciss_printf(sc, " %d expanders\n", sc->ciss_id->bExpanderCount); 1285f373e6b8SPeter Eriksson ciss_printf(sc, " maximum blocks: %d\n", sc->ciss_id->maximum_blocks); 1286f373e6b8SPeter Eriksson ciss_printf(sc, " controller clock: %d\n", sc->ciss_id->controller_clock); 1287f373e6b8SPeter Eriksson ciss_printf(sc, " %d MB controller memory\n", sc->ciss_id->total_controller_mem_mb); 1288f373e6b8SPeter Eriksson } 1289f373e6b8SPeter Eriksson 12903a31b7ebSMike Smith ciss_printf(sc, " signature '%.4s'\n", sc->ciss_cfg->signature); 12913a31b7ebSMike Smith ciss_printf(sc, " valence %d\n", sc->ciss_cfg->valence); 12923a31b7ebSMike Smith ciss_printf(sc, " supported I/O methods 0x%b\n", 12933a31b7ebSMike Smith sc->ciss_cfg->supported_methods, 12943a31b7ebSMike Smith "\20\1READY\2simple\3performant\4MEMQ\n"); 12953a31b7ebSMike Smith ciss_printf(sc, " active I/O method 0x%b\n", 12963a31b7ebSMike Smith sc->ciss_cfg->active_method, "\20\2simple\3performant\4MEMQ\n"); 12973a31b7ebSMike Smith ciss_printf(sc, " 4G page base 0x%08x\n", 12983a31b7ebSMike Smith sc->ciss_cfg->command_physlimit); 12993a31b7ebSMike Smith ciss_printf(sc, " interrupt coalesce delay %dus\n", 13003a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay); 13013a31b7ebSMike Smith ciss_printf(sc, " interrupt coalesce count %d\n", 13023a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count); 13033a31b7ebSMike Smith ciss_printf(sc, " max outstanding commands %d\n", 13043a31b7ebSMike Smith sc->ciss_cfg->max_outstanding_commands); 13053a31b7ebSMike Smith ciss_printf(sc, " bus types 0x%b\n", sc->ciss_cfg->bus_types, 13063a31b7ebSMike Smith "\20\1ultra2\2ultra3\10fibre1\11fibre2\n"); 13073a31b7ebSMike Smith ciss_printf(sc, " server name '%.16s'\n", sc->ciss_cfg->server_name); 13083a31b7ebSMike Smith ciss_printf(sc, " heartbeat 0x%x\n", sc->ciss_cfg->heartbeat); 13095f8cb13cSAlexander Motin ciss_printf(sc, " max logical volumes: %d\n", sc->ciss_cfg->max_logical_supported); 1310e3edca22SSean Bruno ciss_printf(sc, " max physical disks supported: %d\n", sc->ciss_cfg->max_physical_supported); 1311e3edca22SSean Bruno ciss_printf(sc, " max physical disks per logical volume: %d\n", sc->ciss_cfg->max_physical_per_logical); 13120fb31ed0SSean Bruno ciss_printf(sc, " JBOD Support is %s\n", (sc->ciss_id->uiYetMoreControllerFlags & YMORE_CONTROLLER_FLAGS_JBOD_SUPPORTED) ? 13130fb31ed0SSean Bruno "Available" : "Unavailable"); 13140fb31ed0SSean Bruno ciss_printf(sc, " JBOD Mode is %s\n", (sc->ciss_id->PowerUPNvramFlags & PWR_UP_FLAG_JBOD_ENABLED) ? 13150fb31ed0SSean Bruno "Enabled" : "Disabled"); 13163a31b7ebSMike Smith } 13173a31b7ebSMike Smith 13183a31b7ebSMike Smith out: 13193a31b7ebSMike Smith if (error) { 13203a31b7ebSMike Smith if (sc->ciss_id != NULL) { 13213a31b7ebSMike Smith free(sc->ciss_id, CISS_MALLOC_CLASS); 13223a31b7ebSMike Smith sc->ciss_id = NULL; 13233a31b7ebSMike Smith } 13243a31b7ebSMike Smith } 13253a31b7ebSMike Smith if (cr != NULL) 13263a31b7ebSMike Smith ciss_release_request(cr); 13273a31b7ebSMike Smith return(error); 13283a31b7ebSMike Smith } 13293a31b7ebSMike Smith 13303a31b7ebSMike Smith /************************************************************************ 1331c6131460SPaul Saab * Helper routine for generating a list of logical and physical luns. 13323a31b7ebSMike Smith */ 1333c6131460SPaul Saab static struct ciss_lun_report * 1334c6131460SPaul Saab ciss_report_luns(struct ciss_softc *sc, int opcode, int nunits) 13353a31b7ebSMike Smith { 13363a31b7ebSMike Smith struct ciss_request *cr; 13373a31b7ebSMike Smith struct ciss_command *cc; 13383a31b7ebSMike Smith struct ciss_report_cdb *crc; 13393a31b7ebSMike Smith struct ciss_lun_report *cll; 13403a31b7ebSMike Smith int command_status; 1341c6131460SPaul Saab int report_size; 1342c6131460SPaul Saab int error = 0; 13433a31b7ebSMike Smith 13443a31b7ebSMike Smith debug_called(1); 13453a31b7ebSMike Smith 13463a31b7ebSMike Smith cr = NULL; 13473a31b7ebSMike Smith cll = NULL; 13483a31b7ebSMike Smith 13493a31b7ebSMike Smith /* 13503a31b7ebSMike Smith * Get a request, allocate storage for the address list. 13513a31b7ebSMike Smith */ 13523a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 13533a31b7ebSMike Smith goto out; 1354c6131460SPaul Saab report_size = sizeof(*cll) + nunits * sizeof(union ciss_device_address); 13553a31b7ebSMike Smith if ((cll = malloc(report_size, CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 1356c6131460SPaul Saab ciss_printf(sc, "can't allocate memory for lun report\n"); 13573a31b7ebSMike Smith error = ENOMEM; 13583a31b7ebSMike Smith goto out; 13593a31b7ebSMike Smith } 13603a31b7ebSMike Smith 13613a31b7ebSMike Smith /* 1362c6131460SPaul Saab * Build the Report Logical/Physical LUNs command. 13633a31b7ebSMike Smith */ 13642fdaa90dSScott Long cc = cr->cr_cc; 13653a31b7ebSMike Smith cr->cr_data = cll; 13663a31b7ebSMike Smith cr->cr_length = report_size; 13673a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 13683a31b7ebSMike Smith 13693a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 13703a31b7ebSMike Smith cc->header.address.physical.bus = 0; 13713a31b7ebSMike Smith cc->header.address.physical.target = 0; 13723a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*crc); 13733a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 13743a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 13753a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 13763a31b7ebSMike Smith cc->cdb.timeout = 30; /* XXX better suggestions? */ 13773a31b7ebSMike Smith 13783a31b7ebSMike Smith crc = (struct ciss_report_cdb *)&(cc->cdb.cdb[0]); 13793a31b7ebSMike Smith bzero(crc, sizeof(*crc)); 1380c6131460SPaul Saab crc->opcode = opcode; 13813a31b7ebSMike Smith crc->length = htonl(report_size); /* big-endian field */ 13823a31b7ebSMike Smith cll->list_size = htonl(report_size - sizeof(*cll)); /* big-endian field */ 13833a31b7ebSMike Smith 13843a31b7ebSMike Smith /* 13853a31b7ebSMike Smith * Submit the request and wait for it to complete. (timeout 13863a31b7ebSMike Smith * here should be much greater than above) 13873a31b7ebSMike Smith */ 13883a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 1389c6131460SPaul Saab ciss_printf(sc, "error sending %d LUN command (%d)\n", opcode, error); 13903a31b7ebSMike Smith goto out; 13913a31b7ebSMike Smith } 13923a31b7ebSMike Smith 13933a31b7ebSMike Smith /* 13943a31b7ebSMike Smith * Check response. Note that data over/underrun is OK. 13953a31b7ebSMike Smith */ 13963a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 13973a31b7ebSMike Smith switch(command_status) { 13983a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 13993a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: /* buffer too large, not bad */ 14003a31b7ebSMike Smith break; 14013a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 1402c6131460SPaul Saab ciss_printf(sc, "WARNING: more units than driver limit (%d)\n", 1403e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported); 14043a31b7ebSMike Smith break; 14053a31b7ebSMike Smith default: 14063a31b7ebSMike Smith ciss_printf(sc, "error detecting logical drive configuration (%s)\n", 14073a31b7ebSMike Smith ciss_name_command_status(command_status)); 14083a31b7ebSMike Smith error = EIO; 14093a31b7ebSMike Smith goto out; 14103a31b7ebSMike Smith } 14113a31b7ebSMike Smith ciss_release_request(cr); 14123a31b7ebSMike Smith cr = NULL; 14133a31b7ebSMike Smith 1414c6131460SPaul Saab out: 1415c6131460SPaul Saab if (cr != NULL) 1416c6131460SPaul Saab ciss_release_request(cr); 1417c6131460SPaul Saab if (error && cll != NULL) { 1418c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 1419c6131460SPaul Saab cll = NULL; 1420c6131460SPaul Saab } 1421c6131460SPaul Saab return(cll); 1422c6131460SPaul Saab } 1423c6131460SPaul Saab 1424c6131460SPaul Saab /************************************************************************ 1425c6131460SPaul Saab * Find logical drives on the adapter. 1426c6131460SPaul Saab */ 1427c6131460SPaul Saab static int 1428c6131460SPaul Saab ciss_init_logical(struct ciss_softc *sc) 1429c6131460SPaul Saab { 1430c6131460SPaul Saab struct ciss_lun_report *cll; 1431c6131460SPaul Saab int error = 0, i, j; 1432c6131460SPaul Saab int ndrives; 1433c6131460SPaul Saab 1434c6131460SPaul Saab debug_called(1); 1435c6131460SPaul Saab 1436c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_LOGICAL_LUNS, 1437e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported); 1438c6131460SPaul Saab if (cll == NULL) { 1439c6131460SPaul Saab error = ENXIO; 1440c6131460SPaul Saab goto out; 1441c6131460SPaul Saab } 1442c6131460SPaul Saab 14433a31b7ebSMike Smith /* sanity-check reply */ 14443a31b7ebSMike Smith ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 1445e3edca22SSean Bruno if ((ndrives < 0) || (ndrives > sc->ciss_cfg->max_logical_supported)) { 14463a31b7ebSMike Smith ciss_printf(sc, "adapter claims to report absurd number of logical drives (%d > %d)\n", 1447e3edca22SSean Bruno ndrives, sc->ciss_cfg->max_logical_supported); 1448c6131460SPaul Saab error = ENXIO; 1449c6131460SPaul Saab goto out; 14503a31b7ebSMike Smith } 14513a31b7ebSMike Smith 14523a31b7ebSMike Smith /* 14533a31b7ebSMike Smith * Save logical drive information. 14543a31b7ebSMike Smith */ 1455f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 1456c6131460SPaul Saab ciss_printf(sc, "%d logical drive%s\n", 1457c6131460SPaul Saab ndrives, (ndrives > 1 || ndrives == 0) ? "s" : ""); 1458c6131460SPaul Saab } 1459c6131460SPaul Saab 1460c6131460SPaul Saab sc->ciss_logical = 1461ac2fffa4SPedro F. Giffuni malloc(sc->ciss_max_logical_bus * sizeof(struct ciss_ldrive *), 1462c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1463c6131460SPaul Saab if (sc->ciss_logical == NULL) { 1464c6131460SPaul Saab error = ENXIO; 1465c6131460SPaul Saab goto out; 1466c6131460SPaul Saab } 1467c6131460SPaul Saab 14685eae46afSConrad Meyer for (i = 0; i < sc->ciss_max_logical_bus; i++) { 1469c6131460SPaul Saab sc->ciss_logical[i] = 1470ac2fffa4SPedro F. Giffuni malloc(sc->ciss_cfg->max_logical_supported * 1471e3edca22SSean Bruno sizeof(struct ciss_ldrive), 1472c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1473c6131460SPaul Saab if (sc->ciss_logical[i] == NULL) { 1474c6131460SPaul Saab error = ENXIO; 1475c6131460SPaul Saab goto out; 1476c6131460SPaul Saab } 1477c6131460SPaul Saab 1478e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) 1479c6131460SPaul Saab sc->ciss_logical[i][j].cl_status = CISS_LD_NONEXISTENT; 1480c6131460SPaul Saab } 1481c6131460SPaul Saab 1482e3edca22SSean Bruno for (i = 0; i < sc->ciss_cfg->max_logical_supported; i++) { 14833a31b7ebSMike Smith if (i < ndrives) { 1484c6131460SPaul Saab struct ciss_ldrive *ld; 1485c6131460SPaul Saab int bus, target; 1486c6131460SPaul Saab 1487c6131460SPaul Saab bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); 1488c6131460SPaul Saab target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); 1489c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 1490c6131460SPaul Saab 1491c6131460SPaul Saab ld->cl_address = cll->lun[i]; 1492c6131460SPaul Saab ld->cl_controller = &sc->ciss_controllers[bus]; 1493c6131460SPaul Saab if (ciss_identify_logical(sc, ld) != 0) 14943a31b7ebSMike Smith continue; 14953a31b7ebSMike Smith /* 14963a31b7ebSMike Smith * If the drive has had media exchanged, we should bring it online. 14973a31b7ebSMike Smith */ 1498c6131460SPaul Saab if (ld->cl_lstatus->media_exchanged) 149988c78a38SPaul Saab ciss_accept_media(sc, ld); 15003a31b7ebSMike Smith } 15013a31b7ebSMike Smith } 15023a31b7ebSMike Smith 15033a31b7ebSMike Smith out: 15043a31b7ebSMike Smith if (cll != NULL) 15053a31b7ebSMike Smith free(cll, CISS_MALLOC_CLASS); 15063a31b7ebSMike Smith return(error); 15073a31b7ebSMike Smith } 15083a31b7ebSMike Smith 1509440baa08SPaul Saab static int 1510c6131460SPaul Saab ciss_init_physical(struct ciss_softc *sc) 1511c6131460SPaul Saab { 1512c6131460SPaul Saab struct ciss_lun_report *cll; 1513c6131460SPaul Saab int error = 0, i; 1514c6131460SPaul Saab int nphys; 151579ed7cb3SScott Long int bus; 1516c6131460SPaul Saab 1517c6131460SPaul Saab debug_called(1); 1518c6131460SPaul Saab 15191fe6c4eeSScott Long bus = 0; 15201fe6c4eeSScott Long 1521c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_PHYSICAL_LUNS, 1522e3edca22SSean Bruno sc->ciss_cfg->max_physical_supported); 1523c6131460SPaul Saab if (cll == NULL) { 1524c6131460SPaul Saab error = ENXIO; 1525c6131460SPaul Saab goto out; 1526c6131460SPaul Saab } 1527c6131460SPaul Saab 1528c6131460SPaul Saab nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 1529c6131460SPaul Saab 1530f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 1531c6131460SPaul Saab ciss_printf(sc, "%d physical device%s\n", 1532c6131460SPaul Saab nphys, (nphys > 1 || nphys == 0) ? "s" : ""); 1533c6131460SPaul Saab } 1534c6131460SPaul Saab 1535c6131460SPaul Saab /* 15361fe6c4eeSScott Long * Figure out the bus mapping. 15371fe6c4eeSScott Long * Logical buses include both the local logical bus for local arrays and 15381fe6c4eeSScott Long * proxy buses for remote arrays. Physical buses are numbered by the 15391fe6c4eeSScott Long * controller and represent physical buses that hold physical devices. 15401fe6c4eeSScott Long * We shift these bus numbers so that everything fits into a single flat 15411fe6c4eeSScott Long * numbering space for CAM. Logical buses occupy the first 32 CAM bus 15421fe6c4eeSScott Long * numbers, and the physical bus numbers are shifted to be above that. 15431fe6c4eeSScott Long * This results in the various driver arrays being indexed as follows: 15441fe6c4eeSScott Long * 15451fe6c4eeSScott Long * ciss_controllers[] - indexed by logical bus 15461fe6c4eeSScott Long * ciss_cam_sim[] - indexed by both logical and physical, with physical 15471fe6c4eeSScott Long * being shifted by 32. 15481fe6c4eeSScott Long * ciss_logical[][] - indexed by logical bus 15491fe6c4eeSScott Long * ciss_physical[][] - indexed by physical bus 15501fe6c4eeSScott Long * 15511fe6c4eeSScott Long * XXX This is getting more and more hackish. CISS really doesn't play 15521fe6c4eeSScott Long * well with a standard SCSI model; devices are addressed via magic 15531fe6c4eeSScott Long * cookies, not via b/t/l addresses. Since there is no way to store 15541fe6c4eeSScott Long * the cookie in the CAM device object, we have to keep these lookup 15551fe6c4eeSScott Long * tables handy so that the devices can be found quickly at the cost 15561fe6c4eeSScott Long * of wasting memory and having a convoluted lookup scheme. This 15571fe6c4eeSScott Long * driver should probably be converted to block interface. 15581fe6c4eeSScott Long */ 15591fe6c4eeSScott Long /* 1560c6131460SPaul Saab * If the L2 and L3 SCSI addresses are 0, this signifies a proxy 1561c6131460SPaul Saab * controller. A proxy controller is another physical controller 1562c6131460SPaul Saab * behind the primary PCI controller. We need to know about this 1563c6131460SPaul Saab * so that BMIC commands can be properly targeted. There can be 1564c6131460SPaul Saab * proxy controllers attached to a single PCI controller, so 1565c6131460SPaul Saab * find the highest numbered one so the array can be properly 1566c6131460SPaul Saab * sized. 1567c6131460SPaul Saab */ 15681fe6c4eeSScott Long sc->ciss_max_logical_bus = 1; 1569c6131460SPaul Saab for (i = 0; i < nphys; i++) { 1570c6131460SPaul Saab if (cll->lun[i].physical.extra_address == 0) { 15711fe6c4eeSScott Long bus = cll->lun[i].physical.bus; 15721fe6c4eeSScott Long sc->ciss_max_logical_bus = max(sc->ciss_max_logical_bus, bus) + 1; 15731fe6c4eeSScott Long } else { 15741fe6c4eeSScott Long bus = CISS_EXTRA_BUS2(cll->lun[i].physical.extra_address); 15751fe6c4eeSScott Long sc->ciss_max_physical_bus = max(sc->ciss_max_physical_bus, bus); 1576c6131460SPaul Saab } 1577c6131460SPaul Saab } 1578c6131460SPaul Saab 1579c6131460SPaul Saab sc->ciss_controllers = 1580ac2fffa4SPedro F. Giffuni malloc(sc->ciss_max_logical_bus * sizeof (union ciss_device_address), 1581c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1582c6131460SPaul Saab 1583c6131460SPaul Saab if (sc->ciss_controllers == NULL) { 1584c6131460SPaul Saab ciss_printf(sc, "Could not allocate memory for controller map\n"); 1585c6131460SPaul Saab error = ENOMEM; 1586c6131460SPaul Saab goto out; 1587c6131460SPaul Saab } 1588c6131460SPaul Saab 1589c6131460SPaul Saab /* setup a map of controller addresses */ 1590c6131460SPaul Saab for (i = 0; i < nphys; i++) { 1591c6131460SPaul Saab if (cll->lun[i].physical.extra_address == 0) { 1592c6131460SPaul Saab sc->ciss_controllers[cll->lun[i].physical.bus] = cll->lun[i]; 1593c6131460SPaul Saab } 1594c6131460SPaul Saab } 1595c6131460SPaul Saab 15961fe6c4eeSScott Long sc->ciss_physical = 1597ac2fffa4SPedro F. Giffuni malloc(sc->ciss_max_physical_bus * sizeof(struct ciss_pdrive *), 15981fe6c4eeSScott Long CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 15991fe6c4eeSScott Long if (sc->ciss_physical == NULL) { 16001fe6c4eeSScott Long ciss_printf(sc, "Could not allocate memory for physical device map\n"); 16011fe6c4eeSScott Long error = ENOMEM; 16021fe6c4eeSScott Long goto out; 16031fe6c4eeSScott Long } 16041fe6c4eeSScott Long 16051fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_physical_bus; i++) { 16061fe6c4eeSScott Long sc->ciss_physical[i] = 16071fe6c4eeSScott Long malloc(sizeof(struct ciss_pdrive) * CISS_MAX_PHYSTGT, 16081fe6c4eeSScott Long CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 16091fe6c4eeSScott Long if (sc->ciss_physical[i] == NULL) { 16101fe6c4eeSScott Long ciss_printf(sc, "Could not allocate memory for target map\n"); 16111fe6c4eeSScott Long error = ENOMEM; 16121fe6c4eeSScott Long goto out; 16131fe6c4eeSScott Long } 16141fe6c4eeSScott Long } 16151fe6c4eeSScott Long 16161fe6c4eeSScott Long ciss_filter_physical(sc, cll); 16171fe6c4eeSScott Long 1618c6131460SPaul Saab out: 1619c6131460SPaul Saab if (cll != NULL) 1620c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 1621c6131460SPaul Saab 1622c6131460SPaul Saab return(error); 1623c6131460SPaul Saab } 1624c6131460SPaul Saab 1625c6131460SPaul Saab static int 16261fe6c4eeSScott Long ciss_filter_physical(struct ciss_softc *sc, struct ciss_lun_report *cll) 16271fe6c4eeSScott Long { 16281fe6c4eeSScott Long u_int32_t ea; 16291fe6c4eeSScott Long int i, nphys; 16301fe6c4eeSScott Long int bus, target; 16311fe6c4eeSScott Long 16321fe6c4eeSScott Long nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 16331fe6c4eeSScott Long for (i = 0; i < nphys; i++) { 16341fe6c4eeSScott Long if (cll->lun[i].physical.extra_address == 0) 16351fe6c4eeSScott Long continue; 16361fe6c4eeSScott Long 16371fe6c4eeSScott Long /* 16381fe6c4eeSScott Long * Filter out devices that we don't want. Level 3 LUNs could 16391fe6c4eeSScott Long * probably be supported, but the docs don't give enough of a 16401fe6c4eeSScott Long * hint to know how. 16411fe6c4eeSScott Long * 16421fe6c4eeSScott Long * The mode field of the physical address is likely set to have 16431fe6c4eeSScott Long * hard disks masked out. Honor it unless the user has overridden 16441fe6c4eeSScott Long * us with the tunable. We also munge the inquiry data for these 16451fe6c4eeSScott Long * disks so that they only show up as passthrough devices. Keeping 16461fe6c4eeSScott Long * them visible in this fashion is useful for doing things like 16471fe6c4eeSScott Long * flashing firmware. 16481fe6c4eeSScott Long */ 16491fe6c4eeSScott Long ea = cll->lun[i].physical.extra_address; 16501fe6c4eeSScott Long if ((CISS_EXTRA_BUS3(ea) != 0) || (CISS_EXTRA_TARGET3(ea) != 0) || 16511fe6c4eeSScott Long (CISS_EXTRA_MODE2(ea) == 0x3)) 16521fe6c4eeSScott Long continue; 16531fe6c4eeSScott Long if ((ciss_expose_hidden_physical == 0) && 16541fe6c4eeSScott Long (cll->lun[i].physical.mode == CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL)) 16551fe6c4eeSScott Long continue; 16561fe6c4eeSScott Long 16571fe6c4eeSScott Long /* 16581fe6c4eeSScott Long * Note: CISS firmware numbers physical busses starting at '1', not 16591fe6c4eeSScott Long * '0'. This numbering is internal to the firmware and is only 16601fe6c4eeSScott Long * used as a hint here. 16611fe6c4eeSScott Long */ 16621fe6c4eeSScott Long bus = CISS_EXTRA_BUS2(ea) - 1; 16631fe6c4eeSScott Long target = CISS_EXTRA_TARGET2(ea); 16641fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_address = cll->lun[i]; 16651fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_online = 1; 16661fe6c4eeSScott Long } 16671fe6c4eeSScott Long 16681fe6c4eeSScott Long return (0); 16691fe6c4eeSScott Long } 16701fe6c4eeSScott Long 16711fe6c4eeSScott Long static int 1672440baa08SPaul Saab ciss_inquiry_logical(struct ciss_softc *sc, struct ciss_ldrive *ld) 1673440baa08SPaul Saab { 1674440baa08SPaul Saab struct ciss_request *cr; 1675440baa08SPaul Saab struct ciss_command *cc; 1676440baa08SPaul Saab struct scsi_inquiry *inq; 1677440baa08SPaul Saab int error; 1678440baa08SPaul Saab int command_status; 1679440baa08SPaul Saab 1680440baa08SPaul Saab cr = NULL; 1681440baa08SPaul Saab 1682440baa08SPaul Saab bzero(&ld->cl_geometry, sizeof(ld->cl_geometry)); 1683440baa08SPaul Saab 1684440baa08SPaul Saab if ((error = ciss_get_request(sc, &cr)) != 0) 1685440baa08SPaul Saab goto out; 1686440baa08SPaul Saab 16872fdaa90dSScott Long cc = cr->cr_cc; 1688440baa08SPaul Saab cr->cr_data = &ld->cl_geometry; 1689440baa08SPaul Saab cr->cr_length = sizeof(ld->cl_geometry); 1690440baa08SPaul Saab cr->cr_flags = CISS_REQ_DATAIN; 1691440baa08SPaul Saab 1692c6131460SPaul Saab cc->header.address = ld->cl_address; 1693440baa08SPaul Saab cc->cdb.cdb_length = 6; 1694440baa08SPaul Saab cc->cdb.type = CISS_CDB_TYPE_COMMAND; 1695440baa08SPaul Saab cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 1696440baa08SPaul Saab cc->cdb.direction = CISS_CDB_DIRECTION_READ; 1697440baa08SPaul Saab cc->cdb.timeout = 30; 1698440baa08SPaul Saab 1699440baa08SPaul Saab inq = (struct scsi_inquiry *)&(cc->cdb.cdb[0]); 1700440baa08SPaul Saab inq->opcode = INQUIRY; 1701440baa08SPaul Saab inq->byte2 = SI_EVPD; 1702440baa08SPaul Saab inq->page_code = CISS_VPD_LOGICAL_DRIVE_GEOMETRY; 1703130f4520SKenneth D. Merry scsi_ulto2b(sizeof(ld->cl_geometry), inq->length); 1704440baa08SPaul Saab 1705440baa08SPaul Saab if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 1706440baa08SPaul Saab ciss_printf(sc, "error getting geometry (%d)\n", error); 1707440baa08SPaul Saab goto out; 1708440baa08SPaul Saab } 1709440baa08SPaul Saab 1710440baa08SPaul Saab ciss_report_request(cr, &command_status, NULL); 1711440baa08SPaul Saab switch(command_status) { 1712440baa08SPaul Saab case CISS_CMD_STATUS_SUCCESS: 1713440baa08SPaul Saab case CISS_CMD_STATUS_DATA_UNDERRUN: 1714440baa08SPaul Saab break; 1715440baa08SPaul Saab case CISS_CMD_STATUS_DATA_OVERRUN: 1716440baa08SPaul Saab ciss_printf(sc, "WARNING: Data overrun\n"); 1717440baa08SPaul Saab break; 1718440baa08SPaul Saab default: 1719440baa08SPaul Saab ciss_printf(sc, "Error detecting logical drive geometry (%s)\n", 1720440baa08SPaul Saab ciss_name_command_status(command_status)); 1721440baa08SPaul Saab break; 1722440baa08SPaul Saab } 1723440baa08SPaul Saab 1724440baa08SPaul Saab out: 1725440baa08SPaul Saab if (cr != NULL) 1726440baa08SPaul Saab ciss_release_request(cr); 1727440baa08SPaul Saab return(error); 1728440baa08SPaul Saab } 17293a31b7ebSMike Smith /************************************************************************ 17303a31b7ebSMike Smith * Identify a logical drive, initialise state related to it. 17313a31b7ebSMike Smith */ 17323a31b7ebSMike Smith static int 17333a31b7ebSMike Smith ciss_identify_logical(struct ciss_softc *sc, struct ciss_ldrive *ld) 17343a31b7ebSMike Smith { 17353a31b7ebSMike Smith struct ciss_request *cr; 17363a31b7ebSMike Smith struct ciss_command *cc; 17373a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 17383a31b7ebSMike Smith int error, command_status; 17393a31b7ebSMike Smith 17403a31b7ebSMike Smith debug_called(1); 17413a31b7ebSMike Smith 17423a31b7ebSMike Smith cr = NULL; 17433a31b7ebSMike Smith 17443a31b7ebSMike Smith /* 17453a31b7ebSMike Smith * Build a BMIC request to fetch the drive ID. 17463a31b7ebSMike Smith */ 17473a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_LDRIVE, 17483a31b7ebSMike Smith (void **)&ld->cl_ldrive, 17493a31b7ebSMike Smith sizeof(*ld->cl_ldrive))) != 0) 17503a31b7ebSMike Smith goto out; 17512fdaa90dSScott Long cc = cr->cr_cc; 1752c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 17533a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1754c6131460SPaul Saab cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 17553a31b7ebSMike Smith 17563a31b7ebSMike Smith /* 17573a31b7ebSMike Smith * Submit the request and wait for it to complete. 17583a31b7ebSMike Smith */ 17593a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 17603a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC LDRIVE command (%d)\n", error); 17613a31b7ebSMike Smith goto out; 17623a31b7ebSMike Smith } 17633a31b7ebSMike Smith 17643a31b7ebSMike Smith /* 17653a31b7ebSMike Smith * Check response. 17663a31b7ebSMike Smith */ 17673a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 17683a31b7ebSMike Smith switch(command_status) { 17693a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 17703a31b7ebSMike Smith break; 17713a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 17723a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 17733a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading logical drive ID\n"); 17743a31b7ebSMike Smith default: 17753a31b7ebSMike Smith ciss_printf(sc, "error reading logical drive ID (%s)\n", 17763a31b7ebSMike Smith ciss_name_command_status(command_status)); 17773a31b7ebSMike Smith error = EIO; 17783a31b7ebSMike Smith goto out; 17793a31b7ebSMike Smith } 17803a31b7ebSMike Smith ciss_release_request(cr); 17813a31b7ebSMike Smith cr = NULL; 17823a31b7ebSMike Smith 17833a31b7ebSMike Smith /* 17843a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive status. 17853a31b7ebSMike Smith */ 17863a31b7ebSMike Smith if ((error = ciss_get_ldrive_status(sc, ld)) != 0) 17873a31b7ebSMike Smith goto out; 17883a31b7ebSMike Smith 17893a31b7ebSMike Smith /* 1790440baa08SPaul Saab * Get the logical drive geometry. 1791440baa08SPaul Saab */ 1792440baa08SPaul Saab if ((error = ciss_inquiry_logical(sc, ld)) != 0) 1793440baa08SPaul Saab goto out; 1794440baa08SPaul Saab 1795440baa08SPaul Saab /* 17963a31b7ebSMike Smith * Print the drive's basic characteristics. 17973a31b7ebSMike Smith */ 1798f373e6b8SPeter Eriksson if (bootverbose || ciss_verbose) { 1799c6131460SPaul Saab ciss_printf(sc, "logical drive (b%dt%d): %s, %dMB ", 1800c6131460SPaul Saab CISS_LUN_TO_BUS(ld->cl_address.logical.lun), 1801c6131460SPaul Saab CISS_LUN_TO_TARGET(ld->cl_address.logical.lun), 180279adbf76SPaul Saab ciss_name_ldrive_org(ld->cl_ldrive->fault_tolerance), 18033a31b7ebSMike Smith ((ld->cl_ldrive->blocks_available / (1024 * 1024)) * 18043a31b7ebSMike Smith ld->cl_ldrive->block_size)); 18053a31b7ebSMike Smith 18063a31b7ebSMike Smith ciss_print_ldrive(sc, ld); 18073a31b7ebSMike Smith } 18083a31b7ebSMike Smith out: 18093a31b7ebSMike Smith if (error != 0) { 18103a31b7ebSMike Smith /* make the drive not-exist */ 18113a31b7ebSMike Smith ld->cl_status = CISS_LD_NONEXISTENT; 18123a31b7ebSMike Smith if (ld->cl_ldrive != NULL) { 18133a31b7ebSMike Smith free(ld->cl_ldrive, CISS_MALLOC_CLASS); 18143a31b7ebSMike Smith ld->cl_ldrive = NULL; 18153a31b7ebSMike Smith } 18163a31b7ebSMike Smith if (ld->cl_lstatus != NULL) { 18173a31b7ebSMike Smith free(ld->cl_lstatus, CISS_MALLOC_CLASS); 18183a31b7ebSMike Smith ld->cl_lstatus = NULL; 18193a31b7ebSMike Smith } 18203a31b7ebSMike Smith } 18213a31b7ebSMike Smith if (cr != NULL) 18223a31b7ebSMike Smith ciss_release_request(cr); 18233a31b7ebSMike Smith 18243a31b7ebSMike Smith return(error); 18253a31b7ebSMike Smith } 18263a31b7ebSMike Smith 18273a31b7ebSMike Smith /************************************************************************ 18283a31b7ebSMike Smith * Get status for a logical drive. 18293a31b7ebSMike Smith * 18303a31b7ebSMike Smith * XXX should we also do this in response to Test Unit Ready? 18313a31b7ebSMike Smith */ 18323a31b7ebSMike Smith static int 18333a31b7ebSMike Smith ciss_get_ldrive_status(struct ciss_softc *sc, struct ciss_ldrive *ld) 18343a31b7ebSMike Smith { 18353a31b7ebSMike Smith struct ciss_request *cr; 18363a31b7ebSMike Smith struct ciss_command *cc; 18373a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 18383a31b7ebSMike Smith int error, command_status; 18393a31b7ebSMike Smith 18403a31b7ebSMike Smith /* 18413a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive status. 18423a31b7ebSMike Smith */ 18433a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_LSTATUS, 18443a31b7ebSMike Smith (void **)&ld->cl_lstatus, 18453a31b7ebSMike Smith sizeof(*ld->cl_lstatus))) != 0) 18463a31b7ebSMike Smith goto out; 18472fdaa90dSScott Long cc = cr->cr_cc; 1848c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 18493a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1850c6131460SPaul Saab cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 18513a31b7ebSMike Smith 18523a31b7ebSMike Smith /* 18533a31b7ebSMike Smith * Submit the request and wait for it to complete. 18543a31b7ebSMike Smith */ 18553a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 18563a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC LSTATUS command (%d)\n", error); 18573a31b7ebSMike Smith goto out; 18583a31b7ebSMike Smith } 18593a31b7ebSMike Smith 18603a31b7ebSMike Smith /* 18613a31b7ebSMike Smith * Check response. 18623a31b7ebSMike Smith */ 18633a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 18643a31b7ebSMike Smith switch(command_status) { 18653a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 18663a31b7ebSMike Smith break; 18673a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 18683a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 18693a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading logical drive status\n"); 18703a31b7ebSMike Smith default: 18713a31b7ebSMike Smith ciss_printf(sc, "error reading logical drive status (%s)\n", 18723a31b7ebSMike Smith ciss_name_command_status(command_status)); 18733a31b7ebSMike Smith error = EIO; 18743a31b7ebSMike Smith goto out; 18753a31b7ebSMike Smith } 18763a31b7ebSMike Smith 18773a31b7ebSMike Smith /* 18783a31b7ebSMike Smith * Set the drive's summary status based on the returned status. 18793a31b7ebSMike Smith * 18803a31b7ebSMike Smith * XXX testing shows that a failed JBOD drive comes back at next 18813a31b7ebSMike Smith * boot in "queued for expansion" mode. WTF? 18823a31b7ebSMike Smith */ 18833a31b7ebSMike Smith ld->cl_status = ciss_decode_ldrive_status(ld->cl_lstatus->status); 18843a31b7ebSMike Smith 18853a31b7ebSMike Smith out: 18863a31b7ebSMike Smith if (cr != NULL) 18873a31b7ebSMike Smith ciss_release_request(cr); 18883a31b7ebSMike Smith return(error); 18893a31b7ebSMike Smith } 18903a31b7ebSMike Smith 18913a31b7ebSMike Smith /************************************************************************ 18923a31b7ebSMike Smith * Notify the adapter of a config update. 18933a31b7ebSMike Smith */ 18943a31b7ebSMike Smith static int 18953a31b7ebSMike Smith ciss_update_config(struct ciss_softc *sc) 18963a31b7ebSMike Smith { 18973a31b7ebSMike Smith int i; 18983a31b7ebSMike Smith 18993a31b7ebSMike Smith debug_called(1); 19003a31b7ebSMike Smith 19013a31b7ebSMike Smith CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IDBR, CISS_TL_SIMPLE_IDBR_CFG_TABLE); 19023a31b7ebSMike Smith for (i = 0; i < 1000; i++) { 19033a31b7ebSMike Smith if (!(CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IDBR) & 19043a31b7ebSMike Smith CISS_TL_SIMPLE_IDBR_CFG_TABLE)) { 19053a31b7ebSMike Smith return(0); 19063a31b7ebSMike Smith } 19073a31b7ebSMike Smith DELAY(1000); 19083a31b7ebSMike Smith } 19093a31b7ebSMike Smith return(1); 19103a31b7ebSMike Smith } 19113a31b7ebSMike Smith 19123a31b7ebSMike Smith /************************************************************************ 19133a31b7ebSMike Smith * Accept new media into a logical drive. 19143a31b7ebSMike Smith * 19153a31b7ebSMike Smith * XXX The drive has previously been offline; it would be good if we 19163a31b7ebSMike Smith * could make sure it's not open right now. 19173a31b7ebSMike Smith */ 19183a31b7ebSMike Smith static int 191988c78a38SPaul Saab ciss_accept_media(struct ciss_softc *sc, struct ciss_ldrive *ld) 19203a31b7ebSMike Smith { 19213a31b7ebSMike Smith struct ciss_request *cr; 19223a31b7ebSMike Smith struct ciss_command *cc; 19233a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 192488c78a38SPaul Saab int command_status; 192588c78a38SPaul Saab int error = 0, ldrive; 1926609caf8dSPaul Saab 1927609caf8dSPaul Saab ldrive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 19283a31b7ebSMike Smith 19293ea59fd3SSean Bruno debug(0, "bringing logical drive %d back online", ldrive); 19303a31b7ebSMike Smith 19313a31b7ebSMike Smith /* 19323a31b7ebSMike Smith * Build a CISS BMIC command to bring the drive back online. 19333a31b7ebSMike Smith */ 19343a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ACCEPT_MEDIA, 19353a31b7ebSMike Smith NULL, 0)) != 0) 19363a31b7ebSMike Smith goto out; 19372fdaa90dSScott Long cc = cr->cr_cc; 1938c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 19393a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1940609caf8dSPaul Saab cbc->log_drive = ldrive; 19413a31b7ebSMike Smith 19423a31b7ebSMike Smith /* 19433a31b7ebSMike Smith * Submit the request and wait for it to complete. 19443a31b7ebSMike Smith */ 19453a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 194688c78a38SPaul Saab ciss_printf(sc, "error sending BMIC ACCEPT MEDIA command (%d)\n", error); 19473a31b7ebSMike Smith goto out; 19483a31b7ebSMike Smith } 19493a31b7ebSMike Smith 19503a31b7ebSMike Smith /* 19513a31b7ebSMike Smith * Check response. 19523a31b7ebSMike Smith */ 19533a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 19543a31b7ebSMike Smith switch(command_status) { 19553a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* all OK */ 19563a31b7ebSMike Smith /* we should get a logical drive status changed event here */ 19573a31b7ebSMike Smith break; 19583a31b7ebSMike Smith default: 19593a31b7ebSMike Smith ciss_printf(cr->cr_sc, "error accepting media into failed logical drive (%s)\n", 19603a31b7ebSMike Smith ciss_name_command_status(command_status)); 19613a31b7ebSMike Smith break; 19623a31b7ebSMike Smith } 196388c78a38SPaul Saab 196488c78a38SPaul Saab out: 196588c78a38SPaul Saab if (cr != NULL) 19663a31b7ebSMike Smith ciss_release_request(cr); 196788c78a38SPaul Saab return(error); 19683a31b7ebSMike Smith } 19693a31b7ebSMike Smith 19703a31b7ebSMike Smith /************************************************************************ 19713a31b7ebSMike Smith * Release adapter resources. 19723a31b7ebSMike Smith */ 19733a31b7ebSMike Smith static void 19743a31b7ebSMike Smith ciss_free(struct ciss_softc *sc) 19753a31b7ebSMike Smith { 19763284b9eeSPaul Saab struct ciss_request *cr; 1977ee626b40SPaul Saab int i, j; 19783284b9eeSPaul Saab 19793a31b7ebSMike Smith debug_called(1); 19803a31b7ebSMike Smith 19813a31b7ebSMike Smith /* we're going away */ 19823a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_ABORTING; 19833a31b7ebSMike Smith 19843a31b7ebSMike Smith /* terminate the periodic heartbeat routine */ 19852472e51eSScott Long callout_stop(&sc->ciss_periodic); 19863a31b7ebSMike Smith 19873a31b7ebSMike Smith /* cancel the Event Notify chain */ 19883a31b7ebSMike Smith ciss_notify_abort(sc); 19893a31b7ebSMike Smith 1990c6131460SPaul Saab ciss_kill_notify_thread(sc); 1991c6131460SPaul Saab 19922472e51eSScott Long /* disconnect from CAM */ 19932472e51eSScott Long if (sc->ciss_cam_sim) { 19942472e51eSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 19952472e51eSScott Long if (sc->ciss_cam_sim[i]) { 19962472e51eSScott Long xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); 19972472e51eSScott Long cam_sim_free(sc->ciss_cam_sim[i], 0); 19982472e51eSScott Long } 19992472e51eSScott Long } 20002472e51eSScott Long for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 20012472e51eSScott Long CISS_PHYSICAL_BASE; i++) { 20022472e51eSScott Long if (sc->ciss_cam_sim[i]) { 20032472e51eSScott Long xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); 20042472e51eSScott Long cam_sim_free(sc->ciss_cam_sim[i], 0); 20052472e51eSScott Long } 20062472e51eSScott Long } 20072472e51eSScott Long free(sc->ciss_cam_sim, CISS_MALLOC_CLASS); 20082472e51eSScott Long } 20092472e51eSScott Long if (sc->ciss_cam_devq) 20102472e51eSScott Long cam_simq_free(sc->ciss_cam_devq); 20112472e51eSScott Long 201278d03361SPaul Saab /* remove the control device */ 20132472e51eSScott Long mtx_unlock(&sc->ciss_mtx); 201478d03361SPaul Saab if (sc->ciss_dev_t != NULL) 201578d03361SPaul Saab destroy_dev(sc->ciss_dev_t); 201678d03361SPaul Saab 20172472e51eSScott Long /* Final cleanup of the callout. */ 20182472e51eSScott Long callout_drain(&sc->ciss_periodic); 20192472e51eSScott Long mtx_destroy(&sc->ciss_mtx); 20202472e51eSScott Long 20213a31b7ebSMike Smith /* free the controller data */ 20223a31b7ebSMike Smith if (sc->ciss_id != NULL) 20233a31b7ebSMike Smith free(sc->ciss_id, CISS_MALLOC_CLASS); 20243a31b7ebSMike Smith 20253a31b7ebSMike Smith /* release I/O resources */ 20263a31b7ebSMike Smith if (sc->ciss_regs_resource != NULL) 20273a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, 20283a31b7ebSMike Smith sc->ciss_regs_rid, sc->ciss_regs_resource); 20293a31b7ebSMike Smith if (sc->ciss_cfg_resource != NULL) 20303a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, 20313a31b7ebSMike Smith sc->ciss_cfg_rid, sc->ciss_cfg_resource); 20323a31b7ebSMike Smith if (sc->ciss_intr != NULL) 20333a31b7ebSMike Smith bus_teardown_intr(sc->ciss_dev, sc->ciss_irq_resource, sc->ciss_intr); 20343a31b7ebSMike Smith if (sc->ciss_irq_resource != NULL) 20353a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_IRQ, 203622657ce1SScott Long sc->ciss_irq_rid[0], sc->ciss_irq_resource); 203722657ce1SScott Long if (sc->ciss_msi) 203822657ce1SScott Long pci_release_msi(sc->ciss_dev); 20393284b9eeSPaul Saab 20403284b9eeSPaul Saab while ((cr = ciss_dequeue_free(sc)) != NULL) 20413284b9eeSPaul Saab bus_dmamap_destroy(sc->ciss_buffer_dmat, cr->cr_datamap); 20423a31b7ebSMike Smith if (sc->ciss_buffer_dmat) 20433a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_buffer_dmat); 20443a31b7ebSMike Smith 20453a31b7ebSMike Smith /* destroy command memory and DMA tag */ 20463a31b7ebSMike Smith if (sc->ciss_command != NULL) { 20473a31b7ebSMike Smith bus_dmamap_unload(sc->ciss_command_dmat, sc->ciss_command_map); 20483a31b7ebSMike Smith bus_dmamem_free(sc->ciss_command_dmat, sc->ciss_command, sc->ciss_command_map); 20493a31b7ebSMike Smith } 20503284b9eeSPaul Saab if (sc->ciss_command_dmat) 20513a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_command_dmat); 20523a31b7ebSMike Smith 205322657ce1SScott Long if (sc->ciss_reply) { 205422657ce1SScott Long bus_dmamap_unload(sc->ciss_reply_dmat, sc->ciss_reply_map); 205522657ce1SScott Long bus_dmamem_free(sc->ciss_reply_dmat, sc->ciss_reply, sc->ciss_reply_map); 205622657ce1SScott Long } 205722657ce1SScott Long if (sc->ciss_reply_dmat) 205822657ce1SScott Long bus_dma_tag_destroy(sc->ciss_reply_dmat); 205922657ce1SScott Long 206022657ce1SScott Long /* destroy DMA tags */ 206122657ce1SScott Long if (sc->ciss_parent_dmat) 206222657ce1SScott Long bus_dma_tag_destroy(sc->ciss_parent_dmat); 2063c6131460SPaul Saab if (sc->ciss_logical) { 20645eae46afSConrad Meyer for (i = 0; i < sc->ciss_max_logical_bus; i++) { 2065e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { 2066ee626b40SPaul Saab if (sc->ciss_logical[i][j].cl_ldrive) 2067ee626b40SPaul Saab free(sc->ciss_logical[i][j].cl_ldrive, CISS_MALLOC_CLASS); 2068ee626b40SPaul Saab if (sc->ciss_logical[i][j].cl_lstatus) 2069ee626b40SPaul Saab free(sc->ciss_logical[i][j].cl_lstatus, CISS_MALLOC_CLASS); 2070ee626b40SPaul Saab } 2071c6131460SPaul Saab free(sc->ciss_logical[i], CISS_MALLOC_CLASS); 2072ee626b40SPaul Saab } 2073c6131460SPaul Saab free(sc->ciss_logical, CISS_MALLOC_CLASS); 2074c6131460SPaul Saab } 2075c6131460SPaul Saab 20761fe6c4eeSScott Long if (sc->ciss_physical) { 20771fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_physical_bus; i++) 20781fe6c4eeSScott Long free(sc->ciss_physical[i], CISS_MALLOC_CLASS); 20791fe6c4eeSScott Long free(sc->ciss_physical, CISS_MALLOC_CLASS); 20801fe6c4eeSScott Long } 20811fe6c4eeSScott Long 2082c6131460SPaul Saab if (sc->ciss_controllers) 2083c6131460SPaul Saab free(sc->ciss_controllers, CISS_MALLOC_CLASS); 2084975b7318SScott Long 20853a31b7ebSMike Smith } 20863a31b7ebSMike Smith 20873a31b7ebSMike Smith /************************************************************************ 20883a31b7ebSMike Smith * Give a command to the adapter. 20893a31b7ebSMike Smith * 20903a31b7ebSMike Smith * Note that this uses the simple transport layer directly. If we 20913a31b7ebSMike Smith * want to add support for other layers, we'll need a switch of some 20923a31b7ebSMike Smith * sort. 20933a31b7ebSMike Smith * 20943a31b7ebSMike Smith * Note that the simple transport layer has no way of refusing a 20953a31b7ebSMike Smith * command; we only have as many request structures as the adapter 20963a31b7ebSMike Smith * supports commands, so we don't have to check (this presumes that 20973a31b7ebSMike Smith * the adapter can handle commands as fast as we throw them at it). 20983a31b7ebSMike Smith */ 20993a31b7ebSMike Smith static int 21003a31b7ebSMike Smith ciss_start(struct ciss_request *cr) 21013a31b7ebSMike Smith { 21023a31b7ebSMike Smith int error; 21033a31b7ebSMike Smith 2104fa911920SScott Long debug(2, "post command %d tag %d ", cr->cr_tag, cr->cr_cc->header.host_tag); 21053a31b7ebSMike Smith 21063a31b7ebSMike Smith /* 21073a31b7ebSMike Smith * Map the request's data. 21083a31b7ebSMike Smith */ 21093a31b7ebSMike Smith if ((error = ciss_map_request(cr))) 21103a31b7ebSMike Smith return(error); 21113a31b7ebSMike Smith 21123a31b7ebSMike Smith #if 0 21133a31b7ebSMike Smith ciss_print_request(cr); 21143a31b7ebSMike Smith #endif 21153a31b7ebSMike Smith 21163a31b7ebSMike Smith return(0); 21173a31b7ebSMike Smith } 21183a31b7ebSMike Smith 21193a31b7ebSMike Smith /************************************************************************ 21203a31b7ebSMike Smith * Fetch completed request(s) from the adapter, queue them for 21213a31b7ebSMike Smith * completion handling. 21223a31b7ebSMike Smith * 21233a31b7ebSMike Smith * Note that this uses the simple transport layer directly. If we 21243a31b7ebSMike Smith * want to add support for other layers, we'll need a switch of some 21253a31b7ebSMike Smith * sort. 21263a31b7ebSMike Smith * 21273a31b7ebSMike Smith * Note that the simple transport mechanism does not require any 21283a31b7ebSMike Smith * reentrancy protection; the OPQ read is atomic. If there is a 21293a31b7ebSMike Smith * chance of a race with something else that might move the request 21303a31b7ebSMike Smith * off the busy list, then we will have to lock against that 21313a31b7ebSMike Smith * (eg. timeouts, etc.) 21323a31b7ebSMike Smith */ 21333a31b7ebSMike Smith static void 213422657ce1SScott Long ciss_done(struct ciss_softc *sc, cr_qhead_t *qh) 21353a31b7ebSMike Smith { 21363a31b7ebSMike Smith struct ciss_request *cr; 21373a31b7ebSMike Smith struct ciss_command *cc; 21383a31b7ebSMike Smith u_int32_t tag, index; 21393a31b7ebSMike Smith 21403a31b7ebSMike Smith debug_called(3); 21413a31b7ebSMike Smith 21423a31b7ebSMike Smith /* 21433a31b7ebSMike Smith * Loop quickly taking requests from the adapter and moving them 214422657ce1SScott Long * to the completed queue. 21453a31b7ebSMike Smith */ 21463a31b7ebSMike Smith for (;;) { 21473a31b7ebSMike Smith tag = CISS_TL_SIMPLE_FETCH_CMD(sc); 21483a31b7ebSMike Smith if (tag == CISS_TL_SIMPLE_OPQ_EMPTY) 21493a31b7ebSMike Smith break; 21503a31b7ebSMike Smith index = tag >> 2; 21513a31b7ebSMike Smith debug(2, "completed command %d%s", index, 21523a31b7ebSMike Smith (tag & CISS_HDR_HOST_TAG_ERROR) ? " with error" : ""); 21533a31b7ebSMike Smith if (index >= sc->ciss_max_requests) { 21543a31b7ebSMike Smith ciss_printf(sc, "completed invalid request %d (0x%x)\n", index, tag); 21553a31b7ebSMike Smith continue; 21563a31b7ebSMike Smith } 21573a31b7ebSMike Smith cr = &(sc->ciss_request[index]); 21582fdaa90dSScott Long cc = cr->cr_cc; 21593a31b7ebSMike Smith cc->header.host_tag = tag; /* not updated by adapter */ 216022657ce1SScott Long ciss_enqueue_complete(cr, qh); 21613a31b7ebSMike Smith } 21623a31b7ebSMike Smith 216322657ce1SScott Long } 216422657ce1SScott Long 216522657ce1SScott Long static void 216622657ce1SScott Long ciss_perf_done(struct ciss_softc *sc, cr_qhead_t *qh) 216722657ce1SScott Long { 216822657ce1SScott Long struct ciss_request *cr; 216922657ce1SScott Long struct ciss_command *cc; 217022657ce1SScott Long u_int32_t tag, index; 217122657ce1SScott Long 217222657ce1SScott Long debug_called(3); 217322657ce1SScott Long 21743a31b7ebSMike Smith /* 217522657ce1SScott Long * Loop quickly taking requests from the adapter and moving them 217622657ce1SScott Long * to the completed queue. 21773a31b7ebSMike Smith */ 217822657ce1SScott Long for (;;) { 217922657ce1SScott Long tag = sc->ciss_reply[sc->ciss_rqidx]; 218022657ce1SScott Long if ((tag & CISS_CYCLE_MASK) != sc->ciss_cycle) 218122657ce1SScott Long break; 218222657ce1SScott Long index = tag >> 2; 218322657ce1SScott Long debug(2, "completed command %d%s\n", index, 218422657ce1SScott Long (tag & CISS_HDR_HOST_TAG_ERROR) ? " with error" : ""); 218522657ce1SScott Long if (index < sc->ciss_max_requests) { 218622657ce1SScott Long cr = &(sc->ciss_request[index]); 21872fdaa90dSScott Long cc = cr->cr_cc; 218822657ce1SScott Long cc->header.host_tag = tag; /* not updated by adapter */ 218922657ce1SScott Long ciss_enqueue_complete(cr, qh); 219022657ce1SScott Long } else { 219122657ce1SScott Long ciss_printf(sc, "completed invalid request %d (0x%x)\n", index, tag); 219222657ce1SScott Long } 219322657ce1SScott Long if (++sc->ciss_rqidx == sc->ciss_max_requests) { 219422657ce1SScott Long sc->ciss_rqidx = 0; 219522657ce1SScott Long sc->ciss_cycle ^= 1; 219622657ce1SScott Long } 219722657ce1SScott Long } 219822657ce1SScott Long 21993a31b7ebSMike Smith } 22003a31b7ebSMike Smith 22013a31b7ebSMike Smith /************************************************************************ 22023a31b7ebSMike Smith * Take an interrupt from the adapter. 22033a31b7ebSMike Smith */ 22043a31b7ebSMike Smith static void 22053a31b7ebSMike Smith ciss_intr(void *arg) 22063a31b7ebSMike Smith { 220722657ce1SScott Long cr_qhead_t qh; 22083a31b7ebSMike Smith struct ciss_softc *sc = (struct ciss_softc *)arg; 22093a31b7ebSMike Smith 22103a31b7ebSMike Smith /* 22113a31b7ebSMike Smith * The only interrupt we recognise indicates that there are 22123a31b7ebSMike Smith * entries in the outbound post queue. 22133a31b7ebSMike Smith */ 221422657ce1SScott Long STAILQ_INIT(&qh); 221522657ce1SScott Long ciss_done(sc, &qh); 2216975b7318SScott Long mtx_lock(&sc->ciss_mtx); 221722657ce1SScott Long ciss_complete(sc, &qh); 2218975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 22193a31b7ebSMike Smith } 22203a31b7ebSMike Smith 222122657ce1SScott Long static void 222222657ce1SScott Long ciss_perf_intr(void *arg) 222322657ce1SScott Long { 222422657ce1SScott Long struct ciss_softc *sc = (struct ciss_softc *)arg; 222522657ce1SScott Long 222622657ce1SScott Long /* Clear the interrupt and flush the bridges. Docs say that the flush 222722657ce1SScott Long * needs to be done twice, which doesn't seem right. 222822657ce1SScott Long */ 222922657ce1SScott Long CISS_TL_PERF_CLEAR_INT(sc); 223022657ce1SScott Long CISS_TL_PERF_FLUSH_INT(sc); 223122657ce1SScott Long 223222657ce1SScott Long ciss_perf_msi_intr(sc); 223322657ce1SScott Long } 223422657ce1SScott Long 223522657ce1SScott Long static void 223622657ce1SScott Long ciss_perf_msi_intr(void *arg) 223722657ce1SScott Long { 223822657ce1SScott Long cr_qhead_t qh; 223922657ce1SScott Long struct ciss_softc *sc = (struct ciss_softc *)arg; 224022657ce1SScott Long 224122657ce1SScott Long STAILQ_INIT(&qh); 224222657ce1SScott Long ciss_perf_done(sc, &qh); 224322657ce1SScott Long mtx_lock(&sc->ciss_mtx); 224422657ce1SScott Long ciss_complete(sc, &qh); 224522657ce1SScott Long mtx_unlock(&sc->ciss_mtx); 224622657ce1SScott Long } 224722657ce1SScott Long 22483a31b7ebSMike Smith /************************************************************************ 22493a31b7ebSMike Smith * Process completed requests. 22503a31b7ebSMike Smith * 22513a31b7ebSMike Smith * Requests can be completed in three fashions: 22523a31b7ebSMike Smith * 22533a31b7ebSMike Smith * - by invoking a callback function (cr_complete is non-null) 22543a31b7ebSMike Smith * - by waking up a sleeper (cr_flags has CISS_REQ_SLEEP set) 22553a31b7ebSMike Smith * - by clearing the CISS_REQ_POLL flag in interrupt/timeout context 22563a31b7ebSMike Smith */ 22573a31b7ebSMike Smith static void 225822657ce1SScott Long ciss_complete(struct ciss_softc *sc, cr_qhead_t *qh) 22593a31b7ebSMike Smith { 22603a31b7ebSMike Smith struct ciss_request *cr; 22613a31b7ebSMike Smith 22623a31b7ebSMike Smith debug_called(2); 22633a31b7ebSMike Smith 22643a31b7ebSMike Smith /* 22653a31b7ebSMike Smith * Loop taking requests off the completed queue and performing 22663a31b7ebSMike Smith * completion processing on them. 22673a31b7ebSMike Smith */ 22683a31b7ebSMike Smith for (;;) { 226922657ce1SScott Long if ((cr = ciss_dequeue_complete(sc, qh)) == NULL) 22703a31b7ebSMike Smith break; 22713a31b7ebSMike Smith ciss_unmap_request(cr); 22723a31b7ebSMike Smith 227322657ce1SScott Long if ((cr->cr_flags & CISS_REQ_BUSY) == 0) 227422657ce1SScott Long ciss_printf(sc, "WARNING: completing non-busy request\n"); 227522657ce1SScott Long cr->cr_flags &= ~CISS_REQ_BUSY; 227622657ce1SScott Long 22773a31b7ebSMike Smith /* 22783a31b7ebSMike Smith * If the request has a callback, invoke it. 22793a31b7ebSMike Smith */ 22803a31b7ebSMike Smith if (cr->cr_complete != NULL) { 22813a31b7ebSMike Smith cr->cr_complete(cr); 22823a31b7ebSMike Smith continue; 22833a31b7ebSMike Smith } 22843a31b7ebSMike Smith 22853a31b7ebSMike Smith /* 22863a31b7ebSMike Smith * If someone is sleeping on this request, wake them up. 22873a31b7ebSMike Smith */ 22883a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_SLEEP) { 22893a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_SLEEP; 22903a31b7ebSMike Smith wakeup(cr); 22913a31b7ebSMike Smith continue; 22923a31b7ebSMike Smith } 22933a31b7ebSMike Smith 22943a31b7ebSMike Smith /* 22953a31b7ebSMike Smith * If someone is polling this request for completion, signal. 22963a31b7ebSMike Smith */ 22973a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_POLL) { 22983a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_POLL; 22993a31b7ebSMike Smith continue; 23003a31b7ebSMike Smith } 23013a31b7ebSMike Smith 23023a31b7ebSMike Smith /* 23033a31b7ebSMike Smith * Give up and throw the request back on the free queue. This 23043a31b7ebSMike Smith * should never happen; resources will probably be lost. 23053a31b7ebSMike Smith */ 23063a31b7ebSMike Smith ciss_printf(sc, "WARNING: completed command with no submitter\n"); 23073a31b7ebSMike Smith ciss_enqueue_free(cr); 23083a31b7ebSMike Smith } 23093a31b7ebSMike Smith } 23103a31b7ebSMike Smith 23113a31b7ebSMike Smith /************************************************************************ 23123a31b7ebSMike Smith * Report on the completion status of a request, and pass back SCSI 23133a31b7ebSMike Smith * and command status values. 23143a31b7ebSMike Smith */ 23153a31b7ebSMike Smith static int 231622657ce1SScott Long _ciss_report_request(struct ciss_request *cr, int *command_status, int *scsi_status, const char *func) 23173a31b7ebSMike Smith { 23183a31b7ebSMike Smith struct ciss_command *cc; 23193a31b7ebSMike Smith struct ciss_error_info *ce; 23203a31b7ebSMike Smith 23213a31b7ebSMike Smith debug_called(2); 23223a31b7ebSMike Smith 23232fdaa90dSScott Long cc = cr->cr_cc; 23243a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 23253a31b7ebSMike Smith 23263a31b7ebSMike Smith /* 23273a31b7ebSMike Smith * We don't consider data under/overrun an error for the Report 2328cafc8393SPeter Eriksson * Logical/Physical LUNs, INQUIRY & RECEIVE_DIAGNOSTIC commands. 23293a31b7ebSMike Smith */ 23303a31b7ebSMike Smith if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) && 23312514c5bfSPaul Saab ((ce->command_status == CISS_CMD_STATUS_DATA_OVERRUN) || 23322514c5bfSPaul Saab (ce->command_status == CISS_CMD_STATUS_DATA_UNDERRUN)) && 23333a31b7ebSMike Smith ((cc->cdb.cdb[0] == CISS_OPCODE_REPORT_LOGICAL_LUNS) || 23342514c5bfSPaul Saab (cc->cdb.cdb[0] == CISS_OPCODE_REPORT_PHYSICAL_LUNS) || 2335cafc8393SPeter Eriksson (cc->cdb.cdb[0] == RECEIVE_DIAGNOSTIC) || 23362514c5bfSPaul Saab (cc->cdb.cdb[0] == INQUIRY))) { 23373a31b7ebSMike Smith cc->header.host_tag &= ~CISS_HDR_HOST_TAG_ERROR; 23383a31b7ebSMike Smith debug(2, "ignoring irrelevant under/overrun error"); 23393a31b7ebSMike Smith } 23403a31b7ebSMike Smith 23413a31b7ebSMike Smith /* 23423a31b7ebSMike Smith * Check the command's error bit, if clear, there's no status and 23433a31b7ebSMike Smith * everything is OK. 23443a31b7ebSMike Smith */ 23453a31b7ebSMike Smith if (!(cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR)) { 23463a31b7ebSMike Smith if (scsi_status != NULL) 23473a31b7ebSMike Smith *scsi_status = SCSI_STATUS_OK; 23483a31b7ebSMike Smith if (command_status != NULL) 23493a31b7ebSMike Smith *command_status = CISS_CMD_STATUS_SUCCESS; 23503a31b7ebSMike Smith return(0); 23513a31b7ebSMike Smith } else { 23523a31b7ebSMike Smith if (command_status != NULL) 23533a31b7ebSMike Smith *command_status = ce->command_status; 23543a31b7ebSMike Smith if (scsi_status != NULL) { 2355e8144a13SAlexander Motin if (ce->command_status == CISS_CMD_STATUS_DATA_UNDERRUN) { 2356e8144a13SAlexander Motin *scsi_status = SCSI_STATUS_OK; 2357e8144a13SAlexander Motin } else if (ce->command_status == CISS_CMD_STATUS_TARGET_STATUS) { 23583a31b7ebSMike Smith *scsi_status = ce->scsi_status; 23593a31b7ebSMike Smith } else { 23603a31b7ebSMike Smith *scsi_status = -1; 23613a31b7ebSMike Smith } 23623a31b7ebSMike Smith } 2363*d8b02467SPeter Eriksson if ((bootverbose || ciss_verbose > 3 || (ciss_verbose > 2 && ce->scsi_status != 0)) && 2364*d8b02467SPeter Eriksson (ce->command_status != CISS_CMD_STATUS_DATA_UNDERRUN)) { 2365*d8b02467SPeter Eriksson ciss_printf(cr->cr_sc, "command status 0x%x (%s) scsi status 0x%x (opcode 0x%02x)\n", 23663a31b7ebSMike Smith ce->command_status, ciss_name_command_status(ce->command_status), 2367*d8b02467SPeter Eriksson ce->scsi_status, 2368*d8b02467SPeter Eriksson cc->cdb.cdb[0]); 2369*d8b02467SPeter Eriksson } 23703a31b7ebSMike Smith if (ce->command_status == CISS_CMD_STATUS_INVALID_COMMAND) { 237122657ce1SScott Long ciss_printf(cr->cr_sc, "invalid command, offense size %d at %d, value 0x%x, function %s\n", 23723a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_size, 23733a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_offset, 237422657ce1SScott Long ce->additional_error_info.invalid_command.offense_value, 237522657ce1SScott Long func); 23763a31b7ebSMike Smith } 23773a31b7ebSMike Smith } 2378c6131460SPaul Saab #if 0 2379c6131460SPaul Saab ciss_print_request(cr); 2380c6131460SPaul Saab #endif 23813a31b7ebSMike Smith return(1); 23823a31b7ebSMike Smith } 23833a31b7ebSMike Smith 23843a31b7ebSMike Smith /************************************************************************ 23853a31b7ebSMike Smith * Issue a request and don't return until it's completed. 23863a31b7ebSMike Smith * 23873a31b7ebSMike Smith * Depending on adapter status, we may poll or sleep waiting for 23883a31b7ebSMike Smith * completion. 23893a31b7ebSMike Smith */ 23903a31b7ebSMike Smith static int 23913a31b7ebSMike Smith ciss_synch_request(struct ciss_request *cr, int timeout) 23923a31b7ebSMike Smith { 23933a31b7ebSMike Smith if (cr->cr_sc->ciss_flags & CISS_FLAG_RUNNING) { 23943a31b7ebSMike Smith return(ciss_wait_request(cr, timeout)); 23953a31b7ebSMike Smith } else { 23963a31b7ebSMike Smith return(ciss_poll_request(cr, timeout)); 23973a31b7ebSMike Smith } 23983a31b7ebSMike Smith } 23993a31b7ebSMike Smith 24003a31b7ebSMike Smith /************************************************************************ 24013a31b7ebSMike Smith * Issue a request and poll for completion. 24023a31b7ebSMike Smith * 24033a31b7ebSMike Smith * Timeout in milliseconds. 24043a31b7ebSMike Smith */ 24053a31b7ebSMike Smith static int 24063a31b7ebSMike Smith ciss_poll_request(struct ciss_request *cr, int timeout) 24073a31b7ebSMike Smith { 240822657ce1SScott Long cr_qhead_t qh; 240922657ce1SScott Long struct ciss_softc *sc; 24103a31b7ebSMike Smith int error; 24113a31b7ebSMike Smith 24123a31b7ebSMike Smith debug_called(2); 24133a31b7ebSMike Smith 241422657ce1SScott Long STAILQ_INIT(&qh); 241522657ce1SScott Long sc = cr->cr_sc; 24163a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_POLL; 24173a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) 24183a31b7ebSMike Smith return(error); 24193a31b7ebSMike Smith 24203a31b7ebSMike Smith do { 242122657ce1SScott Long if (sc->ciss_perf) 242222657ce1SScott Long ciss_perf_done(sc, &qh); 242322657ce1SScott Long else 242422657ce1SScott Long ciss_done(sc, &qh); 242522657ce1SScott Long ciss_complete(sc, &qh); 24263a31b7ebSMike Smith if (!(cr->cr_flags & CISS_REQ_POLL)) 24273a31b7ebSMike Smith return(0); 24283a31b7ebSMike Smith DELAY(1000); 24293a31b7ebSMike Smith } while (timeout-- >= 0); 24303a31b7ebSMike Smith return(EWOULDBLOCK); 24313a31b7ebSMike Smith } 24323a31b7ebSMike Smith 24333a31b7ebSMike Smith /************************************************************************ 24343a31b7ebSMike Smith * Issue a request and sleep waiting for completion. 24353a31b7ebSMike Smith * 24363a31b7ebSMike Smith * Timeout in milliseconds. Note that a spurious wakeup will reset 24373a31b7ebSMike Smith * the timeout. 24383a31b7ebSMike Smith */ 24393a31b7ebSMike Smith static int 24403a31b7ebSMike Smith ciss_wait_request(struct ciss_request *cr, int timeout) 24413a31b7ebSMike Smith { 244222657ce1SScott Long int error; 24433a31b7ebSMike Smith 24443a31b7ebSMike Smith debug_called(2); 24453a31b7ebSMike Smith 24463a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_SLEEP; 24473a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) 24483a31b7ebSMike Smith return(error); 24493a31b7ebSMike Smith 245040f05b02SPaul Saab while ((cr->cr_flags & CISS_REQ_SLEEP) && (error != EWOULDBLOCK)) { 245185c9dd9dSSteven Hartland error = msleep_sbt(cr, &cr->cr_sc->ciss_mtx, PRIBIO, "cissREQ", 245285c9dd9dSSteven Hartland SBT_1MS * timeout, 0, 0); 24533a31b7ebSMike Smith } 24543a31b7ebSMike Smith return(error); 24553a31b7ebSMike Smith } 24563a31b7ebSMike Smith 24576197ca15SPeter Wemm #if 0 24583a31b7ebSMike Smith /************************************************************************ 24593a31b7ebSMike Smith * Abort a request. Note that a potential exists here to race the 24603a31b7ebSMike Smith * request being completed; the caller must deal with this. 24613a31b7ebSMike Smith */ 24623a31b7ebSMike Smith static int 24633a31b7ebSMike Smith ciss_abort_request(struct ciss_request *ar) 24643a31b7ebSMike Smith { 24653a31b7ebSMike Smith struct ciss_request *cr; 24663a31b7ebSMike Smith struct ciss_command *cc; 24673a31b7ebSMike Smith struct ciss_message_cdb *cmc; 24683a31b7ebSMike Smith int error; 24693a31b7ebSMike Smith 24703a31b7ebSMike Smith debug_called(1); 24713a31b7ebSMike Smith 24723a31b7ebSMike Smith /* get a request */ 24733a31b7ebSMike Smith if ((error = ciss_get_request(ar->cr_sc, &cr)) != 0) 24743a31b7ebSMike Smith return(error); 24753a31b7ebSMike Smith 24763a31b7ebSMike Smith /* build the abort command */ 24772fdaa90dSScott Long cc = cr->cr_cc; 24783a31b7ebSMike Smith cc->header.address.mode.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; /* addressing? */ 24793a31b7ebSMike Smith cc->header.address.physical.target = 0; 24803a31b7ebSMike Smith cc->header.address.physical.bus = 0; 24813a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cmc); 24823a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_MESSAGE; 24833a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 24843a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_NONE; 24853a31b7ebSMike Smith cc->cdb.timeout = 30; 24863a31b7ebSMike Smith 24873a31b7ebSMike Smith cmc = (struct ciss_message_cdb *)&(cc->cdb.cdb[0]); 24883a31b7ebSMike Smith cmc->opcode = CISS_OPCODE_MESSAGE_ABORT; 24893a31b7ebSMike Smith cmc->type = CISS_MESSAGE_ABORT_TASK; 24903a31b7ebSMike Smith cmc->abort_tag = ar->cr_tag; /* endianness?? */ 24913a31b7ebSMike Smith 24923a31b7ebSMike Smith /* 24933a31b7ebSMike Smith * Send the request and wait for a response. If we believe we 24943a31b7ebSMike Smith * aborted the request OK, clear the flag that indicates it's 24953a31b7ebSMike Smith * running. 24963a31b7ebSMike Smith */ 24973a31b7ebSMike Smith error = ciss_synch_request(cr, 35 * 1000); 24983a31b7ebSMike Smith if (!error) 24993a31b7ebSMike Smith error = ciss_report_request(cr, NULL, NULL); 25003a31b7ebSMike Smith ciss_release_request(cr); 25013a31b7ebSMike Smith 25023a31b7ebSMike Smith return(error); 25033a31b7ebSMike Smith } 25046197ca15SPeter Wemm #endif 25053a31b7ebSMike Smith 25063a31b7ebSMike Smith /************************************************************************ 25073a31b7ebSMike Smith * Fetch and initialise a request 25083a31b7ebSMike Smith */ 25093a31b7ebSMike Smith static int 25103a31b7ebSMike Smith ciss_get_request(struct ciss_softc *sc, struct ciss_request **crp) 25113a31b7ebSMike Smith { 25123a31b7ebSMike Smith struct ciss_request *cr; 25133a31b7ebSMike Smith 25143a31b7ebSMike Smith debug_called(2); 25153a31b7ebSMike Smith 25163a31b7ebSMike Smith /* 25173a31b7ebSMike Smith * Get a request and clean it up. 25183a31b7ebSMike Smith */ 25193a31b7ebSMike Smith if ((cr = ciss_dequeue_free(sc)) == NULL) 25203a31b7ebSMike Smith return(ENOMEM); 25213a31b7ebSMike Smith 25223a31b7ebSMike Smith cr->cr_data = NULL; 25233a31b7ebSMike Smith cr->cr_flags = 0; 25243a31b7ebSMike Smith cr->cr_complete = NULL; 2525639717c8SPaul Saab cr->cr_private = NULL; 252622657ce1SScott Long cr->cr_sg_tag = CISS_SG_MAX; /* Backstop to prevent accidents */ 25273a31b7ebSMike Smith 25283a31b7ebSMike Smith ciss_preen_command(cr); 25293a31b7ebSMike Smith *crp = cr; 25303a31b7ebSMike Smith return(0); 25313a31b7ebSMike Smith } 25323a31b7ebSMike Smith 25333a31b7ebSMike Smith static void 25343a31b7ebSMike Smith ciss_preen_command(struct ciss_request *cr) 25353a31b7ebSMike Smith { 25363a31b7ebSMike Smith struct ciss_command *cc; 25373a31b7ebSMike Smith u_int32_t cmdphys; 25383a31b7ebSMike Smith 25393a31b7ebSMike Smith /* 25403a31b7ebSMike Smith * Clean up the command structure. 25413a31b7ebSMike Smith * 25423a31b7ebSMike Smith * Note that we set up the error_info structure here, since the 25433a31b7ebSMike Smith * length can be overwritten by any command. 25443a31b7ebSMike Smith */ 25452fdaa90dSScott Long cc = cr->cr_cc; 25463a31b7ebSMike Smith cc->header.sg_in_list = 0; /* kinda inefficient this way */ 25473a31b7ebSMike Smith cc->header.sg_total = 0; 25483a31b7ebSMike Smith cc->header.host_tag = cr->cr_tag << 2; 25493a31b7ebSMike Smith cc->header.host_tag_zeroes = 0; 25503d3ddb44SSean Bruno bzero(&(cc->sg[0]), CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)); 25512fdaa90dSScott Long cmdphys = cr->cr_ccphys; 25523a31b7ebSMike Smith cc->error_info.error_info_address = cmdphys + sizeof(struct ciss_command); 25533a31b7ebSMike Smith cc->error_info.error_info_length = CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command); 25543a31b7ebSMike Smith } 25553a31b7ebSMike Smith 25563a31b7ebSMike Smith /************************************************************************ 25573a31b7ebSMike Smith * Release a request to the free list. 25583a31b7ebSMike Smith */ 25593a31b7ebSMike Smith static void 25603a31b7ebSMike Smith ciss_release_request(struct ciss_request *cr) 25613a31b7ebSMike Smith { 25623a31b7ebSMike Smith 25633a31b7ebSMike Smith debug_called(2); 25643a31b7ebSMike Smith 25653a31b7ebSMike Smith /* release the request to the free queue */ 25663a31b7ebSMike Smith ciss_requeue_free(cr); 25673a31b7ebSMike Smith } 25683a31b7ebSMike Smith 25693a31b7ebSMike Smith /************************************************************************ 25703a31b7ebSMike Smith * Allocate a request that will be used to send a BMIC command. Do some 25713a31b7ebSMike Smith * of the common setup here to avoid duplicating it everywhere else. 25723a31b7ebSMike Smith */ 25733a31b7ebSMike Smith static int 25743a31b7ebSMike Smith ciss_get_bmic_request(struct ciss_softc *sc, struct ciss_request **crp, 25753a31b7ebSMike Smith int opcode, void **bufp, size_t bufsize) 25763a31b7ebSMike Smith { 25773a31b7ebSMike Smith struct ciss_request *cr; 25783a31b7ebSMike Smith struct ciss_command *cc; 25793a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 25803a31b7ebSMike Smith void *buf; 25813a31b7ebSMike Smith int error; 25823a31b7ebSMike Smith int dataout; 25833a31b7ebSMike Smith 25843a31b7ebSMike Smith debug_called(2); 25853a31b7ebSMike Smith 25863a31b7ebSMike Smith cr = NULL; 25873a31b7ebSMike Smith buf = NULL; 25883a31b7ebSMike Smith 25893a31b7ebSMike Smith /* 25903a31b7ebSMike Smith * Get a request. 25913a31b7ebSMike Smith */ 25923a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 25933a31b7ebSMike Smith goto out; 25943a31b7ebSMike Smith 25953a31b7ebSMike Smith /* 25963a31b7ebSMike Smith * Allocate data storage if requested, determine the data direction. 25973a31b7ebSMike Smith */ 25983a31b7ebSMike Smith dataout = 0; 25993a31b7ebSMike Smith if ((bufsize > 0) && (bufp != NULL)) { 26003a31b7ebSMike Smith if (*bufp == NULL) { 26013a31b7ebSMike Smith if ((buf = malloc(bufsize, CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 26023a31b7ebSMike Smith error = ENOMEM; 26033a31b7ebSMike Smith goto out; 26043a31b7ebSMike Smith } 26053a31b7ebSMike Smith } else { 26063a31b7ebSMike Smith buf = *bufp; 26073a31b7ebSMike Smith dataout = 1; /* we are given a buffer, so we are writing */ 26083a31b7ebSMike Smith } 26093a31b7ebSMike Smith } 26103a31b7ebSMike Smith 26113a31b7ebSMike Smith /* 26123a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive ID. 26133a31b7ebSMike Smith */ 26143a31b7ebSMike Smith cr->cr_data = buf; 26153a31b7ebSMike Smith cr->cr_length = bufsize; 26163a31b7ebSMike Smith if (!dataout) 26173a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 26183a31b7ebSMike Smith 26192fdaa90dSScott Long cc = cr->cr_cc; 26203a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 26213a31b7ebSMike Smith cc->header.address.physical.bus = 0; 26223a31b7ebSMike Smith cc->header.address.physical.target = 0; 26233a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cbc); 26243a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 26253a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 26263a31b7ebSMike Smith cc->cdb.direction = dataout ? CISS_CDB_DIRECTION_WRITE : CISS_CDB_DIRECTION_READ; 26273a31b7ebSMike Smith cc->cdb.timeout = 0; 26283a31b7ebSMike Smith 26293a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 26303a31b7ebSMike Smith bzero(cbc, sizeof(*cbc)); 26313a31b7ebSMike Smith cbc->opcode = dataout ? CISS_ARRAY_CONTROLLER_WRITE : CISS_ARRAY_CONTROLLER_READ; 26323a31b7ebSMike Smith cbc->bmic_opcode = opcode; 26333a31b7ebSMike Smith cbc->size = htons((u_int16_t)bufsize); 26343a31b7ebSMike Smith 26353a31b7ebSMike Smith out: 26363a31b7ebSMike Smith if (error) { 26373a31b7ebSMike Smith if (cr != NULL) 26383a31b7ebSMike Smith ciss_release_request(cr); 26393a31b7ebSMike Smith } else { 26403a31b7ebSMike Smith *crp = cr; 26413a31b7ebSMike Smith if ((bufp != NULL) && (*bufp == NULL) && (buf != NULL)) 26423a31b7ebSMike Smith *bufp = buf; 26433a31b7ebSMike Smith } 26443a31b7ebSMike Smith return(error); 26453a31b7ebSMike Smith } 26463a31b7ebSMike Smith 26473a31b7ebSMike Smith /************************************************************************ 26483a31b7ebSMike Smith * Handle a command passed in from userspace. 26493a31b7ebSMike Smith */ 26503a31b7ebSMike Smith static int 26513a31b7ebSMike Smith ciss_user_command(struct ciss_softc *sc, IOCTL_Command_struct *ioc) 26523a31b7ebSMike Smith { 26533a31b7ebSMike Smith struct ciss_request *cr; 26543a31b7ebSMike Smith struct ciss_command *cc; 26553a31b7ebSMike Smith struct ciss_error_info *ce; 26563c63a8b4SPaul Saab int error = 0; 26573a31b7ebSMike Smith 26583a31b7ebSMike Smith debug_called(1); 26593a31b7ebSMike Smith 26603a31b7ebSMike Smith cr = NULL; 26613a31b7ebSMike Smith 26623a31b7ebSMike Smith /* 26633a31b7ebSMike Smith * Get a request. 26643a31b7ebSMike Smith */ 2665f83695f5SPaul Saab while (ciss_get_request(sc, &cr) != 0) 2666975b7318SScott Long msleep(sc, &sc->ciss_mtx, PPAUSE, "cissREQ", hz); 26672fdaa90dSScott Long cc = cr->cr_cc; 26683a31b7ebSMike Smith 26693a31b7ebSMike Smith /* 26703a31b7ebSMike Smith * Allocate an in-kernel databuffer if required, copy in user data. 26713a31b7ebSMike Smith */ 2672744c0d23SScott Long mtx_unlock(&sc->ciss_mtx); 26733a31b7ebSMike Smith cr->cr_length = ioc->buf_size; 26743a31b7ebSMike Smith if (ioc->buf_size > 0) { 2675975b7318SScott Long if ((cr->cr_data = malloc(ioc->buf_size, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 26763a31b7ebSMike Smith error = ENOMEM; 2677744c0d23SScott Long goto out_unlocked; 26783a31b7ebSMike Smith } 26793a31b7ebSMike Smith if ((error = copyin(ioc->buf, cr->cr_data, ioc->buf_size))) { 26803a31b7ebSMike Smith debug(0, "copyin: bad data buffer %p/%d", ioc->buf, ioc->buf_size); 2681744c0d23SScott Long goto out_unlocked; 26823a31b7ebSMike Smith } 26833a31b7ebSMike Smith } 26843a31b7ebSMike Smith 26853a31b7ebSMike Smith /* 26863a31b7ebSMike Smith * Build the request based on the user command. 26873a31b7ebSMike Smith */ 26883a31b7ebSMike Smith bcopy(&ioc->LUN_info, &cc->header.address, sizeof(cc->header.address)); 26893a31b7ebSMike Smith bcopy(&ioc->Request, &cc->cdb, sizeof(cc->cdb)); 26903a31b7ebSMike Smith 26913a31b7ebSMike Smith /* XXX anything else to populate here? */ 2692744c0d23SScott Long mtx_lock(&sc->ciss_mtx); 26933a31b7ebSMike Smith 26943a31b7ebSMike Smith /* 26953a31b7ebSMike Smith * Run the command. 26963a31b7ebSMike Smith */ 26973a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000))) { 26983a31b7ebSMike Smith debug(0, "request failed - %d", error); 26993a31b7ebSMike Smith goto out; 27003a31b7ebSMike Smith } 27013a31b7ebSMike Smith 27023a31b7ebSMike Smith /* 27033c63a8b4SPaul Saab * Check to see if the command succeeded. 27043a31b7ebSMike Smith */ 27053a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 27063c6b8353SPaul Saab if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) == 0) 27073c63a8b4SPaul Saab bzero(ce, sizeof(*ce)); 27083c63a8b4SPaul Saab 27093c63a8b4SPaul Saab /* 27103c63a8b4SPaul Saab * Copy the results back to the user. 27113c63a8b4SPaul Saab */ 27123a31b7ebSMike Smith bcopy(ce, &ioc->error_info, sizeof(*ce)); 2713744c0d23SScott Long mtx_unlock(&sc->ciss_mtx); 27143a31b7ebSMike Smith if ((ioc->buf_size > 0) && 27153a31b7ebSMike Smith (error = copyout(cr->cr_data, ioc->buf, ioc->buf_size))) { 27163a31b7ebSMike Smith debug(0, "copyout: bad data buffer %p/%d", ioc->buf, ioc->buf_size); 2717744c0d23SScott Long goto out_unlocked; 27183a31b7ebSMike Smith } 27193a31b7ebSMike Smith 27203a31b7ebSMike Smith /* done OK */ 27213a31b7ebSMike Smith error = 0; 27223a31b7ebSMike Smith 2723744c0d23SScott Long out_unlocked: 2724744c0d23SScott Long mtx_lock(&sc->ciss_mtx); 2725744c0d23SScott Long 27263a31b7ebSMike Smith out: 27273a31b7ebSMike Smith if ((cr != NULL) && (cr->cr_data != NULL)) 27283a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 27293a31b7ebSMike Smith if (cr != NULL) 27303a31b7ebSMike Smith ciss_release_request(cr); 27313a31b7ebSMike Smith return(error); 27323a31b7ebSMike Smith } 27333a31b7ebSMike Smith 27343a31b7ebSMike Smith /************************************************************************ 27353a31b7ebSMike Smith * Map a request into bus-visible space, initialise the scatter/gather 27363a31b7ebSMike Smith * list. 27373a31b7ebSMike Smith */ 27383a31b7ebSMike Smith static int 27393a31b7ebSMike Smith ciss_map_request(struct ciss_request *cr) 27403a31b7ebSMike Smith { 27413a31b7ebSMike Smith struct ciss_softc *sc; 2742639717c8SPaul Saab int error = 0; 27433a31b7ebSMike Smith 27443a31b7ebSMike Smith debug_called(2); 27453a31b7ebSMike Smith 27463a31b7ebSMike Smith sc = cr->cr_sc; 27473a31b7ebSMike Smith 27483a31b7ebSMike Smith /* check that mapping is necessary */ 2749639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_MAPPED) 27503a31b7ebSMike Smith return(0); 27513a31b7ebSMike Smith 27523a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_MAPPED; 2753639717c8SPaul Saab 2754639717c8SPaul Saab bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, 2755639717c8SPaul Saab BUS_DMASYNC_PREWRITE); 2756639717c8SPaul Saab 2757639717c8SPaul Saab if (cr->cr_data != NULL) { 2758dd0b4fb6SKonstantin Belousov if (cr->cr_flags & CISS_REQ_CCB) 2759dd0b4fb6SKonstantin Belousov error = bus_dmamap_load_ccb(sc->ciss_buffer_dmat, 2760dd0b4fb6SKonstantin Belousov cr->cr_datamap, cr->cr_data, 2761dd0b4fb6SKonstantin Belousov ciss_request_map_helper, cr, 0); 2762dd0b4fb6SKonstantin Belousov else 2763639717c8SPaul Saab error = bus_dmamap_load(sc->ciss_buffer_dmat, cr->cr_datamap, 2764639717c8SPaul Saab cr->cr_data, cr->cr_length, 2765639717c8SPaul Saab ciss_request_map_helper, cr, 0); 2766639717c8SPaul Saab if (error != 0) 2767639717c8SPaul Saab return (error); 2768639717c8SPaul Saab } else { 2769639717c8SPaul Saab /* 2770639717c8SPaul Saab * Post the command to the adapter. 2771639717c8SPaul Saab */ 277222657ce1SScott Long cr->cr_sg_tag = CISS_SG_NONE; 277322657ce1SScott Long cr->cr_flags |= CISS_REQ_BUSY; 277422657ce1SScott Long if (sc->ciss_perf) 277522657ce1SScott Long CISS_TL_PERF_POST_CMD(sc, cr); 277622657ce1SScott Long else 27772fdaa90dSScott Long CISS_TL_SIMPLE_POST_CMD(sc, cr->cr_ccphys); 2778639717c8SPaul Saab } 2779639717c8SPaul Saab 27803a31b7ebSMike Smith return(0); 27813a31b7ebSMike Smith } 27823a31b7ebSMike Smith 27833a31b7ebSMike Smith static void 27843a31b7ebSMike Smith ciss_request_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error) 27853a31b7ebSMike Smith { 27863a31b7ebSMike Smith struct ciss_command *cc; 2787639717c8SPaul Saab struct ciss_request *cr; 2788639717c8SPaul Saab struct ciss_softc *sc; 27893a31b7ebSMike Smith int i; 27903a31b7ebSMike Smith 27913a31b7ebSMike Smith debug_called(2); 27923a31b7ebSMike Smith 2793639717c8SPaul Saab cr = (struct ciss_request *)arg; 2794639717c8SPaul Saab sc = cr->cr_sc; 27952fdaa90dSScott Long cc = cr->cr_cc; 2796639717c8SPaul Saab 27973a31b7ebSMike Smith for (i = 0; i < nseg; i++) { 27983a31b7ebSMike Smith cc->sg[i].address = segs[i].ds_addr; 27993a31b7ebSMike Smith cc->sg[i].length = segs[i].ds_len; 28003a31b7ebSMike Smith cc->sg[i].extension = 0; 28013a31b7ebSMike Smith } 28023a31b7ebSMike Smith /* we leave the s/g table entirely within the command */ 28033a31b7ebSMike Smith cc->header.sg_in_list = nseg; 28043a31b7ebSMike Smith cc->header.sg_total = nseg; 2805639717c8SPaul Saab 2806639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_DATAIN) 2807639717c8SPaul Saab bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREREAD); 2808639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_DATAOUT) 2809639717c8SPaul Saab bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREWRITE); 2810639717c8SPaul Saab 281162fdee1dSScott Long if (nseg == 0) 281222657ce1SScott Long cr->cr_sg_tag = CISS_SG_NONE; 281322657ce1SScott Long else if (nseg == 1) 281422657ce1SScott Long cr->cr_sg_tag = CISS_SG_1; 281522657ce1SScott Long else if (nseg == 2) 281622657ce1SScott Long cr->cr_sg_tag = CISS_SG_2; 281722657ce1SScott Long else if (nseg <= 4) 281822657ce1SScott Long cr->cr_sg_tag = CISS_SG_4; 281922657ce1SScott Long else if (nseg <= 8) 282022657ce1SScott Long cr->cr_sg_tag = CISS_SG_8; 282122657ce1SScott Long else if (nseg <= 16) 282222657ce1SScott Long cr->cr_sg_tag = CISS_SG_16; 282322657ce1SScott Long else if (nseg <= 32) 282422657ce1SScott Long cr->cr_sg_tag = CISS_SG_32; 282522657ce1SScott Long else 282622657ce1SScott Long cr->cr_sg_tag = CISS_SG_MAX; 282722657ce1SScott Long 2828639717c8SPaul Saab /* 2829639717c8SPaul Saab * Post the command to the adapter. 2830639717c8SPaul Saab */ 283122657ce1SScott Long cr->cr_flags |= CISS_REQ_BUSY; 283222657ce1SScott Long if (sc->ciss_perf) 283322657ce1SScott Long CISS_TL_PERF_POST_CMD(sc, cr); 283422657ce1SScott Long else 28352fdaa90dSScott Long CISS_TL_SIMPLE_POST_CMD(sc, cr->cr_ccphys); 28363a31b7ebSMike Smith } 28373a31b7ebSMike Smith 28383a31b7ebSMike Smith /************************************************************************ 28393a31b7ebSMike Smith * Unmap a request from bus-visible space. 28403a31b7ebSMike Smith */ 28413a31b7ebSMike Smith static void 28423a31b7ebSMike Smith ciss_unmap_request(struct ciss_request *cr) 28433a31b7ebSMike Smith { 28443a31b7ebSMike Smith struct ciss_softc *sc; 28453a31b7ebSMike Smith 28463a31b7ebSMike Smith debug_called(2); 28473a31b7ebSMike Smith 28483a31b7ebSMike Smith sc = cr->cr_sc; 28493a31b7ebSMike Smith 28503a31b7ebSMike Smith /* check that unmapping is necessary */ 2851639717c8SPaul Saab if ((cr->cr_flags & CISS_REQ_MAPPED) == 0) 28523a31b7ebSMike Smith return; 28533a31b7ebSMike Smith 2854639717c8SPaul Saab bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, 2855639717c8SPaul Saab BUS_DMASYNC_POSTWRITE); 2856639717c8SPaul Saab 2857639717c8SPaul Saab if (cr->cr_data == NULL) 2858639717c8SPaul Saab goto out; 2859639717c8SPaul Saab 28603a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_DATAIN) 28613a31b7ebSMike Smith bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTREAD); 28623a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_DATAOUT) 28633a31b7ebSMike Smith bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTWRITE); 28643a31b7ebSMike Smith 28653a31b7ebSMike Smith bus_dmamap_unload(sc->ciss_buffer_dmat, cr->cr_datamap); 2866639717c8SPaul Saab out: 28673a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_MAPPED; 28683a31b7ebSMike Smith } 28693a31b7ebSMike Smith 28703a31b7ebSMike Smith /************************************************************************ 28713a31b7ebSMike Smith * Attach the driver to CAM. 28723a31b7ebSMike Smith * 28733a31b7ebSMike Smith * We put all the logical drives on a single SCSI bus. 28743a31b7ebSMike Smith */ 28753a31b7ebSMike Smith static int 28763a31b7ebSMike Smith ciss_cam_init(struct ciss_softc *sc) 28773a31b7ebSMike Smith { 28781fe6c4eeSScott Long int i, maxbus; 28793a31b7ebSMike Smith 28803a31b7ebSMike Smith debug_called(1); 28813a31b7ebSMike Smith 28823a31b7ebSMike Smith /* 28833a31b7ebSMike Smith * Allocate a devq. We can reuse this for the masked physical 28843a31b7ebSMike Smith * devices if we decide to export these as well. 28853a31b7ebSMike Smith */ 288695dab4f2SAlexander Motin if ((sc->ciss_cam_devq = cam_simq_alloc(sc->ciss_max_requests - 2)) == NULL) { 28873a31b7ebSMike Smith ciss_printf(sc, "can't allocate CAM SIM queue\n"); 28883a31b7ebSMike Smith return(ENOMEM); 28893a31b7ebSMike Smith } 28903a31b7ebSMike Smith 28913a31b7ebSMike Smith /* 28923a31b7ebSMike Smith * Create a SIM. 28931fe6c4eeSScott Long * 28941fe6c4eeSScott Long * This naturally wastes a bit of memory. The alternative is to allocate 28951fe6c4eeSScott Long * and register each bus as it is found, and then track them on a linked 28961fe6c4eeSScott Long * list. Unfortunately, the driver has a few places where it needs to 28971fe6c4eeSScott Long * look up the SIM based solely on bus number, and it's unclear whether 28981fe6c4eeSScott Long * a list traversal would work for these situations. 28993a31b7ebSMike Smith */ 29001fe6c4eeSScott Long maxbus = max(sc->ciss_max_logical_bus, sc->ciss_max_physical_bus + 29011fe6c4eeSScott Long CISS_PHYSICAL_BASE); 2902ac2fffa4SPedro F. Giffuni sc->ciss_cam_sim = malloc(maxbus * sizeof(struct cam_sim*), 2903c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 2904c6131460SPaul Saab if (sc->ciss_cam_sim == NULL) { 2905c6131460SPaul Saab ciss_printf(sc, "can't allocate memory for controller SIM\n"); 2906c6131460SPaul Saab return(ENOMEM); 2907c6131460SPaul Saab } 2908c6131460SPaul Saab 29091fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 2910c6131460SPaul Saab if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, 2911c6131460SPaul Saab "ciss", sc, 29122aa6b972SPaul Saab device_get_unit(sc->ciss_dev), 291345650f52SScott Long &sc->ciss_mtx, 291422657ce1SScott Long 2, 2915d4aa427fSPaul Saab sc->ciss_max_requests - 2, 29163a31b7ebSMike Smith sc->ciss_cam_devq)) == NULL) { 2917c6131460SPaul Saab ciss_printf(sc, "can't allocate CAM SIM for controller %d\n", i); 29183a31b7ebSMike Smith return(ENOMEM); 29193a31b7ebSMike Smith } 29203a31b7ebSMike Smith 29213a31b7ebSMike Smith /* 2922c6131460SPaul Saab * Register bus with this SIM. 29233a31b7ebSMike Smith */ 2924975b7318SScott Long mtx_lock(&sc->ciss_mtx); 29251fe6c4eeSScott Long if (i == 0 || sc->ciss_controllers[i].physical.bus != 0) { 2926b50569b7SScott Long if (xpt_bus_register(sc->ciss_cam_sim[i], sc->ciss_dev, i) != 0) { 29271fe6c4eeSScott Long ciss_printf(sc, "can't register SCSI bus %d\n", i); 2928975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 29291fe6c4eeSScott Long return (ENXIO); 29301fe6c4eeSScott Long } 29311fe6c4eeSScott Long } 2932975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 29331fe6c4eeSScott Long } 29341fe6c4eeSScott Long 29351fe6c4eeSScott Long for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 29361fe6c4eeSScott Long CISS_PHYSICAL_BASE; i++) { 29371fe6c4eeSScott Long if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, 29381fe6c4eeSScott Long "ciss", sc, 29391fe6c4eeSScott Long device_get_unit(sc->ciss_dev), 2940975b7318SScott Long &sc->ciss_mtx, 1, 29411fe6c4eeSScott Long sc->ciss_max_requests - 2, 29421fe6c4eeSScott Long sc->ciss_cam_devq)) == NULL) { 29431fe6c4eeSScott Long ciss_printf(sc, "can't allocate CAM SIM for controller %d\n", i); 29441fe6c4eeSScott Long return (ENOMEM); 29451fe6c4eeSScott Long } 29461fe6c4eeSScott Long 2947975b7318SScott Long mtx_lock(&sc->ciss_mtx); 2948b50569b7SScott Long if (xpt_bus_register(sc->ciss_cam_sim[i], sc->ciss_dev, i) != 0) { 2949c6131460SPaul Saab ciss_printf(sc, "can't register SCSI bus %d\n", i); 2950975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 29513a31b7ebSMike Smith return (ENXIO); 29523a31b7ebSMike Smith } 2953975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 2954c6131460SPaul Saab } 29553a31b7ebSMike Smith 29563a31b7ebSMike Smith return(0); 29573a31b7ebSMike Smith } 29583a31b7ebSMike Smith 29593a31b7ebSMike Smith /************************************************************************ 29603a31b7ebSMike Smith * Initiate a rescan of the 'logical devices' SIM 29613a31b7ebSMike Smith */ 29623a31b7ebSMike Smith static void 2963c6131460SPaul Saab ciss_cam_rescan_target(struct ciss_softc *sc, int bus, int target) 29643a31b7ebSMike Smith { 29653a31b7ebSMike Smith union ccb *ccb; 29663a31b7ebSMike Smith 29673a31b7ebSMike Smith debug_called(1); 29683a31b7ebSMike Smith 296983c5d981SAlexander Motin if ((ccb = xpt_alloc_ccb_nowait()) == NULL) { 29703a31b7ebSMike Smith ciss_printf(sc, "rescan failed (can't allocate CCB)\n"); 29713a31b7ebSMike Smith return; 29723a31b7ebSMike Smith } 29733a31b7ebSMike Smith 2974e5dfa058SAlexander Motin if (xpt_create_path(&ccb->ccb_h.path, NULL, 297583c5d981SAlexander Motin cam_sim_path(sc->ciss_cam_sim[bus]), 2976c6131460SPaul Saab target, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 29773a31b7ebSMike Smith ciss_printf(sc, "rescan failed (can't create path)\n"); 297883c5d981SAlexander Motin xpt_free_ccb(ccb); 29793a31b7ebSMike Smith return; 29803a31b7ebSMike Smith } 298183c5d981SAlexander Motin xpt_rescan(ccb); 29823a31b7ebSMike Smith /* scan is now in progress */ 29833a31b7ebSMike Smith } 29843a31b7ebSMike Smith 29853a31b7ebSMike Smith /************************************************************************ 29863a31b7ebSMike Smith * Handle requests coming from CAM 29873a31b7ebSMike Smith */ 29883a31b7ebSMike Smith static void 29893a31b7ebSMike Smith ciss_cam_action(struct cam_sim *sim, union ccb *ccb) 29903a31b7ebSMike Smith { 2991440baa08SPaul Saab struct ciss_softc *sc; 2992440baa08SPaul Saab struct ccb_scsiio *csio; 2993c6131460SPaul Saab int bus, target; 29941fe6c4eeSScott Long int physical; 2995440baa08SPaul Saab 2996440baa08SPaul Saab sc = cam_sim_softc(sim); 2997c6131460SPaul Saab bus = cam_sim_bus(sim); 2998440baa08SPaul Saab csio = (struct ccb_scsiio *)&ccb->csio; 2999440baa08SPaul Saab target = csio->ccb_h.target_id; 30001fe6c4eeSScott Long physical = CISS_IS_PHYSICAL(bus); 3001440baa08SPaul Saab 30023a31b7ebSMike Smith switch (ccb->ccb_h.func_code) { 30033a31b7ebSMike Smith /* perform SCSI I/O */ 30043a31b7ebSMike Smith case XPT_SCSI_IO: 3005440baa08SPaul Saab if (!ciss_cam_action_io(sim, csio)) 30063a31b7ebSMike Smith return; 30073a31b7ebSMike Smith break; 30083a31b7ebSMike Smith 30093a31b7ebSMike Smith /* perform geometry calculations */ 30103a31b7ebSMike Smith case XPT_CALC_GEOMETRY: 30113a31b7ebSMike Smith { 30123a31b7ebSMike Smith struct ccb_calc_geometry *ccg = &ccb->ccg; 30131fe6c4eeSScott Long struct ciss_ldrive *ld; 30143a31b7ebSMike Smith 30153a31b7ebSMike Smith debug(1, "XPT_CALC_GEOMETRY %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 30163a31b7ebSMike Smith 30171fe6c4eeSScott Long ld = NULL; 30181fe6c4eeSScott Long if (!physical) 30191fe6c4eeSScott Long ld = &sc->ciss_logical[bus][target]; 30201fe6c4eeSScott Long 30213a31b7ebSMike Smith /* 3022440baa08SPaul Saab * Use the cached geometry settings unless the fault tolerance 3023440baa08SPaul Saab * is invalid. 30243a31b7ebSMike Smith */ 30251fe6c4eeSScott Long if (physical || ld->cl_geometry.fault_tolerance == 0xFF) { 3026440baa08SPaul Saab u_int32_t secs_per_cylinder; 3027440baa08SPaul Saab 30283a31b7ebSMike Smith ccg->heads = 255; 30293a31b7ebSMike Smith ccg->secs_per_track = 32; 30303a31b7ebSMike Smith secs_per_cylinder = ccg->heads * ccg->secs_per_track; 30313a31b7ebSMike Smith ccg->cylinders = ccg->volume_size / secs_per_cylinder; 3032440baa08SPaul Saab } else { 3033440baa08SPaul Saab ccg->heads = ld->cl_geometry.heads; 3034440baa08SPaul Saab ccg->secs_per_track = ld->cl_geometry.sectors; 3035440baa08SPaul Saab ccg->cylinders = ntohs(ld->cl_geometry.cylinders); 3036440baa08SPaul Saab } 30373a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_CMP; 30383a31b7ebSMike Smith break; 30393a31b7ebSMike Smith } 30403a31b7ebSMike Smith 30413a31b7ebSMike Smith /* handle path attribute inquiry */ 30423a31b7ebSMike Smith case XPT_PATH_INQ: 30433a31b7ebSMike Smith { 30443a31b7ebSMike Smith struct ccb_pathinq *cpi = &ccb->cpi; 3045bdde5705SSean Bruno int sg_length; 30463a31b7ebSMike Smith 30473a31b7ebSMike Smith debug(1, "XPT_PATH_INQ %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 30483a31b7ebSMike Smith 30493a31b7ebSMike Smith cpi->version_num = 1; 30503a31b7ebSMike Smith cpi->hba_inquiry = PI_TAG_ABLE; /* XXX is this correct? */ 30513a31b7ebSMike Smith cpi->target_sprt = 0; 30523a31b7ebSMike Smith cpi->hba_misc = 0; 3053e3edca22SSean Bruno cpi->max_target = sc->ciss_cfg->max_logical_supported; 30543a31b7ebSMike Smith cpi->max_lun = 0; /* 'logical drive' channel only */ 3055e3edca22SSean Bruno cpi->initiator_id = sc->ciss_cfg->max_logical_supported; 30564195c7deSAlan Somers strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 30574195c7deSAlan Somers strlcpy(cpi->hba_vid, "CISS", HBA_IDLEN); 30584195c7deSAlan Somers strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 30593a31b7ebSMike Smith cpi->unit_number = cam_sim_unit(sim); 30603a31b7ebSMike Smith cpi->bus_id = cam_sim_bus(sim); 306174575d14SPeter Eriksson cpi->base_transfer_speed = ciss_base_transfer_speed; 3062fa9ed865SMatt Jacob cpi->transport = XPORT_SPI; 3063fa9ed865SMatt Jacob cpi->transport_version = 2; 3064fa9ed865SMatt Jacob cpi->protocol = PROTO_SCSI; 3065fa9ed865SMatt Jacob cpi->protocol_version = SCSI_REV_2; 3066bdde5705SSean Bruno if (sc->ciss_cfg->max_sg_length == 0) { 3067e8e4cdbaSSean Bruno sg_length = 17; 3068bdde5705SSean Bruno } else { 3069bdde5705SSean Bruno /* XXX Fix for ZMR cards that advertise max_sg_length == 32 3070bdde5705SSean Bruno * Confusing bit here. max_sg_length is usually a power of 2. We always 3071bdde5705SSean Bruno * need to subtract 1 to account for partial pages. Then we need to 3072bdde5705SSean Bruno * align on a valid PAGE_SIZE so we round down to the nearest power of 2. 3073bdde5705SSean Bruno * Add 1 so we can then subtract it out in the assignment to maxio. 3074bdde5705SSean Bruno * The reason for all these shenanigans is to create a maxio value that 3075bdde5705SSean Bruno * creates IO operations to volumes that yield consistent operations 3076bdde5705SSean Bruno * with good performance. 3077bdde5705SSean Bruno */ 3078bdde5705SSean Bruno sg_length = sc->ciss_cfg->max_sg_length - 1; 3079bdde5705SSean Bruno sg_length = (1 << (fls(sg_length) - 1)) + 1; 3080bdde5705SSean Bruno } 3081bdde5705SSean Bruno cpi->maxio = (min(CISS_MAX_SG_ELEMENTS, sg_length) - 1) * PAGE_SIZE; 30823a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_CMP; 30833a31b7ebSMike Smith break; 30843a31b7ebSMike Smith } 30853a31b7ebSMike Smith 30863a31b7ebSMike Smith case XPT_GET_TRAN_SETTINGS: 30873a31b7ebSMike Smith { 30883a31b7ebSMike Smith struct ccb_trans_settings *cts = &ccb->cts; 308963b9228bSScott Long struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi; 309063b9228bSScott Long struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi; 30913a31b7ebSMike Smith 3092fa911920SScott Long debug(1, "XPT_GET_TRAN_SETTINGS %d:%d", cam_sim_bus(sim), 3093fa911920SScott Long ctl->ccb_h.target_id); 30943a31b7ebSMike Smith /* disconnect always OK */ 3095fa9ed865SMatt Jacob cts->protocol = PROTO_SCSI; 3096fa9ed865SMatt Jacob cts->protocol_version = SCSI_REV_2; 3097fa9ed865SMatt Jacob cts->transport = XPORT_SPI; 3098fa9ed865SMatt Jacob cts->transport_version = 2; 3099fa9ed865SMatt Jacob 3100fa9ed865SMatt Jacob spi->valid = CTS_SPI_VALID_DISC; 3101fa9ed865SMatt Jacob spi->flags = CTS_SPI_FLAGS_DISC_ENB; 31023a31b7ebSMike Smith 310363b9228bSScott Long scsi->valid = CTS_SCSI_VALID_TQ; 310463b9228bSScott Long scsi->flags = CTS_SCSI_FLAGS_TAG_ENB; 310563b9228bSScott Long 31063a31b7ebSMike Smith cts->ccb_h.status = CAM_REQ_CMP; 31073a31b7ebSMike Smith break; 31083a31b7ebSMike Smith } 31093a31b7ebSMike Smith 31103a31b7ebSMike Smith default: /* we can't do this */ 31113a31b7ebSMike Smith debug(1, "unspported func_code = 0x%x", ccb->ccb_h.func_code); 31123a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_INVALID; 31133a31b7ebSMike Smith break; 31143a31b7ebSMike Smith } 31153a31b7ebSMike Smith 31163a31b7ebSMike Smith xpt_done(ccb); 31173a31b7ebSMike Smith } 31183a31b7ebSMike Smith 31193a31b7ebSMike Smith /************************************************************************ 31203a31b7ebSMike Smith * Handle a CAM SCSI I/O request. 31213a31b7ebSMike Smith */ 31223a31b7ebSMike Smith static int 31233a31b7ebSMike Smith ciss_cam_action_io(struct cam_sim *sim, struct ccb_scsiio *csio) 31243a31b7ebSMike Smith { 31253a31b7ebSMike Smith struct ciss_softc *sc; 31263a31b7ebSMike Smith int bus, target; 31273a31b7ebSMike Smith struct ciss_request *cr; 31283a31b7ebSMike Smith struct ciss_command *cc; 31293a31b7ebSMike Smith int error; 31303a31b7ebSMike Smith 31313a31b7ebSMike Smith sc = cam_sim_softc(sim); 31323a31b7ebSMike Smith bus = cam_sim_bus(sim); 31333a31b7ebSMike Smith target = csio->ccb_h.target_id; 31343a31b7ebSMike Smith 31353a31b7ebSMike Smith debug(2, "XPT_SCSI_IO %d:%d:%d", bus, target, csio->ccb_h.target_lun); 31363a31b7ebSMike Smith 31373a31b7ebSMike Smith /* check that the CDB pointer is not to a physical address */ 31383a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_CDB_POINTER) && (csio->ccb_h.flags & CAM_CDB_PHYS)) { 31393a31b7ebSMike Smith debug(3, " CDB pointer is to physical address"); 31403a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 31413a31b7ebSMike Smith } 31423a31b7ebSMike Smith 31433a31b7ebSMike Smith /* abandon aborted ccbs or those that have failed validation */ 31443a31b7ebSMike Smith if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) { 31453a31b7ebSMike Smith debug(3, "abandoning CCB due to abort/validation failure"); 31463a31b7ebSMike Smith return(EINVAL); 31473a31b7ebSMike Smith } 31483a31b7ebSMike Smith 31493a31b7ebSMike Smith /* handle emulation of some SCSI commands ourself */ 31503a31b7ebSMike Smith if (ciss_cam_emulate(sc, csio)) 31513a31b7ebSMike Smith return(0); 31523a31b7ebSMike Smith 31533a31b7ebSMike Smith /* 31543a31b7ebSMike Smith * Get a request to manage this command. If we can't, return the 31553a31b7ebSMike Smith * ccb, freeze the queue and flag so that we unfreeze it when a 31563a31b7ebSMike Smith * request completes. 31573a31b7ebSMike Smith */ 31583a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) { 31591fe6c4eeSScott Long xpt_freeze_simq(sim, 1); 316095dab4f2SAlexander Motin sc->ciss_flags |= CISS_FLAG_BUSY; 31613a31b7ebSMike Smith csio->ccb_h.status |= CAM_REQUEUE_REQ; 31623a31b7ebSMike Smith return(error); 31633a31b7ebSMike Smith } 31643a31b7ebSMike Smith 31653a31b7ebSMike Smith /* 31663a31b7ebSMike Smith * Build the command. 31673a31b7ebSMike Smith */ 31682fdaa90dSScott Long cc = cr->cr_cc; 3169dd0b4fb6SKonstantin Belousov cr->cr_data = csio; 31703a31b7ebSMike Smith cr->cr_length = csio->dxfer_len; 31713a31b7ebSMike Smith cr->cr_complete = ciss_cam_complete; 31723a31b7ebSMike Smith cr->cr_private = csio; 31733a31b7ebSMike Smith 3174c6131460SPaul Saab /* 3175c6131460SPaul Saab * Target the right logical volume. 3176c6131460SPaul Saab */ 31771fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) 31781fe6c4eeSScott Long cc->header.address = 31791fe6c4eeSScott Long sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_address; 31801fe6c4eeSScott Long else 31811fe6c4eeSScott Long cc->header.address = 31821fe6c4eeSScott Long sc->ciss_logical[bus][target].cl_address; 31833a31b7ebSMike Smith cc->cdb.cdb_length = csio->cdb_len; 31843a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 31853a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; /* XXX ordered tags? */ 31863a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) { 3187dd0b4fb6SKonstantin Belousov cr->cr_flags = CISS_REQ_DATAOUT | CISS_REQ_CCB; 31883a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; 31893a31b7ebSMike Smith } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 3190dd0b4fb6SKonstantin Belousov cr->cr_flags = CISS_REQ_DATAIN | CISS_REQ_CCB; 31913a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 31923a31b7ebSMike Smith } else { 3193dd0b4fb6SKonstantin Belousov cr->cr_data = NULL; 31943a31b7ebSMike Smith cr->cr_flags = 0; 31953a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_NONE; 31963a31b7ebSMike Smith } 31973a31b7ebSMike Smith cc->cdb.timeout = (csio->ccb_h.timeout / 1000) + 1; 31983a31b7ebSMike Smith if (csio->ccb_h.flags & CAM_CDB_POINTER) { 31993a31b7ebSMike Smith bcopy(csio->cdb_io.cdb_ptr, &cc->cdb.cdb[0], csio->cdb_len); 32003a31b7ebSMike Smith } else { 32013a31b7ebSMike Smith bcopy(csio->cdb_io.cdb_bytes, &cc->cdb.cdb[0], csio->cdb_len); 32023a31b7ebSMike Smith } 32033a31b7ebSMike Smith 32043a31b7ebSMike Smith /* 32053a31b7ebSMike Smith * Submit the request to the adapter. 32063a31b7ebSMike Smith * 32073a31b7ebSMike Smith * Note that this may fail if we're unable to map the request (and 32083a31b7ebSMike Smith * if we ever learn a transport layer other than simple, may fail 32093a31b7ebSMike Smith * if the adapter rejects the command). 32103a31b7ebSMike Smith */ 32113a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) { 32121fe6c4eeSScott Long xpt_freeze_simq(sim, 1); 3213639717c8SPaul Saab csio->ccb_h.status |= CAM_RELEASE_SIMQ; 32140a65b79fSAlexander Motin if (error == EINPROGRESS) { 3215639717c8SPaul Saab error = 0; 3216639717c8SPaul Saab } else { 32173a31b7ebSMike Smith csio->ccb_h.status |= CAM_REQUEUE_REQ; 32183a31b7ebSMike Smith ciss_release_request(cr); 3219639717c8SPaul Saab } 32203a31b7ebSMike Smith return(error); 32213a31b7ebSMike Smith } 32223a31b7ebSMike Smith 32233a31b7ebSMike Smith return(0); 32243a31b7ebSMike Smith } 32253a31b7ebSMike Smith 32263a31b7ebSMike Smith /************************************************************************ 32273a31b7ebSMike Smith * Emulate SCSI commands the adapter doesn't handle as we might like. 32283a31b7ebSMike Smith */ 32293a31b7ebSMike Smith static int 32303a31b7ebSMike Smith ciss_cam_emulate(struct ciss_softc *sc, struct ccb_scsiio *csio) 32313a31b7ebSMike Smith { 3232c6131460SPaul Saab int bus, target; 32333a31b7ebSMike Smith u_int8_t opcode; 32343a31b7ebSMike Smith 32353a31b7ebSMike Smith target = csio->ccb_h.target_id; 3236c6131460SPaul Saab bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); 32373a31b7ebSMike Smith opcode = (csio->ccb_h.flags & CAM_CDB_POINTER) ? 32383a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]; 32393a31b7ebSMike Smith 32401fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) { 32411fe6c4eeSScott Long if (sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_online != 1) { 32420a65b79fSAlexander Motin csio->ccb_h.status |= CAM_SEL_TIMEOUT; 32431fe6c4eeSScott Long xpt_done((union ccb *)csio); 32441fe6c4eeSScott Long return(1); 32451fe6c4eeSScott Long } else 32461fe6c4eeSScott Long return(0); 32471fe6c4eeSScott Long } 32481fe6c4eeSScott Long 32493a31b7ebSMike Smith /* 32506f71a953SPaul Saab * Handle requests for volumes that don't exist or are not online. 32516f71a953SPaul Saab * A selection timeout is slightly better than an illegal request. 32526f71a953SPaul Saab * Other errors might be better. 32533a31b7ebSMike Smith */ 32546f71a953SPaul Saab if (sc->ciss_logical[bus][target].cl_status != CISS_LD_ONLINE) { 32550a65b79fSAlexander Motin csio->ccb_h.status |= CAM_SEL_TIMEOUT; 32563a31b7ebSMike Smith xpt_done((union ccb *)csio); 32573a31b7ebSMike Smith return(1); 32583a31b7ebSMike Smith } 32593a31b7ebSMike Smith 32603a31b7ebSMike Smith /* if we have to fake Synchronise Cache */ 32613a31b7ebSMike Smith if (sc->ciss_flags & CISS_FLAG_FAKE_SYNCH) { 32623a31b7ebSMike Smith /* 32633a31b7ebSMike Smith * If this is a Synchronise Cache command, typically issued when 32643a31b7ebSMike Smith * a device is closed, flush the adapter and complete now. 32653a31b7ebSMike Smith */ 32663a31b7ebSMike Smith if (((csio->ccb_h.flags & CAM_CDB_POINTER) ? 32673a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) { 32683a31b7ebSMike Smith ciss_flush_adapter(sc); 32690a65b79fSAlexander Motin csio->ccb_h.status |= CAM_REQ_CMP; 32703a31b7ebSMike Smith xpt_done((union ccb *)csio); 32713a31b7ebSMike Smith return(1); 32723a31b7ebSMike Smith } 32733a31b7ebSMike Smith } 32743a31b7ebSMike Smith 3275a1abcc4fSSean Bruno /* 3276a1abcc4fSSean Bruno * A CISS target can only ever have one lun per target. REPORT_LUNS requires 3277a1abcc4fSSean Bruno * at least one LUN field to be pre created for us, so snag it and fill in 3278a1abcc4fSSean Bruno * the least significant byte indicating 1 LUN here. Emulate the command 3279a1abcc4fSSean Bruno * return to shut up warning on console of a CDB error. swb 3280a1abcc4fSSean Bruno */ 3281a1abcc4fSSean Bruno if (opcode == REPORT_LUNS && csio->dxfer_len > 0) { 3282a1abcc4fSSean Bruno csio->data_ptr[3] = 8; 3283a1abcc4fSSean Bruno csio->ccb_h.status |= CAM_REQ_CMP; 3284a1abcc4fSSean Bruno xpt_done((union ccb *)csio); 3285a1abcc4fSSean Bruno return(1); 3286a1abcc4fSSean Bruno } 3287a1abcc4fSSean Bruno 32883a31b7ebSMike Smith return(0); 32893a31b7ebSMike Smith } 32903a31b7ebSMike Smith 32913a31b7ebSMike Smith /************************************************************************ 32923a31b7ebSMike Smith * Check for possibly-completed commands. 32933a31b7ebSMike Smith */ 32943a31b7ebSMike Smith static void 32953a31b7ebSMike Smith ciss_cam_poll(struct cam_sim *sim) 32963a31b7ebSMike Smith { 329722657ce1SScott Long cr_qhead_t qh; 32983a31b7ebSMike Smith struct ciss_softc *sc = cam_sim_softc(sim); 32993a31b7ebSMike Smith 33003a31b7ebSMike Smith debug_called(2); 33013a31b7ebSMike Smith 330222657ce1SScott Long STAILQ_INIT(&qh); 330322657ce1SScott Long if (sc->ciss_perf) 330422657ce1SScott Long ciss_perf_done(sc, &qh); 330522657ce1SScott Long else 330622657ce1SScott Long ciss_done(sc, &qh); 330722657ce1SScott Long ciss_complete(sc, &qh); 33083a31b7ebSMike Smith } 33093a31b7ebSMike Smith 33103a31b7ebSMike Smith /************************************************************************ 33113a31b7ebSMike Smith * Handle completion of a command - pass results back through the CCB 33123a31b7ebSMike Smith */ 33133a31b7ebSMike Smith static void 33143a31b7ebSMike Smith ciss_cam_complete(struct ciss_request *cr) 33153a31b7ebSMike Smith { 33163a31b7ebSMike Smith struct ciss_softc *sc; 33173a31b7ebSMike Smith struct ciss_command *cc; 33183a31b7ebSMike Smith struct ciss_error_info *ce; 33193a31b7ebSMike Smith struct ccb_scsiio *csio; 33203a31b7ebSMike Smith int scsi_status; 33213a31b7ebSMike Smith int command_status; 33223a31b7ebSMike Smith 33233a31b7ebSMike Smith debug_called(2); 33243a31b7ebSMike Smith 33253a31b7ebSMike Smith sc = cr->cr_sc; 33262fdaa90dSScott Long cc = cr->cr_cc; 33273a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 33283a31b7ebSMike Smith csio = (struct ccb_scsiio *)cr->cr_private; 33293a31b7ebSMike Smith 33303a31b7ebSMike Smith /* 33313a31b7ebSMike Smith * Extract status values from request. 33323a31b7ebSMike Smith */ 33333a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 3334e8144a13SAlexander Motin switch(command_status) { 3335e8144a13SAlexander Motin case CISS_CMD_STATUS_DATA_UNDERRUN: 3336e8144a13SAlexander Motin csio->resid = ce->residual_count; 3337e8144a13SAlexander Motin /* FALLTHROUGH */ 3338e8144a13SAlexander Motin case CISS_CMD_STATUS_SUCCESS: 33393a31b7ebSMike Smith csio->scsi_status = scsi_status; 33403a31b7ebSMike Smith debug(2, "SCSI_STATUS_OK"); 33410a65b79fSAlexander Motin csio->ccb_h.status |= CAM_REQ_CMP; 33423a31b7ebSMike Smith break; 3343e8144a13SAlexander Motin case CISS_CMD_STATUS_TARGET_STATUS: 3344e8144a13SAlexander Motin csio->scsi_status = scsi_status; 33453a31b7ebSMike Smith bzero(&csio->sense_data, SSD_FULL_SIZE); 33463a31b7ebSMike Smith bcopy(&ce->sense_info[0], &csio->sense_data, ce->sense_length); 33471cc052e8SKenneth D. Merry if (csio->sense_len > ce->sense_length) 33481cc052e8SKenneth D. Merry csio->sense_resid = csio->sense_len - ce->sense_length; 33491cc052e8SKenneth D. Merry else 33501cc052e8SKenneth D. Merry csio->sense_resid = 0; 33513a31b7ebSMike Smith csio->resid = ce->residual_count; 33520a65b79fSAlexander Motin csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; 33533a31b7ebSMike Smith break; 3354e8144a13SAlexander Motin case CISS_CMD_STATUS_DATA_OVERRUN: 3355e8144a13SAlexander Motin csio->ccb_h.status |= CAM_DATA_RUN_ERR; 33563a31b7ebSMike Smith break; 33573a31b7ebSMike Smith default: 33580a65b79fSAlexander Motin csio->ccb_h.status |= CAM_REQ_CMP_ERR; 33593a31b7ebSMike Smith break; 33603a31b7ebSMike Smith } 33613a31b7ebSMike Smith 33623a31b7ebSMike Smith /* handle post-command fixup */ 33633a31b7ebSMike Smith ciss_cam_complete_fixup(sc, csio); 33643a31b7ebSMike Smith 33653a31b7ebSMike Smith ciss_release_request(cr); 336695dab4f2SAlexander Motin if (sc->ciss_flags & CISS_FLAG_BUSY) { 336795dab4f2SAlexander Motin sc->ciss_flags &= ~CISS_FLAG_BUSY; 336895dab4f2SAlexander Motin if (csio->ccb_h.status & CAM_RELEASE_SIMQ) 336995dab4f2SAlexander Motin xpt_release_simq(xpt_path_sim(csio->ccb_h.path), 0); 337095dab4f2SAlexander Motin else 337195dab4f2SAlexander Motin csio->ccb_h.status |= CAM_RELEASE_SIMQ; 337295dab4f2SAlexander Motin } 337322657ce1SScott Long xpt_done((union ccb *)csio); 33743a31b7ebSMike Smith } 33753a31b7ebSMike Smith 33763a31b7ebSMike Smith /******************************************************************************** 33773a31b7ebSMike Smith * Fix up the result of some commands here. 33783a31b7ebSMike Smith */ 33793a31b7ebSMike Smith static void 33803a31b7ebSMike Smith ciss_cam_complete_fixup(struct ciss_softc *sc, struct ccb_scsiio *csio) 33813a31b7ebSMike Smith { 33823a31b7ebSMike Smith struct scsi_inquiry_data *inq; 33833a31b7ebSMike Smith struct ciss_ldrive *cl; 338457ae362cSAlexander Motin uint8_t *cdb; 3385c6131460SPaul Saab int bus, target; 33863a31b7ebSMike Smith 338757ae362cSAlexander Motin cdb = (csio->ccb_h.flags & CAM_CDB_POINTER) ? 338857ae362cSAlexander Motin (uint8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes; 338957ae362cSAlexander Motin if (cdb[0] == INQUIRY && 339057ae362cSAlexander Motin (cdb[1] & SI_EVPD) == 0 && 339157ae362cSAlexander Motin (csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN && 339257ae362cSAlexander Motin csio->dxfer_len >= SHORT_INQUIRY_LENGTH) { 33933a31b7ebSMike Smith inq = (struct scsi_inquiry_data *)csio->data_ptr; 33943a31b7ebSMike Smith target = csio->ccb_h.target_id; 3395c6131460SPaul Saab bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); 33961fe6c4eeSScott Long 33971fe6c4eeSScott Long /* 33980fb31ed0SSean Bruno * If the controller is in JBOD mode, there are no logical volumes. 33990fb31ed0SSean Bruno * Let the disks be probed and dealt with via CAM. Else, mask off 34000fb31ed0SSean Bruno * the physical disks and setup the parts of the inq structure for 34010fb31ed0SSean Bruno * the logical volume. swb 34021fe6c4eeSScott Long */ 34030fb31ed0SSean Bruno if( !(sc->ciss_id->PowerUPNvramFlags & PWR_UP_FLAG_JBOD_ENABLED)){ 34041fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) { 34051fe6c4eeSScott Long if (SID_TYPE(inq) == T_DIRECT) 34061fe6c4eeSScott Long inq->device = (inq->device & 0xe0) | T_NODEVICE; 34071fe6c4eeSScott Long return; 34081fe6c4eeSScott Long } 3409c6131460SPaul Saab cl = &sc->ciss_logical[bus][target]; 34103a31b7ebSMike Smith 34111e8b29a4SSean Bruno padstr(inq->vendor, "HP", 3412a9112e5dSSean Bruno SID_VENDOR_SIZE); 3413a9112e5dSSean Bruno padstr(inq->product, 3414a9112e5dSSean Bruno ciss_name_ldrive_org(cl->cl_ldrive->fault_tolerance), 3415a9112e5dSSean Bruno SID_PRODUCT_SIZE); 3416a9112e5dSSean Bruno padstr(inq->revision, 3417a9112e5dSSean Bruno ciss_name_ldrive_status(cl->cl_lstatus->status), 3418a9112e5dSSean Bruno SID_REVISION_SIZE); 34193a31b7ebSMike Smith } 34203a31b7ebSMike Smith } 34210fb31ed0SSean Bruno } 34223a31b7ebSMike Smith 34233a31b7ebSMike Smith /******************************************************************************** 34243a31b7ebSMike Smith * Name the device at (target) 34253a31b7ebSMike Smith * 34263a31b7ebSMike Smith * XXX is this strictly correct? 34273a31b7ebSMike Smith */ 342837c84183SPoul-Henning Kamp static int 3429c6131460SPaul Saab ciss_name_device(struct ciss_softc *sc, int bus, int target) 34303a31b7ebSMike Smith { 34313a31b7ebSMike Smith struct cam_periph *periph; 3432739a9399SSean Bruno struct cam_path *path; 3433739a9399SSean Bruno int status; 34343a31b7ebSMike Smith 3435d49f1379SPaul Saab if (CISS_IS_PHYSICAL(bus)) 34361fe6c4eeSScott Long return (0); 3437739a9399SSean Bruno 3438739a9399SSean Bruno status = xpt_create_path(&path, NULL, cam_sim_path(sc->ciss_cam_sim[bus]), 3439739a9399SSean Bruno target, 0); 3440739a9399SSean Bruno 3441739a9399SSean Bruno if (status == CAM_REQ_CMP) { 3442739a9399SSean Bruno xpt_path_lock(path); 3443739a9399SSean Bruno periph = cam_periph_find(path, NULL); 344497ed09b5SSean Bruno xpt_path_unlock(path); 344597ed09b5SSean Bruno xpt_free_path(path); 344697ed09b5SSean Bruno if (periph != NULL) { 34471fe6c4eeSScott Long sprintf(sc->ciss_logical[bus][target].cl_name, "%s%d", 34481fe6c4eeSScott Long periph->periph_name, periph->unit_number); 34493a31b7ebSMike Smith return(0); 34503a31b7ebSMike Smith } 345197ed09b5SSean Bruno } 3452c6131460SPaul Saab sc->ciss_logical[bus][target].cl_name[0] = 0; 34533a31b7ebSMike Smith return(ENOENT); 34543a31b7ebSMike Smith } 34553a31b7ebSMike Smith 34563a31b7ebSMike Smith /************************************************************************ 34573a31b7ebSMike Smith * Periodic status monitoring. 34583a31b7ebSMike Smith */ 34593a31b7ebSMike Smith static void 34603a31b7ebSMike Smith ciss_periodic(void *arg) 34613a31b7ebSMike Smith { 34623a31b7ebSMike Smith struct ciss_softc *sc; 3463e08d902aSMitsuru IWASAKI struct ciss_request *cr = NULL; 3464e08d902aSMitsuru IWASAKI struct ciss_command *cc = NULL; 3465e08d902aSMitsuru IWASAKI int error = 0; 34663a31b7ebSMike Smith 34673a31b7ebSMike Smith debug_called(1); 34683a31b7ebSMike Smith 34693a31b7ebSMike Smith sc = (struct ciss_softc *)arg; 34703a31b7ebSMike Smith 34713a31b7ebSMike Smith /* 34723a31b7ebSMike Smith * Check the adapter heartbeat. 34733a31b7ebSMike Smith */ 34743a31b7ebSMike Smith if (sc->ciss_cfg->heartbeat == sc->ciss_heartbeat) { 34753a31b7ebSMike Smith sc->ciss_heart_attack++; 34763a31b7ebSMike Smith debug(0, "adapter heart attack in progress 0x%x/%d", 34773a31b7ebSMike Smith sc->ciss_heartbeat, sc->ciss_heart_attack); 34783a31b7ebSMike Smith if (sc->ciss_heart_attack == 3) { 34793a31b7ebSMike Smith ciss_printf(sc, "ADAPTER HEARTBEAT FAILED\n"); 3480e08d902aSMitsuru IWASAKI ciss_disable_adapter(sc); 3481e08d902aSMitsuru IWASAKI return; 34823a31b7ebSMike Smith } 34833a31b7ebSMike Smith } else { 34843a31b7ebSMike Smith sc->ciss_heartbeat = sc->ciss_cfg->heartbeat; 34853a31b7ebSMike Smith sc->ciss_heart_attack = 0; 34863a31b7ebSMike Smith debug(3, "new heartbeat 0x%x", sc->ciss_heartbeat); 34873a31b7ebSMike Smith } 34883a31b7ebSMike Smith 34893a31b7ebSMike Smith /* 3490e08d902aSMitsuru IWASAKI * Send the NOP message and wait for a response. 3491e08d902aSMitsuru IWASAKI */ 34925a3c4d69SMitsuru IWASAKI if (ciss_nop_message_heartbeat != 0 && (error = ciss_get_request(sc, &cr)) == 0) { 34932fdaa90dSScott Long cc = cr->cr_cc; 349454d02e0aSMitsuru IWASAKI cr->cr_complete = ciss_nop_complete; 3495e08d902aSMitsuru IWASAKI cc->cdb.cdb_length = 1; 3496e08d902aSMitsuru IWASAKI cc->cdb.type = CISS_CDB_TYPE_MESSAGE; 3497e08d902aSMitsuru IWASAKI cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 3498e08d902aSMitsuru IWASAKI cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; 3499e08d902aSMitsuru IWASAKI cc->cdb.timeout = 0; 3500e08d902aSMitsuru IWASAKI cc->cdb.cdb[0] = CISS_OPCODE_MESSAGE_NOP; 3501e08d902aSMitsuru IWASAKI 350254d02e0aSMitsuru IWASAKI if ((error = ciss_start(cr)) != 0) { 3503e08d902aSMitsuru IWASAKI ciss_printf(sc, "SENDING NOP MESSAGE FAILED\n"); 3504e08d902aSMitsuru IWASAKI } 3505e08d902aSMitsuru IWASAKI } 3506e08d902aSMitsuru IWASAKI 3507e08d902aSMitsuru IWASAKI /* 35083a31b7ebSMike Smith * If the notify event request has died for some reason, or has 35093a31b7ebSMike Smith * not started yet, restart it. 35103a31b7ebSMike Smith */ 35113a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) { 35123a31b7ebSMike Smith debug(0, "(re)starting Event Notify chain"); 35133a31b7ebSMike Smith ciss_notify_event(sc); 35143a31b7ebSMike Smith } 35153a31b7ebSMike Smith 35163a31b7ebSMike Smith /* 35173a31b7ebSMike Smith * Reschedule. 35183a31b7ebSMike Smith */ 3519975b7318SScott Long callout_reset(&sc->ciss_periodic, CISS_HEARTBEAT_RATE * hz, ciss_periodic, sc); 35203a31b7ebSMike Smith } 35213a31b7ebSMike Smith 352254d02e0aSMitsuru IWASAKI static void 352354d02e0aSMitsuru IWASAKI ciss_nop_complete(struct ciss_request *cr) 352454d02e0aSMitsuru IWASAKI { 352554d02e0aSMitsuru IWASAKI struct ciss_softc *sc; 35260aeee4bdSMitsuru IWASAKI static int first_time = 1; 352754d02e0aSMitsuru IWASAKI 352854d02e0aSMitsuru IWASAKI sc = cr->cr_sc; 352954d02e0aSMitsuru IWASAKI if (ciss_report_request(cr, NULL, NULL) != 0) { 35300aeee4bdSMitsuru IWASAKI if (first_time == 1) { 35310aeee4bdSMitsuru IWASAKI first_time = 0; 35320aeee4bdSMitsuru IWASAKI ciss_printf(sc, "SENDING NOP MESSAGE FAILED (not logging anymore)\n"); 35330aeee4bdSMitsuru IWASAKI } 353454d02e0aSMitsuru IWASAKI } 353554d02e0aSMitsuru IWASAKI 353654d02e0aSMitsuru IWASAKI ciss_release_request(cr); 353754d02e0aSMitsuru IWASAKI } 353854d02e0aSMitsuru IWASAKI 35393a31b7ebSMike Smith /************************************************************************ 3540e08d902aSMitsuru IWASAKI * Disable the adapter. 3541e08d902aSMitsuru IWASAKI * 3542e08d902aSMitsuru IWASAKI * The all requests in completed queue is failed with hardware error. 3543e08d902aSMitsuru IWASAKI * This will cause failover in a multipath configuration. 3544e08d902aSMitsuru IWASAKI */ 3545e08d902aSMitsuru IWASAKI static void 3546e08d902aSMitsuru IWASAKI ciss_disable_adapter(struct ciss_softc *sc) 3547e08d902aSMitsuru IWASAKI { 354822657ce1SScott Long cr_qhead_t qh; 3549e08d902aSMitsuru IWASAKI struct ciss_request *cr; 3550e08d902aSMitsuru IWASAKI struct ciss_command *cc; 3551e08d902aSMitsuru IWASAKI struct ciss_error_info *ce; 355222657ce1SScott Long int i; 3553e08d902aSMitsuru IWASAKI 3554e08d902aSMitsuru IWASAKI CISS_TL_SIMPLE_DISABLE_INTERRUPTS(sc); 3555e08d902aSMitsuru IWASAKI pci_disable_busmaster(sc->ciss_dev); 3556e08d902aSMitsuru IWASAKI sc->ciss_flags &= ~CISS_FLAG_RUNNING; 3557e08d902aSMitsuru IWASAKI 3558d26ae2c1SAlexander Motin STAILQ_INIT(&qh); 355922657ce1SScott Long for (i = 1; i < sc->ciss_max_requests; i++) { 356022657ce1SScott Long cr = &sc->ciss_request[i]; 356122657ce1SScott Long if ((cr->cr_flags & CISS_REQ_BUSY) == 0) 356222657ce1SScott Long continue; 3563e08d902aSMitsuru IWASAKI 35642fdaa90dSScott Long cc = cr->cr_cc; 3565e08d902aSMitsuru IWASAKI ce = (struct ciss_error_info *)&(cc->sg[0]); 3566e08d902aSMitsuru IWASAKI ce->command_status = CISS_CMD_STATUS_HARDWARE_ERROR; 356722657ce1SScott Long ciss_enqueue_complete(cr, &qh); 3568e08d902aSMitsuru IWASAKI } 3569e08d902aSMitsuru IWASAKI 3570e08d902aSMitsuru IWASAKI for (;;) { 357122657ce1SScott Long if ((cr = ciss_dequeue_complete(sc, &qh)) == NULL) 3572e08d902aSMitsuru IWASAKI break; 3573e08d902aSMitsuru IWASAKI 3574e08d902aSMitsuru IWASAKI /* 3575e08d902aSMitsuru IWASAKI * If the request has a callback, invoke it. 3576e08d902aSMitsuru IWASAKI */ 3577e08d902aSMitsuru IWASAKI if (cr->cr_complete != NULL) { 3578e08d902aSMitsuru IWASAKI cr->cr_complete(cr); 3579e08d902aSMitsuru IWASAKI continue; 3580e08d902aSMitsuru IWASAKI } 3581e08d902aSMitsuru IWASAKI 3582e08d902aSMitsuru IWASAKI /* 3583e08d902aSMitsuru IWASAKI * If someone is sleeping on this request, wake them up. 3584e08d902aSMitsuru IWASAKI */ 3585e08d902aSMitsuru IWASAKI if (cr->cr_flags & CISS_REQ_SLEEP) { 3586e08d902aSMitsuru IWASAKI cr->cr_flags &= ~CISS_REQ_SLEEP; 3587e08d902aSMitsuru IWASAKI wakeup(cr); 3588e08d902aSMitsuru IWASAKI continue; 3589e08d902aSMitsuru IWASAKI } 3590e08d902aSMitsuru IWASAKI } 3591e08d902aSMitsuru IWASAKI } 3592e08d902aSMitsuru IWASAKI 3593e08d902aSMitsuru IWASAKI /************************************************************************ 35943a31b7ebSMike Smith * Request a notification response from the adapter. 35953a31b7ebSMike Smith * 35963a31b7ebSMike Smith * If (cr) is NULL, this is the first request of the adapter, so 35973a31b7ebSMike Smith * reset the adapter's message pointer and start with the oldest 35983a31b7ebSMike Smith * message available. 35993a31b7ebSMike Smith */ 36003a31b7ebSMike Smith static void 36013a31b7ebSMike Smith ciss_notify_event(struct ciss_softc *sc) 36023a31b7ebSMike Smith { 36033a31b7ebSMike Smith struct ciss_request *cr; 36043a31b7ebSMike Smith struct ciss_command *cc; 36053a31b7ebSMike Smith struct ciss_notify_cdb *cnc; 36063a31b7ebSMike Smith int error; 36073a31b7ebSMike Smith 36083a31b7ebSMike Smith debug_called(1); 36093a31b7ebSMike Smith 36103a31b7ebSMike Smith cr = sc->ciss_periodic_notify; 36113a31b7ebSMike Smith 36123a31b7ebSMike Smith /* get a request if we don't already have one */ 36133a31b7ebSMike Smith if (cr == NULL) { 36143a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) { 36153a31b7ebSMike Smith debug(0, "can't get notify event request"); 36163a31b7ebSMike Smith goto out; 36173a31b7ebSMike Smith } 36183a31b7ebSMike Smith sc->ciss_periodic_notify = cr; 36193a31b7ebSMike Smith cr->cr_complete = ciss_notify_complete; 36203a31b7ebSMike Smith debug(1, "acquired request %d", cr->cr_tag); 36213a31b7ebSMike Smith } 36223a31b7ebSMike Smith 36233a31b7ebSMike Smith /* 36243a31b7ebSMike Smith * Get a databuffer if we don't already have one, note that the 36253a31b7ebSMike Smith * adapter command wants a larger buffer than the actual 36263a31b7ebSMike Smith * structure. 36273a31b7ebSMike Smith */ 36283a31b7ebSMike Smith if (cr->cr_data == NULL) { 36293a31b7ebSMike Smith if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 36303a31b7ebSMike Smith debug(0, "can't get notify event request buffer"); 36313a31b7ebSMike Smith error = ENOMEM; 36323a31b7ebSMike Smith goto out; 36333a31b7ebSMike Smith } 36343a31b7ebSMike Smith cr->cr_length = CISS_NOTIFY_DATA_SIZE; 36353a31b7ebSMike Smith } 36363a31b7ebSMike Smith 36373a31b7ebSMike Smith /* re-setup the request's command (since we never release it) XXX overkill*/ 36383a31b7ebSMike Smith ciss_preen_command(cr); 36393a31b7ebSMike Smith 36403a31b7ebSMike Smith /* (re)build the notify event command */ 36412fdaa90dSScott Long cc = cr->cr_cc; 36423a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 36433a31b7ebSMike Smith cc->header.address.physical.bus = 0; 36443a31b7ebSMike Smith cc->header.address.physical.target = 0; 36453a31b7ebSMike Smith 36463a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cnc); 36473a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 36483a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 36493a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 36503a31b7ebSMike Smith cc->cdb.timeout = 0; /* no timeout, we hope */ 36513a31b7ebSMike Smith 36523a31b7ebSMike Smith cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); 36533a31b7ebSMike Smith bzero(cr->cr_data, CISS_NOTIFY_DATA_SIZE); 36543a31b7ebSMike Smith cnc->opcode = CISS_OPCODE_READ; 36553a31b7ebSMike Smith cnc->command = CISS_COMMAND_NOTIFY_ON_EVENT; 36563a31b7ebSMike Smith cnc->timeout = 0; /* no timeout, we hope */ 36573a31b7ebSMike Smith cnc->synchronous = 0; 36583a31b7ebSMike Smith cnc->ordered = 0; 36593a31b7ebSMike Smith cnc->seek_to_oldest = 0; 36602e80ca8aSPaul Saab if ((sc->ciss_flags & CISS_FLAG_RUNNING) == 0) 36612e80ca8aSPaul Saab cnc->new_only = 1; 36622e80ca8aSPaul Saab else 36633a31b7ebSMike Smith cnc->new_only = 0; 36643a31b7ebSMike Smith cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); 36653a31b7ebSMike Smith 36663a31b7ebSMike Smith /* submit the request */ 36673a31b7ebSMike Smith error = ciss_start(cr); 36683a31b7ebSMike Smith 36693a31b7ebSMike Smith out: 36703a31b7ebSMike Smith if (error) { 36713a31b7ebSMike Smith if (cr != NULL) { 36723a31b7ebSMike Smith if (cr->cr_data != NULL) 36733a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 36743a31b7ebSMike Smith ciss_release_request(cr); 36753a31b7ebSMike Smith } 36763a31b7ebSMike Smith sc->ciss_periodic_notify = NULL; 36773a31b7ebSMike Smith debug(0, "can't submit notify event request"); 36783a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 36793a31b7ebSMike Smith } else { 36803a31b7ebSMike Smith debug(1, "notify event submitted"); 36813a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_NOTIFY_OK; 36823a31b7ebSMike Smith } 36833a31b7ebSMike Smith } 36843a31b7ebSMike Smith 36853a31b7ebSMike Smith static void 36863a31b7ebSMike Smith ciss_notify_complete(struct ciss_request *cr) 36873a31b7ebSMike Smith { 36883a31b7ebSMike Smith struct ciss_notify *cn; 36893a31b7ebSMike Smith struct ciss_softc *sc; 36903a31b7ebSMike Smith int scsi_status; 36913a31b7ebSMike Smith int command_status; 36923a31b7ebSMike Smith debug_called(1); 36933a31b7ebSMike Smith 36943a31b7ebSMike Smith cn = (struct ciss_notify *)cr->cr_data; 36953a31b7ebSMike Smith sc = cr->cr_sc; 36963a31b7ebSMike Smith 36973a31b7ebSMike Smith /* 36983a31b7ebSMike Smith * Report request results, decode status. 36993a31b7ebSMike Smith */ 37003a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 37013a31b7ebSMike Smith 37023a31b7ebSMike Smith /* 37033a31b7ebSMike Smith * Abort the chain on a fatal error. 37043a31b7ebSMike Smith * 37053a31b7ebSMike Smith * XXX which of these are actually errors? 37063a31b7ebSMike Smith */ 37073a31b7ebSMike Smith if ((command_status != CISS_CMD_STATUS_SUCCESS) && 37083a31b7ebSMike Smith (command_status != CISS_CMD_STATUS_TARGET_STATUS) && 37093a31b7ebSMike Smith (command_status != CISS_CMD_STATUS_TIMEOUT)) { /* XXX timeout? */ 37103a31b7ebSMike Smith ciss_printf(sc, "fatal error in Notify Event request (%s)\n", 37113a31b7ebSMike Smith ciss_name_command_status(command_status)); 37123a31b7ebSMike Smith ciss_release_request(cr); 37133a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 37143a31b7ebSMike Smith return; 37153a31b7ebSMike Smith } 37163a31b7ebSMike Smith 37173a31b7ebSMike Smith /* 37183a31b7ebSMike Smith * If the adapter gave us a text message, print it. 37193a31b7ebSMike Smith */ 37203a31b7ebSMike Smith if (cn->message[0] != 0) 37213a31b7ebSMike Smith ciss_printf(sc, "*** %.80s\n", cn->message); 37223a31b7ebSMike Smith 37233a31b7ebSMike Smith debug(0, "notify event class %d subclass %d detail %d", 37243a31b7ebSMike Smith cn->class, cn->subclass, cn->detail); 37253a31b7ebSMike Smith 37263a31b7ebSMike Smith /* 37273a31b7ebSMike Smith * If the response indicates that the notifier has been aborted, 37283a31b7ebSMike Smith * release the notifier command. 37293a31b7ebSMike Smith */ 37303a31b7ebSMike Smith if ((cn->class == CISS_NOTIFY_NOTIFIER) && 37313a31b7ebSMike Smith (cn->subclass == CISS_NOTIFY_NOTIFIER_STATUS) && 37323a31b7ebSMike Smith (cn->detail == 1)) { 37333a31b7ebSMike Smith debug(0, "notifier exiting"); 37343a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 37353a31b7ebSMike Smith ciss_release_request(cr); 37363a31b7ebSMike Smith sc->ciss_periodic_notify = NULL; 37373a31b7ebSMike Smith wakeup(&sc->ciss_periodic_notify); 3738c6131460SPaul Saab } else { 3739c6131460SPaul Saab /* Handle notify events in a kernel thread */ 3740c6131460SPaul Saab ciss_enqueue_notify(cr); 3741c6131460SPaul Saab sc->ciss_periodic_notify = NULL; 3742c6131460SPaul Saab wakeup(&sc->ciss_periodic_notify); 3743c6131460SPaul Saab wakeup(&sc->ciss_notify); 37443a31b7ebSMike Smith } 37453a31b7ebSMike Smith /* 37463a31b7ebSMike Smith * Send a new notify event command, if we're not aborting. 37473a31b7ebSMike Smith */ 37483a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_ABORTING)) { 37493a31b7ebSMike Smith ciss_notify_event(sc); 37503a31b7ebSMike Smith } 37513a31b7ebSMike Smith } 37523a31b7ebSMike Smith 37533a31b7ebSMike Smith /************************************************************************ 37543a31b7ebSMike Smith * Abort the Notify Event chain. 37553a31b7ebSMike Smith * 37563a31b7ebSMike Smith * Note that we can't just abort the command in progress; we have to 37573a31b7ebSMike Smith * explicitly issue an Abort Notify Event command in order for the 37583a31b7ebSMike Smith * adapter to clean up correctly. 37593a31b7ebSMike Smith * 37603a31b7ebSMike Smith * If we are called with CISS_FLAG_ABORTING set in the adapter softc, 37613a31b7ebSMike Smith * the chain will not restart itself. 37623a31b7ebSMike Smith */ 37633a31b7ebSMike Smith static int 37643a31b7ebSMike Smith ciss_notify_abort(struct ciss_softc *sc) 37653a31b7ebSMike Smith { 37663a31b7ebSMike Smith struct ciss_request *cr; 37673a31b7ebSMike Smith struct ciss_command *cc; 37683a31b7ebSMike Smith struct ciss_notify_cdb *cnc; 376922657ce1SScott Long int error, command_status, scsi_status; 37703a31b7ebSMike Smith 37713a31b7ebSMike Smith debug_called(1); 37723a31b7ebSMike Smith 37733a31b7ebSMike Smith cr = NULL; 37743a31b7ebSMike Smith error = 0; 37753a31b7ebSMike Smith 37763a31b7ebSMike Smith /* verify that there's an outstanding command */ 37773a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) 37783a31b7ebSMike Smith goto out; 37793a31b7ebSMike Smith 37803a31b7ebSMike Smith /* get a command to issue the abort with */ 37813a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr))) 37823a31b7ebSMike Smith goto out; 37833a31b7ebSMike Smith 37843a31b7ebSMike Smith /* get a buffer for the result */ 37853a31b7ebSMike Smith if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 37863a31b7ebSMike Smith debug(0, "can't get notify event request buffer"); 37873a31b7ebSMike Smith error = ENOMEM; 37883a31b7ebSMike Smith goto out; 37893a31b7ebSMike Smith } 37903a31b7ebSMike Smith cr->cr_length = CISS_NOTIFY_DATA_SIZE; 37913a31b7ebSMike Smith 37923a31b7ebSMike Smith /* build the CDB */ 37932fdaa90dSScott Long cc = cr->cr_cc; 37943a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 37953a31b7ebSMike Smith cc->header.address.physical.bus = 0; 37963a31b7ebSMike Smith cc->header.address.physical.target = 0; 37973a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cnc); 37983a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 37993a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 38003a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 38013a31b7ebSMike Smith cc->cdb.timeout = 0; /* no timeout, we hope */ 38023a31b7ebSMike Smith 38033a31b7ebSMike Smith cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); 38043a31b7ebSMike Smith bzero(cnc, sizeof(*cnc)); 38053a31b7ebSMike Smith cnc->opcode = CISS_OPCODE_WRITE; 38063a31b7ebSMike Smith cnc->command = CISS_COMMAND_ABORT_NOTIFY; 38073a31b7ebSMike Smith cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); 38082e3d6d0fSWarner Losh #if 0 38093a31b7ebSMike Smith ciss_print_request(cr); 38102e3d6d0fSWarner Losh #endif 38113a31b7ebSMike Smith 38123a31b7ebSMike Smith /* 38133a31b7ebSMike Smith * Submit the request and wait for it to complete. 38143a31b7ebSMike Smith */ 38153a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 38163a31b7ebSMike Smith ciss_printf(sc, "Abort Notify Event command failed (%d)\n", error); 38173a31b7ebSMike Smith goto out; 38183a31b7ebSMike Smith } 38193a31b7ebSMike Smith 38203a31b7ebSMike Smith /* 38213a31b7ebSMike Smith * Check response. 38223a31b7ebSMike Smith */ 38233a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 38243a31b7ebSMike Smith switch(command_status) { 38253a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 38263a31b7ebSMike Smith break; 38273a31b7ebSMike Smith case CISS_CMD_STATUS_INVALID_COMMAND: 38283a31b7ebSMike Smith /* 38293a31b7ebSMike Smith * Some older adapters don't support the CISS version of this 38303a31b7ebSMike Smith * command. Fall back to using the BMIC version. 38313a31b7ebSMike Smith */ 38323a31b7ebSMike Smith error = ciss_notify_abort_bmic(sc); 38333a31b7ebSMike Smith if (error != 0) 38343a31b7ebSMike Smith goto out; 38353a31b7ebSMike Smith break; 38363a31b7ebSMike Smith 38373a31b7ebSMike Smith case CISS_CMD_STATUS_TARGET_STATUS: 38383a31b7ebSMike Smith /* 38393a31b7ebSMike Smith * This can happen if the adapter thinks there wasn't an outstanding 38403a31b7ebSMike Smith * Notify Event command but we did. We clean up here. 38413a31b7ebSMike Smith */ 38423a31b7ebSMike Smith if (scsi_status == CISS_SCSI_STATUS_CHECK_CONDITION) { 38433a31b7ebSMike Smith if (sc->ciss_periodic_notify != NULL) 38443a31b7ebSMike Smith ciss_release_request(sc->ciss_periodic_notify); 38453a31b7ebSMike Smith error = 0; 38463a31b7ebSMike Smith goto out; 38473a31b7ebSMike Smith } 38483a31b7ebSMike Smith /* FALLTHROUGH */ 38493a31b7ebSMike Smith 38503a31b7ebSMike Smith default: 38513a31b7ebSMike Smith ciss_printf(sc, "Abort Notify Event command failed (%s)\n", 38523a31b7ebSMike Smith ciss_name_command_status(command_status)); 38533a31b7ebSMike Smith error = EIO; 38543a31b7ebSMike Smith goto out; 38553a31b7ebSMike Smith } 38563a31b7ebSMike Smith 38573a31b7ebSMike Smith /* 38583a31b7ebSMike Smith * Sleep waiting for the notifier command to complete. Note 38593a31b7ebSMike Smith * that if it doesn't, we may end up in a bad situation, since 38603a31b7ebSMike Smith * the adapter may deliver it later. Also note that the adapter 38613a31b7ebSMike Smith * requires the Notify Event command to be cancelled in order to 38623a31b7ebSMike Smith * maintain internal bookkeeping. 38633a31b7ebSMike Smith */ 38643a31b7ebSMike Smith while (sc->ciss_periodic_notify != NULL) { 3865975b7318SScott Long error = msleep(&sc->ciss_periodic_notify, &sc->ciss_mtx, PRIBIO, "cissNEA", hz * 5); 38663a31b7ebSMike Smith if (error == EWOULDBLOCK) { 38673a31b7ebSMike Smith ciss_printf(sc, "Notify Event command failed to abort, adapter may wedge.\n"); 38683a31b7ebSMike Smith break; 38693a31b7ebSMike Smith } 38703a31b7ebSMike Smith } 38713a31b7ebSMike Smith 38723a31b7ebSMike Smith out: 38733a31b7ebSMike Smith /* release the cancel request */ 38743a31b7ebSMike Smith if (cr != NULL) { 38753a31b7ebSMike Smith if (cr->cr_data != NULL) 38763a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 38773a31b7ebSMike Smith ciss_release_request(cr); 38783a31b7ebSMike Smith } 38793a31b7ebSMike Smith if (error == 0) 38803a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 38813a31b7ebSMike Smith return(error); 38823a31b7ebSMike Smith } 38833a31b7ebSMike Smith 38843a31b7ebSMike Smith /************************************************************************ 38853a31b7ebSMike Smith * Abort the Notify Event chain using a BMIC command. 38863a31b7ebSMike Smith */ 38873a31b7ebSMike Smith static int 38883a31b7ebSMike Smith ciss_notify_abort_bmic(struct ciss_softc *sc) 38893a31b7ebSMike Smith { 38903a31b7ebSMike Smith struct ciss_request *cr; 38913a31b7ebSMike Smith int error, command_status; 38923a31b7ebSMike Smith 38933a31b7ebSMike Smith debug_called(1); 38943a31b7ebSMike Smith 38953a31b7ebSMike Smith cr = NULL; 38963a31b7ebSMike Smith error = 0; 38973a31b7ebSMike Smith 38983a31b7ebSMike Smith /* verify that there's an outstanding command */ 38993a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) 39003a31b7ebSMike Smith goto out; 39013a31b7ebSMike Smith 39023a31b7ebSMike Smith /* 39033a31b7ebSMike Smith * Build a BMIC command to cancel the Notify on Event command. 39043a31b7ebSMike Smith * 39053a31b7ebSMike Smith * Note that we are sending a CISS opcode here. Odd. 39063a31b7ebSMike Smith */ 39073a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_COMMAND_ABORT_NOTIFY, 39083a31b7ebSMike Smith NULL, 0)) != 0) 39093a31b7ebSMike Smith goto out; 39103a31b7ebSMike Smith 39113a31b7ebSMike Smith /* 39123a31b7ebSMike Smith * Submit the request and wait for it to complete. 39133a31b7ebSMike Smith */ 39143a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 39153a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC Cancel Notify on Event command (%d)\n", error); 39163a31b7ebSMike Smith goto out; 39173a31b7ebSMike Smith } 39183a31b7ebSMike Smith 39193a31b7ebSMike Smith /* 39203a31b7ebSMike Smith * Check response. 39213a31b7ebSMike Smith */ 39223a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 39233a31b7ebSMike Smith switch(command_status) { 39243a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 39253a31b7ebSMike Smith break; 39263a31b7ebSMike Smith default: 39273a31b7ebSMike Smith ciss_printf(sc, "error cancelling Notify on Event (%s)\n", 39283a31b7ebSMike Smith ciss_name_command_status(command_status)); 39293a31b7ebSMike Smith error = EIO; 39303a31b7ebSMike Smith goto out; 39313a31b7ebSMike Smith } 39323a31b7ebSMike Smith 39333a31b7ebSMike Smith out: 39343a31b7ebSMike Smith if (cr != NULL) 39353a31b7ebSMike Smith ciss_release_request(cr); 39363a31b7ebSMike Smith return(error); 39373a31b7ebSMike Smith } 39383a31b7ebSMike Smith 39393a31b7ebSMike Smith /************************************************************************ 3940c6131460SPaul Saab * Handle rescanning all the logical volumes when a notify event 3941c6131460SPaul Saab * causes the drives to come online or offline. 3942c6131460SPaul Saab */ 3943c6131460SPaul Saab static void 3944c6131460SPaul Saab ciss_notify_rescan_logical(struct ciss_softc *sc) 3945c6131460SPaul Saab { 3946c6131460SPaul Saab struct ciss_lun_report *cll; 3947c6131460SPaul Saab struct ciss_ldrive *ld; 3948c6131460SPaul Saab int i, j, ndrives; 3949c6131460SPaul Saab 3950c6131460SPaul Saab /* 3951c6131460SPaul Saab * We must rescan all logical volumes to get the right logical 3952c6131460SPaul Saab * drive address. 3953c6131460SPaul Saab */ 3954c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_LOGICAL_LUNS, 3955e3edca22SSean Bruno sc->ciss_cfg->max_logical_supported); 3956c6131460SPaul Saab if (cll == NULL) 3957c6131460SPaul Saab return; 3958c6131460SPaul Saab 3959c6131460SPaul Saab ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 3960c6131460SPaul Saab 3961c6131460SPaul Saab /* 3962c6131460SPaul Saab * Delete any of the drives which were destroyed by the 3963c6131460SPaul Saab * firmware. 3964c6131460SPaul Saab */ 39651fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 3966e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { 3967c6131460SPaul Saab ld = &sc->ciss_logical[i][j]; 3968c6131460SPaul Saab 3969c6131460SPaul Saab if (ld->cl_update == 0) 3970c6131460SPaul Saab continue; 3971c6131460SPaul Saab 3972c6131460SPaul Saab if (ld->cl_status != CISS_LD_ONLINE) { 3973c6131460SPaul Saab ciss_cam_rescan_target(sc, i, j); 3974c6131460SPaul Saab ld->cl_update = 0; 3975c6131460SPaul Saab if (ld->cl_ldrive) 3976c6131460SPaul Saab free(ld->cl_ldrive, CISS_MALLOC_CLASS); 3977c6131460SPaul Saab if (ld->cl_lstatus) 3978c6131460SPaul Saab free(ld->cl_lstatus, CISS_MALLOC_CLASS); 3979c6131460SPaul Saab 3980c6131460SPaul Saab ld->cl_ldrive = NULL; 3981c6131460SPaul Saab ld->cl_lstatus = NULL; 3982c6131460SPaul Saab } 3983c6131460SPaul Saab } 3984c6131460SPaul Saab } 3985c6131460SPaul Saab 3986c6131460SPaul Saab /* 3987c6131460SPaul Saab * Scan for new drives. 3988c6131460SPaul Saab */ 3989c6131460SPaul Saab for (i = 0; i < ndrives; i++) { 3990c6131460SPaul Saab int bus, target; 3991c6131460SPaul Saab 3992c6131460SPaul Saab bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); 3993c6131460SPaul Saab target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); 3994c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 3995c6131460SPaul Saab 3996c6131460SPaul Saab if (ld->cl_update == 0) 3997c6131460SPaul Saab continue; 3998c6131460SPaul Saab 39995cf5a430SPaul Saab ld->cl_update = 0; 4000c6131460SPaul Saab ld->cl_address = cll->lun[i]; 4001c6131460SPaul Saab ld->cl_controller = &sc->ciss_controllers[bus]; 4002c6131460SPaul Saab if (ciss_identify_logical(sc, ld) == 0) { 4003c6131460SPaul Saab ciss_cam_rescan_target(sc, bus, target); 4004c6131460SPaul Saab } 4005c6131460SPaul Saab } 4006c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 4007c6131460SPaul Saab } 4008c6131460SPaul Saab 4009c6131460SPaul Saab /************************************************************************ 40103a31b7ebSMike Smith * Handle a notify event relating to the status of a logical drive. 40113a31b7ebSMike Smith * 40123a31b7ebSMike Smith * XXX need to be able to defer some of these to properly handle 40133a31b7ebSMike Smith * calling the "ID Physical drive" command, unless the 'extended' 40143a31b7ebSMike Smith * drive IDs are always in BIG_MAP format. 40153a31b7ebSMike Smith */ 40163a31b7ebSMike Smith static void 40173a31b7ebSMike Smith ciss_notify_logical(struct ciss_softc *sc, struct ciss_notify *cn) 40183a31b7ebSMike Smith { 40193a31b7ebSMike Smith struct ciss_ldrive *ld; 4020e6aa1412SSean Bruno int ostatus, bus, target; 40213a31b7ebSMike Smith 40223a31b7ebSMike Smith debug_called(2); 40233a31b7ebSMike Smith 4024c6131460SPaul Saab bus = cn->device.physical.bus; 4025c6131460SPaul Saab target = cn->data.logical_status.logical_drive; 4026c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 40273a31b7ebSMike Smith 40283a31b7ebSMike Smith switch (cn->subclass) { 40293a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_STATUS: 40303a31b7ebSMike Smith switch (cn->detail) { 40313a31b7ebSMike Smith case 0: 4032c6131460SPaul Saab ciss_name_device(sc, bus, target); 40333a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) changed status %s->%s, spare status 0x%b\n", 40343a31b7ebSMike Smith cn->data.logical_status.logical_drive, ld->cl_name, 40353a31b7ebSMike Smith ciss_name_ldrive_status(cn->data.logical_status.previous_state), 40363a31b7ebSMike Smith ciss_name_ldrive_status(cn->data.logical_status.new_state), 40373a31b7ebSMike Smith cn->data.logical_status.spare_state, 40383a31b7ebSMike Smith "\20\1configured\2rebuilding\3failed\4in use\5available\n"); 40393a31b7ebSMike Smith 40403a31b7ebSMike Smith /* 40413a31b7ebSMike Smith * Update our idea of the drive's status. 40423a31b7ebSMike Smith */ 4043e6aa1412SSean Bruno ostatus = ciss_decode_ldrive_status(cn->data.logical_status.previous_state); 40443a31b7ebSMike Smith ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); 4045d4aa427fSPaul Saab if (ld->cl_lstatus != NULL) 40463a31b7ebSMike Smith ld->cl_lstatus->status = cn->data.logical_status.new_state; 40473a31b7ebSMike Smith 4048d4aa427fSPaul Saab /* 4049d4aa427fSPaul Saab * Have CAM rescan the drive if its status has changed. 4050d4aa427fSPaul Saab */ 4051e6aa1412SSean Bruno if (ostatus != ld->cl_status) { 4052c6131460SPaul Saab ld->cl_update = 1; 4053c6131460SPaul Saab ciss_notify_rescan_logical(sc); 4054c6131460SPaul Saab } 4055d4aa427fSPaul Saab 40563a31b7ebSMike Smith break; 40573a31b7ebSMike Smith 40583a31b7ebSMike Smith case 1: /* logical drive has recognised new media, needs Accept Media Exchange */ 4059c6131460SPaul Saab ciss_name_device(sc, bus, target); 40603a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) media exchanged, ready to go online\n", 40613a31b7ebSMike Smith cn->data.logical_status.logical_drive, ld->cl_name); 406288c78a38SPaul Saab ciss_accept_media(sc, ld); 4063139233cbSPaul Saab 4064139233cbSPaul Saab ld->cl_update = 1; 4065139233cbSPaul Saab ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); 4066139233cbSPaul Saab ciss_notify_rescan_logical(sc); 40673a31b7ebSMike Smith break; 40683a31b7ebSMike Smith 40693a31b7ebSMike Smith case 2: 40703a31b7ebSMike Smith case 3: 40713a31b7ebSMike Smith ciss_printf(sc, "rebuild of logical drive %d (%s) failed due to %s error\n", 40723a31b7ebSMike Smith cn->data.rebuild_aborted.logical_drive, 4073c6131460SPaul Saab ld->cl_name, 40743a31b7ebSMike Smith (cn->detail == 2) ? "read" : "write"); 40753a31b7ebSMike Smith break; 40763a31b7ebSMike Smith } 40773a31b7ebSMike Smith break; 40783a31b7ebSMike Smith 40793a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_ERROR: 40803a31b7ebSMike Smith if (cn->detail == 0) { 40813a31b7ebSMike Smith ciss_printf(sc, "FATAL I/O ERROR on logical drive %d (%s), SCSI port %d ID %d\n", 40823a31b7ebSMike Smith cn->data.io_error.logical_drive, 4083c6131460SPaul Saab ld->cl_name, 40843a31b7ebSMike Smith cn->data.io_error.failure_bus, 40853a31b7ebSMike Smith cn->data.io_error.failure_drive); 40863a31b7ebSMike Smith /* XXX should we take the drive down at this point, or will we be told? */ 40873a31b7ebSMike Smith } 40883a31b7ebSMike Smith break; 40893a31b7ebSMike Smith 40903a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_SURFACE: 40913a31b7ebSMike Smith if (cn->detail == 0) 40923a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) completed consistency initialisation\n", 40933a31b7ebSMike Smith cn->data.consistency_completed.logical_drive, 4094c6131460SPaul Saab ld->cl_name); 40953a31b7ebSMike Smith break; 40963a31b7ebSMike Smith } 40973a31b7ebSMike Smith } 40983a31b7ebSMike Smith 40993a31b7ebSMike Smith /************************************************************************ 41003a31b7ebSMike Smith * Handle a notify event relating to the status of a physical drive. 41013a31b7ebSMike Smith */ 41023a31b7ebSMike Smith static void 41033a31b7ebSMike Smith ciss_notify_physical(struct ciss_softc *sc, struct ciss_notify *cn) 41043a31b7ebSMike Smith { 4105c6131460SPaul Saab } 41063a31b7ebSMike Smith 4107c6131460SPaul Saab /************************************************************************ 41081fe6c4eeSScott Long * Handle a notify event relating to the status of a physical drive. 41091fe6c4eeSScott Long */ 41101fe6c4eeSScott Long static void 41111fe6c4eeSScott Long ciss_notify_hotplug(struct ciss_softc *sc, struct ciss_notify *cn) 41121fe6c4eeSScott Long { 4113c1885ab8SPaul Saab struct ciss_lun_report *cll = NULL; 41141fe6c4eeSScott Long int bus, target; 41151fe6c4eeSScott Long 41161fe6c4eeSScott Long switch (cn->subclass) { 41171fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG_PHYSICAL: 41181fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG_NONDISK: 41191fe6c4eeSScott Long bus = CISS_BIG_MAP_BUS(sc, cn->data.drive.big_physical_drive_number); 41201fe6c4eeSScott Long target = 41211fe6c4eeSScott Long CISS_BIG_MAP_TARGET(sc, cn->data.drive.big_physical_drive_number); 41221fe6c4eeSScott Long 41231fe6c4eeSScott Long if (cn->detail == 0) { 41241fe6c4eeSScott Long /* 41251fe6c4eeSScott Long * Mark the device offline so that it'll start producing selection 41261fe6c4eeSScott Long * timeouts to the upper layer. 41271fe6c4eeSScott Long */ 41285f265711SScott Long if ((bus >= 0) && (target >= 0)) 41291fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_online = 0; 41301fe6c4eeSScott Long } else { 41311fe6c4eeSScott Long /* 41321fe6c4eeSScott Long * Rescan the physical lun list for new items 41331fe6c4eeSScott Long */ 41341fe6c4eeSScott Long cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_PHYSICAL_LUNS, 4135e3edca22SSean Bruno sc->ciss_cfg->max_physical_supported); 41361fe6c4eeSScott Long if (cll == NULL) { 41371fe6c4eeSScott Long ciss_printf(sc, "Warning, cannot get physical lun list\n"); 41381fe6c4eeSScott Long break; 41391fe6c4eeSScott Long } 41401fe6c4eeSScott Long ciss_filter_physical(sc, cll); 41411fe6c4eeSScott Long } 41421fe6c4eeSScott Long break; 41431fe6c4eeSScott Long 41441fe6c4eeSScott Long default: 41451fe6c4eeSScott Long ciss_printf(sc, "Unknown hotplug event %d\n", cn->subclass); 41461fe6c4eeSScott Long return; 41471fe6c4eeSScott Long } 4148c1885ab8SPaul Saab 4149c1885ab8SPaul Saab if (cll != NULL) 4150c1885ab8SPaul Saab free(cll, CISS_MALLOC_CLASS); 41511fe6c4eeSScott Long } 41521fe6c4eeSScott Long 41531fe6c4eeSScott Long /************************************************************************ 4154c6131460SPaul Saab * Handle deferred processing of notify events. Notify events may need 4155c6131460SPaul Saab * sleep which is unsafe during an interrupt. 4156c6131460SPaul Saab */ 4157c6131460SPaul Saab static void 4158c6131460SPaul Saab ciss_notify_thread(void *arg) 4159c6131460SPaul Saab { 4160c6131460SPaul Saab struct ciss_softc *sc; 4161c6131460SPaul Saab struct ciss_request *cr; 4162c6131460SPaul Saab struct ciss_notify *cn; 4163c6131460SPaul Saab 4164c6131460SPaul Saab sc = (struct ciss_softc *)arg; 4165975b7318SScott Long mtx_lock(&sc->ciss_mtx); 4166c6131460SPaul Saab 4167c6131460SPaul Saab for (;;) { 416822657ce1SScott Long if (STAILQ_EMPTY(&sc->ciss_notify) != 0 && 4169c6131460SPaul Saab (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) == 0) { 4170975b7318SScott Long msleep(&sc->ciss_notify, &sc->ciss_mtx, PUSER, "idle", 0); 4171c6131460SPaul Saab } 4172c6131460SPaul Saab 4173c6131460SPaul Saab if (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) 4174c6131460SPaul Saab break; 4175c6131460SPaul Saab 4176c6131460SPaul Saab cr = ciss_dequeue_notify(sc); 4177c6131460SPaul Saab 4178c6131460SPaul Saab if (cr == NULL) 4179c6131460SPaul Saab panic("cr null"); 4180c6131460SPaul Saab cn = (struct ciss_notify *)cr->cr_data; 4181c6131460SPaul Saab 4182c6131460SPaul Saab switch (cn->class) { 41831fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG: 41841fe6c4eeSScott Long ciss_notify_hotplug(sc, cn); 41851fe6c4eeSScott Long break; 4186c6131460SPaul Saab case CISS_NOTIFY_LOGICAL: 4187c6131460SPaul Saab ciss_notify_logical(sc, cn); 4188c6131460SPaul Saab break; 4189c6131460SPaul Saab case CISS_NOTIFY_PHYSICAL: 4190c6131460SPaul Saab ciss_notify_physical(sc, cn); 4191c6131460SPaul Saab break; 4192c6131460SPaul Saab } 4193c6131460SPaul Saab 4194c6131460SPaul Saab ciss_release_request(cr); 4195c6131460SPaul Saab } 4196c6131460SPaul Saab sc->ciss_notify_thread = NULL; 4197c6131460SPaul Saab wakeup(&sc->ciss_notify_thread); 4198c6131460SPaul Saab 4199975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 42003745c395SJulian Elischer kproc_exit(0); 4201c6131460SPaul Saab } 4202c6131460SPaul Saab 4203c6131460SPaul Saab /************************************************************************ 4204c6131460SPaul Saab * Start the notification kernel thread. 4205c6131460SPaul Saab */ 4206c6131460SPaul Saab static void 4207c6131460SPaul Saab ciss_spawn_notify_thread(struct ciss_softc *sc) 4208c6131460SPaul Saab { 4209c6131460SPaul Saab 42103745c395SJulian Elischer if (kproc_create((void(*)(void *))ciss_notify_thread, sc, 4211c6131460SPaul Saab &sc->ciss_notify_thread, 0, 0, "ciss_notify%d", 4212c6131460SPaul Saab device_get_unit(sc->ciss_dev))) 4213c6131460SPaul Saab panic("Could not create notify thread\n"); 4214c6131460SPaul Saab } 4215c6131460SPaul Saab 4216c6131460SPaul Saab /************************************************************************ 4217c6131460SPaul Saab * Kill the notification kernel thread. 4218c6131460SPaul Saab */ 4219c6131460SPaul Saab static void 4220c6131460SPaul Saab ciss_kill_notify_thread(struct ciss_softc *sc) 4221c6131460SPaul Saab { 4222c6131460SPaul Saab 4223c6131460SPaul Saab if (sc->ciss_notify_thread == NULL) 4224c6131460SPaul Saab return; 4225c6131460SPaul Saab 4226c6131460SPaul Saab sc->ciss_flags |= CISS_FLAG_THREAD_SHUT; 4227c6131460SPaul Saab wakeup(&sc->ciss_notify); 4228975b7318SScott Long msleep(&sc->ciss_notify_thread, &sc->ciss_mtx, PUSER, "thtrm", 0); 42293a31b7ebSMike Smith } 42303a31b7ebSMike Smith 42313a31b7ebSMike Smith /************************************************************************ 42323a31b7ebSMike Smith * Print a request. 42333a31b7ebSMike Smith */ 42342e3d6d0fSWarner Losh #ifdef DDB 42353a31b7ebSMike Smith static void 42363a31b7ebSMike Smith ciss_print_request(struct ciss_request *cr) 42373a31b7ebSMike Smith { 42383a31b7ebSMike Smith struct ciss_softc *sc; 42393a31b7ebSMike Smith struct ciss_command *cc; 42403a31b7ebSMike Smith int i; 42413a31b7ebSMike Smith 42423a31b7ebSMike Smith sc = cr->cr_sc; 42432fdaa90dSScott Long cc = cr->cr_cc; 42443a31b7ebSMike Smith 42453a31b7ebSMike Smith ciss_printf(sc, "REQUEST @ %p\n", cr); 42463a31b7ebSMike Smith ciss_printf(sc, " data %p/%d tag %d flags %b\n", 42473a31b7ebSMike Smith cr->cr_data, cr->cr_length, cr->cr_tag, cr->cr_flags, 42483a31b7ebSMike Smith "\20\1mapped\2sleep\3poll\4dataout\5datain\n"); 42493a31b7ebSMike Smith ciss_printf(sc, " sg list/total %d/%d host tag 0x%x\n", 42503a31b7ebSMike Smith cc->header.sg_in_list, cc->header.sg_total, cc->header.host_tag); 42513a31b7ebSMike Smith switch(cc->header.address.mode.mode) { 42523a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_PERIPHERAL: 42533a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL: 42543a31b7ebSMike Smith ciss_printf(sc, " physical bus %d target %d\n", 42553a31b7ebSMike Smith cc->header.address.physical.bus, cc->header.address.physical.target); 42563a31b7ebSMike Smith break; 42573a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_LOGICAL: 42583a31b7ebSMike Smith ciss_printf(sc, " logical unit %d\n", cc->header.address.logical.lun); 42593a31b7ebSMike Smith break; 42603a31b7ebSMike Smith } 42613a31b7ebSMike Smith ciss_printf(sc, " %s cdb length %d type %s attribute %s\n", 42623a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_NONE) ? "no-I/O" : 42633a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_READ) ? "READ" : 42643a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_WRITE) ? "WRITE" : "??", 42653a31b7ebSMike Smith cc->cdb.cdb_length, 42663a31b7ebSMike Smith (cc->cdb.type == CISS_CDB_TYPE_COMMAND) ? "command" : 42673a31b7ebSMike Smith (cc->cdb.type == CISS_CDB_TYPE_MESSAGE) ? "message" : "??", 42683a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_UNTAGGED) ? "untagged" : 42693a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_SIMPLE) ? "simple" : 42703a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_HEAD_OF_QUEUE) ? "head-of-queue" : 42713a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_ORDERED) ? "ordered" : 42723a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_AUTO_CONTINGENT) ? "auto-contingent" : "??"); 42733a31b7ebSMike Smith ciss_printf(sc, " %*D\n", cc->cdb.cdb_length, &cc->cdb.cdb[0], " "); 42743a31b7ebSMike Smith 42753a31b7ebSMike Smith if (cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) { 42763a31b7ebSMike Smith /* XXX print error info */ 42773a31b7ebSMike Smith } else { 42783a31b7ebSMike Smith /* since we don't use chained s/g, don't support it here */ 42793a31b7ebSMike Smith for (i = 0; i < cc->header.sg_in_list; i++) { 42803a31b7ebSMike Smith if ((i % 4) == 0) 42813a31b7ebSMike Smith ciss_printf(sc, " "); 42823a31b7ebSMike Smith printf("0x%08x/%d ", (u_int32_t)cc->sg[i].address, cc->sg[i].length); 42833a31b7ebSMike Smith if ((((i + 1) % 4) == 0) || (i == (cc->header.sg_in_list - 1))) 42843a31b7ebSMike Smith printf("\n"); 42853a31b7ebSMike Smith } 42863a31b7ebSMike Smith } 42873a31b7ebSMike Smith } 42882e3d6d0fSWarner Losh #endif 42893a31b7ebSMike Smith 42903a31b7ebSMike Smith /************************************************************************ 42913a31b7ebSMike Smith * Print information about the status of a logical drive. 42923a31b7ebSMike Smith */ 42933a31b7ebSMike Smith static void 42943a31b7ebSMike Smith ciss_print_ldrive(struct ciss_softc *sc, struct ciss_ldrive *ld) 42953a31b7ebSMike Smith { 42963a31b7ebSMike Smith int bus, target, i; 42973a31b7ebSMike Smith 4298d4aa427fSPaul Saab if (ld->cl_lstatus == NULL) { 4299d4aa427fSPaul Saab printf("does not exist\n"); 4300d4aa427fSPaul Saab return; 4301d4aa427fSPaul Saab } 4302d4aa427fSPaul Saab 43033a31b7ebSMike Smith /* print drive status */ 43043a31b7ebSMike Smith switch(ld->cl_lstatus->status) { 43053a31b7ebSMike Smith case CISS_LSTATUS_OK: 43063a31b7ebSMike Smith printf("online\n"); 43073a31b7ebSMike Smith break; 43083a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 43093a31b7ebSMike Smith printf("in interim recovery mode\n"); 43103a31b7ebSMike Smith break; 43113a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 43123a31b7ebSMike Smith printf("ready to begin recovery\n"); 43133a31b7ebSMike Smith break; 43143a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 43153a31b7ebSMike Smith bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); 43163a31b7ebSMike Smith target = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); 43173a31b7ebSMike Smith printf("being recovered, working on physical drive %d.%d, %u blocks remaining\n", 43183a31b7ebSMike Smith bus, target, ld->cl_lstatus->blocks_to_recover); 43193a31b7ebSMike Smith break; 43203a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 43213a31b7ebSMike Smith printf("being expanded, %u blocks remaining\n", 43223a31b7ebSMike Smith ld->cl_lstatus->blocks_to_recover); 43233a31b7ebSMike Smith break; 43243a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 43253a31b7ebSMike Smith printf("queued for expansion\n"); 43263a31b7ebSMike Smith break; 43273a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 43283a31b7ebSMike Smith printf("queued for expansion\n"); 43293a31b7ebSMike Smith break; 43303a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 43313a31b7ebSMike Smith printf("wrong physical drive inserted\n"); 43323a31b7ebSMike Smith break; 43333a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 43343a31b7ebSMike Smith printf("missing a needed physical drive\n"); 43353a31b7ebSMike Smith break; 43363a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 43373a31b7ebSMike Smith printf("becoming ready\n"); 43383a31b7ebSMike Smith break; 43393a31b7ebSMike Smith } 43403a31b7ebSMike Smith 4341d4aa427fSPaul Saab /* print failed physical drives */ 43423a31b7ebSMike Smith for (i = 0; i < CISS_BIG_MAP_ENTRIES / 8; i++) { 43433a31b7ebSMike Smith bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_failure_map[i]); 43443a31b7ebSMike Smith target = CISS_BIG_MAP_TARGET(sc, ld->cl_lstatus->drive_failure_map[i]); 43453a31b7ebSMike Smith if (bus == -1) 43463a31b7ebSMike Smith continue; 43473a31b7ebSMike Smith ciss_printf(sc, "physical drive %d:%d (%x) failed\n", bus, target, 43483a31b7ebSMike Smith ld->cl_lstatus->drive_failure_map[i]); 43493a31b7ebSMike Smith } 43503a31b7ebSMike Smith } 43513a31b7ebSMike Smith 4352b27556e0SSean Bruno #ifdef DDB 4353b27556e0SSean Bruno #include <ddb/ddb.h> 4354d4aa427fSPaul Saab /************************************************************************ 4355d4aa427fSPaul Saab * Print information about the controller/driver. 4356d4aa427fSPaul Saab */ 4357d4aa427fSPaul Saab static void 4358d4aa427fSPaul Saab ciss_print_adapter(struct ciss_softc *sc) 4359d4aa427fSPaul Saab { 4360609caf8dSPaul Saab int i, j; 4361d4aa427fSPaul Saab 4362d4aa427fSPaul Saab ciss_printf(sc, "ADAPTER:\n"); 4363d4aa427fSPaul Saab for (i = 0; i < CISSQ_COUNT; i++) { 4364d4aa427fSPaul Saab ciss_printf(sc, "%s %d/%d\n", 4365d4aa427fSPaul Saab i == 0 ? "free" : 4366d4aa427fSPaul Saab i == 1 ? "busy" : "complete", 4367d4aa427fSPaul Saab sc->ciss_qstat[i].q_length, 4368d4aa427fSPaul Saab sc->ciss_qstat[i].q_max); 4369d4aa427fSPaul Saab } 4370d4aa427fSPaul Saab ciss_printf(sc, "max_requests %d\n", sc->ciss_max_requests); 4371d4aa427fSPaul Saab ciss_printf(sc, "flags %b\n", sc->ciss_flags, 4372d4aa427fSPaul Saab "\20\1notify_ok\2control_open\3aborting\4running\21fake_synch\22bmic_abort\n"); 4373d4aa427fSPaul Saab 43741fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 4375e3edca22SSean Bruno for (j = 0; j < sc->ciss_cfg->max_logical_supported; j++) { 4376d4aa427fSPaul Saab ciss_printf(sc, "LOGICAL DRIVE %d: ", i); 4377609caf8dSPaul Saab ciss_print_ldrive(sc, &sc->ciss_logical[i][j]); 4378609caf8dSPaul Saab } 4379d4aa427fSPaul Saab } 4380d4aa427fSPaul Saab 43811fe6c4eeSScott Long /* XXX Should physical drives be printed out here? */ 43821fe6c4eeSScott Long 4383d4aa427fSPaul Saab for (i = 1; i < sc->ciss_max_requests; i++) 4384d4aa427fSPaul Saab ciss_print_request(sc->ciss_request + i); 4385d4aa427fSPaul Saab } 4386d4aa427fSPaul Saab 4387d4aa427fSPaul Saab /* DDB hook */ 4388b27556e0SSean Bruno DB_COMMAND(ciss_prt, db_ciss_prt) 4389d4aa427fSPaul Saab { 4390d4aa427fSPaul Saab struct ciss_softc *sc; 439111f9f6eaSSean Bruno devclass_t dc; 439211f9f6eaSSean Bruno int maxciss, i; 4393d4aa427fSPaul Saab 439411f9f6eaSSean Bruno dc = devclass_find("ciss"); 439511f9f6eaSSean Bruno if ( dc == NULL ) { 439611f9f6eaSSean Bruno printf("%s: can't find devclass!\n", __func__); 439711f9f6eaSSean Bruno return; 439811f9f6eaSSean Bruno } 439911f9f6eaSSean Bruno maxciss = devclass_get_maxunit(dc); 440011f9f6eaSSean Bruno for (i = 0; i < maxciss; i++) { 440111f9f6eaSSean Bruno sc = devclass_get_softc(dc, i); 4402d4aa427fSPaul Saab ciss_print_adapter(sc); 4403d4aa427fSPaul Saab } 4404d4aa427fSPaul Saab } 4405d4aa427fSPaul Saab #endif 4406d4aa427fSPaul Saab 44073a31b7ebSMike Smith /************************************************************************ 44083a31b7ebSMike Smith * Return a name for a logical drive status value. 44093a31b7ebSMike Smith */ 44103a31b7ebSMike Smith static const char * 44113a31b7ebSMike Smith ciss_name_ldrive_status(int status) 44123a31b7ebSMike Smith { 44133a31b7ebSMike Smith switch (status) { 44143a31b7ebSMike Smith case CISS_LSTATUS_OK: 44153a31b7ebSMike Smith return("OK"); 44163a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 44173a31b7ebSMike Smith return("failed"); 44183a31b7ebSMike Smith case CISS_LSTATUS_NOT_CONFIGURED: 44193a31b7ebSMike Smith return("not configured"); 44203a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 44213a31b7ebSMike Smith return("interim recovery"); 44223a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 44233a31b7ebSMike Smith return("ready for recovery"); 44243a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 44253a31b7ebSMike Smith return("recovering"); 44263a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 44273a31b7ebSMike Smith return("wrong physical drive inserted"); 44283a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 44293a31b7ebSMike Smith return("missing physical drive"); 44303a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 44313a31b7ebSMike Smith return("expanding"); 44323a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 44333a31b7ebSMike Smith return("becoming ready"); 44343a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 44353a31b7ebSMike Smith return("queued for expansion"); 44363a31b7ebSMike Smith } 44373a31b7ebSMike Smith return("unknown status"); 44383a31b7ebSMike Smith } 44393a31b7ebSMike Smith 44403a31b7ebSMike Smith /************************************************************************ 44413a31b7ebSMike Smith * Return an online/offline/nonexistent value for a logical drive 44423a31b7ebSMike Smith * status value. 44433a31b7ebSMike Smith */ 44443a31b7ebSMike Smith static int 44453a31b7ebSMike Smith ciss_decode_ldrive_status(int status) 44463a31b7ebSMike Smith { 44473a31b7ebSMike Smith switch(status) { 44483a31b7ebSMike Smith case CISS_LSTATUS_NOT_CONFIGURED: 44493a31b7ebSMike Smith return(CISS_LD_NONEXISTENT); 44503a31b7ebSMike Smith 44513a31b7ebSMike Smith case CISS_LSTATUS_OK: 44523a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 44533a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 44543a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 44553a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 44563a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 44573a31b7ebSMike Smith return(CISS_LD_ONLINE); 44583a31b7ebSMike Smith 44593a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 44603a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 44613a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 44623a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 44633a31b7ebSMike Smith default: 44643a31b7ebSMike Smith return(CISS_LD_OFFLINE); 44653a31b7ebSMike Smith } 44663a31b7ebSMike Smith } 44673a31b7ebSMike Smith 44683a31b7ebSMike Smith /************************************************************************ 44693a31b7ebSMike Smith * Return a name for a logical drive's organisation. 44703a31b7ebSMike Smith */ 44713a31b7ebSMike Smith static const char * 44723a31b7ebSMike Smith ciss_name_ldrive_org(int org) 44733a31b7ebSMike Smith { 44743a31b7ebSMike Smith switch(org) { 44753a31b7ebSMike Smith case CISS_LDRIVE_RAID0: 44763a31b7ebSMike Smith return("RAID 0"); 44773a31b7ebSMike Smith case CISS_LDRIVE_RAID1: 4478d000b49dSKonstantin Belousov return("RAID 1(1+0)"); 44793a31b7ebSMike Smith case CISS_LDRIVE_RAID4: 44803a31b7ebSMike Smith return("RAID 4"); 44813a31b7ebSMike Smith case CISS_LDRIVE_RAID5: 44823a31b7ebSMike Smith return("RAID 5"); 4483aaf8327bSPaul Saab case CISS_LDRIVE_RAID51: 4484aaf8327bSPaul Saab return("RAID 5+1"); 4485aaf8327bSPaul Saab case CISS_LDRIVE_RAIDADG: 4486aaf8327bSPaul Saab return("RAID ADG"); 44873a31b7ebSMike Smith } 4488b790c193SPedro F. Giffuni return("unknown"); 44893a31b7ebSMike Smith } 44903a31b7ebSMike Smith 44913a31b7ebSMike Smith /************************************************************************ 44923a31b7ebSMike Smith * Return a name for a command status value. 44933a31b7ebSMike Smith */ 44943a31b7ebSMike Smith static const char * 44953a31b7ebSMike Smith ciss_name_command_status(int status) 44963a31b7ebSMike Smith { 44973a31b7ebSMike Smith switch(status) { 44983a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 44993a31b7ebSMike Smith return("success"); 45003a31b7ebSMike Smith case CISS_CMD_STATUS_TARGET_STATUS: 45013a31b7ebSMike Smith return("target status"); 45023a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 45033a31b7ebSMike Smith return("data underrun"); 45043a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 45053a31b7ebSMike Smith return("data overrun"); 45063a31b7ebSMike Smith case CISS_CMD_STATUS_INVALID_COMMAND: 45073a31b7ebSMike Smith return("invalid command"); 45083a31b7ebSMike Smith case CISS_CMD_STATUS_PROTOCOL_ERROR: 45093a31b7ebSMike Smith return("protocol error"); 45103a31b7ebSMike Smith case CISS_CMD_STATUS_HARDWARE_ERROR: 45113a31b7ebSMike Smith return("hardware error"); 45123a31b7ebSMike Smith case CISS_CMD_STATUS_CONNECTION_LOST: 45133a31b7ebSMike Smith return("connection lost"); 45143a31b7ebSMike Smith case CISS_CMD_STATUS_ABORTED: 45153a31b7ebSMike Smith return("aborted"); 45163a31b7ebSMike Smith case CISS_CMD_STATUS_ABORT_FAILED: 45173a31b7ebSMike Smith return("abort failed"); 45183a31b7ebSMike Smith case CISS_CMD_STATUS_UNSOLICITED_ABORT: 45193a31b7ebSMike Smith return("unsolicited abort"); 45203a31b7ebSMike Smith case CISS_CMD_STATUS_TIMEOUT: 45213a31b7ebSMike Smith return("timeout"); 45223a31b7ebSMike Smith case CISS_CMD_STATUS_UNABORTABLE: 45233a31b7ebSMike Smith return("unabortable"); 45243a31b7ebSMike Smith } 45253a31b7ebSMike Smith return("unknown status"); 45263a31b7ebSMike Smith } 45273a31b7ebSMike Smith 45283a31b7ebSMike Smith /************************************************************************ 45293a31b7ebSMike Smith * Handle an open on the control device. 45303a31b7ebSMike Smith */ 45313a31b7ebSMike Smith static int 453200b4e54aSWarner Losh ciss_open(struct cdev *dev, int flags, int fmt, struct thread *p) 45333a31b7ebSMike Smith { 45343a31b7ebSMike Smith struct ciss_softc *sc; 45353a31b7ebSMike Smith 45363a31b7ebSMike Smith debug_called(1); 45373a31b7ebSMike Smith 45383a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 45393a31b7ebSMike Smith 45403a31b7ebSMike Smith /* we might want to veto if someone already has us open */ 45413a31b7ebSMike Smith 4542975b7318SScott Long mtx_lock(&sc->ciss_mtx); 45433a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_CONTROL_OPEN; 4544975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 45453a31b7ebSMike Smith return(0); 45463a31b7ebSMike Smith } 45473a31b7ebSMike Smith 45483a31b7ebSMike Smith /************************************************************************ 45493a31b7ebSMike Smith * Handle the last close on the control device. 45503a31b7ebSMike Smith */ 45513a31b7ebSMike Smith static int 455200b4e54aSWarner Losh ciss_close(struct cdev *dev, int flags, int fmt, struct thread *p) 45533a31b7ebSMike Smith { 45543a31b7ebSMike Smith struct ciss_softc *sc; 45553a31b7ebSMike Smith 45563a31b7ebSMike Smith debug_called(1); 45573a31b7ebSMike Smith 45583a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 45593a31b7ebSMike Smith 4560975b7318SScott Long mtx_lock(&sc->ciss_mtx); 45613a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_CONTROL_OPEN; 4562975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 45633a31b7ebSMike Smith return (0); 45643a31b7ebSMike Smith } 45653a31b7ebSMike Smith 45663a31b7ebSMike Smith /******************************************************************************** 45673a31b7ebSMike Smith * Handle adapter-specific control operations. 45683a31b7ebSMike Smith * 45693a31b7ebSMike Smith * Note that the API here is compatible with the Linux driver, in order to 45703a31b7ebSMike Smith * simplify the porting of Compaq's userland tools. 45713a31b7ebSMike Smith */ 45723a31b7ebSMike Smith static int 457300b4e54aSWarner Losh ciss_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *p) 45743a31b7ebSMike Smith { 45753a31b7ebSMike Smith struct ciss_softc *sc; 45767caeec6aSPaul Saab IOCTL_Command_struct *ioc = (IOCTL_Command_struct *)addr; 45777caeec6aSPaul Saab #ifdef __amd64__ 45787caeec6aSPaul Saab IOCTL_Command_struct32 *ioc32 = (IOCTL_Command_struct32 *)addr; 45797caeec6aSPaul Saab IOCTL_Command_struct ioc_swab; 45807caeec6aSPaul Saab #endif 45813a31b7ebSMike Smith int error; 45823a31b7ebSMike Smith 45833a31b7ebSMike Smith debug_called(1); 45843a31b7ebSMike Smith 45853a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 45863a31b7ebSMike Smith error = 0; 4587975b7318SScott Long mtx_lock(&sc->ciss_mtx); 45883a31b7ebSMike Smith 45893a31b7ebSMike Smith switch(cmd) { 459022657ce1SScott Long case CCISS_GETQSTATS: 459122657ce1SScott Long { 459222657ce1SScott Long union ciss_statrequest *cr = (union ciss_statrequest *)addr; 459322657ce1SScott Long 459422657ce1SScott Long switch (cr->cs_item) { 459522657ce1SScott Long case CISSQ_FREE: 459622657ce1SScott Long case CISSQ_NOTIFY: 459722657ce1SScott Long bcopy(&sc->ciss_qstat[cr->cs_item], &cr->cs_qstat, 459822657ce1SScott Long sizeof(struct ciss_qstat)); 459922657ce1SScott Long break; 460022657ce1SScott Long default: 460122657ce1SScott Long error = ENOIOCTL; 460222657ce1SScott Long break; 460322657ce1SScott Long } 460422657ce1SScott Long 460522657ce1SScott Long break; 460622657ce1SScott Long } 460722657ce1SScott Long 46083a31b7ebSMike Smith case CCISS_GETPCIINFO: 46093a31b7ebSMike Smith { 46103a31b7ebSMike Smith cciss_pci_info_struct *pis = (cciss_pci_info_struct *)addr; 46113a31b7ebSMike Smith 46123a31b7ebSMike Smith pis->bus = pci_get_bus(sc->ciss_dev); 46133a31b7ebSMike Smith pis->dev_fn = pci_get_slot(sc->ciss_dev); 4614e17ef005SSean Bruno pis->board_id = (pci_get_subvendor(sc->ciss_dev) << 16) | 4615e17ef005SSean Bruno pci_get_subdevice(sc->ciss_dev); 46163a31b7ebSMike Smith 46173a31b7ebSMike Smith break; 46183a31b7ebSMike Smith } 46193a31b7ebSMike Smith 46203a31b7ebSMike Smith case CCISS_GETINTINFO: 46213a31b7ebSMike Smith { 46223a31b7ebSMike Smith cciss_coalint_struct *cis = (cciss_coalint_struct *)addr; 46233a31b7ebSMike Smith 46243a31b7ebSMike Smith cis->delay = sc->ciss_cfg->interrupt_coalesce_delay; 46253a31b7ebSMike Smith cis->count = sc->ciss_cfg->interrupt_coalesce_count; 46263a31b7ebSMike Smith 46273a31b7ebSMike Smith break; 46283a31b7ebSMike Smith } 46293a31b7ebSMike Smith 46303a31b7ebSMike Smith case CCISS_SETINTINFO: 46313a31b7ebSMike Smith { 46323a31b7ebSMike Smith cciss_coalint_struct *cis = (cciss_coalint_struct *)addr; 46333a31b7ebSMike Smith 46343a31b7ebSMike Smith if ((cis->delay == 0) && (cis->count == 0)) { 46353a31b7ebSMike Smith error = EINVAL; 46363a31b7ebSMike Smith break; 46373a31b7ebSMike Smith } 46383a31b7ebSMike Smith 46393a31b7ebSMike Smith /* 46403a31b7ebSMike Smith * XXX apparently this is only safe if the controller is idle, 46413a31b7ebSMike Smith * we should suspend it before doing this. 46423a31b7ebSMike Smith */ 46433a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay = cis->delay; 46443a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count = cis->count; 46453a31b7ebSMike Smith 46463a31b7ebSMike Smith if (ciss_update_config(sc)) 46473a31b7ebSMike Smith error = EIO; 46483a31b7ebSMike Smith 46493a31b7ebSMike Smith /* XXX resume the controller here */ 46503a31b7ebSMike Smith break; 46513a31b7ebSMike Smith } 46523a31b7ebSMike Smith 46533a31b7ebSMike Smith case CCISS_GETNODENAME: 46543a31b7ebSMike Smith bcopy(sc->ciss_cfg->server_name, (NodeName_type *)addr, 46553a31b7ebSMike Smith sizeof(NodeName_type)); 46563a31b7ebSMike Smith break; 46573a31b7ebSMike Smith 46583a31b7ebSMike Smith case CCISS_SETNODENAME: 46593a31b7ebSMike Smith bcopy((NodeName_type *)addr, sc->ciss_cfg->server_name, 46603a31b7ebSMike Smith sizeof(NodeName_type)); 46613a31b7ebSMike Smith if (ciss_update_config(sc)) 46623a31b7ebSMike Smith error = EIO; 46633a31b7ebSMike Smith break; 46643a31b7ebSMike Smith 46653a31b7ebSMike Smith case CCISS_GETHEARTBEAT: 46663a31b7ebSMike Smith *(Heartbeat_type *)addr = sc->ciss_cfg->heartbeat; 46673a31b7ebSMike Smith break; 46683a31b7ebSMike Smith 46693a31b7ebSMike Smith case CCISS_GETBUSTYPES: 46703a31b7ebSMike Smith *(BusTypes_type *)addr = sc->ciss_cfg->bus_types; 46713a31b7ebSMike Smith break; 46723a31b7ebSMike Smith 46733a31b7ebSMike Smith case CCISS_GETFIRMVER: 46743a31b7ebSMike Smith bcopy(sc->ciss_id->running_firmware_revision, (FirmwareVer_type *)addr, 46753a31b7ebSMike Smith sizeof(FirmwareVer_type)); 46763a31b7ebSMike Smith break; 46773a31b7ebSMike Smith 46783a31b7ebSMike Smith case CCISS_GETDRIVERVER: 46793a31b7ebSMike Smith *(DriverVer_type *)addr = CISS_DRIVER_VERSION; 46803a31b7ebSMike Smith break; 46813a31b7ebSMike Smith 46823a31b7ebSMike Smith case CCISS_REVALIDVOLS: 46833a31b7ebSMike Smith /* 46843a31b7ebSMike Smith * This is a bit ugly; to do it "right" we really need 46853a31b7ebSMike Smith * to find any disks that have changed, kick CAM off them, 46863a31b7ebSMike Smith * then rescan only these disks. It'd be nice if they 46873a31b7ebSMike Smith * a) told us which disk(s) they were going to play with, 46883a31b7ebSMike Smith * and b) which ones had arrived. 8( 46893a31b7ebSMike Smith */ 46903a31b7ebSMike Smith break; 46913a31b7ebSMike Smith 46927caeec6aSPaul Saab #ifdef __amd64__ 46937caeec6aSPaul Saab case CCISS_PASSTHRU32: 46947caeec6aSPaul Saab ioc_swab.LUN_info = ioc32->LUN_info; 46957caeec6aSPaul Saab ioc_swab.Request = ioc32->Request; 46967caeec6aSPaul Saab ioc_swab.error_info = ioc32->error_info; 46977caeec6aSPaul Saab ioc_swab.buf_size = ioc32->buf_size; 46987caeec6aSPaul Saab ioc_swab.buf = (u_int8_t *)(uintptr_t)ioc32->buf; 46997caeec6aSPaul Saab ioc = &ioc_swab; 47007caeec6aSPaul Saab /* FALLTHROUGH */ 47017caeec6aSPaul Saab #endif 47027caeec6aSPaul Saab 47033a31b7ebSMike Smith case CCISS_PASSTHRU: 47047caeec6aSPaul Saab error = ciss_user_command(sc, ioc); 47053a31b7ebSMike Smith break; 47063a31b7ebSMike Smith 47073a31b7ebSMike Smith default: 47083a31b7ebSMike Smith debug(0, "unknown ioctl 0x%lx", cmd); 47093a31b7ebSMike Smith 47103a31b7ebSMike Smith debug(1, "CCISS_GETPCIINFO: 0x%lx", CCISS_GETPCIINFO); 47113a31b7ebSMike Smith debug(1, "CCISS_GETINTINFO: 0x%lx", CCISS_GETINTINFO); 47123a31b7ebSMike Smith debug(1, "CCISS_SETINTINFO: 0x%lx", CCISS_SETINTINFO); 47133a31b7ebSMike Smith debug(1, "CCISS_GETNODENAME: 0x%lx", CCISS_GETNODENAME); 47143a31b7ebSMike Smith debug(1, "CCISS_SETNODENAME: 0x%lx", CCISS_SETNODENAME); 47153a31b7ebSMike Smith debug(1, "CCISS_GETHEARTBEAT: 0x%lx", CCISS_GETHEARTBEAT); 47163a31b7ebSMike Smith debug(1, "CCISS_GETBUSTYPES: 0x%lx", CCISS_GETBUSTYPES); 47173a31b7ebSMike Smith debug(1, "CCISS_GETFIRMVER: 0x%lx", CCISS_GETFIRMVER); 47183a31b7ebSMike Smith debug(1, "CCISS_GETDRIVERVER: 0x%lx", CCISS_GETDRIVERVER); 47193a31b7ebSMike Smith debug(1, "CCISS_REVALIDVOLS: 0x%lx", CCISS_REVALIDVOLS); 47203a31b7ebSMike Smith debug(1, "CCISS_PASSTHRU: 0x%lx", CCISS_PASSTHRU); 47213a31b7ebSMike Smith 47223a31b7ebSMike Smith error = ENOIOCTL; 47233a31b7ebSMike Smith break; 47243a31b7ebSMike Smith } 47253a31b7ebSMike Smith 4726975b7318SScott Long mtx_unlock(&sc->ciss_mtx); 47273a31b7ebSMike Smith return(error); 47283a31b7ebSMike Smith } 4729