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 ||
248 (dev->mkeyprot_resv_lmc >> 6) == 0)
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_resv_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;
405 char clientrereg = 0;
414 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
417 dev = to_idev(ibdev);
418 event.device = ibdev;
419 event.element.port_num = port;
421 dev->mkey = pip->mkey;
422 dev->gid_prefix = pip->gid_prefix;
423 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
425 lid = be16_to_cpu(pip->lid);
426 if (lid != dev->dd->ipath_lid) {
427 /* Must be a valid unicast LID address. */
428 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE)
430 ipath_set_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
431 event.event = IB_EVENT_LID_CHANGE;
432 ib_dispatch_event(&event);
435 smlid = be16_to_cpu(pip->sm_lid);
436 if (smlid != dev->sm_lid) {
437 /* Must be a valid unicast LID address. */
438 if (smlid == 0 || smlid >= IPATH_MULTICAST_LID_BASE)
441 event.event = IB_EVENT_SM_CHANGE;
442 ib_dispatch_event(&event);
445 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
446 lwe = pip->link_width_enabled;
447 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
450 dev->link_width_enabled = 3; /* 1x or 4x */
452 dev->link_width_enabled = lwe;
454 /* Only 2.5 Gbs supported. */
455 lse = pip->linkspeedactive_enabled & 0xF;
456 if (lse >= 2 && lse <= 0xE)
459 /* Set link down default state. */
460 switch (pip->portphysstate_linkdown & 0xF) {
464 if (set_linkdowndefaultstate(dev->dd, 1))
468 if (set_linkdowndefaultstate(dev->dd, 0))
475 dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
476 dev->vl_high_limit = pip->vl_high_limit;
478 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
495 /* XXX We have already partially updated our state! */
498 ipath_set_mtu(dev->dd, mtu);
500 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
502 /* We only support VL0 */
503 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
506 if (pip->mkey_violations == 0)
507 dev->mkey_violations = 0;
510 * Hardware counter can't be reset so snapshot and subtract
513 if (pip->pkey_violations == 0)
514 dev->z_pkey_violations = ipath_get_cr_errpkey(dev->dd);
516 if (pip->qkey_violations == 0)
517 dev->qkey_violations = 0;
519 ore = pip->localphyerrors_overrunerrors;
520 if (set_phyerrthreshold(dev->dd, (ore >> 4) & 0xF))
523 if (set_overrunthreshold(dev->dd, (ore & 0xF)))
526 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
528 if (pip->clientrereg_resv_subnetto & 0x80) {
530 event.event = IB_EVENT_CLIENT_REREGISTER;
531 ib_dispatch_event(&event);
535 * Do the port state change now that the other link parameters
537 * Changing the port physical state only makes sense if the link
538 * is down or is being set to down.
540 state = pip->linkspeed_portstate & 0xF;
541 flags = dev->dd->ipath_flags;
542 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
543 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
547 * Only state changes of DOWN, ARM, and ACTIVE are valid
548 * and must be in the correct state to take effect (see 7.2.6).
557 if (get_linkdowndefaultstate(dev->dd))
558 lstate = IPATH_IB_LINKDOWN_SLEEP;
560 lstate = IPATH_IB_LINKDOWN;
561 else if (lstate == 1)
562 lstate = IPATH_IB_LINKDOWN_SLEEP;
563 else if (lstate == 2)
564 lstate = IPATH_IB_LINKDOWN;
565 else if (lstate == 3)
566 lstate = IPATH_IB_LINKDOWN_DISABLE;
569 ipath_set_linkstate(dev->dd, lstate);
570 if (flags & IPATH_LINKACTIVE) {
571 event.event = IB_EVENT_PORT_ERR;
572 ib_dispatch_event(&event);
576 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
578 ipath_set_linkstate(dev->dd, IPATH_IB_LINKARM);
579 if (flags & IPATH_LINKACTIVE) {
580 event.event = IB_EVENT_PORT_ERR;
581 ib_dispatch_event(&event);
585 if (!(flags & IPATH_LINKARMED))
587 ipath_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
588 event.event = IB_EVENT_PORT_ACTIVE;
589 ib_dispatch_event(&event);
592 /* XXX We have already partially updated our state! */
596 ret = recv_subn_get_portinfo(smp, ibdev, port);
599 pip->clientrereg_resv_subnetto |= 0x80;
604 smp->status |= IB_SMP_INVALID_FIELD;
605 ret = recv_subn_get_portinfo(smp, ibdev, port);
612 * rm_pkey - decrecment the reference count for the given PKEY
613 * @dd: the infinipath device
614 * @key: the PKEY index
616 * Return true if this was the last reference and the hardware table entry
617 * needs to be changed.
619 static int rm_pkey(struct ipath_devdata *dd, u16 key)
624 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
625 if (dd->ipath_pkeys[i] != key)
627 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
628 dd->ipath_pkeys[i] = 0;
642 * add_pkey - add the given PKEY to the hardware table
643 * @dd: the infinipath device
646 * Return an error code if unable to add the entry, zero if no change,
647 * or 1 if the hardware PKEY register needs to be updated.
649 static int add_pkey(struct ipath_devdata *dd, u16 key)
652 u16 lkey = key & 0x7FFF;
656 if (lkey == 0x7FFF) {
661 /* Look for an empty slot or a matching PKEY. */
662 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
663 if (!dd->ipath_pkeys[i]) {
667 /* If it matches exactly, try to increment the ref count */
668 if (dd->ipath_pkeys[i] == key) {
669 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
673 /* Lost the race. Look for an empty slot below. */
674 atomic_dec(&dd->ipath_pkeyrefs[i]);
678 * It makes no sense to have both the limited and unlimited
679 * PKEY set at the same time since the unlimited one will
680 * disable the limited one.
682 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
691 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
692 if (!dd->ipath_pkeys[i] &&
693 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
694 /* for ipathstats, etc. */
695 ipath_stats.sps_pkeys[i] = lkey;
696 dd->ipath_pkeys[i] = key;
708 * set_pkeys - set the PKEY table for port 0
709 * @dd: the infinipath device
710 * @pkeys: the PKEY table
712 static int set_pkeys(struct ipath_devdata *dd, u16 *pkeys)
714 struct ipath_portdata *pd;
718 pd = dd->ipath_pd[0];
720 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
722 u16 okey = pd->port_pkeys[i];
727 * The value of this PKEY table entry is changing.
728 * Remove the old entry in the hardware's array of PKEYs.
731 changed |= rm_pkey(dd, okey);
733 int ret = add_pkey(dd, key);
740 pd->port_pkeys[i] = key;
745 pkey = (u64) dd->ipath_pkeys[0] |
746 ((u64) dd->ipath_pkeys[1] << 16) |
747 ((u64) dd->ipath_pkeys[2] << 32) |
748 ((u64) dd->ipath_pkeys[3] << 48);
749 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
750 (unsigned long long) pkey);
751 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
757 static int recv_subn_set_pkeytable(struct ib_smp *smp,
758 struct ib_device *ibdev)
760 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
761 __be16 *p = (__be16 *) smp->data;
762 u16 *q = (u16 *) smp->data;
763 struct ipath_ibdev *dev = to_idev(ibdev);
764 unsigned i, n = ipath_get_npkeys(dev->dd);
766 for (i = 0; i < n; i++)
767 q[i] = be16_to_cpu(p[i]);
769 if (startpx != 0 || set_pkeys(dev->dd, q) != 0)
770 smp->status |= IB_SMP_INVALID_FIELD;
772 return recv_subn_get_pkeytable(smp, ibdev);
775 #define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
776 #define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
777 #define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
778 #define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
779 #define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
780 #define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
795 } __attribute__ ((packed));
797 struct ib_pma_classportinfo {
802 u8 resp_time_value; /* only lower 5 bits */
803 union ib_gid redirect_gid;
804 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
806 __be16 redirect_pkey;
807 __be32 redirect_qp; /* only lower 24 bits */
808 __be32 redirect_qkey;
809 union ib_gid trap_gid;
810 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
813 __be32 trap_hl_qp; /* 8, 24 bits respectively */
815 } __attribute__ ((packed));
817 struct ib_pma_portsamplescontrol {
821 u8 counter_width; /* only lower 3 bits */
822 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
823 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
824 u8 sample_mechanisms;
825 u8 sample_status; /* only lower 2 bits */
829 __be32 sample_interval;
831 __be16 counter_select[15];
832 } __attribute__ ((packed));
834 struct ib_pma_portsamplesresult {
836 __be16 sample_status; /* only lower 2 bits */
838 } __attribute__ ((packed));
840 struct ib_pma_portsamplesresult_ext {
842 __be16 sample_status; /* only lower 2 bits */
843 __be32 extended_width; /* only upper 2 bits */
845 } __attribute__ ((packed));
847 struct ib_pma_portcounters {
850 __be16 counter_select;
851 __be16 symbol_error_counter;
852 u8 link_error_recovery_counter;
853 u8 link_downed_counter;
854 __be16 port_rcv_errors;
855 __be16 port_rcv_remphys_errors;
856 __be16 port_rcv_switch_relay_errors;
857 __be16 port_xmit_discards;
858 u8 port_xmit_constraint_errors;
859 u8 port_rcv_constraint_errors;
861 u8 lli_ebor_errors; /* 4, 4, bits */
864 __be32 port_xmit_data;
865 __be32 port_rcv_data;
866 __be32 port_xmit_packets;
867 __be32 port_rcv_packets;
868 } __attribute__ ((packed));
870 #define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
871 #define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
872 #define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
873 #define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
874 #define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
875 #define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
876 #define IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS __constant_htons(0x0200)
877 #define IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS __constant_htons(0x0400)
878 #define IB_PMA_SEL_PORT_VL15_DROPPED __constant_htons(0x0800)
879 #define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
880 #define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
881 #define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
882 #define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
884 struct ib_pma_portcounters_ext {
887 __be16 counter_select;
889 __be64 port_xmit_data;
890 __be64 port_rcv_data;
891 __be64 port_xmit_packets;
892 __be64 port_rcv_packets;
893 __be64 port_unicast_xmit_packets;
894 __be64 port_unicast_rcv_packets;
895 __be64 port_multicast_xmit_packets;
896 __be64 port_multicast_rcv_packets;
897 } __attribute__ ((packed));
899 #define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
900 #define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
901 #define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
902 #define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
903 #define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
904 #define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
905 #define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
906 #define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
908 static int recv_pma_get_classportinfo(struct ib_perf *pmp)
910 struct ib_pma_classportinfo *p =
911 (struct ib_pma_classportinfo *)pmp->data;
913 memset(pmp->data, 0, sizeof(pmp->data));
915 if (pmp->attr_mod != 0)
916 pmp->status |= IB_SMP_INVALID_FIELD;
918 /* Indicate AllPortSelect is valid (only one port anyway) */
919 p->cap_mask = __constant_cpu_to_be16(1 << 8);
921 p->class_version = 1;
923 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
926 p->resp_time_value = 18;
928 return reply((struct ib_smp *) pmp);
932 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
933 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
934 * We support 5 counters which only count the mandatory quantities.
936 #define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
937 #define COUNTER_MASK0_9 \
938 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
939 COUNTER_MASK(1, 1) | \
940 COUNTER_MASK(1, 2) | \
941 COUNTER_MASK(1, 3) | \
944 static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
945 struct ib_device *ibdev, u8 port)
947 struct ib_pma_portsamplescontrol *p =
948 (struct ib_pma_portsamplescontrol *)pmp->data;
949 struct ipath_ibdev *dev = to_idev(ibdev);
951 u8 port_select = p->port_select;
953 memset(pmp->data, 0, sizeof(pmp->data));
955 p->port_select = port_select;
956 if (pmp->attr_mod != 0 ||
957 (port_select != port && port_select != 0xFF))
958 pmp->status |= IB_SMP_INVALID_FIELD;
960 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
961 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
962 * intervals are counted in ticks. Since we use Linux timers, that
963 * count in jiffies, we can't sample for less than 1000 ticks if HZ
964 * == 1000 (4000 ticks if HZ is 250).
966 /* XXX This is WRONG. */
967 p->tick = 250; /* 1 usec. */
968 p->counter_width = 4; /* 32 bit counters */
969 p->counter_mask0_9 = COUNTER_MASK0_9;
970 spin_lock_irqsave(&dev->pending_lock, flags);
971 p->sample_status = dev->pma_sample_status;
972 p->sample_start = cpu_to_be32(dev->pma_sample_start);
973 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
974 p->tag = cpu_to_be16(dev->pma_tag);
975 p->counter_select[0] = dev->pma_counter_select[0];
976 p->counter_select[1] = dev->pma_counter_select[1];
977 p->counter_select[2] = dev->pma_counter_select[2];
978 p->counter_select[3] = dev->pma_counter_select[3];
979 p->counter_select[4] = dev->pma_counter_select[4];
980 spin_unlock_irqrestore(&dev->pending_lock, flags);
982 return reply((struct ib_smp *) pmp);
985 static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
986 struct ib_device *ibdev, u8 port)
988 struct ib_pma_portsamplescontrol *p =
989 (struct ib_pma_portsamplescontrol *)pmp->data;
990 struct ipath_ibdev *dev = to_idev(ibdev);
995 if (pmp->attr_mod != 0 ||
996 (p->port_select != port && p->port_select != 0xFF)) {
997 pmp->status |= IB_SMP_INVALID_FIELD;
998 ret = reply((struct ib_smp *) pmp);
1002 start = be32_to_cpu(p->sample_start);
1004 spin_lock_irqsave(&dev->pending_lock, flags);
1005 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
1006 dev->pma_sample_status =
1007 IB_PMA_SAMPLE_STATUS_STARTED;
1008 dev->pma_sample_start = start;
1009 dev->pma_sample_interval =
1010 be32_to_cpu(p->sample_interval);
1011 dev->pma_tag = be16_to_cpu(p->tag);
1012 if (p->counter_select[0])
1013 dev->pma_counter_select[0] =
1014 p->counter_select[0];
1015 if (p->counter_select[1])
1016 dev->pma_counter_select[1] =
1017 p->counter_select[1];
1018 if (p->counter_select[2])
1019 dev->pma_counter_select[2] =
1020 p->counter_select[2];
1021 if (p->counter_select[3])
1022 dev->pma_counter_select[3] =
1023 p->counter_select[3];
1024 if (p->counter_select[4])
1025 dev->pma_counter_select[4] =
1026 p->counter_select[4];
1028 spin_unlock_irqrestore(&dev->pending_lock, flags);
1030 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
1036 static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
1041 case IB_PMA_PORT_XMIT_DATA:
1042 ret = dev->ipath_sword;
1044 case IB_PMA_PORT_RCV_DATA:
1045 ret = dev->ipath_rword;
1047 case IB_PMA_PORT_XMIT_PKTS:
1048 ret = dev->ipath_spkts;
1050 case IB_PMA_PORT_RCV_PKTS:
1051 ret = dev->ipath_rpkts;
1053 case IB_PMA_PORT_XMIT_WAIT:
1054 ret = dev->ipath_xmit_wait;
1063 static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
1064 struct ib_device *ibdev)
1066 struct ib_pma_portsamplesresult *p =
1067 (struct ib_pma_portsamplesresult *)pmp->data;
1068 struct ipath_ibdev *dev = to_idev(ibdev);
1071 memset(pmp->data, 0, sizeof(pmp->data));
1072 p->tag = cpu_to_be16(dev->pma_tag);
1073 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1074 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1075 p->counter[i] = cpu_to_be32(
1076 get_counter(dev, dev->pma_counter_select[i]));
1078 return reply((struct ib_smp *) pmp);
1081 static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
1082 struct ib_device *ibdev)
1084 struct ib_pma_portsamplesresult_ext *p =
1085 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1086 struct ipath_ibdev *dev = to_idev(ibdev);
1089 memset(pmp->data, 0, sizeof(pmp->data));
1090 p->tag = cpu_to_be16(dev->pma_tag);
1091 p->sample_status = cpu_to_be16(dev->pma_sample_status);
1093 p->extended_width = __constant_cpu_to_be32(0x80000000);
1094 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
1095 p->counter[i] = cpu_to_be64(
1096 get_counter(dev, dev->pma_counter_select[i]));
1098 return reply((struct ib_smp *) pmp);
1101 static int recv_pma_get_portcounters(struct ib_perf *pmp,
1102 struct ib_device *ibdev, u8 port)
1104 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1106 struct ipath_ibdev *dev = to_idev(ibdev);
1107 struct ipath_verbs_counters cntrs;
1108 u8 port_select = p->port_select;
1110 ipath_get_counters(dev->dd, &cntrs);
1112 /* Adjust counters for any resets done. */
1113 cntrs.symbol_error_counter -= dev->z_symbol_error_counter;
1114 cntrs.link_error_recovery_counter -=
1115 dev->z_link_error_recovery_counter;
1116 cntrs.link_downed_counter -= dev->z_link_downed_counter;
1117 cntrs.port_rcv_errors += dev->rcv_errors;
1118 cntrs.port_rcv_errors -= dev->z_port_rcv_errors;
1119 cntrs.port_rcv_remphys_errors -= dev->z_port_rcv_remphys_errors;
1120 cntrs.port_xmit_discards -= dev->z_port_xmit_discards;
1121 cntrs.port_xmit_data -= dev->z_port_xmit_data;
1122 cntrs.port_rcv_data -= dev->z_port_rcv_data;
1123 cntrs.port_xmit_packets -= dev->z_port_xmit_packets;
1124 cntrs.port_rcv_packets -= dev->z_port_rcv_packets;
1125 cntrs.local_link_integrity_errors -=
1126 dev->z_local_link_integrity_errors;
1127 cntrs.excessive_buffer_overrun_errors -=
1128 dev->z_excessive_buffer_overrun_errors;
1130 memset(pmp->data, 0, sizeof(pmp->data));
1132 p->port_select = port_select;
1133 if (pmp->attr_mod != 0 ||
1134 (port_select != port && port_select != 0xFF))
1135 pmp->status |= IB_SMP_INVALID_FIELD;
1137 if (cntrs.symbol_error_counter > 0xFFFFUL)
1138 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
1140 p->symbol_error_counter =
1141 cpu_to_be16((u16)cntrs.symbol_error_counter);
1142 if (cntrs.link_error_recovery_counter > 0xFFUL)
1143 p->link_error_recovery_counter = 0xFF;
1145 p->link_error_recovery_counter =
1146 (u8)cntrs.link_error_recovery_counter;
1147 if (cntrs.link_downed_counter > 0xFFUL)
1148 p->link_downed_counter = 0xFF;
1150 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1151 if (cntrs.port_rcv_errors > 0xFFFFUL)
1152 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
1154 p->port_rcv_errors =
1155 cpu_to_be16((u16) cntrs.port_rcv_errors);
1156 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1157 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
1159 p->port_rcv_remphys_errors =
1160 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1161 if (cntrs.port_xmit_discards > 0xFFFFUL)
1162 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
1164 p->port_xmit_discards =
1165 cpu_to_be16((u16)cntrs.port_xmit_discards);
1166 if (cntrs.local_link_integrity_errors > 0xFUL)
1167 cntrs.local_link_integrity_errors = 0xFUL;
1168 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1169 cntrs.excessive_buffer_overrun_errors = 0xFUL;
1170 p->lli_ebor_errors = (cntrs.local_link_integrity_errors << 4) |
1171 cntrs.excessive_buffer_overrun_errors;
1172 if (dev->n_vl15_dropped > 0xFFFFUL)
1173 p->vl15_dropped = __constant_cpu_to_be16(0xFFFF);
1175 p->vl15_dropped = cpu_to_be16((u16)dev->n_vl15_dropped);
1176 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1177 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
1179 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1180 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1181 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
1183 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1184 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1185 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1187 p->port_xmit_packets =
1188 cpu_to_be32((u32)cntrs.port_xmit_packets);
1189 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1190 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
1192 p->port_rcv_packets =
1193 cpu_to_be32((u32) cntrs.port_rcv_packets);
1195 return reply((struct ib_smp *) pmp);
1198 static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
1199 struct ib_device *ibdev, u8 port)
1201 struct ib_pma_portcounters_ext *p =
1202 (struct ib_pma_portcounters_ext *)pmp->data;
1203 struct ipath_ibdev *dev = to_idev(ibdev);
1204 u64 swords, rwords, spkts, rpkts, xwait;
1205 u8 port_select = p->port_select;
1207 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1210 /* Adjust counters for any resets done. */
1211 swords -= dev->z_port_xmit_data;
1212 rwords -= dev->z_port_rcv_data;
1213 spkts -= dev->z_port_xmit_packets;
1214 rpkts -= dev->z_port_rcv_packets;
1216 memset(pmp->data, 0, sizeof(pmp->data));
1218 p->port_select = port_select;
1219 if (pmp->attr_mod != 0 ||
1220 (port_select != port && port_select != 0xFF))
1221 pmp->status |= IB_SMP_INVALID_FIELD;
1223 p->port_xmit_data = cpu_to_be64(swords);
1224 p->port_rcv_data = cpu_to_be64(rwords);
1225 p->port_xmit_packets = cpu_to_be64(spkts);
1226 p->port_rcv_packets = cpu_to_be64(rpkts);
1227 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
1228 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
1229 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
1230 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
1232 return reply((struct ib_smp *) pmp);
1235 static int recv_pma_set_portcounters(struct ib_perf *pmp,
1236 struct ib_device *ibdev, u8 port)
1238 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1240 struct ipath_ibdev *dev = to_idev(ibdev);
1241 struct ipath_verbs_counters cntrs;
1244 * Since the HW doesn't support clearing counters, we save the
1245 * current count and subtract it from future responses.
1247 ipath_get_counters(dev->dd, &cntrs);
1249 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
1250 dev->z_symbol_error_counter = cntrs.symbol_error_counter;
1252 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
1253 dev->z_link_error_recovery_counter =
1254 cntrs.link_error_recovery_counter;
1256 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
1257 dev->z_link_downed_counter = cntrs.link_downed_counter;
1259 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
1260 dev->z_port_rcv_errors =
1261 cntrs.port_rcv_errors + dev->rcv_errors;
1263 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
1264 dev->z_port_rcv_remphys_errors =
1265 cntrs.port_rcv_remphys_errors;
1267 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
1268 dev->z_port_xmit_discards = cntrs.port_xmit_discards;
1270 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1271 dev->z_local_link_integrity_errors =
1272 cntrs.local_link_integrity_errors;
1274 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1275 dev->z_excessive_buffer_overrun_errors =
1276 cntrs.excessive_buffer_overrun_errors;
1278 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED)
1279 dev->n_vl15_dropped = 0;
1281 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
1282 dev->z_port_xmit_data = cntrs.port_xmit_data;
1284 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
1285 dev->z_port_rcv_data = cntrs.port_rcv_data;
1287 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1288 dev->z_port_xmit_packets = cntrs.port_xmit_packets;
1290 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1291 dev->z_port_rcv_packets = cntrs.port_rcv_packets;
1293 return recv_pma_get_portcounters(pmp, ibdev, port);
1296 static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1297 struct ib_device *ibdev, u8 port)
1299 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1301 struct ipath_ibdev *dev = to_idev(ibdev);
1302 u64 swords, rwords, spkts, rpkts, xwait;
1304 ipath_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1307 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1308 dev->z_port_xmit_data = swords;
1310 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1311 dev->z_port_rcv_data = rwords;
1313 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1314 dev->z_port_xmit_packets = spkts;
1316 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1317 dev->z_port_rcv_packets = rpkts;
1319 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1320 dev->n_unicast_xmit = 0;
1322 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1323 dev->n_unicast_rcv = 0;
1325 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1326 dev->n_multicast_xmit = 0;
1328 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1329 dev->n_multicast_rcv = 0;
1331 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1334 static int process_subn(struct ib_device *ibdev, int mad_flags,
1335 u8 port_num, struct ib_mad *in_mad,
1336 struct ib_mad *out_mad)
1338 struct ib_smp *smp = (struct ib_smp *)out_mad;
1339 struct ipath_ibdev *dev = to_idev(ibdev);
1343 if (smp->class_version != 1) {
1344 smp->status |= IB_SMP_UNSUP_VERSION;
1349 /* Is the mkey in the process of expiring? */
1350 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1351 /* Clear timeout and mkey protection field. */
1352 dev->mkey_lease_timeout = 0;
1353 dev->mkeyprot_resv_lmc &= 0x3F;
1357 * M_Key checking depends on
1358 * Portinfo:M_Key_protect_bits
1360 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1361 dev->mkey != smp->mkey &&
1362 (smp->method == IB_MGMT_METHOD_SET ||
1363 (smp->method == IB_MGMT_METHOD_GET &&
1364 (dev->mkeyprot_resv_lmc >> 7) != 0))) {
1365 if (dev->mkey_violations != 0xFFFF)
1366 ++dev->mkey_violations;
1367 if (dev->mkey_lease_timeout ||
1368 dev->mkey_lease_period == 0) {
1369 ret = IB_MAD_RESULT_SUCCESS |
1370 IB_MAD_RESULT_CONSUMED;
1373 dev->mkey_lease_timeout = jiffies +
1374 dev->mkey_lease_period * HZ;
1375 /* Future: Generate a trap notice. */
1376 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1378 } else if (dev->mkey_lease_timeout)
1379 dev->mkey_lease_timeout = 0;
1381 switch (smp->method) {
1382 case IB_MGMT_METHOD_GET:
1383 switch (smp->attr_id) {
1384 case IB_SMP_ATTR_NODE_DESC:
1385 ret = recv_subn_get_nodedescription(smp, ibdev);
1387 case IB_SMP_ATTR_NODE_INFO:
1388 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1390 case IB_SMP_ATTR_GUID_INFO:
1391 ret = recv_subn_get_guidinfo(smp, ibdev);
1393 case IB_SMP_ATTR_PORT_INFO:
1394 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1396 case IB_SMP_ATTR_PKEY_TABLE:
1397 ret = recv_subn_get_pkeytable(smp, ibdev);
1399 case IB_SMP_ATTR_SM_INFO:
1400 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1401 ret = IB_MAD_RESULT_SUCCESS |
1402 IB_MAD_RESULT_CONSUMED;
1405 if (dev->port_cap_flags & IB_PORT_SM) {
1406 ret = IB_MAD_RESULT_SUCCESS;
1411 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1416 case IB_MGMT_METHOD_SET:
1417 switch (smp->attr_id) {
1418 case IB_SMP_ATTR_GUID_INFO:
1419 ret = recv_subn_set_guidinfo(smp, ibdev);
1421 case IB_SMP_ATTR_PORT_INFO:
1422 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1424 case IB_SMP_ATTR_PKEY_TABLE:
1425 ret = recv_subn_set_pkeytable(smp, ibdev);
1427 case IB_SMP_ATTR_SM_INFO:
1428 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1429 ret = IB_MAD_RESULT_SUCCESS |
1430 IB_MAD_RESULT_CONSUMED;
1433 if (dev->port_cap_flags & IB_PORT_SM) {
1434 ret = IB_MAD_RESULT_SUCCESS;
1439 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1444 case IB_MGMT_METHOD_GET_RESP:
1446 * The ib_mad module will call us to process responses
1447 * before checking for other consumers.
1448 * Just tell the caller to process it normally.
1450 ret = IB_MAD_RESULT_FAILURE;
1453 smp->status |= IB_SMP_UNSUP_METHOD;
1461 static int process_perf(struct ib_device *ibdev, u8 port_num,
1462 struct ib_mad *in_mad,
1463 struct ib_mad *out_mad)
1465 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1469 if (pmp->class_version != 1) {
1470 pmp->status |= IB_SMP_UNSUP_VERSION;
1471 ret = reply((struct ib_smp *) pmp);
1475 switch (pmp->method) {
1476 case IB_MGMT_METHOD_GET:
1477 switch (pmp->attr_id) {
1478 case IB_PMA_CLASS_PORT_INFO:
1479 ret = recv_pma_get_classportinfo(pmp);
1481 case IB_PMA_PORT_SAMPLES_CONTROL:
1482 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1485 case IB_PMA_PORT_SAMPLES_RESULT:
1486 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1488 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1489 ret = recv_pma_get_portsamplesresult_ext(pmp,
1492 case IB_PMA_PORT_COUNTERS:
1493 ret = recv_pma_get_portcounters(pmp, ibdev,
1496 case IB_PMA_PORT_COUNTERS_EXT:
1497 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1501 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1502 ret = reply((struct ib_smp *) pmp);
1506 case IB_MGMT_METHOD_SET:
1507 switch (pmp->attr_id) {
1508 case IB_PMA_PORT_SAMPLES_CONTROL:
1509 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1512 case IB_PMA_PORT_COUNTERS:
1513 ret = recv_pma_set_portcounters(pmp, ibdev,
1516 case IB_PMA_PORT_COUNTERS_EXT:
1517 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1521 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1522 ret = reply((struct ib_smp *) pmp);
1526 case IB_MGMT_METHOD_GET_RESP:
1528 * The ib_mad module will call us to process responses
1529 * before checking for other consumers.
1530 * Just tell the caller to process it normally.
1532 ret = IB_MAD_RESULT_FAILURE;
1535 pmp->status |= IB_SMP_UNSUP_METHOD;
1536 ret = reply((struct ib_smp *) pmp);
1544 * ipath_process_mad - process an incoming MAD packet
1545 * @ibdev: the infiniband device this packet came in on
1546 * @mad_flags: MAD flags
1547 * @port_num: the port number this packet came in on
1548 * @in_wc: the work completion entry for this packet
1549 * @in_grh: the global route header for this packet
1550 * @in_mad: the incoming MAD
1551 * @out_mad: any outgoing MAD reply
1553 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1554 * interested in processing.
1556 * Note that the verbs framework has already done the MAD sanity checks,
1557 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1560 * This is called by the ib_mad module.
1562 int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1563 struct ib_wc *in_wc, struct ib_grh *in_grh,
1564 struct ib_mad *in_mad, struct ib_mad *out_mad)
1568 switch (in_mad->mad_hdr.mgmt_class) {
1569 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1570 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1571 ret = process_subn(ibdev, mad_flags, port_num,
1574 case IB_MGMT_CLASS_PERF_MGMT:
1575 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1578 ret = IB_MAD_RESULT_SUCCESS;