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 static 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);
209 /* Detach & delete all children */
210 device_delete_children(dev);
212 /* Free interrupts. */
213 if (ctlr->irq.r_irq) {
214 bus_teardown_intr(dev, ctlr->irq.r_irq,
216 bus_release_resource(dev, SYS_RES_IRQ,
217 ctlr->irq.r_irq_rid, ctlr->irq.r_irq);
219 pci_release_msi(dev);
221 rman_fini(&ctlr->sc_iomem);
222 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_rid, ctlr->r_mem);
223 bus_release_resource(dev, SYS_RES_MEMORY, ctlr->r_grid, ctlr->r_gmem);
228 siis_suspend(device_t dev)
230 struct siis_controller *ctlr = device_get_softc(dev);
232 bus_generic_suspend(dev);
233 /* Put controller into reset state. */
234 ctlr->gctl |= SIIS_GCTL_GRESET;
235 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL, ctlr->gctl);
240 siis_resume(device_t dev)
242 struct siis_controller *ctlr = device_get_softc(dev);
244 /* Set PCIe max read request size to at least 1024 bytes */
245 if (pci_get_max_read_req(dev) < 1024)
246 pci_set_max_read_req(dev, 1024);
247 /* Put controller into reset state. */
248 ctlr->gctl |= SIIS_GCTL_GRESET;
249 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL, ctlr->gctl);
251 /* Get controller out of reset state and enable port interrupts. */
252 ctlr->gctl &= ~(SIIS_GCTL_GRESET | SIIS_GCTL_I2C_IE);
253 ctlr->gctl |= 0x0000000f;
254 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL, ctlr->gctl);
255 return (bus_generic_resume(dev));
259 siis_setup_interrupt(device_t dev)
261 struct siis_controller *ctlr = device_get_softc(dev);
262 int msi = ctlr->quirks & SIIS_Q_NOMSI ? 0 : 1;
265 resource_int_value(device_get_name(dev),
266 device_get_unit(dev), "msi", &msi);
270 msi = min(1, pci_msi_count(dev));
271 /* Allocate MSI if needed/present. */
272 if (msi && pci_alloc_msi(dev, &msi) != 0)
274 /* Allocate all IRQs. */
275 ctlr->irq.r_irq_rid = msi ? 1 : 0;
276 if (!(ctlr->irq.r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
277 &ctlr->irq.r_irq_rid, RF_SHAREABLE | RF_ACTIVE))) {
278 device_printf(dev, "unable to map interrupt\n");
281 if ((bus_setup_intr(dev, ctlr->irq.r_irq, ATA_INTR_FLAGS, NULL,
282 siis_intr, ctlr, &ctlr->irq.handle))) {
283 /* SOS XXX release r_irq */
284 device_printf(dev, "unable to setup interrupt\n");
291 * Common case interrupt handler.
294 siis_intr(void *data)
296 struct siis_controller *ctlr = (struct siis_controller *)data;
301 is = ATA_INL(ctlr->r_gmem, SIIS_IS);
302 for (unit = 0; unit < ctlr->channels; unit++) {
303 if ((is & SIIS_IS_PORT(unit)) != 0 &&
304 (arg = ctlr->interrupt[unit].argument)) {
305 ctlr->interrupt[unit].function(arg);
308 /* Acknowledge interrupt, if MSI enabled. */
309 if (ctlr->irq.r_irq_rid) {
310 ATA_OUTL(ctlr->r_gmem, SIIS_GCTL,
311 ctlr->gctl | SIIS_GCTL_MSIACK);
315 static struct resource *
316 siis_alloc_resource(device_t dev, device_t child, int type, int *rid,
317 u_long start, u_long end, u_long count, u_int flags)
319 struct siis_controller *ctlr = device_get_softc(dev);
320 int unit = ((struct siis_channel *)device_get_softc(child))->unit;
321 struct resource *res = NULL;
322 int offset = unit << 13;
327 st = rman_get_start(ctlr->r_mem);
328 res = rman_reserve_resource(&ctlr->sc_iomem, st + offset,
329 st + offset + 0x2000, 0x2000, RF_ACTIVE, child);
331 bus_space_handle_t bsh;
333 bsh = rman_get_bushandle(ctlr->r_mem);
334 bst = rman_get_bustag(ctlr->r_mem);
335 bus_space_subregion(bst, bsh, offset, 0x2000, &bsh);
336 rman_set_bushandle(res, bsh);
337 rman_set_bustag(res, bst);
341 if (*rid == ATA_IRQ_RID)
342 res = ctlr->irq.r_irq;
349 siis_release_resource(device_t dev, device_t child, int type, int rid,
355 rman_release_resource(r);
358 if (rid != ATA_IRQ_RID)
366 siis_setup_intr(device_t dev, device_t child, struct resource *irq,
367 int flags, driver_filter_t *filter, driver_intr_t *function,
368 void *argument, void **cookiep)
370 struct siis_controller *ctlr = device_get_softc(dev);
371 int unit = (intptr_t)device_get_ivars(child);
373 if (filter != NULL) {
374 printf("siis.c: we cannot use a filter here\n");
377 ctlr->interrupt[unit].function = function;
378 ctlr->interrupt[unit].argument = argument;
383 siis_teardown_intr(device_t dev, device_t child, struct resource *irq,
386 struct siis_controller *ctlr = device_get_softc(dev);
387 int unit = (intptr_t)device_get_ivars(child);
389 ctlr->interrupt[unit].function = NULL;
390 ctlr->interrupt[unit].argument = NULL;
395 siis_print_child(device_t dev, device_t child)
399 retval = bus_print_child_header(dev, child);
400 retval += printf(" at channel %d",
401 (int)(intptr_t)device_get_ivars(child));
402 retval += bus_print_child_footer(dev, child);
408 siis_child_location_str(device_t dev, device_t child, char *buf,
412 snprintf(buf, buflen, "channel=%d",
413 (int)(intptr_t)device_get_ivars(child));
417 devclass_t siis_devclass;
418 static device_method_t siis_methods[] = {
419 DEVMETHOD(device_probe, siis_probe),
420 DEVMETHOD(device_attach, siis_attach),
421 DEVMETHOD(device_detach, siis_detach),
422 DEVMETHOD(device_suspend, siis_suspend),
423 DEVMETHOD(device_resume, siis_resume),
424 DEVMETHOD(bus_print_child, siis_print_child),
425 DEVMETHOD(bus_alloc_resource, siis_alloc_resource),
426 DEVMETHOD(bus_release_resource, siis_release_resource),
427 DEVMETHOD(bus_setup_intr, siis_setup_intr),
428 DEVMETHOD(bus_teardown_intr,siis_teardown_intr),
429 DEVMETHOD(bus_child_location_str, siis_child_location_str),
432 static driver_t siis_driver = {
435 sizeof(struct siis_controller)
437 DRIVER_MODULE(siis, pci, siis_driver, siis_devclass, 0, 0);
438 MODULE_VERSION(siis, 1);
439 MODULE_DEPEND(siis, cam, 1, 1, 1);
442 siis_ch_probe(device_t dev)
445 device_set_desc_copy(dev, "SIIS channel");
450 siis_ch_attach(device_t dev)
452 struct siis_controller *ctlr = device_get_softc(device_get_parent(dev));
453 struct siis_channel *ch = device_get_softc(dev);
454 struct cam_devq *devq;
455 int rid, error, i, sata_rev = 0;
458 ch->unit = (intptr_t)device_get_ivars(dev);
459 ch->quirks = ctlr->quirks;
460 resource_int_value(device_get_name(dev),
461 device_get_unit(dev), "pm_level", &ch->pm_level);
462 resource_int_value(device_get_name(dev),
463 device_get_unit(dev), "sata_rev", &sata_rev);
464 for (i = 0; i < 16; i++) {
465 ch->user[i].revision = sata_rev;
466 ch->user[i].mode = 0;
467 ch->user[i].bytecount = 8192;
468 ch->user[i].tags = SIIS_MAX_SLOTS;
469 ch->curr[i] = ch->user[i];
471 ch->user[i].caps = CTS_SATA_CAPS_H_PMREQ;
472 ch->user[i].caps |= CTS_SATA_CAPS_H_AN;
474 mtx_init(&ch->mtx, "SIIS channel lock", NULL, MTX_DEF);
476 if (!(ch->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
480 siis_slotsalloc(dev);
484 if (!(ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
485 &rid, RF_SHAREABLE | RF_ACTIVE))) {
486 device_printf(dev, "Unable to map interrupt\n");
490 if ((bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL,
491 siis_ch_intr_locked, dev, &ch->ih))) {
492 device_printf(dev, "Unable to setup interrupt\n");
496 /* Create the device queue for our SIM. */
497 devq = cam_simq_alloc(SIIS_MAX_SLOTS);
499 device_printf(dev, "Unable to allocate simq\n");
503 /* Construct SIM entry */
504 ch->sim = cam_sim_alloc(siisaction, siispoll, "siisch", ch,
505 device_get_unit(dev), &ch->mtx, 2, SIIS_MAX_SLOTS, devq);
506 if (ch->sim == NULL) {
508 device_printf(dev, "unable to allocate sim\n");
512 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) {
513 device_printf(dev, "unable to register xpt bus\n");
517 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim),
518 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
519 device_printf(dev, "unable to create path\n");
523 mtx_unlock(&ch->mtx);
524 ch->led = led_create(siis_ch_led, dev, device_get_nameunit(dev));
528 xpt_bus_deregister(cam_sim_path(ch->sim));
530 cam_sim_free(ch->sim, /*free_devq*/TRUE);
532 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
534 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
535 mtx_unlock(&ch->mtx);
536 mtx_destroy(&ch->mtx);
541 siis_ch_detach(device_t dev)
543 struct siis_channel *ch = device_get_softc(dev);
545 led_destroy(ch->led);
547 xpt_async(AC_LOST_DEVICE, ch->path, NULL);
548 xpt_free_path(ch->path);
549 xpt_bus_deregister(cam_sim_path(ch->sim));
550 cam_sim_free(ch->sim, /*free_devq*/TRUE);
551 mtx_unlock(&ch->mtx);
553 bus_teardown_intr(dev, ch->r_irq, ch->ih);
554 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
560 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
561 mtx_destroy(&ch->mtx);
566 siis_ch_init(device_t dev)
568 struct siis_channel *ch = device_get_softc(dev);
570 /* Get port out of reset state. */
571 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
572 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
574 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
576 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
577 /* Enable port interrupts */
578 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
583 siis_ch_deinit(device_t dev)
585 struct siis_channel *ch = device_get_softc(dev);
587 /* Put port into reset state. */
588 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
593 siis_ch_suspend(device_t dev)
595 struct siis_channel *ch = device_get_softc(dev);
598 xpt_freeze_simq(ch->sim, 1);
600 msleep(ch, &ch->mtx, PRIBIO, "siissusp", hz/100);
602 mtx_unlock(&ch->mtx);
607 siis_ch_resume(device_t dev)
609 struct siis_channel *ch = device_get_softc(dev);
614 xpt_release_simq(ch->sim, TRUE);
615 mtx_unlock(&ch->mtx);
619 devclass_t siisch_devclass;
620 static device_method_t siisch_methods[] = {
621 DEVMETHOD(device_probe, siis_ch_probe),
622 DEVMETHOD(device_attach, siis_ch_attach),
623 DEVMETHOD(device_detach, siis_ch_detach),
624 DEVMETHOD(device_suspend, siis_ch_suspend),
625 DEVMETHOD(device_resume, siis_ch_resume),
628 static driver_t siisch_driver = {
631 sizeof(struct siis_channel)
633 DRIVER_MODULE(siisch, siis, siisch_driver, siis_devclass, 0, 0);
636 siis_ch_led(void *priv, int onoff)
639 struct siis_channel *ch;
641 dev = (device_t)priv;
642 ch = device_get_softc(dev);
645 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_LED_ON);
647 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_LED_ON);
650 struct siis_dc_cb_args {
656 siis_dmainit(device_t dev)
658 struct siis_channel *ch = device_get_softc(dev);
659 struct siis_dc_cb_args dcba;
662 if (bus_dma_tag_create(bus_get_dma_tag(dev), 1024, 0,
663 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
664 NULL, NULL, SIIS_WORK_SIZE, 1, SIIS_WORK_SIZE,
665 0, NULL, NULL, &ch->dma.work_tag))
667 if (bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, 0,
670 if (bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work,
671 SIIS_WORK_SIZE, siis_dmasetupc_cb, &dcba, 0) || dcba.error) {
672 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
675 ch->dma.work_bus = dcba.maddr;
677 if (bus_dma_tag_create(bus_get_dma_tag(dev), 1, 0,
678 BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
680 SIIS_SG_ENTRIES * PAGE_SIZE * SIIS_MAX_SLOTS,
681 SIIS_SG_ENTRIES, 0xFFFFFFFF,
682 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag)) {
688 device_printf(dev, "WARNING - DMA initialization failed\n");
693 siis_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
695 struct siis_dc_cb_args *dcba = (struct siis_dc_cb_args *)xsc;
697 if (!(dcba->error = error))
698 dcba->maddr = segs[0].ds_addr;
702 siis_dmafini(device_t dev)
704 struct siis_channel *ch = device_get_softc(dev);
706 if (ch->dma.data_tag) {
707 bus_dma_tag_destroy(ch->dma.data_tag);
708 ch->dma.data_tag = NULL;
710 if (ch->dma.work_bus) {
711 bus_dmamap_unload(ch->dma.work_tag, ch->dma.work_map);
712 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
713 ch->dma.work_bus = 0;
714 ch->dma.work_map = NULL;
717 if (ch->dma.work_tag) {
718 bus_dma_tag_destroy(ch->dma.work_tag);
719 ch->dma.work_tag = NULL;
724 siis_slotsalloc(device_t dev)
726 struct siis_channel *ch = device_get_softc(dev);
729 /* Alloc and setup command/dma slots */
730 bzero(ch->slot, sizeof(ch->slot));
731 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
732 struct siis_slot *slot = &ch->slot[i];
736 slot->state = SIIS_SLOT_EMPTY;
738 callout_init_mtx(&slot->timeout, &ch->mtx, 0);
740 if (bus_dmamap_create(ch->dma.data_tag, 0, &slot->dma.data_map))
741 device_printf(ch->dev, "FAILURE - create data_map\n");
746 siis_slotsfree(device_t dev)
748 struct siis_channel *ch = device_get_softc(dev);
751 /* Free all dma slots */
752 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
753 struct siis_slot *slot = &ch->slot[i];
755 callout_drain(&slot->timeout);
756 if (slot->dma.data_map) {
757 bus_dmamap_destroy(ch->dma.data_tag, slot->dma.data_map);
758 slot->dma.data_map = NULL;
764 siis_notify_events(device_t dev)
766 struct siis_channel *ch = device_get_softc(dev);
767 struct cam_path *dpath;
771 if (ch->quirks & SIIS_Q_SNTF) {
772 status = ATA_INL(ch->r_mem, SIIS_P_SNTF);
773 ATA_OUTL(ch->r_mem, SIIS_P_SNTF, status);
776 * Without SNTF we have no idea which device sent notification.
777 * If PMP is connected, assume it, else - device.
779 status = (ch->pm_present) ? 0x8000 : 0x0001;
782 device_printf(dev, "SNTF 0x%04x\n", status);
783 for (i = 0; i < 16; i++) {
784 if ((status & (1 << i)) == 0)
786 if (xpt_create_path(&dpath, NULL,
787 xpt_path_path_id(ch->path), i, 0) == CAM_REQ_CMP) {
788 xpt_async(AC_SCSI_AEN, dpath, NULL);
789 xpt_free_path(dpath);
796 siis_phy_check_events(device_t dev)
798 struct siis_channel *ch = device_get_softc(dev);
800 /* If we have a connection event, deal with it */
801 if (ch->pm_level == 0) {
802 u_int32_t status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
806 if (((status & ATA_SS_DET_MASK) == ATA_SS_DET_PHY_ONLINE) &&
807 ((status & ATA_SS_SPD_MASK) != ATA_SS_SPD_NO_SPEED) &&
808 ((status & ATA_SS_IPM_MASK) == ATA_SS_IPM_ACTIVE)) {
809 device_printf(dev, "CONNECT requested\n");
811 device_printf(dev, "DISCONNECT requested\n");
814 if ((ccb = xpt_alloc_ccb_nowait()) == NULL)
816 if (xpt_create_path(&ccb->ccb_h.path, NULL,
817 cam_sim_path(ch->sim),
818 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
827 siis_ch_intr_locked(void *data)
829 device_t dev = (device_t)data;
830 struct siis_channel *ch = device_get_softc(dev);
833 xpt_batch_start(ch->sim);
835 xpt_batch_done(ch->sim);
836 mtx_unlock(&ch->mtx);
840 siis_ch_intr(void *data)
842 device_t dev = (device_t)data;
843 struct siis_channel *ch = device_get_softc(dev);
844 uint32_t istatus, sstatus, ctx, estatus, ok, err = 0;
845 enum siis_err_type et;
846 int i, ccs, port, tslots;
848 mtx_assert(&ch->mtx, MA_OWNED);
849 /* Read command statuses. */
850 sstatus = ATA_INL(ch->r_mem, SIIS_P_SS);
851 ok = ch->rslots & ~sstatus;
852 /* Complete all successfull commands. */
853 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
855 siis_end_transaction(&ch->slot[i], SIIS_ERR_NONE);
857 /* Do we have any other events? */
858 if ((sstatus & SIIS_P_SS_ATTN) == 0)
860 /* Read and clear interrupt statuses. */
861 istatus = ATA_INL(ch->r_mem, SIIS_P_IS) &
862 (0xFFFF & ~SIIS_P_IX_COMMCOMP);
863 ATA_OUTL(ch->r_mem, SIIS_P_IS, istatus);
864 /* Process PHY events */
865 if (istatus & SIIS_P_IX_PHYRDYCHG)
866 siis_phy_check_events(dev);
867 /* Process NOTIFY events */
868 if (istatus & SIIS_P_IX_SDBN)
869 siis_notify_events(dev);
870 /* Process command errors */
871 if (istatus & SIIS_P_IX_COMMERR) {
872 estatus = ATA_INL(ch->r_mem, SIIS_P_CMDERR);
873 ctx = ATA_INL(ch->r_mem, SIIS_P_CTX);
874 ccs = (ctx & SIIS_P_CTX_SLOT) >> SIIS_P_CTX_SLOT_SHIFT;
875 port = (ctx & SIIS_P_CTX_PMP) >> SIIS_P_CTX_PMP_SHIFT;
876 err = ch->rslots & sstatus;
877 //device_printf(dev, "%s ERROR ss %08x is %08x rs %08x es %d act %d port %d serr %08x\n",
878 // __func__, sstatus, istatus, ch->rslots, estatus, ccs, port,
879 // ATA_INL(ch->r_mem, SIIS_P_SERR));
881 if (!ch->recoverycmd && !ch->recovery) {
882 xpt_freeze_simq(ch->sim, ch->numrslots);
886 union ccb *fccb = ch->frozen;
888 fccb->ccb_h.status &= ~CAM_STATUS_MASK;
889 fccb->ccb_h.status |= CAM_REQUEUE_REQ | CAM_RELEASE_SIMQ;
890 if (!(fccb->ccb_h.status & CAM_DEV_QFRZN)) {
891 xpt_freeze_devq(fccb->ccb_h.path, 1);
892 fccb->ccb_h.status |= CAM_DEV_QFRZN;
896 if (estatus == SIIS_P_CMDERR_DEV ||
897 estatus == SIIS_P_CMDERR_SDB ||
898 estatus == SIIS_P_CMDERR_DATAFIS) {
899 tslots = ch->numtslots[port];
900 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
901 /* XXX: requests in loading state. */
902 if (((ch->rslots >> i) & 1) == 0)
904 if (ch->slot[i].ccb->ccb_h.target_id != port)
907 /* Untagged operation. */
911 et = SIIS_ERR_INNOCENT;
913 /* Tagged operation. */
916 siis_end_transaction(&ch->slot[i], et);
919 * We can't reinit port if there are some other
920 * commands active, use resume to complete them.
922 if (ch->rslots != 0 && !ch->recoverycmd)
923 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_RESUME);
925 if (estatus == SIIS_P_CMDERR_SENDFIS ||
926 estatus == SIIS_P_CMDERR_INCSTATE ||
927 estatus == SIIS_P_CMDERR_PPE ||
928 estatus == SIIS_P_CMDERR_SERVICE) {
931 et = SIIS_ERR_INVALID;
932 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
933 /* XXX: requests in loading state. */
934 if (((ch->rslots >> i) & 1) == 0)
936 siis_end_transaction(&ch->slot[i], et);
942 /* Must be called with channel locked. */
944 siis_check_collision(device_t dev, union ccb *ccb)
946 struct siis_channel *ch = device_get_softc(dev);
948 mtx_assert(&ch->mtx, MA_OWNED);
949 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
950 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA)) {
951 /* Tagged command while we have no supported tag free. */
952 if (((~ch->oslots) & (0x7fffffff >> (31 -
953 ch->curr[ccb->ccb_h.target_id].tags))) == 0)
956 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
957 (ccb->ataio.cmd.flags & (CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT))) {
958 /* Atomic command while anything active. */
959 if (ch->numrslots != 0)
962 /* We have some atomic command running. */
968 /* Must be called with channel locked. */
970 siis_begin_transaction(device_t dev, union ccb *ccb)
972 struct siis_channel *ch = device_get_softc(dev);
973 struct siis_slot *slot;
976 mtx_assert(&ch->mtx, MA_OWNED);
977 /* Choose empty slot. */
978 tags = SIIS_MAX_SLOTS;
979 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
980 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA))
981 tags = ch->curr[ccb->ccb_h.target_id].tags;
982 tag = fls((~ch->oslots) & (0x7fffffff >> (31 - tags))) - 1;
983 /* Occupy chosen slot. */
984 slot = &ch->slot[tag];
986 /* Update channel stats. */
987 ch->oslots |= (1 << slot->slot);
989 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
990 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA)) {
991 ch->numtslots[ccb->ccb_h.target_id]++;
993 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
994 (ccb->ataio.cmd.flags & (CAM_ATAIO_CONTROL | CAM_ATAIO_NEEDRESULT)))
995 ch->aslots |= (1 << slot->slot);
997 /* If request moves data, setup and load SG list */
998 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
999 slot->state = SIIS_SLOT_LOADING;
1000 bus_dmamap_load_ccb(ch->dma.data_tag, slot->dma.data_map,
1001 ccb, siis_dmasetprd, slot, 0);
1003 siis_execute_transaction(slot);
1006 /* Locked by busdma engine. */
1008 siis_dmasetprd(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
1010 struct siis_slot *slot = arg;
1011 struct siis_channel *ch = device_get_softc(slot->dev);
1012 struct siis_cmd *ctp;
1013 struct siis_dma_prd *prd;
1016 mtx_assert(&ch->mtx, MA_OWNED);
1018 device_printf(slot->dev, "DMA load error\n");
1019 if (!ch->recoverycmd)
1020 xpt_freeze_simq(ch->sim, 1);
1021 siis_end_transaction(slot, SIIS_ERR_INVALID);
1024 KASSERT(nsegs <= SIIS_SG_ENTRIES, ("too many DMA segment entries\n"));
1025 slot->dma.nsegs = nsegs;
1027 /* Get a piece of the workspace for this request */
1028 ctp = (struct siis_cmd *)(ch->dma.work + SIIS_CT_OFFSET +
1029 (SIIS_CT_SIZE * slot->slot));
1030 /* Fill S/G table */
1031 if (slot->ccb->ccb_h.func_code == XPT_ATA_IO)
1032 prd = &ctp->u.ata.prd[0];
1034 prd = &ctp->u.atapi.prd[0];
1035 for (i = 0; i < nsegs; i++) {
1036 prd[i].dba = htole64(segs[i].ds_addr);
1037 prd[i].dbc = htole32(segs[i].ds_len);
1040 prd[nsegs - 1].control = htole32(SIIS_PRD_TRM);
1041 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1042 ((slot->ccb->ccb_h.flags & CAM_DIR_IN) ?
1043 BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
1045 siis_execute_transaction(slot);
1048 /* Must be called with channel locked. */
1050 siis_execute_transaction(struct siis_slot *slot)
1052 device_t dev = slot->dev;
1053 struct siis_channel *ch = device_get_softc(dev);
1054 struct siis_cmd *ctp;
1055 union ccb *ccb = slot->ccb;
1058 mtx_assert(&ch->mtx, MA_OWNED);
1059 /* Get a piece of the workspace for this request */
1060 ctp = (struct siis_cmd *)
1061 (ch->dma.work + SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot));
1063 ctp->protocol_override = 0;
1064 ctp->transfer_count = 0;
1065 /* Special handling for Soft Reset command. */
1066 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1067 if (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) {
1068 ctp->control |= htole16(SIIS_PRB_SOFT_RESET);
1070 ctp->control |= htole16(SIIS_PRB_PROTOCOL_OVERRIDE);
1071 if (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA) {
1072 ctp->protocol_override |=
1073 htole16(SIIS_PRB_PROTO_NCQ);
1075 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1076 ctp->protocol_override |=
1077 htole16(SIIS_PRB_PROTO_READ);
1079 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1080 ctp->protocol_override |=
1081 htole16(SIIS_PRB_PROTO_WRITE);
1084 } else if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1085 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1086 ctp->control |= htole16(SIIS_PRB_PACKET_READ);
1088 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
1089 ctp->control |= htole16(SIIS_PRB_PACKET_WRITE);
1091 /* Special handling for Soft Reset command. */
1092 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
1093 (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) &&
1094 (ccb->ataio.cmd.control & ATA_A_RESET)) {
1095 /* Kick controller into sane state */
1098 /* Setup the FIS for this request */
1099 if (!siis_setup_fis(dev, ctp, ccb, slot->slot)) {
1100 device_printf(ch->dev, "Setting up SATA FIS failed\n");
1101 if (!ch->recoverycmd)
1102 xpt_freeze_simq(ch->sim, 1);
1103 siis_end_transaction(slot, SIIS_ERR_INVALID);
1106 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1107 BUS_DMASYNC_PREWRITE);
1108 /* Issue command to the controller. */
1109 slot->state = SIIS_SLOT_RUNNING;
1110 ch->rslots |= (1 << slot->slot);
1111 prb_bus = ch->dma.work_bus +
1112 SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot);
1113 ATA_OUTL(ch->r_mem, SIIS_P_CACTL(slot->slot), prb_bus);
1114 ATA_OUTL(ch->r_mem, SIIS_P_CACTH(slot->slot), prb_bus >> 32);
1115 /* Start command execution timeout */
1116 callout_reset(&slot->timeout, (int)ccb->ccb_h.timeout * hz / 1000,
1117 (timeout_t*)siis_timeout, slot);
1121 /* Must be called with channel locked. */
1123 siis_process_timeout(device_t dev)
1125 struct siis_channel *ch = device_get_softc(dev);
1128 mtx_assert(&ch->mtx, MA_OWNED);
1129 if (!ch->recoverycmd && !ch->recovery) {
1130 xpt_freeze_simq(ch->sim, ch->numrslots);
1133 /* Handle the rest of commands. */
1134 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1135 /* Do we have a running request on slot? */
1136 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1138 siis_end_transaction(&ch->slot[i], SIIS_ERR_TIMEOUT);
1142 /* Must be called with channel locked. */
1144 siis_rearm_timeout(device_t dev)
1146 struct siis_channel *ch = device_get_softc(dev);
1149 mtx_assert(&ch->mtx, MA_OWNED);
1150 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1151 struct siis_slot *slot = &ch->slot[i];
1153 /* Do we have a running request on slot? */
1154 if (slot->state < SIIS_SLOT_RUNNING)
1156 if ((ch->toslots & (1 << i)) == 0)
1158 callout_reset(&slot->timeout,
1159 (int)slot->ccb->ccb_h.timeout * hz / 1000,
1160 (timeout_t*)siis_timeout, slot);
1164 /* Locked by callout mechanism. */
1166 siis_timeout(struct siis_slot *slot)
1168 device_t dev = slot->dev;
1169 struct siis_channel *ch = device_get_softc(dev);
1170 union ccb *ccb = slot->ccb;
1172 mtx_assert(&ch->mtx, MA_OWNED);
1173 /* Check for stale timeout. */
1174 if (slot->state < SIIS_SLOT_RUNNING)
1177 /* Handle soft-reset timeouts without doing hard-reset. */
1178 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
1179 (ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) &&
1180 (ccb->ataio.cmd.control & ATA_A_RESET)) {
1181 xpt_freeze_simq(ch->sim, ch->numrslots);
1182 siis_end_transaction(slot, SIIS_ERR_TFE);
1186 device_printf(dev, "Timeout on slot %d\n", slot->slot);
1187 device_printf(dev, "%s is %08x ss %08x rs %08x es %08x sts %08x serr %08x\n",
1188 __func__, ATA_INL(ch->r_mem, SIIS_P_IS),
1189 ATA_INL(ch->r_mem, SIIS_P_SS), ch->rslots,
1190 ATA_INL(ch->r_mem, SIIS_P_CMDERR), ATA_INL(ch->r_mem, SIIS_P_STS),
1191 ATA_INL(ch->r_mem, SIIS_P_SERR));
1193 if (ch->toslots == 0)
1194 xpt_freeze_simq(ch->sim, 1);
1195 ch->toslots |= (1 << slot->slot);
1196 if ((ch->rslots & ~ch->toslots) == 0)
1197 siis_process_timeout(dev);
1199 device_printf(dev, " ... waiting for slots %08x\n",
1200 ch->rslots & ~ch->toslots);
1203 /* Must be called with channel locked. */
1205 siis_end_transaction(struct siis_slot *slot, enum siis_err_type et)
1207 device_t dev = slot->dev;
1208 struct siis_channel *ch = device_get_softc(dev);
1209 union ccb *ccb = slot->ccb;
1212 mtx_assert(&ch->mtx, MA_OWNED);
1213 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1214 BUS_DMASYNC_POSTWRITE);
1215 /* Read result registers to the result struct
1216 * May be incorrect if several commands finished same time,
1217 * so read only when sure or have to.
1219 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1220 struct ata_res *res = &ccb->ataio.res;
1221 if ((et == SIIS_ERR_TFE) ||
1222 (ccb->ataio.cmd.flags & CAM_ATAIO_NEEDRESULT)) {
1223 int offs = SIIS_P_LRAM_SLOT(slot->slot) + 8;
1225 res->status = ATA_INB(ch->r_mem, offs + 2);
1226 res->error = ATA_INB(ch->r_mem, offs + 3);
1227 res->lba_low = ATA_INB(ch->r_mem, offs + 4);
1228 res->lba_mid = ATA_INB(ch->r_mem, offs + 5);
1229 res->lba_high = ATA_INB(ch->r_mem, offs + 6);
1230 res->device = ATA_INB(ch->r_mem, offs + 7);
1231 res->lba_low_exp = ATA_INB(ch->r_mem, offs + 8);
1232 res->lba_mid_exp = ATA_INB(ch->r_mem, offs + 9);
1233 res->lba_high_exp = ATA_INB(ch->r_mem, offs + 10);
1234 res->sector_count = ATA_INB(ch->r_mem, offs + 12);
1235 res->sector_count_exp = ATA_INB(ch->r_mem, offs + 13);
1237 bzero(res, sizeof(*res));
1238 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN &&
1239 ch->numrslots == 1) {
1240 ccb->ataio.resid = ccb->ataio.dxfer_len -
1241 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1244 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN &&
1245 ch->numrslots == 1) {
1246 ccb->csio.resid = ccb->csio.dxfer_len -
1247 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1250 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1251 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1252 (ccb->ccb_h.flags & CAM_DIR_IN) ?
1253 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1254 bus_dmamap_unload(ch->dma.data_tag, slot->dma.data_map);
1256 /* Set proper result status. */
1257 if (et != SIIS_ERR_NONE || ch->recovery) {
1258 ch->eslots |= (1 << slot->slot);
1259 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1261 /* In case of error, freeze device for proper recovery. */
1262 if (et != SIIS_ERR_NONE && (!ch->recoverycmd) &&
1263 !(ccb->ccb_h.status & CAM_DEV_QFRZN)) {
1264 xpt_freeze_devq(ccb->ccb_h.path, 1);
1265 ccb->ccb_h.status |= CAM_DEV_QFRZN;
1267 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1270 ccb->ccb_h.status |= CAM_REQ_CMP;
1271 if (ccb->ccb_h.func_code == XPT_SCSI_IO)
1272 ccb->csio.scsi_status = SCSI_STATUS_OK;
1274 case SIIS_ERR_INVALID:
1276 ccb->ccb_h.status |= CAM_REQ_INVALID;
1278 case SIIS_ERR_INNOCENT:
1279 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
1283 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1284 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
1285 ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
1287 ccb->ccb_h.status |= CAM_ATA_STATUS_ERROR;
1292 ccb->ccb_h.status |= CAM_UNCOR_PARITY;
1294 case SIIS_ERR_TIMEOUT:
1296 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1299 ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
1302 ch->oslots &= ~(1 << slot->slot);
1303 ch->rslots &= ~(1 << slot->slot);
1304 ch->aslots &= ~(1 << slot->slot);
1305 slot->state = SIIS_SLOT_EMPTY;
1307 /* Update channel stats. */
1309 if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
1310 (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA)) {
1311 ch->numtslots[ccb->ccb_h.target_id]--;
1313 /* Cancel timeout state if request completed normally. */
1314 if (et != SIIS_ERR_TIMEOUT) {
1315 lastto = (ch->toslots == (1 << slot->slot));
1316 ch->toslots &= ~(1 << slot->slot);
1318 xpt_release_simq(ch->sim, TRUE);
1320 /* If it was our READ LOG command - process it. */
1321 if (ccb->ccb_h.recovery_type == RECOVERY_READ_LOG) {
1322 siis_process_read_log(dev, ccb);
1323 /* If it was our REQUEST SENSE command - process it. */
1324 } else if (ccb->ccb_h.recovery_type == RECOVERY_REQUEST_SENSE) {
1325 siis_process_request_sense(dev, ccb);
1326 /* If it was NCQ or ATAPI command error, put result on hold. */
1327 } else if (et == SIIS_ERR_NCQ ||
1328 ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR &&
1329 (ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0)) {
1330 ch->hold[slot->slot] = ccb;
1334 /* If we have no other active commands, ... */
1335 if (ch->rslots == 0) {
1336 /* if there were timeouts or fatal error - reset port. */
1337 if (ch->toslots != 0 || ch->fatalerr) {
1340 /* if we have slots in error, we can reinit port. */
1341 if (ch->eslots != 0)
1343 /* if there commands on hold, we can do recovery. */
1344 if (!ch->recoverycmd && ch->numhslots)
1345 siis_issue_recovery(dev);
1347 /* If all the reset of commands are in timeout - abort them. */
1348 } else if ((ch->rslots & ~ch->toslots) == 0 &&
1349 et != SIIS_ERR_TIMEOUT)
1350 siis_rearm_timeout(dev);
1351 /* Unfreeze frozen command. */
1352 if (ch->frozen && !siis_check_collision(dev, ch->frozen)) {
1353 union ccb *fccb = ch->frozen;
1355 siis_begin_transaction(dev, fccb);
1356 xpt_release_simq(ch->sim, TRUE);
1361 siis_issue_recovery(device_t dev)
1363 struct siis_channel *ch = device_get_softc(dev);
1365 struct ccb_ataio *ataio;
1366 struct ccb_scsiio *csio;
1369 /* Find some held command. */
1370 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1374 if (i == SIIS_MAX_SLOTS)
1376 ccb = xpt_alloc_ccb_nowait();
1378 device_printf(dev, "Unable to allocate recovery command\n");
1380 /* We can't do anything -- complete held commands. */
1381 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1382 if (ch->hold[i] == NULL)
1384 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1385 ch->hold[i]->ccb_h.status |= CAM_RESRC_UNAVAIL;
1386 xpt_done(ch->hold[i]);
1393 ccb->ccb_h = ch->hold[i]->ccb_h; /* Reuse old header. */
1394 if (ccb->ccb_h.func_code == XPT_ATA_IO) {
1396 ccb->ccb_h.recovery_type = RECOVERY_READ_LOG;
1397 ccb->ccb_h.func_code = XPT_ATA_IO;
1398 ccb->ccb_h.flags = CAM_DIR_IN;
1399 ccb->ccb_h.timeout = 1000; /* 1s should be enough. */
1400 ataio = &ccb->ataio;
1401 ataio->data_ptr = malloc(512, M_SIIS, M_NOWAIT);
1402 if (ataio->data_ptr == NULL) {
1405 "Unable to allocate memory for READ LOG command\n");
1408 ataio->dxfer_len = 512;
1409 bzero(&ataio->cmd, sizeof(ataio->cmd));
1410 ataio->cmd.flags = CAM_ATAIO_48BIT;
1411 ataio->cmd.command = 0x2F; /* READ LOG EXT */
1412 ataio->cmd.sector_count = 1;
1413 ataio->cmd.sector_count_exp = 0;
1414 ataio->cmd.lba_low = 0x10;
1415 ataio->cmd.lba_mid = 0;
1416 ataio->cmd.lba_mid_exp = 0;
1419 ccb->ccb_h.recovery_type = RECOVERY_REQUEST_SENSE;
1420 ccb->ccb_h.recovery_slot = i;
1421 ccb->ccb_h.func_code = XPT_SCSI_IO;
1422 ccb->ccb_h.flags = CAM_DIR_IN;
1423 ccb->ccb_h.status = 0;
1424 ccb->ccb_h.timeout = 1000; /* 1s should be enough. */
1426 csio->data_ptr = (void *)&ch->hold[i]->csio.sense_data;
1427 csio->dxfer_len = ch->hold[i]->csio.sense_len;
1429 bzero(&csio->cdb_io, sizeof(csio->cdb_io));
1430 csio->cdb_io.cdb_bytes[0] = 0x03;
1431 csio->cdb_io.cdb_bytes[4] = csio->dxfer_len;
1433 ch->recoverycmd = 1;
1434 siis_begin_transaction(dev, ccb);
1438 siis_process_read_log(device_t dev, union ccb *ccb)
1440 struct siis_channel *ch = device_get_softc(dev);
1442 struct ata_res *res;
1445 ch->recoverycmd = 0;
1446 data = ccb->ataio.data_ptr;
1447 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP &&
1448 (data[0] & 0x80) == 0) {
1449 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1452 if (ch->hold[i]->ccb_h.target_id != ccb->ccb_h.target_id)
1454 if ((data[0] & 0x1F) == i) {
1455 res = &ch->hold[i]->ataio.res;
1456 res->status = data[2];
1457 res->error = data[3];
1458 res->lba_low = data[4];
1459 res->lba_mid = data[5];
1460 res->lba_high = data[6];
1461 res->device = data[7];
1462 res->lba_low_exp = data[8];
1463 res->lba_mid_exp = data[9];
1464 res->lba_high_exp = data[10];
1465 res->sector_count = data[12];
1466 res->sector_count_exp = data[13];
1468 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1469 ch->hold[i]->ccb_h.status |= CAM_REQUEUE_REQ;
1471 xpt_done(ch->hold[i]);
1476 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
1477 device_printf(dev, "Error while READ LOG EXT\n");
1478 else if ((data[0] & 0x80) == 0) {
1479 device_printf(dev, "Non-queued command error in READ LOG EXT\n");
1481 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1484 if (ch->hold[i]->ccb_h.target_id != ccb->ccb_h.target_id)
1486 xpt_done(ch->hold[i]);
1491 free(ccb->ataio.data_ptr, M_SIIS);
1496 siis_process_request_sense(device_t dev, union ccb *ccb)
1498 struct siis_channel *ch = device_get_softc(dev);
1501 ch->recoverycmd = 0;
1503 i = ccb->ccb_h.recovery_slot;
1504 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
1505 ch->hold[i]->ccb_h.status |= CAM_AUTOSNS_VALID;
1507 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1508 ch->hold[i]->ccb_h.status |= CAM_AUTOSENSE_FAIL;
1510 xpt_done(ch->hold[i]);
1517 siis_portinit(device_t dev)
1519 struct siis_channel *ch = device_get_softc(dev);
1524 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_RESUME);
1525 for (i = 0; i < 16; i++) {
1526 ATA_OUTL(ch->r_mem, SIIS_P_PMPSTS(i), 0),
1527 ATA_OUTL(ch->r_mem, SIIS_P_PMPQACT(i), 0);
1529 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_INIT);
1530 siis_wait_ready(dev, 1000);
1534 siis_devreset(device_t dev)
1536 struct siis_channel *ch = device_get_softc(dev);
1540 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_DEV_RESET);
1541 while (((val = ATA_INL(ch->r_mem, SIIS_P_STS)) &
1542 SIIS_P_CTL_DEV_RESET) != 0) {
1544 if (timeout++ > 1000) {
1545 device_printf(dev, "device reset stuck "
1546 "(timeout 100ms) status = %08x\n", val);
1554 siis_wait_ready(device_t dev, int t)
1556 struct siis_channel *ch = device_get_softc(dev);
1560 while (((val = ATA_INL(ch->r_mem, SIIS_P_STS)) &
1561 SIIS_P_CTL_READY) == 0) {
1563 if (timeout++ > t) {
1564 device_printf(dev, "port is not ready (timeout %dms) "
1565 "status = %08x\n", t, val);
1573 siis_reset(device_t dev)
1575 struct siis_channel *ch = device_get_softc(dev);
1576 int i, retry = 0, sata_rev;
1579 xpt_freeze_simq(ch->sim, 1);
1581 device_printf(dev, "SIIS reset...\n");
1582 if (!ch->recoverycmd && !ch->recovery)
1583 xpt_freeze_simq(ch->sim, ch->numrslots);
1584 /* Requeue frozen command. */
1586 union ccb *fccb = ch->frozen;
1588 fccb->ccb_h.status &= ~CAM_STATUS_MASK;
1589 fccb->ccb_h.status |= CAM_REQUEUE_REQ | CAM_RELEASE_SIMQ;
1590 if (!(fccb->ccb_h.status & CAM_DEV_QFRZN)) {
1591 xpt_freeze_devq(fccb->ccb_h.path, 1);
1592 fccb->ccb_h.status |= CAM_DEV_QFRZN;
1596 /* Requeue all running commands. */
1597 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1598 /* Do we have a running request on slot? */
1599 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1601 /* XXX; Commands in loading state. */
1602 siis_end_transaction(&ch->slot[i], SIIS_ERR_INNOCENT);
1604 /* Finish all held commands as-is. */
1605 for (i = 0; i < SIIS_MAX_SLOTS; i++) {
1608 xpt_done(ch->hold[i]);
1612 if (ch->toslots != 0)
1613 xpt_release_simq(ch->sim, TRUE);
1618 /* Disable port interrupts */
1619 ATA_OUTL(ch->r_mem, SIIS_P_IECLR, 0x0000FFFF);
1620 /* Set speed limit. */
1621 sata_rev = ch->user[ch->pm_present ? 15 : 0].revision;
1623 val = ATA_SC_SPD_SPEED_GEN1;
1624 else if (sata_rev == 2)
1625 val = ATA_SC_SPD_SPEED_GEN2;
1626 else if (sata_rev == 3)
1627 val = ATA_SC_SPD_SPEED_GEN3;
1630 ATA_OUTL(ch->r_mem, SIIS_P_SCTL,
1631 ATA_SC_DET_IDLE | val | ((ch->pm_level > 0) ? 0 :
1632 (ATA_SC_IPM_DIS_PARTIAL | ATA_SC_IPM_DIS_SLUMBER)));
1635 /* Reset and reconnect PHY, */
1636 if (!siis_sata_connect(ch)) {
1638 /* Enable port interrupts */
1639 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
1642 "SIIS reset done: phy reset found no device\n");
1643 /* Tell the XPT about the event */
1644 xpt_async(AC_BUS_RESET, ch->path, NULL);
1645 xpt_release_simq(ch->sim, TRUE);
1648 /* Wait for port ready status. */
1649 if (siis_wait_ready(dev, 1000)) {
1650 device_printf(dev, "port ready timeout\n");
1652 device_printf(dev, "trying full port reset ...\n");
1653 /* Get port to the reset state. */
1654 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
1656 /* Get port out of reset state. */
1657 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
1658 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
1660 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1662 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1663 siis_wait_ready(dev, 5000);
1669 /* Enable port interrupts */
1670 ATA_OUTL(ch->r_mem, SIIS_P_IS, 0xFFFFFFFF);
1671 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
1673 device_printf(dev, "SIIS reset done: devices=%08x\n", ch->devices);
1674 /* Tell the XPT about the event */
1675 xpt_async(AC_BUS_RESET, ch->path, NULL);
1676 xpt_release_simq(ch->sim, TRUE);
1680 siis_setup_fis(device_t dev, struct siis_cmd *ctp, union ccb *ccb, int tag)
1682 struct siis_channel *ch = device_get_softc(dev);
1683 u_int8_t *fis = &ctp->fis[0];
1686 fis[0] = 0x27; /* host to device */
1687 fis[1] = (ccb->ccb_h.target_id & 0x0f);
1688 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
1690 fis[2] = ATA_PACKET_CMD;
1691 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE &&
1692 ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA)
1695 fis[5] = ccb->csio.dxfer_len;
1696 fis[6] = ccb->csio.dxfer_len >> 8;
1699 fis[15] = ATA_A_4BIT;
1700 bzero(ctp->u.atapi.ccb, 16);
1701 bcopy((ccb->ccb_h.flags & CAM_CDB_POINTER) ?
1702 ccb->csio.cdb_io.cdb_ptr : ccb->csio.cdb_io.cdb_bytes,
1703 ctp->u.atapi.ccb, ccb->csio.cdb_len);
1704 } else if ((ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL) == 0) {
1706 fis[2] = ccb->ataio.cmd.command;
1707 fis[3] = ccb->ataio.cmd.features;
1708 fis[4] = ccb->ataio.cmd.lba_low;
1709 fis[5] = ccb->ataio.cmd.lba_mid;
1710 fis[6] = ccb->ataio.cmd.lba_high;
1711 fis[7] = ccb->ataio.cmd.device;
1712 fis[8] = ccb->ataio.cmd.lba_low_exp;
1713 fis[9] = ccb->ataio.cmd.lba_mid_exp;
1714 fis[10] = ccb->ataio.cmd.lba_high_exp;
1715 fis[11] = ccb->ataio.cmd.features_exp;
1716 if (ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA) {
1720 fis[12] = ccb->ataio.cmd.sector_count;
1721 fis[13] = ccb->ataio.cmd.sector_count_exp;
1723 fis[15] = ATA_A_4BIT;
1731 siis_sata_connect(struct siis_channel *ch)
1734 int timeout, found = 0;
1736 /* Wait up to 100ms for "connect well" */
1737 for (timeout = 0; timeout < 1000 ; timeout++) {
1738 status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
1739 if ((status & ATA_SS_DET_MASK) != ATA_SS_DET_NO_DEVICE)
1741 if (((status & ATA_SS_DET_MASK) == ATA_SS_DET_PHY_ONLINE) &&
1742 ((status & ATA_SS_SPD_MASK) != ATA_SS_SPD_NO_SPEED) &&
1743 ((status & ATA_SS_IPM_MASK) == ATA_SS_IPM_ACTIVE))
1745 if ((status & ATA_SS_DET_MASK) == ATA_SS_DET_PHY_OFFLINE) {
1747 device_printf(ch->dev, "SATA offline status=%08x\n",
1752 if (found == 0 && timeout >= 100)
1756 if (timeout >= 1000 || !found) {
1758 device_printf(ch->dev,
1759 "SATA connect timeout time=%dus status=%08x\n",
1760 timeout * 100, status);
1765 device_printf(ch->dev, "SATA connect time=%dus status=%08x\n",
1766 timeout * 100, status);
1768 /* Clear SATA error register */
1769 ATA_OUTL(ch->r_mem, SIIS_P_SERR, 0xffffffff);
1774 siis_check_ids(device_t dev, union ccb *ccb)
1777 if (ccb->ccb_h.target_id > 15) {
1778 ccb->ccb_h.status = CAM_TID_INVALID;
1782 if (ccb->ccb_h.target_lun != 0) {
1783 ccb->ccb_h.status = CAM_LUN_INVALID;
1791 siisaction(struct cam_sim *sim, union ccb *ccb)
1793 device_t dev, parent;
1794 struct siis_channel *ch;
1796 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("siisaction func_code=%x\n",
1797 ccb->ccb_h.func_code));
1799 ch = (struct siis_channel *)cam_sim_softc(sim);
1801 mtx_assert(&ch->mtx, MA_OWNED);
1802 switch (ccb->ccb_h.func_code) {
1803 /* Common cases first */
1804 case XPT_ATA_IO: /* Execute the requested I/O operation */
1806 if (siis_check_ids(dev, ccb))
1808 if (ch->devices == 0 ||
1809 (ch->pm_present == 0 &&
1810 ccb->ccb_h.target_id > 0 && ccb->ccb_h.target_id < 15)) {
1811 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
1814 ccb->ccb_h.recovery_type = RECOVERY_NONE;
1815 /* Check for command collision. */
1816 if (siis_check_collision(dev, ccb)) {
1817 /* Freeze command. */
1819 /* We have only one frozen slot, so freeze simq also. */
1820 xpt_freeze_simq(ch->sim, 1);
1823 siis_begin_transaction(dev, ccb);
1825 case XPT_EN_LUN: /* Enable LUN as a target */
1826 case XPT_TARGET_IO: /* Execute target I/O request */
1827 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
1828 case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/
1829 case XPT_ABORT: /* Abort the specified CCB */
1831 ccb->ccb_h.status = CAM_REQ_INVALID;
1833 case XPT_SET_TRAN_SETTINGS:
1835 struct ccb_trans_settings *cts = &ccb->cts;
1836 struct siis_device *d;
1838 if (siis_check_ids(dev, ccb))
1840 if (cts->type == CTS_TYPE_CURRENT_SETTINGS)
1841 d = &ch->curr[ccb->ccb_h.target_id];
1843 d = &ch->user[ccb->ccb_h.target_id];
1844 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_REVISION)
1845 d->revision = cts->xport_specific.sata.revision;
1846 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_MODE)
1847 d->mode = cts->xport_specific.sata.mode;
1848 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
1849 d->bytecount = min(8192, cts->xport_specific.sata.bytecount);
1850 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_TAGS)
1851 d->tags = min(SIIS_MAX_SLOTS, cts->xport_specific.sata.tags);
1852 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_PM) {
1853 ch->pm_present = cts->xport_specific.sata.pm_present;
1855 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1857 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1859 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_TAGS)
1860 d->atapi = cts->xport_specific.sata.atapi;
1861 if (cts->xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1862 d->caps = cts->xport_specific.sata.caps;
1863 ccb->ccb_h.status = CAM_REQ_CMP;
1866 case XPT_GET_TRAN_SETTINGS:
1867 /* Get default/user set transfer settings for the target */
1869 struct ccb_trans_settings *cts = &ccb->cts;
1870 struct siis_device *d;
1873 if (siis_check_ids(dev, ccb))
1875 if (cts->type == CTS_TYPE_CURRENT_SETTINGS)
1876 d = &ch->curr[ccb->ccb_h.target_id];
1878 d = &ch->user[ccb->ccb_h.target_id];
1879 cts->protocol = PROTO_UNSPECIFIED;
1880 cts->protocol_version = PROTO_VERSION_UNSPECIFIED;
1881 cts->transport = XPORT_SATA;
1882 cts->transport_version = XPORT_VERSION_UNSPECIFIED;
1883 cts->proto_specific.valid = 0;
1884 cts->xport_specific.sata.valid = 0;
1885 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1886 (ccb->ccb_h.target_id == 15 ||
1887 (ccb->ccb_h.target_id == 0 && !ch->pm_present))) {
1888 status = ATA_INL(ch->r_mem, SIIS_P_SSTS) & ATA_SS_SPD_MASK;
1889 if (status & 0x0f0) {
1890 cts->xport_specific.sata.revision =
1891 (status & 0x0f0) >> 4;
1892 cts->xport_specific.sata.valid |=
1893 CTS_SATA_VALID_REVISION;
1895 cts->xport_specific.sata.caps = d->caps & CTS_SATA_CAPS_D;
1897 cts->xport_specific.sata.caps |= CTS_SATA_CAPS_H_PMREQ;
1898 cts->xport_specific.sata.caps |= CTS_SATA_CAPS_H_AN;
1899 cts->xport_specific.sata.caps &=
1900 ch->user[ccb->ccb_h.target_id].caps;
1901 cts->xport_specific.sata.valid |= CTS_SATA_VALID_CAPS;
1903 cts->xport_specific.sata.revision = d->revision;
1904 cts->xport_specific.sata.valid |= CTS_SATA_VALID_REVISION;
1905 cts->xport_specific.sata.caps = d->caps;
1906 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1907 (ch->quirks & SIIS_Q_SNTF) == 0)
1908 cts->xport_specific.sata.caps &= ~CTS_SATA_CAPS_H_AN;
1909 cts->xport_specific.sata.valid |= CTS_SATA_VALID_CAPS;
1911 cts->xport_specific.sata.mode = d->mode;
1912 cts->xport_specific.sata.valid |= CTS_SATA_VALID_MODE;
1913 cts->xport_specific.sata.bytecount = d->bytecount;
1914 cts->xport_specific.sata.valid |= CTS_SATA_VALID_BYTECOUNT;
1915 cts->xport_specific.sata.pm_present = ch->pm_present;
1916 cts->xport_specific.sata.valid |= CTS_SATA_VALID_PM;
1917 cts->xport_specific.sata.tags = d->tags;
1918 cts->xport_specific.sata.valid |= CTS_SATA_VALID_TAGS;
1919 cts->xport_specific.sata.atapi = d->atapi;
1920 cts->xport_specific.sata.valid |= CTS_SATA_VALID_ATAPI;
1921 ccb->ccb_h.status = CAM_REQ_CMP;
1924 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
1925 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
1927 ccb->ccb_h.status = CAM_REQ_CMP;
1929 case XPT_TERM_IO: /* Terminate the I/O process */
1931 ccb->ccb_h.status = CAM_REQ_INVALID;
1933 case XPT_PATH_INQ: /* Path routing inquiry */
1935 struct ccb_pathinq *cpi = &ccb->cpi;
1937 parent = device_get_parent(dev);
1938 cpi->version_num = 1; /* XXX??? */
1939 cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE;
1940 cpi->hba_inquiry |= PI_SATAPM;
1941 cpi->target_sprt = 0;
1942 cpi->hba_misc = PIM_SEQSCAN | PIM_UNMAPPED;
1943 cpi->hba_eng_cnt = 0;
1944 cpi->max_target = 15;
1946 cpi->initiator_id = 0;
1947 cpi->bus_id = cam_sim_bus(sim);
1948 cpi->base_transfer_speed = 150000;
1949 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1950 strncpy(cpi->hba_vid, "SIIS", HBA_IDLEN);
1951 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1952 cpi->unit_number = cam_sim_unit(sim);
1953 cpi->transport = XPORT_SATA;
1954 cpi->transport_version = XPORT_VERSION_UNSPECIFIED;
1955 cpi->protocol = PROTO_ATA;
1956 cpi->protocol_version = PROTO_VERSION_UNSPECIFIED;
1957 cpi->maxio = MAXPHYS;
1958 cpi->hba_vendor = pci_get_vendor(parent);
1959 cpi->hba_device = pci_get_device(parent);
1960 cpi->hba_subvendor = pci_get_subvendor(parent);
1961 cpi->hba_subdevice = pci_get_subdevice(parent);
1962 cpi->ccb_h.status = CAM_REQ_CMP;
1966 ccb->ccb_h.status = CAM_REQ_INVALID;
1973 siispoll(struct cam_sim *sim)
1975 struct siis_channel *ch = (struct siis_channel *)cam_sim_softc(sim);
1977 siis_ch_intr(ch->dev);