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.
35 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
37 __checkReturn efx_rc_t
40 __out efx_link_mode_t *link_modep)
42 efx_port_t *epp = &(enp->en_port);
43 ef10_link_state_t els;
46 if ((rc = ef10_phy_get_link(enp, &els)) != 0)
49 epp->ep_adv_cap_mask = els.els_adv_cap_mask;
50 epp->ep_fcntl = els.els_fcntl;
52 *link_modep = els.els_link_mode;
57 EFSYS_PROBE1(fail1, efx_rc_t, rc);
59 *link_modep = EFX_LINK_UNKNOWN;
64 __checkReturn efx_rc_t
67 __out boolean_t *mac_upp)
69 ef10_link_state_t els;
73 * Because EF10 doesn't *require* polling, we can't rely on
74 * ef10_mac_poll() being executed to populate epp->ep_mac_up.
76 if ((rc = ef10_phy_get_link(enp, &els)) != 0)
79 *mac_upp = els.els_mac_up;
84 EFSYS_PROBE1(fail1, efx_rc_t, rc);
90 * EF10 adapters use MC_CMD_VADAPTOR_SET_MAC to set the
91 * MAC address; the address field in MC_CMD_SET_MAC has no
93 * MC_CMD_VADAPTOR_SET_MAC requires mac-spoofing privilege and
94 * the port to have no filters or queues active.
96 static __checkReturn efx_rc_t
97 efx_mcdi_vadapter_set_mac(
100 efx_port_t *epp = &(enp->en_port);
102 uint8_t payload[MAX(MC_CMD_VADAPTOR_SET_MAC_IN_LEN,
103 MC_CMD_VADAPTOR_SET_MAC_OUT_LEN)];
106 (void) memset(payload, 0, sizeof (payload));
107 req.emr_cmd = MC_CMD_VADAPTOR_SET_MAC;
108 req.emr_in_buf = payload;
109 req.emr_in_length = MC_CMD_VADAPTOR_SET_MAC_IN_LEN;
110 req.emr_out_buf = payload;
111 req.emr_out_length = MC_CMD_VADAPTOR_SET_MAC_OUT_LEN;
113 MCDI_IN_SET_DWORD(req, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
115 EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t, VADAPTOR_SET_MAC_IN_MACADDR),
118 efx_mcdi_execute(enp, &req);
120 if (req.emr_rc != 0) {
128 EFSYS_PROBE1(fail1, efx_rc_t, rc);
133 __checkReturn efx_rc_t
139 if ((rc = efx_mcdi_vadapter_set_mac(enp)) != 0) {
144 * Fallback for older Huntington firmware without Vadapter
147 if ((rc = ef10_mac_reconfigure(enp)) != 0)
157 EFSYS_PROBE1(fail1, efx_rc_t, rc);
162 static __checkReturn efx_rc_t
168 uint8_t payload[MAX(MC_CMD_SET_MAC_EXT_IN_LEN,
169 MC_CMD_SET_MAC_OUT_LEN)];
172 (void) memset(payload, 0, sizeof (payload));
173 req.emr_cmd = MC_CMD_SET_MAC;
174 req.emr_in_buf = payload;
175 req.emr_in_length = MC_CMD_SET_MAC_EXT_IN_LEN;
176 req.emr_out_buf = payload;
177 req.emr_out_length = MC_CMD_SET_MAC_OUT_LEN;
179 /* Only configure the MTU in this call to MC_CMD_SET_MAC */
180 MCDI_IN_SET_DWORD(req, SET_MAC_EXT_IN_MTU, mtu);
181 MCDI_IN_POPULATE_DWORD_1(req, SET_MAC_EXT_IN_CONTROL,
182 SET_MAC_EXT_IN_CFG_MTU, 1);
184 efx_mcdi_execute(enp, &req);
186 if (req.emr_rc != 0) {
194 EFSYS_PROBE1(fail1, efx_rc_t, rc);
199 static __checkReturn efx_rc_t
205 uint8_t payload[MAX(MC_CMD_SET_MAC_EXT_IN_LEN,
206 MC_CMD_SET_MAC_V2_OUT_LEN)];
209 (void) memset(payload, 0, sizeof (payload));
210 req.emr_cmd = MC_CMD_SET_MAC;
211 req.emr_in_buf = payload;
212 req.emr_in_length = MC_CMD_SET_MAC_EXT_IN_LEN;
213 req.emr_out_buf = payload;
214 req.emr_out_length = MC_CMD_SET_MAC_V2_OUT_LEN;
217 * With MC_CMD_SET_MAC_EXT_IN_CONTROL set to 0, this just queries the
218 * MTU. This should always be supported on Medford, but it is not
219 * supported on older Huntington firmware.
221 MCDI_IN_SET_DWORD(req, SET_MAC_EXT_IN_CONTROL, 0);
223 efx_mcdi_execute(enp, &req);
225 if (req.emr_rc != 0) {
229 if (req.emr_out_length_used < MC_CMD_SET_MAC_V2_OUT_MTU_OFST + 4) {
234 *mtu = MCDI_OUT_DWORD(req, SET_MAC_V2_OUT_MTU);
241 EFSYS_PROBE1(fail1, efx_rc_t, rc);
246 __checkReturn efx_rc_t
250 efx_port_t *epp = &(enp->en_port);
251 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
254 if (encp->enc_enhanced_set_mac_supported) {
255 if ((rc = efx_mcdi_mtu_set(enp, epp->ep_mac_pdu)) != 0)
259 * Fallback for older Huntington firmware, which always
260 * configure all of the parameters to MC_CMD_SET_MAC. This isn't
261 * suitable for setting the MTU on unpriviliged functions.
263 if ((rc = ef10_mac_reconfigure(enp)) != 0)
272 EFSYS_PROBE1(fail1, efx_rc_t, rc);
277 __checkReturn efx_rc_t
284 if ((rc = efx_mcdi_mtu_get(enp, pdu)) != 0)
290 EFSYS_PROBE1(fail1, efx_rc_t, rc);
295 __checkReturn efx_rc_t
296 ef10_mac_reconfigure(
299 efx_port_t *epp = &(enp->en_port);
301 uint8_t payload[MAX(MC_CMD_SET_MAC_IN_LEN,
302 MC_CMD_SET_MAC_OUT_LEN)];
305 (void) memset(payload, 0, sizeof (payload));
306 req.emr_cmd = MC_CMD_SET_MAC;
307 req.emr_in_buf = payload;
308 req.emr_in_length = MC_CMD_SET_MAC_IN_LEN;
309 req.emr_out_buf = payload;
310 req.emr_out_length = MC_CMD_SET_MAC_OUT_LEN;
312 MCDI_IN_SET_DWORD(req, SET_MAC_IN_MTU, epp->ep_mac_pdu);
313 MCDI_IN_SET_DWORD(req, SET_MAC_IN_DRAIN, epp->ep_mac_drain ? 1 : 0);
314 EFX_MAC_ADDR_COPY(MCDI_IN2(req, uint8_t, SET_MAC_IN_ADDR),
318 * Note: The Huntington MAC does not support REJECT_BRDCST.
319 * The REJECT_UNCST flag will also prevent multicast traffic
320 * from reaching the filters. As Huntington filters drop any
321 * traffic that does not match a filter it is ok to leave the
322 * MAC running in promiscuous mode. See bug41141.
324 * FIXME: Does REJECT_UNCST behave the same way on Medford?
326 MCDI_IN_POPULATE_DWORD_2(req, SET_MAC_IN_REJECT,
327 SET_MAC_IN_REJECT_UNCST, 0,
328 SET_MAC_IN_REJECT_BRDCST, 0);
331 * Flow control, whether it is auto-negotiated or not,
332 * is set via the PHY advertised capabilities. When set to
333 * automatic the MAC will use the PHY settings to determine
334 * the flow control settings.
336 MCDI_IN_SET_DWORD(req, SET_MAC_IN_FCNTL, MC_CMD_FCNTL_AUTO);
338 /* Do not include the Ethernet frame checksum in RX packets */
339 MCDI_IN_POPULATE_DWORD_1(req, SET_MAC_IN_FLAGS,
340 SET_MAC_IN_FLAG_INCLUDE_FCS, 0);
342 efx_mcdi_execute_quiet(enp, &req);
344 if (req.emr_rc != 0) {
346 * Unprivileged functions cannot control link state,
347 * but still need to configure filters.
349 if (req.emr_rc != EACCES) {
356 * Apply the filters for the MAC configuration.
357 * If the NIC isn't ready to accept filters this may
358 * return success without setting anything.
360 rc = efx_filter_reconfigure(enp, epp->ep_mac_addr,
361 epp->ep_all_unicst, epp->ep_mulcst,
362 epp->ep_all_mulcst, epp->ep_brdcst,
363 epp->ep_mulcst_addr_list,
364 epp->ep_mulcst_addr_count);
369 EFSYS_PROBE1(fail1, efx_rc_t, rc);
374 __checkReturn efx_rc_t
375 ef10_mac_multicast_list_set(
378 efx_port_t *epp = &(enp->en_port);
379 const efx_mac_ops_t *emop = epp->ep_emop;
382 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
383 enp->en_family == EFX_FAMILY_MEDFORD);
385 if ((rc = emop->emo_reconfigure(enp)) != 0)
391 EFSYS_PROBE1(fail1, efx_rc_t, rc);
396 __checkReturn efx_rc_t
397 ef10_mac_filter_default_rxq_set(
400 __in boolean_t using_rss)
402 efx_port_t *epp = &(enp->en_port);
404 boolean_t old_using_rss;
407 ef10_filter_get_default_rxq(enp, &old_rxq, &old_using_rss);
409 ef10_filter_default_rxq_set(enp, erp, using_rss);
411 rc = efx_filter_reconfigure(enp, epp->ep_mac_addr,
412 epp->ep_all_unicst, epp->ep_mulcst,
413 epp->ep_all_mulcst, epp->ep_brdcst,
414 epp->ep_mulcst_addr_list,
415 epp->ep_mulcst_addr_count);
423 EFSYS_PROBE1(fail1, efx_rc_t, rc);
425 ef10_filter_default_rxq_set(enp, old_rxq, old_using_rss);
431 ef10_mac_filter_default_rxq_clear(
434 efx_port_t *epp = &(enp->en_port);
436 ef10_filter_default_rxq_clear(enp);
438 efx_filter_reconfigure(enp, epp->ep_mac_addr,
439 epp->ep_all_unicst, epp->ep_mulcst,
440 epp->ep_all_mulcst, epp->ep_brdcst,
441 epp->ep_mulcst_addr_list,
442 epp->ep_mulcst_addr_count);
446 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */