Skip to content

Commit d89a5c6

Browse files
huww98keithbusch
authored andcommitted
nvme: fix status magic numbers
Replaced some magic numbers about SC and SCT with enum and macro. Signed-off-by: Weiwen Hu <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 22f19a5 commit d89a5c6

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

drivers/nvme/host/constants.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static const char * const nvme_statuses[] = {
173173

174174
const char *nvme_get_error_status_str(u16 status)
175175
{
176-
status &= 0x7ff;
176+
status &= NVME_SCT_SC_MASK;
177177
if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status])
178178
return nvme_statuses[status];
179179
return "Unknown";

drivers/nvme/host/core.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
261261

262262
static blk_status_t nvme_error_status(u16 status)
263263
{
264-
switch (status & 0x7ff) {
264+
switch (status & NVME_SCT_SC_MASK) {
265265
case NVME_SC_SUCCESS:
266266
return BLK_STS_OK;
267267
case NVME_SC_CAP_EXCEEDED:
@@ -329,8 +329,8 @@ static void nvme_log_error(struct request *req)
329329
nvme_sect_to_lba(ns->head, blk_rq_pos(req)),
330330
blk_rq_bytes(req) >> ns->head->lba_shift,
331331
nvme_get_error_status_str(nr->status),
332-
nr->status >> 8 & 7, /* Status Code Type */
333-
nr->status & 0xff, /* Status Code */
332+
NVME_SCT(nr->status), /* Status Code Type */
333+
nr->status & NVME_SC_MASK, /* Status Code */
334334
nr->status & NVME_SC_MORE ? "MORE " : "",
335335
nr->status & NVME_SC_DNR ? "DNR " : "");
336336
return;
@@ -341,8 +341,8 @@ static void nvme_log_error(struct request *req)
341341
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
342342
nr->cmd->common.opcode,
343343
nvme_get_error_status_str(nr->status),
344-
nr->status >> 8 & 7, /* Status Code Type */
345-
nr->status & 0xff, /* Status Code */
344+
NVME_SCT(nr->status), /* Status Code Type */
345+
nr->status & NVME_SC_MASK, /* Status Code */
346346
nr->status & NVME_SC_MORE ? "MORE " : "",
347347
nr->status & NVME_SC_DNR ? "DNR " : "");
348348
}
@@ -359,8 +359,8 @@ static void nvme_log_err_passthru(struct request *req)
359359
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
360360
nr->cmd->common.opcode,
361361
nvme_get_error_status_str(nr->status),
362-
nr->status >> 8 & 7, /* Status Code Type */
363-
nr->status & 0xff, /* Status Code */
362+
NVME_SCT(nr->status), /* Status Code Type */
363+
nr->status & NVME_SC_MASK, /* Status Code */
364364
nr->status & NVME_SC_MORE ? "MORE " : "",
365365
nr->status & NVME_SC_DNR ? "DNR " : "",
366366
nr->cmd->common.cdw10,
@@ -388,7 +388,7 @@ static inline enum nvme_disposition nvme_decide_disposition(struct request *req)
388388
nvme_req(req)->retries >= nvme_max_retries)
389389
return COMPLETE;
390390

391-
if ((nvme_req(req)->status & 0x7ff) == NVME_SC_AUTH_REQUIRED)
391+
if ((nvme_req(req)->status & NVME_SCT_SC_MASK) == NVME_SC_AUTH_REQUIRED)
392392
return AUTHENTICATE;
393393

