2 * Copyright 2007-2009 Solarflare Communications Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
31 #include "efx_types.h"
34 #if EFSYS_OPT_MAC_FALCON_GMAC
35 #include "falcon_gmac.h"
38 #if EFSYS_OPT_MAC_FALCON_XMAC
39 #include "falcon_xmac.h"
42 #if EFSYS_OPT_MAC_FALCON_GMAC
43 static efx_mac_ops_t __cs __efx_falcon_gmac_ops = {
44 falcon_gmac_reset, /* emo_reset */
45 falcon_mac_poll, /* emo_poll */
46 falcon_mac_up, /* emo_up */
47 falcon_gmac_reconfigure, /* emo_reconfigure */
48 #if EFSYS_OPT_LOOPBACK
49 falcon_mac_loopback_set, /* emo_loopback_set */
50 #endif /* EFSYS_OPT_LOOPBACK */
51 #if EFSYS_OPT_MAC_STATS
52 falcon_mac_stats_upload, /* emo_stats_upload */
53 NULL, /* emo_stats_periodic */
54 falcon_gmac_stats_update /* emo_stats_update */
55 #endif /* EFSYS_OPT_MAC_STATS */
57 #endif /* EFSYS_OPT_MAC_FALCON_GMAC */
59 #if EFSYS_OPT_MAC_FALCON_XMAC
60 static efx_mac_ops_t __cs __efx_falcon_xmac_ops = {
61 falcon_xmac_reset, /* emo_reset */
62 falcon_mac_poll, /* emo_poll */
63 falcon_mac_up, /* emo_up */
64 falcon_xmac_reconfigure, /* emo_reconfigure */
65 #if EFSYS_OPT_LOOPBACK
66 falcon_mac_loopback_set, /* emo_loopback_set */
67 #endif /* EFSYS_OPT_LOOPBACK */
68 #if EFSYS_OPT_MAC_STATS
69 falcon_mac_stats_upload, /* emo_stats_upload */
70 NULL, /* emo_stats_periodic */
71 falcon_xmac_stats_update /* emo_stats_update */
72 #endif /* EFSYS_OPT_MAC_STATS */
74 #endif /* EFSYS_OPT_MAC_FALCON_XMAC */
77 static efx_mac_ops_t __cs __efx_siena_mac_ops = {
79 siena_mac_poll, /* emo_poll */
80 siena_mac_up, /* emo_up */
81 siena_mac_reconfigure, /* emo_reconfigure */
82 #if EFSYS_OPT_LOOPBACK
83 siena_mac_loopback_set, /* emo_loopback_set */
84 #endif /* EFSYS_OPT_LOOPBACK */
85 #if EFSYS_OPT_MAC_STATS
86 siena_mac_stats_upload, /* emo_stats_upload */
87 siena_mac_stats_periodic, /* emo_stats_periodic */
88 siena_mac_stats_update /* emo_stats_update */
89 #endif /* EFSYS_OPT_MAC_STATS */
91 #endif /* EFSYS_OPT_SIENA */
93 static efx_mac_ops_t __cs * __cs __efx_mac_ops[] = {
95 #if EFSYS_OPT_MAC_FALCON_GMAC
96 &__efx_falcon_gmac_ops,
99 #endif /* EFSYS_OPT_MAC_FALCON_GMAC */
100 #if EFSYS_OPT_MAC_FALCON_XMAC
101 &__efx_falcon_xmac_ops,
104 #endif /* EFSYS_OPT_MAC_FALCON_XMAC */
106 &__efx_siena_mac_ops,
109 #endif /* EFSYS_OPT_SIENA */
117 efx_port_t *epp = &(enp->en_port);
118 efx_mac_ops_t *emop = epp->ep_emop;
122 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
123 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
124 EFSYS_ASSERT(emop != NULL);
126 if (pdu < EFX_MAC_PDU_MIN) {
131 if (pdu > EFX_MAC_PDU_MAX) {
136 old_pdu = epp->ep_mac_pdu;
137 epp->ep_mac_pdu = (uint32_t)pdu;
138 if ((rc = emop->emo_reconfigure(enp)) != 0)
146 epp->ep_mac_pdu = old_pdu;
151 EFSYS_PROBE1(fail1, int, rc);
161 efx_port_t *epp = &(enp->en_port);
162 efx_mac_ops_t *emop = epp->ep_emop;
167 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
168 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
170 if (addr[0] & 0x01) {
175 oui = addr[0] << 16 | addr[1] << 8 | addr[2];
176 if (oui == 0x000000) {
181 EFX_MAC_ADDR_COPY(old_addr, epp->ep_mac_addr);
182 EFX_MAC_ADDR_COPY(epp->ep_mac_addr, addr);
183 if ((rc = emop->emo_reconfigure(enp)) != 0)
191 EFX_MAC_ADDR_COPY(epp->ep_mac_addr, old_addr);
196 EFSYS_PROBE1(fail1, int, rc);
204 __in boolean_t unicst,
205 __in boolean_t brdcst)
207 efx_port_t *epp = &(enp->en_port);
208 efx_mac_ops_t *emop = epp->ep_emop;
209 boolean_t old_unicst;
210 boolean_t old_brdcst;
213 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
214 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
219 epp->ep_unicst = unicst;
220 epp->ep_brdcst = brdcst;
222 if ((rc = emop->emo_reconfigure(enp)) != 0)
228 EFSYS_PROBE1(fail1, int, rc);
230 epp->ep_unicst = old_unicst;
231 epp->ep_brdcst = old_brdcst;
239 __in boolean_t enabled)
241 efx_port_t *epp = &(enp->en_port);
242 efx_mac_ops_t *emop = epp->ep_emop;
245 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
246 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
247 EFSYS_ASSERT(emop != NULL);
249 if (epp->ep_mac_drain == enabled)
252 epp->ep_mac_drain = enabled;
254 if (enabled && emop->emo_reset != NULL) {
255 if ((rc = emop->emo_reset(enp)) != 0)
258 EFSYS_ASSERT(enp->en_reset_flags & EFX_RESET_MAC);
259 enp->en_reset_flags &= ~EFX_RESET_PHY;
262 if ((rc = emop->emo_reconfigure(enp)) != 0)
270 EFSYS_PROBE1(fail1, int, rc);
278 __out boolean_t *mac_upp)
280 efx_port_t *epp = &(enp->en_port);
281 efx_mac_ops_t *emop = epp->ep_emop;
284 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
285 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
287 if ((rc = emop->emo_up(enp, mac_upp)) != 0)
293 EFSYS_PROBE1(fail1, int, rc);
301 __in unsigned int fcntl,
302 __in boolean_t autoneg)
304 efx_port_t *epp = &(enp->en_port);
305 efx_mac_ops_t *emop = epp->ep_emop;
306 efx_phy_ops_t *epop = epp->ep_epop;
307 unsigned int old_fcntl;
308 boolean_t old_autoneg;
309 unsigned int old_adv_cap;
312 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
313 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
315 if ((fcntl & ~(EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE)) != 0) {
321 * Ignore a request to set flow control autonegotiation
322 * if the PHY doesn't support it.
324 if (~epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_AN))
327 old_fcntl = epp->ep_fcntl;
328 old_autoneg = autoneg;
329 old_adv_cap = epp->ep_adv_cap_mask;
331 epp->ep_fcntl = fcntl;
332 epp->ep_fcntl_autoneg = autoneg;
335 * If the PHY supports autonegotiation, then encode the flow control
336 * settings in the advertised capabilities, and restart AN. Otherwise,
337 * just push the new settings directly to the MAC.
339 if (epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_AN)) {
340 if (fcntl & EFX_FCNTL_RESPOND)
341 epp->ep_adv_cap_mask |= (1 << EFX_PHY_CAP_PAUSE |
342 1 << EFX_PHY_CAP_ASYM);
344 epp->ep_adv_cap_mask &= ~(1 << EFX_PHY_CAP_PAUSE |
345 1 << EFX_PHY_CAP_ASYM);
347 if (fcntl & EFX_FCNTL_GENERATE)
348 epp->ep_adv_cap_mask ^= (1 << EFX_PHY_CAP_ASYM);
350 if ((rc = epop->epo_reconfigure(enp)) != 0)
354 if ((rc = emop->emo_reconfigure(enp)) != 0)
363 epp->ep_fcntl = old_fcntl;
364 epp->ep_fcntl_autoneg = old_autoneg;
365 epp->ep_adv_cap_mask = old_adv_cap;
368 EFSYS_PROBE1(fail1, int, rc);
376 __out unsigned int *fcntl_wantedp,
377 __out unsigned int *fcntl_linkp)
379 efx_port_t *epp = &(enp->en_port);
382 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
383 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
386 * If the PHY supports auto negotiation, then the requested flow
387 * control settings are encoded in the advertised capabilities.
389 if (epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_AN)) {
392 if (epp->ep_adv_cap_mask & (1 << EFX_PHY_CAP_PAUSE))
393 wanted = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
394 if (epp->ep_adv_cap_mask & (1 << EFX_PHY_CAP_ASYM))
395 wanted ^= EFX_FCNTL_GENERATE;
397 wanted = epp->ep_fcntl;
399 *fcntl_linkp = epp->ep_fcntl;
400 *fcntl_wantedp = wanted;
406 __in_ecount(EFX_MAC_HASH_BITS) unsigned int const *bucket)
408 efx_port_t *epp = &(enp->en_port);
409 efx_mac_ops_t *emop = epp->ep_emop;
410 efx_oword_t old_hash[2];
414 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
415 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
417 memcpy(old_hash, epp->ep_multicst_hash, sizeof (old_hash));
419 /* Set the lower 128 bits of the hash */
420 EFX_ZERO_OWORD(epp->ep_multicst_hash[0]);
421 for (index = 0; index < 128; index++) {
422 if (bucket[index] != 0)
423 EFX_SET_OWORD_BIT(epp->ep_multicst_hash[0], index);
426 /* Set the upper 128 bits of the hash */
427 EFX_ZERO_OWORD(epp->ep_multicst_hash[1]);
428 for (index = 0; index < 128; index++) {
429 if (bucket[index + 128] != 0)
430 EFX_SET_OWORD_BIT(epp->ep_multicst_hash[1], index);
433 if ((rc = emop->emo_reconfigure(enp)) != 0)
439 EFSYS_PROBE1(fail1, int, rc);
441 memcpy(epp->ep_multicst_hash, old_hash, sizeof (old_hash));
446 #if EFSYS_OPT_MAC_STATS
450 /* START MKCONFIG GENERATED EfxMacStatNamesBlock adf707adba80813e */
451 static const char __cs * __cs __efx_mac_stat_name[] = {
460 "rx_128_to_255_pkts",
461 "rx_256_to_511_pkts",
462 "rx_512_to_1023_pkts",
463 "rx_1024_to_15xx_pkts",
468 "rx_false_carrier_errors",
471 "rx_internal_errors",
482 "rx_nodesc_drop_cnt",
491 "tx_128_to_255_pkts",
492 "tx_256_to_511_pkts",
493 "tx_512_to_1023_pkts",
494 "tx_1024_to_15xx_pkts",
504 /* END MKCONFIG GENERATED EfxMacStatNamesBlock */
506 __checkReturn const char __cs *
509 __in unsigned int id)
511 _NOTE(ARGUNUSED(enp))
512 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
514 EFSYS_ASSERT3U(id, <, EFX_MAC_NSTATS);
515 return (__efx_mac_stat_name[id]);
518 #endif /* EFSYS_OPT_STAT_NAME */
521 efx_mac_stats_upload(
523 __in efsys_mem_t *esmp)
525 efx_port_t *epp = &(enp->en_port);
526 efx_mac_ops_t *emop = epp->ep_emop;
529 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
530 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
531 EFSYS_ASSERT(emop != NULL);
534 * Don't assert !ep_mac_stats_pending, because the client might
535 * have failed to finalise statistics when previously stopping
538 if ((rc = emop->emo_stats_upload(enp, esmp)) != 0)
541 epp->ep_mac_stats_pending = B_TRUE;
546 EFSYS_PROBE1(fail1, int, rc);
552 efx_mac_stats_periodic(
554 __in efsys_mem_t *esmp,
555 __in uint16_t period_ms,
556 __in boolean_t events)
558 efx_port_t *epp = &(enp->en_port);
559 efx_mac_ops_t *emop = epp->ep_emop;
562 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
563 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
565 EFSYS_ASSERT(emop != NULL);
567 if (emop->emo_stats_periodic == NULL) {
572 if ((rc = emop->emo_stats_periodic(enp, esmp, period_ms, events)) != 0)
580 EFSYS_PROBE1(fail1, int, rc);
587 efx_mac_stats_update(
589 __in efsys_mem_t *esmp,
590 __inout_ecount(EFX_MAC_NSTATS) efsys_stat_t *essp,
591 __in uint32_t *generationp)
593 efx_port_t *epp = &(enp->en_port);
594 efx_mac_ops_t *emop = epp->ep_emop;
597 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
598 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
599 EFSYS_ASSERT(emop != NULL);
601 rc = emop->emo_stats_update(enp, esmp, essp, generationp);
603 epp->ep_mac_stats_pending = B_FALSE;
608 #endif /* EFSYS_OPT_MAC_STATS */
614 efx_port_t *epp = &(enp->en_port);
615 efx_mac_type_t type = EFX_MAC_INVALID;
620 if (enp->en_family == EFX_FAMILY_SIENA) {
621 type = EFX_MAC_SIENA;
627 switch (epp->ep_link_mode) {
628 #if EFSYS_OPT_MAC_FALCON_GMAC
629 case EFX_LINK_100HDX:
630 case EFX_LINK_100FDX:
631 case EFX_LINK_1000HDX:
632 case EFX_LINK_1000FDX:
633 type = EFX_MAC_FALCON_GMAC;
635 #endif /* EFSYS_OPT_FALCON_GMAC */
637 #if EFSYS_OPT_MAC_FALCON_XMAC
638 case EFX_LINK_10000FDX:
639 type = EFX_MAC_FALCON_XMAC;
641 #endif /* EFSYS_OPT_FALCON_XMAC */
644 #if EFSYS_OPT_MAC_FALCON_GMAC && EFSYS_OPT_MAC_FALCON_XMAC
645 /* Only initialise a MAC supported by the PHY */
646 if (epp->ep_phy_cap_mask &
647 ((1 << EFX_PHY_CAP_1000FDX) |
648 (1 << EFX_PHY_CAP_1000HDX) |
649 (1 << EFX_PHY_CAP_100FDX) |
650 (1 << EFX_PHY_CAP_100HDX) |
651 (1 << EFX_PHY_CAP_10FDX) |
652 (1 << EFX_PHY_CAP_10FDX)))
653 type = EFX_MAC_FALCON_GMAC;
655 type = EFX_MAC_FALCON_XMAC;
656 #elif EFSYS_OPT_MAC_FALCON_GMAC
657 type = EFX_MAC_FALCON_GMAC;
659 type = EFX_MAC_FALCON_XMAC;
663 #endif /* EFSYS_OPT_FALCON */
666 EFSYS_ASSERT(type != EFX_MAC_INVALID);
667 EFSYS_ASSERT3U(type, <, EFX_MAC_NTYPES);
668 emop = epp->ep_emop = (efx_mac_ops_t *)__efx_mac_ops[type];
669 EFSYS_ASSERT(emop != NULL);
671 epp->ep_mac_type = type;
673 if (emop->emo_reset != NULL) {
674 if ((rc = emop->emo_reset(enp)) != 0)
677 EFSYS_ASSERT(enp->en_reset_flags & EFX_RESET_MAC);
678 enp->en_reset_flags &= ~EFX_RESET_MAC;
684 EFSYS_PROBE1(fail1, int, rc);