scsi_tcq.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SCSI_SCSI_TCQ_H
  3. #define _SCSI_SCSI_TCQ_H
  4. #include <linux/blkdev.h>
  5. #include <scsi/scsi_cmnd.h>
  6. #include <scsi/scsi_device.h>
  7. #include <scsi/scsi_host.h>
  8. #define SCSI_NO_TAG (-1) /* identify no tag in use */
  9. #ifdef CONFIG_BLOCK
  10. /**
  11. * scsi_host_find_tag - find the tagged command by host
  12. * @shost: pointer to scsi_host
  13. * @tag: tag
  14. *
  15. * Note: for devices using multiple hardware queues tag must have been
  16. * generated by blk_mq_unique_tag().
  17. **/
  18. static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
  19. int tag)
  20. {
  21. struct request *req = NULL;
  22. if (tag == SCSI_NO_TAG)
  23. return NULL;
  24. if (shost_use_blk_mq(shost)) {
  25. u16 hwq = blk_mq_unique_tag_to_hwq(tag);
  26. if (hwq < shost->tag_set.nr_hw_queues) {
  27. req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq],
  28. blk_mq_unique_tag_to_tag(tag));
  29. }
  30. } else {
  31. req = blk_map_queue_find_tag(shost->bqt, tag);
  32. }
  33. if (!req)
  34. return NULL;
  35. return blk_mq_rq_to_pdu(req);
  36. }
  37. #endif /* CONFIG_BLOCK */
  38. #endif /* _SCSI_SCSI_TCQ_H */