scsi_tcq.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #define MSG_SIMPLE_TAG 0x20
  7. #define MSG_HEAD_TAG 0x21
  8. #define MSG_ORDERED_TAG 0x22
  9. #define SCSI_NO_TAG (-1) /* identify no tag in use */
  10. /**
  11. * scsi_get_tag_type - get the type of tag the device supports
  12. * @sdev: the scsi device
  13. *
  14. * Notes:
  15. * If the drive only supports simple tags, returns MSG_SIMPLE_TAG
  16. * if it supports all tag types, returns MSG_ORDERED_TAG.
  17. */
  18. static inline int scsi_get_tag_type(struct scsi_device *sdev)
  19. {
  20. if (!sdev->tagged_supported)
  21. return 0;
  22. if (sdev->ordered_tags)
  23. return MSG_ORDERED_TAG;
  24. if (sdev->simple_tags)
  25. return MSG_SIMPLE_TAG;
  26. return 0;
  27. }
  28. static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)
  29. {
  30. switch (tag) {
  31. case MSG_ORDERED_TAG:
  32. sdev->ordered_tags = 1;
  33. /* fall through */
  34. case MSG_SIMPLE_TAG:
  35. sdev->simple_tags = 1;
  36. break;
  37. case 0:
  38. /* fall through */
  39. default:
  40. sdev->ordered_tags = 0;
  41. sdev->simple_tags = 0;
  42. break;
  43. }
  44. }
  45. /**
  46. * scsi_activate_tcq - turn on tag command queueing
  47. * @SDpnt: device to turn on TCQ for
  48. * @depth: queue depth
  49. *
  50. * Notes:
  51. * Eventually, I hope depth would be the maximum depth
  52. * the device could cope with and the real queue depth
  53. * would be adjustable from 0 to depth.
  54. **/
  55. static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
  56. {
  57. if (!sdev->tagged_supported)
  58. return;
  59. if (!blk_queue_tagged(sdev->request_queue))
  60. blk_queue_init_tags(sdev->request_queue, depth, NULL);
  61. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
  62. }
  63. /**
  64. * scsi_deactivate_tcq - turn off tag command queueing
  65. * @SDpnt: device to turn off TCQ for
  66. **/
  67. static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
  68. {
  69. if (blk_queue_tagged(sdev->request_queue))
  70. blk_queue_free_tags(sdev->request_queue);
  71. scsi_adjust_queue_depth(sdev, 0, depth);
  72. }
  73. /**
  74. * scsi_populate_tag_msg - place a tag message in a buffer
  75. * @SCpnt: pointer to the Scsi_Cmnd for the tag
  76. * @msg: pointer to the area to place the tag
  77. *
  78. * Notes:
  79. * designed to create the correct type of tag message for the
  80. * particular request. Returns the size of the tag message.
  81. * May return 0 if TCQ is disabled for this device.
  82. **/
  83. static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
  84. {
  85. struct request *req = cmd->request;
  86. struct scsi_device *sdev = cmd->device;
  87. if (blk_rq_tagged(req)) {
  88. if (sdev->ordered_tags && req->flags & REQ_HARDBARRIER)
  89. *msg++ = MSG_ORDERED_TAG;
  90. else
  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. #endif /* _SCSI_SCSI_TCQ_H */