blob: ccb119143d20568eb0570ab5b1360a78ca888e08 [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00002 * Copyright (c) 2012 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
Ralph Campbellf9315512010-05-23 21:44:54 -07004 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <rdma/ib_smi.h>
36
37#include "qib.h"
38#include "qib_mad.h"
39
40static int reply(struct ib_smp *smp)
41{
42 /*
43 * The verbs framework will handle the directed/LID route
44 * packet changes.
45 */
46 smp->method = IB_MGMT_METHOD_GET_RESP;
47 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
48 smp->status |= IB_SMP_DIRECTION;
49 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
50}
51
Mike Marciniszyn36a8f012012-07-19 13:04:04 +000052static int reply_failure(struct ib_smp *smp)
53{
54 /*
55 * The verbs framework will handle the directed/LID route
56 * packet changes.
57 */
58 smp->method = IB_MGMT_METHOD_GET_RESP;
59 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
60 smp->status |= IB_SMP_DIRECTION;
61 return IB_MAD_RESULT_FAILURE | IB_MAD_RESULT_REPLY;
62}
63
Ralph Campbellf9315512010-05-23 21:44:54 -070064static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len)
65{
66 struct ib_mad_send_buf *send_buf;
67 struct ib_mad_agent *agent;
68 struct ib_smp *smp;
69 int ret;
70 unsigned long flags;
71 unsigned long timeout;
72
73 agent = ibp->send_agent;
74 if (!agent)
75 return;
76
77 /* o14-3.2.1 */
78 if (!(ppd_from_ibp(ibp)->lflags & QIBL_LINKACTIVE))
79 return;
80
81 /* o14-2 */
82 if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout))
83 return;
84
85 send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
86 IB_MGMT_MAD_DATA, GFP_ATOMIC);
87 if (IS_ERR(send_buf))
88 return;
89
90 smp = send_buf->mad;
91 smp->base_version = IB_MGMT_BASE_VERSION;
92 smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
93 smp->class_version = 1;
94 smp->method = IB_MGMT_METHOD_TRAP;
95 ibp->tid++;
96 smp->tid = cpu_to_be64(ibp->tid);
97 smp->attr_id = IB_SMP_ATTR_NOTICE;
98 /* o14-1: smp->mkey = 0; */
99 memcpy(smp->data, data, len);
100
101 spin_lock_irqsave(&ibp->lock, flags);
102 if (!ibp->sm_ah) {
103 if (ibp->sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
104 struct ib_ah *ah;
Ralph Campbellf9315512010-05-23 21:44:54 -0700105
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +0000106 ah = qib_create_qp0_ah(ibp, ibp->sm_lid);
Ralph Campbellf9315512010-05-23 21:44:54 -0700107 if (IS_ERR(ah))
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +0000108 ret = PTR_ERR(ah);
Ralph Campbellf9315512010-05-23 21:44:54 -0700109 else {
110 send_buf->ah = ah;
111 ibp->sm_ah = to_iah(ah);
112 ret = 0;
113 }
114 } else
115 ret = -EINVAL;
116 } else {
117 send_buf->ah = &ibp->sm_ah->ibah;
118 ret = 0;
119 }
120 spin_unlock_irqrestore(&ibp->lock, flags);
121
122 if (!ret)
123 ret = ib_post_send_mad(send_buf, NULL);
124 if (!ret) {
125 /* 4.096 usec. */
126 timeout = (4096 * (1UL << ibp->subnet_timeout)) / 1000;
127 ibp->trap_timeout = jiffies + usecs_to_jiffies(timeout);
128 } else {
129 ib_free_send_mad(send_buf);
130 ibp->trap_timeout = 0;
131 }
132}
133
134/*
135 * Send a bad [PQ]_Key trap (ch. 14.3.8).
136 */
137void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
138 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2)
139{
140 struct ib_mad_notice_attr data;
141
142 if (trap_num == IB_NOTICE_TRAP_BAD_PKEY)
143 ibp->pkey_violations++;
144 else
145 ibp->qkey_violations++;
146 ibp->n_pkt_drops++;
147
148 /* Send violation trap */
149 data.generic_type = IB_NOTICE_TYPE_SECURITY;
150 data.prod_type_msb = 0;
151 data.prod_type_lsb = IB_NOTICE_PROD_CA;
152 data.trap_num = trap_num;
153 data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
154 data.toggle_count = 0;
155 memset(&data.details, 0, sizeof data.details);
156 data.details.ntc_257_258.lid1 = lid1;
157 data.details.ntc_257_258.lid2 = lid2;
158 data.details.ntc_257_258.key = cpu_to_be32(key);
159 data.details.ntc_257_258.sl_qp1 = cpu_to_be32((sl << 28) | qp1);
160 data.details.ntc_257_258.qp2 = cpu_to_be32(qp2);
161
162 qib_send_trap(ibp, &data, sizeof data);
163}
164
165/*
166 * Send a bad M_Key trap (ch. 14.3.9).
167 */
168static void qib_bad_mkey(struct qib_ibport *ibp, struct ib_smp *smp)
169{
170 struct ib_mad_notice_attr data;
171
172 /* Send violation trap */
173 data.generic_type = IB_NOTICE_TYPE_SECURITY;
174 data.prod_type_msb = 0;
175 data.prod_type_lsb = IB_NOTICE_PROD_CA;
176 data.trap_num = IB_NOTICE_TRAP_BAD_MKEY;
177 data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
178 data.toggle_count = 0;
179 memset(&data.details, 0, sizeof data.details);
180 data.details.ntc_256.lid = data.issuer_lid;
181 data.details.ntc_256.method = smp->method;
182 data.details.ntc_256.attr_id = smp->attr_id;
183 data.details.ntc_256.attr_mod = smp->attr_mod;
184 data.details.ntc_256.mkey = smp->mkey;
185 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
186 u8 hop_cnt;
187
188 data.details.ntc_256.dr_slid = smp->dr_slid;
189 data.details.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE;
190 hop_cnt = smp->hop_cnt;
191 if (hop_cnt > ARRAY_SIZE(data.details.ntc_256.dr_rtn_path)) {
192 data.details.ntc_256.dr_trunc_hop |=
193 IB_NOTICE_TRAP_DR_TRUNC;
194 hop_cnt = ARRAY_SIZE(data.details.ntc_256.dr_rtn_path);
195 }
196 data.details.ntc_256.dr_trunc_hop |= hop_cnt;
197 memcpy(data.details.ntc_256.dr_rtn_path, smp->return_path,
198 hop_cnt);
199 }
200
201 qib_send_trap(ibp, &data, sizeof data);
202}
203
204/*
205 * Send a Port Capability Mask Changed trap (ch. 14.3.11).
206 */
207void qib_cap_mask_chg(struct qib_ibport *ibp)
208{
209 struct ib_mad_notice_attr data;
210
211 data.generic_type = IB_NOTICE_TYPE_INFO;
212 data.prod_type_msb = 0;
213 data.prod_type_lsb = IB_NOTICE_PROD_CA;
214 data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG;
215 data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
216 data.toggle_count = 0;
217 memset(&data.details, 0, sizeof data.details);
218 data.details.ntc_144.lid = data.issuer_lid;
219 data.details.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags);
220
221 qib_send_trap(ibp, &data, sizeof data);
222}
223
224/*
225 * Send a System Image GUID Changed trap (ch. 14.3.12).
226 */
227void qib_sys_guid_chg(struct qib_ibport *ibp)
228{
229 struct ib_mad_notice_attr data;
230
231 data.generic_type = IB_NOTICE_TYPE_INFO;
232 data.prod_type_msb = 0;
233 data.prod_type_lsb = IB_NOTICE_PROD_CA;
234 data.trap_num = IB_NOTICE_TRAP_SYS_GUID_CHG;
235 data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
236 data.toggle_count = 0;
237 memset(&data.details, 0, sizeof data.details);
238 data.details.ntc_145.lid = data.issuer_lid;
239 data.details.ntc_145.new_sys_guid = ib_qib_sys_image_guid;
240
241 qib_send_trap(ibp, &data, sizeof data);
242}
243
244/*
245 * Send a Node Description Changed trap (ch. 14.3.13).
246 */
247void qib_node_desc_chg(struct qib_ibport *ibp)
248{
249 struct ib_mad_notice_attr data;
250
251 data.generic_type = IB_NOTICE_TYPE_INFO;
252 data.prod_type_msb = 0;
253 data.prod_type_lsb = IB_NOTICE_PROD_CA;
254 data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG;
255 data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid);
256 data.toggle_count = 0;
257 memset(&data.details, 0, sizeof data.details);
258 data.details.ntc_144.lid = data.issuer_lid;
259 data.details.ntc_144.local_changes = 1;
260 data.details.ntc_144.change_flags = IB_NOTICE_TRAP_NODE_DESC_CHG;
261
262 qib_send_trap(ibp, &data, sizeof data);
263}
264
265static int subn_get_nodedescription(struct ib_smp *smp,
266 struct ib_device *ibdev)
267{
268 if (smp->attr_mod)
269 smp->status |= IB_SMP_INVALID_FIELD;
270
271 memcpy(smp->data, ibdev->node_desc, sizeof(smp->data));
272
273 return reply(smp);
274}
275
276static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev,
277 u8 port)
278{
279 struct ib_node_info *nip = (struct ib_node_info *)&smp->data;
280 struct qib_devdata *dd = dd_from_ibdev(ibdev);
281 u32 vendor, majrev, minrev;
282 unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
283
284 /* GUID 0 is illegal */
285 if (smp->attr_mod || pidx >= dd->num_pports ||
286 dd->pport[pidx].guid == 0)
287 smp->status |= IB_SMP_INVALID_FIELD;
288 else
289 nip->port_guid = dd->pport[pidx].guid;
290
291 nip->base_version = 1;
292 nip->class_version = 1;
293 nip->node_type = 1; /* channel adapter */
294 nip->num_ports = ibdev->phys_port_cnt;
295 /* This is already in network order */
296 nip->sys_guid = ib_qib_sys_image_guid;
297 nip->node_guid = dd->pport->guid; /* Use first-port GUID as node */
298 nip->partition_cap = cpu_to_be16(qib_get_npkeys(dd));
299 nip->device_id = cpu_to_be16(dd->deviceid);
300 majrev = dd->majrev;
301 minrev = dd->minrev;
302 nip->revision = cpu_to_be32((majrev << 16) | minrev);
303 nip->local_port_num = port;
304 vendor = dd->vendorid;
305 nip->vendor_id[0] = QIB_SRC_OUI_1;
306 nip->vendor_id[1] = QIB_SRC_OUI_2;
307 nip->vendor_id[2] = QIB_SRC_OUI_3;
308
309 return reply(smp);
310}
311
312static int subn_get_guidinfo(struct ib_smp *smp, struct ib_device *ibdev,
313 u8 port)
314{
315 struct qib_devdata *dd = dd_from_ibdev(ibdev);
316 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
317 __be64 *p = (__be64 *) smp->data;
318 unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
319
320 /* 32 blocks of 8 64-bit GUIDs per block */
321
322 memset(smp->data, 0, sizeof(smp->data));
323
324 if (startgx == 0 && pidx < dd->num_pports) {
325 struct qib_pportdata *ppd = dd->pport + pidx;
326 struct qib_ibport *ibp = &ppd->ibport_data;
327 __be64 g = ppd->guid;
328 unsigned i;
329
330 /* GUID 0 is illegal */
331 if (g == 0)
332 smp->status |= IB_SMP_INVALID_FIELD;
333 else {
334 /* The first is a copy of the read-only HW GUID. */
335 p[0] = g;
336 for (i = 1; i < QIB_GUIDS_PER_PORT; i++)
337 p[i] = ibp->guids[i - 1];
338 }
339 } else
340 smp->status |= IB_SMP_INVALID_FIELD;
341
342 return reply(smp);
343}
344
345static void set_link_width_enabled(struct qib_pportdata *ppd, u32 w)
346{
347 (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LWID_ENB, w);
348}
349
350static void set_link_speed_enabled(struct qib_pportdata *ppd, u32 s)
351{
352 (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_SPD_ENB, s);
353}
354
355static int get_overrunthreshold(struct qib_pportdata *ppd)
356{
357 return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH);
358}
359
360/**
361 * set_overrunthreshold - set the overrun threshold
362 * @ppd: the physical port data
363 * @n: the new threshold
364 *
365 * Note that this will only take effect when the link state changes.
366 */
367static int set_overrunthreshold(struct qib_pportdata *ppd, unsigned n)
368{
369 (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH,
370 (u32)n);
371 return 0;
372}
373
374static int get_phyerrthreshold(struct qib_pportdata *ppd)
375{
376 return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH);
377}
378
379/**
380 * set_phyerrthreshold - set the physical error threshold
381 * @ppd: the physical port data
382 * @n: the new threshold
383 *
384 * Note that this will only take effect when the link state changes.
385 */
386static int set_phyerrthreshold(struct qib_pportdata *ppd, unsigned n)
387{
388 (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH,
389 (u32)n);
390 return 0;
391}
392
393/**
394 * get_linkdowndefaultstate - get the default linkdown state
395 * @ppd: the physical port data
396 *
397 * Returns zero if the default is POLL, 1 if the default is SLEEP.
398 */
399static int get_linkdowndefaultstate(struct qib_pportdata *ppd)
400{
401 return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT) ==
402 IB_LINKINITCMD_SLEEP;
403}
404
405static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags)
406{
Jim Foraker6199c892012-05-02 14:39:11 -0400407 int valid_mkey = 0;
Ralph Campbellf9315512010-05-23 21:44:54 -0700408 int ret = 0;
409
410 /* Is the mkey in the process of expiring? */
411 if (ibp->mkey_lease_timeout &&
412 time_after_eq(jiffies, ibp->mkey_lease_timeout)) {
413 /* Clear timeout and mkey protection field. */
414 ibp->mkey_lease_timeout = 0;
415 ibp->mkeyprot = 0;
416 }
417
Jim Foraker6199c892012-05-02 14:39:11 -0400418 if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->mkey == 0 ||
419 ibp->mkey == smp->mkey)
420 valid_mkey = 1;
421
422 /* Unset lease timeout on any valid Get/Set/TrapRepress */
423 if (valid_mkey && ibp->mkey_lease_timeout &&
424 (smp->method == IB_MGMT_METHOD_GET ||
425 smp->method == IB_MGMT_METHOD_SET ||
426 smp->method == IB_MGMT_METHOD_TRAP_REPRESS))
Ralph Campbellf9315512010-05-23 21:44:54 -0700427 ibp->mkey_lease_timeout = 0;
428
Jim Foraker6199c892012-05-02 14:39:11 -0400429 if (!valid_mkey) {
430 switch (smp->method) {
431 case IB_MGMT_METHOD_GET:
432 /* Bad mkey not a violation below level 2 */
433 if (ibp->mkeyprot < 2)
434 break;
435 case IB_MGMT_METHOD_SET:
436 case IB_MGMT_METHOD_TRAP_REPRESS:
437 if (ibp->mkey_violations != 0xFFFF)
438 ++ibp->mkey_violations;
439 if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period)
440 ibp->mkey_lease_timeout = jiffies +
441 ibp->mkey_lease_period * HZ;
442 /* Generate a trap notice. */
443 qib_bad_mkey(ibp, smp);
Jim Foraker3236b2d2012-05-02 14:57:23 -0400444 ret = 1;
Jim Foraker6199c892012-05-02 14:39:11 -0400445 }
446 }
447
Ralph Campbellf9315512010-05-23 21:44:54 -0700448 return ret;
449}
450
451static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
452 u8 port)
453{
454 struct qib_devdata *dd;
455 struct qib_pportdata *ppd;
456 struct qib_ibport *ibp;
457 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
Ralph Campbellf9315512010-05-23 21:44:54 -0700458 u8 mtu;
459 int ret;
460 u32 state;
461 u32 port_num = be32_to_cpu(smp->attr_mod);
462
463 if (port_num == 0)
464 port_num = port;
465 else {
466 if (port_num > ibdev->phys_port_cnt) {
467 smp->status |= IB_SMP_INVALID_FIELD;
468 ret = reply(smp);
469 goto bail;
470 }
471 if (port_num != port) {
472 ibp = to_iport(ibdev, port_num);
473 ret = check_mkey(ibp, smp, 0);
Mike Marciniszyn4c355002012-09-12 13:01:29 +0000474 if (ret) {
Jim Foraker3236b2d2012-05-02 14:57:23 -0400475 ret = IB_MAD_RESULT_FAILURE;
Ralph Campbellf9315512010-05-23 21:44:54 -0700476 goto bail;
Mike Marciniszyn4c355002012-09-12 13:01:29 +0000477 }
Ralph Campbellf9315512010-05-23 21:44:54 -0700478 }
479 }
480
481 dd = dd_from_ibdev(ibdev);
482 /* IB numbers ports from 1, hdw from 0 */
483 ppd = dd->pport + (port_num - 1);
484 ibp = &ppd->ibport_data;
485
486 /* Clear all fields. Only set the non-zero fields. */
487 memset(smp->data, 0, sizeof(smp->data));
488
489 /* Only return the mkey if the protection field allows it. */
Mitko Haralanov36b87b42011-03-04 18:53:17 +0000490 if (!(smp->method == IB_MGMT_METHOD_GET &&
491 ibp->mkey != smp->mkey &&
492 ibp->mkeyprot == 1))
Ralph Campbellf9315512010-05-23 21:44:54 -0700493 pip->mkey = ibp->mkey;
494 pip->gid_prefix = ibp->gid_prefix;
Mike Marciniszyn520b3ee2012-02-25 17:45:50 -0800495 pip->lid = cpu_to_be16(ppd->lid);
Ralph Campbellf9315512010-05-23 21:44:54 -0700496 pip->sm_lid = cpu_to_be16(ibp->sm_lid);
497 pip->cap_mask = cpu_to_be32(ibp->port_cap_flags);
498 /* pip->diag_code; */
499 pip->mkey_lease_period = cpu_to_be16(ibp->mkey_lease_period);
500 pip->local_port_num = port;
501 pip->link_width_enabled = ppd->link_width_enabled;
502 pip->link_width_supported = ppd->link_width_supported;
503 pip->link_width_active = ppd->link_width_active;
504 state = dd->f_iblink_state(ppd->lastibcstat);
505 pip->linkspeed_portstate = ppd->link_speed_supported << 4 | state;
506
507 pip->portphysstate_linkdown =
508 (dd->f_ibphys_portstate(ppd->lastibcstat) << 4) |
509 (get_linkdowndefaultstate(ppd) ? 1 : 2);
510 pip->mkeyprot_resv_lmc = (ibp->mkeyprot << 6) | ppd->lmc;
511 pip->linkspeedactive_enabled = (ppd->link_speed_active << 4) |
512 ppd->link_speed_enabled;
513 switch (ppd->ibmtu) {
514 default: /* something is wrong; fall through */
515 case 4096:
516 mtu = IB_MTU_4096;
517 break;
518 case 2048:
519 mtu = IB_MTU_2048;
520 break;
521 case 1024:
522 mtu = IB_MTU_1024;
523 break;
524 case 512:
525 mtu = IB_MTU_512;
526 break;
527 case 256:
528 mtu = IB_MTU_256;
529 break;
530 }
531 pip->neighbormtu_mastersmsl = (mtu << 4) | ibp->sm_sl;
532 pip->vlcap_inittype = ppd->vls_supported << 4; /* InitType = 0 */
533 pip->vl_high_limit = ibp->vl_high_limit;
534 pip->vl_arb_high_cap =
535 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_CAP);
536 pip->vl_arb_low_cap =
537 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_LOW_CAP);
538 /* InitTypeReply = 0 */
539 pip->inittypereply_mtucap = qib_ibmtu ? qib_ibmtu : IB_MTU_4096;
540 /* HCAs ignore VLStallCount and HOQLife */
541 /* pip->vlstallcnt_hoqlife; */
542 pip->operationalvl_pei_peo_fpi_fpo =
543 dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OP_VLS) << 4;
544 pip->mkey_violations = cpu_to_be16(ibp->mkey_violations);
545 /* P_KeyViolations are counted by hardware. */
546 pip->pkey_violations = cpu_to_be16(ibp->pkey_violations);
547 pip->qkey_violations = cpu_to_be16(ibp->qkey_violations);
548 /* Only the hardware GUID is supported for now */
549 pip->guid_cap = QIB_GUIDS_PER_PORT;
550 pip->clientrereg_resv_subnetto = ibp->subnet_timeout;
551 /* 32.768 usec. response time (guessing) */
552 pip->resv_resptimevalue = 3;
553 pip->localphyerrors_overrunerrors =
554 (get_phyerrthreshold(ppd) << 4) |
555 get_overrunthreshold(ppd);
556 /* pip->max_credit_hint; */
557 if (ibp->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) {
558 u32 v;
559
560 v = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKLATENCY);
561 pip->link_roundtrip_latency[0] = v >> 16;
562 pip->link_roundtrip_latency[1] = v >> 8;
563 pip->link_roundtrip_latency[2] = v;
564 }
565
566 ret = reply(smp);
567
568bail:
569 return ret;
570}
571
572/**
573 * get_pkeys - return the PKEY table
574 * @dd: the qlogic_ib device
575 * @port: the IB port number
576 * @pkeys: the pkey table is placed here
577 */
578static int get_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
579{
580 struct qib_pportdata *ppd = dd->pport + port - 1;
581 /*
582 * always a kernel context, no locking needed.
583 * If we get here with ppd setup, no need to check
584 * that pd is valid.
585 */
586 struct qib_ctxtdata *rcd = dd->rcd[ppd->hw_pidx];
587
588 memcpy(pkeys, rcd->pkeys, sizeof(rcd->pkeys));
589
590 return 0;
591}
592
593static int subn_get_pkeytable(struct ib_smp *smp, struct ib_device *ibdev,
594 u8 port)
595{
596 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
597 u16 *p = (u16 *) smp->data;
598 __be16 *q = (__be16 *) smp->data;
599
600 /* 64 blocks of 32 16-bit P_Key entries */
601
602 memset(smp->data, 0, sizeof(smp->data));
603 if (startpx == 0) {
604 struct qib_devdata *dd = dd_from_ibdev(ibdev);
605 unsigned i, n = qib_get_npkeys(dd);
606
607 get_pkeys(dd, port, p);
608
609 for (i = 0; i < n; i++)
610 q[i] = cpu_to_be16(p[i]);
611 } else
612 smp->status |= IB_SMP_INVALID_FIELD;
613
614 return reply(smp);
615}
616
617static int subn_set_guidinfo(struct ib_smp *smp, struct ib_device *ibdev,
618 u8 port)
619{
620 struct qib_devdata *dd = dd_from_ibdev(ibdev);
621 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
622 __be64 *p = (__be64 *) smp->data;
623 unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
624
625 /* 32 blocks of 8 64-bit GUIDs per block */
626
627 if (startgx == 0 && pidx < dd->num_pports) {
628 struct qib_pportdata *ppd = dd->pport + pidx;
629 struct qib_ibport *ibp = &ppd->ibport_data;
630 unsigned i;
631
632 /* The first entry is read-only. */
633 for (i = 1; i < QIB_GUIDS_PER_PORT; i++)
634 ibp->guids[i - 1] = p[i];
635 } else
636 smp->status |= IB_SMP_INVALID_FIELD;
637
638 /* The only GUID we support is the first read-only entry. */
639 return subn_get_guidinfo(smp, ibdev, port);
640}
641
642/**
643 * subn_set_portinfo - set port information
644 * @smp: the incoming SM packet
645 * @ibdev: the infiniband device
646 * @port: the port on the device
647 *
648 * Set Portinfo (see ch. 14.2.5.6).
649 */
650static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev,
651 u8 port)
652{
653 struct ib_port_info *pip = (struct ib_port_info *)smp->data;
654 struct ib_event event;
655 struct qib_devdata *dd;
656 struct qib_pportdata *ppd;
657 struct qib_ibport *ibp;
Todd Rimmer4ccf28a2012-05-02 14:35:18 -0400658 u8 clientrereg = (pip->clientrereg_resv_subnetto & 0x80);
Ralph Campbellf9315512010-05-23 21:44:54 -0700659 unsigned long flags;
660 u16 lid, smlid;
661 u8 lwe;
662 u8 lse;
663 u8 state;
664 u8 vls;
665 u8 msl;
666 u16 lstate;
667 int ret, ore, mtu;
668 u32 port_num = be32_to_cpu(smp->attr_mod);
669
670 if (port_num == 0)
671 port_num = port;
672 else {
673 if (port_num > ibdev->phys_port_cnt)
674 goto err;
675 /* Port attributes can only be set on the receiving port */
676 if (port_num != port)
677 goto get_only;
678 }
679
680 dd = dd_from_ibdev(ibdev);
681 /* IB numbers ports from 1, hdw from 0 */
682 ppd = dd->pport + (port_num - 1);
683 ibp = &ppd->ibport_data;
684 event.device = ibdev;
685 event.element.port_num = port;
686
687 ibp->mkey = pip->mkey;
688 ibp->gid_prefix = pip->gid_prefix;
689 ibp->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
690
691 lid = be16_to_cpu(pip->lid);
692 /* Must be a valid unicast LID address. */
693 if (lid == 0 || lid >= QIB_MULTICAST_LID_BASE)
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800694 smp->status |= IB_SMP_INVALID_FIELD;
695 else if (ppd->lid != lid || ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700696 if (ppd->lid != lid)
697 qib_set_uevent_bits(ppd, _QIB_EVENT_LID_CHANGE_BIT);
698 if (ppd->lmc != (pip->mkeyprot_resv_lmc & 7))
699 qib_set_uevent_bits(ppd, _QIB_EVENT_LMC_CHANGE_BIT);
700 qib_set_lid(ppd, lid, pip->mkeyprot_resv_lmc & 7);
701 event.event = IB_EVENT_LID_CHANGE;
702 ib_dispatch_event(&event);
703 }
704
705 smlid = be16_to_cpu(pip->sm_lid);
706 msl = pip->neighbormtu_mastersmsl & 0xF;
707 /* Must be a valid unicast LID address. */
708 if (smlid == 0 || smlid >= QIB_MULTICAST_LID_BASE)
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800709 smp->status |= IB_SMP_INVALID_FIELD;
710 else if (smlid != ibp->sm_lid || msl != ibp->sm_sl) {
Ralph Campbellf9315512010-05-23 21:44:54 -0700711 spin_lock_irqsave(&ibp->lock, flags);
712 if (ibp->sm_ah) {
713 if (smlid != ibp->sm_lid)
714 ibp->sm_ah->attr.dlid = smlid;
715 if (msl != ibp->sm_sl)
716 ibp->sm_ah->attr.sl = msl;
717 }
718 spin_unlock_irqrestore(&ibp->lock, flags);
719 if (smlid != ibp->sm_lid)
720 ibp->sm_lid = smlid;
721 if (msl != ibp->sm_sl)
722 ibp->sm_sl = msl;
723 event.event = IB_EVENT_SM_CHANGE;
724 ib_dispatch_event(&event);
725 }
726
727 /* Allow 1x or 4x to be set (see 14.2.6.6). */
728 lwe = pip->link_width_enabled;
729 if (lwe) {
730 if (lwe == 0xFF)
Mitko Haralanovcc7fb052011-02-22 16:56:37 -0800731 set_link_width_enabled(ppd, ppd->link_width_supported);
Ralph Campbellf9315512010-05-23 21:44:54 -0700732 else if (lwe >= 16 || (lwe & ~ppd->link_width_supported))
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800733 smp->status |= IB_SMP_INVALID_FIELD;
734 else if (lwe != ppd->link_width_enabled)
735 set_link_width_enabled(ppd, lwe);
Ralph Campbellf9315512010-05-23 21:44:54 -0700736 }
737
738 lse = pip->linkspeedactive_enabled & 0xF;
739 if (lse) {
740 /*
741 * The IB 1.2 spec. only allows link speed values
742 * 1, 3, 5, 7, 15. 1.2.1 extended to allow specific
743 * speeds.
744 */
745 if (lse == 15)
Mitko Haralanovcc7fb052011-02-22 16:56:37 -0800746 set_link_speed_enabled(ppd,
747 ppd->link_speed_supported);
Ralph Campbellf9315512010-05-23 21:44:54 -0700748 else if (lse >= 8 || (lse & ~ppd->link_speed_supported))
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800749 smp->status |= IB_SMP_INVALID_FIELD;
750 else if (lse != ppd->link_speed_enabled)
751 set_link_speed_enabled(ppd, lse);
Ralph Campbellf9315512010-05-23 21:44:54 -0700752 }
753
754 /* Set link down default state. */
755 switch (pip->portphysstate_linkdown & 0xF) {
756 case 0: /* NOP */
757 break;
758 case 1: /* SLEEP */
759 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT,
760 IB_LINKINITCMD_SLEEP);
761 break;
762 case 2: /* POLL */
763 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT,
764 IB_LINKINITCMD_POLL);
765 break;
766 default:
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800767 smp->status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -0700768 }
769
770 ibp->mkeyprot = pip->mkeyprot_resv_lmc >> 6;
771 ibp->vl_high_limit = pip->vl_high_limit;
772 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_LIMIT,
773 ibp->vl_high_limit);
774
775 mtu = ib_mtu_enum_to_int((pip->neighbormtu_mastersmsl >> 4) & 0xF);
776 if (mtu == -1)
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800777 smp->status |= IB_SMP_INVALID_FIELD;
778 else
779 qib_set_mtu(ppd, mtu);
Ralph Campbellf9315512010-05-23 21:44:54 -0700780
781 /* Set operational VLs */
782 vls = (pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF;
783 if (vls) {
784 if (vls > ppd->vls_supported)
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800785 smp->status |= IB_SMP_INVALID_FIELD;
786 else
787 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OP_VLS, vls);
Ralph Campbellf9315512010-05-23 21:44:54 -0700788 }
789
790 if (pip->mkey_violations == 0)
791 ibp->mkey_violations = 0;
792
793 if (pip->pkey_violations == 0)
794 ibp->pkey_violations = 0;
795
796 if (pip->qkey_violations == 0)
797 ibp->qkey_violations = 0;
798
799 ore = pip->localphyerrors_overrunerrors;
800 if (set_phyerrthreshold(ppd, (ore >> 4) & 0xF))
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800801 smp->status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -0700802
803 if (set_overrunthreshold(ppd, (ore & 0xF)))
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800804 smp->status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -0700805
806 ibp->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
807
Ralph Campbellf9315512010-05-23 21:44:54 -0700808 /*
809 * Do the port state change now that the other link parameters
810 * have been set.
811 * Changing the port physical state only makes sense if the link
812 * is down or is being set to down.
813 */
814 state = pip->linkspeed_portstate & 0xF;
815 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
816 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800817 smp->status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -0700818
819 /*
820 * Only state changes of DOWN, ARM, and ACTIVE are valid
821 * and must be in the correct state to take effect (see 7.2.6).
822 */
823 switch (state) {
824 case IB_PORT_NOP:
825 if (lstate == 0)
826 break;
827 /* FALLTHROUGH */
828 case IB_PORT_DOWN:
829 if (lstate == 0)
830 lstate = QIB_IB_LINKDOWN_ONLY;
831 else if (lstate == 1)
832 lstate = QIB_IB_LINKDOWN_SLEEP;
833 else if (lstate == 2)
834 lstate = QIB_IB_LINKDOWN;
835 else if (lstate == 3)
836 lstate = QIB_IB_LINKDOWN_DISABLE;
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800837 else {
838 smp->status |= IB_SMP_INVALID_FIELD;
839 break;
840 }
Ralph Campbellf9315512010-05-23 21:44:54 -0700841 spin_lock_irqsave(&ppd->lflags_lock, flags);
842 ppd->lflags &= ~QIBL_LINKV;
843 spin_unlock_irqrestore(&ppd->lflags_lock, flags);
844 qib_set_linkstate(ppd, lstate);
845 /*
846 * Don't send a reply if the response would be sent
847 * through the disabled port.
848 */
849 if (lstate == QIB_IB_LINKDOWN_DISABLE && smp->hop_cnt) {
850 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
851 goto done;
852 }
853 qib_wait_linkstate(ppd, QIBL_LINKV, 10);
854 break;
855 case IB_PORT_ARMED:
856 qib_set_linkstate(ppd, QIB_IB_LINKARM);
857 break;
858 case IB_PORT_ACTIVE:
859 qib_set_linkstate(ppd, QIB_IB_LINKACTIVE);
860 break;
861 default:
Mike Marciniszyn3c9e5f42011-01-10 17:42:19 -0800862 smp->status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -0700863 }
864
Todd Rimmer4ccf28a2012-05-02 14:35:18 -0400865 if (clientrereg) {
866 event.event = IB_EVENT_CLIENT_REREGISTER;
867 ib_dispatch_event(&event);
868 }
869
Ralph Campbellf9315512010-05-23 21:44:54 -0700870 ret = subn_get_portinfo(smp, ibdev, port);
871
Todd Rimmer4ccf28a2012-05-02 14:35:18 -0400872 /* restore re-reg bit per o14-12.2.1 */
873 pip->clientrereg_resv_subnetto |= clientrereg;
Ralph Campbellf9315512010-05-23 21:44:54 -0700874
Mitko Haralanovcc7fb052011-02-22 16:56:37 -0800875 goto get_only;
Ralph Campbellf9315512010-05-23 21:44:54 -0700876
877err:
878 smp->status |= IB_SMP_INVALID_FIELD;
879get_only:
880 ret = subn_get_portinfo(smp, ibdev, port);
881done:
882 return ret;
883}
884
885/**
886 * rm_pkey - decrecment the reference count for the given PKEY
887 * @dd: the qlogic_ib device
888 * @key: the PKEY index
889 *
890 * Return true if this was the last reference and the hardware table entry
891 * needs to be changed.
892 */
893static int rm_pkey(struct qib_pportdata *ppd, u16 key)
894{
895 int i;
896 int ret;
897
898 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
899 if (ppd->pkeys[i] != key)
900 continue;
901 if (atomic_dec_and_test(&ppd->pkeyrefs[i])) {
902 ppd->pkeys[i] = 0;
903 ret = 1;
904 goto bail;
905 }
906 break;
907 }
908
909 ret = 0;
910
911bail:
912 return ret;
913}
914
915/**
916 * add_pkey - add the given PKEY to the hardware table
917 * @dd: the qlogic_ib device
918 * @key: the PKEY
919 *
920 * Return an error code if unable to add the entry, zero if no change,
921 * or 1 if the hardware PKEY register needs to be updated.
922 */
923static int add_pkey(struct qib_pportdata *ppd, u16 key)
924{
925 int i;
926 u16 lkey = key & 0x7FFF;
927 int any = 0;
928 int ret;
929
930 if (lkey == 0x7FFF) {
931 ret = 0;
932 goto bail;
933 }
934
935 /* Look for an empty slot or a matching PKEY. */
936 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
937 if (!ppd->pkeys[i]) {
938 any++;
939 continue;
940 }
941 /* If it matches exactly, try to increment the ref count */
942 if (ppd->pkeys[i] == key) {
943 if (atomic_inc_return(&ppd->pkeyrefs[i]) > 1) {
944 ret = 0;
945 goto bail;
946 }
947 /* Lost the race. Look for an empty slot below. */
948 atomic_dec(&ppd->pkeyrefs[i]);
949 any++;
950 }
951 /*
952 * It makes no sense to have both the limited and unlimited
953 * PKEY set at the same time since the unlimited one will
954 * disable the limited one.
955 */
956 if ((ppd->pkeys[i] & 0x7FFF) == lkey) {
957 ret = -EEXIST;
958 goto bail;
959 }
960 }
961 if (!any) {
962 ret = -EBUSY;
963 goto bail;
964 }
965 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
966 if (!ppd->pkeys[i] &&
967 atomic_inc_return(&ppd->pkeyrefs[i]) == 1) {
968 /* for qibstats, etc. */
969 ppd->pkeys[i] = key;
970 ret = 1;
971 goto bail;
972 }
973 }
974 ret = -EBUSY;
975
976bail:
977 return ret;
978}
979
980/**
981 * set_pkeys - set the PKEY table for ctxt 0
982 * @dd: the qlogic_ib device
983 * @port: the IB port number
984 * @pkeys: the PKEY table
985 */
986static int set_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys)
987{
988 struct qib_pportdata *ppd;
989 struct qib_ctxtdata *rcd;
990 int i;
991 int changed = 0;
992
993 /*
994 * IB port one/two always maps to context zero/one,
995 * always a kernel context, no locking needed
996 * If we get here with ppd setup, no need to check
997 * that rcd is valid.
998 */
999 ppd = dd->pport + (port - 1);
1000 rcd = dd->rcd[ppd->hw_pidx];
1001
1002 for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) {
1003 u16 key = pkeys[i];
1004 u16 okey = rcd->pkeys[i];
1005
1006 if (key == okey)
1007 continue;
1008 /*
1009 * The value of this PKEY table entry is changing.
1010 * Remove the old entry in the hardware's array of PKEYs.
1011 */
1012 if (okey & 0x7FFF)
1013 changed |= rm_pkey(ppd, okey);
1014 if (key & 0x7FFF) {
1015 int ret = add_pkey(ppd, key);
1016
1017 if (ret < 0)
1018 key = 0;
1019 else
1020 changed |= ret;
1021 }
1022 rcd->pkeys[i] = key;
1023 }
1024 if (changed) {
1025 struct ib_event event;
1026
1027 (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0);
1028
1029 event.event = IB_EVENT_PKEY_CHANGE;
1030 event.device = &dd->verbs_dev.ibdev;
1031 event.element.port_num = 1;
1032 ib_dispatch_event(&event);
1033 }
1034 return 0;
1035}
1036
1037static int subn_set_pkeytable(struct ib_smp *smp, struct ib_device *ibdev,
1038 u8 port)
1039{
1040 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
1041 __be16 *p = (__be16 *) smp->data;
1042 u16 *q = (u16 *) smp->data;
1043 struct qib_devdata *dd = dd_from_ibdev(ibdev);
1044 unsigned i, n = qib_get_npkeys(dd);
1045
1046 for (i = 0; i < n; i++)
1047 q[i] = be16_to_cpu(p[i]);
1048
1049 if (startpx != 0 || set_pkeys(dd, port, q) != 0)
1050 smp->status |= IB_SMP_INVALID_FIELD;
1051
1052 return subn_get_pkeytable(smp, ibdev, port);
1053}
1054
1055static int subn_get_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
1056 u8 port)
1057{
1058 struct qib_ibport *ibp = to_iport(ibdev, port);
1059 u8 *p = (u8 *) smp->data;
1060 unsigned i;
1061
1062 memset(smp->data, 0, sizeof(smp->data));
1063
1064 if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP))
1065 smp->status |= IB_SMP_UNSUP_METHOD;
1066 else
1067 for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2)
1068 *p++ = (ibp->sl_to_vl[i] << 4) | ibp->sl_to_vl[i + 1];
1069
1070 return reply(smp);
1071}
1072
1073static int subn_set_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev,
1074 u8 port)
1075{
1076 struct qib_ibport *ibp = to_iport(ibdev, port);
1077 u8 *p = (u8 *) smp->data;
1078 unsigned i;
1079
1080 if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP)) {
1081 smp->status |= IB_SMP_UNSUP_METHOD;
1082 return reply(smp);
1083 }
1084
1085 for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2, p++) {
1086 ibp->sl_to_vl[i] = *p >> 4;
1087 ibp->sl_to_vl[i + 1] = *p & 0xF;
1088 }
1089 qib_set_uevent_bits(ppd_from_ibp(to_iport(ibdev, port)),
1090 _QIB_EVENT_SL2VL_CHANGE_BIT);
1091
1092 return subn_get_sl_to_vl(smp, ibdev, port);
1093}
1094
1095static int subn_get_vl_arb(struct ib_smp *smp, struct ib_device *ibdev,
1096 u8 port)
1097{
1098 unsigned which = be32_to_cpu(smp->attr_mod) >> 16;
1099 struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
1100
1101 memset(smp->data, 0, sizeof(smp->data));
1102
1103 if (ppd->vls_supported == IB_VL_VL0)
1104 smp->status |= IB_SMP_UNSUP_METHOD;
1105 else if (which == IB_VLARB_LOWPRI_0_31)
1106 (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB,
1107 smp->data);
1108 else if (which == IB_VLARB_HIGHPRI_0_31)
1109 (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB,
1110 smp->data);
1111 else
1112 smp->status |= IB_SMP_INVALID_FIELD;
1113
1114 return reply(smp);
1115}
1116
1117static int subn_set_vl_arb(struct ib_smp *smp, struct ib_device *ibdev,
1118 u8 port)
1119{
1120 unsigned which = be32_to_cpu(smp->attr_mod) >> 16;
1121 struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
1122
1123 if (ppd->vls_supported == IB_VL_VL0)
1124 smp->status |= IB_SMP_UNSUP_METHOD;
1125 else if (which == IB_VLARB_LOWPRI_0_31)
1126 (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB,
1127 smp->data);
1128 else if (which == IB_VLARB_HIGHPRI_0_31)
1129 (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB,
1130 smp->data);
1131 else
1132 smp->status |= IB_SMP_INVALID_FIELD;
1133
1134 return subn_get_vl_arb(smp, ibdev, port);
1135}
1136
1137static int subn_trap_repress(struct ib_smp *smp, struct ib_device *ibdev,
1138 u8 port)
1139{
1140 /*
1141 * For now, we only send the trap once so no need to process this.
1142 * o13-6, o13-7,
1143 * o14-3.a4 The SMA shall not send any message in response to a valid
1144 * SubnTrapRepress() message.
1145 */
1146 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1147}
1148
Or Gerlitz6aea2132011-07-05 15:46:29 +00001149static int pma_get_classportinfo(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001150 struct ib_device *ibdev)
1151{
Or Gerlitz6aea2132011-07-05 15:46:29 +00001152 struct ib_class_port_info *p =
1153 (struct ib_class_port_info *)pmp->data;
Ralph Campbellf9315512010-05-23 21:44:54 -07001154 struct qib_devdata *dd = dd_from_ibdev(ibdev);
1155
1156 memset(pmp->data, 0, sizeof(pmp->data));
1157
Or Gerlitz6aea2132011-07-05 15:46:29 +00001158 if (pmp->mad_hdr.attr_mod != 0)
1159 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -07001160
1161 /* Note that AllPortSelect is not valid */
1162 p->base_version = 1;
1163 p->class_version = 1;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001164 p->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
Ralph Campbellf9315512010-05-23 21:44:54 -07001165 /*
1166 * Set the most significant bit of CM2 to indicate support for
1167 * congestion statistics
1168 */
1169 p->reserved[0] = dd->psxmitwait_supported << 7;
1170 /*
1171 * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
1172 */
1173 p->resp_time_value = 18;
1174
1175 return reply((struct ib_smp *) pmp);
1176}
1177
Or Gerlitz6aea2132011-07-05 15:46:29 +00001178static int pma_get_portsamplescontrol(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001179 struct ib_device *ibdev, u8 port)
1180{
1181 struct ib_pma_portsamplescontrol *p =
1182 (struct ib_pma_portsamplescontrol *)pmp->data;
1183 struct qib_ibdev *dev = to_idev(ibdev);
1184 struct qib_devdata *dd = dd_from_dev(dev);
1185 struct qib_ibport *ibp = to_iport(ibdev, port);
1186 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1187 unsigned long flags;
1188 u8 port_select = p->port_select;
1189
1190 memset(pmp->data, 0, sizeof(pmp->data));
1191
1192 p->port_select = port_select;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001193 if (pmp->mad_hdr.attr_mod != 0 || port_select != port) {
1194 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -07001195 goto bail;
1196 }
1197 spin_lock_irqsave(&ibp->lock, flags);
1198 p->tick = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PMA_TICKS);
1199 p->sample_status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
1200 p->counter_width = 4; /* 32 bit counters */
1201 p->counter_mask0_9 = COUNTER_MASK0_9;
1202 p->sample_start = cpu_to_be32(ibp->pma_sample_start);
1203 p->sample_interval = cpu_to_be32(ibp->pma_sample_interval);
1204 p->tag = cpu_to_be16(ibp->pma_tag);
1205 p->counter_select[0] = ibp->pma_counter_select[0];
1206 p->counter_select[1] = ibp->pma_counter_select[1];
1207 p->counter_select[2] = ibp->pma_counter_select[2];
1208 p->counter_select[3] = ibp->pma_counter_select[3];
1209 p->counter_select[4] = ibp->pma_counter_select[4];
1210 spin_unlock_irqrestore(&ibp->lock, flags);
1211
1212bail:
1213 return reply((struct ib_smp *) pmp);
1214}
1215
Or Gerlitz6aea2132011-07-05 15:46:29 +00001216static int pma_set_portsamplescontrol(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001217 struct ib_device *ibdev, u8 port)
1218{
1219 struct ib_pma_portsamplescontrol *p =
1220 (struct ib_pma_portsamplescontrol *)pmp->data;
1221 struct qib_ibdev *dev = to_idev(ibdev);
1222 struct qib_devdata *dd = dd_from_dev(dev);
1223 struct qib_ibport *ibp = to_iport(ibdev, port);
1224 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1225 unsigned long flags;
1226 u8 status, xmit_flags;
1227 int ret;
1228
Or Gerlitz6aea2132011-07-05 15:46:29 +00001229 if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
1230 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -07001231 ret = reply((struct ib_smp *) pmp);
1232 goto bail;
1233 }
1234
1235 spin_lock_irqsave(&ibp->lock, flags);
1236
1237 /* Port Sampling code owns the PS* HW counters */
1238 xmit_flags = ppd->cong_stats.flags;
1239 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_SAMPLE;
1240 status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
1241 if (status == IB_PMA_SAMPLE_STATUS_DONE ||
1242 (status == IB_PMA_SAMPLE_STATUS_RUNNING &&
1243 xmit_flags == IB_PMA_CONG_HW_CONTROL_TIMER)) {
1244 ibp->pma_sample_start = be32_to_cpu(p->sample_start);
1245 ibp->pma_sample_interval = be32_to_cpu(p->sample_interval);
1246 ibp->pma_tag = be16_to_cpu(p->tag);
1247 ibp->pma_counter_select[0] = p->counter_select[0];
1248 ibp->pma_counter_select[1] = p->counter_select[1];
1249 ibp->pma_counter_select[2] = p->counter_select[2];
1250 ibp->pma_counter_select[3] = p->counter_select[3];
1251 ibp->pma_counter_select[4] = p->counter_select[4];
1252 dd->f_set_cntr_sample(ppd, ibp->pma_sample_interval,
1253 ibp->pma_sample_start);
1254 }
1255 spin_unlock_irqrestore(&ibp->lock, flags);
1256
1257 ret = pma_get_portsamplescontrol(pmp, ibdev, port);
1258
1259bail:
1260 return ret;
1261}
1262
1263static u64 get_counter(struct qib_ibport *ibp, struct qib_pportdata *ppd,
1264 __be16 sel)
1265{
1266 u64 ret;
1267
1268 switch (sel) {
1269 case IB_PMA_PORT_XMIT_DATA:
1270 ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITDATA);
1271 break;
1272 case IB_PMA_PORT_RCV_DATA:
1273 ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVDATA);
1274 break;
1275 case IB_PMA_PORT_XMIT_PKTS:
1276 ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITPKTS);
1277 break;
1278 case IB_PMA_PORT_RCV_PKTS:
1279 ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVPKTS);
1280 break;
1281 case IB_PMA_PORT_XMIT_WAIT:
1282 ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITWAIT);
1283 break;
1284 default:
1285 ret = 0;
1286 }
1287
1288 return ret;
1289}
1290
1291/* This function assumes that the xmit_wait lock is already held */
1292static u64 xmit_wait_get_value_delta(struct qib_pportdata *ppd)
1293{
1294 u32 delta;
1295
1296 delta = get_counter(&ppd->ibport_data, ppd,
1297 IB_PMA_PORT_XMIT_WAIT);
1298 return ppd->cong_stats.counter + delta;
1299}
1300
1301static void cache_hw_sample_counters(struct qib_pportdata *ppd)
1302{
1303 struct qib_ibport *ibp = &ppd->ibport_data;
1304
1305 ppd->cong_stats.counter_cache.psxmitdata =
1306 get_counter(ibp, ppd, IB_PMA_PORT_XMIT_DATA);
1307 ppd->cong_stats.counter_cache.psrcvdata =
1308 get_counter(ibp, ppd, IB_PMA_PORT_RCV_DATA);
1309 ppd->cong_stats.counter_cache.psxmitpkts =
1310 get_counter(ibp, ppd, IB_PMA_PORT_XMIT_PKTS);
1311 ppd->cong_stats.counter_cache.psrcvpkts =
1312 get_counter(ibp, ppd, IB_PMA_PORT_RCV_PKTS);
1313 ppd->cong_stats.counter_cache.psxmitwait =
1314 get_counter(ibp, ppd, IB_PMA_PORT_XMIT_WAIT);
1315}
1316
1317static u64 get_cache_hw_sample_counters(struct qib_pportdata *ppd,
1318 __be16 sel)
1319{
1320 u64 ret;
1321
1322 switch (sel) {
1323 case IB_PMA_PORT_XMIT_DATA:
1324 ret = ppd->cong_stats.counter_cache.psxmitdata;
1325 break;
1326 case IB_PMA_PORT_RCV_DATA:
1327 ret = ppd->cong_stats.counter_cache.psrcvdata;
1328 break;
1329 case IB_PMA_PORT_XMIT_PKTS:
1330 ret = ppd->cong_stats.counter_cache.psxmitpkts;
1331 break;
1332 case IB_PMA_PORT_RCV_PKTS:
1333 ret = ppd->cong_stats.counter_cache.psrcvpkts;
1334 break;
1335 case IB_PMA_PORT_XMIT_WAIT:
1336 ret = ppd->cong_stats.counter_cache.psxmitwait;
1337 break;
1338 default:
1339 ret = 0;
1340 }
1341
1342 return ret;
1343}
1344
Or Gerlitz6aea2132011-07-05 15:46:29 +00001345static int pma_get_portsamplesresult(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001346 struct ib_device *ibdev, u8 port)
1347{
1348 struct ib_pma_portsamplesresult *p =
1349 (struct ib_pma_portsamplesresult *)pmp->data;
1350 struct qib_ibdev *dev = to_idev(ibdev);
1351 struct qib_devdata *dd = dd_from_dev(dev);
1352 struct qib_ibport *ibp = to_iport(ibdev, port);
1353 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1354 unsigned long flags;
1355 u8 status;
1356 int i;
1357
1358 memset(pmp->data, 0, sizeof(pmp->data));
1359 spin_lock_irqsave(&ibp->lock, flags);
1360 p->tag = cpu_to_be16(ibp->pma_tag);
1361 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
1362 p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
1363 else {
1364 status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
1365 p->sample_status = cpu_to_be16(status);
1366 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
1367 cache_hw_sample_counters(ppd);
1368 ppd->cong_stats.counter =
1369 xmit_wait_get_value_delta(ppd);
1370 dd->f_set_cntr_sample(ppd,
1371 QIB_CONG_TIMER_PSINTERVAL, 0);
1372 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
1373 }
1374 }
1375 for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++)
1376 p->counter[i] = cpu_to_be32(
1377 get_cache_hw_sample_counters(
1378 ppd, ibp->pma_counter_select[i]));
1379 spin_unlock_irqrestore(&ibp->lock, flags);
1380
1381 return reply((struct ib_smp *) pmp);
1382}
1383
Or Gerlitz6aea2132011-07-05 15:46:29 +00001384static int pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001385 struct ib_device *ibdev, u8 port)
1386{
1387 struct ib_pma_portsamplesresult_ext *p =
1388 (struct ib_pma_portsamplesresult_ext *)pmp->data;
1389 struct qib_ibdev *dev = to_idev(ibdev);
1390 struct qib_devdata *dd = dd_from_dev(dev);
1391 struct qib_ibport *ibp = to_iport(ibdev, port);
1392 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1393 unsigned long flags;
1394 u8 status;
1395 int i;
1396
1397 /* Port Sampling code owns the PS* HW counters */
1398 memset(pmp->data, 0, sizeof(pmp->data));
1399 spin_lock_irqsave(&ibp->lock, flags);
1400 p->tag = cpu_to_be16(ibp->pma_tag);
1401 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER)
1402 p->sample_status = IB_PMA_SAMPLE_STATUS_DONE;
1403 else {
1404 status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
1405 p->sample_status = cpu_to_be16(status);
1406 /* 64 bits */
1407 p->extended_width = cpu_to_be32(0x80000000);
1408 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
1409 cache_hw_sample_counters(ppd);
1410 ppd->cong_stats.counter =
1411 xmit_wait_get_value_delta(ppd);
1412 dd->f_set_cntr_sample(ppd,
1413 QIB_CONG_TIMER_PSINTERVAL, 0);
1414 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
1415 }
1416 }
1417 for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++)
1418 p->counter[i] = cpu_to_be64(
1419 get_cache_hw_sample_counters(
1420 ppd, ibp->pma_counter_select[i]));
1421 spin_unlock_irqrestore(&ibp->lock, flags);
1422
1423 return reply((struct ib_smp *) pmp);
1424}
1425
Or Gerlitz6aea2132011-07-05 15:46:29 +00001426static int pma_get_portcounters(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001427 struct ib_device *ibdev, u8 port)
1428{
1429 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1430 pmp->data;
1431 struct qib_ibport *ibp = to_iport(ibdev, port);
1432 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1433 struct qib_verbs_counters cntrs;
1434 u8 port_select = p->port_select;
1435
1436 qib_get_counters(ppd, &cntrs);
1437
1438 /* Adjust counters for any resets done. */
1439 cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
1440 cntrs.link_error_recovery_counter -=
1441 ibp->z_link_error_recovery_counter;
1442 cntrs.link_downed_counter -= ibp->z_link_downed_counter;
1443 cntrs.port_rcv_errors -= ibp->z_port_rcv_errors;
1444 cntrs.port_rcv_remphys_errors -= ibp->z_port_rcv_remphys_errors;
1445 cntrs.port_xmit_discards -= ibp->z_port_xmit_discards;
1446 cntrs.port_xmit_data -= ibp->z_port_xmit_data;
1447 cntrs.port_rcv_data -= ibp->z_port_rcv_data;
1448 cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
1449 cntrs.port_rcv_packets -= ibp->z_port_rcv_packets;
1450 cntrs.local_link_integrity_errors -=
1451 ibp->z_local_link_integrity_errors;
1452 cntrs.excessive_buffer_overrun_errors -=
1453 ibp->z_excessive_buffer_overrun_errors;
1454 cntrs.vl15_dropped -= ibp->z_vl15_dropped;
1455 cntrs.vl15_dropped += ibp->n_vl15_dropped;
1456
1457 memset(pmp->data, 0, sizeof(pmp->data));
1458
1459 p->port_select = port_select;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001460 if (pmp->mad_hdr.attr_mod != 0 || port_select != port)
1461 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -07001462
1463 if (cntrs.symbol_error_counter > 0xFFFFUL)
1464 p->symbol_error_counter = cpu_to_be16(0xFFFF);
1465 else
1466 p->symbol_error_counter =
1467 cpu_to_be16((u16)cntrs.symbol_error_counter);
1468 if (cntrs.link_error_recovery_counter > 0xFFUL)
1469 p->link_error_recovery_counter = 0xFF;
1470 else
1471 p->link_error_recovery_counter =
1472 (u8)cntrs.link_error_recovery_counter;
1473 if (cntrs.link_downed_counter > 0xFFUL)
1474 p->link_downed_counter = 0xFF;
1475 else
1476 p->link_downed_counter = (u8)cntrs.link_downed_counter;
1477 if (cntrs.port_rcv_errors > 0xFFFFUL)
1478 p->port_rcv_errors = cpu_to_be16(0xFFFF);
1479 else
1480 p->port_rcv_errors =
1481 cpu_to_be16((u16) cntrs.port_rcv_errors);
1482 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1483 p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
1484 else
1485 p->port_rcv_remphys_errors =
1486 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
1487 if (cntrs.port_xmit_discards > 0xFFFFUL)
1488 p->port_xmit_discards = cpu_to_be16(0xFFFF);
1489 else
1490 p->port_xmit_discards =
1491 cpu_to_be16((u16)cntrs.port_xmit_discards);
1492 if (cntrs.local_link_integrity_errors > 0xFUL)
1493 cntrs.local_link_integrity_errors = 0xFUL;
1494 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1495 cntrs.excessive_buffer_overrun_errors = 0xFUL;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001496 p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
Ralph Campbellf9315512010-05-23 21:44:54 -07001497 cntrs.excessive_buffer_overrun_errors;
1498 if (cntrs.vl15_dropped > 0xFFFFUL)
1499 p->vl15_dropped = cpu_to_be16(0xFFFF);
1500 else
1501 p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
1502 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
1503 p->port_xmit_data = cpu_to_be32(0xFFFFFFFF);
1504 else
1505 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
1506 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
1507 p->port_rcv_data = cpu_to_be32(0xFFFFFFFF);
1508 else
1509 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
1510 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
1511 p->port_xmit_packets = cpu_to_be32(0xFFFFFFFF);
1512 else
1513 p->port_xmit_packets =
1514 cpu_to_be32((u32)cntrs.port_xmit_packets);
1515 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
1516 p->port_rcv_packets = cpu_to_be32(0xFFFFFFFF);
1517 else
1518 p->port_rcv_packets =
1519 cpu_to_be32((u32) cntrs.port_rcv_packets);
1520
1521 return reply((struct ib_smp *) pmp);
1522}
1523
Or Gerlitz6aea2132011-07-05 15:46:29 +00001524static int pma_get_portcounters_cong(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001525 struct ib_device *ibdev, u8 port)
1526{
1527 /* Congestion PMA packets start at offset 24 not 64 */
1528 struct ib_pma_portcounters_cong *p =
1529 (struct ib_pma_portcounters_cong *)pmp->reserved;
1530 struct qib_verbs_counters cntrs;
1531 struct qib_ibport *ibp = to_iport(ibdev, port);
1532 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1533 struct qib_devdata *dd = dd_from_ppd(ppd);
Or Gerlitz6aea2132011-07-05 15:46:29 +00001534 u32 port_select = be32_to_cpu(pmp->mad_hdr.attr_mod) & 0xFF;
Ralph Campbellf9315512010-05-23 21:44:54 -07001535 u64 xmit_wait_counter;
1536 unsigned long flags;
1537
1538 /*
1539 * This check is performed only in the GET method because the
1540 * SET method ends up calling this anyway.
1541 */
1542 if (!dd->psxmitwait_supported)
Or Gerlitz6aea2132011-07-05 15:46:29 +00001543 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
Ralph Campbellf9315512010-05-23 21:44:54 -07001544 if (port_select != port)
Or Gerlitz6aea2132011-07-05 15:46:29 +00001545 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -07001546
1547 qib_get_counters(ppd, &cntrs);
1548 spin_lock_irqsave(&ppd->ibport_data.lock, flags);
1549 xmit_wait_counter = xmit_wait_get_value_delta(ppd);
1550 spin_unlock_irqrestore(&ppd->ibport_data.lock, flags);
1551
1552 /* Adjust counters for any resets done. */
1553 cntrs.symbol_error_counter -= ibp->z_symbol_error_counter;
1554 cntrs.link_error_recovery_counter -=
1555 ibp->z_link_error_recovery_counter;
1556 cntrs.link_downed_counter -= ibp->z_link_downed_counter;
1557 cntrs.port_rcv_errors -= ibp->z_port_rcv_errors;
1558 cntrs.port_rcv_remphys_errors -=
1559 ibp->z_port_rcv_remphys_errors;
1560 cntrs.port_xmit_discards -= ibp->z_port_xmit_discards;
1561 cntrs.local_link_integrity_errors -=
1562 ibp->z_local_link_integrity_errors;
1563 cntrs.excessive_buffer_overrun_errors -=
1564 ibp->z_excessive_buffer_overrun_errors;
1565 cntrs.vl15_dropped -= ibp->z_vl15_dropped;
1566 cntrs.vl15_dropped += ibp->n_vl15_dropped;
1567 cntrs.port_xmit_data -= ibp->z_port_xmit_data;
1568 cntrs.port_rcv_data -= ibp->z_port_rcv_data;
1569 cntrs.port_xmit_packets -= ibp->z_port_xmit_packets;
1570 cntrs.port_rcv_packets -= ibp->z_port_rcv_packets;
1571
1572 memset(pmp->reserved, 0, sizeof(pmp->reserved) +
1573 sizeof(pmp->data));
1574
1575 /*
1576 * Set top 3 bits to indicate interval in picoseconds in
1577 * remaining bits.
1578 */
1579 p->port_check_rate =
1580 cpu_to_be16((QIB_XMIT_RATE_PICO << 13) |
1581 (dd->psxmitwait_check_rate &
1582 ~(QIB_XMIT_RATE_PICO << 13)));
1583 p->port_adr_events = cpu_to_be64(0);
1584 p->port_xmit_wait = cpu_to_be64(xmit_wait_counter);
1585 p->port_xmit_data = cpu_to_be64(cntrs.port_xmit_data);
1586 p->port_rcv_data = cpu_to_be64(cntrs.port_rcv_data);
1587 p->port_xmit_packets =
1588 cpu_to_be64(cntrs.port_xmit_packets);
1589 p->port_rcv_packets =
1590 cpu_to_be64(cntrs.port_rcv_packets);
1591 if (cntrs.symbol_error_counter > 0xFFFFUL)
1592 p->symbol_error_counter = cpu_to_be16(0xFFFF);
1593 else
1594 p->symbol_error_counter =
1595 cpu_to_be16(
1596 (u16)cntrs.symbol_error_counter);
1597 if (cntrs.link_error_recovery_counter > 0xFFUL)
1598 p->link_error_recovery_counter = 0xFF;
1599 else
1600 p->link_error_recovery_counter =
1601 (u8)cntrs.link_error_recovery_counter;
1602 if (cntrs.link_downed_counter > 0xFFUL)
1603 p->link_downed_counter = 0xFF;
1604 else
1605 p->link_downed_counter =
1606 (u8)cntrs.link_downed_counter;
1607 if (cntrs.port_rcv_errors > 0xFFFFUL)
1608 p->port_rcv_errors = cpu_to_be16(0xFFFF);
1609 else
1610 p->port_rcv_errors =
1611 cpu_to_be16((u16) cntrs.port_rcv_errors);
1612 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
1613 p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
1614 else
1615 p->port_rcv_remphys_errors =
1616 cpu_to_be16(
1617 (u16)cntrs.port_rcv_remphys_errors);
1618 if (cntrs.port_xmit_discards > 0xFFFFUL)
1619 p->port_xmit_discards = cpu_to_be16(0xFFFF);
1620 else
1621 p->port_xmit_discards =
1622 cpu_to_be16((u16)cntrs.port_xmit_discards);
1623 if (cntrs.local_link_integrity_errors > 0xFUL)
1624 cntrs.local_link_integrity_errors = 0xFUL;
1625 if (cntrs.excessive_buffer_overrun_errors > 0xFUL)
1626 cntrs.excessive_buffer_overrun_errors = 0xFUL;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001627 p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) |
Ralph Campbellf9315512010-05-23 21:44:54 -07001628 cntrs.excessive_buffer_overrun_errors;
1629 if (cntrs.vl15_dropped > 0xFFFFUL)
1630 p->vl15_dropped = cpu_to_be16(0xFFFF);
1631 else
1632 p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped);
1633
1634 return reply((struct ib_smp *)pmp);
1635}
1636
Or Gerlitz6aea2132011-07-05 15:46:29 +00001637static int pma_get_portcounters_ext(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001638 struct ib_device *ibdev, u8 port)
1639{
1640 struct ib_pma_portcounters_ext *p =
1641 (struct ib_pma_portcounters_ext *)pmp->data;
1642 struct qib_ibport *ibp = to_iport(ibdev, port);
1643 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1644 u64 swords, rwords, spkts, rpkts, xwait;
1645 u8 port_select = p->port_select;
1646
1647 memset(pmp->data, 0, sizeof(pmp->data));
1648
1649 p->port_select = port_select;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001650 if (pmp->mad_hdr.attr_mod != 0 || port_select != port) {
1651 pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
Ralph Campbellf9315512010-05-23 21:44:54 -07001652 goto bail;
1653 }
1654
1655 qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait);
1656
1657 /* Adjust counters for any resets done. */
1658 swords -= ibp->z_port_xmit_data;
1659 rwords -= ibp->z_port_rcv_data;
1660 spkts -= ibp->z_port_xmit_packets;
1661 rpkts -= ibp->z_port_rcv_packets;
1662
1663 p->port_xmit_data = cpu_to_be64(swords);
1664 p->port_rcv_data = cpu_to_be64(rwords);
1665 p->port_xmit_packets = cpu_to_be64(spkts);
1666 p->port_rcv_packets = cpu_to_be64(rpkts);
1667 p->port_unicast_xmit_packets = cpu_to_be64(ibp->n_unicast_xmit);
1668 p->port_unicast_rcv_packets = cpu_to_be64(ibp->n_unicast_rcv);
1669 p->port_multicast_xmit_packets = cpu_to_be64(ibp->n_multicast_xmit);
1670 p->port_multicast_rcv_packets = cpu_to_be64(ibp->n_multicast_rcv);
1671
1672bail:
1673 return reply((struct ib_smp *) pmp);
1674}
1675
Or Gerlitz6aea2132011-07-05 15:46:29 +00001676static int pma_set_portcounters(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001677 struct ib_device *ibdev, u8 port)
1678{
1679 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1680 pmp->data;
1681 struct qib_ibport *ibp = to_iport(ibdev, port);
1682 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1683 struct qib_verbs_counters cntrs;
1684
1685 /*
1686 * Since the HW doesn't support clearing counters, we save the
1687 * current count and subtract it from future responses.
1688 */
1689 qib_get_counters(ppd, &cntrs);
1690
1691 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
1692 ibp->z_symbol_error_counter = cntrs.symbol_error_counter;
1693
1694 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
1695 ibp->z_link_error_recovery_counter =
1696 cntrs.link_error_recovery_counter;
1697
1698 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
1699 ibp->z_link_downed_counter = cntrs.link_downed_counter;
1700
1701 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
1702 ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
1703
1704 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
1705 ibp->z_port_rcv_remphys_errors =
1706 cntrs.port_rcv_remphys_errors;
1707
1708 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
1709 ibp->z_port_xmit_discards = cntrs.port_xmit_discards;
1710
1711 if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS)
1712 ibp->z_local_link_integrity_errors =
1713 cntrs.local_link_integrity_errors;
1714
1715 if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS)
1716 ibp->z_excessive_buffer_overrun_errors =
1717 cntrs.excessive_buffer_overrun_errors;
1718
1719 if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) {
1720 ibp->n_vl15_dropped = 0;
1721 ibp->z_vl15_dropped = cntrs.vl15_dropped;
1722 }
1723
1724 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
1725 ibp->z_port_xmit_data = cntrs.port_xmit_data;
1726
1727 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
1728 ibp->z_port_rcv_data = cntrs.port_rcv_data;
1729
1730 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1731 ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
1732
1733 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1734 ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
1735
1736 return pma_get_portcounters(pmp, ibdev, port);
1737}
1738
Or Gerlitz6aea2132011-07-05 15:46:29 +00001739static int pma_set_portcounters_cong(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001740 struct ib_device *ibdev, u8 port)
1741{
1742 struct qib_ibport *ibp = to_iport(ibdev, port);
1743 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1744 struct qib_devdata *dd = dd_from_ppd(ppd);
1745 struct qib_verbs_counters cntrs;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001746 u32 counter_select = (be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24) & 0xFF;
Ralph Campbellf9315512010-05-23 21:44:54 -07001747 int ret = 0;
1748 unsigned long flags;
1749
1750 qib_get_counters(ppd, &cntrs);
1751 /* Get counter values before we save them */
1752 ret = pma_get_portcounters_cong(pmp, ibdev, port);
1753
1754 if (counter_select & IB_PMA_SEL_CONG_XMIT) {
1755 spin_lock_irqsave(&ppd->ibport_data.lock, flags);
1756 ppd->cong_stats.counter = 0;
1757 dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL,
1758 0x0);
1759 spin_unlock_irqrestore(&ppd->ibport_data.lock, flags);
1760 }
1761 if (counter_select & IB_PMA_SEL_CONG_PORT_DATA) {
1762 ibp->z_port_xmit_data = cntrs.port_xmit_data;
1763 ibp->z_port_rcv_data = cntrs.port_rcv_data;
1764 ibp->z_port_xmit_packets = cntrs.port_xmit_packets;
1765 ibp->z_port_rcv_packets = cntrs.port_rcv_packets;
1766 }
1767 if (counter_select & IB_PMA_SEL_CONG_ALL) {
1768 ibp->z_symbol_error_counter =
1769 cntrs.symbol_error_counter;
1770 ibp->z_link_error_recovery_counter =
1771 cntrs.link_error_recovery_counter;
1772 ibp->z_link_downed_counter =
1773 cntrs.link_downed_counter;
1774 ibp->z_port_rcv_errors = cntrs.port_rcv_errors;
1775 ibp->z_port_rcv_remphys_errors =
1776 cntrs.port_rcv_remphys_errors;
1777 ibp->z_port_xmit_discards =
1778 cntrs.port_xmit_discards;
1779 ibp->z_local_link_integrity_errors =
1780 cntrs.local_link_integrity_errors;
1781 ibp->z_excessive_buffer_overrun_errors =
1782 cntrs.excessive_buffer_overrun_errors;
1783 ibp->n_vl15_dropped = 0;
1784 ibp->z_vl15_dropped = cntrs.vl15_dropped;
1785 }
1786
1787 return ret;
1788}
1789
Or Gerlitz6aea2132011-07-05 15:46:29 +00001790static int pma_set_portcounters_ext(struct ib_pma_mad *pmp,
Ralph Campbellf9315512010-05-23 21:44:54 -07001791 struct ib_device *ibdev, u8 port)
1792{
1793 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1794 pmp->data;
1795 struct qib_ibport *ibp = to_iport(ibdev, port);
1796 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1797 u64 swords, rwords, spkts, rpkts, xwait;
1798
1799 qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait);
1800
1801 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1802 ibp->z_port_xmit_data = swords;
1803
1804 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1805 ibp->z_port_rcv_data = rwords;
1806
1807 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1808 ibp->z_port_xmit_packets = spkts;
1809
1810 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1811 ibp->z_port_rcv_packets = rpkts;
1812
1813 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1814 ibp->n_unicast_xmit = 0;
1815
1816 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1817 ibp->n_unicast_rcv = 0;
1818
1819 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1820 ibp->n_multicast_xmit = 0;
1821
1822 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1823 ibp->n_multicast_rcv = 0;
1824
1825 return pma_get_portcounters_ext(pmp, ibdev, port);
1826}
1827
1828static int process_subn(struct ib_device *ibdev, int mad_flags,
1829 u8 port, struct ib_mad *in_mad,
1830 struct ib_mad *out_mad)
1831{
1832 struct ib_smp *smp = (struct ib_smp *)out_mad;
1833 struct qib_ibport *ibp = to_iport(ibdev, port);
1834 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
1835 int ret;
1836
1837 *out_mad = *in_mad;
1838 if (smp->class_version != 1) {
1839 smp->status |= IB_SMP_UNSUP_VERSION;
1840 ret = reply(smp);
1841 goto bail;
1842 }
1843
1844 ret = check_mkey(ibp, smp, mad_flags);
1845 if (ret) {
1846 u32 port_num = be32_to_cpu(smp->attr_mod);
1847
1848 /*
1849 * If this is a get/set portinfo, we already check the
1850 * M_Key if the MAD is for another port and the M_Key
1851 * is OK on the receiving port. This check is needed
1852 * to increment the error counters when the M_Key
1853 * fails to match on *both* ports.
1854 */
1855 if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
1856 (smp->method == IB_MGMT_METHOD_GET ||
1857 smp->method == IB_MGMT_METHOD_SET) &&
1858 port_num && port_num <= ibdev->phys_port_cnt &&
1859 port != port_num)
1860 (void) check_mkey(to_iport(ibdev, port_num), smp, 0);
Jim Foraker3236b2d2012-05-02 14:57:23 -04001861 ret = IB_MAD_RESULT_FAILURE;
Ralph Campbellf9315512010-05-23 21:44:54 -07001862 goto bail;
1863 }
1864
1865 switch (smp->method) {
1866 case IB_MGMT_METHOD_GET:
1867 switch (smp->attr_id) {
1868 case IB_SMP_ATTR_NODE_DESC:
1869 ret = subn_get_nodedescription(smp, ibdev);
1870 goto bail;
1871 case IB_SMP_ATTR_NODE_INFO:
1872 ret = subn_get_nodeinfo(smp, ibdev, port);
1873 goto bail;
1874 case IB_SMP_ATTR_GUID_INFO:
1875 ret = subn_get_guidinfo(smp, ibdev, port);
1876 goto bail;
1877 case IB_SMP_ATTR_PORT_INFO:
1878 ret = subn_get_portinfo(smp, ibdev, port);
1879 goto bail;
1880 case IB_SMP_ATTR_PKEY_TABLE:
1881 ret = subn_get_pkeytable(smp, ibdev, port);
1882 goto bail;
1883 case IB_SMP_ATTR_SL_TO_VL_TABLE:
1884 ret = subn_get_sl_to_vl(smp, ibdev, port);
1885 goto bail;
1886 case IB_SMP_ATTR_VL_ARB_TABLE:
1887 ret = subn_get_vl_arb(smp, ibdev, port);
1888 goto bail;
1889 case IB_SMP_ATTR_SM_INFO:
1890 if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) {
1891 ret = IB_MAD_RESULT_SUCCESS |
1892 IB_MAD_RESULT_CONSUMED;
1893 goto bail;
1894 }
1895 if (ibp->port_cap_flags & IB_PORT_SM) {
1896 ret = IB_MAD_RESULT_SUCCESS;
1897 goto bail;
1898 }
1899 /* FALLTHROUGH */
1900 default:
1901 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1902 ret = reply(smp);
1903 goto bail;
1904 }
1905
1906 case IB_MGMT_METHOD_SET:
1907 switch (smp->attr_id) {
1908 case IB_SMP_ATTR_GUID_INFO:
1909 ret = subn_set_guidinfo(smp, ibdev, port);
1910 goto bail;
1911 case IB_SMP_ATTR_PORT_INFO:
1912 ret = subn_set_portinfo(smp, ibdev, port);
1913 goto bail;
1914 case IB_SMP_ATTR_PKEY_TABLE:
1915 ret = subn_set_pkeytable(smp, ibdev, port);
1916 goto bail;
1917 case IB_SMP_ATTR_SL_TO_VL_TABLE:
1918 ret = subn_set_sl_to_vl(smp, ibdev, port);
1919 goto bail;
1920 case IB_SMP_ATTR_VL_ARB_TABLE:
1921 ret = subn_set_vl_arb(smp, ibdev, port);
1922 goto bail;
1923 case IB_SMP_ATTR_SM_INFO:
1924 if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) {
1925 ret = IB_MAD_RESULT_SUCCESS |
1926 IB_MAD_RESULT_CONSUMED;
1927 goto bail;
1928 }
1929 if (ibp->port_cap_flags & IB_PORT_SM) {
1930 ret = IB_MAD_RESULT_SUCCESS;
1931 goto bail;
1932 }
1933 /* FALLTHROUGH */
1934 default:
1935 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1936 ret = reply(smp);
1937 goto bail;
1938 }
1939
1940 case IB_MGMT_METHOD_TRAP_REPRESS:
1941 if (smp->attr_id == IB_SMP_ATTR_NOTICE)
1942 ret = subn_trap_repress(smp, ibdev, port);
1943 else {
1944 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1945 ret = reply(smp);
1946 }
1947 goto bail;
1948
1949 case IB_MGMT_METHOD_TRAP:
1950 case IB_MGMT_METHOD_REPORT:
1951 case IB_MGMT_METHOD_REPORT_RESP:
1952 case IB_MGMT_METHOD_GET_RESP:
1953 /*
1954 * The ib_mad module will call us to process responses
1955 * before checking for other consumers.
1956 * Just tell the caller to process it normally.
1957 */
1958 ret = IB_MAD_RESULT_SUCCESS;
1959 goto bail;
1960
1961 case IB_MGMT_METHOD_SEND:
1962 if (ib_get_smp_direction(smp) &&
1963 smp->attr_id == QIB_VENDOR_IPG) {
1964 ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PORT,
1965 smp->data[0]);
1966 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1967 } else
1968 ret = IB_MAD_RESULT_SUCCESS;
1969 goto bail;
1970
1971 default:
1972 smp->status |= IB_SMP_UNSUP_METHOD;
1973 ret = reply(smp);
1974 }
1975
1976bail:
1977 return ret;
1978}
1979
1980static int process_perf(struct ib_device *ibdev, u8 port,
1981 struct ib_mad *in_mad,
1982 struct ib_mad *out_mad)
1983{
Or Gerlitz6aea2132011-07-05 15:46:29 +00001984 struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
Ralph Campbellf9315512010-05-23 21:44:54 -07001985 int ret;
1986
1987 *out_mad = *in_mad;
Or Gerlitz6aea2132011-07-05 15:46:29 +00001988 if (pmp->mad_hdr.class_version != 1) {
1989 pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
Ralph Campbellf9315512010-05-23 21:44:54 -07001990 ret = reply((struct ib_smp *) pmp);
1991 goto bail;
1992 }
1993
Or Gerlitz6aea2132011-07-05 15:46:29 +00001994 switch (pmp->mad_hdr.method) {
Ralph Campbellf9315512010-05-23 21:44:54 -07001995 case IB_MGMT_METHOD_GET:
Or Gerlitz6aea2132011-07-05 15:46:29 +00001996 switch (pmp->mad_hdr.attr_id) {
Ralph Campbellf9315512010-05-23 21:44:54 -07001997 case IB_PMA_CLASS_PORT_INFO:
1998 ret = pma_get_classportinfo(pmp, ibdev);
1999 goto bail;
2000 case IB_PMA_PORT_SAMPLES_CONTROL:
2001 ret = pma_get_portsamplescontrol(pmp, ibdev, port);
2002 goto bail;
2003 case IB_PMA_PORT_SAMPLES_RESULT:
2004 ret = pma_get_portsamplesresult(pmp, ibdev, port);
2005 goto bail;
2006 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
2007 ret = pma_get_portsamplesresult_ext(pmp, ibdev, port);
2008 goto bail;
2009 case IB_PMA_PORT_COUNTERS:
2010 ret = pma_get_portcounters(pmp, ibdev, port);
2011 goto bail;
2012 case IB_PMA_PORT_COUNTERS_EXT:
2013 ret = pma_get_portcounters_ext(pmp, ibdev, port);
2014 goto bail;
2015 case IB_PMA_PORT_COUNTERS_CONG:
2016 ret = pma_get_portcounters_cong(pmp, ibdev, port);
2017 goto bail;
2018 default:
Or Gerlitz6aea2132011-07-05 15:46:29 +00002019 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
Ralph Campbellf9315512010-05-23 21:44:54 -07002020 ret = reply((struct ib_smp *) pmp);
2021 goto bail;
2022 }
2023
2024 case IB_MGMT_METHOD_SET:
Or Gerlitz6aea2132011-07-05 15:46:29 +00002025 switch (pmp->mad_hdr.attr_id) {
Ralph Campbellf9315512010-05-23 21:44:54 -07002026 case IB_PMA_PORT_SAMPLES_CONTROL:
2027 ret = pma_set_portsamplescontrol(pmp, ibdev, port);
2028 goto bail;
2029 case IB_PMA_PORT_COUNTERS:
2030 ret = pma_set_portcounters(pmp, ibdev, port);
2031 goto bail;
2032 case IB_PMA_PORT_COUNTERS_EXT:
2033 ret = pma_set_portcounters_ext(pmp, ibdev, port);
2034 goto bail;
2035 case IB_PMA_PORT_COUNTERS_CONG:
2036 ret = pma_set_portcounters_cong(pmp, ibdev, port);
2037 goto bail;
2038 default:
Or Gerlitz6aea2132011-07-05 15:46:29 +00002039 pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
Ralph Campbellf9315512010-05-23 21:44:54 -07002040 ret = reply((struct ib_smp *) pmp);
2041 goto bail;
2042 }
2043
2044 case IB_MGMT_METHOD_TRAP:
2045 case IB_MGMT_METHOD_GET_RESP:
2046 /*
2047 * The ib_mad module will call us to process responses
2048 * before checking for other consumers.
2049 * Just tell the caller to process it normally.
2050 */
2051 ret = IB_MAD_RESULT_SUCCESS;
2052 goto bail;
2053
2054 default:
Or Gerlitz6aea2132011-07-05 15:46:29 +00002055 pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
Ralph Campbellf9315512010-05-23 21:44:54 -07002056 ret = reply((struct ib_smp *) pmp);
2057 }
2058
2059bail:
2060 return ret;
2061}
2062
Mike Marciniszyn36a8f012012-07-19 13:04:04 +00002063static int cc_get_classportinfo(struct ib_cc_mad *ccp,
2064 struct ib_device *ibdev)
2065{
2066 struct ib_cc_classportinfo_attr *p =
2067 (struct ib_cc_classportinfo_attr *)ccp->mgmt_data;
2068
2069 memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
2070
2071 p->base_version = 1;
2072 p->class_version = 1;
2073 p->cap_mask = 0;
2074
2075 /*
2076 * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
2077 */
2078 p->resp_time_value = 18;
2079
2080 return reply((struct ib_smp *) ccp);
2081}
2082
2083static int cc_get_congestion_info(struct ib_cc_mad *ccp,
2084 struct ib_device *ibdev, u8 port)
2085{
2086 struct ib_cc_info_attr *p =
2087 (struct ib_cc_info_attr *)ccp->mgmt_data;
2088 struct qib_ibport *ibp = to_iport(ibdev, port);
2089 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2090
2091 memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
2092
2093 p->congestion_info = 0;
2094 p->control_table_cap = ppd->cc_max_table_entries;
2095
2096 return reply((struct ib_smp *) ccp);
2097}
2098
2099static int cc_get_congestion_setting(struct ib_cc_mad *ccp,
2100 struct ib_device *ibdev, u8 port)
2101{
2102 int i;
2103 struct ib_cc_congestion_setting_attr *p =
2104 (struct ib_cc_congestion_setting_attr *)ccp->mgmt_data;
2105 struct qib_ibport *ibp = to_iport(ibdev, port);
2106 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2107 struct ib_cc_congestion_entry_shadow *entries;
2108
2109 memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
2110
2111 spin_lock(&ppd->cc_shadow_lock);
2112
2113 entries = ppd->congestion_entries_shadow->entries;
2114 p->port_control = cpu_to_be16(
2115 ppd->congestion_entries_shadow->port_control);
2116 p->control_map = cpu_to_be16(
2117 ppd->congestion_entries_shadow->control_map);
2118 for (i = 0; i < IB_CC_CCS_ENTRIES; i++) {
2119 p->entries[i].ccti_increase = entries[i].ccti_increase;
2120 p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer);
2121 p->entries[i].trigger_threshold = entries[i].trigger_threshold;
2122 p->entries[i].ccti_min = entries[i].ccti_min;
2123 }
2124
2125 spin_unlock(&ppd->cc_shadow_lock);
2126
2127 return reply((struct ib_smp *) ccp);
2128}
2129
2130static int cc_get_congestion_control_table(struct ib_cc_mad *ccp,
2131 struct ib_device *ibdev, u8 port)
2132{
2133 struct ib_cc_table_attr *p =
2134 (struct ib_cc_table_attr *)ccp->mgmt_data;
2135 struct qib_ibport *ibp = to_iport(ibdev, port);
2136 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2137 u32 cct_block_index = be32_to_cpu(ccp->attr_mod);
2138 u32 max_cct_block;
2139 u32 cct_entry;
2140 struct ib_cc_table_entry_shadow *entries;
2141 int i;
2142
2143 /* Is the table index more than what is supported? */
2144 if (cct_block_index > IB_CC_TABLE_CAP_DEFAULT - 1)
2145 goto bail;
2146
2147 memset(ccp->mgmt_data, 0, sizeof(ccp->mgmt_data));
2148
2149 spin_lock(&ppd->cc_shadow_lock);
2150
2151 max_cct_block =
2152 (ppd->ccti_entries_shadow->ccti_last_entry + 1)/IB_CCT_ENTRIES;
2153 max_cct_block = max_cct_block ? max_cct_block - 1 : 0;
2154
2155 if (cct_block_index > max_cct_block) {
2156 spin_unlock(&ppd->cc_shadow_lock);
2157 goto bail;
2158 }
2159
2160 ccp->attr_mod = cpu_to_be32(cct_block_index);
2161
2162 cct_entry = IB_CCT_ENTRIES * (cct_block_index + 1);
2163
2164 cct_entry--;
2165
2166 p->ccti_limit = cpu_to_be16(cct_entry);
2167
2168 entries = &ppd->ccti_entries_shadow->
2169 entries[IB_CCT_ENTRIES * cct_block_index];
2170 cct_entry %= IB_CCT_ENTRIES;
2171
2172 for (i = 0; i <= cct_entry; i++)
2173 p->ccti_entries[i].entry = cpu_to_be16(entries[i].entry);
2174
2175 spin_unlock(&ppd->cc_shadow_lock);
2176
2177 return reply((struct ib_smp *) ccp);
2178
2179bail:
2180 return reply_failure((struct ib_smp *) ccp);
2181}
2182
2183static int cc_set_congestion_setting(struct ib_cc_mad *ccp,
2184 struct ib_device *ibdev, u8 port)
2185{
2186 struct ib_cc_congestion_setting_attr *p =
2187 (struct ib_cc_congestion_setting_attr *)ccp->mgmt_data;
2188 struct qib_ibport *ibp = to_iport(ibdev, port);
2189 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2190 int i;
2191
2192 ppd->cc_sl_control_map = be16_to_cpu(p->control_map);
2193
2194 for (i = 0; i < IB_CC_CCS_ENTRIES; i++) {
2195 ppd->congestion_entries[i].ccti_increase =
2196 p->entries[i].ccti_increase;
2197
2198 ppd->congestion_entries[i].ccti_timer =
2199 be16_to_cpu(p->entries[i].ccti_timer);
2200
2201 ppd->congestion_entries[i].trigger_threshold =
2202 p->entries[i].trigger_threshold;
2203
2204 ppd->congestion_entries[i].ccti_min =
2205 p->entries[i].ccti_min;
2206 }
2207
2208 return reply((struct ib_smp *) ccp);
2209}
2210
2211static int cc_set_congestion_control_table(struct ib_cc_mad *ccp,
2212 struct ib_device *ibdev, u8 port)
2213{
2214 struct ib_cc_table_attr *p =
2215 (struct ib_cc_table_attr *)ccp->mgmt_data;
2216 struct qib_ibport *ibp = to_iport(ibdev, port);
2217 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
2218 u32 cct_block_index = be32_to_cpu(ccp->attr_mod);
2219 u32 cct_entry;
2220 struct ib_cc_table_entry_shadow *entries;
2221 int i;
2222
2223 /* Is the table index more than what is supported? */
2224 if (cct_block_index > IB_CC_TABLE_CAP_DEFAULT - 1)
2225 goto bail;
2226
2227 /* If this packet is the first in the sequence then
2228 * zero the total table entry count.
2229 */
2230 if (be16_to_cpu(p->ccti_limit) < IB_CCT_ENTRIES)
2231 ppd->total_cct_entry = 0;
2232
2233 cct_entry = (be16_to_cpu(p->ccti_limit))%IB_CCT_ENTRIES;
2234
2235 /* ccti_limit is 0 to 63 */
2236 ppd->total_cct_entry += (cct_entry + 1);
2237
2238 if (ppd->total_cct_entry > ppd->cc_supported_table_entries)
2239 goto bail;
2240
2241 ppd->ccti_limit = be16_to_cpu(p->ccti_limit);
2242
2243 entries = ppd->ccti_entries + (IB_CCT_ENTRIES * cct_block_index);
2244
2245 for (i = 0; i <= cct_entry; i++)
2246 entries[i].entry = be16_to_cpu(p->ccti_entries[i].entry);
2247
2248 spin_lock(&ppd->cc_shadow_lock);
2249
2250 ppd->ccti_entries_shadow->ccti_last_entry = ppd->total_cct_entry - 1;
2251 memcpy(ppd->ccti_entries_shadow->entries, ppd->ccti_entries,
2252 (ppd->total_cct_entry * sizeof(struct ib_cc_table_entry)));
2253
2254 ppd->congestion_entries_shadow->port_control = IB_CC_CCS_PC_SL_BASED;
2255 ppd->congestion_entries_shadow->control_map = ppd->cc_sl_control_map;
2256 memcpy(ppd->congestion_entries_shadow->entries, ppd->congestion_entries,
2257 IB_CC_CCS_ENTRIES * sizeof(struct ib_cc_congestion_entry));
2258
2259 spin_unlock(&ppd->cc_shadow_lock);
2260
2261 return reply((struct ib_smp *) ccp);
2262
2263bail:
2264 return reply_failure((struct ib_smp *) ccp);
2265}
2266
2267static int check_cc_key(struct qib_ibport *ibp,
2268 struct ib_cc_mad *ccp, int mad_flags)
2269{
2270 return 0;
2271}
2272
2273static int process_cc(struct ib_device *ibdev, int mad_flags,
2274 u8 port, struct ib_mad *in_mad,
2275 struct ib_mad *out_mad)
2276{
2277 struct ib_cc_mad *ccp = (struct ib_cc_mad *)out_mad;
2278 struct qib_ibport *ibp = to_iport(ibdev, port);
2279 int ret;
2280
2281 *out_mad = *in_mad;
2282
2283 if (ccp->class_version != 2) {
2284 ccp->status |= IB_SMP_UNSUP_VERSION;
2285 ret = reply((struct ib_smp *)ccp);
2286 goto bail;
2287 }
2288
2289 ret = check_cc_key(ibp, ccp, mad_flags);
2290 if (ret)
2291 goto bail;
2292
2293 switch (ccp->method) {
2294 case IB_MGMT_METHOD_GET:
2295 switch (ccp->attr_id) {
2296 case IB_CC_ATTR_CLASSPORTINFO:
2297 ret = cc_get_classportinfo(ccp, ibdev);
2298 goto bail;
2299
2300 case IB_CC_ATTR_CONGESTION_INFO:
2301 ret = cc_get_congestion_info(ccp, ibdev, port);
2302 goto bail;
2303
2304 case IB_CC_ATTR_CA_CONGESTION_SETTING:
2305 ret = cc_get_congestion_setting(ccp, ibdev, port);
2306 goto bail;
2307
2308 case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
2309 ret = cc_get_congestion_control_table(ccp, ibdev, port);
2310 goto bail;
2311
2312 /* FALLTHROUGH */
2313 default:
2314 ccp->status |= IB_SMP_UNSUP_METH_ATTR;
2315 ret = reply((struct ib_smp *) ccp);
2316 goto bail;
2317 }
2318
2319 case IB_MGMT_METHOD_SET:
2320 switch (ccp->attr_id) {
2321 case IB_CC_ATTR_CA_CONGESTION_SETTING:
2322 ret = cc_set_congestion_setting(ccp, ibdev, port);
2323 goto bail;
2324
2325 case IB_CC_ATTR_CONGESTION_CONTROL_TABLE:
2326 ret = cc_set_congestion_control_table(ccp, ibdev, port);
2327 goto bail;
2328
2329 /* FALLTHROUGH */
2330 default:
2331 ccp->status |= IB_SMP_UNSUP_METH_ATTR;
2332 ret = reply((struct ib_smp *) ccp);
2333 goto bail;
2334 }
2335
2336 case IB_MGMT_METHOD_GET_RESP:
2337 /*
2338 * The ib_mad module will call us to process responses
2339 * before checking for other consumers.
2340 * Just tell the caller to process it normally.
2341 */
2342 ret = IB_MAD_RESULT_SUCCESS;
2343 goto bail;
2344
2345 case IB_MGMT_METHOD_TRAP:
2346 default:
2347 ccp->status |= IB_SMP_UNSUP_METHOD;
2348 ret = reply((struct ib_smp *) ccp);
2349 }
2350
2351bail:
2352 return ret;
2353}
2354
Ralph Campbellf9315512010-05-23 21:44:54 -07002355/**
2356 * qib_process_mad - process an incoming MAD packet
2357 * @ibdev: the infiniband device this packet came in on
2358 * @mad_flags: MAD flags
2359 * @port: the port number this packet came in on
2360 * @in_wc: the work completion entry for this packet
2361 * @in_grh: the global route header for this packet
2362 * @in_mad: the incoming MAD
2363 * @out_mad: any outgoing MAD reply
2364 *
2365 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
2366 * interested in processing.
2367 *
2368 * Note that the verbs framework has already done the MAD sanity checks,
2369 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
2370 * MADs.
2371 *
2372 * This is called by the ib_mad module.
2373 */
2374int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
2375 struct ib_wc *in_wc, struct ib_grh *in_grh,
2376 struct ib_mad *in_mad, struct ib_mad *out_mad)
2377{
2378 int ret;
Mike Marciniszyn36a8f012012-07-19 13:04:04 +00002379 struct qib_ibport *ibp = to_iport(ibdev, port);
2380 struct qib_pportdata *ppd = ppd_from_ibp(ibp);
Ralph Campbellf9315512010-05-23 21:44:54 -07002381
2382 switch (in_mad->mad_hdr.mgmt_class) {
2383 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
2384 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
2385 ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad);
2386 goto bail;
2387
2388 case IB_MGMT_CLASS_PERF_MGMT:
2389 ret = process_perf(ibdev, port, in_mad, out_mad);
2390 goto bail;
2391
Mike Marciniszyn36a8f012012-07-19 13:04:04 +00002392 case IB_MGMT_CLASS_CONG_MGMT:
2393 if (!ppd->congestion_entries_shadow ||
2394 !qib_cc_table_size) {
2395 ret = IB_MAD_RESULT_SUCCESS;
2396 goto bail;
2397 }
2398 ret = process_cc(ibdev, mad_flags, port, in_mad, out_mad);
2399 goto bail;
2400
Ralph Campbellf9315512010-05-23 21:44:54 -07002401 default:
2402 ret = IB_MAD_RESULT_SUCCESS;
2403 }
2404
2405bail:
2406 return ret;
2407}
2408
2409static void send_handler(struct ib_mad_agent *agent,
2410 struct ib_mad_send_wc *mad_send_wc)
2411{
2412 ib_free_send_mad(mad_send_wc->send_buf);
2413}
2414
2415static void xmit_wait_timer_func(unsigned long opaque)
2416{
2417 struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
2418 struct qib_devdata *dd = dd_from_ppd(ppd);
2419 unsigned long flags;
2420 u8 status;
2421
2422 spin_lock_irqsave(&ppd->ibport_data.lock, flags);
2423 if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_SAMPLE) {
2424 status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT);
2425 if (status == IB_PMA_SAMPLE_STATUS_DONE) {
2426 /* save counter cache */
2427 cache_hw_sample_counters(ppd);
2428 ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER;
2429 } else
2430 goto done;
2431 }
2432 ppd->cong_stats.counter = xmit_wait_get_value_delta(ppd);
2433 dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 0x0);
2434done:
2435 spin_unlock_irqrestore(&ppd->ibport_data.lock, flags);
2436 mod_timer(&ppd->cong_stats.timer, jiffies + HZ);
2437}
2438
2439int qib_create_agents(struct qib_ibdev *dev)
2440{
2441 struct qib_devdata *dd = dd_from_dev(dev);
2442 struct ib_mad_agent *agent;
2443 struct qib_ibport *ibp;
2444 int p;
2445 int ret;
2446
2447 for (p = 0; p < dd->num_pports; p++) {
2448 ibp = &dd->pport[p].ibport_data;
2449 agent = ib_register_mad_agent(&dev->ibdev, p + 1, IB_QPT_SMI,
2450 NULL, 0, send_handler,
2451 NULL, NULL);
2452 if (IS_ERR(agent)) {
2453 ret = PTR_ERR(agent);
2454 goto err;
2455 }
2456
2457 /* Initialize xmit_wait structure */
2458 dd->pport[p].cong_stats.counter = 0;
2459 init_timer(&dd->pport[p].cong_stats.timer);
2460 dd->pport[p].cong_stats.timer.function = xmit_wait_timer_func;
2461 dd->pport[p].cong_stats.timer.data =
2462 (unsigned long)(&dd->pport[p]);
2463 dd->pport[p].cong_stats.timer.expires = 0;
2464 add_timer(&dd->pport[p].cong_stats.timer);
2465
2466 ibp->send_agent = agent;
2467 }
2468
2469 return 0;
2470
2471err:
2472 for (p = 0; p < dd->num_pports; p++) {
2473 ibp = &dd->pport[p].ibport_data;
2474 if (ibp->send_agent) {
2475 agent = ibp->send_agent;
2476 ibp->send_agent = NULL;
2477 ib_unregister_mad_agent(agent);
2478 }
2479 }
2480
2481 return ret;
2482}
2483
2484void qib_free_agents(struct qib_ibdev *dev)
2485{
2486 struct qib_devdata *dd = dd_from_dev(dev);
2487 struct ib_mad_agent *agent;
2488 struct qib_ibport *ibp;
2489 int p;
2490
2491 for (p = 0; p < dd->num_pports; p++) {
2492 ibp = &dd->pport[p].ibport_data;
2493 if (ibp->send_agent) {
2494 agent = ibp->send_agent;
2495 ibp->send_agent = NULL;
2496 ib_unregister_mad_agent(agent);
2497 }
2498 if (ibp->sm_ah) {
2499 ib_destroy_ah(&ibp->sm_ah->ibah);
2500 ibp->sm_ah = NULL;
2501 }
2502 if (dd->pport[p].cong_stats.timer.data)
2503 del_timer_sync(&dd->pport[p].cong_stats.timer);
2504 }
2505}