1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/device.h>
6 #include <scsi/scsi_device.h>
7 #include <linux/sbitmap.h>
15 struct scsi_host_template;
19 #define SCSI_CMD_RETRIES_NO_LIMIT -1
22 * Error codes used by scsi-ml internally. These must not be used by drivers.
25 SCSIML_STAT_OK = 0x00,
26 SCSIML_STAT_RESV_CONFLICT = 0x01, /* Reservation conflict */
27 SCSIML_STAT_NOSPC = 0x02, /* Space allocation on the dev failed */
28 SCSIML_STAT_MED_ERROR = 0x03, /* Medium error */
29 SCSIML_STAT_TGT_FAILURE = 0x04, /* Permanent target failure */
33 * Scsi Error Handler Flags
35 #define SCSI_EH_ABORT_SCHEDULED 0x0002 /* Abort has been scheduled */
37 #define SCSI_SENSE_VALID(scmd) \
38 (((scmd)->sense_buffer[0] & 0x70) == 0x70)
41 extern int scsi_init_hosts(void);
42 extern void scsi_exit_hosts(void);
45 int scsi_init_sense_cache(struct Scsi_Host *shost);
46 void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd);
47 #ifdef CONFIG_SCSI_LOGGING
48 void scsi_log_send(struct scsi_cmnd *cmd);
49 void scsi_log_completion(struct scsi_cmnd *cmd, int disposition);
51 static inline void scsi_log_send(struct scsi_cmnd *cmd)
53 static inline void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
59 /* list of keys for the lists */
60 enum scsi_devinfo_key {
61 SCSI_DEVINFO_GLOBAL = 0,
65 extern blist_flags_t scsi_get_device_flags(struct scsi_device *sdev,
66 const unsigned char *vendor,
67 const unsigned char *model);
68 extern blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
69 const unsigned char *vendor,
70 const unsigned char *model,
71 enum scsi_devinfo_key key);
72 extern int scsi_dev_info_list_add_keyed(int compatible, char *vendor,
73 char *model, char *strflags,
75 enum scsi_devinfo_key key);
76 extern int scsi_dev_info_list_del_keyed(char *vendor, char *model,
77 enum scsi_devinfo_key key);
78 extern int scsi_dev_info_add_list(enum scsi_devinfo_key key, const char *name);
79 extern int scsi_dev_info_remove_list(enum scsi_devinfo_key key);
81 extern int __init scsi_init_devinfo(void);
82 extern void scsi_exit_devinfo(void);
85 extern void scmd_eh_abort_handler(struct work_struct *work);
86 extern enum blk_eh_timer_return scsi_timeout(struct request *req);
87 extern int scsi_error_handler(void *host);
88 extern enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *cmd);
89 extern void scsi_eh_wakeup(struct Scsi_Host *shost);
90 extern void scsi_eh_scmd_add(struct scsi_cmnd *);
91 void scsi_eh_ready_devs(struct Scsi_Host *shost,
92 struct list_head *work_q,
93 struct list_head *done_q);
94 int scsi_eh_get_sense(struct list_head *work_q,
95 struct list_head *done_q);
96 bool scsi_noretry_cmd(struct scsi_cmnd *scmd);
97 void scsi_eh_done(struct scsi_cmnd *scmd);
100 extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
101 extern void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd);
102 extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason);
103 extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
104 extern void scsi_run_host_queues(struct Scsi_Host *shost);
105 extern void scsi_requeue_run_queue(struct work_struct *work);
106 extern void scsi_start_queue(struct scsi_device *sdev);
107 extern int scsi_mq_setup_tags(struct Scsi_Host *shost);
108 extern void scsi_mq_free_tags(struct kref *kref);
109 extern void scsi_exit_queue(void);
110 extern void scsi_evt_thread(struct work_struct *work);
113 #ifdef CONFIG_SCSI_PROC_FS
114 extern void scsi_proc_hostdir_add(struct scsi_host_template *);
115 extern void scsi_proc_hostdir_rm(struct scsi_host_template *);
116 extern void scsi_proc_host_add(struct Scsi_Host *);
117 extern void scsi_proc_host_rm(struct Scsi_Host *);
118 extern int scsi_init_procfs(void);
119 extern void scsi_exit_procfs(void);
121 # define scsi_proc_hostdir_add(sht) do { } while (0)
122 # define scsi_proc_hostdir_rm(sht) do { } while (0)
123 # define scsi_proc_host_add(shost) do { } while (0)
124 # define scsi_proc_host_rm(shost) do { } while (0)
125 # define scsi_init_procfs() (0)
126 # define scsi_exit_procfs() do { } while (0)
127 #endif /* CONFIG_PROC_FS */
130 void scsi_enable_async_suspend(struct device *dev);
131 extern int scsi_complete_async_scans(void);
132 extern int scsi_scan_host_selected(struct Scsi_Host *, unsigned int,
133 unsigned int, u64, enum scsi_scan_mode);
134 extern void scsi_forget_host(struct Scsi_Host *);
138 extern int scsi_init_sysctl(void);
139 extern void scsi_exit_sysctl(void);
141 # define scsi_init_sysctl() (0)
142 # define scsi_exit_sysctl() do { } while (0)
143 #endif /* CONFIG_SYSCTL */
146 extern int scsi_sysfs_add_sdev(struct scsi_device *);
147 extern int scsi_sysfs_add_host(struct Scsi_Host *);
148 extern int scsi_sysfs_register(void);
149 extern void scsi_sysfs_unregister(void);
150 extern void scsi_sysfs_device_initialize(struct scsi_device *);
151 extern int scsi_sysfs_target_initialize(struct scsi_device *);
152 extern struct scsi_transport_template blank_transport_template;
153 extern void __scsi_remove_device(struct scsi_device *);
155 extern struct bus_type scsi_bus_type;
156 extern const struct attribute_group *scsi_shost_groups[];
159 #ifdef CONFIG_SCSI_NETLINK
160 extern void scsi_netlink_init(void);
161 extern void scsi_netlink_exit(void);
162 extern struct sock *scsi_nl_sock;
164 static inline void scsi_netlink_init(void) {}
165 static inline void scsi_netlink_exit(void) {}
170 extern const struct dev_pm_ops scsi_bus_pm_ops;
172 extern void scsi_autopm_get_target(struct scsi_target *);
173 extern void scsi_autopm_put_target(struct scsi_target *);
174 extern int scsi_autopm_get_host(struct Scsi_Host *);
175 extern void scsi_autopm_put_host(struct Scsi_Host *);
177 static inline void scsi_autopm_get_target(struct scsi_target *t) {}
178 static inline void scsi_autopm_put_target(struct scsi_target *t) {}
179 static inline int scsi_autopm_get_host(struct Scsi_Host *h) { return 0; }
180 static inline void scsi_autopm_put_host(struct Scsi_Host *h) {}
181 #endif /* CONFIG_PM */
184 #ifdef CONFIG_SCSI_DH
185 void scsi_dh_add_device(struct scsi_device *sdev);
186 void scsi_dh_release_device(struct scsi_device *sdev);
188 static inline void scsi_dh_add_device(struct scsi_device *sdev) { }
189 static inline void scsi_dh_release_device(struct scsi_device *sdev) { }
192 struct bsg_device *scsi_bsg_register_queue(struct scsi_device *sdev);
194 extern int scsi_device_max_queue_depth(struct scsi_device *sdev);
197 * internal scsi timeout functions: for use by mid-layer and transport
201 #define SCSI_DEVICE_BLOCK_MAX_TIMEOUT 600 /* units in seconds */
203 #endif /* _SCSI_PRIV_H */