ipmi.h 11 KB

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