aboutsummaryrefslogtreecommitdiff
path: root/drivers/infiniband/core/mad.c
diff options
context:
space:
mode:
authorHal Rosenstock <halr@voltaire.com>2005-07-27 11:45:23 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-27 16:26:09 -0700
commit824c8ae7d05bb4d21af707832c5bfa45d5494ec8 (patch)
treece268a0f9268efae69fc4735b0d650d19aeec6e6 /drivers/infiniband/core/mad.c
parentb82cab6b331b51d82f90d2207f3bbfdf09361ac9 (diff)
[PATCH] IB: Add MAD helper functions
Add new helper routines for allocating MADs for sending and formatting a send WR. Signed-off-by: Sean Hefty <sean.hefty@intel.com> Signed-off-by: Hal Rosenstock <halr@voltaire.com> Cc: Roland Dreier <rolandd@cisco.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/infiniband/core/mad.c')
-rw-r--r--drivers/infiniband/core/mad.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 52748b0f768..d66ecf8243e 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -763,6 +763,82 @@ out:
return ret;
}
+static int get_buf_length(int hdr_len, int data_len)
+{
+ int seg_size, pad;
+
+ seg_size = sizeof(struct ib_mad) - hdr_len;
+ if (data_len && seg_size) {
+ pad = seg_size - data_len % seg_size;
+ if (pad == seg_size)
+ pad = 0;
+ } else
+ pad = seg_size;
+ return hdr_len + data_len + pad;
+}
+
+struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
+ u32 remote_qpn, u16 pkey_index,
+ struct ib_ah *ah,
+ int hdr_len, int data_len,
+ unsigned int __nocast gfp_mask)
+{
+ struct ib_mad_agent_private *mad_agent_priv;
+ struct ib_mad_send_buf *send_buf;
+ int buf_size;
+ void *buf;
+
+ mad_agent_priv = container_of(mad_agent,
+ struct ib_mad_agent_private, agent);
+ buf_size = get_buf_length(hdr_len, data_len);
+
+ buf = kmalloc(sizeof *send_buf + buf_size, gfp_mask);
+ if (!buf)
+ return ERR_PTR(-ENOMEM);
+
+ send_buf = buf + buf_size;
+ memset(send_buf, 0, sizeof *send_buf);
+ send_buf->mad = buf;
+
+ send_buf->sge.addr = dma_map_single(mad_agent->device->dma_device,
+ buf, buf_size, DMA_TO_DEVICE);
+ pci_unmap_addr_set(send_buf, mapping, send_buf->sge.addr);
+ send_buf->sge.length = buf_size;
+ send_buf->sge.lkey = mad_agent->mr->lkey;
+
+ send_buf->send_wr.wr_id = (unsigned long) send_buf;
+ send_buf->send_wr.sg_list = &send_buf->sge;
+ send_buf->send_wr.num_sge = 1;
+ send_buf->send_wr.opcode = IB_WR_SEND;
+ send_buf->send_wr.send_flags = IB_SEND_SIGNALED;
+ send_buf->send_wr.wr.ud.ah = ah;
+ send_buf->send_wr.wr.ud.mad_hdr = &send_buf->mad->mad_hdr;
+ send_buf->send_wr.wr.ud.remote_qpn = remote_qpn;
+ send_buf->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY;
+ send_buf->send_wr.wr.ud.pkey_index = pkey_index;
+ send_buf->mad_agent = mad_agent;
+ atomic_inc(&mad_agent_priv->refcount);
+ return send_buf;
+}
+EXPORT_SYMBOL(ib_create_send_mad);
+
+void ib_free_send_mad(struct ib_mad_send_buf *send_buf)
+{
+ struct ib_mad_agent_private *mad_agent_priv;
+
+ mad_agent_priv = container_of(send_buf->mad_agent,
+ struct ib_mad_agent_private, agent);
+
+ dma_unmap_single(send_buf->mad_agent->device->dma_device,
+ pci_unmap_addr(send_buf, mapping),
+ send_buf->sge.length, DMA_TO_DEVICE);
+ kfree(send_buf->mad);
+
+ if (atomic_dec_and_test(&mad_agent_priv->refcount))
+ wake_up(&mad_agent_priv->wait);
+}
+EXPORT_SYMBOL(ib_free_send_mad);
+
static int ib_send_mad(struct ib_mad_agent_private *mad_agent_priv,
struct ib_mad_send_wr_private *mad_send_wr)
{