IB/mad: Return error response for unsupported MADs
authorSwapna Thete <swapna.thete@qlogic.com>
Sun, 26 Feb 2012 01:47:32 +0000 (17:47 -0800)
committerRoland Dreier <roland@purestorage.com>
Sun, 26 Feb 2012 01:47:32 +0000 (17:47 -0800)
Set up a response with appropriate error status and send it for MADs
that are not supported by a specific class/version.

Reviewed-by: Hal Rosenstock <hal@mellanox.com>
Signed-off-by: Swapna Thete <swapna.thete@qlogic.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/core/mad.c

index 2fe428bba54ca947bee81df3f78f34f466c20dd8..426bb7617ec6fa4027dd6d535eab1fa6675562fc 100644 (file)
@@ -1842,6 +1842,24 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
        }
 }
 
+static bool generate_unmatched_resp(struct ib_mad_private *recv,
+                                   struct ib_mad_private *response)
+{
+       if (recv->mad.mad.mad_hdr.method == IB_MGMT_METHOD_GET ||
+           recv->mad.mad.mad_hdr.method == IB_MGMT_METHOD_SET) {
+               memcpy(response, recv, sizeof *response);
+               response->header.recv_wc.wc = &response->header.wc;
+               response->header.recv_wc.recv_buf.mad = &response->mad.mad;
+               response->header.recv_wc.recv_buf.grh = &response->grh;
+               response->mad.mad.mad_hdr.method = IB_MGMT_METHOD_GET_RESP;
+               response->mad.mad.mad_hdr.status =
+                       cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB);
+
+               return true;
+       } else {
+               return false;
+       }
+}
 static void ib_mad_recv_done_handler(struct ib_mad_port_private *port_priv,
                                     struct ib_wc *wc)
 {
@@ -1963,6 +1981,9 @@ local:
                 * or via recv_handler in ib_mad_complete_recv()
                 */
                recv = NULL;
+       } else if (generate_unmatched_resp(recv, response)) {
+               agent_send_response(&response->mad.mad, &recv->grh, wc,
+                                   port_priv->device, port_num, qp_info->qp->qp_num);
        }
 
 out: