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