[openib-general] [PATCH] [MAD] Convert RMPP code to use MAD APIs for send MADs
Sean Hefty
sean.hefty at intel.com
Thu Jun 30 16:23:54 PDT 2005
The following patch converts the RMPP code to use the MAD layer APIs for
allocating send MAD data buffers when sending ACKs.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
Index: mad_rmpp.c
===================================================================
--- mad_rmpp.c (revision 2760)
+++ mad_rmpp.c (working copy)
@@ -69,14 +69,6 @@ struct mad_rmpp_recv {
u8 method;
};
-struct rmpp_msg {
- struct ib_rmpp_mad mad;
- DECLARE_PCI_UNMAP_ADDR(mapping)
- struct ib_mad_agent *mad_agent;
- struct ib_send_wr send_wr;
- struct ib_sge sge;
-};
-
static void destroy_rmpp_recv(struct mad_rmpp_recv *rmpp_recv)
{
atomic_dec(&rmpp_recv->refcount);
@@ -238,47 +230,6 @@ insert_rmpp_recv(struct ib_mad_agent_pri
return cur_rmpp_recv;
}
-static struct rmpp_msg * alloc_rmpp_msg(struct ib_mad_agent *mad_agent,
- u32 remote_qpn, u16 pkey_index,
- struct ib_ah *ah)
-{
- struct rmpp_msg *msg;
-
- msg = kmalloc(sizeof *msg, GFP_KERNEL);
- if (!msg)
- return NULL;
- memset(msg, 0, sizeof *msg);
-
- msg->sge.addr = dma_map_single(mad_agent->device->dma_device,
- &msg->mad, sizeof msg->mad,
- DMA_TO_DEVICE);
- pci_unmap_addr_set(msg, mapping, msg->sge.addr);
- msg->sge.length = sizeof msg->mad;
- msg->sge.lkey = mad_agent->mr->lkey;
-
- msg->send_wr.wr_id = (unsigned long) msg;
- msg->send_wr.sg_list = &msg->sge;
- msg->send_wr.num_sge = 1;
- msg->send_wr.opcode = IB_WR_SEND;
- msg->send_wr.send_flags = IB_SEND_SIGNALED;
- msg->send_wr.wr.ud.ah = ah;
- msg->send_wr.wr.ud.mad_hdr = &msg->mad.mad_hdr;
- msg->send_wr.wr.ud.remote_qpn = remote_qpn;
- msg->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY;
- msg->send_wr.wr.ud.pkey_index = pkey_index;
-
- msg->mad_agent = mad_agent;
- return msg;
-}
-
-static void free_rmpp_msg(struct rmpp_msg *msg)
-{
- dma_unmap_single(msg->mad_agent->device->dma_device,
- pci_unmap_addr(msg, mapping),
- sizeof msg->mad, DMA_TO_DEVICE);
- kfree(msg);
-}
-
static int data_offset(u8 mgmt_class)
{
if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
@@ -313,21 +264,24 @@ static void format_ack(struct ib_rmpp_ma
static void ack_recv(struct mad_rmpp_recv *rmpp_recv,
struct ib_mad_recv_wc *recv_wc)
{
- struct rmpp_msg *msg;
+ struct ib_mad_send_buf *msg;
struct ib_send_wr *bad_send_wr;
- int ret;
+ int hdr_len, ret;
- msg = alloc_rmpp_msg(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
- recv_wc->wc->pkey_index, rmpp_recv->ah);
+ hdr_len = sizeof(struct ib_mad_hdr) + sizeof(struct ib_rmpp_hdr);
+ msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
+ recv_wc->wc->pkey_index, rmpp_recv->ah, 1,
+ hdr_len, sizeof(struct ib_rmpp_mad) - hdr_len,
+ GFP_KERNEL);
if (!msg)
return;
- format_ack(&msg->mad, (struct ib_rmpp_mad *) recv_wc->recv_buf.mad,
- rmpp_recv);
+ format_ack((struct ib_rmpp_mad *) msg->mad,
+ (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, rmpp_recv);
ret = ib_post_send_mad(&rmpp_recv->agent->agent, &msg->send_wr,
&bad_send_wr);
if (ret)
- free_rmpp_msg(msg);
+ ib_free_send_mad(msg);
}
static inline int get_last_flag(struct ib_mad_recv_buf *seg)
@@ -749,7 +703,7 @@ int ib_process_rmpp_send_wc(struct ib_ma
struct ib_mad_send_wc *mad_send_wc)
{
struct ib_rmpp_mad *rmpp_mad;
- struct rmpp_msg *msg;
+ struct ib_mad_send_buf *msg;
int ret;
rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr;
@@ -758,8 +712,9 @@ int ib_process_rmpp_send_wc(struct ib_ma
return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) {
- msg = (struct rmpp_msg *) (unsigned long) mad_send_wc->wr_id;
- free_rmpp_msg(msg);
+ msg = (struct ib_mad_send_buf *) (unsigned long)
+ mad_send_wc->wr_id;
+ ib_free_send_mad(msg);
return IB_RMPP_RESULT_INTERNAL; /* ACK, STOP, or ABORT */
}
More information about the general
mailing list