Merge tag 'drm-misc-fixes-2019-06-05' of git://anongit.freedesktop.org/drm/drm-misc...
[linux-2.6-block.git] / include / linux / ipmi_smi.h
CommitLineData
243ac210 1/* SPDX-License-Identifier: GPL-2.0+ */
1da177e4
LT
2/*
3 * ipmi_smi.h
4 *
5 * MontaVista IPMI system management interface
6 *
7 * Author: MontaVista Software, Inc.
8 * Corey Minyard <minyard@mvista.com>
9 * source@mvista.com
10 *
11 * Copyright 2002 MontaVista Software Inc.
12 *
1da177e4
LT
13 */
14
15#ifndef __LINUX_IPMI_SMI_H
16#define __LINUX_IPMI_SMI_H
17
18#include <linux/ipmi_msgdefs.h>
19#include <linux/proc_fs.h>
50c812b2 20#include <linux/platform_device.h>
16f4232c 21#include <linux/ipmi.h>
1da177e4 22
313162d0
PG
23struct device;
24
6dc1181f
CM
25/*
26 * This files describes the interface for IPMI system management interface
27 * drivers to bind into the IPMI message handler.
28 */
1da177e4
LT
29
30/* Structure for the low-level drivers. */
4372ea94 31struct ipmi_smi;
1da177e4 32
c65ea996
CM
33/*
34 * Flags for set_check_watch() below. Tells if the SMI should be
e1891cff 35 * waiting for watchdog timeouts, commands and/or messages.
c65ea996 36 */
e1891cff
CM
37#define IPMI_WATCH_MASK_CHECK_MESSAGES (1 << 0)
38#define IPMI_WATCH_MASK_CHECK_WATCHDOG (1 << 1)
39#define IPMI_WATCH_MASK_CHECK_COMMANDS (1 << 2)
c65ea996 40
1da177e4
LT
41/*
42 * Messages to/from the lower layer. The smi interface will take one
43 * of these to send. After the send has occurred and a response has
44 * been received, it will report this same data structure back up to
45 * the upper layer. If an error occurs, it should fill in the
46 * response with an error code in the completion code location. When
47 * asynchronous data is received, one of these is allocated, the
48 * data_size is set to zero and the response holds the data from the
49 * get message or get event command that the interface initiated.
50 * Note that it is the interfaces responsibility to detect
51 * asynchronous data and messages and request them from the
52 * interface.
53 */
c70d7499 54struct ipmi_smi_msg {
1da177e4
LT
55 struct list_head link;
56
57 long msgid;
58 void *user_data;
59
60 int data_size;
61 unsigned char data[IPMI_MAX_MSG_LENGTH];
62
63 int rsp_size;
64 unsigned char rsp[IPMI_MAX_MSG_LENGTH];
65
c65ea996
CM
66 /*
67 * Will be called when the system is done with the message
68 * (presumably to free it).
69 */
1da177e4
LT
70 void (*done)(struct ipmi_smi_msg *msg);
71};
72
c70d7499 73struct ipmi_smi_handlers {
1da177e4
LT
74 struct module *owner;
75
6dc1181f
CM
76 /*
77 * The low-level interface cannot start sending messages to
78 * the upper layer until this function is called. This may
79 * not be NULL, the lower layer must take the interface from
80 * this call.
81 */
5ce1a7dc
CM
82 int (*start_processing)(void *send_info,
83 struct ipmi_smi *new_intf);
453823ba 84
b7780dab
CM
85 /*
86 * When called, the low-level interface should disable all
87 * processing, it should be complete shut down when it returns.
88 */
89 void (*shutdown)(void *send_info);
90
16f4232c
ZY
91 /*
92 * Get the detailed private info of the low level interface and store
93 * it into the structure of ipmi_smi_data. For example: the
94 * ACPI device handle will be returned for the pnp_acpi IPMI device.
95 */
96 int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
97
6dc1181f
CM
98 /*
99 * Called to enqueue an SMI message to be sent. This
100 * operation is not allowed to fail. If an error occurs, it
101 * should report back the error in a received message. It may
102 * do this in the current call context, since no write locks
103 * are held when this is run. Message are delivered one at
104 * a time by the message handler, a new message will not be
105 * delivered until the previous message is returned.
106 */
1da177e4 107 void (*sender)(void *send_info,
99ab32f3 108 struct ipmi_smi_msg *msg);
1da177e4 109
6dc1181f
CM
110 /*
111 * Called by the upper layer to request that we try to get
112 * events from the BMC we are attached to.
113 */
1da177e4
LT
114 void (*request_events)(void *send_info);
115
6dc1181f
CM
116 /*
117 * Called by the upper layer when some user requires that the
c65ea996
CM
118 * interface watch for received messages and watchdog
119 * pretimeouts (basically do a "Get Flags", or not. Used by
120 * the SMI to know if it should watch for these. This may be
121 * NULL if the SMI does not implement it. watch_mask is from
122 * IPMI_WATCH_MASK_xxx above. The interface should run slower
123 * timeouts for just watchdog checking or faster timeouts when
124 * waiting for the message queue.
6dc1181f 125 */
c65ea996 126 void (*set_need_watch)(void *send_info, unsigned int watch_mask);
89986496 127
82802f96
HK
128 /*
129 * Called when flushing all pending messages.
130 */
131 void (*flush_messages)(void *send_info);
132
6dc1181f
CM
133 /*
134 * Called when the interface should go into "run to
135 * completion" mode. If this call sets the value to true, the
136 * interface should make sure that all messages are flushed
137 * out and that none are pending, and any new requests are run
138 * to completion immediately.
139 */
7aefac26 140 void (*set_run_to_completion)(void *send_info, bool run_to_completion);
1da177e4 141
6dc1181f
CM
142 /*
143 * Called to poll for work to do. This is so upper layers can
144 * poll for operations during things like crash dumps.
145 */
1da177e4
LT
146 void (*poll)(void *send_info);
147
6dc1181f
CM
148 /*
149 * Enable/disable firmware maintenance mode. Note that this
150 * is *not* the modes defined, this is simply an on/off
151 * setting. The message handler does the mode handling. Note
152 * that this is called from interrupt context, so it cannot
153 * block.
154 */
7aefac26 155 void (*set_maintenance_mode)(void *send_info, bool enable);
1da177e4
LT
156};
157
50c812b2
CM
158struct ipmi_device_id {
159 unsigned char device_id;
160 unsigned char device_revision;
161 unsigned char firmware_revision_1;
162 unsigned char firmware_revision_2;
163 unsigned char ipmi_version;
164 unsigned char additional_device_support;
165 unsigned int manufacturer_id;
166 unsigned int product_id;
167 unsigned char aux_firmware_revision[4];
168 unsigned int aux_firmware_revision_set : 1;
169};
170
171#define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
172#define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
173
6dc1181f
CM
174/*
175 * Take a pointer to an IPMI response and extract device id information from
c468f911
JK
176 * it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from
177 * a SI response.
178 */
179static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
180 const unsigned char *data,
d8c98618
CM
181 unsigned int data_len,
182 struct ipmi_device_id *id)
50c812b2 183{
c468f911 184 if (data_len < 7)
d8c98618 185 return -EINVAL;
c468f911 186 if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD)
d8c98618
CM
187 /* Strange, didn't get the response we expected. */
188 return -EINVAL;
c468f911 189 if (data[0] != 0)
d8c98618
CM
190 /* That's odd, it shouldn't be able to fail. */
191 return -EINVAL;
192
c468f911
JK
193 data++;
194 data_len--;
195
50c812b2
CM
196 id->device_id = data[0];
197 id->device_revision = data[1];
198 id->firmware_revision_1 = data[2];
199 id->firmware_revision_2 = data[3];
200 id->ipmi_version = data[4];
201 id->additional_device_support = data[5];
64e862a5 202 if (data_len >= 11) {
d8c98618
CM
203 id->manufacturer_id = (data[6] | (data[7] << 8) |
204 (data[8] << 16));
205 id->product_id = data[9] | (data[10] << 8);
206 } else {
207 id->manufacturer_id = 0;
208 id->product_id = 0;
209 }
50c812b2
CM
210 if (data_len >= 15) {
211 memcpy(id->aux_firmware_revision, data+11, 4);
212 id->aux_firmware_revision_set = 1;
213 } else
214 id->aux_firmware_revision_set = 0;
d8c98618
CM
215
216 return 0;
50c812b2
CM
217}
218
6dc1181f
CM
219/*
220 * Add a low-level interface to the IPMI driver. Note that if the
221 * interface doesn't know its slave address, it should pass in zero.
222 * The low-level interface should not deliver any messages to the
223 * upper layer until the start_processing() function in the handlers
224 * is called, and the lower layer must get the interface from that
225 * call.
226 */
81d02b7f 227int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
1da177e4 228 void *send_info,
50c812b2 229 struct device *dev,
453823ba 230 unsigned char slave_addr);
1da177e4
LT
231
232/*
233 * Remove a low-level interface from the IPMI driver. This will
234 * return an error if the interface is still in use by a user.
235 */
5ce1a7dc 236void ipmi_unregister_smi(struct ipmi_smi *intf);
1da177e4
LT
237
238/*
239 * The lower layer reports received messages through this interface.
b3834be5 240 * The data_size should be zero if this is an asynchronous message. If
1da177e4
LT
241 * the lower layer gets an error sending a message, it should format
242 * an error response in the message response.
243 */
5ce1a7dc 244void ipmi_smi_msg_received(struct ipmi_smi *intf,
1da177e4
LT
245 struct ipmi_smi_msg *msg);
246
247/* The lower layer received a watchdog pre-timeout on interface. */
5ce1a7dc 248void ipmi_smi_watchdog_pretimeout(struct ipmi_smi *intf);
1da177e4
LT
249
250struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
251static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
252{
253 msg->done(msg);
254}
255
1da177e4 256#endif /* __LINUX_IPMI_SMI_H */