Skip to content

Commit 5fd075c

Browse files
committed
nvmet: implement rotational media information log
Most of the information is stubbed. Supporting these commands is a requirement for supporting rotational media. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 266b652 commit 5fd075c

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

drivers/nvme/host/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5002,6 +5002,7 @@ static inline void _nvme_check_size(void)
50025002
BUILD_BUG_ON(sizeof(struct nvme_lba_range_type) != 64);
50035003
BUILD_BUG_ON(sizeof(struct nvme_smart_log) != 512);
50045004
BUILD_BUG_ON(sizeof(struct nvme_endurance_group_log) != 512);
5005+
BUILD_BUG_ON(sizeof(struct nvme_rotational_media_log) != 512);
50055006
BUILD_BUG_ON(sizeof(struct nvme_dbbuf) != 64);
50065007
BUILD_BUG_ON(sizeof(struct nvme_directive_cmd) != 64);
50075008
BUILD_BUG_ON(sizeof(struct nvme_feat_host_behavior) != 512);

drivers/nvme/target/admin-cmd.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static void nvmet_execute_get_supported_log_pages(struct nvmet_req *req)
9191
logs->lids[NVME_LOG_ENDURANCE_GROUP] = cpu_to_le32(NVME_LIDS_LSUPP);
9292
logs->lids[NVME_LOG_ANA] = cpu_to_le32(NVME_LIDS_LSUPP);
9393
logs->lids[NVME_LOG_FEATURES] = cpu_to_le32(NVME_LIDS_LSUPP);
94+
logs->lids[NVME_LOG_RMI] = cpu_to_le32(NVME_LIDS_LSUPP);
9495
logs->lids[NVME_LOG_RESERVATION] = cpu_to_le32(NVME_LIDS_LSUPP);
9596

9697
status = nvmet_copy_to_sgl(req, 0, logs, sizeof(*logs));
@@ -158,6 +159,45 @@ static u16 nvmet_get_smart_log_all(struct nvmet_req *req,
158159
return NVME_SC_SUCCESS;
159160
}
160161

162+
static void nvmet_execute_get_log_page_rmi(struct nvmet_req *req)
163+
{
164+
struct nvme_rotational_media_log *log;
165+
struct gendisk *disk;
166+
u16 status;
167+
168+
req->cmd->common.nsid = cpu_to_le32(le16_to_cpu(
169+
req->cmd->get_log_page.lsi));
170+
status = nvmet_req_find_ns(req);
171+
if (status)
172+
goto out;
173+
174+
if (!req->ns->bdev || bdev_nonrot(req->ns->bdev)) {
175+
status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
176+
goto out;
177+
}
178+
179+
if (req->transfer_len != sizeof(*log)) {
180+
status = NVME_SC_SGL_INVALID_DATA | NVME_STATUS_DNR;
181+
goto out;
182+
}
183+
184+
log = kzalloc(sizeof(*log), GFP_KERNEL);
185+
if (!log)
186+
goto out;
187+
188+
log->endgid = req->cmd->get_log_page.lsi;
189+
disk = req->ns->bdev->bd_disk;
190+
if (disk && disk->ia_ranges)
191+
log->numa = cpu_to_le16(disk->ia_ranges->nr_ia_ranges);
192+
else
193+
log->numa = cpu_to_le16(1);
194+
195+
status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));
196+
kfree(log);
197+
out:
198+
nvmet_req_complete(req, status);
199+
}
200+
161201
static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)
162202
{
163203
struct nvme_smart_log *log;
@@ -451,6 +491,8 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)
451491
return nvmet_execute_get_log_page_ana(req);
452492
case NVME_LOG_FEATURES:
453493
return nvmet_execute_get_log_page_features(req);
494+
case NVME_LOG_RMI:
495+
return nvmet_execute_get_log_page_rmi(req);
454496
case NVME_LOG_RESERVATION:
455497
return nvmet_execute_get_log_page_resv(req);
456498
}

include/linux/nvme.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,18 @@ struct nvme_endurance_group_log {
642642
__u8 rsvd192[320];
643643
};
644644

645+
struct nvme_rotational_media_log {
646+
__le16 endgid;
647+
__le16 numa;
648+
__le16 nrs;
649+
__u8 rsvd6[2];
650+
__le32 spinc;
651+
__le32 fspinc;
652+
__le32 ldc;
653+
__le32 fldc;
654+
__u8 rsvd24[488];
655+
};
656+
645657
struct nvme_smart_log {
646658
__u8 critical_warning;
647659
__u8 temperature[2];
@@ -1281,6 +1293,7 @@ enum {
12811293
NVME_LOG_ENDURANCE_GROUP = 0x09,
12821294
NVME_LOG_ANA = 0x0c,
12831295
NVME_LOG_FEATURES = 0x12,
1296+
NVME_LOG_RMI = 0x16,
12841297
NVME_LOG_DISC = 0x70,
12851298
NVME_LOG_RESERVATION = 0x80,
12861299
NVME_FWACT_REPL = (0 << 3),
@@ -1435,7 +1448,7 @@ struct nvme_get_log_page_command {
14351448
__u8 lsp; /* upper 4 bits reserved */
14361449
__le16 numdl;
14371450
__le16 numdu;
1438-
__u16 rsvd11;
1451+
__le16 lsi;
14391452
union {
14401453
struct {
14411454
__le32 lpol;

0 commit comments

Comments
 (0)