Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 2 | * Driver for Solarflare network controllers and boards |
| 3 | * Copyright 2009-2013 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 | |
Ben Hutchings | f2b0bef | 2013-08-20 20:35:50 +0100 | [diff] [blame] | 114 | if (outlen < (MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_OFST + |
| 115 | MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_LEN)) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 116 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 117 | goto fail; |
| 118 | } |
| 119 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 120 | *loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_OUT_SUGGESTED); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | |
| 124 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 125 | 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] | 126 | return rc; |
| 127 | } |
| 128 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 129 | static int efx_mcdi_mdio_read(struct net_device *net_dev, |
| 130 | int prtad, int devad, u16 addr) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 131 | { |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 132 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 133 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_READ_IN_LEN); |
| 134 | MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_READ_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 135 | size_t outlen; |
| 136 | int rc; |
| 137 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 138 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, efx->mdio_bus); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 139 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad); |
| 140 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad); |
| 141 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr); |
| 142 | |
| 143 | rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf), |
| 144 | outbuf, sizeof(outbuf), &outlen); |
| 145 | if (rc) |
| 146 | goto fail; |
| 147 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 148 | if (MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS) != |
| 149 | MC_CMD_MDIO_STATUS_GOOD) |
| 150 | return -EIO; |
| 151 | |
| 152 | return (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 153 | |
| 154 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 155 | 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] | 156 | return rc; |
| 157 | } |
| 158 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 159 | static int efx_mcdi_mdio_write(struct net_device *net_dev, |
| 160 | int prtad, int devad, u16 addr, u16 value) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 161 | { |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 162 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 163 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_WRITE_IN_LEN); |
| 164 | MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_WRITE_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 165 | size_t outlen; |
| 166 | int rc; |
| 167 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 168 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, efx->mdio_bus); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 169 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad); |
| 170 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad); |
| 171 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr); |
| 172 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value); |
| 173 | |
| 174 | rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf), |
| 175 | outbuf, sizeof(outbuf), &outlen); |
| 176 | if (rc) |
| 177 | goto fail; |
| 178 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 179 | if (MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS) != |
| 180 | MC_CMD_MDIO_STATUS_GOOD) |
| 181 | return -EIO; |
| 182 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 183 | return 0; |
| 184 | |
| 185 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 186 | 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] | 187 | return rc; |
| 188 | } |
| 189 | |
| 190 | static u32 mcdi_to_ethtool_cap(u32 media, u32 cap) |
| 191 | { |
| 192 | u32 result = 0; |
| 193 | |
| 194 | switch (media) { |
| 195 | case MC_CMD_MEDIA_KX4: |
| 196 | result |= SUPPORTED_Backplane; |
| 197 | if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN)) |
| 198 | result |= SUPPORTED_1000baseKX_Full; |
| 199 | if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN)) |
| 200 | result |= SUPPORTED_10000baseKX4_Full; |
| 201 | break; |
| 202 | |
| 203 | case MC_CMD_MEDIA_XFP: |
| 204 | case MC_CMD_MEDIA_SFP_PLUS: |
| 205 | result |= SUPPORTED_FIBRE; |
| 206 | break; |
| 207 | |
| 208 | case MC_CMD_MEDIA_BASE_T: |
| 209 | result |= SUPPORTED_TP; |
| 210 | if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN)) |
| 211 | result |= SUPPORTED_10baseT_Half; |
| 212 | if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN)) |
| 213 | result |= SUPPORTED_10baseT_Full; |
| 214 | if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN)) |
| 215 | result |= SUPPORTED_100baseT_Half; |
| 216 | if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN)) |
| 217 | result |= SUPPORTED_100baseT_Full; |
| 218 | if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN)) |
| 219 | result |= SUPPORTED_1000baseT_Half; |
| 220 | if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN)) |
| 221 | result |= SUPPORTED_1000baseT_Full; |
| 222 | if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN)) |
| 223 | result |= SUPPORTED_10000baseT_Full; |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN)) |
| 228 | result |= SUPPORTED_Pause; |
| 229 | if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) |
| 230 | result |= SUPPORTED_Asym_Pause; |
| 231 | if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
| 232 | result |= SUPPORTED_Autoneg; |
| 233 | |
| 234 | return result; |
| 235 | } |
| 236 | |
| 237 | static u32 ethtool_to_mcdi_cap(u32 cap) |
| 238 | { |
| 239 | u32 result = 0; |
| 240 | |
| 241 | if (cap & SUPPORTED_10baseT_Half) |
| 242 | result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN); |
| 243 | if (cap & SUPPORTED_10baseT_Full) |
| 244 | result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN); |
| 245 | if (cap & SUPPORTED_100baseT_Half) |
| 246 | result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN); |
| 247 | if (cap & SUPPORTED_100baseT_Full) |
| 248 | result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN); |
| 249 | if (cap & SUPPORTED_1000baseT_Half) |
| 250 | result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN); |
| 251 | if (cap & (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseKX_Full)) |
| 252 | result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN); |
| 253 | if (cap & (SUPPORTED_10000baseT_Full | SUPPORTED_10000baseKX4_Full)) |
| 254 | result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN); |
| 255 | if (cap & SUPPORTED_Pause) |
| 256 | result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN); |
| 257 | if (cap & SUPPORTED_Asym_Pause) |
| 258 | result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN); |
| 259 | if (cap & SUPPORTED_Autoneg) |
| 260 | result |= (1 << MC_CMD_PHY_CAP_AN_LBN); |
| 261 | |
| 262 | return result; |
| 263 | } |
| 264 | |
| 265 | static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx) |
| 266 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 267 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 268 | enum efx_phy_mode mode, supported; |
| 269 | u32 flags; |
| 270 | |
| 271 | /* TODO: Advertise the capabilities supported by this PHY */ |
| 272 | supported = 0; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 273 | 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] | 274 | supported |= PHY_MODE_TX_DISABLED; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 275 | 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] | 276 | supported |= PHY_MODE_LOW_POWER; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 277 | 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] | 278 | supported |= PHY_MODE_OFF; |
| 279 | |
| 280 | mode = efx->phy_mode & supported; |
| 281 | |
| 282 | flags = 0; |
| 283 | if (mode & PHY_MODE_TX_DISABLED) |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 284 | flags |= (1 << MC_CMD_SET_LINK_IN_TXDIS_LBN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 285 | if (mode & PHY_MODE_LOW_POWER) |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 286 | flags |= (1 << MC_CMD_SET_LINK_IN_LOWPOWER_LBN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 287 | if (mode & PHY_MODE_OFF) |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 288 | flags |= (1 << MC_CMD_SET_LINK_IN_POWEROFF_LBN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 289 | |
| 290 | return flags; |
| 291 | } |
| 292 | |
| 293 | static u32 mcdi_to_ethtool_media(u32 media) |
| 294 | { |
| 295 | switch (media) { |
| 296 | case MC_CMD_MEDIA_XAUI: |
| 297 | case MC_CMD_MEDIA_CX4: |
| 298 | case MC_CMD_MEDIA_KX4: |
| 299 | return PORT_OTHER; |
| 300 | |
| 301 | case MC_CMD_MEDIA_XFP: |
| 302 | case MC_CMD_MEDIA_SFP_PLUS: |
| 303 | return PORT_FIBRE; |
| 304 | |
| 305 | case MC_CMD_MEDIA_BASE_T: |
| 306 | return PORT_TP; |
| 307 | |
| 308 | default: |
| 309 | return PORT_OTHER; |
| 310 | } |
| 311 | } |
| 312 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 313 | static void efx_mcdi_phy_decode_link(struct efx_nic *efx, |
| 314 | struct efx_link_state *link_state, |
| 315 | u32 speed, u32 flags, u32 fcntl) |
| 316 | { |
| 317 | switch (fcntl) { |
| 318 | case MC_CMD_FCNTL_AUTO: |
| 319 | WARN_ON(1); /* This is not a link mode */ |
| 320 | link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX; |
| 321 | break; |
| 322 | case MC_CMD_FCNTL_BIDIR: |
| 323 | link_state->fc = EFX_FC_TX | EFX_FC_RX; |
| 324 | break; |
| 325 | case MC_CMD_FCNTL_RESPOND: |
| 326 | link_state->fc = EFX_FC_RX; |
| 327 | break; |
| 328 | default: |
| 329 | WARN_ON(1); |
| 330 | case MC_CMD_FCNTL_OFF: |
| 331 | link_state->fc = 0; |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN)); |
| 336 | link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN)); |
| 337 | link_state->speed = speed; |
| 338 | } |
| 339 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 340 | static int efx_mcdi_phy_probe(struct efx_nic *efx) |
| 341 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 342 | struct efx_mcdi_phy_data *phy_data; |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 343 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 344 | u32 caps; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 345 | int rc; |
| 346 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 347 | /* Initialise and populate phy_data */ |
| 348 | phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL); |
| 349 | if (phy_data == NULL) |
| 350 | return -ENOMEM; |
| 351 | |
| 352 | rc = efx_mcdi_get_phy_cfg(efx, phy_data); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 353 | if (rc != 0) |
| 354 | goto fail; |
| 355 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 356 | /* Read initial link advertisement */ |
| 357 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 358 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 359 | outbuf, sizeof(outbuf), NULL); |
| 360 | if (rc) |
| 361 | goto fail; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 362 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 363 | /* Fill out nic state */ |
| 364 | efx->phy_data = phy_data; |
| 365 | efx->phy_type = phy_data->type; |
| 366 | |
| 367 | efx->mdio_bus = phy_data->channel; |
| 368 | efx->mdio.prtad = phy_data->port; |
| 369 | efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 370 | efx->mdio.mode_support = 0; |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 371 | if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 372 | efx->mdio.mode_support |= MDIO_SUPPORTS_C22; |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 373 | if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 374 | efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 375 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 376 | caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP); |
| 377 | if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
| 378 | efx->link_advertising = |
| 379 | mcdi_to_ethtool_cap(phy_data->media, caps); |
| 380 | else |
| 381 | phy_data->forced_cap = caps; |
| 382 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 383 | /* Assert that we can map efx -> mcdi loopback modes */ |
| 384 | BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE); |
| 385 | BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA); |
| 386 | BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC); |
| 387 | BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII); |
| 388 | BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS); |
| 389 | BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI); |
| 390 | BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII); |
| 391 | BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII); |
| 392 | BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR); |
| 393 | BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI); |
| 394 | BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR); |
| 395 | BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR); |
| 396 | BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR); |
| 397 | BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR); |
| 398 | BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY); |
| 399 | BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS); |
| 400 | BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS); |
| 401 | BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD); |
| 402 | BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT); |
| 403 | BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS); |
| 404 | BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS); |
| 405 | BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR); |
| 406 | BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR); |
| 407 | BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS); |
| 408 | BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS); |
| 409 | BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR); |
| 410 | BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS); |
| 411 | |
| 412 | rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes); |
| 413 | if (rc != 0) |
| 414 | goto fail; |
| 415 | /* The MC indicates that LOOPBACK_NONE is a valid loopback mode, |
| 416 | * but by convention we don't */ |
| 417 | efx->loopback_modes &= ~(1 << LOOPBACK_NONE); |
| 418 | |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 419 | /* Set the initial link mode */ |
| 420 | efx_mcdi_phy_decode_link( |
| 421 | efx, &efx->link_state, |
| 422 | MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED), |
| 423 | MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS), |
| 424 | MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL)); |
| 425 | |
| 426 | /* Default to Autonegotiated flow control if the PHY supports it */ |
| 427 | efx->wanted_fc = EFX_FC_RX | EFX_FC_TX; |
| 428 | if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
| 429 | efx->wanted_fc |= EFX_FC_AUTO; |
Steve Hodgson | cffe9d4 | 2010-06-01 11:18:08 +0000 | [diff] [blame] | 430 | efx_link_set_wanted_fc(efx, efx->wanted_fc); |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 431 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 432 | return 0; |
| 433 | |
| 434 | fail: |
| 435 | kfree(phy_data); |
| 436 | return rc; |
| 437 | } |
| 438 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 439 | int efx_mcdi_port_reconfigure(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 440 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 441 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 442 | u32 caps = (efx->link_advertising ? |
| 443 | ethtool_to_mcdi_cap(efx->link_advertising) : |
| 444 | phy_cfg->forced_cap); |
| 445 | |
| 446 | return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx), |
| 447 | efx->loopback_mode, 0); |
| 448 | } |
| 449 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 450 | /* Verify that the forced flow control settings (!EFX_FC_AUTO) are |
| 451 | * supported by the link partner. Warn the user if this isn't the case |
| 452 | */ |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 453 | static void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 454 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 455 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 456 | u32 rmtadv; |
| 457 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 458 | /* The link partner capabilities are only relevant if the |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 459 | * link supports flow control autonegotiation */ |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 460 | if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 461 | return; |
| 462 | |
| 463 | /* If flow control autoneg is supported and enabled, then fine */ |
| 464 | if (efx->wanted_fc & EFX_FC_AUTO) |
| 465 | return; |
| 466 | |
| 467 | rmtadv = 0; |
| 468 | if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN)) |
| 469 | rmtadv |= ADVERTISED_Pause; |
| 470 | if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) |
| 471 | rmtadv |= ADVERTISED_Asym_Pause; |
| 472 | |
| 473 | if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 474 | netif_err(efx, link, efx->net_dev, |
| 475 | "warning: link partner doesn't support pause frames"); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static bool efx_mcdi_phy_poll(struct efx_nic *efx) |
| 479 | { |
| 480 | struct efx_link_state old_state = efx->link_state; |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 481 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 482 | int rc; |
| 483 | |
| 484 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 485 | |
| 486 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 487 | |
| 488 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 489 | outbuf, sizeof(outbuf), NULL); |
| 490 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 491 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 492 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 493 | efx->link_state.up = false; |
| 494 | } else { |
| 495 | efx_mcdi_phy_decode_link( |
| 496 | efx, &efx->link_state, |
| 497 | MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED), |
| 498 | MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS), |
| 499 | MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL)); |
| 500 | } |
| 501 | |
| 502 | return !efx_link_state_equal(&efx->link_state, &old_state); |
| 503 | } |
| 504 | |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 505 | static void efx_mcdi_phy_remove(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 506 | { |
| 507 | struct efx_mcdi_phy_data *phy_data = efx->phy_data; |
| 508 | |
| 509 | efx->phy_data = NULL; |
| 510 | kfree(phy_data); |
| 511 | } |
| 512 | |
| 513 | static void efx_mcdi_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
| 514 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 515 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 516 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 517 | int rc; |
| 518 | |
| 519 | ecmd->supported = |
| 520 | mcdi_to_ethtool_cap(phy_cfg->media, phy_cfg->supported_cap); |
| 521 | ecmd->advertising = efx->link_advertising; |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 522 | ethtool_cmd_speed_set(ecmd, efx->link_state.speed); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 523 | ecmd->duplex = efx->link_state.fd; |
| 524 | ecmd->port = mcdi_to_ethtool_media(phy_cfg->media); |
| 525 | ecmd->phy_address = phy_cfg->port; |
| 526 | ecmd->transceiver = XCVR_INTERNAL; |
| 527 | ecmd->autoneg = !!(efx->link_advertising & ADVERTISED_Autoneg); |
| 528 | ecmd->mdio_support = (efx->mdio.mode_support & |
| 529 | (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22)); |
| 530 | |
| 531 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 532 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 533 | outbuf, sizeof(outbuf), NULL); |
| 534 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 535 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 536 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 537 | return; |
| 538 | } |
| 539 | ecmd->lp_advertising = |
| 540 | mcdi_to_ethtool_cap(phy_cfg->media, |
| 541 | MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP)); |
| 542 | } |
| 543 | |
| 544 | static int efx_mcdi_phy_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) |
| 545 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 546 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 547 | u32 caps; |
| 548 | int rc; |
| 549 | |
| 550 | if (ecmd->autoneg) { |
| 551 | caps = (ethtool_to_mcdi_cap(ecmd->advertising) | |
| 552 | 1 << MC_CMD_PHY_CAP_AN_LBN); |
| 553 | } else if (ecmd->duplex) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 554 | switch (ethtool_cmd_speed(ecmd)) { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 555 | case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break; |
| 556 | case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break; |
| 557 | case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break; |
| 558 | case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break; |
Ben Hutchings | 9a12a30 | 2013-09-05 17:53:57 +0100 | [diff] [blame^] | 559 | case 40000: caps = 1 << MC_CMD_PHY_CAP_40000FDX_LBN; break; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 560 | default: return -EINVAL; |
| 561 | } |
| 562 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 563 | switch (ethtool_cmd_speed(ecmd)) { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 564 | case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break; |
| 565 | case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break; |
| 566 | case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break; |
| 567 | default: return -EINVAL; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx), |
| 572 | efx->loopback_mode, 0); |
| 573 | if (rc) |
| 574 | return rc; |
| 575 | |
| 576 | if (ecmd->autoneg) { |
| 577 | efx_link_set_advertising( |
| 578 | efx, ecmd->advertising | ADVERTISED_Autoneg); |
| 579 | phy_cfg->forced_cap = 0; |
| 580 | } else { |
| 581 | efx_link_set_advertising(efx, 0); |
| 582 | phy_cfg->forced_cap = caps; |
| 583 | } |
| 584 | return 0; |
| 585 | } |
| 586 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 587 | static int efx_mcdi_phy_test_alive(struct efx_nic *efx) |
| 588 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 589 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_STATE_OUT_LEN); |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 590 | size_t outlen; |
| 591 | int rc; |
| 592 | |
| 593 | BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0); |
| 594 | |
| 595 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0, |
| 596 | outbuf, sizeof(outbuf), &outlen); |
| 597 | if (rc) |
| 598 | return rc; |
| 599 | |
| 600 | if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN) |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 601 | return -EIO; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 602 | 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] | 603 | return -EINVAL; |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 608 | static const char *const mcdi_sft9001_cable_diag_names[] = { |
| 609 | "cable.pairA.length", |
| 610 | "cable.pairB.length", |
| 611 | "cable.pairC.length", |
| 612 | "cable.pairD.length", |
| 613 | "cable.pairA.status", |
| 614 | "cable.pairB.status", |
| 615 | "cable.pairC.status", |
| 616 | "cable.pairD.status", |
| 617 | }; |
| 618 | |
| 619 | static int efx_mcdi_bist(struct efx_nic *efx, unsigned int bist_mode, |
| 620 | int *results) |
| 621 | { |
| 622 | unsigned int retry, i, count = 0; |
| 623 | size_t outlen; |
| 624 | u32 status; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 625 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); |
| 626 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_SFT9001_LEN); |
| 627 | u8 *ptr; |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 628 | int rc; |
| 629 | |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 630 | BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN != 0); |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 631 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_mode); |
| 632 | rc = efx_mcdi_rpc(efx, MC_CMD_START_BIST, |
| 633 | inbuf, MC_CMD_START_BIST_IN_LEN, NULL, 0, NULL); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 634 | if (rc) |
| 635 | goto out; |
| 636 | |
| 637 | /* Wait up to 10s for BIST to finish */ |
| 638 | for (retry = 0; retry < 100; ++retry) { |
| 639 | BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN != 0); |
| 640 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 641 | outbuf, sizeof(outbuf), &outlen); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 642 | if (rc) |
| 643 | goto out; |
| 644 | |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 645 | status = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 646 | if (status != MC_CMD_POLL_BIST_RUNNING) |
| 647 | goto finished; |
| 648 | |
| 649 | msleep(100); |
| 650 | } |
| 651 | |
| 652 | rc = -ETIMEDOUT; |
| 653 | goto out; |
| 654 | |
| 655 | finished: |
| 656 | results[count++] = (status == MC_CMD_POLL_BIST_PASSED) ? 1 : -1; |
| 657 | |
| 658 | /* SFT9001 specific cable diagnostics output */ |
| 659 | if (efx->phy_type == PHY_TYPE_SFT9001B && |
| 660 | (bist_mode == MC_CMD_PHY_BIST_CABLE_SHORT || |
| 661 | bist_mode == MC_CMD_PHY_BIST_CABLE_LONG)) { |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 662 | ptr = MCDI_PTR(outbuf, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A); |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 663 | if (status == MC_CMD_POLL_BIST_PASSED && |
| 664 | outlen >= MC_CMD_POLL_BIST_OUT_SFT9001_LEN) { |
| 665 | for (i = 0; i < 8; i++) { |
| 666 | results[count + i] = |
| 667 | EFX_DWORD_FIELD(((efx_dword_t *)ptr)[i], |
| 668 | EFX_DWORD_0); |
| 669 | } |
| 670 | } |
| 671 | count += 8; |
| 672 | } |
| 673 | rc = count; |
| 674 | |
| 675 | out: |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 676 | return rc; |
| 677 | } |
| 678 | |
| 679 | static int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results, |
| 680 | unsigned flags) |
| 681 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 682 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 683 | u32 mode; |
| 684 | int rc; |
| 685 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 686 | 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] | 687 | rc = efx_mcdi_bist(efx, MC_CMD_PHY_BIST, results); |
| 688 | if (rc < 0) |
| 689 | return rc; |
| 690 | |
| 691 | results += rc; |
| 692 | } |
| 693 | |
| 694 | /* If we support both LONG and SHORT, then run each in response to |
| 695 | * break or not. Otherwise, run the one we support */ |
| 696 | mode = 0; |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 697 | 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] | 698 | if ((flags & ETH_TEST_FL_OFFLINE) && |
| 699 | (phy_cfg->flags & |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 700 | (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 701 | mode = MC_CMD_PHY_BIST_CABLE_LONG; |
| 702 | else |
| 703 | mode = MC_CMD_PHY_BIST_CABLE_SHORT; |
| 704 | } else if (phy_cfg->flags & |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 705 | (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN)) |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 706 | mode = MC_CMD_PHY_BIST_CABLE_LONG; |
| 707 | |
| 708 | if (mode != 0) { |
| 709 | rc = efx_mcdi_bist(efx, mode, results); |
| 710 | if (rc < 0) |
| 711 | return rc; |
| 712 | results += rc; |
| 713 | } |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 718 | static const char *efx_mcdi_phy_test_name(struct efx_nic *efx, |
| 719 | unsigned int index) |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 720 | { |
Ben Hutchings | 3bd9303 | 2010-06-01 11:17:06 +0000 | [diff] [blame] | 721 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 722 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 723 | 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] | 724 | if (index == 0) |
| 725 | return "bist"; |
| 726 | --index; |
| 727 | } |
| 728 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 729 | if (phy_cfg->flags & ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN) | |
| 730 | (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) { |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 731 | if (index == 0) |
| 732 | return "cable"; |
| 733 | --index; |
| 734 | |
| 735 | if (efx->phy_type == PHY_TYPE_SFT9001B) { |
| 736 | if (index < ARRAY_SIZE(mcdi_sft9001_cable_diag_names)) |
| 737 | return mcdi_sft9001_cable_diag_names[index]; |
| 738 | index -= ARRAY_SIZE(mcdi_sft9001_cable_diag_names); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return NULL; |
| 743 | } |
| 744 | |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 745 | #define SFP_PAGE_SIZE 128 |
| 746 | #define SFP_NUM_PAGES 2 |
| 747 | static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx, |
| 748 | struct ethtool_eeprom *ee, u8 *data) |
| 749 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 750 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX); |
| 751 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN); |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 752 | size_t outlen; |
| 753 | int rc; |
| 754 | unsigned int payload_len; |
| 755 | unsigned int space_remaining = ee->len; |
| 756 | unsigned int page; |
| 757 | unsigned int page_off; |
| 758 | unsigned int to_copy; |
| 759 | u8 *user_data = data; |
| 760 | |
| 761 | BUILD_BUG_ON(SFP_PAGE_SIZE * SFP_NUM_PAGES != ETH_MODULE_SFF_8079_LEN); |
| 762 | |
| 763 | page_off = ee->offset % SFP_PAGE_SIZE; |
| 764 | page = ee->offset / SFP_PAGE_SIZE; |
| 765 | |
| 766 | while (space_remaining && (page < SFP_NUM_PAGES)) { |
| 767 | MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page); |
| 768 | |
| 769 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_MEDIA_INFO, |
| 770 | inbuf, sizeof(inbuf), |
| 771 | outbuf, sizeof(outbuf), |
| 772 | &outlen); |
| 773 | if (rc) |
| 774 | return rc; |
| 775 | |
| 776 | if (outlen < (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST + |
| 777 | SFP_PAGE_SIZE)) |
| 778 | return -EIO; |
| 779 | |
| 780 | payload_len = MCDI_DWORD(outbuf, |
| 781 | GET_PHY_MEDIA_INFO_OUT_DATALEN); |
| 782 | if (payload_len != SFP_PAGE_SIZE) |
| 783 | return -EIO; |
| 784 | |
| 785 | /* Copy as much as we can into data */ |
| 786 | payload_len -= page_off; |
| 787 | to_copy = (space_remaining < payload_len) ? |
| 788 | space_remaining : payload_len; |
| 789 | |
| 790 | memcpy(user_data, |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 791 | MCDI_PTR(outbuf, GET_PHY_MEDIA_INFO_OUT_DATA) + page_off, |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 792 | to_copy); |
| 793 | |
| 794 | space_remaining -= to_copy; |
| 795 | user_data += to_copy; |
| 796 | page_off = 0; |
| 797 | page++; |
| 798 | } |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static int efx_mcdi_phy_get_module_info(struct efx_nic *efx, |
| 804 | struct ethtool_modinfo *modinfo) |
| 805 | { |
| 806 | struct efx_mcdi_phy_data *phy_cfg = efx->phy_data; |
| 807 | |
| 808 | switch (phy_cfg->media) { |
| 809 | case MC_CMD_MEDIA_SFP_PLUS: |
| 810 | modinfo->type = ETH_MODULE_SFF_8079; |
| 811 | modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; |
| 812 | return 0; |
| 813 | default: |
| 814 | return -EOPNOTSUPP; |
| 815 | } |
| 816 | } |
| 817 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 818 | static const struct efx_phy_operations efx_mcdi_phy_ops = { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 819 | .probe = efx_mcdi_phy_probe, |
Ben Hutchings | 9c636ba | 2012-01-05 17:19:45 +0000 | [diff] [blame] | 820 | .init = efx_port_dummy_op_int, |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 821 | .reconfigure = efx_mcdi_port_reconfigure, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 822 | .poll = efx_mcdi_phy_poll, |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 823 | .fini = efx_port_dummy_op_void, |
| 824 | .remove = efx_mcdi_phy_remove, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 825 | .get_settings = efx_mcdi_phy_get_settings, |
| 826 | .set_settings = efx_mcdi_phy_set_settings, |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 827 | .test_alive = efx_mcdi_phy_test_alive, |
Steve Hodgson | affaf48 | 2010-04-28 09:30:22 +0000 | [diff] [blame] | 828 | .run_tests = efx_mcdi_phy_run_tests, |
| 829 | .test_name = efx_mcdi_phy_test_name, |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 830 | .get_module_eeprom = efx_mcdi_phy_get_module_eeprom, |
| 831 | .get_module_info = efx_mcdi_phy_get_module_info, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 832 | }; |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 833 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 834 | u32 efx_mcdi_phy_get_caps(struct efx_nic *efx) |
| 835 | { |
| 836 | struct efx_mcdi_phy_data *phy_data = efx->phy_data; |
| 837 | |
| 838 | return phy_data->supported_cap; |
| 839 | } |
| 840 | |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 841 | static unsigned int efx_mcdi_event_link_speed[] = { |
| 842 | [MCDI_EVENT_LINKCHANGE_SPEED_100M] = 100, |
| 843 | [MCDI_EVENT_LINKCHANGE_SPEED_1G] = 1000, |
| 844 | [MCDI_EVENT_LINKCHANGE_SPEED_10G] = 10000, |
Ben Hutchings | 9a12a30 | 2013-09-05 17:53:57 +0100 | [diff] [blame^] | 845 | [MCDI_EVENT_LINKCHANGE_SPEED_40G] = 40000, |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 846 | }; |
| 847 | |
| 848 | void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev) |
| 849 | { |
| 850 | u32 flags, fcntl, speed, lpa; |
| 851 | |
| 852 | speed = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_SPEED); |
| 853 | EFX_BUG_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed)); |
| 854 | speed = efx_mcdi_event_link_speed[speed]; |
| 855 | |
| 856 | flags = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LINK_FLAGS); |
| 857 | fcntl = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_FCNTL); |
| 858 | lpa = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LP_CAP); |
| 859 | |
| 860 | /* efx->link_state is only modified by efx_mcdi_phy_get_link(), |
| 861 | * which is only run after flushing the event queues. Therefore, it |
| 862 | * is safe to modify the link state outside of the mac_lock here. |
| 863 | */ |
| 864 | efx_mcdi_phy_decode_link(efx, &efx->link_state, speed, flags, fcntl); |
| 865 | |
| 866 | efx_mcdi_phy_check_fcntl(efx, lpa); |
| 867 | |
| 868 | efx_link_status_changed(efx); |
| 869 | } |
| 870 | |
| 871 | int efx_mcdi_set_mac(struct efx_nic *efx) |
| 872 | { |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 873 | u32 fcntl; |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 874 | MCDI_DECLARE_BUF(cmdbytes, MC_CMD_SET_MAC_IN_LEN); |
| 875 | |
| 876 | BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0); |
| 877 | |
| 878 | memcpy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR), |
| 879 | efx->net_dev->dev_addr, ETH_ALEN); |
| 880 | |
| 881 | MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU, |
| 882 | EFX_MAX_FRAME_LEN(efx->net_dev->mtu)); |
| 883 | MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0); |
| 884 | |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 885 | /* Set simple MAC filter for Siena */ |
| 886 | MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_REJECT, |
| 887 | SET_MAC_IN_REJECT_UNCST, efx->unicast_filter); |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 888 | |
| 889 | switch (efx->wanted_fc) { |
| 890 | case EFX_FC_RX | EFX_FC_TX: |
| 891 | fcntl = MC_CMD_FCNTL_BIDIR; |
| 892 | break; |
| 893 | case EFX_FC_RX: |
| 894 | fcntl = MC_CMD_FCNTL_RESPOND; |
| 895 | break; |
| 896 | default: |
| 897 | fcntl = MC_CMD_FCNTL_OFF; |
| 898 | break; |
| 899 | } |
| 900 | if (efx->wanted_fc & EFX_FC_AUTO) |
| 901 | fcntl = MC_CMD_FCNTL_AUTO; |
| 902 | if (efx->fc_disable) |
| 903 | fcntl = MC_CMD_FCNTL_OFF; |
| 904 | |
| 905 | MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl); |
| 906 | |
| 907 | return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes), |
| 908 | NULL, 0, NULL); |
| 909 | } |
| 910 | |
| 911 | bool efx_mcdi_mac_check_fault(struct efx_nic *efx) |
| 912 | { |
| 913 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN); |
| 914 | size_t outlength; |
| 915 | int rc; |
| 916 | |
| 917 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); |
| 918 | |
| 919 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, |
| 920 | outbuf, sizeof(outbuf), &outlength); |
| 921 | if (rc) { |
| 922 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 923 | __func__, rc); |
| 924 | return true; |
| 925 | } |
| 926 | |
| 927 | return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0; |
| 928 | } |
| 929 | |
| 930 | static int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr, |
| 931 | u32 dma_len, int enable, int clear) |
| 932 | { |
| 933 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN); |
| 934 | int rc; |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 935 | int period = enable ? 1000 : 0; |
| 936 | |
| 937 | BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0); |
| 938 | |
| 939 | MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, dma_addr); |
Ben Hutchings | f5253d9 | 2012-10-10 23:24:51 +0100 | [diff] [blame] | 940 | MCDI_POPULATE_DWORD_7(inbuf, MAC_STATS_IN_CMD, |
| 941 | MAC_STATS_IN_DMA, !!enable, |
| 942 | MAC_STATS_IN_CLEAR, clear, |
| 943 | MAC_STATS_IN_PERIODIC_CHANGE, 1, |
| 944 | MAC_STATS_IN_PERIODIC_ENABLE, !!enable, |
| 945 | MAC_STATS_IN_PERIODIC_CLEAR, 0, |
| 946 | MAC_STATS_IN_PERIODIC_NOEVENT, 1, |
| 947 | MAC_STATS_IN_PERIOD_MS, period); |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 948 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
| 949 | |
| 950 | rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), |
| 951 | NULL, 0, NULL); |
| 952 | if (rc) |
| 953 | goto fail; |
| 954 | |
| 955 | return 0; |
| 956 | |
| 957 | fail: |
| 958 | netif_err(efx, hw, efx->net_dev, "%s: %s failed rc=%d\n", |
| 959 | __func__, enable ? "enable" : "disable", rc); |
| 960 | return rc; |
| 961 | } |
| 962 | |
| 963 | void efx_mcdi_mac_start_stats(struct efx_nic *efx) |
| 964 | { |
| 965 | __le64 *dma_stats = efx->stats_buffer.addr; |
| 966 | |
| 967 | dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID; |
| 968 | |
| 969 | efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, |
| 970 | MC_CMD_MAC_NSTATS * sizeof(u64), 1, 0); |
| 971 | } |
| 972 | |
| 973 | void efx_mcdi_mac_stop_stats(struct efx_nic *efx) |
| 974 | { |
| 975 | efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 0); |
| 976 | } |
| 977 | |
| 978 | int efx_mcdi_port_probe(struct efx_nic *efx) |
| 979 | { |
| 980 | int rc; |
| 981 | |
| 982 | /* Hook in PHY operations table */ |
| 983 | efx->phy_op = &efx_mcdi_phy_ops; |
| 984 | |
| 985 | /* Set up MDIO structure for PHY */ |
| 986 | efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 987 | efx->mdio.mdio_read = efx_mcdi_mdio_read; |
| 988 | efx->mdio.mdio_write = efx_mcdi_mdio_write; |
| 989 | |
| 990 | /* Fill out MDIO structure, loopback modes, and initial link state */ |
| 991 | rc = efx->phy_op->probe(efx); |
| 992 | if (rc != 0) |
| 993 | return rc; |
| 994 | |
| 995 | /* Allocate buffer for stats */ |
| 996 | rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer, |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 997 | MC_CMD_MAC_NSTATS * sizeof(u64), GFP_KERNEL); |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 998 | if (rc) |
| 999 | return rc; |
| 1000 | netif_dbg(efx, probe, efx->net_dev, |
| 1001 | "stats buffer at %llx (virt %p phys %llx)\n", |
| 1002 | (u64)efx->stats_buffer.dma_addr, |
| 1003 | efx->stats_buffer.addr, |
| 1004 | (u64)virt_to_phys(efx->stats_buffer.addr)); |
| 1005 | |
| 1006 | efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 1); |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | void efx_mcdi_port_remove(struct efx_nic *efx) |
| 1012 | { |
| 1013 | efx->phy_op->remove(efx); |
| 1014 | efx_nic_free_buffer(efx, &efx->stats_buffer); |
| 1015 | } |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 1016 | |
| 1017 | /* Get physical port number (EF10 only; on Siena it is same as PF number) */ |
| 1018 | int efx_mcdi_port_get_number(struct efx_nic *efx) |
| 1019 | { |
| 1020 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN); |
| 1021 | int rc; |
| 1022 | |
| 1023 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PORT_ASSIGNMENT, NULL, 0, |
| 1024 | outbuf, sizeof(outbuf), NULL); |
| 1025 | if (rc) |
| 1026 | return rc; |
| 1027 | |
| 1028 | return MCDI_DWORD(outbuf, GET_PORT_ASSIGNMENT_OUT_PORT); |
| 1029 | } |