]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * ipmi_smi.h | |
3 | * | |
4 | * MontaVista IPMI system management interface | |
5 | * | |
6 | * Author: MontaVista Software, Inc. | |
7 | * Corey Minyard <[email protected]> | |
8 | * [email protected] | |
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> | |
50c812b2 CM |
40 | #include <linux/device.h> |
41 | #include <linux/platform_device.h> | |
42 | #include <linux/ipmi_smi.h> | |
1da177e4 LT |
43 | |
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. */ | |
48 | typedef 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 | */ | |
63 | struct ipmi_smi_msg | |
64 | { | |
65 | struct list_head link; | |
66 | ||
67 | long msgid; | |
68 | void *user_data; | |
69 | ||
70 | int data_size; | |
71 | unsigned char data[IPMI_MAX_MSG_LENGTH]; | |
72 | ||
73 | int rsp_size; | |
74 | unsigned char rsp[IPMI_MAX_MSG_LENGTH]; | |
75 | ||
76 | /* Will be called when the system is done with the message | |
77 | (presumably to free it). */ | |
78 | void (*done)(struct ipmi_smi_msg *msg); | |
79 | }; | |
80 | ||
81 | struct ipmi_smi_handlers | |
82 | { | |
83 | struct module *owner; | |
84 | ||
453823ba CM |
85 | /* The low-level interface cannot start sending messages to |
86 | the upper layer until this function is called. This may | |
87 | not be NULL, the lower layer must take the interface from | |
88 | this call. */ | |
89 | int (*start_processing)(void *send_info, | |
90 | ipmi_smi_t new_intf); | |
91 | ||
1da177e4 LT |
92 | /* Called to enqueue an SMI message to be sent. This |
93 | operation is not allowed to fail. If an error occurs, it | |
94 | should report back the error in a received message. It may | |
95 | do this in the current call context, since no write locks | |
96 | are held when this is run. If the priority is > 0, the | |
97 | message will go into a high-priority queue and be sent | |
98 | first. Otherwise, it goes into a normal-priority queue. */ | |
99 | void (*sender)(void *send_info, | |
100 | struct ipmi_smi_msg *msg, | |
101 | int priority); | |
102 | ||
103 | /* Called by the upper layer to request that we try to get | |
104 | events from the BMC we are attached to. */ | |
105 | void (*request_events)(void *send_info); | |
106 | ||
107 | /* Called when the interface should go into "run to | |
108 | completion" mode. If this call sets the value to true, the | |
109 | interface should make sure that all messages are flushed | |
110 | out and that none are pending, and any new requests are run | |
111 | to completion immediately. */ | |
112 | void (*set_run_to_completion)(void *send_info, int run_to_completion); | |
113 | ||
114 | /* Called to poll for work to do. This is so upper layers can | |
115 | poll for operations during things like crash dumps. */ | |
116 | void (*poll)(void *send_info); | |
117 | ||
b9675136 CM |
118 | /* Enable/disable firmware maintenance mode. Note that this |
119 | is *not* the modes defined, this is simply an on/off | |
120 | setting. The message handler does the mode handling. Note | |
3a4fa0a2 | 121 | that this is called from interrupt context, so it cannot |
b9675136 CM |
122 | block. */ |
123 | void (*set_maintenance_mode)(void *send_info, int enable); | |
124 | ||
1da177e4 LT |
125 | /* Tell the handler that we are using it/not using it. The |
126 | message handler get the modules that this handler belongs | |
127 | to; this function lets the SMI claim any modules that it | |
128 | uses. These may be NULL if this is not required. */ | |
129 | int (*inc_usecount)(void *send_info); | |
130 | void (*dec_usecount)(void *send_info); | |
131 | }; | |
132 | ||
50c812b2 CM |
133 | struct ipmi_device_id { |
134 | unsigned char device_id; | |
135 | unsigned char device_revision; | |
136 | unsigned char firmware_revision_1; | |
137 | unsigned char firmware_revision_2; | |
138 | unsigned char ipmi_version; | |
139 | unsigned char additional_device_support; | |
140 | unsigned int manufacturer_id; | |
141 | unsigned int product_id; | |
142 | unsigned char aux_firmware_revision[4]; | |
143 | unsigned int aux_firmware_revision_set : 1; | |
144 | }; | |
145 | ||
146 | #define ipmi_version_major(v) ((v)->ipmi_version & 0xf) | |
147 | #define ipmi_version_minor(v) ((v)->ipmi_version >> 4) | |
148 | ||
149 | /* Take a pointer to a raw data buffer and a length and extract device | |
150 | id information from it. The first byte of data must point to the | |
d8c98618 CM |
151 | netfn << 2, the data should be of the format: |
152 | netfn << 2, cmd, completion code, data | |
153 | as normally comes from a device interface. */ | |
154 | static inline int ipmi_demangle_device_id(const unsigned char *data, | |
155 | unsigned int data_len, | |
156 | struct ipmi_device_id *id) | |
50c812b2 | 157 | { |
d8c98618 CM |
158 | if (data_len < 9) |
159 | return -EINVAL; | |
160 | if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 || | |
161 | data[1] != IPMI_GET_DEVICE_ID_CMD) | |
162 | /* Strange, didn't get the response we expected. */ | |
163 | return -EINVAL; | |
164 | if (data[2] != 0) | |
165 | /* That's odd, it shouldn't be able to fail. */ | |
166 | return -EINVAL; | |
167 | ||
168 | data += 3; | |
169 | data_len -= 3; | |
50c812b2 CM |
170 | id->device_id = data[0]; |
171 | id->device_revision = data[1]; | |
172 | id->firmware_revision_1 = data[2]; | |
173 | id->firmware_revision_2 = data[3]; | |
174 | id->ipmi_version = data[4]; | |
175 | id->additional_device_support = data[5]; | |
d8c98618 CM |
176 | if (data_len >= 6) { |
177 | id->manufacturer_id = (data[6] | (data[7] << 8) | | |
178 | (data[8] << 16)); | |
179 | id->product_id = data[9] | (data[10] << 8); | |
180 | } else { | |
181 | id->manufacturer_id = 0; | |
182 | id->product_id = 0; | |
183 | } | |
50c812b2 CM |
184 | if (data_len >= 15) { |
185 | memcpy(id->aux_firmware_revision, data+11, 4); | |
186 | id->aux_firmware_revision_set = 1; | |
187 | } else | |
188 | id->aux_firmware_revision_set = 0; | |
d8c98618 CM |
189 | |
190 | return 0; | |
50c812b2 CM |
191 | } |
192 | ||
1da177e4 | 193 | /* Add a low-level interface to the IPMI driver. Note that if the |
453823ba CM |
194 | interface doesn't know its slave address, it should pass in zero. |
195 | The low-level interface should not deliver any messages to the | |
196 | upper layer until the start_processing() function in the handlers | |
197 | is called, and the lower layer must get the interface from that | |
198 | call. */ | |
1da177e4 LT |
199 | int ipmi_register_smi(struct ipmi_smi_handlers *handlers, |
200 | void *send_info, | |
50c812b2 CM |
201 | struct ipmi_device_id *device_id, |
202 | struct device *dev, | |
759643b8 | 203 | const char *sysfs_name, |
453823ba | 204 | unsigned char slave_addr); |
1da177e4 LT |
205 | |
206 | /* | |
207 | * Remove a low-level interface from the IPMI driver. This will | |
208 | * return an error if the interface is still in use by a user. | |
209 | */ | |
210 | int ipmi_unregister_smi(ipmi_smi_t intf); | |
211 | ||
212 | /* | |
213 | * The lower layer reports received messages through this interface. | |
214 | * The data_size should be zero if this is an asyncronous message. If | |
215 | * the lower layer gets an error sending a message, it should format | |
216 | * an error response in the message response. | |
217 | */ | |
218 | void ipmi_smi_msg_received(ipmi_smi_t intf, | |
219 | struct ipmi_smi_msg *msg); | |
220 | ||
221 | /* The lower layer received a watchdog pre-timeout on interface. */ | |
222 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf); | |
223 | ||
224 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void); | |
225 | static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg) | |
226 | { | |
227 | msg->done(msg); | |
228 | } | |
229 | ||
230 | /* Allow the lower layer to add things to the proc filesystem | |
231 | directory for this interface. Note that the entry will | |
232 | automatically be dstroyed when the interface is destroyed. */ | |
233 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, | |
234 | read_proc_t *read_proc, write_proc_t *write_proc, | |
235 | void *data, struct module *owner); | |
236 | ||
237 | #endif /* __LINUX_IPMI_SMI_H */ |