[POWERPC] Generic DCR infrastructure
[linux-2.6.22.y-op.git] / net / atm / atm_sysfs.c
blob62f6ed1f2f98c9c5c25d70759f87d60e3e4f699d
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>
7 #include "common.h"
8 #include "resources.h"
10 #define to_atm_dev(cldev) container_of(cldev, struct atm_dev, class_dev)
12 static ssize_t show_type(struct class_device *cdev, char *buf)
14 struct atm_dev *adev = to_atm_dev(cdev);
15 return sprintf(buf, "%s\n", adev->type);
18 static ssize_t show_address(struct class_device *cdev, char *buf)
20 char *pos = buf;
21 struct atm_dev *adev = to_atm_dev(cdev);
22 int i;
24 for (i = 0; i < (ESI_LEN - 1); i++)
25 pos += sprintf(pos, "%02x:", adev->esi[i]);
26 pos += sprintf(pos, "%02x\n", adev->esi[i]);
28 return pos - buf;
31 static ssize_t show_atmaddress(struct class_device *cdev, char *buf)
33 unsigned long flags;
34 char *pos = buf;
35 struct atm_dev *adev = to_atm_dev(cdev);
36 struct atm_dev_addr *aaddr;
37 int bin[] = { 1, 2, 10, 6, 1 }, *fmt = bin;
38 int i, j;
40 spin_lock_irqsave(&adev->lock, flags);
41 list_for_each_entry(aaddr, &adev->local, entry) {
42 for(i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) {
43 if (j == *fmt) {
44 pos += sprintf(pos, ".");
45 ++fmt;
46 j = 0;
48 pos += sprintf(pos, "%02x", aaddr->addr.sas_addr.prv[i]);
50 pos += sprintf(pos, "\n");
52 spin_unlock_irqrestore(&adev->lock, flags);
54 return pos - buf;
57 static ssize_t show_carrier(struct class_device *cdev, char *buf)
59 char *pos = buf;
60 struct atm_dev *adev = to_atm_dev(cdev);
62 pos += sprintf(pos, "%d\n",
63 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
65 return pos - buf;
68 static ssize_t show_link_rate(struct class_device *cdev, char *buf)
70 char *pos = buf;
71 struct atm_dev *adev = to_atm_dev(cdev);
72 int link_rate;
74 /* show the link rate, not the data rate */
75 switch (adev->link_rate) {
76 case ATM_OC3_PCR:
77 link_rate = 155520000;
78 break;
79 case ATM_OC12_PCR:
80 link_rate = 622080000;
81 break;
82 case ATM_25_PCR:
83 link_rate = 25600000;
84 break;
85 default:
86 link_rate = adev->link_rate * 8 * 53;
88 pos += sprintf(pos, "%d\n", link_rate);
90 return pos - buf;
93 static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
94 static CLASS_DEVICE_ATTR(atmaddress, S_IRUGO, show_atmaddress, NULL);
95 static CLASS_DEVICE_ATTR(carrier, S_IRUGO, show_carrier, NULL);
96 static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
97 static CLASS_DEVICE_ATTR(link_rate, S_IRUGO, show_link_rate, NULL);
99 static struct class_device_attribute *atm_attrs[] = {
100 &class_device_attr_atmaddress,
101 &class_device_attr_address,
102 &class_device_attr_carrier,
103 &class_device_attr_type,
104 &class_device_attr_link_rate,
105 NULL
108 static int atm_uevent(struct class_device *cdev, char **envp, int num_envp, char *buf, int size)
110 struct atm_dev *adev;
111 int i = 0, len = 0;
113 if (!cdev)
114 return -ENODEV;
116 adev = to_atm_dev(cdev);
117 if (!adev)
118 return -ENODEV;
120 if (add_uevent_var(envp, num_envp, &i, buf, size, &len,
121 "NAME=%s%d", adev->type, adev->number))
122 return -ENOMEM;
124 envp[i] = NULL;
125 return 0;
128 static void atm_release(struct class_device *cdev)
130 struct atm_dev *adev = to_atm_dev(cdev);
132 kfree(adev);
135 static struct class atm_class = {
136 .name = "atm",
137 .release = atm_release,
138 .uevent = atm_uevent,
141 int atm_register_sysfs(struct atm_dev *adev)
143 struct class_device *cdev = &adev->class_dev;
144 int i, j, err;
146 cdev->class = &atm_class;
147 class_set_devdata(cdev, adev);
149 snprintf(cdev->class_id, BUS_ID_SIZE, "%s%d", adev->type, adev->number);
150 err = class_device_register(cdev);
151 if (err < 0)
152 return err;
154 for (i = 0; atm_attrs[i]; i++) {
155 err = class_device_create_file(cdev, atm_attrs[i]);
156 if (err)
157 goto err_out;
160 return 0;
162 err_out:
163 for (j = 0; j < i; j++)
164 class_device_remove_file(cdev, atm_attrs[j]);
165 class_device_del(cdev);
166 return err;
169 void atm_unregister_sysfs(struct atm_dev *adev)
171 struct class_device *cdev = &adev->class_dev;
173 class_device_del(cdev);
176 int __init atm_sysfs_init(void)
178 return class_register(&atm_class);
181 void __exit atm_sysfs_exit(void)
183 class_unregister(&atm_class);