Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-leds
[powerpc.git] / drivers / scsi / scsi_transport_srp.c
index dcb3d2a..44a340b 100644 (file)
@@ -30,6 +30,7 @@
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_transport.h>
 #include <scsi/scsi_transport_srp.h>
+#include "scsi_transport_srp_internal.h"
 
 struct srp_host_attrs {
        atomic_t next_port_id;
@@ -37,7 +38,7 @@ struct srp_host_attrs {
 #define to_srp_host_attrs(host)        ((struct srp_host_attrs *)(host)->shost_data)
 
 #define SRP_HOST_ATTRS 0
-#define SRP_RPORT_ATTRS 3
+#define SRP_RPORT_ATTRS 2
 
 struct srp_internal {
        struct scsi_transport_template t;
@@ -107,6 +108,31 @@ show_srp_rport_id(struct class_device *cdev, char *buf)
 
 static CLASS_DEVICE_ATTR(port_id, S_IRUGO, show_srp_rport_id, NULL);
 
+static const struct {
+       u32 value;
+       char *name;
+} srp_rport_role_names[] = {
+       {SRP_RPORT_ROLE_INITIATOR, "SRP Initiator"},
+       {SRP_RPORT_ROLE_TARGET, "SRP Target"},
+};
+
+static ssize_t
+show_srp_rport_roles(struct class_device *cdev, char *buf)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(cdev);
+       int i;
+       char *name = NULL;
+
+       for (i = 0; i < ARRAY_SIZE(srp_rport_role_names); i++)
+               if (srp_rport_role_names[i].value == rport->roles) {
+                       name = srp_rport_role_names[i].name;
+                       break;
+               }
+       return sprintf(buf, "%s\n", name ? : "unknown");
+}
+
+static CLASS_DEVICE_ATTR(roles, S_IRUGO, show_srp_rport_roles, NULL);
+
 static void srp_rport_release(struct device *dev)
 {
        struct srp_rport *rport = dev_to_rport(dev);
@@ -182,6 +208,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
        rport->dev.release = srp_rport_release;
 
        memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
+       rport->roles = ids->roles;
 
        id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
        sprintf(rport->dev.bus_id, "port-%d:%d", shost->host_no, id);
@@ -195,6 +222,18 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
                return ERR_PTR(ret);
        }
 
+       if (shost->active_mode & MODE_TARGET &&
+           ids->roles == SRP_RPORT_ROLE_INITIATOR) {
+               ret = srp_tgt_it_nexus_create(shost, (unsigned long)rport,
+                                             rport->port_id);
+               if (ret) {
+                       device_del(&rport->dev);
+                       transport_destroy_device(&rport->dev);
+                       put_device(&rport->dev);
+                       return ERR_PTR(ret);
+               }
+       }
+
        transport_add_device(&rport->dev);
        transport_configure_device(&rport->dev);
 
@@ -211,6 +250,11 @@ EXPORT_SYMBOL_GPL(srp_rport_add);
 void srp_rport_del(struct srp_rport *rport)
 {
        struct device *dev = &rport->dev;
+       struct Scsi_Host *shost = dev_to_shost(dev->parent);
+
+       if (shost->active_mode & MODE_TARGET &&
+           rport->roles == SRP_RPORT_ROLE_INITIATOR)
+               srp_tgt_it_nexus_destroy(shost, (unsigned long)rport);
 
        transport_remove_device(dev);
        device_del(dev);
@@ -238,6 +282,19 @@ void srp_remove_host(struct Scsi_Host *shost)
 }
 EXPORT_SYMBOL_GPL(srp_remove_host);
 
+static int srp_tsk_mgmt_response(struct Scsi_Host *shost, u64 nexus, u64 tm_id,
+                                int result)
+{
+       struct srp_internal *i = to_srp_internal(shost->transportt);
+       return i->f->tsk_mgmt_response(shost, nexus, tm_id, result);
+}
+
+static int srp_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result)
+{
+       struct srp_internal *i = to_srp_internal(shost->transportt);
+       return i->f->it_nexus_response(shost, nexus, result);
+}
+
 /**
  * srp_attach_transport  --  instantiate SRP transport template
  * @ft:                SRP transport class function template
@@ -252,6 +309,9 @@ srp_attach_transport(struct srp_function_template *ft)
        if (!i)
                return NULL;
 
+       i->t.tsk_mgmt_response = srp_tsk_mgmt_response;
+       i->t.it_nexus_response = srp_it_nexus_response;
+
        i->t.host_size = sizeof(struct srp_host_attrs);
        i->t.host_attrs.ac.attrs = &i->host_attrs[0];
        i->t.host_attrs.ac.class = &srp_host_class.class;
@@ -266,6 +326,7 @@ srp_attach_transport(struct srp_function_template *ft)
 
        count = 0;
        SETUP_RPORT_ATTRIBUTE_RD(port_id);
+       SETUP_RPORT_ATTRIBUTE_RD(roles);
        i->rport_attrs[count] = NULL;
 
        i->f = ft;