transport_class.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * transport_class.h - a generic container for all transport classes
  4. *
  5. * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
  6. */
  7. #ifndef _TRANSPORT_CLASS_H_
  8. #define _TRANSPORT_CLASS_H_
  9. #include <linux/device.h>
  10. #include <linux/bug.h>
  11. #include <linux/attribute_container.h>
  12. struct transport_container;
  13. struct transport_class {
  14. struct class class;
  15. int (*setup)(struct transport_container *, struct device *,
  16. struct device *);
  17. int (*configure)(struct transport_container *, struct device *,
  18. struct device *);
  19. int (*remove)(struct transport_container *, struct device *,
  20. struct device *);
  21. };
  22. #define DECLARE_TRANSPORT_CLASS(cls, nm, su, rm, cfg) \
  23. struct transport_class cls = { \
  24. .class = { \
  25. .name = nm, \
  26. }, \
  27. .setup = su, \
  28. .remove = rm, \
  29. .configure = cfg, \
  30. }
  31. struct anon_transport_class {
  32. struct transport_class tclass;
  33. struct attribute_container container;
  34. };
  35. #define DECLARE_ANON_TRANSPORT_CLASS(cls, mtch, cfg) \
  36. struct anon_transport_class cls = { \
  37. .tclass = { \
  38. .configure = cfg, \
  39. }, \
  40. . container = { \
  41. .match = mtch, \
  42. }, \
  43. }
  44. #define class_to_transport_class(x) \
  45. container_of(x, struct transport_class, class)
  46. struct transport_container {
  47. struct attribute_container ac;
  48. const struct attribute_group *statistics;
  49. };
  50. #define attribute_container_to_transport_container(x) \
  51. container_of(x, struct transport_container, ac)
  52. void transport_remove_device(struct device *);
  53. int transport_add_device(struct device *);
  54. void transport_setup_device(struct device *);
  55. void transport_configure_device(struct device *);
  56. void transport_destroy_device(struct device *);
  57. static inline int
  58. transport_register_device(struct device *dev)
  59. {
  60. transport_setup_device(dev);
  61. return transport_add_device(dev);
  62. }
  63. static inline void
  64. transport_unregister_device(struct device *dev)
  65. {
  66. transport_remove_device(dev);
  67. transport_destroy_device(dev);
  68. }
  69. static inline int transport_container_register(struct transport_container *tc)
  70. {
  71. return attribute_container_register(&tc->ac);
  72. }
  73. static inline void transport_container_unregister(struct transport_container *tc)
  74. {
  75. if (unlikely(attribute_container_unregister(&tc->ac)))
  76. BUG();
  77. }
  78. int transport_class_register(struct transport_class *);
  79. int anon_transport_class_register(struct anon_transport_class *);
  80. void transport_class_unregister(struct transport_class *);
  81. void anon_transport_class_unregister(struct anon_transport_class *);
  82. #endif