2 * Copyright (c) 2008-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
37 * There are three versions of the MCDI interface:
38 * - MCDIv0: Siena BootROM. Transport uses MCDIv1 headers.
39 * - MCDIv1: Siena firmware and Huntington BootROM.
40 * - MCDIv2: EF10 firmware (Huntington/Medford) and Medford BootROM.
41 * Transport uses MCDIv2 headers.
43 * MCDIv2 Header NOT_EPOCH flag
44 * ----------------------------
45 * A new epoch begins at initial startup or after an MC reboot, and defines when
46 * the MC should reject stale MCDI requests.
48 * The first MCDI request sent by the host should contain NOT_EPOCH=0, and all
49 * subsequent requests (until the next MC reboot) should contain NOT_EPOCH=1.
51 * After rebooting the MC will fail all requests with NOT_EPOCH=1 by writing a
52 * response with ERROR=1 and DATALEN=0 until a request is seen with NOT_EPOCH=0.
57 __checkReturn efx_rc_t
60 __in const efx_mcdi_transport_t *emtp)
62 const efx_mcdi_ops_t *emcop;
65 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
66 EFSYS_ASSERT3U(enp->en_mod_flags, ==, 0);
68 switch (enp->en_family) {
76 if (enp->en_features & EFX_FEATURE_MCDI_DMA) {
77 /* MCDI requires a DMA buffer in host memory */
78 if ((emtp == NULL) || (emtp->emt_dma_mem) == NULL) {
83 enp->en_mcdi.em_emtp = emtp;
85 if (emcop != NULL && emcop->emco_init != NULL) {
86 if ((rc = emcop->emco_init(enp, emtp)) != 0)
90 enp->en_mcdi.em_emcop = emcop;
91 enp->en_mod_flags |= EFX_MOD_MCDI;
100 EFSYS_PROBE1(fail1, efx_rc_t, rc);
102 enp->en_mcdi.em_emcop = NULL;
103 enp->en_mcdi.em_emtp = NULL;
104 enp->en_mod_flags &= ~EFX_MOD_MCDI;
113 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
114 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
116 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
117 EFSYS_ASSERT3U(enp->en_mod_flags, ==, EFX_MOD_MCDI);
119 if (emcop != NULL && emcop->emco_fini != NULL)
120 emcop->emco_fini(enp);
123 emip->emi_aborted = 0;
125 enp->en_mcdi.em_emcop = NULL;
126 enp->en_mod_flags &= ~EFX_MOD_MCDI;
133 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
134 efsys_lock_state_t state;
136 /* Start a new epoch (allow fresh MCDI requests to succeed) */
137 EFSYS_LOCK(enp->en_eslp, state);
138 emip->emi_new_epoch = B_TRUE;
139 EFSYS_UNLOCK(enp->en_eslp, state);
143 efx_mcdi_send_request(
150 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
152 emcop->emco_send_request(enp, hdrp, hdr_len, sdup, sdu_len);
156 efx_mcdi_poll_reboot(
159 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
162 rc = emcop->emco_poll_reboot(enp);
167 efx_mcdi_poll_response(
170 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
173 available = emcop->emco_poll_response(enp);
178 efx_mcdi_read_response(
184 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
186 emcop->emco_read_response(enp, bufferp, offset, length);
190 efx_mcdi_request_start(
192 __in efx_mcdi_req_t *emrp,
193 __in boolean_t ev_cpl)
195 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
198 unsigned int max_version;
202 efsys_lock_state_t state;
204 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
205 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
206 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
209 * efx_mcdi_request_start() is naturally serialised against both
210 * efx_mcdi_request_poll() and efx_mcdi_ev_cpl()/efx_mcdi_ev_death(),
211 * by virtue of there only being one outstanding MCDI request.
212 * Unfortunately, upper layers may also call efx_mcdi_request_abort()
213 * at any time, to timeout a pending mcdi request, That request may
214 * then subsequently complete, meaning efx_mcdi_ev_cpl() or
215 * efx_mcdi_ev_death() may end up running in parallel with
216 * efx_mcdi_request_start(). This race is handled by ensuring that
217 * %emi_pending_req, %emi_ev_cpl and %emi_seq are protected by the
220 EFSYS_LOCK(enp->en_eslp, state);
221 EFSYS_ASSERT(emip->emi_pending_req == NULL);
222 emip->emi_pending_req = emrp;
223 emip->emi_ev_cpl = ev_cpl;
224 emip->emi_poll_cnt = 0;
225 seq = emip->emi_seq++ & EFX_MASK32(MCDI_HEADER_SEQ);
226 new_epoch = emip->emi_new_epoch;
227 max_version = emip->emi_max_version;
228 EFSYS_UNLOCK(enp->en_eslp, state);
232 xflags |= MCDI_HEADER_XFLAGS_EVREQ;
235 * Huntington firmware supports MCDIv2, but the Huntington BootROM only
236 * supports MCDIv1. Use MCDIv1 headers for MCDIv1 commands where
237 * possible to support this.
239 if ((max_version >= 2) &&
240 ((emrp->emr_cmd > MC_CMD_CMD_SPACE_ESCAPE_7) ||
241 (emrp->emr_in_length > MCDI_CTL_SDU_LEN_MAX_V1))) {
242 /* Construct MCDI v2 header */
243 hdr_len = sizeof (hdr);
244 EFX_POPULATE_DWORD_8(hdr[0],
245 MCDI_HEADER_CODE, MC_CMD_V2_EXTN,
246 MCDI_HEADER_RESYNC, 1,
247 MCDI_HEADER_DATALEN, 0,
248 MCDI_HEADER_SEQ, seq,
249 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
250 MCDI_HEADER_ERROR, 0,
251 MCDI_HEADER_RESPONSE, 0,
252 MCDI_HEADER_XFLAGS, xflags);
254 EFX_POPULATE_DWORD_2(hdr[1],
255 MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd,
256 MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length);
258 /* Construct MCDI v1 header */
259 hdr_len = sizeof (hdr[0]);
260 EFX_POPULATE_DWORD_8(hdr[0],
261 MCDI_HEADER_CODE, emrp->emr_cmd,
262 MCDI_HEADER_RESYNC, 1,
263 MCDI_HEADER_DATALEN, emrp->emr_in_length,
264 MCDI_HEADER_SEQ, seq,
265 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
266 MCDI_HEADER_ERROR, 0,
267 MCDI_HEADER_RESPONSE, 0,
268 MCDI_HEADER_XFLAGS, xflags);
271 efx_mcdi_send_request(enp, &hdr[0], hdr_len,
272 emrp->emr_in_buf, emrp->emr_in_length);
277 efx_mcdi_read_response_header(
279 __inout efx_mcdi_req_t *emrp)
281 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
283 unsigned int hdr_len;
284 unsigned int data_len;
290 EFSYS_ASSERT(emrp != NULL);
292 efx_mcdi_read_response(enp, &hdr[0], 0, sizeof (hdr[0]));
293 hdr_len = sizeof (hdr[0]);
295 cmd = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE);
296 seq = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_SEQ);
297 error = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR);
299 if (cmd != MC_CMD_V2_EXTN) {
300 data_len = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
302 efx_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
303 hdr_len += sizeof (hdr[1]);
305 cmd = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_EXTENDED_CMD);
307 EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
310 if (error && (data_len == 0)) {
311 /* The MC has rebooted since the request was sent. */
312 EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
313 efx_mcdi_poll_reboot(enp);
317 if ((cmd != emrp->emr_cmd) ||
318 (seq != ((emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ)))) {
319 /* Response is for a different request */
325 unsigned int err_len = MIN(data_len, sizeof (err));
326 int err_code = MC_CMD_ERR_EPROTO;
329 /* Read error code (and arg num for MCDI v2 commands) */
330 efx_mcdi_read_response(enp, &err, hdr_len, err_len);
332 if (err_len >= (MC_CMD_ERR_CODE_OFST + sizeof (efx_dword_t)))
333 err_code = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
335 if (err_len >= (MC_CMD_ERR_ARG_OFST + sizeof (efx_dword_t)))
336 err_arg = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
338 emrp->emr_err_code = err_code;
339 emrp->emr_err_arg = err_arg;
341 if (!emrp->emr_quiet) {
342 EFSYS_PROBE3(mcdi_err_arg, int, emrp->emr_cmd,
343 int, err_code, int, err_arg);
346 rc = efx_mcdi_request_errcode(err_code);
351 emrp->emr_out_length_used = data_len;
358 emrp->emr_out_length_used = 0;
362 efx_mcdi_finish_response(
364 __in efx_mcdi_req_t *emrp)
367 unsigned int hdr_len;
370 if (emrp->emr_out_buf == NULL)
373 /* Read the command header to detect MCDI response format */
374 hdr_len = sizeof (hdr[0]);
375 efx_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
376 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
378 * Read the actual payload length. The length given in the event
379 * is only correct for responses with the V1 format.
381 efx_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
382 hdr_len += sizeof (hdr[1]);
384 emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1],
385 MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
388 /* Copy payload out into caller supplied buffer */
389 bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length);
390 efx_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes);
395 __checkReturn boolean_t
396 efx_mcdi_request_poll(
399 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
400 efx_mcdi_req_t *emrp;
401 efsys_lock_state_t state;
404 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
405 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
406 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
408 /* Serialise against post-watchdog efx_mcdi_ev* */
409 EFSYS_LOCK(enp->en_eslp, state);
411 EFSYS_ASSERT(emip->emi_pending_req != NULL);
412 EFSYS_ASSERT(!emip->emi_ev_cpl);
413 emrp = emip->emi_pending_req;
415 /* Check for reboot atomically w.r.t efx_mcdi_request_start */
416 if (emip->emi_poll_cnt++ == 0) {
417 if ((rc = efx_mcdi_poll_reboot(enp)) != 0) {
418 emip->emi_pending_req = NULL;
419 EFSYS_UNLOCK(enp->en_eslp, state);
421 /* Reboot/Assertion */
422 if (rc == EIO || rc == EINTR)
423 efx_mcdi_raise_exception(enp, emrp, rc);
429 /* Check if a response is available */
430 if (efx_mcdi_poll_response(enp) == B_FALSE) {
431 EFSYS_UNLOCK(enp->en_eslp, state);
435 /* Read the response header */
436 efx_mcdi_read_response_header(enp, emrp);
438 /* Request complete */
439 emip->emi_pending_req = NULL;
441 /* Ensure stale MCDI requests fail after an MC reboot. */
442 emip->emi_new_epoch = B_FALSE;
444 EFSYS_UNLOCK(enp->en_eslp, state);
446 if ((rc = emrp->emr_rc) != 0)
449 efx_mcdi_finish_response(enp, emrp);
453 if (!emrp->emr_quiet)
456 if (!emrp->emr_quiet)
457 EFSYS_PROBE1(fail1, efx_rc_t, rc);
462 __checkReturn boolean_t
463 efx_mcdi_request_abort(
466 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
467 efx_mcdi_req_t *emrp;
469 efsys_lock_state_t state;
471 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
472 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
473 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
476 * efx_mcdi_ev_* may have already completed this event, and be
477 * spinning/blocked on the upper layer lock. So it *is* legitimate
478 * to for emi_pending_req to be NULL. If there is a pending event
479 * completed request, then provide a "credit" to allow
480 * efx_mcdi_ev_cpl() to accept a single spurious completion.
482 EFSYS_LOCK(enp->en_eslp, state);
483 emrp = emip->emi_pending_req;
484 aborted = (emrp != NULL);
486 emip->emi_pending_req = NULL;
488 /* Error the request */
489 emrp->emr_out_length_used = 0;
490 emrp->emr_rc = ETIMEDOUT;
492 /* Provide a credit for seqno/emr_pending_req mismatches */
493 if (emip->emi_ev_cpl)
497 * The upper layer has called us, so we don't
498 * need to complete the request.
501 EFSYS_UNLOCK(enp->en_eslp, state);
507 efx_mcdi_get_timeout(
509 __in efx_mcdi_req_t *emrp,
510 __out uint32_t *timeoutp)
512 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
514 emcop->emco_get_timeout(enp, emrp, timeoutp);
517 __checkReturn efx_rc_t
518 efx_mcdi_request_errcode(
519 __in unsigned int err)
524 case MC_CMD_ERR_EPERM:
526 case MC_CMD_ERR_ENOENT:
528 case MC_CMD_ERR_EINTR:
530 case MC_CMD_ERR_EACCES:
532 case MC_CMD_ERR_EBUSY:
534 case MC_CMD_ERR_EINVAL:
536 case MC_CMD_ERR_EDEADLK:
538 case MC_CMD_ERR_ENOSYS:
540 case MC_CMD_ERR_ETIME:
542 case MC_CMD_ERR_ENOTSUP:
544 case MC_CMD_ERR_EALREADY:
548 case MC_CMD_ERR_EEXIST:
550 #ifdef MC_CMD_ERR_EAGAIN
551 case MC_CMD_ERR_EAGAIN:
554 #ifdef MC_CMD_ERR_ENOSPC
555 case MC_CMD_ERR_ENOSPC:
558 case MC_CMD_ERR_ERANGE:
561 case MC_CMD_ERR_ALLOC_FAIL:
563 case MC_CMD_ERR_NO_VADAPTOR:
565 case MC_CMD_ERR_NO_EVB_PORT:
567 case MC_CMD_ERR_NO_VSWITCH:
569 case MC_CMD_ERR_VLAN_LIMIT:
571 case MC_CMD_ERR_BAD_PCI_FUNC:
573 case MC_CMD_ERR_BAD_VLAN_MODE:
575 case MC_CMD_ERR_BAD_VSWITCH_TYPE:
577 case MC_CMD_ERR_BAD_VPORT_TYPE:
579 case MC_CMD_ERR_MAC_EXIST:
582 case MC_CMD_ERR_PROXY_PENDING:
586 EFSYS_PROBE1(mc_pcol_error, int, err);
592 efx_mcdi_raise_exception(
594 __in_opt efx_mcdi_req_t *emrp,
597 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
598 efx_mcdi_exception_t exception;
600 /* Reboot or Assertion failure only */
601 EFSYS_ASSERT(rc == EIO || rc == EINTR);
604 * If MC_CMD_REBOOT causes a reboot (dependent on parameters),
605 * then the EIO is not worthy of an exception.
607 if (emrp != NULL && emrp->emr_cmd == MC_CMD_REBOOT && rc == EIO)
610 exception = (rc == EIO)
611 ? EFX_MCDI_EXCEPTION_MC_REBOOT
612 : EFX_MCDI_EXCEPTION_MC_BADASSERT;
614 emtp->emt_exception(emtp->emt_context, exception);
620 __inout efx_mcdi_req_t *emrp)
622 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
624 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
625 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
627 emrp->emr_quiet = B_FALSE;
628 emtp->emt_execute(emtp->emt_context, emrp);
632 efx_mcdi_execute_quiet(
634 __inout efx_mcdi_req_t *emrp)
636 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
638 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
639 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
641 emrp->emr_quiet = B_TRUE;
642 emtp->emt_execute(emtp->emt_context, emrp);
648 __in unsigned int seq,
649 __in unsigned int outlen,
652 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
653 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
654 efx_mcdi_req_t *emrp;
655 efsys_lock_state_t state;
657 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MCDI);
658 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
661 * Serialise against efx_mcdi_request_poll()/efx_mcdi_request_start()
662 * when we're completing an aborted request.
664 EFSYS_LOCK(enp->en_eslp, state);
665 if (emip->emi_pending_req == NULL || !emip->emi_ev_cpl ||
666 (seq != ((emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ)))) {
667 EFSYS_ASSERT(emip->emi_aborted > 0);
668 if (emip->emi_aborted > 0)
670 EFSYS_UNLOCK(enp->en_eslp, state);
674 emrp = emip->emi_pending_req;
675 emip->emi_pending_req = NULL;
676 EFSYS_UNLOCK(enp->en_eslp, state);
678 if (emip->emi_max_version >= 2) {
679 /* MCDIv2 response details do not fit into an event. */
680 efx_mcdi_read_response_header(enp, emrp);
683 if (!emrp->emr_quiet) {
684 EFSYS_PROBE2(mcdi_err, int, emrp->emr_cmd,
687 emrp->emr_out_length_used = 0;
688 emrp->emr_rc = efx_mcdi_request_errcode(errcode);
690 emrp->emr_out_length_used = outlen;
695 efx_mcdi_finish_response(enp, emrp);
698 emtp->emt_ev_cpl(emtp->emt_context);
706 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
707 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
708 efx_mcdi_req_t *emrp = NULL;
710 efsys_lock_state_t state;
713 * The MCDI request (if there is one) has been terminated, either
714 * by a BADASSERT or REBOOT event.
716 * If there is an outstanding event-completed MCDI operation, then we
717 * will never receive the completion event (because both MCDI
718 * completions and BADASSERT events are sent to the same evq). So
719 * complete this MCDI op.
721 * This function might run in parallel with efx_mcdi_request_poll()
722 * for poll completed mcdi requests, and also with
723 * efx_mcdi_request_start() for post-watchdog completions.
725 EFSYS_LOCK(enp->en_eslp, state);
726 emrp = emip->emi_pending_req;
727 ev_cpl = emip->emi_ev_cpl;
728 if (emrp != NULL && emip->emi_ev_cpl) {
729 emip->emi_pending_req = NULL;
731 emrp->emr_out_length_used = 0;
737 * Since we're running in parallel with a request, consume the
738 * status word before dropping the lock.
740 if (rc == EIO || rc == EINTR) {
741 EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
742 (void) efx_mcdi_poll_reboot(enp);
743 emip->emi_new_epoch = B_TRUE;
746 EFSYS_UNLOCK(enp->en_eslp, state);
748 efx_mcdi_raise_exception(enp, emrp, rc);
750 if (emrp != NULL && ev_cpl)
751 emtp->emt_ev_cpl(emtp->emt_context);
754 __checkReturn efx_rc_t
757 __out_ecount_opt(4) uint16_t versionp[4],
758 __out_opt uint32_t *buildp,
759 __out_opt efx_mcdi_boot_t *statusp)
762 uint8_t payload[MAX(MAX(MC_CMD_GET_VERSION_IN_LEN,
763 MC_CMD_GET_VERSION_OUT_LEN),
764 MAX(MC_CMD_GET_BOOT_STATUS_IN_LEN,
765 MC_CMD_GET_BOOT_STATUS_OUT_LEN))];
766 efx_word_t *ver_words;
769 efx_mcdi_boot_t status;
772 EFSYS_ASSERT3U(enp->en_features, &, EFX_FEATURE_MCDI);
774 (void) memset(payload, 0, sizeof (payload));
775 req.emr_cmd = MC_CMD_GET_VERSION;
776 req.emr_in_buf = payload;
777 req.emr_in_length = MC_CMD_GET_VERSION_IN_LEN;
778 req.emr_out_buf = payload;
779 req.emr_out_length = MC_CMD_GET_VERSION_OUT_LEN;
781 efx_mcdi_execute(enp, &req);
783 if (req.emr_rc != 0) {
788 /* bootrom support */
789 if (req.emr_out_length_used == MC_CMD_GET_VERSION_V0_OUT_LEN) {
790 version[0] = version[1] = version[2] = version[3] = 0;
791 build = MCDI_OUT_DWORD(req, GET_VERSION_OUT_FIRMWARE);
796 if (req.emr_out_length_used < MC_CMD_GET_VERSION_OUT_LEN) {
801 ver_words = MCDI_OUT2(req, efx_word_t, GET_VERSION_OUT_VERSION);
802 version[0] = EFX_WORD_FIELD(ver_words[0], EFX_WORD_0);
803 version[1] = EFX_WORD_FIELD(ver_words[1], EFX_WORD_0);
804 version[2] = EFX_WORD_FIELD(ver_words[2], EFX_WORD_0);
805 version[3] = EFX_WORD_FIELD(ver_words[3], EFX_WORD_0);
806 build = MCDI_OUT_DWORD(req, GET_VERSION_OUT_FIRMWARE);
809 /* The bootrom doesn't understand BOOT_STATUS */
810 if (MC_FW_VERSION_IS_BOOTLOADER(build)) {
811 status = EFX_MCDI_BOOT_ROM;
815 (void) memset(payload, 0, sizeof (payload));
816 req.emr_cmd = MC_CMD_GET_BOOT_STATUS;
817 req.emr_in_buf = payload;
818 req.emr_in_length = MC_CMD_GET_BOOT_STATUS_IN_LEN;
819 req.emr_out_buf = payload;
820 req.emr_out_length = MC_CMD_GET_BOOT_STATUS_OUT_LEN;
822 efx_mcdi_execute_quiet(enp, &req);
824 if (req.emr_rc == EACCES) {
825 /* Unprivileged functions cannot access BOOT_STATUS */
826 status = EFX_MCDI_BOOT_PRIMARY;
827 version[0] = version[1] = version[2] = version[3] = 0;
832 if (req.emr_rc != 0) {
837 if (req.emr_out_length_used < MC_CMD_GET_BOOT_STATUS_OUT_LEN) {
842 if (MCDI_OUT_DWORD_FIELD(req, GET_BOOT_STATUS_OUT_FLAGS,
843 GET_BOOT_STATUS_OUT_FLAGS_PRIMARY))
844 status = EFX_MCDI_BOOT_PRIMARY;
846 status = EFX_MCDI_BOOT_SECONDARY;
849 if (versionp != NULL)
850 memcpy(versionp, version, sizeof (version));
865 EFSYS_PROBE1(fail1, efx_rc_t, rc);
870 static __checkReturn efx_rc_t
873 __in boolean_t after_assertion)
875 uint8_t payload[MAX(MC_CMD_REBOOT_IN_LEN, MC_CMD_REBOOT_OUT_LEN)];
880 * We could require the caller to have caused en_mod_flags=0 to
881 * call this function. This doesn't help the other port though,
882 * who's about to get the MC ripped out from underneath them.
883 * Since they have to cope with the subsequent fallout of MCDI
884 * failures, we should as well.
886 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
888 (void) memset(payload, 0, sizeof (payload));
889 req.emr_cmd = MC_CMD_REBOOT;
890 req.emr_in_buf = payload;
891 req.emr_in_length = MC_CMD_REBOOT_IN_LEN;
892 req.emr_out_buf = payload;
893 req.emr_out_length = MC_CMD_REBOOT_OUT_LEN;
895 MCDI_IN_SET_DWORD(req, REBOOT_IN_FLAGS,
896 (after_assertion ? MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION : 0));
898 efx_mcdi_execute_quiet(enp, &req);
900 if (req.emr_rc == EACCES) {
901 /* Unprivileged functions cannot reboot the MC. */
905 /* A successful reboot request returns EIO. */
906 if (req.emr_rc != 0 && req.emr_rc != EIO) {
915 EFSYS_PROBE1(fail1, efx_rc_t, rc);
920 __checkReturn efx_rc_t
924 return (efx_mcdi_do_reboot(enp, B_FALSE));
927 __checkReturn efx_rc_t
928 efx_mcdi_exit_assertion_handler(
931 return (efx_mcdi_do_reboot(enp, B_TRUE));
934 __checkReturn efx_rc_t
935 efx_mcdi_read_assertion(
939 uint8_t payload[MAX(MC_CMD_GET_ASSERTS_IN_LEN,
940 MC_CMD_GET_ASSERTS_OUT_LEN)];
949 * Before we attempt to chat to the MC, we should verify that the MC
950 * isn't in it's assertion handler, either due to a previous reboot,
951 * or because we're reinitializing due to an eec_exception().
953 * Use GET_ASSERTS to read any assertion state that may be present.
954 * Retry this command twice. Once because a boot-time assertion failure
955 * might cause the 1st MCDI request to fail. And once again because
956 * we might race with efx_mcdi_exit_assertion_handler() running on
957 * partner port(s) on the same NIC.
961 (void) memset(payload, 0, sizeof (payload));
962 req.emr_cmd = MC_CMD_GET_ASSERTS;
963 req.emr_in_buf = payload;
964 req.emr_in_length = MC_CMD_GET_ASSERTS_IN_LEN;
965 req.emr_out_buf = payload;
966 req.emr_out_length = MC_CMD_GET_ASSERTS_OUT_LEN;
968 MCDI_IN_SET_DWORD(req, GET_ASSERTS_IN_CLEAR, 1);
969 efx_mcdi_execute_quiet(enp, &req);
971 } while ((req.emr_rc == EINTR || req.emr_rc == EIO) && retry-- > 0);
973 if (req.emr_rc != 0) {
974 if (req.emr_rc == EACCES) {
975 /* Unprivileged functions cannot clear assertions. */
982 if (req.emr_out_length_used < MC_CMD_GET_ASSERTS_OUT_LEN) {
987 /* Print out any assertion state recorded */
988 flags = MCDI_OUT_DWORD(req, GET_ASSERTS_OUT_GLOBAL_FLAGS);
989 if (flags == MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS)
992 reason = (flags == MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL)
993 ? "system-level assertion"
994 : (flags == MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL)
995 ? "thread-level assertion"
996 : (flags == MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED)
998 : (flags == MC_CMD_GET_ASSERTS_FLAGS_ADDR_TRAP)
999 ? "illegal address trap"
1000 : "unknown assertion";
1001 EFSYS_PROBE3(mcpu_assertion,
1002 const char *, reason, unsigned int,
1003 MCDI_OUT_DWORD(req, GET_ASSERTS_OUT_SAVED_PC_OFFS),
1005 MCDI_OUT_DWORD(req, GET_ASSERTS_OUT_THREAD_OFFS));
1007 /* Print out the registers (r1 ... r31) */
1008 ofst = MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_OFST;
1010 index < 1 + MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_NUM;
1012 EFSYS_PROBE2(mcpu_register, unsigned int, index, unsigned int,
1013 EFX_DWORD_FIELD(*MCDI_OUT(req, efx_dword_t, ofst),
1015 ofst += sizeof (efx_dword_t);
1017 EFSYS_ASSERT(ofst <= MC_CMD_GET_ASSERTS_OUT_LEN);
1025 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1032 * Internal routines for for specific MCDI requests.
1035 __checkReturn efx_rc_t
1036 efx_mcdi_drv_attach(
1037 __in efx_nic_t *enp,
1038 __in boolean_t attach)
1041 uint8_t payload[MAX(MC_CMD_DRV_ATTACH_IN_LEN,
1042 MC_CMD_DRV_ATTACH_EXT_OUT_LEN)];
1045 (void) memset(payload, 0, sizeof (payload));
1046 req.emr_cmd = MC_CMD_DRV_ATTACH;
1047 req.emr_in_buf = payload;
1048 req.emr_in_length = MC_CMD_DRV_ATTACH_IN_LEN;
1049 req.emr_out_buf = payload;
1050 req.emr_out_length = MC_CMD_DRV_ATTACH_EXT_OUT_LEN;
1053 * Use DONT_CARE for the datapath firmware type to ensure that the
1054 * driver can attach to an unprivileged function. The datapath firmware
1055 * type to use is controlled by the 'sfboot' utility.
1057 MCDI_IN_SET_DWORD(req, DRV_ATTACH_IN_NEW_STATE, attach ? 1 : 0);
1058 MCDI_IN_SET_DWORD(req, DRV_ATTACH_IN_UPDATE, 1);
1059 MCDI_IN_SET_DWORD(req, DRV_ATTACH_IN_FIRMWARE_ID, MC_CMD_FW_DONT_CARE);
1061 efx_mcdi_execute(enp, &req);
1063 if (req.emr_rc != 0) {
1068 if (req.emr_out_length_used < MC_CMD_DRV_ATTACH_OUT_LEN) {
1078 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1083 __checkReturn efx_rc_t
1084 efx_mcdi_get_board_cfg(
1085 __in efx_nic_t *enp,
1086 __out_opt uint32_t *board_typep,
1087 __out_opt efx_dword_t *capabilitiesp,
1088 __out_ecount_opt(6) uint8_t mac_addrp[6])
1090 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
1092 uint8_t payload[MAX(MC_CMD_GET_BOARD_CFG_IN_LEN,
1093 MC_CMD_GET_BOARD_CFG_OUT_LENMIN)];
1096 (void) memset(payload, 0, sizeof (payload));
1097 req.emr_cmd = MC_CMD_GET_BOARD_CFG;
1098 req.emr_in_buf = payload;
1099 req.emr_in_length = MC_CMD_GET_BOARD_CFG_IN_LEN;
1100 req.emr_out_buf = payload;
1101 req.emr_out_length = MC_CMD_GET_BOARD_CFG_OUT_LENMIN;
1103 efx_mcdi_execute(enp, &req);
1105 if (req.emr_rc != 0) {
1110 if (req.emr_out_length_used < MC_CMD_GET_BOARD_CFG_OUT_LENMIN) {
1115 if (mac_addrp != NULL) {
1118 if (emip->emi_port == 1) {
1119 addrp = MCDI_OUT2(req, uint8_t,
1120 GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0);
1121 } else if (emip->emi_port == 2) {
1122 addrp = MCDI_OUT2(req, uint8_t,
1123 GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1);
1129 EFX_MAC_ADDR_COPY(mac_addrp, addrp);
1132 if (capabilitiesp != NULL) {
1133 if (emip->emi_port == 1) {
1134 *capabilitiesp = *MCDI_OUT2(req, efx_dword_t,
1135 GET_BOARD_CFG_OUT_CAPABILITIES_PORT0);
1136 } else if (emip->emi_port == 2) {
1137 *capabilitiesp = *MCDI_OUT2(req, efx_dword_t,
1138 GET_BOARD_CFG_OUT_CAPABILITIES_PORT1);
1145 if (board_typep != NULL) {
1146 *board_typep = MCDI_OUT_DWORD(req,
1147 GET_BOARD_CFG_OUT_BOARD_TYPE);
1159 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1164 __checkReturn efx_rc_t
1165 efx_mcdi_get_resource_limits(
1166 __in efx_nic_t *enp,
1167 __out_opt uint32_t *nevqp,
1168 __out_opt uint32_t *nrxqp,
1169 __out_opt uint32_t *ntxqp)
1172 uint8_t payload[MAX(MC_CMD_GET_RESOURCE_LIMITS_IN_LEN,
1173 MC_CMD_GET_RESOURCE_LIMITS_OUT_LEN)];
1176 (void) memset(payload, 0, sizeof (payload));
1177 req.emr_cmd = MC_CMD_GET_RESOURCE_LIMITS;
1178 req.emr_in_buf = payload;
1179 req.emr_in_length = MC_CMD_GET_RESOURCE_LIMITS_IN_LEN;
1180 req.emr_out_buf = payload;
1181 req.emr_out_length = MC_CMD_GET_RESOURCE_LIMITS_OUT_LEN;
1183 efx_mcdi_execute(enp, &req);
1185 if (req.emr_rc != 0) {
1190 if (req.emr_out_length_used < MC_CMD_GET_RESOURCE_LIMITS_OUT_LEN) {
1196 *nevqp = MCDI_OUT_DWORD(req, GET_RESOURCE_LIMITS_OUT_EVQ);
1198 *nrxqp = MCDI_OUT_DWORD(req, GET_RESOURCE_LIMITS_OUT_RXQ);
1200 *ntxqp = MCDI_OUT_DWORD(req, GET_RESOURCE_LIMITS_OUT_TXQ);
1207 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1212 __checkReturn efx_rc_t
1213 efx_mcdi_get_phy_cfg(
1214 __in efx_nic_t *enp)
1216 efx_port_t *epp = &(enp->en_port);
1217 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1219 uint8_t payload[MAX(MC_CMD_GET_PHY_CFG_IN_LEN,
1220 MC_CMD_GET_PHY_CFG_OUT_LEN)];
1223 (void) memset(payload, 0, sizeof (payload));
1224 req.emr_cmd = MC_CMD_GET_PHY_CFG;
1225 req.emr_in_buf = payload;
1226 req.emr_in_length = MC_CMD_GET_PHY_CFG_IN_LEN;
1227 req.emr_out_buf = payload;
1228 req.emr_out_length = MC_CMD_GET_PHY_CFG_OUT_LEN;
1230 efx_mcdi_execute(enp, &req);
1232 if (req.emr_rc != 0) {
1237 if (req.emr_out_length_used < MC_CMD_GET_PHY_CFG_OUT_LEN) {
1242 encp->enc_phy_type = MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_TYPE);
1244 (void) strncpy(encp->enc_phy_name,
1245 MCDI_OUT2(req, char, GET_PHY_CFG_OUT_NAME),
1246 MIN(sizeof (encp->enc_phy_name) - 1,
1247 MC_CMD_GET_PHY_CFG_OUT_NAME_LEN));
1248 #endif /* EFSYS_OPT_NAMES */
1249 (void) memset(encp->enc_phy_revision, 0,
1250 sizeof (encp->enc_phy_revision));
1251 memcpy(encp->enc_phy_revision,
1252 MCDI_OUT2(req, char, GET_PHY_CFG_OUT_REVISION),
1253 MIN(sizeof (encp->enc_phy_revision) - 1,
1254 MC_CMD_GET_PHY_CFG_OUT_REVISION_LEN));
1256 /* Get the media type of the fixed port, if recognised. */
1257 EFX_STATIC_ASSERT(MC_CMD_MEDIA_XAUI == EFX_PHY_MEDIA_XAUI);
1258 EFX_STATIC_ASSERT(MC_CMD_MEDIA_CX4 == EFX_PHY_MEDIA_CX4);
1259 EFX_STATIC_ASSERT(MC_CMD_MEDIA_KX4 == EFX_PHY_MEDIA_KX4);
1260 EFX_STATIC_ASSERT(MC_CMD_MEDIA_XFP == EFX_PHY_MEDIA_XFP);
1261 EFX_STATIC_ASSERT(MC_CMD_MEDIA_SFP_PLUS == EFX_PHY_MEDIA_SFP_PLUS);
1262 EFX_STATIC_ASSERT(MC_CMD_MEDIA_BASE_T == EFX_PHY_MEDIA_BASE_T);
1263 EFX_STATIC_ASSERT(MC_CMD_MEDIA_QSFP_PLUS == EFX_PHY_MEDIA_QSFP_PLUS);
1264 epp->ep_fixed_port_type =
1265 (efx_phy_media_type_t) MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_MEDIA_TYPE);
1266 if (epp->ep_fixed_port_type >= EFX_PHY_MEDIA_NTYPES)
1267 epp->ep_fixed_port_type = EFX_PHY_MEDIA_INVALID;
1269 epp->ep_phy_cap_mask =
1270 MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_SUPPORTED_CAP);
1272 encp->enc_port = (uint8_t)MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_PRT);
1274 /* Populate internal state */
1275 encp->enc_mcdi_mdio_channel =
1276 (uint8_t)MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_CHANNEL);
1283 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1288 __checkReturn efx_rc_t
1289 efx_mcdi_firmware_update_supported(
1290 __in efx_nic_t *enp,
1291 __out boolean_t *supportedp)
1293 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1296 if (emcop != NULL) {
1297 if ((rc = emcop->emco_feature_supported(enp,
1298 EFX_MCDI_FEATURE_FW_UPDATE, supportedp)) != 0)
1301 /* Earlier devices always supported updates */
1302 *supportedp = B_TRUE;
1308 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1313 __checkReturn efx_rc_t
1314 efx_mcdi_macaddr_change_supported(
1315 __in efx_nic_t *enp,
1316 __out boolean_t *supportedp)
1318 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1321 if (emcop != NULL) {
1322 if ((rc = emcop->emco_feature_supported(enp,
1323 EFX_MCDI_FEATURE_MACADDR_CHANGE, supportedp)) != 0)
1326 /* Earlier devices always supported MAC changes */
1327 *supportedp = B_TRUE;
1333 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1338 __checkReturn efx_rc_t
1339 efx_mcdi_link_control_supported(
1340 __in efx_nic_t *enp,
1341 __out boolean_t *supportedp)
1343 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1346 if (emcop != NULL) {
1347 if ((rc = emcop->emco_feature_supported(enp,
1348 EFX_MCDI_FEATURE_LINK_CONTROL, supportedp)) != 0)
1351 /* Earlier devices always supported link control */
1352 *supportedp = B_TRUE;
1358 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1363 __checkReturn efx_rc_t
1364 efx_mcdi_mac_spoofing_supported(
1365 __in efx_nic_t *enp,
1366 __out boolean_t *supportedp)
1368 const efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
1371 if (emcop != NULL) {
1372 if ((rc = emcop->emco_feature_supported(enp,
1373 EFX_MCDI_FEATURE_MAC_SPOOFING, supportedp)) != 0)
1376 /* Earlier devices always supported MAC spoofing */
1377 *supportedp = B_TRUE;
1383 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1389 /* Enable logging of some events (e.g. link state changes) */
1390 __checkReturn efx_rc_t
1392 __in efx_nic_t *enp)
1395 uint8_t payload[MAX(MC_CMD_LOG_CTRL_IN_LEN,
1396 MC_CMD_LOG_CTRL_OUT_LEN)];
1399 (void) memset(payload, 0, sizeof (payload));
1400 req.emr_cmd = MC_CMD_LOG_CTRL;
1401 req.emr_in_buf = payload;
1402 req.emr_in_length = MC_CMD_LOG_CTRL_IN_LEN;
1403 req.emr_out_buf = payload;
1404 req.emr_out_length = MC_CMD_LOG_CTRL_OUT_LEN;
1406 MCDI_IN_SET_DWORD(req, LOG_CTRL_IN_LOG_DEST,
1407 MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ);
1408 MCDI_IN_SET_DWORD(req, LOG_CTRL_IN_LOG_DEST_EVQ, 0);
1410 efx_mcdi_execute(enp, &req);
1412 if (req.emr_rc != 0) {
1420 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1426 __checkReturn efx_rc_t
1427 efx_mcdi_set_workaround(
1428 __in efx_nic_t *enp,
1430 __in boolean_t enabled,
1431 __out_opt uint32_t *flagsp)
1434 uint8_t payload[MAX(MC_CMD_WORKAROUND_IN_LEN,
1435 MC_CMD_WORKAROUND_EXT_OUT_LEN)];
1438 (void) memset(payload, 0, sizeof (payload));
1439 req.emr_cmd = MC_CMD_WORKAROUND;
1440 req.emr_in_buf = payload;
1441 req.emr_in_length = MC_CMD_WORKAROUND_IN_LEN;
1442 req.emr_out_buf = payload;
1443 req.emr_out_length = MC_CMD_WORKAROUND_OUT_LEN;
1445 MCDI_IN_SET_DWORD(req, WORKAROUND_IN_TYPE, type);
1446 MCDI_IN_SET_DWORD(req, WORKAROUND_IN_ENABLED, enabled ? 1 : 0);
1448 efx_mcdi_execute_quiet(enp, &req);
1450 if (req.emr_rc != 0) {
1455 if (flagsp != NULL) {
1456 if (req.emr_out_length_used >= MC_CMD_WORKAROUND_EXT_OUT_LEN)
1457 *flagsp = MCDI_OUT_DWORD(req, WORKAROUND_EXT_OUT_FLAGS);
1465 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1471 __checkReturn efx_rc_t
1472 efx_mcdi_get_workarounds(
1473 __in efx_nic_t *enp,
1474 __out_opt uint32_t *implementedp,
1475 __out_opt uint32_t *enabledp)
1478 uint8_t payload[MC_CMD_GET_WORKAROUNDS_OUT_LEN];
1481 (void) memset(payload, 0, sizeof (payload));
1482 req.emr_cmd = MC_CMD_GET_WORKAROUNDS;
1483 req.emr_in_buf = NULL;
1484 req.emr_in_length = 0;
1485 req.emr_out_buf = payload;
1486 req.emr_out_length = MC_CMD_GET_WORKAROUNDS_OUT_LEN;
1488 efx_mcdi_execute(enp, &req);
1490 if (req.emr_rc != 0) {
1495 if (implementedp != NULL) {
1497 MCDI_OUT_DWORD(req, GET_WORKAROUNDS_OUT_IMPLEMENTED);
1500 if (enabledp != NULL) {
1501 *enabledp = MCDI_OUT_DWORD(req, GET_WORKAROUNDS_OUT_ENABLED);
1507 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1513 * Size of media information page in accordance with SFF-8472 and SFF-8436.
1514 * It is used in MCDI interface as well.
1516 #define EFX_PHY_MEDIA_INFO_PAGE_SIZE 0x80
1518 static __checkReturn efx_rc_t
1519 efx_mcdi_get_phy_media_info(
1520 __in efx_nic_t *enp,
1521 __in uint32_t mcdi_page,
1522 __in uint8_t offset,
1524 __out_bcount(len) uint8_t *data)
1527 uint8_t payload[MAX(MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN,
1528 MC_CMD_GET_PHY_MEDIA_INFO_OUT_LEN(
1529 EFX_PHY_MEDIA_INFO_PAGE_SIZE))];
1532 EFSYS_ASSERT((uint32_t)offset + len <= EFX_PHY_MEDIA_INFO_PAGE_SIZE);
1534 (void) memset(payload, 0, sizeof (payload));
1535 req.emr_cmd = MC_CMD_GET_PHY_MEDIA_INFO;
1536 req.emr_in_buf = payload;
1537 req.emr_in_length = MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN;
1538 req.emr_out_buf = payload;
1539 req.emr_out_length =
1540 MC_CMD_GET_PHY_MEDIA_INFO_OUT_LEN(EFX_PHY_MEDIA_INFO_PAGE_SIZE);
1542 MCDI_IN_SET_DWORD(req, GET_PHY_MEDIA_INFO_IN_PAGE, mcdi_page);
1544 efx_mcdi_execute(enp, &req);
1546 if (req.emr_rc != 0) {
1551 if (req.emr_out_length_used !=
1552 MC_CMD_GET_PHY_MEDIA_INFO_OUT_LEN(EFX_PHY_MEDIA_INFO_PAGE_SIZE)) {
1557 if (MCDI_OUT_DWORD(req, GET_PHY_MEDIA_INFO_OUT_DATALEN) !=
1558 EFX_PHY_MEDIA_INFO_PAGE_SIZE) {
1564 MCDI_OUT2(req, uint8_t, GET_PHY_MEDIA_INFO_OUT_DATA) + offset,
1574 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1580 * 2-wire device address of the base information in accordance with SFF-8472
1581 * Diagnostic Monitoring Interface for Optical Transceivers section
1582 * 4 Memory Organization.
1584 #define EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_BASE 0xA0
1587 * 2-wire device address of the digital diagnostics monitoring interface
1588 * in accordance with SFF-8472 Diagnostic Monitoring Interface for Optical
1589 * Transceivers section 4 Memory Organization.
1591 #define EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_DDM 0xA2
1594 * Hard wired 2-wire device address for QSFP+ in accordance with SFF-8436
1595 * QSFP+ 10 Gbs 4X PLUGGABLE TRANSCEIVER section 7.4 Device Addressing and
1598 #define EFX_PHY_MEDIA_INFO_DEV_ADDR_QSFP 0xA0
1600 __checkReturn efx_rc_t
1601 efx_mcdi_phy_module_get_info(
1602 __in efx_nic_t *enp,
1603 __in uint8_t dev_addr,
1604 __in uint8_t offset,
1606 __out_bcount(len) uint8_t *data)
1608 efx_port_t *epp = &(enp->en_port);
1610 uint32_t mcdi_lower_page;
1611 uint32_t mcdi_upper_page;
1613 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
1616 * Map device address to MC_CMD_GET_PHY_MEDIA_INFO pages.
1617 * Offset plus length interface allows to access page 0 only.
1618 * I.e. non-zero upper pages are not accessible.
1619 * See SFF-8472 section 4 Memory Organization and SFF-8436 section 7.6
1620 * QSFP+ Memory Map for details on how information is structured
1623 switch (epp->ep_fixed_port_type) {
1624 case EFX_PHY_MEDIA_SFP_PLUS:
1626 * In accordance with SFF-8472 Diagnostic Monitoring
1627 * Interface for Optical Transceivers section 4 Memory
1628 * Organization two 2-wire addresses are defined.
1631 /* Base information */
1632 case EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_BASE:
1634 * MCDI page 0 should be used to access lower
1635 * page 0 (0x00 - 0x7f) at the device address 0xA0.
1637 mcdi_lower_page = 0;
1639 * MCDI page 1 should be used to access upper
1640 * page 0 (0x80 - 0xff) at the device address 0xA0.
1642 mcdi_upper_page = 1;
1645 case EFX_PHY_MEDIA_INFO_DEV_ADDR_SFP_DDM:
1647 * MCDI page 2 should be used to access lower
1648 * page 0 (0x00 - 0x7f) at the device address 0xA2.
1650 mcdi_lower_page = 2;
1652 * MCDI page 3 should be used to access upper
1653 * page 0 (0x80 - 0xff) at the device address 0xA2.
1655 mcdi_upper_page = 3;
1662 case EFX_PHY_MEDIA_QSFP_PLUS:
1664 case EFX_PHY_MEDIA_INFO_DEV_ADDR_QSFP:
1666 * MCDI page -1 should be used to access lower page 0
1669 mcdi_lower_page = (uint32_t)-1;
1671 * MCDI page 0 should be used to access upper page 0
1674 mcdi_upper_page = 0;
1686 if (offset < EFX_PHY_MEDIA_INFO_PAGE_SIZE) {
1688 MIN(len, EFX_PHY_MEDIA_INFO_PAGE_SIZE - offset);
1690 rc = efx_mcdi_get_phy_media_info(enp,
1691 mcdi_lower_page, offset, read_len, data);
1700 offset -= EFX_PHY_MEDIA_INFO_PAGE_SIZE;
1704 EFSYS_ASSERT3U(len, <=, EFX_PHY_MEDIA_INFO_PAGE_SIZE);
1705 EFSYS_ASSERT3U(offset, <, EFX_PHY_MEDIA_INFO_PAGE_SIZE);
1707 rc = efx_mcdi_get_phy_media_info(enp,
1708 mcdi_upper_page, offset, len, data);
1720 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1725 #endif /* EFSYS_OPT_MCDI */