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