scsi_host.h 27 KB

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