blob: a4cf57cd0f7512d66b15a036cb76114d5bf633e0 [file] [log] [blame]
James Bottomleyd569d5b2008-02-03 15:40:56 -06001/*
2 * Enclosure Services
3 *
4 * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
5 *
6**-----------------------------------------------------------------------------
7**
8** This program is free software; you can redistribute it and/or
9** modify it under the terms of the GNU General Public License
10** version 2 as published by the Free Software Foundation.
11**
12** This program is distributed in the hope that it will be useful,
13** but WITHOUT ANY WARRANTY; without even the implied warranty of
14** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15** GNU General Public License for more details.
16**
17** You should have received a copy of the GNU General Public License
18** along with this program; if not, write to the Free Software
19** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20**
21**-----------------------------------------------------------------------------
22*/
23#ifndef _LINUX_ENCLOSURE_H_
24#define _LINUX_ENCLOSURE_H_
25
26#include <linux/device.h>
27#include <linux/list.h>
28
29/* A few generic types ... taken from ses-2 */
30enum enclosure_component_type {
31 ENCLOSURE_COMPONENT_DEVICE = 0x01,
James Bottomley5e103352015-12-11 09:16:38 -080032 ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07,
33 ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
34 ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
James Bottomleyd569d5b2008-02-03 15:40:56 -060035 ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
James Bottomley5e103352015-12-11 09:16:38 -080036 ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
James Bottomleyd569d5b2008-02-03 15:40:56 -060037};
38
39/* ses-2 common element status */
40enum enclosure_status {
41 ENCLOSURE_STATUS_UNSUPPORTED = 0,
42 ENCLOSURE_STATUS_OK,
43 ENCLOSURE_STATUS_CRITICAL,
44 ENCLOSURE_STATUS_NON_CRITICAL,
45 ENCLOSURE_STATUS_UNRECOVERABLE,
46 ENCLOSURE_STATUS_NOT_INSTALLED,
47 ENCLOSURE_STATUS_UNKNOWN,
48 ENCLOSURE_STATUS_UNAVAILABLE,
James Bottomleycc9b2e92009-11-26 09:50:20 -060049 /* last element for counting purposes */
50 ENCLOSURE_STATUS_MAX
James Bottomleyd569d5b2008-02-03 15:40:56 -060051};
52
53/* SFF-8485 activity light settings */
54enum enclosure_component_setting {
55 ENCLOSURE_SETTING_DISABLED = 0,
56 ENCLOSURE_SETTING_ENABLED = 1,
57 ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
58 ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
59 ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
60 ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
61};
62
63struct enclosure_device;
64struct enclosure_component;
65struct enclosure_component_callbacks {
66 void (*get_status)(struct enclosure_device *,
67 struct enclosure_component *);
68 int (*set_status)(struct enclosure_device *,
69 struct enclosure_component *,
70 enum enclosure_status);
71 void (*get_fault)(struct enclosure_device *,
72 struct enclosure_component *);
73 int (*set_fault)(struct enclosure_device *,
74 struct enclosure_component *,
75 enum enclosure_component_setting);
76 void (*get_active)(struct enclosure_device *,
77 struct enclosure_component *);
78 int (*set_active)(struct enclosure_device *,
79 struct enclosure_component *,
80 enum enclosure_component_setting);
81 void (*get_locate)(struct enclosure_device *,
82 struct enclosure_component *);
83 int (*set_locate)(struct enclosure_device *,
84 struct enclosure_component *,
85 enum enclosure_component_setting);
Song Liu08024882014-12-30 14:46:18 -080086 void (*get_power_status)(struct enclosure_device *,
87 struct enclosure_component *);
88 int (*set_power_status)(struct enclosure_device *,
89 struct enclosure_component *,
90 int);
Dan Williams967f7ba2014-12-30 14:46:16 -080091 int (*show_id)(struct enclosure_device *, char *buf);
James Bottomleyd569d5b2008-02-03 15:40:56 -060092};
93
94
95struct enclosure_component {
96 void *scratch;
Tony Jonesee959b02008-02-22 00:13:36 +010097 struct device cdev;
98 struct device *dev;
James Bottomleyd569d5b2008-02-03 15:40:56 -060099 enum enclosure_component_type type;
100 int number;
101 int fault;
102 int active;
103 int locate;
Dan Williams921ce7f2014-12-30 14:46:17 -0800104 int slot;
James Bottomleyd569d5b2008-02-03 15:40:56 -0600105 enum enclosure_status status;
Song Liu08024882014-12-30 14:46:18 -0800106 int power_status;
James Bottomleyd569d5b2008-02-03 15:40:56 -0600107};
108
109struct enclosure_device {
110 void *scratch;
111 struct list_head node;
Tony Jonesee959b02008-02-22 00:13:36 +0100112 struct device edev;
James Bottomleyd569d5b2008-02-03 15:40:56 -0600113 struct enclosure_component_callbacks *cb;
114 int components;
115 struct enclosure_component component[0];
116};
117
118static inline struct enclosure_device *
Tony Jonesee959b02008-02-22 00:13:36 +0100119to_enclosure_device(struct device *dev)
James Bottomleyd569d5b2008-02-03 15:40:56 -0600120{
Tony Jonesee959b02008-02-22 00:13:36 +0100121 return container_of(dev, struct enclosure_device, edev);
James Bottomleyd569d5b2008-02-03 15:40:56 -0600122}
123
124static inline struct enclosure_component *
Tony Jonesee959b02008-02-22 00:13:36 +0100125to_enclosure_component(struct device *dev)
James Bottomleyd569d5b2008-02-03 15:40:56 -0600126{
127 return container_of(dev, struct enclosure_component, cdev);
128}
129
130struct enclosure_device *
131enclosure_register(struct device *, const char *, int,
132 struct enclosure_component_callbacks *);
133void enclosure_unregister(struct enclosure_device *);
134struct enclosure_component *
Dan Williamsed09dcc2014-12-30 14:46:14 -0800135enclosure_component_alloc(struct enclosure_device *, unsigned int,
136 enum enclosure_component_type, const char *);
137int enclosure_component_register(struct enclosure_component *);
James Bottomleyd569d5b2008-02-03 15:40:56 -0600138int enclosure_add_device(struct enclosure_device *enclosure, int component,
139 struct device *dev);
James Bottomley43d8eb92009-08-01 00:41:22 +0000140int enclosure_remove_device(struct enclosure_device *, struct device *);
James Bottomley163f52b2009-08-01 00:39:36 +0000141struct enclosure_device *enclosure_find(struct device *dev,
142 struct enclosure_device *start);
James Bottomleyd569d5b2008-02-03 15:40:56 -0600143int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
144 void *data);
145
146#endif /* _LINUX_ENCLOSURE_H_ */