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 | * |
Lendacky, Thomas | 757e6aa | 2016-02-17 11:48:39 -0600 | [diff] [blame] | 9 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 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 | * |
Lendacky, Thomas | 757e6aa | 2016-02-17 11:48:39 -0600 | [diff] [blame] | 59 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 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 | |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 136 | #define XGMAC_EXT_STAT(_string, _var) \ |
| 137 | { _string, \ |
| 138 | FIELD_SIZEOF(struct xgbe_ext_stats, _var), \ |
| 139 | offsetof(struct xgbe_prv_data, ext_stats._var), \ |
| 140 | } |
| 141 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 142 | static const struct xgbe_stats xgbe_gstring_stats[] = { |
| 143 | XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb), |
| 144 | XGMAC_MMC_STAT("tx_packets", txframecount_gb), |
| 145 | XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb), |
| 146 | XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb), |
| 147 | XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb), |
| 148 | XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g), |
Lendacky, Thomas | 3010608 | 2017-08-18 09:04:14 -0500 | [diff] [blame] | 149 | XGMAC_EXT_STAT("tx_vxlan_packets", tx_vxlan_packets), |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 150 | XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets), |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 151 | XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb), |
| 152 | XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb), |
| 153 | XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb), |
| 154 | XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb), |
| 155 | XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb), |
| 156 | XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb), |
| 157 | XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror), |
| 158 | XGMAC_MMC_STAT("tx_pause_frames", txpauseframes), |
| 159 | |
| 160 | XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb), |
| 161 | XGMAC_MMC_STAT("rx_packets", rxframecount_gb), |
| 162 | XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g), |
| 163 | XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g), |
| 164 | XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g), |
| 165 | XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb), |
Lendacky, Thomas | 3010608 | 2017-08-18 09:04:14 -0500 | [diff] [blame] | 166 | XGMAC_EXT_STAT("rx_vxlan_packets", rx_vxlan_packets), |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 167 | XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb), |
| 168 | XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb), |
| 169 | XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb), |
| 170 | XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb), |
| 171 | XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb), |
| 172 | XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb), |
| 173 | XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g), |
| 174 | XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g), |
| 175 | XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror), |
| 176 | XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror), |
| 177 | XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror), |
| 178 | XGMAC_MMC_STAT("rx_length_errors", rxlengtherror), |
| 179 | XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype), |
| 180 | XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow), |
| 181 | XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror), |
Lendacky, Thomas | 3010608 | 2017-08-18 09:04:14 -0500 | [diff] [blame] | 182 | XGMAC_EXT_STAT("rx_csum_errors", rx_csum_errors), |
| 183 | XGMAC_EXT_STAT("rx_vxlan_csum_errors", rx_vxlan_csum_errors), |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 184 | XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes), |
Lendacky, Thomas | 5452b2d | 2015-05-14 11:43:57 -0500 | [diff] [blame] | 185 | XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets), |
Lendacky, Thomas | 72c9ac4 | 2015-09-30 08:53:10 -0500 | [diff] [blame] | 186 | XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable), |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 187 | }; |
Lendacky, Thomas | a2ea14d | 2014-09-03 12:14:33 -0500 | [diff] [blame] | 188 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 189 | #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats) |
| 190 | |
| 191 | static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data) |
| 192 | { |
Lendacky, Thomas | 80a788c | 2017-08-18 09:03:35 -0500 | [diff] [blame] | 193 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 194 | int i; |
| 195 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 196 | switch (stringset) { |
| 197 | case ETH_SS_STATS: |
| 198 | for (i = 0; i < XGBE_STATS_COUNT; i++) { |
| 199 | memcpy(data, xgbe_gstring_stats[i].stat_string, |
| 200 | ETH_GSTRING_LEN); |
| 201 | data += ETH_GSTRING_LEN; |
| 202 | } |
Lendacky, Thomas | 80a788c | 2017-08-18 09:03:35 -0500 | [diff] [blame] | 203 | for (i = 0; i < pdata->tx_ring_count; i++) { |
| 204 | sprintf(data, "txq_%u_packets", i); |
| 205 | data += ETH_GSTRING_LEN; |
| 206 | sprintf(data, "txq_%u_bytes", i); |
| 207 | data += ETH_GSTRING_LEN; |
| 208 | } |
| 209 | for (i = 0; i < pdata->rx_ring_count; i++) { |
| 210 | sprintf(data, "rxq_%u_packets", i); |
| 211 | data += ETH_GSTRING_LEN; |
| 212 | sprintf(data, "rxq_%u_bytes", i); |
| 213 | data += ETH_GSTRING_LEN; |
| 214 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 215 | break; |
| 216 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static void xgbe_get_ethtool_stats(struct net_device *netdev, |
| 220 | struct ethtool_stats *stats, u64 *data) |
| 221 | { |
| 222 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 223 | u8 *stat; |
| 224 | int i; |
| 225 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 226 | pdata->hw_if.read_mmc_stats(pdata); |
| 227 | for (i = 0; i < XGBE_STATS_COUNT; i++) { |
| 228 | stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset; |
| 229 | *data++ = *(u64 *)stat; |
| 230 | } |
Lendacky, Thomas | 80a788c | 2017-08-18 09:03:35 -0500 | [diff] [blame] | 231 | for (i = 0; i < pdata->tx_ring_count; i++) { |
| 232 | *data++ = pdata->ext_stats.txq_packets[i]; |
| 233 | *data++ = pdata->ext_stats.txq_bytes[i]; |
| 234 | } |
| 235 | for (i = 0; i < pdata->rx_ring_count; i++) { |
| 236 | *data++ = pdata->ext_stats.rxq_packets[i]; |
| 237 | *data++ = pdata->ext_stats.rxq_bytes[i]; |
| 238 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static int xgbe_get_sset_count(struct net_device *netdev, int stringset) |
| 242 | { |
Lendacky, Thomas | 80a788c | 2017-08-18 09:03:35 -0500 | [diff] [blame] | 243 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 244 | int ret; |
| 245 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 246 | switch (stringset) { |
| 247 | case ETH_SS_STATS: |
Lendacky, Thomas | 80a788c | 2017-08-18 09:03:35 -0500 | [diff] [blame] | 248 | ret = XGBE_STATS_COUNT + |
| 249 | (pdata->tx_ring_count * 2) + |
| 250 | (pdata->rx_ring_count * 2); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 251 | break; |
| 252 | |
| 253 | default: |
| 254 | ret = -EOPNOTSUPP; |
| 255 | } |
| 256 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | static void xgbe_get_pauseparam(struct net_device *netdev, |
| 261 | struct ethtool_pauseparam *pause) |
| 262 | { |
| 263 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 264 | |
Lendacky, Thomas | c1ce2f7 | 2015-05-14 11:44:27 -0500 | [diff] [blame] | 265 | pause->autoneg = pdata->phy.pause_autoneg; |
| 266 | pause->tx_pause = pdata->phy.tx_pause; |
| 267 | pause->rx_pause = pdata->phy.rx_pause; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static int xgbe_set_pauseparam(struct net_device *netdev, |
| 271 | struct ethtool_pauseparam *pause) |
| 272 | { |
| 273 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 274 | struct ethtool_link_ksettings *lks = &pdata->phy.lks; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 275 | int ret = 0; |
| 276 | |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 277 | if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) { |
| 278 | netdev_err(netdev, |
Colin Ian King | beef851 | 2017-06-28 17:51:10 +0100 | [diff] [blame] | 279 | "autoneg disabled, pause autoneg not available\n"); |
Lendacky, Thomas | c1ce2f7 | 2015-05-14 11:44:27 -0500 | [diff] [blame] | 280 | return -EINVAL; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 281 | } |
Lendacky, Thomas | c1ce2f7 | 2015-05-14 11:44:27 -0500 | [diff] [blame] | 282 | |
| 283 | pdata->phy.pause_autoneg = pause->autoneg; |
| 284 | pdata->phy.tx_pause = pause->tx_pause; |
| 285 | pdata->phy.rx_pause = pause->rx_pause; |
| 286 | |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 287 | XGBE_CLR_ADV(lks, Pause); |
| 288 | XGBE_CLR_ADV(lks, Asym_Pause); |
Lendacky, Thomas | c1ce2f7 | 2015-05-14 11:44:27 -0500 | [diff] [blame] | 289 | |
| 290 | if (pause->rx_pause) { |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 291 | XGBE_SET_ADV(lks, Pause); |
| 292 | XGBE_SET_ADV(lks, Asym_Pause); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 295 | if (pause->tx_pause) { |
| 296 | /* Equivalent to XOR of Asym_Pause */ |
| 297 | if (XGBE_ADV(lks, Asym_Pause)) |
| 298 | XGBE_CLR_ADV(lks, Asym_Pause); |
| 299 | else |
| 300 | XGBE_SET_ADV(lks, Asym_Pause); |
| 301 | } |
Lendacky, Thomas | c1ce2f7 | 2015-05-14 11:44:27 -0500 | [diff] [blame] | 302 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 303 | if (netif_running(netdev)) |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 304 | ret = pdata->phy_if.phy_config_aneg(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 305 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 306 | return ret; |
| 307 | } |
| 308 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 309 | static int xgbe_get_link_ksettings(struct net_device *netdev, |
| 310 | struct ethtool_link_ksettings *cmd) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 311 | { |
| 312 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 313 | struct ethtool_link_ksettings *lks = &pdata->phy.lks; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 314 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 315 | cmd->base.phy_address = pdata->phy.address; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 316 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 317 | cmd->base.autoneg = pdata->phy.autoneg; |
| 318 | cmd->base.speed = pdata->phy.speed; |
| 319 | cmd->base.duplex = pdata->phy.duplex; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 320 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 321 | cmd->base.port = PORT_NONE; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 322 | |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 323 | XGBE_LM_COPY(cmd, supported, lks, supported); |
| 324 | XGBE_LM_COPY(cmd, advertising, lks, advertising); |
| 325 | XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising); |
| 326 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 327 | return 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 328 | } |
| 329 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 330 | static int xgbe_set_link_ksettings(struct net_device *netdev, |
| 331 | const struct ethtool_link_ksettings *cmd) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 332 | { |
| 333 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 334 | struct ethtool_link_ksettings *lks = &pdata->phy.lks; |
| 335 | __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 336 | u32 speed; |
| 337 | int ret; |
| 338 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 339 | speed = cmd->base.speed; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 340 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 341 | if (cmd->base.phy_address != pdata->phy.address) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 342 | netdev_err(netdev, "invalid phy address %hhu\n", |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 343 | cmd->base.phy_address); |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 344 | return -EINVAL; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 345 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 346 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 347 | if ((cmd->base.autoneg != AUTONEG_ENABLE) && |
| 348 | (cmd->base.autoneg != AUTONEG_DISABLE)) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 349 | netdev_err(netdev, "unsupported autoneg %hhu\n", |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 350 | cmd->base.autoneg); |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 351 | return -EINVAL; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 352 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 353 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 354 | if (cmd->base.autoneg == AUTONEG_DISABLE) { |
Lendacky, Thomas | e57f7a3 | 2016-11-03 13:18:27 -0500 | [diff] [blame] | 355 | if (!pdata->phy_if.phy_valid_speed(pdata, speed)) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 356 | netdev_err(netdev, "unsupported speed %u\n", speed); |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 357 | return -EINVAL; |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 358 | } |
| 359 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 360 | if (cmd->base.duplex != DUPLEX_FULL) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 361 | netdev_err(netdev, "unsupported duplex %hhu\n", |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 362 | cmd->base.duplex); |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 363 | return -EINVAL; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 364 | } |
Lendacky, Thomas | f047604 | 2014-07-29 08:57:25 -0500 | [diff] [blame] | 365 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 366 | |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 367 | netif_dbg(pdata, link, netdev, |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 368 | "requested advertisement 0x%*pb, phy supported 0x%*pb\n", |
| 369 | __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising, |
| 370 | __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported); |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 371 | |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 372 | bitmap_and(advertising, |
| 373 | cmd->link_modes.advertising, lks->link_modes.supported, |
| 374 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 375 | |
| 376 | if ((cmd->base.autoneg == AUTONEG_ENABLE) && |
| 377 | bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 378 | netdev_err(netdev, |
| 379 | "unsupported requested advertisement\n"); |
Lendacky, Thomas | 8c43a2c | 2014-08-01 11:56:29 -0500 | [diff] [blame] | 380 | return -EINVAL; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 381 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 382 | |
| 383 | ret = 0; |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 384 | pdata->phy.autoneg = cmd->base.autoneg; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 385 | pdata->phy.speed = speed; |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 386 | pdata->phy.duplex = cmd->base.duplex; |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 387 | bitmap_copy(lks->link_modes.advertising, advertising, |
| 388 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 389 | |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 390 | if (cmd->base.autoneg == AUTONEG_ENABLE) |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 391 | XGBE_SET_ADV(lks, Autoneg); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 392 | else |
Lendacky, Thomas | 85f9feb | 2017-08-18 09:03:55 -0500 | [diff] [blame] | 393 | XGBE_CLR_ADV(lks, Autoneg); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 394 | |
| 395 | if (netif_running(netdev)) |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 396 | ret = pdata->phy_if.phy_config_aneg(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 397 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 398 | return ret; |
| 399 | } |
| 400 | |
| 401 | static void xgbe_get_drvinfo(struct net_device *netdev, |
| 402 | struct ethtool_drvinfo *drvinfo) |
| 403 | { |
| 404 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 405 | struct xgbe_hw_features *hw_feat = &pdata->hw_feat; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 406 | |
| 407 | strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver)); |
| 408 | strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version)); |
| 409 | strlcpy(drvinfo->bus_info, dev_name(pdata->dev), |
| 410 | sizeof(drvinfo->bus_info)); |
| 411 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d", |
Lendacky, Thomas | a9a4a2d | 2014-08-29 13:16:50 -0500 | [diff] [blame] | 412 | XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER), |
| 413 | XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID), |
| 414 | XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 415 | } |
| 416 | |
Lendacky, Thomas | 349fb2d7 | 2015-09-30 08:52:51 -0500 | [diff] [blame] | 417 | static u32 xgbe_get_msglevel(struct net_device *netdev) |
| 418 | { |
| 419 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 420 | |
| 421 | return pdata->msg_enable; |
| 422 | } |
| 423 | |
| 424 | static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel) |
| 425 | { |
| 426 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 427 | |
| 428 | pdata->msg_enable = msglevel; |
| 429 | } |
| 430 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 431 | static int xgbe_get_coalesce(struct net_device *netdev, |
| 432 | struct ethtool_coalesce *ec) |
| 433 | { |
| 434 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 435 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 436 | memset(ec, 0, sizeof(struct ethtool_coalesce)); |
| 437 | |
Lendacky, Thomas | 4a57ebc | 2015-03-20 11:50:34 -0500 | [diff] [blame] | 438 | ec->rx_coalesce_usecs = pdata->rx_usecs; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 439 | ec->rx_max_coalesced_frames = pdata->rx_frames; |
| 440 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 441 | ec->tx_max_coalesced_frames = pdata->tx_frames; |
| 442 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | static int xgbe_set_coalesce(struct net_device *netdev, |
| 447 | struct ethtool_coalesce *ec) |
| 448 | { |
| 449 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 450 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 451 | unsigned int rx_frames, rx_riwt, rx_usecs; |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 452 | unsigned int tx_frames; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 453 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 454 | /* Check for not supported parameters */ |
| 455 | if ((ec->rx_coalesce_usecs_irq) || |
| 456 | (ec->rx_max_coalesced_frames_irq) || |
Lendacky, Thomas | c635eaa | 2015-03-20 11:50:28 -0500 | [diff] [blame] | 457 | (ec->tx_coalesce_usecs) || |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 458 | (ec->tx_coalesce_usecs_irq) || |
| 459 | (ec->tx_max_coalesced_frames_irq) || |
| 460 | (ec->stats_block_coalesce_usecs) || |
| 461 | (ec->use_adaptive_rx_coalesce) || |
| 462 | (ec->use_adaptive_tx_coalesce) || |
| 463 | (ec->pkt_rate_low) || |
| 464 | (ec->rx_coalesce_usecs_low) || |
| 465 | (ec->rx_max_coalesced_frames_low) || |
| 466 | (ec->tx_coalesce_usecs_low) || |
| 467 | (ec->tx_max_coalesced_frames_low) || |
| 468 | (ec->pkt_rate_high) || |
| 469 | (ec->rx_coalesce_usecs_high) || |
| 470 | (ec->rx_max_coalesced_frames_high) || |
| 471 | (ec->tx_coalesce_usecs_high) || |
| 472 | (ec->tx_max_coalesced_frames_high) || |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 473 | (ec->rate_sample_interval)) { |
| 474 | netdev_err(netdev, "unsupported coalescing parameter\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 475 | return -EOPNOTSUPP; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 476 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 477 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 478 | rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs); |
Lendacky, Thomas | 4a57ebc | 2015-03-20 11:50:34 -0500 | [diff] [blame] | 479 | rx_usecs = ec->rx_coalesce_usecs; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 480 | rx_frames = ec->rx_max_coalesced_frames; |
| 481 | |
| 482 | /* Use smallest possible value if conversion resulted in zero */ |
Lendacky, Thomas | 4a57ebc | 2015-03-20 11:50:34 -0500 | [diff] [blame] | 483 | if (rx_usecs && !rx_riwt) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 484 | rx_riwt = 1; |
| 485 | |
| 486 | /* Check the bounds of values for Rx */ |
| 487 | if (rx_riwt > XGMAC_MAX_DMA_RIWT) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 488 | netdev_err(netdev, "rx-usec is limited to %d usecs\n", |
| 489 | hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT)); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 490 | return -EINVAL; |
| 491 | } |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 492 | if (rx_frames > pdata->rx_desc_count) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 493 | netdev_err(netdev, "rx-frames is limited to %d frames\n", |
| 494 | pdata->rx_desc_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 495 | return -EINVAL; |
| 496 | } |
| 497 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 498 | tx_frames = ec->tx_max_coalesced_frames; |
| 499 | |
| 500 | /* Check the bounds of values for Tx */ |
Lendacky, Thomas | 4780b7c | 2014-11-04 16:06:26 -0600 | [diff] [blame] | 501 | if (tx_frames > pdata->tx_desc_count) { |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 502 | netdev_err(netdev, "tx-frames is limited to %d frames\n", |
| 503 | pdata->tx_desc_count); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 504 | return -EINVAL; |
| 505 | } |
| 506 | |
| 507 | pdata->rx_riwt = rx_riwt; |
Lendacky, Thomas | 4a57ebc | 2015-03-20 11:50:34 -0500 | [diff] [blame] | 508 | pdata->rx_usecs = rx_usecs; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 509 | pdata->rx_frames = rx_frames; |
| 510 | hw_if->config_rx_coalesce(pdata); |
| 511 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 512 | pdata->tx_frames = tx_frames; |
| 513 | hw_if->config_tx_coalesce(pdata); |
| 514 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 515 | return 0; |
| 516 | } |
| 517 | |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 518 | static int xgbe_get_rxnfc(struct net_device *netdev, |
| 519 | struct ethtool_rxnfc *rxnfc, u32 *rule_locs) |
| 520 | { |
| 521 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 522 | |
| 523 | switch (rxnfc->cmd) { |
| 524 | case ETHTOOL_GRXRINGS: |
| 525 | rxnfc->data = pdata->rx_ring_count; |
| 526 | break; |
| 527 | default: |
| 528 | return -EOPNOTSUPP; |
| 529 | } |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static u32 xgbe_get_rxfh_key_size(struct net_device *netdev) |
| 535 | { |
| 536 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 537 | |
| 538 | return sizeof(pdata->rss_key); |
| 539 | } |
| 540 | |
| 541 | static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev) |
| 542 | { |
| 543 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 544 | |
| 545 | return ARRAY_SIZE(pdata->rss_table); |
| 546 | } |
| 547 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 548 | static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, |
| 549 | u8 *hfunc) |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 550 | { |
| 551 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 552 | unsigned int i; |
| 553 | |
| 554 | if (indir) { |
| 555 | for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) |
| 556 | indir[i] = XGMAC_GET_BITS(pdata->rss_table[i], |
| 557 | MAC_RSSDR, DMCH); |
| 558 | } |
| 559 | |
| 560 | if (key) |
| 561 | memcpy(key, pdata->rss_key, sizeof(pdata->rss_key)); |
| 562 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 563 | if (hfunc) |
| 564 | *hfunc = ETH_RSS_HASH_TOP; |
| 565 | |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir, |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 570 | const u8 *key, const u8 hfunc) |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 571 | { |
| 572 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 573 | struct xgbe_hw_if *hw_if = &pdata->hw_if; |
| 574 | unsigned int ret; |
| 575 | |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 576 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) { |
| 577 | netdev_err(netdev, "unsupported hash function\n"); |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 578 | return -EOPNOTSUPP; |
Lendacky, Thomas | e5dd8b8 | 2015-09-30 08:52:57 -0500 | [diff] [blame] | 579 | } |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 580 | |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 581 | if (indir) { |
| 582 | ret = hw_if->set_rss_lookup_table(pdata, indir); |
| 583 | if (ret) |
| 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | if (key) { |
| 588 | ret = hw_if->set_rss_hash_key(pdata, key); |
| 589 | if (ret) |
| 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 596 | static int xgbe_get_ts_info(struct net_device *netdev, |
| 597 | struct ethtool_ts_info *ts_info) |
| 598 | { |
| 599 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 600 | |
| 601 | ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 602 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 603 | SOF_TIMESTAMPING_SOFTWARE | |
| 604 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 605 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 606 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 607 | |
| 608 | if (pdata->ptp_clock) |
| 609 | ts_info->phc_index = ptp_clock_index(pdata->ptp_clock); |
| 610 | else |
| 611 | ts_info->phc_index = -1; |
| 612 | |
| 613 | ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 614 | ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 615 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | |
| 616 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 617 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 618 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | |
| 619 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 620 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) | |
| 621 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 622 | (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 623 | (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
| 624 | (1 << HWTSTAMP_FILTER_ALL); |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 629 | static const struct ethtool_ops xgbe_ethtool_ops = { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 630 | .get_drvinfo = xgbe_get_drvinfo, |
Lendacky, Thomas | 349fb2d7 | 2015-09-30 08:52:51 -0500 | [diff] [blame] | 631 | .get_msglevel = xgbe_get_msglevel, |
| 632 | .set_msglevel = xgbe_set_msglevel, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 633 | .get_link = ethtool_op_get_link, |
| 634 | .get_coalesce = xgbe_get_coalesce, |
| 635 | .set_coalesce = xgbe_set_coalesce, |
| 636 | .get_pauseparam = xgbe_get_pauseparam, |
| 637 | .set_pauseparam = xgbe_set_pauseparam, |
| 638 | .get_strings = xgbe_get_strings, |
| 639 | .get_ethtool_stats = xgbe_get_ethtool_stats, |
| 640 | .get_sset_count = xgbe_get_sset_count, |
Lendacky, Thomas | f6ac862 | 2014-11-04 16:07:23 -0600 | [diff] [blame] | 641 | .get_rxnfc = xgbe_get_rxnfc, |
| 642 | .get_rxfh_key_size = xgbe_get_rxfh_key_size, |
| 643 | .get_rxfh_indir_size = xgbe_get_rxfh_indir_size, |
| 644 | .get_rxfh = xgbe_get_rxfh, |
| 645 | .set_rxfh = xgbe_set_rxfh, |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 646 | .get_ts_info = xgbe_get_ts_info, |
Philippe Reynes | 90fdd04 | 2016-11-06 14:57:04 +0100 | [diff] [blame] | 647 | .get_link_ksettings = xgbe_get_link_ksettings, |
| 648 | .set_link_ksettings = xgbe_set_link_ksettings, |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 649 | }; |
| 650 | |
stephen hemminger | ce0b15d | 2016-08-31 08:57:36 -0700 | [diff] [blame] | 651 | const struct ethtool_ops *xgbe_get_ethtool_ops(void) |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 652 | { |
stephen hemminger | ce0b15d | 2016-08-31 08:57:36 -0700 | [diff] [blame] | 653 | return &xgbe_ethtool_ops; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 654 | } |