enclosure.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_CONTROLLER_ELECTRONICS = 0x07,
  31. ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
  32. ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
  33. ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
  34. ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
  35. };
  36. /* ses-2 common element status */
  37. enum enclosure_status {
  38. ENCLOSURE_STATUS_UNSUPPORTED = 0,
  39. ENCLOSURE_STATUS_OK,
  40. ENCLOSURE_STATUS_CRITICAL,
  41. ENCLOSURE_STATUS_NON_CRITICAL,
  42. ENCLOSURE_STATUS_UNRECOVERABLE,
  43. ENCLOSURE_STATUS_NOT_INSTALLED,
  44. ENCLOSURE_STATUS_UNKNOWN,
  45. ENCLOSURE_STATUS_UNAVAILABLE,
  46. /* last element for counting purposes */
  47. ENCLOSURE_STATUS_MAX
  48. };
  49. /* SFF-8485 activity light settings */
  50. enum enclosure_component_setting {
  51. ENCLOSURE_SETTING_DISABLED = 0,
  52. ENCLOSURE_SETTING_ENABLED = 1,
  53. ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
  54. ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
  55. ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
  56. ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
  57. };
  58. struct enclosure_device;
  59. struct enclosure_component;
  60. struct enclosure_component_callbacks {
  61. void (*get_status)(struct enclosure_device *,
  62. struct enclosure_component *);
  63. int (*set_status)(struct enclosure_device *,
  64. struct enclosure_component *,
  65. enum enclosure_status);
  66. void (*get_fault)(struct enclosure_device *,
  67. struct enclosure_component *);
  68. int (*set_fault)(struct enclosure_device *,
  69. struct enclosure_component *,
  70. enum enclosure_component_setting);
  71. void (*get_active)(struct enclosure_device *,
  72. struct enclosure_component *);
  73. int (*set_active)(struct enclosure_device *,
  74. struct enclosure_component *,
  75. enum enclosure_component_setting);
  76. void (*get_locate)(struct enclosure_device *,
  77. struct enclosure_component *);
  78. int (*set_locate)(struct enclosure_device *,
  79. struct enclosure_component *,
  80. enum enclosure_component_setting);
  81. };
  82. struct enclosure_component {
  83. void *scratch;
  84. struct device cdev;
  85. struct device *dev;
  86. enum enclosure_component_type type;
  87. int number;
  88. int fault;
  89. int active;
  90. int locate;
  91. enum enclosure_status status;
  92. };
  93. struct enclosure_device {
  94. void *scratch;
  95. struct list_head node;
  96. struct device edev;
  97. struct enclosure_component_callbacks *cb;
  98. int components;
  99. struct enclosure_component component[0];
  100. };
  101. static inline struct enclosure_device *
  102. to_enclosure_device(struct device *dev)
  103. {
  104. return container_of(dev, struct enclosure_device, edev);
  105. }
  106. static inline struct enclosure_component *
  107. to_enclosure_component(struct device *dev)
  108. {
  109. return container_of(dev, struct enclosure_component, cdev);
  110. }
  111. struct enclosure_device *
  112. enclosure_register(struct device *, const char *, int,
  113. struct enclosure_component_callbacks *);
  114. void enclosure_unregister(struct enclosure_device *);
  115. struct enclosure_component *
  116. enclosure_component_register(struct enclosure_device *, unsigned int,
  117. enum enclosure_component_type, const char *);
  118. int enclosure_add_device(struct enclosure_device *enclosure, int component,
  119. struct device *dev);
  120. int enclosure_remove_device(struct enclosure_device *, struct device *);
  121. struct enclosure_device *enclosure_find(struct device *dev,
  122. struct enclosure_device *start);
  123. int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
  124. void *data);
  125. #endif /* _LINUX_ENCLOSURE_H_ */