Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0+ */
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 *
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>
20#include <linux/platform_device.h>
21#include <linux/ipmi.h>
22
23struct device;
24
25/* This files describes the interface for IPMI system management interface
26 drivers to bind into the IPMI message handler. */
27
28/* Structure for the low-level drivers. */
29typedef struct ipmi_smi *ipmi_smi_t;
30
31/*
32 * Messages to/from the lower layer. The smi interface will take one
33 * of these to send. After the send has occurred and a response has
34 * been received, it will report this same data structure back up to
35 * the upper layer. If an error occurs, it should fill in the
36 * response with an error code in the completion code location. When
37 * asynchronous data is received, one of these is allocated, the
38 * data_size is set to zero and the response holds the data from the
39 * get message or get event command that the interface initiated.
40 * Note that it is the interfaces responsibility to detect
41 * asynchronous data and messages and request them from the
42 * interface.
43 */
44struct ipmi_smi_msg {
45 struct list_head link;
46
47 long msgid;
48 void *user_data;
49
50 int data_size;
51 unsigned char data[IPMI_MAX_MSG_LENGTH];
52
53 int rsp_size;
54 unsigned char rsp[IPMI_MAX_MSG_LENGTH];
55
56 /* Will be called when the system is done with the message
57 (presumably to free it). */
58 void (*done)(struct ipmi_smi_msg *msg);
59};
60
61struct ipmi_smi_handlers {
62 struct module *owner;
63
64 /* The low-level interface cannot start sending messages to
65 the upper layer until this function is called. This may
66 not be NULL, the lower layer must take the interface from
67 this call. */
68 int (*start_processing)(void *send_info,
69 ipmi_smi_t new_intf);
70
71 /*
72 * Get the detailed private info of the low level interface and store
73 * it into the structure of ipmi_smi_data. For example: the
74 * ACPI device handle will be returned for the pnp_acpi IPMI device.
75 */
76 int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
77
78 /* Called to enqueue an SMI message to be sent. This
79 operation is not allowed to fail. If an error occurs, it
80 should report back the error in a received message. It may
81 do this in the current call context, since no write locks
82 are held when this is run. Message are delivered one at
83 a time by the message handler, a new message will not be
84 delivered until the previous message is returned. */
85 void (*sender)(void *send_info,
86 struct ipmi_smi_msg *msg);
87
88 /* Called by the upper layer to request that we try to get
89 events from the BMC we are attached to. */
90 void (*request_events)(void *send_info);
91
92 /* Called by the upper layer when some user requires that the
93 interface watch for events, received messages, watchdog
94 pretimeouts, or not. Used by the SMI to know if it should
95 watch for these. This may be NULL if the SMI does not
96 implement it. */
97 void (*set_need_watch)(void *send_info, bool enable);
98
99 /*
100 * Called when flushing all pending messages.
101 */
102 void (*flush_messages)(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, bool 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
115 /* 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
118 that this is called from interrupt context, so it cannot
119 block. */
120 void (*set_maintenance_mode)(void *send_info, bool enable);
121
122 /* 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
130struct 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 an IPMI response and extract device id information from
147 * it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from
148 * a SI response.
149 */
150static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
151 const unsigned char *data,
152 unsigned int data_len,
153 struct ipmi_device_id *id)
154{
155 if (data_len < 7)
156 return -EINVAL;
157 if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD)
158 /* Strange, didn't get the response we expected. */
159 return -EINVAL;
160 if (data[0] != 0)
161 /* That's odd, it shouldn't be able to fail. */
162 return -EINVAL;
163
164 data++;
165 data_len--;
166
167 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];
173 if (data_len >= 11) {
174 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 }
181 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;
186
187 return 0;
188}
189
190/* Add a low-level interface to the IPMI driver. Note that if the
191 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. */
196int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
197 void *send_info,
198 struct device *dev,
199 unsigned char slave_addr);
200
201/*
202 * Remove a low-level interface from the IPMI driver. This will
203 * return an error if the interface is still in use by a user.
204 */
205int ipmi_unregister_smi(ipmi_smi_t intf);
206
207/*
208 * The lower layer reports received messages through this interface.
209 * The data_size should be zero if this is an asynchronous message. If
210 * the lower layer gets an error sending a message, it should format
211 * an error response in the message response.
212 */
213void ipmi_smi_msg_received(ipmi_smi_t intf,
214 struct ipmi_smi_msg *msg);
215
216/* The lower layer received a watchdog pre-timeout on interface. */
217void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
218
219struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
220static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
221{
222 msg->done(msg);
223}
224
225#ifdef CONFIG_IPMI_PROC_INTERFACE
226/* Allow the lower layer to add things to the proc filesystem
227 directory for this interface. Note that the entry will
228 automatically be dstroyed when the interface is destroyed. */
229int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
230 const struct file_operations *proc_ops,
231 void *data);
232#endif
233
234#endif /* __LINUX_IPMI_SMI_H */