Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 4 | * Copyright 2005-2011 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation, incorporated herein by reference. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/socket.h> |
| 12 | #include <linux/in.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 14 | #include <linux/ip.h> |
| 15 | #include <linux/tcp.h> |
| 16 | #include <linux/udp.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 17 | #include <linux/prefetch.h> |
Paul Gortmaker | 6eb07ca | 2011-09-15 19:46:05 -0400 | [diff] [blame] | 18 | #include <linux/moduleparam.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 19 | #include <net/ip.h> |
| 20 | #include <net/checksum.h> |
| 21 | #include "net_driver.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 22 | #include "efx.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 23 | #include "nic.h" |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 24 | #include "selftest.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 25 | #include "workarounds.h" |
| 26 | |
| 27 | /* Number of RX descriptors pushed at once. */ |
| 28 | #define EFX_RX_BATCH 8 |
| 29 | |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 30 | /* Maximum length for an RX descriptor sharing a page */ |
| 31 | #define EFX_RX_HALF_PAGE ((PAGE_SIZE >> 1) - sizeof(struct efx_rx_page_state) \ |
| 32 | - EFX_PAGE_IP_ALIGN) |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 33 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 34 | /* Size of buffer allocated for skb header area. */ |
| 35 | #define EFX_SKB_HEADERS 64u |
| 36 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 37 | /* This is the percentage fill level below which new RX descriptors |
| 38 | * will be added to the RX descriptor ring. |
| 39 | */ |
David Riddoch | 6423518 | 2012-04-11 13:12:41 +0100 | [diff] [blame] | 40 | static unsigned int rx_refill_threshold; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 41 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 42 | /* |
| 43 | * RX maximum head room required. |
| 44 | * |
| 45 | * This must be at least 1 to prevent overflow and at least 2 to allow |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 46 | * pipelined receives. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 47 | */ |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 48 | #define EFX_RXD_HEAD_ROOM 2 |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 49 | |
Ben Hutchings | b184f16 | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 50 | static inline u8 *efx_rx_buf_va(struct efx_rx_buffer *buf) |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 51 | { |
Ben Hutchings | b184f16 | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 52 | return page_address(buf->page) + buf->page_offset; |
Steve Hodgson | a526f14 | 2011-02-24 23:45:16 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static inline u32 efx_rx_buf_hash(const u8 *eh) |
| 56 | { |
| 57 | /* The ethernet header is always directly after any hash. */ |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 58 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || NET_IP_ALIGN % 4 == 0 |
Steve Hodgson | a526f14 | 2011-02-24 23:45:16 +0000 | [diff] [blame] | 59 | return __le32_to_cpup((const __le32 *)(eh - 4)); |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 60 | #else |
Steve Hodgson | a526f14 | 2011-02-24 23:45:16 +0000 | [diff] [blame] | 61 | const u8 *data = eh - 4; |
Ben Hutchings | 0beaca2 | 2012-01-05 18:54:04 +0000 | [diff] [blame] | 62 | return (u32)data[0] | |
| 63 | (u32)data[1] << 8 | |
| 64 | (u32)data[2] << 16 | |
| 65 | (u32)data[3] << 24; |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 66 | #endif |
| 67 | } |
| 68 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 69 | /** |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 70 | * efx_init_rx_buffers - create EFX_RX_BATCH page-based RX buffers |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 71 | * |
| 72 | * @rx_queue: Efx RX queue |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 73 | * |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 74 | * This allocates memory for EFX_RX_BATCH receive buffers, maps them for DMA, |
| 75 | * and populates struct efx_rx_buffers for each one. Return a negative error |
| 76 | * code or 0 on success. If a single page can be split between two buffers, |
| 77 | * then the page will either be inserted fully, or not at at all. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 78 | */ |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 79 | static int efx_init_rx_buffers(struct efx_rx_queue *rx_queue) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 80 | { |
| 81 | struct efx_nic *efx = rx_queue->efx; |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 82 | struct efx_rx_buffer *rx_buf; |
| 83 | struct page *page; |
Ben Hutchings | b590ace | 2013-01-10 23:51:54 +0000 | [diff] [blame] | 84 | unsigned int page_offset; |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 85 | struct efx_rx_page_state *state; |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 86 | dma_addr_t dma_addr; |
| 87 | unsigned index, count; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 88 | |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 89 | /* We can split a page between two buffers */ |
| 90 | BUILD_BUG_ON(EFX_RX_BATCH & 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 91 | |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 92 | for (count = 0; count < EFX_RX_BATCH; ++count) { |
| 93 | page = alloc_pages(__GFP_COLD | __GFP_COMP | GFP_ATOMIC, |
| 94 | efx->rx_buffer_order); |
| 95 | if (unlikely(page == NULL)) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 96 | return -ENOMEM; |
Ben Hutchings | 0e33d87 | 2012-05-17 17:46:55 +0100 | [diff] [blame] | 97 | dma_addr = dma_map_page(&efx->pci_dev->dev, page, 0, |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 98 | PAGE_SIZE << efx->rx_buffer_order, |
Ben Hutchings | 0e33d87 | 2012-05-17 17:46:55 +0100 | [diff] [blame] | 99 | DMA_FROM_DEVICE); |
| 100 | if (unlikely(dma_mapping_error(&efx->pci_dev->dev, dma_addr))) { |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 101 | __free_pages(page, efx->rx_buffer_order); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 102 | return -EIO; |
| 103 | } |
Ben Hutchings | b8e0251 | 2012-09-06 23:54:15 +0100 | [diff] [blame] | 104 | state = page_address(page); |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 105 | state->refcnt = 0; |
| 106 | state->dma_addr = dma_addr; |
| 107 | |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 108 | dma_addr += sizeof(struct efx_rx_page_state); |
Ben Hutchings | b590ace | 2013-01-10 23:51:54 +0000 | [diff] [blame] | 109 | page_offset = sizeof(struct efx_rx_page_state); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 110 | |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 111 | split: |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 112 | index = rx_queue->added_count & rx_queue->ptr_mask; |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 113 | rx_buf = efx_rx_buffer(rx_queue, index); |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 114 | rx_buf->dma_addr = dma_addr + EFX_PAGE_IP_ALIGN; |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 115 | rx_buf->page = page; |
Ben Hutchings | c73e787 | 2013-03-05 17:49:39 +0000 | [diff] [blame] | 116 | rx_buf->page_offset = page_offset + EFX_PAGE_IP_ALIGN; |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 117 | rx_buf->len = efx->rx_dma_len; |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 118 | rx_buf->flags = 0; |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 119 | ++rx_queue->added_count; |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 120 | ++state->refcnt; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 121 | |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 122 | if ((~count & 1) && (efx->rx_dma_len <= EFX_RX_HALF_PAGE)) { |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 123 | /* Use the second half of the page */ |
| 124 | get_page(page); |
| 125 | dma_addr += (PAGE_SIZE >> 1); |
Ben Hutchings | b590ace | 2013-01-10 23:51:54 +0000 | [diff] [blame] | 126 | page_offset += (PAGE_SIZE >> 1); |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 127 | ++count; |
| 128 | goto split; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
Ben Hutchings | 4d56606 | 2008-09-01 12:47:12 +0100 | [diff] [blame] | 135 | static void efx_unmap_rx_buffer(struct efx_nic *efx, |
Ben Hutchings | 3a68f19 | 2012-12-20 18:48:20 +0000 | [diff] [blame] | 136 | struct efx_rx_buffer *rx_buf, |
| 137 | unsigned int used_len) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 138 | { |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 139 | if (rx_buf->page) { |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 140 | struct efx_rx_page_state *state; |
| 141 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 142 | state = page_address(rx_buf->page); |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 143 | if (--state->refcnt == 0) { |
Ben Hutchings | 0e33d87 | 2012-05-17 17:46:55 +0100 | [diff] [blame] | 144 | dma_unmap_page(&efx->pci_dev->dev, |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 145 | state->dma_addr, |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 146 | PAGE_SIZE << efx->rx_buffer_order, |
Ben Hutchings | 0e33d87 | 2012-05-17 17:46:55 +0100 | [diff] [blame] | 147 | DMA_FROM_DEVICE); |
Ben Hutchings | 3a68f19 | 2012-12-20 18:48:20 +0000 | [diff] [blame] | 148 | } else if (used_len) { |
| 149 | dma_sync_single_for_cpu(&efx->pci_dev->dev, |
| 150 | rx_buf->dma_addr, used_len, |
| 151 | DMA_FROM_DEVICE); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 152 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Ben Hutchings | 4d56606 | 2008-09-01 12:47:12 +0100 | [diff] [blame] | 156 | static void efx_free_rx_buffer(struct efx_nic *efx, |
| 157 | struct efx_rx_buffer *rx_buf) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 158 | { |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 159 | if (rx_buf->page) { |
| 160 | __free_pages(rx_buf->page, efx->rx_buffer_order); |
| 161 | rx_buf->page = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
Ben Hutchings | 4d56606 | 2008-09-01 12:47:12 +0100 | [diff] [blame] | 165 | static void efx_fini_rx_buffer(struct efx_rx_queue *rx_queue, |
| 166 | struct efx_rx_buffer *rx_buf) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 167 | { |
Ben Hutchings | 3a68f19 | 2012-12-20 18:48:20 +0000 | [diff] [blame] | 168 | efx_unmap_rx_buffer(rx_queue->efx, rx_buf, 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 169 | efx_free_rx_buffer(rx_queue->efx, rx_buf); |
| 170 | } |
| 171 | |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 172 | /* Attempt to resurrect the other receive buffer that used to share this page, |
| 173 | * which had previously been passed up to the kernel and freed. */ |
| 174 | static void efx_resurrect_rx_buffer(struct efx_rx_queue *rx_queue, |
| 175 | struct efx_rx_buffer *rx_buf) |
| 176 | { |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 177 | struct efx_rx_page_state *state = page_address(rx_buf->page); |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 178 | struct efx_rx_buffer *new_buf; |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 179 | unsigned fill_level, index; |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 180 | |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 181 | /* +1 because efx_rx_packet() incremented removed_count. +1 because |
| 182 | * we'd like to insert an additional descriptor whilst leaving |
| 183 | * EFX_RXD_HEAD_ROOM for the non-recycle path */ |
| 184 | fill_level = (rx_queue->added_count - rx_queue->removed_count + 2); |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 185 | if (unlikely(fill_level > rx_queue->max_fill)) { |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 186 | /* We could place "state" on a list, and drain the list in |
| 187 | * efx_fast_push_rx_descriptors(). For now, this will do. */ |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | ++state->refcnt; |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 192 | get_page(rx_buf->page); |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 193 | |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 194 | index = rx_queue->added_count & rx_queue->ptr_mask; |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 195 | new_buf = efx_rx_buffer(rx_queue, index); |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 196 | new_buf->dma_addr = rx_buf->dma_addr ^ (PAGE_SIZE >> 1); |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 197 | new_buf->page = rx_buf->page; |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 198 | new_buf->len = rx_buf->len; |
| 199 | ++rx_queue->added_count; |
| 200 | } |
| 201 | |
| 202 | /* Recycle the given rx buffer directly back into the rx_queue. There is |
| 203 | * always room to add this buffer, because we've just popped a buffer. */ |
| 204 | static void efx_recycle_rx_buffer(struct efx_channel *channel, |
| 205 | struct efx_rx_buffer *rx_buf) |
| 206 | { |
| 207 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 208 | struct efx_rx_queue *rx_queue = efx_channel_get_rx_queue(channel); |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 209 | struct efx_rx_buffer *new_buf; |
| 210 | unsigned index; |
| 211 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 212 | rx_buf->flags = 0; |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 213 | |
Ben Hutchings | 272baee | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 214 | if (efx->rx_dma_len <= EFX_RX_HALF_PAGE && |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 215 | page_count(rx_buf->page) == 1) |
Steve Hodgson | 62b330b | 2010-06-01 11:20:53 +0000 | [diff] [blame] | 216 | efx_resurrect_rx_buffer(rx_queue, rx_buf); |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 217 | |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 218 | index = rx_queue->added_count & rx_queue->ptr_mask; |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 219 | new_buf = efx_rx_buffer(rx_queue, index); |
| 220 | |
| 221 | memcpy(new_buf, rx_buf, sizeof(*new_buf)); |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 222 | rx_buf->page = NULL; |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 223 | ++rx_queue->added_count; |
| 224 | } |
| 225 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 226 | /** |
| 227 | * efx_fast_push_rx_descriptors - push new RX descriptors quickly |
| 228 | * @rx_queue: RX descriptor queue |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 229 | * |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 230 | * This will aim to fill the RX descriptor queue up to |
David Riddoch | da9ca50 | 2012-04-11 13:09:24 +0100 | [diff] [blame] | 231 | * @rx_queue->@max_fill. If there is insufficient atomic |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 232 | * memory to do so, a slow fill will be scheduled. |
| 233 | * |
| 234 | * The caller must provide serialisation (none is used here). In practise, |
| 235 | * this means this function must run from the NAPI handler, or be called |
| 236 | * when NAPI is disabled. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 237 | */ |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 238 | void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 239 | { |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 240 | unsigned fill_level; |
| 241 | int space, rc = 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 242 | |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 243 | /* Calculate current fill level, and exit if we don't need to fill */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 244 | fill_level = (rx_queue->added_count - rx_queue->removed_count); |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 245 | EFX_BUG_ON_PARANOID(fill_level > rx_queue->efx->rxq_entries); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 246 | if (fill_level >= rx_queue->fast_fill_trigger) |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 247 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 248 | |
| 249 | /* Record minimum fill level */ |
Ben Hutchings | b347564 | 2008-05-16 21:15:49 +0100 | [diff] [blame] | 250 | if (unlikely(fill_level < rx_queue->min_fill)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 251 | if (fill_level) |
| 252 | rx_queue->min_fill = fill_level; |
Ben Hutchings | b347564 | 2008-05-16 21:15:49 +0100 | [diff] [blame] | 253 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 254 | |
David Riddoch | da9ca50 | 2012-04-11 13:09:24 +0100 | [diff] [blame] | 255 | space = rx_queue->max_fill - fill_level; |
David Riddoch | 6423518 | 2012-04-11 13:12:41 +0100 | [diff] [blame] | 256 | EFX_BUG_ON_PARANOID(space < EFX_RX_BATCH); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 257 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 258 | netif_vdbg(rx_queue->efx, rx_status, rx_queue->efx->net_dev, |
| 259 | "RX queue %d fast-filling descriptor ring from" |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 260 | " level %d to level %d\n", |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 261 | efx_rx_queue_index(rx_queue), fill_level, |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 262 | rx_queue->max_fill); |
| 263 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 264 | |
| 265 | do { |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 266 | rc = efx_init_rx_buffers(rx_queue); |
Steve Hodgson | f7d6f37 | 2010-06-01 11:33:17 +0000 | [diff] [blame] | 267 | if (unlikely(rc)) { |
| 268 | /* Ensure that we don't leave the rx queue empty */ |
| 269 | if (rx_queue->added_count == rx_queue->removed_count) |
| 270 | efx_schedule_slow_fill(rx_queue); |
| 271 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 272 | } |
| 273 | } while ((space -= EFX_RX_BATCH) >= EFX_RX_BATCH); |
| 274 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 275 | netif_vdbg(rx_queue->efx, rx_status, rx_queue->efx->net_dev, |
| 276 | "RX queue %d fast-filled descriptor ring " |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 277 | "to level %d\n", efx_rx_queue_index(rx_queue), |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 278 | rx_queue->added_count - rx_queue->removed_count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 279 | |
| 280 | out: |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 281 | if (rx_queue->notified_count != rx_queue->added_count) |
| 282 | efx_nic_notify_rx_desc(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 285 | void efx_rx_slow_fill(unsigned long context) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 286 | { |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 287 | struct efx_rx_queue *rx_queue = (struct efx_rx_queue *)context; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 288 | |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 289 | /* Post an event to cause NAPI to run and refill the queue */ |
Ben Hutchings | 2ae75da | 2012-02-07 23:49:52 +0000 | [diff] [blame] | 290 | efx_nic_generate_fill_event(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 291 | ++rx_queue->slow_fill_count; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Ben Hutchings | 4d56606 | 2008-09-01 12:47:12 +0100 | [diff] [blame] | 294 | static void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue, |
| 295 | struct efx_rx_buffer *rx_buf, |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 296 | int len) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 297 | { |
| 298 | struct efx_nic *efx = rx_queue->efx; |
| 299 | unsigned max_len = rx_buf->len - efx->type->rx_buffer_padding; |
| 300 | |
| 301 | if (likely(len <= max_len)) |
| 302 | return; |
| 303 | |
| 304 | /* The packet must be discarded, but this is only a fatal error |
| 305 | * if the caller indicated it was |
| 306 | */ |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 307 | rx_buf->flags |= EFX_RX_PKT_DISCARD; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 308 | |
| 309 | if ((len > rx_buf->len) && EFX_WORKAROUND_8071(efx)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 310 | if (net_ratelimit()) |
| 311 | netif_err(efx, rx_err, efx->net_dev, |
| 312 | " RX queue %d seriously overlength " |
| 313 | "RX event (0x%x > 0x%x+0x%x). Leaking\n", |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 314 | efx_rx_queue_index(rx_queue), len, max_len, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 315 | efx->type->rx_buffer_padding); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 316 | efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY); |
| 317 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 318 | if (net_ratelimit()) |
| 319 | netif_err(efx, rx_err, efx->net_dev, |
| 320 | " RX queue %d overlength RX event " |
| 321 | "(0x%x > 0x%x)\n", |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 322 | efx_rx_queue_index(rx_queue), len, max_len); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 325 | efx_rx_queue_channel(rx_queue)->n_rx_overlength++; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Ben Hutchings | 61321d9 | 2012-02-25 01:58:35 +0000 | [diff] [blame] | 328 | /* Pass a received packet up through GRO. GRO can handle pages |
| 329 | * regardless of checksum state and skbs with a good checksum. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 330 | */ |
stephen hemminger | 4afb752 | 2010-12-06 12:33:01 +0000 | [diff] [blame] | 331 | static void efx_rx_packet_gro(struct efx_channel *channel, |
Ben Hutchings | 345056a | 2009-10-28 03:43:49 -0700 | [diff] [blame] | 332 | struct efx_rx_buffer *rx_buf, |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 333 | const u8 *eh) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 334 | { |
Herbert Xu | da3bc07 | 2009-01-18 21:50:16 -0800 | [diff] [blame] | 335 | struct napi_struct *napi = &channel->napi_str; |
Ben Hutchings | 18e1d2b | 2009-10-29 07:21:24 +0000 | [diff] [blame] | 336 | gro_result_t gro_result; |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 337 | struct efx_nic *efx = channel->efx; |
| 338 | struct page *page = rx_buf->page; |
| 339 | struct sk_buff *skb; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 340 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 341 | rx_buf->page = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 342 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 343 | skb = napi_get_frags(napi); |
| 344 | if (!skb) { |
| 345 | put_page(page); |
| 346 | return; |
| 347 | } |
Ben Hutchings | 1241e95 | 2009-11-23 16:02:25 +0000 | [diff] [blame] | 348 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 349 | if (efx->net_dev->features & NETIF_F_RXHASH) |
| 350 | skb->rxhash = efx_rx_buf_hash(eh); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 351 | |
Ben Hutchings | b74e3e8 | 2013-01-29 23:33:15 +0000 | [diff] [blame^] | 352 | skb_fill_page_desc(skb, 0, page, rx_buf->page_offset, rx_buf->len); |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 353 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 354 | skb->len = rx_buf->len; |
| 355 | skb->data_len = rx_buf->len; |
| 356 | skb->truesize += rx_buf->len; |
| 357 | skb->ip_summed = ((rx_buf->flags & EFX_RX_PKT_CSUMMED) ? |
| 358 | CHECKSUM_UNNECESSARY : CHECKSUM_NONE); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 359 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 360 | skb_record_rx_queue(skb, channel->rx_queue.core_index); |
Ben Hutchings | 3eadb7b | 2009-11-23 16:02:40 +0000 | [diff] [blame] | 361 | |
Ben Hutchings | 18e1d2b | 2009-10-29 07:21:24 +0000 | [diff] [blame] | 362 | gro_result = napi_gro_frags(napi); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 363 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 364 | if (gro_result != GRO_DROP) |
Ben Hutchings | 18e1d2b | 2009-10-29 07:21:24 +0000 | [diff] [blame] | 365 | channel->irq_mod_score += 2; |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /* Allocate and construct an SKB around a struct page.*/ |
| 369 | static struct sk_buff *efx_rx_mk_skb(struct efx_channel *channel, |
| 370 | struct efx_rx_buffer *rx_buf, |
| 371 | u8 *eh, int hdr_len) |
| 372 | { |
| 373 | struct efx_nic *efx = channel->efx; |
| 374 | struct sk_buff *skb; |
| 375 | |
| 376 | /* Allocate an SKB to store the headers */ |
| 377 | skb = netdev_alloc_skb(efx->net_dev, hdr_len + EFX_PAGE_SKB_ALIGN); |
| 378 | if (unlikely(skb == NULL)) |
| 379 | return NULL; |
| 380 | |
| 381 | EFX_BUG_ON_PARANOID(rx_buf->len < hdr_len); |
| 382 | |
| 383 | skb_reserve(skb, EFX_PAGE_SKB_ALIGN); |
| 384 | |
| 385 | skb->len = rx_buf->len; |
| 386 | skb->truesize = rx_buf->len + sizeof(struct sk_buff); |
| 387 | memcpy(skb->data, eh, hdr_len); |
| 388 | skb->tail += hdr_len; |
| 389 | |
| 390 | /* Append the remaining page onto the frag list */ |
| 391 | if (rx_buf->len > hdr_len) { |
| 392 | skb->data_len = skb->len - hdr_len; |
| 393 | skb_fill_page_desc(skb, 0, rx_buf->page, |
Ben Hutchings | b74e3e8 | 2013-01-29 23:33:15 +0000 | [diff] [blame^] | 394 | rx_buf->page_offset + hdr_len, |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 395 | skb->data_len); |
| 396 | } else { |
| 397 | __free_pages(rx_buf->page, efx->rx_buffer_order); |
| 398 | skb->data_len = 0; |
Ben Hutchings | 18e1d2b | 2009-10-29 07:21:24 +0000 | [diff] [blame] | 399 | } |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 400 | |
| 401 | /* Ownership has transferred from the rx_buf to skb */ |
| 402 | rx_buf->page = NULL; |
| 403 | |
| 404 | /* Move past the ethernet header */ |
| 405 | skb->protocol = eth_type_trans(skb, efx->net_dev); |
| 406 | |
| 407 | return skb; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 410 | void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index, |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 411 | unsigned int len, u16 flags) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 412 | { |
| 413 | struct efx_nic *efx = rx_queue->efx; |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 414 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 415 | struct efx_rx_buffer *rx_buf; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 416 | |
| 417 | rx_buf = efx_rx_buffer(rx_queue, index); |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 418 | rx_buf->flags |= flags; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 419 | |
| 420 | /* This allows the refill path to post another buffer. |
| 421 | * EFX_RXD_HEAD_ROOM ensures that the slot we are using |
| 422 | * isn't overwritten yet. |
| 423 | */ |
| 424 | rx_queue->removed_count++; |
| 425 | |
| 426 | /* Validate the length encoded in the event vs the descriptor pushed */ |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 427 | efx_rx_packet__check_len(rx_queue, rx_buf, len); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 428 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 429 | netif_vdbg(efx, rx_status, efx->net_dev, |
| 430 | "RX queue %d received id %x at %llx+%x %s%s\n", |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 431 | efx_rx_queue_index(rx_queue), index, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 432 | (unsigned long long)rx_buf->dma_addr, len, |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 433 | (rx_buf->flags & EFX_RX_PKT_CSUMMED) ? " [SUMMED]" : "", |
| 434 | (rx_buf->flags & EFX_RX_PKT_DISCARD) ? " [DISCARD]" : ""); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 435 | |
| 436 | /* Discard packet, if instructed to do so */ |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 437 | if (unlikely(rx_buf->flags & EFX_RX_PKT_DISCARD)) { |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 438 | efx_recycle_rx_buffer(channel, rx_buf); |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 439 | |
| 440 | /* Don't hold off the previous receive */ |
| 441 | rx_buf = NULL; |
| 442 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Ben Hutchings | 3a68f19 | 2012-12-20 18:48:20 +0000 | [diff] [blame] | 445 | /* Release and/or sync DMA mapping - assumes all RX buffers |
| 446 | * consumed in-order per RX queue |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 447 | */ |
Ben Hutchings | 3a68f19 | 2012-12-20 18:48:20 +0000 | [diff] [blame] | 448 | efx_unmap_rx_buffer(efx, rx_buf, len); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 449 | |
| 450 | /* Prefetch nice and early so data will (hopefully) be in cache by |
| 451 | * the time we look at it. |
| 452 | */ |
Ben Hutchings | 5036b7c | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 453 | prefetch(efx_rx_buf_va(rx_buf)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 454 | |
Ben Hutchings | b74e3e8 | 2013-01-29 23:33:15 +0000 | [diff] [blame^] | 455 | rx_buf->page_offset += efx->type->rx_buffer_hash_size; |
| 456 | rx_buf->len = len - efx->type->rx_buffer_hash_size; |
| 457 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 458 | /* Pipeline receives so that we give time for packet headers to be |
| 459 | * prefetched into cache. |
| 460 | */ |
Steve Hodgson | 2445580 | 2010-06-01 11:20:34 +0000 | [diff] [blame] | 461 | out: |
Ben Hutchings | ff734ef | 2013-01-29 23:33:14 +0000 | [diff] [blame] | 462 | efx_rx_flush_packet(channel); |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 463 | channel->rx_pkt = rx_buf; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 466 | static void efx_rx_deliver(struct efx_channel *channel, u8 *eh, |
Ben Hutchings | 1ddceb4 | 2012-01-23 22:41:30 +0000 | [diff] [blame] | 467 | struct efx_rx_buffer *rx_buf) |
| 468 | { |
| 469 | struct sk_buff *skb; |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 470 | u16 hdr_len = min_t(u16, rx_buf->len, EFX_SKB_HEADERS); |
Ben Hutchings | 1ddceb4 | 2012-01-23 22:41:30 +0000 | [diff] [blame] | 471 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 472 | skb = efx_rx_mk_skb(channel, rx_buf, eh, hdr_len); |
| 473 | if (unlikely(skb == NULL)) { |
| 474 | efx_free_rx_buffer(channel->efx, rx_buf); |
| 475 | return; |
| 476 | } |
| 477 | skb_record_rx_queue(skb, channel->rx_queue.core_index); |
Ben Hutchings | 1ddceb4 | 2012-01-23 22:41:30 +0000 | [diff] [blame] | 478 | |
| 479 | /* Set the SKB flags */ |
| 480 | skb_checksum_none_assert(skb); |
| 481 | |
Stuart Hodgson | c31e5f9 | 2012-07-18 09:52:11 +0100 | [diff] [blame] | 482 | if (channel->type->receive_skb) |
Ben Hutchings | 4a74dc6 | 2013-03-05 20:13:54 +0000 | [diff] [blame] | 483 | if (channel->type->receive_skb(channel, skb)) |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 484 | return; |
Ben Hutchings | 1ddceb4 | 2012-01-23 22:41:30 +0000 | [diff] [blame] | 485 | |
Ben Hutchings | 4a74dc6 | 2013-03-05 20:13:54 +0000 | [diff] [blame] | 486 | /* Pass the packet up */ |
| 487 | netif_receive_skb(skb); |
Ben Hutchings | 1ddceb4 | 2012-01-23 22:41:30 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 490 | /* Handle a received packet. Second half: Touches packet payload. */ |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 491 | void __efx_rx_packet(struct efx_channel *channel, struct efx_rx_buffer *rx_buf) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 492 | { |
| 493 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | b74e3e8 | 2013-01-29 23:33:15 +0000 | [diff] [blame^] | 494 | u8 *eh = efx_rx_buf_va(rx_buf); |
Ben Hutchings | 604f604 | 2010-06-25 07:05:33 +0000 | [diff] [blame] | 495 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 496 | /* If we're in loopback test, then pass the packet directly to the |
| 497 | * loopback layer, and free the rx_buf here |
| 498 | */ |
| 499 | if (unlikely(efx->loopback_selftest)) { |
Steve Hodgson | a526f14 | 2011-02-24 23:45:16 +0000 | [diff] [blame] | 500 | efx_loopback_rx_packet(efx, eh, rx_buf->len); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 501 | efx_free_rx_buffer(efx, rx_buf); |
Ben Hutchings | d96d7dc | 2009-11-23 16:01:44 +0000 | [diff] [blame] | 502 | return; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Ben Hutchings | abfe903 | 2011-04-05 15:00:02 +0100 | [diff] [blame] | 505 | if (unlikely(!(efx->net_dev->features & NETIF_F_RXCSUM))) |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 506 | rx_buf->flags &= ~EFX_RX_PKT_CSUMMED; |
Ben Hutchings | ab3cf6d | 2011-04-01 22:20:06 +0100 | [diff] [blame] | 507 | |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 508 | if (!channel->type->receive_skb) |
Ben Hutchings | db33956 | 2011-08-26 18:05:11 +0100 | [diff] [blame] | 509 | efx_rx_packet_gro(channel, rx_buf, eh); |
Ben Hutchings | 1ddceb4 | 2012-01-23 22:41:30 +0000 | [diff] [blame] | 510 | else |
Alexandre Rames | 97d48a1 | 2013-01-11 12:26:21 +0000 | [diff] [blame] | 511 | efx_rx_deliver(channel, eh, rx_buf); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | int efx_probe_rx_queue(struct efx_rx_queue *rx_queue) |
| 515 | { |
| 516 | struct efx_nic *efx = rx_queue->efx; |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 517 | unsigned int entries; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 518 | int rc; |
| 519 | |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 520 | /* Create the smallest power-of-two aligned ring */ |
| 521 | entries = max(roundup_pow_of_two(efx->rxq_entries), EFX_MIN_DMAQ_SIZE); |
| 522 | EFX_BUG_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE); |
| 523 | rx_queue->ptr_mask = entries - 1; |
| 524 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 525 | netif_dbg(efx, probe, efx->net_dev, |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 526 | "creating RX queue %d size %#x mask %#x\n", |
| 527 | efx_rx_queue_index(rx_queue), efx->rxq_entries, |
| 528 | rx_queue->ptr_mask); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 529 | |
| 530 | /* Allocate RX buffers */ |
Thomas Meyer | c2e4e25 | 2011-12-02 12:36:13 +0000 | [diff] [blame] | 531 | rx_queue->buffer = kcalloc(entries, sizeof(*rx_queue->buffer), |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 532 | GFP_KERNEL); |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 533 | if (!rx_queue->buffer) |
| 534 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 535 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 536 | rc = efx_nic_probe_rx(rx_queue); |
Ben Hutchings | 8831da7 | 2008-09-01 12:47:48 +0100 | [diff] [blame] | 537 | if (rc) { |
| 538 | kfree(rx_queue->buffer); |
| 539 | rx_queue->buffer = NULL; |
| 540 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 541 | return rc; |
| 542 | } |
| 543 | |
Ben Hutchings | bc3c90a | 2008-09-01 12:48:46 +0100 | [diff] [blame] | 544 | void efx_init_rx_queue(struct efx_rx_queue *rx_queue) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 545 | { |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 546 | struct efx_nic *efx = rx_queue->efx; |
David Riddoch | 6423518 | 2012-04-11 13:12:41 +0100 | [diff] [blame] | 547 | unsigned int max_fill, trigger, max_trigger; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 548 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 549 | netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev, |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 550 | "initialising RX queue %d\n", efx_rx_queue_index(rx_queue)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 551 | |
| 552 | /* Initialise ptr fields */ |
| 553 | rx_queue->added_count = 0; |
| 554 | rx_queue->notified_count = 0; |
| 555 | rx_queue->removed_count = 0; |
| 556 | rx_queue->min_fill = -1U; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 557 | |
| 558 | /* Initialise limit fields */ |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 559 | max_fill = efx->rxq_entries - EFX_RXD_HEAD_ROOM; |
David Riddoch | 6423518 | 2012-04-11 13:12:41 +0100 | [diff] [blame] | 560 | max_trigger = max_fill - EFX_RX_BATCH; |
| 561 | if (rx_refill_threshold != 0) { |
| 562 | trigger = max_fill * min(rx_refill_threshold, 100U) / 100U; |
| 563 | if (trigger > max_trigger) |
| 564 | trigger = max_trigger; |
| 565 | } else { |
| 566 | trigger = max_trigger; |
| 567 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 568 | |
| 569 | rx_queue->max_fill = max_fill; |
| 570 | rx_queue->fast_fill_trigger = trigger; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 571 | |
| 572 | /* Set up RX descriptor ring */ |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 573 | rx_queue->enabled = true; |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 574 | efx_nic_init_rx(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | void efx_fini_rx_queue(struct efx_rx_queue *rx_queue) |
| 578 | { |
| 579 | int i; |
| 580 | struct efx_rx_buffer *rx_buf; |
| 581 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 582 | netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev, |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 583 | "shutting down RX queue %d\n", efx_rx_queue_index(rx_queue)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 584 | |
Ben Hutchings | 9f2cb71 | 2012-02-08 00:11:20 +0000 | [diff] [blame] | 585 | /* A flush failure might have left rx_queue->enabled */ |
| 586 | rx_queue->enabled = false; |
| 587 | |
Steve Hodgson | 90d683a | 2010-06-01 11:19:39 +0000 | [diff] [blame] | 588 | del_timer_sync(&rx_queue->slow_fill); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 589 | efx_nic_fini_rx(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 590 | |
| 591 | /* Release RX buffers NB start at index 0 not current HW ptr */ |
| 592 | if (rx_queue->buffer) { |
Steve Hodgson | ecc910f | 2010-09-10 06:42:22 +0000 | [diff] [blame] | 593 | for (i = 0; i <= rx_queue->ptr_mask; i++) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 594 | rx_buf = efx_rx_buffer(rx_queue, i); |
| 595 | efx_fini_rx_buffer(rx_queue, rx_buf); |
| 596 | } |
| 597 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | void efx_remove_rx_queue(struct efx_rx_queue *rx_queue) |
| 601 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 602 | netif_dbg(rx_queue->efx, drv, rx_queue->efx->net_dev, |
Ben Hutchings | ba1e8a3 | 2010-09-10 06:41:36 +0000 | [diff] [blame] | 603 | "destroying RX queue %d\n", efx_rx_queue_index(rx_queue)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 604 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 605 | efx_nic_remove_rx(rx_queue); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 606 | |
| 607 | kfree(rx_queue->buffer); |
| 608 | rx_queue->buffer = NULL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 611 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 612 | module_param(rx_refill_threshold, uint, 0444); |
| 613 | MODULE_PARM_DESC(rx_refill_threshold, |
David Riddoch | 6423518 | 2012-04-11 13:12:41 +0100 | [diff] [blame] | 614 | "RX descriptor ring refill threshold (%)"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 615 | |