blob: ae78305b59d0c4954ab1fd2521a8e925395422f1 [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Mike Marciniszyn36a8f012012-07-19 13:04:04 +00002 * Copyright (c) 2012 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
Ralph Campbellf9315512010-05-23 21:44:54 -07004 * Copyright (c) 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 Marciniszyn36a8f012012-07-19 13:04:04 +000037#include "qib_mad.h"
Ralph Campbellf9315512010-05-23 21:44:54 -070038
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 */
46static 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
70bail:
71 return ret;
72}
73
74/* start of per-port functions */
75/*
76 * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
77 */
78static 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
88static 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
111static 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
124static 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
139static 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 Marciniszyn865b64b2011-11-09 13:35:55 -0500155static const char * const qib_status_str[] = {
Ralph Campbellf9315512010-05-23 21:44:54 -0700156 "Initted",
157 "",
158 "",
159 "",
160 "",
161 "Present",
162 "IB_link_up",
163 "IB_configured",
164 "",
165 "Fatal_Hardware_Error",
166 NULL,
167};
168
169static 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
199bail:
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
214struct 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
220QIB_PORT_ATTR(loopback, S_IWUSR, NULL, store_loopback);
221QIB_PORT_ATTR(led_override, S_IWUSR, NULL, store_led_override);
222QIB_PORT_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,
223 store_hrtbt_enb);
224QIB_PORT_ATTR(status, S_IRUGO, show_status, NULL);
225QIB_PORT_ATTR(status_str, S_IRUGO, show_status_str, NULL);
226
227static 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 Marciniszyn36a8f012012-07-19 13:04:04 +0000236/*
237 * Start of per-port congestion control structures and support code
238 */
239
240/*
241 * Congestion control table size followed by table entries
242 */
243static 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
273static void qib_port_release(struct kobject *kobj)
274{
275 /* nothing to do since memory is freed by qib_free_devdata() */
276}
277
278static struct kobj_type qib_port_cc_ktype = {
279 .release = qib_port_release,
280};
281
282static 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 */
293static 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
321static 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 Campbellf9315512010-05-23 21:44:54 -0700328static 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
339static 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 Campbellf9315512010-05-23 21:44:54 -0700350
351static const struct sysfs_ops qib_port_ops = {
352 .show = qib_portattr_show,
353 .store = qib_portattr_store,
354};
355
356static 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
370struct qib_sl2vl_attr {
371 struct attribute attr;
372 int sl;
373};
374
375QIB_SL2VL_ATTR(0);
376QIB_SL2VL_ATTR(1);
377QIB_SL2VL_ATTR(2);
378QIB_SL2VL_ATTR(3);
379QIB_SL2VL_ATTR(4);
380QIB_SL2VL_ATTR(5);
381QIB_SL2VL_ATTR(6);
382QIB_SL2VL_ATTR(7);
383QIB_SL2VL_ATTR(8);
384QIB_SL2VL_ATTR(9);
385QIB_SL2VL_ATTR(10);
386QIB_SL2VL_ATTR(11);
387QIB_SL2VL_ATTR(12);
388QIB_SL2VL_ATTR(13);
389QIB_SL2VL_ATTR(14);
390QIB_SL2VL_ATTR(15);
391
392static 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
412static 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
424static const struct sysfs_ops qib_sl2vl_ops = {
425 .show = sl2vl_attr_show,
426};
427
428static 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 Weiny4c6931f2010-07-14 01:53:18 +0000440 .attr = { .name = __stringify(N), .mode = 0664 }, \
Ralph Campbellf9315512010-05-23 21:44:54 -0700441 .counter = offsetof(struct qib_ibport, n_##N) \
442 }
443
444struct qib_diagc_attr {
445 struct attribute attr;
446 size_t counter;
447};
448
449QIB_DIAGC_ATTR(rc_resends);
450QIB_DIAGC_ATTR(rc_acks);
451QIB_DIAGC_ATTR(rc_qacks);
452QIB_DIAGC_ATTR(rc_delayed_comp);
453QIB_DIAGC_ATTR(seq_naks);
454QIB_DIAGC_ATTR(rdma_seq);
455QIB_DIAGC_ATTR(rnr_naks);
456QIB_DIAGC_ATTR(other_naks);
457QIB_DIAGC_ATTR(rc_timeouts);
458QIB_DIAGC_ATTR(loop_pkts);
459QIB_DIAGC_ATTR(pkt_drops);
460QIB_DIAGC_ATTR(dmawait);
461QIB_DIAGC_ATTR(unaligned);
462QIB_DIAGC_ATTR(rc_dupreq);
463QIB_DIAGC_ATTR(rc_seqnak);
464
465static 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
484static 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 Weiny4c6931f2010-07-14 01:53:18 +0000496static 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 Campbellf9315512010-05-23 21:44:54 -0700514static const struct sysfs_ops qib_diagc_ops = {
515 .show = diagc_attr_show,
Ira Weiny4c6931f2010-07-14 01:53:18 +0000516 .store = diagc_attr_store,
Ralph Campbellf9315512010-05-23 21:44:54 -0700517};
518
519static 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 */
533static 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
542static 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
557static 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
564static 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
576static 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
588static 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 Haralanov6ceaade2012-05-07 14:03:02 -0400596 /* 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 Campbellf9315512010-05-23 21:44:54 -0700601}
602
Ram Vepa2df4f752011-05-31 20:20:43 +0000603static 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 Marciniszyn53ab1c62011-10-06 09:33:35 -0700611 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
Ram Vepa2df4f752011-05-31 20:20:43 +0000612}
613
Ralph Campbellf9315512010-05-23 21:44:54 -0700614static 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
627static 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);
642bail:
643 return ret < 0 ? ret : count;
644}
645
646static 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 */
671static 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 */
706static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
707static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
708static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
709static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
710static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
Ram Vepa2df4f752011-05-31 20:20:43 +0000711static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
Ralph Campbellf9315512010-05-23 21:44:54 -0700712static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
713static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
714static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL);
715static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
716static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);
717static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
718
719static 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 Vepa2df4f752011-05-31 20:20:43 +0000725 &dev_attr_nfreectxts,
Ralph Campbellf9315512010-05-23 21:44:54 -0700726 &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
734int 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 Marciniszyn36a8f012012-07-19 13:04:04 +0000763 goto bail_link;
Ralph Campbellf9315512010-05-23 21:44:54 -0700764 }
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 Marciniszyn36a8f012012-07-19 13:04:04 +0000772 goto bail_sl;
Ralph Campbellf9315512010-05-23 21:44:54 -0700773 }
774 kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD);
775
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000776 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 Campbellf9315512010-05-23 21:44:54 -0700812 return 0;
813
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000814bail_cc_entry_bin:
815 sysfs_remove_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
816bail_cc:
817 kobject_put(&ppd->pport_cc_kobj);
Ralph Campbellf9315512010-05-23 21:44:54 -0700818bail_diagc:
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000819 kobject_put(&ppd->diagc_kobj);
Ralph Campbellf9315512010-05-23 21:44:54 -0700820bail_sl:
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000821 kobject_put(&ppd->sl2vl_kobj);
822bail_link:
Ralph Campbellf9315512010-05-23 21:44:54 -0700823 kobject_put(&ppd->pport_kobj);
824bail:
825 return ret;
826}
827
828/*
829 * Register and create our files in /sys/class/infiniband.
830 */
831int 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 */
848void 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 Marciniszyn36a8f012012-07-19 13:04:04 +0000855 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 Campbellf9315512010-05-23 21:44:54 -0700863 kobject_put(&ppd->sl2vl_kobj);
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000864 kobject_put(&ppd->pport_kobj);
Ralph Campbellf9315512010-05-23 21:44:54 -0700865 }
866}