]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/infiniband/ulp/srp/ib_srp.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6-omap-h63xx.git] / drivers / infiniband / ulp / srp / ib_srp.c
index f01ca182f226a5df9c1d21adf195458ca95325e6..bdb6f8517401d5950872c05e47aa64685e8287c6 100644 (file)
@@ -47,6 +47,7 @@
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_dbg.h>
 #include <scsi/srp.h>
+#include <scsi/scsi_transport_srp.h>
 
 #include <rdma/ib_cache.h>
 
@@ -75,21 +76,19 @@ module_param(topspin_workarounds, int, 0444);
 MODULE_PARM_DESC(topspin_workarounds,
                 "Enable workarounds for Topspin/Cisco SRP target bugs if != 0");
 
-static const u8 topspin_oui[3] = { 0x00, 0x05, 0xad };
-
 static int mellanox_workarounds = 1;
 
 module_param(mellanox_workarounds, int, 0444);
 MODULE_PARM_DESC(mellanox_workarounds,
                 "Enable workarounds for Mellanox SRP target bugs if != 0");
 
-static const u8 mellanox_oui[3] = { 0x00, 0x02, 0xc9 };
-
 static void srp_add_one(struct ib_device *device);
 static void srp_remove_one(struct ib_device *device);
 static void srp_completion(struct ib_cq *cq, void *target_ptr);
 static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event);
 
+static struct scsi_transport_template *ib_srp_transport_template;
+
 static struct ib_client srp_client = {
        .name   = "srp",
        .add    = srp_add_one,
@@ -108,6 +107,24 @@ static const char *srp_target_info(struct Scsi_Host *host)
        return host_to_target(host)->target_name;
 }
 
+static int srp_target_is_topspin(struct srp_target_port *target)
+{
+       static const u8 topspin_oui[3] = { 0x00, 0x05, 0xad };
+       static const u8 cisco_oui[3]   = { 0x00, 0x1b, 0x0d };
+
+       return topspin_workarounds &&
+               (!memcmp(&target->ioc_guid, topspin_oui, sizeof topspin_oui) ||
+                !memcmp(&target->ioc_guid, cisco_oui, sizeof cisco_oui));
+}
+
+static int srp_target_is_mellanox(struct srp_target_port *target)
+{
+       static const u8 mellanox_oui[3] = { 0x00, 0x02, 0xc9 };
+
+       return mellanox_workarounds &&
+               !memcmp(&target->ioc_guid, mellanox_oui, sizeof mellanox_oui);
+}
+
 static struct srp_iu *srp_alloc_iu(struct srp_host *host, size_t size,
                                   gfp_t gfp_mask,
                                   enum dma_data_direction direction)
@@ -271,6 +288,7 @@ static int srp_lookup_path(struct srp_target_port *target)
                                                   target->srp_host->dev->dev,
                                                   target->srp_host->port,
                                                   &target->path,
+                                                  IB_SA_PATH_REC_SERVICE_ID    |
                                                   IB_SA_PATH_REC_DGID          |
                                                   IB_SA_PATH_REC_SGID          |
                                                   IB_SA_PATH_REC_NUMB_PATH     |
@@ -360,7 +378,7 @@ static int srp_send_req(struct srp_target_port *target)
         * zero out the first 8 bytes of our initiator port ID and set
         * the second 8 bytes to the local node GUID.
         */
