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 */ 32 33 #ifndef _IPMIVARS_H_ 34 #define _IPMIVARS_H_ 35 36 #include <sys/types.h> 37 #include <sys/queue.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 struct ipmi_device; 44 struct ipmi_request; 45 46 struct ipmi_request { 47 TAILQ_ENTRY(ipmi_request) ir_link; 48 struct ipmi_device *ir_owner; /* Driver uses NULL. */ 49 uchar_t *ir_request; /* Request is data to send to BMC. */ 50 size_t ir_requestlen; 51 uchar_t *ir_reply; /* Reply is data read from BMC. */ 52 size_t ir_replybuflen; /* Length of ir_reply[] buffer. */ 53 int ir_replylen; /* Length of reply from BMC. */ 54 int ir_error; 55 long ir_msgid; 56 uint8_t ir_addr; 57 uint8_t ir_command; 58 uint8_t ir_compcode; 59 int ir_sz; /* size of request */ 60 }; 61 62 #define MAX_RES 3 63 #define KCS_DATA 0 64 #define KCS_CTL_STS 1 65 #define SMIC_DATA 0 66 #define SMIC_CTL_STS 1 67 #define SMIC_FLAGS 2 68 69 /* Per file descriptor data. */ 70 typedef struct ipmi_device { 71 TAILQ_HEAD(, ipmi_request) ipmi_completed_requests; 72 pollhead_t *ipmi_pollhead; 73 int ipmi_requests; 74 uchar_t ipmi_address; /* IPMB address. */ 75 uchar_t ipmi_lun; 76 dev_t ipmi_dev; 77 list_node_t ipmi_node; /* list link for open devs */ 78 } ipmi_device_t; 79 80 struct ipmi_softc { 81 int ipmi_io_rid; 82 int ipmi_io_type; 83 uint64_t ipmi_io_address; 84 int ipmi_io_mode; 85 int ipmi_io_spacing; 86 int ipmi_io_irq; 87 void *ipmi_irq; 88 int ipmi_detaching; 89 TAILQ_HEAD(, ipmi_request) ipmi_pending_requests; 90 kmutex_t ipmi_lock; 91 kcondvar_t ipmi_request_added; 92 taskq_t *ipmi_kthread; 93 int (*ipmi_startup)(struct ipmi_softc *); 94 int (*ipmi_enqueue_request)(struct ipmi_softc *, 95 struct ipmi_request *); 96 }; 97 98 #define KCS_MODE 0x01 99 #define SMIC_MODE 0x02 100 #define BT_MODE 0x03 101 #define SSIF_MODE 0x04 102 103 /* KCS status flags */ 104 #define KCS_STATUS_OBF 0x01 /* Data Out ready from BMC */ 105 #define KCS_STATUS_IBF 0x02 /* Data In from System */ 106 #define KCS_STATUS_SMS_ATN 0x04 /* Ready in RX queue */ 107 #define KCS_STATUS_C_D 0x08 /* Command/Data register write */ 108 #define KCS_STATUS_OEM1 0x10 109 #define KCS_STATUS_OEM2 0x20 110 #define KCS_STATUS_S0 0x40 111 #define KCS_STATUS_S1 0x80 112 #define KCS_STATUS_STATE(x) ((x)>>6) 113 #define KCS_STATUS_STATE_IDLE 0x0 114 #define KCS_STATUS_STATE_READ 0x1 115 #define KCS_STATUS_STATE_WRITE 0x2 116 #define KCS_STATUS_STATE_ERROR 0x3 117 #define KCS_IFACE_STATUS_OK 0x00 118 #define KCS_IFACE_STATUS_ABORT 0x01 119 #define KCS_IFACE_STATUS_ILLEGAL 0x02 120 #define KCS_IFACE_STATUS_LENGTH_ERR 0x06 121 #define KCS_IFACE_STATUS_UNKNOWN_ERR 0xff 122 123 /* KCS control codes */ 124 #define KCS_CONTROL_GET_STATUS_ABORT 0x60 125 #define KCS_CONTROL_WRITE_START 0x61 126 #define KCS_CONTROL_WRITE_END 0x62 127 #define KCS_DATA_IN_READ 0x68 128 129 /* SMIC status flags */ 130 #define SMIC_STATUS_BUSY 0x01 /* System set and BMC clears it */ 131 #define SMIC_STATUS_SMS_ATN 0x04 /* BMC has a message */ 132 #define SMIC_STATUS_EVT_ATN 0x08 /* Event has been RX */ 133 #define SMIC_STATUS_SMI 0x10 /* asserted SMI */ 134 #define SMIC_STATUS_TX_RDY 0x40 /* Ready to accept WRITE */ 135 #define SMIC_STATUS_RX_RDY 0x80 /* Ready to read */ 136 #define SMIC_STATUS_RESERVED 0x22 137 138 /* SMIC control codes */ 139 #define SMIC_CC_SMS_GET_STATUS 0x40 140 #define SMIC_CC_SMS_WR_START 0x41 141 #define SMIC_CC_SMS_WR_NEXT 0x42 142 #define SMIC_CC_SMS_WR_END 0x43 143 #define SMIC_CC_SMS_RD_START 0x44 144 #define SMIC_CC_SMS_RD_NEXT 0x45 145 #define SMIC_CC_SMS_RD_END 0x46 146 147 /* SMIC status codes */ 148 #define SMIC_SC_SMS_RDY 0xc0 149 #define SMIC_SC_SMS_WR_START 0xc1 150 #define SMIC_SC_SMS_WR_NEXT 0xc2 151 #define SMIC_SC_SMS_WR_END 0xc3 152 #define SMIC_SC_SMS_RD_START 0xc4 153 #define SMIC_SC_SMS_RD_NEXT 0xc5 154 #define SMIC_SC_SMS_RD_END 0xc6 155 156 #define IPMI_ADDR(netfn, lun) ((netfn) << 2 | (lun)) 157 #define IPMI_REPLY_ADDR(addr) ((addr) + 0x4) 158 159 #define IPMI_LOCK(sc) mutex_enter(&(sc)->ipmi_lock) 160 #define IPMI_UNLOCK(sc) mutex_exit(&(sc)->ipmi_lock) 161 #define IPMI_LOCK_ASSERT(sc) ASSERT(MUTEX_HELD(&(sc)->ipmi_lock)) 162 163 #define ipmi_alloc_driver_request(addr, cmd, reqlen, replylen) \ 164 ipmi_alloc_request(NULL, 0, (addr), (cmd), (reqlen), (replylen)) 165 166 #define INB(sc, x) \ 167 inb((sc)->ipmi_io_address + ((sc)->ipmi_io_spacing * (x))) 168 #define OUTB(sc, x, value) \ 169 outb((sc)->ipmi_io_address + ((sc)->ipmi_io_spacing * (x)), value) 170 171 #define MAX_TIMEOUT (3 * hz) 172 173 /* Manage requests. */ 174 void ipmi_complete_request(struct ipmi_softc *, struct ipmi_request *); 175 struct ipmi_request *ipmi_dequeue_request(struct ipmi_softc *); 176 int ipmi_polled_enqueue_request(struct ipmi_softc *, struct ipmi_request *); 177 struct ipmi_request *ipmi_alloc_request(struct ipmi_device *, long msgid, 178 uint8_t, uint8_t, size_t, size_t); 179 void ipmi_free_request(struct ipmi_request *); 180 181 /* Interface attach routines. */ 182 void ipmi_startup(struct ipmi_softc *sc); 183 int ipmi_kcs_attach(struct ipmi_softc *); 184 185 #ifdef __cplusplus 186 } 187 #endif 188 189 #endif /* _IPMIVARS_H_ */ 190