scsi_tcq.h 4.1 KB

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