1 /* ATM driver model support. */
3 #include <linux/config.h>
4 #include <linux/kernel.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 class_device
*cdev
, 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 class_device
*cdev
, char *buf
)
22 struct atm_dev
*adev
= to_atm_dev(cdev
);
25 for (i
= 0; i
< (ESI_LEN
- 1); i
++)
26 pos
+= sprintf(pos
, "%02x:", adev
->esi
[i
]);
27 pos
+= sprintf(pos
, "%02x\n", adev
->esi
[i
]);
32 static ssize_t
show_atmaddress(struct class_device
*cdev
, char *buf
)
36 struct atm_dev
*adev
= to_atm_dev(cdev
);
37 struct atm_dev_addr
*aaddr
;
38 int bin
[] = { 1, 2, 10, 6, 1 }, *fmt
= bin
;
41 spin_lock_irqsave(&adev
->lock
, flags
);
42 list_for_each_entry(aaddr
, &adev
->local
, entry
) {
43 for(i
= 0, j
= 0; i
< ATM_ESA_LEN
; ++i
, ++j
) {
45 pos
+= sprintf(pos
, ".");
49 pos
+= sprintf(pos
, "%02x", aaddr
->addr
.sas_addr
.prv
[i
]);
51 pos
+= sprintf(pos
, "\n");
53 spin_unlock_irqrestore(&adev
->lock
, flags
);
58 static ssize_t
show_carrier(struct class_device
*cdev
, char *buf
)
61 struct atm_dev
*adev
= to_atm_dev(cdev
);
63 pos
+= sprintf(pos
, "%d\n",
64 adev
->signal
== ATM_PHY_SIG_LOST
? 0 : 1);
69 static ssize_t
show_link_rate(struct class_device
*cdev
, char *buf
)
72 struct atm_dev
*adev
= to_atm_dev(cdev
);
75 /* show the link rate, not the data rate */
76 switch (adev
->link_rate
) {
78 link_rate
= 155520000;
81 link_rate
= 622080000;
87 link_rate
= adev
->link_rate
* 8 * 53;
89 pos
+= sprintf(pos
, "%d\n", link_rate
);
94 static CLASS_DEVICE_ATTR(address
, S_IRUGO
, show_address
, NULL
);
95 static CLASS_DEVICE_ATTR(atmaddress
, S_IRUGO
, show_atmaddress
, NULL
);
96 static CLASS_DEVICE_ATTR(carrier
, S_IRUGO
, show_carrier
, NULL
);
97 static CLASS_DEVICE_ATTR(type
, S_IRUGO
, show_type
, NULL
);
98 static CLASS_DEVICE_ATTR(link_rate
, S_IRUGO
, show_link_rate
, NULL
);
100 static struct class_device_attribute
*atm_attrs
[] = {
101 &class_device_attr_atmaddress
,
102 &class_device_attr_address
,
103 &class_device_attr_carrier
,
104 &class_device_attr_type
,
105 &class_device_attr_link_rate
,
109 static int atm_uevent(struct class_device
*cdev
, char **envp
, int num_envp
, char *buf
, int size
)
111 struct atm_dev
*adev
;
117 adev
= to_atm_dev(cdev
);
121 if (add_uevent_var(envp
, num_envp
, &i
, buf
, size
, &len
,
122 "NAME=%s%d", adev
->type
, adev
->number
))
129 static void atm_release(struct class_device
*cdev
)
131 struct atm_dev
*adev
= to_atm_dev(cdev
);
136 static struct class atm_class
= {
138 .release
= atm_release
,
139 .uevent
= atm_uevent
,
142 int atm_register_sysfs(struct atm_dev
*adev
)
144 struct class_device
*cdev
= &adev
->class_dev
;
147 cdev
->class = &atm_class
;
148 class_set_devdata(cdev
, adev
);
150 snprintf(cdev
->class_id
, BUS_ID_SIZE
, "%s%d", adev
->type
, adev
->number
);
151 err
= class_device_register(cdev
);
155 for (i
= 0; atm_attrs
[i
]; i
++)
156 class_device_create_file(cdev
, atm_attrs
[i
]);
161 void atm_unregister_sysfs(struct atm_dev
*adev
)
163 struct class_device
*cdev
= &adev
->class_dev
;
165 class_device_del(cdev
);
168 int __init
atm_sysfs_init(void)
170 return class_register(&atm_class
);
173 void __exit
atm_sysfs_exit(void)
175 class_unregister(&atm_class
);