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.
34 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
38 __in uint32_t mcdi_cap,
39 __out uint32_t *maskp)
44 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
45 mask |= (1 << EFX_PHY_CAP_10HDX);
46 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
47 mask |= (1 << EFX_PHY_CAP_10FDX);
48 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
49 mask |= (1 << EFX_PHY_CAP_100HDX);
50 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
51 mask |= (1 << EFX_PHY_CAP_100FDX);
52 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
53 mask |= (1 << EFX_PHY_CAP_1000HDX);
54 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
55 mask |= (1 << EFX_PHY_CAP_1000FDX);
56 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
57 mask |= (1 << EFX_PHY_CAP_10000FDX);
58 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
59 mask |= (1 << EFX_PHY_CAP_40000FDX);
60 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
61 mask |= (1 << EFX_PHY_CAP_PAUSE);
62 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
63 mask |= (1 << EFX_PHY_CAP_ASYM);
64 if (mcdi_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
65 mask |= (1 << EFX_PHY_CAP_AN);
71 mcdi_phy_decode_link_mode(
73 __in uint32_t link_flags,
74 __in unsigned int speed,
75 __in unsigned int fcntl,
76 __out efx_link_mode_t *link_modep,
77 __out unsigned int *fcntlp)
79 boolean_t fd = !!(link_flags &
80 (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN));
81 boolean_t up = !!(link_flags &
82 (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN));
87 *link_modep = EFX_LINK_DOWN;
88 else if (speed == 40000 && fd)
89 *link_modep = EFX_LINK_40000FDX;
90 else if (speed == 10000 && fd)
91 *link_modep = EFX_LINK_10000FDX;
92 else if (speed == 1000)
93 *link_modep = fd ? EFX_LINK_1000FDX : EFX_LINK_1000HDX;
94 else if (speed == 100)
95 *link_modep = fd ? EFX_LINK_100FDX : EFX_LINK_100HDX;
97 *link_modep = fd ? EFX_LINK_10FDX : EFX_LINK_10HDX;
99 *link_modep = EFX_LINK_UNKNOWN;
101 if (fcntl == MC_CMD_FCNTL_OFF)
103 else if (fcntl == MC_CMD_FCNTL_RESPOND)
104 *fcntlp = EFX_FCNTL_RESPOND;
105 else if (fcntl == MC_CMD_FCNTL_GENERATE)
106 *fcntlp = EFX_FCNTL_GENERATE;
107 else if (fcntl == MC_CMD_FCNTL_BIDIR)
108 *fcntlp = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
110 EFSYS_PROBE1(mc_pcol_error, int, fcntl);
119 __in efx_qword_t *eqp,
120 __out efx_link_mode_t *link_modep)
122 efx_port_t *epp = &(enp->en_port);
123 unsigned int link_flags;
126 efx_link_mode_t link_mode;
127 uint32_t lp_cap_mask;
130 * Convert the LINKCHANGE speed enumeration into mbit/s, in the
131 * same way as GET_LINK encodes the speed
133 switch (MCDI_EV_FIELD(eqp, LINKCHANGE_SPEED)) {
134 case MCDI_EVENT_LINKCHANGE_SPEED_100M:
137 case MCDI_EVENT_LINKCHANGE_SPEED_1G:
140 case MCDI_EVENT_LINKCHANGE_SPEED_10G:
143 case MCDI_EVENT_LINKCHANGE_SPEED_40G:
151 link_flags = MCDI_EV_FIELD(eqp, LINKCHANGE_LINK_FLAGS);
152 mcdi_phy_decode_link_mode(enp, link_flags, speed,
153 MCDI_EV_FIELD(eqp, LINKCHANGE_FCNTL),
155 mcdi_phy_decode_cap(MCDI_EV_FIELD(eqp, LINKCHANGE_LP_CAP),
159 * It's safe to update ep_lp_cap_mask without the driver's port lock
160 * because presumably any concurrently running efx_port_poll() is
161 * only going to arrive at the same value.
163 * ep_fcntl has two meanings. It's either the link common fcntl
164 * (if the PHY supports AN), or it's the forced link state. If
165 * the former, it's safe to update the value for the same reason as
166 * for ep_lp_cap_mask. If the latter, then just ignore the value,
167 * because we can race with efx_mac_fcntl_set().
169 epp->ep_lp_cap_mask = lp_cap_mask;
170 epp->ep_fcntl = fcntl;
172 *link_modep = link_mode;
175 __checkReturn efx_rc_t
178 __in boolean_t power)
185 /* Check if the PHY is a zombie */
186 if ((rc = ef10_phy_verify(enp)) != 0)
189 enp->en_reset_flags |= EFX_RESET_PHY;
194 EFSYS_PROBE1(fail1, efx_rc_t, rc);
199 __checkReturn efx_rc_t
202 __out ef10_link_state_t *elsp)
205 uint8_t payload[MAX(MC_CMD_GET_LINK_IN_LEN,
206 MC_CMD_GET_LINK_OUT_LEN)];
209 (void) memset(payload, 0, sizeof (payload));
210 req.emr_cmd = MC_CMD_GET_LINK;
211 req.emr_in_buf = payload;
212 req.emr_in_length = MC_CMD_GET_LINK_IN_LEN;
213 req.emr_out_buf = payload;
214 req.emr_out_length = MC_CMD_GET_LINK_OUT_LEN;
216 efx_mcdi_execute(enp, &req);
218 if (req.emr_rc != 0) {
223 if (req.emr_out_length_used < MC_CMD_GET_LINK_OUT_LEN) {
228 mcdi_phy_decode_cap(MCDI_OUT_DWORD(req, GET_LINK_OUT_CAP),
229 &elsp->els_adv_cap_mask);
230 mcdi_phy_decode_cap(MCDI_OUT_DWORD(req, GET_LINK_OUT_LP_CAP),
231 &elsp->els_lp_cap_mask);
233 mcdi_phy_decode_link_mode(enp, MCDI_OUT_DWORD(req, GET_LINK_OUT_FLAGS),
234 MCDI_OUT_DWORD(req, GET_LINK_OUT_LINK_SPEED),
235 MCDI_OUT_DWORD(req, GET_LINK_OUT_FCNTL),
236 &elsp->els_link_mode, &elsp->els_fcntl);
238 elsp->els_mac_up = MCDI_OUT_DWORD(req, GET_LINK_OUT_MAC_FAULT) == 0;
245 EFSYS_PROBE1(fail1, efx_rc_t, rc);
250 __checkReturn efx_rc_t
251 ef10_phy_reconfigure(
254 efx_port_t *epp = &(enp->en_port);
256 uint8_t payload[MAX(MC_CMD_SET_LINK_IN_LEN,
257 MC_CMD_SET_LINK_OUT_LEN)];
259 unsigned int led_mode;
264 if ((rc = efx_mcdi_link_control_supported(enp, &supported)) != 0)
266 if (supported == B_FALSE)
269 (void) memset(payload, 0, sizeof (payload));
270 req.emr_cmd = MC_CMD_SET_LINK;
271 req.emr_in_buf = payload;
272 req.emr_in_length = MC_CMD_SET_LINK_IN_LEN;
273 req.emr_out_buf = payload;
274 req.emr_out_length = MC_CMD_SET_LINK_OUT_LEN;
276 cap_mask = epp->ep_adv_cap_mask;
277 MCDI_IN_POPULATE_DWORD_10(req, SET_LINK_IN_CAP,
278 PHY_CAP_10HDX, (cap_mask >> EFX_PHY_CAP_10HDX) & 0x1,
279 PHY_CAP_10FDX, (cap_mask >> EFX_PHY_CAP_10FDX) & 0x1,
280 PHY_CAP_100HDX, (cap_mask >> EFX_PHY_CAP_100HDX) & 0x1,
281 PHY_CAP_100FDX, (cap_mask >> EFX_PHY_CAP_100FDX) & 0x1,
282 PHY_CAP_1000HDX, (cap_mask >> EFX_PHY_CAP_1000HDX) & 0x1,
283 PHY_CAP_1000FDX, (cap_mask >> EFX_PHY_CAP_1000FDX) & 0x1,
284 PHY_CAP_10000FDX, (cap_mask >> EFX_PHY_CAP_10000FDX) & 0x1,
285 PHY_CAP_PAUSE, (cap_mask >> EFX_PHY_CAP_PAUSE) & 0x1,
286 PHY_CAP_ASYM, (cap_mask >> EFX_PHY_CAP_ASYM) & 0x1,
287 PHY_CAP_AN, (cap_mask >> EFX_PHY_CAP_AN) & 0x1);
288 /* Too many fields for for POPULATE macros, so insert this afterwards */
289 MCDI_IN_SET_DWORD_FIELD(req, SET_LINK_IN_CAP,
290 PHY_CAP_40000FDX, (cap_mask >> EFX_PHY_CAP_40000FDX) & 0x1);
292 MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_MODE, MC_CMD_LOOPBACK_NONE);
294 MCDI_IN_SET_DWORD(req, SET_LINK_IN_LOOPBACK_SPEED, speed);
296 MCDI_IN_SET_DWORD(req, SET_LINK_IN_FLAGS, 0);
298 efx_mcdi_execute(enp, &req);
300 if (req.emr_rc != 0) {
305 /* And set the blink mode */
306 (void) memset(payload, 0, sizeof (payload));
307 req.emr_cmd = MC_CMD_SET_ID_LED;
308 req.emr_in_buf = payload;
309 req.emr_in_length = MC_CMD_SET_ID_LED_IN_LEN;
310 req.emr_out_buf = payload;
311 req.emr_out_length = MC_CMD_SET_ID_LED_OUT_LEN;
313 MCDI_IN_SET_DWORD(req, SET_ID_LED_IN_STATE, MC_CMD_LED_DEFAULT);
315 efx_mcdi_execute(enp, &req);
317 if (req.emr_rc != 0) {
329 EFSYS_PROBE1(fail1, efx_rc_t, rc);
334 __checkReturn efx_rc_t
339 uint8_t payload[MAX(MC_CMD_GET_PHY_STATE_IN_LEN,
340 MC_CMD_GET_PHY_STATE_OUT_LEN)];
344 (void) memset(payload, 0, sizeof (payload));
345 req.emr_cmd = MC_CMD_GET_PHY_STATE;
346 req.emr_in_buf = payload;
347 req.emr_in_length = MC_CMD_GET_PHY_STATE_IN_LEN;
348 req.emr_out_buf = payload;
349 req.emr_out_length = MC_CMD_GET_PHY_STATE_OUT_LEN;
351 efx_mcdi_execute(enp, &req);
353 if (req.emr_rc != 0) {
358 if (req.emr_out_length_used < MC_CMD_GET_PHY_STATE_OUT_LEN) {
363 state = MCDI_OUT_DWORD(req, GET_PHY_STATE_OUT_STATE);
364 if (state != MC_CMD_PHY_STATE_OK) {
365 if (state != MC_CMD_PHY_STATE_ZOMBIE)
366 EFSYS_PROBE1(mc_pcol_error, int, state);
378 EFSYS_PROBE1(fail1, efx_rc_t, rc);
383 __checkReturn efx_rc_t
386 __out uint32_t *ouip)
388 _NOTE(ARGUNUSED(enp, ouip))
393 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */