Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * transport_class.h - a generic container for all transport classes
0004  *
0005  * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
0006  */
0007 
0008 #ifndef _TRANSPORT_CLASS_H_
0009 #define _TRANSPORT_CLASS_H_
0010 
0011 #include <linux/device.h>
0012 #include <linux/bug.h>
0013 #include <linux/attribute_container.h>
0014 
0015 struct transport_container;
0016 
0017 struct transport_class {
0018     struct class class;
0019     int (*setup)(struct transport_container *, struct device *,
0020              struct device *);
0021     int (*configure)(struct transport_container *, struct device *,
0022              struct device *);
0023     int (*remove)(struct transport_container *, struct device *,
0024               struct device *);
0025 };
0026 
0027 #define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg)           \
0028 struct transport_class cls = {                      \
0029     .class = {                          \
0030         .name = nm,                     \
0031     },                              \
0032     .setup = su,                            \
0033     .remove = rm,                           \
0034     .configure = cfg,                       \
0035 }
0036 
0037 
0038 struct anon_transport_class {
0039     struct transport_class tclass;
0040     struct attribute_container container;
0041 };
0042 
0043 #define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg)        \
0044 struct anon_transport_class cls = {             \
0045     .tclass = {                     \
0046         .configure = cfg,               \
0047     },                          \
0048     . container = {                     \
0049         .match = mtch,                  \
0050     },                          \
0051 }
0052 
0053 #define class_to_transport_class(x) \
0054     container_of(x, struct transport_class, class)
0055 
0056 struct transport_container {
0057     struct attribute_container ac;
0058     const struct attribute_group *statistics;
0059 };
0060 
0061 #define attribute_container_to_transport_container(x) \
0062     container_of(x, struct transport_container, ac)
0063 
0064 void transport_remove_device(struct device *);
0065 int transport_add_device(struct device *);
0066 void transport_setup_device(struct device *);
0067 void transport_configure_device(struct device *);
0068 void transport_destroy_device(struct device *);
0069 
0070 static inline int
0071 transport_register_device(struct device *dev)
0072 {
0073     transport_setup_device(dev);
0074     return transport_add_device(dev);
0075 }
0076 
0077 static inline void
0078 transport_unregister_device(struct device *dev)
0079 {
0080     transport_remove_device(dev);
0081     transport_destroy_device(dev);
0082 }
0083 
0084 static inline int transport_container_register(struct transport_container *tc)
0085 {
0086     return attribute_container_register(&tc->ac);
0087 }
0088 
0089 static inline void transport_container_unregister(struct transport_container *tc)
0090 {
0091     if (unlikely(attribute_container_unregister(&tc->ac)))
0092         BUG();
0093 }
0094 
0095 int transport_class_register(struct transport_class *);
0096 int anon_transport_class_register(struct anon_transport_class *);
0097 void transport_class_unregister(struct transport_class *);
0098 void anon_transport_class_unregister(struct anon_transport_class *);
0099 
0100 
0101 #endif