Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 1 | /* |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2012 Intel Corporation. All rights reserved. |
| 3 | * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved. |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 4 | * Copyright (c) 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 | #include <linux/ctype.h> |
| 35 | |
| 36 | #include "qib.h" |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 37 | #include "qib_mad.h" |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * qib_parse_ushort - parse an unsigned short value in an arbitrary base |
| 41 | * @str: the string containing the number |
| 42 | * @valp: where to put the result |
| 43 | * |
| 44 | * Returns the number of bytes consumed, or negative value on error. |
| 45 | */ |
| 46 | static int qib_parse_ushort(const char *str, unsigned short *valp) |
| 47 | { |
| 48 | unsigned long val; |
| 49 | char *end; |
| 50 | int ret; |
| 51 | |
| 52 | if (!isdigit(str[0])) { |
| 53 | ret = -EINVAL; |
| 54 | goto bail; |
| 55 | } |
| 56 | |
| 57 | val = simple_strtoul(str, &end, 0); |
| 58 | |
| 59 | if (val > 0xffff) { |
| 60 | ret = -EINVAL; |
| 61 | goto bail; |
| 62 | } |
| 63 | |
| 64 | *valp = val; |
| 65 | |
| 66 | ret = end + 1 - str; |
| 67 | if (ret == 0) |
| 68 | ret = -EINVAL; |
| 69 | |
| 70 | bail: |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | /* start of per-port functions */ |
| 75 | /* |
| 76 | * Get/Set heartbeat enable. OR of 1=enabled, 2=auto |
| 77 | */ |
| 78 | static ssize_t show_hrtbt_enb(struct qib_pportdata *ppd, char *buf) |
| 79 | { |
| 80 | struct qib_devdata *dd = ppd->dd; |
| 81 | int ret; |
| 82 | |
| 83 | ret = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_HRTBT); |
| 84 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | static ssize_t store_hrtbt_enb(struct qib_pportdata *ppd, const char *buf, |
| 89 | size_t count) |
| 90 | { |
| 91 | struct qib_devdata *dd = ppd->dd; |
| 92 | int ret; |
| 93 | u16 val; |
| 94 | |
| 95 | ret = qib_parse_ushort(buf, &val); |
| 96 | |
| 97 | /* |
| 98 | * Set the "intentional" heartbeat enable per either of |
| 99 | * "Enable" and "Auto", as these are normally set together. |
| 100 | * This bit is consulted when leaving loopback mode, |
| 101 | * because entering loopback mode overrides it and automatically |
| 102 | * disables heartbeat. |
| 103 | */ |
| 104 | if (ret >= 0) |
| 105 | ret = dd->f_set_ib_cfg(ppd, QIB_IB_CFG_HRTBT, val); |
| 106 | if (ret < 0) |
| 107 | qib_dev_err(dd, "attempt to set invalid Heartbeat enable\n"); |
| 108 | return ret < 0 ? ret : count; |
| 109 | } |
| 110 | |
| 111 | static ssize_t store_loopback(struct qib_pportdata *ppd, const char *buf, |
| 112 | size_t count) |
| 113 | { |
| 114 | struct qib_devdata *dd = ppd->dd; |
| 115 | int ret = count, r; |
| 116 | |
| 117 | r = dd->f_set_ib_loopback(ppd, buf); |
| 118 | if (r < 0) |
| 119 | ret = r; |
| 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | static ssize_t store_led_override(struct qib_pportdata *ppd, const char *buf, |
| 125 | size_t count) |
| 126 | { |
| 127 | struct qib_devdata *dd = ppd->dd; |
| 128 | int ret; |
| 129 | u16 val; |
| 130 | |
| 131 | ret = qib_parse_ushort(buf, &val); |
| 132 | if (ret > 0) |
| 133 | qib_set_led_override(ppd, val); |
| 134 | else |
| 135 | qib_dev_err(dd, "attempt to set invalid LED override\n"); |
| 136 | return ret < 0 ? ret : count; |
| 137 | } |
| 138 | |
| 139 | static ssize_t show_status(struct qib_pportdata *ppd, char *buf) |
| 140 | { |
| 141 | ssize_t ret; |
| 142 | |
| 143 | if (!ppd->statusp) |
| 144 | ret = -EINVAL; |
| 145 | else |
| 146 | ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n", |
| 147 | (unsigned long long) *(ppd->statusp)); |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * For userland compatibility, these offsets must remain fixed. |
| 153 | * They are strings for QIB_STATUS_* |
| 154 | */ |
Mike Marciniszyn | 865b64b | 2011-11-09 13:35:55 -0500 | [diff] [blame] | 155 | static const char * const qib_status_str[] = { |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 156 | "Initted", |
| 157 | "", |
| 158 | "", |
| 159 | "", |
| 160 | "", |
| 161 | "Present", |
| 162 | "IB_link_up", |
| 163 | "IB_configured", |
| 164 | "", |
| 165 | "Fatal_Hardware_Error", |
| 166 | NULL, |
| 167 | }; |
| 168 | |
| 169 | static ssize_t show_status_str(struct qib_pportdata *ppd, char *buf) |
| 170 | { |
| 171 | int i, any; |
| 172 | u64 s; |
| 173 | ssize_t ret; |
| 174 | |
| 175 | if (!ppd->statusp) { |
| 176 | ret = -EINVAL; |
| 177 | goto bail; |
| 178 | } |
| 179 | |
| 180 | s = *(ppd->statusp); |
| 181 | *buf = '\0'; |
| 182 | for (any = i = 0; s && qib_status_str[i]; i++) { |
| 183 | if (s & 1) { |
| 184 | /* if overflow */ |
| 185 | if (any && strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE) |
| 186 | break; |
| 187 | if (strlcat(buf, qib_status_str[i], PAGE_SIZE) >= |
| 188 | PAGE_SIZE) |
| 189 | break; |
| 190 | any = 1; |
| 191 | } |
| 192 | s >>= 1; |
| 193 | } |
| 194 | if (any) |
| 195 | strlcat(buf, "\n", PAGE_SIZE); |
| 196 | |
| 197 | ret = strlen(buf); |
| 198 | |
| 199 | bail: |
| 200 | return ret; |
| 201 | } |
| 202 | |
| 203 | /* end of per-port functions */ |
| 204 | |
| 205 | /* |
| 206 | * Start of per-port file structures and support code |
| 207 | * Because we are fitting into other infrastructure, we have to supply the |
| 208 | * full set of kobject/sysfs_ops structures and routines. |
| 209 | */ |
| 210 | #define QIB_PORT_ATTR(name, mode, show, store) \ |
| 211 | static struct qib_port_attr qib_port_attr_##name = \ |
| 212 | __ATTR(name, mode, show, store) |
| 213 | |
| 214 | struct qib_port_attr { |
| 215 | struct attribute attr; |
| 216 | ssize_t (*show)(struct qib_pportdata *, char *); |
| 217 | ssize_t (*store)(struct qib_pportdata *, const char *, size_t); |
| 218 | }; |
| 219 | |
| 220 | QIB_PORT_ATTR(loopback, S_IWUSR, NULL, store_loopback); |
| 221 | QIB_PORT_ATTR(led_override, S_IWUSR, NULL, store_led_override); |
| 222 | QIB_PORT_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb, |
| 223 | store_hrtbt_enb); |
| 224 | QIB_PORT_ATTR(status, S_IRUGO, show_status, NULL); |
| 225 | QIB_PORT_ATTR(status_str, S_IRUGO, show_status_str, NULL); |
| 226 | |
| 227 | static struct attribute *port_default_attributes[] = { |
| 228 | &qib_port_attr_loopback.attr, |
| 229 | &qib_port_attr_led_override.attr, |
| 230 | &qib_port_attr_hrtbt_enable.attr, |
| 231 | &qib_port_attr_status.attr, |
| 232 | &qib_port_attr_status_str.attr, |
| 233 | NULL |
| 234 | }; |
| 235 | |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 236 | /* |
| 237 | * Start of per-port congestion control structures and support code |
| 238 | */ |
| 239 | |
| 240 | /* |
| 241 | * Congestion control table size followed by table entries |
| 242 | */ |
| 243 | static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj, |
| 244 | struct bin_attribute *bin_attr, |
| 245 | char *buf, loff_t pos, size_t count) |
| 246 | { |
| 247 | int ret; |
| 248 | struct qib_pportdata *ppd = |
| 249 | container_of(kobj, struct qib_pportdata, pport_cc_kobj); |
| 250 | |
| 251 | if (!qib_cc_table_size || !ppd->ccti_entries_shadow) |
| 252 | return -EINVAL; |
| 253 | |
| 254 | ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow) |
| 255 | + sizeof(__be16); |
| 256 | |
| 257 | if (pos > ret) |
| 258 | return -EINVAL; |
| 259 | |
| 260 | if (count > ret - pos) |
| 261 | count = ret - pos; |
| 262 | |
| 263 | if (!count) |
| 264 | return count; |
| 265 | |
| 266 | spin_lock(&ppd->cc_shadow_lock); |
| 267 | memcpy(buf, ppd->ccti_entries_shadow, count); |
| 268 | spin_unlock(&ppd->cc_shadow_lock); |
| 269 | |
| 270 | return count; |
| 271 | } |
| 272 | |
| 273 | static void qib_port_release(struct kobject *kobj) |
| 274 | { |
| 275 | /* nothing to do since memory is freed by qib_free_devdata() */ |
| 276 | } |
| 277 | |
| 278 | static struct kobj_type qib_port_cc_ktype = { |
| 279 | .release = qib_port_release, |
| 280 | }; |
| 281 | |
| 282 | static struct bin_attribute cc_table_bin_attr = { |
| 283 | .attr = {.name = "cc_table_bin", .mode = 0444}, |
| 284 | .read = read_cc_table_bin, |
| 285 | .size = PAGE_SIZE, |
| 286 | }; |
| 287 | |
| 288 | /* |
| 289 | * Congestion settings: port control, control map and an array of 16 |
| 290 | * entries for the congestion entries - increase, timer, event log |
| 291 | * trigger threshold and the minimum injection rate delay. |
| 292 | */ |
| 293 | static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj, |
| 294 | struct bin_attribute *bin_attr, |
| 295 | char *buf, loff_t pos, size_t count) |
| 296 | { |
| 297 | int ret; |
| 298 | struct qib_pportdata *ppd = |
| 299 | container_of(kobj, struct qib_pportdata, pport_cc_kobj); |
| 300 | |
| 301 | if (!qib_cc_table_size || !ppd->congestion_entries_shadow) |
| 302 | return -EINVAL; |
| 303 | |
| 304 | ret = sizeof(struct ib_cc_congestion_setting_attr_shadow); |
| 305 | |
| 306 | if (pos > ret) |
| 307 | return -EINVAL; |
| 308 | if (count > ret - pos) |
| 309 | count = ret - pos; |
| 310 | |
| 311 | if (!count) |
| 312 | return count; |
| 313 | |
| 314 | spin_lock(&ppd->cc_shadow_lock); |
| 315 | memcpy(buf, ppd->congestion_entries_shadow, count); |
| 316 | spin_unlock(&ppd->cc_shadow_lock); |
| 317 | |
| 318 | return count; |
| 319 | } |
| 320 | |
| 321 | static struct bin_attribute cc_setting_bin_attr = { |
| 322 | .attr = {.name = "cc_settings_bin", .mode = 0444}, |
| 323 | .read = read_cc_setting_bin, |
| 324 | .size = PAGE_SIZE, |
| 325 | }; |
| 326 | |
| 327 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 328 | static ssize_t qib_portattr_show(struct kobject *kobj, |
| 329 | struct attribute *attr, char *buf) |
| 330 | { |
| 331 | struct qib_port_attr *pattr = |
| 332 | container_of(attr, struct qib_port_attr, attr); |
| 333 | struct qib_pportdata *ppd = |
| 334 | container_of(kobj, struct qib_pportdata, pport_kobj); |
| 335 | |
| 336 | return pattr->show(ppd, buf); |
| 337 | } |
| 338 | |
| 339 | static ssize_t qib_portattr_store(struct kobject *kobj, |
| 340 | struct attribute *attr, const char *buf, size_t len) |
| 341 | { |
| 342 | struct qib_port_attr *pattr = |
| 343 | container_of(attr, struct qib_port_attr, attr); |
| 344 | struct qib_pportdata *ppd = |
| 345 | container_of(kobj, struct qib_pportdata, pport_kobj); |
| 346 | |
| 347 | return pattr->store(ppd, buf, len); |
| 348 | } |
| 349 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 350 | |
| 351 | static const struct sysfs_ops qib_port_ops = { |
| 352 | .show = qib_portattr_show, |
| 353 | .store = qib_portattr_store, |
| 354 | }; |
| 355 | |
| 356 | static struct kobj_type qib_port_ktype = { |
| 357 | .release = qib_port_release, |
| 358 | .sysfs_ops = &qib_port_ops, |
| 359 | .default_attrs = port_default_attributes |
| 360 | }; |
| 361 | |
| 362 | /* Start sl2vl */ |
| 363 | |
| 364 | #define QIB_SL2VL_ATTR(N) \ |
| 365 | static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \ |
| 366 | .attr = { .name = __stringify(N), .mode = 0444 }, \ |
| 367 | .sl = N \ |
| 368 | } |
| 369 | |
| 370 | struct qib_sl2vl_attr { |
| 371 | struct attribute attr; |
| 372 | int sl; |
| 373 | }; |
| 374 | |
| 375 | QIB_SL2VL_ATTR(0); |
| 376 | QIB_SL2VL_ATTR(1); |
| 377 | QIB_SL2VL_ATTR(2); |
| 378 | QIB_SL2VL_ATTR(3); |
| 379 | QIB_SL2VL_ATTR(4); |
| 380 | QIB_SL2VL_ATTR(5); |
| 381 | QIB_SL2VL_ATTR(6); |
| 382 | QIB_SL2VL_ATTR(7); |
| 383 | QIB_SL2VL_ATTR(8); |
| 384 | QIB_SL2VL_ATTR(9); |
| 385 | QIB_SL2VL_ATTR(10); |
| 386 | QIB_SL2VL_ATTR(11); |
| 387 | QIB_SL2VL_ATTR(12); |
| 388 | QIB_SL2VL_ATTR(13); |
| 389 | QIB_SL2VL_ATTR(14); |
| 390 | QIB_SL2VL_ATTR(15); |
| 391 | |
| 392 | static struct attribute *sl2vl_default_attributes[] = { |
| 393 | &qib_sl2vl_attr_0.attr, |
| 394 | &qib_sl2vl_attr_1.attr, |
| 395 | &qib_sl2vl_attr_2.attr, |
| 396 | &qib_sl2vl_attr_3.attr, |
| 397 | &qib_sl2vl_attr_4.attr, |
| 398 | &qib_sl2vl_attr_5.attr, |
| 399 | &qib_sl2vl_attr_6.attr, |
| 400 | &qib_sl2vl_attr_7.attr, |
| 401 | &qib_sl2vl_attr_8.attr, |
| 402 | &qib_sl2vl_attr_9.attr, |
| 403 | &qib_sl2vl_attr_10.attr, |
| 404 | &qib_sl2vl_attr_11.attr, |
| 405 | &qib_sl2vl_attr_12.attr, |
| 406 | &qib_sl2vl_attr_13.attr, |
| 407 | &qib_sl2vl_attr_14.attr, |
| 408 | &qib_sl2vl_attr_15.attr, |
| 409 | NULL |
| 410 | }; |
| 411 | |
| 412 | static ssize_t sl2vl_attr_show(struct kobject *kobj, struct attribute *attr, |
| 413 | char *buf) |
| 414 | { |
| 415 | struct qib_sl2vl_attr *sattr = |
| 416 | container_of(attr, struct qib_sl2vl_attr, attr); |
| 417 | struct qib_pportdata *ppd = |
| 418 | container_of(kobj, struct qib_pportdata, sl2vl_kobj); |
| 419 | struct qib_ibport *qibp = &ppd->ibport_data; |
| 420 | |
| 421 | return sprintf(buf, "%u\n", qibp->sl_to_vl[sattr->sl]); |
| 422 | } |
| 423 | |
| 424 | static const struct sysfs_ops qib_sl2vl_ops = { |
| 425 | .show = sl2vl_attr_show, |
| 426 | }; |
| 427 | |
| 428 | static struct kobj_type qib_sl2vl_ktype = { |
| 429 | .release = qib_port_release, |
| 430 | .sysfs_ops = &qib_sl2vl_ops, |
| 431 | .default_attrs = sl2vl_default_attributes |
| 432 | }; |
| 433 | |
| 434 | /* End sl2vl */ |
| 435 | |
| 436 | /* Start diag_counters */ |
| 437 | |
| 438 | #define QIB_DIAGC_ATTR(N) \ |
| 439 | static struct qib_diagc_attr qib_diagc_attr_##N = { \ |
Ira Weiny | 4c6931f | 2010-07-14 01:53:18 +0000 | [diff] [blame] | 440 | .attr = { .name = __stringify(N), .mode = 0664 }, \ |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 441 | .counter = offsetof(struct qib_ibport, n_##N) \ |
| 442 | } |
| 443 | |
| 444 | struct qib_diagc_attr { |
| 445 | struct attribute attr; |
| 446 | size_t counter; |
| 447 | }; |
| 448 | |
| 449 | QIB_DIAGC_ATTR(rc_resends); |
| 450 | QIB_DIAGC_ATTR(rc_acks); |
| 451 | QIB_DIAGC_ATTR(rc_qacks); |
| 452 | QIB_DIAGC_ATTR(rc_delayed_comp); |
| 453 | QIB_DIAGC_ATTR(seq_naks); |
| 454 | QIB_DIAGC_ATTR(rdma_seq); |
| 455 | QIB_DIAGC_ATTR(rnr_naks); |
| 456 | QIB_DIAGC_ATTR(other_naks); |
| 457 | QIB_DIAGC_ATTR(rc_timeouts); |
| 458 | QIB_DIAGC_ATTR(loop_pkts); |
| 459 | QIB_DIAGC_ATTR(pkt_drops); |
| 460 | QIB_DIAGC_ATTR(dmawait); |
| 461 | QIB_DIAGC_ATTR(unaligned); |
| 462 | QIB_DIAGC_ATTR(rc_dupreq); |
| 463 | QIB_DIAGC_ATTR(rc_seqnak); |
| 464 | |
| 465 | static struct attribute *diagc_default_attributes[] = { |
| 466 | &qib_diagc_attr_rc_resends.attr, |
| 467 | &qib_diagc_attr_rc_acks.attr, |
| 468 | &qib_diagc_attr_rc_qacks.attr, |
| 469 | &qib_diagc_attr_rc_delayed_comp.attr, |
| 470 | &qib_diagc_attr_seq_naks.attr, |
| 471 | &qib_diagc_attr_rdma_seq.attr, |
| 472 | &qib_diagc_attr_rnr_naks.attr, |
| 473 | &qib_diagc_attr_other_naks.attr, |
| 474 | &qib_diagc_attr_rc_timeouts.attr, |
| 475 | &qib_diagc_attr_loop_pkts.attr, |
| 476 | &qib_diagc_attr_pkt_drops.attr, |
| 477 | &qib_diagc_attr_dmawait.attr, |
| 478 | &qib_diagc_attr_unaligned.attr, |
| 479 | &qib_diagc_attr_rc_dupreq.attr, |
| 480 | &qib_diagc_attr_rc_seqnak.attr, |
| 481 | NULL |
| 482 | }; |
| 483 | |
| 484 | static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr, |
| 485 | char *buf) |
| 486 | { |
| 487 | struct qib_diagc_attr *dattr = |
| 488 | container_of(attr, struct qib_diagc_attr, attr); |
| 489 | struct qib_pportdata *ppd = |
| 490 | container_of(kobj, struct qib_pportdata, diagc_kobj); |
| 491 | struct qib_ibport *qibp = &ppd->ibport_data; |
| 492 | |
| 493 | return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter)); |
| 494 | } |
| 495 | |
Ira Weiny | 4c6931f | 2010-07-14 01:53:18 +0000 | [diff] [blame] | 496 | static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr, |
| 497 | const char *buf, size_t size) |
| 498 | { |
| 499 | struct qib_diagc_attr *dattr = |
| 500 | container_of(attr, struct qib_diagc_attr, attr); |
| 501 | struct qib_pportdata *ppd = |
| 502 | container_of(kobj, struct qib_pportdata, diagc_kobj); |
| 503 | struct qib_ibport *qibp = &ppd->ibport_data; |
| 504 | char *endp; |
| 505 | long val = simple_strtol(buf, &endp, 0); |
| 506 | |
| 507 | if (val < 0 || endp == buf) |
| 508 | return -EINVAL; |
| 509 | |
| 510 | *(u32 *)((char *) qibp + dattr->counter) = val; |
| 511 | return size; |
| 512 | } |
| 513 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 514 | static const struct sysfs_ops qib_diagc_ops = { |
| 515 | .show = diagc_attr_show, |
Ira Weiny | 4c6931f | 2010-07-14 01:53:18 +0000 | [diff] [blame] | 516 | .store = diagc_attr_store, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | static struct kobj_type qib_diagc_ktype = { |
| 520 | .release = qib_port_release, |
| 521 | .sysfs_ops = &qib_diagc_ops, |
| 522 | .default_attrs = diagc_default_attributes |
| 523 | }; |
| 524 | |
| 525 | /* End diag_counters */ |
| 526 | |
| 527 | /* end of per-port file structures and support code */ |
| 528 | |
| 529 | /* |
| 530 | * Start of per-unit (or driver, in some cases, but replicated |
| 531 | * per unit) functions (these get a device *) |
| 532 | */ |
| 533 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 534 | char *buf) |
| 535 | { |
| 536 | struct qib_ibdev *dev = |
| 537 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 538 | |
| 539 | return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); |
| 540 | } |
| 541 | |
| 542 | static ssize_t show_hca(struct device *device, struct device_attribute *attr, |
| 543 | char *buf) |
| 544 | { |
| 545 | struct qib_ibdev *dev = |
| 546 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 547 | struct qib_devdata *dd = dd_from_dev(dev); |
| 548 | int ret; |
| 549 | |
| 550 | if (!dd->boardname) |
| 551 | ret = -EINVAL; |
| 552 | else |
| 553 | ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname); |
| 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | static ssize_t show_version(struct device *device, |
| 558 | struct device_attribute *attr, char *buf) |
| 559 | { |
| 560 | /* The string printed here is already newline-terminated. */ |
| 561 | return scnprintf(buf, PAGE_SIZE, "%s", (char *)ib_qib_version); |
| 562 | } |
| 563 | |
| 564 | static ssize_t show_boardversion(struct device *device, |
| 565 | struct device_attribute *attr, char *buf) |
| 566 | { |
| 567 | struct qib_ibdev *dev = |
| 568 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 569 | struct qib_devdata *dd = dd_from_dev(dev); |
| 570 | |
| 571 | /* The string printed here is already newline-terminated. */ |
| 572 | return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | static ssize_t show_localbus_info(struct device *device, |
| 577 | struct device_attribute *attr, char *buf) |
| 578 | { |
| 579 | struct qib_ibdev *dev = |
| 580 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 581 | struct qib_devdata *dd = dd_from_dev(dev); |
| 582 | |
| 583 | /* The string printed here is already newline-terminated. */ |
| 584 | return scnprintf(buf, PAGE_SIZE, "%s", dd->lbus_info); |
| 585 | } |
| 586 | |
| 587 | |
| 588 | static ssize_t show_nctxts(struct device *device, |
| 589 | struct device_attribute *attr, char *buf) |
| 590 | { |
| 591 | struct qib_ibdev *dev = |
| 592 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 593 | struct qib_devdata *dd = dd_from_dev(dev); |
| 594 | |
| 595 | /* Return the number of user ports (contexts) available. */ |
Mitko Haralanov | 6ceaade | 2012-05-07 14:03:02 -0400 | [diff] [blame] | 596 | /* The calculation below deals with a special case where |
| 597 | * cfgctxts is set to 1 on a single-port board. */ |
| 598 | return scnprintf(buf, PAGE_SIZE, "%u\n", |
| 599 | (dd->first_user_ctxt > dd->cfgctxts) ? 0 : |
| 600 | (dd->cfgctxts - dd->first_user_ctxt)); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Ram Vepa | 2df4f75 | 2011-05-31 20:20:43 +0000 | [diff] [blame] | 603 | static ssize_t show_nfreectxts(struct device *device, |
| 604 | struct device_attribute *attr, char *buf) |
| 605 | { |
| 606 | struct qib_ibdev *dev = |
| 607 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 608 | struct qib_devdata *dd = dd_from_dev(dev); |
| 609 | |
| 610 | /* Return the number of free user ports (contexts) available. */ |
Mike Marciniszyn | 53ab1c6 | 2011-10-06 09:33:35 -0700 | [diff] [blame] | 611 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts); |
Ram Vepa | 2df4f75 | 2011-05-31 20:20:43 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 614 | static ssize_t show_serial(struct device *device, |
| 615 | struct device_attribute *attr, char *buf) |
| 616 | { |
| 617 | struct qib_ibdev *dev = |
| 618 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 619 | struct qib_devdata *dd = dd_from_dev(dev); |
| 620 | |
| 621 | buf[sizeof dd->serial] = '\0'; |
| 622 | memcpy(buf, dd->serial, sizeof dd->serial); |
| 623 | strcat(buf, "\n"); |
| 624 | return strlen(buf); |
| 625 | } |
| 626 | |
| 627 | static ssize_t store_chip_reset(struct device *device, |
| 628 | struct device_attribute *attr, const char *buf, |
| 629 | size_t count) |
| 630 | { |
| 631 | struct qib_ibdev *dev = |
| 632 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 633 | struct qib_devdata *dd = dd_from_dev(dev); |
| 634 | int ret; |
| 635 | |
| 636 | if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) { |
| 637 | ret = -EINVAL; |
| 638 | goto bail; |
| 639 | } |
| 640 | |
| 641 | ret = qib_reset_device(dd->unit); |
| 642 | bail: |
| 643 | return ret < 0 ? ret : count; |
| 644 | } |
| 645 | |
| 646 | static ssize_t show_logged_errs(struct device *device, |
| 647 | struct device_attribute *attr, char *buf) |
| 648 | { |
| 649 | struct qib_ibdev *dev = |
| 650 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 651 | struct qib_devdata *dd = dd_from_dev(dev); |
| 652 | int idx, count; |
| 653 | |
| 654 | /* force consistency with actual EEPROM */ |
| 655 | if (qib_update_eeprom_log(dd) != 0) |
| 656 | return -ENXIO; |
| 657 | |
| 658 | count = 0; |
| 659 | for (idx = 0; idx < QIB_EEP_LOG_CNT; ++idx) { |
| 660 | count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c", |
| 661 | dd->eep_st_errs[idx], |
| 662 | idx == (QIB_EEP_LOG_CNT - 1) ? '\n' : ' '); |
| 663 | } |
| 664 | |
| 665 | return count; |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Dump tempsense regs. in decimal, to ease shell-scripts. |
| 670 | */ |
| 671 | static ssize_t show_tempsense(struct device *device, |
| 672 | struct device_attribute *attr, char *buf) |
| 673 | { |
| 674 | struct qib_ibdev *dev = |
| 675 | container_of(device, struct qib_ibdev, ibdev.dev); |
| 676 | struct qib_devdata *dd = dd_from_dev(dev); |
| 677 | int ret; |
| 678 | int idx; |
| 679 | u8 regvals[8]; |
| 680 | |
| 681 | ret = -ENXIO; |
| 682 | for (idx = 0; idx < 8; ++idx) { |
| 683 | if (idx == 6) |
| 684 | continue; |
| 685 | ret = dd->f_tempsense_rd(dd, idx); |
| 686 | if (ret < 0) |
| 687 | break; |
| 688 | regvals[idx] = ret; |
| 689 | } |
| 690 | if (idx == 8) |
| 691 | ret = scnprintf(buf, PAGE_SIZE, "%d %d %02X %02X %d %d\n", |
| 692 | *(signed char *)(regvals), |
| 693 | *(signed char *)(regvals + 1), |
| 694 | regvals[2], regvals[3], |
| 695 | *(signed char *)(regvals + 5), |
| 696 | *(signed char *)(regvals + 7)); |
| 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * end of per-unit (or driver, in some cases, but replicated |
| 702 | * per unit) functions |
| 703 | */ |
| 704 | |
| 705 | /* start of per-unit file structures and support code */ |
| 706 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 707 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 708 | static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL); |
| 709 | static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); |
| 710 | static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL); |
Ram Vepa | 2df4f75 | 2011-05-31 20:20:43 +0000 | [diff] [blame] | 711 | static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 712 | static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); |
| 713 | static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); |
| 714 | static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL); |
| 715 | static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL); |
| 716 | static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL); |
| 717 | static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset); |
| 718 | |
| 719 | static struct device_attribute *qib_attributes[] = { |
| 720 | &dev_attr_hw_rev, |
| 721 | &dev_attr_hca_type, |
| 722 | &dev_attr_board_id, |
| 723 | &dev_attr_version, |
| 724 | &dev_attr_nctxts, |
Ram Vepa | 2df4f75 | 2011-05-31 20:20:43 +0000 | [diff] [blame] | 725 | &dev_attr_nfreectxts, |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 726 | &dev_attr_serial, |
| 727 | &dev_attr_boardversion, |
| 728 | &dev_attr_logged_errors, |
| 729 | &dev_attr_tempsense, |
| 730 | &dev_attr_localbus_info, |
| 731 | &dev_attr_chip_reset, |
| 732 | }; |
| 733 | |
| 734 | int qib_create_port_files(struct ib_device *ibdev, u8 port_num, |
| 735 | struct kobject *kobj) |
| 736 | { |
| 737 | struct qib_pportdata *ppd; |
| 738 | struct qib_devdata *dd = dd_from_ibdev(ibdev); |
| 739 | int ret; |
| 740 | |
| 741 | if (!port_num || port_num > dd->num_pports) { |
| 742 | qib_dev_err(dd, "Skipping infiniband class with " |
| 743 | "invalid port %u\n", port_num); |
| 744 | ret = -ENODEV; |
| 745 | goto bail; |
| 746 | } |
| 747 | ppd = &dd->pport[port_num - 1]; |
| 748 | |
| 749 | ret = kobject_init_and_add(&ppd->pport_kobj, &qib_port_ktype, kobj, |
| 750 | "linkcontrol"); |
| 751 | if (ret) { |
| 752 | qib_dev_err(dd, "Skipping linkcontrol sysfs info, " |
| 753 | "(err %d) port %u\n", ret, port_num); |
| 754 | goto bail; |
| 755 | } |
| 756 | kobject_uevent(&ppd->pport_kobj, KOBJ_ADD); |
| 757 | |
| 758 | ret = kobject_init_and_add(&ppd->sl2vl_kobj, &qib_sl2vl_ktype, kobj, |
| 759 | "sl2vl"); |
| 760 | if (ret) { |
| 761 | qib_dev_err(dd, "Skipping sl2vl sysfs info, " |
| 762 | "(err %d) port %u\n", ret, port_num); |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 763 | goto bail_link; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 764 | } |
| 765 | kobject_uevent(&ppd->sl2vl_kobj, KOBJ_ADD); |
| 766 | |
| 767 | ret = kobject_init_and_add(&ppd->diagc_kobj, &qib_diagc_ktype, kobj, |
| 768 | "diag_counters"); |
| 769 | if (ret) { |
| 770 | qib_dev_err(dd, "Skipping diag_counters sysfs info, " |
| 771 | "(err %d) port %u\n", ret, port_num); |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 772 | goto bail_sl; |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 773 | } |
| 774 | kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD); |
| 775 | |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 776 | if (!qib_cc_table_size || !ppd->congestion_entries_shadow) |
| 777 | return 0; |
| 778 | |
| 779 | ret = kobject_init_and_add(&ppd->pport_cc_kobj, &qib_port_cc_ktype, |
| 780 | kobj, "CCMgtA"); |
| 781 | if (ret) { |
| 782 | qib_dev_err(dd, |
| 783 | "Skipping Congestion Control sysfs info, (err %d) port %u\n", |
| 784 | ret, port_num); |
| 785 | goto bail_diagc; |
| 786 | } |
| 787 | |
| 788 | kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD); |
| 789 | |
| 790 | ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, |
| 791 | &cc_setting_bin_attr); |
| 792 | if (ret) { |
| 793 | qib_dev_err(dd, |
| 794 | "Skipping Congestion Control setting sysfs info, (err %d) port %u\n", |
| 795 | ret, port_num); |
| 796 | goto bail_cc; |
| 797 | } |
| 798 | |
| 799 | ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, |
| 800 | &cc_table_bin_attr); |
| 801 | if (ret) { |
| 802 | qib_dev_err(dd, |
| 803 | "Skipping Congestion Control table sysfs info, (err %d) port %u\n", |
| 804 | ret, port_num); |
| 805 | goto bail_cc_entry_bin; |
| 806 | } |
| 807 | |
| 808 | qib_devinfo(dd->pcidev, |
| 809 | "IB%u: Congestion Control Agent enabled for port %d\n", |
| 810 | dd->unit, port_num); |
| 811 | |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 812 | return 0; |
| 813 | |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 814 | bail_cc_entry_bin: |
| 815 | sysfs_remove_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr); |
| 816 | bail_cc: |
| 817 | kobject_put(&ppd->pport_cc_kobj); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 818 | bail_diagc: |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 819 | kobject_put(&ppd->diagc_kobj); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 820 | bail_sl: |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 821 | kobject_put(&ppd->sl2vl_kobj); |
| 822 | bail_link: |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 823 | kobject_put(&ppd->pport_kobj); |
| 824 | bail: |
| 825 | return ret; |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | * Register and create our files in /sys/class/infiniband. |
| 830 | */ |
| 831 | int qib_verbs_register_sysfs(struct qib_devdata *dd) |
| 832 | { |
| 833 | struct ib_device *dev = &dd->verbs_dev.ibdev; |
| 834 | int i, ret; |
| 835 | |
| 836 | for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i) { |
| 837 | ret = device_create_file(&dev->dev, qib_attributes[i]); |
| 838 | if (ret) |
| 839 | return ret; |
| 840 | } |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | /* |
| 846 | * Unregister and remove our files in /sys/class/infiniband. |
| 847 | */ |
| 848 | void qib_verbs_unregister_sysfs(struct qib_devdata *dd) |
| 849 | { |
| 850 | struct qib_pportdata *ppd; |
| 851 | int i; |
| 852 | |
| 853 | for (i = 0; i < dd->num_pports; i++) { |
| 854 | ppd = &dd->pport[i]; |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 855 | if (qib_cc_table_size && |
| 856 | ppd->congestion_entries_shadow) { |
| 857 | sysfs_remove_bin_file(&ppd->pport_cc_kobj, |
| 858 | &cc_setting_bin_attr); |
| 859 | sysfs_remove_bin_file(&ppd->pport_cc_kobj, |
| 860 | &cc_table_bin_attr); |
| 861 | kobject_put(&ppd->pport_cc_kobj); |
| 862 | } |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 863 | kobject_put(&ppd->sl2vl_kobj); |
Mike Marciniszyn | 36a8f01 | 2012-07-19 13:04:04 +0000 | [diff] [blame^] | 864 | kobject_put(&ppd->pport_kobj); |
Ralph Campbell | f931551 | 2010-05-23 21:44:54 -0700 | [diff] [blame] | 865 | } |
| 866 | } |