scsi_host.h 28 KB

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