]> git.ipfire.org Git - thirdparty/linux.git/blob - include/linux/enclosure.h
Merge tag 'block-5.7-2020-05-16' of git://git.kernel.dk/linux-block
[thirdparty/linux.git] / include / linux / enclosure.h
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
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,
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,
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,
38 /* last element for counting purposes */
39 ENCLOSURE_STATUS_MAX
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);
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);
80 int (*show_id)(struct enclosure_device *, char *buf);
81 };
82
83
84 struct enclosure_component {
85 void *scratch;
86 struct device cdev;
87 struct device *dev;
88 enum enclosure_component_type type;
89 int number;
90 int fault;
91 int active;
92 int locate;
93 int slot;
94 enum enclosure_status status;
95 int power_status;
96 };
97
98 struct enclosure_device {
99 void *scratch;
100 struct list_head node;
101 struct device edev;
102 struct enclosure_component_callbacks *cb;
103 int components;
104 struct enclosure_component component[];
105 };
106
107 static inline struct enclosure_device *
108 to_enclosure_device(struct device *dev)
109 {
110 return container_of(dev, struct enclosure_device, edev);
111 }
112
113 static inline struct enclosure_component *
114 to_enclosure_component(struct device *dev)
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 *
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,
128 struct device *dev);
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 *),
133 void *data);
134
135 #endif /* _LINUX_ENCLOSURE_H_ */