enclosure.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Enclosure Services
  4. *
  5. * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
  6. *
  7. **-----------------------------------------------------------------------------
  8. **
  9. **
  10. **-----------------------------------------------------------------------------
  11. */
  12. #ifndef _LINUX_ENCLOSURE_H_
  13. #define _LINUX_ENCLOSURE_H_
  14. #include <linux/device.h>
  15. #include <linux/list.h>
  16. /* A few generic types ... taken from ses-2 */
  17. enum enclosure_component_type {
  18. ENCLOSURE_COMPONENT_DEVICE = 0x01,
  19. ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07,
  20. ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
  21. ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
  22. ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
  23. ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
  24. };
  25. /* ses-2 common element status */
  26. enum enclosure_status {
  27. ENCLOSURE_STATUS_UNSUPPORTED = 0,
  28. ENCLOSURE_STATUS_OK,
  29. ENCLOSURE_STATUS_CRITICAL,
  30. ENCLOSURE_STATUS_NON_CRITICAL,
  31. ENCLOSURE_STATUS_UNRECOVERABLE,
  32. ENCLOSURE_STATUS_NOT_INSTALLED,
  33. ENCLOSURE_STATUS_UNKNOWN,
  34. ENCLOSURE_STATUS_UNAVAILABLE,
  35. /* last element for counting purposes */
  36. ENCLOSURE_STATUS_MAX
  37. };
  38. /* SFF-8485 activity light settings */
  39. enum enclosure_component_setting {
  40. ENCLOSURE_SETTING_DISABLED = 0,
  41. ENCLOSURE_SETTING_ENABLED = 1,
  42. ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
  43. ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
  44. ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
  45. ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
  46. };
  47. struct enclosure_device;
  48. struct enclosure_component;
  49. struct enclosure_component_callbacks {
  50. void (*get_status)(struct enclosure_device *,
  51. struct enclosure_component *);
  52. int (*set_status)(struct enclosure_device *,
  53. struct enclosure_component *,
  54. enum enclosure_status);
  55. void (*get_fault)(struct enclosure_device *,
  56. struct enclosure_component *);
  57. int (*set_fault)(struct enclosure_device *,
  58. struct enclosure_component *,
  59. enum enclosure_component_setting);
  60. void (*get_active)(struct enclosure_device *,
  61. struct enclosure_component *);
  62. int (*set_active)(struct enclosure_device *,
  63. struct enclosure_component *,
  64. enum enclosure_component_setting);
  65. void (*get_locate)(struct enclosure_device *,
  66. struct enclosure_component *);
  67. int (*set_locate)(struct enclosure_device *,
  68. struct enclosure_component *,
  69. enum enclosure_component_setting);
  70. void (*get_power_status)(struct enclosure_device *,
  71. struct enclosure_component *);
  72. int (*set_power_status)(struct enclosure_device *,
  73. struct enclosure_component *,
  74. int);
  75. int (*show_id)(struct enclosure_device *, char *buf);
  76. };
  77. struct enclosure_component {
  78. void *scratch;
  79. struct device cdev;
  80. struct device *dev;
  81. enum enclosure_component_type type;
  82. int number;
  83. int fault;
  84. int active;
  85. int locate;
  86. int slot;
  87. enum enclosure_status status;
  88. int power_status;
  89. };
  90. struct enclosure_device {
  91. void *scratch;
  92. struct list_head node;
  93. struct device edev;
  94. struct enclosure_component_callbacks *cb;
  95. int components;
  96. struct enclosure_component component[];
  97. };
  98. static inline struct enclosure_device *
  99. to_enclosure_device(struct device *dev)
  100. {
  101. return container_of(dev, struct enclosure_device, edev);
  102. }
  103. static inline struct enclosure_component *
  104. to_enclosure_component(struct device *dev)
  105. {
  106. return container_of(dev, struct enclosure_component, cdev);
  107. }
  108. struct enclosure_device *
  109. enclosure_register(struct device *, const char *, int,
  110. struct enclosure_component_callbacks *);
  111. void enclosure_unregister(struct enclosure_device *);
  112. struct enclosure_component *
  113. enclosure_component_alloc(struct enclosure_device *, unsigned int,
  114. enum enclosure_component_type, const char *);
  115. int enclosure_component_register(struct enclosure_component *);
  116. int enclosure_add_device(struct enclosure_device *enclosure, int component,
  117. struct device *dev);
  118. int enclosure_remove_device(struct enclosure_device *, struct device *);
  119. struct enclosure_device *enclosure_find(struct device *dev,
  120. struct enclosure_device *start);
  121. int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
  122. void *data);
  123. #endif /* _LINUX_ENCLOSURE_H_ */