2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2006 PathScale, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/ctype.h>
38 * qib_parse_ushort - parse an unsigned short value in an arbitrary base
39 * @str: the string containing the number
40 * @valp: where to put the result
42 * Returns the number of bytes consumed, or negative value on error.
44 static int qib_parse_ushort(const char *str
, unsigned short *valp
)
50 if (!isdigit(str
[0])) {
55 val
= simple_strtoul(str
, &end
, 0);
72 /* start of per-port functions */
74 * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
76 static ssize_t
show_hrtbt_enb(struct qib_pportdata
*ppd
, char *buf
)
78 struct qib_devdata
*dd
= ppd
->dd
;
81 ret
= dd
->f_get_ib_cfg(ppd
, QIB_IB_CFG_HRTBT
);
82 ret
= scnprintf(buf
, PAGE_SIZE
, "%d\n", ret
);
86 static ssize_t
store_hrtbt_enb(struct qib_pportdata
*ppd
, const char *buf
,
89 struct qib_devdata
*dd
= ppd
->dd
;
93 ret
= qib_parse_ushort(buf
, &val
);
96 * Set the "intentional" heartbeat enable per either of
97 * "Enable" and "Auto", as these are normally set together.
98 * This bit is consulted when leaving loopback mode,
99 * because entering loopback mode overrides it and automatically
100 * disables heartbeat.
103 ret
= dd
->f_set_ib_cfg(ppd
, QIB_IB_CFG_HRTBT
, val
);
105 qib_dev_err(dd
, "attempt to set invalid Heartbeat enable\n");
106 return ret
< 0 ? ret
: count
;
109 static ssize_t
store_loopback(struct qib_pportdata
*ppd
, const char *buf
,
112 struct qib_devdata
*dd
= ppd
->dd
;
115 r
= dd
->f_set_ib_loopback(ppd
, buf
);
122 static ssize_t
store_led_override(struct qib_pportdata
*ppd
, const char *buf
,
125 struct qib_devdata
*dd
= ppd
->dd
;
129 ret
= qib_parse_ushort(buf
, &val
);
131 qib_set_led_override(ppd
, val
);
133 qib_dev_err(dd
, "attempt to set invalid LED override\n");
134 return ret
< 0 ? ret
: count
;
137 static ssize_t
show_status(struct qib_pportdata
*ppd
, char *buf
)
144 ret
= scnprintf(buf
, PAGE_SIZE
, "0x%llx\n",
145 (unsigned long long) *(ppd
->statusp
));
150 * For userland compatibility, these offsets must remain fixed.
151 * They are strings for QIB_STATUS_*
153 static const char *qib_status_str
[] = {
163 "Fatal_Hardware_Error",
167 static ssize_t
show_status_str(struct qib_pportdata
*ppd
, char *buf
)
180 for (any
= i
= 0; s
&& qib_status_str
[i
]; i
++) {
183 if (any
&& strlcat(buf
, " ", PAGE_SIZE
) >= PAGE_SIZE
)
185 if (strlcat(buf
, qib_status_str
[i
], PAGE_SIZE
) >=
193 strlcat(buf
, "\n", PAGE_SIZE
);
201 /* end of per-port functions */
204 * Start of per-port file structures and support code
205 * Because we are fitting into other infrastructure, we have to supply the
206 * full set of kobject/sysfs_ops structures and routines.
208 #define QIB_PORT_ATTR(name, mode, show, store) \
209 static struct qib_port_attr qib_port_attr_##name = \
210 __ATTR(name, mode, show, store)
212 struct qib_port_attr
{
213 struct attribute attr
;
214 ssize_t (*show
)(struct qib_pportdata
*, char *);
215 ssize_t (*store
)(struct qib_pportdata
*, const char *, size_t);
218 QIB_PORT_ATTR(loopback
, S_IWUSR
, NULL
, store_loopback
);
219 QIB_PORT_ATTR(led_override
, S_IWUSR
, NULL
, store_led_override
);
220 QIB_PORT_ATTR(hrtbt_enable
, S_IWUSR
| S_IRUGO
, show_hrtbt_enb
,
222 QIB_PORT_ATTR(status
, S_IRUGO
, show_status
, NULL
);
223 QIB_PORT_ATTR(status_str
, S_IRUGO
, show_status_str
, NULL
);
225 static struct attribute
*port_default_attributes
[] = {
226 &qib_port_attr_loopback
.attr
,
227 &qib_port_attr_led_override
.attr
,
228 &qib_port_attr_hrtbt_enable
.attr
,
229 &qib_port_attr_status
.attr
,
230 &qib_port_attr_status_str
.attr
,
234 static ssize_t
qib_portattr_show(struct kobject
*kobj
,
235 struct attribute
*attr
, char *buf
)
237 struct qib_port_attr
*pattr
=
238 container_of(attr
, struct qib_port_attr
, attr
);
239 struct qib_pportdata
*ppd
=
240 container_of(kobj
, struct qib_pportdata
, pport_kobj
);
242 return pattr
->show(ppd
, buf
);
245 static ssize_t
qib_portattr_store(struct kobject
*kobj
,
246 struct attribute
*attr
, const char *buf
, size_t len
)
248 struct qib_port_attr
*pattr
=
249 container_of(attr
, struct qib_port_attr
, attr
);
250 struct qib_pportdata
*ppd
=
251 container_of(kobj
, struct qib_pportdata
, pport_kobj
);
253 return pattr
->store(ppd
, buf
, len
);
256 static void qib_port_release(struct kobject
*kobj
)
258 /* nothing to do since memory is freed by qib_free_devdata() */
261 static const struct sysfs_ops qib_port_ops
= {
262 .show
= qib_portattr_show
,
263 .store
= qib_portattr_store
,
266 static struct kobj_type qib_port_ktype
= {
267 .release
= qib_port_release
,
268 .sysfs_ops
= &qib_port_ops
,
269 .default_attrs
= port_default_attributes
274 #define QIB_SL2VL_ATTR(N) \
275 static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \
276 .attr = { .name = __stringify(N), .mode = 0444 }, \
280 struct qib_sl2vl_attr
{
281 struct attribute attr
;
302 static struct attribute
*sl2vl_default_attributes
[] = {
303 &qib_sl2vl_attr_0
.attr
,
304 &qib_sl2vl_attr_1
.attr
,
305 &qib_sl2vl_attr_2
.attr
,
306 &qib_sl2vl_attr_3
.attr
,
307 &qib_sl2vl_attr_4
.attr
,
308 &qib_sl2vl_attr_5
.attr
,
309 &qib_sl2vl_attr_6
.attr
,
310 &qib_sl2vl_attr_7
.attr
,
311 &qib_sl2vl_attr_8
.attr
,
312 &qib_sl2vl_attr_9
.attr
,
313 &qib_sl2vl_attr_10
.attr
,
314 &qib_sl2vl_attr_11
.attr
,
315 &qib_sl2vl_attr_12
.attr
,
316 &qib_sl2vl_attr_13
.attr
,
317 &qib_sl2vl_attr_14
.attr
,
318 &qib_sl2vl_attr_15
.attr
,
322 static ssize_t
sl2vl_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
325 struct qib_sl2vl_attr
*sattr
=
326 container_of(attr
, struct qib_sl2vl_attr
, attr
);
327 struct qib_pportdata
*ppd
=
328 container_of(kobj
, struct qib_pportdata
, sl2vl_kobj
);
329 struct qib_ibport
*qibp
= &ppd
->ibport_data
;
331 return sprintf(buf
, "%u\n", qibp
->sl_to_vl
[sattr
->sl
]);
334 static const struct sysfs_ops qib_sl2vl_ops
= {
335 .show
= sl2vl_attr_show
,
338 static struct kobj_type qib_sl2vl_ktype
= {
339 .release
= qib_port_release
,
340 .sysfs_ops
= &qib_sl2vl_ops
,
341 .default_attrs
= sl2vl_default_attributes
346 /* Start diag_counters */
348 #define QIB_DIAGC_ATTR(N) \
349 static struct qib_diagc_attr qib_diagc_attr_##N = { \
350 .attr = { .name = __stringify(N), .mode = 0664 }, \
351 .counter = offsetof(struct qib_ibport, n_##N) \
354 struct qib_diagc_attr
{
355 struct attribute attr
;
359 QIB_DIAGC_ATTR(rc_resends
);
360 QIB_DIAGC_ATTR(rc_acks
);
361 QIB_DIAGC_ATTR(rc_qacks
);
362 QIB_DIAGC_ATTR(rc_delayed_comp
);
363 QIB_DIAGC_ATTR(seq_naks
);
364 QIB_DIAGC_ATTR(rdma_seq
);
365 QIB_DIAGC_ATTR(rnr_naks
);
366 QIB_DIAGC_ATTR(other_naks
);
367 QIB_DIAGC_ATTR(rc_timeouts
);
368 QIB_DIAGC_ATTR(loop_pkts
);
369 QIB_DIAGC_ATTR(pkt_drops
);
370 QIB_DIAGC_ATTR(dmawait
);
371 QIB_DIAGC_ATTR(unaligned
);
372 QIB_DIAGC_ATTR(rc_dupreq
);
373 QIB_DIAGC_ATTR(rc_seqnak
);
375 static struct attribute
*diagc_default_attributes
[] = {
376 &qib_diagc_attr_rc_resends
.attr
,
377 &qib_diagc_attr_rc_acks
.attr
,
378 &qib_diagc_attr_rc_qacks
.attr
,
379 &qib_diagc_attr_rc_delayed_comp
.attr
,
380 &qib_diagc_attr_seq_naks
.attr
,
381 &qib_diagc_attr_rdma_seq
.attr
,
382 &qib_diagc_attr_rnr_naks
.attr
,
383 &qib_diagc_attr_other_naks
.attr
,
384 &qib_diagc_attr_rc_timeouts
.attr
,
385 &qib_diagc_attr_loop_pkts
.attr
,
386 &qib_diagc_attr_pkt_drops
.attr
,
387 &qib_diagc_attr_dmawait
.attr
,
388 &qib_diagc_attr_unaligned
.attr
,
389 &qib_diagc_attr_rc_dupreq
.attr
,
390 &qib_diagc_attr_rc_seqnak
.attr
,
394 static ssize_t
diagc_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
397 struct qib_diagc_attr
*dattr
=
398 container_of(attr
, struct qib_diagc_attr
, attr
);
399 struct qib_pportdata
*ppd
=
400 container_of(kobj
, struct qib_pportdata
, diagc_kobj
);
401 struct qib_ibport
*qibp
= &ppd
->ibport_data
;
403 return sprintf(buf
, "%u\n", *(u32
*)((char *)qibp
+ dattr
->counter
));
406 static ssize_t
diagc_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
407 const char *buf
, size_t size
)
409 struct qib_diagc_attr
*dattr
=
410 container_of(attr
, struct qib_diagc_attr
, attr
);
411 struct qib_pportdata
*ppd
=
412 container_of(kobj
, struct qib_pportdata
, diagc_kobj
);
413 struct qib_ibport
*qibp
= &ppd
->ibport_data
;
415 long val
= simple_strtol(buf
, &endp
, 0);
417 if (val
< 0 || endp
== buf
)
420 *(u32
*)((char *) qibp
+ dattr
->counter
) = val
;
424 static const struct sysfs_ops qib_diagc_ops
= {
425 .show
= diagc_attr_show
,
426 .store
= diagc_attr_store
,
429 static struct kobj_type qib_diagc_ktype
= {
430 .release
= qib_port_release
,
431 .sysfs_ops
= &qib_diagc_ops
,
432 .default_attrs
= diagc_default_attributes
435 /* End diag_counters */
437 /* end of per-port file structures and support code */
440 * Start of per-unit (or driver, in some cases, but replicated
441 * per unit) functions (these get a device *)
443 static ssize_t
show_rev(struct device
*device
, struct device_attribute
*attr
,
446 struct qib_ibdev
*dev
=
447 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
449 return sprintf(buf
, "%x\n", dd_from_dev(dev
)->minrev
);
452 static ssize_t
show_hca(struct device
*device
, struct device_attribute
*attr
,
455 struct qib_ibdev
*dev
=
456 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
457 struct qib_devdata
*dd
= dd_from_dev(dev
);
463 ret
= scnprintf(buf
, PAGE_SIZE
, "%s\n", dd
->boardname
);
467 static ssize_t
show_version(struct device
*device
,
468 struct device_attribute
*attr
, char *buf
)
470 /* The string printed here is already newline-terminated. */
471 return scnprintf(buf
, PAGE_SIZE
, "%s", (char *)ib_qib_version
);
474 static ssize_t
show_boardversion(struct device
*device
,
475 struct device_attribute
*attr
, char *buf
)
477 struct qib_ibdev
*dev
=
478 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
479 struct qib_devdata
*dd
= dd_from_dev(dev
);
481 /* The string printed here is already newline-terminated. */
482 return scnprintf(buf
, PAGE_SIZE
, "%s", dd
->boardversion
);
486 static ssize_t
show_localbus_info(struct device
*device
,
487 struct device_attribute
*attr
, char *buf
)
489 struct qib_ibdev
*dev
=
490 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
491 struct qib_devdata
*dd
= dd_from_dev(dev
);
493 /* The string printed here is already newline-terminated. */
494 return scnprintf(buf
, PAGE_SIZE
, "%s", dd
->lbus_info
);
498 static ssize_t
show_nctxts(struct device
*device
,
499 struct device_attribute
*attr
, char *buf
)
501 struct qib_ibdev
*dev
=
502 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
503 struct qib_devdata
*dd
= dd_from_dev(dev
);
505 /* Return the number of user ports (contexts) available. */
506 return scnprintf(buf
, PAGE_SIZE
, "%u\n", dd
->cfgctxts
-
507 dd
->first_user_ctxt
);
510 static ssize_t
show_serial(struct device
*device
,
511 struct device_attribute
*attr
, char *buf
)
513 struct qib_ibdev
*dev
=
514 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
515 struct qib_devdata
*dd
= dd_from_dev(dev
);
517 buf
[sizeof dd
->serial
] = '\0';
518 memcpy(buf
, dd
->serial
, sizeof dd
->serial
);
523 static ssize_t
store_chip_reset(struct device
*device
,
524 struct device_attribute
*attr
, const char *buf
,
527 struct qib_ibdev
*dev
=
528 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
529 struct qib_devdata
*dd
= dd_from_dev(dev
);
532 if (count
< 5 || memcmp(buf
, "reset", 5) || !dd
->diag_client
) {
537 ret
= qib_reset_device(dd
->unit
);
539 return ret
< 0 ? ret
: count
;
542 static ssize_t
show_logged_errs(struct device
*device
,
543 struct device_attribute
*attr
, char *buf
)
545 struct qib_ibdev
*dev
=
546 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
547 struct qib_devdata
*dd
= dd_from_dev(dev
);
550 /* force consistency with actual EEPROM */
551 if (qib_update_eeprom_log(dd
) != 0)
555 for (idx
= 0; idx
< QIB_EEP_LOG_CNT
; ++idx
) {
556 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
, "%d%c",
557 dd
->eep_st_errs
[idx
],
558 idx
== (QIB_EEP_LOG_CNT
- 1) ? '\n' : ' ');
565 * Dump tempsense regs. in decimal, to ease shell-scripts.
567 static ssize_t
show_tempsense(struct device
*device
,
568 struct device_attribute
*attr
, char *buf
)
570 struct qib_ibdev
*dev
=
571 container_of(device
, struct qib_ibdev
, ibdev
.dev
);
572 struct qib_devdata
*dd
= dd_from_dev(dev
);
578 for (idx
= 0; idx
< 8; ++idx
) {
581 ret
= dd
->f_tempsense_rd(dd
, idx
);
587 ret
= scnprintf(buf
, PAGE_SIZE
, "%d %d %02X %02X %d %d\n",
588 *(signed char *)(regvals
),
589 *(signed char *)(regvals
+ 1),
590 regvals
[2], regvals
[3],
591 *(signed char *)(regvals
+ 5),
592 *(signed char *)(regvals
+ 7));
597 * end of per-unit (or driver, in some cases, but replicated
598 * per unit) functions
601 /* start of per-unit file structures and support code */
602 static DEVICE_ATTR(hw_rev
, S_IRUGO
, show_rev
, NULL
);
603 static DEVICE_ATTR(hca_type
, S_IRUGO
, show_hca
, NULL
);
604 static DEVICE_ATTR(board_id
, S_IRUGO
, show_hca
, NULL
);
605 static DEVICE_ATTR(version
, S_IRUGO
, show_version
, NULL
);
606 static DEVICE_ATTR(nctxts
, S_IRUGO
, show_nctxts
, NULL
);
607 static DEVICE_ATTR(serial
, S_IRUGO
, show_serial
, NULL
);
608 static DEVICE_ATTR(boardversion
, S_IRUGO
, show_boardversion
, NULL
);
609 static DEVICE_ATTR(logged_errors
, S_IRUGO
, show_logged_errs
, NULL
);
610 static DEVICE_ATTR(tempsense
, S_IRUGO
, show_tempsense
, NULL
);
611 static DEVICE_ATTR(localbus_info
, S_IRUGO
, show_localbus_info
, NULL
);
612 static DEVICE_ATTR(chip_reset
, S_IWUSR
, NULL
, store_chip_reset
);
614 static struct device_attribute
*qib_attributes
[] = {
621 &dev_attr_boardversion
,
622 &dev_attr_logged_errors
,
624 &dev_attr_localbus_info
,
625 &dev_attr_chip_reset
,
628 int qib_create_port_files(struct ib_device
*ibdev
, u8 port_num
,
629 struct kobject
*kobj
)
631 struct qib_pportdata
*ppd
;
632 struct qib_devdata
*dd
= dd_from_ibdev(ibdev
);
635 if (!port_num
|| port_num
> dd
->num_pports
) {
636 qib_dev_err(dd
, "Skipping infiniband class with "
637 "invalid port %u\n", port_num
);
641 ppd
= &dd
->pport
[port_num
- 1];
643 ret
= kobject_init_and_add(&ppd
->pport_kobj
, &qib_port_ktype
, kobj
,
646 qib_dev_err(dd
, "Skipping linkcontrol sysfs info, "
647 "(err %d) port %u\n", ret
, port_num
);
650 kobject_uevent(&ppd
->pport_kobj
, KOBJ_ADD
);
652 ret
= kobject_init_and_add(&ppd
->sl2vl_kobj
, &qib_sl2vl_ktype
, kobj
,
655 qib_dev_err(dd
, "Skipping sl2vl sysfs info, "
656 "(err %d) port %u\n", ret
, port_num
);
659 kobject_uevent(&ppd
->sl2vl_kobj
, KOBJ_ADD
);
661 ret
= kobject_init_and_add(&ppd
->diagc_kobj
, &qib_diagc_ktype
, kobj
,
664 qib_dev_err(dd
, "Skipping diag_counters sysfs info, "
665 "(err %d) port %u\n", ret
, port_num
);
668 kobject_uevent(&ppd
->diagc_kobj
, KOBJ_ADD
);
673 kobject_put(&ppd
->sl2vl_kobj
);
675 kobject_put(&ppd
->pport_kobj
);
681 * Register and create our files in /sys/class/infiniband.
683 int qib_verbs_register_sysfs(struct qib_devdata
*dd
)
685 struct ib_device
*dev
= &dd
->verbs_dev
.ibdev
;
688 for (i
= 0; i
< ARRAY_SIZE(qib_attributes
); ++i
) {
689 ret
= device_create_file(&dev
->dev
, qib_attributes
[i
]);
698 * Unregister and remove our files in /sys/class/infiniband.
700 void qib_verbs_unregister_sysfs(struct qib_devdata
*dd
)
702 struct qib_pportdata
*ppd
;
705 for (i
= 0; i
< dd
->num_pports
; i
++) {
707 kobject_put(&ppd
->pport_kobj
);
708 kobject_put(&ppd
->sl2vl_kobj
);