blk-mq: fix iteration of busy bitmap
[linux-2.6-block.git] / include / linux / ipmi_smi.h
CommitLineData
1da177e4
LT
1/*
2 * ipmi_smi.h
3 *
4 * MontaVista IPMI system management interface
5 *
6 * Author: MontaVista Software, Inc.
7 * Corey Minyard <minyard@mvista.com>
8 * source@mvista.com
9 *
10 * Copyright 2002 MontaVista Software Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33
34#ifndef __LINUX_IPMI_SMI_H
35#define __LINUX_IPMI_SMI_H
36
37#include <linux/ipmi_msgdefs.h>
38#include <linux/proc_fs.h>
50c812b2 39#include <linux/platform_device.h>
16f4232c 40#include <linux/ipmi.h>
1da177e4 41
313162d0
PG
42struct device;
43
1da177e4
LT
44/* This files describes the interface for IPMI system management interface
45 drivers to bind into the IPMI message handler. */
46
47/* Structure for the low-level drivers. */
48typedef struct ipmi_smi *ipmi_smi_t;
49
50/*
51 * Messages to/from the lower layer. The smi interface will take one
52 * of these to send. After the send has occurred and a response has
53 * been received, it will report this same data structure back up to
54 * the upper layer. If an error occurs, it should fill in the
55 * response with an error code in the completion code location. When
56 * asynchronous data is received, one of these is allocated, the
57 * data_size is set to zero and the response holds the data from the
58 * get message or get event command that the interface initiated.
59 * Note that it is the interfaces responsibility to detect
60 * asynchronous data and messages and request them from the
61 * interface.
62 */
c70d7499 63struct ipmi_smi_msg {
1da177e4
LT
64 struct list_head link;
65
66 long msgid;
67 void *user_data;
68
69 int data_size;
70 unsigned char data[IPMI_MAX_MSG_LENGTH];
71
72 int rsp_size;
73 unsigned char rsp[IPMI_MAX_MSG_LENGTH];
74
75 /* Will be called when the system is done with the message
c70d7499 76 (presumably to free it). */
1da177e4
LT
77 void (*done)(struct ipmi_smi_msg *msg);
78};
79
c70d7499 80struct ipmi_smi_handlers {
1da177e4
LT
81 struct module *owner;
82
453823ba
CM
83 /* The low-level interface cannot start sending messages to
84 the upper layer until this function is called. This may
85 not be NULL, the lower layer must take the interface from
86 this call. */
87 int (*start_processing)(void *send_info,
88 ipmi_smi_t new_intf);
89
16f4232c
ZY
90 /*
91 * Get the detailed private info of the low level interface and store
92 * it into the structure of ipmi_smi_data. For example: the
93 * ACPI device handle will be returned for the pnp_acpi IPMI device.
94 */
95 int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
96
1da177e4
LT
97 /* Called to enqueue an SMI message to be sent. This
98 operation is not allowed to fail. If an error occurs, it
99 should report back the error in a received message. It may
100 do this in the current call context, since no write locks
99ab32f3
CM
101 are held when this is run. Message are delivered one at
102 a time by the message handler, a new message will not be
103 delivered until the previous message is returned. */
1da177e4 104 void (*sender)(void *send_info,
99ab32f3 105 struct ipmi_smi_msg *msg);
1da177e4
LT
106
107 /* Called by the upper layer to request that we try to get
108 events from the BMC we are attached to. */
109 void (*request_events)(void *send_info);
110
89986496
CM
111 /* Called by the upper layer when some user requires that the
112 interface watch for events, received messages, watchdog
113 pretimeouts, or not. Used by the SMI to know if it should
114 watch for these. This may be NULL if the SMI does not
115 implement it. */
7aefac26 116 void (*set_need_watch)(void *send_info, bool enable);
89986496 117
1da177e4
LT
118 /* Called when the interface should go into "run to
119 completion" mode. If this call sets the value to true, the
120 interface should make sure that all messages are flushed
121 out and that none are pending, and any new requests are run
122 to completion immediately. */
7aefac26 123 void (*set_run_to_completion)(void *send_info, bool run_to_completion);
1da177e4
LT
124
125 /* Called to poll for work to do. This is so upper layers can
126 poll for operations during things like crash dumps. */
127 void (*poll)(void *send_info);
128
b9675136
CM
129 /* Enable/disable firmware maintenance mode. Note that this
130 is *not* the modes defined, this is simply an on/off
131 setting. The message handler does the mode handling. Note
3a4fa0a2 132 that this is called from interrupt context, so it cannot
b9675136 133 block. */
7aefac26 134 void (*set_maintenance_mode)(void *send_info, bool enable);
b9675136 135
1da177e4
LT
136 /* Tell the handler that we are using it/not using it. The
137 message handler get the modules that this handler belongs
138 to; this function lets the SMI claim any modules that it
139 uses. These may be NULL if this is not required. */
140 int (*inc_usecount)(void *send_info);
141 void (*dec_usecount)(void *send_info);
142};
143
50c812b2
CM
144struct ipmi_device_id {
145 unsigned char device_id;
146 unsigned char device_revision;
147 unsigned char firmware_revision_1;
148 unsigned char firmware_revision_2;
149 unsigned char ipmi_version;
150 unsigned char additional_device_support;
151 unsigned int manufacturer_id;
152 unsigned int product_id;
153 unsigned char aux_firmware_revision[4];
154 unsigned int aux_firmware_revision_set : 1;
155};
156
157#define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
158#define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
159
160/* Take a pointer to a raw data buffer and a length and extract device
161 id information from it. The first byte of data must point to the
d8c98618
CM
162 netfn << 2, the data should be of the format:
163 netfn << 2, cmd, completion code, data
164 as normally comes from a device interface. */
165static inline int ipmi_demangle_device_id(const unsigned char *data,
166 unsigned int data_len,
167 struct ipmi_device_id *id)
50c812b2 168{
d8c98618
CM
169 if (data_len < 9)
170 return -EINVAL;
171 if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 ||
172 data[1] != IPMI_GET_DEVICE_ID_CMD)
173 /* Strange, didn't get the response we expected. */
174 return -EINVAL;
175 if (data[2] != 0)
176 /* That's odd, it shouldn't be able to fail. */
177 return -EINVAL;
178
179 data += 3;
180 data_len -= 3;
50c812b2
CM
181 id->device_id = data[0];
182 id->device_revision = data[1];
183 id->firmware_revision_1 = data[2];
184 id->firmware_revision_2 = data[3];
185 id->ipmi_version = data[4];
186 id->additional_device_support = data[5];
64e862a5 187 if (data_len >= 11) {
d8c98618
CM
188 id->manufacturer_id = (data[6] | (data[7] << 8) |
189 (data[8] << 16));
190 id->product_id = data[9] | (data[10] << 8);
191 } else {
192 id->manufacturer_id = 0;
193 id->product_id = 0;
194 }
50c812b2
CM
195 if (data_len >= 15) {
196 memcpy(id->aux_firmware_revision, data+11, 4);
197 id->aux_firmware_revision_set = 1;
198 } else
199 id->aux_firmware_revision_set = 0;
d8c98618
CM
200
201 return 0;
50c812b2
CM
202}
203
1da177e4 204/* Add a low-level interface to the IPMI driver. Note that if the
453823ba
CM
205 interface doesn't know its slave address, it should pass in zero.
206 The low-level interface should not deliver any messages to the
207 upper layer until the start_processing() function in the handlers
208 is called, and the lower layer must get the interface from that
209 call. */
1da177e4
LT
210int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
211 void *send_info,
50c812b2
CM
212 struct ipmi_device_id *device_id,
213 struct device *dev,
453823ba 214 unsigned char slave_addr);
1da177e4
LT
215
216/*
217 * Remove a low-level interface from the IPMI driver. This will
218 * return an error if the interface is still in use by a user.
219 */
220int ipmi_unregister_smi(ipmi_smi_t intf);
221
222/*
223 * The lower layer reports received messages through this interface.
b3834be5 224 * The data_size should be zero if this is an asynchronous message. If
1da177e4
LT
225 * the lower layer gets an error sending a message, it should format
226 * an error response in the message response.
227 */
228void ipmi_smi_msg_received(ipmi_smi_t intf,
229 struct ipmi_smi_msg *msg);
230
231/* The lower layer received a watchdog pre-timeout on interface. */
232void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
233
234struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
235static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
236{
237 msg->done(msg);
238}
239
240/* Allow the lower layer to add things to the proc filesystem
241 directory for this interface. Note that the entry will
242 automatically be dstroyed when the interface is destroyed. */
243int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
07412736 244 const struct file_operations *proc_ops,
99b76233 245 void *data);
1da177e4
LT
246
247#endif /* __LINUX_IPMI_SMI_H */