blob: 4b48318ac542edd957061081c1debde8af0a4662 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
39#include <linux/module.h>
Corey Minyard50c812b2006-03-26 01:37:21 -080040#include <linux/device.h>
41#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* This files describes the interface for IPMI system management interface
44 drivers to bind into the IPMI message handler. */
45
46/* Structure for the low-level drivers. */
47typedef struct ipmi_smi *ipmi_smi_t;
48
49/*
50 * Messages to/from the lower layer. The smi interface will take one
51 * of these to send. After the send has occurred and a response has
52 * been received, it will report this same data structure back up to
53 * the upper layer. If an error occurs, it should fill in the
54 * response with an error code in the completion code location. When
55 * asynchronous data is received, one of these is allocated, the
56 * data_size is set to zero and the response holds the data from the
57 * get message or get event command that the interface initiated.
58 * Note that it is the interfaces responsibility to detect
59 * asynchronous data and messages and request them from the
60 * interface.
61 */
Corey Minyardc70d7492008-04-29 01:01:09 -070062struct ipmi_smi_msg {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 struct list_head link;
64
65 long msgid;
66 void *user_data;
67
68 int data_size;
69 unsigned char data[IPMI_MAX_MSG_LENGTH];
70
71 int rsp_size;
72 unsigned char rsp[IPMI_MAX_MSG_LENGTH];
73
74 /* Will be called when the system is done with the message
Corey Minyardc70d7492008-04-29 01:01:09 -070075 (presumably to free it). */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 void (*done)(struct ipmi_smi_msg *msg);
77};
78
Corey Minyardc70d7492008-04-29 01:01:09 -070079struct ipmi_smi_handlers {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 struct module *owner;
81
Corey Minyard453823b2006-03-31 02:30:39 -080082 /* The low-level interface cannot start sending messages to
83 the upper layer until this function is called. This may
84 not be NULL, the lower layer must take the interface from
85 this call. */
86 int (*start_processing)(void *send_info,
87 ipmi_smi_t new_intf);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 /* Called to enqueue an SMI message to be sent. This
90 operation is not allowed to fail. If an error occurs, it
91 should report back the error in a received message. It may
92 do this in the current call context, since no write locks
93 are held when this is run. If the priority is > 0, the
94 message will go into a high-priority queue and be sent
95 first. Otherwise, it goes into a normal-priority queue. */
96 void (*sender)(void *send_info,
97 struct ipmi_smi_msg *msg,
98 int priority);
99
100 /* Called by the upper layer to request that we try to get
101 events from the BMC we are attached to. */
102 void (*request_events)(void *send_info);
103
104 /* Called when the interface should go into "run to
105 completion" mode. If this call sets the value to true, the
106 interface should make sure that all messages are flushed
107 out and that none are pending, and any new requests are run
108 to completion immediately. */
109 void (*set_run_to_completion)(void *send_info, int run_to_completion);
110
111 /* Called to poll for work to do. This is so upper layers can
112 poll for operations during things like crash dumps. */
113 void (*poll)(void *send_info);
114
Corey Minyardb9675132006-12-06 20:41:02 -0800115 /* Enable/disable firmware maintenance mode. Note that this
116 is *not* the modes defined, this is simply an on/off
117 setting. The message handler does the mode handling. Note
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200118 that this is called from interrupt context, so it cannot
Corey Minyardb9675132006-12-06 20:41:02 -0800119 block. */
120 void (*set_maintenance_mode)(void *send_info, int enable);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /* Tell the handler that we are using it/not using it. The
123 message handler get the modules that this handler belongs
124 to; this function lets the SMI claim any modules that it
125 uses. These may be NULL if this is not required. */
126 int (*inc_usecount)(void *send_info);
127 void (*dec_usecount)(void *send_info);
128};
129
Corey Minyard50c812b2006-03-26 01:37:21 -0800130struct ipmi_device_id {
131 unsigned char device_id;
132 unsigned char device_revision;
133 unsigned char firmware_revision_1;
134 unsigned char firmware_revision_2;
135 unsigned char ipmi_version;
136 unsigned char additional_device_support;
137 unsigned int manufacturer_id;
138 unsigned int product_id;
139 unsigned char aux_firmware_revision[4];
140 unsigned int aux_firmware_revision_set : 1;
141};
142
143#define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
144#define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
145
146/* Take a pointer to a raw data buffer and a length and extract device
147 id information from it. The first byte of data must point to the
Corey Minyardd8c98612007-10-18 03:07:11 -0700148 netfn << 2, the data should be of the format:
149 netfn << 2, cmd, completion code, data
150 as normally comes from a device interface. */
151static inline int ipmi_demangle_device_id(const unsigned char *data,
152 unsigned int data_len,
153 struct ipmi_device_id *id)
Corey Minyard50c812b2006-03-26 01:37:21 -0800154{
Corey Minyardd8c98612007-10-18 03:07:11 -0700155 if (data_len < 9)
156 return -EINVAL;
157 if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 ||
158 data[1] != IPMI_GET_DEVICE_ID_CMD)
159 /* Strange, didn't get the response we expected. */
160 return -EINVAL;
161 if (data[2] != 0)
162 /* That's odd, it shouldn't be able to fail. */
163 return -EINVAL;
164
165 data += 3;
166 data_len -= 3;
Corey Minyard50c812b2006-03-26 01:37:21 -0800167 id->device_id = data[0];
168 id->device_revision = data[1];
169 id->firmware_revision_1 = data[2];
170 id->firmware_revision_2 = data[3];
171 id->ipmi_version = data[4];
172 id->additional_device_support = data[5];
Corey Minyard64e862a2007-10-29 14:37:13 -0700173 if (data_len >= 11) {
Corey Minyardd8c98612007-10-18 03:07:11 -0700174 id->manufacturer_id = (data[6] | (data[7] << 8) |
175 (data[8] << 16));
176 id->product_id = data[9] | (data[10] << 8);
177 } else {
178 id->manufacturer_id = 0;
179 id->product_id = 0;
180 }
Corey Minyard50c812b2006-03-26 01:37:21 -0800181 if (data_len >= 15) {
182 memcpy(id->aux_firmware_revision, data+11, 4);
183 id->aux_firmware_revision_set = 1;
184 } else
185 id->aux_firmware_revision_set = 0;
Corey Minyardd8c98612007-10-18 03:07:11 -0700186
187 return 0;
Corey Minyard50c812b2006-03-26 01:37:21 -0800188}
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* Add a low-level interface to the IPMI driver. Note that if the
Corey Minyard453823b2006-03-31 02:30:39 -0800191 interface doesn't know its slave address, it should pass in zero.
192 The low-level interface should not deliver any messages to the
193 upper layer until the start_processing() function in the handlers
194 is called, and the lower layer must get the interface from that
195 call. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
197 void *send_info,
Corey Minyard50c812b2006-03-26 01:37:21 -0800198 struct ipmi_device_id *device_id,
199 struct device *dev,
Corey Minyard759643b2006-12-06 20:40:59 -0800200 const char *sysfs_name,
Corey Minyard453823b2006-03-31 02:30:39 -0800201 unsigned char slave_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203/*
204 * Remove a low-level interface from the IPMI driver. This will
205 * return an error if the interface is still in use by a user.
206 */
207int ipmi_unregister_smi(ipmi_smi_t intf);
208
209/*
210 * The lower layer reports received messages through this interface.
211 * The data_size should be zero if this is an asyncronous message. If
212 * the lower layer gets an error sending a message, it should format
213 * an error response in the message response.
214 */
215void ipmi_smi_msg_received(ipmi_smi_t intf,
216 struct ipmi_smi_msg *msg);
217
218/* The lower layer received a watchdog pre-timeout on interface. */
219void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
220
221struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
222static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
223{
224 msg->done(msg);
225}
226
227/* Allow the lower layer to add things to the proc filesystem
228 directory for this interface. Note that the entry will
229 automatically be dstroyed when the interface is destroyed. */
230int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
Alexey Dobriyanfa68be02008-04-29 01:01:13 -0700231 read_proc_t *read_proc,
Alexey Dobriyan99b76232009-03-25 22:48:06 +0300232 void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234#endif /* __LINUX_IPMI_SMI_H */