]>
Commit | Line | Data |
---|---|---|
82c29810 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
d569d5bb JB |
2 | /* |
3 | * Enclosure Services | |
4 | * | |
5 | * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com> | |
6 | * | |
7 | **----------------------------------------------------------------------------- | |
8 | ** | |
d569d5bb JB |
9 | ** |
10 | **----------------------------------------------------------------------------- | |
11 | */ | |
12 | #ifndef _LINUX_ENCLOSURE_H_ | |
13 | #define _LINUX_ENCLOSURE_H_ | |
14 | ||
15 | #include <linux/device.h> | |
16 | #include <linux/list.h> | |
17 | ||
18 | /* A few generic types ... taken from ses-2 */ | |
19 | enum enclosure_component_type { | |
20 | ENCLOSURE_COMPONENT_DEVICE = 0x01, | |
5e103356 JB |
21 | ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07, |
22 | ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14, | |
23 | ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15, | |
d569d5bb | 24 | ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17, |
5e103356 | 25 | ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18, |
d569d5bb JB |
26 | }; |
27 | ||
28 | /* ses-2 common element status */ | |
29 | enum enclosure_status { | |
30 | ENCLOSURE_STATUS_UNSUPPORTED = 0, | |
31 | ENCLOSURE_STATUS_OK, | |
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, | |
cc9b2e9f JB |
38 | /* last element for counting purposes */ |
39 | ENCLOSURE_STATUS_MAX | |
d569d5bb JB |
40 | }; |
41 | ||
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, | |
50 | }; | |
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); | |
08024885 SL |
75 | void (*get_power_status)(struct enclosure_device *, |
76 | struct enclosure_component *); | |
77 | int (*set_power_status)(struct enclosure_device *, | |
78 | struct enclosure_component *, | |
79 | int); | |
967f7bab | 80 | int (*show_id)(struct enclosure_device *, char *buf); |
d569d5bb JB |
81 | }; |
82 | ||
83 | ||
84 | struct enclosure_component { | |
85 | void *scratch; | |
ee959b00 TJ |
86 | struct device cdev; |
87 | struct device *dev; | |
d569d5bb JB |
88 | enum enclosure_component_type type; |
89 | int number; | |
90 | int fault; | |
91 | int active; | |
92 | int locate; | |
921ce7f5 | 93 | int slot; |
d569d5bb | 94 | enum enclosure_status status; |
08024885 | 95 | int power_status; |
d569d5bb JB |
96 | }; |
97 | ||
98 | struct enclosure_device { | |
99 | void *scratch; | |
100 | struct list_head node; | |
ee959b00 | 101 | struct device edev; |
d569d5bb JB |
102 | struct enclosure_component_callbacks *cb; |
103 | int components; | |
19219946 | 104 | struct enclosure_component component[]; |
d569d5bb JB |
105 | }; |
106 | ||
107 | static inline struct enclosure_device * | |
ee959b00 | 108 | to_enclosure_device(struct device *dev) |
d569d5bb | 109 | { |
ee959b00 | 110 | return container_of(dev, struct enclosure_device, edev); |
d569d5bb JB |
111 | } |
112 | ||
113 | static inline struct enclosure_component * | |
ee959b00 | 114 | to_enclosure_component(struct device *dev) |
d569d5bb JB |
115 | { |
116 | return container_of(dev, struct enclosure_component, cdev); | |
117 | } | |
118 | ||
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 * | |
ed09dcc8 DW |
124 | enclosure_component_alloc(struct enclosure_device *, unsigned int, |
125 | enum enclosure_component_type, const char *); | |
126 | int enclosure_component_register(struct enclosure_component *); | |
d569d5bb JB |
127 | int enclosure_add_device(struct enclosure_device *enclosure, int component, |
128 | struct device *dev); | |
43d8eb9c | 129 | int enclosure_remove_device(struct enclosure_device *, struct device *); |
163f52b6 JB |
130 | struct enclosure_device *enclosure_find(struct device *dev, |
131 | struct enclosure_device *start); | |
d569d5bb JB |
132 | int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *), |
133 | void *data); | |
134 | ||
135 | #endif /* _LINUX_ENCLOSURE_H_ */ |