1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * transport_class.h - a generic container for all transport classes
5 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
8 #ifndef _TRANSPORT_CLASS_H_
9 #define _TRANSPORT_CLASS_H_
11 #include <linux/device.h>
12 #include <linux/bug.h>
13 #include <linux/attribute_container.h>
15 struct transport_container;
17 struct transport_class {
19 int (*setup)(struct transport_container *, struct device *,
21 int (*configure)(struct transport_container *, struct device *,
23 int (*remove)(struct transport_container *, struct device *,
27 #define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg) \
28 struct transport_class cls = { \
38 struct anon_transport_class {
39 struct transport_class tclass;
40 struct attribute_container container;
43 #define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg) \
44 struct anon_transport_class cls = { \
53 #define class_to_transport_class(x) \
54 container_of(x, struct transport_class, class)
56 struct transport_container {
57 struct attribute_container ac;
58 const struct attribute_group *statistics;
61 #define attribute_container_to_transport_container(x) \
62 container_of(x, struct transport_container, ac)
64 void transport_remove_device(struct device *);
65 int transport_add_device(struct device *);
66 void transport_setup_device(struct device *);
67 void transport_configure_device(struct device *);
68 void transport_destroy_device(struct device *);
71 transport_register_device(struct device *dev)
75 transport_setup_device(dev);
76 ret = transport_add_device(dev);
78 transport_destroy_device(dev);
84 transport_unregister_device(struct device *dev)
86 transport_remove_device(dev);
87 transport_destroy_device(dev);
90 static inline int transport_container_register(struct transport_container *tc)
92 return attribute_container_register(&tc->ac);
95 static inline void transport_container_unregister(struct transport_container *tc)
97 if (unlikely(attribute_container_unregister(&tc->ac)))
101 int transport_class_register(struct transport_class *);
102 int anon_transport_class_register(struct anon_transport_class *);
103 void transport_class_unregister(struct transport_class *);
104 void anon_transport_class_unregister(struct anon_transport_class *);