nlm: Ensure callback code also checks that the files match
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / enclosure.h
CommitLineData
d569d5bb
JB
1/*
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,
f80e6add
JB
32 ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07,
33 ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
34 ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
d569d5bb 35 ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
f80e6add 36 ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
d569d5bb
JB
37};
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,
cc9b2e9f
JB
49 /* last element for counting purposes */
50 ENCLOSURE_STATUS_MAX
d569d5bb
JB
51};
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);
86};
87
88
89struct enclosure_component {
90 void *scratch;
ee959b00
TJ
91 struct device cdev;
92 struct device *dev;
d569d5bb
JB
93 enum enclosure_component_type type;
94 int number;
95 int fault;
96 int active;
97 int locate;
98 enum enclosure_status status;
99};
100
101struct enclosure_device {
102 void *scratch;
103 struct list_head node;
ee959b00 104 struct device edev;
d569d5bb
JB
105 struct enclosure_component_callbacks *cb;
106 int components;
107 struct enclosure_component component[0];
108};
109
110static inline struct enclosure_device *
ee959b00 111to_enclosure_device(struct device *dev)
d569d5bb 112{
ee959b00 113 return container_of(dev, struct enclosure_device, edev);
d569d5bb
JB
114}
115
116static inline struct enclosure_component *
ee959b00 117to_enclosure_component(struct device *dev)
d569d5bb
JB
118{
119 return container_of(dev, struct enclosure_component, cdev);
120}
121
122struct enclosure_device *
123enclosure_register(struct device *, const char *, int,
124 struct enclosure_component_callbacks *);
125void enclosure_unregister(struct enclosure_device *);
126struct enclosure_component *
127enclosure_component_register(struct enclosure_device *, unsigned int,
128 enum enclosure_component_type, const char *);
129int enclosure_add_device(struct enclosure_device *enclosure, int component,
130 struct device *dev);
43d8eb9c 131int enclosure_remove_device(struct enclosure_device *, struct device *);
163f52b6
JB
132struct enclosure_device *enclosure_find(struct device *dev,
133 struct enclosure_device *start);
d569d5bb
JB
134int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
135 void *data);
136
137#endif /* _LINUX_ENCLOSURE_H_ */