scsi_tcq.h 4.1 KB

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