scsi_tcq.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _SCSI_SCSI_TCQ_H
  2. #define _SCSI_SCSI_TCQ_H
  3. #include <linux/blkdev.h>
  4. #include <scsi/scsi_cmnd.h>
  5. #include <scsi/scsi_device.h>
  6. #include <scsi/scsi_host.h>
  7. #define SCSI_NO_TAG (-1) /* identify no tag in use */
  8. #ifdef CONFIG_BLOCK
  9. static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost,
  10. int unique_tag)
  11. {
  12. u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
  13. struct request *req = NULL;
  14. if (hwq < shost->tag_set.nr_hw_queues)
  15. req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq],
  16. blk_mq_unique_tag_to_tag(unique_tag));
  17. return req ? (struct scsi_cmnd *)req->special : NULL;
  18. }
  19. /**
  20. * scsi_find_tag - find a tagged command by device
  21. * @SDpnt: pointer to the ScSI device
  22. * @tag: tag generated by blk_mq_unique_tag()
  23. *
  24. * Notes:
  25. * Only works with tags allocated by the generic blk layer.
  26. **/
  27. static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
  28. {
  29. struct request *req;
  30. if (tag != SCSI_NO_TAG) {
  31. if (shost_use_blk_mq(sdev->host))
  32. return scsi_mq_find_tag(sdev->host, tag);
  33. req = blk_queue_find_tag(sdev->request_queue, tag);
  34. return req ? (struct scsi_cmnd *)req->special : NULL;
  35. }
  36. /* single command, look in space */
  37. return sdev->current_cmnd;
  38. }
  39. /**
  40. * scsi_init_shared_tag_map - create a shared tag map
  41. * @shost: the host to share the tag map among all devices
  42. * @depth: the total depth of the map
  43. */
  44. static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
  45. {
  46. /*
  47. * We always have a shared tag map around when using blk-mq.
  48. */
  49. if (shost_use_blk_mq(shost))
  50. return 0;
  51. /*
  52. * If the shared tag map isn't already initialized, do it now.
  53. * This saves callers from having to check ->bqt when setting up
  54. * devices on the shared host (for libata)
  55. */
  56. if (!shost->bqt) {
  57. shost->bqt = blk_init_tags(depth,
  58. shost->hostt->tag_alloc_policy);
  59. if (!shost->bqt)
  60. return -ENOMEM;
  61. }
  62. return 0;
  63. }
  64. /**
  65. * scsi_host_find_tag - find the tagged command by host
  66. * @shost: pointer to scsi_host
  67. * @tag: tag generated by blk_mq_unique_tag()
  68. *
  69. * Notes:
  70. * Only works with tags allocated by the generic blk layer.
  71. **/
  72. static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
  73. int tag)
  74. {
  75. struct request *req;
  76. if (tag != SCSI_NO_TAG) {
  77. if (shost_use_blk_mq(shost))
  78. return scsi_mq_find_tag(shost, tag);
  79. req = blk_map_queue_find_tag(shost->bqt, tag);
  80. return req ? (struct scsi_cmnd *)req->special : NULL;
  81. }
  82. return NULL;
  83. }
  84. #endif /* CONFIG_BLOCK */
  85. #endif /* _SCSI_SCSI_TCQ_H */