2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/module.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
36 #include <sys/endian.h>
37 #include <sys/malloc.h>
39 #include <sys/mutex.h>
41 #include <sys/taskqueue.h>
43 #include <machine/stdarg.h>
44 #include <machine/resource.h>
45 #include <machine/bus.h>
47 #include <dev/led/led.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
53 #include <cam/cam_ccb.h>
54 #include <cam/cam_sim.h>
55 #include <cam/cam_xpt_sim.h>
56 #include <cam/cam_debug.h>
58 /* local prototypes */
59 static int siis_setup_interrupt(device_t dev);
60 static void siis_intr(void *data);
61 static int siis_suspend(device_t dev);
62 static int siis_resume(device_t dev);
63 static int siis_ch_init(device_t dev);
64 static int siis_ch_deinit(device_t dev);
65 static int siis_ch_suspend(device_t dev);
66 static int siis_ch_resume(device_t dev);
67 static void siis_ch_intr_locked(void *data);
68 static void siis_ch_intr(void *data);
69 static void siis_ch_led(void *priv, int onoff);
70 static void siis_begin_transaction(device_t dev, union ccb *ccb);
71 static void siis_dmasetprd(void *arg, bus_dma_segment_t *segs, int nsegs, int error);
72 static void siis_execute_transaction(struct siis_slot *slot);
73 static void siis_timeout(struct siis_slot *slot);
74 static void siis_end_transaction(struct siis_slot *slot, enum siis_err_type et);
75 static int siis_setup_fis(device_t dev, struct siis_cmd *ctp, union ccb *ccb, int tag);
76 static void siis_dmainit(device_t dev);
77 static void siis_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error);
78 static void siis_dmafini(device_t dev);
79 static void siis_slotsalloc(device_t dev);
80 static void siis_slotsfree(device_t dev);
81 static void siis_reset(device_t dev);
82 static void siis_portinit(device_t dev);
83 static int siis_wait_ready(device_t dev, int t);
85 static int siis_sata_connect(struct siis_channel *ch);
87 static void siis_issue_recovery(device_t dev);
88 static void siis_process_read_log(device_t dev, union ccb *ccb);
89 static void siis_process_request_sense(device_t dev, union ccb *ccb);
91 static void siisaction(struct cam_sim *sim, union ccb *ccb);
92 static void siispoll(struct cam_sim *sim);
94 MALLOC_DEFINE(M_SIIS, "SIIS driver", "SIIS driver data buffers");
101 #define SIIS_Q_SNTF 1
102 #define SIIS_Q_NOMSI 2
104 {0x31241095, "SiI3124", 4, 0},
105 {0x31248086, "SiI3124", 4, 0},
106 {0x31321095, "SiI3132", 2, SIIS_Q_SNTF|SIIS_Q_NOMSI},
107 {0x02421095, "SiI3132", 2, SIIS_Q_SNTF|SIIS_Q_NOMSI},
108 {0x02441095, "SiI3132", 2, SIIS_Q_SNTF|SIIS_Q_NOMSI},
109 {0x31311095, "SiI3131", 1, SIIS_Q_SNTF|SIIS_Q_NOMSI},
110 {0x35311095, "SiI3531", 1, SIIS_Q_SNTF|SIIS_Q_NOMSI},
114 #define recovery_type spriv_field0
115 #define RECOVERY_NONE 0
116 #define RECOVERY_READ_LOG 1
117 #define RECOVERY_REQUEST_SENSE 2
118 #define recovery_slot spriv_field1
121 siis_probe(device_t dev)
125 uint32_t devid = pci_get_devid(dev);
127 for (i = 0; siis_ids[i].id != 0; i++) {
128 if (siis_ids[i].id == devid) {
129 snprintf(buf, sizeof(buf), "%s SATA controller",
131 device_set_desc_copy(dev, buf);
132 return (BUS_PROBE_VENDOR);
139 siis_attach(device_t dev)
141 struct siis_controller *ctlr = device_get_softc(dev);
142 uint32_t devid = pci_get_devid(dev);
147 for (i = 0; siis_ids[i].id != 0; i++) {
148 if (siis_ids[i].id == devid)
151 ctlr->quirks = siis_ids[i].quirks;
153 ctlr->r_grid = PCIR_BAR(0);
154 if (!(ctlr->r_gmem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
155 &ctlr->r_grid, RF_ACTIVE)))
157 ctlr->gctl = ATA_INL(ctlr->r_gmem, SIIS_GCTL);
158 /* Channels memory */
159 ctlr->r_rid = PCIR_BAR(2);
160 if (!(ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
161 &ctlr->r_rid, RF_ACTIVE)))
163 /* Setup our own memory management for channels. */
164 ctlr->sc_iomem.rm_start = rman_get_start(ctlr->r_mem);
165 ctlr->sc_iomem.rm_end = rman_get_end(ctlr->r_mem);
166 ctlr->sc_iomem.rm_type = RMAN_ARRAY;
167 ctlr->sc_iomem.rm_descr = "I/O memory addresses";
168 if ((error = rman_init(&ctlr->sc_iomem)) != 0) {
169 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem);
170 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_grid, ctlr->r_gmem);
173 if ((error = rman_manage_region(&ctlr->sc_iomem,
174 rman_get_start(ctlr->r_mem), rman_get_end(ctlr->r_mem))) != 0) {
175 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem);
176 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_grid, ctlr->r_gmem);
177 rman_fini(&ctlr->sc_iomem);
180 pci_enable_busmaster(dev);
181 /* Reset controller */
183 /* Number of HW channels */
184 ctlr->channels = siis_ids[i].ports;
185 /* Setup interrupts. */
186 if (siis_setup_interrupt(dev)) {
187 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem);
188 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_grid, ctlr->r_gmem);
189 rman_fini(&ctlr->sc_iomem);
192 /* Attach all channels on this controller */
193 for (unit = 0; unit < ctlr->channels; unit++) {
194 child = device_add_child(dev, "siisch", -1);
196 device_printf(dev, "failed to add channel device\n");
198 device_set_ivars(child, (void *)(intptr_t)unit);
200 bus_generic_attach(dev);
205 siis_detach(device_t dev)
207 struct siis_controller *ctlr = device_get_softc(dev);
211 /* Detach & delete all children */
212 if (!device_get_children(dev, &children, &nchildren)) {
213 for (i = 0; i < nchildren; i++)
214 device_delete_child(dev, children[i]);
215 free(children, M_TEMP);
217 /* Free interrupts. */
218 if (ctlr->irq.r_irq) {
219 bus_teardown_intr(dev, ctlr->irq.r_irq,
221 bus_release_resource(dev, SYS_RES_IRQ,
222 ctlr->irq.r_irq_rid, ctlr->irq.r_irq);
224 pci_release_msi(dev);
226 rman_fini(&ctlr->sc_iomem);
227 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem);
228 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_grid, ctlr->r_gmem);
233 siis_suspend(device_t dev)
235 struct siis_controller *ctlr = device_get_softc(dev);
237 bus_generic_suspend(dev);
238 /* Put controller into reset state. */
239 ctlr->gctl |= SIIS_GCTL_GRESET;
240 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL, ctlr->gctl);
245 siis_resume(device_t dev)
247 struct siis_controller *ctlr = device_get_softc(dev);
249 /* Set PCIe max read request size to at least 1024 bytes */
250 if (pci_get_max_read_req(dev) < 1024)
251 pci_set_max_read_req(dev, 1024);
252 /* Put controller into reset state. */
253 ctlr->gctl |= SIIS_GCTL_GRESET;
254 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL, ctlr->gctl);
256 /* Get controller out of reset state and enable port interrupts. */
257 ctlr->gctl &= ~(SIIS_GCTL_GRESET | SIIS_GCTL_I2C_IE);
258 ctlr->gctl |= 0x0000000f;
259 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL, ctlr->gctl);
260 return (bus_generic_resume(dev));
264 siis_setup_interrupt(device_t dev)
266 struct siis_controller *ctlr = device_get_softc(dev);
267 int msi = ctlr->quirks & SIIS_Q_NOMSI ? 0 : 1;
270 resource_int_value(device_get_name(dev),
271 device_get_unit(dev), "msi", &msi);
275 msi = min(1, pci_msi_count(dev));
276 /* Allocate MSI if needed/present. */
277 if (msi && pci_alloc_msi(dev, &msi) != 0)
279 /* Allocate all IRQs. */
280 ctlr->irq.r_irq_rid = msi ? 1 : 0;
281 if (!(ctlr->irq.r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
282 &ctlr->irq.r_irq_rid, RF_SHAREABLE | RF_ACTIVE))) {
283 device_printf(dev, "unable to map interrupt\n");
286 if ((bus_setup_intr(dev, ctlr->irq.r_irq, ATA_INTR_FLAGS, NULL,
287 siis_intr, ctlr, &ctlr->irq.handle))) {
288 /* SOS XXX release r_irq */
289 device_printf(dev, "unable to setup interrupt\n");
296 * Common case interrupt handler.
299 siis_intr(void *data)
301 struct siis_controller *ctlr = (struct siis_controller *)data;
306 is = ATA_INL(ctlr->r_gmem, SIIS_IS);
307 for (unit = 0; unit < ctlr->channels; unit++) {
308 if ((is & SIIS_IS_PORT(unit)) != 0 &&
309 (arg = ctlr->interrupt[unit].argument)) {
310 ctlr->interrupt[unit].function(arg);
313 /* Acknowledge interrupt, if MSI enabled. */
314 if (ctlr->irq.r_irq_rid) {
315 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL,
316 ctlr->gctl | SIIS_GCTL_MSIACK);
320 static struct resource *
321 siis_alloc_resource(device_t dev, device_t child, int type, int *rid,
322 u_long start, u_long end, u_long count, u_int flags)
324 struct siis_controller *ctlr = device_get_softc(dev);
325 int unit = ((struct siis_channel *)device_get_softc(child))->unit;
326 struct resource *res = NULL;
327 int offset = unit << 13;
332 st = rman_get_start(ctlr->r_mem);
333 res = rman_reserve_resource(&ctlr->sc_iomem, st + offset,
334 st + offset + 0x2000, 0x2000, RF_ACTIVE, child);
336 bus_space_handle_t bsh;
338 bsh = rman_get_bushandle(ctlr->r_mem);
339 bst = rman_get_bustag(ctlr->r_mem);
340 bus_space_subregion(bst, bsh, offset, 0x2000, &bsh);
341 rman_set_bushandle(res, bsh);
342 rman_set_bustag(res, bst);
346 if (*rid == ATA_IRQ_RID)
347 res = ctlr->irq.r_irq;
354 siis_release_resource(device_t dev, device_t child, int type, int rid,
360 rman_release_resource(r);
363 if (rid != ATA_IRQ_RID)
371 siis_setup_intr(device_t dev, device_t child, struct resource *irq,
372 int flags, driver_filter_t *filter, driver_intr_t *function,
373 void *argument, void **cookiep)
375 struct siis_controller *ctlr = device_get_softc(dev);
376 int unit = (intptr_t)device_get_ivars(child);
378 if (filter != NULL) {
379 printf("siis.c: we cannot use a filter here\n");
382 ctlr->interrupt[unit].function = function;
383 ctlr->interrupt[unit].argument = argument;
388 siis_teardown_intr(device_t dev, device_t child, struct resource *irq,
391 struct siis_controller *ctlr = device_get_softc(dev);
392 int unit = (intptr_t)device_get_ivars(child);
394 ctlr->interrupt[unit].function = NULL;
395 ctlr->interrupt[unit].argument = NULL;
400 siis_print_child(device_t dev, device_t child)
404 retval = bus_print_child_header(dev, child);
405 retval += printf(" at channel %d",
406 (int)(intptr_t)device_get_ivars(child));
407 retval += bus_print_child_footer(dev, child);
413 siis_child_location_str(device_t dev, device_t child, char *buf,
417 snprintf(buf, buflen, "channel=%d",
418 (int)(intptr_t)device_get_ivars(child));
422 devclass_t siis_devclass;
423 static device_method_t siis_methods[] = {
424 DEVMETHOD(device_probe, siis_probe),
425 DEVMETHOD(device_attach, siis_attach),
426 DEVMETHOD(device_detach, siis_detach),
427 DEVMETHOD(device_suspend, siis_suspend),
428 DEVMETHOD(device_resume, siis_resume),
429 DEVMETHOD(bus_print_child, siis_print_child),
430 DEVMETHOD(bus_alloc_resource, siis_alloc_resource),
431 DEVMETHOD(bus_release_resource, siis_release_resource),
432 DEVMETHOD(bus_setup_intr, siis_setup_intr),
433 DEVMETHOD(bus_teardown_intr,siis_teardown_intr),
434 DEVMETHOD(bus_child_location_str, siis_child_location_str),
437 static driver_t siis_driver = {
440 sizeof(struct siis_controller)
442 DRIVER_MODULE(siis, pci, siis_driver, siis_devclass, 0, 0);
443 MODULE_VERSION(siis, 1);
444 MODULE_DEPEND(siis, cam, 1, 1, 1);
447 siis_ch_probe(device_t dev)
450 device_set_desc_copy(dev, "SIIS channel");
455 siis_ch_attach(device_t dev)
457 struct siis_controller *ctlr = device_get_softc(device_get_parent(dev));
458 struct siis_channel *ch = device_get_softc(dev);
459 struct cam_devq *devq;
460 int rid, error, i, sata_rev = 0;
463 ch->unit = (intptr_t)device_get_ivars(dev);
464 ch->quirks = ctlr->quirks;
465 resource_int_value(device_get_name(dev),
466 device_get_unit(dev), "pm_level", &ch->pm_level);
467 resource_int_value(device_get_name(dev),
468 device_get_unit(dev), "sata_rev", &sata_rev);
469 for (i = 0; i < 16; i++) {
470 ch->user[i].revision = sata_rev;
471 ch->user[i].mode = 0;
472 ch->user[i].bytecount = 8192;
473 ch->user[i].tags = SIIS_MAX_SLOTS;
474 ch->curr[i] = ch->user[i];
476 ch->user[i].caps = CTS_SATA_CAPS_H_PMREQ;
477 ch->user[i].caps |= CTS_SATA_CAPS_H_AN;
479 mtx_init(&ch->mtx, "SIIS channel lock", NULL, MTX_DEF);
481 if (!(ch->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
485 siis_slotsalloc(dev);
489 if (!(ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
490 &rid, RF_SHAREABLE | RF_ACTIVE))) {
491 device_printf(dev, "Unable to map interrupt\n");
495 if ((bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL,
496 siis_ch_intr_locked, dev, &ch->ih))) {
497 device_printf(dev, "Unable to setup interrupt\n");
501 /* Create the device queue for our SIM. */
502 devq = cam_simq_alloc(SIIS_MAX_SLOTS);
504 device_printf(dev, "Unable to allocate simq\n");
508 /* Construct SIM entry */
509 ch->sim = cam_sim_alloc(siisaction, siispoll, "siisch", ch,
510 device_get_unit(dev), &ch->mtx, 2, SIIS_MAX_SLOTS, devq);
511 if (ch->sim == NULL) {
513 device_printf(dev, "unable to allocate sim\n");
517 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) {
518 device_printf(dev, "unable to register xpt bus\n");
522 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim),
523 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
524 device_printf(dev, "unable to create path\n");
528 mtx_unlock(&ch->mtx);
529 ch->led = led_create(siis_ch_led, dev, device_get_nameunit(dev));
533 xpt_bus_deregister(cam_sim_path(ch->sim));
535 cam_sim_free(ch->sim, /*free_devq*/TRUE);
537 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
539 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
540 mtx_unlock(&ch->mtx);
541 mtx_destroy(&ch->mtx);
546 siis_ch_detach(device_t dev)
548 struct siis_channel *ch = device_get_softc(dev);
550 led_destroy(ch->led);
552 xpt_async(AC_LOST_DEVICE, ch->path, NULL);
553 xpt_free_path(ch->path);
554 xpt_bus_deregister(cam_sim_path(ch->sim));
555 cam_sim_free(ch->sim, /*free_devq*/TRUE);
556 mtx_unlock(&ch->mtx);
558 bus_teardown_intr(dev, ch->r_irq, ch->ih);
559 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
565 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
566 mtx_destroy(&ch->mtx);
571 siis_ch_init(device_t dev)
573 struct siis_channel *ch = device_get_softc(dev);
575 /* Get port out of reset state. */
576 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
577 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
579 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
581 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
582 /* Enable port interrupts */
583 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
588 siis_ch_deinit(device_t dev)
590 struct siis_channel *ch = device_get_softc(dev);
592 /* Put port into reset state. */
593 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
598 siis_ch_suspend(device_t dev)
600 struct siis_channel *ch = device_get_softc(dev);
603 xpt_freeze_simq(ch->sim, 1);
605 msleep(ch, &ch->mtx, PRIBIO, "siissusp", hz/100);
607 mtx_unlock(&ch->mtx);
612 siis_ch_resume(device_t dev)
614 struct siis_channel *ch = device_get_softc(dev);
619 xpt_release_simq(ch->sim, TRUE);
620 mtx_unlock(&ch->mtx);
624 devclass_t siisch_devclass;
625 static device_method_t siisch_methods[] = {
626 DEVMETHOD(device_probe, siis_ch_probe),
627 DEVMETHOD(device_attach, siis_ch_attach),
628 DEVMETHOD(device_detach, siis_ch_detach),
629 DEVMETHOD(device_suspend, siis_ch_suspend),
630 DEVMETHOD(device_resume, siis_ch_resume),
633 static driver_t siisch_driver = {
636 sizeof(struct siis_channel)
638 DRIVER_MODULE(siisch, siis, siisch_driver, siis_devclass, 0, 0);
641 siis_ch_led(void *priv, int onoff)
644 struct siis_channel *ch;
646 dev = (device_t)priv;
647 ch = device_get_softc(dev);
650 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_LED_ON);
652 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_LED_ON);
655 struct siis_dc_cb_args {
661 siis_dmainit(device_t dev)
663 struct siis_channel *ch = device_get_softc(dev);
664 struct siis_dc_cb_args dcba;
667 if (bus_dma_tag_create(bus_get_dma_tag(dev), 1024, 0,
668 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
669 NULL, NULL, SIIS_WORK_SIZE, 1, SIIS_WORK_SIZE,
670 0, NULL, NULL, &ch->dma.work_tag))
672 if (bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, 0,
675 if (bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work,
676 SIIS_WORK_SIZE, siis_dmasetupc_cb, &dcba, 0) || dcba.error) {
677 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
680 ch->dma.work_bus = dcba.maddr;
682 if (bus_dma_tag_create(bus_get_dma_tag(dev), 1, 0,
683 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
685 SIIS_SG_ENTRIES * PAGE_SIZE * SIIS_MAX_SLOTS,
686 SIIS_SG_ENTRIES, 0xFFFFFFFF,
687 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag)) {
693 device_printf(dev, "WARNING - DMA initialization failed\n");
698 siis_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
700 struct siis_dc_cb_args *dcba = (struct siis_dc_cb_args *)xsc;
702 if (!(dcba->error = error))
703 dcba->maddr = segs[0].ds_addr;
707 siis_dmafini(device_t dev)
709 struct siis_channel *ch = device_get_softc(dev);
711 if (ch->dma.data_tag) {
712 bus_dma_tag_destroy(ch->dma.data_tag);
713 ch->dma.data_tag = NULL;
715 if (ch->dma.work_bus) {
716 bus_dmamap_unload(ch->dma.work_tag, ch->dma.work_map);
717 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
718 ch->dma.work_bus = 0;
719 ch->dma.work_map = NULL;
722 if (ch->dma.work_tag) {
723 bus_dma_tag_destroy(ch->dma.work_tag);
724 ch->dma.work_tag = NULL;
729 siis_slotsalloc(device_t dev)
731 struct siis_channel *ch = device_get_softc(dev);
734 /* Alloc and setup command/dma slots */
735 bzero(ch->slot, sizeof(ch->slot));
736 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
737 struct siis_slot *slot = &ch->slot[i];
741 slot->state = SIIS_SLOT_EMPTY;
743 callout_init_mtx(&slot->timeout, &ch->mtx, 0);
745 if (bus_dmamap_create(ch->dma.data_tag, 0, &slot->dma.data_map))
746 device_printf(ch->dev, "FAILURE - create data_map\n");
751 siis_slotsfree(device_t dev)
753 struct siis_channel *ch = device_get_softc(dev);
756 /* Free all dma slots */
757 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
758 struct siis_slot *slot = &ch->slot[i];
760 callout_drain(&slot->timeout);
761 if (slot->dma.data_map) {
762 bus_dmamap_destroy(ch->dma.data_tag, slot->dma.data_map);
763 slot->dma.data_map = NULL;
769 siis_notify_events(device_t dev)
771 struct siis_channel *ch = device_get_softc(dev);
772 struct cam_path *dpath;
776 if (ch->quirks & SIIS_Q_SNTF) {
777 status = ATA_INL(ch->r_mem, SIIS_P_SNTF);
778 ATA_OUTL(ch->r_mem, SIIS_P_SNTF, status);
781 * Without SNTF we have no idea which device sent notification.
782 * If PMP is connected, assume it, else - device.
784 status = (ch->pm_present) ? 0x8000 : 0x0001;
787 device_printf(dev, "SNTF 0x%04x\n", status);
788 for (i = 0; i < 16; i++) {
789 if ((status & (1 << i)) == 0)
791 if (xpt_create_path(&dpath, NULL,
792 xpt_path_path_id(ch->path), i, 0) == CAM_REQ_CMP) {
793 xpt_async(AC_SCSI_AEN, dpath, NULL);
794 xpt_free_path(dpath);
801 siis_phy_check_events(device_t dev)
803 struct siis_channel *ch = device_get_softc(dev);
805 /* If we have a connection event, deal with it */
806 if (ch->pm_level == 0) {
807 u_int32_t status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
811 if (((status & ATA_SS_DET_MASK) == ATA_SS_DET_PHY_ONLINE) &&
812 ((status & ATA_SS_SPD_MASK) != ATA_SS_SPD_NO_SPEED) &&
813 ((status & ATA_SS_IPM_MASK) == ATA_SS_IPM_ACTIVE)) {
814 device_printf(dev, "CONNECT requested\n");
816 device_printf(dev, "DISCONNECT requested\n");
819 if ((ccb = xpt_alloc_ccb_nowait()) == NULL)
821 if (xpt_create_path(&ccb->ccb_h.path, NULL,
822 cam_sim_path(ch->sim),
823 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
832 siis_ch_intr_locked(void *data)
834 device_t dev = (device_t)data;
835 struct siis_channel *ch = device_get_softc(dev);
838 xpt_batch_start(ch->sim);
840 xpt_batch_done(ch->sim);
841 mtx_unlock(&ch->mtx);
845 siis_ch_intr(void *data)
847 device_t dev = (device_t)data;
848 struct siis_channel *ch = device_get_softc(dev);
849 uint32_t istatus, sstatus, ctx, estatus, ok, err = 0;
850 enum siis_err_type et;
851 int i, ccs, port, tslots;
853 mtx_assert(&ch->mtx, MA_OWNED);
854 /* Read command statuses. */
855 sstatus = ATA_INL(ch->r_mem, SIIS_P_SS);
856 ok = ch->rslots & ~sstatus;
857 /* Complete all successfull commands. */
858 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
860 siis_end_transaction(&ch->slot[i], SIIS_ERR_NONE);
862 /* Do we have any other events? */
863 if ((sstatus & SIIS_P_SS_ATTN) == 0)
865 /* Read and clear interrupt statuses. */
866 istatus = ATA_INL(ch->r_mem, SIIS_P_IS) &
867 (0xFFFF & ~SIIS_P_IX_COMMCOMP);
868 ATA_OUTL(ch->r_mem, SIIS_P_IS, istatus);
869 /* Process PHY events */
870 if (istatus & SIIS_P_IX_PHYRDYCHG)
871 siis_phy_check_events(dev);
872 /* Process NOTIFY events */
873 if (istatus & SIIS_P_IX_SDBN)
874 siis_notify_events(dev);
875 /* Process command errors */
876 if (istatus & SIIS_P_IX_COMMERR) {
877 estatus = ATA_INL(ch->r_mem, SIIS_P_CMDERR);
878 ctx = ATA_INL(ch->r_mem, SIIS_P_CTX);
879 ccs = (ctx & SIIS_P_CTX_SLOT) >> SIIS_P_CTX_SLOT_SHIFT;
880 port = (ctx & SIIS_P_CTX_PMP) >> SIIS_P_CTX_PMP_SHIFT;
881 err = ch->rslots & sstatus;
882 //device_printf(dev, "%s ERROR ss %08x is %08x rs %08x es %d act %d port %d serr %08x\n",
883 // __func__, sstatus, istatus, ch->rslots, estatus, ccs, port,
884 // ATA_INL(ch->r_mem, SIIS_P_SERR));
886 if (!ch->recoverycmd && !ch->recovery) {
887 xpt_freeze_simq(ch->sim, ch->numrslots);
891 union ccb *fccb = ch->frozen;
893 fccb->ccb_h.status &= ~CAM_STATUS_MASK;
894 fccb->ccb_h.status |= CAM_REQUEUE_REQ | CAM_RELEASE_SIMQ;
895 if (!(fccb->ccb_h.status & CAM_DEV_QFRZN)) {
896 xpt_freeze_devq(fccb->ccb_h.path, 1);
897 fccb->ccb_h.status |= CAM_DEV_QFRZN;
901 if (estatus == SIIS_P_CMDERR_DEV ||
902 estatus == SIIS_P_CMDERR_SDB ||
903 estatus == SIIS_P_CMDERR_DATAFIS) {
904 tslots = ch->numtslots[port];
905 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
906 /* XXX: requests in loading state. */
907 if (((ch->rslots >> i) & 1) == 0)
909 if (ch->slot[i].ccb->ccb_h.target_id != port)
912 /* Untagged operation. */
916 et = SIIS_ERR_INNOCENT;
918 /* Tagged operation. */
921 siis_end_transaction(&ch->slot[i], et);
924 * We can't reinit port if there are some other
925 * commands active, use resume to complete them.
927 if (ch->rslots != 0 && !ch->recoverycmd)
928 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_RESUME);
930 if (estatus == SIIS_P_CMDERR_SENDFIS ||
931 estatus == SIIS_P_CMDERR_INCSTATE ||
932 estatus == SIIS_P_CMDERR_PPE ||
933 estatus == SIIS_P_CMDERR_SERVICE) {
936 et = SIIS_ERR_INVALID;
937 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
938 /* XXX: requests in loading state. */
939 if (((ch->rslots >> i) & 1) == 0)
941 siis_end_transaction(&ch->slot[i], et);
947 /* Must be called with channel locked. */
949 siis_check_collision(device_t dev, union ccb *ccb)
951 struct siis_channel *ch = device_get_softc(dev);
953 mtx_assert(&ch->mtx, MA_OWNED);
954 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
955 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA)) {
956 /* Tagged command while we have no supported tag free. */
957 if (((~ch->oslots) & (0x7fffffff >> (31 -
958 ch->curr[ccb->ccb_h.target_id].tags))) == 0)
961 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
962 (ccb->ataio.cmd.flags & (CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT))) {
963 /* Atomic command while anything active. */
964 if (ch->numrslots != 0)
967 /* We have some atomic command running. */
973 /* Must be called with channel locked. */
975 siis_begin_transaction(device_t dev, union ccb *ccb)
977 struct siis_channel *ch = device_get_softc(dev);
978 struct siis_slot *slot;
981 mtx_assert(&ch->mtx, MA_OWNED);
982 /* Choose empty slot. */
983 tags = SIIS_MAX_SLOTS;
984 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
985 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA))
986 tags = ch->curr[ccb->ccb_h.target_id].tags;
987 tag = fls((~ch->oslots) & (0x7fffffff >> (31 - tags))) - 1;
988 /* Occupy chosen slot. */
989 slot = &ch->slot[tag];
991 /* Update channel stats. */
992 ch->oslots |= (1 << slot->slot);
994 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
995 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA)) {
996 ch->numtslots[ccb->ccb_h.target_id]++;
998 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
999 (ccb->ataio.cmd.flags & (CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT)))
1000 ch->aslots |= (1 << slot->slot);
1001 slot->dma.nsegs = 0;
1002 /* If request moves data, setup and load SG list */
1003 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1007 slot->state = SIIS_SLOT_LOADING;
1008 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1009 buf = ccb->ataio.data_ptr;
1010 size = ccb->ataio.dxfer_len;
1012 buf = ccb->csio.data_ptr;
1013 size = ccb->csio.dxfer_len;
1015 bus_dmamap_load(ch->dma.data_tag, slot->dma.data_map,
1016 buf, size, siis_dmasetprd, slot, 0);
1018 siis_execute_transaction(slot);
1021 /* Locked by busdma engine. */
1023 siis_dmasetprd(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
1025 struct siis_slot *slot = arg;
1026 struct siis_channel *ch = device_get_softc(slot->dev);
1027 struct siis_cmd *ctp;
1028 struct siis_dma_prd *prd;
1031 mtx_assert(&ch->mtx, MA_OWNED);
1033 device_printf(slot->dev, "DMA load error\n");
1034 if (!ch->recoverycmd)
1035 xpt_freeze_simq(ch->sim, 1);
1036 siis_end_transaction(slot, SIIS_ERR_INVALID);
1039 KASSERT(nsegs <= SIIS_SG_ENTRIES, ("too many DMA segment entries\n"));
1040 /* Get a piece of the workspace for this request */
1041 ctp = (struct siis_cmd *)
1042 (ch->dma.work + SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot));
1043 /* Fill S/G table */
1044 if (slot->ccb->ccb_h.func_code == XPT_ATA_IO)
1045 prd = &ctp->u.ata.prd[0];
1047 prd = &ctp->u.atapi.prd[0];
1048 for (i = 0; i < nsegs; i++) {
1049 prd[i].dba = htole64(segs[i].ds_addr);
1050 prd[i].dbc = htole32(segs[i].ds_len);
1053 prd[nsegs - 1].control = htole32(SIIS_PRD_TRM);
1054 slot->dma.nsegs = nsegs;
1055 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1056 ((slot->ccb->ccb_h.flags & CAM_DIR_IN) ?
1057 BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
1058 siis_execute_transaction(slot);
1061 /* Must be called with channel locked. */
1063 siis_execute_transaction(struct siis_slot *slot)
1065 device_t dev = slot->dev;
1066 struct siis_channel *ch = device_get_softc(dev);
1067 struct siis_cmd *ctp;
1068 union ccb *ccb = slot->ccb;
1071 mtx_assert(&ch->mtx, MA_OWNED);
1072 /* Get a piece of the workspace for this request */
1073 ctp = (struct siis_cmd *)
1074 (ch->dma.work + SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot));
1076 ctp->protocol_override = 0;
1077 ctp->transfer_count = 0;
1078 /* Special handling for Soft Reset command. */
1079 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1080 if (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) {
1081 ctp->control |= htole16(SIIS_PRB_SOFT_RESET);
1083 ctp->control |= htole16(SIIS_PRB_PROTOCOL_OVERRIDE);
1084 if (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA) {
1085 ctp->protocol_override |=
1086 htole16(SIIS_PRB_PROTO_NCQ);
1088 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1089 ctp->protocol_override |=
1090 htole16(SIIS_PRB_PROTO_READ);
1092 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1093 ctp->protocol_override |=
1094 htole16(SIIS_PRB_PROTO_WRITE);
1097 } else if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1098 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1099 ctp->control |= htole16(SIIS_PRB_PACKET_READ);
1101 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
1102 ctp->control |= htole16(SIIS_PRB_PACKET_WRITE);
1104 /* Special handling for Soft Reset command. */
1105 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
1106 (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) &&
1107 (ccb->ataio.cmd.control & ATA_A_RESET)) {
1108 /* Kick controller into sane state */
1111 /* Setup the FIS for this request */
1112 if (!siis_setup_fis(dev, ctp, ccb, slot->slot)) {
1113 device_printf(ch->dev, "Setting up SATA FIS failed\n");
1114 if (!ch->recoverycmd)
1115 xpt_freeze_simq(ch->sim, 1);
1116 siis_end_transaction(slot, SIIS_ERR_INVALID);
1119 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1120 BUS_DMASYNC_PREWRITE);
1121 /* Issue command to the controller. */
1122 slot->state = SIIS_SLOT_RUNNING;
1123 ch->rslots |= (1 << slot->slot);
1124 prb_bus = ch->dma.work_bus +
1125 SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot);
1126 ATA_OUTL(ch->r_mem, SIIS_P_CACTL(slot->slot), prb_bus);
1127 ATA_OUTL(ch->r_mem, SIIS_P_CACTH(slot->slot), prb_bus >> 32);
1128 /* Start command execution timeout */
1129 callout_reset(&slot->timeout, (int)ccb->ccb_h.timeout * hz / 1000,
1130 (timeout_t*)siis_timeout, slot);
1134 /* Must be called with channel locked. */
1136 siis_process_timeout(device_t dev)
1138 struct siis_channel *ch = device_get_softc(dev);
1141 mtx_assert(&ch->mtx, MA_OWNED);
1142 if (!ch->recoverycmd && !ch->recovery) {
1143 xpt_freeze_simq(ch->sim, ch->numrslots);
1146 /* Handle the rest of commands. */
1147 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1148 /* Do we have a running request on slot? */
1149 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1151 siis_end_transaction(&ch->slot[i], SIIS_ERR_TIMEOUT);
1155 /* Must be called with channel locked. */
1157 siis_rearm_timeout(device_t dev)
1159 struct siis_channel *ch = device_get_softc(dev);
1162 mtx_assert(&ch->mtx, MA_OWNED);
1163 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1164 struct siis_slot *slot = &ch->slot[i];
1166 /* Do we have a running request on slot? */
1167 if (slot->state < SIIS_SLOT_RUNNING)
1169 if ((ch->toslots & (1 << i)) == 0)
1171 callout_reset(&slot->timeout,
1172 (int)slot->ccb->ccb_h.timeout * hz / 1000,
1173 (timeout_t*)siis_timeout, slot);
1177 /* Locked by callout mechanism. */
1179 siis_timeout(struct siis_slot *slot)
1181 device_t dev = slot->dev;
1182 struct siis_channel *ch = device_get_softc(dev);
1183 union ccb *ccb = slot->ccb;
1185 mtx_assert(&ch->mtx, MA_OWNED);
1186 /* Check for stale timeout. */
1187 if (slot->state < SIIS_SLOT_RUNNING)
1190 /* Handle soft-reset timeouts without doing hard-reset. */
1191 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
1192 (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) &&
1193 (ccb->ataio.cmd.control & ATA_A_RESET)) {
1194 xpt_freeze_simq(ch->sim, ch->numrslots);
1195 siis_end_transaction(slot, SIIS_ERR_TFE);
1199 device_printf(dev, "Timeout on slot %d\n", slot->slot);
1200 device_printf(dev, "%s is %08x ss %08x rs %08x es %08x sts %08x serr %08x\n",
1201 __func__, ATA_INL(ch->r_mem, SIIS_P_IS),
1202 ATA_INL(ch->r_mem, SIIS_P_SS), ch->rslots,
1203 ATA_INL(ch->r_mem, SIIS_P_CMDERR), ATA_INL(ch->r_mem, SIIS_P_STS),
1204 ATA_INL(ch->r_mem, SIIS_P_SERR));
1206 if (ch->toslots == 0)
1207 xpt_freeze_simq(ch->sim, 1);
1208 ch->toslots |= (1 << slot->slot);
1209 if ((ch->rslots & ~ch->toslots) == 0)
1210 siis_process_timeout(dev);
1212 device_printf(dev, " ... waiting for slots %08x\n",
1213 ch->rslots & ~ch->toslots);
1216 /* Must be called with channel locked. */
1218 siis_end_transaction(struct siis_slot *slot, enum siis_err_type et)
1220 device_t dev = slot->dev;
1221 struct siis_channel *ch = device_get_softc(dev);
1222 union ccb *ccb = slot->ccb;
1225 mtx_assert(&ch->mtx, MA_OWNED);
1226 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1227 BUS_DMASYNC_POSTWRITE);
1228 /* Read result registers to the result struct
1229 * May be incorrect if several commands finished same time,
1230 * so read only when sure or have to.
1232 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1233 struct ata_res *res = &ccb->ataio.res;
1234 if ((et == SIIS_ERR_TFE) ||
1235 (ccb->ataio.cmd.flags & CAM_ATAIO_NEEDRESULT)) {
1236 int offs = SIIS_P_LRAM_SLOT(slot->slot) + 8;
1238 res->status = ATA_INB(ch->r_mem, offs + 2);
1239 res->error = ATA_INB(ch->r_mem, offs + 3);
1240 res->lba_low = ATA_INB(ch->r_mem, offs + 4);
1241 res->lba_mid = ATA_INB(ch->r_mem, offs + 5);
1242 res->lba_high = ATA_INB(ch->r_mem, offs + 6);
1243 res->device = ATA_INB(ch->r_mem, offs + 7);
1244 res->lba_low_exp = ATA_INB(ch->r_mem, offs + 8);
1245 res->lba_mid_exp = ATA_INB(ch->r_mem, offs + 9);
1246 res->lba_high_exp = ATA_INB(ch->r_mem, offs + 10);
1247 res->sector_count = ATA_INB(ch->r_mem, offs + 12);
1248 res->sector_count_exp = ATA_INB(ch->r_mem, offs + 13);
1250 bzero(res, sizeof(*res));
1251 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN &&
1252 ch->numrslots == 1) {
1253 ccb->ataio.resid = ccb->ataio.dxfer_len -
1254 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1257 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN &&
1258 ch->numrslots == 1) {
1259 ccb->csio.resid = ccb->csio.dxfer_len -
1260 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1263 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1264 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1265 (ccb->ccb_h.flags & CAM_DIR_IN) ?
1266 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1267 bus_dmamap_unload(ch->dma.data_tag, slot->dma.data_map);
1269 /* Set proper result status. */
1270 if (et != SIIS_ERR_NONE || ch->recovery) {
1271 ch->eslots |= (1 << slot->slot);
1272 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1274 /* In case of error, freeze device for proper recovery. */
1275 if (et != SIIS_ERR_NONE && (!ch->recoverycmd) &&
1276 !(ccb->ccb_h.status & CAM_DEV_QFRZN)) {
1277 xpt_freeze_devq(ccb->ccb_h.path, 1);
1278 ccb->ccb_h.status |= CAM_DEV_QFRZN;
1280 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1283 ccb->ccb_h.status |= CAM_REQ_CMP;
1284 if (ccb->ccb_h.func_code == XPT_SCSI_IO)
1285 ccb->csio.scsi_status = SCSI_STATUS_OK;
1287 case SIIS_ERR_INVALID:
1289 ccb->ccb_h.status |= CAM_REQ_INVALID;
1291 case SIIS_ERR_INNOCENT:
1292 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
1296 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1297 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
1298 ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
1300 ccb->ccb_h.status |= CAM_ATA_STATUS_ERROR;
1305 ccb->ccb_h.status |= CAM_UNCOR_PARITY;
1307 case SIIS_ERR_TIMEOUT:
1309 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1312 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
1315 ch->oslots &= ~(1 << slot->slot);
1316 ch->rslots &= ~(1 << slot->slot);
1317 ch->aslots &= ~(1 << slot->slot);
1318 slot->state = SIIS_SLOT_EMPTY;
1320 /* Update channel stats. */
1322 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
1323 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA)) {
1324 ch->numtslots[ccb->ccb_h.target_id]--;
1326 /* Cancel timeout state if request completed normally. */
1327 if (et != SIIS_ERR_TIMEOUT) {
1328 lastto = (ch->toslots == (1 << slot->slot));
1329 ch->toslots &= ~(1 << slot->slot);
1331 xpt_release_simq(ch->sim, TRUE);
1333 /* If it was our READ LOG command - process it. */
1334 if (ccb->ccb_h.recovery_type == RECOVERY_READ_LOG) {
1335 siis_process_read_log(dev, ccb);
1336 /* If it was our REQUEST SENSE command - process it. */
1337 } else if (ccb->ccb_h.recovery_type == RECOVERY_REQUEST_SENSE) {
1338 siis_process_request_sense(dev, ccb);
1339 /* If it was NCQ or ATAPI command error, put result on hold. */
1340 } else if (et == SIIS_ERR_NCQ ||
1341 ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR &&
1342 (ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0)) {
1343 ch->hold[slot->slot] = ccb;
1347 /* If we have no other active commands, ... */
1348 if (ch->rslots == 0) {
1349 /* if there were timeouts or fatal error - reset port. */
1350 if (ch->toslots != 0 || ch->fatalerr) {
1353 /* if we have slots in error, we can reinit port. */
1354 if (ch->eslots != 0)
1356 /* if there commands on hold, we can do recovery. */
1357 if (!ch->recoverycmd && ch->numhslots)
1358 siis_issue_recovery(dev);
1360 /* If all the reset of commands are in timeout - abort them. */
1361 } else if ((ch->rslots & ~ch->toslots) == 0 &&
1362 et != SIIS_ERR_TIMEOUT)
1363 siis_rearm_timeout(dev);
1364 /* Unfreeze frozen command. */
1365 if (ch->frozen && !siis_check_collision(dev, ch->frozen)) {
1366 union ccb *fccb = ch->frozen;
1368 siis_begin_transaction(dev, fccb);
1369 xpt_release_simq(ch->sim, TRUE);
1374 siis_issue_recovery(device_t dev)
1376 struct siis_channel *ch = device_get_softc(dev);
1378 struct ccb_ataio *ataio;
1379 struct ccb_scsiio *csio;
1382 /* Find some held command. */
1383 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1387 if (i == SIIS_MAX_SLOTS)
1389 ccb = xpt_alloc_ccb_nowait();
1391 device_printf(dev, "Unable to allocate recovery command\n");
1393 /* We can't do anything -- complete held commands. */
1394 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1395 if (ch->hold[i] == NULL)
1397 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1398 ch->hold[i]->ccb_h.status |= CAM_RESRC_UNAVAIL;
1399 xpt_done(ch->hold[i]);
1406 ccb->ccb_h = ch->hold[i]->ccb_h; /* Reuse old header. */
1407 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1409 ccb->ccb_h.recovery_type = RECOVERY_READ_LOG;
1410 ccb->ccb_h.func_code = XPT_ATA_IO;
1411 ccb->ccb_h.flags = CAM_DIR_IN;
1412 ccb->ccb_h.timeout = 1000; /* 1s should be enough. */
1413 ataio = &ccb->ataio;
1414 ataio->data_ptr = malloc(512, M_SIIS, M_NOWAIT);
1415 if (ataio->data_ptr == NULL) {
1418 "Unable to allocate memory for READ LOG command\n");
1421 ataio->dxfer_len = 512;
1422 bzero(&ataio->cmd, sizeof(ataio->cmd));
1423 ataio->cmd.flags = CAM_ATAIO_48BIT;
1424 ataio->cmd.command = 0x2F; /* READ LOG EXT */
1425 ataio->cmd.sector_count = 1;
1426 ataio->cmd.sector_count_exp = 0;
1427 ataio->cmd.lba_low = 0x10;
1428 ataio->cmd.lba_mid = 0;
1429 ataio->cmd.lba_mid_exp = 0;
1432 ccb->ccb_h.recovery_type = RECOVERY_REQUEST_SENSE;
1433 ccb->ccb_h.recovery_slot = i;
1434 ccb->ccb_h.func_code = XPT_SCSI_IO;
1435 ccb->ccb_h.flags = CAM_DIR_IN;
1436 ccb->ccb_h.status = 0;
1437 ccb->ccb_h.timeout = 1000; /* 1s should be enough. */
1439 csio->data_ptr = (void *)&ch->hold[i]->csio.sense_data;
1440 csio->dxfer_len = ch->hold[i]->csio.sense_len;
1442 bzero(&csio->cdb_io, sizeof(csio->cdb_io));
1443 csio->cdb_io.cdb_bytes[0] = 0x03;
1444 csio->cdb_io.cdb_bytes[4] = csio->dxfer_len;
1446 ch->recoverycmd = 1;
1447 siis_begin_transaction(dev, ccb);
1451 siis_process_read_log(device_t dev, union ccb *ccb)
1453 struct siis_channel *ch = device_get_softc(dev);
1455 struct ata_res *res;
1458 ch->recoverycmd = 0;
1459 data = ccb->ataio.data_ptr;
1460 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP &&
1461 (data[0] & 0x80) == 0) {
1462 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1465 if (ch->hold[i]->ccb_h.target_id != ccb->ccb_h.target_id)
1467 if ((data[0] & 0x1F) == i) {
1468 res = &ch->hold[i]->ataio.res;
1469 res->status = data[2];
1470 res->error = data[3];
1471 res->lba_low = data[4];
1472 res->lba_mid = data[5];
1473 res->lba_high = data[6];
1474 res->device = data[7];
1475 res->lba_low_exp = data[8];
1476 res->lba_mid_exp = data[9];
1477 res->lba_high_exp = data[10];
1478 res->sector_count = data[12];
1479 res->sector_count_exp = data[13];
1481 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1482 ch->hold[i]->ccb_h.status |= CAM_REQUEUE_REQ;
1484 xpt_done(ch->hold[i]);
1489 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
1490 device_printf(dev, "Error while READ LOG EXT\n");
1491 else if ((data[0] & 0x80) == 0) {
1492 device_printf(dev, "Non-queued command error in READ LOG EXT\n");
1494 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1497 if (ch->hold[i]->ccb_h.target_id != ccb->ccb_h.target_id)
1499 xpt_done(ch->hold[i]);
1504 free(ccb->ataio.data_ptr, M_SIIS);
1509 siis_process_request_sense(device_t dev, union ccb *ccb)
1511 struct siis_channel *ch = device_get_softc(dev);
1514 ch->recoverycmd = 0;
1516 i = ccb->ccb_h.recovery_slot;
1517 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1518 ch->hold[i]->ccb_h.status |= CAM_AUTOSNS_VALID;
1520 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1521 ch->hold[i]->ccb_h.status |= CAM_AUTOSENSE_FAIL;
1523 xpt_done(ch->hold[i]);
1530 siis_portinit(device_t dev)
1532 struct siis_channel *ch = device_get_softc(dev);
1537 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_RESUME);
1538 for (i = 0; i < 16; i++) {
1539 ATA_OUTL(ch->r_mem, SIIS_P_PMPSTS(i), 0),
1540 ATA_OUTL(ch->r_mem, SIIS_P_PMPQACT(i), 0);
1542 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_INIT);
1543 siis_wait_ready(dev, 1000);
1547 siis_devreset(device_t dev)
1549 struct siis_channel *ch = device_get_softc(dev);
1553 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_DEV_RESET);
1554 while (((val = ATA_INL(ch->r_mem, SIIS_P_STS)) &
1555 SIIS_P_CTL_DEV_RESET) != 0) {
1557 if (timeout++ > 1000) {
1558 device_printf(dev, "device reset stuck "
1559 "(timeout 100ms) status = %08x\n", val);
1567 siis_wait_ready(device_t dev, int t)
1569 struct siis_channel *ch = device_get_softc(dev);
1573 while (((val = ATA_INL(ch->r_mem, SIIS_P_STS)) &
1574 SIIS_P_CTL_READY) == 0) {
1576 if (timeout++ > t) {
1577 device_printf(dev, "port is not ready (timeout %dms) "
1578 "status = %08x\n", t, val);
1586 siis_reset(device_t dev)
1588 struct siis_channel *ch = device_get_softc(dev);
1589 int i, retry = 0, sata_rev;
1592 xpt_freeze_simq(ch->sim, 1);
1594 device_printf(dev, "SIIS reset...\n");
1595 if (!ch->recoverycmd && !ch->recovery)
1596 xpt_freeze_simq(ch->sim, ch->numrslots);
1597 /* Requeue frozen command. */
1599 union ccb *fccb = ch->frozen;
1601 fccb->ccb_h.status &= ~CAM_STATUS_MASK;
1602 fccb->ccb_h.status |= CAM_REQUEUE_REQ | CAM_RELEASE_SIMQ;
1603 if (!(fccb->ccb_h.status & CAM_DEV_QFRZN)) {
1604 xpt_freeze_devq(fccb->ccb_h.path, 1);
1605 fccb->ccb_h.status |= CAM_DEV_QFRZN;
1609 /* Requeue all running commands. */
1610 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1611 /* Do we have a running request on slot? */
1612 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1614 /* XXX; Commands in loading state. */
1615 siis_end_transaction(&ch->slot[i], SIIS_ERR_INNOCENT);
1617 /* Finish all held commands as-is. */
1618 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1621 xpt_done(ch->hold[i]);
1625 if (ch->toslots != 0)
1626 xpt_release_simq(ch->sim, TRUE);
1631 /* Disable port interrupts */
1632 ATA_OUTL(ch->r_mem, SIIS_P_IECLR, 0x0000FFFF);
1633 /* Set speed limit. */
1634 sata_rev = ch->user[ch->pm_present ? 15 : 0].revision;
1636 val = ATA_SC_SPD_SPEED_GEN1;
1637 else if (sata_rev == 2)
1638 val = ATA_SC_SPD_SPEED_GEN2;
1639 else if (sata_rev == 3)
1640 val = ATA_SC_SPD_SPEED_GEN3;
1643 ATA_OUTL(ch->r_mem, SIIS_P_SCTL,
1644 ATA_SC_DET_IDLE | val | ((ch->pm_level > 0) ? 0 :
1645 (ATA_SC_IPM_DIS_PARTIAL | ATA_SC_IPM_DIS_SLUMBER)));
1648 /* Reset and reconnect PHY, */
1649 if (!siis_sata_connect(ch)) {
1651 /* Enable port interrupts */
1652 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
1655 "SIIS reset done: phy reset found no device\n");
1656 /* Tell the XPT about the event */
1657 xpt_async(AC_BUS_RESET, ch->path, NULL);
1658 xpt_release_simq(ch->sim, TRUE);
1661 /* Wait for port ready status. */
1662 if (siis_wait_ready(dev, 1000)) {
1663 device_printf(dev, "port ready timeout\n");
1665 device_printf(dev, "trying full port reset ...\n");
1666 /* Get port to the reset state. */
1667 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
1669 /* Get port out of reset state. */
1670 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
1671 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
1673 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1675 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1676 siis_wait_ready(dev, 5000);
1682 /* Enable port interrupts */
1683 ATA_OUTL(ch->r_mem, SIIS_P_IS, 0xFFFFFFFF);
1684 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
1686 device_printf(dev, "SIIS reset done: devices=%08x\n", ch->devices);
1687 /* Tell the XPT about the event */
1688 xpt_async(AC_BUS_RESET, ch->path, NULL);
1689 xpt_release_simq(ch->sim, TRUE);
1693 siis_setup_fis(device_t dev, struct siis_cmd *ctp, union ccb *ccb, int tag)
1695 struct siis_channel *ch = device_get_softc(dev);
1696 u_int8_t *fis = &ctp->fis[0];
1699 fis[0] = 0x27; /* host to device */
1700 fis[1] = (ccb->ccb_h.target_id & 0x0f);
1701 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1703 fis[2] = ATA_PACKET_CMD;
1704 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE &&
1705 ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA)
1708 fis[5] = ccb->csio.dxfer_len;
1709 fis[6] = ccb->csio.dxfer_len >> 8;
1712 fis[15] = ATA_A_4BIT;
1713 bzero(ctp->u.atapi.ccb, 16);
1714 bcopy((ccb->ccb_h.flags & CAM_CDB_POINTER) ?
1715 ccb->csio.cdb_io.cdb_ptr : ccb->csio.cdb_io.cdb_bytes,
1716 ctp->u.atapi.ccb, ccb->csio.cdb_len);
1717 } else if ((ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) == 0) {
1719 fis[2] = ccb->ataio.cmd.command;
1720 fis[3] = ccb->ataio.cmd.features;
1721 fis[4] = ccb->ataio.cmd.lba_low;
1722 fis[5] = ccb->ataio.cmd.lba_mid;
1723 fis[6] = ccb->ataio.cmd.lba_high;
1724 fis[7] = ccb->ataio.cmd.device;
1725 fis[8] = ccb->ataio.cmd.lba_low_exp;
1726 fis[9] = ccb->ataio.cmd.lba_mid_exp;
1727 fis[10] = ccb->ataio.cmd.lba_high_exp;
1728 fis[11] = ccb->ataio.cmd.features_exp;
1729 if (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA) {
1733 fis[12] = ccb->ataio.cmd.sector_count;
1734 fis[13] = ccb->ataio.cmd.sector_count_exp;
1736 fis[15] = ATA_A_4BIT;
1744 siis_sata_connect(struct siis_channel *ch)
1747 int timeout, found = 0;
1749 /* Wait up to 100ms for "connect well" */
1750 for (timeout = 0; timeout < 1000 ; timeout++) {
1751 status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
1752 if ((status & ATA_SS_DET_MASK) != ATA_SS_DET_NO_DEVICE)
1754 if (((status & ATA_SS_DET_MASK) == ATA_SS_DET_PHY_ONLINE) &&
1755 ((status & ATA_SS_SPD_MASK) != ATA_SS_SPD_NO_SPEED) &&
1756 ((status & ATA_SS_IPM_MASK) == ATA_SS_IPM_ACTIVE))
1758 if ((status & ATA_SS_DET_MASK) == ATA_SS_DET_PHY_OFFLINE) {
1760 device_printf(ch->dev, "SATA offline status=%08x\n",
1765 if (found == 0 && timeout >= 100)
1769 if (timeout >= 1000 || !found) {
1771 device_printf(ch->dev,
1772 "SATA connect timeout time=%dus status=%08x\n",
1773 timeout * 100, status);
1778 device_printf(ch->dev, "SATA connect time=%dus status=%08x\n",
1779 timeout * 100, status);
1781 /* Clear SATA error register */
1782 ATA_OUTL(ch->r_mem, SIIS_P_SERR, 0xffffffff);
1787 siis_check_ids(device_t dev, union ccb *ccb)
1790 if (ccb->ccb_h.target_id > 15) {
1791 ccb->ccb_h.status = CAM_TID_INVALID;
1795 if (ccb->ccb_h.target_lun != 0) {
1796 ccb->ccb_h.status = CAM_LUN_INVALID;
1804 siisaction(struct cam_sim *sim, union ccb *ccb)
1807 struct siis_channel *ch;
1809 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("siisaction func_code=%x\n",
1810 ccb->ccb_h.func_code));
1812 ch = (struct siis_channel *)cam_sim_softc(sim);
1814 mtx_assert(&ch->mtx, MA_OWNED);
1815 switch (ccb->ccb_h.func_code) {
1816 /* Common cases first */
1817 case XPT_ATA_IO: /* Execute the requested I/O operation */
1819 if (siis_check_ids(dev, ccb))
1821 if (ch->devices == 0 ||
1822 (ch->pm_present == 0 &&
1823 ccb->ccb_h.target_id > 0 && ccb->ccb_h.target_id < 15)) {
1824 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
1827 ccb->ccb_h.recovery_type = RECOVERY_NONE;
1828 /* Check for command collision. */
1829 if (siis_check_collision(dev, ccb)) {
1830 /* Freeze command. */
1832 /* We have only one frozen slot, so freeze simq also. */
1833 xpt_freeze_simq(ch->sim, 1);
1836 siis_begin_transaction(dev, ccb);
1838 case XPT_EN_LUN: /* Enable LUN as a target */
1839 case XPT_TARGET_IO: /* Execute target I/O request */
1840 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
1841 case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/
1842 case XPT_ABORT: /* Abort the specified CCB */
1844 ccb->ccb_h.status = CAM_REQ_INVALID;
1846 case XPT_SET_TRAN_SETTINGS:
1848 struct ccb_trans_settings *cts = &ccb->cts;
1849 struct siis_device *d;
1851 if (siis_check_ids(dev, ccb))
1853 if (cts->type == CTS_TYPE_CURRENT_SETTINGS)
1854 d = &ch->curr[ccb->ccb_h.target_id];
1856 d = &ch->user[ccb->ccb_h.target_id];
1857 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_REVISION)
1858 d->revision = cts->xport_specific.sata.revision;
1859 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_MODE)
1860 d->mode = cts->xport_specific.sata.mode;
1861 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
1862 d->bytecount = min(8192, cts->xport_specific.sata.bytecount);
1863 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_TAGS)
1864 d->tags = min(SIIS_MAX_SLOTS, cts->xport_specific.sata.tags);
1865 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_PM) {
1866 ch->pm_present = cts->xport_specific.sata.pm_present;
1868 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1870 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1872 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_TAGS)
1873 d->atapi = cts->xport_specific.sata.atapi;
1874 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1875 d->caps = cts->xport_specific.sata.caps;
1876 ccb->ccb_h.status = CAM_REQ_CMP;
1879 case XPT_GET_TRAN_SETTINGS:
1880 /* Get default/user set transfer settings for the target */
1882 struct ccb_trans_settings *cts = &ccb->cts;
1883 struct siis_device *d;
1886 if (siis_check_ids(dev, ccb))
1888 if (cts->type == CTS_TYPE_CURRENT_SETTINGS)
1889 d = &ch->curr[ccb->ccb_h.target_id];
1891 d = &ch->user[ccb->ccb_h.target_id];
1892 cts->protocol = PROTO_UNSPECIFIED;
1893 cts->protocol_version = PROTO_VERSION_UNSPECIFIED;
1894 cts->transport = XPORT_SATA;
1895 cts->transport_version = XPORT_VERSION_UNSPECIFIED;
1896 cts->proto_specific.valid = 0;
1897 cts->xport_specific.sata.valid = 0;
1898 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1899 (ccb->ccb_h.target_id == 15 ||
1900 (ccb->ccb_h.target_id == 0 && !ch->pm_present))) {
1901 status = ATA_INL(ch->r_mem, SIIS_P_SSTS) & ATA_SS_SPD_MASK;
1902 if (status & 0x0f0) {
1903 cts->xport_specific.sata.revision =
1904 (status & 0x0f0) >> 4;
1905 cts->xport_specific.sata.valid |=
1906 CTS_SATA_VALID_REVISION;
1908 cts->xport_specific.sata.caps = d->caps & CTS_SATA_CAPS_D;
1910 cts->xport_specific.sata.caps |= CTS_SATA_CAPS_H_PMREQ;
1911 cts->xport_specific.sata.caps |= CTS_SATA_CAPS_H_AN;
1912 cts->xport_specific.sata.caps &=
1913 ch->user[ccb->ccb_h.target_id].caps;
1914 cts->xport_specific.sata.valid |= CTS_SATA_VALID_CAPS;
1916 cts->xport_specific.sata.revision = d->revision;
1917 cts->xport_specific.sata.valid |= CTS_SATA_VALID_REVISION;
1918 cts->xport_specific.sata.caps = d->caps;
1919 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1920 (ch->quirks & SIIS_Q_SNTF) == 0)
1921 cts->xport_specific.sata.caps &= ~CTS_SATA_CAPS_H_AN;
1922 cts->xport_specific.sata.valid |= CTS_SATA_VALID_CAPS;
1924 cts->xport_specific.sata.mode = d->mode;
1925 cts->xport_specific.sata.valid |= CTS_SATA_VALID_MODE;
1926 cts->xport_specific.sata.bytecount = d->bytecount;
1927 cts->xport_specific.sata.valid |= CTS_SATA_VALID_BYTECOUNT;
1928 cts->xport_specific.sata.pm_present = ch->pm_present;
1929 cts->xport_specific.sata.valid |= CTS_SATA_VALID_PM;
1930 cts->xport_specific.sata.tags = d->tags;
1931 cts->xport_specific.sata.valid |= CTS_SATA_VALID_TAGS;
1932 cts->xport_specific.sata.atapi = d->atapi;
1933 cts->xport_specific.sata.valid |= CTS_SATA_VALID_ATAPI;
1934 ccb->ccb_h.status = CAM_REQ_CMP;
1937 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
1938 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
1940 ccb->ccb_h.status = CAM_REQ_CMP;
1942 case XPT_TERM_IO: /* Terminate the I/O process */
1944 ccb->ccb_h.status = CAM_REQ_INVALID;
1946 case XPT_PATH_INQ: /* Path routing inquiry */
1948 struct ccb_pathinq *cpi = &ccb->cpi;
1950 cpi->version_num = 1; /* XXX??? */
1951 cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE;
1952 cpi->hba_inquiry |= PI_SATAPM;
1953 cpi->target_sprt = 0;
1954 cpi->hba_misc = PIM_SEQSCAN;
1955 cpi->hba_eng_cnt = 0;
1956 cpi->max_target = 15;
1958 cpi->initiator_id = 0;
1959 cpi->bus_id = cam_sim_bus(sim);
1960 cpi->base_transfer_speed = 150000;
1961 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1962 strncpy(cpi->hba_vid, "SIIS", HBA_IDLEN);
1963 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1964 cpi->unit_number = cam_sim_unit(sim);
1965 cpi->transport = XPORT_SATA;
1966 cpi->transport_version = XPORT_VERSION_UNSPECIFIED;
1967 cpi->protocol = PROTO_UNSPECIFIED;
1968 cpi->protocol_version = PROTO_VERSION_UNSPECIFIED;
1969 cpi->ccb_h.status = CAM_REQ_CMP;
1970 cpi->maxio = MAXPHYS;
1974 ccb->ccb_h.status = CAM_REQ_INVALID;
1981 siispoll(struct cam_sim *sim)
1983 struct siis_channel *ch = (struct siis_channel *)cam_sim_softc(sim);
1985 siis_ch_intr(ch->dev);