scsi_tcq.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 MSG_SIMPLE_TAG 0x20
  8. #define MSG_HEAD_TAG 0x21
  9. #define MSG_ORDERED_TAG 0x22
  10. #define SCSI_NO_TAG (-1) /* identify no tag in use */
  11. /**
  12. * scsi_get_tag_type - get the type of tag the device supports
  13. * @sdev: the scsi device
  14. *
  15. * Notes:
  16. * If the drive only supports simple tags, returns MSG_SIMPLE_TAG
  17. * if it supports all tag types, returns MSG_ORDERED_TAG.
  18. */
  19. static inline int scsi_get_tag_type(struct scsi_device *sdev)
  20. {
  21. if (!sdev->tagged_supported)
  22. return 0;
  23. if (sdev->ordered_tags)
  24. return MSG_ORDERED_TAG;
  25. if (sdev->simple_tags)
  26. return MSG_SIMPLE_TAG;
  27. return 0;
  28. }
  29. static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)
  30. {
  31. switch (tag) {
  32. case MSG_ORDERED_TAG:
  33. sdev->ordered_tags = 1;
  34. /* fall through */
  35. case MSG_SIMPLE_TAG:
  36. sdev->simple_tags = 1;
  37. break;
  38. case 0:
  39. /* fall through */
  40. default:
  41. sdev->ordered_tags = 0;
  42. sdev->simple_tags = 0;
  43. break;
  44. }
  45. }
  46. /**
  47. * scsi_activate_tcq - turn on tag command queueing
  48. * @SDpnt: device to turn on TCQ for
  49. * @depth: queue depth
  50. *
  51. * Notes:
  52. * Eventually, I hope depth would be the maximum depth
  53. * the device could cope with and the real queue depth
  54. * would be adjustable from 0 to depth.
  55. **/
  56. static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
  57. {
  58. if (!sdev->tagged_supported)
  59. return;
  60. if (!blk_queue_tagged(sdev->request_queue))
  61. blk_queue_init_tags(sdev->request_queue, depth,
  62. sdev->host->bqt);
  63. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
  64. }
  65. /**
  66. * scsi_deactivate_tcq - turn off tag command queueing
  67. * @SDpnt: device to turn off TCQ for
  68. **/
  69. static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
  70. {
  71. if (blk_queue_tagged(sdev->request_queue))
  72. blk_queue_free_tags(sdev->request_queue);
  73. scsi_adjust_queue_depth(sdev, 0, depth);
  74. }
  75. /**
  76. * scsi_populate_tag_msg - place a tag message in a buffer
  77. * @SCpnt: pointer to the Scsi_Cmnd for the tag
  78. * @msg: pointer to the area to place the tag
  79. *
  80. * Notes:
  81. * designed to create the correct type of tag message for the
  82. * particular request. Returns the size of the tag message.
  83. * May return 0 if TCQ is disabled for this device.
  84. **/
  85. static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
  86. {
  87. struct request *req = cmd->request;
  88. struct scsi_device *sdev = cmd->device;
  89. if (blk_rq_tagged(req)) {
  90. if (sdev->ordered_tags && req->flags & REQ_HARDBARRIER)
  91. *msg++ = MSG_ORDERED_TAG;
  92. else
  93. *msg++ = MSG_SIMPLE_TAG;
  94. *msg++ = req->tag;
  95. return 2;
  96. }
  97. return 0;
  98. }
  99. /**
  100. * scsi_find_tag - find a tagged command by device
  101. * @SDpnt: pointer to the ScSI device
  102. * @tag: the tag number
  103. *
  104. * Notes:
  105. * Only works with tags allocated by the generic blk layer.
  106. **/
  107. static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
  108. {
  109. struct request *req;
  110. if (tag != SCSI_NO_TAG) {
  111. req = blk_queue_find_tag(sdev->request_queue, tag);
  112. return req ? (struct scsi_cmnd *)req->special : NULL;
  113. }
  114. /* single command, look in space */
  115. return sdev->current_cmnd;
  116. }
  117. /**
  118. * scsi_init_shared_tag_map - create a shared tag map
  119. * @shost: the host to share the tag map among all devices
  120. * @depth: the total depth of the map
  121. */
  122. static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
  123. {
  124. shost->bqt = blk_init_tags(depth);
  125. return shost->bqt ? 0 : -ENOMEM;
  126. }
  127. #endif /* _SCSI_SCSI_TCQ_H */