ipmi_smi.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/module.h>
  38. #include <linux/device.h>
  39. #include <linux/platform_device.h>
  40. #include <linux/ipmi_smi.h>
  41. /* This files describes the interface for IPMI system management interface
  42. drivers to bind into the IPMI message handler. */
  43. /* Structure for the low-level drivers. */
  44. typedef struct ipmi_smi *ipmi_smi_t;
  45. /*
  46. * Messages to/from the lower layer. The smi interface will take one
  47. * of these to send. After the send has occurred and a response has
  48. * been received, it will report this same data structure back up to
  49. * the upper layer. If an error occurs, it should fill in the
  50. * response with an error code in the completion code location. When
  51. * asynchronous data is received, one of these is allocated, the
  52. * data_size is set to zero and the response holds the data from the
  53. * get message or get event command that the interface initiated.
  54. * Note that it is the interfaces responsibility to detect
  55. * asynchronous data and messages and request them from the
  56. * interface.
  57. */
  58. struct ipmi_smi_msg
  59. {
  60. struct list_head link;
  61. long msgid;
  62. void *user_data;
  63. int data_size;
  64. unsigned char data[IPMI_MAX_MSG_LENGTH];
  65. int rsp_size;
  66. unsigned char rsp[IPMI_MAX_MSG_LENGTH];
  67. /* Will be called when the system is done with the message
  68. (presumably to free it). */
  69. void (*done)(struct ipmi_smi_msg *msg);
  70. };
  71. struct ipmi_smi_handlers
  72. {
  73. struct module *owner;
  74. /* The low-level interface cannot start sending messages to
  75. the upper layer until this function is called. This may
  76. not be NULL, the lower layer must take the interface from
  77. this call. */
  78. int (*start_processing)(void *send_info,
  79. ipmi_smi_t new_intf);
  80. /* Called to enqueue an SMI message to be sent. This
  81. operation is not allowed to fail. If an error occurs, it
  82. should report back the error in a received message. It may
  83. do this in the current call context, since no write locks
  84. are held when this is run. If the priority is > 0, the
  85. message will go into a high-priority queue and be sent
  86. first. Otherwise, it goes into a normal-priority queue. */
  87. void (*sender)(void *send_info,
  88. struct ipmi_smi_msg *msg,
  89. int priority);
  90. /* Called by the upper layer to request that we try to get
  91. events from the BMC we are attached to. */
  92. void (*request_events)(void *send_info);
  93. /* Called when the interface should go into "run to
  94. completion" mode. If this call sets the value to true, the
  95. interface should make sure that all messages are flushed
  96. out and that none are pending, and any new requests are run
  97. to completion immediately. */
  98. void (*set_run_to_completion)(void *send_info, int run_to_completion);
  99. /* Called to poll for work to do. This is so upper layers can
  100. poll for operations during things like crash dumps. */
  101. void (*poll)(void *send_info);
  102. /* Tell the handler that we are using it/not using it. The
  103. message handler get the modules that this handler belongs
  104. to; this function lets the SMI claim any modules that it
  105. uses. These may be NULL if this is not required. */
  106. int (*inc_usecount)(void *send_info);
  107. void (*dec_usecount)(void *send_info);
  108. };
  109. struct ipmi_device_id {
  110. unsigned char device_id;
  111. unsigned char device_revision;
  112. unsigned char firmware_revision_1;
  113. unsigned char firmware_revision_2;
  114. unsigned char ipmi_version;
  115. unsigned char additional_device_support;
  116. unsigned int manufacturer_id;
  117. unsigned int product_id;
  118. unsigned char aux_firmware_revision[4];
  119. unsigned int aux_firmware_revision_set : 1;
  120. };
  121. #define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
  122. #define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
  123. /* Take a pointer to a raw data buffer and a length and extract device
  124. id information from it. The first byte of data must point to the
  125. byte from the get device id response after the completion code.
  126. The caller is responsible for making sure the length is at least
  127. 11 and the command completed without error. */
  128. static inline void ipmi_demangle_device_id(unsigned char *data,
  129. unsigned int data_len,
  130. struct ipmi_device_id *id)
  131. {
  132. id->device_id = data[0];
  133. id->device_revision = data[1];
  134. id->firmware_revision_1 = data[2];
  135. id->firmware_revision_2 = data[3];
  136. id->ipmi_version = data[4];
  137. id->additional_device_support = data[5];
  138. id->manufacturer_id = data[6] | (data[7] << 8) | (data[8] << 16);
  139. id->product_id = data[9] | (data[10] << 8);
  140. if (data_len >= 15) {
  141. memcpy(id->aux_firmware_revision, data+11, 4);
  142. id->aux_firmware_revision_set = 1;
  143. } else
  144. id->aux_firmware_revision_set = 0;
  145. }
  146. /* Add a low-level interface to the IPMI driver. Note that if the
  147. interface doesn't know its slave address, it should pass in zero.
  148. The low-level interface should not deliver any messages to the
  149. upper layer until the start_processing() function in the handlers
  150. is called, and the lower layer must get the interface from that
  151. call. */
  152. int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
  153. void *send_info,
  154. struct ipmi_device_id *device_id,
  155. struct device *dev,
  156. unsigned char slave_addr);
  157. /*
  158. * Remove a low-level interface from the IPMI driver. This will
  159. * return an error if the interface is still in use by a user.
  160. */
  161. int ipmi_unregister_smi(ipmi_smi_t intf);
  162. /*
  163. * The lower layer reports received messages through this interface.
  164. * The data_size should be zero if this is an asyncronous message. If
  165. * the lower layer gets an error sending a message, it should format
  166. * an error response in the message response.
  167. */
  168. void ipmi_smi_msg_received(ipmi_smi_t intf,
  169. struct ipmi_smi_msg *msg);
  170. /* The lower layer received a watchdog pre-timeout on interface. */
  171. void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
  172. struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
  173. static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
  174. {
  175. msg->done(msg);
  176. }
  177. /* Allow the lower layer to add things to the proc filesystem
  178. directory for this interface. Note that the entry will
  179. automatically be dstroyed when the interface is destroyed. */
  180. int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
  181. read_proc_t *read_proc, write_proc_t *write_proc,
  182. void *data, struct module *owner);
  183. #endif /* __LINUX_IPMI_SMI_H */