1db57feb7SJonathan Lemon /*- 2ee7eb00eSJonathan Lemon * Copyright (c) 1999,2000 Jonathan Lemon 3db57feb7SJonathan Lemon * All rights reserved. 4db57feb7SJonathan Lemon * 5db57feb7SJonathan Lemon # Derived from the original IDA Compaq RAID driver, which is 6db57feb7SJonathan Lemon * Copyright (c) 1996, 1997, 1998, 1999 7db57feb7SJonathan Lemon * Mark Dawson and David James. All rights reserved. 8db57feb7SJonathan Lemon * 9db57feb7SJonathan Lemon * Redistribution and use in source and binary forms, with or without 10db57feb7SJonathan Lemon * modification, are permitted provided that the following conditions 11db57feb7SJonathan Lemon * are met: 12db57feb7SJonathan Lemon * 1. Redistributions of source code must retain the above copyright 13db57feb7SJonathan Lemon * notice, this list of conditions and the following disclaimer. 14db57feb7SJonathan Lemon * 2. Redistributions in binary form must reproduce the above copyright 15db57feb7SJonathan Lemon * notice, this list of conditions and the following disclaimer in the 16db57feb7SJonathan Lemon * documentation and/or other materials provided with the distribution. 17db57feb7SJonathan Lemon * 18db57feb7SJonathan Lemon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19db57feb7SJonathan Lemon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20db57feb7SJonathan Lemon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21db57feb7SJonathan Lemon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22db57feb7SJonathan Lemon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23db57feb7SJonathan Lemon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24db57feb7SJonathan Lemon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25db57feb7SJonathan Lemon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26db57feb7SJonathan Lemon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27db57feb7SJonathan Lemon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28db57feb7SJonathan Lemon * SUCH DAMAGE. 29db57feb7SJonathan Lemon */ 30db57feb7SJonathan Lemon 31aad970f1SDavid E. O'Brien #include <sys/cdefs.h> 32aad970f1SDavid E. O'Brien __FBSDID("$FreeBSD$"); 33aad970f1SDavid E. O'Brien 34db57feb7SJonathan Lemon /* 35db57feb7SJonathan Lemon * Generic driver for Compaq SMART RAID adapters. 36db57feb7SJonathan Lemon */ 37db57feb7SJonathan Lemon 38db57feb7SJonathan Lemon #include <sys/param.h> 3955d782fcSJonathan Lemon #include <sys/kernel.h> 40db57feb7SJonathan Lemon #include <sys/systm.h> 41db57feb7SJonathan Lemon #include <sys/malloc.h> 42a85ce5b6SMatthew N. Dodd #include <sys/stat.h> 43db57feb7SJonathan Lemon 449626b608SPoul-Henning Kamp #include <sys/bio.h> 45db57feb7SJonathan Lemon #include <sys/bus.h> 46e5dc8339SPoul-Henning Kamp #include <sys/conf.h> 47cacc81a6SMatthew N. Dodd #include <sys/endian.h> 48db57feb7SJonathan Lemon 49db57feb7SJonathan Lemon #include <machine/bus_memio.h> 50db57feb7SJonathan Lemon #include <machine/bus_pio.h> 51db57feb7SJonathan Lemon #include <machine/bus.h> 52db57feb7SJonathan Lemon #include <sys/rman.h> 53db57feb7SJonathan Lemon 54891619a6SPoul-Henning Kamp #include <geom/geom_disk.h> 55891619a6SPoul-Henning Kamp 56db57feb7SJonathan Lemon #include <dev/ida/idareg.h> 57db57feb7SJonathan Lemon #include <dev/ida/idavar.h> 58a85ce5b6SMatthew N. Dodd #include <dev/ida/idaio.h> 59db57feb7SJonathan Lemon 60db57feb7SJonathan Lemon /* prototypes */ 61db57feb7SJonathan Lemon static void ida_alloc_qcb(struct ida_softc *ida); 62db57feb7SJonathan Lemon static void ida_construct_qcb(struct ida_softc *ida); 63db57feb7SJonathan Lemon static void ida_start(struct ida_softc *ida); 64db57feb7SJonathan Lemon static void ida_done(struct ida_softc *ida, struct ida_qcb *qcb); 6555d782fcSJonathan Lemon static int ida_wait(struct ida_softc *ida, struct ida_qcb *qcb); 6684339b16SMatthew N. Dodd static void ida_timeout (void *arg); 67db57feb7SJonathan Lemon 68a85ce5b6SMatthew N. Dodd static d_ioctl_t ida_ioctl; 69a85ce5b6SMatthew N. Dodd static struct cdevsw ida_cdevsw = { 70dc08ffecSPoul-Henning Kamp .d_version = D_VERSION, 71dc08ffecSPoul-Henning Kamp .d_flags = D_NEEDGIANT, 72a85ce5b6SMatthew N. Dodd .d_ioctl = ida_ioctl, 73a85ce5b6SMatthew N. Dodd .d_name = "ida", 74a85ce5b6SMatthew N. Dodd }; 75a85ce5b6SMatthew N. Dodd 76db57feb7SJonathan Lemon void 77db57feb7SJonathan Lemon ida_free(struct ida_softc *ida) 78db57feb7SJonathan Lemon { 79ee7eb00eSJonathan Lemon int i; 80db57feb7SJonathan Lemon 8184339b16SMatthew N. Dodd callout_stop(&ida->ch); 8284339b16SMatthew N. Dodd 83ee7eb00eSJonathan Lemon for (i = 0; i < ida->num_qcbs; i++) 84ee7eb00eSJonathan Lemon bus_dmamap_destroy(ida->buffer_dmat, ida->qcbs[i].dmamap); 85db57feb7SJonathan Lemon 86db57feb7SJonathan Lemon if (ida->hwqcb_busaddr) 87db57feb7SJonathan Lemon bus_dmamap_unload(ida->hwqcb_dmat, ida->hwqcb_dmamap); 88db57feb7SJonathan Lemon 89db57feb7SJonathan Lemon if (ida->hwqcbs) 90db57feb7SJonathan Lemon bus_dmamem_free(ida->hwqcb_dmat, ida->hwqcbs, 91db57feb7SJonathan Lemon ida->hwqcb_dmamap); 92db57feb7SJonathan Lemon 93db57feb7SJonathan Lemon if (ida->buffer_dmat) 94db57feb7SJonathan Lemon bus_dma_tag_destroy(ida->buffer_dmat); 95db57feb7SJonathan Lemon 96db57feb7SJonathan Lemon if (ida->hwqcb_dmat) 97db57feb7SJonathan Lemon bus_dma_tag_destroy(ida->hwqcb_dmat); 98db57feb7SJonathan Lemon 99db57feb7SJonathan Lemon if (ida->qcbs != NULL) 100db57feb7SJonathan Lemon free(ida->qcbs, M_DEVBUF); 101db57feb7SJonathan Lemon 102db57feb7SJonathan Lemon if (ida->ih != NULL) 103db57feb7SJonathan Lemon bus_teardown_intr(ida->dev, ida->irq, ida->ih); 104db57feb7SJonathan Lemon 105db57feb7SJonathan Lemon if (ida->irq != NULL) 106db57feb7SJonathan Lemon bus_release_resource(ida->dev, ida->irq_res_type, 107db57feb7SJonathan Lemon 0, ida->irq); 108db57feb7SJonathan Lemon 109db57feb7SJonathan Lemon if (ida->parent_dmat != NULL) 110db57feb7SJonathan Lemon bus_dma_tag_destroy(ida->parent_dmat); 111db57feb7SJonathan Lemon 112db57feb7SJonathan Lemon if (ida->regs != NULL) 113db57feb7SJonathan Lemon bus_release_resource(ida->dev, ida->regs_res_type, 114db57feb7SJonathan Lemon ida->regs_res_id, ida->regs); 115db57feb7SJonathan Lemon } 116db57feb7SJonathan Lemon 117db57feb7SJonathan Lemon /* 118db57feb7SJonathan Lemon * record bus address from bus_dmamap_load 119db57feb7SJonathan Lemon */ 120db57feb7SJonathan Lemon static void 121db57feb7SJonathan Lemon ida_dma_map_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) 122db57feb7SJonathan Lemon { 123db57feb7SJonathan Lemon bus_addr_t *baddr; 124db57feb7SJonathan Lemon 125db57feb7SJonathan Lemon baddr = (bus_addr_t *)arg; 126db57feb7SJonathan Lemon *baddr = segs->ds_addr; 127db57feb7SJonathan Lemon } 128db57feb7SJonathan Lemon 129db57feb7SJonathan Lemon static __inline struct ida_qcb * 130db57feb7SJonathan Lemon ida_get_qcb(struct ida_softc *ida) 131db57feb7SJonathan Lemon { 132db57feb7SJonathan Lemon struct ida_qcb *qcb; 133db57feb7SJonathan Lemon 134db57feb7SJonathan Lemon if ((qcb = SLIST_FIRST(&ida->free_qcbs)) != NULL) { 135db57feb7SJonathan Lemon SLIST_REMOVE_HEAD(&ida->free_qcbs, link.sle); 136db57feb7SJonathan Lemon } else { 137db57feb7SJonathan Lemon ida_alloc_qcb(ida); 138db57feb7SJonathan Lemon if ((qcb = SLIST_FIRST(&ida->free_qcbs)) != NULL) 139db57feb7SJonathan Lemon SLIST_REMOVE_HEAD(&ida->free_qcbs, link.sle); 140db57feb7SJonathan Lemon } 141db57feb7SJonathan Lemon return (qcb); 142db57feb7SJonathan Lemon } 143db57feb7SJonathan Lemon 144ee7eb00eSJonathan Lemon static __inline bus_addr_t 145ee7eb00eSJonathan Lemon idahwqcbvtop(struct ida_softc *ida, struct ida_hardware_qcb *hwqcb) 146ee7eb00eSJonathan Lemon { 147ee7eb00eSJonathan Lemon return (ida->hwqcb_busaddr + 148ee7eb00eSJonathan Lemon ((bus_addr_t)hwqcb - (bus_addr_t)ida->hwqcbs)); 149ee7eb00eSJonathan Lemon } 150ee7eb00eSJonathan Lemon 151ee7eb00eSJonathan Lemon static __inline struct ida_qcb * 152ee7eb00eSJonathan Lemon idahwqcbptov(struct ida_softc *ida, bus_addr_t hwqcb_addr) 153ee7eb00eSJonathan Lemon { 154ee7eb00eSJonathan Lemon struct ida_hardware_qcb *hwqcb; 155ee7eb00eSJonathan Lemon 156ee7eb00eSJonathan Lemon hwqcb = (struct ida_hardware_qcb *) 157ee7eb00eSJonathan Lemon ((bus_addr_t)ida->hwqcbs + (hwqcb_addr - ida->hwqcb_busaddr)); 158ee7eb00eSJonathan Lemon return (hwqcb->qcb); 159ee7eb00eSJonathan Lemon } 160ee7eb00eSJonathan Lemon 161db57feb7SJonathan Lemon /* 162db57feb7SJonathan Lemon * XXX 163db57feb7SJonathan Lemon * since we allocate all QCB space up front during initialization, then 164db57feb7SJonathan Lemon * why bother with this routine? 165db57feb7SJonathan Lemon */ 166db57feb7SJonathan Lemon static void 167db57feb7SJonathan Lemon ida_alloc_qcb(struct ida_softc *ida) 168db57feb7SJonathan Lemon { 169db57feb7SJonathan Lemon struct ida_qcb *qcb; 170db57feb7SJonathan Lemon int error; 171db57feb7SJonathan Lemon 172db57feb7SJonathan Lemon if (ida->num_qcbs >= IDA_QCB_MAX) 173db57feb7SJonathan Lemon return; 174db57feb7SJonathan Lemon 175db57feb7SJonathan Lemon qcb = &ida->qcbs[ida->num_qcbs]; 176db57feb7SJonathan Lemon 177db57feb7SJonathan Lemon error = bus_dmamap_create(ida->buffer_dmat, /*flags*/0, &qcb->dmamap); 178db57feb7SJonathan Lemon if (error != 0) 179db57feb7SJonathan Lemon return; 180db57feb7SJonathan Lemon 181db57feb7SJonathan Lemon qcb->flags = QCB_FREE; 182db57feb7SJonathan Lemon qcb->hwqcb = &ida->hwqcbs[ida->num_qcbs]; 183db57feb7SJonathan Lemon qcb->hwqcb->qcb = qcb; 184ee7eb00eSJonathan Lemon qcb->hwqcb_busaddr = idahwqcbvtop(ida, qcb->hwqcb); 185db57feb7SJonathan Lemon SLIST_INSERT_HEAD(&ida->free_qcbs, qcb, link.sle); 186db57feb7SJonathan Lemon ida->num_qcbs++; 187db57feb7SJonathan Lemon } 188db57feb7SJonathan Lemon 189db57feb7SJonathan Lemon int 190db57feb7SJonathan Lemon ida_init(struct ida_softc *ida) 191db57feb7SJonathan Lemon { 192db57feb7SJonathan Lemon int error; 193db57feb7SJonathan Lemon 194db57feb7SJonathan Lemon ida->unit = device_get_unit(ida->dev); 195db57feb7SJonathan Lemon ida->tag = rman_get_bustag(ida->regs); 196db57feb7SJonathan Lemon ida->bsh = rman_get_bushandle(ida->regs); 197db57feb7SJonathan Lemon 198db57feb7SJonathan Lemon SLIST_INIT(&ida->free_qcbs); 199db57feb7SJonathan Lemon STAILQ_INIT(&ida->qcb_queue); 2008177437dSPoul-Henning Kamp bioq_init(&ida->bio_queue); 201db57feb7SJonathan Lemon 202db57feb7SJonathan Lemon ida->qcbs = (struct ida_qcb *) 2037cc0979fSDavid Malone malloc(IDA_QCB_MAX * sizeof(struct ida_qcb), M_DEVBUF, 2047cc0979fSDavid Malone M_NOWAIT | M_ZERO); 205db57feb7SJonathan Lemon if (ida->qcbs == NULL) 206db57feb7SJonathan Lemon return (ENOMEM); 207db57feb7SJonathan Lemon 208db57feb7SJonathan Lemon /* 209db57feb7SJonathan Lemon * Create our DMA tags 210db57feb7SJonathan Lemon */ 211db57feb7SJonathan Lemon 212db57feb7SJonathan Lemon /* DMA tag for our hardware QCB structures */ 213b75ab906SMatthew N. Dodd error = bus_dma_tag_create( 214b75ab906SMatthew N. Dodd /* parent */ ida->parent_dmat, 215b75ab906SMatthew N. Dodd /* alignment */ 1, 216b75ab906SMatthew N. Dodd /* boundary */ 0, 217b75ab906SMatthew N. Dodd /* lowaddr */ BUS_SPACE_MAXADDR, 218b75ab906SMatthew N. Dodd /* highaddr */ BUS_SPACE_MAXADDR, 219b75ab906SMatthew N. Dodd /* filter */ NULL, 220b75ab906SMatthew N. Dodd /* filterarg */ NULL, 221b75ab906SMatthew N. Dodd /* maxsize */ IDA_QCB_MAX * sizeof(struct ida_hardware_qcb), 222b75ab906SMatthew N. Dodd /* nsegments */ 1, 223b75ab906SMatthew N. Dodd /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, 224b75ab906SMatthew N. Dodd /* flags */ 0, 225b75ab906SMatthew N. Dodd /* lockfunc */ busdma_lock_mutex, 226b75ab906SMatthew N. Dodd /* lockarg */ &Giant, 227f6b1c44dSScott Long &ida->hwqcb_dmat); 228db57feb7SJonathan Lemon if (error) 229db57feb7SJonathan Lemon return (ENOMEM); 230db57feb7SJonathan Lemon 231db57feb7SJonathan Lemon /* DMA tag for mapping buffers into device space */ 232b75ab906SMatthew N. Dodd error = bus_dma_tag_create( 233b75ab906SMatthew N. Dodd /* parent */ ida->parent_dmat, 234b75ab906SMatthew N. Dodd /* alignment */ 1, 235b75ab906SMatthew N. Dodd /* boundary */ 0, 236b75ab906SMatthew N. Dodd /* lowaddr */ BUS_SPACE_MAXADDR, 237b75ab906SMatthew N. Dodd /* highaddr */ BUS_SPACE_MAXADDR, 238b75ab906SMatthew N. Dodd /* filter */ NULL, 239b75ab906SMatthew N. Dodd /* filterarg */ NULL, 240b75ab906SMatthew N. Dodd /* maxsize */ MAXBSIZE, 241b75ab906SMatthew N. Dodd /* nsegments */ IDA_NSEG, 242b75ab906SMatthew N. Dodd /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT, 243b75ab906SMatthew N. Dodd /* flags */ 0, 244b75ab906SMatthew N. Dodd /* lockfunc */ busdma_lock_mutex, 245b75ab906SMatthew N. Dodd /* lockarg */ &Giant, 246b75ab906SMatthew N. Dodd &ida->buffer_dmat); 247db57feb7SJonathan Lemon if (error) 248db57feb7SJonathan Lemon return (ENOMEM); 249db57feb7SJonathan Lemon 250db57feb7SJonathan Lemon /* Allocation of hardware QCBs */ 251db57feb7SJonathan Lemon /* XXX allocation is rounded to hardware page size */ 252db57feb7SJonathan Lemon error = bus_dmamem_alloc(ida->hwqcb_dmat, 253db57feb7SJonathan Lemon (void **)&ida->hwqcbs, BUS_DMA_NOWAIT, &ida->hwqcb_dmamap); 254db57feb7SJonathan Lemon if (error) 255db57feb7SJonathan Lemon return (ENOMEM); 256db57feb7SJonathan Lemon 257db57feb7SJonathan Lemon /* And permanently map them in */ 258db57feb7SJonathan Lemon bus_dmamap_load(ida->hwqcb_dmat, ida->hwqcb_dmamap, 259db57feb7SJonathan Lemon ida->hwqcbs, IDA_QCB_MAX * sizeof(struct ida_hardware_qcb), 260db57feb7SJonathan Lemon ida_dma_map_cb, &ida->hwqcb_busaddr, /*flags*/0); 261db57feb7SJonathan Lemon 262db57feb7SJonathan Lemon bzero(ida->hwqcbs, IDA_QCB_MAX * sizeof(struct ida_hardware_qcb)); 263db57feb7SJonathan Lemon 264db57feb7SJonathan Lemon ida_alloc_qcb(ida); /* allocate an initial qcb */ 265db57feb7SJonathan Lemon 26684339b16SMatthew N. Dodd callout_init(&ida->ch, CALLOUT_MPSAFE); 26784339b16SMatthew N. Dodd 268db57feb7SJonathan Lemon return (0); 269db57feb7SJonathan Lemon } 270db57feb7SJonathan Lemon 271db57feb7SJonathan Lemon void 272db57feb7SJonathan Lemon ida_attach(struct ida_softc *ida) 273db57feb7SJonathan Lemon { 274db57feb7SJonathan Lemon struct ida_controller_info cinfo; 275db57feb7SJonathan Lemon int error, i; 276db57feb7SJonathan Lemon 277ee7eb00eSJonathan Lemon ida->cmd.int_enable(ida, 0); 278db57feb7SJonathan Lemon 279db57feb7SJonathan Lemon error = ida_command(ida, CMD_GET_CTRL_INFO, &cinfo, sizeof(cinfo), 28055d782fcSJonathan Lemon IDA_CONTROLLER, 0, DMA_DATA_IN); 281db57feb7SJonathan Lemon if (error) { 282db57feb7SJonathan Lemon device_printf(ida->dev, "CMD_GET_CTRL_INFO failed.\n"); 283db57feb7SJonathan Lemon return; 284db57feb7SJonathan Lemon } 285db57feb7SJonathan Lemon 286db57feb7SJonathan Lemon device_printf(ida->dev, "drives=%d firm_rev=%c%c%c%c\n", 287db57feb7SJonathan Lemon cinfo.num_drvs, cinfo.firm_rev[0], cinfo.firm_rev[1], 288db57feb7SJonathan Lemon cinfo.firm_rev[2], cinfo.firm_rev[3]); 289db57feb7SJonathan Lemon 2901277c3baSJonathan Lemon if (ida->flags & IDA_FIRMWARE) { 2911277c3baSJonathan Lemon int data; 292db57feb7SJonathan Lemon 2931277c3baSJonathan Lemon error = ida_command(ida, CMD_START_FIRMWARE, 29455d782fcSJonathan Lemon &data, sizeof(data), IDA_CONTROLLER, 0, DMA_DATA_IN); 2951277c3baSJonathan Lemon if (error) { 2961277c3baSJonathan Lemon device_printf(ida->dev, "CMD_START_FIRMWARE failed.\n"); 2971277c3baSJonathan Lemon return; 2981277c3baSJonathan Lemon } 2991277c3baSJonathan Lemon } 3001277c3baSJonathan Lemon 301a85ce5b6SMatthew N. Dodd ida->ida_dev_t = make_dev(&ida_cdevsw, ida->unit, 302a85ce5b6SMatthew N. Dodd UID_ROOT, GID_OPERATOR, S_IRUSR | S_IWUSR, 303a85ce5b6SMatthew N. Dodd "ida%d", ida->unit); 304a85ce5b6SMatthew N. Dodd ida->ida_dev_t->si_drv1 = ida; 305a85ce5b6SMatthew N. Dodd 3061277c3baSJonathan Lemon ida->num_drives = 0; 3071277c3baSJonathan Lemon for (i = 0; i < cinfo.num_drvs; i++) 308ee7eb00eSJonathan Lemon device_add_child(ida->dev, /*"idad"*/NULL, -1); 309db57feb7SJonathan Lemon 310db57feb7SJonathan Lemon bus_generic_attach(ida->dev); 311db57feb7SJonathan Lemon 312ee7eb00eSJonathan Lemon ida->cmd.int_enable(ida, 1); 313ee7eb00eSJonathan Lemon } 314ee7eb00eSJonathan Lemon 315ee7eb00eSJonathan Lemon int 316ee7eb00eSJonathan Lemon ida_detach(device_t dev) 317ee7eb00eSJonathan Lemon { 318ee7eb00eSJonathan Lemon struct ida_softc *ida; 319ee7eb00eSJonathan Lemon int error = 0; 320ee7eb00eSJonathan Lemon 321ee7eb00eSJonathan Lemon ida = (struct ida_softc *)device_get_softc(dev); 322ee7eb00eSJonathan Lemon 323ee7eb00eSJonathan Lemon /* 324ee7eb00eSJonathan Lemon * XXX 325ee7eb00eSJonathan Lemon * before detaching, we must make sure that the system is 326ee7eb00eSJonathan Lemon * quiescent; nothing mounted, no pending activity. 327ee7eb00eSJonathan Lemon */ 328ee7eb00eSJonathan Lemon 329ee7eb00eSJonathan Lemon /* 330ee7eb00eSJonathan Lemon * XXX 331ee7eb00eSJonathan Lemon * now, how are we supposed to maintain a list of our drives? 332ee7eb00eSJonathan Lemon * iterate over our "child devices"? 333ee7eb00eSJonathan Lemon */ 334ee7eb00eSJonathan Lemon 335a85ce5b6SMatthew N. Dodd destroy_dev(ida->ida_dev_t); 336ee7eb00eSJonathan Lemon ida_free(ida); 337ee7eb00eSJonathan Lemon return (error); 338db57feb7SJonathan Lemon } 339db57feb7SJonathan Lemon 340db57feb7SJonathan Lemon static void 341db57feb7SJonathan Lemon ida_setup_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error) 342db57feb7SJonathan Lemon { 343db57feb7SJonathan Lemon struct ida_hardware_qcb *hwqcb = (struct ida_hardware_qcb *)arg; 344db57feb7SJonathan Lemon int i; 345db57feb7SJonathan Lemon 346cacc81a6SMatthew N. Dodd hwqcb->hdr.size = htole16((sizeof(struct ida_req) + 347cacc81a6SMatthew N. Dodd sizeof(struct ida_sgb) * IDA_NSEG) >> 2); 348db57feb7SJonathan Lemon 349db57feb7SJonathan Lemon for (i = 0; i < nsegments; i++) { 350cacc81a6SMatthew N. Dodd hwqcb->seg[i].addr = htole32(segs[i].ds_addr); 351cacc81a6SMatthew N. Dodd hwqcb->seg[i].length = htole32(segs[i].ds_len); 352db57feb7SJonathan Lemon } 353db57feb7SJonathan Lemon hwqcb->req.sgcount = nsegments; 354db57feb7SJonathan Lemon } 355db57feb7SJonathan Lemon 356db57feb7SJonathan Lemon int 357db57feb7SJonathan Lemon ida_command(struct ida_softc *ida, int command, void *data, int datasize, 35855d782fcSJonathan Lemon int drive, u_int32_t pblkno, int flags) 359db57feb7SJonathan Lemon { 360db57feb7SJonathan Lemon struct ida_hardware_qcb *hwqcb; 361db57feb7SJonathan Lemon struct ida_qcb *qcb; 3627e71df93SScott Long bus_dmasync_op_t op; 36355d782fcSJonathan Lemon int s, error; 364db57feb7SJonathan Lemon 365db57feb7SJonathan Lemon s = splbio(); 366db57feb7SJonathan Lemon qcb = ida_get_qcb(ida); 367db57feb7SJonathan Lemon splx(s); 368db57feb7SJonathan Lemon 369db57feb7SJonathan Lemon if (qcb == NULL) { 370db57feb7SJonathan Lemon printf("ida_command: out of QCBs"); 37155d782fcSJonathan Lemon return (EAGAIN); 372db57feb7SJonathan Lemon } 373db57feb7SJonathan Lemon 374db57feb7SJonathan Lemon hwqcb = qcb->hwqcb; 375db57feb7SJonathan Lemon bzero(hwqcb, sizeof(struct ida_hdr) + sizeof(struct ida_req)); 376db57feb7SJonathan Lemon 377db57feb7SJonathan Lemon bus_dmamap_load(ida->buffer_dmat, qcb->dmamap, 378db57feb7SJonathan Lemon (void *)data, datasize, ida_setup_dmamap, hwqcb, 0); 379db57feb7SJonathan Lemon op = qcb->flags & DMA_DATA_IN ? 380db57feb7SJonathan Lemon BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE; 381db57feb7SJonathan Lemon bus_dmamap_sync(ida->buffer_dmat, qcb->dmamap, op); 382db57feb7SJonathan Lemon 3831277c3baSJonathan Lemon hwqcb->hdr.drive = drive; 384cacc81a6SMatthew N. Dodd hwqcb->req.blkno = htole32(pblkno); 385cacc81a6SMatthew N. Dodd hwqcb->req.bcount = htole16(howmany(datasize, DEV_BSIZE)); 386db57feb7SJonathan Lemon hwqcb->req.command = command; 387db57feb7SJonathan Lemon 388db57feb7SJonathan Lemon qcb->flags = flags | IDA_COMMAND; 389db57feb7SJonathan Lemon 390db57feb7SJonathan Lemon s = splbio(); 391db57feb7SJonathan Lemon STAILQ_INSERT_TAIL(&ida->qcb_queue, qcb, link.stqe); 392db57feb7SJonathan Lemon ida_start(ida); 39355d782fcSJonathan Lemon error = ida_wait(ida, qcb); 394db57feb7SJonathan Lemon splx(s); 395db57feb7SJonathan Lemon 396db57feb7SJonathan Lemon /* XXX should have status returned here? */ 397db57feb7SJonathan Lemon /* XXX have "status pointer" area in QCB? */ 398db57feb7SJonathan Lemon 39955d782fcSJonathan Lemon return (error); 400db57feb7SJonathan Lemon } 401db57feb7SJonathan Lemon 402db57feb7SJonathan Lemon void 4038177437dSPoul-Henning Kamp ida_submit_buf(struct ida_softc *ida, struct bio *bp) 404db57feb7SJonathan Lemon { 4058177437dSPoul-Henning Kamp bioq_insert_tail(&ida->bio_queue, bp); 406db57feb7SJonathan Lemon ida_construct_qcb(ida); 407db57feb7SJonathan Lemon ida_start(ida); 408db57feb7SJonathan Lemon } 409db57feb7SJonathan Lemon 410db57feb7SJonathan Lemon static void 411db57feb7SJonathan Lemon ida_construct_qcb(struct ida_softc *ida) 412db57feb7SJonathan Lemon { 413db57feb7SJonathan Lemon struct ida_hardware_qcb *hwqcb; 414db57feb7SJonathan Lemon struct ida_qcb *qcb; 4157e71df93SScott Long bus_dmasync_op_t op; 4168177437dSPoul-Henning Kamp struct bio *bp; 417db57feb7SJonathan Lemon 4188177437dSPoul-Henning Kamp bp = bioq_first(&ida->bio_queue); 419db57feb7SJonathan Lemon if (bp == NULL) 420db57feb7SJonathan Lemon return; /* no more buffers */ 421db57feb7SJonathan Lemon 422db57feb7SJonathan Lemon qcb = ida_get_qcb(ida); 423db57feb7SJonathan Lemon if (qcb == NULL) 424db57feb7SJonathan Lemon return; /* out of resources */ 425db57feb7SJonathan Lemon 4268177437dSPoul-Henning Kamp bioq_remove(&ida->bio_queue, bp); 427db57feb7SJonathan Lemon qcb->buf = bp; 42868d2672dSMatthew N. Dodd qcb->flags = bp->bio_cmd == BIO_READ ? DMA_DATA_IN : DMA_DATA_OUT; 429db57feb7SJonathan Lemon 430db57feb7SJonathan Lemon hwqcb = qcb->hwqcb; 431db57feb7SJonathan Lemon bzero(hwqcb, sizeof(struct ida_hdr) + sizeof(struct ida_req)); 432db57feb7SJonathan Lemon 433db57feb7SJonathan Lemon bus_dmamap_load(ida->buffer_dmat, qcb->dmamap, 4348177437dSPoul-Henning Kamp (void *)bp->bio_data, bp->bio_bcount, ida_setup_dmamap, hwqcb, 0); 435db57feb7SJonathan Lemon op = qcb->flags & DMA_DATA_IN ? 436db57feb7SJonathan Lemon BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE; 437db57feb7SJonathan Lemon bus_dmamap_sync(ida->buffer_dmat, qcb->dmamap, op); 438db57feb7SJonathan Lemon 439db57feb7SJonathan Lemon { 44081530866SMatthew N. Dodd struct idad_softc *drv = (struct idad_softc *)bp->bio_driver1; 4411277c3baSJonathan Lemon hwqcb->hdr.drive = drv->drive; 442db57feb7SJonathan Lemon } 443db57feb7SJonathan Lemon 4448177437dSPoul-Henning Kamp hwqcb->req.blkno = bp->bio_pblkno; 4458177437dSPoul-Henning Kamp hwqcb->req.bcount = howmany(bp->bio_bcount, DEV_BSIZE); 4468177437dSPoul-Henning Kamp hwqcb->req.command = bp->bio_cmd == BIO_READ ? CMD_READ : CMD_WRITE; 447db57feb7SJonathan Lemon 448db57feb7SJonathan Lemon STAILQ_INSERT_TAIL(&ida->qcb_queue, qcb, link.stqe); 449db57feb7SJonathan Lemon } 450db57feb7SJonathan Lemon 451db57feb7SJonathan Lemon /* 452db57feb7SJonathan Lemon * This routine will be called from ida_intr in order to queue up more 453db57feb7SJonathan Lemon * I/O, meaning that we may be in an interrupt context. Hence, we should 454db57feb7SJonathan Lemon * not muck around with spl() in this routine. 455db57feb7SJonathan Lemon */ 456db57feb7SJonathan Lemon static void 457db57feb7SJonathan Lemon ida_start(struct ida_softc *ida) 458db57feb7SJonathan Lemon { 459db57feb7SJonathan Lemon struct ida_qcb *qcb; 460db57feb7SJonathan Lemon 461db57feb7SJonathan Lemon while ((qcb = STAILQ_FIRST(&ida->qcb_queue)) != NULL) { 462ee7eb00eSJonathan Lemon if (ida->cmd.fifo_full(ida)) 463ee7eb00eSJonathan Lemon break; 464db57feb7SJonathan Lemon STAILQ_REMOVE_HEAD(&ida->qcb_queue, link.stqe); 465db57feb7SJonathan Lemon /* 466db57feb7SJonathan Lemon * XXX 46784339b16SMatthew N. Dodd * place the qcb on an active list? 468db57feb7SJonathan Lemon */ 46984339b16SMatthew N. Dodd 47084339b16SMatthew N. Dodd /* Set a timeout. */ 47184339b16SMatthew N. Dodd if (!ida->qactive) 47284339b16SMatthew N. Dodd callout_reset(&ida->ch, hz * 5, ida_timeout, ida); 47384339b16SMatthew N. Dodd ida->qactive++; 47484339b16SMatthew N. Dodd 475db57feb7SJonathan Lemon qcb->state = QCB_ACTIVE; 476ee7eb00eSJonathan Lemon ida->cmd.submit(ida, qcb); 477db57feb7SJonathan Lemon } 478db57feb7SJonathan Lemon } 479db57feb7SJonathan Lemon 48055d782fcSJonathan Lemon static int 48155d782fcSJonathan Lemon ida_wait(struct ida_softc *ida, struct ida_qcb *qcb) 482db57feb7SJonathan Lemon { 483db57feb7SJonathan Lemon struct ida_qcb *qcb_done = NULL; 484db57feb7SJonathan Lemon bus_addr_t completed; 48555d782fcSJonathan Lemon int delay; 486db57feb7SJonathan Lemon 48755d782fcSJonathan Lemon if (ida->flags & IDA_INTERRUPTS) { 488521f364bSDag-Erling Smørgrav if (tsleep(qcb, PRIBIO, "idacmd", 5 * hz)) 48955d782fcSJonathan Lemon return (ETIMEDOUT); 49055d782fcSJonathan Lemon return (0); 491db57feb7SJonathan Lemon } 492db57feb7SJonathan Lemon 49355d782fcSJonathan Lemon again: 49455d782fcSJonathan Lemon delay = 5 * 1000 * 100; /* 5 sec delay */ 495ee7eb00eSJonathan Lemon while ((completed = ida->cmd.done(ida)) == 0) { 496db57feb7SJonathan Lemon if (delay-- == 0) 49755d782fcSJonathan Lemon return (ETIMEDOUT); 498db57feb7SJonathan Lemon DELAY(10); 499db57feb7SJonathan Lemon } 500db57feb7SJonathan Lemon 501db57feb7SJonathan Lemon qcb_done = idahwqcbptov(ida, completed & ~3); 502db57feb7SJonathan Lemon if (qcb_done != qcb) 50355d782fcSJonathan Lemon goto again; 504db57feb7SJonathan Lemon ida_done(ida, qcb); 50555d782fcSJonathan Lemon return (0); 506db57feb7SJonathan Lemon } 507db57feb7SJonathan Lemon 508db57feb7SJonathan Lemon void 509db57feb7SJonathan Lemon ida_intr(void *data) 510db57feb7SJonathan Lemon { 511db57feb7SJonathan Lemon struct ida_softc *ida; 512db57feb7SJonathan Lemon struct ida_qcb *qcb; 513db57feb7SJonathan Lemon bus_addr_t completed; 514db57feb7SJonathan Lemon 515db57feb7SJonathan Lemon ida = (struct ida_softc *)data; 516db57feb7SJonathan Lemon 517ee7eb00eSJonathan Lemon if (ida->cmd.int_pending(ida) == 0) 518db57feb7SJonathan Lemon return; /* not our interrupt */ 519db57feb7SJonathan Lemon 520ee7eb00eSJonathan Lemon while ((completed = ida->cmd.done(ida)) != 0) { 521db57feb7SJonathan Lemon qcb = idahwqcbptov(ida, completed & ~3); 522db57feb7SJonathan Lemon 523db57feb7SJonathan Lemon if (qcb == NULL || qcb->state != QCB_ACTIVE) { 524db57feb7SJonathan Lemon device_printf(ida->dev, 525482a5259SJohn Baldwin "ignoring completion %jx\n", (intmax_t)completed); 526db57feb7SJonathan Lemon continue; 527db57feb7SJonathan Lemon } 528a14b52feSMatthew N. Dodd /* Handle "Bad Command List" errors. */ 529a14b52feSMatthew N. Dodd if ((completed & 3) && (qcb->hwqcb->req.error == 0)) 530a14b52feSMatthew N. Dodd qcb->hwqcb->req.error = CMD_REJECTED; 531db57feb7SJonathan Lemon ida_done(ida, qcb); 532db57feb7SJonathan Lemon } 533db57feb7SJonathan Lemon ida_start(ida); 534db57feb7SJonathan Lemon } 535db57feb7SJonathan Lemon 536db57feb7SJonathan Lemon /* 537db57feb7SJonathan Lemon * should switch out command type; may be status, not just I/O. 538db57feb7SJonathan Lemon */ 539db57feb7SJonathan Lemon static void 540db57feb7SJonathan Lemon ida_done(struct ida_softc *ida, struct ida_qcb *qcb) 541db57feb7SJonathan Lemon { 542db57feb7SJonathan Lemon int error = 0; 543db57feb7SJonathan Lemon 544db57feb7SJonathan Lemon /* 545db57feb7SJonathan Lemon * finish up command 546db57feb7SJonathan Lemon */ 547db57feb7SJonathan Lemon if (qcb->flags & DMA_DATA_TRANSFER) { 5487e71df93SScott Long bus_dmasync_op_t op; 549db57feb7SJonathan Lemon 550db57feb7SJonathan Lemon op = qcb->flags & DMA_DATA_IN ? 551db57feb7SJonathan Lemon BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE; 552db57feb7SJonathan Lemon bus_dmamap_sync(ida->buffer_dmat, qcb->dmamap, op); 553db57feb7SJonathan Lemon bus_dmamap_unload(ida->buffer_dmat, qcb->dmamap); 554db57feb7SJonathan Lemon } 555db57feb7SJonathan Lemon 55668d2672dSMatthew N. Dodd if (qcb->hwqcb->req.error & SOFT_ERROR) { 55768d2672dSMatthew N. Dodd if (qcb->buf) 55868d2672dSMatthew N. Dodd device_printf(ida->dev, "soft %s error\n", 55968d2672dSMatthew N. Dodd qcb->buf->bio_cmd == BIO_READ ? 56068d2672dSMatthew N. Dodd "read" : "write"); 56168d2672dSMatthew N. Dodd else 562db57feb7SJonathan Lemon device_printf(ida->dev, "soft error\n"); 56368d2672dSMatthew N. Dodd } 564db57feb7SJonathan Lemon if (qcb->hwqcb->req.error & HARD_ERROR) { 565db57feb7SJonathan Lemon error = 1; 56668d2672dSMatthew N. Dodd if (qcb->buf) 56768d2672dSMatthew N. Dodd device_printf(ida->dev, "hard %s error\n", 56868d2672dSMatthew N. Dodd qcb->buf->bio_cmd == BIO_READ ? 56968d2672dSMatthew N. Dodd "read" : "write"); 57068d2672dSMatthew N. Dodd else 571db57feb7SJonathan Lemon device_printf(ida->dev, "hard error\n"); 572db57feb7SJonathan Lemon } 573db57feb7SJonathan Lemon if (qcb->hwqcb->req.error & CMD_REJECTED) { 574db57feb7SJonathan Lemon error = 1; 575db57feb7SJonathan Lemon device_printf(ida->dev, "invalid request\n"); 576db57feb7SJonathan Lemon } 577db57feb7SJonathan Lemon 578db57feb7SJonathan Lemon if (qcb->flags & IDA_COMMAND) { 57955d782fcSJonathan Lemon if (ida->flags & IDA_INTERRUPTS) 580db57feb7SJonathan Lemon wakeup(qcb); 581db57feb7SJonathan Lemon } else { 582682249c0SMatthew N. Dodd KASSERT(qcb->buf != NULL, ("ida_done(): qcb->buf is NULL!")); 583db57feb7SJonathan Lemon if (error) 5848177437dSPoul-Henning Kamp qcb->buf->bio_flags |= BIO_ERROR; 58581530866SMatthew N. Dodd idad_intr(qcb->buf); 586db57feb7SJonathan Lemon } 587db57feb7SJonathan Lemon 58884339b16SMatthew N. Dodd ida->qactive--; 58984339b16SMatthew N. Dodd /* Reschedule or cancel timeout */ 59084339b16SMatthew N. Dodd if (ida->qactive) 59184339b16SMatthew N. Dodd callout_reset(&ida->ch, hz * 5, ida_timeout, ida); 59284339b16SMatthew N. Dodd else 59384339b16SMatthew N. Dodd callout_stop(&ida->ch); 59484339b16SMatthew N. Dodd 595db57feb7SJonathan Lemon qcb->state = QCB_FREE; 59668d2672dSMatthew N. Dodd qcb->buf = NULL; 597db57feb7SJonathan Lemon SLIST_INSERT_HEAD(&ida->free_qcbs, qcb, link.sle); 598db57feb7SJonathan Lemon ida_construct_qcb(ida); 599db57feb7SJonathan Lemon } 600a85ce5b6SMatthew N. Dodd 60184339b16SMatthew N. Dodd static void 60284339b16SMatthew N. Dodd ida_timeout (void *arg) 60384339b16SMatthew N. Dodd { 60484339b16SMatthew N. Dodd struct ida_softc *ida; 60584339b16SMatthew N. Dodd 60684339b16SMatthew N. Dodd ida = (struct ida_softc *)arg; 60784339b16SMatthew N. Dodd device_printf(ida->dev, "%s() qactive %d\n", __func__, ida->qactive); 60884339b16SMatthew N. Dodd 60984339b16SMatthew N. Dodd if (ida->flags & IDA_INTERRUPTS) 61084339b16SMatthew N. Dodd device_printf(ida->dev, "IDA_INTERRUPTS\n"); 61184339b16SMatthew N. Dodd 61284339b16SMatthew N. Dodd device_printf(ida->dev, "\t R_CMD_FIFO: %08x\n" 61384339b16SMatthew N. Dodd "\t R_DONE_FIFO: %08x\n" 61484339b16SMatthew N. Dodd "\t R_INT_MASK: %08x\n" 61584339b16SMatthew N. Dodd "\t R_STATUS: %08x\n" 61684339b16SMatthew N. Dodd "\tR_INT_PENDING: %08x\n", 61784339b16SMatthew N. Dodd ida_inl(ida, R_CMD_FIFO), 61884339b16SMatthew N. Dodd ida_inl(ida, R_DONE_FIFO), 61984339b16SMatthew N. Dodd ida_inl(ida, R_INT_MASK), 62084339b16SMatthew N. Dodd ida_inl(ida, R_STATUS), 62184339b16SMatthew N. Dodd ida_inl(ida, R_INT_PENDING)); 62284339b16SMatthew N. Dodd 62384339b16SMatthew N. Dodd return; 62484339b16SMatthew N. Dodd } 62584339b16SMatthew N. Dodd 626a85ce5b6SMatthew N. Dodd /* 627a85ce5b6SMatthew N. Dodd * IOCTL stuff follows. 628a85ce5b6SMatthew N. Dodd */ 629a85ce5b6SMatthew N. Dodd struct cmd_info { 630a85ce5b6SMatthew N. Dodd int cmd; 631a85ce5b6SMatthew N. Dodd int len; 632a85ce5b6SMatthew N. Dodd int flags; 633a85ce5b6SMatthew N. Dodd }; 634a85ce5b6SMatthew N. Dodd static struct cmd_info *ida_cmd_lookup(int); 635a85ce5b6SMatthew N. Dodd 636a85ce5b6SMatthew N. Dodd static int 63789c9c53dSPoul-Henning Kamp ida_ioctl (struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td) 638a85ce5b6SMatthew N. Dodd { 639a85ce5b6SMatthew N. Dodd struct ida_softc *sc; 640a85ce5b6SMatthew N. Dodd struct ida_user_command *uc; 641a85ce5b6SMatthew N. Dodd struct cmd_info *ci; 642a85ce5b6SMatthew N. Dodd int len; 643a85ce5b6SMatthew N. Dodd int flags; 644a85ce5b6SMatthew N. Dodd int error; 645a85ce5b6SMatthew N. Dodd int data; 646a85ce5b6SMatthew N. Dodd void *daddr; 647a85ce5b6SMatthew N. Dodd 648a85ce5b6SMatthew N. Dodd sc = (struct ida_softc *)dev->si_drv1; 649a85ce5b6SMatthew N. Dodd uc = (struct ida_user_command *)addr; 650a85ce5b6SMatthew N. Dodd error = 0; 651a85ce5b6SMatthew N. Dodd 652a85ce5b6SMatthew N. Dodd switch (cmd) { 653a85ce5b6SMatthew N. Dodd case IDAIO_COMMAND: 654a85ce5b6SMatthew N. Dodd ci = ida_cmd_lookup(uc->command); 655a85ce5b6SMatthew N. Dodd if (ci == NULL) { 656a85ce5b6SMatthew N. Dodd error = EINVAL; 657a85ce5b6SMatthew N. Dodd break; 658a85ce5b6SMatthew N. Dodd } 659a85ce5b6SMatthew N. Dodd len = ci->len; 660a85ce5b6SMatthew N. Dodd flags = ci->flags; 661a85ce5b6SMatthew N. Dodd if (len) 662a85ce5b6SMatthew N. Dodd daddr = &uc->d.buf; 663a85ce5b6SMatthew N. Dodd else { 664a85ce5b6SMatthew N. Dodd daddr = &data; 665a85ce5b6SMatthew N. Dodd len = sizeof(data); 666a85ce5b6SMatthew N. Dodd } 667a85ce5b6SMatthew N. Dodd error = ida_command(sc, uc->command, daddr, len, 668a85ce5b6SMatthew N. Dodd uc->drive, uc->blkno, flags); 669a85ce5b6SMatthew N. Dodd break; 670a85ce5b6SMatthew N. Dodd default: 671a85ce5b6SMatthew N. Dodd error = ENOIOCTL; 672a85ce5b6SMatthew N. Dodd break; 673a85ce5b6SMatthew N. Dodd } 674a85ce5b6SMatthew N. Dodd return (error); 675a85ce5b6SMatthew N. Dodd } 676a85ce5b6SMatthew N. Dodd 677a85ce5b6SMatthew N. Dodd static struct cmd_info ci_list[] = { 678a85ce5b6SMatthew N. Dodd { CMD_GET_LOG_DRV_INFO, 679a85ce5b6SMatthew N. Dodd sizeof(struct ida_drive_info), DMA_DATA_IN }, 680a85ce5b6SMatthew N. Dodd { CMD_GET_CTRL_INFO, 681a85ce5b6SMatthew N. Dodd sizeof(struct ida_controller_info), DMA_DATA_IN }, 682a85ce5b6SMatthew N. Dodd { CMD_SENSE_DRV_STATUS, 683a85ce5b6SMatthew N. Dodd sizeof(struct ida_drive_status), DMA_DATA_IN }, 684a85ce5b6SMatthew N. Dodd { CMD_START_RECOVERY, 0, 0 }, 685a85ce5b6SMatthew N. Dodd { CMD_GET_PHYS_DRV_INFO, 686a85ce5b6SMatthew N. Dodd sizeof(struct ida_phys_drv_info), DMA_DATA_TRANSFER }, 687a85ce5b6SMatthew N. Dodd { CMD_BLINK_DRV_LEDS, 688a85ce5b6SMatthew N. Dodd sizeof(struct ida_blink_drv_leds), DMA_DATA_OUT }, 689a85ce5b6SMatthew N. Dodd { CMD_SENSE_DRV_LEDS, 690a85ce5b6SMatthew N. Dodd sizeof(struct ida_blink_drv_leds), DMA_DATA_IN }, 691a85ce5b6SMatthew N. Dodd { CMD_GET_LOG_DRV_EXT, 692a85ce5b6SMatthew N. Dodd sizeof(struct ida_drive_info_ext), DMA_DATA_IN }, 693a85ce5b6SMatthew N. Dodd { CMD_RESET_CTRL, 0, 0 }, 694a85ce5b6SMatthew N. Dodd { CMD_GET_CONFIG, 0, 0 }, 695a85ce5b6SMatthew N. Dodd { CMD_SET_CONFIG, 0, 0 }, 696a85ce5b6SMatthew N. Dodd { CMD_LABEL_LOG_DRV, 697a85ce5b6SMatthew N. Dodd sizeof(struct ida_label_logical), DMA_DATA_OUT }, 698a85ce5b6SMatthew N. Dodd { CMD_SET_SURFACE_DELAY, 0, 0 }, 699a85ce5b6SMatthew N. Dodd { CMD_SENSE_BUS_PARAMS, 0, 0 }, 700a85ce5b6SMatthew N. Dodd { CMD_SENSE_SUBSYS_INFO, 0, 0 }, 701a85ce5b6SMatthew N. Dodd { CMD_SENSE_SURFACE_ATS, 0, 0 }, 702a85ce5b6SMatthew N. Dodd { CMD_PASSTHROUGH, 0, 0 }, 703a85ce5b6SMatthew N. Dodd { CMD_RESET_SCSI_DEV, 0, 0 }, 704a85ce5b6SMatthew N. Dodd { CMD_PAUSE_BG_ACT, 0, 0 }, 705a85ce5b6SMatthew N. Dodd { CMD_RESUME_BG_ACT, 0, 0 }, 706a85ce5b6SMatthew N. Dodd { CMD_START_FIRMWARE, 0, 0 }, 707a85ce5b6SMatthew N. Dodd { CMD_SENSE_DRV_ERR_LOG, 0, 0 }, 708a85ce5b6SMatthew N. Dodd { CMD_START_CPM, 0, 0 }, 709a85ce5b6SMatthew N. Dodd { CMD_SENSE_CP, 0, 0 }, 710a85ce5b6SMatthew N. Dodd { CMD_STOP_CPM, 0, 0 }, 711a85ce5b6SMatthew N. Dodd { CMD_FLUSH_CACHE, 0, 0 }, 712a85ce5b6SMatthew N. Dodd { CMD_ACCEPT_MEDIA_EXCH, 0, 0 }, 713a85ce5b6SMatthew N. Dodd { 0, 0, 0 } 714a85ce5b6SMatthew N. Dodd }; 715a85ce5b6SMatthew N. Dodd 716a85ce5b6SMatthew N. Dodd static struct cmd_info * 717a85ce5b6SMatthew N. Dodd ida_cmd_lookup (int command) 718a85ce5b6SMatthew N. Dodd { 719a85ce5b6SMatthew N. Dodd struct cmd_info *ci; 720a85ce5b6SMatthew N. Dodd 721a85ce5b6SMatthew N. Dodd ci = ci_list; 722a85ce5b6SMatthew N. Dodd while (ci->cmd) { 723a85ce5b6SMatthew N. Dodd if (ci->cmd == command) 724a85ce5b6SMatthew N. Dodd return (ci); 725a85ce5b6SMatthew N. Dodd ci++; 726a85ce5b6SMatthew N. Dodd } 727a85ce5b6SMatthew N. Dodd return (NULL); 728a85ce5b6SMatthew N. Dodd } 729