aboutsummaryrefslogtreecommitdiffstats
path: root/include/scsi/scsi_host.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/scsi/scsi_host.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/scsi/scsi_host.h')
-rw-r--r--include/scsi/scsi_host.h642
1 files changed, 642 insertions, 0 deletions
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
new file mode 100644
index 000000000000..27f2c4e8943a
--- /dev/null
+++ b/include/scsi/scsi_host.h
@@ -0,0 +1,642 @@
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>
8
9struct block_device;
10struct module;
11struct scsi_cmnd;
12struct scsi_device;
13struct Scsi_Host;
14struct scsi_host_cmd_pool;
15struct scsi_transport_template;
16
17
18/*
19 * The various choices mean:
20 * NONE: Self evident. Host adapter is not capable of scatter-gather.
21 * ALL: Means that the host adapter module can do scatter-gather,
22 * and that there is no limit to the size of the table to which
23 * we scatter/gather data.
24 * Anything else: Indicates the maximum number of chains that can be
25 * used in one scatter-gather request.
26 */
27#define SG_NONE 0
28#define SG_ALL 0xff
29
30
31#define DISABLE_CLUSTERING 0
32#define ENABLE_CLUSTERING 1
33
34enum scsi_eh_timer_return {
35 EH_NOT_HANDLED,
36 EH_HANDLED,
37 EH_RESET_TIMER,
38};
39
40
41struct scsi_host_template {
42 struct module *module;
43 const char *name;
44
45 /*
46 * Used to initialize old-style drivers. For new-style drivers
47 * just perform all work in your module initialization function.
48 *
49 * Status: OBSOLETE
50 */
51 int (* detect)(struct scsi_host_template *);
52
53 /*
54 * Used as unload callback for hosts with old-style drivers.
55 *
56 * Status: OBSOLETE
57 */
58 int (* release)(struct Scsi_Host *);
59
60 /*
61 * The info function will return whatever useful information the
62 * developer sees fit. If not provided, then the name field will
63 * be used instead.
64 *
65 * Status: OPTIONAL
66 */
67 const char *(* info)(struct Scsi_Host *);
68
69 /*
70 * Ioctl interface
71 *
72 * Status: OPTIONAL
73 */
74 int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
75
76
77#ifdef CONFIG_COMPAT
78 /*
79 * Compat handler. Handle 32bit ABI.
80 * When unknown ioctl is passed return -ENOIOCTLCMD.
81 *
82 * Status: OPTIONAL
83 */
84 int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
85#endif
86
87 /*
88 * The queuecommand function is used to queue up a scsi
89 * command block to the LLDD. When the driver finished
90 * processing the command the done callback is invoked.
91 *
92 * If queuecommand returns 0, then the HBA has accepted the
93 * command. The done() function must be called on the command
94 * when the driver has finished with it. (you may call done on the
95 * command before queuecommand returns, but in this case you
96 * *must* return 0 from queuecommand).
97 *
98 * Queuecommand may also reject the command, in which case it may
99 * not touch the command and must not call done() for it.
100 *
101 * There are two possible rejection returns:
102 *
103 * SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
104 * allow commands to other devices serviced by this host.
105 *
106 * SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
107 * host temporarily.
108 *
109 * For compatibility, any other non-zero return is treated the
110 * same as SCSI_MLQUEUE_HOST_BUSY.
111 *
112 * NOTE: "temporarily" means either until the next command for#
113 * this device/host completes, or a period of time determined by
114 * I/O pressure in the system if there are no other outstanding
115 * commands.
116 *
117 * STATUS: REQUIRED
118 */
119 int (* queuecommand)(struct scsi_cmnd *,
120 void (*done)(struct scsi_cmnd *));
121
122 /*
123 * This is an error handling strategy routine. You don't need to
124 * define one of these if you don't want to - there is a default
125 * routine that is present that should work in most cases. For those
126 * driver authors that have the inclination and ability to write their
127 * own strategy routine, this is where it is specified. Note - the
128 * strategy routine is *ALWAYS* run in the context of the kernel eh
129 * thread. Thus you are guaranteed to *NOT* be in an interrupt
130 * handler when you execute this, and you are also guaranteed to
131 * *NOT* have any other commands being queued while you are in the
132 * strategy routine. When you return from this function, operations
133 * return to normal.
134 *
135 * See scsi_error.c scsi_unjam_host for additional comments about
136 * what this function should and should not be attempting to do.
137 *
138 * Status: REQUIRED (at least one of them)
139 */
140 int (* eh_strategy_handler)(struct Scsi_Host *);
141 int (* eh_abort_handler)(struct scsi_cmnd *);
142 int (* eh_device_reset_handler)(struct scsi_cmnd *);
143 int (* eh_bus_reset_handler)(struct scsi_cmnd *);
144 int (* eh_host_reset_handler)(struct scsi_cmnd *);
145
146 /*
147 * This is an optional routine to notify the host that the scsi
148 * timer just fired. The returns tell the timer routine what to
149 * do about this:
150 *
151 * EH_HANDLED: I fixed the error, please complete the command
152 * EH_RESET_TIMER: I need more time, reset the timer and
153 * begin counting again
154 * EH_NOT_HANDLED Begin normal error recovery
155 *
156 * Status: OPTIONAL
157 */
158 enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
159
160 /*
161 * Before the mid layer attempts to scan for a new device where none
162 * currently exists, it will call this entry in your driver. Should
163 * your driver need to allocate any structs or perform any other init
164 * items in order to send commands to a currently unused target/lun
165 * combo, then this is where you can perform those allocations. This
166 * is specifically so that drivers won't have to perform any kind of
167 * "is this a new device" checks in their queuecommand routine,
168 * thereby making the hot path a bit quicker.
169 *
170 * Return values: 0 on success, non-0 on failure
171 *
172 * Deallocation: If we didn't find any devices at this ID, you will
173 * get an immediate call to slave_destroy(). If we find something
174 * here then you will get a call to slave_configure(), then the
175 * device will be used for however long it is kept around, then when
176 * the device is removed from the system (or * possibly at reboot
177 * time), you will then get a call to slave_destroy(). This is
178 * assuming you implement slave_configure and slave_destroy.
179 * However, if you allocate memory and hang it off the device struct,
180 * then you must implement the slave_destroy() routine at a minimum
181 * in order to avoid leaking memory
182 * each time a device is tore down.
183 *
184 * Status: OPTIONAL
185 */
186 int (* slave_alloc)(struct scsi_device *);
187
188 /*
189 * Once the device has responded to an INQUIRY and we know the
190 * device is online, we call into the low level driver with the
191 * struct scsi_device *. If the low level device driver implements
192 * this function, it *must* perform the task of setting the queue
193 * depth on the device. All other tasks are optional and depend
194 * on what the driver supports and various implementation details.
195 *
196 * Things currently recommended to be handled at this time include:
197 *
198 * 1. Setting the device queue depth. Proper setting of this is
199 * described in the comments for scsi_adjust_queue_depth.
200 * 2. Determining if the device supports the various synchronous
201 * negotiation protocols. The device struct will already have
202 * responded to INQUIRY and the results of the standard items
203 * will have been shoved into the various device flag bits, eg.
204 * device->sdtr will be true if the device supports SDTR messages.
205 * 3. Allocating command structs that the device will need.
206 * 4. Setting the default timeout on this device (if needed).
207 * 5. Anything else the low level driver might want to do on a device
208 * specific setup basis...
209 * 6. Return 0 on success, non-0 on error. The device will be marked
210 * as offline on error so that no access will occur. If you return
211 * non-0, your slave_destroy routine will never get called for this
212 * device, so don't leave any loose memory hanging around, clean
213 * up after yourself before returning non-0
214 *
215 * Status: OPTIONAL
216 */
217 int (* slave_configure)(struct scsi_device *);
218
219 /*
220 * Immediately prior to deallocating the device and after all activity
221 * has ceased the mid layer calls this point so that the low level
222 * driver may completely detach itself from the scsi device and vice
223 * versa. The low level driver is responsible for freeing any memory
224 * it allocated in the slave_alloc or slave_configure calls.
225 *
226 * Status: OPTIONAL
227 */
228 void (* slave_destroy)(struct scsi_device *);
229
230 /*
231 * fill in this function to allow the queue depth of this host
232 * to be changeable (on a per device basis). returns either
233 * the current queue depth setting (may be different from what
234 * was passed in) or an error. An error should only be
235 * returned if the requested depth is legal but the driver was
236 * unable to set it. If the requested depth is illegal, the
237 * driver should set and return the closest legal queue depth.
238 *
239 */
240 int (* change_queue_depth)(struct scsi_device *, int);
241
242 /*
243 * fill in this function to allow the changing of tag types
244 * (this also allows the enabling/disabling of tag command
245 * queueing). An error should only be returned if something
246 * went wrong in the driver while trying to set the tag type.
247 * If the driver doesn't support the requested tag type, then
248 * it should set the closest type it does support without
249 * returning an error. Returns the actual tag type set.
250 */
251 int (* change_queue_type)(struct scsi_device *, int);
252
253 /*
254 * This function determines the bios parameters for a given
255 * harddisk. These tend to be numbers that are made up by
256 * the host adapter. Parameters:
257 * size, device, list (heads, sectors, cylinders)
258 *
259 * Status: OPTIONAL */
260 int (* bios_param)(struct scsi_device *, struct block_device *,
261 sector_t, int []);
262
263 /*
264 * Can be used to export driver statistics and other infos to the
265 * world outside the kernel ie. userspace and it also provides an
266 * interface to feed the driver with information.
267 *
268 * Status: OBSOLETE
269 */
270 int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
271
272 /*
273 * Name of proc directory
274 */
275 char *proc_name;
276
277 /*
278 * Used to store the procfs directory if a driver implements the
279 * proc_info method.
280 */
281 struct proc_dir_entry *proc_dir;
282
283 /*
284 * This determines if we will use a non-interrupt driven
285 * or an interrupt driven scheme, It is set to the maximum number
286 * of simultaneous commands a given host adapter will accept.
287 */
288 int can_queue;
289
290 /*
291 * In many instances, especially where disconnect / reconnect are
292 * supported, our host also has an ID on the SCSI bus. If this is
293 * the case, then it must be reserved. Please set this_id to -1 if
294 * your setup is in single initiator mode, and the host lacks an
295 * ID.
296 */
297 int this_id;
298
299 /*
300 * This determines the degree to which the host adapter is capable
301 * of scatter-gather.
302 */
303 unsigned short sg_tablesize;
304
305 /*
306 * If the host adapter has limitations beside segment count
307 */
308 unsigned short max_sectors;
309
310 /*
311 * dma scatter gather segment boundary limit. a segment crossing this
312 * boundary will be split in two.
313 */
314 unsigned long dma_boundary;
315
316 /*
317 * This specifies "machine infinity" for host templates which don't
318 * limit the transfer size. Note this limit represents an absolute
319 * maximum, and may be over the transfer limits allowed for
320 * individual devices (e.g. 256 for SCSI-1)
321 */
322#define SCSI_DEFAULT_MAX_SECTORS 1024
323
324 /*
325 * True if this host adapter can make good use of linked commands.
326 * This will allow more than one command to be queued to a given
327 * unit on a given host. Set this to the maximum number of command
328 * blocks to be provided for each device. Set this to 1 for one
329 * command block per lun, 2 for two, etc. Do not set this to 0.
330 * You should make sure that the host adapter will do the right thing
331 * before you try setting this above 1.
332 */
333 short cmd_per_lun;
334
335 /*
336 * present contains counter indicating how many boards of this
337 * type were found when we did the scan.
338 */
339 unsigned char present;
340
341 /*
342 * true if this host adapter uses unchecked DMA onto an ISA bus.
343 */
344 unsigned unchecked_isa_dma:1;
345
346 /*
347 * true if this host adapter can make good use of clustering.
348 * I originally thought that if the tablesize was large that it
349 * was a waste of CPU cycles to prepare a cluster list, but
350 * it works out that the Buslogic is faster if you use a smaller
351 * number of segments (i.e. use clustering). I guess it is
352 * inefficient.
353 */
354 unsigned use_clustering:1;
355
356 /*
357 * True for emulated SCSI host adapters (e.g. ATAPI)
358 */
359 unsigned emulated:1;
360
361 /*
362 * True if the low-level driver performs its own reset-settle delays.
363 */
364 unsigned skip_settle_delay:1;
365
366 /*
367 * ordered write support
368 */
369 unsigned ordered_flush:1;
370 unsigned ordered_tag:1;
371
372 /*
373 * Countdown for host blocking with no commands outstanding
374 */
375 unsigned int max_host_blocked;
376
377 /*
378 * Default value for the blocking. If the queue is empty,
379 * host_blocked counts down in the request_fn until it restarts
380 * host operations as zero is reached.
381 *
382 * FIXME: This should probably be a value in the template
383 */
384#define SCSI_DEFAULT_HOST_BLOCKED 7
385
386 /*
387 * Pointer to the sysfs class properties for this host, NULL terminated.
388 */
389 struct class_device_attribute **shost_attrs;
390
391 /*
392 * Pointer to the SCSI device properties for this host, NULL terminated.
393 */
394 struct device_attribute **sdev_attrs;
395
396 /*
397 * List of hosts per template.
398 *
399 * This is only for use by scsi_module.c for legacy templates.
400 * For these access to it is synchronized implicitly by
401 * module_init/module_exit.
402 */
403 struct list_head legacy_hosts;
404};
405
406/*
407 * shost states
408 */
409enum {
410 SHOST_ADD,
411 SHOST_DEL,
412 SHOST_CANCEL,
413 SHOST_RECOVERY,
414};
415
416struct Scsi_Host {
417 /*
418 * __devices is protected by the host_lock, but you should
419 * usually use scsi_device_lookup / shost_for_each_device
420 * to access it and don't care about locking yourself.
421 * In the rare case of beeing in irq context you can use
422 * their __ prefixed variants with the lock held. NEVER
423 * access this list directly from a driver.
424 */
425 struct list_head __devices;
426 struct list_head __targets;
427
428 struct scsi_host_cmd_pool *cmd_pool;
429 spinlock_t free_list_lock;
430 struct list_head free_list; /* backup store of cmd structs */
431 struct list_head starved_list;
432
433 spinlock_t default_lock;
434 spinlock_t *host_lock;
435
436 struct semaphore scan_mutex;/* serialize scanning activity */
437
438 struct list_head eh_cmd_q;
439 struct task_struct * ehandler; /* Error recovery thread. */
440 struct semaphore * eh_wait; /* The error recovery thread waits
441 on this. */
442 struct completion * eh_notify; /* wait for eh to begin or end */
443 struct semaphore * eh_action; /* Wait for specific actions on the
444 host. */
445 unsigned int eh_active:1; /* Indicates the eh thread is awake and active if
446 this is true. */
447 unsigned int eh_kill:1; /* set when killing the eh thread */
448 wait_queue_head_t host_wait;
449 struct scsi_host_template *hostt;
450 struct scsi_transport_template *transportt;
451 volatile unsigned short host_busy; /* commands actually active on low-level */
452 volatile unsigned short host_failed; /* commands that failed. */
453
454 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
455 int resetting; /* if set, it means that last_reset is a valid value */
456 unsigned long last_reset;
457
458 /*
459 * These three parameters can be used to allow for wide scsi,
460 * and for host adapters that support multiple busses
461 * The first two should be set to 1 more than the actual max id
462 * or lun (i.e. 8 for normal systems).
463 */
464 unsigned int max_id;
465 unsigned int max_lun;
466 unsigned int max_channel;
467
468 /*
469 * This is a unique identifier that must be assigned so that we
470 * have some way of identifying each detected host adapter properly
471 * and uniquely. For hosts that do not support more than one card
472 * in the system at one time, this does not need to be set. It is
473 * initialized to 0 in scsi_register.
474 */
475 unsigned int unique_id;
476
477 /*
478 * The maximum length of SCSI commands that this host can accept.
479 * Probably 12 for most host adapters, but could be 16 for others.
480 * For drivers that don't set this field, a value of 12 is
481 * assumed. I am leaving this as a number rather than a bit
482 * because you never know what subsequent SCSI standards might do
483 * (i.e. could there be a 20 byte or a 24-byte command a few years
484 * down the road?).
485 */
486 unsigned char max_cmd_len;
487
488 int this_id;
489 int can_queue;
490 short cmd_per_lun;
491 short unsigned int sg_tablesize;
492 short unsigned int max_sectors;
493 unsigned long dma_boundary;
494 /*
495 * Used to assign serial numbers to the cmds.
496 * Protected by the host lock.
497 */
498 unsigned long cmd_serial_number, cmd_pid;
499
500 unsigned unchecked_isa_dma:1;
501 unsigned use_clustering:1;
502 unsigned use_blk_tcq:1;
503
504 /*
505 * Host has requested that no further requests come through for the
506 * time being.
507 */
508 unsigned host_self_blocked:1;
509
510 /*
511 * Host uses correct SCSI ordering not PC ordering. The bit is
512 * set for the minority of drivers whose authors actually read
513 * the spec ;)
514 */
515 unsigned reverse_ordering:1;
516
517 /*
518 * ordered write support
519 */
520 unsigned ordered_flush:1;
521 unsigned ordered_tag:1;
522
523 /*
524 * Optional work queue to be utilized by the transport
525 */
526 char work_q_name[KOBJ_NAME_LEN];
527 struct workqueue_struct *work_q;
528
529 /*
530 * Host has rejected a command because it was busy.
531 */
532 unsigned int host_blocked;
533
534 /*
535 * Value host_blocked counts down from
536 */
537 unsigned int max_host_blocked;
538
539 /* legacy crap */
540 unsigned long base;
541 unsigned long io_port;
542 unsigned char n_io_port;
543 unsigned char dma_channel;
544 unsigned int irq;
545
546
547 unsigned long shost_state;
548
549 /* ldm bits */
550 struct device shost_gendev;
551 struct class_device shost_classdev;
552
553 /*
554 * List of hosts per template.
555 *
556 * This is only for use by scsi_module.c for legacy templates.
557 * For these access to it is synchronized implicitly by
558 * module_init/module_exit.
559 */
560 struct list_head sht_legacy_list;
561
562 /*
563 * Points to the transport data (if any) which is allocated
564 * separately
565 */
566 void *shost_data;
567
568 /*
569 * We should ensure that this is aligned, both for better performance
570 * and also because some compilers (m68k) don't automatically force
571 * alignment to a long boundary.
572 */
573 unsigned long hostdata[0] /* Used for storage of host specific stuff */
574 __attribute__ ((aligned (sizeof(unsigned long))));
575};
576
577#define class_to_shost(d) \
578 container_of(d, struct Scsi_Host, shost_classdev)
579
580int scsi_is_host_device(const struct device *);
581
582static inline struct Scsi_Host *dev_to_shost(struct device *dev)
583{
584 while (!scsi_is_host_device(dev)) {
585 if (!dev->parent)
586 return NULL;
587 dev = dev->parent;
588 }
589 return container_of(dev, struct Scsi_Host, shost_gendev);
590}
591
592extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
593extern void scsi_flush_work(struct Scsi_Host *);
594
595extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
596extern int __must_check scsi_add_host(struct Scsi_Host *, struct device *);
597extern void scsi_scan_host(struct Scsi_Host *);
598extern void scsi_scan_single_target(struct Scsi_Host *, unsigned int,
599 unsigned int);
600extern void scsi_rescan_device(struct device *);
601extern void scsi_remove_host(struct Scsi_Host *);
602extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
603extern void scsi_host_put(struct Scsi_Host *t);
604extern struct Scsi_Host *scsi_host_lookup(unsigned short);
605
606extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
607
608static inline void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock)
609{
610 shost->host_lock = lock;
611}
612
613static inline void scsi_set_device(struct Scsi_Host *shost,
614 struct device *dev)
615{
616 shost->shost_gendev.parent = dev;
617}
618
619static inline struct device *scsi_get_device(struct Scsi_Host *shost)
620{
621 return shost->shost_gendev.parent;
622}
623
624extern void scsi_unblock_requests(struct Scsi_Host *);
625extern void scsi_block_requests(struct Scsi_Host *);
626
627struct class_container;
628/*
629 * These two functions are used to allocate and free a pseudo device
630 * which will connect to the host adapter itself rather than any
631 * physical device. You must deallocate when you are done with the
632 * thing. This physical pseudo-device isn't real and won't be available
633 * from any high-level drivers.
634 */
635extern void scsi_free_host_dev(struct scsi_device *);
636extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
637
638/* legacy interfaces */
639extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
640extern void scsi_unregister(struct Scsi_Host *);
641
642#endif /* _SCSI_SCSI_HOST_H */