dm integrity: fix ppc64le warning
[linux-2.6-block.git] / net / atm / atm_sysfs.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
656d98b0
RK
2/* ATM driver model support. */
3
656d98b0 4#include <linux/kernel.h>
5a0e3ad6 5#include <linux/slab.h>
656d98b0
RK
6#include <linux/init.h>
7#include <linux/kobject.h>
8#include <linux/atmdev.h>
9#include "common.h"
10#include "resources.h"
11
12#define to_atm_dev(cldev) container_of(cldev, struct atm_dev, class_dev)
13
ef39592f
KS
14static ssize_t show_type(struct device *cdev,
15 struct device_attribute *attr, char *buf)
656d98b0
RK
16{
17 struct atm_dev *adev = to_atm_dev(cdev);
3c417771
C
18
19 return scnprintf(buf, PAGE_SIZE, "%s\n", adev->type);
656d98b0
RK
20}
21
ef39592f
KS
22static ssize_t show_address(struct device *cdev,
23 struct device_attribute *attr, char *buf)
656d98b0 24{
656d98b0 25 struct atm_dev *adev = to_atm_dev(cdev);
656d98b0 26
3c417771 27 return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
656d98b0
RK
28}
29
ef39592f
KS
30static ssize_t show_atmaddress(struct device *cdev,
31 struct device_attribute *attr, char *buf)
656d98b0 32{
f7d57453 33 unsigned long flags;
656d98b0 34 struct atm_dev *adev = to_atm_dev(cdev);
f7d57453 35 struct atm_dev_addr *aaddr;
79ac5224 36 int count = 0;
656d98b0 37
f7d57453
YH
38 spin_lock_irqsave(&adev->lock, flags);
39 list_for_each_entry(aaddr, &adev->local, entry) {
79ac5224
AS
40 count += scnprintf(buf + count, PAGE_SIZE - count,
41 "%1phN.%2phN.%10phN.%6phN.%1phN\n",
42 &aaddr->addr.sas_addr.prv[0],
43 &aaddr->addr.sas_addr.prv[1],
44 &aaddr->addr.sas_addr.prv[3],
45 &aaddr->addr.sas_addr.prv[13],
46 &aaddr->addr.sas_addr.prv[19]);
656d98b0 47 }
f7d57453 48 spin_unlock_irqrestore(&adev->lock, flags);
656d98b0 49
3c417771 50 return count;
656d98b0
RK
51}
52
e7a46b4d
DW
53static ssize_t show_atmindex(struct device *cdev,
54 struct device_attribute *attr, char *buf)
55{
56 struct atm_dev *adev = to_atm_dev(cdev);
57
3c417771 58 return scnprintf(buf, PAGE_SIZE, "%d\n", adev->number);
e7a46b4d
DW
59}
60
ef39592f
KS
61static ssize_t show_carrier(struct device *cdev,
62 struct device_attribute *attr, char *buf)
656d98b0 63{
656d98b0
RK
64 struct atm_dev *adev = to_atm_dev(cdev);
65
3c417771
C
66 return scnprintf(buf, PAGE_SIZE, "%d\n",
67 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
656d98b0
RK
68}
69
ef39592f
KS
70static ssize_t show_link_rate(struct device *cdev,
71 struct device_attribute *attr, char *buf)
656d98b0 72{
656d98b0
RK
73 struct atm_dev *adev = to_atm_dev(cdev);
74 int link_rate;
75
76 /* show the link rate, not the data rate */
77 switch (adev->link_rate) {
f0a6cb11
JP
78 case ATM_OC3_PCR:
79 link_rate = 155520000;
80 break;
81 case ATM_OC12_PCR:
82 link_rate = 622080000;
83 break;
84 case ATM_25_PCR:
85 link_rate = 25600000;
86 break;
87 default:
88 link_rate = adev->link_rate * 8 * 53;
656d98b0 89 }
3c417771 90 return scnprintf(buf, PAGE_SIZE, "%d\n", link_rate);
656d98b0
RK
91}
92
d6444062
JP
93static DEVICE_ATTR(address, 0444, show_address, NULL);
94static DEVICE_ATTR(atmaddress, 0444, show_atmaddress, NULL);
95static DEVICE_ATTR(atmindex, 0444, show_atmindex, NULL);
96static DEVICE_ATTR(carrier, 0444, show_carrier, NULL);
97static DEVICE_ATTR(type, 0444, show_type, NULL);
98static DEVICE_ATTR(link_rate, 0444, show_link_rate, NULL);
ef39592f
KS
99
100static struct device_attribute *atm_attrs[] = {
101 &dev_attr_atmaddress,
102 &dev_attr_address,
e7a46b4d 103 &dev_attr_atmindex,
ef39592f
KS
104 &dev_attr_carrier,
105 &dev_attr_type,
106 &dev_attr_link_rate,
656d98b0
RK
107 NULL
108};
109
ef39592f
KS
110
111static int atm_uevent(struct device *cdev, struct kobj_uevent_env *env)
656d98b0
RK
112{
113 struct atm_dev *adev;
656d98b0
RK
114
115 if (!cdev)
116 return -ENODEV;
117
118 adev = to_atm_dev(cdev);
119 if (!adev)
120 return -ENODEV;
121
7eff2e7a 122 if (add_uevent_var(env, "NAME=%s%d", adev->type, adev->number))
656d98b0
RK
123 return -ENOMEM;
124
656d98b0
RK
125 return 0;
126}
127
ef39592f 128static void atm_release(struct device *cdev)
656d98b0
RK
129{
130 struct atm_dev *adev = to_atm_dev(cdev);
131
132 kfree(adev);
133}
134
135static struct class atm_class = {
136 .name = "atm",
ef39592f
KS
137 .dev_release = atm_release,
138 .dev_uevent = atm_uevent,
656d98b0
RK
139};
140
d9ca676b 141int atm_register_sysfs(struct atm_dev *adev, struct device *parent)
656d98b0 142{
ef39592f 143 struct device *cdev = &adev->class_dev;
97f80bc6 144 int i, j, err;
656d98b0
RK
145
146 cdev->class = &atm_class;
d9ca676b 147 cdev->parent = parent;
ef39592f 148 dev_set_drvdata(cdev, adev);
656d98b0 149
fb28ad35 150 dev_set_name(cdev, "%s%d", adev->type, adev->number);
ef39592f 151 err = device_register(cdev);
656d98b0
RK
152 if (err < 0)
153 return err;
154
97f80bc6 155 for (i = 0; atm_attrs[i]; i++) {
ef39592f 156 err = device_create_file(cdev, atm_attrs[i]);
97f80bc6
JG
157 if (err)
158 goto err_out;
159 }
656d98b0
RK
160
161 return 0;
97f80bc6
JG
162
163err_out:
164 for (j = 0; j < i; j++)
ef39592f
KS
165 device_remove_file(cdev, atm_attrs[j]);
166 device_del(cdev);
97f80bc6 167 return err;
656d98b0
RK
168}
169
170void atm_unregister_sysfs(struct atm_dev *adev)
171{
ef39592f 172 struct device *cdev = &adev->class_dev;
656d98b0 173
ef39592f 174 device_del(cdev);
656d98b0
RK
175}
176
177int __init atm_sysfs_init(void)
178{
179 return class_register(&atm_class);
180}
181
182void __exit atm_sysfs_exit(void)
183{
184 class_unregister(&atm_class);
185}