tgt: removal
[deliverable/linux.git] / include / scsi / scsi_host.h
CommitLineData
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 12struct request_queue;
1da177e4 13struct block_device;
7dfdc9a5 14struct completion;
1da177e4
LT
15struct module;
16struct scsi_cmnd;
17struct scsi_device;
89d9a567 18struct scsi_host_cmd_pool;
a283bd37 19struct scsi_target;
1da177e4
LT
20struct Scsi_Host;
21struct scsi_host_cmd_pool;
22struct scsi_transport_template;
86e33a29 23struct 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
48enum {
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
54struct 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
539enum 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
549struct 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
06f81ea8 585 /*
586 * The following two fields are protected with host_lock;
587 * however, eh routines can safely access during eh processing
588 * without acquiring the lock.
589 */
590 unsigned int host_busy; /* commands actually active on low-level */
591 unsigned int host_failed; /* commands that failed. */
ee7863bc 592 unsigned int host_eh_scheduled; /* EH scheduled without command */
1da177e4 593
6d49f63b 594 unsigned int host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
1da177e4 595
b4562022
HR
596 /* next two fields are used to bound the time spent in error handling */
597 int eh_deadline;
598 unsigned long last_reset;
599
600
1da177e4
LT
601 /*
602 * These three parameters can be used to allow for wide scsi,
603 * and for host adapters that support multiple busses
604 * The first two should be set to 1 more than the actual max id
1abf635d 605 * or lun (e.g. 8 for SCSI parallel systems).
1da177e4 606 */
1da177e4 607 unsigned int max_channel;
1abf635d
HR
608 unsigned int max_id;
609 u64 max_lun;
1da177e4
LT
610
611 /*
612 * This is a unique identifier that must be assigned so that we
613 * have some way of identifying each detected host adapter properly
614 * and uniquely. For hosts that do not support more than one card
615 * in the system at one time, this does not need to be set. It is
616 * initialized to 0 in scsi_register.
617 */
618 unsigned int unique_id;
619
620 /*
621 * The maximum length of SCSI commands that this host can accept.
622 * Probably 12 for most host adapters, but could be 16 for others.
db4742dd 623 * or 260 if the driver supports variable length cdbs.
1da177e4 624 * For drivers that don't set this field, a value of 12 is
db4742dd 625 * assumed.
1da177e4 626 */
db4742dd 627 unsigned short max_cmd_len;
1da177e4
LT
628
629 int this_id;
630 int can_queue;
631 short cmd_per_lun;
632 short unsigned int sg_tablesize;
13f05c8d 633 short unsigned int sg_prot_tablesize;
8ed5a4d2 634 unsigned int max_sectors;
1da177e4
LT
635 unsigned long dma_boundary;
636 /*
637 * Used to assign serial numbers to the cmds.
638 * Protected by the host lock.
639 */
12a44162 640 unsigned long cmd_serial_number;
1da177e4 641
5dc2b89e 642 unsigned active_mode:2;
1da177e4
LT
643 unsigned unchecked_isa_dma:1;
644 unsigned use_clustering:1;
645 unsigned use_blk_tcq:1;
646
647 /*
648 * Host has requested that no further requests come through for the
649 * time being.
650 */
651 unsigned host_self_blocked:1;
652
653 /*
654 * Host uses correct SCSI ordering not PC ordering. The bit is
655 * set for the minority of drivers whose authors actually read
d850bd34 656 * the spec ;).
1da177e4
LT
657 */
658 unsigned reverse_ordering:1;
659
660 /*
d850bd34 661 * Ordered write support
1da177e4 662 */
1da177e4
LT
663 unsigned ordered_tag:1;
664
d850bd34 665 /* Task mgmt function in progress */
d7a1bb0a
JS
666 unsigned tmf_in_progress:1;
667
3e082a91
MW
668 /* Asynchronous scan in progress */
669 unsigned async_scan:1;
670
ae0751ff
LM
671 /* Don't resume host in EH */
672 unsigned eh_noresume:1;
673
54b2b50c
MP
674 /* The controller does not support WRITE SAME */
675 unsigned no_write_same:1;
676
1da177e4
LT
677 /*
678 * Optional work queue to be utilized by the transport
679 */
aab0de24 680 char work_q_name[20];
1da177e4
LT
681 struct workqueue_struct *work_q;
682
e494f6a7
HR
683 /*
684 * Task management function work queue
685 */
686 struct workqueue_struct *tmf_work_q;
687
1da177e4
LT
688 /*
689 * Host has rejected a command because it was busy.
690 */
691 unsigned int host_blocked;
692
693 /*
694 * Value host_blocked counts down from
695 */
696 unsigned int max_host_blocked;
697
4469f987
MP
698 /* Protection Information */
699 unsigned int prot_capabilities;
700 unsigned char prot_guard_type;
701
b58d9154
FT
702 /*
703 * q used for scsi_tgt msgs, async events or any other requests that
704 * need to be processed in userspace
705 */
706 struct request_queue *uspace_req_q;
707
1da177e4
LT
708 /* legacy crap */
709 unsigned long base;
710 unsigned long io_port;
711 unsigned char n_io_port;
712 unsigned char dma_channel;
713 unsigned int irq;
714
715
d3301874 716 enum scsi_host_state shost_state;
1da177e4
LT
717
718 /* ldm bits */
ee959b00 719 struct device shost_gendev, shost_dev;
1da177e4
LT
720
721 /*
722 * List of hosts per template.
723 *
724 * This is only for use by scsi_module.c for legacy templates.
725 * For these access to it is synchronized implicitly by
726 * module_init/module_exit.
727 */
728 struct list_head sht_legacy_list;
729
730 /*
731 * Points to the transport data (if any) which is allocated
732 * separately
733 */
734 void *shost_data;
735
d139b9bd
JB
736 /*
737 * Points to the physical bus device we'd use to do DMA
738 * Needed just in case we have virtual hosts.
739 */
740 struct device *dma_dev;
741
1da177e4
LT
742 /*
743 * We should ensure that this is aligned, both for better performance
744 * and also because some compilers (m68k) don't automatically force
745 * alignment to a long boundary.
746 */
747 unsigned long hostdata[0] /* Used for storage of host specific stuff */
748 __attribute__ ((aligned (sizeof(unsigned long))));
749};
750
751#define class_to_shost(d) \
ee959b00 752 container_of(d, struct Scsi_Host, shost_dev)
1da177e4 753
9ccfc756
JB
754#define shost_printk(prefix, shost, fmt, a...) \
755 dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)
756
bcd92c9f
CH
757static inline void *shost_priv(struct Scsi_Host *shost)
758{
759 return (void *)shost->hostdata;
760}
9ccfc756 761
1da177e4
LT
762int scsi_is_host_device(const struct device *);
763
764static inline struct Scsi_Host *dev_to_shost(struct device *dev)
765{
766 while (!scsi_is_host_device(dev)) {
767 if (!dev->parent)
768 return NULL;
769 dev = dev->parent;
770 }
771 return container_of(dev, struct Scsi_Host, shost_gendev);
772}
773
939647ee
JB
774static inline int scsi_host_in_recovery(struct Scsi_Host *shost)
775{
776 return shost->shost_state == SHOST_RECOVERY ||
777 shost->shost_state == SHOST_CANCEL_RECOVERY ||
d7a1bb0a
JS
778 shost->shost_state == SHOST_DEL_RECOVERY ||
779 shost->tmf_in_progress;
939647ee
JB
780}
781
1da177e4
LT
782extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
783extern void scsi_flush_work(struct Scsi_Host *);
784
785extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
d139b9bd
JB
786extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,
787 struct device *,
788 struct device *);
1da177e4 789extern void scsi_scan_host(struct Scsi_Host *);
1da177e4
LT
790extern void scsi_rescan_device(struct device *);
791extern void scsi_remove_host(struct Scsi_Host *);
792extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
793extern void scsi_host_put(struct Scsi_Host *t);
794extern struct Scsi_Host *scsi_host_lookup(unsigned short);
d3301874 795extern const char *scsi_host_state_name(enum scsi_host_state);
f281233d 796extern void scsi_cmd_get_serial(struct Scsi_Host *, struct scsi_cmnd *);
1da177e4
LT
797
798extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
799
d139b9bd
JB
800static inline int __must_check scsi_add_host(struct Scsi_Host *host,
801 struct device *dev)
802{
803 return scsi_add_host_with_dma(host, dev, dev);
804}
805
1da177e4
LT
806static inline struct device *scsi_get_device(struct Scsi_Host *shost)
807{
808 return shost->shost_gendev.parent;
809}
810
82f29467
MA
811/**
812 * scsi_host_scan_allowed - Is scanning of this host allowed
813 * @shost: Pointer to Scsi_Host.
814 **/
815static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)
816{
76e4e12f
MC
817 return shost->shost_state == SHOST_RUNNING ||
818 shost->shost_state == SHOST_RECOVERY;
82f29467
MA
819}
820
1da177e4
LT
821extern void scsi_unblock_requests(struct Scsi_Host *);
822extern void scsi_block_requests(struct Scsi_Host *);
823
824struct class_container;
b58d9154
FT
825
826extern struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
827 void (*) (struct request_queue *));
1da177e4
LT
828/*
829 * These two functions are used to allocate and free a pseudo device
830 * which will connect to the host adapter itself rather than any
831 * physical device. You must deallocate when you are done with the
832 * thing. This physical pseudo-device isn't real and won't be available
833 * from any high-level drivers.
834 */
835extern void scsi_free_host_dev(struct scsi_device *);
836extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
837
4469f987
MP
838/*
839 * DIF defines the exchange of protection information between
840 * initiator and SBC block device.
841 *
842 * DIX defines the exchange of protection information between OS and
843 * initiator.
844 */
845enum scsi_host_prot_capabilities {
846 SHOST_DIF_TYPE1_PROTECTION = 1 << 0, /* T10 DIF Type 1 */
847 SHOST_DIF_TYPE2_PROTECTION = 1 << 1, /* T10 DIF Type 2 */
848 SHOST_DIF_TYPE3_PROTECTION = 1 << 2, /* T10 DIF Type 3 */
849
850 SHOST_DIX_TYPE0_PROTECTION = 1 << 3, /* DIX between OS and HBA only */
851 SHOST_DIX_TYPE1_PROTECTION = 1 << 4, /* DIX with DIF Type 1 */
852 SHOST_DIX_TYPE2_PROTECTION = 1 << 5, /* DIX with DIF Type 2 */
853 SHOST_DIX_TYPE3_PROTECTION = 1 << 6, /* DIX with DIF Type 3 */
854};
855
856/*
857 * SCSI hosts which support the Data Integrity Extensions must
858 * indicate their capabilities by setting the prot_capabilities using
859 * this call.
860 */
861static inline void scsi_host_set_prot(struct Scsi_Host *shost, unsigned int mask)
862{
863 shost->prot_capabilities = mask;
864}
865
866static inline unsigned int scsi_host_get_prot(struct Scsi_Host *shost)
867{
868 return shost->prot_capabilities;
869}
870
13f05c8d
MP
871static inline int scsi_host_prot_dma(struct Scsi_Host *shost)
872{
873 return shost->prot_capabilities >= SHOST_DIX_TYPE0_PROTECTION;
874}
875
4469f987
MP
876static inline unsigned int scsi_host_dif_capable(struct Scsi_Host *shost, unsigned int target_type)
877{
b2b465e9
MP
878 static unsigned char cap[] = { 0,
879 SHOST_DIF_TYPE1_PROTECTION,
880 SHOST_DIF_TYPE2_PROTECTION,
881 SHOST_DIF_TYPE3_PROTECTION };
4469f987 882
4d24834d 883 if (target_type >= ARRAY_SIZE(cap))
fe542396
MP
884 return 0;
885
b2b465e9 886 return shost->prot_capabilities & cap[target_type] ? target_type : 0;
4469f987
MP
887}
888
889static inline unsigned int scsi_host_dix_capable(struct Scsi_Host *shost, unsigned int target_type)
890{
35e1a5d9 891#if defined(CONFIG_BLK_DEV_INTEGRITY)
b2b465e9
MP
892 static unsigned char cap[] = { SHOST_DIX_TYPE0_PROTECTION,
893 SHOST_DIX_TYPE1_PROTECTION,
894 SHOST_DIX_TYPE2_PROTECTION,
895 SHOST_DIX_TYPE3_PROTECTION };
896
4d24834d 897 if (target_type >= ARRAY_SIZE(cap))
fe542396
MP
898 return 0;
899
b2b465e9 900 return shost->prot_capabilities & cap[target_type];
35e1a5d9 901#endif
4469f987
MP
902 return 0;
903}
904
905/*
906 * All DIX-capable initiators must support the T10-mandated CRC
907 * checksum. Controllers can optionally implement the IP checksum
908 * scheme which has much lower impact on system performance. Note
909 * that the main rationale for the checksum is to match integrity
910 * metadata with data. Detecting bit errors are a job for ECC memory
911 * and buses.
912 */
913
914enum scsi_host_guard_type {
915 SHOST_DIX_GUARD_CRC = 1 << 0,
916 SHOST_DIX_GUARD_IP = 1 << 1,
917};
918
919static inline void scsi_host_set_guard(struct Scsi_Host *shost, unsigned char type)
920{
921 shost->prot_guard_type = type;
922}
923
924static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)
925{
926 return shost->prot_guard_type;
927}
928
1da177e4
LT
929/* legacy interfaces */
930extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
931extern void scsi_unregister(struct Scsi_Host *);
47ba39ee 932extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);
1da177e4
LT
933
934#endif /* _SCSI_SCSI_HOST_H */
This page took 0.576079 seconds and 5 git commands to generate.