Lines Matching full:ch
64 static void ahci_ch_intr_main(struct ahci_channel *ch, uint32_t istatus);
65 static void ahci_begin_transaction(struct ahci_channel *ch, union ccb *ccb);
70 static int ahci_setup_fis(struct ahci_channel *ch, struct ahci_cmd_tab *ctp, union ccb *ccb, int ta…
76 static void ahci_reset(struct ahci_channel *ch);
77 static void ahci_start(struct ahci_channel *ch, int fbs);
78 static void ahci_stop(struct ahci_channel *ch);
79 static void ahci_clo(struct ahci_channel *ch);
80 static void ahci_start_fr(struct ahci_channel *ch);
81 static void ahci_stop_fr(struct ahci_channel *ch);
82 static int ahci_phy_check_events(struct ahci_channel *ch, u_int32_t serr);
83 static uint32_t ahci_ch_detval(struct ahci_channel *ch, uint32_t val);
85 static int ahci_sata_connect(struct ahci_channel *ch);
86 static int ahci_sata_phy_reset(struct ahci_channel *ch);
87 static int ahci_wait_ready(struct ahci_channel *ch, int t, int t0);
89 static void ahci_issue_recovery(struct ahci_channel *ch);
90 static void ahci_process_read_log(struct ahci_channel *ch, union ccb *ccb);
91 static void ahci_process_request_sense(struct ahci_channel *ch, union ccb *ccb);
105 ahci_ch_detval(struct ahci_channel *ch, uint32_t val) in ahci_ch_detval() argument
108 return ch->disablephy ? ATA_SC_DET_DISABLE : val; in ahci_ch_detval()
486 "ch%d" : "%d", i); in ahci_setup_interrupt()
721 ahci_attached(device_t dev, struct ahci_channel *ch) in ahci_attached() argument
726 ctlr->ch[ch->unit] = ch; in ahci_attached()
731 ahci_detached(device_t dev, struct ahci_channel *ch) in ahci_detached() argument
736 mtx_lock(&ch->mtx); in ahci_detached()
737 ctlr->ch[ch->unit] = NULL; in ahci_detached()
738 mtx_unlock(&ch->mtx); in ahci_detached()
746 struct ahci_channel *ch; in ahci_getch() local
750 ch = ctlr->ch[n]; in ahci_getch()
751 if (ch != NULL) in ahci_getch()
752 mtx_lock(&ch->mtx); in ahci_getch()
754 return (ch); in ahci_getch()
758 ahci_putch(struct ahci_channel *ch) in ahci_putch() argument
761 mtx_unlock(&ch->mtx); in ahci_putch()
775 struct ahci_channel *ch; in ahci_ch_disablephy_proc() local
778 ch = arg1; in ahci_ch_disablephy_proc()
779 value = ch->disablephy; in ahci_ch_disablephy_proc()
784 mtx_lock(&ch->mtx); in ahci_ch_disablephy_proc()
785 ch->disablephy = value; in ahci_ch_disablephy_proc()
787 ahci_ch_deinit(ch->dev); in ahci_ch_disablephy_proc()
789 ahci_ch_init(ch->dev); in ahci_ch_disablephy_proc()
790 ahci_phy_check_events(ch, ATA_SE_PHY_CHANGED | ATA_SE_EXCHANGED); in ahci_ch_disablephy_proc()
792 mtx_unlock(&ch->mtx); in ahci_ch_disablephy_proc()
801 struct ahci_channel *ch = device_get_softc(dev); in ahci_ch_attach() local
808 ch->dev = dev; in ahci_ch_attach()
809 ch->unit = (intptr_t)device_get_ivars(dev); in ahci_ch_attach()
810 ch->caps = ctlr->caps; in ahci_ch_attach()
811 ch->caps2 = ctlr->caps2; in ahci_ch_attach()
812 ch->start = ctlr->ch_start; in ahci_ch_attach()
813 ch->quirks = ctlr->quirks; in ahci_ch_attach()
814 ch->vendorid = ctlr->vendorid; in ahci_ch_attach()
815 ch->deviceid = ctlr->deviceid; in ahci_ch_attach()
816 ch->subvendorid = ctlr->subvendorid; in ahci_ch_attach()
817 ch->subdeviceid = ctlr->subdeviceid; in ahci_ch_attach()
818 ch->numslots = ((ch->caps & AHCI_CAP_NCS) >> AHCI_CAP_NCS_SHIFT) + 1; in ahci_ch_attach()
819 mtx_init(&ch->mtx, "AHCI channel lock", NULL, MTX_DEF); in ahci_ch_attach()
820 ch->pm_level = 0; in ahci_ch_attach()
822 device_get_unit(dev), "pm_level", &ch->pm_level); in ahci_ch_attach()
823 STAILQ_INIT(&ch->doneq); in ahci_ch_attach()
824 if (ch->pm_level > 3) in ahci_ch_attach()
825 callout_init_mtx(&ch->pm_timer, &ch->mtx, 0); in ahci_ch_attach()
826 callout_init_mtx(&ch->reset_timer, &ch->mtx, 0); in ahci_ch_attach()
828 if ((ctlr->quirks & AHCI_Q_SATA1_UNIT0) && ch->unit == 0) in ahci_ch_attach()
830 if (ch->quirks & AHCI_Q_SATA2) in ahci_ch_attach()
835 ch->user[i].revision = sata_rev; in ahci_ch_attach()
836 ch->user[i].mode = 0; in ahci_ch_attach()
837 ch->user[i].bytecount = 8192; in ahci_ch_attach()
838 ch->user[i].tags = ch->numslots; in ahci_ch_attach()
839 ch->user[i].caps = 0; in ahci_ch_attach()
840 ch->curr[i] = ch->user[i]; in ahci_ch_attach()
841 if (ch->pm_level) { in ahci_ch_attach()
842 ch->user[i].caps = CTS_SATA_CAPS_H_PMREQ | in ahci_ch_attach()
846 ch->user[i].caps |= CTS_SATA_CAPS_H_DMAAA | in ahci_ch_attach()
850 if (!(ch->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in ahci_ch_attach()
853 ch->chcaps = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_ch_attach()
856 ch->chcaps |= AHCI_P_CMD_FBSCP; in ahci_ch_attach()
857 if (ch->caps2 & AHCI_CAP2_SDS) in ahci_ch_attach()
858 ch->chscaps = ATA_INL(ch->r_mem, AHCI_P_DEVSLP); in ahci_ch_attach()
861 (ch->chcaps & AHCI_P_CMD_HPCP) ? " HPCP":"", in ahci_ch_attach()
862 (ch->chcaps & AHCI_P_CMD_MPSP) ? " MPSP":"", in ahci_ch_attach()
863 (ch->chcaps & AHCI_P_CMD_CPD) ? " CPD":"", in ahci_ch_attach()
864 (ch->chcaps & AHCI_P_CMD_ESP) ? " ESP":"", in ahci_ch_attach()
865 (ch->chcaps & AHCI_P_CMD_FBSCP) ? " FBSCP":"", in ahci_ch_attach()
866 (ch->chscaps & AHCI_P_DEVSLP_DSP) ? " DSP":""); in ahci_ch_attach()
870 mtx_lock(&ch->mtx); in ahci_ch_attach()
873 if (!(ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, in ahci_ch_attach()
879 if ((bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL, in ahci_ch_attach()
881 ch, &ch->ih))) { in ahci_ch_attach()
887 devq = cam_simq_alloc(ch->numslots); in ahci_ch_attach()
894 ch->sim = cam_sim_alloc(ahciaction, ahcipoll, "ahcich", ch, in ahci_ch_attach()
895 device_get_unit(dev), (struct mtx *)&ch->mtx, in ahci_ch_attach()
896 (ch->quirks & AHCI_Q_NOCCS) ? 1 : min(2, ch->numslots), in ahci_ch_attach()
897 (ch->caps & AHCI_CAP_SNCQ) ? ch->numslots : 0, in ahci_ch_attach()
899 if (ch->sim == NULL) { in ahci_ch_attach()
905 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) { in ahci_ch_attach()
910 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim), in ahci_ch_attach()
916 if (ch->pm_level > 3) { in ahci_ch_attach()
917 callout_reset(&ch->pm_timer, in ahci_ch_attach()
918 (ch->pm_level == 4) ? hz / 1000 : hz / 8, in ahci_ch_attach()
919 ahci_ch_pm, ch); in ahci_ch_attach()
921 mtx_unlock(&ch->mtx); in ahci_ch_attach()
922 ahci_attached(device_get_parent(dev), ch); in ahci_ch_attach()
926 CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, ch, in ahci_ch_attach()
931 xpt_bus_deregister(cam_sim_path(ch->sim)); in ahci_ch_attach()
933 cam_sim_free(ch->sim, /*free_devq*/TRUE); in ahci_ch_attach()
935 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq); in ahci_ch_attach()
937 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem); in ahci_ch_attach()
938 mtx_unlock(&ch->mtx); in ahci_ch_attach()
939 mtx_destroy(&ch->mtx); in ahci_ch_attach()
946 struct ahci_channel *ch = device_get_softc(dev); in ahci_ch_detach() local
948 ahci_detached(device_get_parent(dev), ch); in ahci_ch_detach()
949 mtx_lock(&ch->mtx); in ahci_ch_detach()
950 xpt_async(AC_LOST_DEVICE, ch->path, NULL); in ahci_ch_detach()
952 if (ch->resetting) { in ahci_ch_detach()
953 ch->resetting = 0; in ahci_ch_detach()
954 xpt_release_simq(ch->sim, TRUE); in ahci_ch_detach()
956 xpt_free_path(ch->path); in ahci_ch_detach()
957 xpt_bus_deregister(cam_sim_path(ch->sim)); in ahci_ch_detach()
958 cam_sim_free(ch->sim, /*free_devq*/TRUE); in ahci_ch_detach()
959 mtx_unlock(&ch->mtx); in ahci_ch_detach()
961 if (ch->pm_level > 3) in ahci_ch_detach()
962 callout_drain(&ch->pm_timer); in ahci_ch_detach()
963 callout_drain(&ch->reset_timer); in ahci_ch_detach()
964 bus_teardown_intr(dev, ch->r_irq, ch->ih); in ahci_ch_detach()
965 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq); in ahci_ch_detach()
971 bus_release_resource(dev, SYS_RES_MEMORY, ch->unit, ch->r_mem); in ahci_ch_detach()
972 mtx_destroy(&ch->mtx); in ahci_ch_detach()
979 struct ahci_channel *ch = device_get_softc(dev); in ahci_ch_init() local
983 ATA_OUTL(ch->r_mem, AHCI_P_IE, 0); in ahci_ch_init()
985 work = ch->dma.work_bus + AHCI_CL_OFFSET; in ahci_ch_init()
986 ATA_OUTL(ch->r_mem, AHCI_P_CLB, work & 0xffffffff); in ahci_ch_init()
987 ATA_OUTL(ch->r_mem, AHCI_P_CLBU, work >> 32); in ahci_ch_init()
988 work = ch->dma.rfis_bus; in ahci_ch_init()
989 ATA_OUTL(ch->r_mem, AHCI_P_FB, work & 0xffffffff); in ahci_ch_init()
990 ATA_OUTL(ch->r_mem, AHCI_P_FBU, work >> 32); in ahci_ch_init()
992 ATA_OUTL(ch->r_mem, AHCI_P_CMD, in ahci_ch_init()
994 ((ch->pm_level == 2 || ch->pm_level == 3) ? AHCI_P_CMD_ALPE : 0) | in ahci_ch_init()
995 ((ch->pm_level > 2) ? AHCI_P_CMD_ASP : 0 ))); in ahci_ch_init()
996 ahci_start_fr(ch); in ahci_ch_init()
997 ahci_start(ch, 1); in ahci_ch_init()
1004 struct ahci_channel *ch = device_get_softc(dev); in ahci_ch_deinit() local
1007 ATA_OUTL(ch->r_mem, AHCI_P_IE, 0); in ahci_ch_deinit()
1009 ahci_stop(ch); in ahci_ch_deinit()
1010 ahci_stop_fr(ch); in ahci_ch_deinit()
1011 ATA_OUTL(ch->r_mem, AHCI_P_CMD, 0); in ahci_ch_deinit()
1013 ATA_OUTL(ch->r_mem, AHCI_P_SCTL, 0); in ahci_ch_deinit()
1015 ATA_OUTL(ch->r_mem, AHCI_P_CMD, AHCI_P_CMD_SLUMBER); in ahci_ch_deinit()
1018 ATA_OUTL(ch->r_mem, AHCI_P_SCTL, ATA_SC_DET_DISABLE); in ahci_ch_deinit()
1025 struct ahci_channel *ch = device_get_softc(dev); in ahci_ch_suspend() local
1027 mtx_lock(&ch->mtx); in ahci_ch_suspend()
1028 xpt_freeze_simq(ch->sim, 1); in ahci_ch_suspend()
1030 if (ch->resetting) { in ahci_ch_suspend()
1031 ch->resetting = 0; in ahci_ch_suspend()
1032 callout_stop(&ch->reset_timer); in ahci_ch_suspend()
1033 xpt_release_simq(ch->sim, TRUE); in ahci_ch_suspend()
1035 while (ch->oslots) in ahci_ch_suspend()
1036 msleep(ch, &ch->mtx, PRIBIO, "ahcisusp", hz/100); in ahci_ch_suspend()
1038 mtx_unlock(&ch->mtx); in ahci_ch_suspend()
1045 struct ahci_channel *ch = device_get_softc(dev); in ahci_ch_resume() local
1047 mtx_lock(&ch->mtx); in ahci_ch_resume()
1049 ahci_reset(ch); in ahci_ch_resume()
1050 xpt_release_simq(ch->sim, TRUE); in ahci_ch_resume()
1051 mtx_unlock(&ch->mtx); in ahci_ch_resume()
1078 struct ahci_channel *ch = device_get_softc(dev); in ahci_dmainit() local
1087 0, NULL, NULL, &ch->dma.work_tag); in ahci_dmainit()
1090 error = bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, in ahci_dmainit()
1091 BUS_DMA_ZERO, &ch->dma.work_map); in ahci_dmainit()
1094 error = bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work, in ahci_dmainit()
1097 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map); in ahci_dmainit()
1100 ch->dma.work_bus = dcba.maddr; in ahci_dmainit()
1102 if (ch->chcaps & AHCI_P_CMD_FBSCP) in ahci_dmainit()
1109 0, NULL, NULL, &ch->dma.rfis_tag); in ahci_dmainit()
1112 error = bus_dmamem_alloc(ch->dma.rfis_tag, (void **)&ch->dma.rfis, 0, in ahci_dmainit()
1113 &ch->dma.rfis_map); in ahci_dmainit()
1116 error = bus_dmamap_load(ch->dma.rfis_tag, ch->dma.rfis_map, ch->dma.rfis, in ahci_dmainit()
1119 bus_dmamem_free(ch->dma.rfis_tag, ch->dma.rfis, ch->dma.rfis_map); in ahci_dmainit()
1122 ch->dma.rfis_bus = dcba.maddr; in ahci_dmainit()
1128 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag); in ahci_dmainit()
1151 struct ahci_channel *ch = device_get_softc(dev); in ahci_dmafini() local
1153 if (ch->dma.data_tag) { in ahci_dmafini()
1154 bus_dma_tag_destroy(ch->dma.data_tag); in ahci_dmafini()
1155 ch->dma.data_tag = NULL; in ahci_dmafini()
1157 if (ch->dma.rfis_bus) { in ahci_dmafini()
1158 bus_dmamap_unload(ch->dma.rfis_tag, ch->dma.rfis_map); in ahci_dmafini()
1159 bus_dmamem_free(ch->dma.rfis_tag, ch->dma.rfis, ch->dma.rfis_map); in ahci_dmafini()
1160 ch->dma.rfis_bus = 0; in ahci_dmafini()
1161 ch->dma.rfis = NULL; in ahci_dmafini()
1163 if (ch->dma.work_bus) { in ahci_dmafini()
1164 bus_dmamap_unload(ch->dma.work_tag, ch->dma.work_map); in ahci_dmafini()
1165 bus_dmamem_free(ch->dma.work_tag, ch->dma.work, ch->dma.work_map); in ahci_dmafini()
1166 ch->dma.work_bus = 0; in ahci_dmafini()
1167 ch->dma.work = NULL; in ahci_dmafini()
1169 if (ch->dma.work_tag) { in ahci_dmafini()
1170 bus_dma_tag_destroy(ch->dma.work_tag); in ahci_dmafini()
1171 ch->dma.work_tag = NULL; in ahci_dmafini()
1178 struct ahci_channel *ch = device_get_softc(dev); in ahci_slotsalloc() local
1182 bzero(ch->slot, sizeof(ch->slot)); in ahci_slotsalloc()
1183 for (i = 0; i < ch->numslots; i++) { in ahci_slotsalloc()
1184 struct ahci_slot *slot = &ch->slot[i]; in ahci_slotsalloc()
1186 slot->ch = ch; in ahci_slotsalloc()
1191 callout_init_mtx(&slot->timeout, &ch->mtx, 0); in ahci_slotsalloc()
1193 if (bus_dmamap_create(ch->dma.data_tag, 0, &slot->dma.data_map)) in ahci_slotsalloc()
1194 device_printf(ch->dev, "FAILURE - create data_map\n"); in ahci_slotsalloc()
1201 struct ahci_channel *ch = device_get_softc(dev); in ahci_slotsfree() local
1205 for (i = 0; i < ch->numslots; i++) { in ahci_slotsfree()
1206 struct ahci_slot *slot = &ch->slot[i]; in ahci_slotsfree()
1210 bus_dmamap_destroy(ch->dma.data_tag, slot->dma.data_map); in ahci_slotsfree()
1217 ahci_phy_check_events(struct ahci_channel *ch, u_int32_t serr) in ahci_phy_check_events() argument
1220 if (((ch->pm_level == 0) && (serr & ATA_SE_PHY_CHANGED)) || in ahci_phy_check_events()
1221 ((ch->pm_level != 0 || ch->listening) && (serr & ATA_SE_EXCHANGED))) { in ahci_phy_check_events()
1222 u_int32_t status = ATA_INL(ch->r_mem, AHCI_P_SSTS); in ahci_phy_check_events()
1227 device_printf(ch->dev, "CONNECT requested\n"); in ahci_phy_check_events()
1229 device_printf(ch->dev, "DISCONNECT requested\n"); in ahci_phy_check_events()
1231 ahci_reset(ch); in ahci_phy_check_events()
1235 cam_sim_path(ch->sim), in ahci_phy_check_events()
1247 ahci_cpd_check_events(struct ahci_channel *ch) in ahci_cpd_check_events() argument
1253 if (ch->pm_level == 0) in ahci_cpd_check_events()
1256 status = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_cpd_check_events()
1261 dev = ch->dev; in ahci_cpd_check_events()
1267 ahci_reset(ch); in ahci_cpd_check_events()
1270 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(ch->sim), in ahci_cpd_check_events()
1279 ahci_notify_events(struct ahci_channel *ch, u_int32_t status) in ahci_notify_events() argument
1284 if (ch->caps & AHCI_CAP_SSNTF) in ahci_notify_events()
1285 ATA_OUTL(ch->r_mem, AHCI_P_SNTF, status); in ahci_notify_events()
1287 device_printf(ch->dev, "SNTF 0x%04x\n", status); in ahci_notify_events()
1292 xpt_path_path_id(ch->path), i, 0) == CAM_REQ_CMP) { in ahci_notify_events()
1300 ahci_done(struct ahci_channel *ch, union ccb *ccb) in ahci_done() argument
1303 mtx_assert(&ch->mtx, MA_OWNED); in ahci_done()
1305 ch->batch == 0) { in ahci_done()
1310 STAILQ_INSERT_TAIL(&ch->doneq, &ccb->ccb_h, sim_links.stqe); in ahci_done()
1316 struct ahci_channel *ch = (struct ahci_channel *)arg; in ahci_ch_intr() local
1320 istatus = ATA_INL(ch->r_mem, AHCI_P_IS); in ahci_ch_intr()
1322 mtx_lock(&ch->mtx); in ahci_ch_intr()
1323 ahci_ch_intr_main(ch, istatus); in ahci_ch_intr()
1324 mtx_unlock(&ch->mtx); in ahci_ch_intr()
1330 struct ahci_channel *ch = (struct ahci_channel *)arg; in ahci_ch_intr_direct() local
1336 istatus = ATA_INL(ch->r_mem, AHCI_P_IS); in ahci_ch_intr_direct()
1338 mtx_lock(&ch->mtx); in ahci_ch_intr_direct()
1339 ch->batch = 1; in ahci_ch_intr_direct()
1340 ahci_ch_intr_main(ch, istatus); in ahci_ch_intr_direct()
1341 ch->batch = 0; in ahci_ch_intr_direct()
1346 STAILQ_CONCAT(&tmp_doneq, &ch->doneq); in ahci_ch_intr_direct()
1347 mtx_unlock(&ch->mtx); in ahci_ch_intr_direct()
1357 struct ahci_channel *ch = (struct ahci_channel *)arg; in ahci_ch_pm() local
1360 if (ch->numrslots != 0) in ahci_ch_pm()
1362 work = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_ch_pm()
1363 if (ch->pm_level == 4) in ahci_ch_pm()
1367 ATA_OUTL(ch->r_mem, AHCI_P_CMD, work); in ahci_ch_pm()
1371 ahci_ch_intr_main(struct ahci_channel *ch, uint32_t istatus) in ahci_ch_intr_main() argument
1378 ATA_OUTL(ch->r_mem, AHCI_P_IS, istatus); in ahci_ch_intr_main()
1380 if (ch->numtslots != 0) in ahci_ch_intr_main()
1381 cstatus = ATA_INL(ch->r_mem, AHCI_P_SACT); in ahci_ch_intr_main()
1384 if (ch->numrslots != ch->numtslots) in ahci_ch_intr_main()
1385 cstatus |= ATA_INL(ch->r_mem, AHCI_P_CI); in ahci_ch_intr_main()
1388 (ch->pm_present || ch->curr[0].atapi != 0)) { in ahci_ch_intr_main()
1389 if (ch->caps & AHCI_CAP_SSNTF) in ahci_ch_intr_main()
1390 sntf = ATA_INL(ch->r_mem, AHCI_P_SNTF); in ahci_ch_intr_main()
1391 else if (ch->fbs_enabled) { in ahci_ch_intr_main()
1392 u_int8_t *fis = ch->dma.rfis + 0x58; in ahci_ch_intr_main()
1402 u_int8_t *fis = ch->dma.rfis + 0x58; in ahci_ch_intr_main()
1411 serr = ATA_INL(ch->r_mem, AHCI_P_SERR); in ahci_ch_intr_main()
1413 ATA_OUTL(ch->r_mem, AHCI_P_SERR, serr); in ahci_ch_intr_main()
1414 reset = ahci_phy_check_events(ch, serr); in ahci_ch_intr_main()
1419 ahci_cpd_check_events(ch); in ahci_ch_intr_main()
1423 if (ch->quirks & AHCI_Q_NOCCS) { in ahci_ch_intr_main()
1428 cstatus |= ch->rslots; in ahci_ch_intr_main()
1433 ccs = (ATA_INL(ch->r_mem, AHCI_P_CMD) & in ahci_ch_intr_main()
1437 // __func__, istatus, cstatus, sstatus, ch->rslots, ATA_INL(ch->r_mem, AHCI_P_TFD), in ahci_ch_intr_main()
1438 // serr, ATA_INL(ch->r_mem, AHCI_P_FBS), ccs); in ahci_ch_intr_main()
1440 if (ch->fbs_enabled) { in ahci_ch_intr_main()
1441 uint32_t fbs = ATA_INL(ch->r_mem, AHCI_P_FBS); in ahci_ch_intr_main()
1447 if (ch->numrslotspd[i] == 0) in ahci_ch_intr_main()
1458 err = ch->rslots & cstatus; in ahci_ch_intr_main()
1465 ok = ch->rslots & ~cstatus; in ahci_ch_intr_main()
1466 for (i = 0; i < ch->numslots; i++) { in ahci_ch_intr_main()
1468 ahci_end_transaction(&ch->slot[i], AHCI_ERR_NONE); in ahci_ch_intr_main()
1472 if (ch->frozen) { in ahci_ch_intr_main()
1473 union ccb *fccb = ch->frozen; in ahci_ch_intr_main()
1474 ch->frozen = NULL; in ahci_ch_intr_main()
1480 ahci_done(ch, fccb); in ahci_ch_intr_main()
1482 for (i = 0; i < ch->numslots; i++) { in ahci_ch_intr_main()
1487 ch->slot[i].ccb->ccb_h.target_id != port) in ahci_ch_intr_main()
1492 if (ch->numtslotspd[ in ahci_ch_intr_main()
1493 ch->slot[i].ccb->ccb_h.target_id] == 0) { in ahci_ch_intr_main()
1505 ch->fatalerr = 1; in ahci_ch_intr_main()
1508 if (ch->numtslots == 0 && i != ccs && port != -2) in ahci_ch_intr_main()
1514 ahci_end_transaction(&ch->slot[i], et); in ahci_ch_intr_main()
1520 if (ch->rslots != 0 && !ch->recoverycmd) in ahci_ch_intr_main()
1521 ATA_OUTL(ch->r_mem, AHCI_P_FBS, AHCI_P_FBS_EN | AHCI_P_FBS_DEC); in ahci_ch_intr_main()
1525 ahci_notify_events(ch, sntf); in ahci_ch_intr_main()
1530 ahci_check_collision(struct ahci_channel *ch, union ccb *ccb) in ahci_check_collision() argument
1537 if (((~ch->oslots) & (0xffffffff >> (32 - in ahci_check_collision()
1538 ch->curr[t].tags))) == 0) in ahci_check_collision()
1541 if (ch->fbs_enabled) { in ahci_check_collision()
1543 if (ch->numrslotspd[t] != 0 && ch->numtslotspd[t] == 0) in ahci_check_collision()
1547 if (ch->numrslots != 0 && ch->numtslots == 0) in ahci_check_collision()
1550 if (ch->numtslots != 0 && in ahci_check_collision()
1551 ch->taggedtarget != ccb->ccb_h.target_id) in ahci_check_collision()
1556 if (ch->fbs_enabled) { in ahci_check_collision()
1558 if (ch->numrslotspd[t] != 0 && ch->numtslotspd[t] != 0) in ahci_check_collision()
1562 if (ch->numrslots != 0 && ch->numtslots != 0) in ahci_check_collision()
1569 if (ch->numrslots != 0) in ahci_check_collision()
1573 if (ch->aslots != 0) in ahci_check_collision()
1580 ahci_begin_transaction(struct ahci_channel *ch, union ccb *ccb) in ahci_begin_transaction() argument
1586 tags = ch->numslots; in ahci_begin_transaction()
1589 tags = ch->curr[ccb->ccb_h.target_id].tags; in ahci_begin_transaction()
1590 if (ch->lastslot + 1 < tags) in ahci_begin_transaction()
1591 tag = ffs(~(ch->oslots >> (ch->lastslot + 1))); in ahci_begin_transaction()
1594 if (tag == 0 || tag + ch->lastslot >= tags) in ahci_begin_transaction()
1595 tag = ffs(~ch->oslots) - 1; in ahci_begin_transaction()
1597 tag += ch->lastslot; in ahci_begin_transaction()
1598 ch->lastslot = tag; in ahci_begin_transaction()
1600 slot = &ch->slot[tag]; in ahci_begin_transaction()
1603 if (ch->numrslots == 0 && ch->pm_level > 3) in ahci_begin_transaction()
1604 callout_stop(&ch->pm_timer); in ahci_begin_transaction()
1606 ch->oslots |= (1 << tag); in ahci_begin_transaction()
1607 ch->numrslots++; in ahci_begin_transaction()
1608 ch->numrslotspd[ccb->ccb_h.target_id]++; in ahci_begin_transaction()
1611 ch->numtslots++; in ahci_begin_transaction()
1612 ch->numtslotspd[ccb->ccb_h.target_id]++; in ahci_begin_transaction()
1613 ch->taggedtarget = ccb->ccb_h.target_id; in ahci_begin_transaction()
1617 ch->aslots |= (1 << tag); in ahci_begin_transaction()
1620 bus_dmamap_load_ccb(ch->dma.data_tag, slot->dma.data_map, ccb, in ahci_begin_transaction()
1633 struct ahci_channel *ch = slot->ch; in ahci_dmasetprd() local
1639 device_printf(ch->dev, "DMA load error\n"); in ahci_dmasetprd()
1645 ctp = (struct ahci_cmd_tab *)(ch->dma.work + slot->ct_offset); in ahci_dmasetprd()
1653 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map, in ahci_dmasetprd()
1663 struct ahci_channel *ch = slot->ch; in ahci_execute_transaction() local
1669 uint8_t *fis = ch->dma.rfis + 0x40; in ahci_execute_transaction()
1674 ctp = (struct ahci_cmd_tab *)(ch->dma.work + slot->ct_offset); in ahci_execute_transaction()
1676 if (!(fis_size = ahci_setup_fis(ch, ctp, ccb, slot->slot))) { in ahci_execute_transaction()
1677 device_printf(ch->dev, "Setting up SATA FIS failed\n"); in ahci_execute_transaction()
1683 (ch->dma.work + AHCI_CL_OFFSET + (AHCI_CL_SIZE * slot->slot)); in ahci_execute_transaction()
1697 ahci_stop(ch); in ahci_execute_transaction()
1698 ahci_clo(ch); in ahci_execute_transaction()
1699 ahci_start(ch, 0); in ahci_execute_transaction()
1711 clp->cmd_table_phys = htole64(ch->dma.work_bus + slot->ct_offset); in ahci_execute_transaction()
1712 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map, in ahci_execute_transaction()
1714 bus_dmamap_sync(ch->dma.rfis_tag, ch->dma.rfis_map, in ahci_execute_transaction()
1719 ATA_OUTL(ch->r_mem, AHCI_P_SACT, 1 << slot->slot); in ahci_execute_transaction()
1722 if (ch->fbs_enabled) { in ahci_execute_transaction()
1723 ATA_OUTL(ch->r_mem, AHCI_P_FBS, AHCI_P_FBS_EN | in ahci_execute_transaction()
1728 ch->rslots |= (1 << slot->slot); in ahci_execute_transaction()
1729 ATA_OUTL(ch->r_mem, AHCI_P_CI, (1 << slot->slot)); in ahci_execute_transaction()
1738 if (!(ATA_INL(ch->r_mem, AHCI_P_CI) & (1 << slot->slot))) in ahci_execute_transaction()
1740 if ((ATA_INL(ch->r_mem, AHCI_P_TFD) & ATA_S_ERROR) && in ahci_execute_transaction()
1743 device_printf(ch->dev, in ahci_execute_transaction()
1745 slot->slot, ATA_INL(ch->r_mem, AHCI_P_TFD)); in ahci_execute_transaction()
1752 (ch->quirks & AHCI_Q_ATI_PMP_BUG) && in ahci_execute_transaction()
1753 (ATA_INL(ch->r_mem, AHCI_P_IS) & AHCI_P_IX_IPM)) { in ahci_execute_transaction()
1764 if (ch->quirks & AHCI_Q_MRVL_SR_DEL) in ahci_execute_transaction()
1774 if ((ch->quirks & AHCI_Q_NOBSYRES) == 0 && in ahci_execute_transaction()
1775 (ch->quirks & AHCI_Q_ATI_PMP_BUG) == 0 && in ahci_execute_transaction()
1778 bus_dmamap_sync(ch->dma.rfis_tag, in ahci_execute_transaction()
1779 ch->dma.rfis_map, BUS_DMASYNC_POSTREAD); in ahci_execute_transaction()
1781 bus_dmamap_sync(ch->dma.rfis_tag, in ahci_execute_transaction()
1782 ch->dma.rfis_map, BUS_DMASYNC_PREREAD); in ahci_execute_transaction()
1790 device_printf(ch->dev, "Poll timeout on slot %d port %d\n", in ahci_execute_transaction()
1792 device_printf(ch->dev, "is %08x cs %08x ss %08x " in ahci_execute_transaction()
1794 ATA_INL(ch->r_mem, AHCI_P_IS), in ahci_execute_transaction()
1795 ATA_INL(ch->r_mem, AHCI_P_CI), in ahci_execute_transaction()
1796 ATA_INL(ch->r_mem, AHCI_P_SACT), ch->rslots, in ahci_execute_transaction()
1797 ATA_INL(ch->r_mem, AHCI_P_TFD), in ahci_execute_transaction()
1798 ATA_INL(ch->r_mem, AHCI_P_SERR), in ahci_execute_transaction()
1799 ATA_INL(ch->r_mem, AHCI_P_CMD)); in ahci_execute_transaction()
1805 ch->eslots |= (1 << slot->slot); in ahci_execute_transaction()
1817 ahci_process_timeout(struct ahci_channel *ch) in ahci_process_timeout() argument
1821 mtx_assert(&ch->mtx, MA_OWNED); in ahci_process_timeout()
1823 for (i = 0; i < ch->numslots; i++) { in ahci_process_timeout()
1825 if (ch->slot[i].state < AHCI_SLOT_RUNNING) in ahci_process_timeout()
1827 ahci_end_transaction(&ch->slot[i], AHCI_ERR_TIMEOUT); in ahci_process_timeout()
1833 ahci_rearm_timeout(struct ahci_channel *ch) in ahci_rearm_timeout() argument
1837 mtx_assert(&ch->mtx, MA_OWNED); in ahci_rearm_timeout()
1838 for (i = 0; i < ch->numslots; i++) { in ahci_rearm_timeout()
1839 struct ahci_slot *slot = &ch->slot[i]; in ahci_rearm_timeout()
1844 if ((ch->toslots & (1 << i)) == 0) in ahci_rearm_timeout()
1857 struct ahci_channel *ch = slot->ch; in ahci_timeout() local
1858 device_t dev = ch->dev; in ahci_timeout()
1870 sstatus = ATA_INL(ch->r_mem, AHCI_P_SACT); in ahci_timeout()
1871 ccs = (ATA_INL(ch->r_mem, AHCI_P_CMD) & AHCI_P_CMD_CCS_MASK) in ahci_timeout()
1874 ch->fbs_enabled || ch->wrongccs) in ahci_timeout()
1876 else if ((ch->rslots & (1 << ccs)) == 0) { in ahci_timeout()
1877 ch->wrongccs = 1; in ahci_timeout()
1891 ATA_INL(ch->r_mem, AHCI_P_IS), ATA_INL(ch->r_mem, AHCI_P_CI), in ahci_timeout()
1892 ATA_INL(ch->r_mem, AHCI_P_SACT), ch->rslots, in ahci_timeout()
1893 ATA_INL(ch->r_mem, AHCI_P_TFD), ATA_INL(ch->r_mem, AHCI_P_SERR), in ahci_timeout()
1894 ATA_INL(ch->r_mem, AHCI_P_CMD)); in ahci_timeout()
1897 if (ch->frozen) { in ahci_timeout()
1898 union ccb *fccb = ch->frozen; in ahci_timeout()
1899 ch->frozen = NULL; in ahci_timeout()
1905 ahci_done(ch, fccb); in ahci_timeout()
1907 if (!ch->fbs_enabled && !ch->wrongccs) { in ahci_timeout()
1909 ch->fatalerr = 1; in ahci_timeout()
1911 ahci_end_transaction(&ch->slot[slot->slot], AHCI_ERR_TIMEOUT); in ahci_timeout()
1913 for (i = 0; i < ch->numslots; i++) { in ahci_timeout()
1915 if (ch->slot[i].state < AHCI_SLOT_RUNNING) in ahci_timeout()
1917 ahci_end_transaction(&ch->slot[i], AHCI_ERR_INNOCENT); in ahci_timeout()
1921 if (ch->toslots == 0) in ahci_timeout()
1922 xpt_freeze_simq(ch->sim, 1); in ahci_timeout()
1923 ch->toslots |= (1 << slot->slot); in ahci_timeout()
1924 if ((ch->rslots & ~ch->toslots) == 0) in ahci_timeout()
1925 ahci_process_timeout(ch); in ahci_timeout()
1928 ch->rslots & ~ch->toslots); in ahci_timeout()
1936 struct ahci_channel *ch = slot->ch; in ahci_end_transaction() local
1942 bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map, in ahci_end_transaction()
1945 (ch->dma.work + AHCI_CL_OFFSET + (AHCI_CL_SIZE * slot->slot)); in ahci_end_transaction()
1955 u_int8_t *fis = ch->dma.rfis + 0x40; in ahci_end_transaction()
1957 bus_dmamap_sync(ch->dma.rfis_tag, ch->dma.rfis_map, in ahci_end_transaction()
1959 if (ch->fbs_enabled) { in ahci_end_transaction()
1964 uint16_t tfd = ATA_INL(ch->r_mem, AHCI_P_TFD); in ahci_end_transaction()
1983 if ((ch->quirks & AHCI_Q_ALTSIG) && in ahci_end_transaction()
1986 sig = ATA_INL(ch->r_mem, AHCI_P_SIG); in ahci_end_transaction()
1996 (ch->quirks & AHCI_Q_NOCOUNT) == 0) { in ahci_end_transaction()
2002 (ch->quirks & AHCI_Q_NOCOUNT) == 0) { in ahci_end_transaction()
2008 bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map, in ahci_end_transaction()
2011 bus_dmamap_unload(ch->dma.data_tag, slot->dma.data_map); in ahci_end_transaction()
2014 ch->eslots |= (1 << slot->slot); in ahci_end_transaction()
2016 if ((et != AHCI_ERR_NONE) && (!ch->recoverycmd) && in ahci_end_transaction()
2030 ch->fatalerr = 1; in ahci_end_transaction()
2046 ch->fatalerr = 1; in ahci_end_transaction()
2047 if (!ch->recoverycmd) { in ahci_end_transaction()
2048 xpt_freeze_simq(ch->sim, 1); in ahci_end_transaction()
2055 if (!ch->recoverycmd) { in ahci_end_transaction()
2056 xpt_freeze_simq(ch->sim, 1); in ahci_end_transaction()
2063 ch->fatalerr = 1; in ahci_end_transaction()
2067 ch->oslots &= ~(1 << slot->slot); in ahci_end_transaction()
2068 ch->rslots &= ~(1 << slot->slot); in ahci_end_transaction()
2069 ch->aslots &= ~(1 << slot->slot); in ahci_end_transaction()
2073 ch->numrslots--; in ahci_end_transaction()
2074 ch->numrslotspd[ccb->ccb_h.target_id]--; in ahci_end_transaction()
2077 ch->numtslots--; in ahci_end_transaction()
2078 ch->numtslotspd[ccb->ccb_h.target_id]--; in ahci_end_transaction()
2082 lastto = (ch->toslots == (1 << slot->slot)); in ahci_end_transaction()
2083 ch->toslots &= ~(1 << slot->slot); in ahci_end_transaction()
2085 xpt_release_simq(ch->sim, TRUE); in ahci_end_transaction()
2094 ahci_begin_transaction(ch, ccb); in ahci_end_transaction()
2099 ahci_process_read_log(ch, ccb); in ahci_end_transaction()
2102 ahci_process_request_sense(ch, ccb); in ahci_end_transaction()
2107 ch->hold[slot->slot] = ccb; in ahci_end_transaction()
2108 ch->numhslots++; in ahci_end_transaction()
2110 ahci_done(ch, ccb); in ahci_end_transaction()
2112 if (ch->rslots == 0) { in ahci_end_transaction()
2114 if (ch->toslots != 0 || ch->fatalerr) { in ahci_end_transaction()
2115 ahci_reset(ch); in ahci_end_transaction()
2118 if (ch->eslots != 0) { in ahci_end_transaction()
2119 ahci_stop(ch); in ahci_end_transaction()
2120 ahci_clo(ch); in ahci_end_transaction()
2121 ahci_start(ch, 1); in ahci_end_transaction()
2124 if (!ch->recoverycmd && ch->numhslots) in ahci_end_transaction()
2125 ahci_issue_recovery(ch); in ahci_end_transaction()
2128 } else if ((ch->rslots & ~ch->toslots) == 0 && in ahci_end_transaction()
2130 ahci_rearm_timeout(ch); in ahci_end_transaction()
2132 if (ch->frozen && !ahci_check_collision(ch, ch->frozen)) { in ahci_end_transaction()
2133 union ccb *fccb = ch->frozen; in ahci_end_transaction()
2134 ch->frozen = NULL; in ahci_end_transaction()
2135 ahci_begin_transaction(ch, fccb); in ahci_end_transaction()
2136 xpt_release_simq(ch->sim, TRUE); in ahci_end_transaction()
2139 if (ch->numrslots == 0 && ch->pm_level > 3 && in ahci_end_transaction()
2140 (ch->curr[ch->pm_present ? 15 : 0].caps & CTS_SATA_CAPS_D_PMREQ)) { in ahci_end_transaction()
2141 callout_schedule(&ch->pm_timer, in ahci_end_transaction()
2142 (ch->pm_level == 4) ? hz / 1000 : hz / 8); in ahci_end_transaction()
2147 ahci_issue_recovery(struct ahci_channel *ch) in ahci_issue_recovery() argument
2155 for (i = 0; i < ch->numslots; i++) { in ahci_issue_recovery()
2156 if (ch->hold[i]) in ahci_issue_recovery()
2161 device_printf(ch->dev, "Unable to allocate recovery command\n"); in ahci_issue_recovery()
2164 for (i = 0; i < ch->numslots; i++) { in ahci_issue_recovery()
2165 if (ch->hold[i] == NULL) in ahci_issue_recovery()
2167 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK; in ahci_issue_recovery()
2168 ch->hold[i]->ccb_h.status |= CAM_RESRC_UNAVAIL; in ahci_issue_recovery()
2169 ahci_done(ch, ch->hold[i]); in ahci_issue_recovery()
2170 ch->hold[i] = NULL; in ahci_issue_recovery()
2171 ch->numhslots--; in ahci_issue_recovery()
2173 ahci_reset(ch); in ahci_issue_recovery()
2176 xpt_setup_ccb(&ccb->ccb_h, ch->hold[i]->ccb_h.path, in ahci_issue_recovery()
2177 ch->hold[i]->ccb_h.pinfo.priority); in ahci_issue_recovery()
2178 if (ch->hold[i]->ccb_h.func_code == XPT_ATA_IO) { in ahci_issue_recovery()
2188 device_printf(ch->dev, in ahci_issue_recovery()
2210 csio->data_ptr = (void *)&ch->hold[i]->csio.sense_data; in ahci_issue_recovery()
2211 csio->dxfer_len = ch->hold[i]->csio.sense_len; in ahci_issue_recovery()
2218 ch->recoverycmd = 1; in ahci_issue_recovery()
2219 xpt_freeze_simq(ch->sim, 1); in ahci_issue_recovery()
2220 ahci_begin_transaction(ch, ccb); in ahci_issue_recovery()
2224 ahci_process_read_log(struct ahci_channel *ch, union ccb *ccb) in ahci_process_read_log() argument
2230 ch->recoverycmd = 0; in ahci_process_read_log()
2235 for (i = 0; i < ch->numslots; i++) { in ahci_process_read_log()
2236 if (!ch->hold[i]) in ahci_process_read_log()
2238 if (ch->hold[i]->ccb_h.func_code != XPT_ATA_IO) in ahci_process_read_log()
2241 res = &ch->hold[i]->ataio.res; in ahci_process_read_log()
2254 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK; in ahci_process_read_log()
2255 ch->hold[i]->ccb_h.status |= CAM_REQUEUE_REQ; in ahci_process_read_log()
2257 ahci_done(ch, ch->hold[i]); in ahci_process_read_log()
2258 ch->hold[i] = NULL; in ahci_process_read_log()
2259 ch->numhslots--; in ahci_process_read_log()
2263 device_printf(ch->dev, "Error while READ LOG EXT\n"); in ahci_process_read_log()
2265 device_printf(ch->dev, "Non-queued command error in READ LOG EXT\n"); in ahci_process_read_log()
2267 for (i = 0; i < ch->numslots; i++) { in ahci_process_read_log()
2268 if (!ch->hold[i]) in ahci_process_read_log()
2270 if (ch->hold[i]->ccb_h.func_code != XPT_ATA_IO) in ahci_process_read_log()
2272 ahci_done(ch, ch->hold[i]); in ahci_process_read_log()
2273 ch->hold[i] = NULL; in ahci_process_read_log()
2274 ch->numhslots--; in ahci_process_read_log()
2279 xpt_release_simq(ch->sim, TRUE); in ahci_process_read_log()
2283 ahci_process_request_sense(struct ahci_channel *ch, union ccb *ccb) in ahci_process_request_sense() argument
2287 ch->recoverycmd = 0; in ahci_process_request_sense()
2291 ch->hold[i]->ccb_h.status |= CAM_AUTOSNS_VALID; in ahci_process_request_sense()
2293 ch->hold[i]->ccb_h.status &= ~CAM_STATUS_MASK; in ahci_process_request_sense()
2294 ch->hold[i]->ccb_h.status |= CAM_AUTOSENSE_FAIL; in ahci_process_request_sense()
2296 ahci_done(ch, ch->hold[i]); in ahci_process_request_sense()
2297 ch->hold[i] = NULL; in ahci_process_request_sense()
2298 ch->numhslots--; in ahci_process_request_sense()
2300 xpt_release_simq(ch->sim, TRUE); in ahci_process_request_sense()
2304 ahci_start(struct ahci_channel *ch, int fbs) in ahci_start() argument
2309 if (ch->start) in ahci_start()
2310 ch->start(ch); in ahci_start()
2313 ATA_OUTL(ch->r_mem, AHCI_P_SERR, 0xFFFFFFFF); in ahci_start()
2315 ATA_OUTL(ch->r_mem, AHCI_P_IS, 0xFFFFFFFF); in ahci_start()
2317 if (ch->chcaps & AHCI_P_CMD_FBSCP) { in ahci_start()
2318 ch->fbs_enabled = (fbs && ch->pm_present) ? 1 : 0; in ahci_start()
2319 ATA_OUTL(ch->r_mem, AHCI_P_FBS, in ahci_start()
2320 ch->fbs_enabled ? AHCI_P_FBS_EN : 0); in ahci_start()
2323 cmd = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_start()
2325 ATA_OUTL(ch->r_mem, AHCI_P_CMD, cmd | AHCI_P_CMD_ST | in ahci_start()
2326 (ch->pm_present ? AHCI_P_CMD_PMA : 0)); in ahci_start()
2330 ahci_stop(struct ahci_channel *ch) in ahci_stop() argument
2336 cmd = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_stop()
2337 ATA_OUTL(ch->r_mem, AHCI_P_CMD, cmd & ~AHCI_P_CMD_ST); in ahci_stop()
2343 device_printf(ch->dev, "stopping AHCI engine failed\n"); in ahci_stop()
2346 } while (ATA_INL(ch->r_mem, AHCI_P_CMD) & AHCI_P_CMD_CR); in ahci_stop()
2347 ch->eslots = 0; in ahci_stop()
2351 ahci_clo(struct ahci_channel *ch) in ahci_clo() argument
2357 if (ch->caps & AHCI_CAP_SCLO) { in ahci_clo()
2358 cmd = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_clo()
2360 ATA_OUTL(ch->r_mem, AHCI_P_CMD, cmd); in ahci_clo()
2365 device_printf(ch->dev, "executing CLO failed\n"); in ahci_clo()
2368 } while (ATA_INL(ch->r_mem, AHCI_P_CMD) & AHCI_P_CMD_CLO); in ahci_clo()
2373 ahci_stop_fr(struct ahci_channel *ch) in ahci_stop_fr() argument
2379 cmd = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_stop_fr()
2380 ATA_OUTL(ch->r_mem, AHCI_P_CMD, cmd & ~AHCI_P_CMD_FRE); in ahci_stop_fr()
2386 device_printf(ch->dev, "stopping AHCI FR engine failed\n"); in ahci_stop_fr()
2389 } while (ATA_INL(ch->r_mem, AHCI_P_CMD) & AHCI_P_CMD_FR); in ahci_stop_fr()
2393 ahci_start_fr(struct ahci_channel *ch) in ahci_start_fr() argument
2398 cmd = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_start_fr()
2399 ATA_OUTL(ch->r_mem, AHCI_P_CMD, cmd | AHCI_P_CMD_FRE); in ahci_start_fr()
2403 ahci_wait_ready(struct ahci_channel *ch, int t, int t0) in ahci_wait_ready() argument
2408 while ((val = ATA_INL(ch->r_mem, AHCI_P_TFD)) & in ahci_wait_ready()
2412 device_printf(ch->dev, in ahci_wait_ready()
2423 device_printf(ch->dev, "AHCI reset: device ready after %dms\n", in ahci_wait_ready()
2431 struct ahci_channel *ch = arg; in ahci_reset_to() local
2433 if (ch->resetting == 0) in ahci_reset_to()
2435 ch->resetting--; in ahci_reset_to()
2436 if (ahci_wait_ready(ch, ch->resetting == 0 ? -1 : 0, in ahci_reset_to()
2437 (310 - ch->resetting) * 100) == 0) { in ahci_reset_to()
2438 ch->resetting = 0; in ahci_reset_to()
2439 ahci_start(ch, 1); in ahci_reset_to()
2440 xpt_release_simq(ch->sim, TRUE); in ahci_reset_to()
2443 if (ch->resetting == 0) { in ahci_reset_to()
2444 ahci_clo(ch); in ahci_reset_to()
2445 ahci_start(ch, 1); in ahci_reset_to()
2446 xpt_release_simq(ch->sim, TRUE); in ahci_reset_to()
2449 callout_schedule(&ch->reset_timer, hz / 10); in ahci_reset_to()
2453 ahci_reset(struct ahci_channel *ch) in ahci_reset() argument
2455 struct ahci_controller *ctlr = device_get_softc(device_get_parent(ch->dev)); in ahci_reset()
2458 xpt_freeze_simq(ch->sim, 1); in ahci_reset()
2460 device_printf(ch->dev, "AHCI reset...\n"); in ahci_reset()
2462 if (ch->resetting) { in ahci_reset()
2463 ch->resetting = 0; in ahci_reset()
2464 callout_stop(&ch->reset_timer); in ahci_reset()
2465 xpt_release_simq(ch->sim, TRUE); in ahci_reset()
2468 if (ch->frozen) { in ahci_reset()
2469 union ccb *fccb = ch->frozen; in ahci_reset()
2470 ch->frozen = NULL; in ahci_reset()
2476 ahci_done(ch, fccb); in ahci_reset()
2479 ahci_stop(ch); in ahci_reset()
2480 for (i = 0; i < ch->numslots; i++) { in ahci_reset()
2482 if (ch->slot[i].state < AHCI_SLOT_RUNNING) in ahci_reset()
2485 ahci_end_transaction(&ch->slot[i], AHCI_ERR_INNOCENT); in ahci_reset()
2487 for (i = 0; i < ch->numslots; i++) { in ahci_reset()
2488 if (!ch->hold[i]) in ahci_reset()
2490 ahci_done(ch, ch->hold[i]); in ahci_reset()
2491 ch->hold[i] = NULL; in ahci_reset()
2492 ch->numhslots--; in ahci_reset()
2494 if (ch->toslots != 0) in ahci_reset()
2495 xpt_release_simq(ch->sim, TRUE); in ahci_reset()
2496 ch->eslots = 0; in ahci_reset()
2497 ch->toslots = 0; in ahci_reset()
2498 ch->wrongccs = 0; in ahci_reset()
2499 ch->fatalerr = 0; in ahci_reset()
2501 xpt_async(AC_BUS_RESET, ch->path, NULL); in ahci_reset()
2503 ATA_OUTL(ch->r_mem, AHCI_P_IE, 0); in ahci_reset()
2505 if (!ahci_sata_phy_reset(ch)) { in ahci_reset()
2507 device_printf(ch->dev, in ahci_reset()
2509 ch->devices = 0; in ahci_reset()
2511 ATA_OUTL(ch->r_mem, AHCI_P_IE, in ahci_reset()
2512 (((ch->pm_level != 0) ? AHCI_P_IX_CPD | AHCI_P_IX_MP : 0) | in ahci_reset()
2514 xpt_release_simq(ch->sim, TRUE); in ahci_reset()
2518 device_printf(ch->dev, "AHCI reset: device found\n"); in ahci_reset()
2520 if (ahci_wait_ready(ch, dumping ? 31000 : 0, 0)) { in ahci_reset()
2522 ahci_clo(ch); in ahci_reset()
2524 ch->resetting = 310; in ahci_reset()
2526 ch->devices = 1; in ahci_reset()
2528 ATA_OUTL(ch->r_mem, AHCI_P_IE, in ahci_reset()
2529 (((ch->pm_level != 0) ? AHCI_P_IX_CPD | AHCI_P_IX_MP : 0) | in ahci_reset()
2532 ((ch->pm_level == 0) ? AHCI_P_IX_PRC : 0) | AHCI_P_IX_PC | in ahci_reset()
2535 if (ch->resetting) in ahci_reset()
2536 callout_reset(&ch->reset_timer, hz / 10, ahci_reset_to, ch); in ahci_reset()
2538 ahci_start(ch, 1); in ahci_reset()
2539 xpt_release_simq(ch->sim, TRUE); in ahci_reset()
2544 ahci_setup_fis(struct ahci_channel *ch, struct ahci_cmd_tab *ctp, union ccb *ccb, int tag) in ahci_setup_fis() argument
2555 ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA) in ahci_setup_fis()
2601 ahci_sata_connect(struct ahci_channel *ch) in ahci_sata_connect() argument
2610 timeoutslot = ((ch->quirks & AHCI_Q_SLOWDEV) ? 5000 : 1000); in ahci_sata_connect()
2612 status = ATA_INL(ch->r_mem, AHCI_P_SSTS); in ahci_sata_connect()
2621 device_printf(ch->dev, "SATA offline status=%08x\n", in ahci_sata_connect()
2632 device_printf(ch->dev, in ahci_sata_connect()
2639 device_printf(ch->dev, "SATA connect time=%dus status=%08x\n", in ahci_sata_connect()
2643 ATA_OUTL(ch->r_mem, AHCI_P_SERR, 0xffffffff); in ahci_sata_connect()
2648 ahci_sata_phy_reset(struct ahci_channel *ch) in ahci_sata_phy_reset() argument
2653 if (ch->listening) { in ahci_sata_phy_reset()
2654 val = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_sata_phy_reset()
2656 ATA_OUTL(ch->r_mem, AHCI_P_CMD, val); in ahci_sata_phy_reset()
2657 ch->listening = 0; in ahci_sata_phy_reset()
2659 sata_rev = ch->user[ch->pm_present ? 15 : 0].revision; in ahci_sata_phy_reset()
2668 detval = ahci_ch_detval(ch, ATA_SC_DET_RESET); in ahci_sata_phy_reset()
2669 ATA_OUTL(ch->r_mem, AHCI_P_SCTL, in ahci_sata_phy_reset()
2673 detval = ahci_ch_detval(ch, ATA_SC_DET_IDLE); in ahci_sata_phy_reset()
2674 ATA_OUTL(ch->r_mem, AHCI_P_SCTL, in ahci_sata_phy_reset()
2675 detval | val | ((ch->pm_level > 0) ? 0 : in ahci_sata_phy_reset()
2677 if (!ahci_sata_connect(ch)) { in ahci_sata_phy_reset()
2678 if (ch->caps & AHCI_CAP_SSS) { in ahci_sata_phy_reset()
2679 val = ATA_INL(ch->r_mem, AHCI_P_CMD); in ahci_sata_phy_reset()
2681 ATA_OUTL(ch->r_mem, AHCI_P_CMD, val); in ahci_sata_phy_reset()
2682 ch->listening = 1; in ahci_sata_phy_reset()
2683 } else if (ch->pm_level > 0) in ahci_sata_phy_reset()
2684 ATA_OUTL(ch->r_mem, AHCI_P_SCTL, ATA_SC_DET_DISABLE); in ahci_sata_phy_reset()
2691 ahci_check_ids(struct ahci_channel *ch, union ccb *ccb) in ahci_check_ids() argument
2694 if (ccb->ccb_h.target_id > ((ch->caps & AHCI_CAP_SPM) ? 15 : 0)) { in ahci_check_ids()
2696 ahci_done(ch, ccb); in ahci_check_ids()
2701 ahci_done(ch, ccb); in ahci_check_ids()
2710 struct ahci_channel *ch; in ahciaction() local
2715 ch = (struct ahci_channel *)cam_sim_softc(sim); in ahciaction()
2720 if (ahci_check_ids(ch, ccb)) in ahciaction()
2722 if (ch->devices == 0 || in ahciaction()
2723 (ch->pm_present == 0 && in ahciaction()
2730 if (ahci_check_collision(ch, ccb)) { in ahciaction()
2732 ch->frozen = ccb; in ahciaction()
2734 xpt_freeze_simq(ch->sim, 1); in ahciaction()
2737 ahci_begin_transaction(ch, ccb); in ahciaction()
2748 if (ahci_check_ids(ch, ccb)) in ahciaction()
2751 d = &ch->curr[ccb->ccb_h.target_id]; in ahciaction()
2753 d = &ch->user[ccb->ccb_h.target_id]; in ahciaction()
2761 d->tags = min(ch->numslots, cts->xport_specific.sata.tags); in ahciaction()
2763 ch->pm_present = cts->xport_specific.sata.pm_present; in ahciaction()
2778 if (ahci_check_ids(ch, ccb)) in ahciaction()
2781 d = &ch->curr[ccb->ccb_h.target_id]; in ahciaction()
2783 d = &ch->user[ccb->ccb_h.target_id]; in ahciaction()
2792 (ccb->ccb_h.target_id == 0 && !ch->pm_present))) { in ahciaction()
2793 status = ATA_INL(ch->r_mem, AHCI_P_SSTS) & ATA_SS_SPD_MASK; in ahciaction()
2801 if (ch->pm_level) { in ahciaction()
2802 if (ch->caps & (AHCI_CAP_PSC | AHCI_CAP_SSC)) in ahciaction()
2804 if (ch->caps2 & AHCI_CAP2_APST) in ahciaction()
2807 if ((ch->caps & AHCI_CAP_SNCQ) && in ahciaction()
2808 (ch->quirks & AHCI_Q_NOAA) == 0) in ahciaction()
2812 ch->user[ccb->ccb_h.target_id].caps; in ahciaction()
2824 cts->xport_specific.sata.pm_present = ch->pm_present; in ahciaction()
2835 ahci_reset(ch); in ahciaction()
2848 if (ch->caps & AHCI_CAP_SNCQ) in ahciaction()
2850 if (ch->caps & AHCI_CAP_SPM) in ahciaction()
2854 if ((ch->quirks & AHCI_Q_NOAUX) == 0) in ahciaction()
2857 if (ch->caps & AHCI_CAP_SPM) in ahciaction()
2875 if (ch->quirks & AHCI_Q_MAXIO_64K) in ahciaction()
2877 cpi->hba_vendor = ch->vendorid; in ahciaction()
2878 cpi->hba_device = ch->deviceid; in ahciaction()
2879 cpi->hba_subvendor = ch->subvendorid; in ahciaction()
2880 cpi->hba_subdevice = ch->subdeviceid; in ahciaction()
2888 ahci_done(ch, ccb); in ahciaction()
2894 struct ahci_channel *ch = (struct ahci_channel *)cam_sim_softc(sim); in ahcipoll() local
2898 istatus = ATA_INL(ch->r_mem, AHCI_P_IS); in ahcipoll()
2900 ahci_ch_intr_main(ch, istatus); in ahcipoll()
2901 if (ch->resetting != 0 && in ahcipoll()
2902 (--ch->resetpolldiv <= 0 || !callout_pending(&ch->reset_timer))) { in ahcipoll()
2903 ch->resetpolldiv = 1000; in ahcipoll()
2904 ahci_reset_to(ch); in ahcipoll()