SCSI: scsi_dh: check queuedata pointer before proceeding further
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / atm / atm_sysfs.c
blob7bbe81ee917f6faaf05303a35548e449ecde974d
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 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)
22 char *pos = buf;
23 struct atm_dev *adev = to_atm_dev(cdev);
24 int i;
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]);
30 return pos - buf;
33 static ssize_t show_atmaddress(struct device *cdev,
34 struct device_attribute *attr, char *buf)
36 unsigned long flags;
37 char *pos = 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;
41 int i, j;
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) {
46 if (j == *fmt) {
47 pos += sprintf(pos, ".");
48 ++fmt;
49 j = 0;
51 pos += sprintf(pos, "%02x", aaddr->addr.sas_addr.prv[i]);
53 pos += sprintf(pos, "\n");
55 spin_unlock_irqrestore(&adev->lock, flags);
57 return pos - buf;
60 static ssize_t show_atmindex(struct device *cdev,
61 struct device_attribute *attr, char *buf)
63 struct atm_dev *adev = to_atm_dev(cdev);
65 return sprintf(buf, "%d\n", adev->number);
68 static ssize_t show_carrier(struct device *cdev,
69 struct device_attribute *attr, char *buf)
71 char *pos = buf;
72 struct atm_dev *adev = to_atm_dev(cdev);
74 pos += sprintf(pos, "%d\n",
75 adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
77 return pos - buf;
80 static ssize_t show_link_rate(struct device *cdev,
81 struct device_attribute *attr, char *buf)
83 char *pos = buf;
84 struct atm_dev *adev = to_atm_dev(cdev);
85 int link_rate;
87 /* show the link rate, not the data rate */
88 switch (adev->link_rate) {
89 case ATM_OC3_PCR:
90 link_rate = 155520000;
91 break;
92 case ATM_OC12_PCR:
93 link_rate = 622080000;
94 break;
95 case ATM_25_PCR:
96 link_rate = 25600000;
97 break;
98 default:
99 link_rate = adev->link_rate * 8 * 53;
101 pos += sprintf(pos, "%d\n", link_rate);
103 return pos - buf;
106 static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
107 static DEVICE_ATTR(atmaddress, S_IRUGO, show_atmaddress, NULL);
108 static DEVICE_ATTR(atmindex, S_IRUGO, show_atmindex, NULL);
109 static DEVICE_ATTR(carrier, S_IRUGO, show_carrier, NULL);
110 static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
111 static DEVICE_ATTR(link_rate, S_IRUGO, show_link_rate, NULL);
113 static struct device_attribute *atm_attrs[] = {
114 &dev_attr_atmaddress,
115 &dev_attr_address,
116 &dev_attr_atmindex,
117 &dev_attr_carrier,
118 &dev_attr_type,
119 &dev_attr_link_rate,
120 NULL
124 static int atm_uevent(struct device *cdev, struct kobj_uevent_env *env)
126 struct atm_dev *adev;
128 if (!cdev)
129 return -ENODEV;
131 adev = to_atm_dev(cdev);
132 if (!adev)
133 return -ENODEV;
135 if (add_uevent_var(env, "NAME=%s%d", adev->type, adev->number))
136 return -ENOMEM;
138 return 0;
141 static void atm_release(struct device *cdev)
143 struct atm_dev *adev = to_atm_dev(cdev);
145 kfree(adev);
148 static struct class atm_class = {
149 .name = "atm",
150 .dev_release = atm_release,
151 .dev_uevent = atm_uevent,
154 int atm_register_sysfs(struct atm_dev *adev)
156 struct device *cdev = &adev->class_dev;
157 int i, j, err;
159 cdev->class = &atm_class;
160 dev_set_drvdata(cdev, adev);
162 dev_set_name(cdev, "%s%d", adev->type, adev->number);
163 err = device_register(cdev);
164 if (err < 0)
165 return err;
167 for (i = 0; atm_attrs[i]; i++) {
168 err = device_create_file(cdev, atm_attrs[i]);
169 if (err)
170 goto err_out;
173 return 0;
175 err_out:
176 for (j = 0; j < i; j++)
177 device_remove_file(cdev, atm_attrs[j]);
178 device_del(cdev);
179 return err;
182 void atm_unregister_sysfs(struct atm_dev *adev)
184 struct device *cdev = &adev->class_dev;
186 device_del(cdev);
189 int __init atm_sysfs_init(void)
191 return class_register(&atm_class);
194 void __exit atm_sysfs_exit(void)
196 class_unregister(&atm_class);