xref: /linux/drivers/scsi/scsi_priv.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _SCSI_PRIV_H
3 #define _SCSI_PRIV_H
4 
5 #include <linux/device.h>
6 #include <scsi/scsi_device.h>
7 #include <linux/sbitmap.h>
8 
9 struct bsg_device;
10 struct request_queue;
11 struct request;
12 struct scsi_cmnd;
13 struct scsi_device;
14 struct scsi_target;
15 struct scsi_host_template;
16 struct Scsi_Host;
17 struct scsi_nl_hdr;
18 
19 #define SCSI_CMD_RETRIES_NO_LIMIT -1
20 
21 /*
22  * Scsi Error Handler Flags
23  */
24 #define SCSI_EH_ABORT_SCHEDULED	0x0002	/* Abort has been scheduled */
25 
26 #define SCSI_SENSE_VALID(scmd) \
27 	(((scmd)->sense_buffer[0] & 0x70) == 0x70)
28 
29 /* hosts.c */
30 extern int scsi_init_hosts(void);
31 extern void scsi_exit_hosts(void);
32 
33 /* scsi.c */
34 int scsi_init_sense_cache(struct Scsi_Host *shost);
35 void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd);
36 #ifdef CONFIG_SCSI_LOGGING
37 void scsi_log_send(struct scsi_cmnd *cmd);
38 void scsi_log_completion(struct scsi_cmnd *cmd, int disposition);
39 #else
40 static inline void scsi_log_send(struct scsi_cmnd *cmd)
41 	{ };
42 static inline void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
43 	{ };
44 #endif
45 
46 /* scsi_devinfo.c */
47 
48 /* list of keys for the lists */
49 enum scsi_devinfo_key {
50 	SCSI_DEVINFO_GLOBAL = 0,
51 	SCSI_DEVINFO_SPI,
52 };
53 
54 extern blist_flags_t scsi_get_device_flags(struct scsi_device *sdev,
55 					   const unsigned char *vendor,
56 					   const unsigned char *model);
57 extern blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
58 						 const unsigned char *vendor,
59 						 const unsigned char *model,
60 						 enum scsi_devinfo_key key);
61 extern int scsi_dev_info_list_add_keyed(int compatible, char *vendor,
62 					char *model, char *strflags,
63 					blist_flags_t flags,
64 					enum scsi_devinfo_key key);
65 extern int scsi_dev_info_list_del_keyed(char *vendor, char *model,
66 					enum scsi_devinfo_key key);
67 extern int scsi_dev_info_add_list(enum scsi_devinfo_key key, const char *name);
68 extern int scsi_dev_info_remove_list(enum scsi_devinfo_key key);
69 
70 extern int __init scsi_init_devinfo(void);
71 extern void scsi_exit_devinfo(void);
72 
73 /* scsi_error.c */
74 extern void scmd_eh_abort_handler(struct work_struct *work);
75 extern enum blk_eh_timer_return scsi_times_out(struct request *req);
76 extern int scsi_error_handler(void *host);
77 extern enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *cmd);
78 extern void scsi_eh_wakeup(struct Scsi_Host *shost);
79 extern void scsi_eh_scmd_add(struct scsi_cmnd *);
80 void scsi_eh_ready_devs(struct Scsi_Host *shost,
81 			struct list_head *work_q,
82 			struct list_head *done_q);
83 int scsi_eh_get_sense(struct list_head *work_q,
84 		      struct list_head *done_q);
85 int scsi_noretry_cmd(struct scsi_cmnd *scmd);
86 void scsi_eh_done(struct scsi_cmnd *scmd);
87 
88 /* scsi_lib.c */
89 extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
90 extern void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd);
91 extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason);
92 extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
93 extern void scsi_run_host_queues(struct Scsi_Host *shost);
94 extern void scsi_requeue_run_queue(struct work_struct *work);
95 extern void scsi_start_queue(struct scsi_device *sdev);
96 extern int scsi_mq_setup_tags(struct Scsi_Host *shost);
97 extern void scsi_mq_destroy_tags(struct Scsi_Host *shost);
98 extern void scsi_exit_queue(void);
99 extern void scsi_evt_thread(struct work_struct *work);
100 
101 /* scsi_proc.c */
102 #ifdef CONFIG_SCSI_PROC_FS
103 extern void scsi_proc_hostdir_add(struct scsi_host_template *);
104 extern void scsi_proc_hostdir_rm(struct scsi_host_template *);
105 extern void scsi_proc_host_add(struct Scsi_Host *);
106 extern void scsi_proc_host_rm(struct Scsi_Host *);
107 extern int scsi_init_procfs(void);
108 extern void scsi_exit_procfs(void);
109 #else
110 # define scsi_proc_hostdir_add(sht)	do { } while (0)
111 # define scsi_proc_hostdir_rm(sht)	do { } while (0)
112 # define scsi_proc_host_add(shost)	do { } while (0)
113 # define scsi_proc_host_rm(shost)	do { } while (0)
114 # define scsi_init_procfs()		(0)
115 # define scsi_exit_procfs()		do { } while (0)
116 #endif /* CONFIG_PROC_FS */
117 
118 /* scsi_scan.c */
119 void scsi_enable_async_suspend(struct device *dev);
120 extern int scsi_complete_async_scans(void);
121 extern int scsi_scan_host_selected(struct Scsi_Host *, unsigned int,
122 				   unsigned int, u64, enum scsi_scan_mode);
123 extern void scsi_forget_host(struct Scsi_Host *);
124 extern void scsi_rescan_device(struct device *);
125 
126 /* scsi_sysctl.c */
127 #ifdef CONFIG_SYSCTL
128 extern int scsi_init_sysctl(void);
129 extern void scsi_exit_sysctl(void);
130 #else
131 # define scsi_init_sysctl()		(0)
132 # define scsi_exit_sysctl()		do { } while (0)
133 #endif /* CONFIG_SYSCTL */
134 
135 /* scsi_sysfs.c */
136 extern int scsi_sysfs_add_sdev(struct scsi_device *);
137 extern int scsi_sysfs_add_host(struct Scsi_Host *);
138 extern int scsi_sysfs_register(void);
139 extern void scsi_sysfs_unregister(void);
140 extern void scsi_sysfs_device_initialize(struct scsi_device *);
141 extern int scsi_sysfs_target_initialize(struct scsi_device *);
142 extern struct scsi_transport_template blank_transport_template;
143 extern void __scsi_remove_device(struct scsi_device *);
144 
145 extern struct bus_type scsi_bus_type;
146 extern const struct attribute_group *scsi_shost_groups[];
147 
148 /* scsi_netlink.c */
149 #ifdef CONFIG_SCSI_NETLINK
150 extern void scsi_netlink_init(void);
151 extern void scsi_netlink_exit(void);
152 extern struct sock *scsi_nl_sock;
153 #else
154 static inline void scsi_netlink_init(void) {}
155 static inline void scsi_netlink_exit(void) {}
156 #endif
157 
158 /* scsi_pm.c */
159 #ifdef CONFIG_PM
160 extern const struct dev_pm_ops scsi_bus_pm_ops;
161 
162 extern void scsi_autopm_get_target(struct scsi_target *);
163 extern void scsi_autopm_put_target(struct scsi_target *);
164 extern int scsi_autopm_get_host(struct Scsi_Host *);
165 extern void scsi_autopm_put_host(struct Scsi_Host *);
166 #else
167 static inline void scsi_autopm_get_target(struct scsi_target *t) {}
168 static inline void scsi_autopm_put_target(struct scsi_target *t) {}
169 static inline int scsi_autopm_get_host(struct Scsi_Host *h) { return 0; }
170 static inline void scsi_autopm_put_host(struct Scsi_Host *h) {}
171 #endif /* CONFIG_PM */
172 
173 /* scsi_dh.c */
174 #ifdef CONFIG_SCSI_DH
175 void scsi_dh_add_device(struct scsi_device *sdev);
176 void scsi_dh_release_device(struct scsi_device *sdev);
177 #else
178 static inline void scsi_dh_add_device(struct scsi_device *sdev) { }
179 static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
180 #endif
181 
182 struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev);
183 
184 extern int scsi_device_max_queue_depth(struct scsi_device *sdev);
185 
186 /*
187  * internal scsi timeout functions: for use by mid-layer and transport
188  * classes.
189  */
190 
191 #define SCSI_DEVICE_BLOCK_MAX_TIMEOUT	600	/* units in seconds */
192 
193 #endif /* _SCSI_PRIV_H */
194