blob: 7f1f411d07af04c47f1faf7ce6400b57c197fef2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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>
Arjan van de Ven0b950672006-01-11 13:16:10 +01008#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
FUJITA Tomonorib58d9152006-11-16 19:24:10 +090010struct request_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011struct block_device;
Christoph Hellwig7dfdc9a2005-10-31 18:49:52 +010012struct completion;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013struct module;
14struct scsi_cmnd;
15struct scsi_device;
James Bottomleya283bd32005-05-24 12:06:38 -050016struct scsi_target;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017struct Scsi_Host;
18struct scsi_host_cmd_pool;
19struct scsi_transport_template;
James Bottomley86e33a22006-08-30 09:45:51 -040020struct blk_queue_tags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22
23/*
24 * The various choices mean:
25 * NONE: Self evident. Host adapter is not capable of scatter-gather.
26 * ALL: Means that the host adapter module can do scatter-gather,
27 * and that there is no limit to the size of the table to which
28 * we scatter/gather data.
29 * Anything else: Indicates the maximum number of chains that can be
30 * used in one scatter-gather request.
31 */
32#define SG_NONE 0
33#define SG_ALL 0xff
34
35
36#define DISABLE_CLUSTERING 0
37#define ENABLE_CLUSTERING 1
38
39enum scsi_eh_timer_return {
40 EH_NOT_HANDLED,
41 EH_HANDLED,
42 EH_RESET_TIMER,
43};
44
45
46struct scsi_host_template {
47 struct module *module;
48 const char *name;
49
50 /*
51 * Used to initialize old-style drivers. For new-style drivers
52 * just perform all work in your module initialization function.
53 *
54 * Status: OBSOLETE
55 */
56 int (* detect)(struct scsi_host_template *);
57
58 /*
59 * Used as unload callback for hosts with old-style drivers.
60 *
61 * Status: OBSOLETE
62 */
63 int (* release)(struct Scsi_Host *);
64
65 /*
66 * The info function will return whatever useful information the
67 * developer sees fit. If not provided, then the name field will
68 * be used instead.
69 *
70 * Status: OPTIONAL
71 */
72 const char *(* info)(struct Scsi_Host *);
73
74 /*
75 * Ioctl interface
76 *
77 * Status: OPTIONAL
78 */
79 int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
80
81
82#ifdef CONFIG_COMPAT
83 /*
84 * Compat handler. Handle 32bit ABI.
85 * When unknown ioctl is passed return -ENOIOCTLCMD.
86 *
87 * Status: OPTIONAL
88 */
89 int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
90#endif
91
92 /*
93 * The queuecommand function is used to queue up a scsi
94 * command block to the LLDD. When the driver finished
95 * processing the command the done callback is invoked.
96 *
97 * If queuecommand returns 0, then the HBA has accepted the
98 * command. The done() function must be called on the command
99 * when the driver has finished with it. (you may call done on the
100 * command before queuecommand returns, but in this case you
101 * *must* return 0 from queuecommand).
102 *
103 * Queuecommand may also reject the command, in which case it may
104 * not touch the command and must not call done() for it.
105 *
106 * There are two possible rejection returns:
107 *
108 * SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
109 * allow commands to other devices serviced by this host.
110 *
111 * SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
112 * host temporarily.
113 *
114 * For compatibility, any other non-zero return is treated the
115 * same as SCSI_MLQUEUE_HOST_BUSY.
116 *
117 * NOTE: "temporarily" means either until the next command for#
118 * this device/host completes, or a period of time determined by
119 * I/O pressure in the system if there are no other outstanding
120 * commands.
121 *
122 * STATUS: REQUIRED
123 */
124 int (* queuecommand)(struct scsi_cmnd *,
125 void (*done)(struct scsi_cmnd *));
126
127 /*
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900128 * The transfer functions are used to queue a scsi command to
129 * the LLD. When the driver is finished processing the command
130 * the done callback is invoked.
131 *
132 * return values: see queuecommand
133 *
134 * If the LLD accepts the cmd, it should set the result to an
135 * appropriate value when completed before calling the done function.
136 *
137 * STATUS: REQUIRED FOR TARGET DRIVERS
138 */
139 /* TODO: rename */
140 int (* transfer_response)(struct scsi_cmnd *,
141 void (*done)(struct scsi_cmnd *));
142 /*
143 * This is called to inform the LLD to transfer cmd->request_bufflen
144 * bytes of the cmd at cmd->offset in the cmd. The cmd->use_sg
145 * speciefies the number of scatterlist entried in the command
146 * and cmd->request_buffer contains the scatterlist.
147 *
148 * If the command cannot be processed in one transfer_data call
149 * becuase a scatterlist within the LLD's limits cannot be
150 * created then transfer_data will be called multiple times.
151 * It is initially called from process context, and later
152 * calls are from the interrup context.
153 */
154 int (* transfer_data)(struct scsi_cmnd *,
155 void (*done)(struct scsi_cmnd *));
156
157 /* Used as callback for the completion of task management request. */
158 int (* tsk_mgmt_response)(u64 mid, int result);
159
160 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 * This is an error handling strategy routine. You don't need to
162 * define one of these if you don't want to - there is a default
163 * routine that is present that should work in most cases. For those
164 * driver authors that have the inclination and ability to write their
165 * own strategy routine, this is where it is specified. Note - the
166 * strategy routine is *ALWAYS* run in the context of the kernel eh
167 * thread. Thus you are guaranteed to *NOT* be in an interrupt
168 * handler when you execute this, and you are also guaranteed to
169 * *NOT* have any other commands being queued while you are in the
170 * strategy routine. When you return from this function, operations
171 * return to normal.
172 *
173 * See scsi_error.c scsi_unjam_host for additional comments about
174 * what this function should and should not be attempting to do.
175 *
176 * Status: REQUIRED (at least one of them)
177 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 int (* eh_abort_handler)(struct scsi_cmnd *);
179 int (* eh_device_reset_handler)(struct scsi_cmnd *);
180 int (* eh_bus_reset_handler)(struct scsi_cmnd *);
181 int (* eh_host_reset_handler)(struct scsi_cmnd *);
182
183 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 * Before the mid layer attempts to scan for a new device where none
185 * currently exists, it will call this entry in your driver. Should
186 * your driver need to allocate any structs or perform any other init
187 * items in order to send commands to a currently unused target/lun
188 * combo, then this is where you can perform those allocations. This
189 * is specifically so that drivers won't have to perform any kind of
190 * "is this a new device" checks in their queuecommand routine,
191 * thereby making the hot path a bit quicker.
192 *
193 * Return values: 0 on success, non-0 on failure
194 *
195 * Deallocation: If we didn't find any devices at this ID, you will
196 * get an immediate call to slave_destroy(). If we find something
197 * here then you will get a call to slave_configure(), then the
198 * device will be used for however long it is kept around, then when
199 * the device is removed from the system (or * possibly at reboot
200 * time), you will then get a call to slave_destroy(). This is
201 * assuming you implement slave_configure and slave_destroy.
202 * However, if you allocate memory and hang it off the device struct,
203 * then you must implement the slave_destroy() routine at a minimum
204 * in order to avoid leaking memory
205 * each time a device is tore down.
206 *
207 * Status: OPTIONAL
208 */
209 int (* slave_alloc)(struct scsi_device *);
210
211 /*
212 * Once the device has responded to an INQUIRY and we know the
213 * device is online, we call into the low level driver with the
214 * struct scsi_device *. If the low level device driver implements
215 * this function, it *must* perform the task of setting the queue
216 * depth on the device. All other tasks are optional and depend
217 * on what the driver supports and various implementation details.
218 *
219 * Things currently recommended to be handled at this time include:
220 *
221 * 1. Setting the device queue depth. Proper setting of this is
222 * described in the comments for scsi_adjust_queue_depth.
223 * 2. Determining if the device supports the various synchronous
224 * negotiation protocols. The device struct will already have
225 * responded to INQUIRY and the results of the standard items
226 * will have been shoved into the various device flag bits, eg.
227 * device->sdtr will be true if the device supports SDTR messages.
228 * 3. Allocating command structs that the device will need.
229 * 4. Setting the default timeout on this device (if needed).
230 * 5. Anything else the low level driver might want to do on a device
231 * specific setup basis...
232 * 6. Return 0 on success, non-0 on error. The device will be marked
233 * as offline on error so that no access will occur. If you return
234 * non-0, your slave_destroy routine will never get called for this
235 * device, so don't leave any loose memory hanging around, clean
236 * up after yourself before returning non-0
237 *
238 * Status: OPTIONAL
239 */
240 int (* slave_configure)(struct scsi_device *);
241
242 /*
243 * Immediately prior to deallocating the device and after all activity
244 * has ceased the mid layer calls this point so that the low level
245 * driver may completely detach itself from the scsi device and vice
246 * versa. The low level driver is responsible for freeing any memory
247 * it allocated in the slave_alloc or slave_configure calls.
248 *
249 * Status: OPTIONAL
250 */
251 void (* slave_destroy)(struct scsi_device *);
252
253 /*
James Bottomleya283bd32005-05-24 12:06:38 -0500254 * Before the mid layer attempts to scan for a new device attached
255 * to a target where no target currently exists, it will call this
256 * entry in your driver. Should your driver need to allocate any
257 * structs or perform any other init items in order to send commands
258 * to a currently unused target, then this is where you can perform
259 * those allocations.
260 *
261 * Return values: 0 on success, non-0 on failure
262 *
263 * Status: OPTIONAL
264 */
265 int (* target_alloc)(struct scsi_target *);
266
267 /*
268 * Immediately prior to deallocating the target structure, and
269 * after all activity to attached scsi devices has ceased, the
270 * midlayer calls this point so that the driver may deallocate
271 * and terminate any references to the target.
272 *
273 * Status: OPTIONAL
274 */
275 void (* target_destroy)(struct scsi_target *);
276
277 /*
Matthew Wilcox1aa8fab2006-11-22 13:24:54 -0700278 * If a host has the ability to discover targets on its own instead
279 * of scanning the entire bus, it can fill in this function and
280 * call scsi_scan_host(). This function will be called periodically
281 * until it returns 1 with the scsi_host and the elapsed time of
282 * the scan in jiffies.
283 *
284 * Status: OPTIONAL
285 */
286 int (* scan_finished)(struct Scsi_Host *, unsigned long);
287
288 /*
289 * If the host wants to be called before the scan starts, but
290 * after the midlayer has set up ready for the scan, it can fill
291 * in this function.
292 */
293 void (* scan_start)(struct Scsi_Host *);
294
295 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 * fill in this function to allow the queue depth of this host
297 * to be changeable (on a per device basis). returns either
298 * the current queue depth setting (may be different from what
299 * was passed in) or an error. An error should only be
300 * returned if the requested depth is legal but the driver was
301 * unable to set it. If the requested depth is illegal, the
302 * driver should set and return the closest legal queue depth.
303 *
304 */
305 int (* change_queue_depth)(struct scsi_device *, int);
306
307 /*
308 * fill in this function to allow the changing of tag types
309 * (this also allows the enabling/disabling of tag command
310 * queueing). An error should only be returned if something
311 * went wrong in the driver while trying to set the tag type.
312 * If the driver doesn't support the requested tag type, then
313 * it should set the closest type it does support without
314 * returning an error. Returns the actual tag type set.
315 */
316 int (* change_queue_type)(struct scsi_device *, int);
317
318 /*
319 * This function determines the bios parameters for a given
320 * harddisk. These tend to be numbers that are made up by
321 * the host adapter. Parameters:
322 * size, device, list (heads, sectors, cylinders)
323 *
324 * Status: OPTIONAL */
325 int (* bios_param)(struct scsi_device *, struct block_device *,
326 sector_t, int []);
327
328 /*
329 * Can be used to export driver statistics and other infos to the
330 * world outside the kernel ie. userspace and it also provides an
331 * interface to feed the driver with information.
332 *
333 * Status: OBSOLETE
334 */
335 int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
336
337 /*
Jens Axboe9b847542006-01-06 09:28:07 +0100338 * suspend support
339 */
340 int (*resume)(struct scsi_device *);
Nigel Cunningham082776e2006-03-23 23:22:16 +1000341 int (*suspend)(struct scsi_device *, pm_message_t state);
Jens Axboe9b847542006-01-06 09:28:07 +0100342
343 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 * Name of proc directory
345 */
346 char *proc_name;
347
348 /*
349 * Used to store the procfs directory if a driver implements the
350 * proc_info method.
351 */
352 struct proc_dir_entry *proc_dir;
353
354 /*
355 * This determines if we will use a non-interrupt driven
356 * or an interrupt driven scheme, It is set to the maximum number
357 * of simultaneous commands a given host adapter will accept.
358 */
359 int can_queue;
360
361 /*
362 * In many instances, especially where disconnect / reconnect are
363 * supported, our host also has an ID on the SCSI bus. If this is
364 * the case, then it must be reserved. Please set this_id to -1 if
365 * your setup is in single initiator mode, and the host lacks an
366 * ID.
367 */
368 int this_id;
369
370 /*
371 * This determines the degree to which the host adapter is capable
372 * of scatter-gather.
373 */
374 unsigned short sg_tablesize;
375
376 /*
377 * If the host adapter has limitations beside segment count
378 */
379 unsigned short max_sectors;
380
381 /*
382 * dma scatter gather segment boundary limit. a segment crossing this
383 * boundary will be split in two.
384 */
385 unsigned long dma_boundary;
386
387 /*
388 * This specifies "machine infinity" for host templates which don't
389 * limit the transfer size. Note this limit represents an absolute
390 * maximum, and may be over the transfer limits allowed for
391 * individual devices (e.g. 256 for SCSI-1)
392 */
393#define SCSI_DEFAULT_MAX_SECTORS 1024
394
395 /*
396 * True if this host adapter can make good use of linked commands.
397 * This will allow more than one command to be queued to a given
398 * unit on a given host. Set this to the maximum number of command
399 * blocks to be provided for each device. Set this to 1 for one
400 * command block per lun, 2 for two, etc. Do not set this to 0.
401 * You should make sure that the host adapter will do the right thing
402 * before you try setting this above 1.
403 */
404 short cmd_per_lun;
405
406 /*
407 * present contains counter indicating how many boards of this
408 * type were found when we did the scan.
409 */
410 unsigned char present;
411
412 /*
413 * true if this host adapter uses unchecked DMA onto an ISA bus.
414 */
415 unsigned unchecked_isa_dma:1;
416
417 /*
418 * true if this host adapter can make good use of clustering.
419 * I originally thought that if the tablesize was large that it
420 * was a waste of CPU cycles to prepare a cluster list, but
421 * it works out that the Buslogic is faster if you use a smaller
422 * number of segments (i.e. use clustering). I guess it is
423 * inefficient.
424 */
425 unsigned use_clustering:1;
426
427 /*
428 * True for emulated SCSI host adapters (e.g. ATAPI)
429 */
430 unsigned emulated:1;
431
432 /*
433 * True if the low-level driver performs its own reset-settle delays.
434 */
435 unsigned skip_settle_delay:1;
436
437 /*
438 * ordered write support
439 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 unsigned ordered_tag:1;
441
442 /*
443 * Countdown for host blocking with no commands outstanding
444 */
445 unsigned int max_host_blocked;
446
447 /*
448 * Default value for the blocking. If the queue is empty,
449 * host_blocked counts down in the request_fn until it restarts
450 * host operations as zero is reached.
451 *
452 * FIXME: This should probably be a value in the template
453 */
454#define SCSI_DEFAULT_HOST_BLOCKED 7
455
456 /*
457 * Pointer to the sysfs class properties for this host, NULL terminated.
458 */
459 struct class_device_attribute **shost_attrs;
460
461 /*
462 * Pointer to the SCSI device properties for this host, NULL terminated.
463 */
464 struct device_attribute **sdev_attrs;
465
466 /*
467 * List of hosts per template.
468 *
469 * This is only for use by scsi_module.c for legacy templates.
470 * For these access to it is synchronized implicitly by
471 * module_init/module_exit.
472 */
473 struct list_head legacy_hosts;
474};
475
476/*
Mike Andersond3301872005-06-16 11:12:38 -0700477 * shost state: If you alter this, you also need to alter scsi_sysfs.c
478 * (for the ascii descriptions) and the state model enforcer:
479 * scsi_host_set_state()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 */
Mike Andersond3301872005-06-16 11:12:38 -0700481enum scsi_host_state {
482 SHOST_CREATED = 1,
483 SHOST_RUNNING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 SHOST_CANCEL,
Mike Andersond3301872005-06-16 11:12:38 -0700485 SHOST_DEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 SHOST_RECOVERY,
James Bottomley939647e2005-09-18 15:05:20 -0500487 SHOST_CANCEL_RECOVERY,
488 SHOST_DEL_RECOVERY,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489};
490
491struct Scsi_Host {
492 /*
493 * __devices is protected by the host_lock, but you should
494 * usually use scsi_device_lookup / shost_for_each_device
495 * to access it and don't care about locking yourself.
496 * In the rare case of beeing in irq context you can use
497 * their __ prefixed variants with the lock held. NEVER
498 * access this list directly from a driver.
499 */
500 struct list_head __devices;
501 struct list_head __targets;
502
503 struct scsi_host_cmd_pool *cmd_pool;
504 spinlock_t free_list_lock;
505 struct list_head free_list; /* backup store of cmd structs */
506 struct list_head starved_list;
507
508 spinlock_t default_lock;
509 spinlock_t *host_lock;
510
Arjan van de Ven0b950672006-01-11 13:16:10 +0100511 struct mutex scan_mutex;/* serialize scanning activity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 struct list_head eh_cmd_q;
514 struct task_struct * ehandler; /* Error recovery thread. */
Christoph Hellwig7dfdc9a2005-10-31 18:49:52 +0100515 struct completion * eh_action; /* Wait for specific actions on the
516 host. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 wait_queue_head_t host_wait;
518 struct scsi_host_template *hostt;
519 struct scsi_transport_template *transportt;
06f81ea2005-04-17 14:57:29 -0500520
521 /*
James Bottomley86e33a22006-08-30 09:45:51 -0400522 * area to keep a shared tag map (if needed, will be
523 * NULL if not)
524 */
525 struct blk_queue_tag *bqt;
526
527 /*
06f81ea2005-04-17 14:57:29 -0500528 * The following two fields are protected with host_lock;
529 * however, eh routines can safely access during eh processing
530 * without acquiring the lock.
531 */
532 unsigned int host_busy; /* commands actually active on low-level */
533 unsigned int host_failed; /* commands that failed. */
Tejun Heoee7863b2006-05-15 20:57:20 +0900534 unsigned int host_eh_scheduled; /* EH scheduled without command */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
537 int resetting; /* if set, it means that last_reset is a valid value */
538 unsigned long last_reset;
539
540 /*
541 * These three parameters can be used to allow for wide scsi,
542 * and for host adapters that support multiple busses
543 * The first two should be set to 1 more than the actual max id
544 * or lun (i.e. 8 for normal systems).
545 */
546 unsigned int max_id;
547 unsigned int max_lun;
548 unsigned int max_channel;
549
550 /*
551 * This is a unique identifier that must be assigned so that we
552 * have some way of identifying each detected host adapter properly
553 * and uniquely. For hosts that do not support more than one card
554 * in the system at one time, this does not need to be set. It is
555 * initialized to 0 in scsi_register.
556 */
557 unsigned int unique_id;
558
559 /*
560 * The maximum length of SCSI commands that this host can accept.
561 * Probably 12 for most host adapters, but could be 16 for others.
562 * For drivers that don't set this field, a value of 12 is
563 * assumed. I am leaving this as a number rather than a bit
564 * because you never know what subsequent SCSI standards might do
565 * (i.e. could there be a 20 byte or a 24-byte command a few years
566 * down the road?).
567 */
568 unsigned char max_cmd_len;
569
570 int this_id;
571 int can_queue;
572 short cmd_per_lun;
573 short unsigned int sg_tablesize;
574 short unsigned int max_sectors;
575 unsigned long dma_boundary;
576 /*
577 * Used to assign serial numbers to the cmds.
578 * Protected by the host lock.
579 */
580 unsigned long cmd_serial_number, cmd_pid;
581
582 unsigned unchecked_isa_dma:1;
583 unsigned use_clustering:1;
584 unsigned use_blk_tcq:1;
585
586 /*
587 * Host has requested that no further requests come through for the
588 * time being.
589 */
590 unsigned host_self_blocked:1;
591
592 /*
593 * Host uses correct SCSI ordering not PC ordering. The bit is
594 * set for the minority of drivers whose authors actually read
595 * the spec ;)
596 */
597 unsigned reverse_ordering:1;
598
599 /*
600 * ordered write support
601 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 unsigned ordered_tag:1;
603
James Smartd7a1bb02006-03-08 14:50:12 -0500604 /* task mgmt function in progress */
605 unsigned tmf_in_progress:1;
606
Matthew Wilcox3e082a92006-09-28 15:19:20 -0600607 /* Asynchronous scan in progress */
608 unsigned async_scan:1;
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /*
611 * Optional work queue to be utilized by the transport
612 */
613 char work_q_name[KOBJ_NAME_LEN];
614 struct workqueue_struct *work_q;
615
616 /*
617 * Host has rejected a command because it was busy.
618 */
619 unsigned int host_blocked;
620
621 /*
622 * Value host_blocked counts down from
623 */
624 unsigned int max_host_blocked;
625
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900626 /*
627 * q used for scsi_tgt msgs, async events or any other requests that
628 * need to be processed in userspace
629 */
630 struct request_queue *uspace_req_q;
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 /* legacy crap */
633 unsigned long base;
634 unsigned long io_port;
635 unsigned char n_io_port;
636 unsigned char dma_channel;
637 unsigned int irq;
638
639
Mike Andersond3301872005-06-16 11:12:38 -0700640 enum scsi_host_state shost_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 /* ldm bits */
643 struct device shost_gendev;
644 struct class_device shost_classdev;
645
646 /*
647 * List of hosts per template.
648 *
649 * This is only for use by scsi_module.c for legacy templates.
650 * For these access to it is synchronized implicitly by
651 * module_init/module_exit.
652 */
653 struct list_head sht_legacy_list;
654
655 /*
656 * Points to the transport data (if any) which is allocated
657 * separately
658 */
659 void *shost_data;
660
661 /*
662 * We should ensure that this is aligned, both for better performance
663 * and also because some compilers (m68k) don't automatically force
664 * alignment to a long boundary.
665 */
666 unsigned long hostdata[0] /* Used for storage of host specific stuff */
667 __attribute__ ((aligned (sizeof(unsigned long))));
668};
669
670#define class_to_shost(d) \
671 container_of(d, struct Scsi_Host, shost_classdev)
672
James Bottomley9ccfc752005-10-02 11:45:08 -0500673#define shost_printk(prefix, shost, fmt, a...) \
674 dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)
675
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677int scsi_is_host_device(const struct device *);
678
679static inline struct Scsi_Host *dev_to_shost(struct device *dev)
680{
681 while (!scsi_is_host_device(dev)) {
682 if (!dev->parent)
683 return NULL;
684 dev = dev->parent;
685 }
686 return container_of(dev, struct Scsi_Host, shost_gendev);
687}
688
James Bottomley939647e2005-09-18 15:05:20 -0500689static inline int scsi_host_in_recovery(struct Scsi_Host *shost)
690{
691 return shost->shost_state == SHOST_RECOVERY ||
692 shost->shost_state == SHOST_CANCEL_RECOVERY ||
James Smartd7a1bb02006-03-08 14:50:12 -0500693 shost->shost_state == SHOST_DEL_RECOVERY ||
694 shost->tmf_in_progress;
James Bottomley939647e2005-09-18 15:05:20 -0500695}
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
698extern void scsi_flush_work(struct Scsi_Host *);
699
700extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
701extern int __must_check scsi_add_host(struct Scsi_Host *, struct device *);
702extern void scsi_scan_host(struct Scsi_Host *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703extern void scsi_rescan_device(struct device *);
704extern void scsi_remove_host(struct Scsi_Host *);
705extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
706extern void scsi_host_put(struct Scsi_Host *t);
707extern struct Scsi_Host *scsi_host_lookup(unsigned short);
Mike Andersond3301872005-06-16 11:12:38 -0700708extern const char *scsi_host_state_name(enum scsi_host_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712static inline struct device *scsi_get_device(struct Scsi_Host *shost)
713{
714 return shost->shost_gendev.parent;
715}
716
Mike Anderson82f29462005-06-16 11:14:33 -0700717/**
718 * scsi_host_scan_allowed - Is scanning of this host allowed
719 * @shost: Pointer to Scsi_Host.
720 **/
721static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)
722{
723 return shost->shost_state == SHOST_RUNNING;
724}
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726extern void scsi_unblock_requests(struct Scsi_Host *);
727extern void scsi_block_requests(struct Scsi_Host *);
728
729struct class_container;
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900730
731extern struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
732 void (*) (struct request_queue *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733/*
734 * These two functions are used to allocate and free a pseudo device
735 * which will connect to the host adapter itself rather than any
736 * physical device. You must deallocate when you are done with the
737 * thing. This physical pseudo-device isn't real and won't be available
738 * from any high-level drivers.
739 */
740extern void scsi_free_host_dev(struct scsi_device *);
741extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
742
743/* legacy interfaces */
744extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
745extern void scsi_unregister(struct Scsi_Host *);
James Bottomley47ba39e2005-07-30 11:39:53 -0500746extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748#endif /* _SCSI_SCSI_HOST_H */