efx_port.c revision 227569
1276541Sdes/*- 2276541Sdes * Copyright 2009 Solarflare Communications Inc. All rights reserved. 3276541Sdes * 4276541Sdes * Redistribution and use in source and binary forms, with or without 5276541Sdes * modification, are permitted provided that the following conditions 6276541Sdes * are met: 7276541Sdes * 1. Redistributions of source code must retain the above copyright 8276541Sdes * notice, this list of conditions and the following disclaimer. 9276541Sdes * 2. Redistributions in binary form must reproduce the above copyright 10276541Sdes * notice, this list of conditions and the following disclaimer in the 11276541Sdes * documentation and/or other materials provided with the distribution. 12276541Sdes * 13276541Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND 14276541Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15276541Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16276541Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17276541Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18276541Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19276541Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20276541Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21276541Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22276541Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23276541Sdes * SUCH DAMAGE. 24276541Sdes */ 25276541Sdes 26276541Sdes#include "efsys.h" 27276541Sdes#include "efx.h" 28276541Sdes#include "efx_types.h" 29276541Sdes#include "efx_impl.h" 30276541Sdes 31276541Sdes __checkReturn int 32276541Sdesefx_port_init( 33276541Sdes __in efx_nic_t *enp) 34276541Sdes{ 35276541Sdes efx_port_t *epp = &(enp->en_port); 36276541Sdes efx_phy_ops_t *epop = epp->ep_epop; 37276541Sdes int rc; 38276541Sdes 39276541Sdes EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 40276541Sdes EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE); 41276541Sdes EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC); 42276541Sdes 43276541Sdes if (enp->en_mod_flags & EFX_MOD_PORT) { 44276541Sdes rc = EINVAL; 45276541Sdes goto fail1; 46276541Sdes } 47276541Sdes 48276541Sdes enp->en_mod_flags |= EFX_MOD_PORT; 49276541Sdes 50276541Sdes epp->ep_mac_type = EFX_MAC_INVALID; 51276541Sdes epp->ep_link_mode = EFX_LINK_UNKNOWN; 52276541Sdes epp->ep_mac_poll_needed = B_TRUE; 53276541Sdes epp->ep_mac_drain = B_TRUE; 54276541Sdes 55276541Sdes /* Configure the MAC */ 56276541Sdes if ((rc = efx_mac_select(enp)) != 0) 57276541Sdes goto fail1; 58 59 epp->ep_emop->emo_reconfigure(enp); 60 61 /* 62 * Turn on the PHY if available, otherwise reset it, and 63 * reconfigure it with the current configuration. 64 */ 65 if (epop->epo_power != NULL) { 66 if ((rc = epop->epo_power(enp, B_TRUE)) != 0) 67 goto fail2; 68 } else { 69 if ((rc = epop->epo_reset(enp)) != 0) 70 goto fail2; 71 } 72 73 EFSYS_ASSERT(enp->en_reset_flags & EFX_RESET_PHY); 74 enp->en_reset_flags &= ~EFX_RESET_PHY; 75 76 if ((rc = epop->epo_reconfigure(enp)) != 0) 77 goto fail3; 78 79 return (0); 80 81fail3: 82 EFSYS_PROBE(fail3); 83fail2: 84 EFSYS_PROBE(fail2); 85fail1: 86 EFSYS_PROBE1(fail1, int, rc); 87 88 enp->en_mod_flags &= ~EFX_MOD_PORT; 89 90 return (rc); 91} 92 93 __checkReturn int 94efx_port_poll( 95 __in efx_nic_t *enp, 96 __out efx_link_mode_t *link_modep) 97{ 98 efx_port_t *epp = &(enp->en_port); 99 efx_mac_ops_t *emop = epp->ep_emop; 100 efx_link_mode_t ignore_link_mode; 101 int rc; 102 103 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 104 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT); 105 106 EFSYS_ASSERT(emop != NULL); 107 EFSYS_ASSERT(!epp->ep_mac_stats_pending); 108 109 if (link_modep == NULL) 110 link_modep = &ignore_link_mode; 111 112 if ((rc = emop->emo_poll(enp, link_modep)) != 0) 113 goto fail1; 114 115 return (0); 116 117fail1: 118 EFSYS_PROBE1(fail1, int, rc); 119 120 return (rc); 121} 122 123#if EFSYS_OPT_LOOPBACK 124 125 __checkReturn int 126efx_port_loopback_set( 127 __in efx_nic_t *enp, 128 __in efx_link_mode_t link_mode, 129 __in efx_loopback_type_t loopback_type) 130{ 131 efx_port_t *epp = &(enp->en_port); 132 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 133 efx_mac_ops_t *emop = epp->ep_emop; 134 int rc; 135 136 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 137 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT); 138 EFSYS_ASSERT(emop != NULL); 139 140 EFSYS_ASSERT(link_mode < EFX_LINK_NMODES); 141 if ((1 << loopback_type) & ~encp->enc_loopback_types[link_mode]) { 142 rc = ENOTSUP; 143 goto fail1; 144 } 145 146 if (epp->ep_loopback_type == loopback_type && 147 epp->ep_loopback_link_mode == link_mode) 148 return (0); 149 150 if ((rc = emop->emo_loopback_set(enp, link_mode, loopback_type)) != 0) 151 goto fail2; 152 153 return (0); 154 155fail2: 156 EFSYS_PROBE(fail2); 157fail1: 158 EFSYS_PROBE1(fail1, int, rc); 159 160 return (rc); 161} 162 163#if EFSYS_OPT_NAMES 164 165static const char __cs * __cs __efx_loopback_type_name[] = { 166 "OFF", 167 "DATA", 168 "GMAC", 169 "XGMII", 170 "XGXS", 171 "XAUI", 172 "GMII", 173 "SGMII", 174 "XGBR", 175 "XFI", 176 "XAUI_FAR", 177 "GMII_FAR", 178 "SGMII_FAR", 179 "XFI_FAR", 180 "GPHY", 181 "PHY_XS", 182 "PCS", 183 "PMA_PMD", 184}; 185 186 __checkReturn const char __cs * 187efx_loopback_type_name( 188 __in efx_nic_t *enp, 189 __in efx_loopback_type_t type) 190{ 191 _NOTE(ARGUNUSED(enp)) 192 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 193 EFSYS_ASSERT3U(type, <, EFX_LOOPBACK_NTYPES); 194 195 return (__efx_loopback_type_name[type]); 196} 197 198#endif /* EFSYS_OPT_NAMES */ 199 200#endif /* EFSYS_OPT_LOOPBACK */ 201 202 void 203efx_port_fini( 204 __in efx_nic_t *enp) 205{ 206 efx_port_t *epp = &(enp->en_port); 207 efx_phy_ops_t *epop = epp->ep_epop; 208 209 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 210 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE); 211 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC); 212 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PORT); 213 214 EFSYS_ASSERT(epp->ep_mac_drain); 215 216 epp->ep_emop = NULL; 217 epp->ep_mac_type = EFX_MAC_INVALID; 218 epp->ep_mac_drain = B_FALSE; 219 epp->ep_mac_poll_needed = B_FALSE; 220 221 /* Turn off the PHY */ 222 if (epop->epo_power != NULL) 223 (void) epop->epo_power(enp, B_FALSE); 224 225 enp->en_mod_flags &= ~EFX_MOD_PORT; 226} 227