scsi_host.h 27 KB

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