Lines Matching +full:fis +full:- +full:based

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2015-2016 Alexander Motin <mav@FreeBSD.org>
70 FIS_TYPE_REGH2D = 0x27, /* Register FIS - host to device */
71 FIS_TYPE_REGD2H = 0x34, /* Register FIS - device to host */
72 FIS_TYPE_DMAACT = 0x39, /* DMA activate FIS - device to host */
73 FIS_TYPE_DMASETUP = 0x41, /* DMA setup FIS - bidirectional */
74 FIS_TYPE_DATA = 0x46, /* Data FIS - bidirectional */
75 FIS_TYPE_BIST = 0x58, /* BIST activate FIS - bidirectional */
76 FIS_TYPE_PIOSETUP = 0x5F, /* PIO setup FIS - device to host */
77 FIS_TYPE_SETDEVBITS = 0xA1, /* Set dev bits FIS - device to host */
215 #define ahci_ctx(sc) ((sc)->asc_pi->pi_vmctx)
235 struct pci_devinst *pi = sc->asc_pi; in ahci_generate_intr()
241 for (i = 0; i < sc->ports; i++) { in ahci_generate_intr()
242 p = &sc->port[i]; in ahci_generate_intr()
243 if (p->is & p->ie) in ahci_generate_intr()
244 sc->is |= (1 << i); in ahci_generate_intr()
246 DPRINTF("%s(%08x) %08x", __func__, mask, sc->is); in ahci_generate_intr()
248 /* If there is nothing enabled -- clear legacy interrupt and exit. */ in ahci_generate_intr()
249 if (sc->is == 0 || (sc->ghc & AHCI_GHC_IE) == 0) { in ahci_generate_intr()
250 if (sc->lintr) { in ahci_generate_intr()
252 sc->lintr = 0; in ahci_generate_intr()
257 /* If there is anything and no MSI -- assert legacy interrupt. */ in ahci_generate_intr()
260 if (!sc->lintr) { in ahci_generate_intr()
261 sc->lintr = 1; in ahci_generate_intr()
269 if (sc->ports <= nmsg || i < nmsg - 1) in ahci_generate_intr()
273 if (sc->is & mask && mmask & mask) in ahci_generate_intr()
284 struct pci_ahci_softc *sc = p->pr_sc; in ahci_port_intr()
285 struct pci_devinst *pi = sc->asc_pi; in ahci_port_intr()
289 p->port, p->is, p->ie, sc->is); in ahci_port_intr()
291 /* If there is nothing enabled -- we are done. */ in ahci_port_intr()
292 if ((p->is & p->ie) == 0) in ahci_port_intr()
295 /* In case of non-shared MSI always generate interrupt. */ in ahci_port_intr()
297 if (sc->ports <= nmsg || p->port < nmsg - 1) { in ahci_port_intr()
298 sc->is |= (1 << p->port); in ahci_port_intr()
299 if ((sc->ghc & AHCI_GHC_IE) == 0) in ahci_port_intr()
301 pci_generate_msi(pi, p->port); in ahci_port_intr()
305 /* If IS for this port is already set -- do nothing. */ in ahci_port_intr()
306 if (sc->is & (1 << p->port)) in ahci_port_intr()
309 sc->is |= (1 << p->port); in ahci_port_intr()
311 /* If interrupts are enabled -- generate one. */ in ahci_port_intr()
312 if ((sc->ghc & AHCI_GHC_IE) == 0) in ahci_port_intr()
315 pci_generate_msi(pi, nmsg - 1); in ahci_port_intr()
316 } else if (!sc->lintr) { in ahci_port_intr()
317 sc->lintr = 1; in ahci_port_intr()
323 ahci_write_fis(struct ahci_port *p, enum sata_fis_type ft, uint8_t *fis) in ahci_write_fis() argument
327 if (p->rfis == NULL || !(p->cmd & AHCI_P_CMD_FRE)) in ahci_write_fis()
334 irq = (fis[1] & (1 << 6)) ? AHCI_P_IX_DHR : 0; in ahci_write_fis()
339 irq = (fis[1] & (1 << 6)) ? AHCI_P_IX_SDB : 0; in ahci_write_fis()
344 irq = (fis[1] & (1 << 6)) ? AHCI_P_IX_PS : 0; in ahci_write_fis()
347 EPRINTLN("unsupported fis type %d", ft); in ahci_write_fis()
350 if (fis[2] & ATA_S_ERROR) { in ahci_write_fis()
351 p->waitforclear = 1; in ahci_write_fis()
354 memcpy(p->rfis + offset, fis, len); in ahci_write_fis()
356 if (~p->is & irq) { in ahci_write_fis()
357 p->is |= irq; in ahci_write_fis()
366 uint8_t fis[20]; in ahci_write_fis_piosetup() local
368 memset(fis, 0, sizeof(fis)); in ahci_write_fis_piosetup()
369 fis[0] = FIS_TYPE_PIOSETUP; in ahci_write_fis_piosetup()
370 ahci_write_fis(p, FIS_TYPE_PIOSETUP, fis); in ahci_write_fis_piosetup()
376 uint8_t fis[8]; in ahci_write_fis_sdb() local
381 memset(fis, 0, sizeof(fis)); in ahci_write_fis_sdb()
382 fis[0] = FIS_TYPE_SETDEVBITS; in ahci_write_fis_sdb()
383 fis[1] = (1 << 6); in ahci_write_fis_sdb()
384 fis[2] = tfd; in ahci_write_fis_sdb()
385 fis[3] = error; in ahci_write_fis_sdb()
386 if (fis[2] & ATA_S_ERROR) { in ahci_write_fis_sdb()
387 p->err_cfis[0] = slot; in ahci_write_fis_sdb()
388 p->err_cfis[2] = tfd; in ahci_write_fis_sdb()
389 p->err_cfis[3] = error; in ahci_write_fis_sdb()
390 memcpy(&p->err_cfis[4], cfis + 4, 16); in ahci_write_fis_sdb()
392 *(uint32_t *)(fis + 4) = (1 << slot); in ahci_write_fis_sdb()
393 p->sact &= ~(1 << slot); in ahci_write_fis_sdb()
395 p->tfd &= ~0x77; in ahci_write_fis_sdb()
396 p->tfd |= tfd; in ahci_write_fis_sdb()
397 ahci_write_fis(p, FIS_TYPE_SETDEVBITS, fis); in ahci_write_fis_sdb()
403 uint8_t fis[20]; in ahci_write_fis_d2h() local
407 memset(fis, 0, sizeof(fis)); in ahci_write_fis_d2h()
408 fis[0] = FIS_TYPE_REGD2H; in ahci_write_fis_d2h()
409 fis[1] = (1 << 6); in ahci_write_fis_d2h()
410 fis[2] = tfd & 0xff; in ahci_write_fis_d2h()
411 fis[3] = error; in ahci_write_fis_d2h()
412 fis[4] = cfis[4]; in ahci_write_fis_d2h()
413 fis[5] = cfis[5]; in ahci_write_fis_d2h()
414 fis[6] = cfis[6]; in ahci_write_fis_d2h()
415 fis[7] = cfis[7]; in ahci_write_fis_d2h()
416 fis[8] = cfis[8]; in ahci_write_fis_d2h()
417 fis[9] = cfis[9]; in ahci_write_fis_d2h()
418 fis[10] = cfis[10]; in ahci_write_fis_d2h()
419 fis[11] = cfis[11]; in ahci_write_fis_d2h()
420 fis[12] = cfis[12]; in ahci_write_fis_d2h()
421 fis[13] = cfis[13]; in ahci_write_fis_d2h()
422 if (fis[2] & ATA_S_ERROR) { in ahci_write_fis_d2h()
423 p->err_cfis[0] = 0x80; in ahci_write_fis_d2h()
424 p->err_cfis[2] = tfd & 0xff; in ahci_write_fis_d2h()
425 p->err_cfis[3] = error; in ahci_write_fis_d2h()
426 memcpy(&p->err_cfis[4], cfis + 4, 16); in ahci_write_fis_d2h()
428 p->ci &= ~(1 << slot); in ahci_write_fis_d2h()
429 p->tfd = tfd; in ahci_write_fis_d2h()
430 ahci_write_fis(p, FIS_TYPE_REGD2H, fis); in ahci_write_fis_d2h()
436 uint8_t fis[20]; in ahci_write_fis_d2h_ncq() local
438 p->tfd = ATA_S_READY | ATA_S_DSC; in ahci_write_fis_d2h_ncq()
439 memset(fis, 0, sizeof(fis)); in ahci_write_fis_d2h_ncq()
440 fis[0] = FIS_TYPE_REGD2H; in ahci_write_fis_d2h_ncq()
441 fis[1] = 0; /* No interrupt */ in ahci_write_fis_d2h_ncq()
442 fis[2] = p->tfd; /* Status */ in ahci_write_fis_d2h_ncq()
443 fis[3] = 0; /* No error */ in ahci_write_fis_d2h_ncq()
444 p->ci &= ~(1 << slot); in ahci_write_fis_d2h_ncq()
445 ahci_write_fis(p, FIS_TYPE_REGD2H, fis); in ahci_write_fis_d2h_ncq()
451 uint8_t fis[20]; in ahci_write_reset_fis_d2h() local
453 memset(fis, 0, sizeof(fis)); in ahci_write_reset_fis_d2h()
454 fis[0] = FIS_TYPE_REGD2H; in ahci_write_reset_fis_d2h()
455 fis[3] = 1; in ahci_write_reset_fis_d2h()
456 fis[4] = 1; in ahci_write_reset_fis_d2h()
457 if (p->atapi) { in ahci_write_reset_fis_d2h()
458 fis[5] = 0x14; in ahci_write_reset_fis_d2h()
459 fis[6] = 0xeb; in ahci_write_reset_fis_d2h()
461 fis[12] = 1; in ahci_write_reset_fis_d2h()
462 ahci_write_fis(p, FIS_TYPE_REGD2H, fis); in ahci_write_reset_fis_d2h()
470 * is in-flight, clear the running bit, the current command in ahci_check_stopped()
473 if (!(p->cmd & AHCI_P_CMD_ST)) { in ahci_check_stopped()
474 if (p->pending == 0) { in ahci_check_stopped()
475 p->ccs = 0; in ahci_check_stopped()
476 p->cmd &= ~(AHCI_P_CMD_CR | AHCI_P_CMD_CCS_MASK); in ahci_check_stopped()
477 p->ci = 0; in ahci_check_stopped()
478 p->sact = 0; in ahci_check_stopped()
479 p->waitforclear = 0; in ahci_check_stopped()
492 assert(pthread_mutex_isowned_np(&p->pr_sc->mtx)); in ahci_port_stop()
494 TAILQ_FOREACH(aior, &p->iobhd, io_blist) { in ahci_port_stop()
498 error = blockif_cancel(p->bctx, &aior->io_req); in ahci_port_stop()
502 slot = aior->slot; in ahci_port_stop()
503 cfis = aior->cfis; in ahci_port_stop()
507 p->sact &= ~(1 << slot); /* NCQ */ in ahci_port_stop()
509 p->ci &= ~(1 << slot); in ahci_port_stop()
514 p->pending &= ~(1 << slot); in ahci_port_stop()
519 TAILQ_REMOVE(&p->iobhd, aior, io_blist); in ahci_port_stop()
524 STAILQ_INSERT_TAIL(&p->iofhd, aior, io_flist); in ahci_port_stop()
533 pr->serr = 0; in ahci_port_reset()
534 pr->sact = 0; in ahci_port_reset()
535 pr->xfermode = ATA_UDMA6; in ahci_port_reset()
536 pr->mult_sectors = 128; in ahci_port_reset()
538 if (!pr->bctx) { in ahci_port_reset()
539 pr->ssts = ATA_SS_DET_NO_DEVICE; in ahci_port_reset()
540 pr->sig = 0xFFFFFFFF; in ahci_port_reset()
541 pr->tfd = 0x7F; in ahci_port_reset()
544 pr->ssts = ATA_SS_DET_PHY_ONLINE | ATA_SS_IPM_ACTIVE; in ahci_port_reset()
545 if (pr->sctl & ATA_SC_SPD_MASK) in ahci_port_reset()
546 pr->ssts |= (pr->sctl & ATA_SC_SPD_MASK); in ahci_port_reset()
548 pr->ssts |= ATA_SS_SPD_GEN3; in ahci_port_reset()
549 pr->tfd = (1 << 8) | ATA_S_DSC | ATA_S_DMA; in ahci_port_reset()
550 if (!pr->atapi) { in ahci_port_reset()
551 pr->sig = PxSIG_ATA; in ahci_port_reset()
552 pr->tfd |= ATA_S_READY; in ahci_port_reset()
554 pr->sig = PxSIG_ATAPI; in ahci_port_reset()
563 sc->ghc = AHCI_GHC_AE; in ahci_reset()
564 sc->is = 0; in ahci_reset()
566 if (sc->lintr) { in ahci_reset()
567 pci_lintr_deassert(sc->asc_pi); in ahci_reset()
568 sc->lintr = 0; in ahci_reset()
571 for (i = 0; i < sc->ports; i++) { in ahci_reset()
572 sc->port[i].ie = 0; in ahci_reset()
573 sc->port[i].is = 0; in ahci_reset()
574 sc->port[i].cmd = (AHCI_P_CMD_SUD | AHCI_P_CMD_POD); in ahci_reset()
575 if (sc->port[i].bctx) in ahci_reset()
576 sc->port[i].cmd |= AHCI_P_CMD_CPS; in ahci_reset()
577 sc->port[i].sctl = 0; in ahci_reset()
578 ahci_port_reset(&sc->port[i]); in ahci_reset()
609 * Build up the iovec based on the PRDT, 'done' and 'len'.
615 struct blockif_req *breq = &aior->io_req; in ahci_build_iov()
619 assert(aior->len >= aior->done); in ahci_build_iov()
622 skip = aior->done; in ahci_build_iov()
623 left = aior->len - aior->done; in ahci_build_iov()
627 dbcsz = (prdt->dbc & DBCMASK) + 1; in ahci_build_iov()
630 skip -= dbcsz; in ahci_build_iov()
633 dbcsz -= skip; in ahci_build_iov()
636 breq->br_iov[j].iov_base = paddr_guest2host(ahci_ctx(p->pr_sc), in ahci_build_iov()
637 prdt->dba + skip, dbcsz); in ahci_build_iov()
638 breq->br_iov[j].iov_len = dbcsz; in ahci_build_iov()
640 left -= dbcsz; in ahci_build_iov()
647 extra = todo % blockif_sectsz(p->bctx); in ahci_build_iov()
648 todo -= extra; in ahci_build_iov()
651 if (breq->br_iov[j - 1].iov_len > extra) { in ahci_build_iov()
652 breq->br_iov[j - 1].iov_len -= extra; in ahci_build_iov()
655 extra -= breq->br_iov[j - 1].iov_len; in ahci_build_iov()
656 j--; in ahci_build_iov()
660 breq->br_iovcnt = j; in ahci_build_iov()
661 breq->br_resid = todo; in ahci_build_iov()
662 aior->done += todo; in ahci_build_iov()
663 aior->more = (aior->done < aior->len && i < prdtl); in ahci_build_iov()
678 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in ahci_handle_rw()
720 lba *= blockif_sectsz(p->bctx); in ahci_handle_rw()
721 len *= blockif_sectsz(p->bctx); in ahci_handle_rw()
724 aior = STAILQ_FIRST(&p->iofhd); in ahci_handle_rw()
726 STAILQ_REMOVE_HEAD(&p->iofhd, io_flist); in ahci_handle_rw()
728 aior->cfis = cfis; in ahci_handle_rw()
729 aior->slot = slot; in ahci_handle_rw()
730 aior->len = len; in ahci_handle_rw()
731 aior->done = done; in ahci_handle_rw()
732 aior->readop = readop; in ahci_handle_rw()
733 breq = &aior->io_req; in ahci_handle_rw()
734 breq->br_offset = lba + done; in ahci_handle_rw()
735 ahci_build_iov(p, aior, prdt, hdr->prdtl); in ahci_handle_rw()
737 /* Mark this command in-flight. */ in ahci_handle_rw()
738 p->pending |= 1 << slot; in ahci_handle_rw()
741 TAILQ_INSERT_HEAD(&p->iobhd, aior, io_blist); in ahci_handle_rw()
747 err = blockif_read(p->bctx, breq); in ahci_handle_rw()
749 err = blockif_write(p->bctx, breq); in ahci_handle_rw()
763 aior = STAILQ_FIRST(&p->iofhd); in ahci_handle_flush()
765 STAILQ_REMOVE_HEAD(&p->iofhd, io_flist); in ahci_handle_flush()
766 aior->cfis = cfis; in ahci_handle_flush()
767 aior->slot = slot; in ahci_handle_flush()
768 aior->len = 0; in ahci_handle_flush()
769 aior->done = 0; in ahci_handle_flush()
770 aior->more = 0; in ahci_handle_flush()
771 breq = &aior->io_req; in ahci_handle_flush()
774 * Mark this command in-flight. in ahci_handle_flush()
776 p->pending |= 1 << slot; in ahci_handle_flush()
781 TAILQ_INSERT_HEAD(&p->iobhd, aior, io_blist); in ahci_handle_flush()
783 err = blockif_flush(p->bctx, breq); in ahci_handle_flush()
797 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in read_prdt()
801 for (i = 0; i < hdr->prdtl && len; i++) { in read_prdt()
806 dbcsz = (prdt->dbc & DBCMASK) + 1; in read_prdt()
807 ptr = paddr_guest2host(ahci_ctx(p->pr_sc), prdt->dba, dbcsz); in read_prdt()
810 len -= sublen; in read_prdt()
814 return (size - len); in read_prdt()
908 p->pending &= ~(1 << slot); in ahci_handle_next_trim()
918 aior = STAILQ_FIRST(&p->iofhd); in ahci_handle_next_trim()
920 STAILQ_REMOVE_HEAD(&p->iofhd, io_flist); in ahci_handle_next_trim()
921 aior->cfis = cfis; in ahci_handle_next_trim()
922 aior->slot = slot; in ahci_handle_next_trim()
923 aior->len = len; in ahci_handle_next_trim()
924 aior->done = done; in ahci_handle_next_trim()
925 aior->dsm = buf; in ahci_handle_next_trim()
926 aior->more = (len != done); in ahci_handle_next_trim()
928 breq = &aior->io_req; in ahci_handle_next_trim()
929 breq->br_offset = elba * blockif_sectsz(p->bctx); in ahci_handle_next_trim()
930 breq->br_resid = elen * blockif_sectsz(p->bctx); in ahci_handle_next_trim()
933 * Mark this command in-flight. in ahci_handle_next_trim()
935 p->pending |= 1 << slot; in ahci_handle_next_trim()
940 TAILQ_INSERT_HEAD(&p->iobhd, aior, io_blist); in ahci_handle_next_trim()
945 err = blockif_delete(p->bctx, breq); in ahci_handle_next_trim()
959 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in write_prdt()
963 for (i = 0; i < hdr->prdtl && len; i++) { in write_prdt()
968 dbcsz = (prdt->dbc & DBCMASK) + 1; in write_prdt()
969 ptr = paddr_guest2host(ahci_ctx(p->pr_sc), prdt->dba, dbcsz); in write_prdt()
972 len -= sublen; in write_prdt()
976 hdr->prdbc = size - len; in write_prdt()
985 for (i = 0; i < size - 1; i++) in ahci_checksum()
987 buf[size - 1] = 0x100 - sum; in ahci_checksum()
998 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in ahci_handle_read_log()
999 if (p->atapi || hdr->prdtl == 0 || cfis[5] != 0 || in ahci_handle_read_log()
1008 buf16[0x00] = 1; /* Version -- 1 */ in ahci_handle_read_log()
1009 buf16[0x10] = 1; /* NCQ Command Error Log -- 1 page */ in ahci_handle_read_log()
1010 buf16[0x13] = 1; /* SATA NCQ Send and Receive Log -- 1 page */ in ahci_handle_read_log()
1012 memcpy(buf8, p->err_cfis, sizeof(p->err_cfis)); in ahci_handle_read_log()
1015 if (blockif_candelete(p->bctx) && !blockif_is_ro(p->bctx)) { in ahci_handle_read_log()
1036 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in handle_identify()
1037 if (p->atapi || hdr->prdtl == 0) { in handle_identify()
1042 write_prdt(p, slot, cfis, (void*)&p->ata_ident, sizeof(struct ata_params)); in handle_identify()
1050 struct ata_params* ata_ident = &p->ata_ident; in ata_identify_init()
1053 ata_ident->config = ATA_PROTO_ATAPI | ATA_ATAPI_TYPE_CDROM | in ata_identify_init()
1055 ata_ident->capabilities1 = ATA_SUPPORT_LBA | in ata_identify_init()
1057 ata_ident->capabilities2 = (1 << 14 | 1); in ata_identify_init()
1058 ata_ident->atavalid = ATA_FLAG_64_70 | ATA_FLAG_88; in ata_identify_init()
1059 ata_ident->obsolete62 = 0x3f; in ata_identify_init()
1060 ata_ident->mwdmamodes = 7; in ata_identify_init()
1061 if (p->xfermode & ATA_WDMA0) in ata_identify_init()
1062 ata_ident->mwdmamodes |= (1 << ((p->xfermode & 7) + 8)); in ata_identify_init()
1063 ata_ident->apiomodes = 3; in ata_identify_init()
1064 ata_ident->mwdmamin = 0x0078; in ata_identify_init()
1065 ata_ident->mwdmarec = 0x0078; in ata_identify_init()
1066 ata_ident->pioblind = 0x0078; in ata_identify_init()
1067 ata_ident->pioiordy = 0x0078; in ata_identify_init()
1068 ata_ident->satacapabilities = (ATA_SATA_GEN1 | ATA_SATA_GEN2 | ATA_SATA_GEN3); in ata_identify_init()
1069 ata_ident->satacapabilities2 = ((p->ssts & ATA_SS_SPD_MASK) >> 3); in ata_identify_init()
1070 ata_ident->satasupport = ATA_SUPPORT_NCQ_STREAM; in ata_identify_init()
1071 ata_ident->version_major = 0x3f0; in ata_identify_init()
1072 ata_ident->support.command1 = (ATA_SUPPORT_POWERMGT | ATA_SUPPORT_PACKET | in ata_identify_init()
1074 ata_ident->support.command2 = (1 << 14); in ata_identify_init()
1075 ata_ident->support.extension = (1 << 14); in ata_identify_init()
1076 ata_ident->enabled.command1 = (ATA_SUPPORT_POWERMGT | ATA_SUPPORT_PACKET | in ata_identify_init()
1078 ata_ident->enabled.extension = (1 << 14); in ata_identify_init()
1079 ata_ident->udmamodes = 0x7f; in ata_identify_init()
1080 if (p->xfermode & ATA_UDMA0) in ata_identify_init()
1081 ata_ident->udmamodes |= (1 << ((p->xfermode & 7) + 8)); in ata_identify_init()
1082 ata_ident->transport_major = 0x1020; in ata_identify_init()
1083 ata_ident->integrity = 0x00a5; in ata_identify_init()
1090 ro = blockif_is_ro(p->bctx); in ata_identify_init()
1091 candelete = blockif_candelete(p->bctx); in ata_identify_init()
1092 sectsz = blockif_sectsz(p->bctx); in ata_identify_init()
1093 sectors = blockif_size(p->bctx) / sectsz; in ata_identify_init()
1094 blockif_chs(p->bctx, &cyl, &heads, &sech); in ata_identify_init()
1095 blockif_psectsz(p->bctx, &psectsz, &psectoff); in ata_identify_init()
1096 ata_ident->config = ATA_DRQ_FAST; in ata_identify_init()
1097 ata_ident->cylinders = cyl; in ata_identify_init()
1098 ata_ident->heads = heads; in ata_identify_init()
1099 ata_ident->sectors = sech; in ata_identify_init()
1101 ata_ident->sectors_intr = (0x8000 | 128); in ata_identify_init()
1102 ata_ident->tcg = 0; in ata_identify_init()
1104 ata_ident->capabilities1 = ATA_SUPPORT_DMA | in ata_identify_init()
1106 ata_ident->capabilities2 = (1 << 14); in ata_identify_init()
1107 ata_ident->atavalid = ATA_FLAG_64_70 | ATA_FLAG_88; in ata_identify_init()
1108 if (p->mult_sectors) in ata_identify_init()
1109 ata_ident->multi = (ATA_MULTI_VALID | p->mult_sectors); in ata_identify_init()
1111 ata_ident->lba_size_1 = sectors; in ata_identify_init()
1112 ata_ident->lba_size_2 = (sectors >> 16); in ata_identify_init()
1114 ata_ident->lba_size_1 = 0xffff; in ata_identify_init()
1115 ata_ident->lba_size_2 = 0x0fff; in ata_identify_init()
1117 ata_ident->mwdmamodes = 0x7; in ata_identify_init()
1118 if (p->xfermode & ATA_WDMA0) in ata_identify_init()
1119 ata_ident->mwdmamodes |= (1 << ((p->xfermode & 7) + 8)); in ata_identify_init()
1120 ata_ident->apiomodes = 0x3; in ata_identify_init()
1121 ata_ident->mwdmamin = 0x0078; in ata_identify_init()
1122 ata_ident->mwdmarec = 0x0078; in ata_identify_init()
1123 ata_ident->pioblind = 0x0078; in ata_identify_init()
1124 ata_ident->pioiordy = 0x0078; in ata_identify_init()
1125 ata_ident->support3 = 0; in ata_identify_init()
1126 ata_ident->queue = 31; in ata_identify_init()
1127 ata_ident->satacapabilities = (ATA_SATA_GEN1 | ATA_SATA_GEN2 | ATA_SATA_GEN3 | in ata_identify_init()
1129 ata_ident->satacapabilities2 = (ATA_SUPPORT_RCVSND_FPDMA_QUEUED | in ata_identify_init()
1130 (p->ssts & ATA_SS_SPD_MASK) >> 3); in ata_identify_init()
1131 ata_ident->version_major = 0x3f0; in ata_identify_init()
1132 ata_ident->version_minor = 0x28; in ata_identify_init()
1133 ata_ident->support.command1 = (ATA_SUPPORT_POWERMGT | ATA_SUPPORT_WRITECACHE | in ata_identify_init()
1135 ata_ident->support.command2 = (ATA_SUPPORT_ADDRESS48 | ATA_SUPPORT_FLUSHCACHE | in ata_identify_init()
1137 ata_ident->support.extension = (1 << 14); in ata_identify_init()
1138 ata_ident->enabled.command1 = (ATA_SUPPORT_POWERMGT | ATA_SUPPORT_WRITECACHE | in ata_identify_init()
1140 ata_ident->enabled.command2 = (ATA_SUPPORT_ADDRESS48 | ATA_SUPPORT_FLUSHCACHE | in ata_identify_init()
1142 ata_ident->enabled.extension = (1 << 14); in ata_identify_init()
1143 ata_ident->udmamodes = 0x7f; in ata_identify_init()
1144 if (p->xfermode & ATA_UDMA0) in ata_identify_init()
1145 ata_ident->udmamodes |= (1 << ((p->xfermode & 7) + 8)); in ata_identify_init()
1146 ata_ident->lba_size48_1 = sectors; in ata_identify_init()
1147 ata_ident->lba_size48_2 = (sectors >> 16); in ata_identify_init()
1148 ata_ident->lba_size48_3 = (sectors >> 32); in ata_identify_init()
1149 ata_ident->lba_size48_4 = (sectors >> 48); in ata_identify_init()
1152 ata_ident->support3 |= ATA_SUPPORT_RZAT | ATA_SUPPORT_DRAT; in ata_identify_init()
1153 ata_ident->max_dsm_blocks = 1; in ata_identify_init()
1154 ata_ident->support_dsm = ATA_SUPPORT_DSM_TRIM; in ata_identify_init()
1156 ata_ident->pss = ATA_PSS_VALID_VALUE; in ata_identify_init()
1157 ata_ident->lsalign = 0x4000; in ata_identify_init()
1159 ata_ident->pss |= ATA_PSS_MULTLS; in ata_identify_init()
1160 ata_ident->pss |= ffsl(psectsz / sectsz) - 1; in ata_identify_init()
1161 ata_ident->lsalign |= (psectoff / sectsz); in ata_identify_init()
1164 ata_ident->pss |= ATA_PSS_LSSABOVE512; in ata_identify_init()
1165 ata_ident->lss_1 = sectsz / 2; in ata_identify_init()
1166 ata_ident->lss_2 = ((sectsz / 2) >> 16); in ata_identify_init()
1168 ata_ident->support2 = (ATA_SUPPORT_RWLOGDMAEXT | 1 << 14); in ata_identify_init()
1169 ata_ident->enabled2 = (ATA_SUPPORT_RWLOGDMAEXT | 1 << 14); in ata_identify_init()
1170 ata_ident->transport_major = 0x1020; in ata_identify_init()
1171 ata_ident->integrity = 0x00a5; in ata_identify_init()
1179 if (!p->atapi) { in handle_atapi_identify()
1184 write_prdt(p, slot, cfis, (void *)&p->ata_ident, sizeof(struct ata_params)); in handle_atapi_identify()
1208 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_inquiry()
1209 p->asc = 0x24; in atapi_inquiry()
1210 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_inquiry()
1225 atapi_string(buf + 16, "BHYVE DVD-ROM", 16); in atapi_inquiry()
1243 sectors = blockif_size(p->bctx) / 2048; in atapi_read_capacity()
1244 be32enc(buf, sectors - 1); in atapi_read_capacity()
1274 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_read_toc()
1275 p->asc = 0x24; in atapi_read_toc()
1276 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_read_toc()
1304 sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx); in atapi_read_toc()
1314 size = bp - buf; in atapi_read_toc()
1315 be16enc(buf, size - 2); in atapi_read_toc()
1381 sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx); in atapi_read_toc()
1410 size = bp - buf; in atapi_read_toc()
1411 be16enc(buf, size - 2); in atapi_read_toc()
1423 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_read_toc()
1424 p->asc = 0x24; in atapi_read_toc()
1425 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_read_toc()
1459 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in atapi_read()
1477 aior = STAILQ_FIRST(&p->iofhd); in atapi_read()
1479 STAILQ_REMOVE_HEAD(&p->iofhd, io_flist); in atapi_read()
1480 aior->cfis = cfis; in atapi_read()
1481 aior->slot = slot; in atapi_read()
1482 aior->len = len; in atapi_read()
1483 aior->done = done; in atapi_read()
1484 aior->readop = 1; in atapi_read()
1485 breq = &aior->io_req; in atapi_read()
1486 breq->br_offset = lba + done; in atapi_read()
1487 ahci_build_iov(p, aior, prdt, hdr->prdtl); in atapi_read()
1489 /* Mark this command in-flight. */ in atapi_read()
1490 p->pending |= 1 << slot; in atapi_read()
1493 TAILQ_INSERT_HEAD(&p->iobhd, aior, io_blist); in atapi_read()
1495 err = blockif_read(p->bctx, breq); in atapi_read()
1512 buf[2] = p->sense_key; in atapi_request_sense()
1514 buf[12] = p->asc; in atapi_request_sense()
1536 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_start_stop_unit()
1537 p->asc = 0x53; in atapi_start_stop_unit()
1538 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_start_stop_unit()
1568 be16enc(buf, 16 - 2); in atapi_mode_sense()
1571 buf[9] = 16 - 10; in atapi_mode_sense()
1585 be16enc(buf, 30 - 2); in atapi_mode_sense()
1588 buf[9] = 30 - 10; in atapi_mode_sense()
1603 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_mode_sense()
1604 p->asc = 0x39; in atapi_mode_sense()
1605 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_mode_sense()
1610 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_mode_sense()
1611 p->asc = 0x24; in atapi_mode_sense()
1612 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_mode_sense()
1630 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_get_event_status_notification()
1631 p->asc = 0x24; in atapi_get_event_status_notification()
1632 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_get_event_status_notification()
1642 be16enc(buf, 8 - 2); in atapi_get_event_status_notification()
1710 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in handle_packet_cmd()
1711 p->asc = 0x20; in handle_packet_cmd()
1712 ahci_write_fis_d2h(p, slot, cfis, (p->sense_key << 12) | in handle_packet_cmd()
1722 p->tfd |= ATA_S_BUSY; in ahci_handle_cmd()
1733 p->tfd = ATA_S_DSC | ATA_S_READY; in ahci_handle_cmd()
1736 p->tfd = ATA_S_ERROR | ATA_S_READY; in ahci_handle_cmd()
1737 p->tfd |= (ATA_ERROR_ABORT << 8); in ahci_handle_cmd()
1745 p->tfd = ATA_S_DSC | ATA_S_READY; in ahci_handle_cmd()
1755 p->xfermode = (cfis[12] & 0x7); in ahci_handle_cmd()
1758 p->tfd = ATA_S_DSC | ATA_S_READY; in ahci_handle_cmd()
1762 p->tfd = ATA_S_ERROR | ATA_S_READY; in ahci_handle_cmd()
1763 p->tfd |= (ATA_ERROR_ABORT << 8); in ahci_handle_cmd()
1766 ahci_write_fis_d2h(p, slot, cfis, p->tfd); in ahci_handle_cmd()
1771 (cfis[12] > 128 || (cfis[12] & (cfis[12] - 1)))) { in ahci_handle_cmd()
1772 p->tfd = ATA_S_ERROR | ATA_S_READY; in ahci_handle_cmd()
1773 p->tfd |= (ATA_ERROR_ABORT << 8); in ahci_handle_cmd()
1775 p->mult_sectors = cfis[12]; in ahci_handle_cmd()
1776 p->tfd = ATA_S_DSC | ATA_S_READY; in ahci_handle_cmd()
1778 ahci_write_fis_d2h(p, slot, cfis, p->tfd); in ahci_handle_cmd()
1846 if (!p->atapi) { in ahci_handle_cmd()
1873 sc = p->pr_sc; in ahci_handle_slot()
1874 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in ahci_handle_slot()
1876 cfl = (hdr->flags & 0x1f) * 4; in ahci_handle_slot()
1878 cfis = paddr_guest2host(ahci_ctx(sc), hdr->ctba, in ahci_handle_slot()
1879 0x80 + hdr->prdtl * sizeof(struct ahci_prdt_entry)); in ahci_handle_slot()
1891 for (i = 0; i < hdr->prdtl; i++) { in ahci_handle_slot()
1892 DPRINTF("%d@%08"PRIx64"", prdt->dbc & 0x3fffff, prdt->dba); in ahci_handle_slot()
1898 EPRINTLN("Not a H2D FIS:%02x", cfis[0]); in ahci_handle_slot()
1906 p->reset = 1; in ahci_handle_slot()
1907 else if (p->reset) { in ahci_handle_slot()
1908 p->reset = 0; in ahci_handle_slot()
1911 p->ci &= ~(1 << slot); in ahci_handle_slot()
1919 if (!(p->cmd & AHCI_P_CMD_ST)) in ahci_handle_port()
1924 * are already in-flight. Stop if device is busy or in error. in ahci_handle_port()
1926 for (; (p->ci & ~p->pending) != 0; p->ccs = ((p->ccs + 1) & 31)) { in ahci_handle_port()
1927 if ((p->tfd & (ATA_S_BUSY | ATA_S_DRQ)) != 0) in ahci_handle_port()
1929 if (p->waitforclear) in ahci_handle_port()
1931 if ((p->ci & ~p->pending & (1 << p->ccs)) != 0) { in ahci_handle_port()
1932 p->cmd &= ~AHCI_P_CMD_CCS_MASK; in ahci_handle_port()
1933 p->cmd |= p->ccs << AHCI_P_CMD_CCS_SHIFT; in ahci_handle_port()
1934 ahci_handle_slot(p, p->ccs); in ahci_handle_port()
1940 * blockif callback routine - this runs in the context of the blockif
1957 aior = br->br_param; in ata_ioreq_cb()
1958 p = aior->io_pr; in ata_ioreq_cb()
1959 cfis = aior->cfis; in ata_ioreq_cb()
1960 slot = aior->slot; in ata_ioreq_cb()
1961 sc = p->pr_sc; in ata_ioreq_cb()
1962 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); in ata_ioreq_cb()
1968 dsm = aior->dsm; in ata_ioreq_cb()
1969 aior->dsm = NULL; in ata_ioreq_cb()
1971 pthread_mutex_lock(&sc->mtx); in ata_ioreq_cb()
1976 TAILQ_REMOVE(&p->iobhd, aior, io_blist); in ata_ioreq_cb()
1981 STAILQ_INSERT_TAIL(&p->iofhd, aior, io_flist); in ata_ioreq_cb()
1984 hdr->prdbc = aior->done; in ata_ioreq_cb()
1986 if (!err && aior->more) { in ata_ioreq_cb()
1989 aior->len, aior->done); in ata_ioreq_cb()
1991 ahci_handle_rw(p, slot, cfis, aior->done); in ata_ioreq_cb()
2007 p->pending &= ~(1 << slot); in ata_ioreq_cb()
2013 pthread_mutex_unlock(&sc->mtx); in ata_ioreq_cb()
2030 aior = br->br_param; in atapi_ioreq_cb()
2031 p = aior->io_pr; in atapi_ioreq_cb()
2032 cfis = aior->cfis; in atapi_ioreq_cb()
2033 slot = aior->slot; in atapi_ioreq_cb()
2034 sc = p->pr_sc; in atapi_ioreq_cb()
2035 hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + aior->slot * AHCI_CL_SIZE); in atapi_ioreq_cb()
2037 pthread_mutex_lock(&sc->mtx); in atapi_ioreq_cb()
2042 TAILQ_REMOVE(&p->iobhd, aior, io_blist); in atapi_ioreq_cb()
2047 STAILQ_INSERT_TAIL(&p->iofhd, aior, io_flist); in atapi_ioreq_cb()
2050 hdr->prdbc = aior->done; in atapi_ioreq_cb()
2052 if (!err && aior->more) { in atapi_ioreq_cb()
2053 atapi_read(p, slot, cfis, aior->done); in atapi_ioreq_cb()
2060 p->sense_key = ATA_SENSE_ILLEGAL_REQUEST; in atapi_ioreq_cb()
2061 p->asc = 0x21; in atapi_ioreq_cb()
2062 tfd = (p->sense_key << 12) | ATA_S_READY | ATA_S_ERROR; in atapi_ioreq_cb()
2070 p->pending &= ~(1 << slot); in atapi_ioreq_cb()
2075 pthread_mutex_unlock(&sc->mtx); in atapi_ioreq_cb()
2085 pr->ioqsz = blockif_queuesz(pr->bctx); in pci_ahci_ioreq_init()
2086 pr->ioreq = calloc(pr->ioqsz, sizeof(struct ahci_ioreq)); in pci_ahci_ioreq_init()
2087 STAILQ_INIT(&pr->iofhd); in pci_ahci_ioreq_init()
2092 for (i = 0; i < pr->ioqsz; i++) { in pci_ahci_ioreq_init()
2093 vr = &pr->ioreq[i]; in pci_ahci_ioreq_init()
2094 vr->io_pr = pr; in pci_ahci_ioreq_init()
2095 if (!pr->atapi) in pci_ahci_ioreq_init()
2096 vr->io_req.br_callback = ata_ioreq_cb; in pci_ahci_ioreq_init()
2098 vr->io_req.br_callback = atapi_ioreq_cb; in pci_ahci_ioreq_init()
2099 vr->io_req.br_param = vr; in pci_ahci_ioreq_init()
2100 STAILQ_INSERT_TAIL(&pr->iofhd, vr, io_flist); in pci_ahci_ioreq_init()
2103 TAILQ_INIT(&pr->iobhd); in pci_ahci_ioreq_init()
2109 int port = (offset - AHCI_OFFSET) / AHCI_STEP; in pci_ahci_port_write()
2110 offset = (offset - AHCI_OFFSET) % AHCI_STEP; in pci_ahci_port_write()
2111 struct ahci_port *p = &sc->port[port]; in pci_ahci_port_write()
2118 p->clb = value; in pci_ahci_port_write()
2121 p->clbu = value; in pci_ahci_port_write()
2124 p->fb = value; in pci_ahci_port_write()
2127 p->fbu = value; in pci_ahci_port_write()
2130 p->is &= ~value; in pci_ahci_port_write()
2134 p->ie = value & 0xFDC000FF; in pci_ahci_port_write()
2139 p->cmd &= ~(AHCI_P_CMD_ST | AHCI_P_CMD_SUD | AHCI_P_CMD_POD | in pci_ahci_port_write()
2143 p->cmd |= (AHCI_P_CMD_ST | AHCI_P_CMD_SUD | AHCI_P_CMD_POD | in pci_ahci_port_write()
2153 p->cmd |= AHCI_P_CMD_CR; in pci_ahci_port_write()
2154 clb = (uint64_t)p->clbu << 32 | p->clb; in pci_ahci_port_write()
2155 p->cmd_lst = paddr_guest2host(ahci_ctx(sc), clb, in pci_ahci_port_write()
2162 p->cmd |= AHCI_P_CMD_FR; in pci_ahci_port_write()
2163 fb = (uint64_t)p->fbu << 32 | p->fb; in pci_ahci_port_write()
2165 p->rfis = paddr_guest2host(ahci_ctx(sc), fb, 256); in pci_ahci_port_write()
2167 p->cmd &= ~AHCI_P_CMD_FR; in pci_ahci_port_write()
2171 p->tfd &= ~(ATA_S_BUSY | ATA_S_DRQ); in pci_ahci_port_write()
2172 p->cmd &= ~AHCI_P_CMD_CLO; in pci_ahci_port_write()
2176 p->cmd &= ~AHCI_P_CMD_ICC_MASK; in pci_ahci_port_write()
2188 p->sctl = value; in pci_ahci_port_write()
2189 if (!(p->cmd & AHCI_P_CMD_ST)) { in pci_ahci_port_write()
2195 p->serr &= ~value; in pci_ahci_port_write()
2198 p->sact |= value; in pci_ahci_port_write()
2201 p->ci |= value; in pci_ahci_port_write()
2230 sc->ghc |= AHCI_GHC_IE; in pci_ahci_host_write()
2232 sc->ghc &= ~AHCI_GHC_IE; in pci_ahci_host_write()
2236 sc->is &= ~value; in pci_ahci_host_write()
2248 struct pci_ahci_softc *sc = pi->pi_arg; in pci_ahci_write()
2253 pthread_mutex_lock(&sc->mtx); in pci_ahci_write()
2257 else if (offset < (uint64_t)AHCI_OFFSET + sc->ports * AHCI_STEP) in pci_ahci_write()
2262 pthread_mutex_unlock(&sc->mtx); in pci_ahci_write()
2282 uint32_t *p = &sc->cap; in pci_ahci_host_read()
2283 p += (offset - AHCI_CAP) / sizeof(uint32_t); in pci_ahci_host_read()
2301 int port = (offset - AHCI_OFFSET) / AHCI_STEP; in pci_ahci_port_read()
2302 offset = (offset - AHCI_OFFSET) % AHCI_STEP; in pci_ahci_port_read()
2322 uint32_t *p= &sc->port[port].clb; in pci_ahci_port_read()
2323 p += (offset - AHCI_P_CLB) / sizeof(uint32_t); in pci_ahci_port_read()
2341 struct pci_ahci_softc *sc = pi->pi_arg; in pci_ahci_read()
2347 assert((regoff & (size - 1)) == 0); in pci_ahci_read()
2349 pthread_mutex_lock(&sc->mtx); in pci_ahci_read()
2354 else if (offset < (uint64_t)AHCI_OFFSET + sc->ports * AHCI_STEP) in pci_ahci_read()
2363 pthread_mutex_unlock(&sc->mtx); in pci_ahci_read()
2485 pi->pi_arg = sc; in pci_ahci_init()
2486 sc->asc_pi = pi; in pci_ahci_init()
2487 pthread_mutex_init(&sc->mtx, NULL); in pci_ahci_init()
2488 sc->ports = 0; in pci_ahci_init()
2489 sc->pi = 0; in pci_ahci_init()
2494 struct ata_params *ata_ident = &sc->port[p].ata_ident; in pci_ahci_init()
2515 snprintf(bident, sizeof(bident), "%u:%u:%u", pi->pi_slot, in pci_ahci_init()
2516 pi->pi_func, p); in pci_ahci_init()
2520 sc->ports = p; in pci_ahci_init()
2527 sc->ports = p; in pci_ahci_init()
2531 sc->port[p].bctx = bctxt; in pci_ahci_init()
2532 sc->port[p].pr_sc = sc; in pci_ahci_init()
2533 sc->port[p].port = p; in pci_ahci_init()
2534 sc->port[p].atapi = atapi; in pci_ahci_init()
2545 "BHYVE-%02X%02X-%02X%02X-%02X%02X", in pci_ahci_init()
2550 ata_string((uint8_t*)&ata_ident->serial, ident, 20); in pci_ahci_init()
2551 ata_string((uint8_t*)&ata_ident->revision, "001", 8); in pci_ahci_init()
2553 ata_string((uint8_t*)&ata_ident->model, "BHYVE SATA DVD ROM", 40); in pci_ahci_init()
2555 ata_string((uint8_t*)&ata_ident->model, "BHYVE SATA DISK", 40); in pci_ahci_init()
2558 ata_ident->media_rotation_rate = atoi(value); in pci_ahci_init()
2561 ata_string((uint8_t*)(&ata_ident->serial), value, 20); in pci_ahci_init()
2564 ata_string((uint8_t*)(&ata_ident->revision), value, 8); in pci_ahci_init()
2567 ata_string((uint8_t*)(&ata_ident->model), value, 40); in pci_ahci_init()
2568 ata_identify_init(&sc->port[p], atapi); in pci_ahci_init()
2574 pci_ahci_ioreq_init(&sc->port[p]); in pci_ahci_init()
2576 sc->pi |= (1 << p); in pci_ahci_init()
2577 if (sc->port[p].ioqsz < slots) in pci_ahci_init()
2578 slots = sc->port[p].ioqsz; in pci_ahci_init()
2580 sc->ports = p; in pci_ahci_init()
2583 --slots; in pci_ahci_init()
2584 if (sc->ports < DEF_PORTS) in pci_ahci_init()
2585 sc->ports = DEF_PORTS; in pci_ahci_init()
2586 sc->cap = AHCI_CAP_64BIT | AHCI_CAP_SNCQ | AHCI_CAP_SSNTF | in pci_ahci_init()
2590 (slots << AHCI_CAP_NCS_SHIFT) | AHCI_CAP_SXS | (sc->ports - 1); in pci_ahci_init()
2592 sc->vs = 0x10300; in pci_ahci_init()
2593 sc->cap2 = AHCI_CAP2_APST; in pci_ahci_init()
2601 p = MIN(sc->ports, 16); in pci_ahci_init()
2602 p = flsl(p) - ((p & (p - 1)) ? 0 : 1); in pci_ahci_init()
2605 AHCI_OFFSET + sc->ports * AHCI_STEP); in pci_ahci_init()
2611 for (p = 0; p < sc->ports; p++) { in pci_ahci_init()
2612 if (sc->port[p].bctx != NULL) in pci_ahci_init()
2613 blockif_close(sc->port[p].bctx); in pci_ahci_init()
2631 pi = meta->dev_data; in pci_ahci_snapshot()
2632 sc = pi->pi_arg; in pci_ahci_snapshot()
2636 SNAPSHOT_VAR_OR_LEAVE(sc->ports, meta, ret, done); in pci_ahci_snapshot()
2637 SNAPSHOT_VAR_OR_LEAVE(sc->cap, meta, ret, done); in pci_ahci_snapshot()
2638 SNAPSHOT_VAR_OR_LEAVE(sc->ghc, meta, ret, done); in pci_ahci_snapshot()
2639 SNAPSHOT_VAR_OR_LEAVE(sc->is, meta, ret, done); in pci_ahci_snapshot()
2640 SNAPSHOT_VAR_OR_LEAVE(sc->pi, meta, ret, done); in pci_ahci_snapshot()
2641 SNAPSHOT_VAR_OR_LEAVE(sc->vs, meta, ret, done); in pci_ahci_snapshot()
2642 SNAPSHOT_VAR_OR_LEAVE(sc->ccc_ctl, meta, ret, done); in pci_ahci_snapshot()
2643 SNAPSHOT_VAR_OR_LEAVE(sc->ccc_pts, meta, ret, done); in pci_ahci_snapshot()
2644 SNAPSHOT_VAR_OR_LEAVE(sc->em_loc, meta, ret, done); in pci_ahci_snapshot()
2645 SNAPSHOT_VAR_OR_LEAVE(sc->em_ctl, meta, ret, done); in pci_ahci_snapshot()
2646 SNAPSHOT_VAR_OR_LEAVE(sc->cap2, meta, ret, done); in pci_ahci_snapshot()
2647 SNAPSHOT_VAR_OR_LEAVE(sc->bohc, meta, ret, done); in pci_ahci_snapshot()
2648 SNAPSHOT_VAR_OR_LEAVE(sc->lintr, meta, ret, done); in pci_ahci_snapshot()
2651 port = &sc->port[i]; in pci_ahci_snapshot()
2653 if (meta->op == VM_SNAPSHOT_SAVE) in pci_ahci_snapshot()
2654 bctx = port->bctx; in pci_ahci_snapshot()
2657 SNAPSHOT_VAR_OR_LEAVE(port->port, meta, ret, done); in pci_ahci_snapshot()
2660 if (((bctx == NULL) && (port->bctx != NULL)) || in pci_ahci_snapshot()
2661 ((bctx != NULL) && (port->bctx == NULL))) { in pci_ahci_snapshot()
2667 if (port->bctx == NULL) in pci_ahci_snapshot()
2670 if (port->port != i) { in pci_ahci_snapshot()
2672 "actual: %d expected: %d", __func__, port->port, i); in pci_ahci_snapshot()
2677 SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(pi->pi_vmctx, port->cmd_lst, in pci_ahci_snapshot()
2679 SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(pi->pi_vmctx, port->rfis, 256, in pci_ahci_snapshot()
2682 SNAPSHOT_VAR_OR_LEAVE(port->ata_ident, meta, ret, done); in pci_ahci_snapshot()
2683 SNAPSHOT_VAR_OR_LEAVE(port->atapi, meta, ret, done); in pci_ahci_snapshot()
2684 SNAPSHOT_VAR_OR_LEAVE(port->reset, meta, ret, done); in pci_ahci_snapshot()
2685 SNAPSHOT_VAR_OR_LEAVE(port->waitforclear, meta, ret, done); in pci_ahci_snapshot()
2686 SNAPSHOT_VAR_OR_LEAVE(port->mult_sectors, meta, ret, done); in pci_ahci_snapshot()
2687 SNAPSHOT_VAR_OR_LEAVE(port->xfermode, meta, ret, done); in pci_ahci_snapshot()
2688 SNAPSHOT_VAR_OR_LEAVE(port->err_cfis, meta, ret, done); in pci_ahci_snapshot()
2689 SNAPSHOT_VAR_OR_LEAVE(port->sense_key, meta, ret, done); in pci_ahci_snapshot()
2690 SNAPSHOT_VAR_OR_LEAVE(port->asc, meta, ret, done); in pci_ahci_snapshot()
2691 SNAPSHOT_VAR_OR_LEAVE(port->ccs, meta, ret, done); in pci_ahci_snapshot()
2692 SNAPSHOT_VAR_OR_LEAVE(port->pending, meta, ret, done); in pci_ahci_snapshot()
2694 SNAPSHOT_VAR_OR_LEAVE(port->clb, meta, ret, done); in pci_ahci_snapshot()
2695 SNAPSHOT_VAR_OR_LEAVE(port->clbu, meta, ret, done); in pci_ahci_snapshot()
2696 SNAPSHOT_VAR_OR_LEAVE(port->fb, meta, ret, done); in pci_ahci_snapshot()
2697 SNAPSHOT_VAR_OR_LEAVE(port->fbu, meta, ret, done); in pci_ahci_snapshot()
2698 SNAPSHOT_VAR_OR_LEAVE(port->ie, meta, ret, done); in pci_ahci_snapshot()
2699 SNAPSHOT_VAR_OR_LEAVE(port->cmd, meta, ret, done); in pci_ahci_snapshot()
2700 SNAPSHOT_VAR_OR_LEAVE(port->unused0, meta, ret, done); in pci_ahci_snapshot()
2701 SNAPSHOT_VAR_OR_LEAVE(port->tfd, meta, ret, done); in pci_ahci_snapshot()
2702 SNAPSHOT_VAR_OR_LEAVE(port->sig, meta, ret, done); in pci_ahci_snapshot()
2703 SNAPSHOT_VAR_OR_LEAVE(port->ssts, meta, ret, done); in pci_ahci_snapshot()
2704 SNAPSHOT_VAR_OR_LEAVE(port->sctl, meta, ret, done); in pci_ahci_snapshot()
2705 SNAPSHOT_VAR_OR_LEAVE(port->serr, meta, ret, done); in pci_ahci_snapshot()
2706 SNAPSHOT_VAR_OR_LEAVE(port->sact, meta, ret, done); in pci_ahci_snapshot()
2707 SNAPSHOT_VAR_OR_LEAVE(port->ci, meta, ret, done); in pci_ahci_snapshot()
2708 SNAPSHOT_VAR_OR_LEAVE(port->sntf, meta, ret, done); in pci_ahci_snapshot()
2709 SNAPSHOT_VAR_OR_LEAVE(port->fbs, meta, ret, done); in pci_ahci_snapshot()
2710 SNAPSHOT_VAR_OR_LEAVE(port->ioqsz, meta, ret, done); in pci_ahci_snapshot()
2712 assert(TAILQ_EMPTY(&port->iobhd)); in pci_ahci_snapshot()
2726 sc = pi->pi_arg; in pci_ahci_pause()
2729 bctxt = sc->port[i].bctx; in pci_ahci_pause()
2746 sc = pi->pi_arg; in pci_ahci_resume()
2749 bctxt = sc->port[i].bctx; in pci_ahci_resume()
2778 .pe_emu = "ahci-hd",
2785 .pe_emu = "ahci-cd",