ipmi_smi.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 <[email protected]>
  9. * [email protected]
  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. * SMI messages
  36. *
  37. * When communicating with an SMI, messages come in two formats:
  38. *
  39. * * Normal (to a BMC over a BMC interface)
  40. *
  41. * * IPMB (over a IPMB to another MC)
  42. *
  43. * When normal, commands are sent using the format defined by a
  44. * standard message over KCS (NetFn must be even):
  45. *
  46. * +-----------+-----+------+
  47. * | NetFn/LUN | Cmd | Data |
  48. * +-----------+-----+------+
  49. *
  50. * And responses, similarly, with an completion code added (NetFn must
  51. * be odd):
  52. *
  53. * +-----------+-----+------+------+
  54. * | NetFn/LUN | Cmd | CC | Data |
  55. * +-----------+-----+------+------+
  56. *
  57. * With normal messages, only commands are sent and only responses are
  58. * received.
  59. *
  60. * In IPMB mode, we are acting as an IPMB device. Commands will be in
  61. * the following format (NetFn must be even):
  62. *
  63. * +-------------+------+-------------+-----+------+
  64. * | NetFn/rsLUN | Addr | rqSeq/rqLUN | Cmd | Data |
  65. * +-------------+------+-------------+-----+------+
  66. *
  67. * Responses will using the following format:
  68. *
  69. * +-------------+------+-------------+-----+------+------+
  70. * | NetFn/rqLUN | Addr | rqSeq/rsLUN | Cmd | CC | Data |
  71. * +-------------+------+-------------+-----+------+------+
  72. *
  73. * This is similar to the format defined in the IPMB manual section
  74. * 2.11.1 with the checksums and the first address removed. Also, the
  75. * address is always the remote address.
  76. *
  77. * IPMB messages can be commands and responses in both directions.
  78. * Received commands are handled as received commands from the message
  79. * queue.
  80. */
  81. enum ipmi_smi_msg_type {
  82. IPMI_SMI_MSG_TYPE_NORMAL = 0,
  83. IPMI_SMI_MSG_TYPE_IPMB_DIRECT
  84. };
  85. /*
  86. * Messages to/from the lower layer. The smi interface will take one
  87. * of these to send. After the send has occurred and a response has
  88. * been received, it will report this same data structure back up to
  89. * the upper layer. If an error occurs, it should fill in the
  90. * response with an error code in the completion code location. When
  91. * asynchronous data is received, one of these is allocated, the
  92. * data_size is set to zero and the response holds the data from the
  93. * get message or get event command that the interface initiated.
  94. * Note that it is the interfaces responsibility to detect
  95. * asynchronous data and messages and request them from the
  96. * interface.
  97. */
  98. struct ipmi_smi_msg {
  99. struct list_head link;
  100. enum ipmi_smi_msg_type type;
  101. long msgid;
  102. void *user_data;
  103. int data_size;
  104. unsigned char data[IPMI_MAX_MSG_LENGTH];
  105. int rsp_size;
  106. unsigned char rsp[IPMI_MAX_MSG_LENGTH];
  107. /*
  108. * Will be called when the system is done with the message
  109. * (presumably to free it).
  110. */
  111. void (*done)(struct ipmi_smi_msg *msg);
  112. };
  113. #define INIT_IPMI_SMI_MSG(done_handler) \
  114. { \
  115. .done = done_handler, \
  116. .type = IPMI_SMI_MSG_TYPE_NORMAL \
  117. }
  118. struct ipmi_smi_handlers {
  119. struct module *owner;
  120. /* Capabilities of the SMI. */
  121. #define IPMI_SMI_CAN_HANDLE_IPMB_DIRECT (1 << 0)
  122. unsigned int flags;
  123. /*
  124. * The low-level interface cannot start sending messages to
  125. * the upper layer until this function is called. This may
  126. * not be NULL, the lower layer must take the interface from
  127. * this call.
  128. */
  129. int (*start_processing)(void *send_info,
  130. struct ipmi_smi *new_intf);
  131. /*
  132. * When called, the low-level interface should disable all
  133. * processing, it should be complete shut down when it returns.
  134. */
  135. void (*shutdown)(void *send_info);
  136. /*
  137. * Get the detailed private info of the low level interface and store
  138. * it into the structure of ipmi_smi_data. For example: the
  139. * ACPI device handle will be returned for the pnp_acpi IPMI device.
  140. */
  141. int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
  142. /*
  143. * Called to enqueue an SMI message to be sent. This
  144. * operation is not allowed to fail. If an error occurs, it
  145. * should report back the error in a received message. It may
  146. * do this in the current call context, since no write locks
  147. * are held when this is run. Message are delivered one at
  148. * a time by the message handler, a new message will not be
  149. * delivered until the previous message is returned.
  150. */
  151. void (*sender)(void *send_info,
  152. struct ipmi_smi_msg *msg);
  153. /*
  154. * Called by the upper layer to request that we try to get
  155. * events from the BMC we are attached to.
  156. */
  157. void (*request_events)(void *send_info);
  158. /*
  159. * Called by the upper layer when some user requires that the
  160. * interface watch for received messages and watchdog
  161. * pretimeouts (basically do a "Get Flags", or not. Used by
  162. * the SMI to know if it should watch for these. This may be
  163. * NULL if the SMI does not implement it. watch_mask is from
  164. * IPMI_WATCH_MASK_xxx above. The interface should run slower
  165. * timeouts for just watchdog checking or faster timeouts when
  166. * waiting for the message queue.
  167. */
  168. void (*set_need_watch)(void *send_info, unsigned int watch_mask);
  169. /*
  170. * Called when flushing all pending messages.
  171. */
  172. void (*flush_messages)(void *send_info);
  173. /*
  174. * Called when the interface should go into "run to
  175. * completion" mode. If this call sets the value to true, the
  176. * interface should make sure that all messages are flushed
  177. * out and that none are pending, and any new requests are run
  178. * to completion immediately.
  179. */
  180. void (*set_run_to_completion)(void *send_info, bool run_to_completion);
  181. /*
  182. * Called to poll for work to do. This is so upper layers can
  183. * poll for operations during things like crash dumps.
  184. */
  185. void (*poll)(void *send_info);
  186. /*
  187. * Enable/disable firmware maintenance mode. Note that this
  188. * is *not* the modes defined, this is simply an on/off
  189. * setting. The message handler does the mode handling. Note
  190. * that this is called from interrupt context, so it cannot
  191. * block.
  192. */
  193. void (*set_maintenance_mode)(void *send_info, bool enable);
  194. };
  195. struct ipmi_device_id {
  196. unsigned char device_id;
  197. unsigned char device_revision;
  198. unsigned char firmware_revision_1;
  199. unsigned char firmware_revision_2;
  200. unsigned char ipmi_version;
  201. unsigned char additional_device_support;
  202. unsigned int manufacturer_id;
  203. unsigned int product_id;
  204. unsigned char aux_firmware_revision[4];
  205. unsigned int aux_firmware_revision_set : 1;
  206. };
  207. #define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
  208. #define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
  209. /*
  210. * Take a pointer to an IPMI response and extract device id information from
  211. * it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from
  212. * a SI response.
  213. */
  214. static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
  215. const unsigned char *data,
  216. unsigned int data_len,
  217. struct ipmi_device_id *id)
  218. {
  219. if (data_len < 7)
  220. return -EINVAL;
  221. if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD)
  222. /* Strange, didn't get the response we expected. */
  223. return -EINVAL;
  224. if (data[0] != 0)
  225. /* That's odd, it shouldn't be able to fail. */
  226. return -EINVAL;
  227. data++;
  228. data_len--;
  229. id->device_id = data[0];
  230. id->device_revision = data[1];
  231. id->firmware_revision_1 = data[2];
  232. id->firmware_revision_2 = data[3];
  233. id->ipmi_version = data[4];
  234. id->additional_device_support = data[5];
  235. if (data_len >= 11) {
  236. id->manufacturer_id = (data[6] | (data[7] << 8) |
  237. (data[8] << 16));
  238. id->product_id = data[9] | (data[10] << 8);
  239. } else {
  240. id->manufacturer_id = 0;
  241. id->product_id = 0;
  242. }
  243. if (data_len >= 15) {
  244. memcpy(id->aux_firmware_revision, data+11, 4);
  245. id->aux_firmware_revision_set = 1;
  246. } else
  247. id->aux_firmware_revision_set = 0;
  248. return 0;
  249. }
  250. /*
  251. * Add a low-level interface to the IPMI driver. Note that if the
  252. * interface doesn't know its slave address, it should pass in zero.
  253. * The low-level interface should not deliver any messages to the
  254. * upper layer until the start_processing() function in the handlers
  255. * is called, and the lower layer must get the interface from that
  256. * call.
  257. */
  258. int ipmi_add_smi(struct module *owner,
  259. const struct ipmi_smi_handlers *handlers,
  260. void *send_info,
  261. struct device *dev,
  262. unsigned char slave_addr);
  263. #define ipmi_register_smi(handlers, send_info, dev, slave_addr) \
  264. ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr)
  265. /*
  266. * Remove a low-level interface from the IPMI driver. This will
  267. * return an error if the interface is still in use by a user.
  268. */
  269. void ipmi_unregister_smi(struct ipmi_smi *intf);
  270. /*
  271. * The lower layer reports received messages through this interface.
  272. * The data_size should be zero if this is an asynchronous message. If
  273. * the lower layer gets an error sending a message, it should format
  274. * an error response in the message response.
  275. */
  276. void ipmi_smi_msg_received(struct ipmi_smi *intf,
  277. struct ipmi_smi_msg *msg);
  278. /* The lower layer received a watchdog pre-timeout on interface. */
  279. void ipmi_smi_watchdog_pretimeout(struct ipmi_smi *intf);
  280. struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
  281. static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
  282. {
  283. msg->done(msg);
  284. }
  285. #endif /* __LINUX_IPMI_SMI_H */