enclosure.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 class_device cdev;
  79. enum enclosure_component_type type;
  80. int number;
  81. int fault;
  82. int active;
  83. int locate;
  84. enum enclosure_status status;
  85. };
  86. struct enclosure_device {
  87. void *scratch;
  88. struct list_head node;
  89. struct class_device cdev;
  90. struct enclosure_component_callbacks *cb;
  91. int components;
  92. struct enclosure_component component[0];
  93. };
  94. static inline struct enclosure_device *
  95. to_enclosure_device(struct class_device *dev)
  96. {
  97. return container_of(dev, struct enclosure_device, cdev);
  98. }
  99. static inline struct enclosure_component *
  100. to_enclosure_component(struct class_device *dev)
  101. {
  102. return container_of(dev, struct enclosure_component, cdev);
  103. }
  104. struct enclosure_device *
  105. enclosure_register(struct device *, const char *, int,
  106. struct enclosure_component_callbacks *);
  107. void enclosure_unregister(struct enclosure_device *);
  108. struct enclosure_component *
  109. enclosure_component_register(struct enclosure_device *, unsigned int,
  110. enum enclosure_component_type, const char *);
  111. int enclosure_add_device(struct enclosure_device *enclosure, int component,
  112. struct device *dev);
  113. int enclosure_remove_device(struct enclosure_device *enclosure, int component);
  114. struct enclosure_device *enclosure_find(struct device *dev);
  115. int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
  116. void *data);
  117. #endif /* _LINUX_ENCLOSURE_H_ */