summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/constants.c
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2014-10-24 14:26:56 +0200
committerChristoph Hellwig <hch@lst.de>2014-11-12 11:16:03 +0100
commit2478a736a7d01e3ef8d273e8fc5b11b6ed9af3ea (patch)
tree4c1a052410411ce08b2093776019e483330eec35 /drivers/scsi/constants.c
parentscsi: merge print_opcode_name() (diff)
downloadlinux-2478a736a7d01e3ef8d273e8fc5b11b6ed9af3ea.tar.xz
linux-2478a736a7d01e3ef8d273e8fc5b11b6ed9af3ea.zip
scsi: consolidate opcode lookup in scsi_opcode_sa_name()
Consolidate the CDB opcode lookup in scsi_opcode_sa_name(), so that we don't have to call several functions to figure out the CDB opcode string. Signed-off-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Robert Elliott <elliott@hp.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/scsi/constants.c')
-rw-r--r--drivers/scsi/constants.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 3707d8a6377a..dc1b18c821ed 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -29,6 +29,7 @@
#define THIRD_PARTY_COPY_OUT 0x83
#define THIRD_PARTY_COPY_IN 0x84
+#define VENDOR_SPECIFIC_CDB 0xc0
struct sa_name_list {
int opcode;
@@ -266,7 +267,7 @@ static struct sa_name_list sa_names_arr[] = {
};
#else /* ifndef CONFIG_SCSI_CONSTANTS */
-static const char *cdb_byte0_names[];
+static const char *cdb_byte0_names[0];
static struct sa_name_list sa_names_arr[] = {
{VARIABLE_LENGTH_CMD, NULL, 0},
@@ -286,12 +287,19 @@ static struct sa_name_list sa_names_arr[] = {
#endif /* CONFIG_SCSI_CONSTANTS */
static bool scsi_opcode_sa_name(int opcode, int service_action,
- const char **sa_name)
+ const char **cdb_name, const char **sa_name)
{
struct sa_name_list *sa_name_ptr;
const struct value_name_pair *arr = NULL;
int arr_sz, k;
+ *cdb_name = NULL;
+ if (opcode >= VENDOR_SPECIFIC_CDB)
+ return false;
+
+ if (opcode < ARRAY_SIZE(cdb_byte0_names))
+ *cdb_name = cdb_byte0_names[opcode];
+
for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) {
if (sa_name_ptr->opcode == opcode) {
arr = sa_name_ptr->arr;
@@ -316,7 +324,7 @@ static bool scsi_opcode_sa_name(int opcode, int service_action,
static void print_opcode_name(unsigned char * cdbp, int cdb_len)
{
int sa, len, cdb0;
- const char *name = NULL;
+ const char *cdb_name = NULL, *sa_name = NULL;
cdb0 = cdbp[0];
if (cdb0 == VARIABLE_LENGTH_CMD) {
@@ -332,21 +340,20 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
len = cdb_len;
}
- if (!scsi_opcode_sa_name(cdb0, sa, &name)) {
- if (cdb0 < 0xc0) {
- if (ARRAY_SIZE(cdb_byte0_names) > 1) {
- name = cdb_byte0_names[cdb0];
- if (name)
- printk("%s", name);
- else
- printk("cdb[0]=0x%x (reserved)", cdb0);
- } else
- printk("cdb[0]=0x%x", cdb0);
- } else
+ if (!scsi_opcode_sa_name(cdb0, sa, &cdb_name, &sa_name)) {
+ if (cdb_name)
+ printk("%s", cdb_name);
+ else if (cdb0 >= VENDOR_SPECIFIC_CDB)
printk("cdb[0]=0x%x (vendor)", cdb0);
+ else if (cdb0 >= 0x60 && cdb0 < 0x7e)
+ printk("cdb[0]=0x%x (reserved)", cdb0);
+ else
+ printk("cdb[0]=0x%x", cdb0);
} else {
- if (name)
- printk("%s", name);
+ if (sa_name)
+ printk("%s", sa_name);
+ else if (cdb_name)
+ printk("%s, sa=0x%x", cdb_name, sa);
else
printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);