blob: 32bf1fecf86406d7a51cc61bd03388f5ad090312 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01002 * Driver for Solarflare network controllers and boards
Ben Hutchings8ceee662008-04-27 12:55:59 +01003 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01004 * Copyright 2005-2013 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/pci.h>
12#include <linux/tcp.h>
13#include <linux/ip.h>
14#include <linux/in.h>
Ben Hutchings738a8f42009-11-29 15:16:05 +000015#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Ben Hutchings738a8f42009-11-29 15:16:05 +000017#include <net/ipv6.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010018#include <linux/if_ether.h>
19#include <linux/highmem.h>
Ben Hutchings183233b2013-06-28 21:47:12 +010020#include <linux/cache.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010021#include "net_driver.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010022#include "efx.h"
Ben Hutchings183233b2013-06-28 21:47:12 +010023#include "io.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000024#include "nic.h"
Bert Kenwarde9117e52016-11-17 10:51:54 +000025#include "tx.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010026#include "workarounds.h"
Ben Hutchingsdfa50be2013-03-08 21:20:09 +000027#include "ef10_regs.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010028
Ben Hutchings183233b2013-06-28 21:47:12 +010029#ifdef EFX_USE_PIO
30
Ben Hutchings183233b2013-06-28 21:47:12 +010031#define EFX_PIOBUF_SIZE_DEF ALIGN(256, L1_CACHE_BYTES)
32unsigned int efx_piobuf_size __read_mostly = EFX_PIOBUF_SIZE_DEF;
33
34#endif /* EFX_USE_PIO */
35
Bert Kenwarde9117e52016-11-17 10:51:54 +000036static inline u8 *efx_tx_get_copy_buffer(struct efx_tx_queue *tx_queue,
37 struct efx_tx_buffer *buffer)
Ben Hutchings0fe55652013-06-28 21:47:15 +010038{
Bert Kenwarde9117e52016-11-17 10:51:54 +000039 unsigned int index = efx_tx_queue_get_insert_index(tx_queue);
40 struct efx_buffer *page_buf =
41 &tx_queue->cb_page[index >> (PAGE_SHIFT - EFX_TX_CB_ORDER)];
42 unsigned int offset =
43 ((index << EFX_TX_CB_ORDER) + NET_IP_ALIGN) & (PAGE_SIZE - 1);
44
45 if (unlikely(!page_buf->addr) &&
46 efx_nic_alloc_buffer(tx_queue->efx, page_buf, PAGE_SIZE,
47 GFP_ATOMIC))
48 return NULL;
49 buffer->dma_addr = page_buf->dma_addr + offset;
50 buffer->unmap_len = 0;
51 return (u8 *)page_buf->addr + offset;
Ben Hutchings0fe55652013-06-28 21:47:15 +010052}
53
Bert Kenwarde9117e52016-11-17 10:51:54 +000054u8 *efx_tx_get_copy_buffer_limited(struct efx_tx_queue *tx_queue,
55 struct efx_tx_buffer *buffer, size_t len)
Ben Hutchings0fe55652013-06-28 21:47:15 +010056{
Bert Kenwarde9117e52016-11-17 10:51:54 +000057 if (len > EFX_TX_CB_SIZE)
58 return NULL;
59 return efx_tx_get_copy_buffer(tx_queue, buffer);
Ben Hutchings0fe55652013-06-28 21:47:15 +010060}
61
Ben Hutchings4d566062008-09-01 12:47:12 +010062static void efx_dequeue_buffer(struct efx_tx_queue *tx_queue,
Tom Herbertc3940992011-11-28 16:33:43 +000063 struct efx_tx_buffer *buffer,
64 unsigned int *pkts_compl,
65 unsigned int *bytes_compl)
Ben Hutchings8ceee662008-04-27 12:55:59 +010066{
67 if (buffer->unmap_len) {
Ben Hutchings0e33d872012-05-17 17:46:55 +010068 struct device *dma_dev = &tx_queue->efx->pci_dev->dev;
Alexandre Rames2acdb922013-10-31 12:42:32 +000069 dma_addr_t unmap_addr = buffer->dma_addr - buffer->dma_offset;
Ben Hutchings7668ff92012-05-17 20:52:20 +010070 if (buffer->flags & EFX_TX_BUF_MAP_SINGLE)
Ben Hutchings0e33d872012-05-17 17:46:55 +010071 dma_unmap_single(dma_dev, unmap_addr, buffer->unmap_len,
72 DMA_TO_DEVICE);
Ben Hutchings8ceee662008-04-27 12:55:59 +010073 else
Ben Hutchings0e33d872012-05-17 17:46:55 +010074 dma_unmap_page(dma_dev, unmap_addr, buffer->unmap_len,
75 DMA_TO_DEVICE);
Ben Hutchings8ceee662008-04-27 12:55:59 +010076 buffer->unmap_len = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +010077 }
78
Ben Hutchings7668ff92012-05-17 20:52:20 +010079 if (buffer->flags & EFX_TX_BUF_SKB) {
Tom Herbertc3940992011-11-28 16:33:43 +000080 (*pkts_compl)++;
81 (*bytes_compl) += buffer->skb->len;
Rick Jones4ef6dae2014-09-09 14:43:27 -070082 dev_consume_skb_any((struct sk_buff *)buffer->skb);
Ben Hutchings62776d02010-06-23 11:30:07 +000083 netif_vdbg(tx_queue->efx, tx_done, tx_queue->efx->net_dev,
84 "TX queue %d transmission id %x complete\n",
85 tx_queue->queue, tx_queue->read_count);
Ben Hutchings8ceee662008-04-27 12:55:59 +010086 }
Ben Hutchings7668ff92012-05-17 20:52:20 +010087
Ben Hutchingsf7251a92012-05-17 18:40:54 +010088 buffer->len = 0;
89 buffer->flags = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +010090}
91
Ben Hutchings7e6d06f2012-07-30 15:57:44 +000092unsigned int efx_tx_max_skb_descs(struct efx_nic *efx)
93{
94 /* Header and payload descriptor for each output segment, plus
95 * one for every input fragment boundary within a segment
96 */
97 unsigned int max_descs = EFX_TSO_MAX_SEGS * 2 + MAX_SKB_FRAGS;
98
Edward Cree5a6681e2016-11-28 18:55:34 +000099 /* Possibly one more per segment for option descriptors */
100 if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000101 max_descs += EFX_TSO_MAX_SEGS;
102
103 /* Possibly more for PCIe page boundaries within input fragments */
104 if (PAGE_SIZE > EFX_PAGE_SIZE)
105 max_descs += max_t(unsigned int, MAX_SKB_FRAGS,
106 DIV_ROUND_UP(GSO_MAX_SIZE, EFX_PAGE_SIZE));
107
108 return max_descs;
109}
110
Ben Hutchings14bf7182012-05-22 01:27:58 +0100111static void efx_tx_maybe_stop_queue(struct efx_tx_queue *txq1)
112{
113 /* We need to consider both queues that the net core sees as one */
114 struct efx_tx_queue *txq2 = efx_tx_queue_partner(txq1);
115 struct efx_nic *efx = txq1->efx;
116 unsigned int fill_level;
117
118 fill_level = max(txq1->insert_count - txq1->old_read_count,
119 txq2->insert_count - txq2->old_read_count);
120 if (likely(fill_level < efx->txq_stop_thresh))
121 return;
122
123 /* We used the stale old_read_count above, which gives us a
124 * pessimistic estimate of the fill level (which may even
125 * validly be >= efx->txq_entries). Now try again using
126 * read_count (more likely to be a cache miss).
127 *
128 * If we read read_count and then conditionally stop the
129 * queue, it is possible for the completion path to race with
130 * us and complete all outstanding descriptors in the middle,
131 * after which there will be no more completions to wake it.
132 * Therefore we stop the queue first, then read read_count
133 * (with a memory barrier to ensure the ordering), then
134 * restart the queue if the fill level turns out to be low
135 * enough.
136 */
137 netif_tx_stop_queue(txq1->core_txq);
138 smp_mb();
139 txq1->old_read_count = ACCESS_ONCE(txq1->read_count);
140 txq2->old_read_count = ACCESS_ONCE(txq2->read_count);
141
142 fill_level = max(txq1->insert_count - txq1->old_read_count,
143 txq2->insert_count - txq2->old_read_count);
Edward Creee01b16a2016-12-02 15:51:33 +0000144 EFX_WARN_ON_ONCE_PARANOID(fill_level >= efx->txq_entries);
Ben Hutchings14bf7182012-05-22 01:27:58 +0100145 if (likely(fill_level < efx->txq_stop_thresh)) {
146 smp_mb();
147 if (likely(!efx->loopback_selftest))
148 netif_tx_start_queue(txq1->core_txq);
149 }
150}
151
Bert Kenwarde9117e52016-11-17 10:51:54 +0000152static int efx_enqueue_skb_copy(struct efx_tx_queue *tx_queue,
153 struct sk_buff *skb)
154{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000155 unsigned int copy_len = skb->len;
156 struct efx_tx_buffer *buffer;
157 u8 *copy_buffer;
158 int rc;
159
Edward Creee01b16a2016-12-02 15:51:33 +0000160 EFX_WARN_ON_ONCE_PARANOID(copy_len > EFX_TX_CB_SIZE);
Bert Kenwarde9117e52016-11-17 10:51:54 +0000161
162 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
163
164 copy_buffer = efx_tx_get_copy_buffer(tx_queue, buffer);
165 if (unlikely(!copy_buffer))
166 return -ENOMEM;
167
168 rc = skb_copy_bits(skb, 0, copy_buffer, copy_len);
169 EFX_WARN_ON_PARANOID(rc);
Edward Cree5a6681e2016-11-28 18:55:34 +0000170 buffer->len = copy_len;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000171
172 buffer->skb = skb;
173 buffer->flags = EFX_TX_BUF_SKB;
174
175 ++tx_queue->insert_count;
176 return rc;
177}
178
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100179#ifdef EFX_USE_PIO
180
181struct efx_short_copy_buffer {
182 int used;
183 u8 buf[L1_CACHE_BYTES];
184};
185
186/* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
187 * Advances piobuf pointer. Leaves additional data in the copy buffer.
188 */
189static void efx_memcpy_toio_aligned(struct efx_nic *efx, u8 __iomem **piobuf,
190 u8 *data, int len,
191 struct efx_short_copy_buffer *copy_buf)
192{
193 int block_len = len & ~(sizeof(copy_buf->buf) - 1);
194
Ben Hutchings4984c232014-07-27 03:14:39 +0100195 __iowrite64_copy(*piobuf, data, block_len >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100196 *piobuf += block_len;
197 len -= block_len;
198
199 if (len) {
200 data += block_len;
201 BUG_ON(copy_buf->used);
202 BUG_ON(len > sizeof(copy_buf->buf));
203 memcpy(copy_buf->buf, data, len);
204 copy_buf->used = len;
205 }
206}
207
208/* Copy to PIO, respecting dword alignment, popping data from copy buffer first.
209 * Advances piobuf pointer. Leaves additional data in the copy buffer.
210 */
211static void efx_memcpy_toio_aligned_cb(struct efx_nic *efx, u8 __iomem **piobuf,
212 u8 *data, int len,
213 struct efx_short_copy_buffer *copy_buf)
214{
215 if (copy_buf->used) {
216 /* if the copy buffer is partially full, fill it up and write */
217 int copy_to_buf =
218 min_t(int, sizeof(copy_buf->buf) - copy_buf->used, len);
219
220 memcpy(copy_buf->buf + copy_buf->used, data, copy_to_buf);
221 copy_buf->used += copy_to_buf;
222
223 /* if we didn't fill it up then we're done for now */
224 if (copy_buf->used < sizeof(copy_buf->buf))
225 return;
226
Ben Hutchings4984c232014-07-27 03:14:39 +0100227 __iowrite64_copy(*piobuf, copy_buf->buf,
228 sizeof(copy_buf->buf) >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100229 *piobuf += sizeof(copy_buf->buf);
230 data += copy_to_buf;
231 len -= copy_to_buf;
232 copy_buf->used = 0;
233 }
234
235 efx_memcpy_toio_aligned(efx, piobuf, data, len, copy_buf);
236}
237
238static void efx_flush_copy_buffer(struct efx_nic *efx, u8 __iomem *piobuf,
239 struct efx_short_copy_buffer *copy_buf)
240{
241 /* if there's anything in it, write the whole buffer, including junk */
242 if (copy_buf->used)
Ben Hutchings4984c232014-07-27 03:14:39 +0100243 __iowrite64_copy(piobuf, copy_buf->buf,
244 sizeof(copy_buf->buf) >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100245}
246
247/* Traverse skb structure and copy fragments in to PIO buffer.
248 * Advances piobuf pointer.
249 */
250static void efx_skb_copy_bits_to_pio(struct efx_nic *efx, struct sk_buff *skb,
251 u8 __iomem **piobuf,
252 struct efx_short_copy_buffer *copy_buf)
253{
254 int i;
255
256 efx_memcpy_toio_aligned(efx, piobuf, skb->data, skb_headlen(skb),
257 copy_buf);
258
259 for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) {
260 skb_frag_t *f = &skb_shinfo(skb)->frags[i];
261 u8 *vaddr;
262
263 vaddr = kmap_atomic(skb_frag_page(f));
264
265 efx_memcpy_toio_aligned_cb(efx, piobuf, vaddr + f->page_offset,
266 skb_frag_size(f), copy_buf);
267 kunmap_atomic(vaddr);
268 }
269
Edward Creee01b16a2016-12-02 15:51:33 +0000270 EFX_WARN_ON_ONCE_PARANOID(skb_shinfo(skb)->frag_list);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100271}
272
Bert Kenwarde9117e52016-11-17 10:51:54 +0000273static int efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue,
274 struct sk_buff *skb)
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100275{
276 struct efx_tx_buffer *buffer =
277 efx_tx_queue_get_insert_buffer(tx_queue);
278 u8 __iomem *piobuf = tx_queue->piobuf;
279
280 /* Copy to PIO buffer. Ensure the writes are padded to the end
281 * of a cache line, as this is required for write-combining to be
282 * effective on at least x86.
283 */
284
285 if (skb_shinfo(skb)->nr_frags) {
286 /* The size of the copy buffer will ensure all writes
287 * are the size of a cache line.
288 */
289 struct efx_short_copy_buffer copy_buf;
290
291 copy_buf.used = 0;
292
293 efx_skb_copy_bits_to_pio(tx_queue->efx, skb,
294 &piobuf, &copy_buf);
295 efx_flush_copy_buffer(tx_queue->efx, piobuf, &copy_buf);
296 } else {
297 /* Pad the write to the size of a cache line.
Bert Kenwarde9117e52016-11-17 10:51:54 +0000298 * We can do this because we know the skb_shared_info struct is
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100299 * after the source, and the destination buffer is big enough.
300 */
301 BUILD_BUG_ON(L1_CACHE_BYTES >
302 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
Ben Hutchings4984c232014-07-27 03:14:39 +0100303 __iowrite64_copy(tx_queue->piobuf, skb->data,
304 ALIGN(skb->len, L1_CACHE_BYTES) >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100305 }
306
Bert Kenwarde9117e52016-11-17 10:51:54 +0000307 buffer->skb = skb;
308 buffer->flags = EFX_TX_BUF_SKB | EFX_TX_BUF_OPTION;
309
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100310 EFX_POPULATE_QWORD_5(buffer->option,
311 ESF_DZ_TX_DESC_IS_OPT, 1,
312 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_PIO,
313 ESF_DZ_TX_PIO_CONT, 0,
314 ESF_DZ_TX_PIO_BYTE_CNT, skb->len,
315 ESF_DZ_TX_PIO_BUF_ADDR,
316 tx_queue->piobuf_offset);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100317 ++tx_queue->insert_count;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000318 return 0;
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100319}
320#endif /* EFX_USE_PIO */
321
Bert Kenwarde9117e52016-11-17 10:51:54 +0000322static struct efx_tx_buffer *efx_tx_map_chunk(struct efx_tx_queue *tx_queue,
323 dma_addr_t dma_addr,
324 size_t len)
325{
326 const struct efx_nic_type *nic_type = tx_queue->efx->type;
327 struct efx_tx_buffer *buffer;
328 unsigned int dma_len;
329
330 /* Map the fragment taking account of NIC-dependent DMA limits. */
331 do {
332 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
333 dma_len = nic_type->tx_limit_len(tx_queue, dma_addr, len);
334
335 buffer->len = dma_len;
336 buffer->dma_addr = dma_addr;
337 buffer->flags = EFX_TX_BUF_CONT;
338 len -= dma_len;
339 dma_addr += dma_len;
340 ++tx_queue->insert_count;
341 } while (len);
342
343 return buffer;
344}
345
346/* Map all data from an SKB for DMA and create descriptors on the queue.
347 */
348static int efx_tx_map_data(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
349 unsigned int segment_count)
350{
351 struct efx_nic *efx = tx_queue->efx;
352 struct device *dma_dev = &efx->pci_dev->dev;
353 unsigned int frag_index, nr_frags;
354 dma_addr_t dma_addr, unmap_addr;
355 unsigned short dma_flags;
356 size_t len, unmap_len;
357
358 nr_frags = skb_shinfo(skb)->nr_frags;
359 frag_index = 0;
360
361 /* Map header data. */
362 len = skb_headlen(skb);
363 dma_addr = dma_map_single(dma_dev, skb->data, len, DMA_TO_DEVICE);
364 dma_flags = EFX_TX_BUF_MAP_SINGLE;
365 unmap_len = len;
366 unmap_addr = dma_addr;
367
368 if (unlikely(dma_mapping_error(dma_dev, dma_addr)))
369 return -EIO;
370
371 if (segment_count) {
372 /* For TSO we need to put the header in to a separate
373 * descriptor. Map this separately if necessary.
374 */
375 size_t header_len = skb_transport_header(skb) - skb->data +
376 (tcp_hdr(skb)->doff << 2u);
377
378 if (header_len != len) {
379 tx_queue->tso_long_headers++;
380 efx_tx_map_chunk(tx_queue, dma_addr, header_len);
381 len -= header_len;
382 dma_addr += header_len;
383 }
384 }
385
386 /* Add descriptors for each fragment. */
387 do {
388 struct efx_tx_buffer *buffer;
389 skb_frag_t *fragment;
390
391 buffer = efx_tx_map_chunk(tx_queue, dma_addr, len);
392
393 /* The final descriptor for a fragment is responsible for
394 * unmapping the whole fragment.
395 */
396 buffer->flags = EFX_TX_BUF_CONT | dma_flags;
397 buffer->unmap_len = unmap_len;
398 buffer->dma_offset = buffer->dma_addr - unmap_addr;
399
400 if (frag_index >= nr_frags) {
401 /* Store SKB details with the final buffer for
402 * the completion.
403 */
404 buffer->skb = skb;
405 buffer->flags = EFX_TX_BUF_SKB | dma_flags;
406 return 0;
407 }
408
409 /* Move on to the next fragment. */
410 fragment = &skb_shinfo(skb)->frags[frag_index++];
411 len = skb_frag_size(fragment);
412 dma_addr = skb_frag_dma_map(dma_dev, fragment,
413 0, len, DMA_TO_DEVICE);
414 dma_flags = 0;
415 unmap_len = len;
416 unmap_addr = dma_addr;
417
418 if (unlikely(dma_mapping_error(dma_dev, dma_addr)))
419 return -EIO;
420 } while (1);
421}
422
423/* Remove buffers put into a tx_queue. None of the buffers must have
424 * an skb attached.
425 */
426static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue)
427{
428 struct efx_tx_buffer *buffer;
429
430 /* Work backwards until we hit the original insert pointer value */
431 while (tx_queue->insert_count != tx_queue->write_count) {
432 --tx_queue->insert_count;
433 buffer = __efx_tx_queue_get_insert_buffer(tx_queue);
434 efx_dequeue_buffer(tx_queue, buffer, NULL, NULL);
435 }
436}
437
Edward Cree46d1efd2016-11-17 10:52:36 +0000438/*
439 * Fallback to software TSO.
440 *
441 * This is used if we are unable to send a GSO packet through hardware TSO.
442 * This should only ever happen due to per-queue restrictions - unsupported
443 * packets should first be filtered by the feature flags.
444 *
445 * Returns 0 on success, error code otherwise.
446 */
447static int efx_tx_tso_fallback(struct efx_tx_queue *tx_queue,
448 struct sk_buff *skb)
Bert Kenwarde9117e52016-11-17 10:51:54 +0000449{
Edward Cree46d1efd2016-11-17 10:52:36 +0000450 struct sk_buff *segments, *next;
451
452 segments = skb_gso_segment(skb, 0);
453 if (IS_ERR(segments))
454 return PTR_ERR(segments);
455
456 dev_kfree_skb_any(skb);
457 skb = segments;
458
459 while (skb) {
460 next = skb->next;
461 skb->next = NULL;
462
463 if (next)
464 skb->xmit_more = true;
465 efx_enqueue_skb(tx_queue, skb);
466 skb = next;
467 }
468
469 return 0;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000470}
471
Ben Hutchings8ceee662008-04-27 12:55:59 +0100472/*
473 * Add a socket buffer to a TX queue
474 *
475 * This maps all fragments of a socket buffer for DMA and adds them to
476 * the TX queue. The queue's insert pointer will be incremented by
477 * the number of fragments in the socket buffer.
478 *
479 * If any DMA mapping fails, any mapped fragments will be unmapped,
480 * the queue's insert pointer will be restored to its original value.
481 *
Ben Hutchings497f5ba2009-11-23 16:07:05 +0000482 * This function is split out from efx_hard_start_xmit to allow the
483 * loopback test to direct packets via specific TX queues.
484 *
Ben Hutchings14bf7182012-05-22 01:27:58 +0100485 * Returns NETDEV_TX_OK.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100486 * You must hold netif_tx_lock() to call this function.
487 */
Ben Hutchings497f5ba2009-11-23 16:07:05 +0000488netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100489{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000490 bool data_mapped = false;
491 unsigned int segments;
492 unsigned int skb_len;
Edward Cree46d1efd2016-11-17 10:52:36 +0000493 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100494
Bert Kenwarde9117e52016-11-17 10:51:54 +0000495 skb_len = skb->len;
496 segments = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 0;
497 if (segments == 1)
498 segments = 0; /* Don't use TSO for a single segment. */
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100499
Bert Kenwarde9117e52016-11-17 10:51:54 +0000500 /* Handle TSO first - it's *possible* (although unlikely) that we might
501 * be passed a packet to segment that's smaller than the copybreak/PIO
502 * size limit.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100503 */
Bert Kenwarde9117e52016-11-17 10:51:54 +0000504 if (segments) {
Edward Creee01b16a2016-12-02 15:51:33 +0000505 EFX_WARN_ON_ONCE_PARANOID(!tx_queue->handle_tso);
Edward Cree46d1efd2016-11-17 10:52:36 +0000506 rc = tx_queue->handle_tso(tx_queue, skb, &data_mapped);
507 if (rc == -EINVAL) {
508 rc = efx_tx_tso_fallback(tx_queue, skb);
509 tx_queue->tso_fallbacks++;
510 if (rc == 0)
511 return 0;
512 }
513 if (rc)
Bert Kenwarde9117e52016-11-17 10:51:54 +0000514 goto err;
515#ifdef EFX_USE_PIO
516 } else if (skb_len <= efx_piobuf_size && !skb->xmit_more &&
517 efx_nic_may_tx_pio(tx_queue)) {
518 /* Use PIO for short packets with an empty queue. */
519 if (efx_enqueue_skb_pio(tx_queue, skb))
520 goto err;
521 tx_queue->pio_packets++;
522 data_mapped = true;
523#endif
Edward Cree5a6681e2016-11-28 18:55:34 +0000524 } else if (skb->data_len && skb_len <= EFX_TX_CB_SIZE) {
Bert Kenwarde9117e52016-11-17 10:51:54 +0000525 /* Pad short packets or coalesce short fragmented packets. */
526 if (efx_enqueue_skb_copy(tx_queue, skb))
527 goto err;
528 tx_queue->cb_packets++;
529 data_mapped = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100530 }
531
Bert Kenwarde9117e52016-11-17 10:51:54 +0000532 /* Map for DMA and create descriptors if we haven't done so already. */
533 if (!data_mapped && (efx_tx_map_data(tx_queue, skb, segments)))
534 goto err;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100535
Bert Kenwarde9117e52016-11-17 10:51:54 +0000536 /* Update BQL */
537 netdev_tx_sent_queue(tx_queue->core_txq, skb_len);
Edward Cree70b33fb2014-10-17 15:32:25 +0100538
Ben Hutchings8ceee662008-04-27 12:55:59 +0100539 /* Pass off to hardware */
Martin Habetsb2663a42015-11-02 12:51:31 +0000540 if (!skb->xmit_more || netif_xmit_stopped(tx_queue->core_txq)) {
541 struct efx_tx_queue *txq2 = efx_tx_queue_partner(tx_queue);
542
543 /* There could be packets left on the partner queue if those
544 * SKBs had skb->xmit_more set. If we do not push those they
545 * could be left for a long time and cause a netdev watchdog.
546 */
547 if (txq2->xmit_more_available)
548 efx_nic_push_buffers(txq2);
549
Edward Cree70b33fb2014-10-17 15:32:25 +0100550 efx_nic_push_buffers(tx_queue);
Martin Habetsb2663a42015-11-02 12:51:31 +0000551 } else {
552 tx_queue->xmit_more_available = skb->xmit_more;
553 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100554
Bert Kenwarde9117e52016-11-17 10:51:54 +0000555 if (segments) {
556 tx_queue->tso_bursts++;
557 tx_queue->tso_packets += segments;
558 tx_queue->tx_packets += segments;
559 } else {
560 tx_queue->tx_packets++;
561 }
562
563 efx_tx_maybe_stop_queue(tx_queue);
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100564
Ben Hutchings8ceee662008-04-27 12:55:59 +0100565 return NETDEV_TX_OK;
566
Ben Hutchings8ceee662008-04-27 12:55:59 +0100567
Bert Kenwarde9117e52016-11-17 10:51:54 +0000568err:
569 efx_enqueue_unwind(tx_queue);
Ben Hutchings9bc183d2009-11-23 16:06:47 +0000570 dev_kfree_skb_any(skb);
Ben Hutchings14bf7182012-05-22 01:27:58 +0100571 return NETDEV_TX_OK;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100572}
573
574/* Remove packets from the TX queue
575 *
576 * This removes packets from the TX queue, up to and including the
577 * specified index.
578 */
Ben Hutchings4d566062008-09-01 12:47:12 +0100579static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue,
Tom Herbertc3940992011-11-28 16:33:43 +0000580 unsigned int index,
581 unsigned int *pkts_compl,
582 unsigned int *bytes_compl)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100583{
584 struct efx_nic *efx = tx_queue->efx;
585 unsigned int stop_index, read_ptr;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100586
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000587 stop_index = (index + 1) & tx_queue->ptr_mask;
588 read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100589
590 while (read_ptr != stop_index) {
591 struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr];
Ben Hutchingsba8977b2013-01-08 23:43:19 +0000592
593 if (!(buffer->flags & EFX_TX_BUF_OPTION) &&
594 unlikely(buffer->len == 0)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000595 netif_err(efx, tx_err, efx->net_dev,
596 "TX queue %d spurious TX completion id %x\n",
597 tx_queue->queue, read_ptr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100598 efx_schedule_reset(efx, RESET_TYPE_TX_SKIP);
599 return;
600 }
601
Tom Herbertc3940992011-11-28 16:33:43 +0000602 efx_dequeue_buffer(tx_queue, buffer, pkts_compl, bytes_compl);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100603
604 ++tx_queue->read_count;
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000605 read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100606 }
607}
608
Ben Hutchings8ceee662008-04-27 12:55:59 +0100609/* Initiate a packet transmission. We use one channel per CPU
610 * (sharing when we have more CPUs than channels). On Falcon, the TX
611 * completion events will be directed back to the CPU that transmitted
612 * the packet, which should be cache-efficient.
613 *
614 * Context: non-blocking.
615 * Note that returning anything other than NETDEV_TX_OK will cause the
616 * OS to free the skb.
617 */
Stephen Hemminger613573252009-08-31 19:50:58 +0000618netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
Ben Hutchings2d0cc562012-02-17 00:10:45 +0000619 struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100620{
Ben Hutchings767e4682008-09-01 12:43:14 +0100621 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100622 struct efx_tx_queue *tx_queue;
Ben Hutchings94b274b2011-01-10 21:18:20 +0000623 unsigned index, type;
Ben Hutchings60ac1062008-09-01 12:44:59 +0100624
Ben Hutchingse4abce82011-05-16 18:51:24 +0100625 EFX_WARN_ON_PARANOID(!netif_device_present(net_dev));
Ben Hutchingsa7ef5932009-03-04 09:52:37 +0000626
Stuart Hodgson7c236c42012-09-03 11:09:36 +0100627 /* PTP "event" packet */
628 if (unlikely(efx_xmit_with_hwtstamp(skb)) &&
629 unlikely(efx_ptp_is_ptp_tx(efx, skb))) {
630 return efx_ptp_tx(efx, skb);
631 }
632
Ben Hutchings94b274b2011-01-10 21:18:20 +0000633 index = skb_get_queue_mapping(skb);
634 type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
635 if (index >= efx->n_tx_channels) {
636 index -= efx->n_tx_channels;
637 type |= EFX_TXQ_TYPE_HIGHPRI;
638 }
639 tx_queue = efx_get_tx_queue(efx, index, type);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100640
Ben Hutchings497f5ba2009-11-23 16:07:05 +0000641 return efx_enqueue_skb(tx_queue, skb);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100642}
643
Ben Hutchings60031fc2011-01-12 18:39:40 +0000644void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
645{
Ben Hutchings94b274b2011-01-10 21:18:20 +0000646 struct efx_nic *efx = tx_queue->efx;
647
Ben Hutchings60031fc2011-01-12 18:39:40 +0000648 /* Must be inverse of queue lookup in efx_hard_start_xmit() */
Ben Hutchings94b274b2011-01-10 21:18:20 +0000649 tx_queue->core_txq =
650 netdev_get_tx_queue(efx->net_dev,
651 tx_queue->queue / EFX_TXQ_TYPES +
652 ((tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ?
653 efx->n_tx_channels : 0));
654}
655
Jiri Pirko2572ac52017-08-07 10:15:17 +0200656int efx_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +0200657 void *type_data)
Ben Hutchings94b274b2011-01-10 21:18:20 +0000658{
659 struct efx_nic *efx = netdev_priv(net_dev);
Jiri Pirkode4784c2017-08-07 10:15:32 +0200660 struct tc_mqprio_qopt *mqprio = type_data;
Ben Hutchings94b274b2011-01-10 21:18:20 +0000661 struct efx_channel *channel;
662 struct efx_tx_queue *tx_queue;
John Fastabend16e5cc62016-02-16 21:16:43 -0800663 unsigned tc, num_tc;
Ben Hutchings94b274b2011-01-10 21:18:20 +0000664 int rc;
665
Jiri Pirko2572ac52017-08-07 10:15:17 +0200666 if (type != TC_SETUP_MQPRIO)
Jiri Pirko38cf0422017-08-07 10:15:31 +0200667 return -EOPNOTSUPP;
John Fastabende4c67342016-02-16 21:16:15 -0800668
Jiri Pirkode4784c2017-08-07 10:15:32 +0200669 num_tc = mqprio->num_tc;
John Fastabend16e5cc62016-02-16 21:16:43 -0800670
Edward Cree5a6681e2016-11-28 18:55:34 +0000671 if (num_tc > EFX_MAX_TX_TC)
Ben Hutchings94b274b2011-01-10 21:18:20 +0000672 return -EINVAL;
673
Jiri Pirkode4784c2017-08-07 10:15:32 +0200674 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
Amritha Nambiar56f36ac2017-03-15 10:39:25 -0700675
Ben Hutchings94b274b2011-01-10 21:18:20 +0000676 if (num_tc == net_dev->num_tc)
677 return 0;
678
679 for (tc = 0; tc < num_tc; tc++) {
680 net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels;
681 net_dev->tc_to_txq[tc].count = efx->n_tx_channels;
682 }
683
684 if (num_tc > net_dev->num_tc) {
685 /* Initialise high-priority queues as necessary */
686 efx_for_each_channel(channel, efx) {
687 efx_for_each_possible_channel_tx_queue(tx_queue,
688 channel) {
689 if (!(tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI))
690 continue;
691 if (!tx_queue->buffer) {
692 rc = efx_probe_tx_queue(tx_queue);
693 if (rc)
694 return rc;
695 }
696 if (!tx_queue->initialised)
697 efx_init_tx_queue(tx_queue);
698 efx_init_tx_queue_core_txq(tx_queue);
699 }
700 }
701 } else {
702 /* Reduce number of classes before number of queues */
703 net_dev->num_tc = num_tc;
704 }
705
706 rc = netif_set_real_num_tx_queues(net_dev,
707 max_t(int, num_tc, 1) *
708 efx->n_tx_channels);
709 if (rc)
710 return rc;
711
712 /* Do not destroy high-priority queues when they become
713 * unused. We would have to flush them first, and it is
714 * fairly difficult to flush a subset of TX queues. Leave
715 * it to efx_fini_channels().
716 */
717
718 net_dev->num_tc = num_tc;
719 return 0;
Ben Hutchings60031fc2011-01-12 18:39:40 +0000720}
721
Ben Hutchings8ceee662008-04-27 12:55:59 +0100722void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index)
723{
724 unsigned fill_level;
725 struct efx_nic *efx = tx_queue->efx;
Ben Hutchings14bf7182012-05-22 01:27:58 +0100726 struct efx_tx_queue *txq2;
Tom Herbertc3940992011-11-28 16:33:43 +0000727 unsigned int pkts_compl = 0, bytes_compl = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100728
Edward Creee01b16a2016-12-02 15:51:33 +0000729 EFX_WARN_ON_ONCE_PARANOID(index > tx_queue->ptr_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100730
Tom Herbertc3940992011-11-28 16:33:43 +0000731 efx_dequeue_buffers(tx_queue, index, &pkts_compl, &bytes_compl);
Peter Dunningc9368352015-07-08 10:05:10 +0100732 tx_queue->pkts_compl += pkts_compl;
733 tx_queue->bytes_compl += bytes_compl;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100734
Ben Hutchings02e12162013-04-27 01:55:21 +0100735 if (pkts_compl > 1)
736 ++tx_queue->merge_events;
737
Ben Hutchings14bf7182012-05-22 01:27:58 +0100738 /* See if we need to restart the netif queue. This memory
739 * barrier ensures that we write read_count (inside
740 * efx_dequeue_buffers()) before reading the queue status.
741 */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100742 smp_mb();
Ben Hutchingsc04bfc62010-12-10 01:24:16 +0000743 if (unlikely(netif_tx_queue_stopped(tx_queue->core_txq)) &&
Neil Turton9d1aea62011-04-04 13:46:23 +0100744 likely(efx->port_enabled) &&
Ben Hutchingse4abce82011-05-16 18:51:24 +0100745 likely(netif_device_present(efx->net_dev))) {
Ben Hutchings14bf7182012-05-22 01:27:58 +0100746 txq2 = efx_tx_queue_partner(tx_queue);
747 fill_level = max(tx_queue->insert_count - tx_queue->read_count,
748 txq2->insert_count - txq2->read_count);
749 if (fill_level <= efx->txq_wake_thresh)
Ben Hutchingsc04bfc62010-12-10 01:24:16 +0000750 netif_tx_wake_queue(tx_queue->core_txq);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100751 }
Ben Hutchingscd385572010-11-15 23:53:11 +0000752
753 /* Check whether the hardware queue is now empty */
754 if ((int)(tx_queue->read_count - tx_queue->old_write_count) >= 0) {
755 tx_queue->old_write_count = ACCESS_ONCE(tx_queue->write_count);
756 if (tx_queue->read_count == tx_queue->old_write_count) {
757 smp_mb();
758 tx_queue->empty_read_count =
759 tx_queue->read_count | EFX_EMPTY_COUNT_VALID;
760 }
761 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100762}
763
Bert Kenwarde9117e52016-11-17 10:51:54 +0000764static unsigned int efx_tx_cb_page_count(struct efx_tx_queue *tx_queue)
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100765{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000766 return DIV_ROUND_UP(tx_queue->ptr_mask + 1, PAGE_SIZE >> EFX_TX_CB_ORDER);
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100767}
768
Ben Hutchings8ceee662008-04-27 12:55:59 +0100769int efx_probe_tx_queue(struct efx_tx_queue *tx_queue)
770{
771 struct efx_nic *efx = tx_queue->efx;
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000772 unsigned int entries;
Ben Hutchings7668ff92012-05-17 20:52:20 +0100773 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100774
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000775 /* Create the smallest power-of-two aligned ring */
776 entries = max(roundup_pow_of_two(efx->txq_entries), EFX_MIN_DMAQ_SIZE);
Edward Creee01b16a2016-12-02 15:51:33 +0000777 EFX_WARN_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE);
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000778 tx_queue->ptr_mask = entries - 1;
779
780 netif_dbg(efx, probe, efx->net_dev,
781 "creating TX queue %d size %#x mask %#x\n",
782 tx_queue->queue, efx->txq_entries, tx_queue->ptr_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100783
784 /* Allocate software ring */
Thomas Meyerc2e4e252011-12-02 12:36:13 +0000785 tx_queue->buffer = kcalloc(entries, sizeof(*tx_queue->buffer),
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000786 GFP_KERNEL);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100787 if (!tx_queue->buffer)
788 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100789
Bert Kenwarde9117e52016-11-17 10:51:54 +0000790 tx_queue->cb_page = kcalloc(efx_tx_cb_page_count(tx_queue),
791 sizeof(tx_queue->cb_page[0]), GFP_KERNEL);
792 if (!tx_queue->cb_page) {
793 rc = -ENOMEM;
794 goto fail1;
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100795 }
796
Ben Hutchings8ceee662008-04-27 12:55:59 +0100797 /* Allocate hardware ring */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000798 rc = efx_nic_probe_tx(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100799 if (rc)
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100800 goto fail2;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100801
802 return 0;
803
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100804fail2:
Bert Kenwarde9117e52016-11-17 10:51:54 +0000805 kfree(tx_queue->cb_page);
806 tx_queue->cb_page = NULL;
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100807fail1:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100808 kfree(tx_queue->buffer);
809 tx_queue->buffer = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100810 return rc;
811}
812
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100813void efx_init_tx_queue(struct efx_tx_queue *tx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100814{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000815 struct efx_nic *efx = tx_queue->efx;
816
817 netif_dbg(efx, drv, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000818 "initialising TX queue %d\n", tx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100819
820 tx_queue->insert_count = 0;
821 tx_queue->write_count = 0;
Edward Creede1deff2017-01-13 21:20:14 +0000822 tx_queue->packet_write_count = 0;
Ben Hutchingscd385572010-11-15 23:53:11 +0000823 tx_queue->old_write_count = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100824 tx_queue->read_count = 0;
825 tx_queue->old_read_count = 0;
Ben Hutchingscd385572010-11-15 23:53:11 +0000826 tx_queue->empty_read_count = 0 | EFX_EMPTY_COUNT_VALID;
Martin Habetsb2663a42015-11-02 12:51:31 +0000827 tx_queue->xmit_more_available = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100828
Bert Kenwarde9117e52016-11-17 10:51:54 +0000829 /* Set up default function pointers. These may get replaced by
830 * efx_nic_init_tx() based off NIC/queue capabilities.
831 */
Edward Cree46d1efd2016-11-17 10:52:36 +0000832 tx_queue->handle_tso = efx_enqueue_skb_tso;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000833
Ben Hutchings8ceee662008-04-27 12:55:59 +0100834 /* Set up TX descriptor ring */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000835 efx_nic_init_tx(tx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000836
837 tx_queue->initialised = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100838}
839
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100840void efx_fini_tx_queue(struct efx_tx_queue *tx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100841{
842 struct efx_tx_buffer *buffer;
843
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100844 netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
845 "shutting down TX queue %d\n", tx_queue->queue);
846
Ben Hutchings8ceee662008-04-27 12:55:59 +0100847 if (!tx_queue->buffer)
848 return;
849
850 /* Free any buffers left in the ring */
851 while (tx_queue->read_count != tx_queue->write_count) {
Tom Herbertc3940992011-11-28 16:33:43 +0000852 unsigned int pkts_compl = 0, bytes_compl = 0;
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000853 buffer = &tx_queue->buffer[tx_queue->read_count & tx_queue->ptr_mask];
Tom Herbertc3940992011-11-28 16:33:43 +0000854 efx_dequeue_buffer(tx_queue, buffer, &pkts_compl, &bytes_compl);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100855
856 ++tx_queue->read_count;
857 }
Martin Habetsb2663a42015-11-02 12:51:31 +0000858 tx_queue->xmit_more_available = false;
Tom Herbertc3940992011-11-28 16:33:43 +0000859 netdev_tx_reset_queue(tx_queue->core_txq);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100860}
861
Ben Hutchings8ceee662008-04-27 12:55:59 +0100862void efx_remove_tx_queue(struct efx_tx_queue *tx_queue)
863{
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100864 int i;
865
Ben Hutchings94b274b2011-01-10 21:18:20 +0000866 if (!tx_queue->buffer)
867 return;
868
Ben Hutchings62776d02010-06-23 11:30:07 +0000869 netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
870 "destroying TX queue %d\n", tx_queue->queue);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000871 efx_nic_remove_tx(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100872
Bert Kenwarde9117e52016-11-17 10:51:54 +0000873 if (tx_queue->cb_page) {
874 for (i = 0; i < efx_tx_cb_page_count(tx_queue); i++)
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100875 efx_nic_free_buffer(tx_queue->efx,
Bert Kenwarde9117e52016-11-17 10:51:54 +0000876 &tx_queue->cb_page[i]);
877 kfree(tx_queue->cb_page);
878 tx_queue->cb_page = NULL;
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100879 }
880
Ben Hutchings8ceee662008-04-27 12:55:59 +0100881 kfree(tx_queue->buffer);
882 tx_queue->buffer = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100883}