2121#include "mi.h"
2222#include "private.h"
2323
24- static const int default_timeout = 1000 ; /* milliseconds; endpoints may
25- override */
24+ static const int default_timeout = 1000 ; /* milliseconds; endpoints may override */
2625
2726static bool nvme_mi_probe_enabled_default (void )
2827{
@@ -38,7 +37,8 @@ static bool nvme_mi_probe_enabled_default(void)
3837
3938}
4039
41- /* MI-equivalent of nvme_create_root, but avoids clashing symbol names
40+ /*
41+ * MI-equivalent of nvme_create_root, but avoids clashing symbol names
4242 * when linking against both libnvme and libnvme-mi.
4343 */
4444nvme_root_t nvme_mi_create_root (FILE * fp , int log_level )
@@ -58,8 +58,9 @@ nvme_root_t nvme_mi_create_root(FILE *fp, int log_level)
5858 free (r );
5959 return NULL ;
6060 }
61- } else
61+ } else {
6262 fd = STDERR_FILENO ;
63+ }
6364
6465 r -> log .fd = fd ;
6566 r -> log .level = log_level ;
@@ -119,7 +120,8 @@ static void __nvme_mi_format_mn(struct nvme_id_ctrl *id,
119120 const size_t id_mn_size = sizeof (id -> mn );
120121 int i ;
121122
122- /* A BUILD_ASSERT() would be nice here, but we're not const enough for
123+ /*
124+ * A BUILD_ASSERT() would be nice here, but we're not const enough for
123125 * that
124126 */
125127 if (mn_len <= id_mn_size )
@@ -144,14 +146,16 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep)
144146 struct nvme_mi_ctrl * ctrl ;
145147 int rc ;
146148
147- /* Ensure the probe occurs at most once. This isn't just to mitigate doubling
149+ /*
150+ * Ensure the probe occurs at most once. This isn't just to mitigate doubling
148151 * a linear stream of commands, it also terminates recursion via the
149152 * nvme_mi_submit() call issued by nvme_mi_admin_identify_partial() below.
150153 */
151154 if (ep -> quirks_probed )
152155 return ;
153156
154- /* Mark ep->quirks as valid. Note that for the purpose of quirk probing,
157+ /*
158+ * Mark ep->quirks as valid. Note that for the purpose of quirk probing,
155159 * the quirk probe itself cannot rely on quirks, and so the fact that none are
156160 * yet set is desirable. The request that triggered nvme_mi_submit() will have
157161 * an initialised ep->quirks when we return from the root probe call.
@@ -168,7 +172,8 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep)
168172 if (!ctrl )
169173 return ;
170174
171- /* Do enough of an identify (assuming controller 0) to retrieve
175+ /*
176+ * Do enough of an identify (assuming controller 0) to retrieve
172177 * device and firmware identification information. This gives us the
173178 * following fields in id:
174179 *
@@ -188,14 +193,15 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep)
188193 id_args .csi = NVME_CSI_NVM ;
189194
190195 rc = nvme_mi_admin_identify_partial (ctrl , & id_args , 0 ,
191- offsetof(struct nvme_id_ctrl , rab ));
196+ offsetof(struct nvme_id_ctrl , rab ));
192197 if (rc ) {
193198 nvme_msg (ep -> root , LOG_WARNING ,
194199 "Identify Controller failed, no quirks applied\n" );
195200 goto out_close ;
196201 }
197202
198- /* Samsung MZUL2512: cannot receive commands sent within ~1ms of
203+ /*
204+ * Samsung MZUL2512: cannot receive commands sent within ~1ms of
199205 * the previous response. Set an inter-command delay of 1.2ms for
200206 * a little extra tolerance.
201207 */
@@ -204,7 +210,8 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep)
204210 ep -> inter_command_us = 1200 ;
205211 }
206212
207- /* If we're quirking for the inter-command time, record the last
213+ /*
214+ * If we're quirking for the inter-command time, record the last
208215 * command time now, so we don't conflict with the just-sent identify.
209216 */
210217 if (ep -> quirks & NVME_QUIRK_MIN_INTER_COMMAND_TIME )
@@ -224,6 +231,7 @@ void nvme_mi_ep_probe(struct nvme_mi_ep *ep)
224231}
225232
226233static const int nsec_per_sec = 1000 * 1000 * 1000 ;
234+
227235/* timercmp and timersub, but for struct timespec */
228236#define timespec_cmp (a , b , CMP ) \
229237 (((a)->tv_sec == (b)->tv_sec) \
@@ -531,8 +539,8 @@ static void nvme_mi_admin_init_resp(struct nvme_mi_resp *resp,
531539}
532540
533541static void nvme_mi_control_init_req (struct nvme_mi_req * req ,
534- struct nvme_mi_control_req * control_req ,
535- __u8 opcode , __u16 cpsp )
542+ struct nvme_mi_control_req * control_req , __u8 opcode ,
543+ __u16 cpsp )
536544{
537545 memset (req , 0 , sizeof (* req ));
538546 memset (control_req , 0 , sizeof (* control_req ));
@@ -548,7 +556,7 @@ static void nvme_mi_control_init_req(struct nvme_mi_req *req,
548556}
549557
550558static void nvme_mi_control_init_resp (struct nvme_mi_resp * resp ,
551- struct nvme_mi_control_resp * control_resp )
559+ struct nvme_mi_control_resp * control_resp )
552560{
553561 memset (resp , 0 , sizeof (* resp ));
554562 resp -> hdr = & control_resp -> hdr ;
@@ -562,7 +570,8 @@ static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u32 *result)
562570 __u32 nvme_status ;
563571 __u32 nvme_result ;
564572
565- /* we have a few different sources of "result" here: the status header
573+ /*
574+ * we have a few different sources of "result" here: the status header
566575 * in the MI response, the cdw3 status field, and (command specific)
567576 * return values in cdw0. The latter is returned in the result pointer,
568577 * the former two generate return values here
@@ -574,15 +583,17 @@ static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u32 *result)
574583 }
575584 resp_hdr = (struct nvme_mi_msg_resp * )resp -> hdr ;
576585
577- /* If we have a MI error, we can't be sure there's an admin header
586+ /*
587+ * If we have a MI error, we can't be sure there's an admin header
578588 * following; return just the MI status, with the status type
579589 * indicator of MI.
580590 */
581591 if (resp_hdr -> status )
582592 return resp_hdr -> status |
583593 (NVME_STATUS_TYPE_MI << NVME_STATUS_TYPE_SHIFT );
584594
585- /* We shouldn't hit this, as we'd have an error reported earlier.
595+ /*
596+ * We shouldn't hit this, as we'd have an error reported earlier.
586597 * However, for pointer safety, ensure we have a full admin header
587598 */
588599 if (resp -> hdr_len < sizeof (* admin_hdr )) {
@@ -593,7 +604,8 @@ static int nvme_mi_admin_parse_status(struct nvme_mi_resp *resp, __u32 *result)
593604 admin_hdr = (struct nvme_mi_admin_resp_hdr * )resp -> hdr ;
594605 nvme_result = le32_to_cpu (admin_hdr -> cdw0 );
595606
596- /* Shift down 17 here: the SC starts at bit 17, and the NVME_SC_*
607+ /*
608+ * Shift down 17 here: the SC starts at bit 17, and the NVME_SC_*
597609 * definitions align to this bit (and up). The CRD, MORE and DNR
598610 * bits are defined accordingly (eg., DNR is 0x4000).
599611 */
@@ -638,7 +650,8 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl,
638650 __u32 dlen , doff ;
639651 int rc ;
640652
641- /* length/offset checks. The common _submit() API will do further
653+ /*
654+ * length/offset checks. The common _submit() API will do further
642655 * checking on the message lengths too, so these are kept specific
643656 * to the requirements of the Admin command set
644657 */
@@ -675,8 +688,7 @@ int nvme_mi_admin_xfer(nvme_mi_ctrl_t ctrl,
675688 }
676689
677690 admin_req -> hdr .type = NVME_MI_MSGTYPE_NVME ;
678- admin_req -> hdr .nmp = (NVME_MI_ROR_REQ << 7 ) |
679- (NVME_MI_MT_ADMIN << 3 );
691+ admin_req -> hdr .nmp = (NVME_MI_ROR_REQ << 7 ) | (NVME_MI_MT_ADMIN << 3 );
680692 admin_req -> ctrl_id = cpu_to_le16 (ctrl -> id );
681693 memset (& req , 0 , sizeof (req ));
682694 req .hdr = & admin_req -> hdr ;
@@ -882,8 +894,10 @@ int nvme_mi_admin_identify_partial(nvme_mi_ctrl_t ctrl,
882894 if (rc )
883895 return rc ;
884896
885- /* callers will expect a full response; if the data buffer isn't
886- * fully valid, return an error */
897+ /*
898+ * callers will expect a full response; if the data buffer isn't
899+ * fully valid, return an error
900+ */
887901 if (resp .data_len != size ) {
888902 errno = EPROTO ;
889903 return -1 ;
@@ -915,15 +929,16 @@ int nvme_mi_control(nvme_mi_ep_t ep, __u8 opcode,
915929 return 0 ;
916930}
917931
918- /* retrieves a MCTP-messsage-sized chunk of log page data. offset and len are
932+ /*
933+ * retrieves a MCTP-messsage-sized chunk of log page data. offset and len are
919934 * specified within the args->data area. The `offset` parameter is a relative
920935 * offset to the args->lpo !
921936 *
922937 * What's more, we change the LPO of original command to chunk the request
923938 * message into proper size which is allowed by MI interface. One reason is that
924939 * this option seems to be supported better by devices. For more information
925940 * about this option, please check https://github.com/linux-nvme/libnvme/pull/539
926- * * /
941+ */
927942static int __nvme_mi_admin_get_log (nvme_mi_ctrl_t ctrl ,
928943 const struct nvme_get_log_args * args ,
929944 off_t offset , size_t * lenp , bool final )
@@ -937,8 +952,10 @@ static int __nvme_mi_admin_get_log(nvme_mi_ctrl_t ctrl,
937952 __u32 ndw ;
938953 int rc ;
939954
940- /* MI spec requires that the data length field is less than or equal
941- * to 4096 */
955+ /*
956+ * MI spec requires that the data length field is less than or equal
957+ * to 4096
958+ */
942959 len = * lenp ;
943960 if (!len || len > 4096 || len < 4 ) {
944961 errno = EINVAL ;
@@ -1020,8 +1037,10 @@ int nvme_mi_admin_get_log_page(nvme_mi_ctrl_t ctrl, __u32 xfer_size,
10201037 break ;
10211038
10221039 xfer_offset += xfered_size ;
1023- /* if we returned less data than expected, consider that
1024- * the end of the log page */
1040+ /*
1041+ * if we returned less data than expected, consider that
1042+ * the end of the log page
1043+ */
10251044 if (xfered_size != cur_xfer_size )
10261045 break ;
10271046 }
@@ -1167,7 +1186,6 @@ int nvme_mi_admin_get_ana_log_atomic(nvme_mi_ctrl_t ctrl, bool rgo, bool rae,
11671186int nvme_mi_admin_security_send (nvme_mi_ctrl_t ctrl ,
11681187 struct nvme_security_send_args * args )
11691188{
1170-
11711189 struct nvme_mi_admin_resp_hdr resp_hdr ;
11721190 struct nvme_mi_admin_req_hdr req_hdr ;
11731191 struct nvme_mi_resp resp ;
@@ -1213,7 +1231,6 @@ int nvme_mi_admin_security_send(nvme_mi_ctrl_t ctrl,
12131231int nvme_mi_admin_security_recv (nvme_mi_ctrl_t ctrl ,
12141232 struct nvme_security_receive_args * args )
12151233{
1216-
12171234 struct nvme_mi_admin_resp_hdr resp_hdr ;
12181235 struct nvme_mi_admin_req_hdr req_hdr ;
12191236 struct nvme_mi_resp resp ;
@@ -1378,8 +1395,7 @@ int nvme_mi_admin_ns_mgmt(nvme_mi_ctrl_t ctrl,
13781395 req .data = args -> data ;
13791396 data_len = sizeof (* args -> data );
13801397 }
1381- }
1382- else {
1398+ } else {
13831399 if (args -> ns ) {
13841400 req .data = args -> ns ;
13851401 data_len = sizeof (* args -> ns );
@@ -1624,11 +1640,8 @@ static int nvme_mi_read_data(nvme_mi_ep_t ep, __u32 cdw0,
16241640 return 0 ;
16251641}
16261642
1627- int nvme_mi_mi_xfer (nvme_mi_ep_t ep ,
1628- struct nvme_mi_mi_req_hdr * mi_req ,
1629- size_t req_data_size ,
1630- struct nvme_mi_mi_resp_hdr * mi_resp ,
1631- size_t * resp_data_size )
1643+ int nvme_mi_mi_xfer (nvme_mi_ep_t ep , struct nvme_mi_mi_req_hdr * mi_req , size_t req_data_size ,
1644+ struct nvme_mi_mi_resp_hdr * mi_resp , size_t * resp_data_size )
16321645{
16331646 int rc ;
16341647 struct nvme_mi_req req ;
@@ -1664,8 +1677,7 @@ int nvme_mi_mi_xfer(nvme_mi_ep_t ep,
16641677 }
16651678
16661679 mi_req -> hdr .type = NVME_MI_MSGTYPE_NVME ;
1667- mi_req -> hdr .nmp = (NVME_MI_ROR_REQ << 7 ) |
1668- (NVME_MI_MT_MI << 3 );
1680+ mi_req -> hdr .nmp = (NVME_MI_ROR_REQ << 7 ) | (NVME_MI_MT_MI << 3 );
16691681
16701682 memset (& req , 0 , sizeof (req ));
16711683 req .hdr = & mi_req -> hdr ;
@@ -1739,7 +1751,7 @@ int nvme_mi_mi_read_mi_data_port(nvme_mi_ep_t ep, __u8 portid,
17391751}
17401752
17411753int nvme_mi_mi_read_mi_data_ctrl_list (nvme_mi_ep_t ep , __u8 start_ctrlid ,
1742- struct nvme_ctrl_list * list )
1754+ struct nvme_ctrl_list * list )
17431755{
17441756 size_t len ;
17451757 __u32 cdw0 ;
@@ -1965,26 +1977,25 @@ nvme_mi_ctrl_t nvme_mi_next_ctrl(nvme_mi_ep_t ep, nvme_mi_ctrl_t c)
19651977 return c ? list_next (& ep -> controllers , c , ep_entry ) : NULL ;
19661978}
19671979
1968-
19691980static const char * const mi_status [] = {
1970- [NVME_MI_RESP_MPR ] = "More Processing Required: The command message is in progress and requires more time to complete processing" ,
1971- [NVME_MI_RESP_INTERNAL_ERR ] = "Internal Error: The request message could not be processed due to a vendor-specific error" ,
1972- [NVME_MI_RESP_INVALID_OPCODE ] = "Invalid Command Opcode" ,
1973- [NVME_MI_RESP_INVALID_PARAM ] = "Invalid Parameter" ,
1974- [NVME_MI_RESP_INVALID_CMD_SIZE ] = "Invalid Command Size: The size of the message body of the request was different than expected" ,
1975- [NVME_MI_RESP_INVALID_INPUT_SIZE ] = "Invalid Command Input Data Size: The command requires data and contains too much or too little data" ,
1976- [NVME_MI_RESP_ACCESS_DENIED ] = "Access Denied. Processing prohibited due to a vendor-specific mechanism of the Command and Feature lockdown function" ,
1977- [NVME_MI_RESP_VPD_UPDATES_EXCEEDED ] = "VPD Updates Exceeded" ,
1978- [NVME_MI_RESP_PCIE_INACCESSIBLE ] = "PCIe Inaccessible. The PCIe functionality is not available at this time" ,
1979- [NVME_MI_RESP_MEB_SANITIZED ] = "Management Endpoint Buffer Cleared Due to Sanitize" ,
1980- [NVME_MI_RESP_ENC_SERV_FAILURE ] = "Enclosure Services Failure" ,
1981- [NVME_MI_RESP_ENC_SERV_XFER_FAILURE ] = "Enclosure Services Transfer Failure: Communication with the Enclosure Services Process has failed" ,
1982- [NVME_MI_RESP_ENC_FAILURE ] = "An unrecoverable enclosure failure has been detected by the Enclosuer Services Process" ,
1983- [NVME_MI_RESP_ENC_XFER_REFUSED ] = "Enclosure Services Transfer Refused: The NVM Subsystem or Enclosure Services Process indicated an error or an invalid format in communication" ,
1984- [NVME_MI_RESP_ENC_FUNC_UNSUP ] = "Unsupported Enclosure Function: An SES Send command has been attempted to a simple Subenclosure" ,
1985- [NVME_MI_RESP_ENC_SERV_UNAVAIL ] = "Enclosure Services Unavailable: The NVM Subsystem or Enclosure Services Process has encountered an error but may become available again" ,
1986- [NVME_MI_RESP_ENC_DEGRADED ] = "Enclosure Degraded: A noncritical failure has been detected by the Enclosure Services Process" ,
1987- [NVME_MI_RESP_SANITIZE_IN_PROGRESS ] = "Sanitize In Progress: The requested command is prohibited while a sanitize operation is in progress" ,
1981+ [NVME_MI_RESP_MPR ] = "More Processing Required: The command message is in progress and requires more time to complete processing" ,
1982+ [NVME_MI_RESP_INTERNAL_ERR ] = "Internal Error: The request message could not be processed due to a vendor-specific error" ,
1983+ [NVME_MI_RESP_INVALID_OPCODE ] = "Invalid Command Opcode" ,
1984+ [NVME_MI_RESP_INVALID_PARAM ] = "Invalid Parameter" ,
1985+ [NVME_MI_RESP_INVALID_CMD_SIZE ] = "Invalid Command Size: The size of the message body of the request was different than expected" ,
1986+ [NVME_MI_RESP_INVALID_INPUT_SIZE ] = "Invalid Command Input Data Size: The command requires data and contains too much or too little data" ,
1987+ [NVME_MI_RESP_ACCESS_DENIED ] = "Access Denied. Processing prohibited due to a vendor-specific mechanism of the Command and Feature lockdown function" ,
1988+ [NVME_MI_RESP_VPD_UPDATES_EXCEEDED ] = "VPD Updates Exceeded" ,
1989+ [NVME_MI_RESP_PCIE_INACCESSIBLE ] = "PCIe Inaccessible. The PCIe functionality is not available at this time" ,
1990+ [NVME_MI_RESP_MEB_SANITIZED ] = "Management Endpoint Buffer Cleared Due to Sanitize" ,
1991+ [NVME_MI_RESP_ENC_SERV_FAILURE ] = "Enclosure Services Failure" ,
1992+ [NVME_MI_RESP_ENC_SERV_XFER_FAILURE ] = "Enclosure Services Transfer Failure: Communication with the Enclosure Services Process has failed" ,
1993+ [NVME_MI_RESP_ENC_FAILURE ] = "An unrecoverable enclosure failure has been detected by the Enclosuer Services Process" ,
1994+ [NVME_MI_RESP_ENC_XFER_REFUSED ] = "Enclosure Services Transfer Refused: The NVM Subsystem or Enclosure Services Process indicated an error or an invalid format in communication" ,
1995+ [NVME_MI_RESP_ENC_FUNC_UNSUP ] = "Unsupported Enclosure Function: An SES Send command has been attempted to a simple Subenclosure" ,
1996+ [NVME_MI_RESP_ENC_SERV_UNAVAIL ] = "Enclosure Services Unavailable: The NVM Subsystem or Enclosure Services Process has encountered an error but may become available again" ,
1997+ [NVME_MI_RESP_ENC_DEGRADED ] = "Enclosure Degraded: A noncritical failure has been detected by the Enclosure Services Process" ,
1998+ [NVME_MI_RESP_SANITIZE_IN_PROGRESS ] = "Sanitize In Progress: The requested command is prohibited while a sanitize operation is in progress" ,
19881999};
19892000
19902001/* kept in mi.c while we have a split libnvme/libnvme-mi; consider moving
@@ -1994,7 +2005,7 @@ const char *nvme_mi_status_to_string(int status)
19942005 const char * s = "Unknown status" ;
19952006
19962007 if (status < ARRAY_SIZE (mi_status ) && mi_status [status ])
1997- s = mi_status [status ];
2008+ s = mi_status [status ];
19982009
1999- return s ;
2010+ return s ;
20002011}
0 commit comments