1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
7 **-----------------------------------------------------------------------------
10 **-----------------------------------------------------------------------------
12 #ifndef _LINUX_ENCLOSURE_H_
13 #define _LINUX_ENCLOSURE_H_
15 #include <linux/device.h>
16 #include <linux/list.h>
18 /* A few generic types ... taken from ses-2 */
19 enum enclosure_component_type
{
20 ENCLOSURE_COMPONENT_DEVICE
= 0x01,
21 ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS
= 0x07,
22 ENCLOSURE_COMPONENT_SCSI_TARGET_PORT
= 0x14,
23 ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT
= 0x15,
24 ENCLOSURE_COMPONENT_ARRAY_DEVICE
= 0x17,
25 ENCLOSURE_COMPONENT_SAS_EXPANDER
= 0x18,
28 /* ses-2 common element status */
29 enum enclosure_status
{
30 ENCLOSURE_STATUS_UNSUPPORTED
= 0,
32 ENCLOSURE_STATUS_CRITICAL
,
33 ENCLOSURE_STATUS_NON_CRITICAL
,
34 ENCLOSURE_STATUS_UNRECOVERABLE
,
35 ENCLOSURE_STATUS_NOT_INSTALLED
,
36 ENCLOSURE_STATUS_UNKNOWN
,
37 ENCLOSURE_STATUS_UNAVAILABLE
,
38 /* last element for counting purposes */
42 /* SFF-8485 activity light settings */
43 enum enclosure_component_setting
{
44 ENCLOSURE_SETTING_DISABLED
= 0,
45 ENCLOSURE_SETTING_ENABLED
= 1,
46 ENCLOSURE_SETTING_BLINK_A_ON_OFF
= 2,
47 ENCLOSURE_SETTING_BLINK_A_OFF_ON
= 3,
48 ENCLOSURE_SETTING_BLINK_B_ON_OFF
= 6,
49 ENCLOSURE_SETTING_BLINK_B_OFF_ON
= 7,
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 void (*get_power_status
)(struct enclosure_device
*,
76 struct enclosure_component
*);
77 int (*set_power_status
)(struct enclosure_device
*,
78 struct enclosure_component
*,
80 int (*show_id
)(struct enclosure_device
*, char *buf
);
84 struct enclosure_component
{
88 enum enclosure_component_type type
;
94 enum enclosure_status status
;
98 struct enclosure_device
{
100 struct list_head node
;
102 struct enclosure_component_callbacks
*cb
;
104 struct enclosure_component component
[];
107 static inline struct enclosure_device
*
108 to_enclosure_device(struct device
*dev
)
110 return container_of(dev
, struct enclosure_device
, edev
);
113 static inline struct enclosure_component
*
114 to_enclosure_component(struct device
*dev
)
116 return container_of(dev
, struct enclosure_component
, cdev
);
119 struct enclosure_device
*
120 enclosure_register(struct device
*, const char *, int,
121 struct enclosure_component_callbacks
*);
122 void enclosure_unregister(struct enclosure_device
*);
123 struct enclosure_component
*
124 enclosure_component_alloc(struct enclosure_device
*, unsigned int,
125 enum enclosure_component_type
, const char *);
126 int enclosure_component_register(struct enclosure_component
*);
127 int enclosure_add_device(struct enclosure_device
*enclosure
, int component
,
129 int enclosure_remove_device(struct enclosure_device
*, struct device
*);
130 struct enclosure_device
*enclosure_find(struct device
*dev
,
131 struct enclosure_device
*start
);
132 int enclosure_for_each_device(int (*fn
)(struct enclosure_device
*, void *),
135 #endif /* _LINUX_ENCLOSURE_H_ */