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 "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;
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 = dd->ipath_guid;
105 nip->port_guid = nip->sys_guid;
106 nip->partition_cap = cpu_to_be16(ipath_get_npkeys(dd));
107 nip->device_id = cpu_to_be16(dd->ipath_deviceid);
108 majrev = dd->ipath_majrev;
109 minrev = dd->ipath_minrev;
110 nip->revision = cpu_to_be32((majrev << 16) | minrev);
111 nip->local_port_num = port;
112 vendor = dd->ipath_vendorid;
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 = to_idev(ibdev)->dd->ipath_guid;
138 smp->status |= IB_SMP_INVALID_FIELD;
144 static int get_overrunthreshold(struct ipath_devdata *dd)
146 return (dd->ipath_ibcctrl >>
147 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
148 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
152 * set_overrunthreshold - set the overrun threshold
153 * @dd: the infinipath device
154 * @n: the new threshold
156 * Note that this will only take effect when the link state changes.
158 static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
162 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
163 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
166 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
167 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
169 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
170 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
176 static int get_phyerrthreshold(struct ipath_devdata *dd)
178 return (dd->ipath_ibcctrl >>
179 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
180 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
184 * set_phyerrthreshold - set the physical error threshold
185 * @dd: the infinipath device
186 * @n: the new threshold
188 * Note that this will only take effect when the link state changes.
190 static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
194 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
195 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
198 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
199 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
201 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
202 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
209 * get_linkdowndefaultstate - get the default linkdown state
210 * @dd: the infinipath device
212 * Returns zero if the default is POLL, 1 if the default is SLEEP.
214 static int get_linkdowndefaultstate(struct ipath_devdata *dd)
216 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
219 static int recv_subn_get_portinfo(struct ib_smp *smp,
220 struct ib_device *ibdev, u8 port)
222 struct ipath_ibdev *dev;
223 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
229 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
230 smp->status |= IB_SMP_INVALID_FIELD;
235 dev = to_idev(ibdev);
237 /* Clear all fields. Only set the non-zero fields. */
238 memset(smp->data, 0, sizeof(smp->data));
240 /* Only return the mkey if the protection field allows it. */
241 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
242 (dev->mkeyprot_resv_lmc >> 6) == 0)
243 pip->mkey = dev->mkey;
244 pip->gid_prefix = dev->gid_prefix;
245 lid = dev->dd->ipath_lid;
246 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
247 pip->sm_lid = cpu_to_be16(dev->sm_lid);
248 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
249 /* pip->diag_code; */
250 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
251 pip->local_port_num = port;
252 pip->link_width_enabled = dev->link_width_enabled;
253 pip->link_width_supported = 3; /* 1x or 4x */
254 pip->link_width_active = 2; /* 4x */
255 pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
256 ibcstat = dev->dd->ipath_lastibcstat;
257 pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
258 pip->portphysstate_linkdown =
259 (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
260 (get_linkdowndefaultstate(dev->dd) ? 1 : 2);
261 pip->mkeyprot_resv_lmc = dev->mkeyprot_resv_lmc;
262 pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
263 switch (dev->dd->ipath_ibmtu) {
279 default: /* oops, something is wrong */
283 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
284 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
285 pip->vl_high_limit = dev->vl_high_limit;
286 /* pip->vl_arb_high_cap; // only one VL */
287 /* pip->vl_arb_low_cap; // only one VL */
288 /* InitTypeReply = 0 */
289 pip->inittypereply_mtucap = IB_MTU_4096;
290 // HCAs ignore VLStallCount and HOQLife
291 /* pip->vlstallcnt_hoqlife; */
292 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
293 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
294 /* P_KeyViolations are counted by hardware. */
295 pip->pkey_violations =
296 cpu_to_be16((ipath_get_cr_errpkey(dev->dd) -
297 dev->z_pkey_violations) & 0xFFFF);
298 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
299 /* Only the hardware GUID is supported for now */
301 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
302 /* 32.768 usec. response time (guessing) */
303 pip->resv_resptimevalue = 3;
304 pip->localphyerrors_overrunerrors =
305 (get_phyerrthreshold(dev->dd) << 4) |
306 get_overrunthreshold(dev->dd);
307 /* pip->max_credit_hint; */
308 /* pip->link_roundtrip_latency[3]; */
317 * get_pkeys - return the PKEY table for port 0
318 * @dd: the infinipath device
319 * @pkeys: the pkey table is placed here
321 static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
323 struct ipath_portdata *pd = dd->ipath_pd[0];
325 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
330 static int recv_subn_get_pkeytable(struct ib_smp *smp,
331 struct ib_device *ibdev)
333 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
334 u16 *p = (u16 *) smp->data;
335 __be16 *q = (__be16 *) smp->data;
337 /* 64 blocks of 32 16-bit P_Key entries */
339 memset(smp->data, 0, sizeof(smp->data));
341 struct ipath_ibdev *dev = to_idev(ibdev);
342 unsigned i, n = ipath_get_npkeys(dev->dd);
344 get_pkeys(dev->dd, p);
346 for (i = 0; i < n; i++)
347 q[i] = cpu_to_be16(p[i]);
349 smp->status |= IB_SMP_INVALID_FIELD;
354 static int recv_subn_set_guidinfo(struct ib_smp *smp,
355 struct ib_device *ibdev)
357 /* The only GUID we support is the first read-only entry. */
358 return recv_subn_get_guidinfo(smp, ibdev);
362 * set_linkdowndefaultstate - set the default linkdown state
363 * @dd: the infinipath device
364 * @sleep: the new state
366 * Note that this will only take effect when the link state changes.
368 static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
371 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
373 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
374 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
380 * recv_subn_set_portinfo - set port information
381 * @smp: the incoming SM packet
382 * @ibdev: the infiniband device
383 * @port: the port on the device
385 * Set Portinfo (see ch. 14.2.5.6).
387 static int recv_subn_set_portinfo(struct ib_smp *smp,
388 struct ib_device *ibdev, u8 port)
390 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
391 struct ib_event event;
392 struct ipath_ibdev *dev;
394 char clientrereg = 0;
403 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
406 dev = to_idev(ibdev);
407 event.device = ibdev;
408 event.element.port_num = port;
410 dev->mkey = pip->mkey;
411 dev->gid_prefix = pip->gid_prefix;
412 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
414 lid = be16_to_cpu(pip->lid);
415 if (lid != dev->dd->ipath_lid) {
416 /* Must be a valid unicast LID address. */
417 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
419 ipath_set_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
420 event.event = IB_EVENT_LID_CHANGE;
421 ib_dispatch_event(&event);
424 smlid = be16_to_cpu(pip->sm_lid);
425 if (smlid != dev->sm_lid) {
426 /* Must be a valid unicast LID address. */
427 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
430 event.event = IB_EVENT_SM_CHANGE;
431 ib_dispatch_event(&event);
434 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
435 lwe = pip->link_width_enabled;
436 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
439 dev->link_width_enabled = 3; /* 1x or 4x */
441 dev->link_width_enabled = lwe;
443 /* Only 2.5 Gbs supported. */
444 lse = pip->linkspeedactive_enabled & 0xF;
445 if (lse >= 2 && lse <= 0xE)
448 /* Set link down default state. */
449 switch (pip->portphysstate_linkdown & 0xF) {
453 if (set_linkdowndefaultstate(dev->dd, 1))
457 if (set_linkdowndefaultstate(dev->dd, 0))
464 dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
465 dev->vl_high_limit = pip->vl_high_limit;
467 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
484 /* XXX We have already partially updated our state! */
487 ipath_set_mtu(dev->dd, mtu);
489 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
491 /* We only support VL0 */
492 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
495 if (pip->mkey_violations == 0)
496 dev->mkey_violations = 0;
499 * Hardware counter can't be reset so snapshot and subtract
502 if (pip->pkey_violations == 0)
503 dev->z_pkey_violations = ipath_get_cr_errpkey(dev->dd);
505 if (pip->qkey_violations == 0)
506 dev->qkey_violations = 0;
508 ore = pip->localphyerrors_overrunerrors;
509 if (set_phyerrthreshold(dev->dd, (ore >> 4) & 0xF))
512 if (set_overrunthreshold(dev->dd, (ore & 0xF)))
515 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
517 if (pip->clientrereg_resv_subnetto & 0x80) {
519 event.event = IB_EVENT_CLIENT_REREGISTER;
520 ib_dispatch_event(&event);
524 * Do the port state change now that the other link parameters
526 * Changing the port physical state only makes sense if the link
527 * is down or is being set to down.
529 state = pip->linkspeed_portstate & 0xF;
530 flags = dev->dd->ipath_flags;
531 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
532 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
536 * Only state changes of DOWN, ARM, and ACTIVE are valid
537 * and must be in the correct state to take effect (see 7.2.6).
546 if (get_linkdowndefaultstate(dev->dd))
547 lstate = IPATH_IB_LINKDOWN_SLEEP;
549 lstate = IPATH_IB_LINKDOWN;
550 else if (lstate == 1)
551 lstate = IPATH_IB_LINKDOWN_SLEEP;
552 else if (lstate == 2)
553 lstate = IPATH_IB_LINKDOWN;
554 else if (lstate == 3)
555 lstate = IPATH_IB_LINKDOWN_DISABLE;
558 ipath_set_linkstate(dev->dd, lstate);
559 if (flags & IPATH_LINKACTIVE) {
560 event.event = IB_EVENT_PORT_ERR;
561 ib_dispatch_event(&event);
565 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
567 ipath_set_linkstate(dev->dd, IPATH_IB_LINKARM);
568 if (flags & IPATH_LINKACTIVE) {
569 event.event = IB_EVENT_PORT_ERR;
570 ib_dispatch_event(&event);
574 if (!(flags & IPATH_LINKARMED))
576 ipath_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
577 event.event = IB_EVENT_PORT_ACTIVE;
578 ib_dispatch_event(&event);
581 /* XXX We have already partially updated our state! */
585 ret = recv_subn_get_portinfo(smp, ibdev, port);
588 pip->clientrereg_resv_subnetto |= 0x80;
593 smp->status |= IB_SMP_INVALID_FIELD;
594 ret = recv_subn_get_portinfo(smp, ibdev, port);
601 * rm_pkey - decrecment the reference count for the given PKEY
602 * @dd: the infinipath device
603 * @key: the PKEY index
605 * Return true if this was the last reference and the hardware table entry
606 * needs to be changed.
608 static int rm_pkey(struct ipath_devdata *dd, u16 key)
613 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
614 if (dd->ipath_pkeys[i] != key)
616 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
617 dd->ipath_pkeys[i] = 0;
631 * add_pkey - add the given PKEY to the hardware table
632 * @dd: the infinipath device
635 * Return an error code if unable to add the entry, zero if no change,
636 * or 1 if the hardware PKEY register needs to be updated.
638 static int add_pkey(struct ipath_devdata *dd, u16 key)
641 u16 lkey = key & 0x7FFF;
645 if (lkey == 0x7FFF) {
650 /* Look for an empty slot or a matching PKEY. */
651 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
652 if (!dd->ipath_pkeys[i]) {
656 /* If it matches exactly, try to increment the ref count */
657 if (dd->ipath_pkeys[i] == key) {
658 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
662 /* Lost the race. Look for an empty slot below. */
663 atomic_dec(&dd->ipath_pkeyrefs[i]);
667 * It makes no sense to have both the limited and unlimited
668 * PKEY set at the same time since the unlimited one will
669 * disable the limited one.
671 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
680 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
681 if (!dd->ipath_pkeys[i] &&
682 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
683 /* for ipathstats, etc. */
684 ipath_stats.sps_pkeys[i] = lkey;
685 dd->ipath_pkeys[i] = key;
697 * set_pkeys - set the PKEY table for port 0
698 * @dd: the infinipath device
699 * @pkeys: the PKEY table
701 static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
703 struct ipath_portdata *pd;
707 pd = dd->ipath_pd[0];
709 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
711 u16 okey = pd->port_pkeys[i];
716 * The value of this PKEY table entry is changing.
717 * Remove the old entry in the hardware's array of PKEYs.
720 changed |= rm_pkey(dd, okey);
722 int ret = add_pkey(dd, key);
729 pd->port_pkeys[i] = key;
734 pkey = (u64) dd->ipath_pkeys[0] |
735 ((u64) dd->ipath_pkeys[1] << 16) |
736 ((u64) dd->ipath_pkeys[2] << 32) |
737 ((u64) dd->ipath_pkeys[3] << 48);
738 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
739 (unsigned long long) pkey);
740 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
746 static int recv_subn_set_pkeytable(struct ib_smp *smp,
747 struct ib_device *ibdev)
749 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
750 __be16 *p = (__be16 *) smp->data;
751 u16 *q = (u16 *) smp->data;
752 struct ipath_ibdev *dev = to_idev(ibdev);
753 unsigned i, n = ipath_get_npkeys(dev->dd);
755 for (i = 0; i < n; i++)
756 q[i] = be16_to_cpu(p[i]);
758 if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
759 smp->status |= IB_SMP_INVALID_FIELD;
761 return recv_subn_get_pkeytable(smp, ibdev);
764 #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
765 #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
766 #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
767 #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
768 #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
769 #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
784 } __attribute__ ((packed));
786 struct ib_pma_classportinfo {
791 u8 resp_time_value; /* only lower 5 bits */
792 union ib_gid redirect_gid;
793 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
795 __be16 redirect_pkey;
796 __be32 redirect_qp; /* only lower 24 bits */
797 __be32 redirect_qkey;
798 union ib_gid trap_gid;
799 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
802 __be32 trap_hl_qp; /* 8, 24 bits respectively */
804 } __attribute__ ((packed));
806 struct ib_pma_portsamplescontrol {
810 u8 counter_width; /* only lower 3 bits */
811 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
812 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
813 u8 sample_mechanisms;
814 u8 sample_status; /* only lower 2 bits */
818 __be32 sample_interval;
820 __be16 counter_select[15];
821 } __attribute__ ((packed));
823 struct ib_pma_portsamplesresult {
825 __be16 sample_status; /* only lower 2 bits */
827 } __attribute__ ((packed));
829 struct ib_pma_portsamplesresult_ext {
831 __be16 sample_status; /* only lower 2 bits */
832 __be32 extended_width; /* only upper 2 bits */
834 } __attribute__ ((packed));
836 struct ib_pma_portcounters {
839 __be16 counter_select;
840 __be16 symbol_error_counter;
841 u8 link_error_recovery_counter;
842 u8 link_downed_counter;
843 __be16 port_rcv_errors;
844 __be16 port_rcv_remphys_errors;
845 __be16 port_rcv_switch_relay_errors;
846 __be16 port_xmit_discards;
847 u8 port_xmit_constraint_errors;
848 u8 port_rcv_constraint_errors;
850 u8 lli_ebor_errors; /* 4, 4, bits */
853 __be32 port_xmit_data;
854 __be32 port_rcv_data;
855 __be32 port_xmit_packets;
856 __be32 port_rcv_packets;
857 } __attribute__ ((packed));
859 #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
860 #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
861 #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
862 #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
863 #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
864 #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
865 #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
866 #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
867 #define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
868 #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
869 #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
870 #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
871 #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
873 struct ib_pma_portcounters_ext {
876 __be16 counter_select;
878 __be64 port_xmit_data;
879 __be64 port_rcv_data;
880 __be64 port_xmit_packets;
881 __be64 port_rcv_packets;
882 __be64 port_unicast_xmit_packets;
883 __be64 port_unicast_rcv_packets;
884 __be64 port_multicast_xmit_packets;
885 __be64 port_multicast_rcv_packets;
886 } __attribute__ ((packed));
888 #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
889 #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
890 #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
891 #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
892 #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
893 #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
894 #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
895 #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
897 static int recv_pma_get_classportinfo(struct ib_perf *pmp)
899 struct ib_pma_classportinfo *p =
900 (struct ib_pma_classportinfo *)pmp->data;
902 memset(pmp->data, 0, sizeof(pmp->data));
904 if (pmp->attr_mod != 0)
905 pmp->status |= IB_SMP_INVALID_FIELD;
907 /* Indicate AllPortSelect is valid (only one port anyway) */
908 p->cap_mask = __constant_cpu_to_be16(1 << 8);
910 p->class_version = 1;
912 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
915 p->resp_time_value = 18;
917 return reply((struct ib_smp *) pmp);
921 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
922 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
923 * We support 5 counters which only count the mandatory quantities.
925 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
926 #define COUNTER_MASK0_9 \
927 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
928 COUNTER_MASK(1, 1) | \
929 COUNTER_MASK(1, 2) | \
930 COUNTER_MASK(1, 3) | \
933 static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
934 struct ib_device *ibdev, u8 port)
936 struct ib_pma_portsamplescontrol *p =
937 (struct ib_pma_portsamplescontrol *)pmp->data;
938 struct ipath_ibdev *dev = to_idev(ibdev);
940 u8 port_select = p->port_select;
942 memset(pmp->data, 0, sizeof(pmp->data));
944 p->port_select = port_select;
945 if (pmp->attr_mod != 0 ||
946 (port_select != port && port_select != 0xFF))
947 pmp->status |= IB_SMP_INVALID_FIELD;
949 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
950 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
951 * intervals are counted in ticks. Since we use Linux timers, that
952 * count in jiffies, we can't sample for less than 1000 ticks if HZ
953 * == 1000 (4000 ticks if HZ is 250).
955 /* XXX This is WRONG. */
956 p->tick = 250; /* 1 usec. */
957 p->counter_width = 4; /* 32 bit counters */
958 p->counter_mask0_9 = COUNTER_MASK0_9;
959 spin_lock_irqsave(&dev->pending_lock, flags);
960 p->sample_status = dev->pma_sample_status;
961 p->sample_start = cpu_to_be32(dev->pma_sample_start);
962 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
963 p->tag = cpu_to_be16(dev->pma_tag);
964 p->counter_select[0] = dev->pma_counter_select[0];
965 p->counter_select[1] = dev->pma_counter_select[1];
966 p->counter_select[2] = dev->pma_counter_select[2];
967 p->counter_select[3] = dev->pma_counter_select[3];
968 p->counter_select[4] = dev->pma_counter_select[4];
969 spin_unlock_irqrestore(&dev->pending_lock, flags);
971 return reply((struct ib_smp *) pmp);
974 static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
975 struct ib_device *ibdev, u8 port)
977 struct ib_pma_portsamplescontrol *p =
978 (struct ib_pma_portsamplescontrol *)pmp->data;
979 struct ipath_ibdev *dev = to_idev(ibdev);
984 if (pmp->attr_mod != 0 ||
985 (p->port_select != port && p->port_select != 0xFF)) {
986 pmp->status |= IB_SMP_INVALID_FIELD;
987 ret = reply((struct ib_smp *) pmp);
991 start = be32_to_cpu(p->sample_start);
993 spin_lock_irqsave(&dev->pending_lock, flags);
994 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
995 dev->pma_sample_status =
996 IB_PMA_SAMPLE_STATUS_STARTED;
997 dev->pma_sample_start = start;
998 dev->pma_sample_interval =
999 be32_to_cpu(p->sample_interval);
1000 dev->pma_tag = be16_to_cpu(p->tag);
1001 if (p->counter_select[0])
1002 dev->pma_counter_select[0] =
1003 p->counter_select[0];
1004 if (p->counter_select[1])
1005 dev->pma_counter_select[1] =
1006 p->counter_select[1];
1007 if (p->counter_select[2])
1008 dev->pma_counter_select[2] =
1009 p->counter_select[2];
1010 if (p->counter_select[3])
1011 dev->pma_counter_select[3] =
1012 p->counter_select[3];
1013 if (p->counter_select[4])
1014 dev->pma_counter_select[4] =
1015 p->counter_select[4];
1017 spin_unlock_irqrestore(&dev->pending_lock, flags);
1019 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
1025 static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
1030 case IB_PMA_PORT_XMIT_DATA:
1031 ret = dev->ipath_sword;
1033 case IB_PMA_PORT_RCV_DATA:
1034 ret = dev->ipath_rword;
1036 case IB_PMA_PORT_XMIT_PKTS:
1037 ret = dev->ipath_spkts;
1039 case IB_PMA_PORT_RCV_PKTS:
1040 ret = dev->ipath_rpkts;
1042 case IB_PMA_PORT_XMIT_WAIT:
1043 ret = dev->ipath_xmit_wait;
1052 static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
1053 struct ib_device *ibdev)
1055 struct ib_pma_portsamplesresult *p =
1056 (struct ib_pma_portsamplesresult *)pmp->data;
1057 struct ipath_ibdev *dev = to_idev(ibdev);
1060 memset(pmp->data, 0, sizeof(pmp->data));
1061 p->tag = cpu_to_be16(dev->pma_tag);
1062 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1063 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1064 p->counter[i] = cpu_to_be32(
1065 get_counter(dev, dev->pma_counter_select[i]));
1067 return reply((struct ib_smp *) pmp);
1070 static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
1071 struct ib_device *ibdev)
1073 struct ib_pma_portsamplesresult_ext *p =
1074 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1075 struct ipath_ibdev *dev = to_idev(ibdev);
1078 memset(pmp->data, 0, sizeof(pmp->data));
1079 p->tag = cpu_to_be16(dev->pma_tag);
1080 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1082 p->extended_width = __constant_cpu_to_be32(0x80000000);
1083 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1084 p->counter[i] = cpu_to_be64(
1085 get_counter(dev, dev->pma_counter_select[i]));
1087 return reply((struct ib_smp *) pmp);
1090 static int recv_pma_get_portcounters(struct ib_perf *pmp,
1091 struct ib_device *ibdev, u8 port)
1093 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1095 struct ipath_ibdev *dev = to_idev(ibdev);
1096 struct ipath_verbs_counters cntrs;
1097 u8 port_select = p->port_select;
1099 ipath_get_counters(dev->dd, &cntrs);
1101 /* Adjust counters for any resets done. */
1102 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
1103 cntrs.link_error_recovery_counter -=
1104 dev->z_link_error_recovery_counter;
1105 cntrs.link_downed_counter -= dev->z_link_downed_counter;
1106 cntrs.port_rcv_errors += dev->rcv_errors;
1107 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1108 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1109 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1110 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1111 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1112 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1113 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
1114 cntrs.local_link_integrity_errors -=
1115 dev->z_local_link_integrity_errors;
1116 cntrs.excessive_buffer_overrun_errors -=
1117 dev->z_excessive_buffer_overrun_errors;
1119 memset(pmp->data, 0, sizeof(pmp->data));
1121 p->port_select = port_select;
1122 if (pmp->attr_mod != 0 ||
1123 (port_select != port && port_select != 0xFF))
1124 pmp->status |= IB_SMP_INVALID_FIELD;
1126 if (cntrs.symbol_error_counter > 0xFFFFUL)
1127 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
1129 p->symbol_error_counter =
1130 cpu_to_be16((u16)cntrs.symbol_error_counter);
1131 if (cntrs.link_error_recovery_counter > 0xFFUL)
1132 p->link_error_recovery_counter = 0xFF;
1134 p->link_error_recovery_counter =
1135 (u8)cntrs.link_error_recovery_counter;
1136 if (cntrs.link_downed_counter > 0xFFUL)
1137 p->link_downed_counter = 0xFF;
1139 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1140 if (cntrs.port_rcv_errors > 0xFFFFUL)
1141 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
1143 p->port_rcv_errors =
1144 cpu_to_be16((u16) cntrs.port_rcv_errors);
1145 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1146 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
1148 p->port_rcv_remphys_errors =
1149 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1150 if (cntrs.port_xmit_discards > 0xFFFFUL)
1151 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
1153 p->port_xmit_discards =
1154 cpu_to_be16((u16)cntrs.port_xmit_discards);
1155 if (cntrs.local_link_integrity_errors > 0xFUL)
1156 cntrs.local_link_integrity_errors = 0xFUL;
1157 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1158 cntrs.excessive_buffer_overrun_errors = 0xFUL;
1159 p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
1160 cntrs.excessive_buffer_overrun_errors;
1161 if (dev->n_vl15_dropped > 0xFFFFUL)
1162 p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
1164 p->vl15_dropped = cpu_to_be16((u16)dev->n_vl15_dropped);
1165 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1166 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
1168 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1169 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1170 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
1172 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1173 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1174 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1176 p->port_xmit_packets =
1177 cpu_to_be32((u32)cntrs.port_xmit_packets);
1178 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1179 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1181 p->port_rcv_packets =
1182 cpu_to_be32((u32) cntrs.port_rcv_packets);
1184 return reply((struct ib_smp *) pmp);
1187 static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
1188 struct ib_device *ibdev, u8 port)
1190 struct ib_pma_portcounters_ext *p =
1191 (struct ib_pma_portcounters_ext *)pmp->data;
1192 struct ipath_ibdev *dev = to_idev(ibdev);
1193 u64 swords, rwords, spkts, rpkts, xwait;
1194 u8 port_select = p->port_select;
1196 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1199 /* Adjust counters for any resets done. */
1200 swords -= dev->z_port_xmit_data;
1201 rwords -= dev->z_port_rcv_data;
1202 spkts -= dev->z_port_xmit_packets;
1203 rpkts -= dev->z_port_rcv_packets;
1205 memset(pmp->data, 0, sizeof(pmp->data));
1207 p->port_select = port_select;
1208 if (pmp->attr_mod != 0 ||
1209 (port_select != port && port_select != 0xFF))
1210 pmp->status |= IB_SMP_INVALID_FIELD;
1212 p->port_xmit_data = cpu_to_be64(swords);
1213 p->port_rcv_data = cpu_to_be64(rwords);
1214 p->port_xmit_packets = cpu_to_be64(spkts);
1215 p->port_rcv_packets = cpu_to_be64(rpkts);
1216 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1217 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1218 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1219 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1221 return reply((struct ib_smp *) pmp);
1224 static int recv_pma_set_portcounters(struct ib_perf *pmp,
1225 struct ib_device *ibdev, u8 port)
1227 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1229 struct ipath_ibdev *dev = to_idev(ibdev);
1230 struct ipath_verbs_counters cntrs;
1233 * Since the HW doesn't support clearing counters, we save the
1234 * current count and subtract it from future responses.
1236 ipath_get_counters(dev->dd, &cntrs);
1238 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
1239 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
1241 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
1242 dev->z_link_error_recovery_counter =
1243 cntrs.link_error_recovery_counter;
1245 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
1246 dev->z_link_downed_counter = cntrs.link_downed_counter;
1248 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
1249 dev->z_port_rcv_errors =
1250 cntrs.port_rcv_errors + dev->rcv_errors;
1252 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
1253 dev->z_port_rcv_remphys_errors =
1254 cntrs.port_rcv_remphys_errors;
1256 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
1257 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
1259 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1260 dev->z_local_link_integrity_errors =
1261 cntrs.local_link_integrity_errors;
1263 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1264 dev->z_excessive_buffer_overrun_errors =
1265 cntrs.excessive_buffer_overrun_errors;
1267 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED)
1268 dev->n_vl15_dropped = 0;
1270 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
1271 dev->z_port_xmit_data = cntrs.port_xmit_data;
1273 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
1274 dev->z_port_rcv_data = cntrs.port_rcv_data;
1276 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1277 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
1279 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1280 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
1282 return recv_pma_get_portcounters(pmp, ibdev, port);
1285 static int recv_pma_set_portcounters_ext(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 u64 swords, rwords, spkts, rpkts, xwait;
1293 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1296 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1297 dev->z_port_xmit_data = swords;
1299 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1300 dev->z_port_rcv_data = rwords;
1302 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1303 dev->z_port_xmit_packets = spkts;
1305 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1306 dev->z_port_rcv_packets = rpkts;
1308 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1309 dev->n_unicast_xmit = 0;
1311 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1312 dev->n_unicast_rcv = 0;
1314 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1315 dev->n_multicast_xmit = 0;
1317 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1318 dev->n_multicast_rcv = 0;
1320 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1323 static int process_subn(struct ib_device *ibdev, int mad_flags,
1324 u8 port_num, struct ib_mad *in_mad,
1325 struct ib_mad *out_mad)
1327 struct ib_smp *smp = (struct ib_smp *)out_mad;
1328 struct ipath_ibdev *dev = to_idev(ibdev);
1332 if (smp->class_version != 1) {
1333 smp->status |= IB_SMP_UNSUP_VERSION;
1338 /* Is the mkey in the process of expiring? */
1339 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1340 /* Clear timeout and mkey protection field. */
1341 dev->mkey_lease_timeout = 0;
1342 dev->mkeyprot_resv_lmc &= 0x3F;
1346 * M_Key checking depends on
1347 * Portinfo:M_Key_protect_bits
1349 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1350 dev->mkey != smp->mkey &&
1351 (smp->method == IB_MGMT_METHOD_SET ||
1352 (smp->method == IB_MGMT_METHOD_GET &&
1353 (dev->mkeyprot_resv_lmc >> 7) != 0))) {
1354 if (dev->mkey_violations != 0xFFFF)
1355 ++dev->mkey_violations;
1356 if (dev->mkey_lease_timeout ||
1357 dev->mkey_lease_period == 0) {
1358 ret = IB_MAD_RESULT_SUCCESS |
1359 IB_MAD_RESULT_CONSUMED;
1362 dev->mkey_lease_timeout = jiffies +
1363 dev->mkey_lease_period * HZ;
1364 /* Future: Generate a trap notice. */
1365 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1367 } else if (dev->mkey_lease_timeout)
1368 dev->mkey_lease_timeout = 0;
1370 switch (smp->method) {
1371 case IB_MGMT_METHOD_GET:
1372 switch (smp->attr_id) {
1373 case IB_SMP_ATTR_NODE_DESC:
1374 ret = recv_subn_get_nodedescription(smp, ibdev);
1376 case IB_SMP_ATTR_NODE_INFO:
1377 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1379 case IB_SMP_ATTR_GUID_INFO:
1380 ret = recv_subn_get_guidinfo(smp, ibdev);
1382 case IB_SMP_ATTR_PORT_INFO:
1383 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1385 case IB_SMP_ATTR_PKEY_TABLE:
1386 ret = recv_subn_get_pkeytable(smp, ibdev);
1388 case IB_SMP_ATTR_SM_INFO:
1389 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1390 ret = IB_MAD_RESULT_SUCCESS |
1391 IB_MAD_RESULT_CONSUMED;
1394 if (dev->port_cap_flags & IB_PORT_SM) {
1395 ret = IB_MAD_RESULT_SUCCESS;
1400 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1405 case IB_MGMT_METHOD_SET:
1406 switch (smp->attr_id) {
1407 case IB_SMP_ATTR_GUID_INFO:
1408 ret = recv_subn_set_guidinfo(smp, ibdev);
1410 case IB_SMP_ATTR_PORT_INFO:
1411 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1413 case IB_SMP_ATTR_PKEY_TABLE:
1414 ret = recv_subn_set_pkeytable(smp, ibdev);
1416 case IB_SMP_ATTR_SM_INFO:
1417 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1418 ret = IB_MAD_RESULT_SUCCESS |
1419 IB_MAD_RESULT_CONSUMED;
1422 if (dev->port_cap_flags & IB_PORT_SM) {
1423 ret = IB_MAD_RESULT_SUCCESS;
1428 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1433 case IB_MGMT_METHOD_GET_RESP:
1435 * The ib_mad module will call us to process responses
1436 * before checking for other consumers.
1437 * Just tell the caller to process it normally.
1439 ret = IB_MAD_RESULT_FAILURE;
1442 smp->status |= IB_SMP_UNSUP_METHOD;
1450 static int process_perf(struct ib_device *ibdev, u8 port_num,
1451 struct ib_mad *in_mad,
1452 struct ib_mad *out_mad)
1454 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1458 if (pmp->class_version != 1) {
1459 pmp->status |= IB_SMP_UNSUP_VERSION;
1460 ret = reply((struct ib_smp *) pmp);
1464 switch (pmp->method) {
1465 case IB_MGMT_METHOD_GET:
1466 switch (pmp->attr_id) {
1467 case IB_PMA_CLASS_PORT_INFO:
1468 ret = recv_pma_get_classportinfo(pmp);
1470 case IB_PMA_PORT_SAMPLES_CONTROL:
1471 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1474 case IB_PMA_PORT_SAMPLES_RESULT:
1475 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1477 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1478 ret = recv_pma_get_portsamplesresult_ext(pmp,
1481 case IB_PMA_PORT_COUNTERS:
1482 ret = recv_pma_get_portcounters(pmp, ibdev,
1485 case IB_PMA_PORT_COUNTERS_EXT:
1486 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1490 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1491 ret = reply((struct ib_smp *) pmp);
1495 case IB_MGMT_METHOD_SET:
1496 switch (pmp->attr_id) {
1497 case IB_PMA_PORT_SAMPLES_CONTROL:
1498 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1501 case IB_PMA_PORT_COUNTERS:
1502 ret = recv_pma_set_portcounters(pmp, ibdev,
1505 case IB_PMA_PORT_COUNTERS_EXT:
1506 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1510 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1511 ret = reply((struct ib_smp *) pmp);
1515 case IB_MGMT_METHOD_GET_RESP:
1517 * The ib_mad module will call us to process responses
1518 * before checking for other consumers.
1519 * Just tell the caller to process it normally.
1521 ret = IB_MAD_RESULT_FAILURE;
1524 pmp->status |= IB_SMP_UNSUP_METHOD;
1525 ret = reply((struct ib_smp *) pmp);
1533 * ipath_process_mad - process an incoming MAD packet
1534 * @ibdev: the infiniband device this packet came in on
1535 * @mad_flags: MAD flags
1536 * @port_num: the port number this packet came in on
1537 * @in_wc: the work completion entry for this packet
1538 * @in_grh: the global route header for this packet
1539 * @in_mad: the incoming MAD
1540 * @out_mad: any outgoing MAD reply
1542 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1543 * interested in processing.
1545 * Note that the verbs framework has already done the MAD sanity checks,
1546 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1549 * This is called by the ib_mad module.
1551 int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1552 struct ib_wc *in_wc, struct ib_grh *in_grh,
1553 struct ib_mad *in_mad, struct ib_mad *out_mad)
1557 switch (in_mad->mad_hdr.mgmt_class) {
1558 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1559 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1560 ret = process_subn(ibdev, mad_flags, port_num,
1563 case IB_MGMT_CLASS_PERF_MGMT:
1564 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1567 ret = IB_MAD_RESULT_SUCCESS;