MAD: fix issues routing vendor MADs
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 12 May 2009 17:25:44 +0000 (17:25 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 12 May 2009 17:25:44 +0000 (17:25 +0000)
Only dispatch received vendor defined MADs to the HCA driver if the
management class is one of the MLX vendor defined classes.

When dispatching MADs locally that are not handled by the HCA driver,
copy the sent MAD data into the received MAD buffer.  Also initialize
the address information of the dispatched MAD, so that replies can be
routed correctly back to the sender.  If a MAD is not handled by the
HCA driver and cannot be dispatched, return the MAD to the MAD pool
to avoid leaking MADs.

Finally, we simplify the MAD dispatch code.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2174 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/al/al_mad.c
core/al/kernel/al_smi.c
inc/iba/ib_types.h

index 1cea131..4576fa8 100644 (file)
@@ -1027,7 +1027,6 @@ __use_tid_routing(
        IN              const   ib_mad_t* const                         p_mad_hdr,\r
        IN              const   boolean_t                                       are_we_sender )\r
 {\r
-       ib_rmpp_mad_t           *p_rmpp_mad;\r
        boolean_t                       is_orig;\r
 \r
        AL_ENTER( AL_DBG_MAD_SVC );\r
@@ -1039,45 +1038,10 @@ __use_tid_routing(
                return FALSE;\r
        }\r
 \r
-       /*\r
-        * Determine originator for a sent MAD.  Received MADs are just the\r
-        * opposite.\r
-        */\r
-\r
-       /* Non-DATA RMPP MADs are handled differently. */\r
-       p_rmpp_mad = (ib_rmpp_mad_t*)p_mad_hdr;\r
-       if( (p_mad_hdr->mgmt_class == IB_MCLASS_SUBN_ADM) &&\r
-               ( ib_rmpp_is_flag_set( p_rmpp_mad, IB_RMPP_FLAG_ACTIVE ) &&\r
-               (p_rmpp_mad->rmpp_type != IB_RMPP_TYPE_DATA) ) )\r
-       {\r
-               /*\r
-                * We need to distinguish between ACKs sent after receiving\r
-                * a request, versus ACKs sent after receiving a response.  ACKs\r
-                * to a request are from the responder.  ACKs to a response are\r
-                * from the originator.\r
-\r
-                * Note that we assume STOP and ABORT packets are initiated by\r
-                * receivers.  If both senders and receivers can\r
-                * initiate STOP and ABORT MADs, then we can't distinguish which\r
-                * transaction is associated with the MAD.  The TID for a\r
-                * send and receive can be the same.\r
-                */\r
-               is_orig = !ib_mad_is_response( p_mad_hdr );\r
-       }\r
+       if (are_we_sender)\r
+               is_orig = !ib_mad_is_response(p_mad_hdr);\r
        else\r
-       {\r
-               /*\r
-                * See if the MAD is being sent in response to a previous MAD.  If\r
-                * it is, then we're NOT the originator.  Note that trap repress\r
-                * MADs are responses, even though the response bit isn't set.\r
-                */\r
-               is_orig = !( ib_mad_is_response( p_mad_hdr ) ||\r
-                       (p_mad_hdr->method == IB_MAD_METHOD_TRAP_REPRESS) );\r
-       }\r
-\r
-       /* If we're the receiver, toggle the result. */\r
-       if( !are_we_sender )\r
-               is_orig = !is_orig;\r
+               is_orig = ib_mad_is_response(p_mad_hdr);\r
 \r
        AL_EXIT( AL_DBG_MAD_SVC );\r
        return is_orig;\r
@@ -2228,12 +2192,9 @@ __mad_svc_recv_done(
        }\r
 \r
        /*\r
-        * See if the MAD was sent in response to a previously sent MAD.  Note\r
-        * that trap repress messages are responses, even though the response\r
-        * bit isn't set.\r
+        * See if the MAD was sent in response to a previously sent MAD.\r
         */\r
-       if( ib_mad_is_response( p_mad_hdr ) ||\r
-               (p_mad_hdr->method == IB_MAD_METHOD_TRAP_REPRESS) )\r
+       if( ib_mad_is_response( p_mad_hdr ) )\r
        {\r
                /* Process the received response. */\r
                __process_recv_resp( h_mad_svc, p_mad_element );\r
index 012f96b..7f5abee 100644 (file)
@@ -172,11 +172,11 @@ process_mad_recv(
        IN                              spl_qp_svc_t*                           p_spl_qp_svc,\r
        IN                              ib_mad_element_t*                       p_mad_element );\r
 \r
-mad_route_t\r
+static mad_route_t\r
 route_recv_smp(\r
        IN                              ib_mad_element_t*                       p_mad_element );\r
 \r
-mad_route_t\r
+static mad_route_t\r
 route_recv_smp_attr(\r
        IN                              ib_mad_element_t*                       p_mad_element );\r
 \r
@@ -184,12 +184,12 @@ mad_route_t
 route_recv_dm_mad(\r
        IN                              ib_mad_element_t*                       p_mad_element );\r
 \r
-mad_route_t\r
-route_recv_gmp(\r
+static mad_route_t\r
+route_recv_bm(\r
        IN                              ib_mad_element_t*                       p_mad_element );\r
 \r
-mad_route_t\r
-route_recv_gmp_attr(\r
+static mad_route_t\r
+route_recv_perf(\r
        IN                              ib_mad_element_t*                       p_mad_element );\r
 \r
 ib_api_status_t\r
@@ -2234,6 +2234,7 @@ fwd_local_mad(
        ib_mad_t*                               p_mad;\r
        ib_smp_t*                               p_smp;\r
        al_mad_send_t*                  p_mad_send;\r
+       ib_mad_element_t*               p_send_mad;\r
        ib_mad_element_t*               p_mad_response = NULL;\r
        ib_mad_t*                               p_mad_response_buf;\r
        ib_api_status_t                 status = IB_SUCCESS;\r
@@ -2263,6 +2264,8 @@ fwd_local_mad(
                        return status;\r
                }\r
                p_mad_response_buf = p_mad_response->p_mad_buf;\r
+               /* Copy MAD to dispatch locally in case CA doesn't handle it. */\r
+               *p_mad_response_buf = *p_mad;\r
        }\r
        else\r
        {\r
@@ -2399,9 +2402,17 @@ fwd_local_mad(
                \r
 \r
                /* Construct the receive MAD element. */\r
-               p_mad_response->status          = IB_WCS_SUCCESS;\r
-               p_mad_response->remote_qp       = p_mad_wr->send_wr.dgrm.ud.remote_qp;\r
-               p_mad_response->remote_lid      = p_spl_qp_svc->base_lid;\r
+               p_send_mad = p_mad_send->p_send_mad;\r
+               p_mad_response->status = IB_WCS_SUCCESS;\r
+               p_mad_response->grh_valid = p_send_mad->grh_valid;\r
+               if( p_mad_response->grh_valid )\r
+                       *p_mad_response->p_grh  = *p_send_mad->p_grh;\r
+               p_mad_response->path_bits   = p_send_mad->path_bits;\r
+               p_mad_response->pkey_index  = p_send_mad->pkey_index;\r
+               p_mad_response->remote_lid  = p_send_mad->remote_lid;\r
+               p_mad_response->remote_qkey = p_send_mad->remote_qkey;\r
+               p_mad_response->remote_qp   = p_send_mad->remote_qp;\r
+               p_mad_response->remote_sl   = p_send_mad->remote_sl;\r
                if( p_mad_wr->send_wr.send_opt & IB_RECV_OPT_IMMEDIATE )\r
                {\r
                        p_mad_response->immediate_data = p_mad_wr->send_wr.immediate_data;\r
@@ -2413,6 +2424,8 @@ fwd_local_mad(
                 * the send.  This guarantees that the send request cannot time out.\r
                 */\r
                status = mad_disp_recv_done( p_spl_qp_svc->h_mad_disp, p_mad_response );\r
+               if( status != IB_SUCCESS )\r
+                       ib_put_mad( p_mad_response );\r
        }\r
        \r
        __complete_send_mad( p_spl_qp_svc->h_mad_disp, p_mad_wr,IB_WCS_SUCCESS);\r
@@ -2937,35 +2950,19 @@ process_mad_recv(
                        break;\r
 \r
                case IB_MCLASS_PERF:\r
-                       /* Process the received GMP. */\r
-                       switch( p_mad_element->p_mad_buf->method )\r
-                       {\r
-                       case IB_MAD_METHOD_GET:\r
-                       case IB_MAD_METHOD_SET:\r
-                               route = ROUTE_LOCAL;\r
-                               break;\r
-                       default:\r
-                               break;\r
-                       }\r
+                       route = route_recv_perf( p_mad_element );\r
                        break;\r
 \r
                case IB_MCLASS_BM:\r
-                       route = route_recv_gmp( p_mad_element );\r
+                       route = route_recv_bm( p_mad_element );\r
                        break;\r
 \r
-               case IB_MCLASS_SUBN_ADM:\r
-               case IB_MCLASS_DEV_MGMT:\r
-               case IB_MCLASS_COMM_MGMT:\r
-               case IB_MCLASS_SNMP:\r
+               case IB_MLX_VENDOR_CLASS1:\r
+               case IB_MLX_VENDOR_CLASS2:\r
+                       route = ROUTE_LOCAL;\r
                        break;\r
 \r
                default:\r
-                       /* Route vendor specific MADs to the HCA provider. */\r
-                       if( ib_class_is_vendor_specific(\r
-                               p_mad_element->p_mad_buf->mgmt_class ) )\r
-                       {\r
-                               route = route_recv_gmp( p_mad_element );\r
-                       }\r
                        break;\r
                }\r
        }\r
@@ -2989,7 +2986,7 @@ process_mad_recv(
 /*\r
  * Route a received SMP.\r
  */\r
-mad_route_t\r
+static mad_route_t\r
 route_recv_smp(\r
        IN                              ib_mad_element_t*                       p_mad_element )\r
 {\r
@@ -3054,7 +3051,7 @@ route_recv_smp(
 /*\r
  * Route received SMP attributes.\r
  */\r
-mad_route_t\r
+static mad_route_t\r
 route_recv_smp_attr(\r
        IN                              ib_mad_element_t*                       p_mad_element )\r
 {\r
@@ -3090,72 +3087,38 @@ route_recv_smp_attr(
 }\r
 \r
 \r
-/*\r
- * Route a received GMP.\r
- */\r
-mad_route_t\r
-route_recv_gmp(\r
+static mad_route_t\r
+route_recv_bm(\r
        IN                              ib_mad_element_t*                       p_mad_element )\r
 {\r
-       mad_route_t                             route;\r
-\r
-       AL_ENTER( AL_DBG_SMI );\r
-\r
-       CL_ASSERT( p_mad_element );\r
-\r
-       /* Process the received GMP. */\r
        switch( p_mad_element->p_mad_buf->method )\r
        {\r
        case IB_MAD_METHOD_GET:\r
        case IB_MAD_METHOD_SET:\r
-               /* Route vendor specific MADs to the HCA provider. */\r
-               if( ib_class_is_vendor_specific(\r
-                       p_mad_element->p_mad_buf->mgmt_class ) )\r
-               {\r
-                       route = ROUTE_LOCAL;\r
-               }\r
-               else\r
-               {\r
-                       route = route_recv_gmp_attr( p_mad_element );\r
-               }\r
+               if( p_mad_element->p_mad_buf->attr_id == IB_MAD_ATTR_CLASS_PORT_INFO )\r
+                       return ROUTE_LOCAL;\r
                break;\r
-\r
        default:\r
-               route = ROUTE_DISPATCHER;\r
                break;\r
        }\r
-\r
-       AL_EXIT( AL_DBG_SMI );\r
-       return route;\r
+       return ROUTE_DISPATCHER;\r
 }\r
 \r
-\r
-\r
-/*\r
- * Route received GMP attributes.\r
- */\r
-mad_route_t\r
-route_recv_gmp_attr(\r
+static mad_route_t\r
+route_recv_perf(\r
        IN                              ib_mad_element_t*                       p_mad_element )\r
 {\r
-       mad_route_t                             route;\r
-\r
-       AL_ENTER( AL_DBG_SMI );\r
-\r
-       CL_ASSERT( p_mad_element );\r
-\r
-       /* Process the received GMP attributes. */\r
-       if( p_mad_element->p_mad_buf->attr_id == IB_MAD_ATTR_CLASS_PORT_INFO )\r
-               route = ROUTE_LOCAL;\r
-       else\r
-               route = ROUTE_DISPATCHER;\r
-\r
-       AL_EXIT( AL_DBG_SMI );\r
-       return route;\r
+       switch( p_mad_element->p_mad_buf->method )\r
+       {\r
+       case IB_MAD_METHOD_GET:\r
+       case IB_MAD_METHOD_SET:\r
+               return ROUTE_LOCAL;\r
+       default:\r
+               break;\r
+       }\r
+       return ROUTE_DISPATCHER;\r
 }\r
 \r
-\r
-\r
 /*\r
  * Forward a locally generated Subnet Management trap.\r
  */\r
@@ -3263,8 +3226,7 @@ recv_local_mad(
         * We need to get a response from the local HCA to this MAD only if this\r
         * MAD is not itself a response.\r
         */\r
-       p_mad_request->resp_expected = !( ib_mad_is_response( p_mad_hdr ) ||\r
-               ( p_mad_hdr->method == IB_MAD_METHOD_TRAP_REPRESS ) );\r
+       p_mad_request->resp_expected = !ib_mad_is_response( p_mad_hdr );\r
        p_mad_request->timeout_ms = LOCAL_MAD_TIMEOUT;\r
        p_mad_request->send_opt = IB_SEND_OPT_LOCAL;\r
 \r
index 390d3b2..74d16c6 100644 (file)
@@ -3798,8 +3798,8 @@ ib_mad_is_response(
        IN              const   ib_mad_t* const                         p_mad )\r
 {\r
        CL_ASSERT( p_mad );\r
-       return( (p_mad->method & IB_MAD_METHOD_RESP_MASK) ==\r
-                       IB_MAD_METHOD_RESP_MASK );\r
+       return ((p_mad->method & IB_MAD_METHOD_RESP_MASK) ||\r
+                       (p_mad->method == IB_MAD_METHOD_TRAP_REPRESS));\r
 }\r
 /*\r
 * PARAMETERS\r