Commit 87635b71b544563f29050a9cecaa12b5d2a3e34a

Authored by Roland Dreier
1 parent 105e50a5e8

IB/mthca: Factor common MAD initialization code

Factor out common code for initializing MAD packets, which is shared
by many query routines in mthca_provider.c, into init_query_mad().

add/remove: 1/0 grow/shrink: 0/4 up/down: 16/-44 (-28)
function                                     old     new   delta
init_query_mad                                 -      16     +16
mthca_query_port                             521     518      -3
mthca_query_pkey                             301     294      -7
mthca_query_device                           648     641      -7
mthca_query_gid                              453     426     -27

Signed-off-by: Roland Dreier <rolandd@cisco.com>

Showing 1 changed file with 22 additions and 30 deletions Side-by-side Diff

drivers/infiniband/hw/mthca/mthca_provider.c
... ... @@ -45,6 +45,14 @@
45 45 #include "mthca_user.h"
46 46 #include "mthca_memfree.h"
47 47  
  48 +static void init_query_mad(struct ib_smp *mad)
  49 +{
  50 + mad->base_version = 1;
  51 + mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  52 + mad->class_version = 1;
  53 + mad->method = IB_MGMT_METHOD_GET;
  54 +}
  55 +
48 56 static int mthca_query_device(struct ib_device *ibdev,
49 57 struct ib_device_attr *props)
50 58 {
... ... @@ -64,11 +72,8 @@
64 72  
65 73 props->fw_ver = mdev->fw_ver;
66 74  
67   - in_mad->base_version = 1;
68   - in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
69   - in_mad->class_version = 1;
70   - in_mad->method = IB_MGMT_METHOD_GET;
71   - in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
  75 + init_query_mad(in_mad);
  76 + in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
72 77  
73 78 err = mthca_MAD_IFC(mdev, 1, 1,
74 79 1, NULL, NULL, in_mad, out_mad,
... ... @@ -134,12 +139,9 @@
134 139  
135 140 memset(props, 0, sizeof *props);
136 141  
137   - in_mad->base_version = 1;
138   - in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
139   - in_mad->class_version = 1;
140   - in_mad->method = IB_MGMT_METHOD_GET;
141   - in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
142   - in_mad->attr_mod = cpu_to_be32(port);
  142 + init_query_mad(in_mad);
  143 + in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
  144 + in_mad->attr_mod = cpu_to_be32(port);
143 145  
144 146 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
145 147 port, NULL, NULL, in_mad, out_mad,
... ... @@ -223,12 +225,9 @@
223 225 if (!in_mad || !out_mad)
224 226 goto out;
225 227  
226   - in_mad->base_version = 1;
227   - in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
228   - in_mad->class_version = 1;
229   - in_mad->method = IB_MGMT_METHOD_GET;
230   - in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
231   - in_mad->attr_mod = cpu_to_be32(index / 32);
  228 + init_query_mad(in_mad);
  229 + in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
  230 + in_mad->attr_mod = cpu_to_be32(index / 32);
232 231  
233 232 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
234 233 port, NULL, NULL, in_mad, out_mad,
... ... @@ -261,12 +260,9 @@
261 260 if (!in_mad || !out_mad)
262 261 goto out;
263 262  
264   - in_mad->base_version = 1;
265   - in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
266   - in_mad->class_version = 1;
267   - in_mad->method = IB_MGMT_METHOD_GET;
268   - in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
269   - in_mad->attr_mod = cpu_to_be32(port);
  263 + init_query_mad(in_mad);
  264 + in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
  265 + in_mad->attr_mod = cpu_to_be32(port);
270 266  
271 267 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
272 268 port, NULL, NULL, in_mad, out_mad,
... ... @@ -280,13 +276,9 @@
280 276  
281 277 memcpy(gid->raw, out_mad->data + 8, 8);
282 278  
283   - memset(in_mad, 0, sizeof *in_mad);
284   - in_mad->base_version = 1;
285   - in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
286   - in_mad->class_version = 1;
287   - in_mad->method = IB_MGMT_METHOD_GET;
288   - in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
289   - in_mad->attr_mod = cpu_to_be32(index / 8);
  279 + init_query_mad(in_mad);
  280 + in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
  281 + in_mad->attr_mod = cpu_to_be32(index / 8);
290 282  
291 283 err = mthca_MAD_IFC(to_mdev(ibdev), 1, 1,
292 284 port, NULL, NULL, in_mad, out_mad,