2 * Copyright (c) 2006, 2007, 2008 QLogic Corporation. 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 "ipath_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;
90 /* GUID 0 is illegal */
91 if (smp->attr_mod || (dd->ipath_guid == 0))
92 smp->status |= IB_SMP_INVALID_FIELD;
94 nip->base_version = 1;
95 nip->class_version = 1;
96 nip->node_type = 1; /* channel adapter */
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.
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;
105 nip->node_guid = dd->ipath_guid;
106 nip->port_guid = dd->ipath_guid;
107 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;
111 nip->revision = cpu_to_be32((majrev << 16) | minrev);
112 nip->local_port_num = port;
113 vendor = dd->ipath_vendorid;
114 nip->vendor_id[0] = IPATH_SRC_OUI_1;
115 nip->vendor_id[1] = IPATH_SRC_OUI_2;
116 nip->vendor_id[2] = IPATH_SRC_OUI_3;
121 static int recv_subn_get_guidinfo(struct ib_smp *smp,
122 struct ib_device *ibdev)
124 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
125 __be64 *p = (__be64 *) smp->data;
127 /* 32 blocks of 8 64-bit GUIDs per block */
129 memset(smp->data, 0, sizeof(smp->data));
132 * We only support one GUID for now. If this changes, the
133 * portinfo.guid_cap field needs to be updated too.
136 __be64 g = to_idev(ibdev)->dd->ipath_guid;
138 /* GUID 0 is illegal */
139 smp->status |= IB_SMP_INVALID_FIELD;
141 /* The first is a copy of the read-only HW GUID. */
144 smp->status |= IB_SMP_INVALID_FIELD;
149 static void set_link_width_enabled(struct ipath_devdata *dd, u32 w)
151 (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, w);
154 static void set_link_speed_enabled(struct ipath_devdata *dd, u32 s)
156 (void) dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, s);
159 static int get_overrunthreshold(struct ipath_devdata *dd)
161 return (dd->ipath_ibcctrl >>
162 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
163 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
167 * set_overrunthreshold - set the overrun threshold
168 * @dd: the infinipath device
169 * @n: the new threshold
171 * Note that this will only take effect when the link state changes.
173 static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
177 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
178 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
181 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
182 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
184 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
185 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
191 static int get_phyerrthreshold(struct ipath_devdata *dd)
193 return (dd->ipath_ibcctrl >>
194 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
195 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
199 * set_phyerrthreshold - set the physical error threshold
200 * @dd: the infinipath device
201 * @n: the new threshold
203 * Note that this will only take effect when the link state changes.
205 static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
209 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
210 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
213 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
214 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
216 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
217 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
224 * get_linkdowndefaultstate - get the default linkdown state
225 * @dd: the infinipath device
227 * Returns zero if the default is POLL, 1 if the default is SLEEP.
229 static int get_linkdowndefaultstate(struct ipath_devdata *dd)
231 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
234 static int recv_subn_get_portinfo(struct ib_smp *smp,
235 struct ib_device *ibdev, u8 port)
237 struct ipath_ibdev *dev;
238 struct ipath_devdata *dd;
239 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
245 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
246 smp->status |= IB_SMP_INVALID_FIELD;
251 dev = to_idev(ibdev);
254 /* Clear all fields. Only set the non-zero fields. */
255 memset(smp->data, 0, sizeof(smp->data));
257 /* Only return the mkey if the protection field allows it. */
258 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
260 pip->mkey = dev->mkey;
261 pip->gid_prefix = dev->gid_prefix;
263 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
264 pip->sm_lid = cpu_to_be16(dev->sm_lid);
265 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
266 /* pip->diag_code; */
267 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
268 pip->local_port_num = port;
269 pip->link_width_enabled = dd->ipath_link_width_enabled;
270 pip->link_width_supported = dd->ipath_link_width_supported;
271 pip->link_width_active = dd->ipath_link_width_active;
272 pip->linkspeed_portstate = dd->ipath_link_speed_supported << 4;
273 ibcstat = dd->ipath_lastibcstat;
274 /* map LinkState to IB portinfo values. */
275 pip->linkspeed_portstate |= ipath_ib_linkstate(dd, ibcstat) + 1;
277 pip->portphysstate_linkdown =
278 (ipath_cvt_physportstate[ibcstat & dd->ibcs_lts_mask] << 4) |
279 (get_linkdowndefaultstate(dd) ? 1 : 2);
280 pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dd->ipath_lmc;
281 pip->linkspeedactive_enabled = (dd->ipath_link_speed_active << 4) |
282 dd->ipath_link_speed_enabled;
283 switch (dd->ipath_ibmtu) {
299 default: /* oops, something is wrong */
303 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
304 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
305 pip->vl_high_limit = dev->vl_high_limit;
306 /* pip->vl_arb_high_cap; // only one VL */
307 /* pip->vl_arb_low_cap; // only one VL */
308 /* InitTypeReply = 0 */
309 /* our mtu cap depends on whether 4K MTU enabled or not */
310 pip->inittypereply_mtucap = ipath_mtu4096 ? IB_MTU_4096 : IB_MTU_2048;
311 /* HCAs ignore VLStallCount and HOQLife */
312 /* pip->vlstallcnt_hoqlife; */
313 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
314 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
315 /* P_KeyViolations are counted by hardware. */
316 pip->pkey_violations =
317 cpu_to_be16((ipath_get_cr_errpkey(dd) -
318 dev->z_pkey_violations) & 0xFFFF);
319 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
320 /* Only the hardware GUID is supported for now */
322 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
323 /* 32.768 usec. response time (guessing) */
324 pip->resv_resptimevalue = 3;
325 pip->localphyerrors_overrunerrors =
326 (get_phyerrthreshold(dd) << 4) |
327 get_overrunthreshold(dd);
328 /* pip->max_credit_hint; */
329 if (dev->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
332 v = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LINKLATENCY);
333 pip->link_roundtrip_latency[0] = v >> 16;
334 pip->link_roundtrip_latency[1] = v >> 8;
335 pip->link_roundtrip_latency[2] = v;
345 * get_pkeys - return the PKEY table for port 0
346 * @dd: the infinipath device
347 * @pkeys: the pkey table is placed here
349 static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
351 /* always a kernel port, no locking needed */
352 struct ipath_portdata *pd = dd->ipath_pd[0];
354 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
359 static int recv_subn_get_pkeytable(struct ib_smp *smp,
360 struct ib_device *ibdev)
362 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
363 u16 *p = (u16 *) smp->data;
364 __be16 *q = (__be16 *) smp->data;
366 /* 64 blocks of 32 16-bit P_Key entries */
368 memset(smp->data, 0, sizeof(smp->data));
370 struct ipath_ibdev *dev = to_idev(ibdev);
371 unsigned i, n = ipath_get_npkeys(dev->dd);
373 get_pkeys(dev->dd, p);
375 for (i = 0; i < n; i++)
376 q[i] = cpu_to_be16(p[i]);
378 smp->status |= IB_SMP_INVALID_FIELD;
383 static int recv_subn_set_guidinfo(struct ib_smp *smp,
384 struct ib_device *ibdev)
386 /* The only GUID we support is the first read-only entry. */
387 return recv_subn_get_guidinfo(smp, ibdev);
391 * set_linkdowndefaultstate - set the default linkdown state
392 * @dd: the infinipath device
393 * @sleep: the new state
395 * Note that this will only take effect when the link state changes.
397 static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
400 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
402 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
403 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
409 * recv_subn_set_portinfo - set port information
410 * @smp: the incoming SM packet
411 * @ibdev: the infiniband device
412 * @port: the port on the device
414 * Set Portinfo (see ch. 14.2.5.6).
416 static int recv_subn_set_portinfo(struct ib_smp *smp,
417 struct ib_device *ibdev, u8 port)
419 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
420 struct ib_event event;
421 struct ipath_ibdev *dev;
422 struct ipath_devdata *dd;
423 char clientrereg = 0;
432 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
435 dev = to_idev(ibdev);
437 event.device = ibdev;
438 event.element.port_num = port;
440 dev->mkey = pip->mkey;
441 dev->gid_prefix = pip->gid_prefix;
442 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
444 lid = be16_to_cpu(pip->lid);
445 if (dd->ipath_lid != lid ||
446 dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
447 /* Must be a valid unicast LID address. */
448 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
450 ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
451 event.event = IB_EVENT_LID_CHANGE;
452 ib_dispatch_event(&event);
455 smlid = be16_to_cpu(pip->sm_lid);
456 if (smlid != dev->sm_lid) {
457 /* Must be a valid unicast LID address. */
458 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
461 event.event = IB_EVENT_SM_CHANGE;
462 ib_dispatch_event(&event);
465 /* Allow 1x or 4x to be set (see 14.2.6.6). */
466 lwe = pip->link_width_enabled;
469 lwe = dd->ipath_link_width_supported;
470 else if (lwe >= 16 || (lwe & ~dd->ipath_link_width_supported))
472 set_link_width_enabled(dd, lwe);
475 /* Allow 2.5 or 5.0 Gbs. */
476 lse = pip->linkspeedactive_enabled & 0xF;
479 lse = dd->ipath_link_speed_supported;
480 else if (lse >= 8 || (lse & ~dd->ipath_link_speed_supported))
482 set_link_speed_enabled(dd, lse);
485 /* Set link down default state. */
486 switch (pip->portphysstate_linkdown & 0xF) {
490 if (set_linkdowndefaultstate(dd, 1))
494 if (set_linkdowndefaultstate(dd, 0))
501 dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
502 dev->vl_high_limit = pip->vl_high_limit;
504 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
523 /* XXX We have already partially updated our state! */
526 ipath_set_mtu(dd, mtu);
528 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
530 /* We only support VL0 */
531 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
534 if (pip->mkey_violations == 0)
535 dev->mkey_violations = 0;
538 * Hardware counter can't be reset so snapshot and subtract
541 if (pip->pkey_violations == 0)
542 dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
544 if (pip->qkey_violations == 0)
545 dev->qkey_violations = 0;
547 ore = pip->localphyerrors_overrunerrors;
548 if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
551 if (set_overrunthreshold(dd, (ore & 0xF)))
554 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
556 if (pip->clientrereg_resv_subnetto & 0x80) {
558 event.event = IB_EVENT_CLIENT_REREGISTER;
559 ib_dispatch_event(&event);
563 * Do the port state change now that the other link parameters
565 * Changing the port physical state only makes sense if the link
566 * is down or is being set to down.
568 state = pip->linkspeed_portstate & 0xF;
569 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
570 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
574 * Only state changes of DOWN, ARM, and ACTIVE are valid
575 * and must be in the correct state to take effect (see 7.2.6).
584 lstate = IPATH_IB_LINKDOWN_ONLY;
585 else if (lstate == 1)
586 lstate = IPATH_IB_LINKDOWN_SLEEP;
587 else if (lstate == 2)
588 lstate = IPATH_IB_LINKDOWN;
589 else if (lstate == 3)
590 lstate = IPATH_IB_LINKDOWN_DISABLE;
593 ipath_set_linkstate(dd, lstate);
594 if (lstate == IPATH_IB_LINKDOWN_DISABLE) {
595 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
598 ipath_wait_linkstate(dd, IPATH_LINKINIT | IPATH_LINKARMED |
599 IPATH_LINKACTIVE, 1000);
602 ipath_set_linkstate(dd, IPATH_IB_LINKARM);
605 ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
608 /* XXX We have already partially updated our state! */
612 ret = recv_subn_get_portinfo(smp, ibdev, port);
615 pip->clientrereg_resv_subnetto |= 0x80;
620 smp->status |= IB_SMP_INVALID_FIELD;
621 ret = recv_subn_get_portinfo(smp, ibdev, port);
628 * rm_pkey - decrecment the reference count for the given PKEY
629 * @dd: the infinipath device
630 * @key: the PKEY index
632 * Return true if this was the last reference and the hardware table entry
633 * needs to be changed.
635 static int rm_pkey(struct ipath_devdata *dd, u16 key)
640 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
641 if (dd->ipath_pkeys[i] != key)
643 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
644 dd->ipath_pkeys[i] = 0;
658 * add_pkey - add the given PKEY to the hardware table
659 * @dd: the infinipath device
662 * Return an error code if unable to add the entry, zero if no change,
663 * or 1 if the hardware PKEY register needs to be updated.
665 static int add_pkey(struct ipath_devdata *dd, u16 key)
668 u16 lkey = key & 0x7FFF;
672 if (lkey == 0x7FFF) {
677 /* Look for an empty slot or a matching PKEY. */
678 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
679 if (!dd->ipath_pkeys[i]) {
683 /* If it matches exactly, try to increment the ref count */
684 if (dd->ipath_pkeys[i] == key) {
685 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
689 /* Lost the race. Look for an empty slot below. */
690 atomic_dec(&dd->ipath_pkeyrefs[i]);
694 * It makes no sense to have both the limited and unlimited
695 * PKEY set at the same time since the unlimited one will
696 * disable the limited one.
698 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
707 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
708 if (!dd->ipath_pkeys[i] &&
709 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
710 /* for ipathstats, etc. */
711 ipath_stats.sps_pkeys[i] = lkey;
712 dd->ipath_pkeys[i] = key;
724 * set_pkeys - set the PKEY table for port 0
725 * @dd: the infinipath device
726 * @pkeys: the PKEY table
728 static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
730 struct ipath_portdata *pd;
734 /* always a kernel port, no locking needed */
735 pd = dd->ipath_pd[0];
737 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
739 u16 okey = pd->port_pkeys[i];
744 * The value of this PKEY table entry is changing.
745 * Remove the old entry in the hardware's array of PKEYs.
748 changed |= rm_pkey(dd, okey);
750 int ret = add_pkey(dd, key);
757 pd->port_pkeys[i] = key;
762 pkey = (u64) dd->ipath_pkeys[0] |
763 ((u64) dd->ipath_pkeys[1] << 16) |
764 ((u64) dd->ipath_pkeys[2] << 32) |
765 ((u64) dd->ipath_pkeys[3] << 48);
766 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
767 (unsigned long long) pkey);
768 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
774 static int recv_subn_set_pkeytable(struct ib_smp *smp,
775 struct ib_device *ibdev)
777 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
778 __be16 *p = (__be16 *) smp->data;
779 u16 *q = (u16 *) smp->data;
780 struct ipath_ibdev *dev = to_idev(ibdev);
781 unsigned i, n = ipath_get_npkeys(dev->dd);
783 for (i = 0; i < n; i++)
784 q[i] = be16_to_cpu(p[i]);
786 if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
787 smp->status |= IB_SMP_INVALID_FIELD;
789 return recv_subn_get_pkeytable(smp, ibdev);
792 #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
793 #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
794 #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
795 #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
796 #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
797 #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
812 } __attribute__ ((packed));
814 struct ib_pma_classportinfo {
819 u8 resp_time_value; /* only lower 5 bits */
820 union ib_gid redirect_gid;
821 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
823 __be16 redirect_pkey;
824 __be32 redirect_qp; /* only lower 24 bits */
825 __be32 redirect_qkey;
826 union ib_gid trap_gid;
827 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
830 __be32 trap_hl_qp; /* 8, 24 bits respectively */
832 } __attribute__ ((packed));
834 struct ib_pma_portsamplescontrol {
838 u8 counter_width; /* only lower 3 bits */
839 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
840 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
841 u8 sample_mechanisms;
842 u8 sample_status; /* only lower 2 bits */
846 __be32 sample_interval;
848 __be16 counter_select[15];
849 } __attribute__ ((packed));
851 struct ib_pma_portsamplesresult {
853 __be16 sample_status; /* only lower 2 bits */
855 } __attribute__ ((packed));
857 struct ib_pma_portsamplesresult_ext {
859 __be16 sample_status; /* only lower 2 bits */
860 __be32 extended_width; /* only upper 2 bits */
862 } __attribute__ ((packed));
864 struct ib_pma_portcounters {
867 __be16 counter_select;
868 __be16 symbol_error_counter;
869 u8 link_error_recovery_counter;
870 u8 link_downed_counter;
871 __be16 port_rcv_errors;
872 __be16 port_rcv_remphys_errors;
873 __be16 port_rcv_switch_relay_errors;
874 __be16 port_xmit_discards;
875 u8 port_xmit_constraint_errors;
876 u8 port_rcv_constraint_errors;
878 u8 lli_ebor_errors; /* 4, 4, bits */
881 __be32 port_xmit_data;
882 __be32 port_rcv_data;
883 __be32 port_xmit_packets;
884 __be32 port_rcv_packets;
885 } __attribute__ ((packed));
887 #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
888 #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
889 #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
890 #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
891 #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
892 #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
893 #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
894 #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
895 #define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
896 #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
897 #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
898 #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
899 #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
901 struct ib_pma_portcounters_ext {
904 __be16 counter_select;
906 __be64 port_xmit_data;
907 __be64 port_rcv_data;
908 __be64 port_xmit_packets;
909 __be64 port_rcv_packets;
910 __be64 port_unicast_xmit_packets;
911 __be64 port_unicast_rcv_packets;
912 __be64 port_multicast_xmit_packets;
913 __be64 port_multicast_rcv_packets;
914 } __attribute__ ((packed));
916 #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
917 #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
918 #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
919 #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
920 #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
921 #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
922 #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
923 #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
925 static int recv_pma_get_classportinfo(struct ib_perf *pmp)
927 struct ib_pma_classportinfo *p =
928 (struct ib_pma_classportinfo *)pmp->data;
930 memset(pmp->data, 0, sizeof(pmp->data));
932 if (pmp->attr_mod != 0)
933 pmp->status |= IB_SMP_INVALID_FIELD;
935 /* Indicate AllPortSelect is valid (only one port anyway) */
936 p->cap_mask = __constant_cpu_to_be16(1 << 8);
938 p->class_version = 1;
940 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
943 p->resp_time_value = 18;
945 return reply((struct ib_smp *) pmp);
949 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
950 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
951 * We support 5 counters which only count the mandatory quantities.
953 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
954 #define COUNTER_MASK0_9 \
955 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
956 COUNTER_MASK(1, 1) | \
957 COUNTER_MASK(1, 2) | \
958 COUNTER_MASK(1, 3) | \
961 static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
962 struct ib_device *ibdev, u8 port)
964 struct ib_pma_portsamplescontrol *p =
965 (struct ib_pma_portsamplescontrol *)pmp->data;
966 struct ipath_ibdev *dev = to_idev(ibdev);
967 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
969 u8 port_select = p->port_select;
971 memset(pmp->data, 0, sizeof(pmp->data));
973 p->port_select = port_select;
974 if (pmp->attr_mod != 0 ||
975 (port_select != port && port_select != 0xFF))
976 pmp->status |= IB_SMP_INVALID_FIELD;
978 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
979 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
980 * intervals are counted in ticks. Since we use Linux timers, that
981 * count in jiffies, we can't sample for less than 1000 ticks if HZ
982 * == 1000 (4000 ticks if HZ is 250). link_speed_active returns 2 for
983 * DDR, 1 for SDR, set the tick to 1 for DDR, 0 for SDR on chips that
984 * have hardware support for delaying packets.
987 p->tick = dev->dd->ipath_link_speed_active - 1;
989 p->tick = 250; /* 1 usec. */
990 p->counter_width = 4; /* 32 bit counters */
991 p->counter_mask0_9 = COUNTER_MASK0_9;
992 spin_lock_irqsave(&dev->pending_lock, flags);
994 p->sample_status = ipath_read_creg32(dev->dd, crp->cr_psstat);
996 p->sample_status = dev->pma_sample_status;
997 p->sample_start = cpu_to_be32(dev->pma_sample_start);
998 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
999 p->tag = cpu_to_be16(dev->pma_tag);
1000 p->counter_select[0] = dev->pma_counter_select[0];
1001 p->counter_select[1] = dev->pma_counter_select[1];
1002 p->counter_select[2] = dev->pma_counter_select[2];
1003 p->counter_select[3] = dev->pma_counter_select[3];
1004 p->counter_select[4] = dev->pma_counter_select[4];
1005 spin_unlock_irqrestore(&dev->pending_lock, flags);
1007 return reply((struct ib_smp *) pmp);
1010 static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
1011 struct ib_device *ibdev, u8 port)
1013 struct ib_pma_portsamplescontrol *p =
1014 (struct ib_pma_portsamplescontrol *)pmp->data;
1015 struct ipath_ibdev *dev = to_idev(ibdev);
1016 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
1017 unsigned long flags;
1021 if (pmp->attr_mod != 0 ||
1022 (p->port_select != port && p->port_select != 0xFF)) {
1023 pmp->status |= IB_SMP_INVALID_FIELD;
1024 ret = reply((struct ib_smp *) pmp);
1028 spin_lock_irqsave(&dev->pending_lock, flags);
1030 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1032 status = dev->pma_sample_status;
1033 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
1034 dev->pma_sample_start = be32_to_cpu(p->sample_start);
1035 dev->pma_sample_interval = be32_to_cpu(p->sample_interval);
1036 dev->pma_tag = be16_to_cpu(p->tag);
1037 dev->pma_counter_select[0] = p->counter_select[0];
1038 dev->pma_counter_select[1] = p->counter_select[1];
1039 dev->pma_counter_select[2] = p->counter_select[2];
1040 dev->pma_counter_select[3] = p->counter_select[3];
1041 dev->pma_counter_select[4] = p->counter_select[4];
1042 if (crp->cr_psstat) {
1043 ipath_write_creg(dev->dd, crp->cr_psinterval,
1044 dev->pma_sample_interval);
1045 ipath_write_creg(dev->dd, crp->cr_psstart,
1046 dev->pma_sample_start);
1048 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
1050 spin_unlock_irqrestore(&dev->pending_lock, flags);
1052 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
1058 static u64 get_counter(struct ipath_ibdev *dev,
1059 struct ipath_cregs const *crp,
1065 case IB_PMA_PORT_XMIT_DATA:
1066 ret = (crp->cr_psxmitdatacount) ?
1067 ipath_read_creg32(dev->dd, crp->cr_psxmitdatacount) :
1070 case IB_PMA_PORT_RCV_DATA:
1071 ret = (crp->cr_psrcvdatacount) ?
1072 ipath_read_creg32(dev->dd, crp->cr_psrcvdatacount) :
1075 case IB_PMA_PORT_XMIT_PKTS:
1076 ret = (crp->cr_psxmitpktscount) ?
1077 ipath_read_creg32(dev->dd, crp->cr_psxmitpktscount) :
1080 case IB_PMA_PORT_RCV_PKTS:
1081 ret = (crp->cr_psrcvpktscount) ?
1082 ipath_read_creg32(dev->dd, crp->cr_psrcvpktscount) :
1085 case IB_PMA_PORT_XMIT_WAIT:
1086 ret = (crp->cr_psxmitwaitcount) ?
1087 ipath_read_creg32(dev->dd, crp->cr_psxmitwaitcount) :
1088 dev->ipath_xmit_wait;
1097 static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
1098 struct ib_device *ibdev)
1100 struct ib_pma_portsamplesresult *p =
1101 (struct ib_pma_portsamplesresult *)pmp->data;
1102 struct ipath_ibdev *dev = to_idev(ibdev);
1103 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
1107 memset(pmp->data, 0, sizeof(pmp->data));
1108 p->tag = cpu_to_be16(dev->pma_tag);
1110 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1112 status = dev->pma_sample_status;
1113 p->sample_status = cpu_to_be16(status);
1114 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1115 p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
1117 get_counter(dev, crp, dev->pma_counter_select[i]));
1119 return reply((struct ib_smp *) pmp);
1122 static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
1123 struct ib_device *ibdev)
1125 struct ib_pma_portsamplesresult_ext *p =
1126 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1127 struct ipath_ibdev *dev = to_idev(ibdev);
1128 struct ipath_cregs const *crp = dev->dd->ipath_cregs;
1132 memset(pmp->data, 0, sizeof(pmp->data));
1133 p->tag = cpu_to_be16(dev->pma_tag);
1135 status = ipath_read_creg32(dev->dd, crp->cr_psstat);
1137 status = dev->pma_sample_status;
1138 p->sample_status = cpu_to_be16(status);
1140 p->extended_width = __constant_cpu_to_be32(0x80000000);
1141 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1142 p->counter[i] = (status != IB_PMA_SAMPLE_STATUS_DONE) ? 0 :
1144 get_counter(dev, crp, dev->pma_counter_select[i]));
1146 return reply((struct ib_smp *) pmp);
1149 static int recv_pma_get_portcounters(struct ib_perf *pmp,
1150 struct ib_device *ibdev, u8 port)
1152 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1154 struct ipath_ibdev *dev = to_idev(ibdev);
1155 struct ipath_verbs_counters cntrs;
1156 u8 port_select = p->port_select;
1158 ipath_get_counters(dev->dd, &cntrs);
1160 /* Adjust counters for any resets done. */
1161 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
1162 cntrs.link_error_recovery_counter -=
1163 dev->z_link_error_recovery_counter;
1164 cntrs.link_downed_counter -= dev->z_link_downed_counter;
1165 cntrs.port_rcv_errors += dev->rcv_errors;
1166 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1167 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1168 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1169 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1170 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1171 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1172 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
1173 cntrs.local_link_integrity_errors -=
1174 dev->z_local_link_integrity_errors;
1175 cntrs.excessive_buffer_overrun_errors -=
1176 dev->z_excessive_buffer_overrun_errors;
1177 cntrs.vl15_dropped -= dev->z_vl15_dropped;
1178 cntrs.vl15_dropped += dev->n_vl15_dropped;
1180 memset(pmp->data, 0, sizeof(pmp->data));
1182 p->port_select = port_select;
1183 if (pmp->attr_mod != 0 ||
1184 (port_select != port && port_select != 0xFF))
1185 pmp->status |= IB_SMP_INVALID_FIELD;
1187 if (cntrs.symbol_error_counter > 0xFFFFUL)
1188 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
1190 p->symbol_error_counter =
1191 cpu_to_be16((u16)cntrs.symbol_error_counter);
1192 if (cntrs.link_error_recovery_counter > 0xFFUL)
1193 p->link_error_recovery_counter = 0xFF;
1195 p->link_error_recovery_counter =
1196 (u8)cntrs.link_error_recovery_counter;
1197 if (cntrs.link_downed_counter > 0xFFUL)
1198 p->link_downed_counter = 0xFF;
1200 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1201 if (cntrs.port_rcv_errors > 0xFFFFUL)
1202 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
1204 p->port_rcv_errors =
1205 cpu_to_be16((u16) cntrs.port_rcv_errors);
1206 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1207 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
1209 p->port_rcv_remphys_errors =
1210 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1211 if (cntrs.port_xmit_discards > 0xFFFFUL)
1212 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
1214 p->port_xmit_discards =
1215 cpu_to_be16((u16)cntrs.port_xmit_discards);
1216 if (cntrs.local_link_integrity_errors > 0xFUL)
1217 cntrs.local_link_integrity_errors = 0xFUL;
1218 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1219 cntrs.excessive_buffer_overrun_errors = 0xFUL;
1220 p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
1221 cntrs.excessive_buffer_overrun_errors;
1222 if (cntrs.vl15_dropped > 0xFFFFUL)
1223 p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
1225 p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
1226 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1227 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
1229 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1230 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1231 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
1233 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1234 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1235 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1237 p->port_xmit_packets =
1238 cpu_to_be32((u32)cntrs.port_xmit_packets);
1239 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1240 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1242 p->port_rcv_packets =
1243 cpu_to_be32((u32) cntrs.port_rcv_packets);
1245 return reply((struct ib_smp *) pmp);
1248 static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
1249 struct ib_device *ibdev, u8 port)
1251 struct ib_pma_portcounters_ext *p =
1252 (struct ib_pma_portcounters_ext *)pmp->data;
1253 struct ipath_ibdev *dev = to_idev(ibdev);
1254 u64 swords, rwords, spkts, rpkts, xwait;
1255 u8 port_select = p->port_select;
1257 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1260 /* Adjust counters for any resets done. */
1261 swords -= dev->z_port_xmit_data;
1262 rwords -= dev->z_port_rcv_data;
1263 spkts -= dev->z_port_xmit_packets;
1264 rpkts -= dev->z_port_rcv_packets;
1266 memset(pmp->data, 0, sizeof(pmp->data));
1268 p->port_select = port_select;
1269 if (pmp->attr_mod != 0 ||
1270 (port_select != port && port_select != 0xFF))
1271 pmp->status |= IB_SMP_INVALID_FIELD;
1273 p->port_xmit_data = cpu_to_be64(swords);
1274 p->port_rcv_data = cpu_to_be64(rwords);
1275 p->port_xmit_packets = cpu_to_be64(spkts);
1276 p->port_rcv_packets = cpu_to_be64(rpkts);
1277 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1278 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1279 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1280 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1282 return reply((struct ib_smp *) pmp);
1285 static int recv_pma_set_portcounters(struct ib_perf *pmp,
1286 struct ib_device *ibdev, u8 port)
1288 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1290 struct ipath_ibdev *dev = to_idev(ibdev);
1291 struct ipath_verbs_counters cntrs;
1294 * Since the HW doesn't support clearing counters, we save the
1295 * current count and subtract it from future responses.
1297 ipath_get_counters(dev->dd, &cntrs);
1299 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
1300 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
1302 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
1303 dev->z_link_error_recovery_counter =
1304 cntrs.link_error_recovery_counter;
1306 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
1307 dev->z_link_downed_counter = cntrs.link_downed_counter;
1309 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
1310 dev->z_port_rcv_errors =
1311 cntrs.port_rcv_errors + dev->rcv_errors;
1313 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
1314 dev->z_port_rcv_remphys_errors =
1315 cntrs.port_rcv_remphys_errors;
1317 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
1318 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
1320 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1321 dev->z_local_link_integrity_errors =
1322 cntrs.local_link_integrity_errors;
1324 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1325 dev->z_excessive_buffer_overrun_errors =
1326 cntrs.excessive_buffer_overrun_errors;
1328 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
1329 dev->n_vl15_dropped = 0;
1330 dev->z_vl15_dropped = cntrs.vl15_dropped;
1333 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
1334 dev->z_port_xmit_data = cntrs.port_xmit_data;
1336 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
1337 dev->z_port_rcv_data = cntrs.port_rcv_data;
1339 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1340 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
1342 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1343 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
1345 return recv_pma_get_portcounters(pmp, ibdev, port);
1348 static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1349 struct ib_device *ibdev, u8 port)
1351 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1353 struct ipath_ibdev *dev = to_idev(ibdev);
1354 u64 swords, rwords, spkts, rpkts, xwait;
1356 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1359 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1360 dev->z_port_xmit_data = swords;
1362 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1363 dev->z_port_rcv_data = rwords;
1365 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1366 dev->z_port_xmit_packets = spkts;
1368 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1369 dev->z_port_rcv_packets = rpkts;
1371 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1372 dev->n_unicast_xmit = 0;
1374 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1375 dev->n_unicast_rcv = 0;
1377 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1378 dev->n_multicast_xmit = 0;
1380 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1381 dev->n_multicast_rcv = 0;
1383 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1386 static int process_subn(struct ib_device *ibdev, int mad_flags,
1387 u8 port_num, struct ib_mad *in_mad,
1388 struct ib_mad *out_mad)
1390 struct ib_smp *smp = (struct ib_smp *)out_mad;
1391 struct ipath_ibdev *dev = to_idev(ibdev);
1395 if (smp->class_version != 1) {
1396 smp->status |= IB_SMP_UNSUP_VERSION;
1401 /* Is the mkey in the process of expiring? */
1402 if (dev->mkey_lease_timeout &&
1403 time_after_eq(jiffies, dev->mkey_lease_timeout)) {
1404 /* Clear timeout and mkey protection field. */
1405 dev->mkey_lease_timeout = 0;
1410 * M_Key checking depends on
1411 * Portinfo:M_Key_protect_bits
1413 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1414 dev->mkey != smp->mkey &&
1415 (smp->method == IB_MGMT_METHOD_SET ||
1416 (smp->method == IB_MGMT_METHOD_GET &&
1417 dev->mkeyprot >= 2))) {
1418 if (dev->mkey_violations != 0xFFFF)
1419 ++dev->mkey_violations;
1420 if (dev->mkey_lease_timeout ||
1421 dev->mkey_lease_period == 0) {
1422 ret = IB_MAD_RESULT_SUCCESS |
1423 IB_MAD_RESULT_CONSUMED;
1426 dev->mkey_lease_timeout = jiffies +
1427 dev->mkey_lease_period * HZ;
1428 /* Future: Generate a trap notice. */
1429 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1431 } else if (dev->mkey_lease_timeout)
1432 dev->mkey_lease_timeout = 0;
1434 switch (smp->method) {
1435 case IB_MGMT_METHOD_GET:
1436 switch (smp->attr_id) {
1437 case IB_SMP_ATTR_NODE_DESC:
1438 ret = recv_subn_get_nodedescription(smp, ibdev);
1440 case IB_SMP_ATTR_NODE_INFO:
1441 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1443 case IB_SMP_ATTR_GUID_INFO:
1444 ret = recv_subn_get_guidinfo(smp, ibdev);
1446 case IB_SMP_ATTR_PORT_INFO:
1447 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1449 case IB_SMP_ATTR_PKEY_TABLE:
1450 ret = recv_subn_get_pkeytable(smp, ibdev);
1452 case IB_SMP_ATTR_SM_INFO:
1453 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1454 ret = IB_MAD_RESULT_SUCCESS |
1455 IB_MAD_RESULT_CONSUMED;
1458 if (dev->port_cap_flags & IB_PORT_SM) {
1459 ret = IB_MAD_RESULT_SUCCESS;
1464 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1469 case IB_MGMT_METHOD_SET:
1470 switch (smp->attr_id) {
1471 case IB_SMP_ATTR_GUID_INFO:
1472 ret = recv_subn_set_guidinfo(smp, ibdev);
1474 case IB_SMP_ATTR_PORT_INFO:
1475 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1477 case IB_SMP_ATTR_PKEY_TABLE:
1478 ret = recv_subn_set_pkeytable(smp, ibdev);
1480 case IB_SMP_ATTR_SM_INFO:
1481 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1482 ret = IB_MAD_RESULT_SUCCESS |
1483 IB_MAD_RESULT_CONSUMED;
1486 if (dev->port_cap_flags & IB_PORT_SM) {
1487 ret = IB_MAD_RESULT_SUCCESS;
1492 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1497 case IB_MGMT_METHOD_TRAP:
1498 case IB_MGMT_METHOD_REPORT:
1499 case IB_MGMT_METHOD_REPORT_RESP:
1500 case IB_MGMT_METHOD_TRAP_REPRESS:
1501 case IB_MGMT_METHOD_GET_RESP:
1503 * The ib_mad module will call us to process responses
1504 * before checking for other consumers.
1505 * Just tell the caller to process it normally.
1507 ret = IB_MAD_RESULT_SUCCESS;
1510 smp->status |= IB_SMP_UNSUP_METHOD;
1518 static int process_perf(struct ib_device *ibdev, u8 port_num,
1519 struct ib_mad *in_mad,
1520 struct ib_mad *out_mad)
1522 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1526 if (pmp->class_version != 1) {
1527 pmp->status |= IB_SMP_UNSUP_VERSION;
1528 ret = reply((struct ib_smp *) pmp);
1532 switch (pmp->method) {
1533 case IB_MGMT_METHOD_GET:
1534 switch (pmp->attr_id) {
1535 case IB_PMA_CLASS_PORT_INFO:
1536 ret = recv_pma_get_classportinfo(pmp);
1538 case IB_PMA_PORT_SAMPLES_CONTROL:
1539 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1542 case IB_PMA_PORT_SAMPLES_RESULT:
1543 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1545 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1546 ret = recv_pma_get_portsamplesresult_ext(pmp,
1549 case IB_PMA_PORT_COUNTERS:
1550 ret = recv_pma_get_portcounters(pmp, ibdev,
1553 case IB_PMA_PORT_COUNTERS_EXT:
1554 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1558 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1559 ret = reply((struct ib_smp *) pmp);
1563 case IB_MGMT_METHOD_SET:
1564 switch (pmp->attr_id) {
1565 case IB_PMA_PORT_SAMPLES_CONTROL:
1566 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1569 case IB_PMA_PORT_COUNTERS:
1570 ret = recv_pma_set_portcounters(pmp, ibdev,
1573 case IB_PMA_PORT_COUNTERS_EXT:
1574 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1578 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1579 ret = reply((struct ib_smp *) pmp);
1583 case IB_MGMT_METHOD_GET_RESP:
1585 * The ib_mad module will call us to process responses
1586 * before checking for other consumers.
1587 * Just tell the caller to process it normally.
1589 ret = IB_MAD_RESULT_SUCCESS;
1592 pmp->status |= IB_SMP_UNSUP_METHOD;
1593 ret = reply((struct ib_smp *) pmp);
1601 * ipath_process_mad - process an incoming MAD packet
1602 * @ibdev: the infiniband device this packet came in on
1603 * @mad_flags: MAD flags
1604 * @port_num: the port number this packet came in on
1605 * @in_wc: the work completion entry for this packet
1606 * @in_grh: the global route header for this packet
1607 * @in_mad: the incoming MAD
1608 * @out_mad: any outgoing MAD reply
1610 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1611 * interested in processing.
1613 * Note that the verbs framework has already done the MAD sanity checks,
1614 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1617 * This is called by the ib_mad module.
1619 int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1620 struct ib_wc *in_wc, struct ib_grh *in_grh,
1621 struct ib_mad *in_mad, struct ib_mad *out_mad)
1625 switch (in_mad->mad_hdr.mgmt_class) {
1626 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1627 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1628 ret = process_subn(ibdev, mad_flags, port_num,
1631 case IB_MGMT_CLASS_PERF_MGMT:
1632 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1635 ret = IB_MAD_RESULT_SUCCESS;