Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver |
Ashish Shah | 0e88898 | 2015-02-06 08:52:10 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 Intel Corporation. |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Jesse Brandeburg | b831607 | 2014-04-05 07:46:11 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | /* ethtool support for i40evf */ |
| 28 | #include "i40evf.h" |
| 29 | |
| 30 | #include <linux/uaccess.h> |
| 31 | |
| 32 | |
| 33 | struct i40evf_stats { |
| 34 | char stat_string[ETH_GSTRING_LEN]; |
| 35 | int stat_offset; |
| 36 | }; |
| 37 | |
| 38 | #define I40EVF_STAT(_name, _stat) { \ |
| 39 | .stat_string = _name, \ |
| 40 | .stat_offset = offsetof(struct i40evf_adapter, _stat) \ |
| 41 | } |
| 42 | |
| 43 | /* All stats are u64, so we don't need to track the size of the field. */ |
| 44 | static const struct i40evf_stats i40evf_gstrings_stats[] = { |
| 45 | I40EVF_STAT("rx_bytes", current_stats.rx_bytes), |
| 46 | I40EVF_STAT("rx_unicast", current_stats.rx_unicast), |
| 47 | I40EVF_STAT("rx_multicast", current_stats.rx_multicast), |
| 48 | I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast), |
| 49 | I40EVF_STAT("rx_discards", current_stats.rx_discards), |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 50 | I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol), |
| 51 | I40EVF_STAT("tx_bytes", current_stats.tx_bytes), |
| 52 | I40EVF_STAT("tx_unicast", current_stats.tx_unicast), |
| 53 | I40EVF_STAT("tx_multicast", current_stats.tx_multicast), |
| 54 | I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast), |
| 55 | I40EVF_STAT("tx_discards", current_stats.tx_discards), |
| 56 | I40EVF_STAT("tx_errors", current_stats.tx_errors), |
| 57 | }; |
| 58 | |
| 59 | #define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats) |
Mitch Williams | c7b8d97 | 2014-04-04 04:43:08 +0000 | [diff] [blame] | 60 | #define I40EVF_QUEUE_STATS_LEN(_dev) \ |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 61 | (((struct i40evf_adapter *)\ |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 62 | netdev_priv(_dev))->num_active_queues \ |
Mitch Williams | c7b8d97 | 2014-04-04 04:43:08 +0000 | [diff] [blame] | 63 | * 2 * (sizeof(struct i40e_queue_stats) / sizeof(u64))) |
| 64 | #define I40EVF_STATS_LEN(_dev) \ |
| 65 | (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN(_dev)) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * i40evf_get_settings - Get Link Speed and Duplex settings |
| 69 | * @netdev: network interface device structure |
| 70 | * @ecmd: ethtool command |
| 71 | * |
| 72 | * Reports speed/duplex settings. Because this is a VF, we don't know what |
| 73 | * kind of link we really have, so we fake it. |
| 74 | **/ |
| 75 | static int i40evf_get_settings(struct net_device *netdev, |
| 76 | struct ethtool_cmd *ecmd) |
| 77 | { |
| 78 | /* In the future the VF will be able to query the PF for |
| 79 | * some information - for now use a dummy value |
| 80 | */ |
Mitch Williams | 107f301 | 2014-04-04 04:43:09 +0000 | [diff] [blame] | 81 | ecmd->supported = 0; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 82 | ecmd->autoneg = AUTONEG_DISABLE; |
| 83 | ecmd->transceiver = XCVR_DUMMY1; |
| 84 | ecmd->port = PORT_NONE; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * i40evf_get_sset_count - Get length of string set |
| 91 | * @netdev: network interface device structure |
| 92 | * @sset: id of string set |
| 93 | * |
| 94 | * Reports size of string table. This driver only supports |
| 95 | * strings for statistics. |
| 96 | **/ |
| 97 | static int i40evf_get_sset_count(struct net_device *netdev, int sset) |
| 98 | { |
| 99 | if (sset == ETH_SS_STATS) |
Mitch Williams | c7b8d97 | 2014-04-04 04:43:08 +0000 | [diff] [blame] | 100 | return I40EVF_STATS_LEN(netdev); |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 101 | else |
Mitch Williams | c7b8d97 | 2014-04-04 04:43:08 +0000 | [diff] [blame] | 102 | return -EINVAL; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * i40evf_get_ethtool_stats - report device statistics |
| 107 | * @netdev: network interface device structure |
| 108 | * @stats: ethtool statistics structure |
| 109 | * @data: pointer to data buffer |
| 110 | * |
| 111 | * All statistics are added to the data buffer as an array of u64. |
| 112 | **/ |
| 113 | static void i40evf_get_ethtool_stats(struct net_device *netdev, |
| 114 | struct ethtool_stats *stats, u64 *data) |
| 115 | { |
| 116 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 117 | int i, j; |
| 118 | char *p; |
| 119 | |
| 120 | for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) { |
| 121 | p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset; |
| 122 | data[i] = *(u64 *)p; |
| 123 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 124 | for (j = 0; j < adapter->num_active_queues; j++) { |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 125 | data[i++] = adapter->tx_rings[j]->stats.packets; |
| 126 | data[i++] = adapter->tx_rings[j]->stats.bytes; |
| 127 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 128 | for (j = 0; j < adapter->num_active_queues; j++) { |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 129 | data[i++] = adapter->rx_rings[j]->stats.packets; |
| 130 | data[i++] = adapter->rx_rings[j]->stats.bytes; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * i40evf_get_strings - Get string set |
| 136 | * @netdev: network interface device structure |
| 137 | * @sset: id of string set |
| 138 | * @data: buffer for string data |
| 139 | * |
| 140 | * Builds stats string table. |
| 141 | **/ |
| 142 | static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data) |
| 143 | { |
| 144 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 145 | u8 *p = data; |
| 146 | int i; |
| 147 | |
| 148 | if (sset == ETH_SS_STATS) { |
| 149 | for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) { |
| 150 | memcpy(p, i40evf_gstrings_stats[i].stat_string, |
| 151 | ETH_GSTRING_LEN); |
| 152 | p += ETH_GSTRING_LEN; |
| 153 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 154 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 155 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i); |
| 156 | p += ETH_GSTRING_LEN; |
| 157 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i); |
| 158 | p += ETH_GSTRING_LEN; |
| 159 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 160 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 161 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i); |
| 162 | p += ETH_GSTRING_LEN; |
| 163 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i); |
| 164 | p += ETH_GSTRING_LEN; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * i40evf_get_msglevel - Get debug message level |
| 171 | * @netdev: network interface device structure |
| 172 | * |
| 173 | * Returns current debug message level. |
| 174 | **/ |
| 175 | static u32 i40evf_get_msglevel(struct net_device *netdev) |
| 176 | { |
| 177 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 178 | |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 179 | return adapter->msg_enable; |
| 180 | } |
| 181 | |
| 182 | /** |
Ashish Shah | 0e88898 | 2015-02-06 08:52:10 +0000 | [diff] [blame] | 183 | * i40evf_set_msglevel - Set debug message level |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 184 | * @netdev: network interface device structure |
| 185 | * @data: message level |
| 186 | * |
| 187 | * Set current debug message level. Higher values cause the driver to |
| 188 | * be noisier. |
| 189 | **/ |
| 190 | static void i40evf_set_msglevel(struct net_device *netdev, u32 data) |
| 191 | { |
| 192 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 193 | |
Ashish Shah | 0e88898 | 2015-02-06 08:52:10 +0000 | [diff] [blame] | 194 | if (I40E_DEBUG_USER & data) |
| 195 | adapter->hw.debug_mask = data; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 196 | adapter->msg_enable = data; |
| 197 | } |
| 198 | |
| 199 | /** |
Jesse Brandeburg | b39c1e2 | 2014-08-01 13:27:08 -0700 | [diff] [blame] | 200 | * i40evf_get_drvinfo - Get driver info |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 201 | * @netdev: network interface device structure |
| 202 | * @drvinfo: ethool driver info structure |
| 203 | * |
| 204 | * Returns information about the driver and device for display to the user. |
| 205 | **/ |
| 206 | static void i40evf_get_drvinfo(struct net_device *netdev, |
| 207 | struct ethtool_drvinfo *drvinfo) |
| 208 | { |
| 209 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 210 | |
| 211 | strlcpy(drvinfo->driver, i40evf_driver_name, 32); |
| 212 | strlcpy(drvinfo->version, i40evf_driver_version, 32); |
| 213 | |
| 214 | strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * i40evf_get_ringparam - Get ring parameters |
| 219 | * @netdev: network interface device structure |
| 220 | * @ring: ethtool ringparam structure |
| 221 | * |
| 222 | * Returns current ring parameters. TX and RX rings are reported separately, |
| 223 | * but the number of rings is not reported. |
| 224 | **/ |
| 225 | static void i40evf_get_ringparam(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 226 | struct ethtool_ringparam *ring) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 227 | { |
| 228 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 229 | |
| 230 | ring->rx_max_pending = I40EVF_MAX_RXD; |
| 231 | ring->tx_max_pending = I40EVF_MAX_TXD; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 232 | ring->rx_pending = adapter->rx_desc_count; |
| 233 | ring->tx_pending = adapter->tx_desc_count; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /** |
| 237 | * i40evf_set_ringparam - Set ring parameters |
| 238 | * @netdev: network interface device structure |
| 239 | * @ring: ethtool ringparam structure |
| 240 | * |
| 241 | * Sets ring parameters. TX and RX rings are controlled separately, but the |
| 242 | * number of rings is not specified, so all rings get the same settings. |
| 243 | **/ |
| 244 | static int i40evf_set_ringparam(struct net_device *netdev, |
| 245 | struct ethtool_ringparam *ring) |
| 246 | { |
| 247 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 248 | u32 new_rx_count, new_tx_count; |
| 249 | |
| 250 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | new_tx_count = clamp_t(u32, ring->tx_pending, |
| 254 | I40EVF_MIN_TXD, |
| 255 | I40EVF_MAX_TXD); |
| 256 | new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE); |
| 257 | |
| 258 | new_rx_count = clamp_t(u32, ring->rx_pending, |
| 259 | I40EVF_MIN_RXD, |
| 260 | I40EVF_MAX_RXD); |
| 261 | new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE); |
| 262 | |
| 263 | /* if nothing to do return success */ |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 264 | if ((new_tx_count == adapter->tx_desc_count) && |
| 265 | (new_rx_count == adapter->rx_desc_count)) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 266 | return 0; |
| 267 | |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 268 | adapter->tx_desc_count = new_tx_count; |
| 269 | adapter->rx_desc_count = new_rx_count; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 270 | |
| 271 | if (netif_running(netdev)) |
| 272 | i40evf_reinit_locked(adapter); |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 273 | |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * i40evf_get_coalesce - Get interrupt coalescing settings |
| 279 | * @netdev: network interface device structure |
| 280 | * @ec: ethtool coalesce structure |
| 281 | * |
| 282 | * Returns current coalescing settings. This is referred to elsewhere in the |
| 283 | * driver as Interrupt Throttle Rate, as this is how the hardware describes |
| 284 | * this functionality. |
| 285 | **/ |
| 286 | static int i40evf_get_coalesce(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 287 | struct ethtool_coalesce *ec) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 288 | { |
| 289 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 290 | struct i40e_vsi *vsi = &adapter->vsi; |
| 291 | |
| 292 | ec->tx_max_coalesced_frames = vsi->work_limit; |
| 293 | ec->rx_max_coalesced_frames = vsi->work_limit; |
| 294 | |
| 295 | if (ITR_IS_DYNAMIC(vsi->rx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 296 | ec->use_adaptive_rx_coalesce = 1; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 297 | |
| 298 | if (ITR_IS_DYNAMIC(vsi->tx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 299 | ec->use_adaptive_tx_coalesce = 1; |
| 300 | |
| 301 | ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 302 | ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * i40evf_set_coalesce - Set interrupt coalescing settings |
| 309 | * @netdev: network interface device structure |
| 310 | * @ec: ethtool coalesce structure |
| 311 | * |
| 312 | * Change current coalescing settings. |
| 313 | **/ |
| 314 | static int i40evf_set_coalesce(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 315 | struct ethtool_coalesce *ec) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 316 | { |
| 317 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 318 | struct i40e_hw *hw = &adapter->hw; |
| 319 | struct i40e_vsi *vsi = &adapter->vsi; |
| 320 | struct i40e_q_vector *q_vector; |
| 321 | int i; |
| 322 | |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 323 | if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) |
| 324 | vsi->work_limit = ec->tx_max_coalesced_frames_irq; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 325 | |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 326 | if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) && |
| 327 | (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 328 | vsi->rx_itr_setting = ec->rx_coalesce_usecs; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 329 | |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 330 | else |
| 331 | return -EINVAL; |
| 332 | |
| 333 | if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) && |
| 334 | (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 335 | vsi->tx_itr_setting = ec->tx_coalesce_usecs; |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 336 | else if (ec->use_adaptive_tx_coalesce) |
| 337 | vsi->tx_itr_setting = (I40E_ITR_DYNAMIC | |
| 338 | ITR_REG_TO_USEC(I40E_ITR_RX_DEF)); |
| 339 | else |
| 340 | return -EINVAL; |
| 341 | |
| 342 | if (ec->use_adaptive_rx_coalesce) |
| 343 | vsi->rx_itr_setting |= I40E_ITR_DYNAMIC; |
| 344 | else |
| 345 | vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 346 | |
| 347 | if (ec->use_adaptive_tx_coalesce) |
| 348 | vsi->tx_itr_setting |= I40E_ITR_DYNAMIC; |
| 349 | else |
| 350 | vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 351 | |
| 352 | for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) { |
| 353 | q_vector = adapter->q_vector[i]; |
| 354 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 355 | wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr); |
| 356 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 357 | wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr); |
| 358 | i40e_flush(hw); |
| 359 | } |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 364 | /** |
| 365 | * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type |
| 366 | * @adapter: board private structure |
| 367 | * @cmd: ethtool rxnfc command |
| 368 | * |
| 369 | * Returns Success if the flow is supported, else Invalid Input. |
| 370 | **/ |
| 371 | static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter, |
| 372 | struct ethtool_rxnfc *cmd) |
| 373 | { |
| 374 | struct i40e_hw *hw = &adapter->hw; |
| 375 | u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) | |
| 376 | ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32); |
| 377 | |
| 378 | /* We always hash on IP src and dest addresses */ |
| 379 | cmd->data = RXH_IP_SRC | RXH_IP_DST; |
| 380 | |
| 381 | switch (cmd->flow_type) { |
| 382 | case TCP_V4_FLOW: |
| 383 | if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP)) |
| 384 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 385 | break; |
| 386 | case UDP_V4_FLOW: |
| 387 | if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP)) |
| 388 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 389 | break; |
| 390 | |
| 391 | case SCTP_V4_FLOW: |
| 392 | case AH_ESP_V4_FLOW: |
| 393 | case AH_V4_FLOW: |
| 394 | case ESP_V4_FLOW: |
| 395 | case IPV4_FLOW: |
| 396 | break; |
| 397 | |
| 398 | case TCP_V6_FLOW: |
| 399 | if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP)) |
| 400 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 401 | break; |
| 402 | case UDP_V6_FLOW: |
| 403 | if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP)) |
| 404 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 405 | break; |
| 406 | |
| 407 | case SCTP_V6_FLOW: |
| 408 | case AH_ESP_V6_FLOW: |
| 409 | case AH_V6_FLOW: |
| 410 | case ESP_V6_FLOW: |
| 411 | case IPV6_FLOW: |
| 412 | break; |
| 413 | default: |
| 414 | cmd->data = 0; |
| 415 | return -EINVAL; |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * i40evf_get_rxnfc - command to get RX flow classification rules |
| 423 | * @netdev: network interface device structure |
| 424 | * @cmd: ethtool rxnfc command |
| 425 | * |
| 426 | * Returns Success if the command is supported. |
| 427 | **/ |
| 428 | static int i40evf_get_rxnfc(struct net_device *netdev, |
| 429 | struct ethtool_rxnfc *cmd, |
| 430 | u32 *rule_locs) |
| 431 | { |
| 432 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 433 | int ret = -EOPNOTSUPP; |
| 434 | |
| 435 | switch (cmd->cmd) { |
| 436 | case ETHTOOL_GRXRINGS: |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 437 | cmd->data = adapter->num_active_queues; |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 438 | ret = 0; |
| 439 | break; |
| 440 | case ETHTOOL_GRXFH: |
| 441 | ret = i40evf_get_rss_hash_opts(adapter, cmd); |
| 442 | break; |
| 443 | default: |
| 444 | break; |
| 445 | } |
| 446 | |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash |
| 452 | * @adapter: board private structure |
| 453 | * @cmd: ethtool rxnfc command |
| 454 | * |
| 455 | * Returns Success if the flow input set is supported. |
| 456 | **/ |
| 457 | static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter, |
| 458 | struct ethtool_rxnfc *nfc) |
| 459 | { |
| 460 | struct i40e_hw *hw = &adapter->hw; |
| 461 | |
| 462 | u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) | |
| 463 | ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32); |
| 464 | |
| 465 | /* RSS does not support anything other than hashing |
| 466 | * to queues on src and dst IPs and ports |
| 467 | */ |
| 468 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | |
| 469 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) |
| 470 | return -EINVAL; |
| 471 | |
| 472 | /* We need at least the IP SRC and DEST fields for hashing */ |
| 473 | if (!(nfc->data & RXH_IP_SRC) || |
| 474 | !(nfc->data & RXH_IP_DST)) |
| 475 | return -EINVAL; |
| 476 | |
| 477 | switch (nfc->flow_type) { |
| 478 | case TCP_V4_FLOW: |
| 479 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 480 | case 0: |
| 481 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); |
| 482 | break; |
| 483 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 484 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); |
| 485 | break; |
| 486 | default: |
| 487 | return -EINVAL; |
| 488 | } |
| 489 | break; |
| 490 | case TCP_V6_FLOW: |
| 491 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 492 | case 0: |
| 493 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); |
| 494 | break; |
| 495 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 496 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); |
| 497 | break; |
| 498 | default: |
| 499 | return -EINVAL; |
| 500 | } |
| 501 | break; |
| 502 | case UDP_V4_FLOW: |
| 503 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 504 | case 0: |
| 505 | hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 506 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); |
| 507 | break; |
| 508 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 509 | hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 510 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); |
| 511 | break; |
| 512 | default: |
| 513 | return -EINVAL; |
| 514 | } |
| 515 | break; |
| 516 | case UDP_V6_FLOW: |
| 517 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 518 | case 0: |
| 519 | hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 520 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); |
| 521 | break; |
| 522 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 523 | hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 524 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); |
| 525 | break; |
| 526 | default: |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | break; |
| 530 | case AH_ESP_V4_FLOW: |
| 531 | case AH_V4_FLOW: |
| 532 | case ESP_V4_FLOW: |
| 533 | case SCTP_V4_FLOW: |
| 534 | if ((nfc->data & RXH_L4_B_0_1) || |
| 535 | (nfc->data & RXH_L4_B_2_3)) |
| 536 | return -EINVAL; |
| 537 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); |
| 538 | break; |
| 539 | case AH_ESP_V6_FLOW: |
| 540 | case AH_V6_FLOW: |
| 541 | case ESP_V6_FLOW: |
| 542 | case SCTP_V6_FLOW: |
| 543 | if ((nfc->data & RXH_L4_B_0_1) || |
| 544 | (nfc->data & RXH_L4_B_2_3)) |
| 545 | return -EINVAL; |
| 546 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); |
| 547 | break; |
| 548 | case IPV4_FLOW: |
| 549 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 550 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4); |
| 551 | break; |
| 552 | case IPV6_FLOW: |
| 553 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 554 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6); |
| 555 | break; |
| 556 | default: |
| 557 | return -EINVAL; |
| 558 | } |
| 559 | |
| 560 | wr32(hw, I40E_VFQF_HENA(0), (u32)hena); |
| 561 | wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32)); |
| 562 | i40e_flush(hw); |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * i40evf_set_rxnfc - command to set RX flow classification rules |
| 569 | * @netdev: network interface device structure |
| 570 | * @cmd: ethtool rxnfc command |
| 571 | * |
| 572 | * Returns Success if the command is supported. |
| 573 | **/ |
| 574 | static int i40evf_set_rxnfc(struct net_device *netdev, |
| 575 | struct ethtool_rxnfc *cmd) |
| 576 | { |
| 577 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 578 | int ret = -EOPNOTSUPP; |
| 579 | |
| 580 | switch (cmd->cmd) { |
| 581 | case ETHTOOL_SRXFH: |
| 582 | ret = i40evf_set_rss_hash_opt(adapter, cmd); |
| 583 | break; |
| 584 | default: |
| 585 | break; |
| 586 | } |
| 587 | |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * i40evf_get_channels: get the number of channels supported by the device |
| 593 | * @netdev: network interface device structure |
| 594 | * @ch: channel information structure |
| 595 | * |
| 596 | * For the purposes of our device, we only use combined channels, i.e. a tx/rx |
| 597 | * queue pair. Report one extra channel to match our "other" MSI-X vector. |
| 598 | **/ |
| 599 | static void i40evf_get_channels(struct net_device *netdev, |
| 600 | struct ethtool_channels *ch) |
| 601 | { |
| 602 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 603 | |
| 604 | /* Report maximum channels */ |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 605 | ch->max_combined = adapter->num_active_queues; |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 606 | |
| 607 | ch->max_other = NONQ_VECS; |
| 608 | ch->other_count = NONQ_VECS; |
| 609 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 610 | ch->combined_count = adapter->num_active_queues; |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
| 614 | * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size |
| 615 | * @netdev: network interface device structure |
| 616 | * |
| 617 | * Returns the table size. |
| 618 | **/ |
| 619 | static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev) |
| 620 | { |
| 621 | return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4; |
| 622 | } |
| 623 | |
| 624 | /** |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 625 | * i40evf_get_rxfh - get the rx flow hash indirection table |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 626 | * @netdev: network interface device structure |
| 627 | * @indir: indirection table |
Mitch Williams | 2cda3f3 | 2014-11-11 20:02:31 +0000 | [diff] [blame] | 628 | * @key: hash key |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 629 | * |
| 630 | * Reads the indirection table directly from the hardware. Always returns 0. |
| 631 | **/ |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 632 | static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, |
| 633 | u8 *hfunc) |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 634 | { |
| 635 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 636 | struct i40e_hw *hw = &adapter->hw; |
| 637 | u32 hlut_val; |
| 638 | int i, j; |
| 639 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 640 | if (hfunc) |
| 641 | *hfunc = ETH_RSS_HASH_TOP; |
| 642 | if (!indir) |
| 643 | return 0; |
| 644 | |
Mitch Williams | ed250ec | 2015-02-24 06:58:51 +0000 | [diff] [blame^] | 645 | if (indir) { |
| 646 | for (i = 0, j = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) { |
| 647 | hlut_val = rd32(hw, I40E_VFQF_HLUT(i)); |
| 648 | indir[j++] = hlut_val & 0xff; |
| 649 | indir[j++] = (hlut_val >> 8) & 0xff; |
| 650 | indir[j++] = (hlut_val >> 16) & 0xff; |
| 651 | indir[j++] = (hlut_val >> 24) & 0xff; |
| 652 | } |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 653 | } |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | /** |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 658 | * i40evf_set_rxfh - set the rx flow hash indirection table |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 659 | * @netdev: network interface device structure |
| 660 | * @indir: indirection table |
Mitch Williams | 2cda3f3 | 2014-11-11 20:02:31 +0000 | [diff] [blame] | 661 | * @key: hash key |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 662 | * |
| 663 | * Returns -EINVAL if the table specifies an inavlid queue id, otherwise |
| 664 | * returns 0 after programming the table. |
| 665 | **/ |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 666 | static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir, |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 667 | const u8 *key, const u8 hfunc) |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 668 | { |
| 669 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 670 | struct i40e_hw *hw = &adapter->hw; |
| 671 | u32 hlut_val; |
| 672 | int i, j; |
| 673 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 674 | /* We do not allow change in unsupported parameters */ |
| 675 | if (key || |
| 676 | (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) |
| 677 | return -EOPNOTSUPP; |
| 678 | if (!indir) |
| 679 | return 0; |
| 680 | |
Mitch Williams | cc70b08 | 2014-06-03 23:50:20 +0000 | [diff] [blame] | 681 | for (i = 0, j = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) { |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 682 | hlut_val = indir[j++]; |
| 683 | hlut_val |= indir[j++] << 8; |
| 684 | hlut_val |= indir[j++] << 16; |
| 685 | hlut_val |= indir[j++] << 24; |
| 686 | wr32(hw, I40E_VFQF_HLUT(i), hlut_val); |
| 687 | } |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
Mitch Williams | f0c53c7 | 2014-04-04 04:43:11 +0000 | [diff] [blame] | 692 | static const struct ethtool_ops i40evf_ethtool_ops = { |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 693 | .get_settings = i40evf_get_settings, |
| 694 | .get_drvinfo = i40evf_get_drvinfo, |
| 695 | .get_link = ethtool_op_get_link, |
| 696 | .get_ringparam = i40evf_get_ringparam, |
| 697 | .set_ringparam = i40evf_set_ringparam, |
| 698 | .get_strings = i40evf_get_strings, |
| 699 | .get_ethtool_stats = i40evf_get_ethtool_stats, |
| 700 | .get_sset_count = i40evf_get_sset_count, |
| 701 | .get_msglevel = i40evf_get_msglevel, |
| 702 | .set_msglevel = i40evf_set_msglevel, |
| 703 | .get_coalesce = i40evf_get_coalesce, |
| 704 | .set_coalesce = i40evf_set_coalesce, |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 705 | .get_rxnfc = i40evf_get_rxnfc, |
| 706 | .set_rxnfc = i40evf_set_rxnfc, |
| 707 | .get_rxfh_indir_size = i40evf_get_rxfh_indir_size, |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 708 | .get_rxfh = i40evf_get_rxfh, |
| 709 | .set_rxfh = i40evf_set_rxfh, |
Mitch A Williams | 4e9dc31 | 2014-04-01 04:43:49 +0000 | [diff] [blame] | 710 | .get_channels = i40evf_get_channels, |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 711 | }; |
| 712 | |
| 713 | /** |
| 714 | * i40evf_set_ethtool_ops - Initialize ethtool ops struct |
| 715 | * @netdev: network interface device structure |
| 716 | * |
| 717 | * Sets ethtool ops struct in our netdev so that ethtool can call |
| 718 | * our functions. |
| 719 | **/ |
| 720 | void i40evf_set_ethtool_ops(struct net_device *netdev) |
| 721 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 722 | netdev->ethtool_ops = &i40evf_ethtool_ops; |
Greg Rose | fbb7ddf | 2013-12-21 06:12:56 +0000 | [diff] [blame] | 723 | } |