#ifndef _SCSI_SCSI_TCQ_H1#define _SCSI_SCSI_TCQ_H23#include <linux/blkdev.h>4#include <scsi/scsi_cmnd.h>5#include <scsi/scsi_device.h>6#include <scsi/scsi_host.h>78#define MSG_SIMPLE_TAG 0x209#define MSG_HEAD_TAG 0x2110#define MSG_ORDERED_TAG 0x2211#define MSG_ACA_TAG 0x24 /* unsupported */1213#define SCSI_NO_TAG (-1) /* identify no tag in use */141516#ifdef CONFIG_BLOCK1718/**19* scsi_get_tag_type - get the type of tag the device supports20* @sdev: the scsi device21*22* Notes:23* If the drive only supports simple tags, returns MSG_SIMPLE_TAG24* if it supports all tag types, returns MSG_ORDERED_TAG.25*/26static inline int scsi_get_tag_type(struct scsi_device *sdev)27{28if (!sdev->tagged_supported)29return 0;30if (sdev->ordered_tags)31return MSG_ORDERED_TAG;32if (sdev->simple_tags)33return MSG_SIMPLE_TAG;34return 0;35}3637static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)38{39switch (tag) {40case MSG_ORDERED_TAG:41sdev->ordered_tags = 1;42/* fall through */43case MSG_SIMPLE_TAG:44sdev->simple_tags = 1;45break;46case 0:47/* fall through */48default:49sdev->ordered_tags = 0;50sdev->simple_tags = 0;51break;52}53}54/**55* scsi_activate_tcq - turn on tag command queueing56* @SDpnt: device to turn on TCQ for57* @depth: queue depth58*59* Notes:60* Eventually, I hope depth would be the maximum depth61* the device could cope with and the real queue depth62* would be adjustable from 0 to depth.63**/64static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)65{66if (!sdev->tagged_supported)67return;6869if (!blk_queue_tagged(sdev->request_queue))70blk_queue_init_tags(sdev->request_queue, depth,71sdev->host->bqt);7273scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);74}7576/**77* scsi_deactivate_tcq - turn off tag command queueing78* @SDpnt: device to turn off TCQ for79**/80static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)81{82if (blk_queue_tagged(sdev->request_queue))83blk_queue_free_tags(sdev->request_queue);84scsi_adjust_queue_depth(sdev, 0, depth);85}8687/**88* scsi_populate_tag_msg - place a tag message in a buffer89* @SCpnt: pointer to the Scsi_Cmnd for the tag90* @msg: pointer to the area to place the tag91*92* Notes:93* designed to create the correct type of tag message for the94* particular request. Returns the size of the tag message.95* May return 0 if TCQ is disabled for this device.96**/97static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)98{99struct request *req = cmd->request;100101if (blk_rq_tagged(req)) {102*msg++ = MSG_SIMPLE_TAG;103*msg++ = req->tag;104return 2;105}106107return 0;108}109110/**111* scsi_find_tag - find a tagged command by device112* @SDpnt: pointer to the ScSI device113* @tag: the tag number114*115* Notes:116* Only works with tags allocated by the generic blk layer.117**/118static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)119{120121struct request *req;122123if (tag != SCSI_NO_TAG) {124req = blk_queue_find_tag(sdev->request_queue, tag);125return req ? (struct scsi_cmnd *)req->special : NULL;126}127128/* single command, look in space */129return sdev->current_cmnd;130}131132/**133* scsi_init_shared_tag_map - create a shared tag map134* @shost: the host to share the tag map among all devices135* @depth: the total depth of the map136*/137static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)138{139/*140* If the shared tag map isn't already initialized, do it now.141* This saves callers from having to check ->bqt when setting up142* devices on the shared host (for libata)143*/144if (!shost->bqt) {145shost->bqt = blk_init_tags(depth);146if (!shost->bqt)147return -ENOMEM;148}149150return 0;151}152153/**154* scsi_host_find_tag - find the tagged command by host155* @shost: pointer to scsi_host156* @tag: tag of the scsi_cmnd157*158* Notes:159* Only works with tags allocated by the generic blk layer.160**/161static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,162int tag)163{164struct request *req;165166if (tag != SCSI_NO_TAG) {167req = blk_map_queue_find_tag(shost->bqt, tag);168return req ? (struct scsi_cmnd *)req->special : NULL;169}170return NULL;171}172173#endif /* CONFIG_BLOCK */174#endif /* _SCSI_SCSI_TCQ_H */175176177