summaryrefslogtreecommitdiffstats
path: root/include/scsi
diff options
context:
space:
mode:
authorBart Van Assche <bart.vanassche@sandisk.com>2015-05-08 04:07:48 -0400
committerJames Bottomley <JBottomley@Odin.com>2015-06-01 10:32:43 -0400
commit07e3842055c391e611dd907c81760f4c705f9acb (patch)
tree56005ced37b31c082fa984981a8073a241ff3839 /include/scsi
parentc5f1ac8b94bd10f97f5aa1a3279ad8e8bbc6311a (diff)
Move code that is used both by initiator and target drivers
Move the functions that are used by both the initiator and target subsystems into scsi_common.c/.h. This change will allow to remove the initiator SCSI header include directives from most SCSI target source files in a later patch. Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: James Bottomley <JBottomley@Odin.com>
Diffstat (limited to 'include/scsi')
-rw-r--r--include/scsi/scsi.h19
-rw-r--r--include/scsi/scsi_common.h64
-rw-r--r--include/scsi/scsi_device.h2
-rw-r--r--include/scsi/scsi_eh.h31
4 files changed, 65 insertions, 51 deletions
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index f238e6e8b45f..e0a3398b1547 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -8,6 +8,7 @@
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/scatterlist.h> 9#include <linux/scatterlist.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <scsi/scsi_common.h>
11#include <scsi/scsi_proto.h> 12#include <scsi/scsi_proto.h>
12 13
13struct scsi_cmnd; 14struct scsi_cmnd;
@@ -47,22 +48,6 @@ enum scsi_timeouts {
47 */ 48 */
48#define SCAN_WILD_CARD ~0 49#define SCAN_WILD_CARD ~0
49 50
50static inline unsigned
51scsi_varlen_cdb_length(const void *hdr)
52{
53 return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
54}
55
56extern const unsigned char scsi_command_size_tbl[8];
57#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]
58
59static inline unsigned
60scsi_command_size(const unsigned char *cmnd)
61{
62 return (cmnd[0] == VARIABLE_LENGTH_CMD) ?
63 scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]);
64}
65
66#ifdef CONFIG_ACPI 51#ifdef CONFIG_ACPI
67struct acpi_bus_type; 52struct acpi_bus_type;
68 53
@@ -96,8 +81,6 @@ static inline int scsi_status_is_good(int status)
96 (status == SAM_STAT_COMMAND_TERMINATED)); 81 (status == SAM_STAT_COMMAND_TERMINATED));
97} 82}
98 83
99/* Returns a human-readable name for the device */
100extern const char * scsi_device_type(unsigned type);
101 84
102/* 85/*
103 * standard mode-select header prepended to all mode-select commands 86 * standard mode-select header prepended to all mode-select commands
diff --git a/include/scsi/scsi_common.h b/include/scsi/scsi_common.h
new file mode 100644
index 000000000000..676b03b78e57
--- /dev/null
+++ b/include/scsi/scsi_common.h
@@ -0,0 +1,64 @@
1/*
2 * Functions used by both the SCSI initiator code and the SCSI target code.
3 */
4
5#ifndef _SCSI_COMMON_H_
6#define _SCSI_COMMON_H_
7
8#include <linux/types.h>
9#include <scsi/scsi_proto.h>
10
11static inline unsigned
12scsi_varlen_cdb_length(const void *hdr)
13{
14 return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
15}
16
17extern const unsigned char scsi_command_size_tbl[8];
18#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]
19
20static inline unsigned
21scsi_command_size(const unsigned char *cmnd)
22{
23 return (cmnd[0] == VARIABLE_LENGTH_CMD) ?
24 scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]);
25}
26
27/* Returns a human-readable name for the device */
28extern const char *scsi_device_type(unsigned type);
29
30extern void int_to_scsilun(u64, struct scsi_lun *);
31extern u64 scsilun_to_int(struct scsi_lun *);
32
33/*
34 * This is a slightly modified SCSI sense "descriptor" format header.
35 * The addition is to allow the 0x70 and 0x71 response codes. The idea
36 * is to place the salient data from either "fixed" or "descriptor" sense
37 * format into one structure to ease application processing.
38 *
39 * The original sense buffer should be kept around for those cases
40 * in which more information is required (e.g. the LBA of a MEDIUM ERROR).
41 */
42struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
43 u8 response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
44 u8 sense_key;
45 u8 asc;
46 u8 ascq;
47 u8 byte4;
48 u8 byte5;
49 u8 byte6;
50 u8 additional_length; /* always 0 for fixed sense format */
51};
52
53static inline bool scsi_sense_valid(const struct scsi_sense_hdr *sshdr)
54{
55 if (!sshdr)
56 return false;
57
58 return (sshdr->response_code & 0x70) == 0x70;
59}
60
61extern bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
62 struct scsi_sense_hdr *sshdr);
63
64#endif /* _SCSI_COMMON_H_ */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index a4c9336811d1..ae84b2214d40 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -413,8 +413,6 @@ extern void scsi_target_reap(struct scsi_target *);
413extern void scsi_target_block(struct device *); 413extern void scsi_target_block(struct device *);
414extern void scsi_target_unblock(struct device *, enum scsi_device_state); 414extern void scsi_target_unblock(struct device *, enum scsi_device_state);
415extern void scsi_remove_target(struct device *); 415extern void scsi_remove_target(struct device *);
416extern void int_to_scsilun(u64, struct scsi_lun *);
417extern u64 scsilun_to_int(struct scsi_lun *);
418extern const char *scsi_device_state_name(enum scsi_device_state); 416extern const char *scsi_device_state_name(enum scsi_device_state);
419extern int scsi_is_sdev_device(const struct device *); 417extern int scsi_is_sdev_device(const struct device *);
420extern int scsi_is_target_device(const struct device *); 418extern int scsi_is_target_device(const struct device *);
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index 5a4bb5bb66b3..4942710ef720 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -7,43 +7,12 @@
7struct scsi_device; 7struct scsi_device;
8struct Scsi_Host; 8struct Scsi_Host;
9 9
10/*
11 * This is a slightly modified SCSI sense "descriptor" format header.
12 * The addition is to allow the 0x70 and 0x71 response codes. The idea
13 * is to place the salient data from either "fixed" or "descriptor" sense
14 * format into one structure to ease application processing.
15 *
16 * The original sense buffer should be kept around for those cases
17 * in which more information is required (e.g. the LBA of a MEDIUM ERROR).
18 */
19struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
20 u8 response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
21 u8 sense_key;
22 u8 asc;
23 u8 ascq;
24 u8 byte4;
25 u8 byte5;
26 u8 byte6;
27 u8 additional_length; /* always 0 for fixed sense format */
28};
29
30static inline bool scsi_sense_valid(const struct scsi_sense_hdr *sshdr)
31{
32 if (!sshdr)
33 return false;
34
35 return (sshdr->response_code & 0x70) == 0x70;
36}
37
38
39extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, 10extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
40 struct list_head *done_q); 11 struct list_head *done_q);
41extern void scsi_eh_flush_done_q(struct list_head *done_q); 12extern void scsi_eh_flush_done_q(struct list_head *done_q);
42extern void scsi_report_bus_reset(struct Scsi_Host *, int); 13extern void scsi_report_bus_reset(struct Scsi_Host *, int);
43extern void scsi_report_device_reset(struct Scsi_Host *, int, int); 14extern void scsi_report_device_reset(struct Scsi_Host *, int, int);
44extern int scsi_block_when_processing_errors(struct scsi_device *); 15extern int scsi_block_when_processing_errors(struct scsi_device *);
45extern bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
46 struct scsi_sense_hdr *sshdr);
47extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd, 16extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
48 struct scsi_sense_hdr *sshdr); 17 struct scsi_sense_hdr *sshdr);
49 18