ipmi.h 11 KB

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