Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1 | /* |
| 2 | * AMD 10Gb Ethernet driver |
| 3 | * |
| 4 | * This file is available to you under your choice of the following two |
| 5 | * licenses: |
| 6 | * |
| 7 | * License 1: GPLv2 |
| 8 | * |
| 9 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 10 | * |
| 11 | * This file is free software; you may copy, redistribute and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This file is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * This file incorporates work covered by the following copyright and |
| 25 | * permission notice: |
| 26 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 27 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 28 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 29 | * and you. |
| 30 | * |
| 31 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 32 | * under any End User Software License Agreement or Agreement for Licensed |
| 33 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 34 | * granted, free of charge, to any person obtaining a copy of this software |
| 35 | * annotated with this license and the Software, to deal in the Software |
| 36 | * without restriction, including without limitation the rights to use, |
| 37 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 38 | * of the Software, and to permit persons to whom the Software is furnished |
| 39 | * to do so, subject to the following conditions: |
| 40 | * |
| 41 | * The above copyright notice and this permission notice shall be included |
| 42 | * in all copies or substantial portions of the Software. |
| 43 | * |
| 44 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 45 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 47 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 48 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 49 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 50 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 51 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 52 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 53 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 54 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 55 | * |
| 56 | * |
| 57 | * License 2: Modified BSD |
| 58 | * |
| 59 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 60 | * All rights reserved. |
| 61 | * |
| 62 | * Redistribution and use in source and binary forms, with or without |
| 63 | * modification, are permitted provided that the following conditions are met: |
| 64 | * * Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * * Redistributions in binary form must reproduce the above copyright |
| 67 | * notice, this list of conditions and the following disclaimer in the |
| 68 | * documentation and/or other materials provided with the distribution. |
| 69 | * * Neither the name of Advanced Micro Devices, Inc. nor the |
| 70 | * names of its contributors may be used to endorse or promote products |
| 71 | * derived from this software without specific prior written permission. |
| 72 | * |
| 73 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 74 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 75 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 76 | * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 77 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 78 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 79 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 80 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 81 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 82 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 83 | * |
| 84 | * This file incorporates work covered by the following copyright and |
| 85 | * permission notice: |
| 86 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 87 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 88 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 89 | * and you. |
| 90 | * |
| 91 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 92 | * under any End User Software License Agreement or Agreement for Licensed |
| 93 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 94 | * granted, free of charge, to any person obtaining a copy of this software |
| 95 | * annotated with this license and the Software, to deal in the Software |
| 96 | * without restriction, including without limitation the rights to use, |
| 97 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 98 | * of the Software, and to permit persons to whom the Software is furnished |
| 99 | * to do so, subject to the following conditions: |
| 100 | * |
| 101 | * The above copyright notice and this permission notice shall be included |
| 102 | * in all copies or substantial portions of the Software. |
| 103 | * |
| 104 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 105 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 106 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 107 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 108 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 109 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 110 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 111 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 112 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 113 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 114 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 115 | */ |
| 116 | |
| 117 | #include <linux/spinlock.h> |
| 118 | #include <linux/phy.h> |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 119 | #include <linux/net_tstamp.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 120 | |
| 121 | #include "xgbe.h" |
| 122 | #include "xgbe-common.h" |
| 123 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 124 | struct xgbe_stats { |
| 125 | char stat_string[ETH_GSTRING_LEN]; |
| 126 | int stat_size; |
| 127 | int stat_offset; |
| 128 | }; |
| 129 | |
| 130 | #define XGMAC_MMC_STAT(_string, _var) \ |
| 131 | { _string, \ |
| 132 | FIELD_SIZEOF(struct xgbe_mmc_stats, _var), \ |
| 133 | offsetof(struct xgbe_prv_data, mmc_stats._var), \ |
| 134 | } |
| 135 | |
| 136 | static const struct xgbe_stats xgbe_gstring_stats[] = { |
| 137 | XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb), |
| 138 | XGMAC_MMC_STAT("tx_packets", txframecount_gb), |
| 139 | XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb), |
| 140 | XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb), |
| 141 | XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb), |
| 142 | XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g), |
| 143 | XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb), |
| 144 | XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb), |
| 145 | XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb), |
| 146 | XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb), |
| 147 | XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb), |
| 148 | XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb), |
| 149 | XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror), |
| 150 | XGMAC_MMC_STAT("tx_pause_frames", txpauseframes), |
| 151 | |
| 152 | XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb), |
| 153 | XGMAC_MMC_STAT("rx_packets", rxframecount_gb), |
| 154 | XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g), |
| 155 | XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g), |
| 156 | XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g), |
| 157 | XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb), |
| 158 | XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb), |
| 159 | XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb), |
| 160 | XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb), |
| 161 | XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb), |
| 162 | XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb), |
| 163 | XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb), |
| 164 | XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g), |
| 165 | XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g), |
| 166 | XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror), |
| 167 | XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror), |
| 168 | XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror), |
| 169 | XGMAC_MMC_STAT("rx_length_errors", rxlengtherror), |
| 170 | XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype), |
| 171 | XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow), |
| 172 | XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror), |
| 173 | XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes), |
| 174 | }; |
Lendacky, Thomas | a2ea14d | 2014-09-03 12:14:33 -0500 | [diff] [blame] | 175 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 176 | #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats) |
| 177 | |
| 178 | static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data) |
| 179 | { |
| 180 | int i; |
| 181 | |
| 182 | DBGPR("-->%s\n", __func__); |
| 183 | |
| 184 | switch (stringset) { |
| 185 | case ETH_SS_STATS: |
| 186 | for (i = 0; i < XGBE_STATS_COUNT; i++) { |
| 187 | memcpy(data, xgbe_gstring_stats[i].stat_string, |
| 188 | ETH_GSTRING_LEN); |
| 189 | data += ETH_GSTRING_LEN; |
| 190 | } |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | DBGPR("<--%s\n", __func__); |
| 195 | } |
| 196 | |
| 197 | static void xgbe_get_ethtool_stats(struct net_device *netdev, |
| 198 | struct ethtool_stats *stats, u64 *data) |
| 199 | { |
| 200 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 201 | u8 *stat; |
| 202 | int i; |
| 203 | |
| 204 | DBGPR("-->%s\n", __func__); |
| 205 | |
| 206 | pdata->hw_if.read_mmc_stats(pdata); |
| 207 | for (i = 0; i < XGBE_STATS_COUNT; i++) { |
| 208 | stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset; |
| 209 | *data++ = *(u64 *)stat; |
| 210 | } |
| 211 | |
| 212 | DBGPR("<--%s\n", __func__); |
| 213 | } |
| 214 | |
| 215 | static int xgbe_get_sset_count(struct net_device *netdev, int stringset) |
| 216 | { |
| 217 | int ret; |
| 218 | |
| 219 | DBGPR("-->%s\n", __func__); |
| 220 | |
| 221 | switch (stringset) { |
| 222 | case ETH_SS_STATS: |
| 223 | ret = XGBE_STATS_COUNT; |
| 224 | break; |
| 225 | |
| 226 | default: |
| 227 | ret = -EOPNOTSUPP; |
| 228 | } |
| 229 | |
| 230 | DBGPR("<--%s\n", __func__); |
| 231 | |
| 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | static void xgbe_get_pauseparam(struct net_device *netdev, |
| 236 | struct ethtool_pauseparam *pause) |
| 237 | { |
| 238 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 239 | |
| 240 | DBGPR("-->xgbe_get_pauseparam\n"); |
| 241 | |
| 242 | pause->autoneg = pdata->pause_autoneg; |
| 243 | pause->tx_pause = pdata->tx_pause; |
| 244 | pause->rx_pause = pdata->rx_pause; |
| 245 | |
| 246 | DBGPR("<--xgbe_get_pauseparam\n"); |
| 247 | } |
| 248 | |
| 249 | static int xgbe_set_pauseparam(struct net_device *netdev, |
| 250 | struct ethtool_pauseparam *pause) |
| 251 | { |
| 252 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 253 | struct phy_device *phydev = pdata->phydev; |
| 254 | int ret = 0; |
| 255 | |
| 256 | DBGPR("-->xgbe_set_pauseparam\n"); |
| 257 | |
| 258 | DBGPR(" autoneg = %d, tx_pause = %d, rx_pause = %d\n", |
| 259 | pause->autoneg, pause->tx_pause, pause->rx_pause); |
| 260 | |
| 261 | pdata->pause_autoneg = pause->autoneg; |
| 262 | if (pause->autoneg) { |
| 263 | phydev->advertising |= ADVERTISED_Pause; |
| 264 | phydev->advertising |= ADVERTISED_Asym_Pause; |
| 265 | |
| 266 | } else { |
| 267 | phydev->advertising &= ~ADVERTISED_Pause; |
| 268 | phydev->advertising &= ~ADVERTISED_Asym_Pause; |
| 269 | |
| 270 | pdata->tx_pause = pause->tx_pause; |
| 271 | pdata->rx_pause = pause->rx_pause; |
| 272 | } |
| 273 | |
| 274 | if (netif_running(netdev)) |
| 275 | ret = phy_start_aneg(phydev); |
| 276 | |
| 277 | DBGPR("<--xgbe_set_pauseparam\n"); |
| 278 | |
| 279 | return ret; |
| 280 | } |
| 281 | |
| 282 | static int xgbe_get_settings(struct net_device *netdev, |
| 283 | struct ethtool_cmd *cmd) |
| 284 | { |
| 285 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 286 | int ret; |
| 287 | |
| 288 | DBGPR("-->xgbe_get_settings\n"); |
| 289 | |
| 290 | if (!pdata->phydev) |
| 291 | return -ENODEV; |
| 292 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 293 | ret = phy_ethtool_gset(pdata->phydev, cmd); |
| 294 | cmd->transceiver = XCVR_EXTERNAL; |
| 295 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 296 | DBGPR("<--xgbe_get_settings\n"); |
| 297 | |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | static int xgbe_set_settings(struct net_device *netdev, |
| 302 | struct ethtool_cmd *cmd) |
| 303 | { |
| 304 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 305 | struct phy_device *phydev = pdata->phydev; |
| 306 | u32 speed; |
| 307 | int ret; |
| 308 | |
| 309 | DBGPR("-->xgbe_set_settings\n"); |
| 310 | |
| 311 | if (!pdata->phydev) |
| 312 | return -ENODEV; |
| 313 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 314 | speed = ethtool_cmd_speed(cmd); |
| 315 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 316 | if (cmd->phy_address != phydev->addr) |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 317 | return -EINVAL; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 318 | |
| 319 | if ((cmd->autoneg != AUTONEG_ENABLE) && |
| 320 | (cmd->autoneg != AUTONEG_DISABLE)) |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 321 | return -EINVAL; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 322 | |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 323 | if (cmd->autoneg == AUTONEG_DISABLE) { |
| 324 | switch (speed) { |
| 325 | case SPEED_10000: |
| 326 | case SPEED_2500: |
| 327 | case SPEED_1000: |
| 328 | break; |
| 329 | default: |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 330 | return -EINVAL; |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | if (cmd->duplex != DUPLEX_FULL) |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 334 | return -EINVAL; |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 335 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 336 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 337 | cmd->advertising &= phydev->supported; |
| 338 | if ((cmd->autoneg == AUTONEG_ENABLE) && !cmd->advertising) |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 339 | return -EINVAL; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 340 | |
| 341 | ret = 0; |
| 342 | phydev->autoneg = cmd->autoneg; |
| 343 | phydev->speed = speed; |
| 344 | phydev->duplex = cmd->duplex; |
| 345 | phydev->advertising = cmd->advertising; |
| 346 | |
| 347 | if (cmd->autoneg == AUTONEG_ENABLE) |
| 348 | phydev->advertising |= ADVERTISED_Autoneg; |
| 349 | else |
| 350 | phydev->advertising &= ~ADVERTISED_Autoneg; |
| 351 | |
| 352 | if (netif_running(netdev)) |
| 353 | ret = phy_start_aneg(phydev); |
| 354 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 355 | DBGPR("<--xgbe_set_settings\n"); |
| 356 | |
| 357 | return ret; |
| 358 | } |
| 359 | |
| 360 | static void xgbe_get_drvinfo(struct net_device *netdev, |
| 361 | struct ethtool_drvinfo *drvinfo) |
| 362 | { |
| 363 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 364 | struct xgbe_hw_features *hw_feat = &pdata->hw_feat; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 365 | |
| 366 | strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver)); |
| 367 | strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version)); |
| 368 | strlcpy(drvinfo->bus_info, dev_name(pdata->dev), |
| 369 | sizeof(drvinfo->bus_info)); |
| 370 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d", |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 371 | XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER), |
| 372 | XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID), |
| 373 | XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 374 | drvinfo->n_stats = XGBE_STATS_COUNT; |
| 375 | } |
| 376 | |
| 377 | static int xgbe_get_coalesce(struct net_device *netdev, |
| 378 | struct ethtool_coalesce *ec) |
| 379 | { |
| 380 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 381 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 382 | unsigned int riwt; |
| 383 | |
| 384 | DBGPR("-->xgbe_get_coalesce\n"); |
| 385 | |
| 386 | memset(ec, 0, sizeof(struct ethtool_coalesce)); |
| 387 | |
| 388 | riwt = pdata->rx_riwt; |
| 389 | ec->rx_coalesce_usecs = hw_if->riwt_to_usec(pdata, riwt); |
| 390 | ec->rx_max_coalesced_frames = pdata->rx_frames; |
| 391 | |
| 392 | ec->tx_coalesce_usecs = pdata->tx_usecs; |
| 393 | ec->tx_max_coalesced_frames = pdata->tx_frames; |
| 394 | |
| 395 | DBGPR("<--xgbe_get_coalesce\n"); |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static int xgbe_set_coalesce(struct net_device *netdev, |
| 401 | struct ethtool_coalesce *ec) |
| 402 | { |
| 403 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 404 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 405 | unsigned int rx_frames, rx_riwt, rx_usecs; |
| 406 | unsigned int tx_frames, tx_usecs; |
| 407 | |
| 408 | DBGPR("-->xgbe_set_coalesce\n"); |
| 409 | |
| 410 | /* Check for not supported parameters */ |
| 411 | if ((ec->rx_coalesce_usecs_irq) || |
| 412 | (ec->rx_max_coalesced_frames_irq) || |
| 413 | (ec->tx_coalesce_usecs_irq) || |
| 414 | (ec->tx_max_coalesced_frames_irq) || |
| 415 | (ec->stats_block_coalesce_usecs) || |
| 416 | (ec->use_adaptive_rx_coalesce) || |
| 417 | (ec->use_adaptive_tx_coalesce) || |
| 418 | (ec->pkt_rate_low) || |
| 419 | (ec->rx_coalesce_usecs_low) || |
| 420 | (ec->rx_max_coalesced_frames_low) || |
| 421 | (ec->tx_coalesce_usecs_low) || |
| 422 | (ec->tx_max_coalesced_frames_low) || |
| 423 | (ec->pkt_rate_high) || |
| 424 | (ec->rx_coalesce_usecs_high) || |
| 425 | (ec->rx_max_coalesced_frames_high) || |
| 426 | (ec->tx_coalesce_usecs_high) || |
| 427 | (ec->tx_max_coalesced_frames_high) || |
| 428 | (ec->rate_sample_interval)) |
| 429 | return -EOPNOTSUPP; |
| 430 | |
| 431 | /* Can only change rx-frames when interface is down (see |
| 432 | * rx_descriptor_init in xgbe-dev.c) |
| 433 | */ |
| 434 | rx_frames = pdata->rx_frames; |
| 435 | if (rx_frames != ec->rx_max_coalesced_frames && netif_running(netdev)) { |
| 436 | netdev_alert(netdev, |
| 437 | "interface must be down to change rx-frames\n"); |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs); |
| 442 | rx_frames = ec->rx_max_coalesced_frames; |
| 443 | |
| 444 | /* Use smallest possible value if conversion resulted in zero */ |
| 445 | if (ec->rx_coalesce_usecs && !rx_riwt) |
| 446 | rx_riwt = 1; |
| 447 | |
| 448 | /* Check the bounds of values for Rx */ |
| 449 | if (rx_riwt > XGMAC_MAX_DMA_RIWT) { |
| 450 | rx_usecs = hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT); |
| 451 | netdev_alert(netdev, "rx-usec is limited to %d usecs\n", |
| 452 | rx_usecs); |
| 453 | return -EINVAL; |
| 454 | } |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 455 | if (rx_frames > pdata->rx_desc_count) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 456 | netdev_alert(netdev, "rx-frames is limited to %d frames\n", |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 457 | pdata->rx_desc_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 458 | return -EINVAL; |
| 459 | } |
| 460 | |
| 461 | tx_usecs = ec->tx_coalesce_usecs; |
| 462 | tx_frames = ec->tx_max_coalesced_frames; |
| 463 | |
| 464 | /* Check the bounds of values for Tx */ |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 465 | if (tx_frames > pdata->tx_desc_count) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 466 | netdev_alert(netdev, "tx-frames is limited to %d frames\n", |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 467 | pdata->tx_desc_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 468 | return -EINVAL; |
| 469 | } |
| 470 | |
| 471 | pdata->rx_riwt = rx_riwt; |
| 472 | pdata->rx_frames = rx_frames; |
| 473 | hw_if->config_rx_coalesce(pdata); |
| 474 | |
| 475 | pdata->tx_usecs = tx_usecs; |
| 476 | pdata->tx_frames = tx_frames; |
| 477 | hw_if->config_tx_coalesce(pdata); |
| 478 | |
| 479 | DBGPR("<--xgbe_set_coalesce\n"); |
| 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame^] | 484 | static int xgbe_get_rxnfc(struct net_device *netdev, |
| 485 | struct ethtool_rxnfc *rxnfc, u32 *rule_locs) |
| 486 | { |
| 487 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 488 | |
| 489 | switch (rxnfc->cmd) { |
| 490 | case ETHTOOL_GRXRINGS: |
| 491 | rxnfc->data = pdata->rx_ring_count; |
| 492 | break; |
| 493 | default: |
| 494 | return -EOPNOTSUPP; |
| 495 | } |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static u32 xgbe_get_rxfh_key_size(struct net_device *netdev) |
| 501 | { |
| 502 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 503 | |
| 504 | return sizeof(pdata->rss_key); |
| 505 | } |
| 506 | |
| 507 | static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev) |
| 508 | { |
| 509 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 510 | |
| 511 | return ARRAY_SIZE(pdata->rss_table); |
| 512 | } |
| 513 | |
| 514 | static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key) |
| 515 | { |
| 516 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 517 | unsigned int i; |
| 518 | |
| 519 | if (indir) { |
| 520 | for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) |
| 521 | indir[i] = XGMAC_GET_BITS(pdata->rss_table[i], |
| 522 | MAC_RSSDR, DMCH); |
| 523 | } |
| 524 | |
| 525 | if (key) |
| 526 | memcpy(key, pdata->rss_key, sizeof(pdata->rss_key)); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir, |
| 532 | const u8 *key) |
| 533 | { |
| 534 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 535 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 536 | unsigned int ret; |
| 537 | |
| 538 | if (indir) { |
| 539 | ret = hw_if->set_rss_lookup_table(pdata, indir); |
| 540 | if (ret) |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | if (key) { |
| 545 | ret = hw_if->set_rss_hash_key(pdata, key); |
| 546 | if (ret) |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 553 | static int xgbe_get_ts_info(struct net_device *netdev, |
| 554 | struct ethtool_ts_info *ts_info) |
| 555 | { |
| 556 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 557 | |
| 558 | ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 559 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 560 | SOF_TIMESTAMPING_SOFTWARE | |
| 561 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 562 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 563 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 564 | |
| 565 | if (pdata->ptp_clock) |
| 566 | ts_info->phc_index = ptp_clock_index(pdata->ptp_clock); |
| 567 | else |
| 568 | ts_info->phc_index = -1; |
| 569 | |
| 570 | ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 571 | ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 572 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | |
| 573 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 574 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 575 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | |
| 576 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 577 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) | |
| 578 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 579 | (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 580 | (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
| 581 | (1 << HWTSTAMP_FILTER_ALL); |
| 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 586 | static const struct ethtool_ops xgbe_ethtool_ops = { |
| 587 | .get_settings = xgbe_get_settings, |
| 588 | .set_settings = xgbe_set_settings, |
| 589 | .get_drvinfo = xgbe_get_drvinfo, |
| 590 | .get_link = ethtool_op_get_link, |
| 591 | .get_coalesce = xgbe_get_coalesce, |
| 592 | .set_coalesce = xgbe_set_coalesce, |
| 593 | .get_pauseparam = xgbe_get_pauseparam, |
| 594 | .set_pauseparam = xgbe_set_pauseparam, |
| 595 | .get_strings = xgbe_get_strings, |
| 596 | .get_ethtool_stats = xgbe_get_ethtool_stats, |
| 597 | .get_sset_count = xgbe_get_sset_count, |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame^] | 598 | .get_rxnfc = xgbe_get_rxnfc, |
| 599 | .get_rxfh_key_size = xgbe_get_rxfh_key_size, |
| 600 | .get_rxfh_indir_size = xgbe_get_rxfh_indir_size, |
| 601 | .get_rxfh = xgbe_get_rxfh, |
| 602 | .set_rxfh = xgbe_set_rxfh, |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 603 | .get_ts_info = xgbe_get_ts_info, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | struct ethtool_ops *xgbe_get_ethtool_ops(void) |
| 607 | { |
| 608 | return (struct ethtool_ops *)&xgbe_ethtool_ops; |
| 609 | } |