Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvme: fix status magic numbers

Replaced some magic numbers about SC and SCT with enum and macro.

Signed-off-by: Weiwen Hu <huweiwen@linux.alibaba.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>

authored by

Weiwen Hu and committed by
Keith Busch
d89a5c67 22f19a58

+26 -16
+1 -1
drivers/nvme/host/constants.c
··· 173 173 174 174 const char *nvme_get_error_status_str(u16 status) 175 175 { 176 - status &= 0x7ff; 176 + status &= NVME_SCT_SC_MASK; 177 177 if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status]) 178 178 return nvme_statuses[status]; 179 179 return "Unknown";
+9 -9
drivers/nvme/host/core.c
··· 261 261 262 262 static blk_status_t nvme_error_status(u16 status) 263 263 { 264 - switch (status & 0x7ff) { 264 + switch (status & NVME_SCT_SC_MASK) { 265 265 case NVME_SC_SUCCESS: 266 266 return BLK_STS_OK; 267 267 case NVME_SC_CAP_EXCEEDED: ··· 329 329 nvme_sect_to_lba(ns->head, blk_rq_pos(req)), 330 330 blk_rq_bytes(req) >> ns->head->lba_shift, 331 331 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 */ 334 334 nr->status & NVME_SC_MORE ? "MORE " : "", 335 335 nr->status & NVME_SC_DNR ? "DNR " : ""); 336 336 return; ··· 341 341 nvme_get_admin_opcode_str(nr->cmd->common.opcode), 342 342 nr->cmd->common.opcode, 343 343 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 */ 346 346 nr->status & NVME_SC_MORE ? "MORE " : "", 347 347 nr->status & NVME_SC_DNR ? "DNR " : ""); 348 348 } ··· 359 359 nvme_get_admin_opcode_str(nr->cmd->common.opcode), 360 360 nr->cmd->common.opcode, 361 361 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 */ 364 364 nr->status & NVME_SC_MORE ? "MORE " : "", 365 365 nr->status & NVME_SC_DNR ? "DNR " : "", 366 366 nr->cmd->common.cdw10, ··· 388 388 nvme_req(req)->retries >= nvme_max_retries) 389 389 return COMPLETE; 390 390 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) 392 392 return AUTHENTICATE; 393 393 394 394 if (req->cmd_flags & REQ_NVME_MPATH) { ··· 1256 1256 1257 1257 /* 1258 1258 * Recommended frequency for KATO commands per NVMe 1.4 section 7.12.1: 1259 - * 1259 + * 1260 1260 * The host should send Keep Alive commands at half of the Keep Alive Timeout 1261 1261 * accounting for transport roundtrip times [..]. 1262 1262 */
+1 -1
drivers/nvme/host/multipath.c
··· 83 83 void nvme_failover_req(struct request *req) 84 84 { 85 85 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; 87 87 unsigned long flags; 88 88 struct bio *bio; 89 89
+2 -2
drivers/nvme/host/nvme.h
··· 689 689 690 690 static inline bool nvme_is_ana_error(u16 status) 691 691 { 692 - switch (status & 0x7ff) { 692 + switch (status & NVME_SCT_SC_MASK) { 693 693 case NVME_SC_ANA_TRANSITION: 694 694 case NVME_SC_ANA_INACCESSIBLE: 695 695 case NVME_SC_ANA_PERSISTENT_LOSS: ··· 702 702 static inline bool nvme_is_path_error(u16 status) 703 703 { 704 704 /* check for a status code type of 'path related status' */ 705 - return (status & 0x700) == 0x300; 705 + return (status & NVME_SCT_MASK) == NVME_SCT_PATH; 706 706 } 707 707 708 708 /*
+1 -1
drivers/nvme/host/pr.c
··· 77 77 if (nvme_is_path_error(status)) 78 78 return PR_STS_PATH_FAILED; 79 79 80 - switch (status & 0x7ff) { 80 + switch (status & NVME_SCT_SC_MASK) { 81 81 case NVME_SC_SUCCESS: 82 82 return PR_STS_SUCCESS; 83 83 case NVME_SC_RESERVATION_CONFLICT:
+12 -2
include/linux/nvme.h
··· 1846 1846 /* 1847 1847 * Generic Command Status: 1848 1848 */ 1849 + NVME_SCT_GENERIC = 0x0, 1849 1850 NVME_SC_SUCCESS = 0x0, 1850 1851 NVME_SC_INVALID_OPCODE = 0x1, 1851 1852 NVME_SC_INVALID_FIELD = 0x2, ··· 1894 1893 /* 1895 1894 * Command Specific Status: 1896 1895 */ 1896 + NVME_SCT_COMMAND_SPECIFIC = 0x100, 1897 1897 NVME_SC_CQ_INVALID = 0x100, 1898 1898 NVME_SC_QID_INVALID = 0x101, 1899 1899 NVME_SC_QUEUE_SIZE = 0x102, ··· 1968 1966 /* 1969 1967 * Media and Data Integrity Errors: 1970 1968 */ 1969 + NVME_SCT_MEDIA_ERROR = 0x200, 1971 1970 NVME_SC_WRITE_FAULT = 0x280, 1972 1971 NVME_SC_READ_ERROR = 0x281, 1973 1972 NVME_SC_GUARD_CHECK = 0x282, ··· 1981 1978 /* 1982 1979 * Path-related Errors: 1983 1980 */ 1981 + NVME_SCT_PATH = 0x300, 1984 1982 NVME_SC_INTERNAL_PATH_ERROR = 0x300, 1985 1983 NVME_SC_ANA_PERSISTENT_LOSS = 0x301, 1986 1984 NVME_SC_ANA_INACCESSIBLE = 0x302, ··· 1990 1986 NVME_SC_HOST_PATH_ERROR = 0x370, 1991 1987 NVME_SC_HOST_ABORTED_CMD = 0x371, 1992 1988 1993 - NVME_SC_CRD = 0x1800, 1989 + NVME_SC_MASK = 0x00ff, /* Status Code */ 1990 + NVME_SCT_MASK = 0x0700, /* Status Code Type */ 1991 + NVME_SCT_SC_MASK = NVME_SCT_MASK | NVME_SC_MASK, 1992 + 1993 + NVME_SC_CRD = 0x1800, /* Command Retry Delayed */ 1994 1994 NVME_SC_MORE = 0x2000, 1995 - NVME_SC_DNR = 0x4000, 1995 + NVME_SC_DNR = 0x4000, /* Do Not Retry */ 1996 1996 }; 1997 + 1998 + #define NVME_SCT(status) ((status) >> 8 & 7) 1997 1999 1998 2000 struct nvme_completion { 1999 2001 /*