OSDN Git Service

scsi: rename SERVICE_ACTION_IN to SERVICE_ACTION_IN_16
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / scsi / constants.c
index a84ced0..52afabd 100644 (file)
@@ -24,7 +24,6 @@
 #define SERVICE_ACTION_IN_12 0xab
 #define SERVICE_ACTION_OUT_12 0xa9
 #define SERVICE_ACTION_BIDIRECTIONAL 0x9d
-#define SERVICE_ACTION_IN_16 0x9e
 #define SERVICE_ACTION_OUT_16 0x9f
 #define THIRD_PARTY_COPY_OUT 0x83
 #define THIRD_PARTY_COPY_IN 0x84
@@ -1407,38 +1406,87 @@ static const char * const hostbyte_table[]={
 "DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE",
 "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
 "DID_NEXUS_FAILURE" };
-#define NUM_HOSTBYTE_STRS ARRAY_SIZE(hostbyte_table)
 
 static const char * const driverbyte_table[]={
 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
 "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
-#define NUM_DRIVERBYTE_STRS ARRAY_SIZE(driverbyte_table)
 
-void scsi_show_result(int result)
+#endif
+
+const char *scsi_hostbyte_string(int result)
 {
+       const char *hb_string = NULL;
+#ifdef CONFIG_SCSI_CONSTANTS
        int hb = host_byte(result);
-       int db = driver_byte(result);
 
-       printk("Result: hostbyte=%s driverbyte=%s\n",
-              (hb < NUM_HOSTBYTE_STRS ? hostbyte_table[hb]     : "invalid"),
-              (db < NUM_DRIVERBYTE_STRS ? driverbyte_table[db] : "invalid"));
+       if (hb < ARRAY_SIZE(hostbyte_table))
+               hb_string = hostbyte_table[hb];
+#endif
+       return hb_string;
 }
+EXPORT_SYMBOL(scsi_hostbyte_string);
 
-#else
-
-void scsi_show_result(int result)
+const char *scsi_driverbyte_string(int result)
 {
-       printk("Result: hostbyte=0x%02x driverbyte=0x%02x\n",
-              host_byte(result), driver_byte(result));
+       const char *db_string = NULL;
+#ifdef CONFIG_SCSI_CONSTANTS
+       int db = driver_byte(result);
+
+       if (db < ARRAY_SIZE(driverbyte_table))
+               db_string = driverbyte_table[db];
+#endif
+       return db_string;
 }
+EXPORT_SYMBOL(scsi_driverbyte_string);
 
+#ifdef CONFIG_SCSI_CONSTANTS
+#define scsi_mlreturn_name(result)     { result, #result }
+static const struct value_name_pair scsi_mlreturn_arr[] = {
+       scsi_mlreturn_name(NEEDS_RETRY),
+       scsi_mlreturn_name(SUCCESS),
+       scsi_mlreturn_name(FAILED),
+       scsi_mlreturn_name(QUEUED),
+       scsi_mlreturn_name(SOFT_ERROR),
+       scsi_mlreturn_name(ADD_TO_MLQUEUE),
+       scsi_mlreturn_name(TIMEOUT_ERROR),
+       scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED),
+       scsi_mlreturn_name(FAST_IO_FAIL)
+};
 #endif
-EXPORT_SYMBOL(scsi_show_result);
 
+const char *scsi_mlreturn_string(int result)
+{
+#ifdef CONFIG_SCSI_CONSTANTS
+       const struct value_name_pair *arr = scsi_mlreturn_arr;
+       int k;
+
+       for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) {
+               if (result == arr->value)
+                       return arr->name;
+       }
+#endif
+       return NULL;
+}
+EXPORT_SYMBOL(scsi_mlreturn_string);
 
-void scsi_print_result(struct scsi_cmnd *cmd)
+void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition)
 {
-       scmd_printk(KERN_INFO, cmd, " ");
-       scsi_show_result(cmd->result);
+       const char *mlret_string = scsi_mlreturn_string(disposition);
+       const char *hb_string = scsi_hostbyte_string(cmd->result);
+       const char *db_string = scsi_driverbyte_string(cmd->result);
+
+       if (hb_string || db_string)
+               scmd_printk(KERN_INFO, cmd,
+                           "%s%s Result: hostbyte=%s driverbyte=%s",
+                           msg ? msg : "",
+                           mlret_string ? mlret_string : "UNKNOWN",
+                           hb_string ? hb_string : "invalid",
+                           db_string ? db_string : "invalid");
+       else
+               scmd_printk(KERN_INFO, cmd,
+                           "%s%s Result: hostbyte=0x%02x driverbyte=0x%02x",
+                           msg ? msg : "",
+                           mlret_string ? mlret_string : "UNKNOWN",
+                           host_byte(cmd->result), driver_byte(cmd->result));
 }
 EXPORT_SYMBOL(scsi_print_result);