Lines Matching full:ch
85 static int siis_sata_connect(struct siis_channel *ch);
461 struct siis_channel *ch = device_get_softc(dev);
465 ch->dev = dev;
466 ch->unit = (intptr_t)device_get_ivars(dev);
467 ch->quirks = ctlr->quirks;
468 ch->pm_level = 0;
470 device_get_unit(dev), "pm_level", &ch->pm_level);
474 ch->user[i].revision = sata_rev;
475 ch->user[i].mode = 0;
476 ch->user[i].bytecount = 8192;
477 ch->user[i].tags = SIIS_MAX_SLOTS;
478 ch->curr[i] = ch->user[i];
479 if (ch->pm_level)
480 ch->user[i].caps = CTS_SATA_CAPS_H_PMREQ;
481 ch->user[i].caps |= CTS_SATA_CAPS_H_AN;
483 mtx_init(&ch->mtx, "SIIS channel lock", NULL, MTX_DEF);
484 rid = ch->unit;
485 if (!(ch->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
491 mtx_lock(&ch->mtx);
493 if (!(ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
499 if ((bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL,
500 siis_ch_intr_locked, dev, &ch->ih))) {
513 ch->sim = cam_sim_alloc(siisaction, siispoll, "siisch", ch,
514 device_get_unit(dev), &ch->mtx, 2, SIIS_MAX_SLOTS, devq);
515 if (ch->sim == NULL) {
521 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) {
526 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim),
532 mtx_unlock(&ch->mtx);
533 ch->led = led_create(siis_ch_led, dev, device_get_nameunit(dev));
537 xpt_bus_deregister(cam_sim_path(ch->sim));
539 cam_sim_free(ch->sim, /*free_devq*/TRUE);
541 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
543 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
544 mtx_unlock(&ch->mtx);
545 mtx_destroy(&ch->mtx);
552 struct siis_channel *ch = device_get_softc(dev);
554 led_destroy(ch->led);
555 mtx_lock(&ch->mtx);
556 xpt_async(AC_LOST_DEVICE, ch->path, NULL);
557 xpt_free_path(ch->path);
558 xpt_bus_deregister(cam_sim_path(ch->sim));
559 cam_sim_free(ch->sim, /*free_devq*/TRUE);
560 mtx_unlock(&ch->mtx);
562 bus_teardown_intr(dev, ch->r_irq, ch->ih);
563 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
569 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
570 mtx_destroy(&ch->mtx);
577 struct siis_channel *ch = device_get_softc(dev);
580 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
581 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
582 if (ch->pm_present)
583 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
585 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
587 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
594 struct siis_channel *ch = device_get_softc(dev);
597 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
604 struct siis_channel *ch = device_get_softc(dev);
606 mtx_lock(&ch->mtx);
607 xpt_freeze_simq(ch->sim, 1);
608 while (ch->oslots)
609 msleep(ch, &ch->mtx, PRIBIO, "siissusp", hz/100);
611 mtx_unlock(&ch->mtx);
618 struct siis_channel *ch = device_get_softc(dev);
620 mtx_lock(&ch->mtx);
623 xpt_release_simq(ch->sim, TRUE);
624 mtx_unlock(&ch->mtx);
649 struct siis_channel *ch;
652 ch = device_get_softc(dev);
655 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_LED_ON);
657 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_LED_ON);
668 struct siis_channel *ch = device_get_softc(dev);
675 0, NULL, NULL, &ch->dma.work_tag))
677 if (bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, 0,
678 &ch->dma.work_map))
680 if (bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work,
682 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
685 ch->dma.work_bus = dcba.maddr;
691 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag)) {
713 struct siis_channel *ch = device_get_softc(dev);
715 if (ch->dma.data_tag) {
716 bus_dma_tag_destroy(ch->dma.data_tag);
717 ch->dma.data_tag = NULL;
719 if (ch->dma.work_bus) {
720 bus_dmamap_unload(ch->dma.work_tag, ch->dma.work_map);
721 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
722 ch->dma.work_bus = 0;
723 ch->dma.work_map = NULL;
724 ch->dma.work = NULL;
726 if (ch->dma.work_tag) {
727 bus_dma_tag_destroy(ch->dma.work_tag);
728 ch->dma.work_tag = NULL;
735 struct siis_channel *ch = device_get_softc(dev);
739 bzero(ch->slot, sizeof(ch->slot));
741 struct siis_slot *slot = &ch->slot[i];
748 callout_init_mtx(&slot->timeout, &ch->mtx, 0);
750 if (bus_dmamap_create(ch->dma.data_tag, 0, &slot->dma.data_map))
751 device_printf(ch->dev, "FAILURE - create data_map\n");
758 struct siis_channel *ch = device_get_softc(dev);
763 struct siis_slot *slot = &ch->slot[i];
767 bus_dmamap_destroy(ch->dma.data_tag, slot->dma.data_map);
776 struct siis_channel *ch = device_get_softc(dev);
781 if (ch->quirks & SIIS_Q_SNTF) {
782 status = ATA_INL(ch->r_mem, SIIS_P_SNTF);
783 ATA_OUTL(ch->r_mem, SIIS_P_SNTF, status);
789 status = (ch->pm_present) ? 0x8000 : 0x0001;
797 xpt_path_path_id(ch->path), i, 0) == CAM_REQ_CMP) {
808 struct siis_channel *ch = device_get_softc(dev);
811 if (ch->pm_level == 0) {
812 u_int32_t status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
827 cam_sim_path(ch->sim),
840 struct siis_channel *ch = device_get_softc(dev);
842 mtx_lock(&ch->mtx);
844 mtx_unlock(&ch->mtx);
851 struct siis_channel *ch = device_get_softc(dev);
856 mtx_assert(&ch->mtx, MA_OWNED);
858 sstatus = ATA_INL(ch->r_mem, SIIS_P_SS);
859 ok = ch->rslots & ~sstatus;
863 siis_end_transaction(&ch->slot[i], SIIS_ERR_NONE);
869 istatus = ATA_INL(ch->r_mem, SIIS_P_IS) &
871 ATA_OUTL(ch->r_mem, SIIS_P_IS, istatus);
880 estatus = ATA_INL(ch->r_mem, SIIS_P_CMDERR);
881 ctx = ATA_INL(ch->r_mem, SIIS_P_CTX);
885 // __func__, sstatus, istatus, ch->rslots, estatus, ccs, port,
886 // ATA_INL(ch->r_mem, SIIS_P_SERR));
888 if (!ch->recoverycmd && !ch->recovery) {
889 xpt_freeze_simq(ch->sim, ch->numrslots);
890 ch->recovery = 1;
892 if (ch->frozen) {
893 union ccb *fccb = ch->frozen;
894 ch->frozen = NULL;
906 tslots = ch->numtslots[port];
909 if (((ch->rslots >> i) & 1) == 0)
911 if (ch->slot[i].ccb->ccb_h.target_id != port)
923 siis_end_transaction(&ch->slot[i], et);
929 if (ch->rslots != 0 && !ch->recoverycmd)
930 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_RESUME);
941 if (((ch->rslots >> i) & 1) == 0)
943 siis_end_transaction(&ch->slot[i], et);
953 struct siis_channel *ch = device_get_softc(dev);
955 mtx_assert(&ch->mtx, MA_OWNED);
959 if (((~ch->oslots) & (0x7fffffff >> (31 -
960 ch->curr[ccb->ccb_h.target_id].tags))) == 0)
966 if (ch->numrslots != 0)
970 if (ch->aslots != 0)
979 struct siis_channel *ch = device_get_softc(dev);
983 mtx_assert(&ch->mtx, MA_OWNED);
988 tags = ch->curr[ccb->ccb_h.target_id].tags;
989 tag = fls((~ch->oslots) & (0x7fffffff >> (31 - tags))) - 1;
991 slot = &ch->slot[tag];
994 ch->oslots |= (1 << slot->slot);
995 ch->numrslots++;
998 ch->numtslots[ccb->ccb_h.target_id]++;
1002 ch->aslots |= (1 << slot->slot);
1007 bus_dmamap_load_ccb(ch->dma.data_tag, slot->dma.data_map,
1018 struct siis_channel *ch = device_get_softc(slot->dev);
1023 mtx_assert(&ch->mtx, MA_OWNED);
1026 if (!ch->recoverycmd)
1027 xpt_freeze_simq(ch->sim, 1);
1035 ctp = (struct siis_cmd *)(ch->dma.work + slot->prb_offset);
1047 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1059 struct siis_channel *ch = device_get_softc(dev);
1064 mtx_assert(&ch->mtx, MA_OWNED);
1066 ctp = (struct siis_cmd *)(ch->dma.work + slot->prb_offset);
1105 device_printf(ch->dev, "Setting up SATA FIS failed\n");
1106 if (!ch->recoverycmd)
1107 xpt_freeze_simq(ch->sim, 1);
1111 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1115 ch->rslots |= (1 << slot->slot);
1116 prb_bus = ch->dma.work_bus + slot->prb_offset;
1117 ATA_OUTL(ch->r_mem, SIIS_P_CACTL(slot->slot), prb_bus);
1118 ATA_OUTL(ch->r_mem, SIIS_P_CACTH(slot->slot), prb_bus >> 32);
1129 struct siis_channel *ch = device_get_softc(dev);
1132 mtx_assert(&ch->mtx, MA_OWNED);
1133 if (!ch->recoverycmd && !ch->recovery) {
1134 xpt_freeze_simq(ch->sim, ch->numrslots);
1135 ch->recovery = 1;
1140 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1142 siis_end_transaction(&ch->slot[i], SIIS_ERR_TIMEOUT);
1150 struct siis_channel *ch = device_get_softc(dev);
1153 mtx_assert(&ch->mtx, MA_OWNED);
1155 struct siis_slot *slot = &ch->slot[i];
1160 if ((ch->toslots & (1 << i)) == 0)
1174 struct siis_channel *ch = device_get_softc(dev);
1177 mtx_assert(&ch->mtx, MA_OWNED);
1186 xpt_freeze_simq(ch->sim, ch->numrslots);
1193 __func__, ATA_INL(ch->r_mem, SIIS_P_IS),
1194 ATA_INL(ch->r_mem, SIIS_P_SS), ch->rslots,
1195 ATA_INL(ch->r_mem, SIIS_P_CMDERR), ATA_INL(ch->r_mem, SIIS_P_STS),
1196 ATA_INL(ch->r_mem, SIIS_P_SERR));
1198 if (ch->toslots == 0)
1199 xpt_freeze_simq(ch->sim, 1);
1200 ch->toslots |= (1 << slot->slot);
1201 if ((ch->rslots & ~ch->toslots) == 0)
1205 ch->rslots & ~ch->toslots);
1213 struct siis_channel *ch = device_get_softc(dev);
1217 mtx_assert(&ch->mtx, MA_OWNED);
1218 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1230 res->status = ATA_INB(ch->r_mem, offs + 2);
1231 res->error = ATA_INB(ch->r_mem, offs + 3);
1232 res->lba_low = ATA_INB(ch->r_mem, offs + 4);
1233 res->lba_mid = ATA_INB(ch->r_mem, offs + 5);
1234 res->lba_high = ATA_INB(ch->r_mem, offs + 6);
1235 res->device = ATA_INB(ch->r_mem, offs + 7);
1236 res->lba_low_exp = ATA_INB(ch->r_mem, offs + 8);
1237 res->lba_mid_exp = ATA_INB(ch->r_mem, offs + 9);
1238 res->lba_high_exp = ATA_INB(ch->r_mem, offs + 10);
1239 res->sector_count = ATA_INB(ch->r_mem, offs + 12);
1240 res->sector_count_exp = ATA_INB(ch->r_mem, offs + 13);
1244 ch->numrslots == 1) {
1246 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1250 ch->numrslots == 1) {
1252 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1256 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1259 bus_dmamap_unload(ch->dma.data_tag, slot->dma.data_map);
1262 if (et != SIIS_ERR_NONE || ch->recovery) {
1263 ch->eslots |= (1 << slot->slot);
1267 if (et != SIIS_ERR_NONE && (!ch->recoverycmd) &&
1280 ch->fatalerr = 1;
1296 ch->fatalerr = 1;
1300 ch->fatalerr = 1;
1307 ch->oslots &= ~(1 << slot->slot);
1308 ch->rslots &= ~(1 << slot->slot);
1309 ch->aslots &= ~(1 << slot->slot);
1313 ch->numrslots--;
1316 ch->numtslots[ccb->ccb_h.target_id]--;
1320 lastto = (ch->toslots == (1 << slot->slot));
1321 ch->toslots &= ~(1 << slot->slot);
1323 xpt_release_simq(ch->sim, TRUE);
1335 ch->hold[slot->slot] = ccb;
1336 ch->numhslots++;
1340 if (ch->rslots == 0) {
1342 if (ch->toslots != 0 || ch->fatalerr) {
1346 if (ch->eslots != 0)
1349 if (!ch->recoverycmd && ch->numhslots)
1353 } else if ((ch->rslots & ~ch->toslots) == 0 &&
1357 if (ch->frozen && !siis_check_collision(dev, ch->frozen)) {
1358 union ccb *fccb = ch->frozen;
1359 ch->frozen = NULL;
1361 xpt_release_simq(ch->sim, TRUE);
1368 struct siis_channel *ch = device_get_softc(dev);
1376 if (ch->hold[i])
1387 if (ch->hold[i] == NULL)
1389 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1390 ch->hold[i]->ccb_h.status |= CAM_RESRC_UNAVAIL;
1391 xpt_done(ch->hold[i]);
1392 ch->hold[i] = NULL;
1393 ch->numhslots--;
1398 xpt_setup_ccb(&ccb->ccb_h, ch->hold[i]->ccb_h.path,
1399 ch->hold[i]->ccb_h.pinfo.priority);
1400 if (ch->hold[i]->ccb_h.func_code == XPT_ATA_IO) {
1432 csio->data_ptr = (void *)&ch->hold[i]->csio.sense_data;
1433 csio->dxfer_len = ch->hold[i]->csio.sense_len;
1439 ch->recoverycmd = 1;
1446 struct siis_channel *ch = device_get_softc(dev);
1451 ch->recoverycmd = 0;
1456 if (!ch->hold[i])
1458 if (ch->hold[i]->ccb_h.target_id != ccb->ccb_h.target_id)
1461 res = &ch->hold[i]->ataio.res;
1474 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1475 ch->hold[i]->ccb_h.status |= CAM_REQUEUE_REQ;
1477 xpt_done(ch->hold[i]);
1478 ch->hold[i] = NULL;
1479 ch->numhslots--;
1488 if (!ch->hold[i])
1490 if (ch->hold[i]->ccb_h.target_id != ccb->ccb_h.target_id)
1492 xpt_done(ch->hold[i]);
1493 ch->hold[i] = NULL;
1494 ch->numhslots--;
1504 struct siis_channel *ch = device_get_softc(dev);
1507 ch->recoverycmd = 0;
1511 ch->hold[i]->ccb_h.status |= CAM_AUTOSNS_VALID;
1513 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1514 ch->hold[i]->ccb_h.status |= CAM_AUTOSENSE_FAIL;
1516 xpt_done(ch->hold[i]);
1517 ch->hold[i] = NULL;
1518 ch->numhslots--;
1525 struct siis_channel *ch = device_get_softc(dev);
1528 ch->eslots = 0;
1529 ch->recovery = 0;
1530 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_RESUME);
1532 ATA_OUTL(ch->r_mem, SIIS_P_PMPSTS(i), 0),
1533 ATA_OUTL(ch->r_mem, SIIS_P_PMPQACT(i), 0);
1535 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_INIT);
1542 struct siis_channel *ch = device_get_softc(dev);
1546 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_DEV_RESET);
1547 while (((val = ATA_INL(ch->r_mem, SIIS_P_STS)) &
1562 struct siis_channel *ch = device_get_softc(dev);
1566 while (((val = ATA_INL(ch->r_mem, SIIS_P_STS)) &
1581 struct siis_channel *ch = device_get_softc(dev);
1585 xpt_freeze_simq(ch->sim, 1);
1588 if (!ch->recoverycmd && !ch->recovery)
1589 xpt_freeze_simq(ch->sim, ch->numrslots);
1591 if (ch->frozen) {
1592 union ccb *fccb = ch->frozen;
1593 ch->frozen = NULL;
1605 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1608 siis_end_transaction(&ch->slot[i], SIIS_ERR_INNOCENT);
1612 if (!ch->hold[i])
1614 xpt_done(ch->hold[i]);
1615 ch->hold[i] = NULL;
1616 ch->numhslots--;
1618 if (ch->toslots != 0)
1619 xpt_release_simq(ch->sim, TRUE);
1620 ch->eslots = 0;
1621 ch->recovery = 0;
1622 ch->toslots = 0;
1623 ch->fatalerr = 0;
1625 ATA_OUTL(ch->r_mem, SIIS_P_IECLR, 0x0000FFFF);
1627 sata_rev = ch->user[ch->pm_present ? 15 : 0].revision;
1636 ATA_OUTL(ch->r_mem, SIIS_P_SCTL,
1637 ATA_SC_DET_IDLE | val | ((ch->pm_level > 0) ? 0 :
1642 if (!siis_sata_connect(ch)) {
1643 ch->devices = 0;
1645 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
1650 xpt_async(AC_BUS_RESET, ch->path, NULL);
1651 xpt_release_simq(ch->sim, TRUE);
1660 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
1663 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
1664 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
1665 if (ch->pm_present)
1666 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1668 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1674 ch->devices = 1;
1676 ATA_OUTL(ch->r_mem, SIIS_P_IS, 0xFFFFFFFF);
1677 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
1679 device_printf(dev, "SIIS reset done: devices=%08x\n", ch->devices);
1681 xpt_async(AC_BUS_RESET, ch->path, NULL);
1682 xpt_release_simq(ch->sim, TRUE);
1688 struct siis_channel *ch = device_get_softc(dev);
1698 ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA)
1744 siis_sata_connect(struct siis_channel *ch)
1751 status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
1760 device_printf(ch->dev, "SATA offline status=%08x\n",
1771 device_printf(ch->dev,
1778 device_printf(ch->dev, "SATA connect time=%dus status=%08x\n",
1782 ATA_OUTL(ch->r_mem, SIIS_P_SERR, 0xffffffff);
1807 struct siis_channel *ch;
1812 ch = (struct siis_channel *)cam_sim_softc(sim);
1813 dev = ch->dev;
1814 mtx_assert(&ch->mtx, MA_OWNED);
1821 if (ch->devices == 0 ||
1822 (ch->pm_present == 0 &&
1831 ch->frozen = ccb;
1833 xpt_freeze_simq(ch->sim, 1);
1850 d = &ch->curr[ccb->ccb_h.target_id];
1852 d = &ch->user[ccb->ccb_h.target_id];
1862 ch->pm_present = cts->xport_specific.sata.pm_present;
1863 if (ch->pm_present)
1864 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1866 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1885 d = &ch->curr[ccb->ccb_h.target_id];
1887 d = &ch->user[ccb->ccb_h.target_id];
1896 (ccb->ccb_h.target_id == 0 && !ch->pm_present))) {
1897 status = ATA_INL(ch->r_mem, SIIS_P_SSTS) & ATA_SS_SPD_MASK;
1905 if (ch->pm_level)
1909 ch->user[ccb->ccb_h.target_id].caps;
1916 (ch->quirks & SIIS_Q_SNTF) == 0)
1924 cts->xport_specific.sata.pm_present = ch->pm_present;
1984 struct siis_channel *ch = (struct siis_channel *)cam_sim_softc(sim);
1986 siis_ch_intr(ch->dev);