IB/sa: Add new QoS fields to path record
[pandora-kernel.git] / drivers / infiniband / core / sa_query.c
index 6469406..cf474ec 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
- * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
+ * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
  * Copyright (c) 2006 Intel Corporation.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
@@ -56,6 +56,7 @@ MODULE_LICENSE("Dual BSD/GPL");
 struct ib_sa_sm_ah {
        struct ib_ah        *ah;
        struct kref          ref;
+       u16                  pkey_index;
        u8                   src_path_mask;
 };
 
@@ -122,14 +123,10 @@ static u32 tid;
        .field_name          = "sa_path_rec:" #field
 
 static const struct ib_field path_rec_table[] = {
-       { RESERVED,
+       { PATH_REC_FIELD(service_id),
          .offset_words = 0,
          .offset_bits  = 0,
-         .size_bits    = 32 },
-       { RESERVED,
-         .offset_words = 1,
-         .offset_bits  = 0,
-         .size_bits    = 32 },
+         .size_bits    = 64 },
        { PATH_REC_FIELD(dgid),
          .offset_words = 2,
          .offset_bits  = 0,
@@ -178,7 +175,7 @@ static const struct ib_field path_rec_table[] = {
          .offset_words = 12,
          .offset_bits  = 16,
          .size_bits    = 16 },
-       { RESERVED,
+       { PATH_REC_FIELD(qos_class),
          .offset_words = 13,
          .offset_bits  = 0,
          .size_bits    = 12 },
@@ -382,6 +379,11 @@ static void update_sm_ah(struct work_struct *work)
        kref_init(&new_ah->ref);
        new_ah->src_path_mask = (1 << port_attr.lmc) - 1;
 
+       new_ah->pkey_index = 0;
+       if (ib_find_pkey(port->agent->device, port->port_num,
+                        IB_DEFAULT_PKEY_FULL, &new_ah->pkey_index))
+               printk(KERN_ERR "Couldn't find index for default PKey\n");
+
        memset(&ah_attr, 0, sizeof ah_attr);
        ah_attr.dlid     = port_attr.sm_lid;
        ah_attr.sl       = port_attr.sm_sl;
@@ -512,6 +514,35 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
 }
 EXPORT_SYMBOL(ib_init_ah_from_path);
 
+static int alloc_mad(struct ib_sa_query *query, gfp_t gfp_mask)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&query->port->ah_lock, flags);
+       kref_get(&query->port->sm_ah->ref);
+       query->sm_ah = query->port->sm_ah;
+       spin_unlock_irqrestore(&query->port->ah_lock, flags);
+
+       query->mad_buf = ib_create_send_mad(query->port->agent, 1,
+                                           query->sm_ah->pkey_index,
+                                           0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA,
+                                           gfp_mask);
+       if (IS_ERR(query->mad_buf)) {
+               kref_put(&query->sm_ah->ref, free_sm_ah);
+               return -ENOMEM;
+       }
+
+       query->mad_buf->ah = query->sm_ah->ah;
+
+       return 0;
+}
+
+static void free_mad(struct ib_sa_query *query)
+{
+       ib_free_send_mad(query->mad_buf);
+       kref_put(&query->sm_ah->ref, free_sm_ah);
+}
+
 static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
 {
        unsigned long flags;
@@ -548,20 +579,11 @@ retry:
        query->mad_buf->context[0] = query;
        query->id = id;
 
-       spin_lock_irqsave(&query->port->ah_lock, flags);
-       kref_get(&query->port->sm_ah->ref);
-       query->sm_ah = query->port->sm_ah;
-       spin_unlock_irqrestore(&query->port->ah_lock, flags);
-
-       query->mad_buf->ah = query->sm_ah->ah;
-
        ret = ib_post_send_mad(query->mad_buf, NULL);
        if (ret) {
                spin_lock_irqsave(&idr_lock, flags);
                idr_remove(&query_idr, id);
                spin_unlock_irqrestore(&idr_lock, flags);
-
-               kref_put(&query->sm_ah->ref, free_sm_ah);
        }
 
        /*
@@ -647,13 +669,10 @@ int ib_sa_path_rec_get(struct ib_sa_client *client,
        if (!query)
                return -ENOMEM;
 
-       query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
-                                                    0, IB_MGMT_SA_HDR,
-                                                    IB_MGMT_SA_DATA, gfp_mask);
-       if (!query->sa_query.mad_buf) {
-               ret = -ENOMEM;
+       query->sa_query.port     = port;
+       ret = alloc_mad(&query->sa_query, gfp_mask);
+       if (ret)
                goto err1;
-       }
 
        ib_sa_client_get(client);
        query->sa_query.client = client;
@@ -665,7 +684,6 @@ int ib_sa_path_rec_get(struct ib_sa_client *client,
 
        query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
        query->sa_query.release  = ib_sa_path_rec_release;
-       query->sa_query.port     = port;
        mad->mad_hdr.method      = IB_MGMT_METHOD_GET;
        mad->mad_hdr.attr_id     = cpu_to_be16(IB_SA_ATTR_PATH_REC);
        mad->sa_hdr.comp_mask    = comp_mask;
@@ -683,7 +701,7 @@ int ib_sa_path_rec_get(struct ib_sa_client *client,
 err2:
        *sa_query = NULL;
        ib_sa_client_put(query->sa_query.client);
-       ib_free_send_mad(query->sa_query.mad_buf);
+       free_mad(&query->sa_query);
 
 err1:
        kfree(query);
@@ -773,13 +791,10 @@ int ib_sa_service_rec_query(struct ib_sa_client *client,
        if (!query)
                return -ENOMEM;
 
-       query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
-                                                    0, IB_MGMT_SA_HDR,
-                                                    IB_MGMT_SA_DATA, gfp_mask);
-       if (!query->sa_query.mad_buf) {
-               ret = -ENOMEM;
+       query->sa_query.port     = port;
+       ret = alloc_mad(&query->sa_query, gfp_mask);
+       if (ret)
                goto err1;
-       }
 
        ib_sa_client_get(client);
        query->sa_query.client = client;
@@ -791,7 +806,6 @@ int ib_sa_service_rec_query(struct ib_sa_client *client,
 
        query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
        query->sa_query.release  = ib_sa_service_rec_release;
-       query->sa_query.port     = port;
        mad->mad_hdr.method      = method;
        mad->mad_hdr.attr_id     = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
        mad->sa_hdr.comp_mask    = comp_mask;
@@ -810,7 +824,7 @@ int ib_sa_service_rec_query(struct ib_sa_client *client,
 err2:
        *sa_query = NULL;
        ib_sa_client_put(query->sa_query.client);
-       ib_free_send_mad(query->sa_query.mad_buf);
+       free_mad(&query->sa_query);
 
 err1:
        kfree(query);
@@ -869,13 +883,10 @@ int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
        if (!query)
                return -ENOMEM;
 
-       query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
-                                                    0, IB_MGMT_SA_HDR,
-                                                    IB_MGMT_SA_DATA, gfp_mask);
-       if (!query->sa_query.mad_buf) {
-               ret = -ENOMEM;
+       query->sa_query.port     = port;
+       ret = alloc_mad(&query->sa_query, gfp_mask);
+       if (ret)
                goto err1;
-       }
 
        ib_sa_client_get(client);
        query->sa_query.client = client;
@@ -887,7 +898,6 @@ int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
 
        query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
        query->sa_query.release  = ib_sa_mcmember_rec_release;
-       query->sa_query.port     = port;
        mad->mad_hdr.method      = method;
        mad->mad_hdr.attr_id     = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
        mad->sa_hdr.comp_mask    = comp_mask;
@@ -906,7 +916,7 @@ int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
 err2:
        *sa_query = NULL;
        ib_sa_client_put(query->sa_query.client);
-       ib_free_send_mad(query->sa_query.mad_buf);
+       free_mad(&query->sa_query);
 
 err1:
        kfree(query);
@@ -939,8 +949,7 @@ static void send_handler(struct ib_mad_agent *agent,
        idr_remove(&query_idr, query->id);
        spin_unlock_irqrestore(&idr_lock, flags);
 
-       ib_free_send_mad(mad_send_wc->send_buf);
-       kref_put(&query->sm_ah->ref, free_sm_ah);
+       free_mad(query);
        ib_sa_client_put(query->client);
        query->release(query);
 }