Corey Minyard | 243ac21 | 2018-02-20 07:30:22 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Zhao Yakui | 16f4232 | 2010-12-08 10:10:16 +0800 | [diff] [blame] | 21 | #include <linux/ipmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 23 | struct device; |
| 24 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 25 | /* |
| 26 | * This files describes the interface for IPMI system management interface |
| 27 | * drivers to bind into the IPMI message handler. |
| 28 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | /* Structure for the low-level drivers. */ |
Corey Minyard | 4372ea9 | 2018-04-18 10:00:47 -0500 | [diff] [blame] | 31 | struct ipmi_smi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 34 | * Flags for set_check_watch() below. Tells if the SMI should be |
Corey Minyard | e1891cf | 2018-10-24 15:17:04 -0500 | [diff] [blame] | 35 | * waiting for watchdog timeouts, commands and/or messages. |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 36 | */ |
Corey Minyard | e1891cf | 2018-10-24 15:17:04 -0500 | [diff] [blame] | 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) |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 40 | |
| 41 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 54 | struct ipmi_smi_msg { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 66 | /* |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 67 | * Will be called when the system is done with the message |
| 68 | * (presumably to free it). |
| 69 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | void (*done)(struct ipmi_smi_msg *msg); |
| 71 | }; |
| 72 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 73 | struct ipmi_smi_handlers { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | struct module *owner; |
| 75 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 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 | */ |
Corey Minyard | 5ce1a7d | 2018-04-11 13:11:54 -0500 | [diff] [blame] | 82 | int (*start_processing)(void *send_info, |
| 83 | struct ipmi_smi *new_intf); |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 84 | |
Zhao Yakui | 16f4232 | 2010-12-08 10:10:16 +0800 | [diff] [blame] | 85 | /* |
Corey Minyard | b7780da | 2018-04-05 16:44:12 -0500 | [diff] [blame] | 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 | |
| 91 | /* |
Zhao Yakui | 16f4232 | 2010-12-08 10:10:16 +0800 | [diff] [blame] | 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 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | void (*sender)(void *send_info, |
Corey Minyard | 99ab32f | 2014-11-07 07:57:31 -0600 | [diff] [blame] | 108 | struct ipmi_smi_msg *msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 110 | /* |
| 111 | * Called by the upper layer to request that we try to get |
| 112 | * events from the BMC we are attached to. |
| 113 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | void (*request_events)(void *send_info); |
| 115 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 116 | /* |
| 117 | * Called by the upper layer when some user requires that the |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 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. |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 125 | */ |
Corey Minyard | c65ea99 | 2018-10-23 11:29:02 -0500 | [diff] [blame] | 126 | void (*set_need_watch)(void *send_info, unsigned int watch_mask); |
Corey Minyard | 8998649 | 2014-04-14 09:46:54 -0500 | [diff] [blame] | 127 | |
Hidehiro Kawai | 82802f9 | 2015-07-27 14:55:16 +0900 | [diff] [blame] | 128 | /* |
| 129 | * Called when flushing all pending messages. |
| 130 | */ |
| 131 | void (*flush_messages)(void *send_info); |
| 132 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 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 | */ |
Corey Minyard | 7aefac2 | 2014-04-14 09:46:56 -0500 | [diff] [blame] | 140 | void (*set_run_to_completion)(void *send_info, bool run_to_completion); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | void (*poll)(void *send_info); |
| 147 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 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 | */ |
Corey Minyard | 7aefac2 | 2014-04-14 09:46:56 -0500 | [diff] [blame] | 155 | void (*set_maintenance_mode)(void *send_info, bool enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 158 | struct 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 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 174 | /* |
| 175 | * Take a pointer to an IPMI response and extract device id information from |
Jeremy Kerr | c468f91 | 2017-08-25 15:47:23 +0800 | [diff] [blame] | 176 | * it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from |
| 177 | * a SI response. |
| 178 | */ |
| 179 | static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd, |
| 180 | const unsigned char *data, |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 181 | unsigned int data_len, |
| 182 | struct ipmi_device_id *id) |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 183 | { |
Jeremy Kerr | c468f91 | 2017-08-25 15:47:23 +0800 | [diff] [blame] | 184 | if (data_len < 7) |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 185 | return -EINVAL; |
Jeremy Kerr | c468f91 | 2017-08-25 15:47:23 +0800 | [diff] [blame] | 186 | if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD) |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 187 | /* Strange, didn't get the response we expected. */ |
| 188 | return -EINVAL; |
Jeremy Kerr | c468f91 | 2017-08-25 15:47:23 +0800 | [diff] [blame] | 189 | if (data[0] != 0) |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 190 | /* That's odd, it shouldn't be able to fail. */ |
| 191 | return -EINVAL; |
| 192 | |
Jeremy Kerr | c468f91 | 2017-08-25 15:47:23 +0800 | [diff] [blame] | 193 | data++; |
| 194 | data_len--; |
| 195 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 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]; |
Corey Minyard | 64e862a | 2007-10-29 14:37:13 -0700 | [diff] [blame] | 202 | if (data_len >= 11) { |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 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 | } |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 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; |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 215 | |
| 216 | return 0; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Corey Minyard | 6dc1181 | 2018-04-04 08:54:05 -0500 | [diff] [blame] | 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 | */ |
Corey Minyard | cbb7986 | 2019-10-14 10:35:56 -0500 | [diff] [blame] | 227 | int ipmi_add_smi(struct module *owner, |
| 228 | const struct ipmi_smi_handlers *handlers, |
| 229 | void *send_info, |
| 230 | struct device *dev, |
| 231 | unsigned char slave_addr); |
| 232 | |
| 233 | #define ipmi_register_smi(handlers, send_info, dev, slave_addr) \ |
| 234 | ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * Remove a low-level interface from the IPMI driver. This will |
| 238 | * return an error if the interface is still in use by a user. |
| 239 | */ |
Corey Minyard | 5ce1a7d | 2018-04-11 13:11:54 -0500 | [diff] [blame] | 240 | void ipmi_unregister_smi(struct ipmi_smi *intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * The lower layer reports received messages through this interface. |
Adam Buchbinder | b3834be | 2012-09-19 21:48:02 -0400 | [diff] [blame] | 244 | * The data_size should be zero if this is an asynchronous message. If |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | * the lower layer gets an error sending a message, it should format |
| 246 | * an error response in the message response. |
| 247 | */ |
Corey Minyard | 5ce1a7d | 2018-04-11 13:11:54 -0500 | [diff] [blame] | 248 | void ipmi_smi_msg_received(struct ipmi_smi *intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | struct ipmi_smi_msg *msg); |
| 250 | |
| 251 | /* The lower layer received a watchdog pre-timeout on interface. */ |
Corey Minyard | 5ce1a7d | 2018-04-11 13:11:54 -0500 | [diff] [blame] | 252 | void ipmi_smi_watchdog_pretimeout(struct ipmi_smi *intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void); |
| 255 | static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg) |
| 256 | { |
| 257 | msg->done(msg); |
| 258 | } |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | #endif /* __LINUX_IPMI_SMI_H */ |