scsi_host.h 24 KB

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