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