scsi_host.h 28 KB

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