18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _SCSI_SCSI_EH_H
38c2ecf20Sopenharmony_ci#define _SCSI_SCSI_EH_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <scsi/scsi_cmnd.h>
88c2ecf20Sopenharmony_ci#include <scsi/scsi_common.h>
98c2ecf20Sopenharmony_cistruct scsi_device;
108c2ecf20Sopenharmony_cistruct Scsi_Host;
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciextern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
138c2ecf20Sopenharmony_ci			       struct list_head *done_q);
148c2ecf20Sopenharmony_ciextern void scsi_eh_flush_done_q(struct list_head *done_q);
158c2ecf20Sopenharmony_ciextern void scsi_report_bus_reset(struct Scsi_Host *, int);
168c2ecf20Sopenharmony_ciextern void scsi_report_device_reset(struct Scsi_Host *, int, int);
178c2ecf20Sopenharmony_ciextern int scsi_block_when_processing_errors(struct scsi_device *);
188c2ecf20Sopenharmony_ciextern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
198c2ecf20Sopenharmony_ci					 struct scsi_sense_hdr *sshdr);
208c2ecf20Sopenharmony_ciextern enum scsi_disposition scsi_check_sense(struct scsi_cmnd *);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1));
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciextern bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len,
288c2ecf20Sopenharmony_ci				    u64 *info_out);
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciextern int scsi_ioctl_reset(struct scsi_device *, int __user *);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct scsi_eh_save {
338c2ecf20Sopenharmony_ci	/* saved state */
348c2ecf20Sopenharmony_ci	int result;
358c2ecf20Sopenharmony_ci	unsigned int resid_len;
368c2ecf20Sopenharmony_ci	int eh_eflags;
378c2ecf20Sopenharmony_ci	enum dma_data_direction data_direction;
388c2ecf20Sopenharmony_ci	unsigned underflow;
398c2ecf20Sopenharmony_ci	unsigned char cmd_len;
408c2ecf20Sopenharmony_ci	unsigned char prot_op;
418c2ecf20Sopenharmony_ci	unsigned char *cmnd;
428c2ecf20Sopenharmony_ci	struct scsi_data_buffer sdb;
438c2ecf20Sopenharmony_ci	/* new command support */
448c2ecf20Sopenharmony_ci	unsigned char eh_cmnd[BLK_MAX_CDB];
458c2ecf20Sopenharmony_ci	struct scatterlist sense_sgl;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciextern void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd,
498c2ecf20Sopenharmony_ci		struct scsi_eh_save *ses, unsigned char *cmnd,
508c2ecf20Sopenharmony_ci		int cmnd_size, unsigned sense_bytes);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciextern void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd,
538c2ecf20Sopenharmony_ci		struct scsi_eh_save *ses);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#endif /* _SCSI_SCSI_EH_H */
56