scsi_host.h 28 KB

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