blob: 11087cdd4ad3e2856659d13a00117bd909c07711 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * transport_class.h - a generic container for all transport classes
3 *
4 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
5 *
6 * This file is licensed under GPLv2
7 */
8
9#ifndef _TRANSPORT_CLASS_H_
10#define _TRANSPORT_CLASS_H_
11
12#include <linux/device.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050013#include <linux/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/attribute_container.h>
15
James Bottomleyd0a7e572005-08-14 17:09:01 -050016struct transport_container;
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018struct transport_class {
19 struct class class;
James Bottomleyd0a7e572005-08-14 17:09:01 -050020 int (*setup)(struct transport_container *, struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010021 struct device *);
James Bottomleyd0a7e572005-08-14 17:09:01 -050022 int (*configure)(struct transport_container *, struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010023 struct device *);
James Bottomleyd0a7e572005-08-14 17:09:01 -050024 int (*remove)(struct transport_container *, struct device *,
Tony Jonesee959b02008-02-22 00:13:36 +010025 struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026};
27
28#define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg) \
29struct transport_class cls = { \
30 .class = { \
31 .name = nm, \
32 }, \
33 .setup = su, \
34 .remove = rm, \
35 .configure = cfg, \
36}
37
38
39struct anon_transport_class {
40 struct transport_class tclass;
41 struct attribute_container container;
42};
43
44#define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg) \
45struct anon_transport_class cls = { \
46 .tclass = { \
47 .configure = cfg, \
48 }, \
49 . container = { \
50 .match = mtch, \
51 }, \
52}
53
54#define class_to_transport_class(x) \
55 container_of(x, struct transport_class, class)
56
57struct transport_container {
58 struct attribute_container ac;
David Brownella4dbd672009-06-24 10:06:31 -070059 const struct attribute_group *statistics;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
62#define attribute_container_to_transport_container(x) \
63 container_of(x, struct transport_container, ac)
64
65void transport_remove_device(struct device *);
66void transport_add_device(struct device *);
67void transport_setup_device(struct device *);
68void transport_configure_device(struct device *);
69void transport_destroy_device(struct device *);
70
71static inline void
72transport_register_device(struct device *dev)
73{
74 transport_setup_device(dev);
75 transport_add_device(dev);
76}
77
78static inline void
79transport_unregister_device(struct device *dev)
80{
81 transport_remove_device(dev);
82 transport_destroy_device(dev);
83}
84
85static inline int transport_container_register(struct transport_container *tc)
86{
87 return attribute_container_register(&tc->ac);
88}
89
James Bottomley2f3edc692008-04-02 10:05:48 -050090static inline void transport_container_unregister(struct transport_container *tc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
James Bottomley2f3edc692008-04-02 10:05:48 -050092 if (unlikely(attribute_container_unregister(&tc->ac)))
93 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
96int transport_class_register(struct transport_class *);
97int anon_transport_class_register(struct anon_transport_class *);
98void transport_class_unregister(struct transport_class *);
99void anon_transport_class_unregister(struct anon_transport_class *);
100
101
102#endif