Skip to content

Commit e4d3816

Browse files
authored
Merge pull request #480 from CodeConstruct/dev/mi-id-secondary
mi: Add Identify function for secondary controller list
2 parents 901bd0a + 0b2c99d commit e4d3816

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

src/nvme/mi.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,46 @@ static inline int nvme_mi_admin_identify_active_ns_list(nvme_mi_ctrl_t ctrl,
12301230
return nvme_mi_admin_identify(ctrl, &args);
12311231
}
12321232

1233+
/**
1234+
* nvme_mi_admin_identify_secondary_ctrl_list() - Perform an Admin identify for
1235+
* a secondary controller list.
1236+
* @ctrl: Controller to process identify command
1237+
* @nsid: Namespace ID to specify list start
1238+
* @cntid: Controller ID to specify list start
1239+
* @list: List data to populate
1240+
*
1241+
* Perform an Identify command, for the secondary controllers associated with
1242+
* the current primary controller. Only entries with IDs greater than or
1243+
* equal to @cntid are returned.
1244+
*
1245+
* Will return an error if the length of the response data (from the
1246+
* controller) is not a full &NVME_IDENTIFY_DATA_SIZE, so @list will be
1247+
* be fully populated on success.
1248+
*
1249+
* Return: 0 on success, non-zero on failure
1250+
*
1251+
* See: &struct nvme_secondary_ctrl_list
1252+
*/
1253+
static inline int nvme_mi_admin_identify_secondary_ctrl_list(nvme_mi_ctrl_t ctrl,
1254+
__u32 nsid,
1255+
__u16 cntid,
1256+
struct nvme_secondary_ctrl_list *list)
1257+
{
1258+
struct nvme_identify_args args = {
1259+
.result = NULL,
1260+
.data = list,
1261+
.args_size = sizeof(args),
1262+
.cns = NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST,
1263+
.csi = NVME_CSI_NVM,
1264+
.nsid = nsid,
1265+
.cntid = cntid,
1266+
.cns_specific_id = NVME_CNSSPECID_NONE,
1267+
.uuidx = NVME_UUID_NONE,
1268+
};
1269+
1270+
return nvme_mi_admin_identify(ctrl, &args);
1271+
}
1272+
12331273
/**
12341274
* nvme_mi_admin_get_log() - Retrieve log page data from controller
12351275
* @ctrl: Controller to query

test/mi.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,52 @@ static void test_admin_id_nsid_ctrl_list(struct nvme_mi_ep *ep)
11701170
assert(!rc);
11711171
}
11721172

1173+
static int test_admin_id_secondary_ctrl_list_cb(struct nvme_mi_ep *ep,
1174+
struct nvme_mi_req *req,
1175+
struct nvme_mi_resp *resp,
1176+
void *data)
1177+
{
1178+
__u16 cns, ctrlid;
1179+
__u32 nsid;
1180+
__u8 *hdr;
1181+
1182+
hdr = (__u8 *)req->hdr;
1183+
assert(hdr[4] == nvme_admin_identify);
1184+
1185+
assert(req->data_len == 0);
1186+
1187+
cns = hdr[45] << 8 | hdr[44];
1188+
assert(cns == NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST);
1189+
1190+
nsid = hdr[11] << 24 | hdr[10] << 16 | hdr[9] << 8 | hdr[8];
1191+
assert(nsid == 0x01020304);
1192+
1193+
ctrlid = hdr[47] << 8 | hdr[46];
1194+
assert(ctrlid == 5);
1195+
1196+
resp->data_len = sizeof(struct nvme_secondary_ctrl_list);
1197+
test_transport_resp_calc_mic(resp);
1198+
1199+
return 0;
1200+
}
1201+
1202+
static void test_admin_id_secondary_ctrl_list(struct nvme_mi_ep *ep)
1203+
{
1204+
struct nvme_secondary_ctrl_list list;
1205+
nvme_mi_ctrl_t ctrl;
1206+
int rc;
1207+
1208+
test_set_transport_callback(ep, test_admin_id_secondary_ctrl_list_cb,
1209+
NULL);
1210+
1211+
ctrl = nvme_mi_init_ctrl(ep, 5);
1212+
assert(ctrl);
1213+
1214+
rc = nvme_mi_admin_identify_secondary_ctrl_list(ctrl, 0x01020304,
1215+
5, &list);
1216+
assert(!rc);
1217+
}
1218+
11731219
static int test_admin_ns_mgmt_cb(struct nvme_mi_ep *ep,
11741220
struct nvme_mi_req *req,
11751221
struct nvme_mi_resp *resp,
@@ -1522,6 +1568,7 @@ struct test {
15221568
DEFINE_TEST(admin_id_alloc_ns),
15231569
DEFINE_TEST(admin_id_active_ns),
15241570
DEFINE_TEST(admin_id_nsid_ctrl_list),
1571+
DEFINE_TEST(admin_id_secondary_ctrl_list),
15251572
DEFINE_TEST(admin_ns_mgmt_create),
15261573
DEFINE_TEST(admin_ns_mgmt_delete),
15271574
DEFINE_TEST(admin_ns_attach),

0 commit comments

Comments
 (0)