1 /*- 2 * Copyright (c) 2009-2016 Solarflare Communications Inc. 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 are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * The views and conclusions contained in the software and documentation are 27 * those of the authors and should not be interpreted as representing official 28 * policies, either expressed or implied, of the FreeBSD Project. 29 * 30 * $FreeBSD$ 31 */ 32 33 #ifndef _SYS_EFX_MCDI_H 34 #define _SYS_EFX_MCDI_H 35 36 #include "efx.h" 37 #include "efx_regs_mcdi.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* 44 * A reboot/assertion causes the MCDI status word to be set after the 45 * command word is set or a REBOOT event is sent. If we notice a reboot 46 * via these mechanisms then wait 10ms for the status word to be set. 47 */ 48 #define EFX_MCDI_STATUS_SLEEP_US 10000 49 50 struct efx_mcdi_req_s { 51 boolean_t emr_quiet; 52 /* Inputs: Command #, input buffer and length */ 53 unsigned int emr_cmd; 54 uint8_t *emr_in_buf; 55 size_t emr_in_length; 56 /* Outputs: retcode, buffer, length, and length used*/ 57 efx_rc_t emr_rc; 58 uint8_t *emr_out_buf; 59 size_t emr_out_length; 60 size_t emr_out_length_used; 61 /* Internals: low level transport details */ 62 unsigned int emr_err_code; 63 unsigned int emr_err_arg; 64 #if EFSYS_OPT_MCDI_PROXY_AUTH 65 uint32_t emr_proxy_handle; 66 #endif 67 }; 68 69 typedef struct efx_mcdi_iface_s { 70 unsigned int emi_port; 71 unsigned int emi_max_version; 72 unsigned int emi_seq; 73 efx_mcdi_req_t *emi_pending_req; 74 boolean_t emi_ev_cpl; 75 boolean_t emi_new_epoch; 76 int emi_aborted; 77 uint32_t emi_poll_cnt; 78 uint32_t emi_mc_reboot_status; 79 } efx_mcdi_iface_t; 80 81 extern void 82 efx_mcdi_execute( 83 __in efx_nic_t *enp, 84 __inout efx_mcdi_req_t *emrp); 85 86 extern void 87 efx_mcdi_execute_quiet( 88 __in efx_nic_t *enp, 89 __inout efx_mcdi_req_t *emrp); 90 91 extern void 92 efx_mcdi_ev_cpl( 93 __in efx_nic_t *enp, 94 __in unsigned int seq, 95 __in unsigned int outlen, 96 __in int errcode); 97 98 #if EFSYS_OPT_MCDI_PROXY_AUTH 99 extern __checkReturn efx_rc_t 100 efx_mcdi_get_proxy_handle( 101 __in efx_nic_t *enp, 102 __in efx_mcdi_req_t *emrp, 103 __out uint32_t *handlep); 104 105 extern void 106 efx_mcdi_ev_proxy_response( 107 __in efx_nic_t *enp, 108 __in unsigned int handle, 109 __in unsigned int status); 110 #endif 111 112 extern void 113 efx_mcdi_ev_death( 114 __in efx_nic_t *enp, 115 __in int rc); 116 117 extern __checkReturn efx_rc_t 118 efx_mcdi_request_errcode( 119 __in unsigned int err); 120 121 extern void 122 efx_mcdi_raise_exception( 123 __in efx_nic_t *enp, 124 __in_opt efx_mcdi_req_t *emrp, 125 __in int rc); 126 127 typedef enum efx_mcdi_boot_e { 128 EFX_MCDI_BOOT_PRIMARY, 129 EFX_MCDI_BOOT_SECONDARY, 130 EFX_MCDI_BOOT_ROM, 131 } efx_mcdi_boot_t; 132 133 extern __checkReturn efx_rc_t 134 efx_mcdi_version( 135 __in efx_nic_t *enp, 136 __out_ecount_opt(4) uint16_t versionp[4], 137 __out_opt uint32_t *buildp, 138 __out_opt efx_mcdi_boot_t *statusp); 139 140 extern __checkReturn efx_rc_t 141 efx_mcdi_read_assertion( 142 __in efx_nic_t *enp); 143 144 extern __checkReturn efx_rc_t 145 efx_mcdi_exit_assertion_handler( 146 __in efx_nic_t *enp); 147 148 extern __checkReturn efx_rc_t 149 efx_mcdi_drv_attach( 150 __in efx_nic_t *enp, 151 __in boolean_t attach); 152 153 extern __checkReturn efx_rc_t 154 efx_mcdi_get_board_cfg( 155 __in efx_nic_t *enp, 156 __out_opt uint32_t *board_typep, 157 __out_opt efx_dword_t *capabilitiesp, 158 __out_ecount_opt(6) uint8_t mac_addrp[6]); 159 160 extern __checkReturn efx_rc_t 161 efx_mcdi_get_phy_cfg( 162 __in efx_nic_t *enp); 163 164 extern __checkReturn efx_rc_t 165 efx_mcdi_firmware_update_supported( 166 __in efx_nic_t *enp, 167 __out boolean_t *supportedp); 168 169 extern __checkReturn efx_rc_t 170 efx_mcdi_macaddr_change_supported( 171 __in efx_nic_t *enp, 172 __out boolean_t *supportedp); 173 174 extern __checkReturn efx_rc_t 175 efx_mcdi_link_control_supported( 176 __in efx_nic_t *enp, 177 __out boolean_t *supportedp); 178 179 extern __checkReturn efx_rc_t 180 efx_mcdi_mac_spoofing_supported( 181 __in efx_nic_t *enp, 182 __out boolean_t *supportedp); 183 184 185 #if EFSYS_OPT_BIST 186 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD 187 extern __checkReturn efx_rc_t 188 efx_mcdi_bist_enable_offline( 189 __in efx_nic_t *enp); 190 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */ 191 extern __checkReturn efx_rc_t 192 efx_mcdi_bist_start( 193 __in efx_nic_t *enp, 194 __in efx_bist_type_t type); 195 #endif /* EFSYS_OPT_BIST */ 196 197 extern __checkReturn efx_rc_t 198 efx_mcdi_get_resource_limits( 199 __in efx_nic_t *enp, 200 __out_opt uint32_t *nevqp, 201 __out_opt uint32_t *nrxqp, 202 __out_opt uint32_t *ntxqp); 203 204 extern __checkReturn efx_rc_t 205 efx_mcdi_log_ctrl( 206 __in efx_nic_t *enp); 207 208 extern __checkReturn efx_rc_t 209 efx_mcdi_mac_stats_clear( 210 __in efx_nic_t *enp); 211 212 extern __checkReturn efx_rc_t 213 efx_mcdi_mac_stats_upload( 214 __in efx_nic_t *enp, 215 __in efsys_mem_t *esmp); 216 217 extern __checkReturn efx_rc_t 218 efx_mcdi_mac_stats_periodic( 219 __in efx_nic_t *enp, 220 __in efsys_mem_t *esmp, 221 __in uint16_t period_ms, 222 __in boolean_t events); 223 224 225 #if EFSYS_OPT_LOOPBACK 226 extern __checkReturn efx_rc_t 227 efx_mcdi_get_loopback_modes( 228 __in efx_nic_t *enp); 229 #endif /* EFSYS_OPT_LOOPBACK */ 230 231 extern __checkReturn efx_rc_t 232 efx_mcdi_phy_module_get_info( 233 __in efx_nic_t *enp, 234 __in uint8_t dev_addr, 235 __in uint8_t offset, 236 __in uint8_t len, 237 __out_bcount(len) uint8_t *data); 238 239 #define MCDI_IN(_emr, _type, _ofst) \ 240 ((_type *)((_emr).emr_in_buf + (_ofst))) 241 242 #define MCDI_IN2(_emr, _type, _ofst) \ 243 MCDI_IN(_emr, _type, MC_CMD_ ## _ofst ## _OFST) 244 245 #define MCDI_IN_SET_BYTE(_emr, _ofst, _value) \ 246 EFX_POPULATE_BYTE_1(*MCDI_IN2(_emr, efx_byte_t, _ofst), \ 247 EFX_BYTE_0, _value) 248 249 #define MCDI_IN_SET_WORD(_emr, _ofst, _value) \ 250 EFX_POPULATE_WORD_1(*MCDI_IN2(_emr, efx_word_t, _ofst), \ 251 EFX_WORD_0, _value) 252 253 #define MCDI_IN_SET_DWORD(_emr, _ofst, _value) \ 254 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 255 EFX_DWORD_0, _value) 256 257 #define MCDI_IN_SET_DWORD_FIELD(_emr, _ofst, _field, _value) \ 258 EFX_SET_DWORD_FIELD(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 259 MC_CMD_ ## _field, _value) 260 261 #define MCDI_IN_POPULATE_DWORD_1(_emr, _ofst, _field1, _value1) \ 262 EFX_POPULATE_DWORD_1(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 263 MC_CMD_ ## _field1, _value1) 264 265 #define MCDI_IN_POPULATE_DWORD_2(_emr, _ofst, _field1, _value1, \ 266 _field2, _value2) \ 267 EFX_POPULATE_DWORD_2(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 268 MC_CMD_ ## _field1, _value1, \ 269 MC_CMD_ ## _field2, _value2) 270 271 #define MCDI_IN_POPULATE_DWORD_3(_emr, _ofst, _field1, _value1, \ 272 _field2, _value2, _field3, _value3) \ 273 EFX_POPULATE_DWORD_3(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 274 MC_CMD_ ## _field1, _value1, \ 275 MC_CMD_ ## _field2, _value2, \ 276 MC_CMD_ ## _field3, _value3) 277 278 #define MCDI_IN_POPULATE_DWORD_4(_emr, _ofst, _field1, _value1, \ 279 _field2, _value2, _field3, _value3, _field4, _value4) \ 280 EFX_POPULATE_DWORD_4(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 281 MC_CMD_ ## _field1, _value1, \ 282 MC_CMD_ ## _field2, _value2, \ 283 MC_CMD_ ## _field3, _value3, \ 284 MC_CMD_ ## _field4, _value4) 285 286 #define MCDI_IN_POPULATE_DWORD_5(_emr, _ofst, _field1, _value1, \ 287 _field2, _value2, _field3, _value3, _field4, _value4, \ 288 _field5, _value5) \ 289 EFX_POPULATE_DWORD_5(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 290 MC_CMD_ ## _field1, _value1, \ 291 MC_CMD_ ## _field2, _value2, \ 292 MC_CMD_ ## _field3, _value3, \ 293 MC_CMD_ ## _field4, _value4, \ 294 MC_CMD_ ## _field5, _value5) 295 296 #define MCDI_IN_POPULATE_DWORD_6(_emr, _ofst, _field1, _value1, \ 297 _field2, _value2, _field3, _value3, _field4, _value4, \ 298 _field5, _value5, _field6, _value6) \ 299 EFX_POPULATE_DWORD_6(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 300 MC_CMD_ ## _field1, _value1, \ 301 MC_CMD_ ## _field2, _value2, \ 302 MC_CMD_ ## _field3, _value3, \ 303 MC_CMD_ ## _field4, _value4, \ 304 MC_CMD_ ## _field5, _value5, \ 305 MC_CMD_ ## _field6, _value6) 306 307 #define MCDI_IN_POPULATE_DWORD_7(_emr, _ofst, _field1, _value1, \ 308 _field2, _value2, _field3, _value3, _field4, _value4, \ 309 _field5, _value5, _field6, _value6, _field7, _value7) \ 310 EFX_POPULATE_DWORD_7(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 311 MC_CMD_ ## _field1, _value1, \ 312 MC_CMD_ ## _field2, _value2, \ 313 MC_CMD_ ## _field3, _value3, \ 314 MC_CMD_ ## _field4, _value4, \ 315 MC_CMD_ ## _field5, _value5, \ 316 MC_CMD_ ## _field6, _value6, \ 317 MC_CMD_ ## _field7, _value7) 318 319 #define MCDI_IN_POPULATE_DWORD_8(_emr, _ofst, _field1, _value1, \ 320 _field2, _value2, _field3, _value3, _field4, _value4, \ 321 _field5, _value5, _field6, _value6, _field7, _value7, \ 322 _field8, _value8) \ 323 EFX_POPULATE_DWORD_8(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 324 MC_CMD_ ## _field1, _value1, \ 325 MC_CMD_ ## _field2, _value2, \ 326 MC_CMD_ ## _field3, _value3, \ 327 MC_CMD_ ## _field4, _value4, \ 328 MC_CMD_ ## _field5, _value5, \ 329 MC_CMD_ ## _field6, _value6, \ 330 MC_CMD_ ## _field7, _value7, \ 331 MC_CMD_ ## _field8, _value8) 332 333 #define MCDI_IN_POPULATE_DWORD_9(_emr, _ofst, _field1, _value1, \ 334 _field2, _value2, _field3, _value3, _field4, _value4, \ 335 _field5, _value5, _field6, _value6, _field7, _value7, \ 336 _field8, _value8, _field9, _value9) \ 337 EFX_POPULATE_DWORD_9(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 338 MC_CMD_ ## _field1, _value1, \ 339 MC_CMD_ ## _field2, _value2, \ 340 MC_CMD_ ## _field3, _value3, \ 341 MC_CMD_ ## _field4, _value4, \ 342 MC_CMD_ ## _field5, _value5, \ 343 MC_CMD_ ## _field6, _value6, \ 344 MC_CMD_ ## _field7, _value7, \ 345 MC_CMD_ ## _field8, _value8, \ 346 MC_CMD_ ## _field9, _value9) 347 348 #define MCDI_IN_POPULATE_DWORD_10(_emr, _ofst, _field1, _value1, \ 349 _field2, _value2, _field3, _value3, _field4, _value4, \ 350 _field5, _value5, _field6, _value6, _field7, _value7, \ 351 _field8, _value8, _field9, _value9, _field10, _value10) \ 352 EFX_POPULATE_DWORD_10(*MCDI_IN2(_emr, efx_dword_t, _ofst), \ 353 MC_CMD_ ## _field1, _value1, \ 354 MC_CMD_ ## _field2, _value2, \ 355 MC_CMD_ ## _field3, _value3, \ 356 MC_CMD_ ## _field4, _value4, \ 357 MC_CMD_ ## _field5, _value5, \ 358 MC_CMD_ ## _field6, _value6, \ 359 MC_CMD_ ## _field7, _value7, \ 360 MC_CMD_ ## _field8, _value8, \ 361 MC_CMD_ ## _field9, _value9, \ 362 MC_CMD_ ## _field10, _value10) 363 364 #define MCDI_OUT(_emr, _type, _ofst) \ 365 ((_type *)((_emr).emr_out_buf + (_ofst))) 366 367 #define MCDI_OUT2(_emr, _type, _ofst) \ 368 MCDI_OUT(_emr, _type, MC_CMD_ ## _ofst ## _OFST) 369 370 #define MCDI_OUT_BYTE(_emr, _ofst) \ 371 EFX_BYTE_FIELD(*MCDI_OUT2(_emr, efx_byte_t, _ofst), \ 372 EFX_BYTE_0) 373 374 #define MCDI_OUT_WORD(_emr, _ofst) \ 375 EFX_WORD_FIELD(*MCDI_OUT2(_emr, efx_word_t, _ofst), \ 376 EFX_WORD_0) 377 378 #define MCDI_OUT_DWORD(_emr, _ofst) \ 379 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \ 380 EFX_DWORD_0) 381 382 #define MCDI_OUT_DWORD_FIELD(_emr, _ofst, _field) \ 383 EFX_DWORD_FIELD(*MCDI_OUT2(_emr, efx_dword_t, _ofst), \ 384 MC_CMD_ ## _field) 385 386 #define MCDI_EV_FIELD(_eqp, _field) \ 387 EFX_QWORD_FIELD(*_eqp, MCDI_EVENT_ ## _field) 388 389 #define MCDI_CMD_DWORD_FIELD(_edp, _field) \ 390 EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field) 391 392 #define EFX_MCDI_HAVE_PRIVILEGE(mask, priv) \ 393 (((mask) & (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) == \ 394 (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) 395 396 typedef enum efx_mcdi_feature_id_e { 397 EFX_MCDI_FEATURE_FW_UPDATE = 0, 398 EFX_MCDI_FEATURE_LINK_CONTROL, 399 EFX_MCDI_FEATURE_MACADDR_CHANGE, 400 EFX_MCDI_FEATURE_MAC_SPOOFING, 401 EFX_MCDI_FEATURE_NIDS 402 } efx_mcdi_feature_id_t; 403 404 #ifdef __cplusplus 405 } 406 #endif 407 408 #endif /* _SYS_EFX_MCDI_H */ 409