ipmi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * ipmi.h
  3. *
  4. * MontaVista IPMI 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_H
  34. #define __LINUX_IPMI_H
  35. #include <uapi/linux/ipmi.h>
  36. #include <linux/list.h>
  37. #include <linux/proc_fs.h>
  38. struct module;
  39. struct device;
  40. /* Opaque type for a IPMI message user. One of these is needed to
  41. send and receive messages. */
  42. typedef struct ipmi_user *ipmi_user_t;
  43. /*
  44. * Stuff coming from the receive interface comes as one of these.
  45. * They are allocated, the receiver must free them with
  46. * ipmi_free_recv_msg() when done with the message. The link is not
  47. * used after the message is delivered, so the upper layer may use the
  48. * link to build a linked list, if it likes.
  49. */
  50. struct ipmi_recv_msg {
  51. struct list_head link;
  52. /* The type of message as defined in the "Receive Types"
  53. defines above. */
  54. int recv_type;
  55. ipmi_user_t user;
  56. struct ipmi_addr addr;
  57. long msgid;
  58. struct kernel_ipmi_msg msg;
  59. /* The user_msg_data is the data supplied when a message was
  60. sent, if this is a response to a sent message. If this is
  61. not a response to a sent message, then user_msg_data will
  62. be NULL. If the user above is NULL, then this will be the
  63. intf. */
  64. void *user_msg_data;
  65. /* Call this when done with the message. It will presumably free
  66. the message and do any other necessary cleanup. */
  67. void (*done)(struct ipmi_recv_msg *msg);
  68. /* Place-holder for the data, don't make any assumptions about
  69. the size or existence of this, since it may change. */
  70. unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
  71. };
  72. /* Allocate and free the receive message. */
  73. void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
  74. struct ipmi_user_hndl {
  75. /* Routine type to call when a message needs to be routed to
  76. the upper layer. This will be called with some locks held,
  77. the only IPMI routines that can be called are ipmi_request
  78. and the alloc/free operations. The handler_data is the
  79. variable supplied when the receive handler was registered. */
  80. void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
  81. void *user_msg_data);
  82. /* Called when the interface detects a watchdog pre-timeout. If
  83. this is NULL, it will be ignored for the user. */
  84. void (*ipmi_watchdog_pretimeout)(void *handler_data);
  85. };
  86. /* Create a new user of the IPMI layer on the given interface number. */
  87. int ipmi_create_user(unsigned int if_num,
  88. struct ipmi_user_hndl *handler,
  89. void *handler_data,
  90. ipmi_user_t *user);
  91. /* Destroy the given user of the IPMI layer. Note that after this
  92. function returns, the system is guaranteed to not call any
  93. callbacks for the user. Thus as long as you destroy all the users
  94. before you unload a module, you will be safe. And if you destroy
  95. the users before you destroy the callback structures, it should be
  96. safe, too. */
  97. int ipmi_destroy_user(ipmi_user_t user);
  98. /* Get the IPMI version of the BMC we are talking to. */
  99. void ipmi_get_version(ipmi_user_t user,
  100. unsigned char *major,
  101. unsigned char *minor);
  102. /* Set and get the slave address and LUN that we will use for our
  103. source messages. Note that this affects the interface, not just
  104. this user, so it will affect all users of this interface. This is
  105. so some initialization code can come in and do the OEM-specific
  106. things it takes to determine your address (if not the BMC) and set
  107. it for everyone else. Note that each channel can have its own address. */
  108. int ipmi_set_my_address(ipmi_user_t user,
  109. unsigned int channel,
  110. unsigned char address);
  111. int ipmi_get_my_address(ipmi_user_t user,
  112. unsigned int channel,
  113. unsigned char *address);
  114. int ipmi_set_my_LUN(ipmi_user_t user,
  115. unsigned int channel,
  116. unsigned char LUN);
  117. int ipmi_get_my_LUN(ipmi_user_t user,
  118. unsigned int channel,
  119. unsigned char *LUN);
  120. /*
  121. * Like ipmi_request, but lets you specify the number of retries and
  122. * the retry time. The retries is the number of times the message
  123. * will be resent if no reply is received. If set to -1, the default
  124. * value will be used. The retry time is the time in milliseconds
  125. * between retries. If set to zero, the default value will be
  126. * used.
  127. *
  128. * Don't use this unless you *really* have to. It's primarily for the
  129. * IPMI over LAN converter; since the LAN stuff does its own retries,
  130. * it makes no sense to do it here. However, this can be used if you
  131. * have unusual requirements.
  132. */
  133. int ipmi_request_settime(ipmi_user_t user,
  134. struct ipmi_addr *addr,
  135. long msgid,
  136. struct kernel_ipmi_msg *msg,
  137. void *user_msg_data,
  138. int priority,
  139. int max_retries,
  140. unsigned int retry_time_ms);
  141. /*
  142. * Like ipmi_request, but with messages supplied. This will not
  143. * allocate any memory, and the messages may be statically allocated
  144. * (just make sure to do the "done" handling on them). Note that this
  145. * is primarily for the watchdog timer, since it should be able to
  146. * send messages even if no memory is available. This is subject to
  147. * change as the system changes, so don't use it unless you REALLY
  148. * have to.
  149. */
  150. int ipmi_request_supply_msgs(ipmi_user_t user,
  151. struct ipmi_addr *addr,
  152. long msgid,
  153. struct kernel_ipmi_msg *msg,
  154. void *user_msg_data,
  155. void *supplied_smi,
  156. struct ipmi_recv_msg *supplied_recv,
  157. int priority);
  158. /*
  159. * Poll the IPMI interface for the user. This causes the IPMI code to
  160. * do an immediate check for information from the driver and handle
  161. * anything that is immediately pending. This will not block in any
  162. * way. This is useful if you need to spin waiting for something to
  163. * happen in the IPMI driver.
  164. */
  165. void ipmi_poll_interface(ipmi_user_t user);
  166. /*
  167. * When commands come in to the SMS, the user can register to receive
  168. * them. Only one user can be listening on a specific netfn/cmd/chan tuple
  169. * at a time, you will get an EBUSY error if the command is already
  170. * registered. If a command is received that does not have a user
  171. * registered, the driver will automatically return the proper
  172. * error. Channels are specified as a bitfield, use IPMI_CHAN_ALL to
  173. * mean all channels.
  174. */
  175. int ipmi_register_for_cmd(ipmi_user_t user,
  176. unsigned char netfn,
  177. unsigned char cmd,
  178. unsigned int chans);
  179. int ipmi_unregister_for_cmd(ipmi_user_t user,
  180. unsigned char netfn,
  181. unsigned char cmd,
  182. unsigned int chans);
  183. /*
  184. * Go into a mode where the driver will not autonomously attempt to do
  185. * things with the interface. It will still respond to attentions and
  186. * interrupts, and it will expect that commands will complete. It
  187. * will not automatcially check for flags, events, or things of that
  188. * nature.
  189. *
  190. * This is primarily used for firmware upgrades. The idea is that
  191. * when you go into firmware upgrade mode, you do this operation
  192. * and the driver will not attempt to do anything but what you tell
  193. * it or what the BMC asks for.
  194. *
  195. * Note that if you send a command that resets the BMC, the driver
  196. * will still expect a response from that command. So the BMC should
  197. * reset itself *after* the response is sent. Resetting before the
  198. * response is just silly.
  199. *
  200. * If in auto maintenance mode, the driver will automatically go into
  201. * maintenance mode for 30 seconds if it sees a cold reset, a warm
  202. * reset, or a firmware NetFN. This means that code that uses only
  203. * firmware NetFN commands to do upgrades will work automatically
  204. * without change, assuming it sends a message every 30 seconds or
  205. * less.
  206. *
  207. * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
  208. */
  209. int ipmi_get_maintenance_mode(ipmi_user_t user);
  210. int ipmi_set_maintenance_mode(ipmi_user_t user, int mode);
  211. /*
  212. * When the user is created, it will not receive IPMI events by
  213. * default. The user must set this to TRUE to get incoming events.
  214. * The first user that sets this to TRUE will receive all events that
  215. * have been queued while no one was waiting for events.
  216. */
  217. int ipmi_set_gets_events(ipmi_user_t user, bool val);
  218. /*
  219. * Called when a new SMI is registered. This will also be called on
  220. * every existing interface when a new watcher is registered with
  221. * ipmi_smi_watcher_register().
  222. */
  223. struct ipmi_smi_watcher {
  224. struct list_head link;
  225. /* You must set the owner to the current module, if you are in
  226. a module (generally just set it to "THIS_MODULE"). */
  227. struct module *owner;
  228. /* These two are called with read locks held for the interface
  229. the watcher list. So you can add and remove users from the
  230. IPMI interface, send messages, etc., but you cannot add
  231. or remove SMI watchers or SMI interfaces. */
  232. void (*new_smi)(int if_num, struct device *dev);
  233. void (*smi_gone)(int if_num);
  234. };
  235. int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
  236. int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
  237. /* The following are various helper functions for dealing with IPMI
  238. addresses. */
  239. /* Return the maximum length of an IPMI address given it's type. */
  240. unsigned int ipmi_addr_length(int addr_type);
  241. /* Validate that the given IPMI address is valid. */
  242. int ipmi_validate_addr(struct ipmi_addr *addr, int len);
  243. /*
  244. * How did the IPMI driver find out about the device?
  245. */
  246. enum ipmi_addr_src {
  247. SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
  248. SI_PCI, SI_DEVICETREE, SI_DEFAULT
  249. };
  250. union ipmi_smi_info_union {
  251. /*
  252. * the acpi_info element is defined for the SI_ACPI
  253. * address type
  254. */
  255. struct {
  256. void *acpi_handle;
  257. } acpi_info;
  258. };
  259. struct ipmi_smi_info {
  260. enum ipmi_addr_src addr_src;
  261. /*
  262. * Base device for the interface. Don't forget to put this when
  263. * you are done.
  264. */
  265. struct device *dev;
  266. /*
  267. * The addr_info provides more detailed info for some IPMI
  268. * devices, depending on the addr_src. Currently only SI_ACPI
  269. * info is provided.
  270. */
  271. union ipmi_smi_info_union addr_info;
  272. };
  273. /* This is to get the private info of ipmi_smi_t */
  274. extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
  275. #endif /* __LINUX_IPMI_H */