2 * Copyright 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"
38 efx_port_t *epp = &(enp->en_port);
39 efx_phy_ops_t *epop = epp->ep_epop;
42 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
43 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
44 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
46 if (enp->en_mod_flags & EFX_MOD_PORT) {
51 enp->en_mod_flags |= EFX_MOD_PORT;
53 epp->ep_mac_type = EFX_MAC_INVALID;
54 epp->ep_link_mode = EFX_LINK_UNKNOWN;
55 epp->ep_mac_poll_needed = B_TRUE;
56 epp->ep_mac_drain = B_TRUE;
58 /* Configure the MAC */
59 if ((rc = efx_mac_select(enp)) != 0)
62 epp->ep_emop->emo_reconfigure(enp);
65 * Turn on the PHY if available, otherwise reset it, and
66 * reconfigure it with the current configuration.
68 if (epop->epo_power != NULL) {
69 if ((rc = epop->epo_power(enp, B_TRUE)) != 0)
72 if ((rc = epop->epo_reset(enp)) != 0)
76 EFSYS_ASSERT(enp->en_reset_flags & EFX_RESET_PHY);
77 enp->en_reset_flags &= ~EFX_RESET_PHY;
79 if ((rc = epop->epo_reconfigure(enp)) != 0)
89 EFSYS_PROBE1(fail1, int, rc);
91 enp->en_mod_flags &= ~EFX_MOD_PORT;
99 __out efx_link_mode_t *link_modep)
101 efx_port_t *epp = &(enp->en_port);
102 efx_mac_ops_t *emop = epp->ep_emop;
103 efx_link_mode_t ignore_link_mode;
106 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
107 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
109 EFSYS_ASSERT(emop != NULL);
110 EFSYS_ASSERT(!epp->ep_mac_stats_pending);
112 if (link_modep == NULL)
113 link_modep = &ignore_link_mode;
115 if ((rc = emop->emo_poll(enp, link_modep)) != 0)
121 EFSYS_PROBE1(fail1, int, rc);
126 #if EFSYS_OPT_LOOPBACK
129 efx_port_loopback_set(
131 __in efx_link_mode_t link_mode,
132 __in efx_loopback_type_t loopback_type)
134 efx_port_t *epp = &(enp->en_port);
135 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
136 efx_mac_ops_t *emop = epp->ep_emop;
139 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
140 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
141 EFSYS_ASSERT(emop != NULL);
143 EFSYS_ASSERT(link_mode < EFX_LINK_NMODES);
144 if ((1 << loopback_type) & ~encp->enc_loopback_types[link_mode]) {
149 if (epp->ep_loopback_type == loopback_type &&
150 epp->ep_loopback_link_mode == link_mode)
153 if ((rc = emop->emo_loopback_set(enp, link_mode, loopback_type)) != 0)
161 EFSYS_PROBE1(fail1, int, rc);
168 static const char __cs * __cs __efx_loopback_type_name[] = {
189 __checkReturn const char __cs *
190 efx_loopback_type_name(
192 __in efx_loopback_type_t type)
194 _NOTE(ARGUNUSED(enp))
195 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
196 EFSYS_ASSERT3U(type, <, EFX_LOOPBACK_NTYPES);
198 return (__efx_loopback_type_name[type]);
201 #endif /* EFSYS_OPT_NAMES */
203 #endif /* EFSYS_OPT_LOOPBACK */
209 efx_port_t *epp = &(enp->en_port);
210 efx_phy_ops_t *epop = epp->ep_epop;
212 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
213 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
214 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
215 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT);
217 EFSYS_ASSERT(epp->ep_mac_drain);
220 epp->ep_mac_type = EFX_MAC_INVALID;
221 epp->ep_mac_drain = B_FALSE;
222 epp->ep_mac_poll_needed = B_FALSE;
224 /* Turn off the PHY */
225 if (epop->epo_power != NULL)
226 (void) epop->epo_power(enp, B_FALSE);
228 enp->en_mod_flags &= ~EFX_MOD_PORT;