1 #include <linux/device.h>
2 #include <linux/kernel.h>
3 #include <linux/sysfs.h>
6 #include <linux/tapi/tapi.h>
8 struct tapi_sysfs_port
{
9 struct tapi_device
*tdev
;
14 struct tapi_sysfs_entry
{
15 ssize_t (*show
)(struct tapi_device
*, unsigned int port
, char *);
16 ssize_t (*store
)(struct tapi_device
*, unsigned int port
, const char *, size_t);
17 struct attribute attr
;
20 static ssize_t
tapi_port_store(struct kobject
*kobj
, struct attribute
*attr
,
21 const char *s
, size_t len
)
23 struct tapi_sysfs_port
*port
= container_of(kobj
, struct tapi_sysfs_port
, kobj
);
24 struct tapi_sysfs_entry
*entry
= container_of(attr
, struct tapi_sysfs_entry
,
30 return entry
->store(port
->tdev
, port
->id
, s
, len
);
33 static ssize_t
tapi_port_show(struct kobject
*kobj
, struct attribute
*attr
,
39 #define TAPI_PORT_ATTR(_name, _mode, _show, _store) \
40 struct tapi_sysfs_entry tapi_port_ ## _name ## _attr = \
41 __ATTR(_name, _mode, _show, _store)
43 static int tapi_port_store_ring(struct tapi_device
*tdev
, unsigned int port
,
44 const char *s
, size_t len
)
49 ret
= strict_strtoul(s
, 10, &val
);
54 ret
= tapi_port_set_ring(tdev
, &tdev
->ports
[port
], val
);
60 static TAPI_PORT_ATTR(ring
, 0644, NULL
, tapi_port_store_ring
);
62 static struct attribute
*tapi_port_default_attrs
[] = {
63 &tapi_port_ring_attr
.attr
,
67 static void tapi_port_free(struct kobject
*kobj
)
69 struct tapi_sysfs_port
*port
= container_of(kobj
, struct tapi_sysfs_port
, kobj
);
73 static struct sysfs_ops tapi_port_sysfs_ops
= {
74 .show
= tapi_port_show
,
75 .store
= tapi_port_store
,
78 static struct kobj_type tapi_port_ktype
= {
79 .release
= tapi_port_free
,
80 .sysfs_ops
= &tapi_port_sysfs_ops
,
81 .default_attrs
= tapi_port_default_attrs
,
84 struct tapi_sysfs_port
*tapi_port_alloc(struct tapi_device
*tdev
, unsigned int id
)
86 struct tapi_sysfs_port
*port
;
89 port
= kzalloc(sizeof(*port
), GFP_KERNEL
);
93 ret
= kobject_init_and_add(&port
->kobj
, &tapi_port_ktype
, &tdev
->dev
.kobj
,
103 void tapi_port_delete(struct tapi_sysfs_port
*port
)
105 kobject_del(&port
->kobj
);
106 kobject_put(&port
->kobj
);