xref: /OK3568_Linux_fs/kernel/include/scsi/scsi_host.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _SCSI_SCSI_HOST_H
3*4882a593Smuzhiyun #define _SCSI_SCSI_HOST_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <linux/device.h>
6*4882a593Smuzhiyun #include <linux/list.h>
7*4882a593Smuzhiyun #include <linux/types.h>
8*4882a593Smuzhiyun #include <linux/workqueue.h>
9*4882a593Smuzhiyun #include <linux/mutex.h>
10*4882a593Smuzhiyun #include <linux/seq_file.h>
11*4882a593Smuzhiyun #include <linux/blk-mq.h>
12*4882a593Smuzhiyun #include <scsi/scsi.h>
13*4882a593Smuzhiyun #include <linux/android_kabi.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct block_device;
16*4882a593Smuzhiyun struct completion;
17*4882a593Smuzhiyun struct module;
18*4882a593Smuzhiyun struct scsi_cmnd;
19*4882a593Smuzhiyun struct scsi_device;
20*4882a593Smuzhiyun struct scsi_host_cmd_pool;
21*4882a593Smuzhiyun struct scsi_target;
22*4882a593Smuzhiyun struct Scsi_Host;
23*4882a593Smuzhiyun struct scsi_host_cmd_pool;
24*4882a593Smuzhiyun struct scsi_transport_template;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define SG_ALL	SG_CHUNK_SIZE
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define MODE_UNKNOWN 0x00
30*4882a593Smuzhiyun #define MODE_INITIATOR 0x01
31*4882a593Smuzhiyun #define MODE_TARGET 0x02
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun struct scsi_host_template {
34*4882a593Smuzhiyun 	struct module *module;
35*4882a593Smuzhiyun 	const char *name;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	/*
38*4882a593Smuzhiyun 	 * The info function will return whatever useful information the
39*4882a593Smuzhiyun 	 * developer sees fit.  If not provided, then the name field will
40*4882a593Smuzhiyun 	 * be used instead.
41*4882a593Smuzhiyun 	 *
42*4882a593Smuzhiyun 	 * Status: OPTIONAL
43*4882a593Smuzhiyun 	 */
44*4882a593Smuzhiyun 	const char *(* info)(struct Scsi_Host *);
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	/*
47*4882a593Smuzhiyun 	 * Ioctl interface
48*4882a593Smuzhiyun 	 *
49*4882a593Smuzhiyun 	 * Status: OPTIONAL
50*4882a593Smuzhiyun 	 */
51*4882a593Smuzhiyun 	int (*ioctl)(struct scsi_device *dev, unsigned int cmd,
52*4882a593Smuzhiyun 		     void __user *arg);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
56*4882a593Smuzhiyun 	/*
57*4882a593Smuzhiyun 	 * Compat handler. Handle 32bit ABI.
58*4882a593Smuzhiyun 	 * When unknown ioctl is passed return -ENOIOCTLCMD.
59*4882a593Smuzhiyun 	 *
60*4882a593Smuzhiyun 	 * Status: OPTIONAL
61*4882a593Smuzhiyun 	 */
62*4882a593Smuzhiyun 	int (*compat_ioctl)(struct scsi_device *dev, unsigned int cmd,
63*4882a593Smuzhiyun 			    void __user *arg);
64*4882a593Smuzhiyun #endif
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	int (*init_cmd_priv)(struct Scsi_Host *shost, struct scsi_cmnd *cmd);
67*4882a593Smuzhiyun 	int (*exit_cmd_priv)(struct Scsi_Host *shost, struct scsi_cmnd *cmd);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	/*
70*4882a593Smuzhiyun 	 * The queuecommand function is used to queue up a scsi
71*4882a593Smuzhiyun 	 * command block to the LLDD.  When the driver finished
72*4882a593Smuzhiyun 	 * processing the command the done callback is invoked.
73*4882a593Smuzhiyun 	 *
74*4882a593Smuzhiyun 	 * If queuecommand returns 0, then the driver has accepted the
75*4882a593Smuzhiyun 	 * command.  It must also push it to the HBA if the scsi_cmnd
76*4882a593Smuzhiyun 	 * flag SCMD_LAST is set, or if the driver does not implement
77*4882a593Smuzhiyun 	 * commit_rqs.  The done() function must be called on the command
78*4882a593Smuzhiyun 	 * when the driver has finished with it. (you may call done on the
79*4882a593Smuzhiyun 	 * command before queuecommand returns, but in this case you
80*4882a593Smuzhiyun 	 * *must* return 0 from queuecommand).
81*4882a593Smuzhiyun 	 *
82*4882a593Smuzhiyun 	 * Queuecommand may also reject the command, in which case it may
83*4882a593Smuzhiyun 	 * not touch the command and must not call done() for it.
84*4882a593Smuzhiyun 	 *
85*4882a593Smuzhiyun 	 * There are two possible rejection returns:
86*4882a593Smuzhiyun 	 *
87*4882a593Smuzhiyun 	 *   SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
88*4882a593Smuzhiyun 	 *   allow commands to other devices serviced by this host.
89*4882a593Smuzhiyun 	 *
90*4882a593Smuzhiyun 	 *   SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
91*4882a593Smuzhiyun 	 *   host temporarily.
92*4882a593Smuzhiyun 	 *
93*4882a593Smuzhiyun          * For compatibility, any other non-zero return is treated the
94*4882a593Smuzhiyun          * same as SCSI_MLQUEUE_HOST_BUSY.
95*4882a593Smuzhiyun 	 *
96*4882a593Smuzhiyun 	 * NOTE: "temporarily" means either until the next command for#
97*4882a593Smuzhiyun 	 * this device/host completes, or a period of time determined by
98*4882a593Smuzhiyun 	 * I/O pressure in the system if there are no other outstanding
99*4882a593Smuzhiyun 	 * commands.
100*4882a593Smuzhiyun 	 *
101*4882a593Smuzhiyun 	 * STATUS: REQUIRED
102*4882a593Smuzhiyun 	 */
103*4882a593Smuzhiyun 	int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	/*
106*4882a593Smuzhiyun 	 * The commit_rqs function is used to trigger a hardware
107*4882a593Smuzhiyun 	 * doorbell after some requests have been queued with
108*4882a593Smuzhiyun 	 * queuecommand, when an error is encountered before sending
109*4882a593Smuzhiyun 	 * the request with SCMD_LAST set.
110*4882a593Smuzhiyun 	 *
111*4882a593Smuzhiyun 	 * STATUS: OPTIONAL
112*4882a593Smuzhiyun 	 */
113*4882a593Smuzhiyun 	void (*commit_rqs)(struct Scsi_Host *, u16);
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	/*
116*4882a593Smuzhiyun 	 * This is an error handling strategy routine.  You don't need to
117*4882a593Smuzhiyun 	 * define one of these if you don't want to - there is a default
118*4882a593Smuzhiyun 	 * routine that is present that should work in most cases.  For those
119*4882a593Smuzhiyun 	 * driver authors that have the inclination and ability to write their
120*4882a593Smuzhiyun 	 * own strategy routine, this is where it is specified.  Note - the
121*4882a593Smuzhiyun 	 * strategy routine is *ALWAYS* run in the context of the kernel eh
122*4882a593Smuzhiyun 	 * thread.  Thus you are guaranteed to *NOT* be in an interrupt
123*4882a593Smuzhiyun 	 * handler when you execute this, and you are also guaranteed to
124*4882a593Smuzhiyun 	 * *NOT* have any other commands being queued while you are in the
125*4882a593Smuzhiyun 	 * strategy routine. When you return from this function, operations
126*4882a593Smuzhiyun 	 * return to normal.
127*4882a593Smuzhiyun 	 *
128*4882a593Smuzhiyun 	 * See scsi_error.c scsi_unjam_host for additional comments about
129*4882a593Smuzhiyun 	 * what this function should and should not be attempting to do.
130*4882a593Smuzhiyun 	 *
131*4882a593Smuzhiyun 	 * Status: REQUIRED	(at least one of them)
132*4882a593Smuzhiyun 	 */
133*4882a593Smuzhiyun 	int (* eh_abort_handler)(struct scsi_cmnd *);
134*4882a593Smuzhiyun 	int (* eh_device_reset_handler)(struct scsi_cmnd *);
135*4882a593Smuzhiyun 	int (* eh_target_reset_handler)(struct scsi_cmnd *);
136*4882a593Smuzhiyun 	int (* eh_bus_reset_handler)(struct scsi_cmnd *);
137*4882a593Smuzhiyun 	int (* eh_host_reset_handler)(struct scsi_cmnd *);
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	/*
140*4882a593Smuzhiyun 	 * Before the mid layer attempts to scan for a new device where none
141*4882a593Smuzhiyun 	 * currently exists, it will call this entry in your driver.  Should
142*4882a593Smuzhiyun 	 * your driver need to allocate any structs or perform any other init
143*4882a593Smuzhiyun 	 * items in order to send commands to a currently unused target/lun
144*4882a593Smuzhiyun 	 * combo, then this is where you can perform those allocations.  This
145*4882a593Smuzhiyun 	 * is specifically so that drivers won't have to perform any kind of
146*4882a593Smuzhiyun 	 * "is this a new device" checks in their queuecommand routine,
147*4882a593Smuzhiyun 	 * thereby making the hot path a bit quicker.
148*4882a593Smuzhiyun 	 *
149*4882a593Smuzhiyun 	 * Return values: 0 on success, non-0 on failure
150*4882a593Smuzhiyun 	 *
151*4882a593Smuzhiyun 	 * Deallocation:  If we didn't find any devices at this ID, you will
152*4882a593Smuzhiyun 	 * get an immediate call to slave_destroy().  If we find something
153*4882a593Smuzhiyun 	 * here then you will get a call to slave_configure(), then the
154*4882a593Smuzhiyun 	 * device will be used for however long it is kept around, then when
155*4882a593Smuzhiyun 	 * the device is removed from the system (or * possibly at reboot
156*4882a593Smuzhiyun 	 * time), you will then get a call to slave_destroy().  This is
157*4882a593Smuzhiyun 	 * assuming you implement slave_configure and slave_destroy.
158*4882a593Smuzhiyun 	 * However, if you allocate memory and hang it off the device struct,
159*4882a593Smuzhiyun 	 * then you must implement the slave_destroy() routine at a minimum
160*4882a593Smuzhiyun 	 * in order to avoid leaking memory
161*4882a593Smuzhiyun 	 * each time a device is tore down.
162*4882a593Smuzhiyun 	 *
163*4882a593Smuzhiyun 	 * Status: OPTIONAL
164*4882a593Smuzhiyun 	 */
165*4882a593Smuzhiyun 	int (* slave_alloc)(struct scsi_device *);
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	/*
168*4882a593Smuzhiyun 	 * Once the device has responded to an INQUIRY and we know the
169*4882a593Smuzhiyun 	 * device is online, we call into the low level driver with the
170*4882a593Smuzhiyun 	 * struct scsi_device *.  If the low level device driver implements
171*4882a593Smuzhiyun 	 * this function, it *must* perform the task of setting the queue
172*4882a593Smuzhiyun 	 * depth on the device.  All other tasks are optional and depend
173*4882a593Smuzhiyun 	 * on what the driver supports and various implementation details.
174*4882a593Smuzhiyun 	 *
175*4882a593Smuzhiyun 	 * Things currently recommended to be handled at this time include:
176*4882a593Smuzhiyun 	 *
177*4882a593Smuzhiyun 	 * 1.  Setting the device queue depth.  Proper setting of this is
178*4882a593Smuzhiyun 	 *     described in the comments for scsi_change_queue_depth.
179*4882a593Smuzhiyun 	 * 2.  Determining if the device supports the various synchronous
180*4882a593Smuzhiyun 	 *     negotiation protocols.  The device struct will already have
181*4882a593Smuzhiyun 	 *     responded to INQUIRY and the results of the standard items
182*4882a593Smuzhiyun 	 *     will have been shoved into the various device flag bits, eg.
183*4882a593Smuzhiyun 	 *     device->sdtr will be true if the device supports SDTR messages.
184*4882a593Smuzhiyun 	 * 3.  Allocating command structs that the device will need.
185*4882a593Smuzhiyun 	 * 4.  Setting the default timeout on this device (if needed).
186*4882a593Smuzhiyun 	 * 5.  Anything else the low level driver might want to do on a device
187*4882a593Smuzhiyun 	 *     specific setup basis...
188*4882a593Smuzhiyun 	 * 6.  Return 0 on success, non-0 on error.  The device will be marked
189*4882a593Smuzhiyun 	 *     as offline on error so that no access will occur.  If you return
190*4882a593Smuzhiyun 	 *     non-0, your slave_destroy routine will never get called for this
191*4882a593Smuzhiyun 	 *     device, so don't leave any loose memory hanging around, clean
192*4882a593Smuzhiyun 	 *     up after yourself before returning non-0
193*4882a593Smuzhiyun 	 *
194*4882a593Smuzhiyun 	 * Status: OPTIONAL
195*4882a593Smuzhiyun 	 */
196*4882a593Smuzhiyun 	int (* slave_configure)(struct scsi_device *);
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	/*
199*4882a593Smuzhiyun 	 * Immediately prior to deallocating the device and after all activity
200*4882a593Smuzhiyun 	 * has ceased the mid layer calls this point so that the low level
201*4882a593Smuzhiyun 	 * driver may completely detach itself from the scsi device and vice
202*4882a593Smuzhiyun 	 * versa.  The low level driver is responsible for freeing any memory
203*4882a593Smuzhiyun 	 * it allocated in the slave_alloc or slave_configure calls.
204*4882a593Smuzhiyun 	 *
205*4882a593Smuzhiyun 	 * Status: OPTIONAL
206*4882a593Smuzhiyun 	 */
207*4882a593Smuzhiyun 	void (* slave_destroy)(struct scsi_device *);
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	/*
210*4882a593Smuzhiyun 	 * Before the mid layer attempts to scan for a new device attached
211*4882a593Smuzhiyun 	 * to a target where no target currently exists, it will call this
212*4882a593Smuzhiyun 	 * entry in your driver.  Should your driver need to allocate any
213*4882a593Smuzhiyun 	 * structs or perform any other init items in order to send commands
214*4882a593Smuzhiyun 	 * to a currently unused target, then this is where you can perform
215*4882a593Smuzhiyun 	 * those allocations.
216*4882a593Smuzhiyun 	 *
217*4882a593Smuzhiyun 	 * Return values: 0 on success, non-0 on failure
218*4882a593Smuzhiyun 	 *
219*4882a593Smuzhiyun 	 * Status: OPTIONAL
220*4882a593Smuzhiyun 	 */
221*4882a593Smuzhiyun 	int (* target_alloc)(struct scsi_target *);
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	/*
224*4882a593Smuzhiyun 	 * Immediately prior to deallocating the target structure, and
225*4882a593Smuzhiyun 	 * after all activity to attached scsi devices has ceased, the
226*4882a593Smuzhiyun 	 * midlayer calls this point so that the driver may deallocate
227*4882a593Smuzhiyun 	 * and terminate any references to the target.
228*4882a593Smuzhiyun 	 *
229*4882a593Smuzhiyun 	 * Status: OPTIONAL
230*4882a593Smuzhiyun 	 */
231*4882a593Smuzhiyun 	void (* target_destroy)(struct scsi_target *);
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	/*
234*4882a593Smuzhiyun 	 * If a host has the ability to discover targets on its own instead
235*4882a593Smuzhiyun 	 * of scanning the entire bus, it can fill in this function and
236*4882a593Smuzhiyun 	 * call scsi_scan_host().  This function will be called periodically
237*4882a593Smuzhiyun 	 * until it returns 1 with the scsi_host and the elapsed time of
238*4882a593Smuzhiyun 	 * the scan in jiffies.
239*4882a593Smuzhiyun 	 *
240*4882a593Smuzhiyun 	 * Status: OPTIONAL
241*4882a593Smuzhiyun 	 */
242*4882a593Smuzhiyun 	int (* scan_finished)(struct Scsi_Host *, unsigned long);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	/*
245*4882a593Smuzhiyun 	 * If the host wants to be called before the scan starts, but
246*4882a593Smuzhiyun 	 * after the midlayer has set up ready for the scan, it can fill
247*4882a593Smuzhiyun 	 * in this function.
248*4882a593Smuzhiyun 	 *
249*4882a593Smuzhiyun 	 * Status: OPTIONAL
250*4882a593Smuzhiyun 	 */
251*4882a593Smuzhiyun 	void (* scan_start)(struct Scsi_Host *);
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	/*
254*4882a593Smuzhiyun 	 * Fill in this function to allow the queue depth of this host
255*4882a593Smuzhiyun 	 * to be changeable (on a per device basis).  Returns either
256*4882a593Smuzhiyun 	 * the current queue depth setting (may be different from what
257*4882a593Smuzhiyun 	 * was passed in) or an error.  An error should only be
258*4882a593Smuzhiyun 	 * returned if the requested depth is legal but the driver was
259*4882a593Smuzhiyun 	 * unable to set it.  If the requested depth is illegal, the
260*4882a593Smuzhiyun 	 * driver should set and return the closest legal queue depth.
261*4882a593Smuzhiyun 	 *
262*4882a593Smuzhiyun 	 * Status: OPTIONAL
263*4882a593Smuzhiyun 	 */
264*4882a593Smuzhiyun 	int (* change_queue_depth)(struct scsi_device *, int);
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	/*
267*4882a593Smuzhiyun 	 * This functions lets the driver expose the queue mapping
268*4882a593Smuzhiyun 	 * to the block layer.
269*4882a593Smuzhiyun 	 *
270*4882a593Smuzhiyun 	 * Status: OPTIONAL
271*4882a593Smuzhiyun 	 */
272*4882a593Smuzhiyun 	int (* map_queues)(struct Scsi_Host *shost);
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun 	/*
275*4882a593Smuzhiyun 	 * Check if scatterlists need to be padded for DMA draining.
276*4882a593Smuzhiyun 	 *
277*4882a593Smuzhiyun 	 * Status: OPTIONAL
278*4882a593Smuzhiyun 	 */
279*4882a593Smuzhiyun 	bool (* dma_need_drain)(struct request *rq);
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun 	/*
282*4882a593Smuzhiyun 	 * This function determines the BIOS parameters for a given
283*4882a593Smuzhiyun 	 * harddisk.  These tend to be numbers that are made up by
284*4882a593Smuzhiyun 	 * the host adapter.  Parameters:
285*4882a593Smuzhiyun 	 * size, device, list (heads, sectors, cylinders)
286*4882a593Smuzhiyun 	 *
287*4882a593Smuzhiyun 	 * Status: OPTIONAL
288*4882a593Smuzhiyun 	 */
289*4882a593Smuzhiyun 	int (* bios_param)(struct scsi_device *, struct block_device *,
290*4882a593Smuzhiyun 			sector_t, int []);
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	/*
293*4882a593Smuzhiyun 	 * This function is called when one or more partitions on the
294*4882a593Smuzhiyun 	 * device reach beyond the end of the device.
295*4882a593Smuzhiyun 	 *
296*4882a593Smuzhiyun 	 * Status: OPTIONAL
297*4882a593Smuzhiyun 	 */
298*4882a593Smuzhiyun 	void (*unlock_native_capacity)(struct scsi_device *);
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun 	/*
301*4882a593Smuzhiyun 	 * Can be used to export driver statistics and other infos to the
302*4882a593Smuzhiyun 	 * world outside the kernel ie. userspace and it also provides an
303*4882a593Smuzhiyun 	 * interface to feed the driver with information.
304*4882a593Smuzhiyun 	 *
305*4882a593Smuzhiyun 	 * Status: OBSOLETE
306*4882a593Smuzhiyun 	 */
307*4882a593Smuzhiyun 	int (*show_info)(struct seq_file *, struct Scsi_Host *);
308*4882a593Smuzhiyun 	int (*write_info)(struct Scsi_Host *, char *, int);
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	/*
311*4882a593Smuzhiyun 	 * This is an optional routine that allows the transport to become
312*4882a593Smuzhiyun 	 * involved when a scsi io timer fires. The return value tells the
313*4882a593Smuzhiyun 	 * timer routine how to finish the io timeout handling.
314*4882a593Smuzhiyun 	 *
315*4882a593Smuzhiyun 	 * Status: OPTIONAL
316*4882a593Smuzhiyun 	 */
317*4882a593Smuzhiyun 	enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 	/* This is an optional routine that allows transport to initiate
320*4882a593Smuzhiyun 	 * LLD adapter or firmware reset using sysfs attribute.
321*4882a593Smuzhiyun 	 *
322*4882a593Smuzhiyun 	 * Return values: 0 on success, -ve value on failure.
323*4882a593Smuzhiyun 	 *
324*4882a593Smuzhiyun 	 * Status: OPTIONAL
325*4882a593Smuzhiyun 	 */
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	int (*host_reset)(struct Scsi_Host *shost, int reset_type);
328*4882a593Smuzhiyun #define SCSI_ADAPTER_RESET	1
329*4882a593Smuzhiyun #define SCSI_FIRMWARE_RESET	2
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun 	/*
333*4882a593Smuzhiyun 	 * Name of proc directory
334*4882a593Smuzhiyun 	 */
335*4882a593Smuzhiyun 	const char *proc_name;
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	/*
338*4882a593Smuzhiyun 	 * Used to store the procfs directory if a driver implements the
339*4882a593Smuzhiyun 	 * show_info method.
340*4882a593Smuzhiyun 	 */
341*4882a593Smuzhiyun 	struct proc_dir_entry *proc_dir;
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	/*
344*4882a593Smuzhiyun 	 * This determines if we will use a non-interrupt driven
345*4882a593Smuzhiyun 	 * or an interrupt driven scheme.  It is set to the maximum number
346*4882a593Smuzhiyun 	 * of simultaneous commands a single hw queue in HBA will accept.
347*4882a593Smuzhiyun 	 */
348*4882a593Smuzhiyun 	int can_queue;
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun 	/*
351*4882a593Smuzhiyun 	 * In many instances, especially where disconnect / reconnect are
352*4882a593Smuzhiyun 	 * supported, our host also has an ID on the SCSI bus.  If this is
353*4882a593Smuzhiyun 	 * the case, then it must be reserved.  Please set this_id to -1 if
354*4882a593Smuzhiyun 	 * your setup is in single initiator mode, and the host lacks an
355*4882a593Smuzhiyun 	 * ID.
356*4882a593Smuzhiyun 	 */
357*4882a593Smuzhiyun 	int this_id;
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun 	/*
360*4882a593Smuzhiyun 	 * This determines the degree to which the host adapter is capable
361*4882a593Smuzhiyun 	 * of scatter-gather.
362*4882a593Smuzhiyun 	 */
363*4882a593Smuzhiyun 	unsigned short sg_tablesize;
364*4882a593Smuzhiyun 	unsigned short sg_prot_tablesize;
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 	/*
367*4882a593Smuzhiyun 	 * Set this if the host adapter has limitations beside segment count.
368*4882a593Smuzhiyun 	 */
369*4882a593Smuzhiyun 	unsigned int max_sectors;
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	/*
372*4882a593Smuzhiyun 	 * Maximum size in bytes of a single segment.
373*4882a593Smuzhiyun 	 */
374*4882a593Smuzhiyun 	unsigned int max_segment_size;
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	/*
377*4882a593Smuzhiyun 	 * DMA scatter gather segment boundary limit. A segment crossing this
378*4882a593Smuzhiyun 	 * boundary will be split in two.
379*4882a593Smuzhiyun 	 */
380*4882a593Smuzhiyun 	unsigned long dma_boundary;
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	unsigned long virt_boundary_mask;
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun 	/*
385*4882a593Smuzhiyun 	 * This specifies "machine infinity" for host templates which don't
386*4882a593Smuzhiyun 	 * limit the transfer size.  Note this limit represents an absolute
387*4882a593Smuzhiyun 	 * maximum, and may be over the transfer limits allowed for
388*4882a593Smuzhiyun 	 * individual devices (e.g. 256 for SCSI-1).
389*4882a593Smuzhiyun 	 */
390*4882a593Smuzhiyun #define SCSI_DEFAULT_MAX_SECTORS	1024
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun 	/*
393*4882a593Smuzhiyun 	 * True if this host adapter can make good use of linked commands.
394*4882a593Smuzhiyun 	 * This will allow more than one command to be queued to a given
395*4882a593Smuzhiyun 	 * unit on a given host.  Set this to the maximum number of command
396*4882a593Smuzhiyun 	 * blocks to be provided for each device.  Set this to 1 for one
397*4882a593Smuzhiyun 	 * command block per lun, 2 for two, etc.  Do not set this to 0.
398*4882a593Smuzhiyun 	 * You should make sure that the host adapter will do the right thing
399*4882a593Smuzhiyun 	 * before you try setting this above 1.
400*4882a593Smuzhiyun 	 */
401*4882a593Smuzhiyun 	short cmd_per_lun;
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun 	/*
404*4882a593Smuzhiyun 	 * present contains counter indicating how many boards of this
405*4882a593Smuzhiyun 	 * type were found when we did the scan.
406*4882a593Smuzhiyun 	 */
407*4882a593Smuzhiyun 	unsigned char present;
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun 	/* If use block layer to manage tags, this is tag allocation policy */
410*4882a593Smuzhiyun 	int tag_alloc_policy;
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 	/*
413*4882a593Smuzhiyun 	 * Track QUEUE_FULL events and reduce queue depth on demand.
414*4882a593Smuzhiyun 	 */
415*4882a593Smuzhiyun 	unsigned track_queue_depth:1;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 	/*
418*4882a593Smuzhiyun 	 * This specifies the mode that a LLD supports.
419*4882a593Smuzhiyun 	 */
420*4882a593Smuzhiyun 	unsigned supported_mode:2;
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	/*
423*4882a593Smuzhiyun 	 * True if this host adapter uses unchecked DMA onto an ISA bus.
424*4882a593Smuzhiyun 	 */
425*4882a593Smuzhiyun 	unsigned unchecked_isa_dma:1;
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun 	/*
428*4882a593Smuzhiyun 	 * True for emulated SCSI host adapters (e.g. ATAPI).
429*4882a593Smuzhiyun 	 */
430*4882a593Smuzhiyun 	unsigned emulated:1;
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun 	/*
433*4882a593Smuzhiyun 	 * True if the low-level driver performs its own reset-settle delays.
434*4882a593Smuzhiyun 	 */
435*4882a593Smuzhiyun 	unsigned skip_settle_delay:1;
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun 	/* True if the controller does not support WRITE SAME */
438*4882a593Smuzhiyun 	unsigned no_write_same:1;
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	/* True if the host uses host-wide tagspace */
441*4882a593Smuzhiyun 	unsigned host_tagset:1;
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	/*
444*4882a593Smuzhiyun 	 * Countdown for host blocking with no commands outstanding.
445*4882a593Smuzhiyun 	 */
446*4882a593Smuzhiyun 	unsigned int max_host_blocked;
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun 	/*
449*4882a593Smuzhiyun 	 * Default value for the blocking.  If the queue is empty,
450*4882a593Smuzhiyun 	 * host_blocked counts down in the request_fn until it restarts
451*4882a593Smuzhiyun 	 * host operations as zero is reached.
452*4882a593Smuzhiyun 	 *
453*4882a593Smuzhiyun 	 * FIXME: This should probably be a value in the template
454*4882a593Smuzhiyun 	 */
455*4882a593Smuzhiyun #define SCSI_DEFAULT_HOST_BLOCKED	7
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	/*
458*4882a593Smuzhiyun 	 * Pointer to the sysfs class properties for this host, NULL terminated.
459*4882a593Smuzhiyun 	 */
460*4882a593Smuzhiyun 	struct device_attribute **shost_attrs;
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun 	/*
463*4882a593Smuzhiyun 	 * Pointer to the SCSI device properties for this host, NULL terminated.
464*4882a593Smuzhiyun 	 */
465*4882a593Smuzhiyun 	struct device_attribute **sdev_attrs;
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun 	/*
468*4882a593Smuzhiyun 	 * Pointer to the SCSI device attribute groups for this host,
469*4882a593Smuzhiyun 	 * NULL terminated.
470*4882a593Smuzhiyun 	 */
471*4882a593Smuzhiyun 	const struct attribute_group **sdev_groups;
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun 	/*
474*4882a593Smuzhiyun 	 * Vendor Identifier associated with the host
475*4882a593Smuzhiyun 	 *
476*4882a593Smuzhiyun 	 * Note: When specifying vendor_id, be sure to read the
477*4882a593Smuzhiyun 	 *   Vendor Type and ID formatting requirements specified in
478*4882a593Smuzhiyun 	 *   scsi_netlink.h
479*4882a593Smuzhiyun 	 */
480*4882a593Smuzhiyun 	u64 vendor_id;
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun 	/*
483*4882a593Smuzhiyun 	 * Additional per-command data allocated for the driver.
484*4882a593Smuzhiyun 	 */
485*4882a593Smuzhiyun 	unsigned int cmd_size;
486*4882a593Smuzhiyun 	struct scsi_host_cmd_pool *cmd_pool;
487*4882a593Smuzhiyun 
488*4882a593Smuzhiyun 	/* Delay for runtime autosuspend */
489*4882a593Smuzhiyun 	int rpm_autosuspend_delay;
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
492*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
493*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(3);
494*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(4);
495*4882a593Smuzhiyun };
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun /*
498*4882a593Smuzhiyun  * Temporary #define for host lock push down. Can be removed when all
499*4882a593Smuzhiyun  * drivers have been updated to take advantage of unlocked
500*4882a593Smuzhiyun  * queuecommand.
501*4882a593Smuzhiyun  *
502*4882a593Smuzhiyun  */
503*4882a593Smuzhiyun #define DEF_SCSI_QCMD(func_name) \
504*4882a593Smuzhiyun 	int func_name(struct Scsi_Host *shost, struct scsi_cmnd *cmd)	\
505*4882a593Smuzhiyun 	{								\
506*4882a593Smuzhiyun 		unsigned long irq_flags;				\
507*4882a593Smuzhiyun 		int rc;							\
508*4882a593Smuzhiyun 		spin_lock_irqsave(shost->host_lock, irq_flags);		\
509*4882a593Smuzhiyun 		rc = func_name##_lck (cmd, cmd->scsi_done);			\
510*4882a593Smuzhiyun 		spin_unlock_irqrestore(shost->host_lock, irq_flags);	\
511*4882a593Smuzhiyun 		return rc;						\
512*4882a593Smuzhiyun 	}
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun /*
516*4882a593Smuzhiyun  * shost state: If you alter this, you also need to alter scsi_sysfs.c
517*4882a593Smuzhiyun  * (for the ascii descriptions) and the state model enforcer:
518*4882a593Smuzhiyun  * scsi_host_set_state()
519*4882a593Smuzhiyun  */
520*4882a593Smuzhiyun enum scsi_host_state {
521*4882a593Smuzhiyun 	SHOST_CREATED = 1,
522*4882a593Smuzhiyun 	SHOST_RUNNING,
523*4882a593Smuzhiyun 	SHOST_CANCEL,
524*4882a593Smuzhiyun 	SHOST_DEL,
525*4882a593Smuzhiyun 	SHOST_RECOVERY,
526*4882a593Smuzhiyun 	SHOST_CANCEL_RECOVERY,
527*4882a593Smuzhiyun 	SHOST_DEL_RECOVERY,
528*4882a593Smuzhiyun };
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun struct Scsi_Host {
531*4882a593Smuzhiyun 	/*
532*4882a593Smuzhiyun 	 * __devices is protected by the host_lock, but you should
533*4882a593Smuzhiyun 	 * usually use scsi_device_lookup / shost_for_each_device
534*4882a593Smuzhiyun 	 * to access it and don't care about locking yourself.
535*4882a593Smuzhiyun 	 * In the rare case of being in irq context you can use
536*4882a593Smuzhiyun 	 * their __ prefixed variants with the lock held. NEVER
537*4882a593Smuzhiyun 	 * access this list directly from a driver.
538*4882a593Smuzhiyun 	 */
539*4882a593Smuzhiyun 	struct list_head	__devices;
540*4882a593Smuzhiyun 	struct list_head	__targets;
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun 	struct list_head	starved_list;
543*4882a593Smuzhiyun 
544*4882a593Smuzhiyun 	spinlock_t		default_lock;
545*4882a593Smuzhiyun 	spinlock_t		*host_lock;
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun 	struct mutex		scan_mutex;/* serialize scanning activity */
548*4882a593Smuzhiyun 
549*4882a593Smuzhiyun 	struct list_head	eh_cmd_q;
550*4882a593Smuzhiyun 	struct task_struct    * ehandler;  /* Error recovery thread. */
551*4882a593Smuzhiyun 	struct completion     * eh_action; /* Wait for specific actions on the
552*4882a593Smuzhiyun 					      host. */
553*4882a593Smuzhiyun 	wait_queue_head_t       host_wait;
554*4882a593Smuzhiyun 	struct scsi_host_template *hostt;
555*4882a593Smuzhiyun 	struct scsi_transport_template *transportt;
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	/* Area to keep a shared tag map */
558*4882a593Smuzhiyun 	struct blk_mq_tag_set	tag_set;
559*4882a593Smuzhiyun 
560*4882a593Smuzhiyun 	atomic_t host_blocked;
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun 	unsigned int host_failed;	   /* commands that failed.
563*4882a593Smuzhiyun 					      protected by host_lock */
564*4882a593Smuzhiyun 	unsigned int host_eh_scheduled;    /* EH scheduled without command */
565*4882a593Smuzhiyun 
566*4882a593Smuzhiyun 	unsigned int host_no;  /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 	/* next two fields are used to bound the time spent in error handling */
569*4882a593Smuzhiyun 	int eh_deadline;
570*4882a593Smuzhiyun 	unsigned long last_reset;
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun 	/*
574*4882a593Smuzhiyun 	 * These three parameters can be used to allow for wide scsi,
575*4882a593Smuzhiyun 	 * and for host adapters that support multiple busses
576*4882a593Smuzhiyun 	 * The last two should be set to 1 more than the actual max id
577*4882a593Smuzhiyun 	 * or lun (e.g. 8 for SCSI parallel systems).
578*4882a593Smuzhiyun 	 */
579*4882a593Smuzhiyun 	unsigned int max_channel;
580*4882a593Smuzhiyun 	unsigned int max_id;
581*4882a593Smuzhiyun 	u64 max_lun;
582*4882a593Smuzhiyun 
583*4882a593Smuzhiyun 	/*
584*4882a593Smuzhiyun 	 * This is a unique identifier that must be assigned so that we
585*4882a593Smuzhiyun 	 * have some way of identifying each detected host adapter properly
586*4882a593Smuzhiyun 	 * and uniquely.  For hosts that do not support more than one card
587*4882a593Smuzhiyun 	 * in the system at one time, this does not need to be set.  It is
588*4882a593Smuzhiyun 	 * initialized to 0 in scsi_register.
589*4882a593Smuzhiyun 	 */
590*4882a593Smuzhiyun 	unsigned int unique_id;
591*4882a593Smuzhiyun 
592*4882a593Smuzhiyun 	/*
593*4882a593Smuzhiyun 	 * The maximum length of SCSI commands that this host can accept.
594*4882a593Smuzhiyun 	 * Probably 12 for most host adapters, but could be 16 for others.
595*4882a593Smuzhiyun 	 * or 260 if the driver supports variable length cdbs.
596*4882a593Smuzhiyun 	 * For drivers that don't set this field, a value of 12 is
597*4882a593Smuzhiyun 	 * assumed.
598*4882a593Smuzhiyun 	 */
599*4882a593Smuzhiyun 	unsigned short max_cmd_len;
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	int this_id;
602*4882a593Smuzhiyun 	int can_queue;
603*4882a593Smuzhiyun 	short cmd_per_lun;
604*4882a593Smuzhiyun 	short unsigned int sg_tablesize;
605*4882a593Smuzhiyun 	short unsigned int sg_prot_tablesize;
606*4882a593Smuzhiyun 	unsigned int max_sectors;
607*4882a593Smuzhiyun 	unsigned int max_segment_size;
608*4882a593Smuzhiyun 	unsigned long dma_boundary;
609*4882a593Smuzhiyun 	unsigned long virt_boundary_mask;
610*4882a593Smuzhiyun 	/*
611*4882a593Smuzhiyun 	 * In scsi-mq mode, the number of hardware queues supported by the LLD.
612*4882a593Smuzhiyun 	 *
613*4882a593Smuzhiyun 	 * Note: it is assumed that each hardware queue has a queue depth of
614*4882a593Smuzhiyun 	 * can_queue. In other words, the total queue depth per host
615*4882a593Smuzhiyun 	 * is nr_hw_queues * can_queue. However, for when host_tagset is set,
616*4882a593Smuzhiyun 	 * the total queue depth is can_queue.
617*4882a593Smuzhiyun 	 */
618*4882a593Smuzhiyun 	unsigned nr_hw_queues;
619*4882a593Smuzhiyun 	unsigned active_mode:2;
620*4882a593Smuzhiyun 	unsigned unchecked_isa_dma:1;
621*4882a593Smuzhiyun 
622*4882a593Smuzhiyun 	/*
623*4882a593Smuzhiyun 	 * Host has requested that no further requests come through for the
624*4882a593Smuzhiyun 	 * time being.
625*4882a593Smuzhiyun 	 */
626*4882a593Smuzhiyun 	unsigned host_self_blocked:1;
627*4882a593Smuzhiyun 
628*4882a593Smuzhiyun 	/*
629*4882a593Smuzhiyun 	 * Host uses correct SCSI ordering not PC ordering. The bit is
630*4882a593Smuzhiyun 	 * set for the minority of drivers whose authors actually read
631*4882a593Smuzhiyun 	 * the spec ;).
632*4882a593Smuzhiyun 	 */
633*4882a593Smuzhiyun 	unsigned reverse_ordering:1;
634*4882a593Smuzhiyun 
635*4882a593Smuzhiyun 	/* Task mgmt function in progress */
636*4882a593Smuzhiyun 	unsigned tmf_in_progress:1;
637*4882a593Smuzhiyun 
638*4882a593Smuzhiyun 	/* Asynchronous scan in progress */
639*4882a593Smuzhiyun 	unsigned async_scan:1;
640*4882a593Smuzhiyun 
641*4882a593Smuzhiyun 	/* Don't resume host in EH */
642*4882a593Smuzhiyun 	unsigned eh_noresume:1;
643*4882a593Smuzhiyun 
644*4882a593Smuzhiyun 	/* The controller does not support WRITE SAME */
645*4882a593Smuzhiyun 	unsigned no_write_same:1;
646*4882a593Smuzhiyun 
647*4882a593Smuzhiyun 	/* True if the host uses host-wide tagspace */
648*4882a593Smuzhiyun 	unsigned host_tagset:1;
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun 	/* Host responded with short (<36 bytes) INQUIRY result */
651*4882a593Smuzhiyun 	unsigned short_inquiry:1;
652*4882a593Smuzhiyun 
653*4882a593Smuzhiyun 	/* The transport requires the LUN bits NOT to be stored in CDB[1] */
654*4882a593Smuzhiyun 	unsigned no_scsi2_lun_in_cdb:1;
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun 	/*
657*4882a593Smuzhiyun 	 * Optional work queue to be utilized by the transport
658*4882a593Smuzhiyun 	 */
659*4882a593Smuzhiyun 	char work_q_name[20];
660*4882a593Smuzhiyun 	struct workqueue_struct *work_q;
661*4882a593Smuzhiyun 
662*4882a593Smuzhiyun 	/*
663*4882a593Smuzhiyun 	 * Task management function work queue
664*4882a593Smuzhiyun 	 */
665*4882a593Smuzhiyun 	struct workqueue_struct *tmf_work_q;
666*4882a593Smuzhiyun 
667*4882a593Smuzhiyun 	/*
668*4882a593Smuzhiyun 	 * Value host_blocked counts down from
669*4882a593Smuzhiyun 	 */
670*4882a593Smuzhiyun 	unsigned int max_host_blocked;
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun 	/* Protection Information */
673*4882a593Smuzhiyun 	unsigned int prot_capabilities;
674*4882a593Smuzhiyun 	unsigned char prot_guard_type;
675*4882a593Smuzhiyun 
676*4882a593Smuzhiyun 	/* legacy crap */
677*4882a593Smuzhiyun 	unsigned long base;
678*4882a593Smuzhiyun 	unsigned long io_port;
679*4882a593Smuzhiyun 	unsigned char n_io_port;
680*4882a593Smuzhiyun 	unsigned char dma_channel;
681*4882a593Smuzhiyun 	unsigned int  irq;
682*4882a593Smuzhiyun 
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun 	enum scsi_host_state shost_state;
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun 	/* ldm bits */
687*4882a593Smuzhiyun 	struct device		shost_gendev, shost_dev;
688*4882a593Smuzhiyun 
689*4882a593Smuzhiyun 	/*
690*4882a593Smuzhiyun 	 * Points to the transport data (if any) which is allocated
691*4882a593Smuzhiyun 	 * separately
692*4882a593Smuzhiyun 	 */
693*4882a593Smuzhiyun 	void *shost_data;
694*4882a593Smuzhiyun 
695*4882a593Smuzhiyun 	/*
696*4882a593Smuzhiyun 	 * Points to the physical bus device we'd use to do DMA
697*4882a593Smuzhiyun 	 * Needed just in case we have virtual hosts.
698*4882a593Smuzhiyun 	 */
699*4882a593Smuzhiyun 	struct device *dma_dev;
700*4882a593Smuzhiyun 
701*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun 	/*
704*4882a593Smuzhiyun 	 * We should ensure that this is aligned, both for better performance
705*4882a593Smuzhiyun 	 * and also because some compilers (m68k) don't automatically force
706*4882a593Smuzhiyun 	 * alignment to a long boundary.
707*4882a593Smuzhiyun 	 */
708*4882a593Smuzhiyun 	unsigned long hostdata[]  /* Used for storage of host specific stuff */
709*4882a593Smuzhiyun 		__attribute__ ((aligned (sizeof(unsigned long))));
710*4882a593Smuzhiyun };
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun #define		class_to_shost(d)	\
713*4882a593Smuzhiyun 	container_of(d, struct Scsi_Host, shost_dev)
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun #define shost_printk(prefix, shost, fmt, a...)	\
716*4882a593Smuzhiyun 	dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)
717*4882a593Smuzhiyun 
shost_priv(struct Scsi_Host * shost)718*4882a593Smuzhiyun static inline void *shost_priv(struct Scsi_Host *shost)
719*4882a593Smuzhiyun {
720*4882a593Smuzhiyun 	return (void *)shost->hostdata;
721*4882a593Smuzhiyun }
722*4882a593Smuzhiyun 
723*4882a593Smuzhiyun int scsi_is_host_device(const struct device *);
724*4882a593Smuzhiyun 
dev_to_shost(struct device * dev)725*4882a593Smuzhiyun static inline struct Scsi_Host *dev_to_shost(struct device *dev)
726*4882a593Smuzhiyun {
727*4882a593Smuzhiyun 	while (!scsi_is_host_device(dev)) {
728*4882a593Smuzhiyun 		if (!dev->parent)
729*4882a593Smuzhiyun 			return NULL;
730*4882a593Smuzhiyun 		dev = dev->parent;
731*4882a593Smuzhiyun 	}
732*4882a593Smuzhiyun 	return container_of(dev, struct Scsi_Host, shost_gendev);
733*4882a593Smuzhiyun }
734*4882a593Smuzhiyun 
scsi_host_in_recovery(struct Scsi_Host * shost)735*4882a593Smuzhiyun static inline int scsi_host_in_recovery(struct Scsi_Host *shost)
736*4882a593Smuzhiyun {
737*4882a593Smuzhiyun 	return shost->shost_state == SHOST_RECOVERY ||
738*4882a593Smuzhiyun 		shost->shost_state == SHOST_CANCEL_RECOVERY ||
739*4882a593Smuzhiyun 		shost->shost_state == SHOST_DEL_RECOVERY ||
740*4882a593Smuzhiyun 		shost->tmf_in_progress;
741*4882a593Smuzhiyun }
742*4882a593Smuzhiyun 
743*4882a593Smuzhiyun extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
744*4882a593Smuzhiyun extern void scsi_flush_work(struct Scsi_Host *);
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
747*4882a593Smuzhiyun extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,
748*4882a593Smuzhiyun 					       struct device *,
749*4882a593Smuzhiyun 					       struct device *);
750*4882a593Smuzhiyun extern void scsi_scan_host(struct Scsi_Host *);
751*4882a593Smuzhiyun extern void scsi_rescan_device(struct device *);
752*4882a593Smuzhiyun extern void scsi_remove_host(struct Scsi_Host *);
753*4882a593Smuzhiyun extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
754*4882a593Smuzhiyun extern int scsi_host_busy(struct Scsi_Host *shost);
755*4882a593Smuzhiyun extern void scsi_host_put(struct Scsi_Host *t);
756*4882a593Smuzhiyun extern struct Scsi_Host *scsi_host_lookup(unsigned short);
757*4882a593Smuzhiyun extern const char *scsi_host_state_name(enum scsi_host_state);
758*4882a593Smuzhiyun extern void scsi_host_complete_all_commands(struct Scsi_Host *shost,
759*4882a593Smuzhiyun 					    int status);
760*4882a593Smuzhiyun 
scsi_add_host(struct Scsi_Host * host,struct device * dev)761*4882a593Smuzhiyun static inline int __must_check scsi_add_host(struct Scsi_Host *host,
762*4882a593Smuzhiyun 					     struct device *dev)
763*4882a593Smuzhiyun {
764*4882a593Smuzhiyun 	return scsi_add_host_with_dma(host, dev, dev);
765*4882a593Smuzhiyun }
766*4882a593Smuzhiyun 
scsi_get_device(struct Scsi_Host * shost)767*4882a593Smuzhiyun static inline struct device *scsi_get_device(struct Scsi_Host *shost)
768*4882a593Smuzhiyun {
769*4882a593Smuzhiyun         return shost->shost_gendev.parent;
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun 
772*4882a593Smuzhiyun /**
773*4882a593Smuzhiyun  * scsi_host_scan_allowed - Is scanning of this host allowed
774*4882a593Smuzhiyun  * @shost:	Pointer to Scsi_Host.
775*4882a593Smuzhiyun  **/
scsi_host_scan_allowed(struct Scsi_Host * shost)776*4882a593Smuzhiyun static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)
777*4882a593Smuzhiyun {
778*4882a593Smuzhiyun 	return shost->shost_state == SHOST_RUNNING ||
779*4882a593Smuzhiyun 	       shost->shost_state == SHOST_RECOVERY;
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun extern void scsi_unblock_requests(struct Scsi_Host *);
783*4882a593Smuzhiyun extern void scsi_block_requests(struct Scsi_Host *);
784*4882a593Smuzhiyun extern int scsi_host_block(struct Scsi_Host *shost);
785*4882a593Smuzhiyun extern int scsi_host_unblock(struct Scsi_Host *shost, int new_state);
786*4882a593Smuzhiyun 
787*4882a593Smuzhiyun void scsi_host_busy_iter(struct Scsi_Host *,
788*4882a593Smuzhiyun 			 bool (*fn)(struct scsi_cmnd *, void *, bool), void *priv);
789*4882a593Smuzhiyun 
790*4882a593Smuzhiyun struct class_container;
791*4882a593Smuzhiyun 
792*4882a593Smuzhiyun /*
793*4882a593Smuzhiyun  * These two functions are used to allocate and free a pseudo device
794*4882a593Smuzhiyun  * which will connect to the host adapter itself rather than any
795*4882a593Smuzhiyun  * physical device.  You must deallocate when you are done with the
796*4882a593Smuzhiyun  * thing.  This physical pseudo-device isn't real and won't be available
797*4882a593Smuzhiyun  * from any high-level drivers.
798*4882a593Smuzhiyun  */
799*4882a593Smuzhiyun extern void scsi_free_host_dev(struct scsi_device *);
800*4882a593Smuzhiyun extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
801*4882a593Smuzhiyun 
802*4882a593Smuzhiyun /*
803*4882a593Smuzhiyun  * DIF defines the exchange of protection information between
804*4882a593Smuzhiyun  * initiator and SBC block device.
805*4882a593Smuzhiyun  *
806*4882a593Smuzhiyun  * DIX defines the exchange of protection information between OS and
807*4882a593Smuzhiyun  * initiator.
808*4882a593Smuzhiyun  */
809*4882a593Smuzhiyun enum scsi_host_prot_capabilities {
810*4882a593Smuzhiyun 	SHOST_DIF_TYPE1_PROTECTION = 1 << 0, /* T10 DIF Type 1 */
811*4882a593Smuzhiyun 	SHOST_DIF_TYPE2_PROTECTION = 1 << 1, /* T10 DIF Type 2 */
812*4882a593Smuzhiyun 	SHOST_DIF_TYPE3_PROTECTION = 1 << 2, /* T10 DIF Type 3 */
813*4882a593Smuzhiyun 
814*4882a593Smuzhiyun 	SHOST_DIX_TYPE0_PROTECTION = 1 << 3, /* DIX between OS and HBA only */
815*4882a593Smuzhiyun 	SHOST_DIX_TYPE1_PROTECTION = 1 << 4, /* DIX with DIF Type 1 */
816*4882a593Smuzhiyun 	SHOST_DIX_TYPE2_PROTECTION = 1 << 5, /* DIX with DIF Type 2 */
817*4882a593Smuzhiyun 	SHOST_DIX_TYPE3_PROTECTION = 1 << 6, /* DIX with DIF Type 3 */
818*4882a593Smuzhiyun };
819*4882a593Smuzhiyun 
820*4882a593Smuzhiyun /*
821*4882a593Smuzhiyun  * SCSI hosts which support the Data Integrity Extensions must
822*4882a593Smuzhiyun  * indicate their capabilities by setting the prot_capabilities using
823*4882a593Smuzhiyun  * this call.
824*4882a593Smuzhiyun  */
scsi_host_set_prot(struct Scsi_Host * shost,unsigned int mask)825*4882a593Smuzhiyun static inline void scsi_host_set_prot(struct Scsi_Host *shost, unsigned int mask)
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun 	shost->prot_capabilities = mask;
828*4882a593Smuzhiyun }
829*4882a593Smuzhiyun 
scsi_host_get_prot(struct Scsi_Host * shost)830*4882a593Smuzhiyun static inline unsigned int scsi_host_get_prot(struct Scsi_Host *shost)
831*4882a593Smuzhiyun {
832*4882a593Smuzhiyun 	return shost->prot_capabilities;
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun 
scsi_host_prot_dma(struct Scsi_Host * shost)835*4882a593Smuzhiyun static inline int scsi_host_prot_dma(struct Scsi_Host *shost)
836*4882a593Smuzhiyun {
837*4882a593Smuzhiyun 	return shost->prot_capabilities >= SHOST_DIX_TYPE0_PROTECTION;
838*4882a593Smuzhiyun }
839*4882a593Smuzhiyun 
scsi_host_dif_capable(struct Scsi_Host * shost,unsigned int target_type)840*4882a593Smuzhiyun static inline unsigned int scsi_host_dif_capable(struct Scsi_Host *shost, unsigned int target_type)
841*4882a593Smuzhiyun {
842*4882a593Smuzhiyun 	static unsigned char cap[] = { 0,
843*4882a593Smuzhiyun 				       SHOST_DIF_TYPE1_PROTECTION,
844*4882a593Smuzhiyun 				       SHOST_DIF_TYPE2_PROTECTION,
845*4882a593Smuzhiyun 				       SHOST_DIF_TYPE3_PROTECTION };
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun 	if (target_type >= ARRAY_SIZE(cap))
848*4882a593Smuzhiyun 		return 0;
849*4882a593Smuzhiyun 
850*4882a593Smuzhiyun 	return shost->prot_capabilities & cap[target_type] ? target_type : 0;
851*4882a593Smuzhiyun }
852*4882a593Smuzhiyun 
scsi_host_dix_capable(struct Scsi_Host * shost,unsigned int target_type)853*4882a593Smuzhiyun static inline unsigned int scsi_host_dix_capable(struct Scsi_Host *shost, unsigned int target_type)
854*4882a593Smuzhiyun {
855*4882a593Smuzhiyun #if defined(CONFIG_BLK_DEV_INTEGRITY)
856*4882a593Smuzhiyun 	static unsigned char cap[] = { SHOST_DIX_TYPE0_PROTECTION,
857*4882a593Smuzhiyun 				       SHOST_DIX_TYPE1_PROTECTION,
858*4882a593Smuzhiyun 				       SHOST_DIX_TYPE2_PROTECTION,
859*4882a593Smuzhiyun 				       SHOST_DIX_TYPE3_PROTECTION };
860*4882a593Smuzhiyun 
861*4882a593Smuzhiyun 	if (target_type >= ARRAY_SIZE(cap))
862*4882a593Smuzhiyun 		return 0;
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun 	return shost->prot_capabilities & cap[target_type];
865*4882a593Smuzhiyun #endif
866*4882a593Smuzhiyun 	return 0;
867*4882a593Smuzhiyun }
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun /*
870*4882a593Smuzhiyun  * All DIX-capable initiators must support the T10-mandated CRC
871*4882a593Smuzhiyun  * checksum.  Controllers can optionally implement the IP checksum
872*4882a593Smuzhiyun  * scheme which has much lower impact on system performance.  Note
873*4882a593Smuzhiyun  * that the main rationale for the checksum is to match integrity
874*4882a593Smuzhiyun  * metadata with data.  Detecting bit errors are a job for ECC memory
875*4882a593Smuzhiyun  * and buses.
876*4882a593Smuzhiyun  */
877*4882a593Smuzhiyun 
878*4882a593Smuzhiyun enum scsi_host_guard_type {
879*4882a593Smuzhiyun 	SHOST_DIX_GUARD_CRC = 1 << 0,
880*4882a593Smuzhiyun 	SHOST_DIX_GUARD_IP  = 1 << 1,
881*4882a593Smuzhiyun };
882*4882a593Smuzhiyun 
scsi_host_set_guard(struct Scsi_Host * shost,unsigned char type)883*4882a593Smuzhiyun static inline void scsi_host_set_guard(struct Scsi_Host *shost, unsigned char type)
884*4882a593Smuzhiyun {
885*4882a593Smuzhiyun 	shost->prot_guard_type = type;
886*4882a593Smuzhiyun }
887*4882a593Smuzhiyun 
scsi_host_get_guard(struct Scsi_Host * shost)888*4882a593Smuzhiyun static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)
889*4882a593Smuzhiyun {
890*4882a593Smuzhiyun 	return shost->prot_guard_type;
891*4882a593Smuzhiyun }
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);
894*4882a593Smuzhiyun 
895*4882a593Smuzhiyun #endif /* _SCSI_SCSI_HOST_H */
896