blob: 8f152167208ae7ffaaf871cd5df9ad8d71eb8d07 [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'Sullivan11b054f2006-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'Sullivan11b054f2006-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
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700149
150static int get_overrunthreshold(struct ipath_devdata *dd)
151{
152 return (dd->ipath_ibcctrl >>
153 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
154 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
155}
156
157/**
158 * set_overrunthreshold - set the overrun threshold
159 * @dd: the infinipath device
160 * @n: the new threshold
161 *
162 * Note that this will only take effect when the link state changes.
163 */
164static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
165{
166 unsigned v;
167
168 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
169 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
170 if (v != n) {
171 dd->ipath_ibcctrl &=
172 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
173 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
174 dd->ipath_ibcctrl |=
175 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
176 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
177 dd->ipath_ibcctrl);
178 }
179 return 0;
180}
181
182static int get_phyerrthreshold(struct ipath_devdata *dd)
183{
184 return (dd->ipath_ibcctrl >>
185 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
186 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
187}
188
189/**
190 * set_phyerrthreshold - set the physical error threshold
191 * @dd: the infinipath device
192 * @n: the new threshold
193 *
194 * Note that this will only take effect when the link state changes.
195 */
196static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
197{
198 unsigned v;
199
200 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
201 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
202 if (v != n) {
203 dd->ipath_ibcctrl &=
204 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
205 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
206 dd->ipath_ibcctrl |=
207 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
208 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
209 dd->ipath_ibcctrl);
210 }
211 return 0;
212}
213
214/**
215 * get_linkdowndefaultstate - get the default linkdown state
216 * @dd: the infinipath device
217 *
218 * Returns zero if the default is POLL, 1 if the default is SLEEP.
219 */
220static int get_linkdowndefaultstate(struct ipath_devdata *dd)
221{
222 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
223}
224
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800225static int recv_subn_get_portinfo(struct ib_smp *smp,
226 struct ib_device *ibdev, u8 port)
227{
228 struct ipath_ibdev *dev;
Leonid Arshda2ab622006-06-17 20:37:36 -0700229 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800230 u16 lid;
231 u8 ibcstat;
232 u8 mtu;
233 int ret;
234
235 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
236 smp->status |= IB_SMP_INVALID_FIELD;
237 ret = reply(smp);
238 goto bail;
239 }
240
241 dev = to_idev(ibdev);
242
243 /* Clear all fields. Only set the non-zero fields. */
244 memset(smp->data, 0, sizeof(smp->data));
245
246 /* Only return the mkey if the protection field allows it. */
247 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
Ralph Campbell542869a2007-09-13 11:42:52 -0700248 dev->mkeyprot == 0)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800249 pip->mkey = dev->mkey;
250 pip->gid_prefix = dev->gid_prefix;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700251 lid = dev->dd->ipath_lid;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800252 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
253 pip->sm_lid = cpu_to_be16(dev->sm_lid);
254 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
255 /* pip->diag_code; */
256 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
257 pip->local_port_num = port;
258 pip->link_width_enabled = dev->link_width_enabled;
259 pip->link_width_supported = 3; /* 1x or 4x */
260 pip->link_width_active = 2; /* 4x */
261 pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700262 ibcstat = dev->dd->ipath_lastibcstat;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800263 pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
264 pip->portphysstate_linkdown =
265 (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700266 (get_linkdowndefaultstate(dev->dd) ? 1 : 2);
Ralph Campbell542869a2007-09-13 11:42:52 -0700267 pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dev->dd->ipath_lmc;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800268 pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700269 switch (dev->dd->ipath_ibmtu) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800270 case 4096:
271 mtu = IB_MTU_4096;
272 break;
273 case 2048:
274 mtu = IB_MTU_2048;
275 break;
276 case 1024:
277 mtu = IB_MTU_1024;
278 break;
279 case 512:
280 mtu = IB_MTU_512;
281 break;
282 case 256:
283 mtu = IB_MTU_256;
284 break;
285 default: /* oops, something is wrong */
286 mtu = IB_MTU_2048;
287 break;
288 }
289 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
290 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
291 pip->vl_high_limit = dev->vl_high_limit;
292 /* pip->vl_arb_high_cap; // only one VL */
293 /* pip->vl_arb_low_cap; // only one VL */
294 /* InitTypeReply = 0 */
Robert Walshe7340f02007-06-18 14:24:35 -0700295 /*
296 * Note: the chips support a maximum MTU of 4096, but the driver
297 * hasn't implemented this feature yet, so set the maximum value
298 * to 2048.
299 */
300 pip->inittypereply_mtucap = IB_MTU_2048;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800301 // HCAs ignore VLStallCount and HOQLife
302 /* pip->vlstallcnt_hoqlife; */
303 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
304 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
305 /* P_KeyViolations are counted by hardware. */
306 pip->pkey_violations =
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700307 cpu_to_be16((ipath_get_cr_errpkey(dev->dd) -
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -0700308 dev->z_pkey_violations) & 0xFFFF);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800309 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
310 /* Only the hardware GUID is supported for now */
311 pip->guid_cap = 1;
312 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
313 /* 32.768 usec. response time (guessing) */
314 pip->resv_resptimevalue = 3;
315 pip->localphyerrors_overrunerrors =
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700316 (get_phyerrthreshold(dev->dd) << 4) |
317 get_overrunthreshold(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800318 /* pip->max_credit_hint; */
319 /* pip->link_roundtrip_latency[3]; */
320
321 ret = reply(smp);
322
323bail:
324 return ret;
325}
326
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700327/**
328 * get_pkeys - return the PKEY table for port 0
329 * @dd: the infinipath device
330 * @pkeys: the pkey table is placed here
331 */
332static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
333{
334 struct ipath_portdata *pd = dd->ipath_pd[0];
335
336 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
337
338 return 0;
339}
340
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800341static int recv_subn_get_pkeytable(struct ib_smp *smp,
342 struct ib_device *ibdev)
343{
344 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
345 u16 *p = (u16 *) smp->data;
346 __be16 *q = (__be16 *) smp->data;
347
348 /* 64 blocks of 32 16-bit P_Key entries */
349
350 memset(smp->data, 0, sizeof(smp->data));
351 if (startpx == 0) {
352 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700353 unsigned i, n = ipath_get_npkeys(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800354
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700355 get_pkeys(dev->dd, p);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800356
357 for (i = 0; i < n; i++)
358 q[i] = cpu_to_be16(p[i]);
359 } else
360 smp->status |= IB_SMP_INVALID_FIELD;
361
362 return reply(smp);
363}
364
365static int recv_subn_set_guidinfo(struct ib_smp *smp,
366 struct ib_device *ibdev)
367{
368 /* The only GUID we support is the first read-only entry. */
369 return recv_subn_get_guidinfo(smp, ibdev);
370}
371
372/**
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700373 * set_linkdowndefaultstate - set the default linkdown state
374 * @dd: the infinipath device
375 * @sleep: the new state
376 *
377 * Note that this will only take effect when the link state changes.
378 */
379static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
380{
381 if (sleep)
382 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
383 else
384 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
385 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
386 dd->ipath_ibcctrl);
387 return 0;
388}
389
390/**
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800391 * recv_subn_set_portinfo - set port information
392 * @smp: the incoming SM packet
393 * @ibdev: the infiniband device
394 * @port: the port on the device
395 *
396 * Set Portinfo (see ch. 14.2.5.6).
397 */
398static int recv_subn_set_portinfo(struct ib_smp *smp,
399 struct ib_device *ibdev, u8 port)
400{
Leonid Arshda2ab622006-06-17 20:37:36 -0700401 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800402 struct ib_event event;
403 struct ipath_ibdev *dev;
Ralph Campbell542869a2007-09-13 11:42:52 -0700404 struct ipath_devdata *dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800405 u32 flags;
406 char clientrereg = 0;
407 u16 lid, smlid;
408 u8 lwe;
409 u8 lse;
410 u8 state;
411 u16 lstate;
412 u32 mtu;
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700413 int ret, ore;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800414
415 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
416 goto err;
417
418 dev = to_idev(ibdev);
Ralph Campbell542869a2007-09-13 11:42:52 -0700419 dd = dev->dd;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800420 event.device = ibdev;
421 event.element.port_num = port;
422
423 dev->mkey = pip->mkey;
424 dev->gid_prefix = pip->gid_prefix;
425 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
426
427 lid = be16_to_cpu(pip->lid);
Ralph Campbell542869a2007-09-13 11:42:52 -0700428 if (dd->ipath_lid != lid ||
429 dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800430 /* Must be a valid unicast LID address. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700431 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800432 goto err;
Ralph Campbell542869a2007-09-13 11:42:52 -0700433 ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800434 event.event = IB_EVENT_LID_CHANGE;
435 ib_dispatch_event(&event);
436 }
437
438 smlid = be16_to_cpu(pip->sm_lid);
439 if (smlid != dev->sm_lid) {
440 /* Must be a valid unicast LID address. */
Bryan O'Sullivan27b678d2006-07-01 04:36:17 -0700441 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800442 goto err;
443 dev->sm_lid = smlid;
444 event.event = IB_EVENT_SM_CHANGE;
445 ib_dispatch_event(&event);
446 }
447
448 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
449 lwe = pip->link_width_enabled;
450 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
451 goto err;
452 if (lwe == 0xFF)
453 dev->link_width_enabled = 3; /* 1x or 4x */
454 else if (lwe)
455 dev->link_width_enabled = lwe;
456
457 /* Only 2.5 Gbs supported. */
458 lse = pip->linkspeedactive_enabled & 0xF;
459 if (lse >= 2 && lse <= 0xE)
460 goto err;
461
462 /* Set link down default state. */
463 switch (pip->portphysstate_linkdown & 0xF) {
464 case 0: /* NOP */
465 break;
466 case 1: /* SLEEP */
Ralph Campbell542869a2007-09-13 11:42:52 -0700467 if (set_linkdowndefaultstate(dd, 1))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800468 goto err;
469 break;
470 case 2: /* POLL */
Ralph Campbell542869a2007-09-13 11:42:52 -0700471 if (set_linkdowndefaultstate(dd, 0))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800472 goto err;
473 break;
474 default:
475 goto err;
476 }
477
Ralph Campbell542869a2007-09-13 11:42:52 -0700478 dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800479 dev->vl_high_limit = pip->vl_high_limit;
480
481 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
482 case IB_MTU_256:
483 mtu = 256;
484 break;
485 case IB_MTU_512:
486 mtu = 512;
487 break;
488 case IB_MTU_1024:
489 mtu = 1024;
490 break;
491 case IB_MTU_2048:
492 mtu = 2048;
493 break;
494 case IB_MTU_4096:
495 mtu = 4096;
496 break;
497 default:
498 /* XXX We have already partially updated our state! */
499 goto err;
500 }
Ralph Campbell542869a2007-09-13 11:42:52 -0700501 ipath_set_mtu(dd, mtu);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800502
503 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
504
505 /* We only support VL0 */
506 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
507 goto err;
508
509 if (pip->mkey_violations == 0)
510 dev->mkey_violations = 0;
511
512 /*
513 * Hardware counter can't be reset so snapshot and subtract
514 * later.
515 */
516 if (pip->pkey_violations == 0)
Ralph Campbell542869a2007-09-13 11:42:52 -0700517 dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800518
519 if (pip->qkey_violations == 0)
520 dev->qkey_violations = 0;
521
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700522 ore = pip->localphyerrors_overrunerrors;
Ralph Campbell542869a2007-09-13 11:42:52 -0700523 if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800524 goto err;
525
Ralph Campbell542869a2007-09-13 11:42:52 -0700526 if (set_overrunthreshold(dd, (ore & 0xF)))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800527 goto err;
528
529 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
530
531 if (pip->clientrereg_resv_subnetto & 0x80) {
532 clientrereg = 1;
Roland Dreier6eddb5c2006-06-17 20:37:37 -0700533 event.event = IB_EVENT_CLIENT_REREGISTER;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800534 ib_dispatch_event(&event);
535 }
536
537 /*
538 * Do the port state change now that the other link parameters
539 * have been set.
540 * Changing the port physical state only makes sense if the link
541 * is down or is being set to down.
542 */
543 state = pip->linkspeed_portstate & 0xF;
Ralph Campbell542869a2007-09-13 11:42:52 -0700544 flags = dd->ipath_flags;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800545 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
546 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
547 goto err;
548
549 /*
550 * Only state changes of DOWN, ARM, and ACTIVE are valid
551 * and must be in the correct state to take effect (see 7.2.6).
552 */
553 switch (state) {
554 case IB_PORT_NOP:
555 if (lstate == 0)
556 break;
557 /* FALLTHROUGH */
558 case IB_PORT_DOWN:
559 if (lstate == 0)
Ralph Campbell542869a2007-09-13 11:42:52 -0700560 if (get_linkdowndefaultstate(dd))
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800561 lstate = IPATH_IB_LINKDOWN_SLEEP;
562 else
563 lstate = IPATH_IB_LINKDOWN;
564 else if (lstate == 1)
565 lstate = IPATH_IB_LINKDOWN_SLEEP;
566 else if (lstate == 2)
567 lstate = IPATH_IB_LINKDOWN;
568 else if (lstate == 3)
569 lstate = IPATH_IB_LINKDOWN_DISABLE;
570 else
571 goto err;
Ralph Campbell542869a2007-09-13 11:42:52 -0700572 ipath_set_linkstate(dd, lstate);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800573 if (flags & IPATH_LINKACTIVE) {
574 event.event = IB_EVENT_PORT_ERR;
575 ib_dispatch_event(&event);
576 }
577 break;
578 case IB_PORT_ARMED:
579 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
580 break;
Ralph Campbell542869a2007-09-13 11:42:52 -0700581 ipath_set_linkstate(dd, IPATH_IB_LINKARM);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800582 if (flags & IPATH_LINKACTIVE) {
583 event.event = IB_EVENT_PORT_ERR;
584 ib_dispatch_event(&event);
585 }
586 break;
587 case IB_PORT_ACTIVE:
588 if (!(flags & IPATH_LINKARMED))
589 break;
Ralph Campbell542869a2007-09-13 11:42:52 -0700590 ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800591 event.event = IB_EVENT_PORT_ACTIVE;
592 ib_dispatch_event(&event);
593 break;
594 default:
595 /* XXX We have already partially updated our state! */
596 goto err;
597 }
598
599 ret = recv_subn_get_portinfo(smp, ibdev, port);
600
601 if (clientrereg)
602 pip->clientrereg_resv_subnetto |= 0x80;
603
604 goto done;
605
606err:
607 smp->status |= IB_SMP_INVALID_FIELD;
608 ret = recv_subn_get_portinfo(smp, ibdev, port);
609
610done:
611 return ret;
612}
613
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700614/**
615 * rm_pkey - decrecment the reference count for the given PKEY
616 * @dd: the infinipath device
617 * @key: the PKEY index
618 *
619 * Return true if this was the last reference and the hardware table entry
620 * needs to be changed.
621 */
622static int rm_pkey(struct ipath_devdata *dd, u16 key)
623{
624 int i;
625 int ret;
626
627 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
628 if (dd->ipath_pkeys[i] != key)
629 continue;
630 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
631 dd->ipath_pkeys[i] = 0;
632 ret = 1;
633 goto bail;
634 }
635 break;
636 }
637
638 ret = 0;
639
640bail:
641 return ret;
642}
643
644/**
645 * add_pkey - add the given PKEY to the hardware table
646 * @dd: the infinipath device
647 * @key: the PKEY
648 *
649 * Return an error code if unable to add the entry, zero if no change,
650 * or 1 if the hardware PKEY register needs to be updated.
651 */
652static int add_pkey(struct ipath_devdata *dd, u16 key)
653{
654 int i;
655 u16 lkey = key & 0x7FFF;
656 int any = 0;
657 int ret;
658
659 if (lkey == 0x7FFF) {
660 ret = 0;
661 goto bail;
662 }
663
664 /* Look for an empty slot or a matching PKEY. */
665 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
666 if (!dd->ipath_pkeys[i]) {
667 any++;
668 continue;
669 }
670 /* If it matches exactly, try to increment the ref count */
671 if (dd->ipath_pkeys[i] == key) {
672 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
673 ret = 0;
674 goto bail;
675 }
676 /* Lost the race. Look for an empty slot below. */
677 atomic_dec(&dd->ipath_pkeyrefs[i]);
678 any++;
679 }
680 /*
681 * It makes no sense to have both the limited and unlimited
682 * PKEY set at the same time since the unlimited one will
683 * disable the limited one.
684 */
685 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
686 ret = -EEXIST;
687 goto bail;
688 }
689 }
690 if (!any) {
691 ret = -EBUSY;
692 goto bail;
693 }
694 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
695 if (!dd->ipath_pkeys[i] &&
696 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
697 /* for ipathstats, etc. */
698 ipath_stats.sps_pkeys[i] = lkey;
699 dd->ipath_pkeys[i] = key;
700 ret = 1;
701 goto bail;
702 }
703 }
704 ret = -EBUSY;
705
706bail:
707 return ret;
708}
709
710/**
711 * set_pkeys - set the PKEY table for port 0
712 * @dd: the infinipath device
713 * @pkeys: the PKEY table
714 */
715static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
716{
717 struct ipath_portdata *pd;
718 int i;
719 int changed = 0;
720
721 pd = dd->ipath_pd[0];
722
723 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
724 u16 key = pkeys[i];
725 u16 okey = pd->port_pkeys[i];
726
727 if (key == okey)
728 continue;
729 /*
730 * The value of this PKEY table entry is changing.
731 * Remove the old entry in the hardware's array of PKEYs.
732 */
733 if (okey & 0x7FFF)
734 changed |= rm_pkey(dd, okey);
735 if (key & 0x7FFF) {
736 int ret = add_pkey(dd, key);
737
738 if (ret < 0)
739 key = 0;
740 else
741 changed |= ret;
742 }
743 pd->port_pkeys[i] = key;
744 }
745 if (changed) {
746 u64 pkey;
747
748 pkey = (u64) dd->ipath_pkeys[0] |
749 ((u64) dd->ipath_pkeys[1] << 16) |
750 ((u64) dd->ipath_pkeys[2] << 32) |
751 ((u64) dd->ipath_pkeys[3] << 48);
752 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
753 (unsigned long long) pkey);
754 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
755 pkey);
756 }
757 return 0;
758}
759
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800760static int recv_subn_set_pkeytable(struct ib_smp *smp,
761 struct ib_device *ibdev)
762{
763 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
764 __be16 *p = (__be16 *) smp->data;
765 u16 *q = (u16 *) smp->data;
766 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700767 unsigned i, n = ipath_get_npkeys(dev->dd);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800768
769 for (i = 0; i < n; i++)
770 q[i] = be16_to_cpu(p[i]);
771
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -0700772 if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800773 smp->status |= IB_SMP_INVALID_FIELD;
774
775 return recv_subn_get_pkeytable(smp, ibdev);
776}
777
778#define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
779#define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
780#define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
781#define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
782#define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
783#define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
784
785struct ib_perf {
786 u8 base_version;
787 u8 mgmt_class;
788 u8 class_version;
789 u8 method;
790 __be16 status;
791 __be16 unused;
792 __be64 tid;
793 __be16 attr_id;
794 __be16 resv;
795 __be32 attr_mod;
796 u8 reserved[40];
797 u8 data[192];
798} __attribute__ ((packed));
799
800struct ib_pma_classportinfo {
801 u8 base_version;
802 u8 class_version;
803 __be16 cap_mask;
804 u8 reserved[3];
805 u8 resp_time_value; /* only lower 5 bits */
806 union ib_gid redirect_gid;
807 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
808 __be16 redirect_lid;
809 __be16 redirect_pkey;
810 __be32 redirect_qp; /* only lower 24 bits */
811 __be32 redirect_qkey;
812 union ib_gid trap_gid;
813 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
814 __be16 trap_lid;
815 __be16 trap_pkey;
816 __be32 trap_hl_qp; /* 8, 24 bits respectively */
817 __be32 trap_qkey;
818} __attribute__ ((packed));
819
820struct ib_pma_portsamplescontrol {
821 u8 opcode;
822 u8 port_select;
823 u8 tick;
824 u8 counter_width; /* only lower 3 bits */
825 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
826 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
827 u8 sample_mechanisms;
828 u8 sample_status; /* only lower 2 bits */
829 __be64 option_mask;
830 __be64 vendor_mask;
831 __be32 sample_start;
832 __be32 sample_interval;
833 __be16 tag;
834 __be16 counter_select[15];
835} __attribute__ ((packed));
836
837struct ib_pma_portsamplesresult {
838 __be16 tag;
839 __be16 sample_status; /* only lower 2 bits */
840 __be32 counter[15];
841} __attribute__ ((packed));
842
843struct ib_pma_portsamplesresult_ext {
844 __be16 tag;
845 __be16 sample_status; /* only lower 2 bits */
846 __be32 extended_width; /* only upper 2 bits */
847 __be64 counter[15];
848} __attribute__ ((packed));
849
850struct ib_pma_portcounters {
851 u8 reserved;
852 u8 port_select;
853 __be16 counter_select;
854 __be16 symbol_error_counter;
855 u8 link_error_recovery_counter;
856 u8 link_downed_counter;
857 __be16 port_rcv_errors;
858 __be16 port_rcv_remphys_errors;
859 __be16 port_rcv_switch_relay_errors;
860 __be16 port_xmit_discards;
861 u8 port_xmit_constraint_errors;
862 u8 port_rcv_constraint_errors;
863 u8 reserved1;
864 u8 lli_ebor_errors; /* 4, 4, bits */
865 __be16 reserved2;
866 __be16 vl15_dropped;
867 __be32 port_xmit_data;
868 __be32 port_rcv_data;
869 __be32 port_xmit_packets;
870 __be32 port_rcv_packets;
871} __attribute__ ((packed));
872
873#define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
874#define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
875#define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
876#define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
877#define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
878#define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
Bryan O'Sullivanfba75202006-07-01 04:36:09 -0700879#define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
880#define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
881#define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -0800882#define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
883#define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
884#define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
885#define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
886
887struct ib_pma_portcounters_ext {
888 u8 reserved;
889 u8 port_select;
890 __be16 counter_select;
891 __be32 reserved1;
892 __be64 port_xmit_data;
893 __be64 port_rcv_data;
894 __be64 port_xmit_packets;
895 __be64 port_rcv_packets;
896 __be64 port_unicast_xmit_packets;
897 __be64 port_unicast_rcv_packets;
898 __be64 port_multicast_xmit_packets;
899 __be64 port_multicast_rcv_packets;
900} __attribute__ ((packed));
901
902#define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
903#define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
904#define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
905#define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
906#define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
907#define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
908#define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
909#define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
910
911static int recv_pma_get_classportinfo(struct ib_perf *pmp)
912{
913 struct ib_pma_classportinfo *p =
914 (struct ib_pma_classportinfo *)pmp->data;
915
916 memset(pmp->data, 0, sizeof(pmp->data));
917
918 if (pmp->attr_mod != 0)
919 pmp->status |= IB_SMP_INVALID_FIELD;
920
921 /* Indicate AllPortSelect is valid (only one port anyway) */
922 p->cap_mask = __constant_cpu_to_be16(1 << 8);
923 p->base_version = 1;
924 p->class_version = 1;
925 /*
926 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
927 * sec.
928 */
929 p->resp_time_value = 18;
930
931 return reply((struct ib_smp *) pmp);
932}
933
934/*
935 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
936 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
937 * We support 5 counters which only count the mandatory quantities.
938 */
939#define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
940#define COUNTER_MASK0_9 \
941 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
942 COUNTER_MASK(1, 1) | \
943 COUNTER_MASK(1, 2) | \
944 COUNTER_MASK(1, 3) | \
945 COUNTER_MASK(1, 4))
946
947static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
948 struct ib_device *ibdev, u8 port)
949{
950 struct ib_pma_portsamplescontrol *p =
951 (struct ib_pma_portsamplescontrol *)pmp->data;
952 struct ipath_ibdev *dev = to_idev(ibdev);
953 unsigned long flags;
954 u8 port_select = p->port_select;
955
956 memset(pmp->data, 0, sizeof(pmp->data));
957
958 p->port_select = port_select;
959 if (pmp->attr_mod != 0 ||
960 (port_select != port && port_select != 0xFF))
961 pmp->status |= IB_SMP_INVALID_FIELD;
962 /*
963 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
964 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
965 * intervals are counted in ticks. Since we use Linux timers, that
966 * count in jiffies, we can't sample for less than 1000 ticks if HZ
967 * == 1000 (4000 ticks if HZ is 250).
968 */
969 /* XXX This is WRONG. */
970 p->tick = 250; /* 1 usec. */
971 p->counter_width = 4; /* 32 bit counters */
972 p->counter_mask0_9 = COUNTER_MASK0_9;
973 spin_lock_irqsave(&dev->pending_lock, flags);
974 p->sample_status = dev->pma_sample_status;
975 p->sample_start = cpu_to_be32(dev->pma_sample_start);
976 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
977 p->tag = cpu_to_be16(dev->pma_tag);
978 p->counter_select[0] = dev->pma_counter_select[0];
979 p->counter_select[1] = dev->pma_counter_select[1];
980 p->counter_select[2] = dev->pma_counter_select[2];
981 p->counter_select[3] = dev->pma_counter_select[3];
982 p->counter_select[4] = dev->pma_counter_select[4];
983 spin_unlock_irqrestore(&dev->pending_lock, flags);
984
985 return reply((struct ib_smp *) pmp);
986}
987
988static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
989 struct ib_device *ibdev, u8 port)
990{
991 struct ib_pma_portsamplescontrol *p =
992 (struct ib_pma_portsamplescontrol *)pmp->data;
993 struct ipath_ibdev *dev = to_idev(ibdev);
994 unsigned long flags;
995 u32 start;
996 int ret;
997
998 if (pmp->attr_mod != 0 ||
999 (p->port_select != port && p->port_select != 0xFF)) {
1000 pmp->status |= IB_SMP_INVALID_FIELD;
1001 ret = reply((struct ib_smp *) pmp);
1002 goto bail;
1003 }
1004
1005 start = be32_to_cpu(p->sample_start);
1006 if (start != 0) {
1007 spin_lock_irqsave(&dev->pending_lock, flags);
1008 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
1009 dev->pma_sample_status =
1010 IB_PMA_SAMPLE_STATUS_STARTED;
1011 dev->pma_sample_start = start;
1012 dev->pma_sample_interval =
1013 be32_to_cpu(p->sample_interval);
1014 dev->pma_tag = be16_to_cpu(p->tag);
1015 if (p->counter_select[0])
1016 dev->pma_counter_select[0] =
1017 p->counter_select[0];
1018 if (p->counter_select[1])
1019 dev->pma_counter_select[1] =
1020 p->counter_select[1];
1021 if (p->counter_select[2])
1022 dev->pma_counter_select[2] =
1023 p->counter_select[2];
1024 if (p->counter_select[3])
1025 dev->pma_counter_select[3] =
1026 p->counter_select[3];
1027 if (p->counter_select[4])
1028 dev->pma_counter_select[4] =
1029 p->counter_select[4];
1030 }
1031 spin_unlock_irqrestore(&dev->pending_lock, flags);
1032 }
1033 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
1034
1035bail:
1036 return ret;
1037}
1038
1039static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
1040{
1041 u64 ret;
1042
1043 switch (sel) {
1044 case IB_PMA_PORT_XMIT_DATA:
1045 ret = dev->ipath_sword;
1046 break;
1047 case IB_PMA_PORT_RCV_DATA:
1048 ret = dev->ipath_rword;
1049 break;
1050 case IB_PMA_PORT_XMIT_PKTS:
1051 ret = dev->ipath_spkts;
1052 break;
1053 case IB_PMA_PORT_RCV_PKTS:
1054 ret = dev->ipath_rpkts;
1055 break;
1056 case IB_PMA_PORT_XMIT_WAIT:
1057 ret = dev->ipath_xmit_wait;
1058 break;
1059 default:
1060 ret = 0;
1061 }
1062
1063 return ret;
1064}
1065
1066static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
1067 struct ib_device *ibdev)
1068{
1069 struct ib_pma_portsamplesresult *p =
1070 (struct ib_pma_portsamplesresult *)pmp->data;
1071 struct ipath_ibdev *dev = to_idev(ibdev);
1072 int i;
1073
1074 memset(pmp->data, 0, sizeof(pmp->data));
1075 p->tag = cpu_to_be16(dev->pma_tag);
1076 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1077 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1078 p->counter[i] = cpu_to_be32(
1079 get_counter(dev, dev->pma_counter_select[i]));
1080
1081 return reply((struct ib_smp *) pmp);
1082}
1083
1084static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
1085 struct ib_device *ibdev)
1086{
1087 struct ib_pma_portsamplesresult_ext *p =
1088 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1089 struct ipath_ibdev *dev = to_idev(ibdev);
1090 int i;
1091
1092 memset(pmp->data, 0, sizeof(pmp->data));
1093 p->tag = cpu_to_be16(dev->pma_tag);
1094 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1095 /* 64 bits */
1096 p->extended_width = __constant_cpu_to_be32(0x80000000);
1097 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1098 p->counter[i] = cpu_to_be64(
1099 get_counter(dev, dev->pma_counter_select[i]));
1100
1101 return reply((struct ib_smp *) pmp);
1102}
1103
1104static int recv_pma_get_portcounters(struct ib_perf *pmp,
1105 struct ib_device *ibdev, u8 port)
1106{
1107 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1108 pmp->data;
1109 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001110 struct ipath_verbs_counters cntrs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001111 u8 port_select = p->port_select;
1112
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001113 ipath_get_counters(dev->dd, &cntrs);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001114
1115 /* Adjust counters for any resets done. */
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001116 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001117 cntrs.link_error_recovery_counter -=
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001118 dev->z_link_error_recovery_counter;
1119 cntrs.link_downed_counter -= dev->z_link_downed_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001120 cntrs.port_rcv_errors += dev->rcv_errors;
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001121 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1122 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1123 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1124 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1125 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1126 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1127 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001128 cntrs.local_link_integrity_errors -=
1129 dev->z_local_link_integrity_errors;
1130 cntrs.excessive_buffer_overrun_errors -=
1131 dev->z_excessive_buffer_overrun_errors;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001132
1133 memset(pmp->data, 0, sizeof(pmp->data));
1134
1135 p->port_select = port_select;
1136 if (pmp->attr_mod != 0 ||
1137 (port_select != port && port_select != 0xFF))
1138 pmp->status |= IB_SMP_INVALID_FIELD;
1139
1140 if (cntrs.symbol_error_counter > 0xFFFFUL)
1141 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
1142 else
1143 p->symbol_error_counter =
1144 cpu_to_be16((u16)cntrs.symbol_error_counter);
1145 if (cntrs.link_error_recovery_counter > 0xFFUL)
1146 p->link_error_recovery_counter = 0xFF;
1147 else
1148 p->link_error_recovery_counter =
1149 (u8)cntrs.link_error_recovery_counter;
1150 if (cntrs.link_downed_counter > 0xFFUL)
1151 p->link_downed_counter = 0xFF;
1152 else
1153 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1154 if (cntrs.port_rcv_errors > 0xFFFFUL)
1155 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
1156 else
1157 p->port_rcv_errors =
1158 cpu_to_be16((u16) cntrs.port_rcv_errors);
1159 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1160 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
1161 else
1162 p->port_rcv_remphys_errors =
1163 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1164 if (cntrs.port_xmit_discards > 0xFFFFUL)
1165 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
1166 else
1167 p->port_xmit_discards =
1168 cpu_to_be16((u16)cntrs.port_xmit_discards);
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001169 if (cntrs.local_link_integrity_errors > 0xFUL)
1170 cntrs.local_link_integrity_errors = 0xFUL;
1171 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1172 cntrs.excessive_buffer_overrun_errors = 0xFUL;
1173 p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
1174 cntrs.excessive_buffer_overrun_errors;
1175 if (dev->n_vl15_dropped > 0xFFFFUL)
1176 p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
1177 else
1178 p->vl15_dropped = cpu_to_be16((u16)dev->n_vl15_dropped);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001179 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1180 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
1181 else
1182 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1183 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1184 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
1185 else
1186 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1187 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1188 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1189 else
1190 p->port_xmit_packets =
1191 cpu_to_be32((u32)cntrs.port_xmit_packets);
1192 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1193 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1194 else
1195 p->port_rcv_packets =
1196 cpu_to_be32((u32) cntrs.port_rcv_packets);
1197
1198 return reply((struct ib_smp *) pmp);
1199}
1200
1201static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
1202 struct ib_device *ibdev, u8 port)
1203{
1204 struct ib_pma_portcounters_ext *p =
1205 (struct ib_pma_portcounters_ext *)pmp->data;
1206 struct ipath_ibdev *dev = to_idev(ibdev);
1207 u64 swords, rwords, spkts, rpkts, xwait;
1208 u8 port_select = p->port_select;
1209
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001210 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1211 &rpkts, &xwait);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001212
1213 /* Adjust counters for any resets done. */
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001214 swords -= dev->z_port_xmit_data;
1215 rwords -= dev->z_port_rcv_data;
1216 spkts -= dev->z_port_xmit_packets;
1217 rpkts -= dev->z_port_rcv_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001218
1219 memset(pmp->data, 0, sizeof(pmp->data));
1220
1221 p->port_select = port_select;
1222 if (pmp->attr_mod != 0 ||
1223 (port_select != port && port_select != 0xFF))
1224 pmp->status |= IB_SMP_INVALID_FIELD;
1225
1226 p->port_xmit_data = cpu_to_be64(swords);
1227 p->port_rcv_data = cpu_to_be64(rwords);
1228 p->port_xmit_packets = cpu_to_be64(spkts);
1229 p->port_rcv_packets = cpu_to_be64(rpkts);
1230 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1231 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1232 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1233 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1234
1235 return reply((struct ib_smp *) pmp);
1236}
1237
1238static int recv_pma_set_portcounters(struct ib_perf *pmp,
1239 struct ib_device *ibdev, u8 port)
1240{
1241 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1242 pmp->data;
1243 struct ipath_ibdev *dev = to_idev(ibdev);
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001244 struct ipath_verbs_counters cntrs;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001245
1246 /*
1247 * Since the HW doesn't support clearing counters, we save the
1248 * current count and subtract it from future responses.
1249 */
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001250 ipath_get_counters(dev->dd, &cntrs);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001251
1252 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001253 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001254
1255 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001256 dev->z_link_error_recovery_counter =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001257 cntrs.link_error_recovery_counter;
1258
1259 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001260 dev->z_link_downed_counter = cntrs.link_downed_counter;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001261
1262 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001263 dev->z_port_rcv_errors =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001264 cntrs.port_rcv_errors + dev->rcv_errors;
1265
1266 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001267 dev->z_port_rcv_remphys_errors =
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001268 cntrs.port_rcv_remphys_errors;
1269
1270 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001271 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001272
Bryan O'Sullivanfba75202006-07-01 04:36:09 -07001273 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1274 dev->z_local_link_integrity_errors =
1275 cntrs.local_link_integrity_errors;
1276
1277 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1278 dev->z_excessive_buffer_overrun_errors =
1279 cntrs.excessive_buffer_overrun_errors;
1280
1281 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED)
1282 dev->n_vl15_dropped = 0;
1283
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001284 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001285 dev->z_port_xmit_data = cntrs.port_xmit_data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001286
1287 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001288 dev->z_port_rcv_data = cntrs.port_rcv_data;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001289
1290 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001291 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001292
1293 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001294 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001295
1296 return recv_pma_get_portcounters(pmp, ibdev, port);
1297}
1298
1299static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1300 struct ib_device *ibdev, u8 port)
1301{
1302 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1303 pmp->data;
1304 struct ipath_ibdev *dev = to_idev(ibdev);
1305 u64 swords, rwords, spkts, rpkts, xwait;
1306
Bryan O'Sullivan34b2aaf2006-08-25 11:24:32 -07001307 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1308 &rpkts, &xwait);
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001309
1310 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001311 dev->z_port_xmit_data = swords;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001312
1313 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001314 dev->z_port_rcv_data = rwords;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001315
1316 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001317 dev->z_port_xmit_packets = spkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001318
1319 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
Bryan O'Sullivan443a64a2006-07-01 04:35:48 -07001320 dev->z_port_rcv_packets = rpkts;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001321
1322 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1323 dev->n_unicast_xmit = 0;
1324
1325 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1326 dev->n_unicast_rcv = 0;
1327
1328 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1329 dev->n_multicast_xmit = 0;
1330
1331 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1332 dev->n_multicast_rcv = 0;
1333
1334 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1335}
1336
1337static int process_subn(struct ib_device *ibdev, int mad_flags,
1338 u8 port_num, struct ib_mad *in_mad,
1339 struct ib_mad *out_mad)
1340{
1341 struct ib_smp *smp = (struct ib_smp *)out_mad;
1342 struct ipath_ibdev *dev = to_idev(ibdev);
1343 int ret;
1344
1345 *out_mad = *in_mad;
1346 if (smp->class_version != 1) {
1347 smp->status |= IB_SMP_UNSUP_VERSION;
1348 ret = reply(smp);
1349 goto bail;
1350 }
1351
1352 /* Is the mkey in the process of expiring? */
1353 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1354 /* Clear timeout and mkey protection field. */
1355 dev->mkey_lease_timeout = 0;
Ralph Campbell542869a2007-09-13 11:42:52 -07001356 dev->mkeyprot = 0;
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001357 }
1358
1359 /*
1360 * M_Key checking depends on
1361 * Portinfo:M_Key_protect_bits
1362 */
1363 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1364 dev->mkey != smp->mkey &&
1365 (smp->method == IB_MGMT_METHOD_SET ||
1366 (smp->method == IB_MGMT_METHOD_GET &&
Ralph Campbell542869a2007-09-13 11:42:52 -07001367 dev->mkeyprot >= 2))) {
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001368 if (dev->mkey_violations != 0xFFFF)
1369 ++dev->mkey_violations;
1370 if (dev->mkey_lease_timeout ||
1371 dev->mkey_lease_period == 0) {
1372 ret = IB_MAD_RESULT_SUCCESS |
1373 IB_MAD_RESULT_CONSUMED;
1374 goto bail;
1375 }
1376 dev->mkey_lease_timeout = jiffies +
1377 dev->mkey_lease_period * HZ;
1378 /* Future: Generate a trap notice. */
1379 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1380 goto bail;
1381 } else if (dev->mkey_lease_timeout)
1382 dev->mkey_lease_timeout = 0;
1383
1384 switch (smp->method) {
1385 case IB_MGMT_METHOD_GET:
1386 switch (smp->attr_id) {
1387 case IB_SMP_ATTR_NODE_DESC:
1388 ret = recv_subn_get_nodedescription(smp, ibdev);
1389 goto bail;
1390 case IB_SMP_ATTR_NODE_INFO:
1391 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1392 goto bail;
1393 case IB_SMP_ATTR_GUID_INFO:
1394 ret = recv_subn_get_guidinfo(smp, ibdev);
1395 goto bail;
1396 case IB_SMP_ATTR_PORT_INFO:
1397 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1398 goto bail;
1399 case IB_SMP_ATTR_PKEY_TABLE:
1400 ret = recv_subn_get_pkeytable(smp, ibdev);
1401 goto bail;
1402 case IB_SMP_ATTR_SM_INFO:
1403 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1404 ret = IB_MAD_RESULT_SUCCESS |
1405 IB_MAD_RESULT_CONSUMED;
1406 goto bail;
1407 }
1408 if (dev->port_cap_flags & IB_PORT_SM) {
1409 ret = IB_MAD_RESULT_SUCCESS;
1410 goto bail;
1411 }
1412 /* FALLTHROUGH */
1413 default:
1414 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1415 ret = reply(smp);
1416 goto bail;
1417 }
1418
1419 case IB_MGMT_METHOD_SET:
1420 switch (smp->attr_id) {
1421 case IB_SMP_ATTR_GUID_INFO:
1422 ret = recv_subn_set_guidinfo(smp, ibdev);
1423 goto bail;
1424 case IB_SMP_ATTR_PORT_INFO:
1425 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1426 goto bail;
1427 case IB_SMP_ATTR_PKEY_TABLE:
1428 ret = recv_subn_set_pkeytable(smp, ibdev);
1429 goto bail;
1430 case IB_SMP_ATTR_SM_INFO:
1431 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1432 ret = IB_MAD_RESULT_SUCCESS |
1433 IB_MAD_RESULT_CONSUMED;
1434 goto bail;
1435 }
1436 if (dev->port_cap_flags & IB_PORT_SM) {
1437 ret = IB_MAD_RESULT_SUCCESS;
1438 goto bail;
1439 }
1440 /* FALLTHROUGH */
1441 default:
1442 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1443 ret = reply(smp);
1444 goto bail;
1445 }
1446
1447 case IB_MGMT_METHOD_GET_RESP:
1448 /*
1449 * The ib_mad module will call us to process responses
1450 * before checking for other consumers.
1451 * Just tell the caller to process it normally.
1452 */
1453 ret = IB_MAD_RESULT_FAILURE;
1454 goto bail;
1455 default:
1456 smp->status |= IB_SMP_UNSUP_METHOD;
1457 ret = reply(smp);
1458 }
1459
1460bail:
1461 return ret;
1462}
1463
1464static int process_perf(struct ib_device *ibdev, u8 port_num,
1465 struct ib_mad *in_mad,
1466 struct ib_mad *out_mad)
1467{
1468 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1469 int ret;
1470
1471 *out_mad = *in_mad;
1472 if (pmp->class_version != 1) {
1473 pmp->status |= IB_SMP_UNSUP_VERSION;
1474 ret = reply((struct ib_smp *) pmp);
1475 goto bail;
1476 }
1477
1478 switch (pmp->method) {
1479 case IB_MGMT_METHOD_GET:
1480 switch (pmp->attr_id) {
1481 case IB_PMA_CLASS_PORT_INFO:
1482 ret = recv_pma_get_classportinfo(pmp);
1483 goto bail;
1484 case IB_PMA_PORT_SAMPLES_CONTROL:
1485 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1486 port_num);
1487 goto bail;
1488 case IB_PMA_PORT_SAMPLES_RESULT:
1489 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1490 goto bail;
1491 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1492 ret = recv_pma_get_portsamplesresult_ext(pmp,
1493 ibdev);
1494 goto bail;
1495 case IB_PMA_PORT_COUNTERS:
1496 ret = recv_pma_get_portcounters(pmp, ibdev,
1497 port_num);
1498 goto bail;
1499 case IB_PMA_PORT_COUNTERS_EXT:
1500 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1501 port_num);
1502 goto bail;
1503 default:
1504 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1505 ret = reply((struct ib_smp *) pmp);
1506 goto bail;
1507 }
1508
1509 case IB_MGMT_METHOD_SET:
1510 switch (pmp->attr_id) {
1511 case IB_PMA_PORT_SAMPLES_CONTROL:
1512 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1513 port_num);
1514 goto bail;
1515 case IB_PMA_PORT_COUNTERS:
1516 ret = recv_pma_set_portcounters(pmp, ibdev,
1517 port_num);
1518 goto bail;
1519 case IB_PMA_PORT_COUNTERS_EXT:
1520 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1521 port_num);
1522 goto bail;
1523 default:
1524 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1525 ret = reply((struct ib_smp *) pmp);
1526 goto bail;
1527 }
1528
1529 case IB_MGMT_METHOD_GET_RESP:
1530 /*
1531 * The ib_mad module will call us to process responses
1532 * before checking for other consumers.
1533 * Just tell the caller to process it normally.
1534 */
1535 ret = IB_MAD_RESULT_FAILURE;
1536 goto bail;
1537 default:
1538 pmp->status |= IB_SMP_UNSUP_METHOD;
1539 ret = reply((struct ib_smp *) pmp);
1540 }
1541
1542bail:
1543 return ret;
1544}
1545
1546/**
1547 * ipath_process_mad - process an incoming MAD packet
1548 * @ibdev: the infiniband device this packet came in on
1549 * @mad_flags: MAD flags
1550 * @port_num: the port number this packet came in on
1551 * @in_wc: the work completion entry for this packet
1552 * @in_grh: the global route header for this packet
1553 * @in_mad: the incoming MAD
1554 * @out_mad: any outgoing MAD reply
1555 *
1556 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1557 * interested in processing.
1558 *
1559 * Note that the verbs framework has already done the MAD sanity checks,
1560 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1561 * MADs.
1562 *
1563 * This is called by the ib_mad module.
1564 */
1565int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1566 struct ib_wc *in_wc, struct ib_grh *in_grh,
1567 struct ib_mad *in_mad, struct ib_mad *out_mad)
1568{
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001569 int ret;
1570
Bryan O'Sullivane28c00a2006-03-29 15:23:37 -08001571 switch (in_mad->mad_hdr.mgmt_class) {
1572 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1573 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1574 ret = process_subn(ibdev, mad_flags, port_num,
1575 in_mad, out_mad);
1576 goto bail;
1577 case IB_MGMT_CLASS_PERF_MGMT:
1578 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1579 goto bail;
1580 default:
1581 ret = IB_MAD_RESULT_SUCCESS;
1582 }
1583
1584bail:
1585 return ret;
1586}