aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ibmvscsi/ibmvstgt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/ibmvscsi/ibmvstgt.c')
-rw-r--r--drivers/scsi/ibmvscsi/ibmvstgt.c61
1 files changed, 54 insertions, 7 deletions
diff --git a/drivers/scsi/ibmvscsi/ibmvstgt.c b/drivers/scsi/ibmvscsi/ibmvstgt.c
index 8ba7dd09d01d..82bcab688b44 100644
--- a/drivers/scsi/ibmvscsi/ibmvstgt.c
+++ b/drivers/scsi/ibmvscsi/ibmvstgt.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <scsi/scsi.h> 26#include <scsi/scsi.h>
27#include <scsi/scsi_host.h> 27#include <scsi/scsi_host.h>
28#include <scsi/scsi_transport_srp.h>
28#include <scsi/scsi_tgt.h> 29#include <scsi/scsi_tgt.h>
29#include <scsi/libsrp.h> 30#include <scsi/libsrp.h>
30#include <asm/hvcall.h> 31#include <asm/hvcall.h>
@@ -68,9 +69,12 @@ struct vio_port {
68 unsigned long liobn; 69 unsigned long liobn;
69 unsigned long riobn; 70 unsigned long riobn;
70 struct srp_target *target; 71 struct srp_target *target;
72
73 struct srp_rport *rport;
71}; 74};
72 75
73static struct workqueue_struct *vtgtd; 76static struct workqueue_struct *vtgtd;
77static struct scsi_transport_template *ibmvstgt_transport_template;
74 78
75/* 79/*
76 * These are fixed for the system and come from the Open Firmware device tree. 80 * These are fixed for the system and come from the Open Firmware device tree.
@@ -188,6 +192,7 @@ static int send_rsp(struct iu_entry *iue, struct scsi_cmnd *sc,
188static void handle_cmd_queue(struct srp_target *target) 192static void handle_cmd_queue(struct srp_target *target)
189{ 193{
190 struct Scsi_Host *shost = target->shost; 194 struct Scsi_Host *shost = target->shost;
195 struct srp_rport *rport = target_to_port(target)->rport;
191 struct iu_entry *iue; 196 struct iu_entry *iue;
192 struct srp_cmd *cmd; 197 struct srp_cmd *cmd;
193 unsigned long flags; 198 unsigned long flags;
@@ -200,7 +205,8 @@ retry:
200 if (!test_and_set_bit(V_FLYING, &iue->flags)) { 205 if (!test_and_set_bit(V_FLYING, &iue->flags)) {
201 spin_unlock_irqrestore(&target->lock, flags); 206 spin_unlock_irqrestore(&target->lock, flags);
202 cmd = iue->sbuf->buf; 207 cmd = iue->sbuf->buf;
203 err = srp_cmd_queue(shost, cmd, iue, 0); 208 err = srp_cmd_queue(shost, cmd, iue,
209 (unsigned long)rport, 0);
204 if (err) { 210 if (err) {
205 eprintk("cannot queue cmd %p %d\n", cmd, err); 211 eprintk("cannot queue cmd %p %d\n", cmd, err);
206 srp_iu_put(iue); 212 srp_iu_put(iue);
@@ -359,6 +365,16 @@ static void process_login(struct iu_entry *iue)
359 union viosrp_iu *iu = vio_iu(iue); 365 union viosrp_iu *iu = vio_iu(iue);
360 struct srp_login_rsp *rsp = &iu->srp.login_rsp; 366 struct srp_login_rsp *rsp = &iu->srp.login_rsp;
361 uint64_t tag = iu->srp.rsp.tag; 367 uint64_t tag = iu->srp.rsp.tag;
368 struct Scsi_Host *shost = iue->target->shost;
369 struct srp_target *target = host_to_srp_target(shost);
370 struct vio_port *vport = target_to_port(target);
371 struct srp_rport_identifiers ids;
372
373 memset(&ids, 0, sizeof(ids));
374 sprintf(ids.port_id, "%x", vport->dma_dev->unit_address);
375 ids.roles = SRP_RPORT_ROLE_INITIATOR;
376 if (!vport->rport)
377 vport->rport = srp_rport_add(shost, &ids);
362 378
363 /* TODO handle case that requested size is wrong and 379 /* TODO handle case that requested size is wrong and
364 * buffer format is wrong 380 * buffer format is wrong
@@ -412,7 +428,9 @@ static int process_tsk_mgmt(struct iu_entry *iue)
412 fn = 0; 428 fn = 0;
413 } 429 }
414 if (fn) 430 if (fn)
415 scsi_tgt_tsk_mgmt_request(iue->target->shost, fn, 431 scsi_tgt_tsk_mgmt_request(iue->target->shost,
432 (unsigned long)iue->target->shost,
433 fn,
416 iu->srp.tsk_mgmt.task_tag, 434 iu->srp.tsk_mgmt.task_tag,
417 (struct scsi_lun *) &iu->srp.tsk_mgmt.lun, 435 (struct scsi_lun *) &iu->srp.tsk_mgmt.lun,
418 iue); 436 iue);
@@ -721,7 +739,8 @@ static int ibmvstgt_eh_abort_handler(struct scsi_cmnd *sc)
721 return 0; 739 return 0;
722} 740}
723 741
724static int ibmvstgt_tsk_mgmt_response(u64 mid, int result) 742static int ibmvstgt_tsk_mgmt_response(struct Scsi_Host *shost,
743 u64 itn_id, u64 mid, int result)
725{ 744{
726 struct iu_entry *iue = (struct iu_entry *) ((void *) mid); 745 struct iu_entry *iue = (struct iu_entry *) ((void *) mid);
727 union viosrp_iu *iu = vio_iu(iue); 746 union viosrp_iu *iu = vio_iu(iue);
@@ -747,6 +766,20 @@ static int ibmvstgt_tsk_mgmt_response(u64 mid, int result)
747 return 0; 766 return 0;
748} 767}
749 768
769static int ibmvstgt_it_nexus_response(struct Scsi_Host *shost, u64 itn_id,
770 int result)
771{
772 struct srp_target *target = host_to_srp_target(shost);
773 struct vio_port *vport = target_to_port(target);
774
775 if (result) {
776 eprintk("%p %d\n", shost, result);
777 srp_rport_del(vport->rport);
778 vport->rport = NULL;
779 }
780 return 0;
781}
782
750static ssize_t system_id_show(struct class_device *cdev, char *buf) 783static ssize_t system_id_show(struct class_device *cdev, char *buf)
751{ 784{
752 return snprintf(buf, PAGE_SIZE, "%s\n", system_id); 785 return snprintf(buf, PAGE_SIZE, "%s\n", system_id);
@@ -785,9 +818,9 @@ static struct scsi_host_template ibmvstgt_sht = {
785 .max_sectors = DEFAULT_MAX_SECTORS, 818 .max_sectors = DEFAULT_MAX_SECTORS,
786 .transfer_response = ibmvstgt_cmd_done, 819 .transfer_response = ibmvstgt_cmd_done,
787 .eh_abort_handler = ibmvstgt_eh_abort_handler, 820 .eh_abort_handler = ibmvstgt_eh_abort_handler,
788 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
789 .shost_attrs = ibmvstgt_attrs, 821 .shost_attrs = ibmvstgt_attrs,
790 .proc_name = TGT_NAME, 822 .proc_name = TGT_NAME,
823 .supported_mode = MODE_TARGET,
791}; 824};
792 825
793static int ibmvstgt_probe(struct vio_dev *dev, const struct vio_device_id *id) 826static int ibmvstgt_probe(struct vio_dev *dev, const struct vio_device_id *id)
@@ -804,6 +837,7 @@ static int ibmvstgt_probe(struct vio_dev *dev, const struct vio_device_id *id)
804 shost = scsi_host_alloc(&ibmvstgt_sht, sizeof(struct srp_target)); 837 shost = scsi_host_alloc(&ibmvstgt_sht, sizeof(struct srp_target));
805 if (!shost) 838 if (!shost)
806 goto free_vport; 839 goto free_vport;
840 shost->transportt = ibmvstgt_transport_template;
807 err = scsi_tgt_alloc_queue(shost); 841 err = scsi_tgt_alloc_queue(shost);
808 if (err) 842 if (err)
809 goto put_host; 843 goto put_host;
@@ -837,8 +871,8 @@ static int ibmvstgt_probe(struct vio_dev *dev, const struct vio_device_id *id)
837 err = scsi_add_host(shost, target->dev); 871 err = scsi_add_host(shost, target->dev);
838 if (err) 872 if (err)
839 goto destroy_queue; 873 goto destroy_queue;
840 return 0;
841 874
875 return 0;
842destroy_queue: 876destroy_queue:
843 crq_queue_destroy(target); 877 crq_queue_destroy(target);
844free_srp_target: 878free_srp_target:
@@ -857,6 +891,7 @@ static int ibmvstgt_remove(struct vio_dev *dev)
857 struct vio_port *vport = target->ldata; 891 struct vio_port *vport = target->ldata;
858 892
859 crq_queue_destroy(target); 893 crq_queue_destroy(target);
894 srp_remove_host(shost);
860 scsi_remove_host(shost); 895 scsi_remove_host(shost);
861 scsi_tgt_free_queue(shost); 896 scsi_tgt_free_queue(shost);
862 srp_target_free(target); 897 srp_target_free(target);
@@ -909,15 +944,25 @@ static int get_system_info(void)
909 return 0; 944 return 0;
910} 945}
911 946
947static struct srp_function_template ibmvstgt_transport_functions = {
948 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
949 .it_nexus_response = ibmvstgt_it_nexus_response,
950};
951
912static int ibmvstgt_init(void) 952static int ibmvstgt_init(void)
913{ 953{
914 int err = -ENOMEM; 954 int err = -ENOMEM;
915 955
916 printk("IBM eServer i/pSeries Virtual SCSI Target Driver\n"); 956 printk("IBM eServer i/pSeries Virtual SCSI Target Driver\n");
917 957
958 ibmvstgt_transport_template =
959 srp_attach_transport(&ibmvstgt_transport_functions);
960 if (!ibmvstgt_transport_template)
961 return err;
962
918 vtgtd = create_workqueue("ibmvtgtd"); 963 vtgtd = create_workqueue("ibmvtgtd");
919 if (!vtgtd) 964 if (!vtgtd)
920 return err; 965 goto release_transport;
921 966
922 err = get_system_info(); 967 err = get_system_info();
923 if (err) 968 if (err)
@@ -928,9 +973,10 @@ static int ibmvstgt_init(void)
928 goto destroy_wq; 973 goto destroy_wq;
929 974
930 return 0; 975 return 0;
931
932destroy_wq: 976destroy_wq:
933 destroy_workqueue(vtgtd); 977 destroy_workqueue(vtgtd);
978release_transport:
979 srp_release_transport(ibmvstgt_transport_template);
934 return err; 980 return err;
935} 981}
936 982
@@ -940,6 +986,7 @@ static void ibmvstgt_exit(void)
940 986
941 destroy_workqueue(vtgtd); 987 destroy_workqueue(vtgtd);
942 vio_unregister_driver(&ibmvstgt_driver); 988 vio_unregister_driver(&ibmvstgt_driver);
989 srp_release_transport(ibmvstgt_transport_template);
943} 990}
944 991
945MODULE_DESCRIPTION("IBM Virtual SCSI Target"); 992MODULE_DESCRIPTION("IBM Virtual SCSI Target");