23 #include <linux/hash.h>
24 #include <linux/module.h>
26 #include <linux/slab.h>
27 #include <scsi/scsi.h>
55 #define TGT_HASH_ORDER 4
56 #define cmd_hashfn(tag) hash_long((unsigned long) (tag), TGT_HASH_ORDER)
114 rq->cmd_type = REQ_TYPE_SPECIAL;
115 rq->cmd_flags |= REQ_TYPE_BLOCK_PC;
116 rq->end_io_data = tcmd;
156 spin_unlock_irqrestore(q->queue_lock, flags);
174 static void scsi_unmap_user_pages(
struct scsi_tgt_cmd *tcmd)
187 scsi_unmap_user_pages(tcmd);
230 queuedata = kzalloc(
sizeof(*queuedata),
GFP_KERNEL);
236 q->queuedata = queuedata;
253 INIT_LIST_HEAD(&queuedata->
cmd_hash[i]);
284 while (!list_empty(&
cmds)) {
287 cmd = tcmd->
rq->special;
289 shost->
hostt->eh_abort_handler(cmd);
290 scsi_tgt_cmd_destroy(&tcmd->
work);
314 init_scsi_tgt_cmd(cmd->
request, tcmd, itn_id, tag);
317 cmd_hashlist_del(cmd);
327 static void scsi_tgt_cmd_done(
struct scsi_cmnd *cmd)
340 static int scsi_tgt_transfer_response(
struct scsi_cmnd *cmd)
347 err = shost->
hostt->transfer_response(cmd, scsi_tgt_cmd_done);
358 unsigned long uaddr,
unsigned int len,
int rw)
364 dprintk(
"%lx %u\n", uaddr, len);
376 eprintk(
"Could not handle request of size %u.\n", len);
390 cmd->
sdb.length = blk_rq_bytes(rq);
395 scsi_unmap_user_pages(tcmd);
399 static int scsi_tgt_copy_sense(
struct scsi_cmnd *cmd,
unsigned long uaddr,
417 err = shost->
hostt->eh_abort_handler(cmd);
419 eprintk(
"fail to abort %p\n", cmd);
421 tcmd = cmd->
request->end_io_data;
422 scsi_tgt_cmd_destroy(&tcmd->
work);
437 if (tcmd->
tag == tag) {
458 dprintk(
"%d %llu %d %u %lx %u\n", host_no, (
unsigned long long) tag,
459 result, len, uaddr, rw);
476 (
unsigned long long) tag);
482 dprintk(
"cmd %p scb %x result %d len %d bufflen %u %u %x\n",
483 cmd, cmd->
cmnd[0], result, len, scsi_bufflen(cmd),
484 rq_data_dir(rq), cmd->
cmnd[0]);
487 scsi_tgt_abort_cmd(shost, cmd);
494 tcmd = cmd->
request->end_io_data;
498 scsi_tgt_copy_sense(cmd, sense_uaddr, sense_len);
501 err = scsi_map_user_pages(rq->end_io_data, cmd, uaddr, len, rw);
511 eprintk(
"cmd %p ret %d uaddr %lx len %d rw %d\n",
512 cmd, err, uaddr, len, rw);
524 err = scsi_tgt_transfer_response(cmd);
538 function, tag, scsilun, data);
540 eprintk(
"The task management request lost!\n");
550 dprintk(
"%d %d %llx\n", host_no, result, (
unsigned long long) mid);
563 err = shost->
transportt->tsk_mgmt_response(shost, itn_id, mid, result);
578 eprintk(
"The i_t_neuxs request lost, %d %llx!\n",
579 shost->
host_no, (
unsigned long long)itn_id);
592 eprintk(
"The i_t_neuxs request lost, %d %llx!\n",
593 shost->
host_no, (
unsigned long long)itn_id);
603 dprintk(
"%d %d%llx\n", host_no, result, (
unsigned long long)itn_id);
616 err = shost->
transportt->it_nexus_response(shost, itn_id, result);
622 static int __init scsi_tgt_init(
void)
627 if (!scsi_tgt_cmd_cache)
649 static void __exit scsi_tgt_exit(
void)