scsi_host.h 28 KB

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