Lines Matching refs: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;
469 device_get_unit(dev), "pm_level", &ch->pm_level);
473 ch->user[i].revision = sata_rev;
474 ch->user[i].mode = 0;
475 ch->user[i].bytecount = 8192;
476 ch->user[i].tags = SIIS_MAX_SLOTS;
477 ch->curr[i] = ch->user[i];
478 if (ch->pm_level)
479 ch->user[i].caps = CTS_SATA_CAPS_H_PMREQ;
480 ch->user[i].caps |= CTS_SATA_CAPS_H_AN;
482 mtx_init(&ch->mtx, "SIIS channel lock", NULL, MTX_DEF);
483 rid = ch->unit;
484 if (!(ch->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
490 mtx_lock(&ch->mtx);
492 if (!(ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
498 if ((bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL,
499 siis_ch_intr_locked, dev, &ch->ih))) {
512 ch->sim = cam_sim_alloc(siisaction, siispoll, "siisch", ch,
513 device_get_unit(dev), &ch->mtx, 2, SIIS_MAX_SLOTS, devq);
514 if (ch->sim == NULL) {
520 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) {
525 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim),
531 mtx_unlock(&ch->mtx);
532 ch->led = led_create(siis_ch_led, dev, device_get_nameunit(dev));
536 xpt_bus_deregister(cam_sim_path(ch->sim));
538 cam_sim_free(ch->sim, /*free_devq*/TRUE);
540 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
542 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
543 mtx_unlock(&ch->mtx);
544 mtx_destroy(&ch->mtx);
551 struct siis_channel *ch = device_get_softc(dev);
553 led_destroy(ch->led);
554 mtx_lock(&ch->mtx);
555 xpt_async(AC_LOST_DEVICE, ch->path, NULL);
556 xpt_free_path(ch->path);
557 xpt_bus_deregister(cam_sim_path(ch->sim));
558 cam_sim_free(ch->sim, /*free_devq*/TRUE);
559 mtx_unlock(&ch->mtx);
561 bus_teardown_intr(dev, ch->r_irq, ch->ih);
562 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq);
568 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem);
569 mtx_destroy(&ch->mtx);
576 struct siis_channel *ch = device_get_softc(dev);
579 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PORT_RESET);
580 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_32BIT);
581 if (ch->pm_present)
582 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
584 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
586 ATA_OUTL(ch->r_mem, SIIS_P_IESET, SIIS_P_IX_ENABLED);
593 struct siis_channel *ch = device_get_softc(dev);
596 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PORT_RESET);
603 struct siis_channel *ch = device_get_softc(dev);
605 mtx_lock(&ch->mtx);
606 xpt_freeze_simq(ch->sim, 1);
607 while (ch->oslots)
608 msleep(ch, &ch->mtx, PRIBIO, "siissusp", hz/100);
610 mtx_unlock(&ch->mtx);
617 struct siis_channel *ch = device_get_softc(dev);
619 mtx_lock(&ch->mtx);
622 xpt_release_simq(ch->sim, TRUE);
623 mtx_unlock(&ch->mtx);
647 struct siis_channel *ch;
650 ch = device_get_softc(dev);
653 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_LED_ON);
655 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_LED_ON);
666 struct siis_channel *ch = device_get_softc(dev);
673 0, NULL, NULL, &ch->dma.work_tag))
675 if (bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, 0,
676 &ch->dma.work_map))
678 if (bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work,
680 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
683 ch->dma.work_bus = dcba.maddr;
690 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag)) {
712 struct siis_channel *ch = device_get_softc(dev);
714 if (ch->dma.data_tag) {
715 bus_dma_tag_destroy(ch->dma.data_tag);
716 ch->dma.data_tag = NULL;
718 if (ch->dma.work_bus) {
719 bus_dmamap_unload(ch->dma.work_tag, ch->dma.work_map);
720 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map);
721 ch->dma.work_bus = 0;
722 ch->dma.work_map = NULL;
723 ch->dma.work = NULL;
725 if (ch->dma.work_tag) {
726 bus_dma_tag_destroy(ch->dma.work_tag);
727 ch->dma.work_tag = NULL;
734 struct siis_channel *ch = device_get_softc(dev);
738 bzero(ch->slot, sizeof(ch->slot));
740 struct siis_slot *slot = &ch->slot[i];
746 callout_init_mtx(&slot->timeout, &ch->mtx, 0);
748 if (bus_dmamap_create(ch->dma.data_tag, 0, &slot->dma.data_map))
749 device_printf(ch->dev, "FAILURE - create data_map\n");
756 struct siis_channel *ch = device_get_softc(dev);
761 struct siis_slot *slot = &ch->slot[i];
765 bus_dmamap_destroy(ch->dma.data_tag, slot->dma.data_map);
774 struct siis_channel *ch = device_get_softc(dev);
779 if (ch->quirks & SIIS_Q_SNTF) {
780 status = ATA_INL(ch->r_mem, SIIS_P_SNTF);
781 ATA_OUTL(ch->r_mem, SIIS_P_SNTF, status);
787 status = (ch->pm_present) ? 0x8000 : 0x0001;
795 xpt_path_path_id(ch->path), i, 0) == CAM_REQ_CMP) {
806 struct siis_channel *ch = device_get_softc(dev);
809 if (ch->pm_level == 0) {
810 u_int32_t status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
825 cam_sim_path(ch->sim),
838 struct siis_channel *ch = device_get_softc(dev);
840 mtx_lock(&ch->mtx);
842 mtx_unlock(&ch->mtx);
849 struct siis_channel *ch = device_get_softc(dev);
854 mtx_assert(&ch->mtx, MA_OWNED);
856 sstatus = ATA_INL(ch->r_mem, SIIS_P_SS);
857 ok = ch->rslots & ~sstatus;
861 siis_end_transaction(&ch->slot[i], SIIS_ERR_NONE);
867 istatus = ATA_INL(ch->r_mem, SIIS_P_IS) &
869 ATA_OUTL(ch->r_mem, SIIS_P_IS, istatus);
878 estatus = ATA_INL(ch->r_mem, SIIS_P_CMDERR);
879 ctx = ATA_INL(ch->r_mem, SIIS_P_CTX);
882 err = ch->rslots & sstatus;
884 // __func__, sstatus, istatus, ch->rslots, estatus, ccs, port,
885 // ATA_INL(ch->r_mem, SIIS_P_SERR));
887 if (!ch->recoverycmd && !ch->recovery) {
888 xpt_freeze_simq(ch->sim, ch->numrslots);
889 ch->recovery = 1;
891 if (ch->frozen) {
892 union ccb *fccb = ch->frozen;
893 ch->frozen = NULL;
905 tslots = ch->numtslots[port];
908 if (((ch->rslots >> i) & 1) == 0)
910 if (ch->slot[i].ccb->ccb_h.target_id != port)
922 siis_end_transaction(&ch->slot[i], et);
928 if (ch->rslots != 0 && !ch->recoverycmd)
929 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_RESUME);
940 if (((ch->rslots >> i) & 1) == 0)
942 siis_end_transaction(&ch->slot[i], et);
952 struct siis_channel *ch = device_get_softc(dev);
954 mtx_assert(&ch->mtx, MA_OWNED);
958 if (((~ch->oslots) & (0x7fffffff >> (31 -
959 ch->curr[ccb->ccb_h.target_id].tags))) == 0)
965 if (ch->numrslots != 0)
969 if (ch->aslots != 0)
978 struct siis_channel *ch = device_get_softc(dev);
982 mtx_assert(&ch->mtx, MA_OWNED);
987 tags = ch->curr[ccb->ccb_h.target_id].tags;
988 tag = fls((~ch->oslots) & (0x7fffffff >> (31 - tags))) - 1;
990 slot = &ch->slot[tag];
993 ch->oslots |= (1 << slot->slot);
994 ch->numrslots++;
997 ch->numtslots[ccb->ccb_h.target_id]++;
1001 ch->aslots |= (1 << slot->slot);
1006 bus_dmamap_load_ccb(ch->dma.data_tag, slot->dma.data_map,
1017 struct siis_channel *ch = device_get_softc(slot->dev);
1022 mtx_assert(&ch->mtx, MA_OWNED);
1025 if (!ch->recoverycmd)
1026 xpt_freeze_simq(ch->sim, 1);
1034 ctp = (struct siis_cmd *)(ch->dma.work + SIIS_CT_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);
1067 (ch->dma.work + SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot));
1106 device_printf(ch->dev, "Setting up SATA FIS failed\n");
1107 if (!ch->recoverycmd)
1108 xpt_freeze_simq(ch->sim, 1);
1112 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1116 ch->rslots |= (1 << slot->slot);
1117 prb_bus = ch->dma.work_bus +
1119 ATA_OUTL(ch->r_mem, SIIS_P_CACTL(slot->slot), prb_bus);
1120 ATA_OUTL(ch->r_mem, SIIS_P_CACTH(slot->slot), prb_bus >> 32);
1131 struct siis_channel *ch = device_get_softc(dev);
1134 mtx_assert(&ch->mtx, MA_OWNED);
1135 if (!ch->recoverycmd && !ch->recovery) {
1136 xpt_freeze_simq(ch->sim, ch->numrslots);
1137 ch->recovery = 1;
1142 if (ch->slot[i].state < SIIS_SLOT_RUNNING)
1144 siis_end_transaction(&ch->slot[i], SIIS_ERR_TIMEOUT);
1152 struct siis_channel *ch = device_get_softc(dev);
1155 mtx_assert(&ch->mtx, MA_OWNED);
1157 struct siis_slot *slot = &ch->slot[i];
1162 if ((ch->toslots & (1 << i)) == 0)
1175 struct siis_channel *ch = device_get_softc(dev);
1178 mtx_assert(&ch->mtx, MA_OWNED);
1187 xpt_freeze_simq(ch->sim, ch->numrslots);
1194 __func__, ATA_INL(ch->r_mem, SIIS_P_IS),
1195 ATA_INL(ch->r_mem, SIIS_P_SS), ch->rslots,
1196 ATA_INL(ch->r_mem, SIIS_P_CMDERR), ATA_INL(ch->r_mem, SIIS_P_STS),
1197 ATA_INL(ch->r_mem, SIIS_P_SERR));
1199 if (ch->toslots == 0)
1200 xpt_freeze_simq(ch->sim, 1);
1201 ch->toslots |= (1 << slot->slot);
1202 if ((ch->rslots & ~ch->toslots) == 0)
1206 ch->rslots & ~ch->toslots);
1214 struct siis_channel *ch = device_get_softc(dev);
1218 mtx_assert(&ch->mtx, MA_OWNED);
1219 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
1231 res->status = ATA_INB(ch->r_mem, offs + 2);
1232 res->error = ATA_INB(ch->r_mem, offs + 3);
1233 res->lba_low = ATA_INB(ch->r_mem, offs + 4);
1234 res->lba_mid = ATA_INB(ch->r_mem, offs + 5);
1235 res->lba_high = ATA_INB(ch->r_mem, offs + 6);
1236 res->device = ATA_INB(ch->r_mem, offs + 7);
1237 res->lba_low_exp = ATA_INB(ch->r_mem, offs + 8);
1238 res->lba_mid_exp = ATA_INB(ch->r_mem, offs + 9);
1239 res->lba_high_exp = ATA_INB(ch->r_mem, offs + 10);
1240 res->sector_count = ATA_INB(ch->r_mem, offs + 12);
1241 res->sector_count_exp = ATA_INB(ch->r_mem, offs + 13);
1245 ch->numrslots == 1) {
1247 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1251 ch->numrslots == 1) {
1253 ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
1257 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
1260 bus_dmamap_unload(ch->dma.data_tag, slot->dma.data_map);
1263 if (et != SIIS_ERR_NONE || ch->recovery) {
1264 ch->eslots |= (1 << slot->slot);
1268 if (et != SIIS_ERR_NONE && (!ch->recoverycmd) &&
1281 ch->fatalerr = 1;
1297 ch->fatalerr = 1;
1301 ch->fatalerr = 1;
1308 ch->oslots &= ~(1 << slot->slot);
1309 ch->rslots &= ~(1 << slot->slot);
1310 ch->aslots &= ~(1 << slot->slot);
1314 ch->numrslots--;
1317 ch->numtslots[ccb->ccb_h.target_id]--;
1321 lastto = (ch->toslots == (1 << slot->slot));
1322 ch->toslots &= ~(1 << slot->slot);
1324 xpt_release_simq(ch->sim, TRUE);
1336 ch->hold[slot->slot] = ccb;
1337 ch->numhslots++;
1341 if (ch->rslots == 0) {
1343 if (ch->toslots != 0 || ch->fatalerr) {
1347 if (ch->eslots != 0)
1350 if (!ch->recoverycmd && ch->numhslots)
1354 } else if ((ch->rslots & ~ch->toslots) == 0 &&
1358 if (ch->frozen && !siis_check_collision(dev, ch->frozen)) {
1359 union ccb *fccb = ch->frozen;
1360 ch->frozen = NULL;
1362 xpt_release_simq(ch->sim, TRUE);
1369 struct siis_channel *ch = device_get_softc(dev);
1377 if (ch->hold[i])
1388 if (ch->hold[i] == NULL)
1390 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK;
1391 ch->hold[i]->ccb_h.status |= CAM_RESRC_UNAVAIL;
1392 xpt_done(ch->hold[i]);
1393 ch->hold[i] = NULL;
1394 ch->numhslots--;
1399 ccb->ccb_h = ch->hold[i]->ccb_h; /* Reuse old header. */
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)
1737 siis_sata_connect(struct siis_channel *ch)
1744 status = ATA_INL(ch->r_mem, SIIS_P_SSTS);
1753 device_printf(ch->dev, "SATA offline status=%08x\n",
1764 device_printf(ch->dev,
1771 device_printf(ch->dev, "SATA connect time=%dus status=%08x\n",
1775 ATA_OUTL(ch->r_mem, SIIS_P_SERR, 0xffffffff);
1800 struct siis_channel *ch;
1805 ch = (struct siis_channel *)cam_sim_softc(sim);
1806 dev = ch->dev;
1807 mtx_assert(&ch->mtx, MA_OWNED);
1814 if (ch->devices == 0 ||
1815 (ch->pm_present == 0 &&
1824 ch->frozen = ccb;
1826 xpt_freeze_simq(ch->sim, 1);
1847 d = &ch->curr[ccb->ccb_h.target_id];
1849 d = &ch->user[ccb->ccb_h.target_id];
1859 ch->pm_present = cts->xport_specific.sata.pm_present;
1860 if (ch->pm_present)
1861 ATA_OUTL(ch->r_mem, SIIS_P_CTLSET, SIIS_P_CTL_PME);
1863 ATA_OUTL(ch->r_mem, SIIS_P_CTLCLR, SIIS_P_CTL_PME);
1882 d = &ch->curr[ccb->ccb_h.target_id];
1884 d = &ch->user[ccb->ccb_h.target_id];
1893 (ccb->ccb_h.target_id == 0 && !ch->pm_present))) {
1894 status = ATA_INL(ch->r_mem, SIIS_P_SSTS) & ATA_SS_SPD_MASK;
1902 if (ch->pm_level)
1906 ch->user[ccb->ccb_h.target_id].caps;
1913 (ch->quirks & SIIS_Q_SNTF) == 0)
1921 cts->xport_specific.sata.pm_present = ch->pm_present;
1981 struct siis_channel *ch = (struct siis_channel *)cam_sim_softc(sim);
1983 siis_ch_intr(ch->dev);