Files
linux-apfs/net/atm/atm_sysfs.c
T

191 lines
4.1 KiB
C
Raw Normal View History

2006-06-29 12:36:34 -07:00
/* ATM driver model support. */
#include <linux/kernel.h>
#include <linux/slab.h>
2006-06-29 12:36:34 -07:00
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/atmdev.h>
#include "common.h"
#include "resources.h"
#define to_atm_dev(cldev) container_of(cldev, struct atm_dev, class_dev)
static ssize_t show_type(struct device *cdev,
struct device_attribute *attr, char *buf)
2006-06-29 12:36:34 -07:00
{
struct atm_dev *adev = to_atm_dev(cdev);
2012-12-17 06:00:01 +00:00
return scnprintf(buf, PAGE_SIZE, "%s\n", adev->type);
2006-06-29 12:36:34 -07:00
}
static ssize_t show_address(struct device *cdev,
struct device_attribute *attr, char *buf)
2006-06-29 12:36:34 -07:00
{
struct atm_dev *adev = to_atm_dev(cdev);
2012-12-17 06:00:01 +00:00
return scnprintf(buf, PAGE_SIZE, "%pM\n", adev->esi);
2006-06-29 12:36:34 -07:00
}
static ssize_t show_atmaddress(struct device *cdev,
struct device_attribute *attr, char *buf)
2006-06-29 12:36:34 -07:00
{
2007-02-09 23:24:29 +09:00
unsigned long flags;
2006-06-29 12:36:34 -07:00
struct atm_dev *adev = to_atm_dev(cdev);
2007-02-09 23:24:29 +09:00
struct atm_dev_addr *aaddr;
2006-06-29 12:36:34 -07:00
int bin[] = { 1, 2, 10, 6, 1 }, *fmt = bin;
2012-12-17 06:00:01 +00:00
int i, j, count = 0;
2006-06-29 12:36:34 -07:00
2007-02-09 23:24:29 +09:00
spin_lock_irqsave(&adev->lock, flags);
list_for_each_entry(aaddr, &adev->local, entry) {
2010-01-26 11:40:03 +00:00
for (i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) {
2006-06-29 12:36:34 -07:00
if (j == *fmt) {
2012-12-17 06:00:01 +00:00
count += scnprintf(buf + count,
PAGE_SIZE - count, ".");
2006-06-29 12:36:34 -07:00
++fmt;
j = 0;
}
2012-12-17 06:00:01 +00:00
count += scnprintf(buf + count,
PAGE_SIZE - count, "%02x",
aaddr->addr.sas_addr.prv[i]);
2006-06-29 12:36:34 -07:00
}
2012-12-17 06:00:01 +00:00
count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
2006-06-29 12:36:34 -07:00
}
2007-02-09 23:24:29 +09:00
spin_unlock_irqrestore(&adev->lock, flags);
2006-06-29 12:36:34 -07:00
2012-12-17 06:00:01 +00:00
return count;
2006-06-29 12:36:34 -07:00
}
2011-05-27 04:51:54 +00:00
static ssize_t show_atmindex(struct device *cdev,
struct device_attribute *attr, char *buf)
{
struct atm_dev *adev = to_atm_dev(cdev);
2012-12-17 06:00:01 +00:00
return scnprintf(buf, PAGE_SIZE, "%d\n", adev->number);
2011-05-27 04:51:54 +00:00
}
static ssize_t show_carrier(struct device *cdev,
struct device_attribute *attr, char *buf)
2006-06-29 12:36:34 -07:00
{
struct atm_dev *adev = to_atm_dev(cdev);
2012-12-17 06:00:01 +00:00
return scnprintf(buf, PAGE_SIZE, "%d\n",
adev->signal == ATM_PHY_SIG_LOST ? 0 : 1);
2006-06-29 12:36:34 -07:00
}
static ssize_t show_link_rate(struct device *cdev,
struct device_attribute *attr, char *buf)
2006-06-29 12:36:34 -07:00
{
struct atm_dev *adev = to_atm_dev(cdev);
int link_rate;
/* show the link rate, not the data rate */
switch (adev->link_rate) {
2010-01-26 11:40:03 +00:00
case ATM_OC3_PCR:
link_rate = 155520000;
break;
case ATM_OC12_PCR:
link_rate = 622080000;
break;
case ATM_25_PCR:
link_rate = 25600000;
break;
default:
link_rate = adev->link_rate * 8 * 53;
2006-06-29 12:36:34 -07:00
}
2012-12-17 06:00:01 +00:00
return scnprintf(buf, PAGE_SIZE, "%d\n", link_rate);
2006-06-29 12:36:34 -07:00
}
static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
static DEVICE_ATTR(atmaddress, S_IRUGO, show_atmaddress, NULL);
2011-05-27 04:51:54 +00:00
static DEVICE_ATTR(atmindex, S_IRUGO, show_atmindex, NULL);
static DEVICE_ATTR(carrier, S_IRUGO, show_carrier, NULL);
static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
static DEVICE_ATTR(link_rate, S_IRUGO, show_link_rate, NULL);
2006-06-29 12:36:34 -07:00
static struct device_attribute *atm_attrs[] = {
&dev_attr_atmaddress,
&dev_attr_address,
2011-05-27 04:51:54 +00:00
&dev_attr_atmindex,
&dev_attr_carrier,
&dev_attr_type,
&dev_attr_link_rate,
2006-06-29 12:36:34 -07:00
NULL
};
static int atm_uevent(struct device *cdev, struct kobj_uevent_env *env)
2006-06-29 12:36:34 -07:00
{
struct atm_dev *adev;
if (!cdev)
return -ENODEV;
adev = to_atm_dev(cdev);
if (!adev)
return -ENODEV;
if (add_uevent_var(env, "NAME=%s%d", adev->type, adev->number))
2006-06-29 12:36:34 -07:00
return -ENOMEM;
return 0;
}
static void atm_release(struct device *cdev)
2006-06-29 12:36:34 -07:00
{
struct atm_dev *adev = to_atm_dev(cdev);
kfree(adev);
}
static struct class atm_class = {
.name = "atm",
.dev_release = atm_release,
.dev_uevent = atm_uevent,
2006-06-29 12:36:34 -07:00
};
int atm_register_sysfs(struct atm_dev *adev, struct device *parent)
2006-06-29 12:36:34 -07:00
{
struct device *cdev = &adev->class_dev;
2006-10-20 19:48:42 -07:00
int i, j, err;
2006-06-29 12:36:34 -07:00
cdev->class = &atm_class;
cdev->parent = parent;
dev_set_drvdata(cdev, adev);
2006-06-29 12:36:34 -07:00
dev_set_name(cdev, "%s%d", adev->type, adev->number);
err = device_register(cdev);
2006-06-29 12:36:34 -07:00
if (err < 0)
return err;
2006-10-20 19:48:42 -07:00
for (i = 0; atm_attrs[i]; i++) {
err = device_create_file(cdev, atm_attrs[i]);
2006-10-20 19:48:42 -07:00
if (err)
goto err_out;
}
2006-06-29 12:36:34 -07:00
return 0;
2006-10-20 19:48:42 -07:00
err_out:
for (j = 0; j < i; j++)
device_remove_file(cdev, atm_attrs[j]);
device_del(cdev);
2006-10-20 19:48:42 -07:00
return err;
2006-06-29 12:36:34 -07:00
}
void atm_unregister_sysfs(struct atm_dev *adev)
{
struct device *cdev = &adev->class_dev;
2006-06-29 12:36:34 -07:00
device_del(cdev);
2006-06-29 12:36:34 -07:00
}
int __init atm_sysfs_init(void)
{
return class_register(&atm_class);
}
void __exit atm_sysfs_exit(void)
{
class_unregister(&atm_class);
}