@@ -2923,6 +2923,10 @@ static int ib_mad_port_open(struct ib_device *device,
unsigned long flags;
char name[sizeof "ib_mad123"];
int has_smi;
+ size_t max_mad_size = rdma_dev_max_mad_size(device, port_num);
+
+ if (WARN_ON(max_mad_size < IB_MGMT_MAD_SIZE))
+ return -EFAULT;
/* Create new device info */
port_priv = kzalloc(sizeof *port_priv, GFP_KERNEL);
@@ -197,6 +197,7 @@ static int c2_rnic_query(struct c2_dev *c2dev, struct ib_device_attr *props)
props->max_srq_sge = 0;
props->max_pkeys = 0;
props->local_ca_ack_delay = 0;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
bail2:
vq_repbuf_free(c2dev, reply);
@@ -1174,6 +1174,7 @@ static int iwch_query_device(struct ib_device *ibdev,
props->max_pd = dev->attr.max_pds;
props->local_ca_ack_delay = 0;
props->max_fast_reg_page_list_len = T3_MAX_FASTREG_DEPTH;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
@@ -332,6 +332,7 @@ static int c4iw_query_device(struct ib_device *ibdev,
props->max_pd = T4_MAX_NUM_PD;
props->local_ca_ack_delay = 0;
props->max_fast_reg_page_list_len = t4_max_fr_depth(use_dsgl);
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
@@ -40,6 +40,7 @@
*/
#include <linux/gfp.h>
+#include <rdma/ib_mad.h>
#include "ehca_tools.h"
#include "ehca_iverbs.h"
@@ -133,6 +134,8 @@ int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
if (rblock->hca_cap_indicators & cap_mapping[i + 1])
props->device_cap_flags |= cap_mapping[i];
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
+
query_device1:
ehca_free_fw_ctrlblock(rblock);
@@ -1538,6 +1538,7 @@ static int ipath_query_device(struct ib_device *ibdev,
props->max_mcast_qp_attach = ib_ipath_max_mcast_qp_attached;
props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
props->max_mcast_grp;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
@@ -229,6 +229,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
props->max_mcast_grp;
props->max_map_per_fmr = dev->dev->caps.max_fmr_maps;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
out:
kfree(in_mad);
@@ -154,6 +154,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
props->max_mcast_grp;
props->max_map_per_fmr = INT_MAX; /* no limit in ConnectIB */
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
if (dev->mdev->caps.gen.flags & MLX5_DEV_CAP_FLAG_ON_DMND_PG)
@@ -123,6 +123,8 @@ static int mthca_query_device(struct ib_device *ibdev,
props->max_map_per_fmr =
(1 << (32 - ilog2(mdev->limits.num_mpts))) - 1;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
+
err = 0;
out:
kfree(in_mad);
@@ -555,6 +555,7 @@ static int nes_query_device(struct ib_device *ibdev, struct ib_device_attr *prop
props->max_qp_init_rd_atom = props->max_qp_rd_atom;
props->atomic_cap = IB_ATOMIC_NONE;
props->max_map_per_fmr = 1;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
@@ -103,6 +103,7 @@ int ocrdma_query_device(struct ib_device *ibdev, struct ib_device_attr *attr)
attr->local_ca_ack_delay = dev->attr.local_ca_ack_delay;
attr->max_fast_reg_page_list_len = dev->attr.max_pages_per_frmr;
attr->max_pkeys = 1;
+ attr->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
@@ -1592,6 +1592,7 @@ static int qib_query_device(struct ib_device *ibdev,
props->max_mcast_qp_attach = ib_qib_max_mcast_qp_attached;
props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
props->max_mcast_grp;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
@@ -22,6 +22,7 @@
#include <rdma/ib_user_verbs.h>
#include <rdma/ib_addr.h>
+#include <rdma/ib_mad.h>
#include "usnic_abi.h"
#include "usnic_ib.h"
@@ -296,6 +297,7 @@ int usnic_ib_query_device(struct ib_device *ibdev,
props->max_mcast_qp_attach = 0;
props->max_total_mcast_qp_attach = 0;
props->max_map_per_fmr = 0;
+ props->max_mad_size = IB_MGMT_MAD_SIZE;
/* Owned by Userspace
* max_qp_wr, max_sge, max_sge_rd, max_cqe */
mutex_unlock(&us_ibdev->usdev_lock);
@@ -135,6 +135,7 @@ enum {
IB_MGMT_SA_DATA = 200,
IB_MGMT_DEVICE_HDR = 64,
IB_MGMT_DEVICE_DATA = 192,
+ IB_MGMT_MAD_SIZE = IB_MGMT_MAD_HDR + IB_MGMT_MAD_DATA,
};
struct ib_mad_hdr {
@@ -217,6 +217,7 @@ struct ib_device_attr {
int sig_prot_cap;
int sig_guard_cap;
struct ib_odp_caps odp_caps;
+ u32 max_mad_size;
};
enum ib_mtu {
@@ -1930,6 +1931,24 @@ static inline int cap_read_multi_sge(struct ib_device *device, u8 port_num)
return !rdma_protocol_iwarp(device, port_num);
}
+/**
+ * rdma_dev_max_mad_size - Return the max MAD size required by this RDMA Port.
+ *
+ * @device: Device
+ * @port_num: Port number
+ *
+ * Return the max MAD size required by the Port. May return 0 if the port does
+ * not support MADs
+ */
+static inline size_t rdma_dev_max_mad_size(struct ib_device *device,
+ u8 port_num)
+{
+ struct ib_device_attr attr;
+
+ device->query_device(device, &attr);
+ return attr.max_mad_size;
+}
+
int ib_query_gid(struct ib_device *device,
u8 port_num, int index, union ib_gid *gid);