Skip to content

Commit 2cf1526

Browse files
ikegami-tdwsuse
authored andcommitted
util: Add get feature length 2 API to support direction parameter
Since feature identifier 0Dh: host memory buffer length is affected by the direction as mentioned by the issue #1681. Signed-off-by: Tokunori Ikegami <[email protected]> [dwagner: reordered definitions and declerations] Signed-off-by: Daniel Wagner <[email protected]>
1 parent 8cbbfd6 commit 2cf1526

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/libnvme.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LIBNVME_1_2 {
55
nvme_ctrl_get_dhchap_host_key;
66
nvme_ctrl_set_dhchap_host_key;
77
nvmf_get_discovery_wargs;
8+
nvme_get_feature_length2;
89
};
910

1011
LIBNVME_1_1 {

src/nvme/util.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,22 @@ int nvme_get_feature_length(int fid, __u32 cdw11, __u32 *len)
494494
return 0;
495495
}
496496

497+
int nvme_get_feature_length2(int fid, __u32 cdw11, enum nvme_data_tfr dir,
498+
__u32 *len)
499+
{
500+
switch (fid) {
501+
case NVME_FEAT_FID_HOST_MEM_BUF:
502+
if (dir == NVME_DATA_TFR_HOST_TO_CTRL) {
503+
*len = 0;
504+
break;
505+
}
506+
fallthrough;
507+
default:
508+
return nvme_get_feature_length(fid, cdw11, len);
509+
}
510+
return 0;
511+
}
512+
497513
int nvme_get_directive_receive_length(enum nvme_directive_dtype dtype,
498514
enum nvme_directive_receive_doper doper, __u32 *len)
499515
{

src/nvme/util.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
* libnvme utility functions
1818
*/
1919

20+
#if __has_attribute(__fallthrough__)
21+
# define fallthrough __attribute__((__fallthrough__))
22+
#else
23+
# define fallthrough do {} while (0) /* fallthrough */
24+
#endif
25+
2026
/**
2127
* enum nvme_connect_err - nvme connect error codes
2228
* @ENVME_CONNECT_RESOLVE: failed to resolve host
@@ -155,6 +161,37 @@ void nvme_init_copy_range_f1(struct nvme_copy_range_f1 *copy, __u16 *nlbs,
155161
*/
156162
int nvme_get_feature_length(int fid, __u32 cdw11, __u32 *len);
157163

164+
/**
165+
* enum nvme_data_tfr - Data transfer direction of the command
166+
* @NVME_DATA_TFR_NO_DATA_TFR: No data transfer
167+
* @NVME_DATA_TFR_HOST_TO_CTRL: Host to controller
168+
* @NVME_DATA_TFR_CTRL_TO_HOST: Controller to host
169+
* @NVME_DATA_TFR_BIDIRECTIONAL: Bidirectional
170+
*/
171+
enum nvme_data_tfr {
172+
NVME_DATA_TFR_NO_DATA_TFR,
173+
NVME_DATA_TFR_HOST_TO_CTRL,
174+
NVME_DATA_TFR_CTRL_TO_HOST,
175+
NVME_DATA_TFR_BIDIRECTIONAL
176+
};
177+
178+
/**
179+
* nvme_get_feature_length2() - Retreive the command payload length for a
180+
* specific feature identifier
181+
* @fid: Feature identifier, see &enum nvme_features_id.
182+
* @cdw11: The cdw11 value may affect the transfer (only known fid is
183+
* %NVME_FEAT_FID_HOST_ID)
184+
* @dir: Data transfer direction: false - host to controller, true -
185+
* controller to host may affect the transfer (only known fid is
186+
* %NVME_FEAT_FID_HOST_MEM_BUF).
187+
* @len: On success, set to this features payload length in bytes.
188+
*
189+
* Return: 0 on success, -1 with errno set to EINVAL if the function did not
190+
* recognize &fid.
191+
*/
192+
int nvme_get_feature_length2(int fid, __u32 cdw11, enum nvme_data_tfr dir,
193+
__u32 *len);
194+
158195
/**
159196
* nvme_get_directive_receive_length() - Get directive receive length
160197
* @dtype: Directive type, see &enum nvme_directive_dtype

0 commit comments

Comments
 (0)