Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 3 | * Copyright 2009-2010 Solarflare Communications Inc. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation, incorporated herein by reference. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Driver for PHY related operations via MCDI. |
| 12 | */ |
| 13 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 15 | #include "efx.h" |
| 16 | #include "phy.h" |
| 17 | #include "mcdi.h" |
| 18 | #include "mcdi_pcol.h" |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 19 | #include "nic.h" |
| 20 | #include "selftest.h" |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 21 | |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 22 | struct efx_mcdi_phy_data { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 23 | u32 flags; |
| 24 | u32 type; |
| 25 | u32 supported_cap; |
| 26 | u32 channel; |
| 27 | u32 port; |
| 28 | u32 stats_mask; |
| 29 | u8 name[20]; |
| 30 | u32 media; |
| 31 | u32 mmd_mask; |
| 32 | u8 revision[20]; |
| 33 | u32 forced_cap; |
| 34 | }; |
| 35 | |
| 36 | static int |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 37 | efx_mcdi_get_phy_cfg(struct efx_nic *efx, struct efx_mcdi_phy_data *cfg) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 38 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 39 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_CFG_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 40 | size_t outlen; |
| 41 | int rc; |
| 42 | |
| 43 | BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN != 0); |
| 44 | BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN != sizeof(cfg->name)); |
| 45 | |
| 46 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_CFG, NULL, 0, |
| 47 | outbuf, sizeof(outbuf), &outlen); |
| 48 | if (rc) |
| 49 | goto fail; |
| 50 | |
| 51 | if (outlen < MC_CMD_GET_PHY_CFG_OUT_LEN) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 52 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 53 | goto fail; |
| 54 | } |
| 55 | |
| 56 | cfg->flags = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_FLAGS); |
| 57 | cfg->type = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_TYPE); |
| 58 | cfg->supported_cap = |
| 59 | MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_SUPPORTED_CAP); |
| 60 | cfg->channel = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_CHANNEL); |
| 61 | cfg->port = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_PRT); |
| 62 | cfg->stats_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_STATS_MASK); |
| 63 | memcpy(cfg->name, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_NAME), |
| 64 | sizeof(cfg->name)); |
| 65 | cfg->media = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MEDIA_TYPE); |
| 66 | cfg->mmd_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MMD_MASK); |
| 67 | memcpy(cfg->revision, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_REVISION), |
| 68 | sizeof(cfg->revision)); |
| 69 | |
| 70 | return 0; |
| 71 | |
| 72 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 73 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 74 | return rc; |
| 75 | } |
| 76 | |
| 77 | static int efx_mcdi_set_link(struct efx_nic *efx, u32 capabilities, |
| 78 | u32 flags, u32 loopback_mode, |
| 79 | u32 loopback_speed) |
| 80 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 81 | MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_LINK_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 82 | int rc; |
| 83 | |
| 84 | BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN != 0); |
| 85 | |
| 86 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_CAP, capabilities); |
| 87 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_FLAGS, flags); |
| 88 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_MODE, loopback_mode); |
| 89 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_SPEED, loopback_speed); |
| 90 | |
| 91 | rc = efx_mcdi_rpc(efx, MC_CMD_SET_LINK, inbuf, sizeof(inbuf), |
| 92 | NULL, 0, NULL); |
| 93 | if (rc) |
| 94 | goto fail; |
| 95 | |
| 96 | return 0; |
| 97 | |
| 98 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 99 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 100 | return rc; |
| 101 | } |
| 102 | |
| 103 | static int efx_mcdi_loopback_modes(struct efx_nic *efx, u64 *loopback_modes) |
| 104 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 105 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LOOPBACK_MODES_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 106 | size_t outlen; |
| 107 | int rc; |
| 108 | |
| 109 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LOOPBACK_MODES, NULL, 0, |
| 110 | outbuf, sizeof(outbuf), &outlen); |
| 111 | if (rc) |
| 112 | goto fail; |
| 113 | |
| 114 | if (outlen < MC_CMD_GET_LOOPBACK_MODES_OUT_LEN) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 115 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 116 | goto fail; |
| 117 | } |
| 118 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 119 | *loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_OUT_SUGGESTED); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | |
| 123 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 124 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 125 | return rc; |
| 126 | } |
| 127 | |
| 128 | int efx_mcdi_mdio_read(struct efx_nic *efx, unsigned int bus, |
| 129 | unsigned int prtad, unsigned int devad, u16 addr, |
| 130 | u16 *value_out, u32 *status_out) |
| 131 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 132 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_READ_IN_LEN); |
| 133 | MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_READ_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 134 | size_t outlen; |
| 135 | int rc; |
| 136 | |
| 137 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, bus); |
| 138 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad); |
| 139 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad); |
| 140 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr); |
| 141 | |
| 142 | rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf), |
| 143 | outbuf, sizeof(outbuf), &outlen); |
| 144 | if (rc) |
| 145 | goto fail; |
| 146 | |
| 147 | *value_out = (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE); |
| 148 | *status_out = MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS); |
| 149 | return 0; |
| 150 | |
| 151 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 152 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 153 | return rc; |
| 154 | } |
| 155 | |
| 156 | int efx_mcdi_mdio_write(struct efx_nic *efx, unsigned int bus, |
| 157 | unsigned int prtad, unsigned int devad, u16 addr, |
| 158 | u16 value, u32 *status_out) |
| 159 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 160 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_WRITE_IN_LEN); |
| 161 | MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_WRITE_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 162 | size_t outlen; |
| 163 | int rc; |
| 164 | |
| 165 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, bus); |
| 166 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad); |
| 167 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad); |
| 168 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr); |
| 169 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value); |
| 170 | |
| 171 | rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf), |
| 172 | outbuf, sizeof(outbuf), &outlen); |
| 173 | if (rc) |
| 174 | goto fail; |
| 175 | |
| 176 | *status_out = MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS); |
| 177 | return 0; |
| 178 | |
| 179 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 180 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 181 | return rc; |
| 182 | } |
| 183 | |
| 184 | static u32 mcdi_to_ethtool_cap(u32 media, u32 cap) |
| 185 | { |
| 186 | u32 result = 0; |
| 187 | |
| 188 | switch (media) { |
| 189 | case MC_CMD_MEDIA_KX4: |
| 190 | result |= SUPPORTED_Backplane; |
| 191 | if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN)) |
| 192 | result |= SUPPORTED_1000baseKX_Full; |
| 193 | if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN)) |
| 194 | result |= SUPPORTED_10000baseKX4_Full; |
| 195 | break; |
| 196 | |
| 197 | case MC_CMD_MEDIA_XFP: |
| 198 | case MC_CMD_MEDIA_SFP_PLUS: |
| 199 | result |= SUPPORTED_FIBRE; |
| 200 | break; |
| 201 | |
| 202 | case MC_CMD_MEDIA_BASE_T: |
| 203 | result |= SUPPORTED_TP; |
| 204 | if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN)) |
| 205 | result |= SUPPORTED_10baseT_Half; |
| 206 | if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN)) |
| 207 | result |= SUPPORTED_10baseT_Full; |
| 208 | if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN)) |
| 209 | result |= SUPPORTED_100baseT_Half; |
| 210 | if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN)) |
| 211 | result |= SUPPORTED_100baseT_Full; |
| 212 | if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN)) |
| 213 | result |= SUPPORTED_1000baseT_Half; |
| 214 | if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN)) |
| 215 | result |= SUPPORTED_1000baseT_Full; |
| 216 | if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN)) |
| 217 | result |= SUPPORTED_10000baseT_Full; |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN)) |
| 222 | result |= SUPPORTED_Pause; |
| 223 | if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) |
| 224 | result |= SUPPORTED_Asym_Pause; |
| 225 | if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
| 226 | result |= SUPPORTED_Autoneg; |
| 227 | |
| 228 | return result; |
| 229 | } |
| 230 | |
| 231 | static u32 ethtool_to_mcdi_cap(u32 cap) |
| 232 | { |
| 233 | u32 result = 0; |
| 234 | |
| 235 | if (cap & SUPPORTED_10baseT_Half) |
| 236 | result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN); |
| 237 | if (cap & SUPPORTED_10baseT_Full) |
| 238 | result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN); |
| 239 | if (cap & SUPPORTED_100baseT_Half) |
| 240 | result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN); |
| 241 | if (cap & SUPPORTED_100baseT_Full) |
| 242 | result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN); |
| 243 | if (cap & SUPPORTED_1000baseT_Half) |
| 244 | result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN); |
| 245 | if (cap & (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseKX_Full)) |
| 246 | result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN); |
| 247 | if (cap & (SUPPORTED_10000baseT_Full | SUPPORTED_10000baseKX4_Full)) |
| 248 | result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN); |
| 249 | if (cap & SUPPORTED_Pause) |
| 250 | result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN); |
| 251 | if (cap & SUPPORTED_Asym_Pause) |
| 252 | result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN); |
| 253 | if (cap & SUPPORTED_Autoneg) |
| 254 | result |= (1 << MC_CMD_PHY_CAP_AN_LBN); |
| 255 | |
| 256 | return result; |
| 257 | } |
| 258 | |
| 259 | static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx) |
| 260 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 261 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 262 | enum efx_phy_mode mode, supported; |
| 263 | u32 flags; |
| 264 | |
| 265 | /* TODO: Advertise the capabilities supported by this PHY */ |
| 266 | supported = 0; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 267 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_TXDIS_LBN)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 268 | supported |= PHY_MODE_TX_DISABLED; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 269 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_LOWPOWER_LBN)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 270 | supported |= PHY_MODE_LOW_POWER; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 271 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_POWEROFF_LBN)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 272 | supported |= PHY_MODE_OFF; |
| 273 | |
| 274 | mode = efx->phy_mode & supported; |
| 275 | |
| 276 | flags = 0; |
| 277 | if (mode & PHY_MODE_TX_DISABLED) |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 278 | flags |= (1 << MC_CMD_SET_LINK_IN_TXDIS_LBN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 279 | if (mode & PHY_MODE_LOW_POWER) |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 280 | flags |= (1 << MC_CMD_SET_LINK_IN_LOWPOWER_LBN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 281 | if (mode & PHY_MODE_OFF) |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 282 | flags |= (1 << MC_CMD_SET_LINK_IN_POWEROFF_LBN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 283 | |
| 284 | return flags; |
| 285 | } |
| 286 | |
| 287 | static u32 mcdi_to_ethtool_media(u32 media) |
| 288 | { |
| 289 | switch (media) { |
| 290 | case MC_CMD_MEDIA_XAUI: |
| 291 | case MC_CMD_MEDIA_CX4: |
| 292 | case MC_CMD_MEDIA_KX4: |
| 293 | return PORT_OTHER; |
| 294 | |
| 295 | case MC_CMD_MEDIA_XFP: |
| 296 | case MC_CMD_MEDIA_SFP_PLUS: |
| 297 | return PORT_FIBRE; |
| 298 | |
| 299 | case MC_CMD_MEDIA_BASE_T: |
| 300 | return PORT_TP; |
| 301 | |
| 302 | default: |
| 303 | return PORT_OTHER; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | static int efx_mcdi_phy_probe(struct efx_nic *efx) |
| 308 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 309 | struct efx_mcdi_phy_data *phy_data; |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 310 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 311 | u32 caps; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 312 | int rc; |
| 313 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 314 | /* Initialise and populate phy_data */ |
| 315 | phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL); |
| 316 | if (phy_data == NULL) |
| 317 | return -ENOMEM; |
| 318 | |
| 319 | rc = efx_mcdi_get_phy_cfg(efx, phy_data); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 320 | if (rc != 0) |
| 321 | goto fail; |
| 322 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 323 | /* Read initial link advertisement */ |
| 324 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 325 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 326 | outbuf, sizeof(outbuf), NULL); |
| 327 | if (rc) |
| 328 | goto fail; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 329 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 330 | /* Fill out nic state */ |
| 331 | efx->phy_data = phy_data; |
| 332 | efx->phy_type = phy_data->type; |
| 333 | |
| 334 | efx->mdio_bus = phy_data->channel; |
| 335 | efx->mdio.prtad = phy_data->port; |
| 336 | efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 337 | efx->mdio.mode_support = 0; |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 338 | if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 339 | efx->mdio.mode_support |= MDIO_SUPPORTS_C22; |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 340 | if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 341 | efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 342 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 343 | caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP); |
| 344 | if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
| 345 | efx->link_advertising = |
| 346 | mcdi_to_ethtool_cap(phy_data->media, caps); |
| 347 | else |
| 348 | phy_data->forced_cap = caps; |
| 349 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 350 | /* Assert that we can map efx -> mcdi loopback modes */ |
| 351 | BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE); |
| 352 | BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA); |
| 353 | BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC); |
| 354 | BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII); |
| 355 | BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS); |
| 356 | BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI); |
| 357 | BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII); |
| 358 | BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII); |
| 359 | BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR); |
| 360 | BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI); |
| 361 | BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR); |
| 362 | BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR); |
| 363 | BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR); |
| 364 | BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR); |
| 365 | BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY); |
| 366 | BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS); |
| 367 | BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS); |
| 368 | BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD); |
| 369 | BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT); |
| 370 | BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS); |
| 371 | BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS); |
| 372 | BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR); |
| 373 | BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR); |
| 374 | BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS); |
| 375 | BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS); |
| 376 | BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR); |
| 377 | BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS); |
| 378 | |
| 379 | rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes); |
| 380 | if (rc != 0) |
| 381 | goto fail; |
| 382 | /* The MC indicates that LOOPBACK_NONE is a valid loopback mode, |
| 383 | * but by convention we don't */ |
| 384 | efx->loopback_modes &= ~(1 << LOOPBACK_NONE); |
| 385 | |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 386 | /* Set the initial link mode */ |
| 387 | efx_mcdi_phy_decode_link( |
| 388 | efx, &efx->link_state, |
| 389 | MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED), |
| 390 | MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS), |
| 391 | MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL)); |
| 392 | |
| 393 | /* Default to Autonegotiated flow control if the PHY supports it */ |
| 394 | efx->wanted_fc = EFX_FC_RX | EFX_FC_TX; |
| 395 | if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
| 396 | efx->wanted_fc |= EFX_FC_AUTO; |
Steve Hodgson | cffe9d4 | 2010-06-01 11:18:08 +0000 | [diff] [blame] | 397 | efx_link_set_wanted_fc(efx, efx->wanted_fc); |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 398 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 399 | return 0; |
| 400 | |
| 401 | fail: |
| 402 | kfree(phy_data); |
| 403 | return rc; |
| 404 | } |
| 405 | |
| 406 | int efx_mcdi_phy_reconfigure(struct efx_nic *efx) |
| 407 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 408 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 409 | u32 caps = (efx->link_advertising ? |
| 410 | ethtool_to_mcdi_cap(efx->link_advertising) : |
| 411 | phy_cfg->forced_cap); |
| 412 | |
| 413 | return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx), |
| 414 | efx->loopback_mode, 0); |
| 415 | } |
| 416 | |
| 417 | void efx_mcdi_phy_decode_link(struct efx_nic *efx, |
| 418 | struct efx_link_state *link_state, |
| 419 | u32 speed, u32 flags, u32 fcntl) |
| 420 | { |
| 421 | switch (fcntl) { |
| 422 | case MC_CMD_FCNTL_AUTO: |
| 423 | WARN_ON(1); /* This is not a link mode */ |
| 424 | link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX; |
| 425 | break; |
| 426 | case MC_CMD_FCNTL_BIDIR: |
| 427 | link_state->fc = EFX_FC_TX | EFX_FC_RX; |
| 428 | break; |
| 429 | case MC_CMD_FCNTL_RESPOND: |
| 430 | link_state->fc = EFX_FC_RX; |
| 431 | break; |
| 432 | default: |
| 433 | WARN_ON(1); |
| 434 | case MC_CMD_FCNTL_OFF: |
| 435 | link_state->fc = 0; |
| 436 | break; |
| 437 | } |
| 438 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 439 | link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN)); |
| 440 | link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 441 | link_state->speed = speed; |
| 442 | } |
| 443 | |
| 444 | /* Verify that the forced flow control settings (!EFX_FC_AUTO) are |
| 445 | * supported by the link partner. Warn the user if this isn't the case |
| 446 | */ |
| 447 | void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa) |
| 448 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 449 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 450 | u32 rmtadv; |
| 451 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 452 | /* The link partner capabilities are only relevant if the |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 453 | * link supports flow control autonegotiation */ |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 454 | if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 455 | return; |
| 456 | |
| 457 | /* If flow control autoneg is supported and enabled, then fine */ |
| 458 | if (efx->wanted_fc & EFX_FC_AUTO) |
| 459 | return; |
| 460 | |
| 461 | rmtadv = 0; |
| 462 | if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN)) |
| 463 | rmtadv |= ADVERTISED_Pause; |
| 464 | if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) |
| 465 | rmtadv |= ADVERTISED_Asym_Pause; |
| 466 | |
| 467 | if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 468 | netif_err(efx, link, efx->net_dev, |
| 469 | "warning: link partner doesn't support pause frames"); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static bool efx_mcdi_phy_poll(struct efx_nic *efx) |
| 473 | { |
| 474 | struct efx_link_state old_state = efx->link_state; |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 475 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 476 | int rc; |
| 477 | |
| 478 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 479 | |
| 480 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 481 | |
| 482 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 483 | outbuf, sizeof(outbuf), NULL); |
| 484 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 485 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 486 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 487 | efx->link_state.up = false; |
| 488 | } else { |
| 489 | efx_mcdi_phy_decode_link( |
| 490 | efx, &efx->link_state, |
| 491 | MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED), |
| 492 | MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS), |
| 493 | MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL)); |
| 494 | } |
| 495 | |
| 496 | return !efx_link_state_equal(&efx->link_state, &old_state); |
| 497 | } |
| 498 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 499 | static void efx_mcdi_phy_remove(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 500 | { |
| 501 | struct efx_mcdi_phy_data *phy_data = efx->phy_data; |
| 502 | |
| 503 | efx->phy_data = NULL; |
| 504 | kfree(phy_data); |
| 505 | } |
| 506 | |
| 507 | static void efx_mcdi_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
| 508 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 509 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 510 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 511 | int rc; |
| 512 | |
| 513 | ecmd->supported = |
| 514 | mcdi_to_ethtool_cap(phy_cfg->media, phy_cfg->supported_cap); |
| 515 | ecmd->advertising = efx->link_advertising; |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 516 | ethtool_cmd_speed_set(ecmd, efx->link_state.speed); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 517 | ecmd->duplex = efx->link_state.fd; |
| 518 | ecmd->port = mcdi_to_ethtool_media(phy_cfg->media); |
| 519 | ecmd->phy_address = phy_cfg->port; |
| 520 | ecmd->transceiver = XCVR_INTERNAL; |
| 521 | ecmd->autoneg = !!(efx->link_advertising & ADVERTISED_Autoneg); |
| 522 | ecmd->mdio_support = (efx->mdio.mode_support & |
| 523 | (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22)); |
| 524 | |
| 525 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 526 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 527 | outbuf, sizeof(outbuf), NULL); |
| 528 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 529 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 530 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 531 | return; |
| 532 | } |
| 533 | ecmd->lp_advertising = |
| 534 | mcdi_to_ethtool_cap(phy_cfg->media, |
| 535 | MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP)); |
| 536 | } |
| 537 | |
| 538 | static int efx_mcdi_phy_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
| 539 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 540 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 541 | u32 caps; |
| 542 | int rc; |
| 543 | |
| 544 | if (ecmd->autoneg) { |
| 545 | caps = (ethtool_to_mcdi_cap(ecmd->advertising) | |
| 546 | 1 << MC_CMD_PHY_CAP_AN_LBN); |
| 547 | } else if (ecmd->duplex) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 548 | switch (ethtool_cmd_speed(ecmd)) { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 549 | case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break; |
| 550 | case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break; |
| 551 | case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break; |
| 552 | case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break; |
| 553 | default: return -EINVAL; |
| 554 | } |
| 555 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 556 | switch (ethtool_cmd_speed(ecmd)) { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 557 | case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break; |
| 558 | case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break; |
| 559 | case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break; |
| 560 | default: return -EINVAL; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx), |
| 565 | efx->loopback_mode, 0); |
| 566 | if (rc) |
| 567 | return rc; |
| 568 | |
| 569 | if (ecmd->autoneg) { |
| 570 | efx_link_set_advertising( |
| 571 | efx, ecmd->advertising | ADVERTISED_Autoneg); |
| 572 | phy_cfg->forced_cap = 0; |
| 573 | } else { |
| 574 | efx_link_set_advertising(efx, 0); |
| 575 | phy_cfg->forced_cap = caps; |
| 576 | } |
| 577 | return 0; |
| 578 | } |
| 579 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 580 | static int efx_mcdi_phy_test_alive(struct efx_nic *efx) |
| 581 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 582 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_STATE_OUT_LEN); |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 583 | size_t outlen; |
| 584 | int rc; |
| 585 | |
| 586 | BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0); |
| 587 | |
| 588 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0, |
| 589 | outbuf, sizeof(outbuf), &outlen); |
| 590 | if (rc) |
| 591 | return rc; |
| 592 | |
| 593 | if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN) |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 594 | return -EIO; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 595 | if (MCDI_DWORD(outbuf, GET_PHY_STATE_OUT_STATE) != MC_CMD_PHY_STATE_OK) |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 596 | return -EINVAL; |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 601 | static const char *const mcdi_sft9001_cable_diag_names[] = { |
| 602 | "cable.pairA.length", |
| 603 | "cable.pairB.length", |
| 604 | "cable.pairC.length", |
| 605 | "cable.pairD.length", |
| 606 | "cable.pairA.status", |
| 607 | "cable.pairB.status", |
| 608 | "cable.pairC.status", |
| 609 | "cable.pairD.status", |
| 610 | }; |
| 611 | |
| 612 | static int efx_mcdi_bist(struct efx_nic *efx, unsigned int bist_mode, |
| 613 | int *results) |
| 614 | { |
| 615 | unsigned int retry, i, count = 0; |
| 616 | size_t outlen; |
| 617 | u32 status; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame^] | 618 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); |
| 619 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_SFT9001_LEN); |
| 620 | u8 *ptr; |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 621 | int rc; |
| 622 | |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 623 | BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN != 0); |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame^] | 624 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_mode); |
| 625 | rc = efx_mcdi_rpc(efx, MC_CMD_START_BIST, |
| 626 | inbuf, MC_CMD_START_BIST_IN_LEN, NULL, 0, NULL); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 627 | if (rc) |
| 628 | goto out; |
| 629 | |
| 630 | /* Wait up to 10s for BIST to finish */ |
| 631 | for (retry = 0; retry < 100; ++retry) { |
| 632 | BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN != 0); |
| 633 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame^] | 634 | outbuf, sizeof(outbuf), &outlen); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 635 | if (rc) |
| 636 | goto out; |
| 637 | |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame^] | 638 | status = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 639 | if (status != MC_CMD_POLL_BIST_RUNNING) |
| 640 | goto finished; |
| 641 | |
| 642 | msleep(100); |
| 643 | } |
| 644 | |
| 645 | rc = -ETIMEDOUT; |
| 646 | goto out; |
| 647 | |
| 648 | finished: |
| 649 | results[count++] = (status == MC_CMD_POLL_BIST_PASSED) ? 1 : -1; |
| 650 | |
| 651 | /* SFT9001 specific cable diagnostics output */ |
| 652 | if (efx->phy_type == PHY_TYPE_SFT9001B && |
| 653 | (bist_mode == MC_CMD_PHY_BIST_CABLE_SHORT || |
| 654 | bist_mode == MC_CMD_PHY_BIST_CABLE_LONG)) { |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame^] | 655 | ptr = MCDI_PTR(outbuf, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 656 | if (status == MC_CMD_POLL_BIST_PASSED && |
| 657 | outlen >= MC_CMD_POLL_BIST_OUT_SFT9001_LEN) { |
| 658 | for (i = 0; i < 8; i++) { |
| 659 | results[count + i] = |
| 660 | EFX_DWORD_FIELD(((efx_dword_t *)ptr)[i], |
| 661 | EFX_DWORD_0); |
| 662 | } |
| 663 | } |
| 664 | count += 8; |
| 665 | } |
| 666 | rc = count; |
| 667 | |
| 668 | out: |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 669 | return rc; |
| 670 | } |
| 671 | |
| 672 | static int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results, |
| 673 | unsigned flags) |
| 674 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 675 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 676 | u32 mode; |
| 677 | int rc; |
| 678 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 679 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) { |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 680 | rc = efx_mcdi_bist(efx, MC_CMD_PHY_BIST, results); |
| 681 | if (rc < 0) |
| 682 | return rc; |
| 683 | |
| 684 | results += rc; |
| 685 | } |
| 686 | |
| 687 | /* If we support both LONG and SHORT, then run each in response to |
| 688 | * break or not. Otherwise, run the one we support */ |
| 689 | mode = 0; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 690 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN)) { |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 691 | if ((flags & ETH_TEST_FL_OFFLINE) && |
| 692 | (phy_cfg->flags & |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 693 | (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 694 | mode = MC_CMD_PHY_BIST_CABLE_LONG; |
| 695 | else |
| 696 | mode = MC_CMD_PHY_BIST_CABLE_SHORT; |
| 697 | } else if (phy_cfg->flags & |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 698 | (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN)) |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 699 | mode = MC_CMD_PHY_BIST_CABLE_LONG; |
| 700 | |
| 701 | if (mode != 0) { |
| 702 | rc = efx_mcdi_bist(efx, mode, results); |
| 703 | if (rc < 0) |
| 704 | return rc; |
| 705 | results += rc; |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 711 | static const char *efx_mcdi_phy_test_name(struct efx_nic *efx, |
| 712 | unsigned int index) |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 713 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 714 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 715 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 716 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) { |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 717 | if (index == 0) |
| 718 | return "bist"; |
| 719 | --index; |
| 720 | } |
| 721 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 722 | if (phy_cfg->flags & ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN) | |
| 723 | (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) { |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 724 | if (index == 0) |
| 725 | return "cable"; |
| 726 | --index; |
| 727 | |
| 728 | if (efx->phy_type == PHY_TYPE_SFT9001B) { |
| 729 | if (index < ARRAY_SIZE(mcdi_sft9001_cable_diag_names)) |
| 730 | return mcdi_sft9001_cable_diag_names[index]; |
| 731 | index -= ARRAY_SIZE(mcdi_sft9001_cable_diag_names); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | return NULL; |
| 736 | } |
| 737 | |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 738 | #define SFP_PAGE_SIZE 128 |
| 739 | #define SFP_NUM_PAGES 2 |
| 740 | static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx, |
| 741 | struct ethtool_eeprom *ee, u8 *data) |
| 742 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 743 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX); |
| 744 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN); |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 745 | size_t outlen; |
| 746 | int rc; |
| 747 | unsigned int payload_len; |
| 748 | unsigned int space_remaining = ee->len; |
| 749 | unsigned int page; |
| 750 | unsigned int page_off; |
| 751 | unsigned int to_copy; |
| 752 | u8 *user_data = data; |
| 753 | |
| 754 | BUILD_BUG_ON(SFP_PAGE_SIZE * SFP_NUM_PAGES != ETH_MODULE_SFF_8079_LEN); |
| 755 | |
| 756 | page_off = ee->offset % SFP_PAGE_SIZE; |
| 757 | page = ee->offset / SFP_PAGE_SIZE; |
| 758 | |
| 759 | while (space_remaining && (page < SFP_NUM_PAGES)) { |
| 760 | MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page); |
| 761 | |
| 762 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_MEDIA_INFO, |
| 763 | inbuf, sizeof(inbuf), |
| 764 | outbuf, sizeof(outbuf), |
| 765 | &outlen); |
| 766 | if (rc) |
| 767 | return rc; |
| 768 | |
| 769 | if (outlen < (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST + |
| 770 | SFP_PAGE_SIZE)) |
| 771 | return -EIO; |
| 772 | |
| 773 | payload_len = MCDI_DWORD(outbuf, |
| 774 | GET_PHY_MEDIA_INFO_OUT_DATALEN); |
| 775 | if (payload_len != SFP_PAGE_SIZE) |
| 776 | return -EIO; |
| 777 | |
| 778 | /* Copy as much as we can into data */ |
| 779 | payload_len -= page_off; |
| 780 | to_copy = (space_remaining < payload_len) ? |
| 781 | space_remaining : payload_len; |
| 782 | |
| 783 | memcpy(user_data, |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame^] | 784 | MCDI_PTR(outbuf, GET_PHY_MEDIA_INFO_OUT_DATA) + page_off, |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 785 | to_copy); |
| 786 | |
| 787 | space_remaining -= to_copy; |
| 788 | user_data += to_copy; |
| 789 | page_off = 0; |
| 790 | page++; |
| 791 | } |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static int efx_mcdi_phy_get_module_info(struct efx_nic *efx, |
| 797 | struct ethtool_modinfo *modinfo) |
| 798 | { |
| 799 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
| 800 | |
| 801 | switch (phy_cfg->media) { |
| 802 | case MC_CMD_MEDIA_SFP_PLUS: |
| 803 | modinfo->type = ETH_MODULE_SFF_8079; |
| 804 | modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; |
| 805 | return 0; |
| 806 | default: |
| 807 | return -EOPNOTSUPP; |
| 808 | } |
| 809 | } |
| 810 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 811 | const struct efx_phy_operations efx_mcdi_phy_ops = { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 812 | .probe = efx_mcdi_phy_probe, |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 813 | .init = efx_port_dummy_op_int, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 814 | .reconfigure = efx_mcdi_phy_reconfigure, |
| 815 | .poll = efx_mcdi_phy_poll, |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 816 | .fini = efx_port_dummy_op_void, |
| 817 | .remove = efx_mcdi_phy_remove, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 818 | .get_settings = efx_mcdi_phy_get_settings, |
| 819 | .set_settings = efx_mcdi_phy_set_settings, |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 820 | .test_alive = efx_mcdi_phy_test_alive, |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 821 | .run_tests = efx_mcdi_phy_run_tests, |
| 822 | .test_name = efx_mcdi_phy_test_name, |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 823 | .get_module_eeprom = efx_mcdi_phy_get_module_eeprom, |
| 824 | .get_module_info = efx_mcdi_phy_get_module_info, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 825 | }; |