1 /* ATM driver model support. */
3 #include <linux/kernel.h>
4 #include <linux/slab.h>
5 #include <linux/init.h>
6 #include <linux/kobject.h>
7 #include <linux/atmdev.h>
11 #define to_atm_dev(cldev) container_of(cldev, struct atm_dev, class_dev)
13 static ssize_t
show_type(struct device
*cdev
,
14 struct device_attribute
*attr
, char *buf
)
16 struct atm_dev
*adev
= to_atm_dev(cdev
);
18 return scnprintf(buf
, PAGE_SIZE
, "%s\n", adev
->type
);
21 static ssize_t
show_address(struct device
*cdev
,
22 struct device_attribute
*attr
, char *buf
)
24 struct atm_dev
*adev
= to_atm_dev(cdev
);
26 return scnprintf(buf
, PAGE_SIZE
, "%pM\n", adev
->esi
);
29 static ssize_t
show_atmaddress(struct device
*cdev
,
30 struct device_attribute
*attr
, char *buf
)
33 struct atm_dev
*adev
= to_atm_dev(cdev
);
34 struct atm_dev_addr
*aaddr
;
35 int bin
[] = { 1, 2, 10, 6, 1 }, *fmt
= bin
;
38 spin_lock_irqsave(&adev
->lock
, flags
);
39 list_for_each_entry(aaddr
, &adev
->local
, entry
) {
40 for (i
= 0, j
= 0; i
< ATM_ESA_LEN
; ++i
, ++j
) {
42 count
+= scnprintf(buf
+ count
,
43 PAGE_SIZE
- count
, ".");
47 count
+= scnprintf(buf
+ count
,
48 PAGE_SIZE
- count
, "%02x",
49 aaddr
->addr
.sas_addr
.prv
[i
]);
51 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
, "\n");
53 spin_unlock_irqrestore(&adev
->lock
, flags
);
58 static ssize_t
show_atmindex(struct device
*cdev
,
59 struct device_attribute
*attr
, char *buf
)
61 struct atm_dev
*adev
= to_atm_dev(cdev
);
63 return scnprintf(buf
, PAGE_SIZE
, "%d\n", adev
->number
);
66 static ssize_t
show_carrier(struct device
*cdev
,
67 struct device_attribute
*attr
, char *buf
)
69 struct atm_dev
*adev
= to_atm_dev(cdev
);
71 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
72 adev
->signal
== ATM_PHY_SIG_LOST
? 0 : 1);
75 static ssize_t
show_link_rate(struct device
*cdev
,
76 struct device_attribute
*attr
, char *buf
)
78 struct atm_dev
*adev
= to_atm_dev(cdev
);
81 /* show the link rate, not the data rate */
82 switch (adev
->link_rate
) {
84 link_rate
= 155520000;
87 link_rate
= 622080000;
93 link_rate
= adev
->link_rate
* 8 * 53;
95 return scnprintf(buf
, PAGE_SIZE
, "%d\n", link_rate
);
98 static DEVICE_ATTR(address
, S_IRUGO
, show_address
, NULL
);
99 static DEVICE_ATTR(atmaddress
, S_IRUGO
, show_atmaddress
, NULL
);
100 static DEVICE_ATTR(atmindex
, S_IRUGO
, show_atmindex
, NULL
);
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
);
105 static struct device_attribute
*atm_attrs
[] = {
106 &dev_attr_atmaddress
,
116 static int atm_uevent(struct device
*cdev
, struct kobj_uevent_env
*env
)
118 struct atm_dev
*adev
;
123 adev
= to_atm_dev(cdev
);
127 if (add_uevent_var(env
, "NAME=%s%d", adev
->type
, adev
->number
))
133 static void atm_release(struct device
*cdev
)
135 struct atm_dev
*adev
= to_atm_dev(cdev
);
140 static struct class atm_class
= {
142 .dev_release
= atm_release
,
143 .dev_uevent
= atm_uevent
,
146 int atm_register_sysfs(struct atm_dev
*adev
, struct device
*parent
)
148 struct device
*cdev
= &adev
->class_dev
;
151 cdev
->class = &atm_class
;
152 cdev
->parent
= parent
;
153 dev_set_drvdata(cdev
, adev
);
155 dev_set_name(cdev
, "%s%d", adev
->type
, adev
->number
);
156 err
= device_register(cdev
);
160 for (i
= 0; atm_attrs
[i
]; i
++) {
161 err
= device_create_file(cdev
, atm_attrs
[i
]);
169 for (j
= 0; j
< i
; j
++)
170 device_remove_file(cdev
, atm_attrs
[j
]);
175 void atm_unregister_sysfs(struct atm_dev
*adev
)
177 struct device
*cdev
= &adev
->class_dev
;
182 int __init
atm_sysfs_init(void)
184 return class_register(&atm_class
);
187 void __exit
atm_sysfs_exit(void)
189 class_unregister(&atm_class
);