blob: 1aa728cfa8ba84051e222405d12e4e18bcc91278 [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
31#define EFX_PIOBUF_SIZE_MAX ER_DZ_TX_PIOBUF_SIZE
32#define EFX_PIOBUF_SIZE_DEF ALIGN(256, L1_CACHE_BYTES)
33unsigned int efx_piobuf_size __read_mostly = EFX_PIOBUF_SIZE_DEF;
34
35#endif /* EFX_USE_PIO */
36
Bert Kenwarde9117e52016-11-17 10:51:54 +000037static inline u8 *efx_tx_get_copy_buffer(struct efx_tx_queue *tx_queue,
38 struct efx_tx_buffer *buffer)
Ben Hutchings0fe55652013-06-28 21:47:15 +010039{
Bert Kenwarde9117e52016-11-17 10:51:54 +000040 unsigned int index = efx_tx_queue_get_insert_index(tx_queue);
41 struct efx_buffer *page_buf =
42 &tx_queue->cb_page[index >> (PAGE_SHIFT - EFX_TX_CB_ORDER)];
43 unsigned int offset =
44 ((index << EFX_TX_CB_ORDER) + NET_IP_ALIGN) & (PAGE_SIZE - 1);
45
46 if (unlikely(!page_buf->addr) &&
47 efx_nic_alloc_buffer(tx_queue->efx, page_buf, PAGE_SIZE,
48 GFP_ATOMIC))
49 return NULL;
50 buffer->dma_addr = page_buf->dma_addr + offset;
51 buffer->unmap_len = 0;
52 return (u8 *)page_buf->addr + offset;
Ben Hutchings0fe55652013-06-28 21:47:15 +010053}
54
Bert Kenwarde9117e52016-11-17 10:51:54 +000055u8 *efx_tx_get_copy_buffer_limited(struct efx_tx_queue *tx_queue,
56 struct efx_tx_buffer *buffer, size_t len)
Ben Hutchings0fe55652013-06-28 21:47:15 +010057{
Bert Kenwarde9117e52016-11-17 10:51:54 +000058 if (len > EFX_TX_CB_SIZE)
59 return NULL;
60 return efx_tx_get_copy_buffer(tx_queue, buffer);
Ben Hutchings0fe55652013-06-28 21:47:15 +010061}
62
Ben Hutchings4d566062008-09-01 12:47:12 +010063static void efx_dequeue_buffer(struct efx_tx_queue *tx_queue,
Tom Herbertc3940992011-11-28 16:33:43 +000064 struct efx_tx_buffer *buffer,
65 unsigned int *pkts_compl,
66 unsigned int *bytes_compl)
Ben Hutchings8ceee662008-04-27 12:55:59 +010067{
68 if (buffer->unmap_len) {
Ben Hutchings0e33d872012-05-17 17:46:55 +010069 struct device *dma_dev = &tx_queue->efx->pci_dev->dev;
Alexandre Rames2acdb922013-10-31 12:42:32 +000070 dma_addr_t unmap_addr = buffer->dma_addr - buffer->dma_offset;
Ben Hutchings7668ff92012-05-17 20:52:20 +010071 if (buffer->flags & EFX_TX_BUF_MAP_SINGLE)
Ben Hutchings0e33d872012-05-17 17:46:55 +010072 dma_unmap_single(dma_dev, unmap_addr, buffer->unmap_len,
73 DMA_TO_DEVICE);
Ben Hutchings8ceee662008-04-27 12:55:59 +010074 else
Ben Hutchings0e33d872012-05-17 17:46:55 +010075 dma_unmap_page(dma_dev, unmap_addr, buffer->unmap_len,
76 DMA_TO_DEVICE);
Ben Hutchings8ceee662008-04-27 12:55:59 +010077 buffer->unmap_len = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +010078 }
79
Ben Hutchings7668ff92012-05-17 20:52:20 +010080 if (buffer->flags & EFX_TX_BUF_SKB) {
Tom Herbertc3940992011-11-28 16:33:43 +000081 (*pkts_compl)++;
82 (*bytes_compl) += buffer->skb->len;
Rick Jones4ef6dae2014-09-09 14:43:27 -070083 dev_consume_skb_any((struct sk_buff *)buffer->skb);
Ben Hutchings62776d02010-06-23 11:30:07 +000084 netif_vdbg(tx_queue->efx, tx_done, tx_queue->efx->net_dev,
85 "TX queue %d transmission id %x complete\n",
86 tx_queue->queue, tx_queue->read_count);
Ben Hutchingsf7251a92012-05-17 18:40:54 +010087 } else if (buffer->flags & EFX_TX_BUF_HEAP) {
88 kfree(buffer->heap_buf);
Ben Hutchings8ceee662008-04-27 12:55:59 +010089 }
Ben Hutchings7668ff92012-05-17 20:52:20 +010090
Ben Hutchingsf7251a92012-05-17 18:40:54 +010091 buffer->len = 0;
92 buffer->flags = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +010093}
94
Ben Hutchings7e6d06f2012-07-30 15:57:44 +000095unsigned int efx_tx_max_skb_descs(struct efx_nic *efx)
96{
97 /* Header and payload descriptor for each output segment, plus
98 * one for every input fragment boundary within a segment
99 */
100 unsigned int max_descs = EFX_TSO_MAX_SEGS * 2 + MAX_SKB_FRAGS;
101
Ben Hutchingsdfa50be2013-03-08 21:20:09 +0000102 /* Possibly one more per segment for the alignment workaround,
103 * or for option descriptors
104 */
105 if (EFX_WORKAROUND_5391(efx) || efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000106 max_descs += EFX_TSO_MAX_SEGS;
107
108 /* Possibly more for PCIe page boundaries within input fragments */
109 if (PAGE_SIZE > EFX_PAGE_SIZE)
110 max_descs += max_t(unsigned int, MAX_SKB_FRAGS,
111 DIV_ROUND_UP(GSO_MAX_SIZE, EFX_PAGE_SIZE));
112
113 return max_descs;
114}
115
Ben Hutchings14bf7182012-05-22 01:27:58 +0100116static void efx_tx_maybe_stop_queue(struct efx_tx_queue *txq1)
117{
118 /* We need to consider both queues that the net core sees as one */
119 struct efx_tx_queue *txq2 = efx_tx_queue_partner(txq1);
120 struct efx_nic *efx = txq1->efx;
121 unsigned int fill_level;
122
123 fill_level = max(txq1->insert_count - txq1->old_read_count,
124 txq2->insert_count - txq2->old_read_count);
125 if (likely(fill_level < efx->txq_stop_thresh))
126 return;
127
128 /* We used the stale old_read_count above, which gives us a
129 * pessimistic estimate of the fill level (which may even
130 * validly be >= efx->txq_entries). Now try again using
131 * read_count (more likely to be a cache miss).
132 *
133 * If we read read_count and then conditionally stop the
134 * queue, it is possible for the completion path to race with
135 * us and complete all outstanding descriptors in the middle,
136 * after which there will be no more completions to wake it.
137 * Therefore we stop the queue first, then read read_count
138 * (with a memory barrier to ensure the ordering), then
139 * restart the queue if the fill level turns out to be low
140 * enough.
141 */
142 netif_tx_stop_queue(txq1->core_txq);
143 smp_mb();
144 txq1->old_read_count = ACCESS_ONCE(txq1->read_count);
145 txq2->old_read_count = ACCESS_ONCE(txq2->read_count);
146
147 fill_level = max(txq1->insert_count - txq1->old_read_count,
148 txq2->insert_count - txq2->old_read_count);
149 EFX_BUG_ON_PARANOID(fill_level >= efx->txq_entries);
150 if (likely(fill_level < efx->txq_stop_thresh)) {
151 smp_mb();
152 if (likely(!efx->loopback_selftest))
153 netif_tx_start_queue(txq1->core_txq);
154 }
155}
156
Bert Kenwarde9117e52016-11-17 10:51:54 +0000157static int efx_enqueue_skb_copy(struct efx_tx_queue *tx_queue,
158 struct sk_buff *skb)
159{
160 unsigned int min_len = tx_queue->tx_min_size;
161 unsigned int copy_len = skb->len;
162 struct efx_tx_buffer *buffer;
163 u8 *copy_buffer;
164 int rc;
165
166 EFX_BUG_ON_PARANOID(copy_len > EFX_TX_CB_SIZE);
167
168 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
169
170 copy_buffer = efx_tx_get_copy_buffer(tx_queue, buffer);
171 if (unlikely(!copy_buffer))
172 return -ENOMEM;
173
174 rc = skb_copy_bits(skb, 0, copy_buffer, copy_len);
175 EFX_WARN_ON_PARANOID(rc);
176 if (unlikely(copy_len < min_len)) {
177 memset(copy_buffer + copy_len, 0, min_len - copy_len);
178 buffer->len = min_len;
179 } else {
180 buffer->len = copy_len;
181 }
182
183 buffer->skb = skb;
184 buffer->flags = EFX_TX_BUF_SKB;
185
186 ++tx_queue->insert_count;
187 return rc;
188}
189
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100190#ifdef EFX_USE_PIO
191
192struct efx_short_copy_buffer {
193 int used;
194 u8 buf[L1_CACHE_BYTES];
195};
196
197/* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
198 * Advances piobuf pointer. Leaves additional data in the copy buffer.
199 */
200static void efx_memcpy_toio_aligned(struct efx_nic *efx, u8 __iomem **piobuf,
201 u8 *data, int len,
202 struct efx_short_copy_buffer *copy_buf)
203{
204 int block_len = len & ~(sizeof(copy_buf->buf) - 1);
205
Ben Hutchings4984c232014-07-27 03:14:39 +0100206 __iowrite64_copy(*piobuf, data, block_len >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100207 *piobuf += block_len;
208 len -= block_len;
209
210 if (len) {
211 data += block_len;
212 BUG_ON(copy_buf->used);
213 BUG_ON(len > sizeof(copy_buf->buf));
214 memcpy(copy_buf->buf, data, len);
215 copy_buf->used = len;
216 }
217}
218
219/* Copy to PIO, respecting dword alignment, popping data from copy buffer first.
220 * Advances piobuf pointer. Leaves additional data in the copy buffer.
221 */
222static void efx_memcpy_toio_aligned_cb(struct efx_nic *efx, u8 __iomem **piobuf,
223 u8 *data, int len,
224 struct efx_short_copy_buffer *copy_buf)
225{
226 if (copy_buf->used) {
227 /* if the copy buffer is partially full, fill it up and write */
228 int copy_to_buf =
229 min_t(int, sizeof(copy_buf->buf) - copy_buf->used, len);
230
231 memcpy(copy_buf->buf + copy_buf->used, data, copy_to_buf);
232 copy_buf->used += copy_to_buf;
233
234 /* if we didn't fill it up then we're done for now */
235 if (copy_buf->used < sizeof(copy_buf->buf))
236 return;
237
Ben Hutchings4984c232014-07-27 03:14:39 +0100238 __iowrite64_copy(*piobuf, copy_buf->buf,
239 sizeof(copy_buf->buf) >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100240 *piobuf += sizeof(copy_buf->buf);
241 data += copy_to_buf;
242 len -= copy_to_buf;
243 copy_buf->used = 0;
244 }
245
246 efx_memcpy_toio_aligned(efx, piobuf, data, len, copy_buf);
247}
248
249static void efx_flush_copy_buffer(struct efx_nic *efx, u8 __iomem *piobuf,
250 struct efx_short_copy_buffer *copy_buf)
251{
252 /* if there's anything in it, write the whole buffer, including junk */
253 if (copy_buf->used)
Ben Hutchings4984c232014-07-27 03:14:39 +0100254 __iowrite64_copy(piobuf, copy_buf->buf,
255 sizeof(copy_buf->buf) >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100256}
257
258/* Traverse skb structure and copy fragments in to PIO buffer.
259 * Advances piobuf pointer.
260 */
261static void efx_skb_copy_bits_to_pio(struct efx_nic *efx, struct sk_buff *skb,
262 u8 __iomem **piobuf,
263 struct efx_short_copy_buffer *copy_buf)
264{
265 int i;
266
267 efx_memcpy_toio_aligned(efx, piobuf, skb->data, skb_headlen(skb),
268 copy_buf);
269
270 for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) {
271 skb_frag_t *f = &skb_shinfo(skb)->frags[i];
272 u8 *vaddr;
273
274 vaddr = kmap_atomic(skb_frag_page(f));
275
276 efx_memcpy_toio_aligned_cb(efx, piobuf, vaddr + f->page_offset,
277 skb_frag_size(f), copy_buf);
278 kunmap_atomic(vaddr);
279 }
280
281 EFX_BUG_ON_PARANOID(skb_shinfo(skb)->frag_list);
282}
283
Bert Kenwarde9117e52016-11-17 10:51:54 +0000284static int efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue,
285 struct sk_buff *skb)
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100286{
287 struct efx_tx_buffer *buffer =
288 efx_tx_queue_get_insert_buffer(tx_queue);
289 u8 __iomem *piobuf = tx_queue->piobuf;
290
291 /* Copy to PIO buffer. Ensure the writes are padded to the end
292 * of a cache line, as this is required for write-combining to be
293 * effective on at least x86.
294 */
295
296 if (skb_shinfo(skb)->nr_frags) {
297 /* The size of the copy buffer will ensure all writes
298 * are the size of a cache line.
299 */
300 struct efx_short_copy_buffer copy_buf;
301
302 copy_buf.used = 0;
303
304 efx_skb_copy_bits_to_pio(tx_queue->efx, skb,
305 &piobuf, &copy_buf);
306 efx_flush_copy_buffer(tx_queue->efx, piobuf, &copy_buf);
307 } else {
308 /* Pad the write to the size of a cache line.
Bert Kenwarde9117e52016-11-17 10:51:54 +0000309 * We can do this because we know the skb_shared_info struct is
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100310 * after the source, and the destination buffer is big enough.
311 */
312 BUILD_BUG_ON(L1_CACHE_BYTES >
313 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
Ben Hutchings4984c232014-07-27 03:14:39 +0100314 __iowrite64_copy(tx_queue->piobuf, skb->data,
315 ALIGN(skb->len, L1_CACHE_BYTES) >> 3);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100316 }
317
Bert Kenwarde9117e52016-11-17 10:51:54 +0000318 buffer->skb = skb;
319 buffer->flags = EFX_TX_BUF_SKB | EFX_TX_BUF_OPTION;
320
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100321 EFX_POPULATE_QWORD_5(buffer->option,
322 ESF_DZ_TX_DESC_IS_OPT, 1,
323 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_PIO,
324 ESF_DZ_TX_PIO_CONT, 0,
325 ESF_DZ_TX_PIO_BYTE_CNT, skb->len,
326 ESF_DZ_TX_PIO_BUF_ADDR,
327 tx_queue->piobuf_offset);
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100328 ++tx_queue->insert_count;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000329 return 0;
Jon Cooperee45fd92c2013-09-02 18:24:29 +0100330}
331#endif /* EFX_USE_PIO */
332
Bert Kenwarde9117e52016-11-17 10:51:54 +0000333static struct efx_tx_buffer *efx_tx_map_chunk(struct efx_tx_queue *tx_queue,
334 dma_addr_t dma_addr,
335 size_t len)
336{
337 const struct efx_nic_type *nic_type = tx_queue->efx->type;
338 struct efx_tx_buffer *buffer;
339 unsigned int dma_len;
340
341 /* Map the fragment taking account of NIC-dependent DMA limits. */
342 do {
343 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
344 dma_len = nic_type->tx_limit_len(tx_queue, dma_addr, len);
345
346 buffer->len = dma_len;
347 buffer->dma_addr = dma_addr;
348 buffer->flags = EFX_TX_BUF_CONT;
349 len -= dma_len;
350 dma_addr += dma_len;
351 ++tx_queue->insert_count;
352 } while (len);
353
354 return buffer;
355}
356
357/* Map all data from an SKB for DMA and create descriptors on the queue.
358 */
359static int efx_tx_map_data(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
360 unsigned int segment_count)
361{
362 struct efx_nic *efx = tx_queue->efx;
363 struct device *dma_dev = &efx->pci_dev->dev;
364 unsigned int frag_index, nr_frags;
365 dma_addr_t dma_addr, unmap_addr;
366 unsigned short dma_flags;
367 size_t len, unmap_len;
368
369 nr_frags = skb_shinfo(skb)->nr_frags;
370 frag_index = 0;
371
372 /* Map header data. */
373 len = skb_headlen(skb);
374 dma_addr = dma_map_single(dma_dev, skb->data, len, DMA_TO_DEVICE);
375 dma_flags = EFX_TX_BUF_MAP_SINGLE;
376 unmap_len = len;
377 unmap_addr = dma_addr;
378
379 if (unlikely(dma_mapping_error(dma_dev, dma_addr)))
380 return -EIO;
381
382 if (segment_count) {
383 /* For TSO we need to put the header in to a separate
384 * descriptor. Map this separately if necessary.
385 */
386 size_t header_len = skb_transport_header(skb) - skb->data +
387 (tcp_hdr(skb)->doff << 2u);
388
389 if (header_len != len) {
390 tx_queue->tso_long_headers++;
391 efx_tx_map_chunk(tx_queue, dma_addr, header_len);
392 len -= header_len;
393 dma_addr += header_len;
394 }
395 }
396
397 /* Add descriptors for each fragment. */
398 do {
399 struct efx_tx_buffer *buffer;
400 skb_frag_t *fragment;
401
402 buffer = efx_tx_map_chunk(tx_queue, dma_addr, len);
403
404 /* The final descriptor for a fragment is responsible for
405 * unmapping the whole fragment.
406 */
407 buffer->flags = EFX_TX_BUF_CONT | dma_flags;
408 buffer->unmap_len = unmap_len;
409 buffer->dma_offset = buffer->dma_addr - unmap_addr;
410
411 if (frag_index >= nr_frags) {
412 /* Store SKB details with the final buffer for
413 * the completion.
414 */
415 buffer->skb = skb;
416 buffer->flags = EFX_TX_BUF_SKB | dma_flags;
417 return 0;
418 }
419
420 /* Move on to the next fragment. */
421 fragment = &skb_shinfo(skb)->frags[frag_index++];
422 len = skb_frag_size(fragment);
423 dma_addr = skb_frag_dma_map(dma_dev, fragment,
424 0, len, DMA_TO_DEVICE);
425 dma_flags = 0;
426 unmap_len = len;
427 unmap_addr = dma_addr;
428
429 if (unlikely(dma_mapping_error(dma_dev, dma_addr)))
430 return -EIO;
431 } while (1);
432}
433
434/* Remove buffers put into a tx_queue. None of the buffers must have
435 * an skb attached.
436 */
437static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue)
438{
439 struct efx_tx_buffer *buffer;
440
441 /* Work backwards until we hit the original insert pointer value */
442 while (tx_queue->insert_count != tx_queue->write_count) {
443 --tx_queue->insert_count;
444 buffer = __efx_tx_queue_get_insert_buffer(tx_queue);
445 efx_dequeue_buffer(tx_queue, buffer, NULL, NULL);
446 }
447}
448
Edward Cree46d1efd2016-11-17 10:52:36 +0000449/*
450 * Fallback to software TSO.
451 *
452 * This is used if we are unable to send a GSO packet through hardware TSO.
453 * This should only ever happen due to per-queue restrictions - unsupported
454 * packets should first be filtered by the feature flags.
455 *
456 * Returns 0 on success, error code otherwise.
457 */
458static int efx_tx_tso_fallback(struct efx_tx_queue *tx_queue,
459 struct sk_buff *skb)
Bert Kenwarde9117e52016-11-17 10:51:54 +0000460{
Edward Cree46d1efd2016-11-17 10:52:36 +0000461 struct sk_buff *segments, *next;
462
463 segments = skb_gso_segment(skb, 0);
464 if (IS_ERR(segments))
465 return PTR_ERR(segments);
466
467 dev_kfree_skb_any(skb);
468 skb = segments;
469
470 while (skb) {
471 next = skb->next;
472 skb->next = NULL;
473
474 if (next)
475 skb->xmit_more = true;
476 efx_enqueue_skb(tx_queue, skb);
477 skb = next;
478 }
479
480 return 0;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000481}
482
Ben Hutchings8ceee662008-04-27 12:55:59 +0100483/*
484 * Add a socket buffer to a TX queue
485 *
486 * This maps all fragments of a socket buffer for DMA and adds them to
487 * the TX queue. The queue's insert pointer will be incremented by
488 * the number of fragments in the socket buffer.
489 *
490 * If any DMA mapping fails, any mapped fragments will be unmapped,
491 * the queue's insert pointer will be restored to its original value.
492 *
Ben Hutchings497f5ba2009-11-23 16:07:05 +0000493 * This function is split out from efx_hard_start_xmit to allow the
494 * loopback test to direct packets via specific TX queues.
495 *
Ben Hutchings14bf7182012-05-22 01:27:58 +0100496 * Returns NETDEV_TX_OK.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100497 * You must hold netif_tx_lock() to call this function.
498 */
Ben Hutchings497f5ba2009-11-23 16:07:05 +0000499netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100500{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000501 bool data_mapped = false;
502 unsigned int segments;
503 unsigned int skb_len;
Edward Cree46d1efd2016-11-17 10:52:36 +0000504 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100505
Bert Kenwarde9117e52016-11-17 10:51:54 +0000506 skb_len = skb->len;
507 segments = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 0;
508 if (segments == 1)
509 segments = 0; /* Don't use TSO for a single segment. */
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100510
Bert Kenwarde9117e52016-11-17 10:51:54 +0000511 /* Handle TSO first - it's *possible* (although unlikely) that we might
512 * be passed a packet to segment that's smaller than the copybreak/PIO
513 * size limit.
Ben Hutchings8ceee662008-04-27 12:55:59 +0100514 */
Bert Kenwarde9117e52016-11-17 10:51:54 +0000515 if (segments) {
516 EFX_BUG_ON_PARANOID(!tx_queue->handle_tso);
Edward Cree46d1efd2016-11-17 10:52:36 +0000517 rc = tx_queue->handle_tso(tx_queue, skb, &data_mapped);
518 if (rc == -EINVAL) {
519 rc = efx_tx_tso_fallback(tx_queue, skb);
520 tx_queue->tso_fallbacks++;
521 if (rc == 0)
522 return 0;
523 }
524 if (rc)
Bert Kenwarde9117e52016-11-17 10:51:54 +0000525 goto err;
526#ifdef EFX_USE_PIO
527 } else if (skb_len <= efx_piobuf_size && !skb->xmit_more &&
528 efx_nic_may_tx_pio(tx_queue)) {
529 /* Use PIO for short packets with an empty queue. */
530 if (efx_enqueue_skb_pio(tx_queue, skb))
531 goto err;
532 tx_queue->pio_packets++;
533 data_mapped = true;
534#endif
535 } else if (skb_len < tx_queue->tx_min_size ||
536 (skb->data_len && skb_len <= EFX_TX_CB_SIZE)) {
537 /* Pad short packets or coalesce short fragmented packets. */
538 if (efx_enqueue_skb_copy(tx_queue, skb))
539 goto err;
540 tx_queue->cb_packets++;
541 data_mapped = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100542 }
543
Bert Kenwarde9117e52016-11-17 10:51:54 +0000544 /* Map for DMA and create descriptors if we haven't done so already. */
545 if (!data_mapped && (efx_tx_map_data(tx_queue, skb, segments)))
546 goto err;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100547
Bert Kenwarde9117e52016-11-17 10:51:54 +0000548 /* Update BQL */
549 netdev_tx_sent_queue(tx_queue->core_txq, skb_len);
Edward Cree70b33fb2014-10-17 15:32:25 +0100550
Ben Hutchings8ceee662008-04-27 12:55:59 +0100551 /* Pass off to hardware */
Martin Habetsb2663a42015-11-02 12:51:31 +0000552 if (!skb->xmit_more || netif_xmit_stopped(tx_queue->core_txq)) {
553 struct efx_tx_queue *txq2 = efx_tx_queue_partner(tx_queue);
554
555 /* There could be packets left on the partner queue if those
556 * SKBs had skb->xmit_more set. If we do not push those they
557 * could be left for a long time and cause a netdev watchdog.
558 */
559 if (txq2->xmit_more_available)
560 efx_nic_push_buffers(txq2);
561
Edward Cree70b33fb2014-10-17 15:32:25 +0100562 efx_nic_push_buffers(tx_queue);
Martin Habetsb2663a42015-11-02 12:51:31 +0000563 } else {
564 tx_queue->xmit_more_available = skb->xmit_more;
565 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100566
Bert Kenwarde9117e52016-11-17 10:51:54 +0000567 if (segments) {
568 tx_queue->tso_bursts++;
569 tx_queue->tso_packets += segments;
570 tx_queue->tx_packets += segments;
571 } else {
572 tx_queue->tx_packets++;
573 }
574
575 efx_tx_maybe_stop_queue(tx_queue);
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100576
Ben Hutchings8ceee662008-04-27 12:55:59 +0100577 return NETDEV_TX_OK;
578
Ben Hutchings8ceee662008-04-27 12:55:59 +0100579
Bert Kenwarde9117e52016-11-17 10:51:54 +0000580err:
581 efx_enqueue_unwind(tx_queue);
Ben Hutchings9bc183d2009-11-23 16:06:47 +0000582 dev_kfree_skb_any(skb);
Ben Hutchings14bf7182012-05-22 01:27:58 +0100583 return NETDEV_TX_OK;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100584}
585
586/* Remove packets from the TX queue
587 *
588 * This removes packets from the TX queue, up to and including the
589 * specified index.
590 */
Ben Hutchings4d566062008-09-01 12:47:12 +0100591static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue,
Tom Herbertc3940992011-11-28 16:33:43 +0000592 unsigned int index,
593 unsigned int *pkts_compl,
594 unsigned int *bytes_compl)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100595{
596 struct efx_nic *efx = tx_queue->efx;
597 unsigned int stop_index, read_ptr;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100598
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000599 stop_index = (index + 1) & tx_queue->ptr_mask;
600 read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100601
602 while (read_ptr != stop_index) {
603 struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr];
Ben Hutchingsba8977b2013-01-08 23:43:19 +0000604
605 if (!(buffer->flags & EFX_TX_BUF_OPTION) &&
606 unlikely(buffer->len == 0)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000607 netif_err(efx, tx_err, efx->net_dev,
608 "TX queue %d spurious TX completion id %x\n",
609 tx_queue->queue, read_ptr);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100610 efx_schedule_reset(efx, RESET_TYPE_TX_SKIP);
611 return;
612 }
613
Tom Herbertc3940992011-11-28 16:33:43 +0000614 efx_dequeue_buffer(tx_queue, buffer, pkts_compl, bytes_compl);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100615
616 ++tx_queue->read_count;
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000617 read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100618 }
619}
620
Ben Hutchings8ceee662008-04-27 12:55:59 +0100621/* Initiate a packet transmission. We use one channel per CPU
622 * (sharing when we have more CPUs than channels). On Falcon, the TX
623 * completion events will be directed back to the CPU that transmitted
624 * the packet, which should be cache-efficient.
625 *
626 * Context: non-blocking.
627 * Note that returning anything other than NETDEV_TX_OK will cause the
628 * OS to free the skb.
629 */
Stephen Hemminger613573252009-08-31 19:50:58 +0000630netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
Ben Hutchings2d0cc562012-02-17 00:10:45 +0000631 struct net_device *net_dev)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100632{
Ben Hutchings767e4682008-09-01 12:43:14 +0100633 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100634 struct efx_tx_queue *tx_queue;
Ben Hutchings94b274b2011-01-10 21:18:20 +0000635 unsigned index, type;
Ben Hutchings60ac1062008-09-01 12:44:59 +0100636
Ben Hutchingse4abce82011-05-16 18:51:24 +0100637 EFX_WARN_ON_PARANOID(!netif_device_present(net_dev));
Ben Hutchingsa7ef5932009-03-04 09:52:37 +0000638
Stuart Hodgson7c236c42012-09-03 11:09:36 +0100639 /* PTP "event" packet */
640 if (unlikely(efx_xmit_with_hwtstamp(skb)) &&
641 unlikely(efx_ptp_is_ptp_tx(efx, skb))) {
642 return efx_ptp_tx(efx, skb);
643 }
644
Ben Hutchings94b274b2011-01-10 21:18:20 +0000645 index = skb_get_queue_mapping(skb);
646 type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
647 if (index >= efx->n_tx_channels) {
648 index -= efx->n_tx_channels;
649 type |= EFX_TXQ_TYPE_HIGHPRI;
650 }
651 tx_queue = efx_get_tx_queue(efx, index, type);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100652
Ben Hutchings497f5ba2009-11-23 16:07:05 +0000653 return efx_enqueue_skb(tx_queue, skb);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100654}
655
Ben Hutchings60031fc2011-01-12 18:39:40 +0000656void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
657{
Ben Hutchings94b274b2011-01-10 21:18:20 +0000658 struct efx_nic *efx = tx_queue->efx;
659
Ben Hutchings60031fc2011-01-12 18:39:40 +0000660 /* Must be inverse of queue lookup in efx_hard_start_xmit() */
Ben Hutchings94b274b2011-01-10 21:18:20 +0000661 tx_queue->core_txq =
662 netdev_get_tx_queue(efx->net_dev,
663 tx_queue->queue / EFX_TXQ_TYPES +
664 ((tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ?
665 efx->n_tx_channels : 0));
666}
667
John Fastabend16e5cc62016-02-16 21:16:43 -0800668int efx_setup_tc(struct net_device *net_dev, u32 handle, __be16 proto,
669 struct tc_to_netdev *ntc)
Ben Hutchings94b274b2011-01-10 21:18:20 +0000670{
671 struct efx_nic *efx = netdev_priv(net_dev);
672 struct efx_channel *channel;
673 struct efx_tx_queue *tx_queue;
John Fastabend16e5cc62016-02-16 21:16:43 -0800674 unsigned tc, num_tc;
Ben Hutchings94b274b2011-01-10 21:18:20 +0000675 int rc;
676
John Fastabend5eb4dce2016-02-29 11:26:13 -0800677 if (ntc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -0800678 return -EINVAL;
679
John Fastabend16e5cc62016-02-16 21:16:43 -0800680 num_tc = ntc->tc;
681
Ben Hutchings94b274b2011-01-10 21:18:20 +0000682 if (efx_nic_rev(efx) < EFX_REV_FALCON_B0 || num_tc > EFX_MAX_TX_TC)
683 return -EINVAL;
684
685 if (num_tc == net_dev->num_tc)
686 return 0;
687
688 for (tc = 0; tc < num_tc; tc++) {
689 net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels;
690 net_dev->tc_to_txq[tc].count = efx->n_tx_channels;
691 }
692
693 if (num_tc > net_dev->num_tc) {
694 /* Initialise high-priority queues as necessary */
695 efx_for_each_channel(channel, efx) {
696 efx_for_each_possible_channel_tx_queue(tx_queue,
697 channel) {
698 if (!(tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI))
699 continue;
700 if (!tx_queue->buffer) {
701 rc = efx_probe_tx_queue(tx_queue);
702 if (rc)
703 return rc;
704 }
705 if (!tx_queue->initialised)
706 efx_init_tx_queue(tx_queue);
707 efx_init_tx_queue_core_txq(tx_queue);
708 }
709 }
710 } else {
711 /* Reduce number of classes before number of queues */
712 net_dev->num_tc = num_tc;
713 }
714
715 rc = netif_set_real_num_tx_queues(net_dev,
716 max_t(int, num_tc, 1) *
717 efx->n_tx_channels);
718 if (rc)
719 return rc;
720
721 /* Do not destroy high-priority queues when they become
722 * unused. We would have to flush them first, and it is
723 * fairly difficult to flush a subset of TX queues. Leave
724 * it to efx_fini_channels().
725 */
726
727 net_dev->num_tc = num_tc;
728 return 0;
Ben Hutchings60031fc2011-01-12 18:39:40 +0000729}
730
Ben Hutchings8ceee662008-04-27 12:55:59 +0100731void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index)
732{
733 unsigned fill_level;
734 struct efx_nic *efx = tx_queue->efx;
Ben Hutchings14bf7182012-05-22 01:27:58 +0100735 struct efx_tx_queue *txq2;
Tom Herbertc3940992011-11-28 16:33:43 +0000736 unsigned int pkts_compl = 0, bytes_compl = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100737
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000738 EFX_BUG_ON_PARANOID(index > tx_queue->ptr_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100739
Tom Herbertc3940992011-11-28 16:33:43 +0000740 efx_dequeue_buffers(tx_queue, index, &pkts_compl, &bytes_compl);
Peter Dunningc9368352015-07-08 10:05:10 +0100741 tx_queue->pkts_compl += pkts_compl;
742 tx_queue->bytes_compl += bytes_compl;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100743
Ben Hutchings02e12162013-04-27 01:55:21 +0100744 if (pkts_compl > 1)
745 ++tx_queue->merge_events;
746
Ben Hutchings14bf7182012-05-22 01:27:58 +0100747 /* See if we need to restart the netif queue. This memory
748 * barrier ensures that we write read_count (inside
749 * efx_dequeue_buffers()) before reading the queue status.
750 */
Ben Hutchings8ceee662008-04-27 12:55:59 +0100751 smp_mb();
Ben Hutchingsc04bfc62010-12-10 01:24:16 +0000752 if (unlikely(netif_tx_queue_stopped(tx_queue->core_txq)) &&
Neil Turton9d1aea62011-04-04 13:46:23 +0100753 likely(efx->port_enabled) &&
Ben Hutchingse4abce82011-05-16 18:51:24 +0100754 likely(netif_device_present(efx->net_dev))) {
Ben Hutchings14bf7182012-05-22 01:27:58 +0100755 txq2 = efx_tx_queue_partner(tx_queue);
756 fill_level = max(tx_queue->insert_count - tx_queue->read_count,
757 txq2->insert_count - txq2->read_count);
758 if (fill_level <= efx->txq_wake_thresh)
Ben Hutchingsc04bfc62010-12-10 01:24:16 +0000759 netif_tx_wake_queue(tx_queue->core_txq);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100760 }
Ben Hutchingscd385572010-11-15 23:53:11 +0000761
762 /* Check whether the hardware queue is now empty */
763 if ((int)(tx_queue->read_count - tx_queue->old_write_count) >= 0) {
764 tx_queue->old_write_count = ACCESS_ONCE(tx_queue->write_count);
765 if (tx_queue->read_count == tx_queue->old_write_count) {
766 smp_mb();
767 tx_queue->empty_read_count =
768 tx_queue->read_count | EFX_EMPTY_COUNT_VALID;
769 }
770 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100771}
772
Bert Kenwarde9117e52016-11-17 10:51:54 +0000773static unsigned int efx_tx_cb_page_count(struct efx_tx_queue *tx_queue)
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100774{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000775 return DIV_ROUND_UP(tx_queue->ptr_mask + 1, PAGE_SIZE >> EFX_TX_CB_ORDER);
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100776}
777
Ben Hutchings8ceee662008-04-27 12:55:59 +0100778int efx_probe_tx_queue(struct efx_tx_queue *tx_queue)
779{
780 struct efx_nic *efx = tx_queue->efx;
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000781 unsigned int entries;
Ben Hutchings7668ff92012-05-17 20:52:20 +0100782 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100783
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000784 /* Create the smallest power-of-two aligned ring */
785 entries = max(roundup_pow_of_two(efx->txq_entries), EFX_MIN_DMAQ_SIZE);
786 EFX_BUG_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE);
787 tx_queue->ptr_mask = entries - 1;
788
789 netif_dbg(efx, probe, efx->net_dev,
790 "creating TX queue %d size %#x mask %#x\n",
791 tx_queue->queue, efx->txq_entries, tx_queue->ptr_mask);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100792
793 /* Allocate software ring */
Thomas Meyerc2e4e252011-12-02 12:36:13 +0000794 tx_queue->buffer = kcalloc(entries, sizeof(*tx_queue->buffer),
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000795 GFP_KERNEL);
Ben Hutchings60ac1062008-09-01 12:44:59 +0100796 if (!tx_queue->buffer)
797 return -ENOMEM;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100798
Bert Kenwarde9117e52016-11-17 10:51:54 +0000799 tx_queue->cb_page = kcalloc(efx_tx_cb_page_count(tx_queue),
800 sizeof(tx_queue->cb_page[0]), GFP_KERNEL);
801 if (!tx_queue->cb_page) {
802 rc = -ENOMEM;
803 goto fail1;
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100804 }
805
Ben Hutchings8ceee662008-04-27 12:55:59 +0100806 /* Allocate hardware ring */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000807 rc = efx_nic_probe_tx(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100808 if (rc)
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100809 goto fail2;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100810
811 return 0;
812
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100813fail2:
Bert Kenwarde9117e52016-11-17 10:51:54 +0000814 kfree(tx_queue->cb_page);
815 tx_queue->cb_page = NULL;
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100816fail1:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100817 kfree(tx_queue->buffer);
818 tx_queue->buffer = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100819 return rc;
820}
821
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100822void efx_init_tx_queue(struct efx_tx_queue *tx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100823{
Bert Kenwarde9117e52016-11-17 10:51:54 +0000824 struct efx_nic *efx = tx_queue->efx;
825
826 netif_dbg(efx, drv, efx->net_dev,
Ben Hutchings62776d02010-06-23 11:30:07 +0000827 "initialising TX queue %d\n", tx_queue->queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100828
829 tx_queue->insert_count = 0;
830 tx_queue->write_count = 0;
Ben Hutchingscd385572010-11-15 23:53:11 +0000831 tx_queue->old_write_count = 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100832 tx_queue->read_count = 0;
833 tx_queue->old_read_count = 0;
Ben Hutchingscd385572010-11-15 23:53:11 +0000834 tx_queue->empty_read_count = 0 | EFX_EMPTY_COUNT_VALID;
Martin Habetsb2663a42015-11-02 12:51:31 +0000835 tx_queue->xmit_more_available = false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100836
Bert Kenwarde9117e52016-11-17 10:51:54 +0000837 /* Set up default function pointers. These may get replaced by
838 * efx_nic_init_tx() based off NIC/queue capabilities.
839 */
Edward Cree46d1efd2016-11-17 10:52:36 +0000840 tx_queue->handle_tso = efx_enqueue_skb_tso;
Bert Kenwarde9117e52016-11-17 10:51:54 +0000841
842 /* Some older hardware requires Tx writes larger than 32. */
843 tx_queue->tx_min_size = EFX_WORKAROUND_15592(efx) ? 33 : 0;
844
Ben Hutchings8ceee662008-04-27 12:55:59 +0100845 /* Set up TX descriptor ring */
Ben Hutchings152b6a62009-11-29 03:43:56 +0000846 efx_nic_init_tx(tx_queue);
Ben Hutchings94b274b2011-01-10 21:18:20 +0000847
848 tx_queue->initialised = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100849}
850
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100851void efx_fini_tx_queue(struct efx_tx_queue *tx_queue)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100852{
853 struct efx_tx_buffer *buffer;
854
Ben Hutchingse42c3d82013-05-27 16:52:54 +0100855 netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
856 "shutting down TX queue %d\n", tx_queue->queue);
857
Ben Hutchings8ceee662008-04-27 12:55:59 +0100858 if (!tx_queue->buffer)
859 return;
860
861 /* Free any buffers left in the ring */
862 while (tx_queue->read_count != tx_queue->write_count) {
Tom Herbertc3940992011-11-28 16:33:43 +0000863 unsigned int pkts_compl = 0, bytes_compl = 0;
Steve Hodgsonecc910f2010-09-10 06:42:22 +0000864 buffer = &tx_queue->buffer[tx_queue->read_count & tx_queue->ptr_mask];
Tom Herbertc3940992011-11-28 16:33:43 +0000865 efx_dequeue_buffer(tx_queue, buffer, &pkts_compl, &bytes_compl);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100866
867 ++tx_queue->read_count;
868 }
Martin Habetsb2663a42015-11-02 12:51:31 +0000869 tx_queue->xmit_more_available = false;
Tom Herbertc3940992011-11-28 16:33:43 +0000870 netdev_tx_reset_queue(tx_queue->core_txq);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100871}
872
Ben Hutchings8ceee662008-04-27 12:55:59 +0100873void efx_remove_tx_queue(struct efx_tx_queue *tx_queue)
874{
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100875 int i;
876
Ben Hutchings94b274b2011-01-10 21:18:20 +0000877 if (!tx_queue->buffer)
878 return;
879
Ben Hutchings62776d02010-06-23 11:30:07 +0000880 netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
881 "destroying TX queue %d\n", tx_queue->queue);
Ben Hutchings152b6a62009-11-29 03:43:56 +0000882 efx_nic_remove_tx(tx_queue);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100883
Bert Kenwarde9117e52016-11-17 10:51:54 +0000884 if (tx_queue->cb_page) {
885 for (i = 0; i < efx_tx_cb_page_count(tx_queue); i++)
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100886 efx_nic_free_buffer(tx_queue->efx,
Bert Kenwarde9117e52016-11-17 10:51:54 +0000887 &tx_queue->cb_page[i]);
888 kfree(tx_queue->cb_page);
889 tx_queue->cb_page = NULL;
Ben Hutchingsf7251a92012-05-17 18:40:54 +0100890 }
891
Ben Hutchings8ceee662008-04-27 12:55:59 +0100892 kfree(tx_queue->buffer);
893 tx_queue->buffer = NULL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100894}