13a31b7ebSMike Smith /*- 23a31b7ebSMike Smith * Copyright (c) 2001 Michael Smith 3c6131460SPaul Saab * Copyright (c) 2004 Paul Saab 43a31b7ebSMike Smith * All rights reserved. 53a31b7ebSMike Smith * 63a31b7ebSMike Smith * Redistribution and use in source and binary forms, with or without 73a31b7ebSMike Smith * modification, are permitted provided that the following conditions 83a31b7ebSMike Smith * are met: 93a31b7ebSMike Smith * 1. Redistributions of source code must retain the above copyright 103a31b7ebSMike Smith * notice, this list of conditions and the following disclaimer. 113a31b7ebSMike Smith * 2. Redistributions in binary form must reproduce the above copyright 123a31b7ebSMike Smith * notice, this list of conditions and the following disclaimer in the 133a31b7ebSMike Smith * documentation and/or other materials provided with the distribution. 143a31b7ebSMike Smith * 153a31b7ebSMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 163a31b7ebSMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 173a31b7ebSMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 183a31b7ebSMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 193a31b7ebSMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 203a31b7ebSMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 213a31b7ebSMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 223a31b7ebSMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 233a31b7ebSMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 243a31b7ebSMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 253a31b7ebSMike Smith * SUCH DAMAGE. 263a31b7ebSMike Smith * 273a31b7ebSMike Smith * $FreeBSD$ 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> 863a31b7ebSMike Smith 873a31b7ebSMike Smith #include <cam/cam.h> 883a31b7ebSMike Smith #include <cam/cam_ccb.h> 893a31b7ebSMike Smith #include <cam/cam_periph.h> 903a31b7ebSMike Smith #include <cam/cam_sim.h> 913a31b7ebSMike Smith #include <cam/cam_xpt_sim.h> 923a31b7ebSMike Smith #include <cam/scsi/scsi_all.h> 933a31b7ebSMike Smith #include <cam/scsi/scsi_message.h> 943a31b7ebSMike Smith 953a31b7ebSMike Smith #include <machine/clock.h> 963a31b7ebSMike Smith #include <machine/bus_memio.h> 973a31b7ebSMike Smith #include <machine/bus.h> 983a31b7ebSMike Smith #include <machine/endian.h> 993a31b7ebSMike Smith #include <machine/resource.h> 1003a31b7ebSMike Smith #include <sys/rman.h> 1013a31b7ebSMike Smith 1024fbd232cSWarner Losh #include <dev/pci/pcireg.h> 1034fbd232cSWarner Losh #include <dev/pci/pcivar.h> 1043a31b7ebSMike Smith 1053a31b7ebSMike Smith #include <dev/ciss/cissreg.h> 1063a31b7ebSMike Smith #include <dev/ciss/cissvar.h> 1073a31b7ebSMike Smith #include <dev/ciss/cissio.h> 1083a31b7ebSMike Smith 1093a31b7ebSMike Smith MALLOC_DEFINE(CISS_MALLOC_CLASS, "ciss_data", "ciss internal data buffers"); 1103a31b7ebSMike Smith 1113a31b7ebSMike Smith /* pci interface */ 1123a31b7ebSMike Smith static int ciss_lookup(device_t dev); 1133a31b7ebSMike Smith static int ciss_probe(device_t dev); 1143a31b7ebSMike Smith static int ciss_attach(device_t dev); 1153a31b7ebSMike Smith static int ciss_detach(device_t dev); 1163a31b7ebSMike Smith static int ciss_shutdown(device_t dev); 1173a31b7ebSMike Smith 1183a31b7ebSMike Smith /* (de)initialisation functions, control wrappers */ 1193a31b7ebSMike Smith static int ciss_init_pci(struct ciss_softc *sc); 1203a31b7ebSMike Smith static int ciss_wait_adapter(struct ciss_softc *sc); 1213a31b7ebSMike Smith static int ciss_flush_adapter(struct ciss_softc *sc); 1223a31b7ebSMike Smith static int ciss_init_requests(struct ciss_softc *sc); 1233a31b7ebSMike Smith static void ciss_command_map_helper(void *arg, bus_dma_segment_t *segs, 1243a31b7ebSMike Smith int nseg, int error); 1253a31b7ebSMike Smith static int ciss_identify_adapter(struct ciss_softc *sc); 1263a31b7ebSMike Smith static int ciss_init_logical(struct ciss_softc *sc); 127c6131460SPaul Saab static int ciss_init_physical(struct ciss_softc *sc); 1281fe6c4eeSScott Long static int ciss_filter_physical(struct ciss_softc *sc, struct ciss_lun_report *cll); 1293a31b7ebSMike Smith static int ciss_identify_logical(struct ciss_softc *sc, struct ciss_ldrive *ld); 1303a31b7ebSMike Smith static int ciss_get_ldrive_status(struct ciss_softc *sc, struct ciss_ldrive *ld); 1313a31b7ebSMike Smith static int ciss_update_config(struct ciss_softc *sc); 13288c78a38SPaul Saab static int ciss_accept_media(struct ciss_softc *sc, struct ciss_ldrive *ld); 1333a31b7ebSMike Smith static void ciss_free(struct ciss_softc *sc); 134c6131460SPaul Saab static void ciss_spawn_notify_thread(struct ciss_softc *sc); 135c6131460SPaul Saab static void ciss_kill_notify_thread(struct ciss_softc *sc); 1363a31b7ebSMike Smith 1373a31b7ebSMike Smith /* request submission/completion */ 1383a31b7ebSMike Smith static int ciss_start(struct ciss_request *cr); 1393a31b7ebSMike Smith static void ciss_done(struct ciss_softc *sc); 1403a31b7ebSMike Smith static void ciss_intr(void *arg); 1413a31b7ebSMike Smith static void ciss_complete(struct ciss_softc *sc); 1423a31b7ebSMike Smith static int ciss_report_request(struct ciss_request *cr, int *command_status, 1433a31b7ebSMike Smith int *scsi_status); 1443a31b7ebSMike Smith static int ciss_synch_request(struct ciss_request *cr, int timeout); 1453a31b7ebSMike Smith static int ciss_poll_request(struct ciss_request *cr, int timeout); 1463a31b7ebSMike Smith static int ciss_wait_request(struct ciss_request *cr, int timeout); 1476197ca15SPeter Wemm #if 0 1483a31b7ebSMike Smith static int ciss_abort_request(struct ciss_request *cr); 1496197ca15SPeter Wemm #endif 1503a31b7ebSMike Smith 1513a31b7ebSMike Smith /* request queueing */ 1523a31b7ebSMike Smith static int ciss_get_request(struct ciss_softc *sc, struct ciss_request **crp); 1533a31b7ebSMike Smith static void ciss_preen_command(struct ciss_request *cr); 1543a31b7ebSMike Smith static void ciss_release_request(struct ciss_request *cr); 1553a31b7ebSMike Smith 1563a31b7ebSMike Smith /* request helpers */ 1573a31b7ebSMike Smith static int ciss_get_bmic_request(struct ciss_softc *sc, struct ciss_request **crp, 1583a31b7ebSMike Smith int opcode, void **bufp, size_t bufsize); 1593a31b7ebSMike Smith static int ciss_user_command(struct ciss_softc *sc, IOCTL_Command_struct *ioc); 1603a31b7ebSMike Smith 1613a31b7ebSMike Smith /* DMA map/unmap */ 1623a31b7ebSMike Smith static int ciss_map_request(struct ciss_request *cr); 1633a31b7ebSMike Smith static void ciss_request_map_helper(void *arg, bus_dma_segment_t *segs, 1643a31b7ebSMike Smith int nseg, int error); 1653a31b7ebSMike Smith static void ciss_unmap_request(struct ciss_request *cr); 1663a31b7ebSMike Smith 1673a31b7ebSMike Smith /* CAM interface */ 1683a31b7ebSMike Smith static int ciss_cam_init(struct ciss_softc *sc); 169c6131460SPaul Saab static void ciss_cam_rescan_target(struct ciss_softc *sc, 170c6131460SPaul Saab int bus, int target); 1713a31b7ebSMike Smith static void ciss_cam_rescan_all(struct ciss_softc *sc); 1723a31b7ebSMike Smith static void ciss_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb); 1733a31b7ebSMike Smith static void ciss_cam_action(struct cam_sim *sim, union ccb *ccb); 1743a31b7ebSMike Smith static int ciss_cam_action_io(struct cam_sim *sim, struct ccb_scsiio *csio); 1753a31b7ebSMike Smith static int ciss_cam_emulate(struct ciss_softc *sc, struct ccb_scsiio *csio); 1763a31b7ebSMike Smith static void ciss_cam_poll(struct cam_sim *sim); 1773a31b7ebSMike Smith static void ciss_cam_complete(struct ciss_request *cr); 1783a31b7ebSMike Smith static void ciss_cam_complete_fixup(struct ciss_softc *sc, struct ccb_scsiio *csio); 179c6131460SPaul Saab static struct cam_periph *ciss_find_periph(struct ciss_softc *sc, 180c6131460SPaul Saab int bus, int target); 181c6131460SPaul Saab static int ciss_name_device(struct ciss_softc *sc, int bus, int target); 1823a31b7ebSMike Smith 1833a31b7ebSMike Smith /* periodic status monitoring */ 1843a31b7ebSMike Smith static void ciss_periodic(void *arg); 1853a31b7ebSMike Smith static void ciss_notify_event(struct ciss_softc *sc); 1863a31b7ebSMike Smith static void ciss_notify_complete(struct ciss_request *cr); 1873a31b7ebSMike Smith static int ciss_notify_abort(struct ciss_softc *sc); 1883a31b7ebSMike Smith static int ciss_notify_abort_bmic(struct ciss_softc *sc); 1891fe6c4eeSScott Long static void ciss_notify_hotplug(struct ciss_softc *sc, struct ciss_notify *cn); 1903a31b7ebSMike Smith static void ciss_notify_logical(struct ciss_softc *sc, struct ciss_notify *cn); 1913a31b7ebSMike Smith static void ciss_notify_physical(struct ciss_softc *sc, struct ciss_notify *cn); 1923a31b7ebSMike Smith 1933a31b7ebSMike Smith /* debugging output */ 1943a31b7ebSMike Smith static void ciss_print_request(struct ciss_request *cr); 1953a31b7ebSMike Smith static void ciss_print_ldrive(struct ciss_softc *sc, struct ciss_ldrive *ld); 1963a31b7ebSMike Smith static const char *ciss_name_ldrive_status(int status); 1973a31b7ebSMike Smith static int ciss_decode_ldrive_status(int status); 1983a31b7ebSMike Smith static const char *ciss_name_ldrive_org(int org); 1993a31b7ebSMike Smith static const char *ciss_name_command_status(int status); 2003a31b7ebSMike Smith 2013a31b7ebSMike Smith /* 2023a31b7ebSMike Smith * PCI bus interface. 2033a31b7ebSMike Smith */ 2043a31b7ebSMike Smith static device_method_t ciss_methods[] = { 2053a31b7ebSMike Smith /* Device interface */ 2063a31b7ebSMike Smith DEVMETHOD(device_probe, ciss_probe), 2073a31b7ebSMike Smith DEVMETHOD(device_attach, ciss_attach), 2083a31b7ebSMike Smith DEVMETHOD(device_detach, ciss_detach), 2093a31b7ebSMike Smith DEVMETHOD(device_shutdown, ciss_shutdown), 2103a31b7ebSMike Smith { 0, 0 } 2113a31b7ebSMike Smith }; 2123a31b7ebSMike Smith 2133a31b7ebSMike Smith static driver_t ciss_pci_driver = { 2143a31b7ebSMike Smith "ciss", 2153a31b7ebSMike Smith ciss_methods, 2163a31b7ebSMike Smith sizeof(struct ciss_softc) 2173a31b7ebSMike Smith }; 2183a31b7ebSMike Smith 2193a31b7ebSMike Smith static devclass_t ciss_devclass; 2203a31b7ebSMike Smith DRIVER_MODULE(ciss, pci, ciss_pci_driver, ciss_devclass, 0, 0); 2213a31b7ebSMike Smith 2223a31b7ebSMike Smith /* 2233a31b7ebSMike Smith * Control device interface. 2243a31b7ebSMike Smith */ 2253a31b7ebSMike Smith static d_open_t ciss_open; 2263a31b7ebSMike Smith static d_close_t ciss_close; 2273a31b7ebSMike Smith static d_ioctl_t ciss_ioctl; 2283a31b7ebSMike Smith 2293a31b7ebSMike Smith static struct cdevsw ciss_cdevsw = { 230dc08ffecSPoul-Henning Kamp .d_version = D_VERSION, 231dc08ffecSPoul-Henning Kamp .d_flags = D_NEEDGIANT, 2327ac40f5fSPoul-Henning Kamp .d_open = ciss_open, 2337ac40f5fSPoul-Henning Kamp .d_close = ciss_close, 2347ac40f5fSPoul-Henning Kamp .d_ioctl = ciss_ioctl, 2357ac40f5fSPoul-Henning Kamp .d_name = "ciss", 2363a31b7ebSMike Smith }; 2373a31b7ebSMike Smith 2381fe6c4eeSScott Long /* 2391fe6c4eeSScott Long * This tunable can be set at boot time and controls whether physical devices 2401fe6c4eeSScott Long * that are marked hidden by the firmware should be exposed anyways. 2411fe6c4eeSScott Long */ 2421fe6c4eeSScott Long static unsigned int ciss_expose_hidden_physical = 0; 2431fe6c4eeSScott Long TUNABLE_INT("hw.ciss.expose_hidden_physical", &ciss_expose_hidden_physical); 2441fe6c4eeSScott Long 2453a31b7ebSMike Smith /************************************************************************ 2463a31b7ebSMike Smith * CISS adapters amazingly don't have a defined programming interface 2473a31b7ebSMike Smith * value. (One could say some very despairing things about PCI and 2483a31b7ebSMike Smith * people just not getting the general idea.) So we are forced to 2493a31b7ebSMike Smith * stick with matching against subvendor/subdevice, and thus have to 2503a31b7ebSMike Smith * be updated for every new CISS adapter that appears. 2513a31b7ebSMike Smith */ 2523a31b7ebSMike Smith #define CISS_BOARD_SA5 (1<<0) 2533a31b7ebSMike Smith #define CISS_BOARD_SA5B (1<<1) 2543a31b7ebSMike Smith 2553a31b7ebSMike Smith static struct 2563a31b7ebSMike Smith { 2573a31b7ebSMike Smith u_int16_t subvendor; 2583a31b7ebSMike Smith u_int16_t subdevice; 2593a31b7ebSMike Smith int flags; 2603a31b7ebSMike Smith char *desc; 2613a31b7ebSMike Smith } ciss_vendor_data[] = { 2623a31b7ebSMike Smith { 0x0e11, 0x4070, CISS_BOARD_SA5, "Compaq Smart Array 5300" }, 2633a31b7ebSMike Smith { 0x0e11, 0x4080, CISS_BOARD_SA5B, "Compaq Smart Array 5i" }, 2643a31b7ebSMike Smith { 0x0e11, 0x4082, CISS_BOARD_SA5B, "Compaq Smart Array 532" }, 2652648ded5SPaul Saab { 0x0e11, 0x4083, CISS_BOARD_SA5B, "HP Smart Array 5312" }, 266b26392c7SPaul Saab { 0x0e11, 0x4091, CISS_BOARD_SA5, "HP Smart Array 6i" }, 2679e7313bbSPaul Saab { 0x0e11, 0x409A, CISS_BOARD_SA5, "HP Smart Array 641" }, 2689e7313bbSPaul Saab { 0x0e11, 0x409B, CISS_BOARD_SA5, "HP Smart Array 642" }, 2699e7313bbSPaul Saab { 0x0e11, 0x409C, CISS_BOARD_SA5, "HP Smart Array 6400" }, 2709e7313bbSPaul Saab { 0x0e11, 0x409D, CISS_BOARD_SA5, "HP Smart Array 6400 EM" }, 271b612d5e1SPaul Saab { 0x0e11, 0x409E, CISS_BOARD_SA5, "HP Smart Array 6422" }, 272b612d5e1SPaul Saab { 0x103C, 0x3210, CISS_BOARD_SA5, "HP Smart Array V100" }, 273b612d5e1SPaul Saab { 0x103C, 0x3220, CISS_BOARD_SA5, "HP Smart Array" }, 274b612d5e1SPaul Saab { 0x103C, 0x3222, CISS_BOARD_SA5, "HP Smart Array" }, 275b612d5e1SPaul Saab { 0x103C, 0x3230, CISS_BOARD_SA5, "HP Smart Array" }, 276b612d5e1SPaul Saab { 0x103C, 0x3231, CISS_BOARD_SA5, "HP Smart Array" }, 277b612d5e1SPaul Saab { 0x103C, 0x3232, CISS_BOARD_SA5, "HP Smart Array" }, 278b612d5e1SPaul Saab { 0x103C, 0x3233, CISS_BOARD_SA5, "HP Smart Array" }, 279b612d5e1SPaul Saab { 0x103C, 0x3234, CISS_BOARD_SA5, "HP Smart Array" }, 280b612d5e1SPaul Saab { 0x103C, 0x3235, CISS_BOARD_SA5, "HP Smart Array" }, 281b612d5e1SPaul Saab { 0x103C, 0x3236, CISS_BOARD_SA5, "HP Smart Array" }, 282b612d5e1SPaul Saab { 0x103C, 0x3237, CISS_BOARD_SA5, "HP Smart Array" }, 283b612d5e1SPaul Saab { 0x103C, 0x3238, CISS_BOARD_SA5, "HP Smart Array" }, 284b612d5e1SPaul Saab { 0x103C, 0x3239, CISS_BOARD_SA5, "HP Smart Array" }, 285b612d5e1SPaul Saab { 0x103C, 0x323A, CISS_BOARD_SA5, "HP Smart Array" }, 286b612d5e1SPaul Saab { 0x103C, 0x323B, CISS_BOARD_SA5, "HP Smart Array" }, 287b612d5e1SPaul Saab { 0x103C, 0x323C, CISS_BOARD_SA5, "HP Smart Array" }, 2884a6a94d8SArchie Cobbs { 0, 0, 0, NULL } 2893a31b7ebSMike Smith }; 2903a31b7ebSMike Smith 2913a31b7ebSMike Smith /************************************************************************ 2923a31b7ebSMike Smith * Find a match for the device in our list of known adapters. 2933a31b7ebSMike Smith */ 2943a31b7ebSMike Smith static int 2953a31b7ebSMike Smith ciss_lookup(device_t dev) 2963a31b7ebSMike Smith { 2973a31b7ebSMike Smith int i; 2983a31b7ebSMike Smith 2993a31b7ebSMike Smith for (i = 0; ciss_vendor_data[i].desc != NULL; i++) 3003a31b7ebSMike Smith if ((pci_get_subvendor(dev) == ciss_vendor_data[i].subvendor) && 3013a31b7ebSMike Smith (pci_get_subdevice(dev) == ciss_vendor_data[i].subdevice)) { 3023a31b7ebSMike Smith return(i); 3033a31b7ebSMike Smith } 3043a31b7ebSMike Smith return(-1); 3053a31b7ebSMike Smith } 3063a31b7ebSMike Smith 3073a31b7ebSMike Smith /************************************************************************ 3083a31b7ebSMike Smith * Match a known CISS adapter. 3093a31b7ebSMike Smith */ 3103a31b7ebSMike Smith static int 3113a31b7ebSMike Smith ciss_probe(device_t dev) 3123a31b7ebSMike Smith { 3133a31b7ebSMike Smith int i; 3143a31b7ebSMike Smith 3153a31b7ebSMike Smith i = ciss_lookup(dev); 3163a31b7ebSMike Smith if (i != -1) { 3173a31b7ebSMike Smith device_set_desc(dev, ciss_vendor_data[i].desc); 3183a31b7ebSMike Smith return(-10); 3193a31b7ebSMike Smith } 3203a31b7ebSMike Smith return(ENOENT); 3213a31b7ebSMike Smith } 3223a31b7ebSMike Smith 3233a31b7ebSMike Smith /************************************************************************ 3243a31b7ebSMike Smith * Attach the driver to this adapter. 3253a31b7ebSMike Smith */ 3263a31b7ebSMike Smith static int 3273a31b7ebSMike Smith ciss_attach(device_t dev) 3283a31b7ebSMike Smith { 3293a31b7ebSMike Smith struct ciss_softc *sc; 3303a31b7ebSMike Smith int i, error; 3313a31b7ebSMike Smith 3323a31b7ebSMike Smith debug_called(1); 3333a31b7ebSMike Smith 3343a31b7ebSMike Smith #ifdef CISS_DEBUG 3353a31b7ebSMike Smith /* print structure/union sizes */ 3363a31b7ebSMike Smith debug_struct(ciss_command); 3373a31b7ebSMike Smith debug_struct(ciss_header); 3383a31b7ebSMike Smith debug_union(ciss_device_address); 3393a31b7ebSMike Smith debug_struct(ciss_cdb); 3403a31b7ebSMike Smith debug_struct(ciss_report_cdb); 3413a31b7ebSMike Smith debug_struct(ciss_notify_cdb); 3423a31b7ebSMike Smith debug_struct(ciss_notify); 3433a31b7ebSMike Smith debug_struct(ciss_message_cdb); 3443a31b7ebSMike Smith debug_struct(ciss_error_info_pointer); 3453a31b7ebSMike Smith debug_struct(ciss_error_info); 3463a31b7ebSMike Smith debug_struct(ciss_sg_entry); 3473a31b7ebSMike Smith debug_struct(ciss_config_table); 3483a31b7ebSMike Smith debug_struct(ciss_bmic_cdb); 3493a31b7ebSMike Smith debug_struct(ciss_bmic_id_ldrive); 3503a31b7ebSMike Smith debug_struct(ciss_bmic_id_lstatus); 3513a31b7ebSMike Smith debug_struct(ciss_bmic_id_table); 3523a31b7ebSMike Smith debug_struct(ciss_bmic_id_pdrive); 3533a31b7ebSMike Smith debug_struct(ciss_bmic_blink_pdrive); 3543a31b7ebSMike Smith debug_struct(ciss_bmic_flush_cache); 3553a31b7ebSMike Smith debug_const(CISS_MAX_REQUESTS); 3563a31b7ebSMike Smith debug_const(CISS_MAX_LOGICAL); 3573a31b7ebSMike Smith debug_const(CISS_INTERRUPT_COALESCE_DELAY); 3583a31b7ebSMike Smith debug_const(CISS_INTERRUPT_COALESCE_COUNT); 3593a31b7ebSMike Smith debug_const(CISS_COMMAND_ALLOC_SIZE); 3603a31b7ebSMike Smith debug_const(CISS_COMMAND_SG_LENGTH); 3613a31b7ebSMike Smith 3623a31b7ebSMike Smith debug_type(cciss_pci_info_struct); 3633a31b7ebSMike Smith debug_type(cciss_coalint_struct); 3643a31b7ebSMike Smith debug_type(cciss_coalint_struct); 3653a31b7ebSMike Smith debug_type(NodeName_type); 3663a31b7ebSMike Smith debug_type(NodeName_type); 3673a31b7ebSMike Smith debug_type(Heartbeat_type); 3683a31b7ebSMike Smith debug_type(BusTypes_type); 3693a31b7ebSMike Smith debug_type(FirmwareVer_type); 3703a31b7ebSMike Smith debug_type(DriverVer_type); 3713a31b7ebSMike Smith debug_type(IOCTL_Command_struct); 3723a31b7ebSMike Smith #endif 3733a31b7ebSMike Smith 3743a31b7ebSMike Smith sc = device_get_softc(dev); 3753a31b7ebSMike Smith sc->ciss_dev = dev; 3763a31b7ebSMike Smith 3773a31b7ebSMike Smith /* 3783a31b7ebSMike Smith * Work out adapter type. 3793a31b7ebSMike Smith */ 3803a31b7ebSMike Smith i = ciss_lookup(dev); 3813a31b7ebSMike Smith if (ciss_vendor_data[i].flags & CISS_BOARD_SA5) { 3823a31b7ebSMike Smith sc->ciss_interrupt_mask = CISS_TL_SIMPLE_INTR_OPQ_SA5; 3833a31b7ebSMike Smith } else if (ciss_vendor_data[i].flags & CISS_BOARD_SA5B) { 3843a31b7ebSMike Smith sc->ciss_interrupt_mask = CISS_TL_SIMPLE_INTR_OPQ_SA5B; 3853a31b7ebSMike Smith } else { 3863a31b7ebSMike Smith /* really an error on our part */ 3873a31b7ebSMike Smith ciss_printf(sc, "unable to determine hardware type\n"); 3883a31b7ebSMike Smith error = ENXIO; 3893a31b7ebSMike Smith goto out; 3903a31b7ebSMike Smith } 3913a31b7ebSMike Smith 3923a31b7ebSMike Smith /* 3933a31b7ebSMike Smith * Do PCI-specific init. 3943a31b7ebSMike Smith */ 3953a31b7ebSMike Smith if ((error = ciss_init_pci(sc)) != 0) 3963a31b7ebSMike Smith goto out; 3973a31b7ebSMike Smith 3983a31b7ebSMike Smith /* 3993a31b7ebSMike Smith * Initialise driver queues. 4003a31b7ebSMike Smith */ 4013a31b7ebSMike Smith ciss_initq_free(sc); 4023a31b7ebSMike Smith ciss_initq_busy(sc); 4033a31b7ebSMike Smith ciss_initq_complete(sc); 404c6131460SPaul Saab ciss_initq_notify(sc); 4053a31b7ebSMike Smith 4063a31b7ebSMike Smith /* 4073a31b7ebSMike Smith * Initialise command/request pool. 4083a31b7ebSMike Smith */ 4093a31b7ebSMike Smith if ((error = ciss_init_requests(sc)) != 0) 4103a31b7ebSMike Smith goto out; 4113a31b7ebSMike Smith 4123a31b7ebSMike Smith /* 4133a31b7ebSMike Smith * Get adapter information. 4143a31b7ebSMike Smith */ 4153a31b7ebSMike Smith if ((error = ciss_identify_adapter(sc)) != 0) 4163a31b7ebSMike Smith goto out; 4173a31b7ebSMike Smith 4183a31b7ebSMike Smith /* 419c6131460SPaul Saab * Find all the physical devices. 420c6131460SPaul Saab */ 421c6131460SPaul Saab if ((error = ciss_init_physical(sc)) != 0) 422c6131460SPaul Saab goto out; 423c6131460SPaul Saab 424c6131460SPaul Saab /* 4253a31b7ebSMike Smith * Build our private table of logical devices. 4263a31b7ebSMike Smith */ 4273a31b7ebSMike Smith if ((error = ciss_init_logical(sc)) != 0) 4283a31b7ebSMike Smith goto out; 4293a31b7ebSMike Smith 4303a31b7ebSMike Smith /* 4313a31b7ebSMike Smith * Enable interrupts so that the CAM scan can complete. 4323a31b7ebSMike Smith */ 4333a31b7ebSMike Smith CISS_TL_SIMPLE_ENABLE_INTERRUPTS(sc); 4343a31b7ebSMike Smith 4353a31b7ebSMike Smith /* 4363a31b7ebSMike Smith * Initialise the CAM interface. 4373a31b7ebSMike Smith */ 4383a31b7ebSMike Smith if ((error = ciss_cam_init(sc)) != 0) 4393a31b7ebSMike Smith goto out; 4403a31b7ebSMike Smith 4413a31b7ebSMike Smith /* 4423a31b7ebSMike Smith * Start the heartbeat routine and event chain. 4433a31b7ebSMike Smith */ 4443a31b7ebSMike Smith ciss_periodic(sc); 4453a31b7ebSMike Smith 4463a31b7ebSMike Smith /* 4473a31b7ebSMike Smith * Create the control device. 4483a31b7ebSMike Smith */ 4493a31b7ebSMike Smith sc->ciss_dev_t = make_dev(&ciss_cdevsw, device_get_unit(sc->ciss_dev), 4503a31b7ebSMike Smith UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, 4513a31b7ebSMike Smith "ciss%d", device_get_unit(sc->ciss_dev)); 4523a31b7ebSMike Smith sc->ciss_dev_t->si_drv1 = sc; 4533a31b7ebSMike Smith 4543a31b7ebSMike Smith /* 4553a31b7ebSMike Smith * The adapter is running; synchronous commands can now sleep 4563a31b7ebSMike Smith * waiting for an interrupt to signal completion. 4573a31b7ebSMike Smith */ 4583a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_RUNNING; 4593a31b7ebSMike Smith 460c6131460SPaul Saab ciss_spawn_notify_thread(sc); 461c6131460SPaul Saab 4623a31b7ebSMike Smith error = 0; 4633a31b7ebSMike Smith out: 4643a31b7ebSMike Smith if (error != 0) 4653a31b7ebSMike Smith ciss_free(sc); 4663a31b7ebSMike Smith return(error); 4673a31b7ebSMike Smith } 4683a31b7ebSMike Smith 4693a31b7ebSMike Smith /************************************************************************ 4703a31b7ebSMike Smith * Detach the driver from this adapter. 4713a31b7ebSMike Smith */ 4723a31b7ebSMike Smith static int 4733a31b7ebSMike Smith ciss_detach(device_t dev) 4743a31b7ebSMike Smith { 4753a31b7ebSMike Smith struct ciss_softc *sc = device_get_softc(dev); 4763a31b7ebSMike Smith 4773a31b7ebSMike Smith debug_called(1); 4783a31b7ebSMike Smith 479ffdf82e1SPaul Saab if (sc->ciss_flags & CISS_FLAG_CONTROL_OPEN) 480ffdf82e1SPaul Saab return (EBUSY); 481ffdf82e1SPaul Saab 4823a31b7ebSMike Smith /* flush adapter cache */ 4833a31b7ebSMike Smith ciss_flush_adapter(sc); 4843a31b7ebSMike Smith 4853a31b7ebSMike Smith /* release all resources */ 4863a31b7ebSMike Smith ciss_free(sc); 4873a31b7ebSMike Smith 4883a31b7ebSMike Smith return(0); 4893a31b7ebSMike Smith } 4903a31b7ebSMike Smith 4913a31b7ebSMike Smith /************************************************************************ 4923a31b7ebSMike Smith * Prepare adapter for system shutdown. 4933a31b7ebSMike Smith */ 4943a31b7ebSMike Smith static int 4953a31b7ebSMike Smith ciss_shutdown(device_t dev) 4963a31b7ebSMike Smith { 4973a31b7ebSMike Smith struct ciss_softc *sc = device_get_softc(dev); 4983a31b7ebSMike Smith 4993a31b7ebSMike Smith debug_called(1); 5003a31b7ebSMike Smith 5013a31b7ebSMike Smith /* flush adapter cache */ 5023a31b7ebSMike Smith ciss_flush_adapter(sc); 5033a31b7ebSMike Smith 5043a31b7ebSMike Smith return(0); 5053a31b7ebSMike Smith } 5063a31b7ebSMike Smith 5073a31b7ebSMike Smith /************************************************************************ 5083a31b7ebSMike Smith * Perform PCI-specific attachment actions. 5093a31b7ebSMike Smith */ 5103a31b7ebSMike Smith static int 5113a31b7ebSMike Smith ciss_init_pci(struct ciss_softc *sc) 5123a31b7ebSMike Smith { 5133a31b7ebSMike Smith uintptr_t cbase, csize, cofs; 5143a31b7ebSMike Smith int error; 5153a31b7ebSMike Smith 5163a31b7ebSMike Smith debug_called(1); 5173a31b7ebSMike Smith 5183a31b7ebSMike Smith /* 5193a31b7ebSMike Smith * Allocate register window first (we need this to find the config 5203a31b7ebSMike Smith * struct). 5213a31b7ebSMike Smith */ 5223a31b7ebSMike Smith error = ENXIO; 5233a31b7ebSMike Smith sc->ciss_regs_rid = CISS_TL_SIMPLE_BAR_REGS; 5243a31b7ebSMike Smith if ((sc->ciss_regs_resource = 5255f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, 5265f96beb9SNate Lawson &sc->ciss_regs_rid, RF_ACTIVE)) == NULL) { 5273a31b7ebSMike Smith ciss_printf(sc, "can't allocate register window\n"); 5283a31b7ebSMike Smith return(ENXIO); 5293a31b7ebSMike Smith } 5303a31b7ebSMike Smith sc->ciss_regs_bhandle = rman_get_bushandle(sc->ciss_regs_resource); 5313a31b7ebSMike Smith sc->ciss_regs_btag = rman_get_bustag(sc->ciss_regs_resource); 5323a31b7ebSMike Smith 5333a31b7ebSMike Smith /* 5343a31b7ebSMike Smith * Find the BAR holding the config structure. If it's not the one 5353a31b7ebSMike Smith * we already mapped for registers, map it too. 5363a31b7ebSMike Smith */ 5373a31b7ebSMike Smith sc->ciss_cfg_rid = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_BAR) & 0xffff; 5383a31b7ebSMike Smith if (sc->ciss_cfg_rid != sc->ciss_regs_rid) { 5393a31b7ebSMike Smith if ((sc->ciss_cfg_resource = 5405f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_MEMORY, 5415f96beb9SNate Lawson &sc->ciss_cfg_rid, RF_ACTIVE)) == NULL) { 5423a31b7ebSMike Smith ciss_printf(sc, "can't allocate config window\n"); 5433a31b7ebSMike Smith return(ENXIO); 5443a31b7ebSMike Smith } 5453a31b7ebSMike Smith cbase = (uintptr_t)rman_get_virtual(sc->ciss_cfg_resource); 5463a31b7ebSMike Smith csize = rman_get_end(sc->ciss_cfg_resource) - 5473a31b7ebSMike Smith rman_get_start(sc->ciss_cfg_resource) + 1; 5483a31b7ebSMike Smith } else { 5493a31b7ebSMike Smith cbase = (uintptr_t)rman_get_virtual(sc->ciss_regs_resource); 5503a31b7ebSMike Smith csize = rman_get_end(sc->ciss_regs_resource) - 5513a31b7ebSMike Smith rman_get_start(sc->ciss_regs_resource) + 1; 5523a31b7ebSMike Smith } 5533a31b7ebSMike Smith cofs = CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_CFG_OFF); 5543a31b7ebSMike Smith 5553a31b7ebSMike Smith /* 5563a31b7ebSMike Smith * Use the base/size/offset values we just calculated to 5573a31b7ebSMike Smith * sanity-check the config structure. If it's OK, point to it. 5583a31b7ebSMike Smith */ 5593a31b7ebSMike Smith if ((cofs + sizeof(struct ciss_config_table)) > csize) { 5603a31b7ebSMike Smith ciss_printf(sc, "config table outside window\n"); 5613a31b7ebSMike Smith return(ENXIO); 5623a31b7ebSMike Smith } 5633a31b7ebSMike Smith sc->ciss_cfg = (struct ciss_config_table *)(cbase + cofs); 5643a31b7ebSMike Smith debug(1, "config struct at %p", sc->ciss_cfg); 5653a31b7ebSMike Smith 5663a31b7ebSMike Smith /* 5673a31b7ebSMike Smith * Validate the config structure. If we supported other transport 5683a31b7ebSMike Smith * methods, we could select amongst them at this point in time. 5693a31b7ebSMike Smith */ 5703a31b7ebSMike Smith if (strncmp(sc->ciss_cfg->signature, "CISS", 4)) { 5713a31b7ebSMike Smith ciss_printf(sc, "config signature mismatch (got '%c%c%c%c')\n", 5723a31b7ebSMike Smith sc->ciss_cfg->signature[0], sc->ciss_cfg->signature[1], 5733a31b7ebSMike Smith sc->ciss_cfg->signature[2], sc->ciss_cfg->signature[3]); 5743a31b7ebSMike Smith return(ENXIO); 5753a31b7ebSMike Smith } 5763a31b7ebSMike Smith if ((sc->ciss_cfg->valence < CISS_MIN_VALENCE) || 5773a31b7ebSMike Smith (sc->ciss_cfg->valence > CISS_MAX_VALENCE)) { 5783a31b7ebSMike Smith ciss_printf(sc, "adapter interface specification (%d) unsupported\n", 5793a31b7ebSMike Smith sc->ciss_cfg->valence); 5803a31b7ebSMike Smith return(ENXIO); 5813a31b7ebSMike Smith } 5823a31b7ebSMike Smith 5833a31b7ebSMike Smith /* 5843a31b7ebSMike Smith * Put the board into simple mode, and tell it we're using the low 5853a31b7ebSMike Smith * 4GB of RAM. Set the default interrupt coalescing options. 5863a31b7ebSMike Smith */ 5873a31b7ebSMike Smith if (!(sc->ciss_cfg->supported_methods & CISS_TRANSPORT_METHOD_SIMPLE)) { 5883a31b7ebSMike Smith ciss_printf(sc, "adapter does not support 'simple' transport layer\n"); 5893a31b7ebSMike Smith return(ENXIO); 5903a31b7ebSMike Smith } 5913a31b7ebSMike Smith sc->ciss_cfg->requested_method = CISS_TRANSPORT_METHOD_SIMPLE; 5923a31b7ebSMike Smith sc->ciss_cfg->command_physlimit = 0; 5933a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay = CISS_INTERRUPT_COALESCE_DELAY; 5943a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count = CISS_INTERRUPT_COALESCE_COUNT; 5953a31b7ebSMike Smith 596a891a3bfSPaul Saab #ifdef __i386__ 597a891a3bfSPaul Saab sc->ciss_cfg->host_driver |= CISS_DRIVER_SCSI_PREFETCH; 598a891a3bfSPaul Saab #endif 599a891a3bfSPaul Saab 6003a31b7ebSMike Smith if (ciss_update_config(sc)) { 6013a31b7ebSMike Smith ciss_printf(sc, "adapter refuses to accept config update (IDBR 0x%x)\n", 6023a31b7ebSMike Smith CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IDBR)); 6033a31b7ebSMike Smith return(ENXIO); 6043a31b7ebSMike Smith } 6053a31b7ebSMike Smith if (!(sc->ciss_cfg->active_method != CISS_TRANSPORT_METHOD_SIMPLE)) { 6063a31b7ebSMike Smith ciss_printf(sc, 6073a31b7ebSMike Smith "adapter refuses to go into 'simple' transport mode (0x%x, 0x%x)\n", 6083a31b7ebSMike Smith sc->ciss_cfg->supported_methods, sc->ciss_cfg->active_method); 6093a31b7ebSMike Smith return(ENXIO); 6103a31b7ebSMike Smith } 6113a31b7ebSMike Smith 6123a31b7ebSMike Smith /* 6133a31b7ebSMike Smith * Wait for the adapter to come ready. 6143a31b7ebSMike Smith */ 6153a31b7ebSMike Smith if ((error = ciss_wait_adapter(sc)) != 0) 6163a31b7ebSMike Smith return(error); 6173a31b7ebSMike Smith 6183a31b7ebSMike Smith /* 6193a31b7ebSMike Smith * Turn off interrupts before we go routing anything. 6203a31b7ebSMike Smith */ 6213a31b7ebSMike Smith CISS_TL_SIMPLE_DISABLE_INTERRUPTS(sc); 6223a31b7ebSMike Smith 6233a31b7ebSMike Smith /* 6243a31b7ebSMike Smith * Allocate and set up our interrupt. 6253a31b7ebSMike Smith */ 6263a31b7ebSMike Smith sc->ciss_irq_rid = 0; 6273a31b7ebSMike Smith if ((sc->ciss_irq_resource = 6285f96beb9SNate Lawson bus_alloc_resource_any(sc->ciss_dev, SYS_RES_IRQ, &sc->ciss_irq_rid, 6293a31b7ebSMike Smith RF_ACTIVE | RF_SHAREABLE)) == NULL) { 6303a31b7ebSMike Smith ciss_printf(sc, "can't allocate interrupt\n"); 6313a31b7ebSMike Smith return(ENXIO); 6323a31b7ebSMike Smith } 633cc850363SPeter Wemm if (bus_setup_intr(sc->ciss_dev, sc->ciss_irq_resource, 634cc850363SPeter Wemm INTR_TYPE_CAM|INTR_ENTROPY, ciss_intr, sc, 6353a31b7ebSMike Smith &sc->ciss_intr)) { 6363a31b7ebSMike Smith ciss_printf(sc, "can't set up interrupt\n"); 6373a31b7ebSMike Smith return(ENXIO); 6383a31b7ebSMike Smith } 6393a31b7ebSMike Smith 6403a31b7ebSMike Smith /* 6413a31b7ebSMike Smith * Allocate the parent bus DMA tag appropriate for our PCI 6423a31b7ebSMike Smith * interface. 6433a31b7ebSMike Smith * 6443a31b7ebSMike Smith * Note that "simple" adapters can only address within a 32-bit 6453a31b7ebSMike Smith * span. 6463a31b7ebSMike Smith */ 6473a31b7ebSMike Smith if (bus_dma_tag_create(NULL, /* parent */ 6483a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 649639717c8SPaul Saab BUS_SPACE_MAXADDR, /* lowaddr */ 6503a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 6513a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 652639717c8SPaul Saab BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 653639717c8SPaul Saab CISS_COMMAND_SG_LENGTH, /* nsegments */ 6543a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 6553a31b7ebSMike Smith BUS_DMA_ALLOCNOW, /* flags */ 656f6b1c44dSScott Long NULL, NULL, /* lockfunc, lockarg */ 6573a31b7ebSMike Smith &sc->ciss_parent_dmat)) { 6583a31b7ebSMike Smith ciss_printf(sc, "can't allocate parent DMA tag\n"); 6593a31b7ebSMike Smith return(ENOMEM); 6603a31b7ebSMike Smith } 6613a31b7ebSMike Smith 6623a31b7ebSMike Smith /* 6633a31b7ebSMike Smith * Create DMA tag for mapping buffers into adapter-addressable 6643a31b7ebSMike Smith * space. 6653a31b7ebSMike Smith */ 6663a31b7ebSMike Smith if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 6673a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 6683a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* lowaddr */ 6693a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 6703a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 6713a31b7ebSMike Smith MAXBSIZE, CISS_COMMAND_SG_LENGTH, /* maxsize, nsegments */ 6723a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 6733a31b7ebSMike Smith 0, /* flags */ 674f6b1c44dSScott Long busdma_lock_mutex, &Giant, /* lockfunc, lockarg */ 6753a31b7ebSMike Smith &sc->ciss_buffer_dmat)) { 6763a31b7ebSMike Smith ciss_printf(sc, "can't allocate buffer DMA tag\n"); 6773a31b7ebSMike Smith return(ENOMEM); 6783a31b7ebSMike Smith } 6793a31b7ebSMike Smith return(0); 6803a31b7ebSMike Smith } 6813a31b7ebSMike Smith 6823a31b7ebSMike Smith /************************************************************************ 6833a31b7ebSMike Smith * Wait for the adapter to come ready. 6843a31b7ebSMike Smith */ 6853a31b7ebSMike Smith static int 6863a31b7ebSMike Smith ciss_wait_adapter(struct ciss_softc *sc) 6873a31b7ebSMike Smith { 6883a31b7ebSMike Smith int i; 6893a31b7ebSMike Smith 6903a31b7ebSMike Smith debug_called(1); 6913a31b7ebSMike Smith 6923a31b7ebSMike Smith /* 6933a31b7ebSMike Smith * Wait for the adapter to come ready. 6943a31b7ebSMike Smith */ 6953a31b7ebSMike Smith if (!(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY)) { 6963a31b7ebSMike Smith ciss_printf(sc, "waiting for adapter to come ready...\n"); 6973a31b7ebSMike Smith for (i = 0; !(sc->ciss_cfg->active_method & CISS_TRANSPORT_METHOD_READY); i++) { 6983a31b7ebSMike Smith DELAY(1000000); /* one second */ 6993a31b7ebSMike Smith if (i > 30) { 7003a31b7ebSMike Smith ciss_printf(sc, "timed out waiting for adapter to come ready\n"); 7013a31b7ebSMike Smith return(EIO); 7023a31b7ebSMike Smith } 7033a31b7ebSMike Smith } 7043a31b7ebSMike Smith } 7053a31b7ebSMike Smith return(0); 7063a31b7ebSMike Smith } 7073a31b7ebSMike Smith 7083a31b7ebSMike Smith /************************************************************************ 7093a31b7ebSMike Smith * Flush the adapter cache. 7103a31b7ebSMike Smith */ 7113a31b7ebSMike Smith static int 7123a31b7ebSMike Smith ciss_flush_adapter(struct ciss_softc *sc) 7133a31b7ebSMike Smith { 7143a31b7ebSMike Smith struct ciss_request *cr; 7153a31b7ebSMike Smith struct ciss_bmic_flush_cache *cbfc; 7163a31b7ebSMike Smith int error, command_status; 7173a31b7ebSMike Smith 7183a31b7ebSMike Smith debug_called(1); 7193a31b7ebSMike Smith 7203a31b7ebSMike Smith cr = NULL; 7213a31b7ebSMike Smith cbfc = NULL; 7223a31b7ebSMike Smith 7233a31b7ebSMike Smith /* 7243a31b7ebSMike Smith * Build a BMIC request to flush the cache. We don't disable 7253a31b7ebSMike Smith * it, as we may be going to do more I/O (eg. we are emulating 7263a31b7ebSMike Smith * the Synchronise Cache command). 7273a31b7ebSMike Smith */ 7283a31b7ebSMike Smith if ((cbfc = malloc(sizeof(*cbfc), CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 7293a31b7ebSMike Smith error = ENOMEM; 7303a31b7ebSMike Smith goto out; 7313a31b7ebSMike Smith } 7323a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_FLUSH_CACHE, 7333a31b7ebSMike Smith (void **)&cbfc, sizeof(*cbfc))) != 0) 7343a31b7ebSMike Smith goto out; 7353a31b7ebSMike Smith 7363a31b7ebSMike Smith /* 7373a31b7ebSMike Smith * Submit the request and wait for it to complete. 7383a31b7ebSMike Smith */ 7393a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 7403a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC FLUSH_CACHE command (%d)\n", error); 7413a31b7ebSMike Smith goto out; 7423a31b7ebSMike Smith } 7433a31b7ebSMike Smith 7443a31b7ebSMike Smith /* 7453a31b7ebSMike Smith * Check response. 7463a31b7ebSMike Smith */ 7473a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 7483a31b7ebSMike Smith switch(command_status) { 7493a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 7503a31b7ebSMike Smith break; 7513a31b7ebSMike Smith default: 7523a31b7ebSMike Smith ciss_printf(sc, "error flushing cache (%s)\n", 7533a31b7ebSMike Smith ciss_name_command_status(command_status)); 7543a31b7ebSMike Smith error = EIO; 7553a31b7ebSMike Smith goto out; 7563a31b7ebSMike Smith } 7573a31b7ebSMike Smith 7583a31b7ebSMike Smith out: 7593a31b7ebSMike Smith if (cbfc != NULL) 7603a31b7ebSMike Smith free(cbfc, CISS_MALLOC_CLASS); 7613a31b7ebSMike Smith if (cr != NULL) 7623a31b7ebSMike Smith ciss_release_request(cr); 7633a31b7ebSMike Smith return(error); 7643a31b7ebSMike Smith } 7653a31b7ebSMike Smith 7663a31b7ebSMike Smith /************************************************************************ 7673a31b7ebSMike Smith * Allocate memory for the adapter command structures, initialise 7683a31b7ebSMike Smith * the request structures. 7693a31b7ebSMike Smith * 7703a31b7ebSMike Smith * Note that the entire set of commands are allocated in a single 7713a31b7ebSMike Smith * contiguous slab. 7723a31b7ebSMike Smith */ 7733a31b7ebSMike Smith static int 7743a31b7ebSMike Smith ciss_init_requests(struct ciss_softc *sc) 7753a31b7ebSMike Smith { 7763a31b7ebSMike Smith struct ciss_request *cr; 7773a31b7ebSMike Smith int i; 7783a31b7ebSMike Smith 7793a31b7ebSMike Smith debug_called(1); 7803a31b7ebSMike Smith 7813a31b7ebSMike Smith /* 7823a31b7ebSMike Smith * Calculate the number of request structures/commands we are 7833a31b7ebSMike Smith * going to provide for this adapter. 7843a31b7ebSMike Smith */ 7853a31b7ebSMike Smith sc->ciss_max_requests = min(CISS_MAX_REQUESTS, sc->ciss_cfg->max_outstanding_commands); 7863a31b7ebSMike Smith 7874bca277bSPaul Saab if (bootverbose) 7883a31b7ebSMike Smith ciss_printf(sc, "using %d of %d available commands\n", 7893a31b7ebSMike Smith sc->ciss_max_requests, sc->ciss_cfg->max_outstanding_commands); 7903a31b7ebSMike Smith 7913a31b7ebSMike Smith /* 7923a31b7ebSMike Smith * Create the DMA tag for commands. 7933a31b7ebSMike Smith */ 7943a31b7ebSMike Smith if (bus_dma_tag_create(sc->ciss_parent_dmat, /* parent */ 7953a31b7ebSMike Smith 1, 0, /* alignment, boundary */ 796639717c8SPaul Saab BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ 7973a31b7ebSMike Smith BUS_SPACE_MAXADDR, /* highaddr */ 7983a31b7ebSMike Smith NULL, NULL, /* filter, filterarg */ 7993a31b7ebSMike Smith CISS_COMMAND_ALLOC_SIZE * 8003a31b7ebSMike Smith sc->ciss_max_requests, 1, /* maxsize, nsegments */ 8013a31b7ebSMike Smith BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 802639717c8SPaul Saab BUS_DMA_ALLOCNOW, /* flags */ 803639717c8SPaul Saab NULL, NULL, /* lockfunc, lockarg */ 8043a31b7ebSMike Smith &sc->ciss_command_dmat)) { 8053a31b7ebSMike Smith ciss_printf(sc, "can't allocate command DMA tag\n"); 8063a31b7ebSMike Smith return(ENOMEM); 8073a31b7ebSMike Smith } 8083a31b7ebSMike Smith /* 8093a31b7ebSMike Smith * Allocate memory and make it available for DMA. 8103a31b7ebSMike Smith */ 8113a31b7ebSMike Smith if (bus_dmamem_alloc(sc->ciss_command_dmat, (void **)&sc->ciss_command, 8123a31b7ebSMike Smith BUS_DMA_NOWAIT, &sc->ciss_command_map)) { 8133a31b7ebSMike Smith ciss_printf(sc, "can't allocate command memory\n"); 8143a31b7ebSMike Smith return(ENOMEM); 8153a31b7ebSMike Smith } 8163a31b7ebSMike Smith bus_dmamap_load(sc->ciss_command_dmat, sc->ciss_command_map, sc->ciss_command, 817be241f79SPaul Saab CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests, 8183a31b7ebSMike Smith ciss_command_map_helper, sc, 0); 8193a31b7ebSMike Smith bzero(sc->ciss_command, CISS_COMMAND_ALLOC_SIZE * sc->ciss_max_requests); 8203a31b7ebSMike Smith 8213a31b7ebSMike Smith /* 8223a31b7ebSMike Smith * Set up the request and command structures, push requests onto 8233a31b7ebSMike Smith * the free queue. 8243a31b7ebSMike Smith */ 8253a31b7ebSMike Smith for (i = 1; i < sc->ciss_max_requests; i++) { 8263a31b7ebSMike Smith cr = &sc->ciss_request[i]; 8273a31b7ebSMike Smith cr->cr_sc = sc; 8283a31b7ebSMike Smith cr->cr_tag = i; 8293284b9eeSPaul Saab bus_dmamap_create(sc->ciss_buffer_dmat, 0, &cr->cr_datamap); 8303a31b7ebSMike Smith ciss_enqueue_free(cr); 8313a31b7ebSMike Smith } 8323a31b7ebSMike Smith return(0); 8333a31b7ebSMike Smith } 8343a31b7ebSMike Smith 8353a31b7ebSMike Smith static void 8363a31b7ebSMike Smith ciss_command_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error) 8373a31b7ebSMike Smith { 8383a31b7ebSMike Smith struct ciss_softc *sc = (struct ciss_softc *)arg; 8393a31b7ebSMike Smith 8403a31b7ebSMike Smith sc->ciss_command_phys = segs->ds_addr; 8413a31b7ebSMike Smith } 8423a31b7ebSMike Smith 8433a31b7ebSMike Smith /************************************************************************ 8443a31b7ebSMike Smith * Identify the adapter, print some information about it. 8453a31b7ebSMike Smith */ 8463a31b7ebSMike Smith static int 8473a31b7ebSMike Smith ciss_identify_adapter(struct ciss_softc *sc) 8483a31b7ebSMike Smith { 8493a31b7ebSMike Smith struct ciss_request *cr; 8503a31b7ebSMike Smith int error, command_status; 8513a31b7ebSMike Smith 8523a31b7ebSMike Smith debug_called(1); 8533a31b7ebSMike Smith 8543a31b7ebSMike Smith cr = NULL; 8553a31b7ebSMike Smith 8563a31b7ebSMike Smith /* 8573a31b7ebSMike Smith * Get a request, allocate storage for the adapter data. 8583a31b7ebSMike Smith */ 8593a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_CTLR, 8603a31b7ebSMike Smith (void **)&sc->ciss_id, 8613a31b7ebSMike Smith sizeof(*sc->ciss_id))) != 0) 8623a31b7ebSMike Smith goto out; 8633a31b7ebSMike Smith 8643a31b7ebSMike Smith /* 8653a31b7ebSMike Smith * Submit the request and wait for it to complete. 8663a31b7ebSMike Smith */ 8673a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 8683a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC ID_CTLR command (%d)\n", error); 8693a31b7ebSMike Smith goto out; 8703a31b7ebSMike Smith } 8713a31b7ebSMike Smith 8723a31b7ebSMike Smith /* 8733a31b7ebSMike Smith * Check response. 8743a31b7ebSMike Smith */ 8753a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 8763a31b7ebSMike Smith switch(command_status) { 8773a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 8783a31b7ebSMike Smith break; 8793a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 8803a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 8813a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading adapter information\n"); 8823a31b7ebSMike Smith default: 8833a31b7ebSMike Smith ciss_printf(sc, "error reading adapter information (%s)\n", 8843a31b7ebSMike Smith ciss_name_command_status(command_status)); 8853a31b7ebSMike Smith error = EIO; 8863a31b7ebSMike Smith goto out; 8873a31b7ebSMike Smith } 8883a31b7ebSMike Smith 8893a31b7ebSMike Smith /* sanity-check reply */ 8903a31b7ebSMike Smith if (!sc->ciss_id->big_map_supported) { 8913a31b7ebSMike Smith ciss_printf(sc, "adapter does not support BIG_MAP\n"); 8923a31b7ebSMike Smith error = ENXIO; 8933a31b7ebSMike Smith goto out; 8943a31b7ebSMike Smith } 8953a31b7ebSMike Smith 896d4aa427fSPaul Saab #if 0 8973a31b7ebSMike Smith /* XXX later revisions may not need this */ 8983a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_FAKE_SYNCH; 899d4aa427fSPaul Saab #endif 9003a31b7ebSMike Smith 9013a31b7ebSMike Smith /* XXX only really required for old 5300 adapters? */ 9023a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_BMIC_ABORT; 9033a31b7ebSMike Smith 9043a31b7ebSMike Smith /* print information */ 9054bca277bSPaul Saab if (bootverbose) { 906c6131460SPaul Saab #if 0 /* XXX proxy volumes??? */ 9073a31b7ebSMike Smith ciss_printf(sc, " %d logical drive%s configured\n", 9083a31b7ebSMike Smith sc->ciss_id->configured_logical_drives, 9093a31b7ebSMike Smith (sc->ciss_id->configured_logical_drives == 1) ? "" : "s"); 910c6131460SPaul Saab #endif 9113a31b7ebSMike Smith ciss_printf(sc, " firmware %4.4s\n", sc->ciss_id->running_firmware_revision); 9123a31b7ebSMike Smith ciss_printf(sc, " %d SCSI channels\n", sc->ciss_id->scsi_bus_count); 9133a31b7ebSMike Smith 9143a31b7ebSMike Smith ciss_printf(sc, " signature '%.4s'\n", sc->ciss_cfg->signature); 9153a31b7ebSMike Smith ciss_printf(sc, " valence %d\n", sc->ciss_cfg->valence); 9163a31b7ebSMike Smith ciss_printf(sc, " supported I/O methods 0x%b\n", 9173a31b7ebSMike Smith sc->ciss_cfg->supported_methods, 9183a31b7ebSMike Smith "\20\1READY\2simple\3performant\4MEMQ\n"); 9193a31b7ebSMike Smith ciss_printf(sc, " active I/O method 0x%b\n", 9203a31b7ebSMike Smith sc->ciss_cfg->active_method, "\20\2simple\3performant\4MEMQ\n"); 9213a31b7ebSMike Smith ciss_printf(sc, " 4G page base 0x%08x\n", 9223a31b7ebSMike Smith sc->ciss_cfg->command_physlimit); 9233a31b7ebSMike Smith ciss_printf(sc, " interrupt coalesce delay %dus\n", 9243a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay); 9253a31b7ebSMike Smith ciss_printf(sc, " interrupt coalesce count %d\n", 9263a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count); 9273a31b7ebSMike Smith ciss_printf(sc, " max outstanding commands %d\n", 9283a31b7ebSMike Smith sc->ciss_cfg->max_outstanding_commands); 9293a31b7ebSMike Smith ciss_printf(sc, " bus types 0x%b\n", sc->ciss_cfg->bus_types, 9303a31b7ebSMike Smith "\20\1ultra2\2ultra3\10fibre1\11fibre2\n"); 9313a31b7ebSMike Smith ciss_printf(sc, " server name '%.16s'\n", sc->ciss_cfg->server_name); 9323a31b7ebSMike Smith ciss_printf(sc, " heartbeat 0x%x\n", sc->ciss_cfg->heartbeat); 9333a31b7ebSMike Smith } 9343a31b7ebSMike Smith 9353a31b7ebSMike Smith out: 9363a31b7ebSMike Smith if (error) { 9373a31b7ebSMike Smith if (sc->ciss_id != NULL) { 9383a31b7ebSMike Smith free(sc->ciss_id, CISS_MALLOC_CLASS); 9393a31b7ebSMike Smith sc->ciss_id = NULL; 9403a31b7ebSMike Smith } 9413a31b7ebSMike Smith } 9423a31b7ebSMike Smith if (cr != NULL) 9433a31b7ebSMike Smith ciss_release_request(cr); 9443a31b7ebSMike Smith return(error); 9453a31b7ebSMike Smith } 9463a31b7ebSMike Smith 9473a31b7ebSMike Smith /************************************************************************ 948c6131460SPaul Saab * Helper routine for generating a list of logical and physical luns. 9493a31b7ebSMike Smith */ 950c6131460SPaul Saab static struct ciss_lun_report * 951c6131460SPaul Saab ciss_report_luns(struct ciss_softc *sc, int opcode, int nunits) 9523a31b7ebSMike Smith { 9533a31b7ebSMike Smith struct ciss_request *cr; 9543a31b7ebSMike Smith struct ciss_command *cc; 9553a31b7ebSMike Smith struct ciss_report_cdb *crc; 9563a31b7ebSMike Smith struct ciss_lun_report *cll; 9573a31b7ebSMike Smith int command_status; 958c6131460SPaul Saab int report_size; 959c6131460SPaul Saab int error = 0; 9603a31b7ebSMike Smith 9613a31b7ebSMike Smith debug_called(1); 9623a31b7ebSMike Smith 9633a31b7ebSMike Smith cr = NULL; 9643a31b7ebSMike Smith cll = NULL; 9653a31b7ebSMike Smith 9663a31b7ebSMike Smith /* 9673a31b7ebSMike Smith * Get a request, allocate storage for the address list. 9683a31b7ebSMike Smith */ 9693a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 9703a31b7ebSMike Smith goto out; 971c6131460SPaul Saab report_size = sizeof(*cll) + nunits * sizeof(union ciss_device_address); 9723a31b7ebSMike Smith if ((cll = malloc(report_size, CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 973c6131460SPaul Saab ciss_printf(sc, "can't allocate memory for lun report\n"); 9743a31b7ebSMike Smith error = ENOMEM; 9753a31b7ebSMike Smith goto out; 9763a31b7ebSMike Smith } 9773a31b7ebSMike Smith 9783a31b7ebSMike Smith /* 979c6131460SPaul Saab * Build the Report Logical/Physical LUNs command. 9803a31b7ebSMike Smith */ 9813a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 9823a31b7ebSMike Smith cr->cr_data = cll; 9833a31b7ebSMike Smith cr->cr_length = report_size; 9843a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 9853a31b7ebSMike Smith 9863a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 9873a31b7ebSMike Smith cc->header.address.physical.bus = 0; 9883a31b7ebSMike Smith cc->header.address.physical.target = 0; 9893a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*crc); 9903a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 9913a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 9923a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 9933a31b7ebSMike Smith cc->cdb.timeout = 30; /* XXX better suggestions? */ 9943a31b7ebSMike Smith 9953a31b7ebSMike Smith crc = (struct ciss_report_cdb *)&(cc->cdb.cdb[0]); 9963a31b7ebSMike Smith bzero(crc, sizeof(*crc)); 997c6131460SPaul Saab crc->opcode = opcode; 9983a31b7ebSMike Smith crc->length = htonl(report_size); /* big-endian field */ 9993a31b7ebSMike Smith cll->list_size = htonl(report_size - sizeof(*cll)); /* big-endian field */ 10003a31b7ebSMike Smith 10013a31b7ebSMike Smith /* 10023a31b7ebSMike Smith * Submit the request and wait for it to complete. (timeout 10033a31b7ebSMike Smith * here should be much greater than above) 10043a31b7ebSMike Smith */ 10053a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 1006c6131460SPaul Saab ciss_printf(sc, "error sending %d LUN command (%d)\n", opcode, error); 10073a31b7ebSMike Smith goto out; 10083a31b7ebSMike Smith } 10093a31b7ebSMike Smith 10103a31b7ebSMike Smith /* 10113a31b7ebSMike Smith * Check response. Note that data over/underrun is OK. 10123a31b7ebSMike Smith */ 10133a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 10143a31b7ebSMike Smith switch(command_status) { 10153a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 10163a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: /* buffer too large, not bad */ 10173a31b7ebSMike Smith break; 10183a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 1019c6131460SPaul Saab ciss_printf(sc, "WARNING: more units than driver limit (%d)\n", 10203a31b7ebSMike Smith CISS_MAX_LOGICAL); 10213a31b7ebSMike Smith break; 10223a31b7ebSMike Smith default: 10233a31b7ebSMike Smith ciss_printf(sc, "error detecting logical drive configuration (%s)\n", 10243a31b7ebSMike Smith ciss_name_command_status(command_status)); 10253a31b7ebSMike Smith error = EIO; 10263a31b7ebSMike Smith goto out; 10273a31b7ebSMike Smith } 10283a31b7ebSMike Smith ciss_release_request(cr); 10293a31b7ebSMike Smith cr = NULL; 10303a31b7ebSMike Smith 1031c6131460SPaul Saab out: 1032c6131460SPaul Saab if (cr != NULL) 1033c6131460SPaul Saab ciss_release_request(cr); 1034c6131460SPaul Saab if (error && cll != NULL) { 1035c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 1036c6131460SPaul Saab cll = NULL; 1037c6131460SPaul Saab } 1038c6131460SPaul Saab return(cll); 1039c6131460SPaul Saab } 1040c6131460SPaul Saab 1041c6131460SPaul Saab /************************************************************************ 1042c6131460SPaul Saab * Find logical drives on the adapter. 1043c6131460SPaul Saab */ 1044c6131460SPaul Saab static int 1045c6131460SPaul Saab ciss_init_logical(struct ciss_softc *sc) 1046c6131460SPaul Saab { 1047c6131460SPaul Saab struct ciss_lun_report *cll; 1048c6131460SPaul Saab int error = 0, i, j; 1049c6131460SPaul Saab int ndrives; 1050c6131460SPaul Saab 1051c6131460SPaul Saab debug_called(1); 1052c6131460SPaul Saab 1053c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_LOGICAL_LUNS, 1054c6131460SPaul Saab CISS_MAX_LOGICAL); 1055c6131460SPaul Saab if (cll == NULL) { 1056c6131460SPaul Saab error = ENXIO; 1057c6131460SPaul Saab goto out; 1058c6131460SPaul Saab } 1059c6131460SPaul Saab 10603a31b7ebSMike Smith /* sanity-check reply */ 10613a31b7ebSMike Smith ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 1062777d1b39SPoul-Henning Kamp if ((ndrives < 0) || (ndrives >= CISS_MAX_LOGICAL)) { 10633a31b7ebSMike Smith ciss_printf(sc, "adapter claims to report absurd number of logical drives (%d > %d)\n", 10643a31b7ebSMike Smith ndrives, CISS_MAX_LOGICAL); 1065c6131460SPaul Saab error = ENXIO; 1066c6131460SPaul Saab goto out; 10673a31b7ebSMike Smith } 10683a31b7ebSMike Smith 10693a31b7ebSMike Smith /* 10703a31b7ebSMike Smith * Save logical drive information. 10713a31b7ebSMike Smith */ 1072c6131460SPaul Saab if (bootverbose) { 1073c6131460SPaul Saab ciss_printf(sc, "%d logical drive%s\n", 1074c6131460SPaul Saab ndrives, (ndrives > 1 || ndrives == 0) ? "s" : ""); 1075c6131460SPaul Saab } 1076c6131460SPaul Saab 1077c6131460SPaul Saab sc->ciss_logical = 10781fe6c4eeSScott Long malloc(sc->ciss_max_logical_bus * sizeof(struct ciss_ldrive *), 1079c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1080c6131460SPaul Saab if (sc->ciss_logical == NULL) { 1081c6131460SPaul Saab error = ENXIO; 1082c6131460SPaul Saab goto out; 1083c6131460SPaul Saab } 1084c6131460SPaul Saab 10851fe6c4eeSScott Long for (i = 0; i <= sc->ciss_max_logical_bus; i++) { 1086c6131460SPaul Saab sc->ciss_logical[i] = 1087c6131460SPaul Saab malloc(CISS_MAX_LOGICAL * sizeof(struct ciss_ldrive), 1088c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1089c6131460SPaul Saab if (sc->ciss_logical[i] == NULL) { 1090c6131460SPaul Saab error = ENXIO; 1091c6131460SPaul Saab goto out; 1092c6131460SPaul Saab } 1093c6131460SPaul Saab 1094c6131460SPaul Saab for (j = 0; j < CISS_MAX_LOGICAL; j++) 1095c6131460SPaul Saab sc->ciss_logical[i][j].cl_status = CISS_LD_NONEXISTENT; 1096c6131460SPaul Saab } 1097c6131460SPaul Saab 1098c6131460SPaul Saab 10993a31b7ebSMike Smith for (i = 0; i < CISS_MAX_LOGICAL; i++) { 11003a31b7ebSMike Smith if (i < ndrives) { 1101c6131460SPaul Saab struct ciss_ldrive *ld; 1102c6131460SPaul Saab int bus, target; 1103c6131460SPaul Saab 1104c6131460SPaul Saab bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); 1105c6131460SPaul Saab target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); 1106c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 1107c6131460SPaul Saab 1108c6131460SPaul Saab ld->cl_address = cll->lun[i]; 1109c6131460SPaul Saab ld->cl_controller = &sc->ciss_controllers[bus]; 1110c6131460SPaul Saab if (ciss_identify_logical(sc, ld) != 0) 11113a31b7ebSMike Smith continue; 11123a31b7ebSMike Smith /* 11133a31b7ebSMike Smith * If the drive has had media exchanged, we should bring it online. 11143a31b7ebSMike Smith */ 1115c6131460SPaul Saab if (ld->cl_lstatus->media_exchanged) 111688c78a38SPaul Saab ciss_accept_media(sc, ld); 11173a31b7ebSMike Smith 11183a31b7ebSMike Smith } 11193a31b7ebSMike Smith } 11203a31b7ebSMike Smith 11213a31b7ebSMike Smith out: 11223a31b7ebSMike Smith if (cll != NULL) 11233a31b7ebSMike Smith free(cll, CISS_MALLOC_CLASS); 11243a31b7ebSMike Smith return(error); 11253a31b7ebSMike Smith } 11263a31b7ebSMike Smith 1127440baa08SPaul Saab static int 1128c6131460SPaul Saab ciss_init_physical(struct ciss_softc *sc) 1129c6131460SPaul Saab { 1130c6131460SPaul Saab struct ciss_lun_report *cll; 1131c6131460SPaul Saab int error = 0, i; 1132c6131460SPaul Saab int nphys; 11331fe6c4eeSScott Long int bus, target; 1134c6131460SPaul Saab 1135c6131460SPaul Saab debug_called(1); 1136c6131460SPaul Saab 11371fe6c4eeSScott Long bus = 0; 11381fe6c4eeSScott Long target = 0; 11391fe6c4eeSScott Long 1140c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_PHYSICAL_LUNS, 1141c6131460SPaul Saab CISS_MAX_PHYSICAL); 1142c6131460SPaul Saab if (cll == NULL) { 1143c6131460SPaul Saab error = ENXIO; 1144c6131460SPaul Saab goto out; 1145c6131460SPaul Saab } 1146c6131460SPaul Saab 1147c6131460SPaul Saab nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 1148c6131460SPaul Saab 1149c6131460SPaul Saab if (bootverbose) { 1150c6131460SPaul Saab ciss_printf(sc, "%d physical device%s\n", 1151c6131460SPaul Saab nphys, (nphys > 1 || nphys == 0) ? "s" : ""); 1152c6131460SPaul Saab } 1153c6131460SPaul Saab 1154c6131460SPaul Saab /* 11551fe6c4eeSScott Long * Figure out the bus mapping. 11561fe6c4eeSScott Long * Logical buses include both the local logical bus for local arrays and 11571fe6c4eeSScott Long * proxy buses for remote arrays. Physical buses are numbered by the 11581fe6c4eeSScott Long * controller and represent physical buses that hold physical devices. 11591fe6c4eeSScott Long * We shift these bus numbers so that everything fits into a single flat 11601fe6c4eeSScott Long * numbering space for CAM. Logical buses occupy the first 32 CAM bus 11611fe6c4eeSScott Long * numbers, and the physical bus numbers are shifted to be above that. 11621fe6c4eeSScott Long * This results in the various driver arrays being indexed as follows: 11631fe6c4eeSScott Long * 11641fe6c4eeSScott Long * ciss_controllers[] - indexed by logical bus 11651fe6c4eeSScott Long * ciss_cam_sim[] - indexed by both logical and physical, with physical 11661fe6c4eeSScott Long * being shifted by 32. 11671fe6c4eeSScott Long * ciss_logical[][] - indexed by logical bus 11681fe6c4eeSScott Long * ciss_physical[][] - indexed by physical bus 11691fe6c4eeSScott Long * 11701fe6c4eeSScott Long * XXX This is getting more and more hackish. CISS really doesn't play 11711fe6c4eeSScott Long * well with a standard SCSI model; devices are addressed via magic 11721fe6c4eeSScott Long * cookies, not via b/t/l addresses. Since there is no way to store 11731fe6c4eeSScott Long * the cookie in the CAM device object, we have to keep these lookup 11741fe6c4eeSScott Long * tables handy so that the devices can be found quickly at the cost 11751fe6c4eeSScott Long * of wasting memory and having a convoluted lookup scheme. This 11761fe6c4eeSScott Long * driver should probably be converted to block interface. 11771fe6c4eeSScott Long */ 11781fe6c4eeSScott Long /* 1179c6131460SPaul Saab * If the L2 and L3 SCSI addresses are 0, this signifies a proxy 1180c6131460SPaul Saab * controller. A proxy controller is another physical controller 1181c6131460SPaul Saab * behind the primary PCI controller. We need to know about this 1182c6131460SPaul Saab * so that BMIC commands can be properly targeted. There can be 1183c6131460SPaul Saab * proxy controllers attached to a single PCI controller, so 1184c6131460SPaul Saab * find the highest numbered one so the array can be properly 1185c6131460SPaul Saab * sized. 1186c6131460SPaul Saab */ 11871fe6c4eeSScott Long sc->ciss_max_logical_bus = 1; 1188c6131460SPaul Saab for (i = 0; i < nphys; i++) { 1189c6131460SPaul Saab if (cll->lun[i].physical.extra_address == 0) { 11901fe6c4eeSScott Long bus = cll->lun[i].physical.bus; 11911fe6c4eeSScott Long sc->ciss_max_logical_bus = max(sc->ciss_max_logical_bus, bus) + 1; 11921fe6c4eeSScott Long } else { 11931fe6c4eeSScott Long bus = CISS_EXTRA_BUS2(cll->lun[i].physical.extra_address); 11941fe6c4eeSScott Long sc->ciss_max_physical_bus = max(sc->ciss_max_physical_bus, bus); 1195c6131460SPaul Saab } 1196c6131460SPaul Saab } 1197c6131460SPaul Saab 1198c6131460SPaul Saab sc->ciss_controllers = 11991fe6c4eeSScott Long malloc(sc->ciss_max_logical_bus * sizeof (union ciss_device_address), 1200c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 1201c6131460SPaul Saab 1202c6131460SPaul Saab if (sc->ciss_controllers == NULL) { 1203c6131460SPaul Saab ciss_printf(sc, "Could not allocate memory for controller map\n"); 1204c6131460SPaul Saab error = ENOMEM; 1205c6131460SPaul Saab goto out; 1206c6131460SPaul Saab } 1207c6131460SPaul Saab 1208c6131460SPaul Saab /* setup a map of controller addresses */ 1209c6131460SPaul Saab for (i = 0; i < nphys; i++) { 1210c6131460SPaul Saab if (cll->lun[i].physical.extra_address == 0) { 1211c6131460SPaul Saab sc->ciss_controllers[cll->lun[i].physical.bus] = cll->lun[i]; 1212c6131460SPaul Saab } 1213c6131460SPaul Saab } 1214c6131460SPaul Saab 12151fe6c4eeSScott Long sc->ciss_physical = 12161fe6c4eeSScott Long malloc(sc->ciss_max_physical_bus * sizeof(struct ciss_pdrive *), 12171fe6c4eeSScott Long CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 12181fe6c4eeSScott Long if (sc->ciss_physical == NULL) { 12191fe6c4eeSScott Long ciss_printf(sc, "Could not allocate memory for physical device map\n"); 12201fe6c4eeSScott Long error = ENOMEM; 12211fe6c4eeSScott Long goto out; 12221fe6c4eeSScott Long } 12231fe6c4eeSScott Long 12241fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_physical_bus; i++) { 12251fe6c4eeSScott Long sc->ciss_physical[i] = 12261fe6c4eeSScott Long malloc(sizeof(struct ciss_pdrive) * CISS_MAX_PHYSTGT, 12271fe6c4eeSScott Long CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 12281fe6c4eeSScott Long if (sc->ciss_physical[i] == NULL) { 12291fe6c4eeSScott Long ciss_printf(sc, "Could not allocate memory for target map\n"); 12301fe6c4eeSScott Long error = ENOMEM; 12311fe6c4eeSScott Long goto out; 12321fe6c4eeSScott Long } 12331fe6c4eeSScott Long } 12341fe6c4eeSScott Long 12351fe6c4eeSScott Long ciss_filter_physical(sc, cll); 12361fe6c4eeSScott Long 1237c6131460SPaul Saab out: 1238c6131460SPaul Saab if (cll != NULL) 1239c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 1240c6131460SPaul Saab 1241c6131460SPaul Saab return(error); 1242c6131460SPaul Saab } 1243c6131460SPaul Saab 1244c6131460SPaul Saab static int 12451fe6c4eeSScott Long ciss_filter_physical(struct ciss_softc *sc, struct ciss_lun_report *cll) 12461fe6c4eeSScott Long { 12471fe6c4eeSScott Long u_int32_t ea; 12481fe6c4eeSScott Long int i, nphys; 12491fe6c4eeSScott Long int bus, target; 12501fe6c4eeSScott Long 12511fe6c4eeSScott Long nphys = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 12521fe6c4eeSScott Long for (i = 0; i < nphys; i++) { 12531fe6c4eeSScott Long if (cll->lun[i].physical.extra_address == 0) 12541fe6c4eeSScott Long continue; 12551fe6c4eeSScott Long 12561fe6c4eeSScott Long /* 12571fe6c4eeSScott Long * Filter out devices that we don't want. Level 3 LUNs could 12581fe6c4eeSScott Long * probably be supported, but the docs don't give enough of a 12591fe6c4eeSScott Long * hint to know how. 12601fe6c4eeSScott Long * 12611fe6c4eeSScott Long * The mode field of the physical address is likely set to have 12621fe6c4eeSScott Long * hard disks masked out. Honor it unless the user has overridden 12631fe6c4eeSScott Long * us with the tunable. We also munge the inquiry data for these 12641fe6c4eeSScott Long * disks so that they only show up as passthrough devices. Keeping 12651fe6c4eeSScott Long * them visible in this fashion is useful for doing things like 12661fe6c4eeSScott Long * flashing firmware. 12671fe6c4eeSScott Long */ 12681fe6c4eeSScott Long ea = cll->lun[i].physical.extra_address; 12691fe6c4eeSScott Long if ((CISS_EXTRA_BUS3(ea) != 0) || (CISS_EXTRA_TARGET3(ea) != 0) || 12701fe6c4eeSScott Long (CISS_EXTRA_MODE2(ea) == 0x3)) 12711fe6c4eeSScott Long continue; 12721fe6c4eeSScott Long if ((ciss_expose_hidden_physical == 0) && 12731fe6c4eeSScott Long (cll->lun[i].physical.mode == CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL)) 12741fe6c4eeSScott Long continue; 12751fe6c4eeSScott Long 12761fe6c4eeSScott Long /* 12771fe6c4eeSScott Long * Note: CISS firmware numbers physical busses starting at '1', not 12781fe6c4eeSScott Long * '0'. This numbering is internal to the firmware and is only 12791fe6c4eeSScott Long * used as a hint here. 12801fe6c4eeSScott Long */ 12811fe6c4eeSScott Long bus = CISS_EXTRA_BUS2(ea) - 1; 12821fe6c4eeSScott Long target = CISS_EXTRA_TARGET2(ea); 12831fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_address = cll->lun[i]; 12841fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_online = 1; 12851fe6c4eeSScott Long } 12861fe6c4eeSScott Long 12871fe6c4eeSScott Long return (0); 12881fe6c4eeSScott Long } 12891fe6c4eeSScott Long 12901fe6c4eeSScott Long static int 1291440baa08SPaul Saab ciss_inquiry_logical(struct ciss_softc *sc, struct ciss_ldrive *ld) 1292440baa08SPaul Saab { 1293440baa08SPaul Saab struct ciss_request *cr; 1294440baa08SPaul Saab struct ciss_command *cc; 1295440baa08SPaul Saab struct scsi_inquiry *inq; 1296440baa08SPaul Saab int error; 1297440baa08SPaul Saab int command_status; 1298440baa08SPaul Saab 1299440baa08SPaul Saab cr = NULL; 1300440baa08SPaul Saab 1301440baa08SPaul Saab bzero(&ld->cl_geometry, sizeof(ld->cl_geometry)); 1302440baa08SPaul Saab 1303440baa08SPaul Saab if ((error = ciss_get_request(sc, &cr)) != 0) 1304440baa08SPaul Saab goto out; 1305440baa08SPaul Saab 1306440baa08SPaul Saab cc = CISS_FIND_COMMAND(cr); 1307440baa08SPaul Saab cr->cr_data = &ld->cl_geometry; 1308440baa08SPaul Saab cr->cr_length = sizeof(ld->cl_geometry); 1309440baa08SPaul Saab cr->cr_flags = CISS_REQ_DATAIN; 1310440baa08SPaul Saab 1311c6131460SPaul Saab cc->header.address = ld->cl_address; 1312440baa08SPaul Saab cc->cdb.cdb_length = 6; 1313440baa08SPaul Saab cc->cdb.type = CISS_CDB_TYPE_COMMAND; 1314440baa08SPaul Saab cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 1315440baa08SPaul Saab cc->cdb.direction = CISS_CDB_DIRECTION_READ; 1316440baa08SPaul Saab cc->cdb.timeout = 30; 1317440baa08SPaul Saab 1318440baa08SPaul Saab inq = (struct scsi_inquiry *)&(cc->cdb.cdb[0]); 1319440baa08SPaul Saab inq->opcode = INQUIRY; 1320440baa08SPaul Saab inq->byte2 = SI_EVPD; 1321440baa08SPaul Saab inq->page_code = CISS_VPD_LOGICAL_DRIVE_GEOMETRY; 1322440baa08SPaul Saab inq->length = sizeof(ld->cl_geometry); 1323440baa08SPaul Saab 1324440baa08SPaul Saab if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 1325440baa08SPaul Saab ciss_printf(sc, "error getting geometry (%d)\n", error); 1326440baa08SPaul Saab goto out; 1327440baa08SPaul Saab } 1328440baa08SPaul Saab 1329440baa08SPaul Saab ciss_report_request(cr, &command_status, NULL); 1330440baa08SPaul Saab switch(command_status) { 1331440baa08SPaul Saab case CISS_CMD_STATUS_SUCCESS: 1332440baa08SPaul Saab case CISS_CMD_STATUS_DATA_UNDERRUN: 1333440baa08SPaul Saab break; 1334440baa08SPaul Saab case CISS_CMD_STATUS_DATA_OVERRUN: 1335440baa08SPaul Saab ciss_printf(sc, "WARNING: Data overrun\n"); 1336440baa08SPaul Saab break; 1337440baa08SPaul Saab default: 1338440baa08SPaul Saab ciss_printf(sc, "Error detecting logical drive geometry (%s)\n", 1339440baa08SPaul Saab ciss_name_command_status(command_status)); 1340440baa08SPaul Saab break; 1341440baa08SPaul Saab } 1342440baa08SPaul Saab 1343440baa08SPaul Saab out: 1344440baa08SPaul Saab if (cr != NULL) 1345440baa08SPaul Saab ciss_release_request(cr); 1346440baa08SPaul Saab return(error); 1347440baa08SPaul Saab } 13483a31b7ebSMike Smith /************************************************************************ 13493a31b7ebSMike Smith * Identify a logical drive, initialise state related to it. 13503a31b7ebSMike Smith */ 13513a31b7ebSMike Smith static int 13523a31b7ebSMike Smith ciss_identify_logical(struct ciss_softc *sc, struct ciss_ldrive *ld) 13533a31b7ebSMike Smith { 13543a31b7ebSMike Smith struct ciss_request *cr; 13553a31b7ebSMike Smith struct ciss_command *cc; 13563a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 13573a31b7ebSMike Smith int error, command_status; 13583a31b7ebSMike Smith 13593a31b7ebSMike Smith debug_called(1); 13603a31b7ebSMike Smith 13613a31b7ebSMike Smith cr = NULL; 13623a31b7ebSMike Smith 13633a31b7ebSMike Smith /* 13643a31b7ebSMike Smith * Build a BMIC request to fetch the drive ID. 13653a31b7ebSMike Smith */ 13663a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_LDRIVE, 13673a31b7ebSMike Smith (void **)&ld->cl_ldrive, 13683a31b7ebSMike Smith sizeof(*ld->cl_ldrive))) != 0) 13693a31b7ebSMike Smith goto out; 13703a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 1371c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 13723a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1373c6131460SPaul Saab cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 13743a31b7ebSMike Smith 13753a31b7ebSMike Smith /* 13763a31b7ebSMike Smith * Submit the request and wait for it to complete. 13773a31b7ebSMike Smith */ 13783a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 13793a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC LDRIVE command (%d)\n", error); 13803a31b7ebSMike Smith goto out; 13813a31b7ebSMike Smith } 13823a31b7ebSMike Smith 13833a31b7ebSMike Smith /* 13843a31b7ebSMike Smith * Check response. 13853a31b7ebSMike Smith */ 13863a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 13873a31b7ebSMike Smith switch(command_status) { 13883a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 13893a31b7ebSMike Smith break; 13903a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 13913a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 13923a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading logical drive ID\n"); 13933a31b7ebSMike Smith default: 13943a31b7ebSMike Smith ciss_printf(sc, "error reading logical drive ID (%s)\n", 13953a31b7ebSMike Smith ciss_name_command_status(command_status)); 13963a31b7ebSMike Smith error = EIO; 13973a31b7ebSMike Smith goto out; 13983a31b7ebSMike Smith } 13993a31b7ebSMike Smith ciss_release_request(cr); 14003a31b7ebSMike Smith cr = NULL; 14013a31b7ebSMike Smith 14023a31b7ebSMike Smith /* 14033a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive status. 14043a31b7ebSMike Smith */ 14053a31b7ebSMike Smith if ((error = ciss_get_ldrive_status(sc, ld)) != 0) 14063a31b7ebSMike Smith goto out; 14073a31b7ebSMike Smith 14083a31b7ebSMike Smith /* 1409440baa08SPaul Saab * Get the logical drive geometry. 1410440baa08SPaul Saab */ 1411440baa08SPaul Saab if ((error = ciss_inquiry_logical(sc, ld)) != 0) 1412440baa08SPaul Saab goto out; 1413440baa08SPaul Saab 1414440baa08SPaul Saab /* 14153a31b7ebSMike Smith * Print the drive's basic characteristics. 14163a31b7ebSMike Smith */ 14174bca277bSPaul Saab if (bootverbose) { 1418c6131460SPaul Saab ciss_printf(sc, "logical drive (b%dt%d): %s, %dMB ", 1419c6131460SPaul Saab CISS_LUN_TO_BUS(ld->cl_address.logical.lun), 1420c6131460SPaul Saab CISS_LUN_TO_TARGET(ld->cl_address.logical.lun), 142179adbf76SPaul Saab ciss_name_ldrive_org(ld->cl_ldrive->fault_tolerance), 14223a31b7ebSMike Smith ((ld->cl_ldrive->blocks_available / (1024 * 1024)) * 14233a31b7ebSMike Smith ld->cl_ldrive->block_size)); 14243a31b7ebSMike Smith 14253a31b7ebSMike Smith ciss_print_ldrive(sc, ld); 14263a31b7ebSMike Smith } 14273a31b7ebSMike Smith out: 14283a31b7ebSMike Smith if (error != 0) { 14293a31b7ebSMike Smith /* make the drive not-exist */ 14303a31b7ebSMike Smith ld->cl_status = CISS_LD_NONEXISTENT; 14313a31b7ebSMike Smith if (ld->cl_ldrive != NULL) { 14323a31b7ebSMike Smith free(ld->cl_ldrive, CISS_MALLOC_CLASS); 14333a31b7ebSMike Smith ld->cl_ldrive = NULL; 14343a31b7ebSMike Smith } 14353a31b7ebSMike Smith if (ld->cl_lstatus != NULL) { 14363a31b7ebSMike Smith free(ld->cl_lstatus, CISS_MALLOC_CLASS); 14373a31b7ebSMike Smith ld->cl_lstatus = NULL; 14383a31b7ebSMike Smith } 14393a31b7ebSMike Smith } 14403a31b7ebSMike Smith if (cr != NULL) 14413a31b7ebSMike Smith ciss_release_request(cr); 14423a31b7ebSMike Smith 14433a31b7ebSMike Smith return(error); 14443a31b7ebSMike Smith } 14453a31b7ebSMike Smith 14463a31b7ebSMike Smith /************************************************************************ 14473a31b7ebSMike Smith * Get status for a logical drive. 14483a31b7ebSMike Smith * 14493a31b7ebSMike Smith * XXX should we also do this in response to Test Unit Ready? 14503a31b7ebSMike Smith */ 14513a31b7ebSMike Smith static int 14523a31b7ebSMike Smith ciss_get_ldrive_status(struct ciss_softc *sc, struct ciss_ldrive *ld) 14533a31b7ebSMike Smith { 14543a31b7ebSMike Smith struct ciss_request *cr; 14553a31b7ebSMike Smith struct ciss_command *cc; 14563a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 14573a31b7ebSMike Smith int error, command_status; 14583a31b7ebSMike Smith 14593a31b7ebSMike Smith /* 14603a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive status. 14613a31b7ebSMike Smith */ 14623a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ID_LSTATUS, 14633a31b7ebSMike Smith (void **)&ld->cl_lstatus, 14643a31b7ebSMike Smith sizeof(*ld->cl_lstatus))) != 0) 14653a31b7ebSMike Smith goto out; 14663a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 1467c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 14683a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1469c6131460SPaul Saab cbc->log_drive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 14703a31b7ebSMike Smith 14713a31b7ebSMike Smith /* 14723a31b7ebSMike Smith * Submit the request and wait for it to complete. 14733a31b7ebSMike Smith */ 14743a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 14753a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC LSTATUS command (%d)\n", error); 14763a31b7ebSMike Smith goto out; 14773a31b7ebSMike Smith } 14783a31b7ebSMike Smith 14793a31b7ebSMike Smith /* 14803a31b7ebSMike Smith * Check response. 14813a31b7ebSMike Smith */ 14823a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 14833a31b7ebSMike Smith switch(command_status) { 14843a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* buffer right size */ 14853a31b7ebSMike Smith break; 14863a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 14873a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 14883a31b7ebSMike Smith ciss_printf(sc, "data over/underrun reading logical drive status\n"); 14893a31b7ebSMike Smith default: 14903a31b7ebSMike Smith ciss_printf(sc, "error reading logical drive status (%s)\n", 14913a31b7ebSMike Smith ciss_name_command_status(command_status)); 14923a31b7ebSMike Smith error = EIO; 14933a31b7ebSMike Smith goto out; 14943a31b7ebSMike Smith } 14953a31b7ebSMike Smith 14963a31b7ebSMike Smith /* 14973a31b7ebSMike Smith * Set the drive's summary status based on the returned status. 14983a31b7ebSMike Smith * 14993a31b7ebSMike Smith * XXX testing shows that a failed JBOD drive comes back at next 15003a31b7ebSMike Smith * boot in "queued for expansion" mode. WTF? 15013a31b7ebSMike Smith */ 15023a31b7ebSMike Smith ld->cl_status = ciss_decode_ldrive_status(ld->cl_lstatus->status); 15033a31b7ebSMike Smith 15043a31b7ebSMike Smith out: 15053a31b7ebSMike Smith if (cr != NULL) 15063a31b7ebSMike Smith ciss_release_request(cr); 15073a31b7ebSMike Smith return(error); 15083a31b7ebSMike Smith } 15093a31b7ebSMike Smith 15103a31b7ebSMike Smith /************************************************************************ 15113a31b7ebSMike Smith * Notify the adapter of a config update. 15123a31b7ebSMike Smith */ 15133a31b7ebSMike Smith static int 15143a31b7ebSMike Smith ciss_update_config(struct ciss_softc *sc) 15153a31b7ebSMike Smith { 15163a31b7ebSMike Smith int i; 15173a31b7ebSMike Smith 15183a31b7ebSMike Smith debug_called(1); 15193a31b7ebSMike Smith 15203a31b7ebSMike Smith CISS_TL_SIMPLE_WRITE(sc, CISS_TL_SIMPLE_IDBR, CISS_TL_SIMPLE_IDBR_CFG_TABLE); 15213a31b7ebSMike Smith for (i = 0; i < 1000; i++) { 15223a31b7ebSMike Smith if (!(CISS_TL_SIMPLE_READ(sc, CISS_TL_SIMPLE_IDBR) & 15233a31b7ebSMike Smith CISS_TL_SIMPLE_IDBR_CFG_TABLE)) { 15243a31b7ebSMike Smith return(0); 15253a31b7ebSMike Smith } 15263a31b7ebSMike Smith DELAY(1000); 15273a31b7ebSMike Smith } 15283a31b7ebSMike Smith return(1); 15293a31b7ebSMike Smith } 15303a31b7ebSMike Smith 15313a31b7ebSMike Smith /************************************************************************ 15323a31b7ebSMike Smith * Accept new media into a logical drive. 15333a31b7ebSMike Smith * 15343a31b7ebSMike Smith * XXX The drive has previously been offline; it would be good if we 15353a31b7ebSMike Smith * could make sure it's not open right now. 15363a31b7ebSMike Smith */ 15373a31b7ebSMike Smith static int 153888c78a38SPaul Saab ciss_accept_media(struct ciss_softc *sc, struct ciss_ldrive *ld) 15393a31b7ebSMike Smith { 15403a31b7ebSMike Smith struct ciss_request *cr; 15413a31b7ebSMike Smith struct ciss_command *cc; 15423a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 154388c78a38SPaul Saab int command_status; 154488c78a38SPaul Saab int error = 0, ldrive; 1545609caf8dSPaul Saab 1546609caf8dSPaul Saab ldrive = CISS_LUN_TO_TARGET(ld->cl_address.logical.lun); 15473a31b7ebSMike Smith 154888c78a38SPaul Saab debug(0, "bringing logical drive %d back online"); 15493a31b7ebSMike Smith 15503a31b7ebSMike Smith /* 15513a31b7ebSMike Smith * Build a CISS BMIC command to bring the drive back online. 15523a31b7ebSMike Smith */ 15533a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_BMIC_ACCEPT_MEDIA, 15543a31b7ebSMike Smith NULL, 0)) != 0) 15553a31b7ebSMike Smith goto out; 15563a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 1557c6131460SPaul Saab cc->header.address = *ld->cl_controller; /* target controller */ 15583a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 1559609caf8dSPaul Saab cbc->log_drive = ldrive; 15603a31b7ebSMike Smith 15613a31b7ebSMike Smith /* 15623a31b7ebSMike Smith * Submit the request and wait for it to complete. 15633a31b7ebSMike Smith */ 15643a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 156588c78a38SPaul Saab ciss_printf(sc, "error sending BMIC ACCEPT MEDIA command (%d)\n", error); 15663a31b7ebSMike Smith goto out; 15673a31b7ebSMike Smith } 15683a31b7ebSMike Smith 15693a31b7ebSMike Smith /* 15703a31b7ebSMike Smith * Check response. 15713a31b7ebSMike Smith */ 15723a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 15733a31b7ebSMike Smith switch(command_status) { 15743a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: /* all OK */ 15753a31b7ebSMike Smith /* we should get a logical drive status changed event here */ 15763a31b7ebSMike Smith break; 15773a31b7ebSMike Smith default: 15783a31b7ebSMike Smith ciss_printf(cr->cr_sc, "error accepting media into failed logical drive (%s)\n", 15793a31b7ebSMike Smith ciss_name_command_status(command_status)); 15803a31b7ebSMike Smith break; 15813a31b7ebSMike Smith } 158288c78a38SPaul Saab 158388c78a38SPaul Saab out: 158488c78a38SPaul Saab if (cr != NULL) 15853a31b7ebSMike Smith ciss_release_request(cr); 158688c78a38SPaul Saab return(error); 15873a31b7ebSMike Smith } 15883a31b7ebSMike Smith 15893a31b7ebSMike Smith /************************************************************************ 15903a31b7ebSMike Smith * Release adapter resources. 15913a31b7ebSMike Smith */ 15923a31b7ebSMike Smith static void 15933a31b7ebSMike Smith ciss_free(struct ciss_softc *sc) 15943a31b7ebSMike Smith { 15953284b9eeSPaul Saab struct ciss_request *cr; 1596c6131460SPaul Saab int i; 15973284b9eeSPaul Saab 15983a31b7ebSMike Smith debug_called(1); 15993a31b7ebSMike Smith 16003a31b7ebSMike Smith /* we're going away */ 16013a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_ABORTING; 16023a31b7ebSMike Smith 16033a31b7ebSMike Smith /* terminate the periodic heartbeat routine */ 16043a31b7ebSMike Smith untimeout(ciss_periodic, sc, sc->ciss_periodic); 16053a31b7ebSMike Smith 16063a31b7ebSMike Smith /* cancel the Event Notify chain */ 16073a31b7ebSMike Smith ciss_notify_abort(sc); 16083a31b7ebSMike Smith 1609c6131460SPaul Saab ciss_kill_notify_thread(sc); 1610c6131460SPaul Saab 161178d03361SPaul Saab /* remove the control device */ 161278d03361SPaul Saab if (sc->ciss_dev_t != NULL) 161378d03361SPaul Saab destroy_dev(sc->ciss_dev_t); 161478d03361SPaul Saab 16153a31b7ebSMike Smith /* free the controller data */ 16163a31b7ebSMike Smith if (sc->ciss_id != NULL) 16173a31b7ebSMike Smith free(sc->ciss_id, CISS_MALLOC_CLASS); 16183a31b7ebSMike Smith 16193a31b7ebSMike Smith /* release I/O resources */ 16203a31b7ebSMike Smith if (sc->ciss_regs_resource != NULL) 16213a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, 16223a31b7ebSMike Smith sc->ciss_regs_rid, sc->ciss_regs_resource); 16233a31b7ebSMike Smith if (sc->ciss_cfg_resource != NULL) 16243a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_MEMORY, 16253a31b7ebSMike Smith sc->ciss_cfg_rid, sc->ciss_cfg_resource); 16263a31b7ebSMike Smith if (sc->ciss_intr != NULL) 16273a31b7ebSMike Smith bus_teardown_intr(sc->ciss_dev, sc->ciss_irq_resource, sc->ciss_intr); 16283a31b7ebSMike Smith if (sc->ciss_irq_resource != NULL) 16293a31b7ebSMike Smith bus_release_resource(sc->ciss_dev, SYS_RES_IRQ, 16303a31b7ebSMike Smith sc->ciss_irq_rid, sc->ciss_irq_resource); 16313a31b7ebSMike Smith 16323a31b7ebSMike Smith /* destroy DMA tags */ 16333a31b7ebSMike Smith if (sc->ciss_parent_dmat) 16343a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_parent_dmat); 16353284b9eeSPaul Saab 16363284b9eeSPaul Saab while ((cr = ciss_dequeue_free(sc)) != NULL) 16373284b9eeSPaul Saab bus_dmamap_destroy(sc->ciss_buffer_dmat, cr->cr_datamap); 16383a31b7ebSMike Smith if (sc->ciss_buffer_dmat) 16393a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_buffer_dmat); 16403a31b7ebSMike Smith 16413a31b7ebSMike Smith /* destroy command memory and DMA tag */ 16423a31b7ebSMike Smith if (sc->ciss_command != NULL) { 16433a31b7ebSMike Smith bus_dmamap_unload(sc->ciss_command_dmat, sc->ciss_command_map); 16443a31b7ebSMike Smith bus_dmamem_free(sc->ciss_command_dmat, sc->ciss_command, sc->ciss_command_map); 16453a31b7ebSMike Smith } 16463284b9eeSPaul Saab if (sc->ciss_command_dmat) 16473a31b7ebSMike Smith bus_dma_tag_destroy(sc->ciss_command_dmat); 16483a31b7ebSMike Smith 16493a31b7ebSMike Smith /* disconnect from CAM */ 16503a31b7ebSMike Smith if (sc->ciss_cam_sim) { 16511fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 16521fe6c4eeSScott Long if (sc->ciss_cam_sim[i]) { 16531fe6c4eeSScott Long xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); 16541fe6c4eeSScott Long cam_sim_free(sc->ciss_cam_sim[i], 0); 16551fe6c4eeSScott Long } 16561fe6c4eeSScott Long } 16571fe6c4eeSScott Long for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 16581fe6c4eeSScott Long CISS_PHYSICAL_BASE; i++) { 1659c6131460SPaul Saab if (sc->ciss_cam_sim[i]) { 1660c6131460SPaul Saab xpt_bus_deregister(cam_sim_path(sc->ciss_cam_sim[i])); 1661c6131460SPaul Saab cam_sim_free(sc->ciss_cam_sim[i], 0); 1662c6131460SPaul Saab } 1663c6131460SPaul Saab } 1664c6131460SPaul Saab free(sc->ciss_cam_sim, CISS_MALLOC_CLASS); 16653a31b7ebSMike Smith } 16663a31b7ebSMike Smith if (sc->ciss_cam_devq) 16673a31b7ebSMike Smith cam_simq_free(sc->ciss_cam_devq); 1668c6131460SPaul Saab 1669c6131460SPaul Saab if (sc->ciss_logical) { 16701fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) 1671c6131460SPaul Saab free(sc->ciss_logical[i], CISS_MALLOC_CLASS); 1672c6131460SPaul Saab free(sc->ciss_logical, CISS_MALLOC_CLASS); 1673c6131460SPaul Saab } 1674c6131460SPaul Saab 16751fe6c4eeSScott Long if (sc->ciss_physical) { 16761fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_physical_bus; i++) 16771fe6c4eeSScott Long free(sc->ciss_physical[i], CISS_MALLOC_CLASS); 16781fe6c4eeSScott Long free(sc->ciss_physical, CISS_MALLOC_CLASS); 16791fe6c4eeSScott Long } 16801fe6c4eeSScott Long 1681c6131460SPaul Saab if (sc->ciss_controllers) 1682c6131460SPaul Saab free(sc->ciss_controllers, CISS_MALLOC_CLASS); 16833a31b7ebSMike Smith } 16843a31b7ebSMike Smith 16853a31b7ebSMike Smith /************************************************************************ 16863a31b7ebSMike Smith * Give a command to the adapter. 16873a31b7ebSMike Smith * 16883a31b7ebSMike Smith * Note that this uses the simple transport layer directly. If we 16893a31b7ebSMike Smith * want to add support for other layers, we'll need a switch of some 16903a31b7ebSMike Smith * sort. 16913a31b7ebSMike Smith * 16923a31b7ebSMike Smith * Note that the simple transport layer has no way of refusing a 16933a31b7ebSMike Smith * command; we only have as many request structures as the adapter 16943a31b7ebSMike Smith * supports commands, so we don't have to check (this presumes that 16953a31b7ebSMike Smith * the adapter can handle commands as fast as we throw them at it). 16963a31b7ebSMike Smith */ 16973a31b7ebSMike Smith static int 16983a31b7ebSMike Smith ciss_start(struct ciss_request *cr) 16993a31b7ebSMike Smith { 17003a31b7ebSMike Smith struct ciss_command *cc; /* XXX debugging only */ 17013a31b7ebSMike Smith int error; 17023a31b7ebSMike Smith 17033a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 17043a31b7ebSMike Smith debug(2, "post command %d tag %d ", cr->cr_tag, cc->header.host_tag); 17053a31b7ebSMike Smith 17063a31b7ebSMike Smith /* 17073a31b7ebSMike Smith * Map the request's data. 17083a31b7ebSMike Smith */ 17093a31b7ebSMike Smith if ((error = ciss_map_request(cr))) 17103a31b7ebSMike Smith return(error); 17113a31b7ebSMike Smith 17123a31b7ebSMike Smith #if 0 17133a31b7ebSMike Smith ciss_print_request(cr); 17143a31b7ebSMike Smith #endif 17153a31b7ebSMike Smith 17163a31b7ebSMike Smith return(0); 17173a31b7ebSMike Smith } 17183a31b7ebSMike Smith 17193a31b7ebSMike Smith /************************************************************************ 17203a31b7ebSMike Smith * Fetch completed request(s) from the adapter, queue them for 17213a31b7ebSMike Smith * completion handling. 17223a31b7ebSMike Smith * 17233a31b7ebSMike Smith * Note that this uses the simple transport layer directly. If we 17243a31b7ebSMike Smith * want to add support for other layers, we'll need a switch of some 17253a31b7ebSMike Smith * sort. 17263a31b7ebSMike Smith * 17273a31b7ebSMike Smith * Note that the simple transport mechanism does not require any 17283a31b7ebSMike Smith * reentrancy protection; the OPQ read is atomic. If there is a 17293a31b7ebSMike Smith * chance of a race with something else that might move the request 17303a31b7ebSMike Smith * off the busy list, then we will have to lock against that 17313a31b7ebSMike Smith * (eg. timeouts, etc.) 17323a31b7ebSMike Smith */ 17333a31b7ebSMike Smith static void 17343a31b7ebSMike Smith ciss_done(struct ciss_softc *sc) 17353a31b7ebSMike Smith { 17363a31b7ebSMike Smith struct ciss_request *cr; 17373a31b7ebSMike Smith struct ciss_command *cc; 17383a31b7ebSMike Smith u_int32_t tag, index; 17393a31b7ebSMike Smith int complete; 17403a31b7ebSMike Smith 17413a31b7ebSMike Smith debug_called(3); 17423a31b7ebSMike Smith 17433a31b7ebSMike Smith /* 17443a31b7ebSMike Smith * Loop quickly taking requests from the adapter and moving them 17453a31b7ebSMike Smith * from the busy queue to the completed queue. 17463a31b7ebSMike Smith */ 17473a31b7ebSMike Smith complete = 0; 17483a31b7ebSMike Smith for (;;) { 17493a31b7ebSMike Smith 17503a31b7ebSMike Smith /* see if the OPQ contains anything */ 17513a31b7ebSMike Smith if (!CISS_TL_SIMPLE_OPQ_INTERRUPT(sc)) 17523a31b7ebSMike Smith break; 17533a31b7ebSMike Smith 17543a31b7ebSMike Smith tag = CISS_TL_SIMPLE_FETCH_CMD(sc); 17553a31b7ebSMike Smith if (tag == CISS_TL_SIMPLE_OPQ_EMPTY) 17563a31b7ebSMike Smith break; 17573a31b7ebSMike Smith index = tag >> 2; 17583a31b7ebSMike Smith debug(2, "completed command %d%s", index, 17593a31b7ebSMike Smith (tag & CISS_HDR_HOST_TAG_ERROR) ? " with error" : ""); 17603a31b7ebSMike Smith if (index >= sc->ciss_max_requests) { 17613a31b7ebSMike Smith ciss_printf(sc, "completed invalid request %d (0x%x)\n", index, tag); 17623a31b7ebSMike Smith continue; 17633a31b7ebSMike Smith } 17643a31b7ebSMike Smith cr = &(sc->ciss_request[index]); 17653a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 17663a31b7ebSMike Smith cc->header.host_tag = tag; /* not updated by adapter */ 17673a31b7ebSMike Smith if (ciss_remove_busy(cr)) { 17683a31b7ebSMike Smith /* assume this is garbage out of the adapter */ 17693a31b7ebSMike Smith ciss_printf(sc, "completed nonbusy request %d\n", index); 17703a31b7ebSMike Smith } else { 17713a31b7ebSMike Smith ciss_enqueue_complete(cr); 17723a31b7ebSMike Smith } 17733a31b7ebSMike Smith complete = 1; 17743a31b7ebSMike Smith } 17753a31b7ebSMike Smith 17763a31b7ebSMike Smith /* 17773a31b7ebSMike Smith * Invoke completion processing. If we can defer this out of 17783a31b7ebSMike Smith * interrupt context, that'd be good. 17793a31b7ebSMike Smith */ 17803a31b7ebSMike Smith if (complete) 17813a31b7ebSMike Smith ciss_complete(sc); 17823a31b7ebSMike Smith } 17833a31b7ebSMike Smith 17843a31b7ebSMike Smith /************************************************************************ 17853a31b7ebSMike Smith * Take an interrupt from the adapter. 17863a31b7ebSMike Smith */ 17873a31b7ebSMike Smith static void 17883a31b7ebSMike Smith ciss_intr(void *arg) 17893a31b7ebSMike Smith { 17903a31b7ebSMike Smith struct ciss_softc *sc = (struct ciss_softc *)arg; 17913a31b7ebSMike Smith 17923a31b7ebSMike Smith /* 17933a31b7ebSMike Smith * The only interrupt we recognise indicates that there are 17943a31b7ebSMike Smith * entries in the outbound post queue. 17953a31b7ebSMike Smith */ 17963a31b7ebSMike Smith ciss_done(sc); 17973a31b7ebSMike Smith } 17983a31b7ebSMike Smith 17993a31b7ebSMike Smith /************************************************************************ 18003a31b7ebSMike Smith * Process completed requests. 18013a31b7ebSMike Smith * 18023a31b7ebSMike Smith * Requests can be completed in three fashions: 18033a31b7ebSMike Smith * 18043a31b7ebSMike Smith * - by invoking a callback function (cr_complete is non-null) 18053a31b7ebSMike Smith * - by waking up a sleeper (cr_flags has CISS_REQ_SLEEP set) 18063a31b7ebSMike Smith * - by clearing the CISS_REQ_POLL flag in interrupt/timeout context 18073a31b7ebSMike Smith */ 18083a31b7ebSMike Smith static void 18093a31b7ebSMike Smith ciss_complete(struct ciss_softc *sc) 18103a31b7ebSMike Smith { 18113a31b7ebSMike Smith struct ciss_request *cr; 18123a31b7ebSMike Smith 18133a31b7ebSMike Smith debug_called(2); 18143a31b7ebSMike Smith 18153a31b7ebSMike Smith /* 18163a31b7ebSMike Smith * Loop taking requests off the completed queue and performing 18173a31b7ebSMike Smith * completion processing on them. 18183a31b7ebSMike Smith */ 18193a31b7ebSMike Smith for (;;) { 18203a31b7ebSMike Smith if ((cr = ciss_dequeue_complete(sc)) == NULL) 18213a31b7ebSMike Smith break; 18223a31b7ebSMike Smith ciss_unmap_request(cr); 18233a31b7ebSMike Smith 18243a31b7ebSMike Smith /* 18253a31b7ebSMike Smith * If the request has a callback, invoke it. 18263a31b7ebSMike Smith */ 18273a31b7ebSMike Smith if (cr->cr_complete != NULL) { 18283a31b7ebSMike Smith cr->cr_complete(cr); 18293a31b7ebSMike Smith continue; 18303a31b7ebSMike Smith } 18313a31b7ebSMike Smith 18323a31b7ebSMike Smith /* 18333a31b7ebSMike Smith * If someone is sleeping on this request, wake them up. 18343a31b7ebSMike Smith */ 18353a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_SLEEP) { 18363a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_SLEEP; 18373a31b7ebSMike Smith wakeup(cr); 18383a31b7ebSMike Smith continue; 18393a31b7ebSMike Smith } 18403a31b7ebSMike Smith 18413a31b7ebSMike Smith /* 18423a31b7ebSMike Smith * If someone is polling this request for completion, signal. 18433a31b7ebSMike Smith */ 18443a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_POLL) { 18453a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_POLL; 18463a31b7ebSMike Smith continue; 18473a31b7ebSMike Smith } 18483a31b7ebSMike Smith 18493a31b7ebSMike Smith /* 18503a31b7ebSMike Smith * Give up and throw the request back on the free queue. This 18513a31b7ebSMike Smith * should never happen; resources will probably be lost. 18523a31b7ebSMike Smith */ 18533a31b7ebSMike Smith ciss_printf(sc, "WARNING: completed command with no submitter\n"); 18543a31b7ebSMike Smith ciss_enqueue_free(cr); 18553a31b7ebSMike Smith } 18563a31b7ebSMike Smith } 18573a31b7ebSMike Smith 18583a31b7ebSMike Smith /************************************************************************ 18593a31b7ebSMike Smith * Report on the completion status of a request, and pass back SCSI 18603a31b7ebSMike Smith * and command status values. 18613a31b7ebSMike Smith */ 18623a31b7ebSMike Smith static int 18633a31b7ebSMike Smith ciss_report_request(struct ciss_request *cr, int *command_status, int *scsi_status) 18643a31b7ebSMike Smith { 18653a31b7ebSMike Smith struct ciss_command *cc; 18663a31b7ebSMike Smith struct ciss_error_info *ce; 18673a31b7ebSMike Smith 18683a31b7ebSMike Smith debug_called(2); 18693a31b7ebSMike Smith 18703a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 18713a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 18723a31b7ebSMike Smith 18733a31b7ebSMike Smith /* 18743a31b7ebSMike Smith * We don't consider data under/overrun an error for the Report 18753a31b7ebSMike Smith * Logical/Physical LUNs commands. 18763a31b7ebSMike Smith */ 18773a31b7ebSMike Smith if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) && 18783a31b7ebSMike Smith ((cc->cdb.cdb[0] == CISS_OPCODE_REPORT_LOGICAL_LUNS) || 18793a31b7ebSMike Smith (cc->cdb.cdb[0] == CISS_OPCODE_REPORT_PHYSICAL_LUNS))) { 18803a31b7ebSMike Smith cc->header.host_tag &= ~CISS_HDR_HOST_TAG_ERROR; 18813a31b7ebSMike Smith debug(2, "ignoring irrelevant under/overrun error"); 18823a31b7ebSMike Smith } 18833a31b7ebSMike Smith 18843a31b7ebSMike Smith /* 18853a31b7ebSMike Smith * Check the command's error bit, if clear, there's no status and 18863a31b7ebSMike Smith * everything is OK. 18873a31b7ebSMike Smith */ 18883a31b7ebSMike Smith if (!(cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR)) { 18893a31b7ebSMike Smith if (scsi_status != NULL) 18903a31b7ebSMike Smith *scsi_status = SCSI_STATUS_OK; 18913a31b7ebSMike Smith if (command_status != NULL) 18923a31b7ebSMike Smith *command_status = CISS_CMD_STATUS_SUCCESS; 18933a31b7ebSMike Smith return(0); 18943a31b7ebSMike Smith } else { 18953a31b7ebSMike Smith if (command_status != NULL) 18963a31b7ebSMike Smith *command_status = ce->command_status; 18973a31b7ebSMike Smith if (scsi_status != NULL) { 18983a31b7ebSMike Smith if (ce->command_status == CISS_CMD_STATUS_TARGET_STATUS) { 18993a31b7ebSMike Smith *scsi_status = ce->scsi_status; 19003a31b7ebSMike Smith } else { 19013a31b7ebSMike Smith *scsi_status = -1; 19023a31b7ebSMike Smith } 19033a31b7ebSMike Smith } 19043a31b7ebSMike Smith if (bootverbose) 19053a31b7ebSMike Smith ciss_printf(cr->cr_sc, "command status 0x%x (%s) scsi status 0x%x\n", 19063a31b7ebSMike Smith ce->command_status, ciss_name_command_status(ce->command_status), 19073a31b7ebSMike Smith ce->scsi_status); 19083a31b7ebSMike Smith if (ce->command_status == CISS_CMD_STATUS_INVALID_COMMAND) { 19093a31b7ebSMike Smith ciss_printf(cr->cr_sc, "invalid command, offense size %d at %d, value 0x%x\n", 19103a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_size, 19113a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_offset, 19123a31b7ebSMike Smith ce->additional_error_info.invalid_command.offense_value); 19133a31b7ebSMike Smith } 19143a31b7ebSMike Smith } 1915c6131460SPaul Saab #if 0 1916c6131460SPaul Saab ciss_print_request(cr); 1917c6131460SPaul Saab #endif 19183a31b7ebSMike Smith return(1); 19193a31b7ebSMike Smith } 19203a31b7ebSMike Smith 19213a31b7ebSMike Smith /************************************************************************ 19223a31b7ebSMike Smith * Issue a request and don't return until it's completed. 19233a31b7ebSMike Smith * 19243a31b7ebSMike Smith * Depending on adapter status, we may poll or sleep waiting for 19253a31b7ebSMike Smith * completion. 19263a31b7ebSMike Smith */ 19273a31b7ebSMike Smith static int 19283a31b7ebSMike Smith ciss_synch_request(struct ciss_request *cr, int timeout) 19293a31b7ebSMike Smith { 19303a31b7ebSMike Smith if (cr->cr_sc->ciss_flags & CISS_FLAG_RUNNING) { 19313a31b7ebSMike Smith return(ciss_wait_request(cr, timeout)); 19323a31b7ebSMike Smith } else { 19333a31b7ebSMike Smith return(ciss_poll_request(cr, timeout)); 19343a31b7ebSMike Smith } 19353a31b7ebSMike Smith } 19363a31b7ebSMike Smith 19373a31b7ebSMike Smith /************************************************************************ 19383a31b7ebSMike Smith * Issue a request and poll for completion. 19393a31b7ebSMike Smith * 19403a31b7ebSMike Smith * Timeout in milliseconds. 19413a31b7ebSMike Smith */ 19423a31b7ebSMike Smith static int 19433a31b7ebSMike Smith ciss_poll_request(struct ciss_request *cr, int timeout) 19443a31b7ebSMike Smith { 19453a31b7ebSMike Smith int error; 19463a31b7ebSMike Smith 19473a31b7ebSMike Smith debug_called(2); 19483a31b7ebSMike Smith 19493a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_POLL; 19503a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) 19513a31b7ebSMike Smith return(error); 19523a31b7ebSMike Smith 19533a31b7ebSMike Smith do { 19543a31b7ebSMike Smith ciss_done(cr->cr_sc); 19553a31b7ebSMike Smith if (!(cr->cr_flags & CISS_REQ_POLL)) 19563a31b7ebSMike Smith return(0); 19573a31b7ebSMike Smith DELAY(1000); 19583a31b7ebSMike Smith } while (timeout-- >= 0); 19593a31b7ebSMike Smith return(EWOULDBLOCK); 19603a31b7ebSMike Smith } 19613a31b7ebSMike Smith 19623a31b7ebSMike Smith /************************************************************************ 19633a31b7ebSMike Smith * Issue a request and sleep waiting for completion. 19643a31b7ebSMike Smith * 19653a31b7ebSMike Smith * Timeout in milliseconds. Note that a spurious wakeup will reset 19663a31b7ebSMike Smith * the timeout. 19673a31b7ebSMike Smith */ 19683a31b7ebSMike Smith static int 19693a31b7ebSMike Smith ciss_wait_request(struct ciss_request *cr, int timeout) 19703a31b7ebSMike Smith { 19713a31b7ebSMike Smith int s, error; 19723a31b7ebSMike Smith 19733a31b7ebSMike Smith debug_called(2); 19743a31b7ebSMike Smith 19753a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_SLEEP; 19763a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) 19773a31b7ebSMike Smith return(error); 19783a31b7ebSMike Smith 19793a31b7ebSMike Smith s = splcam(); 198040f05b02SPaul Saab while ((cr->cr_flags & CISS_REQ_SLEEP) && (error != EWOULDBLOCK)) { 198140f05b02SPaul Saab error = tsleep(cr, PRIBIO, "cissREQ", (timeout * hz) / 1000); 19823a31b7ebSMike Smith } 19833a31b7ebSMike Smith splx(s); 19843a31b7ebSMike Smith return(error); 19853a31b7ebSMike Smith } 19863a31b7ebSMike Smith 19876197ca15SPeter Wemm #if 0 19883a31b7ebSMike Smith /************************************************************************ 19893a31b7ebSMike Smith * Abort a request. Note that a potential exists here to race the 19903a31b7ebSMike Smith * request being completed; the caller must deal with this. 19913a31b7ebSMike Smith */ 19923a31b7ebSMike Smith static int 19933a31b7ebSMike Smith ciss_abort_request(struct ciss_request *ar) 19943a31b7ebSMike Smith { 19953a31b7ebSMike Smith struct ciss_request *cr; 19963a31b7ebSMike Smith struct ciss_command *cc; 19973a31b7ebSMike Smith struct ciss_message_cdb *cmc; 19983a31b7ebSMike Smith int error; 19993a31b7ebSMike Smith 20003a31b7ebSMike Smith debug_called(1); 20013a31b7ebSMike Smith 20023a31b7ebSMike Smith /* get a request */ 20033a31b7ebSMike Smith if ((error = ciss_get_request(ar->cr_sc, &cr)) != 0) 20043a31b7ebSMike Smith return(error); 20053a31b7ebSMike Smith 20063a31b7ebSMike Smith /* build the abort command */ 20073a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 20083a31b7ebSMike Smith cc->header.address.mode.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; /* addressing? */ 20093a31b7ebSMike Smith cc->header.address.physical.target = 0; 20103a31b7ebSMike Smith cc->header.address.physical.bus = 0; 20113a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cmc); 20123a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_MESSAGE; 20133a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 20143a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_NONE; 20153a31b7ebSMike Smith cc->cdb.timeout = 30; 20163a31b7ebSMike Smith 20173a31b7ebSMike Smith cmc = (struct ciss_message_cdb *)&(cc->cdb.cdb[0]); 20183a31b7ebSMike Smith cmc->opcode = CISS_OPCODE_MESSAGE_ABORT; 20193a31b7ebSMike Smith cmc->type = CISS_MESSAGE_ABORT_TASK; 20203a31b7ebSMike Smith cmc->abort_tag = ar->cr_tag; /* endianness?? */ 20213a31b7ebSMike Smith 20223a31b7ebSMike Smith /* 20233a31b7ebSMike Smith * Send the request and wait for a response. If we believe we 20243a31b7ebSMike Smith * aborted the request OK, clear the flag that indicates it's 20253a31b7ebSMike Smith * running. 20263a31b7ebSMike Smith */ 20273a31b7ebSMike Smith error = ciss_synch_request(cr, 35 * 1000); 20283a31b7ebSMike Smith if (!error) 20293a31b7ebSMike Smith error = ciss_report_request(cr, NULL, NULL); 20303a31b7ebSMike Smith ciss_release_request(cr); 20313a31b7ebSMike Smith 20323a31b7ebSMike Smith return(error); 20333a31b7ebSMike Smith } 20346197ca15SPeter Wemm #endif 20353a31b7ebSMike Smith 20363a31b7ebSMike Smith 20373a31b7ebSMike Smith /************************************************************************ 20383a31b7ebSMike Smith * Fetch and initialise a request 20393a31b7ebSMike Smith */ 20403a31b7ebSMike Smith static int 20413a31b7ebSMike Smith ciss_get_request(struct ciss_softc *sc, struct ciss_request **crp) 20423a31b7ebSMike Smith { 20433a31b7ebSMike Smith struct ciss_request *cr; 20443a31b7ebSMike Smith 20453a31b7ebSMike Smith debug_called(2); 20463a31b7ebSMike Smith 20473a31b7ebSMike Smith /* 20483a31b7ebSMike Smith * Get a request and clean it up. 20493a31b7ebSMike Smith */ 20503a31b7ebSMike Smith if ((cr = ciss_dequeue_free(sc)) == NULL) 20513a31b7ebSMike Smith return(ENOMEM); 20523a31b7ebSMike Smith 20533a31b7ebSMike Smith cr->cr_data = NULL; 20543a31b7ebSMike Smith cr->cr_flags = 0; 20553a31b7ebSMike Smith cr->cr_complete = NULL; 2056639717c8SPaul Saab cr->cr_private = NULL; 20573a31b7ebSMike Smith 20583a31b7ebSMike Smith ciss_preen_command(cr); 20593a31b7ebSMike Smith *crp = cr; 20603a31b7ebSMike Smith return(0); 20613a31b7ebSMike Smith } 20623a31b7ebSMike Smith 20633a31b7ebSMike Smith static void 20643a31b7ebSMike Smith ciss_preen_command(struct ciss_request *cr) 20653a31b7ebSMike Smith { 20663a31b7ebSMike Smith struct ciss_command *cc; 20673a31b7ebSMike Smith u_int32_t cmdphys; 20683a31b7ebSMike Smith 20693a31b7ebSMike Smith /* 20703a31b7ebSMike Smith * Clean up the command structure. 20713a31b7ebSMike Smith * 20723a31b7ebSMike Smith * Note that we set up the error_info structure here, since the 20733a31b7ebSMike Smith * length can be overwritten by any command. 20743a31b7ebSMike Smith */ 20753a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 20763a31b7ebSMike Smith cc->header.sg_in_list = 0; /* kinda inefficient this way */ 20773a31b7ebSMike Smith cc->header.sg_total = 0; 20783a31b7ebSMike Smith cc->header.host_tag = cr->cr_tag << 2; 20793a31b7ebSMike Smith cc->header.host_tag_zeroes = 0; 20803a31b7ebSMike Smith cmdphys = CISS_FIND_COMMANDPHYS(cr); 20813a31b7ebSMike Smith cc->error_info.error_info_address = cmdphys + sizeof(struct ciss_command); 20823a31b7ebSMike Smith cc->error_info.error_info_length = CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command); 20833a31b7ebSMike Smith } 20843a31b7ebSMike Smith 20853a31b7ebSMike Smith /************************************************************************ 20863a31b7ebSMike Smith * Release a request to the free list. 20873a31b7ebSMike Smith */ 20883a31b7ebSMike Smith static void 20893a31b7ebSMike Smith ciss_release_request(struct ciss_request *cr) 20903a31b7ebSMike Smith { 20913a31b7ebSMike Smith struct ciss_softc *sc; 20923a31b7ebSMike Smith 20933a31b7ebSMike Smith debug_called(2); 20943a31b7ebSMike Smith 20953a31b7ebSMike Smith sc = cr->cr_sc; 20963a31b7ebSMike Smith 20973a31b7ebSMike Smith /* release the request to the free queue */ 20983a31b7ebSMike Smith ciss_requeue_free(cr); 20993a31b7ebSMike Smith } 21003a31b7ebSMike Smith 21013a31b7ebSMike Smith /************************************************************************ 21023a31b7ebSMike Smith * Allocate a request that will be used to send a BMIC command. Do some 21033a31b7ebSMike Smith * of the common setup here to avoid duplicating it everywhere else. 21043a31b7ebSMike Smith */ 21053a31b7ebSMike Smith static int 21063a31b7ebSMike Smith ciss_get_bmic_request(struct ciss_softc *sc, struct ciss_request **crp, 21073a31b7ebSMike Smith int opcode, void **bufp, size_t bufsize) 21083a31b7ebSMike Smith { 21093a31b7ebSMike Smith struct ciss_request *cr; 21103a31b7ebSMike Smith struct ciss_command *cc; 21113a31b7ebSMike Smith struct ciss_bmic_cdb *cbc; 21123a31b7ebSMike Smith void *buf; 21133a31b7ebSMike Smith int error; 21143a31b7ebSMike Smith int dataout; 21153a31b7ebSMike Smith 21163a31b7ebSMike Smith debug_called(2); 21173a31b7ebSMike Smith 21183a31b7ebSMike Smith cr = NULL; 21193a31b7ebSMike Smith buf = NULL; 21203a31b7ebSMike Smith 21213a31b7ebSMike Smith /* 21223a31b7ebSMike Smith * Get a request. 21233a31b7ebSMike Smith */ 21243a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 21253a31b7ebSMike Smith goto out; 21263a31b7ebSMike Smith 21273a31b7ebSMike Smith /* 21283a31b7ebSMike Smith * Allocate data storage if requested, determine the data direction. 21293a31b7ebSMike Smith */ 21303a31b7ebSMike Smith dataout = 0; 21313a31b7ebSMike Smith if ((bufsize > 0) && (bufp != NULL)) { 21323a31b7ebSMike Smith if (*bufp == NULL) { 21333a31b7ebSMike Smith if ((buf = malloc(bufsize, CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO)) == NULL) { 21343a31b7ebSMike Smith error = ENOMEM; 21353a31b7ebSMike Smith goto out; 21363a31b7ebSMike Smith } 21373a31b7ebSMike Smith } else { 21383a31b7ebSMike Smith buf = *bufp; 21393a31b7ebSMike Smith dataout = 1; /* we are given a buffer, so we are writing */ 21403a31b7ebSMike Smith } 21413a31b7ebSMike Smith } 21423a31b7ebSMike Smith 21433a31b7ebSMike Smith /* 21443a31b7ebSMike Smith * Build a CISS BMIC command to get the logical drive ID. 21453a31b7ebSMike Smith */ 21463a31b7ebSMike Smith cr->cr_data = buf; 21473a31b7ebSMike Smith cr->cr_length = bufsize; 21483a31b7ebSMike Smith if (!dataout) 21493a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 21503a31b7ebSMike Smith 21513a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 21523a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 21533a31b7ebSMike Smith cc->header.address.physical.bus = 0; 21543a31b7ebSMike Smith cc->header.address.physical.target = 0; 21553a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cbc); 21563a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 21573a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 21583a31b7ebSMike Smith cc->cdb.direction = dataout ? CISS_CDB_DIRECTION_WRITE : CISS_CDB_DIRECTION_READ; 21593a31b7ebSMike Smith cc->cdb.timeout = 0; 21603a31b7ebSMike Smith 21613a31b7ebSMike Smith cbc = (struct ciss_bmic_cdb *)&(cc->cdb.cdb[0]); 21623a31b7ebSMike Smith bzero(cbc, sizeof(*cbc)); 21633a31b7ebSMike Smith cbc->opcode = dataout ? CISS_ARRAY_CONTROLLER_WRITE : CISS_ARRAY_CONTROLLER_READ; 21643a31b7ebSMike Smith cbc->bmic_opcode = opcode; 21653a31b7ebSMike Smith cbc->size = htons((u_int16_t)bufsize); 21663a31b7ebSMike Smith 21673a31b7ebSMike Smith out: 21683a31b7ebSMike Smith if (error) { 21693a31b7ebSMike Smith if (cr != NULL) 21703a31b7ebSMike Smith ciss_release_request(cr); 21713a31b7ebSMike Smith if ((bufp != NULL) && (*bufp == NULL) && (buf != NULL)) 21723a31b7ebSMike Smith free(buf, CISS_MALLOC_CLASS); 21733a31b7ebSMike Smith } else { 21743a31b7ebSMike Smith *crp = cr; 21753a31b7ebSMike Smith if ((bufp != NULL) && (*bufp == NULL) && (buf != NULL)) 21763a31b7ebSMike Smith *bufp = buf; 21773a31b7ebSMike Smith } 21783a31b7ebSMike Smith return(error); 21793a31b7ebSMike Smith } 21803a31b7ebSMike Smith 21813a31b7ebSMike Smith /************************************************************************ 21823a31b7ebSMike Smith * Handle a command passed in from userspace. 21833a31b7ebSMike Smith */ 21843a31b7ebSMike Smith static int 21853a31b7ebSMike Smith ciss_user_command(struct ciss_softc *sc, IOCTL_Command_struct *ioc) 21863a31b7ebSMike Smith { 21873a31b7ebSMike Smith struct ciss_request *cr; 21883a31b7ebSMike Smith struct ciss_command *cc; 21893a31b7ebSMike Smith struct ciss_error_info *ce; 21903c63a8b4SPaul Saab int error = 0; 21913a31b7ebSMike Smith 21923a31b7ebSMike Smith debug_called(1); 21933a31b7ebSMike Smith 21943a31b7ebSMike Smith cr = NULL; 21953a31b7ebSMike Smith 21963a31b7ebSMike Smith /* 21973a31b7ebSMike Smith * Get a request. 21983a31b7ebSMike Smith */ 21993a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) 22003a31b7ebSMike Smith goto out; 22013a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 22023a31b7ebSMike Smith 22033a31b7ebSMike Smith /* 22043a31b7ebSMike Smith * Allocate an in-kernel databuffer if required, copy in user data. 22053a31b7ebSMike Smith */ 22063a31b7ebSMike Smith cr->cr_length = ioc->buf_size; 22073a31b7ebSMike Smith if (ioc->buf_size > 0) { 2208a163d034SWarner Losh if ((cr->cr_data = malloc(ioc->buf_size, CISS_MALLOC_CLASS, M_WAITOK)) == NULL) { 22093a31b7ebSMike Smith error = ENOMEM; 22103a31b7ebSMike Smith goto out; 22113a31b7ebSMike Smith } 22123a31b7ebSMike Smith if ((error = copyin(ioc->buf, cr->cr_data, ioc->buf_size))) { 22133a31b7ebSMike Smith debug(0, "copyin: bad data buffer %p/%d", ioc->buf, ioc->buf_size); 22143a31b7ebSMike Smith goto out; 22153a31b7ebSMike Smith } 22163a31b7ebSMike Smith } 22173a31b7ebSMike Smith 22183a31b7ebSMike Smith /* 22193a31b7ebSMike Smith * Build the request based on the user command. 22203a31b7ebSMike Smith */ 22213a31b7ebSMike Smith bcopy(&ioc->LUN_info, &cc->header.address, sizeof(cc->header.address)); 22223a31b7ebSMike Smith bcopy(&ioc->Request, &cc->cdb, sizeof(cc->cdb)); 22233a31b7ebSMike Smith 22243a31b7ebSMike Smith /* XXX anything else to populate here? */ 22253a31b7ebSMike Smith 22263a31b7ebSMike Smith /* 22273a31b7ebSMike Smith * Run the command. 22283a31b7ebSMike Smith */ 22293a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000))) { 22303a31b7ebSMike Smith debug(0, "request failed - %d", error); 22313a31b7ebSMike Smith goto out; 22323a31b7ebSMike Smith } 22333a31b7ebSMike Smith 22343a31b7ebSMike Smith /* 22353c63a8b4SPaul Saab * Check to see if the command succeeded. 22363a31b7ebSMike Smith */ 22373a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 22383c6b8353SPaul Saab if ((cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) == 0) 22393c63a8b4SPaul Saab bzero(ce, sizeof(*ce)); 22403c63a8b4SPaul Saab 22413c63a8b4SPaul Saab /* 22423c63a8b4SPaul Saab * Copy the results back to the user. 22433c63a8b4SPaul Saab */ 22443a31b7ebSMike Smith bcopy(ce, &ioc->error_info, sizeof(*ce)); 22453a31b7ebSMike Smith if ((ioc->buf_size > 0) && 22463a31b7ebSMike Smith (error = copyout(cr->cr_data, ioc->buf, ioc->buf_size))) { 22473a31b7ebSMike Smith debug(0, "copyout: bad data buffer %p/%d", ioc->buf, ioc->buf_size); 22483a31b7ebSMike Smith goto out; 22493a31b7ebSMike Smith } 22503a31b7ebSMike Smith 22513a31b7ebSMike Smith /* done OK */ 22523a31b7ebSMike Smith error = 0; 22533a31b7ebSMike Smith 22543a31b7ebSMike Smith out: 22553a31b7ebSMike Smith if ((cr != NULL) && (cr->cr_data != NULL)) 22563a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 22573a31b7ebSMike Smith if (cr != NULL) 22583a31b7ebSMike Smith ciss_release_request(cr); 22593a31b7ebSMike Smith return(error); 22603a31b7ebSMike Smith } 22613a31b7ebSMike Smith 22623a31b7ebSMike Smith /************************************************************************ 22633a31b7ebSMike Smith * Map a request into bus-visible space, initialise the scatter/gather 22643a31b7ebSMike Smith * list. 22653a31b7ebSMike Smith */ 22663a31b7ebSMike Smith static int 22673a31b7ebSMike Smith ciss_map_request(struct ciss_request *cr) 22683a31b7ebSMike Smith { 22693a31b7ebSMike Smith struct ciss_softc *sc; 2270639717c8SPaul Saab int error = 0; 22713a31b7ebSMike Smith 22723a31b7ebSMike Smith debug_called(2); 22733a31b7ebSMike Smith 22743a31b7ebSMike Smith sc = cr->cr_sc; 22753a31b7ebSMike Smith 22763a31b7ebSMike Smith /* check that mapping is necessary */ 2277639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_MAPPED) 22783a31b7ebSMike Smith return(0); 22793a31b7ebSMike Smith 22803a31b7ebSMike Smith cr->cr_flags |= CISS_REQ_MAPPED; 2281639717c8SPaul Saab 2282639717c8SPaul Saab bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, 2283639717c8SPaul Saab BUS_DMASYNC_PREWRITE); 2284639717c8SPaul Saab 2285639717c8SPaul Saab if (cr->cr_data != NULL) { 2286639717c8SPaul Saab error = bus_dmamap_load(sc->ciss_buffer_dmat, cr->cr_datamap, 2287639717c8SPaul Saab cr->cr_data, cr->cr_length, 2288639717c8SPaul Saab ciss_request_map_helper, cr, 0); 2289639717c8SPaul Saab if (error != 0) 2290639717c8SPaul Saab return (error); 2291639717c8SPaul Saab } else { 2292639717c8SPaul Saab /* 2293639717c8SPaul Saab * Post the command to the adapter. 2294639717c8SPaul Saab */ 2295639717c8SPaul Saab ciss_enqueue_busy(cr); 2296639717c8SPaul Saab CISS_TL_SIMPLE_POST_CMD(cr->cr_sc, CISS_FIND_COMMANDPHYS(cr)); 2297639717c8SPaul Saab } 2298639717c8SPaul Saab 22993a31b7ebSMike Smith return(0); 23003a31b7ebSMike Smith } 23013a31b7ebSMike Smith 23023a31b7ebSMike Smith static void 23033a31b7ebSMike Smith ciss_request_map_helper(void *arg, bus_dma_segment_t *segs, int nseg, int error) 23043a31b7ebSMike Smith { 23053a31b7ebSMike Smith struct ciss_command *cc; 2306639717c8SPaul Saab struct ciss_request *cr; 2307639717c8SPaul Saab struct ciss_softc *sc; 23083a31b7ebSMike Smith int i; 23093a31b7ebSMike Smith 23103a31b7ebSMike Smith debug_called(2); 23113a31b7ebSMike Smith 2312639717c8SPaul Saab cr = (struct ciss_request *)arg; 2313639717c8SPaul Saab sc = cr->cr_sc; 2314639717c8SPaul Saab cc = CISS_FIND_COMMAND(cr); 2315639717c8SPaul Saab 23163a31b7ebSMike Smith for (i = 0; i < nseg; i++) { 23173a31b7ebSMike Smith cc->sg[i].address = segs[i].ds_addr; 23183a31b7ebSMike Smith cc->sg[i].length = segs[i].ds_len; 23193a31b7ebSMike Smith cc->sg[i].extension = 0; 23203a31b7ebSMike Smith } 23213a31b7ebSMike Smith /* we leave the s/g table entirely within the command */ 23223a31b7ebSMike Smith cc->header.sg_in_list = nseg; 23233a31b7ebSMike Smith cc->header.sg_total = nseg; 2324639717c8SPaul Saab 2325639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_DATAIN) 2326639717c8SPaul Saab bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREREAD); 2327639717c8SPaul Saab if (cr->cr_flags & CISS_REQ_DATAOUT) 2328639717c8SPaul Saab bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_PREWRITE); 2329639717c8SPaul Saab 2330639717c8SPaul Saab /* 2331639717c8SPaul Saab * Post the command to the adapter. 2332639717c8SPaul Saab */ 2333639717c8SPaul Saab ciss_enqueue_busy(cr); 2334639717c8SPaul Saab CISS_TL_SIMPLE_POST_CMD(cr->cr_sc, CISS_FIND_COMMANDPHYS(cr)); 23353a31b7ebSMike Smith } 23363a31b7ebSMike Smith 23373a31b7ebSMike Smith /************************************************************************ 23383a31b7ebSMike Smith * Unmap a request from bus-visible space. 23393a31b7ebSMike Smith */ 23403a31b7ebSMike Smith static void 23413a31b7ebSMike Smith ciss_unmap_request(struct ciss_request *cr) 23423a31b7ebSMike Smith { 23433a31b7ebSMike Smith struct ciss_softc *sc; 23443a31b7ebSMike Smith 23453a31b7ebSMike Smith debug_called(2); 23463a31b7ebSMike Smith 23473a31b7ebSMike Smith sc = cr->cr_sc; 23483a31b7ebSMike Smith 23493a31b7ebSMike Smith /* check that unmapping is necessary */ 2350639717c8SPaul Saab if ((cr->cr_flags & CISS_REQ_MAPPED) == 0) 23513a31b7ebSMike Smith return; 23523a31b7ebSMike Smith 2353639717c8SPaul Saab bus_dmamap_sync(sc->ciss_command_dmat, sc->ciss_command_map, 2354639717c8SPaul Saab BUS_DMASYNC_POSTWRITE); 2355639717c8SPaul Saab 2356639717c8SPaul Saab if (cr->cr_data == NULL) 2357639717c8SPaul Saab goto out; 2358639717c8SPaul Saab 23593a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_DATAIN) 23603a31b7ebSMike Smith bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTREAD); 23613a31b7ebSMike Smith if (cr->cr_flags & CISS_REQ_DATAOUT) 23623a31b7ebSMike Smith bus_dmamap_sync(sc->ciss_buffer_dmat, cr->cr_datamap, BUS_DMASYNC_POSTWRITE); 23633a31b7ebSMike Smith 23643a31b7ebSMike Smith bus_dmamap_unload(sc->ciss_buffer_dmat, cr->cr_datamap); 2365639717c8SPaul Saab out: 23663a31b7ebSMike Smith cr->cr_flags &= ~CISS_REQ_MAPPED; 23673a31b7ebSMike Smith } 23683a31b7ebSMike Smith 23693a31b7ebSMike Smith /************************************************************************ 23703a31b7ebSMike Smith * Attach the driver to CAM. 23713a31b7ebSMike Smith * 23723a31b7ebSMike Smith * We put all the logical drives on a single SCSI bus. 23733a31b7ebSMike Smith */ 23743a31b7ebSMike Smith static int 23753a31b7ebSMike Smith ciss_cam_init(struct ciss_softc *sc) 23763a31b7ebSMike Smith { 23771fe6c4eeSScott Long int i, maxbus; 23783a31b7ebSMike Smith 23793a31b7ebSMike Smith debug_called(1); 23803a31b7ebSMike Smith 23813a31b7ebSMike Smith /* 23823a31b7ebSMike Smith * Allocate a devq. We can reuse this for the masked physical 23833a31b7ebSMike Smith * devices if we decide to export these as well. 23843a31b7ebSMike Smith */ 23853a31b7ebSMike Smith if ((sc->ciss_cam_devq = cam_simq_alloc(sc->ciss_max_requests)) == NULL) { 23863a31b7ebSMike Smith ciss_printf(sc, "can't allocate CAM SIM queue\n"); 23873a31b7ebSMike Smith return(ENOMEM); 23883a31b7ebSMike Smith } 23893a31b7ebSMike Smith 23903a31b7ebSMike Smith /* 23913a31b7ebSMike Smith * Create a SIM. 23921fe6c4eeSScott Long * 23931fe6c4eeSScott Long * This naturally wastes a bit of memory. The alternative is to allocate 23941fe6c4eeSScott Long * and register each bus as it is found, and then track them on a linked 23951fe6c4eeSScott Long * list. Unfortunately, the driver has a few places where it needs to 23961fe6c4eeSScott Long * look up the SIM based solely on bus number, and it's unclear whether 23971fe6c4eeSScott Long * a list traversal would work for these situations. 23983a31b7ebSMike Smith */ 23991fe6c4eeSScott Long maxbus = max(sc->ciss_max_logical_bus, sc->ciss_max_physical_bus + 24001fe6c4eeSScott Long CISS_PHYSICAL_BASE); 24011fe6c4eeSScott Long sc->ciss_cam_sim = malloc(maxbus * sizeof(struct cam_sim*), 2402c6131460SPaul Saab CISS_MALLOC_CLASS, M_NOWAIT | M_ZERO); 2403c6131460SPaul Saab if (sc->ciss_cam_sim == NULL) { 2404c6131460SPaul Saab ciss_printf(sc, "can't allocate memory for controller SIM\n"); 2405c6131460SPaul Saab return(ENOMEM); 2406c6131460SPaul Saab } 2407c6131460SPaul Saab 24081fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 2409c6131460SPaul Saab if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, 2410c6131460SPaul Saab "ciss", sc, 24112aa6b972SPaul Saab device_get_unit(sc->ciss_dev), 2412d4aa427fSPaul Saab sc->ciss_max_requests - 2, 24132aa6b972SPaul Saab 1, 24143a31b7ebSMike Smith sc->ciss_cam_devq)) == NULL) { 2415c6131460SPaul Saab ciss_printf(sc, "can't allocate CAM SIM for controller %d\n", i); 24163a31b7ebSMike Smith return(ENOMEM); 24173a31b7ebSMike Smith } 24183a31b7ebSMike Smith 24193a31b7ebSMike Smith /* 2420c6131460SPaul Saab * Register bus with this SIM. 24213a31b7ebSMike Smith */ 24221fe6c4eeSScott Long if (i == 0 || sc->ciss_controllers[i].physical.bus != 0) { 24231fe6c4eeSScott Long if (xpt_bus_register(sc->ciss_cam_sim[i], i) != 0) { 24241fe6c4eeSScott Long ciss_printf(sc, "can't register SCSI bus %d\n", i); 24251fe6c4eeSScott Long return (ENXIO); 24261fe6c4eeSScott Long } 24271fe6c4eeSScott Long } 24281fe6c4eeSScott Long } 24291fe6c4eeSScott Long 24301fe6c4eeSScott Long for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 24311fe6c4eeSScott Long CISS_PHYSICAL_BASE; i++) { 24321fe6c4eeSScott Long if ((sc->ciss_cam_sim[i] = cam_sim_alloc(ciss_cam_action, ciss_cam_poll, 24331fe6c4eeSScott Long "ciss", sc, 24341fe6c4eeSScott Long device_get_unit(sc->ciss_dev), 24351fe6c4eeSScott Long sc->ciss_max_requests - 2, 24361fe6c4eeSScott Long 1, 24371fe6c4eeSScott Long sc->ciss_cam_devq)) == NULL) { 24381fe6c4eeSScott Long ciss_printf(sc, "can't allocate CAM SIM for controller %d\n", i); 24391fe6c4eeSScott Long return (ENOMEM); 24401fe6c4eeSScott Long } 24411fe6c4eeSScott Long 24421fe6c4eeSScott Long if (xpt_bus_register(sc->ciss_cam_sim[i], i) != 0) { 2443c6131460SPaul Saab ciss_printf(sc, "can't register SCSI bus %d\n", i); 24443a31b7ebSMike Smith return (ENXIO); 24453a31b7ebSMike Smith } 2446c6131460SPaul Saab } 24473a31b7ebSMike Smith 24483a31b7ebSMike Smith /* 24493a31b7ebSMike Smith * Initiate a rescan of the bus. 24503a31b7ebSMike Smith */ 24513a31b7ebSMike Smith ciss_cam_rescan_all(sc); 24523a31b7ebSMike Smith 24533a31b7ebSMike Smith return(0); 24543a31b7ebSMike Smith } 24553a31b7ebSMike Smith 24563a31b7ebSMike Smith /************************************************************************ 24573a31b7ebSMike Smith * Initiate a rescan of the 'logical devices' SIM 24583a31b7ebSMike Smith */ 24593a31b7ebSMike Smith static void 2460c6131460SPaul Saab ciss_cam_rescan_target(struct ciss_softc *sc, int bus, int target) 24613a31b7ebSMike Smith { 2462c6131460SPaul Saab struct cam_path *path; 24633a31b7ebSMike Smith union ccb *ccb; 24643a31b7ebSMike Smith 24653a31b7ebSMike Smith debug_called(1); 24663a31b7ebSMike Smith 2467a163d034SWarner Losh if ((ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO)) == NULL) { 24683a31b7ebSMike Smith ciss_printf(sc, "rescan failed (can't allocate CCB)\n"); 24693a31b7ebSMike Smith return; 24703a31b7ebSMike Smith } 24713a31b7ebSMike Smith 2472c6131460SPaul Saab if (xpt_create_path(&path, xpt_periph, cam_sim_path(sc->ciss_cam_sim[bus]), 2473c6131460SPaul Saab target, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 24743a31b7ebSMike Smith ciss_printf(sc, "rescan failed (can't create path)\n"); 24754c7ca6e5SRuslan Ermilov free(ccb, M_TEMP); 24763a31b7ebSMike Smith return; 24773a31b7ebSMike Smith } 24783a31b7ebSMike Smith 2479c6131460SPaul Saab xpt_setup_ccb(&ccb->ccb_h, path, 5/*priority (low)*/); 24803a31b7ebSMike Smith ccb->ccb_h.func_code = XPT_SCAN_BUS; 24813a31b7ebSMike Smith ccb->ccb_h.cbfcnp = ciss_cam_rescan_callback; 24823a31b7ebSMike Smith ccb->crcn.flags = CAM_FLAG_NONE; 24833a31b7ebSMike Smith xpt_action(ccb); 24843a31b7ebSMike Smith 24853a31b7ebSMike Smith /* scan is now in progress */ 24863a31b7ebSMike Smith } 24873a31b7ebSMike Smith 24883a31b7ebSMike Smith static void 24893a31b7ebSMike Smith ciss_cam_rescan_all(struct ciss_softc *sc) 24903a31b7ebSMike Smith { 2491c6131460SPaul Saab int i; 2492c6131460SPaul Saab 24931fe6c4eeSScott Long /* Rescan the logical buses */ 24941fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) 24951fe6c4eeSScott Long ciss_cam_rescan_target(sc, i, CAM_TARGET_WILDCARD); 24961fe6c4eeSScott Long /* Rescan the physical buses */ 249767688644SPaul Saab for (i = CISS_PHYSICAL_BASE; i < sc->ciss_max_physical_bus + 24981fe6c4eeSScott Long CISS_PHYSICAL_BASE; i++) 2499c6131460SPaul Saab ciss_cam_rescan_target(sc, i, CAM_TARGET_WILDCARD); 25003a31b7ebSMike Smith } 25013a31b7ebSMike Smith 25023a31b7ebSMike Smith static void 25033a31b7ebSMike Smith ciss_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb) 25043a31b7ebSMike Smith { 2505e010b6bcSPaul Saab xpt_free_path(ccb->ccb_h.path); 25063a31b7ebSMike Smith free(ccb, M_TEMP); 25073a31b7ebSMike Smith } 25083a31b7ebSMike Smith 25093a31b7ebSMike Smith /************************************************************************ 25103a31b7ebSMike Smith * Handle requests coming from CAM 25113a31b7ebSMike Smith */ 25123a31b7ebSMike Smith static void 25133a31b7ebSMike Smith ciss_cam_action(struct cam_sim *sim, union ccb *ccb) 25143a31b7ebSMike Smith { 2515440baa08SPaul Saab struct ciss_softc *sc; 2516440baa08SPaul Saab struct ccb_scsiio *csio; 2517c6131460SPaul Saab int bus, target; 25181fe6c4eeSScott Long int physical; 2519440baa08SPaul Saab 2520440baa08SPaul Saab sc = cam_sim_softc(sim); 2521c6131460SPaul Saab bus = cam_sim_bus(sim); 2522440baa08SPaul Saab csio = (struct ccb_scsiio *)&ccb->csio; 2523440baa08SPaul Saab target = csio->ccb_h.target_id; 25241fe6c4eeSScott Long physical = CISS_IS_PHYSICAL(bus); 2525440baa08SPaul Saab 25263a31b7ebSMike Smith switch (ccb->ccb_h.func_code) { 25273a31b7ebSMike Smith 25283a31b7ebSMike Smith /* perform SCSI I/O */ 25293a31b7ebSMike Smith case XPT_SCSI_IO: 2530440baa08SPaul Saab if (!ciss_cam_action_io(sim, csio)) 25313a31b7ebSMike Smith return; 25323a31b7ebSMike Smith break; 25333a31b7ebSMike Smith 25343a31b7ebSMike Smith /* perform geometry calculations */ 25353a31b7ebSMike Smith case XPT_CALC_GEOMETRY: 25363a31b7ebSMike Smith { 25373a31b7ebSMike Smith struct ccb_calc_geometry *ccg = &ccb->ccg; 25381fe6c4eeSScott Long struct ciss_ldrive *ld; 25393a31b7ebSMike Smith 25403a31b7ebSMike Smith debug(1, "XPT_CALC_GEOMETRY %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 25413a31b7ebSMike Smith 25421fe6c4eeSScott Long ld = NULL; 25431fe6c4eeSScott Long if (!physical) 25441fe6c4eeSScott Long ld = &sc->ciss_logical[bus][target]; 25451fe6c4eeSScott Long 25463a31b7ebSMike Smith /* 2547440baa08SPaul Saab * Use the cached geometry settings unless the fault tolerance 2548440baa08SPaul Saab * is invalid. 25493a31b7ebSMike Smith */ 25501fe6c4eeSScott Long if (physical || ld->cl_geometry.fault_tolerance == 0xFF) { 2551440baa08SPaul Saab u_int32_t secs_per_cylinder; 2552440baa08SPaul Saab 25533a31b7ebSMike Smith ccg->heads = 255; 25543a31b7ebSMike Smith ccg->secs_per_track = 32; 25553a31b7ebSMike Smith secs_per_cylinder = ccg->heads * ccg->secs_per_track; 25563a31b7ebSMike Smith ccg->cylinders = ccg->volume_size / secs_per_cylinder; 2557440baa08SPaul Saab } else { 2558440baa08SPaul Saab ccg->heads = ld->cl_geometry.heads; 2559440baa08SPaul Saab ccg->secs_per_track = ld->cl_geometry.sectors; 2560440baa08SPaul Saab ccg->cylinders = ntohs(ld->cl_geometry.cylinders); 2561440baa08SPaul Saab } 25623a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_CMP; 25633a31b7ebSMike Smith break; 25643a31b7ebSMike Smith } 25653a31b7ebSMike Smith 25663a31b7ebSMike Smith /* handle path attribute inquiry */ 25673a31b7ebSMike Smith case XPT_PATH_INQ: 25683a31b7ebSMike Smith { 25693a31b7ebSMike Smith struct ccb_pathinq *cpi = &ccb->cpi; 25703a31b7ebSMike Smith 25713a31b7ebSMike Smith debug(1, "XPT_PATH_INQ %d:%d:%d", cam_sim_bus(sim), ccb->ccb_h.target_id, ccb->ccb_h.target_lun); 25723a31b7ebSMike Smith 25733a31b7ebSMike Smith cpi->version_num = 1; 25743a31b7ebSMike Smith cpi->hba_inquiry = PI_TAG_ABLE; /* XXX is this correct? */ 25753a31b7ebSMike Smith cpi->target_sprt = 0; 25763a31b7ebSMike Smith cpi->hba_misc = 0; 25773a31b7ebSMike Smith cpi->max_target = CISS_MAX_LOGICAL; 25783a31b7ebSMike Smith cpi->max_lun = 0; /* 'logical drive' channel only */ 25793a31b7ebSMike Smith cpi->initiator_id = CISS_MAX_LOGICAL; 25803a31b7ebSMike Smith strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 25813a31b7ebSMike Smith strncpy(cpi->hba_vid, "msmith@freebsd.org", HBA_IDLEN); 25823a31b7ebSMike Smith strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 25833a31b7ebSMike Smith cpi->unit_number = cam_sim_unit(sim); 25843a31b7ebSMike Smith cpi->bus_id = cam_sim_bus(sim); 25853a31b7ebSMike Smith cpi->base_transfer_speed = 132 * 1024; /* XXX what to set this to? */ 25863a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_CMP; 25873a31b7ebSMike Smith break; 25883a31b7ebSMike Smith } 25893a31b7ebSMike Smith 25903a31b7ebSMike Smith case XPT_GET_TRAN_SETTINGS: 25913a31b7ebSMike Smith { 25923a31b7ebSMike Smith struct ccb_trans_settings *cts = &ccb->cts; 25933a31b7ebSMike Smith int bus, target; 25943a31b7ebSMike Smith 25953a31b7ebSMike Smith bus = cam_sim_bus(sim); 25963a31b7ebSMike Smith target = cts->ccb_h.target_id; 25973a31b7ebSMike Smith 25983a31b7ebSMike Smith debug(1, "XPT_GET_TRAN_SETTINGS %d:%d", bus, target); 25993a31b7ebSMike Smith cts->valid = 0; 26003a31b7ebSMike Smith 26013a31b7ebSMike Smith /* disconnect always OK */ 26023a31b7ebSMike Smith cts->flags |= CCB_TRANS_DISC_ENB; 26033a31b7ebSMike Smith cts->valid |= CCB_TRANS_DISC_VALID; 26043a31b7ebSMike Smith 26053a31b7ebSMike Smith cts->ccb_h.status = CAM_REQ_CMP; 26063a31b7ebSMike Smith break; 26073a31b7ebSMike Smith } 26083a31b7ebSMike Smith 26093a31b7ebSMike Smith default: /* we can't do this */ 26103a31b7ebSMike Smith debug(1, "unspported func_code = 0x%x", ccb->ccb_h.func_code); 26113a31b7ebSMike Smith ccb->ccb_h.status = CAM_REQ_INVALID; 26123a31b7ebSMike Smith break; 26133a31b7ebSMike Smith } 26143a31b7ebSMike Smith 26153a31b7ebSMike Smith xpt_done(ccb); 26163a31b7ebSMike Smith } 26173a31b7ebSMike Smith 26183a31b7ebSMike Smith /************************************************************************ 26193a31b7ebSMike Smith * Handle a CAM SCSI I/O request. 26203a31b7ebSMike Smith */ 26213a31b7ebSMike Smith static int 26223a31b7ebSMike Smith ciss_cam_action_io(struct cam_sim *sim, struct ccb_scsiio *csio) 26233a31b7ebSMike Smith { 26243a31b7ebSMike Smith struct ciss_softc *sc; 26253a31b7ebSMike Smith int bus, target; 26263a31b7ebSMike Smith struct ciss_request *cr; 26273a31b7ebSMike Smith struct ciss_command *cc; 26283a31b7ebSMike Smith int error; 26293a31b7ebSMike Smith 26303a31b7ebSMike Smith sc = cam_sim_softc(sim); 26313a31b7ebSMike Smith bus = cam_sim_bus(sim); 26323a31b7ebSMike Smith target = csio->ccb_h.target_id; 26333a31b7ebSMike Smith 26343a31b7ebSMike Smith debug(2, "XPT_SCSI_IO %d:%d:%d", bus, target, csio->ccb_h.target_lun); 26353a31b7ebSMike Smith 26363a31b7ebSMike Smith /* firmware does not support commands > 10 bytes */ 26373a31b7ebSMike Smith if (csio->cdb_len > 12/*CISS_CDB_BUFFER_SIZE*/) { 26383a31b7ebSMike Smith debug(3, " command too large (%d > %d)", csio->cdb_len, CISS_CDB_BUFFER_SIZE); 26393a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 26403a31b7ebSMike Smith } 26413a31b7ebSMike Smith 26423a31b7ebSMike Smith /* check that the CDB pointer is not to a physical address */ 26433a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_CDB_POINTER) && (csio->ccb_h.flags & CAM_CDB_PHYS)) { 26443a31b7ebSMike Smith debug(3, " CDB pointer is to physical address"); 26453a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 26463a31b7ebSMike Smith } 26473a31b7ebSMike Smith 26483a31b7ebSMike Smith /* if there is data transfer, it must be to/from a virtual address */ 26493a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 26503a31b7ebSMike Smith if (csio->ccb_h.flags & CAM_DATA_PHYS) { /* we can't map it */ 26513a31b7ebSMike Smith debug(3, " data pointer is to physical address"); 26523a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 26533a31b7ebSMike Smith } 26543a31b7ebSMike Smith if (csio->ccb_h.flags & CAM_SCATTER_VALID) { /* we want to do the s/g setup */ 26553a31b7ebSMike Smith debug(3, " data has premature s/g setup"); 26563a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 26573a31b7ebSMike Smith } 26583a31b7ebSMike Smith } 26593a31b7ebSMike Smith 26603a31b7ebSMike Smith /* abandon aborted ccbs or those that have failed validation */ 26613a31b7ebSMike Smith if ((csio->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) { 26623a31b7ebSMike Smith debug(3, "abandoning CCB due to abort/validation failure"); 26633a31b7ebSMike Smith return(EINVAL); 26643a31b7ebSMike Smith } 26653a31b7ebSMike Smith 26663a31b7ebSMike Smith /* handle emulation of some SCSI commands ourself */ 26673a31b7ebSMike Smith if (ciss_cam_emulate(sc, csio)) 26683a31b7ebSMike Smith return(0); 26693a31b7ebSMike Smith 26703a31b7ebSMike Smith /* 26713a31b7ebSMike Smith * Get a request to manage this command. If we can't, return the 26723a31b7ebSMike Smith * ccb, freeze the queue and flag so that we unfreeze it when a 26733a31b7ebSMike Smith * request completes. 26743a31b7ebSMike Smith */ 26753a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) { 26761fe6c4eeSScott Long xpt_freeze_simq(sim, 1); 26773a31b7ebSMike Smith csio->ccb_h.status |= CAM_REQUEUE_REQ; 26783a31b7ebSMike Smith return(error); 26793a31b7ebSMike Smith } 26803a31b7ebSMike Smith 26813a31b7ebSMike Smith /* 26823a31b7ebSMike Smith * Build the command. 26833a31b7ebSMike Smith */ 26843a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 26853a31b7ebSMike Smith cr->cr_data = csio->data_ptr; 26863a31b7ebSMike Smith cr->cr_length = csio->dxfer_len; 26873a31b7ebSMike Smith cr->cr_complete = ciss_cam_complete; 26883a31b7ebSMike Smith cr->cr_private = csio; 26893a31b7ebSMike Smith 2690c6131460SPaul Saab /* 2691c6131460SPaul Saab * Target the right logical volume. 2692c6131460SPaul Saab */ 26931fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) 26941fe6c4eeSScott Long cc->header.address = 26951fe6c4eeSScott Long sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_address; 26961fe6c4eeSScott Long else 26971fe6c4eeSScott Long cc->header.address = 26981fe6c4eeSScott Long sc->ciss_logical[bus][target].cl_address; 26993a31b7ebSMike Smith cc->cdb.cdb_length = csio->cdb_len; 27003a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 27013a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; /* XXX ordered tags? */ 27023a31b7ebSMike Smith if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) { 27033a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAOUT; 27043a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; 27053a31b7ebSMike Smith } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) { 27063a31b7ebSMike Smith cr->cr_flags = CISS_REQ_DATAIN; 27073a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 27083a31b7ebSMike Smith } else { 27093a31b7ebSMike Smith cr->cr_flags = 0; 27103a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_NONE; 27113a31b7ebSMike Smith } 27123a31b7ebSMike Smith cc->cdb.timeout = (csio->ccb_h.timeout / 1000) + 1; 27133a31b7ebSMike Smith if (csio->ccb_h.flags & CAM_CDB_POINTER) { 27143a31b7ebSMike Smith bcopy(csio->cdb_io.cdb_ptr, &cc->cdb.cdb[0], csio->cdb_len); 27153a31b7ebSMike Smith } else { 27163a31b7ebSMike Smith bcopy(csio->cdb_io.cdb_bytes, &cc->cdb.cdb[0], csio->cdb_len); 27173a31b7ebSMike Smith } 27183a31b7ebSMike Smith 27193a31b7ebSMike Smith /* 27203a31b7ebSMike Smith * Submit the request to the adapter. 27213a31b7ebSMike Smith * 27223a31b7ebSMike Smith * Note that this may fail if we're unable to map the request (and 27233a31b7ebSMike Smith * if we ever learn a transport layer other than simple, may fail 27243a31b7ebSMike Smith * if the adapter rejects the command). 27253a31b7ebSMike Smith */ 27263a31b7ebSMike Smith if ((error = ciss_start(cr)) != 0) { 27271fe6c4eeSScott Long xpt_freeze_simq(sim, 1); 2728639717c8SPaul Saab if (error == EINPROGRESS) { 2729639717c8SPaul Saab csio->ccb_h.status |= CAM_RELEASE_SIMQ; 2730639717c8SPaul Saab error = 0; 2731639717c8SPaul Saab } else { 27323a31b7ebSMike Smith csio->ccb_h.status |= CAM_REQUEUE_REQ; 27333a31b7ebSMike Smith ciss_release_request(cr); 2734639717c8SPaul Saab } 27353a31b7ebSMike Smith return(error); 27363a31b7ebSMike Smith } 27373a31b7ebSMike Smith 27383a31b7ebSMike Smith return(0); 27393a31b7ebSMike Smith } 27403a31b7ebSMike Smith 27413a31b7ebSMike Smith /************************************************************************ 27423a31b7ebSMike Smith * Emulate SCSI commands the adapter doesn't handle as we might like. 27433a31b7ebSMike Smith */ 27443a31b7ebSMike Smith static int 27453a31b7ebSMike Smith ciss_cam_emulate(struct ciss_softc *sc, struct ccb_scsiio *csio) 27463a31b7ebSMike Smith { 2747c6131460SPaul Saab int bus, target; 27483a31b7ebSMike Smith u_int8_t opcode; 27493a31b7ebSMike Smith 27503a31b7ebSMike Smith target = csio->ccb_h.target_id; 2751c6131460SPaul Saab bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); 27523a31b7ebSMike Smith opcode = (csio->ccb_h.flags & CAM_CDB_POINTER) ? 27533a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]; 27543a31b7ebSMike Smith 27551fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) { 27561fe6c4eeSScott Long if (sc->ciss_physical[CISS_CAM_TO_PBUS(bus)][target].cp_online != 1) { 27571fe6c4eeSScott Long csio->ccb_h.status = CAM_SEL_TIMEOUT; 27581fe6c4eeSScott Long xpt_done((union ccb *)csio); 27591fe6c4eeSScott Long return(1); 27601fe6c4eeSScott Long } else 27611fe6c4eeSScott Long return(0); 27621fe6c4eeSScott Long } 27631fe6c4eeSScott Long 27643a31b7ebSMike Smith /* 27656f71a953SPaul Saab * Handle requests for volumes that don't exist or are not online. 27666f71a953SPaul Saab * A selection timeout is slightly better than an illegal request. 27676f71a953SPaul Saab * Other errors might be better. 27683a31b7ebSMike Smith */ 27696f71a953SPaul Saab if (sc->ciss_logical[bus][target].cl_status != CISS_LD_ONLINE) { 27703a31b7ebSMike Smith csio->ccb_h.status = CAM_SEL_TIMEOUT; 27713a31b7ebSMike Smith xpt_done((union ccb *)csio); 27723a31b7ebSMike Smith return(1); 27733a31b7ebSMike Smith } 27743a31b7ebSMike Smith 27753a31b7ebSMike Smith /* if we have to fake Synchronise Cache */ 27763a31b7ebSMike Smith if (sc->ciss_flags & CISS_FLAG_FAKE_SYNCH) { 27773a31b7ebSMike Smith /* 27783a31b7ebSMike Smith * If this is a Synchronise Cache command, typically issued when 27793a31b7ebSMike Smith * a device is closed, flush the adapter and complete now. 27803a31b7ebSMike Smith */ 27813a31b7ebSMike Smith if (((csio->ccb_h.flags & CAM_CDB_POINTER) ? 27823a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) { 27833a31b7ebSMike Smith ciss_flush_adapter(sc); 27843a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP; 27853a31b7ebSMike Smith xpt_done((union ccb *)csio); 27863a31b7ebSMike Smith return(1); 27873a31b7ebSMike Smith } 27883a31b7ebSMike Smith } 27893a31b7ebSMike Smith 27903a31b7ebSMike Smith return(0); 27913a31b7ebSMike Smith } 27923a31b7ebSMike Smith 27933a31b7ebSMike Smith /************************************************************************ 27943a31b7ebSMike Smith * Check for possibly-completed commands. 27953a31b7ebSMike Smith */ 27963a31b7ebSMike Smith static void 27973a31b7ebSMike Smith ciss_cam_poll(struct cam_sim *sim) 27983a31b7ebSMike Smith { 27993a31b7ebSMike Smith struct ciss_softc *sc = cam_sim_softc(sim); 28003a31b7ebSMike Smith 28013a31b7ebSMike Smith debug_called(2); 28023a31b7ebSMike Smith 28033a31b7ebSMike Smith ciss_done(sc); 28043a31b7ebSMike Smith } 28053a31b7ebSMike Smith 28063a31b7ebSMike Smith /************************************************************************ 28073a31b7ebSMike Smith * Handle completion of a command - pass results back through the CCB 28083a31b7ebSMike Smith */ 28093a31b7ebSMike Smith static void 28103a31b7ebSMike Smith ciss_cam_complete(struct ciss_request *cr) 28113a31b7ebSMike Smith { 28123a31b7ebSMike Smith struct ciss_softc *sc; 28133a31b7ebSMike Smith struct ciss_command *cc; 28143a31b7ebSMike Smith struct ciss_error_info *ce; 28153a31b7ebSMike Smith struct ccb_scsiio *csio; 28163a31b7ebSMike Smith int scsi_status; 28173a31b7ebSMike Smith int command_status; 28183a31b7ebSMike Smith 28193a31b7ebSMike Smith debug_called(2); 28203a31b7ebSMike Smith 28213a31b7ebSMike Smith sc = cr->cr_sc; 28223a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 28233a31b7ebSMike Smith ce = (struct ciss_error_info *)&(cc->sg[0]); 28243a31b7ebSMike Smith csio = (struct ccb_scsiio *)cr->cr_private; 28253a31b7ebSMike Smith 28263a31b7ebSMike Smith /* 28273a31b7ebSMike Smith * Extract status values from request. 28283a31b7ebSMike Smith */ 28293a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 28303a31b7ebSMike Smith csio->scsi_status = scsi_status; 28313a31b7ebSMike Smith 28323a31b7ebSMike Smith /* 28333a31b7ebSMike Smith * Handle specific SCSI status values. 28343a31b7ebSMike Smith */ 28353a31b7ebSMike Smith switch(scsi_status) { 28363a31b7ebSMike Smith /* no status due to adapter error */ 28373a31b7ebSMike Smith case -1: 28383a31b7ebSMike Smith debug(0, "adapter error"); 28393a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 28403a31b7ebSMike Smith break; 28413a31b7ebSMike Smith 28423a31b7ebSMike Smith /* no status due to command completed OK */ 28433a31b7ebSMike Smith case SCSI_STATUS_OK: /* CISS_SCSI_STATUS_GOOD */ 28443a31b7ebSMike Smith debug(2, "SCSI_STATUS_OK"); 28453a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP; 28463a31b7ebSMike Smith break; 28473a31b7ebSMike Smith 28483a31b7ebSMike Smith /* check condition, sense data included */ 28493a31b7ebSMike Smith case SCSI_STATUS_CHECK_COND: /* CISS_SCSI_STATUS_CHECK_CONDITION */ 2850c6131460SPaul Saab debug(0, "SCSI_STATUS_CHECK_COND sense size %d resid %d\n", 28513a31b7ebSMike Smith ce->sense_length, ce->residual_count); 28523a31b7ebSMike Smith bzero(&csio->sense_data, SSD_FULL_SIZE); 28533a31b7ebSMike Smith bcopy(&ce->sense_info[0], &csio->sense_data, ce->sense_length); 28543a31b7ebSMike Smith csio->sense_len = ce->sense_length; 28553a31b7ebSMike Smith csio->resid = ce->residual_count; 28563a31b7ebSMike Smith csio->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; 28573a31b7ebSMike Smith #ifdef CISS_DEBUG 28583a31b7ebSMike Smith { 28593a31b7ebSMike Smith struct scsi_sense_data *sns = (struct scsi_sense_data *)&ce->sense_info[0]; 28603a31b7ebSMike Smith debug(0, "sense key %x", sns->flags & SSD_KEY); 28613a31b7ebSMike Smith } 28623a31b7ebSMike Smith #endif 28633a31b7ebSMike Smith break; 28643a31b7ebSMike Smith 28653a31b7ebSMike Smith case SCSI_STATUS_BUSY: /* CISS_SCSI_STATUS_BUSY */ 28663a31b7ebSMike Smith debug(0, "SCSI_STATUS_BUSY"); 28673a31b7ebSMike Smith csio->ccb_h.status = CAM_SCSI_BUSY; 28683a31b7ebSMike Smith break; 28693a31b7ebSMike Smith 28703a31b7ebSMike Smith default: 28713a31b7ebSMike Smith debug(0, "unknown status 0x%x", csio->scsi_status); 28723a31b7ebSMike Smith csio->ccb_h.status = CAM_REQ_CMP_ERR; 28733a31b7ebSMike Smith break; 28743a31b7ebSMike Smith } 28753a31b7ebSMike Smith 28763a31b7ebSMike Smith /* handle post-command fixup */ 28773a31b7ebSMike Smith ciss_cam_complete_fixup(sc, csio); 28783a31b7ebSMike Smith 2879d4aa427fSPaul Saab /* tell CAM we're ready for more commands */ 2880d4aa427fSPaul Saab csio->ccb_h.status |= CAM_RELEASE_SIMQ; 2881d4aa427fSPaul Saab 28823a31b7ebSMike Smith xpt_done((union ccb *)csio); 28833a31b7ebSMike Smith ciss_release_request(cr); 28843a31b7ebSMike Smith } 28853a31b7ebSMike Smith 28863a31b7ebSMike Smith /******************************************************************************** 28873a31b7ebSMike Smith * Fix up the result of some commands here. 28883a31b7ebSMike Smith */ 28893a31b7ebSMike Smith static void 28903a31b7ebSMike Smith ciss_cam_complete_fixup(struct ciss_softc *sc, struct ccb_scsiio *csio) 28913a31b7ebSMike Smith { 28923a31b7ebSMike Smith struct scsi_inquiry_data *inq; 28933a31b7ebSMike Smith struct ciss_ldrive *cl; 2894c6131460SPaul Saab int bus, target; 28953a31b7ebSMike Smith 28963a31b7ebSMike Smith if (((csio->ccb_h.flags & CAM_CDB_POINTER) ? 28973a31b7ebSMike Smith *(u_int8_t *)csio->cdb_io.cdb_ptr : csio->cdb_io.cdb_bytes[0]) == INQUIRY) { 28983a31b7ebSMike Smith 28993a31b7ebSMike Smith inq = (struct scsi_inquiry_data *)csio->data_ptr; 29003a31b7ebSMike Smith target = csio->ccb_h.target_id; 2901c6131460SPaul Saab bus = cam_sim_bus(xpt_path_sim(csio->ccb_h.path)); 29021fe6c4eeSScott Long 29031fe6c4eeSScott Long /* 29041fe6c4eeSScott Long * Don't let hard drives be seen by the DA driver. They will still be 29051fe6c4eeSScott Long * attached by the PASS driver. 29061fe6c4eeSScott Long */ 29071fe6c4eeSScott Long if (CISS_IS_PHYSICAL(bus)) { 29081fe6c4eeSScott Long if (SID_TYPE(inq) == T_DIRECT) 29091fe6c4eeSScott Long inq->device = (inq->device & 0xe0) | T_NODEVICE; 29101fe6c4eeSScott Long return; 29111fe6c4eeSScott Long } 29121fe6c4eeSScott Long 2913c6131460SPaul Saab cl = &sc->ciss_logical[bus][target]; 29143a31b7ebSMike Smith 2915d4aa427fSPaul Saab padstr(inq->vendor, "COMPAQ", 8); 2916d4aa427fSPaul Saab padstr(inq->product, ciss_name_ldrive_org(cl->cl_ldrive->fault_tolerance), 8); 2917d4aa427fSPaul Saab padstr(inq->revision, ciss_name_ldrive_status(cl->cl_lstatus->status), 16); 29183a31b7ebSMike Smith } 29193a31b7ebSMike Smith } 29203a31b7ebSMike Smith 29213a31b7ebSMike Smith 29223a31b7ebSMike Smith /******************************************************************************** 2923d4aa427fSPaul Saab * Find a peripheral attached at (target) 29243a31b7ebSMike Smith */ 29253a31b7ebSMike Smith static struct cam_periph * 2926c6131460SPaul Saab ciss_find_periph(struct ciss_softc *sc, int bus, int target) 29273a31b7ebSMike Smith { 29283a31b7ebSMike Smith struct cam_periph *periph; 29293a31b7ebSMike Smith struct cam_path *path; 29303a31b7ebSMike Smith int status; 29313a31b7ebSMike Smith 2932c6131460SPaul Saab status = xpt_create_path(&path, NULL, cam_sim_path(sc->ciss_cam_sim[bus]), 2933c6131460SPaul Saab target, 0); 29343a31b7ebSMike Smith if (status == CAM_REQ_CMP) { 29353a31b7ebSMike Smith periph = cam_periph_find(path, NULL); 29363a31b7ebSMike Smith xpt_free_path(path); 29373a31b7ebSMike Smith } else { 29383a31b7ebSMike Smith periph = NULL; 29393a31b7ebSMike Smith } 29403a31b7ebSMike Smith return(periph); 29413a31b7ebSMike Smith } 29423a31b7ebSMike Smith 29433a31b7ebSMike Smith /******************************************************************************** 29443a31b7ebSMike Smith * Name the device at (target) 29453a31b7ebSMike Smith * 29463a31b7ebSMike Smith * XXX is this strictly correct? 29473a31b7ebSMike Smith */ 294837c84183SPoul-Henning Kamp static int 2949c6131460SPaul Saab ciss_name_device(struct ciss_softc *sc, int bus, int target) 29503a31b7ebSMike Smith { 29513a31b7ebSMike Smith struct cam_periph *periph; 29523a31b7ebSMike Smith 2953d49f1379SPaul Saab if (CISS_IS_PHYSICAL(bus)) 29541fe6c4eeSScott Long return (0); 2955c6131460SPaul Saab if ((periph = ciss_find_periph(sc, bus, target)) != NULL) { 29561fe6c4eeSScott Long sprintf(sc->ciss_logical[bus][target].cl_name, "%s%d", 29571fe6c4eeSScott Long periph->periph_name, periph->unit_number); 29583a31b7ebSMike Smith return(0); 29593a31b7ebSMike Smith } 2960c6131460SPaul Saab sc->ciss_logical[bus][target].cl_name[0] = 0; 29613a31b7ebSMike Smith return(ENOENT); 29623a31b7ebSMike Smith } 29633a31b7ebSMike Smith 29643a31b7ebSMike Smith /************************************************************************ 29653a31b7ebSMike Smith * Periodic status monitoring. 29663a31b7ebSMike Smith */ 29673a31b7ebSMike Smith static void 29683a31b7ebSMike Smith ciss_periodic(void *arg) 29693a31b7ebSMike Smith { 29703a31b7ebSMike Smith struct ciss_softc *sc; 29713a31b7ebSMike Smith 29723a31b7ebSMike Smith debug_called(1); 29733a31b7ebSMike Smith 29743a31b7ebSMike Smith sc = (struct ciss_softc *)arg; 29753a31b7ebSMike Smith 29763a31b7ebSMike Smith /* 29773a31b7ebSMike Smith * Check the adapter heartbeat. 29783a31b7ebSMike Smith */ 29793a31b7ebSMike Smith if (sc->ciss_cfg->heartbeat == sc->ciss_heartbeat) { 29803a31b7ebSMike Smith sc->ciss_heart_attack++; 29813a31b7ebSMike Smith debug(0, "adapter heart attack in progress 0x%x/%d", 29823a31b7ebSMike Smith sc->ciss_heartbeat, sc->ciss_heart_attack); 29833a31b7ebSMike Smith if (sc->ciss_heart_attack == 3) { 29843a31b7ebSMike Smith ciss_printf(sc, "ADAPTER HEARTBEAT FAILED\n"); 29853a31b7ebSMike Smith /* XXX should reset adapter here */ 29863a31b7ebSMike Smith } 29873a31b7ebSMike Smith } else { 29883a31b7ebSMike Smith sc->ciss_heartbeat = sc->ciss_cfg->heartbeat; 29893a31b7ebSMike Smith sc->ciss_heart_attack = 0; 29903a31b7ebSMike Smith debug(3, "new heartbeat 0x%x", sc->ciss_heartbeat); 29913a31b7ebSMike Smith } 29923a31b7ebSMike Smith 29933a31b7ebSMike Smith /* 29943a31b7ebSMike Smith * If the notify event request has died for some reason, or has 29953a31b7ebSMike Smith * not started yet, restart it. 29963a31b7ebSMike Smith */ 29973a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) { 29983a31b7ebSMike Smith debug(0, "(re)starting Event Notify chain"); 29993a31b7ebSMike Smith ciss_notify_event(sc); 30003a31b7ebSMike Smith } 30013a31b7ebSMike Smith 30023a31b7ebSMike Smith /* 30033a31b7ebSMike Smith * Reschedule. 30043a31b7ebSMike Smith */ 30053a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_ABORTING)) 30063a31b7ebSMike Smith sc->ciss_periodic = timeout(ciss_periodic, sc, CISS_HEARTBEAT_RATE * hz); 30073a31b7ebSMike Smith } 30083a31b7ebSMike Smith 30093a31b7ebSMike Smith /************************************************************************ 30103a31b7ebSMike Smith * Request a notification response from the adapter. 30113a31b7ebSMike Smith * 30123a31b7ebSMike Smith * If (cr) is NULL, this is the first request of the adapter, so 30133a31b7ebSMike Smith * reset the adapter's message pointer and start with the oldest 30143a31b7ebSMike Smith * message available. 30153a31b7ebSMike Smith */ 30163a31b7ebSMike Smith static void 30173a31b7ebSMike Smith ciss_notify_event(struct ciss_softc *sc) 30183a31b7ebSMike Smith { 30193a31b7ebSMike Smith struct ciss_request *cr; 30203a31b7ebSMike Smith struct ciss_command *cc; 30213a31b7ebSMike Smith struct ciss_notify_cdb *cnc; 30223a31b7ebSMike Smith int error; 30233a31b7ebSMike Smith 30243a31b7ebSMike Smith debug_called(1); 30253a31b7ebSMike Smith 30263a31b7ebSMike Smith cr = sc->ciss_periodic_notify; 30273a31b7ebSMike Smith 30283a31b7ebSMike Smith /* get a request if we don't already have one */ 30293a31b7ebSMike Smith if (cr == NULL) { 30303a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr)) != 0) { 30313a31b7ebSMike Smith debug(0, "can't get notify event request"); 30323a31b7ebSMike Smith goto out; 30333a31b7ebSMike Smith } 30343a31b7ebSMike Smith sc->ciss_periodic_notify = cr; 30353a31b7ebSMike Smith cr->cr_complete = ciss_notify_complete; 30363a31b7ebSMike Smith debug(1, "acquired request %d", cr->cr_tag); 30373a31b7ebSMike Smith } 30383a31b7ebSMike Smith 30393a31b7ebSMike Smith /* 30403a31b7ebSMike Smith * Get a databuffer if we don't already have one, note that the 30413a31b7ebSMike Smith * adapter command wants a larger buffer than the actual 30423a31b7ebSMike Smith * structure. 30433a31b7ebSMike Smith */ 30443a31b7ebSMike Smith if (cr->cr_data == NULL) { 30453a31b7ebSMike Smith if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 30463a31b7ebSMike Smith debug(0, "can't get notify event request buffer"); 30473a31b7ebSMike Smith error = ENOMEM; 30483a31b7ebSMike Smith goto out; 30493a31b7ebSMike Smith } 30503a31b7ebSMike Smith cr->cr_length = CISS_NOTIFY_DATA_SIZE; 30513a31b7ebSMike Smith } 30523a31b7ebSMike Smith 30533a31b7ebSMike Smith /* re-setup the request's command (since we never release it) XXX overkill*/ 30543a31b7ebSMike Smith ciss_preen_command(cr); 30553a31b7ebSMike Smith 30563a31b7ebSMike Smith /* (re)build the notify event command */ 30573a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 30583a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 30593a31b7ebSMike Smith cc->header.address.physical.bus = 0; 30603a31b7ebSMike Smith cc->header.address.physical.target = 0; 30613a31b7ebSMike Smith 30623a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cnc); 30633a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 30643a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 30653a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 30663a31b7ebSMike Smith cc->cdb.timeout = 0; /* no timeout, we hope */ 30673a31b7ebSMike Smith 30683a31b7ebSMike Smith cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); 30693a31b7ebSMike Smith bzero(cr->cr_data, CISS_NOTIFY_DATA_SIZE); 30703a31b7ebSMike Smith cnc->opcode = CISS_OPCODE_READ; 30713a31b7ebSMike Smith cnc->command = CISS_COMMAND_NOTIFY_ON_EVENT; 30723a31b7ebSMike Smith cnc->timeout = 0; /* no timeout, we hope */ 30733a31b7ebSMike Smith cnc->synchronous = 0; 30743a31b7ebSMike Smith cnc->ordered = 0; 30753a31b7ebSMike Smith cnc->seek_to_oldest = 0; 30762e80ca8aSPaul Saab if ((sc->ciss_flags & CISS_FLAG_RUNNING) == 0) 30772e80ca8aSPaul Saab cnc->new_only = 1; 30782e80ca8aSPaul Saab else 30793a31b7ebSMike Smith cnc->new_only = 0; 30803a31b7ebSMike Smith cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); 30813a31b7ebSMike Smith 30823a31b7ebSMike Smith /* submit the request */ 30833a31b7ebSMike Smith error = ciss_start(cr); 30843a31b7ebSMike Smith 30853a31b7ebSMike Smith out: 30863a31b7ebSMike Smith if (error) { 30873a31b7ebSMike Smith if (cr != NULL) { 30883a31b7ebSMike Smith if (cr->cr_data != NULL) 30893a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 30903a31b7ebSMike Smith ciss_release_request(cr); 30913a31b7ebSMike Smith } 30923a31b7ebSMike Smith sc->ciss_periodic_notify = NULL; 30933a31b7ebSMike Smith debug(0, "can't submit notify event request"); 30943a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 30953a31b7ebSMike Smith } else { 30963a31b7ebSMike Smith debug(1, "notify event submitted"); 30973a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_NOTIFY_OK; 30983a31b7ebSMike Smith } 30993a31b7ebSMike Smith } 31003a31b7ebSMike Smith 31013a31b7ebSMike Smith static void 31023a31b7ebSMike Smith ciss_notify_complete(struct ciss_request *cr) 31033a31b7ebSMike Smith { 31043a31b7ebSMike Smith struct ciss_command *cc; 31053a31b7ebSMike Smith struct ciss_notify *cn; 31063a31b7ebSMike Smith struct ciss_softc *sc; 31073a31b7ebSMike Smith int scsi_status; 31083a31b7ebSMike Smith int command_status; 31093a31b7ebSMike Smith debug_called(1); 31103a31b7ebSMike Smith 31113a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 31123a31b7ebSMike Smith cn = (struct ciss_notify *)cr->cr_data; 31133a31b7ebSMike Smith sc = cr->cr_sc; 31143a31b7ebSMike Smith 31153a31b7ebSMike Smith /* 31163a31b7ebSMike Smith * Report request results, decode status. 31173a31b7ebSMike Smith */ 31183a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 31193a31b7ebSMike Smith 31203a31b7ebSMike Smith /* 31213a31b7ebSMike Smith * Abort the chain on a fatal error. 31223a31b7ebSMike Smith * 31233a31b7ebSMike Smith * XXX which of these are actually errors? 31243a31b7ebSMike Smith */ 31253a31b7ebSMike Smith if ((command_status != CISS_CMD_STATUS_SUCCESS) && 31263a31b7ebSMike Smith (command_status != CISS_CMD_STATUS_TARGET_STATUS) && 31273a31b7ebSMike Smith (command_status != CISS_CMD_STATUS_TIMEOUT)) { /* XXX timeout? */ 31283a31b7ebSMike Smith ciss_printf(sc, "fatal error in Notify Event request (%s)\n", 31293a31b7ebSMike Smith ciss_name_command_status(command_status)); 31303a31b7ebSMike Smith ciss_release_request(cr); 31313a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 31323a31b7ebSMike Smith return; 31333a31b7ebSMike Smith } 31343a31b7ebSMike Smith 31353a31b7ebSMike Smith /* 31363a31b7ebSMike Smith * If the adapter gave us a text message, print it. 31373a31b7ebSMike Smith */ 31383a31b7ebSMike Smith if (cn->message[0] != 0) 31393a31b7ebSMike Smith ciss_printf(sc, "*** %.80s\n", cn->message); 31403a31b7ebSMike Smith 31413a31b7ebSMike Smith debug(0, "notify event class %d subclass %d detail %d", 31423a31b7ebSMike Smith cn->class, cn->subclass, cn->detail); 31433a31b7ebSMike Smith 31443a31b7ebSMike Smith /* 31453a31b7ebSMike Smith * If the response indicates that the notifier has been aborted, 31463a31b7ebSMike Smith * release the notifier command. 31473a31b7ebSMike Smith */ 31483a31b7ebSMike Smith if ((cn->class == CISS_NOTIFY_NOTIFIER) && 31493a31b7ebSMike Smith (cn->subclass == CISS_NOTIFY_NOTIFIER_STATUS) && 31503a31b7ebSMike Smith (cn->detail == 1)) { 31513a31b7ebSMike Smith debug(0, "notifier exiting"); 31523a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 31533a31b7ebSMike Smith ciss_release_request(cr); 31543a31b7ebSMike Smith sc->ciss_periodic_notify = NULL; 31553a31b7ebSMike Smith wakeup(&sc->ciss_periodic_notify); 3156c6131460SPaul Saab } else { 3157c6131460SPaul Saab /* Handle notify events in a kernel thread */ 3158c6131460SPaul Saab ciss_enqueue_notify(cr); 3159c6131460SPaul Saab sc->ciss_periodic_notify = NULL; 3160c6131460SPaul Saab wakeup(&sc->ciss_periodic_notify); 3161c6131460SPaul Saab wakeup(&sc->ciss_notify); 31623a31b7ebSMike Smith } 31633a31b7ebSMike Smith /* 31643a31b7ebSMike Smith * Send a new notify event command, if we're not aborting. 31653a31b7ebSMike Smith */ 31663a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_ABORTING)) { 31673a31b7ebSMike Smith ciss_notify_event(sc); 31683a31b7ebSMike Smith } 31693a31b7ebSMike Smith } 31703a31b7ebSMike Smith 31713a31b7ebSMike Smith /************************************************************************ 31723a31b7ebSMike Smith * Abort the Notify Event chain. 31733a31b7ebSMike Smith * 31743a31b7ebSMike Smith * Note that we can't just abort the command in progress; we have to 31753a31b7ebSMike Smith * explicitly issue an Abort Notify Event command in order for the 31763a31b7ebSMike Smith * adapter to clean up correctly. 31773a31b7ebSMike Smith * 31783a31b7ebSMike Smith * If we are called with CISS_FLAG_ABORTING set in the adapter softc, 31793a31b7ebSMike Smith * the chain will not restart itself. 31803a31b7ebSMike Smith */ 31813a31b7ebSMike Smith static int 31823a31b7ebSMike Smith ciss_notify_abort(struct ciss_softc *sc) 31833a31b7ebSMike Smith { 31843a31b7ebSMike Smith struct ciss_request *cr; 31853a31b7ebSMike Smith struct ciss_command *cc; 31863a31b7ebSMike Smith struct ciss_notify_cdb *cnc; 31873a31b7ebSMike Smith int error, s, command_status, scsi_status; 31883a31b7ebSMike Smith 31893a31b7ebSMike Smith debug_called(1); 31903a31b7ebSMike Smith 31913a31b7ebSMike Smith cr = NULL; 31923a31b7ebSMike Smith error = 0; 31933a31b7ebSMike Smith 31943a31b7ebSMike Smith /* verify that there's an outstanding command */ 31953a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) 31963a31b7ebSMike Smith goto out; 31973a31b7ebSMike Smith 31983a31b7ebSMike Smith /* get a command to issue the abort with */ 31993a31b7ebSMike Smith if ((error = ciss_get_request(sc, &cr))) 32003a31b7ebSMike Smith goto out; 32013a31b7ebSMike Smith 32023a31b7ebSMike Smith /* get a buffer for the result */ 32033a31b7ebSMike Smith if ((cr->cr_data = malloc(CISS_NOTIFY_DATA_SIZE, CISS_MALLOC_CLASS, M_NOWAIT)) == NULL) { 32043a31b7ebSMike Smith debug(0, "can't get notify event request buffer"); 32053a31b7ebSMike Smith error = ENOMEM; 32063a31b7ebSMike Smith goto out; 32073a31b7ebSMike Smith } 32083a31b7ebSMike Smith cr->cr_length = CISS_NOTIFY_DATA_SIZE; 32093a31b7ebSMike Smith 32103a31b7ebSMike Smith /* build the CDB */ 32113a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 32123a31b7ebSMike Smith cc->header.address.physical.mode = CISS_HDR_ADDRESS_MODE_PERIPHERAL; 32133a31b7ebSMike Smith cc->header.address.physical.bus = 0; 32143a31b7ebSMike Smith cc->header.address.physical.target = 0; 32153a31b7ebSMike Smith cc->cdb.cdb_length = sizeof(*cnc); 32163a31b7ebSMike Smith cc->cdb.type = CISS_CDB_TYPE_COMMAND; 32173a31b7ebSMike Smith cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; 32183a31b7ebSMike Smith cc->cdb.direction = CISS_CDB_DIRECTION_READ; 32193a31b7ebSMike Smith cc->cdb.timeout = 0; /* no timeout, we hope */ 32203a31b7ebSMike Smith 32213a31b7ebSMike Smith cnc = (struct ciss_notify_cdb *)&(cc->cdb.cdb[0]); 32223a31b7ebSMike Smith bzero(cnc, sizeof(*cnc)); 32233a31b7ebSMike Smith cnc->opcode = CISS_OPCODE_WRITE; 32243a31b7ebSMike Smith cnc->command = CISS_COMMAND_ABORT_NOTIFY; 32253a31b7ebSMike Smith cnc->length = htonl(CISS_NOTIFY_DATA_SIZE); 32263a31b7ebSMike Smith 32273a31b7ebSMike Smith ciss_print_request(cr); 32283a31b7ebSMike Smith 32293a31b7ebSMike Smith /* 32303a31b7ebSMike Smith * Submit the request and wait for it to complete. 32313a31b7ebSMike Smith */ 32323a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 32333a31b7ebSMike Smith ciss_printf(sc, "Abort Notify Event command failed (%d)\n", error); 32343a31b7ebSMike Smith goto out; 32353a31b7ebSMike Smith } 32363a31b7ebSMike Smith 32373a31b7ebSMike Smith /* 32383a31b7ebSMike Smith * Check response. 32393a31b7ebSMike Smith */ 32403a31b7ebSMike Smith ciss_report_request(cr, &command_status, &scsi_status); 32413a31b7ebSMike Smith switch(command_status) { 32423a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 32433a31b7ebSMike Smith break; 32443a31b7ebSMike Smith case CISS_CMD_STATUS_INVALID_COMMAND: 32453a31b7ebSMike Smith /* 32463a31b7ebSMike Smith * Some older adapters don't support the CISS version of this 32473a31b7ebSMike Smith * command. Fall back to using the BMIC version. 32483a31b7ebSMike Smith */ 32493a31b7ebSMike Smith error = ciss_notify_abort_bmic(sc); 32503a31b7ebSMike Smith if (error != 0) 32513a31b7ebSMike Smith goto out; 32523a31b7ebSMike Smith break; 32533a31b7ebSMike Smith 32543a31b7ebSMike Smith case CISS_CMD_STATUS_TARGET_STATUS: 32553a31b7ebSMike Smith /* 32563a31b7ebSMike Smith * This can happen if the adapter thinks there wasn't an outstanding 32573a31b7ebSMike Smith * Notify Event command but we did. We clean up here. 32583a31b7ebSMike Smith */ 32593a31b7ebSMike Smith if (scsi_status == CISS_SCSI_STATUS_CHECK_CONDITION) { 32603a31b7ebSMike Smith if (sc->ciss_periodic_notify != NULL) 32613a31b7ebSMike Smith ciss_release_request(sc->ciss_periodic_notify); 32623a31b7ebSMike Smith error = 0; 32633a31b7ebSMike Smith goto out; 32643a31b7ebSMike Smith } 32653a31b7ebSMike Smith /* FALLTHROUGH */ 32663a31b7ebSMike Smith 32673a31b7ebSMike Smith default: 32683a31b7ebSMike Smith ciss_printf(sc, "Abort Notify Event command failed (%s)\n", 32693a31b7ebSMike Smith ciss_name_command_status(command_status)); 32703a31b7ebSMike Smith error = EIO; 32713a31b7ebSMike Smith goto out; 32723a31b7ebSMike Smith } 32733a31b7ebSMike Smith 32743a31b7ebSMike Smith /* 32753a31b7ebSMike Smith * Sleep waiting for the notifier command to complete. Note 32763a31b7ebSMike Smith * that if it doesn't, we may end up in a bad situation, since 32773a31b7ebSMike Smith * the adapter may deliver it later. Also note that the adapter 32783a31b7ebSMike Smith * requires the Notify Event command to be cancelled in order to 32793a31b7ebSMike Smith * maintain internal bookkeeping. 32803a31b7ebSMike Smith */ 32813a31b7ebSMike Smith s = splcam(); 32823a31b7ebSMike Smith while (sc->ciss_periodic_notify != NULL) { 32833a31b7ebSMike Smith error = tsleep(&sc->ciss_periodic_notify, 0, "cissNEA", hz * 5); 32843a31b7ebSMike Smith if (error == EWOULDBLOCK) { 32853a31b7ebSMike Smith ciss_printf(sc, "Notify Event command failed to abort, adapter may wedge.\n"); 32863a31b7ebSMike Smith break; 32873a31b7ebSMike Smith } 32883a31b7ebSMike Smith } 32893a31b7ebSMike Smith splx(s); 32903a31b7ebSMike Smith 32913a31b7ebSMike Smith out: 32923a31b7ebSMike Smith /* release the cancel request */ 32933a31b7ebSMike Smith if (cr != NULL) { 32943a31b7ebSMike Smith if (cr->cr_data != NULL) 32953a31b7ebSMike Smith free(cr->cr_data, CISS_MALLOC_CLASS); 32963a31b7ebSMike Smith ciss_release_request(cr); 32973a31b7ebSMike Smith } 32983a31b7ebSMike Smith if (error == 0) 32993a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_NOTIFY_OK; 33003a31b7ebSMike Smith return(error); 33013a31b7ebSMike Smith } 33023a31b7ebSMike Smith 33033a31b7ebSMike Smith /************************************************************************ 33043a31b7ebSMike Smith * Abort the Notify Event chain using a BMIC command. 33053a31b7ebSMike Smith */ 33063a31b7ebSMike Smith static int 33073a31b7ebSMike Smith ciss_notify_abort_bmic(struct ciss_softc *sc) 33083a31b7ebSMike Smith { 33093a31b7ebSMike Smith struct ciss_request *cr; 33103a31b7ebSMike Smith int error, command_status; 33113a31b7ebSMike Smith 33123a31b7ebSMike Smith debug_called(1); 33133a31b7ebSMike Smith 33143a31b7ebSMike Smith cr = NULL; 33153a31b7ebSMike Smith error = 0; 33163a31b7ebSMike Smith 33173a31b7ebSMike Smith /* verify that there's an outstanding command */ 33183a31b7ebSMike Smith if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) 33193a31b7ebSMike Smith goto out; 33203a31b7ebSMike Smith 33213a31b7ebSMike Smith /* 33223a31b7ebSMike Smith * Build a BMIC command to cancel the Notify on Event command. 33233a31b7ebSMike Smith * 33243a31b7ebSMike Smith * Note that we are sending a CISS opcode here. Odd. 33253a31b7ebSMike Smith */ 33263a31b7ebSMike Smith if ((error = ciss_get_bmic_request(sc, &cr, CISS_COMMAND_ABORT_NOTIFY, 33273a31b7ebSMike Smith NULL, 0)) != 0) 33283a31b7ebSMike Smith goto out; 33293a31b7ebSMike Smith 33303a31b7ebSMike Smith /* 33313a31b7ebSMike Smith * Submit the request and wait for it to complete. 33323a31b7ebSMike Smith */ 33333a31b7ebSMike Smith if ((error = ciss_synch_request(cr, 60 * 1000)) != 0) { 33343a31b7ebSMike Smith ciss_printf(sc, "error sending BMIC Cancel Notify on Event command (%d)\n", error); 33353a31b7ebSMike Smith goto out; 33363a31b7ebSMike Smith } 33373a31b7ebSMike Smith 33383a31b7ebSMike Smith /* 33393a31b7ebSMike Smith * Check response. 33403a31b7ebSMike Smith */ 33413a31b7ebSMike Smith ciss_report_request(cr, &command_status, NULL); 33423a31b7ebSMike Smith switch(command_status) { 33433a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 33443a31b7ebSMike Smith break; 33453a31b7ebSMike Smith default: 33463a31b7ebSMike Smith ciss_printf(sc, "error cancelling Notify on Event (%s)\n", 33473a31b7ebSMike Smith ciss_name_command_status(command_status)); 33483a31b7ebSMike Smith error = EIO; 33493a31b7ebSMike Smith goto out; 33503a31b7ebSMike Smith } 33513a31b7ebSMike Smith 33523a31b7ebSMike Smith out: 33533a31b7ebSMike Smith if (cr != NULL) 33543a31b7ebSMike Smith ciss_release_request(cr); 33553a31b7ebSMike Smith return(error); 33563a31b7ebSMike Smith } 33573a31b7ebSMike Smith 33583a31b7ebSMike Smith /************************************************************************ 3359c6131460SPaul Saab * Handle rescanning all the logical volumes when a notify event 3360c6131460SPaul Saab * causes the drives to come online or offline. 3361c6131460SPaul Saab */ 3362c6131460SPaul Saab static void 3363c6131460SPaul Saab ciss_notify_rescan_logical(struct ciss_softc *sc) 3364c6131460SPaul Saab { 3365c6131460SPaul Saab struct ciss_lun_report *cll; 3366c6131460SPaul Saab struct ciss_ldrive *ld; 3367c6131460SPaul Saab int i, j, ndrives; 3368c6131460SPaul Saab 3369c6131460SPaul Saab /* 3370c6131460SPaul Saab * We must rescan all logical volumes to get the right logical 3371c6131460SPaul Saab * drive address. 3372c6131460SPaul Saab */ 3373c6131460SPaul Saab cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_LOGICAL_LUNS, 3374c6131460SPaul Saab CISS_MAX_LOGICAL); 3375c6131460SPaul Saab if (cll == NULL) 3376c6131460SPaul Saab return; 3377c6131460SPaul Saab 3378c6131460SPaul Saab ndrives = (ntohl(cll->list_size) / sizeof(union ciss_device_address)); 3379c6131460SPaul Saab 3380c6131460SPaul Saab /* 3381c6131460SPaul Saab * Delete any of the drives which were destroyed by the 3382c6131460SPaul Saab * firmware. 3383c6131460SPaul Saab */ 33841fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 3385c6131460SPaul Saab for (j = 0; j < CISS_MAX_LOGICAL; j++) { 3386c6131460SPaul Saab ld = &sc->ciss_logical[i][j]; 3387c6131460SPaul Saab 3388c6131460SPaul Saab if (ld->cl_update == 0) 3389c6131460SPaul Saab continue; 3390c6131460SPaul Saab 3391c6131460SPaul Saab if (ld->cl_status != CISS_LD_ONLINE) { 3392c6131460SPaul Saab ciss_cam_rescan_target(sc, i, j); 3393c6131460SPaul Saab ld->cl_update = 0; 3394c6131460SPaul Saab if (ld->cl_ldrive) 3395c6131460SPaul Saab free(ld->cl_ldrive, CISS_MALLOC_CLASS); 3396c6131460SPaul Saab if (ld->cl_lstatus) 3397c6131460SPaul Saab free(ld->cl_lstatus, CISS_MALLOC_CLASS); 3398c6131460SPaul Saab 3399c6131460SPaul Saab ld->cl_ldrive = NULL; 3400c6131460SPaul Saab ld->cl_lstatus = NULL; 3401c6131460SPaul Saab } 3402c6131460SPaul Saab } 3403c6131460SPaul Saab } 3404c6131460SPaul Saab 3405c6131460SPaul Saab /* 3406c6131460SPaul Saab * Scan for new drives. 3407c6131460SPaul Saab */ 3408c6131460SPaul Saab for (i = 0; i < ndrives; i++) { 3409c6131460SPaul Saab int bus, target; 3410c6131460SPaul Saab 3411c6131460SPaul Saab bus = CISS_LUN_TO_BUS(cll->lun[i].logical.lun); 3412c6131460SPaul Saab target = CISS_LUN_TO_TARGET(cll->lun[i].logical.lun); 3413c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 3414c6131460SPaul Saab 3415c6131460SPaul Saab if (ld->cl_update == 0) 3416c6131460SPaul Saab continue; 3417c6131460SPaul Saab 34185cf5a430SPaul Saab ld->cl_update = 0; 3419c6131460SPaul Saab ld->cl_address = cll->lun[i]; 3420c6131460SPaul Saab ld->cl_controller = &sc->ciss_controllers[bus]; 3421c6131460SPaul Saab if (ciss_identify_logical(sc, ld) == 0) { 3422c6131460SPaul Saab ciss_cam_rescan_target(sc, bus, target); 3423c6131460SPaul Saab } 3424c6131460SPaul Saab } 3425c6131460SPaul Saab free(cll, CISS_MALLOC_CLASS); 3426c6131460SPaul Saab } 3427c6131460SPaul Saab 3428c6131460SPaul Saab /************************************************************************ 34293a31b7ebSMike Smith * Handle a notify event relating to the status of a logical drive. 34303a31b7ebSMike Smith * 34313a31b7ebSMike Smith * XXX need to be able to defer some of these to properly handle 34323a31b7ebSMike Smith * calling the "ID Physical drive" command, unless the 'extended' 34333a31b7ebSMike Smith * drive IDs are always in BIG_MAP format. 34343a31b7ebSMike Smith */ 34353a31b7ebSMike Smith static void 34363a31b7ebSMike Smith ciss_notify_logical(struct ciss_softc *sc, struct ciss_notify *cn) 34373a31b7ebSMike Smith { 34383a31b7ebSMike Smith struct ciss_ldrive *ld; 3439c6131460SPaul Saab int ostatus, bus, target; 34403a31b7ebSMike Smith 34413a31b7ebSMike Smith debug_called(2); 34423a31b7ebSMike Smith 3443c6131460SPaul Saab bus = cn->device.physical.bus; 3444c6131460SPaul Saab target = cn->data.logical_status.logical_drive; 3445c6131460SPaul Saab ld = &sc->ciss_logical[bus][target]; 34463a31b7ebSMike Smith 34473a31b7ebSMike Smith switch (cn->subclass) { 34483a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_STATUS: 34493a31b7ebSMike Smith switch (cn->detail) { 34503a31b7ebSMike Smith case 0: 3451c6131460SPaul Saab ciss_name_device(sc, bus, target); 34523a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) changed status %s->%s, spare status 0x%b\n", 34533a31b7ebSMike Smith cn->data.logical_status.logical_drive, ld->cl_name, 34543a31b7ebSMike Smith ciss_name_ldrive_status(cn->data.logical_status.previous_state), 34553a31b7ebSMike Smith ciss_name_ldrive_status(cn->data.logical_status.new_state), 34563a31b7ebSMike Smith cn->data.logical_status.spare_state, 34573a31b7ebSMike Smith "\20\1configured\2rebuilding\3failed\4in use\5available\n"); 34583a31b7ebSMike Smith 34593a31b7ebSMike Smith /* 34603a31b7ebSMike Smith * Update our idea of the drive's status. 34613a31b7ebSMike Smith */ 34623a31b7ebSMike Smith ostatus = ciss_decode_ldrive_status(cn->data.logical_status.previous_state); 34633a31b7ebSMike Smith ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); 3464d4aa427fSPaul Saab if (ld->cl_lstatus != NULL) 34653a31b7ebSMike Smith ld->cl_lstatus->status = cn->data.logical_status.new_state; 34663a31b7ebSMike Smith 3467d4aa427fSPaul Saab /* 3468d4aa427fSPaul Saab * Have CAM rescan the drive if its status has changed. 3469d4aa427fSPaul Saab */ 3470c6131460SPaul Saab if (ostatus != ld->cl_status) { 3471c6131460SPaul Saab ld->cl_update = 1; 3472c6131460SPaul Saab ciss_notify_rescan_logical(sc); 3473c6131460SPaul Saab } 3474d4aa427fSPaul Saab 34753a31b7ebSMike Smith break; 34763a31b7ebSMike Smith 34773a31b7ebSMike Smith case 1: /* logical drive has recognised new media, needs Accept Media Exchange */ 3478c6131460SPaul Saab ciss_name_device(sc, bus, target); 34793a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) media exchanged, ready to go online\n", 34803a31b7ebSMike Smith cn->data.logical_status.logical_drive, ld->cl_name); 348188c78a38SPaul Saab ciss_accept_media(sc, ld); 3482139233cbSPaul Saab 3483139233cbSPaul Saab ld->cl_update = 1; 3484139233cbSPaul Saab ld->cl_status = ciss_decode_ldrive_status(cn->data.logical_status.new_state); 3485139233cbSPaul Saab ciss_notify_rescan_logical(sc); 34863a31b7ebSMike Smith break; 34873a31b7ebSMike Smith 34883a31b7ebSMike Smith case 2: 34893a31b7ebSMike Smith case 3: 34903a31b7ebSMike Smith ciss_printf(sc, "rebuild of logical drive %d (%s) failed due to %s error\n", 34913a31b7ebSMike Smith cn->data.rebuild_aborted.logical_drive, 3492c6131460SPaul Saab ld->cl_name, 34933a31b7ebSMike Smith (cn->detail == 2) ? "read" : "write"); 34943a31b7ebSMike Smith break; 34953a31b7ebSMike Smith } 34963a31b7ebSMike Smith break; 34973a31b7ebSMike Smith 34983a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_ERROR: 34993a31b7ebSMike Smith if (cn->detail == 0) { 35003a31b7ebSMike Smith ciss_printf(sc, "FATAL I/O ERROR on logical drive %d (%s), SCSI port %d ID %d\n", 35013a31b7ebSMike Smith cn->data.io_error.logical_drive, 3502c6131460SPaul Saab ld->cl_name, 35033a31b7ebSMike Smith cn->data.io_error.failure_bus, 35043a31b7ebSMike Smith cn->data.io_error.failure_drive); 35053a31b7ebSMike Smith /* XXX should we take the drive down at this point, or will we be told? */ 35063a31b7ebSMike Smith } 35073a31b7ebSMike Smith break; 35083a31b7ebSMike Smith 35093a31b7ebSMike Smith case CISS_NOTIFY_LOGICAL_SURFACE: 35103a31b7ebSMike Smith if (cn->detail == 0) 35113a31b7ebSMike Smith ciss_printf(sc, "logical drive %d (%s) completed consistency initialisation\n", 35123a31b7ebSMike Smith cn->data.consistency_completed.logical_drive, 3513c6131460SPaul Saab ld->cl_name); 35143a31b7ebSMike Smith break; 35153a31b7ebSMike Smith } 35163a31b7ebSMike Smith } 35173a31b7ebSMike Smith 35183a31b7ebSMike Smith /************************************************************************ 35193a31b7ebSMike Smith * Handle a notify event relating to the status of a physical drive. 35203a31b7ebSMike Smith */ 35213a31b7ebSMike Smith static void 35223a31b7ebSMike Smith ciss_notify_physical(struct ciss_softc *sc, struct ciss_notify *cn) 35233a31b7ebSMike Smith { 3524c6131460SPaul Saab } 35253a31b7ebSMike Smith 3526c6131460SPaul Saab /************************************************************************ 35271fe6c4eeSScott Long * Handle a notify event relating to the status of a physical drive. 35281fe6c4eeSScott Long */ 35291fe6c4eeSScott Long static void 35301fe6c4eeSScott Long ciss_notify_hotplug(struct ciss_softc *sc, struct ciss_notify *cn) 35311fe6c4eeSScott Long { 35321fe6c4eeSScott Long struct ciss_lun_report *cll; 35331fe6c4eeSScott Long int bus, target; 35341fe6c4eeSScott Long int s; 35351fe6c4eeSScott Long 35361fe6c4eeSScott Long switch (cn->subclass) { 35371fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG_PHYSICAL: 35381fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG_NONDISK: 35391fe6c4eeSScott Long bus = CISS_BIG_MAP_BUS(sc, cn->data.drive.big_physical_drive_number); 35401fe6c4eeSScott Long target = 35411fe6c4eeSScott Long CISS_BIG_MAP_TARGET(sc, cn->data.drive.big_physical_drive_number); 35421fe6c4eeSScott Long 35431fe6c4eeSScott Long s = splcam(); 35441fe6c4eeSScott Long if (cn->detail == 0) { 35451fe6c4eeSScott Long /* 35461fe6c4eeSScott Long * Mark the device offline so that it'll start producing selection 35471fe6c4eeSScott Long * timeouts to the upper layer. 35481fe6c4eeSScott Long */ 35491fe6c4eeSScott Long sc->ciss_physical[bus][target].cp_online = 0; 35501fe6c4eeSScott Long } else { 35511fe6c4eeSScott Long /* 35521fe6c4eeSScott Long * Rescan the physical lun list for new items 35531fe6c4eeSScott Long */ 35541fe6c4eeSScott Long cll = ciss_report_luns(sc, CISS_OPCODE_REPORT_PHYSICAL_LUNS, 35551fe6c4eeSScott Long CISS_MAX_PHYSICAL); 35561fe6c4eeSScott Long if (cll == NULL) { 35571fe6c4eeSScott Long ciss_printf(sc, "Warning, cannot get physical lun list\n"); 35581fe6c4eeSScott Long break; 35591fe6c4eeSScott Long } 35601fe6c4eeSScott Long ciss_filter_physical(sc, cll); 35611fe6c4eeSScott Long } 35621fe6c4eeSScott Long splx(s); 35631fe6c4eeSScott Long break; 35641fe6c4eeSScott Long 35651fe6c4eeSScott Long default: 35661fe6c4eeSScott Long ciss_printf(sc, "Unknown hotplug event %d\n", cn->subclass); 35671fe6c4eeSScott Long return; 35681fe6c4eeSScott Long } 35691fe6c4eeSScott Long } 35701fe6c4eeSScott Long 35711fe6c4eeSScott Long /************************************************************************ 3572c6131460SPaul Saab * Handle deferred processing of notify events. Notify events may need 3573c6131460SPaul Saab * sleep which is unsafe during an interrupt. 3574c6131460SPaul Saab */ 3575c6131460SPaul Saab static void 3576c6131460SPaul Saab ciss_notify_thread(void *arg) 3577c6131460SPaul Saab { 3578c6131460SPaul Saab struct ciss_softc *sc; 3579c6131460SPaul Saab struct ciss_request *cr; 3580c6131460SPaul Saab struct ciss_notify *cn; 3581c6131460SPaul Saab int s; 3582c6131460SPaul Saab 3583c6131460SPaul Saab #if __FreeBSD_version >= 500000 3584c6131460SPaul Saab mtx_lock(&Giant); 3585c6131460SPaul Saab #endif 3586c6131460SPaul Saab sc = (struct ciss_softc *)arg; 3587c6131460SPaul Saab 3588c6131460SPaul Saab s = splcam(); 3589c6131460SPaul Saab for (;;) { 3590c6131460SPaul Saab if (TAILQ_EMPTY(&sc->ciss_notify) != 0 && 3591c6131460SPaul Saab (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) == 0) { 3592c6131460SPaul Saab tsleep(&sc->ciss_notify, PUSER, "idle", 0); 3593c6131460SPaul Saab } 3594c6131460SPaul Saab 3595c6131460SPaul Saab if (sc->ciss_flags & CISS_FLAG_THREAD_SHUT) 3596c6131460SPaul Saab break; 3597c6131460SPaul Saab 3598c6131460SPaul Saab cr = ciss_dequeue_notify(sc); 3599c6131460SPaul Saab splx(s); 3600c6131460SPaul Saab 3601c6131460SPaul Saab if (cr == NULL) 3602c6131460SPaul Saab panic("cr null"); 3603c6131460SPaul Saab cn = (struct ciss_notify *)cr->cr_data; 3604c6131460SPaul Saab 3605c6131460SPaul Saab switch (cn->class) { 36061fe6c4eeSScott Long case CISS_NOTIFY_HOTPLUG: 36071fe6c4eeSScott Long ciss_notify_hotplug(sc, cn); 36081fe6c4eeSScott Long break; 3609c6131460SPaul Saab case CISS_NOTIFY_LOGICAL: 3610c6131460SPaul Saab ciss_notify_logical(sc, cn); 3611c6131460SPaul Saab break; 3612c6131460SPaul Saab case CISS_NOTIFY_PHYSICAL: 3613c6131460SPaul Saab ciss_notify_physical(sc, cn); 3614c6131460SPaul Saab break; 3615c6131460SPaul Saab } 3616c6131460SPaul Saab 3617c6131460SPaul Saab ciss_release_request(cr); 3618c6131460SPaul Saab 3619c6131460SPaul Saab s = splcam(); 3620c6131460SPaul Saab } 3621c6131460SPaul Saab sc->ciss_notify_thread = NULL; 3622c6131460SPaul Saab wakeup(&sc->ciss_notify_thread); 3623c6131460SPaul Saab splx(s); 3624c6131460SPaul Saab 3625c6131460SPaul Saab #if __FreeBSD_version >= 500000 3626c6131460SPaul Saab mtx_unlock(&Giant); 3627c6131460SPaul Saab #endif 3628c6131460SPaul Saab kthread_exit(0); 3629c6131460SPaul Saab } 3630c6131460SPaul Saab 3631c6131460SPaul Saab /************************************************************************ 3632c6131460SPaul Saab * Start the notification kernel thread. 3633c6131460SPaul Saab */ 3634c6131460SPaul Saab static void 3635c6131460SPaul Saab ciss_spawn_notify_thread(struct ciss_softc *sc) 3636c6131460SPaul Saab { 3637c6131460SPaul Saab 363878d03361SPaul Saab #if __FreeBSD_version > 500005 3639c6131460SPaul Saab if (kthread_create((void(*)(void *))ciss_notify_thread, sc, 3640c6131460SPaul Saab &sc->ciss_notify_thread, 0, 0, "ciss_notify%d", 3641c6131460SPaul Saab device_get_unit(sc->ciss_dev))) 364278d03361SPaul Saab #else 364378d03361SPaul Saab if (kthread_create((void(*)(void *))ciss_notify_thread, sc, 364478d03361SPaul Saab &sc->ciss_notify_thread, "ciss_notify%d", 364578d03361SPaul Saab device_get_unit(sc->ciss_dev))) 364678d03361SPaul Saab #endif 3647c6131460SPaul Saab panic("Could not create notify thread\n"); 3648c6131460SPaul Saab } 3649c6131460SPaul Saab 3650c6131460SPaul Saab /************************************************************************ 3651c6131460SPaul Saab * Kill the notification kernel thread. 3652c6131460SPaul Saab */ 3653c6131460SPaul Saab static void 3654c6131460SPaul Saab ciss_kill_notify_thread(struct ciss_softc *sc) 3655c6131460SPaul Saab { 3656c6131460SPaul Saab 3657c6131460SPaul Saab if (sc->ciss_notify_thread == NULL) 3658c6131460SPaul Saab return; 3659c6131460SPaul Saab 3660c6131460SPaul Saab sc->ciss_flags |= CISS_FLAG_THREAD_SHUT; 3661c6131460SPaul Saab wakeup(&sc->ciss_notify); 3662c6131460SPaul Saab tsleep(&sc->ciss_notify_thread, PUSER, "thtrm", 0); 36633a31b7ebSMike Smith } 36643a31b7ebSMike Smith 36653a31b7ebSMike Smith /************************************************************************ 36663a31b7ebSMike Smith * Print a request. 36673a31b7ebSMike Smith */ 36683a31b7ebSMike Smith static void 36693a31b7ebSMike Smith ciss_print_request(struct ciss_request *cr) 36703a31b7ebSMike Smith { 36713a31b7ebSMike Smith struct ciss_softc *sc; 36723a31b7ebSMike Smith struct ciss_command *cc; 36733a31b7ebSMike Smith int i; 36743a31b7ebSMike Smith 36753a31b7ebSMike Smith sc = cr->cr_sc; 36763a31b7ebSMike Smith cc = CISS_FIND_COMMAND(cr); 36773a31b7ebSMike Smith 36783a31b7ebSMike Smith ciss_printf(sc, "REQUEST @ %p\n", cr); 36793a31b7ebSMike Smith ciss_printf(sc, " data %p/%d tag %d flags %b\n", 36803a31b7ebSMike Smith cr->cr_data, cr->cr_length, cr->cr_tag, cr->cr_flags, 36813a31b7ebSMike Smith "\20\1mapped\2sleep\3poll\4dataout\5datain\n"); 36823a31b7ebSMike Smith ciss_printf(sc, " sg list/total %d/%d host tag 0x%x\n", 36833a31b7ebSMike Smith cc->header.sg_in_list, cc->header.sg_total, cc->header.host_tag); 36843a31b7ebSMike Smith switch(cc->header.address.mode.mode) { 36853a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_PERIPHERAL: 36863a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_MASK_PERIPHERAL: 36873a31b7ebSMike Smith ciss_printf(sc, " physical bus %d target %d\n", 36883a31b7ebSMike Smith cc->header.address.physical.bus, cc->header.address.physical.target); 36893a31b7ebSMike Smith break; 36903a31b7ebSMike Smith case CISS_HDR_ADDRESS_MODE_LOGICAL: 36913a31b7ebSMike Smith ciss_printf(sc, " logical unit %d\n", cc->header.address.logical.lun); 36923a31b7ebSMike Smith break; 36933a31b7ebSMike Smith } 36943a31b7ebSMike Smith ciss_printf(sc, " %s cdb length %d type %s attribute %s\n", 36953a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_NONE) ? "no-I/O" : 36963a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_READ) ? "READ" : 36973a31b7ebSMike Smith (cc->cdb.direction == CISS_CDB_DIRECTION_WRITE) ? "WRITE" : "??", 36983a31b7ebSMike Smith cc->cdb.cdb_length, 36993a31b7ebSMike Smith (cc->cdb.type == CISS_CDB_TYPE_COMMAND) ? "command" : 37003a31b7ebSMike Smith (cc->cdb.type == CISS_CDB_TYPE_MESSAGE) ? "message" : "??", 37013a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_UNTAGGED) ? "untagged" : 37023a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_SIMPLE) ? "simple" : 37033a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_HEAD_OF_QUEUE) ? "head-of-queue" : 37043a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_ORDERED) ? "ordered" : 37053a31b7ebSMike Smith (cc->cdb.attribute == CISS_CDB_ATTRIBUTE_AUTO_CONTINGENT) ? "auto-contingent" : "??"); 37063a31b7ebSMike Smith ciss_printf(sc, " %*D\n", cc->cdb.cdb_length, &cc->cdb.cdb[0], " "); 37073a31b7ebSMike Smith 37083a31b7ebSMike Smith if (cc->header.host_tag & CISS_HDR_HOST_TAG_ERROR) { 37093a31b7ebSMike Smith /* XXX print error info */ 37103a31b7ebSMike Smith } else { 37113a31b7ebSMike Smith /* since we don't use chained s/g, don't support it here */ 37123a31b7ebSMike Smith for (i = 0; i < cc->header.sg_in_list; i++) { 37133a31b7ebSMike Smith if ((i % 4) == 0) 37143a31b7ebSMike Smith ciss_printf(sc, " "); 37153a31b7ebSMike Smith printf("0x%08x/%d ", (u_int32_t)cc->sg[i].address, cc->sg[i].length); 37163a31b7ebSMike Smith if ((((i + 1) % 4) == 0) || (i == (cc->header.sg_in_list - 1))) 37173a31b7ebSMike Smith printf("\n"); 37183a31b7ebSMike Smith } 37193a31b7ebSMike Smith } 37203a31b7ebSMike Smith } 37213a31b7ebSMike Smith 37223a31b7ebSMike Smith /************************************************************************ 37233a31b7ebSMike Smith * Print information about the status of a logical drive. 37243a31b7ebSMike Smith */ 37253a31b7ebSMike Smith static void 37263a31b7ebSMike Smith ciss_print_ldrive(struct ciss_softc *sc, struct ciss_ldrive *ld) 37273a31b7ebSMike Smith { 37283a31b7ebSMike Smith int bus, target, i; 37293a31b7ebSMike Smith 3730d4aa427fSPaul Saab if (ld->cl_lstatus == NULL) { 3731d4aa427fSPaul Saab printf("does not exist\n"); 3732d4aa427fSPaul Saab return; 3733d4aa427fSPaul Saab } 3734d4aa427fSPaul Saab 37353a31b7ebSMike Smith /* print drive status */ 37363a31b7ebSMike Smith switch(ld->cl_lstatus->status) { 37373a31b7ebSMike Smith case CISS_LSTATUS_OK: 37383a31b7ebSMike Smith printf("online\n"); 37393a31b7ebSMike Smith break; 37403a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 37413a31b7ebSMike Smith printf("in interim recovery mode\n"); 37423a31b7ebSMike Smith break; 37433a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 37443a31b7ebSMike Smith printf("ready to begin recovery\n"); 37453a31b7ebSMike Smith break; 37463a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 37473a31b7ebSMike Smith bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); 37483a31b7ebSMike Smith target = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_rebuilding); 37493a31b7ebSMike Smith printf("being recovered, working on physical drive %d.%d, %u blocks remaining\n", 37503a31b7ebSMike Smith bus, target, ld->cl_lstatus->blocks_to_recover); 37513a31b7ebSMike Smith break; 37523a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 37533a31b7ebSMike Smith printf("being expanded, %u blocks remaining\n", 37543a31b7ebSMike Smith ld->cl_lstatus->blocks_to_recover); 37553a31b7ebSMike Smith break; 37563a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 37573a31b7ebSMike Smith printf("queued for expansion\n"); 37583a31b7ebSMike Smith break; 37593a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 37603a31b7ebSMike Smith printf("queued for expansion\n"); 37613a31b7ebSMike Smith break; 37623a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 37633a31b7ebSMike Smith printf("wrong physical drive inserted\n"); 37643a31b7ebSMike Smith break; 37653a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 37663a31b7ebSMike Smith printf("missing a needed physical drive\n"); 37673a31b7ebSMike Smith break; 37683a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 37693a31b7ebSMike Smith printf("becoming ready\n"); 37703a31b7ebSMike Smith break; 37713a31b7ebSMike Smith } 37723a31b7ebSMike Smith 3773d4aa427fSPaul Saab /* print failed physical drives */ 37743a31b7ebSMike Smith for (i = 0; i < CISS_BIG_MAP_ENTRIES / 8; i++) { 37753a31b7ebSMike Smith bus = CISS_BIG_MAP_BUS(sc, ld->cl_lstatus->drive_failure_map[i]); 37763a31b7ebSMike Smith target = CISS_BIG_MAP_TARGET(sc, ld->cl_lstatus->drive_failure_map[i]); 37773a31b7ebSMike Smith if (bus == -1) 37783a31b7ebSMike Smith continue; 37793a31b7ebSMike Smith ciss_printf(sc, "physical drive %d:%d (%x) failed\n", bus, target, 37803a31b7ebSMike Smith ld->cl_lstatus->drive_failure_map[i]); 37813a31b7ebSMike Smith } 37823a31b7ebSMike Smith } 37833a31b7ebSMike Smith 3784d4aa427fSPaul Saab #ifdef CISS_DEBUG 3785d4aa427fSPaul Saab /************************************************************************ 3786d4aa427fSPaul Saab * Print information about the controller/driver. 3787d4aa427fSPaul Saab */ 3788d4aa427fSPaul Saab static void 3789d4aa427fSPaul Saab ciss_print_adapter(struct ciss_softc *sc) 3790d4aa427fSPaul Saab { 3791609caf8dSPaul Saab int i, j; 3792d4aa427fSPaul Saab 3793d4aa427fSPaul Saab ciss_printf(sc, "ADAPTER:\n"); 3794d4aa427fSPaul Saab for (i = 0; i < CISSQ_COUNT; i++) { 3795d4aa427fSPaul Saab ciss_printf(sc, "%s %d/%d\n", 3796d4aa427fSPaul Saab i == 0 ? "free" : 3797d4aa427fSPaul Saab i == 1 ? "busy" : "complete", 3798d4aa427fSPaul Saab sc->ciss_qstat[i].q_length, 3799d4aa427fSPaul Saab sc->ciss_qstat[i].q_max); 3800d4aa427fSPaul Saab } 3801d4aa427fSPaul Saab ciss_printf(sc, "max_requests %d\n", sc->ciss_max_requests); 3802d4aa427fSPaul Saab ciss_printf(sc, "flags %b\n", sc->ciss_flags, 3803d4aa427fSPaul Saab "\20\1notify_ok\2control_open\3aborting\4running\21fake_synch\22bmic_abort\n"); 3804d4aa427fSPaul Saab 38051fe6c4eeSScott Long for (i = 0; i < sc->ciss_max_logical_bus; i++) { 3806609caf8dSPaul Saab for (j = 0; j < CISS_MAX_LOGICAL; j++) { 3807d4aa427fSPaul Saab ciss_printf(sc, "LOGICAL DRIVE %d: ", i); 3808609caf8dSPaul Saab ciss_print_ldrive(sc, &sc->ciss_logical[i][j]); 3809609caf8dSPaul Saab } 3810d4aa427fSPaul Saab } 3811d4aa427fSPaul Saab 38121fe6c4eeSScott Long /* XXX Should physical drives be printed out here? */ 38131fe6c4eeSScott Long 3814d4aa427fSPaul Saab for (i = 1; i < sc->ciss_max_requests; i++) 3815d4aa427fSPaul Saab ciss_print_request(sc->ciss_request + i); 3816d4aa427fSPaul Saab } 3817d4aa427fSPaul Saab 3818d4aa427fSPaul Saab /* DDB hook */ 3819e6fccf7aSMaxime Henrion static void 3820d4aa427fSPaul Saab ciss_print0(void) 3821d4aa427fSPaul Saab { 3822d4aa427fSPaul Saab struct ciss_softc *sc; 3823d4aa427fSPaul Saab 3824d4aa427fSPaul Saab sc = devclass_get_softc(devclass_find("ciss"), 0); 3825d4aa427fSPaul Saab if (sc == NULL) { 3826d4aa427fSPaul Saab printf("no ciss controllers\n"); 3827d4aa427fSPaul Saab } else { 3828d4aa427fSPaul Saab ciss_print_adapter(sc); 3829d4aa427fSPaul Saab } 3830d4aa427fSPaul Saab } 3831d4aa427fSPaul Saab #endif 3832d4aa427fSPaul Saab 38333a31b7ebSMike Smith /************************************************************************ 38343a31b7ebSMike Smith * Return a name for a logical drive status value. 38353a31b7ebSMike Smith */ 38363a31b7ebSMike Smith static const char * 38373a31b7ebSMike Smith ciss_name_ldrive_status(int status) 38383a31b7ebSMike Smith { 38393a31b7ebSMike Smith switch (status) { 38403a31b7ebSMike Smith case CISS_LSTATUS_OK: 38413a31b7ebSMike Smith return("OK"); 38423a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 38433a31b7ebSMike Smith return("failed"); 38443a31b7ebSMike Smith case CISS_LSTATUS_NOT_CONFIGURED: 38453a31b7ebSMike Smith return("not configured"); 38463a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 38473a31b7ebSMike Smith return("interim recovery"); 38483a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 38493a31b7ebSMike Smith return("ready for recovery"); 38503a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 38513a31b7ebSMike Smith return("recovering"); 38523a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 38533a31b7ebSMike Smith return("wrong physical drive inserted"); 38543a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 38553a31b7ebSMike Smith return("missing physical drive"); 38563a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 38573a31b7ebSMike Smith return("expanding"); 38583a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 38593a31b7ebSMike Smith return("becoming ready"); 38603a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 38613a31b7ebSMike Smith return("queued for expansion"); 38623a31b7ebSMike Smith } 38633a31b7ebSMike Smith return("unknown status"); 38643a31b7ebSMike Smith } 38653a31b7ebSMike Smith 38663a31b7ebSMike Smith /************************************************************************ 38673a31b7ebSMike Smith * Return an online/offline/nonexistent value for a logical drive 38683a31b7ebSMike Smith * status value. 38693a31b7ebSMike Smith */ 38703a31b7ebSMike Smith static int 38713a31b7ebSMike Smith ciss_decode_ldrive_status(int status) 38723a31b7ebSMike Smith { 38733a31b7ebSMike Smith switch(status) { 38743a31b7ebSMike Smith case CISS_LSTATUS_NOT_CONFIGURED: 38753a31b7ebSMike Smith return(CISS_LD_NONEXISTENT); 38763a31b7ebSMike Smith 38773a31b7ebSMike Smith case CISS_LSTATUS_OK: 38783a31b7ebSMike Smith case CISS_LSTATUS_INTERIM_RECOVERY: 38793a31b7ebSMike Smith case CISS_LSTATUS_READY_RECOVERY: 38803a31b7ebSMike Smith case CISS_LSTATUS_RECOVERING: 38813a31b7ebSMike Smith case CISS_LSTATUS_EXPANDING: 38823a31b7ebSMike Smith case CISS_LSTATUS_QUEUED_FOR_EXPANSION: 38833a31b7ebSMike Smith return(CISS_LD_ONLINE); 38843a31b7ebSMike Smith 38853a31b7ebSMike Smith case CISS_LSTATUS_FAILED: 38863a31b7ebSMike Smith case CISS_LSTATUS_WRONG_PDRIVE: 38873a31b7ebSMike Smith case CISS_LSTATUS_MISSING_PDRIVE: 38883a31b7ebSMike Smith case CISS_LSTATUS_BECOMING_READY: 38893a31b7ebSMike Smith default: 38903a31b7ebSMike Smith return(CISS_LD_OFFLINE); 38913a31b7ebSMike Smith } 38923a31b7ebSMike Smith } 38933a31b7ebSMike Smith 38943a31b7ebSMike Smith 38953a31b7ebSMike Smith /************************************************************************ 38963a31b7ebSMike Smith * Return a name for a logical drive's organisation. 38973a31b7ebSMike Smith */ 38983a31b7ebSMike Smith static const char * 38993a31b7ebSMike Smith ciss_name_ldrive_org(int org) 39003a31b7ebSMike Smith { 39013a31b7ebSMike Smith switch(org) { 39023a31b7ebSMike Smith case CISS_LDRIVE_RAID0: 39033a31b7ebSMike Smith return("RAID 0"); 39043a31b7ebSMike Smith case CISS_LDRIVE_RAID1: 39053a31b7ebSMike Smith return("RAID 1"); 39063a31b7ebSMike Smith case CISS_LDRIVE_RAID4: 39073a31b7ebSMike Smith return("RAID 4"); 39083a31b7ebSMike Smith case CISS_LDRIVE_RAID5: 39093a31b7ebSMike Smith return("RAID 5"); 3910aaf8327bSPaul Saab case CISS_LDRIVE_RAID51: 3911aaf8327bSPaul Saab return("RAID 5+1"); 3912aaf8327bSPaul Saab case CISS_LDRIVE_RAIDADG: 3913aaf8327bSPaul Saab return("RAID ADG"); 39143a31b7ebSMike Smith } 39153a31b7ebSMike Smith return("unkown"); 39163a31b7ebSMike Smith } 39173a31b7ebSMike Smith 39183a31b7ebSMike Smith /************************************************************************ 39193a31b7ebSMike Smith * Return a name for a command status value. 39203a31b7ebSMike Smith */ 39213a31b7ebSMike Smith static const char * 39223a31b7ebSMike Smith ciss_name_command_status(int status) 39233a31b7ebSMike Smith { 39243a31b7ebSMike Smith switch(status) { 39253a31b7ebSMike Smith case CISS_CMD_STATUS_SUCCESS: 39263a31b7ebSMike Smith return("success"); 39273a31b7ebSMike Smith case CISS_CMD_STATUS_TARGET_STATUS: 39283a31b7ebSMike Smith return("target status"); 39293a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_UNDERRUN: 39303a31b7ebSMike Smith return("data underrun"); 39313a31b7ebSMike Smith case CISS_CMD_STATUS_DATA_OVERRUN: 39323a31b7ebSMike Smith return("data overrun"); 39333a31b7ebSMike Smith case CISS_CMD_STATUS_INVALID_COMMAND: 39343a31b7ebSMike Smith return("invalid command"); 39353a31b7ebSMike Smith case CISS_CMD_STATUS_PROTOCOL_ERROR: 39363a31b7ebSMike Smith return("protocol error"); 39373a31b7ebSMike Smith case CISS_CMD_STATUS_HARDWARE_ERROR: 39383a31b7ebSMike Smith return("hardware error"); 39393a31b7ebSMike Smith case CISS_CMD_STATUS_CONNECTION_LOST: 39403a31b7ebSMike Smith return("connection lost"); 39413a31b7ebSMike Smith case CISS_CMD_STATUS_ABORTED: 39423a31b7ebSMike Smith return("aborted"); 39433a31b7ebSMike Smith case CISS_CMD_STATUS_ABORT_FAILED: 39443a31b7ebSMike Smith return("abort failed"); 39453a31b7ebSMike Smith case CISS_CMD_STATUS_UNSOLICITED_ABORT: 39463a31b7ebSMike Smith return("unsolicited abort"); 39473a31b7ebSMike Smith case CISS_CMD_STATUS_TIMEOUT: 39483a31b7ebSMike Smith return("timeout"); 39493a31b7ebSMike Smith case CISS_CMD_STATUS_UNABORTABLE: 39503a31b7ebSMike Smith return("unabortable"); 39513a31b7ebSMike Smith } 39523a31b7ebSMike Smith return("unknown status"); 39533a31b7ebSMike Smith } 39543a31b7ebSMike Smith 39553a31b7ebSMike Smith /************************************************************************ 39563a31b7ebSMike Smith * Handle an open on the control device. 39573a31b7ebSMike Smith */ 39583a31b7ebSMike Smith static int 395989c9c53dSPoul-Henning Kamp ciss_open(struct cdev *dev, int flags, int fmt, d_thread_t *p) 39603a31b7ebSMike Smith { 39613a31b7ebSMike Smith struct ciss_softc *sc; 39623a31b7ebSMike Smith 39633a31b7ebSMike Smith debug_called(1); 39643a31b7ebSMike Smith 39653a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 39663a31b7ebSMike Smith 39673a31b7ebSMike Smith /* we might want to veto if someone already has us open */ 39683a31b7ebSMike Smith 39693a31b7ebSMike Smith sc->ciss_flags |= CISS_FLAG_CONTROL_OPEN; 39703a31b7ebSMike Smith return(0); 39713a31b7ebSMike Smith } 39723a31b7ebSMike Smith 39733a31b7ebSMike Smith /************************************************************************ 39743a31b7ebSMike Smith * Handle the last close on the control device. 39753a31b7ebSMike Smith */ 39763a31b7ebSMike Smith static int 397789c9c53dSPoul-Henning Kamp ciss_close(struct cdev *dev, int flags, int fmt, d_thread_t *p) 39783a31b7ebSMike Smith { 39793a31b7ebSMike Smith struct ciss_softc *sc; 39803a31b7ebSMike Smith 39813a31b7ebSMike Smith debug_called(1); 39823a31b7ebSMike Smith 39833a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 39843a31b7ebSMike Smith 39853a31b7ebSMike Smith sc->ciss_flags &= ~CISS_FLAG_CONTROL_OPEN; 39863a31b7ebSMike Smith return (0); 39873a31b7ebSMike Smith } 39883a31b7ebSMike Smith 39893a31b7ebSMike Smith /******************************************************************************** 39903a31b7ebSMike Smith * Handle adapter-specific control operations. 39913a31b7ebSMike Smith * 39923a31b7ebSMike Smith * Note that the API here is compatible with the Linux driver, in order to 39933a31b7ebSMike Smith * simplify the porting of Compaq's userland tools. 39943a31b7ebSMike Smith */ 39953a31b7ebSMike Smith static int 399689c9c53dSPoul-Henning Kamp ciss_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, d_thread_t *p) 39973a31b7ebSMike Smith { 39983a31b7ebSMike Smith struct ciss_softc *sc; 39993a31b7ebSMike Smith int error; 40003a31b7ebSMike Smith 40013a31b7ebSMike Smith debug_called(1); 40023a31b7ebSMike Smith 40033a31b7ebSMike Smith sc = (struct ciss_softc *)dev->si_drv1; 40043a31b7ebSMike Smith error = 0; 40053a31b7ebSMike Smith 40063a31b7ebSMike Smith switch(cmd) { 40073a31b7ebSMike Smith case CCISS_GETPCIINFO: 40083a31b7ebSMike Smith { 40093a31b7ebSMike Smith cciss_pci_info_struct *pis = (cciss_pci_info_struct *)addr; 40103a31b7ebSMike Smith 40113a31b7ebSMike Smith pis->bus = pci_get_bus(sc->ciss_dev); 40123a31b7ebSMike Smith pis->dev_fn = pci_get_slot(sc->ciss_dev); 40133a31b7ebSMike Smith pis->board_id = pci_get_devid(sc->ciss_dev); 40143a31b7ebSMike Smith 40153a31b7ebSMike Smith break; 40163a31b7ebSMike Smith } 40173a31b7ebSMike Smith 40183a31b7ebSMike Smith case CCISS_GETINTINFO: 40193a31b7ebSMike Smith { 40203a31b7ebSMike Smith cciss_coalint_struct *cis = (cciss_coalint_struct *)addr; 40213a31b7ebSMike Smith 40223a31b7ebSMike Smith cis->delay = sc->ciss_cfg->interrupt_coalesce_delay; 40233a31b7ebSMike Smith cis->count = sc->ciss_cfg->interrupt_coalesce_count; 40243a31b7ebSMike Smith 40253a31b7ebSMike Smith break; 40263a31b7ebSMike Smith } 40273a31b7ebSMike Smith 40283a31b7ebSMike Smith case CCISS_SETINTINFO: 40293a31b7ebSMike Smith { 40303a31b7ebSMike Smith cciss_coalint_struct *cis = (cciss_coalint_struct *)addr; 40313a31b7ebSMike Smith 40323a31b7ebSMike Smith if ((cis->delay == 0) && (cis->count == 0)) { 40333a31b7ebSMike Smith error = EINVAL; 40343a31b7ebSMike Smith break; 40353a31b7ebSMike Smith } 40363a31b7ebSMike Smith 40373a31b7ebSMike Smith /* 40383a31b7ebSMike Smith * XXX apparently this is only safe if the controller is idle, 40393a31b7ebSMike Smith * we should suspend it before doing this. 40403a31b7ebSMike Smith */ 40413a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_delay = cis->delay; 40423a31b7ebSMike Smith sc->ciss_cfg->interrupt_coalesce_count = cis->count; 40433a31b7ebSMike Smith 40443a31b7ebSMike Smith if (ciss_update_config(sc)) 40453a31b7ebSMike Smith error = EIO; 40463a31b7ebSMike Smith 40473a31b7ebSMike Smith /* XXX resume the controller here */ 40483a31b7ebSMike Smith break; 40493a31b7ebSMike Smith } 40503a31b7ebSMike Smith 40513a31b7ebSMike Smith case CCISS_GETNODENAME: 40523a31b7ebSMike Smith bcopy(sc->ciss_cfg->server_name, (NodeName_type *)addr, 40533a31b7ebSMike Smith sizeof(NodeName_type)); 40543a31b7ebSMike Smith break; 40553a31b7ebSMike Smith 40563a31b7ebSMike Smith case CCISS_SETNODENAME: 40573a31b7ebSMike Smith bcopy((NodeName_type *)addr, sc->ciss_cfg->server_name, 40583a31b7ebSMike Smith sizeof(NodeName_type)); 40593a31b7ebSMike Smith if (ciss_update_config(sc)) 40603a31b7ebSMike Smith error = EIO; 40613a31b7ebSMike Smith break; 40623a31b7ebSMike Smith 40633a31b7ebSMike Smith case CCISS_GETHEARTBEAT: 40643a31b7ebSMike Smith *(Heartbeat_type *)addr = sc->ciss_cfg->heartbeat; 40653a31b7ebSMike Smith break; 40663a31b7ebSMike Smith 40673a31b7ebSMike Smith case CCISS_GETBUSTYPES: 40683a31b7ebSMike Smith *(BusTypes_type *)addr = sc->ciss_cfg->bus_types; 40693a31b7ebSMike Smith break; 40703a31b7ebSMike Smith 40713a31b7ebSMike Smith case CCISS_GETFIRMVER: 40723a31b7ebSMike Smith bcopy(sc->ciss_id->running_firmware_revision, (FirmwareVer_type *)addr, 40733a31b7ebSMike Smith sizeof(FirmwareVer_type)); 40743a31b7ebSMike Smith break; 40753a31b7ebSMike Smith 40763a31b7ebSMike Smith case CCISS_GETDRIVERVER: 40773a31b7ebSMike Smith *(DriverVer_type *)addr = CISS_DRIVER_VERSION; 40783a31b7ebSMike Smith break; 40793a31b7ebSMike Smith 40803a31b7ebSMike Smith case CCISS_REVALIDVOLS: 40813a31b7ebSMike Smith /* 40823a31b7ebSMike Smith * This is a bit ugly; to do it "right" we really need 40833a31b7ebSMike Smith * to find any disks that have changed, kick CAM off them, 40843a31b7ebSMike Smith * then rescan only these disks. It'd be nice if they 40853a31b7ebSMike Smith * a) told us which disk(s) they were going to play with, 40863a31b7ebSMike Smith * and b) which ones had arrived. 8( 40873a31b7ebSMike Smith */ 40883a31b7ebSMike Smith break; 40893a31b7ebSMike Smith 40903a31b7ebSMike Smith case CCISS_PASSTHRU: 40913a31b7ebSMike Smith error = ciss_user_command(sc, (IOCTL_Command_struct *)addr); 40923a31b7ebSMike Smith break; 40933a31b7ebSMike Smith 40943a31b7ebSMike Smith default: 40953a31b7ebSMike Smith debug(0, "unknown ioctl 0x%lx", cmd); 40963a31b7ebSMike Smith 40973a31b7ebSMike Smith debug(1, "CCISS_GETPCIINFO: 0x%lx", CCISS_GETPCIINFO); 40983a31b7ebSMike Smith debug(1, "CCISS_GETINTINFO: 0x%lx", CCISS_GETINTINFO); 40993a31b7ebSMike Smith debug(1, "CCISS_SETINTINFO: 0x%lx", CCISS_SETINTINFO); 41003a31b7ebSMike Smith debug(1, "CCISS_GETNODENAME: 0x%lx", CCISS_GETNODENAME); 41013a31b7ebSMike Smith debug(1, "CCISS_SETNODENAME: 0x%lx", CCISS_SETNODENAME); 41023a31b7ebSMike Smith debug(1, "CCISS_GETHEARTBEAT: 0x%lx", CCISS_GETHEARTBEAT); 41033a31b7ebSMike Smith debug(1, "CCISS_GETBUSTYPES: 0x%lx", CCISS_GETBUSTYPES); 41043a31b7ebSMike Smith debug(1, "CCISS_GETFIRMVER: 0x%lx", CCISS_GETFIRMVER); 41053a31b7ebSMike Smith debug(1, "CCISS_GETDRIVERVER: 0x%lx", CCISS_GETDRIVERVER); 41063a31b7ebSMike Smith debug(1, "CCISS_REVALIDVOLS: 0x%lx", CCISS_REVALIDVOLS); 41073a31b7ebSMike Smith debug(1, "CCISS_PASSTHRU: 0x%lx", CCISS_PASSTHRU); 41083a31b7ebSMike Smith 41093a31b7ebSMike Smith error = ENOIOCTL; 41103a31b7ebSMike Smith break; 41113a31b7ebSMike Smith } 41123a31b7ebSMike Smith 41133a31b7ebSMike Smith return(error); 41143a31b7ebSMike Smith } 4115