Skip to content

Commit

Permalink
nvme: fix status magic numbers
Browse files Browse the repository at this point in the history
[ Upstream commit d89a5c6705998ddc42b104f8eabd3c4b9e8fde08 ]

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]>
Stable-dep-of: 899d2e5a4e3d ("nvmet: Identify-Active Namespace ID List command should reject invalid nsid")
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
huww98 authored and gregkh committed Sep 12, 2024
1 parent 1be0c30 commit d433e59
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion drivers/nvme/host/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static const char * const nvme_statuses[] = {

const char *nvme_get_error_status_str(u16 status)
{
status &= 0x7ff;
status &= NVME_SCT_SC_MASK;
if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status])
return nvme_statuses[status];
return "Unknown";
Expand Down
18 changes: 9 additions & 9 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)

static blk_status_t nvme_error_status(u16 status)
{
switch (status & 0x7ff) {
switch (status & NVME_SCT_SC_MASK) {
case NVME_SC_SUCCESS:
return BLK_STS_OK;
case NVME_SC_CAP_EXCEEDED:
Expand Down Expand Up @@ -329,8 +329,8 @@ static void nvme_log_error(struct request *req)
nvme_sect_to_lba(ns->head, blk_rq_pos(req)),
blk_rq_bytes(req) >> ns->head->lba_shift,
nvme_get_error_status_str(nr->status),
nr->status >> 8 & 7, /* Status Code Type */
nr->status & 0xff, /* Status Code */
NVME_SCT(nr->status), /* Status Code Type */
nr->status & NVME_SC_MASK, /* Status Code */
nr->status & NVME_SC_MORE ? "MORE " : "",
nr->status & NVME_SC_DNR ? "DNR " : "");
return;
Expand All @@ -341,8 +341,8 @@ static void nvme_log_error(struct request *req)
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
nr->cmd->common.opcode,
nvme_get_error_status_str(nr->status),
nr->status >> 8 & 7, /* Status Code Type */
nr->status & 0xff, /* Status Code */
NVME_SCT(nr->status), /* Status Code Type */
nr->status & NVME_SC_MASK, /* Status Code */
nr->status & NVME_SC_MORE ? "MORE " : "",
nr->status & NVME_SC_DNR ? "DNR " : "");
}
Expand All @@ -359,8 +359,8 @@ static void nvme_log_err_passthru(struct request *req)
nvme_get_admin_opcode_str(nr->cmd->common.opcode),
nr->cmd->common.opcode,
nvme_get_error_status_str(nr->status),
nr->status >> 8 & 7, /* Status Code Type */
nr->status & 0xff, /* Status Code */
NVME_SCT(nr->status), /* Status Code Type */
nr->status & NVME_SC_MASK, /* Status Code */
nr->status & NVME_SC_MORE ? "MORE " : "",
nr->status & NVME_SC_DNR ? "DNR " : "",
nr->cmd->common.cdw10,
Expand Down Expand Up @@ -388,7 +388,7 @@ static inline enum nvme_disposition nvme_decide_disposition(struct request *req)
nvme_req(req)->retries >= nvme_max_retries)
return COMPLETE;

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

if (req->cmd_flags & REQ_NVME_MPATH) {
Expand Down Expand Up @@ -1224,7 +1224,7 @@ EXPORT_SYMBOL_NS_GPL(nvme_passthru_end, NVME_TARGET_PASSTHRU);

/*
* Recommended frequency for KATO commands per NVMe 1.4 section 7.12.1:
*
*
* The host should send Keep Alive commands at half of the Keep Alive Timeout
* accounting for transport roundtrip times [..].
*/
Expand Down
2 changes: 1 addition & 1 deletion drivers/nvme/host/multipath.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
void nvme_failover_req(struct request *req)
{
struct nvme_ns *ns = req->q->queuedata;
u16 status = nvme_req(req)->status & 0x7ff;
u16 status = nvme_req(req)->status & NVME_SCT_SC_MASK;
unsigned long flags;
struct bio *bio;

Expand Down
4 changes: 2 additions & 2 deletions drivers/nvme/host/nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ static inline u32 nvme_bytes_to_numd(size_t len)

static inline bool nvme_is_ana_error(u16 status)
{
switch (status & 0x7ff) {
switch (status & NVME_SCT_SC_MASK) {
case NVME_SC_ANA_TRANSITION:
case NVME_SC_ANA_INACCESSIBLE:
case NVME_SC_ANA_PERSISTENT_LOSS:
Expand All @@ -702,7 +702,7 @@ static inline bool nvme_is_ana_error(u16 status)
static inline bool nvme_is_path_error(u16 status)
{
/* check for a status code type of 'path related status' */
return (status & 0x700) == 0x300;
return (status & NVME_SCT_MASK) == NVME_SCT_PATH;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/nvme/host/pr.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static int nvme_status_to_pr_err(int status)
if (nvme_is_path_error(status))
return PR_STS_PATH_FAILED;

switch (status & 0x7ff) {
switch (status & NVME_SCT_SC_MASK) {
case NVME_SC_SUCCESS:
return PR_STS_SUCCESS;
case NVME_SC_RESERVATION_CONFLICT:
Expand Down
14 changes: 12 additions & 2 deletions include/linux/nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ enum {
/*
* Generic Command Status:
*/
NVME_SCT_GENERIC = 0x0,
NVME_SC_SUCCESS = 0x0,
NVME_SC_INVALID_OPCODE = 0x1,
NVME_SC_INVALID_FIELD = 0x2,
Expand Down Expand Up @@ -1895,6 +1896,7 @@ enum {
/*
* Command Specific Status:
*/
NVME_SCT_COMMAND_SPECIFIC = 0x100,
NVME_SC_CQ_INVALID = 0x100,
NVME_SC_QID_INVALID = 0x101,
NVME_SC_QUEUE_SIZE = 0x102,
Expand Down Expand Up @@ -1968,6 +1970,7 @@ enum {
/*
* Media and Data Integrity Errors:
*/
NVME_SCT_MEDIA_ERROR = 0x200,
NVME_SC_WRITE_FAULT = 0x280,
NVME_SC_READ_ERROR = 0x281,
NVME_SC_GUARD_CHECK = 0x282,
Expand All @@ -1980,6 +1983,7 @@ enum {
/*
* Path-related Errors:
*/
NVME_SCT_PATH = 0x300,
NVME_SC_INTERNAL_PATH_ERROR = 0x300,
NVME_SC_ANA_PERSISTENT_LOSS = 0x301,
NVME_SC_ANA_INACCESSIBLE = 0x302,
Expand All @@ -1988,11 +1992,17 @@ enum {
NVME_SC_HOST_PATH_ERROR = 0x370,
NVME_SC_HOST_ABORTED_CMD = 0x371,

NVME_SC_CRD = 0x1800,
NVME_SC_MASK = 0x00ff, /* Status Code */
NVME_SCT_MASK = 0x0700, /* Status Code Type */
NVME_SCT_SC_MASK = NVME_SCT_MASK | NVME_SC_MASK,

NVME_SC_CRD = 0x1800, /* Command Retry Delayed */
NVME_SC_MORE = 0x2000,
NVME_SC_DNR = 0x4000,
NVME_SC_DNR = 0x4000, /* Do Not Retry */
};

#define NVME_SCT(status) ((status) >> 8 & 7)

struct nvme_completion {
/*
* Used by Admin and Fabrics commands to return data:
Expand Down

0 comments on commit d433e59

Please sign in to comment.