[IBAL] Handle RMPP send payload < MAD buffer length
authorftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 10 Oct 2005 19:54:53 +0000 (19:54 +0000)
committerftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 10 Oct 2005 19:54:53 +0000 (19:54 +0000)
Signed-off-by: Fab Tillier (ftillier@silverstorm.com)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@106 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/al/al_mad.c

index a909da9..6c9d1e7 100644 (file)
@@ -1681,6 +1681,7 @@ __queue_mad_wr(
        al_mad_element_t        *p_al_element;\r
        ib_rmpp_mad_t           *p_rmpp_hdr;\r
        uint8_t                         *p_rmpp_src, *p_rmpp_dst;\r
+       uintn_t                         hdr_len, offset, max_len;\r
 \r
        CL_ENTER( AL_DBG_MAD_SVC, g_al_dbg_lvl );\r
        p_send_wr = &h_send->mad_wr.send_wr;\r
@@ -1702,28 +1703,32 @@ __queue_mad_wr(
                p_rmpp_dst = (uint8_t*)(uintn_t)p_al_element->mad_ds.vaddr;\r
 #endif\r
                p_rmpp_src = (uint8_t* __ptr64)h_send->p_send_mad->p_mad_buf;\r
-               p_rmpp_hdr = (ib_rmpp_mad_t* __ptr64)h_send->p_send_mad->p_mad_buf;\r
+               p_rmpp_hdr = (ib_rmpp_mad_t*)p_rmpp_src;\r
 \r
                if( h_send->p_send_mad->p_mad_buf->mgmt_class == IB_MCLASS_SUBN_ADM )\r
-               {\r
-                       /* Copy the header into the registered send buffer. */\r
-                       cl_memcpy( p_rmpp_dst, p_rmpp_src, IB_SA_MAD_HDR_SIZE );\r
-                       /* Copy this segment's payload into the registered send buffer. */\r
-                       p_rmpp_dst = p_rmpp_dst + IB_SA_MAD_HDR_SIZE;\r
-                       p_rmpp_src = p_rmpp_src + IB_SA_MAD_HDR_SIZE +\r
-                               ( (cl_ntoh32( p_rmpp_hdr->seg_num ) - 1) * IB_SA_DATA_SIZE );\r
-                       cl_memcpy( p_rmpp_dst, p_rmpp_src, IB_SA_DATA_SIZE );\r
-               } \r
+                       hdr_len = IB_SA_MAD_HDR_SIZE;\r
                else\r
+                       hdr_len = MAD_RMPP_HDR_SIZE;\r
+\r
+               max_len = MAD_BLOCK_SIZE - hdr_len;\r
+\r
+               offset = hdr_len + (max_len * (cl_ntoh32( p_rmpp_hdr->seg_num ) - 1));\r
+\r
+               /* Copy the header into the registered send buffer. */\r
+               cl_memcpy( p_rmpp_dst, p_rmpp_src, hdr_len );\r
+\r
+               /* Copy this segment's payload into the registered send buffer. */\r
+               CL_ASSERT( h_send->p_send_mad->size != offset );\r
+               if( (h_send->p_send_mad->size - offset) < max_len )\r
                {\r
-                       /* Copy the header into the registered send buffer. */\r
-                       cl_memcpy( p_rmpp_dst, p_rmpp_src, MAD_RMPP_HDR_SIZE );   \r
-                       /* Copy this segment's payload into the registered send buffer. */\r
-                       p_rmpp_dst = p_rmpp_dst + MAD_RMPP_HDR_SIZE;\r
-                       p_rmpp_src = p_rmpp_src + MAD_RMPP_HDR_SIZE +\r
-                               ( (cl_ntoh32( p_rmpp_hdr->seg_num ) - 1) * MAD_RMPP_DATA_SIZE );\r
-                       cl_memcpy( p_rmpp_dst, p_rmpp_src, MAD_RMPP_DATA_SIZE );\r
+                       max_len = h_send->p_send_mad->size - offset;\r
+                       /* Clear unused payload. */\r
+                       cl_memclr( p_rmpp_dst + hdr_len + max_len,\r
+                               MAD_BLOCK_SIZE - hdr_len - max_len );\r
                }\r
+\r
+               cl_memcpy(\r
+                       p_rmpp_dst + hdr_len, p_rmpp_src + offset, max_len );\r
        }\r
 \r
        p_send_wr->num_ds = 1;\r