Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bhyve/pci_nvme.c
Show First 20 Lines • Show All 1,871 Lines • ▼ Show 20 Lines | if (cmd->cdw11 & NVME_DSM_ATTR_DEALLOCATE) { | ||||
range = calloc(1, NVME_MAX_DSM_TRIM); | range = calloc(1, NVME_MAX_DSM_TRIM); | ||||
if (range == NULL) { | if (range == NULL) { | ||||
pci_nvme_status_genc(status, NVME_SC_INTERNAL_DEVICE_ERROR); | pci_nvme_status_genc(status, NVME_SC_INTERNAL_DEVICE_ERROR); | ||||
goto out; | goto out; | ||||
} | } | ||||
nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, cmd->prp1, cmd->prp2, | nvme_prp_memcpy(sc->nsc_pi->pi_vmctx, cmd->prp1, cmd->prp2, | ||||
(uint8_t *)range, NVME_MAX_DSM_TRIM, NVME_COPY_FROM_PRP); | (uint8_t *)range, NVME_MAX_DSM_TRIM, NVME_COPY_FROM_PRP); | ||||
if ((range[0].starting_lba * sectsz) > nvstore->size) { | |||||
pci_nvme_status_genc(status, NVME_SC_LBA_OUT_OF_RANGE); | |||||
goto out; | |||||
} | |||||
/* | /* | ||||
* If the request is for more than a single range, store | * If the request is for more than a single range, store | ||||
* the ranges in the br_iov. Optimize for the common case | * the ranges in the br_iov. Optimize for the common case | ||||
* of a single range. | * of a single range. | ||||
* | * | ||||
* Note that NVMe Number of Ranges is a zero based value | * Note that NVMe Number of Ranges is a zero based value | ||||
*/ | */ | ||||
nr = cmd->cdw10 & 0xff; | nr = cmd->cdw10 & 0xff; | ||||
req->io_req.br_iovcnt = 0; | req->io_req.br_iovcnt = 0; | ||||
req->io_req.br_offset = range[0].starting_lba * sectsz; | req->io_req.br_offset = range[0].starting_lba * sectsz; | ||||
req->io_req.br_resid = range[0].length * sectsz; | req->io_req.br_resid = range[0].length * sectsz; | ||||
if (nr == 0) { | if (nr == 0) { | ||||
req->io_req.br_callback = pci_nvme_io_done; | req->io_req.br_callback = pci_nvme_io_done; | ||||
} else { | } else { | ||||
struct iovec *iov = req->io_req.br_iov; | struct iovec *iov = req->io_req.br_iov; | ||||
for (r = 0; r <= nr; r++) { | for (r = 0; r <= nr; r++) { | ||||
if ((range[r].starting_lba * sectsz) > nvstore->size) { | |||||
pci_nvme_status_genc(status, NVME_SC_LBA_OUT_OF_RANGE); | |||||
goto out; | |||||
} | |||||
iov[r].iov_base = (void *)(range[r].starting_lba * sectsz); | iov[r].iov_base = (void *)(range[r].starting_lba * sectsz); | ||||
iov[r].iov_len = range[r].length * sectsz; | iov[r].iov_len = range[r].length * sectsz; | ||||
} | } | ||||
req->io_req.br_callback = pci_nvme_dealloc_sm; | req->io_req.br_callback = pci_nvme_dealloc_sm; | ||||
/* | /* | ||||
* Use prev_gpaddr to track the current entry and | * Use prev_gpaddr to track the current entry and | ||||
* prev_size to track the number of entries | * prev_size to track the number of entries | ||||
▲ Show 20 Lines • Show All 614 Lines • Show Last 20 Lines |