394394
if (req->cmd_flags & REQ_NVME_MPATH) {
@@ -1256,7 +1256,7 @@ EXPORT_SYMBOL_NS_GPL(nvme_passthru_end, NVME_TARGET_PASSTHRU);
12561256

12571257
/*
12581258
* Recommended frequency for KATO commands per NVMe 1.4 section 7.12.1:
1259-
*
1259+
*
12601260
* The host should send Keep Alive commands at half of the Keep Alive Timeout
12611261
* accounting for transport roundtrip times [..].
12621262
*/

drivers/nvme/host/multipath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
8383
void nvme_failover_req(struct request *req)
8484
{
8585
struct nvme_ns *ns = req->q->queuedata;
86-
u16 status = nvme_req(req)->status & 0x7ff;
86+
u16 status = nvme_req(req)->status & NVME_SCT_SC_MASK;
8787
unsigned long flags;
8888
struct bio *bio;
8989

drivers/nvme/host/nvme.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static inline u32 nvme_bytes_to_numd(size_t len)
689689

690690
static inline bool nvme_is_ana_error(u16 status)
691691
{
692-
switch (status & 0x7ff) {
692+
switch (status & NVME_SCT_SC_MASK) {
693693
case NVME_SC_ANA_TRANSITION:
694694
case NVME_SC_ANA_INACCESSIBLE:
695695
case NVME_SC_ANA_PERSISTENT_LOSS:
@@ -702,7 +702,7 @@ static inline bool nvme_is_ana_error(u16 status)
702702
static inline bool nvme_is_path_error(u16 status)
703703
{
704704
/* check for a status code type of 'path related status' */
705-
return (status & 0x700) == 0x300;
705+
return (status & NVME_SCT_MASK) == NVME_SCT_PATH;
706706
}
707707

708708
/*

drivers/nvme/host/pr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static int nvme_status_to_pr_err(int status)
7777
if (nvme_is_path_error(status))
7878
return PR_STS_PATH_FAILED;
7979

80-
switch (status & 0x7ff) {
80+
switch (status & NVME_SCT_SC_MASK) {
8181
case NVME_SC_SUCCESS:
8282
return PR_STS_SUCCESS;
8383
case NVME_SC_RESERVATION_CONFLICT:

include/linux/nvme.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ enum {
18461846
/*
18471847
* Generic Command Status:
18481848
*/
1849+
NVME_SCT_GENERIC = 0x0,
18491850
NVME_SC_SUCCESS = 0x0,
18501851
NVME_SC_INVALID_OPCODE = 0x1,
18511852
NVME_SC_INVALID_FIELD = 0x2,
@@ -1893,6 +1894,7 @@ enum {
18931894
/*
18941895
* Command Specific Status:
18951896
*/
1897+
NVME_SCT_COMMAND_SPECIFIC = 0x100,
18961898
NVME_SC_CQ_INVALID = 0x100,
18971899
NVME_SC_QID_INVALID = 0x101,
18981900
NVME_SC_QUEUE_SIZE = 0x102,
@@ -1966,6 +1968,7 @@ enum {
19661968
/*
19671969
* Media and Data Integrity Errors:
19681970
*/
1971+
NVME_SCT_MEDIA_ERROR = 0x200,
19691972
NVME_SC_WRITE_FAULT = 0x280,
19701973
NVME_SC_READ_ERROR = 0x281,
19711974
NVME_SC_GUARD_CHECK = 0x282,
@@ -1978,6 +1981,7 @@ enum {
19781981
/*
19791982
* Path-related Errors:
19801983
*/
1984+
NVME_SCT_PATH = 0x300,
19811985
NVME_SC_INTERNAL_PATH_ERROR = 0x300,
19821986
NVME_SC_ANA_PERSISTENT_LOSS = 0x301,
19831987
NVME_SC_ANA_INACCESSIBLE = 0x302,
@@ -1986,11 +1990,17 @@ enum {
19861990
NVME_SC_HOST_PATH_ERROR = 0x370,
19871991
NVME_SC_HOST_ABORTED_CMD = 0x371,
19881992

1989-
NVME_SC_CRD = 0x1800,
1993+
NVME_SC_MASK = 0x00ff, /* Status Code */
1994+
NVME_SCT_MASK = 0x0700, /* Status Code Type */
1995+
NVME_SCT_SC_MASK = NVME_SCT_MASK | NVME_SC_MASK,
1996+
1997+
NVME_SC_CRD = 0x1800, /* Command Retry Delayed */
19901998
NVME_SC_MORE = 0x2000,
1991-
NVME_SC_DNR = 0x4000,
1999+
NVME_SC_DNR = 0x4000, /* Do Not Retry */
19922000
};
19932001

2002+
#define NVME_SCT(status) ((status) >> 8 & 7)
2003+
19942004
struct nvme_completion {
19952005
/*
19962006
* Used by Admin and Fabrics commands to return data:

0 commit comments

Comments
 (0)