-       if (topspin_workarounds && !memcmp(&target->ioc_guid, topspin_oui, 3)) {
+       if (srp_target_is_topspin(target)) {
                printk(KERN_DEBUG PFX "Topspin/Cisco initiator port ID workaround "
                       "activated for target GUID %016llx\n",
                       (unsigned long long) be64_to_cpu(target->ioc_guid));
@@ -405,6 +423,7 @@ static void srp_remove_work(struct work_struct *work)
        list_del(&target->list);
        spin_unlock(&target->srp_host->target_lock);
 
+       srp_remove_host(target->scsi_host);
        scsi_remove_host(target->scsi_host);
        ib_destroy_cm_id(target->cm_id);
        srp_free_target_ib(target);
@@ -585,8 +604,8 @@ static int srp_map_fmr(struct srp_target_port *target, struct scatterlist *scat,
        if (!dev->fmr_pool)
                return -ENODEV;
 
-       if ((ib_sg_dma_address(ibdev, &scat[0]) & ~dev->fmr_page_mask) &&
-           mellanox_workarounds && !memcmp(&target->ioc_guid, mellanox_oui, 3))
+       if (srp_target_is_mellanox(target) &&
+           (ib_sg_dma_address(ibdev, &scat[0]) & ~dev->fmr_page_mask))
                return -EINVAL;
 
        len = page_cnt = 0;
@@ -1087,8 +1106,7 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
                break;
 
        case IB_CM_REJ_PORT_REDIRECT:
-               if (topspin_workarounds &&
-                   !memcmp(&target->ioc_guid, topspin_oui, 3)) {
+               if (srp_target_is_topspin(target)) {
                        /*
                         * Topspin/Cisco SRP gateways incorrectly send
                         * reject reason code 25 when they mean 24
@@ -1530,12 +1548,24 @@ static struct scsi_host_template srp_template = {
 
 static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
 {
+       struct srp_rport_identifiers ids;
+       struct srp_rport *rport;
+
        sprintf(target->target_name, "SRP.T10:%016llX",
                 (unsigned long long) be64_to_cpu(target->id_ext));
 
        if (scsi_add_host(target->scsi_host, host->dev->dev->dma_device))
                return -ENODEV;
 
+       memcpy(ids.port_id, &target->id_ext, 8);
+       memcpy(ids.port_id + 8, &target->ioc_guid, 8);
+       ids.roles = SRP_RPORT_ROLE_TARGET;
+       rport = srp_rport_add(target->scsi_host, &ids);
+       if (IS_ERR(rport)) {
+               scsi_remove_host(target->scsi_host);
+               return PTR_ERR(rport);
+       }
+
        spin_lock(&host->target_lock);
        list_add_tail(&target->list, &host->target_list);
        spin_unlock(&host->target_lock);
@@ -1679,6 +1709,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
                                goto out;
                        }
                        target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16));
+                       target->path.service_id = target->service_id;
                        kfree(p);
                        break;
 
@@ -1760,6 +1791,7 @@ static ssize_t srp_create_target(struct class_device *class_dev,
        if (!target_host)
                return -ENOMEM;
 
+       target_host->transportt = ib_srp_transport_template;
        target_host->max_lun     = SRP_MAX_LUN;
        target_host->max_cmd_len = sizeof ((struct srp_cmd *) (void *) 0L)->cdb;
 
@@ -2021,6 +2053,7 @@ static void srp_remove_one(struct ib_device *device)
 
                list_for_each_entry_safe(target, tmp_target,
                                         &host->target_list, list) {
+                       srp_remove_host(target->scsi_host);
                        scsi_remove_host(target->scsi_host);
                        srp_disconnect_target(target);
                        ib_destroy_cm_id(target->cm_id);
@@ -2039,10 +2072,18 @@ static void srp_remove_one(struct ib_device *device)
        kfree(srp_dev);
 }
 
+static struct srp_function_template ib_srp_transport_functions = {
+};
+
 static int __init srp_init_module(void)
 {
        int ret;
 
+       ib_srp_transport_template =
+               srp_attach_transport(&ib_srp_transport_functions);
+       if (!ib_srp_transport_template)
+               return -ENOMEM;
+
        srp_template.sg_tablesize = srp_sg_tablesize;
        srp_max_iu_len = (sizeof (struct srp_cmd) +
                          sizeof (struct srp_indirect_buf) +
@@ -2051,6 +2092,7 @@ static int __init srp_init_module(void)
        ret = class_register(&srp_class);
        if (ret) {
                printk(KERN_ERR PFX "couldn't register class infiniband_srp\n");
+               srp_release_transport(ib_srp_transport_template);
                return ret;
        }
 
@@ -2059,6 +2101,7 @@ static int __init srp_init_module(void)
        ret = ib_register_client(&srp_client);
        if (ret) {
                printk(KERN_ERR PFX "couldn't register IB client\n");
+               srp_release_transport(ib_srp_transport_template);
                ib_sa_unregister_client(&srp_sa_client);
                class_unregister(&srp_class);
                return ret;
@@ -2072,6 +2115,7 @@ static void __exit srp_cleanup_module(void)
        ib_unregister_client(&srp_client);
        ib_sa_unregister_client(&srp_sa_client);
        class_unregister(&srp_class);
+       srp_release_transport(ib_srp_transport_template);
 }
 
 module_init(srp_init_module);