Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / infiniband / hw / hfi1 / sysfs.c
blob5650130e68d439fa15ac94ec3f65dac2e348849e
1 /*
2 * Copyright(c) 2015-2017 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
7 * GPL LICENSE SUMMARY
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * BSD LICENSE
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 #include <linux/ctype.h>
49 #include "hfi.h"
50 #include "mad.h"
51 #include "trace.h"
54 * Start of per-port congestion control structures and support code
58 * Congestion control table size followed by table entries
60 static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj,
61 struct bin_attribute *bin_attr,
62 char *buf, loff_t pos, size_t count)
64 int ret;
65 struct hfi1_pportdata *ppd =
66 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
67 struct cc_state *cc_state;
69 ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow)
70 + sizeof(__be16);
72 if (pos > ret)
73 return -EINVAL;
75 if (count > ret - pos)
76 count = ret - pos;
78 if (!count)
79 return count;
81 rcu_read_lock();
82 cc_state = get_cc_state(ppd);
83 if (!cc_state) {
84 rcu_read_unlock();
85 return -EINVAL;
87 memcpy(buf, (void *)&cc_state->cct + pos, count);
88 rcu_read_unlock();
90 return count;
93 static void port_release(struct kobject *kobj)
95 /* nothing to do since memory is freed by hfi1_free_devdata() */
98 static const struct bin_attribute cc_table_bin_attr = {
99 .attr = {.name = "cc_table_bin", .mode = 0444},
100 .read = read_cc_table_bin,
101 .size = PAGE_SIZE,
105 * Congestion settings: port control, control map and an array of 16
106 * entries for the congestion entries - increase, timer, event log
107 * trigger threshold and the minimum injection rate delay.
109 static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj,
110 struct bin_attribute *bin_attr,
111 char *buf, loff_t pos, size_t count)
113 int ret;
114 struct hfi1_pportdata *ppd =
115 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
116 struct cc_state *cc_state;
118 ret = sizeof(struct opa_congestion_setting_attr_shadow);
120 if (pos > ret)
121 return -EINVAL;
122 if (count > ret - pos)
123 count = ret - pos;
125 if (!count)
126 return count;
128 rcu_read_lock();
129 cc_state = get_cc_state(ppd);
130 if (!cc_state) {
131 rcu_read_unlock();
132 return -EINVAL;
134 memcpy(buf, (void *)&cc_state->cong_setting + pos, count);
135 rcu_read_unlock();
137 return count;
140 static const struct bin_attribute cc_setting_bin_attr = {
141 .attr = {.name = "cc_settings_bin", .mode = 0444},
142 .read = read_cc_setting_bin,
143 .size = PAGE_SIZE,
146 struct hfi1_port_attr {
147 struct attribute attr;
148 ssize_t (*show)(struct hfi1_pportdata *, char *);
149 ssize_t (*store)(struct hfi1_pportdata *, const char *, size_t);
152 static ssize_t cc_prescan_show(struct hfi1_pportdata *ppd, char *buf)
154 return sysfs_emit(buf, "%s\n", ppd->cc_prescan ? "on" : "off");
157 static ssize_t cc_prescan_store(struct hfi1_pportdata *ppd, const char *buf,
158 size_t count)
160 if (!memcmp(buf, "on", 2))
161 ppd->cc_prescan = true;
162 else if (!memcmp(buf, "off", 3))
163 ppd->cc_prescan = false;
165 return count;
168 static struct hfi1_port_attr cc_prescan_attr =
169 __ATTR(cc_prescan, 0600, cc_prescan_show, cc_prescan_store);
171 static ssize_t cc_attr_show(struct kobject *kobj, struct attribute *attr,
172 char *buf)
174 struct hfi1_port_attr *port_attr =
175 container_of(attr, struct hfi1_port_attr, attr);
176 struct hfi1_pportdata *ppd =
177 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
179 return port_attr->show(ppd, buf);
182 static ssize_t cc_attr_store(struct kobject *kobj, struct attribute *attr,
183 const char *buf, size_t count)
185 struct hfi1_port_attr *port_attr =
186 container_of(attr, struct hfi1_port_attr, attr);
187 struct hfi1_pportdata *ppd =
188 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
190 return port_attr->store(ppd, buf, count);
193 static const struct sysfs_ops port_cc_sysfs_ops = {
194 .show = cc_attr_show,
195 .store = cc_attr_store
198 static struct attribute *port_cc_default_attributes[] = {
199 &cc_prescan_attr.attr,
200 NULL
203 static struct kobj_type port_cc_ktype = {
204 .release = port_release,
205 .sysfs_ops = &port_cc_sysfs_ops,
206 .default_attrs = port_cc_default_attributes
209 /* Start sc2vl */
210 #define HFI1_SC2VL_ATTR(N) \
211 static struct hfi1_sc2vl_attr hfi1_sc2vl_attr_##N = { \
212 .attr = { .name = __stringify(N), .mode = 0444 }, \
213 .sc = N \
216 struct hfi1_sc2vl_attr {
217 struct attribute attr;
218 int sc;
221 HFI1_SC2VL_ATTR(0);
222 HFI1_SC2VL_ATTR(1);
223 HFI1_SC2VL_ATTR(2);
224 HFI1_SC2VL_ATTR(3);
225 HFI1_SC2VL_ATTR(4);
226 HFI1_SC2VL_ATTR(5);
227 HFI1_SC2VL_ATTR(6);
228 HFI1_SC2VL_ATTR(7);
229 HFI1_SC2VL_ATTR(8);
230 HFI1_SC2VL_ATTR(9);
231 HFI1_SC2VL_ATTR(10);
232 HFI1_SC2VL_ATTR(11);
233 HFI1_SC2VL_ATTR(12);
234 HFI1_SC2VL_ATTR(13);
235 HFI1_SC2VL_ATTR(14);
236 HFI1_SC2VL_ATTR(15);
237 HFI1_SC2VL_ATTR(16);
238 HFI1_SC2VL_ATTR(17);
239 HFI1_SC2VL_ATTR(18);
240 HFI1_SC2VL_ATTR(19);
241 HFI1_SC2VL_ATTR(20);
242 HFI1_SC2VL_ATTR(21);
243 HFI1_SC2VL_ATTR(22);
244 HFI1_SC2VL_ATTR(23);
245 HFI1_SC2VL_ATTR(24);
246 HFI1_SC2VL_ATTR(25);
247 HFI1_SC2VL_ATTR(26);
248 HFI1_SC2VL_ATTR(27);
249 HFI1_SC2VL_ATTR(28);
250 HFI1_SC2VL_ATTR(29);
251 HFI1_SC2VL_ATTR(30);
252 HFI1_SC2VL_ATTR(31);
254 static struct attribute *sc2vl_default_attributes[] = {
255 &hfi1_sc2vl_attr_0.attr,
256 &hfi1_sc2vl_attr_1.attr,
257 &hfi1_sc2vl_attr_2.attr,
258 &hfi1_sc2vl_attr_3.attr,
259 &hfi1_sc2vl_attr_4.attr,
260 &hfi1_sc2vl_attr_5.attr,
261 &hfi1_sc2vl_attr_6.attr,
262 &hfi1_sc2vl_attr_7.attr,
263 &hfi1_sc2vl_attr_8.attr,
264 &hfi1_sc2vl_attr_9.attr,
265 &hfi1_sc2vl_attr_10.attr,
266 &hfi1_sc2vl_attr_11.attr,
267 &hfi1_sc2vl_attr_12.attr,
268 &hfi1_sc2vl_attr_13.attr,
269 &hfi1_sc2vl_attr_14.attr,
270 &hfi1_sc2vl_attr_15.attr,
271 &hfi1_sc2vl_attr_16.attr,
272 &hfi1_sc2vl_attr_17.attr,
273 &hfi1_sc2vl_attr_18.attr,
274 &hfi1_sc2vl_attr_19.attr,
275 &hfi1_sc2vl_attr_20.attr,
276 &hfi1_sc2vl_attr_21.attr,
277 &hfi1_sc2vl_attr_22.attr,
278 &hfi1_sc2vl_attr_23.attr,
279 &hfi1_sc2vl_attr_24.attr,
280 &hfi1_sc2vl_attr_25.attr,
281 &hfi1_sc2vl_attr_26.attr,
282 &hfi1_sc2vl_attr_27.attr,
283 &hfi1_sc2vl_attr_28.attr,
284 &hfi1_sc2vl_attr_29.attr,
285 &hfi1_sc2vl_attr_30.attr,
286 &hfi1_sc2vl_attr_31.attr,
287 NULL
290 static ssize_t sc2vl_attr_show(struct kobject *kobj, struct attribute *attr,
291 char *buf)
293 struct hfi1_sc2vl_attr *sattr =
294 container_of(attr, struct hfi1_sc2vl_attr, attr);
295 struct hfi1_pportdata *ppd =
296 container_of(kobj, struct hfi1_pportdata, sc2vl_kobj);
297 struct hfi1_devdata *dd = ppd->dd;
299 return sysfs_emit(buf, "%u\n", *((u8 *)dd->sc2vl + sattr->sc));
302 static const struct sysfs_ops hfi1_sc2vl_ops = {
303 .show = sc2vl_attr_show,
306 static struct kobj_type hfi1_sc2vl_ktype = {
307 .release = port_release,
308 .sysfs_ops = &hfi1_sc2vl_ops,
309 .default_attrs = sc2vl_default_attributes
312 /* End sc2vl */
314 /* Start sl2sc */
315 #define HFI1_SL2SC_ATTR(N) \
316 static struct hfi1_sl2sc_attr hfi1_sl2sc_attr_##N = { \
317 .attr = { .name = __stringify(N), .mode = 0444 }, \
318 .sl = N \
321 struct hfi1_sl2sc_attr {
322 struct attribute attr;
323 int sl;
326 HFI1_SL2SC_ATTR(0);
327 HFI1_SL2SC_ATTR(1);
328 HFI1_SL2SC_ATTR(2);
329 HFI1_SL2SC_ATTR(3);
330 HFI1_SL2SC_ATTR(4);
331 HFI1_SL2SC_ATTR(5);
332 HFI1_SL2SC_ATTR(6);
333 HFI1_SL2SC_ATTR(7);
334 HFI1_SL2SC_ATTR(8);
335 HFI1_SL2SC_ATTR(9);
336 HFI1_SL2SC_ATTR(10);
337 HFI1_SL2SC_ATTR(11);
338 HFI1_SL2SC_ATTR(12);
339 HFI1_SL2SC_ATTR(13);
340 HFI1_SL2SC_ATTR(14);
341 HFI1_SL2SC_ATTR(15);
342 HFI1_SL2SC_ATTR(16);
343 HFI1_SL2SC_ATTR(17);
344 HFI1_SL2SC_ATTR(18);
345 HFI1_SL2SC_ATTR(19);
346 HFI1_SL2SC_ATTR(20);
347 HFI1_SL2SC_ATTR(21);
348 HFI1_SL2SC_ATTR(22);
349 HFI1_SL2SC_ATTR(23);
350 HFI1_SL2SC_ATTR(24);
351 HFI1_SL2SC_ATTR(25);
352 HFI1_SL2SC_ATTR(26);
353 HFI1_SL2SC_ATTR(27);
354 HFI1_SL2SC_ATTR(28);
355 HFI1_SL2SC_ATTR(29);
356 HFI1_SL2SC_ATTR(30);
357 HFI1_SL2SC_ATTR(31);
359 static struct attribute *sl2sc_default_attributes[] = {
360 &hfi1_sl2sc_attr_0.attr,
361 &hfi1_sl2sc_attr_1.attr,
362 &hfi1_sl2sc_attr_2.attr,
363 &hfi1_sl2sc_attr_3.attr,
364 &hfi1_sl2sc_attr_4.attr,
365 &hfi1_sl2sc_attr_5.attr,
366 &hfi1_sl2sc_attr_6.attr,
367 &hfi1_sl2sc_attr_7.attr,
368 &hfi1_sl2sc_attr_8.attr,
369 &hfi1_sl2sc_attr_9.attr,
370 &hfi1_sl2sc_attr_10.attr,
371 &hfi1_sl2sc_attr_11.attr,
372 &hfi1_sl2sc_attr_12.attr,
373 &hfi1_sl2sc_attr_13.attr,
374 &hfi1_sl2sc_attr_14.attr,
375 &hfi1_sl2sc_attr_15.attr,
376 &hfi1_sl2sc_attr_16.attr,
377 &hfi1_sl2sc_attr_17.attr,
378 &hfi1_sl2sc_attr_18.attr,
379 &hfi1_sl2sc_attr_19.attr,
380 &hfi1_sl2sc_attr_20.attr,
381 &hfi1_sl2sc_attr_21.attr,
382 &hfi1_sl2sc_attr_22.attr,
383 &hfi1_sl2sc_attr_23.attr,
384 &hfi1_sl2sc_attr_24.attr,
385 &hfi1_sl2sc_attr_25.attr,
386 &hfi1_sl2sc_attr_26.attr,
387 &hfi1_sl2sc_attr_27.attr,
388 &hfi1_sl2sc_attr_28.attr,
389 &hfi1_sl2sc_attr_29.attr,
390 &hfi1_sl2sc_attr_30.attr,
391 &hfi1_sl2sc_attr_31.attr,
392 NULL
395 static ssize_t sl2sc_attr_show(struct kobject *kobj, struct attribute *attr,
396 char *buf)
398 struct hfi1_sl2sc_attr *sattr =
399 container_of(attr, struct hfi1_sl2sc_attr, attr);
400 struct hfi1_pportdata *ppd =
401 container_of(kobj, struct hfi1_pportdata, sl2sc_kobj);
402 struct hfi1_ibport *ibp = &ppd->ibport_data;
404 return sysfs_emit(buf, "%u\n", ibp->sl_to_sc[sattr->sl]);
407 static const struct sysfs_ops hfi1_sl2sc_ops = {
408 .show = sl2sc_attr_show,
411 static struct kobj_type hfi1_sl2sc_ktype = {
412 .release = port_release,
413 .sysfs_ops = &hfi1_sl2sc_ops,
414 .default_attrs = sl2sc_default_attributes
417 /* End sl2sc */
419 /* Start vl2mtu */
421 #define HFI1_VL2MTU_ATTR(N) \
422 static struct hfi1_vl2mtu_attr hfi1_vl2mtu_attr_##N = { \
423 .attr = { .name = __stringify(N), .mode = 0444 }, \
424 .vl = N \
427 struct hfi1_vl2mtu_attr {
428 struct attribute attr;
429 int vl;
432 HFI1_VL2MTU_ATTR(0);
433 HFI1_VL2MTU_ATTR(1);
434 HFI1_VL2MTU_ATTR(2);
435 HFI1_VL2MTU_ATTR(3);
436 HFI1_VL2MTU_ATTR(4);
437 HFI1_VL2MTU_ATTR(5);
438 HFI1_VL2MTU_ATTR(6);
439 HFI1_VL2MTU_ATTR(7);
440 HFI1_VL2MTU_ATTR(8);
441 HFI1_VL2MTU_ATTR(9);
442 HFI1_VL2MTU_ATTR(10);
443 HFI1_VL2MTU_ATTR(11);
444 HFI1_VL2MTU_ATTR(12);
445 HFI1_VL2MTU_ATTR(13);
446 HFI1_VL2MTU_ATTR(14);
447 HFI1_VL2MTU_ATTR(15);
449 static struct attribute *vl2mtu_default_attributes[] = {
450 &hfi1_vl2mtu_attr_0.attr,
451 &hfi1_vl2mtu_attr_1.attr,
452 &hfi1_vl2mtu_attr_2.attr,
453 &hfi1_vl2mtu_attr_3.attr,
454 &hfi1_vl2mtu_attr_4.attr,
455 &hfi1_vl2mtu_attr_5.attr,
456 &hfi1_vl2mtu_attr_6.attr,
457 &hfi1_vl2mtu_attr_7.attr,
458 &hfi1_vl2mtu_attr_8.attr,
459 &hfi1_vl2mtu_attr_9.attr,
460 &hfi1_vl2mtu_attr_10.attr,
461 &hfi1_vl2mtu_attr_11.attr,
462 &hfi1_vl2mtu_attr_12.attr,
463 &hfi1_vl2mtu_attr_13.attr,
464 &hfi1_vl2mtu_attr_14.attr,
465 &hfi1_vl2mtu_attr_15.attr,
466 NULL
469 static ssize_t vl2mtu_attr_show(struct kobject *kobj, struct attribute *attr,
470 char *buf)
472 struct hfi1_vl2mtu_attr *vlattr =
473 container_of(attr, struct hfi1_vl2mtu_attr, attr);
474 struct hfi1_pportdata *ppd =
475 container_of(kobj, struct hfi1_pportdata, vl2mtu_kobj);
476 struct hfi1_devdata *dd = ppd->dd;
478 return sysfs_emit(buf, "%u\n", dd->vld[vlattr->vl].mtu);
481 static const struct sysfs_ops hfi1_vl2mtu_ops = {
482 .show = vl2mtu_attr_show,
485 static struct kobj_type hfi1_vl2mtu_ktype = {
486 .release = port_release,
487 .sysfs_ops = &hfi1_vl2mtu_ops,
488 .default_attrs = vl2mtu_default_attributes
491 /* end of per-port file structures and support code */
494 * Start of per-unit (or driver, in some cases, but replicated
495 * per unit) functions (these get a device *)
497 static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
498 char *buf)
500 struct hfi1_ibdev *dev =
501 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
503 return sysfs_emit(buf, "%x\n", dd_from_dev(dev)->minrev);
505 static DEVICE_ATTR_RO(hw_rev);
507 static ssize_t board_id_show(struct device *device,
508 struct device_attribute *attr, char *buf)
510 struct hfi1_ibdev *dev =
511 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
512 struct hfi1_devdata *dd = dd_from_dev(dev);
514 if (!dd->boardname)
515 return -EINVAL;
517 return sysfs_emit(buf, "%s\n", dd->boardname);
519 static DEVICE_ATTR_RO(board_id);
521 static ssize_t boardversion_show(struct device *device,
522 struct device_attribute *attr, char *buf)
524 struct hfi1_ibdev *dev =
525 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
526 struct hfi1_devdata *dd = dd_from_dev(dev);
528 /* The string printed here is already newline-terminated. */
529 return sysfs_emit(buf, "%s", dd->boardversion);
531 static DEVICE_ATTR_RO(boardversion);
533 static ssize_t nctxts_show(struct device *device,
534 struct device_attribute *attr, char *buf)
536 struct hfi1_ibdev *dev =
537 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
538 struct hfi1_devdata *dd = dd_from_dev(dev);
541 * Return the smaller of send and receive contexts.
542 * Normally, user level applications would require both a send
543 * and a receive context, so returning the smaller of the two counts
544 * give a more accurate picture of total contexts available.
546 return sysfs_emit(buf, "%u\n",
547 min(dd->num_user_contexts,
548 (u32)dd->sc_sizes[SC_USER].count));
550 static DEVICE_ATTR_RO(nctxts);
552 static ssize_t nfreectxts_show(struct device *device,
553 struct device_attribute *attr, char *buf)
555 struct hfi1_ibdev *dev =
556 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
557 struct hfi1_devdata *dd = dd_from_dev(dev);
559 /* Return the number of free user ports (contexts) available. */
560 return sysfs_emit(buf, "%u\n", dd->freectxts);
562 static DEVICE_ATTR_RO(nfreectxts);
564 static ssize_t serial_show(struct device *device,
565 struct device_attribute *attr, char *buf)
567 struct hfi1_ibdev *dev =
568 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
569 struct hfi1_devdata *dd = dd_from_dev(dev);
571 /* dd->serial is already newline terminated in chip.c */
572 return sysfs_emit(buf, "%s", dd->serial);
574 static DEVICE_ATTR_RO(serial);
576 static ssize_t chip_reset_store(struct device *device,
577 struct device_attribute *attr, const char *buf,
578 size_t count)
580 struct hfi1_ibdev *dev =
581 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
582 struct hfi1_devdata *dd = dd_from_dev(dev);
583 int ret;
585 if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
586 ret = -EINVAL;
587 goto bail;
590 ret = hfi1_reset_device(dd->unit);
591 bail:
592 return ret < 0 ? ret : count;
594 static DEVICE_ATTR_WO(chip_reset);
597 * Convert the reported temperature from an integer (reported in
598 * units of 0.25C) to a floating point number.
600 #define temp_d(t) ((t) >> 2)
601 #define temp_f(t) (((t)&0x3) * 25u)
604 * Dump tempsense values, in decimal, to ease shell-scripts.
606 static ssize_t tempsense_show(struct device *device,
607 struct device_attribute *attr, char *buf)
609 struct hfi1_ibdev *dev =
610 rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
611 struct hfi1_devdata *dd = dd_from_dev(dev);
612 struct hfi1_temp temp;
613 int ret;
615 ret = hfi1_tempsense_rd(dd, &temp);
616 if (ret)
617 return ret;
619 return sysfs_emit(buf, "%u.%02u %u.%02u %u.%02u %u.%02u %u %u %u\n",
620 temp_d(temp.curr), temp_f(temp.curr),
621 temp_d(temp.lo_lim), temp_f(temp.lo_lim),
622 temp_d(temp.hi_lim), temp_f(temp.hi_lim),
623 temp_d(temp.crit_lim), temp_f(temp.crit_lim),
624 temp.triggers & 0x1,
625 temp.triggers & 0x2,
626 temp.triggers & 0x4);
628 static DEVICE_ATTR_RO(tempsense);
631 * end of per-unit (or driver, in some cases, but replicated
632 * per unit) functions
635 /* start of per-unit file structures and support code */
636 static struct attribute *hfi1_attributes[] = {
637 &dev_attr_hw_rev.attr,
638 &dev_attr_board_id.attr,
639 &dev_attr_nctxts.attr,
640 &dev_attr_nfreectxts.attr,
641 &dev_attr_serial.attr,
642 &dev_attr_boardversion.attr,
643 &dev_attr_tempsense.attr,
644 &dev_attr_chip_reset.attr,
645 NULL,
648 const struct attribute_group ib_hfi1_attr_group = {
649 .attrs = hfi1_attributes,
652 int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
653 struct kobject *kobj)
655 struct hfi1_pportdata *ppd;
656 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
657 int ret;
659 if (!port_num || port_num > dd->num_pports) {
660 dd_dev_err(dd,
661 "Skipping infiniband class with invalid port %u\n",
662 port_num);
663 return -ENODEV;
665 ppd = &dd->pport[port_num - 1];
667 ret = kobject_init_and_add(&ppd->sc2vl_kobj, &hfi1_sc2vl_ktype, kobj,
668 "sc2vl");
669 if (ret) {
670 dd_dev_err(dd,
671 "Skipping sc2vl sysfs info, (err %d) port %u\n",
672 ret, port_num);
674 * Based on the documentation for kobject_init_and_add(), the
675 * caller should call kobject_put even if this call fails.
677 goto bail_sc2vl;
679 kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD);
681 ret = kobject_init_and_add(&ppd->sl2sc_kobj, &hfi1_sl2sc_ktype, kobj,
682 "sl2sc");
683 if (ret) {
684 dd_dev_err(dd,
685 "Skipping sl2sc sysfs info, (err %d) port %u\n",
686 ret, port_num);
687 goto bail_sl2sc;
689 kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD);
691 ret = kobject_init_and_add(&ppd->vl2mtu_kobj, &hfi1_vl2mtu_ktype, kobj,
692 "vl2mtu");
693 if (ret) {
694 dd_dev_err(dd,
695 "Skipping vl2mtu sysfs info, (err %d) port %u\n",
696 ret, port_num);
697 goto bail_vl2mtu;
699 kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);
701 ret = kobject_init_and_add(&ppd->pport_cc_kobj, &port_cc_ktype,
702 kobj, "CCMgtA");
703 if (ret) {
704 dd_dev_err(dd,
705 "Skipping Congestion Control sysfs info, (err %d) port %u\n",
706 ret, port_num);
707 goto bail_cc;
710 kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
712 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
713 if (ret) {
714 dd_dev_err(dd,
715 "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
716 ret, port_num);
717 goto bail_cc;
720 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_table_bin_attr);
721 if (ret) {
722 dd_dev_err(dd,
723 "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
724 ret, port_num);
725 goto bail_cc_entry_bin;
728 dd_dev_info(dd,
729 "Congestion Control Agent enabled for port %d\n",
730 port_num);
732 return 0;
734 bail_cc_entry_bin:
735 sysfs_remove_bin_file(&ppd->pport_cc_kobj,
736 &cc_setting_bin_attr);
737 bail_cc:
738 kobject_put(&ppd->pport_cc_kobj);
739 bail_vl2mtu:
740 kobject_put(&ppd->vl2mtu_kobj);
741 bail_sl2sc:
742 kobject_put(&ppd->sl2sc_kobj);
743 bail_sc2vl:
744 kobject_put(&ppd->sc2vl_kobj);
745 return ret;
748 struct sde_attribute {
749 struct attribute attr;
750 ssize_t (*show)(struct sdma_engine *sde, char *buf);
751 ssize_t (*store)(struct sdma_engine *sde, const char *buf, size_t cnt);
754 static ssize_t sde_show(struct kobject *kobj, struct attribute *attr, char *buf)
756 struct sde_attribute *sde_attr =
757 container_of(attr, struct sde_attribute, attr);
758 struct sdma_engine *sde =
759 container_of(kobj, struct sdma_engine, kobj);
761 if (!sde_attr->show)
762 return -EINVAL;
764 return sde_attr->show(sde, buf);
767 static ssize_t sde_store(struct kobject *kobj, struct attribute *attr,
768 const char *buf, size_t count)
770 struct sde_attribute *sde_attr =
771 container_of(attr, struct sde_attribute, attr);
772 struct sdma_engine *sde =
773 container_of(kobj, struct sdma_engine, kobj);
775 if (!capable(CAP_SYS_ADMIN))
776 return -EPERM;
778 if (!sde_attr->store)
779 return -EINVAL;
781 return sde_attr->store(sde, buf, count);
784 static const struct sysfs_ops sde_sysfs_ops = {
785 .show = sde_show,
786 .store = sde_store,
789 static struct kobj_type sde_ktype = {
790 .sysfs_ops = &sde_sysfs_ops,
793 #define SDE_ATTR(_name, _mode, _show, _store) \
794 struct sde_attribute sde_attr_##_name = \
795 __ATTR(_name, _mode, _show, _store)
797 static ssize_t sde_show_cpu_to_sde_map(struct sdma_engine *sde, char *buf)
799 return sdma_get_cpu_to_sde_map(sde, buf);
802 static ssize_t sde_store_cpu_to_sde_map(struct sdma_engine *sde,
803 const char *buf, size_t count)
805 return sdma_set_cpu_to_sde_map(sde, buf, count);
808 static ssize_t sde_show_vl(struct sdma_engine *sde, char *buf)
810 int vl;
812 vl = sdma_engine_get_vl(sde);
813 if (vl < 0)
814 return vl;
816 return sysfs_emit(buf, "%d\n", vl);
819 static SDE_ATTR(cpu_list, S_IWUSR | S_IRUGO,
820 sde_show_cpu_to_sde_map,
821 sde_store_cpu_to_sde_map);
822 static SDE_ATTR(vl, S_IRUGO, sde_show_vl, NULL);
824 static struct sde_attribute *sde_attribs[] = {
825 &sde_attr_cpu_list,
826 &sde_attr_vl
830 * Register and create our files in /sys/class/infiniband.
832 int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd)
834 struct ib_device *dev = &dd->verbs_dev.rdi.ibdev;
835 struct device *class_dev = &dev->dev;
836 int i, j, ret;
838 for (i = 0; i < dd->num_sdma; i++) {
839 ret = kobject_init_and_add(&dd->per_sdma[i].kobj,
840 &sde_ktype, &class_dev->kobj,
841 "sdma%d", i);
842 if (ret)
843 goto bail;
845 for (j = 0; j < ARRAY_SIZE(sde_attribs); j++) {
846 ret = sysfs_create_file(&dd->per_sdma[i].kobj,
847 &sde_attribs[j]->attr);
848 if (ret)
849 goto bail;
853 return 0;
854 bail:
856 * The function kobject_put() will call kobject_del() if the kobject
857 * has been added successfully. The sysfs files created under the
858 * kobject directory will also be removed during the process.
860 for (; i >= 0; i--)
861 kobject_put(&dd->per_sdma[i].kobj);
863 return ret;
867 * Unregister and remove our files in /sys/class/infiniband.
869 void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *dd)
871 struct hfi1_pportdata *ppd;
872 int i;
874 /* Unwind operations in hfi1_verbs_register_sysfs() */
875 for (i = 0; i < dd->num_sdma; i++)
876 kobject_put(&dd->per_sdma[i].kobj);
878 for (i = 0; i < dd->num_pports; i++) {
879 ppd = &dd->pport[i];
881 sysfs_remove_bin_file(&ppd->pport_cc_kobj,
882 &cc_setting_bin_attr);
883 sysfs_remove_bin_file(&ppd->pport_cc_kobj,
884 &cc_table_bin_attr);
885 kobject_put(&ppd->pport_cc_kobj);
886 kobject_put(&ppd->vl2mtu_kobj);
887 kobject_put(&ppd->sl2sc_kobj);
888 kobject_put(&ppd->sc2vl_kobj);