ipmi_smi.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #ifndef __LINUX_IPMI_SMI_H
  34. #define __LINUX_IPMI_SMI_H
  35. #include <linux/ipmi_msgdefs.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/ipmi.h>
  39. struct device;
  40. /* This files describes the interface for IPMI system management interface
  41. drivers to bind into the IPMI message handler. */
  42. /* Structure for the low-level drivers. */
  43. typedef struct ipmi_smi *ipmi_smi_t;
  44. /*
  45. * Messages to/from the lower layer. The smi interface will take one
  46. * of these to send. After the send has occurred and a response has
  47. * been received, it will report this same data structure back up to
  48. * the upper layer. If an error occurs, it should fill in the
  49. * response with an error code in the completion code location. When
  50. * asynchronous data is received, one of these is allocated, the
  51. * data_size is set to zero and the response holds the data from the
  52. * get message or get event command that the interface initiated.
  53. * Note that it is the interfaces responsibility to detect
  54. * asynchronous data and messages and request them from the
  55. * interface.
  56. */
  57. struct ipmi_smi_msg {
  58. struct list_head link;
  59. long msgid;
  60. void *user_data;
  61. int data_size;
  62. unsigned char data[IPMI_MAX_MSG_LENGTH];
  63. int rsp_size;
  64. unsigned char rsp[IPMI_MAX_MSG_LENGTH];
  65. /* Will be called when the system is done with the message
  66. (presumably to free it). */
  67. void (*done)(struct ipmi_smi_msg *msg);
  68. };
  69. struct ipmi_smi_handlers {
  70. struct module *owner;
  71. /* The low-level interface cannot start sending messages to
  72. the upper layer until this function is called. This may
  73. not be NULL, the lower layer must take the interface from
  74. this call. */
  75. int (*start_processing)(void *send_info,
  76. ipmi_smi_t new_intf);
  77. /*
  78. * Get the detailed private info of the low level interface and store
  79. * it into the structure of ipmi_smi_data. For example: the
  80. * ACPI device handle will be returned for the pnp_acpi IPMI device.
  81. */
  82. int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
  83. /* Called to enqueue an SMI message to be sent. This
  84. operation is not allowed to fail. If an error occurs, it
  85. should report back the error in a received message. It may
  86. do this in the current call context, since no write locks
  87. are held when this is run. Message are delivered one at
  88. a time by the message handler, a new message will not be
  89. delivered until the previous message is returned. */
  90. void (*sender)(void *send_info,
  91. struct ipmi_smi_msg *msg);
  92. /* Called by the upper layer to request that we try to get
  93. events from the BMC we are attached to. */
  94. void (*request_events)(void *send_info);
  95. /* Called by the upper layer when some user requires that the
  96. interface watch for events, received messages, watchdog
  97. pretimeouts, or not. Used by the SMI to know if it should
  98. watch for these. This may be NULL if the SMI does not
  99. implement it. */
  100. void (*set_need_watch)(void *send_info, bool enable);
  101. /*
  102. * Called when flushing all pending messages.
  103. */
  104. void (*flush_messages)(void *send_info);
  105. /* Called when the interface should go into "run to
  106. completion" mode. If this call sets the value to true, the
  107. interface should make sure that all messages are flushed
  108. out and that none are pending, and any new requests are run
  109. to completion immediately. */
  110. void (*set_run_to_completion)(void *send_info, bool run_to_completion);
  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. /* Enable/disable firmware maintenance mode. Note that this
  115. is *not* the modes defined, this is simply an on/off
  116. setting. The message handler does the mode handling. Note
  117. that this is called from interrupt context, so it cannot
  118. block. */
  119. void (*set_maintenance_mode)(void *send_info, bool enable);
  120. /* Tell the handler that we are using it/not using it. The
  121. message handler get the modules that this handler belongs
  122. to; this function lets the SMI claim any modules that it
  123. uses. These may be NULL if this is not required. */
  124. int (*inc_usecount)(void *send_info);
  125. void (*dec_usecount)(void *send_info);
  126. };
  127. struct ipmi_device_id {
  128. unsigned char device_id;
  129. unsigned char device_revision;
  130. unsigned char firmware_revision_1;
  131. unsigned char firmware_revision_2;
  132. unsigned char ipmi_version;
  133. unsigned char additional_device_support;
  134. unsigned int manufacturer_id;
  135. unsigned int product_id;
  136. unsigned char aux_firmware_revision[4];
  137. unsigned int aux_firmware_revision_set : 1;
  138. };
  139. #define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
  140. #define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
  141. /* Take a pointer to a raw data buffer and a length and extract device
  142. id information from it. The first byte of data must point to the
  143. netfn << 2, the data should be of the format:
  144. netfn << 2, cmd, completion code, data
  145. as normally comes from a device interface. */
  146. static inline int ipmi_demangle_device_id(const unsigned char *data,
  147. unsigned int data_len,
  148. struct ipmi_device_id *id)
  149. {
  150. if (data_len < 9)
  151. return -EINVAL;
  152. if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 ||
  153. data[1] != IPMI_GET_DEVICE_ID_CMD)
  154. /* Strange, didn't get the response we expected. */
  155. return -EINVAL;
  156. if (data[2] != 0)
  157. /* That's odd, it shouldn't be able to fail. */
  158. return -EINVAL;
  159. data += 3;
  160. data_len -= 3;
  161. id->device_id = data[0];
  162. id->device_revision = data[1];
  163. id->firmware_revision_1 = data[2];
  164. id->firmware_revision_2 = data[3];
  165. id->ipmi_version = data[4];
  166. id->additional_device_support = data[5];
  167. if (data_len >= 11) {
  168. id->manufacturer_id = (data[6] | (data[7] << 8) |
  169. (data[8] << 16));
  170. id->product_id = data[9] | (data[10] << 8);
  171. } else {
  172. id->manufacturer_id = 0;
  173. id->product_id = 0;
  174. }
  175. if (data_len >= 15) {
  176. memcpy(id->aux_firmware_revision, data+11, 4);
  177. id->aux_firmware_revision_set = 1;
  178. } else
  179. id->aux_firmware_revision_set = 0;
  180. return 0;
  181. }
  182. /* Add a low-level interface to the IPMI driver. Note that if the
  183. interface doesn't know its slave address, it should pass in zero.
  184. The low-level interface should not deliver any messages to the
  185. upper layer until the start_processing() function in the handlers
  186. is called, and the lower layer must get the interface from that
  187. call. */
  188. int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
  189. void *send_info,
  190. struct ipmi_device_id *device_id,
  191. struct device *dev,
  192. unsigned char slave_addr);
  193. /*
  194. * Remove a low-level interface from the IPMI driver. This will
  195. * return an error if the interface is still in use by a user.
  196. */
  197. int ipmi_unregister_smi(ipmi_smi_t intf);
  198. /*
  199. * The lower layer reports received messages through this interface.
  200. * The data_size should be zero if this is an asynchronous message. If
  201. * the lower layer gets an error sending a message, it should format
  202. * an error response in the message response.
  203. */
  204. void ipmi_smi_msg_received(ipmi_smi_t intf,
  205. struct ipmi_smi_msg *msg);
  206. /* The lower layer received a watchdog pre-timeout on interface. */
  207. void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
  208. struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
  209. static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
  210. {
  211. msg->done(msg);
  212. }
  213. /* Allow the lower layer to add things to the proc filesystem
  214. directory for this interface. Note that the entry will
  215. automatically be dstroyed when the interface is destroyed. */
  216. int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
  217. const struct file_operations *proc_ops,
  218. void *data);
  219. #endif /* __LINUX_IPMI_SMI_H */