Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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> |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 39 | #include <linux/platform_device.h> |
Zhao Yakui | 16f4232 | 2010-12-08 10:10:16 +0800 | [diff] [blame] | 40 | #include <linux/ipmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 42 | struct device; |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 63 | struct ipmi_smi_msg { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | struct list_head link; |
| 65 | |
| 66 | long msgid; |
| 67 | void *user_data; |
| 68 | |
| 69 | int data_size; |
| 70 | unsigned char data[IPMI_MAX_MSG_LENGTH]; |
| 71 | |
| 72 | int rsp_size; |
| 73 | unsigned char rsp[IPMI_MAX_MSG_LENGTH]; |
| 74 | |
| 75 | /* Will be called when the system is done with the message |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 76 | (presumably to free it). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | void (*done)(struct ipmi_smi_msg *msg); |
| 78 | }; |
| 79 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 80 | struct ipmi_smi_handlers { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct module *owner; |
| 82 | |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 83 | /* The low-level interface cannot start sending messages to |
| 84 | the upper layer until this function is called. This may |
| 85 | not be NULL, the lower layer must take the interface from |
| 86 | this call. */ |
| 87 | int (*start_processing)(void *send_info, |
| 88 | ipmi_smi_t new_intf); |
| 89 | |
Zhao Yakui | 16f4232 | 2010-12-08 10:10:16 +0800 | [diff] [blame] | 90 | /* |
| 91 | * Get the detailed private info of the low level interface and store |
| 92 | * it into the structure of ipmi_smi_data. For example: the |
| 93 | * ACPI device handle will be returned for the pnp_acpi IPMI device. |
| 94 | */ |
| 95 | int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data); |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* Called to enqueue an SMI message to be sent. This |
| 98 | operation is not allowed to fail. If an error occurs, it |
| 99 | should report back the error in a received message. It may |
| 100 | do this in the current call context, since no write locks |
Corey Minyard | 99ab32f | 2014-11-07 07:57:31 -0600 | [diff] [blame] | 101 | are held when this is run. Message are delivered one at |
| 102 | a time by the message handler, a new message will not be |
| 103 | delivered until the previous message is returned. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | void (*sender)(void *send_info, |
Corey Minyard | 99ab32f | 2014-11-07 07:57:31 -0600 | [diff] [blame] | 105 | struct ipmi_smi_msg *msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* Called by the upper layer to request that we try to get |
| 108 | events from the BMC we are attached to. */ |
| 109 | void (*request_events)(void *send_info); |
| 110 | |
Corey Minyard | 8998649 | 2014-04-14 09:46:54 -0500 | [diff] [blame] | 111 | /* Called by the upper layer when some user requires that the |
| 112 | interface watch for events, received messages, watchdog |
| 113 | pretimeouts, or not. Used by the SMI to know if it should |
| 114 | watch for these. This may be NULL if the SMI does not |
| 115 | implement it. */ |
Corey Minyard | 7aefac2 | 2014-04-14 09:46:56 -0500 | [diff] [blame] | 116 | void (*set_need_watch)(void *send_info, bool enable); |
Corey Minyard | 8998649 | 2014-04-14 09:46:54 -0500 | [diff] [blame] | 117 | |
Hidehiro Kawai | 82802f9 | 2015-07-27 14:55:16 +0900 | [diff] [blame] | 118 | /* |
| 119 | * Called when flushing all pending messages. |
| 120 | */ |
| 121 | void (*flush_messages)(void *send_info); |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* Called when the interface should go into "run to |
| 124 | completion" mode. If this call sets the value to true, the |
| 125 | interface should make sure that all messages are flushed |
| 126 | out and that none are pending, and any new requests are run |
| 127 | to completion immediately. */ |
Corey Minyard | 7aefac2 | 2014-04-14 09:46:56 -0500 | [diff] [blame] | 128 | void (*set_run_to_completion)(void *send_info, bool run_to_completion); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* Called to poll for work to do. This is so upper layers can |
| 131 | poll for operations during things like crash dumps. */ |
| 132 | void (*poll)(void *send_info); |
| 133 | |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 134 | /* Enable/disable firmware maintenance mode. Note that this |
| 135 | is *not* the modes defined, this is simply an on/off |
| 136 | setting. The message handler does the mode handling. Note |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 137 | that this is called from interrupt context, so it cannot |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 138 | block. */ |
Corey Minyard | 7aefac2 | 2014-04-14 09:46:56 -0500 | [diff] [blame] | 139 | void (*set_maintenance_mode)(void *send_info, bool enable); |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* Tell the handler that we are using it/not using it. The |
| 142 | message handler get the modules that this handler belongs |
| 143 | to; this function lets the SMI claim any modules that it |
| 144 | uses. These may be NULL if this is not required. */ |
| 145 | int (*inc_usecount)(void *send_info); |
| 146 | void (*dec_usecount)(void *send_info); |
| 147 | }; |
| 148 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 149 | struct ipmi_device_id { |
| 150 | unsigned char device_id; |
| 151 | unsigned char device_revision; |
| 152 | unsigned char firmware_revision_1; |
| 153 | unsigned char firmware_revision_2; |
| 154 | unsigned char ipmi_version; |
| 155 | unsigned char additional_device_support; |
| 156 | unsigned int manufacturer_id; |
| 157 | unsigned int product_id; |
| 158 | unsigned char aux_firmware_revision[4]; |
| 159 | unsigned int aux_firmware_revision_set : 1; |
| 160 | }; |
| 161 | |
| 162 | #define ipmi_version_major(v) ((v)->ipmi_version & 0xf) |
| 163 | #define ipmi_version_minor(v) ((v)->ipmi_version >> 4) |
| 164 | |
| 165 | /* Take a pointer to a raw data buffer and a length and extract device |
| 166 | id information from it. The first byte of data must point to the |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 167 | netfn << 2, the data should be of the format: |
| 168 | netfn << 2, cmd, completion code, data |
| 169 | as normally comes from a device interface. */ |
| 170 | static inline int ipmi_demangle_device_id(const unsigned char *data, |
| 171 | unsigned int data_len, |
| 172 | struct ipmi_device_id *id) |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 173 | { |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 174 | if (data_len < 9) |
| 175 | return -EINVAL; |
| 176 | if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 || |
| 177 | data[1] != IPMI_GET_DEVICE_ID_CMD) |
| 178 | /* Strange, didn't get the response we expected. */ |
| 179 | return -EINVAL; |
| 180 | if (data[2] != 0) |
| 181 | /* That's odd, it shouldn't be able to fail. */ |
| 182 | return -EINVAL; |
| 183 | |
| 184 | data += 3; |
| 185 | data_len -= 3; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 186 | id->device_id = data[0]; |
| 187 | id->device_revision = data[1]; |
| 188 | id->firmware_revision_1 = data[2]; |
| 189 | id->firmware_revision_2 = data[3]; |
| 190 | id->ipmi_version = data[4]; |
| 191 | id->additional_device_support = data[5]; |
Corey Minyard | 64e862a | 2007-10-29 14:37:13 -0700 | [diff] [blame] | 192 | if (data_len >= 11) { |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 193 | id->manufacturer_id = (data[6] | (data[7] << 8) | |
| 194 | (data[8] << 16)); |
| 195 | id->product_id = data[9] | (data[10] << 8); |
| 196 | } else { |
| 197 | id->manufacturer_id = 0; |
| 198 | id->product_id = 0; |
| 199 | } |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 200 | if (data_len >= 15) { |
| 201 | memcpy(id->aux_firmware_revision, data+11, 4); |
| 202 | id->aux_firmware_revision_set = 1; |
| 203 | } else |
| 204 | id->aux_firmware_revision_set = 0; |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 205 | |
| 206 | return 0; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* Add a low-level interface to the IPMI driver. Note that if the |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 210 | interface doesn't know its slave address, it should pass in zero. |
| 211 | The low-level interface should not deliver any messages to the |
| 212 | upper layer until the start_processing() function in the handlers |
| 213 | is called, and the lower layer must get the interface from that |
| 214 | call. */ |
Corey Minyard | 81d02b7 | 2015-06-13 10:34:25 -0500 | [diff] [blame] | 215 | int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | void *send_info, |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 217 | struct ipmi_device_id *device_id, |
| 218 | struct device *dev, |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 219 | unsigned char slave_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | * Remove a low-level interface from the IPMI driver. This will |
| 223 | * return an error if the interface is still in use by a user. |
| 224 | */ |
| 225 | int ipmi_unregister_smi(ipmi_smi_t intf); |
| 226 | |
| 227 | /* |
| 228 | * The lower layer reports received messages through this interface. |
Adam Buchbinder | b3834be | 2012-09-19 21:48:02 -0400 | [diff] [blame] | 229 | * 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] | 230 | * the lower layer gets an error sending a message, it should format |
| 231 | * an error response in the message response. |
| 232 | */ |
| 233 | void ipmi_smi_msg_received(ipmi_smi_t intf, |
| 234 | struct ipmi_smi_msg *msg); |
| 235 | |
| 236 | /* The lower layer received a watchdog pre-timeout on interface. */ |
| 237 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf); |
| 238 | |
| 239 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void); |
| 240 | static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg) |
| 241 | { |
| 242 | msg->done(msg); |
| 243 | } |
| 244 | |
| 245 | /* Allow the lower layer to add things to the proc filesystem |
| 246 | directory for this interface. Note that the entry will |
| 247 | automatically be dstroyed when the interface is destroyed. */ |
| 248 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 249 | const struct file_operations *proc_ops, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 250 | void *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | #endif /* __LINUX_IPMI_SMI_H */ |