1 /* 2 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: src/sys/dev/ipmi/ipmivars.h,v 1.3 2008/08/28 02:13:53 jhb Exp $ 27 */ 28 29 /* 30 * Copyright 2012, Joyent, Inc. All rights reserved. 31 * Copyright 2013, Nexenta Systems, Inc. All rights reserved. 32 */ 33 34 #ifndef _IPMIVARS_H_ 35 #define _IPMIVARS_H_ 36 37 #include <sys/types.h> 38 #include <sys/queue.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 struct ipmi_device; 45 struct ipmi_request; 46 47 struct ipmi_request { 48 TAILQ_ENTRY(ipmi_request) ir_link; 49 struct ipmi_device *ir_owner; /* Driver uses NULL. */ 50 uchar_t *ir_request; /* Request is data to send to BMC. */ 51 size_t ir_requestlen; 52 uchar_t *ir_reply; /* Reply is data read from BMC. */ 53 size_t ir_replybuflen; /* Length of ir_reply[] buffer. */ 54 int ir_replylen; /* Length of reply from BMC. */ 55 int ir_error; 56 long ir_msgid; 57 uint8_t ir_addr; 58 uint8_t ir_command; 59 uint8_t ir_compcode; 60 int ir_sz; /* size of request */ 61 }; 62 63 #define MAX_RES 3 64 #define KCS_DATA 0 65 #define KCS_CTL_STS 1 66 #define SMIC_DATA 0 67 #define SMIC_CTL_STS 1 68 #define SMIC_FLAGS 2 69 70 /* Per file descriptor data. */ 71 typedef struct ipmi_device { 72 TAILQ_HEAD(, ipmi_request) ipmi_completed_requests; 73 pollhead_t *ipmi_pollhead; 74 int ipmi_requests; 75 uchar_t ipmi_address; /* IPMB address. */ 76 uchar_t ipmi_lun; 77 dev_t ipmi_dev; 78 list_node_t ipmi_node; /* list link for open devs */ 79 } ipmi_device_t; 80 81 struct ipmi_softc { 82 int ipmi_io_rid; 83 int ipmi_io_type; 84 uint64_t ipmi_io_address; 85 int ipmi_io_mode; 86 int ipmi_io_spacing; 87 int ipmi_io_irq; 88 void *ipmi_irq; 89 int ipmi_detaching; 90 TAILQ_HEAD(, ipmi_request) ipmi_pending_requests; 91 kmutex_t ipmi_lock; 92 kcondvar_t ipmi_request_added; 93 taskq_t *ipmi_kthread; 94 int (*ipmi_startup)(struct ipmi_softc *); 95 int (*ipmi_enqueue_request)(struct ipmi_softc *, 96 struct ipmi_request *); 97 }; 98 99 #define KCS_MODE 0x01 100 #define SMIC_MODE 0x02 101 #define BT_MODE 0x03 102 #define SSIF_MODE 0x04 103 104 /* KCS status flags */ 105 #define KCS_STATUS_OBF 0x01 /* Data Out ready from BMC */ 106 #define KCS_STATUS_IBF 0x02 /* Data In from System */ 107 #define KCS_STATUS_SMS_ATN 0x04 /* Ready in RX queue */ 108 #define KCS_STATUS_C_D 0x08 /* Command/Data register write */ 109 #define KCS_STATUS_OEM1 0x10 110 #define KCS_STATUS_OEM2 0x20 111 #define KCS_STATUS_S0 0x40 112 #define KCS_STATUS_S1 0x80 113 #define KCS_STATUS_STATE(x) ((x)>>6) 114 #define KCS_STATUS_STATE_IDLE 0x0 115 #define KCS_STATUS_STATE_READ 0x1 116 #define KCS_STATUS_STATE_WRITE 0x2 117 #define KCS_STATUS_STATE_ERROR 0x3 118 #define KCS_IFACE_STATUS_OK 0x00 119 #define KCS_IFACE_STATUS_ABORT 0x01 120 #define KCS_IFACE_STATUS_ILLEGAL 0x02 121 #define KCS_IFACE_STATUS_LENGTH_ERR 0x06 122 #define KCS_IFACE_STATUS_UNKNOWN_ERR 0xff 123 124 /* KCS control codes */ 125 #define KCS_CONTROL_GET_STATUS_ABORT 0x60 126 #define KCS_CONTROL_WRITE_START 0x61 127 #define KCS_CONTROL_WRITE_END 0x62 128 #define KCS_DATA_IN_READ 0x68 129 130 /* SMIC status flags */ 131 #define SMIC_STATUS_BUSY 0x01 /* System set and BMC clears it */ 132 #define SMIC_STATUS_SMS_ATN 0x04 /* BMC has a message */ 133 #define SMIC_STATUS_EVT_ATN 0x08 /* Event has been RX */ 134 #define SMIC_STATUS_SMI 0x10 /* asserted SMI */ 135 #define SMIC_STATUS_TX_RDY 0x40 /* Ready to accept WRITE */ 136 #define SMIC_STATUS_RX_RDY 0x80 /* Ready to read */ 137 #define SMIC_STATUS_RESERVED 0x22 138 139 /* SMIC control codes */ 140 #define SMIC_CC_SMS_GET_STATUS 0x40 141 #define SMIC_CC_SMS_WR_START 0x41 142 #define SMIC_CC_SMS_WR_NEXT 0x42 143 #define SMIC_CC_SMS_WR_END 0x43 144 #define SMIC_CC_SMS_RD_START 0x44 145 #define SMIC_CC_SMS_RD_NEXT 0x45 146 #define SMIC_CC_SMS_RD_END 0x46 147 148 /* SMIC status codes */ 149 #define SMIC_SC_SMS_RDY 0xc0 150 #define SMIC_SC_SMS_WR_START 0xc1 151 #define SMIC_SC_SMS_WR_NEXT 0xc2 152 #define SMIC_SC_SMS_WR_END 0xc3 153 #define SMIC_SC_SMS_RD_START 0xc4 154 #define SMIC_SC_SMS_RD_NEXT 0xc5 155 #define SMIC_SC_SMS_RD_END 0xc6 156 157 #define IPMI_ADDR(netfn, lun) ((netfn) << 2 | (lun)) 158 #define IPMI_REPLY_ADDR(addr) ((addr) + 0x4) 159 160 #define IPMI_LOCK(sc) mutex_enter(&(sc)->ipmi_lock) 161 #define IPMI_UNLOCK(sc) mutex_exit(&(sc)->ipmi_lock) 162 #define IPMI_LOCK_ASSERT(sc) ASSERT(MUTEX_HELD(&(sc)->ipmi_lock)) 163 164 #define ipmi_alloc_driver_request(addr, cmd, reqlen, replylen) \ 165 ipmi_alloc_request(NULL, 0, (addr), (cmd), (reqlen), (replylen)) 166 167 #define INB(sc, x) \ 168 inb((sc)->ipmi_io_address + ((sc)->ipmi_io_spacing * (x))) 169 #define OUTB(sc, x, value) \ 170 outb((sc)->ipmi_io_address + ((sc)->ipmi_io_spacing * (x)), value) 171 172 #define MAX_TIMEOUT (3 * hz) 173 174 /* Manage requests. */ 175 void ipmi_complete_request(struct ipmi_softc *, struct ipmi_request *); 176 struct ipmi_request *ipmi_dequeue_request(struct ipmi_softc *); 177 int ipmi_polled_enqueue_request(struct ipmi_softc *, struct ipmi_request *); 178 struct ipmi_request *ipmi_alloc_request(struct ipmi_device *, long msgid, 179 uint8_t, uint8_t, size_t, size_t); 180 void ipmi_free_request(struct ipmi_request *); 181 182 /* Interface attach routines. */ 183 boolean_t ipmi_startup(struct ipmi_softc *sc); 184 int ipmi_kcs_attach(struct ipmi_softc *); 185 186 /* Interface detach cleanup */ 187 void ipmi_shutdown(struct ipmi_softc *sc); 188 189 #ifdef __cplusplus 190 } 191 #endif 192 193 #endif /* _IPMIVARS_H_ */ 194