Merge tag 'perf-tools-for-v6.4-3-2023-05-06' of git://git.kernel.org/pub/scm/linux...
[linux-block.git] / include / linux / transport_class.h
CommitLineData
82664963 1/* SPDX-License-Identifier: GPL-2.0-only */
1da177e4
LT
2/*
3 * transport_class.h - a generic container for all transport classes
4 *
5 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
1da177e4
LT
6 */
7
8#ifndef _TRANSPORT_CLASS_H_
9#define _TRANSPORT_CLASS_H_
10
11#include <linux/device.h>
187f1882 12#include <linux/bug.h>
1da177e4
LT
13#include <linux/attribute_container.h>
14
d0a7e574
JB
15struct transport_container;
16
1da177e4
LT
17struct transport_class {
18 struct class class;
d0a7e574 19 int (*setup)(struct transport_container *, struct device *,
ee959b00 20 struct device *);
d0a7e574 21 int (*configure)(struct transport_container *, struct device *,
ee959b00 22 struct device *);
d0a7e574 23 int (*remove)(struct transport_container *, struct device *,
ee959b00 24 struct device *);
1da177e4
LT
25};
26
27#define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg) \
28struct transport_class cls = { \
29 .class = { \
30 .name = nm, \
31 }, \
32 .setup = su, \
33 .remove = rm, \
34 .configure = cfg, \
35}
36
37
38struct anon_transport_class {
39 struct transport_class tclass;
40 struct attribute_container container;
41};
42
43#define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg) \
44struct anon_transport_class cls = { \
45 .tclass = { \
46 .configure = cfg, \
47 }, \
48 . container = { \
49 .match = mtch, \
50 }, \
51}
52
53#define class_to_transport_class(x) \
54 container_of(x, struct transport_class, class)
55
56struct transport_container {
57 struct attribute_container ac;
a4dbd674 58 const struct attribute_group *statistics;
1da177e4
LT
59};
60
61#define attribute_container_to_transport_container(x) \
62 container_of(x, struct transport_container, ac)
63
64void transport_remove_device(struct device *);
cd7ea70b 65int transport_add_device(struct device *);
1da177e4
LT
66void transport_setup_device(struct device *);
67void transport_configure_device(struct device *);
68void transport_destroy_device(struct device *);
69
cd7ea70b 70static inline int
1da177e4
LT
71transport_register_device(struct device *dev)
72{
a8636780
YY
73 int ret;
74
1da177e4 75 transport_setup_device(dev);
a8636780
YY
76 ret = transport_add_device(dev);
77 if (ret)
78 transport_destroy_device(dev);
79
80 return ret;
1da177e4
LT
81}
82
83static inline void
84transport_unregister_device(struct device *dev)
85{
86 transport_remove_device(dev);
87 transport_destroy_device(dev);
88}
89
90static inline int transport_container_register(struct transport_container *tc)
91{
92 return attribute_container_register(&tc->ac);
93}
94
2f3edc69 95static inline void transport_container_unregister(struct transport_container *tc)
1da177e4 96{
2f3edc69
JB
97 if (unlikely(attribute_container_unregister(&tc->ac)))
98 BUG();
1da177e4
LT
99}
100
101int transport_class_register(struct transport_class *);
102int anon_transport_class_register(struct anon_transport_class *);
103void transport_class_unregister(struct transport_class *);
104void anon_transport_class_unregister(struct anon_transport_class *);
105
106
107#endif