scsi_priv.h 6.8 KB

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