ipmi_smi.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * ipmi_smi.h
  4. *
  5. * MontaVista IPMI system management interface
  6. *
  7. * Author: MontaVista Software, Inc.
  8. * Corey Minyard <minyard@mvista.com>
  9. * source@mvista.com
  10. *
  11. * Copyright 2002 MontaVista Software Inc.
  12. *
  13. */
  14. #ifndef __LINUX_IPMI_SMI_H
  15. #define __LINUX_IPMI_SMI_H
  16. #include <linux/ipmi_msgdefs.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/ipmi.h>
  20. struct device;
  21. /*
  22. * This files describes the interface for IPMI system management interface
  23. * drivers to bind into the IPMI message handler.
  24. */
  25. /* Structure for the low-level drivers. */
  26. struct ipmi_smi;
  27. /*
  28. * Flags for set_check_watch() below. Tells if the SMI should be
  29. * waiting for watchdog timeouts, commands and/or messages.
  30. */
  31. #define IPMI_WATCH_MASK_CHECK_MESSAGES (1 << 0)
  32. #define IPMI_WATCH_MASK_CHECK_WATCHDOG (1 << 1)
  33. #define IPMI_WATCH_MASK_CHECK_COMMANDS (1 << 2)
  34. /*
  35. * Messages to/from the lower layer. The smi interface will take one
  36. * of these to send. After the send has occurred and a response has
  37. * been received, it will report this same data structure back up to
  38. * the upper layer. If an error occurs, it should fill in the
  39. * response with an error code in the completion code location. When
  40. * asynchronous data is received, one of these is allocated, the
  41. * data_size is set to zero and the response holds the data from the
  42. * get message or get event command that the interface initiated.
  43. * Note that it is the interfaces responsibility to detect
  44. * asynchronous data and messages and request them from the
  45. * interface.
  46. */
  47. struct ipmi_smi_msg {
  48. struct list_head link;
  49. long msgid;
  50. void *user_data;
  51. int data_size;
  52. unsigned char data[IPMI_MAX_MSG_LENGTH];
  53. int rsp_size;
  54. unsigned char rsp[IPMI_MAX_MSG_LENGTH];
  55. /*
  56. * Will be called when the system is done with the message
  57. * (presumably to free it).
  58. */
  59. void (*done)(struct ipmi_smi_msg *msg);
  60. };
  61. struct ipmi_smi_handlers {
  62. struct module *owner;
  63. /*
  64. * The low-level interface cannot start sending messages to
  65. * the upper layer until this function is called. This may
  66. * not be NULL, the lower layer must take the interface from
  67. * this call.
  68. */
  69. int (*start_processing)(void *send_info,
  70. struct ipmi_smi *new_intf);
  71. /*
  72. * When called, the low-level interface should disable all
  73. * processing, it should be complete shut down when it returns.
  74. */
  75. void (*shutdown)(void *send_info);
  76. /*
  77. * Get the detailed private info of the low level interface and store
  78. * it into the structure of ipmi_smi_data. For example: the
  79. * ACPI device handle will be returned for the pnp_acpi IPMI device.
  80. */
  81. int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
  82. /*
  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. */
  91. void (*sender)(void *send_info,
  92. struct ipmi_smi_msg *msg);
  93. /*
  94. * Called by the upper layer to request that we try to get
  95. * events from the BMC we are attached to.
  96. */
  97. void (*request_events)(void *send_info);
  98. /*
  99. * Called by the upper layer when some user requires that the
  100. * interface watch for received messages and watchdog
  101. * pretimeouts (basically do a "Get Flags", or not. Used by
  102. * the SMI to know if it should watch for these. This may be
  103. * NULL if the SMI does not implement it. watch_mask is from
  104. * IPMI_WATCH_MASK_xxx above. The interface should run slower
  105. * timeouts for just watchdog checking or faster timeouts when
  106. * waiting for the message queue.
  107. */
  108. void (*set_need_watch)(void *send_info, unsigned int watch_mask);
  109. /*
  110. * Called when flushing all pending messages.
  111. */
  112. void (*flush_messages)(void *send_info);
  113. /*
  114. * Called when the interface should go into "run to
  115. * completion" mode. If this call sets the value to true, the
  116. * interface should make sure that all messages are flushed
  117. * out and that none are pending, and any new requests are run
  118. * to completion immediately.
  119. */
  120. void (*set_run_to_completion)(void *send_info, bool run_to_completion);
  121. /*
  122. * Called to poll for work to do. This is so upper layers can
  123. * poll for operations during things like crash dumps.
  124. */
  125. void (*poll)(void *send_info);
  126. /*
  127. * Enable/disable firmware maintenance mode. Note that this
  128. * is *not* the modes defined, this is simply an on/off
  129. * setting. The message handler does the mode handling. Note
  130. * that this is called from interrupt context, so it cannot
  131. * block.
  132. */
  133. void (*set_maintenance_mode)(void *send_info, bool enable);
  134. };
  135. struct ipmi_device_id {
  136. unsigned char device_id;
  137. unsigned char device_revision;
  138. unsigned char firmware_revision_1;
  139. unsigned char firmware_revision_2;
  140. unsigned char ipmi_version;
  141. unsigned char additional_device_support;
  142. unsigned int manufacturer_id;
  143. unsigned int product_id;
  144. unsigned char aux_firmware_revision[4];
  145. unsigned int aux_firmware_revision_set : 1;
  146. };
  147. #define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
  148. #define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
  149. /*
  150. * Take a pointer to an IPMI response and extract device id information from
  151. * it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from
  152. * a SI response.
  153. */
  154. static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
  155. const unsigned char *data,
  156. unsigned int data_len,
  157. struct ipmi_device_id *id)
  158. {
  159. if (data_len < 7)
  160. return -EINVAL;
  161. if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD)
  162. /* Strange, didn't get the response we expected. */
  163. return -EINVAL;
  164. if (data[0] != 0)
  165. /* That's odd, it shouldn't be able to fail. */
  166. return -EINVAL;
  167. data++;
  168. data_len--;
  169. id->device_id = data[0];
  170. id->device_revision = data[1];
  171. id->firmware_revision_1 = data[2];
  172. id->firmware_revision_2 = data[3];
  173. id->ipmi_version = data[4];
  174. id->additional_device_support = data[5];
  175. if (data_len >= 11) {
  176. id->manufacturer_id = (data[6] | (data[7] << 8) |
  177. (data[8] << 16));
  178. id->product_id = data[9] | (data[10] << 8);
  179. } else {
  180. id->manufacturer_id = 0;
  181. id->product_id = 0;
  182. }
  183. if (data_len >= 15) {
  184. memcpy(id->aux_firmware_revision, data+11, 4);
  185. id->aux_firmware_revision_set = 1;
  186. } else
  187. id->aux_firmware_revision_set = 0;
  188. return 0;
  189. }
  190. /*
  191. * Add a low-level interface to the IPMI driver. Note that if the
  192. * interface doesn't know its slave address, it should pass in zero.
  193. * The low-level interface should not deliver any messages to the
  194. * upper layer until the start_processing() function in the handlers
  195. * is called, and the lower layer must get the interface from that
  196. * call.
  197. */
  198. int ipmi_add_smi(struct module *owner,
  199. const struct ipmi_smi_handlers *handlers,
  200. void *send_info,
  201. struct device *dev,
  202. unsigned char slave_addr);
  203. #define ipmi_register_smi(handlers, send_info, dev, slave_addr) \
  204. ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr)
  205. /*
  206. * Remove a low-level interface from the IPMI driver. This will
  207. * return an error if the interface is still in use by a user.
  208. */
  209. void ipmi_unregister_smi(struct ipmi_smi *intf);
  210. /*
  211. * The lower layer reports received messages through this interface.
  212. * The data_size should be zero if this is an asynchronous message. If
  213. * the lower layer gets an error sending a message, it should format
  214. * an error response in the message response.
  215. */
  216. void ipmi_smi_msg_received(struct ipmi_smi *intf,
  217. struct ipmi_smi_msg *msg);
  218. /* The lower layer received a watchdog pre-timeout on interface. */
  219. void ipmi_smi_watchdog_pretimeout(struct ipmi_smi *intf);
  220. struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
  221. static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
  222. {
  223. msg->done(msg);
  224. }
  225. #endif /* __LINUX_IPMI_SMI_H */