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