enclosure.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Enclosure Services
  3. *
  4. * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
  5. *
  6. **-----------------------------------------------------------------------------
  7. **
  8. ** This program is free software; you can redistribute it and/or
  9. ** modify it under the terms of the GNU General Public License
  10. ** version 2 as published by the Free Software Foundation.
  11. **
  12. ** This program is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with this program; if not, write to the Free Software
  19. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. **
  21. **-----------------------------------------------------------------------------
  22. */
  23. #ifndef _LINUX_ENCLOSURE_H_
  24. #define _LINUX_ENCLOSURE_H_
  25. #include <linux/device.h>
  26. #include <linux/list.h>
  27. /* A few generic types ... taken from ses-2 */
  28. enum enclosure_component_type {
  29. ENCLOSURE_COMPONENT_DEVICE = 0x01,
  30. ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
  31. };
  32. /* ses-2 common element status */
  33. enum enclosure_status {
  34. ENCLOSURE_STATUS_UNSUPPORTED = 0,
  35. ENCLOSURE_STATUS_OK,
  36. ENCLOSURE_STATUS_CRITICAL,
  37. ENCLOSURE_STATUS_NON_CRITICAL,
  38. ENCLOSURE_STATUS_UNRECOVERABLE,
  39. ENCLOSURE_STATUS_NOT_INSTALLED,
  40. ENCLOSURE_STATUS_UNKNOWN,
  41. ENCLOSURE_STATUS_UNAVAILABLE,
  42. /* last element for counting purposes */
  43. ENCLOSURE_STATUS_MAX
  44. };
  45. /* SFF-8485 activity light settings */
  46. enum enclosure_component_setting {
  47. ENCLOSURE_SETTING_DISABLED = 0,
  48. ENCLOSURE_SETTING_ENABLED = 1,
  49. ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
  50. ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
  51. ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
  52. ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
  53. };
  54. struct enclosure_device;
  55. struct enclosure_component;
  56. struct enclosure_component_callbacks {
  57. void (*get_status)(struct enclosure_device *,
  58. struct enclosure_component *);
  59. int (*set_status)(struct enclosure_device *,
  60. struct enclosure_component *,
  61. enum enclosure_status);
  62. void (*get_fault)(struct enclosure_device *,
  63. struct enclosure_component *);
  64. int (*set_fault)(struct enclosure_device *,
  65. struct enclosure_component *,
  66. enum enclosure_component_setting);
  67. void (*get_active)(struct enclosure_device *,
  68. struct enclosure_component *);
  69. int (*set_active)(struct enclosure_device *,
  70. struct enclosure_component *,
  71. enum enclosure_component_setting);
  72. void (*get_locate)(struct enclosure_device *,
  73. struct enclosure_component *);
  74. int (*set_locate)(struct enclosure_device *,
  75. struct enclosure_component *,
  76. enum enclosure_component_setting);
  77. };
  78. struct enclosure_component {
  79. void *scratch;
  80. struct device cdev;
  81. struct device *dev;
  82. enum enclosure_component_type type;
  83. int number;
  84. int fault;
  85. int active;
  86. int locate;
  87. enum enclosure_status status;
  88. };
  89. struct enclosure_device {
  90. void *scratch;
  91. struct list_head node;
  92. struct device edev;
  93. struct enclosure_component_callbacks *cb;
  94. int components;
  95. struct enclosure_component component[0];
  96. };
  97. static inline struct enclosure_device *
  98. to_enclosure_device(struct device *dev)
  99. {
  100. return container_of(dev, struct enclosure_device, edev);
  101. }
  102. static inline struct enclosure_component *
  103. to_enclosure_component(struct device *dev)
  104. {
  105. return container_of(dev, struct enclosure_component, cdev);
  106. }
  107. struct enclosure_device *
  108. enclosure_register(struct device *, const char *, int,
  109. struct enclosure_component_callbacks *);
  110. void enclosure_unregister(struct enclosure_device *);
  111. struct enclosure_component *
  112. enclosure_component_register(struct enclosure_device *, unsigned int,
  113. enum enclosure_component_type, const char *);
  114. int enclosure_add_device(struct enclosure_device *enclosure, int component,
  115. struct device *dev);
  116. int enclosure_remove_device(struct enclosure_device *, struct device *);
  117. struct enclosure_device *enclosure_find(struct device *dev,
  118. struct enclosure_device *start);
  119. int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
  120. void *data);
  121. #endif /* _LINUX_ENCLOSURE_H_ */