1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _BMC_INTF_H 28 #define _BMC_INTF_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #define BMC_SUCCESS 0x0 37 #define BMC_FAILURE 0x1 38 39 #define BMC_NETFN_CHASSIS 0x0 40 #define BMC_NETFN_BRIDGE 0x2 41 #define BMC_NETFN_SE 0x4 42 #define BMC_NETFN_APP 0x6 43 #define BMC_NETFN_FIRMWARE 0x8 44 #define BMC_NETFN_STORAGE 0xa 45 #define BMC_NETFN_TRANSPORT 0xc 46 47 #define SEND_MAX_PAYLOAD_SIZE 34 /* MAX payload */ 48 #define RECV_MAX_PAYLOAD_SIZE 33 /* MAX payload */ 49 #define BMC_MIN_RESPONSE_SIZE 3 50 #define BMC_MIN_REQUEST_SIZE 2 51 #define BMC_MAX_RESPONSE_SIZE (BMC_MIN_RESPONSE_SIZE + RECV_MAX_PAYLOAD_SIZE) 52 #define BMC_MAX_REQUEST_SIZE (BMC_MIN_REQUEST_SIZE + BMC_MAX_RESPONSE_SIZE) 53 54 #define BUF_SIZE 256 55 #define MAX_BUF_SIZE 256 56 57 /* 58 * Useful macros 59 */ 60 #define FORM_NETFNLUN(net, lun) ((((net) << 2) | ((lun) & 0x3))) 61 #define GET_NETFN(netfn) (((netfn) >> 2) & 0x3f) 62 #define GET_LUN(netfn) (netfn & 0x3) 63 #define RESP_NETFN(nflun) ((nflun) | 1) 64 #define ISREQUEST(nl) (((nl) & 1) == 0) /* test for request */ 65 #define ISRESPONSE(nl) (((nl) & 1) == 1) /* test for response */ 66 67 68 /* for checking BMC specific stuff */ 69 #define BMC_GET_DEVICE_ID 0x1 /* GET DEVICE ID COMMAND */ 70 #define BMC_IPMI_15_VER 0x51 /* IPMI 1.5 definion */ 71 72 /* BMC Completion Code and OEM Completion Code */ 73 #define BMC_IPMI_UNSPECIFIC_ERROR 0xFF /* Unspecific Error */ 74 #define BMC_IPMI_INVALID_COMMAND 0xC1 /* Invalid Command */ 75 #define BMC_IPMI_COMMAND_TIMEOUT 0xC3 /* Command Timeout */ 76 #define BMC_IPMI_DATA_LENGTH_EXCEED 0xC8 /* DataLength exceeded limit */ 77 #define BMC_IPMI_OEM_FAILURE_SENDBMC 0x7E /* Cannot send BMC req */ 78 79 80 #define IOCTL_IPMI_KCS_ACTION 0x01 81 #define IOCTL_IPMI_INTERFACE_METHOD 0x02 82 83 /* Interface methods returned from IOCTL_IPMI_INTERFACE_METHOD ioctl: */ 84 85 #define BMC_IOCTL_METHOD 0 /* Not returned from ioctl, */ 86 /* but can be used by */ 87 /* applications that want to */ 88 /* compare against an */ 89 /* alternative method. */ 90 #define BMC_PUTMSG_METHOD 1 91 92 /* 93 * bmc_req_t is the data structure to send 94 * request packet from applications to the driver 95 * module. 96 * 97 * the request pkt is mainly for KCS-interface-BMC 98 * messages. Since the system interface is session-less 99 * connections, the packet won't have any session 100 * information. 101 * 102 * the data payload will be 2 bytes less than max 103 * BMC supported packet size. 104 * the address of the responder is always BMC and so 105 * rsSa field is not required. 106 */ 107 typedef struct bmc_req { 108 uint8_t fn; /* netFn for command */ 109 uint8_t lun; /* logical unit on responder */ 110 uint8_t cmd; /* command */ 111 uint8_t datalength; /* length of following data */ 112 uint8_t data[SEND_MAX_PAYLOAD_SIZE]; /* request data */ 113 } bmc_req_t; 114 115 /* 116 * bmc_rsp_t is the data structure to send 117 * respond packet from applications to the driver 118 * module. 119 * 120 * the respond pkt is mainly for KCS-interface-BMC 121 * messages. Since the system interface is session-less 122 * connections, the packet won't have any session 123 * information. 124 * 125 * the data payload will be 2 bytes less than max 126 * BMC supported packet size. 127 */ 128 typedef struct bmc_rsp { 129 uint8_t fn; /* netFn for command */ 130 uint8_t lun; /* logical unit on responder */ 131 uint8_t cmd; /* command */ 132 uint8_t ccode; /* completion code */ 133 uint8_t datalength; /* Length */ 134 uint8_t data[RECV_MAX_PAYLOAD_SIZE]; /* response */ 135 } bmc_rsp_t; 136 137 /* 138 * the data structure for synchronous operation via ioctl (DEPRECATED) 139 */ 140 typedef struct bmc_reqrsp { 141 bmc_req_t req; /* request half */ 142 bmc_rsp_t rsp; /* response half */ 143 } bmc_reqrsp_t; 144 145 146 /* 147 * The new way of communicating with the bmc driver is to use putmsg() to 148 * send a message of a particular type. Replies from the driver also have this 149 * form, and will require the user to process the type field before examining 150 * the rest of the reply. 151 * 152 * The only change that must be observed when using the request and response 153 * structures defined above is as follows: 154 * when sending messages to the bmc driver, the data portion is now variable 155 * (the caller must allocate enough space to store the all structure members, 156 * plus enough space to cover the amount of data in the request), e.g.: 157 * 158 * bmc_msg_t *msg = malloc(offsetof(bmc_msg_t, msg) + sizeof(bmc_req_t) + 10); 159 * 160 * The amount allocated for the message is (# of bytes before the msg field) + 161 * the size of a bmc_req_t (which includes SEND_MAX_PAYLOAD_SIZE 162 * bytes in the data field), plus an additional 10 bytes for the data 163 * field (so the data field would occupy (SEND_MAX_PAYLOAD_SIZE + 10) 164 * bytes). The datalength member must reflect the amount of data in the 165 * request's data field (as was required when using the ioctl interface). 166 */ 167 typedef struct bmc_msg { 168 uint8_t m_type; /* Message type (see below) */ 169 uint32_t m_id; /* Message ID */ 170 uint8_t reserved[32]; 171 uint8_t msg[1]; /* Variable length message data */ 172 } bmc_msg_t; 173 174 175 /* 176 * An error response passed back from the bmc driver will have its m_id 177 * field set to BMC_UNKNOWN_MSG_ID if a message is sent to it that is not 178 * at least as large as a bmc_msg_t. 179 */ 180 #define BMC_UNKNOWN_MSG_ID ~((uint32_t)0) 181 182 183 /* 184 * Possible values for the m_type field in bmc_msg_t: 185 */ 186 #define BMC_MSG_REQUEST 1 /* BMC request (as above, sent to the */ 187 /* driver by the user), bmc_msg.msg */ 188 /* begins with the bmc_req_t */ 189 /* structure. */ 190 #define BMC_MSG_RESPONSE 2 /* BMC response (sent by the driver) */ 191 /* bmc_msg.msg begins with the */ 192 /* bmc_rsp_t structure. */ 193 #define BMC_MSG_ERROR 3 /* Error while processing a user msg */ 194 /* msg[0] is the error code */ 195 /* (interpret as an errno value) */ 196 197 #ifdef __cplusplus 198 } 199 #endif 200 201 #endif /* _BMC_INTF_H */ 202