1 /*- 2 * Copyright 2009 Solarflare Communications 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 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 * 25 * $FreeBSD$ 26 */ 27 28 #ifndef _SYS_EFX_MCDI_H 29 #define _SYS_EFX_MCDI_H 30 31 #include "efx.h" 32 #include "efx_regs.h" 33 #include "efx_regs_mcdi.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /* Number of retries attempted for init code */ 40 #define EFX_MCDI_REQ_RETRY_INIT 2 41 42 struct efx_mcdi_req_s { 43 /* Inputs: Command #, input buffer and length */ 44 unsigned int emr_cmd; 45 uint8_t *emr_in_buf; 46 size_t emr_in_length; 47 /* Outputs: retcode, buffer, length, and length used*/ 48 int emr_rc; 49 uint8_t *emr_out_buf; 50 size_t emr_out_length; 51 size_t emr_out_length_used; 52 }; 53 54 typedef struct efx_mcdi_iface_s { 55 const efx_mcdi_transport_t *emi_mtp; 56 unsigned int emi_port; 57 unsigned int emi_seq; 58 efx_mcdi_req_t *emi_pending_req; 59 boolean_t emi_ev_cpl; 60 int emi_aborted; 61 uint32_t emi_poll_cnt; 62 } efx_mcdi_iface_t; 63 64 extern void 65 efx_mcdi_execute( 66 __in efx_nic_t *enp, 67 __in efx_mcdi_req_t *emrp); 68 69 extern void 70 efx_mcdi_ev_cpl( 71 __in efx_nic_t *enp, 72 __in unsigned int seq, 73 __in unsigned int outlen, 74 __in int errcode); 75 76 extern void 77 efx_mcdi_ev_death( 78 __in efx_nic_t *enp, 79 __in int rc); 80 81 typedef enum efx_mcdi_boot_e { 82 EFX_MCDI_BOOT_PRIMARY, 83 EFX_MCDI_BOOT_SECONDARY, 84 EFX_MCDI_BOOT_ROM, 85 } efx_mcdi_boot_t; 86 87 extern __checkReturn int 88 efx_mcdi_version( 89 __in efx_nic_t *enp, 90 __out_ecount_opt(4) uint16_t versionp[4], 91 __out_opt uint32_t *buildp, 92 __out_opt efx_mcdi_boot_t *statusp); 93 94 #define MCDI_IN(_emr, _type, _ofst) \ 95 ((_type *)((_emr).emr_in_buf + (_ofst))) 96 97 #define MCDI_IN2(_emr, _type, _ofst) \ 98 MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST) 99 100 #define MCDI_IN_SET_BYTE(_emr, _ofst, _value) \ 101 EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst), \ 102 EFX_BYTE_0, _value) 103 104 #define MCDI_IN_SET_DWORD(_emr, _ofst, _value) \ 105 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 106 EFX_DWORD_0, _value) 107 108 #define MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1) \ 109 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 110 MC_CMD_ ## _field1, _value1) 111 112 #define MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1, \ 113 _field2, _value2) \ 114 EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 115 MC_CMD_ ## _field1, _value1, \ 116 MC_CMD_ ## _field2, _value2) 117 118 #define MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1, \ 119 _field2, _value2, _field3, _value3) \ 120 EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 121 MC_CMD_ ## _field1, _value1, \ 122 MC_CMD_ ## _field2, _value2, \ 123 MC_CMD_ ## _field3, _value3) 124 125 #define MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1, \ 126 _field2, _value2, _field3, _value3, _field4, _value4) \ 127 EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 128 MC_CMD_ ## _field1, _value1, \ 129 MC_CMD_ ## _field2, _value2, \ 130 MC_CMD_ ## _field3, _value3, \ 131 MC_CMD_ ## _field4, _value4) 132 133 #define MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1, \ 134 _field2, _value2, _field3, _value3, _field4, _value4, \ 135 _field5, _value5) \ 136 EFX_POPULATE_DWORD_5(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 137 MC_CMD_ ## _field1, _value1, \ 138 MC_CMD_ ## _field2, _value2, \ 139 MC_CMD_ ## _field3, _value3, \ 140 MC_CMD_ ## _field4, _value4, \ 141 MC_CMD_ ## _field5, _value5) 142 143 #define MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1, \ 144 _field2, _value2, _field3, _value3, _field4, _value4, \ 145 _field5, _value5, _field6, _value6) \ 146 EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 147 MC_CMD_ ## _field1, _value1, \ 148 MC_CMD_ ## _field2, _value2, \ 149 MC_CMD_ ## _field3, _value3, \ 150 MC_CMD_ ## _field4, _value4, \ 151 MC_CMD_ ## _field5, _value5, \ 152 MC_CMD_ ## _field6, _value6) 153 154 #define MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1, \ 155 _field2, _value2, _field3, _value3, _field4, _value4, \ 156 _field5, _value5, _field6, _value6, _field7, _value7) \ 157 EFX_POPULATE_DWORD_7(MCDI_IN2(_emr, efx_dword_t, _ofst), \ 158 MC_CMD_ ## _field1, _value1, \ 159 MC_CMD_ ## _field2, _value2, \ 160 MC_CMD_ ## _field3, _value3, \ 161 MC_CMD_ ## _field4, _value4, \ 162 MC_CMD_ ## _field5, _value5, \ 163 MC_CMD_ ## _field6, _value6, \ 164 MC_CMD_ ## _field7, _value7) 165 166 #define MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1, \ 167 _field2, _value2, _field3, _value3, _field4, _value4, \ 168 _field5, _value5, _field6, _value6, _field7, _value7, \ 169 _field8, _value8) \ 170 EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 171 MC_CMD_ ## _field1, _value1, \ 172 MC_CMD_ ## _field2, _value2, \ 173 MC_CMD_ ## _field3, _value3, \ 174 MC_CMD_ ## _field4, _value4, \ 175 MC_CMD_ ## _field5, _value5, \ 176 MC_CMD_ ## _field6, _value6, \ 177 MC_CMD_ ## _field7, _value7, \ 178 MC_CMD_ ## _field8, _value8) 179 180 #define MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1, \ 181 _field2, _value2, _field3, _value3, _field4, _value4, \ 182 _field5, _value5, _field6, _value6, _field7, _value7, \ 183 _field8, _value8, _field9, _value9) \ 184 EFX_POPULATE_DWORD_9(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 185 MC_CMD_ ## _field1, _value1, \ 186 MC_CMD_ ## _field2, _value2, \ 187 MC_CMD_ ## _field3, _value3, \ 188 MC_CMD_ ## _field4, _value4, \ 189 MC_CMD_ ## _field5, _value5, \ 190 MC_CMD_ ## _field6, _value6, \ 191 MC_CMD_ ## _field7, _value7, \ 192 MC_CMD_ ## _field8, _value8, \ 193 MC_CMD_ ## _field9, _value9) 194 195 #define MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1, \ 196 _field2, _value2, _field3, _value3, _field4, _value4, \ 197 _field5, _value5, _field6, _value6, _field7, _value7, \ 198 _field8, _value8, _field9, _value9, _field10, _value10) \ 199 EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 200 MC_CMD_ ## _field1, _value1, \ 201 MC_CMD_ ## _field2, _value2, \ 202 MC_CMD_ ## _field3, _value3, \ 203 MC_CMD_ ## _field4, _value4, \ 204 MC_CMD_ ## _field5, _value5, \ 205 MC_CMD_ ## _field6, _value6, \ 206 MC_CMD_ ## _field7, _value7, \ 207 MC_CMD_ ## _field8, _value8, \ 208 MC_CMD_ ## _field9, _value9, \ 209 MC_CMD_ ## _field10, _value10) 210 211 #define MCDI_OUT(_emr, _type, _ofst) \ 212 ((_type *)((_emr).emr_out_buf + (_ofst))) 213 214 #define MCDI_OUT2(_emr, _type, _ofst) \ 215 MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST) 216 217 #define MCDI_OUT_BYTE(_emr, _ofst) \ 218 EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst), \ 219 EFX_BYTE_0) 220 221 #define MCDI_OUT_WORD(_emr, _ofst) \ 222 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \ 223 EFX_WORD_0) 224 225 #define MCDI_OUT_DWORD(_emr, _ofst) \ 226 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \ 227 EFX_DWORD_0) 228 229 #define MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field) \ 230 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \ 231 MC_CMD_ ## _field) 232 233 #define MCDI_EV_FIELD(_eqp, _field) \ 234 EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field) 235 236 #define MCDI_CMD_DWORD_FIELD(_edp, _field) \ 237 EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field) 238 239 #ifdef __cplusplus 240 } 241 #endif 242 243 #endif /* _SYS_EFX_MCDI_H */ 244