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.
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.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
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
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>
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
)
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
)
75 if (count
> ret
- pos
)
82 cc_state
= get_cc_state(ppd
);
87 memcpy(buf
, (void *)&cc_state
->cct
+ pos
, 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
,
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
)
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
);
122 if (count
> ret
- pos
)
129 cc_state
= get_cc_state(ppd
);
134 memcpy(buf
, (void *)&cc_state
->cong_setting
+ pos
, 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
,
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 sprintf(buf
, "%s\n", ppd
->cc_prescan
? "on" : "off");
157 static ssize_t
cc_prescan_store(struct hfi1_pportdata
*ppd
, const char *buf
,
160 if (!memcmp(buf
, "on", 2))
161 ppd
->cc_prescan
= true;
162 else if (!memcmp(buf
, "off", 3))
163 ppd
->cc_prescan
= false;
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
,
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
,
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
210 #define HFI1_SC2VL_ATTR(N) \
211 static struct hfi1_sc2vl_attr hfi1_sc2vl_attr_##N = { \
212 .attr = { .name = __stringify(N), .mode = 0444 }, \
216 struct hfi1_sc2vl_attr
{
217 struct attribute attr
;
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
,
290 static ssize_t
sc2vl_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
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 sprintf(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
315 #define HFI1_SL2SC_ATTR(N) \
316 static struct hfi1_sl2sc_attr hfi1_sl2sc_attr_##N = { \
317 .attr = { .name = __stringify(N), .mode = 0444 }, \
321 struct hfi1_sl2sc_attr
{
322 struct attribute attr
;
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
,
395 static ssize_t
sl2sc_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
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 sprintf(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
421 #define HFI1_VL2MTU_ATTR(N) \
422 static struct hfi1_vl2mtu_attr hfi1_vl2mtu_attr_##N = { \
423 .attr = { .name = __stringify(N), .mode = 0444 }, \
427 struct hfi1_vl2mtu_attr
{
428 struct attribute attr
;
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
,
469 static ssize_t
vl2mtu_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
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 sprintf(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
show_rev(struct device
*device
, struct device_attribute
*attr
,
500 struct hfi1_ibdev
*dev
=
501 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
503 return sprintf(buf
, "%x\n", dd_from_dev(dev
)->minrev
);
506 static ssize_t
show_hfi(struct device
*device
, struct device_attribute
*attr
,
509 struct hfi1_ibdev
*dev
=
510 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
511 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
517 ret
= scnprintf(buf
, PAGE_SIZE
, "%s\n", dd
->boardname
);
521 static ssize_t
show_boardversion(struct device
*device
,
522 struct device_attribute
*attr
, char *buf
)
524 struct hfi1_ibdev
*dev
=
525 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
526 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
528 /* The string printed here is already newline-terminated. */
529 return scnprintf(buf
, PAGE_SIZE
, "%s", dd
->boardversion
);
532 static ssize_t
show_nctxts(struct device
*device
,
533 struct device_attribute
*attr
, char *buf
)
535 struct hfi1_ibdev
*dev
=
536 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
537 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
540 * Return the smaller of send and receive contexts.
541 * Normally, user level applications would require both a send
542 * and a receive context, so returning the smaller of the two counts
543 * give a more accurate picture of total contexts available.
545 return scnprintf(buf
, PAGE_SIZE
, "%u\n",
546 min(dd
->num_user_contexts
,
547 (u32
)dd
->sc_sizes
[SC_USER
].count
));
550 static ssize_t
show_nfreectxts(struct device
*device
,
551 struct device_attribute
*attr
, char *buf
)
553 struct hfi1_ibdev
*dev
=
554 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
555 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
557 /* Return the number of free user ports (contexts) available. */
558 return scnprintf(buf
, PAGE_SIZE
, "%u\n", dd
->freectxts
);
561 static ssize_t
show_serial(struct device
*device
,
562 struct device_attribute
*attr
, char *buf
)
564 struct hfi1_ibdev
*dev
=
565 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
566 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
568 return scnprintf(buf
, PAGE_SIZE
, "%s", dd
->serial
);
571 static ssize_t
store_chip_reset(struct device
*device
,
572 struct device_attribute
*attr
, const char *buf
,
575 struct hfi1_ibdev
*dev
=
576 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
577 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
580 if (count
< 5 || memcmp(buf
, "reset", 5) || !dd
->diag_client
) {
585 ret
= hfi1_reset_device(dd
->unit
);
587 return ret
< 0 ? ret
: count
;
591 * Convert the reported temperature from an integer (reported in
592 * units of 0.25C) to a floating point number.
594 #define temp2str(temp, buf, size, idx) \
595 scnprintf((buf) + (idx), (size) - (idx), "%u.%02u ", \
596 ((temp) >> 2), ((temp) & 0x3) * 25)
599 * Dump tempsense values, in decimal, to ease shell-scripts.
601 static ssize_t
show_tempsense(struct device
*device
,
602 struct device_attribute
*attr
, char *buf
)
604 struct hfi1_ibdev
*dev
=
605 container_of(device
, struct hfi1_ibdev
, rdi
.ibdev
.dev
);
606 struct hfi1_devdata
*dd
= dd_from_dev(dev
);
607 struct hfi1_temp temp
;
610 ret
= hfi1_tempsense_rd(dd
, &temp
);
614 idx
+= temp2str(temp
.curr
, buf
, PAGE_SIZE
, idx
);
615 idx
+= temp2str(temp
.lo_lim
, buf
, PAGE_SIZE
, idx
);
616 idx
+= temp2str(temp
.hi_lim
, buf
, PAGE_SIZE
, idx
);
617 idx
+= temp2str(temp
.crit_lim
, buf
, PAGE_SIZE
, idx
);
618 idx
+= scnprintf(buf
+ idx
, PAGE_SIZE
- idx
,
619 "%u %u %u\n", temp
.triggers
& 0x1,
620 temp
.triggers
& 0x2, temp
.triggers
& 0x4);
627 * end of per-unit (or driver, in some cases, but replicated
628 * per unit) functions
631 /* start of per-unit file structures and support code */
632 static DEVICE_ATTR(hw_rev
, S_IRUGO
, show_rev
, NULL
);
633 static DEVICE_ATTR(board_id
, S_IRUGO
, show_hfi
, NULL
);
634 static DEVICE_ATTR(nctxts
, S_IRUGO
, show_nctxts
, NULL
);
635 static DEVICE_ATTR(nfreectxts
, S_IRUGO
, show_nfreectxts
, NULL
);
636 static DEVICE_ATTR(serial
, S_IRUGO
, show_serial
, NULL
);
637 static DEVICE_ATTR(boardversion
, S_IRUGO
, show_boardversion
, NULL
);
638 static DEVICE_ATTR(tempsense
, S_IRUGO
, show_tempsense
, NULL
);
639 static DEVICE_ATTR(chip_reset
, S_IWUSR
, NULL
, store_chip_reset
);
641 static struct device_attribute
*hfi1_attributes
[] = {
645 &dev_attr_nfreectxts
,
647 &dev_attr_boardversion
,
649 &dev_attr_chip_reset
,
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
);
659 if (!port_num
|| port_num
> dd
->num_pports
) {
661 "Skipping infiniband class with invalid port %u\n",
665 ppd
= &dd
->pport
[port_num
- 1];
667 ret
= kobject_init_and_add(&ppd
->sc2vl_kobj
, &hfi1_sc2vl_ktype
, kobj
,
671 "Skipping sc2vl sysfs info, (err %d) port %u\n",
675 kobject_uevent(&ppd
->sc2vl_kobj
, KOBJ_ADD
);
677 ret
= kobject_init_and_add(&ppd
->sl2sc_kobj
, &hfi1_sl2sc_ktype
, kobj
,
681 "Skipping sl2sc sysfs info, (err %d) port %u\n",
685 kobject_uevent(&ppd
->sl2sc_kobj
, KOBJ_ADD
);
687 ret
= kobject_init_and_add(&ppd
->vl2mtu_kobj
, &hfi1_vl2mtu_ktype
, kobj
,
691 "Skipping vl2mtu sysfs info, (err %d) port %u\n",
695 kobject_uevent(&ppd
->vl2mtu_kobj
, KOBJ_ADD
);
697 ret
= kobject_init_and_add(&ppd
->pport_cc_kobj
, &port_cc_ktype
,
701 "Skipping Congestion Control sysfs info, (err %d) port %u\n",
706 kobject_uevent(&ppd
->pport_cc_kobj
, KOBJ_ADD
);
708 ret
= sysfs_create_bin_file(&ppd
->pport_cc_kobj
, &cc_setting_bin_attr
);
711 "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
716 ret
= sysfs_create_bin_file(&ppd
->pport_cc_kobj
, &cc_table_bin_attr
);
719 "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
721 goto bail_cc_entry_bin
;
725 "Congestion Control Agent enabled for port %d\n",
731 sysfs_remove_bin_file(&ppd
->pport_cc_kobj
,
732 &cc_setting_bin_attr
);
734 kobject_put(&ppd
->pport_cc_kobj
);
736 kobject_put(&ppd
->vl2mtu_kobj
);
738 kobject_put(&ppd
->sl2sc_kobj
);
740 kobject_put(&ppd
->sc2vl_kobj
);
745 struct sde_attribute
{
746 struct attribute attr
;
747 ssize_t (*show
)(struct sdma_engine
*sde
, char *buf
);
748 ssize_t (*store
)(struct sdma_engine
*sde
, const char *buf
, size_t cnt
);
751 static ssize_t
sde_show(struct kobject
*kobj
, struct attribute
*attr
, char *buf
)
753 struct sde_attribute
*sde_attr
=
754 container_of(attr
, struct sde_attribute
, attr
);
755 struct sdma_engine
*sde
=
756 container_of(kobj
, struct sdma_engine
, kobj
);
761 return sde_attr
->show(sde
, buf
);
764 static ssize_t
sde_store(struct kobject
*kobj
, struct attribute
*attr
,
765 const char *buf
, size_t count
)
767 struct sde_attribute
*sde_attr
=
768 container_of(attr
, struct sde_attribute
, attr
);
769 struct sdma_engine
*sde
=
770 container_of(kobj
, struct sdma_engine
, kobj
);
772 if (!capable(CAP_SYS_ADMIN
))
775 if (!sde_attr
->store
)
778 return sde_attr
->store(sde
, buf
, count
);
781 static const struct sysfs_ops sde_sysfs_ops
= {
786 static struct kobj_type sde_ktype
= {
787 .sysfs_ops
= &sde_sysfs_ops
,
790 #define SDE_ATTR(_name, _mode, _show, _store) \
791 struct sde_attribute sde_attr_##_name = \
792 __ATTR(_name, _mode, _show, _store)
794 static ssize_t
sde_show_cpu_to_sde_map(struct sdma_engine
*sde
, char *buf
)
796 return sdma_get_cpu_to_sde_map(sde
, buf
);
799 static ssize_t
sde_store_cpu_to_sde_map(struct sdma_engine
*sde
,
800 const char *buf
, size_t count
)
802 return sdma_set_cpu_to_sde_map(sde
, buf
, count
);
805 static ssize_t
sde_show_vl(struct sdma_engine
*sde
, char *buf
)
809 vl
= sdma_engine_get_vl(sde
);
813 return snprintf(buf
, PAGE_SIZE
, "%d\n", vl
);
816 static SDE_ATTR(cpu_list
, S_IWUSR
| S_IRUGO
,
817 sde_show_cpu_to_sde_map
,
818 sde_store_cpu_to_sde_map
);
819 static SDE_ATTR(vl
, S_IRUGO
, sde_show_vl
, NULL
);
821 static struct sde_attribute
*sde_attribs
[] = {
827 * Register and create our files in /sys/class/infiniband.
829 int hfi1_verbs_register_sysfs(struct hfi1_devdata
*dd
)
831 struct ib_device
*dev
= &dd
->verbs_dev
.rdi
.ibdev
;
832 struct device
*class_dev
= &dev
->dev
;
835 for (i
= 0; i
< ARRAY_SIZE(hfi1_attributes
); ++i
) {
836 ret
= device_create_file(&dev
->dev
, hfi1_attributes
[i
]);
841 for (i
= 0; i
< dd
->num_sdma
; i
++) {
842 ret
= kobject_init_and_add(&dd
->per_sdma
[i
].kobj
,
843 &sde_ktype
, &class_dev
->kobj
,
848 for (j
= 0; j
< ARRAY_SIZE(sde_attribs
); j
++) {
849 ret
= sysfs_create_file(&dd
->per_sdma
[i
].kobj
,
850 &sde_attribs
[j
]->attr
);
858 for (i
= 0; i
< ARRAY_SIZE(hfi1_attributes
); ++i
)
859 device_remove_file(&dev
->dev
, hfi1_attributes
[i
]);
861 for (i
= 0; i
< dd
->num_sdma
; i
++)
862 kobject_del(&dd
->per_sdma
[i
].kobj
);
868 * Unregister and remove our files in /sys/class/infiniband.
870 void hfi1_verbs_unregister_sysfs(struct hfi1_devdata
*dd
)
872 struct hfi1_pportdata
*ppd
;
875 for (i
= 0; i
< dd
->num_pports
; i
++) {
878 sysfs_remove_bin_file(&ppd
->pport_cc_kobj
,
879 &cc_setting_bin_attr
);
880 sysfs_remove_bin_file(&ppd
->pport_cc_kobj
,
882 kobject_put(&ppd
->pport_cc_kobj
);
883 kobject_put(&ppd
->vl2mtu_kobj
);
884 kobject_put(&ppd
->sl2sc_kobj
);
885 kobject_put(&ppd
->sc2vl_kobj
);