blob: 948188e37f95ab3fc2dfb2dd4ab7a1698c0ae84f [file] [log] [blame]
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001/*
Ralph Campbelle7eacd32008-04-16 21:09:32 -07002 * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08003 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <rdma/ib_smi.h>
Or Gerlitz6aea2132011-07-05 15:46:29 +000035#include <rdma/ib_pma.h>
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080036
37#include "ipath_kernel.h"
38#include "ipath_verbs.h"
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -070039#include "ipath_common.h"
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080040
Harvey Harrison9c3da092009-01-17 17:11:57 -080041#define IB_SMP_UNSUP_VERSION cpu_to_be16(0x0004)
42#define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
43#define IB_SMP_UNSUP_METH_ATTR cpu_to_be16(0x000C)
44#define IB_SMP_INVALID_FIELD cpu_to_be16(0x001C)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080045
46static int reply(struct ib_smp *smp)
47{
48 /*
49 * The verbs framework will handle the directed/LID route
50 * packet changes.
51 */
52 smp->method = IB_MGMT_METHOD_GET_RESP;
53 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
54 smp->status |= IB_SMP_DIRECTION;
55 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
56}
57
58static int recv_subn_get_nodedescription(struct ib_smp *smp,
59 struct ib_device *ibdev)
60{
61 if (smp->attr_mod)
62 smp->status |= IB_SMP_INVALID_FIELD;
63
Roel Kluin286b63d2009-09-05 20:23:21 -070064 memcpy(smp->data, ibdev->node_desc, sizeof(smp->data));
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080065
66 return reply(smp);
67}
68
69struct nodeinfo {
70 u8 base_version;
71 u8 class_version;
72 u8 node_type;
73 u8 num_ports;
74 __be64 sys_guid;
75 __be64 node_guid;
76 __be64 port_guid;
77 __be16 partition_cap;
78 __be16 device_id;
79 __be32 revision;
80 u8 local_port_num;
81 u8 vendor_id[3];
82} __attribute__ ((packed));
83
84static int recv_subn_get_nodeinfo(struct ib_smp *smp,
85 struct ib_device *ibdev, u8 port)
86{
87 struct nodeinfo *nip = (struct nodeinfo *)&smp->data;
88 struct ipath_devdata *dd = to_idev(ibdev)->dd;
Bryan O'Sullivane8a88f02006-07-01 04:35:57 -070089 u32 vendor, majrev, minrev;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080090
Bryan O'Sullivan11b054fe2006-09-28 09:00:02 -070091 /* GUID 0 is illegal */
92 if (smp->attr_mod || (dd->ipath_guid == 0))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080093 smp->status |= IB_SMP_INVALID_FIELD;
94
95 nip->base_version = 1;
96 nip->class_version = 1;
97 nip->node_type = 1; /* channel adapter */
98 /*
99 * XXX The num_ports value will need a layer function to get
100 * the value if we ever have more than one IB port on a chip.
101 * We will also need to get the GUID for the port.
102 */
103 nip->num_ports = ibdev->phys_port_cnt;
104 /* This is already in network order */
105 nip->sys_guid = to_idev(ibdev)->sys_image_guid;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700106 nip->node_guid = dd->ipath_guid;
Sean Heftyf41d2292007-06-28 19:16:20 -0700107 nip->port_guid = dd->ipath_guid;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700108 nip->partition_cap = cpu_to_be16(ipath_get_npkeys(dd));
109 nip->device_id = cpu_to_be16(dd->ipath_deviceid);
110 majrev = dd->ipath_majrev;
111 minrev = dd->ipath_minrev;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800112 nip->revision = cpu_to_be32((majrev << 16) | minrev);
113 nip->local_port_num = port;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700114 vendor = dd->ipath_vendorid;
Ralph Campbelldf866612008-07-14 23:48:52 -0700115 nip->vendor_id[0] = IPATH_SRC_OUI_1;
116 nip->vendor_id[1] = IPATH_SRC_OUI_2;
117 nip->vendor_id[2] = IPATH_SRC_OUI_3;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800118
119 return reply(smp);
120}
121
122static int recv_subn_get_guidinfo(struct ib_smp *smp,
123 struct ib_device *ibdev)
124{
125 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
126 __be64 *p = (__be64 *) smp->data;
127
128 /* 32 blocks of 8 64-bit GUIDs per block */
129
130 memset(smp->data, 0, sizeof(smp->data));
131
132 /*
133 * We only support one GUID for now. If this changes, the
134 * portinfo.guid_cap field needs to be updated too.
135 */
Bryan O'Sullivan11b054fe2006-09-28 09:00:02 -0700136 if (startgx == 0) {
137 __be64 g = to_idev(ibdev)->dd->ipath_guid;
138 if (g == 0)
139 /* GUID 0 is illegal */
140 smp->status |= IB_SMP_INVALID_FIELD;
141 else
142 /* The first is a copy of the read-only HW GUID. */
143 *p = g;
144 } else
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800145 smp->status |= IB_SMP_INVALID_FIELD;
146
147 return reply(smp);
148}
149
Ralph Campbella51a2512008-04-16 21:09:24 -0700150static void set_link_width_enabled(struct ipath_devdata *dd, u32 w)
151{
152 (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, w);
153}
154
155static void set_link_speed_enabled(struct ipath_devdata *dd, u32 s)
156{
157 (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, s);
158}
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700159
160static int get_overrunthreshold(struct ipath_devdata *dd)
161{
162 return (dd->ipath_ibcctrl >>
163 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
164 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
165}
166
167/**
168 * set_overrunthreshold - set the overrun threshold
169 * @dd: the infinipath device
170 * @n: the new threshold
171 *
172 * Note that this will only take effect when the link state changes.
173 */
174static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
175{
176 unsigned v;
177
178 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
179 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
180 if (v != n) {
181 dd->ipath_ibcctrl &=
182 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
183 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
184 dd->ipath_ibcctrl |=
185 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
186 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
187 dd->ipath_ibcctrl);
188 }
189 return 0;
190}
191
192static int get_phyerrthreshold(struct ipath_devdata *dd)
193{
194 return (dd->ipath_ibcctrl >>
195 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
196 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
197}
198
199/**
200 * set_phyerrthreshold - set the physical error threshold
201 * @dd: the infinipath device
202 * @n: the new threshold
203 *
204 * Note that this will only take effect when the link state changes.
205 */
206static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
207{
208 unsigned v;
209
210 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
211 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
212 if (v != n) {
213 dd->ipath_ibcctrl &=
214 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
215 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
216 dd->ipath_ibcctrl |=
217 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
218 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
219 dd->ipath_ibcctrl);
220 }
221 return 0;
222}
223
224/**
225 * get_linkdowndefaultstate - get the default linkdown state
226 * @dd: the infinipath device
227 *
228 * Returns zero if the default is POLL, 1 if the default is SLEEP.
229 */
230static int get_linkdowndefaultstate(struct ipath_devdata *dd)
231{
232 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
233}
234
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800235static int recv_subn_get_portinfo(struct ib_smp *smp,
236 struct ib_device *ibdev, u8 port)
237{
238 struct ipath_ibdev *dev;
Ralph Campbella51a2512008-04-16 21:09:24 -0700239 struct ipath_devdata *dd;
Leonid Arshda2ab622006-06-17 20:37:36 -0700240 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800241 u16 lid;
242 u8 ibcstat;
243 u8 mtu;
244 int ret;
245
246 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
247 smp->status |= IB_SMP_INVALID_FIELD;
248 ret = reply(smp);
249 goto bail;
250 }
251
252 dev = to_idev(ibdev);
Ralph Campbella51a2512008-04-16 21:09:24 -0700253 dd = dev->dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800254
255 /* Clear all fields. Only set the non-zero fields. */
256 memset(smp->data, 0, sizeof(smp->data));
257
258 /* Only return the mkey if the protection field allows it. */
259 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
Ralph Campbell542869a2007-09-13 11:42:52 -0700260 dev->mkeyprot == 0)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800261 pip->mkey = dev->mkey;
262 pip->gid_prefix = dev->gid_prefix;
Ralph Campbella51a2512008-04-16 21:09:24 -0700263 lid = dd->ipath_lid;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800264 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
265 pip->sm_lid = cpu_to_be16(dev->sm_lid);
266 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
267 /* pip->diag_code; */
268 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
269 pip->local_port_num = port;
Ralph Campbella51a2512008-04-16 21:09:24 -0700270 pip->link_width_enabled = dd->ipath_link_width_enabled;
271 pip->link_width_supported = dd->ipath_link_width_supported;
272 pip->link_width_active = dd->ipath_link_width_active;
273 pip->linkspeed_portstate = dd->ipath_link_speed_supported << 4;
274 ibcstat = dd->ipath_lastibcstat;
275 /* map LinkState to IB portinfo values. */
276 pip->linkspeed_portstate |= ipath_ib_linkstate(dd, ibcstat) + 1;
277
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800278 pip->portphysstate_linkdown =
Ralph Campbella51a2512008-04-16 21:09:24 -0700279 (ipath_cvt_physportstate[ibcstat & dd->ibcs_lts_mask] << 4) |
280 (get_linkdowndefaultstate(dd) ? 1 : 2);
281 pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dd->ipath_lmc;
282 pip->linkspeedactive_enabled = (dd->ipath_link_speed_active << 4) |
283 dd->ipath_link_speed_enabled;
284 switch (dd->ipath_ibmtu) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800285 case 4096:
286 mtu = IB_MTU_4096;
287 break;
288 case 2048:
289 mtu = IB_MTU_2048;
290 break;
291 case 1024:
292 mtu = IB_MTU_1024;
293 break;
294 case 512:
295 mtu = IB_MTU_512;
296 break;
297 case 256:
298 mtu = IB_MTU_256;
299 break;
300 default: /* oops, something is wrong */
301 mtu = IB_MTU_2048;
302 break;
303 }
304 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
305 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
306 pip->vl_high_limit = dev->vl_high_limit;
307 /* pip->vl_arb_high_cap; // only one VL */
308 /* pip->vl_arb_low_cap; // only one VL */
309 /* InitTypeReply = 0 */
Dave Olson826d8012008-04-16 21:01:12 -0700310 /* our mtu cap depends on whether 4K MTU enabled or not */
311 pip->inittypereply_mtucap = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
312 /* HCAs ignore VLStallCount and HOQLife */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800313 /* pip->vlstallcnt_hoqlife; */
314 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
315 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
316 /* P_KeyViolations are counted by hardware. */
317 pip->pkey_violations =
Ralph Campbella51a2512008-04-16 21:09:24 -0700318 cpu_to_be16((ipath_get_cr_errpkey(dd) -
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -0700319 dev->z_pkey_violations) & 0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800320 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
321 /* Only the hardware GUID is supported for now */
322 pip->guid_cap = 1;
323 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
324 /* 32.768 usec. response time (guessing) */
325 pip->resv_resptimevalue = 3;
326 pip->localphyerrors_overrunerrors =
Ralph Campbella51a2512008-04-16 21:09:24 -0700327 (get_phyerrthreshold(dd) << 4) |
328 get_overrunthreshold(dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800329 /* pip->max_credit_hint; */
Ralph Campbella51a2512008-04-16 21:09:24 -0700330 if (dev->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
331 u32 v;
332
333 v = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LINKLATENCY);
334 pip->link_roundtrip_latency[0] = v >> 16;
335 pip->link_roundtrip_latency[1] = v >> 8;
336 pip->link_roundtrip_latency[2] = v;
337 }
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800338
339 ret = reply(smp);
340
341bail:
342 return ret;
343}
344
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700345/**
346 * get_pkeys - return the PKEY table for port 0
347 * @dd: the infinipath device
348 * @pkeys: the pkey table is placed here
349 */
350static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
351{
Dave Olson3d089092008-12-05 11:14:38 -0800352 /* always a kernel port, no locking needed */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700353 struct ipath_portdata *pd = dd->ipath_pd[0];
354
355 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
356
357 return 0;
358}
359
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800360static int recv_subn_get_pkeytable(struct ib_smp *smp,
361 struct ib_device *ibdev)
362{
363 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
364 u16 *p = (u16 *) smp->data;
365 __be16 *q = (__be16 *) smp->data;
366
367 /* 64 blocks of 32 16-bit P_Key entries */
368
369 memset(smp->data, 0, sizeof(smp->data));
370 if (startpx == 0) {
371 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700372 unsigned i, n = ipath_get_npkeys(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800373
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700374 get_pkeys(dev->dd, p);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800375
376 for (i = 0; i < n; i++)
377 q[i] = cpu_to_be16(p[i]);
378 } else
379 smp->status |= IB_SMP_INVALID_FIELD;
380
381 return reply(smp);
382}
383
384static int recv_subn_set_guidinfo(struct ib_smp *smp,
385 struct ib_device *ibdev)
386{
387 /* The only GUID we support is the first read-only entry. */
388 return recv_subn_get_guidinfo(smp, ibdev);
389}
390
391/**
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700392 * set_linkdowndefaultstate - set the default linkdown state
393 * @dd: the infinipath device
394 * @sleep: the new state
395 *
396 * Note that this will only take effect when the link state changes.
397 */
398static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
399{
400 if (sleep)
401 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
402 else
403 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
404 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
405 dd->ipath_ibcctrl);
406 return 0;
407}
408
409/**
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800410 * recv_subn_set_portinfo - set port information
411 * @smp: the incoming SM packet
412 * @ibdev: the infiniband device
413 * @port: the port on the device
414 *
415 * Set Portinfo (see ch. 14.2.5.6).
416 */
417static int recv_subn_set_portinfo(struct ib_smp *smp,
418 struct ib_device *ibdev, u8 port)
419{
Leonid Arshda2ab622006-06-17 20:37:36 -0700420 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800421 struct ib_event event;
422 struct ipath_ibdev *dev;
Ralph Campbell542869a2007-09-13 11:42:52 -0700423 struct ipath_devdata *dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800424 char clientrereg = 0;
425 u16 lid, smlid;
426 u8 lwe;
427 u8 lse;
428 u8 state;
429 u16 lstate;
430 u32 mtu;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700431 int ret, ore;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800432
433 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
434 goto err;
435
436 dev = to_idev(ibdev);
Ralph Campbell542869a2007-09-13 11:42:52 -0700437 dd = dev->dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800438 event.device = ibdev;
439 event.element.port_num = port;
440
441 dev->mkey = pip->mkey;
442 dev->gid_prefix = pip->gid_prefix;
443 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
444
445 lid = be16_to_cpu(pip->lid);
Ralph Campbell542869a2007-09-13 11:42:52 -0700446 if (dd->ipath_lid != lid ||
447 dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800448 /* Must be a valid unicast LID address. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700449 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800450 goto err;
Ralph Campbell542869a2007-09-13 11:42:52 -0700451 ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800452 event.event = IB_EVENT_LID_CHANGE;
453 ib_dispatch_event(&event);
454 }
455
456 smlid = be16_to_cpu(pip->sm_lid);
457 if (smlid != dev->sm_lid) {
458 /* Must be a valid unicast LID address. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700459 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800460 goto err;
461 dev->sm_lid = smlid;
462 event.event = IB_EVENT_SM_CHANGE;
463 ib_dispatch_event(&event);
464 }
465
Ralph Campbella51a2512008-04-16 21:09:24 -0700466 /* Allow 1x or 4x to be set (see 14.2.6.6). */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800467 lwe = pip->link_width_enabled;
Ralph Campbella51a2512008-04-16 21:09:24 -0700468 if (lwe) {
469 if (lwe == 0xFF)
470 lwe = dd->ipath_link_width_supported;
471 else if (lwe >= 16 || (lwe & ~dd->ipath_link_width_supported))
472 goto err;
473 set_link_width_enabled(dd, lwe);
474 }
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800475
Ralph Campbella51a2512008-04-16 21:09:24 -0700476 /* Allow 2.5 or 5.0 Gbs. */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800477 lse = pip->linkspeedactive_enabled & 0xF;
Ralph Campbella51a2512008-04-16 21:09:24 -0700478 if (lse) {
479 if (lse == 15)
480 lse = dd->ipath_link_speed_supported;
481 else if (lse >= 8 || (lse & ~dd->ipath_link_speed_supported))
482 goto err;
483 set_link_speed_enabled(dd, lse);
484 }
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800485
486 /* Set link down default state. */
487 switch (pip->portphysstate_linkdown & 0xF) {
488 case 0: /* NOP */
489 break;
490 case 1: /* SLEEP */
Ralph Campbell542869a2007-09-13 11:42:52 -0700491 if (set_linkdowndefaultstate(dd, 1))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800492 goto err;
493 break;
494 case 2: /* POLL */
Ralph Campbell542869a2007-09-13 11:42:52 -0700495 if (set_linkdowndefaultstate(dd, 0))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800496 goto err;
497 break;
498 default:
499 goto err;
500 }
501
Ralph Campbell542869a2007-09-13 11:42:52 -0700502 dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800503 dev->vl_high_limit = pip->vl_high_limit;
504
505 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
506 case IB_MTU_256:
507 mtu = 256;
508 break;
509 case IB_MTU_512:
510 mtu = 512;
511 break;
512 case IB_MTU_1024:
513 mtu = 1024;
514 break;
515 case IB_MTU_2048:
516 mtu = 2048;
517 break;
518 case IB_MTU_4096:
Dave Olson826d8012008-04-16 21:01:12 -0700519 if (!ipath_mtu4096)
520 goto err;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800521 mtu = 4096;
522 break;
523 default:
524 /* XXX We have already partially updated our state! */
525 goto err;
526 }
Ralph Campbell542869a2007-09-13 11:42:52 -0700527 ipath_set_mtu(dd, mtu);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800528
529 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
530
531 /* We only support VL0 */
532 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
533 goto err;
534
535 if (pip->mkey_violations == 0)
536 dev->mkey_violations = 0;
537
538 /*
539 * Hardware counter can't be reset so snapshot and subtract
540 * later.
541 */
542 if (pip->pkey_violations == 0)
Ralph Campbell542869a2007-09-13 11:42:52 -0700543 dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800544
545 if (pip->qkey_violations == 0)
546 dev->qkey_violations = 0;
547
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700548 ore = pip->localphyerrors_overrunerrors;
Ralph Campbell542869a2007-09-13 11:42:52 -0700549 if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800550 goto err;
551
Ralph Campbell542869a2007-09-13 11:42:52 -0700552 if (set_overrunthreshold(dd, (ore & 0xF)))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800553 goto err;
554
555 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
556
557 if (pip->clientrereg_resv_subnetto & 0x80) {
558 clientrereg = 1;
Roland Dreier6eddb5c2006-06-17 20:37:37 -0700559 event.event = IB_EVENT_CLIENT_REREGISTER;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800560 ib_dispatch_event(&event);
561 }
562
563 /*
564 * Do the port state change now that the other link parameters
565 * have been set.
566 * Changing the port physical state only makes sense if the link
567 * is down or is being set to down.
568 */
569 state = pip->linkspeed_portstate & 0xF;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800570 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
571 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
572 goto err;
573
574 /*
575 * Only state changes of DOWN, ARM, and ACTIVE are valid
576 * and must be in the correct state to take effect (see 7.2.6).
577 */
578 switch (state) {
579 case IB_PORT_NOP:
580 if (lstate == 0)
581 break;
582 /* FALLTHROUGH */
583 case IB_PORT_DOWN:
584 if (lstate == 0)
Ralph Campbell140277e2007-12-14 01:53:56 -0800585 lstate = IPATH_IB_LINKDOWN_ONLY;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800586 else if (lstate == 1)
587 lstate = IPATH_IB_LINKDOWN_SLEEP;
588 else if (lstate == 2)
589 lstate = IPATH_IB_LINKDOWN;
590 else if (lstate == 3)
591 lstate = IPATH_IB_LINKDOWN_DISABLE;
592 else
593 goto err;
Ralph Campbell542869a2007-09-13 11:42:52 -0700594 ipath_set_linkstate(dd, lstate);
Michael Albaugh4330e4d2008-04-16 21:09:26 -0700595 if (lstate == IPATH_IB_LINKDOWN_DISABLE) {
596 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
597 goto done;
598 }
Ralph Campbell140277e2007-12-14 01:53:56 -0800599 ipath_wait_linkstate(dd, IPATH_LINKINIT | IPATH_LINKARMED |
600 IPATH_LINKACTIVE, 1000);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800601 break;
602 case IB_PORT_ARMED:
Ralph Campbell542869a2007-09-13 11:42:52 -0700603 ipath_set_linkstate(dd, IPATH_IB_LINKARM);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800604 break;
605 case IB_PORT_ACTIVE:
Ralph Campbell542869a2007-09-13 11:42:52 -0700606 ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800607 break;
608 default:
609 /* XXX We have already partially updated our state! */
610 goto err;
611 }
612
613 ret = recv_subn_get_portinfo(smp, ibdev, port);
614
615 if (clientrereg)
616 pip->clientrereg_resv_subnetto |= 0x80;
617
618 goto done;
619
620err:
621 smp->status |= IB_SMP_INVALID_FIELD;
622 ret = recv_subn_get_portinfo(smp, ibdev, port);
623
624done:
625 return ret;
626}
627
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700628/**
629 * rm_pkey - decrecment the reference count for the given PKEY
630 * @dd: the infinipath device
631 * @key: the PKEY index
632 *
633 * Return true if this was the last reference and the hardware table entry
634 * needs to be changed.
635 */
636static int rm_pkey(struct ipath_devdata *dd, u16 key)
637{
638 int i;
639 int ret;
640
641 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
642 if (dd->ipath_pkeys[i] != key)
643 continue;
644 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
645 dd->ipath_pkeys[i] = 0;
646 ret = 1;
647 goto bail;
648 }
649 break;
650 }
651
652 ret = 0;
653
654bail:
655 return ret;
656}
657
658/**
659 * add_pkey - add the given PKEY to the hardware table
660 * @dd: the infinipath device
661 * @key: the PKEY
662 *
663 * Return an error code if unable to add the entry, zero if no change,
664 * or 1 if the hardware PKEY register needs to be updated.
665 */
666static int add_pkey(struct ipath_devdata *dd, u16 key)
667{
668 int i;
669 u16 lkey = key & 0x7FFF;
670 int any = 0;
671 int ret;
672
673 if (lkey == 0x7FFF) {
674 ret = 0;
675 goto bail;
676 }
677
678 /* Look for an empty slot or a matching PKEY. */
679 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
680 if (!dd->ipath_pkeys[i]) {
681 any++;
682 continue;
683 }
684 /* If it matches exactly, try to increment the ref count */
685 if (dd->ipath_pkeys[i] == key) {
686 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
687 ret = 0;
688 goto bail;
689 }
690 /* Lost the race. Look for an empty slot below. */
691 atomic_dec(&dd->ipath_pkeyrefs[i]);
692 any++;
693 }
694 /*
695 * It makes no sense to have both the limited and unlimited
696 * PKEY set at the same time since the unlimited one will
697 * disable the limited one.
698 */
699 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
700 ret = -EEXIST;
701 goto bail;
702 }
703 }
704 if (!any) {
705 ret = -EBUSY;
706 goto bail;
707 }
708 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
709 if (!dd->ipath_pkeys[i] &&
710 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
711 /* for ipathstats, etc. */
712 ipath_stats.sps_pkeys[i] = lkey;
713 dd->ipath_pkeys[i] = key;
714 ret = 1;
715 goto bail;
716 }
717 }
718 ret = -EBUSY;
719
720bail:
721 return ret;
722}
723
724/**
725 * set_pkeys - set the PKEY table for port 0
726 * @dd: the infinipath device
727 * @pkeys: the PKEY table
728 */
Or Gerlitze3164532014-07-08 12:45:10 +0300729static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys, u8 port)
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700730{
731 struct ipath_portdata *pd;
732 int i;
733 int changed = 0;
734
Dave Olson3d089092008-12-05 11:14:38 -0800735 /* always a kernel port, no locking needed */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700736 pd = dd->ipath_pd[0];
737
738 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
739 u16 key = pkeys[i];
740 u16 okey = pd->port_pkeys[i];
741
742 if (key == okey)
743 continue;
744 /*
745 * The value of this PKEY table entry is changing.
746 * Remove the old entry in the hardware's array of PKEYs.
747 */
748 if (okey & 0x7FFF)
749 changed |= rm_pkey(dd, okey);
750 if (key & 0x7FFF) {
751 int ret = add_pkey(dd, key);
752
753 if (ret < 0)
754 key = 0;
755 else
756 changed |= ret;
757 }
758 pd->port_pkeys[i] = key;
759 }
760 if (changed) {
761 u64 pkey;
Or Gerlitze3164532014-07-08 12:45:10 +0300762 struct ib_event event;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700763
764 pkey = (u64) dd->ipath_pkeys[0] |
765 ((u64) dd->ipath_pkeys[1] << 16) |
766 ((u64) dd->ipath_pkeys[2] << 32) |
767 ((u64) dd->ipath_pkeys[3] << 48);
768 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
769 (unsigned long long) pkey);
770 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
771 pkey);
Or Gerlitze3164532014-07-08 12:45:10 +0300772
773 event.event = IB_EVENT_PKEY_CHANGE;
774 event.device = &dd->verbs_dev->ibdev;
775 event.element.port_num = port;
776 ib_dispatch_event(&event);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700777 }
778 return 0;
779}
780
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800781static int recv_subn_set_pkeytable(struct ib_smp *smp,
Or Gerlitze3164532014-07-08 12:45:10 +0300782 struct ib_device *ibdev, u8 port)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800783{
784 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
785 __be16 *p = (__be16 *) smp->data;
786 u16 *q = (u16 *) smp->data;
787 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700788 unsigned i, n = ipath_get_npkeys(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800789
790 for (i = 0; i < n; i++)
791 q[i] = be16_to_cpu(p[i]);
792
Or Gerlitze3164532014-07-08 12:45:10 +0300793 if (startpx != 0 || set_pkeys(dev->dd, q, port) != 0)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800794 smp->status |= IB_SMP_INVALID_FIELD;
795
796 return recv_subn_get_pkeytable(smp, ibdev);
797}
798
Or Gerlitz6aea2132011-07-05 15:46:29 +0000799static int recv_pma_get_classportinfo(struct ib_pma_mad *pmp)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800800{
Or Gerlitz6aea2132011-07-05 15:46:29 +0000801 struct ib_class_port_info *p =
802 (struct ib_class_port_info *)pmp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800803
804 memset(pmp->data, 0, sizeof(pmp->data));
805
Or Gerlitz6aea2132011-07-05 15:46:29 +0000806 if (pmp->mad_hdr.attr_mod != 0)
807 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800808
809 /* Indicate AllPortSelect is valid (only one port anyway) */
Or Gerlitz6aea2132011-07-05 15:46:29 +0000810 p->capability_mask = cpu_to_be16(1 << 8);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800811 p->base_version = 1;
812 p->class_version = 1;
813 /*
814 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
815 * sec.
816 */
817 p->resp_time_value = 18;
818
819 return reply((struct ib_smp *) pmp);
820}
821
822/*
823 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
824 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
825 * We support 5 counters which only count the mandatory quantities.
826 */
827#define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
Harvey Harrison9c3da092009-01-17 17:11:57 -0800828#define COUNTER_MASK0_9 cpu_to_be32(COUNTER_MASK(1, 0) | \
829 COUNTER_MASK(1, 1) | \
830 COUNTER_MASK(1, 2) | \
831 COUNTER_MASK(1, 3) | \
832 COUNTER_MASK(1, 4))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800833
Or Gerlitz6aea2132011-07-05 15:46:29 +0000834static int recv_pma_get_portsamplescontrol(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800835 struct ib_device *ibdev, u8 port)
836{
837 struct ib_pma_portsamplescontrol *p =
838 (struct ib_pma_portsamplescontrol *)pmp->data;
839 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800840 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800841 unsigned long flags;
842 u8 port_select = p->port_select;
843
844 memset(pmp->data, 0, sizeof(pmp->data));
845
846 p->port_select = port_select;
Or Gerlitz6aea2132011-07-05 15:46:29 +0000847 if (pmp->mad_hdr.attr_mod != 0 ||
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800848 (port_select != port && port_select != 0xFF))
Or Gerlitz6aea2132011-07-05 15:46:29 +0000849 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800850 /*
851 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
852 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
853 * intervals are counted in ticks. Since we use Linux timers, that
854 * count in jiffies, we can't sample for less than 1000 ticks if HZ
Ralph Campbella51a2512008-04-16 21:09:24 -0700855 * == 1000 (4000 ticks if HZ is 250). link_speed_active returns 2 for
856 * DDR, 1 for SDR, set the tick to 1 for DDR, 0 for SDR on chips that
857 * have hardware support for delaying packets.
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800858 */
Ralph Campbella51a2512008-04-16 21:09:24 -0700859 if (crp->cr_psstat)
860 p->tick = dev->dd->ipath_link_speed_active - 1;
861 else
862 p->tick = 250; /* 1 usec. */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800863 p->counter_width = 4; /* 32 bit counters */
864 p->counter_mask0_9 = COUNTER_MASK0_9;
865 spin_lock_irqsave(&dev->pending_lock, flags);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800866 if (crp->cr_psstat)
867 p->sample_status = ipath_read_creg32(dev->dd, crp->cr_psstat);
868 else
869 p->sample_status = dev->pma_sample_status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800870 p->sample_start = cpu_to_be32(dev->pma_sample_start);
871 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
872 p->tag = cpu_to_be16(dev->pma_tag);
873 p->counter_select[0] = dev->pma_counter_select[0];
874 p->counter_select[1] = dev->pma_counter_select[1];
875 p->counter_select[2] = dev->pma_counter_select[2];
876 p->counter_select[3] = dev->pma_counter_select[3];
877 p->counter_select[4] = dev->pma_counter_select[4];
878 spin_unlock_irqrestore(&dev->pending_lock, flags);
879
880 return reply((struct ib_smp *) pmp);
881}
882
Or Gerlitz6aea2132011-07-05 15:46:29 +0000883static int recv_pma_set_portsamplescontrol(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800884 struct ib_device *ibdev, u8 port)
885{
886 struct ib_pma_portsamplescontrol *p =
887 (struct ib_pma_portsamplescontrol *)pmp->data;
888 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800889 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800890 unsigned long flags;
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800891 u8 status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800892 int ret;
893
Or Gerlitz6aea2132011-07-05 15:46:29 +0000894 if (pmp->mad_hdr.attr_mod != 0 ||
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800895 (p->port_select != port && p->port_select != 0xFF)) {
Or Gerlitz6aea2132011-07-05 15:46:29 +0000896 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800897 ret = reply((struct ib_smp *) pmp);
898 goto bail;
899 }
900
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800901 spin_lock_irqsave(&dev->pending_lock, flags);
902 if (crp->cr_psstat)
903 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
904 else
905 status = dev->pma_sample_status;
906 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
907 dev->pma_sample_start = be32_to_cpu(p->sample_start);
908 dev->pma_sample_interval = be32_to_cpu(p->sample_interval);
909 dev->pma_tag = be16_to_cpu(p->tag);
910 dev->pma_counter_select[0] = p->counter_select[0];
911 dev->pma_counter_select[1] = p->counter_select[1];
912 dev->pma_counter_select[2] = p->counter_select[2];
913 dev->pma_counter_select[3] = p->counter_select[3];
914 dev->pma_counter_select[4] = p->counter_select[4];
915 if (crp->cr_psstat) {
916 ipath_write_creg(dev->dd, crp->cr_psinterval,
917 dev->pma_sample_interval);
918 ipath_write_creg(dev->dd, crp->cr_psstart,
919 dev->pma_sample_start);
920 } else
921 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800922 }
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800923 spin_unlock_irqrestore(&dev->pending_lock, flags);
924
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800925 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
926
927bail:
928 return ret;
929}
930
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800931static u64 get_counter(struct ipath_ibdev *dev,
932 struct ipath_cregs const *crp,
933 __be16 sel)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800934{
935 u64 ret;
936
937 switch (sel) {
938 case IB_PMA_PORT_XMIT_DATA:
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800939 ret = (crp->cr_psxmitdatacount) ?
940 ipath_read_creg32(dev->dd, crp->cr_psxmitdatacount) :
941 dev->ipath_sword;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800942 break;
943 case IB_PMA_PORT_RCV_DATA:
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800944 ret = (crp->cr_psrcvdatacount) ?
945 ipath_read_creg32(dev->dd, crp->cr_psrcvdatacount) :
946 dev->ipath_rword;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800947 break;
948 case IB_PMA_PORT_XMIT_PKTS:
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800949 ret = (crp->cr_psxmitpktscount) ?
950 ipath_read_creg32(dev->dd, crp->cr_psxmitpktscount) :
951 dev->ipath_spkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800952 break;
953 case IB_PMA_PORT_RCV_PKTS:
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800954 ret = (crp->cr_psrcvpktscount) ?
955 ipath_read_creg32(dev->dd, crp->cr_psrcvpktscount) :
956 dev->ipath_rpkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800957 break;
958 case IB_PMA_PORT_XMIT_WAIT:
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800959 ret = (crp->cr_psxmitwaitcount) ?
960 ipath_read_creg32(dev->dd, crp->cr_psxmitwaitcount) :
961 dev->ipath_xmit_wait;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800962 break;
963 default:
964 ret = 0;
965 }
966
967 return ret;
968}
969
Or Gerlitz6aea2132011-07-05 15:46:29 +0000970static int recv_pma_get_portsamplesresult(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800971 struct ib_device *ibdev)
972{
973 struct ib_pma_portsamplesresult *p =
974 (struct ib_pma_portsamplesresult *)pmp->data;
975 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800976 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
977 u8 status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800978 int i;
979
980 memset(pmp->data, 0, sizeof(pmp->data));
981 p->tag = cpu_to_be16(dev->pma_tag);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800982 if (crp->cr_psstat)
983 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
984 else
985 status = dev->pma_sample_status;
986 p->sample_status = cpu_to_be16(status);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800987 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800988 p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
989 cpu_to_be32(
990 get_counter(dev, crp, dev->pma_counter_select[i]));
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800991
992 return reply((struct ib_smp *) pmp);
993}
994
Or Gerlitz6aea2132011-07-05 15:46:29 +0000995static int recv_pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800996 struct ib_device *ibdev)
997{
998 struct ib_pma_portsamplesresult_ext *p =
999 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1000 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001001 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
1002 u8 status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001003 int i;
1004
1005 memset(pmp->data, 0, sizeof(pmp->data));
1006 p->tag = cpu_to_be16(dev->pma_tag);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001007 if (crp->cr_psstat)
1008 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1009 else
1010 status = dev->pma_sample_status;
1011 p->sample_status = cpu_to_be16(status);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001012 /* 64 bits */
Harvey Harrison9c3da092009-01-17 17:11:57 -08001013 p->extended_width = cpu_to_be32(0x80000000);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001014 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001015 p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
1016 cpu_to_be64(
1017 get_counter(dev, crp, dev->pma_counter_select[i]));
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001018
1019 return reply((struct ib_smp *) pmp);
1020}
1021
Or Gerlitz6aea2132011-07-05 15:46:29 +00001022static int recv_pma_get_portcounters(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001023 struct ib_device *ibdev, u8 port)
1024{
1025 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1026 pmp->data;
1027 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001028 struct ipath_verbs_counters cntrs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001029 u8 port_select = p->port_select;
1030
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001031 ipath_get_counters(dev->dd, &cntrs);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001032
1033 /* Adjust counters for any resets done. */
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001034 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001035 cntrs.link_error_recovery_counter -=
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001036 dev->z_link_error_recovery_counter;
1037 cntrs.link_downed_counter -= dev->z_link_downed_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001038 cntrs.port_rcv_errors += dev->rcv_errors;
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001039 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1040 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1041 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1042 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1043 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1044 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1045 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001046 cntrs.local_link_integrity_errors -=
1047 dev->z_local_link_integrity_errors;
1048 cntrs.excessive_buffer_overrun_errors -=
1049 dev->z_excessive_buffer_overrun_errors;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001050 cntrs.vl15_dropped -= dev->z_vl15_dropped;
1051 cntrs.vl15_dropped += dev->n_vl15_dropped;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001052
1053 memset(pmp->data, 0, sizeof(pmp->data));
1054
1055 p->port_select = port_select;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001056 if (pmp->mad_hdr.attr_mod != 0 ||
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001057 (port_select != port && port_select != 0xFF))
Or Gerlitz6aea2132011-07-05 15:46:29 +00001058 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001059
1060 if (cntrs.symbol_error_counter > 0xFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001061 p->symbol_error_counter = cpu_to_be16(0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001062 else
1063 p->symbol_error_counter =
1064 cpu_to_be16((u16)cntrs.symbol_error_counter);
1065 if (cntrs.link_error_recovery_counter > 0xFFUL)
1066 p->link_error_recovery_counter = 0xFF;
1067 else
1068 p->link_error_recovery_counter =
1069 (u8)cntrs.link_error_recovery_counter;
1070 if (cntrs.link_downed_counter > 0xFFUL)
1071 p->link_downed_counter = 0xFF;
1072 else
1073 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1074 if (cntrs.port_rcv_errors > 0xFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001075 p->port_rcv_errors = cpu_to_be16(0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001076 else
1077 p->port_rcv_errors =
1078 cpu_to_be16((u16) cntrs.port_rcv_errors);
1079 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001080 p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001081 else
1082 p->port_rcv_remphys_errors =
1083 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1084 if (cntrs.port_xmit_discards > 0xFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001085 p->port_xmit_discards = cpu_to_be16(0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001086 else
1087 p->port_xmit_discards =
1088 cpu_to_be16((u16)cntrs.port_xmit_discards);
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001089 if (cntrs.local_link_integrity_errors > 0xFUL)
1090 cntrs.local_link_integrity_errors = 0xFUL;
1091 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1092 cntrs.excessive_buffer_overrun_errors = 0xFUL;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001093 p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001094 cntrs.excessive_buffer_overrun_errors;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001095 if (cntrs.vl15_dropped > 0xFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001096 p->vl15_dropped = cpu_to_be16(0xFFFF);
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001097 else
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001098 p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001099 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001100 p->port_xmit_data = cpu_to_be32(0xFFFFFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001101 else
1102 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1103 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001104 p->port_rcv_data = cpu_to_be32(0xFFFFFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001105 else
1106 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1107 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001108 p->port_xmit_packets = cpu_to_be32(0xFFFFFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001109 else
1110 p->port_xmit_packets =
1111 cpu_to_be32((u32)cntrs.port_xmit_packets);
1112 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
Harvey Harrison9c3da092009-01-17 17:11:57 -08001113 p->port_rcv_packets = cpu_to_be32(0xFFFFFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001114 else
1115 p->port_rcv_packets =
1116 cpu_to_be32((u32) cntrs.port_rcv_packets);
1117
1118 return reply((struct ib_smp *) pmp);
1119}
1120
Or Gerlitz6aea2132011-07-05 15:46:29 +00001121static int recv_pma_get_portcounters_ext(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001122 struct ib_device *ibdev, u8 port)
1123{
1124 struct ib_pma_portcounters_ext *p =
1125 (struct ib_pma_portcounters_ext *)pmp->data;
1126 struct ipath_ibdev *dev = to_idev(ibdev);
1127 u64 swords, rwords, spkts, rpkts, xwait;
1128 u8 port_select = p->port_select;
1129
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001130 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1131 &rpkts, &xwait);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001132
1133 /* Adjust counters for any resets done. */
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001134 swords -= dev->z_port_xmit_data;
1135 rwords -= dev->z_port_rcv_data;
1136 spkts -= dev->z_port_xmit_packets;
1137 rpkts -= dev->z_port_rcv_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001138
1139 memset(pmp->data, 0, sizeof(pmp->data));
1140
1141 p->port_select = port_select;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001142 if (pmp->mad_hdr.attr_mod != 0 ||
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001143 (port_select != port && port_select != 0xFF))
Or Gerlitz6aea2132011-07-05 15:46:29 +00001144 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001145
1146 p->port_xmit_data = cpu_to_be64(swords);
1147 p->port_rcv_data = cpu_to_be64(rwords);
1148 p->port_xmit_packets = cpu_to_be64(spkts);
1149 p->port_rcv_packets = cpu_to_be64(rpkts);
1150 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1151 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1152 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1153 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1154
1155 return reply((struct ib_smp *) pmp);
1156}
1157
Or Gerlitz6aea2132011-07-05 15:46:29 +00001158static int recv_pma_set_portcounters(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001159 struct ib_device *ibdev, u8 port)
1160{
1161 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1162 pmp->data;
1163 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001164 struct ipath_verbs_counters cntrs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001165
1166 /*
1167 * Since the HW doesn't support clearing counters, we save the
1168 * current count and subtract it from future responses.
1169 */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001170 ipath_get_counters(dev->dd, &cntrs);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001171
1172 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001173 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001174
1175 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001176 dev->z_link_error_recovery_counter =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001177 cntrs.link_error_recovery_counter;
1178
1179 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001180 dev->z_link_downed_counter = cntrs.link_downed_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001181
1182 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001183 dev->z_port_rcv_errors =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001184 cntrs.port_rcv_errors + dev->rcv_errors;
1185
1186 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001187 dev->z_port_rcv_remphys_errors =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001188 cntrs.port_rcv_remphys_errors;
1189
1190 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001191 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001192
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001193 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1194 dev->z_local_link_integrity_errors =
1195 cntrs.local_link_integrity_errors;
1196
1197 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1198 dev->z_excessive_buffer_overrun_errors =
1199 cntrs.excessive_buffer_overrun_errors;
1200
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001201 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001202 dev->n_vl15_dropped = 0;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001203 dev->z_vl15_dropped = cntrs.vl15_dropped;
1204 }
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001205
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001206 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001207 dev->z_port_xmit_data = cntrs.port_xmit_data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001208
1209 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001210 dev->z_port_rcv_data = cntrs.port_rcv_data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001211
1212 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001213 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001214
1215 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001216 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001217
1218 return recv_pma_get_portcounters(pmp, ibdev, port);
1219}
1220
Or Gerlitz6aea2132011-07-05 15:46:29 +00001221static int recv_pma_set_portcounters_ext(struct ib_pma_mad *pmp,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001222 struct ib_device *ibdev, u8 port)
1223{
1224 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1225 pmp->data;
1226 struct ipath_ibdev *dev = to_idev(ibdev);
1227 u64 swords, rwords, spkts, rpkts, xwait;
1228
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001229 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1230 &rpkts, &xwait);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001231
1232 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001233 dev->z_port_xmit_data = swords;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001234
1235 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001236 dev->z_port_rcv_data = rwords;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001237
1238 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001239 dev->z_port_xmit_packets = spkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001240
1241 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001242 dev->z_port_rcv_packets = rpkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001243
1244 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1245 dev->n_unicast_xmit = 0;
1246
1247 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1248 dev->n_unicast_rcv = 0;
1249
1250 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1251 dev->n_multicast_xmit = 0;
1252
1253 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1254 dev->n_multicast_rcv = 0;
1255
1256 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1257}
1258
1259static int process_subn(struct ib_device *ibdev, int mad_flags,
Ira Weinya97e2d82015-05-31 17:15:30 -04001260 u8 port_num, const struct ib_mad *in_mad,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001261 struct ib_mad *out_mad)
1262{
1263 struct ib_smp *smp = (struct ib_smp *)out_mad;
1264 struct ipath_ibdev *dev = to_idev(ibdev);
1265 int ret;
1266
1267 *out_mad = *in_mad;
1268 if (smp->class_version != 1) {
1269 smp->status |= IB_SMP_UNSUP_VERSION;
1270 ret = reply(smp);
1271 goto bail;
1272 }
1273
1274 /* Is the mkey in the process of expiring? */
Robert P. J. Dayb3b81282008-04-16 21:09:28 -07001275 if (dev->mkey_lease_timeout &&
1276 time_after_eq(jiffies, dev->mkey_lease_timeout)) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001277 /* Clear timeout and mkey protection field. */
1278 dev->mkey_lease_timeout = 0;
Ralph Campbell542869a2007-09-13 11:42:52 -07001279 dev->mkeyprot = 0;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001280 }
1281
1282 /*
1283 * M_Key checking depends on
1284 * Portinfo:M_Key_protect_bits
1285 */
1286 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1287 dev->mkey != smp->mkey &&
1288 (smp->method == IB_MGMT_METHOD_SET ||
1289 (smp->method == IB_MGMT_METHOD_GET &&
Ralph Campbell542869a2007-09-13 11:42:52 -07001290 dev->mkeyprot >= 2))) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001291 if (dev->mkey_violations != 0xFFFF)
1292 ++dev->mkey_violations;
1293 if (dev->mkey_lease_timeout ||
1294 dev->mkey_lease_period == 0) {
1295 ret = IB_MAD_RESULT_SUCCESS |
1296 IB_MAD_RESULT_CONSUMED;
1297 goto bail;
1298 }
1299 dev->mkey_lease_timeout = jiffies +
1300 dev->mkey_lease_period * HZ;
1301 /* Future: Generate a trap notice. */
1302 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1303 goto bail;
1304 } else if (dev->mkey_lease_timeout)
1305 dev->mkey_lease_timeout = 0;
1306
1307 switch (smp->method) {
1308 case IB_MGMT_METHOD_GET:
1309 switch (smp->attr_id) {
1310 case IB_SMP_ATTR_NODE_DESC:
1311 ret = recv_subn_get_nodedescription(smp, ibdev);
1312 goto bail;
1313 case IB_SMP_ATTR_NODE_INFO:
1314 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1315 goto bail;
1316 case IB_SMP_ATTR_GUID_INFO:
1317 ret = recv_subn_get_guidinfo(smp, ibdev);
1318 goto bail;
1319 case IB_SMP_ATTR_PORT_INFO:
1320 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1321 goto bail;
1322 case IB_SMP_ATTR_PKEY_TABLE:
1323 ret = recv_subn_get_pkeytable(smp, ibdev);
1324 goto bail;
1325 case IB_SMP_ATTR_SM_INFO:
1326 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1327 ret = IB_MAD_RESULT_SUCCESS |
1328 IB_MAD_RESULT_CONSUMED;
1329 goto bail;
1330 }
1331 if (dev->port_cap_flags & IB_PORT_SM) {
1332 ret = IB_MAD_RESULT_SUCCESS;
1333 goto bail;
1334 }
1335 /* FALLTHROUGH */
1336 default:
1337 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1338 ret = reply(smp);
1339 goto bail;
1340 }
1341
1342 case IB_MGMT_METHOD_SET:
1343 switch (smp->attr_id) {
1344 case IB_SMP_ATTR_GUID_INFO:
1345 ret = recv_subn_set_guidinfo(smp, ibdev);
1346 goto bail;
1347 case IB_SMP_ATTR_PORT_INFO:
1348 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1349 goto bail;
1350 case IB_SMP_ATTR_PKEY_TABLE:
Or Gerlitze3164532014-07-08 12:45:10 +03001351 ret = recv_subn_set_pkeytable(smp, ibdev, port_num);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001352 goto bail;
1353 case IB_SMP_ATTR_SM_INFO:
1354 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1355 ret = IB_MAD_RESULT_SUCCESS |
1356 IB_MAD_RESULT_CONSUMED;
1357 goto bail;
1358 }
1359 if (dev->port_cap_flags & IB_PORT_SM) {
1360 ret = IB_MAD_RESULT_SUCCESS;
1361 goto bail;
1362 }
1363 /* FALLTHROUGH */
1364 default:
1365 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1366 ret = reply(smp);
1367 goto bail;
1368 }
1369
Ralph Campbell27676a32008-06-06 11:23:29 -07001370 case IB_MGMT_METHOD_TRAP:
1371 case IB_MGMT_METHOD_REPORT:
1372 case IB_MGMT_METHOD_REPORT_RESP:
1373 case IB_MGMT_METHOD_TRAP_REPRESS:
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001374 case IB_MGMT_METHOD_GET_RESP:
1375 /*
1376 * The ib_mad module will call us to process responses
1377 * before checking for other consumers.
1378 * Just tell the caller to process it normally.
1379 */
Ralph Campbellf9b40352007-10-23 15:07:41 -07001380 ret = IB_MAD_RESULT_SUCCESS;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001381 goto bail;
1382 default:
1383 smp->status |= IB_SMP_UNSUP_METHOD;
1384 ret = reply(smp);
1385 }
1386
1387bail:
1388 return ret;
1389}
1390
1391static int process_perf(struct ib_device *ibdev, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -04001392 const struct ib_mad *in_mad,
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001393 struct ib_mad *out_mad)
1394{
Or Gerlitz6aea2132011-07-05 15:46:29 +00001395 struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001396 int ret;
1397
1398 *out_mad = *in_mad;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001399 if (pmp->mad_hdr.class_version != 1) {
1400 pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001401 ret = reply((struct ib_smp *) pmp);
1402 goto bail;
1403 }
1404
Or Gerlitz6aea2132011-07-05 15:46:29 +00001405 switch (pmp->mad_hdr.method) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001406 case IB_MGMT_METHOD_GET:
Or Gerlitz6aea2132011-07-05 15:46:29 +00001407 switch (pmp->mad_hdr.attr_id) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001408 case IB_PMA_CLASS_PORT_INFO:
1409 ret = recv_pma_get_classportinfo(pmp);
1410 goto bail;
1411 case IB_PMA_PORT_SAMPLES_CONTROL:
1412 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1413 port_num);
1414 goto bail;
1415 case IB_PMA_PORT_SAMPLES_RESULT:
1416 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1417 goto bail;
1418 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1419 ret = recv_pma_get_portsamplesresult_ext(pmp,
1420 ibdev);
1421 goto bail;
1422 case IB_PMA_PORT_COUNTERS:
1423 ret = recv_pma_get_portcounters(pmp, ibdev,
1424 port_num);
1425 goto bail;
1426 case IB_PMA_PORT_COUNTERS_EXT:
1427 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1428 port_num);
1429 goto bail;
1430 default:
Or Gerlitz6aea2132011-07-05 15:46:29 +00001431 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001432 ret = reply((struct ib_smp *) pmp);
1433 goto bail;
1434 }
1435
1436 case IB_MGMT_METHOD_SET:
Or Gerlitz6aea2132011-07-05 15:46:29 +00001437 switch (pmp->mad_hdr.attr_id) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001438 case IB_PMA_PORT_SAMPLES_CONTROL:
1439 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1440 port_num);
1441 goto bail;
1442 case IB_PMA_PORT_COUNTERS:
1443 ret = recv_pma_set_portcounters(pmp, ibdev,
1444 port_num);
1445 goto bail;
1446 case IB_PMA_PORT_COUNTERS_EXT:
1447 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1448 port_num);
1449 goto bail;
1450 default:
Or Gerlitz6aea2132011-07-05 15:46:29 +00001451 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001452 ret = reply((struct ib_smp *) pmp);
1453 goto bail;
1454 }
1455
1456 case IB_MGMT_METHOD_GET_RESP:
1457 /*
1458 * The ib_mad module will call us to process responses
1459 * before checking for other consumers.
1460 * Just tell the caller to process it normally.
1461 */
Ralph Campbellf9b40352007-10-23 15:07:41 -07001462 ret = IB_MAD_RESULT_SUCCESS;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001463 goto bail;
1464 default:
Or Gerlitz6aea2132011-07-05 15:46:29 +00001465 pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001466 ret = reply((struct ib_smp *) pmp);
1467 }
1468
1469bail:
1470 return ret;
1471}
1472
1473/**
1474 * ipath_process_mad - process an incoming MAD packet
1475 * @ibdev: the infiniband device this packet came in on
1476 * @mad_flags: MAD flags
1477 * @port_num: the port number this packet came in on
1478 * @in_wc: the work completion entry for this packet
1479 * @in_grh: the global route header for this packet
1480 * @in_mad: the incoming MAD
1481 * @out_mad: any outgoing MAD reply
1482 *
1483 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1484 * interested in processing.
1485 *
1486 * Note that the verbs framework has already done the MAD sanity checks,
1487 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1488 * MADs.
1489 *
1490 * This is called by the ib_mad module.
1491 */
1492int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -04001493 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -04001494 const struct ib_mad_hdr *in, size_t in_mad_size,
1495 struct ib_mad_hdr *out, size_t *out_mad_size,
1496 u16 *out_mad_pkey_index)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001497{
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001498 int ret;
Ira Weiny4cd7c942015-06-06 14:38:31 -04001499 const struct ib_mad *in_mad = (const struct ib_mad *)in;
1500 struct ib_mad *out_mad = (struct ib_mad *)out;
1501
1502 BUG_ON(in_mad_size != sizeof(*in_mad) ||
1503 *out_mad_size != sizeof(*out_mad));
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001504
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001505 switch (in_mad->mad_hdr.mgmt_class) {
1506 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1507 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1508 ret = process_subn(ibdev, mad_flags, port_num,
1509 in_mad, out_mad);
1510 goto bail;
1511 case IB_MGMT_CLASS_PERF_MGMT:
1512 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1513 goto bail;
1514 default:
1515 ret = IB_MAD_RESULT_SUCCESS;
1516 }
1517
1518bail:
1519 return ret;
1520}