2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <rdma/ib_smi.h>
35 #include "ipath_kernel.h"
36 #include "ipath_verbs.h"
37 #include "ips_common.h"
39 #define IB_SMP_UNSUP_VERSION __constant_htons(0x0004)
40 #define IB_SMP_UNSUP_METHOD __constant_htons(0x0008)
41 #define IB_SMP_UNSUP_METH_ATTR __constant_htons(0x000C)
42 #define IB_SMP_INVALID_FIELD __constant_htons(0x001C)
44 static int reply(struct ib_smp *smp)
47 * The verbs framework will handle the directed/LID route
50 smp->method = IB_MGMT_METHOD_GET_RESP;
51 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
52 smp->status |= IB_SMP_DIRECTION;
53 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
56 static int recv_subn_get_nodedescription(struct ib_smp *smp,
57 struct ib_device *ibdev)
60 smp->status |= IB_SMP_INVALID_FIELD;
62 strncpy(smp->data, ibdev->node_desc, sizeof(smp->data));
80 } __attribute__ ((packed));
82 static int recv_subn_get_nodeinfo(struct ib_smp *smp,
83 struct ib_device *ibdev, u8 port)
85 struct nodeinfo *nip = (struct nodeinfo *)&smp->data;
86 struct ipath_devdata *dd = to_idev(ibdev)->dd;
87 u32 vendor, boardid, majrev, minrev;
90 smp->status |= IB_SMP_INVALID_FIELD;
92 nip->base_version = 1;
93 nip->class_version = 1;
94 nip->node_type = 1; /* channel adapter */
96 * XXX The num_ports value will need a layer function to get
97 * the value if we ever have more than one IB port on a chip.
98 * We will also need to get the GUID for the port.
100 nip->num_ports = ibdev->phys_port_cnt;
101 /* This is already in network order */
102 nip->sys_guid = to_idev(ibdev)->sys_image_guid;
103 nip->node_guid = ipath_layer_get_guid(dd);
104 nip->port_guid = nip->sys_guid;
105 nip->partition_cap = cpu_to_be16(ipath_layer_get_npkeys(dd));
106 nip->device_id = cpu_to_be16(ipath_layer_get_deviceid(dd));
107 ipath_layer_query_device(dd, &vendor, &boardid, &majrev, &minrev);
108 nip->revision = cpu_to_be32((majrev << 16) | minrev);
109 nip->local_port_num = port;
110 nip->vendor_id[0] = 0;
111 nip->vendor_id[1] = vendor >> 8;
112 nip->vendor_id[2] = vendor;
117 static int recv_subn_get_guidinfo(struct ib_smp *smp,
118 struct ib_device *ibdev)
120 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
121 __be64 *p = (__be64 *) smp->data;
123 /* 32 blocks of 8 64-bit GUIDs per block */
125 memset(smp->data, 0, sizeof(smp->data));
128 * We only support one GUID for now. If this changes, the
129 * portinfo.guid_cap field needs to be updated too.
132 /* The first is a copy of the read-only HW GUID. */
133 *p = ipath_layer_get_guid(to_idev(ibdev)->dd);
135 smp->status |= IB_SMP_INVALID_FIELD;
140 static int recv_subn_get_portinfo(struct ib_smp *smp,
141 struct ib_device *ibdev, u8 port)
143 struct ipath_ibdev *dev;
144 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
150 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
151 smp->status |= IB_SMP_INVALID_FIELD;
156 dev = to_idev(ibdev);
158 /* Clear all fields. Only set the non-zero fields. */
159 memset(smp->data, 0, sizeof(smp->data));
161 /* Only return the mkey if the protection field allows it. */
162 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
163 (dev->mkeyprot_resv_lmc >> 6) == 0)
164 pip->mkey = dev->mkey;
165 pip->gid_prefix = dev->gid_prefix;
166 lid = ipath_layer_get_lid(dev->dd);
167 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
168 pip->sm_lid = cpu_to_be16(dev->sm_lid);
169 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
170 /* pip->diag_code; */
171 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
172 pip->local_port_num = port;
173 pip->link_width_enabled = dev->link_width_enabled;
174 pip->link_width_supported = 3; /* 1x or 4x */
175 pip->link_width_active = 2; /* 4x */
176 pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
177 ibcstat = ipath_layer_get_lastibcstat(dev->dd);
178 pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
179 pip->portphysstate_linkdown =
180 (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
181 (ipath_layer_get_linkdowndefaultstate(dev->dd) ? 1 : 2);
182 pip->mkeyprot_resv_lmc = dev->mkeyprot_resv_lmc;
183 pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
184 switch (ipath_layer_get_ibmtu(dev->dd)) {
200 default: /* oops, something is wrong */
204 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
205 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
206 pip->vl_high_limit = dev->vl_high_limit;
207 /* pip->vl_arb_high_cap; // only one VL */
208 /* pip->vl_arb_low_cap; // only one VL */
209 /* InitTypeReply = 0 */
210 pip->inittypereply_mtucap = IB_MTU_4096;
211 // HCAs ignore VLStallCount and HOQLife
212 /* pip->vlstallcnt_hoqlife; */
213 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
214 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
215 /* P_KeyViolations are counted by hardware. */
216 pip->pkey_violations =
217 cpu_to_be16((ipath_layer_get_cr_errpkey(dev->dd) -
218 dev->n_pkey_violations) & 0xFFFF);
219 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
220 /* Only the hardware GUID is supported for now */
222 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
223 /* 32.768 usec. response time (guessing) */
224 pip->resv_resptimevalue = 3;
225 pip->localphyerrors_overrunerrors =
226 (ipath_layer_get_phyerrthreshold(dev->dd) << 4) |
227 ipath_layer_get_overrunthreshold(dev->dd);
228 /* pip->max_credit_hint; */
229 /* pip->link_roundtrip_latency[3]; */
237 static int recv_subn_get_pkeytable(struct ib_smp *smp,
238 struct ib_device *ibdev)
240 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
241 u16 *p = (u16 *) smp->data;
242 __be16 *q = (__be16 *) smp->data;
244 /* 64 blocks of 32 16-bit P_Key entries */
246 memset(smp->data, 0, sizeof(smp->data));
248 struct ipath_ibdev *dev = to_idev(ibdev);
249 unsigned i, n = ipath_layer_get_npkeys(dev->dd);
251 ipath_layer_get_pkeys(dev->dd, p);
253 for (i = 0; i < n; i++)
254 q[i] = cpu_to_be16(p[i]);
256 smp->status |= IB_SMP_INVALID_FIELD;
261 static int recv_subn_set_guidinfo(struct ib_smp *smp,
262 struct ib_device *ibdev)
264 /* The only GUID we support is the first read-only entry. */
265 return recv_subn_get_guidinfo(smp, ibdev);
269 * recv_subn_set_portinfo - set port information
270 * @smp: the incoming SM packet
271 * @ibdev: the infiniband device
272 * @port: the port on the device
274 * Set Portinfo (see ch. 14.2.5.6).
276 static int recv_subn_set_portinfo(struct ib_smp *smp,
277 struct ib_device *ibdev, u8 port)
279 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
280 struct ib_event event;
281 struct ipath_ibdev *dev;
283 char clientrereg = 0;
292 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
295 dev = to_idev(ibdev);
296 event.device = ibdev;
297 event.element.port_num = port;
299 dev->mkey = pip->mkey;
300 dev->gid_prefix = pip->gid_prefix;
301 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
303 lid = be16_to_cpu(pip->lid);
304 if (lid != ipath_layer_get_lid(dev->dd)) {
305 /* Must be a valid unicast LID address. */
306 if (lid == 0 || lid >= IPS_MULTICAST_LID_BASE)
308 ipath_set_sps_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
309 event.event = IB_EVENT_LID_CHANGE;
310 ib_dispatch_event(&event);
313 smlid = be16_to_cpu(pip->sm_lid);
314 if (smlid != dev->sm_lid) {
315 /* Must be a valid unicast LID address. */
316 if (smlid == 0 || smlid >= IPS_MULTICAST_LID_BASE)
319 event.event = IB_EVENT_SM_CHANGE;
320 ib_dispatch_event(&event);
323 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
324 lwe = pip->link_width_enabled;
325 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
328 dev->link_width_enabled = 3; /* 1x or 4x */
330 dev->link_width_enabled = lwe;
332 /* Only 2.5 Gbs supported. */
333 lse = pip->linkspeedactive_enabled & 0xF;
334 if (lse >= 2 && lse <= 0xE)
337 /* Set link down default state. */
338 switch (pip->portphysstate_linkdown & 0xF) {
342 if (ipath_layer_set_linkdowndefaultstate(dev->dd, 1))
346 if (ipath_layer_set_linkdowndefaultstate(dev->dd, 0))
353 dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
354 dev->vl_high_limit = pip->vl_high_limit;
356 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
373 /* XXX We have already partially updated our state! */
376 ipath_layer_set_mtu(dev->dd, mtu);
378 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
380 /* We only support VL0 */
381 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
384 if (pip->mkey_violations == 0)
385 dev->mkey_violations = 0;
388 * Hardware counter can't be reset so snapshot and subtract
391 if (pip->pkey_violations == 0)
392 dev->n_pkey_violations =
393 ipath_layer_get_cr_errpkey(dev->dd);
395 if (pip->qkey_violations == 0)
396 dev->qkey_violations = 0;
398 if (ipath_layer_set_phyerrthreshold(
400 (pip->localphyerrors_overrunerrors >> 4) & 0xF))
403 if (ipath_layer_set_overrunthreshold(
405 (pip->localphyerrors_overrunerrors & 0xF)))
408 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
410 if (pip->clientrereg_resv_subnetto & 0x80) {
412 event.event = IB_EVENT_CLIENT_REREGISTER;
413 ib_dispatch_event(&event);
417 * Do the port state change now that the other link parameters
419 * Changing the port physical state only makes sense if the link
420 * is down or is being set to down.
422 state = pip->linkspeed_portstate & 0xF;
423 flags = ipath_layer_get_flags(dev->dd);
424 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
425 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
429 * Only state changes of DOWN, ARM, and ACTIVE are valid
430 * and must be in the correct state to take effect (see 7.2.6).
439 if (ipath_layer_get_linkdowndefaultstate(dev->dd))
440 lstate = IPATH_IB_LINKDOWN_SLEEP;
442 lstate = IPATH_IB_LINKDOWN;
443 else if (lstate == 1)
444 lstate = IPATH_IB_LINKDOWN_SLEEP;
445 else if (lstate == 2)
446 lstate = IPATH_IB_LINKDOWN;
447 else if (lstate == 3)
448 lstate = IPATH_IB_LINKDOWN_DISABLE;
451 ipath_layer_set_linkstate(dev->dd, lstate);
452 if (flags & IPATH_LINKACTIVE) {
453 event.event = IB_EVENT_PORT_ERR;
454 ib_dispatch_event(&event);
458 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
460 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKARM);
461 if (flags & IPATH_LINKACTIVE) {
462 event.event = IB_EVENT_PORT_ERR;
463 ib_dispatch_event(&event);
467 if (!(flags & IPATH_LINKARMED))
469 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
470 event.event = IB_EVENT_PORT_ACTIVE;
471 ib_dispatch_event(&event);
474 /* XXX We have already partially updated our state! */
478 ret = recv_subn_get_portinfo(smp, ibdev, port);
481 pip->clientrereg_resv_subnetto |= 0x80;
486 smp->status |= IB_SMP_INVALID_FIELD;
487 ret = recv_subn_get_portinfo(smp, ibdev, port);
493 static int recv_subn_set_pkeytable(struct ib_smp *smp,
494 struct ib_device *ibdev)
496 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
497 __be16 *p = (__be16 *) smp->data;
498 u16 *q = (u16 *) smp->data;
499 struct ipath_ibdev *dev = to_idev(ibdev);
500 unsigned i, n = ipath_layer_get_npkeys(dev->dd);
502 for (i = 0; i < n; i++)
503 q[i] = be16_to_cpu(p[i]);
506 ipath_layer_set_pkeys(dev->dd, q) != 0)
507 smp->status |= IB_SMP_INVALID_FIELD;
509 return recv_subn_get_pkeytable(smp, ibdev);
512 #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
513 #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
514 #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
515 #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
516 #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
517 #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
532 } __attribute__ ((packed));
534 struct ib_pma_classportinfo {
539 u8 resp_time_value; /* only lower 5 bits */
540 union ib_gid redirect_gid;
541 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
543 __be16 redirect_pkey;
544 __be32 redirect_qp; /* only lower 24 bits */
545 __be32 redirect_qkey;
546 union ib_gid trap_gid;
547 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
550 __be32 trap_hl_qp; /* 8, 24 bits respectively */
552 } __attribute__ ((packed));
554 struct ib_pma_portsamplescontrol {
558 u8 counter_width; /* only lower 3 bits */
559 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
560 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
561 u8 sample_mechanisms;
562 u8 sample_status; /* only lower 2 bits */
566 __be32 sample_interval;
568 __be16 counter_select[15];
569 } __attribute__ ((packed));
571 struct ib_pma_portsamplesresult {
573 __be16 sample_status; /* only lower 2 bits */
575 } __attribute__ ((packed));
577 struct ib_pma_portsamplesresult_ext {
579 __be16 sample_status; /* only lower 2 bits */
580 __be32 extended_width; /* only upper 2 bits */
582 } __attribute__ ((packed));
584 struct ib_pma_portcounters {
587 __be16 counter_select;
588 __be16 symbol_error_counter;
589 u8 link_error_recovery_counter;
590 u8 link_downed_counter;
591 __be16 port_rcv_errors;
592 __be16 port_rcv_remphys_errors;
593 __be16 port_rcv_switch_relay_errors;
594 __be16 port_xmit_discards;
595 u8 port_xmit_constraint_errors;
596 u8 port_rcv_constraint_errors;
598 u8 lli_ebor_errors; /* 4, 4, bits */
601 __be32 port_xmit_data;
602 __be32 port_rcv_data;
603 __be32 port_xmit_packets;
604 __be32 port_rcv_packets;
605 } __attribute__ ((packed));
607 #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
608 #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
609 #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
610 #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
611 #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
612 #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
613 #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
614 #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
615 #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
616 #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
618 struct ib_pma_portcounters_ext {
621 __be16 counter_select;
623 __be64 port_xmit_data;
624 __be64 port_rcv_data;
625 __be64 port_xmit_packets;
626 __be64 port_rcv_packets;
627 __be64 port_unicast_xmit_packets;
628 __be64 port_unicast_rcv_packets;
629 __be64 port_multicast_xmit_packets;
630 __be64 port_multicast_rcv_packets;
631 } __attribute__ ((packed));
633 #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
634 #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
635 #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
636 #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
637 #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
638 #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
639 #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
640 #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
642 static int recv_pma_get_classportinfo(struct ib_perf *pmp)
644 struct ib_pma_classportinfo *p =
645 (struct ib_pma_classportinfo *)pmp->data;
647 memset(pmp->data, 0, sizeof(pmp->data));
649 if (pmp->attr_mod != 0)
650 pmp->status |= IB_SMP_INVALID_FIELD;
652 /* Indicate AllPortSelect is valid (only one port anyway) */
653 p->cap_mask = __constant_cpu_to_be16(1 << 8);
655 p->class_version = 1;
657 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
660 p->resp_time_value = 18;
662 return reply((struct ib_smp *) pmp);
666 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
667 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
668 * We support 5 counters which only count the mandatory quantities.
670 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
671 #define COUNTER_MASK0_9 \
672 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
673 COUNTER_MASK(1, 1) | \
674 COUNTER_MASK(1, 2) | \
675 COUNTER_MASK(1, 3) | \
678 static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
679 struct ib_device *ibdev, u8 port)
681 struct ib_pma_portsamplescontrol *p =
682 (struct ib_pma_portsamplescontrol *)pmp->data;
683 struct ipath_ibdev *dev = to_idev(ibdev);
685 u8 port_select = p->port_select;
687 memset(pmp->data, 0, sizeof(pmp->data));
689 p->port_select = port_select;
690 if (pmp->attr_mod != 0 ||
691 (port_select != port && port_select != 0xFF))
692 pmp->status |= IB_SMP_INVALID_FIELD;
694 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
695 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
696 * intervals are counted in ticks. Since we use Linux timers, that
697 * count in jiffies, we can't sample for less than 1000 ticks if HZ
698 * == 1000 (4000 ticks if HZ is 250).
700 /* XXX This is WRONG. */
701 p->tick = 250; /* 1 usec. */
702 p->counter_width = 4; /* 32 bit counters */
703 p->counter_mask0_9 = COUNTER_MASK0_9;
704 spin_lock_irqsave(&dev->pending_lock, flags);
705 p->sample_status = dev->pma_sample_status;
706 p->sample_start = cpu_to_be32(dev->pma_sample_start);
707 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
708 p->tag = cpu_to_be16(dev->pma_tag);
709 p->counter_select[0] = dev->pma_counter_select[0];
710 p->counter_select[1] = dev->pma_counter_select[1];
711 p->counter_select[2] = dev->pma_counter_select[2];
712 p->counter_select[3] = dev->pma_counter_select[3];
713 p->counter_select[4] = dev->pma_counter_select[4];
714 spin_unlock_irqrestore(&dev->pending_lock, flags);
716 return reply((struct ib_smp *) pmp);
719 static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
720 struct ib_device *ibdev, u8 port)
722 struct ib_pma_portsamplescontrol *p =
723 (struct ib_pma_portsamplescontrol *)pmp->data;
724 struct ipath_ibdev *dev = to_idev(ibdev);
729 if (pmp->attr_mod != 0 ||
730 (p->port_select != port && p->port_select != 0xFF)) {
731 pmp->status |= IB_SMP_INVALID_FIELD;
732 ret = reply((struct ib_smp *) pmp);
736 start = be32_to_cpu(p->sample_start);
738 spin_lock_irqsave(&dev->pending_lock, flags);
739 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
740 dev->pma_sample_status =
741 IB_PMA_SAMPLE_STATUS_STARTED;
742 dev->pma_sample_start = start;
743 dev->pma_sample_interval =
744 be32_to_cpu(p->sample_interval);
745 dev->pma_tag = be16_to_cpu(p->tag);
746 if (p->counter_select[0])
747 dev->pma_counter_select[0] =
748 p->counter_select[0];
749 if (p->counter_select[1])
750 dev->pma_counter_select[1] =
751 p->counter_select[1];
752 if (p->counter_select[2])
753 dev->pma_counter_select[2] =
754 p->counter_select[2];
755 if (p->counter_select[3])
756 dev->pma_counter_select[3] =
757 p->counter_select[3];
758 if (p->counter_select[4])
759 dev->pma_counter_select[4] =
760 p->counter_select[4];
762 spin_unlock_irqrestore(&dev->pending_lock, flags);
764 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
770 static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
775 case IB_PMA_PORT_XMIT_DATA:
776 ret = dev->ipath_sword;
778 case IB_PMA_PORT_RCV_DATA:
779 ret = dev->ipath_rword;
781 case IB_PMA_PORT_XMIT_PKTS:
782 ret = dev->ipath_spkts;
784 case IB_PMA_PORT_RCV_PKTS:
785 ret = dev->ipath_rpkts;
787 case IB_PMA_PORT_XMIT_WAIT:
788 ret = dev->ipath_xmit_wait;
797 static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
798 struct ib_device *ibdev)
800 struct ib_pma_portsamplesresult *p =
801 (struct ib_pma_portsamplesresult *)pmp->data;
802 struct ipath_ibdev *dev = to_idev(ibdev);
805 memset(pmp->data, 0, sizeof(pmp->data));
806 p->tag = cpu_to_be16(dev->pma_tag);
807 p->sample_status = cpu_to_be16(dev->pma_sample_status);
808 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
809 p->counter[i] = cpu_to_be32(
810 get_counter(dev, dev->pma_counter_select[i]));
812 return reply((struct ib_smp *) pmp);
815 static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
816 struct ib_device *ibdev)
818 struct ib_pma_portsamplesresult_ext *p =
819 (struct ib_pma_portsamplesresult_ext *)pmp->data;
820 struct ipath_ibdev *dev = to_idev(ibdev);
823 memset(pmp->data, 0, sizeof(pmp->data));
824 p->tag = cpu_to_be16(dev->pma_tag);
825 p->sample_status = cpu_to_be16(dev->pma_sample_status);
827 p->extended_width = __constant_cpu_to_be32(0x80000000);
828 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
829 p->counter[i] = cpu_to_be64(
830 get_counter(dev, dev->pma_counter_select[i]));
832 return reply((struct ib_smp *) pmp);
835 static int recv_pma_get_portcounters(struct ib_perf *pmp,
836 struct ib_device *ibdev, u8 port)
838 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
840 struct ipath_ibdev *dev = to_idev(ibdev);
841 struct ipath_layer_counters cntrs;
842 u8 port_select = p->port_select;
844 ipath_layer_get_counters(dev->dd, &cntrs);
846 /* Adjust counters for any resets done. */
847 cntrs.symbol_error_counter -= dev->n_symbol_error_counter;
848 cntrs.link_error_recovery_counter -=
849 dev->n_link_error_recovery_counter;
850 cntrs.link_downed_counter -= dev->n_link_downed_counter;
851 cntrs.port_rcv_errors += dev->rcv_errors;
852 cntrs.port_rcv_errors -= dev->n_port_rcv_errors;
853 cntrs.port_rcv_remphys_errors -= dev->n_port_rcv_remphys_errors;
854 cntrs.port_xmit_discards -= dev->n_port_xmit_discards;
855 cntrs.port_xmit_data -= dev->n_port_xmit_data;
856 cntrs.port_rcv_data -= dev->n_port_rcv_data;
857 cntrs.port_xmit_packets -= dev->n_port_xmit_packets;
858 cntrs.port_rcv_packets -= dev->n_port_rcv_packets;
860 memset(pmp->data, 0, sizeof(pmp->data));
862 p->port_select = port_select;
863 if (pmp->attr_mod != 0 ||
864 (port_select != port && port_select != 0xFF))
865 pmp->status |= IB_SMP_INVALID_FIELD;
867 if (cntrs.symbol_error_counter > 0xFFFFUL)
868 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
870 p->symbol_error_counter =
871 cpu_to_be16((u16)cntrs.symbol_error_counter);
872 if (cntrs.link_error_recovery_counter > 0xFFUL)
873 p->link_error_recovery_counter = 0xFF;
875 p->link_error_recovery_counter =
876 (u8)cntrs.link_error_recovery_counter;
877 if (cntrs.link_downed_counter > 0xFFUL)
878 p->link_downed_counter = 0xFF;
880 p->link_downed_counter = (u8)cntrs.link_downed_counter;
881 if (cntrs.port_rcv_errors > 0xFFFFUL)
882 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
885 cpu_to_be16((u16) cntrs.port_rcv_errors);
886 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
887 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
889 p->port_rcv_remphys_errors =
890 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
891 if (cntrs.port_xmit_discards > 0xFFFFUL)
892 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
894 p->port_xmit_discards =
895 cpu_to_be16((u16)cntrs.port_xmit_discards);
896 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
897 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
899 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
900 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
901 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
903 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
904 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
905 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
907 p->port_xmit_packets =
908 cpu_to_be32((u32)cntrs.port_xmit_packets);
909 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
910 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
912 p->port_rcv_packets =
913 cpu_to_be32((u32) cntrs.port_rcv_packets);
915 return reply((struct ib_smp *) pmp);
918 static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
919 struct ib_device *ibdev, u8 port)
921 struct ib_pma_portcounters_ext *p =
922 (struct ib_pma_portcounters_ext *)pmp->data;
923 struct ipath_ibdev *dev = to_idev(ibdev);
924 u64 swords, rwords, spkts, rpkts, xwait;
925 u8 port_select = p->port_select;
927 ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
930 /* Adjust counters for any resets done. */
931 swords -= dev->n_port_xmit_data;
932 rwords -= dev->n_port_rcv_data;
933 spkts -= dev->n_port_xmit_packets;
934 rpkts -= dev->n_port_rcv_packets;
936 memset(pmp->data, 0, sizeof(pmp->data));
938 p->port_select = port_select;
939 if (pmp->attr_mod != 0 ||
940 (port_select != port && port_select != 0xFF))
941 pmp->status |= IB_SMP_INVALID_FIELD;
943 p->port_xmit_data = cpu_to_be64(swords);
944 p->port_rcv_data = cpu_to_be64(rwords);
945 p->port_xmit_packets = cpu_to_be64(spkts);
946 p->port_rcv_packets = cpu_to_be64(rpkts);
947 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
948 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
949 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
950 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
952 return reply((struct ib_smp *) pmp);
955 static int recv_pma_set_portcounters(struct ib_perf *pmp,
956 struct ib_device *ibdev, u8 port)
958 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
960 struct ipath_ibdev *dev = to_idev(ibdev);
961 struct ipath_layer_counters cntrs;
964 * Since the HW doesn't support clearing counters, we save the
965 * current count and subtract it from future responses.
967 ipath_layer_get_counters(dev->dd, &cntrs);
969 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
970 dev->n_symbol_error_counter = cntrs.symbol_error_counter;
972 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
973 dev->n_link_error_recovery_counter =
974 cntrs.link_error_recovery_counter;
976 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
977 dev->n_link_downed_counter = cntrs.link_downed_counter;
979 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
980 dev->n_port_rcv_errors =
981 cntrs.port_rcv_errors + dev->rcv_errors;
983 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
984 dev->n_port_rcv_remphys_errors =
985 cntrs.port_rcv_remphys_errors;
987 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
988 dev->n_port_xmit_discards = cntrs.port_xmit_discards;
990 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
991 dev->n_port_xmit_data = cntrs.port_xmit_data;
993 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
994 dev->n_port_rcv_data = cntrs.port_rcv_data;
996 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
997 dev->n_port_xmit_packets = cntrs.port_xmit_packets;
999 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1000 dev->n_port_rcv_packets = cntrs.port_rcv_packets;
1002 return recv_pma_get_portcounters(pmp, ibdev, port);
1005 static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1006 struct ib_device *ibdev, u8 port)
1008 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1010 struct ipath_ibdev *dev = to_idev(ibdev);
1011 u64 swords, rwords, spkts, rpkts, xwait;
1013 ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1016 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1017 dev->n_port_xmit_data = swords;
1019 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1020 dev->n_port_rcv_data = rwords;
1022 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1023 dev->n_port_xmit_packets = spkts;
1025 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1026 dev->n_port_rcv_packets = rpkts;
1028 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1029 dev->n_unicast_xmit = 0;
1031 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1032 dev->n_unicast_rcv = 0;
1034 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1035 dev->n_multicast_xmit = 0;
1037 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1038 dev->n_multicast_rcv = 0;
1040 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1043 static int process_subn(struct ib_device *ibdev, int mad_flags,
1044 u8 port_num, struct ib_mad *in_mad,
1045 struct ib_mad *out_mad)
1047 struct ib_smp *smp = (struct ib_smp *)out_mad;
1048 struct ipath_ibdev *dev = to_idev(ibdev);
1052 if (smp->class_version != 1) {
1053 smp->status |= IB_SMP_UNSUP_VERSION;
1058 /* Is the mkey in the process of expiring? */
1059 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1060 /* Clear timeout and mkey protection field. */
1061 dev->mkey_lease_timeout = 0;
1062 dev->mkeyprot_resv_lmc &= 0x3F;
1066 * M_Key checking depends on
1067 * Portinfo:M_Key_protect_bits
1069 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1070 dev->mkey != smp->mkey &&
1071 (smp->method == IB_MGMT_METHOD_SET ||
1072 (smp->method == IB_MGMT_METHOD_GET &&
1073 (dev->mkeyprot_resv_lmc >> 7) != 0))) {
1074 if (dev->mkey_violations != 0xFFFF)
1075 ++dev->mkey_violations;
1076 if (dev->mkey_lease_timeout ||
1077 dev->mkey_lease_period == 0) {
1078 ret = IB_MAD_RESULT_SUCCESS |
1079 IB_MAD_RESULT_CONSUMED;
1082 dev->mkey_lease_timeout = jiffies +
1083 dev->mkey_lease_period * HZ;
1084 /* Future: Generate a trap notice. */
1085 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1087 } else if (dev->mkey_lease_timeout)
1088 dev->mkey_lease_timeout = 0;
1090 switch (smp->method) {
1091 case IB_MGMT_METHOD_GET:
1092 switch (smp->attr_id) {
1093 case IB_SMP_ATTR_NODE_DESC:
1094 ret = recv_subn_get_nodedescription(smp, ibdev);
1096 case IB_SMP_ATTR_NODE_INFO:
1097 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1099 case IB_SMP_ATTR_GUID_INFO:
1100 ret = recv_subn_get_guidinfo(smp, ibdev);
1102 case IB_SMP_ATTR_PORT_INFO:
1103 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1105 case IB_SMP_ATTR_PKEY_TABLE:
1106 ret = recv_subn_get_pkeytable(smp, ibdev);
1108 case IB_SMP_ATTR_SM_INFO:
1109 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1110 ret = IB_MAD_RESULT_SUCCESS |
1111 IB_MAD_RESULT_CONSUMED;
1114 if (dev->port_cap_flags & IB_PORT_SM) {
1115 ret = IB_MAD_RESULT_SUCCESS;
1120 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1125 case IB_MGMT_METHOD_SET:
1126 switch (smp->attr_id) {
1127 case IB_SMP_ATTR_GUID_INFO:
1128 ret = recv_subn_set_guidinfo(smp, ibdev);
1130 case IB_SMP_ATTR_PORT_INFO:
1131 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1133 case IB_SMP_ATTR_PKEY_TABLE:
1134 ret = recv_subn_set_pkeytable(smp, ibdev);
1136 case IB_SMP_ATTR_SM_INFO:
1137 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1138 ret = IB_MAD_RESULT_SUCCESS |
1139 IB_MAD_RESULT_CONSUMED;
1142 if (dev->port_cap_flags & IB_PORT_SM) {
1143 ret = IB_MAD_RESULT_SUCCESS;
1148 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1153 case IB_MGMT_METHOD_GET_RESP:
1155 * The ib_mad module will call us to process responses
1156 * before checking for other consumers.
1157 * Just tell the caller to process it normally.
1159 ret = IB_MAD_RESULT_FAILURE;
1162 smp->status |= IB_SMP_UNSUP_METHOD;
1170 static int process_perf(struct ib_device *ibdev, u8 port_num,
1171 struct ib_mad *in_mad,
1172 struct ib_mad *out_mad)
1174 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1178 if (pmp->class_version != 1) {
1179 pmp->status |= IB_SMP_UNSUP_VERSION;
1180 ret = reply((struct ib_smp *) pmp);
1184 switch (pmp->method) {
1185 case IB_MGMT_METHOD_GET:
1186 switch (pmp->attr_id) {
1187 case IB_PMA_CLASS_PORT_INFO:
1188 ret = recv_pma_get_classportinfo(pmp);
1190 case IB_PMA_PORT_SAMPLES_CONTROL:
1191 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1194 case IB_PMA_PORT_SAMPLES_RESULT:
1195 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1197 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1198 ret = recv_pma_get_portsamplesresult_ext(pmp,
1201 case IB_PMA_PORT_COUNTERS:
1202 ret = recv_pma_get_portcounters(pmp, ibdev,
1205 case IB_PMA_PORT_COUNTERS_EXT:
1206 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1210 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1211 ret = reply((struct ib_smp *) pmp);
1215 case IB_MGMT_METHOD_SET:
1216 switch (pmp->attr_id) {
1217 case IB_PMA_PORT_SAMPLES_CONTROL:
1218 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1221 case IB_PMA_PORT_COUNTERS:
1222 ret = recv_pma_set_portcounters(pmp, ibdev,
1225 case IB_PMA_PORT_COUNTERS_EXT:
1226 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1230 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1231 ret = reply((struct ib_smp *) pmp);
1235 case IB_MGMT_METHOD_GET_RESP:
1237 * The ib_mad module will call us to process responses
1238 * before checking for other consumers.
1239 * Just tell the caller to process it normally.
1241 ret = IB_MAD_RESULT_FAILURE;
1244 pmp->status |= IB_SMP_UNSUP_METHOD;
1245 ret = reply((struct ib_smp *) pmp);
1253 * ipath_process_mad - process an incoming MAD packet
1254 * @ibdev: the infiniband device this packet came in on
1255 * @mad_flags: MAD flags
1256 * @port_num: the port number this packet came in on
1257 * @in_wc: the work completion entry for this packet
1258 * @in_grh: the global route header for this packet
1259 * @in_mad: the incoming MAD
1260 * @out_mad: any outgoing MAD reply
1262 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1263 * interested in processing.
1265 * Note that the verbs framework has already done the MAD sanity checks,
1266 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1269 * This is called by the ib_mad module.
1271 int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1272 struct ib_wc *in_wc, struct ib_grh *in_grh,
1273 struct ib_mad *in_mad, struct ib_mad *out_mad)
1275 struct ipath_ibdev *dev = to_idev(ibdev);
1279 * Snapshot current HW counters to "clear" them.
1280 * This should be done when the driver is loaded except that for
1281 * some reason we get a zillion errors when brining up the link.
1283 if (dev->rcv_errors == 0) {
1284 struct ipath_layer_counters cntrs;
1286 ipath_layer_get_counters(to_idev(ibdev)->dd, &cntrs);
1288 dev->n_symbol_error_counter = cntrs.symbol_error_counter;
1289 dev->n_link_error_recovery_counter =
1290 cntrs.link_error_recovery_counter;
1291 dev->n_link_downed_counter = cntrs.link_downed_counter;
1292 dev->n_port_rcv_errors = cntrs.port_rcv_errors + 1;
1293 dev->n_port_rcv_remphys_errors =
1294 cntrs.port_rcv_remphys_errors;
1295 dev->n_port_xmit_discards = cntrs.port_xmit_discards;
1296 dev->n_port_xmit_data = cntrs.port_xmit_data;
1297 dev->n_port_rcv_data = cntrs.port_rcv_data;
1298 dev->n_port_xmit_packets = cntrs.port_xmit_packets;
1299 dev->n_port_rcv_packets = cntrs.port_rcv_packets;
1301 switch (in_mad->mad_hdr.mgmt_class) {
1302 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1303 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1304 ret = process_subn(ibdev, mad_flags, port_num,
1307 case IB_MGMT_CLASS_PERF_MGMT:
1308 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1311 ret = IB_MAD_RESULT_SUCCESS;