scsi_host.h 28 KB

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