Jeff Kirsher | ae06c70 | 2018-03-22 10:08:48 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jeff Kirsher | 51dce24 | 2018-04-26 08:08:09 -0700 | [diff] [blame^] | 2 | /* Copyright(c) 2013 - 2018 Intel Corporation. */ |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 3 | |
Paul Gortmaker | 7ed3f5f | 2014-01-11 04:00:31 +0000 | [diff] [blame] | 4 | #include <linux/prefetch.h> |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 5 | #include <net/busy_poll.h> |
Paul Gortmaker | 7ed3f5f | 2014-01-11 04:00:31 +0000 | [diff] [blame] | 6 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 7 | #include "i40evf.h" |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 8 | #include "i40e_trace.h" |
Jesse Brandeburg | 206812b | 2014-02-12 01:45:33 +0000 | [diff] [blame] | 9 | #include "i40e_prototype.h" |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 10 | |
| 11 | static inline __le64 build_ctob(u32 td_cmd, u32 td_offset, unsigned int size, |
| 12 | u32 td_tag) |
| 13 | { |
| 14 | return cpu_to_le64(I40E_TX_DESC_DTYPE_DATA | |
| 15 | ((u64)td_cmd << I40E_TXD_QW1_CMD_SHIFT) | |
| 16 | ((u64)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) | |
| 17 | ((u64)size << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) | |
| 18 | ((u64)td_tag << I40E_TXD_QW1_L2TAG1_SHIFT)); |
| 19 | } |
| 20 | |
| 21 | #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS) |
| 22 | |
| 23 | /** |
| 24 | * i40e_unmap_and_free_tx_resource - Release a Tx buffer |
| 25 | * @ring: the ring that owns the buffer |
| 26 | * @tx_buffer: the buffer to free |
| 27 | **/ |
| 28 | static void i40e_unmap_and_free_tx_resource(struct i40e_ring *ring, |
| 29 | struct i40e_tx_buffer *tx_buffer) |
| 30 | { |
| 31 | if (tx_buffer->skb) { |
Alexander Duyck | 64bfd68 | 2016-09-12 14:18:39 -0700 | [diff] [blame] | 32 | if (tx_buffer->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 33 | kfree(tx_buffer->raw_buf); |
| 34 | else |
| 35 | dev_kfree_skb_any(tx_buffer->skb); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 36 | if (dma_unmap_len(tx_buffer, len)) |
| 37 | dma_unmap_single(ring->dev, |
| 38 | dma_unmap_addr(tx_buffer, dma), |
| 39 | dma_unmap_len(tx_buffer, len), |
| 40 | DMA_TO_DEVICE); |
| 41 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 42 | dma_unmap_page(ring->dev, |
| 43 | dma_unmap_addr(tx_buffer, dma), |
| 44 | dma_unmap_len(tx_buffer, len), |
| 45 | DMA_TO_DEVICE); |
| 46 | } |
Kiran Patil | a42e7a3 | 2015-11-06 15:26:03 -0800 | [diff] [blame] | 47 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 48 | tx_buffer->next_to_watch = NULL; |
| 49 | tx_buffer->skb = NULL; |
| 50 | dma_unmap_len_set(tx_buffer, len, 0); |
| 51 | /* tx_buffer must be completely set up in the transmit path */ |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * i40evf_clean_tx_ring - Free any empty Tx buffers |
| 56 | * @tx_ring: ring to be cleaned |
| 57 | **/ |
| 58 | void i40evf_clean_tx_ring(struct i40e_ring *tx_ring) |
| 59 | { |
| 60 | unsigned long bi_size; |
| 61 | u16 i; |
| 62 | |
| 63 | /* ring already cleared, nothing to do */ |
| 64 | if (!tx_ring->tx_bi) |
| 65 | return; |
| 66 | |
| 67 | /* Free all the Tx ring sk_buffs */ |
| 68 | for (i = 0; i < tx_ring->count; i++) |
| 69 | i40e_unmap_and_free_tx_resource(tx_ring, &tx_ring->tx_bi[i]); |
| 70 | |
| 71 | bi_size = sizeof(struct i40e_tx_buffer) * tx_ring->count; |
| 72 | memset(tx_ring->tx_bi, 0, bi_size); |
| 73 | |
| 74 | /* Zero out the descriptor ring */ |
| 75 | memset(tx_ring->desc, 0, tx_ring->size); |
| 76 | |
| 77 | tx_ring->next_to_use = 0; |
| 78 | tx_ring->next_to_clean = 0; |
| 79 | |
| 80 | if (!tx_ring->netdev) |
| 81 | return; |
| 82 | |
| 83 | /* cleanup Tx queue statistics */ |
Alexander Duyck | e486bdf | 2016-09-12 14:18:40 -0700 | [diff] [blame] | 84 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /** |
| 88 | * i40evf_free_tx_resources - Free Tx resources per queue |
| 89 | * @tx_ring: Tx descriptor ring for a specific queue |
| 90 | * |
| 91 | * Free all transmit software resources |
| 92 | **/ |
| 93 | void i40evf_free_tx_resources(struct i40e_ring *tx_ring) |
| 94 | { |
| 95 | i40evf_clean_tx_ring(tx_ring); |
| 96 | kfree(tx_ring->tx_bi); |
| 97 | tx_ring->tx_bi = NULL; |
| 98 | |
| 99 | if (tx_ring->desc) { |
| 100 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 101 | tx_ring->desc, tx_ring->dma); |
| 102 | tx_ring->desc = NULL; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 107 | * i40evf_get_tx_pending - how many Tx descriptors not processed |
| 108 | * @tx_ring: the ring of descriptors |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 109 | * @in_sw: is tx_pending being checked in SW or HW |
Jesse Brandeburg | a68de58 | 2015-02-24 05:26:03 +0000 | [diff] [blame] | 110 | * |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 111 | * Since there is no access to the ring head register |
| 112 | * in XL710, we need to use our local copies |
Jesse Brandeburg | a68de58 | 2015-02-24 05:26:03 +0000 | [diff] [blame] | 113 | **/ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 114 | u32 i40evf_get_tx_pending(struct i40e_ring *ring, bool in_sw) |
Jesse Brandeburg | a68de58 | 2015-02-24 05:26:03 +0000 | [diff] [blame] | 115 | { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 116 | u32 head, tail; |
Jesse Brandeburg | a68de58 | 2015-02-24 05:26:03 +0000 | [diff] [blame] | 117 | |
Preethi Banala | b1cb07d | 2017-03-10 12:22:00 -0800 | [diff] [blame] | 118 | head = ring->next_to_clean; |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 119 | tail = readl(ring->tail); |
| 120 | |
| 121 | if (head != tail) |
| 122 | return (head < tail) ? |
| 123 | tail - head : (tail + ring->count - head); |
| 124 | |
| 125 | return 0; |
Jesse Brandeburg | a68de58 | 2015-02-24 05:26:03 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Sudheer Mogilappagari | 07d4419 | 2017-12-18 05:17:25 -0500 | [diff] [blame] | 128 | /** |
| 129 | * i40evf_detect_recover_hung - Function to detect and recover hung_queues |
| 130 | * @vsi: pointer to vsi struct with tx queues |
| 131 | * |
| 132 | * VSI has netdev and netdev has TX queues. This function is to check each of |
| 133 | * those TX queues if they are hung, trigger recovery by issuing SW interrupt. |
| 134 | **/ |
| 135 | void i40evf_detect_recover_hung(struct i40e_vsi *vsi) |
| 136 | { |
| 137 | struct i40e_ring *tx_ring = NULL; |
| 138 | struct net_device *netdev; |
| 139 | unsigned int i; |
| 140 | int packets; |
| 141 | |
| 142 | if (!vsi) |
| 143 | return; |
| 144 | |
| 145 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
| 146 | return; |
| 147 | |
| 148 | netdev = vsi->netdev; |
| 149 | if (!netdev) |
| 150 | return; |
| 151 | |
| 152 | if (!netif_carrier_ok(netdev)) |
| 153 | return; |
| 154 | |
| 155 | for (i = 0; i < vsi->back->num_active_queues; i++) { |
| 156 | tx_ring = &vsi->back->tx_rings[i]; |
| 157 | if (tx_ring && tx_ring->desc) { |
| 158 | /* If packet counter has not changed the queue is |
| 159 | * likely stalled, so force an interrupt for this |
| 160 | * queue. |
| 161 | * |
| 162 | * prev_pkt_ctr would be negative if there was no |
| 163 | * pending work. |
| 164 | */ |
| 165 | packets = tx_ring->stats.packets & INT_MAX; |
| 166 | if (tx_ring->tx_stats.prev_pkt_ctr == packets) { |
| 167 | i40evf_force_wb(vsi, tx_ring->q_vector); |
| 168 | continue; |
| 169 | } |
| 170 | |
| 171 | /* Memory barrier between read of packet count and call |
| 172 | * to i40evf_get_tx_pending() |
| 173 | */ |
| 174 | smp_rmb(); |
| 175 | tx_ring->tx_stats.prev_pkt_ctr = |
Alan Brady | 04d41051 | 2018-02-12 09:16:59 -0500 | [diff] [blame] | 176 | i40evf_get_tx_pending(tx_ring, true) ? packets : -1; |
Sudheer Mogilappagari | 07d4419 | 2017-12-18 05:17:25 -0500 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
Alexander Duyck | 1dc8b53 | 2016-10-11 15:26:54 -0700 | [diff] [blame] | 181 | #define WB_STRIDE 4 |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 182 | |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 183 | /** |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 184 | * i40e_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | a619afe | 2016-03-07 09:30:03 -0800 | [diff] [blame] | 185 | * @vsi: the VSI we care about |
| 186 | * @tx_ring: Tx ring to clean |
| 187 | * @napi_budget: Used to determine if we are in netpoll |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 188 | * |
| 189 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 190 | **/ |
Alexander Duyck | a619afe | 2016-03-07 09:30:03 -0800 | [diff] [blame] | 191 | static bool i40e_clean_tx_irq(struct i40e_vsi *vsi, |
| 192 | struct i40e_ring *tx_ring, int napi_budget) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 193 | { |
| 194 | u16 i = tx_ring->next_to_clean; |
| 195 | struct i40e_tx_buffer *tx_buf; |
| 196 | struct i40e_tx_desc *tx_desc; |
Alexander Duyck | a619afe | 2016-03-07 09:30:03 -0800 | [diff] [blame] | 197 | unsigned int total_bytes = 0, total_packets = 0; |
| 198 | unsigned int budget = vsi->work_limit; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 199 | |
| 200 | tx_buf = &tx_ring->tx_bi[i]; |
| 201 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 202 | i -= tx_ring->count; |
| 203 | |
| 204 | do { |
| 205 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 206 | |
| 207 | /* if next_to_watch is not set then there is no work pending */ |
| 208 | if (!eop_desc) |
| 209 | break; |
| 210 | |
| 211 | /* prevent any other reads prior to eop_desc */ |
Brian King | f72271e | 2017-11-17 11:05:49 -0600 | [diff] [blame] | 212 | smp_rmb(); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 213 | |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 214 | i40e_trace(clean_tx_irq, tx_ring, tx_desc, tx_buf); |
Preethi Banala | b1cb07d | 2017-03-10 12:22:00 -0800 | [diff] [blame] | 215 | /* if the descriptor isn't done, no work yet to do */ |
| 216 | if (!(eop_desc->cmd_type_offset_bsz & |
| 217 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 218 | break; |
| 219 | |
| 220 | /* clear next_to_watch to prevent false hangs */ |
| 221 | tx_buf->next_to_watch = NULL; |
| 222 | |
| 223 | /* update the statistics for this packet */ |
| 224 | total_bytes += tx_buf->bytecount; |
| 225 | total_packets += tx_buf->gso_segs; |
| 226 | |
| 227 | /* free the skb */ |
Alexander Duyck | a619afe | 2016-03-07 09:30:03 -0800 | [diff] [blame] | 228 | napi_consume_skb(tx_buf->skb, napi_budget); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 229 | |
| 230 | /* unmap skb header data */ |
| 231 | dma_unmap_single(tx_ring->dev, |
| 232 | dma_unmap_addr(tx_buf, dma), |
| 233 | dma_unmap_len(tx_buf, len), |
| 234 | DMA_TO_DEVICE); |
| 235 | |
| 236 | /* clear tx_buffer data */ |
| 237 | tx_buf->skb = NULL; |
| 238 | dma_unmap_len_set(tx_buf, len, 0); |
| 239 | |
| 240 | /* unmap remaining buffers */ |
| 241 | while (tx_desc != eop_desc) { |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 242 | i40e_trace(clean_tx_irq_unmap, |
| 243 | tx_ring, tx_desc, tx_buf); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 244 | |
| 245 | tx_buf++; |
| 246 | tx_desc++; |
| 247 | i++; |
| 248 | if (unlikely(!i)) { |
| 249 | i -= tx_ring->count; |
| 250 | tx_buf = tx_ring->tx_bi; |
| 251 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 252 | } |
| 253 | |
| 254 | /* unmap any remaining paged data */ |
| 255 | if (dma_unmap_len(tx_buf, len)) { |
| 256 | dma_unmap_page(tx_ring->dev, |
| 257 | dma_unmap_addr(tx_buf, dma), |
| 258 | dma_unmap_len(tx_buf, len), |
| 259 | DMA_TO_DEVICE); |
| 260 | dma_unmap_len_set(tx_buf, len, 0); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /* move us one more past the eop_desc for start of next pkt */ |
| 265 | tx_buf++; |
| 266 | tx_desc++; |
| 267 | i++; |
| 268 | if (unlikely(!i)) { |
| 269 | i -= tx_ring->count; |
| 270 | tx_buf = tx_ring->tx_bi; |
| 271 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 272 | } |
| 273 | |
Jesse Brandeburg | 016890b | 2015-02-27 09:15:31 +0000 | [diff] [blame] | 274 | prefetch(tx_desc); |
| 275 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 276 | /* update budget accounting */ |
| 277 | budget--; |
| 278 | } while (likely(budget)); |
| 279 | |
| 280 | i += tx_ring->count; |
| 281 | tx_ring->next_to_clean = i; |
| 282 | u64_stats_update_begin(&tx_ring->syncp); |
| 283 | tx_ring->stats.bytes += total_bytes; |
| 284 | tx_ring->stats.packets += total_packets; |
| 285 | u64_stats_update_end(&tx_ring->syncp); |
| 286 | tx_ring->q_vector->tx.total_bytes += total_bytes; |
| 287 | tx_ring->q_vector->tx.total_packets += total_packets; |
| 288 | |
Anjali Singhai Jain | f6d83d1 | 2015-12-22 14:25:07 -0800 | [diff] [blame] | 289 | if (tx_ring->flags & I40E_TXR_FLAGS_WB_ON_ITR) { |
Anjali Singhai Jain | f6d83d1 | 2015-12-22 14:25:07 -0800 | [diff] [blame] | 290 | /* check to see if there are < 4 descriptors |
| 291 | * waiting to be written back, then kick the hardware to force |
| 292 | * them to be written back in case we stay in NAPI. |
| 293 | * In this mode on X722 we do not enable Interrupt. |
| 294 | */ |
Mitch Williams | 88dc9e6 | 2016-06-20 09:10:35 -0700 | [diff] [blame] | 295 | unsigned int j = i40evf_get_tx_pending(tx_ring, false); |
Anjali Singhai Jain | f6d83d1 | 2015-12-22 14:25:07 -0800 | [diff] [blame] | 296 | |
| 297 | if (budget && |
Alexander Duyck | 1dc8b53 | 2016-10-11 15:26:54 -0700 | [diff] [blame] | 298 | ((j / WB_STRIDE) == 0) && (j > 0) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 299 | !test_bit(__I40E_VSI_DOWN, vsi->state) && |
Anjali Singhai Jain | f6d83d1 | 2015-12-22 14:25:07 -0800 | [diff] [blame] | 300 | (I40E_DESC_UNUSED(tx_ring) != tx_ring->count)) |
| 301 | tx_ring->arm_wb = true; |
| 302 | } |
| 303 | |
Alexander Duyck | e486bdf | 2016-09-12 14:18:40 -0700 | [diff] [blame] | 304 | /* notify netdev of completed buffers */ |
| 305 | netdev_tx_completed_queue(txring_txq(tx_ring), |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 306 | total_packets, total_bytes); |
| 307 | |
Jesse Brandeburg | b85c94b | 2017-06-20 15:16:59 -0700 | [diff] [blame] | 308 | #define TX_WAKE_THRESHOLD ((s16)(DESC_NEEDED * 2)) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 309 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
| 310 | (I40E_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
| 311 | /* Make sure that anybody stopping the queue after this |
| 312 | * sees the new next_to_clean. |
| 313 | */ |
| 314 | smp_mb(); |
| 315 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 316 | tx_ring->queue_index) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 317 | !test_bit(__I40E_VSI_DOWN, vsi->state)) { |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 318 | netif_wake_subqueue(tx_ring->netdev, |
| 319 | tx_ring->queue_index); |
| 320 | ++tx_ring->tx_stats.restart_queue; |
| 321 | } |
| 322 | } |
| 323 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 324 | return !!budget; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
Anjali Singhai Jain | ecc6a23 | 2016-01-13 16:51:43 -0800 | [diff] [blame] | 328 | * i40evf_enable_wb_on_itr - Arm hardware to do a wb, interrupts are not enabled |
| 329 | * @vsi: the VSI we care about |
| 330 | * @q_vector: the vector on which to enable writeback |
| 331 | * |
| 332 | **/ |
| 333 | static void i40e_enable_wb_on_itr(struct i40e_vsi *vsi, |
| 334 | struct i40e_q_vector *q_vector) |
| 335 | { |
| 336 | u16 flags = q_vector->tx.ring[0].flags; |
| 337 | u32 val; |
| 338 | |
| 339 | if (!(flags & I40E_TXR_FLAGS_WB_ON_ITR)) |
| 340 | return; |
| 341 | |
| 342 | if (q_vector->arm_wb_state) |
| 343 | return; |
| 344 | |
| 345 | val = I40E_VFINT_DYN_CTLN1_WB_ON_ITR_MASK | |
| 346 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK; /* set noitr */ |
| 347 | |
| 348 | wr32(&vsi->back->hw, |
Alexander Duyck | a3f9fb5 | 2017-12-29 08:48:53 -0500 | [diff] [blame] | 349 | I40E_VFINT_DYN_CTLN1(q_vector->reg_idx), val); |
Anjali Singhai Jain | ecc6a23 | 2016-01-13 16:51:43 -0800 | [diff] [blame] | 350 | q_vector->arm_wb_state = true; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * i40evf_force_wb - Issue SW Interrupt so HW does a wb |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 355 | * @vsi: the VSI we care about |
| 356 | * @q_vector: the vector on which to force writeback |
| 357 | * |
| 358 | **/ |
Anjali Singhai Jain | ecc6a23 | 2016-01-13 16:51:43 -0800 | [diff] [blame] | 359 | void i40evf_force_wb(struct i40e_vsi *vsi, struct i40e_q_vector *q_vector) |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 360 | { |
Anjali Singhai Jain | ecc6a23 | 2016-01-13 16:51:43 -0800 | [diff] [blame] | 361 | u32 val = I40E_VFINT_DYN_CTLN1_INTENA_MASK | |
| 362 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | /* set noitr */ |
| 363 | I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK | |
| 364 | I40E_VFINT_DYN_CTLN1_SW_ITR_INDX_ENA_MASK |
| 365 | /* allow 00 to be written to the index */; |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 366 | |
Anjali Singhai Jain | ecc6a23 | 2016-01-13 16:51:43 -0800 | [diff] [blame] | 367 | wr32(&vsi->back->hw, |
Alexander Duyck | a3f9fb5 | 2017-12-29 08:48:53 -0500 | [diff] [blame] | 368 | I40E_VFINT_DYN_CTLN1(q_vector->reg_idx), |
Anjali Singhai Jain | ecc6a23 | 2016-01-13 16:51:43 -0800 | [diff] [blame] | 369 | val); |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 372 | static inline bool i40e_container_is_rx(struct i40e_q_vector *q_vector, |
| 373 | struct i40e_ring_container *rc) |
| 374 | { |
| 375 | return &q_vector->rx == rc; |
| 376 | } |
| 377 | |
| 378 | static inline unsigned int i40e_itr_divisor(struct i40e_q_vector *q_vector) |
| 379 | { |
| 380 | unsigned int divisor; |
| 381 | |
| 382 | switch (q_vector->adapter->link_speed) { |
| 383 | case I40E_LINK_SPEED_40GB: |
| 384 | divisor = I40E_ITR_ADAPTIVE_MIN_INC * 1024; |
| 385 | break; |
| 386 | case I40E_LINK_SPEED_25GB: |
| 387 | case I40E_LINK_SPEED_20GB: |
| 388 | divisor = I40E_ITR_ADAPTIVE_MIN_INC * 512; |
| 389 | break; |
| 390 | default: |
| 391 | case I40E_LINK_SPEED_10GB: |
| 392 | divisor = I40E_ITR_ADAPTIVE_MIN_INC * 256; |
| 393 | break; |
| 394 | case I40E_LINK_SPEED_1GB: |
| 395 | case I40E_LINK_SPEED_100MB: |
| 396 | divisor = I40E_ITR_ADAPTIVE_MIN_INC * 32; |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | return divisor; |
| 401 | } |
| 402 | |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 403 | /** |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 404 | * i40e_update_itr - update the dynamic ITR value based on statistics |
| 405 | * @q_vector: structure containing interrupt and ring information |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 406 | * @rc: structure containing ring performance data |
| 407 | * |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 408 | * Stores a new ITR value based on packets and byte |
| 409 | * counts during the last interrupt. The advantage of per interrupt |
| 410 | * computation is faster updates and more accurate ITR for the current |
| 411 | * traffic pattern. Constants in this function were computed |
| 412 | * based on theoretical maximum wire speed and thresholds were set based |
| 413 | * on testing data as well as attempting to minimize response time |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 414 | * while increasing bulk throughput. |
| 415 | **/ |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 416 | static void i40e_update_itr(struct i40e_q_vector *q_vector, |
| 417 | struct i40e_ring_container *rc) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 418 | { |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 419 | unsigned int avg_wire_size, packets, bytes, itr; |
| 420 | unsigned long next_update = jiffies; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 421 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 422 | /* If we don't have any rings just leave ourselves set for maximum |
| 423 | * possible latency so we take ourselves out of the equation. |
| 424 | */ |
Alexander Duyck | 71dc371 | 2017-12-29 08:49:53 -0500 | [diff] [blame] | 425 | if (!rc->ring || !ITR_IS_DYNAMIC(rc->ring->itr_setting)) |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 426 | return; |
Alexander Duyck | 71dc371 | 2017-12-29 08:49:53 -0500 | [diff] [blame] | 427 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 428 | /* For Rx we want to push the delay up and default to low latency. |
| 429 | * for Tx we want to pull the delay down and default to high latency. |
Jacob Keller | 742c987 | 2017-07-14 09:10:13 -0400 | [diff] [blame] | 430 | */ |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 431 | itr = i40e_container_is_rx(q_vector, rc) ? |
| 432 | I40E_ITR_ADAPTIVE_MIN_USECS | I40E_ITR_ADAPTIVE_LATENCY : |
| 433 | I40E_ITR_ADAPTIVE_MAX_USECS | I40E_ITR_ADAPTIVE_LATENCY; |
| 434 | |
| 435 | /* If we didn't update within up to 1 - 2 jiffies we can assume |
| 436 | * that either packets are coming in so slow there hasn't been |
| 437 | * any work, or that there is so much work that NAPI is dealing |
| 438 | * with interrupt moderation and we don't need to do anything. |
| 439 | */ |
| 440 | if (time_after(next_update, rc->next_update)) |
| 441 | goto clear_counts; |
| 442 | |
| 443 | /* If itr_countdown is set it means we programmed an ITR within |
| 444 | * the last 4 interrupt cycles. This has a side effect of us |
| 445 | * potentially firing an early interrupt. In order to work around |
| 446 | * this we need to throw out any data received for a few |
| 447 | * interrupts following the update. |
| 448 | */ |
| 449 | if (q_vector->itr_countdown) { |
| 450 | itr = rc->target_itr; |
| 451 | goto clear_counts; |
Jacob Keller | 742c987 | 2017-07-14 09:10:13 -0400 | [diff] [blame] | 452 | } |
| 453 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 454 | packets = rc->total_packets; |
| 455 | bytes = rc->total_bytes; |
| 456 | |
| 457 | if (i40e_container_is_rx(q_vector, rc)) { |
| 458 | /* If Rx there are 1 to 4 packets and bytes are less than |
| 459 | * 9000 assume insufficient data to use bulk rate limiting |
| 460 | * approach unless Tx is already in bulk rate limiting. We |
| 461 | * are likely latency driven. |
| 462 | */ |
| 463 | if (packets && packets < 4 && bytes < 9000 && |
| 464 | (q_vector->tx.target_itr & I40E_ITR_ADAPTIVE_LATENCY)) { |
| 465 | itr = I40E_ITR_ADAPTIVE_LATENCY; |
| 466 | goto adjust_by_size; |
| 467 | } |
| 468 | } else if (packets < 4) { |
| 469 | /* If we have Tx and Rx ITR maxed and Tx ITR is running in |
| 470 | * bulk mode and we are receiving 4 or fewer packets just |
| 471 | * reset the ITR_ADAPTIVE_LATENCY bit for latency mode so |
| 472 | * that the Rx can relax. |
| 473 | */ |
| 474 | if (rc->target_itr == I40E_ITR_ADAPTIVE_MAX_USECS && |
| 475 | (q_vector->rx.target_itr & I40E_ITR_MASK) == |
| 476 | I40E_ITR_ADAPTIVE_MAX_USECS) |
| 477 | goto clear_counts; |
| 478 | } else if (packets > 32) { |
| 479 | /* If we have processed over 32 packets in a single interrupt |
| 480 | * for Tx assume we need to switch over to "bulk" mode. |
| 481 | */ |
| 482 | rc->target_itr &= ~I40E_ITR_ADAPTIVE_LATENCY; |
| 483 | } |
| 484 | |
| 485 | /* We have no packets to actually measure against. This means |
| 486 | * either one of the other queues on this vector is active or |
| 487 | * we are a Tx queue doing TSO with too high of an interrupt rate. |
Jesse Brandeburg | 51cc6d9 | 2015-09-28 14:16:52 -0400 | [diff] [blame] | 488 | * |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 489 | * Between 4 and 56 we can assume that our current interrupt delay |
| 490 | * is only slightly too low. As such we should increase it by a small |
| 491 | * fixed amount. |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 492 | */ |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 493 | if (packets < 56) { |
| 494 | itr = rc->target_itr + I40E_ITR_ADAPTIVE_MIN_INC; |
| 495 | if ((itr & I40E_ITR_MASK) > I40E_ITR_ADAPTIVE_MAX_USECS) { |
| 496 | itr &= I40E_ITR_ADAPTIVE_LATENCY; |
| 497 | itr += I40E_ITR_ADAPTIVE_MAX_USECS; |
| 498 | } |
| 499 | goto clear_counts; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 500 | } |
Jesse Brandeburg | c56625d | 2015-09-28 14:16:53 -0400 | [diff] [blame] | 501 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 502 | if (packets <= 256) { |
| 503 | itr = min(q_vector->tx.current_itr, q_vector->rx.current_itr); |
| 504 | itr &= I40E_ITR_MASK; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 505 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 506 | /* Between 56 and 112 is our "goldilocks" zone where we are |
| 507 | * working out "just right". Just report that our current |
| 508 | * ITR is good for us. |
| 509 | */ |
| 510 | if (packets <= 112) |
| 511 | goto clear_counts; |
| 512 | |
| 513 | /* If packet count is 128 or greater we are likely looking |
| 514 | * at a slight overrun of the delay we want. Try halving |
| 515 | * our delay to see if that will cut the number of packets |
| 516 | * in half per interrupt. |
| 517 | */ |
| 518 | itr /= 2; |
| 519 | itr &= I40E_ITR_MASK; |
| 520 | if (itr < I40E_ITR_ADAPTIVE_MIN_USECS) |
| 521 | itr = I40E_ITR_ADAPTIVE_MIN_USECS; |
| 522 | |
| 523 | goto clear_counts; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 526 | /* The paths below assume we are dealing with a bulk ITR since |
| 527 | * number of packets is greater than 256. We are just going to have |
| 528 | * to compute a value and try to bring the count under control, |
| 529 | * though for smaller packet sizes there isn't much we can do as |
| 530 | * NAPI polling will likely be kicking in sooner rather than later. |
| 531 | */ |
| 532 | itr = I40E_ITR_ADAPTIVE_BULK; |
| 533 | |
| 534 | adjust_by_size: |
| 535 | /* If packet counts are 256 or greater we can assume we have a gross |
| 536 | * overestimation of what the rate should be. Instead of trying to fine |
| 537 | * tune it just use the formula below to try and dial in an exact value |
| 538 | * give the current packet size of the frame. |
| 539 | */ |
| 540 | avg_wire_size = bytes / packets; |
| 541 | |
| 542 | /* The following is a crude approximation of: |
| 543 | * wmem_default / (size + overhead) = desired_pkts_per_int |
| 544 | * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate |
| 545 | * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value |
| 546 | * |
| 547 | * Assuming wmem_default is 212992 and overhead is 640 bytes per |
| 548 | * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the |
| 549 | * formula down to |
| 550 | * |
| 551 | * (170 * (size + 24)) / (size + 640) = ITR |
| 552 | * |
| 553 | * We first do some math on the packet size and then finally bitshift |
| 554 | * by 8 after rounding up. We also have to account for PCIe link speed |
| 555 | * difference as ITR scales based on this. |
| 556 | */ |
| 557 | if (avg_wire_size <= 60) { |
| 558 | /* Start at 250k ints/sec */ |
| 559 | avg_wire_size = 4096; |
| 560 | } else if (avg_wire_size <= 380) { |
| 561 | /* 250K ints/sec to 60K ints/sec */ |
| 562 | avg_wire_size *= 40; |
| 563 | avg_wire_size += 1696; |
| 564 | } else if (avg_wire_size <= 1084) { |
| 565 | /* 60K ints/sec to 36K ints/sec */ |
| 566 | avg_wire_size *= 15; |
| 567 | avg_wire_size += 11452; |
| 568 | } else if (avg_wire_size <= 1980) { |
| 569 | /* 36K ints/sec to 30K ints/sec */ |
| 570 | avg_wire_size *= 5; |
| 571 | avg_wire_size += 22420; |
| 572 | } else { |
| 573 | /* plateau at a limit of 30K ints/sec */ |
| 574 | avg_wire_size = 32256; |
| 575 | } |
| 576 | |
| 577 | /* If we are in low latency mode halve our delay which doubles the |
| 578 | * rate to somewhere between 100K to 16K ints/sec |
| 579 | */ |
| 580 | if (itr & I40E_ITR_ADAPTIVE_LATENCY) |
| 581 | avg_wire_size /= 2; |
| 582 | |
| 583 | /* Resultant value is 256 times larger than it needs to be. This |
| 584 | * gives us room to adjust the value as needed to either increase |
| 585 | * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc. |
| 586 | * |
| 587 | * Use addition as we have already recorded the new latency flag |
| 588 | * for the ITR value. |
| 589 | */ |
| 590 | itr += DIV_ROUND_UP(avg_wire_size, i40e_itr_divisor(q_vector)) * |
| 591 | I40E_ITR_ADAPTIVE_MIN_INC; |
| 592 | |
| 593 | if ((itr & I40E_ITR_MASK) > I40E_ITR_ADAPTIVE_MAX_USECS) { |
| 594 | itr &= I40E_ITR_ADAPTIVE_LATENCY; |
| 595 | itr += I40E_ITR_ADAPTIVE_MAX_USECS; |
| 596 | } |
| 597 | |
| 598 | clear_counts: |
| 599 | /* write back value */ |
| 600 | rc->target_itr = itr; |
| 601 | |
| 602 | /* next update should occur within next jiffy */ |
| 603 | rc->next_update = next_update + 1; |
| 604 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 605 | rc->total_bytes = 0; |
| 606 | rc->total_packets = 0; |
| 607 | } |
| 608 | |
Jesse Brandeburg | 4eeb1ff | 2015-11-18 17:35:42 -0800 | [diff] [blame] | 609 | /** |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 610 | * i40evf_setup_tx_descriptors - Allocate the Tx descriptors |
| 611 | * @tx_ring: the tx ring to set up |
| 612 | * |
| 613 | * Return 0 on success, negative on error |
| 614 | **/ |
| 615 | int i40evf_setup_tx_descriptors(struct i40e_ring *tx_ring) |
| 616 | { |
| 617 | struct device *dev = tx_ring->dev; |
| 618 | int bi_size; |
| 619 | |
| 620 | if (!dev) |
| 621 | return -ENOMEM; |
| 622 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 623 | /* warn if we are about to overwrite the pointer */ |
| 624 | WARN_ON(tx_ring->tx_bi); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 625 | bi_size = sizeof(struct i40e_tx_buffer) * tx_ring->count; |
| 626 | tx_ring->tx_bi = kzalloc(bi_size, GFP_KERNEL); |
| 627 | if (!tx_ring->tx_bi) |
| 628 | goto err; |
| 629 | |
| 630 | /* round up to nearest 4K */ |
| 631 | tx_ring->size = tx_ring->count * sizeof(struct i40e_tx_desc); |
| 632 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 633 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 634 | &tx_ring->dma, GFP_KERNEL); |
| 635 | if (!tx_ring->desc) { |
| 636 | dev_info(dev, "Unable to allocate memory for the Tx descriptor ring, size=%d\n", |
| 637 | tx_ring->size); |
| 638 | goto err; |
| 639 | } |
| 640 | |
| 641 | tx_ring->next_to_use = 0; |
| 642 | tx_ring->next_to_clean = 0; |
Sudheer Mogilappagari | 07d4419 | 2017-12-18 05:17:25 -0500 | [diff] [blame] | 643 | tx_ring->tx_stats.prev_pkt_ctr = -1; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 644 | return 0; |
| 645 | |
| 646 | err: |
| 647 | kfree(tx_ring->tx_bi); |
| 648 | tx_ring->tx_bi = NULL; |
| 649 | return -ENOMEM; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * i40evf_clean_rx_ring - Free Rx buffers |
| 654 | * @rx_ring: ring to be cleaned |
| 655 | **/ |
| 656 | void i40evf_clean_rx_ring(struct i40e_ring *rx_ring) |
| 657 | { |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 658 | unsigned long bi_size; |
| 659 | u16 i; |
| 660 | |
| 661 | /* ring already cleared, nothing to do */ |
| 662 | if (!rx_ring->rx_bi) |
| 663 | return; |
| 664 | |
Scott Peterson | e72e565 | 2017-02-09 23:40:25 -0800 | [diff] [blame] | 665 | if (rx_ring->skb) { |
| 666 | dev_kfree_skb(rx_ring->skb); |
| 667 | rx_ring->skb = NULL; |
| 668 | } |
| 669 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 670 | /* Free all the Rx ring sk_buffs */ |
| 671 | for (i = 0; i < rx_ring->count; i++) { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 672 | struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i]; |
| 673 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 674 | if (!rx_bi->page) |
| 675 | continue; |
| 676 | |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 677 | /* Invalidate cache lines that may have been written to by |
| 678 | * device so that we avoid corrupting memory. |
| 679 | */ |
| 680 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 681 | rx_bi->dma, |
| 682 | rx_bi->page_offset, |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 683 | rx_ring->rx_buf_len, |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 684 | DMA_FROM_DEVICE); |
| 685 | |
| 686 | /* free resources associated with mapping */ |
| 687 | dma_unmap_page_attrs(rx_ring->dev, rx_bi->dma, |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 688 | i40e_rx_pg_size(rx_ring), |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 689 | DMA_FROM_DEVICE, |
| 690 | I40E_RX_DMA_ATTR); |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 691 | |
Alexander Duyck | 1793668 | 2017-02-21 15:55:39 -0800 | [diff] [blame] | 692 | __page_frag_cache_drain(rx_bi->page, rx_bi->pagecnt_bias); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 693 | |
| 694 | rx_bi->page = NULL; |
| 695 | rx_bi->page_offset = 0; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | bi_size = sizeof(struct i40e_rx_buffer) * rx_ring->count; |
| 699 | memset(rx_ring->rx_bi, 0, bi_size); |
| 700 | |
| 701 | /* Zero out the descriptor ring */ |
| 702 | memset(rx_ring->desc, 0, rx_ring->size); |
| 703 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 704 | rx_ring->next_to_alloc = 0; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 705 | rx_ring->next_to_clean = 0; |
| 706 | rx_ring->next_to_use = 0; |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * i40evf_free_rx_resources - Free Rx resources |
| 711 | * @rx_ring: ring to clean the resources from |
| 712 | * |
| 713 | * Free all receive software resources |
| 714 | **/ |
| 715 | void i40evf_free_rx_resources(struct i40e_ring *rx_ring) |
| 716 | { |
| 717 | i40evf_clean_rx_ring(rx_ring); |
| 718 | kfree(rx_ring->rx_bi); |
| 719 | rx_ring->rx_bi = NULL; |
| 720 | |
| 721 | if (rx_ring->desc) { |
| 722 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 723 | rx_ring->desc, rx_ring->dma); |
| 724 | rx_ring->desc = NULL; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * i40evf_setup_rx_descriptors - Allocate Rx descriptors |
| 730 | * @rx_ring: Rx descriptor ring (for a specific queue) to setup |
| 731 | * |
| 732 | * Returns 0 on success, negative on failure |
| 733 | **/ |
| 734 | int i40evf_setup_rx_descriptors(struct i40e_ring *rx_ring) |
| 735 | { |
| 736 | struct device *dev = rx_ring->dev; |
| 737 | int bi_size; |
| 738 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 739 | /* warn if we are about to overwrite the pointer */ |
| 740 | WARN_ON(rx_ring->rx_bi); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 741 | bi_size = sizeof(struct i40e_rx_buffer) * rx_ring->count; |
| 742 | rx_ring->rx_bi = kzalloc(bi_size, GFP_KERNEL); |
| 743 | if (!rx_ring->rx_bi) |
| 744 | goto err; |
| 745 | |
Carolyn Wyborny | f217d6c | 2015-02-09 17:42:31 -0800 | [diff] [blame] | 746 | u64_stats_init(&rx_ring->syncp); |
Carolyn Wyborny | 638702b | 2015-01-24 09:58:32 +0000 | [diff] [blame] | 747 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 748 | /* Round up to nearest 4K */ |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 749 | rx_ring->size = rx_ring->count * sizeof(union i40e_32byte_rx_desc); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 750 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 751 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 752 | &rx_ring->dma, GFP_KERNEL); |
| 753 | |
| 754 | if (!rx_ring->desc) { |
| 755 | dev_info(dev, "Unable to allocate memory for the Rx descriptor ring, size=%d\n", |
| 756 | rx_ring->size); |
| 757 | goto err; |
| 758 | } |
| 759 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 760 | rx_ring->next_to_alloc = 0; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 761 | rx_ring->next_to_clean = 0; |
| 762 | rx_ring->next_to_use = 0; |
| 763 | |
| 764 | return 0; |
| 765 | err: |
| 766 | kfree(rx_ring->rx_bi); |
| 767 | rx_ring->rx_bi = NULL; |
| 768 | return -ENOMEM; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * i40e_release_rx_desc - Store the new tail and head values |
| 773 | * @rx_ring: ring to bump |
| 774 | * @val: new head index |
| 775 | **/ |
| 776 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 777 | { |
| 778 | rx_ring->next_to_use = val; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 779 | |
| 780 | /* update next to alloc since we have filled the ring */ |
| 781 | rx_ring->next_to_alloc = val; |
| 782 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 783 | /* Force memory writes to complete before letting h/w |
| 784 | * know there are new descriptors to fetch. (Only |
| 785 | * applicable for weak-ordered memory model archs, |
| 786 | * such as IA-64). |
| 787 | */ |
| 788 | wmb(); |
| 789 | writel(val, rx_ring->tail); |
| 790 | } |
| 791 | |
| 792 | /** |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 793 | * i40e_rx_offset - Return expected offset into page to access data |
| 794 | * @rx_ring: Ring we are requesting offset of |
| 795 | * |
| 796 | * Returns the offset value for ring into the data buffer. |
| 797 | */ |
| 798 | static inline unsigned int i40e_rx_offset(struct i40e_ring *rx_ring) |
| 799 | { |
| 800 | return ring_uses_build_skb(rx_ring) ? I40E_SKB_PAD : 0; |
| 801 | } |
| 802 | |
| 803 | /** |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 804 | * i40e_alloc_mapped_page - recycle or make a new page |
| 805 | * @rx_ring: ring to use |
| 806 | * @bi: rx_buffer struct to modify |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 807 | * |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 808 | * Returns true if the page was successfully allocated or |
| 809 | * reused. |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 810 | **/ |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 811 | static bool i40e_alloc_mapped_page(struct i40e_ring *rx_ring, |
| 812 | struct i40e_rx_buffer *bi) |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 813 | { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 814 | struct page *page = bi->page; |
| 815 | dma_addr_t dma; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 816 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 817 | /* since we are recycling buffers we should seldom need to alloc */ |
| 818 | if (likely(page)) { |
| 819 | rx_ring->rx_stats.page_reuse_count++; |
| 820 | return true; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 823 | /* alloc new page for storage */ |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 824 | page = dev_alloc_pages(i40e_rx_pg_order(rx_ring)); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 825 | if (unlikely(!page)) { |
| 826 | rx_ring->rx_stats.alloc_page_failed++; |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 827 | return false; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 830 | /* map page for use */ |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 831 | dma = dma_map_page_attrs(rx_ring->dev, page, 0, |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 832 | i40e_rx_pg_size(rx_ring), |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 833 | DMA_FROM_DEVICE, |
| 834 | I40E_RX_DMA_ATTR); |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 835 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 836 | /* if mapping failed free memory back to system since |
| 837 | * there isn't much point in holding memory we can't use |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 838 | */ |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 839 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 840 | __free_pages(page, i40e_rx_pg_order(rx_ring)); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 841 | rx_ring->rx_stats.alloc_page_failed++; |
| 842 | return false; |
| 843 | } |
| 844 | |
| 845 | bi->dma = dma; |
| 846 | bi->page = page; |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 847 | bi->page_offset = i40e_rx_offset(rx_ring); |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 848 | |
| 849 | /* initialize pagecnt_bias to 1 representing we fully own page */ |
Alexander Duyck | 1793668 | 2017-02-21 15:55:39 -0800 | [diff] [blame] | 850 | bi->pagecnt_bias = 1; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 851 | |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 852 | return true; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /** |
| 856 | * i40e_receive_skb - Send a completed packet up the stack |
| 857 | * @rx_ring: rx ring in play |
| 858 | * @skb: packet to send up |
| 859 | * @vlan_tag: vlan tag for packet |
| 860 | **/ |
| 861 | static void i40e_receive_skb(struct i40e_ring *rx_ring, |
| 862 | struct sk_buff *skb, u16 vlan_tag) |
| 863 | { |
| 864 | struct i40e_q_vector *q_vector = rx_ring->q_vector; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 865 | |
Jesse Brandeburg | a149f2c | 2016-04-12 08:30:49 -0700 | [diff] [blame] | 866 | if ((rx_ring->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
| 867 | (vlan_tag & VLAN_VID_MASK)) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 868 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tag); |
| 869 | |
Alexander Duyck | 8b65035 | 2015-09-24 09:04:32 -0700 | [diff] [blame] | 870 | napi_gro_receive(&q_vector->napi, skb); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /** |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 874 | * i40evf_alloc_rx_buffers - Replace used receive buffers |
| 875 | * @rx_ring: ring to place buffers on |
| 876 | * @cleaned_count: number of buffers to replace |
| 877 | * |
| 878 | * Returns false if all allocations were successful, true if any fail |
| 879 | **/ |
| 880 | bool i40evf_alloc_rx_buffers(struct i40e_ring *rx_ring, u16 cleaned_count) |
| 881 | { |
| 882 | u16 ntu = rx_ring->next_to_use; |
| 883 | union i40e_rx_desc *rx_desc; |
| 884 | struct i40e_rx_buffer *bi; |
| 885 | |
| 886 | /* do nothing if no valid netdev defined */ |
| 887 | if (!rx_ring->netdev || !cleaned_count) |
| 888 | return false; |
| 889 | |
| 890 | rx_desc = I40E_RX_DESC(rx_ring, ntu); |
| 891 | bi = &rx_ring->rx_bi[ntu]; |
| 892 | |
| 893 | do { |
| 894 | if (!i40e_alloc_mapped_page(rx_ring, bi)) |
| 895 | goto no_buffers; |
| 896 | |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 897 | /* sync the buffer for use by the device */ |
| 898 | dma_sync_single_range_for_device(rx_ring->dev, bi->dma, |
| 899 | bi->page_offset, |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 900 | rx_ring->rx_buf_len, |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 901 | DMA_FROM_DEVICE); |
| 902 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 903 | /* Refresh the desc even if buffer_addrs didn't change |
| 904 | * because each write-back erases this info. |
| 905 | */ |
| 906 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 907 | |
| 908 | rx_desc++; |
| 909 | bi++; |
| 910 | ntu++; |
| 911 | if (unlikely(ntu == rx_ring->count)) { |
| 912 | rx_desc = I40E_RX_DESC(rx_ring, 0); |
| 913 | bi = rx_ring->rx_bi; |
| 914 | ntu = 0; |
| 915 | } |
| 916 | |
| 917 | /* clear the status bits for the next_to_use descriptor */ |
| 918 | rx_desc->wb.qword1.status_error_len = 0; |
| 919 | |
| 920 | cleaned_count--; |
| 921 | } while (cleaned_count); |
| 922 | |
| 923 | if (rx_ring->next_to_use != ntu) |
| 924 | i40e_release_rx_desc(rx_ring, ntu); |
| 925 | |
| 926 | return false; |
| 927 | |
| 928 | no_buffers: |
| 929 | if (rx_ring->next_to_use != ntu) |
| 930 | i40e_release_rx_desc(rx_ring, ntu); |
| 931 | |
| 932 | /* make sure to come back via polling to try again after |
| 933 | * allocation failure |
| 934 | */ |
| 935 | return true; |
| 936 | } |
| 937 | |
| 938 | /** |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 939 | * i40e_rx_checksum - Indicate in skb if hw indicated a good cksum |
| 940 | * @vsi: the VSI we care about |
| 941 | * @skb: skb currently being received and modified |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 942 | * @rx_desc: the receive descriptor |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 943 | **/ |
| 944 | static inline void i40e_rx_checksum(struct i40e_vsi *vsi, |
| 945 | struct sk_buff *skb, |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 946 | union i40e_rx_desc *rx_desc) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 947 | { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 948 | struct i40e_rx_ptype_decoded decoded; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 949 | u32 rx_error, rx_status; |
Alexander Duyck | 858296c8 | 2016-06-14 15:45:42 -0700 | [diff] [blame] | 950 | bool ipv4, ipv6; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 951 | u8 ptype; |
| 952 | u64 qword; |
| 953 | |
| 954 | qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len); |
| 955 | ptype = (qword & I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT; |
| 956 | rx_error = (qword & I40E_RXD_QW1_ERROR_MASK) >> |
| 957 | I40E_RXD_QW1_ERROR_SHIFT; |
| 958 | rx_status = (qword & I40E_RXD_QW1_STATUS_MASK) >> |
| 959 | I40E_RXD_QW1_STATUS_SHIFT; |
| 960 | decoded = decode_rx_desc_ptype(ptype); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 961 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 962 | skb->ip_summed = CHECKSUM_NONE; |
| 963 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 964 | skb_checksum_none_assert(skb); |
| 965 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 966 | /* Rx csum enabled and ip headers found? */ |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 967 | if (!(vsi->netdev->features & NETIF_F_RXCSUM)) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 968 | return; |
| 969 | |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 970 | /* did the hardware decode the packet and checksum? */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 971 | if (!(rx_status & BIT(I40E_RX_DESC_STATUS_L3L4P_SHIFT))) |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 972 | return; |
| 973 | |
| 974 | /* both known and outer_ip must be set for the below code to work */ |
| 975 | if (!(decoded.known && decoded.outer_ip)) |
| 976 | return; |
| 977 | |
Alexander Duyck | fad5733 | 2016-01-24 21:17:22 -0800 | [diff] [blame] | 978 | ipv4 = (decoded.outer_ip == I40E_RX_PTYPE_OUTER_IP) && |
| 979 | (decoded.outer_ip_ver == I40E_RX_PTYPE_OUTER_IPV4); |
| 980 | ipv6 = (decoded.outer_ip == I40E_RX_PTYPE_OUTER_IP) && |
| 981 | (decoded.outer_ip_ver == I40E_RX_PTYPE_OUTER_IPV6); |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 982 | |
| 983 | if (ipv4 && |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 984 | (rx_error & (BIT(I40E_RX_DESC_ERROR_IPE_SHIFT) | |
| 985 | BIT(I40E_RX_DESC_ERROR_EIPE_SHIFT)))) |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 986 | goto checksum_fail; |
| 987 | |
Jesse Brandeburg | ddf1d0d | 2014-02-13 03:48:39 -0800 | [diff] [blame] | 988 | /* likely incorrect csum if alternate IP extension headers found */ |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 989 | if (ipv6 && |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 990 | rx_status & BIT(I40E_RX_DESC_STATUS_IPV6EXADD_SHIFT)) |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 991 | /* don't increment checksum err here, non-fatal err */ |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 992 | return; |
| 993 | |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 994 | /* there was some L4 error, count error and punt packet to the stack */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 995 | if (rx_error & BIT(I40E_RX_DESC_ERROR_L4E_SHIFT)) |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 996 | goto checksum_fail; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 997 | |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 998 | /* handle packets that were not able to be checksummed due |
| 999 | * to arrival speed, in this case the stack can compute |
| 1000 | * the csum. |
| 1001 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1002 | if (rx_error & BIT(I40E_RX_DESC_ERROR_PPRS_SHIFT)) |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 1003 | return; |
| 1004 | |
Alexander Duyck | 858296c8 | 2016-06-14 15:45:42 -0700 | [diff] [blame] | 1005 | /* Only report checksum unnecessary for TCP, UDP, or SCTP */ |
| 1006 | switch (decoded.inner_prot) { |
| 1007 | case I40E_RX_PTYPE_INNER_PROT_TCP: |
| 1008 | case I40E_RX_PTYPE_INNER_PROT_UDP: |
| 1009 | case I40E_RX_PTYPE_INNER_PROT_SCTP: |
| 1010 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1011 | /* fall though */ |
| 1012 | default: |
| 1013 | break; |
| 1014 | } |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 1015 | |
| 1016 | return; |
| 1017 | |
| 1018 | checksum_fail: |
| 1019 | vsi->back->hw_csum_rx_error++; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /** |
Anjali Singhai Jain | 857942f | 2015-12-09 15:50:21 -0800 | [diff] [blame] | 1023 | * i40e_ptype_to_htype - get a hash type |
Jesse Brandeburg | 206812b | 2014-02-12 01:45:33 +0000 | [diff] [blame] | 1024 | * @ptype: the ptype value from the descriptor |
| 1025 | * |
| 1026 | * Returns a hash type to be used by skb_set_hash |
| 1027 | **/ |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1028 | static inline int i40e_ptype_to_htype(u8 ptype) |
Jesse Brandeburg | 206812b | 2014-02-12 01:45:33 +0000 | [diff] [blame] | 1029 | { |
| 1030 | struct i40e_rx_ptype_decoded decoded = decode_rx_desc_ptype(ptype); |
| 1031 | |
| 1032 | if (!decoded.known) |
| 1033 | return PKT_HASH_TYPE_NONE; |
| 1034 | |
| 1035 | if (decoded.outer_ip == I40E_RX_PTYPE_OUTER_IP && |
| 1036 | decoded.payload_layer == I40E_RX_PTYPE_PAYLOAD_LAYER_PAY4) |
| 1037 | return PKT_HASH_TYPE_L4; |
| 1038 | else if (decoded.outer_ip == I40E_RX_PTYPE_OUTER_IP && |
| 1039 | decoded.payload_layer == I40E_RX_PTYPE_PAYLOAD_LAYER_PAY3) |
| 1040 | return PKT_HASH_TYPE_L3; |
| 1041 | else |
| 1042 | return PKT_HASH_TYPE_L2; |
| 1043 | } |
| 1044 | |
| 1045 | /** |
Anjali Singhai Jain | 857942f | 2015-12-09 15:50:21 -0800 | [diff] [blame] | 1046 | * i40e_rx_hash - set the hash value in the skb |
| 1047 | * @ring: descriptor ring |
| 1048 | * @rx_desc: specific descriptor |
| 1049 | **/ |
| 1050 | static inline void i40e_rx_hash(struct i40e_ring *ring, |
| 1051 | union i40e_rx_desc *rx_desc, |
| 1052 | struct sk_buff *skb, |
| 1053 | u8 rx_ptype) |
| 1054 | { |
| 1055 | u32 hash; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1056 | const __le64 rss_mask = |
Anjali Singhai Jain | 857942f | 2015-12-09 15:50:21 -0800 | [diff] [blame] | 1057 | cpu_to_le64((u64)I40E_RX_DESC_FLTSTAT_RSS_HASH << |
| 1058 | I40E_RX_DESC_STATUS_FLTSTAT_SHIFT); |
| 1059 | |
| 1060 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 1061 | return; |
| 1062 | |
| 1063 | if ((rx_desc->wb.qword1.status_error_len & rss_mask) == rss_mask) { |
| 1064 | hash = le32_to_cpu(rx_desc->wb.qword0.hi_dword.rss); |
| 1065 | skb_set_hash(skb, hash, i40e_ptype_to_htype(rx_ptype)); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | /** |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1070 | * i40evf_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1071 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1072 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1073 | * @skb: pointer to current skb being populated |
| 1074 | * @rx_ptype: the packet type decoded by hardware |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1075 | * |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1076 | * This function checks the ring, descriptor, and packet information in |
| 1077 | * order to populate the hash, checksum, VLAN, protocol, and |
| 1078 | * other fields within the skb. |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1079 | **/ |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1080 | static inline |
| 1081 | void i40evf_process_skb_fields(struct i40e_ring *rx_ring, |
| 1082 | union i40e_rx_desc *rx_desc, struct sk_buff *skb, |
| 1083 | u8 rx_ptype) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1084 | { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1085 | i40e_rx_hash(rx_ring, rx_desc, skb, rx_ptype); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1086 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1087 | i40e_rx_checksum(rx_ring->vsi, skb, rx_desc); |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1088 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1089 | skb_record_rx_queue(skb, rx_ring->queue_index); |
Alexander Duyck | a5b268e | 2017-02-21 15:55:46 -0800 | [diff] [blame] | 1090 | |
| 1091 | /* modifies the skb - consumes the enet header */ |
| 1092 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | /** |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1096 | * i40e_cleanup_headers - Correct empty headers |
| 1097 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1098 | * @skb: pointer to current skb being fixed |
| 1099 | * |
| 1100 | * Also address the case where we are pulling data in on pages only |
| 1101 | * and as such no data is present in the skb header. |
| 1102 | * |
| 1103 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1104 | * it is large enough to qualify as a valid Ethernet frame. |
| 1105 | * |
| 1106 | * Returns true if an error was encountered and skb was freed. |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1107 | **/ |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1108 | static bool i40e_cleanup_headers(struct i40e_ring *rx_ring, struct sk_buff *skb) |
| 1109 | { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1110 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1111 | if (eth_skb_pad(skb)) |
| 1112 | return true; |
| 1113 | |
| 1114 | return false; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * i40e_reuse_rx_page - page flip buffer and store it back on the ring |
| 1119 | * @rx_ring: rx descriptor ring to store buffers on |
| 1120 | * @old_buff: donor buffer to have page reused |
| 1121 | * |
| 1122 | * Synchronizes page for reuse by the adapter |
| 1123 | **/ |
| 1124 | static void i40e_reuse_rx_page(struct i40e_ring *rx_ring, |
| 1125 | struct i40e_rx_buffer *old_buff) |
| 1126 | { |
| 1127 | struct i40e_rx_buffer *new_buff; |
| 1128 | u16 nta = rx_ring->next_to_alloc; |
| 1129 | |
| 1130 | new_buff = &rx_ring->rx_bi[nta]; |
| 1131 | |
| 1132 | /* update, and store next to alloc */ |
| 1133 | nta++; |
| 1134 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1135 | |
| 1136 | /* transfer page from old buffer to new buffer */ |
Alexander Duyck | 1793668 | 2017-02-21 15:55:39 -0800 | [diff] [blame] | 1137 | new_buff->dma = old_buff->dma; |
| 1138 | new_buff->page = old_buff->page; |
| 1139 | new_buff->page_offset = old_buff->page_offset; |
| 1140 | new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | /** |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1144 | * i40e_page_is_reusable - check if any reuse is possible |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1145 | * @page: page struct to check |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1146 | * |
| 1147 | * A page is not reusable if it was allocated under low memory |
| 1148 | * conditions, or it's not in the same NUMA node as this CPU. |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1149 | */ |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1150 | static inline bool i40e_page_is_reusable(struct page *page) |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1151 | { |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1152 | return (page_to_nid(page) == numa_mem_id()) && |
| 1153 | !page_is_pfmemalloc(page); |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * i40e_can_reuse_rx_page - Determine if this page can be reused by |
| 1158 | * the adapter for another receive |
| 1159 | * |
| 1160 | * @rx_buffer: buffer containing the page |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1161 | * |
| 1162 | * If page is reusable, rx_buffer->page_offset is adjusted to point to |
| 1163 | * an unused region in the page. |
| 1164 | * |
| 1165 | * For small pages, @truesize will be a constant value, half the size |
| 1166 | * of the memory at page. We'll attempt to alternate between high and |
| 1167 | * low halves of the page, with one half ready for use by the hardware |
| 1168 | * and the other half being consumed by the stack. We use the page |
| 1169 | * ref count to determine whether the stack has finished consuming the |
| 1170 | * portion of this page that was passed up with a previous packet. If |
| 1171 | * the page ref count is >1, we'll assume the "other" half page is |
| 1172 | * still busy, and this page cannot be reused. |
| 1173 | * |
| 1174 | * For larger pages, @truesize will be the actual space used by the |
| 1175 | * received packet (adjusted upward to an even multiple of the cache |
| 1176 | * line size). This will advance through the page by the amount |
| 1177 | * actually consumed by the received packets while there is still |
| 1178 | * space for a buffer. Each region of larger pages will be used at |
| 1179 | * most once, after which the page will not be reused. |
| 1180 | * |
| 1181 | * In either case, if the page is reusable its refcount is increased. |
| 1182 | **/ |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1183 | static bool i40e_can_reuse_rx_page(struct i40e_rx_buffer *rx_buffer) |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1184 | { |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1185 | unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
| 1186 | struct page *page = rx_buffer->page; |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1187 | |
| 1188 | /* Is any reuse possible? */ |
| 1189 | if (unlikely(!i40e_page_is_reusable(page))) |
| 1190 | return false; |
| 1191 | |
| 1192 | #if (PAGE_SIZE < 8192) |
| 1193 | /* if we are only owner of page we can reuse it */ |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1194 | if (unlikely((page_count(page) - pagecnt_bias) > 1)) |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1195 | return false; |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1196 | #else |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 1197 | #define I40E_LAST_OFFSET \ |
| 1198 | (SKB_WITH_OVERHEAD(PAGE_SIZE) - I40E_RXBUFFER_2048) |
| 1199 | if (rx_buffer->page_offset > I40E_LAST_OFFSET) |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1200 | return false; |
| 1201 | #endif |
| 1202 | |
Alexander Duyck | 1793668 | 2017-02-21 15:55:39 -0800 | [diff] [blame] | 1203 | /* If we have drained the page fragment pool we need to update |
| 1204 | * the pagecnt_bias and page count so that we fully restock the |
| 1205 | * number of references the driver holds. |
| 1206 | */ |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1207 | if (unlikely(!pagecnt_bias)) { |
Alexander Duyck | 1793668 | 2017-02-21 15:55:39 -0800 | [diff] [blame] | 1208 | page_ref_add(page, USHRT_MAX); |
| 1209 | rx_buffer->pagecnt_bias = USHRT_MAX; |
| 1210 | } |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1211 | |
| 1212 | return true; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | /** |
| 1216 | * i40e_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1217 | * @rx_ring: rx descriptor ring to transact packets on |
| 1218 | * @rx_buffer: buffer containing page to add |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1219 | * @skb: sk_buff to place the data into |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1220 | * @size: packet length from rx_desc |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1221 | * |
| 1222 | * This function will add the data contained in rx_buffer->page to the skb. |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1223 | * It will just attach the page as a frag to the skb. |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1224 | * |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1225 | * The function will then update the page offset. |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1226 | **/ |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1227 | static void i40e_add_rx_frag(struct i40e_ring *rx_ring, |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1228 | struct i40e_rx_buffer *rx_buffer, |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1229 | struct sk_buff *skb, |
| 1230 | unsigned int size) |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1231 | { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1232 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 1233 | unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1234 | #else |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 1235 | unsigned int truesize = SKB_DATA_ALIGN(size + i40e_rx_offset(rx_ring)); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1236 | #endif |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1237 | |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1238 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, |
| 1239 | rx_buffer->page_offset, size, truesize); |
Scott Peterson | 9b37c93 | 2017-02-09 23:43:30 -0800 | [diff] [blame] | 1240 | |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1241 | /* page is being used so we must update the page offset */ |
| 1242 | #if (PAGE_SIZE < 8192) |
| 1243 | rx_buffer->page_offset ^= truesize; |
| 1244 | #else |
| 1245 | rx_buffer->page_offset += truesize; |
| 1246 | #endif |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | /** |
Alexander Duyck | 9a06412 | 2017-03-14 10:15:23 -0700 | [diff] [blame] | 1250 | * i40e_get_rx_buffer - Fetch Rx buffer and synchronize data for use |
| 1251 | * @rx_ring: rx descriptor ring to transact packets on |
| 1252 | * @size: size of buffer to add to skb |
| 1253 | * |
| 1254 | * This function will pull an Rx buffer from the ring and synchronize it |
| 1255 | * for use by the CPU. |
| 1256 | */ |
| 1257 | static struct i40e_rx_buffer *i40e_get_rx_buffer(struct i40e_ring *rx_ring, |
| 1258 | const unsigned int size) |
| 1259 | { |
| 1260 | struct i40e_rx_buffer *rx_buffer; |
| 1261 | |
| 1262 | rx_buffer = &rx_ring->rx_bi[rx_ring->next_to_clean]; |
| 1263 | prefetchw(rx_buffer->page); |
| 1264 | |
| 1265 | /* we are reusing so sync this buffer for CPU use */ |
| 1266 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1267 | rx_buffer->dma, |
| 1268 | rx_buffer->page_offset, |
| 1269 | size, |
| 1270 | DMA_FROM_DEVICE); |
| 1271 | |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1272 | /* We have pulled a buffer for use, so decrement pagecnt_bias */ |
| 1273 | rx_buffer->pagecnt_bias--; |
| 1274 | |
Alexander Duyck | 9a06412 | 2017-03-14 10:15:23 -0700 | [diff] [blame] | 1275 | return rx_buffer; |
| 1276 | } |
| 1277 | |
| 1278 | /** |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1279 | * i40e_construct_skb - Allocate skb and populate it |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1280 | * @rx_ring: rx descriptor ring to transact packets on |
Alexander Duyck | 9a06412 | 2017-03-14 10:15:23 -0700 | [diff] [blame] | 1281 | * @rx_buffer: rx buffer to pull data from |
Alexander Duyck | d57c0e0 | 2017-03-14 10:15:22 -0700 | [diff] [blame] | 1282 | * @size: size of buffer to add to skb |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1283 | * |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1284 | * This function allocates an skb. It then populates it with the page |
| 1285 | * data from the current receive descriptor, taking care to set up the |
| 1286 | * skb correctly. |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1287 | */ |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1288 | static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring, |
| 1289 | struct i40e_rx_buffer *rx_buffer, |
| 1290 | unsigned int size) |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1291 | { |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1292 | void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; |
| 1293 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 1294 | unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2; |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1295 | #else |
| 1296 | unsigned int truesize = SKB_DATA_ALIGN(size); |
| 1297 | #endif |
| 1298 | unsigned int headlen; |
| 1299 | struct sk_buff *skb; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1300 | |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1301 | /* prefetch first cache line of first page */ |
| 1302 | prefetch(va); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1303 | #if L1_CACHE_BYTES < 128 |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1304 | prefetch(va + L1_CACHE_BYTES); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1305 | #endif |
| 1306 | |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1307 | /* allocate a skb to store the frags */ |
| 1308 | skb = __napi_alloc_skb(&rx_ring->q_vector->napi, |
| 1309 | I40E_RX_HDR_SIZE, |
| 1310 | GFP_ATOMIC | __GFP_NOWARN); |
| 1311 | if (unlikely(!skb)) |
| 1312 | return NULL; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1313 | |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1314 | /* Determine available headroom for copy */ |
| 1315 | headlen = size; |
| 1316 | if (headlen > I40E_RX_HDR_SIZE) |
| 1317 | headlen = eth_get_headlen(va, I40E_RX_HDR_SIZE); |
| 1318 | |
| 1319 | /* align pull length to size of long to optimize memcpy performance */ |
| 1320 | memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long))); |
| 1321 | |
| 1322 | /* update all of the pointers */ |
| 1323 | size -= headlen; |
| 1324 | if (size) { |
| 1325 | skb_add_rx_frag(skb, 0, rx_buffer->page, |
| 1326 | rx_buffer->page_offset + headlen, |
| 1327 | size, truesize); |
| 1328 | |
| 1329 | /* buffer is used by skb, update page_offset */ |
| 1330 | #if (PAGE_SIZE < 8192) |
| 1331 | rx_buffer->page_offset ^= truesize; |
| 1332 | #else |
| 1333 | rx_buffer->page_offset += truesize; |
| 1334 | #endif |
| 1335 | } else { |
| 1336 | /* buffer is unused, reset bias back to rx_buffer */ |
| 1337 | rx_buffer->pagecnt_bias++; |
| 1338 | } |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1339 | |
| 1340 | return skb; |
| 1341 | } |
| 1342 | |
| 1343 | /** |
Alexander Duyck | f8b45b7 | 2017-04-05 07:51:03 -0400 | [diff] [blame] | 1344 | * i40e_build_skb - Build skb around an existing buffer |
| 1345 | * @rx_ring: Rx descriptor ring to transact packets on |
| 1346 | * @rx_buffer: Rx buffer to pull data from |
| 1347 | * @size: size of buffer to add to skb |
| 1348 | * |
| 1349 | * This function builds an skb around an existing Rx buffer, taking care |
| 1350 | * to set up the skb correctly and avoid any memcpy overhead. |
| 1351 | */ |
| 1352 | static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring, |
| 1353 | struct i40e_rx_buffer *rx_buffer, |
| 1354 | unsigned int size) |
| 1355 | { |
| 1356 | void *va = page_address(rx_buffer->page) + rx_buffer->page_offset; |
| 1357 | #if (PAGE_SIZE < 8192) |
| 1358 | unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2; |
| 1359 | #else |
Björn Töpel | 2aae918 | 2017-05-15 06:52:00 +0200 | [diff] [blame] | 1360 | unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
| 1361 | SKB_DATA_ALIGN(I40E_SKB_PAD + size); |
Alexander Duyck | f8b45b7 | 2017-04-05 07:51:03 -0400 | [diff] [blame] | 1362 | #endif |
| 1363 | struct sk_buff *skb; |
| 1364 | |
| 1365 | /* prefetch first cache line of first page */ |
| 1366 | prefetch(va); |
| 1367 | #if L1_CACHE_BYTES < 128 |
| 1368 | prefetch(va + L1_CACHE_BYTES); |
| 1369 | #endif |
| 1370 | /* build an skb around the page buffer */ |
| 1371 | skb = build_skb(va - I40E_SKB_PAD, truesize); |
| 1372 | if (unlikely(!skb)) |
| 1373 | return NULL; |
| 1374 | |
| 1375 | /* update pointers within the skb to store the data */ |
| 1376 | skb_reserve(skb, I40E_SKB_PAD); |
| 1377 | __skb_put(skb, size); |
| 1378 | |
| 1379 | /* buffer is used by skb, update page_offset */ |
| 1380 | #if (PAGE_SIZE < 8192) |
| 1381 | rx_buffer->page_offset ^= truesize; |
| 1382 | #else |
| 1383 | rx_buffer->page_offset += truesize; |
| 1384 | #endif |
| 1385 | |
| 1386 | return skb; |
| 1387 | } |
| 1388 | |
| 1389 | /** |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1390 | * i40e_put_rx_buffer - Clean up used buffer and either recycle or free |
| 1391 | * @rx_ring: rx descriptor ring to transact packets on |
| 1392 | * @rx_buffer: rx buffer to pull data from |
| 1393 | * |
| 1394 | * This function will clean up the contents of the rx_buffer. It will |
Alan Brady | 11a350c | 2017-12-29 08:48:33 -0500 | [diff] [blame] | 1395 | * either recycle the buffer or unmap it and free the associated resources. |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1396 | */ |
| 1397 | static void i40e_put_rx_buffer(struct i40e_ring *rx_ring, |
| 1398 | struct i40e_rx_buffer *rx_buffer) |
| 1399 | { |
| 1400 | if (i40e_can_reuse_rx_page(rx_buffer)) { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1401 | /* hand second half of page back to the ring */ |
| 1402 | i40e_reuse_rx_page(rx_ring, rx_buffer); |
| 1403 | rx_ring->rx_stats.page_reuse_count++; |
| 1404 | } else { |
| 1405 | /* we are not reusing the buffer so unmap it */ |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 1406 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
| 1407 | i40e_rx_pg_size(rx_ring), |
Alexander Duyck | 59605bc | 2017-01-30 12:29:35 -0800 | [diff] [blame] | 1408 | DMA_FROM_DEVICE, I40E_RX_DMA_ATTR); |
Alexander Duyck | 1793668 | 2017-02-21 15:55:39 -0800 | [diff] [blame] | 1409 | __page_frag_cache_drain(rx_buffer->page, |
| 1410 | rx_buffer->pagecnt_bias); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | /* clear contents of buffer_info */ |
| 1414 | rx_buffer->page = NULL; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /** |
| 1418 | * i40e_is_non_eop - process handling of non-EOP buffers |
| 1419 | * @rx_ring: Rx ring being processed |
| 1420 | * @rx_desc: Rx descriptor for current buffer |
| 1421 | * @skb: Current socket buffer containing buffer in progress |
| 1422 | * |
| 1423 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1424 | * this function exits returning false, otherwise it will place the |
| 1425 | * sk_buff in the next buffer to be chained and return true indicating |
| 1426 | * that this is in fact a non-EOP buffer. |
| 1427 | **/ |
| 1428 | static bool i40e_is_non_eop(struct i40e_ring *rx_ring, |
| 1429 | union i40e_rx_desc *rx_desc, |
| 1430 | struct sk_buff *skb) |
| 1431 | { |
| 1432 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1433 | |
| 1434 | /* fetch, update, and store next to clean */ |
| 1435 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1436 | rx_ring->next_to_clean = ntc; |
| 1437 | |
| 1438 | prefetch(I40E_RX_DESC(rx_ring, ntc)); |
| 1439 | |
| 1440 | /* if we are the last buffer then there is nothing else to do */ |
| 1441 | #define I40E_RXD_EOF BIT(I40E_RX_DESC_STATUS_EOF_SHIFT) |
| 1442 | if (likely(i40e_test_staterr(rx_desc, I40E_RXD_EOF))) |
| 1443 | return false; |
| 1444 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1445 | rx_ring->rx_stats.non_eop_descs++; |
| 1446 | |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
| 1450 | /** |
| 1451 | * i40e_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1452 | * @rx_ring: rx descriptor ring to transact packets on |
| 1453 | * @budget: Total limit on number of packets to process |
| 1454 | * |
| 1455 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1456 | * processing. The advantage to this is that on systems that have |
| 1457 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1458 | * it by maintaining the mapping of the page to the system. |
| 1459 | * |
| 1460 | * Returns amount of work completed |
| 1461 | **/ |
| 1462 | static int i40e_clean_rx_irq(struct i40e_ring *rx_ring, int budget) |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1463 | { |
| 1464 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Scott Peterson | e72e565 | 2017-02-09 23:40:25 -0800 | [diff] [blame] | 1465 | struct sk_buff *skb = rx_ring->skb; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1466 | u16 cleaned_count = I40E_DESC_UNUSED(rx_ring); |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 1467 | bool failure = false; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1468 | |
Jesse Brandeburg | b85c94b | 2017-06-20 15:16:59 -0700 | [diff] [blame] | 1469 | while (likely(total_rx_packets < (unsigned int)budget)) { |
Alexander Duyck | 9a06412 | 2017-03-14 10:15:23 -0700 | [diff] [blame] | 1470 | struct i40e_rx_buffer *rx_buffer; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1471 | union i40e_rx_desc *rx_desc; |
Alexander Duyck | d57c0e0 | 2017-03-14 10:15:22 -0700 | [diff] [blame] | 1472 | unsigned int size; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1473 | u16 vlan_tag; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1474 | u8 rx_ptype; |
| 1475 | u64 qword; |
| 1476 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1477 | /* return some buffers to hardware, one at a time is too slow */ |
| 1478 | if (cleaned_count >= I40E_RX_BUFFER_WRITE) { |
Jesse Brandeburg | c2e245a | 2016-01-13 16:51:46 -0800 | [diff] [blame] | 1479 | failure = failure || |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1480 | i40evf_alloc_rx_buffers(rx_ring, cleaned_count); |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1481 | cleaned_count = 0; |
| 1482 | } |
| 1483 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1484 | rx_desc = I40E_RX_DESC(rx_ring, rx_ring->next_to_clean); |
| 1485 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1486 | /* status_error_len will always be zero for unused descriptors |
| 1487 | * because it's cleared in cleanup, and overlaps with hdr_addr |
| 1488 | * which is always zero because packet split isn't used, if the |
Alexander Duyck | d57c0e0 | 2017-03-14 10:15:22 -0700 | [diff] [blame] | 1489 | * hardware wrote DD then the length will be non-zero |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1490 | */ |
Alexander Duyck | d57c0e0 | 2017-03-14 10:15:22 -0700 | [diff] [blame] | 1491 | qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len); |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1492 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1493 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | d57c0e0 | 2017-03-14 10:15:22 -0700 | [diff] [blame] | 1494 | * any other fields out of the rx_desc until we have |
| 1495 | * verified the descriptor has been written back. |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1496 | */ |
Alexander Duyck | 6731716 | 2015-04-08 18:49:43 -0700 | [diff] [blame] | 1497 | dma_rmb(); |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1498 | |
Alexander Duyck | 0e626ff | 2017-04-10 05:18:43 -0400 | [diff] [blame] | 1499 | size = (qword & I40E_RXD_QW1_LENGTH_PBUF_MASK) >> |
| 1500 | I40E_RXD_QW1_LENGTH_PBUF_SHIFT; |
| 1501 | if (!size) |
| 1502 | break; |
| 1503 | |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 1504 | i40e_trace(clean_rx_irq, rx_ring, rx_desc, skb); |
Alexander Duyck | 9a06412 | 2017-03-14 10:15:23 -0700 | [diff] [blame] | 1505 | rx_buffer = i40e_get_rx_buffer(rx_ring, size); |
| 1506 | |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1507 | /* retrieve a buffer from the ring */ |
| 1508 | if (skb) |
| 1509 | i40e_add_rx_frag(rx_ring, rx_buffer, skb, size); |
Alexander Duyck | f8b45b7 | 2017-04-05 07:51:03 -0400 | [diff] [blame] | 1510 | else if (ring_uses_build_skb(rx_ring)) |
| 1511 | skb = i40e_build_skb(rx_ring, rx_buffer, size); |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1512 | else |
| 1513 | skb = i40e_construct_skb(rx_ring, rx_buffer, size); |
| 1514 | |
| 1515 | /* exit if we failed to retrieve a buffer */ |
| 1516 | if (!skb) { |
| 1517 | rx_ring->rx_stats.alloc_buff_failed++; |
| 1518 | rx_buffer->pagecnt_bias++; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1519 | break; |
Alexander Duyck | fa2343e | 2017-03-14 10:15:25 -0700 | [diff] [blame] | 1520 | } |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1521 | |
Alexander Duyck | a0cfc31 | 2017-03-14 10:15:24 -0700 | [diff] [blame] | 1522 | i40e_put_rx_buffer(rx_ring, rx_buffer); |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1523 | cleaned_count++; |
| 1524 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1525 | if (i40e_is_non_eop(rx_ring, rx_desc, skb)) |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1526 | continue; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1527 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1528 | /* ERR_MASK will only have valid bits if EOP set, and |
| 1529 | * what we are doing here is actually checking |
| 1530 | * I40E_RX_DESC_ERROR_RXE_SHIFT, since it is the zeroth bit in |
| 1531 | * the error field |
| 1532 | */ |
| 1533 | if (unlikely(i40e_test_staterr(rx_desc, BIT(I40E_RXD_QW1_ERROR_SHIFT)))) { |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1534 | dev_kfree_skb_any(skb); |
Alexander Duyck | 741b8b8 | 2017-02-21 15:55:41 -0800 | [diff] [blame] | 1535 | skb = NULL; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1536 | continue; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Scott Peterson | e72e565 | 2017-02-09 23:40:25 -0800 | [diff] [blame] | 1539 | if (i40e_cleanup_headers(rx_ring, skb)) { |
| 1540 | skb = NULL; |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1541 | continue; |
Scott Peterson | e72e565 | 2017-02-09 23:40:25 -0800 | [diff] [blame] | 1542 | } |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1543 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1544 | /* probably a little skewed due to removing CRC */ |
| 1545 | total_rx_bytes += skb->len; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1546 | |
Alexander Duyck | 99dad8b | 2016-09-27 11:28:50 -0700 | [diff] [blame] | 1547 | qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len); |
| 1548 | rx_ptype = (qword & I40E_RXD_QW1_PTYPE_MASK) >> |
| 1549 | I40E_RXD_QW1_PTYPE_SHIFT; |
| 1550 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1551 | /* populate checksum, VLAN, and protocol */ |
| 1552 | i40evf_process_skb_fields(rx_ring, rx_desc, skb, rx_ptype); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1553 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1554 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1555 | vlan_tag = (qword & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) ? |
| 1556 | le16_to_cpu(rx_desc->wb.qword0.lo_dword.l2tag1) : 0; |
| 1557 | |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 1558 | i40e_trace(clean_rx_irq_rx, rx_ring, rx_desc, skb); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1559 | i40e_receive_skb(rx_ring, skb, vlan_tag); |
Scott Peterson | e72e565 | 2017-02-09 23:40:25 -0800 | [diff] [blame] | 1560 | skb = NULL; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1561 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1562 | /* update budget accounting */ |
| 1563 | total_rx_packets++; |
| 1564 | } |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1565 | |
Scott Peterson | e72e565 | 2017-02-09 23:40:25 -0800 | [diff] [blame] | 1566 | rx_ring->skb = skb; |
| 1567 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1568 | u64_stats_update_begin(&rx_ring->syncp); |
| 1569 | rx_ring->stats.packets += total_rx_packets; |
| 1570 | rx_ring->stats.bytes += total_rx_bytes; |
| 1571 | u64_stats_update_end(&rx_ring->syncp); |
| 1572 | rx_ring->q_vector->rx.total_packets += total_rx_packets; |
| 1573 | rx_ring->q_vector->rx.total_bytes += total_rx_bytes; |
| 1574 | |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1575 | /* guarantee a trip back through this routine if there was a failure */ |
Jesse Brandeburg | b85c94b | 2017-06-20 15:16:59 -0700 | [diff] [blame] | 1576 | return failure ? budget : (int)total_rx_packets; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Alexander Duyck | 92418fb | 2017-12-29 08:51:08 -0500 | [diff] [blame] | 1579 | static inline u32 i40e_buildreg_itr(const int type, u16 itr) |
Jesse Brandeburg | 8f5e39c | 2015-09-28 14:16:51 -0400 | [diff] [blame] | 1580 | { |
| 1581 | u32 val; |
| 1582 | |
Alexander Duyck | 4ff1792 | 2017-12-29 08:50:55 -0500 | [diff] [blame] | 1583 | /* We don't bother with setting the CLEARPBA bit as the data sheet |
| 1584 | * points out doing so is "meaningless since it was already |
| 1585 | * auto-cleared". The auto-clearing happens when the interrupt is |
| 1586 | * asserted. |
| 1587 | * |
| 1588 | * Hardware errata 28 for also indicates that writing to a |
| 1589 | * xxINT_DYN_CTLx CSR with INTENA_MSK (bit 31) set to 0 will clear |
| 1590 | * an event in the PBA anyway so we need to rely on the automask |
| 1591 | * to hold pending events for us until the interrupt is re-enabled |
Alexander Duyck | 92418fb | 2017-12-29 08:51:08 -0500 | [diff] [blame] | 1592 | * |
| 1593 | * The itr value is reported in microseconds, and the register |
| 1594 | * value is recorded in 2 microsecond units. For this reason we |
| 1595 | * only need to shift by the interval shift - 1 instead of the |
| 1596 | * full value. |
Alexander Duyck | 4ff1792 | 2017-12-29 08:50:55 -0500 | [diff] [blame] | 1597 | */ |
Alexander Duyck | 92418fb | 2017-12-29 08:51:08 -0500 | [diff] [blame] | 1598 | itr &= I40E_ITR_MASK; |
| 1599 | |
Jesse Brandeburg | 8f5e39c | 2015-09-28 14:16:51 -0400 | [diff] [blame] | 1600 | val = I40E_VFINT_DYN_CTLN1_INTENA_MASK | |
Jesse Brandeburg | 8f5e39c | 2015-09-28 14:16:51 -0400 | [diff] [blame] | 1601 | (type << I40E_VFINT_DYN_CTLN1_ITR_INDX_SHIFT) | |
Alexander Duyck | 92418fb | 2017-12-29 08:51:08 -0500 | [diff] [blame] | 1602 | (itr << (I40E_VFINT_DYN_CTLN1_INTERVAL_SHIFT - 1)); |
Jesse Brandeburg | 8f5e39c | 2015-09-28 14:16:51 -0400 | [diff] [blame] | 1603 | |
| 1604 | return val; |
| 1605 | } |
| 1606 | |
| 1607 | /* a small macro to shorten up some long lines */ |
| 1608 | #define INTREG I40E_VFINT_DYN_CTLN1 |
| 1609 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1610 | /* The act of updating the ITR will cause it to immediately trigger. In order |
| 1611 | * to prevent this from throwing off adaptive update statistics we defer the |
| 1612 | * update so that it can only happen so often. So after either Tx or Rx are |
| 1613 | * updated we make the adaptive scheme wait until either the ITR completely |
| 1614 | * expires via the next_update expiration or we have been through at least |
| 1615 | * 3 interrupts. |
| 1616 | */ |
| 1617 | #define ITR_COUNTDOWN_START 3 |
| 1618 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1619 | /** |
Carolyn Wyborny | de32e3e | 2015-06-10 13:42:07 -0400 | [diff] [blame] | 1620 | * i40e_update_enable_itr - Update itr and re-enable MSIX interrupt |
| 1621 | * @vsi: the VSI we care about |
| 1622 | * @q_vector: q_vector for which itr is being updated and interrupt enabled |
| 1623 | * |
| 1624 | **/ |
| 1625 | static inline void i40e_update_enable_itr(struct i40e_vsi *vsi, |
| 1626 | struct i40e_q_vector *q_vector) |
| 1627 | { |
| 1628 | struct i40e_hw *hw = &vsi->back->hw; |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1629 | u32 intval; |
Jesse Brandeburg | 8f5e39c | 2015-09-28 14:16:51 -0400 | [diff] [blame] | 1630 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1631 | /* These will do nothing if dynamic updates are not enabled */ |
| 1632 | i40e_update_itr(q_vector, &q_vector->tx); |
| 1633 | i40e_update_itr(q_vector, &q_vector->rx); |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 1634 | |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1635 | /* This block of logic allows us to get away with only updating |
| 1636 | * one ITR value with each interrupt. The idea is to perform a |
| 1637 | * pseudo-lazy update with the following criteria. |
| 1638 | * |
| 1639 | * 1. Rx is given higher priority than Tx if both are in same state |
| 1640 | * 2. If we must reduce an ITR that is given highest priority. |
| 1641 | * 3. We then give priority to increasing ITR based on amount. |
| 1642 | */ |
| 1643 | if (q_vector->rx.target_itr < q_vector->rx.current_itr) { |
| 1644 | /* Rx ITR needs to be reduced, this is highest priority */ |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1645 | intval = i40e_buildreg_itr(I40E_RX_ITR, |
| 1646 | q_vector->rx.target_itr); |
| 1647 | q_vector->rx.current_itr = q_vector->rx.target_itr; |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1648 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
| 1649 | } else if ((q_vector->tx.target_itr < q_vector->tx.current_itr) || |
| 1650 | ((q_vector->rx.target_itr - q_vector->rx.current_itr) < |
| 1651 | (q_vector->tx.target_itr - q_vector->tx.current_itr))) { |
| 1652 | /* Tx ITR needs to be reduced, this is second priority |
| 1653 | * Tx ITR needs to be increased more than Rx, fourth priority |
| 1654 | */ |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1655 | intval = i40e_buildreg_itr(I40E_TX_ITR, |
| 1656 | q_vector->tx.target_itr); |
| 1657 | q_vector->tx.current_itr = q_vector->tx.target_itr; |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1658 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
| 1659 | } else if (q_vector->rx.current_itr != q_vector->rx.target_itr) { |
| 1660 | /* Rx ITR needs to be increased, third priority */ |
| 1661 | intval = i40e_buildreg_itr(I40E_RX_ITR, |
| 1662 | q_vector->rx.target_itr); |
| 1663 | q_vector->rx.current_itr = q_vector->rx.target_itr; |
| 1664 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1665 | } else { |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1666 | /* No ITR update, lowest priority */ |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1667 | intval = i40e_buildreg_itr(I40E_ITR_NONE, 0); |
Alexander Duyck | a0073a4 | 2017-12-29 08:52:19 -0500 | [diff] [blame] | 1668 | if (q_vector->itr_countdown) |
| 1669 | q_vector->itr_countdown--; |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1670 | } |
| 1671 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1672 | if (!test_bit(__I40E_VSI_DOWN, vsi->state)) |
Alexander Duyck | 556fdfd | 2017-12-29 08:51:25 -0500 | [diff] [blame] | 1673 | wr32(hw, INTREG(q_vector->reg_idx), intval); |
Carolyn Wyborny | de32e3e | 2015-06-10 13:42:07 -0400 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | /** |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1677 | * i40evf_napi_poll - NAPI polling Rx/Tx cleanup routine |
| 1678 | * @napi: napi struct with our devices info in it |
| 1679 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1680 | * |
| 1681 | * This function will clean all queues associated with a q_vector. |
| 1682 | * |
| 1683 | * Returns the amount of work done |
| 1684 | **/ |
| 1685 | int i40evf_napi_poll(struct napi_struct *napi, int budget) |
| 1686 | { |
| 1687 | struct i40e_q_vector *q_vector = |
| 1688 | container_of(napi, struct i40e_q_vector, napi); |
| 1689 | struct i40e_vsi *vsi = q_vector->vsi; |
| 1690 | struct i40e_ring *ring; |
| 1691 | bool clean_complete = true; |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 1692 | bool arm_wb = false; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1693 | int budget_per_ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 1694 | int work_done = 0; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1695 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1696 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) { |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1697 | napi_complete(napi); |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
| 1701 | /* Since the actual Tx work is minimal, we can give the Tx a larger |
| 1702 | * budget and be more aggressive about cleaning up the Tx descriptors. |
| 1703 | */ |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 1704 | i40e_for_each_ring(ring, q_vector->tx) { |
Alexander Duyck | a619afe | 2016-03-07 09:30:03 -0800 | [diff] [blame] | 1705 | if (!i40e_clean_tx_irq(vsi, ring, budget)) { |
Alexander Duyck | f2edaaa | 2016-03-07 09:29:57 -0800 | [diff] [blame] | 1706 | clean_complete = false; |
| 1707 | continue; |
| 1708 | } |
| 1709 | arm_wb |= ring->arm_wb; |
Jesse Brandeburg | 0deda86 | 2015-07-23 16:54:34 -0400 | [diff] [blame] | 1710 | ring->arm_wb = false; |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 1711 | } |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1712 | |
Alexander Duyck | c67cace | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1713 | /* Handle case where we are called by netpoll with a budget of 0 */ |
| 1714 | if (budget <= 0) |
| 1715 | goto tx_only; |
| 1716 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1717 | /* We attempt to distribute budget to each Rx queue fairly, but don't |
| 1718 | * allow the budget to go below 1 because that would exit polling early. |
| 1719 | */ |
| 1720 | budget_per_ring = max(budget/q_vector->num_ringpairs, 1); |
| 1721 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1722 | i40e_for_each_ring(ring, q_vector->rx) { |
Jesse Brandeburg | ab9ad98 | 2016-04-18 11:33:46 -0700 | [diff] [blame] | 1723 | int cleaned = i40e_clean_rx_irq(ring, budget_per_ring); |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 1724 | |
| 1725 | work_done += cleaned; |
Alexander Duyck | f2edaaa | 2016-03-07 09:29:57 -0800 | [diff] [blame] | 1726 | /* if we clean as many as budgeted, we must not be done */ |
| 1727 | if (cleaned >= budget_per_ring) |
| 1728 | clean_complete = false; |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 1729 | } |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1730 | |
| 1731 | /* If work not completed, return budget and polling will return */ |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 1732 | if (!clean_complete) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 1733 | int cpu_id = smp_processor_id(); |
| 1734 | |
| 1735 | /* It is possible that the interrupt affinity has changed but, |
| 1736 | * if the cpu is pegged at 100%, polling will never exit while |
| 1737 | * traffic continues and the interrupt will be stuck on this |
| 1738 | * cpu. We check to make sure affinity is correct before we |
| 1739 | * continue to poll, otherwise we must stop polling so the |
| 1740 | * interrupt can move to the correct cpu. |
| 1741 | */ |
Jacob Keller | 6d97772 | 2017-07-14 09:10:11 -0400 | [diff] [blame] | 1742 | if (!cpumask_test_cpu(cpu_id, &q_vector->affinity_mask)) { |
| 1743 | /* Tell napi that we are done polling */ |
| 1744 | napi_complete_done(napi, work_done); |
| 1745 | |
| 1746 | /* Force an interrupt */ |
| 1747 | i40evf_force_wb(vsi, q_vector); |
| 1748 | |
| 1749 | /* Return budget-1 so that polling stops */ |
| 1750 | return budget - 1; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 1751 | } |
Jacob Keller | 6d97772 | 2017-07-14 09:10:11 -0400 | [diff] [blame] | 1752 | tx_only: |
| 1753 | if (arm_wb) { |
| 1754 | q_vector->tx.ring[0].tx_stats.tx_force_wb++; |
| 1755 | i40e_enable_wb_on_itr(vsi, q_vector); |
| 1756 | } |
| 1757 | return budget; |
Anjali Singhai Jain | c29af37 | 2015-01-10 01:07:19 +0000 | [diff] [blame] | 1758 | } |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1759 | |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 1760 | if (vsi->back->flags & I40E_TXR_FLAGS_WB_ON_ITR) |
| 1761 | q_vector->arm_wb_state = false; |
| 1762 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1763 | /* Work is done so exit the polling mode and re-enable the interrupt */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 1764 | napi_complete_done(napi, work_done); |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 1765 | |
Jacob Keller | 6d97772 | 2017-07-14 09:10:11 -0400 | [diff] [blame] | 1766 | i40e_update_enable_itr(vsi, q_vector); |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 1767 | |
Alexander Duyck | 6beb84a | 2016-11-08 13:05:16 -0800 | [diff] [blame] | 1768 | return min(work_done, budget - 1); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | /** |
Jesse Brandeburg | 3e587cf | 2015-04-16 20:06:10 -0400 | [diff] [blame] | 1772 | * i40evf_tx_prepare_vlan_flags - prepare generic TX VLAN tagging flags for HW |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1773 | * @skb: send buffer |
| 1774 | * @tx_ring: ring to send buffer on |
| 1775 | * @flags: the tx flags to be set |
| 1776 | * |
| 1777 | * Checks the skb and set up correspondingly several generic transmit flags |
| 1778 | * related to VLAN tagging for the HW, such as VLAN, DCB, etc. |
| 1779 | * |
| 1780 | * Returns error code indicate the frame should be dropped upon error and the |
| 1781 | * otherwise returns 0 to indicate the flags has been set properly. |
| 1782 | **/ |
Jesse Brandeburg | 3e587cf | 2015-04-16 20:06:10 -0400 | [diff] [blame] | 1783 | static inline int i40evf_tx_prepare_vlan_flags(struct sk_buff *skb, |
| 1784 | struct i40e_ring *tx_ring, |
| 1785 | u32 *flags) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1786 | { |
| 1787 | __be16 protocol = skb->protocol; |
| 1788 | u32 tx_flags = 0; |
| 1789 | |
Greg Rose | 31eaacc | 2015-03-31 00:45:03 -0700 | [diff] [blame] | 1790 | if (protocol == htons(ETH_P_8021Q) && |
| 1791 | !(tx_ring->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)) { |
| 1792 | /* When HW VLAN acceleration is turned off by the user the |
| 1793 | * stack sets the protocol to 8021q so that the driver |
| 1794 | * can take any steps required to support the SW only |
| 1795 | * VLAN handling. In our case the driver doesn't need |
| 1796 | * to take any further steps so just set the protocol |
| 1797 | * to the encapsulated ethertype. |
| 1798 | */ |
| 1799 | skb->protocol = vlan_get_protocol(skb); |
| 1800 | goto out; |
| 1801 | } |
| 1802 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1803 | /* if we have a HW VLAN tag being added, default to the HW one */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1804 | if (skb_vlan_tag_present(skb)) { |
| 1805 | tx_flags |= skb_vlan_tag_get(skb) << I40E_TX_FLAGS_VLAN_SHIFT; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1806 | tx_flags |= I40E_TX_FLAGS_HW_VLAN; |
| 1807 | /* else if it is a SW VLAN, check the next protocol and store the tag */ |
| 1808 | } else if (protocol == htons(ETH_P_8021Q)) { |
| 1809 | struct vlan_hdr *vhdr, _vhdr; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1810 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1811 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 1812 | if (!vhdr) |
| 1813 | return -EINVAL; |
| 1814 | |
| 1815 | protocol = vhdr->h_vlan_encapsulated_proto; |
| 1816 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << I40E_TX_FLAGS_VLAN_SHIFT; |
| 1817 | tx_flags |= I40E_TX_FLAGS_SW_VLAN; |
| 1818 | } |
| 1819 | |
Greg Rose | 31eaacc | 2015-03-31 00:45:03 -0700 | [diff] [blame] | 1820 | out: |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1821 | *flags = tx_flags; |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * i40e_tso - set up the tso context descriptor |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 1827 | * @first: pointer to first Tx buffer for xmit |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1828 | * @hdr_len: ptr to the size of the packet header |
Shannon Nelson | 9c883bd | 2015-10-21 19:47:02 -0400 | [diff] [blame] | 1829 | * @cd_type_cmd_tso_mss: Quad Word 1 |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1830 | * |
| 1831 | * Returns 0 if no TSO can happen, 1 if tso is going, or error |
| 1832 | **/ |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 1833 | static int i40e_tso(struct i40e_tx_buffer *first, u8 *hdr_len, |
| 1834 | u64 *cd_type_cmd_tso_mss) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1835 | { |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 1836 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 03f9d6a | 2016-01-24 21:16:20 -0800 | [diff] [blame] | 1837 | u64 cd_cmd, cd_tso_len, cd_mss; |
Alexander Duyck | c777019 | 2016-01-24 21:16:35 -0800 | [diff] [blame] | 1838 | union { |
| 1839 | struct iphdr *v4; |
| 1840 | struct ipv6hdr *v6; |
| 1841 | unsigned char *hdr; |
| 1842 | } ip; |
Alexander Duyck | c49a7bc | 2016-01-24 21:16:28 -0800 | [diff] [blame] | 1843 | union { |
| 1844 | struct tcphdr *tcp; |
Alexander Duyck | 5453205 | 2016-01-24 21:17:29 -0800 | [diff] [blame] | 1845 | struct udphdr *udp; |
Alexander Duyck | c49a7bc | 2016-01-24 21:16:28 -0800 | [diff] [blame] | 1846 | unsigned char *hdr; |
| 1847 | } l4; |
| 1848 | u32 paylen, l4_offset; |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 1849 | u16 gso_segs, gso_size; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1850 | int err; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1851 | |
Shannon Nelson | e9f6563 | 2016-01-04 10:33:04 -0800 | [diff] [blame] | 1852 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1853 | return 0; |
| 1854 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1855 | if (!skb_is_gso(skb)) |
| 1856 | return 0; |
| 1857 | |
Francois Romieu | fe6d4aa | 2014-03-30 03:14:53 +0000 | [diff] [blame] | 1858 | err = skb_cow_head(skb, 0); |
| 1859 | if (err < 0) |
| 1860 | return err; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1861 | |
Alexander Duyck | c777019 | 2016-01-24 21:16:35 -0800 | [diff] [blame] | 1862 | ip.hdr = skb_network_header(skb); |
| 1863 | l4.hdr = skb_transport_header(skb); |
Anjali Singhai | 85e76d0 | 2015-02-21 06:44:16 +0000 | [diff] [blame] | 1864 | |
Alexander Duyck | c777019 | 2016-01-24 21:16:35 -0800 | [diff] [blame] | 1865 | /* initialize outer IP header fields */ |
| 1866 | if (ip.v4->version == 4) { |
| 1867 | ip.v4->tot_len = 0; |
| 1868 | ip.v4->check = 0; |
Alexander Duyck | c49a7bc | 2016-01-24 21:16:28 -0800 | [diff] [blame] | 1869 | } else { |
Alexander Duyck | c777019 | 2016-01-24 21:16:35 -0800 | [diff] [blame] | 1870 | ip.v6->payload_len = 0; |
| 1871 | } |
| 1872 | |
Alexander Duyck | 577389a | 2016-04-02 00:06:56 -0700 | [diff] [blame] | 1873 | if (skb_shinfo(skb)->gso_type & (SKB_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 1874 | SKB_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 1875 | SKB_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 1876 | SKB_GSO_IPXIP6 | |
Alexander Duyck | 577389a | 2016-04-02 00:06:56 -0700 | [diff] [blame] | 1877 | SKB_GSO_UDP_TUNNEL | |
Alexander Duyck | 5453205 | 2016-01-24 21:17:29 -0800 | [diff] [blame] | 1878 | SKB_GSO_UDP_TUNNEL_CSUM)) { |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 1879 | if (!(skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) && |
| 1880 | (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM)) { |
| 1881 | l4.udp->len = 0; |
| 1882 | |
Alexander Duyck | 5453205 | 2016-01-24 21:17:29 -0800 | [diff] [blame] | 1883 | /* determine offset of outer transport header */ |
| 1884 | l4_offset = l4.hdr - skb->data; |
| 1885 | |
| 1886 | /* remove payload length from outer checksum */ |
Alexander Duyck | 24d41e5 | 2016-03-18 16:06:47 -0700 | [diff] [blame] | 1887 | paylen = skb->len - l4_offset; |
Jacob Keller | b9c015d | 2016-12-12 15:44:17 -0800 | [diff] [blame] | 1888 | csum_replace_by_diff(&l4.udp->check, |
| 1889 | (__force __wsum)htonl(paylen)); |
Alexander Duyck | 5453205 | 2016-01-24 21:17:29 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
Alexander Duyck | c777019 | 2016-01-24 21:16:35 -0800 | [diff] [blame] | 1892 | /* reset pointers to inner headers */ |
| 1893 | ip.hdr = skb_inner_network_header(skb); |
| 1894 | l4.hdr = skb_inner_transport_header(skb); |
| 1895 | |
| 1896 | /* initialize inner IP header fields */ |
| 1897 | if (ip.v4->version == 4) { |
| 1898 | ip.v4->tot_len = 0; |
| 1899 | ip.v4->check = 0; |
| 1900 | } else { |
| 1901 | ip.v6->payload_len = 0; |
| 1902 | } |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Alexander Duyck | c49a7bc | 2016-01-24 21:16:28 -0800 | [diff] [blame] | 1905 | /* determine offset of inner transport header */ |
| 1906 | l4_offset = l4.hdr - skb->data; |
| 1907 | |
| 1908 | /* remove payload length from inner checksum */ |
Alexander Duyck | 24d41e5 | 2016-03-18 16:06:47 -0700 | [diff] [blame] | 1909 | paylen = skb->len - l4_offset; |
Jacob Keller | b9c015d | 2016-12-12 15:44:17 -0800 | [diff] [blame] | 1910 | csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen)); |
Alexander Duyck | c49a7bc | 2016-01-24 21:16:28 -0800 | [diff] [blame] | 1911 | |
| 1912 | /* compute length of segmentation header */ |
| 1913 | *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1914 | |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 1915 | /* pull values out of skb_shinfo */ |
| 1916 | gso_size = skb_shinfo(skb)->gso_size; |
| 1917 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 1918 | |
| 1919 | /* update GSO size and bytecount with header size */ |
| 1920 | first->gso_segs = gso_segs; |
| 1921 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 1922 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1923 | /* find the field values */ |
| 1924 | cd_cmd = I40E_TX_CTX_DESC_TSO; |
| 1925 | cd_tso_len = skb->len - *hdr_len; |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 1926 | cd_mss = gso_size; |
Alexander Duyck | 03f9d6a | 2016-01-24 21:16:20 -0800 | [diff] [blame] | 1927 | *cd_type_cmd_tso_mss |= (cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) | |
| 1928 | (cd_tso_len << I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) | |
| 1929 | (cd_mss << I40E_TXD_CTX_QW1_MSS_SHIFT); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1930 | return 1; |
| 1931 | } |
| 1932 | |
| 1933 | /** |
| 1934 | * i40e_tx_enable_csum - Enable Tx checksum offloads |
| 1935 | * @skb: send buffer |
Anjali Singhai Jain | 89232c3 | 2015-04-16 20:06:00 -0400 | [diff] [blame] | 1936 | * @tx_flags: pointer to Tx flags currently set |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1937 | * @td_cmd: Tx descriptor command bits to set |
| 1938 | * @td_offset: Tx descriptor header offsets to set |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 1939 | * @tx_ring: Tx descriptor ring |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1940 | * @cd_tunneling: ptr to context desc bits |
| 1941 | **/ |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 1942 | static int i40e_tx_enable_csum(struct sk_buff *skb, u32 *tx_flags, |
| 1943 | u32 *td_cmd, u32 *td_offset, |
| 1944 | struct i40e_ring *tx_ring, |
| 1945 | u32 *cd_tunneling) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1946 | { |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 1947 | union { |
| 1948 | struct iphdr *v4; |
| 1949 | struct ipv6hdr *v6; |
| 1950 | unsigned char *hdr; |
| 1951 | } ip; |
| 1952 | union { |
| 1953 | struct tcphdr *tcp; |
| 1954 | struct udphdr *udp; |
| 1955 | unsigned char *hdr; |
| 1956 | } l4; |
Alexander Duyck | a3fd9d8 | 2016-01-24 21:16:54 -0800 | [diff] [blame] | 1957 | unsigned char *exthdr; |
Jesse Brandeburg | d1bd743 | 2016-04-01 03:56:04 -0700 | [diff] [blame] | 1958 | u32 offset, cmd = 0; |
Alexander Duyck | a3fd9d8 | 2016-01-24 21:16:54 -0800 | [diff] [blame] | 1959 | __be16 frag_off; |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 1960 | u8 l4_proto = 0; |
| 1961 | |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 1962 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1963 | return 0; |
| 1964 | |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 1965 | ip.hdr = skb_network_header(skb); |
| 1966 | l4.hdr = skb_transport_header(skb); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1967 | |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 1968 | /* compute outer L2 header size */ |
| 1969 | offset = ((ip.hdr - skb->data) / 2) << I40E_TX_DESC_LENGTH_MACLEN_SHIFT; |
| 1970 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 1971 | if (skb->encapsulation) { |
Jesse Brandeburg | d1bd743 | 2016-04-01 03:56:04 -0700 | [diff] [blame] | 1972 | u32 tunnel = 0; |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 1973 | /* define outer network header type */ |
| 1974 | if (*tx_flags & I40E_TX_FLAGS_IPV4) { |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 1975 | tunnel |= (*tx_flags & I40E_TX_FLAGS_TSO) ? |
| 1976 | I40E_TX_CTX_EXT_IP_IPV4 : |
| 1977 | I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM; |
| 1978 | |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 1979 | l4_proto = ip.v4->protocol; |
| 1980 | } else if (*tx_flags & I40E_TX_FLAGS_IPV6) { |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 1981 | tunnel |= I40E_TX_CTX_EXT_IP_IPV6; |
Alexander Duyck | a3fd9d8 | 2016-01-24 21:16:54 -0800 | [diff] [blame] | 1982 | |
| 1983 | exthdr = ip.hdr + sizeof(*ip.v6); |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 1984 | l4_proto = ip.v6->nexthdr; |
Alexander Duyck | a3fd9d8 | 2016-01-24 21:16:54 -0800 | [diff] [blame] | 1985 | if (l4.hdr != exthdr) |
| 1986 | ipv6_skip_exthdr(skb, exthdr - skb->data, |
| 1987 | &l4_proto, &frag_off); |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | /* define outer transport */ |
| 1991 | switch (l4_proto) { |
Anjali Singhai Jain | 4599120 | 2015-02-27 09:15:29 +0000 | [diff] [blame] | 1992 | case IPPROTO_UDP: |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 1993 | tunnel |= I40E_TXD_CTX_UDP_TUNNELING; |
Anjali Singhai Jain | 89232c3 | 2015-04-16 20:06:00 -0400 | [diff] [blame] | 1994 | *tx_flags |= I40E_TX_FLAGS_VXLAN_TUNNEL; |
Anjali Singhai Jain | 4599120 | 2015-02-27 09:15:29 +0000 | [diff] [blame] | 1995 | break; |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 1996 | case IPPROTO_GRE: |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 1997 | tunnel |= I40E_TXD_CTX_GRE_TUNNELING; |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 1998 | *tx_flags |= I40E_TX_FLAGS_VXLAN_TUNNEL; |
| 1999 | break; |
Alexander Duyck | 577389a | 2016-04-02 00:06:56 -0700 | [diff] [blame] | 2000 | case IPPROTO_IPIP: |
| 2001 | case IPPROTO_IPV6: |
| 2002 | *tx_flags |= I40E_TX_FLAGS_VXLAN_TUNNEL; |
| 2003 | l4.hdr = skb_inner_network_header(skb); |
| 2004 | break; |
Anjali Singhai Jain | 4599120 | 2015-02-27 09:15:29 +0000 | [diff] [blame] | 2005 | default: |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 2006 | if (*tx_flags & I40E_TX_FLAGS_TSO) |
| 2007 | return -1; |
| 2008 | |
| 2009 | skb_checksum_help(skb); |
| 2010 | return 0; |
Anjali Singhai Jain | 4599120 | 2015-02-27 09:15:29 +0000 | [diff] [blame] | 2011 | } |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 2012 | |
Alexander Duyck | 577389a | 2016-04-02 00:06:56 -0700 | [diff] [blame] | 2013 | /* compute outer L3 header size */ |
| 2014 | tunnel |= ((l4.hdr - ip.hdr) / 4) << |
| 2015 | I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT; |
| 2016 | |
| 2017 | /* switch IP header pointer from outer to inner header */ |
| 2018 | ip.hdr = skb_inner_network_header(skb); |
| 2019 | |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2020 | /* compute tunnel header size */ |
| 2021 | tunnel |= ((ip.hdr - l4.hdr) / 2) << |
| 2022 | I40E_TXD_CTX_QW0_NATLEN_SHIFT; |
| 2023 | |
Alexander Duyck | 5453205 | 2016-01-24 21:17:29 -0800 | [diff] [blame] | 2024 | /* indicate if we need to offload outer UDP header */ |
| 2025 | if ((*tx_flags & I40E_TX_FLAGS_TSO) && |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2026 | !(skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) && |
Alexander Duyck | 5453205 | 2016-01-24 21:17:29 -0800 | [diff] [blame] | 2027 | (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM)) |
| 2028 | tunnel |= I40E_TXD_CTX_QW0_L4T_CS_MASK; |
| 2029 | |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2030 | /* record tunnel offload values */ |
| 2031 | *cd_tunneling |= tunnel; |
| 2032 | |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 2033 | /* switch L4 header pointer from outer to inner */ |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 2034 | l4.hdr = skb_inner_transport_header(skb); |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 2035 | l4_proto = 0; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2036 | |
Alexander Duyck | a006472 | 2016-01-24 21:16:48 -0800 | [diff] [blame] | 2037 | /* reset type as we transition from outer to inner headers */ |
| 2038 | *tx_flags &= ~(I40E_TX_FLAGS_IPV4 | I40E_TX_FLAGS_IPV6); |
| 2039 | if (ip.v4->version == 4) |
| 2040 | *tx_flags |= I40E_TX_FLAGS_IPV4; |
| 2041 | if (ip.v6->version == 6) |
Anjali Singhai Jain | 89232c3 | 2015-04-16 20:06:00 -0400 | [diff] [blame] | 2042 | *tx_flags |= I40E_TX_FLAGS_IPV6; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | /* Enable IP checksum offloads */ |
Anjali Singhai Jain | 89232c3 | 2015-04-16 20:06:00 -0400 | [diff] [blame] | 2046 | if (*tx_flags & I40E_TX_FLAGS_IPV4) { |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 2047 | l4_proto = ip.v4->protocol; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2048 | /* the stack computes the IP header already, the only time we |
| 2049 | * need the hardware to recompute it is in the case of TSO. |
| 2050 | */ |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2051 | cmd |= (*tx_flags & I40E_TX_FLAGS_TSO) ? |
| 2052 | I40E_TX_DESC_CMD_IIPT_IPV4_CSUM : |
| 2053 | I40E_TX_DESC_CMD_IIPT_IPV4; |
Anjali Singhai Jain | 89232c3 | 2015-04-16 20:06:00 -0400 | [diff] [blame] | 2054 | } else if (*tx_flags & I40E_TX_FLAGS_IPV6) { |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2055 | cmd |= I40E_TX_DESC_CMD_IIPT_IPV6; |
Alexander Duyck | a3fd9d8 | 2016-01-24 21:16:54 -0800 | [diff] [blame] | 2056 | |
| 2057 | exthdr = ip.hdr + sizeof(*ip.v6); |
| 2058 | l4_proto = ip.v6->nexthdr; |
| 2059 | if (l4.hdr != exthdr) |
| 2060 | ipv6_skip_exthdr(skb, exthdr - skb->data, |
| 2061 | &l4_proto, &frag_off); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2062 | } |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 2063 | |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2064 | /* compute inner L3 header size */ |
| 2065 | offset |= ((l4.hdr - ip.hdr) / 4) << I40E_TX_DESC_LENGTH_IPLEN_SHIFT; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2066 | |
| 2067 | /* Enable L4 checksum offloads */ |
Alexander Duyck | b96b78f | 2016-01-24 21:16:42 -0800 | [diff] [blame] | 2068 | switch (l4_proto) { |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2069 | case IPPROTO_TCP: |
| 2070 | /* enable checksum offloads */ |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2071 | cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP; |
| 2072 | offset |= l4.tcp->doff << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2073 | break; |
| 2074 | case IPPROTO_SCTP: |
| 2075 | /* enable SCTP checksum offload */ |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2076 | cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP; |
| 2077 | offset |= (sizeof(struct sctphdr) >> 2) << |
| 2078 | I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2079 | break; |
| 2080 | case IPPROTO_UDP: |
| 2081 | /* enable UDP checksum offload */ |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2082 | cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP; |
| 2083 | offset |= (sizeof(struct udphdr) >> 2) << |
| 2084 | I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2085 | break; |
| 2086 | default: |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 2087 | if (*tx_flags & I40E_TX_FLAGS_TSO) |
| 2088 | return -1; |
| 2089 | skb_checksum_help(skb); |
| 2090 | return 0; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2091 | } |
Alexander Duyck | 475b420 | 2016-01-24 21:17:01 -0800 | [diff] [blame] | 2092 | |
| 2093 | *td_cmd |= cmd; |
| 2094 | *td_offset |= offset; |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 2095 | |
| 2096 | return 1; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /** |
| 2100 | * i40e_create_tx_ctx Build the Tx context descriptor |
| 2101 | * @tx_ring: ring to create the descriptor on |
| 2102 | * @cd_type_cmd_tso_mss: Quad Word 1 |
| 2103 | * @cd_tunneling: Quad Word 0 - bits 0-31 |
| 2104 | * @cd_l2tag2: Quad Word 0 - bits 32-63 |
| 2105 | **/ |
| 2106 | static void i40e_create_tx_ctx(struct i40e_ring *tx_ring, |
| 2107 | const u64 cd_type_cmd_tso_mss, |
| 2108 | const u32 cd_tunneling, const u32 cd_l2tag2) |
| 2109 | { |
| 2110 | struct i40e_tx_context_desc *context_desc; |
| 2111 | int i = tx_ring->next_to_use; |
| 2112 | |
Jesse Brandeburg | ff40dd5 | 2014-02-14 02:14:41 +0000 | [diff] [blame] | 2113 | if ((cd_type_cmd_tso_mss == I40E_TX_DESC_DTYPE_CONTEXT) && |
| 2114 | !cd_tunneling && !cd_l2tag2) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2115 | return; |
| 2116 | |
| 2117 | /* grab the next descriptor */ |
| 2118 | context_desc = I40E_TX_CTXTDESC(tx_ring, i); |
| 2119 | |
| 2120 | i++; |
| 2121 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 2122 | |
| 2123 | /* cpu_to_le32 and assign to struct fields */ |
| 2124 | context_desc->tunneling_params = cpu_to_le32(cd_tunneling); |
| 2125 | context_desc->l2tag2 = cpu_to_le16(cd_l2tag2); |
Jesse Brandeburg | 3efbbb2 | 2014-06-04 20:41:54 +0000 | [diff] [blame] | 2126 | context_desc->rsvd = cpu_to_le16(0); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2127 | context_desc->type_cmd_tso_mss = cpu_to_le64(cd_type_cmd_tso_mss); |
| 2128 | } |
| 2129 | |
Jesse Brandeburg | 4eeb1ff | 2015-11-18 17:35:42 -0800 | [diff] [blame] | 2130 | /** |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2131 | * __i40evf_chk_linearize - Check if there are more than 8 buffers per packet |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2132 | * @skb: send buffer |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2133 | * |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2134 | * Note: Our HW can't DMA more than 8 buffers to build a packet on the wire |
| 2135 | * and so we need to figure out the cases where we need to linearize the skb. |
| 2136 | * |
| 2137 | * For TSO we need to count the TSO header and segment payload separately. |
| 2138 | * As such we need to check cases where we have 7 fragments or more as we |
| 2139 | * can potentially require 9 DMA transactions, 1 for the TSO header, 1 for |
| 2140 | * the segment payload in the first descriptor, and another 7 for the |
| 2141 | * fragments. |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2142 | **/ |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2143 | bool __i40evf_chk_linearize(struct sk_buff *skb) |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2144 | { |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2145 | const struct skb_frag_struct *frag, *stale; |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2146 | int nr_frags, sum; |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2147 | |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2148 | /* no need to check if number of frags is less than 7 */ |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2149 | nr_frags = skb_shinfo(skb)->nr_frags; |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2150 | if (nr_frags < (I40E_MAX_BUFFER_TXD - 1)) |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2151 | return false; |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2152 | |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2153 | /* We need to walk through the list and validate that each group |
Alexander Duyck | 841493a | 2016-09-06 18:05:04 -0700 | [diff] [blame] | 2154 | * of 6 fragments totals at least gso_size. |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2155 | */ |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2156 | nr_frags -= I40E_MAX_BUFFER_TXD - 2; |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2157 | frag = &skb_shinfo(skb)->frags[0]; |
| 2158 | |
| 2159 | /* Initialize size to the negative value of gso_size minus 1. We |
| 2160 | * use this as the worst case scenerio in which the frag ahead |
| 2161 | * of us only provides one byte which is why we are limited to 6 |
| 2162 | * descriptors for a single transmit as the header and previous |
| 2163 | * fragment are already consuming 2 descriptors. |
| 2164 | */ |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2165 | sum = 1 - skb_shinfo(skb)->gso_size; |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2166 | |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2167 | /* Add size of frags 0 through 4 to create our initial sum */ |
| 2168 | sum += skb_frag_size(frag++); |
| 2169 | sum += skb_frag_size(frag++); |
| 2170 | sum += skb_frag_size(frag++); |
| 2171 | sum += skb_frag_size(frag++); |
| 2172 | sum += skb_frag_size(frag++); |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2173 | |
| 2174 | /* Walk through fragments adding latest fragment, testing it, and |
| 2175 | * then removing stale fragments from the sum. |
| 2176 | */ |
Alexander Duyck | 248de22 | 2017-12-08 10:55:04 -0800 | [diff] [blame] | 2177 | for (stale = &skb_shinfo(skb)->frags[0];; stale++) { |
| 2178 | int stale_size = skb_frag_size(stale); |
| 2179 | |
Alexander Duyck | 3f3f7cb | 2016-03-30 16:15:37 -0700 | [diff] [blame] | 2180 | sum += skb_frag_size(frag++); |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2181 | |
Alexander Duyck | 248de22 | 2017-12-08 10:55:04 -0800 | [diff] [blame] | 2182 | /* The stale fragment may present us with a smaller |
| 2183 | * descriptor than the actual fragment size. To account |
| 2184 | * for that we need to remove all the data on the front and |
| 2185 | * figure out what the remainder would be in the last |
| 2186 | * descriptor associated with the fragment. |
| 2187 | */ |
| 2188 | if (stale_size > I40E_MAX_DATA_PER_TXD) { |
| 2189 | int align_pad = -(stale->page_offset) & |
| 2190 | (I40E_MAX_READ_REQ_SIZE - 1); |
| 2191 | |
| 2192 | sum -= align_pad; |
| 2193 | stale_size -= align_pad; |
| 2194 | |
| 2195 | do { |
| 2196 | sum -= I40E_MAX_DATA_PER_TXD_ALIGNED; |
| 2197 | stale_size -= I40E_MAX_DATA_PER_TXD_ALIGNED; |
| 2198 | } while (stale_size > I40E_MAX_DATA_PER_TXD); |
| 2199 | } |
| 2200 | |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2201 | /* if sum is negative we failed to make sufficient progress */ |
| 2202 | if (sum < 0) |
| 2203 | return true; |
| 2204 | |
Alexander Duyck | 841493a | 2016-09-06 18:05:04 -0700 | [diff] [blame] | 2205 | if (!nr_frags--) |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2206 | break; |
| 2207 | |
Alexander Duyck | 248de22 | 2017-12-08 10:55:04 -0800 | [diff] [blame] | 2208 | sum -= stale_size; |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2211 | return false; |
Anjali Singhai | 71da619 | 2015-02-21 06:42:35 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2214 | /** |
Jesse Brandeburg | 8f6a2b0 | 2015-04-16 20:06:09 -0400 | [diff] [blame] | 2215 | * __i40evf_maybe_stop_tx - 2nd level check for tx stop conditions |
| 2216 | * @tx_ring: the ring to be checked |
| 2217 | * @size: the size buffer we want to assure is available |
| 2218 | * |
| 2219 | * Returns -EBUSY if a stop is needed, else 0 |
| 2220 | **/ |
Alexander Duyck | 4ec441d | 2016-02-17 11:02:43 -0800 | [diff] [blame] | 2221 | int __i40evf_maybe_stop_tx(struct i40e_ring *tx_ring, int size) |
Jesse Brandeburg | 8f6a2b0 | 2015-04-16 20:06:09 -0400 | [diff] [blame] | 2222 | { |
| 2223 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 2224 | /* Memory barrier before checking head and tail */ |
| 2225 | smp_mb(); |
| 2226 | |
| 2227 | /* Check again in a case another CPU has just made room available. */ |
| 2228 | if (likely(I40E_DESC_UNUSED(tx_ring) < size)) |
| 2229 | return -EBUSY; |
| 2230 | |
| 2231 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 2232 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 2233 | ++tx_ring->tx_stats.restart_queue; |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
| 2237 | /** |
Jesse Brandeburg | 3e587cf | 2015-04-16 20:06:10 -0400 | [diff] [blame] | 2238 | * i40evf_tx_map - Build the Tx descriptor |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2239 | * @tx_ring: ring to send buffer on |
| 2240 | * @skb: send buffer |
| 2241 | * @first: first buffer info buffer to use |
| 2242 | * @tx_flags: collected send information |
| 2243 | * @hdr_len: size of the packet header |
| 2244 | * @td_cmd: the command field in the descriptor |
| 2245 | * @td_offset: offset for checksum or crc |
| 2246 | **/ |
Jesse Brandeburg | 3e587cf | 2015-04-16 20:06:10 -0400 | [diff] [blame] | 2247 | static inline void i40evf_tx_map(struct i40e_ring *tx_ring, struct sk_buff *skb, |
| 2248 | struct i40e_tx_buffer *first, u32 tx_flags, |
| 2249 | const u8 hdr_len, u32 td_cmd, u32 td_offset) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2250 | { |
| 2251 | unsigned int data_len = skb->data_len; |
| 2252 | unsigned int size = skb_headlen(skb); |
| 2253 | struct skb_frag_struct *frag; |
| 2254 | struct i40e_tx_buffer *tx_bi; |
| 2255 | struct i40e_tx_desc *tx_desc; |
| 2256 | u16 i = tx_ring->next_to_use; |
| 2257 | u32 td_tag = 0; |
| 2258 | dma_addr_t dma; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2259 | |
| 2260 | if (tx_flags & I40E_TX_FLAGS_HW_VLAN) { |
| 2261 | td_cmd |= I40E_TX_DESC_CMD_IL2TAG1; |
| 2262 | td_tag = (tx_flags & I40E_TX_FLAGS_VLAN_MASK) >> |
| 2263 | I40E_TX_FLAGS_VLAN_SHIFT; |
| 2264 | } |
| 2265 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2266 | first->tx_flags = tx_flags; |
| 2267 | |
| 2268 | dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); |
| 2269 | |
| 2270 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 2271 | tx_bi = first; |
| 2272 | |
| 2273 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
Alexander Duyck | 5c4654d | 2016-02-19 12:17:08 -0800 | [diff] [blame] | 2274 | unsigned int max_data = I40E_MAX_DATA_PER_TXD_ALIGNED; |
| 2275 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2276 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 2277 | goto dma_error; |
| 2278 | |
| 2279 | /* record length, and DMA address */ |
| 2280 | dma_unmap_len_set(tx_bi, len, size); |
| 2281 | dma_unmap_addr_set(tx_bi, dma, dma); |
| 2282 | |
Alexander Duyck | 5c4654d | 2016-02-19 12:17:08 -0800 | [diff] [blame] | 2283 | /* align size to end of page */ |
| 2284 | max_data += -dma & (I40E_MAX_READ_REQ_SIZE - 1); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2285 | tx_desc->buffer_addr = cpu_to_le64(dma); |
| 2286 | |
| 2287 | while (unlikely(size > I40E_MAX_DATA_PER_TXD)) { |
| 2288 | tx_desc->cmd_type_offset_bsz = |
| 2289 | build_ctob(td_cmd, td_offset, |
Alexander Duyck | 5c4654d | 2016-02-19 12:17:08 -0800 | [diff] [blame] | 2290 | max_data, td_tag); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2291 | |
| 2292 | tx_desc++; |
| 2293 | i++; |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2294 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2295 | if (i == tx_ring->count) { |
| 2296 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 2297 | i = 0; |
| 2298 | } |
| 2299 | |
Alexander Duyck | 5c4654d | 2016-02-19 12:17:08 -0800 | [diff] [blame] | 2300 | dma += max_data; |
| 2301 | size -= max_data; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2302 | |
Alexander Duyck | 5c4654d | 2016-02-19 12:17:08 -0800 | [diff] [blame] | 2303 | max_data = I40E_MAX_DATA_PER_TXD_ALIGNED; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2304 | tx_desc->buffer_addr = cpu_to_le64(dma); |
| 2305 | } |
| 2306 | |
| 2307 | if (likely(!data_len)) |
| 2308 | break; |
| 2309 | |
| 2310 | tx_desc->cmd_type_offset_bsz = build_ctob(td_cmd, td_offset, |
| 2311 | size, td_tag); |
| 2312 | |
| 2313 | tx_desc++; |
| 2314 | i++; |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2315 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2316 | if (i == tx_ring->count) { |
| 2317 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 2318 | i = 0; |
| 2319 | } |
| 2320 | |
| 2321 | size = skb_frag_size(frag); |
| 2322 | data_len -= size; |
| 2323 | |
| 2324 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 2325 | DMA_TO_DEVICE); |
| 2326 | |
| 2327 | tx_bi = &tx_ring->tx_bi[i]; |
| 2328 | } |
| 2329 | |
Alexander Duyck | 1dc8b53 | 2016-10-11 15:26:54 -0700 | [diff] [blame] | 2330 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2331 | |
| 2332 | i++; |
| 2333 | if (i == tx_ring->count) |
| 2334 | i = 0; |
| 2335 | |
| 2336 | tx_ring->next_to_use = i; |
| 2337 | |
Alexander Duyck | 4ec441d | 2016-02-17 11:02:43 -0800 | [diff] [blame] | 2338 | i40e_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2339 | |
Preethi Banala | b1cb07d | 2017-03-10 12:22:00 -0800 | [diff] [blame] | 2340 | /* write last descriptor with RS and EOP bits */ |
| 2341 | td_cmd |= I40E_TXD_CMD; |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2342 | tx_desc->cmd_type_offset_bsz = |
Alexander Duyck | 1dc8b53 | 2016-10-11 15:26:54 -0700 | [diff] [blame] | 2343 | build_ctob(td_cmd, td_offset, size, td_tag); |
| 2344 | |
| 2345 | /* Force memory writes to complete before letting h/w know there |
| 2346 | * are new descriptors to fetch. |
| 2347 | * |
| 2348 | * We also use this memory barrier to make certain all of the |
| 2349 | * status bits have been updated before next_to_watch is written. |
| 2350 | */ |
| 2351 | wmb(); |
| 2352 | |
| 2353 | /* set next_to_watch value indicating a packet is present */ |
| 2354 | first->next_to_watch = tx_desc; |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2355 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2356 | /* notify HW of packet */ |
Preethi Banala | b1cb07d | 2017-03-10 12:22:00 -0800 | [diff] [blame] | 2357 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2358 | writel(i, tx_ring->tail); |
Alexander Duyck | 1dc8b53 | 2016-10-11 15:26:54 -0700 | [diff] [blame] | 2359 | |
| 2360 | /* we need this if more than one processor can write to our tail |
| 2361 | * at a time, it synchronizes IO on IA64/Altix systems |
| 2362 | */ |
| 2363 | mmiowb(); |
Anjali Singhai Jain | 6a7fded | 2015-10-26 19:44:29 -0400 | [diff] [blame] | 2364 | } |
Alexander Duyck | 1dc8b53 | 2016-10-11 15:26:54 -0700 | [diff] [blame] | 2365 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2366 | return; |
| 2367 | |
| 2368 | dma_error: |
| 2369 | dev_info(tx_ring->dev, "TX DMA map failed\n"); |
| 2370 | |
| 2371 | /* clear dma mappings for failed tx_bi map */ |
| 2372 | for (;;) { |
| 2373 | tx_bi = &tx_ring->tx_bi[i]; |
| 2374 | i40e_unmap_and_free_tx_resource(tx_ring, tx_bi); |
| 2375 | if (tx_bi == first) |
| 2376 | break; |
| 2377 | if (i == 0) |
| 2378 | i = tx_ring->count; |
| 2379 | i--; |
| 2380 | } |
| 2381 | |
| 2382 | tx_ring->next_to_use = i; |
| 2383 | } |
| 2384 | |
| 2385 | /** |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2386 | * i40e_xmit_frame_ring - Sends buffer on Tx ring |
| 2387 | * @skb: send buffer |
| 2388 | * @tx_ring: ring to send buffer on |
| 2389 | * |
| 2390 | * Returns NETDEV_TX_OK if sent, else an error code |
| 2391 | **/ |
| 2392 | static netdev_tx_t i40e_xmit_frame_ring(struct sk_buff *skb, |
| 2393 | struct i40e_ring *tx_ring) |
| 2394 | { |
| 2395 | u64 cd_type_cmd_tso_mss = I40E_TX_DESC_DTYPE_CONTEXT; |
| 2396 | u32 cd_tunneling = 0, cd_l2tag2 = 0; |
| 2397 | struct i40e_tx_buffer *first; |
| 2398 | u32 td_offset = 0; |
| 2399 | u32 tx_flags = 0; |
| 2400 | __be16 protocol; |
| 2401 | u32 td_cmd = 0; |
| 2402 | u8 hdr_len = 0; |
Alexander Duyck | 4ec441d | 2016-02-17 11:02:43 -0800 | [diff] [blame] | 2403 | int tso, count; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2404 | |
Jesse Brandeburg | b74118f | 2015-10-26 19:44:30 -0400 | [diff] [blame] | 2405 | /* prefetch the data, we'll need it later */ |
| 2406 | prefetch(skb->data); |
| 2407 | |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 2408 | i40e_trace(xmit_frame_ring, skb, tx_ring); |
| 2409 | |
Alexander Duyck | 4ec441d | 2016-02-17 11:02:43 -0800 | [diff] [blame] | 2410 | count = i40e_xmit_descriptor_count(skb); |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2411 | if (i40e_chk_linearize(skb, count)) { |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 2412 | if (__skb_linearize(skb)) { |
| 2413 | dev_kfree_skb_any(skb); |
| 2414 | return NETDEV_TX_OK; |
| 2415 | } |
Alexander Duyck | 5c4654d | 2016-02-19 12:17:08 -0800 | [diff] [blame] | 2416 | count = i40e_txd_use_count(skb->len); |
Alexander Duyck | 2d37490 | 2016-02-17 11:02:50 -0800 | [diff] [blame] | 2417 | tx_ring->tx_stats.tx_linearize++; |
| 2418 | } |
Alexander Duyck | 4ec441d | 2016-02-17 11:02:43 -0800 | [diff] [blame] | 2419 | |
| 2420 | /* need: 1 descriptor per page * PAGE_SIZE/I40E_MAX_DATA_PER_TXD, |
| 2421 | * + 1 desc for skb_head_len/I40E_MAX_DATA_PER_TXD, |
| 2422 | * + 4 desc gap to avoid the cache line where head is, |
| 2423 | * + 1 desc for context descriptor, |
| 2424 | * otherwise try next time |
| 2425 | */ |
| 2426 | if (i40e_maybe_stop_tx(tx_ring, count + 4 + 1)) { |
| 2427 | tx_ring->tx_stats.tx_busy++; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2428 | return NETDEV_TX_BUSY; |
Alexander Duyck | 4ec441d | 2016-02-17 11:02:43 -0800 | [diff] [blame] | 2429 | } |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2430 | |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 2431 | /* record the location of the first descriptor for this packet */ |
| 2432 | first = &tx_ring->tx_bi[tx_ring->next_to_use]; |
| 2433 | first->skb = skb; |
| 2434 | first->bytecount = skb->len; |
| 2435 | first->gso_segs = 1; |
| 2436 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2437 | /* prepare the xmit flags */ |
Jesse Brandeburg | 3e587cf | 2015-04-16 20:06:10 -0400 | [diff] [blame] | 2438 | if (i40evf_tx_prepare_vlan_flags(skb, tx_ring, &tx_flags)) |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2439 | goto out_drop; |
| 2440 | |
| 2441 | /* obtain protocol of skb */ |
Vlad Yasevich | a12c415 | 2014-08-25 10:34:53 -0400 | [diff] [blame] | 2442 | protocol = vlan_get_protocol(skb); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2443 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2444 | /* setup IPv4/IPv6 offloads */ |
| 2445 | if (protocol == htons(ETH_P_IP)) |
| 2446 | tx_flags |= I40E_TX_FLAGS_IPV4; |
| 2447 | else if (protocol == htons(ETH_P_IPV6)) |
| 2448 | tx_flags |= I40E_TX_FLAGS_IPV6; |
| 2449 | |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 2450 | tso = i40e_tso(first, &hdr_len, &cd_type_cmd_tso_mss); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2451 | |
| 2452 | if (tso < 0) |
| 2453 | goto out_drop; |
| 2454 | else if (tso) |
| 2455 | tx_flags |= I40E_TX_FLAGS_TSO; |
| 2456 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2457 | /* Always offload the checksum, since it's in the data descriptor */ |
Alexander Duyck | 529f1f6 | 2016-01-24 21:17:10 -0800 | [diff] [blame] | 2458 | tso = i40e_tx_enable_csum(skb, &tx_flags, &td_cmd, &td_offset, |
| 2459 | tx_ring, &cd_tunneling); |
| 2460 | if (tso < 0) |
| 2461 | goto out_drop; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2462 | |
Alexander Duyck | 3bc6797 | 2016-02-17 11:02:56 -0800 | [diff] [blame] | 2463 | skb_tx_timestamp(skb); |
| 2464 | |
| 2465 | /* always enable CRC insertion offload */ |
| 2466 | td_cmd |= I40E_TX_DESC_CMD_ICRC; |
| 2467 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2468 | i40e_create_tx_ctx(tx_ring, cd_type_cmd_tso_mss, |
| 2469 | cd_tunneling, cd_l2tag2); |
| 2470 | |
Jesse Brandeburg | 3e587cf | 2015-04-16 20:06:10 -0400 | [diff] [blame] | 2471 | i40evf_tx_map(tx_ring, skb, first, tx_flags, hdr_len, |
| 2472 | td_cmd, td_offset); |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2473 | |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2474 | return NETDEV_TX_OK; |
| 2475 | |
| 2476 | out_drop: |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 2477 | i40e_trace(xmit_frame_ring_drop, first->skb, tx_ring); |
Alexander Duyck | 52ea3e8 | 2016-11-28 16:05:59 -0800 | [diff] [blame] | 2478 | dev_kfree_skb_any(first->skb); |
| 2479 | first->skb = NULL; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2480 | return NETDEV_TX_OK; |
| 2481 | } |
| 2482 | |
| 2483 | /** |
| 2484 | * i40evf_xmit_frame - Selects the correct VSI and Tx queue to send buffer |
| 2485 | * @skb: send buffer |
| 2486 | * @netdev: network interface device structure |
| 2487 | * |
| 2488 | * Returns NETDEV_TX_OK if sent, else an error code |
| 2489 | **/ |
| 2490 | netdev_tx_t i40evf_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 2491 | { |
| 2492 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2493 | struct i40e_ring *tx_ring = &adapter->tx_rings[skb->queue_mapping]; |
Greg Rose | 7f12ad7 | 2013-12-21 06:12:51 +0000 | [diff] [blame] | 2494 | |
| 2495 | /* hardware can't handle really short frames, hardware padding works |
| 2496 | * beyond this point |
| 2497 | */ |
| 2498 | if (unlikely(skb->len < I40E_MIN_TX_LEN)) { |
| 2499 | if (skb_pad(skb, I40E_MIN_TX_LEN - skb->len)) |
| 2500 | return NETDEV_TX_OK; |
| 2501 | skb->len = I40E_MIN_TX_LEN; |
| 2502 | skb_set_tail_pointer(skb, I40E_MIN_TX_LEN); |
| 2503 | } |
| 2504 | |
| 2505 | return i40e_xmit_frame_ring(skb, tx_ring); |
| 2506 | } |