Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation. |
| 3 | * All rights reserved. |
| 4 | * 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 | |
| 40 | static 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 | |
| 52 | static void qib_send_trap(struct qib_ibport *ibp, void *data, unsigned len) |
| 53 | { |
| 54 | struct ib_mad_send_buf *send_buf; |
| 55 | struct ib_mad_agent *agent; |
| 56 | struct ib_smp *smp; |
| 57 | int ret; |
| 58 | unsigned long flags; |
| 59 | unsigned long timeout; |
| 60 | |
| 61 | agent = ibp->send_agent; |
| 62 | if (!agent) |
| 63 | return; |
| 64 | |
| 65 | /* o14-3.2.1 */ |
| 66 | if (!(ppd_from_ibp(ibp)->lflags & QIBL_LINKACTIVE)) |
| 67 | return; |
| 68 | |
| 69 | /* o14-2 */ |
| 70 | if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout)) |
| 71 | return; |
| 72 | |
| 73 | send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR, |
| 74 | IB_MGMT_MAD_DATA, GFP_ATOMIC); |
| 75 | if (IS_ERR(send_buf)) |
| 76 | return; |
| 77 | |
| 78 | smp = send_buf->mad; |
| 79 | smp->base_version = IB_MGMT_BASE_VERSION; |
| 80 | smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; |
| 81 | smp->class_version = 1; |
| 82 | smp->method = IB_MGMT_METHOD_TRAP; |
| 83 | ibp->tid++; |
| 84 | smp->tid = cpu_to_be64(ibp->tid); |
| 85 | smp->attr_id = IB_SMP_ATTR_NOTICE; |
| 86 | /* o14-1: smp->mkey = 0; */ |
| 87 | memcpy(smp->data, data, len); |
| 88 | |
| 89 | spin_lock_irqsave(&ibp->lock, flags); |
| 90 | if (!ibp->sm_ah) { |
| 91 | if (ibp->sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) { |
| 92 | struct ib_ah *ah; |
| 93 | struct ib_ah_attr attr; |
| 94 | |
| 95 | memset(&attr, 0, sizeof attr); |
| 96 | attr.dlid = ibp->sm_lid; |
| 97 | attr.port_num = ppd_from_ibp(ibp)->port; |
| 98 | ah = ib_create_ah(ibp->qp0->ibqp.pd, &attr); |
| 99 | if (IS_ERR(ah)) |
| 100 | ret = -EINVAL; |
| 101 | else { |
| 102 | send_buf->ah = ah; |
| 103 | ibp->sm_ah = to_iah(ah); |
| 104 | ret = 0; |
| 105 | } |
| 106 | } else |
| 107 | ret = -EINVAL; |
| 108 | } else { |
| 109 | send_buf->ah = &ibp->sm_ah->ibah; |
| 110 | ret = 0; |
| 111 | } |
| 112 | spin_unlock_irqrestore(&ibp->lock, flags); |
| 113 | |
| 114 | if (!ret) |
| 115 | ret = ib_post_send_mad(send_buf, NULL); |
| 116 | if (!ret) { |
| 117 | /* 4.096 usec. */ |
| 118 | timeout = (4096 * (1UL << ibp->subnet_timeout)) / 1000; |
| 119 | ibp->trap_timeout = jiffies + usecs_to_jiffies(timeout); |
| 120 | } else { |
| 121 | ib_free_send_mad(send_buf); |
| 122 | ibp->trap_timeout = 0; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Send a bad [PQ]_Key trap (ch. 14.3.8). |
| 128 | */ |
| 129 | void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl, |
| 130 | u32 qp1, u32 qp2, __be16 lid1, __be16 lid2) |
| 131 | { |
| 132 | struct ib_mad_notice_attr data; |
| 133 | |
| 134 | if (trap_num == IB_NOTICE_TRAP_BAD_PKEY) |
| 135 | ibp->pkey_violations++; |
| 136 | else |
| 137 | ibp->qkey_violations++; |
| 138 | ibp->n_pkt_drops++; |
| 139 | |
| 140 | /* Send violation trap */ |
| 141 | data.generic_type = IB_NOTICE_TYPE_SECURITY; |
| 142 | data.prod_type_msb = 0; |
| 143 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
| 144 | data.trap_num = trap_num; |
| 145 | data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); |
| 146 | data.toggle_count = 0; |
| 147 | memset(&data.details, 0, sizeof data.details); |
| 148 | data.details.ntc_257_258.lid1 = lid1; |
| 149 | data.details.ntc_257_258.lid2 = lid2; |
| 150 | data.details.ntc_257_258.key = cpu_to_be32(key); |
| 151 | data.details.ntc_257_258.sl_qp1 = cpu_to_be32((sl << 28) | qp1); |
| 152 | data.details.ntc_257_258.qp2 = cpu_to_be32(qp2); |
| 153 | |
| 154 | qib_send_trap(ibp, &data, sizeof data); |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Send a bad M_Key trap (ch. 14.3.9). |
| 159 | */ |
| 160 | static void qib_bad_mkey(struct qib_ibport *ibp, struct ib_smp *smp) |
| 161 | { |
| 162 | struct ib_mad_notice_attr data; |
| 163 | |
| 164 | /* Send violation trap */ |
| 165 | data.generic_type = IB_NOTICE_TYPE_SECURITY; |
| 166 | data.prod_type_msb = 0; |
| 167 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
| 168 | data.trap_num = IB_NOTICE_TRAP_BAD_MKEY; |
| 169 | data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); |
| 170 | data.toggle_count = 0; |
| 171 | memset(&data.details, 0, sizeof data.details); |
| 172 | data.details.ntc_256.lid = data.issuer_lid; |
| 173 | data.details.ntc_256.method = smp->method; |
| 174 | data.details.ntc_256.attr_id = smp->attr_id; |
| 175 | data.details.ntc_256.attr_mod = smp->attr_mod; |
| 176 | data.details.ntc_256.mkey = smp->mkey; |
| 177 | if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { |
| 178 | u8 hop_cnt; |
| 179 | |
| 180 | data.details.ntc_256.dr_slid = smp->dr_slid; |
| 181 | data.details.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE; |
| 182 | hop_cnt = smp->hop_cnt; |
| 183 | if (hop_cnt > ARRAY_SIZE(data.details.ntc_256.dr_rtn_path)) { |
| 184 | data.details.ntc_256.dr_trunc_hop |= |
| 185 | IB_NOTICE_TRAP_DR_TRUNC; |
| 186 | hop_cnt = ARRAY_SIZE(data.details.ntc_256.dr_rtn_path); |
| 187 | } |
| 188 | data.details.ntc_256.dr_trunc_hop |= hop_cnt; |
| 189 | memcpy(data.details.ntc_256.dr_rtn_path, smp->return_path, |
| 190 | hop_cnt); |
| 191 | } |
| 192 | |
| 193 | qib_send_trap(ibp, &data, sizeof data); |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Send a Port Capability Mask Changed trap (ch. 14.3.11). |
| 198 | */ |
| 199 | void qib_cap_mask_chg(struct qib_ibport *ibp) |
| 200 | { |
| 201 | struct ib_mad_notice_attr data; |
| 202 | |
| 203 | data.generic_type = IB_NOTICE_TYPE_INFO; |
| 204 | data.prod_type_msb = 0; |
| 205 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
| 206 | data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG; |
| 207 | data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); |
| 208 | data.toggle_count = 0; |
| 209 | memset(&data.details, 0, sizeof data.details); |
| 210 | data.details.ntc_144.lid = data.issuer_lid; |
| 211 | data.details.ntc_144.new_cap_mask = cpu_to_be32(ibp->port_cap_flags); |
| 212 | |
| 213 | qib_send_trap(ibp, &data, sizeof data); |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Send a System Image GUID Changed trap (ch. 14.3.12). |
| 218 | */ |
| 219 | void qib_sys_guid_chg(struct qib_ibport *ibp) |
| 220 | { |
| 221 | struct ib_mad_notice_attr data; |
| 222 | |
| 223 | data.generic_type = IB_NOTICE_TYPE_INFO; |
| 224 | data.prod_type_msb = 0; |
| 225 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
| 226 | data.trap_num = IB_NOTICE_TRAP_SYS_GUID_CHG; |
| 227 | data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); |
| 228 | data.toggle_count = 0; |
| 229 | memset(&data.details, 0, sizeof data.details); |
| 230 | data.details.ntc_145.lid = data.issuer_lid; |
| 231 | data.details.ntc_145.new_sys_guid = ib_qib_sys_image_guid; |
| 232 | |
| 233 | qib_send_trap(ibp, &data, sizeof data); |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Send a Node Description Changed trap (ch. 14.3.13). |
| 238 | */ |
| 239 | void qib_node_desc_chg(struct qib_ibport *ibp) |
| 240 | { |
| 241 | struct ib_mad_notice_attr data; |
| 242 | |
| 243 | data.generic_type = IB_NOTICE_TYPE_INFO; |
| 244 | data.prod_type_msb = 0; |
| 245 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
| 246 | data.trap_num = IB_NOTICE_TRAP_CAP_MASK_CHG; |
| 247 | data.issuer_lid = cpu_to_be16(ppd_from_ibp(ibp)->lid); |
| 248 | data.toggle_count = 0; |
| 249 | memset(&data.details, 0, sizeof data.details); |
| 250 | data.details.ntc_144.lid = data.issuer_lid; |
| 251 | data.details.ntc_144.local_changes = 1; |
| 252 | data.details.ntc_144.change_flags = IB_NOTICE_TRAP_NODE_DESC_CHG; |
| 253 | |
| 254 | qib_send_trap(ibp, &data, sizeof data); |
| 255 | } |
| 256 | |
| 257 | static int subn_get_nodedescription(struct ib_smp *smp, |
| 258 | struct ib_device *ibdev) |
| 259 | { |
| 260 | if (smp->attr_mod) |
| 261 | smp->status |= IB_SMP_INVALID_FIELD; |
| 262 | |
| 263 | memcpy(smp->data, ibdev->node_desc, sizeof(smp->data)); |
| 264 | |
| 265 | return reply(smp); |
| 266 | } |
| 267 | |
| 268 | static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev, |
| 269 | u8 port) |
| 270 | { |
| 271 | struct ib_node_info *nip = (struct ib_node_info *)&smp->data; |
| 272 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 273 | u32 vendor, majrev, minrev; |
| 274 | unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */ |
| 275 | |
| 276 | /* GUID 0 is illegal */ |
| 277 | if (smp->attr_mod || pidx >= dd->num_pports || |
| 278 | dd->pport[pidx].guid == 0) |
| 279 | smp->status |= IB_SMP_INVALID_FIELD; |
| 280 | else |
| 281 | nip->port_guid = dd->pport[pidx].guid; |
| 282 | |
| 283 | nip->base_version = 1; |
| 284 | nip->class_version = 1; |
| 285 | nip->node_type = 1; /* channel adapter */ |
| 286 | nip->num_ports = ibdev->phys_port_cnt; |
| 287 | /* This is already in network order */ |
| 288 | nip->sys_guid = ib_qib_sys_image_guid; |
| 289 | nip->node_guid = dd->pport->guid; /* Use first-port GUID as node */ |
| 290 | nip->partition_cap = cpu_to_be16(qib_get_npkeys(dd)); |
| 291 | nip->device_id = cpu_to_be16(dd->deviceid); |
| 292 | majrev = dd->majrev; |
| 293 | minrev = dd->minrev; |
| 294 | nip->revision = cpu_to_be32((majrev << 16) | minrev); |
| 295 | nip->local_port_num = port; |
| 296 | vendor = dd->vendorid; |
| 297 | nip->vendor_id[0] = QIB_SRC_OUI_1; |
| 298 | nip->vendor_id[1] = QIB_SRC_OUI_2; |
| 299 | nip->vendor_id[2] = QIB_SRC_OUI_3; |
| 300 | |
| 301 | return reply(smp); |
| 302 | } |
| 303 | |
| 304 | static int subn_get_guidinfo(struct ib_smp *smp, struct ib_device *ibdev, |
| 305 | u8 port) |
| 306 | { |
| 307 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 308 | u32 startgx = 8 * be32_to_cpu(smp->attr_mod); |
| 309 | __be64 *p = (__be64 *) smp->data; |
| 310 | unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */ |
| 311 | |
| 312 | /* 32 blocks of 8 64-bit GUIDs per block */ |
| 313 | |
| 314 | memset(smp->data, 0, sizeof(smp->data)); |
| 315 | |
| 316 | if (startgx == 0 && pidx < dd->num_pports) { |
| 317 | struct qib_pportdata *ppd = dd->pport + pidx; |
| 318 | struct qib_ibport *ibp = &ppd->ibport_data; |
| 319 | __be64 g = ppd->guid; |
| 320 | unsigned i; |
| 321 | |
| 322 | /* GUID 0 is illegal */ |
| 323 | if (g == 0) |
| 324 | smp->status |= IB_SMP_INVALID_FIELD; |
| 325 | else { |
| 326 | /* The first is a copy of the read-only HW GUID. */ |
| 327 | p[0] = g; |
| 328 | for (i = 1; i < QIB_GUIDS_PER_PORT; i++) |
| 329 | p[i] = ibp->guids[i - 1]; |
| 330 | } |
| 331 | } else |
| 332 | smp->status |= IB_SMP_INVALID_FIELD; |
| 333 | |
| 334 | return reply(smp); |
| 335 | } |
| 336 | |
| 337 | static void set_link_width_enabled(struct qib_pportdata *ppd, u32 w) |
| 338 | { |
| 339 | (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LWID_ENB, w); |
| 340 | } |
| 341 | |
| 342 | static void set_link_speed_enabled(struct qib_pportdata *ppd, u32 s) |
| 343 | { |
| 344 | (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_SPD_ENB, s); |
| 345 | } |
| 346 | |
| 347 | static int get_overrunthreshold(struct qib_pportdata *ppd) |
| 348 | { |
| 349 | return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * set_overrunthreshold - set the overrun threshold |
| 354 | * @ppd: the physical port data |
| 355 | * @n: the new threshold |
| 356 | * |
| 357 | * Note that this will only take effect when the link state changes. |
| 358 | */ |
| 359 | static int set_overrunthreshold(struct qib_pportdata *ppd, unsigned n) |
| 360 | { |
| 361 | (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OVERRUN_THRESH, |
| 362 | (u32)n); |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int get_phyerrthreshold(struct qib_pportdata *ppd) |
| 367 | { |
| 368 | return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH); |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * set_phyerrthreshold - set the physical error threshold |
| 373 | * @ppd: the physical port data |
| 374 | * @n: the new threshold |
| 375 | * |
| 376 | * Note that this will only take effect when the link state changes. |
| 377 | */ |
| 378 | static int set_phyerrthreshold(struct qib_pportdata *ppd, unsigned n) |
| 379 | { |
| 380 | (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PHYERR_THRESH, |
| 381 | (u32)n); |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * get_linkdowndefaultstate - get the default linkdown state |
| 387 | * @ppd: the physical port data |
| 388 | * |
| 389 | * Returns zero if the default is POLL, 1 if the default is SLEEP. |
| 390 | */ |
| 391 | static int get_linkdowndefaultstate(struct qib_pportdata *ppd) |
| 392 | { |
| 393 | return ppd->dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT) == |
| 394 | IB_LINKINITCMD_SLEEP; |
| 395 | } |
| 396 | |
| 397 | static int check_mkey(struct qib_ibport *ibp, struct ib_smp *smp, int mad_flags) |
| 398 | { |
Jim Foraker | 6199c89 | 2012-05-02 14:39:11 -0400 | [diff] [blame^] | 399 | int valid_mkey = 0; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 400 | int ret = 0; |
| 401 | |
| 402 | /* Is the mkey in the process of expiring? */ |
| 403 | if (ibp->mkey_lease_timeout && |
| 404 | time_after_eq(jiffies, ibp->mkey_lease_timeout)) { |
| 405 | /* Clear timeout and mkey protection field. */ |
| 406 | ibp->mkey_lease_timeout = 0; |
| 407 | ibp->mkeyprot = 0; |
| 408 | } |
| 409 | |
Jim Foraker | 6199c89 | 2012-05-02 14:39:11 -0400 | [diff] [blame^] | 410 | if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->mkey == 0 || |
| 411 | ibp->mkey == smp->mkey) |
| 412 | valid_mkey = 1; |
| 413 | |
| 414 | /* Unset lease timeout on any valid Get/Set/TrapRepress */ |
| 415 | if (valid_mkey && ibp->mkey_lease_timeout && |
| 416 | (smp->method == IB_MGMT_METHOD_GET || |
| 417 | smp->method == IB_MGMT_METHOD_SET || |
| 418 | smp->method == IB_MGMT_METHOD_TRAP_REPRESS)) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 419 | ibp->mkey_lease_timeout = 0; |
| 420 | |
Jim Foraker | 6199c89 | 2012-05-02 14:39:11 -0400 | [diff] [blame^] | 421 | if (!valid_mkey) { |
| 422 | switch (smp->method) { |
| 423 | case IB_MGMT_METHOD_GET: |
| 424 | /* Bad mkey not a violation below level 2 */ |
| 425 | if (ibp->mkeyprot < 2) |
| 426 | break; |
| 427 | case IB_MGMT_METHOD_SET: |
| 428 | case IB_MGMT_METHOD_TRAP_REPRESS: |
| 429 | if (ibp->mkey_violations != 0xFFFF) |
| 430 | ++ibp->mkey_violations; |
| 431 | if (!ibp->mkey_lease_timeout && ibp->mkey_lease_period) |
| 432 | ibp->mkey_lease_timeout = jiffies + |
| 433 | ibp->mkey_lease_period * HZ; |
| 434 | /* Generate a trap notice. */ |
| 435 | qib_bad_mkey(ibp, smp); |
| 436 | ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
| 437 | } |
| 438 | } |
| 439 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | static int subn_get_portinfo(struct ib_smp *smp, struct ib_device *ibdev, |
| 444 | u8 port) |
| 445 | { |
| 446 | struct qib_devdata *dd; |
| 447 | struct qib_pportdata *ppd; |
| 448 | struct qib_ibport *ibp; |
| 449 | struct ib_port_info *pip = (struct ib_port_info *)smp->data; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 450 | u8 mtu; |
| 451 | int ret; |
| 452 | u32 state; |
| 453 | u32 port_num = be32_to_cpu(smp->attr_mod); |
| 454 | |
| 455 | if (port_num == 0) |
| 456 | port_num = port; |
| 457 | else { |
| 458 | if (port_num > ibdev->phys_port_cnt) { |
| 459 | smp->status |= IB_SMP_INVALID_FIELD; |
| 460 | ret = reply(smp); |
| 461 | goto bail; |
| 462 | } |
| 463 | if (port_num != port) { |
| 464 | ibp = to_iport(ibdev, port_num); |
| 465 | ret = check_mkey(ibp, smp, 0); |
| 466 | if (ret) |
| 467 | goto bail; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | dd = dd_from_ibdev(ibdev); |
| 472 | /* IB numbers ports from 1, hdw from 0 */ |
| 473 | ppd = dd->pport + (port_num - 1); |
| 474 | ibp = &ppd->ibport_data; |
| 475 | |
| 476 | /* Clear all fields. Only set the non-zero fields. */ |
| 477 | memset(smp->data, 0, sizeof(smp->data)); |
| 478 | |
| 479 | /* Only return the mkey if the protection field allows it. */ |
Mitko Haralanov | 36b87b4 | 2011-03-04 18:53:17 +0000 | [diff] [blame] | 480 | if (!(smp->method == IB_MGMT_METHOD_GET && |
| 481 | ibp->mkey != smp->mkey && |
| 482 | ibp->mkeyprot == 1)) |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 483 | pip->mkey = ibp->mkey; |
| 484 | pip->gid_prefix = ibp->gid_prefix; |
Mike Marciniszyn | 520b3ee | 2012-02-25 17:45:50 -0800 | [diff] [blame] | 485 | pip->lid = cpu_to_be16(ppd->lid); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 486 | pip->sm_lid = cpu_to_be16(ibp->sm_lid); |
| 487 | pip->cap_mask = cpu_to_be32(ibp->port_cap_flags); |
| 488 | /* pip->diag_code; */ |
| 489 | pip->mkey_lease_period = cpu_to_be16(ibp->mkey_lease_period); |
| 490 | pip->local_port_num = port; |
| 491 | pip->link_width_enabled = ppd->link_width_enabled; |
| 492 | pip->link_width_supported = ppd->link_width_supported; |
| 493 | pip->link_width_active = ppd->link_width_active; |
| 494 | state = dd->f_iblink_state(ppd->lastibcstat); |
| 495 | pip->linkspeed_portstate = ppd->link_speed_supported << 4 | state; |
| 496 | |
| 497 | pip->portphysstate_linkdown = |
| 498 | (dd->f_ibphys_portstate(ppd->lastibcstat) << 4) | |
| 499 | (get_linkdowndefaultstate(ppd) ? 1 : 2); |
| 500 | pip->mkeyprot_resv_lmc = (ibp->mkeyprot << 6) | ppd->lmc; |
| 501 | pip->linkspeedactive_enabled = (ppd->link_speed_active << 4) | |
| 502 | ppd->link_speed_enabled; |
| 503 | switch (ppd->ibmtu) { |
| 504 | default: /* something is wrong; fall through */ |
| 505 | case 4096: |
| 506 | mtu = IB_MTU_4096; |
| 507 | break; |
| 508 | case 2048: |
| 509 | mtu = IB_MTU_2048; |
| 510 | break; |
| 511 | case 1024: |
| 512 | mtu = IB_MTU_1024; |
| 513 | break; |
| 514 | case 512: |
| 515 | mtu = IB_MTU_512; |
| 516 | break; |
| 517 | case 256: |
| 518 | mtu = IB_MTU_256; |
| 519 | break; |
| 520 | } |
| 521 | pip->neighbormtu_mastersmsl = (mtu << 4) | ibp->sm_sl; |
| 522 | pip->vlcap_inittype = ppd->vls_supported << 4; /* InitType = 0 */ |
| 523 | pip->vl_high_limit = ibp->vl_high_limit; |
| 524 | pip->vl_arb_high_cap = |
| 525 | dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_CAP); |
| 526 | pip->vl_arb_low_cap = |
| 527 | dd->f_get_ib_cfg(ppd, QIB_IB_CFG_VL_LOW_CAP); |
| 528 | /* InitTypeReply = 0 */ |
| 529 | pip->inittypereply_mtucap = qib_ibmtu ? qib_ibmtu : IB_MTU_4096; |
| 530 | /* HCAs ignore VLStallCount and HOQLife */ |
| 531 | /* pip->vlstallcnt_hoqlife; */ |
| 532 | pip->operationalvl_pei_peo_fpi_fpo = |
| 533 | dd->f_get_ib_cfg(ppd, QIB_IB_CFG_OP_VLS) << 4; |
| 534 | pip->mkey_violations = cpu_to_be16(ibp->mkey_violations); |
| 535 | /* P_KeyViolations are counted by hardware. */ |
| 536 | pip->pkey_violations = cpu_to_be16(ibp->pkey_violations); |
| 537 | pip->qkey_violations = cpu_to_be16(ibp->qkey_violations); |
| 538 | /* Only the hardware GUID is supported for now */ |
| 539 | pip->guid_cap = QIB_GUIDS_PER_PORT; |
| 540 | pip->clientrereg_resv_subnetto = ibp->subnet_timeout; |
| 541 | /* 32.768 usec. response time (guessing) */ |
| 542 | pip->resv_resptimevalue = 3; |
| 543 | pip->localphyerrors_overrunerrors = |
| 544 | (get_phyerrthreshold(ppd) << 4) | |
| 545 | get_overrunthreshold(ppd); |
| 546 | /* pip->max_credit_hint; */ |
| 547 | if (ibp->port_cap_flags & IB_PORT_LINK_LATENCY_SUP) { |
| 548 | u32 v; |
| 549 | |
| 550 | v = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_LINKLATENCY); |
| 551 | pip->link_roundtrip_latency[0] = v >> 16; |
| 552 | pip->link_roundtrip_latency[1] = v >> 8; |
| 553 | pip->link_roundtrip_latency[2] = v; |
| 554 | } |
| 555 | |
| 556 | ret = reply(smp); |
| 557 | |
| 558 | bail: |
| 559 | return ret; |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * get_pkeys - return the PKEY table |
| 564 | * @dd: the qlogic_ib device |
| 565 | * @port: the IB port number |
| 566 | * @pkeys: the pkey table is placed here |
| 567 | */ |
| 568 | static int get_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys) |
| 569 | { |
| 570 | struct qib_pportdata *ppd = dd->pport + port - 1; |
| 571 | /* |
| 572 | * always a kernel context, no locking needed. |
| 573 | * If we get here with ppd setup, no need to check |
| 574 | * that pd is valid. |
| 575 | */ |
| 576 | struct qib_ctxtdata *rcd = dd->rcd[ppd->hw_pidx]; |
| 577 | |
| 578 | memcpy(pkeys, rcd->pkeys, sizeof(rcd->pkeys)); |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | static int subn_get_pkeytable(struct ib_smp *smp, struct ib_device *ibdev, |
| 584 | u8 port) |
| 585 | { |
| 586 | u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff); |
| 587 | u16 *p = (u16 *) smp->data; |
| 588 | __be16 *q = (__be16 *) smp->data; |
| 589 | |
| 590 | /* 64 blocks of 32 16-bit P_Key entries */ |
| 591 | |
| 592 | memset(smp->data, 0, sizeof(smp->data)); |
| 593 | if (startpx == 0) { |
| 594 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 595 | unsigned i, n = qib_get_npkeys(dd); |
| 596 | |
| 597 | get_pkeys(dd, port, p); |
| 598 | |
| 599 | for (i = 0; i < n; i++) |
| 600 | q[i] = cpu_to_be16(p[i]); |
| 601 | } else |
| 602 | smp->status |= IB_SMP_INVALID_FIELD; |
| 603 | |
| 604 | return reply(smp); |
| 605 | } |
| 606 | |
| 607 | static int subn_set_guidinfo(struct ib_smp *smp, struct ib_device *ibdev, |
| 608 | u8 port) |
| 609 | { |
| 610 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 611 | u32 startgx = 8 * be32_to_cpu(smp->attr_mod); |
| 612 | __be64 *p = (__be64 *) smp->data; |
| 613 | unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */ |
| 614 | |
| 615 | /* 32 blocks of 8 64-bit GUIDs per block */ |
| 616 | |
| 617 | if (startgx == 0 && pidx < dd->num_pports) { |
| 618 | struct qib_pportdata *ppd = dd->pport + pidx; |
| 619 | struct qib_ibport *ibp = &ppd->ibport_data; |
| 620 | unsigned i; |
| 621 | |
| 622 | /* The first entry is read-only. */ |
| 623 | for (i = 1; i < QIB_GUIDS_PER_PORT; i++) |
| 624 | ibp->guids[i - 1] = p[i]; |
| 625 | } else |
| 626 | smp->status |= IB_SMP_INVALID_FIELD; |
| 627 | |
| 628 | /* The only GUID we support is the first read-only entry. */ |
| 629 | return subn_get_guidinfo(smp, ibdev, port); |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * subn_set_portinfo - set port information |
| 634 | * @smp: the incoming SM packet |
| 635 | * @ibdev: the infiniband device |
| 636 | * @port: the port on the device |
| 637 | * |
| 638 | * Set Portinfo (see ch. 14.2.5.6). |
| 639 | */ |
| 640 | static int subn_set_portinfo(struct ib_smp *smp, struct ib_device *ibdev, |
| 641 | u8 port) |
| 642 | { |
| 643 | struct ib_port_info *pip = (struct ib_port_info *)smp->data; |
| 644 | struct ib_event event; |
| 645 | struct qib_devdata *dd; |
| 646 | struct qib_pportdata *ppd; |
| 647 | struct qib_ibport *ibp; |
Todd Rimmer | 4ccf28a | 2012-05-02 14:35:18 -0400 | [diff] [blame] | 648 | u8 clientrereg = (pip->clientrereg_resv_subnetto & 0x80); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 649 | unsigned long flags; |
| 650 | u16 lid, smlid; |
| 651 | u8 lwe; |
| 652 | u8 lse; |
| 653 | u8 state; |
| 654 | u8 vls; |
| 655 | u8 msl; |
| 656 | u16 lstate; |
| 657 | int ret, ore, mtu; |
| 658 | u32 port_num = be32_to_cpu(smp->attr_mod); |
| 659 | |
| 660 | if (port_num == 0) |
| 661 | port_num = port; |
| 662 | else { |
| 663 | if (port_num > ibdev->phys_port_cnt) |
| 664 | goto err; |
| 665 | /* Port attributes can only be set on the receiving port */ |
| 666 | if (port_num != port) |
| 667 | goto get_only; |
| 668 | } |
| 669 | |
| 670 | dd = dd_from_ibdev(ibdev); |
| 671 | /* IB numbers ports from 1, hdw from 0 */ |
| 672 | ppd = dd->pport + (port_num - 1); |
| 673 | ibp = &ppd->ibport_data; |
| 674 | event.device = ibdev; |
| 675 | event.element.port_num = port; |
| 676 | |
| 677 | ibp->mkey = pip->mkey; |
| 678 | ibp->gid_prefix = pip->gid_prefix; |
| 679 | ibp->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period); |
| 680 | |
| 681 | lid = be16_to_cpu(pip->lid); |
| 682 | /* Must be a valid unicast LID address. */ |
| 683 | if (lid == 0 || lid >= QIB_MULTICAST_LID_BASE) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 684 | smp->status |= IB_SMP_INVALID_FIELD; |
| 685 | else if (ppd->lid != lid || ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 686 | if (ppd->lid != lid) |
| 687 | qib_set_uevent_bits(ppd, _QIB_EVENT_LID_CHANGE_BIT); |
| 688 | if (ppd->lmc != (pip->mkeyprot_resv_lmc & 7)) |
| 689 | qib_set_uevent_bits(ppd, _QIB_EVENT_LMC_CHANGE_BIT); |
| 690 | qib_set_lid(ppd, lid, pip->mkeyprot_resv_lmc & 7); |
| 691 | event.event = IB_EVENT_LID_CHANGE; |
| 692 | ib_dispatch_event(&event); |
| 693 | } |
| 694 | |
| 695 | smlid = be16_to_cpu(pip->sm_lid); |
| 696 | msl = pip->neighbormtu_mastersmsl & 0xF; |
| 697 | /* Must be a valid unicast LID address. */ |
| 698 | if (smlid == 0 || smlid >= QIB_MULTICAST_LID_BASE) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 699 | smp->status |= IB_SMP_INVALID_FIELD; |
| 700 | else if (smlid != ibp->sm_lid || msl != ibp->sm_sl) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 701 | spin_lock_irqsave(&ibp->lock, flags); |
| 702 | if (ibp->sm_ah) { |
| 703 | if (smlid != ibp->sm_lid) |
| 704 | ibp->sm_ah->attr.dlid = smlid; |
| 705 | if (msl != ibp->sm_sl) |
| 706 | ibp->sm_ah->attr.sl = msl; |
| 707 | } |
| 708 | spin_unlock_irqrestore(&ibp->lock, flags); |
| 709 | if (smlid != ibp->sm_lid) |
| 710 | ibp->sm_lid = smlid; |
| 711 | if (msl != ibp->sm_sl) |
| 712 | ibp->sm_sl = msl; |
| 713 | event.event = IB_EVENT_SM_CHANGE; |
| 714 | ib_dispatch_event(&event); |
| 715 | } |
| 716 | |
| 717 | /* Allow 1x or 4x to be set (see 14.2.6.6). */ |
| 718 | lwe = pip->link_width_enabled; |
| 719 | if (lwe) { |
| 720 | if (lwe == 0xFF) |
Mitko Haralanov | cc7fb05 | 2011-02-22 16:56:37 -0800 | [diff] [blame] | 721 | set_link_width_enabled(ppd, ppd->link_width_supported); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 722 | else if (lwe >= 16 || (lwe & ~ppd->link_width_supported)) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 723 | smp->status |= IB_SMP_INVALID_FIELD; |
| 724 | else if (lwe != ppd->link_width_enabled) |
| 725 | set_link_width_enabled(ppd, lwe); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | lse = pip->linkspeedactive_enabled & 0xF; |
| 729 | if (lse) { |
| 730 | /* |
| 731 | * The IB 1.2 spec. only allows link speed values |
| 732 | * 1, 3, 5, 7, 15. 1.2.1 extended to allow specific |
| 733 | * speeds. |
| 734 | */ |
| 735 | if (lse == 15) |
Mitko Haralanov | cc7fb05 | 2011-02-22 16:56:37 -0800 | [diff] [blame] | 736 | set_link_speed_enabled(ppd, |
| 737 | ppd->link_speed_supported); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 738 | else if (lse >= 8 || (lse & ~ppd->link_speed_supported)) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 739 | smp->status |= IB_SMP_INVALID_FIELD; |
| 740 | else if (lse != ppd->link_speed_enabled) |
| 741 | set_link_speed_enabled(ppd, lse); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /* Set link down default state. */ |
| 745 | switch (pip->portphysstate_linkdown & 0xF) { |
| 746 | case 0: /* NOP */ |
| 747 | break; |
| 748 | case 1: /* SLEEP */ |
| 749 | (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT, |
| 750 | IB_LINKINITCMD_SLEEP); |
| 751 | break; |
| 752 | case 2: /* POLL */ |
| 753 | (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_LINKDEFAULT, |
| 754 | IB_LINKINITCMD_POLL); |
| 755 | break; |
| 756 | default: |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 757 | smp->status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | ibp->mkeyprot = pip->mkeyprot_resv_lmc >> 6; |
| 761 | ibp->vl_high_limit = pip->vl_high_limit; |
| 762 | (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_VL_HIGH_LIMIT, |
| 763 | ibp->vl_high_limit); |
| 764 | |
| 765 | mtu = ib_mtu_enum_to_int((pip->neighbormtu_mastersmsl >> 4) & 0xF); |
| 766 | if (mtu == -1) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 767 | smp->status |= IB_SMP_INVALID_FIELD; |
| 768 | else |
| 769 | qib_set_mtu(ppd, mtu); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 770 | |
| 771 | /* Set operational VLs */ |
| 772 | vls = (pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF; |
| 773 | if (vls) { |
| 774 | if (vls > ppd->vls_supported) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 775 | smp->status |= IB_SMP_INVALID_FIELD; |
| 776 | else |
| 777 | (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_OP_VLS, vls); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | if (pip->mkey_violations == 0) |
| 781 | ibp->mkey_violations = 0; |
| 782 | |
| 783 | if (pip->pkey_violations == 0) |
| 784 | ibp->pkey_violations = 0; |
| 785 | |
| 786 | if (pip->qkey_violations == 0) |
| 787 | ibp->qkey_violations = 0; |
| 788 | |
| 789 | ore = pip->localphyerrors_overrunerrors; |
| 790 | if (set_phyerrthreshold(ppd, (ore >> 4) & 0xF)) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 791 | smp->status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 792 | |
| 793 | if (set_overrunthreshold(ppd, (ore & 0xF))) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 794 | smp->status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 795 | |
| 796 | ibp->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F; |
| 797 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 798 | /* |
| 799 | * Do the port state change now that the other link parameters |
| 800 | * have been set. |
| 801 | * Changing the port physical state only makes sense if the link |
| 802 | * is down or is being set to down. |
| 803 | */ |
| 804 | state = pip->linkspeed_portstate & 0xF; |
| 805 | lstate = (pip->portphysstate_linkdown >> 4) & 0xF; |
| 806 | if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP)) |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 807 | smp->status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 808 | |
| 809 | /* |
| 810 | * Only state changes of DOWN, ARM, and ACTIVE are valid |
| 811 | * and must be in the correct state to take effect (see 7.2.6). |
| 812 | */ |
| 813 | switch (state) { |
| 814 | case IB_PORT_NOP: |
| 815 | if (lstate == 0) |
| 816 | break; |
| 817 | /* FALLTHROUGH */ |
| 818 | case IB_PORT_DOWN: |
| 819 | if (lstate == 0) |
| 820 | lstate = QIB_IB_LINKDOWN_ONLY; |
| 821 | else if (lstate == 1) |
| 822 | lstate = QIB_IB_LINKDOWN_SLEEP; |
| 823 | else if (lstate == 2) |
| 824 | lstate = QIB_IB_LINKDOWN; |
| 825 | else if (lstate == 3) |
| 826 | lstate = QIB_IB_LINKDOWN_DISABLE; |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 827 | else { |
| 828 | smp->status |= IB_SMP_INVALID_FIELD; |
| 829 | break; |
| 830 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 831 | spin_lock_irqsave(&ppd->lflags_lock, flags); |
| 832 | ppd->lflags &= ~QIBL_LINKV; |
| 833 | spin_unlock_irqrestore(&ppd->lflags_lock, flags); |
| 834 | qib_set_linkstate(ppd, lstate); |
| 835 | /* |
| 836 | * Don't send a reply if the response would be sent |
| 837 | * through the disabled port. |
| 838 | */ |
| 839 | if (lstate == QIB_IB_LINKDOWN_DISABLE && smp->hop_cnt) { |
| 840 | ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
| 841 | goto done; |
| 842 | } |
| 843 | qib_wait_linkstate(ppd, QIBL_LINKV, 10); |
| 844 | break; |
| 845 | case IB_PORT_ARMED: |
| 846 | qib_set_linkstate(ppd, QIB_IB_LINKARM); |
| 847 | break; |
| 848 | case IB_PORT_ACTIVE: |
| 849 | qib_set_linkstate(ppd, QIB_IB_LINKACTIVE); |
| 850 | break; |
| 851 | default: |
Mike Marciniszyn | 3c9e5f4 | 2011-01-10 17:42:19 -0800 | [diff] [blame] | 852 | smp->status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Todd Rimmer | 4ccf28a | 2012-05-02 14:35:18 -0400 | [diff] [blame] | 855 | if (clientrereg) { |
| 856 | event.event = IB_EVENT_CLIENT_REREGISTER; |
| 857 | ib_dispatch_event(&event); |
| 858 | } |
| 859 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 860 | ret = subn_get_portinfo(smp, ibdev, port); |
| 861 | |
Todd Rimmer | 4ccf28a | 2012-05-02 14:35:18 -0400 | [diff] [blame] | 862 | /* restore re-reg bit per o14-12.2.1 */ |
| 863 | pip->clientrereg_resv_subnetto |= clientrereg; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 864 | |
Mitko Haralanov | cc7fb05 | 2011-02-22 16:56:37 -0800 | [diff] [blame] | 865 | goto get_only; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 866 | |
| 867 | err: |
| 868 | smp->status |= IB_SMP_INVALID_FIELD; |
| 869 | get_only: |
| 870 | ret = subn_get_portinfo(smp, ibdev, port); |
| 871 | done: |
| 872 | return ret; |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * rm_pkey - decrecment the reference count for the given PKEY |
| 877 | * @dd: the qlogic_ib device |
| 878 | * @key: the PKEY index |
| 879 | * |
| 880 | * Return true if this was the last reference and the hardware table entry |
| 881 | * needs to be changed. |
| 882 | */ |
| 883 | static int rm_pkey(struct qib_pportdata *ppd, u16 key) |
| 884 | { |
| 885 | int i; |
| 886 | int ret; |
| 887 | |
| 888 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { |
| 889 | if (ppd->pkeys[i] != key) |
| 890 | continue; |
| 891 | if (atomic_dec_and_test(&ppd->pkeyrefs[i])) { |
| 892 | ppd->pkeys[i] = 0; |
| 893 | ret = 1; |
| 894 | goto bail; |
| 895 | } |
| 896 | break; |
| 897 | } |
| 898 | |
| 899 | ret = 0; |
| 900 | |
| 901 | bail: |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * add_pkey - add the given PKEY to the hardware table |
| 907 | * @dd: the qlogic_ib device |
| 908 | * @key: the PKEY |
| 909 | * |
| 910 | * Return an error code if unable to add the entry, zero if no change, |
| 911 | * or 1 if the hardware PKEY register needs to be updated. |
| 912 | */ |
| 913 | static int add_pkey(struct qib_pportdata *ppd, u16 key) |
| 914 | { |
| 915 | int i; |
| 916 | u16 lkey = key & 0x7FFF; |
| 917 | int any = 0; |
| 918 | int ret; |
| 919 | |
| 920 | if (lkey == 0x7FFF) { |
| 921 | ret = 0; |
| 922 | goto bail; |
| 923 | } |
| 924 | |
| 925 | /* Look for an empty slot or a matching PKEY. */ |
| 926 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { |
| 927 | if (!ppd->pkeys[i]) { |
| 928 | any++; |
| 929 | continue; |
| 930 | } |
| 931 | /* If it matches exactly, try to increment the ref count */ |
| 932 | if (ppd->pkeys[i] == key) { |
| 933 | if (atomic_inc_return(&ppd->pkeyrefs[i]) > 1) { |
| 934 | ret = 0; |
| 935 | goto bail; |
| 936 | } |
| 937 | /* Lost the race. Look for an empty slot below. */ |
| 938 | atomic_dec(&ppd->pkeyrefs[i]); |
| 939 | any++; |
| 940 | } |
| 941 | /* |
| 942 | * It makes no sense to have both the limited and unlimited |
| 943 | * PKEY set at the same time since the unlimited one will |
| 944 | * disable the limited one. |
| 945 | */ |
| 946 | if ((ppd->pkeys[i] & 0x7FFF) == lkey) { |
| 947 | ret = -EEXIST; |
| 948 | goto bail; |
| 949 | } |
| 950 | } |
| 951 | if (!any) { |
| 952 | ret = -EBUSY; |
| 953 | goto bail; |
| 954 | } |
| 955 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { |
| 956 | if (!ppd->pkeys[i] && |
| 957 | atomic_inc_return(&ppd->pkeyrefs[i]) == 1) { |
| 958 | /* for qibstats, etc. */ |
| 959 | ppd->pkeys[i] = key; |
| 960 | ret = 1; |
| 961 | goto bail; |
| 962 | } |
| 963 | } |
| 964 | ret = -EBUSY; |
| 965 | |
| 966 | bail: |
| 967 | return ret; |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * set_pkeys - set the PKEY table for ctxt 0 |
| 972 | * @dd: the qlogic_ib device |
| 973 | * @port: the IB port number |
| 974 | * @pkeys: the PKEY table |
| 975 | */ |
| 976 | static int set_pkeys(struct qib_devdata *dd, u8 port, u16 *pkeys) |
| 977 | { |
| 978 | struct qib_pportdata *ppd; |
| 979 | struct qib_ctxtdata *rcd; |
| 980 | int i; |
| 981 | int changed = 0; |
| 982 | |
| 983 | /* |
| 984 | * IB port one/two always maps to context zero/one, |
| 985 | * always a kernel context, no locking needed |
| 986 | * If we get here with ppd setup, no need to check |
| 987 | * that rcd is valid. |
| 988 | */ |
| 989 | ppd = dd->pport + (port - 1); |
| 990 | rcd = dd->rcd[ppd->hw_pidx]; |
| 991 | |
| 992 | for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) { |
| 993 | u16 key = pkeys[i]; |
| 994 | u16 okey = rcd->pkeys[i]; |
| 995 | |
| 996 | if (key == okey) |
| 997 | continue; |
| 998 | /* |
| 999 | * The value of this PKEY table entry is changing. |
| 1000 | * Remove the old entry in the hardware's array of PKEYs. |
| 1001 | */ |
| 1002 | if (okey & 0x7FFF) |
| 1003 | changed |= rm_pkey(ppd, okey); |
| 1004 | if (key & 0x7FFF) { |
| 1005 | int ret = add_pkey(ppd, key); |
| 1006 | |
| 1007 | if (ret < 0) |
| 1008 | key = 0; |
| 1009 | else |
| 1010 | changed |= ret; |
| 1011 | } |
| 1012 | rcd->pkeys[i] = key; |
| 1013 | } |
| 1014 | if (changed) { |
| 1015 | struct ib_event event; |
| 1016 | |
| 1017 | (void) dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0); |
| 1018 | |
| 1019 | event.event = IB_EVENT_PKEY_CHANGE; |
| 1020 | event.device = &dd->verbs_dev.ibdev; |
| 1021 | event.element.port_num = 1; |
| 1022 | ib_dispatch_event(&event); |
| 1023 | } |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | static int subn_set_pkeytable(struct ib_smp *smp, struct ib_device *ibdev, |
| 1028 | u8 port) |
| 1029 | { |
| 1030 | u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff); |
| 1031 | __be16 *p = (__be16 *) smp->data; |
| 1032 | u16 *q = (u16 *) smp->data; |
| 1033 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 1034 | unsigned i, n = qib_get_npkeys(dd); |
| 1035 | |
| 1036 | for (i = 0; i < n; i++) |
| 1037 | q[i] = be16_to_cpu(p[i]); |
| 1038 | |
| 1039 | if (startpx != 0 || set_pkeys(dd, port, q) != 0) |
| 1040 | smp->status |= IB_SMP_INVALID_FIELD; |
| 1041 | |
| 1042 | return subn_get_pkeytable(smp, ibdev, port); |
| 1043 | } |
| 1044 | |
| 1045 | static int subn_get_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev, |
| 1046 | u8 port) |
| 1047 | { |
| 1048 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1049 | u8 *p = (u8 *) smp->data; |
| 1050 | unsigned i; |
| 1051 | |
| 1052 | memset(smp->data, 0, sizeof(smp->data)); |
| 1053 | |
| 1054 | if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP)) |
| 1055 | smp->status |= IB_SMP_UNSUP_METHOD; |
| 1056 | else |
| 1057 | for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2) |
| 1058 | *p++ = (ibp->sl_to_vl[i] << 4) | ibp->sl_to_vl[i + 1]; |
| 1059 | |
| 1060 | return reply(smp); |
| 1061 | } |
| 1062 | |
| 1063 | static int subn_set_sl_to_vl(struct ib_smp *smp, struct ib_device *ibdev, |
| 1064 | u8 port) |
| 1065 | { |
| 1066 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1067 | u8 *p = (u8 *) smp->data; |
| 1068 | unsigned i; |
| 1069 | |
| 1070 | if (!(ibp->port_cap_flags & IB_PORT_SL_MAP_SUP)) { |
| 1071 | smp->status |= IB_SMP_UNSUP_METHOD; |
| 1072 | return reply(smp); |
| 1073 | } |
| 1074 | |
| 1075 | for (i = 0; i < ARRAY_SIZE(ibp->sl_to_vl); i += 2, p++) { |
| 1076 | ibp->sl_to_vl[i] = *p >> 4; |
| 1077 | ibp->sl_to_vl[i + 1] = *p & 0xF; |
| 1078 | } |
| 1079 | qib_set_uevent_bits(ppd_from_ibp(to_iport(ibdev, port)), |
| 1080 | _QIB_EVENT_SL2VL_CHANGE_BIT); |
| 1081 | |
| 1082 | return subn_get_sl_to_vl(smp, ibdev, port); |
| 1083 | } |
| 1084 | |
| 1085 | static int subn_get_vl_arb(struct ib_smp *smp, struct ib_device *ibdev, |
| 1086 | u8 port) |
| 1087 | { |
| 1088 | unsigned which = be32_to_cpu(smp->attr_mod) >> 16; |
| 1089 | struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port)); |
| 1090 | |
| 1091 | memset(smp->data, 0, sizeof(smp->data)); |
| 1092 | |
| 1093 | if (ppd->vls_supported == IB_VL_VL0) |
| 1094 | smp->status |= IB_SMP_UNSUP_METHOD; |
| 1095 | else if (which == IB_VLARB_LOWPRI_0_31) |
| 1096 | (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB, |
| 1097 | smp->data); |
| 1098 | else if (which == IB_VLARB_HIGHPRI_0_31) |
| 1099 | (void) ppd->dd->f_get_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB, |
| 1100 | smp->data); |
| 1101 | else |
| 1102 | smp->status |= IB_SMP_INVALID_FIELD; |
| 1103 | |
| 1104 | return reply(smp); |
| 1105 | } |
| 1106 | |
| 1107 | static int subn_set_vl_arb(struct ib_smp *smp, struct ib_device *ibdev, |
| 1108 | u8 port) |
| 1109 | { |
| 1110 | unsigned which = be32_to_cpu(smp->attr_mod) >> 16; |
| 1111 | struct qib_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port)); |
| 1112 | |
| 1113 | if (ppd->vls_supported == IB_VL_VL0) |
| 1114 | smp->status |= IB_SMP_UNSUP_METHOD; |
| 1115 | else if (which == IB_VLARB_LOWPRI_0_31) |
| 1116 | (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_LOW_ARB, |
| 1117 | smp->data); |
| 1118 | else if (which == IB_VLARB_HIGHPRI_0_31) |
| 1119 | (void) ppd->dd->f_set_ib_table(ppd, QIB_IB_TBL_VL_HIGH_ARB, |
| 1120 | smp->data); |
| 1121 | else |
| 1122 | smp->status |= IB_SMP_INVALID_FIELD; |
| 1123 | |
| 1124 | return subn_get_vl_arb(smp, ibdev, port); |
| 1125 | } |
| 1126 | |
| 1127 | static int subn_trap_repress(struct ib_smp *smp, struct ib_device *ibdev, |
| 1128 | u8 port) |
| 1129 | { |
| 1130 | /* |
| 1131 | * For now, we only send the trap once so no need to process this. |
| 1132 | * o13-6, o13-7, |
| 1133 | * o14-3.a4 The SMA shall not send any message in response to a valid |
| 1134 | * SubnTrapRepress() message. |
| 1135 | */ |
| 1136 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
| 1137 | } |
| 1138 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1139 | static int pma_get_classportinfo(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1140 | struct ib_device *ibdev) |
| 1141 | { |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1142 | struct ib_class_port_info *p = |
| 1143 | (struct ib_class_port_info *)pmp->data; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1144 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 1145 | |
| 1146 | memset(pmp->data, 0, sizeof(pmp->data)); |
| 1147 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1148 | if (pmp->mad_hdr.attr_mod != 0) |
| 1149 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1150 | |
| 1151 | /* Note that AllPortSelect is not valid */ |
| 1152 | p->base_version = 1; |
| 1153 | p->class_version = 1; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1154 | p->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1155 | /* |
| 1156 | * Set the most significant bit of CM2 to indicate support for |
| 1157 | * congestion statistics |
| 1158 | */ |
| 1159 | p->reserved[0] = dd->psxmitwait_supported << 7; |
| 1160 | /* |
| 1161 | * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec. |
| 1162 | */ |
| 1163 | p->resp_time_value = 18; |
| 1164 | |
| 1165 | return reply((struct ib_smp *) pmp); |
| 1166 | } |
| 1167 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1168 | static int pma_get_portsamplescontrol(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1169 | struct ib_device *ibdev, u8 port) |
| 1170 | { |
| 1171 | struct ib_pma_portsamplescontrol *p = |
| 1172 | (struct ib_pma_portsamplescontrol *)pmp->data; |
| 1173 | struct qib_ibdev *dev = to_idev(ibdev); |
| 1174 | struct qib_devdata *dd = dd_from_dev(dev); |
| 1175 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1176 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1177 | unsigned long flags; |
| 1178 | u8 port_select = p->port_select; |
| 1179 | |
| 1180 | memset(pmp->data, 0, sizeof(pmp->data)); |
| 1181 | |
| 1182 | p->port_select = port_select; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1183 | if (pmp->mad_hdr.attr_mod != 0 || port_select != port) { |
| 1184 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1185 | goto bail; |
| 1186 | } |
| 1187 | spin_lock_irqsave(&ibp->lock, flags); |
| 1188 | p->tick = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_PMA_TICKS); |
| 1189 | p->sample_status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); |
| 1190 | p->counter_width = 4; /* 32 bit counters */ |
| 1191 | p->counter_mask0_9 = COUNTER_MASK0_9; |
| 1192 | p->sample_start = cpu_to_be32(ibp->pma_sample_start); |
| 1193 | p->sample_interval = cpu_to_be32(ibp->pma_sample_interval); |
| 1194 | p->tag = cpu_to_be16(ibp->pma_tag); |
| 1195 | p->counter_select[0] = ibp->pma_counter_select[0]; |
| 1196 | p->counter_select[1] = ibp->pma_counter_select[1]; |
| 1197 | p->counter_select[2] = ibp->pma_counter_select[2]; |
| 1198 | p->counter_select[3] = ibp->pma_counter_select[3]; |
| 1199 | p->counter_select[4] = ibp->pma_counter_select[4]; |
| 1200 | spin_unlock_irqrestore(&ibp->lock, flags); |
| 1201 | |
| 1202 | bail: |
| 1203 | return reply((struct ib_smp *) pmp); |
| 1204 | } |
| 1205 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1206 | static int pma_set_portsamplescontrol(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1207 | struct ib_device *ibdev, u8 port) |
| 1208 | { |
| 1209 | struct ib_pma_portsamplescontrol *p = |
| 1210 | (struct ib_pma_portsamplescontrol *)pmp->data; |
| 1211 | struct qib_ibdev *dev = to_idev(ibdev); |
| 1212 | struct qib_devdata *dd = dd_from_dev(dev); |
| 1213 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1214 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1215 | unsigned long flags; |
| 1216 | u8 status, xmit_flags; |
| 1217 | int ret; |
| 1218 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1219 | if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) { |
| 1220 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1221 | ret = reply((struct ib_smp *) pmp); |
| 1222 | goto bail; |
| 1223 | } |
| 1224 | |
| 1225 | spin_lock_irqsave(&ibp->lock, flags); |
| 1226 | |
| 1227 | /* Port Sampling code owns the PS* HW counters */ |
| 1228 | xmit_flags = ppd->cong_stats.flags; |
| 1229 | ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_SAMPLE; |
| 1230 | status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); |
| 1231 | if (status == IB_PMA_SAMPLE_STATUS_DONE || |
| 1232 | (status == IB_PMA_SAMPLE_STATUS_RUNNING && |
| 1233 | xmit_flags == IB_PMA_CONG_HW_CONTROL_TIMER)) { |
| 1234 | ibp->pma_sample_start = be32_to_cpu(p->sample_start); |
| 1235 | ibp->pma_sample_interval = be32_to_cpu(p->sample_interval); |
| 1236 | ibp->pma_tag = be16_to_cpu(p->tag); |
| 1237 | ibp->pma_counter_select[0] = p->counter_select[0]; |
| 1238 | ibp->pma_counter_select[1] = p->counter_select[1]; |
| 1239 | ibp->pma_counter_select[2] = p->counter_select[2]; |
| 1240 | ibp->pma_counter_select[3] = p->counter_select[3]; |
| 1241 | ibp->pma_counter_select[4] = p->counter_select[4]; |
| 1242 | dd->f_set_cntr_sample(ppd, ibp->pma_sample_interval, |
| 1243 | ibp->pma_sample_start); |
| 1244 | } |
| 1245 | spin_unlock_irqrestore(&ibp->lock, flags); |
| 1246 | |
| 1247 | ret = pma_get_portsamplescontrol(pmp, ibdev, port); |
| 1248 | |
| 1249 | bail: |
| 1250 | return ret; |
| 1251 | } |
| 1252 | |
| 1253 | static u64 get_counter(struct qib_ibport *ibp, struct qib_pportdata *ppd, |
| 1254 | __be16 sel) |
| 1255 | { |
| 1256 | u64 ret; |
| 1257 | |
| 1258 | switch (sel) { |
| 1259 | case IB_PMA_PORT_XMIT_DATA: |
| 1260 | ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITDATA); |
| 1261 | break; |
| 1262 | case IB_PMA_PORT_RCV_DATA: |
| 1263 | ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVDATA); |
| 1264 | break; |
| 1265 | case IB_PMA_PORT_XMIT_PKTS: |
| 1266 | ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITPKTS); |
| 1267 | break; |
| 1268 | case IB_PMA_PORT_RCV_PKTS: |
| 1269 | ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSRCVPKTS); |
| 1270 | break; |
| 1271 | case IB_PMA_PORT_XMIT_WAIT: |
| 1272 | ret = ppd->dd->f_portcntr(ppd, QIBPORTCNTR_PSXMITWAIT); |
| 1273 | break; |
| 1274 | default: |
| 1275 | ret = 0; |
| 1276 | } |
| 1277 | |
| 1278 | return ret; |
| 1279 | } |
| 1280 | |
| 1281 | /* This function assumes that the xmit_wait lock is already held */ |
| 1282 | static u64 xmit_wait_get_value_delta(struct qib_pportdata *ppd) |
| 1283 | { |
| 1284 | u32 delta; |
| 1285 | |
| 1286 | delta = get_counter(&ppd->ibport_data, ppd, |
| 1287 | IB_PMA_PORT_XMIT_WAIT); |
| 1288 | return ppd->cong_stats.counter + delta; |
| 1289 | } |
| 1290 | |
| 1291 | static void cache_hw_sample_counters(struct qib_pportdata *ppd) |
| 1292 | { |
| 1293 | struct qib_ibport *ibp = &ppd->ibport_data; |
| 1294 | |
| 1295 | ppd->cong_stats.counter_cache.psxmitdata = |
| 1296 | get_counter(ibp, ppd, IB_PMA_PORT_XMIT_DATA); |
| 1297 | ppd->cong_stats.counter_cache.psrcvdata = |
| 1298 | get_counter(ibp, ppd, IB_PMA_PORT_RCV_DATA); |
| 1299 | ppd->cong_stats.counter_cache.psxmitpkts = |
| 1300 | get_counter(ibp, ppd, IB_PMA_PORT_XMIT_PKTS); |
| 1301 | ppd->cong_stats.counter_cache.psrcvpkts = |
| 1302 | get_counter(ibp, ppd, IB_PMA_PORT_RCV_PKTS); |
| 1303 | ppd->cong_stats.counter_cache.psxmitwait = |
| 1304 | get_counter(ibp, ppd, IB_PMA_PORT_XMIT_WAIT); |
| 1305 | } |
| 1306 | |
| 1307 | static u64 get_cache_hw_sample_counters(struct qib_pportdata *ppd, |
| 1308 | __be16 sel) |
| 1309 | { |
| 1310 | u64 ret; |
| 1311 | |
| 1312 | switch (sel) { |
| 1313 | case IB_PMA_PORT_XMIT_DATA: |
| 1314 | ret = ppd->cong_stats.counter_cache.psxmitdata; |
| 1315 | break; |
| 1316 | case IB_PMA_PORT_RCV_DATA: |
| 1317 | ret = ppd->cong_stats.counter_cache.psrcvdata; |
| 1318 | break; |
| 1319 | case IB_PMA_PORT_XMIT_PKTS: |
| 1320 | ret = ppd->cong_stats.counter_cache.psxmitpkts; |
| 1321 | break; |
| 1322 | case IB_PMA_PORT_RCV_PKTS: |
| 1323 | ret = ppd->cong_stats.counter_cache.psrcvpkts; |
| 1324 | break; |
| 1325 | case IB_PMA_PORT_XMIT_WAIT: |
| 1326 | ret = ppd->cong_stats.counter_cache.psxmitwait; |
| 1327 | break; |
| 1328 | default: |
| 1329 | ret = 0; |
| 1330 | } |
| 1331 | |
| 1332 | return ret; |
| 1333 | } |
| 1334 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1335 | static int pma_get_portsamplesresult(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1336 | struct ib_device *ibdev, u8 port) |
| 1337 | { |
| 1338 | struct ib_pma_portsamplesresult *p = |
| 1339 | (struct ib_pma_portsamplesresult *)pmp->data; |
| 1340 | struct qib_ibdev *dev = to_idev(ibdev); |
| 1341 | struct qib_devdata *dd = dd_from_dev(dev); |
| 1342 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1343 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1344 | unsigned long flags; |
| 1345 | u8 status; |
| 1346 | int i; |
| 1347 | |
| 1348 | memset(pmp->data, 0, sizeof(pmp->data)); |
| 1349 | spin_lock_irqsave(&ibp->lock, flags); |
| 1350 | p->tag = cpu_to_be16(ibp->pma_tag); |
| 1351 | if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER) |
| 1352 | p->sample_status = IB_PMA_SAMPLE_STATUS_DONE; |
| 1353 | else { |
| 1354 | status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); |
| 1355 | p->sample_status = cpu_to_be16(status); |
| 1356 | if (status == IB_PMA_SAMPLE_STATUS_DONE) { |
| 1357 | cache_hw_sample_counters(ppd); |
| 1358 | ppd->cong_stats.counter = |
| 1359 | xmit_wait_get_value_delta(ppd); |
| 1360 | dd->f_set_cntr_sample(ppd, |
| 1361 | QIB_CONG_TIMER_PSINTERVAL, 0); |
| 1362 | ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER; |
| 1363 | } |
| 1364 | } |
| 1365 | for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++) |
| 1366 | p->counter[i] = cpu_to_be32( |
| 1367 | get_cache_hw_sample_counters( |
| 1368 | ppd, ibp->pma_counter_select[i])); |
| 1369 | spin_unlock_irqrestore(&ibp->lock, flags); |
| 1370 | |
| 1371 | return reply((struct ib_smp *) pmp); |
| 1372 | } |
| 1373 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1374 | static int pma_get_portsamplesresult_ext(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1375 | struct ib_device *ibdev, u8 port) |
| 1376 | { |
| 1377 | struct ib_pma_portsamplesresult_ext *p = |
| 1378 | (struct ib_pma_portsamplesresult_ext *)pmp->data; |
| 1379 | struct qib_ibdev *dev = to_idev(ibdev); |
| 1380 | struct qib_devdata *dd = dd_from_dev(dev); |
| 1381 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1382 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1383 | unsigned long flags; |
| 1384 | u8 status; |
| 1385 | int i; |
| 1386 | |
| 1387 | /* Port Sampling code owns the PS* HW counters */ |
| 1388 | memset(pmp->data, 0, sizeof(pmp->data)); |
| 1389 | spin_lock_irqsave(&ibp->lock, flags); |
| 1390 | p->tag = cpu_to_be16(ibp->pma_tag); |
| 1391 | if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_TIMER) |
| 1392 | p->sample_status = IB_PMA_SAMPLE_STATUS_DONE; |
| 1393 | else { |
| 1394 | status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); |
| 1395 | p->sample_status = cpu_to_be16(status); |
| 1396 | /* 64 bits */ |
| 1397 | p->extended_width = cpu_to_be32(0x80000000); |
| 1398 | if (status == IB_PMA_SAMPLE_STATUS_DONE) { |
| 1399 | cache_hw_sample_counters(ppd); |
| 1400 | ppd->cong_stats.counter = |
| 1401 | xmit_wait_get_value_delta(ppd); |
| 1402 | dd->f_set_cntr_sample(ppd, |
| 1403 | QIB_CONG_TIMER_PSINTERVAL, 0); |
| 1404 | ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER; |
| 1405 | } |
| 1406 | } |
| 1407 | for (i = 0; i < ARRAY_SIZE(ibp->pma_counter_select); i++) |
| 1408 | p->counter[i] = cpu_to_be64( |
| 1409 | get_cache_hw_sample_counters( |
| 1410 | ppd, ibp->pma_counter_select[i])); |
| 1411 | spin_unlock_irqrestore(&ibp->lock, flags); |
| 1412 | |
| 1413 | return reply((struct ib_smp *) pmp); |
| 1414 | } |
| 1415 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1416 | static int pma_get_portcounters(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1417 | struct ib_device *ibdev, u8 port) |
| 1418 | { |
| 1419 | struct ib_pma_portcounters *p = (struct ib_pma_portcounters *) |
| 1420 | pmp->data; |
| 1421 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1422 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1423 | struct qib_verbs_counters cntrs; |
| 1424 | u8 port_select = p->port_select; |
| 1425 | |
| 1426 | qib_get_counters(ppd, &cntrs); |
| 1427 | |
| 1428 | /* Adjust counters for any resets done. */ |
| 1429 | cntrs.symbol_error_counter -= ibp->z_symbol_error_counter; |
| 1430 | cntrs.link_error_recovery_counter -= |
| 1431 | ibp->z_link_error_recovery_counter; |
| 1432 | cntrs.link_downed_counter -= ibp->z_link_downed_counter; |
| 1433 | cntrs.port_rcv_errors -= ibp->z_port_rcv_errors; |
| 1434 | cntrs.port_rcv_remphys_errors -= ibp->z_port_rcv_remphys_errors; |
| 1435 | cntrs.port_xmit_discards -= ibp->z_port_xmit_discards; |
| 1436 | cntrs.port_xmit_data -= ibp->z_port_xmit_data; |
| 1437 | cntrs.port_rcv_data -= ibp->z_port_rcv_data; |
| 1438 | cntrs.port_xmit_packets -= ibp->z_port_xmit_packets; |
| 1439 | cntrs.port_rcv_packets -= ibp->z_port_rcv_packets; |
| 1440 | cntrs.local_link_integrity_errors -= |
| 1441 | ibp->z_local_link_integrity_errors; |
| 1442 | cntrs.excessive_buffer_overrun_errors -= |
| 1443 | ibp->z_excessive_buffer_overrun_errors; |
| 1444 | cntrs.vl15_dropped -= ibp->z_vl15_dropped; |
| 1445 | cntrs.vl15_dropped += ibp->n_vl15_dropped; |
| 1446 | |
| 1447 | memset(pmp->data, 0, sizeof(pmp->data)); |
| 1448 | |
| 1449 | p->port_select = port_select; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1450 | if (pmp->mad_hdr.attr_mod != 0 || port_select != port) |
| 1451 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1452 | |
| 1453 | if (cntrs.symbol_error_counter > 0xFFFFUL) |
| 1454 | p->symbol_error_counter = cpu_to_be16(0xFFFF); |
| 1455 | else |
| 1456 | p->symbol_error_counter = |
| 1457 | cpu_to_be16((u16)cntrs.symbol_error_counter); |
| 1458 | if (cntrs.link_error_recovery_counter > 0xFFUL) |
| 1459 | p->link_error_recovery_counter = 0xFF; |
| 1460 | else |
| 1461 | p->link_error_recovery_counter = |
| 1462 | (u8)cntrs.link_error_recovery_counter; |
| 1463 | if (cntrs.link_downed_counter > 0xFFUL) |
| 1464 | p->link_downed_counter = 0xFF; |
| 1465 | else |
| 1466 | p->link_downed_counter = (u8)cntrs.link_downed_counter; |
| 1467 | if (cntrs.port_rcv_errors > 0xFFFFUL) |
| 1468 | p->port_rcv_errors = cpu_to_be16(0xFFFF); |
| 1469 | else |
| 1470 | p->port_rcv_errors = |
| 1471 | cpu_to_be16((u16) cntrs.port_rcv_errors); |
| 1472 | if (cntrs.port_rcv_remphys_errors > 0xFFFFUL) |
| 1473 | p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF); |
| 1474 | else |
| 1475 | p->port_rcv_remphys_errors = |
| 1476 | cpu_to_be16((u16)cntrs.port_rcv_remphys_errors); |
| 1477 | if (cntrs.port_xmit_discards > 0xFFFFUL) |
| 1478 | p->port_xmit_discards = cpu_to_be16(0xFFFF); |
| 1479 | else |
| 1480 | p->port_xmit_discards = |
| 1481 | cpu_to_be16((u16)cntrs.port_xmit_discards); |
| 1482 | if (cntrs.local_link_integrity_errors > 0xFUL) |
| 1483 | cntrs.local_link_integrity_errors = 0xFUL; |
| 1484 | if (cntrs.excessive_buffer_overrun_errors > 0xFUL) |
| 1485 | cntrs.excessive_buffer_overrun_errors = 0xFUL; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1486 | p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1487 | cntrs.excessive_buffer_overrun_errors; |
| 1488 | if (cntrs.vl15_dropped > 0xFFFFUL) |
| 1489 | p->vl15_dropped = cpu_to_be16(0xFFFF); |
| 1490 | else |
| 1491 | p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped); |
| 1492 | if (cntrs.port_xmit_data > 0xFFFFFFFFUL) |
| 1493 | p->port_xmit_data = cpu_to_be32(0xFFFFFFFF); |
| 1494 | else |
| 1495 | p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data); |
| 1496 | if (cntrs.port_rcv_data > 0xFFFFFFFFUL) |
| 1497 | p->port_rcv_data = cpu_to_be32(0xFFFFFFFF); |
| 1498 | else |
| 1499 | p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data); |
| 1500 | if (cntrs.port_xmit_packets > 0xFFFFFFFFUL) |
| 1501 | p->port_xmit_packets = cpu_to_be32(0xFFFFFFFF); |
| 1502 | else |
| 1503 | p->port_xmit_packets = |
| 1504 | cpu_to_be32((u32)cntrs.port_xmit_packets); |
| 1505 | if (cntrs.port_rcv_packets > 0xFFFFFFFFUL) |
| 1506 | p->port_rcv_packets = cpu_to_be32(0xFFFFFFFF); |
| 1507 | else |
| 1508 | p->port_rcv_packets = |
| 1509 | cpu_to_be32((u32) cntrs.port_rcv_packets); |
| 1510 | |
| 1511 | return reply((struct ib_smp *) pmp); |
| 1512 | } |
| 1513 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1514 | static int pma_get_portcounters_cong(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1515 | struct ib_device *ibdev, u8 port) |
| 1516 | { |
| 1517 | /* Congestion PMA packets start at offset 24 not 64 */ |
| 1518 | struct ib_pma_portcounters_cong *p = |
| 1519 | (struct ib_pma_portcounters_cong *)pmp->reserved; |
| 1520 | struct qib_verbs_counters cntrs; |
| 1521 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1522 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1523 | struct qib_devdata *dd = dd_from_ppd(ppd); |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1524 | u32 port_select = be32_to_cpu(pmp->mad_hdr.attr_mod) & 0xFF; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1525 | u64 xmit_wait_counter; |
| 1526 | unsigned long flags; |
| 1527 | |
| 1528 | /* |
| 1529 | * This check is performed only in the GET method because the |
| 1530 | * SET method ends up calling this anyway. |
| 1531 | */ |
| 1532 | if (!dd->psxmitwait_supported) |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1533 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1534 | if (port_select != port) |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1535 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1536 | |
| 1537 | qib_get_counters(ppd, &cntrs); |
| 1538 | spin_lock_irqsave(&ppd->ibport_data.lock, flags); |
| 1539 | xmit_wait_counter = xmit_wait_get_value_delta(ppd); |
| 1540 | spin_unlock_irqrestore(&ppd->ibport_data.lock, flags); |
| 1541 | |
| 1542 | /* Adjust counters for any resets done. */ |
| 1543 | cntrs.symbol_error_counter -= ibp->z_symbol_error_counter; |
| 1544 | cntrs.link_error_recovery_counter -= |
| 1545 | ibp->z_link_error_recovery_counter; |
| 1546 | cntrs.link_downed_counter -= ibp->z_link_downed_counter; |
| 1547 | cntrs.port_rcv_errors -= ibp->z_port_rcv_errors; |
| 1548 | cntrs.port_rcv_remphys_errors -= |
| 1549 | ibp->z_port_rcv_remphys_errors; |
| 1550 | cntrs.port_xmit_discards -= ibp->z_port_xmit_discards; |
| 1551 | cntrs.local_link_integrity_errors -= |
| 1552 | ibp->z_local_link_integrity_errors; |
| 1553 | cntrs.excessive_buffer_overrun_errors -= |
| 1554 | ibp->z_excessive_buffer_overrun_errors; |
| 1555 | cntrs.vl15_dropped -= ibp->z_vl15_dropped; |
| 1556 | cntrs.vl15_dropped += ibp->n_vl15_dropped; |
| 1557 | cntrs.port_xmit_data -= ibp->z_port_xmit_data; |
| 1558 | cntrs.port_rcv_data -= ibp->z_port_rcv_data; |
| 1559 | cntrs.port_xmit_packets -= ibp->z_port_xmit_packets; |
| 1560 | cntrs.port_rcv_packets -= ibp->z_port_rcv_packets; |
| 1561 | |
| 1562 | memset(pmp->reserved, 0, sizeof(pmp->reserved) + |
| 1563 | sizeof(pmp->data)); |
| 1564 | |
| 1565 | /* |
| 1566 | * Set top 3 bits to indicate interval in picoseconds in |
| 1567 | * remaining bits. |
| 1568 | */ |
| 1569 | p->port_check_rate = |
| 1570 | cpu_to_be16((QIB_XMIT_RATE_PICO << 13) | |
| 1571 | (dd->psxmitwait_check_rate & |
| 1572 | ~(QIB_XMIT_RATE_PICO << 13))); |
| 1573 | p->port_adr_events = cpu_to_be64(0); |
| 1574 | p->port_xmit_wait = cpu_to_be64(xmit_wait_counter); |
| 1575 | p->port_xmit_data = cpu_to_be64(cntrs.port_xmit_data); |
| 1576 | p->port_rcv_data = cpu_to_be64(cntrs.port_rcv_data); |
| 1577 | p->port_xmit_packets = |
| 1578 | cpu_to_be64(cntrs.port_xmit_packets); |
| 1579 | p->port_rcv_packets = |
| 1580 | cpu_to_be64(cntrs.port_rcv_packets); |
| 1581 | if (cntrs.symbol_error_counter > 0xFFFFUL) |
| 1582 | p->symbol_error_counter = cpu_to_be16(0xFFFF); |
| 1583 | else |
| 1584 | p->symbol_error_counter = |
| 1585 | cpu_to_be16( |
| 1586 | (u16)cntrs.symbol_error_counter); |
| 1587 | if (cntrs.link_error_recovery_counter > 0xFFUL) |
| 1588 | p->link_error_recovery_counter = 0xFF; |
| 1589 | else |
| 1590 | p->link_error_recovery_counter = |
| 1591 | (u8)cntrs.link_error_recovery_counter; |
| 1592 | if (cntrs.link_downed_counter > 0xFFUL) |
| 1593 | p->link_downed_counter = 0xFF; |
| 1594 | else |
| 1595 | p->link_downed_counter = |
| 1596 | (u8)cntrs.link_downed_counter; |
| 1597 | if (cntrs.port_rcv_errors > 0xFFFFUL) |
| 1598 | p->port_rcv_errors = cpu_to_be16(0xFFFF); |
| 1599 | else |
| 1600 | p->port_rcv_errors = |
| 1601 | cpu_to_be16((u16) cntrs.port_rcv_errors); |
| 1602 | if (cntrs.port_rcv_remphys_errors > 0xFFFFUL) |
| 1603 | p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF); |
| 1604 | else |
| 1605 | p->port_rcv_remphys_errors = |
| 1606 | cpu_to_be16( |
| 1607 | (u16)cntrs.port_rcv_remphys_errors); |
| 1608 | if (cntrs.port_xmit_discards > 0xFFFFUL) |
| 1609 | p->port_xmit_discards = cpu_to_be16(0xFFFF); |
| 1610 | else |
| 1611 | p->port_xmit_discards = |
| 1612 | cpu_to_be16((u16)cntrs.port_xmit_discards); |
| 1613 | if (cntrs.local_link_integrity_errors > 0xFUL) |
| 1614 | cntrs.local_link_integrity_errors = 0xFUL; |
| 1615 | if (cntrs.excessive_buffer_overrun_errors > 0xFUL) |
| 1616 | cntrs.excessive_buffer_overrun_errors = 0xFUL; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1617 | p->link_overrun_errors = (cntrs.local_link_integrity_errors << 4) | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1618 | cntrs.excessive_buffer_overrun_errors; |
| 1619 | if (cntrs.vl15_dropped > 0xFFFFUL) |
| 1620 | p->vl15_dropped = cpu_to_be16(0xFFFF); |
| 1621 | else |
| 1622 | p->vl15_dropped = cpu_to_be16((u16)cntrs.vl15_dropped); |
| 1623 | |
| 1624 | return reply((struct ib_smp *)pmp); |
| 1625 | } |
| 1626 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1627 | static int pma_get_portcounters_ext(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1628 | struct ib_device *ibdev, u8 port) |
| 1629 | { |
| 1630 | struct ib_pma_portcounters_ext *p = |
| 1631 | (struct ib_pma_portcounters_ext *)pmp->data; |
| 1632 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1633 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1634 | u64 swords, rwords, spkts, rpkts, xwait; |
| 1635 | u8 port_select = p->port_select; |
| 1636 | |
| 1637 | memset(pmp->data, 0, sizeof(pmp->data)); |
| 1638 | |
| 1639 | p->port_select = port_select; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1640 | if (pmp->mad_hdr.attr_mod != 0 || port_select != port) { |
| 1641 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1642 | goto bail; |
| 1643 | } |
| 1644 | |
| 1645 | qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait); |
| 1646 | |
| 1647 | /* Adjust counters for any resets done. */ |
| 1648 | swords -= ibp->z_port_xmit_data; |
| 1649 | rwords -= ibp->z_port_rcv_data; |
| 1650 | spkts -= ibp->z_port_xmit_packets; |
| 1651 | rpkts -= ibp->z_port_rcv_packets; |
| 1652 | |
| 1653 | p->port_xmit_data = cpu_to_be64(swords); |
| 1654 | p->port_rcv_data = cpu_to_be64(rwords); |
| 1655 | p->port_xmit_packets = cpu_to_be64(spkts); |
| 1656 | p->port_rcv_packets = cpu_to_be64(rpkts); |
| 1657 | p->port_unicast_xmit_packets = cpu_to_be64(ibp->n_unicast_xmit); |
| 1658 | p->port_unicast_rcv_packets = cpu_to_be64(ibp->n_unicast_rcv); |
| 1659 | p->port_multicast_xmit_packets = cpu_to_be64(ibp->n_multicast_xmit); |
| 1660 | p->port_multicast_rcv_packets = cpu_to_be64(ibp->n_multicast_rcv); |
| 1661 | |
| 1662 | bail: |
| 1663 | return reply((struct ib_smp *) pmp); |
| 1664 | } |
| 1665 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1666 | static int pma_set_portcounters(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1667 | struct ib_device *ibdev, u8 port) |
| 1668 | { |
| 1669 | struct ib_pma_portcounters *p = (struct ib_pma_portcounters *) |
| 1670 | pmp->data; |
| 1671 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1672 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1673 | struct qib_verbs_counters cntrs; |
| 1674 | |
| 1675 | /* |
| 1676 | * Since the HW doesn't support clearing counters, we save the |
| 1677 | * current count and subtract it from future responses. |
| 1678 | */ |
| 1679 | qib_get_counters(ppd, &cntrs); |
| 1680 | |
| 1681 | if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR) |
| 1682 | ibp->z_symbol_error_counter = cntrs.symbol_error_counter; |
| 1683 | |
| 1684 | if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY) |
| 1685 | ibp->z_link_error_recovery_counter = |
| 1686 | cntrs.link_error_recovery_counter; |
| 1687 | |
| 1688 | if (p->counter_select & IB_PMA_SEL_LINK_DOWNED) |
| 1689 | ibp->z_link_downed_counter = cntrs.link_downed_counter; |
| 1690 | |
| 1691 | if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS) |
| 1692 | ibp->z_port_rcv_errors = cntrs.port_rcv_errors; |
| 1693 | |
| 1694 | if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS) |
| 1695 | ibp->z_port_rcv_remphys_errors = |
| 1696 | cntrs.port_rcv_remphys_errors; |
| 1697 | |
| 1698 | if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS) |
| 1699 | ibp->z_port_xmit_discards = cntrs.port_xmit_discards; |
| 1700 | |
| 1701 | if (p->counter_select & IB_PMA_SEL_LOCAL_LINK_INTEGRITY_ERRORS) |
| 1702 | ibp->z_local_link_integrity_errors = |
| 1703 | cntrs.local_link_integrity_errors; |
| 1704 | |
| 1705 | if (p->counter_select & IB_PMA_SEL_EXCESSIVE_BUFFER_OVERRUNS) |
| 1706 | ibp->z_excessive_buffer_overrun_errors = |
| 1707 | cntrs.excessive_buffer_overrun_errors; |
| 1708 | |
| 1709 | if (p->counter_select & IB_PMA_SEL_PORT_VL15_DROPPED) { |
| 1710 | ibp->n_vl15_dropped = 0; |
| 1711 | ibp->z_vl15_dropped = cntrs.vl15_dropped; |
| 1712 | } |
| 1713 | |
| 1714 | if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA) |
| 1715 | ibp->z_port_xmit_data = cntrs.port_xmit_data; |
| 1716 | |
| 1717 | if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA) |
| 1718 | ibp->z_port_rcv_data = cntrs.port_rcv_data; |
| 1719 | |
| 1720 | if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS) |
| 1721 | ibp->z_port_xmit_packets = cntrs.port_xmit_packets; |
| 1722 | |
| 1723 | if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS) |
| 1724 | ibp->z_port_rcv_packets = cntrs.port_rcv_packets; |
| 1725 | |
| 1726 | return pma_get_portcounters(pmp, ibdev, port); |
| 1727 | } |
| 1728 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1729 | static int pma_set_portcounters_cong(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1730 | struct ib_device *ibdev, u8 port) |
| 1731 | { |
| 1732 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1733 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1734 | struct qib_devdata *dd = dd_from_ppd(ppd); |
| 1735 | struct qib_verbs_counters cntrs; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1736 | u32 counter_select = (be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24) & 0xFF; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1737 | int ret = 0; |
| 1738 | unsigned long flags; |
| 1739 | |
| 1740 | qib_get_counters(ppd, &cntrs); |
| 1741 | /* Get counter values before we save them */ |
| 1742 | ret = pma_get_portcounters_cong(pmp, ibdev, port); |
| 1743 | |
| 1744 | if (counter_select & IB_PMA_SEL_CONG_XMIT) { |
| 1745 | spin_lock_irqsave(&ppd->ibport_data.lock, flags); |
| 1746 | ppd->cong_stats.counter = 0; |
| 1747 | dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, |
| 1748 | 0x0); |
| 1749 | spin_unlock_irqrestore(&ppd->ibport_data.lock, flags); |
| 1750 | } |
| 1751 | if (counter_select & IB_PMA_SEL_CONG_PORT_DATA) { |
| 1752 | ibp->z_port_xmit_data = cntrs.port_xmit_data; |
| 1753 | ibp->z_port_rcv_data = cntrs.port_rcv_data; |
| 1754 | ibp->z_port_xmit_packets = cntrs.port_xmit_packets; |
| 1755 | ibp->z_port_rcv_packets = cntrs.port_rcv_packets; |
| 1756 | } |
| 1757 | if (counter_select & IB_PMA_SEL_CONG_ALL) { |
| 1758 | ibp->z_symbol_error_counter = |
| 1759 | cntrs.symbol_error_counter; |
| 1760 | ibp->z_link_error_recovery_counter = |
| 1761 | cntrs.link_error_recovery_counter; |
| 1762 | ibp->z_link_downed_counter = |
| 1763 | cntrs.link_downed_counter; |
| 1764 | ibp->z_port_rcv_errors = cntrs.port_rcv_errors; |
| 1765 | ibp->z_port_rcv_remphys_errors = |
| 1766 | cntrs.port_rcv_remphys_errors; |
| 1767 | ibp->z_port_xmit_discards = |
| 1768 | cntrs.port_xmit_discards; |
| 1769 | ibp->z_local_link_integrity_errors = |
| 1770 | cntrs.local_link_integrity_errors; |
| 1771 | ibp->z_excessive_buffer_overrun_errors = |
| 1772 | cntrs.excessive_buffer_overrun_errors; |
| 1773 | ibp->n_vl15_dropped = 0; |
| 1774 | ibp->z_vl15_dropped = cntrs.vl15_dropped; |
| 1775 | } |
| 1776 | |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1780 | static int pma_set_portcounters_ext(struct ib_pma_mad *pmp, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1781 | struct ib_device *ibdev, u8 port) |
| 1782 | { |
| 1783 | struct ib_pma_portcounters *p = (struct ib_pma_portcounters *) |
| 1784 | pmp->data; |
| 1785 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1786 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1787 | u64 swords, rwords, spkts, rpkts, xwait; |
| 1788 | |
| 1789 | qib_snapshot_counters(ppd, &swords, &rwords, &spkts, &rpkts, &xwait); |
| 1790 | |
| 1791 | if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA) |
| 1792 | ibp->z_port_xmit_data = swords; |
| 1793 | |
| 1794 | if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA) |
| 1795 | ibp->z_port_rcv_data = rwords; |
| 1796 | |
| 1797 | if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS) |
| 1798 | ibp->z_port_xmit_packets = spkts; |
| 1799 | |
| 1800 | if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS) |
| 1801 | ibp->z_port_rcv_packets = rpkts; |
| 1802 | |
| 1803 | if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS) |
| 1804 | ibp->n_unicast_xmit = 0; |
| 1805 | |
| 1806 | if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS) |
| 1807 | ibp->n_unicast_rcv = 0; |
| 1808 | |
| 1809 | if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS) |
| 1810 | ibp->n_multicast_xmit = 0; |
| 1811 | |
| 1812 | if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS) |
| 1813 | ibp->n_multicast_rcv = 0; |
| 1814 | |
| 1815 | return pma_get_portcounters_ext(pmp, ibdev, port); |
| 1816 | } |
| 1817 | |
| 1818 | static int process_subn(struct ib_device *ibdev, int mad_flags, |
| 1819 | u8 port, struct ib_mad *in_mad, |
| 1820 | struct ib_mad *out_mad) |
| 1821 | { |
| 1822 | struct ib_smp *smp = (struct ib_smp *)out_mad; |
| 1823 | struct qib_ibport *ibp = to_iport(ibdev, port); |
| 1824 | struct qib_pportdata *ppd = ppd_from_ibp(ibp); |
| 1825 | int ret; |
| 1826 | |
| 1827 | *out_mad = *in_mad; |
| 1828 | if (smp->class_version != 1) { |
| 1829 | smp->status |= IB_SMP_UNSUP_VERSION; |
| 1830 | ret = reply(smp); |
| 1831 | goto bail; |
| 1832 | } |
| 1833 | |
| 1834 | ret = check_mkey(ibp, smp, mad_flags); |
| 1835 | if (ret) { |
| 1836 | u32 port_num = be32_to_cpu(smp->attr_mod); |
| 1837 | |
| 1838 | /* |
| 1839 | * If this is a get/set portinfo, we already check the |
| 1840 | * M_Key if the MAD is for another port and the M_Key |
| 1841 | * is OK on the receiving port. This check is needed |
| 1842 | * to increment the error counters when the M_Key |
| 1843 | * fails to match on *both* ports. |
| 1844 | */ |
| 1845 | if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO && |
| 1846 | (smp->method == IB_MGMT_METHOD_GET || |
| 1847 | smp->method == IB_MGMT_METHOD_SET) && |
| 1848 | port_num && port_num <= ibdev->phys_port_cnt && |
| 1849 | port != port_num) |
| 1850 | (void) check_mkey(to_iport(ibdev, port_num), smp, 0); |
| 1851 | goto bail; |
| 1852 | } |
| 1853 | |
| 1854 | switch (smp->method) { |
| 1855 | case IB_MGMT_METHOD_GET: |
| 1856 | switch (smp->attr_id) { |
| 1857 | case IB_SMP_ATTR_NODE_DESC: |
| 1858 | ret = subn_get_nodedescription(smp, ibdev); |
| 1859 | goto bail; |
| 1860 | case IB_SMP_ATTR_NODE_INFO: |
| 1861 | ret = subn_get_nodeinfo(smp, ibdev, port); |
| 1862 | goto bail; |
| 1863 | case IB_SMP_ATTR_GUID_INFO: |
| 1864 | ret = subn_get_guidinfo(smp, ibdev, port); |
| 1865 | goto bail; |
| 1866 | case IB_SMP_ATTR_PORT_INFO: |
| 1867 | ret = subn_get_portinfo(smp, ibdev, port); |
| 1868 | goto bail; |
| 1869 | case IB_SMP_ATTR_PKEY_TABLE: |
| 1870 | ret = subn_get_pkeytable(smp, ibdev, port); |
| 1871 | goto bail; |
| 1872 | case IB_SMP_ATTR_SL_TO_VL_TABLE: |
| 1873 | ret = subn_get_sl_to_vl(smp, ibdev, port); |
| 1874 | goto bail; |
| 1875 | case IB_SMP_ATTR_VL_ARB_TABLE: |
| 1876 | ret = subn_get_vl_arb(smp, ibdev, port); |
| 1877 | goto bail; |
| 1878 | case IB_SMP_ATTR_SM_INFO: |
| 1879 | if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) { |
| 1880 | ret = IB_MAD_RESULT_SUCCESS | |
| 1881 | IB_MAD_RESULT_CONSUMED; |
| 1882 | goto bail; |
| 1883 | } |
| 1884 | if (ibp->port_cap_flags & IB_PORT_SM) { |
| 1885 | ret = IB_MAD_RESULT_SUCCESS; |
| 1886 | goto bail; |
| 1887 | } |
| 1888 | /* FALLTHROUGH */ |
| 1889 | default: |
| 1890 | smp->status |= IB_SMP_UNSUP_METH_ATTR; |
| 1891 | ret = reply(smp); |
| 1892 | goto bail; |
| 1893 | } |
| 1894 | |
| 1895 | case IB_MGMT_METHOD_SET: |
| 1896 | switch (smp->attr_id) { |
| 1897 | case IB_SMP_ATTR_GUID_INFO: |
| 1898 | ret = subn_set_guidinfo(smp, ibdev, port); |
| 1899 | goto bail; |
| 1900 | case IB_SMP_ATTR_PORT_INFO: |
| 1901 | ret = subn_set_portinfo(smp, ibdev, port); |
| 1902 | goto bail; |
| 1903 | case IB_SMP_ATTR_PKEY_TABLE: |
| 1904 | ret = subn_set_pkeytable(smp, ibdev, port); |
| 1905 | goto bail; |
| 1906 | case IB_SMP_ATTR_SL_TO_VL_TABLE: |
| 1907 | ret = subn_set_sl_to_vl(smp, ibdev, port); |
| 1908 | goto bail; |
| 1909 | case IB_SMP_ATTR_VL_ARB_TABLE: |
| 1910 | ret = subn_set_vl_arb(smp, ibdev, port); |
| 1911 | goto bail; |
| 1912 | case IB_SMP_ATTR_SM_INFO: |
| 1913 | if (ibp->port_cap_flags & IB_PORT_SM_DISABLED) { |
| 1914 | ret = IB_MAD_RESULT_SUCCESS | |
| 1915 | IB_MAD_RESULT_CONSUMED; |
| 1916 | goto bail; |
| 1917 | } |
| 1918 | if (ibp->port_cap_flags & IB_PORT_SM) { |
| 1919 | ret = IB_MAD_RESULT_SUCCESS; |
| 1920 | goto bail; |
| 1921 | } |
| 1922 | /* FALLTHROUGH */ |
| 1923 | default: |
| 1924 | smp->status |= IB_SMP_UNSUP_METH_ATTR; |
| 1925 | ret = reply(smp); |
| 1926 | goto bail; |
| 1927 | } |
| 1928 | |
| 1929 | case IB_MGMT_METHOD_TRAP_REPRESS: |
| 1930 | if (smp->attr_id == IB_SMP_ATTR_NOTICE) |
| 1931 | ret = subn_trap_repress(smp, ibdev, port); |
| 1932 | else { |
| 1933 | smp->status |= IB_SMP_UNSUP_METH_ATTR; |
| 1934 | ret = reply(smp); |
| 1935 | } |
| 1936 | goto bail; |
| 1937 | |
| 1938 | case IB_MGMT_METHOD_TRAP: |
| 1939 | case IB_MGMT_METHOD_REPORT: |
| 1940 | case IB_MGMT_METHOD_REPORT_RESP: |
| 1941 | case IB_MGMT_METHOD_GET_RESP: |
| 1942 | /* |
| 1943 | * The ib_mad module will call us to process responses |
| 1944 | * before checking for other consumers. |
| 1945 | * Just tell the caller to process it normally. |
| 1946 | */ |
| 1947 | ret = IB_MAD_RESULT_SUCCESS; |
| 1948 | goto bail; |
| 1949 | |
| 1950 | case IB_MGMT_METHOD_SEND: |
| 1951 | if (ib_get_smp_direction(smp) && |
| 1952 | smp->attr_id == QIB_VENDOR_IPG) { |
| 1953 | ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PORT, |
| 1954 | smp->data[0]); |
| 1955 | ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
| 1956 | } else |
| 1957 | ret = IB_MAD_RESULT_SUCCESS; |
| 1958 | goto bail; |
| 1959 | |
| 1960 | default: |
| 1961 | smp->status |= IB_SMP_UNSUP_METHOD; |
| 1962 | ret = reply(smp); |
| 1963 | } |
| 1964 | |
| 1965 | bail: |
| 1966 | return ret; |
| 1967 | } |
| 1968 | |
| 1969 | static int process_perf(struct ib_device *ibdev, u8 port, |
| 1970 | struct ib_mad *in_mad, |
| 1971 | struct ib_mad *out_mad) |
| 1972 | { |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1973 | struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1974 | int ret; |
| 1975 | |
| 1976 | *out_mad = *in_mad; |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1977 | if (pmp->mad_hdr.class_version != 1) { |
| 1978 | pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1979 | ret = reply((struct ib_smp *) pmp); |
| 1980 | goto bail; |
| 1981 | } |
| 1982 | |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1983 | switch (pmp->mad_hdr.method) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1984 | case IB_MGMT_METHOD_GET: |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 1985 | switch (pmp->mad_hdr.attr_id) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1986 | case IB_PMA_CLASS_PORT_INFO: |
| 1987 | ret = pma_get_classportinfo(pmp, ibdev); |
| 1988 | goto bail; |
| 1989 | case IB_PMA_PORT_SAMPLES_CONTROL: |
| 1990 | ret = pma_get_portsamplescontrol(pmp, ibdev, port); |
| 1991 | goto bail; |
| 1992 | case IB_PMA_PORT_SAMPLES_RESULT: |
| 1993 | ret = pma_get_portsamplesresult(pmp, ibdev, port); |
| 1994 | goto bail; |
| 1995 | case IB_PMA_PORT_SAMPLES_RESULT_EXT: |
| 1996 | ret = pma_get_portsamplesresult_ext(pmp, ibdev, port); |
| 1997 | goto bail; |
| 1998 | case IB_PMA_PORT_COUNTERS: |
| 1999 | ret = pma_get_portcounters(pmp, ibdev, port); |
| 2000 | goto bail; |
| 2001 | case IB_PMA_PORT_COUNTERS_EXT: |
| 2002 | ret = pma_get_portcounters_ext(pmp, ibdev, port); |
| 2003 | goto bail; |
| 2004 | case IB_PMA_PORT_COUNTERS_CONG: |
| 2005 | ret = pma_get_portcounters_cong(pmp, ibdev, port); |
| 2006 | goto bail; |
| 2007 | default: |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 2008 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 2009 | ret = reply((struct ib_smp *) pmp); |
| 2010 | goto bail; |
| 2011 | } |
| 2012 | |
| 2013 | case IB_MGMT_METHOD_SET: |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 2014 | switch (pmp->mad_hdr.attr_id) { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 2015 | case IB_PMA_PORT_SAMPLES_CONTROL: |
| 2016 | ret = pma_set_portsamplescontrol(pmp, ibdev, port); |
| 2017 | goto bail; |
| 2018 | case IB_PMA_PORT_COUNTERS: |
| 2019 | ret = pma_set_portcounters(pmp, ibdev, port); |
| 2020 | goto bail; |
| 2021 | case IB_PMA_PORT_COUNTERS_EXT: |
| 2022 | ret = pma_set_portcounters_ext(pmp, ibdev, port); |
| 2023 | goto bail; |
| 2024 | case IB_PMA_PORT_COUNTERS_CONG: |
| 2025 | ret = pma_set_portcounters_cong(pmp, ibdev, port); |
| 2026 | goto bail; |
| 2027 | default: |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 2028 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 2029 | ret = reply((struct ib_smp *) pmp); |
| 2030 | goto bail; |
| 2031 | } |
| 2032 | |
| 2033 | case IB_MGMT_METHOD_TRAP: |
| 2034 | case IB_MGMT_METHOD_GET_RESP: |
| 2035 | /* |
| 2036 | * The ib_mad module will call us to process responses |
| 2037 | * before checking for other consumers. |
| 2038 | * Just tell the caller to process it normally. |
| 2039 | */ |
| 2040 | ret = IB_MAD_RESULT_SUCCESS; |
| 2041 | goto bail; |
| 2042 | |
| 2043 | default: |
Or Gerlitz | 6aea213 | 2011-07-05 15:46:29 +0000 | [diff] [blame] | 2044 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 2045 | ret = reply((struct ib_smp *) pmp); |
| 2046 | } |
| 2047 | |
| 2048 | bail: |
| 2049 | return ret; |
| 2050 | } |
| 2051 | |
| 2052 | /** |
| 2053 | * qib_process_mad - process an incoming MAD packet |
| 2054 | * @ibdev: the infiniband device this packet came in on |
| 2055 | * @mad_flags: MAD flags |
| 2056 | * @port: the port number this packet came in on |
| 2057 | * @in_wc: the work completion entry for this packet |
| 2058 | * @in_grh: the global route header for this packet |
| 2059 | * @in_mad: the incoming MAD |
| 2060 | * @out_mad: any outgoing MAD reply |
| 2061 | * |
| 2062 | * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not |
| 2063 | * interested in processing. |
| 2064 | * |
| 2065 | * Note that the verbs framework has already done the MAD sanity checks, |
| 2066 | * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE |
| 2067 | * MADs. |
| 2068 | * |
| 2069 | * This is called by the ib_mad module. |
| 2070 | */ |
| 2071 | int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port, |
| 2072 | struct ib_wc *in_wc, struct ib_grh *in_grh, |
| 2073 | struct ib_mad *in_mad, struct ib_mad *out_mad) |
| 2074 | { |
| 2075 | int ret; |
| 2076 | |
| 2077 | switch (in_mad->mad_hdr.mgmt_class) { |
| 2078 | case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: |
| 2079 | case IB_MGMT_CLASS_SUBN_LID_ROUTED: |
| 2080 | ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad); |
| 2081 | goto bail; |
| 2082 | |
| 2083 | case IB_MGMT_CLASS_PERF_MGMT: |
| 2084 | ret = process_perf(ibdev, port, in_mad, out_mad); |
| 2085 | goto bail; |
| 2086 | |
| 2087 | default: |
| 2088 | ret = IB_MAD_RESULT_SUCCESS; |
| 2089 | } |
| 2090 | |
| 2091 | bail: |
| 2092 | return ret; |
| 2093 | } |
| 2094 | |
| 2095 | static void send_handler(struct ib_mad_agent *agent, |
| 2096 | struct ib_mad_send_wc *mad_send_wc) |
| 2097 | { |
| 2098 | ib_free_send_mad(mad_send_wc->send_buf); |
| 2099 | } |
| 2100 | |
| 2101 | static void xmit_wait_timer_func(unsigned long opaque) |
| 2102 | { |
| 2103 | struct qib_pportdata *ppd = (struct qib_pportdata *)opaque; |
| 2104 | struct qib_devdata *dd = dd_from_ppd(ppd); |
| 2105 | unsigned long flags; |
| 2106 | u8 status; |
| 2107 | |
| 2108 | spin_lock_irqsave(&ppd->ibport_data.lock, flags); |
| 2109 | if (ppd->cong_stats.flags == IB_PMA_CONG_HW_CONTROL_SAMPLE) { |
| 2110 | status = dd->f_portcntr(ppd, QIBPORTCNTR_PSSTAT); |
| 2111 | if (status == IB_PMA_SAMPLE_STATUS_DONE) { |
| 2112 | /* save counter cache */ |
| 2113 | cache_hw_sample_counters(ppd); |
| 2114 | ppd->cong_stats.flags = IB_PMA_CONG_HW_CONTROL_TIMER; |
| 2115 | } else |
| 2116 | goto done; |
| 2117 | } |
| 2118 | ppd->cong_stats.counter = xmit_wait_get_value_delta(ppd); |
| 2119 | dd->f_set_cntr_sample(ppd, QIB_CONG_TIMER_PSINTERVAL, 0x0); |
| 2120 | done: |
| 2121 | spin_unlock_irqrestore(&ppd->ibport_data.lock, flags); |
| 2122 | mod_timer(&ppd->cong_stats.timer, jiffies + HZ); |
| 2123 | } |
| 2124 | |
| 2125 | int qib_create_agents(struct qib_ibdev *dev) |
| 2126 | { |
| 2127 | struct qib_devdata *dd = dd_from_dev(dev); |
| 2128 | struct ib_mad_agent *agent; |
| 2129 | struct qib_ibport *ibp; |
| 2130 | int p; |
| 2131 | int ret; |
| 2132 | |
| 2133 | for (p = 0; p < dd->num_pports; p++) { |
| 2134 | ibp = &dd->pport[p].ibport_data; |
| 2135 | agent = ib_register_mad_agent(&dev->ibdev, p + 1, IB_QPT_SMI, |
| 2136 | NULL, 0, send_handler, |
| 2137 | NULL, NULL); |
| 2138 | if (IS_ERR(agent)) { |
| 2139 | ret = PTR_ERR(agent); |
| 2140 | goto err; |
| 2141 | } |
| 2142 | |
| 2143 | /* Initialize xmit_wait structure */ |
| 2144 | dd->pport[p].cong_stats.counter = 0; |
| 2145 | init_timer(&dd->pport[p].cong_stats.timer); |
| 2146 | dd->pport[p].cong_stats.timer.function = xmit_wait_timer_func; |
| 2147 | dd->pport[p].cong_stats.timer.data = |
| 2148 | (unsigned long)(&dd->pport[p]); |
| 2149 | dd->pport[p].cong_stats.timer.expires = 0; |
| 2150 | add_timer(&dd->pport[p].cong_stats.timer); |
| 2151 | |
| 2152 | ibp->send_agent = agent; |
| 2153 | } |
| 2154 | |
| 2155 | return 0; |
| 2156 | |
| 2157 | err: |
| 2158 | for (p = 0; p < dd->num_pports; p++) { |
| 2159 | ibp = &dd->pport[p].ibport_data; |
| 2160 | if (ibp->send_agent) { |
| 2161 | agent = ibp->send_agent; |
| 2162 | ibp->send_agent = NULL; |
| 2163 | ib_unregister_mad_agent(agent); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | return ret; |
| 2168 | } |
| 2169 | |
| 2170 | void qib_free_agents(struct qib_ibdev *dev) |
| 2171 | { |
| 2172 | struct qib_devdata *dd = dd_from_dev(dev); |
| 2173 | struct ib_mad_agent *agent; |
| 2174 | struct qib_ibport *ibp; |
| 2175 | int p; |
| 2176 | |
| 2177 | for (p = 0; p < dd->num_pports; p++) { |
| 2178 | ibp = &dd->pport[p].ibport_data; |
| 2179 | if (ibp->send_agent) { |
| 2180 | agent = ibp->send_agent; |
| 2181 | ibp->send_agent = NULL; |
| 2182 | ib_unregister_mad_agent(agent); |
| 2183 | } |
| 2184 | if (ibp->sm_ah) { |
| 2185 | ib_destroy_ah(&ibp->sm_ah->ibah); |
| 2186 | ibp->sm_ah = NULL; |
| 2187 | } |
| 2188 | if (dd->pport[p].cong_stats.timer.data) |
| 2189 | del_timer_sync(&dd->pport[p].cong_stats.timer); |
| 2190 | } |
| 2191 | } |