blob: 7516a26089882b83c473fb4d696d09c34e640247 [file] [log] [blame]
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001/*
John Gregor87427da2007-06-11 10:21:14 -07002 * Copyright (c) 2006, 2007 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>
35
36#include "ipath_kernel.h"
37#include "ipath_verbs.h"
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -070038#include "ipath_common.h"
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080039
40#define IB_SMP_UNSUP_VERSION __constant_htons(0x0004)
41#define IB_SMP_UNSUP_METHOD __constant_htons(0x0008)
42#define IB_SMP_UNSUP_METH_ATTR __constant_htons(0x000C)
43#define IB_SMP_INVALID_FIELD __constant_htons(0x001C)
44
45static int reply(struct ib_smp *smp)
46{
47 /*
48 * The verbs framework will handle the directed/LID route
49 * packet changes.
50 */
51 smp->method = IB_MGMT_METHOD_GET_RESP;
52 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
53 smp->status |= IB_SMP_DIRECTION;
54 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
55}
56
57static int recv_subn_get_nodedescription(struct ib_smp *smp,
58 struct ib_device *ibdev)
59{
60 if (smp->attr_mod)
61 smp->status |= IB_SMP_INVALID_FIELD;
62
63 strncpy(smp->data, ibdev->node_desc, sizeof(smp->data));
64
65 return reply(smp);
66}
67
68struct nodeinfo {
69 u8 base_version;
70 u8 class_version;
71 u8 node_type;
72 u8 num_ports;
73 __be64 sys_guid;
74 __be64 node_guid;
75 __be64 port_guid;
76 __be16 partition_cap;
77 __be16 device_id;
78 __be32 revision;
79 u8 local_port_num;
80 u8 vendor_id[3];
81} __attribute__ ((packed));
82
83static int recv_subn_get_nodeinfo(struct ib_smp *smp,
84 struct ib_device *ibdev, u8 port)
85{
86 struct nodeinfo *nip = (struct nodeinfo *)&smp->data;
87 struct ipath_devdata *dd = to_idev(ibdev)->dd;
Bryan O'Sullivane8a88f02006-07-01 04:35:57 -070088 u32 vendor, majrev, minrev;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080089
Bryan O'Sullivan11b054fe2006-09-28 09:00:02 -070090 /* GUID 0 is illegal */
91 if (smp->attr_mod || (dd->ipath_guid == 0))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -080092 smp->status |= IB_SMP_INVALID_FIELD;
93
94 nip->base_version = 1;
95 nip->class_version = 1;
96 nip->node_type = 1; /* channel adapter */
97 /*
98 * XXX The num_ports value will need a layer function to get
99 * the value if we ever have more than one IB port on a chip.
100 * We will also need to get the GUID for the port.
101 */
102 nip->num_ports = ibdev->phys_port_cnt;
103 /* This is already in network order */
104 nip->sys_guid = to_idev(ibdev)->sys_image_guid;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700105 nip->node_guid = dd->ipath_guid;
Sean Heftyf41d2292007-06-28 19:16:20 -0700106 nip->port_guid = dd->ipath_guid;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700107 nip->partition_cap = cpu_to_be16(ipath_get_npkeys(dd));
108 nip->device_id = cpu_to_be16(dd->ipath_deviceid);
109 majrev = dd->ipath_majrev;
110 minrev = dd->ipath_minrev;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800111 nip->revision = cpu_to_be32((majrev << 16) | minrev);
112 nip->local_port_num = port;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700113 vendor = dd->ipath_vendorid;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800114 nip->vendor_id[0] = 0;
115 nip->vendor_id[1] = vendor >> 8;
116 nip->vendor_id[2] = vendor;
117
118 return reply(smp);
119}
120
121static int recv_subn_get_guidinfo(struct ib_smp *smp,
122 struct ib_device *ibdev)
123{
124 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
125 __be64 *p = (__be64 *) smp->data;
126
127 /* 32 blocks of 8 64-bit GUIDs per block */
128
129 memset(smp->data, 0, sizeof(smp->data));
130
131 /*
132 * We only support one GUID for now. If this changes, the
133 * portinfo.guid_cap field needs to be updated too.
134 */
Bryan O'Sullivan11b054fe2006-09-28 09:00:02 -0700135 if (startgx == 0) {
136 __be64 g = to_idev(ibdev)->dd->ipath_guid;
137 if (g == 0)
138 /* GUID 0 is illegal */
139 smp->status |= IB_SMP_INVALID_FIELD;
140 else
141 /* The first is a copy of the read-only HW GUID. */
142 *p = g;
143 } else
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800144 smp->status |= IB_SMP_INVALID_FIELD;
145
146 return reply(smp);
147}
148
Ralph Campbella51a2512008-04-16 21:09:24 -0700149static void set_link_width_enabled(struct ipath_devdata *dd, u32 w)
150{
151 (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, w);
152}
153
154static void set_link_speed_enabled(struct ipath_devdata *dd, u32 s)
155{
156 (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, s);
157}
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700158
159static int get_overrunthreshold(struct ipath_devdata *dd)
160{
161 return (dd->ipath_ibcctrl >>
162 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
163 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
164}
165
166/**
167 * set_overrunthreshold - set the overrun threshold
168 * @dd: the infinipath device
169 * @n: the new threshold
170 *
171 * Note that this will only take effect when the link state changes.
172 */
173static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
174{
175 unsigned v;
176
177 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
178 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
179 if (v != n) {
180 dd->ipath_ibcctrl &=
181 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
182 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
183 dd->ipath_ibcctrl |=
184 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
185 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
186 dd->ipath_ibcctrl);
187 }
188 return 0;
189}
190
191static int get_phyerrthreshold(struct ipath_devdata *dd)
192{
193 return (dd->ipath_ibcctrl >>
194 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
195 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
196}
197
198/**
199 * set_phyerrthreshold - set the physical error threshold
200 * @dd: the infinipath device
201 * @n: the new threshold
202 *
203 * Note that this will only take effect when the link state changes.
204 */
205static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
206{
207 unsigned v;
208
209 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
210 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
211 if (v != n) {
212 dd->ipath_ibcctrl &=
213 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
214 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
215 dd->ipath_ibcctrl |=
216 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
217 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
218 dd->ipath_ibcctrl);
219 }
220 return 0;
221}
222
223/**
224 * get_linkdowndefaultstate - get the default linkdown state
225 * @dd: the infinipath device
226 *
227 * Returns zero if the default is POLL, 1 if the default is SLEEP.
228 */
229static int get_linkdowndefaultstate(struct ipath_devdata *dd)
230{
231 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
232}
233
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800234static int recv_subn_get_portinfo(struct ib_smp *smp,
235 struct ib_device *ibdev, u8 port)
236{
237 struct ipath_ibdev *dev;
Ralph Campbella51a2512008-04-16 21:09:24 -0700238 struct ipath_devdata *dd;
Leonid Arshda2ab622006-06-17 20:37:36 -0700239 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800240 u16 lid;
241 u8 ibcstat;
242 u8 mtu;
243 int ret;
244
245 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
246 smp->status |= IB_SMP_INVALID_FIELD;
247 ret = reply(smp);
248 goto bail;
249 }
250
251 dev = to_idev(ibdev);
Ralph Campbella51a2512008-04-16 21:09:24 -0700252 dd = dev->dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800253
254 /* Clear all fields. Only set the non-zero fields. */
255 memset(smp->data, 0, sizeof(smp->data));
256
257 /* Only return the mkey if the protection field allows it. */
258 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
Ralph Campbell542869a2007-09-13 11:42:52 -0700259 dev->mkeyprot == 0)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800260 pip->mkey = dev->mkey;
261 pip->gid_prefix = dev->gid_prefix;
Ralph Campbella51a2512008-04-16 21:09:24 -0700262 lid = dd->ipath_lid;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800263 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
264 pip->sm_lid = cpu_to_be16(dev->sm_lid);
265 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
266 /* pip->diag_code; */
267 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
268 pip->local_port_num = port;
Ralph Campbella51a2512008-04-16 21:09:24 -0700269 pip->link_width_enabled = dd->ipath_link_width_enabled;
270 pip->link_width_supported = dd->ipath_link_width_supported;
271 pip->link_width_active = dd->ipath_link_width_active;
272 pip->linkspeed_portstate = dd->ipath_link_speed_supported << 4;
273 ibcstat = dd->ipath_lastibcstat;
274 /* map LinkState to IB portinfo values. */
275 pip->linkspeed_portstate |= ipath_ib_linkstate(dd, ibcstat) + 1;
276
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800277 pip->portphysstate_linkdown =
Ralph Campbella51a2512008-04-16 21:09:24 -0700278 (ipath_cvt_physportstate[ibcstat & dd->ibcs_lts_mask] << 4) |
279 (get_linkdowndefaultstate(dd) ? 1 : 2);
280 pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dd->ipath_lmc;
281 pip->linkspeedactive_enabled = (dd->ipath_link_speed_active << 4) |
282 dd->ipath_link_speed_enabled;
283 switch (dd->ipath_ibmtu) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800284 case 4096:
285 mtu = IB_MTU_4096;
286 break;
287 case 2048:
288 mtu = IB_MTU_2048;
289 break;
290 case 1024:
291 mtu = IB_MTU_1024;
292 break;
293 case 512:
294 mtu = IB_MTU_512;
295 break;
296 case 256:
297 mtu = IB_MTU_256;
298 break;
299 default: /* oops, something is wrong */
300 mtu = IB_MTU_2048;
301 break;
302 }
303 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
304 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
305 pip->vl_high_limit = dev->vl_high_limit;
306 /* pip->vl_arb_high_cap; // only one VL */
307 /* pip->vl_arb_low_cap; // only one VL */
308 /* InitTypeReply = 0 */
Dave Olson826d8012008-04-16 21:01:12 -0700309 /* our mtu cap depends on whether 4K MTU enabled or not */
310 pip->inittypereply_mtucap = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
311 /* HCAs ignore VLStallCount and HOQLife */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800312 /* pip->vlstallcnt_hoqlife; */
313 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
314 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
315 /* P_KeyViolations are counted by hardware. */
316 pip->pkey_violations =
Ralph Campbella51a2512008-04-16 21:09:24 -0700317 cpu_to_be16((ipath_get_cr_errpkey(dd) -
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -0700318 dev->z_pkey_violations) & 0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800319 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
320 /* Only the hardware GUID is supported for now */
321 pip->guid_cap = 1;
322 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
323 /* 32.768 usec. response time (guessing) */
324 pip->resv_resptimevalue = 3;
325 pip->localphyerrors_overrunerrors =
Ralph Campbella51a2512008-04-16 21:09:24 -0700326 (get_phyerrthreshold(dd) << 4) |
327 get_overrunthreshold(dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800328 /* pip->max_credit_hint; */
Ralph Campbella51a2512008-04-16 21:09:24 -0700329 if (dev->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
330 u32 v;
331
332 v = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LINKLATENCY);
333 pip->link_roundtrip_latency[0] = v >> 16;
334 pip->link_roundtrip_latency[1] = v >> 8;
335 pip->link_roundtrip_latency[2] = v;
336 }
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800337
338 ret = reply(smp);
339
340bail:
341 return ret;
342}
343
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700344/**
345 * get_pkeys - return the PKEY table for port 0
346 * @dd: the infinipath device
347 * @pkeys: the pkey table is placed here
348 */
349static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
350{
351 struct ipath_portdata *pd = dd->ipath_pd[0];
352
353 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
354
355 return 0;
356}
357
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800358static int recv_subn_get_pkeytable(struct ib_smp *smp,
359 struct ib_device *ibdev)
360{
361 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
362 u16 *p = (u16 *) smp->data;
363 __be16 *q = (__be16 *) smp->data;
364
365 /* 64 blocks of 32 16-bit P_Key entries */
366
367 memset(smp->data, 0, sizeof(smp->data));
368 if (startpx == 0) {
369 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700370 unsigned i, n = ipath_get_npkeys(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800371
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700372 get_pkeys(dev->dd, p);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800373
374 for (i = 0; i < n; i++)
375 q[i] = cpu_to_be16(p[i]);
376 } else
377 smp->status |= IB_SMP_INVALID_FIELD;
378
379 return reply(smp);
380}
381
382static int recv_subn_set_guidinfo(struct ib_smp *smp,
383 struct ib_device *ibdev)
384{
385 /* The only GUID we support is the first read-only entry. */
386 return recv_subn_get_guidinfo(smp, ibdev);
387}
388
389/**
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700390 * set_linkdowndefaultstate - set the default linkdown state
391 * @dd: the infinipath device
392 * @sleep: the new state
393 *
394 * Note that this will only take effect when the link state changes.
395 */
396static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
397{
398 if (sleep)
399 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
400 else
401 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
402 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
403 dd->ipath_ibcctrl);
404 return 0;
405}
406
407/**
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800408 * recv_subn_set_portinfo - set port information
409 * @smp: the incoming SM packet
410 * @ibdev: the infiniband device
411 * @port: the port on the device
412 *
413 * Set Portinfo (see ch. 14.2.5.6).
414 */
415static int recv_subn_set_portinfo(struct ib_smp *smp,
416 struct ib_device *ibdev, u8 port)
417{
Leonid Arshda2ab622006-06-17 20:37:36 -0700418 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800419 struct ib_event event;
420 struct ipath_ibdev *dev;
Ralph Campbell542869a2007-09-13 11:42:52 -0700421 struct ipath_devdata *dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800422 char clientrereg = 0;
423 u16 lid, smlid;
424 u8 lwe;
425 u8 lse;
426 u8 state;
427 u16 lstate;
428 u32 mtu;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700429 int ret, ore;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800430
431 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
432 goto err;
433
434 dev = to_idev(ibdev);
Ralph Campbell542869a2007-09-13 11:42:52 -0700435 dd = dev->dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800436 event.device = ibdev;
437 event.element.port_num = port;
438
439 dev->mkey = pip->mkey;
440 dev->gid_prefix = pip->gid_prefix;
441 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
442
443 lid = be16_to_cpu(pip->lid);
Ralph Campbell542869a2007-09-13 11:42:52 -0700444 if (dd->ipath_lid != lid ||
445 dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800446 /* Must be a valid unicast LID address. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700447 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800448 goto err;
Ralph Campbell542869a2007-09-13 11:42:52 -0700449 ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800450 event.event = IB_EVENT_LID_CHANGE;
451 ib_dispatch_event(&event);
452 }
453
454 smlid = be16_to_cpu(pip->sm_lid);
455 if (smlid != dev->sm_lid) {
456 /* Must be a valid unicast LID address. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700457 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800458 goto err;
459 dev->sm_lid = smlid;
460 event.event = IB_EVENT_SM_CHANGE;
461 ib_dispatch_event(&event);
462 }
463
Ralph Campbella51a2512008-04-16 21:09:24 -0700464 /* Allow 1x or 4x to be set (see 14.2.6.6). */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800465 lwe = pip->link_width_enabled;
Ralph Campbella51a2512008-04-16 21:09:24 -0700466 if (lwe) {
467 if (lwe == 0xFF)
468 lwe = dd->ipath_link_width_supported;
469 else if (lwe >= 16 || (lwe & ~dd->ipath_link_width_supported))
470 goto err;
471 set_link_width_enabled(dd, lwe);
472 }
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800473
Ralph Campbella51a2512008-04-16 21:09:24 -0700474 /* Allow 2.5 or 5.0 Gbs. */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800475 lse = pip->linkspeedactive_enabled & 0xF;
Ralph Campbella51a2512008-04-16 21:09:24 -0700476 if (lse) {
477 if (lse == 15)
478 lse = dd->ipath_link_speed_supported;
479 else if (lse >= 8 || (lse & ~dd->ipath_link_speed_supported))
480 goto err;
481 set_link_speed_enabled(dd, lse);
482 }
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800483
484 /* Set link down default state. */
485 switch (pip->portphysstate_linkdown & 0xF) {
486 case 0: /* NOP */
487 break;
488 case 1: /* SLEEP */
Ralph Campbell542869a2007-09-13 11:42:52 -0700489 if (set_linkdowndefaultstate(dd, 1))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800490 goto err;
491 break;
492 case 2: /* POLL */
Ralph Campbell542869a2007-09-13 11:42:52 -0700493 if (set_linkdowndefaultstate(dd, 0))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800494 goto err;
495 break;
496 default:
497 goto err;
498 }
499
Ralph Campbell542869a2007-09-13 11:42:52 -0700500 dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800501 dev->vl_high_limit = pip->vl_high_limit;
502
503 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
504 case IB_MTU_256:
505 mtu = 256;
506 break;
507 case IB_MTU_512:
508 mtu = 512;
509 break;
510 case IB_MTU_1024:
511 mtu = 1024;
512 break;
513 case IB_MTU_2048:
514 mtu = 2048;
515 break;
516 case IB_MTU_4096:
Dave Olson826d8012008-04-16 21:01:12 -0700517 if (!ipath_mtu4096)
518 goto err;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800519 mtu = 4096;
520 break;
521 default:
522 /* XXX We have already partially updated our state! */
523 goto err;
524 }
Ralph Campbell542869a2007-09-13 11:42:52 -0700525 ipath_set_mtu(dd, mtu);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800526
527 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
528
529 /* We only support VL0 */
530 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
531 goto err;
532
533 if (pip->mkey_violations == 0)
534 dev->mkey_violations = 0;
535
536 /*
537 * Hardware counter can't be reset so snapshot and subtract
538 * later.
539 */
540 if (pip->pkey_violations == 0)
Ralph Campbell542869a2007-09-13 11:42:52 -0700541 dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800542
543 if (pip->qkey_violations == 0)
544 dev->qkey_violations = 0;
545
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700546 ore = pip->localphyerrors_overrunerrors;
Ralph Campbell542869a2007-09-13 11:42:52 -0700547 if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800548 goto err;
549
Ralph Campbell542869a2007-09-13 11:42:52 -0700550 if (set_overrunthreshold(dd, (ore & 0xF)))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800551 goto err;
552
553 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
554
555 if (pip->clientrereg_resv_subnetto & 0x80) {
556 clientrereg = 1;
Roland Dreier6eddb5c2006-06-17 20:37:37 -0700557 event.event = IB_EVENT_CLIENT_REREGISTER;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800558 ib_dispatch_event(&event);
559 }
560
561 /*
562 * Do the port state change now that the other link parameters
563 * have been set.
564 * Changing the port physical state only makes sense if the link
565 * is down or is being set to down.
566 */
567 state = pip->linkspeed_portstate & 0xF;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800568 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
569 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
570 goto err;
571
572 /*
573 * Only state changes of DOWN, ARM, and ACTIVE are valid
574 * and must be in the correct state to take effect (see 7.2.6).
575 */
576 switch (state) {
577 case IB_PORT_NOP:
578 if (lstate == 0)
579 break;
580 /* FALLTHROUGH */
581 case IB_PORT_DOWN:
582 if (lstate == 0)
Ralph Campbell140277e2007-12-14 01:53:56 -0800583 lstate = IPATH_IB_LINKDOWN_ONLY;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800584 else if (lstate == 1)
585 lstate = IPATH_IB_LINKDOWN_SLEEP;
586 else if (lstate == 2)
587 lstate = IPATH_IB_LINKDOWN;
588 else if (lstate == 3)
589 lstate = IPATH_IB_LINKDOWN_DISABLE;
590 else
591 goto err;
Ralph Campbell542869a2007-09-13 11:42:52 -0700592 ipath_set_linkstate(dd, lstate);
Ralph Campbell140277e2007-12-14 01:53:56 -0800593 ipath_wait_linkstate(dd, IPATH_LINKINIT | IPATH_LINKARMED |
594 IPATH_LINKACTIVE, 1000);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800595 break;
596 case IB_PORT_ARMED:
Ralph Campbell542869a2007-09-13 11:42:52 -0700597 ipath_set_linkstate(dd, IPATH_IB_LINKARM);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800598 break;
599 case IB_PORT_ACTIVE:
Ralph Campbell542869a2007-09-13 11:42:52 -0700600 ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800601 break;
602 default:
603 /* XXX We have already partially updated our state! */
604 goto err;
605 }
606
607 ret = recv_subn_get_portinfo(smp, ibdev, port);
608
609 if (clientrereg)
610 pip->clientrereg_resv_subnetto |= 0x80;
611
612 goto done;
613
614err:
615 smp->status |= IB_SMP_INVALID_FIELD;
616 ret = recv_subn_get_portinfo(smp, ibdev, port);
617
618done:
619 return ret;
620}
621
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700622/**
623 * rm_pkey - decrecment the reference count for the given PKEY
624 * @dd: the infinipath device
625 * @key: the PKEY index
626 *
627 * Return true if this was the last reference and the hardware table entry
628 * needs to be changed.
629 */
630static int rm_pkey(struct ipath_devdata *dd, u16 key)
631{
632 int i;
633 int ret;
634
635 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
636 if (dd->ipath_pkeys[i] != key)
637 continue;
638 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
639 dd->ipath_pkeys[i] = 0;
640 ret = 1;
641 goto bail;
642 }
643 break;
644 }
645
646 ret = 0;
647
648bail:
649 return ret;
650}
651
652/**
653 * add_pkey - add the given PKEY to the hardware table
654 * @dd: the infinipath device
655 * @key: the PKEY
656 *
657 * Return an error code if unable to add the entry, zero if no change,
658 * or 1 if the hardware PKEY register needs to be updated.
659 */
660static int add_pkey(struct ipath_devdata *dd, u16 key)
661{
662 int i;
663 u16 lkey = key & 0x7FFF;
664 int any = 0;
665 int ret;
666
667 if (lkey == 0x7FFF) {
668 ret = 0;
669 goto bail;
670 }
671
672 /* Look for an empty slot or a matching PKEY. */
673 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
674 if (!dd->ipath_pkeys[i]) {
675 any++;
676 continue;
677 }
678 /* If it matches exactly, try to increment the ref count */
679 if (dd->ipath_pkeys[i] == key) {
680 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
681 ret = 0;
682 goto bail;
683 }
684 /* Lost the race. Look for an empty slot below. */
685 atomic_dec(&dd->ipath_pkeyrefs[i]);
686 any++;
687 }
688 /*
689 * It makes no sense to have both the limited and unlimited
690 * PKEY set at the same time since the unlimited one will
691 * disable the limited one.
692 */
693 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
694 ret = -EEXIST;
695 goto bail;
696 }
697 }
698 if (!any) {
699 ret = -EBUSY;
700 goto bail;
701 }
702 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
703 if (!dd->ipath_pkeys[i] &&
704 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
705 /* for ipathstats, etc. */
706 ipath_stats.sps_pkeys[i] = lkey;
707 dd->ipath_pkeys[i] = key;
708 ret = 1;
709 goto bail;
710 }
711 }
712 ret = -EBUSY;
713
714bail:
715 return ret;
716}
717
718/**
719 * set_pkeys - set the PKEY table for port 0
720 * @dd: the infinipath device
721 * @pkeys: the PKEY table
722 */
723static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
724{
725 struct ipath_portdata *pd;
726 int i;
727 int changed = 0;
728
729 pd = dd->ipath_pd[0];
730
731 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
732 u16 key = pkeys[i];
733 u16 okey = pd->port_pkeys[i];
734
735 if (key == okey)
736 continue;
737 /*
738 * The value of this PKEY table entry is changing.
739 * Remove the old entry in the hardware's array of PKEYs.
740 */
741 if (okey & 0x7FFF)
742 changed |= rm_pkey(dd, okey);
743 if (key & 0x7FFF) {
744 int ret = add_pkey(dd, key);
745
746 if (ret < 0)
747 key = 0;
748 else
749 changed |= ret;
750 }
751 pd->port_pkeys[i] = key;
752 }
753 if (changed) {
754 u64 pkey;
755
756 pkey = (u64) dd->ipath_pkeys[0] |
757 ((u64) dd->ipath_pkeys[1] << 16) |
758 ((u64) dd->ipath_pkeys[2] << 32) |
759 ((u64) dd->ipath_pkeys[3] << 48);
760 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
761 (unsigned long long) pkey);
762 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
763 pkey);
764 }
765 return 0;
766}
767
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800768static int recv_subn_set_pkeytable(struct ib_smp *smp,
769 struct ib_device *ibdev)
770{
771 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
772 __be16 *p = (__be16 *) smp->data;
773 u16 *q = (u16 *) smp->data;
774 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700775 unsigned i, n = ipath_get_npkeys(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800776
777 for (i = 0; i < n; i++)
778 q[i] = be16_to_cpu(p[i]);
779
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700780 if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800781 smp->status |= IB_SMP_INVALID_FIELD;
782
783 return recv_subn_get_pkeytable(smp, ibdev);
784}
785
786#define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
787#define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
788#define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
789#define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
790#define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
791#define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
792
793struct ib_perf {
794 u8 base_version;
795 u8 mgmt_class;
796 u8 class_version;
797 u8 method;
798 __be16 status;
799 __be16 unused;
800 __be64 tid;
801 __be16 attr_id;
802 __be16 resv;
803 __be32 attr_mod;
804 u8 reserved[40];
805 u8 data[192];
806} __attribute__ ((packed));
807
808struct ib_pma_classportinfo {
809 u8 base_version;
810 u8 class_version;
811 __be16 cap_mask;
812 u8 reserved[3];
813 u8 resp_time_value; /* only lower 5 bits */
814 union ib_gid redirect_gid;
815 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
816 __be16 redirect_lid;
817 __be16 redirect_pkey;
818 __be32 redirect_qp; /* only lower 24 bits */
819 __be32 redirect_qkey;
820 union ib_gid trap_gid;
821 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
822 __be16 trap_lid;
823 __be16 trap_pkey;
824 __be32 trap_hl_qp; /* 8, 24 bits respectively */
825 __be32 trap_qkey;
826} __attribute__ ((packed));
827
828struct ib_pma_portsamplescontrol {
829 u8 opcode;
830 u8 port_select;
831 u8 tick;
832 u8 counter_width; /* only lower 3 bits */
833 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
834 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
835 u8 sample_mechanisms;
836 u8 sample_status; /* only lower 2 bits */
837 __be64 option_mask;
838 __be64 vendor_mask;
839 __be32 sample_start;
840 __be32 sample_interval;
841 __be16 tag;
842 __be16 counter_select[15];
843} __attribute__ ((packed));
844
845struct ib_pma_portsamplesresult {
846 __be16 tag;
847 __be16 sample_status; /* only lower 2 bits */
848 __be32 counter[15];
849} __attribute__ ((packed));
850
851struct ib_pma_portsamplesresult_ext {
852 __be16 tag;
853 __be16 sample_status; /* only lower 2 bits */
854 __be32 extended_width; /* only upper 2 bits */
855 __be64 counter[15];
856} __attribute__ ((packed));
857
858struct ib_pma_portcounters {
859 u8 reserved;
860 u8 port_select;
861 __be16 counter_select;
862 __be16 symbol_error_counter;
863 u8 link_error_recovery_counter;
864 u8 link_downed_counter;
865 __be16 port_rcv_errors;
866 __be16 port_rcv_remphys_errors;
867 __be16 port_rcv_switch_relay_errors;
868 __be16 port_xmit_discards;
869 u8 port_xmit_constraint_errors;
870 u8 port_rcv_constraint_errors;
871 u8 reserved1;
872 u8 lli_ebor_errors; /* 4, 4, bits */
873 __be16 reserved2;
874 __be16 vl15_dropped;
875 __be32 port_xmit_data;
876 __be32 port_rcv_data;
877 __be32 port_xmit_packets;
878 __be32 port_rcv_packets;
879} __attribute__ ((packed));
880
881#define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
882#define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
883#define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
884#define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
885#define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
886#define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
Bryan O'Sullivanfba75202006-07-01 04:36:09 -0700887#define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
888#define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
889#define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800890#define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
891#define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
892#define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
893#define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
894
895struct ib_pma_portcounters_ext {
896 u8 reserved;
897 u8 port_select;
898 __be16 counter_select;
899 __be32 reserved1;
900 __be64 port_xmit_data;
901 __be64 port_rcv_data;
902 __be64 port_xmit_packets;
903 __be64 port_rcv_packets;
904 __be64 port_unicast_xmit_packets;
905 __be64 port_unicast_rcv_packets;
906 __be64 port_multicast_xmit_packets;
907 __be64 port_multicast_rcv_packets;
908} __attribute__ ((packed));
909
910#define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
911#define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
912#define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
913#define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
914#define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
915#define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
916#define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
917#define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
918
919static int recv_pma_get_classportinfo(struct ib_perf *pmp)
920{
921 struct ib_pma_classportinfo *p =
922 (struct ib_pma_classportinfo *)pmp->data;
923
924 memset(pmp->data, 0, sizeof(pmp->data));
925
926 if (pmp->attr_mod != 0)
927 pmp->status |= IB_SMP_INVALID_FIELD;
928
929 /* Indicate AllPortSelect is valid (only one port anyway) */
930 p->cap_mask = __constant_cpu_to_be16(1 << 8);
931 p->base_version = 1;
932 p->class_version = 1;
933 /*
934 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
935 * sec.
936 */
937 p->resp_time_value = 18;
938
939 return reply((struct ib_smp *) pmp);
940}
941
942/*
943 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
944 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
945 * We support 5 counters which only count the mandatory quantities.
946 */
947#define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
948#define COUNTER_MASK0_9 \
949 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
950 COUNTER_MASK(1, 1) | \
951 COUNTER_MASK(1, 2) | \
952 COUNTER_MASK(1, 3) | \
953 COUNTER_MASK(1, 4))
954
955static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
956 struct ib_device *ibdev, u8 port)
957{
958 struct ib_pma_portsamplescontrol *p =
959 (struct ib_pma_portsamplescontrol *)pmp->data;
960 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800961 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800962 unsigned long flags;
963 u8 port_select = p->port_select;
964
965 memset(pmp->data, 0, sizeof(pmp->data));
966
967 p->port_select = port_select;
968 if (pmp->attr_mod != 0 ||
969 (port_select != port && port_select != 0xFF))
970 pmp->status |= IB_SMP_INVALID_FIELD;
971 /*
972 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
973 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
974 * intervals are counted in ticks. Since we use Linux timers, that
975 * count in jiffies, we can't sample for less than 1000 ticks if HZ
Ralph Campbella51a2512008-04-16 21:09:24 -0700976 * == 1000 (4000 ticks if HZ is 250). link_speed_active returns 2 for
977 * DDR, 1 for SDR, set the tick to 1 for DDR, 0 for SDR on chips that
978 * have hardware support for delaying packets.
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800979 */
Ralph Campbella51a2512008-04-16 21:09:24 -0700980 if (crp->cr_psstat)
981 p->tick = dev->dd->ipath_link_speed_active - 1;
982 else
983 p->tick = 250; /* 1 usec. */
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800984 p->counter_width = 4; /* 32 bit counters */
985 p->counter_mask0_9 = COUNTER_MASK0_9;
986 spin_lock_irqsave(&dev->pending_lock, flags);
Ralph Campbell6c719ca2008-01-06 21:02:33 -0800987 if (crp->cr_psstat)
988 p->sample_status = ipath_read_creg32(dev->dd, crp->cr_psstat);
989 else
990 p->sample_status = dev->pma_sample_status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800991 p->sample_start = cpu_to_be32(dev->pma_sample_start);
992 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
993 p->tag = cpu_to_be16(dev->pma_tag);
994 p->counter_select[0] = dev->pma_counter_select[0];
995 p->counter_select[1] = dev->pma_counter_select[1];
996 p->counter_select[2] = dev->pma_counter_select[2];
997 p->counter_select[3] = dev->pma_counter_select[3];
998 p->counter_select[4] = dev->pma_counter_select[4];
999 spin_unlock_irqrestore(&dev->pending_lock, flags);
1000
1001 return reply((struct ib_smp *) pmp);
1002}
1003
1004static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
1005 struct ib_device *ibdev, u8 port)
1006{
1007 struct ib_pma_portsamplescontrol *p =
1008 (struct ib_pma_portsamplescontrol *)pmp->data;
1009 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001010 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001011 unsigned long flags;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001012 u8 status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001013 int ret;
1014
1015 if (pmp->attr_mod != 0 ||
1016 (p->port_select != port && p->port_select != 0xFF)) {
1017 pmp->status |= IB_SMP_INVALID_FIELD;
1018 ret = reply((struct ib_smp *) pmp);
1019 goto bail;
1020 }
1021
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001022 spin_lock_irqsave(&dev->pending_lock, flags);
1023 if (crp->cr_psstat)
1024 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1025 else
1026 status = dev->pma_sample_status;
1027 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
1028 dev->pma_sample_start = be32_to_cpu(p->sample_start);
1029 dev->pma_sample_interval = be32_to_cpu(p->sample_interval);
1030 dev->pma_tag = be16_to_cpu(p->tag);
1031 dev->pma_counter_select[0] = p->counter_select[0];
1032 dev->pma_counter_select[1] = p->counter_select[1];
1033 dev->pma_counter_select[2] = p->counter_select[2];
1034 dev->pma_counter_select[3] = p->counter_select[3];
1035 dev->pma_counter_select[4] = p->counter_select[4];
1036 if (crp->cr_psstat) {
1037 ipath_write_creg(dev->dd, crp->cr_psinterval,
1038 dev->pma_sample_interval);
1039 ipath_write_creg(dev->dd, crp->cr_psstart,
1040 dev->pma_sample_start);
1041 } else
1042 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001043 }
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001044 spin_unlock_irqrestore(&dev->pending_lock, flags);
1045
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001046 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
1047
1048bail:
1049 return ret;
1050}
1051
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001052static u64 get_counter(struct ipath_ibdev *dev,
1053 struct ipath_cregs const *crp,
1054 __be16 sel)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001055{
1056 u64 ret;
1057
1058 switch (sel) {
1059 case IB_PMA_PORT_XMIT_DATA:
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001060 ret = (crp->cr_psxmitdatacount) ?
1061 ipath_read_creg32(dev->dd, crp->cr_psxmitdatacount) :
1062 dev->ipath_sword;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001063 break;
1064 case IB_PMA_PORT_RCV_DATA:
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001065 ret = (crp->cr_psrcvdatacount) ?
1066 ipath_read_creg32(dev->dd, crp->cr_psrcvdatacount) :
1067 dev->ipath_rword;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001068 break;
1069 case IB_PMA_PORT_XMIT_PKTS:
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001070 ret = (crp->cr_psxmitpktscount) ?
1071 ipath_read_creg32(dev->dd, crp->cr_psxmitpktscount) :
1072 dev->ipath_spkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001073 break;
1074 case IB_PMA_PORT_RCV_PKTS:
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001075 ret = (crp->cr_psrcvpktscount) ?
1076 ipath_read_creg32(dev->dd, crp->cr_psrcvpktscount) :
1077 dev->ipath_rpkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001078 break;
1079 case IB_PMA_PORT_XMIT_WAIT:
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001080 ret = (crp->cr_psxmitwaitcount) ?
1081 ipath_read_creg32(dev->dd, crp->cr_psxmitwaitcount) :
1082 dev->ipath_xmit_wait;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001083 break;
1084 default:
1085 ret = 0;
1086 }
1087
1088 return ret;
1089}
1090
1091static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
1092 struct ib_device *ibdev)
1093{
1094 struct ib_pma_portsamplesresult *p =
1095 (struct ib_pma_portsamplesresult *)pmp->data;
1096 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001097 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
1098 u8 status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001099 int i;
1100
1101 memset(pmp->data, 0, sizeof(pmp->data));
1102 p->tag = cpu_to_be16(dev->pma_tag);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001103 if (crp->cr_psstat)
1104 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1105 else
1106 status = dev->pma_sample_status;
1107 p->sample_status = cpu_to_be16(status);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001108 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001109 p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
1110 cpu_to_be32(
1111 get_counter(dev, crp, dev->pma_counter_select[i]));
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001112
1113 return reply((struct ib_smp *) pmp);
1114}
1115
1116static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
1117 struct ib_device *ibdev)
1118{
1119 struct ib_pma_portsamplesresult_ext *p =
1120 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1121 struct ipath_ibdev *dev = to_idev(ibdev);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001122 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
1123 u8 status;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001124 int i;
1125
1126 memset(pmp->data, 0, sizeof(pmp->data));
1127 p->tag = cpu_to_be16(dev->pma_tag);
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001128 if (crp->cr_psstat)
1129 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1130 else
1131 status = dev->pma_sample_status;
1132 p->sample_status = cpu_to_be16(status);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001133 /* 64 bits */
1134 p->extended_width = __constant_cpu_to_be32(0x80000000);
1135 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001136 p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
1137 cpu_to_be64(
1138 get_counter(dev, crp, dev->pma_counter_select[i]));
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001139
1140 return reply((struct ib_smp *) pmp);
1141}
1142
1143static int recv_pma_get_portcounters(struct ib_perf *pmp,
1144 struct ib_device *ibdev, u8 port)
1145{
1146 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1147 pmp->data;
1148 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001149 struct ipath_verbs_counters cntrs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001150 u8 port_select = p->port_select;
1151
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001152 ipath_get_counters(dev->dd, &cntrs);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001153
1154 /* Adjust counters for any resets done. */
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001155 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001156 cntrs.link_error_recovery_counter -=
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001157 dev->z_link_error_recovery_counter;
1158 cntrs.link_downed_counter -= dev->z_link_downed_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001159 cntrs.port_rcv_errors += dev->rcv_errors;
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001160 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1161 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1162 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1163 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1164 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1165 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1166 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001167 cntrs.local_link_integrity_errors -=
1168 dev->z_local_link_integrity_errors;
1169 cntrs.excessive_buffer_overrun_errors -=
1170 dev->z_excessive_buffer_overrun_errors;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001171 cntrs.vl15_dropped -= dev->z_vl15_dropped;
1172 cntrs.vl15_dropped += dev->n_vl15_dropped;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001173
1174 memset(pmp->data, 0, sizeof(pmp->data));
1175
1176 p->port_select = port_select;
1177 if (pmp->attr_mod != 0 ||
1178 (port_select != port && port_select != 0xFF))
1179 pmp->status |= IB_SMP_INVALID_FIELD;
1180
1181 if (cntrs.symbol_error_counter > 0xFFFFUL)
1182 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
1183 else
1184 p->symbol_error_counter =
1185 cpu_to_be16((u16)cntrs.symbol_error_counter);
1186 if (cntrs.link_error_recovery_counter > 0xFFUL)
1187 p->link_error_recovery_counter = 0xFF;
1188 else
1189 p->link_error_recovery_counter =
1190 (u8)cntrs.link_error_recovery_counter;
1191 if (cntrs.link_downed_counter > 0xFFUL)
1192 p->link_downed_counter = 0xFF;
1193 else
1194 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1195 if (cntrs.port_rcv_errors > 0xFFFFUL)
1196 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
1197 else
1198 p->port_rcv_errors =
1199 cpu_to_be16((u16) cntrs.port_rcv_errors);
1200 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1201 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
1202 else
1203 p->port_rcv_remphys_errors =
1204 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1205 if (cntrs.port_xmit_discards > 0xFFFFUL)
1206 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
1207 else
1208 p->port_xmit_discards =
1209 cpu_to_be16((u16)cntrs.port_xmit_discards);
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001210 if (cntrs.local_link_integrity_errors > 0xFUL)
1211 cntrs.local_link_integrity_errors = 0xFUL;
1212 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1213 cntrs.excessive_buffer_overrun_errors = 0xFUL;
1214 p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
1215 cntrs.excessive_buffer_overrun_errors;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001216 if (cntrs.vl15_dropped > 0xFFFFUL)
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001217 p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
1218 else
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001219 p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001220 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1221 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
1222 else
1223 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1224 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1225 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
1226 else
1227 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1228 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1229 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1230 else
1231 p->port_xmit_packets =
1232 cpu_to_be32((u32)cntrs.port_xmit_packets);
1233 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1234 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1235 else
1236 p->port_rcv_packets =
1237 cpu_to_be32((u32) cntrs.port_rcv_packets);
1238
1239 return reply((struct ib_smp *) pmp);
1240}
1241
1242static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
1243 struct ib_device *ibdev, u8 port)
1244{
1245 struct ib_pma_portcounters_ext *p =
1246 (struct ib_pma_portcounters_ext *)pmp->data;
1247 struct ipath_ibdev *dev = to_idev(ibdev);
1248 u64 swords, rwords, spkts, rpkts, xwait;
1249 u8 port_select = p->port_select;
1250
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001251 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1252 &rpkts, &xwait);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001253
1254 /* Adjust counters for any resets done. */
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001255 swords -= dev->z_port_xmit_data;
1256 rwords -= dev->z_port_rcv_data;
1257 spkts -= dev->z_port_xmit_packets;
1258 rpkts -= dev->z_port_rcv_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001259
1260 memset(pmp->data, 0, sizeof(pmp->data));
1261
1262 p->port_select = port_select;
1263 if (pmp->attr_mod != 0 ||
1264 (port_select != port && port_select != 0xFF))
1265 pmp->status |= IB_SMP_INVALID_FIELD;
1266
1267 p->port_xmit_data = cpu_to_be64(swords);
1268 p->port_rcv_data = cpu_to_be64(rwords);
1269 p->port_xmit_packets = cpu_to_be64(spkts);
1270 p->port_rcv_packets = cpu_to_be64(rpkts);
1271 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1272 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1273 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1274 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1275
1276 return reply((struct ib_smp *) pmp);
1277}
1278
1279static int recv_pma_set_portcounters(struct ib_perf *pmp,
1280 struct ib_device *ibdev, u8 port)
1281{
1282 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1283 pmp->data;
1284 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001285 struct ipath_verbs_counters cntrs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001286
1287 /*
1288 * Since the HW doesn't support clearing counters, we save the
1289 * current count and subtract it from future responses.
1290 */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001291 ipath_get_counters(dev->dd, &cntrs);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001292
1293 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001294 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001295
1296 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001297 dev->z_link_error_recovery_counter =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001298 cntrs.link_error_recovery_counter;
1299
1300 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001301 dev->z_link_downed_counter = cntrs.link_downed_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001302
1303 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001304 dev->z_port_rcv_errors =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001305 cntrs.port_rcv_errors + dev->rcv_errors;
1306
1307 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001308 dev->z_port_rcv_remphys_errors =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001309 cntrs.port_rcv_remphys_errors;
1310
1311 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001312 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001313
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001314 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1315 dev->z_local_link_integrity_errors =
1316 cntrs.local_link_integrity_errors;
1317
1318 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1319 dev->z_excessive_buffer_overrun_errors =
1320 cntrs.excessive_buffer_overrun_errors;
1321
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001322 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001323 dev->n_vl15_dropped = 0;
Ralph Campbell6c719ca2008-01-06 21:02:33 -08001324 dev->z_vl15_dropped = cntrs.vl15_dropped;
1325 }
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001326
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001327 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001328 dev->z_port_xmit_data = cntrs.port_xmit_data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001329
1330 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001331 dev->z_port_rcv_data = cntrs.port_rcv_data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001332
1333 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001334 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001335
1336 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001337 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001338
1339 return recv_pma_get_portcounters(pmp, ibdev, port);
1340}
1341
1342static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1343 struct ib_device *ibdev, u8 port)
1344{
1345 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1346 pmp->data;
1347 struct ipath_ibdev *dev = to_idev(ibdev);
1348 u64 swords, rwords, spkts, rpkts, xwait;
1349
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001350 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1351 &rpkts, &xwait);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001352
1353 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001354 dev->z_port_xmit_data = swords;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001355
1356 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001357 dev->z_port_rcv_data = rwords;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001358
1359 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001360 dev->z_port_xmit_packets = spkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001361
1362 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001363 dev->z_port_rcv_packets = rpkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001364
1365 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1366 dev->n_unicast_xmit = 0;
1367
1368 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1369 dev->n_unicast_rcv = 0;
1370
1371 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1372 dev->n_multicast_xmit = 0;
1373
1374 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1375 dev->n_multicast_rcv = 0;
1376
1377 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1378}
1379
1380static int process_subn(struct ib_device *ibdev, int mad_flags,
1381 u8 port_num, struct ib_mad *in_mad,
1382 struct ib_mad *out_mad)
1383{
1384 struct ib_smp *smp = (struct ib_smp *)out_mad;
1385 struct ipath_ibdev *dev = to_idev(ibdev);
1386 int ret;
1387
1388 *out_mad = *in_mad;
1389 if (smp->class_version != 1) {
1390 smp->status |= IB_SMP_UNSUP_VERSION;
1391 ret = reply(smp);
1392 goto bail;
1393 }
1394
1395 /* Is the mkey in the process of expiring? */
1396 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1397 /* Clear timeout and mkey protection field. */
1398 dev->mkey_lease_timeout = 0;
Ralph Campbell542869a2007-09-13 11:42:52 -07001399 dev->mkeyprot = 0;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001400 }
1401
1402 /*
1403 * M_Key checking depends on
1404 * Portinfo:M_Key_protect_bits
1405 */
1406 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1407 dev->mkey != smp->mkey &&
1408 (smp->method == IB_MGMT_METHOD_SET ||
1409 (smp->method == IB_MGMT_METHOD_GET &&
Ralph Campbell542869a2007-09-13 11:42:52 -07001410 dev->mkeyprot >= 2))) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001411 if (dev->mkey_violations != 0xFFFF)
1412 ++dev->mkey_violations;
1413 if (dev->mkey_lease_timeout ||
1414 dev->mkey_lease_period == 0) {
1415 ret = IB_MAD_RESULT_SUCCESS |
1416 IB_MAD_RESULT_CONSUMED;
1417 goto bail;
1418 }
1419 dev->mkey_lease_timeout = jiffies +
1420 dev->mkey_lease_period * HZ;
1421 /* Future: Generate a trap notice. */
1422 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1423 goto bail;
1424 } else if (dev->mkey_lease_timeout)
1425 dev->mkey_lease_timeout = 0;
1426
1427 switch (smp->method) {
1428 case IB_MGMT_METHOD_GET:
1429 switch (smp->attr_id) {
1430 case IB_SMP_ATTR_NODE_DESC:
1431 ret = recv_subn_get_nodedescription(smp, ibdev);
1432 goto bail;
1433 case IB_SMP_ATTR_NODE_INFO:
1434 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1435 goto bail;
1436 case IB_SMP_ATTR_GUID_INFO:
1437 ret = recv_subn_get_guidinfo(smp, ibdev);
1438 goto bail;
1439 case IB_SMP_ATTR_PORT_INFO:
1440 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1441 goto bail;
1442 case IB_SMP_ATTR_PKEY_TABLE:
1443 ret = recv_subn_get_pkeytable(smp, ibdev);
1444 goto bail;
1445 case IB_SMP_ATTR_SM_INFO:
1446 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1447 ret = IB_MAD_RESULT_SUCCESS |
1448 IB_MAD_RESULT_CONSUMED;
1449 goto bail;
1450 }
1451 if (dev->port_cap_flags & IB_PORT_SM) {
1452 ret = IB_MAD_RESULT_SUCCESS;
1453 goto bail;
1454 }
1455 /* FALLTHROUGH */
1456 default:
1457 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1458 ret = reply(smp);
1459 goto bail;
1460 }
1461
1462 case IB_MGMT_METHOD_SET:
1463 switch (smp->attr_id) {
1464 case IB_SMP_ATTR_GUID_INFO:
1465 ret = recv_subn_set_guidinfo(smp, ibdev);
1466 goto bail;
1467 case IB_SMP_ATTR_PORT_INFO:
1468 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1469 goto bail;
1470 case IB_SMP_ATTR_PKEY_TABLE:
1471 ret = recv_subn_set_pkeytable(smp, ibdev);
1472 goto bail;
1473 case IB_SMP_ATTR_SM_INFO:
1474 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1475 ret = IB_MAD_RESULT_SUCCESS |
1476 IB_MAD_RESULT_CONSUMED;
1477 goto bail;
1478 }
1479 if (dev->port_cap_flags & IB_PORT_SM) {
1480 ret = IB_MAD_RESULT_SUCCESS;
1481 goto bail;
1482 }
1483 /* FALLTHROUGH */
1484 default:
1485 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1486 ret = reply(smp);
1487 goto bail;
1488 }
1489
1490 case IB_MGMT_METHOD_GET_RESP:
1491 /*
1492 * The ib_mad module will call us to process responses
1493 * before checking for other consumers.
1494 * Just tell the caller to process it normally.
1495 */
Ralph Campbellf9b40352007-10-23 15:07:41 -07001496 ret = IB_MAD_RESULT_SUCCESS;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001497 goto bail;
1498 default:
1499 smp->status |= IB_SMP_UNSUP_METHOD;
1500 ret = reply(smp);
1501 }
1502
1503bail:
1504 return ret;
1505}
1506
1507static int process_perf(struct ib_device *ibdev, u8 port_num,
1508 struct ib_mad *in_mad,
1509 struct ib_mad *out_mad)
1510{
1511 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1512 int ret;
1513
1514 *out_mad = *in_mad;
1515 if (pmp->class_version != 1) {
1516 pmp->status |= IB_SMP_UNSUP_VERSION;
1517 ret = reply((struct ib_smp *) pmp);
1518 goto bail;
1519 }
1520
1521 switch (pmp->method) {
1522 case IB_MGMT_METHOD_GET:
1523 switch (pmp->attr_id) {
1524 case IB_PMA_CLASS_PORT_INFO:
1525 ret = recv_pma_get_classportinfo(pmp);
1526 goto bail;
1527 case IB_PMA_PORT_SAMPLES_CONTROL:
1528 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1529 port_num);
1530 goto bail;
1531 case IB_PMA_PORT_SAMPLES_RESULT:
1532 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1533 goto bail;
1534 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1535 ret = recv_pma_get_portsamplesresult_ext(pmp,
1536 ibdev);
1537 goto bail;
1538 case IB_PMA_PORT_COUNTERS:
1539 ret = recv_pma_get_portcounters(pmp, ibdev,
1540 port_num);
1541 goto bail;
1542 case IB_PMA_PORT_COUNTERS_EXT:
1543 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1544 port_num);
1545 goto bail;
1546 default:
1547 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1548 ret = reply((struct ib_smp *) pmp);
1549 goto bail;
1550 }
1551
1552 case IB_MGMT_METHOD_SET:
1553 switch (pmp->attr_id) {
1554 case IB_PMA_PORT_SAMPLES_CONTROL:
1555 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1556 port_num);
1557 goto bail;
1558 case IB_PMA_PORT_COUNTERS:
1559 ret = recv_pma_set_portcounters(pmp, ibdev,
1560 port_num);
1561 goto bail;
1562 case IB_PMA_PORT_COUNTERS_EXT:
1563 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1564 port_num);
1565 goto bail;
1566 default:
1567 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1568 ret = reply((struct ib_smp *) pmp);
1569 goto bail;
1570 }
1571
1572 case IB_MGMT_METHOD_GET_RESP:
1573 /*
1574 * The ib_mad module will call us to process responses
1575 * before checking for other consumers.
1576 * Just tell the caller to process it normally.
1577 */
Ralph Campbellf9b40352007-10-23 15:07:41 -07001578 ret = IB_MAD_RESULT_SUCCESS;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001579 goto bail;
1580 default:
1581 pmp->status |= IB_SMP_UNSUP_METHOD;
1582 ret = reply((struct ib_smp *) pmp);
1583 }
1584
1585bail:
1586 return ret;
1587}
1588
1589/**
1590 * ipath_process_mad - process an incoming MAD packet
1591 * @ibdev: the infiniband device this packet came in on
1592 * @mad_flags: MAD flags
1593 * @port_num: the port number this packet came in on
1594 * @in_wc: the work completion entry for this packet
1595 * @in_grh: the global route header for this packet
1596 * @in_mad: the incoming MAD
1597 * @out_mad: any outgoing MAD reply
1598 *
1599 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1600 * interested in processing.
1601 *
1602 * Note that the verbs framework has already done the MAD sanity checks,
1603 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1604 * MADs.
1605 *
1606 * This is called by the ib_mad module.
1607 */
1608int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1609 struct ib_wc *in_wc, struct ib_grh *in_grh,
1610 struct ib_mad *in_mad, struct ib_mad *out_mad)
1611{
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001612 int ret;
1613
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001614 switch (in_mad->mad_hdr.mgmt_class) {
1615 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1616 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1617 ret = process_subn(ibdev, mad_flags, port_num,
1618 in_mad, out_mad);
1619 goto bail;
1620 case IB_MGMT_CLASS_PERF_MGMT:
1621 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1622 goto bail;
1623 default:
1624 ret = IB_MAD_RESULT_SUCCESS;
1625 }
1626
1627bail:
1628 return ret;
1629}