scsi_host.h 23 KB

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