2 * Copyright (c) 2006, 2007 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] = 0;
115 nip->vendor_id[1] = vendor >> 8;
116 nip->vendor_id[2] = vendor;
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;
150 static int get_overrunthreshold(struct ipath_devdata *dd)
152 return (dd->ipath_ibcctrl >>
153 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
154 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
158 * set_overrunthreshold - set the overrun threshold
159 * @dd: the infinipath device
160 * @n: the new threshold
162 * Note that this will only take effect when the link state changes.
164 static int set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
168 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
169 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
172 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
173 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
175 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
176 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
182 static int get_phyerrthreshold(struct ipath_devdata *dd)
184 return (dd->ipath_ibcctrl >>
185 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
186 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
190 * set_phyerrthreshold - set the physical error threshold
191 * @dd: the infinipath device
192 * @n: the new threshold
194 * Note that this will only take effect when the link state changes.
196 static int set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
200 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
201 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
204 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
205 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
207 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
208 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
215 * get_linkdowndefaultstate - get the default linkdown state
216 * @dd: the infinipath device
218 * Returns zero if the default is POLL, 1 if the default is SLEEP.
220 static int get_linkdowndefaultstate(struct ipath_devdata *dd)
222 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
225 static int recv_subn_get_portinfo(struct ib_smp *smp,
226 struct ib_device *ibdev, u8 port)
228 struct ipath_ibdev *dev;
229 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
235 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
236 smp->status |= IB_SMP_INVALID_FIELD;
241 dev = to_idev(ibdev);
243 /* Clear all fields. Only set the non-zero fields. */
244 memset(smp->data, 0, sizeof(smp->data));
246 /* Only return the mkey if the protection field allows it. */
247 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
249 pip->mkey = dev->mkey;
250 pip->gid_prefix = dev->gid_prefix;
251 lid = dev->dd->ipath_lid;
252 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
253 pip->sm_lid = cpu_to_be16(dev->sm_lid);
254 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
255 /* pip->diag_code; */
256 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
257 pip->local_port_num = port;
258 pip->link_width_enabled = dev->link_width_enabled;
259 pip->link_width_supported = 3; /* 1x or 4x */
260 pip->link_width_active = 2; /* 4x */
261 pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
262 ibcstat = dev->dd->ipath_lastibcstat;
263 pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
264 pip->portphysstate_linkdown =
265 (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
266 (get_linkdowndefaultstate(dev->dd) ? 1 : 2);
267 pip->mkeyprot_resv_lmc = (dev->mkeyprot << 6) | dev->dd->ipath_lmc;
268 pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
269 switch (dev->dd->ipath_ibmtu) {
285 default: /* oops, something is wrong */
289 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
290 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
291 pip->vl_high_limit = dev->vl_high_limit;
292 /* pip->vl_arb_high_cap; // only one VL */
293 /* pip->vl_arb_low_cap; // only one VL */
294 /* InitTypeReply = 0 */
296 * Note: the chips support a maximum MTU of 4096, but the driver
297 * hasn't implemented this feature yet, so set the maximum value
300 pip->inittypereply_mtucap = IB_MTU_2048;
301 // HCAs ignore VLStallCount and HOQLife
302 /* pip->vlstallcnt_hoqlife; */
303 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
304 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
305 /* P_KeyViolations are counted by hardware. */
306 pip->pkey_violations =
307 cpu_to_be16((ipath_get_cr_errpkey(dev->dd) -
308 dev->z_pkey_violations) & 0xFFFF);
309 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
310 /* Only the hardware GUID is supported for now */
312 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
313 /* 32.768 usec. response time (guessing) */
314 pip->resv_resptimevalue = 3;
315 pip->localphyerrors_overrunerrors =
316 (get_phyerrthreshold(dev->dd) << 4) |
317 get_overrunthreshold(dev->dd);
318 /* pip->max_credit_hint; */
319 /* pip->link_roundtrip_latency[3]; */
328 * get_pkeys - return the PKEY table for port 0
329 * @dd: the infinipath device
330 * @pkeys: the pkey table is placed here
332 static int get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
334 struct ipath_portdata *pd = dd->ipath_pd[0];
336 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
341 static int recv_subn_get_pkeytable(struct ib_smp *smp,
342 struct ib_device *ibdev)
344 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
345 u16 *p = (u16 *) smp->data;
346 __be16 *q = (__be16 *) smp->data;
348 /* 64 blocks of 32 16-bit P_Key entries */
350 memset(smp->data, 0, sizeof(smp->data));
352 struct ipath_ibdev *dev = to_idev(ibdev);
353 unsigned i, n = ipath_get_npkeys(dev->dd);
355 get_pkeys(dev->dd, p);
357 for (i = 0; i < n; i++)
358 q[i] = cpu_to_be16(p[i]);
360 smp->status |= IB_SMP_INVALID_FIELD;
365 static int recv_subn_set_guidinfo(struct ib_smp *smp,
366 struct ib_device *ibdev)
368 /* The only GUID we support is the first read-only entry. */
369 return recv_subn_get_guidinfo(smp, ibdev);
373 * set_linkdowndefaultstate - set the default linkdown state
374 * @dd: the infinipath device
375 * @sleep: the new state
377 * Note that this will only take effect when the link state changes.
379 static int set_linkdowndefaultstate(struct ipath_devdata *dd, int sleep)
382 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
384 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
385 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
391 * recv_subn_set_portinfo - set port information
392 * @smp: the incoming SM packet
393 * @ibdev: the infiniband device
394 * @port: the port on the device
396 * Set Portinfo (see ch. 14.2.5.6).
398 static int recv_subn_set_portinfo(struct ib_smp *smp,
399 struct ib_device *ibdev, u8 port)
401 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
402 struct ib_event event;
403 struct ipath_ibdev *dev;
404 struct ipath_devdata *dd;
406 char clientrereg = 0;
415 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
418 dev = to_idev(ibdev);
420 event.device = ibdev;
421 event.element.port_num = port;
423 dev->mkey = pip->mkey;
424 dev->gid_prefix = pip->gid_prefix;
425 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
427 lid = be16_to_cpu(pip->lid);
428 if (dd->ipath_lid != lid ||
429 dd->ipath_lmc != (pip->mkeyprot_resv_lmc & 7)) {
430 /* Must be a valid unicast LID address. */
431 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
433 ipath_set_lid(dd, lid, pip->mkeyprot_resv_lmc & 7);
434 event.event = IB_EVENT_LID_CHANGE;
435 ib_dispatch_event(&event);
438 smlid = be16_to_cpu(pip->sm_lid);
439 if (smlid != dev->sm_lid) {
440 /* Must be a valid unicast LID address. */
441 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
444 event.event = IB_EVENT_SM_CHANGE;
445 ib_dispatch_event(&event);
448 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
449 lwe = pip->link_width_enabled;
450 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
453 dev->link_width_enabled = 3; /* 1x or 4x */
455 dev->link_width_enabled = lwe;
457 /* Only 2.5 Gbs supported. */
458 lse = pip->linkspeedactive_enabled & 0xF;
459 if (lse >= 2 && lse <= 0xE)
462 /* Set link down default state. */
463 switch (pip->portphysstate_linkdown & 0xF) {
467 if (set_linkdowndefaultstate(dd, 1))
471 if (set_linkdowndefaultstate(dd, 0))
478 dev->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
479 dev->vl_high_limit = pip->vl_high_limit;
481 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
498 /* XXX We have already partially updated our state! */
501 ipath_set_mtu(dd, mtu);
503 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
505 /* We only support VL0 */
506 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
509 if (pip->mkey_violations == 0)
510 dev->mkey_violations = 0;
513 * Hardware counter can't be reset so snapshot and subtract
516 if (pip->pkey_violations == 0)
517 dev->z_pkey_violations = ipath_get_cr_errpkey(dd);
519 if (pip->qkey_violations == 0)
520 dev->qkey_violations = 0;
522 ore = pip->localphyerrors_overrunerrors;
523 if (set_phyerrthreshold(dd, (ore >> 4) & 0xF))
526 if (set_overrunthreshold(dd, (ore & 0xF)))
529 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
531 if (pip->clientrereg_resv_subnetto & 0x80) {
533 event.event = IB_EVENT_CLIENT_REREGISTER;
534 ib_dispatch_event(&event);
538 * Do the port state change now that the other link parameters
540 * Changing the port physical state only makes sense if the link
541 * is down or is being set to down.
543 state = pip->linkspeed_portstate & 0xF;
544 flags = dd->ipath_flags;
545 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
546 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
550 * Only state changes of DOWN, ARM, and ACTIVE are valid
551 * and must be in the correct state to take effect (see 7.2.6).
560 if (get_linkdowndefaultstate(dd))
561 lstate = IPATH_IB_LINKDOWN_SLEEP;
563 lstate = IPATH_IB_LINKDOWN;
564 else if (lstate == 1)
565 lstate = IPATH_IB_LINKDOWN_SLEEP;
566 else if (lstate == 2)
567 lstate = IPATH_IB_LINKDOWN;
568 else if (lstate == 3)
569 lstate = IPATH_IB_LINKDOWN_DISABLE;
572 ipath_set_linkstate(dd, lstate);
575 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
577 ipath_set_linkstate(dd, IPATH_IB_LINKARM);
580 if (!(flags & IPATH_LINKARMED))
582 ipath_set_linkstate(dd, IPATH_IB_LINKACTIVE);
585 /* XXX We have already partially updated our state! */
589 ret = recv_subn_get_portinfo(smp, ibdev, port);
592 pip->clientrereg_resv_subnetto |= 0x80;
597 smp->status |= IB_SMP_INVALID_FIELD;
598 ret = recv_subn_get_portinfo(smp, ibdev, port);
605 * rm_pkey - decrecment the reference count for the given PKEY
606 * @dd: the infinipath device
607 * @key: the PKEY index
609 * Return true if this was the last reference and the hardware table entry
610 * needs to be changed.
612 static int rm_pkey(struct ipath_devdata *dd, u16 key)
617 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
618 if (dd->ipath_pkeys[i] != key)
620 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
621 dd->ipath_pkeys[i] = 0;
635 * add_pkey - add the given PKEY to the hardware table
636 * @dd: the infinipath device
639 * Return an error code if unable to add the entry, zero if no change,
640 * or 1 if the hardware PKEY register needs to be updated.
642 static int add_pkey(struct ipath_devdata *dd, u16 key)
645 u16 lkey = key & 0x7FFF;
649 if (lkey == 0x7FFF) {
654 /* Look for an empty slot or a matching PKEY. */
655 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
656 if (!dd->ipath_pkeys[i]) {
660 /* If it matches exactly, try to increment the ref count */
661 if (dd->ipath_pkeys[i] == key) {
662 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
666 /* Lost the race. Look for an empty slot below. */
667 atomic_dec(&dd->ipath_pkeyrefs[i]);
671 * It makes no sense to have both the limited and unlimited
672 * PKEY set at the same time since the unlimited one will
673 * disable the limited one.
675 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
684 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
685 if (!dd->ipath_pkeys[i] &&
686 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
687 /* for ipathstats, etc. */
688 ipath_stats.sps_pkeys[i] = lkey;
689 dd->ipath_pkeys[i] = key;
701 * set_pkeys - set the PKEY table for port 0
702 * @dd: the infinipath device
703 * @pkeys: the PKEY table
705 static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
707 struct ipath_portdata *pd;
711 pd = dd->ipath_pd[0];
713 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
715 u16 okey = pd->port_pkeys[i];
720 * The value of this PKEY table entry is changing.
721 * Remove the old entry in the hardware's array of PKEYs.
724 changed |= rm_pkey(dd, okey);
726 int ret = add_pkey(dd, key);
733 pd->port_pkeys[i] = key;
738 pkey = (u64) dd->ipath_pkeys[0] |
739 ((u64) dd->ipath_pkeys[1] << 16) |
740 ((u64) dd->ipath_pkeys[2] << 32) |
741 ((u64) dd->ipath_pkeys[3] << 48);
742 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
743 (unsigned long long) pkey);
744 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
750 static int recv_subn_set_pkeytable(struct ib_smp *smp,
751 struct ib_device *ibdev)
753 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
754 __be16 *p = (__be16 *) smp->data;
755 u16 *q = (u16 *) smp->data;
756 struct ipath_ibdev *dev = to_idev(ibdev);
757 unsigned i, n = ipath_get_npkeys(dev->dd);
759 for (i = 0; i < n; i++)
760 q[i] = be16_to_cpu(p[i]);
762 if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
763 smp->status |= IB_SMP_INVALID_FIELD;
765 return recv_subn_get_pkeytable(smp, ibdev);
768 #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
769 #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
770 #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
771 #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
772 #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
773 #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
788 } __attribute__ ((packed));
790 struct ib_pma_classportinfo {
795 u8 resp_time_value; /* only lower 5 bits */
796 union ib_gid redirect_gid;
797 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
799 __be16 redirect_pkey;
800 __be32 redirect_qp; /* only lower 24 bits */
801 __be32 redirect_qkey;
802 union ib_gid trap_gid;
803 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
806 __be32 trap_hl_qp; /* 8, 24 bits respectively */
808 } __attribute__ ((packed));
810 struct ib_pma_portsamplescontrol {
814 u8 counter_width; /* only lower 3 bits */
815 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
816 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
817 u8 sample_mechanisms;
818 u8 sample_status; /* only lower 2 bits */
822 __be32 sample_interval;
824 __be16 counter_select[15];
825 } __attribute__ ((packed));
827 struct ib_pma_portsamplesresult {
829 __be16 sample_status; /* only lower 2 bits */
831 } __attribute__ ((packed));
833 struct ib_pma_portsamplesresult_ext {
835 __be16 sample_status; /* only lower 2 bits */
836 __be32 extended_width; /* only upper 2 bits */
838 } __attribute__ ((packed));
840 struct ib_pma_portcounters {
843 __be16 counter_select;
844 __be16 symbol_error_counter;
845 u8 link_error_recovery_counter;
846 u8 link_downed_counter;
847 __be16 port_rcv_errors;
848 __be16 port_rcv_remphys_errors;
849 __be16 port_rcv_switch_relay_errors;
850 __be16 port_xmit_discards;
851 u8 port_xmit_constraint_errors;
852 u8 port_rcv_constraint_errors;
854 u8 lli_ebor_errors; /* 4, 4, bits */
857 __be32 port_xmit_data;
858 __be32 port_rcv_data;
859 __be32 port_xmit_packets;
860 __be32 port_rcv_packets;
861 } __attribute__ ((packed));
863 #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
864 #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
865 #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
866 #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
867 #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
868 #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
869 #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
870 #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
871 #define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
872 #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
873 #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
874 #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
875 #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
877 struct ib_pma_portcounters_ext {
880 __be16 counter_select;
882 __be64 port_xmit_data;
883 __be64 port_rcv_data;
884 __be64 port_xmit_packets;
885 __be64 port_rcv_packets;
886 __be64 port_unicast_xmit_packets;
887 __be64 port_unicast_rcv_packets;
888 __be64 port_multicast_xmit_packets;
889 __be64 port_multicast_rcv_packets;
890 } __attribute__ ((packed));
892 #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
893 #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
894 #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
895 #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
896 #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
897 #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
898 #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
899 #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
901 static int recv_pma_get_classportinfo(struct ib_perf *pmp)
903 struct ib_pma_classportinfo *p =
904 (struct ib_pma_classportinfo *)pmp->data;
906 memset(pmp->data, 0, sizeof(pmp->data));
908 if (pmp->attr_mod != 0)
909 pmp->status |= IB_SMP_INVALID_FIELD;
911 /* Indicate AllPortSelect is valid (only one port anyway) */
912 p->cap_mask = __constant_cpu_to_be16(1 << 8);
914 p->class_version = 1;
916 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
919 p->resp_time_value = 18;
921 return reply((struct ib_smp *) pmp);
925 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
926 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
927 * We support 5 counters which only count the mandatory quantities.
929 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
930 #define COUNTER_MASK0_9 \
931 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
932 COUNTER_MASK(1, 1) | \
933 COUNTER_MASK(1, 2) | \
934 COUNTER_MASK(1, 3) | \
937 static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
938 struct ib_device *ibdev, u8 port)
940 struct ib_pma_portsamplescontrol *p =
941 (struct ib_pma_portsamplescontrol *)pmp->data;
942 struct ipath_ibdev *dev = to_idev(ibdev);
944 u8 port_select = p->port_select;
946 memset(pmp->data, 0, sizeof(pmp->data));
948 p->port_select = port_select;
949 if (pmp->attr_mod != 0 ||
950 (port_select != port && port_select != 0xFF))
951 pmp->status |= IB_SMP_INVALID_FIELD;
953 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
954 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
955 * intervals are counted in ticks. Since we use Linux timers, that
956 * count in jiffies, we can't sample for less than 1000 ticks if HZ
957 * == 1000 (4000 ticks if HZ is 250).
959 /* XXX This is WRONG. */
960 p->tick = 250; /* 1 usec. */
961 p->counter_width = 4; /* 32 bit counters */
962 p->counter_mask0_9 = COUNTER_MASK0_9;
963 spin_lock_irqsave(&dev->pending_lock, flags);
964 p->sample_status = dev->pma_sample_status;
965 p->sample_start = cpu_to_be32(dev->pma_sample_start);
966 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
967 p->tag = cpu_to_be16(dev->pma_tag);
968 p->counter_select[0] = dev->pma_counter_select[0];
969 p->counter_select[1] = dev->pma_counter_select[1];
970 p->counter_select[2] = dev->pma_counter_select[2];
971 p->counter_select[3] = dev->pma_counter_select[3];
972 p->counter_select[4] = dev->pma_counter_select[4];
973 spin_unlock_irqrestore(&dev->pending_lock, flags);
975 return reply((struct ib_smp *) pmp);
978 static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
979 struct ib_device *ibdev, u8 port)
981 struct ib_pma_portsamplescontrol *p =
982 (struct ib_pma_portsamplescontrol *)pmp->data;
983 struct ipath_ibdev *dev = to_idev(ibdev);
988 if (pmp->attr_mod != 0 ||
989 (p->port_select != port && p->port_select != 0xFF)) {
990 pmp->status |= IB_SMP_INVALID_FIELD;
991 ret = reply((struct ib_smp *) pmp);
995 start = be32_to_cpu(p->sample_start);
997 spin_lock_irqsave(&dev->pending_lock, flags);
998 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
999 dev->pma_sample_status =
1000 IB_PMA_SAMPLE_STATUS_STARTED;
1001 dev->pma_sample_start = start;
1002 dev->pma_sample_interval =
1003 be32_to_cpu(p->sample_interval);
1004 dev->pma_tag = be16_to_cpu(p->tag);
1005 if (p->counter_select[0])
1006 dev->pma_counter_select[0] =
1007 p->counter_select[0];
1008 if (p->counter_select[1])
1009 dev->pma_counter_select[1] =
1010 p->counter_select[1];
1011 if (p->counter_select[2])
1012 dev->pma_counter_select[2] =
1013 p->counter_select[2];
1014 if (p->counter_select[3])
1015 dev->pma_counter_select[3] =
1016 p->counter_select[3];
1017 if (p->counter_select[4])
1018 dev->pma_counter_select[4] =
1019 p->counter_select[4];
1021 spin_unlock_irqrestore(&dev->pending_lock, flags);
1023 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
1029 static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
1034 case IB_PMA_PORT_XMIT_DATA:
1035 ret = dev->ipath_sword;
1037 case IB_PMA_PORT_RCV_DATA:
1038 ret = dev->ipath_rword;
1040 case IB_PMA_PORT_XMIT_PKTS:
1041 ret = dev->ipath_spkts;
1043 case IB_PMA_PORT_RCV_PKTS:
1044 ret = dev->ipath_rpkts;
1046 case IB_PMA_PORT_XMIT_WAIT:
1047 ret = dev->ipath_xmit_wait;
1056 static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
1057 struct ib_device *ibdev)
1059 struct ib_pma_portsamplesresult *p =
1060 (struct ib_pma_portsamplesresult *)pmp->data;
1061 struct ipath_ibdev *dev = to_idev(ibdev);
1064 memset(pmp->data, 0, sizeof(pmp->data));
1065 p->tag = cpu_to_be16(dev->pma_tag);
1066 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1067 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1068 p->counter[i] = cpu_to_be32(
1069 get_counter(dev, dev->pma_counter_select[i]));
1071 return reply((struct ib_smp *) pmp);
1074 static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
1075 struct ib_device *ibdev)
1077 struct ib_pma_portsamplesresult_ext *p =
1078 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1079 struct ipath_ibdev *dev = to_idev(ibdev);
1082 memset(pmp->data, 0, sizeof(pmp->data));
1083 p->tag = cpu_to_be16(dev->pma_tag);
1084 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1086 p->extended_width = __constant_cpu_to_be32(0x80000000);
1087 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1088 p->counter[i] = cpu_to_be64(
1089 get_counter(dev, dev->pma_counter_select[i]));
1091 return reply((struct ib_smp *) pmp);
1094 static int recv_pma_get_portcounters(struct ib_perf *pmp,
1095 struct ib_device *ibdev, u8 port)
1097 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1099 struct ipath_ibdev *dev = to_idev(ibdev);
1100 struct ipath_verbs_counters cntrs;
1101 u8 port_select = p->port_select;
1103 ipath_get_counters(dev->dd, &cntrs);
1105 /* Adjust counters for any resets done. */
1106 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
1107 cntrs.link_error_recovery_counter -=
1108 dev->z_link_error_recovery_counter;
1109 cntrs.link_downed_counter -= dev->z_link_downed_counter;
1110 cntrs.port_rcv_errors += dev->rcv_errors;
1111 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1112 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1113 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1114 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1115 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1116 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1117 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
1118 cntrs.local_link_integrity_errors -=
1119 dev->z_local_link_integrity_errors;
1120 cntrs.excessive_buffer_overrun_errors -=
1121 dev->z_excessive_buffer_overrun_errors;
1123 memset(pmp->data, 0, sizeof(pmp->data));
1125 p->port_select = port_select;
1126 if (pmp->attr_mod != 0 ||
1127 (port_select != port && port_select != 0xFF))
1128 pmp->status |= IB_SMP_INVALID_FIELD;
1130 if (cntrs.symbol_error_counter > 0xFFFFUL)
1131 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
1133 p->symbol_error_counter =
1134 cpu_to_be16((u16)cntrs.symbol_error_counter);
1135 if (cntrs.link_error_recovery_counter > 0xFFUL)
1136 p->link_error_recovery_counter = 0xFF;
1138 p->link_error_recovery_counter =
1139 (u8)cntrs.link_error_recovery_counter;
1140 if (cntrs.link_downed_counter > 0xFFUL)
1141 p->link_downed_counter = 0xFF;
1143 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1144 if (cntrs.port_rcv_errors > 0xFFFFUL)
1145 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
1147 p->port_rcv_errors =
1148 cpu_to_be16((u16) cntrs.port_rcv_errors);
1149 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1150 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
1152 p->port_rcv_remphys_errors =
1153 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1154 if (cntrs.port_xmit_discards > 0xFFFFUL)
1155 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
1157 p->port_xmit_discards =
1158 cpu_to_be16((u16)cntrs.port_xmit_discards);
1159 if (cntrs.local_link_integrity_errors > 0xFUL)
1160 cntrs.local_link_integrity_errors = 0xFUL;
1161 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1162 cntrs.excessive_buffer_overrun_errors = 0xFUL;
1163 p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
1164 cntrs.excessive_buffer_overrun_errors;
1165 if (dev->n_vl15_dropped > 0xFFFFUL)
1166 p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
1168 p->vl15_dropped = cpu_to_be16((u16)dev->n_vl15_dropped);
1169 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1170 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
1172 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1173 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1174 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
1176 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1177 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1178 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1180 p->port_xmit_packets =
1181 cpu_to_be32((u32)cntrs.port_xmit_packets);
1182 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1183 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1185 p->port_rcv_packets =
1186 cpu_to_be32((u32) cntrs.port_rcv_packets);
1188 return reply((struct ib_smp *) pmp);
1191 static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
1192 struct ib_device *ibdev, u8 port)
1194 struct ib_pma_portcounters_ext *p =
1195 (struct ib_pma_portcounters_ext *)pmp->data;
1196 struct ipath_ibdev *dev = to_idev(ibdev);
1197 u64 swords, rwords, spkts, rpkts, xwait;
1198 u8 port_select = p->port_select;
1200 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1203 /* Adjust counters for any resets done. */
1204 swords -= dev->z_port_xmit_data;
1205 rwords -= dev->z_port_rcv_data;
1206 spkts -= dev->z_port_xmit_packets;
1207 rpkts -= dev->z_port_rcv_packets;
1209 memset(pmp->data, 0, sizeof(pmp->data));
1211 p->port_select = port_select;
1212 if (pmp->attr_mod != 0 ||
1213 (port_select != port && port_select != 0xFF))
1214 pmp->status |= IB_SMP_INVALID_FIELD;
1216 p->port_xmit_data = cpu_to_be64(swords);
1217 p->port_rcv_data = cpu_to_be64(rwords);
1218 p->port_xmit_packets = cpu_to_be64(spkts);
1219 p->port_rcv_packets = cpu_to_be64(rpkts);
1220 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1221 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1222 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1223 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1225 return reply((struct ib_smp *) pmp);
1228 static int recv_pma_set_portcounters(struct ib_perf *pmp,
1229 struct ib_device *ibdev, u8 port)
1231 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1233 struct ipath_ibdev *dev = to_idev(ibdev);
1234 struct ipath_verbs_counters cntrs;
1237 * Since the HW doesn't support clearing counters, we save the
1238 * current count and subtract it from future responses.
1240 ipath_get_counters(dev->dd, &cntrs);
1242 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
1243 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
1245 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
1246 dev->z_link_error_recovery_counter =
1247 cntrs.link_error_recovery_counter;
1249 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
1250 dev->z_link_downed_counter = cntrs.link_downed_counter;
1252 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
1253 dev->z_port_rcv_errors =
1254 cntrs.port_rcv_errors + dev->rcv_errors;
1256 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
1257 dev->z_port_rcv_remphys_errors =
1258 cntrs.port_rcv_remphys_errors;
1260 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
1261 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
1263 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1264 dev->z_local_link_integrity_errors =
1265 cntrs.local_link_integrity_errors;
1267 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1268 dev->z_excessive_buffer_overrun_errors =
1269 cntrs.excessive_buffer_overrun_errors;
1271 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED)
1272 dev->n_vl15_dropped = 0;
1274 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
1275 dev->z_port_xmit_data = cntrs.port_xmit_data;
1277 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
1278 dev->z_port_rcv_data = cntrs.port_rcv_data;
1280 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1281 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
1283 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1284 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
1286 return recv_pma_get_portcounters(pmp, ibdev, port);
1289 static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1290 struct ib_device *ibdev, u8 port)
1292 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1294 struct ipath_ibdev *dev = to_idev(ibdev);
1295 u64 swords, rwords, spkts, rpkts, xwait;
1297 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1300 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1301 dev->z_port_xmit_data = swords;
1303 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1304 dev->z_port_rcv_data = rwords;
1306 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1307 dev->z_port_xmit_packets = spkts;
1309 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1310 dev->z_port_rcv_packets = rpkts;
1312 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1313 dev->n_unicast_xmit = 0;
1315 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1316 dev->n_unicast_rcv = 0;
1318 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1319 dev->n_multicast_xmit = 0;
1321 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1322 dev->n_multicast_rcv = 0;
1324 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1327 static int process_subn(struct ib_device *ibdev, int mad_flags,
1328 u8 port_num, struct ib_mad *in_mad,
1329 struct ib_mad *out_mad)
1331 struct ib_smp *smp = (struct ib_smp *)out_mad;
1332 struct ipath_ibdev *dev = to_idev(ibdev);
1336 if (smp->class_version != 1) {
1337 smp->status |= IB_SMP_UNSUP_VERSION;
1342 /* Is the mkey in the process of expiring? */
1343 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1344 /* Clear timeout and mkey protection field. */
1345 dev->mkey_lease_timeout = 0;
1350 * M_Key checking depends on
1351 * Portinfo:M_Key_protect_bits
1353 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1354 dev->mkey != smp->mkey &&
1355 (smp->method == IB_MGMT_METHOD_SET ||
1356 (smp->method == IB_MGMT_METHOD_GET &&
1357 dev->mkeyprot >= 2))) {
1358 if (dev->mkey_violations != 0xFFFF)
1359 ++dev->mkey_violations;
1360 if (dev->mkey_lease_timeout ||
1361 dev->mkey_lease_period == 0) {
1362 ret = IB_MAD_RESULT_SUCCESS |
1363 IB_MAD_RESULT_CONSUMED;
1366 dev->mkey_lease_timeout = jiffies +
1367 dev->mkey_lease_period * HZ;
1368 /* Future: Generate a trap notice. */
1369 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1371 } else if (dev->mkey_lease_timeout)
1372 dev->mkey_lease_timeout = 0;
1374 switch (smp->method) {
1375 case IB_MGMT_METHOD_GET:
1376 switch (smp->attr_id) {
1377 case IB_SMP_ATTR_NODE_DESC:
1378 ret = recv_subn_get_nodedescription(smp, ibdev);
1380 case IB_SMP_ATTR_NODE_INFO:
1381 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1383 case IB_SMP_ATTR_GUID_INFO:
1384 ret = recv_subn_get_guidinfo(smp, ibdev);
1386 case IB_SMP_ATTR_PORT_INFO:
1387 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1389 case IB_SMP_ATTR_PKEY_TABLE:
1390 ret = recv_subn_get_pkeytable(smp, ibdev);
1392 case IB_SMP_ATTR_SM_INFO:
1393 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1394 ret = IB_MAD_RESULT_SUCCESS |
1395 IB_MAD_RESULT_CONSUMED;
1398 if (dev->port_cap_flags & IB_PORT_SM) {
1399 ret = IB_MAD_RESULT_SUCCESS;
1404 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1409 case IB_MGMT_METHOD_SET:
1410 switch (smp->attr_id) {
1411 case IB_SMP_ATTR_GUID_INFO:
1412 ret = recv_subn_set_guidinfo(smp, ibdev);
1414 case IB_SMP_ATTR_PORT_INFO:
1415 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1417 case IB_SMP_ATTR_PKEY_TABLE:
1418 ret = recv_subn_set_pkeytable(smp, ibdev);
1420 case IB_SMP_ATTR_SM_INFO:
1421 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1422 ret = IB_MAD_RESULT_SUCCESS |
1423 IB_MAD_RESULT_CONSUMED;
1426 if (dev->port_cap_flags & IB_PORT_SM) {
1427 ret = IB_MAD_RESULT_SUCCESS;
1432 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1437 case IB_MGMT_METHOD_GET_RESP:
1439 * The ib_mad module will call us to process responses
1440 * before checking for other consumers.
1441 * Just tell the caller to process it normally.
1443 ret = IB_MAD_RESULT_FAILURE;
1446 smp->status |= IB_SMP_UNSUP_METHOD;
1454 static int process_perf(struct ib_device *ibdev, u8 port_num,
1455 struct ib_mad *in_mad,
1456 struct ib_mad *out_mad)
1458 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1462 if (pmp->class_version != 1) {
1463 pmp->status |= IB_SMP_UNSUP_VERSION;
1464 ret = reply((struct ib_smp *) pmp);
1468 switch (pmp->method) {
1469 case IB_MGMT_METHOD_GET:
1470 switch (pmp->attr_id) {
1471 case IB_PMA_CLASS_PORT_INFO:
1472 ret = recv_pma_get_classportinfo(pmp);
1474 case IB_PMA_PORT_SAMPLES_CONTROL:
1475 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1478 case IB_PMA_PORT_SAMPLES_RESULT:
1479 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1481 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1482 ret = recv_pma_get_portsamplesresult_ext(pmp,
1485 case IB_PMA_PORT_COUNTERS:
1486 ret = recv_pma_get_portcounters(pmp, ibdev,
1489 case IB_PMA_PORT_COUNTERS_EXT:
1490 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1494 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1495 ret = reply((struct ib_smp *) pmp);
1499 case IB_MGMT_METHOD_SET:
1500 switch (pmp->attr_id) {
1501 case IB_PMA_PORT_SAMPLES_CONTROL:
1502 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1505 case IB_PMA_PORT_COUNTERS:
1506 ret = recv_pma_set_portcounters(pmp, ibdev,
1509 case IB_PMA_PORT_COUNTERS_EXT:
1510 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1514 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1515 ret = reply((struct ib_smp *) pmp);
1519 case IB_MGMT_METHOD_GET_RESP:
1521 * The ib_mad module will call us to process responses
1522 * before checking for other consumers.
1523 * Just tell the caller to process it normally.
1525 ret = IB_MAD_RESULT_FAILURE;
1528 pmp->status |= IB_SMP_UNSUP_METHOD;
1529 ret = reply((struct ib_smp *) pmp);
1537 * ipath_process_mad - process an incoming MAD packet
1538 * @ibdev: the infiniband device this packet came in on
1539 * @mad_flags: MAD flags
1540 * @port_num: the port number this packet came in on
1541 * @in_wc: the work completion entry for this packet
1542 * @in_grh: the global route header for this packet
1543 * @in_mad: the incoming MAD
1544 * @out_mad: any outgoing MAD reply
1546 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1547 * interested in processing.
1549 * Note that the verbs framework has already done the MAD sanity checks,
1550 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1553 * This is called by the ib_mad module.
1555 int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1556 struct ib_wc *in_wc, struct ib_grh *in_grh,
1557 struct ib_mad *in_mad, struct ib_mad *out_mad)
1561 switch (in_mad->mad_hdr.mgmt_class) {
1562 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1563 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1564 ret = process_subn(ibdev, mad_flags, port_num,
1567 case IB_MGMT_CLASS_PERF_MGMT:
1568 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1571 ret = IB_MAD_RESULT_SUCCESS;