xref: /openbmc/ipmitool/src/plugins/bmc/bmc_intf.h (revision c18ec02f3304ce2a889a50e378f07a4168af3884)
1  /*
2   * Copyright (c) 2004 Sun Microsystems, Inc.  All Rights Reserved.
3   *
4   * Redistribution and use in source and binary forms, with or without
5   * modification, are permitted provided that the following conditions
6   * are met:
7   *
8   * Redistribution of source code must retain the above copyright
9   * notice, this list of conditions and the following disclaimer.
10   *
11   * Redistribution in binary form must reproduce the above copyright
12   * notice, this list of conditions and the following disclaimer in the
13   * documentation and/or other materials provided with the distribution.
14   *
15   * Neither the name of Sun Microsystems, Inc. or the names of
16   * contributors may be used to endorse or promote products derived
17   * from this software without specific prior written permission.
18   *
19   * This software is provided "AS IS," without a warranty of any kind.
20   * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21   * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22   * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
23   * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
24   * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
25   * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL
26   * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
27   * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
28   * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
29   * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30   * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31   */
32  
33  #ifndef _BMC_INTF_H
34  #define	_BMC_INTF_H
35  
36  #pragma ident	"@(#)bmc_intf.h	1.2	05/03/07 SMI"
37  
38  #ifdef __cplusplus
39  extern "C" {
40  #endif
41  
42  #define	BMC_SUCCESS		0x0
43  #define	BMC_FAILURE		0x1
44  
45  #define	BMC_NETFN_CHASSIS		0x0
46  #define	BMC_NETFN_BRIDGE		0x2
47  #define	BMC_NETFN_SE			0x4
48  #define	BMC_NETFN_APP			0x6
49  #define	BMC_NETFN_FIRMWARE		0x8
50  #define	BMC_NETFN_STORAGE		0xa
51  #define	BMC_NETFN_TRANSPORT		0xc
52  
53  #define	SEND_MAX_PAYLOAD_SIZE		34	/* MAX payload */
54  #define	RECV_MAX_PAYLOAD_SIZE		33	/* MAX payload */
55  #define	BMC_MIN_RESPONSE_SIZE		3
56  #define	BMC_MIN_REQUEST_SIZE		2
57  #define	BMC_MAX_RESPONSE_SIZE   (BMC_MIN_RESPONSE_SIZE + RECV_MAX_PAYLOAD_SIZE)
58  #define	BMC_MAX_REQUEST_SIZE	(BMC_MIN_REQUEST_SIZE + BMC_MAX_RESPONSE_SIZE)
59  
60  #define	BUF_SIZE 256
61  #define	MAX_BUF_SIZE			256
62  
63  /*
64   * Useful macros
65   */
66  #define	FORM_NETFNLUN(net, lun)	((((net) << 2) | ((lun) & 0x3)))
67  #define	GET_NETFN(netfn)	(((netfn) >> 2) & 0x3f)
68  #define	GET_LUN(netfn)		(netfn & 0x3)
69  #define	RESP_NETFN(nflun)	((nflun) | 1)
70  #define	ISREQUEST(nl)		(((nl) & 1) == 0)	/* test for request */
71  #define	ISRESPONSE(nl)		(((nl) & 1) == 1)	/* test for response */
72  
73  
74  /* for checking BMC specific stuff */
75  #define	BMC_GET_DEVICE_ID		0x1	/* GET DEVICE ID COMMAND */
76  #define	BMC_IPMI_15_VER		0x51	/* IPMI 1.5 definion */
77  
78  /* BMC Completion Code and OEM Completion Code */
79  #define	BMC_IPMI_UNSPECIFIC_ERROR	0xFF	/* Unspecific Error */
80  #define	BMC_IPMI_INVALID_COMMAND	0xC1	/* Invalid Command */
81  #define	BMC_IPMI_COMMAND_TIMEOUT	0xC3	/* Command Timeout */
82  #define	BMC_IPMI_DATA_LENGTH_EXCEED	0xC8	/* DataLength exceeded limit */
83  #define	BMC_IPMI_OEM_FAILURE_SENDBMC	0x7E	/* Cannot send BMC req */
84  
85  
86  #define	IOCTL_IPMI_KCS_ACTION		0x01
87  #define	IOCTL_IPMI_INTERFACE_METHOD	0x02
88  
89  /* Interface methods returned from IOCTL_IPMI_INTERFACE_METHOD ioctl: */
90  
91  #define	BMC_IOCTL_METHOD		0	/* Not returned from ioctl, */
92  						/* but can be used by	*/
93  						/* applications that want to */
94  						/* compare against an	*/
95  						/* alternative method.	*/
96  #define	BMC_PUTMSG_METHOD		1
97  
98  /*
99   * bmc_req_t is the data structure to send
100   * request packet from applications to the driver
101   * module.
102   *
103   * the request pkt is mainly for KCS-interface-BMC
104   * messages. Since the system interface is session-less
105   * connections, the packet won't have any session
106   * information.
107   *
108   * the data payload will be 2 bytes less than max
109   * BMC supported packet size.
110   * the address of the responder is always BMC and so
111   * rsSa field is not required.
112   */
113  typedef struct bmc_req {
114  	uint8_t fn;			/* netFn for command */
115  	uint8_t lun;			/* logical unit on responder */
116  	uint8_t cmd;			/* command */
117  	uint8_t datalength;		/* length of following data */
118  	uint8_t data[SEND_MAX_PAYLOAD_SIZE]; /* request data */
119  } bmc_req_t;
120  
121  /*
122   * bmc_rsp_t is the data structure to send
123   * respond packet from applications to the driver
124   * module.
125   *
126   * the respond pkt is mainly for KCS-interface-BMC
127   * messages. Since the system interface is session-less
128   * connections, the packet won't have any session
129   * information.
130   *
131   * the data payload will be 2 bytes less than max
132   * BMC supported packet size.
133   */
134  typedef struct bmc_rsp {
135  	uint8_t	fn;			/* netFn for command */
136  	uint8_t	lun;			/* logical unit on responder */
137  	uint8_t	cmd;			/* command */
138  	uint8_t	ccode;			/* completion code */
139  	uint8_t	datalength;		/* Length */
140  	uint8_t	data[RECV_MAX_PAYLOAD_SIZE]; /* response */
141  } bmc_rsp_t;
142  
143  /*
144   * the data structure for synchronous operation via ioctl (DEPRECATED)
145   */
146  typedef struct bmc_reqrsp {
147  	bmc_req_t	req;			/* request half */
148  	bmc_rsp_t	rsp;			/* response half */
149  } bmc_reqrsp_t;
150  
151  
152  /*
153   * The new way of communicating with the bmc driver is to use putmsg() to
154   * send a message of a particular type.  Replies from the driver also have this
155   * form, and will require the user to process the type field before examining
156   * the rest of the reply.
157   *
158   * The only change that must be observed when using the request and response
159   * structures defined above is as follows:
160   * when sending messages to the bmc driver, the data portion is now variable
161   * (the caller must allocate enough space to store the all structure members,
162   * plus enough space to cover the amount of data in the request), e.g.:
163   *
164   * bmc_msg_t *msg = malloc(offsetof(bmc_msg_t, msg) + sizeof(bmc_req_t) + 10);
165   *
166   * The amount allocated for the message is (# of bytes before the msg field) +
167   * the size of a bmc_req_t (which includes SEND_MAX_PAYLOAD_SIZE
168   * bytes in the data field), plus an additional 10 bytes for the data
169   * field (so the data field would occupy (SEND_MAX_PAYLOAD_SIZE + 10)
170   * bytes).  The datalength member must reflect the amount of data in the
171   * request's data field (as was required when using the ioctl interface).
172   */
173  typedef struct bmc_msg {
174  	uint8_t		m_type;		/* Message type (see below) */
175  	uint32_t	m_id;		/* Message ID */
176  	uint8_t		reserved[32];
177  	uint8_t		msg[1];		/* Variable length message data */
178  } bmc_msg_t;
179  
180  
181  /*
182   * An error response passed back from the bmc driver will have its m_id
183   * field set to BMC_UNKNOWN_MSG_ID if a message is sent to it that is not
184   * at least as large as a bmc_msg_t.
185   */
186  #define	BMC_UNKNOWN_MSG_ID	~((uint32_t)0)
187  
188  
189  /*
190   * Possible values for the m_type field in bmc_msg_t:
191   */
192  #define	BMC_MSG_REQUEST		1	/* BMC request (as above, sent to the */
193  					/* driver by the user), bmc_msg.msg */
194  					/* begins with the bmc_req_t	*/
195  					/* structure.			*/
196  #define	BMC_MSG_RESPONSE	2	/* BMC response (sent by the driver) */
197  					/* bmc_msg.msg begins with the	*/
198  					/* bmc_rsp_t structure.		*/
199  #define	BMC_MSG_ERROR		3	/* Error while processing a user msg */
200  					/* msg[0] is the error code	*/
201  					/* (interpret as an errno value) */
202  
203  #ifdef	__cplusplus
204  }
205  #endif
206  
207  #endif /* _BMC_INTF_H */
208