ipmi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  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 _UAPI__LINUX_IPMI_H
  15. #define _UAPI__LINUX_IPMI_H
  16. #include <linux/ipmi_msgdefs.h>
  17. #include <linux/compiler.h>
  18. /*
  19. * This file describes an interface to an IPMI driver. You have to
  20. * have a fairly good understanding of IPMI to use this, so go read
  21. * the specs first before actually trying to do anything.
  22. *
  23. * With that said, this driver provides a multi-user interface to the
  24. * IPMI driver, and it allows multiple IPMI physical interfaces below
  25. * the driver. The physical interfaces bind as a lower layer on the
  26. * driver. They appear as interfaces to the application using this
  27. * interface.
  28. *
  29. * Multi-user means that multiple applications may use the driver,
  30. * send commands, receive responses, etc. The driver keeps track of
  31. * commands the user sends and tracks the responses. The responses
  32. * will go back to the application that send the command. If the
  33. * response doesn't come back in time, the driver will return a
  34. * timeout error response to the application. Asynchronous events
  35. * from the BMC event queue will go to all users bound to the driver.
  36. * The incoming event queue in the BMC will automatically be flushed
  37. * if it becomes full and it is queried once a second to see if
  38. * anything is in it. Incoming commands to the driver will get
  39. * delivered as commands.
  40. */
  41. /*
  42. * This is an overlay for all the address types, so it's easy to
  43. * determine the actual address type. This is kind of like addresses
  44. * work for sockets.
  45. */
  46. #define IPMI_MAX_ADDR_SIZE 32
  47. struct ipmi_addr {
  48. /* Try to take these from the "Channel Medium Type" table
  49. in section 6.5 of the IPMI 1.5 manual. */
  50. int addr_type;
  51. short channel;
  52. char data[IPMI_MAX_ADDR_SIZE];
  53. };
  54. /*
  55. * When the address is not used, the type will be set to this value.
  56. * The channel is the BMC's channel number for the channel (usually
  57. * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC.
  58. */
  59. #define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c
  60. struct ipmi_system_interface_addr {
  61. int addr_type;
  62. short channel;
  63. unsigned char lun;
  64. };
  65. /* An IPMB Address. */
  66. #define IPMI_IPMB_ADDR_TYPE 0x01
  67. /* Used for broadcast get device id as described in section 17.9 of the
  68. IPMI 1.5 manual. */
  69. #define IPMI_IPMB_BROADCAST_ADDR_TYPE 0x41
  70. struct ipmi_ipmb_addr {
  71. int addr_type;
  72. short channel;
  73. unsigned char slave_addr;
  74. unsigned char lun;
  75. };
  76. /*
  77. * Used for messages received directly from an IPMB that have not gone
  78. * through a MC. This is for systems that sit right on an IPMB so
  79. * they can receive commands and respond to them.
  80. */
  81. #define IPMI_IPMB_DIRECT_ADDR_TYPE 0x81
  82. struct ipmi_ipmb_direct_addr {
  83. int addr_type;
  84. short channel;
  85. unsigned char slave_addr;
  86. unsigned char rs_lun;
  87. unsigned char rq_lun;
  88. };
  89. /*
  90. * A LAN Address. This is an address to/from a LAN interface bridged
  91. * by the BMC, not an address actually out on the LAN.
  92. *
  93. * A conscious decision was made here to deviate slightly from the IPMI
  94. * spec. We do not use rqSWID and rsSWID like it shows in the
  95. * message. Instead, we use remote_SWID and local_SWID. This means
  96. * that any message (a request or response) from another device will
  97. * always have exactly the same address. If you didn't do this,
  98. * requests and responses from the same device would have different
  99. * addresses, and that's not too cool.
  100. *
  101. * In this address, the remote_SWID is always the SWID the remote
  102. * message came from, or the SWID we are sending the message to.
  103. * local_SWID is always our SWID. Note that having our SWID in the
  104. * message is a little weird, but this is required.
  105. */
  106. #define IPMI_LAN_ADDR_TYPE 0x04
  107. struct ipmi_lan_addr {
  108. int addr_type;
  109. short channel;
  110. unsigned char privilege;
  111. unsigned char session_handle;
  112. unsigned char remote_SWID;
  113. unsigned char local_SWID;
  114. unsigned char lun;
  115. };
  116. /*
  117. * Channel for talking directly with the BMC. When using this
  118. * channel, This is for the system interface address type only. FIXME
  119. * - is this right, or should we use -1?
  120. */
  121. #define IPMI_BMC_CHANNEL 0xf
  122. #define IPMI_NUM_CHANNELS 0x10
  123. /*
  124. * Used to signify an "all channel" bitmask. This is more than the
  125. * actual number of channels because this is used in userland and
  126. * will cover us if the number of channels is extended.
  127. */
  128. #define IPMI_CHAN_ALL (~0)
  129. /*
  130. * A raw IPMI message without any addressing. This covers both
  131. * commands and responses. The completion code is always the first
  132. * byte of data in the response (as the spec shows the messages laid
  133. * out).
  134. */
  135. struct ipmi_msg {
  136. unsigned char netfn;
  137. unsigned char cmd;
  138. unsigned short data_len;
  139. unsigned char __user *data;
  140. };
  141. struct kernel_ipmi_msg {
  142. unsigned char netfn;
  143. unsigned char cmd;
  144. unsigned short data_len;
  145. unsigned char *data;
  146. };
  147. /*
  148. * Various defines that are useful for IPMI applications.
  149. */
  150. #define IPMI_INVALID_CMD_COMPLETION_CODE 0xC1
  151. #define IPMI_TIMEOUT_COMPLETION_CODE 0xC3
  152. #define IPMI_UNKNOWN_ERR_COMPLETION_CODE 0xff
  153. /*
  154. * Receive types for messages coming from the receive interface. This
  155. * is used for the receive in-kernel interface and in the receive
  156. * IOCTL.
  157. *
  158. * The "IPMI_RESPONSE_RESPONSE_TYPE" is a little strange sounding, but
  159. * it allows you to get the message results when you send a response
  160. * message.
  161. */
  162. #define IPMI_RESPONSE_RECV_TYPE 1 /* A response to a command */
  163. #define IPMI_ASYNC_EVENT_RECV_TYPE 2 /* Something from the event queue */
  164. #define IPMI_CMD_RECV_TYPE 3 /* A command from somewhere else */
  165. #define IPMI_RESPONSE_RESPONSE_TYPE 4 /* The response for
  166. a sent response, giving any
  167. error status for sending the
  168. response. When you send a
  169. response message, this will
  170. be returned. */
  171. #define IPMI_OEM_RECV_TYPE 5 /* The response for OEM Channels */
  172. /* Note that async events and received commands do not have a completion
  173. code as the first byte of the incoming data, unlike a response. */
  174. /*
  175. * Modes for ipmi_set_maint_mode() and the userland IOCTL. The AUTO
  176. * setting is the default and means it will be set on certain
  177. * commands. Hard setting it on and off will override automatic
  178. * operation.
  179. */
  180. #define IPMI_MAINTENANCE_MODE_AUTO 0
  181. #define IPMI_MAINTENANCE_MODE_OFF 1
  182. #define IPMI_MAINTENANCE_MODE_ON 2
  183. /*
  184. * The userland interface
  185. */
  186. /*
  187. * The userland interface for the IPMI driver is a standard character
  188. * device, with each instance of an interface registered as a minor
  189. * number under the major character device.
  190. *
  191. * The read and write calls do not work, to get messages in and out
  192. * requires ioctl calls because of the complexity of the data. select
  193. * and poll do work, so you can wait for input using the file
  194. * descriptor, you just can use read to get it.
  195. *
  196. * In general, you send a command down to the interface and receive
  197. * responses back. You can use the msgid value to correlate commands
  198. * and responses, the driver will take care of figuring out which
  199. * incoming messages are for which command and find the proper msgid
  200. * value to report. You will only receive reponses for commands you
  201. * send. Asynchronous events, however, go to all open users, so you
  202. * must be ready to handle these (or ignore them if you don't care).
  203. *
  204. * The address type depends upon the channel type. When talking
  205. * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored
  206. * (IPMI_UNUSED_ADDR_TYPE). When talking to an IPMB channel, you must
  207. * supply a valid IPMB address with the addr_type set properly.
  208. *
  209. * When talking to normal channels, the driver takes care of the
  210. * details of formatting and sending messages on that channel. You do
  211. * not, for instance, have to format a send command, you just send
  212. * whatever command you want to the channel, the driver will create
  213. * the send command, automatically issue receive command and get even
  214. * commands, and pass those up to the proper user.
  215. */
  216. /* The magic IOCTL value for this interface. */
  217. #define IPMI_IOC_MAGIC 'i'
  218. /* Messages sent to the interface are this format. */
  219. struct ipmi_req {
  220. unsigned char __user *addr; /* Address to send the message to. */
  221. unsigned int addr_len;
  222. long msgid; /* The sequence number for the message. This
  223. exact value will be reported back in the
  224. response to this request if it is a command.
  225. If it is a response, this will be used as
  226. the sequence value for the response. */
  227. struct ipmi_msg msg;
  228. };
  229. /*
  230. * Send a message to the interfaces. error values are:
  231. * - EFAULT - an address supplied was invalid.
  232. * - EINVAL - The address supplied was not valid, or the command
  233. * was not allowed.
  234. * - EMSGSIZE - The message to was too large.
  235. * - ENOMEM - Buffers could not be allocated for the command.
  236. */
  237. #define IPMICTL_SEND_COMMAND _IOR(IPMI_IOC_MAGIC, 13, \
  238. struct ipmi_req)
  239. /* Messages sent to the interface with timing parameters are this
  240. format. */
  241. struct ipmi_req_settime {
  242. struct ipmi_req req;
  243. /* See ipmi_request_settime() above for details on these
  244. values. */
  245. int retries;
  246. unsigned int retry_time_ms;
  247. };
  248. /*
  249. * Send a message to the interfaces with timing parameters. error values
  250. * are:
  251. * - EFAULT - an address supplied was invalid.
  252. * - EINVAL - The address supplied was not valid, or the command
  253. * was not allowed.
  254. * - EMSGSIZE - The message to was too large.
  255. * - ENOMEM - Buffers could not be allocated for the command.
  256. */
  257. #define IPMICTL_SEND_COMMAND_SETTIME _IOR(IPMI_IOC_MAGIC, 21, \
  258. struct ipmi_req_settime)
  259. /* Messages received from the interface are this format. */
  260. struct ipmi_recv {
  261. int recv_type; /* Is this a command, response or an
  262. asyncronous event. */
  263. unsigned char __user *addr; /* Address the message was from is put
  264. here. The caller must supply the
  265. memory. */
  266. unsigned int addr_len; /* The size of the address buffer.
  267. The caller supplies the full buffer
  268. length, this value is updated to
  269. the actual message length when the
  270. message is received. */
  271. long msgid; /* The sequence number specified in the request
  272. if this is a response. If this is a command,
  273. this will be the sequence number from the
  274. command. */
  275. struct ipmi_msg msg; /* The data field must point to a buffer.
  276. The data_size field must be set to the
  277. size of the message buffer. The
  278. caller supplies the full buffer
  279. length, this value is updated to the
  280. actual message length when the message
  281. is received. */
  282. };
  283. /*
  284. * Receive a message. error values:
  285. * - EAGAIN - no messages in the queue.
  286. * - EFAULT - an address supplied was invalid.
  287. * - EINVAL - The address supplied was not valid.
  288. * - EMSGSIZE - The message to was too large to fit into the message buffer,
  289. * the message will be left in the buffer. */
  290. #define IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, \
  291. struct ipmi_recv)
  292. /*
  293. * Like RECEIVE_MSG, but if the message won't fit in the buffer, it
  294. * will truncate the contents instead of leaving the data in the
  295. * buffer.
  296. */
  297. #define IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, \
  298. struct ipmi_recv)
  299. /* Register to get commands from other entities on this interface. */
  300. struct ipmi_cmdspec {
  301. unsigned char netfn;
  302. unsigned char cmd;
  303. };
  304. /*
  305. * Register to receive a specific command. error values:
  306. * - EFAULT - an address supplied was invalid.
  307. * - EBUSY - The netfn/cmd supplied was already in use.
  308. * - ENOMEM - could not allocate memory for the entry.
  309. */
  310. #define IPMICTL_REGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 14, \
  311. struct ipmi_cmdspec)
  312. /*
  313. * Unregister a registered command. error values:
  314. * - EFAULT - an address supplied was invalid.
  315. * - ENOENT - The netfn/cmd was not found registered for this user.
  316. */
  317. #define IPMICTL_UNREGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 15, \
  318. struct ipmi_cmdspec)
  319. /*
  320. * Register to get commands from other entities on specific channels.
  321. * This way, you can only listen on specific channels, or have messages
  322. * from some channels go to one place and other channels to someplace
  323. * else. The chans field is a bitmask, (1 << channel) for each channel.
  324. * It may be IPMI_CHAN_ALL for all channels.
  325. */
  326. struct ipmi_cmdspec_chans {
  327. unsigned int netfn;
  328. unsigned int cmd;
  329. unsigned int chans;
  330. };
  331. /*
  332. * Register to receive a specific command on specific channels. error values:
  333. * - EFAULT - an address supplied was invalid.
  334. * - EBUSY - One of the netfn/cmd/chans supplied was already in use.
  335. * - ENOMEM - could not allocate memory for the entry.
  336. */
  337. #define IPMICTL_REGISTER_FOR_CMD_CHANS _IOR(IPMI_IOC_MAGIC, 28, \
  338. struct ipmi_cmdspec_chans)
  339. /*
  340. * Unregister some netfn/cmd/chans. error values:
  341. * - EFAULT - an address supplied was invalid.
  342. * - ENOENT - None of the netfn/cmd/chans were found registered for this user.
  343. */
  344. #define IPMICTL_UNREGISTER_FOR_CMD_CHANS _IOR(IPMI_IOC_MAGIC, 29, \
  345. struct ipmi_cmdspec_chans)
  346. /*
  347. * Set whether this interface receives events. Note that the first
  348. * user registered for events will get all pending events for the
  349. * interface. error values:
  350. * - EFAULT - an address supplied was invalid.
  351. */
  352. #define IPMICTL_SET_GETS_EVENTS_CMD _IOR(IPMI_IOC_MAGIC, 16, int)
  353. /*
  354. * Set and get the slave address and LUN that we will use for our
  355. * source messages. Note that this affects the interface, not just
  356. * this user, so it will affect all users of this interface. This is
  357. * so some initialization code can come in and do the OEM-specific
  358. * things it takes to determine your address (if not the BMC) and set
  359. * it for everyone else. You should probably leave the LUN alone.
  360. */
  361. struct ipmi_channel_lun_address_set {
  362. unsigned short channel;
  363. unsigned char value;
  364. };
  365. #define IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD \
  366. _IOR(IPMI_IOC_MAGIC, 24, struct ipmi_channel_lun_address_set)
  367. #define IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD \
  368. _IOR(IPMI_IOC_MAGIC, 25, struct ipmi_channel_lun_address_set)
  369. #define IPMICTL_SET_MY_CHANNEL_LUN_CMD \
  370. _IOR(IPMI_IOC_MAGIC, 26, struct ipmi_channel_lun_address_set)
  371. #define IPMICTL_GET_MY_CHANNEL_LUN_CMD \
  372. _IOR(IPMI_IOC_MAGIC, 27, struct ipmi_channel_lun_address_set)
  373. /* Legacy interfaces, these only set IPMB 0. */
  374. #define IPMICTL_SET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 17, unsigned int)
  375. #define IPMICTL_GET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 18, unsigned int)
  376. #define IPMICTL_SET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 19, unsigned int)
  377. #define IPMICTL_GET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 20, unsigned int)
  378. /*
  379. * Get/set the default timing values for an interface. You shouldn't
  380. * generally mess with these.
  381. */
  382. struct ipmi_timing_parms {
  383. int retries;
  384. unsigned int retry_time_ms;
  385. };
  386. #define IPMICTL_SET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 22, \
  387. struct ipmi_timing_parms)
  388. #define IPMICTL_GET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 23, \
  389. struct ipmi_timing_parms)
  390. /*
  391. * Set the maintenance mode. See ipmi_set_maintenance_mode() above
  392. * for a description of what this does.
  393. */
  394. #define IPMICTL_GET_MAINTENANCE_MODE_CMD _IOR(IPMI_IOC_MAGIC, 30, int)
  395. #define IPMICTL_SET_MAINTENANCE_MODE_CMD _IOW(IPMI_IOC_MAGIC, 31, int)
  396. #endif /* _UAPI__LINUX_IPMI_H */