enclosure.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. };
  43. /* SFF-8485 activity light settings */
  44. enum enclosure_component_setting {
  45. ENCLOSURE_SETTING_DISABLED = 0,
  46. ENCLOSURE_SETTING_ENABLED = 1,
  47. ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
  48. ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
  49. ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
  50. ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
  51. };
  52. struct enclosure_device;
  53. struct enclosure_component;
  54. struct enclosure_component_callbacks {
  55. void (*get_status)(struct enclosure_device *,
  56. struct enclosure_component *);
  57. int (*set_status)(struct enclosure_device *,
  58. struct enclosure_component *,
  59. enum enclosure_status);
  60. void (*get_fault)(struct enclosure_device *,
  61. struct enclosure_component *);
  62. int (*set_fault)(struct enclosure_device *,
  63. struct enclosure_component *,
  64. enum enclosure_component_setting);
  65. void (*get_active)(struct enclosure_device *,
  66. struct enclosure_component *);
  67. int (*set_active)(struct enclosure_device *,
  68. struct enclosure_component *,
  69. enum enclosure_component_setting);
  70. void (*get_locate)(struct enclosure_device *,
  71. struct enclosure_component *);
  72. int (*set_locate)(struct enclosure_device *,
  73. struct enclosure_component *,
  74. enum enclosure_component_setting);
  75. };
  76. struct enclosure_component {
  77. void *scratch;
  78. struct device cdev;
  79. struct device *dev;
  80. enum enclosure_component_type type;
  81. int number;
  82. int fault;
  83. int active;
  84. int locate;
  85. enum enclosure_status status;
  86. };
  87. struct enclosure_device {
  88. void *scratch;
  89. struct list_head node;
  90. struct device edev;
  91. struct enclosure_component_callbacks *cb;
  92. int components;
  93. struct enclosure_component component[0];
  94. };
  95. static inline struct enclosure_device *
  96. to_enclosure_device(struct device *dev)
  97. {
  98. return container_of(dev, struct enclosure_device, edev);
  99. }
  100. static inline struct enclosure_component *
  101. to_enclosure_component(struct device *dev)
  102. {
  103. return container_of(dev, struct enclosure_component, cdev);
  104. }
  105. struct enclosure_device *
  106. enclosure_register(struct device *, const char *, int,
  107. struct enclosure_component_callbacks *);
  108. void enclosure_unregister(struct enclosure_device *);
  109. struct enclosure_component *
  110. enclosure_component_register(struct enclosure_device *, unsigned int,
  111. enum enclosure_component_type, const char *);
  112. int enclosure_add_device(struct enclosure_device *enclosure, int component,
  113. struct device *dev);
  114. int enclosure_remove_device(struct enclosure_device *, struct device *);
  115. struct enclosure_device *enclosure_find(struct device *dev,
  116. struct enclosure_device *start);
  117. int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
  118. void *data);
  119. #endif /* _LINUX_ENCLOSURE_H_ */