xref: /openbmc/linux/include/scsi/scsi_device.h (revision 7b7fd0ac7dc1ffcaf24d9bca0f051b0168e43cd4)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _SCSI_SCSI_DEVICE_H
31da177e4SLinus Torvalds #define _SCSI_SCSI_DEVICE_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include <linux/list.h>
61da177e4SLinus Torvalds #include <linux/spinlock.h>
7ffedb452SJames Bottomley #include <linux/workqueue.h>
824b83debSChristoph Hellwig #include <linux/blk-mq.h>
9d211f052SHugh Dickins #include <scsi/scsi.h>
1060063497SArun Sharma #include <linux/atomic.h>
11020b0f0aSMing Lei #include <linux/sbitmap.h>
121da177e4SLinus Torvalds 
13ead09dd3SChristoph Hellwig struct bsg_device;
14313162d0SPaul Gortmaker struct device;
151da177e4SLinus Torvalds struct request_queue;
161da177e4SLinus Torvalds struct scsi_cmnd;
17e10fb91cSJames Bottomley struct scsi_lun;
18ea73a9f2SJames Bottomley struct scsi_sense_hdr;
191da177e4SLinus Torvalds 
2014098803SMartin Wilck typedef __u64 __bitwise blist_flags_t;
215ebde469SHannes Reinecke 
22704f8392SKees Cook #define SCSI_SENSE_BUFFERSIZE	96
23704f8392SKees Cook 
241cf72699SJames Bottomley struct scsi_mode_data {
251cf72699SJames Bottomley 	__u32	length;
261cf72699SJames Bottomley 	__u16	block_descriptor_length;
271cf72699SJames Bottomley 	__u8	medium_type;
281cf72699SJames Bottomley 	__u8	device_specific;
291cf72699SJames Bottomley 	__u8	header_length;
301cf72699SJames Bottomley 	__u8	longlba:1;
311cf72699SJames Bottomley };
321cf72699SJames Bottomley 
331da177e4SLinus Torvalds /*
341da177e4SLinus Torvalds  * sdev state: If you alter this, you also need to alter scsi_sysfs.c
351da177e4SLinus Torvalds  * (for the ascii descriptions) and the state model enforcer:
361da177e4SLinus Torvalds  * scsi_lib:scsi_device_set_state().
371da177e4SLinus Torvalds  */
381da177e4SLinus Torvalds enum scsi_device_state {
391da177e4SLinus Torvalds 	SDEV_CREATED = 1,	/* device created but not added to sysfs
401da177e4SLinus Torvalds 				 * Only internal commands allowed (for inq) */
411da177e4SLinus Torvalds 	SDEV_RUNNING,		/* device properly configured
421da177e4SLinus Torvalds 				 * All commands allowed */
431da177e4SLinus Torvalds 	SDEV_CANCEL,		/* beginning to delete device
441da177e4SLinus Torvalds 				 * Only error handler commands allowed */
451da177e4SLinus Torvalds 	SDEV_DEL,		/* device deleted
461da177e4SLinus Torvalds 				 * no commands allowed */
471da177e4SLinus Torvalds 	SDEV_QUIESCE,		/* Device quiescent.  No block commands
481da177e4SLinus Torvalds 				 * will be accepted, only specials (which
491da177e4SLinus Torvalds 				 * originate in the mid-layer) */
501da177e4SLinus Torvalds 	SDEV_OFFLINE,		/* Device offlined (by error handling or
511da177e4SLinus Torvalds 				 * user request */
521b8d2620SMike Christie 	SDEV_TRANSPORT_OFFLINE,	/* Offlined by transport class error handler */
536f4267e3SJames Bottomley 	SDEV_BLOCK,		/* Device blocked by scsi lld.  No
546f4267e3SJames Bottomley 				 * scsi commands from user or midlayer
556f4267e3SJames Bottomley 				 * should be issued to the scsi
566f4267e3SJames Bottomley 				 * lld. */
576f4267e3SJames Bottomley 	SDEV_CREATED_BLOCK,	/* same as above but for created devices */
581da177e4SLinus Torvalds };
591da177e4SLinus Torvalds 
601d645088SHannes Reinecke enum scsi_scan_mode {
611d645088SHannes Reinecke 	SCSI_SCAN_INITIAL = 0,
621d645088SHannes Reinecke 	SCSI_SCAN_RESCAN,
631d645088SHannes Reinecke 	SCSI_SCAN_MANUAL,
641d645088SHannes Reinecke };
651d645088SHannes Reinecke 
66a341cd0fSJeff Garzik enum scsi_device_event {
67a341cd0fSJeff Garzik 	SDEV_EVT_MEDIA_CHANGE	= 1,	/* media has changed */
68279afdfeSEwan D. Milne 	SDEV_EVT_INQUIRY_CHANGE_REPORTED,		/* 3F 03  UA reported */
69279afdfeSEwan D. Milne 	SDEV_EVT_CAPACITY_CHANGE_REPORTED,		/* 2A 09  UA reported */
70279afdfeSEwan D. Milne 	SDEV_EVT_SOFT_THRESHOLD_REACHED_REPORTED,	/* 38 07  UA reported */
71279afdfeSEwan D. Milne 	SDEV_EVT_MODE_PARAMETER_CHANGE_REPORTED,	/* 2A 01  UA reported */
72279afdfeSEwan D. Milne 	SDEV_EVT_LUN_CHANGE_REPORTED,			/* 3F 0E  UA reported */
7314c3e677SHannes Reinecke 	SDEV_EVT_ALUA_STATE_CHANGE_REPORTED,		/* 2A 06  UA reported */
74cf3431bbSHannes Reinecke 	SDEV_EVT_POWER_ON_RESET_OCCURRED,		/* 29 00  UA reported */
75a341cd0fSJeff Garzik 
76279afdfeSEwan D. Milne 	SDEV_EVT_FIRST		= SDEV_EVT_MEDIA_CHANGE,
77cf3431bbSHannes Reinecke 	SDEV_EVT_LAST		= SDEV_EVT_POWER_ON_RESET_OCCURRED,
78279afdfeSEwan D. Milne 
79a341cd0fSJeff Garzik 	SDEV_EVT_MAXBITS	= SDEV_EVT_LAST + 1
80a341cd0fSJeff Garzik };
81a341cd0fSJeff Garzik 
82a341cd0fSJeff Garzik struct scsi_event {
83a341cd0fSJeff Garzik 	enum scsi_device_event	evt_type;
84a341cd0fSJeff Garzik 	struct list_head	node;
85a341cd0fSJeff Garzik 
86a341cd0fSJeff Garzik 	/* put union of data structures, for non-simple event types,
87a341cd0fSJeff Garzik 	 * here
88a341cd0fSJeff Garzik 	 */
89a341cd0fSJeff Garzik };
90a341cd0fSJeff Garzik 
91ccf1e004SBart Van Assche /**
92ccf1e004SBart Van Assche  * struct scsi_vpd - SCSI Vital Product Data
93ccf1e004SBart Van Assche  * @rcu: For kfree_rcu().
94ccf1e004SBart Van Assche  * @len: Length in bytes of @data.
95ccf1e004SBart Van Assche  * @data: VPD data as defined in various T10 SCSI standard documents.
96ccf1e004SBart Van Assche  */
97ccf1e004SBart Van Assche struct scsi_vpd {
98ccf1e004SBart Van Assche 	struct rcu_head	rcu;
99ccf1e004SBart Van Assche 	int		len;
100ccf1e004SBart Van Assche 	unsigned char	data[];
101ccf1e004SBart Van Assche };
102ccf1e004SBart Van Assche 
1031da177e4SLinus Torvalds struct scsi_device {
1041da177e4SLinus Torvalds 	struct Scsi_Host *host;
1051da177e4SLinus Torvalds 	struct request_queue *request_queue;
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	/* the next two are protected by the host->host_lock */
1081da177e4SLinus Torvalds 	struct list_head    siblings;   /* list of all devices on this host */
1091da177e4SLinus Torvalds 	struct list_head    same_target_siblings; /* just the devices sharing same target id */
1101da177e4SLinus Torvalds 
111020b0f0aSMing Lei 	struct sbitmap budget_map;
112cd9070c9SChristoph Hellwig 	atomic_t device_blocked;	/* Device returned QUEUE_FULL. */
113cd9070c9SChristoph Hellwig 
114ed5dd6a6SMing Lei 	atomic_t restarts;
1151da177e4SLinus Torvalds 	spinlock_t list_lock;
1161da177e4SLinus Torvalds 	struct list_head starved_entry;
1171da177e4SLinus Torvalds 	unsigned short queue_depth;	/* How deep of a queue we want */
1184a84067dSVasu Dev 	unsigned short max_queue_depth;	/* max queue depth */
1191da177e4SLinus Torvalds 	unsigned short last_queue_full_depth; /* These two are used by */
1201da177e4SLinus Torvalds 	unsigned short last_queue_full_count; /* scsi_track_queue_full() */
1214a84067dSVasu Dev 	unsigned long last_queue_full_time;	/* last queue full time */
1224a84067dSVasu Dev 	unsigned long queue_ramp_up_period;	/* ramp up period in jiffies */
1234a84067dSVasu Dev #define SCSI_DEFAULT_RAMP_UP_PERIOD	(120 * HZ)
1244a84067dSVasu Dev 
1254a84067dSVasu Dev 	unsigned long last_queue_ramp_up;	/* last queue ramp up time */
1261da177e4SLinus Torvalds 
1279cb78c16SHannes Reinecke 	unsigned int id, channel;
1289cb78c16SHannes Reinecke 	u64 lun;
1291da177e4SLinus Torvalds 	unsigned int manufacturer;	/* Manufacturer of device, for using
1301da177e4SLinus Torvalds 					 * vendor-specific cmd's */
1311da177e4SLinus Torvalds 	unsigned sector_size;	/* size in bytes */
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds 	void *hostdata;		/* available to low-level driver */
134c2e872a2SBart Van Assche 	unsigned char type;
1351da177e4SLinus Torvalds 	char scsi_level;
1361da177e4SLinus Torvalds 	char inq_periph_qual;	/* PQ from INQUIRY data */
13709e2b0b1SHannes Reinecke 	struct mutex inquiry_mutex;
1381da177e4SLinus Torvalds 	unsigned char inquiry_len;	/* valid bytes in 'inquiry' */
1391da177e4SLinus Torvalds 	unsigned char * inquiry;	/* INQUIRY response data */
1407f23e146SJames Bottomley 	const char * vendor;		/* [back_compat] point into 'inquiry' ... */
1417f23e146SJames Bottomley 	const char * model;		/* ... after scan; point to static string */
1427f23e146SJames Bottomley 	const char * rev;		/* ... "nullnullnullnull" before scan */
143b3ae8780SHannes Reinecke 
1444b1a2c2aSLee Duncan #define SCSI_DEFAULT_VPD_LEN	255	/* default SCSI VPD page size (max) */
145d188b067SRyan Attard 	struct scsi_vpd __rcu *vpd_pg0;
146ccf1e004SBart Van Assche 	struct scsi_vpd __rcu *vpd_pg83;
147ccf1e004SBart Van Assche 	struct scsi_vpd __rcu *vpd_pg80;
148d188b067SRyan Attard 	struct scsi_vpd __rcu *vpd_pg89;
149e60ac0b9SMartin K. Petersen 	struct scsi_vpd __rcu *vpd_pgb0;
150e60ac0b9SMartin K. Petersen 	struct scsi_vpd __rcu *vpd_pgb1;
151e60ac0b9SMartin K. Petersen 	struct scsi_vpd __rcu *vpd_pgb2;
152e60ac0b9SMartin K. Petersen 
153886874afSBart Van Assche 	struct scsi_target      *sdev_target;
1541da177e4SLinus Torvalds 
1555ebde469SHannes Reinecke 	blist_flags_t		sdev_bflags; /* black/white flags as also found in
1561da177e4SLinus Torvalds 				 * scsi_devinfo.[hc]. For now used only to
1571da177e4SLinus Torvalds 				 * pass settings from slave_alloc to scsi
1581da177e4SLinus Torvalds 				 * core. */
1590816c925SMartin K. Petersen 	unsigned int eh_timeout; /* Error handling timeout */
1603cc2ffe5SDamien Le Moal 
16124eca2dcSDamien Le Moal 	/*
16224eca2dcSDamien Le Moal 	 * If true, let the high-level device driver (sd) manage the device
16324eca2dcSDamien Le Moal 	 * power state for system suspend/resume (suspend to RAM and
16424eca2dcSDamien Le Moal 	 * hibernation) operations.
16524eca2dcSDamien Le Moal 	 */
16680fb1378SDamien Le Moal 	unsigned manage_system_start_stop:1;
16724eca2dcSDamien Le Moal 
16824eca2dcSDamien Le Moal 	/*
16924eca2dcSDamien Le Moal 	 * If true, let the high-level device driver (sd) manage the device
17024eca2dcSDamien Le Moal 	 * power state for runtime device suspand and resume operations.
17124eca2dcSDamien Le Moal 	 */
17280fb1378SDamien Le Moal 	unsigned manage_runtime_start_stop:1;
17324eca2dcSDamien Le Moal 
17424eca2dcSDamien Le Moal 	/*
17524eca2dcSDamien Le Moal 	 * If true, let the high-level device driver (sd) manage the device
17624eca2dcSDamien Le Moal 	 * power state for system shutdown (power off) operations.
17724eca2dcSDamien Le Moal 	 */
17880fb1378SDamien Le Moal 	unsigned manage_shutdown:1;
1793cc2ffe5SDamien Le Moal 
180b32c0a7cSDamien Le Moal 	/*
181b32c0a7cSDamien Le Moal 	 * If set and if the device is runtime suspended, ask the high-level
182b32c0a7cSDamien Le Moal 	 * device driver (sd) to force a runtime resume of the device.
183b32c0a7cSDamien Le Moal 	 */
184b32c0a7cSDamien Le Moal 	unsigned force_runtime_start_on_system_start:1;
185b32c0a7cSDamien Le Moal 
1861da177e4SLinus Torvalds 	unsigned removable:1;
1871da177e4SLinus Torvalds 	unsigned changed:1;	/* Data invalid due to media change */
1881da177e4SLinus Torvalds 	unsigned busy:1;	/* Used to prevent races */
1891da177e4SLinus Torvalds 	unsigned lockable:1;	/* Able to prevent media removal */
1901da177e4SLinus Torvalds 	unsigned locked:1;      /* Media removal disabled */
1911da177e4SLinus Torvalds 	unsigned borken:1;	/* Tell the Seagate driver to be
1921da177e4SLinus Torvalds 				 * painfully slow on this device */
1931da177e4SLinus Torvalds 	unsigned disconnect:1;	/* can disconnect */
1941da177e4SLinus Torvalds 	unsigned soft_reset:1;	/* Uses soft reset option */
1951da177e4SLinus Torvalds 	unsigned sdtr:1;	/* Device supports SDTR messages */
1961da177e4SLinus Torvalds 	unsigned wdtr:1;	/* Device supports WDTR messages */
1971da177e4SLinus Torvalds 	unsigned ppr:1;		/* Device supports PPR messages */
1981da177e4SLinus Torvalds 	unsigned tagged_supported:1;	/* Supports SCSI-II tagged queuing */
1991da177e4SLinus Torvalds 	unsigned simple_tags:1;	/* simple queue tag messages are enabled */
2001da177e4SLinus Torvalds 	unsigned was_reset:1;	/* There was a bus reset on the bus for
2011da177e4SLinus Torvalds 				 * this device */
2021da177e4SLinus Torvalds 	unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
2031da177e4SLinus Torvalds 				     * because we did a bus reset. */
2041da177e4SLinus Torvalds 	unsigned use_10_for_rw:1; /* first try 10-byte read / write */
2051da177e4SLinus Torvalds 	unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */
2060ec96913SCan Guo 	unsigned set_dbd_for_ms:1; /* Set "DBD" field in mode sense */
207*9eb04addSMartin K. Petersen 	unsigned read_before_ms:1;	/* perform a READ before MODE SENSE */
2083c6bdaeaSMartin K. Petersen 	unsigned no_report_opcodes:1;	/* no REPORT SUPPORTED OPERATION CODES */
2095db44863SMartin K. Petersen 	unsigned no_write_same:1;	/* no WRITE SAME command */
21053ad570bSJason J. Herne 	unsigned use_16_for_rw:1; /* Use read/write(16) over read/write(10) */
21142c59077SShin'ichiro Kawasaki 	unsigned use_16_for_sync:1;	/* Use sync (16) over sync (10) */
2121da177e4SLinus Torvalds 	unsigned skip_ms_page_8:1;	/* do not use MODE SENSE page 0x08 */
2131da177e4SLinus Torvalds 	unsigned skip_ms_page_3f:1;	/* do not use MODE SENSE page 0x3f */
21409b6b51bSAlan Stern 	unsigned skip_vpd_pages:1;	/* do not read VPD pages */
215c1d40a52SMartin K. Petersen 	unsigned try_vpd_pages:1;	/* attempt to read VPD pages */
2161da177e4SLinus Torvalds 	unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
2171da177e4SLinus Torvalds 	unsigned no_start_on_add:1;	/* do not issue start on add */
2181da177e4SLinus Torvalds 	unsigned allow_restart:1; /* issue START_UNIT in error handler */
219d2886ea3SStefan Richter 	unsigned start_stop_pwr_cond:1;	/* Set power cond. in START_STOP_UNIT */
2201da177e4SLinus Torvalds 	unsigned no_uld_attach:1; /* disable connecting to upper level drivers */
2211da177e4SLinus Torvalds 	unsigned select_no_atn:1;
2221da177e4SLinus Torvalds 	unsigned fix_capacity:1;	/* READ_CAPACITY is too high by 1 */
22361bf54b7SOliver Neukum 	unsigned guess_capacity:1;	/* READ_CAPACITY might be too high by 1 */
2241da177e4SLinus Torvalds 	unsigned retry_hwerror:1;	/* Retry HARDWARE_ERROR */
22518351070SLinus Torvalds 	unsigned last_sector_bug:1;	/* do not use multisector accesses on
22618351070SLinus Torvalds 					   SD_LAST_BUGGY_SECTORS */
2278e04d805SHans de Goede 	unsigned no_read_disc_info:1;	/* Avoid READ_DISC_INFO cmds */
2285ce524bdSHans de Goede 	unsigned no_read_capacity_16:1; /* Avoid READ_CAPACITY_16 cmds */
2296a0bdffaSAlan Stern 	unsigned try_rc_10_first:1;	/* Try READ_CAPACACITY_10 first */
230d80210f2SChristoph Hellwig 	unsigned security_supported:1;	/* Supports Security Protocols */
231860dc736SJames Bottomley 	unsigned is_visible:1;	/* is the device visible in sysfs */
232b81478d8SNamjae Jeon 	unsigned wce_default_on:1;	/* Cache is ON by default */
233d974e426SMartin K. Petersen 	unsigned no_dif:1;	/* T10 PI (DIF) should be disabled */
234b14bf2d0SAlan Stern 	unsigned broken_fua:1;		/* Don't set FUA bit */
23550c4e964SAlan Stern 	unsigned lun_in_cdb:1;		/* Store LUN bits in CDB[1] */
23628a0bc41SMartin K. Petersen 	unsigned unmap_limit_for_ws:1;	/* Use the UNMAP limit for WRITE SAME */
237c74f8056SStanley Chu 	unsigned rpm_autosuspend:1;	/* Enable runtime autosuspend at device
238c74f8056SStanley Chu 					 * creation time */
239f591a2e0SMartin Kepplinger 	unsigned ignore_media_change:1; /* Ignore MEDIA CHANGE on resume */
240af4edb1dSAdrian Hunter 	unsigned silence_suspend:1;	/* Do not print runtime PM related messages */
2414b1a2c2aSLee Duncan 	unsigned no_vpd_size:1;		/* No VPD size reported in header */
242b0962c53SEwan D. Milne 
24362488520SDamien Le Moal 	unsigned cdl_supported:1;	/* Command duration limits supported */
2441b22cfb1SDamien Le Moal 	unsigned cdl_enable:1;		/* Enable/disable Command duration limits */
24562488520SDamien Le Moal 
24693542fbfSMing Lei 	unsigned int queue_stopped;	/* request queue is quiesced */
247b0962c53SEwan D. Milne 	bool offline_already;		/* Device offline message logged */
248b0962c53SEwan D. Milne 
2496f4c827eSAaron Lu 	atomic_t disk_events_disable_depth; /* disable depth for disk events */
2506f4c827eSAaron Lu 
251a341cd0fSJeff Garzik 	DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */
252279afdfeSEwan D. Milne 	DECLARE_BITMAP(pending_events, SDEV_EVT_MAXBITS); /* pending events */
253a341cd0fSJeff Garzik 	struct list_head event_list;	/* asserted events */
254a341cd0fSJeff Garzik 	struct work_struct event_work;
255a341cd0fSJeff Garzik 
2561da177e4SLinus Torvalds 	unsigned int max_device_blocked; /* what device_blocked counts down from  */
2571da177e4SLinus Torvalds #define SCSI_DEFAULT_DEVICE_BLOCKED	3
2581da177e4SLinus Torvalds 
2591da177e4SLinus Torvalds 	atomic_t iorequest_cnt;
2601da177e4SLinus Torvalds 	atomic_t iodone_cnt;
2611da177e4SLinus Torvalds 	atomic_t ioerr_cnt;
26248517eefSWu Bo 	atomic_t iotmo_cnt;
2631da177e4SLinus Torvalds 
264ee959b00STony Jones 	struct device		sdev_gendev,
265ee959b00STony Jones 				sdev_dev;
2661da177e4SLinus Torvalds 
2679937a5e2SJens Axboe 	struct work_struct	requeue_work;
268ffedb452SJames Bottomley 
269ee14c674SChristoph Hellwig 	struct scsi_device_handler *handler;
270ee14c674SChristoph Hellwig 	void			*handler_data;
271ee14c674SChristoph Hellwig 
272cc97923aSChristoph Hellwig 	size_t			dma_drain_len;
273cc97923aSChristoph Hellwig 	void			*dma_drain_buf;
274cc97923aSChristoph Hellwig 
2751e61c1a8SChristoph Hellwig 	unsigned int		sg_timeout;
2761e61c1a8SChristoph Hellwig 	unsigned int		sg_reserved_size;
2771e61c1a8SChristoph Hellwig 
278ead09dd3SChristoph Hellwig 	struct bsg_device	*bsg_dev;
27977c9df96SHannes Reinecke 	unsigned char		access_state;
2800db6ca8aSBart Van Assche 	struct mutex		state_mutex;
2811da177e4SLinus Torvalds 	enum scsi_device_state sdev_state;
2823a0a5299SBart Van Assche 	struct task_struct	*quiesced_by;
2835febf6d6SGustavo A. R. Silva 	unsigned long		sdev_data[];
2841da177e4SLinus Torvalds } __attribute__((aligned(sizeof(unsigned long))));
285a6a8d9f8SChandra Seetharaman 
2861da177e4SLinus Torvalds #define	to_scsi_device(d)	\
2871da177e4SLinus Torvalds 	container_of(d, struct scsi_device, sdev_gendev)
2881da177e4SLinus Torvalds #define	class_to_sdev(d)	\
289ee959b00STony Jones 	container_of(d, struct scsi_device, sdev_dev)
2901da177e4SLinus Torvalds #define transport_class_to_sdev(class_dev) \
291ee959b00STony Jones 	to_scsi_device(class_dev->parent)
2921da177e4SLinus Torvalds 
2933af74a3cSDan Williams #define sdev_dbg(sdev, fmt, a...) \
2943af74a3cSDan Williams 	dev_dbg(&(sdev)->sdev_gendev, fmt, ##a)
2953af74a3cSDan Williams 
29622e0d994SHannes Reinecke /*
29722e0d994SHannes Reinecke  * like scmd_printk, but the device name is passed in
29822e0d994SHannes Reinecke  * as a string pointer
29922e0d994SHannes Reinecke  */
3009c4a6b1eSHannes Reinecke __printf(4, 5) void
3016a806cbcSChristoph Hellwig sdev_prefix_printk(const char *, const struct scsi_device *, const char *,
3026a806cbcSChristoph Hellwig 		const char *, ...);
30322e0d994SHannes Reinecke 
304ded85c19SHannes Reinecke #define sdev_printk(l, sdev, fmt, a...)				\
305ded85c19SHannes Reinecke 	sdev_prefix_printk(l, sdev, NULL, fmt, ##a)
306ded85c19SHannes Reinecke 
3079c4a6b1eSHannes Reinecke __printf(3, 4) void
3086a806cbcSChristoph Hellwig scmd_printk(const char *, const struct scsi_cmnd *, const char *, ...);
30901d7b3b8SJeff Garzik 
3103af74a3cSDan Williams #define scmd_dbg(scmd, fmt, a...)					\
3113af74a3cSDan Williams 	do {								\
312aa8e25e5SBart Van Assche 		struct request *__rq = scsi_cmd_to_rq((scmd));		\
313aa8e25e5SBart Van Assche 									\
314f3fa33acSChristoph Hellwig 		if (__rq->q->disk)					\
3153af74a3cSDan Williams 			sdev_dbg((scmd)->device, "[%s] " fmt,		\
316f3fa33acSChristoph Hellwig 				 __rq->q->disk->disk_name, ##a);	\
3173af74a3cSDan Williams 		else							\
3183af74a3cSDan Williams 			sdev_dbg((scmd)->device, fmt, ##a);		\
3193af74a3cSDan Williams 	} while (0)
3203af74a3cSDan Williams 
321ffedb452SJames Bottomley enum scsi_target_state {
322643eb2d9SJames Bottomley 	STARGET_CREATED = 1,
323643eb2d9SJames Bottomley 	STARGET_RUNNING,
324f05795d3SJohannes Thumshirn 	STARGET_REMOVE,
325f9279c96SEwan D. Milne 	STARGET_CREATED_REMOVE,
326ffedb452SJames Bottomley 	STARGET_DEL,
327ffedb452SJames Bottomley };
328ffedb452SJames Bottomley 
3291da177e4SLinus Torvalds /*
3301da177e4SLinus Torvalds  * scsi_target: representation of a scsi target, for now, this is only
3311da177e4SLinus Torvalds  * used for single_lun devices. If no one has active IO to the target,
3321da177e4SLinus Torvalds  * starget_sdev_user is NULL, else it points to the active sdev.
3331da177e4SLinus Torvalds  */
3341da177e4SLinus Torvalds struct scsi_target {
3351da177e4SLinus Torvalds 	struct scsi_device	*starget_sdev_user;
3361da177e4SLinus Torvalds 	struct list_head	siblings;
3371da177e4SLinus Torvalds 	struct list_head	devices;
3381da177e4SLinus Torvalds 	struct device		dev;
339e63ed0d7SJames Bottomley 	struct kref		reap_ref; /* last put renders target invisible */
3401da177e4SLinus Torvalds 	unsigned int		channel;
3411da177e4SLinus Torvalds 	unsigned int		id; /* target id ... replace
3421da177e4SLinus Torvalds 				     * scsi_device.id eventually */
3431bfc5d9dSAlan Stern 	unsigned int		create:1; /* signal that it needs to be added */
34425d7c363STony Battersby 	unsigned int		single_lun:1;	/* Indicates we should only
34525d7c363STony Battersby 						 * allow I/O to one of the luns
34625d7c363STony Battersby 						 * for the device at a time. */
347de8c46bfSAlan Stern 	unsigned int		pdt_1f_for_no_lun:1;	/* PDT = 0x1f
348de8c46bfSAlan Stern 						 * means no lun present. */
34909b6b51bSAlan Stern 	unsigned int		no_report_luns:1;	/* Don't use
35009b6b51bSAlan Stern 						 * REPORT LUNS for scanning. */
351279afdfeSEwan D. Milne 	unsigned int		expecting_lun_change:1;	/* A device has reported
352279afdfeSEwan D. Milne 						 * a 3F/0E UA, other devices on
353279afdfeSEwan D. Milne 						 * the same target will also. */
3547ae65c0fSChristoph Hellwig 	/* commands actually active on LLD. */
3557ae65c0fSChristoph Hellwig 	atomic_t		target_busy;
356cd9070c9SChristoph Hellwig 	atomic_t		target_blocked;
357cd9070c9SChristoph Hellwig 
358f0c0a376SMike Christie 	/*
359f0c0a376SMike Christie 	 * LLDs should set this in the slave_alloc host template callout.
360f0c0a376SMike Christie 	 * If set to zero then there is not limit.
361f0c0a376SMike Christie 	 */
362f0c0a376SMike Christie 	unsigned int		can_queue;
363f0c0a376SMike Christie 	unsigned int		max_target_blocked;
364f0c0a376SMike Christie #define SCSI_DEFAULT_TARGET_BLOCKED	3
3651bfc5d9dSAlan Stern 
3666f3a2024SJames Bottomley 	char			scsi_level;
367ffedb452SJames Bottomley 	enum scsi_target_state	state;
368a283bd37SJames Bottomley 	void 			*hostdata; /* available to low-level driver */
3695febf6d6SGustavo A. R. Silva 	unsigned long		starget_data[]; /* for the transport */
370a283bd37SJames Bottomley 	/* starget_data must be the last element!!!! */
3711da177e4SLinus Torvalds } __attribute__((aligned(sizeof(unsigned long))));
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds #define to_scsi_target(d)	container_of(d, struct scsi_target, dev)
scsi_target(struct scsi_device * sdev)3741da177e4SLinus Torvalds static inline struct scsi_target *scsi_target(struct scsi_device *sdev)
3751da177e4SLinus Torvalds {
3761da177e4SLinus Torvalds 	return to_scsi_target(sdev->sdev_gendev.parent);
3771da177e4SLinus Torvalds }
3781da177e4SLinus Torvalds #define transport_class_to_starget(class_dev) \
379ee959b00STony Jones 	to_scsi_target(class_dev->parent)
3801da177e4SLinus Torvalds 
3819ccfc756SJames Bottomley #define starget_printk(prefix, starget, fmt, a...)	\
3829ccfc756SJames Bottomley 	dev_printk(prefix, &(starget)->dev, fmt, ##a)
3839ccfc756SJames Bottomley 
3841da177e4SLinus Torvalds extern struct scsi_device *__scsi_add_device(struct Scsi_Host *,
3859cb78c16SHannes Reinecke 		uint, uint, u64, void *hostdata);
386146f7262SJames Bottomley extern int scsi_add_device(struct Scsi_Host *host, uint channel,
3879cb78c16SHannes Reinecke 			   uint target, u64 lun);
388a6a8d9f8SChandra Seetharaman extern int scsi_register_device_handler(struct scsi_device_handler *scsi_dh);
3891da177e4SLinus Torvalds extern void scsi_remove_device(struct scsi_device *);
390a6a8d9f8SChandra Seetharaman extern int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh);
391b3ae8780SHannes Reinecke void scsi_attach_vpd(struct scsi_device *sdev);
39262488520SDamien Le Moal void scsi_cdl_check(struct scsi_device *sdev);
3931b22cfb1SDamien Le Moal int scsi_cdl_enable(struct scsi_device *sdev, bool enable);
3941da177e4SLinus Torvalds 
395857de6e0SHannes Reinecke extern struct scsi_device *scsi_device_from_queue(struct request_queue *q);
396ed12e031SBart Van Assche extern int __must_check scsi_device_get(struct scsi_device *);
3971da177e4SLinus Torvalds extern void scsi_device_put(struct scsi_device *);
3981da177e4SLinus Torvalds extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,
3999cb78c16SHannes Reinecke 					      uint, uint, u64);
4001da177e4SLinus Torvalds extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *,
4019cb78c16SHannes Reinecke 						uint, uint, u64);
4021da177e4SLinus Torvalds extern struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *,
4039cb78c16SHannes Reinecke 							u64);
4041da177e4SLinus Torvalds extern struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *,
4059cb78c16SHannes Reinecke 							  u64);
4061da177e4SLinus Torvalds extern void starget_for_each_device(struct scsi_target *, void *,
4071da177e4SLinus Torvalds 		     void (*fn)(struct scsi_device *, void *));
408522939d4SMaciej W. Rozycki extern void __starget_for_each_device(struct scsi_target *, void *,
409522939d4SMaciej W. Rozycki 				      void (*fn)(struct scsi_device *,
410522939d4SMaciej W. Rozycki 						 void *));
4111da177e4SLinus Torvalds 
4121da177e4SLinus Torvalds /* only exposed to implement shost_for_each_device */
4131da177e4SLinus Torvalds extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
4141da177e4SLinus Torvalds 						  struct scsi_device *);
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds /**
4171da177e4SLinus Torvalds  * shost_for_each_device - iterate over all devices of a host
4183e082a91SMatthew Wilcox  * @sdev: the &struct scsi_device to use as a cursor
4193e082a91SMatthew Wilcox  * @shost: the &struct scsi_host to iterate over
4201da177e4SLinus Torvalds  *
4213e082a91SMatthew Wilcox  * Iterator that returns each device attached to @shost.  This loop
4223e082a91SMatthew Wilcox  * takes a reference on each device and releases it at the end.  If
4233e082a91SMatthew Wilcox  * you break out of the loop, you must call scsi_device_put(sdev).
4241da177e4SLinus Torvalds  */
4251da177e4SLinus Torvalds #define shost_for_each_device(sdev, shost) \
4261da177e4SLinus Torvalds 	for ((sdev) = __scsi_iterate_devices((shost), NULL); \
4271da177e4SLinus Torvalds 	     (sdev); \
4281da177e4SLinus Torvalds 	     (sdev) = __scsi_iterate_devices((shost), (sdev)))
4291da177e4SLinus Torvalds 
4301da177e4SLinus Torvalds /**
4311da177e4SLinus Torvalds  * __shost_for_each_device - iterate over all devices of a host (UNLOCKED)
4323e082a91SMatthew Wilcox  * @sdev: the &struct scsi_device to use as a cursor
4333e082a91SMatthew Wilcox  * @shost: the &struct scsi_host to iterate over
4341da177e4SLinus Torvalds  *
4353e082a91SMatthew Wilcox  * Iterator that returns each device attached to @shost.  It does _not_
4363e082a91SMatthew Wilcox  * take a reference on the scsi_device, so the whole loop must be
4373e082a91SMatthew Wilcox  * protected by shost->host_lock.
4381da177e4SLinus Torvalds  *
4393e082a91SMatthew Wilcox  * Note: The only reason to use this is because you need to access the
4403e082a91SMatthew Wilcox  * device list in interrupt context.  Otherwise you really want to use
4413e082a91SMatthew Wilcox  * shost_for_each_device instead.
4421da177e4SLinus Torvalds  */
4431da177e4SLinus Torvalds #define __shost_for_each_device(sdev, shost) \
4441da177e4SLinus Torvalds 	list_for_each_entry((sdev), &((shost)->__devices), siblings)
4451da177e4SLinus Torvalds 
446db5ed4dfSChristoph Hellwig extern int scsi_change_queue_depth(struct scsi_device *, int);
4471da177e4SLinus Torvalds extern int scsi_track_queue_full(struct scsi_device *, int);
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds extern int scsi_set_medium_removal(struct scsi_device *, char);
4501da177e4SLinus Torvalds 
451a6cdc35fSDamien Le Moal int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
452a6cdc35fSDamien Le Moal 		    int subpage, unsigned char *buffer, int len, int timeout,
4531cf72699SJames Bottomley 		    int retries, struct scsi_mode_data *data,
454ea73a9f2SJames Bottomley 		    struct scsi_sense_hdr *);
4555baba830SJames Bottomley extern int scsi_mode_select(struct scsi_device *sdev, int pf, int sp,
45681d3f500SDamien Le Moal 			    unsigned char *buffer, int len, int timeout,
45781d3f500SDamien Le Moal 			    int retries, struct scsi_mode_data *data,
4585baba830SJames Bottomley 			    struct scsi_sense_hdr *);
4591da177e4SLinus Torvalds extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout,
460001aac25SJames Bottomley 				int retries, struct scsi_sense_hdr *sshdr);
461e3deec09SJames Bottomley extern int scsi_get_vpd_page(struct scsi_device *, u8 page, unsigned char *buf,
462e3deec09SJames Bottomley 			     int buf_len);
463152e52fbSDamien Le Moal int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer,
464152e52fbSDamien Le Moal 		       unsigned int len, unsigned char opcode,
465152e52fbSDamien Le Moal 		       unsigned short sa);
4661da177e4SLinus Torvalds extern int scsi_device_set_state(struct scsi_device *sdev,
4671da177e4SLinus Torvalds 				 enum scsi_device_state state);
468a341cd0fSJeff Garzik extern struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type,
469a341cd0fSJeff Garzik 					  gfp_t gfpflags);
470a341cd0fSJeff Garzik extern void sdev_evt_send(struct scsi_device *sdev, struct scsi_event *evt);
471a341cd0fSJeff Garzik extern void sdev_evt_send_simple(struct scsi_device *sdev,
472a341cd0fSJeff Garzik 			  enum scsi_device_event evt_type, gfp_t gfpflags);
4731da177e4SLinus Torvalds extern int scsi_device_quiesce(struct scsi_device *sdev);
4741da177e4SLinus Torvalds extern void scsi_device_resume(struct scsi_device *sdev);
4751da177e4SLinus Torvalds extern void scsi_target_quiesce(struct scsi_target *);
4761da177e4SLinus Torvalds extern void scsi_target_resume(struct scsi_target *);
4771da177e4SLinus Torvalds extern void scsi_scan_target(struct device *parent, unsigned int channel,
4781d645088SHannes Reinecke 			     unsigned int id, u64 lun,
4791d645088SHannes Reinecke 			     enum scsi_scan_mode rescan);
4801da177e4SLinus Torvalds extern void scsi_target_reap(struct scsi_target *);
48131950192SMartin Wilck void scsi_block_targets(struct Scsi_Host *shost, struct device *dev);
4825d9fb5ccSMike Christie extern void scsi_target_unblock(struct device *, enum scsi_device_state);
4831da177e4SLinus Torvalds extern void scsi_remove_target(struct device *);
4841da177e4SLinus Torvalds extern const char *scsi_device_state_name(enum scsi_device_state);
4851da177e4SLinus Torvalds extern int scsi_is_sdev_device(const struct device *);
4861da177e4SLinus Torvalds extern int scsi_is_target_device(const struct device *);
4873846470aSDon Brace extern void scsi_sanitize_inquiry_string(unsigned char *s, int len);
488d0949565SMike Christie 
489d0949565SMike Christie /* Optional arguments to scsi_execute_cmd */
490d0949565SMike Christie struct scsi_exec_args {
491d0949565SMike Christie 	unsigned char *sense;		/* sense buffer */
492d0949565SMike Christie 	unsigned int sense_len;		/* sense buffer len */
493d0949565SMike Christie 	struct scsi_sense_hdr *sshdr;	/* decoded sense header */
494d0949565SMike Christie 	blk_mq_req_flags_t req_flags;	/* BLK_MQ_REQ flags */
49535cd2f55SBart Van Assche 	int scmd_flags;			/* SCMD flags */
496d0949565SMike Christie 	int *resid;			/* residual length */
497d0949565SMike Christie };
498d0949565SMike Christie 
499d0949565SMike Christie int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
500d0949565SMike Christie 		     blk_opf_t opf, void *buffer, unsigned int bufflen,
501d0949565SMike Christie 		     int timeout, int retries,
502d0949565SMike Christie 		     const struct scsi_exec_args *args);
503d0949565SMike Christie 
5046f4c827eSAaron Lu extern void sdev_disable_disk_events(struct scsi_device *sdev);
5056f4c827eSAaron Lu extern void sdev_enable_disk_events(struct scsi_device *sdev);
5069983bed3SHannes Reinecke extern int scsi_vpd_lun_id(struct scsi_device *, char *, size_t);
507a8aa3978SHannes Reinecke extern int scsi_vpd_tpg_id(struct scsi_device *, int *);
508ea73a9f2SJames Bottomley 
5094f7ad521SRafael J. Wysocki #ifdef CONFIG_PM
510bc4f2401SAlan Stern extern int scsi_autopm_get_device(struct scsi_device *);
511bc4f2401SAlan Stern extern void scsi_autopm_put_device(struct scsi_device *);
512bc4f2401SAlan Stern #else
scsi_autopm_get_device(struct scsi_device * d)513bc4f2401SAlan Stern static inline int scsi_autopm_get_device(struct scsi_device *d) { return 0; }
scsi_autopm_put_device(struct scsi_device * d)514bc4f2401SAlan Stern static inline void scsi_autopm_put_device(struct scsi_device *d) {}
5154f7ad521SRafael J. Wysocki #endif /* CONFIG_PM */
516bc4f2401SAlan Stern 
scsi_device_reprobe(struct scsi_device * sdev)517cb5d9e09SAndrew Morton static inline int __must_check scsi_device_reprobe(struct scsi_device *sdev)
518e28482c5SJames Bottomley {
519cb5d9e09SAndrew Morton 	return device_reprobe(&sdev->sdev_gendev);
520e28482c5SJames Bottomley }
521e28482c5SJames Bottomley 
sdev_channel(struct scsi_device * sdev)52201d7b3b8SJeff Garzik static inline unsigned int sdev_channel(struct scsi_device *sdev)
52301d7b3b8SJeff Garzik {
52401d7b3b8SJeff Garzik 	return sdev->channel;
52501d7b3b8SJeff Garzik }
52601d7b3b8SJeff Garzik 
sdev_id(struct scsi_device * sdev)52701d7b3b8SJeff Garzik static inline unsigned int sdev_id(struct scsi_device *sdev)
52801d7b3b8SJeff Garzik {
52901d7b3b8SJeff Garzik 	return sdev->id;
53001d7b3b8SJeff Garzik }
53101d7b3b8SJeff Garzik 
53201d7b3b8SJeff Garzik #define scmd_id(scmd) sdev_id((scmd)->device)
53301d7b3b8SJeff Garzik #define scmd_channel(scmd) sdev_channel((scmd)->device)
53401d7b3b8SJeff Garzik 
5350f1d87a2SJames Bottomley /*
5360f1d87a2SJames Bottomley  * checks for positions of the SCSI state machine
5370f1d87a2SJames Bottomley  */
scsi_device_online(struct scsi_device * sdev)5381da177e4SLinus Torvalds static inline int scsi_device_online(struct scsi_device *sdev)
5391da177e4SLinus Torvalds {
5400762a482SHannes Reinecke 	return (sdev->sdev_state != SDEV_OFFLINE &&
5411b8d2620SMike Christie 		sdev->sdev_state != SDEV_TRANSPORT_OFFLINE &&
5420762a482SHannes Reinecke 		sdev->sdev_state != SDEV_DEL);
5431da177e4SLinus Torvalds }
scsi_device_blocked(struct scsi_device * sdev)5440f1d87a2SJames Bottomley static inline int scsi_device_blocked(struct scsi_device *sdev)
5450f1d87a2SJames Bottomley {
5466f4267e3SJames Bottomley 	return sdev->sdev_state == SDEV_BLOCK ||
5476f4267e3SJames Bottomley 		sdev->sdev_state == SDEV_CREATED_BLOCK;
5480f1d87a2SJames Bottomley }
scsi_device_created(struct scsi_device * sdev)5490f1d87a2SJames Bottomley static inline int scsi_device_created(struct scsi_device *sdev)
5500f1d87a2SJames Bottomley {
5516f4267e3SJames Bottomley 	return sdev->sdev_state == SDEV_CREATED ||
5526f4267e3SJames Bottomley 		sdev->sdev_state == SDEV_CREATED_BLOCK;
5530f1d87a2SJames Bottomley }
5541da177e4SLinus Torvalds 
555551eb598SBart Van Assche int scsi_internal_device_block_nowait(struct scsi_device *sdev);
55643f7571bSBart Van Assche int scsi_internal_device_unblock_nowait(struct scsi_device *sdev,
5578893cf6cSBart Van Assche 					enum scsi_device_state new_state);
5588893cf6cSBart Van Assche 
5591da177e4SLinus Torvalds /* accessor functions for the SCSI parameters */
scsi_device_sync(struct scsi_device * sdev)5601da177e4SLinus Torvalds static inline int scsi_device_sync(struct scsi_device *sdev)
5611da177e4SLinus Torvalds {
5621da177e4SLinus Torvalds 	return sdev->sdtr;
5631da177e4SLinus Torvalds }
scsi_device_wide(struct scsi_device * sdev)5641da177e4SLinus Torvalds static inline int scsi_device_wide(struct scsi_device *sdev)
5651da177e4SLinus Torvalds {
5661da177e4SLinus Torvalds 	return sdev->wdtr;
5671da177e4SLinus Torvalds }
scsi_device_dt(struct scsi_device * sdev)5681da177e4SLinus Torvalds static inline int scsi_device_dt(struct scsi_device *sdev)
5691da177e4SLinus Torvalds {
5701da177e4SLinus Torvalds 	return sdev->ppr;
5711da177e4SLinus Torvalds }
scsi_device_dt_only(struct scsi_device * sdev)5721da177e4SLinus Torvalds static inline int scsi_device_dt_only(struct scsi_device *sdev)
5731da177e4SLinus Torvalds {
5741da177e4SLinus Torvalds 	if (sdev->inquiry_len < 57)
5751da177e4SLinus Torvalds 		return 0;
5761da177e4SLinus Torvalds 	return (sdev->inquiry[56] & 0x0c) == 0x04;
5771da177e4SLinus Torvalds }
scsi_device_ius(struct scsi_device * sdev)5781da177e4SLinus Torvalds static inline int scsi_device_ius(struct scsi_device *sdev)
5791da177e4SLinus Torvalds {
5801da177e4SLinus Torvalds 	if (sdev->inquiry_len < 57)
5811da177e4SLinus Torvalds 		return 0;
5821da177e4SLinus Torvalds 	return sdev->inquiry[56] & 0x01;
5831da177e4SLinus Torvalds }
scsi_device_qas(struct scsi_device * sdev)5841da177e4SLinus Torvalds static inline int scsi_device_qas(struct scsi_device *sdev)
5851da177e4SLinus Torvalds {
5861da177e4SLinus Torvalds 	if (sdev->inquiry_len < 57)
5871da177e4SLinus Torvalds 		return 0;
5881da177e4SLinus Torvalds 	return sdev->inquiry[56] & 0x02;
5891da177e4SLinus Torvalds }
scsi_device_enclosure(struct scsi_device * sdev)590b30c2fc1SJames Bottomley static inline int scsi_device_enclosure(struct scsi_device *sdev)
591b30c2fc1SJames Bottomley {
592d1e12de8SKrishnasamy, Somasundaram 	return sdev->inquiry ? (sdev->inquiry[6] & (1<<6)) : 1;
593b30c2fc1SJames Bottomley }
594d7b8bcb0SMichael Tokarev 
scsi_device_protection(struct scsi_device * sdev)5957027ad72SMartin K. Petersen static inline int scsi_device_protection(struct scsi_device *sdev)
5967027ad72SMartin K. Petersen {
597d974e426SMartin K. Petersen 	if (sdev->no_dif)
598d974e426SMartin K. Petersen 		return 0;
599d974e426SMartin K. Petersen 
600d211f052SHugh Dickins 	return sdev->scsi_level > SCSI_2 && sdev->inquiry[5] & (1<<0);
6017027ad72SMartin K. Petersen }
6027027ad72SMartin K. Petersen 
scsi_device_tpgs(struct scsi_device * sdev)603d7c48febSHannes Reinecke static inline int scsi_device_tpgs(struct scsi_device *sdev)
604d7c48febSHannes Reinecke {
605d7c48febSHannes Reinecke 	return sdev->inquiry ? (sdev->inquiry[5] >> 4) & 0x3 : 0;
606d7c48febSHannes Reinecke }
607d7c48febSHannes Reinecke 
6085ddfe085SHannes Reinecke /**
6095ddfe085SHannes Reinecke  * scsi_device_supports_vpd - test if a device supports VPD pages
6105ddfe085SHannes Reinecke  * @sdev: the &struct scsi_device to test
6115ddfe085SHannes Reinecke  *
6125ddfe085SHannes Reinecke  * If the 'try_vpd_pages' flag is set it takes precedence.
6135ddfe085SHannes Reinecke  * Otherwise we will assume VPD pages are supported if the
6145ddfe085SHannes Reinecke  * SCSI level is at least SPC-3 and 'skip_vpd_pages' is not set.
6155ddfe085SHannes Reinecke  */
scsi_device_supports_vpd(struct scsi_device * sdev)6165ddfe085SHannes Reinecke static inline int scsi_device_supports_vpd(struct scsi_device *sdev)
6175ddfe085SHannes Reinecke {
6185ddfe085SHannes Reinecke 	/* Attempt VPD inquiry if the device blacklist explicitly calls
6195ddfe085SHannes Reinecke 	 * for it.
6205ddfe085SHannes Reinecke 	 */
6215ddfe085SHannes Reinecke 	if (sdev->try_vpd_pages)
6225ddfe085SHannes Reinecke 		return 1;
6235ddfe085SHannes Reinecke 	/*
6245ddfe085SHannes Reinecke 	 * Although VPD inquiries can go to SCSI-2 type devices,
6255ddfe085SHannes Reinecke 	 * some USB ones crash on receiving them, and the pages
626e4c36ad7SHannes Reinecke 	 * we currently ask for are mandatory for SPC-2 and beyond
6275ddfe085SHannes Reinecke 	 */
628e4c36ad7SHannes Reinecke 	if (sdev->scsi_level >= SCSI_SPC_2 && !sdev->skip_vpd_pages)
6295ddfe085SHannes Reinecke 		return 1;
6305ddfe085SHannes Reinecke 	return 0;
6315ddfe085SHannes Reinecke }
6325ddfe085SHannes Reinecke 
scsi_device_busy(struct scsi_device * sdev)6338278807aSMing Lei static inline int scsi_device_busy(struct scsi_device *sdev)
6348278807aSMing Lei {
635020b0f0aSMing Lei 	return sbitmap_weight(&sdev->budget_map);
6368278807aSMing Lei }
6378278807aSMing Lei 
638d7b8bcb0SMichael Tokarev #define MODULE_ALIAS_SCSI_DEVICE(type) \
639d7b8bcb0SMichael Tokarev 	MODULE_ALIAS("scsi:t-" __stringify(type) "*")
640d7b8bcb0SMichael Tokarev #define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x"
641d7b8bcb0SMichael Tokarev 
6421da177e4SLinus Torvalds #endif /* _SCSI_SCSI_DEVICE_H */
643