Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007 Mellanox Technologies. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | * |
| 32 | */ |
| 33 | |
Eliezer Tamir | 076bb0c | 2013-07-10 17:13:17 +0300 | [diff] [blame] | 34 | #include <net/busy_poll.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 35 | #include <linux/mlx4/cq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 37 | #include <linux/mlx4/qp.h> |
| 38 | #include <linux/skbuff.h> |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 39 | #include <linux/rculist.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 40 | #include <linux/if_ether.h> |
| 41 | #include <linux/if_vlan.h> |
| 42 | #include <linux/vmalloc.h> |
Amir Vadai | 35f6f45 | 2014-06-29 11:54:55 +0300 | [diff] [blame] | 43 | #include <linux/irq.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 44 | |
| 45 | #include "mlx4_en.h" |
| 46 | |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 47 | static int mlx4_alloc_pages(struct mlx4_en_priv *priv, |
| 48 | struct mlx4_en_rx_alloc *page_alloc, |
| 49 | const struct mlx4_en_frag_info *frag_info, |
| 50 | gfp_t _gfp) |
| 51 | { |
| 52 | int order; |
| 53 | struct page *page; |
| 54 | dma_addr_t dma; |
| 55 | |
| 56 | for (order = MLX4_EN_ALLOC_PREFER_ORDER; ;) { |
| 57 | gfp_t gfp = _gfp; |
| 58 | |
| 59 | if (order) |
| 60 | gfp |= __GFP_COMP | __GFP_NOWARN; |
| 61 | page = alloc_pages(gfp, order); |
| 62 | if (likely(page)) |
| 63 | break; |
| 64 | if (--order < 0 || |
| 65 | ((PAGE_SIZE << order) < frag_info->frag_size)) |
| 66 | return -ENOMEM; |
| 67 | } |
| 68 | dma = dma_map_page(priv->ddev, page, 0, PAGE_SIZE << order, |
| 69 | PCI_DMA_FROMDEVICE); |
| 70 | if (dma_mapping_error(priv->ddev, dma)) { |
| 71 | put_page(page); |
| 72 | return -ENOMEM; |
| 73 | } |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 74 | page_alloc->page_size = PAGE_SIZE << order; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 75 | page_alloc->page = page; |
| 76 | page_alloc->dma = dma; |
Ido Shamay | 5f6e980 | 2014-11-02 16:26:15 +0200 | [diff] [blame] | 77 | page_alloc->page_offset = 0; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 78 | /* Not doing get_page() for each frag is a big win |
Eric Dumazet | 9822620 | 2014-10-10 04:48:17 -0700 | [diff] [blame] | 79 | * on asymetric workloads. Note we can not use atomic_set(). |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 80 | */ |
Eric Dumazet | 9822620 | 2014-10-10 04:48:17 -0700 | [diff] [blame] | 81 | atomic_add(page_alloc->page_size / frag_info->frag_stride - 1, |
| 82 | &page->_count); |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 86 | static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv, |
| 87 | struct mlx4_en_rx_desc *rx_desc, |
| 88 | struct mlx4_en_rx_alloc *frags, |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 89 | struct mlx4_en_rx_alloc *ring_alloc, |
| 90 | gfp_t gfp) |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 91 | { |
| 92 | struct mlx4_en_rx_alloc page_alloc[MLX4_EN_MAX_RX_FRAGS]; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 93 | const struct mlx4_en_frag_info *frag_info; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 94 | struct page *page; |
| 95 | dma_addr_t dma; |
| 96 | int i; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 97 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 98 | for (i = 0; i < priv->num_frags; i++) { |
| 99 | frag_info = &priv->frag_info[i]; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 100 | page_alloc[i] = ring_alloc[i]; |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 101 | page_alloc[i].page_offset += frag_info->frag_stride; |
| 102 | |
| 103 | if (page_alloc[i].page_offset + frag_info->frag_stride <= |
| 104 | ring_alloc[i].page_size) |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 105 | continue; |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 106 | |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 107 | if (mlx4_alloc_pages(priv, &page_alloc[i], frag_info, gfp)) |
| 108 | goto out; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | for (i = 0; i < priv->num_frags; i++) { |
| 112 | frags[i] = ring_alloc[i]; |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 113 | dma = ring_alloc[i].dma + ring_alloc[i].page_offset; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 114 | ring_alloc[i] = page_alloc[i]; |
| 115 | rx_desc->data[i].addr = cpu_to_be64(dma); |
| 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 120 | out: |
| 121 | while (i--) { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 122 | if (page_alloc[i].page != ring_alloc[i].page) { |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 123 | dma_unmap_page(priv->ddev, page_alloc[i].dma, |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 124 | page_alloc[i].page_size, PCI_DMA_FROMDEVICE); |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 125 | page = page_alloc[i].page; |
| 126 | atomic_set(&page->_count, 1); |
| 127 | put_page(page); |
| 128 | } |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 129 | } |
| 130 | return -ENOMEM; |
| 131 | } |
| 132 | |
| 133 | static void mlx4_en_free_frag(struct mlx4_en_priv *priv, |
| 134 | struct mlx4_en_rx_alloc *frags, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 135 | int i) |
| 136 | { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 137 | const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i]; |
Amir Vadai | 021f110 | 2013-10-07 13:38:13 +0200 | [diff] [blame] | 138 | u32 next_frag_end = frags[i].page_offset + 2 * frag_info->frag_stride; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 139 | |
Amir Vadai | 021f110 | 2013-10-07 13:38:13 +0200 | [diff] [blame] | 140 | |
| 141 | if (next_frag_end > frags[i].page_size) |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 142 | dma_unmap_page(priv->ddev, frags[i].dma, frags[i].page_size, |
| 143 | PCI_DMA_FROMDEVICE); |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 144 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 145 | if (frags[i].page) |
| 146 | put_page(frags[i].page); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static int mlx4_en_init_allocator(struct mlx4_en_priv *priv, |
| 150 | struct mlx4_en_rx_ring *ring) |
| 151 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 152 | int i; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 153 | struct mlx4_en_rx_alloc *page_alloc; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 154 | |
| 155 | for (i = 0; i < priv->num_frags; i++) { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 156 | const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 157 | |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 158 | if (mlx4_alloc_pages(priv, &ring->page_alloc[i], |
Ido Shamay | 1ab25f8 | 2014-11-02 16:26:16 +0200 | [diff] [blame] | 159 | frag_info, GFP_KERNEL | __GFP_COLD)) |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 160 | goto out; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 161 | } |
| 162 | return 0; |
| 163 | |
| 164 | out: |
| 165 | while (i--) { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 166 | struct page *page; |
| 167 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 168 | page_alloc = &ring->page_alloc[i]; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 169 | dma_unmap_page(priv->ddev, page_alloc->dma, |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 170 | page_alloc->page_size, PCI_DMA_FROMDEVICE); |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 171 | page = page_alloc->page; |
| 172 | atomic_set(&page->_count, 1); |
| 173 | put_page(page); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 174 | page_alloc->page = NULL; |
| 175 | } |
| 176 | return -ENOMEM; |
| 177 | } |
| 178 | |
| 179 | static void mlx4_en_destroy_allocator(struct mlx4_en_priv *priv, |
| 180 | struct mlx4_en_rx_ring *ring) |
| 181 | { |
| 182 | struct mlx4_en_rx_alloc *page_alloc; |
| 183 | int i; |
| 184 | |
| 185 | for (i = 0; i < priv->num_frags; i++) { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 186 | const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i]; |
| 187 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 188 | page_alloc = &ring->page_alloc[i]; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 189 | en_dbg(DRV, priv, "Freeing allocator:%d count:%d\n", |
| 190 | i, page_count(page_alloc->page)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 191 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 192 | dma_unmap_page(priv->ddev, page_alloc->dma, |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 193 | page_alloc->page_size, PCI_DMA_FROMDEVICE); |
| 194 | while (page_alloc->page_offset + frag_info->frag_stride < |
| 195 | page_alloc->page_size) { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 196 | put_page(page_alloc->page); |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 197 | page_alloc->page_offset += frag_info->frag_stride; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 198 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 199 | page_alloc->page = NULL; |
| 200 | } |
| 201 | } |
| 202 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 203 | static void mlx4_en_init_rx_desc(struct mlx4_en_priv *priv, |
| 204 | struct mlx4_en_rx_ring *ring, int index) |
| 205 | { |
| 206 | struct mlx4_en_rx_desc *rx_desc = ring->buf + ring->stride * index; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 207 | int possible_frags; |
| 208 | int i; |
| 209 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 210 | /* Set size and memtype fields */ |
| 211 | for (i = 0; i < priv->num_frags; i++) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 212 | rx_desc->data[i].byte_count = |
| 213 | cpu_to_be32(priv->frag_info[i].frag_size); |
| 214 | rx_desc->data[i].lkey = cpu_to_be32(priv->mdev->mr.key); |
| 215 | } |
| 216 | |
| 217 | /* If the number of used fragments does not fill up the ring stride, |
| 218 | * remaining (unused) fragments must be padded with null address/size |
| 219 | * and a special memory key */ |
| 220 | possible_frags = (ring->stride - sizeof(struct mlx4_en_rx_desc)) / DS_SIZE; |
| 221 | for (i = priv->num_frags; i < possible_frags; i++) { |
| 222 | rx_desc->data[i].byte_count = 0; |
| 223 | rx_desc->data[i].lkey = cpu_to_be32(MLX4_EN_MEMTYPE_PAD); |
| 224 | rx_desc->data[i].addr = 0; |
| 225 | } |
| 226 | } |
| 227 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 228 | static int mlx4_en_prepare_rx_desc(struct mlx4_en_priv *priv, |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 229 | struct mlx4_en_rx_ring *ring, int index, |
| 230 | gfp_t gfp) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 231 | { |
| 232 | struct mlx4_en_rx_desc *rx_desc = ring->buf + (index * ring->stride); |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 233 | struct mlx4_en_rx_alloc *frags = ring->rx_info + |
| 234 | (index << priv->log_rx_info); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 235 | |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 236 | return mlx4_en_alloc_frags(priv, rx_desc, frags, ring->page_alloc, gfp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static inline void mlx4_en_update_rx_prod_db(struct mlx4_en_rx_ring *ring) |
| 240 | { |
| 241 | *ring->wqres.db.db = cpu_to_be32(ring->prod & 0xffff); |
| 242 | } |
| 243 | |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 244 | static void mlx4_en_free_rx_desc(struct mlx4_en_priv *priv, |
| 245 | struct mlx4_en_rx_ring *ring, |
| 246 | int index) |
| 247 | { |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 248 | struct mlx4_en_rx_alloc *frags; |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 249 | int nr; |
| 250 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 251 | frags = ring->rx_info + (index << priv->log_rx_info); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 252 | for (nr = 0; nr < priv->num_frags; nr++) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 253 | en_dbg(DRV, priv, "Freeing fragment:%d\n", nr); |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 254 | mlx4_en_free_frag(priv, frags, nr); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 258 | static int mlx4_en_fill_rx_buffers(struct mlx4_en_priv *priv) |
| 259 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 260 | struct mlx4_en_rx_ring *ring; |
| 261 | int ring_ind; |
| 262 | int buf_ind; |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 263 | int new_size; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 264 | |
| 265 | for (buf_ind = 0; buf_ind < priv->prof->rx_ring_size; buf_ind++) { |
| 266 | for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 267 | ring = priv->rx_ring[ring_ind]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 268 | |
| 269 | if (mlx4_en_prepare_rx_desc(priv, ring, |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 270 | ring->actual_size, |
Ido Shamay | 1ab25f8 | 2014-11-02 16:26:16 +0200 | [diff] [blame] | 271 | GFP_KERNEL | __GFP_COLD)) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 272 | if (ring->actual_size < MLX4_EN_MIN_RX_SIZE) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 273 | en_err(priv, "Failed to allocate enough rx buffers\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 274 | return -ENOMEM; |
| 275 | } else { |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 276 | new_size = rounddown_pow_of_two(ring->actual_size); |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 277 | en_warn(priv, "Only %d buffers allocated reducing ring size to %d\n", |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 278 | ring->actual_size, new_size); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 279 | goto reduce_rings; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | ring->actual_size++; |
| 283 | ring->prod++; |
| 284 | } |
| 285 | } |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 286 | return 0; |
| 287 | |
| 288 | reduce_rings: |
| 289 | for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 290 | ring = priv->rx_ring[ring_ind]; |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 291 | while (ring->actual_size > new_size) { |
| 292 | ring->actual_size--; |
| 293 | ring->prod--; |
| 294 | mlx4_en_free_rx_desc(priv, ring, ring->actual_size); |
| 295 | } |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 301 | static void mlx4_en_free_rx_buf(struct mlx4_en_priv *priv, |
| 302 | struct mlx4_en_rx_ring *ring) |
| 303 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 304 | int index; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 305 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 306 | en_dbg(DRV, priv, "Freeing Rx buf - cons:%d prod:%d\n", |
| 307 | ring->cons, ring->prod); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 308 | |
| 309 | /* Unmap and free Rx buffers */ |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 310 | BUG_ON((u32) (ring->prod - ring->cons) > ring->actual_size); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 311 | while (ring->cons != ring->prod) { |
| 312 | index = ring->cons & ring->size_mask; |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 313 | en_dbg(DRV, priv, "Processing descriptor:%d\n", index); |
Yevgeny Petrilin | 38aab07 | 2009-05-24 03:17:11 +0000 | [diff] [blame] | 314 | mlx4_en_free_rx_desc(priv, ring, index); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 315 | ++ring->cons; |
| 316 | } |
| 317 | } |
| 318 | |
Ido Shamay | 0251248 | 2014-02-21 12:39:17 +0200 | [diff] [blame] | 319 | void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev) |
| 320 | { |
| 321 | int i; |
| 322 | int num_of_eqs; |
Ido Shamay | bb2146b | 2014-02-21 12:39:18 +0200 | [diff] [blame] | 323 | int num_rx_rings; |
Ido Shamay | 0251248 | 2014-02-21 12:39:17 +0200 | [diff] [blame] | 324 | struct mlx4_dev *dev = mdev->dev; |
| 325 | |
| 326 | mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { |
| 327 | if (!dev->caps.comp_pool) |
| 328 | num_of_eqs = max_t(int, MIN_RX_RINGS, |
| 329 | min_t(int, |
| 330 | dev->caps.num_comp_vectors, |
| 331 | DEF_RX_RINGS)); |
| 332 | else |
| 333 | num_of_eqs = min_t(int, MAX_MSIX_P_PORT, |
| 334 | dev->caps.comp_pool/ |
| 335 | dev->caps.num_ports) - 1; |
| 336 | |
Amir Vadai | ea1c1af | 2014-07-22 15:44:12 +0300 | [diff] [blame] | 337 | num_rx_rings = mlx4_low_memory_profile() ? MIN_RX_RINGS : |
| 338 | min_t(int, num_of_eqs, |
| 339 | netif_get_num_default_rss_queues()); |
Ido Shamay | 0251248 | 2014-02-21 12:39:17 +0200 | [diff] [blame] | 340 | mdev->profile.prof[i].rx_ring_num = |
Ido Shamay | bb2146b | 2014-02-21 12:39:18 +0200 | [diff] [blame] | 341 | rounddown_pow_of_two(num_rx_rings); |
Ido Shamay | 0251248 | 2014-02-21 12:39:17 +0200 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 345 | int mlx4_en_create_rx_ring(struct mlx4_en_priv *priv, |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 346 | struct mlx4_en_rx_ring **pring, |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 347 | u32 size, u16 stride, int node) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 348 | { |
| 349 | struct mlx4_en_dev *mdev = priv->mdev; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 350 | struct mlx4_en_rx_ring *ring; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 351 | int err = -ENOMEM; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 352 | int tmp; |
| 353 | |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 354 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, node); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 355 | if (!ring) { |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 356 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
| 357 | if (!ring) { |
| 358 | en_err(priv, "Failed to allocate RX ring structure\n"); |
| 359 | return -ENOMEM; |
| 360 | } |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 363 | ring->prod = 0; |
| 364 | ring->cons = 0; |
| 365 | ring->size = size; |
| 366 | ring->size_mask = size - 1; |
| 367 | ring->stride = stride; |
| 368 | ring->log_stride = ffs(ring->stride) - 1; |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 369 | ring->buf_size = ring->size * ring->stride + TXBB_SIZE; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 370 | |
| 371 | tmp = size * roundup_pow_of_two(MLX4_EN_MAX_RX_FRAGS * |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 372 | sizeof(struct mlx4_en_rx_alloc)); |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 373 | ring->rx_info = vmalloc_node(tmp, node); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 374 | if (!ring->rx_info) { |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 375 | ring->rx_info = vmalloc(tmp); |
| 376 | if (!ring->rx_info) { |
| 377 | err = -ENOMEM; |
| 378 | goto err_ring; |
| 379 | } |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 380 | } |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 381 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 382 | en_dbg(DRV, priv, "Allocated rx_info ring at addr:%p size:%d\n", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 383 | ring->rx_info, tmp); |
| 384 | |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 385 | /* Allocate HW buffers on provided NUMA node */ |
| 386 | set_dev_node(&mdev->dev->pdev->dev, node); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 387 | err = mlx4_alloc_hwq_res(mdev->dev, &ring->wqres, |
| 388 | ring->buf_size, 2 * PAGE_SIZE); |
Eugenia Emantayev | 163561a | 2013-11-07 12:19:54 +0200 | [diff] [blame] | 389 | set_dev_node(&mdev->dev->pdev->dev, mdev->dev->numa_node); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 390 | if (err) |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 391 | goto err_info; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 392 | |
| 393 | err = mlx4_en_map_buffer(&ring->wqres.buf); |
| 394 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 395 | en_err(priv, "Failed to map RX buffer\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 396 | goto err_hwq; |
| 397 | } |
| 398 | ring->buf = ring->wqres.buf.direct.buf; |
| 399 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 400 | ring->hwtstamp_rx_filter = priv->hwtstamp_config.rx_filter; |
| 401 | |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 402 | *pring = ring; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 403 | return 0; |
| 404 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 405 | err_hwq: |
| 406 | mlx4_free_hwq_res(mdev->dev, &ring->wqres, ring->buf_size); |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 407 | err_info: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 408 | vfree(ring->rx_info); |
| 409 | ring->rx_info = NULL; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 410 | err_ring: |
| 411 | kfree(ring); |
| 412 | *pring = NULL; |
| 413 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 414 | return err; |
| 415 | } |
| 416 | |
| 417 | int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv) |
| 418 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 419 | struct mlx4_en_rx_ring *ring; |
| 420 | int i; |
| 421 | int ring_ind; |
| 422 | int err; |
| 423 | int stride = roundup_pow_of_two(sizeof(struct mlx4_en_rx_desc) + |
| 424 | DS_SIZE * priv->num_frags); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 425 | |
| 426 | for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 427 | ring = priv->rx_ring[ring_ind]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 428 | |
| 429 | ring->prod = 0; |
| 430 | ring->cons = 0; |
| 431 | ring->actual_size = 0; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 432 | ring->cqn = priv->rx_cq[ring_ind]->mcq.cqn; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 433 | |
| 434 | ring->stride = stride; |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 435 | if (ring->stride <= TXBB_SIZE) |
| 436 | ring->buf += TXBB_SIZE; |
| 437 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 438 | ring->log_stride = ffs(ring->stride) - 1; |
| 439 | ring->buf_size = ring->size * ring->stride; |
| 440 | |
| 441 | memset(ring->buf, 0, ring->buf_size); |
| 442 | mlx4_en_update_rx_prod_db(ring); |
| 443 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 444 | /* Initialize all descriptors */ |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 445 | for (i = 0; i < ring->size; i++) |
| 446 | mlx4_en_init_rx_desc(priv, ring, i); |
| 447 | |
| 448 | /* Initialize page allocators */ |
| 449 | err = mlx4_en_init_allocator(priv, ring); |
| 450 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 451 | en_err(priv, "Failed initializing ring allocator\n"); |
Yevgeny Petrilin | 60b1809 | 2011-04-06 23:25:45 +0000 | [diff] [blame] | 452 | if (ring->stride <= TXBB_SIZE) |
| 453 | ring->buf -= TXBB_SIZE; |
Yevgeny Petrilin | 9a4f92a | 2009-04-20 04:24:28 +0000 | [diff] [blame] | 454 | ring_ind--; |
| 455 | goto err_allocator; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 456 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 457 | } |
Ingo Molnar | b58515b | 2008-11-25 16:53:32 -0800 | [diff] [blame] | 458 | err = mlx4_en_fill_rx_buffers(priv); |
| 459 | if (err) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 460 | goto err_buffers; |
| 461 | |
| 462 | for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 463 | ring = priv->rx_ring[ring_ind]; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 464 | |
Yevgeny Petrilin | 00d7d7b | 2010-08-24 03:45:20 +0000 | [diff] [blame] | 465 | ring->size_mask = ring->actual_size - 1; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 466 | mlx4_en_update_rx_prod_db(ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | return 0; |
| 470 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 471 | err_buffers: |
| 472 | for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 473 | mlx4_en_free_rx_buf(priv, priv->rx_ring[ring_ind]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 474 | |
| 475 | ring_ind = priv->rx_ring_num - 1; |
| 476 | err_allocator: |
| 477 | while (ring_ind >= 0) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 478 | if (priv->rx_ring[ring_ind]->stride <= TXBB_SIZE) |
| 479 | priv->rx_ring[ring_ind]->buf -= TXBB_SIZE; |
| 480 | mlx4_en_destroy_allocator(priv, priv->rx_ring[ring_ind]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 481 | ring_ind--; |
| 482 | } |
| 483 | return err; |
| 484 | } |
| 485 | |
| 486 | void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv, |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 487 | struct mlx4_en_rx_ring **pring, |
| 488 | u32 size, u16 stride) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 489 | { |
| 490 | struct mlx4_en_dev *mdev = priv->mdev; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 491 | struct mlx4_en_rx_ring *ring = *pring; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 492 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 493 | mlx4_en_unmap_buffer(&ring->wqres.buf); |
Thadeu Lima de Souza Cascardo | 68355f7 | 2012-02-06 08:39:49 +0000 | [diff] [blame] | 494 | mlx4_free_hwq_res(mdev->dev, &ring->wqres, size * stride + TXBB_SIZE); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 495 | vfree(ring->rx_info); |
| 496 | ring->rx_info = NULL; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 497 | kfree(ring); |
| 498 | *pring = NULL; |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 499 | #ifdef CONFIG_RFS_ACCEL |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 500 | mlx4_en_cleanup_filters(priv); |
Amir Vadai | 1eb8c69 | 2012-07-18 22:33:52 +0000 | [diff] [blame] | 501 | #endif |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | void mlx4_en_deactivate_rx_ring(struct mlx4_en_priv *priv, |
| 505 | struct mlx4_en_rx_ring *ring) |
| 506 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 507 | mlx4_en_free_rx_buf(priv, ring); |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 508 | if (ring->stride <= TXBB_SIZE) |
| 509 | ring->buf -= TXBB_SIZE; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 510 | mlx4_en_destroy_allocator(priv, ring); |
| 511 | } |
| 512 | |
| 513 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 514 | static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv, |
| 515 | struct mlx4_en_rx_desc *rx_desc, |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 516 | struct mlx4_en_rx_alloc *frags, |
Eric Dumazet | 90278c9 | 2011-10-19 18:49:52 +0000 | [diff] [blame] | 517 | struct sk_buff *skb, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 518 | int length) |
| 519 | { |
Eric Dumazet | 90278c9 | 2011-10-19 18:49:52 +0000 | [diff] [blame] | 520 | struct skb_frag_struct *skb_frags_rx = skb_shinfo(skb)->frags; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 521 | struct mlx4_en_frag_info *frag_info; |
| 522 | int nr; |
| 523 | dma_addr_t dma; |
| 524 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 525 | /* Collect used fragments while replacing them in the HW descriptors */ |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 526 | for (nr = 0; nr < priv->num_frags; nr++) { |
| 527 | frag_info = &priv->frag_info[nr]; |
| 528 | if (length <= frag_info->frag_prefix_size) |
| 529 | break; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 530 | if (!frags[nr].page) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 531 | goto fail; |
| 532 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 533 | dma = be64_to_cpu(rx_desc->data[nr].addr); |
| 534 | dma_sync_single_for_cpu(priv->ddev, dma, frag_info->frag_size, |
| 535 | DMA_FROM_DEVICE); |
| 536 | |
| 537 | /* Save page reference in skb */ |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 538 | __skb_frag_set_page(&skb_frags_rx[nr], frags[nr].page); |
| 539 | skb_frag_size_set(&skb_frags_rx[nr], frag_info->frag_size); |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 540 | skb_frags_rx[nr].page_offset = frags[nr].page_offset; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 541 | skb->truesize += frag_info->frag_stride; |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 542 | frags[nr].page = NULL; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 543 | } |
| 544 | /* Adjust size of last fragment to match actual length */ |
roel kluin | 973507c | 2009-08-08 23:54:21 +0000 | [diff] [blame] | 545 | if (nr > 0) |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 546 | skb_frag_size_set(&skb_frags_rx[nr - 1], |
| 547 | length - priv->frag_info[nr - 1].frag_prefix_size); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 548 | return nr; |
| 549 | |
| 550 | fail: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 551 | while (nr > 0) { |
| 552 | nr--; |
Ian Campbell | 311761c | 2011-10-19 23:01:45 +0000 | [diff] [blame] | 553 | __skb_frag_unref(&skb_frags_rx[nr]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 554 | } |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | |
| 559 | static struct sk_buff *mlx4_en_rx_skb(struct mlx4_en_priv *priv, |
| 560 | struct mlx4_en_rx_desc *rx_desc, |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 561 | struct mlx4_en_rx_alloc *frags, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 562 | unsigned int length) |
| 563 | { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 564 | struct sk_buff *skb; |
| 565 | void *va; |
| 566 | int used_frags; |
| 567 | dma_addr_t dma; |
| 568 | |
Pradeep A Dalvi | c056b73 | 2012-02-05 02:50:38 +0000 | [diff] [blame] | 569 | skb = netdev_alloc_skb(priv->dev, SMALL_PACKET_SIZE + NET_IP_ALIGN); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 570 | if (!skb) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 571 | en_dbg(RX_ERR, priv, "Failed allocating skb\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 572 | return NULL; |
| 573 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 574 | skb_reserve(skb, NET_IP_ALIGN); |
| 575 | skb->len = length; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 576 | |
| 577 | /* Get pointer to first fragment so we could copy the headers into the |
| 578 | * (linear part of the) skb */ |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 579 | va = page_address(frags[0].page) + frags[0].page_offset; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 580 | |
| 581 | if (length <= SMALL_PACKET_SIZE) { |
| 582 | /* We are copying all relevant data to the skb - temporarily |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 583 | * sync buffers for the copy */ |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 584 | dma = be64_to_cpu(rx_desc->data[0].addr); |
Yevgeny Petrilin | ebf8c9a | 2012-03-06 04:03:34 +0000 | [diff] [blame] | 585 | dma_sync_single_for_cpu(priv->ddev, dma, length, |
FUJITA Tomonori | e4fc856 | 2010-02-04 18:57:42 +0000 | [diff] [blame] | 586 | DMA_FROM_DEVICE); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 587 | skb_copy_to_linear_data(skb, va, length); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 588 | skb->tail += length; |
| 589 | } else { |
Eric Dumazet | cfecec5 | 2014-09-05 18:29:45 -0700 | [diff] [blame] | 590 | unsigned int pull_len; |
| 591 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 592 | /* Move relevant fragments to skb */ |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 593 | used_frags = mlx4_en_complete_rx_desc(priv, rx_desc, frags, |
| 594 | skb, length); |
Yevgeny Petrilin | 785a0982 | 2009-04-26 20:42:57 +0000 | [diff] [blame] | 595 | if (unlikely(!used_frags)) { |
| 596 | kfree_skb(skb); |
| 597 | return NULL; |
| 598 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 599 | skb_shinfo(skb)->nr_frags = used_frags; |
| 600 | |
Eric Dumazet | cfecec5 | 2014-09-05 18:29:45 -0700 | [diff] [blame] | 601 | pull_len = eth_get_headlen(va, SMALL_PACKET_SIZE); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 602 | /* Copy headers into the skb linear buffer */ |
Eric Dumazet | cfecec5 | 2014-09-05 18:29:45 -0700 | [diff] [blame] | 603 | memcpy(skb->data, va, pull_len); |
| 604 | skb->tail += pull_len; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 605 | |
| 606 | /* Skip headers in first fragment */ |
Eric Dumazet | cfecec5 | 2014-09-05 18:29:45 -0700 | [diff] [blame] | 607 | skb_shinfo(skb)->frags[0].page_offset += pull_len; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 608 | |
| 609 | /* Adjust size of first fragment */ |
Eric Dumazet | cfecec5 | 2014-09-05 18:29:45 -0700 | [diff] [blame] | 610 | skb_frag_size_sub(&skb_shinfo(skb)->frags[0], pull_len); |
| 611 | skb->data_len = length - pull_len; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 612 | } |
| 613 | return skb; |
| 614 | } |
| 615 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 616 | static void validate_loopback(struct mlx4_en_priv *priv, struct sk_buff *skb) |
| 617 | { |
| 618 | int i; |
| 619 | int offset = ETH_HLEN; |
| 620 | |
| 621 | for (i = 0; i < MLX4_LOOPBACK_TEST_PAYLOAD; i++, offset++) { |
| 622 | if (*(skb->data + offset) != (unsigned char) (i & 0xff)) |
| 623 | goto out_loopback; |
| 624 | } |
| 625 | /* Loopback found */ |
| 626 | priv->loopback_ok = 1; |
| 627 | |
| 628 | out_loopback: |
| 629 | dev_kfree_skb_any(skb); |
| 630 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 631 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 632 | static void mlx4_en_refill_rx_buffers(struct mlx4_en_priv *priv, |
| 633 | struct mlx4_en_rx_ring *ring) |
| 634 | { |
| 635 | int index = ring->prod & ring->size_mask; |
| 636 | |
| 637 | while ((u32) (ring->prod - ring->cons) < ring->actual_size) { |
Ido Shamay | 1ab25f8 | 2014-11-02 16:26:16 +0200 | [diff] [blame] | 638 | if (mlx4_en_prepare_rx_desc(priv, ring, index, |
| 639 | GFP_ATOMIC | __GFP_COLD)) |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 640 | break; |
| 641 | ring->prod++; |
| 642 | index = ring->prod & ring->size_mask; |
| 643 | } |
| 644 | } |
| 645 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 646 | int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budget) |
| 647 | { |
| 648 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 649 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 650 | struct mlx4_cqe *cqe; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 651 | struct mlx4_en_rx_ring *ring = priv->rx_ring[cq->ring]; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 652 | struct mlx4_en_rx_alloc *frags; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 653 | struct mlx4_en_rx_desc *rx_desc; |
| 654 | struct sk_buff *skb; |
| 655 | int index; |
| 656 | int nr; |
| 657 | unsigned int length; |
| 658 | int polled = 0; |
| 659 | int ip_summed; |
Or Gerlitz | 08ff323 | 2012-10-21 14:59:24 +0000 | [diff] [blame] | 660 | int factor = priv->cqe_factor; |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 661 | u64 timestamp; |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 662 | bool l2_tunnel; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 663 | |
| 664 | if (!priv->port_up) |
| 665 | return 0; |
| 666 | |
Eric W. Biederman | 38be0a3 | 2014-03-14 18:05:58 -0700 | [diff] [blame] | 667 | if (budget <= 0) |
| 668 | return polled; |
| 669 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 670 | /* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx |
| 671 | * descriptor offset can be deduced from the CQE index instead of |
| 672 | * reading 'cqe->index' */ |
| 673 | index = cq->mcq.cons_index & ring->size_mask; |
Ido Shamay | b1b6b4d | 2014-09-18 11:51:01 +0300 | [diff] [blame] | 674 | cqe = mlx4_en_get_cqe(cq->buf, index, priv->cqe_size) + factor; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 675 | |
| 676 | /* Process all completed CQEs */ |
| 677 | while (XNOR(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK, |
| 678 | cq->mcq.cons_index & cq->size)) { |
| 679 | |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 680 | frags = ring->rx_info + (index << priv->log_rx_info); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 681 | rx_desc = ring->buf + (index << ring->log_stride); |
| 682 | |
| 683 | /* |
| 684 | * make sure we read the CQE after we read the ownership bit |
| 685 | */ |
| 686 | rmb(); |
| 687 | |
| 688 | /* Drop packet on bad receive or bad checksum */ |
| 689 | if (unlikely((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) == |
| 690 | MLX4_CQE_OPCODE_ERROR)) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 691 | en_err(priv, "CQE completed in error - vendor syndrom:%d syndrom:%d\n", |
| 692 | ((struct mlx4_err_cqe *)cqe)->vendor_err_syndrome, |
| 693 | ((struct mlx4_err_cqe *)cqe)->syndrome); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 694 | goto next; |
| 695 | } |
| 696 | if (unlikely(cqe->badfcs_enc & MLX4_CQE_BAD_FCS)) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 697 | en_dbg(RX_ERR, priv, "Accepted frame with bad FCS\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 698 | goto next; |
| 699 | } |
| 700 | |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 701 | /* Check if we need to drop the packet if SRIOV is not enabled |
| 702 | * and not performing the selftest or flb disabled |
| 703 | */ |
| 704 | if (priv->flags & MLX4_EN_FLAG_RX_FILTER_NEEDED) { |
| 705 | struct ethhdr *ethh; |
| 706 | dma_addr_t dma; |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 707 | /* Get pointer to first fragment since we haven't |
| 708 | * skb yet and cast it to ethhdr struct |
| 709 | */ |
| 710 | dma = be64_to_cpu(rx_desc->data[0].addr); |
| 711 | dma_sync_single_for_cpu(priv->ddev, dma, sizeof(*ethh), |
| 712 | DMA_FROM_DEVICE); |
| 713 | ethh = (struct ethhdr *)(page_address(frags[0].page) + |
Amir Vadai | 70fbe07 | 2013-10-07 13:38:12 +0200 | [diff] [blame] | 714 | frags[0].page_offset); |
Eugenia Emantayev | 5b4c4d3 | 2011-12-13 04:16:38 +0000 | [diff] [blame] | 715 | |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 716 | if (is_multicast_ether_addr(ethh->h_dest)) { |
| 717 | struct mlx4_mac_entry *entry; |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 718 | struct hlist_head *bucket; |
| 719 | unsigned int mac_hash; |
| 720 | |
| 721 | /* Drop the packet, since HW loopback-ed it */ |
| 722 | mac_hash = ethh->h_source[MLX4_EN_MAC_HASH_IDX]; |
| 723 | bucket = &priv->mac_hash[mac_hash]; |
| 724 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 725 | hlist_for_each_entry_rcu(entry, bucket, hlist) { |
Yan Burman | c07cb4b | 2013-02-07 02:25:25 +0000 | [diff] [blame] | 726 | if (ether_addr_equal_64bits(entry->mac, |
| 727 | ethh->h_source)) { |
| 728 | rcu_read_unlock(); |
| 729 | goto next; |
| 730 | } |
| 731 | } |
| 732 | rcu_read_unlock(); |
| 733 | } |
Yan Burman | 79aeacc | 2013-02-07 02:25:19 +0000 | [diff] [blame] | 734 | } |
Eugenia Emantayev | 5b4c4d3 | 2011-12-13 04:16:38 +0000 | [diff] [blame] | 735 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 736 | /* |
| 737 | * Packet is OK - process it. |
| 738 | */ |
| 739 | length = be32_to_cpu(cqe->byte_cnt); |
Yevgeny Petrilin | 4a5f4dd | 2011-11-14 14:25:36 -0500 | [diff] [blame] | 740 | length -= ring->fcs_del; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 741 | ring->bytes += length; |
| 742 | ring->packets++; |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 743 | l2_tunnel = (dev->hw_enc_features & NETIF_F_RXCSUM) && |
| 744 | (cqe->vlan_my_qpn & cpu_to_be32(MLX4_CQE_L2_TUNNEL)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 745 | |
Michał Mirosław | c8c64cf | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 746 | if (likely(dev->features & NETIF_F_RXCSUM)) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 747 | if ((cqe->status & cpu_to_be16(MLX4_CQE_STATUS_IPOK)) && |
| 748 | (cqe->checksum == cpu_to_be16(0xffff))) { |
Yevgeny Petrilin | ad04378 | 2011-10-18 01:50:56 +0000 | [diff] [blame] | 749 | ring->csum_ok++; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 750 | ip_summed = CHECKSUM_UNNECESSARY; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 751 | } else { |
| 752 | ip_summed = CHECKSUM_NONE; |
Yevgeny Petrilin | ad04378 | 2011-10-18 01:50:56 +0000 | [diff] [blame] | 753 | ring->csum_none++; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 754 | } |
| 755 | } else { |
| 756 | ip_summed = CHECKSUM_NONE; |
Yevgeny Petrilin | ad04378 | 2011-10-18 01:50:56 +0000 | [diff] [blame] | 757 | ring->csum_none++; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Shani Michaeli | dd65bea | 2014-11-09 13:51:52 +0200 | [diff] [blame^] | 760 | /* This packet is eligible for GRO if it is: |
| 761 | * - DIX Ethernet (type interpretation) |
| 762 | * - TCP/IP (v4) |
| 763 | * - without IP options |
| 764 | * - not an IP fragment |
| 765 | * - no LLS polling in progress |
| 766 | */ |
| 767 | if (!mlx4_en_cq_busy_polling(cq) && |
| 768 | (dev->features & NETIF_F_GRO)) { |
| 769 | struct sk_buff *gro_skb = napi_get_frags(&cq->napi); |
| 770 | if (!gro_skb) |
| 771 | goto next; |
| 772 | |
| 773 | nr = mlx4_en_complete_rx_desc(priv, |
| 774 | rx_desc, frags, gro_skb, |
| 775 | length); |
| 776 | if (!nr) |
| 777 | goto next; |
| 778 | |
| 779 | skb_shinfo(gro_skb)->nr_frags = nr; |
| 780 | gro_skb->len = length; |
| 781 | gro_skb->data_len = length; |
| 782 | gro_skb->ip_summed = ip_summed; |
| 783 | |
| 784 | if (l2_tunnel && ip_summed == CHECKSUM_UNNECESSARY) |
| 785 | gro_skb->encapsulation = 1; |
| 786 | if ((cqe->vlan_my_qpn & |
| 787 | cpu_to_be32(MLX4_CQE_VLAN_PRESENT_MASK)) && |
| 788 | (dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
| 789 | u16 vid = be16_to_cpu(cqe->sl_vid); |
| 790 | |
| 791 | __vlan_hwaccel_put_tag(gro_skb, htons(ETH_P_8021Q), vid); |
| 792 | } |
| 793 | |
| 794 | if (dev->features & NETIF_F_RXHASH) |
| 795 | skb_set_hash(gro_skb, |
| 796 | be32_to_cpu(cqe->immed_rss_invalid), |
| 797 | PKT_HASH_TYPE_L3); |
| 798 | |
| 799 | skb_record_rx_queue(gro_skb, cq->ring); |
| 800 | skb_mark_napi_id(gro_skb, &cq->napi); |
| 801 | |
| 802 | if (ring->hwtstamp_rx_filter == HWTSTAMP_FILTER_ALL) { |
| 803 | timestamp = mlx4_en_get_cqe_ts(cqe); |
| 804 | mlx4_en_fill_hwtstamps(mdev, |
| 805 | skb_hwtstamps(gro_skb), |
| 806 | timestamp); |
| 807 | } |
| 808 | |
| 809 | napi_gro_frags(&cq->napi); |
| 810 | goto next; |
| 811 | } |
| 812 | |
| 813 | /* GRO not possible, complete processing here */ |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 814 | skb = mlx4_en_rx_skb(priv, rx_desc, frags, length); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 815 | if (!skb) { |
| 816 | priv->stats.rx_dropped++; |
| 817 | goto next; |
| 818 | } |
| 819 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 820 | if (unlikely(priv->validate_loopback)) { |
| 821 | validate_loopback(priv, skb); |
| 822 | goto next; |
| 823 | } |
| 824 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 825 | skb->ip_summed = ip_summed; |
| 826 | skb->protocol = eth_type_trans(skb, dev); |
David S. Miller | 0c8dfc8 | 2009-01-27 16:22:32 -0800 | [diff] [blame] | 827 | skb_record_rx_queue(skb, cq->ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 828 | |
Tom Herbert | 9ca8600 | 2014-08-27 21:27:53 -0700 | [diff] [blame] | 829 | if (l2_tunnel && ip_summed == CHECKSUM_UNNECESSARY) |
| 830 | skb->csum_level = 1; |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 831 | |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 832 | if (dev->features & NETIF_F_RXHASH) |
Tom Herbert | 6917441 | 2013-12-17 23:31:23 -0800 | [diff] [blame] | 833 | skb_set_hash(skb, |
| 834 | be32_to_cpu(cqe->immed_rss_invalid), |
| 835 | PKT_HASH_TYPE_L3); |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 836 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 837 | if ((be32_to_cpu(cqe->vlan_my_qpn) & |
| 838 | MLX4_CQE_VLAN_PRESENT_MASK) && |
| 839 | (dev->features & NETIF_F_HW_VLAN_CTAG_RX)) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 840 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), be16_to_cpu(cqe->sl_vid)); |
Jiri Pirko | f1b553f | 2011-07-20 04:54:22 +0000 | [diff] [blame] | 841 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 842 | if (ring->hwtstamp_rx_filter == HWTSTAMP_FILTER_ALL) { |
| 843 | timestamp = mlx4_en_get_cqe_ts(cqe); |
| 844 | mlx4_en_fill_hwtstamps(mdev, skb_hwtstamps(skb), |
| 845 | timestamp); |
| 846 | } |
| 847 | |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 848 | skb_mark_napi_id(skb, &cq->napi); |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 849 | |
Eric Dumazet | e6a7675 | 2014-01-09 10:30:13 -0800 | [diff] [blame] | 850 | if (!mlx4_en_cq_busy_polling(cq)) |
| 851 | napi_gro_receive(&cq->napi, skb); |
| 852 | else |
| 853 | netif_receive_skb(skb); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 854 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 855 | next: |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 856 | for (nr = 0; nr < priv->num_frags; nr++) |
| 857 | mlx4_en_free_frag(priv, frags, nr); |
| 858 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 859 | ++cq->mcq.cons_index; |
| 860 | index = (cq->mcq.cons_index) & ring->size_mask; |
Ido Shamay | b1b6b4d | 2014-09-18 11:51:01 +0300 | [diff] [blame] | 861 | cqe = mlx4_en_get_cqe(cq->buf, index, priv->cqe_size) + factor; |
Ben Hutchings | f1d29a3 | 2012-11-16 12:44:56 +0000 | [diff] [blame] | 862 | if (++polled == budget) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 863 | goto out; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 866 | out: |
| 867 | AVG_PERF_COUNTER(priv->pstats.rx_coal_avg, polled); |
| 868 | mlx4_cq_set_ci(&cq->mcq); |
| 869 | wmb(); /* ensure HW sees CQ consumer before we post new buffers */ |
| 870 | ring->cons = cq->mcq.cons_index; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 871 | mlx4_en_refill_rx_buffers(priv, ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 872 | mlx4_en_update_rx_prod_db(ring); |
| 873 | return polled; |
| 874 | } |
| 875 | |
| 876 | |
| 877 | void mlx4_en_rx_irq(struct mlx4_cq *mcq) |
| 878 | { |
| 879 | struct mlx4_en_cq *cq = container_of(mcq, struct mlx4_en_cq, mcq); |
| 880 | struct mlx4_en_priv *priv = netdev_priv(cq->dev); |
| 881 | |
Eric Dumazet | 477b35b | 2014-10-29 16:54:45 -0700 | [diff] [blame] | 882 | if (likely(priv->port_up)) |
| 883 | napi_schedule_irqoff(&cq->napi); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 884 | else |
| 885 | mlx4_en_arm_cq(priv, cq); |
| 886 | } |
| 887 | |
| 888 | /* Rx CQ polling - called by NAPI */ |
| 889 | int mlx4_en_poll_rx_cq(struct napi_struct *napi, int budget) |
| 890 | { |
| 891 | struct mlx4_en_cq *cq = container_of(napi, struct mlx4_en_cq, napi); |
| 892 | struct net_device *dev = cq->dev; |
| 893 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 894 | int done; |
| 895 | |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 896 | if (!mlx4_en_cq_lock_napi(cq)) |
| 897 | return budget; |
| 898 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 899 | done = mlx4_en_process_rx_cq(dev, cq, budget); |
| 900 | |
Amir Vadai | 9e77a2b | 2013-06-18 16:18:27 +0300 | [diff] [blame] | 901 | mlx4_en_cq_unlock_napi(cq); |
| 902 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 903 | /* If we used up all the quota - we're probably not done yet... */ |
Yuval Atias | 2eacc23 | 2014-05-14 12:15:10 +0300 | [diff] [blame] | 904 | if (done == budget) { |
Amir Vadai | 35f6f45 | 2014-06-29 11:54:55 +0300 | [diff] [blame] | 905 | int cpu_curr; |
| 906 | const struct cpumask *aff; |
| 907 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 908 | INC_PERF_COUNTER(priv->pstats.napi_quota); |
Amir Vadai | 35f6f45 | 2014-06-29 11:54:55 +0300 | [diff] [blame] | 909 | |
| 910 | cpu_curr = smp_processor_id(); |
| 911 | aff = irq_desc_get_irq_data(cq->irq_desc)->affinity; |
| 912 | |
Eric Dumazet | 2e1af7d | 2014-11-10 14:07:20 -0800 | [diff] [blame] | 913 | if (likely(cpumask_test_cpu(cpu_curr, aff))) |
| 914 | return budget; |
| 915 | |
| 916 | /* Current cpu is not according to smp_irq_affinity - |
| 917 | * probably affinity changed. need to stop this NAPI |
| 918 | * poll, and restart it on the right CPU |
| 919 | */ |
| 920 | done = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 921 | } |
Eric Dumazet | 1a28817 | 2014-11-06 21:10:11 -0800 | [diff] [blame] | 922 | /* Done for now */ |
| 923 | napi_complete_done(napi, done); |
| 924 | mlx4_en_arm_cq(priv, cq); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 925 | return done; |
| 926 | } |
| 927 | |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 928 | static const int frag_sizes[] = { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 929 | FRAG_SZ0, |
| 930 | FRAG_SZ1, |
| 931 | FRAG_SZ2, |
| 932 | FRAG_SZ3 |
| 933 | }; |
| 934 | |
| 935 | void mlx4_en_calc_rx_buf(struct net_device *dev) |
| 936 | { |
| 937 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yishai Hadas | d5b8dff | 2014-07-08 11:25:23 +0300 | [diff] [blame] | 938 | int eff_mtu = dev->mtu + ETH_HLEN + VLAN_HLEN; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 939 | int buf_size = 0; |
| 940 | int i = 0; |
| 941 | |
| 942 | while (buf_size < eff_mtu) { |
| 943 | priv->frag_info[i].frag_size = |
| 944 | (eff_mtu > buf_size + frag_sizes[i]) ? |
| 945 | frag_sizes[i] : eff_mtu - buf_size; |
| 946 | priv->frag_info[i].frag_prefix_size = buf_size; |
Ido Shamay | 5f6e980 | 2014-11-02 16:26:15 +0200 | [diff] [blame] | 947 | priv->frag_info[i].frag_stride = ALIGN(frag_sizes[i], |
| 948 | SMP_CACHE_BYTES); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 949 | buf_size += priv->frag_info[i].frag_size; |
| 950 | i++; |
| 951 | } |
| 952 | |
| 953 | priv->num_frags = i; |
| 954 | priv->rx_skb_size = eff_mtu; |
Thadeu Lima de Souza Cascardo | 4cce66c | 2012-07-16 07:01:53 +0000 | [diff] [blame] | 955 | priv->log_rx_info = ROUNDUP_LOG2(i * sizeof(struct mlx4_en_rx_alloc)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 956 | |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 957 | en_dbg(DRV, priv, "Rx buffer scatter-list (effective-mtu:%d num_frags:%d):\n", |
| 958 | eff_mtu, priv->num_frags); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 959 | for (i = 0; i < priv->num_frags; i++) { |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 960 | en_err(priv, |
Ido Shamay | 5f6e980 | 2014-11-02 16:26:15 +0200 | [diff] [blame] | 961 | " frag:%d - size:%d prefix:%d stride:%d\n", |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 962 | i, |
| 963 | priv->frag_info[i].frag_size, |
| 964 | priv->frag_info[i].frag_prefix_size, |
Eric Dumazet | 51151a1 | 2013-06-23 08:17:56 -0700 | [diff] [blame] | 965 | priv->frag_info[i].frag_stride); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
| 969 | /* RSS related functions */ |
| 970 | |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 971 | static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn, |
| 972 | struct mlx4_en_rx_ring *ring, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 973 | enum mlx4_qp_state *state, |
| 974 | struct mlx4_qp *qp) |
| 975 | { |
| 976 | struct mlx4_en_dev *mdev = priv->mdev; |
| 977 | struct mlx4_qp_context *context; |
| 978 | int err = 0; |
| 979 | |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 980 | context = kmalloc(sizeof(*context), GFP_KERNEL); |
| 981 | if (!context) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 982 | return -ENOMEM; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 983 | |
Jiri Kosina | 40f2287 | 2014-05-11 15:15:12 +0300 | [diff] [blame] | 984 | err = mlx4_qp_alloc(mdev->dev, qpn, qp, GFP_KERNEL); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 985 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 986 | en_err(priv, "Failed to allocate qp #%x\n", qpn); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 987 | goto out; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 988 | } |
| 989 | qp->event = mlx4_en_sqp_event; |
| 990 | |
| 991 | memset(context, 0, sizeof *context); |
Yevgeny Petrilin | 00d7d7b | 2010-08-24 03:45:20 +0000 | [diff] [blame] | 992 | mlx4_en_fill_qp_context(priv, ring->actual_size, ring->stride, 0, 0, |
Amir Vadai | 0e98b52 | 2012-04-04 21:33:24 +0000 | [diff] [blame] | 993 | qpn, ring->cqn, -1, context); |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 994 | context->db_rec_addr = cpu_to_be64(ring->wqres.db.dma); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 995 | |
Yevgeny Petrilin | f3a9d1f | 2011-10-18 01:50:42 +0000 | [diff] [blame] | 996 | /* Cancel FCS removal if FW allows */ |
Yevgeny Petrilin | 4a5f4dd | 2011-11-14 14:25:36 -0500 | [diff] [blame] | 997 | if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP) { |
Yevgeny Petrilin | f3a9d1f | 2011-10-18 01:50:42 +0000 | [diff] [blame] | 998 | context->param3 |= cpu_to_be32(1 << 29); |
Yevgeny Petrilin | 4a5f4dd | 2011-11-14 14:25:36 -0500 | [diff] [blame] | 999 | ring->fcs_del = ETH_FCS_LEN; |
| 1000 | } else |
| 1001 | ring->fcs_del = 0; |
Yevgeny Petrilin | f3a9d1f | 2011-10-18 01:50:42 +0000 | [diff] [blame] | 1002 | |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 1003 | err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, context, qp, state); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1004 | if (err) { |
| 1005 | mlx4_qp_remove(mdev->dev, qp); |
| 1006 | mlx4_qp_free(mdev->dev, qp); |
| 1007 | } |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 1008 | mlx4_en_update_rx_prod_db(ring); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1009 | out: |
| 1010 | kfree(context); |
| 1011 | return err; |
| 1012 | } |
| 1013 | |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1014 | int mlx4_en_create_drop_qp(struct mlx4_en_priv *priv) |
| 1015 | { |
| 1016 | int err; |
| 1017 | u32 qpn; |
| 1018 | |
| 1019 | err = mlx4_qp_reserve_range(priv->mdev->dev, 1, 1, &qpn); |
| 1020 | if (err) { |
| 1021 | en_err(priv, "Failed reserving drop qpn\n"); |
| 1022 | return err; |
| 1023 | } |
Jiri Kosina | 40f2287 | 2014-05-11 15:15:12 +0300 | [diff] [blame] | 1024 | err = mlx4_qp_alloc(priv->mdev->dev, qpn, &priv->drop_qp, GFP_KERNEL); |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1025 | if (err) { |
| 1026 | en_err(priv, "Failed allocating drop qp\n"); |
| 1027 | mlx4_qp_release_range(priv->mdev->dev, qpn, 1); |
| 1028 | return err; |
| 1029 | } |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv) |
| 1035 | { |
| 1036 | u32 qpn; |
| 1037 | |
| 1038 | qpn = priv->drop_qp.qpn; |
| 1039 | mlx4_qp_remove(priv->mdev->dev, &priv->drop_qp); |
| 1040 | mlx4_qp_free(priv->mdev->dev, &priv->drop_qp); |
| 1041 | mlx4_qp_release_range(priv->mdev->dev, qpn, 1); |
| 1042 | } |
| 1043 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1044 | /* Allocate rx qp's and configure them according to rss map */ |
| 1045 | int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv) |
| 1046 | { |
| 1047 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1048 | struct mlx4_en_rss_map *rss_map = &priv->rss_map; |
| 1049 | struct mlx4_qp_context context; |
Or Gerlitz | 876f6e6 | 2011-11-26 19:54:58 +0000 | [diff] [blame] | 1050 | struct mlx4_rss_context *rss_context; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1051 | int rss_rings; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1052 | void *ptr; |
Or Gerlitz | 876f6e6 | 2011-11-26 19:54:58 +0000 | [diff] [blame] | 1053 | u8 rss_mask = (MLX4_RSS_IPV4 | MLX4_RSS_TCP_IPV4 | MLX4_RSS_IPV6 | |
Or Gerlitz | 1202d46 | 2011-11-26 19:55:02 +0000 | [diff] [blame] | 1054 | MLX4_RSS_TCP_IPV6); |
Yevgeny Petrilin | 9f519f6 | 2009-08-06 19:28:18 -0700 | [diff] [blame] | 1055 | int i, qpn; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1056 | int err = 0; |
| 1057 | int good_qps = 0; |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 1058 | static const u32 rsskey[10] = { 0xD181C62C, 0xF7F4DB5B, 0x1983A2FC, |
| 1059 | 0x943E1ADB, 0xD9389E6B, 0xD1039C2C, 0xA74499AD, |
| 1060 | 0x593D56D9, 0xF3253C06, 0x2ADC1FFC}; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1061 | |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1062 | en_dbg(DRV, priv, "Configuring rss steering\n"); |
Yevgeny Petrilin | b6b912e | 2009-08-06 19:27:51 -0700 | [diff] [blame] | 1063 | err = mlx4_qp_reserve_range(mdev->dev, priv->rx_ring_num, |
| 1064 | priv->rx_ring_num, |
| 1065 | &rss_map->base_qpn); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1066 | if (err) { |
Yevgeny Petrilin | b6b912e | 2009-08-06 19:27:51 -0700 | [diff] [blame] | 1067 | en_err(priv, "Failed reserving %d qps\n", priv->rx_ring_num); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1068 | return err; |
| 1069 | } |
| 1070 | |
Yevgeny Petrilin | b6b912e | 2009-08-06 19:27:51 -0700 | [diff] [blame] | 1071 | for (i = 0; i < priv->rx_ring_num; i++) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1072 | qpn = rss_map->base_qpn + i; |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1073 | err = mlx4_en_config_rss_qp(priv, qpn, priv->rx_ring[i], |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1074 | &rss_map->state[i], |
| 1075 | &rss_map->qps[i]); |
| 1076 | if (err) |
| 1077 | goto rss_err; |
| 1078 | |
| 1079 | ++good_qps; |
| 1080 | } |
| 1081 | |
| 1082 | /* Configure RSS indirection qp */ |
Jiri Kosina | 40f2287 | 2014-05-11 15:15:12 +0300 | [diff] [blame] | 1083 | err = mlx4_qp_alloc(mdev->dev, priv->base_qpn, &rss_map->indir_qp, GFP_KERNEL); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1084 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1085 | en_err(priv, "Failed to allocate RSS indirection QP\n"); |
Yevgeny Petrilin | 1679200 | 2011-03-22 22:38:31 +0000 | [diff] [blame] | 1086 | goto rss_err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1087 | } |
| 1088 | rss_map->indir_qp.event = mlx4_en_sqp_event; |
| 1089 | mlx4_en_fill_qp_context(priv, 0, 0, 0, 1, priv->base_qpn, |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1090 | priv->rx_ring[0]->cqn, -1, &context); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1091 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1092 | if (!priv->prof->rss_rings || priv->prof->rss_rings > priv->rx_ring_num) |
| 1093 | rss_rings = priv->rx_ring_num; |
| 1094 | else |
| 1095 | rss_rings = priv->prof->rss_rings; |
| 1096 | |
Or Gerlitz | 876f6e6 | 2011-11-26 19:54:58 +0000 | [diff] [blame] | 1097 | ptr = ((void *) &context) + offsetof(struct mlx4_qp_context, pri_path) |
| 1098 | + MLX4_RSS_OFFSET_IN_QPC_PRI_PATH; |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 1099 | rss_context = ptr; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1100 | rss_context->base_qpn = cpu_to_be32(ilog2(rss_rings) << 24 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1101 | (rss_map->base_qpn)); |
Yevgeny Petrilin | 89efea2 | 2011-12-19 21:53:38 +0000 | [diff] [blame] | 1102 | rss_context->default_qpn = cpu_to_be32(rss_map->base_qpn); |
Or Gerlitz | 1202d46 | 2011-11-26 19:55:02 +0000 | [diff] [blame] | 1103 | if (priv->mdev->profile.udp_rss) { |
| 1104 | rss_mask |= MLX4_RSS_UDP_IPV4 | MLX4_RSS_UDP_IPV6; |
| 1105 | rss_context->base_qpn_udp = rss_context->default_qpn; |
| 1106 | } |
Or Gerlitz | 837052d | 2013-12-23 16:09:44 +0200 | [diff] [blame] | 1107 | |
| 1108 | if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) { |
| 1109 | en_info(priv, "Setting RSS context tunnel type to RSS on inner headers\n"); |
| 1110 | rss_mask |= MLX4_RSS_BY_INNER_HEADERS; |
| 1111 | } |
| 1112 | |
Yevgeny Petrilin | 0533943 | 2010-08-24 03:46:42 +0000 | [diff] [blame] | 1113 | rss_context->flags = rss_mask; |
Or Gerlitz | 876f6e6 | 2011-11-26 19:54:58 +0000 | [diff] [blame] | 1114 | rss_context->hash_fn = MLX4_RSS_HASH_TOP; |
Yevgeny Petrilin | ad86107 | 2011-10-18 01:51:24 +0000 | [diff] [blame] | 1115 | for (i = 0; i < 10; i++) |
Yevgeny Petrilin | 39b2c4e | 2012-03-06 04:04:07 +0000 | [diff] [blame] | 1116 | rss_context->rss_key[i] = cpu_to_be32(rsskey[i]); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1117 | |
| 1118 | err = mlx4_qp_to_ready(mdev->dev, &priv->res.mtt, &context, |
| 1119 | &rss_map->indir_qp, &rss_map->indir_state); |
| 1120 | if (err) |
| 1121 | goto indir_err; |
| 1122 | |
| 1123 | return 0; |
| 1124 | |
| 1125 | indir_err: |
| 1126 | mlx4_qp_modify(mdev->dev, NULL, rss_map->indir_state, |
| 1127 | MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->indir_qp); |
| 1128 | mlx4_qp_remove(mdev->dev, &rss_map->indir_qp); |
| 1129 | mlx4_qp_free(mdev->dev, &rss_map->indir_qp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1130 | rss_err: |
| 1131 | for (i = 0; i < good_qps; i++) { |
| 1132 | mlx4_qp_modify(mdev->dev, NULL, rss_map->state[i], |
| 1133 | MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->qps[i]); |
| 1134 | mlx4_qp_remove(mdev->dev, &rss_map->qps[i]); |
| 1135 | mlx4_qp_free(mdev->dev, &rss_map->qps[i]); |
| 1136 | } |
Yevgeny Petrilin | b6b912e | 2009-08-06 19:27:51 -0700 | [diff] [blame] | 1137 | mlx4_qp_release_range(mdev->dev, rss_map->base_qpn, priv->rx_ring_num); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1138 | return err; |
| 1139 | } |
| 1140 | |
| 1141 | void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv) |
| 1142 | { |
| 1143 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1144 | struct mlx4_en_rss_map *rss_map = &priv->rss_map; |
| 1145 | int i; |
| 1146 | |
| 1147 | mlx4_qp_modify(mdev->dev, NULL, rss_map->indir_state, |
| 1148 | MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->indir_qp); |
| 1149 | mlx4_qp_remove(mdev->dev, &rss_map->indir_qp); |
| 1150 | mlx4_qp_free(mdev->dev, &rss_map->indir_qp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1151 | |
Yevgeny Petrilin | b6b912e | 2009-08-06 19:27:51 -0700 | [diff] [blame] | 1152 | for (i = 0; i < priv->rx_ring_num; i++) { |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1153 | mlx4_qp_modify(mdev->dev, NULL, rss_map->state[i], |
| 1154 | MLX4_QP_STATE_RST, NULL, 0, 0, &rss_map->qps[i]); |
| 1155 | mlx4_qp_remove(mdev->dev, &rss_map->qps[i]); |
| 1156 | mlx4_qp_free(mdev->dev, &rss_map->qps[i]); |
| 1157 | } |
Yevgeny Petrilin | b6b912e | 2009-08-06 19:27:51 -0700 | [diff] [blame] | 1158 | mlx4_qp_release_range(mdev->dev, rss_map->base_qpn, priv->rx_ring_num); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1159 | } |