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