include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-3.10.git] / drivers / infiniband / hw / mlx4 / mad.c
index 0ed02b7..f38d5b1 100644 (file)
@@ -34,6 +34,7 @@
 #include <rdma/ib_smi.h>
 
 #include <linux/mlx4/cmd.h>
+#include <linux/gfp.h>
 
 #include "mlx4_ib.h"
 
@@ -147,7 +148,8 @@ static void update_sm_ah(struct mlx4_ib_dev *dev, u8 port_num, u16 lid, u8 sl)
  * Snoop SM MADs for port info and P_Key table sets, so we can
  * synthesize LID change and P_Key change events.
  */
-static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad)
+static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad,
+                               u16 prev_lid)
 {
        struct ib_event event;
 
@@ -157,6 +159,7 @@ static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad)
                if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO) {
                        struct ib_port_info *pinfo =
                                (struct ib_port_info *) ((struct ib_smp *) mad)->data;
+                       u16 lid = be16_to_cpu(pinfo->lid);
 
                        update_sm_ah(to_mdev(ibdev), port_num,
                                     be16_to_cpu(pinfo->sm_lid),
@@ -165,12 +168,15 @@ static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad)
                        event.device           = ibdev;
                        event.element.port_num = port_num;
 
-                       if(pinfo->clientrereg_resv_subnetto & 0x80)
+                       if (pinfo->clientrereg_resv_subnetto & 0x80) {
                                event.event    = IB_EVENT_CLIENT_REREGISTER;
-                       else
-                               event.event    = IB_EVENT_LID_CHANGE;
+                               ib_dispatch_event(&event);
+                       }
 
-                       ib_dispatch_event(&event);
+                       if (prev_lid != lid) {
+                               event.event    = IB_EVENT_LID_CHANGE;
+                               ib_dispatch_event(&event);
+                       }
                }
 
                if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PKEY_TABLE) {
@@ -228,8 +234,9 @@ int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags,     u8 port_num,
                        struct ib_wc *in_wc, struct ib_grh *in_grh,
                        struct ib_mad *in_mad, struct ib_mad *out_mad)
 {
-       u16 slid;
+       u16 slid, prev_lid = 0;
        int err;
+       struct ib_port_attr pattr;
 
        slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);
 
@@ -255,13 +262,21 @@ int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags,   u8 port_num,
                        return IB_MAD_RESULT_SUCCESS;
        } else if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT ||
                   in_mad->mad_hdr.mgmt_class == MLX4_IB_VENDOR_CLASS1   ||
-                  in_mad->mad_hdr.mgmt_class == MLX4_IB_VENDOR_CLASS2) {
+                  in_mad->mad_hdr.mgmt_class == MLX4_IB_VENDOR_CLASS2   ||
+                  in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_CONG_MGMT) {
                if (in_mad->mad_hdr.method  != IB_MGMT_METHOD_GET &&
                    in_mad->mad_hdr.method  != IB_MGMT_METHOD_SET)
                        return IB_MAD_RESULT_SUCCESS;
        } else
                return IB_MAD_RESULT_SUCCESS;
 
+       if ((in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
+            in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
+           in_mad->mad_hdr.method == IB_MGMT_METHOD_SET &&
+           in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
+           !ib_query_port(ibdev, port_num, &pattr))
+               prev_lid = pattr.lid;
+
        err = mlx4_MAD_IFC(to_mdev(ibdev),
                           mad_flags & IB_MAD_IGNORE_MKEY,
                           mad_flags & IB_MAD_IGNORE_BKEY,
@@ -270,7 +285,7 @@ int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags,     u8 port_num,
                return IB_MAD_RESULT_FAILURE;
 
        if (!out_mad->mad_hdr.status) {
-               smp_snoop(ibdev, port_num, in_mad);
+               smp_snoop(ibdev, port_num, in_mad, prev_lid);
                node_desc_override(ibdev, out_mad);
        }
 
@@ -297,7 +312,7 @@ int mlx4_ib_mad_init(struct mlx4_ib_dev *dev)
        int p, q;
        int ret;
 
-       for (p = 0; p < dev->dev->caps.num_ports; ++p)
+       for (p = 0; p < dev->num_ports; ++p)
                for (q = 0; q <= 1; ++q) {
                        agent = ib_register_mad_agent(&dev->ib_dev, p + 1,
                                                      q ? IB_QPT_GSI : IB_QPT_SMI,
@@ -313,7 +328,7 @@ int mlx4_ib_mad_init(struct mlx4_ib_dev *dev)
        return 0;
 
 err:
-       for (p = 0; p < dev->dev->caps.num_ports; ++p)
+       for (p = 0; p < dev->num_ports; ++p)
                for (q = 0; q <= 1; ++q)
                        if (dev->send_agent[p][q])
                                ib_unregister_mad_agent(dev->send_agent[p][q]);
@@ -326,7 +341,7 @@ void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev)
        struct ib_mad_agent *agent;
        int p, q;
 
-       for (p = 0; p < dev->dev->caps.num_ports; ++p) {
+       for (p = 0; p < dev->num_ports; ++p) {
                for (q = 0; q <= 1; ++q) {
                        agent = dev->send_agent[p][q];
                        dev->send_agent[p][q] = NULL;