2 * Copyright (c) 2012-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.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
37 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
41 __in uint32_t mcdi_cap,
42 __out uint32_t *maskp)
47 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
48 mask |= (1 << EFX_PHY_CAP_10HDX);
49 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
50 mask |= (1 << EFX_PHY_CAP_10FDX);
51 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
52 mask |= (1 << EFX_PHY_CAP_100HDX);
53 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
54 mask |= (1 << EFX_PHY_CAP_100FDX);
55 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
56 mask |= (1 << EFX_PHY_CAP_1000HDX);
57 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
58 mask |= (1 << EFX_PHY_CAP_1000FDX);
59 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
60 mask |= (1 << EFX_PHY_CAP_10000FDX);
61 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
62 mask |= (1 << EFX_PHY_CAP_40000FDX);
63 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
64 mask |= (1 << EFX_PHY_CAP_PAUSE);
65 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
66 mask |= (1 << EFX_PHY_CAP_ASYM);
67 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
68 mask |= (1 << EFX_PHY_CAP_AN);
74 mcdi_phy_decode_link_mode(
76 __in uint32_t link_flags,
77 __in unsigned int speed,
78 __in unsigned int fcntl,
79 __out efx_link_mode_t *link_modep,
80 __out unsigned int *fcntlp)
82 boolean_t fd = !!(link_flags &
83 (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN));
84 boolean_t up = !!(link_flags &
85 (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN));
90 *link_modep = EFX_LINK_DOWN;
91 else if (speed == 40000 && fd)
92 *link_modep = EFX_LINK_40000FDX;
93 else if (speed == 10000 && fd)
94 *link_modep = EFX_LINK_10000FDX;
95 else if (speed == 1000)
96 *link_modep = fd ? EFX_LINK_1000FDX : EFX_LINK_1000HDX;
97 else if (speed == 100)
98 *link_modep = fd ? EFX_LINK_100FDX : EFX_LINK_100HDX;
100 *link_modep = fd ? EFX_LINK_10FDX : EFX_LINK_10HDX;
102 *link_modep = EFX_LINK_UNKNOWN;
104 if (fcntl == MC_CMD_FCNTL_OFF)
106 else if (fcntl == MC_CMD_FCNTL_RESPOND)
107 *fcntlp = EFX_FCNTL_RESPOND;
108 else if (fcntl == MC_CMD_FCNTL_GENERATE)
109 *fcntlp = EFX_FCNTL_GENERATE;
110 else if (fcntl == MC_CMD_FCNTL_BIDIR)
111 *fcntlp = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
113 EFSYS_PROBE1(mc_pcol_error, int, fcntl);
122 __in efx_qword_t *eqp,
123 __out efx_link_mode_t *link_modep)
125 efx_port_t *epp = &(enp->en_port);
126 unsigned int link_flags;
129 efx_link_mode_t link_mode;
130 uint32_t lp_cap_mask;
133 * Convert the LINKCHANGE speed enumeration into mbit/s, in the
134 * same way as GET_LINK encodes the speed
136 switch (MCDI_EV_FIELD(eqp, LINKCHANGE_SPEED)) {
137 case MCDI_EVENT_LINKCHANGE_SPEED_100M:
140 case MCDI_EVENT_LINKCHANGE_SPEED_1G:
143 case MCDI_EVENT_LINKCHANGE_SPEED_10G:
146 case MCDI_EVENT_LINKCHANGE_SPEED_40G:
154 link_flags = MCDI_EV_FIELD(eqp, LINKCHANGE_LINK_FLAGS);
155 mcdi_phy_decode_link_mode(enp, link_flags, speed,
156 MCDI_EV_FIELD(eqp, LINKCHANGE_FCNTL),
158 mcdi_phy_decode_cap(MCDI_EV_FIELD(eqp, LINKCHANGE_LP_CAP),
162 * It's safe to update ep_lp_cap_mask without the driver's port lock
163 * because presumably any concurrently running efx_port_poll() is
164 * only going to arrive at the same value.
166 * ep_fcntl has two meanings. It's either the link common fcntl
167 * (if the PHY supports AN), or it's the forced link state. If
168 * the former, it's safe to update the value for the same reason as
169 * for ep_lp_cap_mask. If the latter, then just ignore the value,
170 * because we can race with efx_mac_fcntl_set().
172 epp->ep_lp_cap_mask = lp_cap_mask;
173 epp->ep_fcntl = fcntl;
175 *link_modep = link_mode;
178 __checkReturn efx_rc_t
181 __in boolean_t power)
188 /* Check if the PHY is a zombie */
189 if ((rc = ef10_phy_verify(enp)) != 0)
192 enp->en_reset_flags |= EFX_RESET_PHY;
197 EFSYS_PROBE1(fail1, efx_rc_t, rc);
202 __checkReturn efx_rc_t
205 __out ef10_link_state_t *elsp)
208 uint8_t payload[MAX(MC_CMD_GET_LINK_IN_LEN,
209 MC_CMD_GET_LINK_OUT_LEN)];
212 (void) memset(payload, 0, sizeof (payload));
213 req.emr_cmd = MC_CMD_GET_LINK;
214 req.emr_in_buf = payload;
215 req.emr_in_length = MC_CMD_GET_LINK_IN_LEN;
216 req.emr_out_buf = payload;
217 req.emr_out_length = MC_CMD_GET_LINK_OUT_LEN;
219 efx_mcdi_execute(enp, &req);
221 if (req.emr_rc != 0) {
226 if (req.emr_out_length_used < MC_CMD_GET_LINK_OUT_LEN) {
231 mcdi_phy_decode_cap(MCDI_OUT_DWORD(req, GET_LINK_OUT_CAP),
232 &elsp->els_adv_cap_mask);
233 mcdi_phy_decode_cap(MCDI_OUT_DWORD(req, GET_LINK_OUT_LP_CAP),
234 &elsp->els_lp_cap_mask);
236 mcdi_phy_decode_link_mode(enp, MCDI_OUT_DWORD(req, GET_LINK_OUT_FLAGS),
237 MCDI_OUT_DWORD(req, GET_LINK_OUT_LINK_SPEED),
238 MCDI_OUT_DWORD(req, GET_LINK_OUT_FCNTL),
239 &elsp->els_link_mode, &elsp->els_fcntl);
241 #if EFSYS_OPT_LOOPBACK
242 /* Assert the MC_CMD_LOOPBACK and EFX_LOOPBACK namespace agree */
243 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_NONE == EFX_LOOPBACK_OFF);
244 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_DATA == EFX_LOOPBACK_DATA);
245 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GMAC == EFX_LOOPBACK_GMAC);
246 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XGMII == EFX_LOOPBACK_XGMII);
247 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XGXS == EFX_LOOPBACK_XGXS);
248 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XAUI == EFX_LOOPBACK_XAUI);
249 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GMII == EFX_LOOPBACK_GMII);
250 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_SGMII == EFX_LOOPBACK_SGMII);
251 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XGBR == EFX_LOOPBACK_XGBR);
252 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XFI == EFX_LOOPBACK_XFI);
253 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XAUI_FAR == EFX_LOOPBACK_XAUI_FAR);
254 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GMII_FAR == EFX_LOOPBACK_GMII_FAR);
255 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_SGMII_FAR == EFX_LOOPBACK_SGMII_FAR);
256 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_XFI_FAR == EFX_LOOPBACK_XFI_FAR);
257 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_GPHY == EFX_LOOPBACK_GPHY);
258 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_PHYXS == EFX_LOOPBACK_PHY_XS);
259 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_PCS == EFX_LOOPBACK_PCS);
260 EFX_STATIC_ASSERT(MC_CMD_LOOPBACK_PMAPMD == EFX_LOOPBACK_PMA_PMD);
262 elsp->els_loopback = MCDI_OUT_DWORD(req, GET_LINK_OUT_LOOPBACK_MODE);
263 #endif /* EFSYS_OPT_LOOPBACK */
265 elsp->els_mac_up = MCDI_OUT_DWORD(req, GET_LINK_OUT_MAC_FAULT) == 0;
272 EFSYS_PROBE1(fail1, efx_rc_t, rc);
277 __checkReturn efx_rc_t
278 ef10_phy_reconfigure(
281 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
282 efx_port_t *epp = &(enp->en_port);
284 uint8_t payload[MAX(MC_CMD_SET_LINK_IN_LEN,
285 MC_CMD_SET_LINK_OUT_LEN)];
287 unsigned int led_mode;
291 if (~encp->enc_func_flags & EFX_NIC_FUNC_LINKCTRL)
294 (void) memset(payload, 0, sizeof (payload));
295 req.emr_cmd = MC_CMD_SET_LINK;
296 req.emr_in_buf = payload;
297 req.emr_in_length = MC_CMD_SET_LINK_IN_LEN;
298 req.emr_out_buf = payload;
299 req.emr_out_length = MC_CMD_SET_LINK_OUT_LEN;
301 cap_mask = epp->ep_adv_cap_mask;
302 MCDI_IN_POPULATE_DWORD_10(req, SET_LINK_IN_CAP,
303 PHY_CAP_10HDX, (cap_mask >> EFX_PHY_CAP_10HDX) & 0x1,
304 PHY_CAP_10FDX, (cap_mask >> EFX_PHY_CAP_10FDX) & 0x1,
305 PHY_CAP_100HDX, (cap_mask >> EFX_PHY_CAP_100HDX) & 0x1,
306 PHY_CAP_100FDX, (cap_mask >> EFX_PHY_CAP_100FDX) & 0x1,
307 PHY_CAP_1000HDX, (cap_mask >> EFX_PHY_CAP_1000HDX) & 0x1,
308 PHY_CAP_1000FDX, (cap_mask >> EFX_PHY_CAP_1000FDX) & 0x1,
309 PHY_CAP_10000FDX, (cap_mask >> EFX_PHY_CAP_10000FDX) & 0x1,
310 PHY_CAP_PAUSE, (cap_mask >> EFX_PHY_CAP_PAUSE) & 0x1,
311 PHY_CAP_ASYM, (cap_mask >> EFX_PHY_CAP_ASYM) & 0x1,
312 PHY_CAP_AN, (cap_mask >> EFX_PHY_CAP_AN) & 0x1);
313 /* Too many fields for for POPULATE macros, so insert this afterwards */
314 MCDI_IN_SET_DWORD_FIELD(req, SET_LINK_IN_CAP,
315 PHY_CAP_40000FDX, (cap_mask >> EFX_PHY_CAP_40000FDX) & 0x1);
317 #if EFSYS_OPT_LOOPBACK
318 MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_MODE,
319 epp->ep_loopback_type);
320 switch (epp->ep_loopback_link_mode) {
321 case EFX_LINK_100FDX:
324 case EFX_LINK_1000FDX:
327 case EFX_LINK_10000FDX:
330 case EFX_LINK_40000FDX:
337 MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_MODE, MC_CMD_LOOPBACK_NONE);
339 #endif /* EFSYS_OPT_LOOPBACK */
340 MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_SPEED, speed);
342 #if EFSYS_OPT_PHY_FLAGS
343 MCDI_IN_SET_DWORD(req, SET_LINK_IN_FLAGS, epp->ep_phy_flags);
345 MCDI_IN_SET_DWORD(req, SET_LINK_IN_FLAGS, 0);
346 #endif /* EFSYS_OPT_PHY_FLAGS */
348 efx_mcdi_execute(enp, &req);
350 if (req.emr_rc != 0) {
355 /* And set the blink mode */
356 (void) memset(payload, 0, sizeof (payload));
357 req.emr_cmd = MC_CMD_SET_ID_LED;
358 req.emr_in_buf = payload;
359 req.emr_in_length = MC_CMD_SET_ID_LED_IN_LEN;
360 req.emr_out_buf = payload;
361 req.emr_out_length = MC_CMD_SET_ID_LED_OUT_LEN;
363 #if EFSYS_OPT_PHY_LED_CONTROL
364 switch (epp->ep_phy_led_mode) {
365 case EFX_PHY_LED_DEFAULT:
366 led_mode = MC_CMD_LED_DEFAULT;
368 case EFX_PHY_LED_OFF:
369 led_mode = MC_CMD_LED_OFF;
372 led_mode = MC_CMD_LED_ON;
376 led_mode = MC_CMD_LED_DEFAULT;
379 MCDI_IN_SET_DWORD(req, SET_ID_LED_IN_STATE, led_mode);
381 MCDI_IN_SET_DWORD(req, SET_ID_LED_IN_STATE, MC_CMD_LED_DEFAULT);
382 #endif /* EFSYS_OPT_PHY_LED_CONTROL */
384 efx_mcdi_execute(enp, &req);
386 if (req.emr_rc != 0) {
396 EFSYS_PROBE1(fail1, efx_rc_t, rc);
401 __checkReturn efx_rc_t
406 uint8_t payload[MAX(MC_CMD_GET_PHY_STATE_IN_LEN,
407 MC_CMD_GET_PHY_STATE_OUT_LEN)];
411 (void) memset(payload, 0, sizeof (payload));
412 req.emr_cmd = MC_CMD_GET_PHY_STATE;
413 req.emr_in_buf = payload;
414 req.emr_in_length = MC_CMD_GET_PHY_STATE_IN_LEN;
415 req.emr_out_buf = payload;
416 req.emr_out_length = MC_CMD_GET_PHY_STATE_OUT_LEN;
418 efx_mcdi_execute(enp, &req);
420 if (req.emr_rc != 0) {
425 if (req.emr_out_length_used < MC_CMD_GET_PHY_STATE_OUT_LEN) {
430 state = MCDI_OUT_DWORD(req, GET_PHY_STATE_OUT_STATE);
431 if (state != MC_CMD_PHY_STATE_OK) {
432 if (state != MC_CMD_PHY_STATE_ZOMBIE)
433 EFSYS_PROBE1(mc_pcol_error, int, state);
445 EFSYS_PROBE1(fail1, efx_rc_t, rc);
450 __checkReturn efx_rc_t
453 __out uint32_t *ouip)
455 _NOTE(ARGUNUSED(enp, ouip))
460 #if EFSYS_OPT_PHY_STATS
462 __checkReturn efx_rc_t
463 ef10_phy_stats_update(
465 __in efsys_mem_t *esmp,
466 __inout_ecount(EFX_PHY_NSTATS) uint32_t *stat)
468 /* TBD: no stats support in firmware yet */
469 _NOTE(ARGUNUSED(enp, esmp))
470 memset(stat, 0, EFX_PHY_NSTATS * sizeof (*stat));
475 #endif /* EFSYS_OPT_PHY_STATS */
477 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */