2 * Copyright (c) 2006 QLogic, Inc. All rights reserved.
3 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
34 #include <rdma/ib_smi.h>
36 #include "ipath_kernel.h"
37 #include "ipath_verbs.h"
38 #include "ips_common.h"
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)
45 static int reply(struct ib_smp *smp)
48 * The verbs framework will handle the directed/LID route
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;
57 static int recv_subn_get_nodedescription(struct ib_smp *smp,
58 struct ib_device *ibdev)
61 smp->status |= IB_SMP_INVALID_FIELD;
63 strncpy(smp->data, ibdev->node_desc, sizeof(smp->data));
81 } __attribute__ ((packed));
83 static int recv_subn_get_nodeinfo(struct ib_smp *smp,
84 struct ib_device *ibdev, u8 port)
86 struct nodeinfo *nip = (struct nodeinfo *)&smp->data;
87 struct ipath_devdata *dd = to_idev(ibdev)->dd;
88 u32 vendor, majrev, minrev;
91 smp->status |= IB_SMP_INVALID_FIELD;
93 nip->base_version = 1;
94 nip->class_version = 1;
95 nip->node_type = 1; /* channel adapter */
97 * XXX The num_ports value will need a layer function to get
98 * the value if we ever have more than one IB port on a chip.
99 * We will also need to get the GUID for the port.
101 nip->num_ports = ibdev->phys_port_cnt;
102 /* This is already in network order */
103 nip->sys_guid = to_idev(ibdev)->sys_image_guid;
104 nip->node_guid = ipath_layer_get_guid(dd);
105 nip->port_guid = nip->sys_guid;
106 nip->partition_cap = cpu_to_be16(ipath_layer_get_npkeys(dd));
107 nip->device_id = cpu_to_be16(ipath_layer_get_deviceid(dd));
108 majrev = ipath_layer_get_majrev(dd);
109 minrev = ipath_layer_get_minrev(dd);
110 nip->revision = cpu_to_be32((majrev << 16) | minrev);
111 nip->local_port_num = port;
112 vendor = ipath_layer_get_vendorid(dd);
113 nip->vendor_id[0] = 0;
114 nip->vendor_id[1] = vendor >> 8;
115 nip->vendor_id[2] = vendor;
120 static int recv_subn_get_guidinfo(struct ib_smp *smp,
121 struct ib_device *ibdev)
123 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
124 __be64 *p = (__be64 *) smp->data;
126 /* 32 blocks of 8 64-bit GUIDs per block */
128 memset(smp->data, 0, sizeof(smp->data));
131 * We only support one GUID for now. If this changes, the
132 * portinfo.guid_cap field needs to be updated too.
135 /* The first is a copy of the read-only HW GUID. */
136 *p = ipath_layer_get_guid(to_idev(ibdev)->dd);
138 smp->status |= IB_SMP_INVALID_FIELD;
143 static int recv_subn_get_portinfo(struct ib_smp *smp,
144 struct ib_device *ibdev, u8 port)
146 struct ipath_ibdev *dev;
147 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
153 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
154 smp->status |= IB_SMP_INVALID_FIELD;
159 dev = to_idev(ibdev);
161 /* Clear all fields. Only set the non-zero fields. */
162 memset(smp->data, 0, sizeof(smp->data));
164 /* Only return the mkey if the protection field allows it. */
165 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
166 (dev->mkeyprot_resv_lmc >> 6) == 0)
167 pip->mkey = dev->mkey;
168 pip->gid_prefix = dev->gid_prefix;
169 lid = ipath_layer_get_lid(dev->dd);
170 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
171 pip->sm_lid = cpu_to_be16(dev->sm_lid);
172 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
173 /* pip->diag_code; */
174 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
175 pip->local_port_num = port;
176 pip->link_width_enabled = dev->link_width_enabled;
177 pip->link_width_supported = 3; /* 1x or 4x */
178 pip->link_width_active = 2; /* 4x */
179 pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
180 ibcstat = ipath_layer_get_lastibcstat(dev->dd);
181 pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
182 pip->portphysstate_linkdown =
183 (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
184 (ipath_layer_get_linkdowndefaultstate(dev->dd) ? 1 : 2);
185 pip->mkeyprot_resv_lmc = dev->mkeyprot_resv_lmc;
186 pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
187 switch (ipath_layer_get_ibmtu(dev->dd)) {
203 default: /* oops, something is wrong */
207 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
208 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
209 pip->vl_high_limit = dev->vl_high_limit;
210 /* pip->vl_arb_high_cap; // only one VL */
211 /* pip->vl_arb_low_cap; // only one VL */
212 /* InitTypeReply = 0 */
213 pip->inittypereply_mtucap = IB_MTU_4096;
214 // HCAs ignore VLStallCount and HOQLife
215 /* pip->vlstallcnt_hoqlife; */
216 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
217 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
218 /* P_KeyViolations are counted by hardware. */
219 pip->pkey_violations =
220 cpu_to_be16((ipath_layer_get_cr_errpkey(dev->dd) -
221 dev->z_pkey_violations) & 0xFFFF);
222 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
223 /* Only the hardware GUID is supported for now */
225 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
226 /* 32.768 usec. response time (guessing) */
227 pip->resv_resptimevalue = 3;
228 pip->localphyerrors_overrunerrors =
229 (ipath_layer_get_phyerrthreshold(dev->dd) << 4) |
230 ipath_layer_get_overrunthreshold(dev->dd);
231 /* pip->max_credit_hint; */
232 /* pip->link_roundtrip_latency[3]; */
240 static int recv_subn_get_pkeytable(struct ib_smp *smp,
241 struct ib_device *ibdev)
243 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
244 u16 *p = (u16 *) smp->data;
245 __be16 *q = (__be16 *) smp->data;
247 /* 64 blocks of 32 16-bit P_Key entries */
249 memset(smp->data, 0, sizeof(smp->data));
251 struct ipath_ibdev *dev = to_idev(ibdev);
252 unsigned i, n = ipath_layer_get_npkeys(dev->dd);
254 ipath_layer_get_pkeys(dev->dd, p);
256 for (i = 0; i < n; i++)
257 q[i] = cpu_to_be16(p[i]);
259 smp->status |= IB_SMP_INVALID_FIELD;
264 static int recv_subn_set_guidinfo(struct ib_smp *smp,
265 struct ib_device *ibdev)
267 /* The only GUID we support is the first read-only entry. */
268 return recv_subn_get_guidinfo(smp, ibdev);
272 * recv_subn_set_portinfo - set port information
273 * @smp: the incoming SM packet
274 * @ibdev: the infiniband device
275 * @port: the port on the device
277 * Set Portinfo (see ch. 14.2.5.6).
279 static int recv_subn_set_portinfo(struct ib_smp *smp,
280 struct ib_device *ibdev, u8 port)
282 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
283 struct ib_event event;
284 struct ipath_ibdev *dev;
286 char clientrereg = 0;
295 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
298 dev = to_idev(ibdev);
299 event.device = ibdev;
300 event.element.port_num = port;
302 dev->mkey = pip->mkey;
303 dev->gid_prefix = pip->gid_prefix;
304 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
306 lid = be16_to_cpu(pip->lid);
307 if (lid != ipath_layer_get_lid(dev->dd)) {
308 /* Must be a valid unicast LID address. */
309 if (lid == 0 || lid >= IPS_MULTICAST_LID_BASE)
311 ipath_set_sps_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
312 event.event = IB_EVENT_LID_CHANGE;
313 ib_dispatch_event(&event);
316 smlid = be16_to_cpu(pip->sm_lid);
317 if (smlid != dev->sm_lid) {
318 /* Must be a valid unicast LID address. */
319 if (smlid == 0 || smlid >= IPS_MULTICAST_LID_BASE)
322 event.event = IB_EVENT_SM_CHANGE;
323 ib_dispatch_event(&event);
326 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
327 lwe = pip->link_width_enabled;
328 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
331 dev->link_width_enabled = 3; /* 1x or 4x */
333 dev->link_width_enabled = lwe;
335 /* Only 2.5 Gbs supported. */
336 lse = pip->linkspeedactive_enabled & 0xF;
337 if (lse >= 2 && lse <= 0xE)
340 /* Set link down default state. */
341 switch (pip->portphysstate_linkdown & 0xF) {
345 if (ipath_layer_set_linkdowndefaultstate(dev->dd, 1))
349 if (ipath_layer_set_linkdowndefaultstate(dev->dd, 0))
356 dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
357 dev->vl_high_limit = pip->vl_high_limit;
359 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
376 /* XXX We have already partially updated our state! */
379 ipath_layer_set_mtu(dev->dd, mtu);
381 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
383 /* We only support VL0 */
384 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
387 if (pip->mkey_violations == 0)
388 dev->mkey_violations = 0;
391 * Hardware counter can't be reset so snapshot and subtract
394 if (pip->pkey_violations == 0)
395 dev->z_pkey_violations =
396 ipath_layer_get_cr_errpkey(dev->dd);
398 if (pip->qkey_violations == 0)
399 dev->qkey_violations = 0;
401 if (ipath_layer_set_phyerrthreshold(
403 (pip->localphyerrors_overrunerrors >> 4) & 0xF))
406 if (ipath_layer_set_overrunthreshold(
408 (pip->localphyerrors_overrunerrors & 0xF)))
411 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
413 if (pip->clientrereg_resv_subnetto & 0x80) {
415 event.event = IB_EVENT_CLIENT_REREGISTER;
416 ib_dispatch_event(&event);
420 * Do the port state change now that the other link parameters
422 * Changing the port physical state only makes sense if the link
423 * is down or is being set to down.
425 state = pip->linkspeed_portstate & 0xF;
426 flags = ipath_layer_get_flags(dev->dd);
427 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
428 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
432 * Only state changes of DOWN, ARM, and ACTIVE are valid
433 * and must be in the correct state to take effect (see 7.2.6).
442 if (ipath_layer_get_linkdowndefaultstate(dev->dd))
443 lstate = IPATH_IB_LINKDOWN_SLEEP;
445 lstate = IPATH_IB_LINKDOWN;
446 else if (lstate == 1)
447 lstate = IPATH_IB_LINKDOWN_SLEEP;
448 else if (lstate == 2)
449 lstate = IPATH_IB_LINKDOWN;
450 else if (lstate == 3)
451 lstate = IPATH_IB_LINKDOWN_DISABLE;
454 ipath_layer_set_linkstate(dev->dd, lstate);
455 if (flags & IPATH_LINKACTIVE) {
456 event.event = IB_EVENT_PORT_ERR;
457 ib_dispatch_event(&event);
461 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
463 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKARM);
464 if (flags & IPATH_LINKACTIVE) {
465 event.event = IB_EVENT_PORT_ERR;
466 ib_dispatch_event(&event);
470 if (!(flags & IPATH_LINKARMED))
472 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
473 event.event = IB_EVENT_PORT_ACTIVE;
474 ib_dispatch_event(&event);
477 /* XXX We have already partially updated our state! */
481 ret = recv_subn_get_portinfo(smp, ibdev, port);
484 pip->clientrereg_resv_subnetto |= 0x80;
489 smp->status |= IB_SMP_INVALID_FIELD;
490 ret = recv_subn_get_portinfo(smp, ibdev, port);
496 static int recv_subn_set_pkeytable(struct ib_smp *smp,
497 struct ib_device *ibdev)
499 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
500 __be16 *p = (__be16 *) smp->data;
501 u16 *q = (u16 *) smp->data;
502 struct ipath_ibdev *dev = to_idev(ibdev);
503 unsigned i, n = ipath_layer_get_npkeys(dev->dd);
505 for (i = 0; i < n; i++)
506 q[i] = be16_to_cpu(p[i]);
509 ipath_layer_set_pkeys(dev->dd, q) != 0)
510 smp->status |= IB_SMP_INVALID_FIELD;
512 return recv_subn_get_pkeytable(smp, ibdev);
515 #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
516 #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
517 #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
518 #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
519 #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
520 #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
535 } __attribute__ ((packed));
537 struct ib_pma_classportinfo {
542 u8 resp_time_value; /* only lower 5 bits */
543 union ib_gid redirect_gid;
544 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
546 __be16 redirect_pkey;
547 __be32 redirect_qp; /* only lower 24 bits */
548 __be32 redirect_qkey;
549 union ib_gid trap_gid;
550 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
553 __be32 trap_hl_qp; /* 8, 24 bits respectively */
555 } __attribute__ ((packed));
557 struct ib_pma_portsamplescontrol {
561 u8 counter_width; /* only lower 3 bits */
562 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
563 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
564 u8 sample_mechanisms;
565 u8 sample_status; /* only lower 2 bits */
569 __be32 sample_interval;
571 __be16 counter_select[15];
572 } __attribute__ ((packed));
574 struct ib_pma_portsamplesresult {
576 __be16 sample_status; /* only lower 2 bits */
578 } __attribute__ ((packed));
580 struct ib_pma_portsamplesresult_ext {
582 __be16 sample_status; /* only lower 2 bits */
583 __be32 extended_width; /* only upper 2 bits */
585 } __attribute__ ((packed));
587 struct ib_pma_portcounters {
590 __be16 counter_select;
591 __be16 symbol_error_counter;
592 u8 link_error_recovery_counter;
593 u8 link_downed_counter;
594 __be16 port_rcv_errors;
595 __be16 port_rcv_remphys_errors;
596 __be16 port_rcv_switch_relay_errors;
597 __be16 port_xmit_discards;
598 u8 port_xmit_constraint_errors;
599 u8 port_rcv_constraint_errors;
601 u8 lli_ebor_errors; /* 4, 4, bits */
604 __be32 port_xmit_data;
605 __be32 port_rcv_data;
606 __be32 port_xmit_packets;
607 __be32 port_rcv_packets;
608 } __attribute__ ((packed));
610 #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
611 #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
612 #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
613 #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
614 #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
615 #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
616 #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
617 #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
618 #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
619 #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
621 struct ib_pma_portcounters_ext {
624 __be16 counter_select;
626 __be64 port_xmit_data;
627 __be64 port_rcv_data;
628 __be64 port_xmit_packets;
629 __be64 port_rcv_packets;
630 __be64 port_unicast_xmit_packets;
631 __be64 port_unicast_rcv_packets;
632 __be64 port_multicast_xmit_packets;
633 __be64 port_multicast_rcv_packets;
634 } __attribute__ ((packed));
636 #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
637 #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
638 #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
639 #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
640 #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
641 #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
642 #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
643 #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
645 static int recv_pma_get_classportinfo(struct ib_perf *pmp)
647 struct ib_pma_classportinfo *p =
648 (struct ib_pma_classportinfo *)pmp->data;
650 memset(pmp->data, 0, sizeof(pmp->data));
652 if (pmp->attr_mod != 0)
653 pmp->status |= IB_SMP_INVALID_FIELD;
655 /* Indicate AllPortSelect is valid (only one port anyway) */
656 p->cap_mask = __constant_cpu_to_be16(1 << 8);
658 p->class_version = 1;
660 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
663 p->resp_time_value = 18;
665 return reply((struct ib_smp *) pmp);
669 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
670 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
671 * We support 5 counters which only count the mandatory quantities.
673 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
674 #define COUNTER_MASK0_9 \
675 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
676 COUNTER_MASK(1, 1) | \
677 COUNTER_MASK(1, 2) | \
678 COUNTER_MASK(1, 3) | \
681 static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
682 struct ib_device *ibdev, u8 port)
684 struct ib_pma_portsamplescontrol *p =
685 (struct ib_pma_portsamplescontrol *)pmp->data;
686 struct ipath_ibdev *dev = to_idev(ibdev);
688 u8 port_select = p->port_select;
690 memset(pmp->data, 0, sizeof(pmp->data));
692 p->port_select = port_select;
693 if (pmp->attr_mod != 0 ||
694 (port_select != port && port_select != 0xFF))
695 pmp->status |= IB_SMP_INVALID_FIELD;
697 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
698 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
699 * intervals are counted in ticks. Since we use Linux timers, that
700 * count in jiffies, we can't sample for less than 1000 ticks if HZ
701 * == 1000 (4000 ticks if HZ is 250).
703 /* XXX This is WRONG. */
704 p->tick = 250; /* 1 usec. */
705 p->counter_width = 4; /* 32 bit counters */
706 p->counter_mask0_9 = COUNTER_MASK0_9;
707 spin_lock_irqsave(&dev->pending_lock, flags);
708 p->sample_status = dev->pma_sample_status;
709 p->sample_start = cpu_to_be32(dev->pma_sample_start);
710 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
711 p->tag = cpu_to_be16(dev->pma_tag);
712 p->counter_select[0] = dev->pma_counter_select[0];
713 p->counter_select[1] = dev->pma_counter_select[1];
714 p->counter_select[2] = dev->pma_counter_select[2];
715 p->counter_select[3] = dev->pma_counter_select[3];
716 p->counter_select[4] = dev->pma_counter_select[4];
717 spin_unlock_irqrestore(&dev->pending_lock, flags);
719 return reply((struct ib_smp *) pmp);
722 static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
723 struct ib_device *ibdev, u8 port)
725 struct ib_pma_portsamplescontrol *p =
726 (struct ib_pma_portsamplescontrol *)pmp->data;
727 struct ipath_ibdev *dev = to_idev(ibdev);
732 if (pmp->attr_mod != 0 ||
733 (p->port_select != port && p->port_select != 0xFF)) {
734 pmp->status |= IB_SMP_INVALID_FIELD;
735 ret = reply((struct ib_smp *) pmp);
739 start = be32_to_cpu(p->sample_start);
741 spin_lock_irqsave(&dev->pending_lock, flags);
742 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
743 dev->pma_sample_status =
744 IB_PMA_SAMPLE_STATUS_STARTED;
745 dev->pma_sample_start = start;
746 dev->pma_sample_interval =
747 be32_to_cpu(p->sample_interval);
748 dev->pma_tag = be16_to_cpu(p->tag);
749 if (p->counter_select[0])
750 dev->pma_counter_select[0] =
751 p->counter_select[0];
752 if (p->counter_select[1])
753 dev->pma_counter_select[1] =
754 p->counter_select[1];
755 if (p->counter_select[2])
756 dev->pma_counter_select[2] =
757 p->counter_select[2];
758 if (p->counter_select[3])
759 dev->pma_counter_select[3] =
760 p->counter_select[3];
761 if (p->counter_select[4])
762 dev->pma_counter_select[4] =
763 p->counter_select[4];
765 spin_unlock_irqrestore(&dev->pending_lock, flags);
767 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
773 static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
778 case IB_PMA_PORT_XMIT_DATA:
779 ret = dev->ipath_sword;
781 case IB_PMA_PORT_RCV_DATA:
782 ret = dev->ipath_rword;
784 case IB_PMA_PORT_XMIT_PKTS:
785 ret = dev->ipath_spkts;
787 case IB_PMA_PORT_RCV_PKTS:
788 ret = dev->ipath_rpkts;
790 case IB_PMA_PORT_XMIT_WAIT:
791 ret = dev->ipath_xmit_wait;
800 static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
801 struct ib_device *ibdev)
803 struct ib_pma_portsamplesresult *p =
804 (struct ib_pma_portsamplesresult *)pmp->data;
805 struct ipath_ibdev *dev = to_idev(ibdev);
808 memset(pmp->data, 0, sizeof(pmp->data));
809 p->tag = cpu_to_be16(dev->pma_tag);
810 p->sample_status = cpu_to_be16(dev->pma_sample_status);
811 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
812 p->counter[i] = cpu_to_be32(
813 get_counter(dev, dev->pma_counter_select[i]));
815 return reply((struct ib_smp *) pmp);
818 static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
819 struct ib_device *ibdev)
821 struct ib_pma_portsamplesresult_ext *p =
822 (struct ib_pma_portsamplesresult_ext *)pmp->data;
823 struct ipath_ibdev *dev = to_idev(ibdev);
826 memset(pmp->data, 0, sizeof(pmp->data));
827 p->tag = cpu_to_be16(dev->pma_tag);
828 p->sample_status = cpu_to_be16(dev->pma_sample_status);
830 p->extended_width = __constant_cpu_to_be32(0x80000000);
831 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
832 p->counter[i] = cpu_to_be64(
833 get_counter(dev, dev->pma_counter_select[i]));
835 return reply((struct ib_smp *) pmp);
838 static int recv_pma_get_portcounters(struct ib_perf *pmp,
839 struct ib_device *ibdev, u8 port)
841 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
843 struct ipath_ibdev *dev = to_idev(ibdev);
844 struct ipath_layer_counters cntrs;
845 u8 port_select = p->port_select;
847 ipath_layer_get_counters(dev->dd, &cntrs);
849 /* Adjust counters for any resets done. */
850 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
851 cntrs.link_error_recovery_counter -=
852 dev->z_link_error_recovery_counter;
853 cntrs.link_downed_counter -= dev->z_link_downed_counter;
854 cntrs.port_rcv_errors += dev->rcv_errors;
855 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
856 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
857 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
858 cntrs.port_xmit_data -= dev->z_port_xmit_data;
859 cntrs.port_rcv_data -= dev->z_port_rcv_data;
860 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
861 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
863 memset(pmp->data, 0, sizeof(pmp->data));
865 p->port_select = port_select;
866 if (pmp->attr_mod != 0 ||
867 (port_select != port && port_select != 0xFF))
868 pmp->status |= IB_SMP_INVALID_FIELD;
870 if (cntrs.symbol_error_counter > 0xFFFFUL)
871 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
873 p->symbol_error_counter =
874 cpu_to_be16((u16)cntrs.symbol_error_counter);
875 if (cntrs.link_error_recovery_counter > 0xFFUL)
876 p->link_error_recovery_counter = 0xFF;
878 p->link_error_recovery_counter =
879 (u8)cntrs.link_error_recovery_counter;
880 if (cntrs.link_downed_counter > 0xFFUL)
881 p->link_downed_counter = 0xFF;
883 p->link_downed_counter = (u8)cntrs.link_downed_counter;
884 if (cntrs.port_rcv_errors > 0xFFFFUL)
885 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
888 cpu_to_be16((u16) cntrs.port_rcv_errors);
889 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
890 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
892 p->port_rcv_remphys_errors =
893 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
894 if (cntrs.port_xmit_discards > 0xFFFFUL)
895 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
897 p->port_xmit_discards =
898 cpu_to_be16((u16)cntrs.port_xmit_discards);
899 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
900 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
902 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
903 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
904 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
906 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
907 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
908 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
910 p->port_xmit_packets =
911 cpu_to_be32((u32)cntrs.port_xmit_packets);
912 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
913 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
915 p->port_rcv_packets =
916 cpu_to_be32((u32) cntrs.port_rcv_packets);
918 return reply((struct ib_smp *) pmp);
921 static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
922 struct ib_device *ibdev, u8 port)
924 struct ib_pma_portcounters_ext *p =
925 (struct ib_pma_portcounters_ext *)pmp->data;
926 struct ipath_ibdev *dev = to_idev(ibdev);
927 u64 swords, rwords, spkts, rpkts, xwait;
928 u8 port_select = p->port_select;
930 ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
933 /* Adjust counters for any resets done. */
934 swords -= dev->z_port_xmit_data;
935 rwords -= dev->z_port_rcv_data;
936 spkts -= dev->z_port_xmit_packets;
937 rpkts -= dev->z_port_rcv_packets;
939 memset(pmp->data, 0, sizeof(pmp->data));
941 p->port_select = port_select;
942 if (pmp->attr_mod != 0 ||
943 (port_select != port && port_select != 0xFF))
944 pmp->status |= IB_SMP_INVALID_FIELD;
946 p->port_xmit_data = cpu_to_be64(swords);
947 p->port_rcv_data = cpu_to_be64(rwords);
948 p->port_xmit_packets = cpu_to_be64(spkts);
949 p->port_rcv_packets = cpu_to_be64(rpkts);
950 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
951 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
952 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
953 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
955 return reply((struct ib_smp *) pmp);
958 static int recv_pma_set_portcounters(struct ib_perf *pmp,
959 struct ib_device *ibdev, u8 port)
961 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
963 struct ipath_ibdev *dev = to_idev(ibdev);
964 struct ipath_layer_counters cntrs;
967 * Since the HW doesn't support clearing counters, we save the
968 * current count and subtract it from future responses.
970 ipath_layer_get_counters(dev->dd, &cntrs);
972 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
973 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
975 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
976 dev->z_link_error_recovery_counter =
977 cntrs.link_error_recovery_counter;
979 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
980 dev->z_link_downed_counter = cntrs.link_downed_counter;
982 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
983 dev->z_port_rcv_errors =
984 cntrs.port_rcv_errors + dev->rcv_errors;
986 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
987 dev->z_port_rcv_remphys_errors =
988 cntrs.port_rcv_remphys_errors;
990 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
991 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
993 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
994 dev->z_port_xmit_data = cntrs.port_xmit_data;
996 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
997 dev->z_port_rcv_data = cntrs.port_rcv_data;
999 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1000 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
1002 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1003 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
1005 return recv_pma_get_portcounters(pmp, ibdev, port);
1008 static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1009 struct ib_device *ibdev, u8 port)
1011 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1013 struct ipath_ibdev *dev = to_idev(ibdev);
1014 u64 swords, rwords, spkts, rpkts, xwait;
1016 ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1019 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1020 dev->z_port_xmit_data = swords;
1022 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1023 dev->z_port_rcv_data = rwords;
1025 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1026 dev->z_port_xmit_packets = spkts;
1028 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1029 dev->z_port_rcv_packets = rpkts;
1031 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1032 dev->n_unicast_xmit = 0;
1034 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1035 dev->n_unicast_rcv = 0;
1037 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1038 dev->n_multicast_xmit = 0;
1040 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1041 dev->n_multicast_rcv = 0;
1043 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1046 static int process_subn(struct ib_device *ibdev, int mad_flags,
1047 u8 port_num, struct ib_mad *in_mad,
1048 struct ib_mad *out_mad)
1050 struct ib_smp *smp = (struct ib_smp *)out_mad;
1051 struct ipath_ibdev *dev = to_idev(ibdev);
1055 if (smp->class_version != 1) {
1056 smp->status |= IB_SMP_UNSUP_VERSION;
1061 /* Is the mkey in the process of expiring? */
1062 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1063 /* Clear timeout and mkey protection field. */
1064 dev->mkey_lease_timeout = 0;
1065 dev->mkeyprot_resv_lmc &= 0x3F;
1069 * M_Key checking depends on
1070 * Portinfo:M_Key_protect_bits
1072 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1073 dev->mkey != smp->mkey &&
1074 (smp->method == IB_MGMT_METHOD_SET ||
1075 (smp->method == IB_MGMT_METHOD_GET &&
1076 (dev->mkeyprot_resv_lmc >> 7) != 0))) {
1077 if (dev->mkey_violations != 0xFFFF)
1078 ++dev->mkey_violations;
1079 if (dev->mkey_lease_timeout ||
1080 dev->mkey_lease_period == 0) {
1081 ret = IB_MAD_RESULT_SUCCESS |
1082 IB_MAD_RESULT_CONSUMED;
1085 dev->mkey_lease_timeout = jiffies +
1086 dev->mkey_lease_period * HZ;
1087 /* Future: Generate a trap notice. */
1088 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1090 } else if (dev->mkey_lease_timeout)
1091 dev->mkey_lease_timeout = 0;
1093 switch (smp->method) {
1094 case IB_MGMT_METHOD_GET:
1095 switch (smp->attr_id) {
1096 case IB_SMP_ATTR_NODE_DESC:
1097 ret = recv_subn_get_nodedescription(smp, ibdev);
1099 case IB_SMP_ATTR_NODE_INFO:
1100 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1102 case IB_SMP_ATTR_GUID_INFO:
1103 ret = recv_subn_get_guidinfo(smp, ibdev);
1105 case IB_SMP_ATTR_PORT_INFO:
1106 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1108 case IB_SMP_ATTR_PKEY_TABLE:
1109 ret = recv_subn_get_pkeytable(smp, ibdev);
1111 case IB_SMP_ATTR_SM_INFO:
1112 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1113 ret = IB_MAD_RESULT_SUCCESS |
1114 IB_MAD_RESULT_CONSUMED;
1117 if (dev->port_cap_flags & IB_PORT_SM) {
1118 ret = IB_MAD_RESULT_SUCCESS;
1123 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1128 case IB_MGMT_METHOD_SET:
1129 switch (smp->attr_id) {
1130 case IB_SMP_ATTR_GUID_INFO:
1131 ret = recv_subn_set_guidinfo(smp, ibdev);
1133 case IB_SMP_ATTR_PORT_INFO:
1134 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1136 case IB_SMP_ATTR_PKEY_TABLE:
1137 ret = recv_subn_set_pkeytable(smp, ibdev);
1139 case IB_SMP_ATTR_SM_INFO:
1140 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1141 ret = IB_MAD_RESULT_SUCCESS |
1142 IB_MAD_RESULT_CONSUMED;
1145 if (dev->port_cap_flags & IB_PORT_SM) {
1146 ret = IB_MAD_RESULT_SUCCESS;
1151 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1156 case IB_MGMT_METHOD_GET_RESP:
1158 * The ib_mad module will call us to process responses
1159 * before checking for other consumers.
1160 * Just tell the caller to process it normally.
1162 ret = IB_MAD_RESULT_FAILURE;
1165 smp->status |= IB_SMP_UNSUP_METHOD;
1173 static int process_perf(struct ib_device *ibdev, u8 port_num,
1174 struct ib_mad *in_mad,
1175 struct ib_mad *out_mad)
1177 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1181 if (pmp->class_version != 1) {
1182 pmp->status |= IB_SMP_UNSUP_VERSION;
1183 ret = reply((struct ib_smp *) pmp);
1187 switch (pmp->method) {
1188 case IB_MGMT_METHOD_GET:
1189 switch (pmp->attr_id) {
1190 case IB_PMA_CLASS_PORT_INFO:
1191 ret = recv_pma_get_classportinfo(pmp);
1193 case IB_PMA_PORT_SAMPLES_CONTROL:
1194 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1197 case IB_PMA_PORT_SAMPLES_RESULT:
1198 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1200 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1201 ret = recv_pma_get_portsamplesresult_ext(pmp,
1204 case IB_PMA_PORT_COUNTERS:
1205 ret = recv_pma_get_portcounters(pmp, ibdev,
1208 case IB_PMA_PORT_COUNTERS_EXT:
1209 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1213 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1214 ret = reply((struct ib_smp *) pmp);
1218 case IB_MGMT_METHOD_SET:
1219 switch (pmp->attr_id) {
1220 case IB_PMA_PORT_SAMPLES_CONTROL:
1221 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1224 case IB_PMA_PORT_COUNTERS:
1225 ret = recv_pma_set_portcounters(pmp, ibdev,
1228 case IB_PMA_PORT_COUNTERS_EXT:
1229 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1233 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1234 ret = reply((struct ib_smp *) pmp);
1238 case IB_MGMT_METHOD_GET_RESP:
1240 * The ib_mad module will call us to process responses
1241 * before checking for other consumers.
1242 * Just tell the caller to process it normally.
1244 ret = IB_MAD_RESULT_FAILURE;
1247 pmp->status |= IB_SMP_UNSUP_METHOD;
1248 ret = reply((struct ib_smp *) pmp);
1256 * ipath_process_mad - process an incoming MAD packet
1257 * @ibdev: the infiniband device this packet came in on
1258 * @mad_flags: MAD flags
1259 * @port_num: the port number this packet came in on
1260 * @in_wc: the work completion entry for this packet
1261 * @in_grh: the global route header for this packet
1262 * @in_mad: the incoming MAD
1263 * @out_mad: any outgoing MAD reply
1265 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1266 * interested in processing.
1268 * Note that the verbs framework has already done the MAD sanity checks,
1269 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1272 * This is called by the ib_mad module.
1274 int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1275 struct ib_wc *in_wc, struct ib_grh *in_grh,
1276 struct ib_mad *in_mad, struct ib_mad *out_mad)
1278 struct ipath_ibdev *dev = to_idev(ibdev);
1282 * Snapshot current HW counters to "clear" them.
1283 * This should be done when the driver is loaded except that for
1284 * some reason we get a zillion errors when brining up the link.
1286 if (dev->rcv_errors == 0) {
1287 struct ipath_layer_counters cntrs;
1289 ipath_layer_get_counters(to_idev(ibdev)->dd, &cntrs);
1291 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
1292 dev->z_link_error_recovery_counter =
1293 cntrs.link_error_recovery_counter;
1294 dev->z_link_downed_counter = cntrs.link_downed_counter;
1295 dev->z_port_rcv_errors = cntrs.port_rcv_errors + 1;
1296 dev->z_port_rcv_remphys_errors =
1297 cntrs.port_rcv_remphys_errors;
1298 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
1299 dev->z_port_xmit_data = cntrs.port_xmit_data;
1300 dev->z_port_rcv_data = cntrs.port_rcv_data;
1301 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
1302 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
1304 switch (in_mad->mad_hdr.mgmt_class) {
1305 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1306 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1307 ret = process_subn(ibdev, mad_flags, port_num,
1310 case IB_MGMT_CLASS_PERF_MGMT:
1311 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1314 ret = IB_MAD_RESULT_SUCCESS;