Skip to content

Commit ae84ed9

Browse files
authored
Merge pull request #539 from jinliangw/master
mi: use correct log page offset
2 parents 5f2d222 + 6662218 commit ae84ed9

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

src/nvme/mi.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,19 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl,
772772
}
773773

774774
/* retrieves a MCTP-messsage-sized chunk of log page data. offset and len are
775-
* specified within the args->data area */
775+
* specified within the args->data area. The `offset` parameter is a relative
776+
* offset to the args->lpo !
777+
*
778+
* What's more, we change the LPO of original command to chunk the request
779+
* message into proper size which is allowed by MI interface. One reason is that
780+
* this option seems to be supported better by devices. For more information
781+
* about this option, please check https://github.com/linux-nvme/libnvme/pull/539
782+
* */
776783
static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl,
777784
const struct nvme_get_log_args *args,
778785
off_t offset, size_t *lenp, bool final)
779786
{
787+
__u64 log_page_offset = args->lpo + offset;
780788
struct nvme_mi_admin_resp_hdr resp_hdr;
781789
struct nvme_mi_admin_req_hdr req_hdr;
782790
struct nvme_mi_resp resp;
@@ -808,17 +816,13 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl,
808816
(args->lid & 0xff));
809817
req_hdr.cdw11 = cpu_to_le32(args->lsi << 16 |
810818
ndw >> 16);
811-
req_hdr.cdw12 = cpu_to_le32(args->lpo & 0xffffffff);
812-
req_hdr.cdw13 = cpu_to_le32(args->lpo >> 32);
819+
req_hdr.cdw12 = cpu_to_le32(log_page_offset & 0xffffffff);
820+
req_hdr.cdw13 = cpu_to_le32(log_page_offset >> 32);
813821
req_hdr.cdw14 = cpu_to_le32(args->csi << 24 |
814822
(args->ot ? 1 : 0) << 23 |
815823
args->uuidx);
816824
req_hdr.flags = 0x1;
817825
req_hdr.dlen = cpu_to_le32(len & 0xffffffff);
818-
if (offset) {
819-
req_hdr.flags |= 0x2;
820-
req_hdr.doff = cpu_to_le32(offset);
821-
}
822826

823827
nvme_mi_calc_req_mic(&req);
824828

@@ -848,6 +852,11 @@ int nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl, struct nvme_get_log_args *args)
848852
return -1;
849853
}
850854

855+
if (args->ot && (args->len > max_xfer_size)) {
856+
errno = EINVAL;
857+
return -1;
858+
}
859+
851860
for (xfer_offset = 0; xfer_offset < args->len;) {
852861
size_t xfered_size, cur_xfer_size = max_xfer_size;
853862
bool final;

test/mi.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@ static int test_admin_get_log_split_cb(struct nvme_mi_ep *ep,
17761776
struct nvme_mi_resp *resp,
17771777
void *data)
17781778
{
1779+
uint32_t log_page_offset_lower;
17791780
struct log_data *ldata = data;
17801781
uint32_t len, off;
17811782
__u8 *rq_hdr;
@@ -1790,19 +1791,25 @@ static int test_admin_get_log_split_cb(struct nvme_mi_ep *ep,
17901791
off = rq_hdr[31] << 24 | rq_hdr[30] << 16 | rq_hdr[29] << 8 | rq_hdr[28];
17911792
len = rq_hdr[35] << 24 | rq_hdr[34] << 16 | rq_hdr[33] << 8 | rq_hdr[32];
17921793

1794+
/* From the MI message's Command Dword 12 */
1795+
log_page_offset_lower = rq_hdr[55] << 24 | rq_hdr[54] << 16 | rq_hdr[53] << 8 | rq_hdr[52];
1796+
17931797
/* we should have a full-sized start and middle, and a short end */
17941798
switch (ldata->n) {
17951799
case 0:
1800+
assert(log_page_offset_lower == 0);
17961801
assert(len == 4096);
17971802
assert(off == 0);
17981803
break;
17991804
case 1:
1805+
assert(log_page_offset_lower == 4096);
18001806
assert(len == 4096);
1801-
assert(off == 4096);
1807+
assert(off == 0);
18021808
break;
18031809
case 2:
1810+
assert(log_page_offset_lower == 8192);
18041811
assert(len == 4);
1805-
assert(off == 4096 * 2);
1812+
assert(off == 0);
18061813
break;
18071814
default:
18081815
assert(0);
@@ -1836,6 +1843,8 @@ static void test_admin_get_log_split(struct nvme_mi_ep *ep)
18361843
args.lid = 1;
18371844
args.log = buf;
18381845
args.len = sizeof(buf);
1846+
args.lpo = 0;
1847+
args.ot = false;
18391848

18401849
rc = nvme_mi_admin_get_log(ctrl, &args);
18411850

0 commit comments

Comments
 (0)