1/*- 2 * Copyright (c) 2012-2015 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 31#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2012-2015 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 31#include <sys/cdefs.h>
|
92 /* A host DMA buffer is required for EF10 MCDI */ 93 if (esmp == NULL) { 94 rc = EINVAL; 95 goto fail1; 96 } 97 98 /* 99 * Ensure that the MC doorbell is in a known state before issuing MCDI 100 * commands. The recovery algorithm requires that the MC command buffer 101 * must be 256 byte aligned. See bug24769. 102 */ 103 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) { 104 rc = EINVAL; 105 goto fail2; 106 } 107 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1); 108 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE); 109 110 /* Save initial MC reboot status */ 111 (void) ef10_mcdi_poll_reboot(enp); 112 113 /* Start a new epoch (allow fresh MCDI requests to succeed) */ 114 efx_mcdi_new_epoch(enp); 115 116 return (0); 117 118fail2: 119 EFSYS_PROBE(fail2); 120fail1: 121 EFSYS_PROBE1(fail1, efx_rc_t, rc); 122 123 return (rc); 124} 125 126 void 127ef10_mcdi_fini( 128 __in efx_nic_t *enp) 129{ 130 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip); 131 132 emip->emi_new_epoch = B_FALSE; 133} 134 135 void 136ef10_mcdi_request_copyin( 137 __in efx_nic_t *enp, 138 __in efx_mcdi_req_t *emrp, 139 __in unsigned int seq, 140 __in boolean_t ev_cpl, 141 __in boolean_t new_epoch) 142{ 143 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 144 efsys_mem_t *esmp = emtp->emt_dma_mem; 145 efx_mcdi_header_type_t hdr_type; 146 efx_dword_t dword; 147 efx_dword_t hdr[2]; 148 unsigned int xflags; 149 unsigned int pos; 150 size_t offset; 151 152 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON || 153 enp->en_family == EFX_FAMILY_MEDFORD); 154 155 xflags = 0; 156 if (ev_cpl) 157 xflags |= MCDI_HEADER_XFLAGS_EVREQ; 158 159 offset = 0; 160 161 hdr_type = EFX_MCDI_HEADER_TYPE(emrp->emr_cmd, 162 MAX(emrp->emr_in_length, emrp->emr_out_length)); 163 164 if (hdr_type == EFX_MCDI_HEADER_TYPE_V2) { 165 /* Construct MCDI v2 header */ 166 EFX_POPULATE_DWORD_8(hdr[0], 167 MCDI_HEADER_CODE, MC_CMD_V2_EXTN, 168 MCDI_HEADER_RESYNC, 1, 169 MCDI_HEADER_DATALEN, 0, 170 MCDI_HEADER_SEQ, seq, 171 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1, 172 MCDI_HEADER_ERROR, 0, 173 MCDI_HEADER_RESPONSE, 0, 174 MCDI_HEADER_XFLAGS, xflags); 175 EFSYS_MEM_WRITED(esmp, offset, &hdr[0]); 176 offset += sizeof (efx_dword_t); 177 178 EFX_POPULATE_DWORD_2(hdr[1], 179 MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd, 180 MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length); 181 EFSYS_MEM_WRITED(esmp, offset, &hdr[1]); 182 offset += sizeof (efx_dword_t); 183 } else { 184 /* Construct MCDI v1 header */ 185 EFX_POPULATE_DWORD_8(hdr[0], 186 MCDI_HEADER_CODE, emrp->emr_cmd, 187 MCDI_HEADER_RESYNC, 1, 188 MCDI_HEADER_DATALEN, emrp->emr_in_length, 189 MCDI_HEADER_SEQ, seq, 190 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1, 191 MCDI_HEADER_ERROR, 0, 192 MCDI_HEADER_RESPONSE, 0, 193 MCDI_HEADER_XFLAGS, xflags); 194 EFSYS_MEM_WRITED(esmp, 0, &hdr[0]); 195 offset += sizeof (efx_dword_t); 196 } 197 198#if EFSYS_OPT_MCDI_LOGGING 199 if (emtp->emt_logger != NULL) { 200 emtp->emt_logger(emtp->emt_context, EFX_LOG_MCDI_REQUEST, 201 &hdr, offset, 202 emrp->emr_in_buf, emrp->emr_in_length); 203 } 204#endif /* EFSYS_OPT_MCDI_LOGGING */ 205 206 /* Construct the payload */ 207 for (pos = 0; pos < emrp->emr_in_length; pos += sizeof (efx_dword_t)) { 208 memcpy(&dword, MCDI_IN(*emrp, efx_dword_t, pos), 209 MIN(sizeof (dword), emrp->emr_in_length - pos)); 210 EFSYS_MEM_WRITED(esmp, offset + pos, &dword); 211 } 212 213 /* Ring the doorbell to post the command DMA address to the MC */ 214 EFSYS_ASSERT((EFSYS_MEM_ADDR(esmp) & 0xFF) == 0); 215 216 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */ 217 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, offset + emrp->emr_in_length); 218 EFSYS_PIO_WRITE_BARRIER(); 219 220 EFX_POPULATE_DWORD_1(dword, 221 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) >> 32); 222 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE); 223 224 EFX_POPULATE_DWORD_1(dword, 225 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) & 0xffffffff); 226 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE); 227} 228 229 void 230ef10_mcdi_request_copyout( 231 __in efx_nic_t *enp, 232 __in efx_mcdi_req_t *emrp) 233{ 234#if EFSYS_OPT_MCDI_LOGGING 235 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 236#endif /* EFSYS_OPT_MCDI_LOGGING */ 237 efx_dword_t hdr[2]; 238 unsigned int hdr_len; 239 size_t bytes; 240 241 if (emrp->emr_out_buf == NULL) 242 return; 243 244 /* Read the command header to detect MCDI response format */ 245 hdr_len = sizeof (hdr[0]); 246 ef10_mcdi_read_response(enp, &hdr[0], 0, hdr_len); 247 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) { 248 /* 249 * Read the actual payload length. The length given in the event 250 * is only correct for responses with the V1 format. 251 */ 252 ef10_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1])); 253 hdr_len += sizeof (hdr[1]); 254 255 emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1], 256 MC_CMD_V2_EXTN_IN_ACTUAL_LEN); 257 } 258 259 /* Copy payload out into caller supplied buffer */ 260 bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length); 261 ef10_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes); 262 263#if EFSYS_OPT_MCDI_LOGGING 264 if (emtp->emt_logger != NULL) { 265 emtp->emt_logger(emtp->emt_context, 266 EFX_LOG_MCDI_RESPONSE, 267 &hdr, hdr_len, 268 emrp->emr_out_buf, bytes); 269 } 270#endif /* EFSYS_OPT_MCDI_LOGGING */ 271} 272 273 __checkReturn boolean_t 274ef10_mcdi_poll_response( 275 __in efx_nic_t *enp) 276{ 277 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 278 efsys_mem_t *esmp = emtp->emt_dma_mem; 279 efx_dword_t hdr; 280 281 EFSYS_MEM_READD(esmp, 0, &hdr); 282 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE); 283} 284 285 void 286ef10_mcdi_read_response( 287 __in efx_nic_t *enp, 288 __out void *bufferp, 289 __in size_t offset, 290 __in size_t length) 291{ 292 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 293 efsys_mem_t *esmp = emtp->emt_dma_mem; 294 unsigned int pos; 295 efx_dword_t data; 296 297 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) { 298 EFSYS_MEM_READD(esmp, offset + pos, &data); 299 memcpy((uint8_t *)bufferp + pos, &data, 300 MIN(sizeof (data), length - pos)); 301 } 302} 303 304 efx_rc_t 305ef10_mcdi_poll_reboot( 306 __in efx_nic_t *enp) 307{ 308 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip); 309 efx_dword_t dword; 310 uint32_t old_status; 311 uint32_t new_status; 312 efx_rc_t rc; 313 314 old_status = emip->emi_mc_reboot_status; 315 316 /* Update MC reboot status word */ 317 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE); 318 new_status = dword.ed_u32[0]; 319 320 /* MC has rebooted if the value has changed */ 321 if (new_status != old_status) { 322 emip->emi_mc_reboot_status = new_status; 323 324 /* 325 * FIXME: Ignore detected MC REBOOT for now. 326 * 327 * The Siena support for checking for MC reboot from status 328 * flags is broken - see comments in siena_mcdi_poll_reboot(). 329 * As the generic MCDI code is shared the EF10 reboot 330 * detection suffers similar problems. 331 * 332 * Do not report an error when the boot status changes until 333 * this can be handled by common code drivers (and reworked to 334 * support Siena too). 335 */ 336 if (B_FALSE) { 337 rc = EIO; 338 goto fail1; 339 } 340 } 341 342 return (0); 343 344fail1: 345 EFSYS_PROBE1(fail1, efx_rc_t, rc); 346 347 return (rc); 348} 349 350 __checkReturn efx_rc_t 351ef10_mcdi_feature_supported( 352 __in efx_nic_t *enp, 353 __in efx_mcdi_feature_id_t id, 354 __out boolean_t *supportedp) 355{ 356 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 357 uint32_t privilege_mask = encp->enc_privilege_mask; 358 efx_rc_t rc; 359 360 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON || 361 enp->en_family == EFX_FAMILY_MEDFORD); 362 363 /* 364 * Use privilege mask state at MCDI attach. 365 */ 366 367 switch (id) { 368 case EFX_MCDI_FEATURE_FW_UPDATE: 369 /* 370 * Admin privilege must be used prior to introduction of 371 * specific flag. 372 */ 373 *supportedp = 374 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 375 break; 376 case EFX_MCDI_FEATURE_LINK_CONTROL: 377 /* 378 * Admin privilege used prior to introduction of 379 * specific flag. 380 */ 381 *supportedp = 382 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) || 383 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 384 break; 385 case EFX_MCDI_FEATURE_MACADDR_CHANGE: 386 /* 387 * Admin privilege must be used prior to introduction of 388 * mac spoofing privilege (at v4.6), which is used up to 389 * introduction of change mac spoofing privilege (at v4.7) 390 */ 391 *supportedp = 392 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) || 393 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) || 394 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 395 break; 396 case EFX_MCDI_FEATURE_MAC_SPOOFING: 397 /* 398 * Admin privilege must be used prior to introduction of 399 * mac spoofing privilege (at v4.6), which is used up to 400 * introduction of mac spoofing TX privilege (at v4.7) 401 */ 402 *supportedp = 403 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) || 404 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) || 405 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 406 break; 407 default: 408 rc = ENOTSUP; 409 goto fail1; 410 break; 411 } 412 413 return (0); 414 415fail1: 416 EFSYS_PROBE1(fail1, efx_rc_t, rc); 417 418 return (rc); 419} 420 421#endif /* EFSYS_OPT_MCDI */ 422 423#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
| 100 /* A host DMA buffer is required for EF10 MCDI */ 101 if (esmp == NULL) { 102 rc = EINVAL; 103 goto fail1; 104 } 105 106 /* 107 * Ensure that the MC doorbell is in a known state before issuing MCDI 108 * commands. The recovery algorithm requires that the MC command buffer 109 * must be 256 byte aligned. See bug24769. 110 */ 111 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) { 112 rc = EINVAL; 113 goto fail2; 114 } 115 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1); 116 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE); 117 118 /* Save initial MC reboot status */ 119 (void) ef10_mcdi_poll_reboot(enp); 120 121 /* Start a new epoch (allow fresh MCDI requests to succeed) */ 122 efx_mcdi_new_epoch(enp); 123 124 return (0); 125 126fail2: 127 EFSYS_PROBE(fail2); 128fail1: 129 EFSYS_PROBE1(fail1, efx_rc_t, rc); 130 131 return (rc); 132} 133 134 void 135ef10_mcdi_fini( 136 __in efx_nic_t *enp) 137{ 138 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip); 139 140 emip->emi_new_epoch = B_FALSE; 141} 142 143 void 144ef10_mcdi_request_copyin( 145 __in efx_nic_t *enp, 146 __in efx_mcdi_req_t *emrp, 147 __in unsigned int seq, 148 __in boolean_t ev_cpl, 149 __in boolean_t new_epoch) 150{ 151 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 152 efsys_mem_t *esmp = emtp->emt_dma_mem; 153 efx_mcdi_header_type_t hdr_type; 154 efx_dword_t dword; 155 efx_dword_t hdr[2]; 156 unsigned int xflags; 157 unsigned int pos; 158 size_t offset; 159 160 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON || 161 enp->en_family == EFX_FAMILY_MEDFORD); 162 163 xflags = 0; 164 if (ev_cpl) 165 xflags |= MCDI_HEADER_XFLAGS_EVREQ; 166 167 offset = 0; 168 169 hdr_type = EFX_MCDI_HEADER_TYPE(emrp->emr_cmd, 170 MAX(emrp->emr_in_length, emrp->emr_out_length)); 171 172 if (hdr_type == EFX_MCDI_HEADER_TYPE_V2) { 173 /* Construct MCDI v2 header */ 174 EFX_POPULATE_DWORD_8(hdr[0], 175 MCDI_HEADER_CODE, MC_CMD_V2_EXTN, 176 MCDI_HEADER_RESYNC, 1, 177 MCDI_HEADER_DATALEN, 0, 178 MCDI_HEADER_SEQ, seq, 179 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1, 180 MCDI_HEADER_ERROR, 0, 181 MCDI_HEADER_RESPONSE, 0, 182 MCDI_HEADER_XFLAGS, xflags); 183 EFSYS_MEM_WRITED(esmp, offset, &hdr[0]); 184 offset += sizeof (efx_dword_t); 185 186 EFX_POPULATE_DWORD_2(hdr[1], 187 MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd, 188 MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length); 189 EFSYS_MEM_WRITED(esmp, offset, &hdr[1]); 190 offset += sizeof (efx_dword_t); 191 } else { 192 /* Construct MCDI v1 header */ 193 EFX_POPULATE_DWORD_8(hdr[0], 194 MCDI_HEADER_CODE, emrp->emr_cmd, 195 MCDI_HEADER_RESYNC, 1, 196 MCDI_HEADER_DATALEN, emrp->emr_in_length, 197 MCDI_HEADER_SEQ, seq, 198 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1, 199 MCDI_HEADER_ERROR, 0, 200 MCDI_HEADER_RESPONSE, 0, 201 MCDI_HEADER_XFLAGS, xflags); 202 EFSYS_MEM_WRITED(esmp, 0, &hdr[0]); 203 offset += sizeof (efx_dword_t); 204 } 205 206#if EFSYS_OPT_MCDI_LOGGING 207 if (emtp->emt_logger != NULL) { 208 emtp->emt_logger(emtp->emt_context, EFX_LOG_MCDI_REQUEST, 209 &hdr, offset, 210 emrp->emr_in_buf, emrp->emr_in_length); 211 } 212#endif /* EFSYS_OPT_MCDI_LOGGING */ 213 214 /* Construct the payload */ 215 for (pos = 0; pos < emrp->emr_in_length; pos += sizeof (efx_dword_t)) { 216 memcpy(&dword, MCDI_IN(*emrp, efx_dword_t, pos), 217 MIN(sizeof (dword), emrp->emr_in_length - pos)); 218 EFSYS_MEM_WRITED(esmp, offset + pos, &dword); 219 } 220 221 /* Ring the doorbell to post the command DMA address to the MC */ 222 EFSYS_ASSERT((EFSYS_MEM_ADDR(esmp) & 0xFF) == 0); 223 224 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */ 225 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, offset + emrp->emr_in_length); 226 EFSYS_PIO_WRITE_BARRIER(); 227 228 EFX_POPULATE_DWORD_1(dword, 229 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) >> 32); 230 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE); 231 232 EFX_POPULATE_DWORD_1(dword, 233 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) & 0xffffffff); 234 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE); 235} 236 237 void 238ef10_mcdi_request_copyout( 239 __in efx_nic_t *enp, 240 __in efx_mcdi_req_t *emrp) 241{ 242#if EFSYS_OPT_MCDI_LOGGING 243 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 244#endif /* EFSYS_OPT_MCDI_LOGGING */ 245 efx_dword_t hdr[2]; 246 unsigned int hdr_len; 247 size_t bytes; 248 249 if (emrp->emr_out_buf == NULL) 250 return; 251 252 /* Read the command header to detect MCDI response format */ 253 hdr_len = sizeof (hdr[0]); 254 ef10_mcdi_read_response(enp, &hdr[0], 0, hdr_len); 255 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) { 256 /* 257 * Read the actual payload length. The length given in the event 258 * is only correct for responses with the V1 format. 259 */ 260 ef10_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1])); 261 hdr_len += sizeof (hdr[1]); 262 263 emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1], 264 MC_CMD_V2_EXTN_IN_ACTUAL_LEN); 265 } 266 267 /* Copy payload out into caller supplied buffer */ 268 bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length); 269 ef10_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes); 270 271#if EFSYS_OPT_MCDI_LOGGING 272 if (emtp->emt_logger != NULL) { 273 emtp->emt_logger(emtp->emt_context, 274 EFX_LOG_MCDI_RESPONSE, 275 &hdr, hdr_len, 276 emrp->emr_out_buf, bytes); 277 } 278#endif /* EFSYS_OPT_MCDI_LOGGING */ 279} 280 281 __checkReturn boolean_t 282ef10_mcdi_poll_response( 283 __in efx_nic_t *enp) 284{ 285 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 286 efsys_mem_t *esmp = emtp->emt_dma_mem; 287 efx_dword_t hdr; 288 289 EFSYS_MEM_READD(esmp, 0, &hdr); 290 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE); 291} 292 293 void 294ef10_mcdi_read_response( 295 __in efx_nic_t *enp, 296 __out void *bufferp, 297 __in size_t offset, 298 __in size_t length) 299{ 300 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp; 301 efsys_mem_t *esmp = emtp->emt_dma_mem; 302 unsigned int pos; 303 efx_dword_t data; 304 305 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) { 306 EFSYS_MEM_READD(esmp, offset + pos, &data); 307 memcpy((uint8_t *)bufferp + pos, &data, 308 MIN(sizeof (data), length - pos)); 309 } 310} 311 312 efx_rc_t 313ef10_mcdi_poll_reboot( 314 __in efx_nic_t *enp) 315{ 316 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip); 317 efx_dword_t dword; 318 uint32_t old_status; 319 uint32_t new_status; 320 efx_rc_t rc; 321 322 old_status = emip->emi_mc_reboot_status; 323 324 /* Update MC reboot status word */ 325 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE); 326 new_status = dword.ed_u32[0]; 327 328 /* MC has rebooted if the value has changed */ 329 if (new_status != old_status) { 330 emip->emi_mc_reboot_status = new_status; 331 332 /* 333 * FIXME: Ignore detected MC REBOOT for now. 334 * 335 * The Siena support for checking for MC reboot from status 336 * flags is broken - see comments in siena_mcdi_poll_reboot(). 337 * As the generic MCDI code is shared the EF10 reboot 338 * detection suffers similar problems. 339 * 340 * Do not report an error when the boot status changes until 341 * this can be handled by common code drivers (and reworked to 342 * support Siena too). 343 */ 344 if (B_FALSE) { 345 rc = EIO; 346 goto fail1; 347 } 348 } 349 350 return (0); 351 352fail1: 353 EFSYS_PROBE1(fail1, efx_rc_t, rc); 354 355 return (rc); 356} 357 358 __checkReturn efx_rc_t 359ef10_mcdi_feature_supported( 360 __in efx_nic_t *enp, 361 __in efx_mcdi_feature_id_t id, 362 __out boolean_t *supportedp) 363{ 364 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 365 uint32_t privilege_mask = encp->enc_privilege_mask; 366 efx_rc_t rc; 367 368 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON || 369 enp->en_family == EFX_FAMILY_MEDFORD); 370 371 /* 372 * Use privilege mask state at MCDI attach. 373 */ 374 375 switch (id) { 376 case EFX_MCDI_FEATURE_FW_UPDATE: 377 /* 378 * Admin privilege must be used prior to introduction of 379 * specific flag. 380 */ 381 *supportedp = 382 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 383 break; 384 case EFX_MCDI_FEATURE_LINK_CONTROL: 385 /* 386 * Admin privilege used prior to introduction of 387 * specific flag. 388 */ 389 *supportedp = 390 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) || 391 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 392 break; 393 case EFX_MCDI_FEATURE_MACADDR_CHANGE: 394 /* 395 * Admin privilege must be used prior to introduction of 396 * mac spoofing privilege (at v4.6), which is used up to 397 * introduction of change mac spoofing privilege (at v4.7) 398 */ 399 *supportedp = 400 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) || 401 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) || 402 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 403 break; 404 case EFX_MCDI_FEATURE_MAC_SPOOFING: 405 /* 406 * Admin privilege must be used prior to introduction of 407 * mac spoofing privilege (at v4.6), which is used up to 408 * introduction of mac spoofing TX privilege (at v4.7) 409 */ 410 *supportedp = 411 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) || 412 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) || 413 EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN); 414 break; 415 default: 416 rc = ENOTSUP; 417 goto fail1; 418 break; 419 } 420 421 return (0); 422 423fail1: 424 EFSYS_PROBE1(fail1, efx_rc_t, rc); 425 426 return (rc); 427} 428 429#endif /* EFSYS_OPT_MCDI */ 430 431#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
|