xref: /linux-6.15/include/linux/enclosure.h (revision 19219946)
182c29810SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2d569d5bbSJames Bottomley /*
3d569d5bbSJames Bottomley  * Enclosure Services
4d569d5bbSJames Bottomley  *
5d569d5bbSJames Bottomley  * Copyright (C) 2008 James Bottomley <[email protected]>
6d569d5bbSJames Bottomley  *
7d569d5bbSJames Bottomley **-----------------------------------------------------------------------------
8d569d5bbSJames Bottomley **
9d569d5bbSJames Bottomley **
10d569d5bbSJames Bottomley **-----------------------------------------------------------------------------
11d569d5bbSJames Bottomley */
12d569d5bbSJames Bottomley #ifndef _LINUX_ENCLOSURE_H_
13d569d5bbSJames Bottomley #define _LINUX_ENCLOSURE_H_
14d569d5bbSJames Bottomley 
15d569d5bbSJames Bottomley #include <linux/device.h>
16d569d5bbSJames Bottomley #include <linux/list.h>
17d569d5bbSJames Bottomley 
18d569d5bbSJames Bottomley /* A few generic types ... taken from ses-2 */
19d569d5bbSJames Bottomley enum enclosure_component_type {
20d569d5bbSJames Bottomley 	ENCLOSURE_COMPONENT_DEVICE = 0x01,
215e103356SJames Bottomley 	ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07,
225e103356SJames Bottomley 	ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
235e103356SJames Bottomley 	ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
24d569d5bbSJames Bottomley 	ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
255e103356SJames Bottomley 	ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
26d569d5bbSJames Bottomley };
27d569d5bbSJames Bottomley 
28d569d5bbSJames Bottomley /* ses-2 common element status */
29d569d5bbSJames Bottomley enum enclosure_status {
30d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_UNSUPPORTED = 0,
31d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_OK,
32d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_CRITICAL,
33d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_NON_CRITICAL,
34d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_UNRECOVERABLE,
35d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_NOT_INSTALLED,
36d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_UNKNOWN,
37d569d5bbSJames Bottomley 	ENCLOSURE_STATUS_UNAVAILABLE,
38cc9b2e9fSJames Bottomley 	/* last element for counting purposes */
39cc9b2e9fSJames Bottomley 	ENCLOSURE_STATUS_MAX
40d569d5bbSJames Bottomley };
41d569d5bbSJames Bottomley 
42d569d5bbSJames Bottomley /* SFF-8485 activity light settings */
43d569d5bbSJames Bottomley enum enclosure_component_setting {
44d569d5bbSJames Bottomley 	ENCLOSURE_SETTING_DISABLED = 0,
45d569d5bbSJames Bottomley 	ENCLOSURE_SETTING_ENABLED = 1,
46d569d5bbSJames Bottomley 	ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
47d569d5bbSJames Bottomley 	ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
48d569d5bbSJames Bottomley 	ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
49d569d5bbSJames Bottomley 	ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
50d569d5bbSJames Bottomley };
51d569d5bbSJames Bottomley 
52d569d5bbSJames Bottomley struct enclosure_device;
53d569d5bbSJames Bottomley struct enclosure_component;
54d569d5bbSJames Bottomley struct enclosure_component_callbacks {
55d569d5bbSJames Bottomley 	void (*get_status)(struct enclosure_device *,
56d569d5bbSJames Bottomley 			     struct enclosure_component *);
57d569d5bbSJames Bottomley 	int (*set_status)(struct enclosure_device *,
58d569d5bbSJames Bottomley 			  struct enclosure_component *,
59d569d5bbSJames Bottomley 			  enum enclosure_status);
60d569d5bbSJames Bottomley 	void (*get_fault)(struct enclosure_device *,
61d569d5bbSJames Bottomley 			  struct enclosure_component *);
62d569d5bbSJames Bottomley 	int (*set_fault)(struct enclosure_device *,
63d569d5bbSJames Bottomley 			 struct enclosure_component *,
64d569d5bbSJames Bottomley 			 enum enclosure_component_setting);
65d569d5bbSJames Bottomley 	void (*get_active)(struct enclosure_device *,
66d569d5bbSJames Bottomley 			   struct enclosure_component *);
67d569d5bbSJames Bottomley 	int (*set_active)(struct enclosure_device *,
68d569d5bbSJames Bottomley 			  struct enclosure_component *,
69d569d5bbSJames Bottomley 			  enum enclosure_component_setting);
70d569d5bbSJames Bottomley 	void (*get_locate)(struct enclosure_device *,
71d569d5bbSJames Bottomley 			   struct enclosure_component *);
72d569d5bbSJames Bottomley 	int (*set_locate)(struct enclosure_device *,
73d569d5bbSJames Bottomley 			  struct enclosure_component *,
74d569d5bbSJames Bottomley 			  enum enclosure_component_setting);
7508024885SSong Liu 	void (*get_power_status)(struct enclosure_device *,
7608024885SSong Liu 				 struct enclosure_component *);
7708024885SSong Liu 	int (*set_power_status)(struct enclosure_device *,
7808024885SSong Liu 				struct enclosure_component *,
7908024885SSong Liu 				int);
80967f7babSDan Williams 	int (*show_id)(struct enclosure_device *, char *buf);
81d569d5bbSJames Bottomley };
82d569d5bbSJames Bottomley 
83d569d5bbSJames Bottomley 
84d569d5bbSJames Bottomley struct enclosure_component {
85d569d5bbSJames Bottomley 	void *scratch;
86ee959b00STony Jones 	struct device cdev;
87ee959b00STony Jones 	struct device *dev;
88d569d5bbSJames Bottomley 	enum enclosure_component_type type;
89d569d5bbSJames Bottomley 	int number;
90d569d5bbSJames Bottomley 	int fault;
91d569d5bbSJames Bottomley 	int active;
92d569d5bbSJames Bottomley 	int locate;
93921ce7f5SDan Williams 	int slot;
94d569d5bbSJames Bottomley 	enum enclosure_status status;
9508024885SSong Liu 	int power_status;
96d569d5bbSJames Bottomley };
97d569d5bbSJames Bottomley 
98d569d5bbSJames Bottomley struct enclosure_device {
99d569d5bbSJames Bottomley 	void *scratch;
100d569d5bbSJames Bottomley 	struct list_head node;
101ee959b00STony Jones 	struct device edev;
102d569d5bbSJames Bottomley 	struct enclosure_component_callbacks *cb;
103d569d5bbSJames Bottomley 	int components;
104*19219946SGustavo A. R. Silva 	struct enclosure_component component[];
105d569d5bbSJames Bottomley };
106d569d5bbSJames Bottomley 
107d569d5bbSJames Bottomley static inline struct enclosure_device *
to_enclosure_device(struct device * dev)108ee959b00STony Jones to_enclosure_device(struct device *dev)
109d569d5bbSJames Bottomley {
110ee959b00STony Jones 	return container_of(dev, struct enclosure_device, edev);
111d569d5bbSJames Bottomley }
112d569d5bbSJames Bottomley 
113d569d5bbSJames Bottomley static inline struct enclosure_component *
to_enclosure_component(struct device * dev)114ee959b00STony Jones to_enclosure_component(struct device *dev)
115d569d5bbSJames Bottomley {
116d569d5bbSJames Bottomley 	return container_of(dev, struct enclosure_component, cdev);
117d569d5bbSJames Bottomley }
118d569d5bbSJames Bottomley 
119d569d5bbSJames Bottomley struct enclosure_device *
120d569d5bbSJames Bottomley enclosure_register(struct device *, const char *, int,
121d569d5bbSJames Bottomley 		   struct enclosure_component_callbacks *);
122d569d5bbSJames Bottomley void enclosure_unregister(struct enclosure_device *);
123d569d5bbSJames Bottomley struct enclosure_component *
124ed09dcc8SDan Williams enclosure_component_alloc(struct enclosure_device *, unsigned int,
125d569d5bbSJames Bottomley 			  enum enclosure_component_type, const char *);
126ed09dcc8SDan Williams int enclosure_component_register(struct enclosure_component *);
127d569d5bbSJames Bottomley int enclosure_add_device(struct enclosure_device *enclosure, int component,
128d569d5bbSJames Bottomley 			 struct device *dev);
12943d8eb9cSJames Bottomley int enclosure_remove_device(struct enclosure_device *, struct device *);
130163f52b6SJames Bottomley struct enclosure_device *enclosure_find(struct device *dev,
131163f52b6SJames Bottomley 					struct enclosure_device *start);
132d569d5bbSJames Bottomley int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
133d569d5bbSJames Bottomley 			      void *data);
134d569d5bbSJames Bottomley 
135d569d5bbSJames Bottomley #endif /* _LINUX_ENCLOSURE_H_ */
136