raid_class.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * raid_class.h - a generic raid visualisation class
  4. *
  5. * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
  6. */
  7. #include <linux/transport_class.h>
  8. struct raid_template {
  9. struct transport_container raid_attrs;
  10. };
  11. struct raid_function_template {
  12. void *cookie;
  13. int (*is_raid)(struct device *);
  14. void (*get_resync)(struct device *);
  15. void (*get_state)(struct device *);
  16. };
  17. enum raid_state {
  18. RAID_STATE_UNKNOWN = 0,
  19. RAID_STATE_ACTIVE,
  20. RAID_STATE_DEGRADED,
  21. RAID_STATE_RESYNCING,
  22. RAID_STATE_OFFLINE,
  23. };
  24. enum raid_level {
  25. RAID_LEVEL_UNKNOWN = 0,
  26. RAID_LEVEL_LINEAR,
  27. RAID_LEVEL_0,
  28. RAID_LEVEL_1,
  29. RAID_LEVEL_10,
  30. RAID_LEVEL_1E,
  31. RAID_LEVEL_3,
  32. RAID_LEVEL_4,
  33. RAID_LEVEL_5,
  34. RAID_LEVEL_50,
  35. RAID_LEVEL_6,
  36. RAID_LEVEL_JBOD,
  37. };
  38. struct raid_data {
  39. struct list_head component_list;
  40. int component_count;
  41. enum raid_level level;
  42. enum raid_state state;
  43. int resync;
  44. };
  45. /* resync complete goes from 0 to this */
  46. #define RAID_MAX_RESYNC (10000)
  47. #define DEFINE_RAID_ATTRIBUTE(type, attr) \
  48. static inline void \
  49. raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
  50. struct device *device = \
  51. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  52. struct raid_data *rd; \
  53. BUG_ON(!device); \
  54. rd = dev_get_drvdata(device); \
  55. rd->attr = value; \
  56. } \
  57. static inline type \
  58. raid_get_##attr(struct raid_template *r, struct device *dev) { \
  59. struct device *device = \
  60. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  61. struct raid_data *rd; \
  62. BUG_ON(!device); \
  63. rd = dev_get_drvdata(device); \
  64. return rd->attr; \
  65. }
  66. DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
  67. DEFINE_RAID_ATTRIBUTE(int, resync)
  68. DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
  69. struct raid_template *raid_class_attach(struct raid_function_template *);
  70. void raid_class_release(struct raid_template *);
  71. int __must_check raid_component_add(struct raid_template *, struct device *,
  72. struct device *);