1 /* ATM driver model support. */
3 #include <linux/kernel.h>
4 #include <linux/init.h>
5 #include <linux/kobject.h>
6 #include <linux/atmdev.h>
10 #define to_atm_dev(cldev) container_of(cldev, struct atm_dev, class_dev)
12 static ssize_t
show_type(struct device
*cdev
,
13 struct device_attribute
*attr
, char *buf
)
15 struct atm_dev
*adev
= to_atm_dev(cdev
);
16 return sprintf(buf
, "%s\n", adev
->type
);
19 static ssize_t
show_address(struct device
*cdev
,
20 struct device_attribute
*attr
, char *buf
)
23 struct atm_dev
*adev
= to_atm_dev(cdev
);
26 for (i
= 0; i
< (ESI_LEN
- 1); i
++)
27 pos
+= sprintf(pos
, "%02x:", adev
->esi
[i
]);
28 pos
+= sprintf(pos
, "%02x\n", adev
->esi
[i
]);
33 static ssize_t
show_atmaddress(struct device
*cdev
,
34 struct device_attribute
*attr
, char *buf
)
38 struct atm_dev
*adev
= to_atm_dev(cdev
);
39 struct atm_dev_addr
*aaddr
;
40 int bin
[] = { 1, 2, 10, 6, 1 }, *fmt
= bin
;
43 spin_lock_irqsave(&adev
->lock
, flags
);
44 list_for_each_entry(aaddr
, &adev
->local
, entry
) {
45 for (i
= 0, j
= 0; i
< ATM_ESA_LEN
; ++i
, ++j
) {
47 pos
+= sprintf(pos
, ".");
51 pos
+= sprintf(pos
, "%02x",
52 aaddr
->addr
.sas_addr
.prv
[i
]);
54 pos
+= sprintf(pos
, "\n");
56 spin_unlock_irqrestore(&adev
->lock
, flags
);
61 static ssize_t
show_carrier(struct device
*cdev
,
62 struct device_attribute
*attr
, char *buf
)
65 struct atm_dev
*adev
= to_atm_dev(cdev
);
67 pos
+= sprintf(pos
, "%d\n",
68 adev
->signal
== ATM_PHY_SIG_LOST
? 0 : 1);
73 static ssize_t
show_link_rate(struct device
*cdev
,
74 struct device_attribute
*attr
, char *buf
)
77 struct atm_dev
*adev
= to_atm_dev(cdev
);
80 /* show the link rate, not the data rate */
81 switch (adev
->link_rate
) {
83 link_rate
= 155520000;
86 link_rate
= 622080000;
92 link_rate
= adev
->link_rate
* 8 * 53;
94 pos
+= sprintf(pos
, "%d\n", link_rate
);
99 static DEVICE_ATTR(address
, S_IRUGO
, show_address
, NULL
);
100 static DEVICE_ATTR(atmaddress
, S_IRUGO
, show_atmaddress
, 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
,
115 static int atm_uevent(struct device
*cdev
, struct kobj_uevent_env
*env
)
117 struct atm_dev
*adev
;
122 adev
= to_atm_dev(cdev
);
126 if (add_uevent_var(env
, "NAME=%s%d", adev
->type
, adev
->number
))
132 static void atm_release(struct device
*cdev
)
134 struct atm_dev
*adev
= to_atm_dev(cdev
);
139 static struct class atm_class
= {
141 .dev_release
= atm_release
,
142 .dev_uevent
= atm_uevent
,
145 int atm_register_sysfs(struct atm_dev
*adev
)
147 struct device
*cdev
= &adev
->class_dev
;
150 cdev
->class = &atm_class
;
151 dev_set_drvdata(cdev
, adev
);
153 dev_set_name(cdev
, "%s%d", adev
->type
, adev
->number
);
154 err
= device_register(cdev
);
158 for (i
= 0; atm_attrs
[i
]; i
++) {
159 err
= device_create_file(cdev
, atm_attrs
[i
]);
167 for (j
= 0; j
< i
; j
++)
168 device_remove_file(cdev
, atm_attrs
[j
]);
173 void atm_unregister_sysfs(struct atm_dev
*adev
)
175 struct device
*cdev
= &adev
->class_dev
;
180 int __init
atm_sysfs_init(void)
182 return class_register(&atm_class
);
185 void __exit
atm_sysfs_exit(void)
187 class_unregister(&atm_class
);