scsi_host.h 27 KB

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