Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1 | /* Intel Ethernet Switch Host Interface Driver |
Jacob Keller | 9de6a1a | 2016-04-01 16:17:31 -0700 | [diff] [blame] | 2 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * The full GNU General Public License is included in this distribution in |
| 14 | * the file called "COPYING". |
| 15 | * |
| 16 | * Contact Information: |
| 17 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 18 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 19 | */ |
| 20 | |
| 21 | #include "fm10k.h" |
Alexander Duyck | 3abaae4 | 2014-09-20 19:49:43 -0400 | [diff] [blame] | 22 | #include <linux/vmalloc.h> |
Bruce Allan | 0d722ec | 2015-12-08 17:20:49 -0800 | [diff] [blame] | 23 | #ifdef CONFIG_FM10K_VXLAN |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 24 | #include <net/vxlan.h> |
Andy Zhou | f6b03c1 | 2014-10-04 06:19:11 +0000 | [diff] [blame] | 25 | #endif /* CONFIG_FM10K_VXLAN */ |
Alexander Duyck | 3abaae4 | 2014-09-20 19:49:43 -0400 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * fm10k_setup_tx_resources - allocate Tx resources (Descriptors) |
| 29 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
| 30 | * |
| 31 | * Return 0 on success, negative on failure |
| 32 | **/ |
| 33 | int fm10k_setup_tx_resources(struct fm10k_ring *tx_ring) |
| 34 | { |
| 35 | struct device *dev = tx_ring->dev; |
| 36 | int size; |
| 37 | |
| 38 | size = sizeof(struct fm10k_tx_buffer) * tx_ring->count; |
| 39 | |
| 40 | tx_ring->tx_buffer = vzalloc(size); |
| 41 | if (!tx_ring->tx_buffer) |
| 42 | goto err; |
| 43 | |
| 44 | u64_stats_init(&tx_ring->syncp); |
| 45 | |
| 46 | /* round up to nearest 4K */ |
| 47 | tx_ring->size = tx_ring->count * sizeof(struct fm10k_tx_desc); |
| 48 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 49 | |
| 50 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 51 | &tx_ring->dma, GFP_KERNEL); |
| 52 | if (!tx_ring->desc) |
| 53 | goto err; |
| 54 | |
| 55 | return 0; |
| 56 | |
| 57 | err: |
| 58 | vfree(tx_ring->tx_buffer); |
| 59 | tx_ring->tx_buffer = NULL; |
| 60 | return -ENOMEM; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * fm10k_setup_all_tx_resources - allocate all queues Tx resources |
| 65 | * @interface: board private structure |
| 66 | * |
| 67 | * If this function returns with an error, then it's possible one or |
| 68 | * more of the rings is populated (while the rest are not). It is the |
| 69 | * callers duty to clean those orphaned rings. |
| 70 | * |
| 71 | * Return 0 on success, negative on failure |
| 72 | **/ |
| 73 | static int fm10k_setup_all_tx_resources(struct fm10k_intfc *interface) |
| 74 | { |
| 75 | int i, err = 0; |
| 76 | |
| 77 | for (i = 0; i < interface->num_tx_queues; i++) { |
| 78 | err = fm10k_setup_tx_resources(interface->tx_ring[i]); |
| 79 | if (!err) |
| 80 | continue; |
| 81 | |
| 82 | netif_err(interface, probe, interface->netdev, |
| 83 | "Allocation for Tx Queue %u failed\n", i); |
| 84 | goto err_setup_tx; |
| 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | err_setup_tx: |
| 89 | /* rewind the index freeing the rings as we go */ |
| 90 | while (i--) |
| 91 | fm10k_free_tx_resources(interface->tx_ring[i]); |
| 92 | return err; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * fm10k_setup_rx_resources - allocate Rx resources (Descriptors) |
| 97 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 98 | * |
| 99 | * Returns 0 on success, negative on failure |
| 100 | **/ |
| 101 | int fm10k_setup_rx_resources(struct fm10k_ring *rx_ring) |
| 102 | { |
| 103 | struct device *dev = rx_ring->dev; |
| 104 | int size; |
| 105 | |
| 106 | size = sizeof(struct fm10k_rx_buffer) * rx_ring->count; |
| 107 | |
| 108 | rx_ring->rx_buffer = vzalloc(size); |
| 109 | if (!rx_ring->rx_buffer) |
| 110 | goto err; |
| 111 | |
| 112 | u64_stats_init(&rx_ring->syncp); |
| 113 | |
| 114 | /* Round up to nearest 4K */ |
| 115 | rx_ring->size = rx_ring->count * sizeof(union fm10k_rx_desc); |
| 116 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 117 | |
| 118 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 119 | &rx_ring->dma, GFP_KERNEL); |
| 120 | if (!rx_ring->desc) |
| 121 | goto err; |
| 122 | |
| 123 | return 0; |
| 124 | err: |
| 125 | vfree(rx_ring->rx_buffer); |
| 126 | rx_ring->rx_buffer = NULL; |
| 127 | return -ENOMEM; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * fm10k_setup_all_rx_resources - allocate all queues Rx resources |
| 132 | * @interface: board private structure |
| 133 | * |
| 134 | * If this function returns with an error, then it's possible one or |
| 135 | * more of the rings is populated (while the rest are not). It is the |
| 136 | * callers duty to clean those orphaned rings. |
| 137 | * |
| 138 | * Return 0 on success, negative on failure |
| 139 | **/ |
| 140 | static int fm10k_setup_all_rx_resources(struct fm10k_intfc *interface) |
| 141 | { |
| 142 | int i, err = 0; |
| 143 | |
| 144 | for (i = 0; i < interface->num_rx_queues; i++) { |
| 145 | err = fm10k_setup_rx_resources(interface->rx_ring[i]); |
| 146 | if (!err) |
| 147 | continue; |
| 148 | |
| 149 | netif_err(interface, probe, interface->netdev, |
| 150 | "Allocation for Rx Queue %u failed\n", i); |
| 151 | goto err_setup_rx; |
| 152 | } |
| 153 | |
| 154 | return 0; |
| 155 | err_setup_rx: |
| 156 | /* rewind the index freeing the rings as we go */ |
| 157 | while (i--) |
| 158 | fm10k_free_rx_resources(interface->rx_ring[i]); |
| 159 | return err; |
| 160 | } |
| 161 | |
| 162 | void fm10k_unmap_and_free_tx_resource(struct fm10k_ring *ring, |
| 163 | struct fm10k_tx_buffer *tx_buffer) |
| 164 | { |
| 165 | if (tx_buffer->skb) { |
| 166 | dev_kfree_skb_any(tx_buffer->skb); |
| 167 | if (dma_unmap_len(tx_buffer, len)) |
| 168 | dma_unmap_single(ring->dev, |
| 169 | dma_unmap_addr(tx_buffer, dma), |
| 170 | dma_unmap_len(tx_buffer, len), |
| 171 | DMA_TO_DEVICE); |
| 172 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 173 | dma_unmap_page(ring->dev, |
| 174 | dma_unmap_addr(tx_buffer, dma), |
| 175 | dma_unmap_len(tx_buffer, len), |
| 176 | DMA_TO_DEVICE); |
| 177 | } |
| 178 | tx_buffer->next_to_watch = NULL; |
| 179 | tx_buffer->skb = NULL; |
| 180 | dma_unmap_len_set(tx_buffer, len, 0); |
| 181 | /* tx_buffer must be completely set up in the transmit path */ |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * fm10k_clean_tx_ring - Free Tx Buffers |
| 186 | * @tx_ring: ring to be cleaned |
| 187 | **/ |
| 188 | static void fm10k_clean_tx_ring(struct fm10k_ring *tx_ring) |
| 189 | { |
| 190 | struct fm10k_tx_buffer *tx_buffer; |
| 191 | unsigned long size; |
| 192 | u16 i; |
| 193 | |
| 194 | /* ring already cleared, nothing to do */ |
| 195 | if (!tx_ring->tx_buffer) |
| 196 | return; |
| 197 | |
| 198 | /* Free all the Tx ring sk_buffs */ |
| 199 | for (i = 0; i < tx_ring->count; i++) { |
| 200 | tx_buffer = &tx_ring->tx_buffer[i]; |
| 201 | fm10k_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 202 | } |
| 203 | |
| 204 | /* reset BQL values */ |
| 205 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 206 | |
| 207 | size = sizeof(struct fm10k_tx_buffer) * tx_ring->count; |
| 208 | memset(tx_ring->tx_buffer, 0, size); |
| 209 | |
| 210 | /* Zero out the descriptor ring */ |
| 211 | memset(tx_ring->desc, 0, tx_ring->size); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * fm10k_free_tx_resources - Free Tx Resources per Queue |
| 216 | * @tx_ring: Tx descriptor ring for a specific queue |
| 217 | * |
| 218 | * Free all transmit software resources |
| 219 | **/ |
| 220 | void fm10k_free_tx_resources(struct fm10k_ring *tx_ring) |
| 221 | { |
| 222 | fm10k_clean_tx_ring(tx_ring); |
| 223 | |
| 224 | vfree(tx_ring->tx_buffer); |
| 225 | tx_ring->tx_buffer = NULL; |
| 226 | |
| 227 | /* if not set, then don't free */ |
| 228 | if (!tx_ring->desc) |
| 229 | return; |
| 230 | |
| 231 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 232 | tx_ring->desc, tx_ring->dma); |
| 233 | tx_ring->desc = NULL; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * fm10k_clean_all_tx_rings - Free Tx Buffers for all queues |
| 238 | * @interface: board private structure |
| 239 | **/ |
| 240 | void fm10k_clean_all_tx_rings(struct fm10k_intfc *interface) |
| 241 | { |
| 242 | int i; |
| 243 | |
| 244 | for (i = 0; i < interface->num_tx_queues; i++) |
| 245 | fm10k_clean_tx_ring(interface->tx_ring[i]); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * fm10k_free_all_tx_resources - Free Tx Resources for All Queues |
| 250 | * @interface: board private structure |
| 251 | * |
| 252 | * Free all transmit software resources |
| 253 | **/ |
| 254 | static void fm10k_free_all_tx_resources(struct fm10k_intfc *interface) |
| 255 | { |
| 256 | int i = interface->num_tx_queues; |
| 257 | |
| 258 | while (i--) |
| 259 | fm10k_free_tx_resources(interface->tx_ring[i]); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * fm10k_clean_rx_ring - Free Rx Buffers per Queue |
| 264 | * @rx_ring: ring to free buffers from |
| 265 | **/ |
| 266 | static void fm10k_clean_rx_ring(struct fm10k_ring *rx_ring) |
| 267 | { |
| 268 | unsigned long size; |
| 269 | u16 i; |
| 270 | |
| 271 | if (!rx_ring->rx_buffer) |
| 272 | return; |
| 273 | |
| 274 | if (rx_ring->skb) |
| 275 | dev_kfree_skb(rx_ring->skb); |
| 276 | rx_ring->skb = NULL; |
| 277 | |
| 278 | /* Free all the Rx ring sk_buffs */ |
| 279 | for (i = 0; i < rx_ring->count; i++) { |
| 280 | struct fm10k_rx_buffer *buffer = &rx_ring->rx_buffer[i]; |
| 281 | /* clean-up will only set page pointer to NULL */ |
| 282 | if (!buffer->page) |
| 283 | continue; |
| 284 | |
| 285 | dma_unmap_page(rx_ring->dev, buffer->dma, |
| 286 | PAGE_SIZE, DMA_FROM_DEVICE); |
| 287 | __free_page(buffer->page); |
| 288 | |
| 289 | buffer->page = NULL; |
| 290 | } |
| 291 | |
| 292 | size = sizeof(struct fm10k_rx_buffer) * rx_ring->count; |
| 293 | memset(rx_ring->rx_buffer, 0, size); |
| 294 | |
| 295 | /* Zero out the descriptor ring */ |
| 296 | memset(rx_ring->desc, 0, rx_ring->size); |
| 297 | |
| 298 | rx_ring->next_to_alloc = 0; |
| 299 | rx_ring->next_to_clean = 0; |
| 300 | rx_ring->next_to_use = 0; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * fm10k_free_rx_resources - Free Rx Resources |
| 305 | * @rx_ring: ring to clean the resources from |
| 306 | * |
| 307 | * Free all receive software resources |
| 308 | **/ |
| 309 | void fm10k_free_rx_resources(struct fm10k_ring *rx_ring) |
| 310 | { |
| 311 | fm10k_clean_rx_ring(rx_ring); |
| 312 | |
| 313 | vfree(rx_ring->rx_buffer); |
| 314 | rx_ring->rx_buffer = NULL; |
| 315 | |
| 316 | /* if not set, then don't free */ |
| 317 | if (!rx_ring->desc) |
| 318 | return; |
| 319 | |
| 320 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 321 | rx_ring->desc, rx_ring->dma); |
| 322 | |
| 323 | rx_ring->desc = NULL; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * fm10k_clean_all_rx_rings - Free Rx Buffers for all queues |
| 328 | * @interface: board private structure |
| 329 | **/ |
| 330 | void fm10k_clean_all_rx_rings(struct fm10k_intfc *interface) |
| 331 | { |
| 332 | int i; |
| 333 | |
| 334 | for (i = 0; i < interface->num_rx_queues; i++) |
| 335 | fm10k_clean_rx_ring(interface->rx_ring[i]); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * fm10k_free_all_rx_resources - Free Rx Resources for All Queues |
| 340 | * @interface: board private structure |
| 341 | * |
| 342 | * Free all receive software resources |
| 343 | **/ |
| 344 | static void fm10k_free_all_rx_resources(struct fm10k_intfc *interface) |
| 345 | { |
| 346 | int i = interface->num_rx_queues; |
| 347 | |
| 348 | while (i--) |
| 349 | fm10k_free_rx_resources(interface->rx_ring[i]); |
| 350 | } |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 351 | |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 352 | /** |
| 353 | * fm10k_request_glort_range - Request GLORTs for use in configuring rules |
| 354 | * @interface: board private structure |
| 355 | * |
Matthew Vick | eca3204 | 2015-01-31 02:23:05 +0000 | [diff] [blame] | 356 | * This function allocates a range of glorts for this interface to use. |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 357 | **/ |
| 358 | static void fm10k_request_glort_range(struct fm10k_intfc *interface) |
| 359 | { |
| 360 | struct fm10k_hw *hw = &interface->hw; |
| 361 | u16 mask = (~hw->mac.dglort_map) >> FM10K_DGLORTMAP_MASK_SHIFT; |
| 362 | |
| 363 | /* establish GLORT base */ |
| 364 | interface->glort = hw->mac.dglort_map & FM10K_DGLORTMAP_NONE; |
| 365 | interface->glort_count = 0; |
| 366 | |
| 367 | /* nothing we can do until mask is allocated */ |
| 368 | if (hw->mac.dglort_map == FM10K_DGLORTMAP_NONE) |
| 369 | return; |
| 370 | |
Alexander Duyck | 883a9cc | 2014-09-20 19:52:09 -0400 | [diff] [blame] | 371 | /* we support 3 possible GLORT configurations. |
| 372 | * 1: VFs consume all but the last 1 |
| 373 | * 2: VFs and PF split glorts with possible gap between |
| 374 | * 3: VFs allocated first 64, all others belong to PF |
| 375 | */ |
| 376 | if (mask <= hw->iov.total_vfs) { |
| 377 | interface->glort_count = 1; |
| 378 | interface->glort += mask; |
| 379 | } else if (mask < 64) { |
| 380 | interface->glort_count = (mask + 1) / 2; |
| 381 | interface->glort += interface->glort_count; |
| 382 | } else { |
| 383 | interface->glort_count = mask - 63; |
| 384 | interface->glort += 64; |
| 385 | } |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /** |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 389 | * fm10k_del_vxlan_port_all |
| 390 | * @interface: board private structure |
| 391 | * |
| 392 | * This function frees the entire vxlan_port list |
| 393 | **/ |
| 394 | static void fm10k_del_vxlan_port_all(struct fm10k_intfc *interface) |
| 395 | { |
| 396 | struct fm10k_vxlan_port *vxlan_port; |
| 397 | |
| 398 | /* flush all entries from list */ |
| 399 | vxlan_port = list_first_entry_or_null(&interface->vxlan_port, |
| 400 | struct fm10k_vxlan_port, list); |
| 401 | while (vxlan_port) { |
| 402 | list_del(&vxlan_port->list); |
| 403 | kfree(vxlan_port); |
| 404 | vxlan_port = list_first_entry_or_null(&interface->vxlan_port, |
| 405 | struct fm10k_vxlan_port, |
| 406 | list); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * fm10k_restore_vxlan_port |
| 412 | * @interface: board private structure |
| 413 | * |
| 414 | * This function restores the value in the tunnel_cfg register after reset |
| 415 | **/ |
| 416 | static void fm10k_restore_vxlan_port(struct fm10k_intfc *interface) |
| 417 | { |
| 418 | struct fm10k_hw *hw = &interface->hw; |
| 419 | struct fm10k_vxlan_port *vxlan_port; |
| 420 | |
| 421 | /* only the PF supports configuring tunnels */ |
| 422 | if (hw->mac.type != fm10k_mac_pf) |
| 423 | return; |
| 424 | |
| 425 | vxlan_port = list_first_entry_or_null(&interface->vxlan_port, |
| 426 | struct fm10k_vxlan_port, list); |
| 427 | |
| 428 | /* restore tunnel configuration register */ |
| 429 | fm10k_write_reg(hw, FM10K_TUNNEL_CFG, |
| 430 | (vxlan_port ? ntohs(vxlan_port->port) : 0) | |
| 431 | (ETH_P_TEB << FM10K_TUNNEL_CFG_NVGRE_SHIFT)); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * fm10k_add_vxlan_port |
| 436 | * @netdev: network interface device structure |
| 437 | * @sa_family: Address family of new port |
| 438 | * @port: port number used for VXLAN |
| 439 | * |
Jacob Keller | d8ec92f | 2016-02-10 14:45:51 -0800 | [diff] [blame] | 440 | * This function is called when a new VXLAN interface has added a new port |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 441 | * number to the range that is currently in use for VXLAN. The new port |
| 442 | * number is always added to the tail so that the port number list should |
| 443 | * match the order in which the ports were allocated. The head of the list |
| 444 | * is always used as the VXLAN port number for offloads. |
| 445 | **/ |
| 446 | static void fm10k_add_vxlan_port(struct net_device *dev, |
| 447 | sa_family_t sa_family, __be16 port) { |
| 448 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 449 | struct fm10k_vxlan_port *vxlan_port; |
| 450 | |
| 451 | /* only the PF supports configuring tunnels */ |
| 452 | if (interface->hw.mac.type != fm10k_mac_pf) |
| 453 | return; |
| 454 | |
| 455 | /* existing ports are pulled out so our new entry is always last */ |
| 456 | fm10k_vxlan_port_for_each(vxlan_port, interface) { |
| 457 | if ((vxlan_port->port == port) && |
| 458 | (vxlan_port->sa_family == sa_family)) { |
| 459 | list_del(&vxlan_port->list); |
| 460 | goto insert_tail; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* allocate memory to track ports */ |
| 465 | vxlan_port = kmalloc(sizeof(*vxlan_port), GFP_ATOMIC); |
| 466 | if (!vxlan_port) |
| 467 | return; |
| 468 | vxlan_port->port = port; |
| 469 | vxlan_port->sa_family = sa_family; |
| 470 | |
| 471 | insert_tail: |
| 472 | /* add new port value to list */ |
| 473 | list_add_tail(&vxlan_port->list, &interface->vxlan_port); |
| 474 | |
| 475 | fm10k_restore_vxlan_port(interface); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * fm10k_del_vxlan_port |
| 480 | * @netdev: network interface device structure |
| 481 | * @sa_family: Address family of freed port |
| 482 | * @port: port number used for VXLAN |
| 483 | * |
Jacob Keller | d8ec92f | 2016-02-10 14:45:51 -0800 | [diff] [blame] | 484 | * This function is called when a new VXLAN interface has freed a port |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 485 | * number from the range that is currently in use for VXLAN. The freed |
| 486 | * port is removed from the list and the new head is used to determine |
| 487 | * the port number for offloads. |
| 488 | **/ |
| 489 | static void fm10k_del_vxlan_port(struct net_device *dev, |
| 490 | sa_family_t sa_family, __be16 port) { |
| 491 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 492 | struct fm10k_vxlan_port *vxlan_port; |
| 493 | |
| 494 | if (interface->hw.mac.type != fm10k_mac_pf) |
| 495 | return; |
| 496 | |
| 497 | /* find the port in the list and free it */ |
| 498 | fm10k_vxlan_port_for_each(vxlan_port, interface) { |
| 499 | if ((vxlan_port->port == port) && |
| 500 | (vxlan_port->sa_family == sa_family)) { |
| 501 | list_del(&vxlan_port->list); |
| 502 | kfree(vxlan_port); |
| 503 | break; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | fm10k_restore_vxlan_port(interface); |
| 508 | } |
| 509 | |
| 510 | /** |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 511 | * fm10k_open - Called when a network interface is made active |
| 512 | * @netdev: network interface device structure |
| 513 | * |
| 514 | * Returns 0 on success, negative value on failure |
| 515 | * |
| 516 | * The open entry point is called when a network interface is made |
| 517 | * active by the system (IFF_UP). At this point all resources needed |
| 518 | * for transmit and receive operations are allocated, the interrupt |
| 519 | * handler is registered with the OS, the watchdog timer is started, |
| 520 | * and the stack is notified that the interface is ready. |
| 521 | **/ |
| 522 | int fm10k_open(struct net_device *netdev) |
| 523 | { |
| 524 | struct fm10k_intfc *interface = netdev_priv(netdev); |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 525 | int err; |
| 526 | |
Alexander Duyck | 3abaae4 | 2014-09-20 19:49:43 -0400 | [diff] [blame] | 527 | /* allocate transmit descriptors */ |
| 528 | err = fm10k_setup_all_tx_resources(interface); |
| 529 | if (err) |
| 530 | goto err_setup_tx; |
| 531 | |
| 532 | /* allocate receive descriptors */ |
| 533 | err = fm10k_setup_all_rx_resources(interface); |
| 534 | if (err) |
| 535 | goto err_setup_rx; |
| 536 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 537 | /* allocate interrupt resources */ |
| 538 | err = fm10k_qv_request_irq(interface); |
| 539 | if (err) |
| 540 | goto err_req_irq; |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 541 | |
| 542 | /* setup GLORT assignment for this port */ |
| 543 | fm10k_request_glort_range(interface); |
| 544 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 545 | /* Notify the stack of the actual queue counts */ |
Alexander Duyck | c9d4994 | 2014-09-30 22:49:22 +0000 | [diff] [blame] | 546 | err = netif_set_real_num_tx_queues(netdev, |
| 547 | interface->num_tx_queues); |
| 548 | if (err) |
| 549 | goto err_set_queues; |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 550 | |
| 551 | err = netif_set_real_num_rx_queues(netdev, |
| 552 | interface->num_rx_queues); |
| 553 | if (err) |
| 554 | goto err_set_queues; |
| 555 | |
Bruce Allan | 0d722ec | 2015-12-08 17:20:49 -0800 | [diff] [blame] | 556 | #ifdef CONFIG_FM10K_VXLAN |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 557 | /* update VXLAN port configuration */ |
| 558 | vxlan_get_rx_port(netdev); |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 559 | #endif |
Bruce Allan | 0d722ec | 2015-12-08 17:20:49 -0800 | [diff] [blame] | 560 | |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 561 | fm10k_up(interface); |
| 562 | |
| 563 | return 0; |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 564 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 565 | err_set_queues: |
| 566 | fm10k_qv_free_irq(interface); |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 567 | err_req_irq: |
Alexander Duyck | 3abaae4 | 2014-09-20 19:49:43 -0400 | [diff] [blame] | 568 | fm10k_free_all_rx_resources(interface); |
| 569 | err_setup_rx: |
| 570 | fm10k_free_all_tx_resources(interface); |
| 571 | err_setup_tx: |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 572 | return err; |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * fm10k_close - Disables a network interface |
| 577 | * @netdev: network interface device structure |
| 578 | * |
| 579 | * Returns 0, this is not allowed to fail |
| 580 | * |
| 581 | * The close entry point is called when an interface is de-activated |
| 582 | * by the OS. The hardware is still under the drivers control, but |
| 583 | * needs to be disabled. A global MAC reset is issued to stop the |
| 584 | * hardware, and all transmit and receive resources are freed. |
| 585 | **/ |
| 586 | int fm10k_close(struct net_device *netdev) |
| 587 | { |
| 588 | struct fm10k_intfc *interface = netdev_priv(netdev); |
| 589 | |
| 590 | fm10k_down(interface); |
| 591 | |
Alexander Duyck | 18283ca | 2014-09-20 19:48:51 -0400 | [diff] [blame] | 592 | fm10k_qv_free_irq(interface); |
| 593 | |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 594 | fm10k_del_vxlan_port_all(interface); |
| 595 | |
Alexander Duyck | 3abaae4 | 2014-09-20 19:49:43 -0400 | [diff] [blame] | 596 | fm10k_free_all_tx_resources(interface); |
| 597 | fm10k_free_all_rx_resources(interface); |
| 598 | |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 599 | return 0; |
| 600 | } |
| 601 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 602 | static netdev_tx_t fm10k_xmit_frame(struct sk_buff *skb, struct net_device *dev) |
| 603 | { |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 604 | struct fm10k_intfc *interface = netdev_priv(dev); |
Alexander Duyck | c9d4994 | 2014-09-30 22:49:22 +0000 | [diff] [blame] | 605 | unsigned int r_idx = skb->queue_mapping; |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 606 | int err; |
| 607 | |
Bruce Allan | a4fcad6 | 2015-10-28 17:19:40 -0700 | [diff] [blame] | 608 | if ((skb->protocol == htons(ETH_P_8021Q)) && |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 609 | !skb_vlan_tag_present(skb)) { |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 610 | /* FM10K only supports hardware tagging, any tags in frame |
| 611 | * are considered 2nd level or "outer" tags |
| 612 | */ |
| 613 | struct vlan_hdr *vhdr; |
| 614 | __be16 proto; |
| 615 | |
| 616 | /* make sure skb is not shared */ |
| 617 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 618 | if (!skb) |
| 619 | return NETDEV_TX_OK; |
| 620 | |
| 621 | /* make sure there is enough room to move the ethernet header */ |
| 622 | if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN))) |
| 623 | return NETDEV_TX_OK; |
| 624 | |
| 625 | /* verify the skb head is not shared */ |
| 626 | err = skb_cow_head(skb, 0); |
stephen hemminger | 6f97532 | 2015-11-17 14:24:27 -0800 | [diff] [blame] | 627 | if (err) { |
| 628 | dev_kfree_skb(skb); |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 629 | return NETDEV_TX_OK; |
stephen hemminger | 6f97532 | 2015-11-17 14:24:27 -0800 | [diff] [blame] | 630 | } |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 631 | |
Jacob Keller | aa502b4 | 2015-11-02 12:10:22 -0800 | [diff] [blame] | 632 | /* locate VLAN header */ |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 633 | vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN); |
| 634 | |
| 635 | /* pull the 2 key pieces of data out of it */ |
| 636 | __vlan_hwaccel_put_tag(skb, |
| 637 | htons(ETH_P_8021Q), |
| 638 | ntohs(vhdr->h_vlan_TCI)); |
| 639 | proto = vhdr->h_vlan_encapsulated_proto; |
| 640 | skb->protocol = (ntohs(proto) >= 1536) ? proto : |
| 641 | htons(ETH_P_802_2); |
| 642 | |
| 643 | /* squash it by moving the ethernet addresses up 4 bytes */ |
| 644 | memmove(skb->data + VLAN_HLEN, skb->data, 12); |
| 645 | __skb_pull(skb, VLAN_HLEN); |
| 646 | skb_reset_mac_header(skb); |
| 647 | } |
| 648 | |
| 649 | /* The minimum packet size for a single buffer is 17B so pad the skb |
| 650 | * in order to meet this minimum size requirement. |
| 651 | */ |
| 652 | if (unlikely(skb->len < 17)) { |
| 653 | int pad_len = 17 - skb->len; |
| 654 | |
| 655 | if (skb_pad(skb, pad_len)) |
| 656 | return NETDEV_TX_OK; |
| 657 | __skb_put(skb, pad_len); |
| 658 | } |
| 659 | |
| 660 | if (r_idx >= interface->num_tx_queues) |
| 661 | r_idx %= interface->num_tx_queues; |
| 662 | |
| 663 | err = fm10k_xmit_frame_ring(skb, interface->tx_ring[r_idx]); |
| 664 | |
| 665 | return err; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int fm10k_change_mtu(struct net_device *dev, int new_mtu) |
| 669 | { |
| 670 | if (new_mtu < 68 || new_mtu > FM10K_MAX_JUMBO_FRAME_SIZE) |
| 671 | return -EINVAL; |
| 672 | |
| 673 | dev->mtu = new_mtu; |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 678 | /** |
| 679 | * fm10k_tx_timeout - Respond to a Tx Hang |
| 680 | * @netdev: network interface device structure |
| 681 | **/ |
| 682 | static void fm10k_tx_timeout(struct net_device *netdev) |
| 683 | { |
| 684 | struct fm10k_intfc *interface = netdev_priv(netdev); |
| 685 | bool real_tx_hang = false; |
| 686 | int i; |
| 687 | |
| 688 | #define TX_TIMEO_LIMIT 16000 |
| 689 | for (i = 0; i < interface->num_tx_queues; i++) { |
| 690 | struct fm10k_ring *tx_ring = interface->tx_ring[i]; |
| 691 | |
| 692 | if (check_for_tx_hang(tx_ring) && fm10k_check_tx_hang(tx_ring)) |
| 693 | real_tx_hang = true; |
| 694 | } |
| 695 | |
| 696 | if (real_tx_hang) { |
| 697 | fm10k_tx_timeout_reset(interface); |
| 698 | } else { |
| 699 | netif_info(interface, drv, netdev, |
| 700 | "Fake Tx hang detected with timeout of %d seconds\n", |
Bruce Allan | a4fcad6 | 2015-10-28 17:19:40 -0700 | [diff] [blame] | 701 | netdev->watchdog_timeo / HZ); |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 702 | |
| 703 | /* fake Tx hang - increase the kernel timeout */ |
| 704 | if (netdev->watchdog_timeo < TX_TIMEO_LIMIT) |
| 705 | netdev->watchdog_timeo *= 2; |
| 706 | } |
| 707 | } |
| 708 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 709 | static int fm10k_uc_vlan_unsync(struct net_device *netdev, |
| 710 | const unsigned char *uc_addr) |
| 711 | { |
| 712 | struct fm10k_intfc *interface = netdev_priv(netdev); |
| 713 | struct fm10k_hw *hw = &interface->hw; |
| 714 | u16 glort = interface->glort; |
| 715 | u16 vid = interface->vid; |
| 716 | bool set = !!(vid / VLAN_N_VID); |
| 717 | int err; |
| 718 | |
| 719 | /* drop any leading bits on the VLAN ID */ |
| 720 | vid &= VLAN_N_VID - 1; |
| 721 | |
| 722 | err = hw->mac.ops.update_uc_addr(hw, glort, uc_addr, vid, set, 0); |
| 723 | if (err) |
| 724 | return err; |
| 725 | |
| 726 | /* return non-zero value as we are only doing a partial sync/unsync */ |
| 727 | return 1; |
| 728 | } |
| 729 | |
| 730 | static int fm10k_mc_vlan_unsync(struct net_device *netdev, |
| 731 | const unsigned char *mc_addr) |
| 732 | { |
| 733 | struct fm10k_intfc *interface = netdev_priv(netdev); |
| 734 | struct fm10k_hw *hw = &interface->hw; |
| 735 | u16 glort = interface->glort; |
| 736 | u16 vid = interface->vid; |
| 737 | bool set = !!(vid / VLAN_N_VID); |
| 738 | int err; |
| 739 | |
| 740 | /* drop any leading bits on the VLAN ID */ |
| 741 | vid &= VLAN_N_VID - 1; |
| 742 | |
| 743 | err = hw->mac.ops.update_mc_addr(hw, glort, mc_addr, vid, set); |
| 744 | if (err) |
| 745 | return err; |
| 746 | |
| 747 | /* return non-zero value as we are only doing a partial sync/unsync */ |
| 748 | return 1; |
| 749 | } |
| 750 | |
| 751 | static int fm10k_update_vid(struct net_device *netdev, u16 vid, bool set) |
| 752 | { |
| 753 | struct fm10k_intfc *interface = netdev_priv(netdev); |
| 754 | struct fm10k_hw *hw = &interface->hw; |
| 755 | s32 err; |
Jacob Keller | e71c931 | 2015-06-24 13:34:46 -0700 | [diff] [blame] | 756 | int i; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 757 | |
| 758 | /* updates do not apply to VLAN 0 */ |
| 759 | if (!vid) |
| 760 | return 0; |
| 761 | |
| 762 | if (vid >= VLAN_N_VID) |
| 763 | return -EINVAL; |
| 764 | |
| 765 | /* Verify we have permission to add VLANs */ |
| 766 | if (hw->mac.vlan_override) |
| 767 | return -EACCES; |
| 768 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 769 | /* update active_vlans bitmask */ |
| 770 | set_bit(vid, interface->active_vlans); |
| 771 | if (!set) |
| 772 | clear_bit(vid, interface->active_vlans); |
| 773 | |
Jacob Keller | aa502b4 | 2015-11-02 12:10:22 -0800 | [diff] [blame] | 774 | /* disable the default VLAN ID on ring if we have an active VLAN */ |
Jacob Keller | e71c931 | 2015-06-24 13:34:46 -0700 | [diff] [blame] | 775 | for (i = 0; i < interface->num_rx_queues; i++) { |
| 776 | struct fm10k_ring *rx_ring = interface->rx_ring[i]; |
| 777 | u16 rx_vid = rx_ring->vid & (VLAN_N_VID - 1); |
| 778 | |
| 779 | if (test_bit(rx_vid, interface->active_vlans)) |
| 780 | rx_ring->vid |= FM10K_VLAN_CLEAR; |
| 781 | else |
| 782 | rx_ring->vid &= ~FM10K_VLAN_CLEAR; |
| 783 | } |
| 784 | |
Bruce Allan | 3d02b3d | 2015-10-28 17:19:56 -0700 | [diff] [blame] | 785 | /* Do not remove default VLAN ID related entries from VLAN and MAC |
| 786 | * tables |
| 787 | */ |
Jacob Keller | 56f0569 | 2015-06-15 15:00:53 -0700 | [diff] [blame] | 788 | if (!set && vid == hw->mac.default_vid) |
Jeff Kirsher | 661b206 | 2015-04-10 16:48:19 -0700 | [diff] [blame] | 789 | return 0; |
| 790 | |
Jacob Keller | 3f0bdb2 | 2015-06-19 10:56:09 -0700 | [diff] [blame] | 791 | /* Do not throw an error if the interface is down. We will sync once |
| 792 | * we come up |
| 793 | */ |
| 794 | if (test_bit(__FM10K_DOWN, &interface->state)) |
| 795 | return 0; |
| 796 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 797 | fm10k_mbx_lock(interface); |
| 798 | |
Matthew Vick | eca3204 | 2015-01-31 02:23:05 +0000 | [diff] [blame] | 799 | /* only need to update the VLAN if not in promiscuous mode */ |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 800 | if (!(netdev->flags & IFF_PROMISC)) { |
| 801 | err = hw->mac.ops.update_vlan(hw, vid, 0, set); |
| 802 | if (err) |
Matthew Vick | 13cb2da | 2014-10-03 00:43:35 +0000 | [diff] [blame] | 803 | goto err_out; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /* update our base MAC address */ |
| 807 | err = hw->mac.ops.update_uc_addr(hw, interface->glort, hw->mac.addr, |
| 808 | vid, set, 0); |
| 809 | if (err) |
Matthew Vick | 13cb2da | 2014-10-03 00:43:35 +0000 | [diff] [blame] | 810 | goto err_out; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 811 | |
Jacob Keller | aa502b4 | 2015-11-02 12:10:22 -0800 | [diff] [blame] | 812 | /* set VLAN ID prior to syncing/unsyncing the VLAN */ |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 813 | interface->vid = vid + (set ? VLAN_N_VID : 0); |
| 814 | |
| 815 | /* Update the unicast and multicast address list to add/drop VLAN */ |
| 816 | __dev_uc_unsync(netdev, fm10k_uc_vlan_unsync); |
| 817 | __dev_mc_unsync(netdev, fm10k_mc_vlan_unsync); |
| 818 | |
Matthew Vick | 13cb2da | 2014-10-03 00:43:35 +0000 | [diff] [blame] | 819 | err_out: |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 820 | fm10k_mbx_unlock(interface); |
| 821 | |
Matthew Vick | 13cb2da | 2014-10-03 00:43:35 +0000 | [diff] [blame] | 822 | return err; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | static int fm10k_vlan_rx_add_vid(struct net_device *netdev, |
| 826 | __always_unused __be16 proto, u16 vid) |
| 827 | { |
| 828 | /* update VLAN and address table based on changes */ |
| 829 | return fm10k_update_vid(netdev, vid, true); |
| 830 | } |
| 831 | |
| 832 | static int fm10k_vlan_rx_kill_vid(struct net_device *netdev, |
| 833 | __always_unused __be16 proto, u16 vid) |
| 834 | { |
| 835 | /* update VLAN and address table based on changes */ |
| 836 | return fm10k_update_vid(netdev, vid, false); |
| 837 | } |
| 838 | |
| 839 | static u16 fm10k_find_next_vlan(struct fm10k_intfc *interface, u16 vid) |
| 840 | { |
| 841 | struct fm10k_hw *hw = &interface->hw; |
| 842 | u16 default_vid = hw->mac.default_vid; |
| 843 | u16 vid_limit = vid < default_vid ? default_vid : VLAN_N_VID; |
| 844 | |
| 845 | vid = find_next_bit(interface->active_vlans, vid_limit, ++vid); |
| 846 | |
| 847 | return vid; |
| 848 | } |
| 849 | |
| 850 | static void fm10k_clear_unused_vlans(struct fm10k_intfc *interface) |
| 851 | { |
| 852 | struct fm10k_hw *hw = &interface->hw; |
| 853 | u32 vid, prev_vid; |
| 854 | |
| 855 | /* loop through and find any gaps in the table */ |
| 856 | for (vid = 0, prev_vid = 0; |
| 857 | prev_vid < VLAN_N_VID; |
| 858 | prev_vid = vid + 1, vid = fm10k_find_next_vlan(interface, vid)) { |
| 859 | if (prev_vid == vid) |
| 860 | continue; |
| 861 | |
| 862 | /* send request to clear multiple bits at a time */ |
| 863 | prev_vid += (vid - prev_vid - 1) << FM10K_VLAN_LENGTH_SHIFT; |
| 864 | hw->mac.ops.update_vlan(hw, prev_vid, 0, false); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | static int __fm10k_uc_sync(struct net_device *dev, |
| 869 | const unsigned char *addr, bool sync) |
| 870 | { |
| 871 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 872 | struct fm10k_hw *hw = &interface->hw; |
| 873 | u16 vid, glort = interface->glort; |
| 874 | s32 err; |
| 875 | |
| 876 | if (!is_valid_ether_addr(addr)) |
| 877 | return -EADDRNOTAVAIL; |
| 878 | |
| 879 | /* update table with current entries */ |
Ngai-Mint Kwan | 8998763 | 2016-04-01 16:17:32 -0700 | [diff] [blame^] | 880 | for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 1; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 881 | vid < VLAN_N_VID; |
| 882 | vid = fm10k_find_next_vlan(interface, vid)) { |
| 883 | err = hw->mac.ops.update_uc_addr(hw, glort, addr, |
| 884 | vid, sync, 0); |
| 885 | if (err) |
| 886 | return err; |
| 887 | } |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static int fm10k_uc_sync(struct net_device *dev, |
| 893 | const unsigned char *addr) |
| 894 | { |
| 895 | return __fm10k_uc_sync(dev, addr, true); |
| 896 | } |
| 897 | |
| 898 | static int fm10k_uc_unsync(struct net_device *dev, |
| 899 | const unsigned char *addr) |
| 900 | { |
| 901 | return __fm10k_uc_sync(dev, addr, false); |
| 902 | } |
| 903 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 904 | static int fm10k_set_mac(struct net_device *dev, void *p) |
| 905 | { |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 906 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 907 | struct fm10k_hw *hw = &interface->hw; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 908 | struct sockaddr *addr = p; |
| 909 | s32 err = 0; |
| 910 | |
| 911 | if (!is_valid_ether_addr(addr->sa_data)) |
| 912 | return -EADDRNOTAVAIL; |
| 913 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 914 | if (dev->flags & IFF_UP) { |
| 915 | /* setting MAC address requires mailbox */ |
| 916 | fm10k_mbx_lock(interface); |
| 917 | |
| 918 | err = fm10k_uc_sync(dev, addr->sa_data); |
| 919 | if (!err) |
| 920 | fm10k_uc_unsync(dev, hw->mac.addr); |
| 921 | |
| 922 | fm10k_mbx_unlock(interface); |
| 923 | } |
| 924 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 925 | if (!err) { |
| 926 | ether_addr_copy(dev->dev_addr, addr->sa_data); |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 927 | ether_addr_copy(hw->mac.addr, addr->sa_data); |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 928 | dev->addr_assign_type &= ~NET_ADDR_RANDOM; |
| 929 | } |
| 930 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 931 | /* if we had a mailbox error suggest trying again */ |
| 932 | return err ? -EAGAIN : 0; |
| 933 | } |
| 934 | |
| 935 | static int __fm10k_mc_sync(struct net_device *dev, |
| 936 | const unsigned char *addr, bool sync) |
| 937 | { |
| 938 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 939 | struct fm10k_hw *hw = &interface->hw; |
| 940 | u16 vid, glort = interface->glort; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 941 | |
| 942 | /* update table with current entries */ |
Ngai-Mint Kwan | 8998763 | 2016-04-01 16:17:32 -0700 | [diff] [blame^] | 943 | for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 1; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 944 | vid < VLAN_N_VID; |
| 945 | vid = fm10k_find_next_vlan(interface, vid)) { |
Jacob Keller | 745136a | 2015-06-03 16:30:58 -0700 | [diff] [blame] | 946 | hw->mac.ops.update_mc_addr(hw, glort, addr, vid, sync); |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static int fm10k_mc_sync(struct net_device *dev, |
| 953 | const unsigned char *addr) |
| 954 | { |
| 955 | return __fm10k_mc_sync(dev, addr, true); |
| 956 | } |
| 957 | |
| 958 | static int fm10k_mc_unsync(struct net_device *dev, |
| 959 | const unsigned char *addr) |
| 960 | { |
| 961 | return __fm10k_mc_sync(dev, addr, false); |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | static void fm10k_set_rx_mode(struct net_device *dev) |
| 965 | { |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 966 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 967 | struct fm10k_hw *hw = &interface->hw; |
| 968 | int xcast_mode; |
| 969 | |
| 970 | /* no need to update the harwdare if we are not running */ |
| 971 | if (!(dev->flags & IFF_UP)) |
| 972 | return; |
| 973 | |
| 974 | /* determine new mode based on flags */ |
| 975 | xcast_mode = (dev->flags & IFF_PROMISC) ? FM10K_XCAST_MODE_PROMISC : |
| 976 | (dev->flags & IFF_ALLMULTI) ? FM10K_XCAST_MODE_ALLMULTI : |
| 977 | (dev->flags & (IFF_BROADCAST | IFF_MULTICAST)) ? |
| 978 | FM10K_XCAST_MODE_MULTI : FM10K_XCAST_MODE_NONE; |
| 979 | |
| 980 | fm10k_mbx_lock(interface); |
| 981 | |
Jeff Kirsher | a7731cc | 2015-04-03 13:27:11 -0700 | [diff] [blame] | 982 | /* update xcast mode first, but only if it changed */ |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 983 | if (interface->xcast_mode != xcast_mode) { |
| 984 | /* update VLAN table */ |
| 985 | if (xcast_mode == FM10K_XCAST_MODE_PROMISC) |
| 986 | hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, 0, true); |
| 987 | if (interface->xcast_mode == FM10K_XCAST_MODE_PROMISC) |
| 988 | fm10k_clear_unused_vlans(interface); |
| 989 | |
| 990 | /* update xcast mode */ |
| 991 | hw->mac.ops.update_xcast_mode(hw, interface->glort, xcast_mode); |
| 992 | |
| 993 | /* record updated xcast mode state */ |
| 994 | interface->xcast_mode = xcast_mode; |
| 995 | } |
| 996 | |
Jeff Kirsher | a7731cc | 2015-04-03 13:27:11 -0700 | [diff] [blame] | 997 | /* synchronize all of the addresses */ |
Ngai-Mint Kwan | 8998763 | 2016-04-01 16:17:32 -0700 | [diff] [blame^] | 998 | __dev_uc_sync(dev, fm10k_uc_sync, fm10k_uc_unsync); |
| 999 | __dev_mc_sync(dev, fm10k_mc_sync, fm10k_mc_unsync); |
Jeff Kirsher | a7731cc | 2015-04-03 13:27:11 -0700 | [diff] [blame] | 1000 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1001 | fm10k_mbx_unlock(interface); |
| 1002 | } |
| 1003 | |
| 1004 | void fm10k_restore_rx_state(struct fm10k_intfc *interface) |
| 1005 | { |
| 1006 | struct net_device *netdev = interface->netdev; |
| 1007 | struct fm10k_hw *hw = &interface->hw; |
| 1008 | int xcast_mode; |
| 1009 | u16 vid, glort; |
| 1010 | |
| 1011 | /* record glort for this interface */ |
| 1012 | glort = interface->glort; |
| 1013 | |
| 1014 | /* convert interface flags to xcast mode */ |
| 1015 | if (netdev->flags & IFF_PROMISC) |
| 1016 | xcast_mode = FM10K_XCAST_MODE_PROMISC; |
| 1017 | else if (netdev->flags & IFF_ALLMULTI) |
| 1018 | xcast_mode = FM10K_XCAST_MODE_ALLMULTI; |
| 1019 | else if (netdev->flags & (IFF_BROADCAST | IFF_MULTICAST)) |
| 1020 | xcast_mode = FM10K_XCAST_MODE_MULTI; |
| 1021 | else |
| 1022 | xcast_mode = FM10K_XCAST_MODE_NONE; |
| 1023 | |
| 1024 | fm10k_mbx_lock(interface); |
| 1025 | |
| 1026 | /* Enable logical port */ |
| 1027 | hw->mac.ops.update_lport_state(hw, glort, interface->glort_count, true); |
| 1028 | |
| 1029 | /* update VLAN table */ |
| 1030 | hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, 0, |
| 1031 | xcast_mode == FM10K_XCAST_MODE_PROMISC); |
| 1032 | |
| 1033 | /* Add filter for VLAN 0 */ |
| 1034 | hw->mac.ops.update_vlan(hw, 0, 0, true); |
| 1035 | |
| 1036 | /* update table with current entries */ |
Ngai-Mint Kwan | 8998763 | 2016-04-01 16:17:32 -0700 | [diff] [blame^] | 1037 | for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 1; |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1038 | vid < VLAN_N_VID; |
| 1039 | vid = fm10k_find_next_vlan(interface, vid)) { |
| 1040 | hw->mac.ops.update_vlan(hw, vid, 0, true); |
| 1041 | hw->mac.ops.update_uc_addr(hw, glort, hw->mac.addr, |
| 1042 | vid, true, 0); |
| 1043 | } |
| 1044 | |
Jacob Keller | 5c2d642 | 2015-06-24 13:34:47 -0700 | [diff] [blame] | 1045 | /* update xcast mode before synchronizing addresses */ |
Jeff Kirsher | a7731cc | 2015-04-03 13:27:11 -0700 | [diff] [blame] | 1046 | hw->mac.ops.update_xcast_mode(hw, glort, xcast_mode); |
| 1047 | |
Matthew Vick | eca3204 | 2015-01-31 02:23:05 +0000 | [diff] [blame] | 1048 | /* synchronize all of the addresses */ |
Ngai-Mint Kwan | 8998763 | 2016-04-01 16:17:32 -0700 | [diff] [blame^] | 1049 | __dev_uc_sync(netdev, fm10k_uc_sync, fm10k_uc_unsync); |
| 1050 | __dev_mc_sync(netdev, fm10k_mc_sync, fm10k_mc_unsync); |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1051 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1052 | fm10k_mbx_unlock(interface); |
| 1053 | |
| 1054 | /* record updated xcast mode state */ |
| 1055 | interface->xcast_mode = xcast_mode; |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 1056 | |
| 1057 | /* Restore tunnel configuration */ |
| 1058 | fm10k_restore_vxlan_port(interface); |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | void fm10k_reset_rx_state(struct fm10k_intfc *interface) |
| 1062 | { |
| 1063 | struct net_device *netdev = interface->netdev; |
| 1064 | struct fm10k_hw *hw = &interface->hw; |
| 1065 | |
| 1066 | fm10k_mbx_lock(interface); |
| 1067 | |
| 1068 | /* clear the logical port state on lower device */ |
| 1069 | hw->mac.ops.update_lport_state(hw, interface->glort, |
| 1070 | interface->glort_count, false); |
| 1071 | |
| 1072 | fm10k_mbx_unlock(interface); |
| 1073 | |
| 1074 | /* reset flags to default state */ |
| 1075 | interface->xcast_mode = FM10K_XCAST_MODE_NONE; |
| 1076 | |
| 1077 | /* clear the sync flag since the lport has been dropped */ |
| 1078 | __dev_uc_unsync(netdev, NULL); |
| 1079 | __dev_mc_unsync(netdev, NULL); |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 1082 | /** |
| 1083 | * fm10k_get_stats64 - Get System Network Statistics |
| 1084 | * @netdev: network interface device structure |
| 1085 | * @stats: storage space for 64bit statistics |
| 1086 | * |
| 1087 | * Returns 64bit statistics, for use in the ndo_get_stats64 callback. This |
| 1088 | * function replaces fm10k_get_stats for kernels which support it. |
| 1089 | */ |
| 1090 | static struct rtnl_link_stats64 *fm10k_get_stats64(struct net_device *netdev, |
| 1091 | struct rtnl_link_stats64 *stats) |
| 1092 | { |
| 1093 | struct fm10k_intfc *interface = netdev_priv(netdev); |
| 1094 | struct fm10k_ring *ring; |
| 1095 | unsigned int start, i; |
| 1096 | u64 bytes, packets; |
| 1097 | |
| 1098 | rcu_read_lock(); |
| 1099 | |
| 1100 | for (i = 0; i < interface->num_rx_queues; i++) { |
| 1101 | ring = ACCESS_ONCE(interface->rx_ring[i]); |
| 1102 | |
| 1103 | if (!ring) |
| 1104 | continue; |
| 1105 | |
| 1106 | do { |
| 1107 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
| 1108 | packets = ring->stats.packets; |
| 1109 | bytes = ring->stats.bytes; |
| 1110 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
| 1111 | |
| 1112 | stats->rx_packets += packets; |
| 1113 | stats->rx_bytes += bytes; |
| 1114 | } |
| 1115 | |
| 1116 | for (i = 0; i < interface->num_tx_queues; i++) { |
Jeff Kirsher | f4e25f6 | 2015-04-03 13:26:51 -0700 | [diff] [blame] | 1117 | ring = ACCESS_ONCE(interface->tx_ring[i]); |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 1118 | |
| 1119 | if (!ring) |
| 1120 | continue; |
| 1121 | |
| 1122 | do { |
| 1123 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
| 1124 | packets = ring->stats.packets; |
| 1125 | bytes = ring->stats.bytes; |
| 1126 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
| 1127 | |
| 1128 | stats->tx_packets += packets; |
| 1129 | stats->tx_bytes += bytes; |
| 1130 | } |
| 1131 | |
| 1132 | rcu_read_unlock(); |
| 1133 | |
| 1134 | /* following stats updated by fm10k_service_task() */ |
| 1135 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 1136 | |
| 1137 | return stats; |
| 1138 | } |
| 1139 | |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 1140 | int fm10k_setup_tc(struct net_device *dev, u8 tc) |
| 1141 | { |
| 1142 | struct fm10k_intfc *interface = netdev_priv(dev); |
Alexander Duyck | 09f8a82 | 2015-11-10 09:40:30 -0800 | [diff] [blame] | 1143 | int err; |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 1144 | |
| 1145 | /* Currently only the PF supports priority classes */ |
| 1146 | if (tc && (interface->hw.mac.type != fm10k_mac_pf)) |
| 1147 | return -EINVAL; |
| 1148 | |
| 1149 | /* Hardware supports up to 8 traffic classes */ |
| 1150 | if (tc > 8) |
| 1151 | return -EINVAL; |
| 1152 | |
| 1153 | /* Hardware has to reinitialize queues to match packet |
| 1154 | * buffer alignment. Unfortunately, the hardware is not |
| 1155 | * flexible enough to do this dynamically. |
| 1156 | */ |
| 1157 | if (netif_running(dev)) |
| 1158 | fm10k_close(dev); |
| 1159 | |
| 1160 | fm10k_mbx_free_irq(interface); |
| 1161 | |
| 1162 | fm10k_clear_queueing_scheme(interface); |
| 1163 | |
| 1164 | /* we expect the prio_tc map to be repopulated later */ |
| 1165 | netdev_reset_tc(dev); |
| 1166 | netdev_set_num_tc(dev, tc); |
| 1167 | |
Alexander Duyck | 09f8a82 | 2015-11-10 09:40:30 -0800 | [diff] [blame] | 1168 | err = fm10k_init_queueing_scheme(interface); |
| 1169 | if (err) |
| 1170 | goto err_queueing_scheme; |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 1171 | |
Alexander Duyck | 09f8a82 | 2015-11-10 09:40:30 -0800 | [diff] [blame] | 1172 | err = fm10k_mbx_request_irq(interface); |
| 1173 | if (err) |
| 1174 | goto err_mbx_irq; |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 1175 | |
Alexander Duyck | 09f8a82 | 2015-11-10 09:40:30 -0800 | [diff] [blame] | 1176 | err = netif_running(dev) ? fm10k_open(dev) : 0; |
| 1177 | if (err) |
| 1178 | goto err_open; |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 1179 | |
| 1180 | /* flag to indicate SWPRI has yet to be updated */ |
| 1181 | interface->flags |= FM10K_FLAG_SWPRI_CONFIG; |
| 1182 | |
| 1183 | return 0; |
Alexander Duyck | 09f8a82 | 2015-11-10 09:40:30 -0800 | [diff] [blame] | 1184 | err_open: |
| 1185 | fm10k_mbx_free_irq(interface); |
| 1186 | err_mbx_irq: |
| 1187 | fm10k_clear_queueing_scheme(interface); |
| 1188 | err_queueing_scheme: |
| 1189 | netif_device_detach(dev); |
| 1190 | |
| 1191 | return err; |
Alexander Duyck | aa3ac82 | 2014-09-20 19:50:42 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 1194 | static int __fm10k_setup_tc(struct net_device *dev, u32 handle, __be16 proto, |
| 1195 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 1196 | { |
John Fastabend | 5eb4dce | 2016-02-29 11:26:13 -0800 | [diff] [blame] | 1197 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 1198 | return -EINVAL; |
| 1199 | |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 1200 | return fm10k_setup_tc(dev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 1203 | static void fm10k_assign_l2_accel(struct fm10k_intfc *interface, |
| 1204 | struct fm10k_l2_accel *l2_accel) |
| 1205 | { |
| 1206 | struct fm10k_ring *ring; |
| 1207 | int i; |
| 1208 | |
| 1209 | for (i = 0; i < interface->num_rx_queues; i++) { |
| 1210 | ring = interface->rx_ring[i]; |
| 1211 | rcu_assign_pointer(ring->l2_accel, l2_accel); |
| 1212 | } |
| 1213 | |
| 1214 | interface->l2_accel = l2_accel; |
| 1215 | } |
| 1216 | |
| 1217 | static void *fm10k_dfwd_add_station(struct net_device *dev, |
| 1218 | struct net_device *sdev) |
| 1219 | { |
| 1220 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 1221 | struct fm10k_l2_accel *l2_accel = interface->l2_accel; |
| 1222 | struct fm10k_l2_accel *old_l2_accel = NULL; |
| 1223 | struct fm10k_dglort_cfg dglort = { 0 }; |
| 1224 | struct fm10k_hw *hw = &interface->hw; |
| 1225 | int size = 0, i; |
| 1226 | u16 glort; |
| 1227 | |
| 1228 | /* allocate l2 accel structure if it is not available */ |
| 1229 | if (!l2_accel) { |
| 1230 | /* verify there is enough free GLORTs to support l2_accel */ |
| 1231 | if (interface->glort_count < 7) |
| 1232 | return ERR_PTR(-EBUSY); |
| 1233 | |
| 1234 | size = offsetof(struct fm10k_l2_accel, macvlan[7]); |
| 1235 | l2_accel = kzalloc(size, GFP_KERNEL); |
| 1236 | if (!l2_accel) |
| 1237 | return ERR_PTR(-ENOMEM); |
| 1238 | |
| 1239 | l2_accel->size = 7; |
| 1240 | l2_accel->dglort = interface->glort; |
| 1241 | |
| 1242 | /* update pointers */ |
| 1243 | fm10k_assign_l2_accel(interface, l2_accel); |
| 1244 | /* do not expand if we are at our limit */ |
| 1245 | } else if ((l2_accel->count == FM10K_MAX_STATIONS) || |
| 1246 | (l2_accel->count == (interface->glort_count - 1))) { |
| 1247 | return ERR_PTR(-EBUSY); |
| 1248 | /* expand if we have hit the size limit */ |
| 1249 | } else if (l2_accel->count == l2_accel->size) { |
| 1250 | old_l2_accel = l2_accel; |
| 1251 | size = offsetof(struct fm10k_l2_accel, |
| 1252 | macvlan[(l2_accel->size * 2) + 1]); |
| 1253 | l2_accel = kzalloc(size, GFP_KERNEL); |
| 1254 | if (!l2_accel) |
| 1255 | return ERR_PTR(-ENOMEM); |
| 1256 | |
| 1257 | memcpy(l2_accel, old_l2_accel, |
| 1258 | offsetof(struct fm10k_l2_accel, |
| 1259 | macvlan[old_l2_accel->size])); |
| 1260 | |
| 1261 | l2_accel->size = (old_l2_accel->size * 2) + 1; |
| 1262 | |
| 1263 | /* update pointers */ |
| 1264 | fm10k_assign_l2_accel(interface, l2_accel); |
| 1265 | kfree_rcu(old_l2_accel, rcu); |
| 1266 | } |
| 1267 | |
| 1268 | /* add macvlan to accel table, and record GLORT for position */ |
| 1269 | for (i = 0; i < l2_accel->size; i++) { |
| 1270 | if (!l2_accel->macvlan[i]) |
| 1271 | break; |
| 1272 | } |
| 1273 | |
| 1274 | /* record station */ |
| 1275 | l2_accel->macvlan[i] = sdev; |
| 1276 | l2_accel->count++; |
| 1277 | |
| 1278 | /* configure default DGLORT mapping for RSS/DCB */ |
| 1279 | dglort.idx = fm10k_dglort_pf_rss; |
| 1280 | dglort.inner_rss = 1; |
| 1281 | dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask); |
| 1282 | dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask); |
| 1283 | dglort.glort = interface->glort; |
| 1284 | dglort.shared_l = fls(l2_accel->size); |
| 1285 | hw->mac.ops.configure_dglort_map(hw, &dglort); |
| 1286 | |
| 1287 | /* Add rules for this specific dglort to the switch */ |
| 1288 | fm10k_mbx_lock(interface); |
| 1289 | |
| 1290 | glort = l2_accel->dglort + 1 + i; |
| 1291 | hw->mac.ops.update_xcast_mode(hw, glort, FM10K_XCAST_MODE_MULTI); |
| 1292 | hw->mac.ops.update_uc_addr(hw, glort, sdev->dev_addr, 0, true, 0); |
| 1293 | |
| 1294 | fm10k_mbx_unlock(interface); |
| 1295 | |
| 1296 | return sdev; |
| 1297 | } |
| 1298 | |
| 1299 | static void fm10k_dfwd_del_station(struct net_device *dev, void *priv) |
| 1300 | { |
| 1301 | struct fm10k_intfc *interface = netdev_priv(dev); |
| 1302 | struct fm10k_l2_accel *l2_accel = ACCESS_ONCE(interface->l2_accel); |
| 1303 | struct fm10k_dglort_cfg dglort = { 0 }; |
| 1304 | struct fm10k_hw *hw = &interface->hw; |
| 1305 | struct net_device *sdev = priv; |
| 1306 | int i; |
| 1307 | u16 glort; |
| 1308 | |
| 1309 | if (!l2_accel) |
| 1310 | return; |
| 1311 | |
| 1312 | /* search table for matching interface */ |
| 1313 | for (i = 0; i < l2_accel->size; i++) { |
| 1314 | if (l2_accel->macvlan[i] == sdev) |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | /* exit if macvlan not found */ |
| 1319 | if (i == l2_accel->size) |
| 1320 | return; |
| 1321 | |
| 1322 | /* Remove any rules specific to this dglort */ |
| 1323 | fm10k_mbx_lock(interface); |
| 1324 | |
| 1325 | glort = l2_accel->dglort + 1 + i; |
| 1326 | hw->mac.ops.update_xcast_mode(hw, glort, FM10K_XCAST_MODE_NONE); |
| 1327 | hw->mac.ops.update_uc_addr(hw, glort, sdev->dev_addr, 0, false, 0); |
| 1328 | |
| 1329 | fm10k_mbx_unlock(interface); |
| 1330 | |
| 1331 | /* record removal */ |
| 1332 | l2_accel->macvlan[i] = NULL; |
| 1333 | l2_accel->count--; |
| 1334 | |
| 1335 | /* configure default DGLORT mapping for RSS/DCB */ |
| 1336 | dglort.idx = fm10k_dglort_pf_rss; |
| 1337 | dglort.inner_rss = 1; |
| 1338 | dglort.rss_l = fls(interface->ring_feature[RING_F_RSS].mask); |
| 1339 | dglort.pc_l = fls(interface->ring_feature[RING_F_QOS].mask); |
| 1340 | dglort.glort = interface->glort; |
Jacob Keller | f1f3322 | 2015-06-03 16:31:04 -0700 | [diff] [blame] | 1341 | dglort.shared_l = fls(l2_accel->size); |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 1342 | hw->mac.ops.configure_dglort_map(hw, &dglort); |
| 1343 | |
| 1344 | /* If table is empty remove it */ |
| 1345 | if (l2_accel->count == 0) { |
| 1346 | fm10k_assign_l2_accel(interface, NULL); |
| 1347 | kfree_rcu(l2_accel, rcu); |
| 1348 | } |
| 1349 | } |
| 1350 | |
Matthew Vick | 5bf33dc | 2015-01-29 07:17:27 +0000 | [diff] [blame] | 1351 | static netdev_features_t fm10k_features_check(struct sk_buff *skb, |
| 1352 | struct net_device *dev, |
| 1353 | netdev_features_t features) |
| 1354 | { |
| 1355 | if (!skb->encapsulation || fm10k_tx_encap_offload(skb)) |
| 1356 | return features; |
| 1357 | |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 1358 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Matthew Vick | 5bf33dc | 2015-01-29 07:17:27 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1361 | static const struct net_device_ops fm10k_netdev_ops = { |
Alexander Duyck | 504c5ea | 2014-09-20 19:48:29 -0400 | [diff] [blame] | 1362 | .ndo_open = fm10k_open, |
| 1363 | .ndo_stop = fm10k_close, |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1364 | .ndo_validate_addr = eth_validate_addr, |
| 1365 | .ndo_start_xmit = fm10k_xmit_frame, |
| 1366 | .ndo_set_mac_address = fm10k_set_mac, |
| 1367 | .ndo_change_mtu = fm10k_change_mtu, |
Alexander Duyck | b101c96 | 2014-09-20 19:50:03 -0400 | [diff] [blame] | 1368 | .ndo_tx_timeout = fm10k_tx_timeout, |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1369 | .ndo_vlan_rx_add_vid = fm10k_vlan_rx_add_vid, |
| 1370 | .ndo_vlan_rx_kill_vid = fm10k_vlan_rx_kill_vid, |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1371 | .ndo_set_rx_mode = fm10k_set_rx_mode, |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 1372 | .ndo_get_stats64 = fm10k_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 1373 | .ndo_setup_tc = __fm10k_setup_tc, |
Alexander Duyck | 883a9cc | 2014-09-20 19:52:09 -0400 | [diff] [blame] | 1374 | .ndo_set_vf_mac = fm10k_ndo_set_vf_mac, |
| 1375 | .ndo_set_vf_vlan = fm10k_ndo_set_vf_vlan, |
| 1376 | .ndo_set_vf_rate = fm10k_ndo_set_vf_bw, |
| 1377 | .ndo_get_vf_config = fm10k_ndo_get_vf_config, |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 1378 | .ndo_add_vxlan_port = fm10k_add_vxlan_port, |
| 1379 | .ndo_del_vxlan_port = fm10k_del_vxlan_port, |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 1380 | .ndo_dfwd_add_station = fm10k_dfwd_add_station, |
| 1381 | .ndo_dfwd_del_station = fm10k_dfwd_del_station, |
Jeff Kirsher | 8b4a98c | 2015-04-10 19:14:31 -0700 | [diff] [blame] | 1382 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1383 | .ndo_poll_controller = fm10k_netpoll, |
| 1384 | #endif |
Matthew Vick | 5bf33dc | 2015-01-29 07:17:27 +0000 | [diff] [blame] | 1385 | .ndo_features_check = fm10k_features_check, |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1386 | }; |
| 1387 | |
| 1388 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 1389 | |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 1390 | struct net_device *fm10k_alloc_netdev(const struct fm10k_info *info) |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1391 | { |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 1392 | netdev_features_t hw_features; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1393 | struct fm10k_intfc *interface; |
| 1394 | struct net_device *dev; |
| 1395 | |
Alexander Duyck | e27ef59 | 2014-09-20 19:49:03 -0400 | [diff] [blame] | 1396 | dev = alloc_etherdev_mq(sizeof(struct fm10k_intfc), MAX_QUEUES); |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1397 | if (!dev) |
| 1398 | return NULL; |
| 1399 | |
| 1400 | /* set net device and ethtool ops */ |
| 1401 | dev->netdev_ops = &fm10k_netdev_ops; |
Alexander Duyck | 82dd0f7 | 2014-09-20 19:50:15 -0400 | [diff] [blame] | 1402 | fm10k_set_ethtool_ops(dev); |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1403 | |
| 1404 | /* configure default debug level */ |
| 1405 | interface = netdev_priv(dev); |
Bruce Allan | fcdb0a9 | 2015-12-22 13:43:49 -0800 | [diff] [blame] | 1406 | interface->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1407 | |
| 1408 | /* configure default features */ |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 1409 | dev->features |= NETIF_F_IP_CSUM | |
| 1410 | NETIF_F_IPV6_CSUM | |
| 1411 | NETIF_F_SG | |
| 1412 | NETIF_F_TSO | |
| 1413 | NETIF_F_TSO6 | |
| 1414 | NETIF_F_TSO_ECN | |
Alexander Duyck | 76a540d | 2014-09-20 19:51:02 -0400 | [diff] [blame] | 1415 | NETIF_F_RXHASH | |
| 1416 | NETIF_F_RXCSUM; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1417 | |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 1418 | /* Only the PF can support VXLAN and NVGRE tunnel offloads */ |
| 1419 | if (info->mac == fm10k_mac_pf) { |
| 1420 | dev->hw_enc_features = NETIF_F_IP_CSUM | |
| 1421 | NETIF_F_TSO | |
| 1422 | NETIF_F_TSO6 | |
| 1423 | NETIF_F_TSO_ECN | |
| 1424 | NETIF_F_GSO_UDP_TUNNEL | |
| 1425 | NETIF_F_IPV6_CSUM | |
| 1426 | NETIF_F_SG; |
| 1427 | |
| 1428 | dev->features |= NETIF_F_GSO_UDP_TUNNEL; |
| 1429 | } |
| 1430 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1431 | /* all features defined to this point should be changeable */ |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 1432 | hw_features = dev->features; |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1433 | |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 1434 | /* allow user to enable L2 forwarding acceleration */ |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 1435 | hw_features |= NETIF_F_HW_L2FW_DOFFLOAD; |
Alexander Duyck | 5cd5e2e | 2014-09-20 19:51:15 -0400 | [diff] [blame] | 1436 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1437 | /* configure VLAN features */ |
| 1438 | dev->vlan_features |= dev->features; |
| 1439 | |
Alexander Duyck | 8f5e20d | 2014-09-20 19:48:20 -0400 | [diff] [blame] | 1440 | /* we want to leave these both on as we cannot disable VLAN tag |
| 1441 | * insertion or stripping on the hardware since it is contained |
| 1442 | * in the FTAG and not in the frame itself. |
| 1443 | */ |
| 1444 | dev->features |= NETIF_F_HW_VLAN_CTAG_TX | |
| 1445 | NETIF_F_HW_VLAN_CTAG_RX | |
| 1446 | NETIF_F_HW_VLAN_CTAG_FILTER; |
| 1447 | |
| 1448 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 1449 | |
Jacob Keller | e024490 | 2015-10-16 10:56:56 -0700 | [diff] [blame] | 1450 | dev->hw_features |= hw_features; |
| 1451 | |
Alexander Duyck | 0e7b364 | 2014-09-20 19:48:10 -0400 | [diff] [blame] | 1452 | return dev; |
| 1453 | } |