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