@@ -161,6 +161,22 @@ static void nvme_irq_deassert(NvmeCtrl *n, NvmeCQueue *cq)
}
}
+static void nvme_set_error_page(NvmeCtrl *n, uint16_t sqid, uint16_t cid,
+ uint16_t status, uint16_t location, uint64_t lba, uint32_t nsid)
+{
+ NvmeErrorLog *elp;
+
+ elp = &n->elpes[n->elp_index];
+ elp->error_count = n->error_count++;
+ elp->sqid = sqid;
+ elp->cid = cid;
+ elp->status_field = status;
+ elp->param_error_location = location;
+ elp->lba = lba;
+ elp->nsid = nsid;
+ n->elp_index = (n->elp_index + 1) % n->params.elpe;
+}
+
static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
uint64_t prp2, uint32_t len, NvmeCtrl *n)
{
@@ -386,7 +402,9 @@ static void nvme_rw_cb(void *opaque, int ret)
req->status = NVME_SUCCESS;
} else {
block_acct_failed(blk_get_stats(n->conf.blk), &req->acct);
- req->status = NVME_INTERNAL_DEV_ERROR;
+ nvme_set_error_page(n, sq->sqid, cpu_to_le16(req->cid),
+ NVME_INTERNAL_DEV_ERROR, 0, 0, 1);
+ req->status = NVME_INTERNAL_DEV_ERROR | NVME_MORE;
}
if (req->has_sg) {
qemu_sglist_destroy(&req->qsg);
@@ -677,7 +695,7 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, NvmeCmd *cmd, uint8_t rae,
smart.host_read_commands[0] = cpu_to_le64(read_commands);
smart.host_write_commands[0] = cpu_to_le64(write_commands);
- smart.number_of_error_log_entries[0] = cpu_to_le64(0);
+ smart.number_of_error_log_entries[0] = cpu_to_le64(n->error_count);
smart.temperature[0] = n->temperature & 0xff;
smart.temperature[1] = (n->temperature >> 8) & 0xff;
@@ -100,6 +100,8 @@ typedef struct NvmeCtrl {
uint64_t timestamp_set_qemu_clock_ms; /* QEMU clock time */
uint64_t starttime_ms;
uint16_t temperature;
+ uint8_t elp_index;
+ uint64_t error_count;
QEMUTimer *aer_timer;
uint8_t aer_mask;
This adds the nvme_set_error_page function which allows errors to be written to the error information log page. The functionality is largely unused in the device, but with this in place we can at least try to push new contributions to use it. NOTE: In violation of the specification the Error Count field is *not* retained across power off conditions because the device currently has no place to store this kind of persistent state. Cribbed from Keith's qemu-nvme tree. Signed-off-by: Klaus Jensen <k.jensen@samsung.com> --- hw/block/nvme.c | 22 ++++++++++++++++++++-- hw/block/nvme.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-)